Cleanup conditionals

This commit is contained in:
Edoardo Lolletti 2024-04-28 13:35:50 +02:00
parent 03f1df6f8e
commit 06d374d28b

View File

@ -143,6 +143,7 @@ static int mainMenu(int cursor)
if (konamiCode == 5) if (konamiCode == 5)
{ {
advancedOptionsUnlocked = true; advancedOptionsUnlocked = true;
addMenuItem(m, tidPatchesStr, NULL, foundUnlaunchInstallerVersion == v1_9 || foundUnlaunchInstallerVersion == v2_0, false);
addMenuItem(m, "Uninstall unlaunch no backup", NULL, unlaunchFound, false); addMenuItem(m, "Uninstall unlaunch no backup", NULL, unlaunchFound, false);
addMenuItem(m, "Write nocash footer", NULL, needsNocashFooterToBeWritten, false); addMenuItem(m, "Write nocash footer", NULL, needsNocashFooterToBeWritten, false);
} }
@ -318,45 +319,58 @@ int main(int argc, char **argv)
{ {
case MAIN_MENU_SAFE_UNLAUNCH_UNINSTALL: case MAIN_MENU_SAFE_UNLAUNCH_UNINSTALL:
case MAIN_MENU_SAFE_UNLAUNCH_UNINSTALL_NO_BACKUP: case MAIN_MENU_SAFE_UNLAUNCH_UNINSTALL_NO_BACKUP:
if(unlaunchFound && nandio_unlock_writing()) { if(!unlaunchFound)
bool unsafeUninstall = advancedOptionsUnlocked && cursor == MAIN_MENU_SAFE_UNLAUNCH_UNINSTALL_NO_BACKUP; {
printf("Uninstalling"); break;
if(needsNocashFooterToBeWritten)
{
printf("Writing nocash footer\n");
if(!nandio_write_nocash_footer(&computedNocashFooter))
{
messageBox("Failed to write nocash footer");
break;
}
needsNocashFooterToBeWritten = false;
}
if(uninstallUnlaunch(retailConsole, hnaaUnlaunchFound, retailLauncherTmdPath, unsafeUninstall))
{
messageBox("Uninstall successful!\n");
unlaunchFound = false;
} else {
messageBox("\x1B[31mError:\x1B[33m Uninstall failed\n");
}
nandio_lock_writing();
printf("Synchronizing FAT tables...\n");
nandio_synchronize_fats();
} }
if(!nandio_unlock_writing())
{
break;
}
bool unsafeUninstall = advancedOptionsUnlocked && cursor == MAIN_MENU_SAFE_UNLAUNCH_UNINSTALL_NO_BACKUP;
printf("Uninstalling");
if(needsNocashFooterToBeWritten)
{
printf("Writing nocash footer\n");
if(!nandio_write_nocash_footer(&computedNocashFooter))
{
nandio_lock_writing();
messageBox("Failed to write nocash footer");
break;
}
needsNocashFooterToBeWritten = false;
}
if(uninstallUnlaunch(retailConsole, hnaaUnlaunchFound, retailLauncherTmdPath, unsafeUninstall))
{
messageBox("Uninstall successful!\n");
unlaunchFound = false;
}
else
{
messageBox("\x1B[31mError:\x1B[33m Uninstall failed\n");
}
nandio_lock_writing();
printf("Synchronizing FAT tables...\n");
nandio_synchronize_fats();
break; break;
case MAIN_MENU_CUSTOM_BG: case MAIN_MENU_CUSTOM_BG:
if(foundUnlaunchInstallerVersion != INVALID) { if(foundUnlaunchInstallerVersion == INVALID)
const char* customBg = backgroundMenu(); {
if(!customBg) break;
break; }
if(strcmp(customBg, "default") == 0) const char* customBg = backgroundMenu();
{ if(!customBg)
customBgPath = NULL; {
} break;
else }
{ if(strcmp(customBg, "default") == 0)
customBgPath = customBg; {
} customBgPath = NULL;
}
else
{
customBgPath = customBg;
} }
break; break;
@ -373,48 +387,66 @@ int main(int argc, char **argv)
break; break;
case MAIN_MENU_SAFE_UNLAUNCH_INSTALL: case MAIN_MENU_SAFE_UNLAUNCH_INSTALL:
if (!unlaunchFound && foundUnlaunchInstallerVersion != INVALID && (choiceBox("Install unlaunch?") == YES) if(unlaunchFound || foundUnlaunchInstallerVersion == INVALID)
&& (retailLauncherTmdPresentAndToBePatched || (choiceBox("There doesn't seem to be a launcher.tmd\nfile matcing the hwinfo file\nKeep installing?") == YES))
&& nandio_unlock_writing())
{ {
printf("Installing\n"); break;
if(needsNocashFooterToBeWritten)
{
printf("Writing nocash footer\n");
if(!nandio_write_nocash_footer(&computedNocashFooter))
{
messageBox("Failed to write nocash footer");
break;
}
needsNocashFooterToBeWritten = false;
}
if(installUnlaunch(retailConsole,
retailLauncherTmdPresentAndToBePatched ? retailLauncherTmdPath : NULL,
disableAllPatches,
enableSoundAndSplash ? splashSoundBinaryPatchPath : NULL,
customBgPath))
{
messageBox("Install successful!\n");
unlaunchFound = true;
} else {
messageBox("\x1B[31mError:\x1B[33m Install failed\n");
}
nandio_lock_writing();
printf("Synchronizing FAT tables...\n");
nandio_synchronize_fats();
} }
break; if(choiceBox("Install unlaunch?") == NO)
{
case MAIN_MENU_WRITE_NOCASH_FOOTER_ONLY: break;
}
if(!retailLauncherTmdPresentAndToBePatched
&& (choiceBox("There doesn't seem to be a launcher.tmd\n"
"file matcing the hwinfo file\n"
"Keep installing?") == NO))
{
break;
}
if(!nandio_unlock_writing())
{
break;
}
printf("Installing\n");
if(needsNocashFooterToBeWritten) if(needsNocashFooterToBeWritten)
{ {
printf("Writing nocash footer\n");
if(!nandio_write_nocash_footer(&computedNocashFooter)) if(!nandio_write_nocash_footer(&computedNocashFooter))
{ {
nandio_lock_writing();
messageBox("Failed to write nocash footer"); messageBox("Failed to write nocash footer");
break; break;
} }
needsNocashFooterToBeWritten = false; needsNocashFooterToBeWritten = false;
} }
if(installUnlaunch(retailConsole,
retailLauncherTmdPresentAndToBePatched ? retailLauncherTmdPath : NULL,
disableAllPatches,
enableSoundAndSplash ? splashSoundBinaryPatchPath : NULL,
customBgPath))
{
messageBox("Install successful!\n");
unlaunchFound = true;
}
else
{
messageBox("\x1B[31mError:\x1B[33m Install failed\n");
}
nandio_lock_writing();
printf("Synchronizing FAT tables...\n");
nandio_synchronize_fats();
break;
case MAIN_MENU_WRITE_NOCASH_FOOTER_ONLY:
if(!needsNocashFooterToBeWritten)
{
break;
}
if(!nandio_write_nocash_footer(&computedNocashFooter))
{
messageBox("Failed to write nocash footer");
break;
}
needsNocashFooterToBeWritten = false;
break; break;
case MAIN_MENU_EXIT: case MAIN_MENU_EXIT: