diff --git a/CMakeLists.txt b/CMakeLists.txt index 834668e92a..63ed9edfe1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 50) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 95) +set(OPENMW_LUA_API_REVISION 96) set(OPENMW_POSTPROCESSING_API_REVISION 3) set(OPENMW_VERSION_COMMITHASH "") diff --git a/apps/components_tests/misc/testresourcehelpers.cpp b/apps/components_tests/misc/testresourcehelpers.cpp index 2e02590624..4b6c544038 100644 --- a/apps/components_tests/misc/testresourcehelpers.cpp +++ b/apps/components_tests/misc/testresourcehelpers.cpp @@ -37,7 +37,7 @@ namespace Misc::ResourceHelpers TEST(MiscResourceHelpersCorrectResourcePath, shouldFallbackToGivenExtentionIfDoesNotExistInVfs) { const std::unique_ptr vfs = TestingOpenMW::createTestVFS({}); - EXPECT_EQ(correctResourcePath({ { "sound" } }, "sound/foo.wav", vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, "sound/foo.wav", vfs.get(), ".mp3"), "sound/foo.mp3"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldFallbackToGivenExtentionIfBothExistInVfs) @@ -48,7 +48,7 @@ namespace Misc::ResourceHelpers { wav, nullptr }, { mp3, nullptr }, }); - EXPECT_EQ(correctResourcePath({ { "sound" } }, wav.value(), vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, wav.value(), vfs.get(), ".mp3"), "sound/foo.mp3"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldKeepExtentionIfExistInVfs) @@ -57,13 +57,13 @@ namespace Misc::ResourceHelpers const std::unique_ptr vfs = TestingOpenMW::createTestVFS({ { wav, nullptr }, }); - EXPECT_EQ(correctResourcePath({ { "sound" } }, wav.value(), vfs.get(), ".mp3"), "sound\\foo.wav"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, wav.value(), vfs.get(), ".mp3"), "sound/foo.wav"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldPrefixWithGivenTopDirectory) { const std::unique_ptr vfs = TestingOpenMW::createTestVFS({}); - EXPECT_EQ(correctResourcePath({ { "sound" } }, "foo.mp3", vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, "foo.mp3", vfs.get(), ".mp3"), "sound/foo.mp3"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldChangeTopDirectoryAndKeepExtensionIfOriginalExistInVfs) @@ -72,8 +72,8 @@ namespace Misc::ResourceHelpers const std::unique_ptr vfs = TestingOpenMW::createTestVFS({ { a, nullptr }, }); - EXPECT_EQ(correctResourcePath({ { "textures", "bookart" } }, "bookart/foo.a", vfs.get(), ".b"), - "textures\\foo.a"); + EXPECT_EQ( + correctResourcePath({ { "textures", "bookart" } }, "bookart/foo.a", vfs.get(), ".b"), "textures/foo.a"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldChangeTopDirectoryAndChangeExtensionIfFallbackExistInVfs) @@ -82,33 +82,32 @@ namespace Misc::ResourceHelpers const std::unique_ptr vfs = TestingOpenMW::createTestVFS({ { b, nullptr }, }); - EXPECT_EQ(correctResourcePath({ { "textures", "bookart" } }, "bookart/foo.a", vfs.get(), ".b"), - "textures\\foo.b"); + EXPECT_EQ( + correctResourcePath({ { "textures", "bookart" } }, "bookart/foo.a", vfs.get(), ".b"), "textures/foo.b"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldLowerCase) { const std::unique_ptr vfs = TestingOpenMW::createTestVFS({}); - EXPECT_EQ(correctResourcePath({ { "sound" } }, "SOUND\\Foo.MP3", vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, "SOUND\\Foo.MP3", vfs.get(), ".mp3"), "sound/foo.mp3"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldRemoveLeadingSlash) { const std::unique_ptr vfs = TestingOpenMW::createTestVFS({}); - EXPECT_EQ(correctResourcePath({ { "sound" } }, "\\SOUND\\Foo.MP3", vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, "\\SOUND\\Foo.MP3", vfs.get(), ".mp3"), "sound/foo.mp3"); } TEST(MiscResourceHelpersCorrectResourcePath, shouldRemoveDuplicateSlashes) { const std::unique_ptr vfs = TestingOpenMW::createTestVFS({}); - EXPECT_EQ( - correctResourcePath({ { "sound" } }, "\\\\SOUND\\\\Foo.MP3", vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, "\\\\SOUND\\\\Foo.MP3", vfs.get(), ".mp3"), "sound/foo.mp3"); } - TEST(MiscResourceHelpersCorrectResourcePath, shouldConvertToBackSlash) + TEST(MiscResourceHelpersCorrectResourcePath, shouldConvertToForwardSlash) { const std::unique_ptr vfs = TestingOpenMW::createTestVFS({}); - EXPECT_EQ(correctResourcePath({ { "sound" } }, "SOUND/Foo.MP3", vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, "SOUND/Foo.MP3", vfs.get(), ".mp3"), "sound/foo.mp3"); } struct MiscResourceHelpersCorrectResourcePathShouldRemoveExtraPrefix : TestWithParam @@ -118,7 +117,7 @@ namespace Misc::ResourceHelpers TEST_P(MiscResourceHelpersCorrectResourcePathShouldRemoveExtraPrefix, shouldMatchExpected) { const std::unique_ptr vfs = TestingOpenMW::createTestVFS({}); - EXPECT_EQ(correctResourcePath({ { "sound" } }, GetParam(), vfs.get(), ".mp3"), "sound\\foo.mp3"); + EXPECT_EQ(correctResourcePath({ { "sound" } }, GetParam(), vfs.get(), ".mp3"), "sound/foo.mp3"); } const std::vector pathsWithPrefix = { diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index c3164b0dfe..9b0e81dc59 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -37,15 +37,14 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path) std::string Misc::ResourceHelpers::correctResourcePath(std::span topLevelDirectories, std::string_view resPath, const VFS::Manager* vfs, std::string_view ext) { - std::string correctedPath = Misc::StringUtils::lowerCase(resPath); + std::string correctedPath = VFS::Path::normalizeFilename(resPath); // Flatten slashes - std::replace(correctedPath.begin(), correctedPath.end(), '/', '\\'); - auto bothSeparators = [](char a, char b) { return a == '\\' && b == '\\'; }; + auto bothSeparators = [](char a, char b) { return a == VFS::Path::separator && b == VFS::Path::separator; }; correctedPath.erase(std::unique(correctedPath.begin(), correctedPath.end(), bothSeparators), correctedPath.end()); // Remove leading separator - if (!correctedPath.empty() && correctedPath[0] == '\\') + if (!correctedPath.empty() && correctedPath[0] == VFS::Path::separator) correctedPath.erase(0, 1); // Handle top level directory @@ -54,15 +53,15 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::span potentialTopLevelDirectory.size() - && correctedPath[potentialTopLevelDirectory.size()] == '\\') + && correctedPath[potentialTopLevelDirectory.size()] == VFS::Path::separator) { needsPrefix = false; break; } else { - std::string topLevelPrefix = std::string{ potentialTopLevelDirectory } + '\\'; - size_t topLevelPos = correctedPath.find('\\' + topLevelPrefix); + std::string topLevelPrefix = std::string{ potentialTopLevelDirectory } + VFS::Path::separator; + size_t topLevelPos = correctedPath.find(VFS::Path::separator + topLevelPrefix); if (topLevelPos != std::string::npos) { correctedPath.erase(0, topLevelPos + 1); @@ -72,7 +71,7 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::spanexists(fallback)) @@ -97,7 +96,7 @@ std::string Misc::ResourceHelpers::correctResourcePath(std::spanexists(fallback)) return fallback;