mirror of
https://github.com/libretro/RetroArch
synced 2024-12-26 21:29:08 +00:00
copy the old save state before making a new savestate
This commit is contained in:
parent
aa81de0ca0
commit
28aafddd91
12
command.c
12
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))
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -18,10 +18,12 @@
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <lists/string_list.h>
|
||||
#include <streams/file_stream.h>
|
||||
#include <file/file_path.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user