mirror of https://github.com/mgba-emu/mgba.git
VFS: Add VDirOpenArchive
This commit is contained in:
parent
b4c86ea161
commit
5b22a628fa
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue