X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=menu.c;h=5d96b7e3ed773426ad9c5784a7e577f440a206d7;hb=HEAD;hp=da9ddf2a0d1ae39c91f2f4e21c49f01df44259ba;hpb=f5b32cc30c98b1772cdfd4ed1ff5476dced770cc;p=libpicofe.git diff --git a/menu.c b/menu.c index da9ddf2..5d96b7e 100644 --- a/menu.c +++ b/menu.c @@ -983,7 +983,7 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c) for (i = sel + 1; ; i++) { if (i >= len) - i = 1; + i = 0; if (i == sel) break; @@ -994,10 +994,11 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c) return i; } -static const char *menu_loop_romsel(char *curr_path, int len, +static const char *menu_loop_romsel_d(char *curr_path, int len, const char **filter_exts, int (*extra_filter)(struct dirent **namelist, int count, - const char *basedir)) + const char *basedir), + void (*draw_prep)(void)) { static char rom_fname_reload[256]; // used for scratch and return char sel_fname[256]; @@ -1020,13 +1021,12 @@ static const char *menu_loop_romsel(char *curr_path, int len, curr_path_restore = p; snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1); } - - if (rom_fname_reload[0] == 0) - show_help = 2; } + show_help = 2; rescan: if (namelist != NULL) { + n += !n; while (n-- > 0) free(namelist[n]); free(namelist); @@ -1038,16 +1038,17 @@ rescan: filter = scandir_filter; n = scandir(curr_path, &namelist, filter, (void *)scandir_cmp); - if (n < 0) { + if (n < 0 || !namelist) { lprintf("menu_loop_romsel failed, dir: %s\n", curr_path); // try data root plat_get_data_dir(curr_path, len); n = scandir(curr_path, &namelist, filter, (void *)scandir_cmp); - if (n < 0) { + if (n < 0 || !namelist) { // oops, we failed lprintf("menu_loop_romsel failed, dir: %s\n", curr_path); - return NULL; + namelist = malloc(sizeof(*namelist)); + namelist[0] = calloc(1, sizeof(**namelist)); } } @@ -1098,6 +1099,8 @@ rescan: for (;;) { + if (draw_prep != NULL) + draw_prep(); draw_dirlist(curr_path, namelist, n, sel, show_help); inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT | PBTN_L|PBTN_R|PBTN_MA2|PBTN_MA3|PBTN_MOK|PBTN_MBACK @@ -1106,16 +1109,18 @@ rescan: g_menu_filter_off = !g_menu_filter_off; snprintf(sel_fname, sizeof(sel_fname), "%s", namelist[sel]->d_name); + show_help = 2; goto rescan; } - if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-1; } - if (inp & PBTN_DOWN) { sel++; if (sel > n-1) sel = 0; } - if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } - if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } - if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-1) sel = n-1; } - if (inp & PBTN_R) { sel+=24; if (sel > n-1) sel = n-1; } - - if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2)) + int last = n ? n-1 : 0; + if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = last; } + else if (inp & PBTN_DOWN) { sel++; if (sel > n-1) sel = 0; } + else if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } + else if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-1) sel = last; } + else if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } + else if (inp & PBTN_R) { sel+=24; if (sel > n-1) sel = last; } + + else if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2)) { if (namelist[sel]->d_type == DT_REG) { @@ -1154,7 +1159,7 @@ rescan: strcat(newdir, "/"); strcat(newdir, namelist[sel]->d_name); } - ret = menu_loop_romsel(newdir, newlen, filter_exts, extra_filter); + ret = menu_loop_romsel_d(newdir, newlen, filter_exts, extra_filter, draw_prep); free(newdir); break; } @@ -1188,6 +1193,14 @@ rescan: return ret; } +static const char *menu_loop_romsel(char *curr_path, int len, + const char **filter_exts, + int (*extra_filter)(struct dirent **namelist, int count, + const char *basedir)) +{ + return menu_loop_romsel_d(curr_path, len, filter_exts, extra_filter, NULL); +} + // ------------ savestate loader ------------ #define STATE_SLOT_COUNT 10