diff --git a/command.c b/command.c index 14c0612ad0..e6757b1928 100644 --- a/command.c +++ b/command.c @@ -1469,6 +1469,18 @@ static void command_event_save_state(const char *path, char *s, size_t len) { settings_t *settings = config_get_ptr(); + char buf[PATH_MAX_LENGTH] = {0}; + + if (path_file_exists(path)) + { + /* TODO: Fence with a setting */ + strlcpy(buf, path, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s", path); + path_remove_extension(buf); + snprintf(buf, sizeof(buf), "%s.last", buf); + + content_rename_state(path, buf); + } if (!content_save_state(path)) { diff --git a/content.h b/content.h index d3dc23b098..432fbbd36e 100644 --- a/content.h +++ b/content.h @@ -51,6 +51,9 @@ bool content_load_state(const char *path); /* Save a state from memory to disk. */ bool content_save_state(const char *path); +/* Copy a save state. */ +bool content_rename_state(const char *origin, const char *dest); + /* Load a state backup from disk to memory. */ bool content_undo_load_state(const char *path); diff --git a/tasks/task_save_state.c b/tasks/task_save_state.c index e732f667de..21bda19e52 100644 --- a/tasks/task_save_state.c +++ b/tasks/task_save_state.c @@ -18,10 +18,12 @@ #include #include #include +#include #include #include #include +#include #include "../core.h" #include "../msg_hash.h" @@ -210,3 +212,19 @@ error: free(buf); return false; } + +bool content_rename_state(const char *origin, const char *dest) +{ + int ret = 0; + if (path_file_exists(dest)) + unlink(dest); + + ret = rename (origin, dest); + if (!ret) + return true; + else + { + RARCH_LOG ("Error %d renaming file %s", ret, origin); + return false; + } +}