void data_proc(t_file *dir) { dir->next = NULL; dir = rewind_lst(dir); if (no_perm(dir) && g_flags[FLAG_R] == 1 && g_flags[FLAG_T] == 1) rsort_date(dir); else if (g_flags[FLAG_R] == 1 && g_flags[FLAG_T] != 1) rsort_dir(dir); else if (no_perm(dir) && g_flags[FLAG_R] != 1 && g_flags[FLAG_T] == 1) sort_date(dir); else sort_dir(dir); if (g_flags[FLAG_RR] != 1) print_dir(dir, 0); else ft_recurs(dir); ft_free_dir_lst(dir); }
void auth_ticket_load(const char *tickets) { size_t n = 0; client_tickets = xxrealloc(client_tickets, sizeof(char *)); client_tickets[n] = NULL; if(tickets) { const char *start, *end; for(start = end = tickets; start < tickets + strlen(tickets); start = ++end) { while(*end != '\0' && *end != ',') end++; if(start == end) continue; char *value = xxmalloc(end - start + 1); memset(value, 0, end - start + 1); strncpy(value, start, end - start); debug(D_CHIRP, "adding %s", value); client_tickets = xxrealloc(client_tickets, sizeof(char *) * ((++n) + 1)); client_tickets[n - 1] = value; client_tickets[n] = NULL; } } else { /* populate a list with tickets in the current directory */ int i; char **list; sort_dir(".", &list, strcmp); for(i = 0; list[i]; i++) { if(strncmp(list[i], "ticket.", strlen("ticket.")) == 0 && (strlen(list[i]) == (strlen("ticket.") + (MD5_DIGEST_LENGTH << 1)))) { debug(D_CHIRP, "adding ticket %s", list[i]); client_tickets = xxrealloc(client_tickets, sizeof(char *) * ((++n) + 1)); client_tickets[n - 1] = strdup(list[i]); client_tickets[n] = NULL; } } sort_dir_free(list); } }
char *FileReq(char *dir, const char *ext) { static s8 *cwd=NULL; static s32 cursor_pos=1; static s32 first_visible; static s32 num_items=0; DIR *dirstream; struct dirent *direntry; s8 *path; struct stat item; static s32 row; s32 pathlength; s8 tmp_string[32]; s8 *selected; u32 keys; #define MENU_Y 90 #define MENU_LS MENU_Y+10 #define MENU_HEIGHT 12 if(dir!=NULL) cwd=dir; if(cwd==NULL) { sprintf(filereq_fullgamepath, "%s/", gamepath); cwd=filereq_fullgamepath; } for(;;) { keys = gp2x_joystick_read(); gp2x_video_RGB_clearscreen16(); backg(); //exems(); //gp2x_timer_delay(500000); //gp2x_printf(NULL, 0, 10, PSX4ALL_NAME " V " PSX4ALL_VERSION "." PSX4ALL_BUILD " By " PSX4ALL_BY); //gp2x_printf(NULL, 0, 20, PSX4ALL_CREDITS); //gp2x_printf(NULL, 0, 30, PSX4ALL_PORT); //gp2x_printf(NULL, 0, 40, PSX4ALL_OR); if( keys & GP2X_L ) { for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; gp2x_timer_delay(90); return NULL; } if(num_items==0) { s32 i2; dirstream=opendir(cwd); if(dirstream==NULL) { gp2x_printf(NULL, 0, 20, PSX4ALL_ER); return NULL; } while((direntry=readdir(dirstream))) { if( (ext == NULL && ((NULL == strstr(direntry->d_name, ".")) || (strlen(direntry->d_name) > 1 && 0 == strnicmp(direntry->d_name, "..", 2)) || (strlen(direntry->d_name) > 2 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-2), ".z", 2)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".iso", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".bin", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".img", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".znx", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".cbn", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".pbp", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".cue", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".psx", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".zip", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".mdf", 4))) ) || (ext != NULL && (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-strlen(ext)), ext, strlen(ext)))) ) { filereq_dir_items[num_items].name=(s8 *)malloc(strlen(direntry->d_name)+1); strcpy(filereq_dir_items[num_items].name, direntry->d_name); num_items++; if(num_items>1024) break; } } closedir(dirstream); for(i2=0; i2<num_items; i2++) { path=(s8 *)malloc(strlen(cwd)+strlen(filereq_dir_items[i2].name)+2); sprintf(path, PSX4ALL_SSR, cwd, filereq_dir_items[i2].name); if(!stat(path, &item)) { if(S_ISDIR(item.st_mode)) { filereq_dir_items[i2].type=0; } else { s32 len = strlen(filereq_dir_items[i2].name); filereq_dir_items[i2].type = 2; if (len >= 4) { if (!strnicmp(filereq_dir_items[i2].name+(len-2), ".Z", 2)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".bin", 4)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".ZNX", 4)) { filereq_dir_items[i2].type = 1; } } } } else { filereq_dir_items[i2].type=0; } free(path); } sort_dir(filereq_dir_items, num_items, 1); cursor_pos=0; first_visible=0; } gp2x_printf(NULL, 90, MENU_Y, cwd); if(keys & GP2X_DOWN) { if(cursor_pos<(num_items-1)) cursor_pos++; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible++; } else if(keys & GP2X_UP) { if(cursor_pos>0) cursor_pos--; if(cursor_pos<first_visible) first_visible--; } else if(keys & GP2X_LEFT) { if(cursor_pos>=10) cursor_pos-=10; else cursor_pos=0; if(cursor_pos<first_visible) first_visible=cursor_pos; } else if(keys & GP2X_RIGHT) { if(cursor_pos<(num_items-11)) cursor_pos+=10; else cursor_pos=num_items-1; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible=cursor_pos-(MENU_HEIGHT-1); } else if(keys & GP2X_B) { path=(s8 *)malloc(strlen(cwd) +strlen(filereq_dir_items[cursor_pos].name) +2); sprintf(path, PSX4ALL_SSR, cwd, filereq_dir_items[cursor_pos].name); for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; if(filereq_dir_items[cursor_pos].type==0) { pathlength=strlen(path); if( path[pathlength-1]=='.' && path[pathlength-2]=='/') { path[pathlength-2]='\0'; cwd=path; } else if(path[pathlength-1]=='.' && path[pathlength-2]=='.' && path[pathlength-3]=='/' ) { if( pathlength > 4 ) { s8* p = strrchr(path, '/'); p[0] = '\0'; p = strrchr(path, '/'); p[0] = '\0'; p = strrchr(path, '/'); p[1] = '\0'; cwd=path; } } else { if( path[0] == '/' && path[1] == '/' ) { cwd = path + 1; } else { cwd = path; } } } else { //gp2x_video_RGB_clearscreen16(); gp2x_printf(NULL, 10, 120, PSX4ALL_SL); gp2x_printf(NULL, 10, 130, PSX4ALL_STR, path); gp2x_printf(NULL, 10, 140, PSX4ALL_YN); gp2x_video_flip(); for(;;) { u32 keys = gp2x_joystick_read(); if( keys & GP2X_SELECT ) { return NULL; } if( keys & GP2X_START ) { char* p = strrchr(path, '/'); if( p != NULL ) { sprintf(CdromLabel, "%10.10s", p + 1); } return path; } gp2x_timer_delay(90); } } } row=0; while(row<num_items && row<MENU_HEIGHT) { if(row==(cursor_pos-first_visible)) { gp2x_printf(NULL, 90, MENU_LS+(10*row), PSX4ALL_ROW); selected=filereq_dir_items[row+first_visible].name; } if(filereq_dir_items[row+first_visible].type==0) { gp2x_printf(NULL, 90, MENU_LS+(10*row), "DIR "); } snprintf(tmp_string, 30, PSX4ALL_STR, filereq_dir_items[row+first_visible].name); gp2x_printf(NULL, 90+(10*6), MENU_LS+(10*row), tmp_string); row++; } while(row<MENU_HEIGHT) { row++; } gp2x_video_flip(); gp2x_timer_delay(75); if(keys & (GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_L|GP2X_R|GP2X_PUSH| GP2X_LEFT|GP2X_RIGHT|GP2X_UP|GP2X_DOWN) ) { gp2x_timer_delay(50); } } return NULL; }
char *FileReq(char *dir, const char *ext, char *result) { static char *cwd = NULL; static s32 cursor_pos = 1; static s32 first_visible; static s32 num_items = 0; DIR *dirstream; struct dirent *direntry; static s32 row; char tmp_string[41]; u32 keys; if (dir) ChDir(dir); cwd = GetCwd(); for (;;) { keys = key_read(); video_clear(); if (keys & KEY_SELECT) { FREE_LIST(); key_reset(); return NULL; } if (num_items == 0) { dirstream = opendir(cwd); if (dirstream == NULL) { port_printf(0, 20, "error opening directory"); return NULL; } // read directory entries while ((direntry = readdir(dirstream))) { s32 type = get_entry_type(cwd, direntry->d_name); // this is a very ugly way of only accepting a certain extension if ((type == 0 && strcmp(direntry->d_name, ".")) || check_ext(direntry->d_name) || (ext && (strlen(direntry->d_name) > 4 &&0 == strncasecmp(direntry->d_name + (strlen(direntry->d_name) - strlen(ext)), ext, strlen(ext))))) { // Hide ".." if at Unix root dir. Don't display Unix hidden files (.file). if ((!strcmp(direntry->d_name, "..") && strcmp(cwd, "/")) || direntry->d_name[0] != '.') { filereq_dir_items[num_items].name = (char *)malloc(strlen(direntry->d_name) + 1); strcpy(filereq_dir_items[num_items].name, direntry->d_name); filereq_dir_items[num_items].type = type; num_items++; if (num_items > 1024) break; } } } closedir(dirstream); sort_dir(filereq_dir_items, num_items); cursor_pos = 0; first_visible = 0; } // display current directory int len = strlen(cwd); if (len > 40) { strcpy(tmp_string, ".."); strcat(tmp_string, cwd + len - 38); port_printf(0, MENU_Y, tmp_string); } else port_printf(0, MENU_Y, cwd); if (keys & KEY_DOWN) { //down if (++cursor_pos >= num_items) { cursor_pos = 0; first_visible = 0; } if ((cursor_pos - first_visible) >= MENU_HEIGHT) first_visible++; } else if (keys & KEY_UP) { // up if (--cursor_pos < 0) { cursor_pos = num_items - 1; first_visible = cursor_pos - MENU_HEIGHT + 1; if (first_visible < 0) first_visible = 0; } if (cursor_pos < first_visible) first_visible--; } else if (keys & KEY_LEFT) { //left if (cursor_pos >= 10) cursor_pos -= 10; else cursor_pos = 0; if (cursor_pos < first_visible) first_visible = cursor_pos; } else if (keys & KEY_RIGHT) { //right if (cursor_pos < (num_items - 11)) cursor_pos += 10; else cursor_pos = num_items - 1; if ((cursor_pos - first_visible) >= MENU_HEIGHT) first_visible = cursor_pos - (MENU_HEIGHT - 1); } else if (keys & KEY_A) { // button 1 // directory selected if (filereq_dir_items[cursor_pos].type == 0) { strcat(cwd, "/"); strcat(cwd, filereq_dir_items[cursor_pos].name); ChDir(cwd); cwd = GetCwd(); FREE_LIST(); key_reset(); } else { sprintf(result, "%s/%s", cwd, filereq_dir_items[cursor_pos].name); if (dir) strcpy(dir, cwd); video_clear(); port_printf(16 * 8, 120, "LOADING"); video_flip(); FREE_LIST(); key_reset(); return result; } } else if (keys & KEY_B) { cursor_pos = 0; first_visible = 0; key_reset(); } // display directory contents row = 0; while (row < num_items && row < MENU_HEIGHT) { if (row == (cursor_pos - first_visible)) { // draw cursor port_printf(MENU_X + 16, MENU_LS + (10 * row), "-->"); } if (filereq_dir_items[row + first_visible].type == 0) port_printf(MENU_X, MENU_LS + (10 * row), "DIR"); int len = strlen(filereq_dir_items[row + first_visible].name); if (len > 32) { snprintf(tmp_string, 16, "%s", filereq_dir_items[row + first_visible].name); strcat(tmp_string, ".."); strcat(tmp_string, &filereq_dir_items[row + first_visible].name[len - 15]); } else snprintf(tmp_string, 33, "%s", filereq_dir_items[row + first_visible].name); port_printf(MENU_X + (8 * 5), MENU_LS + (10 * row), tmp_string); row++; } while (row < MENU_HEIGHT) row++; video_flip(); timer_delay(75); if (keys & (KEY_A | KEY_B | KEY_X | KEY_Y | KEY_L | KEY_R | KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN)) timer_delay(50); } return NULL; }
char *filerequest(char *dir) { static const char *cwd=NULL; static int num_items=0; struct dir_item dir_items[1024]; struct stat item; static int fcursor_pos; static int first_visible; static int row, column; DIR *dirstream; struct dirent *direntry; char *path; uint16 bg,fg; int i; int pathlength; const char *blank_line=" "; int menu_x=5; int menu_y=3; int menu_height=25; static int is_moving=0; static int threshold=10; static int stepping=2; uint8 menu_bg=14; uint8 menu_fg=6; uint8 menu_selbg=7; uint8 menu_selfg=6; if(dir!=NULL) cwd=dir; if(cwd==NULL) cwd="frodo"; if(num_items==0) { dirstream=opendir(cwd); if(dirstream==NULL) { button_state&=~X_PRESSED; printf("error opening directory %s\n", cwd); return (char *)-1; } // read directory entries while(direntry=readdir(dirstream)) { dir_items[num_items].name=(char *)malloc( strlen(direntry->d_name)+1); strcpy(dir_items[num_items].name, direntry->d_name); printf("found file -%s-\n", direntry->d_name); num_items++; if(num_items>1024) break; } closedir(dirstream); // get entry types for(i=0; i<num_items; i++) { path=(char *)malloc(strlen(cwd) +strlen(dir_items[i].name) +2); sprintf(path, "%s/%s", cwd, dir_items[i].name); if(!stat(path, &item)) { if(S_ISDIR(item.st_mode)) { dir_items[i].type=0; } else { dir_items[i].type=1; } } else { dir_items[i].type=0; } free(path); } sort_dir(dir_items, num_items, 1); fcursor_pos=0; first_visible=0; } // display current directory text_out8((uint8 *)gp.pixels, cwd, menu_bg, menu_fg, 5, menu_y-1, 0); // display directory contents row=0; while(row<num_items //&& row<(DISPLAY_HEIGHT/FONT_HEIGHT)) { && row<menu_height) { column=menu_x; if(row==(fcursor_pos-first_visible)) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } if(dir_items[row+first_visible].type==0) { text_out8((uint8 *)gp.pixels, "<DIR> ", bg, fg, column, menu_y+row, 0); } else { text_out8((uint8 *)gp.pixels, " ", bg, fg, column, menu_y+row, 0); } column+=6; text_out8((uint8 *)gp.pixels, blank_line, bg, fg, column, menu_y+row, 0); text_out8((uint8 *)gp.pixels, dir_items[row+first_visible].name, bg, fg, column, menu_y+row, 0); row++; } while(row<menu_height) { text_out8((uint8 *)gp.pixels, " ", menu_bg, menu_fg, menu_x, menu_y+row, 0); text_out8((uint8 *)gp.pixels, blank_line, menu_bg, menu_fg, column, menu_y+row, 0); row++; } if(button_state&DOWN_PRESSED) { if(is_moving==0||((is_moving>threshold)&&(is_moving%stepping==0))) { if(fcursor_pos<(num_items-1)) fcursor_pos++; if((fcursor_pos-first_visible) >=menu_height) first_visible++; } is_moving++; } else if(button_state&UP_PRESSED) { if(is_moving==0||((is_moving>threshold)&&(is_moving%stepping==0))) { if(fcursor_pos>0) fcursor_pos--; if(fcursor_pos<first_visible) first_visible--; } is_moving++; } else { is_moving=0; } if(button_state&X_PRESSED) { button_state&=~X_PRESSED; path=(char *)malloc(strlen(cwd) +strlen(dir_items[fcursor_pos].name) +2); sprintf(path, "%s/%s", cwd, dir_items[fcursor_pos].name); for(i=0; i<num_items; i++) free(dir_items[i].name); num_items=0; if(dir_items[fcursor_pos].type==0) { // directory selected pathlength=strlen(path); if(path[pathlength-1]=='.' // check for . selected && path[pathlength-2]=='/') { path[pathlength-2]='\0'; return path; } else if(path[pathlength-1]=='.' // check for .. selected && path[pathlength-2]=='.' && path[pathlength-3]=='/' &&pathlength>8) { for(i=4; path[pathlength-i]!='/'; i++); path[pathlength-i]='\0'; if(strlen(path)<=5) { path[5]='/'; path[6]='\0'; } cwd=path; } else { cwd=path; } } else { // file selected printf("selected file -%s-\n", path); return path; } } else if(button_state&O_PRESSED) { return (char *)-1; } return NULL; }
char *FileReq(char *dir, const char *ext) { static s8 *cwd=NULL; static s32 cursor_pos=1; static s32 first_visible; static s32 num_items=0; DIR *dirstream; struct dirent *direntry; s8 *path; struct stat item; static s32 row; s32 pathlength; s8 tmp_string[32]; s8 *selected; u32 keys; #define MENU_Y 90 #define MENU_LS MENU_Y+10 #define MENU_HEIGHT 12 if(dir!=NULL) cwd=dir; if(cwd==NULL) { sprintf(filereq_fullgamepath, "%s/", gamepath); cwd=filereq_fullgamepath; } for(;;) { keys = gp2x_joystick_read(); gp2x_video_RGB_clearscreen16(); gp2x_printf(NULL, 0, 10, "psx4all-dingoo http://github.com/uli/psx4all-dingoo"); gp2x_printf(NULL, 0, 20, "CREDITS: UNAI - ZODTTD - HLIDE - CHUI - TINNUS"); gp2x_printf(NULL, 0, 30, "Dingoo/MIPS port by Ulrich Hecht"); gp2x_printf(NULL, 0, 40, "CHOOSE A GAME OR PRESS L TO EXIT"); if( keys & GP2X_L ) { for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; gp2x_timer_delay(100); return NULL; } if(num_items==0) { s32 i2; dirstream=opendir(cwd); if(dirstream==NULL) { gp2x_printf(NULL, 0, 20, "error opening directory"); return NULL; } // read directory entries while((direntry=readdir(dirstream))) { // this is a very ugly way of only accepting a certain extension if( (ext == NULL && ((NULL == strstr(direntry->d_name, ".")) || (strlen(direntry->d_name) > 1 && 0 == strnicmp(direntry->d_name, "..", 2)) || (strlen(direntry->d_name) > 2 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-2), ".z", 2)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".iso", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".bin", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".img", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".znx", 4)) || (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-4), ".cbn", 4))) ) || (ext != NULL && (strlen(direntry->d_name) > 4 && 0 == strnicmp(direntry->d_name+(strlen(direntry->d_name)-strlen(ext)), ext, strlen(ext)))) ) { filereq_dir_items[num_items].name=(s8 *)malloc(strlen(direntry->d_name)+1); strcpy(filereq_dir_items[num_items].name, direntry->d_name); num_items++; if(num_items>1024) break; } } closedir(dirstream); // get entry types for(i2=0; i2<num_items; i2++) { path=(s8 *)malloc(strlen(cwd)+strlen(filereq_dir_items[i2].name)+2); sprintf(path, "%s/%s", cwd, filereq_dir_items[i2].name); if(!stat(path, &item)) { if(S_ISDIR(item.st_mode)) { filereq_dir_items[i2].type=0; } else { s32 len = strlen(filereq_dir_items[i2].name); filereq_dir_items[i2].type = 2; /* Not Used */ if (len >= 4) { if (!strnicmp(filereq_dir_items[i2].name+(len-2), ".Z", 2)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".bin", 4)) { filereq_dir_items[i2].type = 1; } if (!strnicmp(filereq_dir_items[i2].name+(len-4), ".ZNX", 4)) { filereq_dir_items[i2].type = 1; } } } } else { filereq_dir_items[i2].type=0; } free(path); } sort_dir(filereq_dir_items, num_items, 1); cursor_pos=0; first_visible=0; } // display current directory gp2x_printf(NULL, 80, MENU_Y, cwd); if(keys & GP2X_DOWN) { //down if(cursor_pos<(num_items-1)) cursor_pos++; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible++; } else if(keys & GP2X_UP) { // up if(cursor_pos>0) cursor_pos--; if(cursor_pos<first_visible) first_visible--; } else if(keys & GP2X_LEFT) { //left if(cursor_pos>=10) cursor_pos-=10; else cursor_pos=0; if(cursor_pos<first_visible) first_visible=cursor_pos; } else if(keys & GP2X_RIGHT) { //right if(cursor_pos<(num_items-11)) cursor_pos+=10; else cursor_pos=num_items-1; if((cursor_pos-first_visible)>=MENU_HEIGHT) first_visible=cursor_pos-(MENU_HEIGHT-1); } else if(keys & GP2X_B) // button 1 { //s32 i; path=(s8 *)malloc(strlen(cwd) +strlen(filereq_dir_items[cursor_pos].name) +2); sprintf(path, "%s/%s", cwd, filereq_dir_items[cursor_pos].name); for(int i=0; i<num_items; i++) if (filereq_dir_items[i].name) { free(filereq_dir_items[i].name); filereq_dir_items[i].name = NULL; } num_items=0; if(filereq_dir_items[cursor_pos].type==0) { // directory selected pathlength=strlen(path); if( path[pathlength-1]=='.' && path[pathlength-2]=='/') // check for . selected { path[pathlength-2]='\0'; cwd=path; } else if(path[pathlength-1]=='.' && path[pathlength-2]=='.' && path[pathlength-3]=='/' ) // check for .. selected { if( pathlength > 4 ) { s8* p = strrchr(path, '/'); // PATH: /x/y/z/..[/] p[0] = '\0'; p = strrchr(path, '/'); // PATH: /x/y/z[/]../ p[0] = '\0'; p = strrchr(path, '/'); // PATH: /x/y[/]z/../ p[1] = '\0'; // PATH: /x/y/ cwd=path; } } else { // dirty fix if( path[0] == '/' && path[1] == '/' ) { cwd = path + 1; // Add 1 to ignore the first slash. This occurs when traversing to root dir. } else { cwd = path; } } } else { gp2x_video_RGB_clearscreen16(); gp2x_printf(NULL, 10, 120, "ARE YOU SURE YOU WANT TO SELECT..."); gp2x_printf(NULL, 10, 130, "%s", path); gp2x_printf(NULL, 10, 140, "PRESS START FOR YES OR SELECT FOR NO"); gp2x_video_flip(); // file selected check if it was intended for(;;) { u32 keys = gp2x_joystick_read(); if( keys & GP2X_SELECT ) { return NULL; } if( keys & GP2X_START ) { /* Store the 10 character filename in CdromLabel so save states work */ char* p = strrchr(path, '/'); if( p != NULL ) { sprintf(CdromLabel, "%10.10s", p + 1); } return path; } gp2x_timer_delay(100); } } } // display directory contents row=0; while(row<num_items && row<MENU_HEIGHT) { if(row==(cursor_pos-first_visible)) { // draw cursor gp2x_printf(NULL, 80, MENU_LS+(10*row), "------>"); selected=filereq_dir_items[row+first_visible].name; } if(filereq_dir_items[row+first_visible].type==0) { gp2x_printf(NULL, 80, MENU_LS+(10*row), "DIR "); } snprintf(tmp_string, 30, "%s", filereq_dir_items[row+first_visible].name); gp2x_printf(NULL, 80+(10*6), MENU_LS+(10*row), tmp_string); row++; } while(row<MENU_HEIGHT) { row++; } gp2x_video_flip(); gp2x_timer_delay(75); if(keys & (GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_L|GP2X_R|GP2X_PUSH| GP2X_LEFT|GP2X_RIGHT|GP2X_UP|GP2X_DOWN) ) { gp2x_timer_delay(50); } } return NULL; }