Allow updating the .sha file if it doesn't match

fixes #285
This commit is contained in:
d0k3 2017-12-29 02:53:09 +01:00
parent 24f93a24c4
commit 636e8ea348

View File

@ -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);
}