Merge pull request #457 from libretro/per-core-config

Per-core configuration
This commit is contained in:
Toad King 2014-01-01 16:11:25 -08:00
commit de5d749a3b
8 changed files with 84 additions and 0 deletions

View File

@ -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__)

View File

@ -284,7 +284,14 @@ 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);
// 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);
}
#endif
rarch_main_deinit();

View File

@ -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;
@ -1924,6 +1925,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

View File

@ -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,

View File

@ -443,6 +443,19 @@ 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:
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:
if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT)
@ -1722,6 +1735,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);

View File

@ -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,9 @@ struct global
bool libretro_no_rom;
bool libretro_dummy;
char original_config_path[PATH_MAX];
char core_specific_config_path[PATH_MAX];
};
struct rarch_main_wrap

View File

@ -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"

View File

@ -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,44 @@ void config_load(void)
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));
}
}
}
static config_file_t *open_default_config_file(void)
@ -931,6 +971,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;
}
@ -1243,6 +1285,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;