Remove user.cfg from javascript

remove path from javascript
path is defined by the configuration scope

combine some calls
remove not needed calls

Differential revision: D4616
Accepted by: @Freagarach, @nani
Comments by: @phosit
This was SVN commit r27192.
This commit is contained in:
Angen 2022-11-02 07:21:25 +00:00
parent 2b94c6ca27
commit 281bb0b2ec
20 changed files with 76 additions and 78 deletions

View File

@ -155,8 +155,7 @@ function initGUIButtons(data)
function saveMods() function saveMods()
{ {
sortEnabledMods(); sortEnabledMods();
Engine.ConfigDB_CreateValue("user", "mod.enabledmods", ["mod"].concat(g_ModsEnabled).join(" ")); Engine.ConfigDB_CreateAndSaveValue("user", "mod.enabledmods", ["mod"].concat(g_ModsEnabled).join(" "));
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
Engine.GetGUIObjectByName("saveConfigurationButton").enabled = false; Engine.GetGUIObjectByName("saveConfigurationButton").enabled = false;
} }

View File

@ -38,8 +38,7 @@ class CampaignRun
static clearCurrentRun() static clearCurrentRun()
{ {
Engine.ConfigDB_RemoveValue("user", "currentcampaign"); Engine.ConfigDB_RemoveValueAndSave("user", "currentcampaign");
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
} }
constructor(name = "") constructor(name = "")

View File

@ -14,7 +14,7 @@ class PlayerAssignmentsController
let name = singleplayerName(); let name = singleplayerName();
// Replace empty player name when entering a single-player match for the first time. // Replace empty player name when entering a single-player match for the first time.
Engine.ConfigDB_CreateAndWriteValueToFile("user", this.ConfigNameSingleplayer, name, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", this.ConfigNameSingleplayer, name);
// By default, assign the player to the first slot. // By default, assign the player to the first slot.
g_PlayerAssignments = { g_PlayerAssignments = {

View File

@ -24,11 +24,11 @@ class TipsPanel
onPress() onPress()
{ {
Engine.ConfigDB_CreateAndWriteValueToFile( Engine.ConfigDB_CreateAndSaveValue(
"user", "user",
this.Config, this.Config,
String(this.displaySPTips.checked), String(this.displaySPTips.checked)
"config/user.cfg"); );
} }
onGameSettingsPanelResize(settingsPanel) onGameSettingsPanelResize(settingsPanel)

View File

@ -347,9 +347,9 @@ function startHost(playername, servername, port, password)
{ {
startConnectionStatus("server"); startConnectionStatus("server");
Engine.ConfigDB_CreateAndWriteValueToFile("user", "playername.multiplayer", playername, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "playername.multiplayer", playername);
Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerhosting.port", port, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "multiplayerhosting.port", port);
let hostFeedback = Engine.GetGUIObjectByName("hostFeedback"); let hostFeedback = Engine.GetGUIObjectByName("hostFeedback");
@ -415,9 +415,9 @@ function startJoin(playername, ip, port)
Engine.LobbySetPlayerPresence("playing"); Engine.LobbySetPlayerPresence("playing");
// Only save the player name and host address if they're valid. // Only save the player name and host address if they're valid.
Engine.ConfigDB_CreateAndWriteValueToFile("user", "playername.multiplayer", playername, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "playername.multiplayer", playername);
Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerserver", ip, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "multiplayerserver", ip);
Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerjoining.port", port, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "multiplayerjoining.port", port);
return true; return true;
} }

View File

@ -122,7 +122,7 @@
<object name="hostSTUNWrapper" size="120 136 100% 180"> <object name="hostSTUNWrapper" size="120 136 100% 180">
<object name="useSTUN" size="0 10 32 100%" type="checkbox" style="ModernTickBox"> <object name="useSTUN" size="0 10 32 100%" type="checkbox" style="ModernTickBox">
<action on="Press">Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.stun.enabled", String(this.checked), "config/user.cfg");</action> <action on="Press">Engine.ConfigDB_CreateAndSaveValue("user", "lobby.stun.enabled", String(this.checked));</action>
</object> </object>
<object type="text" size="26 0 100% 100%" style="ModernLeftLabelText"> <object type="text" size="26 0 100% 100%" style="ModernLeftLabelText">
<translatableAttribute id="caption">Use STUN to work around firewalls</translatableAttribute> <translatableAttribute id="caption">Use STUN to work around firewalls</translatableAttribute>

View File

@ -30,8 +30,7 @@ class HotkeyPicker
Engine.GetGUIObjectByName("hotkeyPickerReset").onPress = () => { Engine.GetGUIObjectByName("hotkeyPickerReset").onPress = () => {
// This is a bit "using a bazooka to kill a fly" // This is a bit "using a bazooka to kill a fly"
Engine.ConfigDB_RemoveValue("user", "hotkey." + this.name); Engine.ConfigDB_RemoveValueAndSave("user", "hotkey." + this.name);
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
Engine.ReloadHotkeys(); Engine.ReloadHotkeys();
let data = Engine.GetHotkeyMap(); let data = Engine.GetHotkeyMap();
this.combinations = data[this.name]; this.combinations = data[this.name];

View File

@ -163,7 +163,7 @@ class HotkeysPage
this.categories[cat].hotkeys.forEach(([name, _]) => { this.categories[cat].hotkeys.forEach(([name, _]) => {
Engine.ConfigDB_RemoveValue("user", "hotkey." + name); Engine.ConfigDB_RemoveValue("user", "hotkey." + name);
}); });
Engine.ConfigDB_WriteFile("user", "config/user.cfg"); Engine.ConfigDB_SaveChanges("user");
Engine.ReloadHotkeys(); Engine.ReloadHotkeys();
this.saveButton.enabled = false; this.saveButton.enabled = false;
this.setupHotkeyData(); this.setupHotkeyData();
@ -184,7 +184,7 @@ class HotkeysPage
if (keymap.join("") !== formatHotkeyCombinations(defaultData[hotkey], false).join("")) if (keymap.join("") !== formatHotkeyCombinations(defaultData[hotkey], false).join(""))
Engine.ConfigDB_CreateValues("user", "hotkey." + hotkey, keymap); Engine.ConfigDB_CreateValues("user", "hotkey." + hotkey, keymap);
} }
Engine.ConfigDB_WriteFile("user", "config/user.cfg"); Engine.ConfigDB_SaveChanges("user");
Engine.ReloadHotkeys(); Engine.ReloadHotkeys();
} }
} }

View File

@ -53,11 +53,11 @@ class BuddyButton
else else
g_Buddies.push(this.playerName); g_Buddies.push(this.playerName);
Engine.ConfigDB_CreateAndWriteValueToFile( Engine.ConfigDB_CreateAndSaveValue(
"user", "user",
"lobby.buddies", "lobby.buddies",
g_Buddies.filter(nick => nick).join(g_BuddyListDelimiter) || g_BuddyListDelimiter, g_Buddies.filter(nick => nick).join(g_BuddyListDelimiter) || g_BuddyListDelimiter
"config/user.cfg"); );
this.rebuild(); this.rebuild();

View File

@ -292,7 +292,6 @@ function displayOptions()
const hasChanges = Engine.ConfigDB_HasChanges("user"); const hasChanges = Engine.ConfigDB_HasChanges("user");
Engine.ConfigDB_CreateValue("user", option.config, String(value)); Engine.ConfigDB_CreateValue("user", option.config, String(value));
Engine.ConfigDB_SetChanges("user", true);
g_ChangedKeys.add(option.config); g_ChangedKeys.add(option.config);
fireConfigChangeHandlers(new Set([option.config])); fireConfigChangeHandlers(new Set([option.config]));
@ -374,16 +373,17 @@ function reallySetDefaults()
g_ChangedKeys.add(option.config); g_ChangedKeys.add(option.config);
} }
Engine.ConfigDB_WriteFile("user", "config/user.cfg"); Engine.ConfigDB_SaveChanges("user");
revertChanges(); revertChanges();
} }
function revertChange(option, oldValue, hadChanges) function revertChange(option, oldValue, hadChanges)
{ {
Engine.ConfigDB_CreateValue("user", option.config, String(oldValue));
if (!hadChanges) if (!hadChanges)
Engine.ConfigDB_SetChanges("user", false); Engine.ConfigDB_SetChanges("user", false);
Engine.ConfigDB_CreateValue("user", option.config, String(oldValue));
if (option.function) if (option.function)
Engine[option.function](oldValue); Engine[option.function](oldValue);
@ -393,7 +393,6 @@ function revertChange(option, oldValue, hadChanges)
function revertChanges() function revertChanges()
{ {
Engine.ConfigDB_Reload("user"); Engine.ConfigDB_Reload("user");
Engine.ConfigDB_SetChanges("user", false);
for (let category in g_Options) for (let category in g_Options)
for (let option of g_Options[category].options) for (let option of g_Options[category].options)
@ -436,8 +435,7 @@ function saveChanges()
function reallySaveChanges() function reallySaveChanges()
{ {
Engine.ConfigDB_WriteFile("user", "config/user.cfg"); Engine.ConfigDB_SaveChanges("user");
Engine.ConfigDB_SetChanges("user", false);
enableButtons(); enableButtons();
} }

View File

@ -56,10 +56,10 @@ function toggleRememberPassword()
[translate("No"), translate("Yes")], [translate("No"), translate("Yes")],
[ [
() => { checkbox.checked = true; }, () => { checkbox.checked = true; },
() => { Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.rememberpassword", String(!enabled), "config/user.cfg"); } () => { Engine.ConfigDB_CreateAndSaveValue("user", "lobby.rememberpassword", String(!enabled)); }
]); ]);
else else
Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.rememberpassword", String(!enabled), "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "lobby.rememberpassword", String(!enabled));
} }
function getEncryptedPassword() function getEncryptedPassword()
@ -78,14 +78,13 @@ function getEncryptedPassword()
function saveCredentials() function saveCredentials()
{ {
let username = Engine.GetGUIObjectByName("username").caption; let username = Engine.GetGUIObjectByName("username").caption;
Engine.ConfigDB_CreateAndWriteValueToFile("user", "playername.multiplayer", username, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "playername.multiplayer", username);
Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.login", username, "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "lobby.login", username);
if (Engine.ConfigDB_GetValue("user", "lobby.rememberpassword") == "true") if (Engine.ConfigDB_GetValue("user", "lobby.rememberpassword") == "true")
Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.password", getEncryptedPassword(), "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "lobby.password", getEncryptedPassword());
else else
{ {
Engine.ConfigDB_RemoveValue("user", "lobby.password"); Engine.ConfigDB_RemoveValueAndSave("user", "lobby.password");
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
} }
} }

View File

@ -38,10 +38,7 @@ class AutoFormation
this.defaultFormation = formation; this.defaultFormation = formation;
if (formation !== NULL_FORMATION) if (formation !== NULL_FORMATION)
this.lastDefault = this.defaultFormation; this.lastDefault = this.defaultFormation;
Engine.ConfigDB_CreateValue("user", "gui.session.defaultformation", this.defaultFormation); Engine.ConfigDB_ConfigDB_CreateAndSaveValue("user", "gui.session.defaultformation", this.defaultFormation);
// TODO: It's extremely terrible that we have to explicitly flush the config...
Engine.ConfigDB_SetChanges("user", true);
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
return true; return true;
} }

View File

@ -51,11 +51,10 @@ class RangeOverlayManager
{ {
let enabled = !this.isEnabled(type); let enabled = !this.isEnabled(type);
Engine.ConfigDB_CreateAndWriteValueToFile( Engine.ConfigDB_CreateAndSaveValue(
"user", "user",
type.config, type.config,
String(enabled), String(enabled));
"config/user.cfg");
this.setEnabled(type, enabled); this.setEnabled(type, enabled);
} }

View File

@ -28,7 +28,7 @@ class ChatWindow
this.closeChat.onPress = this.closePage.bind(this); this.closeChat.onPress = this.closePage.bind(this);
this.extendedChat.onPress = () => { this.extendedChat.onPress = () => {
Engine.ConfigDB_CreateAndWriteValueToFile("user", "chat.session.extended", String(this.isExtended()), "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "chat.session.extended", String(this.isExtended()));
this.resizeChatWindow(); this.resizeChatWindow();
this.chatInput.focus(); this.chatInput.focus();
}; };

View File

@ -832,7 +832,7 @@ function updateDisplayedNames()
function toggleConfigBool(configName) function toggleConfigBool(configName)
{ {
let enabled = Engine.ConfigDB_GetValue("user", configName) != "true"; let enabled = Engine.ConfigDB_GetValue("user", configName) != "true";
Engine.ConfigDB_CreateAndWriteValueToFile("user", configName, String(enabled), "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", configName, String(enabled));
return enabled; return enabled;
} }

View File

@ -55,11 +55,10 @@ class CounterManager
onPress() onPress()
{ {
Engine.ConfigDB_CreateAndWriteValueToFile( Engine.ConfigDB_CreateAndSaveValue(
"user", "user",
"gui.session.respoptooltipsort", "gui.session.respoptooltipsort",
String((+Engine.ConfigDB_GetValue("user", "gui.session.respoptooltipsort") + 2) % 3 - 1), String((+Engine.ConfigDB_GetValue("user", "gui.session.respoptooltipsort") + 2) % 3 - 1));
"config/user.cfg");
this.rebuild(); this.rebuild();
} }

View File

@ -8,7 +8,7 @@ function init(data)
function closePage() function closePage()
{ {
Engine.ConfigDB_CreateAndWriteValueToFile("user", "gui.splashscreen.enable", String(Engine.GetGUIObjectByName("displaySplashScreen").checked), "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "gui.splashscreen.enable", String(Engine.GetGUIObjectByName("displaySplashScreen").checked));
Engine.ConfigDB_CreateAndWriteValueToFile("user", "gui.splashscreen.version", Engine.GetFileMTime(g_SplashScreenFile), "config/user.cfg"); Engine.ConfigDB_CreateAndSaveValue("user", "gui.splashscreen.version", Engine.GetFileMTime(g_SplashScreenFile));
Engine.PopGuiPage(); Engine.PopGuiPage();
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games. /* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -264,17 +264,18 @@ void CConfigDB::SetValueList(EConfigNamespace ns, const CStr& name, std::vector<
it->second = values; it->second = values;
} }
void CConfigDB::RemoveValue(EConfigNamespace ns, const CStr& name) bool CConfigDB::RemoveValue(EConfigNamespace ns, const CStr& name)
{ {
CHECK_NS(;); CHECK_NS(false);
std::lock_guard<std::recursive_mutex> s(m_Mutex); std::lock_guard<std::recursive_mutex> s(m_Mutex);
TConfigMap::iterator it = m_Map[ns].find(name); TConfigMap::iterator it = m_Map[ns].find(name);
if (it == m_Map[ns].end()) if (it == m_Map[ns].end())
return; return false;
m_Map[ns].erase(it); m_Map[ns].erase(it);
TriggerAllHooks(m_Hooks, name); TriggerAllHooks(m_Hooks, name);
return true;
} }
void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path) void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games. /* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -134,7 +134,7 @@ public:
/** /**
* Remove a config value in the specified namespace. * Remove a config value in the specified namespace.
*/ */
void RemoveValue(EConfigNamespace ns, const CStr& name); bool RemoveValue(EConfigNamespace ns, const CStr& name);
/** /**
* Set the path to the config file used to populate the specified namespace * Set the path to the config file used to populate the specified namespace

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games. /* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -113,6 +113,7 @@ bool CreateValue(const std::wstring& cfgNsString, const std::string& name, const
return false; return false;
g_ConfigDB.SetValueString(cfgNs, name, value); g_ConfigDB.SetValueString(cfgNs, name, value);
g_ConfigDB.SetChanges(cfgNs, true);
return true; return true;
} }
@ -126,6 +127,7 @@ bool CreateValues(const std::wstring& cfgNsString, const std::string& name, cons
return false; return false;
g_ConfigDB.SetValueList(cfgNs, name, values); g_ConfigDB.SetValueList(cfgNs, name, values);
g_ConfigDB.SetChanges(cfgNs, true);
return true; return true;
} }
@ -139,20 +141,36 @@ bool RemoveValue(const std::wstring& cfgNsString, const std::string& name)
if (!GetConfigNamespace(cfgNsString, cfgNs)) if (!GetConfigNamespace(cfgNsString, cfgNs))
return false; return false;
g_ConfigDB.RemoveValue(cfgNs, name); bool result = g_ConfigDB.RemoveValue(cfgNs, name);
return true; if (result)
g_ConfigDB.SetChanges(cfgNs, true);
return result;
} }
bool WriteFile(const std::wstring& cfgNsString, const Path& path) bool SaveChanges(const std::wstring& cfgNsString)
{ {
EConfigNamespace cfgNs; EConfigNamespace cfgNs;
if (!GetConfigNamespace(cfgNsString, cfgNs)) if (!GetConfigNamespace(cfgNsString, cfgNs))
return false; return false;
return g_ConfigDB.WriteFile(cfgNs, path); bool result = g_ConfigDB.WriteFile(cfgNs);
if (result)
g_ConfigDB.SetChanges(cfgNs, false);
return result;
} }
bool WriteValueToFile(const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path) bool RemoveValueAndSave(const std::wstring& cfgNsString, const std::string& name)
{
if (RemoveValue(cfgNsString, name))
return SaveChanges(cfgNsString);
return false;
}
bool SaveValue(const std::wstring& cfgNsString, const std::string& name, const std::string& value)
{ {
if (IsProtectedConfigName(name)) if (IsProtectedConfigName(name))
return false; return false;
@ -161,13 +179,13 @@ bool WriteValueToFile(const std::wstring& cfgNsString, const std::string& name,
if (!GetConfigNamespace(cfgNsString, cfgNs)) if (!GetConfigNamespace(cfgNsString, cfgNs))
return false; return false;
return g_ConfigDB.WriteValueToFile(cfgNs, name, value, path); return g_ConfigDB.WriteValueToFile(cfgNs, name, value);
} }
void CreateAndWriteValueToFile(const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path) void CreateAndSaveValue(const std::wstring& cfgNsString, const std::string& name, const std::string& value)
{ {
CreateValue(cfgNsString, name, value); if (CreateValue(cfgNsString, name, value))
WriteValueToFile(cfgNsString, name, value, path); SaveValue(cfgNsString, name, value);
} }
bool Reload(const std::wstring& cfgNsString) bool Reload(const std::wstring& cfgNsString)
@ -179,16 +197,6 @@ bool Reload(const std::wstring& cfgNsString)
return g_ConfigDB.Reload(cfgNs); return g_ConfigDB.Reload(cfgNs);
} }
bool SetFile(const std::wstring& cfgNsString, const Path& path)
{
EConfigNamespace cfgNs;
if (!GetConfigNamespace(cfgNsString, cfgNs))
return false;
g_ConfigDB.SetConfigFile(cfgNs, path);
return true;
}
void PauseOnFocusLoss(bool pause) void PauseOnFocusLoss(bool pause)
{ {
g_PauseOnFocusLoss = pause; g_PauseOnFocusLoss = pause;
@ -207,10 +215,10 @@ void RegisterScriptFunctions(const ScriptRequest& rq)
ScriptFunction::Register<&CreateValue>(rq, "ConfigDB_CreateValue"); ScriptFunction::Register<&CreateValue>(rq, "ConfigDB_CreateValue");
ScriptFunction::Register<&CreateValues>(rq, "ConfigDB_CreateValues"); ScriptFunction::Register<&CreateValues>(rq, "ConfigDB_CreateValues");
ScriptFunction::Register<&RemoveValue>(rq, "ConfigDB_RemoveValue"); ScriptFunction::Register<&RemoveValue>(rq, "ConfigDB_RemoveValue");
ScriptFunction::Register<&WriteFile>(rq, "ConfigDB_WriteFile"); ScriptFunction::Register<&RemoveValueAndSave>(rq, "ConfigDB_RemoveValueAndSave");
ScriptFunction::Register<&WriteValueToFile>(rq, "ConfigDB_WriteValueToFile"); ScriptFunction::Register<&SaveChanges>(rq, "ConfigDB_SaveChanges");
ScriptFunction::Register<&CreateAndWriteValueToFile>(rq, "ConfigDB_CreateAndWriteValueToFile"); ScriptFunction::Register<&SaveValue>(rq, "ConfigDB_SaveValue");
ScriptFunction::Register<&SetFile>(rq, "ConfigDB_SetFile"); ScriptFunction::Register<&CreateAndSaveValue>(rq, "ConfigDB_CreateAndSaveValue");
ScriptFunction::Register<&Reload>(rq, "ConfigDB_Reload"); ScriptFunction::Register<&Reload>(rq, "ConfigDB_Reload");
ScriptFunction::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss"); ScriptFunction::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss");
ScriptFunction::Register<&SetGUIScale>(rq, "SetGUIScale"); ScriptFunction::Register<&SetGUIScale>(rq, "SetGUIScale");