when saving an option to file, write only that value and not all the content of the user configDB, refs #3737
This was SVN commit r17738.
This commit is contained in:
parent
26f7a3df96
commit
43f358563c
@ -193,7 +193,7 @@ function startHost(playername, servername)
|
||||
{
|
||||
// Save player name
|
||||
Engine.ConfigDB_CreateValue("user", "playername", playername);
|
||||
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
|
||||
Engine.ConfigDB_WriteValueToFile("user", "playername", playername, "config/user.cfg");
|
||||
// Disallow identically named games in the multiplayer lobby
|
||||
if (Engine.HasXmppClient())
|
||||
{
|
||||
@ -253,11 +253,13 @@ function startJoin(playername, ip)
|
||||
if (Engine.HasXmppClient())
|
||||
// Set player lobby presence
|
||||
Engine.LobbySetPlayerPresence("playing");
|
||||
else {
|
||||
else
|
||||
{
|
||||
// Only save the player name and host address if they're valid and we're not in the lobby
|
||||
Engine.ConfigDB_CreateValue("user", "playername", playername);
|
||||
Engine.ConfigDB_WriteValueToFile("user", "playername", playername, "config/user.cfg");
|
||||
Engine.ConfigDB_CreateValue("user", "multiplayerserver", ip);
|
||||
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
|
||||
Engine.ConfigDB_WriteValueToFile("user", "multiplayerserver", ip, "config/user.cfg");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -180,12 +180,14 @@ function onTick()
|
||||
Engine.PopGuiPage();
|
||||
Engine.SwitchGuiPage("page_lobby.xml");
|
||||
Engine.ConfigDB_CreateValue("user", "playername", sanitizePlayerName(username, true, true));
|
||||
Engine.ConfigDB_WriteValueToFile("user", "playername", sanitizePlayerName(username, true, true), "config/user.cfg");
|
||||
Engine.ConfigDB_CreateValue("user", "lobby.login", username);
|
||||
Engine.ConfigDB_WriteValueToFile("user", "lobby.login", username, "config/user.cfg");
|
||||
// We only store the encrypted password, so make sure to re-encrypt it if changed before saving.
|
||||
if (password != g_EncrytedPassword.substring(0, 10))
|
||||
g_EncrytedPassword = Engine.EncryptPassword(password, username);
|
||||
Engine.ConfigDB_CreateValue("user", "lobby.password", g_EncrytedPassword);
|
||||
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
|
||||
Engine.ConfigDB_WriteValueToFile("user", "lobby.password", g_EncrytedPassword, "config/user.cfg");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,9 @@
|
||||
<object name="btnOK" type="button" style="ModernButtonRed" size="18 100%-45 50%-5 100%-17" hotkey="cancel">
|
||||
<translatableAttribute id="caption">OK</translatableAttribute>
|
||||
<action on="Press"><![CDATA[
|
||||
if (Engine.GetGUIObjectByName("displaySplashScreen").checked)
|
||||
Engine.ConfigDB_CreateValue("user", "splashscreenversion", 0);
|
||||
else
|
||||
Engine.ConfigDB_CreateValue("user", "splashscreenversion", Engine.GetFileMTime("gui/splashscreen/splashscreen.txt"));
|
||||
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
|
||||
let version = Engine.GetGUIObjectByName("displaySplashScreen").checked ? 0 : Engine.GetFileMTime("gui/splashscreen/splashscreen.txt");
|
||||
Engine.ConfigDB_CreateValue("user", "splashscreenversion", version);
|
||||
Engine.ConfigDB_WriteValueToFile("user", "splashscreenversion", version, "config/user.cfg");
|
||||
Engine.PopGuiPageCB();
|
||||
]]></action>
|
||||
</object>
|
||||
|
@ -93,7 +93,7 @@ bool L10n::SaveLocale(const Locale& locale) const
|
||||
return false;
|
||||
|
||||
g_ConfigDB.SetValueString(CFG_USER, "locale", locale.getName());
|
||||
g_ConfigDB.WriteFile(CFG_USER);
|
||||
g_ConfigDB.WriteValueToFile(CFG_USER, "locale", locale.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ void* CNetServerWorker::SetupUPnP(void*)
|
||||
|
||||
// Cache root descriptor URL to try to avoid discovery next time.
|
||||
g_ConfigDB.SetValueString(CFG_USER, "network.upnprootdescurl", urls.controlURL);
|
||||
g_ConfigDB.WriteFile(CFG_USER);
|
||||
g_ConfigDB.WriteValueToFile(CFG_USER, "network.upnprootdescurl", urls.controlURL);
|
||||
LOGMESSAGE("Net server: cached UPnP root descriptor URL as %s", urls.controlURL);
|
||||
|
||||
// Make sure everything is properly freed.
|
||||
|
@ -404,4 +404,29 @@ bool CConfigDB::WriteFile(EConfigNamespace ns, const VfsPath& path) const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CConfigDB::WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value)
|
||||
{
|
||||
CHECK_NS(false);
|
||||
|
||||
CScopeLock s(&cfgdb_mutex);
|
||||
return WriteValueToFile(ns, name, value, m_ConfigFile[ns]);
|
||||
}
|
||||
|
||||
bool CConfigDB::WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path)
|
||||
{
|
||||
CHECK_NS(false);
|
||||
|
||||
CScopeLock s(&cfgdb_mutex);
|
||||
|
||||
TConfigMap newMap;
|
||||
m_Map[ns].swap(newMap);
|
||||
if (!Reload(ns))
|
||||
return false;
|
||||
|
||||
SetValueString(ns, name, value);
|
||||
bool ret = WriteFile(ns, path);
|
||||
m_Map[ns].swap(newMap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#undef CHECK_NS
|
||||
|
@ -137,6 +137,17 @@ public:
|
||||
* false: if an error occurred
|
||||
*/
|
||||
bool WriteFile(EConfigNamespace ns) const;
|
||||
|
||||
/**
|
||||
* Write a config value to the file specified by 'path'
|
||||
*
|
||||
* Returns:
|
||||
* true: if the config value was successfully saved and written to the file
|
||||
* false: if an error occurred
|
||||
*/
|
||||
bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path);
|
||||
|
||||
bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value);
|
||||
};
|
||||
|
||||
|
||||
|
@ -538,7 +538,7 @@ std::string CUserReporter::LoadUserID()
|
||||
}
|
||||
|
||||
g_ConfigDB.SetValueString(CFG_USER, "userreport.id", userID);
|
||||
g_ConfigDB.WriteFile(CFG_USER);
|
||||
g_ConfigDB.WriteValueToFile(CFG_USER, "userreport.id", userID);
|
||||
}
|
||||
|
||||
return userID;
|
||||
@ -555,7 +555,7 @@ void CUserReporter::SetReportingEnabled(bool enabled)
|
||||
{
|
||||
CStr val = CStr::FromInt(enabled ? REPORTER_VERSION : 0);
|
||||
g_ConfigDB.SetValueString(CFG_USER, "userreport.enabledversion", val);
|
||||
g_ConfigDB.WriteFile(CFG_USER);
|
||||
g_ConfigDB.WriteValueToFile(CFG_USER, "userreport.enabledversion", val);
|
||||
|
||||
if (m_Worker)
|
||||
m_Worker->SetEnabled(enabled);
|
||||
|
@ -73,6 +73,16 @@ bool JSI_ConfigDB::WriteFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), con
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool JSI_ConfigDB::WriteValueToFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path)
|
||||
{
|
||||
EConfigNamespace cfgNs;
|
||||
if (!GetConfigNamespace(cfgNsString, cfgNs))
|
||||
return false;
|
||||
|
||||
bool ret = g_ConfigDB.WriteValueToFile(cfgNs, name, value, path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool JSI_ConfigDB::Reload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString)
|
||||
{
|
||||
EConfigNamespace cfgNs;
|
||||
@ -98,7 +108,7 @@ void JSI_ConfigDB::RegisterScriptFunctions(ScriptInterface& scriptInterface)
|
||||
scriptInterface.RegisterFunction<std::string, std::wstring, std::string, &JSI_ConfigDB::GetValue>("ConfigDB_GetValue");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, &JSI_ConfigDB::CreateValue>("ConfigDB_CreateValue");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::WriteFile>("ConfigDB_WriteFile");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, Path, &JSI_ConfigDB::WriteValueToFile>("ConfigDB_WriteValueToFile");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::SetFile>("ConfigDB_SetFile");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::Reload>("ConfigDB_Reload");
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ namespace JSI_ConfigDB
|
||||
std::string GetValue(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name);
|
||||
bool CreateValue(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value);
|
||||
bool WriteFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path);
|
||||
bool WriteValueToFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path);
|
||||
bool Reload(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString);
|
||||
bool SetFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path);
|
||||
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
|
||||
|
Loading…
Reference in New Issue
Block a user