/* Try locate the file szFileName in the zipfile. For the iCaseSensitivity signification, see unzipStringFileNameCompare return value : UNZ_OK if the file is found. It becomes the current file. UNZ_END_OF_LIST_OF_FILE if the file is not found */ extern int ZEXPORT unzLocateFile(unzFile file,const char *szFileName, int iCaseSensitivity,int iIgnorePaths, char *actual_filename) { unz_s *s; int err,match_ok,n,patlen; const char *p1,*p2; uLong num_fileSaved; uLong pos_in_central_dirSaved; char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; if (file==NULL) return UNZ_PARAMERROR; if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) return UNZ_PARAMERROR; p1 = (iIgnorePaths) ? basename(szFileName) : szFileName; patlen = (*p1=='*') ? strlen(p1)-1 : 0; s = (unz_s*) file; if (!s->current_file_ok) return UNZ_END_OF_LIST_OF_FILE; num_fileSaved = s->num_file; pos_in_central_dirSaved = s->pos_in_central_dir; err = unzGoToFirstFile(file); while (err == UNZ_OK) { unzGetCurrentFileInfo(file,NULL,szCurrentFileName, sizeof(szCurrentFileName)-1,NULL,0,NULL,0); p2 = (iIgnorePaths) ? basename(szCurrentFileName) : szCurrentFileName; if (patlen>0) { n = strlen(p2); match_ok = (n>patlen && lstrcmpi(p2+n-patlen,p1+1)==0); } else match_ok = (unzStringFileNameCompare(p2,p1,iCaseSensitivity)==0); if (match_ok) { if (actual_filename) strcpy(actual_filename,szCurrentFileName); return UNZ_OK; } err = unzGoToNextFile(file); } s->num_file = num_fileSaved ; s->pos_in_central_dir = pos_in_central_dirSaved ; return err; }
static void vfsInitPakFile(const char *filename) { unz_global_info gi; unzFile uf; guint32 i; int err; uf = unzOpen(filename); if(uf == NULL) return; g_unzFiles = g_slist_append(g_unzFiles, uf); err = unzGetGlobalInfo(uf, &gi); if(err != UNZ_OK) return; unzGoToFirstFile(uf); Sys_Printf("VFS Init: %s (pk3)\n", filename); for(i = 0; i < gi.number_entry; i++) { char filename_inzip[NAME_MAX]; unz_file_info file_info; VFS_PAKFILE *file; err = unzGetCurrentFileInfo(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); if(err != UNZ_OK) break; file = (VFS_PAKFILE *) safe_malloc(sizeof(VFS_PAKFILE)); g_pakFiles = g_slist_append(g_pakFiles, file); vfsFixDOSName(filename_inzip); g_strdown(filename_inzip); file->name = strdup(filename_inzip); file->size = file_info.uncompressed_size; file->zipfile = uf; memcpy(&file->zipinfo, uf, sizeof(unz_s)); if((i + 1) < gi.number_entry) { err = unzGoToNextFile(uf); if(err != UNZ_OK) break; } } }
void UnzipBase::getAllFilenames(vector<wcs>& array_filename) const { if(!_handle) return; int ret; for(ret=unzGoToFirstFile(_handle);ret==UNZ_OK;ret=unzGoToNextFile(_handle)) { char filename[4096]; if(unzGetCurrentFileInfo(_handle,0,filename,(unsigned long)sizeof(filename),0,0,0,0)!=UNZ_OK) continue; filename[4095]=0; array_filename.push_back(MBSTOWCS(filename)); } }
SEXP R_unzGoToNextFile(SEXP r_r274) { SEXP r_ans = R_NilValue; unzFile r274 ; int ans ; r274 = DEREF_REF_PTR_CLASS( r_r274 , unzFile, unzContent ) ; ans = unzGoToNextFile ( r274 ) ; r_ans = ScalarInteger( ans ) ; return(r_ans); }
int UnzipGetData( void *zFile, unsigned char *buffer, size_t bytestoread ) { int zStatus; zStatus = unzReadCurrentFile( zFile , buffer, bytestoread ); if ( zStatus <= 0 ) { unzCloseCurrentFile( zFile ); if ( unzGoToNextFile( zFile ) == UNZ_OK ) { if ( unzOpenCurrentFile( zFile ) == UNZ_OK ) zStatus = UnzipGetData( zFile, buffer, bytestoread ); } } return zStatus; }
bool ZipFile::LoadList() { ClearList(); if(!SwitchMode(ZipFile::OPEN)) return false; int ret = unzGoToFirstFile(uzFile); if(ret != UNZ_OK) return false; char filename[1024]; unz_file_info cur_file_info; RealArchiveItemCount = 0; do { if(unzGetCurrentFileInfo(uzFile, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) == UNZ_OK) { bool isDir = false; if(filename[strlen(filename)-1] == '/') { isDir = true; filename[strlen(filename)-1] = '\0'; } int strlength = strlen(filename)+1; ArchiveFileStruct * CurArcFile = new ArchiveFileStruct; CurArcFile->filename = new char[strlength]; strcpy(CurArcFile->filename, filename); CurArcFile->length = cur_file_info.uncompressed_size; CurArcFile->comp_length = cur_file_info.compressed_size; CurArcFile->isdir = isDir; CurArcFile->fileindex = RealArchiveItemCount; CurArcFile->ModTime = (u64) cur_file_info.dosDate; CurArcFile->archiveType = ZIP; ZipStructure.push_back(CurArcFile); } ++RealArchiveItemCount; } while(unzGoToNextFile(uzFile) == UNZ_OK); PathControl(); return true; }
/*! \brief Gets a list of files stored in the zip archive. \param[out] container StringContainer used to store the list of file in the zip archive. \return Returns dmz::True if the container was successfully populated. Returns dmz::False if there is no open zip archive open. */ dmz::Boolean dmz::ReaderZip::get_file_list (StringContainer &container) const { Boolean result (False); if (_state.zf) { result = True; int value = unzGoToFirstFile (_state.zf); while (result && (UNZ_OK == value)) { unz_file_info info; const int Found = unzGetCurrentFileInfo (_state.zf, &info, 0, 0, 0, 0, 0, 0); if (Found == UNZ_OK && (info.size_filename > 0)) { char *buffer = new char[info.size_filename + 1]; if (buffer) { buffer[0] = '\0'; if (UNZ_OK == unzGetCurrentFileInfo ( _state.zf, 0, // info struct buffer, info.size_filename, 0, 0, // extra field 0, 0)) { // comment field buffer[info.size_filename] = '\0'; container.add (buffer); } delete []buffer; buffer = 0; } } else { result = _state.zip_error (Found); } value = unzGoToNextFile (_state.zf); } } return result; }
struct VDirEntry* _vdzListNext(struct VDir* vd) { struct VDirZip* vdz = (struct VDirZip*) vd; if (!vdz->hasNextFile) { return 0; } unz_file_info64 info; int status = unzGetCurrentFileInfo64(vdz->z, &info, vdz->dirent.name, sizeof(vdz->dirent.name), 0, 0, 0, 0); if (status < 0) { return 0; } vdz->dirent.fileSize = info.uncompressed_size; if (unzGoToNextFile(vdz->z) == UNZ_END_OF_LIST_OF_FILE) { vdz->hasNextFile = false; } return &vdz->dirent.d; }
bool MFFileZipFile_FindNext(MFFind *pFind, MFFindData *pFindData) { unzFile zipFile = (unzFile)pFind->pMount->pFilesysData; int err = unzGoToNextFile(zipFile); if(err != UNZ_OK) return false; unz_file_info fileInfo; unzGetCurrentFileInfo(zipFile, &fileInfo, pFindData->pFilename, sizeof(pFindData->pFilename), NULL, 0, NULL, 0); pFindData->attributes = 0; pFindData->fileSize = fileInfo.uncompressed_size; return true; }
int zip_findnext(struct zip_find_t *file) { if (zipfile && zip_mode == ZIP_READOPEN) { if (unzGoToNextFile(zipfile) == UNZ_OK) { unz_file_info info; unzGetCurrentFileInfo(zipfile, &info, file->name, MAX_PATH, NULL, 0, NULL, 0); file->length = info.uncompressed_size; file->crc32 = info.crc; return 1; } } return 0; }
/****************************************************************************** *** Description *** Creates a list of file names inside a zip that matches a given *** extension. *** *** Arguments *** zipName - Name of zip file *** ext - Extension to check *** count - Output for number of matching files in zip file. *** *** Return *** 1 if files with the given extension exists in the zip file, *** 0 otherwise. *** ******************************************************************************* */ char* zipGetFileList(const char* zipName, const char* ext, int* count) { char tempName[256]; char extension[8]; unzFile zip; unz_file_info info; char* fileArray = NULL; int totalLen = 0; int status; *count = 0; zip = unzOpen(zipName); if (!zip) { return 0; } strcpy(extension, ext); toLower(extension); status = unzGoToFirstFile(zip); unzGetCurrentFileInfo(zip,&info,tempName,256,NULL,0,NULL,0); while (status == UNZ_OK) { char tmp[256]; unzGetCurrentFileInfo(zip, &info, tempName, 256, NULL, 0, NULL, 0); strcpy(tmp, tempName); toLower(tmp); if (strstr(tmp, extension) != NULL) { int entryLen = strlen(tempName) + 1; fileArray = realloc(fileArray, totalLen + entryLen + 1); strcpy(fileArray + totalLen, tempName); totalLen += entryLen; fileArray[totalLen] = '\0'; // double null termination at end *count = *count + 1; } status = unzGoToNextFile(zip); } unzClose(zip); return fileArray; }
//--------------------------------------------------------------------------- bool zipclass::next() { if (enable_zip==0) return ZIPPY_FAIL; if (strcmp(type,"ZIP")==0){ #ifdef UNIX if (is_open==0) return ZIPPY_FAIL; if (current_file_n>=(int)(gi.number_entry-1)) return ZIPPY_FAIL; err=unzGoToNextFile(uf); if (err) return ZIPPY_FAIL; err=unzGetCurrentFileInfo(uf,&fi,filename_inzip, sizeof(filename_inzip),NULL,0,NULL,0); if (err) return ZIPPY_FAIL; current_file_n++; current_file_offset=current_file_n; crc=fi.crc; #endif #ifdef WIN32 err=GetNextInZip(&PackInfo); if (err!=UNZIP_Ok) return ZIPPY_FAIL; attrib=PackInfo.Attr; crc=PackInfo.Crc; current_file_n++; current_file_offset=PackInfo.HeaderOffset; #endif return ZIPPY_SUCCEED; #ifdef RAR_SUPPORT }else if (strcmp(type,"RAR")==0){ if (is_open==0 || rar_current==NULL) return ZIPPY_FAIL; do{ rar_current=rar_current->next; current_file_n++; if (rar_current==NULL) return ZIPPY_FAIL; }while (rar_current->item.FileAttr & 0x10); // Skip if directory current_file_offset=current_file_n; attrib=WORD(rar_current->item.FileAttr); crc=rar_current->item.FileCRC; return ZIPPY_SUCCEED; #endif } return ZIPPY_FAIL; }
void loadZipFile2(const char* ipsw, OutputState** output, const char* file, int useMemory) { char* fileName; void* buffer; unzFile zip; unz_file_info pfile_info; ASSERT(zip = unzOpen(ipsw), "cannot open input ipsw"); ASSERT(unzGoToFirstFile(zip) == UNZ_OK, "cannot seek to first file in input ipsw"); do { ASSERT(unzGetCurrentFileInfo(zip, &pfile_info, NULL, 0, NULL, 0, NULL, 0) == UNZ_OK, "cannot get current file info from ipsw"); fileName = (char*) malloc(pfile_info.size_filename + 1); ASSERT(unzGetCurrentFileInfo(zip, NULL, fileName, pfile_info.size_filename + 1, NULL, 0, NULL, 0) == UNZ_OK, "cannot get current file name from ipsw"); if((file == NULL && fileName[strlen(fileName) - 1] != '/') || (file != NULL && strcmp(fileName, file)) == 0) { printf("loading: %s (%ld)\n", fileName, pfile_info.uncompressed_size); fflush(stdout); ASSERT(unzOpenCurrentFile(zip) == UNZ_OK, "cannot open compressed file in IPSW"); if(useMemory) { buffer = malloc((pfile_info.uncompressed_size > 0) ? pfile_info.uncompressed_size : 1); ASSERT(unzReadCurrentFile(zip, buffer, pfile_info.uncompressed_size) == pfile_info.uncompressed_size, "cannot read file from ipsw"); addToOutput(output, fileName, buffer, pfile_info.uncompressed_size); } else { char* tmpFileName = createTempFile(); FILE* tmpFile = fopen(tmpFileName, "wb"); buffer = malloc(DEFAULT_BUFFER_SIZE); size_t left = pfile_info.uncompressed_size; while(left > 0) { size_t toRead; if(left > DEFAULT_BUFFER_SIZE) toRead = DEFAULT_BUFFER_SIZE; else toRead = left; ASSERT(unzReadCurrentFile(zip, buffer, toRead) == toRead, "cannot read file from ipsw"); fwrite(buffer, toRead, 1, tmpFile); left -= toRead; } fclose(tmpFile); free(buffer); addToOutput2(output, fileName, NULL, pfile_info.uncompressed_size, tmpFileName); } ASSERT(unzCloseCurrentFile(zip) == UNZ_OK, "cannot close compressed file in IPSW"); } free(fileName); } while(unzGoToNextFile(zip) == UNZ_OK); ASSERT(unzClose(zip) == UNZ_OK, "cannot close input ipsw file"); }
void ZipFile::init() { zlib_filefunc64_def file_functions; unz_file_info64 info; unz64_file_pos position; boost::scoped_array<char> file_name; String index; Uint32 size; Sint32 ok; file_functions.zopen64_file = open_ifstream_func; file_functions.zread_file = read_istream_func; file_functions.zwrite_file = write_istream_func; file_functions.ztell64_file = tell_istream_func; file_functions.zseek64_file = seek_istream_func; file_functions.zclose_file = close_istream_func; file_functions.zerror_file = error_istream_func; m_file = unzOpen2_64(utf8_to_string(get_name()).c_str(), &file_functions); ok = unzGoToFirstFile(m_file); while (ok == UNZ_OK) { unzGetFilePos64(m_file, &position); unzGetCurrentFileInfo64(m_file, &info, 0, 0, 0, 0, 0, 0); size = info.size_filename; file_name.reset(new char[size + 1]); unzGetCurrentFileInfo64(m_file, 0, file_name.get(), size, 0, 0, 0, 0); index = String(string_to_utf8(std::string( file_name.get(), size))); m_files[index] = ZipFileEntry(position); ok = unzGoToNextFile(m_file); } }
gboolean ManagedUnzip::StreamToStreamNthFile (ManagedStreamCallbacks *source, ManagedStreamCallbacks *dest, int file) { zlib_filefunc_def funcs; unzFile zipFile; gboolean ret; ret = FALSE; funcs.zopen_file = managed_stream_open; funcs.zread_file = managed_stream_read; funcs.zwrite_file = managed_stream_write; funcs.ztell_file = managed_stream_tell; funcs.zseek_file = managed_stream_seek; funcs.zclose_file = managed_stream_close; funcs.zerror_file = managed_stream_error; funcs.opaque = source; zipFile = unzOpen2 (NULL, &funcs); if (!zipFile) return FALSE; if (unzGoToFirstFile (zipFile) != UNZ_OK) goto cleanup; while (!IsCurrentFileValid (zipFile) || file > 0) { if (unzGoToNextFile (zipFile) != UNZ_OK) goto cleanup; if (!IsCurrentFileValid (zipFile)) continue; file --; } if (unzOpenCurrentFile (zipFile) != UNZ_OK) goto cleanup; ret = ExtractToStream (zipFile, dest); cleanup: unzCloseCurrentFile (zipFile); unzClose (zipFile); return ret; }
int ZipArchive::listMembers(ArchiveMemberList &list) { int matches = 0; int err = unzGoToFirstFile(_zipFile); while (err == UNZ_OK) { char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; if (unzGetCurrentFileInfo(_zipFile, NULL, szCurrentFileName, sizeof(szCurrentFileName)-1, NULL, 0, NULL, 0) == UNZ_OK) { list.push_back(ArchiveMemberList::value_type(new GenericArchiveMember(szCurrentFileName, this))); matches++; } err = unzGoToNextFile(_zipFile); } return matches; }
void unzip_mem(char* buf, int len, TCHAR* dest) { zlib_filefunc64_def ffunc; fill_memory_filefunc64(&ffunc); char zipfile[128]; mir_snprintf(zipfile, sizeof(zipfile), "%p+%x", buf, len); unzFile uf = unzOpen2_64(zipfile, &ffunc); if (uf) { do { extractCurrentFile(uf, dest); } while (unzGoToNextFile(uf) == UNZ_OK); unzClose(uf); } }
bool ArchiveReader::Enumerate_ZIP() { clPtr<iIStream> TheSource = FSourceFile; FSourceFile->Seek( 0 ); zlib_filefunc64_def ffunc; fill_functions( TheSource.GetInternalPtr(), &ffunc ); unzFile uf = unzOpen2_64( "", &ffunc ); unz_global_info64 gi; int err = unzGetGlobalInfo64( uf, &gi ); for ( uLong i = 0; i < gi.number_entry; i++ ) { char filename_inzip[256]; unz_file_info64 file_info; err = unzGetCurrentFileInfo64( uf, &file_info, filename_inzip, sizeof( filename_inzip ), NULL, 0, NULL, 0 ); if ( err != UNZ_OK ) { break; } if ( ( i + 1 ) < gi.number_entry ) { err = unzGoToNextFile( uf ); // WARNING: "error %d with zipfile in unzGoToNextFile\n", err if ( err != UNZ_OK ) { break; } } sFileInfo Info; Info.FOffset = 0; Info.FCompressedSize = file_info.compressed_size; Info.FSize = file_info.uncompressed_size; FFileInfos.push_back( Info ); std::string TheName = Arch_FixFileName( filename_inzip ); FFileInfoIdx[TheName] = ( int )FFileNames.size(); FFileNames.push_back( TheName ); FRealFileNames.push_back( std::string( filename_inzip ) ); } unzClose( uf ); return true; }
/* Try locate the file szFileName in the zipfile. For the iCaseSensitivity signification, see unzipStringFileNameCompare return value : UNZ_OK if the file is found. It becomes the current file. UNZ_END_OF_LIST_OF_FILE if the file is not found */ extern int ZEXPORT unzLocateFile( unzFile file, const char *szFileName, int iCaseSensitivity ) { unz_s* s; int err; uLong num_fileSaved; uLong pos_in_central_dirSaved; if (file==NULL) return UNZ_PARAMERROR; if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) return UNZ_PARAMERROR; s=(unz_s*)file; if (!s->current_file_ok) return UNZ_END_OF_LIST_OF_FILE; num_fileSaved = s->num_file; pos_in_central_dirSaved = s->pos_in_central_dir; err = unzGoToFirstFile(file); while (err == UNZ_OK) { char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; unzGetCurrentFileInfo(file,NULL, szCurrentFileName,sizeof(szCurrentFileName)-1, NULL,0,NULL,0); if (unzStringFileNameCompare(szCurrentFileName, szFileName,iCaseSensitivity)==0) return UNZ_OK; err = unzGoToNextFile(file); } s->num_file = num_fileSaved ; s->pos_in_central_dir = pos_in_central_dirSaved ; return err; }
std::vector<std::string> FileSystemZip::GetContents() { uLong i; unz_global_info gi; int err; char filename_inzip[512]; unz_file_info file_info; std::vector<std::string> contents; err = unzGetGlobalInfo(m_unzf,&gi); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGetGlobalInfo \n",err); return contents; } unzGoToFirstFile(m_unzf); for (i=0;i<gi.number_entry;i++) { err = unzGetCurrentFileInfo(m_unzf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGetCurrentFileInfo\n",err); break; } contents.push_back(std::string(filename_inzip)); if ((i+1)<gi.number_entry) { err = unzGoToNextFile(m_unzf); if (err!=UNZ_OK) { LogError("error %d with zipfile in unzGoToNextFile\n",err); break; } } } return contents; }
static status_t ReadZipFileAux(zipFile zf, Message & msg, char * nameBuf, uint32 nameBufLen, bool loadData) { while(unzOpenCurrentFile(zf) == UNZ_OK) { unz_file_info fileInfo; if (unzGetCurrentFileInfo(zf, &fileInfo, nameBuf, nameBufLen, NULL, 0, NULL, 0) != UNZ_OK) return B_ERROR; // Add the new entry to the appropriate spot in the tree (demand-allocate sub-Messages as necessary) { const char * nulByte = strchr(nameBuf, '\0'); const bool isFolder = ((nulByte > nameBuf)&&(*(nulByte-1) == '/')); Message * m = &msg; StringTokenizer tok(true, nameBuf, "/"); const char * nextTok; while((nextTok = tok()) != NULL) { String fn(nextTok); if ((isFolder)||(tok.GetRemainderOfString())) { // Demand-allocate a sub-message MessageRef subMsg; if (m->FindMessage(fn, subMsg) != B_NO_ERROR) { if ((m->AddMessage(fn, Message()) != B_NO_ERROR)||(m->FindMessage(fn, subMsg) != B_NO_ERROR)) return B_ERROR; } m = subMsg(); } else { if (loadData) { ByteBufferRef bufRef = GetByteBufferFromPool((uint32) fileInfo.uncompressed_size); if ((bufRef() == NULL)||(unzReadCurrentFile(zf, bufRef()->GetBuffer(), bufRef()->GetNumBytes()) != (int32)bufRef()->GetNumBytes())||(m->AddFlat(fn, bufRef) != B_NO_ERROR)) return B_ERROR; } else if (m->AddInt64(fn, fileInfo.uncompressed_size) != B_NO_ERROR) return B_ERROR; } } } if (unzCloseCurrentFile(zf) != UNZ_OK) return B_ERROR; if (unzGoToNextFile(zf) != UNZ_OK) break; } return B_NO_ERROR; }
bool unzip(const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath,bool ch) { bool bResult = true; zlib_filefunc64_def ffunc; fill_fopen64_filefunc(&ffunc); unzFile uf = unzOpen2_64(ptszZipFile, &ffunc); if (uf) { do { if (!extractCurrentFile(uf, ptszDestPath, ptszBackPath,ch)) bResult = false; } while (unzGoToNextFile(uf) == UNZ_OK); unzClose(uf); } return bResult; }
int UnzipCache::unzip(const char *pattern, std::list<clc::Buffer> *matchedNames) { uLong i; unz_global_info64 gi; int numMatched = 0; if (m_uf) unzClose(m_uf); m_uf = unzOpen64(m_filename.c_str()); int err = unzGetGlobalInfo64(m_uf, &gi); if (err != UNZ_OK) { clc::Log::error("ocher.epub.unzip", "unzGetGlobalInfo: %d", err); return -1; } for (i = 0; i < gi.number_entry; i++) { int r; if (matchedNames) { clc::Buffer matchedName; r = unzipFile(pattern, &matchedName); if (!matchedName.empty()) matchedNames->push_back(matchedName); } else { r = unzipFile(pattern, NULL); } if (r > 0) { ++numMatched; if (r > 1) break; } if ((i + 1) < gi.number_entry) { err = unzGoToNextFile(m_uf); if (err != UNZ_OK) { clc::Log::error("ocher.epub.unzip", "unzGoToNextFile: %d", err); return -1; } } } return numMatched; }
void Zips::read(unzFile zp) { do { unz_file_pos pos; unzGetFilePos(zp, &pos); file_entry entry; unzGetCurrentFileInfo(zp, 0, entry.name, sizeof(entry.name) - 1, 0, 0, 0, 0); entry.pos = pos; entry.zp = zp; //strcpy(entry.name, entry.name); _files.push_back(entry); } while (unzGoToNextFile(zp) != UNZ_END_OF_LIST_OF_FILE); _sort = true; }
bool eFileTypeZIP::Open(unzFile h, char* name) const { if(!h) return false; bool ok = false; if(unzGoToFirstFile(h) == UNZ_OK) { for(;;) { if(OpenCurrent(h, name)) { ok = true; break; } if(unzGoToNextFile(h) == UNZ_END_OF_LIST_OF_FILE) break; } } unzClose(h); return ok; }
std::vector<openstudio::path> UnzipFile::listFiles() const { bool cont = unzGoToFirstFile(m_unzFile) == UNZ_OK; std::vector<openstudio::path> paths; do { unz_file_info file_info; std::vector<char> filename(300); unzGetCurrentFileInfo(m_unzFile, &file_info, &filename.front(), filename.size(), nullptr,0, nullptr,0); paths.push_back(openstudio::toPath(std::string(&filename.front(), file_info.size_filename))); cont = unzGoToNextFile(m_unzFile) == UNZ_OK; } while (cont); return paths; }
int minizip_unzip(const char * lpszzipfilename, const char * lpszdirname, const char * lpszpassword) { int nret = -1; int nstatus = 0; int nct = 0; unzFile uf = NULL; // Open zip file if (lpszzipfilename != NULL) { uf = unzOpen64(lpszzipfilename); } if (uf == NULL) { return ERROR_ZIP_FILE_NOT_FOUND; } // Extract all nstatus = unzGoToFirstFile(uf); while (nstatus == UNZ_OK) { chdir(lpszdirname); nstatus = extractCurrentFile(uf, lpszpassword); if (nstatus == UNZ_OK) { nct ++; nstatus =unzGoToNextFile(uf); } } if (nct > 0) { nret = 0; } return nret; }
void Unzip::retrieveAllFileInfos(void) { do{ unz_file_pos pos; if(UNZ_OK != unzGetFilePos(zipfile_handle, &pos)){ continue; } unz_file_info info; char currentFileName[CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE]; char currentExtraField[CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE]; char currentComment[CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE]; unzGetCurrentFileInfo(zipfile_handle, &info, currentFileName, CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE, currentExtraField, CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE, currentComment, CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE); std::shared_ptr<InnerZipFileInfo> innerFileInfo(new InnerZipFileInfo()); innerFileInfo->fileName = currentFileName; innerFileInfo->extraField = currentExtraField; innerFileInfo->comment = currentComment; innerFileInfo->time_sec = info.tmu_date.tm_sec; innerFileInfo->time_min = info.tmu_date.tm_min; innerFileInfo->time_hour = info.tmu_date.tm_hour; innerFileInfo->time_day_of_month = info.tmu_date.tm_mday; innerFileInfo->time_month = info.tmu_date.tm_mon; innerFileInfo->time_year = info.tmu_date.tm_year; innerFileInfo->dosDate = info.dosDate; innerFileInfo->crc = info.crc; innerFileInfo->compressed_size = info.compressed_size; innerFileInfo->uncompressed_size = info.uncompressed_size; innerFileInfo->internal_fileAttributes = info.internal_fa; innerFileInfo->external_fileAttributes = info.external_fa; fileInfos.insert(std::make_pair(innerFileInfo->fileName, innerFileInfo)); } while(UNZ_OK == unzGoToNextFile(zipfile_handle)); }
CArchiveZip::CArchiveZip(const std::string& name): CArchiveBuffered(name), curSearchHandle(1) { #ifdef USEWIN32IOAPI zlib_filefunc_def ffunc; fill_win32_filefunc(&ffunc); zip = unzOpen2(name.c_str(),&ffunc); #else zip = unzOpen(name.c_str()); #endif if (!zip) { LogObject() << "Error opening " << name; return; } // We need to map file positions to speed up opening later for (int ret = unzGoToFirstFile(zip); ret == UNZ_OK; ret = unzGoToNextFile(zip)) { unz_file_info info; char fname[512]; unzGetCurrentFileInfo(zip, &info, fname, 512, NULL, 0, NULL, 0); const std::string name = StringToLower(fname); if (name.empty()) { continue; } const char last = name[name.length() - 1]; if ((last == '/') || (last == '\\')) { continue; // exclude directory names } FileData fd; unzGetFilePos(zip, &fd.fp); fd.size = info.uncompressed_size; fd.origName = fname; fd.crc = info.crc; fileData[name] = fd; } }
bool ZipFile::SeekFile(int ind) { if(ind < 0 || ind >= (int) ZipStructure.size()) return false; if(!SwitchMode(ZipFile::OPEN)) return false; int ret = unzGoToFirstFile(uzFile); if(ret != UNZ_OK) return false; while(ind > 0) { if(unzGoToNextFile(uzFile) != UNZ_OK) return false; --ind; } return true; }