forked from Mirror/GodMode9
Totally revised write permission system
... now allows granular control
This commit is contained in:
parent
7082457918
commit
0aae5408b8
103
source/fs.c
103
source/fs.c
@ -14,8 +14,8 @@
|
|||||||
// don't use this area for anything else!
|
// don't use this area for anything else!
|
||||||
static FATFS* fs = (FATFS*)0x20316000;
|
static FATFS* fs = (FATFS*)0x20316000;
|
||||||
|
|
||||||
// write permission level - careful with this
|
// write permissions - careful with this
|
||||||
static u32 write_permission_level = 1;
|
static u32 write_permissions = PERM_BASE;
|
||||||
|
|
||||||
// number of currently open file systems
|
// number of currently open file systems
|
||||||
static bool fs_mounted[NORM_FS] = { false };
|
static bool fs_mounted[NORM_FS] = { false };
|
||||||
@ -79,72 +79,93 @@ bool IsMountedFS(const char* path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CheckWritePermissions(const char* path) {
|
bool CheckWritePermissions(const char* path) {
|
||||||
|
char area_name[16];
|
||||||
int pdrv = PathToNumFS(path);
|
int pdrv = PathToNumFS(path);
|
||||||
if (pdrv < 0) {
|
u32 perm;
|
||||||
if (GetVirtualSource(path)) // this is a hack, but okay for now
|
|
||||||
pdrv = (GetVirtualSource(path) == VRT_MEMORY) ? 10 :
|
if (pdrv == 0) {
|
||||||
(GetVirtualSource(path) == VRT_SYSNAND) ? 1 :
|
perm = PERM_SDCARD;
|
||||||
(GetVirtualSource(path) == VRT_EMUNAND) ? 4 : 7;
|
snprintf(area_name, 16, "the SD card");
|
||||||
else return false;
|
} else if (GetMountState() == IMG_RAMDRV) {
|
||||||
} else if ((pdrv == 7) && (GetMountState() == IMG_RAMDRV)) {
|
perm = PERM_RAMDRIVE;
|
||||||
pdrv = 0; // ...and another hack
|
snprintf(area_name, 16, "the RAM drive");
|
||||||
|
} else if (((pdrv >= 1) && (pdrv <= 3)) || (GetVirtualSource(path) == VRT_SYSNAND)) {
|
||||||
|
perm = PERM_SYSNAND;
|
||||||
|
snprintf(area_name, 16, "the SysNAND");
|
||||||
|
} else if (((pdrv >= 4) && (pdrv <= 6)) || (GetVirtualSource(path) == VRT_EMUNAND)) {
|
||||||
|
perm = PERM_EMUNAND;
|
||||||
|
snprintf(area_name, 16, "the EmuNAND");
|
||||||
|
} else if ((pdrv >= 7) && (pdrv <= 9)) {
|
||||||
|
perm = PERM_IMAGE;
|
||||||
|
snprintf(area_name, 16, "images");
|
||||||
|
} else if (GetVirtualSource(path) == VRT_MEMORY) {
|
||||||
|
perm = PERM_MEMORY;
|
||||||
|
snprintf(area_name, 16, "memory areas");
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pdrv >= 1) && (pdrv <= 3) && (write_permission_level < 3)) {
|
// check permission, return if already set
|
||||||
if (ShowPrompt(true, "Writing to the SysNAND is locked!\nUnlock it now?"))
|
if ((write_permissions & perm) == perm)
|
||||||
return SetWritePermissions(3);
|
return true;
|
||||||
|
|
||||||
|
// ask the user
|
||||||
|
if (!ShowPrompt(true, "Writing to %s is locked!\nUnlock it now?", area_name))
|
||||||
return false;
|
return false;
|
||||||
} else if ((pdrv >= 4) && (pdrv <= 6) && (write_permission_level < 2)) {
|
|
||||||
if (ShowPrompt(true, "Writing to the EmuNAND is locked!\nUnlock it now?"))
|
|
||||||
return SetWritePermissions(2);
|
|
||||||
return false;
|
|
||||||
} else if ((pdrv >= 7) && (pdrv <= 9) && (write_permission_level < 2)) {
|
|
||||||
if (ShowPrompt(true, "Writing to images is locked!\nUnlock it now?"))
|
|
||||||
return SetWritePermissions(2);
|
|
||||||
return false;
|
|
||||||
} else if ((pdrv == 0) && (write_permission_level < 1)) {
|
|
||||||
if (ShowPrompt(true, "Writing to the SD card is locked!\nUnlock it now?"))
|
|
||||||
return SetWritePermissions(1);
|
|
||||||
return false;
|
|
||||||
} else if (pdrv >= 10) {
|
|
||||||
ShowPrompt(false, "Writing to memory is not allowed!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return SetWritePermissions(perm, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetWritePermissions(u32 level) {
|
bool SetWritePermissions(u32 perm, bool add_perm) {
|
||||||
if (write_permission_level >= level) {
|
if ((write_permissions & perm) == perm) { // write permissions already given
|
||||||
// no need to ask the user here
|
if (!add_perm) write_permissions = perm;
|
||||||
write_permission_level = level;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (level) {
|
switch (perm) {
|
||||||
case 1:
|
case PERM_SDCARD:
|
||||||
if (!ShowUnlockSequence(1, "You want to enable SD card\nwriting permissions."))
|
if (!ShowUnlockSequence(1, "You want to enable SD card\nwriting permissions."))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case PERM_RAMDRIVE:
|
||||||
if (!ShowUnlockSequence(2, "You want to enable EmuNAND &\nimage writing permissions.\nKeep backups, just in case."))
|
if (!ShowUnlockSequence(1, "You want to enable RAM drive\nwriting permissions."))
|
||||||
|
return false;
|
||||||
|
case PERM_EMUNAND:
|
||||||
|
if (!ShowUnlockSequence(2, "You want to enable EmuNAND\nwriting permissions.\nKeep backups, just in case."))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case PERM_IMAGE:
|
||||||
|
if (!ShowUnlockSequence(2, "You want to enable image\nwriting permissions.\nKeep backups, just in case."))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case PERM_SYSNAND:
|
||||||
if (!ShowUnlockSequence(3, "!This is your only warning!\n \nYou want to enable SysNAND\nwriting permissions.\nThis enables you to do some\nreally dangerous stuff!\nHaving a SysNAND backup and\nNANDmod is recommended."))
|
if (!ShowUnlockSequence(3, "!This is your only warning!\n \nYou want to enable SysNAND\nwriting permissions.\nThis enables you to do some\nreally dangerous stuff!\nHaving a SysNAND backup and\nNANDmod is recommended."))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
case PERM_MEMORY:
|
||||||
|
if (!ShowUnlockSequence(4, "!Better be careful!\n \nYou want to enable memory\nwriting permissions.\nWriting to certain areas may\nlead to unexpected results."))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case PERM_BASE:
|
||||||
|
if (!ShowUnlockSequence(1, "You want to enable base\nwriting permissions."))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case PERM_ALL:
|
||||||
|
if (!ShowUnlockSequence(3, "!This is your only warning!\n \nYou want to enable ALL\nwriting permissions.\nThis enables you to do some\nreally dangerous stuff!\nHaving a SysNAND backup and\nNANDmod is recommended."))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_permission_level = level;
|
write_permissions = add_perm ? write_permissions | perm : perm;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetWritePermissions() {
|
u32 GetWritePermissions() {
|
||||||
return write_permission_level;
|
return write_permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetTempFileName(char* path) {
|
bool GetTempFileName(char* path) {
|
||||||
|
11
source/fs.h
11
source/fs.h
@ -11,6 +11,15 @@ typedef enum {
|
|||||||
|
|
||||||
#define MAX_ENTRIES 1024
|
#define MAX_ENTRIES 1024
|
||||||
|
|
||||||
|
#define PERM_SDCARD (1<<0)
|
||||||
|
#define PERM_RAMDRIVE (1<<1)
|
||||||
|
#define PERM_EMUNAND (1<<2)
|
||||||
|
#define PERM_SYSNAND (1<<3)
|
||||||
|
#define PERM_IMAGE (1<<4)
|
||||||
|
#define PERM_MEMORY (1<<5)
|
||||||
|
#define PERM_BASE (PERM_SDCARD | PERM_RAMDRIVE)
|
||||||
|
#define PERM_ALL (PERM_SDCARD | PERM_RAMDRIVE | PERM_EMUNAND | PERM_SYSNAND | PERM_IMAGE | PERM_MEMORY)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* name; // should point to the correct portion of the path
|
char* name; // should point to the correct portion of the path
|
||||||
char path[256];
|
char path[256];
|
||||||
@ -33,7 +42,7 @@ void DeinitSDCardFS();
|
|||||||
bool CheckWritePermissions(const char* path);
|
bool CheckWritePermissions(const char* path);
|
||||||
|
|
||||||
/** Set new write permissions */
|
/** Set new write permissions */
|
||||||
bool SetWritePermissions(u32 level);
|
bool SetWritePermissions(u32 perm, bool add_perm);
|
||||||
|
|
||||||
/** Get write permissions */
|
/** Get write permissions */
|
||||||
u32 GetWritePermissions();
|
u32 GetWritePermissions();
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
#include "virtual.h"
|
#include "virtual.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
#define VERSION "0.4.9"
|
#define VERSION "0.5.0rc1"
|
||||||
|
|
||||||
#define N_PANES 2
|
#define N_PANES 2
|
||||||
#define IMG_DRV "789I"
|
#define IMG_DRV "789I"
|
||||||
|
|
||||||
#define WORK_BUFFER ((u8*)0x21100000)
|
#define WORK_BUFFER ((u8*)0x21100000)
|
||||||
|
|
||||||
#define COLOR_TOP_BAR ((GetWritePermissions() == 0) ? COLOR_WHITE : (GetWritePermissions() == 1) ? COLOR_BRIGHTGREEN : (GetWritePermissions() == 2) ? COLOR_BRIGHTYELLOW : COLOR_RED)
|
#define COLOR_TOP_BAR ((GetWritePermissions() & PERM_SYSNAND) ? COLOR_RED : (GetWritePermissions() & PERM_MEMORY) ? COLOR_BRIGHTBLUE : (GetWritePermissions() & (PERM_EMUNAND|PERM_IMAGE)) ? COLOR_BRIGHTYELLOW : GetWritePermissions() ? COLOR_BRIGHTGREEN : COLOR_WHITE)
|
||||||
#define COLOR_SIDE_BAR COLOR_DARKGREY
|
#define COLOR_SIDE_BAR COLOR_DARKGREY
|
||||||
#define COLOR_MARKED COLOR_TINTEDYELLOW
|
#define COLOR_MARKED COLOR_TINTEDYELLOW
|
||||||
#define COLOR_FILE COLOR_TINTEDGREEN
|
#define COLOR_FILE COLOR_TINTEDGREEN
|
||||||
@ -107,9 +107,8 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
|
|||||||
"GodMode9 Explorer v", VERSION, // generic start part
|
"GodMode9 Explorer v", VERSION, // generic start part
|
||||||
(*curr_path) ? ((clipboard->n_entries == 0) ? "L - MARK files (use with \x18\x19\x1A\x1B)\nX - DELETE / [+R] RENAME file(s)\nY - COPY file(s) / [+R] CREATE dir\n" :
|
(*curr_path) ? ((clipboard->n_entries == 0) ? "L - MARK files (use with \x18\x19\x1A\x1B)\nX - DELETE / [+R] RENAME file(s)\nY - COPY file(s) / [+R] CREATE dir\n" :
|
||||||
"L - MARK files (use with \x18\x19\x1A\x1B)\nX - DELETE / [+R] RENAME file(s)\nY - PASTE file(s) / [+R] CREATE dir\n") :
|
"L - MARK files (use with \x18\x19\x1A\x1B)\nX - DELETE / [+R] RENAME file(s)\nY - PASTE file(s) / [+R] CREATE dir\n") :
|
||||||
((GetWritePermissions() <= 1) ? "X - Unlock EmuNAND / image writing\nY - Unlock SysNAND writing\nR+B - Unmount SD card\n" :
|
((GetWritePermissions() > PERM_BASE) ? "R+Y - Relock write permissions\nR+B - Unmount SD card\n" :
|
||||||
(GetWritePermissions() == 2) ? "X - Relock EmuNAND / image writing\nY - Unlock SysNAND writing\nR+B - Unmount SD card\n" :
|
"R+Y - Unlock write permissions\nR+B - Unmount SD card\n"),
|
||||||
"X - Relock EmuNAND writing\nY - Relock SysNAND writing\nR+B - Unmount SD card\n"),
|
|
||||||
(*curr_path) ? "" : ((GetMountState() == IMG_RAMDRV) ? "R+X - Unmount RAM drive\n" :
|
(*curr_path) ? "" : ((GetMountState() == IMG_RAMDRV) ? "R+X - Unmount RAM drive\n" :
|
||||||
(GetMountState()) ? "R+X - Unmount image\n" : "R+X - Mount RAM drive\n"),
|
(GetMountState()) ? "R+X - Unmount image\n" : "R+X - Mount RAM drive\n"),
|
||||||
"R+L - Make a Screenshot\n",
|
"R+L - Make a Screenshot\n",
|
||||||
@ -553,8 +552,8 @@ u32 GodMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// highly specific commands
|
// highly specific commands
|
||||||
if (!(*current_path)) { // in the root folder...
|
if (!*current_path) { // in the root folder...
|
||||||
if (switched && !*current_path && (pad_state & BUTTON_X)) { // unmount image
|
if (switched && (pad_state & BUTTON_X)) { // unmount image
|
||||||
DeinitExtFS();
|
DeinitExtFS();
|
||||||
if (!GetMountState()) MountRamDrive();
|
if (!GetMountState()) MountRamDrive();
|
||||||
else MountImage(NULL);
|
else MountImage(NULL);
|
||||||
@ -562,10 +561,8 @@ u32 GodMode() {
|
|||||||
GetDirContents(current_dir, current_path);
|
GetDirContents(current_dir, current_path);
|
||||||
if (clipboard->n_entries && (strcspn(clipboard->entry[0].path, IMG_DRV) == 0))
|
if (clipboard->n_entries && (strcspn(clipboard->entry[0].path, IMG_DRV) == 0))
|
||||||
clipboard->n_entries = 0; // remove invalid clipboard stuff
|
clipboard->n_entries = 0; // remove invalid clipboard stuff
|
||||||
} else if (pad_state & BUTTON_X) {
|
} else if (switched && (pad_state & BUTTON_Y)) {
|
||||||
SetWritePermissions((GetWritePermissions() >= 2) ? 1 : 2);
|
SetWritePermissions((GetWritePermissions() > PERM_BASE) ? PERM_BASE : PERM_ALL, false);
|
||||||
} else if (pad_state & BUTTON_Y) {
|
|
||||||
SetWritePermissions((GetWritePermissions() >= 3) ? 2 : 3);
|
|
||||||
}
|
}
|
||||||
} else if (!switched) { // standard unswitched command set
|
} else if (!switched) { // standard unswitched command set
|
||||||
if (GetVirtualSource(current_path) && (pad_state & BUTTON_X)) {
|
if (GetVirtualSource(current_path) && (pad_state & BUTTON_X)) {
|
||||||
|
10
source/ui.c
10
source/ui.c
@ -192,18 +192,20 @@ bool ShowPrompt(bool ask, const char *format, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
|
bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
|
||||||
const int seqcolors[4] = { COLOR_STD_FONT, COLOR_GREEN, COLOR_YELLOW, COLOR_RED };
|
const int seqcolors[5] = { COLOR_STD_FONT, COLOR_BRIGHTGREEN, COLOR_BRIGHTYELLOW, COLOR_RED, COLOR_BRIGHTBLUE };
|
||||||
const u32 sequences[4][5] = {
|
const u32 sequences[5][5] = {
|
||||||
{ BUTTON_RIGHT, BUTTON_DOWN, BUTTON_RIGHT, BUTTON_DOWN, BUTTON_A },
|
{ BUTTON_RIGHT, BUTTON_DOWN, BUTTON_RIGHT, BUTTON_DOWN, BUTTON_A },
|
||||||
{ BUTTON_LEFT, BUTTON_DOWN, BUTTON_RIGHT, BUTTON_UP, BUTTON_A },
|
{ BUTTON_LEFT, BUTTON_DOWN, BUTTON_RIGHT, BUTTON_UP, BUTTON_A },
|
||||||
{ BUTTON_LEFT, BUTTON_RIGHT, BUTTON_DOWN, BUTTON_UP, BUTTON_A },
|
{ BUTTON_LEFT, BUTTON_RIGHT, BUTTON_DOWN, BUTTON_UP, BUTTON_A },
|
||||||
{ BUTTON_LEFT, BUTTON_UP, BUTTON_RIGHT, BUTTON_UP, BUTTON_A }
|
{ BUTTON_LEFT, BUTTON_UP, BUTTON_RIGHT, BUTTON_UP, BUTTON_A },
|
||||||
|
{ BUTTON_RIGHT, BUTTON_DOWN, BUTTON_LEFT, BUTTON_DOWN, BUTTON_A }
|
||||||
};
|
};
|
||||||
const char seqsymbols[4][5] = {
|
const char seqsymbols[5][5] = {
|
||||||
{ '\x1A', '\x19', '\x1A', '\x19', 'A' },
|
{ '\x1A', '\x19', '\x1A', '\x19', 'A' },
|
||||||
{ '\x1B', '\x19', '\x1A', '\x18', 'A' },
|
{ '\x1B', '\x19', '\x1A', '\x18', 'A' },
|
||||||
{ '\x1B', '\x1A', '\x19', '\x18', 'A' },
|
{ '\x1B', '\x1A', '\x19', '\x18', 'A' },
|
||||||
{ '\x1B', '\x18', '\x1A', '\x18', 'A' },
|
{ '\x1B', '\x18', '\x1A', '\x18', 'A' },
|
||||||
|
{ '\x1A', '\x19', '\x1B', '\x19', 'A' }
|
||||||
};
|
};
|
||||||
const u32 len = 5;
|
const u32 len = 5;
|
||||||
u32 lvl = 0;
|
u32 lvl = 0;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#define COLOR_BRIGHTRED RGB(0xFF, 0x30, 0x30)
|
#define COLOR_BRIGHTRED RGB(0xFF, 0x30, 0x30)
|
||||||
#define COLOR_BRIGHTYELLOW RGB(0xFF, 0xFF, 0x30)
|
#define COLOR_BRIGHTYELLOW RGB(0xFF, 0xFF, 0x30)
|
||||||
#define COLOR_BRIGHTGREEN RGB(0x30, 0xFF, 0x30)
|
#define COLOR_BRIGHTGREEN RGB(0x30, 0xFF, 0x30)
|
||||||
|
#define COLOR_BRIGHTBLUE RGB(0x30, 0x30, 0xFF)
|
||||||
|
|
||||||
#define COLOR_TINTEDBLUE RGB(0x60, 0x60, 0x80)
|
#define COLOR_TINTEDBLUE RGB(0x60, 0x60, 0x80)
|
||||||
#define COLOR_TINTEDYELLOW RGB(0xD0, 0xD0, 0x60)
|
#define COLOR_TINTEDYELLOW RGB(0xD0, 0xD0, 0x60)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user