VFS: Add VDir.openDir
Jeffrey Pfau jeffrey@endrift.com
Tue, 22 Sep 2015 21:19:55 -0700
6 files changed,
75 insertions(+),
2 deletions(-)
M
src/platform/3ds/3ds-vfs.c
→
src/platform/3ds/3ds-vfs.c
@@ -44,6 +44,7 @@ static bool _vd3dClose(struct VDir* vd);
static void _vd3dRewind(struct VDir* vd); static struct VDirEntry* _vd3dListNext(struct VDir* vd); static struct VFile* _vd3dOpenFile(struct VDir* vd, const char* path, int mode); +static struct VDir* _vd3dOpenDir(struct VDir* vd, const char* path); static const char* _vd3deName(struct VDirEntry* vde); static enum VFSType _vd3deType(struct VDirEntry* vde);@@ -185,8 +186,9 @@ vd3d->path = strdup(path);
vd3d->d.close = _vd3dClose; vd3d->d.rewind = _vd3dRewind; - vd3d->d.listNext = _vd3dListNext; //// Crashes here for no good reason + vd3d->d.listNext = _vd3dListNext; vd3d->d.openFile = _vd3dOpenFile; + vd3d->d.openDir = _vd3dOpenDir; vd3d->vde.d.name = _vd3deName; vd3d->vde.d.type = _vd3deType;@@ -233,6 +235,23 @@
struct VFile* file = VFileOpen(combined, mode); free(combined); return file; +} + +static struct VDir* _vd3dOpenDir(struct VDir* vd, const char* path) { + struct VDir3DS* vd3d = (struct VDir3DS*) vd; + if (!path) { + return 0; + } + const char* dir = vd3d->path; + char* combined = malloc(sizeof(char) * (strlen(path) + strlen(dir) + 2)); + sprintf(combined, "%s/%s", dir, path); + + struct VDir* vd2 = VDirOpen(combined); + if (!vd2) { + vd2 = VDirOpenArchive(combined); + } + free(combined); + return vd2; } static const char* _vd3deName(struct VDirEntry* vde) {
M
src/platform/psp2/sce-vfs.c
→
src/platform/psp2/sce-vfs.c
@@ -42,6 +42,7 @@ static bool _vdsceClose(struct VDir* vd);
static void _vdsceRewind(struct VDir* vd); static struct VDirEntry* _vdsceListNext(struct VDir* vd); static struct VFile* _vdsceOpenFile(struct VDir* vd, const char* path, int mode); +static struct VDir* _vdsceOpenDir(struct VDir* vd, const char* path); static const char* _vdesceName(struct VDirEntry* vde); static enum VFSType _vdesceType(struct VDirEntry* vde);@@ -150,6 +151,7 @@ vd->d.close = _vdsceClose;
vd->d.rewind = _vdsceRewind; vd->d.listNext = _vdsceListNext; vd->d.openFile = _vdsceOpenFile; + vd->d.openDir = _vdsceOpenDir; vd->path = strdup(path); vd->de.d.name = _vdesceName;@@ -190,11 +192,27 @@ }
const char* dir = vdsce->path; char* combined = malloc(sizeof(char) * (strlen(path) + strlen(dir) + strlen(PATH_SEP) + 1)); sprintf(combined, "%s%s%s", dir, PATH_SEP, path); - printf("Opening %s\n", combined); struct VFile* file = VFileOpen(combined, mode); free(combined); return file; +} + +struct VDir* _vdsceOpenDir(struct VDir* vd, const char* path) { + struct VDirSce* vdsce = (struct VDirSce*) vd; + if (!path) { + return 0; + } + const char* dir = vdsce->path; + char* combined = malloc(sizeof(char) * (strlen(path) + strlen(dir) + strlen(PATH_SEP) + 1)); + sprintf(combined, "%s%s%s", dir, PATH_SEP, path); + + struct VDir* vd2 = VDirOpen(combined); + if (!vd2) { + vd2 = VDirOpenArchive(combined); + } + free(combined); + return vd2; } static const char* _vdesceName(struct VDirEntry* vde) {
M
src/util/vfs.h
→
src/util/vfs.h
@@ -58,6 +58,7 @@ bool (*close)(struct VDir* vd);
void (*rewind)(struct VDir* vd); struct VDirEntry* (*listNext)(struct VDir* vd); struct VFile* (*openFile)(struct VDir* vd, const char* name, int mode); + struct VDir* (*openDir)(struct VDir* vd, const char* name); }; struct VFile* VFileOpen(const char* path, int flags);
M
src/util/vfs/vfs-dirent.c
→
src/util/vfs/vfs-dirent.c
@@ -14,6 +14,7 @@ static bool _vdClose(struct VDir* vd);
static void _vdRewind(struct VDir* vd); static struct VDirEntry* _vdListNext(struct VDir* vd); static struct VFile* _vdOpenFile(struct VDir* vd, const char* path, int mode); +static struct VDir* _vdOpenDir(struct VDir* vd, const char* path); static const char* _vdeName(struct VDirEntry* vde); static enum VFSType _vdeType(struct VDirEntry* vde);@@ -48,6 +49,7 @@ vd->d.close = _vdClose;
vd->d.rewind = _vdRewind; vd->d.listNext = _vdListNext; vd->d.openFile = _vdOpenFile; + vd->d.openDir = _vdOpenDir; vd->path = strdup(path); vd->de = de;@@ -95,6 +97,23 @@
struct VFile* file = VFileOpen(combined, mode); free(combined); return file; +} + +struct VDir* _vdOpenDir(struct VDir* vd, const char* path) { + struct VDirDE* vdde = (struct VDirDE*) vd; + if (!path) { + return 0; + } + const char* dir = vdde->path; + char* combined = malloc(sizeof(char) * (strlen(path) + strlen(dir) + 2)); + sprintf(combined, "%s%s%s", dir, PATH_SEP, path); + + struct VDir* vd2 = VDirOpen(combined); + if (!vd2) { + vd2 = VDirOpenArchive(combined); + } + free(combined); + return vd2; } const char* _vdeName(struct VDirEntry* vde) {
M
src/util/vfs/vfs-lzma.c
→
src/util/vfs/vfs-lzma.c
@@ -62,6 +62,7 @@ static bool _vd7zClose(struct VDir* vd);
static void _vd7zRewind(struct VDir* vd); static struct VDirEntry* _vd7zListNext(struct VDir* vd); static struct VFile* _vd7zOpenFile(struct VDir* vd, const char* path, int mode); +static struct VDir* _vd7zOpenDir(struct VDir* vd, const char* path); static const char* _vde7zName(struct VDirEntry* vde); static enum VFSType _vde7zType(struct VDirEntry* vde);@@ -111,6 +112,7 @@ vd->d.close = _vd7zClose;
vd->d.rewind = _vd7zRewind; vd->d.listNext = _vd7zListNext; vd->d.openFile = _vd7zOpenFile; + vd->d.openDir = _vd7zOpenDir; return &vd->d; }@@ -299,6 +301,12 @@ vf->d.size = _vf7zSize;
vf->d.sync = _vf7zSync; return &vf->d; +} + +struct VDir* _vd7zOpenDir(struct VDir* vd, const char* path) { + UNUSED(vd); + UNUSED(path); + return 0; } bool _vf7zSync(struct VFile* vf, const void* memory, size_t size) {
M
src/util/vfs/vfs-zip.c
→
src/util/vfs/vfs-zip.c
@@ -49,6 +49,7 @@ static bool _vdzClose(struct VDir* vd);
static void _vdzRewind(struct VDir* vd); static struct VDirEntry* _vdzListNext(struct VDir* vd); static struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode); +static struct VDir* _vdzOpenDir(struct VDir* vd, const char* path); static const char* _vdezName(struct VDirEntry* vde); static enum VFSType _vdezType(struct VDirEntry* vde);@@ -72,6 +73,7 @@ vd->d.close = _vdzClose;
vd->d.rewind = _vdzRewind; vd->d.listNext = _vdzListNext; vd->d.openFile = _vdzOpenFile; + vd->d.openDir = _vdzOpenDir; vd->z = z; vd->dirent.d.name = _vdezName;@@ -295,6 +297,12 @@ vfz->d.size = _vfzSize;
vfz->d.sync = _vfzSync; return &vfz->d; +} + +struct VDir* _vdzOpenDir(struct VDir* vd, const char* path) { + UNUSED(vd); + UNUSED(path); + return 0; } bool _vfzSync(struct VFile* vf, const void* memory, size_t size) {