mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Misc code reorganization
This commit is contained in:
parent
925861b3e7
commit
1f852472c9
19
source/fs.c
19
source/fs.c
@ -5,9 +5,6 @@
|
|||||||
// 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;
|
||||||
|
|
||||||
// reserve one MB for this, just to be safe -> 512kb is more than enough!
|
|
||||||
static DirStruct* curdir_contents = (DirStruct*)0x21000000;
|
|
||||||
|
|
||||||
// this is the main buffer
|
// this is the main buffer
|
||||||
static u8* main_buffer = (u8*)0x21100000;
|
static u8* main_buffer = (u8*)0x21100000;
|
||||||
// this is the main buffer size
|
// this is the main buffer size
|
||||||
@ -317,20 +314,18 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fsize, bool recu
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirStruct* GetDirContents(const char* path) {
|
void GetDirContents(DirStruct* contents, const char* path) {
|
||||||
curdir_contents->n_entries = 0;
|
contents->n_entries = 0;
|
||||||
if (strncmp(path, "", 256) == 0) { // root directory
|
if (strncmp(path, "", 256) == 0) { // root directory
|
||||||
if (!GetRootDirContentsWorker(curdir_contents))
|
if (!GetRootDirContentsWorker(contents))
|
||||||
curdir_contents->n_entries = 0; // not required, but so what?
|
contents->n_entries = 0; // not required, but so what?
|
||||||
} else {
|
} else {
|
||||||
char fpath[256]; // 256 is the maximum length of a full path
|
char fpath[256]; // 256 is the maximum length of a full path
|
||||||
strncpy(fpath, path, 256);
|
strncpy(fpath, path, 256);
|
||||||
if (!GetDirContentsWorker(curdir_contents, fpath, 256, false))
|
if (!GetDirContentsWorker(contents, fpath, 256, false))
|
||||||
curdir_contents->n_entries = 0;
|
contents->n_entries = 0;
|
||||||
SortDirStruct(curdir_contents);
|
SortDirStruct(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
return curdir_contents;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GetFreeSpace(const char* path)
|
uint64_t GetFreeSpace(const char* path)
|
||||||
|
@ -39,7 +39,7 @@ bool PathDelete(const char* path);
|
|||||||
void CreateScreenshot();
|
void CreateScreenshot();
|
||||||
|
|
||||||
/** Get directory content under a given path **/
|
/** Get directory content under a given path **/
|
||||||
DirStruct* GetDirContents(const char* path);
|
void GetDirContents(DirStruct* contents, const char* path);
|
||||||
|
|
||||||
/** Gets remaining space in filesystem in bytes */
|
/** Gets remaining space in filesystem in bytes */
|
||||||
uint64_t GetFreeSpace(const char* path);
|
uint64_t GetFreeSpace(const char* path);
|
||||||
|
@ -97,42 +97,47 @@ void DrawDirContents(DirStruct* contents, u32 cursor) {
|
|||||||
u32 GodMode() {
|
u32 GodMode() {
|
||||||
static const u32 quick_stp = 20;
|
static const u32 quick_stp = 20;
|
||||||
u32 exit_mode = GODMODE_EXIT_REBOOT;
|
u32 exit_mode = GODMODE_EXIT_REBOOT;
|
||||||
|
|
||||||
|
// reserve 512kB for each, just to be safe
|
||||||
|
static DirStruct* current_dir = (DirStruct*)0x21000000;
|
||||||
|
static DirStruct* clipboard = (DirStruct*)0x21080000;
|
||||||
char current_path[256] = { 0x00 };
|
char current_path[256] = { 0x00 };
|
||||||
DirStruct* contents;
|
|
||||||
u32 cursor = 0;
|
u32 cursor = 0;
|
||||||
|
|
||||||
ClearScreenF(true, true, COLOR_BLACK);
|
ClearScreenF(true, true, COLOR_BLACK);
|
||||||
if (!InitFS()) return exit_mode;
|
if (!InitFS()) return exit_mode;
|
||||||
|
|
||||||
contents = GetDirContents("");
|
GetDirContents(current_dir, "");
|
||||||
|
clipboard->n_entries = 0;
|
||||||
while (true) { // this is the main loop
|
while (true) { // this is the main loop
|
||||||
DrawUserInterface(current_path, &contents->entry[cursor]); // no need to fully do this everytime!
|
DrawUserInterface(current_path, ¤t_dir->entry[cursor]); // no need to fully do this everytime!
|
||||||
DrawDirContents(contents, cursor);
|
DrawDirContents(current_dir, cursor);
|
||||||
u32 pad_state = InputWait();
|
u32 pad_state = InputWait();
|
||||||
if (pad_state & BUTTON_DOWN) {
|
if (pad_state & BUTTON_DOWN) {
|
||||||
cursor++;
|
cursor++;
|
||||||
if (cursor >= contents->n_entries)
|
if (cursor >= current_dir->n_entries)
|
||||||
cursor = contents->n_entries - 1;
|
cursor = current_dir->n_entries - 1;
|
||||||
} else if ((pad_state & BUTTON_UP) && cursor) {
|
} else if ((pad_state & BUTTON_UP) && cursor) {
|
||||||
cursor--;
|
cursor--;
|
||||||
} else if (pad_state & BUTTON_RIGHT) {
|
} else if (pad_state & BUTTON_RIGHT) {
|
||||||
cursor += quick_stp;
|
cursor += quick_stp;
|
||||||
if (cursor >= contents->n_entries)
|
if (cursor >= current_dir->n_entries)
|
||||||
cursor = contents->n_entries - 1;
|
cursor = current_dir->n_entries - 1;
|
||||||
} else if (pad_state & BUTTON_LEFT) {
|
} else if (pad_state & BUTTON_LEFT) {
|
||||||
cursor = (cursor >= quick_stp) ? cursor - quick_stp : 0;
|
cursor = (cursor >= quick_stp) ? cursor - quick_stp : 0;
|
||||||
} else if ((pad_state & BUTTON_L1) && *current_path) {
|
} else if ((pad_state & BUTTON_L1) && *current_path) {
|
||||||
contents->entry[cursor].marked ^= 0x1;
|
current_dir->entry[cursor].marked ^= 0x1;
|
||||||
} else if ((pad_state & BUTTON_A) && (contents->entry[cursor].type != T_FAT_FILE)) {
|
} else if ((pad_state & BUTTON_A) && (current_dir->entry[cursor].type != T_FAT_FILE)) {
|
||||||
strncpy(current_path, contents->entry[cursor].path, 256);
|
strncpy(current_path, current_dir->entry[cursor].path, 256);
|
||||||
contents = GetDirContents(current_path);
|
GetDirContents(current_dir, current_path);
|
||||||
cursor = 0;
|
cursor = 0;
|
||||||
ClearScreenF(true, true, COLOR_STD_BG); // not really required
|
ClearScreenF(true, true, COLOR_STD_BG); // not really required
|
||||||
} else if (pad_state & BUTTON_B) {
|
} else if (pad_state & BUTTON_B) {
|
||||||
char* last_slash = strrchr(current_path, '/');
|
char* last_slash = strrchr(current_path, '/');
|
||||||
if (last_slash) *last_slash = '\0';
|
if (last_slash) *last_slash = '\0';
|
||||||
else *current_path = '\0';
|
else *current_path = '\0';
|
||||||
contents = GetDirContents(current_path);
|
GetDirContents(current_dir, current_path);
|
||||||
cursor = 0;
|
cursor = 0;
|
||||||
ClearScreenF(true, true, COLOR_STD_BG); // not really required
|
ClearScreenF(true, true, COLOR_STD_BG); // not really required
|
||||||
} else if (pad_state & BUTTON_X) {
|
} else if (pad_state & BUTTON_X) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user