Allow (un)installing non-preinstalled system apps

This commit is contained in:
Pk11 2022-01-14 20:42:01 -06:00
parent cfbbd949d8
commit af3408a8aa
4 changed files with 67 additions and 33 deletions

View File

@ -112,12 +112,12 @@ static bool _checkSdSpace(unsigned long long size)
return true; return true;
} }
static bool _checkDsiSpace(unsigned long long size) static bool _checkDsiSpace(unsigned long long size, bool systemApp)
{ {
iprintf("Enough room on DSi?..."); iprintf("Enough room on DSi?...");
swiWaitForVBlank(); swiWaitForVBlank();
if (getDsiFree() < size) if ((systemApp ? getDsiRealFree() : getDsiFree()) < size)
{ {
iprintf("\x1B[31m"); //red iprintf("\x1B[31m"); //red
iprintf("No\n"); iprintf("No\n");
@ -397,24 +397,40 @@ bool install(char* fpath, bool systemTitle)
goto error; goto error;
} }
if (!sdnandMode && //blacklisted titles
(h->tid_high == 0x00030005 ||
h->tid_high == 0x00030015))
{ {
iprintf("\x1B[31m"); //red //tid without region
iprintf("Error: "); u32 tidLow = (h->tid_low & 0xFFFFFF00);
iprintf("\x1B[33m"); //yellow if (!sdnandMode && (
iprintf("This title cannot be\ninstalled to SysNAND.\n"); (h->tid_high == 0x00030005 && (
iprintf("\x1B[47m"); //white tidLow == 0x484e4400 || // DS Download Play
goto error; 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 //confirmation message
{ {
char str[] = "Are you sure you want to install\n"; const char system[] = "\x1B[41mWARNING:\x1B[47m This is a system app,\ninstalling it is potentially\nmore risky than regular DSiWare.\n\x1B[33m";
char* msg = (char*)malloc(strlen(str) + strlen(fpath) + 8); const char areYouSure[] = "Are you sure you want to install\n";
sprintf(msg, "%s%s\n", str, fpath); 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); bool choice = choiceBox(msg);
free(msg); free(msg);
@ -475,20 +491,17 @@ bool install(char* fpath, bool systemTitle)
fixHeader = true; fixHeader = true;
} }
//skip nand check if system title //check that there's space on nand
if (h->tid_high != 0x00030015) 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;
h->tid_high = 0x00030015; }
fixHeader = true; else
} {
else goto error;
{
goto error;
}
} }
} }

View File

@ -533,6 +533,15 @@ unsigned long long getDsiFree()
return size; 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() u32 getDsiClusterSize()
{ {
struct statvfs st; struct statvfs st;

View File

@ -42,6 +42,7 @@ unsigned long long getSDCardFree();
//internal storage //internal storage
unsigned long long getDsiSize(); unsigned long long getDsiSize();
unsigned long long getDsiFree(); unsigned long long getDsiFree();
unsigned long long getDsiRealFree();
u32 getDsiClusterSize(); u32 getDsiClusterSize();
#define getDsiUsed() (getDSIStorageSize() - getDSIStorageFree()) #define getDsiUsed() (getDSIStorageSize() - getDSIStorageFree())

View File

@ -79,16 +79,12 @@ static void generateList(Menu* m)
{ {
if (!m) return; if (!m) return;
const int NUM_OF_DIRS = sdnandMode ? 3 : 1; const int NUM_OF_DIRS = 3;
const char* sdnandDirs[] = { const char* dirs[] = {
"00030004", "00030004",
"00030005", "00030005",
"00030015" "00030015"
}; };
const char* nandDirs[] = {
"00030004"
};
const char** dirs = sdnandMode ? sdnandDirs : nandDirs;
//Reset menu //Reset menu
clearMenu(m); clearMenu(m);
@ -115,6 +111,21 @@ static void generateList(Menu* m)
if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0) if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0)
continue; 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) if (ent->d_type == DT_DIR)
{ {
//scan content folder /title/XXXXXXXX/content //scan content folder /title/XXXXXXXX/content