diff --git a/src/api/api.cpp b/src/api/api.cpp index 851b381d..8ee77a27 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -137,20 +137,6 @@ 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 @@ -493,9 +479,6 @@ BOSS_API unsigned int boss_get_plugin_tags (boss_db db, const char * const plugi *numTags_added = 0; *numTags_removed = 0; - if (db->bashTagMap.empty()) - return boss_error_no_tag_map; - boost::unordered_set tagsAdded, tagsRemoved; std::list::iterator pluginIt = std::find(db->metadata.begin(), db->metadata.end(), boss::Plugin(plugin)); if (pluginIt != db->metadata.end()) { @@ -513,6 +496,11 @@ BOSS_API unsigned int boss_get_plugin_tags (boss_db db, const char * const plugi *userlistModified = true; } + if ((!tagsAdded.empty() || !tagsRemoved.empty()) && db->bashTagMap.empty()) { + extMessageStr = "No Bash Tag map has been previously generated."; + return boss_error_no_tag_map; + } + std::vector tagsAddedIDs, tagsRemovedIDs; for (boost::unordered_set::const_iterator it=tagsAdded.begin(), endIt=tagsAdded.end(); it != endIt; ++it) { boost::unordered_map::const_iterator mapIter = db->bashTagMap.find(*it); @@ -605,58 +593,26 @@ BOSS_API unsigned int boss_get_plugin_messages (boss_db db, const char * const p return boss_ok; } -// Outputs the first warning message found for the given plugin that warns about dirty edits, and also whether the plugin should be cleaned or not, or if BOSS doesn't know (ie. no message, in which case *message == NULL). needsCleaning is one of the plugin cleanliness codes above. -BOSS_API unsigned int boss_get_dirty_message (boss_db db, const char * const plugin, - boss_message * const message, - unsigned int * const needsCleaning) { - if (db == NULL || plugin == NULL || message == NULL || needsCleaning == NULL) +BOSS_API unsigned int boss_get_dirty_info(boss_db db, const char * const plugin, unsigned int * const needsCleaning) { + if (db == NULL || plugin == NULL || needsCleaning == NULL) return boss_error_invalid_args; - //Clear existing allocation. - if (db->extMessage.message != NULL) { - delete [] db->extMessage.message; - } - - *message = db->extMessage; *needsCleaning = boss_needs_cleaning_unknown; - //Get all messages. - std::list pluginMessages; + //Get all dirty info. + std::set dirtyInfo; std::list::iterator pluginIt = std::find(db->metadata.begin(), db->metadata.end(), boss::Plugin(plugin)); if (pluginIt != db->metadata.end()) { - pluginMessages = pluginIt->Messages(); + dirtyInfo = pluginIt->DirtyInfo(); } - pluginIt = std::find(db->userMetadata.begin(), db->userMetadata.end(), boss::Plugin(plugin)); if (pluginIt != db->userMetadata.end()) { - std::list temp = pluginIt->Messages(); - pluginMessages.insert(pluginMessages.end(), temp.begin(), temp.end()); + std::set temp = pluginIt->DirtyInfo(); + dirtyInfo.insert(temp.begin(), temp.end()); } - //Now discard any that aren't about dirty edits. - std::list::iterator it=pluginMessages.begin(); - while (it != pluginMessages.end()) { - if (IsDirtyMessage(it->ChooseContent(boss::g_lang_any).Str())) - it = pluginMessages.erase(it); - } - - if (!pluginMessages.empty()) { - boss::Message dirtyMessage = pluginMessages.front(); - - try { - db->extMessage.type = dirtyMessage.Type(); - db->extMessage.message = ToNewCString(dirtyMessage.ChooseContent(boss::g_lang_any).Str()); - } catch (std::bad_alloc& e) { - extMessageStr = e.what(); - return boss_error_no_mem; - } - - *message = db->extMessage; - if (dirtyMessage.Type() == boss_message_say) - *needsCleaning = boss_needs_cleaning_no; - else - *needsCleaning = boss_needs_cleaning_yes; - + if (!dirtyInfo.empty()) { + *needsCleaning = boss_needs_cleaning_yes; } return boss_ok; @@ -678,15 +634,7 @@ BOSS_API unsigned int boss_write_minimal_list (boss_db db, const char * const ou for (std::list::iterator it=temp.begin(), endIt=temp.end(); it != endIt; ++it) { boss::Plugin p(it->Name()); p.Tags(it->Tags()); - - std::list messages = it->Messages(), newMessages; - for (std::list::iterator messageIter = messages.begin(); messageIter != messages.end(); ++messageIter) { - if (messageIter->Type() == boss_message_warn) { - if (IsDirtyMessage(messageIter->ChooseContent(boss::g_lang_any).Str())) - newMessages.push_back(*messageIter); - } - } - it->Messages(newMessages); + p.DirtyInfo(it->DirtyInfo()); *it = p; } diff --git a/src/api/api.h b/src/api/api.h index 8af9b8fe..22a495d4 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -336,21 +336,18 @@ BOSS_API unsigned int boss_get_plugin_messages (boss_db db, const char * const p /** @brief Determines the database's knowledge of a plugin's dirtiness. - - @details Outputs the first message associated with the specified plugin that is about dirty edits, and also whether the plugin should be cleaned or not, or if no data is available. + @details Outputs whether the plugin should be cleaned or not, or if no data is available. @param db The database the function acts on. @param plugin The plugin to look up dirty status information for. - @param message A pointer to the message outputted. @param needsCleaning A pointer to a plugin cleanliness code. - @returns A return code. + @returns A return code. */ -BOSS_API unsigned int boss_get_dirty_message (boss_db db, const char * const plugin, - boss_message * const message, - unsigned int * const needsCleaning); +BOSS_API unsigned int boss_get_dirty_info (boss_db db, const char * const plugin, + unsigned int * const needsCleaning); /** - @brief Writes a minimal metadata file that only contains plugins with Bash Tag suggestions and/or warning messages about dirtiness, plus the suggestions and messages themselves. + @brief Writes a minimal metadata file that only contains plugins with Bash Tag suggestions and/or dirty info, plus the suggestions and info themselves. @param db The database the function acts on. @param outputFile The path to which the file shall be written. @param overwrite If `false` and `outputFile` already exists, no data will be written. Otherwise, data will be written.