From 255913915455a4215aebb64f752ad7d4f7d7c0d9 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 17 May 2016 15:32:50 +0200 Subject: [PATCH] Cleanup tasks_save_ram.c --- command.c | 21 ++------------------ content.h | 10 +++------- tasks/task_save_ram.c | 44 ++++++++++++++++++++++++++++++------------ tasks/tasks_internal.h | 4 ---- 4 files changed, 37 insertions(+), 42 deletions(-) diff --git a/command.c b/command.c index 4aa9aa55de..4726a9057a 100644 --- a/command.c +++ b/command.c @@ -1094,13 +1094,7 @@ static bool event_load_save_files(void) return false; for (i = 0; i < global->savefiles->size; i++) - { - ram_type_t ram; - ram.path = global->savefiles->elems[i].data; - ram.type = global->savefiles->elems[i].attr.i; - - content_load_ram_file(&ram); - } + content_load_ram_file(i); return true; } @@ -2084,18 +2078,7 @@ bool command_event(enum event_command cmd, void *data) return false; for (i = 0; i < global->savefiles->size; i++) - { - ram_type_t ram; - ram.type = global->savefiles->elems[i].attr.i; - ram.path = global->savefiles->elems[i].data; - - RARCH_LOG("%s #%u %s \"%s\".\n", - msg_hash_to_str(MSG_SAVING_RAM_TYPE), - ram.type, - msg_hash_to_str(MSG_TO), - ram.path); - content_save_ram_file(&ram); - } + content_save_ram_file(i); } return true; case CMD_EVENT_SAVEFILES_DEINIT: diff --git a/content.h b/content.h index 98c8a69c98..a2f040715e 100644 --- a/content.h +++ b/content.h @@ -30,11 +30,7 @@ extern "C" { #endif -typedef struct ram_type -{ - const char *path; - int type; -} ram_type_t; +typedef struct ram_type ram_type_t; typedef struct content_ctx_info { @@ -45,10 +41,10 @@ typedef struct content_ctx_info } content_ctx_info_t; /* Load a RAM state from disk to memory. */ -bool content_load_ram_file(ram_type_t *ram); +bool content_load_ram_file(unsigned slot); /* Save a RAM state from memory to disk. */ -bool content_save_ram_file(ram_type_t *ram); +bool content_save_ram_file(unsigned slot); /* Load a state from disk to memory. */ bool content_load_state(const char *path); diff --git a/tasks/task_save_ram.c b/tasks/task_save_ram.c index e7b63f7cfa..d32587b53c 100644 --- a/tasks/task_save_ram.c +++ b/tasks/task_save_ram.c @@ -20,6 +20,7 @@ #include #include +#include #include #include "../core.h" @@ -29,6 +30,12 @@ /* TODO/FIXME - turn this into actual task */ +struct ram_type +{ + const char *path; + int type; +}; + /** * content_load_ram_file: * @path : path of RAM state that will be loaded from. @@ -36,23 +43,25 @@ * * Load a RAM state from disk to memory. */ -bool content_load_ram_file(ram_type_t *ram) +bool content_load_ram_file(unsigned slot) { ssize_t rc; + ram_type_t ram; retro_ctx_memory_info_t mem_info; - void *buf = NULL; + global_t *global = global_get_ptr(); + void *buf = NULL; - if (!ram) - return false; + ram.path = global->savefiles->elems[slot].data; + ram.type = global->savefiles->elems[slot].attr.i; - mem_info.id = ram->type; + mem_info.id = ram.type; core_get_memory(&mem_info); if (mem_info.size == 0 || !mem_info.data) return false; - if (!filestream_read_file(ram->path, &buf, &rc)) + if (!filestream_read_file(ram.path, &buf, &rc)) return false; if (rc > 0) @@ -84,21 +93,32 @@ bool content_load_ram_file(ram_type_t *ram) * Save a RAM state from memory to disk. * */ -bool content_save_ram_file(ram_type_t *ram) +bool content_save_ram_file(unsigned slot) { retro_ctx_memory_info_t mem_info; + ram_type_t ram; + global_t *global = global_get_ptr(); - if (!ram) + if (!global) return false; - mem_info.id = ram->type; + ram.type = global->savefiles->elems[slot].attr.i; + ram.path = global->savefiles->elems[slot].data; + + mem_info.id = ram.type; core_get_memory(&mem_info); if (!mem_info.data || mem_info.size == 0) return false; - if (!filestream_write_file(ram->path, mem_info.data, mem_info.size)) + RARCH_LOG("%s #%u %s \"%s\".\n", + msg_hash_to_str(MSG_SAVING_RAM_TYPE), + ram.type, + msg_hash_to_str(MSG_TO), + ram.path); + + if (!filestream_write_file(ram.path, mem_info.data, mem_info.size)) { RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM)); @@ -107,7 +127,7 @@ bool content_save_ram_file(ram_type_t *ram) /* In case the file could not be written to, * the fallback function 'dump_to_file_desperate' * will be called. */ - if (!dump_to_file_desperate(mem_info.data, mem_info.size, ram->type)) + if (!dump_to_file_desperate(mem_info.data, mem_info.size, ram.type)) { RARCH_WARN("Failed ... Cannot recover save file.\n"); } @@ -116,7 +136,7 @@ bool content_save_ram_file(ram_type_t *ram) RARCH_LOG("%s \"%s\".\n", msg_hash_to_str(MSG_SAVED_SUCCESSFULLY_TO), - ram->path); + ram.path); return true; } diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index b819e6011e..8bc731c630 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -141,12 +141,8 @@ void rarch_task_file_load_handler(retro_task_t *task); /* TODO/FIXME - turn this into actual task */ bool take_screenshot(void); -bool content_save_ram_file(ram_type_t *ram); -bool content_load_ram_file(ram_type_t *ram); bool dump_to_file_desperate(const void *data, size_t size, unsigned type); -bool content_save_state(const char *path); -bool content_load_state(const char *path); #ifdef __cplusplus }