From 580d98535b2be80d3a02c9020109b593c827d30c Mon Sep 17 00:00:00 2001 From: Pk11 Date: Sun, 9 Jan 2022 20:29:51 -0600 Subject: [PATCH] Minor code cleanup --- arm9/src/backupmenu.c | 4 ++-- arm9/src/install.c | 10 +++++----- arm9/src/main.c | 8 +++++--- arm9/src/message.c | 14 +++++++++----- arm9/src/nand/nandio.c | 9 +++++---- arm9/src/storage.c | 6 +++--- arm9/src/titlemenu.c | 4 ++-- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/arm9/src/backupmenu.c b/arm9/src/backupmenu.c index 9fc4704..0161573 100644 --- a/arm9/src/backupmenu.c +++ b/arm9/src/backupmenu.c @@ -191,7 +191,7 @@ static void restore(Menu* m) } else { - if(!sdnandMode && !nandio_unlock_writing()) + if (!sdnandMode && !nandio_unlock_writing()) return; clearScreen(&bottomScreen); @@ -205,7 +205,7 @@ static void restore(Menu* m) messagePrint("\x1B[42m\nBackup restored.\n\x1B[47m"); } - if(!sdnandMode) + if (!sdnandMode) nandio_lock_writing(); } } diff --git a/arm9/src/install.c b/arm9/src/install.c index df9da17..1973981 100644 --- a/arm9/src/install.c +++ b/arm9/src/install.c @@ -347,8 +347,8 @@ bool install(char* fpath, bool systemTitle) goto error; } - if(!sdnandMode && !nandio_unlock_writing()) - return false; + if (!sdnandMode && !nandio_unlock_writing()) + return false; clearScreen(&bottomScreen); iprintf("Installing %s\n\n", fpath); swiWaitForVBlank(); @@ -491,10 +491,10 @@ bool install(char* fpath, bool systemTitle) mkdir(contentPath, 0777); u8 appVersion = 0; - if(tmdFound) + if (tmdFound) { FILE *file = fopen(tmdPath, "rb"); - if(file) + if (file) { fseek(file, 0x1E7, SEEK_SET); fread(&appVersion, sizeof(appVersion), 1, file); @@ -669,7 +669,7 @@ error: complete: free(h); - if(!sdnandMode) + if (!sdnandMode) nandio_lock_writing(); return result; diff --git a/arm9/src/main.c b/arm9/src/main.c index 486c8c5..920b011 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -91,8 +91,9 @@ static int _mainMenu(int cursor) return result; } -void fifoHandler(u32 value32, void* userdata) { - if(value32 == 0x54495845) // 'EXIT' +void fifoHandler(u32 value32, void* userdata) +{ + if (value32 == 0x54495845) // 'EXIT' programEnd = true; } @@ -157,7 +158,8 @@ int main(int argc, char **argv) break; case MAIN_MENU_FIX: - if(nandio_unlock_writing()) { + if (nandio_unlock_writing()) + { nandio_force_fat_fix(); nandio_lock_writing(); messageBox("Mismatch in FAT copies will be\nfixed on close.\n"); diff --git a/arm9/src/message.c b/arm9/src/message.c index 78b962b..34a14a0 100644 --- a/arm9/src/message.c +++ b/arm9/src/message.c @@ -93,7 +93,8 @@ bool randomConfirmBox(char* message) int sequencePosition = 0; 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])); } @@ -111,19 +112,22 @@ bool randomConfirmBox(char* message) //Print sequence 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("%s ", keysLabels[sequence[i]]); } - 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() & (KEY_UP | KEY_DOWN | KEY_RIGHT | KEY_LEFT | KEY_A | KEY_B | KEY_X | KEY_Y)) + { + if (keysDown() & keys[sequence[sequencePosition]]) sequencePosition++; else sequencePosition = 0; } - if (keysDown() & KEY_START) { + if (keysDown() & KEY_START) + { sequencePosition = 0; break; } diff --git a/arm9/src/nand/nandio.c b/arm9/src/nand/nandio.c index 76eb6df..a9d997a 100644 --- a/arm9/src/nand/nandio.c +++ b/arm9/src/nand/nandio.c @@ -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) { - if(writingLocked) + if (writingLocked) return false; nandWritten = true; @@ -202,7 +202,8 @@ bool nandio_clear_status() bool nandio_shutdown() { - if(nandWritten) { + if (nandWritten) + { // at cleanup we synchronize the FAT statgings // A FatFS might have multiple copies of the FAT. // 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() { - 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; return !writingLocked; @@ -257,7 +258,7 @@ bool nandio_unlock_writing() bool nandio_force_fat_fix() { - if(!writingLocked) + if (!writingLocked) nandWritten = true; return true; diff --git a/arm9/src/storage.c b/arm9/src/storage.c index 6444a5d..abcd219 100644 --- a/arm9/src/storage.c +++ b/arm9/src/storage.c @@ -258,7 +258,7 @@ bool copyDir(char const* src, char const* dst) int ret = copyFile(fsrc, fdst); - if(ret != 0) + if (ret != 0) { iprintf("\x1B[31m"); //red iprintf("Fail\n"); @@ -396,7 +396,7 @@ unsigned long long getDirSize(const char* path) { 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; if (ent->d_type == DT_DIR) @@ -455,7 +455,7 @@ int getMenuSlotsFree() { 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; if (ent->d_type == DT_DIR) diff --git a/arm9/src/titlemenu.c b/arm9/src/titlemenu.c index 93122c4..efc97b4 100644 --- a/arm9/src/titlemenu.c +++ b/arm9/src/titlemenu.c @@ -361,7 +361,7 @@ static bool delete(Menu* m) } else { - if(!sdnandMode && !nandio_unlock_writing()) + if (!sdnandMode && !nandio_unlock_writing()) return false; clearScreen(&bottomScreen); @@ -376,7 +376,7 @@ static bool delete(Menu* m) messagePrint("\nTitle could not be deleted.\n"); } - if(!sdnandMode) + if (!sdnandMode) nandio_lock_writing(); } }