Add RARCH_ACTION_STATE_REPLACE_CONFIG

This commit is contained in:
twinaphex 2015-09-27 02:04:53 +02:00
parent 9679804382
commit 2364ae6b17
3 changed files with 31 additions and 45 deletions

View File

@ -564,7 +564,7 @@ static int generic_action_ok(const char *path,
msg_force = true;
menu_display_ctl(MENU_DISPLAY_CTL_SET_MSG_FORCE, &msg_force);
if (rarch_replace_config(action_path))
if (rarch_ctl(RARCH_ACTION_STATE_REPLACE_CONFIG, action_path))
{
bool pending_push = false;
menu_navigation_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push);

View File

@ -1365,7 +1365,7 @@ void rarch_main_init_wrap(const struct rarch_main_wrap *args,
#endif
}
void rarch_ctl(enum rarch_ctl_state state, void *data)
bool rarch_ctl(enum rarch_ctl_state state, void *data)
{
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
@ -1374,6 +1374,27 @@ void rarch_ctl(enum rarch_ctl_state state, void *data)
switch(state)
{
case RARCH_ACTION_STATE_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 (!strcmp(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));
global->block_config_read = false;
*settings->libretro = '\0'; /* Load core in new config. */
}
event_command(EVENT_CMD_PREPARE_DUMMY);
return true;
case RARCH_ACTION_STATE_MENU_RUNNING:
#ifdef HAVE_MENU
menu_driver_toggle(true);
@ -1432,8 +1453,10 @@ void rarch_ctl(enum rarch_ctl_state state, void *data)
break;
case RARCH_ACTION_STATE_NONE:
default:
break;
return false;
}
return true;
}
/**
@ -1569,44 +1592,3 @@ int rarch_defer_core(core_info_list_t *core_info, const char *dir,
return -1;
}
/**
* rarch_replace_config:
* @path : Path to config file to replace
* current config file with.
*
* Replaces currently loaded configuration file with
* another one. Will load a dummy core to flush state
* properly.
*
* Quite intrusive and error prone.
* Likely to have lots of small bugs.
* Cleanly exit the main loop to ensure that all the tiny details
* get set properly.
*
* This should mitigate most of the smaller bugs.
*
* Returns: true (1) if successful, false (0) if @path was the
* same as the current config file.
**/
bool rarch_replace_config(const char *path)
{
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
/* If config file to be replaced is the same as the
* current config file, exit. */
if (!strcmp(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));
global->block_config_read = false;
*settings->libretro = '\0'; /* Load core in new config. */
event_command(EVENT_CMD_PREPARE_DUMMY);
return true;
}

View File

@ -63,6 +63,10 @@ enum rarch_ctl_state
RARCH_ACTION_STATE_LOAD_CONTENT_IMAGEVIEWER,
RARCH_ACTION_STATE_MENU_RUNNING,
RARCH_ACTION_STATE_MENU_RUNNING_FINISHED,
/* Replaces currently loaded configuration file with
* another one. Will load a dummy core to flush state
* properly. */
RARCH_ACTION_STATE_REPLACE_CONFIG,
RARCH_ACTION_STATE_QUIT,
RARCH_ACTION_STATE_FORCE_QUIT
};
@ -101,7 +105,7 @@ void rarch_main_new(void);
void rarch_main_free(void);
void rarch_ctl(enum rarch_ctl_state state, void *data);
bool rarch_ctl(enum rarch_ctl_state state, void *data);
/**
* rarch_main_init: