diff --git a/source/common/common.h b/source/common/common.h index 9e5d583..56b73b7 100644 --- a/source/common/common.h +++ b/source/common/common.h @@ -48,7 +48,7 @@ #endif // GodMode9 version -#define VERSION "1.0.2" +#define VERSION "1.0.3" // Maximum payload size (arbitrary value!) #define SELF_MAX_SIZE (320 * 1024) // 320kB diff --git a/source/fs/fsutil.c b/source/fs/fsutil.c index a17606b..b515913 100644 --- a/source/fs/fsutil.c +++ b/source/fs/fsutil.c @@ -575,6 +575,7 @@ bool PathCopyVrtToFat(char* dest, char* orig, u32* flags) { f_sync(&dfile); ret = true; + if (flags && (*flags & CALC_SHA)) sha_init(SHA256_MODE); for (u64 pos = 0; (pos < osize) && ret; pos += MAIN_BUFFER_SIZE) { UINT read_bytes = min(MAIN_BUFFER_SIZE, osize - pos); UINT bytes_written = 0; @@ -586,11 +587,20 @@ bool PathCopyVrtToFat(char* dest, char* orig, u32* flags) { ret = false; if (read_bytes != bytes_written) ret = false; + if (flags && (*flags & CALC_SHA)) + sha_update(MAIN_BUFFER, read_bytes); } ShowProgress(1, 1, orig); fx_close(&dfile); if (!ret) f_unlink(dest); + else if (flags && (*flags & CALC_SHA)) { + u8 sha256[0x20]; + char* ext_sha = dest + strnlen(dest, 256); + strncpy(ext_sha, ".sha", 256 - (ext_sha - dest)); + sha_get(sha256); + FileSetData(dest, sha256, 0x20, 0, true); + } } *(--dname) = '\0'; @@ -600,7 +610,7 @@ bool PathCopyVrtToFat(char* dest, char* orig, u32* flags) { bool PathCopyWorker(char* dest, char* orig, u32* flags, bool move) { FILINFO fno; bool ret = false; - + if (fa_stat(dest, &fno) != FR_OK) { // is root or destination does not exist DIR tmp_dir; // check if root if (fa_opendir(&tmp_dir, dest) != FR_OK) return false; @@ -738,6 +748,7 @@ bool PathCopyWorker(char* dest, char* orig, u32* flags, bool move) { f_sync(&ofile); ret = true; + if (flags && (*flags & CALC_SHA)) sha_init(SHA256_MODE); for (u64 pos = 0; (pos < fsize) && ret; pos += MAIN_BUFFER_SIZE) { UINT bytes_read = 0; UINT bytes_written = 0; @@ -749,12 +760,21 @@ bool PathCopyWorker(char* dest, char* orig, u32* flags, bool move) { ret = false; if (bytes_read != bytes_written) ret = false; + if (flags && (*flags & CALC_SHA)) + sha_update(MAIN_BUFFER, bytes_read); } ShowProgress(1, 1, orig); fx_close(&ofile); fx_close(&dfile); if (!ret) f_unlink(dest); + else if (flags && (*flags & CALC_SHA)) { + u8 sha256[0x20]; + char* ext_sha = dest + strnlen(dest, 256); + strncpy(ext_sha, ".sha", 256 - (ext_sha - dest)); + sha_get(sha256); + FileSetData(dest, sha256, 0x20, 0, true); + } } *(--dname) = '\0'; diff --git a/source/godmode.c b/source/godmode.c index d4d44e2..ed47ec1 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -1099,9 +1099,9 @@ u32 HomeMoreMenu(char* current_path, DirStruct* current_dir, DirStruct* clipboar if (emu > 0) optionstr[emu - 1] = "Backup EmuNAND"; user_select = (n_opt > 1) ? ShowSelectPrompt(n_opt, optionstr, promptstr) : n_opt; if (user_select > 0) { - u32 flags = CALC_SHA; + u32 flags = BUILD_PATH | CALC_SHA; ShowPrompt(false, "NAND backup: %s", - (PathCopy(OUTPUT_PATH, (user_select == sys) ? "1:/nand_min.bin" : "4:/nand_min.bin", &flags)) ? + (PathCopy(OUTPUT_PATH, (user_select == sys) ? "S:/nand.bin" : "E:/nand.bin", &flags)) ? "success" : "failed"); GetDirContents(current_dir, current_path); return 0;