Example #1
0
BOOL CUnzipper::Unzip(LPCTSTR szFileName, LPCTSTR szFolder, BOOL bIgnoreFilePath)
{
	CloseZip();

	if (!OpenZip(szFileName))
		return FALSE;
	if (szFolder == NULL)
		szFolder = m_szOutputFolder;

	BOOL bRet = UnzipTo(szFolder, bIgnoreFilePath);

	CloseZip();

	return bRet;
}
Example #2
0
void UnzipWithProgress(const TCHAR *zipfn, HWND hprog)
{ HZIP hz = OpenZip(zipfn,0);
  ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numentries=ze.index;
  // first we retrieve the total size of all zip items
  DWORD tot=0; for (int i=0; i<numentries; i++) {GetZipItem(hz,i,&ze); tot+=ze.unc_size;}
  //
  DWORD countall=0; // this is our progress so far
  for (int i=0; i<numentries && !abort_p; i++)
  { GetZipItem(hz,i,&ze);
    // We'll unzip each file bit by bit, to a file on disk
    char fn[1024]; wsprintf(fn,"\\z\\%s",ze.name);
    HANDLE hf = CreateFile(fn,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
    char buf[16384]; // Each chunk will be 16k big. After each chunk, we show progress
    DWORD countfile=0;
    for (ZRESULT zr=ZR_MORE; zr==ZR_MORE && !abort_p; ) // nb. the global "abort_p" flag is set by the user clicking the Cancel button.
    { zr=UnzipItem(hz,i,buf,16384);
      unsigned long bufsize=16384; if (zr==ZR_OK) bufsize=ze.unc_size-countfile; // bufsize is how much we got this time
      DWORD writ; WriteFile(hf,buf,bufsize,&writ,0); 
      countfile+=bufsize; // countfile counts how much of this file we've unzipped so far
      countall+=bufsize; // countall counts how much total we've unzipped so far
      // Now show progress, and let Windows catch up...
      int i = (int)(100.0*((double)countall)/((double)tot));
      SendMessage(hprog,PBM_SETPOS,i,0); PumpMessages();
    }
    CloseHandle(hf);
    if (abort_p) DeleteFile(fn);
  }
  CloseZip(hz);
}
//-----------------------------------------------------------------------------
// Uploads a screenshot to a particular listener
//-----------------------------------------------------------------------------
void CServerRemoteAccess::UploadScreenshot( const char *pFileName )
{
#ifndef SWDS
	if ( m_nScreenshotListener < 0 )
		return;

	CUtlBuffer buf( 128 * 1024, 0 );
	if ( g_pFullFileSystem->ReadFile( pFileName, "MOD", buf ) )
	{
		HZIP hZip = CreateZipZ( 0, 1024 * 1024, ZIP_MEMORY );
		void *pMem;
		unsigned long nLen;
		ZipAdd( hZip, "screenshot.jpg", buf.Base(), buf.TellMaxPut(), ZIP_MEMORY );
		ZipGetMemory( hZip, &pMem, &nLen );
		SendResponseToClient( m_nScreenshotListener, SERVERDATA_SCREENSHOT_RESPONSE, pMem, nLen );
		CloseZip( hZip );
	}
	else
	{
		LogCommand( m_nScreenshotListener, "Failed to read screenshot!\n" );
		RespondString( m_nScreenshotListener, 0, "Failed to read screenshot!\n" );
	}

	m_nScreenshotListener = -1;
#endif
}
Example #4
0
void CPropertiesFiles::OnBnClickedPropPreview()
{
	// TODO: 在此加入控制項告知處理常式程式碼
	CListBox* listBox=(CListBox*)this->GetDlgItem(IDC_PROP_FILELIST);
	int curSel=listBox->GetCurSel();

	if (curSel>=0) {
		LPTSTR pszFile=(LPTSTR)malloc(listBox->GetTextLen(curSel)+1);
		HZIP hZip;
		ZIPENTRY ze;
		CARMDlg* dlg=(CARMDlg*)this->GetParentOwner()->GetParent();
		arfile* arFile=(arfile*)dlg->m_lstFiles.GetItemDataPtr(dlg->m_lstFiles.GetCurSel());

		listBox->GetText(curSel,pszFile);
		hZip=OpenZip(arFile->fileName,0,ZIP_FILENAME);
		if (hZip) {
			int nIndex;
			if (FindZipItem(hZip,pszFile,TRUE,&nIndex,&ze)!=ZR_ARGS) {
				LPBYTE pszContent=(LPBYTE)malloc(ze.unc_size);
				UnzipItem(hZip,nIndex,pszContent,ze.unc_size,ZIP_MEMORY);
				bitmapInfo=&ze;

				DialogBoxParam(theApp.m_hInstance,MAKEINTRESOURCE(IDD_PREVIEW),this->GetSafeHwnd(),(DLGPROC)CPropertiesFiles::previewWndProc,(LPARAM)pszContent);
				free(pszContent);
			}

			CloseZip(hZip);
		}

		free(pszFile);
	}
}
Example #5
0
bool CZipObj::UnZipFile(CString strZipPath, CString strUnzipPath)
{
	USES_CONVERSION;
	int nPos = strZipPath.ReverseFind('.');
	CString strPath = strZipPath.Left(nPos);		//.zip		strZipPath.GetLength() - 4
	if (strUnzipPath != "")
		strPath = strUnzipPath;
	std::string strUtf8Path = CMyCodeConvert::Gb2312ToUtf8(T2A(strPath));

	try
	{
		Poco::File p(strUtf8Path);	//T2A(strPath)
		if (p.exists())
			p.remove(true);
	}
	catch (Poco::Exception)
	{
	}
	
	HZIP hz = OpenZip(strZipPath, _strPwd.c_str());
	ZIPENTRY ze;
	GetZipItem(hz, -1, &ze);
	int numitems = ze.index;
	SetUnzipBaseDir(hz, strPath);
	for (int i = 0; i < numitems; i++)
	{
		GetZipItem(hz, i, &ze);
		UnzipItem(hz, i, ze.name);
	}
	CloseZip(hz);

	return true;
}
Example #6
0
CZipper::CZipper(LPCTSTR szFilePath, LPCTSTR szRootFolder, bool bAppend) : m_uzFile(0)
{
	CloseZip();

	if (szFilePath)
		OpenZip(szFilePath, szRootFolder, bAppend);
}
Example #7
0
BOOL CUnzipper::OpenZip(LPCTSTR szFileName)
{
	CloseZip();

	if (szFileName)
	{
		zlib_filefunc64_def filefunc_def;
		fill_fopen64_filefunc(&filefunc_def);
		filefunc_def.zopen64_file = (open64_file_func)wfopen_file_func;
		filefunc_def.ztell64_file = (tell64_file_func)ftell64_file_func;
		filefunc_def.zseek64_file = (seek64_file_func)fseek64_file_func;
		m_uzFile = unzOpen2_64((const char *)szFileName, &filefunc_def);

		if (m_uzFile)
		{
			// set the default output folder
			wchar_t* szPath = _wcsdup(szFileName);

			// strip off extension
			wchar_t* p = wcsrchr(szPath, '.');

			if (p)
				*p = 0;
			wcscpy_s(m_szOutputFolder, MAX_PATH + 1, szPath);
			free(szPath);
		}
	}

	return (m_uzFile != NULL);
}
Example #8
0
			void File::Close()
			{
				if ( m_Write )
				{
					CloseZip( ( XZip::HZIP ) m_Write );
					m_Write = NULL;
				}
			}
Example #9
0
void test_unzip()
{
    wstring sFilePath;
    sFilePath = L"c:\\1.zip";

    HZIP hz = OpenZip((void *)sFilePath.c_str(), 0, 2);
    if( hz == NULL )
    {
        cout<<"Error opening zip file"<<endl;
        return;
    }
    ZIPENTRY ze; 
    int i; 
    if( FindZipItem(hz, L"1.txt", true, &i, &ze) != 0 )
    {
        cout<<"Could not find ziped file"<<endl;
        return;
    }
    DWORD dwSize = ze.unc_size;
    if( dwSize == 0 ) 
    {
        cout<<"File is empty";
        return;
    }
    if ( dwSize > 4096*1024 ) 
    {
        cout<<"File too large";
        return;
    }
    BYTE* pByte = new BYTE[ dwSize + 1 ];
    ZeroMemory(pByte, dwSize + 1);
    int res = UnzipItem(hz, i, pByte, dwSize, 3);
    if( res != 0x00000000 && res != 0x00000600)
    {
        delete[] pByte;
        CloseZip(hz);
        cout<<"Could not unzip file";
        return;
    }
    CloseZip(hz);
    cout<<pByte<<endl;
    delete[] pByte;
}
Example #10
0
bool CompressFiles(std::string ZipName, std::vector<std::string>* pFilePaths, std::string* pError) //pointer to a vector of filepath strings to zip into location of ZipName (also a filepath)
{
#ifdef WIN32

	HZIP hz = CreateZip(ZipName.c_str(),0);
	if (!hz){if (pError) *pError += "Could not create ZIP archive. Aborting\n"; return false;}

	int NumFiles = pFilePaths->size();
	for (int i=0; i<NumFiles; i++){
		std::string ThisFilePath = (*pFilePaths)[i];

		//extract file name (without path)
		int StartName = ThisFilePath.find_last_of('/')+1;
		int EndName = ThisFilePath.size();
		std::string Name = ThisFilePath.substr(StartName, EndName-StartName);

		//remove .tmp from end if it exists...
		std::string Last4 = Name.substr(Name.size()-4, 4);
		if (Last4.compare(".tmp")==0) Name = Name.substr(0, Name.size()-4);

		if(ZipAdd(hz, Name.c_str(), ThisFilePath.c_str()) != ZR_OK){if (pError) *pError += ("Could not add file to ZIP archive. Aborting.\n"); return false;}
	}

	if(CloseZip(hz) != ZR_OK){if (pError) *pError += ("Could not close ZIP archive. Aborting.\n"); return false;}

	return true;
#else
	//Mac/Linux Zip write code
	remove(ZipName.c_str());
	int err;
	struct zip * hz = zip_open(ZipName.c_str(), ZIP_CREATE, &err);
	if (!hz){if (pError) *pError += "Could not create ZIP archive. Aborting\n"; return false;}

	int NumFiles = pFilePaths->size();
	for (int i=0; i<NumFiles; i++){
		std::string ThisFilePath = (*pFilePaths)[i];

		//extract file name (without path)
		int StartName = ThisFilePath.find_last_of('/')+1;
		int EndName = ThisFilePath.size();
		std::string Name = ThisFilePath.substr(StartName, EndName-StartName);

		//remove .tmp from end if it exists...
		std::string Last4 = Name.substr(Name.size()-4, 4);
		if (Last4.compare(".tmp")==0) Name = Name.substr(0, Name.size()-4);

		struct zip_source * source =
		  zip_source_file(hz, ThisFilePath.c_str(), 0, 0);

		if(source == NULL || zip_add(hz, Name.c_str(), source) == -1){if (pError) *pError += ("Could not add file to ZIP archive. Aborting.\n"); return false;}
	}
	if (zip_close(hz) != 0) {if(pError) *pError += "Error closing ZIP file.\n"; return false;}
	return true;
#endif
}
Example #11
0
bool CZip::extract(const QString & filePath, const QString & extDirPath, const QString & singleFileName, const QString &password)
{
    HZIP hz = OpenZip(filePath.toStdString().c_str(), password.isEmpty() ? 0 : password.toStdString().c_str());

    if(!hz) {
        return false;
    }

    SetUnzipBaseDir(hz,extDirPath.toStdString().c_str());

    if (!singleFileName.isEmpty())
    {
        ZIPENTRY ze;
        int i; 
        FindZipItem(hz, singleFileName.toStdString().c_str(), true, &i, &ze);
        UnzipItem(hz, i, ze.name);
        CloseZip(hz);

        return true;
    }

    for (int i = 0; ;i++)
    { 
        ZIPENTRY ze;
        ZRESULT zr = GetZipItem(hz, i, &ze); 

        if (zr != ZR_OK) {

            if(zr == ZR_FAILED || zr == ZR_NOTFOUND) {
                CloseZip(hz);
                return false;
            }

            break; // no more
        }
        UnzipItem(hz, i, ze.name);
    }

    CloseZip(hz);

    return true;
}
Example #12
0
bool CZip::archive(const QString &filePath, const QDir &dir, const QString &comment)
{
   HZIP hz = CreateZip(filePath.toLatin1().data(), 0); 
   if (hz == 0) {
       qDebug() << "* Failed to create folders.zip";
   }

   ZRESULT zr;

   //zr = ZipAddFolder(hz, dir.dirName().toLatin1().data());

   if(!RecurseDirectory(hz, dir.absolutePath()))
   {
       zr = CloseZip(hz);
       return false;
   }
   zr = CloseZip(hz);

   return true;
 }
static BOOL unzip(HZIP zipf, int nitems, IProgressDialog *pd) {
    int i = 0;
    ZRESULT res;
    ZIPENTRYW ze;

    for (i = 0; i < nitems; i++) {
        res = GetZipItem(zipf, i, &ze);
        if (res != ZR_OK) { show_zip_error(L"Failed to get zip item", L"", res); return false;}
        
        res = UnzipItem(zipf, i, ze.name, 0, ZIP_FILENAME);
        if (res != ZR_OK) { CloseZip(zipf); show_zip_error(L"Failed to extract zip item (is your disk full?):", ze.name, res); return false;}

        pd->SetLine(2, ze.name, true, NULL);
        pd->SetProgress(i, nitems);
    }

    CloseZip(zipf);

    return true;
}
Example #14
0
DWORD WINAPI ZipThreadProc(void *)
{ int size=40*1024*1024; // 40mb big!
  char *c=new char[size]; for (int i=0; i<size; i+=4) {*(int*)(c+i) = rand();}
  CreateDirectory("\\z",0);
  HZIP hz = CreateZip("\\z\\progress.zip",0);
  ZipAdd(hz,"progress1.zip",c,size);
  ZipAdd(hz,"progress2.zip",c,size);
  CloseZip(hz);
  delete[] c;
  return 0;
}
Example #15
0
int main()
{   HZIP hz;

    hz = CreateZip("std1.zip",0);
    ZipAdd(hz,"znsimple.jpg", "std_sample.jpg");
    ZipAdd(hz,"znsimple.txt", "std_sample.txt");
    CloseZip(hz);

    hz = OpenZip("std1.zip",0);
    ZIPENTRY ze;
    GetZipItem(hz,-1,&ze);
    int numitems=ze.index;
    for (int zi=0; zi<numitems; zi++)
    {   GetZipItem(hz,zi,&ze);
        UnzipItem(hz,zi,ze.name);
    }
    CloseZip(hz);

    return 0;
}
Example #16
0
bool CZipObj::ZipFile(CString strSrcPath, CString strDstPath, CString strExtName /*= _T(".zip")*/)
{
	USES_CONVERSION;
	//	CString modelName = strSrcPath.Right(strSrcPath.GetLength() - strSrcPath.ReverseFind('\\') - 1);
	CString zipName = strDstPath + strExtName;
	std::string strUtf8ZipName = CMyCodeConvert::Gb2312ToUtf8(T2A(zipName));

	try
	{
		Poco::File p(strUtf8ZipName);	//T2A(zipName)
		if (p.exists())
			p.remove(true);
	}
	catch (Poco::Exception)
	{
	}

	//	std::string strModelPath = T2A(strSrcPath);
	std::string strUtf8ModelPath = CMyCodeConvert::Gb2312ToUtf8(T2A(strSrcPath));
	try
	{
		Poco::File p2(strUtf8ModelPath);	//T2A(zipName)
		if (!p2.exists())
		{
			std::string strErr = Poco::format("需要压缩的原文件夹(%s)不存在。", T2A(strSrcPath));
			RecordLog(strErr);
			return false;
		}
	}
	catch (Poco::Exception)
	{
	}

	HZIP hz = CreateZip(zipName, _strPwd.c_str());

	Poco::DirectoryIterator it(strUtf8ModelPath);	//strModelPath
	Poco::DirectoryIterator end;
	while (it != end)
	{
		Poco::Path p(it->path());
		//		std::string strZipFileName = p.getFileName();
		std::string strPath = CMyCodeConvert::Utf8ToGb2312(p.toString());
		std::string strZipFileName = CMyCodeConvert::Utf8ToGb2312(p.getFileName());
		CString strZipPath = A2T(strPath.c_str());
		CString strName = A2T(strZipFileName.c_str());
		//		ZipAdd(hz, A2T(strZipFileName.c_str()), A2T(p.toString().c_str()));
		ZipAdd(hz, strName, strZipPath);
		it++;
	}
	CloseZip(hz);

	return true;
}
Example #17
0
void CAppManager::ReloadRhoBundle(const char* szUrl, const char* szZipPassword)
{
	if ( szUrl )
	{
		//get zip file with rhodes
		DWORD dwDataSize = 0;
		char* zipData = remote_data( L"GET", const_cast<char*>(szUrl), NULL, 0, false, true, false, &dwDataSize );

		LPWSTR rootw = wce_mbtowc(RhoGetRootPath());  

		//TODO: Add error handling
		if ( zipData && dwDataSize > 0 )
		{
			ZIPENTRY ze; 
			// Open zip file
			HZIP hz = OpenZip(zipData, dwDataSize, szZipPassword);
			
			if ( hz )
			{
				//Stop HTTP Server
				CHttpServer::Instance()->FreezeThread();

				// Set base for unziping
				SetUnzipBaseDir(hz, rootw);
				
				// Get info about the zip
				// -1 gives overall information about the zipfile
				GetZipItem(hz,-1,&ze);
				int numitems = ze.index;
				
				// Iterate through items and unzip them
				for (int zi = 0; zi<numitems; zi++)
				{ 
					// fetch individual details, e.g. the item's name.
					GetZipItem(hz,zi,&ze); 
					// unzip item
					UnzipItem(hz, zi, ze.name);         
				}
				
				CloseZip(hz);

				//Show MessageBox
				MessageBox(NULL, _T("Rhobundle has been updated successfully.\n\nPlease restart application."), _T("Information"), MB_OK | MB_ICONINFORMATION );
			}
		}

		if ( rootw )
			free(rootw);

		if ( zipData )
			delete zipData;
	}
}
Example #18
0
void CMainDlg::AddUserInfoToCrashDescriptorXML(CString sEmail, CString sDesc)
{ 
  USES_CONVERSION;

  HZIP hz = CreateZip(m_sZipName, NULL);
  
  TStrStrMap::iterator cur = m_pUDFiles.begin();
  unsigned int i;
  for (i = 0; i < m_pUDFiles.size(); i++, cur++)
  {
    CString sFileName = cur->first.c_str();
    sFileName = sFileName.Mid(sFileName.ReverseFind('\\')+1);
    if(sFileName.CompareNoCase(_T("crashrpt.xml"))==0)
    {
      TiXmlDocument doc;
  
      bool bLoad = doc.LoadFile(cur->first.c_str());
      if(!bLoad)
        return;

      TiXmlNode* root = doc.FirstChild("CrashRpt");
      if(!root)
        return;

      // Write user e-mail

      TiXmlElement* email = new TiXmlElement("UserEmail");
      root->LinkEndChild(email);

      LPSTR lpszEmail = T2A(sEmail.GetBuffer(0));
      TiXmlText* email_text = new TiXmlText(lpszEmail);
      email->LinkEndChild(email_text);              

      // Write problem description

      TiXmlElement* desc = new TiXmlElement("ProblemDescription");
      root->LinkEndChild(desc);

      LPSTR lpszDesc = T2A(sDesc.GetBuffer(0));
      TiXmlText* desc_text = new TiXmlText(lpszDesc);
      desc->LinkEndChild(desc_text);              

      doc.SaveFile();      
    }

	LPTSTR lptszFilePath = A2T((char*)cur->first.c_str());
    ZRESULT zr = ZipAdd(hz, sFileName, lptszFilePath);
    ATLASSERT(zr==ZR_OK); 
	zr;
  }  

  CloseZip(hz);
}
QString ClassSpaceChecker::unzipFile(const QString &jarPath, const ClassFileContext *ctx)
{
	QString output;
	bool ok = false;

#if defined(Q_WS_WIN)
	QString f = jarPath;
	
	HZIP hz = OpenZip( (void *)f.toStdWString().c_str(), 0, ZIP_FILENAME );
	if( !hz ) 
	{
		QMessageBox::warning(this, "", tr("Jar file not found."));
		ui.comboBox_JarFile->setFocus();
		return "";
	}

	do{
		ZIPENTRYW ze; 
		ZRESULT zr = GetZipItem( hz, -1, &ze ); 
		if( zr != ZR_OK )
			break;
		
		int i; 
		zr = FindZipItem(hz, ctx->filePath.toStdWString().c_str(), true, &i, &ze);
		if( zr != ZR_OK )
			break;

		//QString output = generateFileTempPath() + "Temp.class";
		output = generateFileTempPath() + ctx->fullClassNameForKey + (ctx->javaFileFlag ? ".java" : ".class");
		zr = UnzipItem(hz, i, (void*)output.toStdWString().c_str(), 0, ZIP_FILENAME);
		if( zr != ZR_OK )
			break;

		ok = true;
	} while( false );

	CloseZip(hz);

#else
	// TODO : other platform(MacOS) unzip patch file
	return false;
#endif

	if(ok)
		return output;

	return "";
}
Example #20
0
// Packages all files in "path" into a .zip file.
void CreateArchive(string path, string name, ArchiveInfo& info)
{
	HZIP hz = CreateZip(name.c_str(), 0);

	HANDLE hFind = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA ffd;
	string spec;
    stack<string> directories;

    directories.push(path);

    while (!directories.empty()) {
        path = directories.top();
        spec = path + "/*";
        directories.pop();

        hFind = FindFirstFile(spec.c_str(), &ffd);
        if (hFind == INVALID_HANDLE_VALUE)  
            return;

        do {
            if (strcmp(ffd.cFileName, ".") != 0 && strcmp(ffd.cFileName, "..") != 0) {
                if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
					// Add folder to archive.
					ZipAddFolder(hz, string(path + "/" + ffd.cFileName).c_str());
                    directories.push(path + "/" + ffd.cFileName);
                }
                else {
					// Add file to archive.
					ZipAdd(hz, string(path + "/" + ffd.cFileName).c_str(), string(path + "/" + ffd.cFileName).c_str());
					info.files++;
					info.size += FileSize(path + "/" + ffd.cFileName);
                }
            }
        } while (FindNextFile(hFind, &ffd) != 0);

        if (GetLastError() != ERROR_NO_MORE_FILES) {
            FindClose(hFind);
            return;
        }

        FindClose(hFind);
        hFind = INVALID_HANDLE_VALUE;
    }

	CloseZip(hz);
}
Example #21
0
int CUpdateThread::UnzipPackage(wchar_t* pPackageName)
{
	if( pPackageName == NULL)
		return -1;

	// 启动线程,进行更新
	HZIP hz = OpenZip((void*)pPackageName, 0, 2);

	unsigned int nZipItemNum;
	ZRESULT zResult = GetZipItemNum(hz, &nZipItemNum);
	if( zResult != ZR_OK)
		return -1;

	size_t i=0;
	for( ; i<nZipItemNum; i++)
	{
		ZIPENTRY ze; 
		zResult = GetZipItemA(hz, i, &ze);
		if( zResult != ZR_OK)
			continue;

		USES_CONVERSION;
		wchar_t* pName = wcsdup(A2W(ze.name));

		wchar_t szName[MAX_PATH];
		memset(szName, 0x0, MAX_PATH);
		swprintf(szName, L"%s%s", MiscHelper::GetUnpackagePath(),pName);
		zResult = UnzipItem(hz, i, (void*)szName, wcslen(szName),ZIP_FILENAME);

		// 解压失败
		if( zResult != ZR_OK)
			break;

		FileHelper::ModifyFileAttribute(szName, 0, FILE_ATTRIBUTE_READONLY);
	}
	CloseZip(hz);

	// 更新失败
	if( i < nZipItemNum)
	{
		::MessageBox(NULL, L"安装包解压失败,无法正确进行更新", L"更新提示", MB_OK);
		return -1;
	}

	return 0;
}
Example #22
0
// CPropertiesFiles 訊息處理常式
BOOL CPropertiesFiles::OnInitDialog() {
	CPropertyPage::OnInitDialog();

	HZIP hZip;
	ZIPENTRY ze;
	CARMDlg* dlg=(CARMDlg*)this->GetParentOwner()->GetParent();
	arfile* arFile=(arfile*)dlg->m_lstFiles.GetItemDataPtr(dlg->m_lstFiles.GetCurSel());

	hZip=OpenZip(arFile->fileName,0,ZIP_FILENAME);
	if (hZip) {
		for (int c=0; GetZipItem(hZip,c,&ze)!=ZR_ARGS; c++) {
			if (ze.name[_tcslen(ze.name)-1]!='/')
				((CListBox*)this->GetDlgItem(IDC_PROP_FILELIST))->AddString(ze.name);
		}
		CloseZip(hZip);
	}
	return FALSE;
}
Example #23
0
bool CDlgView::UnZipFile(string unzipfilename,string zipfilepath)
{
    HZIP hz; //DWORD writ;

    // EXAMPLE 2 - unzip it with the names suggested in the zip
    hz = OpenZip(unzipfilename.c_str(),0);
    string path = zipfilepath +"\\";
    SetUnzipBaseDir(hz,path.c_str());
    ZIPENTRY ze;
    GetZipItem(hz,-1,&ze);
    int numitems=ze.index;
    for (int zi=0; zi<numitems; zi++)
    {   GetZipItem(hz,zi,&ze);
        UnzipItem(hz,zi,ze.name);
    }
    CloseZip(hz);
    return true;
}
Example #24
0
duWindowManager::~duWindowManager()
{
	if (m_pJavaScript)
	{
		delete m_pJavaScript;
		m_pJavaScript = NULL;
	}

	if (m_pDocXml)
	{
		delete m_pDocXml;
		m_pDocXml = NULL;
	}
	
	if (m_hZip)
	{
		CloseZip(m_hZip);
		m_hZip = NULL;
	}
	
	if (m_pTrialImage)
	{
		m_pTrialImage->FinalRelease();
		m_pTrialImage = NULL;
	}

	//SAFE_DELETE(m_pResManager);
	//m_mapCtrlManager.clear();

	//if (g_setValid)
	//{
	//	g_setValid->clear();
	//	delete g_setValid;
	//	g_setValid = NULL;
	//}			

	//if (g_pTypeLib)
	//{
	//	delete g_pTypeLib;
	//	g_pTypeLib = NULL;
	//}

	//GdiplusShutdown(g_gdiplusToken);
}
bool findPackageFromEmbeddedZip(wchar_t* buf, DWORD cbSize) 
{
	bool ret = false;

	CResource zipResource;
	if (!zipResource.Load(L"DATA", IDR_UPDATE_ZIP)) {
		return false;
	}

	DWORD dwSize = zipResource.GetSize();
	if (dwSize < 0x100) {
		return false;
	}

	BYTE* pData = (BYTE*)zipResource.Lock();
	HZIP zipFile = OpenZip(pData, dwSize, NULL);

	ZRESULT zr;
	int index = 0;
	do {
		ZIPENTRY zentry;

		zr = GetZipItem(zipFile, index, &zentry);
		if (zr != ZR_OK && zr != ZR_MORE) {
			break;
		}

		if (wcsstr(zentry.name, L"nupkg")) {
			ZeroMemory(buf, cbSize);

			int idx = wcscspn(zentry.name, L"-");
			memcpy(buf, zentry.name, sizeof(wchar_t) * idx);
			ret = true;
			break;
		}

		index++;
	} while (zr == ZR_MORE || zr == ZR_OK);

	CloseZip(zipFile);
	zipResource.Release();

	return ret;
}
BOOL CMyUtility::UnZip( LPCTSTR wcPathIn, LPCTSTR wcExtractObject, LPCTSTR wcPathOut )
{
	HZIP hz;
	int index, numfile;
	ZIPENTRYW ze = {0};
	TCHAR wcFilePath[MAX_PATH] = {0};
	if(!wcPathIn)
		return FALSE;


	hz = OpenZip((void*)wcPathIn, 0, ZIP_FILENAME);
	if (!hz)
		return FALSE;
	GetZipItem(hz, -1, &ze);
	numfile = ze.index;
	for(index = 0; index < numfile; index++)
	{
		GetZipItem(hz, index, &ze);
		if (!wcExtractObject)
		{
			swprintf(wcFilePath, MAX_PATH - 1, _T("%s\\%s"), wcPathOut, ze.name);
			UnzipItem(hz, index, wcFilePath, 0, ZIP_FILENAME);
		}
		else 
		{
			int len = lstrlen(wcExtractObject);
			if (_tcsnicmp(wcExtractObject, ze.name, len) == 0)
			{
				swprintf(wcFilePath, MAX_PATH - 1, _T("%s\\%s"), wcPathOut, ze.name);
				UnzipItem(hz, index, wcFilePath, 0, ZIP_FILENAME);
				//check to know object need to be extracted is file
				if (!(ze.attr & FILE_ATTRIBUTE_DIRECTORY) && len == lstrlen(ze.name))
					break;
			}
		}
	}
	CloseZip(hz);
	return TRUE;

	return TRUE;
}
Example #27
0
	void FileUtils::Unzip(std::string& source, std::string& destination, 
		UnzipCallback callback, void *data)
	{
		std::wstring wideSource = UTILS_NS::UTF8ToWide(source);
		std::wstring wideDestination = UTILS_NS::UTF8ToWide(destination);

		HZIP handle = OpenZip(wideSource.c_str(), 0);
		SetUnzipBaseDir(handle, wideDestination.c_str());

		ZIPENTRY zipEntry; ZeroMemory(&zipEntry, sizeof(ZIPENTRY));

		GetZipItem(handle, -1, &zipEntry);
		int numItems = zipEntry.index;
		if (callback != NULL)
		{ 
			std::ostringstream message;
			message << "Starting extraction of " << numItems 
				<< " items from " << source << "to " << destination;
			std::string messageString = message.str();
			callback((char*) messageString.c_str(), 0, numItems, data);
		}
		
		for (int zi = 0; zi < numItems; zi++) 
		{ 
			ZeroMemory(&zipEntry, sizeof(ZIPENTRY));
			GetZipItem(handle, zi, &zipEntry);
			
			if (callback != NULL)
			{
				std::string name = WideToUTF8(zipEntry.name);
				std::string message = "Extracting ";
				message.append(name);
				message.append("...");
				callback((char*) message.c_str(), zi, numItems, data);
			}
			
			UnzipItem(handle, zi, zipEntry.name);
		}
		CloseZip(handle);
	}
Example #28
0
int rho_unzip_file(const char* szZipPath)
{
#ifdef  UNICODE
    rho::StringW strZipPathW;
    rho::common::convertToStringW(szZipPath, strZipPathW);
    HZIP hz = OpenZipFile(strZipPathW.c_str(), "");
    if ( !hz )
        return 0;

	// Set base for unziping
    SetUnzipBaseDir(hz, rho::common::convertToStringW(RHODESAPPBASE().getDBDirPath()).c_str() );
#else
    HZIP hz = OpenZipFile(szZipPath, "");
    if ( !hz )
        return 0;

	// Set base for unziping
    SetUnzipBaseDir(hz, RHODESAPPBASE().getDBDirPath().c_str() );
#endif

    ZIPENTRY ze;
    ZRESULT res = 0;
	// Get info about the zip
	// -1 gives overall information about the zipfile
	res = GetZipItem(hz,-1,&ze);
	int numitems = ze.index;

	// Iterate through items and unzip them
	for (int zi = 0; zi<numitems; zi++)
	{ 
		// fetch individual details, e.g. the item's name.
		res = GetZipItem(hz,zi,&ze); 
        if ( res == ZR_OK )
    		res = UnzipItem(hz, zi, ze.name);         
	}

	CloseZip(hz);

    return res == ZR_OK ? 1 : 0;
}
Example #29
0
duWindowManager::~duWindowManager()
{
	if (m_pDocXml)
	{
		delete m_pDocXml;
		m_pDocXml = NULL;
	}
	
	if (m_hZip)
	{
		CloseZip(m_hZip);
		m_hZip = NULL;
	}
	
	if (m_pTrialImage)
	{
		m_pTrialImage->FinalRelease();
		m_pTrialImage = NULL;
	}

	SAFE_DELETE(m_pResManager);
	m_mapCtrlManager.clear();
}
Example #30
0
void ZipArchive::UnzipThreadFunc(const std::string& zip, const std::string& target, UnzipDoneCallback callback, void* cbUserdata)
{
	LogInfo() << "Unzipping file: " << zip;

	HZIP hz = OpenZip((void *)zip.c_str(), 0, ZIP_FILENAME);

	if(!hz)
	{
		LogWarn() << "Failed to open Zip-File: " << zip;
		return;
	}

	// Get last entry
	ZIPENTRY ze;
	ZRESULT zr = GetZipItem(hz, -1, &ze); 

	if (zr == ZR_OK)
	{
		int numItems = ze.index;

		LogInfo() << " - Found " << numItems << " items in ZipFile";

		for(int i=0;i<numItems;i++)
		{
			GetZipItem(hz, i, &ze); 
			std::string t = target + "\\" + ze.name;
			LogInfo() << " - Unzipping file to: " << t;;

			UnzipItem(hz, i, (void *)t.c_str(), 0, ZIP_FILENAME);

			callback(zip, cbUserdata, i, numItems);
		}
	}
	
	CloseZip(hz);
}