mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
commit
86b35c8ff2
6
Makefile
6
Makefile
@ -54,9 +54,9 @@ ifeq ($(DEBUG), 1)
|
||||
OPTIMIZE_FLAG = -O0 -g
|
||||
else
|
||||
OPTIMIZE_FLAG = -O3 -ffast-math
|
||||
ifneq ($(findstring Win32,$(OS)),)
|
||||
LDFLAGS += -mwindows
|
||||
endif
|
||||
ifneq ($(findstring Win32,$(OS)),)
|
||||
LDFLAGS += -mwindows
|
||||
endif
|
||||
endif
|
||||
|
||||
CFLAGS += -Wall $(OPTIMIZE_FLAG) $(INCLUDE_DIRS) $(DEBUG_FLAG) -I.
|
||||
|
63
command.c
63
command.c
@ -1469,6 +1469,24 @@ 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);
|
||||
|
||||
if (!content_rename_state(path, buf))
|
||||
{
|
||||
snprintf(s, len, "%s \"%s\".",
|
||||
"Failed to save undo information\n",
|
||||
buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!content_save_state(path))
|
||||
{
|
||||
@ -1494,9 +1512,27 @@ static void command_event_save_state(const char *path,
|
||||
*
|
||||
* Loads a state with path being @path.
|
||||
**/
|
||||
static void command_event_load_state(const char *path, char *s, size_t len)
|
||||
static void command_event_load_state(const char *path, char *s, size_t len, bool undo)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
char buf[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
if (!undo)
|
||||
{
|
||||
/* 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.undo", buf);
|
||||
|
||||
if (!content_save_state(buf))
|
||||
{
|
||||
snprintf(s, len, "%s \"%s\".",
|
||||
"Failed to save undo information\n",
|
||||
buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!content_load_state(path))
|
||||
{
|
||||
@ -1509,15 +1545,18 @@ static void command_event_load_state(const char *path, char *s, size_t len)
|
||||
if (settings->state_slot < 0)
|
||||
snprintf(s, len, "%s #-1 (auto).",
|
||||
msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT));
|
||||
else
|
||||
else if (!undo)
|
||||
snprintf(s, len, "%s #%d.", msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT),
|
||||
settings->state_slot);
|
||||
else
|
||||
snprintf(s, len, "%s #-1 (undo).", msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT));
|
||||
}
|
||||
|
||||
static void command_event_main_state(unsigned cmd)
|
||||
{
|
||||
retro_ctx_size_info_t info;
|
||||
char path[PATH_MAX_LENGTH] = {0};
|
||||
char buf[PATH_MAX_LENGTH] = {0};
|
||||
char msg[128] = {0};
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
@ -1541,7 +1580,19 @@ static void command_event_main_state(unsigned cmd)
|
||||
command_event_save_state(path, msg, sizeof(msg));
|
||||
break;
|
||||
case CMD_EVENT_LOAD_STATE:
|
||||
command_event_load_state(path, msg, sizeof(msg));
|
||||
command_event_load_state(path, msg, sizeof(msg), false);
|
||||
break;
|
||||
case CMD_EVENT_UNDO_LOAD_STATE:
|
||||
strlcpy(buf, path, sizeof(buf));
|
||||
path_remove_extension(buf);
|
||||
snprintf(buf, sizeof(buf), "%s.undo", buf);
|
||||
command_event_load_state(buf, msg, sizeof(msg), true);
|
||||
break;
|
||||
case CMD_EVENT_UNDO_SAVE_STATE:
|
||||
strlcpy(buf, path, sizeof(buf));
|
||||
path_remove_extension(buf);
|
||||
snprintf(buf, sizeof(buf), "%s.last", buf);
|
||||
command_event_load_state(buf, msg, sizeof(msg), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1661,6 +1712,12 @@ bool command_event(enum event_command cmd, void *data)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
command_event_main_state(cmd);
|
||||
break;
|
||||
case CMD_EVENT_UNDO_LOAD_STATE:
|
||||
command_event_main_state(cmd);
|
||||
break;
|
||||
case CMD_EVENT_UNDO_SAVE_STATE:
|
||||
command_event_main_state(cmd);
|
||||
break;
|
||||
case CMD_EVENT_RESIZE_WINDOWED_SCALE:
|
||||
|
@ -48,6 +48,8 @@ enum event_command
|
||||
CMD_EVENT_LOAD_CORE_PERSIST,
|
||||
CMD_EVENT_UNLOAD_CORE,
|
||||
CMD_EVENT_LOAD_STATE,
|
||||
CMD_EVENT_UNDO_LOAD_STATE,
|
||||
CMD_EVENT_UNDO_SAVE_STATE,
|
||||
CMD_EVENT_SAVE_STATE,
|
||||
CMD_EVENT_SAVE_STATE_DECREMENT,
|
||||
CMD_EVENT_SAVE_STATE_INCREMENT,
|
||||
|
@ -51,6 +51,12 @@ 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);
|
||||
|
||||
bool content_does_not_need_content(void);
|
||||
|
||||
void content_set_does_not_need_content(void);
|
||||
|
@ -1272,8 +1272,7 @@ static int action_ok_load_state(const char *path,
|
||||
if (generic_action_ok_command(CMD_EVENT_LOAD_STATE) == -1)
|
||||
return menu_cbs_exit();
|
||||
return generic_action_ok_command(CMD_EVENT_RESUME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int action_ok_save_state(const char *path,
|
||||
const char *label, unsigned type, size_t idx, size_t entry_idx)
|
||||
@ -1283,6 +1282,22 @@ static int action_ok_save_state(const char *path,
|
||||
return generic_action_ok_command(CMD_EVENT_RESUME);
|
||||
}
|
||||
|
||||
static int action_ok_undo_load_state(const char *path,
|
||||
const char *label, unsigned type, size_t idx, size_t entry_idx)
|
||||
{
|
||||
if (generic_action_ok_command(CMD_EVENT_UNDO_LOAD_STATE) == -1)
|
||||
return menu_cbs_exit();
|
||||
return generic_action_ok_command(CMD_EVENT_RESUME);
|
||||
}
|
||||
|
||||
static int action_ok_undo_save_state(const char *path,
|
||||
const char *label, unsigned type, size_t idx, size_t entry_idx)
|
||||
{
|
||||
if (generic_action_ok_command(CMD_EVENT_UNDO_SAVE_STATE) == -1)
|
||||
return menu_cbs_exit();
|
||||
return generic_action_ok_command(CMD_EVENT_RESUME);
|
||||
}
|
||||
|
||||
#ifdef HAVE_NETWORKING
|
||||
#ifdef HAVE_ZLIB
|
||||
static void cb_decompressed(void *task_data, void *user_data, const char *err)
|
||||
@ -2373,6 +2388,12 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs,
|
||||
case MENU_LABEL_LOADSTATE:
|
||||
BIND_ACTION_OK(cbs, action_ok_load_state);
|
||||
break;
|
||||
case MENU_LABEL_UNDOLOADSTATE:
|
||||
BIND_ACTION_OK(cbs, action_ok_undo_load_state);
|
||||
break;
|
||||
case MENU_LABEL_UNDOSAVESTATE:
|
||||
BIND_ACTION_OK(cbs, action_ok_undo_save_state);
|
||||
break;
|
||||
case MENU_LABEL_RESUME_CONTENT:
|
||||
BIND_ACTION_OK(cbs, action_ok_resume_content);
|
||||
break;
|
||||
|
@ -658,6 +658,10 @@ static const char *menu_hash_to_str_us_label(uint32_t hash)
|
||||
return "savestate";
|
||||
case MENU_LABEL_LOAD_STATE:
|
||||
return "loadstate";
|
||||
case MENU_LABEL_UNDO_LOAD_STATE:
|
||||
return "undoloadstate";
|
||||
case MENU_LABEL_UNDO_SAVE_STATE:
|
||||
return "undosavestate";
|
||||
case MENU_LABEL_RESUME_CONTENT:
|
||||
return "resume_content";
|
||||
case MENU_LABEL_INPUT_DRIVER:
|
||||
@ -1374,6 +1378,10 @@ const char *menu_hash_to_str_us(uint32_t hash)
|
||||
return "Save State";
|
||||
case MENU_LABEL_VALUE_LOAD_STATE:
|
||||
return "Load State";
|
||||
case MENU_LABEL_VALUE_UNDO_LOAD_STATE:
|
||||
return "Undo Load State";
|
||||
case MENU_LABEL_VALUE_UNDO_SAVE_STATE:
|
||||
return "Undo Save State";
|
||||
case MENU_LABEL_VALUE_RESUME_CONTENT:
|
||||
return "Resume";
|
||||
case MENU_LABEL_VALUE_INPUT_DRIVER:
|
||||
|
@ -2282,6 +2282,16 @@ static int menu_displaylist_parse_load_content_settings(
|
||||
menu_hash_to_str(MENU_LABEL_LOAD_STATE),
|
||||
MENU_SETTING_ACTION_LOADSTATE, 0, 0);
|
||||
|
||||
menu_entries_add(info->list,
|
||||
menu_hash_to_str(MENU_LABEL_VALUE_UNDO_LOAD_STATE),
|
||||
menu_hash_to_str(MENU_LABEL_UNDO_LOAD_STATE),
|
||||
MENU_SETTING_ACTION_LOADSTATE, 0, 0);
|
||||
|
||||
menu_entries_add(info->list,
|
||||
menu_hash_to_str(MENU_LABEL_VALUE_UNDO_SAVE_STATE),
|
||||
menu_hash_to_str(MENU_LABEL_UNDO_SAVE_STATE),
|
||||
MENU_SETTING_ACTION_LOADSTATE, 0, 0);
|
||||
|
||||
menu_entries_add(info->list,
|
||||
menu_hash_to_str(MENU_LABEL_VALUE_CORE_OPTIONS),
|
||||
menu_hash_to_str(MENU_LABEL_CORE_OPTIONS),
|
||||
|
@ -298,8 +298,12 @@ RETRO_BEGIN_DECLS
|
||||
#define MENU_LABEL_VALUE_NO_CORES_AVAILABLE 0xe16bfd0dU
|
||||
#define MENU_LABEL_SAVE_STATE 0x3a4849b5U
|
||||
#define MENU_LABEL_VALUE_LOAD_STATE 0xd23ba706U
|
||||
#define MENU_LABEL_VALUE_UNDO_LOAD_STATE 0xc83f09fcU
|
||||
#define MENU_LABEL_VALUE_UNDO_SAVE_STATE 0x341b870bU
|
||||
#define MENU_LABEL_VALUE_SAVE_STATE 0x3e182415U
|
||||
#define MENU_LABEL_LOAD_STATE 0xa39eb286U
|
||||
#define MENU_LABEL_UNDO_LOAD_STATE 0x464aaf5cU
|
||||
#define MENU_LABEL_UNDO_SAVE_STATE 0xdcf4468bU
|
||||
#define MENU_LABEL_REWIND 0x1931d5aeU
|
||||
#define MENU_LABEL_NETPLAY_FLIP_PLAYERS 0x801425abU
|
||||
#define MENU_LABEL_CHEAT_INDEX_MINUS 0x57f58b6cU
|
||||
@ -955,6 +959,8 @@ RETRO_BEGIN_DECLS
|
||||
#define MENU_LABEL_CUSTOM_BIND_DEFAULTS 0xe88f7b13U
|
||||
#define MENU_LABEL_SAVESTATE 0x3a4849b5U
|
||||
#define MENU_LABEL_LOADSTATE 0xa39eb286U
|
||||
#define MENU_LABEL_UNDOLOADSTATE 0x464aaf5cU
|
||||
#define MENU_LABEL_UNDOSAVESTATE 0xdcf4468bU
|
||||
#define MENU_LABEL_RESUME_CONTENT 0xd9f088b0U
|
||||
#define MENU_LABEL_VALUE_RESUME_CONTENT 0xae6e5911U
|
||||
#define MENU_LABEL_VALUE_RESUME 0xce8ac2f6U
|
||||
|
@ -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…
x
Reference in New Issue
Block a user