diff --git a/third_party/libromfs/generator/source/main.cpp b/third_party/libromfs/generator/source/main.cpp index c6a4c0b..9ffa706 100644 --- a/third_party/libromfs/generator/source/main.cpp +++ b/third_party/libromfs/generator/source/main.cpp @@ -62,7 +62,16 @@ int main() { auto resourceLocations = splitString(RESOURCE_LOCATION, ","); for (const auto &resourceLocation : resourceLocations) { - std::printf("[libromfs] Resource Folder: %s\n", resourceLocation.c_str()); + std::printf("[libromfs] Packing resource folder: %s\n", resourceLocation.c_str()); + + std::error_code errorCode; + if (!std::filesystem::exists(resourceLocation, errorCode)) { + if (errorCode) { + std::printf("[libromfs] Error: %s\n", errorCode.message().c_str()); + } + + continue; + } outputFile << "\n/* Resource folder: " << resourceLocation << " */\n"; for (const auto &entry : fs::recursive_directory_iterator(resourceLocation)) { @@ -81,13 +90,11 @@ int main() { bytes.resize(std::fread(bytes.data(), 1, entry.file_size(), file)); std::fclose(file); - outputFile << std::hex << std::uppercase << std::setfill('0') << std::setw(2); for (std::byte byte : bytes) { - outputFile << "0x" << static_cast(byte) << ", "; + outputFile << static_cast(byte) << ","; } - outputFile << std::dec << std::nouppercase << std::setfill(' ') << std::setw(0); - outputFile << "\n 0x00 };\n\n"; + outputFile << "0 };\n\n"; paths.push_back(relativePath); @@ -99,7 +106,7 @@ int main() { { outputFile << "/* Resource map */\n"; - outputFile << "std::span RomFs_" LIBROMFS_PROJECT_NAME "_get_resources() {\n"; + outputFile << "ROMFS_VISIBILITY std::span RomFs_" LIBROMFS_PROJECT_NAME "_get_resources() {\n"; outputFile << " static std::array resources = {\n"; for (std::uint64_t i = 0; i < identifierCount; i++) { @@ -117,7 +124,7 @@ int main() { { outputFile << "/* Resource paths */\n"; - outputFile << "std::span RomFs_" LIBROMFS_PROJECT_NAME "_get_paths() {\n"; + outputFile << "ROMFS_VISIBILITY std::span RomFs_" LIBROMFS_PROJECT_NAME "_get_paths() {\n"; outputFile << " static std::array paths = {\n"; for (std::uint64_t i = 0; i < identifierCount; i++) { @@ -133,7 +140,7 @@ int main() { { outputFile << "/* RomFS name */\n"; - outputFile << "const char* RomFs_" LIBROMFS_PROJECT_NAME "_get_name() {\n"; + outputFile << "ROMFS_VISIBILITY const char* RomFs_" LIBROMFS_PROJECT_NAME "_get_name() {\n"; outputFile << " return \"" LIBROMFS_PROJECT_NAME "\";\n"; outputFile << "}\n\n"; } diff --git a/third_party/libromfs/lib/include/romfs/romfs.hpp b/third_party/libromfs/lib/include/romfs/romfs.hpp index 3325e9a..42becdf 100644 --- a/third_party/libromfs/lib/include/romfs/romfs.hpp +++ b/third_party/libromfs/lib/include/romfs/romfs.hpp @@ -12,6 +12,12 @@ #define ROMFS_NAME ROMFS_CONCAT(RomFs_, LIBROMFS_PROJECT_NAME) +#if !defined(WIN32) + #define ROMFS_VISIBILITY [[gnu::visibility("hidden")]] +#else + #define ROMFS_VISIBILITY +#endif + template concept ByteType = std::is_trivial_v && sizeof(T) == sizeof(std::byte); @@ -63,15 +69,15 @@ namespace romfs { Resource resource; }; - [[nodiscard]] const Resource& ROMFS_CONCAT(get_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &path); - [[nodiscard]] std::vector ROMFS_CONCAT(list_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &path); - [[nodiscard]] std::string_view ROMFS_CONCAT(name_, LIBROMFS_PROJECT_NAME)(); + [[nodiscard]] ROMFS_VISIBILITY const Resource& ROMFS_CONCAT(get_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &path); + [[nodiscard]] ROMFS_VISIBILITY std::vector ROMFS_CONCAT(list_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &path); + [[nodiscard]] ROMFS_VISIBILITY std::string_view ROMFS_CONCAT(name_, LIBROMFS_PROJECT_NAME)(); } - [[nodiscard]] inline const Resource& get(const std::filesystem::path &path) { return impl::ROMFS_CONCAT(get_, LIBROMFS_PROJECT_NAME)(path); } - [[nodiscard]] inline std::vector list(const std::filesystem::path &path = {}) { return impl::ROMFS_CONCAT(list_, LIBROMFS_PROJECT_NAME)(path); } - [[nodiscard]] inline std::string_view name() { return impl::ROMFS_CONCAT(name_, LIBROMFS_PROJECT_NAME)(); } + [[nodiscard]] ROMFS_VISIBILITY inline const Resource& get(const std::filesystem::path &path) { return impl::ROMFS_CONCAT(get_, LIBROMFS_PROJECT_NAME)(path); } + [[nodiscard]] ROMFS_VISIBILITY inline std::vector list(const std::filesystem::path &path = {}) { return impl::ROMFS_CONCAT(list_, LIBROMFS_PROJECT_NAME)(path); } + [[nodiscard]] ROMFS_VISIBILITY inline std::string_view name() { return impl::ROMFS_CONCAT(name_, LIBROMFS_PROJECT_NAME)(); } } \ No newline at end of file diff --git a/third_party/libromfs/lib/source/romfs.cpp b/third_party/libromfs/lib/source/romfs.cpp index 0d189a0..f1cf2f3 100644 --- a/third_party/libromfs/lib/source/romfs.cpp +++ b/third_party/libromfs/lib/source/romfs.cpp @@ -1,12 +1,14 @@ #include +#include + std::span ROMFS_CONCAT(ROMFS_NAME, _get_resources)(); std::span ROMFS_CONCAT(ROMFS_NAME, _get_paths)(); const char* ROMFS_CONCAT(ROMFS_NAME, _get_name)(); namespace romfs { - const romfs::Resource &impl::ROMFS_CONCAT(get_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &path) { + ROMFS_VISIBILITY const romfs::Resource &impl::ROMFS_CONCAT(get_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &path) { for (const auto &[resourcePath, resourceData] : ROMFS_CONCAT(ROMFS_NAME, _get_resources)()) { if (path == resourcePath) return resourceData; @@ -15,18 +17,18 @@ namespace romfs { throw std::invalid_argument(std::string("Invalid romfs resource path! File '") + std::string(romfs::name()) + "' : " + path.string()); } - std::vector impl::ROMFS_CONCAT(list_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &parent) { + ROMFS_VISIBILITY std::vector impl::ROMFS_CONCAT(list_, LIBROMFS_PROJECT_NAME)(const std::filesystem::path &parent) { std::vector result; for (const auto &pathString : ROMFS_CONCAT(ROMFS_NAME, _get_paths)()) { auto path = std::filesystem::path(pathString); - if (path.parent_path() == parent) + if (std::ranges::mismatch(parent, path).in1 == parent.end()) result.emplace_back(std::move(path)); } return result; } - std::string_view impl::ROMFS_CONCAT(name_, LIBROMFS_PROJECT_NAME)() { + ROMFS_VISIBILITY std::string_view impl::ROMFS_CONCAT(name_, LIBROMFS_PROJECT_NAME)() { return ROMFS_CONCAT(ROMFS_NAME, _get_name)(); }