Minor code cleanup

This commit is contained in:
Pk11 2022-01-09 20:29:51 -06:00
parent 643bc4143c
commit 580d98535b
7 changed files with 31 additions and 24 deletions

View File

@ -191,7 +191,7 @@ static void restore(Menu* m)
} }
else else
{ {
if(!sdnandMode && !nandio_unlock_writing()) if (!sdnandMode && !nandio_unlock_writing())
return; return;
clearScreen(&bottomScreen); clearScreen(&bottomScreen);
@ -205,7 +205,7 @@ static void restore(Menu* m)
messagePrint("\x1B[42m\nBackup restored.\n\x1B[47m"); messagePrint("\x1B[42m\nBackup restored.\n\x1B[47m");
} }
if(!sdnandMode) if (!sdnandMode)
nandio_lock_writing(); nandio_lock_writing();
} }
} }

View File

@ -347,8 +347,8 @@ bool install(char* fpath, bool systemTitle)
goto error; goto error;
} }
if(!sdnandMode && !nandio_unlock_writing()) if (!sdnandMode && !nandio_unlock_writing())
return false; return false;
clearScreen(&bottomScreen); clearScreen(&bottomScreen);
iprintf("Installing %s\n\n", fpath); swiWaitForVBlank(); iprintf("Installing %s\n\n", fpath); swiWaitForVBlank();
@ -491,10 +491,10 @@ bool install(char* fpath, bool systemTitle)
mkdir(contentPath, 0777); mkdir(contentPath, 0777);
u8 appVersion = 0; u8 appVersion = 0;
if(tmdFound) if (tmdFound)
{ {
FILE *file = fopen(tmdPath, "rb"); FILE *file = fopen(tmdPath, "rb");
if(file) if (file)
{ {
fseek(file, 0x1E7, SEEK_SET); fseek(file, 0x1E7, SEEK_SET);
fread(&appVersion, sizeof(appVersion), 1, file); fread(&appVersion, sizeof(appVersion), 1, file);
@ -669,7 +669,7 @@ error:
complete: complete:
free(h); free(h);
if(!sdnandMode) if (!sdnandMode)
nandio_lock_writing(); nandio_lock_writing();
return result; return result;

View File

@ -91,8 +91,9 @@ static int _mainMenu(int cursor)
return result; return result;
} }
void fifoHandler(u32 value32, void* userdata) { void fifoHandler(u32 value32, void* userdata)
if(value32 == 0x54495845) // 'EXIT' {
if (value32 == 0x54495845) // 'EXIT'
programEnd = true; programEnd = true;
} }
@ -157,7 +158,8 @@ int main(int argc, char **argv)
break; break;
case MAIN_MENU_FIX: case MAIN_MENU_FIX:
if(nandio_unlock_writing()) { if (nandio_unlock_writing())
{
nandio_force_fat_fix(); nandio_force_fat_fix();
nandio_lock_writing(); nandio_lock_writing();
messageBox("Mismatch in FAT copies will be\nfixed on close.\n"); messageBox("Mismatch in FAT copies will be\nfixed on close.\n");

View File

@ -93,7 +93,8 @@ bool randomConfirmBox(char* message)
int sequencePosition = 0; int sequencePosition = 0;
u8 sequence[8]; u8 sequence[8];
for(int i = 0; i < sizeof(sequence); i++) { for (int i = 0; i < sizeof(sequence); i++)
{
sequence[i] = rand() % (sizeof(keys) / sizeof(keys[0])); sequence[i] = rand() % (sizeof(keys) / sizeof(keys[0]));
} }
@ -111,19 +112,22 @@ bool randomConfirmBox(char* message)
//Print sequence //Print sequence
iprintf("\x1b[%d;0H", choiceRow); iprintf("\x1b[%d;0H", choiceRow);
for(int i = 0; i < sizeof(sequence); i++) { for (int i = 0; i < sizeof(sequence); i++)
{
iprintf("\x1B[%0om", i < sequencePosition ? 032 : 047); iprintf("\x1B[%0om", i < sequencePosition ? 032 : 047);
iprintf("%s ", keysLabels[sequence[i]]); iprintf("%s ", keysLabels[sequence[i]]);
} }
if (keysDown() & (KEY_UP | KEY_DOWN | KEY_RIGHT | KEY_LEFT | KEY_A | KEY_B | KEY_X | KEY_Y)) { if (keysDown() & (KEY_UP | KEY_DOWN | KEY_RIGHT | KEY_LEFT | KEY_A | KEY_B | KEY_X | KEY_Y))
if(keysDown() & keys[sequence[sequencePosition]]) {
if (keysDown() & keys[sequence[sequencePosition]])
sequencePosition++; sequencePosition++;
else else
sequencePosition = 0; sequencePosition = 0;
} }
if (keysDown() & KEY_START) { if (keysDown() & KEY_START)
{
sequencePosition = 0; sequencePosition = 0;
break; break;
} }

View File

@ -171,7 +171,7 @@ bool nandio_read_sectors(sec_t offset, sec_t len, void *buffer)
bool nandio_write_sectors(sec_t offset, sec_t len, const void *buffer) bool nandio_write_sectors(sec_t offset, sec_t len, const void *buffer)
{ {
if(writingLocked) if (writingLocked)
return false; return false;
nandWritten = true; nandWritten = true;
@ -202,7 +202,8 @@ bool nandio_clear_status()
bool nandio_shutdown() bool nandio_shutdown()
{ {
if(nandWritten) { if (nandWritten)
{
// at cleanup we synchronize the FAT statgings // at cleanup we synchronize the FAT statgings
// A FatFS might have multiple copies of the FAT. // A FatFS might have multiple copies of the FAT.
// we will get them back synchonized as we just worked on the first copy // we will get them back synchonized as we just worked on the first copy
@ -249,7 +250,7 @@ bool nandio_lock_writing()
bool nandio_unlock_writing() bool nandio_unlock_writing()
{ {
if(writingLocked && randomConfirmBox("Writing to NAND is locked!\nIf you're sure you understand\nthe risk, input the sequence\nbelow.")) if (writingLocked && randomConfirmBox("Writing to NAND is locked!\nIf you're sure you understand\nthe risk, input the sequence\nbelow."))
writingLocked = false; writingLocked = false;
return !writingLocked; return !writingLocked;
@ -257,7 +258,7 @@ bool nandio_unlock_writing()
bool nandio_force_fat_fix() bool nandio_force_fat_fix()
{ {
if(!writingLocked) if (!writingLocked)
nandWritten = true; nandWritten = true;
return true; return true;

View File

@ -258,7 +258,7 @@ bool copyDir(char const* src, char const* dst)
int ret = copyFile(fsrc, fdst); int ret = copyFile(fsrc, fdst);
if(ret != 0) if (ret != 0)
{ {
iprintf("\x1B[31m"); //red iprintf("\x1B[31m"); //red
iprintf("Fail\n"); iprintf("Fail\n");
@ -396,7 +396,7 @@ unsigned long long getDirSize(const char* path)
{ {
while ((ent = readdir(dir))) while ((ent = readdir(dir)))
{ {
if(strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0) if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0)
continue; continue;
if (ent->d_type == DT_DIR) if (ent->d_type == DT_DIR)
@ -455,7 +455,7 @@ int getMenuSlotsFree()
{ {
while ( (ent = readdir(dir)) != NULL ) while ( (ent = readdir(dir)) != NULL )
{ {
if(strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0) if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0)
continue; continue;
if (ent->d_type == DT_DIR) if (ent->d_type == DT_DIR)

View File

@ -361,7 +361,7 @@ static bool delete(Menu* m)
} }
else else
{ {
if(!sdnandMode && !nandio_unlock_writing()) if (!sdnandMode && !nandio_unlock_writing())
return false; return false;
clearScreen(&bottomScreen); clearScreen(&bottomScreen);
@ -376,7 +376,7 @@ static bool delete(Menu* m)
messagePrint("\nTitle could not be deleted.\n"); messagePrint("\nTitle could not be deleted.\n");
} }
if(!sdnandMode) if (!sdnandMode)
nandio_lock_writing(); nandio_lock_writing();
} }
} }