Add sysmodule selector
Build / Build (push) Successful in 17s

Lists every sd:/atmosphere/contents/<TID>/ that ships a toolbox.json and
removes the chosen sysmodule, so any installed sysmodule can be
uninstalled without hardcoded title IDs.
This commit is contained in:
niklascfw committed 2026-11-30 22:14:22 +01:00
1 parent 2f07b26963
commit 81c8f0c92a
3 files changed
+187

No files matched your search

+180
View File
@@ -953,3 +953,183 @@ void m_entry_fixAll(){
m_entry_stillNoBootInfo();
}
// ---------------------------------------------------------------------------
// Sysmodule selector: lists every sd:/atmosphere/contents/<TID>/ 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/<TitleID>\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);
}
+1
View File
@@ -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);
+6
View File
@@ -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,