/* Load a GtkTreeModel after re-scanning directories. */ void rombrowser_refresh(unsigned int roms, unsigned short clear) { int arrayroms; GtkTreeModel* model; /* If clear flag is set, clear the models. */ if(clear) { model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romFullList)); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_MainWindow.romFullList)); gtk_tree_selection_select_all(selection); gtk_list_store_clear(GTK_LIST_STORE(model)); model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romDisplay)); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_MainWindow.romDisplay)); gtk_tree_selection_select_all(selection); gtk_list_store_clear(GTK_LIST_STORE(model)); } model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romFullList)); arrayroms = gtk_tree_model_iter_n_children(model, NULL); /* If there are currently more ROMs in cache than in the rombrowser, add them. */ if(roms>arrayroms) { gboolean fullpaths; GtkTreeIter* iter = (GtkTreeIter*)malloc(sizeof(GtkTreeIter)); char *country, *goodname, *usercomments, *md5hash, *crc1, *crc2, *internalname, *savetype, *players, *size, *compressiontype, *imagetype, *cicchip, *rumble; char* filename = NULL; /* Needs to be NULLed if fullpaths and zero roms are updated, for free. */ GdkPixbuf* flag; GdkPixbuf* status[5]; unsigned int romcounter; int counter; country = (char*)calloc(32, sizeof(char)); md5hash = (char*)calloc(33, sizeof(char)); crc1 = (char*)calloc(9, sizeof(char)); crc2 = (char*)calloc(9, sizeof(char)); savetype = (char*)calloc(16, sizeof(char)); players = (char*)calloc(16, sizeof(char)); size = (char*)calloc(16, sizeof(char)); compressiontype = (char*)calloc(16, sizeof(char)); imagetype = (char*)calloc(32, sizeof(char)); cicchip = (char*)calloc(16, sizeof(char)); rumble = (char*)calloc(8, sizeof(char)); if(iter==NULL||country==NULL||md5hash==NULL||crc1==NULL||crc2==NULL||size==NULL||compressiontype==NULL||imagetype==NULL||cicchip==NULL) { fprintf(stderr, "%s, %d: Out of memory!\n", __FILE__, __LINE__); return; } fullpaths = config_get_bool("RomBrowserShowFullPaths", FALSE); cache_entry* entry; entry = g_romcache.top; /* Advance cache pointer. */ for(romcounter=0; romcounter < arrayroms; ++romcounter) { entry = entry->next; if(entry==NULL) return; } for(romcounter=0; (romcounter < roms) && (entry != NULL); ++romcounter) { countrycodestring(entry->countrycode, country); countrycodeflag(entry->countrycode, &flag); goodname = entry->inientry->goodname; for(counter = 0; counter < 5; ++counter) { if(entry->inientry->status>counter) status[counter] = star; else status[counter] = staroff; } usercomments = entry->usercomments; if(fullpaths) filename = entry->filename; else filename = filefrompath(entry->filename); for(counter = 0; counter < 16; ++counter) sprintf(md5hash+counter*2, "%02X", entry->md5[counter]); sprintf(crc1, "%08X", entry->crc1); sprintf(crc2, "%08X", entry->crc2); internalname=entry->internalname; savestring(entry->inientry->savetype, savetype); playersstring(entry->inientry->players, players); sprintf(size, "%.1f MBits", (float)(entry->romsize / (float)0x20000)); compressionstring(entry->compressiontype, compressiontype); imagestring(entry->imagetype, imagetype); cicstring(entry->cic, cicchip); rumblestring(entry->inientry->rumble, rumble); /* Actually add entries to models. */ model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romFullList)); gtk_list_store_append(GTK_LIST_STORE(model), iter); gtk_list_store_set(GTK_LIST_STORE(model), iter, 0, country, 1, goodname, 2, NULL, 3, usercomments, 4, filename, 5, md5hash, 6, crc1, 7, crc2, 8, internalname, 9, savetype, 10, players, 11, size, 12, compressiontype, 13, imagetype, 14, cicchip, 15, rumble, 16, status[0], 17, status[1], 18, status[2], 19, status[3], 20, status[4], 21, flag, 22, entry, -1); model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romDisplay)); gtk_list_store_append(GTK_LIST_STORE(model), iter); gtk_list_store_set(GTK_LIST_STORE(model), iter, 0, country, 1, goodname, 2, NULL, 3, usercomments, 4, filename, 5, md5hash, 6, crc1, 7, crc2, 8, internalname, 9, savetype, 10, players, 11, size, 12, compressiontype, 13, imagetype, 14, cicchip, 15, rumble, 16, status[0], 17, status[1], 18, status[2], 19, status[3], 20, status[4], 21, flag, 22, entry, -1); /*printf("Added: %s\n", goodname);*/ entry = entry->next; } free(country); free(md5hash); free(crc1); free(crc2); free(savetype); free(players); free(size); free(compressiontype); free(imagetype); free(cicchip); free(rumble); if(!fullpaths) { if(filename!=NULL) free(filename); } free(iter); /* Do an initial sort. */ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), g_MainWindow.romSortColumn, rombrowser_compare, (gpointer)NULL, (gpointer)NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), g_MainWindow.romSortColumn, g_MainWindow.romSortType); gtk_tree_view_set_model(GTK_TREE_VIEW(g_MainWindow.romDisplay), model); } }
boolean pathtofilespec ( bigstring bspath, ptrfilespec fs ) { // // 2010-01-24 creedon: fix for relative paths not working on mac, // bsfullpath was ending up with :: in it as well as // the full path to the application, see initfsdefault // function // // 2009-08-30 aradke: refactored mac version to make it easier to understand. // fixed bug where a bspath containing a non-existing volume name was accepted as valid, // e.g. filespec("foobar:"), thus deviating from previous behaviour. // // 2006-10-16 creedon: for Mac, FSRef-ized // // 5.0d8 dmb: clear fs first thing // // 2.1b2 dmb: use new fsdefault for building filespec. note that if bspath // isn't a partial path, the vref and dirid will be ignored. // // 2.1b2 dmb: added special case for empty string. also, added drive // number interpretation here. // // 1993-06-11 dmb: if FSMakeFSSpec returns fnfErr, the spec is cool (but // file doesn't exist) // // 1991-012-17 dmb: dont append path to default directory if it's a full // path // // 1991-07-05 dmb: use FSMakeFSSpec if it's available. since it only // returns noErr if the file exists, and we want to handle // non-existant files, we don't give up right away. // #ifdef MACVERSION FSRef fsr; bigstring bspathtmp, bsfullpath, bsfile, bsfolder; short ix = 1; boolean flvolume = false; #endif #ifdef WIN95VERSION bigstring bsfolder; #endif clearbytes ( fs, sizeof ( *fs ) ); if ( isemptystring ( bspath ) ) return ( true ); #ifdef MACVERSION // create cleaned-up full path representation of our input suitable for pathtosref copystring ( bspath, bspathtmp ); cleanendoffilename ( bspathtmp ); if ( scanstring ( ':', bspath, &ix ) && ( ix > 1 ) ) { // contains a colon but doesn't start with one, so it must be a full path if ( ix == stringlength ( bspath ) ) // the colon we found is the last char, so bspath is a volume name flvolume = true; copystring ( bspathtmp, bsfullpath ); } else { // it's a partial path, prefix with default directory (see initfsdefault) if ( ! filespectopath ( &fsdefault, bsfullpath ) ) // get path of default directory return ( false ); // delete first path separator if partial path begins with one because bsfullpath always ends with one if ( bspathtmp [ 1 ] == chpathseparator ) deletefirstchar ( bspathtmp ); pushstring ( bspathtmp, bsfullpath ); // append partial path } // now see if the full path resolves if ( pathtofsref ( bsfullpath, &fsr ) == noErr ) { return ( macmakefilespec ( &fsr, fs ) == noErr ); } // full path did not resolve but we actually only require the parent folder to exist if ( ! flvolume ) { // volumes don't have a parent folder filefrompath ( bsfullpath, bsfile ); folderfrompath ( bsfullpath, bsfolder ); if ( pathtofsref ( bsfolder, &fsr ) == noErr ) { clearfilespec ( fs ); fs->ref = fsr; bigstringtofsname ( bsfile, &fs->name ); return ( true ); } } return ( false ); #endif #ifdef WIN95VERSION copystring (bspath, fsname (fs)); folderfrompath (bspath, bsfolder); if ((isemptystring (bsfolder)) && (! fileisvolume(fs))) { filegetdefaultpath (fs); pushstring (bspath, fsname (fs)); } nullterminate (fsname (fs)); return (true); #endif } // pathtofilespec