mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Added a write permission system
This commit is contained in:
parent
759da56e67
commit
44c351c1a7
34
source/fs.c
34
source/fs.c
@ -10,6 +10,9 @@ static u8* main_buffer = (u8*)0x21100000;
|
||||
// this is the main buffer size
|
||||
static size_t main_buffer_size = 4 * 1024 * 1024;
|
||||
|
||||
// write permission level - careful with this
|
||||
static u32 write_permission_level = 1;
|
||||
|
||||
// number of currently open file systems
|
||||
static u32 numfs = 0;
|
||||
|
||||
@ -42,9 +45,38 @@ void DeinitFS() {
|
||||
numfs = 0;
|
||||
}
|
||||
|
||||
bool CheckWritePermissions(const char* path) {
|
||||
u32 pdrv = *path - '0';
|
||||
|
||||
if ((pdrv > 6) || (*(path+1) != ':')) {
|
||||
ShowPrompt(false, "Invalid path");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((pdrv >= 1) && (pdrv <= 3) && (write_permission_level < 3)) {
|
||||
ShowPrompt(false, "Writing to the SysNAND is locked!\nUnlock it from the root menu.");
|
||||
return false;
|
||||
} else if ((pdrv >= 4) && (pdrv <= 6) && (write_permission_level < 2)) {
|
||||
ShowPrompt(false, "Writing to the EmuNAND is locked!\nUnlock it from the root menu.");
|
||||
return false;
|
||||
} else if ((pdrv == 0) && (write_permission_level < 1)) {
|
||||
ShowPrompt(false, "Writing to the SD card is locked!\nUnlock it from the root menu.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetWritePermissions(u32 level) {
|
||||
write_permission_level = level;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileCreate(const char* path, u8* data, u32 size) {
|
||||
FIL file;
|
||||
UINT bytes_written = 0;
|
||||
if (!CheckWritePermissions(path)) return false;
|
||||
if (f_open(&file, path, FA_READ | FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
|
||||
return false;
|
||||
f_write(&file, data, size, &bytes_written);
|
||||
@ -145,6 +177,7 @@ bool PathCopyWorker(char* dest, char* orig) {
|
||||
bool PathCopy(const char* destdir, const char* orig) {
|
||||
char fdpath[256]; // 256 is the maximum length of a full path
|
||||
char fopath[256];
|
||||
if (!CheckWritePermissions(destdir)) return false;
|
||||
strncpy(fdpath, destdir, 256);
|
||||
strncpy(fopath, orig, 256);
|
||||
return PathCopyWorker(fdpath, fopath);
|
||||
@ -187,6 +220,7 @@ bool PathDeleteWorker(char* fpath) {
|
||||
|
||||
bool PathDelete(const char* path) {
|
||||
char fpath[256]; // 256 is the maximum length of a full path
|
||||
if (!CheckWritePermissions(path)) return false;
|
||||
strncpy(fpath, path, 256);
|
||||
return PathDeleteWorker(fpath);
|
||||
}
|
||||
|
@ -26,6 +26,12 @@ typedef struct {
|
||||
bool InitFS();
|
||||
void DeinitFS();
|
||||
|
||||
/** Check if writing to this path is allowed **/
|
||||
bool CheckWritePermissions(const char* path);
|
||||
|
||||
/** Set new write permissions */
|
||||
bool SetWritePermissions(u32 level);
|
||||
|
||||
/** Create / overwrite file and write the provided data to it **/
|
||||
bool FileCreate(const char* path, u8* data, u32 size);
|
||||
|
||||
|
@ -56,7 +56,7 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
|
||||
|
||||
|
||||
// bottom: inctruction block
|
||||
char* instr = "GodMode 9 v0.0.1\n<A>/<B>/<\x18\x19\x1A\x1B> - Navigation\n<L> - Mark (multiple) file(s)\n<X> - Make a Screenshot\n<START/+\x1B> - Reboot / Power off";
|
||||
char* instr = "GodMode 9 v0.0.3\n<A>/<B>/<\x18\x19\x1A\x1B> - Navigation\n<L>(+<\x18\x19\x1A\x1B> - Mark entries(s)\n<X> - Make a Screenshot\n<START/+\x1B> - Reboot/Poweroff";
|
||||
DrawStringF(true, (SCREEN_WIDTH_TOP - GetDrawStringWidth(instr)) / 2, SCREEN_HEIGHT - 2 - GetDrawStringHeight(instr), COLOR_STD_FONT, COLOR_STD_BG, instr);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user