Fix: Backing up NAND from home menu

This commit is contained in:
d0k3 2017-02-28 17:58:48 +01:00
parent 35c87abf10
commit 5c566ced14
3 changed files with 24 additions and 4 deletions

View File

@ -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

View File

@ -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';
@ -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';

View File

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