Index: ps/trunk/binaries/data/mods/mod/gui/modmod/modmod.js =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/modmod/modmod.js +++ ps/trunk/binaries/data/mods/mod/gui/modmod/modmod.js @@ -155,8 +155,7 @@ function saveMods() { sortEnabledMods(); - Engine.ConfigDB_CreateValue("user", "mod.enabledmods", ["mod"].concat(g_ModsEnabled).join(" ")); - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + Engine.ConfigDB_CreateAndSaveValue("user", "mod.enabledmods", ["mod"].concat(g_ModsEnabled).join(" ")); Engine.GetGUIObjectByName("saveConfigurationButton").enabled = false; } Index: ps/trunk/binaries/data/mods/public/gui/common/campaigns/CampaignRun.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/common/campaigns/CampaignRun.js +++ ps/trunk/binaries/data/mods/public/gui/common/campaigns/CampaignRun.js @@ -38,8 +38,7 @@ static clearCurrentRun() { - Engine.ConfigDB_RemoveValue("user", "currentcampaign"); - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + Engine.ConfigDB_RemoveValueAndSave("user", "currentcampaign"); } constructor(name = "") Index: ps/trunk/binaries/data/mods/public/gui/gamesetup/Controllers/PlayerAssignmentsController.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/gamesetup/Controllers/PlayerAssignmentsController.js +++ ps/trunk/binaries/data/mods/public/gui/gamesetup/Controllers/PlayerAssignmentsController.js @@ -14,7 +14,7 @@ let name = singleplayerName(); // 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. g_PlayerAssignments = { Index: ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/TipsPanel.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/TipsPanel.js +++ ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/TipsPanel.js @@ -24,11 +24,11 @@ onPress() { - Engine.ConfigDB_CreateAndWriteValueToFile( + Engine.ConfigDB_CreateAndSaveValue( "user", this.Config, - String(this.displaySPTips.checked), - "config/user.cfg"); + String(this.displaySPTips.checked) + ); } onGameSettingsPanelResize(settingsPanel) Index: ps/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js +++ ps/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js @@ -347,9 +347,9 @@ { 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"); @@ -415,9 +415,9 @@ Engine.LobbySetPlayerPresence("playing"); // Only save the player name and host address if they're valid. - Engine.ConfigDB_CreateAndWriteValueToFile("user", "playername.multiplayer", playername, "config/user.cfg"); - Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerserver", ip, "config/user.cfg"); - Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerjoining.port", port, "config/user.cfg"); + Engine.ConfigDB_CreateAndSaveValue("user", "playername.multiplayer", playername); + Engine.ConfigDB_CreateAndSaveValue("user", "multiplayerserver", ip); + Engine.ConfigDB_CreateAndSaveValue("user", "multiplayerjoining.port", port); return true; } Index: ps/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.xml +++ ps/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.xml @@ -122,7 +122,7 @@ - Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.stun.enabled", String(this.checked), "config/user.cfg"); + Engine.ConfigDB_CreateAndSaveValue("user", "lobby.stun.enabled", String(this.checked)); Use STUN to work around firewalls Index: ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeyPicker.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeyPicker.js +++ ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeyPicker.js @@ -30,8 +30,7 @@ Engine.GetGUIObjectByName("hotkeyPickerReset").onPress = () => { // This is a bit "using a bazooka to kill a fly" - Engine.ConfigDB_RemoveValue("user", "hotkey." + this.name); - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + Engine.ConfigDB_RemoveValueAndSave("user", "hotkey." + this.name); Engine.ReloadHotkeys(); let data = Engine.GetHotkeyMap(); this.combinations = data[this.name]; Index: ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeysPage.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeysPage.js +++ ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeysPage.js @@ -163,7 +163,7 @@ this.categories[cat].hotkeys.forEach(([name, _]) => { Engine.ConfigDB_RemoveValue("user", "hotkey." + name); }); - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + Engine.ConfigDB_SaveChanges("user"); Engine.ReloadHotkeys(); this.saveButton.enabled = false; this.setupHotkeyData(); @@ -184,7 +184,7 @@ if (keymap.join("") !== formatHotkeyCombinations(defaultData[hotkey], false).join("")) Engine.ConfigDB_CreateValues("user", "hotkey." + hotkey, keymap); } - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + Engine.ConfigDB_SaveChanges("user"); Engine.ReloadHotkeys(); } } Index: ps/trunk/binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/BuddyButton.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/BuddyButton.js +++ ps/trunk/binaries/data/mods/public/gui/lobby/LobbyPage/Buttons/BuddyButton.js @@ -53,11 +53,11 @@ else g_Buddies.push(this.playerName); - Engine.ConfigDB_CreateAndWriteValueToFile( + Engine.ConfigDB_CreateAndSaveValue( "user", "lobby.buddies", - g_Buddies.filter(nick => nick).join(g_BuddyListDelimiter) || g_BuddyListDelimiter, - "config/user.cfg"); + g_Buddies.filter(nick => nick).join(g_BuddyListDelimiter) || g_BuddyListDelimiter + ); this.rebuild(); Index: ps/trunk/binaries/data/mods/public/gui/options/options.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/options/options.js +++ ps/trunk/binaries/data/mods/public/gui/options/options.js @@ -292,7 +292,6 @@ const hasChanges = Engine.ConfigDB_HasChanges("user"); Engine.ConfigDB_CreateValue("user", option.config, String(value)); - Engine.ConfigDB_SetChanges("user", true); g_ChangedKeys.add(option.config); fireConfigChangeHandlers(new Set([option.config])); @@ -374,16 +373,17 @@ g_ChangedKeys.add(option.config); } - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + Engine.ConfigDB_SaveChanges("user"); revertChanges(); } function revertChange(option, oldValue, hadChanges) { + Engine.ConfigDB_CreateValue("user", option.config, String(oldValue)); + if (!hadChanges) Engine.ConfigDB_SetChanges("user", false); - Engine.ConfigDB_CreateValue("user", option.config, String(oldValue)); if (option.function) Engine[option.function](oldValue); @@ -393,7 +393,6 @@ function revertChanges() { Engine.ConfigDB_Reload("user"); - Engine.ConfigDB_SetChanges("user", false); for (let category in g_Options) for (let option of g_Options[category].options) @@ -436,8 +435,7 @@ function reallySaveChanges() { - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); - Engine.ConfigDB_SetChanges("user", false); + Engine.ConfigDB_SaveChanges("user"); enableButtons(); } Index: ps/trunk/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.js +++ ps/trunk/binaries/data/mods/public/gui/prelobby/common/credentials/credentials.js @@ -56,10 +56,10 @@ [translate("No"), translate("Yes")], [ () => { checkbox.checked = true; }, - () => { Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.rememberpassword", String(!enabled), "config/user.cfg"); } + () => { Engine.ConfigDB_CreateAndSaveValue("user", "lobby.rememberpassword", String(!enabled)); } ]); else - Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.rememberpassword", String(!enabled), "config/user.cfg"); + Engine.ConfigDB_CreateAndSaveValue("user", "lobby.rememberpassword", String(!enabled)); } function getEncryptedPassword() @@ -78,14 +78,13 @@ function saveCredentials() { let username = Engine.GetGUIObjectByName("username").caption; - Engine.ConfigDB_CreateAndWriteValueToFile("user", "playername.multiplayer", username, "config/user.cfg"); - Engine.ConfigDB_CreateAndWriteValueToFile("user", "lobby.login", username, "config/user.cfg"); + Engine.ConfigDB_CreateAndSaveValue("user", "playername.multiplayer", username); + Engine.ConfigDB_CreateAndSaveValue("user", "lobby.login", username); 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 { - Engine.ConfigDB_RemoveValue("user", "lobby.password"); - Engine.ConfigDB_WriteFile("user", "config/user.cfg"); + Engine.ConfigDB_RemoveValueAndSave("user", "lobby.password"); } } Index: ps/trunk/binaries/data/mods/public/gui/session/AutoFormation.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/AutoFormation.js +++ ps/trunk/binaries/data/mods/public/gui/session/AutoFormation.js @@ -38,10 +38,7 @@ this.defaultFormation = formation; if (formation !== NULL_FORMATION) this.lastDefault = this.defaultFormation; - Engine.ConfigDB_CreateValue("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"); + Engine.ConfigDB_ConfigDB_CreateAndSaveValue("user", "gui.session.defaultformation", this.defaultFormation); return true; } Index: ps/trunk/binaries/data/mods/public/gui/session/RangeOverlayManager.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/RangeOverlayManager.js +++ ps/trunk/binaries/data/mods/public/gui/session/RangeOverlayManager.js @@ -51,11 +51,10 @@ { let enabled = !this.isEnabled(type); - Engine.ConfigDB_CreateAndWriteValueToFile( + Engine.ConfigDB_CreateAndSaveValue( "user", type.config, - String(enabled), - "config/user.cfg"); + String(enabled)); this.setEnabled(type, enabled); } Index: ps/trunk/binaries/data/mods/public/gui/session/chat/ChatWindow.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/chat/ChatWindow.js +++ ps/trunk/binaries/data/mods/public/gui/session/chat/ChatWindow.js @@ -28,7 +28,7 @@ this.closeChat.onPress = this.closePage.bind(this); 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.chatInput.focus(); }; Index: ps/trunk/binaries/data/mods/public/gui/session/session.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/session.js +++ ps/trunk/binaries/data/mods/public/gui/session/session.js @@ -832,7 +832,7 @@ function toggleConfigBool(configName) { 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; } Index: ps/trunk/binaries/data/mods/public/gui/session/top_panel/CounterManager.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/top_panel/CounterManager.js +++ ps/trunk/binaries/data/mods/public/gui/session/top_panel/CounterManager.js @@ -55,11 +55,10 @@ onPress() { - Engine.ConfigDB_CreateAndWriteValueToFile( + Engine.ConfigDB_CreateAndSaveValue( "user", "gui.session.respoptooltipsort", - String((+Engine.ConfigDB_GetValue("user", "gui.session.respoptooltipsort") + 2) % 3 - 1), - "config/user.cfg"); + String((+Engine.ConfigDB_GetValue("user", "gui.session.respoptooltipsort") + 2) % 3 - 1)); this.rebuild(); } Index: ps/trunk/binaries/data/mods/public/gui/splashscreen/splashscreen.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/splashscreen/splashscreen.js +++ ps/trunk/binaries/data/mods/public/gui/splashscreen/splashscreen.js @@ -8,7 +8,7 @@ function closePage() { - Engine.ConfigDB_CreateAndWriteValueToFile("user", "gui.splashscreen.enable", String(Engine.GetGUIObjectByName("displaySplashScreen").checked), "config/user.cfg"); - Engine.ConfigDB_CreateAndWriteValueToFile("user", "gui.splashscreen.version", Engine.GetFileMTime(g_SplashScreenFile), "config/user.cfg"); + Engine.ConfigDB_CreateAndSaveValue("user", "gui.splashscreen.enable", String(Engine.GetGUIObjectByName("displaySplashScreen").checked)); + Engine.ConfigDB_CreateAndSaveValue("user", "gui.splashscreen.version", Engine.GetFileMTime(g_SplashScreenFile)); Engine.PopGuiPage(); } Index: ps/trunk/source/ps/ConfigDB.h =================================================================== --- ps/trunk/source/ps/ConfigDB.h +++ ps/trunk/source/ps/ConfigDB.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -134,7 +134,7 @@ /** * 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 Index: ps/trunk/source/ps/ConfigDB.cpp =================================================================== --- ps/trunk/source/ps/ConfigDB.cpp +++ ps/trunk/source/ps/ConfigDB.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -264,17 +264,18 @@ 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 s(m_Mutex); TConfigMap::iterator it = m_Map[ns].find(name); if (it == m_Map[ns].end()) - return; + return false; m_Map[ns].erase(it); TriggerAllHooks(m_Hooks, name); + return true; } void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path) Index: ps/trunk/source/ps/scripting/JSInterface_ConfigDB.cpp =================================================================== --- ps/trunk/source/ps/scripting/JSInterface_ConfigDB.cpp +++ ps/trunk/source/ps/scripting/JSInterface_ConfigDB.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -113,6 +113,7 @@ return false; g_ConfigDB.SetValueString(cfgNs, name, value); + g_ConfigDB.SetChanges(cfgNs, true); return true; } @@ -126,6 +127,7 @@ return false; g_ConfigDB.SetValueList(cfgNs, name, values); + g_ConfigDB.SetChanges(cfgNs, true); return true; } @@ -139,20 +141,36 @@ if (!GetConfigNamespace(cfgNsString, cfgNs)) return false; - g_ConfigDB.RemoveValue(cfgNs, name); - return true; + bool result = g_ConfigDB.RemoveValue(cfgNs, name); + 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; if (!GetConfigNamespace(cfgNsString, cfgNs)) 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)) return false; @@ -161,13 +179,13 @@ if (!GetConfigNamespace(cfgNsString, cfgNs)) 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); - WriteValueToFile(cfgNsString, name, value, path); + if (CreateValue(cfgNsString, name, value)) + SaveValue(cfgNsString, name, value); } bool Reload(const std::wstring& cfgNsString) @@ -179,16 +197,6 @@ 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) { g_PauseOnFocusLoss = pause; @@ -207,10 +215,10 @@ ScriptFunction::Register<&CreateValue>(rq, "ConfigDB_CreateValue"); ScriptFunction::Register<&CreateValues>(rq, "ConfigDB_CreateValues"); ScriptFunction::Register<&RemoveValue>(rq, "ConfigDB_RemoveValue"); - ScriptFunction::Register<&WriteFile>(rq, "ConfigDB_WriteFile"); - ScriptFunction::Register<&WriteValueToFile>(rq, "ConfigDB_WriteValueToFile"); - ScriptFunction::Register<&CreateAndWriteValueToFile>(rq, "ConfigDB_CreateAndWriteValueToFile"); - ScriptFunction::Register<&SetFile>(rq, "ConfigDB_SetFile"); + ScriptFunction::Register<&RemoveValueAndSave>(rq, "ConfigDB_RemoveValueAndSave"); + ScriptFunction::Register<&SaveChanges>(rq, "ConfigDB_SaveChanges"); + ScriptFunction::Register<&SaveValue>(rq, "ConfigDB_SaveValue"); + ScriptFunction::Register<&CreateAndSaveValue>(rq, "ConfigDB_CreateAndSaveValue"); ScriptFunction::Register<&Reload>(rq, "ConfigDB_Reload"); ScriptFunction::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss"); ScriptFunction::Register<&SetGUIScale>(rq, "SetGUIScale");