mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2025-02-19 23:15:37 +00:00
Add a debug file browser
This commit is contained in:
parent
497052d9df
commit
18e0170bcb
3 changed files with 85 additions and 5 deletions
|
@ -1,6 +1,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <memory.h>
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "dumper.h"
|
#include "dumper.h"
|
||||||
#include "ccolor.h"
|
#include "ccolor.h"
|
||||||
|
@ -24,18 +27,94 @@ void startOperation(const char* title) {
|
||||||
printf(C_DIM "%s\n\n" C_RESET, title);
|
printf(C_DIM "%s\n\n" C_RESET, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpPartitionZero() {
|
void dumpPartitionZero(MenuItem* item) {
|
||||||
startOperation("Raw Dump Partition 0 (SysUpdate)");
|
startOperation("Raw Dump Partition 0 (SysUpdate)");
|
||||||
workaroundPartitionZeroAccess(&fsOperatorInstance);
|
workaroundPartitionZeroAccess(&fsOperatorInstance);
|
||||||
dumpPartitionRaw(&fsOperatorInstance, 0);
|
dumpPartitionRaw(&fsOperatorInstance, 0);
|
||||||
menuWaitForAnyButton();
|
menuWaitForAnyButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printFilesInDirMenuItem(MenuItem* item);
|
||||||
|
|
||||||
MenuItem mainMenu[] = {
|
MenuItem mainMenu[] = {
|
||||||
{ .text = "Raw Dump Partition 0 (SysUpdate)", .callback = dumpPartitionZero },
|
{ .text = "Raw Dump Partition 0 (SysUpdate)", .callback = dumpPartitionZero },
|
||||||
|
{ .text = "Print files on SD Card", .callback = printFilesInDirMenuItem, .userdata = "/" },
|
||||||
{ .text = NULL }
|
{ .text = NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
MenuItem* currentFileListBuf;
|
||||||
|
|
||||||
|
void freeCurrentFileListBuf() {
|
||||||
|
MenuItem* ptr = currentFileListBuf;
|
||||||
|
while (ptr != NULL) {
|
||||||
|
free(ptr->text);
|
||||||
|
if (ptr->userdata != NULL)
|
||||||
|
free(ptr->userdata);
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
free(currentFileListBuf);
|
||||||
|
}
|
||||||
|
void exitFileList() {
|
||||||
|
freeCurrentFileListBuf();
|
||||||
|
menuSetCurrent(mainMenu, menuExit);
|
||||||
|
}
|
||||||
|
char* getParentDir(const char* path) {
|
||||||
|
char* ptr = strrchr(path, '/');
|
||||||
|
if (ptr == NULL || ptr == path) // not found or first character
|
||||||
|
return NULL;
|
||||||
|
char* retval = (char*) malloc(ptr - path + 1);
|
||||||
|
memcpy(retval, path, ptr - path);
|
||||||
|
retval[ptr - path] = '\0';
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
char* pathJoin(const char* p1, const char* p2) {
|
||||||
|
size_t p1s = strlen(p1);
|
||||||
|
if (p1s == 0)
|
||||||
|
return strdup(p2);
|
||||||
|
size_t p2s = strlen(p2);
|
||||||
|
char* retval = (char*) malloc(p1s + 1 + p2s + 1);
|
||||||
|
memcpy(retval, p1, p1s);
|
||||||
|
retval[p1s] = '/';
|
||||||
|
memcpy(&retval[p1s + 1], p2, p2s + 1); // copy with null terminator
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
void printFilesInDir(const char* path) {
|
||||||
|
int maxMenuItemCount = 48;
|
||||||
|
MenuItem* buf = (MenuItem*) malloc(sizeof(MenuItem) * (maxMenuItemCount + 1));
|
||||||
|
currentFileListBuf = buf;
|
||||||
|
DIR* dir = opendir(path);
|
||||||
|
struct dirent* ent;
|
||||||
|
int bufi = 0;
|
||||||
|
char* parentDir = getParentDir(path);
|
||||||
|
if (parentDir != NULL) {
|
||||||
|
buf[bufi].userdata = parentDir;
|
||||||
|
buf[bufi].text = strdup("..");
|
||||||
|
buf[bufi].callback = printFilesInDirMenuItem;
|
||||||
|
bufi++;
|
||||||
|
}
|
||||||
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
|
if (ent->d_type == DT_DIR) {
|
||||||
|
buf[bufi].text = pathJoin(ent->d_name, "");
|
||||||
|
buf[bufi].userdata = pathJoin(path, ent->d_name);
|
||||||
|
buf[bufi].callback = printFilesInDirMenuItem;
|
||||||
|
} else {
|
||||||
|
buf[bufi].text = strdup(ent->d_name);
|
||||||
|
buf[bufi].userdata = buf[bufi].callback = NULL;
|
||||||
|
}
|
||||||
|
if (++bufi >= maxMenuItemCount)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf[bufi].text = NULL;
|
||||||
|
closedir(dir);
|
||||||
|
menuSetCurrent(buf, exitFileList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printFilesInDirMenuItem(MenuItem* item) {
|
||||||
|
printFilesInDir(item->userdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
gfxInitDefault();
|
gfxInitDefault();
|
||||||
consoleInit(NULL);
|
consoleInit(NULL);
|
||||||
|
|
|
@ -41,7 +41,7 @@ int menuHandleInput() {
|
||||||
bool needsRefresh = false;
|
bool needsRefresh = false;
|
||||||
u64 keys = hidKeysDown(CONTROLLER_P1_AUTO);
|
u64 keys = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||||
if ((keys & KEY_A) && menuCurrent[menuSelIndex].callback != NULL) {
|
if ((keys & KEY_A) && menuCurrent[menuSelIndex].callback != NULL) {
|
||||||
menuCurrent[menuSelIndex].callback();
|
menuCurrent[menuSelIndex].callback(&menuCurrent[menuSelIndex]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((keys & KEY_B) && menuExitCallback != NULL) {
|
if ((keys & KEY_B) && menuExitCallback != NULL) {
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct _MenuItem {
|
||||||
const char* text;
|
char* text;
|
||||||
void (*callback)();
|
void (*callback)(struct _MenuItem* item);
|
||||||
|
void* userdata;
|
||||||
} MenuItem;
|
} MenuItem;
|
||||||
|
|
||||||
void menuPrint();
|
void menuPrint();
|
||||||
|
|
Loading…
Add table
Reference in a new issue