From 0a91c528f9d81f66b5050f36848a8dde36156a64 Mon Sep 17 00:00:00 2001 From: Toad King Date: Wed, 1 Jan 2014 14:44:20 -0500 Subject: [PATCH 1/5] core-specific config files --- config.def.h | 6 ++++++ frontend/frontend.c | 5 +++++ general.h | 4 ++++ settings.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/config.def.h b/config.def.h index 3ada7c7bd1..00764cc9ea 100644 --- a/config.def.h +++ b/config.def.h @@ -347,6 +347,12 @@ static bool default_block_config_read = true; static bool default_block_config_read = false; #endif +#ifdef RARCH_CONSOLE +static bool default_core_specific_config = true; +#else +static bool default_core_specific_config = false; +#endif + #if defined(ANDROID) static const char *default_libretro_info_path = "/data/data/com.retroarch/info/"; #elif defined(__QNX__) diff --git a/frontend/frontend.c b/frontend/frontend.c index 99c9ed361f..7cdba6e8a0 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -284,7 +284,12 @@ void main_exit(args_type() args) menu_free(); if (g_extern.config_save_on_exit && *g_extern.config_path) + { config_save_file(g_extern.config_path); + + 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); + } #endif rarch_main_deinit(); diff --git a/general.h b/general.h index 46f8c2fc65..59aa3cc945 100644 --- a/general.h +++ b/general.h @@ -301,6 +301,8 @@ struct settings bool rgui_show_start_screen; #endif bool fps_show; + + bool core_specific_config; }; enum rarch_game_type @@ -650,6 +652,8 @@ struct global bool libretro_no_rom; bool libretro_dummy; + + char original_config_path[PATH_MAX]; }; struct rarch_main_wrap diff --git a/settings.c b/settings.c index 52ec0cea66..29e4142dba 100644 --- a/settings.c +++ b/settings.c @@ -383,6 +383,8 @@ void config_set_defaults(void) g_settings.video.msg_pos_y = 0.90f; g_settings.video.aspect_ratio = -1.0f; + g_settings.core_specific_config = default_core_specific_config; + // g_extern strlcpy(g_extern.savefile_dir, default_paths.sram_dir, sizeof(g_extern.savefile_dir)); g_extern.console.screen.gamma_correction = DEFAULT_GAMMA; @@ -443,6 +445,36 @@ void config_load(void) config_set_defaults(); parse_config_file(); } + + if (!*g_extern.original_config_path) + { + 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.core_specific_config && *g_settings.libretro) + { + char new_path[PATH_MAX]; + + if (*g_settings.rgui_config_directory) + { + path_resolve_realpath(g_settings.rgui_config_directory, sizeof(g_settings.rgui_config_directory)); + strlcpy(new_path, g_settings.rgui_config_directory, sizeof(new_path)); + } + else + { + strlcpy(new_path, g_extern.config_path, sizeof(new_path)); + path_basedir(new_path); + } + + fill_pathname_dir(new_path, g_settings.libretro, ".cfg", sizeof(new_path)); + strlcpy(g_extern.config_path, new_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"); + } + } } static config_file_t *open_default_config_file(void) @@ -931,6 +963,8 @@ bool config_load_file(const char *path) config_read_keybinds_conf(conf); + CONFIG_GET_BOOL(core_specific_config, "core_specific_config"); + config_file_free(conf); return true; } From 5215a7cf249eaaf30429ff030bc3edafb34ca56a Mon Sep 17 00:00:00 2001 From: Toad King Date: Wed, 1 Jan 2014 14:52:35 -0500 Subject: [PATCH 2/5] save core specific config option --- retroarch.cfg | 3 +++ settings.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/retroarch.cfg b/retroarch.cfg index e18b750862..a97ef26009 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -59,6 +59,9 @@ # Overwrites the config. #include's and comments are not preserved. # config_save_on_exit = false +# Load up a specific config file based on the core being used. +# core_specific_config = false + #### Video # Video driver to use. "gl", "xvideo", "sdl" diff --git a/settings.c b/settings.c index 29e4142dba..ed798e5465 100644 --- a/settings.c +++ b/settings.c @@ -1277,6 +1277,8 @@ bool config_save_file(const char *path) for (i = 0; i < MAX_PLAYERS; i++) save_keybinds_player(conf, i); + config_set_bool(conf, "core_specific_config", g_settings.core_specific_config); + bool ret = config_file_write(conf, path); config_file_free(conf); return ret; From 8f45063f749e6f4b97b83084bcd0b291b891af90 Mon Sep 17 00:00:00 2001 From: Toad King Date: Wed, 1 Jan 2014 15:02:57 -0500 Subject: [PATCH 3/5] menu support for core specific config --- frontend/frontend.c | 2 ++ frontend/menu/menu_common.c | 1 + frontend/menu/menu_common.h | 1 + frontend/menu/menu_settings.c | 15 +++++++++++++++ general.h | 1 + settings.c | 30 ++++++++++++++---------------- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/frontend/frontend.c b/frontend/frontend.c index 7cdba6e8a0..96a05f98ac 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -287,6 +287,8 @@ void main_exit(args_type() args) { 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); } diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index 9bc0fbe1ef..6a186b0860 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -1924,6 +1924,7 @@ void menu_populate_entries(void *data, unsigned menu_type) file_list_push(rgui->selection_buf, "GPU Screenshots", RGUI_SETTINGS_GPU_SCREENSHOT, 0); #endif file_list_push(rgui->selection_buf, "Config Save On Exit", RGUI_SETTINGS_CONFIG_SAVE_ON_EXIT, 0); + file_list_push(rgui->selection_buf, "Per-Core Configs", RGUI_SETTINGS_PER_CORE_CONFIG, 0); #if defined(HAVE_THREADS) file_list_push(rgui->selection_buf, "SRAM Autosave", RGUI_SETTINGS_SRAM_AUTOSAVE, 0); #endif diff --git a/frontend/menu/menu_common.h b/frontend/menu/menu_common.h index 94e173a449..ad0d949913 100644 --- a/frontend/menu/menu_common.h +++ b/frontend/menu/menu_common.h @@ -114,6 +114,7 @@ typedef enum RGUI_SETTINGS_REWIND_ENABLE, RGUI_SETTINGS_REWIND_GRANULARITY, RGUI_SETTINGS_CONFIG_SAVE_ON_EXIT, + RGUI_SETTINGS_PER_CORE_CONFIG, RGUI_SETTINGS_SRAM_AUTOSAVE, RGUI_SETTINGS_SAVESTATE_SAVE, RGUI_SETTINGS_SAVESTATE_LOAD, diff --git a/frontend/menu/menu_settings.c b/frontend/menu/menu_settings.c index 629052f655..e46482fbbc 100644 --- a/frontend/menu/menu_settings.c +++ b/frontend/menu/menu_settings.c @@ -443,6 +443,18 @@ int menu_set_settings(void *data, unsigned setting, unsigned action) else if (action == RGUI_ACTION_START) g_extern.config_save_on_exit = true; break; + case RGUI_SETTINGS_PER_CORE_CONFIG: + 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) + strlcpy(g_extern.config_path, g_extern.core_specific_config_path, sizeof(g_extern.config_path)); + else + 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: if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT) @@ -1722,6 +1734,9 @@ void menu_set_settings_label(char *type_str, size_t type_str_size, unsigned *w, case RGUI_SETTINGS_CONFIG_SAVE_ON_EXIT: strlcpy(type_str, g_extern.config_save_on_exit ? "ON" : "OFF", type_str_size); break; + case RGUI_SETTINGS_PER_CORE_CONFIG: + strlcpy(type_str, g_settings.core_specific_config ? "ON" : "OFF", type_str_size); + break; case RGUI_SETTINGS_SRAM_AUTOSAVE: if (g_settings.autosave_interval) snprintf(type_str, type_str_size, "%u seconds", g_settings.autosave_interval); diff --git a/general.h b/general.h index 59aa3cc945..35144c7811 100644 --- a/general.h +++ b/general.h @@ -654,6 +654,7 @@ struct global bool libretro_dummy; char original_config_path[PATH_MAX]; + char core_specific_config_path[PATH_MAX]; }; struct rarch_main_wrap diff --git a/settings.c b/settings.c index ed798e5465..f1e80f4b65 100644 --- a/settings.c +++ b/settings.c @@ -446,29 +446,27 @@ void config_load(void) parse_config_file(); } - if (!*g_extern.original_config_path) + if (!*g_extern.original_config_path && *g_settings.libretro) { 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.core_specific_config && *g_settings.libretro) + if (*g_settings.rgui_config_directory) { - char new_path[PATH_MAX]; + 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 + { + strlcpy(g_extern.core_specific_config_path, g_extern.config_path, sizeof(g_extern.core_specific_config_path)); + path_basedir(g_extern.core_specific_config_path); + } - if (*g_settings.rgui_config_directory) - { - path_resolve_realpath(g_settings.rgui_config_directory, sizeof(g_settings.rgui_config_directory)); - strlcpy(new_path, g_settings.rgui_config_directory, sizeof(new_path)); - } - else - { - strlcpy(new_path, g_extern.config_path, sizeof(new_path)); - path_basedir(new_path); - } - - fill_pathname_dir(new_path, g_settings.libretro, ".cfg", sizeof(new_path)); - strlcpy(g_extern.config_path, new_path, sizeof(g_extern.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) + { + 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)) From e022b39061a12d78aa9915c347637ee41a53fbb6 Mon Sep 17 00:00:00 2001 From: Toad King Date: Wed, 1 Jan 2014 15:34:56 -0500 Subject: [PATCH 4/5] fix per-core config on PC --- frontend/menu/menu_settings.c | 4 ++-- settings.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/menu/menu_settings.c b/frontend/menu/menu_settings.c index e46482fbbc..5156677811 100644 --- a/frontend/menu/menu_settings.c +++ b/frontend/menu/menu_settings.c @@ -450,9 +450,9 @@ int menu_set_settings(void *data, unsigned setting, unsigned action) else if (action == RGUI_ACTION_START) g_settings.core_specific_config = default_core_specific_config; - if (g_settings.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 + 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) diff --git a/settings.c b/settings.c index f1e80f4b65..9db62cdde3 100644 --- a/settings.c +++ b/settings.c @@ -446,11 +446,14 @@ void config_load(void) parse_config_file(); } - if (!*g_extern.original_config_path && *g_settings.libretro) + if (!*g_extern.original_config_path) { 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)); @@ -458,7 +461,7 @@ void config_load(void) } else { - strlcpy(g_extern.core_specific_config_path, g_extern.config_path, sizeof(g_extern.core_specific_config_path)); + 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); } @@ -466,11 +469,16 @@ void config_load(void) 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"); + + // make sure we don't accidentally switch this + strlcpy(g_settings.libretro, tmp, sizeof(g_settings.libretro)); } } } From e0671aba8be558cec9578827a4262b13c44eadf5 Mon Sep 17 00:00:00 2001 From: Toad King Date: Wed, 1 Jan 2014 19:06:06 -0500 Subject: [PATCH 5/5] per-core minor fixes --- frontend/menu/menu_common.c | 1 + frontend/menu/menu_settings.c | 1 + settings.c | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index 6a186b0860..a3a04e6953 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -1515,6 +1515,7 @@ 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 5156677811..1fbed0656a 100644 --- a/frontend/menu/menu_settings.c +++ b/frontend/menu/menu_settings.c @@ -444,6 +444,7 @@ 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; diff --git a/settings.c b/settings.c index 9db62cdde3..cd7768e98c 100644 --- a/settings.c +++ b/settings.c @@ -448,6 +448,7 @@ void config_load(void) 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)); } @@ -461,6 +462,7 @@ void config_load(void) } 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); } @@ -477,7 +479,7 @@ void config_load(void) if (!config_load_file(g_extern.config_path)) RARCH_WARN("Core-specific config not found, reusing last config.\n"); - // make sure we don't accidentally switch this + // don't have the core config file overwrite the libretro path strlcpy(g_settings.libretro, tmp, sizeof(g_settings.libretro)); } }