diff --git a/source/apl/apl.c b/source/apl/apl.c index 3fae79d..d9c8b99 100644 --- a/source/apl/apl.c +++ b/source/apl/apl.c @@ -953,3 +953,183 @@ void m_entry_fixAll(){ m_entry_stillNoBootInfo(); } + + +// --------------------------------------------------------------------------- +// Sysmodule selector: lists every sd:/atmosphere/contents// that ships a +// toolbox.json (Hekate-Toolbox / Ultrahand convention) and removes the chosen +// one. Works for any sysmodule the user installed, no hardcoded title IDs. +// --------------------------------------------------------------------------- + +#define SYSMOD_MAX 64 +#define SYSMOD_NAME_LEN 48 +#define SYSMOD_LABEL_LEN 80 +#define TOOLBOX_MAX_SIZE 4096 + +typedef struct { + char tid[24]; + char label[SYSMOD_LABEL_LEN]; +} sysmod_entry_t; + +// Extract the string value of "name" from a toolbox.json. Minimal parser: +// the file is a flat object, we only need one string key. +static bool _toolbox_read_name(const char *json_path, char *out, u32 out_sz) +{ + FIL fp; + if (f_open(&fp, json_path, FA_READ) != FR_OK) + return false; + + u32 size = f_size(&fp); + if (size == 0 || size > TOOLBOX_MAX_SIZE) + { + f_close(&fp); + return false; + } + + char *buf = malloc(size + 1); + UINT br = 0; + FRESULT res = f_read(&fp, buf, size, &br); + f_close(&fp); + if (res != FR_OK) + { + free(buf); + return false; + } + buf[br] = 0; + + bool found = false; + char *p = strstr(buf, "\"name\""); + if (p) + { + p += 6; + while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') + p++; + if (*p == ':') + { + p++; + while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') + p++; + if (*p == '"') + { + p++; + u32 n = 0; + while (*p && *p != '"' && n + 1 < out_sz) + { + if (*p == '\\' && p[1]) + p++; + // Font only covers ASCII; replace anything else. + out[n++] = ((u8)*p >= 0x20 && (u8)*p < 0x7F) ? *p : '?'; + p++; + } + out[n] = 0; + found = n > 0; + } + } + } + + free(buf); + return found; +} + +// Fills entries[], returns count (-1 if contents folder can't be read). +static int _sysmod_scan(sysmod_entry_t *entries, int max) +{ + const char *base = "sd:/atmosphere/contents"; + DIR dir; + static FILINFO fno; + if (f_opendir(&dir, base) != FR_OK) + return -1; + + int count = 0; + char json_path[128]; + char name[SYSMOD_NAME_LEN]; + while (count < max) + { + if (f_readdir(&dir, &fno) != FR_OK || fno.fname[0] == 0) + break; + if (!(fno.fattrib & AM_DIR)) + continue; + if (strlen(fno.fname) != 16) // title IDs only + continue; + + s_printf(json_path, "%s/%s/toolbox.json", base, fno.fname); + if (!_toolbox_read_name(json_path, name, sizeof(name))) + continue; + + strcpy(entries[count].tid, fno.fname); + s_printf(entries[count].label, "%s (%s)", name, fno.fname); + count++; + } + f_closedir(&dir); + return count; +} + +void m_entry_sysmoduleSelector(void) +{ + sysmod_entry_t *mods = calloc(SYSMOD_MAX, sizeof(sysmod_entry_t)); + MenuEntry_t *entries = calloc(SYSMOD_MAX + 1, sizeof(MenuEntry_t)); + int sel = 0; + + while (1) + { + gfx_clearscreen(); + gfx_printf("\n\n-- Sysmodule deinstallieren --\n\n"); + + if (!sd_mount()) + { + gfx_printf("SD-Karte konnte nicht gemountet werden.\n"); + gfx_printf("\n\n Druecke eine Taste um zurueckzukehren"); + hidWait(); + break; + } + + int count = _sysmod_scan(mods, SYSMOD_MAX); + if (count <= 0) + { + if (count < 0) + gfx_printf("Ordner sd:/atmosphere/contents nicht gefunden.\n"); + else + gfx_printf("Keine Sysmodule mit toolbox.json gefunden.\n"); + gfx_printf("\n\n Druecke eine Taste um zurueckzukehren"); + hidWait(); + break; + } + + gfx_printf("Auswahl mit A loescht das Sysmodul sofort.\n"); + gfx_printf("Ordner: sd:/atmosphere/contents/\n\n"); + + entries[0].optionUnion = COLORTORGB(COLOR_WHITE); + entries[0].name = "<- Zurueck"; + for (int i = 0; i < count; i++) + { + entries[i + 1].optionUnion = COLORTORGB(COLOR_CYAN); + entries[i + 1].name = mods[i].label; + } + + if (sel > count) + sel = count; + + Vector_t ent = vecFromArray(entries, count + 1, sizeof(MenuEntry_t)); + sel = newMenu(&ent, sel, 79, 20, ENABLEB | ALWAYSREDRAW, count + 1); + if (sel <= 0 || sel > count) + break; + + sysmod_entry_t *m = &mods[sel - 1]; + char path[64]; + s_printf(path, "sd:/atmosphere/contents/%s", m->tid); + + gfx_clearscreen(); + gfx_printf("\n\n-- Sysmodule deinstallieren --\n\n"); + gfx_printf("Entferne %s ...\n", m->label); + ErrCode_t err = FolderDelete(path); + if (err.err) + gfx_printf("%kFehler beim Loeschen (Code %d).%k\n", COLOR_RED, err.err, COLOR_DEFAULT); + else + gfx_printf("%kErfolgreich deinstalliert.%k\n", 0xFF96FF00, 0xFFCCCCCC); + gfx_printf("\n\n Druecke eine Taste um zurueckzukehren"); + hidWait(); + } + + free(entries); + free(mods); +} diff --git a/source/apl/apl.h b/source/apl/apl.h index 0e41e07..3e21d83 100644 --- a/source/apl/apl.h +++ b/source/apl/apl.h @@ -12,3 +12,4 @@ void m_entry_fixAll(); void m_entry_stillNoBootInfo(); void m_entry_fixMacSpecialFolders(); void m_entry_fixMarikoWarmbootSleep(void); +void m_entry_sysmoduleSelector(void); diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index 9a6ab37..a6fee7f 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -40,6 +40,8 @@ enum { FixAMS_4200, FixAMS_6900, FixAMS_BD00, + MainSysmodules, + SysmoduleSelector, MainConvenience, FixMarikoWarmbootSleep, FixMacSpecialFolders, @@ -66,6 +68,9 @@ MenuEntry_t mainMenuEntries[] = { [FixAMS_6900] = {.optionUnion = COLORTORGB(COLOR_CYAN), .name = "Fix 690000000000000D (sys-con)"}, [FixAMS_BD00] = {.optionUnion = COLORTORGB(COLOR_CYAN), .name = "Fix 010000000000BD00 (MissionControl)"}, + [MainSysmodules] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Installierte Sysmodule --"}, + [SysmoduleSelector] = {.optionUnion = COLORTORGB(COLOR_CYAN), .name = "Sysmodul auswaehlen und deinstallieren"}, + [MainConvenience] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Bequemlichkeit --"}, [FixMarikoWarmbootSleep] = {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Mariko Sleep Fix (Warmboot)"}, [FixMacSpecialFolders] = {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Entferne spezielle MacOS Dateien"}, @@ -134,6 +139,7 @@ menuPaths mainMenuPaths[] = { [FixAMS_4200] = m_entry_fixAMSError_4200, [FixAMS_6900] = m_entry_fixAMSError_6900, [FixAMS_BD00] = m_entry_fixAMSError_BD00, + [SysmoduleSelector] = m_entry_sysmoduleSelector, [FixMacSpecialFolders] = m_entry_fixMacSpecialFolders, [FixMarikoWarmbootSleep] = m_entry_fixMarikoWarmbootSleep, // [FixAll] = m_entry_fixAll,