use fatfs for dir listing

This commit is contained in:
Robin Jones 2023-02-23 02:59:54 +00:00
parent 6aafc026c5
commit e4809345fa

View File

@ -4,6 +4,7 @@
#include <unistd.h>
#include <libdragon.h>
#include <fatfs/ff.h>
#include "flashcart/flashcart.h"
#include "libs/toml/toml.h"
@ -103,6 +104,37 @@ void menu_restore (menu_t *menu) {
// TODO: restore last menu state from SD card
}
FRESULT scan_files (
char* path /* Start node to be scanned (***also used as work area***) */
)
{
FRESULT res;
DIR dir;
UINT i;
static FILINFO fno;
res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
for (;;) {
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) { /* It is a directory */
i = strlen(path);
sprintf(&path[i], "/%s", fno.fname);
res = scan_files(path); /* Enter the directory */
if (res != FR_OK) break;
path[i] = 0;
} else { /* It is a file. */
printf("%s/%s\n", path, fno.fname);
}
}
f_closedir(&dir);
}
return res;
}
void menu_run (menu_t *menu) {
// TODO: implement nice user interface here
@ -122,21 +154,11 @@ void menu_run (menu_t *menu) {
else {
printf("N64 Flashcart Menu\n\n");
printf("File list:\n");
DIR *dp;
struct dirent *ep;
dp = opendir ("sd://");
if (dp != NULL)
{
while ((ep = readdir (dp)) != NULL)
puts (ep->d_name);
(void) closedir (dp);
return 0;
}
else
{
printf("Couldn't open the directory");
}
FRESULT res;
char buff[256];
strcpy(buff, "/");
res = scan_files(buff);
// TODO: wait for a key input
}
// TODO: write menu state to SD card