mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-26 12:12:02 +00:00
File list improvements
This commit is contained in:
parent
1ac1de5470
commit
f5403611b8
3 changed files with 24 additions and 17 deletions
|
@ -3,11 +3,11 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void openMainMenu();
|
||||
static MenuItem* currentFileListBuf;
|
||||
static const char* currentBasePath;
|
||||
static void (*currentExitCb)();
|
||||
|
||||
MenuItem* currentFileListBuf;
|
||||
|
||||
void freeCurrentFileListBuf() {
|
||||
static void freeCurrentFileListBuf() {
|
||||
MenuItem* ptr = currentFileListBuf;
|
||||
while (ptr != NULL) {
|
||||
free(ptr->text);
|
||||
|
@ -17,20 +17,21 @@ void freeCurrentFileListBuf() {
|
|||
}
|
||||
free(currentFileListBuf);
|
||||
}
|
||||
void exitFileList() {
|
||||
static void exitFileList() {
|
||||
freeCurrentFileListBuf();
|
||||
openMainMenu();
|
||||
currentBasePath = NULL;
|
||||
currentExitCb();
|
||||
}
|
||||
char* getParentDir(const char* path) {
|
||||
static char* getParentDir(const char* path, const char* basePath) {
|
||||
char* ptr = strrchr(path, '/');
|
||||
if (ptr == NULL || ptr == path) // not found or first character
|
||||
if (ptr == NULL || (ptr - path < strlen(basePath) && strcmp(path, basePath) == 0))
|
||||
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) {
|
||||
static char* pathJoin(const char* p1, const char* p2) {
|
||||
size_t p1s = strlen(p1);
|
||||
if (p1s == 0)
|
||||
return strdup(p2);
|
||||
|
@ -41,14 +42,17 @@ char* pathJoin(const char* p1, const char* p2) {
|
|||
memcpy(&retval[p1s + 1], p2, p2s + 1); // copy with null terminator
|
||||
return retval;
|
||||
}
|
||||
void printFilesInDir(const char* path) {
|
||||
static void printFilesInDirMenuItem(MenuItem* item);
|
||||
void printFilesInDir(const char* path, const char* basePath, void (*exitCb)()) {
|
||||
int maxMenuItemCount = 48;
|
||||
MenuItem* buf = (MenuItem*) malloc(sizeof(MenuItem) * (maxMenuItemCount + 1));
|
||||
currentFileListBuf = buf;
|
||||
currentBasePath = basePath;
|
||||
currentExitCb = exitCb;
|
||||
DIR* dir = opendir(path);
|
||||
struct dirent* ent;
|
||||
int bufi = 0;
|
||||
char* parentDir = getParentDir(path);
|
||||
char* parentDir = getParentDir(path, basePath);
|
||||
if (parentDir != NULL) {
|
||||
buf[bufi].userdata = parentDir;
|
||||
buf[bufi].text = strdup("..");
|
||||
|
@ -72,6 +76,6 @@ void printFilesInDir(const char* path) {
|
|||
menuSetCurrent(buf, exitFileList);
|
||||
}
|
||||
|
||||
void printFilesInDirMenuItem(MenuItem* item) {
|
||||
printFilesInDir(item->userdata);
|
||||
static void printFilesInDirMenuItem(MenuItem* item) {
|
||||
printFilesInDir(item->userdata, currentBasePath, currentExitCb);
|
||||
}
|
||||
|
|
|
@ -2,5 +2,4 @@
|
|||
|
||||
#include "menu.h"
|
||||
|
||||
void printFilesInDir(const char* path);
|
||||
void printFilesInDirMenuItem(MenuItem* item);
|
||||
void printFilesInDir(const char* path, const char* basePath, void (*exitCb)());
|
|
@ -63,6 +63,11 @@ void dumpPartitionDataMenuItem(MenuItem* item) {
|
|||
menuWaitForAnyButton();
|
||||
}
|
||||
|
||||
void openMainMenu();
|
||||
void viewPartitionExitCb() {
|
||||
fsdevUnmountDevice("view");
|
||||
openMainMenu();
|
||||
}
|
||||
void viewPartitionMenuItem(MenuItem* item) {
|
||||
u32 partition = (u32) (size_t) item->userdata;
|
||||
|
||||
|
@ -74,13 +79,12 @@ void viewPartitionMenuItem(MenuItem* item) {
|
|||
menuWaitForAnyButton();
|
||||
return;
|
||||
}
|
||||
fsdevUnmountDevice("view"); // unmount it if it exists TODO: This should be done when exiting, not here
|
||||
if (fsdevMountDevice("view", fs) == -1) {
|
||||
printf("fsdevMountDevice failed\n");
|
||||
menuWaitForAnyButton();
|
||||
return;
|
||||
}
|
||||
printFilesInDir("view:/");
|
||||
printFilesInDir("view://", "view://", viewPartitionExitCb);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue