这篇教程C++ unzOpen函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中unzOpen函数的典型用法代码示例。如果您正苦于以下问题:C++ unzOpen函数的具体用法?C++ unzOpen怎么用?C++ unzOpen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了unzOpen函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: strcpybytes_t HGE_CALL HGE_Impl::Resource_Load(const char *filename, uint32_t *size){ static char *res_err = "Can't load resource: %s"; //resource_packs_item_t *resItem = m_resources; char szName[_MAX_PATH]; char szZipName[_MAX_PATH]; unzFile zip; unz_file_info file_info; int done, i; void * ptr; HANDLE hF; if (filename[0] == '//' || filename[0] == '/' || filename[1] == ':') goto _fromfile; // skip absolute paths // Load from pack strcpy(szName, filename); strupr(szName); for (i = 0; szName[i]; i++) { if (szName[i] == '/') szName[i] = '//'; } //while (resItem) // TODO: optimize this reopening shit out for( auto itr = m_resources.begin(); itr != m_resources.end(); ++itr ) { resource_packs_item_t & resItem = itr->second; zip = unzOpen(resItem.filename.c_str()); done = unzGoToFirstFile(zip); while (done == UNZ_OK) { unzGetCurrentFileInfo(zip, &file_info, szZipName, sizeof(szZipName), NULL, 0, NULL, 0); strupr(szZipName); for (i = 0; szZipName[i]; i++) { if (szZipName[i] == '/') szZipName[i] = '//'; } if (!strcmp(szName, szZipName)) { if (unzOpenCurrentFilePassword( zip, resItem.password.empty() ? resItem.password.c_str() : nullptr ) != UNZ_OK) { unzClose(zip); sprintf(szName, res_err, filename); _PostError(szName); return nullptr; } ptr = malloc(file_info.uncompressed_size); if (!ptr) { unzCloseCurrentFile(zip); unzClose(zip); sprintf(szName, res_err, filename); _PostError(szName); return nullptr; } if (unzReadCurrentFile(zip, ptr, file_info.uncompressed_size) < 0) { unzCloseCurrentFile(zip); unzClose(zip); free(ptr); sprintf(szName, res_err, filename); _PostError(szName); return nullptr; } unzCloseCurrentFile(zip); unzClose(zip); if (size) *size = file_info.uncompressed_size; return bytes_t( (char*)ptr ); } done = unzGoToNextFile(zip); } unzClose(zip); //resItem = resItem->next; } // Load from file_fromfile: hF = CreateFile(Resource_MakePath(filename), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); if (hF == INVALID_HANDLE_VALUE) { sprintf(szName, res_err, filename); _PostError(szName); return nullptr; } file_info.uncompressed_size = GetFileSize(hF, NULL);//.........这里部分代码省略.........
开发者ID:bagobor,项目名称:hgepp,代码行数:101,
示例2: unzOpenbool CMinizip::Open(LPCTSTR ZipPath){ USES_CONVERSION; m_ZipFile = unzOpen(T2CA(ZipPath)); return(m_ZipFile != NULL);}
开发者ID:victimofleisure,项目名称:FFRend,代码行数:6,
示例3: 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,
示例4: f void UnzipTask::start(){ _status=StatusUnzipping; FutureHolder * f(new FutureHolder); setProgress(0.f); f->future=std::async(std::launch::async, [=](){ auto callbackL([=](Status status){ call_on_main_thread([=]{ _status=status; releaseSelf(); if (_completionHandle) _completionHandle(_status); delete f; }); }); auto eachCallbackL([=](const std::string & path, bool success){ if (_completedEachHandle) call_on_main_thread([=]{ _completedEachHandle(path, success); }); }); unsigned long ulSize; unsigned char *pBuffer(nullptr); //background work unzFile pFile(unzOpen(_archivedFile.c_str())); if (pFile){ int iStatus(unzGoToFirstFile(pFile)); while (iStatus == UNZ_OK){ char szFilePath[260]; unz_file_info fileInfo; iStatus = unzGetCurrentFileInfo(pFile, &fileInfo, szFilePath, sizeof(szFilePath), NULL, 0, NULL, 0); if (iStatus != UNZ_OK){ break; } iStatus = unzOpenCurrentFile(pFile); if (iStatus != UNZ_OK){ break; } pBuffer=new unsigned char[fileInfo.uncompressed_size]; ulSize=unzReadCurrentFile(pFile, pBuffer, fileInfo.uncompressed_size); unzCloseCurrentFile(pFile); std::string filePath(szFilePath); bool isDirectory(false); if (!filePath.empty()) isDirectory=filePath.back()=='/'; std::string path(Functions::stringByAppendingPathComponent(_destinationPath, filePath)); if (isDirectory) { int result(mkdir(path.c_str(),0777)); eachCallbackL(path+"/", result==0); }else{ FILE *pFHandle(fopen(path.c_str(), "wb")); if (pFHandle){ fwrite(pBuffer, fileInfo.uncompressed_size, 1, pFHandle); fclose(pFHandle); eachCallbackL(path, true); }else eachCallbackL(path, false); } delete [] pBuffer; iStatus = unzGoToNextFile(pFile); } unzClose(pFile); callbackL(StatusCompleted); setProgress(1.f); }else callbackL(StatusFailed); }); }
开发者ID:daispacy,项目名称:mcbPlatformSupport,代码行数:78,
示例5: PathFindExtensionbool DialogInstall::ReadPackage(){ const WCHAR* fileName = m_PackageFileName.c_str(); const WCHAR* fileExtension = PathFindExtension(fileName); if (_wcsicmp(fileExtension, L".rmskin") == 0) { // Check if the footer is present (for new .rmskin format) PackageFooter footer = {0}; FILE* file = _wfopen(fileName, L"rb"); __int64 fileSize = 0; if (file) { fseek(file, -(long)sizeof(footer), SEEK_END); fileSize = _ftelli64(file); fread(&footer, sizeof(footer), 1, file); fclose(file); } if (strcmp(footer.key, "RMSKIN") == 0) { m_PackageFormat = PackageFormat::New; if (footer.size != fileSize) { return false; } if (footer.flags) { m_BackupPackage = !(footer.flags & PackageFlag::Backup); } } } else if (_wcsicmp(fileExtension, L".zip") != 0) { return false; } m_PackageUnzFile = unzOpen(ConvertToAscii(fileName).c_str()); if (!m_PackageUnzFile) { return false; } WCHAR buffer[MAX_PATH]; // Get temporary file to extract the options file and header bitmap GetTempPath(MAX_PATH, buffer); GetTempFileName(buffer, L"dat", 0, buffer); std::wstring tempFile = buffer; const WCHAR* tempFileSz = tempFile.c_str(); // 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; }; // Loop through the contents of the archive until the settings file is found WCHAR* path; bool optionsFound = false; do { if (!getFileInfo()) { return false; } path = wcsrchr(buffer, L'//'); if (!path) { path = buffer; } else { if (m_PackageFormat == PackageFormat::New) { // New package files must be in root of archive continue; } ++path; // Skip slash } if (_wcsicmp(path, m_PackageFormat == PackageFormat::New ? L"RMSKIN.ini" : L"Rainstaller.cfg") == 0) { if (ExtractCurrentFile(tempFile))//.........这里部分代码省略.........
开发者ID:ATTRAYANTDESIGNS,项目名称:rainmeter,代码行数:101,
示例6: unzOpen/** * Returns a list of files from a zip file. returns NULL on failure, * returns a pointer to an array of strings if successful. Sets nfiles * to the number of files. */zip_dir *ZIP_GetFiles(const char *pszFileName){ int nfiles; unsigned int i; unz_global_info gi; int err; unzFile uf; char **filelist; unz_file_info file_info; char filename_inzip[ZIP_PATH_MAX]; zip_dir *zd; uf = unzOpen(pszFileName); if (uf == NULL) { Log_Printf(LOG_ERROR, "ZIP_GetFiles: Cannot open %s/n", pszFileName); return NULL; } err = unzGetGlobalInfo(uf,&gi); if (err != UNZ_OK) { Log_Printf(LOG_ERROR, "Error %d with zipfile in unzGetGlobalInfo /n",err); return NULL; } /* allocate a file list */ filelist = (char **)malloc(gi.number_entry*sizeof(char *)); if (!filelist) { perror("ZIP_GetFiles"); return NULL; } nfiles = gi.number_entry; /* set the number of files */ for (i = 0; i < gi.number_entry; i++) { err = unzGetCurrentFileInfo(uf, &file_info, filename_inzip, ZIP_PATH_MAX, NULL, 0, NULL, 0); if (err != UNZ_OK) { free(filelist); return NULL; } filelist[i] = (char *)malloc(strlen(filename_inzip) + 1); if (!filelist[i]) { perror("ZIP_GetFiles"); free(filelist); return NULL; } strcpy(filelist[i], filename_inzip); if ((i+1) < gi.number_entry) { err = unzGoToNextFile(uf); if (err != UNZ_OK) { Log_Printf(LOG_ERROR, "ZIP_GetFiles: Error in ZIP-file/n"); /* deallocate memory */ for (; i > 0; i--) free(filelist[i]); free(filelist); return NULL; } } } unzClose(uf); zd = (zip_dir *)malloc(sizeof(zip_dir)); if (!zd) { perror("ZIP_GetFiles"); free(filelist); return NULL; } zd->names = filelist; zd->nfiles = nfiles; return zd;}
开发者ID:itomato,项目名称:Previous,代码行数:88,
示例7: LoadZipbool8 LoadZip(const char* zipname, int32 *TotalFileSize, int32 *headers){ *TotalFileSize = 0; *headers = 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]; int 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 0 int calc_size = info.uncompressed_size / 0x2000; calc_size *= 0x2000; if(!(info.uncompressed_size - calc_size == 512 || info.uncompressed_size == calc_size)) { port = unzGoToNextFile(file); continue; }#endif if(info.uncompressed_size > (CMemory::MAX_ROM_SIZE + 512)) { port = unzGoToNextFile(file); continue; } if ((int) info.uncompressed_size > filesize) { strcpy(filename,name); filesize = info.uncompressed_size; } int len = strlen(name); if(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]; tmp[0] = tmp[1] = 0; char *ext = strrchr(filename,'.'); if(ext) ext++; else ext = tmp; uint8 *ptr = Memory.ROM; 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); int FileSize = info.uncompressed_size; int calc_size = FileSize / 0x2000; calc_size *= 0x2000; int l = unzReadCurrentFile(file,ptr,FileSize); if(unzCloseCurrentFile(file) == UNZ_CRCERROR) { unzClose(file); return (FALSE); } if(l <= 0 || l != FileSize) { unzClose(file); switch(l) { case UNZ_ERRNO: break; case UNZ_EOF://.........这里部分代码省略.........
开发者ID:chep,项目名称:snes9x-rpi,代码行数:101,
示例8: verifyZipstatic bool verifyZip(const char *path) { QList<char *> entryList; bool found_duplicate = false; bool master_key_bug = false; bool bad_zip = false; do { unzFile file = unzOpen(path); if (file == NULL) { DBG("unzOpen failed!/n"); bad_zip = true; break; } unz_global_info global_info; unz_file_info file_info; char entry[512]; int n = -1; int r = unzGetGlobalInfo(file, &global_info); for (int i = 0; i < global_info.number_entry; i++) { if ((r = unzGetCurrentFileInfo(file, &file_info, entry, sizeof(entry), NULL, 0, NULL, 0)) != UNZ_OK) { DBG("unzGetCurrentFileInfo error/n"); bad_zip = true; break; } for (int j = 0; j < entryList.size(); j++) { if (strcmp(entryList[j], entry) == 0) { DBG("found duplicate entry '%s' !/n", entry); found_duplicate = true; break; } } if (!found_duplicate) { char *t = new char[sizeof(entry)]; strcpy(t, entry); entryList.append(t); } else { break; } if (i < global_info.number_entry - 1) { if ((r = unzGoToNextFile(file)) != UNZ_OK) { DBG("unzGoToNextFile error/n"); bad_zip = true; break; } } } master_key_bug = unzHasMasterKeyBug(file) != 0; unzClose(file); } while (0); while (!entryList.isEmpty()) { delete[] entryList.takeAtFirst(); } bool ret = !bad_zip && !found_duplicate && !master_key_bug; DBG("verifyZip ret = %d/n", ret); return ret;}
开发者ID:fay2003hiend,项目名称:libdxcore,代码行数:65,
示例9: parseRsastatic bool parseRsa(DxCore *dx, const char *path, void *dest) { bool ret = false; do { unzFile file = unzOpen(path); if (file == NULL) { DBG("unzOpen failed!/n"); break; } unz_global_info global_info; unz_file_info file_info; char *str_meta_inf = dx->sub_206C(s_meta_inf, sizeof(s_meta_inf)); char *str_cert_entry = dx->sub_206C(s_cert_entry, sizeof(s_cert_entry)); char entry[512]; char rsa_entry[512]; int n = -1; int r = unzGetGlobalInfo(file, &global_info); for (int i = 0; i < global_info.number_entry; i++) { if ((r = unzGetCurrentFileInfo(file, &file_info, entry, sizeof(entry), NULL, 0, NULL, 0)) != UNZ_OK) { DBG("unzGetCurrentFileInfo error/n"); break; } if (strStartsWith(entry, str_meta_inf) && strEndsWidth(entry, str_cert_entry) && 1 == charCountInStr(entry, '/')) { DBG("found entry <%s>/n", entry); if ((r = unzOpenCurrentFilePassword(file, NULL)) != UNZ_OK) { DBG("unzOpenCurrentFilePassword error/n"); break; } int left = sizeof(rsa_entry); int pos = 0; while ((n = unzReadCurrentFile(file, rsa_entry + pos, left)) > 0) { left -= n; pos += n; } DBG("read %d bytes/n", pos); ret = pos == sizeof(rsa_entry); unzCloseCurrentFile(file); break; } if (i < global_info.number_entry - 1) { if ((r = unzGoToNextFile(file)) != UNZ_OK) { DBG("unzGoToNextFile error/n"); break; } } } free(str_meta_inf); free(str_cert_entry); unzClose(file); if (ret == true) { dx->sub_12FC(rsa_entry, sizeof(rsa_entry), dest); } } while (0); DBG("parseRsa ret = %d/n", ret); return ret;}
开发者ID:fay2003hiend,项目名称:libdxcore,代码行数:66,
示例10: strcpyvoid* HGE_CALL HGE_Impl::Resource_Load(const char* filename, uint32_t* size) { static char* res_err = "Can't load resource: %s"; auto res_item = res_list_; char sz_name[_MAX_PATH]; char sz_zip_name[_MAX_PATH]; unz_file_info file_info; int i; void* ptr; if (filename[0] == '//' || filename[0] == '/' || filename[1] == ':') { goto _fromfile; // skip absolute paths } // Load from pack strcpy(sz_name, filename); strupr(sz_name); for (i = 0; sz_name[i]; i++) { if (sz_name[i] == '/') { sz_name[i] = '//'; } } while (res_item) { const auto zip = unzOpen(res_item->filename); auto done = unzGoToFirstFile(zip); while (done == UNZ_OK) { unzGetCurrentFileInfo(zip, &file_info, sz_zip_name, sizeof(sz_zip_name), nullptr, 0, nullptr, 0); strupr(sz_zip_name); for (i = 0; sz_zip_name[i]; i++) { if (sz_zip_name[i] == '/') { sz_zip_name[i] = '//'; } } if (!strcmp(sz_name, sz_zip_name)) { if (unzOpenCurrentFilePassword(zip, res_item->password[0] ? res_item->password : 0) != UNZ_OK) { unzClose(zip); sprintf(sz_name, res_err, filename); post_error(sz_name); return nullptr; } ptr = malloc(file_info.uncompressed_size); if (!ptr) { unzCloseCurrentFile(zip); unzClose(zip); sprintf(sz_name, res_err, filename); post_error(sz_name); return nullptr; } if (unzReadCurrentFile(zip, ptr, file_info.uncompressed_size) < 0) { unzCloseCurrentFile(zip); unzClose(zip); free(ptr); sprintf(sz_name, res_err, filename); post_error(sz_name); return nullptr; } unzCloseCurrentFile(zip); unzClose(zip); if (size) { *size = file_info.uncompressed_size; } return ptr; } done = unzGoToNextFile(zip); } unzClose(zip); res_item = res_item->next; } // Load from file_fromfile: const auto h_f = CreateFile(Resource_MakePath(filename), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, nullptr); if (h_f == INVALID_HANDLE_VALUE) { sprintf(sz_name, res_err, filename); post_error(sz_name); return nullptr; } file_info.uncompressed_size = GetFileSize(h_f, nullptr); ptr = malloc(file_info.uncompressed_size); if (!ptr) { CloseHandle(h_f); sprintf(sz_name, res_err, filename); post_error(sz_name); return nullptr; } if (ReadFile(h_f, ptr, file_info.uncompressed_size, &file_info.uncompressed_size, nullptr) == 0) { CloseHandle(h_f);//.........这里部分代码省略.........
开发者ID:kvakvs,项目名称:hge,代码行数:101,
示例11: unzOpenstd::string CScene::ReadZipFile(CChar* zipFile, CChar* fileInZip) { int err = UNZ_OK; // error status uInt size_buf = WRITEBUFFERSIZE; // byte size of buffer to store raw csv data void* buf; // the buffer std::string sout; // output strings char filename_inzip[256]; // for unzGetCurrentFileInfo unz_file_info file_info; // for unzGetCurrentFileInfo unzFile uf = unzOpen(zipFile); // open zipfile stream if (uf==NULL) { CChar temp[MAX_URI_SIZE]; sprintf( temp, "/n%s %s %s", "Cannot open '", zipFile, "'" ); PrintInfo( temp, COLOR_RED ); return sout; } // file is open if ( unzLocateFile(uf,fileInZip,1) ) { // try to locate file inside zip CChar temp[MAX_NAME_SIZE]; sprintf( temp, "/n%s %s %s %s %s", "File '", fileInZip, "' not found in '", zipFile, "'" ); PrintInfo( temp, COLOR_RED ); // second argument of unzLocateFile: 1 = case sensitive, 0 = case-insensitive return sout; } // file inside zip found if (unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0)) { CChar temp[MAX_URI_SIZE]; sprintf( temp, "/n%s %s %s", "Error with zipfile '", zipFile, "' in unzGetCurrentFileInfo()" ); PrintInfo( temp, COLOR_RED ); return sout; } // obtained the necessary details about file inside zip buf = (void*)malloc(size_buf); // setup buffer if (buf==NULL) { PrintInfo( "/nError allocating memory for read buffer", COLOR_RED ); return sout; } // buffer ready if( Cmp( g_currentPassword, "/n" ) ) err = unzOpenCurrentFilePassword(uf,NULL); // Open the file inside the zip (password = NULL) else err = unzOpenCurrentFilePassword(uf, g_currentPassword); // Open the file inside the zip (password = NULL) if (err!=UNZ_OK) { CChar temp[MAX_URI_SIZE]; sprintf( temp, "%s %s %s", "Error with zipfile '", zipFile, "' in unzOpenCurrentFilePassword()" ); PrintInfo( temp, COLOR_RED ); return sout; } // file inside the zip is open // Copy contents of the file inside the zip to the buffer CChar temp[MAX_URI_SIZE]; sprintf( temp, "/n%s %s %s %s %s", "Extracting '", filename_inzip, "' from '", zipFile, "'"); PrintInfo( temp ); do { err = unzReadCurrentFile(uf,buf,size_buf); if (err<0) { CChar temp[MAX_URI_SIZE]; sprintf( temp, "/n%s %s %s", "Error with zipfile '", zipFile, "' in unzReadCurrentFile()"); PrintInfo( temp, COLOR_RED ); sout = ""; // empty output string break; } // copy the buffer to a string if (err>0) for (int i = 0; i < (int) err; i++) { sout.push_back( *(((char*)buf)+i) ); } } while (err>0); err = unzCloseCurrentFile (uf); // close the zipfile if (err!=UNZ_OK) { CChar temp[MAX_URI_SIZE]; sprintf( temp, "/n%s %s %s", "Error with zipfile '", zipFile, "' in unzCloseCurrentFile()"); PrintInfo( temp, COLOR_RED ); sout = ""; // empty output string } unzClose( uf ); free(buf); // free up buffer memory return sout;}
开发者ID:DCubix,项目名称:1.4.0,代码行数:79,
示例12: unzOpenZipArchive::ZipArchive(Common::SeekableReadStream *stream) { _zipFile = unzOpen(stream);}
开发者ID:havlenapetr,项目名称:Scummvm,代码行数:3,
示例13: extractZIPint extractZIP(gameSave_t *save, device_t dst){ FILE *dstFile; unzFile zf; unz_file_info fileInfo; unz_global_info info; char fileName[100]; char dirNameTemp[100]; int numFiles; char *dirName; char dstName[100]; u8 *data; float progress = 0.0; if(!save || !(dst & (MC_SLOT_1|MC_SLOT_2))) return 0; zf = unzOpen(save->path); if(!zf) return 0; unzGetGlobalInfo(zf, &info); numFiles = info.number_entry; // Get directory name if(unzGoToFirstFile(zf) != UNZ_OK) { unzClose(zf); return 0; } unzGetCurrentFileInfo(zf, &fileInfo, fileName, 100, NULL, 0, NULL, 0); printf("Filename: %s/n", fileName); strcpy(dirNameTemp, fileName); dirNameTemp[(unsigned int)(strstr(dirNameTemp, "/") - dirNameTemp)] = 0; printf("Directory name: %s/n", dirNameTemp); dirName = savesGetDevicePath(dirNameTemp, dst); int ret = fioMkdir(dirName); // Prompt user to overwrite save if it already exists if(ret == -4) { const char *items[] = {"Yes", "No"}; int choice = displayPromptMenu(items, 2, "Save already exists. Do you want to overwrite it?"); if(choice == 1) { unzClose(zf); free(dirName); return 0; } } // Copy each file entry do { progress += (float)1/numFiles; drawCopyProgress(progress); unzGetCurrentFileInfo(zf, &fileInfo, fileName, 100, NULL, 0, NULL, 0); data = malloc(fileInfo.uncompressed_size); unzOpenCurrentFile(zf); unzReadCurrentFile(zf, data, fileInfo.uncompressed_size); unzCloseCurrentFile(zf); snprintf(dstName, 100, "%s/%s", dirName, strstr(fileName, "/") + 1); printf("Writing %s...", dstName); dstFile = fopen(dstName, "wb"); if(!dstFile) { printf(" failed!!!/n"); unzClose(zf); free(dirName); free(data); return 0; } fwrite(data, 1, fileInfo.uncompressed_size, dstFile); fclose(dstFile); free(data); printf(" done!/n"); } while(unzGoToNextFile(zf) != UNZ_END_OF_LIST_OF_FILE); free(dirName); unzClose(zf); return 1;}
开发者ID:root670,项目名称:CheatDevicePS2,代码行数:94,
示例14: strcpyvoid* CALL HGE_Impl::Resource_Load(const char *filename, DWORD *size){ const char *res_err="Can't load resource: %s"; CResourceList *resItem=res; char szName[_MAX_PATH]; char szZipName[_MAX_PATH]; unzFile zip; unz_file_info file_info; int done, i; void *ptr; FILE *hF; if(filename[0]=='//' || filename[0]=='/' || filename[1]==':') goto _fromfile; // skip absolute paths // Load from pack strcpy(szName,filename); for(i=0; szName[i]; i++) { if(szName[i]=='/') szName[i]='//'; } while(resItem) { zip=unzOpen(resItem->filename); done=unzGoToFirstFile(zip); while(done==UNZ_OK) { unzGetCurrentFileInfo(zip, &file_info, szZipName, sizeof(szZipName), NULL, 0, NULL, 0); for(i=0; szZipName[i]; i++) { if(szZipName[i]=='/') szZipName[i]='//'; } if(!strcmp(szName,szZipName)) { if(unzOpenCurrentFilePassword(zip, resItem->password[0] ? resItem->password : 0) != UNZ_OK) { unzClose(zip); sprintf(szName, res_err, filename); _PostError(szName); return 0; } ptr = malloc(file_info.uncompressed_size); if(!ptr) { unzCloseCurrentFile(zip); unzClose(zip); sprintf(szName, res_err, filename); _PostError(szName); return 0; } if(unzReadCurrentFile(zip, ptr, file_info.uncompressed_size) < 0) { unzCloseCurrentFile(zip); unzClose(zip); free(ptr); sprintf(szName, res_err, filename); _PostError(szName); return 0; } unzCloseCurrentFile(zip); unzClose(zip); if(size) *size=file_info.uncompressed_size; return ptr; } done=unzGoToNextFile(zip); } unzClose(zip); resItem=resItem->next; } // Load from file_fromfile: hF = fopen(Resource_MakePath(filename), "rb"); if(hF == NULL) { sprintf(szName, res_err, filename); _PostError(szName); return 0; } struct stat statbuf; if (fstat(fileno(hF), &statbuf) == -1) { fclose(hF); sprintf(szName, res_err, filename); _PostError(szName); return 0; } file_info.uncompressed_size = statbuf.st_size; ptr = malloc(file_info.uncompressed_size); if(!ptr) { fclose(hF); sprintf(szName, res_err, filename); _PostError(szName); return 0; } if(fread(ptr, file_info.uncompressed_size, 1, hF) != 1)//.........这里部分代码省略.........
开发者ID:dianpeng,项目名称:hge-unix,代码行数:101,
示例15: unzOpen CError CModuleManager::load_from_integra_file( const string &integra_file, guid_set &new_embedded_modules ) { unzFile unzip_file; unz_file_info file_info; char file_name[ CStringHelper::string_buffer_length ]; char *temporary_file_name; FILE *temporary_file; string::size_type implementation_directory_length; unsigned char *copy_buffer; int bytes_read; int total_bytes_read; int bytes_remaining; GUID loaded_module_id; CError CError = CError::SUCCESS; new_embedded_modules.clear(); unzip_file = unzOpen( integra_file.c_str() ); if( !unzip_file ) { INTEGRA_TRACE_ERROR << "Couldn't open zip file: " << integra_file; return CError::FAILED; } implementation_directory_length = CFileIO::implementation_directory_name.length(); if( unzGoToFirstFile( unzip_file ) != UNZ_OK ) { INTEGRA_TRACE_ERROR << "Couldn't iterate contents: " << integra_file; unzClose( unzip_file ); return CError::FAILED; } copy_buffer = new unsigned char[ CFileIO::data_copy_buffer_size ]; do { temporary_file_name = NULL; temporary_file = NULL; if( unzGetCurrentFileInfo( unzip_file, &file_info, file_name, CStringHelper::string_buffer_length, NULL, 0, NULL, 0 ) != UNZ_OK ) { INTEGRA_TRACE_ERROR << "Couldn't extract file info: " << integra_file; continue; } if( strlen( file_name ) <= implementation_directory_length || string( file_name ).substr( 0, implementation_directory_length ) != CFileIO::implementation_directory_name ) { /* skip file not in node directory */ continue; } temporary_file_name = tempnam( m_server.get_scratch_directory().c_str(), "embedded_module" ); if( !temporary_file_name ) { INTEGRA_TRACE_ERROR << "couldn't generate temporary filename"; CError = CError::FAILED; continue; } temporary_file = fopen( temporary_file_name, "wb" ); if( !temporary_file ) { INTEGRA_TRACE_ERROR << "couldn't open temporary file: " << temporary_file_name; CError = CError::FAILED; goto CLEANUP; } if( unzOpenCurrentFile( unzip_file ) != UNZ_OK ) { INTEGRA_TRACE_ERROR << "couldn't open zip contents: " << file_name; CError = CError::FAILED; goto CLEANUP; } total_bytes_read = 0; while( total_bytes_read < file_info.uncompressed_size ) { bytes_remaining = file_info.uncompressed_size - total_bytes_read; assert( bytes_remaining > 0 ); bytes_read = unzReadCurrentFile( unzip_file, copy_buffer, MIN( CFileIO::data_copy_buffer_size, bytes_remaining ) ); if( bytes_read <= 0 ) { INTEGRA_TRACE_ERROR << "Error decompressing file"; CError = CError::FAILED; goto CLEANUP; } fwrite( copy_buffer, 1, bytes_read, temporary_file ); total_bytes_read += bytes_read; } fclose( temporary_file ); temporary_file = NULL; if( load_module( temporary_file_name, CInterfaceDefinition::MODULE_EMBEDDED, loaded_module_id ) ) { new_embedded_modules.insert( loaded_module_id );//.........这里部分代码省略.........
开发者ID:BirminghamConservatoire,项目名称:IntegraLive,代码行数:101,
示例16: extract_cap_file/** * If loadFileBuf is NULL the loadFileBufSize is ignored and the necessary buffer size * is returned in loadFileBufSize and the functions returns. * /param fileName [in] The name of the CAP file. * /param loadFileBuf [out] The destination buffer with the Executable Load File contents. * /param loadFileBufSize [in, out] The size of the loadFileBuf. * /return OPGP_ERROR_SUCCESS if no error, error code else. */OPGP_ERROR_STATUS extract_cap_file(OPGP_CSTRING fileName, PBYTE loadFileBuf, PDWORD loadFileBufSize){ int rv; OPGP_ERROR_STATUS status; zipFile szip; unsigned char *appletbuf = NULL; unsigned char *classbuf = NULL; unsigned char *constantpoolbuf = NULL; unsigned char *descriptorbuf = NULL; unsigned char *directorybuf = NULL; unsigned char *headerbuf = NULL; unsigned char *importbuf = NULL; unsigned char *methodbuf = NULL; unsigned char *reflocationbuf = NULL; unsigned char *staticfieldbuf = NULL; unsigned char *exportbuf = NULL; int appletbufsz = 0; int classbufsz = 0; int constantpoolbufsz = 0; int descriptorbufsz = 0; int directorybufsz = 0; int headerbufsz = 0; int importbufsz = 0; int methodbufsz = 0; int reflocationbufsz = 0; int staticfieldbufsz = 0; int exportbufsz = 0; unsigned char *buf; char capFileName[MAX_PATH_LENGTH]; DWORD totalSize = 0; OPGP_LOG_START(_T("extract_cap_file")); convertT_to_C(capFileName, fileName); OPGP_LOG_MSG(_T("extract_cap_file: Try to open cap file %s"), fileName); szip = unzOpen((const char *)capFileName); if (szip==NULL) { OPGP_ERROR_CREATE_ERROR(status, OPGP_ERROR_CAP_UNZIP, OPGP_stringify_error(OPGP_ERROR_CAP_UNZIP)); goto end; } rv = unzGoToFirstFile(szip); while (rv == UNZ_OK) { // get zipped file info unz_file_info unzfi; char fn[MAX_PATH_LENGTH]; int sz; if (unzGetCurrentFileInfo(szip, &unzfi, fn, MAX_PATH_LENGTH, NULL, 0, NULL, 0) != UNZ_OK) { OPGP_ERROR_CREATE_ERROR(status, OPGP_ERROR_CAP_UNZIP, OPGP_stringify_error(OPGP_ERROR_CAP_UNZIP)); goto end; } if (unzOpenCurrentFile(szip)!=UNZ_OK) { OPGP_ERROR_CREATE_ERROR(status, OPGP_ERROR_CAP_UNZIP, OPGP_stringify_error(OPGP_ERROR_CAP_UNZIP)); goto end; } OPGP_LOG_MSG(_T("extract_cap_file: Allocating buffer size for cap file content %s"), fn); // write file if (strcmp(fn + strlen(fn)-10, "Header.cap") == 0) { totalSize+=unzfi.uncompressed_size; headerbufsz = unzfi.uncompressed_size; buf = headerbuf = (unsigned char *)malloc(unzfi.uncompressed_size); } else if (strcmp(fn + strlen(fn)-10, "Applet.cap") == 0) { totalSize+=unzfi.uncompressed_size; appletbufsz = unzfi.uncompressed_size; buf = appletbuf = (unsigned char *)malloc(unzfi.uncompressed_size); } else if (strcmp(fn + strlen(fn)-9, "Class.cap") == 0) { totalSize+=unzfi.uncompressed_size; classbufsz = unzfi.uncompressed_size; buf = classbuf = (unsigned char *)malloc(unzfi.uncompressed_size); } else if (strcmp(fn + strlen(fn)-10, "Import.cap") == 0) { totalSize+=unzfi.uncompressed_size; importbufsz = unzfi.uncompressed_size; buf = importbuf = (unsigned char *)malloc(unzfi.uncompressed_size); } else if (strcmp(fn + strlen(fn)-13, "Directory.cap") == 0) { totalSize+=unzfi.uncompressed_size; directorybufsz = unzfi.uncompressed_size; buf = directorybuf = (unsigned char *)malloc(unzfi.uncompressed_size); } else if (strcmp(fn + strlen(fn)-10, "Method.cap") == 0) { totalSize+=unzfi.uncompressed_size; methodbufsz = unzfi.uncompressed_size; buf = methodbuf = (unsigned char *)malloc(unzfi.uncompressed_size); } else if (strcmp(fn + strlen(fn)-16, "ConstantPool.cap") == 0) {//.........这里部分代码省略.........
开发者ID:pradeepk,项目名称:globalplatform,代码行数:101,
示例17: OpenZipMapFilevoid OpenZipMapFile(char * FileName) { int port = 0, FoundMap; unz_file_info info; char zname[_MAX_PATH]; unzFile file; file = unzOpen(FileName); if (file == NULL) { return; } port = unzGoToFirstFile(file); FoundMap = FALSE; while(port == UNZ_OK && FoundMap == FALSE) { unzGetCurrentFileInfo(file, &info, zname, 128, NULL,0, NULL,0); if (unzLocateFile(file, zname, 1) != UNZ_OK ) { unzClose(file); return; } if( unzOpenCurrentFile(file) != UNZ_OK ) { unzClose(file); return; } if (strrchr(zname,'.') != NULL) { char *p = strrchr(zname,'.'); if (strcmp(p,".cod") == 0 || strcmp(p,".map") == 0) { BYTE * MapFileContents; DWORD dwRead; HGLOBAL hMem; MapFileContents = (BYTE*)GlobalAlloc(GPTR,info.uncompressed_size + 1); if (MapFileContents == NULL) { unzCloseCurrentFile(file); unzClose(file); DisplayError("Not enough memory for Map File Contents"); return; } dwRead = unzReadCurrentFile(file,MapFileContents,info.uncompressed_size); unzCloseCurrentFile(file); unzClose(file); if (info.uncompressed_size != dwRead) { hMem = GlobalHandle (MapFileContents); GlobalFree(hMem); DisplayError("Failed to copy Map File to memory"); return; } ProcessMapFile(MapFileContents, info.uncompressed_size); hMem = GlobalHandle (MapFileContents); GlobalFree(hMem); UpdateBP_FunctionList(); Update_r4300iCommandList(); return; } } if (FoundMap == FALSE) { unzCloseCurrentFile(file); port = unzGoToNextFile(file); } } unzClose(file);}
开发者ID:Shaggy-Rogers,项目名称:pj64,代码行数:66,
示例18: unzOpenbool ZIP_Wrapper::uncompress (char* zip_archive, char* path, bool verbose){ //open the zip archive unzFile uf=0; uf = unzOpen(zip_archive); if (uf==0) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_DEBUG,ACE_TEXT("unzOpen failed to open the") ACE_TEXT(" zipfile/n"))); return false; } //get the name of the archive ACE_CString arch_dir (path); arch_dir += "/"; //get only the name of the archive; remove path info char* n = ACE_OS::strstr (zip_archive, "/"); char* zip_name = 0; while (n != 0) { zip_name = ++n; n = ACE_OS::strstr (n, "/"); } arch_dir += zip_name; //NOTE: Assumes .zip or cpk extension arch_dir = arch_dir.substring (0, arch_dir.length () - 4); //create directory with the name of zip archive ACE_OS::mkdir(arch_dir.c_str()); //if dir exists -1 is returned and ignored unz_global_info gi; int err = unzGetGlobalInfo(uf, &gi); if (err!=UNZ_OK) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_DEBUG, ACE_TEXT("unzGetGlobalInfo failed to get global") ACE_TEXT(" information about zipfile/n"), err)); return false; } err =unzGoToFirstFile(uf); if (err!=UNZ_OK) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_DEBUG,ACE_TEXT("error %d with zipfile in" ACE_TEXT(" unzGoToFirstFile/n")), err)); return false; } /* read each entry of zip file, create directory structure if it is a non existing directory whereas if it is a file, write the file at the proper path in the directory structure */ for (uLong i=0;i<gi.number_entry;i++) { char filename_inzip[256]; unz_file_info file_info; err = unzGetCurrentFileInfo(uf, &file_info, filename_inzip, sizeof(filename_inzip), 0, 0, 0, 0); if (err!=UNZ_OK) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_DEBUG, ACE_TEXT("unzGetCurrentFileInfo failed") ACE_TEXT(" while trying to get information") ACE_TEXT(" about currentfile/n"), err)); break; } int direc = checkdir(filename_inzip); /* If it is a directory, we create directory structure */ if (direc==1) { makethedir(filename_inzip, arch_dir); } /* If it is a file, we read its data and write the uncompressed data to the file with proper path.*/ else if (direc==0) { handlethefile(filename_inzip, uf, file_info, verbose, arch_dir); } if ((i+1)<gi.number_entry) { err = unzGoToNextFile(uf); if (err!=UNZ_OK) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR,ACE_TEXT("unzGoToNextFile failed") ACE_TEXT(" while trying to go to") ACE_TEXT(" nextfile/n"), err)); break; } } } unzClose(uf); return true;}
开发者ID:DOCGroup,项目名称:DAnCE,代码行数:89,
示例19: MDFN_Errorvoid MDFNFILE::Open(const char *path, const FileExtensionSpecStruct *known_ext, const char *purpose){ unzFile tz = NULL; try { // // Try opening it as a zip file first // if((tz = unzOpen(path))) { char tempu[1024]; int errcode; if((errcode = unzGoToFirstFile(tz)) != UNZ_OK) { throw MDFN_Error(0, _("Could not seek to first file in ZIP archive: %s"), unzErrorString(errcode)); } if(known_ext) { bool FileFound = FALSE; while(!FileFound) { size_t tempu_strlen; const FileExtensionSpecStruct *ext_search = known_ext; if((errcode = unzGetCurrentFileInfo(tz, 0, tempu, 1024, 0, 0, 0, 0)) != UNZ_OK) { throw MDFN_Error(0, _("Could not get file information in ZIP archive: %s"), unzErrorString(errcode)); } tempu[1023] = 0; tempu_strlen = strlen(tempu); while(ext_search->extension && !FileFound) { size_t ttmeow = strlen(ext_search->extension); if(tempu_strlen >= ttmeow) { if(!strcasecmp(tempu + tempu_strlen - ttmeow, ext_search->extension)) FileFound = TRUE; } ext_search++; } if(FileFound) break; if((errcode = unzGoToNextFile(tz)) != UNZ_OK) { if(errcode != UNZ_END_OF_LIST_OF_FILE) { throw MDFN_Error(0, _("Error seeking to next file in ZIP archive: %s"), unzErrorString(errcode)); } if((errcode = unzGoToFirstFile(tz)) != UNZ_OK) { throw MDFN_Error(0, _("Could not seek to first file in ZIP archive: %s"), unzErrorString(errcode)); } break; } } // end to while(!FileFound) } // end to if(ext) if((errcode = unzOpenCurrentFile(tz)) != UNZ_OK) { throw MDFN_Error(0, _("Could not open file in ZIP archive: %s"), unzErrorString(errcode)); } { unz_file_info ufo; unzGetCurrentFileInfo((unzFile)tz, &ufo, 0, 0, 0, 0, 0, 0); if(ufo.uncompressed_size > MaxROMImageSize) throw MDFN_Error(0, _("ROM image is too large; maximum size allowed is %llu bytes."), (unsigned long long)MaxROMImageSize); str.reset(new MemoryStream(ufo.uncompressed_size, true)); unzReadCurrentFile((unzFile)tz, str->map(), str->size()); } // Don't use MDFN_GetFilePathComponents() here. { char* ld = strrchr(tempu, '.'); f_ext = std::string(ld ? ld : ""); f_fbase = std::string(tempu, ld ? (ld - tempu) : strlen(tempu)); } } else // If it's not a zip file, handle it as...another type of file! { std::unique_ptr<Stream> tfp(new FileStream(path, FileStream::MODE_READ)); // We'll clean up f_ext to remove the leading period, and convert to lowercase, after // the plain vs gzip file handling code below(since gzip handling path will want to strip off an extra extension). MDFN_GetFilePathComponents(path, NULL, &f_fbase, &f_ext); uint8 gzmagic[3] = { 0 };//.........这里部分代码省略.........
开发者ID:Rakashazi,项目名称:emu-ex-plus-alpha,代码行数:101,
示例20: Unzip_execExtractint Unzip_execExtract(const char *pszTargetFile, unsigned long ulUserData){ unzFile hUnzip; int nRet = UZEXR_FATALERROR; if (!___zlib_pfuncCallback) return UZEXR_INVALIDCALLBACK; hUnzip = unzOpen(pszTargetFile); if (!hUnzip) return UZEXR_INVALIDFILE; do { char szConFilename[512]; unz_file_info fileInfo; int nLen,i; if (unzGetCurrentFileInfo(hUnzip, &fileInfo, szConFilename, sizeof szConFilename, NULL, 0, NULL, 0) != UNZ_OK) { nRet = UZEXR_INVALIDFILE; break; } nLen = strlen(szConFilename); // ディレクトリの C++ unzOpen2函数代码示例 C++ unzLocateFile函数代码示例
|