X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fmenu.c;h=55995b9e7d9063d1c4651eb30fb1a47dfca66382;hb=558d8e1fdd54558c58fe5f661369f76458e1addc;hp=df5ff8a436a11df01890e274874d787e2ea2d7bf;hpb=8e708f920ffd20b026aed616e58c8c8e94c8fb8d;p=libpicofe.git diff --git a/gp2x/menu.c b/gp2x/menu.c index df5ff8a..55995b9 100644 --- a/gp2x/menu.c +++ b/gp2x/menu.c @@ -124,6 +124,8 @@ static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy) // handle only 1 event at a time for (i = 1; i != 0; i <<= 1) if (ret & i) { ret &= i; break; } + // ... but allow select + ret |= inp_prev & GP2X_SELECT; return ret; } @@ -275,6 +277,31 @@ static int scandir_filter(const struct dirent *ent) return 1; } +static void do_delete(const char *fpath, const char *fname) +{ + int len, inp; + + gp2x_pd_clone_buffer2(); + + if (!rom_loaded) + menu_darken_bg(gp2x_screen, 320*240, 0); + + len = strlen(fname); + if (len > 320/6) len = 320/6; + + text_out16(320/2 - 15*8/2, 80, "About to delete"); + smalltext_out16_lim(320/2 - len*6/2, 95, fname, 0xbdff, len); + text_out16(320/2 - 13*8/2, 110, "Are you sure?"); + text_out16(320/2 - 25*8/2, 120, "(Y - confirm, X - cancel)"); + menu_flip(); + + + while (gp2x_joystick_read(1) & (GP2X_A|GP2X_SELECT)) usleep(50*1000); + inp = wait_for_input(GP2X_Y|GP2X_X); + if (inp & GP2X_Y) + remove(fpath); +} + static char *romsel_loop(char *curr_path) { struct dirent **namelist; @@ -283,6 +310,7 @@ static char *romsel_loop(char *curr_path) unsigned long inp = 0; char *ret = NULL, *fname = NULL; +rescan: // is this a dir or a full path? if ((dir = opendir(curr_path))) { closedir(dir); @@ -319,24 +347,39 @@ static char *romsel_loop(char *curr_path) for (;;) { draw_dirlist(curr_path, namelist, n, sel); - inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X); + inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_A|GP2X_B|GP2X_X|GP2X_SELECT); if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; } if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; } if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; } if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; } if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; } - if(inp & GP2X_B) { // enter dir/select + if ((inp & GP2X_B) || (inp & (GP2X_SELECT|GP2X_A)) == (GP2X_SELECT|GP2X_A)) // enter dir/select || delete + { again: - if (namelist[sel+1]->d_type == DT_REG) { + if (namelist[sel+1]->d_type == DT_REG) + { strcpy(romFileName, curr_path); strcat(romFileName, "/"); strcat(romFileName, namelist[sel+1]->d_name); - ret = romFileName; - break; - } else if (namelist[sel+1]->d_type == DT_DIR) { - int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; - char *p, *newdir = malloc(newlen); + if (inp & GP2X_B) { // return sel + ret = romFileName; + break; + } + do_delete(romFileName, namelist[sel+1]->d_name); + if (n > 0) { + while (n--) free(namelist[n]); + free(namelist); + } + goto rescan; + } + else if (namelist[sel+1]->d_type == DT_DIR) + { + int newlen; + char *p, *newdir; + if (!(inp & GP2X_B)) continue; + newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; + newdir = malloc(newlen); if (strcmp(namelist[sel+1]->d_name, "..") == 0) { char *start = curr_path; p = start + strlen(start) - 1; @@ -354,7 +397,9 @@ static char *romsel_loop(char *curr_path) ret = romsel_loop(newdir); free(newdir); break; - } else { + } + else + { // unknown file type, happens on NTFS mounts. Try to guess. FILE *tstf; int tmp; strcpy(romFileName, curr_path); @@ -375,7 +420,7 @@ static char *romsel_loop(char *curr_path) } if (n > 0) { - while(n--) free(namelist[n]); + while (n--) free(namelist[n]); free(namelist); } @@ -737,7 +782,8 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ draw_key_config(opts, opt_cnt, player_idx, sel); inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy); // printf("got %08lX from joy %i\n", inp, joy); - if (joy == 0) { + if (joy == 0) + { if (!(inp & GP2X_SELECT)) { prev_select = 0; if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; } @@ -960,9 +1006,9 @@ static void cd_menu_loop_options(void) selected_id == MA_CDOPT_READAHEAD) { if (inp & GP2X_LEFT) { PicoCDBuffers >>= 1; - if (PicoCDBuffers < 64) PicoCDBuffers = 0; + if (PicoCDBuffers < 2) PicoCDBuffers = 0; } else { - if (PicoCDBuffers < 64) PicoCDBuffers = 64; + if (PicoCDBuffers < 2) PicoCDBuffers = 2; else PicoCDBuffers <<= 1; if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M }