diff --git a/src/api/api.cpp b/src/api/api.cpp index dd6dc142..b042ff02 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -130,6 +130,21 @@ char * ToNewCString(std::string str) { return strcpy(p, str.c_str()); } +bool IsDirtyMessage(std::string message) { + const std::string local[3] = { + "Contains dirty edits: ", + "Contiene ediciones sucia: ", + "\"Грязные\" правки: " + }; + + for (int i=0; i < 3; ++i) { + if (boost::icontains(message, local[i])) + return true; + } + + return false; +} + ////////////////////////////// // Error Handling Functions ////////////////////////////// @@ -251,7 +266,8 @@ BOSS_API unsigned int boss_load_lists (boss_db db, const char * const masterlist temp = tempNode["plugins"].as< std::list >(); } else { boost::filesystem::path p(masterlistPath); - Loadv2Masterlist(p, temp); + std::list filler; + Loadv2Masterlist(p, temp, filler); } } catch (YAML::Exception& e) { extMessageStr = e.what(); @@ -604,10 +620,10 @@ BOSS_API unsigned int boss_get_dirty_message (boss_db db, const char * const plu pluginMessages.insert(pluginMessages.end(), temp.begin(), temp.end()); } - //Now discard any that aren't warnings about dirty edits. + //Now discard any that aren't about dirty edits. std::list::iterator it=pluginMessages.begin(); while (it != pluginMessages.end()) { - if (it->ChooseContent(boss::g_lang_any).Str().find("dirty edits") == std::string::npos) + if (IsDirtyMessage(it->ChooseContent(boss::g_lang_any).Str())) it = pluginMessages.erase(it); } @@ -653,10 +669,7 @@ BOSS_API unsigned int boss_write_minimal_list (boss_db db, const char * const ou std::list messages = it->Messages(), newMessages; for (std::list::iterator messageIter = messages.begin(); messageIter != messages.end(); ++messageIter) { if (messageIter->Type() == boss_message_warn) { - const std::string content = messageIter->ChooseContent(boss::g_lang_any).Str(); - if (boost::contains(content, "Do not clean")) - newMessages.push_back(*messageIter); - else if (boost::contains(content, "Contains dirty edits")) + if (IsDirtyMessage(messageIter->ChooseContent(boss::g_lang_any).Str())) newMessages.push_back(*messageIter); } } diff --git a/src/backend/generators.h b/src/backend/generators.h index b8a988ef..2d3737ff 100644 --- a/src/backend/generators.h +++ b/src/backend/generators.h @@ -588,10 +588,7 @@ namespace YAML { else out << Key << "type" << Value << "error"; - if (rhs.Content().size() == 1) - out << Key << "content" << Value << rhs.Content().front(); - else - out << Key << "content" << Value << rhs.Content(); + out << Key << "content" << Value << rhs.Content(); if (!rhs.Condition().empty()) out << Key << "condition" << Value << rhs.Condition(); diff --git a/src/backend/legacy-parser.h b/src/backend/legacy-parser.h index a62f8c4f..469266d7 100644 --- a/src/backend/legacy-parser.h +++ b/src/backend/legacy-parser.h @@ -25,8 +25,10 @@ $Revision: 2188 $, $Date: 2011-01-20 10:05:16 +0000 (Thu, 20 Jan 2011) $ */ -#ifndef __BOSS_GRAMMAR_H__ -#define __BOSS_GRAMMAR_H__ +#ifndef __BOSS_LEGACY_PARSER__ +#define __BOSS_LEGACY_PARSER__ + +// This file holds the code necessary for inputting a v2 masterlist and getting a list of plugins and a list of global messages from it. #ifndef BOOST_SPIRIT_UNICODE #define BOOST_SPIRIT_UNICODE @@ -57,6 +59,11 @@ namespace boss { namespace unicode = boost::spirit::unicode; namespace phoenix = boost::phoenix; + //Message types for those that will be converted, but need identifying in the interim. Must not conflict with the values for the global types. + unsigned int message_inc = 1000; + unsigned int message_req = 1001; + unsigned int message_dirty = 1002; + /////////////////////////////// // Keyword structures @@ -67,9 +74,9 @@ namespace boss { add //New Message keywords. ("say",g_message_say) ("tag",g_message_tag) - ("req",g_message_say) - ("inc", g_message_say) - ("dirty",g_message_warn) + ("req",message_req) + ("inc", message_inc) + ("dirty",message_dirty) ("warn",g_message_warn) ("error",g_message_error) ; @@ -615,7 +622,7 @@ namespace boss { //BOSSv2 supports Chinese and German in addition to English, Russian and Spanish, but they aren't used in any of the masterlists so don't bother mapping them. unsigned int langInt; - if (lang == "english") + if (lang == "english" || lang == "chinese" || lang == "german") langInt = g_lang_english; else if (lang == "russian") langInt = g_lang_russian; @@ -624,15 +631,54 @@ namespace boss { else langInt = g_lang_any; - //Also convert warning messages about dirty edits that say "do not clean" to notes. - if (type == g_message_warn && content.find("dirty edits") != std::string::npos) { - std::string search = "do not clean"; - const boost::iterator_range ir1(content.begin(), content.end()); - const boost::iterator_range ir2(search.begin(), search.end()); + /* Now convert the temporary message types into say or warning messages as appropriate. Translations were obtained from the BOSSv2 translation files. Thanks to the translators for them. */ - if (boost::ifind_first(ir1, ir2)) + if (type == message_dirty) { + + std::string search; + std::string opener; + if (langInt == g_lang_english || langInt == g_lang_any) { + search = "do not clean"; + opener = "Contains dirty edits: "; + } else if (langInt == g_lang_spanish) { + search = "no se limpia"; + opener = "Contiene ediciones sucia: "; + } else if (langInt == g_lang_russian) { + search = "Не очищать"; + opener = "\"Грязные\" правки: "; + } + + if (boost::icontains(content, search)) type = g_message_say; + else + type = g_message_warn; + + content = opener + content; + } else if (type == message_req) { + type = g_message_say; + + std::string opener; + if (langInt == g_lang_english || langInt == g_lang_any) + opener = "Requires: "; + else if (langInt == g_lang_spanish) + opener = "Requiere: "; + else if (langInt == g_lang_russian) + opener = "Требуется: "; + + content = opener + content; + } else if (type == message_inc) { + type = g_message_say; + + std::string opener; + if (langInt == g_lang_english || langInt == g_lang_any) + opener = "Incompatible with: "; + else if (langInt == g_lang_spanish) + opener = "Incompatible con: "; + else if (langInt == g_lang_russian) + opener = "Несовместим с: "; + + content = opener + content; } std::vector mc_vec; diff --git a/src/backend/parsers.h b/src/backend/parsers.h index f073c33f..96933534 100644 --- a/src/backend/parsers.h +++ b/src/backend/parsers.h @@ -113,14 +113,14 @@ namespace YAML { Node node; node["str"] = rhs.Str(); node["lang"] = boss::GetLangString(rhs.Language()); - + return node; } static bool decode(const Node& node, boss::MessageContent& rhs) { - if (!node["str"] || !node["lang"]) + if (!node.IsMap() || !node["str"] || !node["lang"]) return false; - + std::string str = node["str"].as(); unsigned int lang = boss::GetLangNum(node["lang"].as()); @@ -143,7 +143,7 @@ namespace YAML { node["type"] = "warn"; else node["type"] = "error"; - + return node; } @@ -177,10 +177,11 @@ namespace YAML { if (it->Language() == boss::g_lang_english) found = true; } - if (!found) - return false; + //Commented out because the auto-converted masterlist has localisations as separate messages and so will always fail. + // if (!found) + // return false; } - + std::string condition; if (node["condition"]) condition = node["condition"].as(); @@ -242,7 +243,7 @@ namespace YAML { rhs = boss::Tag(tag.substr(1), false, condition); else rhs = boss::Tag(tag, true, condition); - + return true; } };