From 7bbce34702384ad9ed00e3bce908d9d5e306b489 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 7 Feb 2017 18:54:04 +0000 Subject: [PATCH] Don't load plugins twice when sorting The API loads the plugins it's given to sort. --- src/gui/query/sort_plugins_query.h | 4 ---- src/gui/state/game.cpp | 36 +++++++++++++++--------------- src/gui/state/game.h | 1 + 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/gui/query/sort_plugins_query.h b/src/gui/query/sort_plugins_query.h index 991a590c..e1562c0c 100644 --- a/src/gui/query/sort_plugins_query.h +++ b/src/gui/query/sort_plugins_query.h @@ -44,10 +44,6 @@ public: std::string executeLogic() { BOOST_LOG_TRIVIAL(info) << "Beginning sorting operation."; - // Always reload all the plugins. - sendProgressUpdate(frame_, boost::locale::translate("Loading plugin contents...")); - state_.getCurrentGame().LoadAllInstalledPlugins(false); - //Sort plugins into their load order. sendProgressUpdate(frame_, boost::locale::translate("Sorting load order...")); std::vector plugins = state_.getCurrentGame().SortPlugins(); diff --git a/src/gui/state/game.cpp b/src/gui/state/game.cpp index 2fac0a50..d29bb560 100644 --- a/src/gui/state/game.cpp +++ b/src/gui/state/game.cpp @@ -204,19 +204,7 @@ void Game::RedatePlugins() { } void Game::LoadAllInstalledPlugins(bool headersOnly) { - std::vector plugins; - - BOOST_LOG_TRIVIAL(trace) << "Scanning for plugins in " << this->DataPath(); - for (fs::directory_iterator it(this->DataPath()); it != fs::directory_iterator(); ++it) { - if (fs::is_regular_file(it->status()) && gameHandle_->IsValidPlugin(it->path().filename().string())) { - string name = it->path().filename().string(); - BOOST_LOG_TRIVIAL(info) << "Found plugin: " << name; - - plugins.push_back(name); - } - } - - gameHandle_->LoadPlugins(plugins, headersOnly); + gameHandle_->LoadPlugins(GetInstalledPluginNames(), headersOnly); pluginsFullyLoaded_ = !headersOnly; } @@ -277,12 +265,8 @@ short Game::GetActiveLoadOrderIndex(const std::string& pluginName, const std::ve } std::vector Game::SortPlugins() { - std::vector plugins; + std::vector plugins = GetInstalledPluginNames(); try { - for (const auto& plugin : gameHandle_->GetLoadedPlugins()) { - plugins.push_back(plugin->GetName()); - } - // Clear any existing game-specific messages, as these only relate to // state that has been changed by sorting. ClearMessages(); @@ -465,6 +449,22 @@ void Game::BackupLoadOrder(const std::vector& loadOrder, out << plugin << std::endl; } +std::vector Game::GetInstalledPluginNames() { + std::vector plugins; + + BOOST_LOG_TRIVIAL(trace) << "Scanning for plugins in " << this->DataPath(); + for (fs::directory_iterator it(this->DataPath()); it != fs::directory_iterator(); ++it) { + if (fs::is_regular_file(it->status()) && gameHandle_->IsValidPlugin(it->path().filename().string())) { + string name = it->path().filename().string(); + BOOST_LOG_TRIVIAL(info) << "Found plugin: " << name; + + plugins.push_back(name); + } + } + + return plugins; +} + #ifdef _WIN32 std::string Game::RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value) { HKEY hKey = NULL; diff --git a/src/gui/state/game.h b/src/gui/state/game.h index e245b5e2..c4d26ffe 100644 --- a/src/gui/state/game.h +++ b/src/gui/state/game.h @@ -97,6 +97,7 @@ private: static boost::filesystem::path DetectGamePath(const GameSettings& gameSettings); static void BackupLoadOrder(const std::vector& loadOrder, const boost::filesystem::path& backupDirectory); + std::vector GetInstalledPluginNames(); boost::filesystem::path lootDataPath_;