diff --git a/src/gba/context/config.c b/src/gba/context/config.c index c0c87ea67..fc6f52fe7 100644 --- a/src/gba/context/config.c +++ b/src/gba/context/config.c @@ -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); diff --git a/src/platform/wii/CMakeLists.txt b/src/platform/wii/CMakeLists.txt index b449d23f1..f31073e88 100644 --- a/src/platform/wii/CMakeLists.txt +++ b/src/platform/wii/CMakeLists.txt @@ -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}) diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index 1b8721b00..60f45a541 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -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, diff --git a/src/util/gui/file-select.c b/src/util/gui/file-select.c index 7844f359d..57ebdc67d 100644 --- a/src/util/gui/file-select.c +++ b/src/util/gui/file-select.c @@ -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); diff --git a/src/util/vfs.h b/src/util/vfs.h index f08322654..8f89e32cf 100644 --- a/src/util/vfs.h +++ b/src/util/vfs.h @@ -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, diff --git a/src/util/vfs/vfs-devlist.c b/src/util/vfs/vfs-devlist.c new file mode 100644 index 000000000..29db4bc07 --- /dev/null +++ b/src/util/vfs/vfs-devlist.c @@ -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 + +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; +} diff --git a/src/util/vfs/vfs-dirent.c b/src/util/vfs/vfs-dirent.c index c3ce64321..5f37be05a 100644 --- a/src/util/vfs/vfs-dirent.c +++ b/src/util/vfs/vfs-dirent.c @@ -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;