diff --git a/src/gui/query/cancel_sort_query.h b/src/gui/query/cancel_sort_query.h index b75dc7c7..307861f4 100644 --- a/src/gui/query/cancel_sort_query.h +++ b/src/gui/query/cancel_sort_query.h @@ -33,7 +33,7 @@ namespace loot { class CancelSortQuery : public MetadataQuery { public: CancelSortQuery(LootState& state) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), state_(state) {} std::string executeLogic() { diff --git a/src/gui/query/clear_all_metadata_query.h b/src/gui/query/clear_all_metadata_query.h index 0eb8ff8e..cd056128 100644 --- a/src/gui/query/clear_all_metadata_query.h +++ b/src/gui/query/clear_all_metadata_query.h @@ -33,7 +33,7 @@ namespace loot { class ClearAllMetadataQuery : public MetadataQuery { public: ClearAllMetadataQuery(LootState& state) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), game_(state.getCurrentGame()) {} std::string executeLogic() { diff --git a/src/gui/query/clear_plugin_metadata_query.h b/src/gui/query/clear_plugin_metadata_query.h index 3aa16252..c8d03a44 100644 --- a/src/gui/query/clear_plugin_metadata_query.h +++ b/src/gui/query/clear_plugin_metadata_query.h @@ -33,7 +33,7 @@ namespace loot { class ClearPluginMetadataQuery : public MetadataQuery { public: ClearPluginMetadataQuery(LootState& state, const std::string& pluginName) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), game_(state.getCurrentGame()), pluginName_(pluginName) {} diff --git a/src/gui/query/editor_closed_query.h b/src/gui/query/editor_closed_query.h index 67610d73..5e1a3db9 100644 --- a/src/gui/query/editor_closed_query.h +++ b/src/gui/query/editor_closed_query.h @@ -32,7 +32,7 @@ namespace loot { class EditorClosedQuery : public MetadataQuery { public: EditorClosedQuery(LootState& state, YAML::Node metadata) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), state_(state), metadata_(metadata) {} std::string executeLogic() { diff --git a/src/gui/query/get_conflicting_plugins_query.h b/src/gui/query/get_conflicting_plugins_query.h index 526e1997..8a67a021 100644 --- a/src/gui/query/get_conflicting_plugins_query.h +++ b/src/gui/query/get_conflicting_plugins_query.h @@ -33,7 +33,7 @@ namespace loot { class GetConflictingPluginsQuery : public MetadataQuery { public: GetConflictingPluginsQuery(LootState& state, const std::string& pluginName) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), game_(state.getCurrentGame()), pluginName_(pluginName) {} diff --git a/src/gui/query/get_game_data_query.h b/src/gui/query/get_game_data_query.h index 120ea023..512a2638 100644 --- a/src/gui/query/get_game_data_query.h +++ b/src/gui/query/get_game_data_query.h @@ -37,7 +37,7 @@ namespace loot { class GetGameDataQuery : public MetadataQuery { public: GetGameDataQuery(LootState& state, CefRefPtr frame) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), state_(state), frame_(frame) {} @@ -49,11 +49,13 @@ public: /* If the game's plugins object is empty, this is the first time loading the game data, so also load the metadata lists. */ - if (state_.getCurrentGame().GetPlugins().empty()) - loadMetadataLists(); + bool isFirstLoad = state_.getCurrentGame().GetPlugins().empty(); state_.getCurrentGame().LoadAllInstalledPlugins(true); + if (isFirstLoad) + loadMetadataLists(); + //Sort plugins into their load order. std::vector installed; std::vector loadOrder = state_.getCurrentGame().GetLoadOrder(); diff --git a/src/gui/query/metadata_query.h b/src/gui/query/metadata_query.h index 07175510..26a80291 100644 --- a/src/gui/query/metadata_query.h +++ b/src/gui/query/metadata_query.h @@ -35,18 +35,17 @@ along with LOOT. If not, see namespace loot { class MetadataQuery : public Query { protected: - MetadataQuery(Game& game, const LanguageCode language) : - game_(game), language_(language) {} + MetadataQuery(LootState& state) : state_(state) {} std::vector getGeneralMessages() { std::vector messages; - appendMessages(messages, game_.GetMasterlist().Messages()); - appendMessages(messages, game_.GetUserlist().Messages()); - appendMessages(messages, game_.GetMessages()); + appendMessages(messages, state_.getCurrentGame().GetMasterlist().Messages()); + appendMessages(messages, state_.getCurrentGame().GetUserlist().Messages()); + appendMessages(messages, state_.getCurrentGame().GetMessages()); evaluateMessageConditions(messages); - return toSimpleMessages(messages, language_); + return toSimpleMessages(messages, state_.getLanguage().GetCode()); } YAML::Node generateDerivedMetadata(const Plugin& file, @@ -65,9 +64,9 @@ protected: YAML::Node generateDerivedMetadata(const std::string& pluginName) { // Now rederive the displayed metadata from the masterlist and userlist. try { - auto plugin = game_.GetPlugin(pluginName); - PluginMetadata master(game_.GetMasterlist().FindPlugin(plugin)); - PluginMetadata user(game_.GetUserlist().FindPlugin(plugin)); + auto plugin = state_.getCurrentGame().GetPlugin(pluginName); + PluginMetadata master(state_.getCurrentGame().GetMasterlist().FindPlugin(plugin)); + PluginMetadata user(state_.getCurrentGame().GetUserlist().FindPlugin(plugin)); return generateDerivedMetadata(plugin, master, user); } catch (...) { @@ -85,7 +84,7 @@ private: try { auto it = begin(messages); while (it != end(messages)) { - if (!it->EvalCondition(game_)) + if (!it->EvalCondition(state_.getCurrentGame())) it = messages.erase(it); else ++it; @@ -114,7 +113,7 @@ private: //Evaluate any conditions BOOST_LOG_TRIVIAL(trace) << "Evaluate conditions for merged plugin data."; try { - plugin.EvalAllConditions(game_); + plugin.EvalAllConditions(state_.getCurrentGame()); } catch (std::exception& e) { BOOST_LOG_TRIVIAL(error) << "\"" << plugin.Name() << "\" contains a condition that could not be evaluated. Details: " << e.what(); std::vector messages(plugin.Messages()); @@ -123,20 +122,20 @@ private: } //Also check install validity. - plugin.CheckInstallValidity(game_); + plugin.CheckInstallValidity(state_.getCurrentGame()); } YAML::Node toYaml(const Plugin& plugin) { - BOOST_LOG_TRIVIAL(info) << "Using message language: " << Language(language_).GetName(); + BOOST_LOG_TRIVIAL(info) << "Using message language: " << state_.getLanguage().GetName(); YAML::Node pluginNode; pluginNode["name"] = plugin.Name(); pluginNode["priority"] = plugin.LocalPriority().getValue(); pluginNode["globalPriority"] = plugin.GlobalPriority().getValue(); - pluginNode["messages"] = plugin.SimpleMessages(language_); + pluginNode["messages"] = plugin.SimpleMessages(state_.getLanguage().GetCode()); pluginNode["tags"] = plugin.Tags(); pluginNode["isDirty"] = !plugin.DirtyInfo().empty(); - pluginNode["loadOrderIndex"] = game_.GetActiveLoadOrderIndex(plugin.Name()); + pluginNode["loadOrderIndex"] = state_.getCurrentGame().GetActiveLoadOrderIndex(plugin.Name()); if (!plugin.CleanInfo().empty()) { pluginNode["cleanedWith"] = plugin.CleanInfo().begin()->CleaningUtility(); @@ -147,8 +146,7 @@ private: return pluginNode; } - Game& game_; - const LanguageCode language_; + LootState& state_; }; } diff --git a/src/gui/query/sort_plugins_query.h b/src/gui/query/sort_plugins_query.h index d3c17f56..0bc13e88 100644 --- a/src/gui/query/sort_plugins_query.h +++ b/src/gui/query/sort_plugins_query.h @@ -35,7 +35,7 @@ namespace loot { class SortPluginsQuery : public MetadataQuery { public: SortPluginsQuery(LootState& state, CefRefPtr frame) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), state_(state), frame_(frame) {} diff --git a/src/gui/query/update_masterlist_query.h b/src/gui/query/update_masterlist_query.h index 6d786a27..e3d19517 100644 --- a/src/gui/query/update_masterlist_query.h +++ b/src/gui/query/update_masterlist_query.h @@ -33,7 +33,7 @@ namespace loot { class UpdateMasterlistQuery : public MetadataQuery { public: UpdateMasterlistQuery(LootState& state) : - MetadataQuery(state.getCurrentGame(), state.getLanguage().GetCode()), + MetadataQuery(state), game_(state.getCurrentGame()) {} std::string executeLogic() {