mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-12-25 01:31:51 +01:00
Add ability to transverse directories
This commit is contained in:
parent
3acaae4e6d
commit
40017a53a6
@ -15,7 +15,8 @@
|
||||
|
||||
static int scroll_menu_position = 0;
|
||||
static int items_in_dir = 0;
|
||||
static char current_filename[256];
|
||||
|
||||
static FILINFO current_fileinfo;
|
||||
|
||||
// e.g. if (str_endswith(cur_rom, ".z64") || str_endswith(cur_rom, ".n64"))
|
||||
static bool str_endswith(const char *str, const char *suffix) {
|
||||
@ -29,21 +30,21 @@ FRESULT scan_file_path (char* path) {
|
||||
FRESULT res;
|
||||
DIR dir;
|
||||
char sfno[280];
|
||||
int counter = 0;
|
||||
int counter = 0; //FIXME: we dont account for an empty dir or only one valid file!
|
||||
|
||||
res = f_opendir(&dir, path);
|
||||
|
||||
if (res == FR_OK) {
|
||||
for (;;) {
|
||||
FILINFO fno;
|
||||
FILINFO file_info;
|
||||
|
||||
res = f_readdir(&dir, &fno);
|
||||
res = f_readdir(&dir, &file_info);
|
||||
|
||||
if ((res != FR_OK) || (fno.fname[0] == 0)) {
|
||||
if ((res != FR_OK) || (file_info.fname[0] == 0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (fno.fattrib & AM_SYS) {
|
||||
if (file_info.fattrib & AM_SYS) {
|
||||
continue; // we do not want to show system files ever...
|
||||
}
|
||||
|
||||
@ -51,14 +52,14 @@ FRESULT scan_file_path (char* path) {
|
||||
|
||||
// TODO: convert these to icons...
|
||||
sprintf(sfno, "| %c%c%c | %10d | %s",
|
||||
((fno.fattrib & AM_DIR) ? 'D' : '-'),
|
||||
((fno.fattrib & AM_RDO) ? 'R' : '-'),
|
||||
((fno.fattrib & AM_HID) ? 'H' : '-'),
|
||||
(int)fno.fsize, fno.fname);
|
||||
((file_info.fattrib & AM_DIR) ? 'D' : '-'),
|
||||
((file_info.fattrib & AM_RDO) ? 'R' : '-'),
|
||||
((file_info.fattrib & AM_HID) ? 'H' : '-'),
|
||||
(int)file_info.fsize, file_info.fname);
|
||||
|
||||
if (scroll_menu_position == counter -1) {
|
||||
printf("-> %s\n", sfno);
|
||||
sprintf(current_filename, fno.fname);
|
||||
current_fileinfo = file_info;
|
||||
}
|
||||
else {
|
||||
printf(" %s\n", sfno);
|
||||
@ -72,7 +73,7 @@ FRESULT scan_file_path (char* path) {
|
||||
|
||||
void menu_main_refresh (char *dir_path) {
|
||||
console_clear();
|
||||
printf("SC64 Flashcart Menu Rev: 0.0.1\n\n");
|
||||
printf("SC64 Flashcart Menu Rev: 0.0.2\n\n");
|
||||
printf("SD Card Directory list:\n\n");
|
||||
printf(" | DRH | FILE SIZE | FILE NAME\n");
|
||||
printf(" |-----|------------|----------\n");
|
||||
@ -88,6 +89,9 @@ void menu_main_init (settings_t *settings) {
|
||||
controller_init();
|
||||
|
||||
controller_scan();
|
||||
|
||||
char *current_dir = settings->last_state.current_directory;
|
||||
char *last_dir = current_dir;
|
||||
struct controller_data joypad = get_keys_down();
|
||||
|
||||
if ((settings->last_state.auto_load_last_rom) && !(joypad.c[0].B)) { // FIXME: the B button on any controller!
|
||||
@ -99,7 +103,7 @@ void menu_main_init (settings_t *settings) {
|
||||
}
|
||||
else {
|
||||
settings->last_state.auto_load_last_rom = false;
|
||||
menu_main_refresh(settings->last_state.current_directory);
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@ -114,7 +118,7 @@ void menu_main_init (settings_t *settings) {
|
||||
else {
|
||||
scroll_menu_position = items_in_dir;
|
||||
}
|
||||
menu_main_refresh(settings->last_state.current_directory);
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
|
||||
if (joypad.c[0].down) {
|
||||
@ -125,16 +129,16 @@ void menu_main_init (settings_t *settings) {
|
||||
else {
|
||||
scroll_menu_position = 0;
|
||||
}
|
||||
menu_main_refresh(settings->last_state.current_directory);
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
|
||||
if (joypad.c[0].A) {
|
||||
//console_clear();
|
||||
printf("Loading ROM...\n");
|
||||
printf("%s\n", current_filename);
|
||||
// TODO: move this to a function and check that the ROM is valid by checking the header...
|
||||
if (str_endswith(current_filename, ".z64") || str_endswith(current_filename, ".n64") || str_endswith(current_filename, ".v64") || str_endswith(current_filename, ".rom")) {
|
||||
assertf(flashcart_load_rom(current_filename) == FLASHCART_OK, "ROM load error");
|
||||
if (str_endswith(current_fileinfo.fname, ".z64") || str_endswith(current_fileinfo.fname, ".n64") || str_endswith(current_fileinfo.fname, ".v64") || str_endswith(current_fileinfo.fname, ".rom")) {
|
||||
printf("Loading N64 ROM type...\n");
|
||||
printf("%s\n", current_fileinfo.fname);
|
||||
assertf(flashcart_load_rom(current_fileinfo.fname) == FLASHCART_OK, "ROM load error");
|
||||
// FIXME: we now need the header ID and CRC HI...
|
||||
// ed64_dma_read_rom(buff, 0, 1);
|
||||
// crc_high = (buff[0x10] << 24) | (buff[0x11] << 16) | (buff[0x12] << 8) | (buff[0x13] << 0);
|
||||
@ -144,21 +148,34 @@ void menu_main_init (settings_t *settings) {
|
||||
break; //required!
|
||||
}
|
||||
else {
|
||||
// TODO: if this is a directory we need to transverse to it!
|
||||
printf("Failed... Returning to menu...\n");
|
||||
wait_ms(1000);
|
||||
menu_main_refresh(settings->last_state.current_directory);
|
||||
if (current_fileinfo.fattrib & AM_DIR) {
|
||||
// if this is a directory we need to transverse to it!
|
||||
last_dir = current_dir;
|
||||
current_dir = current_fileinfo.fname;
|
||||
scroll_menu_position = 0;
|
||||
items_in_dir = 0;
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
else {
|
||||
printf("Failed... Returning to menu...\n");
|
||||
wait_ms(1000);
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (joypad.c[0].B) {
|
||||
menu_main_refresh(last_dir);
|
||||
current_dir = last_dir;
|
||||
}
|
||||
if (joypad.c[0].start) { // FIXME: the START button on any controller!
|
||||
//console_clear();
|
||||
menu_info();
|
||||
menu_main_refresh(settings->last_state.current_directory);
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
if (joypad.c[0].Z) {
|
||||
//console_clear();
|
||||
menu_fileinfo();
|
||||
menu_main_refresh(settings->last_state.current_directory);
|
||||
menu_main_refresh(current_dir);
|
||||
}
|
||||
}
|
||||
// TODO: write menu state to SD card
|
||||
|
Loading…
Reference in New Issue
Block a user