diff --git a/source/config/config.cpp b/source/config/config.cpp index be8f9aab..4fb1b567 100644 --- a/source/config/config.cpp +++ b/source/config/config.cpp @@ -1,5 +1,6 @@ #include +#include #include "config.hpp" #include "gecko/gecko.hpp" @@ -196,6 +197,7 @@ void Config::unload(void) m_changed = false; m_filename = emptyString; m_domains.clear(); + m_groupCustomTitles.clear(); } void Config::save(bool unload) @@ -225,6 +227,18 @@ bool Config::has(const std::string &domain, const std::string &key) const return i->second.find(lowerCase(key)) != i->second.end(); } +void Config::groupCustomTitles(void) +{ + for (Config::DomainMap::iterator k = m_domains.begin(); k != m_domains.end(); ++k) + { + string uc_domain(upperCase(k->first)); + istringstream f(uc_domain); + string s; + while (getline(f, s, ',')) + m_groupCustomTitles[s] = uc_domain; + } +} + void Config::setWString(const string &domain, const string &key, const wstringEx &val) { if (domain.empty() || key.empty()) return; @@ -345,6 +359,22 @@ string Config::getString(const string &domain, const string &key, const string & return data; } +string Config::getStringCustomTitles(const string &domain, const string &key, const string &defVal) +{ + if(domain.empty() || key.empty()) + return defVal; + KeyMap::iterator i = m_groupCustomTitles.find(upperCase(domain)); + if (i == m_groupCustomTitles.end()) return defVal; + string &data = m_domains[i->second][lowerCase(key)]; + if(data.empty()) + { + data = defVal; + //gprintf("setString %s\n", defVal.c_str()); + m_changed = true; + } + return data; +} + vector Config::getStrings(const string &domain, const string &key, char seperator, const string &defVal) { vector retval; diff --git a/source/config/config.hpp b/source/config/config.hpp index 9abb8840..3ecb6654 100644 --- a/source/config/config.hpp +++ b/source/config/config.hpp @@ -13,8 +13,9 @@ class Config { public: Config(void); - void clear(void) { m_domains.clear(); } + void clear(void) { m_domains.clear(); m_groupCustomTitles.clear();} bool load(const char *filename = 0); + void groupCustomTitles(void); void unload(void); void save(bool unload = false); bool loaded(void) const { return m_loaded; } @@ -32,6 +33,7 @@ public: // Get wstringEx getWString(const std::string &domain, const std::string &key, const wstringEx &defVal = wstringEx()); std::string getString(const std::string &domain, const std::string &key, const std::string &defVal = std::string()); + std::string getStringCustomTitles(const std::string &domain, const std::string &key, const std::string &defVal = std::string()); vector getStrings(const std::string &domain, const std::string &key, char seperator = ',', const std::string &defval = std::string()); bool getBool(const std::string &domain, const std::string &key, bool defVal = false); int getOptBool(const std::string &domain, const std::string &key, int defVal = 2); @@ -60,6 +62,7 @@ private: DomainMap m_domains; std::string m_filename; DomainMap::iterator m_iter; + KeyMap m_groupCustomTitles; static const std::string emptyString; private: Config(const Config &); diff --git a/source/list/ListGenerator.cpp b/source/list/ListGenerator.cpp index 0ce24523..62ab9404 100644 --- a/source/list/ListGenerator.cpp +++ b/source/list/ListGenerator.cpp @@ -56,6 +56,7 @@ void ListGenerator::OpenConfigs() if(gameTDB.IsLoaded()) gameTDB.SetLanguageCode(gameTDB_Language.c_str()); CustomTitles.load(CustomTitlesPath.c_str()); + CustomTitles.groupCustomTitles(); } void ListGenerator::CloseConfigs() @@ -275,7 +276,7 @@ static void Add_Plugin_Game(char *FullPath) const char *RomFilename = strrchr(FullPath, '/') + 1; *strrchr(RomFilename, '.') = '\0'; - string customTitle = CustomTitles.getString(m_plugin.PluginMagicWord, RomFilename, ""); + string customTitle = CustomTitles.getStringCustomTitles(m_plugin.PluginMagicWord, RomFilename, ""); const char *gameTDB_Title = NULL; if(gameTDB.IsLoaded() && customTitle.empty() && m_cacheList.usePluginDBTitles) @@ -410,6 +411,7 @@ void ListGenerator::CreateRomList(Config &platform_cfg, const string& romsDir, c } } CustomTitles.load(CustomTitlesPath.c_str()); + CustomTitles.groupCustomTitles(); GetFiles(romsDir.c_str(), FileTypes, Add_Plugin_Game, false, 30);//wow 30 subfolders! really? CloseConfigs(); romNamesDB.unload();