static int game_list_sel_change(SLIST *self) { SLIST *sl=self; DRIVER *dr; static char *shotsdir=DATA_DIRECTORY"/shots"; if (self->data_selected) { G_GAME_LIST *gl=sl->data_selected->data; if (gl->dir) { update_game_info(NULL); return TAKE_EVENT; } if (game_only==SDL_TRUE) { update_game_info(gl->dr); } else { char *filepath=alloca(strlen((char*)GUI_WIDGET(self)->pdata1)+strlen(gl->file)+1); sprintf(filepath,"%s/%s",(char*)GUI_WIDGET(self)->pdata1,gl->file); if ((dr=get_driver_for_zip(filepath))!=NULL) { update_game_info(dr); } else { update_game_info(NULL); } } } return TAKE_EVENT; }
DRIVER *dr_get_by_name(char *name) { char *zip=get_zip_name(name); DRIVER *dr=get_driver_for_zip(zip); free(zip); return dr; }
static LIST* create_list_from_dir(char *dir) { DIR *dir_p; G_GAME_LIST *t; struct dirent *dirent_p; char filename[strlen(dir)+256]; LIST *l=NULL; struct stat filestat; struct DIRENT **namelist; int nbf, i; /* if (dir[strlen(dir)-1]=='/') dir[strlen(dir)-1]=0; */ if ((nbf = scandir(dir, &namelist, NULL/*game_selection*/, my_alphasort )) != -1) { for (i = 0; i < nbf; i++) { #ifdef __QNXNTO__ if (strcmp(namelist[i]->d_name, "..") == 0) continue; else if (strcmp(namelist[i]->d_name, ".") == 0) continue; else if (stricmp(namelist[i]->d_name, "romrc.d") == 0) continue; else if (stricmp(namelist[i]->d_name, "shots") == 0) continue; #endif sprintf(filename, "%s/%s", dir, namelist[i]->d_name); lstat(filename, &filestat); if (S_ISDIR(filestat.st_mode)) { t=malloc(sizeof(G_GAME_LIST)); t->dir=malloc(strlen(namelist[i]->d_name)*sizeof(char)+2); sprintf(t->dir,"%s",namelist[i]->d_name); t->dr=NULL; t->file=NULL; l=list_prepend(l,t); } else if (game_only==SDL_TRUE) { DRIVER *dr; if ((dr=get_driver_for_zip(filename))!=NULL) { t=malloc(sizeof(G_GAME_LIST)); t->dir=NULL; t->file=strdup(namelist[i]->d_name); t->dr=dr; l=list_prepend(l,t); //printf("GAME %s\n",t->dr->longname); } } else { t=malloc(sizeof(G_GAME_LIST)); t->file=strdup(namelist[i]->d_name); t->dir=NULL; t->dr=NULL; l=list_prepend(l,t); //printf("FILE %s\n",t->file); } } } if (nbf==-1) { /* the dir is unreadable, we create pseudo dir . and .. */ t=malloc(sizeof(G_GAME_LIST)); t->dir=strdup(".."); t->dr=NULL; t->file=NULL; l=list_prepend(l,t); t=malloc(sizeof(G_GAME_LIST)); t->dir=strdup("."); t->dr=NULL; t->file=NULL; l=list_prepend(l,t); } return l; }