示例#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
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;   
    }

}
示例#3
0
void FindInZip(CZipArchive& zip, FILELIST& l, CZipWordArray& n)
{

	for (FILELISTIT it = l.begin(); it != l.end(); ++it)
		zip.FindMatches(*it, n);
}
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;
}