From e4809345fac8a6a64dd3af5cd394afee891bb263 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Thu, 23 Feb 2023 02:59:54 +0000 Subject: [PATCH] use fatfs for dir listing --- src/menu/menu.c | 52 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/menu/menu.c b/src/menu/menu.c index adbc065d..4b172293 100644 --- a/src/menu/menu.c +++ b/src/menu/menu.c @@ -4,6 +4,7 @@ #include #include +#include #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