1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-29 21:52:22 +00:00

File list improvements

This commit is contained in:
MCMrARM 2018-05-16 20:03:47 +02:00
parent 1ac1de5470
commit f5403611b8
3 changed files with 24 additions and 17 deletions

View file

@ -3,11 +3,11 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
void openMainMenu(); static MenuItem* currentFileListBuf;
static const char* currentBasePath;
static void (*currentExitCb)();
MenuItem* currentFileListBuf; static void freeCurrentFileListBuf() {
void freeCurrentFileListBuf() {
MenuItem* ptr = currentFileListBuf; MenuItem* ptr = currentFileListBuf;
while (ptr != NULL) { while (ptr != NULL) {
free(ptr->text); free(ptr->text);
@ -17,20 +17,21 @@ void freeCurrentFileListBuf() {
} }
free(currentFileListBuf); free(currentFileListBuf);
} }
void exitFileList() { static void exitFileList() {
freeCurrentFileListBuf(); freeCurrentFileListBuf();
openMainMenu(); currentBasePath = NULL;
currentExitCb();
} }
char* getParentDir(const char* path) { static char* getParentDir(const char* path, const char* basePath) {
char* ptr = strrchr(path, '/'); 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; return NULL;
char* retval = (char*) malloc(ptr - path + 1); char* retval = (char*) malloc(ptr - path + 1);
memcpy(retval, path, ptr - path); memcpy(retval, path, ptr - path);
retval[ptr - path] = '\0'; retval[ptr - path] = '\0';
return retval; return retval;
} }
char* pathJoin(const char* p1, const char* p2) { static char* pathJoin(const char* p1, const char* p2) {
size_t p1s = strlen(p1); size_t p1s = strlen(p1);
if (p1s == 0) if (p1s == 0)
return strdup(p2); 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 memcpy(&retval[p1s + 1], p2, p2s + 1); // copy with null terminator
return retval; 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; int maxMenuItemCount = 48;
MenuItem* buf = (MenuItem*) malloc(sizeof(MenuItem) * (maxMenuItemCount + 1)); MenuItem* buf = (MenuItem*) malloc(sizeof(MenuItem) * (maxMenuItemCount + 1));
currentFileListBuf = buf; currentFileListBuf = buf;
currentBasePath = basePath;
currentExitCb = exitCb;
DIR* dir = opendir(path); DIR* dir = opendir(path);
struct dirent* ent; struct dirent* ent;
int bufi = 0; int bufi = 0;
char* parentDir = getParentDir(path); char* parentDir = getParentDir(path, basePath);
if (parentDir != NULL) { if (parentDir != NULL) {
buf[bufi].userdata = parentDir; buf[bufi].userdata = parentDir;
buf[bufi].text = strdup(".."); buf[bufi].text = strdup("..");
@ -72,6 +76,6 @@ void printFilesInDir(const char* path) {
menuSetCurrent(buf, exitFileList); menuSetCurrent(buf, exitFileList);
} }
void printFilesInDirMenuItem(MenuItem* item) { static void printFilesInDirMenuItem(MenuItem* item) {
printFilesInDir(item->userdata); printFilesInDir(item->userdata, currentBasePath, currentExitCb);
} }

View file

@ -2,5 +2,4 @@
#include "menu.h" #include "menu.h"
void printFilesInDir(const char* path); void printFilesInDir(const char* path, const char* basePath, void (*exitCb)());
void printFilesInDirMenuItem(MenuItem* item);

View file

@ -63,6 +63,11 @@ void dumpPartitionDataMenuItem(MenuItem* item) {
menuWaitForAnyButton(); menuWaitForAnyButton();
} }
void openMainMenu();
void viewPartitionExitCb() {
fsdevUnmountDevice("view");
openMainMenu();
}
void viewPartitionMenuItem(MenuItem* item) { void viewPartitionMenuItem(MenuItem* item) {
u32 partition = (u32) (size_t) item->userdata; u32 partition = (u32) (size_t) item->userdata;
@ -74,13 +79,12 @@ void viewPartitionMenuItem(MenuItem* item) {
menuWaitForAnyButton(); menuWaitForAnyButton();
return; return;
} }
fsdevUnmountDevice("view"); // unmount it if it exists TODO: This should be done when exiting, not here
if (fsdevMountDevice("view", fs) == -1) { if (fsdevMountDevice("view", fs) == -1) {
printf("fsdevMountDevice failed\n"); printf("fsdevMountDevice failed\n");
menuWaitForAnyButton(); menuWaitForAnyButton();
return; return;
} }
printFilesInDir("view:/"); printFilesInDir("view://", "view://", viewPartitionExitCb);
} }