Update compressed_archive to support the latest version of 7zip 18.05

p7zip has been abandoned and the latest version available is 16.02.
This commit is contained in:
Luis Ángel San Martín
2018-09-18 18:48:57 +02:00
parent 9321d864db
commit 1903b6753f
9 changed files with 303 additions and 307 deletions

View File

@ -28,11 +28,11 @@ static HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propI
NCOM::CPropVariant prop;
RINOK(archive->GetProperty(index, propID, &prop));
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt == VT_EMPTY)
result = false;
result = false;
else
return E_FAIL;
return E_FAIL;
return S_OK;
}
static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)
@ -40,7 +40,7 @@ static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &resu
return IsArchiveItemProp(archive, index, kpidIsDir, result);
}
class CArchiveExtractCallback:
class YCArchiveExtractCallback:
public IArchiveExtractCallback,
public ICryptoGetTextPassword,
public CMyUnknownImp
@ -71,11 +71,11 @@ private:
UInt32 _index;
struct CProcessedFileInfo
{
FILETIME MTime;
UInt32 Attrib;
bool isDir;
bool AttribDefined;
bool MTimeDefined;
FILETIME MTime;
UInt32 Attrib;
bool isDir;
bool AttribDefined;
bool MTimeDefined;
} _processedFileInfo;
COutFileStream *_outFileStreamSpec;
@ -92,29 +92,29 @@ public:
UInt64 newFileSize;
QMap<qint32, qint32> indexesToPages;
CArchiveExtractCallback(const QMap<qint32, qint32> & indexesToPages ,bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d),indexesToPages(indexesToPages) {}
~CArchiveExtractCallback() {MidFree(data);}
YCArchiveExtractCallback(const QMap<qint32, qint32> & indexesToPages ,bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d),indexesToPages(indexesToPages) {}
~YCArchiveExtractCallback() {MidFree(data);}
};
void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)
void YCArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)
{
NumErrors = 0;
_archiveHandler = archiveHandler;
directoryPath;//unused
directoryPath;//unused
}
STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)
STDMETHODIMP YCArchiveExtractCallback::SetTotal(UInt64 /* size */)
{
return S_OK;
}
STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)
STDMETHODIMP YCArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)
{
return S_OK;
}
STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
ISequentialOutStream **outStream, Int32 askExtractMode)
STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
ISequentialOutStream **outStream, Int32 askExtractMode)
{
*outStream = 0;
_outFileStream.Release();
@ -125,83 +125,83 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
_index = indexesToPages.value(index);
{
// Get Name
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));
UString fullPath;
if (prop.vt == VT_EMPTY)
fullPath = kEmptyFileAlias;
else
{
if (prop.vt != VT_BSTR)
return E_FAIL;
fullPath = prop.bstrVal;
}
_filePath = fullPath;
// Get Name
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));
UString fullPath;
if (prop.vt == VT_EMPTY)
fullPath = kEmptyFileAlias;
else
{
if (prop.vt != VT_BSTR)
return E_FAIL;
fullPath = prop.bstrVal;
}
_filePath = fullPath;
}
askExtractMode;//unused
askExtractMode;//unused
//if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)
//return S_OK;
//return S_OK;
{
// Get Attrib
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));
if (prop.vt == VT_EMPTY)
{
_processedFileInfo.Attrib = 0;
_processedFileInfo.AttribDefined = false;
}
else
{
if (prop.vt != VT_UI4)
return E_FAIL;
_processedFileInfo.Attrib = prop.ulVal;
_processedFileInfo.AttribDefined = true;
}
// Get Attrib
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));
if (prop.vt == VT_EMPTY)
{
_processedFileInfo.Attrib = 0;
_processedFileInfo.AttribDefined = false;
}
else
{
if (prop.vt != VT_UI4)
return E_FAIL;
_processedFileInfo.Attrib = prop.ulVal;
_processedFileInfo.AttribDefined = true;
}
}
RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));
{
// Get Modified Time
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
_processedFileInfo.MTimeDefined = false;
switch(prop.vt)
{
case VT_EMPTY:
// _processedFileInfo.MTime = _utcMTimeDefault;
break;
case VT_FILETIME:
_processedFileInfo.MTime = prop.filetime;
_processedFileInfo.MTimeDefined = true;
break;
default:
return E_FAIL;
}
// Get Modified Time
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
_processedFileInfo.MTimeDefined = false;
switch(prop.vt)
{
case VT_EMPTY:
// _processedFileInfo.MTime = _utcMTimeDefault;
break;
case VT_FILETIME:
_processedFileInfo.MTime = prop.filetime;
_processedFileInfo.MTimeDefined = true;
break;
default:
return E_FAIL;
}
}
//se necesita conocer el tama<EFBFBD>o del archivo para poder reservar suficiente memoria
//se necesita conocer el tama?o del archivo para poder reservar suficiente memoria
bool newFileSizeDefined;
{
// Get Size
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));
newFileSizeDefined = (prop.vt != VT_EMPTY);
if (newFileSizeDefined)
newFileSize = ConvertPropVariantToUInt64(prop);
// Get Size
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));
newFileSizeDefined = (prop.vt != VT_EMPTY);
if (newFileSizeDefined)
ConvertPropVariantToUInt64(prop, newFileSize);
}
//No hay que crear ning<EFBFBD>n fichero, ni directorios intermedios
//No hay que crear ning?n fichero, ni directorios intermedios
/*{
// Create folders for file
int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
if (slashPos >= 0)
NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));
// Create folders for file
int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
if (slashPos >= 0)
NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));
}
UString fullProcessedPath = _directoryPath + _filePath;
@ -209,123 +209,123 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
*/
if (_processedFileInfo.isDir)
{
//NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
//NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
}
else
{
/*NFile::NFind::CFileInfoW fi;
if (fi.Find(fullProcessedPath))
{
if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
{
qDebug() <<(UString(kCantDeleteOutputFile) + fullProcessedPath);
return E_ABORT;
}
}*/
if(newFileSizeDefined)
{
CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream;
CMyComPtr<CBufPtrSeqOutStream> outStreamLocal(outStreamSpec);
data = (Byte *)MidAlloc(newFileSize);
outStreamSpec->Init(data, newFileSize);
*outStream = outStreamLocal.Detach();
}
else
{
/*NFile::NFind::CFileInfoW fi;
if (fi.Find(fullProcessedPath))
{
if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
{
qDebug() <<(UString(kCantDeleteOutputFile) + fullProcessedPath);
return E_ABORT;
}
}*/
if(newFileSizeDefined)
{
CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream;
CMyComPtr<CBufPtrSeqOutStream> outStreamLocal(outStreamSpec);
data = (Byte *)MidAlloc(newFileSize);
outStreamSpec->Init(data, newFileSize);
*outStream = outStreamLocal.Detach();
}
else
{
}
}
}
return S_OK;
}
STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
STDMETHODIMP YCArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
{
_extractMode = false;
switch (askExtractMode)
{
case NArchive::NExtract::NAskMode::kExtract: _extractMode = true; break;
case NArchive::NExtract::NAskMode::kExtract: _extractMode = true; break;
};
/* switch (askExtractMode)
{
case NArchive::NExtract::NAskMode::kExtract: qDebug() << (kExtractingString); break;
case NArchive::NExtract::NAskMode::kTest: qDebug() <<(kTestingString); break;
case NArchive::NExtract::NAskMode::kSkip: qDebug() <<(kSkippingString); break;
case NArchive::NExtract::NAskMode::kExtract: qDebug() << (kExtractingString); break;
case NArchive::NExtract::NAskMode::kTest: qDebug() <<(kTestingString); break;
case NArchive::NExtract::NAskMode::kSkip: qDebug() <<(kSkippingString); break;
};*/
//qDebug() << _filePath;
return S_OK;
}
STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)
STDMETHODIMP YCArchiveExtractCallback::SetOperationResult(Int32 operationResult)
{
switch(operationResult)
{
case NArchive::NExtract::NOperationResult::kOK:
if(all && !_processedFileInfo.isDir)
{
QByteArray rawData((char *)data,newFileSize);
MidFree(data);
data = 0;
if(delegate != 0)
delegate->fileExtracted(_index,rawData);
else
{
allFiles.append(rawData);
}
}
break;
default:
{
NumErrors++;
qDebug() << " ";
switch(operationResult)
{
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnsupportedMethod;
break;
case NArchive::NExtract::NOperationResult::kCRCError:
if(delegate != 0)
delegate->crcError(_index);
qDebug() << kCRCFailed;
break;
case NArchive::NExtract::NOperationResult::kDataError:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kDataError;
break;
default:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnknownError;
}
}
case NArchive::NExtract::NOperationResult::kOK:
if(all && !_processedFileInfo.isDir)
{
QByteArray rawData((char *)data,newFileSize);
MidFree(data);
data = 0;
if(delegate != 0)
delegate->fileExtracted(_index,rawData);
else
{
allFiles.append(rawData);
}
}
break;
default:
{
NumErrors++;
qDebug() << " ";
switch(operationResult)
{
case NArchive::NExtract::NOperationResult::kUnsupportedMethod:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnsupportedMethod;
break;
case NArchive::NExtract::NOperationResult::kCRCError:
if(delegate != 0)
delegate->crcError(_index);
qDebug() << kCRCFailed;
break;
case NArchive::NExtract::NOperationResult::kDataError:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kDataError;
break;
default:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnknownError;
}
}
}
/*
if (_outFileStream != NULL)
{
if (_processedFileInfo.MTimeDefined)
_outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);
RINOK(_outFileStreamSpec->Close());
if (_processedFileInfo.MTimeDefined)
_outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);
RINOK(_outFileStreamSpec->Close());
}
_outFileStream.Release();
if (_extractMode && _processedFileInfo.AttribDefined)
NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);*/
NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);*/
//qDebug() << endl;
return S_OK;
}
STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
STDMETHODIMP YCArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
{
if (!PasswordIsDefined)
{
// You can ask real password here from user
// Password = GetPassword(OutStream);
// PasswordIsDefined = true;
qDebug() << "Password is not defined" << endl;
return E_ABORT;
// You can ask real password here from user
// Password = GetPassword(OutStream);
// PasswordIsDefined = true;
qDebug() << "Password is not defined" << endl;
return E_ABORT;
}
return StringToBstr(Password, password);
}