mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-22 02:29:19 +01:00
use fatfs for dir listing
This commit is contained in:
parent
6aafc026c5
commit
e4809345fa
@ -4,6 +4,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <libdragon.h>
|
#include <libdragon.h>
|
||||||
|
#include <fatfs/ff.h>
|
||||||
|
|
||||||
#include "flashcart/flashcart.h"
|
#include "flashcart/flashcart.h"
|
||||||
#include "libs/toml/toml.h"
|
#include "libs/toml/toml.h"
|
||||||
@ -103,6 +104,37 @@ void menu_restore (menu_t *menu) {
|
|||||||
// TODO: restore last menu state from SD card
|
// 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) {
|
void menu_run (menu_t *menu) {
|
||||||
// TODO: implement nice user interface here
|
// TODO: implement nice user interface here
|
||||||
|
|
||||||
@ -122,21 +154,11 @@ void menu_run (menu_t *menu) {
|
|||||||
else {
|
else {
|
||||||
printf("N64 Flashcart Menu\n\n");
|
printf("N64 Flashcart Menu\n\n");
|
||||||
printf("File list:\n");
|
printf("File list:\n");
|
||||||
DIR *dp;
|
FRESULT res;
|
||||||
struct dirent *ep;
|
char buff[256];
|
||||||
dp = opendir ("sd://");
|
strcpy(buff, "/");
|
||||||
if (dp != NULL)
|
res = scan_files(buff);
|
||||||
{
|
|
||||||
while ((ep = readdir (dp)) != NULL)
|
|
||||||
puts (ep->d_name);
|
|
||||||
|
|
||||||
(void) closedir (dp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Couldn't open the directory");
|
|
||||||
}
|
|
||||||
// TODO: wait for a key input
|
// TODO: wait for a key input
|
||||||
}
|
}
|
||||||
// TODO: write menu state to SD card
|
// TODO: write menu state to SD card
|
||||||
|
Loading…
Reference in New Issue
Block a user