From bfcdc2ffd585ebf6adb7cff846095bc123c4418f Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sun, 22 Mar 2020 22:56:36 +0100 Subject: [PATCH] Ignore menu entries in entries count and include sd ejection detection --- source/main.c | 11 +--------- source/tegraexplorer/common/common.h | 3 ++- source/tegraexplorer/common/strings.c | 3 ++- source/tegraexplorer/fs/filemenu.c | 2 ++ source/tegraexplorer/fs/foldermenu.c | 1 + source/tegraexplorer/fs/fsmenu.c | 5 ++++- source/tegraexplorer/gfx/gfxutils.c | 2 +- source/tegraexplorer/gfx/menu.c | 31 ++++++++++++++++++++++----- source/tegraexplorer/mainmenu.c | 14 ++++++------ 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/source/main.c b/source/main.c index 51f5378..63d4cd3 100644 --- a/source/main.c +++ b/source/main.c @@ -45,20 +45,11 @@ sdmmc_t sd_sdmmc; sdmmc_storage_t sd_storage; __attribute__ ((aligned (16))) FATFS sd_fs; -static bool sd_mounted, sd_inited; +bool sd_mounted, sd_inited; volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR; hekate_config h_cfg; boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg; -bool return_sd_mounted(int value){ - switch(value){ - case 10: - return sd_inited; - default: - return sd_mounted; - } -} - bool sd_mount() { if (sd_mounted) diff --git a/source/tegraexplorer/common/common.h b/source/tegraexplorer/common/common.h index c7317b2..31c7b61 100644 --- a/source/tegraexplorer/common/common.h +++ b/source/tegraexplorer/common/common.h @@ -19,7 +19,8 @@ enum utils_err_codes_te_call { ERR_MEM_ALLOC_FAILED, ERR_EMMC_READ_FAILED, ERR_EMMC_WRITE_FAILED, - ERR_FILE_TOO_BIG_FOR_DEST + ERR_FILE_TOO_BIG_FOR_DEST, + ERR_SD_EJECTED }; extern const char *utils_err_codes_te[]; diff --git a/source/tegraexplorer/common/strings.c b/source/tegraexplorer/common/strings.c index e3d2f23..6271bf7 100644 --- a/source/tegraexplorer/common/strings.c +++ b/source/tegraexplorer/common/strings.c @@ -48,7 +48,8 @@ const char *utils_err_codes_te[] = { // these start at 50 "MEM ALLOC FAILED", "EMMC READ FAILED", "EMMC WRITE FAILED", - "FILE TOO BIG FOR DEST" + "FILE TOO BIG FOR DEST", + "SD EJECTED" }; const char *pkg2names[] = { diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index 8c0360a..d2792a0 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -179,6 +179,8 @@ int filemenu(menu_entry file){ case FILE_RESTOREBIS: restore_bis_using_file(fsutil_getnextloc(currentpath, file.name), SYSMMC); break; + case -1: + return -1; } return 0; diff --git a/source/tegraexplorer/fs/foldermenu.c b/source/tegraexplorer/fs/foldermenu.c index 5aa5719..0ef97e0 100644 --- a/source/tegraexplorer/fs/foldermenu.c +++ b/source/tegraexplorer/fs/foldermenu.c @@ -66,6 +66,7 @@ int foldermenu(){ switch (res){ case DIR_EXITFOLDER: + case -1: return -1; case DIR_COPYFOLDER: fsreader_writeclipboard(currentpath, OPERATIONCOPY | ISDIR); diff --git a/source/tegraexplorer/fs/fsmenu.c b/source/tegraexplorer/fs/fsmenu.c index 2cdf8fd..7a56e8b 100644 --- a/source/tegraexplorer/fs/fsmenu.c +++ b/source/tegraexplorer/fs/fsmenu.c @@ -54,6 +54,8 @@ void fileexplorer(const char *startpath, int type){ if (foldermenu()) return; break; + case -1: + return; default: if(fsreader_files[res].property & ISDIR){ @@ -61,7 +63,8 @@ void fileexplorer(const char *startpath, int type){ fsreader_readfolder(currentpath); } else - filemenu(fsreader_files[res]); + if(filemenu(fsreader_files[res])) + return; break; } diff --git a/source/tegraexplorer/gfx/gfxutils.c b/source/tegraexplorer/gfx/gfxutils.c index 8d27e5e..144b126 100644 --- a/source/tegraexplorer/gfx/gfxutils.c +++ b/source/tegraexplorer/gfx/gfxutils.c @@ -54,7 +54,7 @@ int gfx_errDisplay(char *src_func, int err, int loc){ if (err < 15) gfx_printf("Desc: %s\n", utils_err_codes[err]); - else if (err >= ERR_SAME_LOC && err <= ERR_FILE_TOO_BIG_FOR_DEST) + else if (err >= ERR_SAME_LOC && err <= ERR_SD_EJECTED) gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]); if (loc) diff --git a/source/tegraexplorer/gfx/menu.c b/source/tegraexplorer/gfx/menu.c index 3ff75da..c10c300 100644 --- a/source/tegraexplorer/gfx/menu.c +++ b/source/tegraexplorer/gfx/menu.c @@ -5,6 +5,11 @@ #include "../common/common.h" #include "../../utils/util.h" #include "../../mem/minerva.h" +#include "../../soc/gpio.h" +#include "gfxutils.h" + +extern void sd_unmount(); +extern bool sd_inited; void _printentry(menu_entry entry, bool highlighted, bool refresh){ int size; @@ -54,17 +59,25 @@ void _printentry(menu_entry entry, bool highlighted, bool refresh){ } int menu_make(menu_entry *entries, int amount, char *toptext){ - int currentpos = 0, res = 0, offset = 0, delay = 300, minscreen = 0, maxscreen = 59; + int currentpos = 0, res = 0, offset = 0, delay = 300, minscreen = 0, maxscreen = 59, calculatedamount = 0; u32 scrolltimer, timer; bool refresh = false; gfx_clearscreen(); + for (int i = 0; i < amount; i++) + if (!(entries[i].property & ISMENU)) + calculatedamount++; + gfx_con_setpos(512, 0); - SWAPCOLOR(COLOR_DEFAULT); - SWAPBGCOLOR(COLOR_WHITE); - gfx_printf("%3d entries\n", amount); - RESETCOLOR; + if (calculatedamount){ + SWAPCOLOR(COLOR_DEFAULT); + SWAPBGCOLOR(COLOR_WHITE); + gfx_printf("%3d entries\n", amount); + RESETCOLOR; + } + else + gfx_printf("\n"); SWAPCOLOR(COLOR_GREEN); gfx_printlength(42, toptext); @@ -108,6 +121,14 @@ int menu_make(menu_entry *entries, int amount, char *toptext){ res = 0; while (!res){ + if (!res){ + if (sd_inited && !!gpio_read(GPIO_PORT_Z, GPIO_PIN_1)){ + gfx_errDisplay("menu", ERR_SD_EJECTED, 0); + sd_unmount(); + return -1; + } + } + res = btn_read(); if (!res) diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index cf2425f..f76b381 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -19,8 +19,9 @@ extern bool sd_mount(); extern void sd_unmount(); -extern bool return_sd_mounted(int value); extern int launch_payload(char *path); +extern bool sd_inited; +extern bool sd_mounted; int res = 0, meter = 0; @@ -47,10 +48,7 @@ void MainMenu_EMUMMC(){ } void MainMenu_MountSD(){ - if (return_sd_mounted(1)) - sd_unmount(); - else - sd_mount(); + (sd_mounted) ? sd_unmount() : sd_mount(); } void MainMenu_Tools(){ @@ -100,7 +98,7 @@ void MainMenu_Credits(){ } void MainMenu_Exit(){ - if (return_sd_mounted(1)){ + if (sd_mounted){ SETBIT(mainmenu_shutdown[4].property, ISHIDE, !fsutil_checkfile("/bootloader/update.bin")); SETBIT(mainmenu_shutdown[5].property, ISHIDE, !fsutil_checkfile("/atmosphere/reboot_payload.bin")); } @@ -169,7 +167,7 @@ void te_main(){ while (1){ //fillmainmenu(); - setter = return_sd_mounted(1); + setter = sd_mounted; if (emu_cfg.enabled){ for (int i = 4; i <= 6; i++) @@ -179,7 +177,7 @@ void te_main(){ SETBIT(mainmenu_main[0].property, ISHIDE, !setter); mainmenu_main[7].name = (menu_sd_states[!setter]); - setter = return_sd_mounted(10); + setter = sd_inited; SETBIT(mainmenu_main[9].property, ISHIDE, !setter); res = menu_make(mainmenu_main, 12, "-- Main Menu --") + 1;