DRIVER *get_driver_for_zip(char *zip) { unzFile *gz; int i; char zfilename[256]; char *t; LIST *zip_list=NULL,*l,*zl; int res; /* first, we check if it a zip */ gz = unzOpen(zip); if (gz==NULL) { return NULL; } //printf("Get driver for %s\n",zip); /* now, we create a list containing the content of the zip */ i=0; unzGoToFirstFile(gz); do { unzGetCurrentFileInfo(gz,NULL,zfilename,256,NULL,0,NULL,0); //printf("List zip %s\n",zfilename); t=strrchr(zfilename,'.'); if (! ( (strncasecmp(zfilename,"n",1)==0 && strlen(zfilename)<=12 )|| (t && (strcasecmp(t,".rom")==0 || strcasecmp(t,".bin")==0) ) ) ) i++; if (i>10) { //printf("More than 10 file are not rom....\n"); /* more than 10 files are not rom.... must not be a valid romset 10 files should be enough */ list_erase_all(zip_list,free_ziplist_item); return NULL; } zip_list=list_prepend(zip_list,strdup(zfilename)); } while (unzGoToNextFile(gz)!=UNZ_END_OF_LIST_OF_FILE); /* now we check every driver to see if it match the zip content */ for (l=driver_list;l;l=l->next) { DRIVER *dr=l->data; if (check_driver_for_zip(dr,gz,zip_list)==SDL_TRUE) { unzClose(gz); list_erase_all(zip_list,free_ziplist_item); return dr; } } list_erase_all(zip_list,free_ziplist_item); unzClose(gz); /* not match found */ return NULL; }
static int game_list_double_click(SLIST* self) { SLIST *sl=self; if (sl->data_selected) { G_GAME_LIST *gl=sl->data_selected->data; if (gl->dir) { char *path=GUI_WIDGET(self)->pdata1; if (strcmp(gl->dir,".")==0) return TAKE_EVENT; if (strcmp(gl->dir,"..")==0) { char *t; if (strcmp(path,"/")==0) return TAKE_EVENT; /* if (path[strlen(path)-1]=='/') path[strlen(path)-1]=0; printf("PATH2=%s\n",path); */ /* t=strrchr(path,'/'); if (t) t[0]=0; */ t=strrchr(path,'/'); if (t) t[0]=0; if (strcmp(path,"")==0) sprintf(path,"/"); } else { if (path) path=realloc(path,strlen(path)+strlen(gl->dir)+2); else path=strdup("/"); GUI_WIDGET(self)->pdata1=path; if (strcmp(path,"/")==0) sprintf(path,"/%s",gl->dir); else sprintf(path,"%s/%s",path,gl->dir); //printf("Change dir %s path=%s\n",gl->dir,path); } /* recreate list */ list_erase_all(GUI_SLIST(sl)->l,NULL); GUI_SLIST(sl)->l=create_list_from_dir(path); gui_slist_update(GUI_SLIST(sl)); sl->data_selected=NULL; } else if (gl->dr) { char *filepath=alloca(strlen((char*)GUI_WIDGET(self)->pdata1)+strlen(gl->file)+1); sprintf(filepath,"%s/%s",(char*)GUI_WIDGET(self)->pdata1,gl->file); printf("Load game %s,%s\n",filepath,gl->dr->longname); if (init_game(filepath)) return QUIT_EVENT; else return TAKE_EVENT; } 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); printf("Should try to load file %s %s\n",filepath,gl->file); if (init_game(filepath)) return QUIT_EVENT; else return TAKE_EVENT; } } return TAKE_EVENT; }