VFS: Add VDir.deleteFile

This commit is contained in:
Jeffrey Pfau 2016-01-31 21:59:16 -08:00
parent 8e99508717
commit 6af9a742bd
7 changed files with 84 additions and 0 deletions

View File

@ -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 @@ struct VDir* VDirOpen(const char* path) {
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;
@ -257,6 +259,22 @@ static struct VDir* _vd3dOpenDir(struct VDir* vd, const char* path) {
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) {
struct VDirEntry3DS* vd3de = (struct VDirEntry3DS*) vde;
if (!vd3de->utf8Name[0]) {

View File

@ -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 @@ struct VDir* VDirOpen(const char* path) {
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;
@ -215,6 +217,20 @@ struct VDir* _vdsceOpenDir(struct VDir* vd, const char* path) {
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) {
struct VDirEntrySce* vdesce = (struct VDirEntrySce*) vde;
return vdesce->ent.d_name;

View File

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

View File

@ -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 @@ struct VDir* VDeviceList() {
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;
@ -93,6 +95,12 @@ static struct VDir* _vdlOpenDir(struct VDir* vd, const char* path) {
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) {
struct VDirEntryDevList* vdle = (struct VDirEntryDevList*) vde;
return vdle->name;

View File

@ -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 @@ struct VDir* VDirOpen(const char* path) {
vd->d.listNext = _vdListNext;
vd->d.openFile = _vdOpenFile;
vd->d.openDir = _vdOpenDir;
vd->d.deleteFile = _vdDeleteFile;
vd->path = strdup(path);
vd->de = de;
@ -121,6 +123,20 @@ struct VDir* _vdOpenDir(struct VDir* vd, const char* path) {
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) {
struct VDirEntryDE* vdede = (struct VDirEntryDE*) vde;
if (vdede->ent) {

View File

@ -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 @@ struct VDir* VDirOpen7z(const char* path, int flags) {
vd->d.listNext = _vd7zListNext;
vd->d.openFile = _vd7zOpenFile;
vd->d.openDir = _vd7zOpenDir;
vd->d.deleteFile = _vd7zDeleteFile;
return &vd->d;
}
@ -309,6 +311,13 @@ struct VDir* _vd7zOpenDir(struct VDir* vd, const char* 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) {
UNUSED(vf);
UNUSED(memory);

View File

@ -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 @@ struct VDir* VDirOpenZip(const char* path, int flags) {
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 @@ struct VDir* _vdzOpenDir(struct VDir* vd, const char* 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);
@ -624,6 +633,13 @@ struct VDir* _vdzOpenDir(struct VDir* vd, const char* 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);