diff --git a/command.c b/command.c index 3a69e11525..63e5ff9d90 100644 --- a/command.c +++ b/command.c @@ -1600,7 +1600,7 @@ static void command_event_undo_save_state(char *s, size_t len) if (!content_undo_save_state()) { snprintf(s, len, "%s \"%s\".", - msg_hash_to_str(MSG_FAILED_TO_SAVE_UNDO), + msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE), "from internal buffer"); } } @@ -1638,7 +1638,7 @@ static void command_event_undo_load_state(char *s, size_t len) if (!content_undo_load_state()) { snprintf(s, len, "%s \"%s\".", - msg_hash_to_str(MSG_FAILED_TO_LOAD_UNDO), + msg_hash_to_str(MSG_FAILED_TO_UNDO_LOAD_STATE), "from internal buffer"); } } diff --git a/internal buffer b/internal buffer new file mode 100644 index 0000000000..84b907ed8e Binary files /dev/null and b/internal buffer differ diff --git a/intl/msg_hash_us.c b/intl/msg_hash_us.c index 5c331af928..201d20f599 100644 --- a/intl/msg_hash_us.c +++ b/intl/msg_hash_us.c @@ -112,13 +112,13 @@ const char *msg_hash_to_str_us(uint32_t hash) case MSG_RESET: return "Reset"; case MSG_FAILED_TO_LOAD_STATE: - return "Failed to load state from"; + return "Nothing to undo."; case MSG_FAILED_TO_SAVE_STATE_TO: return "Failed to save state to"; - case MSG_FAILED_TO_LOAD_UNDO: - return "No undo state found"; - case MSG_FAILED_TO_SAVE_UNDO: - return "Failed to save undo information"; + case MSG_FAILED_TO_UNDO_LOAD_STATE: + return "Failed to undo load state."; + case MSG_FAILED_TO_UNDO_SAVE_STATE: + return "Failed to undo save state."; case MSG_FAILED_TO_SAVE_SRAM: return "Failed to save SRAM"; case MSG_STATE_SIZE: diff --git a/msg_hash.h b/msg_hash.h index 03a11f6b4d..d9481d08ac 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -125,8 +125,8 @@ #define MSG_CORE_DOES_NOT_SUPPORT_SAVESTATES 0xd50adf46U #define MSG_FAILED_TO_LOAD_STATE 0x91f348ebU -#define MSG_FAILED_TO_LOAD_UNDO 0xb6e2fc55U -#define MSG_FAILED_TO_SAVE_UNDO 0xf2e29478U +#define MSG_FAILED_TO_UNDO_LOAD_STATE 0xb6e2fc55U +#define MSG_FAILED_TO_UNDO_SAVE_STATE 0xf2e29478U #define MSG_RESET 0x10474288U diff --git a/tasks/task_save_state.c b/tasks/task_save_state.c index 67da9363ae..932727c3dc 100644 --- a/tasks/task_save_state.c +++ b/tasks/task_save_state.c @@ -64,6 +64,9 @@ struct sram_block bool content_undo_load_state() { + if (old_state_buf.data == NULL) + return false; + unsigned i; //ssize_t size; retro_ctx_serialize_info_t serial_info; @@ -78,9 +81,6 @@ bool content_undo_load_state() msg_hash_to_str(MSG_LOADING_STATE), "from internal buffer"); - if (old_state_buf.size == 0) - return true; - RARCH_LOG("%s: %u %s.\n", msg_hash_to_str(MSG_STATE_SIZE), old_state_buf.size, @@ -165,7 +165,7 @@ bool content_undo_load_state() if (!ret) RARCH_ERR("%s \"%s\".\n", - msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE), + msg_hash_to_str(MSG_FAILED_TO_UNDO_LOAD_STATE), "from internal buffer"); /* Wipe the old state buffer, it's meant to be one use only */ @@ -193,6 +193,11 @@ bool content_undo_save_state() old_save_file.data = 0; + if (!ret) + RARCH_ERR("%s \"%s\".\n", + msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE), + "from internal buffer"); + return ret; } @@ -202,7 +207,7 @@ bool content_undo_save_state() /** * save_state: * @path : path of saved state that shall be written to. - * + * @save_to_disk: If false, saves the state onto old_state_buf. * Save a state from memory to disk. * * Returns: true if successful, false otherwise. @@ -278,13 +283,15 @@ bool content_save_state_with_backup(const char *path, bool save_to_disk) /** * content_load_state: * @path : path that state will be loaded from. - * + * @load_to_backup_buffer: If true, the state will be loaded into old_save_file. * Load a state from disk to memory. * * Returns: true if successful, false otherwise. + * + * **/ bool content_load_state(const char* path) { content_load_state_with_backup(path, false); } -bool content_load_state_with_backup(const char *path, bool save_to_backup_buffer) +bool content_load_state_with_backup(const char *path, bool load_to_backup_buffer) { unsigned i; ssize_t size; @@ -310,7 +317,7 @@ bool content_load_state_with_backup(const char *path, bool save_to_backup_buffer /* This means we're backing up the file in memory, so content_undo_save_state() can restore it */ - if (save_to_backup_buffer) { + if (load_to_backup_buffer) { strcpy(old_save_file.path, path); /* If we were previously backing up a file, let go of it first */ @@ -381,7 +388,7 @@ bool content_load_state_with_backup(const char *path, bool save_to_backup_buffer serial_info.size = size; /* Backup the current state so we can undo this load */ - content_save_state_with_backup(NULL, true); + content_save_state_with_backup("internal buffer", false); ret = core_unserialize(&serial_info); /* Flush back. */