diff --git a/include/arm11/config.h b/include/arm11/config.h index 7077031..5064671 100644 --- a/include/arm11/config.h +++ b/include/arm11/config.h @@ -75,6 +75,7 @@ bool configIsLoaded(); bool configHasChanged(); FsDevice configGetStorageLocation(); +bool configSetStorageLocation(FsDevice device); bool writeConfigFile(); void *configCopyText(int key); const void *configGetData(int key); diff --git a/include/arm11/menu/menu_fb3ds.h b/include/arm11/menu/menu_fb3ds.h index d7bfc59..c826642 100644 --- a/include/arm11/menu/menu_fb3ds.h +++ b/include/arm11/menu/menu_fb3ds.h @@ -75,6 +75,7 @@ #define DESC_DUMP_BOOTROM "Dump boot9.bin, boot11.bin & otp.bin.\nFiles are written to sdmc:/3DS. Your console will power off when finished." #define DESC_UPDATE "Update fastboot3ds. Only signed updates are allowed." +#define DESC_MOVE_CONFIG "Change location of the config file." #define DESC_CREDITS "Show fastboot3ds credits." // unused definitions below: @@ -152,10 +153,11 @@ } }, { // 6 - "Miscellaneous", 3, NULL, 0, + "Miscellaneous", 4, NULL, 0, { { "Update fastboot3DS", DESC_UPDATE, &menuUpdateFastboot3ds, 0 }, { "Dump bootroms & OTP", DESC_DUMP_BOOTROM, &menuDumpBootrom, 0 }, + { "Change config location", DESC_MOVE_CONFIG, &menuMoveConfig, 0 }, { "Credits", DESC_CREDITS, &menuShowCredits, 0 } } }, diff --git a/include/arm11/menu/menu_func.h b/include/arm11/menu/menu_func.h index c206a8f..56d6a9b 100644 --- a/include/arm11/menu/menu_func.h +++ b/include/arm11/menu/menu_func.h @@ -63,6 +63,7 @@ u32 menuUpdateFastboot3ds(PrintConsole* term_con, PrintConsole* menu_con, u32 param); u32 menuShowCredits(PrintConsole* term_con, PrintConsole* menu_con, u32 param); u32 menuDumpBootrom(PrintConsole* term_con, PrintConsole* menu_con, u32 param); +u32 menuMoveConfig(PrintConsole* term_con, PrintConsole* menu_con, u32 param); // everything below has to go u32 menuDummyFunc(PrintConsole* term_con, PrintConsole* menu_con, u32 param); diff --git a/source/arm11/config.c b/source/arm11/config.c index 4506e61..f39a5db 100644 --- a/source/arm11/config.c +++ b/source/arm11/config.c @@ -53,6 +53,7 @@ static void unloadConfigFile(); static bool createConfigFile(); +static bool moveConfigFile(); static bool parseConfigFile(); static bool parsePath(AttributeEntryType *attr); static bool writePath(AttributeEntryType *attr, const void *newData, int key); @@ -139,7 +140,6 @@ s32 file; u32 fileSize; bool SdPresent; - bool adpotChanges = false; bool createFile = false; if(filebuf) @@ -162,11 +162,13 @@ if(fStat(NandFilepath, &fileStat) == FR_OK) { /* no config on SD, but there is one on the NAND, - so just load it and save it later on. */ - adpotChanges = true; + so we will use this instead. */ + filepath = NandFilepath; } - - createFile = true; + else + { + createFile = true; + } } } else /* use NAND */ @@ -185,12 +187,6 @@ if(!createConfigFile()) return false; - if(adpotChanges) - { - // created file on SD, load config from NAND - filepath = NandFilepath; - } - // retrieve size if(fStat(filepath, &fileStat) != FR_OK) return false; @@ -236,13 +232,6 @@ if(!parseConfigFile()) goto fail; - // we loaded a file we want to adpot? - if(adpotChanges) - { - filepath = SdmcFilepath; - configDirty = true; - } - return true; fail: @@ -301,6 +290,17 @@ return FS_DEVICE_NAND; } +bool configSetStorageLocation(FsDevice device) +{ + if (!configLoaded) + panic(); + + if (device == configGetStorageLocation()) + return false; + + return moveConfigFile(); +} + bool writeConfigFile() { s32 file; @@ -367,6 +367,38 @@ return ret; } +static bool moveConfigFile() +{ + const char* filepath_old = filepath; + + // if current location is SD: + // delete config file from SD, write to NAND + if (configGetStorageLocation() == FS_DEVICE_SDMC) + { + fUnlink(filepath); + + filepath = NandFilepath; + } + // if current location is NAND and SD present: + // just change the location + else + { + filepath = SdmcFilepath; + } + + if (writeConfigFile()) + { + configDirty = false; + return true; + } + else + { + filepath = filepath_old; + configDirty = true; + return false; + } +} + static inline bool isEOL(const char c) { const char LF = 0x0A, CR = 0x0D, NEL = 0x15; diff --git a/source/arm11/menu/menu_func.c b/source/arm11/menu/menu_func.c index 7fa0329..2520540 100644 --- a/source/arm11/menu/menu_func.c +++ b/source/arm11/menu/menu_func.c @@ -1137,6 +1137,63 @@ return result; } +u32 menuMoveConfig(PrintConsole* term_con, PrintConsole* menu_con, u32 param) +{ + (void) menu_con; + (void) param; + u32 result = MENU_FAIL; + + FsDevice loc_conf = configGetStorageLocation(); + FsDevice loc_new = (loc_conf == FS_DEVICE_NAND) ? FS_DEVICE_SDMC : FS_DEVICE_NAND; + + // select & clear console + consoleSelect(term_con); + consoleClear(); + + + ee_printf(ESC_SCHEME_ACCENT1 "Moving config file:\nCurrent location is %s\n" ESC_RESET "\nMoving config to %s...\n", + (loc_conf == FS_DEVICE_NAND) ? "NAND" : "SDMC", + (loc_new == FS_DEVICE_NAND) ? "NAND" : "SDMC"); + updateScreens(); + + + // ensure SD mounted + if (!fsEnsureMounted("sdmc:")) + { + ee_printf("SD not inserted or corrupt!\n"); + goto fail; + } + + // get NAND size (return value in sectors) + const s64 nand_size = fGetDeviceSize(FS_DEVICE_NAND) * 0x200; + if (!nand_size) + { + ee_printf("Failed communicating with NAND!\n"); + goto fail; + } + + // actually move the config file + if (!configSetStorageLocation(loc_new)) + { + ee_printf("Failed moving the config file!\n"); + goto fail; + } + + ee_printf("Config written to new location.\n"); + result = MENU_OK; + + + fail: + + ee_printf("\nPress B or HOME to return."); + updateScreens(); + outputEndWait(); + + + hidScanInput(); // throw away any input from impatient users + return result; +} + u32 menuShowCredits(PrintConsole* term_con, PrintConsole* menu_con, u32 param) { (void) menu_con;