Cleanups - add more actions to content_ctl

This commit is contained in:
twinaphex 2016-01-19 22:33:37 +01:00
parent 40beb7092a
commit 4726e3cb4f
3 changed files with 27 additions and 27 deletions

View File

@ -459,7 +459,7 @@ static void event_load_auto_state(void)
if (!path_file_exists(savestate_name_auto)) if (!path_file_exists(savestate_name_auto))
return; return;
ret = load_state(savestate_name_auto); ret = content_ctl(CONTENT_CTL_LOAD_STATE, (void*)savestate_name_auto);
RARCH_LOG("Found auto savestate in: %s\n", savestate_name_auto); RARCH_LOG("Found auto savestate in: %s\n", savestate_name_auto);
@ -612,7 +612,7 @@ static bool event_save_auto_state(void)
fill_pathname_noext(savestate_name_auto, global->name.savestate, fill_pathname_noext(savestate_name_auto, global->name.savestate,
".auto", sizeof(savestate_name_auto)); ".auto", sizeof(savestate_name_auto));
ret = save_state(savestate_name_auto); ret = content_ctl(CONTENT_CTL_SAVE_STATE, (void*)savestate_name_auto);
RARCH_LOG("Auto save state to \"%s\" %s.\n", savestate_name_auto, ret ? RARCH_LOG("Auto save state to \"%s\" %s.\n", savestate_name_auto, ret ?
"succeeded" : "failed"); "succeeded" : "failed");
@ -780,7 +780,7 @@ static void event_save_state(const char *path,
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
if (!save_state(path)) if (!content_ctl(CONTENT_CTL_SAVE_STATE, (void*)path))
{ {
snprintf(s, len, "%s \"%s\".", snprintf(s, len, "%s \"%s\".",
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO), msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
@ -807,7 +807,7 @@ static void event_load_state(const char *path, char *s, size_t len)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
if (!load_state(path)) if (!content_ctl(CONTENT_CTL_LOAD_STATE, (void*)path))
{ {
snprintf(s, len, "%s \"%s\".", snprintf(s, len, "%s \"%s\".",
msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE), msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE),

View File

@ -153,7 +153,7 @@ error:
* *
* Returns: true if successful, false otherwise. * Returns: true if successful, false otherwise.
**/ **/
bool save_state(const char *path) static bool content_save_state(const char *path)
{ {
bool ret = false; bool ret = false;
void *data = NULL; void *data = NULL;
@ -192,14 +192,14 @@ bool save_state(const char *path)
} }
/** /**
* load_state: * content_load_state:
* @path : path that state will be loaded from. * @path : path that state will be loaded from.
* *
* Load a state from disk to memory. * Load a state from disk to memory.
* *
* Returns: true if successful, false otherwise. * Returns: true if successful, false otherwise.
**/ **/
bool load_state(const char *path) static bool content_load_state(const char *path)
{ {
unsigned i; unsigned i;
ssize_t size; ssize_t size;
@ -770,6 +770,20 @@ bool content_ctl(enum content_ctl_state state, void *data)
switch(state) switch(state)
{ {
case CONTENT_CTL_LOAD_STATE:
{
const char *path = (const char*)data;
if (!path)
return false;
return content_load_state(path);
}
case CONTENT_CTL_SAVE_STATE:
{
const char *path = (const char*)data;
if (!path)
return false;
return content_save_state(path);
}
case CONTENT_CTL_INIT: case CONTENT_CTL_INIT:
if (content_init_file(temporary_content)) if (content_init_file(temporary_content))
return true; return true;

View File

@ -40,32 +40,18 @@ enum content_ctl_state
* Returns : true if successful, otherwise false. */ * Returns : true if successful, otherwise false. */
CONTENT_CTL_INIT, CONTENT_CTL_INIT,
/* Load a state from disk to memory. */
CONTENT_CTL_LOAD_STATE,
/* Save a state from memory to disk. */
CONTENT_CTL_SAVE_STATE,
/* Frees temporary content handle. */ /* Frees temporary content handle. */
CONTENT_CTL_TEMPORARY_FREE CONTENT_CTL_TEMPORARY_FREE
}; };
/* Handles files related to libretro. */ /* Handles files related to libretro. */
/**
* load_state:
* @path : path that state will be loaded from.
*
* Load a state from disk to memory.
*
* Returns: true if successful, false otherwise.
**/
bool load_state(const char *path);
/**
* save_state:
* @path : path of saved state that shall be written to.
*
* Save a state from memory to disk.
*
* Returns: true if successful, false otherwise.
**/
bool save_state(const char *path);
/** /**
* load_ram_file: * load_ram_file:
* @path : path of RAM state that will be loaded from. * @path : path of RAM state that will be loaded from.