From 5b831e0bf26611a281114fb2aa7f915cbdb1394c Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Wed, 2 Jul 2025 16:56:05 -0500 Subject: [PATCH] Only update config when necessary Instead of updating the config on each emulator boot, calculate the number of entries stored in the config and compare to a hardcoded constant. If the config doesn't have the right number of entries, then regenerate it. --- src/common/config.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 866aafbfc..f8bb7492c 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -54,6 +54,8 @@ static bool useSpecialPad = false; static int specialPadClass = 1; static bool isMotionControlsEnabled = true; static bool useUnifiedInputConfig = true; + +// These two entries aren't stored in the config static bool overrideControllerColor = false; static int controllerCustomColorRGB[3] = {0, 0, 255}; @@ -97,7 +99,10 @@ std::filesystem::path save_data_path = {}; u32 m_language = 1; // english // Keys -static std::string trophyKey; +static std::string trophyKey = ""; + +// Expected number of items in the config file +static constexpr u64 total_entries = 50; bool allowHDR() { return isHDRAllowed; @@ -567,6 +572,9 @@ void load(const std::filesystem::path& path) { fmt::print("Got exception trying to load config file. Exception: {}\n", ex.what()); return; } + + u64 entry_count = 0; + if (data.contains("General")) { const toml::value& general = data.at("General"); @@ -587,6 +595,8 @@ 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")) { @@ -600,6 +610,8 @@ void load(const std::filesystem::path& path) { toml::find_or(input, "isMotionControlsEnabled", isMotionControlsEnabled); useUnifiedInputConfig = toml::find_or(input, "useUnifiedInputConfig", useUnifiedInputConfig); + + entry_count += input.size(); } if (data.contains("GPU")) { @@ -616,6 +628,8 @@ 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")) { @@ -629,6 +643,8 @@ 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(); } if (data.contains("Debug")) { @@ -639,6 +655,8 @@ 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(); } if (data.contains("GUI")) { @@ -670,21 +688,30 @@ 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. - save(path); + if (entry_count != total_entries) { + fmt::print("Outdated config detected, updating config file.\n"); + save(path); + } + } void sortTomlSections(toml::ordered_value& data) {