mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-23 11:12:33 +00:00
Cleanup tasks_save_ram.c
This commit is contained in:
parent
4a0334b4fa
commit
2559139154
21
command.c
21
command.c
@ -1094,13 +1094,7 @@ static bool event_load_save_files(void)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < global->savefiles->size; i++)
|
for (i = 0; i < global->savefiles->size; i++)
|
||||||
{
|
content_load_ram_file(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2084,18 +2078,7 @@ bool command_event(enum event_command cmd, void *data)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < global->savefiles->size; i++)
|
for (i = 0; i < global->savefiles->size; i++)
|
||||||
{
|
content_save_ram_file(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case CMD_EVENT_SAVEFILES_DEINIT:
|
case CMD_EVENT_SAVEFILES_DEINIT:
|
||||||
|
10
content.h
10
content.h
@ -30,11 +30,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct ram_type
|
typedef struct ram_type ram_type_t;
|
||||||
{
|
|
||||||
const char *path;
|
|
||||||
int type;
|
|
||||||
} ram_type_t;
|
|
||||||
|
|
||||||
typedef struct content_ctx_info
|
typedef struct content_ctx_info
|
||||||
{
|
{
|
||||||
@ -45,10 +41,10 @@ typedef struct content_ctx_info
|
|||||||
} content_ctx_info_t;
|
} content_ctx_info_t;
|
||||||
|
|
||||||
/* Load a RAM state from disk to memory. */
|
/* 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. */
|
/* 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. */
|
/* Load a state from disk to memory. */
|
||||||
bool content_load_state(const char *path);
|
bool content_load_state(const char *path);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <lists/string_list.h>
|
||||||
#include <streams/file_stream.h>
|
#include <streams/file_stream.h>
|
||||||
|
|
||||||
#include "../core.h"
|
#include "../core.h"
|
||||||
@ -29,6 +30,12 @@
|
|||||||
|
|
||||||
/* TODO/FIXME - turn this into actual task */
|
/* TODO/FIXME - turn this into actual task */
|
||||||
|
|
||||||
|
struct ram_type
|
||||||
|
{
|
||||||
|
const char *path;
|
||||||
|
int type;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* content_load_ram_file:
|
* content_load_ram_file:
|
||||||
* @path : path of RAM state that will be loaded from.
|
* @path : path of RAM state that will be loaded from.
|
||||||
@ -36,23 +43,25 @@
|
|||||||
*
|
*
|
||||||
* Load a RAM state from disk to memory.
|
* 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;
|
ssize_t rc;
|
||||||
|
ram_type_t ram;
|
||||||
retro_ctx_memory_info_t mem_info;
|
retro_ctx_memory_info_t mem_info;
|
||||||
void *buf = NULL;
|
global_t *global = global_get_ptr();
|
||||||
|
void *buf = NULL;
|
||||||
|
|
||||||
if (!ram)
|
ram.path = global->savefiles->elems[slot].data;
|
||||||
return false;
|
ram.type = global->savefiles->elems[slot].attr.i;
|
||||||
|
|
||||||
mem_info.id = ram->type;
|
mem_info.id = ram.type;
|
||||||
|
|
||||||
core_get_memory(&mem_info);
|
core_get_memory(&mem_info);
|
||||||
|
|
||||||
if (mem_info.size == 0 || !mem_info.data)
|
if (mem_info.size == 0 || !mem_info.data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!filestream_read_file(ram->path, &buf, &rc))
|
if (!filestream_read_file(ram.path, &buf, &rc))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (rc > 0)
|
if (rc > 0)
|
||||||
@ -84,21 +93,32 @@ bool content_load_ram_file(ram_type_t *ram)
|
|||||||
* Save a RAM state from memory to disk.
|
* 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;
|
retro_ctx_memory_info_t mem_info;
|
||||||
|
ram_type_t ram;
|
||||||
|
global_t *global = global_get_ptr();
|
||||||
|
|
||||||
if (!ram)
|
if (!global)
|
||||||
return false;
|
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);
|
core_get_memory(&mem_info);
|
||||||
|
|
||||||
if (!mem_info.data || mem_info.size == 0)
|
if (!mem_info.data || mem_info.size == 0)
|
||||||
return false;
|
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",
|
RARCH_ERR("%s.\n",
|
||||||
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
|
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,
|
/* In case the file could not be written to,
|
||||||
* the fallback function 'dump_to_file_desperate'
|
* the fallback function 'dump_to_file_desperate'
|
||||||
* will be called. */
|
* 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");
|
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",
|
RARCH_LOG("%s \"%s\".\n",
|
||||||
msg_hash_to_str(MSG_SAVED_SUCCESSFULLY_TO),
|
msg_hash_to_str(MSG_SAVED_SUCCESSFULLY_TO),
|
||||||
ram->path);
|
ram.path);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -141,12 +141,8 @@ void rarch_task_file_load_handler(retro_task_t *task);
|
|||||||
|
|
||||||
/* TODO/FIXME - turn this into actual task */
|
/* TODO/FIXME - turn this into actual task */
|
||||||
bool take_screenshot(void);
|
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,
|
bool dump_to_file_desperate(const void *data,
|
||||||
size_t size, unsigned type);
|
size_t size, unsigned type);
|
||||||
bool content_save_state(const char *path);
|
|
||||||
bool content_load_state(const char *path);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user