コード例 #1
0
void DocXDocumentStore::GetDocumentTexts(const CStdString& sFileName, std::vector<std::string>& vDocumentTexts) const
{
	vDocumentTexts.clear();

	CZipArchive zipArchive;
	zipArchive.Open(sFileName, CZipArchive::zipOpenReadOnly);
	if( !zipArchive.IsClosed() )
	{
		CZipWordArray ar;
		zipArchive.FindMatches( L"word\\\\*.xml", ar );
		for( int uIndex = 0; uIndex < ar.GetSize(); uIndex++ )
		{
			CZipFileHeader fhInfo;
			if( zipArchive.GetFileInfo( fhInfo, ar[uIndex] ) )
			{
				const CZipString fileName( fhInfo.GetFileName() );
				if( fileName.find_first_of( '\\' ) == fileName.find_last_of( '\\' ) )
				{
					C2007DocFile mf;
					zipArchive.ExtractFile( ar[uIndex], mf );			
					const CStdStringA sDocText = mf.GetWTInnerText();
					if( sDocText.size() > 0 )
						vDocumentTexts.push_back( sDocText );
				}
			}
		}
		zipArchive.Flush();
		zipArchive.Close();
	}
}
コード例 #2
0
BOOL CPackage::unZip()
{
	CZipArchive cZip;
	CString		csFile;

	// If there is no fragement, assume package unzipped
	if (m_uFrags == 0)
		// No fragment
		return TRUE;
	csFile.Format( _T( "%s\\%s\\%s"), getDownloadFolder(), m_csID, OCS_DOWNLOAD_BUILD);
	try
	{
		cZip.Open( csFile);
		for(ZIP_INDEX_TYPE i=0; i<cZip.GetCount();i++)
			cZip.ExtractFile(i, m_csPath);
		cZip.Close();
		// Create package ID file into unzip directory only if not in store action 
		if (m_csAction != OCS_DOWNLOAD_ACTION_STORE)
		{
			CStdioFile cFile;

			csFile.Format( _T( "%s\\%s"), m_csPath, OCS_DOWNLOAD_PACKAGE_ID);
			if (cFile.Open( csFile, CFile::modeCreate|CFile::modeWrite|CFile::typeText))
			{
				cFile.WriteString( m_csID);
				cFile.Close();
			}
		}
	}
	catch (CException *pE)
	{		
		pE->Delete();
		cZip.Close( CZipArchive::afAfterException);
		return FALSE;			
	}
	catch (std::exception *pEx)
	{
		cZip.Close( CZipArchive::afAfterException);
		delete pEx;
		return FALSE;			
	}
	return TRUE;
}
コード例 #3
0
ファイル: zipFileDll.cpp プロジェクト: hefen1/XCaimi
int WINAPI UnZipFile(const char *pszZipFile,const char *pszPath)
{
	if( pszZipFile == NULL || pszPath == NULL )
		return 0;

	CString strZip,strPath;
	strZip.Format("%s",pszZipFile);
	strPath.Format("%s",pszPath);

	CZipArchive zip;
	zip.Open(strZip, CZipArchive::open);
	for (int i = 0; i < zip.GetNoEntries(); i++)//输出文件(!!!没有文件夹)
	{
		if( !zip.ExtractFile(WORD(i) , strPath) )
		{ 
			break;
		}
	}
	zip.Close();

	return 1;
}
コード例 #4
0
ファイル: SimpleZip.cpp プロジェクト: chuanyou01/Chart
bool CSimpleZip::Extract(std::string strDest,std::string strZipFile)
{
	CZipString szArchive;
	szArchive=CZipString(strZipFile);
	CZipString szPath = CZipString(strDest);

	CZipArchive zip;
	
	int iVolumeSize = 0;
	int iMode = CZipArchive::zipOpen;


	try
	{
		zip.Open(szArchive, iMode, iVolumeSize);
	}
	catch(...)
	{
		return FALSE;
	}

	bool ok=true;
	for (int k = 0; k < zip.GetCount(); ++k)
	{
		
		try
		{
			ok = zip.ExtractFile(k, szPath, TRUE);
		}
		catch (...)
		{					
			ok = false;
			break;
		}
	}
	zip.Close();
	return ok;
}
コード例 #5
0
ファイル: SimpleZip.cpp プロジェクト: chuanyou01/Chart
bool CSimpleZip::Extract( const void* src, const unsigned int& srcSize, void* dst, unsigned int& dstSize, std::string& szErrmsg)
{
	if ( NULL==src )
	{
		szErrmsg = "CSimpleZip: Invalid source.";
		return false;
	}

	bool bRet = false;
	CZipMemFile mfIn;
	CZipMemFile mfOut;
	CZipArchive zip;
	CZipFileHeader fhInfo;
	try
	{
		mfIn.Write(src, srcSize);
		zip.Open(mfIn, CZipArchive::zipOpen);
		if ( !zip.GetFileInfo(fhInfo, 0) )
		{
			szErrmsg = "CSimpleZip: Failed to GetFileInfo";
			zip.Close();
			return false;
		}

		if ( NULL==dst || dstSize<fhInfo.m_uUncomprSize )
		{
			dstSize = fhInfo.m_uUncomprSize;
			szErrmsg = "CSimpleZip: The size of destination buffer is too small.";
			return false;
		}

		mfOut.SetLength( fhInfo.m_uUncomprSize );
		((CZipAbstractFile*)&mfOut)->SeekToBegin(); // may be needed when mfOut was used previously
		if ( !zip.ExtractFile(0, mfOut) )
		{
			szErrmsg =  "CSimpleZip: Failed to ExtractFile";
			zip.Close();
			return false;
		}
		zip.Close();
		BYTE* b = mfOut.Detach();
		//int nLen = (int)mfOut.GetLength();			// this is an error length value 
		memcpy_s(dst, dstSize, b, fhInfo.m_uUncomprSize);
		dstSize = fhInfo.m_uUncomprSize;
		free(b);
		bRet = true;
	}
	catch(CZipException& e)
	{
		if (!zip.IsClosed())
			zip.Close();
		szErrmsg =  e.GetErrorDescription().c_str();
	}
	catch(...)
	{
		if (!zip.IsClosed())
			zip.Close();
		szErrmsg =  "CSimpleZip: Failed to Extract, catch exception.";
	}
	return bRet;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: exaphaser/winstaller
void extractRestoreFiles( string filepath, bool known )
{
    cout << "Extracting restore files" << endl;
    CZipArchive zip;
    ZIP_INDEX_TYPE index;
    
    try
    {
        zip.Open(_T(filepath.c_str()));
    
        cout << "Extracting ramdisk" << endl;
        if( known )
        {
            index = zip.FindFile(_T("694-5259-38.dmg"));
            zip.ExtractFile(index, _T(cwd.c_str()));
            ramdisk = (cwd + "/694-5259-38.dmg");
        }
        else
        {
            CZipIndexesArray indexes;
            zip.FindMatches(_T("*.dmg"), indexes, false);	 
            for (ZIP_ARRAY_SIZE_TYPE i = 0; i < indexes.GetCount(); i++)
            {
                ZIP_INDEX_TYPE ind = indexes[i];        
                if(zip[ind]->m_uUncomprSize > (10*1024*1024) && zip[ind]->m_uUncomprSize < (20*1024*1024) )
                {
                    zip.ExtractFile(ind, _T(cwd.c_str()));   
                    FILE *f = fopen((cwd + "/" + zip[ind]->GetFileName()).c_str(), "rb");
            		if(!f)
            		{
                        continue; 
                    }
                    else
                    {
                        unsigned char magic[4];
                        fread(magic, 1, 4, f);
                        if( magic[0] == 0x38 &&
                            magic[1] == 0x39 &&
                            magic[2] == 0x30 &&
                            magic[3] == 0x30 )
                        {
                            ramdisk = cwd + "/" + zip[ind]->GetFileName();
                            fclose(f);
                            break;
                        }  
                        fclose(f);  
                    }            
                }
            }
        }			
        
        cout << "Extracting kernelcache" << endl; 
        if(known)
        {  
            index = zip.FindFile(_T("kernelcache.restore.release.s5l8900xrb"));
            zip.ExtractFile(index, _T(cwd.c_str()));
            kernelcache = (cwd + "/kernelcache.restore.release.s5l8900xrb");
        }
        else
        {
            CZipIndexesArray indexes;
            zip.FindMatches (_T("*kernelcache*"), indexes, false);	
            if(indexes.GetCount() > 0)
            { 
                zip.ExtractFile(indexes[0], _T(cwd.c_str())); 
                kernelcache = cwd + "/" + zip[indexes[0]]->GetFileName();
            }
        }
        zip.Close();
    }
    catch(...)
    {
        cout << "Error extracting restore file" << endl;   
    }

}
コード例 #7
0
ファイル: WorkerThread.cpp プロジェクト: MrFlibb/WHDRun
void WorkerThread::runUnzip() {
	emit(beginRunUnzip());
	emit(stageEvent("Extracting and merging game data"));
	
	emit(infoEvent("Unzipping original game files"));
	CZipArchive zip;
	try {
	    zip.Open(m_gameFileName.toStdString().c_str(), CZipArchive::zipOpenReadOnly);
		
		ZIP_SIZE_TYPE totalSize = 0;
		for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
			totalSize += zip.GetFileInfo(i)->m_uUncomprSize; // uncompressed size
			QString name = QString::fromUtf8(zip.GetFileInfo(i)->GetFileName());
			if(!validName(name)) {
				emit(errorEvent("Game pack contains illegal file names (e.g. " + name + ")"));
				emit(infoEvent("A near future release of WHDRun will fix this problem, sorry for the inconvenience"));
				m_die = true;
				return;
			}
		}
		emit(unzipTotalSize(totalSize));

		ZIP_SIZE_TYPE progress = 0;
		for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
			progress += zip.GetFileInfo(i)->m_uUncomprSize;
			zip.ExtractFile(i, m_tempPath.toUtf8());
			emit(unzipProgress(progress));
		}

	    zip.Close();
    } catch(CZipException ex) {
		zip.Close(CZipArchive::afAfterException);
		emit(errorEvent(QString("Error while unzipping: %1").arg((LPCTSTR)ex.GetErrorDescription())));
		m_die = true; // no need to rezip
		return;
	}

	emit(infoEvent("Collecting checksums of unmodified files"));
	emit(beginCollect());
	m_checksums.clear();
	collectFiles(m_tempPath, &m_checksums); // TODO: progress for this? (should always be quick)
	
	QString gameFileBase = QFileInfo(m_gameFileName).baseName();
	QString diffFileName = m_dataPath + "/" + gameFileBase + __WHDRun__DiffSuffix;
	if(QFileInfo(diffFileName).exists()) {
		emit(infoEvent("Merging original game files with previously modified files"));
		CZipArchive zip;
		try {
		    zip.Open(diffFileName.toUtf8(), CZipArchive::zipOpenReadOnly);

			//TODO: progress infoEvent for this? (should always be quick)
			for (ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
				zip.ExtractFile(i, m_tempPath.toUtf8());
			}

		    zip.Close();
	    } catch(CZipException ex) {
			zip.Close(CZipArchive::afAfterException);
			emit(errorEvent(QString("Error while unzipping changes: %1").arg((LPCTSTR)ex.GetErrorDescription())));
			m_die = true; // no need to rezip
			return;
		}
	}
	
	emit(endRunUnzip());
}
コード例 #8
0
DWORD ProgressDialog::UpgradeAsync() {
  typedef std::list<CString> BackupFiles;

  CZipArchive ar;
  if (!ar.Open(upgradeFilePath_)) {
    ::PostMessage(m_hWnd, WM_UPGRADE_DONE, FALSE, 0);
    return 0;
  }

  bool copySuccess = true;
  TCHAR filePath[MAX_PATH];
  BackupFiles backupFiles;
  WORD fileCount = ar.GetCount();
  for (WORD i = 0; i < fileCount; i++) {
    CZipFileHeader *fileInfo = ar.GetFileInfo(i);
    if (fileInfo->IsDirectory()) {
      continue;
    }
    const CZipString &fileName = fileInfo->GetFileName();
    _tcscpy(filePath, appDir_);
    PathAddBackslash(filePath);
    _tcscat(filePath, fileName);
    if (PathFileExists(filePath)) {
      TCHAR backupFilePath[MAX_PATH];
      _tcscpy(backupFilePath, appDir_);
      PathAddBackslash(backupFilePath);
      _tcscat(backupFilePath, fileName);
      _tcscat(backupFilePath, _T(".bak"));
      if (PathFileExists(backupFilePath)) {
        DeleteFile(backupFilePath);
      }
      if (!MoveFile(filePath, backupFilePath)) {
        copySuccess = false;
        break;
      }
      backupFiles.push_back((LPCTSTR)fileName);
    }
    if (!ar.ExtractFile(i, appDir_)) {
      copySuccess = false;
      break;
    }
  }
  
  if (copySuccess) {
    AfxGetApp()->WriteProfileString(_T(""), _T("Version"), appVersion_);

    // remove backup files.
    for (BackupFiles::const_iterator i = backupFiles.begin(); i != backupFiles.end(); ++i) {
      TCHAR backupFilePath[MAX_PATH];
      _tcscpy(backupFilePath, appDir_);
      PathAddBackslash(backupFilePath);
      _tcscat(backupFilePath, *i);
      _tcscat(backupFilePath, _T(".bak"));

      DeleteFile(backupFilePath);
    }
  } else {
    // upgrade failed, restore backup.
    for (BackupFiles::const_iterator i = backupFiles.begin(); i != backupFiles.end(); ++i) {
      TCHAR backupFilePath[MAX_PATH];
      _tcscpy(backupFilePath, appDir_);
      PathAddBackslash(backupFilePath);
      _tcscat(backupFilePath, *i);
      _tcscat(backupFilePath, _T(".bak"));

      TCHAR filePath[MAX_PATH];
      _tcscpy(filePath, appDir_);
      PathAddBackslash(filePath);
      _tcscat(filePath, *i);

      DeleteFile(filePath);
      MoveFile(backupFilePath, filePath);
    }
  }

  ::PostMessage(m_hWnd, WM_UPGRADE_DONE, TRUE, 0);

  return 0;
}
コード例 #9
0
bool CWebCDCovers::DownloadImage(CString strLetter, CString strName, CString strFilename, RESOURCEHOST* pHost, HWND hwndProgress, HWND hwndStatus, CString& strLocalFilename)
{
	// get the html page for the image source
	*m_pbCancelDownload = false;

	WCC_GETIMAGEREQUEST* pfn_wccRequest = (WCC_GETIMAGEREQUEST*) GetProcAddress (pHost->hInst, "GetImageRequest");
	WCC_GETIMAGEURL* pfn_wccImgURL = (WCC_GETIMAGEURL*) GetProcAddress (pHost->hInst, "GetImageURL");

	char szUrl[300], szHeaders[300], szData[300];
	int nMethod;
	pfn_wccRequest (strFilename.GetBuffer (0), strLetter.GetBuffer (0), "", szUrl, &nMethod, szHeaders, szData);

	CString strHTML = (*szUrl == 0) ? strFilename.GetBuffer (0) :
		CHttpRequest::DownloadBuffer (szUrl, nMethod, szHeaders, szData,
			m_pbCancelDownload, m_dwDownloadId, m_nError);

	// MCH 29/08/04
	// Send version info to the DLL
	strcpy (szData, ((CCdCoverCreator2App*) AfxGetApp ())->GetVersion ().GetBuffer (-1));

	// get the URL of the image
	CString strURL;
	if (!pfn_wccImgURL (strHTML.GetBuffer (0), strURL.GetBuffer (500), &nMethod, szHeaders, szData))
		return false;
	strURL.ReleaseBuffer ();

	// generate a local temporary file name
	strLocalFilename = ((CCdCoverCreator2App*) AfxGetApp ())->GetImageCacheDir () + strURL.Mid (strURL.ReverseFind ('/') + 1);
	if (strLocalFilename.Find (".php?") >= 0)
	{
		// MCH 15/09/04
		// www.darktown.to sends again JPGs, but via a PHP script. Filename provided as HTTP header which is not available here
		strLocalFilename = ((CCdCoverCreator2App*) AfxGetApp ())->GetImageCacheDir ();
		strLocalFilename.AppendFormat ("dld%d.jpg", GetTickCount ());
	}

	// get the jpeg image
	*m_pbCancelDownload = false;
	CHttpRequest::DownloadFile (strURL, nMethod, szHeaders, szData, strLocalFilename,
		m_pbCancelDownload, m_dwDownloadId, m_nError, 0, hwndProgress, hwndStatus);

	if (m_nError)
		return false;

	// MCH 29/08/04
	// if the download is a zip file, extract the image
	if (strLocalFilename.Right (4).MakeLower () == ".zip")
	{
		CString strPath = strLocalFilename.Left (strLocalFilename.ReverseFind ('\\'));
		CString strZipFile = strLocalFilename;

		// set up and open a zip archive, get the image files inside the zip file
		CZipArchive zip;
		zip.Open (strZipFile);
		CZipWordArray ar;
		zip.FindMatches ("*.jp*g", ar);

		strLocalFilename.Empty ();

		// extract the image files
		for (int i = 0; i < ar.GetSize (); i++)
		{
			// set the local file name
			CZipFileHeader info;
			zip.GetFileInfo (info, i);
			if (!strLocalFilename.IsEmpty ())
				strLocalFilename += ";";
			strLocalFilename += strPath + "\\" + info.GetFileName ();
			
			// extract the file
			zip.ExtractFile (ar.GetAt (i), strPath, false);
		}

		zip.Close ();

		// delete the zip file
		::DeleteFile (strZipFile);
	}

	return true;
}