From ca907e633cf66e863c1580f71ddb68dbfc04398f Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Sun, 17 Aug 2014 08:46:56 +0100 Subject: [PATCH] Conflicts filter is now case-insensitive. Also fixed lowercasing for non-ASCII strings. Not that it really matters because they don't then get displayed to the UI, but it might conceivably cause other problems. --- src/backend/game.cpp | 7 ++++--- src/backend/graph.cpp | 14 -------------- src/backend/metadata.cpp | 10 +++++----- src/gui/handler.cpp | 18 +++++++++--------- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/backend/game.cpp b/src/backend/game.cpp index 25afaa11..df33dcf7 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -447,14 +447,14 @@ namespace loot { activePlugins.clear(); for (size_t i=0; i < pluginArrSize; ++i) { - activePlugins.insert(boost::to_lower_copy(string(pluginArr[i]))); + activePlugins.insert(boost::locale::to_lower(string(pluginArr[i]))); } lo_destroy_handle(gh); } bool Game::IsActive(const std::string& plugin) const { - return activePlugins.find(boost::to_lower_copy(plugin)) != activePlugins.end(); + return activePlugins.find(boost::locale::to_lower(plugin)) != activePlugins.end(); } void Game::GetLoadOrder(std::list& loadOrder) const { @@ -679,7 +679,8 @@ namespace loot { BOOST_LOG_TRIVIAL(info) << "Found plugin: " << pluginPair.first; - auto plugin = plugins.emplace(pluginPair.first, Plugin(pluginPair.first)); + //Insert the lowercased name as a key for case-insensitive matching. + auto plugin = plugins.emplace(boost::locale::to_lower(pluginPair.first), Plugin(pluginPair.first)); if (pluginPair.second > meanFileSize) { BOOST_LOG_TRIVIAL(trace) << "Creating individual loading thread for: " << pluginPair.first; diff --git a/src/backend/graph.cpp b/src/backend/graph.cpp index fd5bb6c8..e21230cc 100644 --- a/src/backend/graph.cpp +++ b/src/backend/graph.cpp @@ -114,20 +114,6 @@ namespace loot { plugins.push_back(graph[vertex]); } return plugins; - - - //Now sort exist plugins list according to order in tempPlugins. - /*plugins.sort([tempPlugins](const Plugin& first, const Plugin& second){ - //Find both plugins, and compare distances from beginning. - auto fIt = find(tempPlugins.begin(), tempPlugins.end(), first); - auto sIt = find(tempPlugins.begin(), tempPlugins.end(), second); - - if (fIt == tempPlugins.end() || sIt == tempPlugins.end()) - return false; - - return distance(tempPlugins.begin(), fIt) < distance(tempPlugins.begin(), sIt); - }); - */ } void CheckForCycles(const PluginGraph& graph) { diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index 1bad1066..605b0b77 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -124,7 +124,7 @@ namespace loot { BOOST_LOG_TRIVIAL(trace) << "Evaluating condition: " << _condition; - unordered_map::const_iterator it = game.conditionCache.find(boost::to_lower_copy(_condition)); + unordered_map::const_iterator it = game.conditionCache.find(boost::locale::to_lower(_condition)); if (it != game.conditionCache.end()) return it->second; @@ -150,7 +150,7 @@ namespace loot { throw loot::error(loot::error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\".")) % _condition).str()); } - game.conditionCache.emplace(boost::to_lower_copy(_condition), eval); + game.conditionCache.emplace(boost::locale::to_lower(_condition), eval); return eval; } @@ -611,15 +611,15 @@ namespace loot { //First need to get plugin's CRC. uint32_t crc = 0; - unordered_map::iterator it = game.crcCache.find(boost::to_lower_copy(name)); + unordered_map::iterator it = game.crcCache.find(boost::locale::to_lower(name)); if (it != game.crcCache.end()) crc = it->second; else if (boost::filesystem::exists(game.DataPath() / name)) { crc = GetCrc32(game.DataPath() / name); - game.crcCache.emplace(boost::to_lower_copy(name), crc); + game.crcCache.emplace(boost::locale::to_lower(name), crc); } else if (boost::filesystem::exists(game.DataPath() / (name + ".ghost"))) { crc = GetCrc32(game.DataPath() / (name + ".ghost")); - game.crcCache.emplace(boost::to_lower_copy(name), crc); + game.crcCache.emplace(boost::locale::to_lower(name), crc); } else _dirtyInfo.clear(); diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index ea75f0b6..7efc1f7a 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -247,7 +247,7 @@ namespace loot { const string pluginName = req["args"][0].as(); BOOST_LOG_TRIVIAL(debug) << "Searching for plugins that conflict with " << pluginName; - auto pluginIt = g_app_state.CurrentGame().plugins.find(pluginName); + auto pluginIt = g_app_state.CurrentGame().plugins.find(boost::locale::to_lower(pluginName)); // Checking for FormID overlap will only work if the plugins have been loaded, so check if // the first plugin has any FormIDs in memory, and if not load all plugins. @@ -258,8 +258,8 @@ namespace loot { if (pluginIt != g_app_state.CurrentGame().plugins.end()) { for (const auto& pluginPair : g_app_state.CurrentGame().plugins) { if (pluginIt->second.DoFormIDsOverlap(pluginPair.second)) { - BOOST_LOG_TRIVIAL(debug) << "Found conflicting plugin: " << pluginPair.first; - conflictingPlugins.emplace(pluginPair.first, pluginPair.second.Crc()); + BOOST_LOG_TRIVIAL(debug) << "Found conflicting plugin: " << pluginPair.second.Name(); + conflictingPlugins.emplace(pluginPair.second.Name(), pluginPair.second.Crc()); } } } @@ -511,7 +511,7 @@ namespace loot { list loadOrder; g_app_state.CurrentGame().GetLoadOrder(loadOrder); for (const auto &pluginName : loadOrder) { - const auto pos = g_app_state.CurrentGame().plugins.find(pluginName); + const auto pos = g_app_state.CurrentGame().plugins.find(boost::locale::to_lower(pluginName)); if (pos != g_app_state.CurrentGame().plugins.end()) installed.push_back(pos->second); @@ -657,7 +657,7 @@ namespace loot { for (const auto& pluginPair : g_app_state.CurrentGame().plugins) { Plugin mlistPlugin(pluginPair.second); - mlistPlugin.MergeMetadata(g_app_state.CurrentGame().masterlist.FindPlugin(pluginPair.first)); + mlistPlugin.MergeMetadata(g_app_state.CurrentGame().masterlist.FindPlugin(pluginPair.second.Name())); YAML::Node pluginNode; if (!mlistPlugin.HasNameOnly()) { @@ -672,7 +672,7 @@ namespace loot { // Now merge masterlist and userlist metadata and evaluate, // putting any resulting metadata into the base of the pluginNode. - YAML::Node derivedNode = GenerateDerivedMetadata(pluginPair.first); + YAML::Node derivedNode = GenerateDerivedMetadata(pluginPair.second.Name()); for (auto it = derivedNode.begin(); it != derivedNode.end(); ++it) { const string key = it->first.as(); @@ -751,11 +751,11 @@ namespace loot { YAML::Node Handler::GenerateDerivedMetadata(const std::string& pluginName) { // Now rederive the displayed metadata from the masterlist and userlist. - auto pluginIt = g_app_state.CurrentGame().plugins.find(pluginName); + auto pluginIt = g_app_state.CurrentGame().plugins.find(boost::locale::to_lower(pluginName)); if (pluginIt != g_app_state.CurrentGame().plugins.end()) { - const Plugin master = g_app_state.CurrentGame().masterlist.FindPlugin(pluginIt->first); - const Plugin user = g_app_state.CurrentGame().userlist.FindPlugin(pluginIt->first); + const Plugin master = g_app_state.CurrentGame().masterlist.FindPlugin(pluginIt->second.Name()); + const Plugin user = g_app_state.CurrentGame().userlist.FindPlugin(pluginIt->second.Name()); return this->GenerateDerivedMetadata(pluginIt->second, master, user); }