all repos — mgba @ 6af9a742bda66c3785cd13f76895558eeac77725

mGBA Game Boy Advance Emulator

VFS: Add VDir.deleteFile
Jeffrey Pfau jeffrey@endrift.com
Sun, 31 Jan 2016 21:59:16 -0800
commit

6af9a742bda66c3785cd13f76895558eeac77725

parent

8e99508717c7c5e2316c50a03dd156d4d86bceeb

M src/platform/3ds/3ds-vfs.csrc/platform/3ds/3ds-vfs.c

@@ -45,6 +45,7 @@ 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 bool _vd3dDeleteFile(struct VDir* vd, const char* path); static const char* _vd3deName(struct VDirEntry* vde); static enum VFSType _vd3deType(struct VDirEntry* vde);

@@ -191,6 +192,7 @@ vd3d->d.rewind = _vd3dRewind;

vd3d->d.listNext = _vd3dListNext; vd3d->d.openFile = _vd3dOpenFile; vd3d->d.openDir = _vd3dOpenDir; + vd3d->d.deleteFile = _vd3dDeleteFile; vd3d->vde.d.name = _vd3deName; vd3d->vde.d.type = _vd3deType;

@@ -255,6 +257,22 @@ vd2 = VDirOpenArchive(combined);

} free(combined); return vd2; +} + +static bool _vd3dDeleteFile(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); + + // TODO: Use UTF-16 + FS_Path newPath = fsMakePath(PATH_ASCII, combined); + bool ret = !FSUSER_DeleteFile(sdmcArchive, newPath); + free(combined); + return ret; } static const char* _vd3deName(struct VDirEntry* vde) {
M src/platform/psp2/sce-vfs.csrc/platform/psp2/sce-vfs.c

@@ -43,6 +43,7 @@ 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 bool _vdsceDeleteFile(struct VDir* vd, const char* path); static const char* _vdesceName(struct VDirEntry* vde); static enum VFSType _vdesceType(struct VDirEntry* vde);

@@ -152,6 +153,7 @@ vd->d.rewind = _vdsceRewind;

vd->d.listNext = _vdsceListNext; vd->d.openFile = _vdsceOpenFile; vd->d.openDir = _vdsceOpenDir; + vd->d.deleteFile = _vdsceDeleteFile; vd->path = strdup(path); vd->de.d.name = _vdesceName;

@@ -213,6 +215,20 @@ vd2 = VDirOpenArchive(combined);

} free(combined); return vd2; +} + +bool _vdsceDeleteFile(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); + + bool ret = sceIoRemove(combined) >= 0; + free(combined); + return ret; } static const char* _vdesceName(struct VDirEntry* vde) {
M src/util/vfs.hsrc/util/vfs.h

@@ -59,6 +59,7 @@ 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); + bool (*deleteFile)(struct VDir* vd, const char* name); }; struct VFile* VFileOpen(const char* path, int flags);
M src/util/vfs/vfs-devlist.csrc/util/vfs/vfs-devlist.c

@@ -12,6 +12,7 @@ static void _vdlRewind(struct VDir* vd);

static struct VDirEntry* _vdlListNext(struct VDir* vd); static struct VFile* _vdlOpenFile(struct VDir* vd, const char* path, int mode); static struct VDir* _vdlOpenDir(struct VDir* vd, const char* path); +static bool _vdlDeleteFile(struct VDir* vd, const char* path); static const char* _vdleName(struct VDirEntry* vde); static enum VFSType _vdleType(struct VDirEntry* vde);

@@ -38,6 +39,7 @@ vd->d.rewind = _vdlRewind;

vd->d.listNext = _vdlListNext; vd->d.openFile = _vdlOpenFile; vd->d.openDir = _vdlOpenDir; + vd->d.deleteFile = _vdlDeleteFile; vd->vde.d.name = _vdleName; vd->vde.d.type = _vdleType;

@@ -91,6 +93,12 @@

static struct VDir* _vdlOpenDir(struct VDir* vd, const char* path) { UNUSED(vd); return VDirOpen(path); +} + +static bool _vdlDeleteFile(struct VDir* vd, const char* path) { + UNUSED(vd); + UNUSED(path); + return false; } static const char* _vdleName(struct VDirEntry* vde) {
M src/util/vfs/vfs-dirent.csrc/util/vfs/vfs-dirent.c

@@ -15,6 +15,7 @@ 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 bool _vdDeleteFile(struct VDir* vd, const char* path); static const char* _vdeName(struct VDirEntry* vde); static enum VFSType _vdeType(struct VDirEntry* vde);

@@ -55,6 +56,7 @@ vd->d.rewind = _vdRewind;

vd->d.listNext = _vdListNext; vd->d.openFile = _vdOpenFile; vd->d.openDir = _vdOpenDir; + vd->d.deleteFile = _vdDeleteFile; vd->path = strdup(path); vd->de = de;

@@ -119,6 +121,20 @@ vd2 = VDirOpenArchive(combined);

} free(combined); return vd2; +} + +bool _vdDeleteFile(struct VDir* vd, const char* path) { + struct VDirDE* vdde = (struct VDirDE*) vd; + if (!path) { + return false; + } + const char* dir = vdde->path; + char* combined = malloc(sizeof(char) * (strlen(path) + strlen(dir) + 2)); + sprintf(combined, "%s%s%s", dir, PATH_SEP, path); + + bool ret = !unlink(combined); + free(combined); + return ret; } const char* _vdeName(struct VDirEntry* vde) {
M src/util/vfs/vfs-lzma.csrc/util/vfs/vfs-lzma.c

@@ -63,6 +63,7 @@ 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 bool _vd7zDeleteFile(struct VDir* vd, const char* path); static const char* _vde7zName(struct VDirEntry* vde); static enum VFSType _vde7zType(struct VDirEntry* vde);

@@ -113,6 +114,7 @@ vd->d.rewind = _vd7zRewind;

vd->d.listNext = _vd7zListNext; vd->d.openFile = _vd7zOpenFile; vd->d.openDir = _vd7zOpenDir; + vd->d.deleteFile = _vd7zDeleteFile; return &vd->d; }

@@ -307,6 +309,13 @@ struct VDir* _vd7zOpenDir(struct VDir* vd, const char* path) {

UNUSED(vd); UNUSED(path); return 0; +} + +bool _vd7zDeleteFile(struct VDir* vd, const char* path) { + UNUSED(vd); + UNUSED(path); + // TODO + return false; } bool _vf7zSync(struct VFile* vf, const void* memory, size_t size) {
M src/util/vfs/vfs-zip.csrc/util/vfs/vfs-zip.c

@@ -74,6 +74,7 @@ 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 bool _vdzDeleteFile(struct VDir* vd, const char* path); static const char* _vdezName(struct VDirEntry* vde); static enum VFSType _vdezType(struct VDirEntry* vde);

@@ -172,6 +173,7 @@ vd->d.rewind = _vdzRewind;

vd->d.listNext = _vdzListNext; vd->d.openFile = _vdzOpenFile; vd->d.openDir = _vdzOpenDir; + vd->d.deleteFile = _vdzDeleteFile; vd->z = z; #ifndef USE_LIBZIP

@@ -410,6 +412,13 @@ UNUSED(path);

return 0; } +bool _vdzDeleteFile(struct VDir* vd, const char* path) { + UNUSED(vd); + UNUSED(path); + // TODO + return false; +} + bool _vfzSync(struct VFile* vf, const void* memory, size_t size) { UNUSED(vf); UNUSED(memory);

@@ -622,6 +631,13 @@ struct VDir* _vdzOpenDir(struct VDir* vd, const char* path) {

UNUSED(vd); UNUSED(path); return 0; +} + +bool _vdzDeleteFile(struct VDir* vd, const char* path) { + UNUSED(vd); + UNUSED(path); + // TODO + return false; } bool _vfzSync(struct VFile* vf, const void* memory, size_t size) {