From 48def49f8b720a55b2a5fdebff4f76170f21cc10 Mon Sep 17 00:00:00 2001 From: profi200 Date: Sun, 29 Nov 2020 22:52:13 +0100 Subject: [PATCH] Use relative paths where possible. --- include/fs.h | 1 + include/ipc_handler.h | 1 + source/arm11/fs.c | 9 +++++++++ source/arm11/main.c | 17 +++++++++-------- source/arm9/fs.c | 5 +++++ source/arm9/ipc_handler.c | 3 +++ thirdparty/fatfs/ffconf.h | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/include/fs.h b/include/fs.h index 142fc19..493adfb 100644 --- a/include/fs.h +++ b/include/fs.h @@ -51,6 +51,7 @@ u32 fTell(FHandle h); u32 fSize(FHandle h); Result fClose(FHandle h); Result fStat(const char *const path, FILINFO *const fi); +Result fChdir(const char *const path); Result fOpenDir(DHandle *const hOut, const char *const path); Result fReadDir(DHandle h, FILINFO *const fi, u32 num, u32 *const entriesRead); Result fCloseDir(DHandle h); diff --git a/include/ipc_handler.h b/include/ipc_handler.h index b95d69b..40bcaca 100644 --- a/include/ipc_handler.h +++ b/include/ipc_handler.h @@ -50,6 +50,7 @@ typedef enum IPC_CMD9_FSIZE = MAKE_CMD9(0, 0, 1), IPC_CMD9_FCLOSE = MAKE_CMD9(0, 0, 1), IPC_CMD9_FSTAT = MAKE_CMD9(1, 1, 0), + IPC_CMD9_FCHDIR = MAKE_CMD9(1, 0, 0), IPC_CMD9_FOPEN_DIR = MAKE_CMD9(1, 1, 0), IPC_CMD9_FREAD_DIR = MAKE_CMD9(0, 2, 2), IPC_CMD9_FCLOSE_DIR = MAKE_CMD9(0, 0, 1), diff --git a/source/arm11/fs.c b/source/arm11/fs.c index 2bd7022..0d7983a 100644 --- a/source/arm11/fs.c +++ b/source/arm11/fs.c @@ -127,6 +127,15 @@ Result fStat(const char *const path, FILINFO *const fi) return PXI_sendCmd(IPC_CMD9_FSTAT, cmdBuf, 4); } +Result fChdir(const char *const path) +{ + u32 cmdBuf[2]; + cmdBuf[0] = (u32)path; + cmdBuf[1] = strlen(path) + 1; + + return PXI_sendCmd(IPC_CMD9_FCHDIR, cmdBuf, 2); +} + Result fOpenDir(DHandle *const hOut, const char *const path) { u32 cmdBuf[4]; diff --git a/source/arm11/main.c b/source/arm11/main.c index 9fc5456..173bc58 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -157,7 +157,7 @@ static Result searchGameDb(u64 x, GameDbEntry *const db, s32 *const entryPos) Result res; FHandle f; - if((res = fOpen(&f, OAF_WORK_DIR "/gba_db.bin", FA_OPEN_EXISTING | FA_READ)) == RES_OK) + if((res = fOpen(&f, "gba_db.bin", FA_OPEN_EXISTING | FA_READ)) == RES_OK) { s32 l = 0; s32 r = fSize(f) / sizeof(GameDbEntry) - 1; // TODO: Check for 0! @@ -391,7 +391,7 @@ static u16 saveDbDebug(const char *const savePath, u32 romSize) { dbEntry.attr = saveType; FHandle f; - if(fOpen(&f, OAF_WORK_DIR "/gba_db.bin", FA_OPEN_EXISTING | FA_WRITE) == RES_OK) + if(fOpen(&f, "gba_db.bin", FA_OPEN_EXISTING | FA_WRITE) == RES_OK) { fLseek(f, (sizeof(GameDbEntry) * dbPos) + offsetof(GameDbEntry, attr)); fWrite(f, &dbEntry.attr, sizeof(dbEntry.attr), NULL); @@ -456,7 +456,7 @@ static Result dumpFrameTex(void) memcpy((void*)0x18400000, bmpHeader, sizeof(bmpHeader)); - return fsQuickWrite("sdmc:/texture_dump.bmp", (void*)0x18400000, 0x40 + 512 * 512 * 3); + return fsQuickWrite("texture_dump.bmp", (void*)0x18400000, 0x40 + 512 * 512 * 3); } static void gbaGfxHandler(void *args) @@ -568,12 +568,12 @@ static Result parseMainConfig(void) char *iniBuf = (char*)calloc(INI_BUF_SIZE, 1); if(iniBuf == NULL) return RES_OUT_OF_MEM; - Result res = fsQuickRead(OAF_WORK_DIR "/config.ini", iniBuf, INI_BUF_SIZE - 1); + Result res = fsQuickRead("config.ini", iniBuf, INI_BUF_SIZE - 1); if(res == RES_OK) ini_parse_string(iniBuf, confIniCallback, &g_oafConfig); else { const char *const defaultConfig = DEFAULT_CONFIG; - res = fsQuickWrite(OAF_WORK_DIR "/config.ini", defaultConfig, strlen(defaultConfig)); + res = fsQuickWrite("config.ini", defaultConfig, strlen(defaultConfig)); } // Apply backlight brightness. @@ -597,14 +597,15 @@ static Result handleFsStuff(char romPath[512]) { do { - // Create working dir. + // Create the work dir and switch to it. if((res = fsMakePath(OAF_WORK_DIR)) != RES_OK && res != RES_FR_EXIST) break; + if((res = fChdir(OAF_WORK_DIR)) != RES_OK) break; // Parse config. parseMainConfig(); // Get last ROM launch path. - if((res = fsQuickRead(OAF_WORK_DIR "/lastdir.bin", lastDir, 511)) != RES_OK) + if((res = fsQuickRead("lastdir.bin", lastDir, 511)) != RES_OK) { if(res == RES_FR_NO_FILE) strcpy(lastDir, "sdmc:/"); else break; @@ -631,7 +632,7 @@ static Result handleFsStuff(char romPath[512]) { strncpy(lastDir, romPath, cmpLen); lastDir[cmpLen] = '\0'; - res = fsQuickWrite(OAF_WORK_DIR "/lastdir.bin", lastDir, cmpLen + 1); + res = fsQuickWrite("lastdir.bin", lastDir, cmpLen + 1); } } } while(0); diff --git a/source/arm9/fs.c b/source/arm9/fs.c index 5a8ae3c..31b4a3b 100644 --- a/source/arm9/fs.c +++ b/source/arm9/fs.c @@ -197,6 +197,11 @@ Result fStat(const char *const path, FILINFO *const fi) return fres2Res(f_stat(path, fi)); } +Result fChdir(const char *const path) +{ + return fres2Res(f_chdir(path)); +} + Result fOpenDir(DHandle *const hOut, const char *const path) { if(hOut == NULL) return RES_INVALID_ARG; diff --git a/source/arm9/ipc_handler.c b/source/arm9/ipc_handler.c index c779f1a..06fe07d 100644 --- a/source/arm9/ipc_handler.c +++ b/source/arm9/ipc_handler.c @@ -73,6 +73,9 @@ u32 IPC_handleCmd(u8 cmdId, u32 inBufs, u32 outBufs, const u32 *const buf) case IPC_CMD_ID_MASK(IPC_CMD9_FSTAT): result = fStat((const char *const)buf[0], (FILINFO *const)buf[2]); break; + case IPC_CMD_ID_MASK(IPC_CMD9_FCHDIR): + result = fChdir((const char *const)buf[0]); + break; case IPC_CMD_ID_MASK(IPC_CMD9_FOPEN_DIR): result = fOpenDir((DHandle *const)buf[2], (const char *const)buf[0]); break; diff --git a/thirdparty/fatfs/ffconf.h b/thirdparty/fatfs/ffconf.h index cbfc685..10c97c6 100644 --- a/thirdparty/fatfs/ffconf.h +++ b/thirdparty/fatfs/ffconf.h @@ -150,7 +150,7 @@ */ -#define FF_FS_RPATH 0 +#define FF_FS_RPATH 1 /* This option configures support for relative path. / / 0: Disable relative path and remove related functions.