Improved SD format dialogue

This commit is contained in:
d0k3 2017-02-22 23:27:34 +01:00
parent 0d5638c3a6
commit 29d8ac186f
3 changed files with 26 additions and 16 deletions

View File

@ -11,8 +11,8 @@
#include "ff.h" #include "ff.h"
#include "ui.h" #include "ui.h"
#define SKIP_CUR (1UL<<3) #define SKIP_CUR (1UL<<4)
#define OVERWRITE_CUR (1UL<<4) #define OVERWRITE_CUR (1UL<<5)
// Volume2Partition resolution table // Volume2Partition resolution table
PARTITION VolToPart[] = { PARTITION VolToPart[] = {
@ -57,7 +57,8 @@ bool FormatSDCard(u64 hidden_mb, u32 cluster_size, const char* label) {
else memset(mbr + 0x1CE, 0, 0x10); else memset(mbr + 0x1CE, 0, 0x10);
// one last warning.... // one last warning....
if (!ShowUnlockSequence(6, "!WARNING!\n \nProceeding will format this SD.\nThis will irreversibly delete\nALL data on it.")) // 0:/Nintendo 3DS/ write permission is ignored here, this warning is enough
if (!ShowUnlockSequence(5, "!WARNING!\n \nProceeding will format this SD.\nThis will irreversibly delete\nALL data on it."))
return false; return false;
ShowString("Formatting SD, please wait..."); ShowString("Formatting SD, please wait...");
@ -258,7 +259,7 @@ bool FileInjectFile(const char* dest, const char* orig, u32 offset) {
return ret; return ret;
} }
bool PathCopyVrtToVrt(const char* destdir, const char* orig) { bool PathCopyVrtToVrt(const char* destdir, const char* orig, u32* flags) {
VirtualFile dvfile; VirtualFile dvfile;
VirtualFile ovfile; VirtualFile ovfile;
bool ret = true; bool ret = true;
@ -287,7 +288,8 @@ bool PathCopyVrtToVrt(const char* destdir, const char* orig) {
dvfile.keyslot = ovfile.keyslot = 0xFF; // this improves copy times for virtual NAND dvfile.keyslot = ovfile.keyslot = 0xFF; // this improves copy times for virtual NAND
// check write permissions // check write permissions
if (!CheckWritePermissions(dest)) return false; if ((!flags || !(*flags & OVERRIDE_PERM)) && !CheckWritePermissions(destdir))
return false;
// unmount critical NAND drives // unmount critical NAND drives
DismountDriveType(DriveType(destdir)&(DRV_SYSNAND|DRV_EMUNAND|DRV_IMAGE)); DismountDriveType(DriveType(destdir)&(DRV_SYSNAND|DRV_EMUNAND|DRV_IMAGE));
@ -307,7 +309,7 @@ bool PathCopyVrtToVrt(const char* destdir, const char* orig) {
return ret; return ret;
} }
bool PathCopyFatToVrt(const char* destdir, const char* orig) { bool PathCopyFatToVrt(const char* destdir, const char* orig, u32* flags) {
VirtualFile dvfile; VirtualFile dvfile;
FIL ofile; FIL ofile;
bool ret = true; bool ret = true;
@ -354,7 +356,8 @@ bool PathCopyFatToVrt(const char* destdir, const char* orig) {
} }
// check write permissions // check write permissions
if (!CheckWritePermissions(dest)) return false; if ((!flags || !(*flags & OVERRIDE_PERM)) && !CheckWritePermissions(destdir))
return false;
// FAT file // FAT file
if ((fx_open(&ofile, orig, FA_READ | FA_OPEN_EXISTING) != FR_OK) && if ((fx_open(&ofile, orig, FA_READ | FA_OPEN_EXISTING) != FR_OK) &&
@ -441,6 +444,7 @@ bool PathCopyVrtToFat(char* dest, char* orig, u32* flags) {
// check destination write permission (special paths only) // check destination write permission (special paths only)
if (((*dest == '1') || (strncmp(dest, "0:/Nintendo 3DS", 16) == 0)) && if (((*dest == '1') || (strncmp(dest, "0:/Nintendo 3DS", 16) == 0)) &&
(!flags || (*flags & (OVERWRITE_CUR|OVERWRITE_ALL))) && (!flags || (*flags & (OVERWRITE_CUR|OVERWRITE_ALL))) &&
(!flags || !(*flags & OVERRIDE_PERM)) &&
!CheckWritePermissions(dest)) return false; !CheckWritePermissions(dest)) return false;
// the copy process takes place here // the copy process takes place here
@ -577,6 +581,7 @@ bool PathCopyWorker(char* dest, char* orig, u32* flags, bool move) {
// check destination write permission (special paths only) // check destination write permission (special paths only)
if (((*dest == '1') || (strncmp(dest, "0:/Nintendo 3DS", 16) == 0)) && if (((*dest == '1') || (strncmp(dest, "0:/Nintendo 3DS", 16) == 0)) &&
(!flags || (*flags & (OVERWRITE_CUR|OVERWRITE_ALL))) && (!flags || (*flags & (OVERWRITE_CUR|OVERWRITE_ALL))) &&
(!flags || !(*flags & OVERRIDE_PERM)) &&
!CheckWritePermissions(dest)) return false; !CheckWritePermissions(dest)) return false;
// the copy process takes place here // the copy process takes place here
@ -675,7 +680,8 @@ bool PathCopyWorker(char* dest, char* orig, u32* flags, bool move) {
} }
bool PathCopy(const char* destdir, const char* orig, u32* flags) { bool PathCopy(const char* destdir, const char* orig, u32* flags) {
if (!CheckWritePermissions(destdir)) return false; if ((!flags || !(*flags & OVERRIDE_PERM)) && !CheckWritePermissions(destdir))
return false;
if (flags) *flags = *flags & ~(SKIP_CUR|OVERWRITE_CUR); // reset local flags if (flags) *flags = *flags & ~(SKIP_CUR|OVERWRITE_CUR); // reset local flags
int ddrvtype = DriveType(destdir); int ddrvtype = DriveType(destdir);
int odrvtype = DriveType(orig); int odrvtype = DriveType(orig);
@ -692,13 +698,15 @@ bool PathCopy(const char* destdir, const char* orig, u32* flags) {
ShowPrompt(false, "Copy operation is not allowed"); ShowPrompt(false, "Copy operation is not allowed");
return false; // prevent illegal operations return false; // prevent illegal operations
} }
return PathCopyFatToVrt(destdir, orig); return PathCopyFatToVrt(destdir, orig, flags);
} else return PathCopyVrtToVrt(destdir, orig); // virtual to virtual } else return PathCopyVrtToVrt(destdir, orig, flags); // virtual to virtual
} }
bool PathMove(const char* destdir, const char* orig, u32* flags) { bool PathMove(const char* destdir, const char* orig, u32* flags) {
if (!CheckWritePermissions(destdir)) return false; if (!flags || !(*flags & OVERRIDE_PERM)) {
if (!CheckDirWritePermissions(orig)) return false; // check orig FULL DIR permissions if (!CheckWritePermissions(destdir)) return false;
if (!CheckDirWritePermissions(orig)) return false;
}
if (flags) *flags = *flags & ~(SKIP_CUR|OVERWRITE_CUR); // reset local flags if (flags) *flags = *flags & ~(SKIP_CUR|OVERWRITE_CUR); // reset local flags
// moving only for regular FAT drives (= not alias drives) // moving only for regular FAT drives (= not alias drives)
if (!(DriveType(destdir) & DriveType(orig) & DRV_STDFAT)) { if (!(DriveType(destdir) & DriveType(orig) & DRV_STDFAT)) {

View File

@ -7,9 +7,10 @@
// #include "fsperm.h" // #include "fsperm.h"
// move / copy flags // move / copy flags
#define ASK_ALL (1UL<<0) #define OVERRIDE_PERM (1UL<<0)
#define SKIP_ALL (1UL<<1) #define ASK_ALL (1UL<<1)
#define OVERWRITE_ALL (1UL<<2) #define SKIP_ALL (1UL<<2)
#define OVERWRITE_ALL (1UL<<3)
/** Return total size of SD card **/ /** Return total size of SD card **/
uint64_t GetSDCardSize(); uint64_t GetSDCardSize();

View File

@ -250,7 +250,8 @@ u32 SdFormatMenu(void) {
return 0; return 0;
InitSDCardFS(); // this has to be initialized for EmuNAND to work InitSDCardFS(); // this has to be initialized for EmuNAND to work
if ((nand.size / (1024*1024) <= emunand_size_mb) && ShowPrompt(true, "Clone SysNAND to RedNAND now?")) { if ((nand.size / (1024*1024) <= emunand_size_mb) && ShowPrompt(true, "Clone SysNAND to RedNAND now?")) {
if (!PathCopy("E:", "S:/nand_minsize.bin", NULL)) u32 flags = OVERRIDE_PERM;
if (!PathCopy("E:", "S:/nand_minsize.bin", &flags))
ShowPrompt(false, "Cloning SysNAND to EmuNAND: failed!"); ShowPrompt(false, "Cloning SysNAND to EmuNAND: failed!");
} }
DeinitSDCardFS(); DeinitSDCardFS();