mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 08:37:41 +00:00
Restructure per-core configs.
Merging yesterday was probably a bit premature. One issue I overlooked was that per-core configs were not flushed to disk when loading a new core on PC. The per-core flushing only happened on main_exit(), which is only run on application termination. This hence would only work with consoles with exitspawn. config_set_defaults() must be called when loading per-core-specifics as well or lots of options silently leak into other core specific configs when cores are changed. The handling with g_extern.config_path and original_config_path was difficult logic and very error prone considering it was mutated aribitrarily by RGUI. I've removed the original config path concept and stuck with that config_path is *only* for global config, and core_specific_config_path is for core-specifics (which are resolved during config load). Saves some memory too, which is always nice. The block_config_read solution I proposed yesterday was not good after all (in fact, broken on PC), and the current solution should work better. "RetroArch Config" option in RGUI now only shows global config.
This commit is contained in:
parent
a60d49293b
commit
13a006d147
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
||||
|
86
settings.c
86
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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user