From 0a91c528f9d81f66b5050f36848a8dde36156a64 Mon Sep 17 00:00:00 2001 From: Toad King Date: Wed, 1 Jan 2014 14:44:20 -0500 Subject: [PATCH] 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; }