VFS: Add VDirOpenArchive

This commit is contained in:
Jeffrey Pfau 2015-09-22 21:18:46 -07:00
parent b4c86ea161
commit 5b22a628fa
4 changed files with 36 additions and 9 deletions

View File

@ -73,7 +73,25 @@ void GBAContextDeinit(struct GBAContext* context) {
}
bool GBAContextLoadROM(struct GBAContext* context, const char* path, bool autoloadSave) {
context->rom = VFileOpen(path, O_RDONLY);
struct VDir* dir = VDirOpenArchive(path);
if (dir) {
struct VDirEntry* de;
while ((de = dir->listNext(dir))) {
struct VFile* vf = dir->openFile(dir, de->name(de), O_RDONLY);
if (!vf) {
continue;
}
if (GBAIsROM(vf)) {
context->rom = vf;
break;
}
vf->close(vf);
}
dir->close(dir);
} else {
context->rom = VFileOpen(path, O_RDONLY);
}
if (!context->rom) {
return false;
}

View File

@ -683,16 +683,9 @@ void GBAThreadPauseFromThread(struct GBAThread* threadContext) {
void GBAThreadLoadROM(struct GBAThread* threadContext, const char* fname) {
threadContext->rom = VFileOpen(fname, O_RDONLY);
threadContext->gameDir = 0;
#if USE_LIBZIP
if (!threadContext->gameDir) {
threadContext->gameDir = VDirOpenZip(fname, 0);
threadContext->gameDir = VDirOpenArchive(fname);
}
#endif
#if USE_LZMA
if (!threadContext->gameDir) {
threadContext->gameDir = VDirOpen7z(fname, 0);
}
#endif
}
static void _loadGameDir(struct GBAThread* threadContext) {

View File

@ -96,6 +96,21 @@ struct VFile* VFileOpen(const char* path, int flags) {
#endif
}
struct VDir* VDirOpenArchive(const char* path) {
struct VDir* dir = 0;
#if USE_LIBZIP
if (!dir) {
dir = VDirOpenZip(path, 0);
}
#endif
#if USE_LZMA
if (!dir) {
dir = VDirOpen7z(path, 0);
}
#endif
return dir;
}
ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) {
size_t bytesRead = 0;
while (bytesRead < size - 1) {

View File

@ -69,6 +69,7 @@ struct VFile* VFileFromMemory(void* mem, size_t size);
struct VFile* VFileFromFILE(FILE* file);
struct VDir* VDirOpen(const char* path);
struct VDir* VDirOpenArchive(const char* path);
#ifdef USE_LIBZIP
struct VDir* VDirOpenZip(const char* path, int flags);