From e62e9233d7a92027c777b3ff637ce41f2c28b89d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 11 Dec 2017 13:21:44 +0100 Subject: [PATCH] Add intfstream_get_size --- cheevos/cheevos.c | 13 +++++++------ .../include/streams/interface_stream.h | 3 +++ libretro-common/streams/interface_stream.c | 19 +++++++++++++++++++ tasks/task_database_cue.c | 14 +++++++------- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 34f7b5e4d4..dae27cbb5c 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -2488,7 +2489,7 @@ typedef struct size_t romsize, bytes; \ int mapper; \ bool round; \ - RFILE* stream; \ + intfstream_t *stream; \ size_t size; \ char url[256]; \ struct http_connection_t *conn; \ @@ -2640,7 +2641,7 @@ static int cheevos_iterate(coro_t* coro) /* Load the content into memory, or copy it over to our own buffer */ if (!CHEEVOS_VAR_DATA) { - CHEEVOS_VAR_STREAM = filestream_open( + CHEEVOS_VAR_STREAM = intfstream_open_file( CHEEVOS_VAR_PATH, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); @@ -2650,7 +2651,7 @@ static int cheevos_iterate(coro_t* coro) CORO_YIELD(); CHEEVOS_VAR_LEN = 0; - CHEEVOS_VAR_COUNT = filestream_get_size(CHEEVOS_VAR_STREAM); + CHEEVOS_VAR_COUNT = intfstream_get_size(CHEEVOS_VAR_STREAM); if (CHEEVOS_VAR_COUNT > CHEEVOS_SIZE_LIMIT) CHEEVOS_VAR_COUNT = CHEEVOS_SIZE_LIMIT; @@ -2659,7 +2660,7 @@ static int cheevos_iterate(coro_t* coro) if (!CHEEVOS_VAR_DATA) { - filestream_close(CHEEVOS_VAR_STREAM); + intfstream_close(CHEEVOS_VAR_STREAM); CORO_STOP(); } @@ -2671,7 +2672,7 @@ static int cheevos_iterate(coro_t* coro) if (to_read > CHEEVOS_VAR_COUNT) to_read = CHEEVOS_VAR_COUNT; - num_read = filestream_read(CHEEVOS_VAR_STREAM, (void*)buffer, to_read); + num_read = intfstream_read(CHEEVOS_VAR_STREAM, (void*)buffer, to_read); if (num_read <= 0) break; @@ -2685,7 +2686,7 @@ static int cheevos_iterate(coro_t* coro) CORO_YIELD(); } - filestream_close(CHEEVOS_VAR_STREAM); + intfstream_close(CHEEVOS_VAR_STREAM); } /* Use the supported extensions as a hint diff --git a/libretro-common/include/streams/interface_stream.h b/libretro-common/include/streams/interface_stream.h index 3a21567d3f..ebcb8fda7d 100644 --- a/libretro-common/include/streams/interface_stream.h +++ b/libretro-common/include/streams/interface_stream.h @@ -90,6 +90,8 @@ void intfstream_putc(intfstream_internal_t *intf, int c); int intfstream_close(intfstream_internal_t *intf); +int64_t intfstream_get_size(intfstream_internal_t *intf); + intfstream_t* intfstream_open_file(const char *path, unsigned mode, unsigned hints); @@ -99,6 +101,7 @@ intfstream_t *intfstream_open_memory(void *data, intfstream_t *intfstream_open_chd_track(const char *path, unsigned mode, unsigned hints, int32_t track); + RETRO_END_DECLS #endif diff --git a/libretro-common/streams/interface_stream.c b/libretro-common/streams/interface_stream.c index 78bb4c525a..fb34bb3657 100644 --- a/libretro-common/streams/interface_stream.c +++ b/libretro-common/streams/interface_stream.c @@ -57,6 +57,25 @@ struct intfstream_internal #endif }; +int64_t intfstream_get_size(intfstream_internal_t *intf) +{ + if (!intf) + return 0; + + switch (intf->type) + { + case INTFSTREAM_FILE: + return filestream_get_size(intf->file.fp); + case INTFSTREAM_MEMORY: + return intf->memory.buf.size; + case INTFSTREAM_CHD: + /* TODO/FIXME - implement this */ + break; + } + + return 0; +} + bool intfstream_resize(intfstream_internal_t *intf, intfstream_info_t *info) { if (!intf || !info) diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index 2215d8c975..cb8e366c74 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -410,15 +410,15 @@ clean: return rv; } -static ssize_t get_file_size(const char *path) +static ssize_t intfstream_get_file_size(const char *path) { ssize_t rv; - RFILE *fd = filestream_open(path, + intfstream_t *fd = intfstream_open_file(path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); - if (fd == NULL) + if (!fd) return -1; - rv = filestream_get_size(fd); - filestream_close(fd); + rv = intfstream_get_size(fd); + intfstream_close(fd); return rv; } @@ -503,7 +503,7 @@ int cue_find_track(const char *cue_path, bool first, get_token(fd, tmp_token, MAX_TOKEN_LEN); fill_pathname_join(last_file, cue_dir, tmp_token, PATH_MAX_LENGTH); - file_size = get_file_size(last_file); + file_size = intfstream_get_file_size(last_file); get_token(fd, tmp_token, MAX_TOKEN_LEN); @@ -685,7 +685,7 @@ int gdi_find_track(const char *gdi_path, bool first, fill_pathname_join(last_file, gdi_dir, tmp_token, PATH_MAX_LENGTH); - file_size = get_file_size(last_file); + file_size = intfstream_get_file_size(last_file); if (file_size < 0) { free(gdi_dir);