mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 03:32:46 +00:00
(task_save.c) Move to intfstream
This commit is contained in:
parent
1cd7568f1f
commit
32511090ca
@ -92,6 +92,8 @@ int intfstream_close(intfstream_internal_t *intf);
|
||||
|
||||
int64_t intfstream_get_size(intfstream_internal_t *intf);
|
||||
|
||||
int intfstream_flush(intfstream_internal_t *intf);
|
||||
|
||||
intfstream_t* intfstream_open_file(const char *path,
|
||||
unsigned mode, unsigned hints);
|
||||
|
||||
|
@ -133,6 +133,24 @@ bool intfstream_open(intfstream_internal_t *intf, const char *path,
|
||||
return true;
|
||||
}
|
||||
|
||||
int intfstream_flush(intfstream_internal_t *intf)
|
||||
{
|
||||
if (!intf)
|
||||
return -1;
|
||||
|
||||
switch (intf->type)
|
||||
{
|
||||
case INTFSTREAM_FILE:
|
||||
return filestream_flush(intf->file.fp);
|
||||
case INTFSTREAM_MEMORY:
|
||||
case INTFSTREAM_CHD:
|
||||
/* Should we stub this for these interfaces? */
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int intfstream_close(intfstream_internal_t *intf)
|
||||
{
|
||||
if (!intf)
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <compat/strl.h>
|
||||
#include <retro_assert.h>
|
||||
#include <lists/string_list.h>
|
||||
#include <streams/interface_stream.h>
|
||||
#include <streams/file_stream.h>
|
||||
#include <rthreads/rthreads.h>
|
||||
#include <file/file_path.h>
|
||||
@ -78,7 +79,7 @@ struct sram_block
|
||||
|
||||
typedef struct
|
||||
{
|
||||
RFILE *file;
|
||||
intfstream_t *file;
|
||||
char path[PATH_MAX_LENGTH];
|
||||
void *data;
|
||||
void *undo_data;
|
||||
@ -157,7 +158,7 @@ static void autosave_thread(void *data)
|
||||
if (differ)
|
||||
{
|
||||
/* Should probably deal with this more elegantly. */
|
||||
RFILE *file = filestream_open(save->path,
|
||||
intfstream_t *file = intfstream_open_file(save->path,
|
||||
RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
|
||||
if (file)
|
||||
@ -174,9 +175,9 @@ static void autosave_thread(void *data)
|
||||
else
|
||||
RARCH_LOG("SRAM changed ... autosaving ...\n");
|
||||
|
||||
failed |= ((size_t)filestream_write(file, save->buffer, save->bufsize) != save->bufsize);
|
||||
failed |= (filestream_flush(file) != 0);
|
||||
failed |= (filestream_close(file) != 0);
|
||||
failed |= ((size_t)intfstream_write(file, save->buffer, save->bufsize) != save->bufsize);
|
||||
failed |= (intfstream_flush(file) != 0);
|
||||
failed |= (intfstream_close(file) != 0);
|
||||
if (failed)
|
||||
RARCH_WARN("Failed to autosave SRAM. Disk might be full.\n");
|
||||
}
|
||||
@ -530,7 +531,7 @@ static void task_save_handler_finished(retro_task_t *task,
|
||||
|
||||
task_set_finished(task, true);
|
||||
|
||||
filestream_close(state->file);
|
||||
intfstream_close(state->file);
|
||||
|
||||
if (!task_get_error(task) && task_get_cancelled(task))
|
||||
task_set_error(task, strdup("Task canceled"));
|
||||
@ -565,7 +566,7 @@ static void task_save_handler(retro_task_t *task)
|
||||
|
||||
if (!state->file)
|
||||
{
|
||||
state->file = filestream_open(state->path, RETRO_VFS_FILE_ACCESS_WRITE,
|
||||
state->file = intfstream_open_file(state->path, RETRO_VFS_FILE_ACCESS_WRITE,
|
||||
RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
|
||||
if (!state->file)
|
||||
@ -573,7 +574,7 @@ static void task_save_handler(retro_task_t *task)
|
||||
}
|
||||
|
||||
remaining = MIN(state->size - state->written, SAVE_STATE_CHUNK);
|
||||
written = (int)filestream_write(state->file,
|
||||
written = (int)intfstream_write(state->file,
|
||||
(uint8_t*)state->data + state->written, remaining);
|
||||
|
||||
state->written += written;
|
||||
@ -712,7 +713,7 @@ static void task_load_handler_finished(retro_task_t *task,
|
||||
task_set_finished(task, true);
|
||||
|
||||
if (state->file)
|
||||
filestream_close(state->file);
|
||||
intfstream_close(state->file);
|
||||
|
||||
if (!task_get_error(task) && task_get_cancelled(task))
|
||||
task_set_error(task, strdup("Task canceled"));
|
||||
@ -738,22 +739,22 @@ static void task_load_handler(retro_task_t *task)
|
||||
|
||||
if (!state->file)
|
||||
{
|
||||
state->file = filestream_open(state->path,
|
||||
state->file = intfstream_open_file(state->path,
|
||||
RETRO_VFS_FILE_ACCESS_READ,
|
||||
RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
|
||||
if (!state->file)
|
||||
goto error;
|
||||
|
||||
if (filestream_seek(state->file, 0, SEEK_END) != 0)
|
||||
if (intfstream_seek(state->file, 0, SEEK_END) != 0)
|
||||
goto error;
|
||||
|
||||
state->size = filestream_tell(state->file);
|
||||
state->size = intfstream_tell(state->file);
|
||||
|
||||
if (state->size < 0)
|
||||
goto error;
|
||||
|
||||
filestream_rewind(state->file);
|
||||
intfstream_rewind(state->file);
|
||||
|
||||
state->data = malloc(state->size + 1);
|
||||
|
||||
@ -762,7 +763,7 @@ static void task_load_handler(retro_task_t *task)
|
||||
}
|
||||
|
||||
remaining = MIN(state->size - state->bytes_read, SAVE_STATE_CHUNK);
|
||||
bytes_read = filestream_read(state->file,
|
||||
bytes_read = intfstream_read(state->file,
|
||||
(uint8_t*)state->data + state->bytes_read, remaining);
|
||||
state->bytes_read += bytes_read;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user