int OnExtract (ExtractStruct *pES) { ArchiveBase *pArchive = (ArchiveBase*)pES->hArchive; pES->bResult = false; char Destination[NM],DestinationDir[NM]; for(int i=0;i<pES->nItemsNumber;i++) { //{FILE *log; log=fopen("c:\\plugins.log","at"); fprintf(log, "%s\n",pae->Item[i]->FindData.cFileName); fclose(log);} strcpy(Destination,pES->lpDestPath); FSF.AddEndSlash(Destination); //if(Command==PA_EXTRACTWITHOUTPATH) // strcat(Destination,GetFilePtr(pae->Item[i]->FindData.cFileName)); //else strcat(Destination,(pES->pItems)[i].FindData.cFileName + (*pES->lpCurrentPath ? strlen (pES->lpCurrentPath) : 0)); strcpy(DestinationDir,Destination); *GetFilePtr(DestinationDir)=0; FSF.AddEndSlash(DestinationDir); if(CreateDirEx(DestinationDir)) //FIXME: show error { pES->bResult = pArchive->Extract(&(pES->pItems)[i],Destination); } } return NAERROR_SUCCESS; }
void CreateDirs (const char *lpFileName) { char lpNameCopy[MAX_PATH] = {0}; strcpy(lpNameCopy, lpFileName); char *pend = lpNameCopy + strlen(lpNameCopy); while( pend>lpNameCopy ) { if(*pend=='/' || *pend=='\\') { *pend = 0; break; } --pend; } CreateDirEx (lpNameCopy); }
bool WcxArchive::pExtract( const char *lpDestPath ) { int nProcessed = 0; int nResult = 0; m_files.clear(); while ( nResult == 0 ) { tHeaderData HeaderData; memset (&HeaderData, 0, sizeof (HeaderData)); nResult = m_pModule->m_pfnReadHeader (m_hArchive, &HeaderData); if( nResult!=0 ) continue; char szDestPath[MAX_PATH] = {0}; strcpy(szDestPath, lpDestPath); PathAppendA(szDestPath, HeaderData.FileName); int nProcessResult = 0; if ( (HeaderData.FileAttr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY ) { CreateDirEx (szDestPath); nProcessResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_SKIP, NULL, NULL); ATLASSERT(FALSE); } else { CreateDirs( szDestPath ); SetFileApisToANSI(); nProcessResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_EXTRACT, NULL, szDestPath); SetFileApisToOEM(); if(!nProcessResult) m_files.push_back( szDestPath ); } if ( !nProcessResult ) nProcessed++; } return nProcessed!=0; }
HRESULT __stdcall CArchiveExtractCallback::GetStream ( unsigned int index, ISequentialOutStream **outStream, int askExtractMode ) { CPropVariant value; IInArchive *archive = m_pArchive->m_pArchive; if ( askExtractMode == 0 ) //extract { if ( archive->GetProperty (index, kpidPath, &value) != S_OK ) return S_OK; //!!! to return error char szArcFileName[MAX_PATH]; char szFullName[MAX_PATH]; if ( value.vt == VT_BSTR ) WideCharToMultiByte (CP_OEMCP, 0, value.bstrVal, -1, szArcFileName, MAX_PATH, NULL, NULL); else { //strcpy (szArcFileName, FSF.PointToName (m_pArchive->m_lpFileName)); //CutTo (szArcFileName, '.', true); ATLASSERT(FALSE); } strcpy (szFullName, m_lpDestPath.c_str()); PathAppendA(szFullName, szArcFileName); if ( (int)m_nLastProcessed == -1 ) m_nLastProcessed = 0; FILETIME ftCreationTime, ftLastAccessTime, ftLastWriteTime; DWORD dwFileAttributes = 0; memset (&ftCreationTime, 0, sizeof (FILETIME)); memset (&ftLastAccessTime, 0, sizeof (FILETIME)); memset (&ftLastWriteTime, 0, sizeof (FILETIME)); if ( archive->GetProperty (index, kpidAttrib, &value) == S_OK ) { if ( value.vt == VT_UI4 ) dwFileAttributes = value.ulVal; } if ( archive->GetProperty (index, kpidCTime, &value) == S_OK ) { if ( value.vt == VT_FILETIME ) memcpy (&ftCreationTime, &value.filetime, sizeof (FILETIME)); } if ( archive->GetProperty (index, kpidATime, &value) == S_OK ) { if ( value.vt == VT_FILETIME ) memcpy (&ftLastAccessTime, &value.filetime, sizeof (FILETIME)); } if ( archive->GetProperty (index, kpidMTime, &value) == S_OK ) { if ( value.vt == VT_FILETIME ) memcpy (&ftLastWriteTime, &value.filetime, sizeof (FILETIME)); } bool bIsFolder = false; if ( archive->GetProperty (index, kpidIsDir, &value) == S_OK ) { if (value.vt == VT_BOOL) bIsFolder = (value.boolVal == VARIANT_TRUE); } if ( bIsFolder || dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY ) { *outStream = NULL; CreateDirEx (szFullName, dwFileAttributes); } else { CreateDirs (szFullName); COutFile *file = new COutFile (szFullName); if ( file->Open () ) { file->SetAttributes (dwFileAttributes); file->SetTime (&ftCreationTime, &ftLastAccessTime, &ftLastWriteTime); *outStream = file; m_files.push_back( szFullName ); } else delete file; } } else *outStream = NULL; return S_OK; }