From 636e8ea34836b4110155c0b9dee49452ceaa59b4 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Fri, 29 Dec 2017 02:53:09 +0100 Subject: [PATCH] Allow updating the .sha file if it doesn't match fixes #285 --- arm9/source/godmode.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index 42d6b10..763e789 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -703,14 +703,16 @@ u32 Sha256Calculator(const char* path) { snprintf(sha_path, 256, "%s.sha", path); bool have_sha = (FileGetData(sha_path, sha256_file, 32, 0) == 32); - bool write_sha = !have_sha && (drvtype & DRV_SDCARD); // writing only on SD + bool match_sha = have_sha && (memcmp(sha256, sha256_file, 32) == 0); + bool match_prev = (memcmp(sha256, sha256_prev, 32) == 0); + bool write_sha = (!have_sha || (have_sha && !match_sha)) && (drvtype & DRV_SDCARD); // writing only on SD if (ShowPrompt(write_sha, "%s\n%016llX%016llX\n%016llX%016llX%s%s%s%s%s", pathstr, getbe64(sha256 + 0), getbe64(sha256 + 8), getbe64(sha256 + 16), getbe64(sha256 + 24), (have_sha) ? "\nSHA verification: " : "", - (have_sha) ? ((memcmp(sha256, sha256_file, 32) == 0) ? "passed!" : "failed!") : "", - (memcmp(sha256, sha256_prev, 32) == 0) ? "\n \nIdentical with previous file:\n" : "", - (memcmp(sha256, sha256_prev, 32) == 0) ? pathstr_prev : "", - (write_sha) ? "\n \nWrite .SHA file?" : "") && !have_sha && write_sha) { + (have_sha) ? ((match_sha) ? "passed!" : "failed!") : "", + (match_prev) ? "\n \nIdentical with previous file:\n" : "", + (match_prev) ? pathstr_prev : "", + (write_sha) ? "\n \nWrite .SHA file?" : "") && write_sha) { FileSetData(sha_path, sha256, 32, 0, true); }