Create retroarch_replace_config

This commit is contained in:
twinaphex 2016-05-11 21:44:52 +02:00
parent 07101f48d3
commit 1abe81b222
3 changed files with 36 additions and 28 deletions

View File

@ -772,7 +772,7 @@ static int generic_action_ok(const char *path,
flush_type = MENU_SETTINGS;
menu_display_set_msg_force(true);
if (rarch_ctl(RARCH_CTL_REPLACE_CONFIG, action_path))
if (retroarch_replace_config(action_path))
{
bool pending_push = false;
menu_navigation_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push);

View File

@ -1463,29 +1463,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
break;
case RARCH_CTL_IS_BLOCK_CONFIG_READ:
return rarch_block_config_read;
case RARCH_CTL_REPLACE_CONFIG:
{
char *path = (char*)data;
if (!path)
return false;
/* If config file to be replaced is the same as the
* current config file, exit. */
if (string_is_equal(path, global->path.config))
return false;
if (settings->config_save_on_exit && *global->path.config)
config_save_file(global->path.config);
strlcpy(global->path.config, path, sizeof(global->path.config));
rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL);
*settings->path.libretro = '\0'; /* Load core in new config. */
}
runloop_ctl(RUNLOOP_CTL_PREPARE_DUMMY, NULL);
break;
case RARCH_CTL_MENU_RUNNING:
#ifdef HAVE_MENU
menu_driver_ctl(RARCH_MENU_CTL_SET_TOGGLE, NULL);
@ -1532,6 +1509,36 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
return true;
}
/* Replaces currently loaded configuration file with
* another one. Will load a dummy core to flush state
* properly. */
bool retroarch_replace_config(char *path)
{
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
if (!path)
return false;
/* If config file to be replaced is the same as the
* current config file, exit. */
if (string_is_equal(path, global->path.config))
return false;
if (settings->config_save_on_exit && *global->path.config)
config_save_file(global->path.config);
strlcpy(global->path.config, path, sizeof(global->path.config));
rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL);
*settings->path.libretro = '\0'; /* Load core in new config. */
runloop_ctl(RUNLOOP_CTL_PREPARE_DUMMY, NULL);
return true;
}
void retroarch_set_pathnames(const char *path)
{
global_t *global = global_get_ptr();

View File

@ -81,10 +81,6 @@ enum rarch_ctl_state
RARCH_CTL_MENU_RUNNING_FINISHED,
/* Replaces currently loaded configuration file with
* another one. Will load a dummy core to flush state
* properly. */
RARCH_CTL_REPLACE_CONFIG,
/* Validates CPU features for given processor architecture.
* Make sure we haven't compiled for something we cannot run.
@ -166,6 +162,11 @@ void retroarch_set_pathnames(const char *path);
void retroarch_fill_pathnames(void);
/* Replaces currently loaded configuration file with
* another one. Will load a dummy core to flush state
* properly. */
bool retroarch_replace_config(char *path);
/**
* retroarch_fail:
* @error_code : Error code.