diff --git a/include/loot/game_interface.h b/include/loot/game_interface.h index a6715dbb..1252ecd0 100644 --- a/include/loot/game_interface.h +++ b/include/loot/game_interface.h @@ -147,8 +147,11 @@ public: * @brief Identify the game's main master file. * @details When sorting, LOOT always only loads the headers of the game's * main master file as a performance optimisation. + * + * A relative path is resolved relative to the game's plugins + * directory, while an absolute path is used as given. */ - virtual void IdentifyMainMasterFile(const std::string& masterFile) = 0; + virtual void IdentifyMainMasterFile(const std::filesystem::path& masterFile) = 0; /** * @brief Calculates a new load order for the game's installed plugins diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index 18b8cb04..52a0dca2 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -161,35 +161,6 @@ std::vector FindArchives( return archivePaths; } - -std::filesystem::path FindPlugin( - GameType gameType, - const std::filesystem::path& dataPath, - const std::vector& additionalDataPaths, - const std::string& pluginName) { - const auto relativePath = std::filesystem::u8path(pluginName); - - const auto finder = [&](const auto& path) { - const auto resolvedPath = ResolvePluginPath(gameType, path, relativePath); - return std::filesystem::exists(resolvedPath); - }; - - if (gameType == GameType::openmw) { - const auto it = std::find_if( - additionalDataPaths.rbegin(), additionalDataPaths.rend(), finder); - if (it != additionalDataPaths.rend()) { - return *it; - } - } else { - const auto it = std::find_if( - additionalDataPaths.begin(), additionalDataPaths.end(), finder); - if (it != additionalDataPaths.end()) { - return *it; - } - } - - return dataPath / relativePath; -} } namespace loot { @@ -295,12 +266,6 @@ void Game::LoadPlugins(const std::vector& pluginPaths, logger->trace("Starting plugin loading."); } - const auto masterPath = GetType() == GameType::openmw - ? FindPlugin(GetType(), - DataPath(), - GetAdditionalDataPaths(), - masterFilename_) - : DataPath() / u8path(masterFilename_); std::for_each( std::execution::par_unseq, pluginPaths.begin(), @@ -312,7 +277,7 @@ void Game::LoadPlugins(const std::vector& pluginPaths, const bool loadHeader = loadHeadersOnly || - loot::equivalent(resolvedPluginPath, masterPath); + loot::equivalent(resolvedPluginPath, masterFilePath_); cache_.AddPlugin( Plugin(GetType(), cache_, resolvedPluginPath, loadHeader)); @@ -352,8 +317,8 @@ std::vector Game::GetLoadedPlugins() const { return interfacePointers; } -void Game::IdentifyMainMasterFile(const std::string& masterFile) { - masterFilename_ = masterFile; +void Game::IdentifyMainMasterFile(const std::filesystem::path& masterFile) { + masterFilePath_ = ResolvePluginPath(GetType(), DataPath(), masterFile); } std::vector Game::SortPlugins( diff --git a/src/api/game/game.h b/src/api/game/game.h index 0a00ff1f..5c0c48a2 100644 --- a/src/api/game/game.h +++ b/src/api/game/game.h @@ -75,7 +75,7 @@ public: std::vector GetLoadedPlugins() const override; - void IdentifyMainMasterFile(const std::string& masterFile) override; + void IdentifyMainMasterFile(const std::filesystem::path& masterFile) override; std::vector SortPlugins( const std::vector& pluginPaths) override; @@ -103,7 +103,7 @@ private: std::shared_ptr conditionEvaluator_; ApiDatabase database_; - std::string masterFilename_; + std::filesystem::path masterFilePath_; std::vector additionalDataPaths_; }; diff --git a/src/tests/api/internals/metadata/condition_evaluator_test.h b/src/tests/api/internals/metadata/condition_evaluator_test.h index 2daa1e7a..219e653c 100644 --- a/src/tests/api/internals/metadata/condition_evaluator_test.h +++ b/src/tests/api/internals/metadata/condition_evaluator_test.h @@ -68,7 +68,7 @@ protected: plugins.push_back(blankEsl); } - game_.IdentifyMainMasterFile(masterFile); + game_.IdentifyMainMasterFile(std::filesystem::u8path(masterFile)); game_.LoadCurrentLoadOrderState(); game_.LoadPlugins(plugins, true); } diff --git a/src/tests/api/internals/sorting/plugin_sort_test.h b/src/tests/api/internals/sorting/plugin_sort_test.h index 44e3fcf6..890ed793 100644 --- a/src/tests/api/internals/sorting/plugin_sort_test.h +++ b/src/tests/api/internals/sorting/plugin_sort_test.h @@ -51,7 +51,7 @@ protected: } } - game.IdentifyMainMasterFile(masterFile); + game.IdentifyMainMasterFile(std::filesystem::u8path(masterFile)); game.LoadCurrentLoadOrderState(); game.LoadPlugins(plugins, headersOnly); } 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 e0198b4e..790a74ca 100644 --- a/src/tests/api/internals/sorting/plugin_sorting_data_test.h +++ b/src/tests/api/internals/sorting/plugin_sorting_data_test.h @@ -46,7 +46,7 @@ protected: } } - game.IdentifyMainMasterFile(masterFile); + game.IdentifyMainMasterFile(std::filesystem::u8path(masterFile)); game.LoadCurrentLoadOrderState(); game.LoadPlugins(plugins, headersOnly); }