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); }
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(); }
void ResourceManager::ShutDown() { #ifdef _CACH_PARSED_DATA_ for (std::map<const char*, ModelFileParser*>::iterator it = mModelFileParsers.begin(); it != mModelFileParsers.end(); it++) { delete it->second; } for (std::map<const char*, SoundData*>::iterator it = mSoundResource.begin(); it != mSoundResource.end(); it++) { delete it->second; } mModelFileParsers.clear(); mSoundResource.clear(); #endif switch ( mAssetPacketExtension ) { case PACA: mPacaReader.Close(); break; case ZIP: zzip_dir_close( mDir ); break; } mThreadPool.Destroy(); }
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; }
/** * the direct function of => zzip_close(fp). it will cleanup the * inflate-portion of => zlib and free the structure given. * * it is called quite from the error-cleanup parts * of the various => _open functions. * * the .refcount is decreased and if zero the fp->dir is closed just as well. */ int zzip_file_close(ZZIP_FILE * fp) { ZZIP_DIR * dir = fp->dir; if (fp->method) inflateEnd(&fp->d_stream); /* inflateEnd() can be called many times */ if (fp->buf32k) { if (dir->cache.buf32k == NULL) dir->cache.buf32k = fp->buf32k; else free(fp->buf32k); } if (dir->currentfp == fp) dir->currentfp = NULL; dir->refcount--; /* ease to notice possible dangling reference errors */ memset(fp, 0, sizeof(*fp)); if (dir->cache.fp == NULL) dir->cache.fp = fp; else free(fp); if (! dir->refcount) return zzip_dir_close(dir); else return 0; }
bool WaypointGlue::LoadWaypoints(Waypoints &way_points, const RasterTerrain *terrain, OperationEnvironment &operation) { LogFormat("ReadWaypoints"); operation.SetText(_("Loading Waypoints...")); bool found = false; // Delete old waypoints way_points.Clear(); TCHAR path[MAX_PATH]; LoadWaypointFile(way_points, LocalPath(path, _T("user.cup")), WaypointFileType::SEEYOU, WaypointOrigin::USER, terrain, operation); // ### FIRST FILE ### if (Profile::GetPath(ProfileKeys::WaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::PRIMARY, terrain, operation); // ### SECOND FILE ### if (Profile::GetPath(ProfileKeys::AdditionalWaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::ADDITIONAL, terrain, operation); // ### WATCHED WAYPOINT/THIRD FILE ### if (Profile::GetPath(ProfileKeys::WatchedWaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::WATCHED, terrain, operation); // ### MAP/FOURTH FILE ### // If no waypoint file found yet if (!found) { auto dir = OpenMapFile(); if (dir != nullptr) { found |= LoadWaypointFile(way_points, dir, "waypoints.xcw", WaypointFileType::WINPILOT, WaypointOrigin::MAP, terrain, operation); found |= LoadWaypointFile(way_points, dir, "waypoints.cup", WaypointFileType::SEEYOU, WaypointOrigin::MAP, terrain, operation); zzip_dir_close(dir); } } // Optimise the waypoint list after attaching new waypoints way_points.Optimise(); // Return whether waypoints have been loaded into the waypoint list return found; }
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; }
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; }
void ZipWorker::Close() { if (archive_) { zzip_dir_close(archive_); archive_ = 0; } }
void ZipAssetBundle::Close() { if (archive_) { zzip_dir_close(archive_); archive_ = 0; } }
/** 卸载ZIP文件包 */ void FZipFilePack::Unload(void) { if( m_pZipDir ) { zzip_dir_close( m_pZipDir ); m_pZipDir = NULL; m_FileInfos.clear(); } }
bool ArchiveZip::close() { ZZIP_DIR* zip = (ZZIP_DIR*) handle; if (!isValid) return true; int ret = zzip_dir_close(zip); return ret == ZZIP_NO_ERROR ; }
/** * Load topography from the map file (ZIP), load the other files from * the same ZIP file. */ static bool LoadConfiguredTopographyZip(TopographyStore &store, OperationEnvironment &operation) { auto dir = OpenMapFile(); if (dir == nullptr) return false; ZipLineReaderA reader(dir, "topology.tpl", IgnoreError()); if (reader.error()) { zzip_dir_close(dir); LogFormat(_T("No topography in map file")); return false; } store.Load(operation, reader, nullptr, dir); zzip_dir_close(dir); return true; }
//----------------------------------------------------------------------- void ZipArchive::unload() { if (mZzipDir) { zzip_dir_close(mZzipDir); mZzipDir = 0; mFileList.clear(); } }
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(); }
//----------------------------------------------------------------------- void ZipArchive::unload() { OGRE_LOCK_AUTO_MUTEX; if (mZzipDir) { zzip_dir_close(mZzipDir); mZzipDir = 0; mFileList.clear(); } }
static int zip_close (lua_State *L) { ZZIP_DIR* f = tofile(L, 1); if (zzip_dir_close(f) == 0) { *(ZZIP_DIR**)lua_touserdata(L, 1) = NULL; /* mark file as close */ lua_pushboolean(L, 1); } else lua_pushboolean(L, 0); return 1; }
void CZipArchive::unloadArchive() { // for(int i=0;i<m_files.size();++i){ // GCPtr<IStream>file=m_files[i].fileData; // } m_files.clear(); if(m_zipDir){ zzip_dir_close(m_zipDir); m_zipDir=0; } }
Updater::~Updater() { //关闭打开的zip文件 PATCHFILE_MAP::iterator it; for(it=m_mapPatchFile.begin(); it!=m_mapPatchFile.end(); it++) { ZZIP_DIR* mZzipDir = (ZZIP_DIR*)(it->second); if(mZzipDir) { zzip_dir_close(mZzipDir); mZzipDir = 0; } } m_mapPatchFile.clear(); }
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; }
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); }
/** * This function is the equivalent of => closedir(3) for a realdir or zipfile. * <p> * This function is magic - if the given arg-ZZIP_DIR * is a real directory, it will call the real => closedir(3) and then * free the wrapping ZZIP_DIR structure. Otherwise it will divert * to => zzip_dir_close which will free the ZZIP_DIR structure. */ int zzip_closedir(ZZIP_DIR* dir) { if (! dir) { errno = EBADF; return -1; } if (USE_DIRENT && dir->realdir) { _zzip_closedir(dir->realdir); free(dir->realname); free(dir); return 0; }else { zzip_dir_close(dir); return 0; } }
/** * This function is the equivalent of => closedir(3) for a realdir or zipfile. * * This function is magic - if the given arg-ZZIP_DIR * is a real directory, it will call the real => closedir(3) and then * free the wrapping ZZIP_DIR structure. Otherwise it will divert * to => zzip_dir_close which will free the ZZIP_DIR structure. */ int zzip_closedir(ZZIP_DIR * dir) { if (! dir) { kdSetError ( KD_EBADF ); return -1; } /* if (USE_DIRENT && dir->realdir) { _zzip_closedir(dir->realdir); free(dir->realname); free(dir); return 0; } else */ { zzip_dir_close(dir); return 0; } }
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; }
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; }
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); }
static TLineReader * OpenMapTextFile(const char *in_map_file, Charset cs) { assert(in_map_file != nullptr); auto dir = OpenMapFile(); if (dir == nullptr) return nullptr; Error error; ZipLineReader *reader = new ZipLineReader(dir, in_map_file, error, cs); zzip_dir_close(dir); if (reader == nullptr) { LogError(error); return nullptr; } if (reader->error()) { delete reader; return nullptr; } return reader; }
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; }