diff --git a/source/cpr/cpr.c b/source/cpr/cpr.c index 40a36f8..35514fa 100644 --- a/source/cpr/cpr.c +++ b/source/cpr/cpr.c @@ -15,6 +15,13 @@ #include "../utils/utils.h" #include "../fs/fsutils.h" +#include +#include +// #include +// #include +#include +#include + void _DeleteFileSimple(char *thing){ //char *thing = CombinePaths(path, entry.name); int res = f_unlink(thing); @@ -28,6 +35,114 @@ void _RenameFileSimple(char *sourcePath, char *destPath){ DrawError(newErrCode(res)); } } +ErrCode_t _FolderDelete(const char *path){ + int res = 0; + ErrCode_t ret = newErrCode(0); + u32 x, y; + gfx_con_getpos(&x, &y); + Vector_t fileVec = ReadFolder(path, &res); + if (res){ + ret = newErrCode(res); + } + else { + vecDefArray(FSEntry_t *, fs, fileVec); + for (int i = 0; i < fileVec.count && !ret.err; i++){ + char *temp = CombinePaths(path, fs[i].name); + if (fs[i].isDir){ + ret = _FolderDelete(temp); + } + else { + res = f_unlink(temp); + if (res){ + ret = newErrCode(res); + } + } + free(temp); + } + } + if (!ret.err){ + res = f_unlink(path); + if (res) + ret = newErrCode(res); + } + clearFileVector(&fileVec); + return ret; +} +int _StartsWith(const char *a, const char *b) +{ + if(strncmp(a, b, strlen(b)) == 0) return 1; + return 0; +} + +int listdir(char *path, u32 hos_folder) +{ + FRESULT res; + DIR dir; + u32 dirLength = 0; + static FILINFO fno; + + // Open directory. + res = f_opendir(&dir, path); + if (res != FR_OK) + return res; + + dirLength = strlen(path); + for (;;) + { + // Clear file or folder path. + path[dirLength] = 0; + // Read a directory item. + res = f_readdir(&dir, &fno); + // Break on error or end of dir. + if (res != FR_OK || fno.fname[0] == 0) + break; + // Skip official Nintendo dir if started from root. + if (!hos_folder && !strcmp(fno.fname, "Nintendo")) + continue; + + // // Set new directory or file. + memcpy(&path[dirLength], "/", 1); + memcpy(&path[dirLength + 1], fno.fname, strlen(fno.fname) + 1); + // gfx_printf("THING: %s\n", fno.fname); + // gfx_printf("Path: %s\n", dir); + // Is it a directory? + if (fno.fattrib & AM_DIR) + { + if ( + strcmp(fno.fname, ".Trash") == 0 || + strcmp(fno.fname, ".Trashes") == 0 || + strcmp(fno.fname, ".DS_Store") == 0 || + strcmp(fno.fname, ".Spotlight-V100") == 0 || + strcmp(fno.fname, ".apDisk") == 0 || + strcmp(fno.fname, ".VolumeIcon.icns") == 0 || + strcmp(fno.fname, ".fseventsd") == 0 || + strcmp(fno.fname, ".TemporaryItems") == 0 + ) { + _FolderDelete(path); + } + + // Enter the directory. + listdir(path, 0); + if (res != FR_OK) + break; + } else { + if ( + strcmp(fno.fname, ".DS_Store") == 0 || + strcmp(fno.fname, ".Spotlight-V100") == 0 || + strcmp(fno.fname, ".apDisk") == 0 || + strcmp(fno.fname, ".VolumeIcon.icns") == 0 || + strcmp(fno.fname, ".fseventsd") == 0 || + strcmp(fno.fname, ".TemporaryItems") == 0 || + _StartsWith(fno.fname, "._") + ) { + _DeleteFileSimple(path); + } + } + } + f_closedir(&dir); + free(path); + return res; +} int _fix_attributes(char *path, u32 *total, u32 hos_folder, u32 check_first_run){ FRESULT res; @@ -286,7 +401,15 @@ void m_entry_deleteBootFlags(){ hidWait(); } -void m_entry_fixMacSpecialFolders(char *path){ + + +void m_entry_fixMacSpecialFolders(){ + gfx_clearscreen(); + gfx_printf("\n\n-- Fix mac folders (this can take some time, please wait.)\n\n"); + listdir("/", 0); + gfx_printf("\n\rDone, press a key to proceed."); + hidWait(); + // browse path // list files & folders // if file -> delete diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index 80841f3..bcafa69 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -37,8 +37,9 @@ enum { FixAIOUpdaterBoot, FixArchiveBitA, FixArchiveBitN, - // FixMacSpecialFolders, - FixAll, + // FixAll, + MainConvenience, + FixMacSpecialFolders, MainOther, MainViewStillNoBootInfo, MainViewCredits, @@ -51,18 +52,28 @@ enum { }; MenuEntry_t mainMenuEntries[] = { - [MainExplore] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "-- Tools --"}, + [MainExplore] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "-- Bootfixes --"}, [DeleteBootFlags] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Disable automatic sysmodule startup"}, [DeleteThemes] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Delete installed themes"}, [FixClingWrap] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix ClingWrap"}, [FixAIOUpdaterBoot] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix Switch-AiO-Updater update"}, [FixArchiveBitA] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix archive bit (all folders except nintendo)"}, [FixArchiveBitN] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Fix archive bit (nintendo folder)"}, - // [FixMacSpecialFolders] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Remove special folders created by Mac"}, - [FixAll] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Try everything"}, - [MainOther] = {.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT, .name = "\n-- Other --"}, + // [FixAll] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Try everything"}, + [MainConvenience] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Convenience --"}, + [FixMacSpecialFolders] = {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Remove special folders created by Mac"}, + [MainOther] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Other --"}, + [MainViewStillNoBootInfo] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "My switch still does not boot"}, + [MainViewCredits] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "Credits"}, + + [MainExit] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Exit --"}, + [MainPowerOff] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Power off"}, + [MainRebootRCM] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to RCM"}, + // [MainRebootNormal] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot normally"}, + [MainRebootHekate] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to bootloader/update.bin"}, + [MainRebootAMS] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to atmosphere/reboot_payload.bin"} // [MainBrowseSd] = {.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Browse SD"}, @@ -73,15 +84,7 @@ MenuEntry_t mainMenuEntries[] = { // [MainPartitionSd] = {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Partition the sd"}, // [MainDumpFw] = {.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Dump Firmware"}, // [MainViewKeys] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "View dumped keys"}, - [MainOther] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Other --"}, - [MainViewStillNoBootInfo] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "My switch still does not boot"}, - [MainViewCredits] = {.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "Credits"}, - [MainExit] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Exit --"}, - [MainPowerOff] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Power off"}, - [MainRebootRCM] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to RCM"}, - // [MainRebootNormal] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot normally"}, - [MainRebootHekate] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to bootloader/update.bin"}, - [MainRebootAMS] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to atmosphere/reboot_payload.bin"} + }; void HandleSD(){ @@ -132,8 +135,8 @@ menuPaths mainMenuPaths[] = { [FixAIOUpdaterBoot] = m_entry_fixAIOUpdate, [FixArchiveBitA] = archBitHelperA, [FixArchiveBitN] = archBitHelperN, - // [FixMacSpecialFolders] = m_entry_fixMacSpecialFolders, - [FixAll] = m_entry_fixAll, + [FixMacSpecialFolders] = m_entry_fixMacSpecialFolders, + // [FixAll] = m_entry_fixAll, [MainViewStillNoBootInfo] = m_entry_stillNoBootInfo, [MainRebootHekate] = RebootToHekate, [MainRebootRCM] = reboot_rcm,