mirror of https://github.com/mgba-emu/mgba.git
VFS: Add VDirEntry.type
This commit is contained in:
parent
a1eb021af5
commit
278b17e56f
|
@ -46,6 +46,7 @@ static struct VDirEntry* _vd3dListNext(struct VDir* vd);
|
|||
static struct VFile* _vd3dOpenFile(struct VDir* vd, const char* path, int mode);
|
||||
|
||||
static const char* _vd3deName(struct VDirEntry* vde);
|
||||
static enum VFSType _vd3deType(struct VDirEntry* vde);
|
||||
|
||||
struct VFile* VFileOpen3DS(FS_archive* archive, const char* path, int flags) {
|
||||
struct VFile3DS* vf3d = malloc(sizeof(struct VFile3DS));
|
||||
|
@ -186,6 +187,7 @@ struct VDir* VDirOpen(const char* path) {
|
|||
vd3d->d.openFile = _vd3dOpenFile;
|
||||
|
||||
vd3d->vde.d.name = _vd3deName;
|
||||
vd3d->vde.d.type = _vd3deType;
|
||||
vd3d->vde.utf8Name = 0;
|
||||
|
||||
return &vd3d->d;
|
||||
|
@ -245,4 +247,12 @@ static const char* _vd3deName(struct VDirEntry* vde) {
|
|||
}
|
||||
return vd3de->utf8Name;
|
||||
}
|
||||
|
||||
static enum VFSType _vd3deType(struct VDirEntry* vde) {
|
||||
struct VDirEntry3DS* vd3de = (struct VDirEntry3DS*) vde;
|
||||
if (vd3de->ent.isDirectory) {
|
||||
return VFS_DIRECTORY;
|
||||
}
|
||||
return VFS_FILE;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -44,6 +44,7 @@ static struct VDirEntry* _vdsceListNext(struct VDir* vd);
|
|||
static struct VFile* _vdsceOpenFile(struct VDir* vd, const char* path, int mode);
|
||||
|
||||
static const char* _vdesceName(struct VDirEntry* vde);
|
||||
static enum VFSType _vdesceType(struct VDirEntry* vde);
|
||||
|
||||
struct VFile* VFileOpenSce(const char* path, int flags, SceMode mode) {
|
||||
struct VFileSce* vfsce = malloc(sizeof(struct VFileSce));
|
||||
|
@ -147,6 +148,7 @@ struct VDir* VDirOpen(const char* path) {
|
|||
vd->path = strdup(path);
|
||||
|
||||
vd->de.d.name = _vdesceName;
|
||||
vd->de.d.type = _vdesceType;
|
||||
|
||||
return &vd->d;
|
||||
}
|
||||
|
@ -193,3 +195,11 @@ static const char* _vdesceName(struct VDirEntry* vde) {
|
|||
struct VDirEntrySce* vdesce = (struct VDirEntrySce*) vde;
|
||||
return vdesce->ent.d_name;
|
||||
}
|
||||
|
||||
static enum VFSType _vdesceType(struct VDirEntry* vde) {
|
||||
struct VDirEntrySce* vdesce = (struct VDirEntrySce*) vde;
|
||||
if (PSP2_S_ISDIR(vdesce->ent.d_stat.st_mode)) {
|
||||
return VFS_DIRECTORY;
|
||||
}
|
||||
return VFS_FILE;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,12 @@ enum {
|
|||
MAP_WRITE = 2
|
||||
};
|
||||
|
||||
enum VFSType {
|
||||
VFS_UNKNOWN = 0,
|
||||
VFS_FILE,
|
||||
VFS_DIRECTORY
|
||||
};
|
||||
|
||||
struct VFile {
|
||||
bool (*close)(struct VFile* vf);
|
||||
off_t (*seek)(struct VFile* vf, off_t offset, int whence);
|
||||
|
@ -44,6 +50,7 @@ struct VFile {
|
|||
|
||||
struct VDirEntry {
|
||||
const char* (*name)(struct VDirEntry* vde);
|
||||
enum VFSType (*type)(struct VDirEntry* vde);
|
||||
};
|
||||
|
||||
struct VDir {
|
||||
|
|
|
@ -15,6 +15,7 @@ static struct VDirEntry* _vdListNext(struct VDir* vd);
|
|||
static struct VFile* _vdOpenFile(struct VDir* vd, const char* path, int mode);
|
||||
|
||||
static const char* _vdeName(struct VDirEntry* vde);
|
||||
static enum VFSType _vdeType(struct VDirEntry* vde);
|
||||
|
||||
struct VDirEntryDE {
|
||||
struct VDirEntry d;
|
||||
|
@ -48,6 +49,7 @@ struct VDir* VDirOpen(const char* path) {
|
|||
vd->de = de;
|
||||
|
||||
vd->vde.d.name = _vdeName;
|
||||
vd->vde.d.type = _vdeType;
|
||||
|
||||
return &vd->d;
|
||||
}
|
||||
|
@ -190,3 +192,25 @@ const char* _vdeName(struct VDirEntry* vde) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum VFSType _vdeType(struct VDirEntry* vde) {
|
||||
struct VDirEntryDE* vdede = (struct VDirEntryDE*) vde;
|
||||
#ifndef WIN32
|
||||
if (vdede->ent->d_type == DT_DIR) {
|
||||
return VFS_DIRECTORY;
|
||||
}
|
||||
return VFS_FILE;
|
||||
#else
|
||||
const char* dir = vdde->path;
|
||||
char* combined = malloc(sizeof(char) * (strlen(vdede->ent->d_name) + strlen(dir) + 2));
|
||||
sprintf(combined, "%s%s%s", dir, PATH_SEP, vdede->ent->d_name);
|
||||
struct stat sb;
|
||||
stat(combined, &sb);
|
||||
free(combined);
|
||||
|
||||
if (S_ISDIR(sb.st_mode)) {
|
||||
return VFS_DIRECTORY;
|
||||
}
|
||||
return VFS_FILE;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ static struct VDirEntry* _vd7zListNext(struct VDir* vd);
|
|||
static struct VFile* _vd7zOpenFile(struct VDir* vd, const char* path, int mode);
|
||||
|
||||
static const char* _vde7zName(struct VDirEntry* vde);
|
||||
static enum VFSType _vde7zType(struct VDirEntry* vde);
|
||||
|
||||
struct VDir* VDirOpen7z(const char* path, int flags) {
|
||||
if (flags & O_WRONLY || flags & O_CREAT) {
|
||||
|
@ -104,6 +105,7 @@ struct VDir* VDirOpen7z(const char* path, int flags) {
|
|||
vd->dirent.utf8 = 0;
|
||||
vd->dirent.vd = vd;
|
||||
vd->dirent.d.name = _vde7zName;
|
||||
vd->dirent.d.type = _vde7zType;
|
||||
|
||||
vd->d.close = _vd7zClose;
|
||||
vd->d.rewind = _vd7zRewind;
|
||||
|
@ -299,6 +301,13 @@ struct VFile* _vd7zOpenFile(struct VDir* vd, const char* path, int mode) {
|
|||
return &vf->d;
|
||||
}
|
||||
|
||||
bool _vf7zSync(struct VFile* vf, const void* memory, size_t size) {
|
||||
UNUSED(vf);
|
||||
UNUSED(memory);
|
||||
UNUSED(size);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* _vde7zName(struct VDirEntry* vde) {
|
||||
struct VDirEntry7z* vde7z = (struct VDirEntry7z*) vde;
|
||||
if (!vde7z->utf8) {
|
||||
|
@ -312,11 +321,12 @@ const char* _vde7zName(struct VDirEntry* vde) {
|
|||
return vde7z->utf8;
|
||||
}
|
||||
|
||||
bool _vf7zSync(struct VFile* vf, const void* memory, size_t size) {
|
||||
UNUSED(vf);
|
||||
UNUSED(memory);
|
||||
UNUSED(size);
|
||||
return false;
|
||||
static enum VFSType _vde7zType(struct VDirEntry* vde) {
|
||||
struct VDirEntry7z* vde7z = (struct VDirEntry7z*) vde;
|
||||
if (SzArEx_IsDir(&vde7z->vd->db, vde7z->index)) {
|
||||
return VFS_DIRECTORY;
|
||||
}
|
||||
return VFS_FILE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,6 +51,7 @@ static struct VDirEntry* _vdzListNext(struct VDir* vd);
|
|||
static struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode);
|
||||
|
||||
static const char* _vdezName(struct VDirEntry* vde);
|
||||
static enum VFSType _vdezType(struct VDirEntry* vde);
|
||||
|
||||
struct VDir* VDirOpenZip(const char* path, int flags) {
|
||||
int zflags = 0;
|
||||
|
@ -74,6 +75,7 @@ struct VDir* VDirOpenZip(const char* path, int flags) {
|
|||
vd->z = z;
|
||||
|
||||
vd->dirent.d.name = _vdezName;
|
||||
vd->dirent.d.type = _vdezType;
|
||||
vd->dirent.index = -1;
|
||||
vd->dirent.z = z;
|
||||
|
||||
|
@ -295,6 +297,13 @@ struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode) {
|
|||
return &vfz->d;
|
||||
}
|
||||
|
||||
bool _vfzSync(struct VFile* vf, const void* memory, size_t size) {
|
||||
UNUSED(vf);
|
||||
UNUSED(memory);
|
||||
UNUSED(size);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* _vdezName(struct VDirEntry* vde) {
|
||||
struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde;
|
||||
struct zip_stat s;
|
||||
|
@ -304,11 +313,9 @@ const char* _vdezName(struct VDirEntry* vde) {
|
|||
return s.name;
|
||||
}
|
||||
|
||||
bool _vfzSync(struct VFile* vf, const void* memory, size_t size) {
|
||||
UNUSED(vf);
|
||||
UNUSED(memory);
|
||||
UNUSED(size);
|
||||
return false;
|
||||
static enum VFSType _vdezType(struct VDirEntry* vde) {
|
||||
struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde;
|
||||
return VFS_UNKNOWN;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue