From af3408a8aa811d29bb49c124f70fffbf484d9f2a Mon Sep 17 00:00:00 2001 From: Pk11 Date: Fri, 14 Jan 2022 20:42:01 -0600 Subject: [PATCH] Allow (un)installing non-preinstalled system apps --- arm9/src/install.c | 67 ++++++++++++++++++++++++++------------------ arm9/src/storage.c | 9 ++++++ arm9/src/storage.h | 1 + arm9/src/titlemenu.c | 23 +++++++++++---- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/arm9/src/install.c b/arm9/src/install.c index 67b2ab9..d91a561 100644 --- a/arm9/src/install.c +++ b/arm9/src/install.c @@ -112,12 +112,12 @@ static bool _checkSdSpace(unsigned long long size) return true; } -static bool _checkDsiSpace(unsigned long long size) +static bool _checkDsiSpace(unsigned long long size, bool systemApp) { iprintf("Enough room on DSi?..."); swiWaitForVBlank(); - if (getDsiFree() < size) + if ((systemApp ? getDsiRealFree() : getDsiFree()) < size) { iprintf("\x1B[31m"); //red iprintf("No\n"); @@ -397,24 +397,40 @@ bool install(char* fpath, bool systemTitle) goto error; } - if (!sdnandMode && - (h->tid_high == 0x00030005 || - h->tid_high == 0x00030015)) + //blacklisted titles { - iprintf("\x1B[31m"); //red - iprintf("Error: "); - iprintf("\x1B[33m"); //yellow - iprintf("This title cannot be\ninstalled to SysNAND.\n"); - iprintf("\x1B[47m"); //white - goto error; + //tid without region + u32 tidLow = (h->tid_low & 0xFFFFFF00); + if (!sdnandMode && ( + (h->tid_high == 0x00030005 && ( + tidLow == 0x484e4400 || // DS Download Play + tidLow == 0x484e4500 || // PictoChat + tidLow == 0x484e4900 || // Nintendo DSi Camera + tidLow == 0x484e4b00 // Nintendo DSi Sound + )) || (h->tid_high == 0x00030015 && ( + tidLow == 0x484e4200 || // System Settings + tidLow == 0x484e4600 // Nintendo DSi Shop + )))) + { + iprintf("\x1B[31m"); //red + iprintf("Error: "); + iprintf("\x1B[33m"); //yellow + iprintf("This title cannot be\ninstalled to SysNAND.\n"); + iprintf("\x1B[47m"); //white + goto error; + } } //confirmation message { - char str[] = "Are you sure you want to install\n"; - char* msg = (char*)malloc(strlen(str) + strlen(fpath) + 8); - sprintf(msg, "%s%s\n", str, fpath); - + const char system[] = "\x1B[41mWARNING:\x1B[47m This is a system app,\ninstalling it is potentially\nmore risky than regular DSiWare.\n\x1B[33m"; + const char areYouSure[] = "Are you sure you want to install\n"; + char* msg = (char*)malloc(strlen(system) + strlen(areYouSure) + strlen(fpath) + 2); + if(sdnandMode || h->tid_high == 0x00030004) + sprintf(msg, "%s%s?\n", areYouSure, fpath); + else + sprintf(msg, "%s%s%s?\n", system, areYouSure, fpath); + bool choice = choiceBox(msg); free(msg); @@ -475,20 +491,17 @@ bool install(char* fpath, bool systemTitle) fixHeader = true; } - //skip nand check if system title - if (h->tid_high != 0x00030015) + //check that there's space on nand + if (!_checkDsiSpace(installSize, (h->tid_high != 0x00030004))) { - if (!_checkDsiSpace(installSize)) + if (sdnandMode && choicePrint("Install as system title?")) { - if (sdnandMode && choicePrint("Install as system title?")) - { - h->tid_high = 0x00030015; - fixHeader = true; - } - else - { - goto error; - } + h->tid_high = 0x00030015; + fixHeader = true; + } + else + { + goto error; } } diff --git a/arm9/src/storage.c b/arm9/src/storage.c index 74ebbf3..7ca8467 100644 --- a/arm9/src/storage.c +++ b/arm9/src/storage.c @@ -533,6 +533,15 @@ unsigned long long getDsiFree() return size; } +unsigned long long getDsiRealFree() +{ + struct statvfs st; + if (statvfs(sdnandMode ? "sd:/" : "nand:/", &st) == 0) + return st.f_bsize * st.f_bavail; + + return 0; +} + u32 getDsiClusterSize() { struct statvfs st; diff --git a/arm9/src/storage.h b/arm9/src/storage.h index 4578b9a..d99a6d3 100644 --- a/arm9/src/storage.h +++ b/arm9/src/storage.h @@ -42,6 +42,7 @@ unsigned long long getSDCardFree(); //internal storage unsigned long long getDsiSize(); unsigned long long getDsiFree(); +unsigned long long getDsiRealFree(); u32 getDsiClusterSize(); #define getDsiUsed() (getDSIStorageSize() - getDSIStorageFree()) diff --git a/arm9/src/titlemenu.c b/arm9/src/titlemenu.c index c0e758d..63667bb 100644 --- a/arm9/src/titlemenu.c +++ b/arm9/src/titlemenu.c @@ -79,16 +79,12 @@ static void generateList(Menu* m) { if (!m) return; - const int NUM_OF_DIRS = sdnandMode ? 3 : 1; - const char* sdnandDirs[] = { + const int NUM_OF_DIRS = 3; + const char* dirs[] = { "00030004", "00030005", "00030015" }; - const char* nandDirs[] = { - "00030004" - }; - const char** dirs = sdnandMode ? sdnandDirs : nandDirs; //Reset menu clearMenu(m); @@ -115,6 +111,21 @@ static void generateList(Menu* m) if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0) continue; + //blacklisted titles + if (!sdnandMode && ( + (i == 1 && ( + strncmp(ent->d_name, "484e44", 6) == 0 || // DS Download Play + strncmp(ent->d_name, "484e45", 6) == 0 || // PictoChat + strncmp(ent->d_name, "484e49", 6) == 0 || // Nintendo DSi Camera + strncmp(ent->d_name, "484e4b", 6) == 0 // Nintendo DSi Sound + )) || (i == 2 && ( + strncmp(ent->d_name, "484e42", 6) == 0 || // System Settings + strncmp(ent->d_name, "484e46", 6) == 0 // Nintendo DSi Shop + )))) + { + continue; + } + if (ent->d_type == DT_DIR) { //scan content folder /title/XXXXXXXX/content