all repos — mgba @ 5b22a628fa50820e8c20732210614adb0143edc3

mGBA Game Boy Advance Emulator

VFS: Add VDirOpenArchive
Jeffrey Pfau jeffrey@endrift.com
Tue, 22 Sep 2015 21:18:46 -0700
commit

5b22a628fa50820e8c20732210614adb0143edc3

parent

b4c86ea161856a61117e3712d00307f6b5cd15e5

4 files changed, 36 insertions(+), 9 deletions(-)

jump to
M src/gba/context/context.csrc/gba/context/context.c

@@ -73,7 +73,25 @@ GBAConfigDeinit(&context->config);

} 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; }
M src/gba/supervisor/thread.csrc/gba/supervisor/thread.c

@@ -683,16 +683,9 @@

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) {
M src/util/vfs.csrc/util/vfs.c

@@ -96,6 +96,21 @@ return VFileOpenFD(path, 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) {
M src/util/vfs.hsrc/util/vfs.h

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