return 1;\r
}\r
\r
+static void do_delete(const char *fpath, const char *fname)\r
+{\r
+ int len, inp;\r
+\r
+ gp2x_pd_clone_buffer2();\r
+\r
+ if (!rom_loaded)\r
+ menu_darken_bg(gp2x_screen, 320*240, 0);\r
+\r
+ len = strlen(fname);\r
+ if (len > 320/6) len = 320/6;\r
+\r
+ text_out16(320/2 - 15*8/2, 80, "About to delete");\r
+ smalltext_out16_lim(320/2 - len*6/2, 95, fname, 0xbdff, len);\r
+ text_out16(320/2 - 13*8/2, 110, "Are you sure?");\r
+ text_out16(320/2 - 25*8/2, 120, "(Y - confirm, X - cancel)");\r
+ menu_flip();\r
+\r
+\r
+ while (gp2x_joystick_read(1) & (GP2X_A|GP2X_SELECT)) usleep(50*1000);\r
+ inp = wait_for_input(GP2X_Y|GP2X_X);\r
+ if (inp & GP2X_Y)\r
+ remove(fpath);\r
+}\r
+\r
static char *romsel_loop(char *curr_path)\r
{\r
struct dirent **namelist;\r
unsigned long inp = 0;\r
char *ret = NULL, *fname = NULL;\r
\r
+rescan:\r
// is this a dir or a full path?\r
if ((dir = opendir(curr_path))) {\r
closedir(dir);\r
for (;;)\r
{\r
draw_dirlist(curr_path, namelist, n, sel);\r
- inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r
+ inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_A|GP2X_B|GP2X_X|GP2X_SELECT);\r
if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }\r
if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }\r
if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r
if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; }\r
if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; }\r
- if(inp & GP2X_B) { // enter dir/select\r
+ if ((inp & GP2X_B) || (inp & (GP2X_SELECT|GP2X_A)) == (GP2X_SELECT|GP2X_A)) // enter dir/select || delete\r
+ {\r
again:\r
- if (namelist[sel+1]->d_type == DT_REG) {\r
+ if (namelist[sel+1]->d_type == DT_REG)\r
+ {\r
strcpy(romFileName, curr_path);\r
strcat(romFileName, "/");\r
strcat(romFileName, namelist[sel+1]->d_name);\r
- ret = romFileName;\r
- break;\r
- } else if (namelist[sel+1]->d_type == DT_DIR) {\r
- int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
- char *p, *newdir = malloc(newlen);\r
+ if (inp & GP2X_B) { // return sel\r
+ ret = romFileName;\r
+ break;\r
+ }\r
+ do_delete(romFileName, namelist[sel+1]->d_name);\r
+ if (n > 0) {\r
+ while (n--) free(namelist[n]);\r
+ free(namelist);\r
+ }\r
+ goto rescan;\r
+ }\r
+ else if (namelist[sel+1]->d_type == DT_DIR)\r
+ {\r
+ int newlen;\r
+ char *p, *newdir;\r
+ if (!(inp & GP2X_B)) continue;\r
+ newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
+ newdir = malloc(newlen);\r
if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r
char *start = curr_path;\r
p = start + strlen(start) - 1;\r
ret = romsel_loop(newdir);\r
free(newdir);\r
break;\r
- } else {\r
+ }\r
+ else\r
+ {\r
// unknown file type, happens on NTFS mounts. Try to guess.\r
FILE *tstf; int tmp;\r
strcpy(romFileName, curr_path);\r
}\r
\r
if (n > 0) {\r
- while(n--) free(namelist[n]);\r
+ while (n--) free(namelist[n]);\r
free(namelist);\r
}\r
\r