forked from Mirror/GodMode9
Misc code reorganization & cleanup
This commit is contained in:
parent
d7ffe06aeb
commit
b575fac6ad
@ -11,7 +11,6 @@
|
|||||||
#define PATH_SYS_LVL3 "S:/firm0.bin", "S:/firm1.bin", "S:/nand.bin", "S:/nand_minsize.bin", "S:/nand_hdr.bin", \
|
#define PATH_SYS_LVL3 "S:/firm0.bin", "S:/firm1.bin", "S:/nand.bin", "S:/nand_minsize.bin", "S:/nand_hdr.bin", \
|
||||||
"S:/sector0x96.bin", "S:/twlmbr.bin"
|
"S:/sector0x96.bin", "S:/twlmbr.bin"
|
||||||
#define PATH_EMU_LVL1 "E:/ctrnand_fat.bin", "E:/ctrnand_full.bin", "E:/nand.bin", "E:/nand_minsize.bin", "E:/nand_hdr.bin"
|
#define PATH_EMU_LVL1 "E:/ctrnand_fat.bin", "E:/ctrnand_full.bin", "E:/nand.bin", "E:/nand_minsize.bin", "E:/nand_hdr.bin"
|
||||||
#define PATH_PERM_CHK "E:", "S:", "1:/rw/sys", "1:/private"
|
|
||||||
|
|
||||||
// write permissions - careful with this
|
// write permissions - careful with this
|
||||||
static u32 write_permissions = PERM_BASE;
|
static u32 write_permissions = PERM_BASE;
|
||||||
|
@ -259,6 +259,88 @@ bool FileInjectFile(const char* dest, const char* orig, u32 offset) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DirBuilderWorker(char* dest) {
|
||||||
|
DIR tmp_dir;
|
||||||
|
if (fa_opendir(&tmp_dir, dest) != FR_OK) {
|
||||||
|
char* slash = strrchr(dest, '/');
|
||||||
|
if (!slash) return false;
|
||||||
|
*slash = '\0';
|
||||||
|
if (!DirBuilderWorker(dest)) return false;
|
||||||
|
*slash = '/';
|
||||||
|
return (fa_mkdir(dest) == FR_OK);
|
||||||
|
} else {
|
||||||
|
f_closedir(&tmp_dir);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DirBuilder(const char* destdir) {
|
||||||
|
char fdpath[256]; // 256 is the maximum length of a full path
|
||||||
|
strncpy(fdpath, destdir, 255);
|
||||||
|
return DirBuilderWorker(fdpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DirCreate(const char* cpath, const char* dirname) {
|
||||||
|
char npath[256]; // 256 is the maximum length of a full path
|
||||||
|
if (!CheckWritePermissions(cpath)) return false;
|
||||||
|
snprintf(npath, 255, "%s/%s", cpath, dirname);
|
||||||
|
return (fa_mkdir(npath) == FR_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DirInfoWorker(char* fpath, bool virtual, u64* tsize, u32* tdirs, u32* tfiles) {
|
||||||
|
char* fname = fpath + strnlen(fpath, 256 - 1);
|
||||||
|
bool ret = true;
|
||||||
|
if (virtual) {
|
||||||
|
VirtualDir vdir;
|
||||||
|
VirtualFile vfile;
|
||||||
|
if (!GetVirtualDir(&vdir, fpath)) return false; // get dir reader object
|
||||||
|
while (ReadVirtualDir(&vfile, &vdir)) {
|
||||||
|
if (vfile.flags & VFLAG_DIR) {
|
||||||
|
(*tdirs)++;
|
||||||
|
*(fname++) = '/';
|
||||||
|
GetVirtualFilename(fname, &vfile, (256 - 1) - (fname - fpath));
|
||||||
|
if (!DirInfoWorker(fpath, virtual, tsize, tdirs, tfiles)) ret = false;
|
||||||
|
*(--fname) = '\0';
|
||||||
|
} else {
|
||||||
|
*tsize += vfile.size;
|
||||||
|
(*tfiles)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DIR pdir;
|
||||||
|
FILINFO fno;
|
||||||
|
if (fa_opendir(&pdir, fpath) != FR_OK) return false; // get dir reader object
|
||||||
|
while (f_readdir(&pdir, &fno) == FR_OK) {
|
||||||
|
if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
|
||||||
|
continue; // filter out virtual entries
|
||||||
|
if (fno.fname[0] == 0) break; // end of dir
|
||||||
|
if (fno.fattrib & AM_DIR) {
|
||||||
|
(*tdirs)++;
|
||||||
|
*(fname++) = '/';
|
||||||
|
strncpy(fname, fno.fname, (256 - 1) - (fname - fpath));
|
||||||
|
if (!DirInfoWorker(fpath, virtual, tsize, tdirs, tfiles)) ret = false;
|
||||||
|
*(--fname) = '\0';
|
||||||
|
} else {
|
||||||
|
*tsize += fno.fsize;
|
||||||
|
(*tfiles)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f_closedir(&pdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DirInfo(const char* path, u64* tsize, u32* tdirs, u32* tfiles) {
|
||||||
|
bool virtual = (DriveType(path) & DRV_VIRTUAL);
|
||||||
|
char fpath[256];
|
||||||
|
strncpy(fpath, path, 255);
|
||||||
|
*tsize = *tdirs = *tfiles = 0;
|
||||||
|
ShowString("Analyzing dir, please wait...");
|
||||||
|
bool res = DirInfoWorker(fpath, virtual, tsize, tdirs, tfiles);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool PathCopyVrtToVrt(const char* destdir, const char* orig, u32* flags) {
|
bool PathCopyVrtToVrt(const char* destdir, const char* orig, u32* flags) {
|
||||||
VirtualFile dvfile;
|
VirtualFile dvfile;
|
||||||
VirtualFile ovfile;
|
VirtualFile ovfile;
|
||||||
@ -686,11 +768,11 @@ bool PathCopy(const char* destdir, const char* orig, u32* flags) {
|
|||||||
int ddrvtype = DriveType(destdir);
|
int ddrvtype = DriveType(destdir);
|
||||||
int odrvtype = DriveType(orig);
|
int odrvtype = DriveType(orig);
|
||||||
if (!(ddrvtype & DRV_VIRTUAL)) { // FAT / virtual to FAT
|
if (!(ddrvtype & DRV_VIRTUAL)) { // FAT / virtual to FAT
|
||||||
if (flags && (*flags & BUILD_PATH)) DirBuilder(destdir);
|
|
||||||
char fdpath[256]; // 256 is the maximum length of a full path
|
char fdpath[256]; // 256 is the maximum length of a full path
|
||||||
char fopath[256];
|
char fopath[256];
|
||||||
strncpy(fdpath, destdir, 255);
|
strncpy(fdpath, destdir, 255);
|
||||||
strncpy(fopath, orig, 255);
|
strncpy(fopath, orig, 255);
|
||||||
|
if (flags && (*flags & BUILD_PATH)) DirBuilderWorker(fdpath);
|
||||||
bool res = (odrvtype & DRV_VIRTUAL) ? PathCopyVrtToFat(fdpath, fopath, flags) :
|
bool res = (odrvtype & DRV_VIRTUAL) ? PathCopyVrtToFat(fdpath, fopath, flags) :
|
||||||
PathCopyWorker(fdpath, fopath, flags, false);
|
PathCopyWorker(fdpath, fopath, flags, false);
|
||||||
return res;
|
return res;
|
||||||
@ -714,11 +796,11 @@ bool PathMove(const char* destdir, const char* orig, u32* flags) {
|
|||||||
ShowPrompt(false, "Error: Moving is not possible here");
|
ShowPrompt(false, "Error: Moving is not possible here");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (flags && (*flags & BUILD_PATH)) DirBuilder(destdir);
|
|
||||||
char fdpath[256]; // 256 is the maximum length of a full path
|
char fdpath[256]; // 256 is the maximum length of a full path
|
||||||
char fopath[256];
|
char fopath[256];
|
||||||
strncpy(fdpath, destdir, 255);
|
strncpy(fdpath, destdir, 255);
|
||||||
strncpy(fopath, orig, 255);
|
strncpy(fopath, orig, 255);
|
||||||
|
if (flags && (*flags & BUILD_PATH)) DirBuilderWorker(fdpath);
|
||||||
bool same_drv = (strncmp(orig, destdir, 2) == 0);
|
bool same_drv = (strncmp(orig, destdir, 2) == 0);
|
||||||
bool res = PathCopyWorker(fdpath, fopath, flags, same_drv);
|
bool res = PathCopyWorker(fdpath, fopath, flags, same_drv);
|
||||||
if (res && (!flags || !(*flags&SKIP_CUR))) PathDelete(orig);
|
if (res && (!flags || !(*flags&SKIP_CUR))) PathDelete(orig);
|
||||||
@ -777,88 +859,6 @@ bool PathRename(const char* path, const char* newname) {
|
|||||||
return (f_rename(path, npath) == FR_OK);
|
return (f_rename(path, npath) == FR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirBuilderWorker(char* dest) {
|
|
||||||
DIR tmp_dir;
|
|
||||||
if (fa_opendir(&tmp_dir, dest) != FR_OK) {
|
|
||||||
char* slash = strrchr(dest, '/');
|
|
||||||
if (!slash) return false;
|
|
||||||
*slash = '\0';
|
|
||||||
if (!DirBuilderWorker(dest)) return false;
|
|
||||||
*slash = '/';
|
|
||||||
return (fa_mkdir(dest) == FR_OK);
|
|
||||||
} else {
|
|
||||||
f_closedir(&tmp_dir);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DirBuilder(const char* destdir) {
|
|
||||||
char fdpath[256]; // 256 is the maximum length of a full path
|
|
||||||
strncpy(fdpath, destdir, 255);
|
|
||||||
return DirBuilderWorker(destdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DirCreate(const char* cpath, const char* dirname) {
|
|
||||||
char npath[256]; // 256 is the maximum length of a full path
|
|
||||||
if (!CheckWritePermissions(cpath)) return false;
|
|
||||||
snprintf(npath, 255, "%s/%s", cpath, dirname);
|
|
||||||
return (fa_mkdir(npath) == FR_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DirInfoWorker(char* fpath, bool virtual, u64* tsize, u32* tdirs, u32* tfiles) {
|
|
||||||
char* fname = fpath + strnlen(fpath, 256 - 1);
|
|
||||||
bool ret = true;
|
|
||||||
if (virtual) {
|
|
||||||
VirtualDir vdir;
|
|
||||||
VirtualFile vfile;
|
|
||||||
if (!GetVirtualDir(&vdir, fpath)) return false; // get dir reader object
|
|
||||||
while (ReadVirtualDir(&vfile, &vdir)) {
|
|
||||||
if (vfile.flags & VFLAG_DIR) {
|
|
||||||
(*tdirs)++;
|
|
||||||
*(fname++) = '/';
|
|
||||||
GetVirtualFilename(fname, &vfile, (256 - 1) - (fname - fpath));
|
|
||||||
if (!DirInfoWorker(fpath, virtual, tsize, tdirs, tfiles)) ret = false;
|
|
||||||
*(--fname) = '\0';
|
|
||||||
} else {
|
|
||||||
*tsize += vfile.size;
|
|
||||||
(*tfiles)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DIR pdir;
|
|
||||||
FILINFO fno;
|
|
||||||
if (fa_opendir(&pdir, fpath) != FR_OK) return false; // get dir reader object
|
|
||||||
while (f_readdir(&pdir, &fno) == FR_OK) {
|
|
||||||
if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
|
|
||||||
continue; // filter out virtual entries
|
|
||||||
if (fno.fname[0] == 0) break; // end of dir
|
|
||||||
if (fno.fattrib & AM_DIR) {
|
|
||||||
(*tdirs)++;
|
|
||||||
*(fname++) = '/';
|
|
||||||
strncpy(fname, fno.fname, (256 - 1) - (fname - fpath));
|
|
||||||
if (!DirInfoWorker(fpath, virtual, tsize, tdirs, tfiles)) ret = false;
|
|
||||||
*(--fname) = '\0';
|
|
||||||
} else {
|
|
||||||
*tsize += fno.fsize;
|
|
||||||
(*tfiles)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f_closedir(&pdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DirInfo(const char* path, u64* tsize, u32* tdirs, u32* tfiles) {
|
|
||||||
bool virtual = (DriveType(path) & DRV_VIRTUAL);
|
|
||||||
char fpath[256];
|
|
||||||
strncpy(fpath, path, 255);
|
|
||||||
*tsize = *tdirs = *tfiles = 0;
|
|
||||||
ShowString("Analyzing dir, please wait...");
|
|
||||||
bool res = DirInfoWorker(fpath, virtual, tsize, tdirs, tfiles);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreateScreenshot() {
|
void CreateScreenshot() {
|
||||||
const u8 bmp_header[54] = {
|
const u8 bmp_header[54] = {
|
||||||
0x42, 0x4D, 0x36, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
|
0x42, 0x4D, 0x36, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
|
||||||
|
@ -44,6 +44,15 @@ u32 FileFindData(const char* path, u8* data, u32 size_data, u32 offset_file);
|
|||||||
/** Inject file into file @offset **/
|
/** Inject file into file @offset **/
|
||||||
bool FileInjectFile(const char* dest, const char* orig, u32 offset);
|
bool FileInjectFile(const char* dest, const char* orig, u32 offset);
|
||||||
|
|
||||||
|
/** Recursively build a directory **/
|
||||||
|
bool DirBuilder(const char* destdir);
|
||||||
|
|
||||||
|
/** Create a new directory in cpath **/
|
||||||
|
bool DirCreate(const char* cpath, const char* dirname);
|
||||||
|
|
||||||
|
/** Get # of files, subdirs and total size for directory **/
|
||||||
|
bool DirInfo(const char* path, u64* tsize, u32* tdirs, u32* tfiles);
|
||||||
|
|
||||||
/** Recursively copy a file or directory **/
|
/** Recursively copy a file or directory **/
|
||||||
bool PathCopy(const char* destdir, const char* orig, u32* flags);
|
bool PathCopy(const char* destdir, const char* orig, u32* flags);
|
||||||
|
|
||||||
@ -56,14 +65,5 @@ bool PathDelete(const char* path);
|
|||||||
/** Rename file / folder in path to new name **/
|
/** Rename file / folder in path to new name **/
|
||||||
bool PathRename(const char* path, const char* newname);
|
bool PathRename(const char* path, const char* newname);
|
||||||
|
|
||||||
/** Recursively build a directory **/
|
|
||||||
bool DirBuilder(const char* destdir);
|
|
||||||
|
|
||||||
/** Create a new directory in cpath **/
|
|
||||||
bool DirCreate(const char* cpath, const char* dirname);
|
|
||||||
|
|
||||||
/** Get # of files, subdirs and total size for directory **/
|
|
||||||
bool DirInfo(const char* path, u64* tsize, u32* tdirs, u32* tfiles);
|
|
||||||
|
|
||||||
/** Create a screenshot of the current framebuffer **/
|
/** Create a screenshot of the current framebuffer **/
|
||||||
void CreateScreenshot();
|
void CreateScreenshot();
|
||||||
|
@ -1096,7 +1096,7 @@ u32 HomeMoreMenu(char* current_path, DirStruct* current_dir, DirStruct* clipboar
|
|||||||
int sys = (DriveType("1:")) ? (int) ++n_opt : -1;
|
int sys = (DriveType("1:")) ? (int) ++n_opt : -1;
|
||||||
int emu = (DriveType("4:")) ? (int) ++n_opt : -1;
|
int emu = (DriveType("4:")) ? (int) ++n_opt : -1;
|
||||||
if (sys > 0) optionstr[sys - 1] = "Backup SysNAND";
|
if (sys > 0) optionstr[sys - 1] = "Backup SysNAND";
|
||||||
if (emu > 0) optionstr[emu - 1] = "BAckup EmuNAND";
|
if (emu > 0) optionstr[emu - 1] = "Backup EmuNAND";
|
||||||
user_select = (n_opt > 1) ? ShowSelectPrompt(n_opt, optionstr, promptstr) : n_opt;
|
user_select = (n_opt > 1) ? ShowSelectPrompt(n_opt, optionstr, promptstr) : n_opt;
|
||||||
if (user_select > 0) {
|
if (user_select > 0) {
|
||||||
u32 flags = CALC_SHA;
|
u32 flags = CALC_SHA;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user