diff --git a/libn3ds/include/fsutil.h b/libn3ds/include/fsutil.h index 7c16595..c3bc973 100644 --- a/libn3ds/include/fsutil.h +++ b/libn3ds/include/fsutil.h @@ -26,3 +26,4 @@ Result fsQuickRead(const char *const path, void *const buf, u32 size); Result fsQuickWrite(const char *const path, const void *const buf, u32 size); Result fsMakePath(const char *const path); +Result fsLoadPathFromFile(const char *const path, char outPath[512]); diff --git a/libn3ds/source/fsutil.c b/libn3ds/source/fsutil.c index a25b22f..884947c 100644 --- a/libn3ds/source/fsutil.c +++ b/libn3ds/source/fsutil.c @@ -87,3 +87,15 @@ Result fsMakePath(const char *const path) return res; } + +Result fsLoadPathFromFile(const char *const path, char outPath[512]) +{ + Result res = fsQuickRead(path, outPath, 511); + if(res == RES_OK) + { + char *const invalidChar = strpbrk(outPath, "\n\r\t"); + if(invalidChar != NULL) *invalidChar = '\0'; + } + + return res; +} diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index 352bef8..148cc02 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -559,7 +559,7 @@ static Result showFileBrowser(char romAndSavePath[512]) do { // Get last ROM launch path. - if((res = fsQuickRead("lastdir.bin", lastDir, 511)) != RES_OK) + if((res = fsLoadPathFromFile("lastdir.txt", lastDir)) != FR_OK) { if(res == RES_FR_NO_FILE) strcpy(lastDir, "sdmc:/"); else break; @@ -583,7 +583,7 @@ static Result showFileBrowser(char romAndSavePath[512]) { strncpy(lastDir, romAndSavePath, cmpLen); lastDir[cmpLen] = '\0'; - res = fsQuickWrite("lastdir.bin", lastDir, cmpLen + 1); + res = fsQuickWrite("lastdir.txt", lastDir, cmpLen + 1); } } } while(0); @@ -618,14 +618,18 @@ u8 oafGetBacklightConfig(void) Result oafInitAndRun(void) { Result res; - char *const romAndSavePath = (char*)malloc(512); + char *const romAndSavePath = (char*)calloc(512, 1); if(romAndSavePath != NULL) { do { - if((res = showFileBrowser(romAndSavePath)) != RES_OK || *romAndSavePath == '\0') break; + if((res = fsLoadPathFromFile("autoboot.txt", romAndSavePath)) == RES_FR_NO_FILE) + { + if((res = showFileBrowser(romAndSavePath)) != RES_OK || *romAndSavePath == '\0') break; + ee_puts("Loading..."); + } + else if(res != RES_OK) break; - ee_puts("Loading..."); u32 romSize; if((res = loadGbaRom(romAndSavePath, &romSize)) != RES_OK) break;