Add intfstream_get_size

This commit is contained in:
twinaphex 2017-12-11 13:21:44 +01:00
parent 12e6f38999
commit e62e9233d7
4 changed files with 36 additions and 13 deletions

View File

@ -19,6 +19,7 @@
#include <file/file_path.h>
#include <string/stdstring.h>
#include <formats/jsonsax.h>
#include <streams/interface_stream.h>
#include <streams/file_stream.h>
#include <features/features_cpu.h>
#include <compat/strl.h>
@ -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

View File

@ -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

View File

@ -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)

View File

@ -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);