Ticket #3737: writeValue.patch

File writeValue.patch, 9.6 KB (added by mimo, 8 years ago)
  • binaries/data/mods/public/gui/gamesetup/gamesetup_mp.js

     
    193193{
    194194    // Save player name
    195195    Engine.ConfigDB_CreateValue("user", "playername", playername);
    196     Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     196    Engine.ConfigDB_WriteValueToFile("user", "playername", playername, "config/user.cfg");
    197197    // Disallow identically named games in the multiplayer lobby
    198198    if (Engine.HasXmppClient())
    199199    {
     
    253253    if (Engine.HasXmppClient())
    254254        // Set player lobby presence
    255255        Engine.LobbySetPlayerPresence("playing");
    256     else {
     256    else
     257    {
    257258        // Only save the player name and host address if they're valid and we're not in the lobby
    258259        Engine.ConfigDB_CreateValue("user", "playername", playername);
     260        Engine.ConfigDB_WriteValueToFile("user", "playername", playername, "config/user.cfg");
    259261        Engine.ConfigDB_CreateValue("user", "multiplayerserver", ip);
    260         Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     262        Engine.ConfigDB_WriteValueToFile("user", "multiplayerserver", ip, "config/user.cfg");
    261263    }
    262264    return true;
    263265}
  • binaries/data/mods/public/gui/lobby/prelobby.js

     
    180180            Engine.PopGuiPage();
    181181            Engine.SwitchGuiPage("page_lobby.xml");
    182182            Engine.ConfigDB_CreateValue("user", "playername", sanitizePlayerName(username, true, true));
     183            Engine.ConfigDB_WriteValueToFile("user", "playername", sanitizePlayerName(username, true, true), "config/user.cfg");
    183184            Engine.ConfigDB_CreateValue("user", "lobby.login", username);
     185            Engine.ConfigDB_WriteValueToFile("user", "lobby.login", username, "config/user.cfg");
    184186            // We only store the encrypted password, so make sure to re-encrypt it if changed before saving.
    185187            if (password != g_EncrytedPassword.substring(0, 10))
    186188                g_EncrytedPassword = Engine.EncryptPassword(password, username);
    187189            Engine.ConfigDB_CreateValue("user", "lobby.password", g_EncrytedPassword);
    188             Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     190            Engine.ConfigDB_WriteValueToFile("user", "lobby.password", g_EncrytedPassword, "config/user.cfg");
    189191            break;
    190192        }
    191193        }
  • binaries/data/mods/public/gui/splashscreen/splashscreen.xml

     
    2727        <object name="btnOK" type="button" style="ModernButtonRed" size="18 100%-45 50%-5 100%-17" hotkey="cancel">
    2828            <translatableAttribute id="caption">OK</translatableAttribute>
    2929            <action on="Press"><![CDATA[
    30             if (Engine.GetGUIObjectByName("displaySplashScreen").checked)
    31                 Engine.ConfigDB_CreateValue("user", "splashscreenversion", 0);
    32             else
    33                 Engine.ConfigDB_CreateValue("user", "splashscreenversion", Engine.GetFileMTime("gui/splashscreen/splashscreen.txt"));
    34             Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     30            let version = Engine.GetGUIObjectByName("displaySplashScreen").checked ? 0 : Engine.GetFileMTime("gui/splashscreen/splashscreen.txt");
     31            Engine.ConfigDB_CreateValue("user", "splashscreenversion", version);
     32            Engine.ConfigDB_WriteValueToFile("user", "splashscreenversion", version, "config/user.cfg");
    3533            Engine.PopGuiPageCB();
    3634            ]]></action>
    3735        </object>
  • source/i18n/L10n.cpp

     
    9393        return false;
    9494
    9595    g_ConfigDB.SetValueString(CFG_USER, "locale", locale.getName());
    96     g_ConfigDB.WriteFile(CFG_USER);
     96    g_ConfigDB.WriteValueToFile(CFG_USER, "locale", locale.getName());
    9797    return true;
    9898}
    9999
  • source/network/NetServer.cpp

     
    310310
    311311    // Cache root descriptor URL to try to avoid discovery next time.
    312312    g_ConfigDB.SetValueString(CFG_USER, "network.upnprootdescurl", urls.controlURL);
    313     g_ConfigDB.WriteFile(CFG_USER);
     313    g_ConfigDB.WriteValueToFile(CFG_USER, "network.upnprootdescurl", urls.controlURL);
    314314    LOGMESSAGE("Net server: cached UPnP root descriptor URL as %s", urls.controlURL);
    315315
    316316    // Make sure everything is properly freed.
  • source/ps/ConfigDB.cpp

     
    398424    return true;
    399425}
    400426
     427bool CConfigDB::WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value)
     428{
     429    CHECK_NS(false);
     430
     431    CScopeLock s(&cfgdb_mutex);
     432    return WriteValueToFile(ns, name, value, m_ConfigFile[ns]);
     433}
     434
     435bool CConfigDB::WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path)
     436{
     437    CHECK_NS(false);
     438
     439    CScopeLock s(&cfgdb_mutex);
     440
     441    TConfigMap newMap;
     442    m_Map[ns].swap(newMap);
     443    if (!Reload(ns))
     444        return false;
     445
     446    SetValueString(ns, name, value);
     447    bool ret = WriteFile(ns, path);
     448    m_Map[ns].swap(newMap);
     449    return ret;
     450}
     451
    401452#undef CHECK_NS
  • source/ps/ConfigDB.h

     
    135148     *  false:  if an error occurred
    136149     */
    137150    bool WriteFile(EConfigNamespace ns) const;
     151
     152    /**
     153     * Write a config value to the file specified by 'path'
     154     *
     155     * Returns:
     156     *  true:   if the config value was successfully saved and written to the file
     157     *  false:  if an error occurred
     158     */
     159    bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path);
     160
     161    bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value);
    138162};
    139163
    140164
  • source/ps/UserReport.cpp

     
    538538        }
    539539
    540540        g_ConfigDB.SetValueString(CFG_USER, "userreport.id", userID);
    541         g_ConfigDB.WriteFile(CFG_USER);
     541        g_ConfigDB.WriteValueToFile(CFG_USER, "userreport.id", userID);
    542542    }
    543543
    544544    return userID;
     
    555555{
    556556    CStr val = CStr::FromInt(enabled ? REPORTER_VERSION : 0);
    557557    g_ConfigDB.SetValueString(CFG_USER, "userreport.enabledversion", val);
    558     g_ConfigDB.WriteFile(CFG_USER);
     558    g_ConfigDB.WriteValueToFile(CFG_USER, "userreport.enabledversion", val);
    559559
    560560    if (m_Worker)
    561561        m_Worker->SetEnabled(enabled);
  • source/ps/scripting/JSInterface_ConfigDB.cpp

     
    73102    return ret;
    74103}
    75104
     105bool JSI_ConfigDB::WriteValueToFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString,  const std::string& name, const std::string& value, const Path& path)
     106{
     107    EConfigNamespace cfgNs;
     108    if (!GetConfigNamespace(cfgNsString, cfgNs))
     109        return false;
     110
     111    bool ret = g_ConfigDB.WriteValueToFile(cfgNs, name, value, path);
     112    return ret;
     113}
     114
    76115bool JSI_ConfigDB::Reload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString)
    77116{
    78117    EConfigNamespace cfgNs;
     
    95134
    96135void JSI_ConfigDB::RegisterScriptFunctions(ScriptInterface& scriptInterface)
    97136{
    98137    scriptInterface.RegisterFunction<std::string, std::wstring, std::string, &JSI_ConfigDB::GetValue>("ConfigDB_GetValue");
    99138    scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, &JSI_ConfigDB::CreateValue>("ConfigDB_CreateValue");
    100139    scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::WriteFile>("ConfigDB_WriteFile");
     140    scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, Path, &JSI_ConfigDB::WriteValueToFile>("ConfigDB_WriteValueToFile");
    101141    scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::SetFile>("ConfigDB_SetFile");
    102142    scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::Reload>("ConfigDB_Reload");
    103    
    104143}
  • source/ps/scripting/JSInterface_ConfigDB.h

     
    2424namespace JSI_ConfigDB
    2525{
    2626    bool GetConfigNamespace(const std::wstring& cfgNsString, EConfigNamespace& cfgNs);
    2727    std::string GetValue(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name);
    2828    bool CreateValue(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value);
    2929    bool WriteFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path);
     30    bool WriteValueToFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path);
    3031    bool Reload(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString);
    3132    bool SetFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path);
    3233    void RegisterScriptFunctions(ScriptInterface& scriptInterface);