Implemented C++ side of masterlist updating.

This commit is contained in:
WrinklyNinja
2014-08-14 22:25:28 +01:00
parent 22a6a1caad
commit 9fd5711bb6
2 changed files with 78 additions and 1 deletions
+77 -1
View File
@@ -167,6 +167,10 @@ namespace loot {
callback->Success("");
return true;
}
else if (request == "updateMasterlist") {
callback->Success(UpdateMasterlist());
return true;
}
else {
// May be a request with arguments.
YAML::Node req;
@@ -258,7 +262,6 @@ namespace loot {
text = yout.c_str();
}
#if defined(OS_WIN)
if (!OpenClipboard(NULL)) {
BOOST_LOG_TRIVIAL(error) << "Failed to open the Windows clipboard.";
@@ -490,6 +493,7 @@ namespace loot {
language = Language(g_app_state.GetSettings()["language"].as<string>()).Code();
else
language = Language::any;
BOOST_LOG_TRIVIAL(info) << "Using message language: " << Language(language).Name();
// The data structure is to be set as 'loot.game'.
YAML::Node gameNode;
@@ -560,8 +564,79 @@ namespace loot {
gameNode["plugins"].push_back(pluginNode);
}
//Evaluate any conditions in the global messages.
BOOST_LOG_TRIVIAL(debug) << "Evaluating global message conditions.";
list<Message> messages = g_app_state.CurrentGame().masterlist.messages;
try {
list<Message>::iterator it = messages.begin();
while (it != messages.end()) {
if (!it->EvalCondition(g_app_state.CurrentGame(), language))
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;
return JSON::stringify(gameNode);
}
std::string Handler::UpdateMasterlist() {
BOOST_LOG_TRIVIAL(debug) << "Updating and parsing masterlist.";
//Set language.
unsigned int language;
if (g_app_state.GetSettings()["language"])
language = Language(g_app_state.GetSettings()["language"].as<string>()).Code();
else
language = Language::any;
BOOST_LOG_TRIVIAL(info) << "Using message language: " << Language(language).Name();
// Update / parse masterlist.
g_app_state.CurrentGame().masterlist.Load(g_app_state.CurrentGame(), language);
// Now regenerate the JS-side masterlist data.
// The data structure is to be set as 'loot.game'.
YAML::Node gameNode;
// Store the masterlist revision and date.
gameNode["masterlist"]["revision"] = g_app_state.CurrentGame().masterlist.GetRevision(g_app_state.CurrentGame().MasterlistPath());
gameNode["masterlist"]["date"] = g_app_state.CurrentGame().masterlist.GetDate(g_app_state.CurrentGame().MasterlistPath());
for (const auto& pluginPair : g_app_state.CurrentGame().plugins) {
Plugin mlistPlugin(pluginPair.second);
mlistPlugin.MergeMetadata(g_app_state.CurrentGame().masterlist.FindPlugin(pluginPair.first));
YAML::Node pluginNode;
if (!mlistPlugin.HasNameOnly()) {
// Now add the masterlist metadata to the pluginNode.
pluginNode["masterlist"]["after"] = mlistPlugin.LoadAfter();
pluginNode["masterlist"]["req"] = mlistPlugin.Reqs();
pluginNode["masterlist"]["inc"] = mlistPlugin.Incs();
pluginNode["masterlist"]["msg"] = mlistPlugin.Messages();
pluginNode["masterlist"]["tag"] = mlistPlugin.Tags();
pluginNode["masterlist"]["dirty"] = mlistPlugin.DirtyInfo();
}
// Now merge masterlist and userlist metadata and evaluate,
// putting any resulting metadata into the base of the pluginNode.
YAML::Node derivedNode = GenerateDerivedMetadata(pluginPair.first);
for (auto it = derivedNode.begin(); it != derivedNode.end(); ++it) {
const string key = it->first.as<string>();
pluginNode[key] = it->second;
}
gameNode["plugins"].push_back(pluginNode);
}
//Evaluate any conditions in the global messages.
BOOST_LOG_TRIVIAL(debug) << "Evaluating global message conditions.";
list<Message> messages = g_app_state.CurrentGame().masterlist.messages;
@@ -592,6 +667,7 @@ namespace loot {
language = Language(g_app_state.GetSettings()["language"].as<string>()).Code();
else
language = Language::any;
BOOST_LOG_TRIVIAL(info) << "Using message language: " << Language(language).Name();
// Now rederive the displayed metadata from the masterlist and userlist.
Plugin tempPlugin(file);
+1
View File
@@ -57,6 +57,7 @@ namespace loot {
std::string GetGameTypes();
std::string GetInstalledGames();
std::string GetGameData();
std::string UpdateMasterlist();
YAML::Node Handler::GenerateDerivedMetadata(const std::string& pluginName);
YAML::Node Handler::GenerateDerivedMetadata(const Plugin& file, const Plugin& masterlist, const Plugin& userlist);