diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index 4d80422a..01a1e164 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -635,7 +635,6 @@ namespace loot { catch (...) {} } - list parsingErrors; if (isFirstLoad) { //Parse masterlist, don't update it. if (fs::exists(_lootState.CurrentGame().MasterlistPath())) { @@ -645,7 +644,7 @@ namespace loot { _lootState.CurrentGame().GetMasterlist().Load(_lootState.CurrentGame().MasterlistPath()); } catch (exception &e) { - parsingErrors.push_back(Message(Message::error, (boost::format(loc::translate( + _lootState.CurrentGame().GetMasterlist().AppendMessage(Message(Message::error, (boost::format(loc::translate( "An error occurred while parsing the masterlist: %1%. " "This probably happened because an update to LOOT changed " "its metadata syntax support. Try updating your masterlist " @@ -662,7 +661,7 @@ namespace loot { _lootState.CurrentGame().GetUserlist().Load(_lootState.CurrentGame().UserlistPath()); } catch (exception &e) { - parsingErrors.push_back(Message(Message::error, (boost::format(loc::translate( + _lootState.CurrentGame().GetUserlist().AppendMessage(Message(Message::error, (boost::format(loc::translate( "An error occurred while parsing the userlist: %1%. " "This probably happened because an update to LOOT changed " "its metadata syntax support. Your user metadata will have " @@ -699,6 +698,10 @@ namespace loot { gameNode["masterlist"]["date"] = e.what(); } + // Now store global messages. + SendProgressUpdate(frame, loc::translate("Loading general messages...")); + gameNode["globalMessages"] = GetGeneralMessages(); + // Now store plugin data. SendProgressUpdate(frame, loc::translate("Merging and evaluating plugin metadata...")); for (const auto& plugin : installed) { @@ -765,37 +768,6 @@ namespace loot { gameNode["plugins"].push_back(pluginNode); } - SendProgressUpdate(frame, loc::translate("Loading general messages...")); - BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().Name(); - - //Evaluate any conditions in the global messages. - BOOST_LOG_TRIVIAL(debug) << "Evaluating global message conditions."; - list messages = parsingErrors; - auto metadataListMessages = _lootState.CurrentGame().GetMasterlist().Messages(); - messages.insert(end(messages), - begin(metadataListMessages), - end(metadataListMessages)); - metadataListMessages = _lootState.CurrentGame().GetUserlist().Messages(); - messages.insert(messages.end(), - begin(metadataListMessages), - end(metadataListMessages)); - try { - list::iterator it = messages.begin(); - while (it != messages.end()) { - if (!it->EvalCondition(_lootState.CurrentGame(), _lootState.getLanguage().Code())) - it = messages.erase(it); - else - ++it; - } - } - catch (std::exception& e) { - BOOST_LOG_TRIVIAL(error) << "A global message contains a condition that could not be evaluated. Details: " << e.what(); - messages.push_back(Message(Message::error, (format(loc::translate("A global message contains a condition that could not be evaluated. Details: %1%")) % e.what()).str())); - } - - // Now store global messages. - gameNode["globalMessages"] = messages; - callback->Success(JSON::stringify(gameNode)); } catch (loot::error &e) { @@ -810,10 +782,8 @@ namespace loot { void Handler::UpdateMasterlist(CefRefPtr frame, CefRefPtr callback) { try { - BOOST_LOG_TRIVIAL(debug) << "Updating and parsing masterlist."; - BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().Name(); - // Update / parse masterlist. + BOOST_LOG_TRIVIAL(debug) << "Updating and parsing masterlist."; bool wasChanged = true; try { SendProgressUpdate(frame, loc::translate("Updating and parsing masterlist...")); @@ -854,6 +824,9 @@ namespace loot { gameNode["masterlist"]["date"] = e.what(); } + // Store global messages in case they have changed. + gameNode["globalMessages"] = GetGeneralMessages(); + for (const auto& plugin : _lootState.CurrentGame().GetPlugins()) { Plugin mlistPlugin(plugin); mlistPlugin.MergeMetadata(_lootState.CurrentGame().GetMasterlist().FindPlugin(plugin)); @@ -882,26 +855,6 @@ namespace loot { gameNode["plugins"].push_back(pluginNode); } - //Evaluate any conditions in the global messages. - BOOST_LOG_TRIVIAL(debug) << "Evaluating global message conditions."; - list messages = _lootState.CurrentGame().GetMasterlist().Messages(); - try { - list::iterator it = messages.begin(); - while (it != messages.end()) { - if (!it->EvalCondition(_lootState.CurrentGame(), _lootState.getLanguage().Code())) - it = messages.erase(it); - else - ++it; - } - } - catch (std::exception& e) { - BOOST_LOG_TRIVIAL(error) << "A global message contains a condition that could not be evaluated. Details: " << e.what(); - messages.push_back(Message(Message::error, (format(loc::translate("A global message contains a condition that could not be evaluated. Details: %1%")) % e.what()).str())); - } - - // Now store global messages from masterlist. - gameNode["globalMessages"] = messages; - callback->Success(JSON::stringify(gameNode)); } else @@ -991,6 +944,35 @@ namespace loot { } } + std::vector Handler::GetGeneralMessages() const { + vector messages; + auto metadataListMessages = _lootState.CurrentGame().GetMasterlist().Messages(); + messages.insert(end(messages), + begin(metadataListMessages), + end(metadataListMessages)); + metadataListMessages = _lootState.CurrentGame().GetUserlist().Messages(); + messages.insert(end(messages), + begin(metadataListMessages), + end(metadataListMessages)); + + try { + BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().Name(); + auto it = begin(messages); + while (it != end(messages)) { + if (!it->EvalCondition(_lootState.CurrentGame(), _lootState.getLanguage().Code())) + it = messages.erase(it); + else + ++it; + } + } + catch (std::exception& e) { + BOOST_LOG_TRIVIAL(error) << "A global message contains a condition that could not be evaluated. Details: " << e.what(); + messages.push_back(Message(Message::error, (format(loc::translate("A global message contains a condition that could not be evaluated. Details: %1%")) % e.what()).str())); + } + + return messages; + } + YAML::Node Handler::GenerateDerivedMetadata(const Plugin& file, const PluginMetadata& masterlist, const PluginMetadata& userlist) { BOOST_LOG_TRIVIAL(info) << "Using message language: " << _lootState.getLanguage().Name(); diff --git a/src/gui/handler.h b/src/gui/handler.h index 25fbdc2e..2d7cebf7 100644 --- a/src/gui/handler.h +++ b/src/gui/handler.h @@ -69,6 +69,7 @@ namespace loot { std::string ClearPluginMetadata(const std::string& pluginName); std::string ApplyUserEdits(const YAML::Node& pluginMetadata); + std::vector GetGeneralMessages() const; YAML::Node GenerateDerivedMetadata(const std::string& pluginName); YAML::Node GenerateDerivedMetadata(const Plugin& file, const PluginMetadata& masterlist, const PluginMetadata& userlist);