//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== quakefile_t *FindQuakeFilesInZip( char *zipfile, char *filter ) { unzFile uf; int err; unz_global_info gi; char filename_inzip[MAX_PATH]; unz_file_info file_info; int i; quakefile_t *qfiles, *lastqf, *qf; uf = unzOpen( zipfile ); err = unzGetGlobalInfo( uf, &gi ); if ( err != UNZ_OK ) { return NULL; } unzGoToFirstFile( uf ); qfiles = NULL; lastqf = NULL; for ( i = 0; i < gi.number_entry; i++ ) { err = unzGetCurrentFileInfo( uf, &file_info, filename_inzip, sizeof( filename_inzip ), NULL,0,NULL,0 ); if ( err != UNZ_OK ) { break; } ConvertPath( filename_inzip ); if ( FileFilter( filter, filename_inzip, false ) ) { qf = GetClearedMemory( sizeof( quakefile_t ) ); if ( !qf ) { Error( "out of memory" ); } memset( qf, 0, sizeof( quakefile_t ) ); strcpy( qf->pakfile, zipfile ); strcpy( qf->filename, zipfile ); strcpy( qf->origname, filename_inzip ); qf->zipfile = true; //memcpy( &buildBuffer[i].zipfileinfo, (unz_s*)uf, sizeof(unz_s)); memcpy( &qf->zipinfo, (unz_s*)uf, sizeof( unz_s ) ); qf->offset = 0; qf->length = file_info.uncompressed_size; qf->type = QuakeFileType( filename_inzip ); //add the file ot the list qf->next = NULL; if ( lastqf ) { lastqf->next = qf; } else { qfiles = qf;} lastqf = qf; } //end if unzGoToNextFile( uf ); } //end for unzClose( uf ); return qfiles; } //end of the function FindQuakeFilesInZip
STDMETHODIMP CUUEngine::QuickDecode(BSTR File2Decode, BSTR OutputPath, BOOL XFile, long *retVal) { Reset(); // Start with everything clear long rc; DLoad(File2Decode, &rc); if (rc != UURET_OK) // Load the source file { *retVal = rc; return(S_OK); // Couldn't load } MString prefix(OutputPath); // Make a copy of the Output Path string if (prefix.IsEmpty()) // No prefix string supplied GetTempPath(256, prefix.GetBuffer(256)); // Read the temporary path char trail = prefix[prefix.GetLength() - 1]; // Read the last character if (trail != ':' && trail != '\\') // Output path must end in slash or colon... prefix += "\\"; // Add the slash short maxIndex; get_DFCount(&maxIndex); // Read the maximum file number CComBSTR tb, tb1, bP, outname; prefix.ToBSTR(&bP); for (short row=0; row < maxIndex; row++) { get_DFileFlags(row, &rc); if (rc & UUFILE_OK) // Ready to decode { get_DFile(row, &tb); FileFilter(tb, &tb1); outname = bP; outname += tb1; DFileTo(row, outname, &rc); if (rc != UURET_OK) // Read the current { *retVal = rc; return(S_OK); } put_DFile(row, outname); // Return the full (filtered) path if (XFile) { if (XFList == NULL) XFList = new XFL(outname); else XFList->AddTail(outname); // User wants these files added to X list } } } *retVal = UURET_OK; // Got it! return S_OK; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== quakefile_t *FindQuakeFilesInPak( char *pakfile, char *filter ) { FILE *fp; dpackheader_t packheader; dsinpackfile_t *packfiles; dpackfile_t *idpackfiles; quakefile_t *qfiles, *lastqf, *qf; int numpackdirs, i; qfiles = NULL; lastqf = NULL; //open the pak file fp = fopen( pakfile, "rb" ); if ( !fp ) { Warning( "can't open pak file %s", pakfile ); return NULL; } //end if //read pak header, check for valid pak id and seek to the dir entries if ( ( fread( &packheader, 1, sizeof( dpackheader_t ), fp ) != sizeof( dpackheader_t ) ) || ( packheader.ident != IDPAKHEADER && packheader.ident != SINPAKHEADER ) || ( fseek( fp, LittleLong( packheader.dirofs ), SEEK_SET ) ) ) { fclose( fp ); Warning( "invalid pak file %s", pakfile ); return NULL; } //end if //if it is a pak file from id software if ( packheader.ident == IDPAKHEADER ) { //number of dir entries in the pak file numpackdirs = LittleLong( packheader.dirlen ) / sizeof( dpackfile_t ); idpackfiles = (dpackfile_t *) GetClearedMemory( numpackdirs * sizeof( dpackfile_t ) ); if ( !idpackfiles ) { Error( "out of memory" ); } //read the dir entry if ( fread( idpackfiles, sizeof( dpackfile_t ), numpackdirs, fp ) != numpackdirs ) { fclose( fp ); FreeMemory( idpackfiles ); Warning( "can't read the Quake pak file dir entries from %s", pakfile ); return NULL; } //end if fclose( fp ); //convert to sin pack files packfiles = (dsinpackfile_t *) GetClearedMemory( numpackdirs * sizeof( dsinpackfile_t ) ); if ( !packfiles ) { Error( "out of memory" ); } for ( i = 0; i < numpackdirs; i++ ) { strcpy( packfiles[i].name, idpackfiles[i].name ); packfiles[i].filepos = LittleLong( idpackfiles[i].filepos ); packfiles[i].filelen = LittleLong( idpackfiles[i].filelen ); } //end for FreeMemory( idpackfiles ); } //end if else //its a Sin pack file { //number of dir entries in the pak file numpackdirs = LittleLong( packheader.dirlen ) / sizeof( dsinpackfile_t ); packfiles = (dsinpackfile_t *) GetClearedMemory( numpackdirs * sizeof( dsinpackfile_t ) ); if ( !packfiles ) { Error( "out of memory" ); } //read the dir entry if ( fread( packfiles, sizeof( dsinpackfile_t ), numpackdirs, fp ) != numpackdirs ) { fclose( fp ); FreeMemory( packfiles ); Warning( "can't read the Sin pak file dir entries from %s", pakfile ); return NULL; } //end if fclose( fp ); for ( i = 0; i < numpackdirs; i++ ) { packfiles[i].filepos = LittleLong( packfiles[i].filepos ); packfiles[i].filelen = LittleLong( packfiles[i].filelen ); } //end for } //end else // for ( i = 0; i < numpackdirs; i++ ) { ConvertPath( packfiles[i].name ); if ( FileFilter( filter, packfiles[i].name, false ) ) { qf = GetClearedMemory( sizeof( quakefile_t ) ); if ( !qf ) { Error( "out of memory" ); } memset( qf, 0, sizeof( quakefile_t ) ); strcpy( qf->pakfile, pakfile ); strcpy( qf->filename, pakfile ); strcpy( qf->origname, packfiles[i].name ); qf->zipfile = false; qf->offset = packfiles[i].filepos; qf->length = packfiles[i].filelen; qf->type = QuakeFileType( packfiles[i].name ); //add the file ot the list qf->next = NULL; if ( lastqf ) { lastqf->next = qf; } else { qfiles = qf;} lastqf = qf; } //end if } //end for FreeMemory( packfiles ); return qfiles; } //end of the function FindQuakeFilesInPak
/*----------------------------------------------------------------------------------------------------------------------*/ void DisplayFiles() { GtkWidget *HBox,*But,*Label; struct dirent **NameList; gchar LStr[LONG_TEXT_FIELD+5],DStr[LONG_TEXT_FIELD+8],FullPath[NAME_MAX+255+5]; struct stat StatBuf; gint i,N,NRow,Row,Col; GList *Node; if (FileX->N) //Get rid of the existing table elements { Node=g_list_last(GTK_TABLE(FileX->Table)->children); //Glist is in reverse order! So this is the first element for (i=0;i<FileX->N;++i) { gtk_widget_destroy(((GtkTableChild *)Node->data)->widget); Node=g_list_previous(Node); } } N=scandir(FileX->Path,&NameList,NULL,alphasort); for (i=0,FileX->N=0;i<N;++i) //First collect the subdirectory names { if (FileX->N==MAX_DIR_ENTRIES) continue; //Terminate the list if there are too many entries if (NameList[i]->d_name[0]=='.') continue; //Avoid hidden directories sprintf(FullPath,"%s%c%s",FileX->Path,'/',NameList[i]->d_name); stat(FullPath,&StatBuf); if (S_ISDIR(StatBuf.st_mode)) { strcpy(FileX->Names[FileX->N],NameList[i]->d_name); ++FileX->N; } } for (i=0,FileX->Files=0;i<N;++i) //Now collect files names that match the file type { if (FileX->N==MAX_DIR_ENTRIES) continue; //Terminate the list if there are too many entries if (NameList[i]->d_name[0]=='.') continue; //Avoid hidden files sprintf(FullPath,"%s%c%s",FileX->Path,'/',NameList[i]->d_name); stat(FullPath,&StatBuf); if ( S_ISREG(StatBuf.st_mode) && FileFilter(NameList[i]->d_name,FileX->Mask) ) { strcpy(FileX->Names[FileX->N],NameList[i]->d_name); ++FileX->N; ++FileX->Files; } } NRow=FileX->N/3+((FileX->N%3)>0); gtk_table_resize(GTK_TABLE(FileX->Table),NRow,3); for (Row=0;Row<NRow;++Row) for (Col=0;Col<3;++Col) //Populate the table to display folders and files { i=3*Row+Col; if (i>=FileX->N) continue; But=gtk_button_new(); gtk_widget_set_usize(GTK_WIDGET(But),152,0); gtk_table_attach(GTK_TABLE(FileX->Table),But,Col,Col+1,Row,Row+1,GTK_FILL,GTK_SHRINK,0,0); gtk_signal_connect(GTK_OBJECT(But),"button_press_event",GTK_SIGNAL_FUNC(FSelect),GINT_TO_POINTER(i)); HBox=gtk_hbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(But),HBox); sprintf(FullPath,"%s%c%s",FileX->Path,'/',FileX->Names[i]); stat(FullPath,&StatBuf); if (S_ISDIR(StatBuf.st_mode)) //It is a directory { SetStyleRecursively(But,FolderStyle); AbbreviateFileName(LStr,FileX->Names[i],20); sprintf(DStr,"[%s]",LStr); Label=gtk_label_new(DStr); SetStyleRecursively(Label,FolderStyle); gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,3); } else //It is a file of matching file type { SetStyleRecursively(But,FileStyle); AbbreviateFileName(LStr,FileX->Names[i],20); Label=gtk_label_new(LStr); SetStyleRecursively(Label,FileStyle); gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,0); } } if (N>-1) free(NameList); gtk_widget_show_all(FileX->Table); }