VFS: Add VDir.openDir

This commit is contained in:
Jeffrey Pfau 2015-09-22 21:19:55 -07:00
parent 5b22a628fa
commit 6cf4179a97
6 changed files with 75 additions and 2 deletions

View File

@ -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 @@ struct VDir* VDirOpen(const char* 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;
@ -235,6 +237,23 @@ static struct VFile* _vd3dOpenFile(struct VDir* vd, const char* path, int mode)
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) {
struct VDirEntry3DS* vd3de = (struct VDirEntry3DS*) vde;
if (!vd3de->utf8Name[0]) {

View File

@ -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 @@ struct VDir* VDirOpen(const char* path) {
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,13 +192,29 @@ struct VFile* _vdsceOpenFile(struct VDir* vd, const char* path, int mode) {
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) {
struct VDirEntrySce* vdesce = (struct VDirEntrySce*) vde;
return vdesce->ent.d_name;

View File

@ -58,6 +58,7 @@ struct VDir {
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);

View File

@ -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 @@ struct VDir* VDirOpen(const char* path) {
vd->d.rewind = _vdRewind;
vd->d.listNext = _vdListNext;
vd->d.openFile = _vdOpenFile;
vd->d.openDir = _vdOpenDir;
vd->path = strdup(path);
vd->de = de;
@ -97,6 +99,23 @@ struct VFile* _vdOpenFile(struct VDir* vd, const char* path, int mode) {
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) {
struct VDirEntryDE* vdede = (struct VDirEntryDE*) vde;
if (vdede->ent) {

View File

@ -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 @@ struct VDir* VDirOpen7z(const char* path, int flags) {
vd->d.rewind = _vd7zRewind;
vd->d.listNext = _vd7zListNext;
vd->d.openFile = _vd7zOpenFile;
vd->d.openDir = _vd7zOpenDir;
return &vd->d;
}
@ -301,6 +303,12 @@ struct VFile* _vd7zOpenFile(struct VDir* vd, const char* path, int mode) {
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) {
UNUSED(vf);
UNUSED(memory);

View File

@ -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 @@ struct VDir* VDirOpenZip(const char* path, int flags) {
vd->d.rewind = _vdzRewind;
vd->d.listNext = _vdzListNext;
vd->d.openFile = _vdzOpenFile;
vd->d.openDir = _vdzOpenDir;
vd->z = z;
vd->dirent.d.name = _vdezName;
@ -297,6 +299,12 @@ struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode) {
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) {
UNUSED(vf);
UNUSED(memory);