Ticket #953: Ticket#953.patch

File Ticket#953.patch, 3.2 KB (added by Bogdan Lazic, 13 years ago)
  • ConfigDB.cpp

     
    364364   
    365365    // Read file line by line
    366366    char *next=filebuf-1;
     367   
    367368    do
    368369    {
    369370        char *pos=next+1;
     
    395396                    continue;
    396397                CConfigValue argument;
    397398                argument.m_String = value;
    398                 newMap[name].push_back( argument );
    399                 LOGMESSAGE(L"Loaded config string \"%hs\" = \"%hs\"", name.c_str(), value.c_str());
     399
     400                // Try to insert into set of used values if value already exist, skip it.
     401                // Shift and Ctrl can be used at more places at once.
     402                if (name.compare(0, 6, "hotkey") == 0 && value.compare(0, 5, "Shift") != 0 &&
     403                    value.compare(0, 4, "Ctrl") != 0 && !usedKeys.insert(value).second)
     404                {
     405                    LOGMESSAGE(L"Loaded config string \"%hs\" = \"%hs\" is already used", name.c_str(), value.c_str());                 
     406                }
     407                else
     408                {
     409                    newMap[name].push_back( argument );
     410                    LOGMESSAGE(L"Loaded config string \"%hs\" = \"%hs\"", name.c_str(), value.c_str());
     411                }               
    400412            }
    401413        }
    402414    }
    403415    while (next < filebufend);
    404    
     416
    405417    m_Map[ns].swap(newMap);
    406418
    407419    return true;
     
    445457
    446458    return true;
    447459}
     460
     461void CConfigDB::ClearUsedSet()
     462{
     463    usedKeys.clear();
     464}
     465
  • ConfigDB.h

     
    7878{
    7979    static std::map <CStr, CConfigValueSet> m_Map[];
    8080    static VfsPath m_ConfigFile[];
     81    std::set<std::string> usedKeys;
    8182
    8283public:
    8384    // NOTE: Construct the Singleton Object *after* JavaScript init, so that
     
    162163     *  false:  if an error occurred
    163164     */
    164165    bool WriteFile(EConfigNamespace ns);
     166
     167    /**
     168     *Clear used set afret finishing using of it
     169     *Call after using the last call of Reload function
     170     *
     171     * Returns:
     172     *  none
     173     */
     174    void ClearUsedSet();
    165175};
    166176
    167177
  • GameSetup/Config.cpp

     
    157157
    158158    new CConfigDB;
    159159
    160     // Load the global, default config file
    161     g_ConfigDB.SetConfigFile(CFG_DEFAULT, L"config/default.cfg");
    162     g_ConfigDB.Reload(CFG_DEFAULT); // 216ms
     160    g_ConfigDB.SetConfigFile(CFG_MOD, L"config/mod.cfg");
     161    // No point in reloading mod.cfg here - we haven't mounted mods yet
     162
     163    g_ConfigDB.SetConfigFile(CFG_USER, L"config/user.cfg");
     164    g_ConfigDB.Reload(CFG_USER);
     165
    163166    // Try loading the local system config file (which doesn't exist by
    164167    // default) - this is designed as a way of letting developers edit the
    165168    // system config without accidentally committing their changes back to SVN.
    166169    g_ConfigDB.SetConfigFile(CFG_SYSTEM, L"config/local.cfg");
    167170    g_ConfigDB.Reload(CFG_SYSTEM);
    168171
    169     g_ConfigDB.SetConfigFile(CFG_USER, L"config/user.cfg");
    170     g_ConfigDB.Reload(CFG_USER);
     172    // Load the global, default config file
     173    g_ConfigDB.SetConfigFile(CFG_DEFAULT, L"config/default.cfg");
     174    g_ConfigDB.Reload(CFG_DEFAULT); // 216ms
     175    g_ConfigDB.ClearUsedSet();
    171176
    172     g_ConfigDB.SetConfigFile(CFG_MOD, L"config/mod.cfg");
    173     // No point in reloading mod.cfg here - we haven't mounted mods yet
    174 
    175177    ProcessCommandLineArgs(args);
    176178
    177179    // Initialise console history file