Wii: List devices at root

This commit is contained in:
Jeffrey Pfau 2015-12-18 22:18:52 -08:00
parent 7d9a897700
commit 2495b650a4
7 changed files with 124 additions and 5 deletions

View File

@ -209,7 +209,7 @@ void GBAConfigDirectory(char* out, size_t outLength) {
sceIoMkdir(out, 0777);
#elif defined(GEKKO)
UNUSED(portable);
snprintf(out, outLength, "/%s", projectName);
snprintf(out, outLength, "sd:/%s", projectName);
mkdir(out, 0777);
#elif defined(_3DS)
snprintf(out, outLength, "/%s", projectName);

View File

@ -4,7 +4,7 @@ find_program(RAW2C raw2c)
find_program(WIILOAD wiiload)
set(OS_DEFINES COLOR_16_BIT COLOR_5_6_5 USE_VFS_FILE)
list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-devlist.c)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

View File

@ -185,7 +185,7 @@ int main() {
font = GUIFontCreate();
fatInitDefault();
fatInit(4, false);
rumble.setRumble = _setRumble;
@ -197,7 +197,7 @@ int main() {
struct GBAGUIRunner runner = {
.params = {
vmode->fbWidth * 0.9, vmode->efbHeight * 0.9,
font, "/",
font, "",
_drawStart, _drawEnd,
_pollInput, _pollCursor,
0,

View File

@ -32,6 +32,7 @@ static void _cleanFiles(struct GUIMenuItemList* currentFiles) {
static void _upDirectory(char* currentPath) {
char* end = strrchr(currentPath, '/');
if (!end) {
currentPath[0] = '\0';
return;
}
if (end == currentPath) {
@ -163,7 +164,7 @@ bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool
} else {
size_t len = strlen(params->currentPath);
const char* sep = PATH_SEP;
if (params->currentPath[len - 1] == *sep) {
if (!len || params->currentPath[len - 1] == *sep) {
sep = "";
}
snprintf(outPath, outLen, "%s%s%s", params->currentPath, sep, item->title);

View File

@ -80,6 +80,8 @@ struct VDir* VDirOpenZip(const char* path, int flags);
struct VDir* VDirOpen7z(const char* path, int flags);
#endif
struct VDir* VDeviceList(void);
struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix,
int mode);
struct VFile* VDirOptionalOpenIncrementFile(struct VDir* dir, const char* realPath, const char* prefix,

111
src/util/vfs/vfs-devlist.c Normal file
View File

@ -0,0 +1,111 @@
/* Copyright (c) 2013-2015 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "util/vfs.h"
#include <fat.h>
static bool _vdlClose(struct VDir* vd);
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 const char* _vdleName(struct VDirEntry* vde);
static enum VFSType _vdleType(struct VDirEntry* vde);
extern const struct {
const char* name;
const DISC_INTERFACE* (*getInterface)(void);
} _FAT_disc_interfaces[];
struct VDirEntryDevList {
struct VDirEntry d;
size_t index;
char* name;
};
struct VDirDevList {
struct VDir d;
struct VDirEntryDevList vde;
};
struct VDir* VDeviceList() {
struct VDirDevList* vd = malloc(sizeof(struct VDirDevList));
if (!vd) {
return 0;
}
vd->d.close = _vdlClose;
vd->d.rewind = _vdlRewind;
vd->d.listNext = _vdlListNext;
vd->d.openFile = _vdlOpenFile;
vd->d.openDir = _vdlOpenDir;
vd->vde.d.name = _vdleName;
vd->vde.d.type = _vdleType;
vd->vde.index = 0;
vd->vde.name = 0;
return &vd->d;
}
static bool _vdlClose(struct VDir* vd) {
struct VDirDevList* vdl = (struct VDirDevList*) vd;
free(vdl->vde.name);
free(vdl);
return true;
}
static void _vdlRewind(struct VDir* vd) {
struct VDirDevList* vdl = (struct VDirDevList*) vd;
free(vdl->vde.name);
vdl->vde.name = 0;
vdl->vde.index = 0;
}
static struct VDirEntry* _vdlListNext(struct VDir* vd) {
struct VDirDevList* vdl = (struct VDirDevList*) vd;
if (vdl->vde.name) {
++vdl->vde.index;
free(vdl->vde.name);
vdl->vde.name = 0;
}
while (true) {
if (!_FAT_disc_interfaces[vdl->vde.index].name || !_FAT_disc_interfaces[vdl->vde.index].getInterface) {
return 0;
}
const DISC_INTERFACE* iface = _FAT_disc_interfaces[vdl->vde.index].getInterface();
if (iface && iface->isInserted()) {
vdl->vde.name = malloc(strlen(_FAT_disc_interfaces[vdl->vde.index].name) + 3);
sprintf(vdl->vde.name, "%s:", _FAT_disc_interfaces[vdl->vde.index].name);
return &vdl->vde.d;
}
++vdl->vde.index;
}
}
static struct VFile* _vdlOpenFile(struct VDir* vd, const char* path, int mode) {
UNUSED(vd);
UNUSED(path);
UNUSED(mode);
return 0;
}
static struct VDir* _vdlOpenDir(struct VDir* vd, const char* path) {
UNUSED(vd);
return VDirOpen(path);
}
static const char* _vdleName(struct VDirEntry* vde) {
struct VDirEntryDevList* vdle = (struct VDirEntryDevList*) vde;
return vdle->name;
}
static enum VFSType _vdleType(struct VDirEntry* vde) {
UNUSED(vde);
return VFS_DIRECTORY;
}

View File

@ -34,6 +34,11 @@ struct VDirDE {
};
struct VDir* VDirOpen(const char* path) {
#ifdef __wii__
if (!path || !path[0]) {
return VDeviceList();
}
#endif
DIR* de = opendir(path);
if (!de) {
return 0;