diff --git a/frontend/frontend.c b/frontend/frontend.c index 96a05f98ac..b216234503 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -285,12 +285,13 @@ void main_exit(args_type() args) if (g_extern.config_save_on_exit && *g_extern.config_path) { + // save last core-specific config to the default config location, needed on + // consoles for core switching and reusing last good config for new cores. config_save_file(g_extern.config_path); - // save last core-specific config to the default config location, needed on - // consoles for core switching and reusing last good config for new cores - if (*g_extern.original_config_path && strcmp(g_extern.config_path, g_extern.original_config_path) != 0) - config_save_file(g_extern.original_config_path); + // Flush out the core specific config. + if (*g_extern.core_specific_config_path) + config_save_file(g_extern.core_specific_config_path); } #endif @@ -373,7 +374,7 @@ returntype main_entry(signature()) menu_rom_history_push_current(); } - while(!main_entry_iterate(signature_expand(), args)); + while (!main_entry_iterate(signature_expand(), args)); #else while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()); #endif diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index a3a04e6953..6a186b0860 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -1515,7 +1515,6 @@ bool menu_replace_config(const char *path) // Load dummy core. *g_extern.fullpath = '\0'; - *g_extern.original_config_path = '\0'; *g_settings.libretro = '\0'; // Load core in new config. g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); rgui->load_no_rom = false; diff --git a/frontend/menu/menu_settings.c b/frontend/menu/menu_settings.c index 1fbed0656a..6fb9a71b1e 100644 --- a/frontend/menu/menu_settings.c +++ b/frontend/menu/menu_settings.c @@ -444,17 +444,11 @@ int menu_set_settings(void *data, unsigned setting, unsigned action) g_extern.config_save_on_exit = true; break; case RGUI_SETTINGS_PER_CORE_CONFIG: - g_extern.block_config_read = false; if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_LEFT) g_settings.core_specific_config = !g_settings.core_specific_config; else if (action == RGUI_ACTION_START) g_settings.core_specific_config = default_core_specific_config; - - if (g_settings.core_specific_config && *g_extern.core_specific_config_path) - strlcpy(g_extern.config_path, g_extern.core_specific_config_path, sizeof(g_extern.config_path)); - else if (!g_settings.core_specific_config && *g_extern.original_config_path) - strlcpy(g_extern.config_path, g_extern.original_config_path, sizeof(g_extern.config_path)); break; #if defined(HAVE_THREADS) case RGUI_SETTINGS_SRAM_AUTOSAVE: diff --git a/general.h b/general.h index 4543465cea..7bb25293ba 100644 --- a/general.h +++ b/general.h @@ -363,6 +363,8 @@ struct global #ifdef HAVE_RMENU char menu_texture_path[PATH_MAX]; #endif + + // Config associated with global "default" config. char config_path[PATH_MAX]; char append_config_path[PATH_MAX]; char input_config_path[PATH_MAX]; @@ -652,7 +654,7 @@ struct global bool libretro_no_rom; bool libretro_dummy; - char original_config_path[PATH_MAX]; + // Config file associated with per-core configs. char core_specific_config_path[PATH_MAX]; }; @@ -684,7 +686,7 @@ const char *config_get_default_audio(void); const char *config_get_default_input(void); #include "conf/config_file.h" -bool config_load_file(const char *path); +bool config_load_file(const char *path, bool set_defaults); bool config_save_file(const char *path); bool config_read_keybinds(const char *path); diff --git a/settings.c b/settings.c index cd7768e98c..9f3b435a14 100644 --- a/settings.c +++ b/settings.c @@ -438,51 +438,54 @@ void config_set_defaults(void) static void parse_config_file(void); +static void config_load_core_specific(void) +{ + *g_extern.core_specific_config_path = '\0'; + + if (!*g_settings.libretro || g_extern.libretro_dummy) + return; + + if (*g_settings.rgui_config_directory) + { + path_resolve_realpath(g_settings.rgui_config_directory, sizeof(g_settings.rgui_config_directory)); + strlcpy(g_extern.core_specific_config_path, g_settings.rgui_config_directory, sizeof(g_extern.core_specific_config_path)); + } + else + { + // Use original config file's directory as a fallback. + fill_pathname_basedir(g_extern.core_specific_config_path, g_extern.config_path, sizeof(g_extern.core_specific_config_path)); + } + + fill_pathname_dir(g_extern.core_specific_config_path, g_settings.libretro, ".cfg", sizeof(g_extern.core_specific_config_path)); + + if (g_settings.core_specific_config) + { + char tmp[PATH_MAX]; + strlcpy(tmp, g_settings.libretro, sizeof(tmp)); + RARCH_LOG("Loading core-specific config from: %s.\n", g_extern.core_specific_config_path); + + if (!config_load_file(g_extern.core_specific_config_path, true)) + RARCH_WARN("Core-specific config not found, reusing last config.\n"); + + // don't have the core config file overwrite the libretro path + strlcpy(g_settings.libretro, tmp, sizeof(g_settings.libretro)); + } +} + void config_load(void) { + // Flush out per-core configs before loading a new config. + if (*g_extern.core_specific_config_path && g_extern.config_save_on_exit) + config_save_file(g_extern.core_specific_config_path); + if (!g_extern.block_config_read) { config_set_defaults(); parse_config_file(); } - if (!*g_extern.original_config_path) - { - // save the original path for saving. a copy of the last core's settings is always saved to the original config file path for future launches - path_resolve_realpath(g_extern.config_path, sizeof(g_extern.config_path)); - strlcpy(g_extern.original_config_path, g_extern.config_path, sizeof(g_extern.original_config_path)); - } - - if (*g_settings.libretro) - { - if (*g_settings.rgui_config_directory) - { - path_resolve_realpath(g_settings.rgui_config_directory, sizeof(g_settings.rgui_config_directory)); - strlcpy(g_extern.core_specific_config_path, g_settings.rgui_config_directory, sizeof(g_extern.core_specific_config_path)); - } - else - { - // use original config file's directory - strlcpy(g_extern.core_specific_config_path, g_extern.original_config_path, sizeof(g_extern.core_specific_config_path)); - path_basedir(g_extern.core_specific_config_path); - } - - fill_pathname_dir(g_extern.core_specific_config_path, g_settings.libretro, ".cfg", sizeof(g_extern.core_specific_config_path)); - - if (g_settings.core_specific_config) - { - char tmp[PATH_MAX]; - strlcpy(tmp, g_settings.libretro, sizeof(tmp)); - strlcpy(g_extern.config_path, g_extern.core_specific_config_path, sizeof(g_extern.config_path)); - RARCH_LOG("Loading core-specific config from: %s.\n", g_extern.config_path); - - if (!config_load_file(g_extern.config_path)) - RARCH_WARN("Core-specific config not found, reusing last config.\n"); - - // don't have the core config file overwrite the libretro path - strlcpy(g_settings.libretro, tmp, sizeof(g_settings.libretro)); - } - } + // Per-core config handling. + config_load_core_specific(); } static config_file_t *open_default_config_file(void) @@ -614,12 +617,12 @@ static void parse_config_file(void) if (*g_extern.config_path) { RARCH_LOG("Loading config from: %s.\n", g_extern.config_path); - ret = config_load_file(g_extern.config_path); + ret = config_load_file(g_extern.config_path, false); } else { RARCH_LOG("Loading default config.\n"); - ret = config_load_file(NULL); + ret = config_load_file(NULL, false); if (*g_extern.config_path) RARCH_LOG("Found default config: %s.\n", g_extern.config_path); } @@ -633,7 +636,7 @@ static void parse_config_file(void) } } -bool config_load_file(const char *path) +bool config_load_file(const char *path, bool set_defaults) { unsigned i; config_file_t *conf = NULL; @@ -650,6 +653,9 @@ bool config_load_file(const char *path) if (conf == NULL) return true; + if (set_defaults) + config_set_defaults(); + char *save; char tmp_append_path[PATH_MAX]; // Don't destroy append_config_path. strlcpy(tmp_append_path, g_extern.append_config_path, sizeof(tmp_append_path));