mirror of
https://github.com/libretro/RetroArch
synced 2024-12-28 09:29:16 +00:00
Clean up some stuff, add comments, reduce the places where
content_reset_backup_buffers is called, try to make the undo messages nicer. * I'm trying to write to differentiate read/write errors from empty buffer errors. I changed command.c and task_save_state.c so the content_undo funcs are the ones writting the success messages. I was told to use runloop_msg_queue_push() to write to the OSD, but that doesn't seem to be working.
This commit is contained in:
parent
fa883d62fc
commit
83a1d9ac1f
16
command.c
16
command.c
@ -1602,13 +1602,7 @@ static void command_event_undo_save_state(char *s, size_t len)
|
||||
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 and there */
|
||||
snprintf(s, len, "%s",
|
||||
"Restored save state.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1646,11 +1640,7 @@ static void command_event_undo_load_state(char *s, size_t len)
|
||||
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 and there */
|
||||
snprintf(s, len, "%s",
|
||||
"Undid load state.");
|
||||
}
|
||||
}
|
||||
|
||||
static void command_event_main_state(unsigned cmd)
|
||||
@ -1789,7 +1779,6 @@ bool command_event(enum event_command cmd, void *data)
|
||||
#ifndef HAVE_DYNAMIC
|
||||
command_event(CMD_EVENT_QUIT, NULL);
|
||||
#endif
|
||||
content_reset_savestate_backups();
|
||||
break;
|
||||
case CMD_EVENT_LOAD_STATE:
|
||||
/* Immutable - disallow savestate load when
|
||||
@ -2082,6 +2071,7 @@ bool command_event(enum event_command cmd, void *data)
|
||||
break;
|
||||
case CMD_EVENT_CORE_DEINIT:
|
||||
{
|
||||
content_reset_savestate_backups();
|
||||
struct retro_hw_render_callback *hwr =
|
||||
video_driver_get_hw_context();
|
||||
command_event_deinit_core(true);
|
||||
@ -2089,8 +2079,6 @@ bool command_event(enum event_command cmd, void *data)
|
||||
if (hwr)
|
||||
memset(hwr, 0, sizeof(*hwr));
|
||||
|
||||
content_reset_savestate_backups();
|
||||
|
||||
break;
|
||||
}
|
||||
case CMD_EVENT_CORE_INIT:
|
||||
|
@ -65,8 +65,17 @@ struct sram_block
|
||||
**/
|
||||
bool content_undo_load_state()
|
||||
{
|
||||
if (undo_load_buf.data == NULL || undo_load_buf.size == 0)
|
||||
return false;
|
||||
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;
|
||||
@ -80,7 +89,7 @@ bool content_undo_load_state()
|
||||
|
||||
RARCH_LOG("%s: \"%s\".\n",
|
||||
msg_hash_to_str(MSG_LOADING_STATE),
|
||||
"RAM");
|
||||
undo_load_buf.path);
|
||||
|
||||
RARCH_LOG("%s: %u %s.\n",
|
||||
msg_hash_to_str(MSG_STATE_SIZE),
|
||||
@ -178,10 +187,13 @@ bool content_undo_load_state()
|
||||
free(blocks[i].data);
|
||||
free(blocks);
|
||||
|
||||
if (!ret)
|
||||
if (!ret) {
|
||||
RARCH_ERR("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_FAILED_TO_UNDO_LOAD_STATE),
|
||||
"RAM");
|
||||
undo_load_buf.path);
|
||||
} else {
|
||||
runloop_msg_queue_push("Undid load state.", 2, 180, true);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -194,6 +206,15 @@ 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 */
|
||||
@ -205,10 +226,13 @@ bool content_undo_save_state()
|
||||
|
||||
undo_save_buf.data = 0;
|
||||
|
||||
if (!ret)
|
||||
if (!ret) {
|
||||
RARCH_ERR("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE),
|
||||
"RAM");
|
||||
undo_save_buf.path);
|
||||
} else {
|
||||
runloop_msg_queue_push("Undid save state.", 2, 180, true);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -257,16 +281,22 @@ bool content_save_state(const char *path, bool save_to_disk)
|
||||
if (ret) {
|
||||
if (save_to_disk) {
|
||||
if (path_file_exists(path)) {
|
||||
/* Before overwritting the savestate file, load it into a buffer
|
||||
to allow undo_save_state() to work */
|
||||
/* TODO/FIXME - Use msg_hash_to_str here */
|
||||
RARCH_LOG("%s\n",
|
||||
"File already exists. Saving to backup buffer...");
|
||||
|
||||
content_load_state(path, true);
|
||||
}
|
||||
|
||||
ret = filestream_write_file(path, data, info.size);
|
||||
}
|
||||
/* save_to_disk is false, which means we are saving the state
|
||||
in undo_load_buf to allow content_undo_load_state() to restore it */
|
||||
|
||||
else
|
||||
{
|
||||
undo_load_buf.path[0] = '\0';
|
||||
/* save_to_disk is false, which means we are saving the state
|
||||
in undo_load_buf to allow content_undo_load_state() to restore it */
|
||||
|
||||
/* If we were holding onto an old state already, clean it up first */
|
||||
if (undo_load_buf.data) {
|
||||
@ -277,6 +307,7 @@ bool content_save_state(const char *path, bool save_to_disk)
|
||||
undo_load_buf.data = malloc(info.size);
|
||||
memcpy(undo_load_buf.data, data, info.size);
|
||||
undo_load_buf.size = info.size;
|
||||
strcpy(undo_load_buf.path, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user