From 800b332f605806f59404c2d3f53f93c3c348f177 Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Wed, 23 Jul 2025 04:04:00 -0500 Subject: [PATCH] Core: Only update configs when using a different build. (#3299) * Use a config version constant to check for config updates Should address the largest issue with the prior update logic, where configs with removed/additional entries will no longer force config updates on every emulator boot. This also makes it easier to add config entries, since you don't need to keep track of how many entries you add, or how many entries you removed. * Use git revision hash instead of constant In exchange for updating configs on every update, this removes the need for PR authors to manually change a constant when adding new settings. --- src/common/config.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 695e52980..12f95777e 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -107,8 +107,8 @@ u32 m_language = 1; // english // Keys static std::string trophyKey = ""; -// Expected number of items in the config file -static constexpr u64 total_entries = 55; +// Config version, used to determine if a user's config file is outdated. +static std::string config_version = Common::g_scm_rev; int getVolumeSlider() { return volumeSlider; @@ -623,8 +623,6 @@ void load(const std::filesystem::path& path) { return; } - u64 entry_count = 0; - if (data.contains("General")) { const toml::value& general = data.at("General"); @@ -646,8 +644,6 @@ void load(const std::filesystem::path& path) { checkCompatibilityOnStartup = toml::find_or(general, "checkCompatibilityOnStartup", checkCompatibilityOnStartup); chooseHomeTab = toml::find_or(general, "chooseHomeTab", chooseHomeTab); - - entry_count += general.size(); } if (data.contains("Input")) { @@ -662,8 +658,6 @@ void load(const std::filesystem::path& path) { useUnifiedInputConfig = toml::find_or(input, "useUnifiedInputConfig", useUnifiedInputConfig); micDevice = toml::find_or(input, "micDevice", micDevice); - - entry_count += input.size(); } if (data.contains("GPU")) { @@ -687,8 +681,6 @@ void load(const std::filesystem::path& path) { isFullscreen = toml::find_or(gpu, "Fullscreen", isFullscreen); fullscreenMode = toml::find_or(gpu, "FullscreenMode", fullscreenMode); isHDRAllowed = toml::find_or(gpu, "allowHDR", isHDRAllowed); - - entry_count += gpu.size(); } if (data.contains("Vulkan")) { @@ -702,10 +694,9 @@ void load(const std::filesystem::path& path) { vkHostMarkers = toml::find_or(vk, "hostMarkers", vkHostMarkers); vkGuestMarkers = toml::find_or(vk, "guestMarkers", vkGuestMarkers); rdocEnable = toml::find_or(vk, "rdocEnable", rdocEnable); - - entry_count += vk.size(); } + std::string current_version = {}; if (data.contains("Debug")) { const toml::value& debug = data.at("Debug"); @@ -714,8 +705,7 @@ void load(const std::filesystem::path& path) { toml::find_or(debug, "isSeparateLogFilesEnabled", isSeparateLogFilesEnabled); isShaderDebug = toml::find_or(debug, "CollectShader", isShaderDebug); isFpsColor = toml::find_or(debug, "FPSColor", isFpsColor); - - entry_count += debug.size(); + current_version = toml::find_or(debug, "ConfigVersion", current_version); } if (data.contains("GUI")) { @@ -747,26 +737,20 @@ void load(const std::filesystem::path& path) { settings_addon_install_dir = toml::find_fs_path_or(gui, "addonInstallDir", settings_addon_install_dir); - - entry_count += gui.size(); } if (data.contains("Settings")) { const toml::value& settings = data.at("Settings"); m_language = toml::find_or(settings, "consoleLanguage", m_language); - - entry_count += settings.size(); } if (data.contains("Keys")) { const toml::value& keys = data.at("Keys"); trophyKey = toml::find_or(keys, "TrophyKey", trophyKey); - - entry_count += keys.size(); } // Run save after loading to generate any missing fields with default values. - if (entry_count != total_entries) { + if (config_version != current_version) { fmt::print("Outdated config detected, updating config file.\n"); save(path); } @@ -874,6 +858,7 @@ void save(const std::filesystem::path& path) { data["Debug"]["CollectShader"] = isShaderDebug; data["Debug"]["isSeparateLogFilesEnabled"] = isSeparateLogFilesEnabled; data["Debug"]["FPSColor"] = isFpsColor; + data["Debug"]["ConfigVersion"] = config_version; data["Keys"]["TrophyKey"] = trophyKey; std::vector install_dirs;