use filestream/VFS for core sideload

This commit is contained in:
Brad Parker 2018-12-17 09:25:52 -05:00
parent af0bf7a992
commit 971591fb9c
1 changed files with 19 additions and 12 deletions

View File

@ -1246,13 +1246,13 @@ static int generic_action_ok_command(enum event_command cmd)
/* TO-DO: Localization for errors */ /* TO-DO: Localization for errors */
static bool file_copy(char* src_path, char* dst_path, char* msg, size_t size) static bool file_copy(char* src_path, char* dst_path, char* msg, size_t size)
{ {
RFILE *src, *dst;
FILE *src, *dst;
char buffer[100];
int numr, numw; int numr, numw;
bool ret = true; bool ret = true;
src = fopen(src_path, "rb"); src = filestream_open(src_path,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!src) if (!src)
{ {
@ -1260,25 +1260,30 @@ static bool file_copy(char* src_path, char* dst_path, char* msg, size_t size)
ret = false; ret = false;
} }
dst = fopen(dst_path, "wb"); dst = filestream_open(dst_path,
RETRO_VFS_FILE_ACCESS_WRITE,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!dst) if (!dst)
{ {
strlcpy(msg, "unable to open destination file", size); strlcpy(msg, "unable to open destination file", size);
ret = false; ret = false;
} }
while (!feof(src)) while (!filestream_eof(src))
{ {
memset(buffer, 0, sizeof(buffer)); char buffer[100] = {0};
numr = fread(buffer, 1, 100, src); numr = filestream_read(src, buffer, sizeof(buffer));
if (ferror(dst) != 0)
if (filestream_error(dst) != 0)
{ {
strlcpy(msg, "error reading file\n", size); strlcpy(msg, "error reading file\n", size);
ret = false; ret = false;
break; break;
} }
numw = fwrite(buffer, sizeof(char), numr, dst); numw = filestream_write(dst, buffer, numr);
if (numw != numr) if (numw != numr)
{ {
strlcpy(msg, "error writing to file\n", size); strlcpy(msg, "error writing to file\n", size);
@ -1286,8 +1291,10 @@ static bool file_copy(char* src_path, char* dst_path, char* msg, size_t size)
break; break;
} }
} }
fclose(src);
fclose(dst); filestream_close(src);
filestream_close(dst);
return ret; return ret;
} }