bool eFileTypeZIP::Open(const char* name) const { char contain_path[xIo::MAX_PATH_LEN]; char contain_name[xIo::MAX_PATH_LEN]; if(Contain(name, contain_path, contain_name)) { unzFile h = unzOpen64(contain_path); if(!h) return false; bool ok = false; if(unzLocateFile(h, contain_name, 0) == UNZ_OK) { ok = OpenCurrent(h); } unzClose(h); return ok; } char opened_name[xIo::MAX_PATH_LEN]; bool ok = Open(unzOpen64(name), opened_name); if(ok) { char full_name[xIo::MAX_PATH_LEN]; strcpy(full_name, name); strcat(full_name, "/"); strcat(full_name, opened_name); OpLastFile(full_name); } return ok; }
int minizip_getfilenameinzip(const char * lpszzipfilename, char *lpszfilenameinzip, int nmaxlen) { int nret = -1; // Open zip file unzFile uf = NULL; if (lpszzipfilename != NULL) { uf = unzOpen64(lpszzipfilename); } if (uf == NULL) { return nret; } // Get filename in zip unz_file_info64 file_info = { 0 }; int status = unzGetCurrentFileInfo64(uf, &file_info, lpszfilenameinzip, nmaxlen, NULL, 0, NULL, 0); if (status != UNZ_OK) { return nret; } nret = 0; return nret; }
bool zip_extract_onefile(const char* zip_filename, const char* filename , const char* save_filename) { // 解压先使用 zipOpen64 来打开一个 ZIP 文件 unzFile uf = unzOpen64(zip_filename); // // 需要先使用 unzGetGlobalInfo64 来取得该文件的一些信息,来了解这个压缩包里一共包含了多少个文件,等等。 // unz_global_info64 gi; // // if (unzGetGlobalInfo64(uf, &gi) != UNZ_OK) { // return false; // } // 尝试zip文件中找到该文件szFileName。 int err = UNZ_OK; if (unzLocateFile(uf, filename, CASESENSITIVITY) != UNZ_OK) { printf("file %s not found in the zipfile\n", filename); return false; } if (!zip_extract_currentfile(uf, save_filename)) { return false; } unzClose(uf); return true; }
bool zip::ZipArchiveInput::Open( String_t const& archiveName, bool caseSensitive ) { m_archiveName = archiveName; m_caseSensitive = caseSensitive; #ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; #endif #ifdef USEWIN32IOAPI # ifdef SCARAB_WCHAR_MODE fill_win32_filefunc64W(&ffunc); # else fill_win32_filefunc64A(&ffunc); # endif uf = unzOpen2_64(m_archiveName.c_str(),&ffunc); #else uf = unzOpen64(m_archiveName.c_str()); #endif // USEWIN32IOAPI if (uf==NULL) { m_errorMessage << _T("Can't open ") << m_archiveName << std::endl; return false; } return Index(); }
int TRI_UnzipFile(char const* filename, char const* outPath, bool skipPaths, bool overwrite, char const* password, std::string& errorMessage) { #ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; #endif size_t bufferSize = 16384; void* buffer = (void*)TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, bufferSize, false); if (buffer == nullptr) { return TRI_ERROR_OUT_OF_MEMORY; } #ifdef USEWIN32IOAPI fill_win32_filefunc64A(&ffunc); unzFile uf = unzOpen2_64(filename, &ffunc); #else unzFile uf = unzOpen64(filename); #endif if (uf == nullptr) { errorMessage = std::string("unable to open zip file ") + filename; return TRI_ERROR_INTERNAL; } int res = UnzipFile(uf, buffer, bufferSize, outPath, skipPaths, overwrite, password, errorMessage); unzClose(uf); TRI_Free(TRI_UNKNOWN_MEM_ZONE, buffer); return res; }
bool QZipFile::open(OpenMode mode) { if (m_unzFile || m_zipFile) { setErrorString("File is already open"); return false; } if (mode == ReadOnly) { m_unzFile = unzOpen64(m_fileName.toAscii()); if (m_unzFile == NULL) { // no valid information at this point setErrorString("Error opening Zip file for reading"); return false; } } else if ((mode == WriteOnlyTruncate) || (mode == WriteOnlyAppend)) { m_zipFile = zipOpen64(m_fileName.toAscii(),(mode == WriteOnlyAppend) ? 2 : 0); if (m_zipFile == NULL) { // no valid information at this point setErrorString("Error opening Zip file for writing"); return false; } } else return false; m_mode = mode; return true; }
celix_status_t extractBundle(char * bundleName, char * revisionRoot) { celix_status_t status = CELIX_SUCCESS; char filename_try[MAXFILENAME+16] = ""; unzFile uf=NULL; if (bundleName!=NULL) { # ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; # endif strncpy(filename_try, bundleName,MAXFILENAME-1); /* strncpy doesnt append the trailing NULL, of the string is too long. */ filename_try[ MAXFILENAME ] = '\0'; # ifdef USEWIN32IOAPI fill_win32_filefunc64A(&ffunc); uf = unzOpen2_64(bundleName,&ffunc); # else uf = unzOpen64(bundleName); # endif if (uf==NULL) { strcat(filename_try,".zip"); # ifdef USEWIN32IOAPI uf = unzOpen2_64(filename_try,&ffunc); # else uf = unzOpen64(filename_try); # endif } } if (uf==NULL) { printf("Cannot open %s or %s.zip\n",bundleName,bundleName); status = CELIX_FILE_IO_EXCEPTION; } else { if (do_extract(uf, revisionRoot) != 0) { status = CELIX_FILE_IO_EXCEPTION; } unzClose(uf); } return status; }
int archiveOpen(char *file) { // Start position of the archive path archive_path_start = strlen(file) + 1; // Close previous zip file first if (uf) unzClose(uf); // Open zip file uf = unzOpen64(file); if (!uf) return -1; // Clear archive list memset(&archive_list, 0, sizeof(FileList)); // Go through all files int res; char name[MAX_PATH_LENGTH]; unz_file_info64 file_info; res = unzGoToFirstFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0); if (res < 0) return res; while (res >= 0) { FileListEntry *entry = malloc(sizeof(FileListEntry)); // File info strcpy(entry->name, name); entry->is_folder = 0; entry->name_length = file_info.size_filename; entry->size = file_info.uncompressed_size; entry->size2 = file_info.compressed_size; // Time SceDateTime time; sceRtcSetDosTime(&time, file_info.dosDate); convertLocalTimeToUtc(&time, &time); memcpy(&entry->ctime, &time, sizeof(SceDateTime)); memcpy(&entry->mtime, &time, sizeof(SceDateTime)); memcpy(&entry->atime, &time, sizeof(SceDateTime)); // Get pos unzGetFilePos64(uf, (unz64_file_pos *)&entry->reserved); // Add entry fileListAddEntry(&archive_list, entry, SORT_BY_NAME); // Next res = unzGoToNextFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0); } return 0; }
unzFile FileUtils::mzOpenInputFile(const std::string &path) { #ifdef USEWIN32IOAPI zlib_filefunc64_def zFunc; memset(&zFunc, 0, sizeof(zFunc)); fill_win32_filefunc64A(&zFunc); return unzOpen2_64(path.c_str(), &zFunc); #else return unzOpen64(path.c_str()); #endif }
static SQRESULT sq_minizip_unzip_constructor(HSQUIRRELVM v) { SQ_FUNC_VARS_NO_TOP(v); SQ_GET_STRING(v, 2, zip_fname); unzFile zip_archive = unzOpen64(zip_fname); if(!zip_archive) { return sq_throwerror(v, _SC("Cannot open %s\n"),zip_fname); } sq_setinstanceup(v, 1, zip_archive); sq_setreleasehook(v,1, sq_minizip_unzip_releasehook); return 1; }
int FolderZip::Populate() { std::string filename(m_path.begin(), m_path.end()); unzFile f = unzOpen64(filename.c_str()); // Support for unicode filename is not yet implemented in unzip(?) //unzFile f = unzOpen64(m_path.c_str()); if (!f) return -1; unz_global_info64 globalInfo; int getGlobalInfoResult = unzGetGlobalInfo64(f, &globalInfo); if (getGlobalInfoResult != UNZ_OK) { unzClose(f); return -2; } int firstFileResult = unzGoToFirstFile(f); if (firstFileResult != UNZ_OK) { unzClose(f); return -3; } int nextFileResult = firstFileResult; do { unz_file_info64 fileInfo; int getInfoResult = unzGetCurrentFileInfo64(f, &fileInfo, NULL, 0, NULL, 0, NULL, 0); if (getInfoResult != UNZ_OK) { unzClose(f); continue; } char *filename = new char[fileInfo.size_filename+1]; unzGetCurrentFileInfo64(f, &fileInfo, filename, fileInfo.size_filename, NULL, 0, NULL, 0); filename[fileInfo.size_filename] = '\0'; File *newFile = new File(); newFile->m_path = std::wstring(filename, filename+fileInfo.size_filename); newFile->m_crc = fileInfo.crc; mFileList.insert(std::pair<std::wstring,File*>(newFile->m_path, newFile)); nextFileResult = unzGoToNextFile(f); } while (nextFileResult == UNZ_OK); unzClose(f); return 0; }
unzFile FileUtils::mzOpenInputFile(const std::string &path) { #if defined(MINIZIP_WIN32) zlib_filefunc64_def zFunc; memset(&zFunc, 0, sizeof(zFunc)); fill_win32_filefunc64W(&zFunc); return unzOpen2_64(utf8::utf8ToUtf16(path).c_str(), &zFunc); #elif defined(MINIZIP_ANDROID) zlib_filefunc64_def zFunc; memset(&zFunc, 0, sizeof(zFunc)); fill_android_filefunc64(&zFunc); return unzOpen2_64(path.c_str(), &zFunc); #else return unzOpen64(path.c_str()); #endif }
bool WorkBook::load(const char* const filename) { if (0 == filename) return false; m_zipfile = unzOpen64(filename); bool b; b = _extrafile(&m_zipfile, "xl/styles.xml", parseStyle); assert(b); b = _extrafile(&m_zipfile, "xl/sharedStrings.xml", parseShardString); assert(b); b = _extrafile(&m_zipfile, "xl/workbook.xml", parseWorkbook); assert(b); // do_extract_onefile(uf, "xl/workbook.xml", 0, 0, 0); return true; }
static DKObject<UnZipFile> Create(const DKString& zipFile, const DKString& file, const char* password) { if (zipFile.Length() == 0 || file.Length() == 0) return NULL; DKString filename = zipFile.FilePathString(); unzFile uf = NULL; #ifdef _WIN32 { zlib_filefunc64_def ffunc; fill_win32_filefunc64W(&ffunc); uf = unzOpen2_64((const wchar_t*)filename, &ffunc); // UTF16LE } #else { DKStringU8 filenameUTF8(filename); if (filenameUTF8.Bytes() > 0) uf = unzOpen64((const char*)filenameUTF8); // UTF8 } #endif if (uf) { unz_file_info64 file_info; DKStringU8 fileUTF8(file); if (fileUTF8.Bytes() > 0 && unzLocateFile(uf, (const char*)fileUTF8, 0) == UNZ_OK && unzGetCurrentFileInfo64(uf, &file_info, NULL, 0, NULL, 0, NULL, 0) == UNZ_OK && file_info.uncompressed_size > 0) { if (unzOpenCurrentFilePassword(uf, password) == UNZ_OK) { DKObject<UnZipFile> p = DKOBJECT_NEW UnZipFile(uf, file_info, password); return p; } else { DKLog("[%s] failed to open file: %ls.\n", DKLIB_FUNCTION_NAME, (const wchar_t*)file); } } } return NULL; }
wstring extractText(const wstring& wpath) { // The unzipping and locating of actualy document content can be // shared among other extracts such as pptx, xlsx etc. // unzip // find [Content_Types].xml // from which read the location of document.xml // read document.xml // string mcpath = CStringUtil::WideStringToUtf8(wpath); unzFile zf = unzOpen64(mcpath.c_str()); string result; if (zf) { string schema = unzReadFile(zf, schemaName()); TiXmlDocument xmlSchema; xmlSchema.Parse(schema.c_str()); DocPathsVisitor pathVisitor(docContentType()); xmlSchema.Accept(&pathVisitor); for (const string& docPath : pathVisitor.paths()) { if (!docPath.empty()) { string xmlContent = unzReadFile(zf, docPath.c_str()); if (!xmlContent.empty()) { TiXmlDocument xmldoc; xmldoc.Parse(xmlContent.c_str()); DocContentVisitor contentVisitor; xmldoc.Accept(&contentVisitor); result += contentVisitor.strDocContent; } } } unzClose(zf); } return CStringUtil::Utf8ToWideString(result); }
/** * @fn int z_open(z_t zip, const z_file_t filename) * @brief Open a new ZIP file. * @param zip The ZIP context. * @param filename ZIP file name. * @return 0 on success else -1. */ int z_open(z_t zip, const z_file_t filename) { struct z_s* z = Z_CAST(zip); if(!Z_VALID(z)) return -1; strcpy(z->filename, filename); /* Open the zip file */ z->ctx = unzOpen64(z->filename); if(!z->ctx) { logger(LOG_ERR, "Unable to open the zip file '%s'\n", z->filename); z_close(z); return -1; } /* Get info about the zip file */ if(unzGetGlobalInfo64(z->ctx, &z->ginfo) != UNZ_OK) { logger(LOG_ERR, "Unable to read the global info related to the '%s' zip file\n", z->filename); z_close(z); return -1; } return 0; }
int UnzipCache::unzip(const char *pattern, std::list<clc::Buffer> *matchedNames) { uLong i; unz_global_info64 gi; int numMatched = 0; if (m_uf) unzClose(m_uf); m_uf = unzOpen64(m_filename.c_str()); int err = unzGetGlobalInfo64(m_uf, &gi); if (err != UNZ_OK) { clc::Log::error("ocher.epub.unzip", "unzGetGlobalInfo: %d", err); return -1; } for (i = 0; i < gi.number_entry; i++) { int r; if (matchedNames) { clc::Buffer matchedName; r = unzipFile(pattern, &matchedName); if (!matchedName.empty()) matchedNames->push_back(matchedName); } else { r = unzipFile(pattern, NULL); } if (r > 0) { ++numMatched; if (r > 1) break; } if ((i + 1) < gi.number_entry) { err = unzGoToNextFile(m_uf); if (err != UNZ_OK) { clc::Log::error("ocher.epub.unzip", "unzGoToNextFile: %d", err); return -1; } } } return numMatched; }
static duk_ret_t dukzip_open(duk_context *ctx) { const char *filename = duk_require_string(ctx, 0); const char *filemode; if (duk_is_string(ctx, 1)) { filemode = duk_require_string(ctx, 1); } else { filemode = "r"; } if (filemode[0] == 'r') { unzFile archive; archive = unzOpen64(filename); if (archive == NULL) { duk_error(ctx, DUK_ERR_INTERNAL_ERROR, "could not open file '%s'", filename); return -1; } dukzip_push_unzfile(ctx, archive, filename); return 1; } else if (filemode[0] == 'w') { zipFile archive; archive = zipOpen64(filename, APPEND_STATUS_CREATE); if (archive == NULL) { duk_error(ctx, DUK_ERR_INTERNAL_ERROR, "could not open file '%s'", filename); return -1; } dukzip_push_zipfile(ctx, archive, filename); return 1; } else { duk_error(ctx, DUK_ERR_TYPE_ERROR, "%s is not a valid file mode (valid modes: 'r' or 'w')", filemode); return -1; } }
int minizip_unzip(const char * lpszzipfilename, const char * lpszdirname, const char * lpszpassword) { int nret = -1; int nstatus = 0; int nct = 0; unzFile uf = NULL; // Open zip file if (lpszzipfilename != NULL) { uf = unzOpen64(lpszzipfilename); } if (uf == NULL) { return ERROR_ZIP_FILE_NOT_FOUND; } // Extract all nstatus = unzGoToFirstFile(uf); while (nstatus == UNZ_OK) { chdir(lpszdirname); nstatus = extractCurrentFile(uf, lpszpassword); if (nstatus == UNZ_OK) { nct ++; nstatus =unzGoToNextFile(uf); } } if (nct > 0) { nret = 0; } return nret; }
int TRI_UnzipFile (const char* filename, const char* outPath, const bool skipPaths, const bool overwrite, const char* password) { unzFile uf; #ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; #endif void* buffer; size_t bufferSize; int res; bufferSize = 16384; buffer = (void*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, bufferSize, false); if (buffer == NULL) { return TRI_ERROR_OUT_OF_MEMORY; } #ifdef USEWIN32IOAPI fill_win32_filefunc64A(&ffunc); uf = unzOpen2_64(filename, &ffunc); #else uf = unzOpen64(filename); #endif res = UnzipFile(uf, buffer, bufferSize, outPath, skipPaths, overwrite, password); unzClose(uf); TRI_Free(TRI_UNKNOWN_MEM_ZONE, buffer); return res; }
/// @brief ÉèÖÃGIF¶¯»Í¼Æ¬,´ÓZIPѹËõ°üÖмÓÔØͼƬ. /// @param hEle ÔªËؾä±ú. /// @param pZipFileName ѹËõ°üÎļþ. /// @param pImageName GIFͼƬÃû. /// @param pPassword ѹËõ°üÃÜÂë. void WINAPI XGif_SetImageZip(HELE hEle,wchar_t *pZipFileName,wchar_t *pImageName,wchar_t *pPassword) { IsGifDebug(hEle,__FUNCTION__); gif_ *pObject=(gif_*)hEle; if(pObject->pGif) { delete pObject->pGif; pObject->pGif=NULL; } if(NULL==pZipFileName || NULL==pImageName) { return ; } IsImageTypeDebug(_T(__FUNCTION__),pImageName); char zipfilename[MAX_PATH]={0}; WideCharToMultiByte(CP_ACP,NULL,pZipFileName,wcslen(pZipFileName),zipfilename,MAX_PATH,NULL,NULL); char filename_to_extract[MAX_PATH]={0}; WideCharToMultiByte(CP_ACP,NULL,pImageName,wcslen(pImageName),filename_to_extract,MAX_PATH,NULL,NULL); char password[MAX_PATH]={0}; if(pPassword) WideCharToMultiByte(CP_ACP,NULL,pPassword,wcslen(pPassword),password,MAX_PATH,NULL,NULL); //const char *password=NULL; //char *zipfilename="C:\\Users\\mengfei\\Desktop\\myzip.zip"; //ѹËõ°ü //char *filename_to_extract="dirtt/123.txt"; //ÌáÈ¡ÎļþÃû //char *filename_to_extract="btn.bmp"; //ÌáÈ¡ÎļþÃû unzFile zipFile=NULL; zipFile = unzOpen64(zipfilename); //´ò¿ªÑ¹Ëõ°ü if (zipFile==NULL) { XTRACE("´ò¿ªZIPѹËõ°üʧ°Ü"); return ; } int outSize=0; void *data =NULL; if(pPassword) data=do_extract_onefile(zipFile, filename_to_extract,password,outSize); else data=do_extract_onefile(zipFile, filename_to_extract,NULL,outSize); unzClose(zipFile); if(data) { HGLOBAL hJPG = ::GlobalAlloc(GMEM_MOVEABLE, outSize); LPVOID lpJGP = ::GlobalLock(hJPG); memcpy(lpJGP, data, outSize); ::GlobalUnlock(hJPG); LPSTREAM pstm =NULL; HRESULT hr =CreateStreamOnHGlobal(hJPG, TRUE, &pstm); assert(SUCCEEDED(hr) && pstm); //Image *pImg=Image::FromStream(pstm); pObject->pGif=new ImageEx(pstm); pstm->Release(); free(data); if(Gdiplus::Ok != (pObject->pGif->GetLastStatus())) { delete pObject->pGif; pObject->pGif=NULL; } if(pObject->pGif->InitAnimation(0,0)) SetTimer(XEle_GetHWnd(hEle),(int)hEle,100,Gif_TimerProc); } }
int main(int argc,char *argv[]) { char zipfilename[MAXFILENAME]= {0}; char filename_to_extract[MAXFILENAME]= {0}; const char *password=NULL; char filename_try[MAXFILENAME+16] = ""; int i; int ret_value=0; int opt_do_list=0; int opt_do_extract=1; int opt_do_extract_withoutpath=0; int opt_overwrite=0; int opt_extractdir=0; char dirname[MAXFILENAME]= {0}; unzFile uf=NULL; do_banner(); if (argc==1) { do_help(); return 0; } else { for (i=1; i<argc; i++) { if ((*argv[i])=='-') { const char *p=argv[i]+1; while ((*p)!='\0') { char c=*(p++);; if ((c=='l') || (c=='L')) opt_do_list = 1; if ((c=='v') || (c=='V')) opt_do_list = 1; if ((c=='x') || (c=='X')) opt_do_extract = 1; if ((c=='e') || (c=='E')) opt_do_extract = opt_do_extract_withoutpath = 1; if ((c=='o') || (c=='O')) opt_overwrite=1; if ((c=='d') || (c=='D')) { opt_extractdir=1; strcat(dirname,__DIR__); strcat(dirname,"/"); strcat(dirname,argv[i+1]); } if (((c=='p') || (c=='P')) && (i+1<argc)) { password=argv[i+1]; i++; } } } else { if (!strlen(zipfilename)) { strcat(zipfilename,__DIR__); strcat(zipfilename,"/"); strcat(zipfilename,argv[i]); } else if ((!strlen(filename_to_extract)) && (!opt_extractdir)) { strcat(filename_to_extract,__DIR__); strcat(filename_to_extract,"/"); strcat(filename_to_extract,argv[i]); } } } } if (strlen(zipfilename)) { # ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; # endif strncpy(filename_try, zipfilename,MAXFILENAME-1); /* strncpy doesnt append the trailing NULL, of the string is too long. */ filename_try[ MAXFILENAME ] = 0; # ifdef USEWIN32IOAPI fill_win32_filefunc64A(&ffunc); uf = unzOpen2_64(zipfilename,&ffunc); # else uf = unzOpen64(zipfilename); # endif if (uf==NULL) { strcat(filename_try,".zip"); # ifdef USEWIN32IOAPI uf = unzOpen2_64(filename_try,&ffunc); # else uf = unzOpen64(filename_try); # endif } } if (uf==NULL) { printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); return 1; } printf("%s opened\n",filename_try); if (opt_do_list==1) ret_value = do_list(uf); else if (opt_do_extract==1) { chdir(__DIR__); #ifdef _WIN32 if (opt_extractdir && _chdir(dirname)) #else if (opt_extractdir && chdir(dirname)) #endif { printf("Error changing into %s, aborting\n", dirname); exit(-1); } if (!strlen(filename_to_extract)) ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password); else ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password); } unzClose(uf); return ret_value; }
void 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); LOG_DEBUG("Adding zip file '%s' at position %d.", file_name, index); zip_files[index].file_name = name; zip_files[index].file = file; zip_files[index].files = files; zip_files[index].count = count; CHECK_AND_UNLOCK_MUTEX(zip_files[index].mutex); LEAVE_DEBUG_MARK("load zip"); LOG_DEBUG("Loaded zip file '%s' with %d files", file_name, count); }
Uint32 update(const char* server, const char* file, const char* dir, const char* zip, progress_fnc update_progress_function, void* user_data) { char *tmp[MAX_OLD_UPDATE_FILES]; const size_t tmp_size = 1024; char *path = NULL; const size_t path_size = 1024; char *str = NULL; const size_t str_size = 1024; char *etag = NULL; const size_t etag_size = 1024; char md5[33]; unzFile source_zips[MAX_OLD_UPDATE_FILES]; zipFile dest_zip; update_info_t* infos; Uint32 count, result, i; path = (char*)calloc(sizeof(char), path_size); safe_snprintf(path, path_size, "http://%s/%s/", server, dir); str = (char *)calloc(sizeof(char), str_size); safe_snprintf(str, str_size, "Downloading from server %s", path); update_progress_function(str, 0, 0, user_data); for (i = 0; i < MAX_OLD_UPDATE_FILES; i++) { tmp[i] = (char *)calloc(sizeof(char), tmp_size); safe_snprintf(tmp[i], tmp_size, "%s%s%i", zip, ".t", i); } safe_snprintf(str, str_size, "Opening %s", zip); update_progress_function(str, 0, 0, user_data); memset(str, 0, str_size); source_zips[0] = unzOpen64(zip); unzGetGlobalComment(source_zips[0], str, str_size); unzClose(source_zips[0]); infos = 0; count = 0; etag = (char *)calloc(sizeof(char), etag_size); memset(md5, 0, sizeof(md5)); sscanf(str, "ETag: %s MD5: %32s", etag, md5); result = build_update_list(server, file, path, &infos, &count, md5, etag_size, etag, update_progress_function, user_data); if (result != 0) { free(path); free(str); free(etag); for (i = 0; i < MAX_OLD_UPDATE_FILES; i++) free(tmp[i]); if (result == 1) return 0; free(infos); return 3; } source_zips[0] = unzOpen64(zip); remove(tmp[MAX_OLD_UPDATE_FILES - 1]); for (i = MAX_OLD_UPDATE_FILES - 1; i > 0; i--) { rename(tmp[i - 1], tmp[i]); source_zips[i] = unzOpen64(tmp[i]); } dest_zip = zipOpen64(tmp[0], APPEND_STATUS_CREATE); result = download_files(infos, count, server, path, MAX_OLD_UPDATE_FILES, source_zips, dest_zip, update_progress_function, user_data); if (result == 0) { memset(str, 0, str_size); safe_snprintf(str, str_size, "ETag: %s MD5: %s", etag, md5); } for (i = 0; i < MAX_OLD_UPDATE_FILES; i++) { unzClose(source_zips[i]); } zipClose(dest_zip, str); if (result == 2) { update_progress_function("Canceled updating", 0, 0, user_data); } free(infos); if (result != 0) { free(path); free(str); free(etag); for (i = 0; i < MAX_OLD_UPDATE_FILES; i++) free(tmp[i]); return result; } unload_zip_archive(zip); remove(zip); rename(tmp[0], zip); load_zip_archive(zip); for (i = 1; i < MAX_OLD_UPDATE_FILES; i++) { remove(tmp[i]); } update_progress_function("Update complete", 0, 0, user_data); free(path); free(str); free(etag); for (i = 0; i < MAX_OLD_UPDATE_FILES; i++) free(tmp[i]); return 0; }
static gboolean gst_genicamsrc_start (GstBaseSrc * bsrc) { GstGenicamSrc *src = GST_GENICAM_SRC (bsrc); GC_ERROR ret; uint32_t i, num_ifaces, num_devs; guint32 width, height, bpp, stride; GstVideoInfo vinfo; GST_DEBUG_OBJECT (src, "start"); /* bind functions from CTI */ if (!gst_genicamsrc_bind_functions (src)) { GST_ELEMENT_ERROR (src, LIBRARY, INIT, ("GenTL CTI could not be opened: %s", g_module_error ()), (NULL)); return FALSE; } /* initialize library and print info */ ret = GTL_GCInitLib (); HANDLE_GTL_ERROR ("GenTL Producer library could not be initialized"); gst_genicam_print_gentl_impl_info (src); /* open GenTL, print info, and update interface list */ ret = GTL_TLOpen (&src->hTL); HANDLE_GTL_ERROR ("System module failed to open"); gst_genicam_print_system_info (src); ret = GTL_TLUpdateInterfaceList (src->hTL, NULL, src->timeout); HANDLE_GTL_ERROR ("Failed to update interface list within timeout"); /* print info for all interfaces and open specified interface */ ret = GTL_TLGetNumInterfaces (src->hTL, &num_ifaces); HANDLE_GTL_ERROR ("Failed to get number of interfaces"); if (num_ifaces > 0) { GST_DEBUG_OBJECT (src, "Found %dGenTL interfaces", num_ifaces); for (i = 0; i < num_ifaces; ++i) { gst_genicam_print_interface_info (src, i); } } else { GST_ELEMENT_ERROR (src, LIBRARY, FAILED, ("No interfaces found"), (NULL)); goto error; } if (!src->interface_id || src->interface_id[0] == 0) { size_t id_size; GST_DEBUG_OBJECT (src, "Trying to find interface ID at index %d", src->interface_index); ret = GTL_TLGetInterfaceID (src->hTL, src->interface_index, NULL, &id_size); HANDLE_GTL_ERROR ("Failed to get interface ID at specified index"); if (src->interface_id) { g_free (src->interface_id); } src->interface_id = (gchar *) g_malloc (id_size); ret = GTL_TLGetInterfaceID (src->hTL, src->interface_index, src->interface_id, &id_size); HANDLE_GTL_ERROR ("Failed to get interface ID at specified index"); } GST_DEBUG_OBJECT (src, "Trying to open interface '%s'", src->interface_id); ret = GTL_TLOpenInterface (src->hTL, src->interface_id, &src->hIF); HANDLE_GTL_ERROR ("Interface module failed to open"); ret = GTL_IFUpdateDeviceList (src->hIF, NULL, src->timeout); HANDLE_GTL_ERROR ("Failed to update device list within timeout"); /* print info for all devices and open specified device */ ret = GTL_IFGetNumDevices (src->hIF, &num_devs); HANDLE_GTL_ERROR ("Failed to get number of devices"); if (num_devs > 0) { for (i = 0; i < num_devs; ++i) { gst_genicam_print_device_info (src, i); } } else { GST_ELEMENT_ERROR (src, LIBRARY, FAILED, ("No devices found on interface"), (NULL)); goto error; } if (!src->device_id || src->device_id[0] == 0) { size_t id_size; GST_DEBUG_OBJECT (src, "Trying to find device ID at index %d", src->device_index); GTL_IFGetDeviceID (src->hIF, src->device_index, NULL, &id_size); HANDLE_GTL_ERROR ("Failed to get device ID at specified index"); if (src->device_id) { g_free (src->device_id); } src->device_id = (gchar *) g_malloc (id_size); GTL_IFGetDeviceID (src->hIF, src->device_index, src->device_id, &id_size); HANDLE_GTL_ERROR ("Failed to get device ID at specified index"); } GST_DEBUG_OBJECT (src, "Trying to open device '%s'", src->device_id); ret = GTL_IFOpenDevice (src->hIF, src->device_id, DEVICE_ACCESS_CONTROL, &src->hDEV); HANDLE_GTL_ERROR ("Failed to open device"); /* find and open specified data stream id */ if (!src->stream_id || src->stream_id[0] == 0) { size_t id_size; GST_DEBUG_OBJECT (src, "Trying to find stream ID at index %d", src->stream_index); GTL_DevGetDataStreamID (src->hDEV, src->stream_index, NULL, &id_size); HANDLE_GTL_ERROR ("Failed to get stream ID at specified index"); if (src->stream_id) { g_free (src->stream_id); } src->stream_id = (gchar *) g_malloc (id_size); GTL_DevGetDataStreamID (src->hDEV, src->stream_index, src->stream_id, &id_size); HANDLE_GTL_ERROR ("Failed to get stream ID at specified index"); } GST_DEBUG_OBJECT (src, "Trying to open data stream '%s'", src->stream_id); ret = GTL_DevOpenDataStream (src->hDEV, src->stream_id, &src->hDS); HANDLE_GTL_ERROR ("Failed to open data stream"); { uint32_t num_urls = 0; char url[2048]; size_t url_len = sizeof (url); INFO_DATATYPE datatype; const uint32_t url_index = 0; ret = GTL_DevGetPort (src->hDEV, &src->hDevPort); HANDLE_GTL_ERROR ("Failed to get port on device"); ret = GTL_GCGetNumPortURLs (src->hDevPort, &num_urls); HANDLE_GTL_ERROR ("Failed to get number of port URLs"); GST_DEBUG_OBJECT (src, "Found %d port URLs", num_urls); GST_DEBUG_OBJECT (src, "Trying to get URL index %d", url_index); GTL_GCGetPortURLInfo (src->hDevPort, url_index, URL_INFO_URL, &datatype, url, &url_len); HANDLE_GTL_ERROR ("Failed to get URL"); GST_DEBUG_OBJECT (src, "Found URL '%s'", url); g_assert (url_len > 6); if (g_str_has_prefix (url, "file")) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("file url not supported yet"), (NULL)); goto error; } else if (g_str_has_prefix (url, "local")) { GError *err = NULL; GMatchInfo *matchInfo; GRegex *regex; gchar *filename, *addr_str, *len_str; uint64_t addr; size_t len; gchar *buf; regex = g_regex_new ("local:(?:///)?(?<filename>[^;]+);(?<address>[^;]+);(?<length>[^?]+)(?:[?]SchemaVersion=([^&]+))?", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, &err); if (!regex) { goto error; } g_regex_match (regex, url, (GRegexMatchFlags) 0, &matchInfo); filename = g_match_info_fetch_named (matchInfo, "filename"); addr_str = g_match_info_fetch_named (matchInfo, "address"); len_str = g_match_info_fetch_named (matchInfo, "length"); if (!filename || !addr_str || !len_str) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to parse local URL"), (NULL)); goto error; } addr = g_ascii_strtoull (addr_str, NULL, 16); len = g_ascii_strtoull (len_str, NULL, 16); buf = (gchar *) g_malloc (len); GTL_GCReadPort (src->hDevPort, addr, buf, &len); HANDLE_GTL_ERROR ("Failed to read XML from port"); if (g_str_has_suffix (filename, "zip")) { gchar *zipfilepath; unzFile uf; unz_file_info64 fileinfo; gchar xmlfilename[2048]; gchar *xml; zipfilepath = g_build_filename (g_get_tmp_dir (), filename, NULL); if (!g_file_set_contents (zipfilepath, buf, len, &err)) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to write zipped XML to %s", zipfilepath), (NULL)); goto error; } uf = unzOpen64 (zipfilepath); if (!uf) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to open zipped XML %s", zipfilepath), (NULL)); goto error; } //ret = unzGetGlobalInfo64(uf, &gi); ret = unzGetCurrentFileInfo64 (uf, &fileinfo, xmlfilename, sizeof (xmlfilename), NULL, 0, NULL, 0); if (ret != UNZ_OK) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to query zip file %s", zipfilepath), (NULL)); goto error; } ret = unzOpenCurrentFile (uf); if (ret != UNZ_OK) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to extract file %s", xmlfilename), (NULL)); goto error; } xml = (gchar *) g_malloc (fileinfo.uncompressed_size); if (!xml) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to allocate memory to extract XML file"), (NULL)); goto error; } ret = unzReadCurrentFile (uf, xml, fileinfo.uncompressed_size); if (ret != fileinfo.uncompressed_size) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to extract XML file %s", xmlfilename), (NULL)); goto error; } unzClose (uf); g_free (zipfilepath); zipfilepath = g_build_filename (g_get_tmp_dir (), xmlfilename, NULL); g_file_set_contents (zipfilepath, xml, fileinfo.uncompressed_size, &err); g_free (zipfilepath); g_free (xml); //GZlibDecompressor *decompress; //char *unzipped; //gsize outbuf_size, bytes_read, bytes_written; //GInputStream *zippedstream, *unzippedstream; //decompress = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB); ////zippedstream = g_memory_input_stream_new_from_data(buf, len, g_free); ////unzippedstream = g_converter_input_stream_new (zippedstream, G_CONVERTER(decompress)); ////g_input_stream_read_all (G_INPUT_STREAM(unzippedstream), //// g_converter_output_stream //outbuf_size = 10000000; //unzipped = (gchar*) g_malloc(outbuf_size); //g_converter_convert (G_CONVERTER (decompress), buf, len, unzipped, outbuf_size, G_CONVERTER_NO_FLAGS, &bytes_read, &bytes_written, &err); //GST_DEBUG_OBJECT (src, unzipped); } g_free (filename); g_free (addr_str); g_free (len_str); g_free (buf); } else if (g_str_has_prefix (url, "http")) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("file url not supported yet"), (NULL)); goto error; } } { // TODO: use Genicam node map for this guint32 val = 0; size_t datasize = 4; ret = GTL_GCReadPort (src->hDevPort, 0x30204, &val, &datasize); HANDLE_GTL_ERROR ("Failed to get width"); width = GUINT32_FROM_BE (val); ret = GTL_GCReadPort (src->hDevPort, 0x30224, &val, &datasize); HANDLE_GTL_ERROR ("Failed to get height"); height = GUINT32_FROM_BE (val); bpp = 8; } if (!gst_genicamsrc_prepare_buffers (src)) { GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to prepare buffers"), (NULL)); goto error; } { ret = GTL_GCRegisterEvent (src->hDS, EVENT_NEW_BUFFER, &src->hNewBufferEvent); HANDLE_GTL_ERROR ("Failed to register New Buffer event"); } ret = GTL_DSStartAcquisition (src->hDS, ACQ_START_FLAGS_DEFAULT, GENTL_INFINITE); HANDLE_GTL_ERROR ("Failed to start stream acquisition"); { // TODO: use Genicam node map for this guint32 val; size_t datasize; /* set AcquisitionMode to Continuous */ val = GUINT32_TO_BE (2); datasize = sizeof (val); ret = GTL_GCWritePort (src->hDevPort, 0x40004, &val, &datasize); HANDLE_GTL_ERROR ("Failed to start device acquisition"); /* send AcquisitionStart command */ val = GUINT32_TO_BE (1); datasize = sizeof (val); ret = GTL_GCWritePort (src->hDevPort, 0x40024, &val, &datasize); HANDLE_GTL_ERROR ("Failed to start device acquisition"); } /* create caps */ if (src->caps) { gst_caps_unref (src->caps); src->caps = NULL; } gst_video_info_init (&vinfo); if (bpp <= 8) { gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY8, width, height); src->caps = gst_video_info_to_caps (&vinfo); } else if (bpp > 8 && bpp <= 16) { GValue val = G_VALUE_INIT; GstStructure *s; if (G_BYTE_ORDER == G_LITTLE_ENDIAN) { gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width, height); } else if (G_BYTE_ORDER == G_BIG_ENDIAN) { gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_BE, width, height); } src->caps = gst_video_info_to_caps (&vinfo); /* set bpp, extra info for GRAY16 so elements can scale properly */ s = gst_caps_get_structure (src->caps, 0); g_value_init (&val, G_TYPE_INT); g_value_set_int (&val, bpp); gst_structure_set_value (s, "bpp", &val); g_value_unset (&val); } else { GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, ("Unknown or unsupported bit depth (%d).", bpp), (NULL)); return FALSE; } src->height = vinfo.height; src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); GST_DEBUG_OBJECT (src, "starting acquisition"); //TODO: start acquisition engine /* TODO: check timestamps on buffers vs start time */ src->acq_start_time = gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); return TRUE; error: if (src->hDS) { GTL_DSClose (src->hDS); src->hDS = NULL; } if (src->hDEV) { GTL_DevClose (src->hDEV); src->hDEV = NULL; } if (src->hIF) { GTL_IFClose (src->hIF); src->hIF = NULL; } if (src->hTL) { GTL_TLClose (src->hTL); src->hTL = NULL; } GTL_GCCloseLib (); return FALSE; }
unsigned char * LoadFirstFileInZip(const char* path,unsigned int *length) { unzFile uf=NULL; void* buf=NULL; # ifdef USEWIN32IOAPI zlib_filefunc64_def ffunc; # endif # ifdef USEWIN32IOAPI fill_win32_filefunc64A(&ffunc); uf = unzOpen2_64(path,&ffunc); # else uf = unzOpen64(path); # endif if (uf==NULL) { printf("Cannot open %s as zip\n",path); return 0; } // Was do Extract- - { uLong i; unz_global_info64 gi; int err; err = unzGetGlobalInfo64(uf,&gi); if (err!=UNZ_OK || gi.number_entry<1) { printf("error %d with zipfile in unzGetGlobalInfo \n",err); return 0; } { char filename_inzip[256]; char* filename_withoutpath; char* p; int err=UNZ_OK; FILE *fout=NULL; uInt size_buf; unz_file_info64 file_info; uLong ratio=0; err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) { printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); return 0; } size_buf=file_info.uncompressed_size; buf = malloc(file_info.uncompressed_size); if (buf==NULL) { printf("Error allocating memory\n"); return 0; } err = unzOpenCurrentFilePassword(uf,NULL); if (err!=UNZ_OK) { printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); return 0; } do { err = unzReadCurrentFile(uf,buf,size_buf); if (err<0) { printf("error %d with zipfile in unzReadCurrentFile\n",err); return 0; } } while (err>0); if (err==UNZ_OK) { err = unzCloseCurrentFile (uf); if (err!=UNZ_OK) { printf("error %d with zipfile in unzCloseCurrentFile\n",err); return 0; } } *length=size_buf; } } unzClose(uf); return buf; }
std::string Kmz2Collada(std::string strInputFile) { int iFileLength; unzFile zFile; unsigned int num = 512; unz_file_info64 zFileInfo; unz_global_info64 zGlobalInfo; char *pFileName = new char[num]; std::string strDaePath; std::string strKmzPath; zFile = unzOpen64(strInputFile.c_str()); if (NULL == zFile) { printf("Open Kmz file error\n"); return ""; } char *pTemporaryContent = new char[strInputFile.size()+1]; std::string strFilePath; for (unsigned int ipos = 0; ipos < strInputFile.size(); ipos ++) { if (strInputFile[ipos] == '\\' || strInputFile[ipos] == '/') { pTemporaryContent[ipos] = '\0'; strFilePath = pTemporaryContent; _mkdir(strFilePath.c_str()); } pTemporaryContent[ipos] = strInputFile[ipos]; } if (strFilePath != "") strFilePath += '\\'; strInputFile = strFilePath; strKmzPath = strInputFile; delete[] pTemporaryContent; if (UNZ_OK != unzGetGlobalInfo64(zFile, &zGlobalInfo)) { printf("Parsing file error\n"); return ""; } for (int i = 0; i < zGlobalInfo.number_entry; i++) { if (UNZ_OK != unzGetCurrentFileInfo64(zFile, &zFileInfo, pFileName, num, NULL, 0, NULL, 0)) { printf("Read file error\n"); return ""; } std::string strFilePath = pFileName; std::string strFolderPath = ""; char *pFolderName = new char[strFilePath.size()]; for (unsigned int i = 0; i < strFilePath.size(); i++) { if (strFilePath[i] == '\\' || strFilePath[i] == '/') { pFolderName[i] = '\0'; strFolderPath = strKmzPath + pFolderName; _mkdir(strFolderPath.c_str()); } pFolderName[i] = strFilePath[i]; } strFilePath = strKmzPath +strFilePath; delete[] pFolderName; if (strstr(strFilePath.c_str(), ".dae")) strDaePath = strFilePath; FILE *fp = fopen(strFilePath.c_str(), "wb"); if (UNZ_OK != unzOpenCurrentFile(zFile)) { printf("Open current file error"); return ""; } iFileLength = (int)zFileInfo.uncompressed_size; char *pFileData = new char[iFileLength]; int len = 1; while (len) { len = unzReadCurrentFile(zFile, (voidp)pFileData, iFileLength - 1); pFileData[len] = '\0'; if ( len <= 0) { break; } fwrite(pFileData, 1, len, fp); } fclose(fp); delete[] pFileData; pFileData = NULL; unzGoToNextFile(zFile); } unzCloseCurrentFile(zFile); delete[] pFileName; pFileName = NULL; return strDaePath; }