Update vfat.cpp so that it works again with new libretro-common code

This commit is contained in:
twinaphex 2016-08-16 08:20:39 +02:00 committed by zeromus
parent 3b0fc202b2
commit 2d0852aaf9
1 changed files with 66 additions and 48 deletions

View File

@ -27,14 +27,16 @@
#include "../types.h"
#include "../debug.h"
#include "../emufile.h"
#include "retro_dirent.h"
#include "retro_stat.h"
#include "file/file_path.h"
#include "emufat.h"
#include "vfat.h"
#include "libfat/libfat_public_api.h"
#include <retro_dirent.h>
#include <retro_stat.h>
#include <file/file_path.h>
static char retro_dir[PATH_MAX_LENGTH];
enum EListCallbackArg {
EListCallbackArg_Item, EListCallbackArg_Pop
@ -50,22 +52,22 @@ static void list_files(const char *filepath, ListCallback list_callback)
u32 dwError;
RDIR *rdir = retro_opendir(filepath);
if(!rdir) return;
if(retro_dirent_error(rdir))
{
retro_closedir(rdir);
if (!rdir)
return;
}
strcpy(retro_dir, filepath);
if (retro_dirent_error(rdir))
goto end;
for (;;)
{
const char *name = NULL;
if (!retro_readdir(rdir))
break;
const char *fname = retro_dirent_get_name(rdir);
list_callback(rdir,EListCallbackArg_Item);
if(retro_dirent_is_dir(rdir) && (strcmp(fname, ".")) && (strcmp(fname, "..")))
if (retro_dirent_is_dir(rdir, filepath) && (strcmp(fname, ".")) && strcmp(fname, ".."))
{
std::string subdir = (std::string)filepath + path_default_slash() + fname;
list_files(subdir.c_str(), list_callback);
@ -73,23 +75,24 @@ static void list_files(const char *filepath, ListCallback list_callback)
}
}
end:
retro_closedir(rdir);
}
static u64 dataSectors = 0;
static unsigned long dataSectors = 0;
void count_ListCallback(RDIR *rdir, EListCallbackArg arg)
{
if(arg == EListCallbackArg_Pop) return;
if(arg == EListCallbackArg_Pop)
return;
u32 sectors = 1;
if(retro_dirent_is_dir(rdir))
if (!retro_dirent_is_dir(rdir, retro_dir))
{
}
else
{
//allocate sectors for file
int32_t fileSize = path_get_size(retro_dirent_get_name(rdir));
const char *path = retro_dirent_get_name(rdir);
/* allocate sectors for file */
int32_t fileSize = path_get_size(path);
sectors += (fileSize+511)/512 + 1;
}
dataSectors += sectors;
}
@ -110,7 +113,7 @@ void build_ListCallback(RDIR* rdir, EListCallbackArg arg)
return;
}
if(retro_dirent_is_dir(rdir))
if (retro_dirent_is_dir(rdir, retro_dir))
{
if(!strcmp(fname,".")) return;
if(!strcmp(fname,"..")) return;
@ -134,11 +137,21 @@ void build_ListCallback(RDIR* rdir, EListCallbackArg arg)
FILE* inf = fopen(path.c_str(),"rb");
if(inf)
{
u8 * buf;
size_t elements_read;
long len;
fseek(inf, 0, SEEK_END);
long len = ftell(inf);
len = ftell(inf);
fseek(inf, 0, SEEK_SET);
u8 *buf = new u8[len];
fread(buf,1,len,inf);
buf = new u8[len];
elements_read = fread(buf, 1, len, inf);
if (elements_read != len)
printf(
"libfat: %lu bytes read instead of %l.\n",
elements_read,
len
);
fclose(inf);
std::string path = currVirtPath + "/" + fname;
@ -149,7 +162,6 @@ void build_ListCallback(RDIR* rdir, EListCallbackArg arg)
delete[] buf;
} else printf("ERROR opening file for fat\n");
}
}
@ -173,7 +185,10 @@ bool VFAT::build(const char* path, int extra_MB)
if(dataSectors>=(0x80000000>>9))
{
printf("error allocating memory for fat (%d KBytes)\n",(dataSectors*512)/1024);
printf(
"error allocating memory for fat (%lu KBytes)\n",
(dataSectors*512) / 1024
);
printf("total fat sizes > 2GB are never going to work\n");
}
@ -184,7 +199,10 @@ bool VFAT::build(const char* path, int extra_MB)
}
catch(std::bad_alloc)
{
printf("error allocating memory for fat (%d KBytes)\n",(dataSectors*512)/1024);
printf(
"error allocating memory for fat (%lu KBytes)\n",
(dataSectors*512) / 1024
);
printf("(out of memory)\n");
return false;
}