From 514258da53aedebe5fed0372ff12d8648981d7f2 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 25 Feb 2026 10:19:21 -0600 Subject: [PATCH] Fix Save Main Configuration saving to wrong file after Load Configuration (#18771) --- configuration.c | 2 +- configuration.h | 2 -- paths.h | 3 ++- retroarch.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/configuration.c b/configuration.c index 0fdb297282..b504f1e9b8 100644 --- a/configuration.c +++ b/configuration.c @@ -3557,7 +3557,7 @@ static bool check_menu_driver_compatibility(settings_t *settings) * * Returns: handle to config file if found, otherwise NULL. **/ -config_file_t *open_default_config_file(void) +static config_file_t *open_default_config_file(void) { char conf_path[PATH_MAX_LENGTH]; config_file_t *conf = NULL; diff --git a/configuration.h b/configuration.h index 148a09adfa..ad74bcd567 100644 --- a/configuration.h +++ b/configuration.h @@ -1377,8 +1377,6 @@ int8_t config_save_overrides(enum override_type type, * another one. Will load a dummy core to flush state * properly. */ bool config_replace(bool config_save_on_exit, char *path); - -config_file_t *open_default_config_file(void); #endif bool config_overlay_enable_default(void); diff --git a/paths.h b/paths.h index eb5abafcc5..f0c66aec77 100644 --- a/paths.h +++ b/paths.h @@ -56,7 +56,8 @@ enum rarch_path_type RARCH_PATH_CONFIG_OVERRIDE, RARCH_PATH_DEFAULT_SHADER_PRESET, RARCH_PATH_BASENAME, - RARCH_PATH_SUBSYSTEM + RARCH_PATH_SUBSYSTEM, + RARCH_PATH_CONFIG_DEFAULT }; void dir_clear(enum rarch_dir_type type); diff --git a/retroarch.c b/retroarch.c index da23cbfafe..70444d0cba 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2439,6 +2439,10 @@ char *path_get_ptr(enum rarch_path_type type) if (!path_is_empty(RARCH_PATH_CONFIG)) return p_rarch->path_config_file; break; + case RARCH_PATH_CONFIG_DEFAULT: + if (!path_is_empty(RARCH_PATH_CONFIG_DEFAULT)) + return p_rarch->path_config_default_file; + break; case RARCH_PATH_CONFIG_APPEND: if (!path_is_empty(RARCH_PATH_CONFIG_APPEND)) return p_rarch->path_config_append_file; @@ -2477,6 +2481,10 @@ const char *path_get(enum rarch_path_type type) if (!path_is_empty(RARCH_PATH_CONFIG)) return p_rarch->path_config_file; break; + case RARCH_PATH_CONFIG_DEFAULT: + if (!path_is_empty(RARCH_PATH_CONFIG_DEFAULT)) + return p_rarch->path_config_default_file; + break; case RARCH_PATH_CONFIG_APPEND: if (!path_is_empty(RARCH_PATH_CONFIG_APPEND)) return p_rarch->path_config_append_file; @@ -2515,6 +2523,8 @@ size_t path_get_realsize(enum rarch_path_type type) return sizeof(p_rarch->path_core_options_file); case RARCH_PATH_CONFIG: return sizeof(p_rarch->path_config_file); + case RARCH_PATH_CONFIG_DEFAULT: + return sizeof(p_rarch->path_config_default_file); case RARCH_PATH_CONFIG_APPEND: return sizeof(p_rarch->path_config_append_file); case RARCH_PATH_CONFIG_OVERRIDE: @@ -2567,6 +2577,10 @@ bool path_set(enum rarch_path_type type, const char *path) strlcpy(p_rarch->path_config_file, path, sizeof(p_rarch->path_config_file)); break; + case RARCH_PATH_CONFIG_DEFAULT: + strlcpy(p_rarch->path_config_default_file, path, + sizeof(p_rarch->path_config_default_file)); + break; case RARCH_PATH_CONFIG_APPEND: strlcpy(p_rarch->path_config_append_file, path, sizeof(p_rarch->path_config_append_file)); @@ -2614,6 +2628,10 @@ bool path_is_empty(enum rarch_path_type type) if (string_is_empty(p_rarch->path_config_file)) return true; break; + case RARCH_PATH_CONFIG_DEFAULT: + if (string_is_empty(p_rarch->path_config_default_file)) + return true; + break; case RARCH_PATH_CONFIG_APPEND: if (string_is_empty(p_rarch->path_config_append_file)) return true; @@ -2676,6 +2694,9 @@ void path_clear(enum rarch_path_type type) case RARCH_PATH_CONFIG: *p_rarch->path_config_file = '\0'; break; + case RARCH_PATH_CONFIG_DEFAULT: + *p_rarch->path_config_default_file = '\0'; + break; case RARCH_PATH_CONFIG_APPEND: *p_rarch->path_config_append_file = '\0'; break; @@ -2706,6 +2727,7 @@ static void path_clear_all(void) path_clear(RARCH_PATH_CORE_LAST); path_clear(RARCH_PATH_CORE_OPTIONS); path_clear(RARCH_PATH_CONFIG); + path_clear(RARCH_PATH_CONFIG_DEFAULT); path_clear(RARCH_PATH_CONFIG_APPEND); path_clear(RARCH_PATH_CONFIG_OVERRIDE); path_clear(RARCH_PATH_DEFAULT_SHADER_PRESET); @@ -4763,8 +4785,24 @@ bool command_event(enum event_command cmd, void *data) case CMD_EVENT_MENU_SAVE_MAIN_CONFIG: { #ifdef HAVE_CONFIGFILE - open_default_config_file(); + char tmp_config[PATH_MAX_LENGTH]; + tmp_config[0] = '\0'; + + /* Temporarily point RARCH_PATH_CONFIG at the + * startup config so the save goes to the right + * file, then restore the previous value. */ + if (!path_is_empty(RARCH_PATH_CONFIG_DEFAULT)) + { + strlcpy(tmp_config, path_get(RARCH_PATH_CONFIG), + sizeof(tmp_config)); + path_set(RARCH_PATH_CONFIG, + path_get(RARCH_PATH_CONFIG_DEFAULT)); + } + command_event_save_current_config(OVERRIDE_NONE); + + if (!string_is_empty(tmp_config)) + path_set(RARCH_PATH_CONFIG, tmp_config); #endif } break; @@ -7368,6 +7406,14 @@ static bool retroarch_parse_input_and_config( config_load_file_salamander(); #endif config_load(global_get_ptr()); + + /* Remember the startup config path so "Save Main + * Configuration" can find it after config_replace() + * changes RARCH_PATH_CONFIG to a different file. */ + if ( !path_is_empty(RARCH_PATH_CONFIG) + && path_is_empty(RARCH_PATH_CONFIG_DEFAULT)) + path_set(RARCH_PATH_CONFIG_DEFAULT, + path_get(RARCH_PATH_CONFIG)); } verbosity_enabled = verbosity_is_enabled();