From 79027591acb8c8f7e9d6c2b87e46d9a909823d87 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sun, 1 Dec 2019 15:42:37 +0100 Subject: [PATCH] Add basic folder navigation + Add hekate/ams to shutdown menu --- source/tegraexplorer/fs.c | 62 +++++++++++++++++++++++++++++++++++++-- source/tegraexplorer/fs.h | 3 +- source/tegraexplorer/te.c | 31 ++++++++++++++++++-- source/tegraexplorer/te.h | 4 ++- 4 files changed, 92 insertions(+), 8 deletions(-) diff --git a/source/tegraexplorer/fs.c b/source/tegraexplorer/fs.c index ebd2d58..ba56976 100644 --- a/source/tegraexplorer/fs.c +++ b/source/tegraexplorer/fs.c @@ -24,6 +24,38 @@ char *getnextloc(char *current, char *add){ return ret; } +char *getprevloc(char *current){ + char *ret, *temp; + size_t size = strlen(current) + 1; + + ret = (char*) malloc (size); + strcpy(ret, current); + + temp = strrchr(ret, '/'); + memset(temp, '\0', 1); + + if (strlen(rootpath) > strlen(ret)) + strcpy(ret, rootpath); + + return ret; +} + +fs_entry getfileobj(int spot){ + return fileobjects[spot]; +} + +bool checkfile(char* path){ + FRESULT fr; + FILINFO fno; + + fr = f_stat(path, &fno); + + if (fr & FR_NO_FILE) + return false; + else + return true; +} + void addobject(char* name, int spot, bool isfol, bool isarc){ size_t size = strlen(name) + 1; fileobjects[spot].property = 0; @@ -76,10 +108,34 @@ int readfolder(const char *path){ } void filemenu(const char *startpath){ - int amount; + int amount, res; strcpy(rootpath, startpath); strcpy(currentpath, startpath); - amount = readfolder(currentpath); - makefilemenu(fileobjects, amount, currentpath); + + while (1){ + res = makefilemenu(fileobjects, amount, currentpath); + if (res < 1){ + if (res == -2){ + if (!strcmp(rootpath, currentpath)) + break; + else { + strcpy(currentpath, getprevloc(currentpath)); + amount = readfolder(currentpath); + } + } + if (res == -1){ + break; + } + + if (res == 0) + break; + } + else { + if (fileobjects[res - 1].property & ISDIR){ + strcpy(currentpath, getnextloc(currentpath, fileobjects[res - 1].name)); + amount = readfolder(currentpath); + } + } + } } \ No newline at end of file diff --git a/source/tegraexplorer/fs.h b/source/tegraexplorer/fs.h index 36bcdc4..3071b60 100644 --- a/source/tegraexplorer/fs.h +++ b/source/tegraexplorer/fs.h @@ -25,4 +25,5 @@ typedef struct _fs_entry { } fs_entry; int readfolder(const char *path); -void filemenu(); \ No newline at end of file +void filemenu(); +bool checkfile(char* path); \ No newline at end of file diff --git a/source/tegraexplorer/te.c b/source/tegraexplorer/te.c index ee54ba2..1cd4495 100644 --- a/source/tegraexplorer/te.c +++ b/source/tegraexplorer/te.c @@ -8,6 +8,7 @@ extern bool sd_mount(); extern void sd_unmount(); +extern int launch_payload(char *path); bool sd_mounted; menu_item mainmenu[MAINMENU_AMOUNT] = { @@ -19,12 +20,14 @@ menu_item mainmenu[MAINMENU_AMOUNT] = { {"Exit", COLOR_WHITE, EXIT, 1} }; -menu_item shutdownmenu[5] = { +menu_item shutdownmenu[7] = { {"-- EXIT --\n", COLOR_ORANGE, -1, 0}, {"Back", COLOR_WHITE, -1, 1}, {"\nReboot to RCM", COLOR_VIOLET, REBOOT_RCM, 1}, {"Reboot normally", COLOR_ORANGE, REBOOT_NORMAL, 1}, - {"Power off", COLOR_BLUE, POWER_OFF, 1} + {"Power off\n", COLOR_BLUE, POWER_OFF, 1}, + {"Reboot to Hekate", COLOR_GREEN, HEKATE, -1}, + {"Reboot to Atmosphere", COLOR_GREEN, AMS, -1} }; menu_item toolsmenu[3] = { @@ -96,7 +99,23 @@ void te_main(){ break; case EXIT: - res = makemenu(shutdownmenu, 5); + if (sd_mounted){ + if (checkfile("/bootloader/update.bin")) + shutdownmenu[5].property = 1; + else + shutdownmenu[5].property = -1; + + if (checkfile("/atmosphere/reboot_payload.bin")) + shutdownmenu[6].property = 1; + else + shutdownmenu[6].property = -1; + } + else { + shutdownmenu[5].property = -1; + shutdownmenu[6].property = -1; + } + + res = makemenu(shutdownmenu, 7); switch(res){ case REBOOT_RCM: @@ -107,6 +126,12 @@ void te_main(){ case POWER_OFF: power_off(); + + case HEKATE: + launch_payload("/bootloader/update.bin"); + + case AMS: + launch_payload("/atmosphere/reboot_payload.bin"); } //todo declock bpmp break; diff --git a/source/tegraexplorer/te.h b/source/tegraexplorer/te.h index f6c2f66..2e362cf 100644 --- a/source/tegraexplorer/te.h +++ b/source/tegraexplorer/te.h @@ -23,7 +23,9 @@ enum mainmenu_return { enum shutdownmenu_return { REBOOT_RCM = 1, REBOOT_NORMAL, - POWER_OFF + POWER_OFF, + HEKATE, + AMS }; enum toolsmenu_return {