diff --git a/include/loot/game_interface.h b/include/loot/game_interface.h index ccc688db..3a292a75 100644 --- a/include/loot/game_interface.h +++ b/include/loot/game_interface.h @@ -77,7 +77,7 @@ public: * as given. * @returns True if the file is a valid plugin, false otherwise. */ - virtual bool IsValidPlugin(const std::string& pluginPath) const = 0; + virtual bool IsValidPlugin(const std::filesystem::path& pluginPath) const = 0; /** * @brief Parses plugins and loads their data. @@ -93,8 +93,9 @@ public: * file if it has been identified by a previous call to * ``IdentifyMainMasterFile()``. */ - virtual void LoadPlugins(const std::vector& pluginPaths, - bool loadHeadersOnly) = 0; + virtual void LoadPlugins( + const std::vector& pluginPaths, + bool loadHeadersOnly) = 0; /** * @brief Get data for a loaded plugin. @@ -144,7 +145,7 @@ public: * order. */ virtual std::vector SortPlugins( - const std::vector& pluginPaths) = 0; + const std::vector& pluginPaths) = 0; /** * @} diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index 002785bd..2ba6d12f 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -142,16 +142,6 @@ std::vector FindArchives( return archivePaths; } - -std::vector StringsToPaths( - const std::vector& pluginPathStrings) { - std::vector pluginPaths; - for (const auto& pluginPathString : pluginPathStrings) { - pluginPaths.push_back(u8path(pluginPathString)); - } - - return pluginPaths; -} } namespace loot { @@ -201,19 +191,10 @@ void Game::SetAdditionalDataPaths( loadOrderHandler_.SetAdditionalDataPaths(additionalDataPaths_); } -bool Game::IsValidPlugin(const std::string& pluginPath) const { - return IsValidPlugin(u8path(pluginPath)); -} - bool Game::IsValidPlugin(const std::filesystem::path& pluginPath) const { return Plugin::IsValid(GetType(), ResolvePluginPath(DataPath(), pluginPath)); } -void Game::LoadPlugins(const std::vector& pluginPathStrings, - bool loadHeadersOnly) { - return LoadPlugins(StringsToPaths(pluginPathStrings), loadHeadersOnly); -} - void Game::LoadPlugins(const std::vector& pluginPaths, bool loadHeadersOnly) { const auto logger = getLogger(); @@ -310,11 +291,6 @@ void Game::IdentifyMainMasterFile(const std::string& masterFile) { masterFilename_ = masterFile; } -std::vector Game::SortPlugins( - const std::vector& pluginPathStrings) { - return SortPlugins(StringsToPaths(pluginPathStrings)); -} - std::vector Game::SortPlugins( const std::vector& pluginPaths) { LoadPlugins(pluginPaths, false); diff --git a/src/api/game/game.h b/src/api/game/game.h index 47e8000e..e68a2e14 100644 --- a/src/api/game/game.h +++ b/src/api/game/game.h @@ -55,14 +55,6 @@ public: void SetAdditionalDataPaths( const std::vector& additionalDataPaths); - bool IsValidPlugin(const std::filesystem::path& pluginPath) const; - - void LoadPlugins(const std::vector& pluginPaths, - bool loadHeadersOnly); - - std::vector SortPlugins( - const std::vector& pluginPaths); - // Game Interface Methods // //////////////////////////// @@ -71,9 +63,9 @@ public: DatabaseInterface& GetDatabase() override; const DatabaseInterface& GetDatabase() const override; - bool IsValidPlugin(const std::string& pluginPath) const override; + bool IsValidPlugin(const std::filesystem::path& pluginPath) const override; - void LoadPlugins(const std::vector& pluginPaths, + void LoadPlugins(const std::vector& pluginPaths, bool loadHeadersOnly) override; const PluginInterface* GetPlugin( @@ -84,7 +76,7 @@ public: void IdentifyMainMasterFile(const std::string& masterFile) override; std::vector SortPlugins( - const std::vector& pluginPaths) override; + const std::vector& pluginPaths) override; void LoadCurrentLoadOrderState() override; diff --git a/src/tests/api/interface/game_interface_test.h b/src/tests/api/interface/game_interface_test.h index 335c8f7c..1211f51b 100644 --- a/src/tests/api/interface/game_interface_test.h +++ b/src/tests/api/interface/game_interface_test.h @@ -36,6 +36,7 @@ protected: emptyFile("EmptyFile.esm"), nonAsciiEsm(u8"non\u00C1scii.esm"), pluginsToLoad({ + // These are all ASCII filenames. masterFile, blankEsm, blankDifferentEsm, @@ -55,7 +56,7 @@ protected: const std::string emptyFile; const std::string nonAsciiEsm; - const std::vector pluginsToLoad; + const std::vector pluginsToLoad; }; // Pass an empty first argument, as it's a prefix for the test instantation, @@ -75,7 +76,7 @@ TEST_P(GameInterfaceTest, isValidPluginShouldReturnTrueForAValidPlugin) { TEST_P(GameInterfaceTest, isValidPluginShouldReturnTrueForAValidNonAsciiPlugin) { - EXPECT_TRUE(handle_->IsValidPlugin(nonAsciiEsm)); + EXPECT_TRUE(handle_->IsValidPlugin(std::filesystem::u8path(nonAsciiEsm))); } TEST_P(GameInterfaceTest, isValidPluginShouldReturnFalseForANonPluginFile) { @@ -131,7 +132,7 @@ TEST_P(GameInterfaceTest, } TEST_P(GameInterfaceTest, loadPluginsWithANonAsciiPluginShouldLoadIt) { - handle_->LoadPlugins({nonAsciiEsm}, false); + handle_->LoadPlugins({std::filesystem::u8path(nonAsciiEsm)}, false); EXPECT_EQ(1, handle_->GetLoadedPlugins().size()); // Check that one plugin's header has been read. @@ -173,7 +174,8 @@ TEST_P(GameInterfaceTest, sortPluginsShouldSucceedIfPassedValidArguments) { ASSERT_NO_THROW(GenerateMasterlist()); ASSERT_NO_THROW(handle_->GetDatabase().LoadLists(masterlistPath, "")); - std::vector pluginsToSort({ + std::vector pluginsToSort({ + // These are all ASCII filenames. blankEsp, blankPluginDependentEsp, blankDifferentMasterDependentEsm, diff --git a/src/tests/api/internals/game/game_test.h b/src/tests/api/internals/game/game_test.h index ae3d2ff4..a02ac8dd 100644 --- a/src/tests/api/internals/game/game_test.h +++ b/src/tests/api/internals/game/game_test.h @@ -38,7 +38,8 @@ protected: } void loadInstalledPlugins(Game& game, bool headersOnly) { - const std::vector plugins({ + const std::vector plugins({ + // These are all ASCII filenames. masterFile, blankEsm, blankDifferentEsm, @@ -149,7 +150,9 @@ TEST_P( TEST_P(GameTest, isValidPluginShouldResolveRelativePathsRelativeToDataPath) { const Game game(GetParam(), dataPath.parent_path(), localPath); - game.IsValidPlugin("../" + dataPath.filename().u8string() + "/" + blankEsm); + const auto path = ".." / dataPath.filename() / blankEsm; + + EXPECT_TRUE(game.IsValidPlugin(path)); } TEST_P(GameTest, isValidPluginShouldUseAbsolutePathsAsGiven) { @@ -158,7 +161,8 @@ TEST_P(GameTest, isValidPluginShouldUseAbsolutePathsAsGiven) { ASSERT_TRUE(dataPath.is_absolute()); const auto path = dataPath / std::filesystem::u8path(blankEsm); - game.IsValidPlugin(path.u8string()); + + EXPECT_TRUE(game.IsValidPlugin(path)); } TEST_P( @@ -181,9 +185,9 @@ TEST_P( TEST_P(GameTest, loadPluginsWithANonPluginShouldNotAddItToTheLoadedPlugins) { Game game = Game(GetParam(), dataPath.parent_path(), localPath); - ASSERT_THROW( - game.LoadPlugins(std::vector({nonPluginFile}), false), - std::invalid_argument); + ASSERT_THROW(game.LoadPlugins( + std::vector({nonPluginFile}), false), + std::invalid_argument); ASSERT_TRUE(game.GetLoadedPlugins().empty()); } @@ -200,8 +204,8 @@ TEST_P(GameTest, Game game = Game(GetParam(), dataPath.parent_path(), localPath); - ASSERT_NO_THROW( - game.LoadPlugins(std::vector({invalidPlugin}), false)); + ASSERT_NO_THROW(game.LoadPlugins( + std::vector({invalidPlugin}), false)); ASSERT_TRUE(game.GetLoadedPlugins().empty()); } @@ -300,20 +304,18 @@ TEST_P(GameTest, const auto sourcePluginPath = getSourcePluginsPath() / std::filesystem::u8path(blankEsm); - EXPECT_THROW( - game.LoadPlugins(std::vector({dataPluginPath.u8string(), - sourcePluginPath.u8string()}), - true), - std::invalid_argument); + EXPECT_THROW(game.LoadPlugins(std::vector( + {dataPluginPath, sourcePluginPath}), + true), + std::invalid_argument); } TEST_P(GameTest, loadPluginsShouldResolveRelativePathsRelativeToDataPath) { Game game = Game(GetParam(), dataPath.parent_path(), localPath); - const auto relativePath = - "../" + dataPath.filename().u8string() + "/" + blankEsm; + const auto relativePath = ".." / dataPath.filename() / blankEsm; - game.LoadPlugins(std::vector({relativePath}), true); + game.LoadPlugins(std::vector({relativePath}), true); EXPECT_NE(nullptr, game.GetPlugin(blankEsm)); } @@ -323,7 +325,7 @@ TEST_P(GameTest, loadPluginsShouldUseAbsolutePathsAsGiven) { const auto absolutePath = dataPath / std::filesystem::u8path(blankEsm); - game.LoadPlugins(std::vector({absolutePath.u8string()}), true); + game.LoadPlugins(std::vector({absolutePath}), true); EXPECT_NE(nullptr, game.GetPlugin(blankEsm)); } @@ -334,7 +336,7 @@ TEST_P(GameTest, sortPluginsShouldHandlePluginPathsThatAreNotJustFilenames) { const auto absolutePath = dataPath / std::filesystem::u8path(blankEsm); const auto newLoadOrder = - game.SortPlugins(std::vector({absolutePath.u8string()})); + game.SortPlugins(std::vector({absolutePath})); EXPECT_EQ(std::vector{blankEsm}, newLoadOrder); } diff --git a/src/tests/api/internals/metadata/condition_evaluator_test.h b/src/tests/api/internals/metadata/condition_evaluator_test.h index f72569ff..3c746764 100644 --- a/src/tests/api/internals/metadata/condition_evaluator_test.h +++ b/src/tests/api/internals/metadata/condition_evaluator_test.h @@ -64,7 +64,8 @@ protected: } void loadInstalledPlugins() { - std::vector plugins({ + std::vector plugins({ + // These are mostly ASCII filenames. masterFile, blankEsm, blankDifferentEsm, @@ -76,7 +77,7 @@ protected: blankDifferentMasterDependentEsp, blankPluginDependentEsp, blankDifferentPluginDependentEsp, - nonAsciiEsm, + std::filesystem::u8path(nonAsciiEsm), }); if (GetParam() == GameType::fo4 || GetParam() == GameType::tes5se) { diff --git a/src/tests/api/internals/sorting/plugin_sort_test.h b/src/tests/api/internals/sorting/plugin_sort_test.h index 8b5b7687..92a4929b 100644 --- a/src/tests/api/internals/sorting/plugin_sort_test.h +++ b/src/tests/api/internals/sorting/plugin_sort_test.h @@ -41,7 +41,8 @@ protected: cccPath_(dataPath.parent_path() / getCCCFilename()) {} void loadInstalledPlugins(Game& game, bool headersOnly) { - std::vector plugins({ + std::vector plugins({ + // These are all ASCII filenames. masterFile, blankEsm, blankDifferentEsm, diff --git a/src/tests/api/internals/sorting/plugin_sorting_data_test.h b/src/tests/api/internals/sorting/plugin_sorting_data_test.h index 1ee0d686..82fc8d48 100644 --- a/src/tests/api/internals/sorting/plugin_sorting_data_test.h +++ b/src/tests/api/internals/sorting/plugin_sorting_data_test.h @@ -37,7 +37,8 @@ protected: blankEslEsp("Blank.esl.esp") {} void loadInstalledPlugins(Game &game, bool headersOnly) { - std::vector plugins({ + std::vector plugins({ + // These are all ASCII filenames. masterFile, blankEsm, blankDifferentEsm,