From 8e20b9e938ec4b3a1e63d0291668a52e1c3965a2 Mon Sep 17 00:00:00 2001 From: Arzed Five Date: Fri, 10 Jun 2016 20:12:43 +0100 Subject: [PATCH] Both Undo options now write distinct messages in the OSD when buffers are empty, when undoing fails and when undoing is successful. Aside from some TODO/FIXME areas added by this fork, the features in the fork are now complete. --- command.c | 29 ++++++++++++++++++++++++++++- content.h | 4 ++++ tasks/task_save_state.c | 37 +++++++++++-------------------------- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/command.c b/command.c index 1d06aa6611..f0f71f53ad 100644 --- a/command.c +++ b/command.c @@ -1597,12 +1597,25 @@ static void command_event_save_state(const char *path, static void command_event_undo_save_state(char *s, size_t len) { + if (content_undo_save_buf_is_empty()) + { + /* TODO/FIXME - use msg_hash_to_str here */ + snprintf(s, len, "%s", + "No save state has been overwritten yet."); + return; + } + if (!content_undo_save_state()) { snprintf(s, len, "%s \"%s\".", msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE), "RAM"); + return; } + + /* TODO/FIXME - use msg_hash_to_str here */ + snprintf(s, len, "%s", + "Restored old save state."); } /** @@ -1635,12 +1648,26 @@ static void command_event_load_state(const char *path, char *s, size_t len) static void command_event_undo_load_state(char *s, size_t len) { + + if (content_undo_load_buf_is_empty()) + { + /* TODO/FIXME - use msg_hash_to_str here */ + snprintf(s, len, "%s", + "No state has been loaded yet."); + return; + } + if (!content_undo_load_state()) { snprintf(s, len, "%s \"%s\".", msg_hash_to_str(MSG_FAILED_TO_UNDO_LOAD_STATE), "RAM"); - } + return; + } + + /* TODO/FIXME - use msg_hash_to_str here */ + snprintf(s, len, "%s", + "Undid load state."); } static void command_event_main_state(unsigned cmd) diff --git a/content.h b/content.h index 4292f4e022..c50773aaed 100644 --- a/content.h +++ b/content.h @@ -79,6 +79,10 @@ bool content_init(void); /* Resets the state and savefile backup buffers */ bool content_reset_savestate_backups(); +/* Checks if the buffers are empty */ +bool content_undo_load_buf_is_empty(); +bool content_undo_save_buf_is_empty(); + RETRO_END_DECLS #endif diff --git a/tasks/task_save_state.c b/tasks/task_save_state.c index 78a23bb7b4..366eb92d62 100644 --- a/tasks/task_save_state.c +++ b/tasks/task_save_state.c @@ -65,18 +65,6 @@ struct sram_block **/ bool content_undo_load_state() { - if (undo_load_buf.data == NULL || undo_load_buf.size == 0) { - /* TODO/FIXME - Use msg_hash_to_str in here */ - /* TODO/FIXME - Should we be using runloop_msg_queue_push in here? */ - - RARCH_LOG("%s\n", - "No load state to undo."); - runloop_msg_queue_push("No load state to undo.", 2, 180, true); - - /* Even though there was no undo, signal this as a success */ - return true; - } - unsigned i; //ssize_t size; retro_ctx_serialize_info_t serial_info; @@ -191,9 +179,7 @@ bool content_undo_load_state() RARCH_ERR("%s \"%s\".\n", msg_hash_to_str(MSG_FAILED_TO_UNDO_LOAD_STATE), undo_load_buf.path); - } else { - runloop_msg_queue_push("Undid load state.", 2, 180, true); - } + } return ret; } @@ -206,15 +192,6 @@ bool content_undo_load_state() **/ bool content_undo_save_state() { - if (undo_save_buf.data == NULL || undo_save_buf.size == 0) - { - /* TODO/FIXME - Use msg_hash_to_str in here */ - RARCH_LOG("%s\n", - "No save state to undo."); - runloop_msg_queue_push("No save state to undo.", 2, 180, false); - return true; - } - bool ret = filestream_write_file(undo_save_buf.path, undo_save_buf.data, undo_save_buf.size); /* Wipe the save file buffer as it's intended to be one use only */ @@ -230,8 +207,6 @@ bool content_undo_save_state() RARCH_ERR("%s \"%s\".\n", msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE), undo_save_buf.path); - } else { - runloop_msg_queue_push("Undid save state.", 2, 180, true); } return ret; @@ -512,3 +487,13 @@ bool content_reset_savestate_backups() return true; } + +bool content_undo_load_buf_is_empty() +{ + return undo_load_buf.data == NULL || undo_load_buf.size == 0; +} + +bool content_undo_save_buf_is_empty() +{ + return undo_save_buf.data == NULL || undo_save_buf.size == 0; +}