这篇教程C++ unzGoToFirstFile函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中unzGoToFirstFile函数的典型用法代码示例。如果您正苦于以下问题:C++ unzGoToFirstFile函数的具体用法?C++ unzGoToFirstFile怎么用?C++ unzGoToFirstFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了unzGoToFirstFile函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ExtractAllboolExtractAll (unzFile zip, const char *dir, CanonMode mode){ char *filename, *dirname, *path, *altpath; char *canonicalized_filename; unz_file_info info; int fd; if (unzGoToFirstFile (zip) != UNZ_OK) return false; do { unzGetCurrentFileInfo (zip, &info, NULL, 0, NULL, 0, NULL, 0); if (info.external_fa & (1 << 4)) continue; if (!(filename = (char *) g_malloc (info.size_filename + 1))) return false; unzGetCurrentFileInfo (zip, NULL, filename, info.size_filename + 1, NULL, 0, NULL, 0); canonicalized_filename = Deployment::GetCurrent ()->CanonicalizeFileName (filename, mode == CanonModeXap); path = g_build_filename (dir, canonicalized_filename, NULL); dirname = g_path_get_dirname (path); if (g_mkdir_with_parents (dirname, 0700) == -1 && errno != EEXIST) { g_free (filename); g_free (dirname); g_free (canonicalized_filename); g_free (path); return false; } g_free (dirname); if ((fd = g_open (path, O_CREAT | O_WRONLY | O_TRUNC, 0600)) == -1) { g_free (filename); g_free (canonicalized_filename); g_free (path); return false; } if (unzOpenCurrentFile (zip) != UNZ_OK) { g_free (filename); g_free (canonicalized_filename); g_free (path); close (fd); return false; } if (!ExtractFile (zip, fd)) { unzCloseCurrentFile (zip); g_free (filename); g_free (canonicalized_filename); g_free (path); return false; } unzCloseCurrentFile (zip); if (mode == CanonModeXap && is_dll_exe_or_mdb (filename, info.size_filename)) { g_free (canonicalized_filename); canonicalized_filename = Deployment::GetCurrent ()->CanonicalizeFileName (filename, false); altpath = g_build_filename (dir, canonicalized_filename, NULL); if (strcmp (path, altpath) != 0) symlink (path, altpath); g_free (altpath); } g_free (filename); g_free (canonicalized_filename); g_free (path); } while (unzGoToNextFile (zip) == UNZ_OK); return true;}
开发者ID:kangaroo,项目名称:moon,代码行数:77,
示例2: epError EditorExportPlatformJavaScript::export_project(const String& p_path,bool p_debug,const String& p_password) { String src_template; EditorProgress ep("export","Exporting for javascript",104); String template_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; if (p_debug) { src_template=custom_debug_package!=""?custom_debug_package:template_path+"javascript_debug.zip"; } else { src_template=custom_release_package!=""?custom_release_package:template_path+"javascript_release.zip"; } FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); ep.step("Exporting to HTML5",0); ep.step("Finding Files..",1); FileAccess *f=FileAccess::open(p_path.get_base_dir()+"/data.pck",FileAccess::WRITE); if (!f) { EditorNode::add_io_error("Could not create file for writing:/n"+p_path.basename()+"_files.js"); return ERR_FILE_CANT_WRITE; } Error err = save_pack(f); size_t len = f->get_len(); memdelete(f); if (err) return err; unzFile pkg = unzOpen2(src_template.utf8().get_data(), &io); if (!pkg) { EditorNode::add_io_error("Could not find template HTML5 to export:/n"+src_template); return ERR_FILE_NOT_FOUND; } ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN); int ret = unzGoToFirstFile(pkg); while(ret==UNZ_OK) { //get filename unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0); String file=fname; Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); unzReadCurrentFile(pkg,data.ptr(),data.size()); unzCloseCurrentFile(pkg); //write if (file=="godot.html") { _fix_html(data,p_path.get_file().basename(),1<<(max_memory+5)); file=p_path.get_file(); } if (file=="filesystem.js") { _fix_files(data,len); file=p_path.get_file().basename()+"_filesystem.js"; } if (file=="godot.js") { //_fix_godot(data); file=p_path.get_file().basename()+".js"; } String dst = p_path.get_base_dir().plus_file(file); FileAccess *f=FileAccess::open(dst,FileAccess::WRITE); if (!f) { EditorNode::add_io_error("Could not create file for writing:/n"+dst); unzClose(pkg); return ERR_FILE_CANT_WRITE; } f->store_buffer(data.ptr(),data.size()); memdelete(f); ret = unzGoToNextFile(pkg); }//.........这里部分代码省略.........
开发者ID:19Staceys,项目名称:godot,代码行数:101,
示例3: GetFilesInZip/** ************************************************************************** * /brief List files in zip and append their names to p_array * /param p_this * /param file Opened zip file * /param p_array vlc_array_t which will receive all filenames * * In case of error, returns VLC_EGENERIC. * In case of success, returns number of files found, and goes back to first file. *****************************************************************************/static int GetFilesInZip( stream_t *p_this, unzFile file, vlc_array_t *p_filenames, vlc_array_t *p_fileinfos ){ if( !p_filenames || !p_this ) return VLC_EGENERIC; int i_ret = 0; /* Get global info */ unz_global_info info; if( unzGetGlobalInfo( file, &info ) != UNZ_OK ) { msg_Warn( p_this, "this is not a valid zip archive" ); return VLC_EGENERIC; } /* Go to first file in archive */ unzGoToFirstFile( file ); /* Get info about each file */ for( unsigned long i = 0; i < info.number_entry; i++ ) { char *psz_fileName = calloc( ZIP_FILENAME_LEN, 1 ); unz_file_info *p_fileInfo = calloc( 1, sizeof( unz_file_info ) ); if( !p_fileInfo || !psz_fileName ) { free( psz_fileName ); free( p_fileInfo ); return VLC_ENOMEM; } if( unzGetCurrentFileInfo( file, p_fileInfo, psz_fileName, ZIP_FILENAME_LEN, NULL, 0, NULL, 0 ) != UNZ_OK ) { msg_Warn( p_this, "can't get info about file in zip" ); return VLC_EGENERIC; } if( p_filenames ) vlc_array_append( p_filenames, strdup( psz_fileName ) ); free( psz_fileName ); if( p_fileinfos ) vlc_array_append( p_fileinfos, p_fileInfo ); else free( p_fileInfo ); if( i < ( info.number_entry - 1 ) ) { /* Go the next file in the archive */ if( unzGoToNextFile( file ) != UNZ_OK ) { msg_Warn( p_this, "can't go to next file in zip" ); return VLC_EGENERIC; } } i_ret++; } /* i_ret should be equal to info.number_entry */ unzGoToFirstFile( file ); return i_ret;}
开发者ID:371816210,项目名称:vlc_vlc,代码行数:76,
示例4: FS_LoadPK3/* * Takes an explicit (not game tree related) path to a pack file. * * Loads the header and directory, adding the files at the beginning of the list * so they override previous pack files. */fsPack_t *FS_LoadPK3(const char *packPath){ char fileName[MAX_QPATH]; /* File name. */ int i = 0; /* Loop counter. */ int numFiles; /* Number of files in PK3. */ int status; /* Error indicator. */ fsPackFile_t *files; /* List of files in PK3. */ fsPack_t *pack; /* PK3 file. */ unzFile *handle; /* Zip file handle. */ unz_file_info info; /* Zip file info. */ unz_global_info global; /* Zip file global info. */ handle = unzOpen(packPath); if (handle == NULL) { return NULL; } if (unzGetGlobalInfo(handle, &global) != UNZ_OK) { unzClose(handle); Com_Error(ERR_FATAL, "FS_LoadPK3: '%s' is not a pack file", packPath); } numFiles = global.number_entry; if ((numFiles > MAX_FILES_IN_PACK) || (numFiles == 0)) { unzClose(handle); Com_Error(ERR_FATAL, "FS_LoadPK3: '%s' has %i files", packPath, numFiles); } files = Z_Malloc(numFiles * sizeof(fsPackFile_t)); /* Parse the directory. */ status = unzGoToFirstFile(handle); while (status == UNZ_OK) { fileName[0] = '/0'; unzGetCurrentFileInfo(handle, &info, fileName, MAX_QPATH, NULL, 0, NULL, 0); Q_strlcpy(files[i].name, fileName, sizeof(files[i].name)); files[i].offset = -1; /* Not used in ZIP files */ files[i].size = info.uncompressed_size; i++; status = unzGoToNextFile(handle); } pack = Z_Malloc(sizeof(fsPack_t)); Q_strlcpy(pack->name, packPath, sizeof(pack->name)); pack->pak = NULL; pack->pk3 = handle; pack->numFiles = numFiles; pack->files = files; Com_Printf("Added packfile '%s' (%i files)./n", pack, numFiles); return pack;}
开发者ID:Jenco420,项目名称:yquake2,代码行数:69,
示例5: crpOpenErrorReportWcrpOpenErrorReportW( LPCWSTR pszFileName, LPCWSTR pszMd5Hash, LPCWSTR pszSymSearchPath, DWORD dwFlags, CrpHandle* pHandle){ UNREFERENCED_PARAMETER(dwFlags); int status = -1; int nNewHandle = 0; CrpReportData report_data; int zr = 0; int xml_find_res = UNZ_END_OF_LIST_OF_FILE; int dmp_find_res = UNZ_END_OF_LIST_OF_FILE; char szXmlFileName[1024]=""; char szDmpFileName[1024]=""; char szFileName[1024]=""; CString sCalculatedMD5Hash; CString sAppName; strconv_t strconv; crpSetErrorMsg(_T("Unspecified error.")); *pHandle = 0; report_data.m_sSymSearchPath = pszSymSearchPath; report_data.m_pDescReader = new CCrashDescReader; report_data.m_pDmpReader = new CMiniDumpReader; // Check dbghelp.dll version if(!report_data.m_pDmpReader->CheckDbgHelpApiVersion()) { crpSetErrorMsg(_T("Invalid dbghelp.dll version (v6.11 expected).")); goto exit; // Invalid hash } // Check ZIP integrity if(pszMd5Hash!=NULL) { int result = CalcFileMD5Hash(pszFileName, sCalculatedMD5Hash); if(result!=0) goto exit; if(sCalculatedMD5Hash.CompareNoCase(pszMd5Hash)!=0) { crpSetErrorMsg(_T("File might be corrupted, because MD5 hash is wrong.")); goto exit; // Invalid hash } } // Open ZIP archive report_data.m_hZip = unzOpen((const char*)pszFileName); if(report_data.m_hZip==NULL) { crpSetErrorMsg(_T("Error opening ZIP archive.")); goto exit; } // Look for v1.1 crash description XML xml_find_res = unzLocateFile(report_data.m_hZip, (const char*)"crashrpt.xml", 1); zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szXmlFileName, 1024, NULL, 0, NULL, 0); // Look for v1.1 crash dump dmp_find_res = unzLocateFile(report_data.m_hZip, (const char*)"crashdump.dmp", 1); zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szDmpFileName, 1024, NULL, 0, NULL, 0); // If xml and dmp still not found, assume it is v1.0 if(xml_find_res!=UNZ_OK && dmp_find_res!=UNZ_OK) { // Look for .dmp file zr = unzGoToFirstFile(report_data.m_hZip); if(zr==UNZ_OK) { for(;;) { zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szDmpFileName, 1024, NULL, 0, NULL, 0); if(zr!=UNZ_OK) break; CString sFileName = szDmpFileName; CString sExt = Utility::GetFileExtension(sFileName); if(sExt.CompareNoCase(_T("dmp"))==0) { // DMP found sAppName = Utility::GetBaseFileName(sFileName); dmp_find_res = UNZ_OK; break; } zr=unzGoToNextFile(report_data.m_hZip); if(zr!=UNZ_OK) break; } } // Assume the name of XML is the same as DMP CString sXmlName = Utility::GetBaseFileName(CString(szDmpFileName)) + _T(".xml"); zr = unzLocateFile(report_data.m_hZip, strconv.t2a(sXmlName), 1); zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szXmlFileName, 1024, NULL, 0, NULL, 0);//.........这里部分代码省略.........
开发者ID:cedral,项目名称:crashrptex,代码行数:101,
示例6: apedax_get_data_fieldstatic GwyDataField*apedax_get_data_field(unzFile uFile, const gchar *chFileName, const APEScanSize *scanSize, gchar *zUnit, gdouble scale, GError **error){ GwyDataField *dfield = NULL; GwySIUnit *xyUnit; GwySIUnit *zSIUnit; gdouble *data; guchar *buffer; gsize size, expectedSize; unz_file_info uFileInfo; /*Checking the dimensions*/ if (err_DIMENSION(error, scanSize->XRes)) { return NULL; } if (err_DIMENSION(error, scanSize->YRes)) { return NULL; } /*If XReal it's not greater than 0 or XReal is NaN*/ if (!(fabs(scanSize->XReal) > 0)) { err_UNSUPPORTED(error, "X scan size"); return NULL; } /*Same for YReal*/ if (!(fabs(scanSize->YReal) > 0)) { err_UNSUPPORTED(error, "Y scan size"); return NULL; } expectedSize = scanSize->XRes * scanSize->YRes * sizeof(gdouble); unzGoToFirstFile(uFile); if (unzLocateFile(uFile, chFileName, 0) != UNZ_OK) { gwy_debug("Binary file not found"); err_NO_DATA(error); return NULL; } if (unzGetCurrentFileInfo(uFile, &uFileInfo, NULL, 0L, NULL, 0L, NULL, 0L) != UNZ_OK) { err_NO_DATA(error); return NULL; } buffer = apedax_get_file_content(uFile, &uFileInfo, &size, error); if (buffer == NULL) { err_NO_DATA(error); return NULL; } if (err_SIZE_MISMATCH(error, expectedSize, size, FALSE)) { return NULL; } dfield = gwy_data_field_new(scanSize->XRes, scanSize->YRes, scanSize->XReal, scanSize->YReal, FALSE); data = gwy_data_field_get_data(dfield); xyUnit = gwy_data_field_get_si_unit_xy(dfield); gwy_si_unit_set_from_string(xyUnit, "m"); zSIUnit = gwy_data_field_get_si_unit_z(dfield); gwy_si_unit_set_from_string(zSIUnit, zUnit); gwy_debug("Reading RAW data"); gwy_convert_raw_data(buffer, scanSize->XRes * scanSize->YRes, 1, GWY_RAW_DATA_DOUBLE, GWY_BYTE_ORDER_LITTLE_ENDIAN, data, scale, 0.0); return dfield;}
开发者ID:DavidMercier,项目名称:gwyddion,代码行数:95,
示例7: load_zip_archivevoid load_zip_archive(const char* file_name){ unzFile file; unz_file_info64 info; unz_global_info64 global_info; el_zip_file_entry_t* files; char* name; Uint32 i, count, size, index; if (file_name == 0) { LOG_ERROR("Empty zip file name", file_name); return; } if (num_zip_files >= MAX_NUM_ZIP_FILES) { LOG_ERROR("Can't add zip file %s", file_name); return; } file = unzOpen64(file_name); if (unzGetGlobalInfo64(file, &global_info) != UNZ_OK) { LOG_ERROR("Can't load zip file %s", file_name); unzClose(file); return; } count = global_info.number_entry; if (unzGoToFirstFile(file) != UNZ_OK) { LOG_ERROR("Can't load zip file %s", file_name); unzClose(file); return; } ENTER_DEBUG_MARK("load zip"); LOG_DEBUG("Loading zip file '%s' with %d files", file_name, count); files = malloc(count * sizeof(el_zip_file_entry_t)); for (i = 0; i < count; i++) { unzGetFilePos64(file, &files[i].position); unzGetCurrentFileInfo64(file, &info, 0, 0, 0, 0, 0, 0); size = info.size_filename; files[i].file_name = calloc(size + 1, 1); unzGetCurrentFileInfo64(file, 0, files[i].file_name, size, 0, 0, 0, 0); LOG_DEBUG("Loading file (%d) '%s' from zip file '%s'.", i, files[i].file_name, file_name); files[i].hash = mem_hash(files[i].file_name, size); unzGoToNextFile(file); } size = strlen(file_name); name = calloc(size + 1, 1); memcpy(name, file_name, size); LOG_DEBUG("Sorting files from zip file '%s'.", file_name); qsort(files, count, sizeof(el_zip_file_entry_t), compare_el_zip_file_entry); CHECK_AND_LOCK_MUTEX(zip_mutex); index = num_zip_files; for (i = 0; i < num_zip_files; i++) { if (zip_files[i].file_name == 0) { index = i; break; } } num_zip_files = max2u(num_zip_files, index + 1); CHECK_AND_LOCK_MUTEX(zip_files[index].mutex); CHECK_AND_UNLOCK_MUTEX(zip_mutex);//.........这里部分代码省略.........
开发者ID:Adamantinus,项目名称:Eternal-Lands,代码行数:101,
示例8: returnbool QZipFile::gotoFirstEntry(){ return (unzGoToFirstFile(m_unzFile) == UNZ_OK);}
开发者ID:gonzoua,项目名称:qompress,代码行数:4,
示例9: unzOpenint F3DFile::ReadMD3(const char *pFilename){ pModel = this; char *pBuffer = NULL; // open .pk3 file unzFile zipFile = unzOpen(pFilename); // iterate files in zip int zipFileIndex = unzGoToFirstFile(zipFile); while(zipFileIndex != UNZ_END_OF_LIST_OF_FILE) { MFDebug_Assert(zipFileIndex == UNZ_OK, "Error in .zip file."); char fileName[256]; unz_file_info fileInfo; unzGetCurrentFileInfo(zipFile, &fileInfo, fileName, 256, NULL, 0, NULL, 0); int filenameLen = MFString_Length(fileName); if(!MFString_CaseCmp(".md3", &fileName[MFMax(filenameLen - 4, 0)])) { // read fle from zip pBuffer = (char*)malloc(fileInfo.uncompressed_size); unzOpenCurrentFile(zipFile); uint32 bytesRead = unzReadCurrentFile(zipFile, pBuffer, fileInfo.uncompressed_size); unzCloseCurrentFile(zipFile); MFDebug_Assert(bytesRead == fileInfo.uncompressed_size, "Incorrect number of bytes read.."); // get subobject and model name.. int a, b; for(a = filenameLen - 4; a >= 0; a--) { if(fileName[a] == '/' || fileName[a] == '//') break; } char *pSubobjectName = &fileName[a+1]; for(b = a-1; b >= 0; b--) { if(fileName[b] == '/' || fileName[b] == '//') break; } MFString_Copy(pModel->name, &fileName[b+1]); pModel->name[a-b-1] = 0; // search for skin file char skinFilename[256]; MFString_Copy(skinFilename, fileName); skinFilename[MFString_Length(skinFilename) - 4] = 0; MFString_Cat(skinFilename, "_"); MFString_Cat(skinFilename, pModel->name); MFString_Cat(skinFilename, ".skin"); // attempt to read skin.. char *pSkinFile = NULL; zipFileIndex = unzLocateFile(zipFile, skinFilename, 0); if(zipFileIndex != UNZ_END_OF_LIST_OF_FILE) { // read skin file from zip unz_file_info skinInfo; char skinName[256]; unzGetCurrentFileInfo(zipFile, &skinInfo, skinName, 256, NULL, 0, NULL, 0); pSkinFile = (char*)malloc(skinInfo.uncompressed_size + 1); pSkinFile[skinInfo.uncompressed_size] = 0; unzOpenCurrentFile(zipFile); uint32 skinBytesRead = unzReadCurrentFile(zipFile, pSkinFile, skinInfo.uncompressed_size); unzCloseCurrentFile(zipFile); MFDebug_Assert(skinBytesRead == skinInfo.uncompressed_size, "Incorrect number of bytes read.."); } zipFileIndex = unzLocateFile(zipFile, fileName, 0); // parse MD3 ParseMD3File(pBuffer, fileInfo.uncompressed_size, pSubobjectName, pSkinFile); // free file free(pBuffer); pBuffer = NULL; }/* else if(!MFString_CaseCmp(".skin", &fileName[Max(filenameLen - 5, 0)])) { int a, b; char skinName[256]; // get subobject and model name//.........这里部分代码省略.........
开发者ID:RemedyGameJam,项目名称:fuji,代码行数:101,
示例10: memset// 从压缩包中读取文件VFile* FileSystem::openFileFromPak(const char* filename){ if (m_pakFileMap.empty()) return NULL; int done = 0; unzFile zip; unz_file_info file_info; char szName[MAX_PATH]; memset(szName, 0, sizeof(szName)); char szZipName[MAX_PATH]; memset(szZipName, 0, sizeof(szZipName)); strncpy(szName,filename,sizeof(szName)-1); NormalFileName(szName); Platform::strlwr(szName); if (szName[0] == '.' && szName[1] == '/') { // 去除"./"符号 memcpy(szName, szName+2, sizeof(szName)); } VFile* pVFile = NULL; for (PakFileMapIter it=m_pakFileMap.begin(); it != m_pakFileMap.end(); ++it) { stPakFile& pakFile = it->second; zip=unzOpen(pakFile.filename.c_str()); done=unzGoToFirstFile(zip); while(done==UNZ_OK) { unzGetCurrentFileInfo(zip, &file_info, szZipName, sizeof(szZipName), NULL, 0, NULL, 0); NormalFileName(szZipName); Platform::strlwr(szZipName); if ( strcmp(szZipName,szName) != 0 ) { done=unzGoToNextFile(zip); continue; } char password[2048]; memset(password,0,sizeof(password)); if (pakFile.password.size() > 0) { size_t pswdLen = pakFile.password.size(); for (size_t i=0; i<pswdLen; ++i) { password[i] = pakFile.password[i]; password[i] = password[i] ^ pakFile.key; } } if(unzOpenCurrentFilePassword(zip, password[0] ? password : 0) != UNZ_OK) { unzClose(zip); return NULL; } memset(password,0,sizeof(password)); pVFile = new VFile; if (pVFile == NULL) { unzCloseCurrentFile(zip); unzClose(zip); return NULL; } pVFile->m_ptrSrc = new byte[file_info.uncompressed_size]; if (pVFile->m_ptrSrc == NULL) { delete pVFile; unzCloseCurrentFile(zip); unzClose(zip); return NULL; } pVFile->m_size = file_info.uncompressed_size; pVFile->m_ptrCur = pVFile->m_ptrSrc; memset(pVFile->m_ptrSrc,0,file_info.uncompressed_size); if(unzReadCurrentFile(zip, pVFile->m_ptrSrc, file_info.uncompressed_size) < 0) { pVFile->release(); delete pVFile; unzCloseCurrentFile(zip); unzClose(zip); return NULL; } unzCloseCurrentFile(zip); unzClose(zip); return pVFile; } unzClose(zip); } return NULL;}
开发者ID:ueverything,项目名称:easyserver,代码行数:92,
示例11: unzOpenBOOL vmsUnZip::Unpack(LPCTSTR ptszFileName, LPCTSTR ptszDstFolder){ USES_CONVERSION; BOOL result = FALSE; unzFile zipFile = unzOpen (CT2AEX<> ((LPTSTR)ptszFileName)); if (NULL != zipFile) { if (UNZ_OK == unzGoToFirstFile(zipFile)) { BOOL bContinue = TRUE; while (bContinue) { result = FALSE; unz_file_info fi; char filename[MAX_PATH] = {0}; if (UNZ_OK == unzGetCurrentFileInfo(zipFile, &fi, filename, sizeof (filename), 0, 0, 0, 0)) { if (*filename && (filename [strlen (filename)-1] == '/' || filename [strlen (filename)-1] == '//')) { assert (fi.uncompressed_size == 0); tstring tstr = ptszDstFolder; tstr += '//'; tstr += CA2TEX<> (filename); tstr += '1'; vmsBuildPathToFile (tstr.c_str ()); result = TRUE; } else if (UNZ_OK == unzOpenCurrentFile(zipFile)) { UINT dataLen = fi.uncompressed_size; BYTE* fileData = new BYTE[dataLen]; if (!fileData) break; if(dataLen == unzReadCurrentFile(zipFile, fileData, dataLen)) { char filePathName[MAX_PATH] = {0}; strcat (filePathName, T2A ((LPTSTR)ptszDstFolder)); strcat (filePathName, "//"); strcat (filePathName, filename); while (strchr (filePathName, '/')) *strchr (filePathName, '/') = '//'; FILE* pFile = fopen (filePathName, "wb"); if (!pFile) { vmsBuildPathToFile (CA2TEX<> (filePathName)); pFile = fopen (filePathName, "wb"); } if (pFile) { result = (dataLen == fwrite(fileData, 1, dataLen, pFile)); result = result && (0 == fclose(pFile)); } } delete [] fileData; result = result && (UNZ_OK == unzCloseCurrentFile(zipFile)); } } if (!result) break; if (UNZ_END_OF_LIST_OF_FILE == unzGoToNextFile(zipFile)) bContinue = FALSE; } } result = result && (UNZ_OK == unzClose(zipFile)); } return result;}
开发者ID:HackLinux,项目名称:Free-Download-Manager-vs2010,代码行数:68,
示例12: load_archiveint load_archive(char *filename, unsigned char *buffer, int maxsize, char *extension){ int size = 0; if(check_zip(filename)) { unz_file_info info; int ret = 0; char fname[256]; /* Attempt to open the archive */ unzFile *fd = unzOpen(filename); if (!fd) return 0; /* Go to first file in archive */ ret = unzGoToFirstFile(fd); if(ret != UNZ_OK) { unzClose(fd); return 0; } /* Get file informations and update filename */ ret = unzGetCurrentFileInfo(fd, &info, fname, 256, NULL, 0, NULL, 0); if(ret != UNZ_OK) { unzClose(fd); return 0; } /* Compressed filename extension */ if (extension) { strncpy(extension, &fname[strlen(fname) - 3], 3); extension[3] = 0; } /* Open the file for reading */ ret = unzOpenCurrentFile(fd); if(ret != UNZ_OK) { unzClose(fd); return 0; } /* Retrieve uncompressed file size */ size = info.uncompressed_size; if(size > maxsize) { size = maxsize; } /* Read (decompress) the file */ ret = unzReadCurrentFile(fd, buffer, size); if(ret != size) { unzCloseCurrentFile(fd); unzClose(fd); return 0; } /* Close the current file */ ret = unzCloseCurrentFile(fd); if(ret != UNZ_OK) { unzClose(fd); return 0; } /* Close the archive */ ret = unzClose(fd); if(ret != UNZ_OK) return 0; } else { /* Open file */ gzFile *gd = gzopen(filename, "rb"); if (!gd) return 0; /* Read file data */ size = gzread(gd, buffer, maxsize); /* filename extension */ if (extension) { strncpy(extension, &filename[strlen(filename) - 3], 3); extension[3] = 0; } /* Close file */ gzclose(gd); } /* Return loaded ROM size */ return size;}
开发者ID:Baubascat,项目名称:Provenance,代码行数:96,
示例13: RunScript//.........这里部分代码省略......... { if (scriptLog) fprintf(scriptLog, "Copying %s to %s/n", from_buf, to_buf); ok = FileToBlock(from_buf, &mem, &len); if (!ok) return; ok = BlockToFile(to_buf, mem); if (!ok) return; free(mem); } else { if (scriptLog) fprintf(scriptLog, "Not copying %s to %s/n", from_buf, to_buf); } } if (!strcmp(t, "UNZIP")) { t = next_token(&p); sprintf(msgBuf, "Installing %s...", t); strcpy(from_buf, app_path); strip_to_delim(from_buf,DIR_CHAR); strcat(from_buf, t); if (!strcmp(p, "/")) { strcpy(partial, path); strcat(partial, DIR_STR); } else { strcpy(partial, path); strcat(partial, DIR_STR); strcat(partial, p); } normalize_dir_chars(partial); normalize_dir_chars(from_buf); if (condition) { if (scriptLog) fprintf(scriptLog, "Unzipping %s to %s/n", from_buf, partial); unzFile unz = unzOpen(from_buf); if (unz == NULL) { ReportError("Unable to open zip file.", EUNKNOWN, from_buf); return; } unz_global_info global; unzGetGlobalInfo(unz, &global); unzGoToFirstFile(unz); int counter = 0; do { char zip_path[1024]; unz_file_info info; unzGetCurrentFileInfo(unz, &info, zip_path, sizeof(zip_path), NULL, 0, NULL, 0); sprintf(msgBuf, "Installing %s...", zip_path); float prog = (global.number_entry > 0) ? ((float) counter / (float) global.number_entry) : -1.0; ShowProgressMessage(msgBuf, &prog); ++counter; strcpy(to_buf, partial); strcat(to_buf, zip_path); normalize_dir_chars(to_buf); strip_to_delim(to_buf, DIR_CHAR); MakeDirExist(to_buf); if (info.uncompressed_size == 0) continue; char * mem = (char *) malloc(info.uncompressed_size); if (!mem) { ReportError("Out of memory", ENOMEM, NULL); return; } unzOpenCurrentFile(unz); int result = unzReadCurrentFile(unz,mem, info.uncompressed_size); if (result != info.uncompressed_size) { ReportError("Could not read installer archive.", EUNKNOWN, zip_path); } unzCloseCurrentFile(unz); strcpy(to_buf, partial); strcat(to_buf, zip_path); normalize_dir_chars(to_buf); FILE * fi = fopen(to_buf, "wb"); if (fi == NULL) { ReportError("Could not create file", errno, to_buf); return; } result = fwrite(mem, 1, info.uncompressed_size, fi); if (result != info.uncompressed_size) { ReportError("Could not read installer archive.", errno, to_buf); } fclose(fi); free(mem); } while(unzGoToNextFile(unz) == UNZ_OK); unzClose(unz); } else { if (scriptLog) fprintf(scriptLog, "Not unzipping %s to %s/n", from_buf, partial); } } } InstallErrFunc(old, NULL); if (scriptLog) fprintf(scriptLog, "Installer completed successfully./n"); if (scriptLog) fclose(scriptLog); DoUserAlert("Installation was successful!");}
开发者ID:highattack30,项目名称:xptools,代码行数:101,
示例14: pathname//.........这里部分代码省略......... const char *path, zlib_filefunc_def* pzlib_filefunc_def){ unz_s us; unz_s *s; uLong central_pos,uL; uLong number_disk; /* number of the current dist, used for spaning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used for spaning ZIP, unsupported, always 0*/ uLong number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ int err=UNZ_OK; if (unz_copyright[0]!=' ') return NULL; if (pzlib_filefunc_def==NULL) fill_fopen_filefunc(&us.z_filefunc); else us.z_filefunc = *pzlib_filefunc_def; us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, path, ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_EXISTING); if (us.filestream==NULL) return NULL; central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); if (central_pos==0) err=UNZ_ERRNO; if (ZSEEK(us.z_filefunc, us.filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) err=UNZ_ERRNO; /* the signature, already checked */ if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) err=UNZ_ERRNO; /* number of this disk */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) err=UNZ_ERRNO; /* number of the disk with the start of the central directory */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir on this disk */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) err=UNZ_ERRNO; if ((number_entry_CD!=us.gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; /* size of the central directory */ if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* offset of start of central directory with respect to the starting disk number */ if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* zipfile comment length */ if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) err=UNZ_ERRNO; if ((central_pos<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; if (err!=UNZ_OK) { ZCLOSE(us.z_filefunc, us.filestream); return NULL; } us.byte_before_the_zipfile = central_pos - (us.offset_central_dir+us.size_central_dir); us.central_pos = central_pos; us.pfile_in_zip_read = NULL; us.encrypted = 0; s=(unz_s*)ALLOC(sizeof(unz_s)); *s=us; unzGoToFirstFile((unzFile)s); return (unzFile)s;}
开发者ID:Aura15,项目名称:OpenJK,代码行数:101,
示例15: fill_win32_filefunc/////////////////////////////////////////////////////////////////// CResourceChecker::ReplaceFilesInZIP//// Based on example at http://www.winimage.com/zLibDll/minizip.html// by Ivan A. Krestinin/////////////////////////////////////////////////////////////////int CResourceChecker::ReplaceFilesInZIP( const string& strOrigZip, const string& strTempZip, const vector < string >& pathInArchiveList, const vector < string >& m_upgradedFullPathList ){ // open source and destination file zlib_filefunc_def ffunc; #ifdef WIN32 fill_win32_filefunc(&ffunc); #else fill_fopen_filefunc(&ffunc); #endif zipFile szip = unzOpen2(strOrigZip.c_str(), &ffunc); if (szip==NULL) { /*free(tmp_name);*/ return 0; } zipFile dzip = zipOpen2(strTempZip.c_str(), APPEND_STATUS_CREATE, NULL, &ffunc); if (dzip==NULL) { unzClose(szip); /*free(tmp_name);*/ return 0; } // get global commentary unz_global_info glob_info; if (unzGetGlobalInfo(szip, &glob_info) != UNZ_OK) { zipClose(dzip, NULL); unzClose(szip); /*free(tmp_name);*/ return 0; } char* glob_comment = NULL; if (glob_info.size_comment > 0) { glob_comment = (char*)malloc(glob_info.size_comment+1); if ((glob_comment==NULL)&&(glob_info.size_comment!=0)) { zipClose(dzip, NULL); unzClose(szip); /*free(tmp_name);*/ return 0; } if ((unsigned int)unzGetGlobalComment(szip, glob_comment, glob_info.size_comment+1) != glob_info.size_comment) { zipClose(dzip, NULL); unzClose(szip); free(glob_comment); /*free(tmp_name);*/ return 0; } } // copying files int n_files = 0; int rv = unzGoToFirstFile(szip); while (rv == UNZ_OK) { // get zipped file info unz_file_info unzfi; char dos_fn[MAX_PATH]; if (unzGetCurrentFileInfo(szip, &unzfi, dos_fn, MAX_PATH, NULL, 0, NULL, 0) != UNZ_OK) break; char fn[MAX_PATH]; #ifdef WIN32 OemToChar(dos_fn, fn); #endif // See if file should be replaced string fullPathReplacement; for ( unsigned long i = 0 ; i < pathInArchiveList.size () ; i++ ) if ( stricmp ( fn, pathInArchiveList[i].c_str () ) == 0 ) fullPathReplacement = m_upgradedFullPathList[i]; // Replace file in zip if ( fullPathReplacement.length () ) { void* buf = NULL; unsigned long ulLength = 0; // Get new file into a buffer if ( FILE* pFile = File::Fopen ( fullPathReplacement.c_str (), "rb" ) ) { // Get the file size, fseek( pFile, 0, SEEK_END ); ulLength = ftell( pFile ); fseek( pFile, 0, SEEK_SET ); // Load file into a buffer buf = malloc( ulLength ); if ( fread ( buf, 1, ulLength, pFile ) != ulLength ) { free( buf ); buf = NULL; } // Clean up fclose ( pFile ); } if( !buf ) break; // open destination file zip_fileinfo zfi; memcpy (&zfi.tmz_date, &unzfi.tmu_date, sizeof(tm_unz)); zfi.dosDate = unzfi.dosDate; zfi.internal_fa = unzfi.internal_fa; zfi.external_fa = unzfi.external_fa; char* extrafield = NULL; char* commentary = NULL; int size_local_extra = 0; void* local_extra = NULL; int unzfi_size_file_extra = 0; int method = Z_DEFLATED; int level = Z_DEFAULT_COMPRESSION;//.........这里部分代码省略.........
开发者ID:ljnx86,项目名称:mtasa-blue,代码行数:101,
示例16: IMZ_libLoad_DiskFileint IMZ_libLoad_DiskFile(HXCFLOPPYEMULATOR* floppycontext,FLOPPY * floppydisk,char * imgfile,void * parameters){ unsigned int filesize; unsigned int i,j; unsigned int file_offset; unsigned short sectorsize; unsigned char gap3len,skew,trackformat,interleave; char filename_inzip[256]; unsigned char* flatimg; int err=UNZ_OK; unzFile uf; unz_file_info file_info; CYLINDER* currentcylinder; unsigned short rpm; floppycontext->hxc_printf(MSG_DEBUG,"IMZ_libLoad_DiskFile %s",imgfile); uf=unzOpen (imgfile); if (!uf) { floppycontext->hxc_printf(MSG_ERROR,"unzOpen: Error while reading the file!"); return HXCFE_BADFILE; } unzGoToFirstFile(uf); err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) { unzClose(uf); return HXCFE_BADFILE; } err=unzOpenCurrentFile(uf); if (err!=UNZ_OK) { unzClose(uf); return HXCFE_BADFILE; } filesize=file_info.uncompressed_size; flatimg=(unsigned char*)malloc(filesize); if(!flatimg) { floppycontext->hxc_printf(MSG_ERROR,"Unpack error!"); return HXCFE_BADFILE; } err=unzReadCurrentFile (uf, flatimg, filesize); if (err<0) { floppycontext->hxc_printf(MSG_ERROR,"error %d with zipfile in unzReadCurrentFile",err); unzClose(uf); free(flatimg); return HXCFE_BADFILE; } unzClose(uf); if(pc_imggetfloppyconfig( flatimg, filesize, &floppydisk->floppyNumberOfTrack, &floppydisk->floppyNumberOfSide, &floppydisk->floppySectorPerTrack, &gap3len, &interleave, &rpm, &floppydisk->floppyBitRate, &floppydisk->floppyiftype)==1 ) { sectorsize=512; skew=0; trackformat=IBMFORMAT_DD; floppydisk->tracks=(CYLINDER**)malloc(sizeof(CYLINDER*)*floppydisk->floppyNumberOfTrack); for(j=0;j<floppydisk->floppyNumberOfTrack;j++) { floppydisk->tracks[j]=allocCylinderEntry(rpm,floppydisk->floppyNumberOfSide); currentcylinder=floppydisk->tracks[j]; for(i=0;i<floppydisk->floppyNumberOfSide;i++) { file_offset=(sectorsize*(j*floppydisk->floppySectorPerTrack*floppydisk->floppyNumberOfSide))+ (sectorsize*(floppydisk->floppySectorPerTrack)*i); currentcylinder->sides[i]=tg_generateTrack(&flatimg[file_offset],sectorsize,floppydisk->floppySectorPerTrack,(unsigned char)j,(unsigned char)i,1,interleave,(unsigned char)(((j<<1)|(i&1))*skew),floppydisk->floppyBitRate,currentcylinder->floppyRPM,trackformat,gap3len,0,2500,-2500); } } floppycontext->hxc_printf(MSG_INFO_1,"IMZ Loader : tracks file successfully loaded and encoded!"); free(flatimg); return 0; } free(flatimg); return HXCFE_BADFILE;//.........这里部分代码省略.........
开发者ID:slimlogic,项目名称:hxc-software,代码行数:101,
示例17: LoadZipbool8 LoadZip (const char *zipname, uint32 *TotalFileSize, uint8 *buffer){ *TotalFileSize = 0; unzFile file = unzOpen(zipname); if (file == NULL) return (FALSE); // find largest file in zip file (under MAX_ROM_SIZE) or a file with extension .1 char filename[132]; uint32 filesize = 0; int port = unzGoToFirstFile(file); unz_file_info info; while (port == UNZ_OK) { char name[132]; unzGetCurrentFileInfo(file, &info, name, 128, NULL, 0, NULL, 0); if (info.uncompressed_size > CMemory::MAX_ROM_SIZE + 512) { port = unzGoToNextFile(file); continue; } if (info.uncompressed_size > filesize) { strcpy(filename, name); filesize = info.uncompressed_size; } int len = strlen(name); if (len > 2 && name[len - 2] == '.' && name[len - 1] == '1') { strcpy(filename, name); filesize = info.uncompressed_size; break; } port = unzGoToNextFile(file); } if (!(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0) { assert(unzClose(file) == UNZ_OK); return (FALSE); } // find extension char tmp[2] = { 0, 0 }; char *ext = strrchr(filename, '.'); if (ext) ext++; else ext = tmp; uint8 *ptr = buffer; bool8 more = FALSE; unzLocateFile(file, filename, 1); unzGetCurrentFileInfo(file, &info, filename, 128, NULL, 0, NULL, 0); if (unzOpenCurrentFile(file) != UNZ_OK) { unzClose(file); return (FALSE); } do { assert(info.uncompressed_size <= CMemory::MAX_ROM_SIZE + 512); uint32 FileSize = info.uncompressed_size; int l = unzReadCurrentFile(file, ptr, FileSize); if (unzCloseCurrentFile(file) == UNZ_CRCERROR) { unzClose(file); return (FALSE); } if (l <= 0 || l != FileSize) { unzClose(file); return (FALSE); } FileSize = Memory.HeaderRemove(FileSize, ptr); ptr += FileSize; *TotalFileSize += FileSize; int len; if (ptr - Memory.ROM < CMemory::MAX_ROM_SIZE + 512 && (isdigit(ext[0]) && ext[1] == 0 && ext[0] < '9')) { more = TRUE; ext[0]++; } else//.........这里部分代码省略.........
开发者ID:unsigned-tamanegi,项目名称:snes9x-rpi,代码行数:101,
示例18: FCEU_fopenFCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext){ FILE *ipsfile=0; FCEUFILE *fceufp; void *t; if(strchr(mode,'r')) ipsfile=FCEUD_UTF8fopen(ipsfn,"rb"); fceufp=(FCEUFILE *)malloc(sizeof(FCEUFILE)); { unzFile tz; if((tz=unzOpen(path))) // If it's not a zip file, use regular file handlers. // Assuming file type by extension usually works, // but I don't like it. :) { if(unzGoToFirstFile(tz)==UNZ_OK) { for(;;) { char tempu[512]; // Longer filenames might be possible, but I don't // think people would name files that long in zip files... unzGetCurrentFileInfo(tz,0,tempu,512,0,0,0,0); tempu[511]=0; if(strlen(tempu)>=4) { char *za=tempu+strlen(tempu)-4; if(!ext) { if(!strcasecmp(za,".nes") || !strcasecmp(za,".fds") || !strcasecmp(za,".nsf") || !strcasecmp(za,".unf") || !strcasecmp(za,".nez")) break; } else if(!strcasecmp(za,ext)) break; } if(strlen(tempu)>=5) { if(!strcasecmp(tempu+strlen(tempu)-5,".unif")) break; } if(unzGoToNextFile(tz)!=UNZ_OK) { if(unzGoToFirstFile(tz)!=UNZ_OK) goto zpfail; break; } } if(unzOpenCurrentFile(tz)!=UNZ_OK) goto zpfail; } else { zpfail: free(fceufp); unzClose(tz); return 0; } if(!(fceufp->fp=MakeMemWrap(tz,2))) { free(fceufp); return(0); } fceufp->type=2; if(ipsfile) ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); return(fceufp); } } if((t=FCEUD_UTF8fopen(path,"rb"))) { uint32 magic; magic=fgetc((FILE *)t); magic|=fgetc((FILE *)t)<<8; magic|=fgetc((FILE *)t)<<16; if(magic!=0x088b1f) /* Not gzip... */ fclose((FILE *)t); else /* Probably gzip */ { int fd; fd = dup(fileno( (FILE *)t)); fclose(t); lseek(fd, 0, SEEK_SET); if((t=gzdopen(fd,mode))) { fceufp->type=1; fceufp->fp=t; if(ipsfile) { fceufp->fp=MakeMemWrap(t,1); gzclose(t);//.........这里部分代码省略.........
开发者ID:BruceJawn,项目名称:FlashNES,代码行数:101,
示例19: fill_win32_filefuncbool KAppRes::OpenResPack(){ bool retval = false; zlib_filefunc_def zip_funcs; std::string strPathAnsi; int nRetCode; HRSRC hResInfo = NULL; HGLOBAL hResDat = NULL; PVOID pResBuffer = NULL; DWORD dwResBuffer = 0; fill_win32_filefunc(&zip_funcs); strPathAnsi = UnicodeToAnsi(m_strResPackPath); m_pResPackData = unzOpen2(strPathAnsi.c_str(), &zip_funcs); if (m_pResPackData) goto UNZRESPACKDATA; if (strlen((const char*)&m_memZipRes) == 0) {//防止.kui格式错误导致unzOpen2返回空的m_pResPackData hResInfo = FindResourceW(_ModulePtr->GetResourceInstance(), L"kuires.dat", L"SKIN"); if (!hResInfo) goto clean0; hResDat = LoadResource(_ModulePtr->GetResourceInstance(), hResInfo); if (!hResDat) goto clean0; pResBuffer = LockResource(hResDat); if (!pResBuffer) goto clean0; dwResBuffer = SizeofResource(_ModulePtr->GetResourceInstance(), hResInfo); m_memZipRes.SetData(pResBuffer, dwResBuffer); } zip_funcs.zopen_file = ZipOpenFunc; zip_funcs.zread_file = ZipReadFunc; zip_funcs.zwrite_file = ZipWriteFunc; zip_funcs.ztell_file = ZipTellFunc; zip_funcs.zseek_file = ZipSeekFunc; zip_funcs.zclose_file = ZipCloseFunc; zip_funcs.zerror_file = ZipErrorFunc; zip_funcs.opaque=NULL; m_pResPackData = unzOpen2((const char*)&m_memZipRes, &zip_funcs); if (!m_pResPackData) goto clean0;UNZRESPACKDATA: nRetCode = unzGoToFirstFile(m_pResPackData); while (UNZ_OK == nRetCode) { char szCurrentFile[260]; unz_file_info fileInfo; uLong dwSeekPos; uLong dwSize; nRetCode = unzGetCurrentFileInfo( m_pResPackData, &fileInfo, szCurrentFile, sizeof(szCurrentFile), NULL, 0, NULL, 0 ); if (nRetCode != UNZ_OK) goto clean0; dwSeekPos = unzGetOffset(m_pResPackData); dwSize = fileInfo.uncompressed_size; m_mapResOffset.insert(KResOffset::value_type(szCurrentFile, KResInfo(dwSeekPos, dwSize))); nRetCode = unzGoToNextFile(m_pResPackData); }clean0: return retval;}
开发者ID:dreamsxin,项目名称:PcManager,代码行数:82,
示例20: ArchiveBaseCZipArchive::CZipArchive(FileReader &file) : ArchiveBase(file)//------------------------------------------------------------{ zlib_filefunc_def functions = { ZipFileAbstraction::fopen_mem, ZipFileAbstraction::fread_mem, ZipFileAbstraction::fwrite_mem, ZipFileAbstraction::ftell_mem, ZipFileAbstraction::fseek_mem, ZipFileAbstraction::fclose_mem, ZipFileAbstraction::ferror_mem, &inFile }; zipFile = unzOpen2(nullptr, &functions); if(zipFile == nullptr) { return; } // read comment { unz_global_info info; if(unzGetGlobalInfo(zipFile, &info) == UNZ_OK) { if(info.size_comment > 0) { if(info.size_comment < Util::MaxValueOfType(info.size_comment)) { info.size_comment++; } std::vector<char> commentData(info.size_comment); if(unzGetGlobalComment(zipFile, &commentData[0], info.size_comment) >= 0) { commentData[info.size_comment - 1] = '/0'; comment = mpt::ToWide(mpt::CharsetCP437, &commentData[0]); } } } } // read contents unz_file_pos curFile; int status = unzGoToFirstFile(zipFile); unzGetFilePos(zipFile, &curFile); while(status == UNZ_OK) { ArchiveFileInfo fileinfo; fileinfo.type = ArchiveFileNormal; unz_file_info info; char name[256]; unzGetCurrentFileInfo(zipFile, &info, name, sizeof(name), nullptr, 0, nullptr, 0); fileinfo.name = mpt::PathString::FromWide(mpt::ToWide(mpt::CharsetCP437, std::string(name))); fileinfo.size = info.uncompressed_size; unzGetFilePos(zipFile, &curFile); fileinfo.cookie1 = curFile.pos_in_zip_directory; fileinfo.cookie2 = curFile.num_of_file; contents.push_back(fileinfo); status = unzGoToNextFile(zipFile); }}
开发者ID:luaman,项目名称:modplug,代码行数:69,
示例21: OpenPK3// OpenPK3// -------// Opens a PK3 ( or zip ) file and creates a list of filenames// and zip info structures// boolean OpenPK3(const char *filename){ char cFilename[WORK_LEN]; char cName[WORK_LEN]; char cWork[WORK_LEN]; unz_file_info zInfo; unzFile *zFile = new unzFile(unzOpen(filename)); g_zFiles.Add(zFile); if (zFile != NULL) { int nStatus = unzGoToFirstFile(*zFile); while (nStatus == UNZ_OK) { cFilename[0] = '/0'; unzGetCurrentFileInfo(*zFile, &zInfo, cFilename, WORK_LEN, NULL, 0, NULL, 0); strlwr(cFilename); __ConvertDOSToUnixName( cWork, cFilename); if (strstr(cWork, ".") != NULL) { PK3FileInfo *pInfo = new PK3FileInfo(); pInfo->m_pName = __StrDup(cWork); memcpy(&pInfo->m_zInfo, (unz_s*)*zFile, sizeof(unz_s)); pInfo->m_lSize = zInfo.uncompressed_size; pInfo->m_zFile = *zFile; g_PK3Files.Add(pInfo); } char *p = strstr(cFilename, TEXTURE_PATH); if (p != NULL) { // FIXME: path differences per os ? // catch solo directory entry if (strlen(p) > strlen(TEXTURE_PATH) + 1) { // skip textures + path seperator p += strlen(TEXTURE_PATH) + 1; int nEnd = strcspn(p, PATH_SEPERATORS); strncpy(cName, p, nEnd); cName[nEnd] = '/0'; boolean bFound = false; StrList *pl = g_PK3TexturePaths.Next(); while (pl != NULL) { if (strcmpi(pl->Ref(), cName) == 0) { // already have this, continue bFound = true; break; } pl = pl->Next(); } if (!bFound) { g_PK3TexturePaths.Add(new Str(cName)); } } } nStatus = unzGoToNextFile(*zFile); } } return (zFile != NULL);}
开发者ID:5Quintessential,项目名称:jedioutcast,代码行数:67,
示例22: readfilechar *readfile (const char *filename, const char *homepage){ char filetoopen[MAXPATH] = ""; char fileinzip[MAXPATH] = ""; char dir[MAXDIR]; char name[MAXFILE]; char extension[MAXEXT]; char *attempt = NULL; unzFile *handle = NULL; fnsplit (filename, NULL, dir, name, extension); /* If extension is ".zip" */ if (strcmpi (extension, ".zip") == 0) { /* try to load this zip file. */ strcpy (filetoopen, filename); strcpy (fileinzip, "index.htm"); handle = unzOpen (filetoopen); } else { char temp1[MAXPATH]; char temp2[MAXPATH]; char *trydir1=NULL, *trydir2=NULL; int i; /* other/no extension: /* Look at the directory and try to open the associated zip file */ strcpy(temp1, filename); for (i = 0; i < strlen(temp1); i++) if (temp1[i] == '/') temp1[i] = '//'; while((trydir1=strrchr(temp1, '//')) != NULL) { *trydir1 = '/0'; trydir2 = strrchr(temp1, '//'); if (trydir2 == NULL) trydir2 = temp1; strcpy(temp2, trydir2); if (*temp1 != '/0') if ((temp1[strlen(temp1)-1] != '//') && temp2[0] != '//') strcat(temp1, "//"); strcat(temp1, temp2); strcat(temp1, ".zip"); if ((handle = unzOpen(temp1)) != 0) { strcpy(filetoopen, temp1); trydir1 = strrchr(temp1, '//'); strcpy(fileinzip, filename+(trydir1-temp1+1)); break; } *trydir1 = '/0'; } /* if that didn't work or wasn't possible, but the homepage is a zip file (happens if a zip is opened directly) then look in the homepage zipfile instead. Added for help 5.3.2 */ if (homepage != NULL && handle == NULL) { if (strcmpi(homepage+strlen(homepage)-4, ".zip") == 0) { strcpy (fileinzip, filename); strcpy (filetoopen, homepage); handle = unzOpen (filetoopen); } } } if (handle) { int i; for (i = 0; i < strlen(fileinzip); i++) if (fileinzip[i] == '//') fileinzip[i] = '/'; if (unzLocateFile (handle, fileinzip, 0) != UNZ_OK) { /* Could not find this file in the zip file */ /* Look for as uncompressed file instead: */ if ((attempt = tryasuncompressed (filename)) != NULL) return attempt; show_error (hcatFirstFile); /* Else look for first html file in zip: */ if (unzGoToFirstFile (handle) != UNZ_OK) { show_error (hcatZipEmpty); return NULL; } unzGetCurrentFileInfo (handle, NULL, fileinzip, MAXPATH, NULL, 0, NULL, 0); fnsplit (fileinzip, NULL, NULL, NULL, extension);//.........这里部分代码省略.........
开发者ID:CivilPol,项目名称:sdcboot,代码行数:101,
示例23: pathname/* Open a Zip file. path contain the full pathname (by example, on a Windows NT computer "c://test//zlib109.zip" or on an Unix computer "zlib/zlib109.zip". If the zipfile cannot be opened (file don't exist or in not valid), the return value is NULL. Else, the return value is a unzFile Handle, usable with other function of this unzip package.*/unzFile ZIP_Open (const char *path, unsigned char hash[MAX_HASH_SIZE], int *hashlen){ unz_s us; unz_s *s; uLong central_pos,uL; FILE * fin ; char buf[22]; char *lowercase_name; int i; uLong number_disk; /* number of the current dist, used for spaning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used for spaning ZIP, unsupported, always 0*/ uLong number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ int numFiles, err=UNZ_OK; fin=fopen(path,"rb"); if (fin==NULL) return NULL; central_pos = unzlocal_SearchCentralDir(fin); if (central_pos==0) err=UNZ_ERRNO; if (fseek(fin,central_pos,SEEK_SET)!=0) err=UNZ_ERRNO; // UTTAR: Reducing the number of calls to fread drastically to improve loading performance if(fread(buf, 22, 1, fin) != 1) { fclose(fin); return NULL; } else { uL = LITTLE_INT(*((int*)&buf[0])); number_disk = LITTLE_SHORT(*((short*)&buf[4])); number_disk_with_CD = LITTLE_SHORT(*((short*)&buf[6])); us.gi.number_entry = LITTLE_SHORT(*((short*)&buf[8])); number_entry_CD = LITTLE_SHORT(*((short*)&buf[10])); us.size_central_dir = LITTLE_INT(*((int*)&buf[12])); us.offset_central_dir = LITTLE_INT(*((int*)&buf[16])); us.gi.size_comment = LITTLE_SHORT(*((short*)&buf[20])); if ((number_entry_CD!=us.gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; if ((central_pos<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; } if (err!=UNZ_OK) { fclose(fin); return NULL; } us.file=fin; us.byte_before_the_zipfile = central_pos - (us.offset_central_dir+us.size_central_dir); us.central_pos = central_pos; us.pfile_in_zip_read = NULL; s=(unz_s*)Tag_Malloc(sizeof(unz_s), MEM_ZIP); *s=us; err = unzGoToFirstFile((unzFile)s); Console_DPrintf("creating new filenameHash/n"); s->filenameHash = g_hash_table_new(g_str_hash, zip_str_equal); numFiles = 0; memset(hash, 0, MAX_HASH_SIZE); Hash_StartHash(); while (err == UNZ_OK) { char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; unzlocal_GetCurrentFileInfoInternal ((unzFile)s, &s->cur_file_info, &s->cur_file_info_internal, szCurrentFileName, sizeof(szCurrentFileName)-1, NULL, 0, NULL, 0);//.........这里部分代码省略.........
开发者ID:newerthcom,项目名称:savagerebirth,代码行数:101,
示例24: pathname/* Open a Zip file. path contain the full pathname (by example, on a Windows NT computer "c://test//zlib109.zip" or on an Unix computer "zlib/zlib109.zip". If the zipfile cannot be opened (file don't exist or in not valid), the return value is NULL. Else, the return value is a unzFile Handle, usable with other function of this unzip package.*/extern unzFile ZEXPORT unzOpen(const char *path){ unz_s us; unz_s *s; uLong central_pos,uL; FILE * fin ; uLong number_disk; /* number of the current dist, used for spaning ZIP, unsupported, always 0*/ uLong number_disk_with_CD; /* number the the disk with central dir, used for spaning ZIP, unsupported, always 0*/ uLong number_entry_CD; /* total number of entries in the central dir (same than number_entry on nospan) */ int err=UNZ_OK; if (unz_copyright[0]!=' ') return NULL; fin=FCEUI_UTF8fopen_C(path,"rb"); //fin=fopen(path,"rb"); if (fin==NULL) return NULL; central_pos = unzlocal_SearchCentralDir(fin); if (central_pos==0) err=UNZ_ERRNO; if (fseek(fin,central_pos,SEEK_SET)!=0) err=UNZ_ERRNO; /* the signature, already checked */ if (unzlocal_getLong(fin,&uL)!=UNZ_OK) err=UNZ_ERRNO; /* number of this disk */ if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) err=UNZ_ERRNO; /* number of the disk with the start of the central directory */ if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir on this disk */ if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) err=UNZ_ERRNO; /* total number of entries in the central dir */ if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) err=UNZ_ERRNO; if ((number_entry_CD!=us.gi.number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) err=UNZ_BADZIPFILE; /* size of the central directory */ if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* offset of start of central directory with respect to the starting disk number */ if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) err=UNZ_ERRNO; /* zipfile comment length */ if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) err=UNZ_ERRNO; if ((central_pos<us.offset_central_dir+us.size_central_dir) && (err==UNZ_OK)) err=UNZ_BADZIPFILE; if (err!=UNZ_OK) { fclose(fin); return NULL; } us.file=fin; us.byte_before_the_zipfile = central_pos - (us.offset_central_dir+us.size_central_dir); us.central_pos = central_pos; us.pfile_in_zip_read = NULL; s=(unz_s*)ALLOC(sizeof(unz_s)); *s=us; unzGoToFirstFile((unzFile)s); return (unzFile)s; //.........这里部分代码省略.........
开发者ID:idispatch,项目名称:FCEUXpb,代码行数:101,
示例25: ZIP_SystemDirvoid ZIP_SystemDir(void *archive, char *_directory, char *wildcard, bool recurse, void(*dirCallback)(const char *dir, void *userdata), void(*fileCallback)(const char *filename, void *userdata), void *userdata){ GPatternSpec* pattern; unz_s* s; unz_s unz_backup; int err, numFiles; char *slash, *fname; char filename[384] = {0}; char directory[256] = {0}; char enumdir[256] = {0}; if (archive==NULL) return; s=(unz_s*)archive; if (!_directory || strlen(_directory) == 0) BPrintf(directory, 1024, ""); else BPrintf(directory, 1024, "%s%s", (_directory[0] == '/') ? &_directory[1] : _directory, (_directory[strlen(_directory)-1] == '/') ? "" : "/"); BPrintf(filename, 1024, "%s%s", directory, wildcard); pattern = g_pattern_spec_new(filename); Console_DPrintf("Doing a System_Dir in a ZIP file matching %s/n", filename); err = unzGoToFirstFile((unzFile)s); numFiles = 0; while (err == UNZ_OK) { unzGetCurrentFileInfo((unzFile)s,NULL, filename,1023, NULL,0,NULL,0); filename[1023] = 0; //Console_DPrintf("...%s/n", filename); if (strcmp(filename, directory) != 0 && strstr(filename, "CVS/") == 0) //don't call a callback for the directory itself { if (g_pattern_match_string(pattern, filename)) { bool goAhead; slash = strchr(&filename[strlen(directory)], '/'); goAhead = (!slash || (slash == filename + strlen(filename) - 1) || recurse) != 0; // UTTAR: Hack: NOTE: Dircallbacks could be activated several times with this method now! :( //if (goAhead) { if (filename[strlen(filename)-1] != '/' && goAhead) { if (fileCallback) { goAhead = 0; slash = strrchr(filename, '/'); if (!slash) { fname = filename; BPrintf(enumdir, 1, ""); } else { fname = slash+1; BPrintf(enumdir, slash - filename + 1, "%s", filename); } Cvar_SetVar(&sys_enumdir, enumdir); //Console_DPrintf("calling fileCallback for %s (in %s)/n", fname, sys_enumdir.string); Mem_Copy(&unz_backup, s, sizeof(unz_s)); fileCallback(fname, userdata); Mem_Copy(s, &unz_backup, sizeof(unz_s)); } } if(dirCallback && goAhead) { if(slash) *slash = 0; if (dirCallback) { //Console_DPrintf("calling dirCallback for %s/n", filename); dirCallback(filename, userdata); } } } } } numFiles++; err = unzGoToNextFile((unzFile)s); } Console_DPrintf("Done reading zip file contents - %i files/n", numFiles); if (err != UNZ_END_OF_LIST_OF_FILE) Console_DPrintf("ZIP error: err was %i/n", err); Cvar_SetVar(&sys_enumdir, ""); g_pattern_spec_free(pattern);}
开发者ID:newerthcom,项目名称:savagerebirth,代码行数:97,
示例26: epError EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug, bool p_dumb) { String src_pkg; EditorProgress ep("export","Exporting for OSX",104); String pkg_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/osx.zip"; if (p_debug) { src_pkg=custom_debug_package!=""?custom_debug_package:pkg_path; } else { src_pkg=custom_release_package!=""?custom_release_package:pkg_path; } FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); ep.step("Creating app",0); unzFile pkg = unzOpen2(src_pkg.utf8().get_data(), &io); if (!pkg) { EditorNode::add_io_error("Could not find template app to export:/n"+src_pkg); return ERR_FILE_NOT_FOUND; } ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN); int ret = unzGoToFirstFile(pkg); zlib_filefunc_def io2=io; FileAccess *dst_f=NULL; io2.opaque=&dst_f; zipFile dpkg=zipOpen2(p_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io2); String binary_to_use="godot_osx_"+String(p_debug?"debug":"release")+"."+String(use64?"64":"32"); print_line("binary: "+binary_to_use); String pkg_name; if (app_name!="") pkg_name=app_name; else if (String(Globals::get_singleton()->get("application/name"))!="") pkg_name=String(Globals::get_singleton()->get("application/name")); else pkg_name="Unnamed"; while(ret==UNZ_OK) { //get filename unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0); String file=fname; print_line("READ: "+file); Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); unzReadCurrentFile(pkg,data.ptr(),data.size()); unzCloseCurrentFile(pkg); //write file = file.replace_first("osx_template.app/",""); if (file=="Contents/Info.plist") { print_line("parse plist"); _fix_plist(data,pkg_name); } if (file.begins_with("Contents/MacOS/godot_")) { if (file!="Contents/MacOS/"+binary_to_use) { ret = unzGoToNextFile(pkg); continue; //ignore! } file="Contents/MacOS/"+pkg_name; } if (file=="Contents/Resources/icon.icns") { //see if there is an icon String iconpath = Globals::get_singleton()->get("application/icon"); print_line("icon? "+iconpath); if (iconpath!="") { Image icon; icon.load(iconpath); if (!icon.empty()) { print_line("loaded?"); _make_icon(icon,data); } } //bleh? }//.........这里部分代码省略.........
开发者ID:9cat,项目名称:godot,代码行数:101,
示例27: get_file_path/*! Open/Extract a file from disk and load it in memory. /param[in] filename The file to load in memory. /param[in] relative_path Determine if the filename is an absolute or relative path. /return Return a MEMORY structure pointer if the file is found and loaded, instead will return NULL.*/MEMORY *mopen( char *filename, unsigned char relative_path ){ #ifdef __IPHONE_4_0 FILE *f; char fname[ MAX_PATH ] = {""}; if( relative_path ) { get_file_path( getenv( "FILESYSTEM" ), fname ); strcat( fname, filename ); } else strcpy( fname, filename ); f = fopen( fname, "rb" ); if( !f ) return NULL; MEMORY *memory = ( MEMORY * ) calloc( 1, sizeof( MEMORY ) ); strcpy( memory->filename, fname ); fseek( f, 0, SEEK_END ); memory->size = ftell( f ); fseek( f, 0, SEEK_SET ); memory->buffer = ( unsigned char * ) calloc( 1, memory->size + 1 ); fread( memory->buffer, memory->size, 1, f ); memory->buffer[ memory->size ] = 0; fclose( f ); return memory; #else char fpath[ MAX_PATH ] = {""}, fname[ MAX_PATH ] = {""}; unzFile uf; unz_file_info fi; unz_file_pos fp; strcpy( fpath, getenv( "FILESYSTEM" ) ); uf = unzOpen( fpath ); if( !uf ) return NULL; if( relative_path ) sprintf( fname, "assets/%s", filename ); else strcpy( fname, filename ); unzGoToFirstFile( uf ); MEMORY *memory = ( MEMORY * ) calloc( 1, sizeof( MEMORY ) ); unzGetFilePos( uf, &fp ); if( unzLocateFile( uf, fname, 1 ) == UNZ_OK ) { unzGetCurrentFileInfo( uf, &fi, memory->filename, MAX_PATH, NULL, 0, NULL, 0 ); if( unzOpenCurrentFilePassword( uf, NULL ) == UNZ_OK ) { memory->position = 0; memory->size = fi.uncompressed_size; memory->buffer = ( unsigned char * ) realloc( memory->buffer, fi.uncompressed_size + 1 ); memory->buffer[ fi.uncompressed_size ] = 0; while( unzReadCurrentFile( uf, memory->buffer, fi.uncompressed_size ) > 0 ){} unzCloseCurrentFile( uf ); unzClose( uf ); return memory; } } //.........这里部分代码省略.........
开发者ID:1414648814,项目名称:OpenglESGame,代码行数:101,
示例28: PokeMini_iLoadROMZip// Load compressed MIN ROMstatic int PokeMini_iLoadROMZip(const char *zipfile, int *colorloaded){ unzFile uf = NULL; unz_global_info64 gi; unz_file_info64 file_inf; char filein[PMTMPV]; void *new_data; int i, size, loaded = 0, cloaded = 0; if (colorloaded) *colorloaded = 0; // Open ZIP uf = unzOpen(zipfile); if (!uf) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Opening ZIP error"); return 0; } if (unzGetGlobalInfo64(uf, &gi) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Getting global info"); unzClose(uf); return 0; } // Find and load MIN for (i=0; i<gi.number_entry; i++) { if (unzGetCurrentFileInfo64(uf, &file_inf, filein, PMTMPV, NULL, 0, NULL, 0) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Current file info"); unzClose(uf); return 0; } if (ExtensionCheck(filein, ".min") && (!loaded)) { if (unzLocateFile(uf, filein, 0) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "LocateFile failed"); unzClose(uf); return 0; } if (unzOpenCurrentFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Opening file error"); unzClose(uf); return 0; } size = GetMultiple2(file_inf.uncompressed_size); new_data = (void *)malloc(size); memset(new_data, 0xFF, size); if (!new_data) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Not enough memory"); unzCloseCurrentFile(uf); unzClose(uf); return 0; } size = unzReadCurrentFile(uf, new_data, file_inf.uncompressed_size); if (size < 0) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Reading file error"); unzCloseCurrentFile(uf); unzClose(uf); return 0; } PokeMini_FreeColorInfo(); // Free existing color information PokeMini_SetMINMem((uint8_t *)new_data, file_inf.uncompressed_size); PM_ROM_Alloc = 1; if (unzCloseCurrentFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Closing file error"); unzClose(uf); return 0; } if (PokeMini_OnAllocMIN) PokeMini_OnAllocMIN(PM_ROM_Size, 1); if (PokeMini_OnLoadMINFile) PokeMini_OnLoadMINFile(zipfile, 1); loaded = 1; break; } if ((i+1) < gi.number_entry) { if (unzGoToNextFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "No next file"); unzClose(uf); return 0; } } } // Check if there's color information file strcat(filein, "c"); if (!loaded) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "No ROM in ZIP"); unzClose(uf); return 0; } else { if (unzGoToFirstFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "No first file"); unzClose(uf); return 0; } if (unzLocateFile(uf, filein, 0) == UNZ_OK) { if (unzOpenCurrentFile(uf) != UNZ_OK) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Opening file error"); unzClose(uf); return 0; } if (!PokeMini_LoadColorStream(PokeMini_StreamFromZIP, uf)) { if (PokeMini_OnUnzipError) PokeMini_OnUnzipError(zipfile, "Reading file error");//.........这里部分代码省略.........
开发者ID:jasarien,项目名称:Provenance,代码行数:101,
示例29: SHFileOperationbool DialogInstall::InstallPackage(){ if ((!m_MergeSkins && m_BackupSkins) || m_BackupPackage) { // Move skins into backup folder for (auto iter = m_PackageSkins.cbegin(); iter != m_PackageSkins.cend(); ++iter) { std::wstring from = g_Data.skinsPath + *iter; if (_waccess(from.c_str(), 0) == -1) { continue; } SHFILEOPSTRUCT fo = { nullptr, FO_DELETE, nullptr, nullptr, FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO }; if (m_BackupPackage) { // Remove current skin from += L'/0'; fo.pFrom = from.c_str(); SHFileOperation(&fo); } else { std::wstring to = g_Data.skinsPath + L"@Backup//"; CreateDirectory(to.c_str(), nullptr); // Delete current backup to += *iter; to += L'/0'; fo.pFrom = to.c_str(); SHFileOperation(&fo); if (!CopyFiles(from, to, true)) { m_ErrorMessage = L"Unable to move to:/n"; m_ErrorMessage += to; return false; } } } } WCHAR buffer[MAX_PATH]; // Helper to sets buffer with current file name auto getFileInfo = [&]()->bool { char cBuffer[MAX_PATH * 3]; unz_file_info ufi; if (unzGetCurrentFileInfo( m_PackageUnzFile, &ufi, cBuffer, _countof(cBuffer), nullptr, 0, nullptr, 0) == UNZ_OK) { const uLong ZIP_UTF8_FLAG = 1 << 11; const DWORD codePage = (ufi.flag & ZIP_UTF8_FLAG) ? CP_UTF8 : CP_ACP; MultiByteToWideChar(codePage, 0, cBuffer, strlen(cBuffer) + 1, buffer, MAX_PATH); while (WCHAR* pos = wcschr(buffer, L'/')) *pos = L'//'; return true; } return false; }; unzGoToFirstFile(m_PackageUnzFile); const WCHAR* root = m_PackageRoot.c_str(); do { if (!getFileInfo()) { m_ErrorMessage = L"Error retrieving file info."; return false; } if (wcsncmp(buffer, root, m_PackageRoot.length()) != 0) { // Ignore everything that isn't in the root directory continue; } WCHAR* component = buffer + m_PackageRoot.length(); WCHAR* path = wcschr(component, L'//'); if (path) { *path = L'/0'; ++path; } else { continue; } bool error = false; std::wstring targetPath;//.........这里部分代码省略.........
开发者ID:ATTRAYANTDESIGNS,项目名称:rainmeter,代码行数:101,
注:本文中的unzGoToFirstFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ unzGoToNextFile函数代码示例 C++ unzGetGlobalInfo函数代码示例 |