size_t getEntry(const char *name, char *contentFile, char **ptr) { size_t size=0; ZZIP_DIR *dir; ZZIP_DIRENT entry; ZZIP_FILE *file; char *buf; dir = zzip_dir_open(name, 0); if (!dir) { fprintf(stderr, "failed to open %s\n", name); return 0; } zzip_dir_read(dir, &entry); file = zzip_file_open(dir, contentFile, 0); (void)zzip_seek(file, 0, SEEK_END); size = zzip_tell(file); (void)zzip_seek(file, 0, SEEK_SET); buf = (char *)malloc(size+1); (void)zzip_read(file, buf, size); buf[size] = '\0'; *ptr = buf; zzip_file_close(file); zzip_dir_close(dir); return size; }
int main(int argc, const char *argv[]) { if (argc < 2) { fprintf(stderr, "usage: %s <file>\n", argv[0]); return -1; } const char* innerFile = ""; if (argc == 3) innerFile = argv[2]; zzip_error_t errcode; ZZIP_DIR* dir = zzip_dir_open(argv[1], &errcode); if (dir == NULL) { fprintf(stderr, "zzip_operdir failed: %s\n", zzip_strerror(errcode)); return -1; } // scan files ZZIP_DIRENT* dirent = zzip_readdir(dir); while (dirent) { printf("%s, compression %d, size %d/%d\n", dirent->d_name, dirent->d_compr, dirent->d_csize, dirent->st_size); checkFile(dir, dirent, innerFile); dirent = zzip_readdir(dir); } int err = zzip_closedir(dir); if (err != 0) { fprintf(stderr, "zzip_closedir failed: %s\n", zzip_strerror_of(dir)); return -1; } return 0; }
static void extract_zip_file_into_loader(GdkPixbufLoader * loader, const char *archname, const char *archpath) { if (loader == NULL) return; ZZIP_DIR *dir = zzip_dir_open(archname, 0); ZZIP_FILE *fp = zzip_file_open(dir, archpath, 0); if (fp) { guchar buf[ZIPBUFSIZE]; GError *error = NULL; zzip_ssize_t len; while ((len = zzip_file_read(fp, buf, ZIPBUFSIZE))) { gdk_pixbuf_loader_write(loader, buf, len, &error); if (error != NULL) { g_warning("load image in zip failed: %s\n", error->message); g_error_free(error); zzip_dir_close(dir); return; } } zzip_file_close(fp); } zzip_dir_close(dir); }
bool ResourceManager::StartUp( SDL_Window* window, size_t threadCount, const std::string& assetFilePath ) { memory = 0; std::string assetFileExtension = assetFilePath.substr( assetFilePath.find_last_of( '.' ) ); if ( assetFileExtension == ".paca" ) mAssetPacketExtension = AssetPacketExtension::PACA; else if ( assetFileExtension == ".zip" ) mAssetPacketExtension = AssetPacketExtension::ZIP; else return false; mThreadPool.Create( threadCount, window ); switch ( mAssetPacketExtension ) { case PACA: mPacaReader.Open( assetFilePath ); break; case ZIP: mDir = zzip_dir_open( assetFilePath.c_str(), 0 ); break; } return true; }
//----------------------------------------------------------------------- void ZipArchive::load() { if (!mZzipDir) { zzip_error_t zzipError; mZzipDir = zzip_dir_open(mName.c_str(), &zzipError); checkZzipError(zzipError, "opening archive"); // Cache names ZZIP_DIRENT zzipEntry; while (zzip_dir_read(mZzipDir, &zzipEntry)) { FileInfo info; info.archive = this; // Get basename / path StringUtil::splitFilename(zzipEntry.d_name, info.basename, info.path); // ignore folder entries if (info.basename.empty()) continue; info.filename = zzipEntry.d_name; // Get sizes info.compressedSize = static_cast<size_t>(zzipEntry.d_csize); info.uncompressedSize = static_cast<size_t>(zzipEntry.st_size); mFileList.push_back(info); } } }
int main(int argc, char **argv) { Args args(argc, argv, "PATH"); const char *path = args.ExpectNext(); args.ExpectEnd(); ZZIP_DIR *dir = zzip_dir_open(path, NULL); if (dir == NULL) { fprintf(stderr, "Failed to open %s\n", (const char *)path); return EXIT_FAILURE; } ZipLineReaderA reader(dir, "topology.tpl"); if (reader.error()) { fprintf(stderr, "Failed to open %s\n", (const char *)path); return EXIT_FAILURE; } TopographyStore topography; NullOperationEnvironment operation; topography.Load(operation, reader, NULL, dir); zzip_dir_close(dir); topography.LoadAll(); #ifdef ENABLE_OPENGL TriangulateAll(topography); #endif return EXIT_SUCCESS; }
int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: %s PATH\n", argv[0]); return 1; } const char *path = argv[1]; ZZIP_DIR *dir = zzip_dir_open(path, NULL); if (dir == NULL) { fprintf(stderr, "Failed to open %s\n", (const char *)path); return EXIT_FAILURE; } ZipLineReaderA reader(dir, "topology.tpl"); if (reader.error()) { fprintf(stderr, "Failed to open %s\n", (const char *)path); return EXIT_FAILURE; } TopographyStore topography; NullOperationEnvironment operation; topography.Load(operation, reader, NULL, dir); zzip_dir_close(dir); TestProjection projection; topography.ScanVisibility(projection); return EXIT_SUCCESS; }
int main(int argc, char** argv) { static const char map_path[] = "tmp/map.xcm"; ZZIP_DIR *dir = zzip_dir_open(map_path, nullptr); if (dir == nullptr) { fprintf(stderr, "Failed to open %s\n", map_path); return EXIT_FAILURE; } RasterMap map; NullOperationEnvironment operation; if (!LoadTerrainOverview(dir, map.GetTileCache(), operation)) { fprintf(stderr, "failed to load map\n"); zzip_dir_close(dir); return EXIT_FAILURE; } map.UpdateProjection(); SharedMutex mutex; do { UpdateTerrainTiles(dir, map.GetTileCache(), mutex, map.GetProjection(), map.GetMapCenter(), 100000); } while (map.IsDirty()); zzip_dir_close(dir); plan_tests(4 + NUM_SOL); ok(test_route(28, map), "route 28", 0); return exit_status(); }
bool ArchiveZip::open(const Path& path) { ZZIP_DIR* zip = zzip_dir_open(path.c_str(), nullptr); handle = zip; isValid = zip != nullptr; return isValid; }
struct zzip_dir * RasterWeatherStore::OpenArchive() { const auto path = LocalPath(_T(RASP_FILENAME)); NarrowPathName narrow_path(path); if (!narrow_path.IsDefined()) return nullptr; return zzip_dir_open(narrow_path, nullptr); }
static int zip_open (lua_State *L) { const char *zipfilename = luaL_checkstring(L, 1); /*const char *mode = luaL_optstring(L, 2, "r");*/ ZZIP_DIR** pf = newfile(L); *pf = zzip_dir_open(zipfilename, 0); if (*pf == NULL) { lua_pushnil(L); lua_pushfstring(L, "could not open file `%s'", zipfilename); return 2; } return 1; }
void ZipResourceManager::populate() { zzip_error_t zzipError; ZZIP_DIR* zzipDir = zzip_dir_open(resourcePath.c_str(), &zzipError); checkZzipError(zzipError); ZZIP_DIRENT zzipEntry; while (zzip_dir_read(zzipDir, &zzipEntry)) { int compressedSize = zzipEntry.d_csize; int uncompressedSize = zzipEntry.st_size; std::string name = std::string(zzipEntry.d_name); files[name] = SDL_RWFromZZIP((resourcePath + "/" + name).c_str(), "rb"); } zzip_dir_close(zzipDir); }
/** 加载ZIP文件包 */ bool FZipFilePack::Load(void) { if( !m_pZipDir ) { zzip_error_t zipError; m_pZipDir = zzip_dir_open( m_sName.c_str(),&zipError ); if( !m_pZipDir ) return false; if( zipError != ZZIP_NO_ERROR ) { AString errInfo; GetZipErrorDesc( zipError,errInfo ); // 抛出异常 FLOG_WARNING( "FZipFilePack::Load(), An exception is found when loading zip archive(" + errInfo + ")!" ); return false; } ZZIP_DIRENT dirEntry; while( zzip_dir_read(m_pZipDir,&dirEntry) ) { VFileInfo info; info.pFilePack = this; AStringUtil::SplitPath( dirEntry.d_name,info.sBaseName,info.sPath ); info.nCompressedSize = static_cast<size_t>(dirEntry.d_csize); info.nUncompressedSize = static_cast<size_t>(dirEntry.st_size); info.sFileName = dirEntry.d_name; // 如果是目录 if( info.sBaseName == "" ) { info.sFileName = info.sFileName.substr( 0,info.sFileName.length()-1 ); AStringUtil::SplitPath( info.sFileName,info.sBaseName,info.sPath ); info.nCompressedSize = (size_t)-1; } m_FileInfos.push_back( info ); } } return true; }
int main(int argc, char** argv) { static const char hc_path[] = "tmp/map.xcm"; const char *map_path; if ((argc<2) || !strlen(argv[0])) { map_path = hc_path; } else { map_path = argv[0]; } ZZIP_DIR *dir = zzip_dir_open(map_path, nullptr); if (dir == nullptr) { fprintf(stderr, "Failed to open %s\n", map_path); return EXIT_FAILURE; } RasterMap map; NullOperationEnvironment operation; if (!LoadTerrainOverview(dir, map.GetTileCache(), operation)) { fprintf(stderr, "failed to load map\n"); zzip_dir_close(dir); return EXIT_FAILURE; } map.UpdateProjection(); SharedMutex mutex; do { UpdateTerrainTiles(dir, map.GetTileCache(), mutex, map.GetProjection(), map.GetMapCenter(), 100000); } while (map.IsDirty()); zzip_dir_close(dir); plan_tests(16*3); test_troute(map, 0, 0.1, 10000); test_troute(map, 0, 0, 10000); test_troute(map, 5.0, 1, 10000); return exit_status(); }
bool PluginLoader::ParseDirectory(FileSpecifier& dir) { std::vector<dir_entry> de; if (!dir.ReadDirectory(de)) { return false; } for (std::vector<dir_entry>::const_iterator it = de.begin(); it != de.end(); ++it) { FileSpecifier file = dir + it->name; if (it->name == "Plugin.xml") { ParsePlugin(file); } else if (it->is_directory && it->name[0] != '.') { ParseDirectory(file); } #ifdef HAVE_ZZIP else if (algo::ends_with(it->name, ".zip") || algo::ends_with(it->name, ".ZIP")) { // search it for a Plugin.xml file ZZIP_DIR* zzipdir = zzip_dir_open(file.GetPath(), 0); if (zzipdir) { ZZIP_DIRENT dirent; while (zzip_dir_read(zzipdir, &dirent)) { if (algo::ends_with(dirent.d_name, "Plugin.xml")) { std::string archive = file.GetPath(); FileSpecifier file_name = FileSpecifier(archive.substr(0, archive.find_last_of('.'))) + dirent.d_name; ParsePlugin(file_name); } } zzip_dir_close(zzipdir); } } #endif } return true; }
GList *get_filelist_from_zip(const char *archname, GtkFileFilter * filter) { GList *filelist = NULL; gchar *filename = NULL; ZZIP_DIR *dir = zzip_dir_open(archname, 0); if (dir) { ZZIP_DIRENT dirent; while (zzip_dir_read(dir, &dirent) != 0) { filename = g_strdup(dirent.d_name); if ((filter != NULL && gtk_filename_filter(filename, filter)) || filter == NULL) filelist = g_list_append(filelist, filename); } zzip_dir_close(dir); } return filelist; }
/** * Load topology from the map file (ZIP), load the other files from * the same ZIP file. */ static bool LoadConfiguredTopologyZip(TopologyStore &store) { TCHAR path[MAX_PATH]; if (!Profile::GetPath(szProfileMapFile, path)) return false; ZZIP_DIR *dir = zzip_dir_open(NarrowPathName(path), NULL); if (dir == NULL) return false; ZipLineReaderA reader(dir, "topology.tpl"); if (reader.error()) { LogStartUp(_T("No topology in map file: %s"), path); return false; } store.Load(reader, NULL, dir); zzip_dir_close(dir); return true; }
void RasterWeather::ScanAll(const GeoPoint &location) { /* not holding the lock here, because this method is only called during startup, when the other threads aren't running yet */ TCHAR fname[MAX_PATH]; LocalPath(fname, _T("xcsoar-rasp.dat")); ZZIP_DIR *dir = zzip_dir_open(NarrowPathName(fname), NULL); if (dir == NULL) return; ProgressGlue::SetRange(MAX_WEATHER_TIMES); for (unsigned i = 0; i < MAX_WEATHER_TIMES; i++) { ProgressGlue::SetValue(i); weather_available[i] = ExistsItem(dir, _T("wstar"), i) || ExistsItem(dir, _T("wstar_bsratio"), i); } zzip_dir_close(dir); }
size_t getEntry(const char *name, char *contentFile, char **ptr) { size_t size=0; ZZIP_DIR *dir; ZZIP_DIRENT entry; ZZIP_FILE *file; zzip_error_t error; char *buf; o_log(DEBUGM, "opening %s", name); dir = zzip_dir_open(name, &error); if (!dir) { o_log(ERROR, "failed to open %s", name); return 0; } while(zzip_dir_read(dir, &entry)) { if( 0 == strcmp(entry.d_name, contentFile) ) { file = zzip_file_open(dir, contentFile, O_RDONLY); (void)zzip_seek(file, 0, SEEK_END); size = zzip_tell(file); (void)zzip_seek(file, 0, SEEK_SET); buf = (char *)malloc(size+1); (void)zzip_read(file, buf, size); buf[size] = '\0'; *ptr = buf; zzip_file_close(file); } } zzip_dir_close(dir); return size; }
int main(int argc, char **argv) { Args args(argc, argv, "PATH"); const auto map_path = args.ExpectNext(); args.ExpectEnd(); ZZIP_DIR *dir = zzip_dir_open(map_path, nullptr); if (dir == nullptr) { fprintf(stderr, "Failed to open %s\n", map_path); return EXIT_FAILURE; } NullOperationEnvironment operation; RasterTileCache rtc; if (!LoadTerrainOverview(dir, rtc, operation)) { fprintf(stderr, "LoadOverview failed\n"); zzip_dir_close(dir); return EXIT_FAILURE; } GeoBounds bounds = rtc.GetBounds(); printf("bounds = %f|%f - %f|%f\n", (double)bounds.GetWest().Degrees(), (double)bounds.GetNorth().Degrees(), (double)bounds.GetEast().Degrees(), (double)bounds.GetSouth().Degrees()); SharedMutex mutex; do { UpdateTerrainTiles(dir, rtc, mutex, rtc.GetWidth() / 2, rtc.GetHeight() / 2, 1000); } while (rtc.IsDirty()); zzip_dir_close(dir); return EXIT_SUCCESS; }
static int unzzip_cat (int argc, char ** argv, int extract) { int done = 0; int argn; ZZIP_DIR* disk; zzip_error_t error; if (argc == 1) { printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n"); return EXIT_OK; /* better provide an archive argument */ } disk = zzip_dir_open (argv[1], &error); if (! disk) { fprintf(stderr, "%s: %s\n", argv[1], zzip_strerror(error)); return exitcode(error); } if (argc == 2) { /* list all */ ZZIP_DIRENT entry; while(zzip_dir_read(disk, &entry)) { char* name = entry.d_name; FILE* out = stdout; if (extract) out = create_fopen(name, "wb", 1); if (! out) { DBG3("fopen' %s : %s", name, strerror(errno)); if (errno != EISDIR) done = EXIT_ERRORS; continue; } unzzip_cat_file (disk, name, out); if (extract) fclose(out); } } else { /* list only the matching entries - in order of zip directory */ ZZIP_DIRENT entry; while(zzip_dir_read(disk, &entry)) { char* name = entry.d_name; for (argn=1; argn < argc; argn++) { if (! _zzip_fnmatch (argv[argn], name, _zzip_FNM_NOESCAPE|_zzip_FNM_PATHNAME|_zzip_FNM_PERIOD)) { FILE* out = stdout; if (extract) out = create_fopen(name, "wb", 1); if (! out) { DBG3("fopen. %s : %s", name, strerror(errno)); if (errno != EISDIR) done = EXIT_ERRORS; continue; } unzzip_cat_file (disk, name, out); if (extract) fclose(out); break; /* match loop */ } } } } zzip_dir_close(disk); return done; }
bool CZipArchive::loadArchive(){ static mchar tempBuff[128]; if(!m_zipDir){ zzip_error_t err; //m_file=gFileSystem.openFile(getName()); //if(!m_file || !m_file->getFD())return 0; //m_zipDir = zzip_dir_fdopen(m_file->getFD()->_file,&err); core::stringc fileName; core::string_to_char(getName(),fileName); m_zipDir = zzip_dir_open(fileName.c_str(),&err); if(checkForError(err,mT(" loadArchive()")))return false; ZZIP_DIRENT zipEntry; sFileEntry entry; core::string tstr; core::string zipName; core::stringc tmpc; while(zzip_dir_read(m_zipDir,&zipEntry)){ zipName=zipEntry.d_name; zipName.replaceChar('\\','/'); int x=zipName.findlast('/'); if(x==zipName.length()){ // entry.dirPath=zipName; // entry.filePath=zipName; entry.dirPath=mT(""); entry.filePath=mT(""); zipName[zipName.length()]='\0'; x=zipName.findlast('/'); tstr=zipName.substr(x,zipName.length()-x+1); entry.fileName=tstr; entry.isfolder=true; entry.fileData=0; }else{ //entry.filePath=zipName; entry.dirPath=mT(""); entry.filePath=mT(""); tstr=zipName.substr(x+1,zipName.length()); entry.fileName=tstr; core::string_to_char(zipName,tmpc); zzip_file*zipFile=zzip_file_open(m_zipDir,tmpc.c_str(),ZZIP_ONLYZIP | ZZIP_CASELESS); if(!zipFile){ int zerr = zzip_error(m_zipDir); checkForError(zerr,mT("open zip file")); entry.fileData=0; }else{ ZZIP_STAT zstate; zzip_dir_stat(m_zipDir,tmpc.c_str(),&zstate,ZZIP_CASEINSENSITIVE); entry.fileData=new CZipFile(entry.fileName.c_str(),zipFile,zstate.st_size); } int s=zipName.find('/'); tstr=zipName.substr(s+1,x-s); entry.dirPath=tstr; entry.filePath=tstr+entry.fileName; entry.isfolder=false; } entry.compressSize=zipEntry.d_csize; entry.uncompressSize=zipEntry.st_size; m_files.push_back(entry); } } return 1; }
: Archive(name, archType), mZzipDir(0) { } //----------------------------------------------------------------------- ZipArchive::~ZipArchive() { unload(); } //----------------------------------------------------------------------- void ZipArchive::load() { OGRE_LOCK_AUTO_MUTEX if (!mZzipDir) { zzip_error_t zzipError; mZzipDir = zzip_dir_open(mName.c_str(), &zzipError); checkZzipError(zzipError, "opening archive"); // Cache names ZZIP_DIRENT zzipEntry; while (zzip_dir_read(mZzipDir, &zzipEntry)) { FileInfo info; info.archive = this; // Get basename / path StringUtil::splitFilename(zzipEntry.d_name, info.basename, info.path); info.filename = zzipEntry.d_name; // Get sizes info.compressedSize = static_cast<size_t>(zzipEntry.d_csize); info.uncompressedSize = static_cast<size_t>(zzipEntry.st_size); // folder entries
static int zipread_showlist(request_rec *r, const char *filter) { const char *filename = r->filename; const char *pathinfo = r->path_info; unsigned int len_filter = filter ? strlen(filter) : 0; ZZIP_DIRENT dirent; int pi_start; char *ppdir; apr_array_header_t * arr = apr_array_make(r->pool, 0, sizeof(char *)); // open the zip file ZZIP_DIR *dir = zzip_dir_open(filename, 0); if (!dir) return HTTP_NOT_FOUND; r->content_type = "text/html"; zipread_showheader(r, r->uri); if (filter && *filter == '/') { filter++; len_filter--; } // figure out the parent directory ppdir = apr_pstrdup(r->pool, ""); if (pathinfo && strlen(pathinfo) >= 2) { int i; for (i = strlen(pathinfo)-2 ; i >= 1 ; i--) { if (pathinfo[i] == '/') { ppdir = apr_pstrndup(r->pool, pathinfo, i); break; } } } else { // the parent dir is outside of the zip file. ppdir = "/.."; } // find the start of pathinfo in r->uri if (pathinfo) pi_start = ap_find_path_info(r->uri, r->path_info); else pi_start = strlen(r->uri); ap_rprintf(r,"<img src=\"/icons/back.gif\" alt=\"[BCK]\" /><a href=\"%s%s/\">%s</a>\n", apr_pstrndup(r->pool, r->uri, pi_start), ppdir, "Parent Directory"); while ( zzip_dir_read(dir, &dirent) ) { if (!filter || strncmp(dirent.d_name, filter, len_filter) == 0) { char **n = apr_array_push(arr); *n = apr_pstrdup(r->pool, dirent.d_name); } } { char **list = (char **)arr->elts; char *old = ""; int i; // Sort the list of files we contructed qsort((void *)list, arr->nelts, sizeof(char *), zipread_cmp); // Show the list of files: get first path part and remove the duplicates if (1 && filter) { for (i = 0; i < arr->nelts; i++) { int dir_found = 0; char *p1; // cut off anything after the first / if ((p1 = strchr(list[i] + len_filter, '/'))) { dir_found = 1; *(p1+1) = '\0'; } if (strcmp(list[i], old) != 0) { if (list[i][strlen(list[i])-1] == '/') { dir_found = 1; // skip the base filter directory entry if (strcmp(list[i], filter) == 0) continue; } zipread_showentry(r, list[i], list[i] + len_filter, dir_found, pi_start); old = apr_pstrdup(r->pool, list[i]); } } } else { // just list all paths unfiltered for (i = 0; i < arr->nelts; i++) { int dir_found = 0; if (list[i][strlen(list[i])-1] == '/') { dir_found = 1; } zipread_showentry(r, list[i], list[i], dir_found, pi_start); } } } ap_rputs("<hr /></pre>mod_zipread on Apache 2.0 (built on "__DATE__ " " __TIME__ ")\n</body></html>", r); zzip_dir_close (dir); return OK; }
static int zipread_showfile(request_rec *r, const char *fname) { char *zipfile, *name; ZZIP_DIR *dir; unsigned int itnum; if (!r->path_info) return HTTP_NOT_FOUND; zipfile = r->filename; if (!fname || !*fname) { name = apr_pstrdup(r->pool, r->path_info); } else { name = apr_pstrcat(r->pool, r->path_info, fname, NULL); } r->content_type = zipread_getcontenttype(r, name); if (*name == '/') name++; // ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_zipread showfile: %s - %s - %s", zipfile, fname, name); for(itnum = 0; itnum < 5; itnum++) { dir = zzip_dir_open(zipfile, 0); if (dir) { ZZIP_STAT st; // fetch stat info of filename, before opening it if (zzip_dir_stat(dir, name, &st, 0) != 0) { // check if a directory entry is available for that name. name = apr_pstrcat(r->pool, name, "/", NULL); if (zzip_dir_stat(dir, name, &st, 0) != 0) { zzip_dir_close(dir); ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_zipread showfile stat failed: %d - %s", zzip_error(dir), zzip_strerror(zzip_error(dir))); return HTTP_NOT_FOUND; } // found a directory entry, do an external redirect to get the // links in the directory listing right. name = apr_pstrcat(r->pool, r->uri, "/", NULL); apr_table_setn(r->headers_out, "Location", name); // ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_zipread showfile directory entry."); return HTTP_MOVED_PERMANENTLY; } ap_set_content_length(r, st.st_size); // cannot check last-modified date of the file itself here, because // zziplib doesnt extract it. instead we use the zip file's date r->mtime = r->finfo.mtime; ap_set_last_modified(r); if (!r->header_only) { ZZIP_FILE *fp = zzip_file_open(dir, name, 0); if (fp) { int len; char buf[32769]; while ((len = zzip_file_read (fp, buf, 32768))) { ap_rwrite(buf, len, r); } zzip_file_close(fp); zzip_dir_close(dir); return OK; } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_zipread showfile file open failed: %d - %s.", zzip_error(dir), zzip_strerror(zzip_error(dir))); if (zzip_dir_stat(dir, name, &st, 0) != 0) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_zipread showfile after stat failed: %d - %s", zzip_error(dir), zzip_strerror(zzip_error(dir))); break; } zzip_dir_close(dir); continue; } } zzip_dir_close(dir); return OK; } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "mod_zipread showfile zip file not open."); return HTTP_NOT_FOUND; } } zzip_dir_close (dir); return HTTP_NOT_FOUND; }
bool ZipAssetBundle::DeserializeFromDiskSource() { if (!assetAPI_->Cache()) { LogError("ZipAssetBundle::DeserializeFromDiskSource: Cannot process archive, AssetAPI cache is null."); return false; } else if (DiskSource().Empty()) { LogError("ZipAssetBundle::DeserializeFromDiskSource: Cannot process archive, no disk source for " + Name()); return false; } /* We want to detect if the extracted files are already up to date to save time. If the last modified date for the sub asset is the same as the parent zip file, we don't extract it. If the zip is re-downloaded from source everything will get unpacked even if only one file would have changed inside it. We could do uncompressed size comparisons but that is not a absolute guarantee that the file has not changed. We'll be on the safe side to unpack the whole zip file. Zip files are meant for deploying the scene and should be touched rather rarely. Note that local:// refs are unpacked to cache but the zips disk source is not in the cache. Meaning that local:// zip files will always be extracted fully even if the disk source was not changed, we don't have a mechanism to get the last modified date properly except from the asset cache. For local scenes this should be fine as there is no real need to zip the scene up as you already have the disk sources right there in the storage. The last modified query will fail if the file is open with zziplib, do it first. */ uint zipLastModified = assetAPI_->Cache()->LastModified(Name()); const String diskSourceInternal = Urho3D::GetInternalPath(DiskSource()); zzip_error_t error = ZZIP_NO_ERROR; archive_ = zzip_dir_open(diskSourceInternal.CString(), &error); if (CheckAndLogZzipError(error) || CheckAndLogArchiveError(archive_) || !archive_) { archive_ = 0; return false; } int uncompressing = 0; ZZIP_DIRENT archiveEntry; while(zzip_dir_read(archive_, &archiveEntry)) { String relativePath = Urho3D::GetInternalPath(archiveEntry.d_name); if (!relativePath.EndsWith("/")) { String subAssetRef = GetFullAssetReference(relativePath); ZipArchiveFile file; file.relativePath = relativePath; file.cachePath = Urho3D::GetInternalPath(assetAPI_->Cache()->DiskSourceByRef(subAssetRef)); file.lastModified = assetAPI_->Cache()->LastModified(subAssetRef); file.compressedSize = archiveEntry.d_csize; file.uncompressedSize = archiveEntry.st_size; /* Mark this file for extraction. If both cache files have valid dates and they differ extract. If they have the same date stamp skip extraction. Note that file.lastModified will be non-valid for non cached files so we will cover also missing files. */ file.doExtract = (zipLastModified > 0 && file.lastModified > 0) ? (zipLastModified != file.lastModified) : true; if (file.doExtract) uncompressing++; files_.Push(file); fileCount_++; } } // Close the zzip directory ptr Close(); // If the zip file was empty we don't want IsLoaded to fail on the files_ check. // The bundle loaded fine but there was no content, log a warning. if (files_.Empty()) { LogWarning("ZipAssetBundle: Bundle loaded but does not contain any files " + Name()); files_.Push(ZipArchiveFile()); Loaded.Emit(this); return true; } // Don't spin the worker if all sub assets are up to date in cache. if (uncompressing > 0) { // Now that the file info has been read, continue in a worker thread. LogDebug("ZipAssetBundle: File information read for " + Name() + ". File count: " + String(files_.Size()) + ". Starting worker thread to uncompress " + String(uncompressing) + " files."); // ZipWorker is a QRunnable we can pass to QThreadPool, it will handle scheduling it and deletes it when done. worker_ = new ZipWorker(this, zipLastModified, diskSourceInternal, files_); if (!worker_->Run()) { LogError("ZipAssetBundle: Failed to start worker thread for " + Name()); files_.Clear(); return false; } assetAPI_->GetFramework()->Frame()->Updated.Connect(this, &ZipAssetBundle::CheckDone); } else Loaded.Emit(this); return true; }
/** Creates a buffer of all the data in the SRTM file. The uncompressed version is used if available. * * \returns The length of the side of the data (e.g. 1201 or 3601) * \note The buffer returned is owned by the caller of this function and _must_ be freed after usage. */ int SrtmZipFile::getData(QString filename, qint16 **buffer) { *buffer = 0; QFileInfo fi(filename); QString uncompressedFile = fi.path()+'/'+fi.completeBaseName(); int size = 0; if (QFileInfo(uncompressedFile).exists()) { QFile file(uncompressedFile); if (!file.open(QIODevice::ReadOnly)) { qCritical() << "ZIP(Uncompressed): Could not open file" << uncompressedFile << file.errorString(); return 0; } size = sqrt(file.size()/2); if (size*size*2 != file.size()) { qCritical() << "ZIP(Uncompressed): Invalid data: Not a square!"; } *buffer = new qint16[file.size()/2]; if (!*buffer) { qCritical() << "ZIP(Uncompressed): Could not allocate buffer."; return 0; } if (file.read((char *)*buffer, file.size()) != file.size()) { qCritical() << "ZIP(Uncompressed): Could not read all bytes."; } file.close(); } else { ZZIP_DIR* dir = zzip_dir_open(filename.toAscii(), 0); if (!dir) { qCritical() << "ZIP: Could not open zip file" << filename; return 0; } ZZIP_FILE* fp = zzip_file_open(dir, fi.completeBaseName().toAscii(), 0); if (!fp) { qCritical() << "ZIP: Could not find" << fi.completeBaseName() << "in" << filename; return 0; } ZZIP_STAT stat; if (zzip_file_stat(fp, &stat) == -1) { qCritical() << "ZIP: Could not get info about" << uncompressedFile; return 0; } size = sqrt(stat.st_size/2); if (size*size*2 != stat.st_size) { qCritical() << "ZIP: Invalid data: Not a square!"; } *buffer = new qint16[stat.st_size/2]; if (zzip_file_read(fp, *buffer, stat.st_size) != stat.st_size) { qCritical() << "ZIP: Could not read all bytes."; delete *buffer; *buffer = 0; return 0; } //store uncompressed content on disk? if (false) { QFile file(uncompressedFile); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { qCritical() << "ZIP(Writing): Could not open file" << uncompressedFile << file.errorString(); } else { file.write((char *)*buffer, stat.st_size); file.close(); } } zzip_file_close(fp); zzip_dir_close(dir); } return size; }
void process_zip(char *pPath) { #ifdef HAVE_LIBZZIP ZZIP_DIR *dir; ZZIP_FILE *fp; ZZIP_DIRENT dirent; char buf[BUF_SIZE]; int nRead; long depth = 0; int ret = 0; dir = zzip_dir_open(pPath, 0); if (!dir) { return; } while (zzip_dir_read(dir, &dirent)) { fp = zzip_file_open(dir, dirent.d_name, 0); if (fp) { // pull the data and scan while ((nRead = zzip_file_read(fp, buf, BUF_SIZE)) > 0) { depth += nRead; if (is_match(buf,nRead)) { ret = 1; if (!LogTotalMatches) { send_match(hit,pPath); break; } } bzero(buf, sizeof(buf)); if ((ScanDepth != 0) && (depth >= (ScanDepth * 1024))) { break; } } zzip_file_close(fp); } } if ((LogTotalMatches && TotalMatches) || ret) { send_match(hit, pPath); } zzip_dir_close(dir); #else #ifdef HAVE_LIBZIP struct zip *za; int err, ret = 0, nRead; char errstr[1024], buf[BUF_SIZE]; long depth; if ((za = zip_open(pPath, 0, &err)) == NULL) { return; } while ((nRead = zip_fread(za, &buf, BUF_SIZE)) > 0) { depth += nRead; if (is_match(buf,nRead)) { ret = 1; if (!LogTotalMatches) { send_match(hit,pPath); zip_close(za); return; } } bzero(buf, sizeof(buf)); if ((ScanDepth != 0) && (depth >= (ScanDepth * 1024))) { break; } } if ((LogTotalMatches && TotalMatches) || ret) { send_match(hit, pPath); } zip_close(za); #endif /* HAVE_LIBZIP */ return; #endif /* HAVE_ZZIP */ }