mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 16:13:40 +00:00
commit
09284dc6ce
@ -555,33 +555,6 @@ static void task_save_handler_finished(retro_task_t *task,
|
|||||||
free(state);
|
free(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* get_serialized_data(const char *path, size_t serial_size)
|
|
||||||
{
|
|
||||||
retro_ctx_serialize_info_t serial_info;
|
|
||||||
bool ret = false;
|
|
||||||
void *data = NULL;
|
|
||||||
|
|
||||||
data = malloc(serial_size);
|
|
||||||
|
|
||||||
if (!data)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
RARCH_LOG("%s: %d %s.\n",
|
|
||||||
msg_hash_to_str(MSG_STATE_SIZE),
|
|
||||||
(int)serial_size,
|
|
||||||
msg_hash_to_str(MSG_BYTES));
|
|
||||||
|
|
||||||
serial_info.data = data;
|
|
||||||
serial_info.size = serial_size;
|
|
||||||
ret = core_serialize(&serial_info);
|
|
||||||
if ( !ret )
|
|
||||||
{
|
|
||||||
free(data) ;
|
|
||||||
return NULL ;
|
|
||||||
}
|
|
||||||
return data ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* task_save_handler:
|
* task_save_handler:
|
||||||
* @task : the task being worked on
|
* @task : the task being worked on
|
||||||
@ -603,22 +576,9 @@ static void task_save_handler(retro_task_t *task)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state->data)
|
|
||||||
{
|
|
||||||
state->data = get_serialized_data(state->path, state->size) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
remaining = MIN(state->size - state->written, SAVE_STATE_CHUNK);
|
remaining = MIN(state->size - state->written, SAVE_STATE_CHUNK);
|
||||||
|
written = (int)intfstream_write(state->file,
|
||||||
if ( state->data )
|
(uint8_t*)state->data + state->written, remaining);
|
||||||
{
|
|
||||||
written = (int)intfstream_write(state->file,
|
|
||||||
(uint8_t*)state->data + state->written, remaining);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
written = 0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
state->written += written;
|
state->written += written;
|
||||||
|
|
||||||
@ -1050,7 +1010,7 @@ static void save_state_cb(void *task_data,
|
|||||||
char *path = strdup(state->path);
|
char *path = strdup(state->path);
|
||||||
|
|
||||||
if (state->thumbnail_enable)
|
if (state->thumbnail_enable)
|
||||||
take_screenshot(path, true, state->has_valid_framebuffer, false, true);
|
take_screenshot(path, true, state->has_valid_framebuffer);
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
@ -1174,7 +1134,6 @@ error:
|
|||||||
free(task);
|
free(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* content_save_state:
|
* content_save_state:
|
||||||
* @path : path of saved state that shall be written to.
|
* @path : path of saved state that shall be written to.
|
||||||
@ -1185,61 +1144,85 @@ error:
|
|||||||
**/
|
**/
|
||||||
bool content_save_state(const char *path, bool save_to_disk, bool autosave)
|
bool content_save_state(const char *path, bool save_to_disk, bool autosave)
|
||||||
{
|
{
|
||||||
//retro_ctx_serialize_info_t serial_info;
|
retro_ctx_serialize_info_t serial_info;
|
||||||
retro_ctx_size_info_t info;
|
retro_ctx_size_info_t info;
|
||||||
|
bool ret = false;
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
|
|
||||||
core_serialize_size(&info);
|
core_serialize_size(&info);
|
||||||
|
|
||||||
if (save_to_disk)
|
RARCH_LOG("%s: \"%s\".\n",
|
||||||
{
|
msg_hash_to_str(MSG_SAVING_STATE),
|
||||||
if (filestream_exists(path) && !autosave)
|
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",
|
|
||||||
msg_hash_to_str(MSG_FILE_ALREADY_EXISTS_SAVING_TO_BACKUP_BUFFER));
|
|
||||||
|
|
||||||
task_push_load_and_save_state(path, data, info.size, true, autosave);
|
if (info.size == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
data = malloc(info.size);
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
RARCH_LOG("%s: %d %s.\n",
|
||||||
|
msg_hash_to_str(MSG_STATE_SIZE),
|
||||||
|
(int)info.size,
|
||||||
|
msg_hash_to_str(MSG_BYTES));
|
||||||
|
|
||||||
|
serial_info.data = data;
|
||||||
|
serial_info.size = info.size;
|
||||||
|
ret = core_serialize(&serial_info);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
if (save_to_disk)
|
||||||
|
{
|
||||||
|
if (filestream_exists(path) && !autosave)
|
||||||
|
{
|
||||||
|
/* 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",
|
||||||
|
msg_hash_to_str(MSG_FILE_ALREADY_EXISTS_SAVING_TO_BACKUP_BUFFER));
|
||||||
|
|
||||||
|
task_push_load_and_save_state(path, data, info.size, true, autosave);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
task_push_save_state(path, data, info.size, autosave);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
task_push_save_state(path, data, info.size, autosave);
|
{
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
free(undo_load_buf.data);
|
||||||
|
undo_load_buf.data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
undo_load_buf.data = malloc(info.size);
|
||||||
|
if (!undo_load_buf.data)
|
||||||
|
{
|
||||||
|
free(data);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(undo_load_buf.data, data, info.size);
|
||||||
|
free(data);
|
||||||
|
undo_load_buf.size = info.size;
|
||||||
|
strlcpy(undo_load_buf.path, path, sizeof(undo_load_buf.path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data = get_serialized_data(path, info.size) ;
|
|
||||||
if ( data == NULL )
|
|
||||||
{
|
|
||||||
RARCH_ERR("%s \"%s\".\n",
|
|
||||||
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
|
|
||||||
path);
|
|
||||||
return false ;
|
|
||||||
}
|
|
||||||
/* 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)
|
|
||||||
{
|
|
||||||
free(undo_load_buf.data);
|
|
||||||
undo_load_buf.data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
undo_load_buf.data = malloc(info.size);
|
|
||||||
if (!undo_load_buf.data)
|
|
||||||
{
|
|
||||||
free(data);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(undo_load_buf.data, data, info.size);
|
|
||||||
free(data);
|
free(data);
|
||||||
undo_load_buf.size = info.size;
|
RARCH_ERR("%s \"%s\".\n",
|
||||||
strlcpy(undo_load_buf.path, path, sizeof(undo_load_buf.path));
|
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
|
||||||
|
path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user