This commit is contained in:
Igor Pavlov
2023-12-22 17:17:05 +00:00
committed by Kornel
parent ec44a8a070
commit a36c48cece
954 changed files with 42199 additions and 25482 deletions

View File

@@ -31,10 +31,11 @@ static const unsigned kMatchMinLen = 3;
static const UInt32 kWindowSize = 1 << 15; // must be >= (1 << 14)
class CCoder:
public ICompressCoder,
public CMyUnknownImp
{
Z7_CLASS_IMP_NOQIB_1(
CCoder
, ICompressCoder
)
CLzOutWindow _outWindow;
NBitm::CDecoder<CInBuffer> _inBitStream;
@@ -50,16 +51,13 @@ class CCoder:
HRESULT CodeReal(UInt64 outSize, ICompressProgressInfo *progress);
public:
MY_UNKNOWN_IMP
bool FinishMode;
CCoder(): FinishMode(false) {}
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
CCoder(): FinishMode(false) {}
UInt64 GetInputProcessedSize() const { return _inBitStream.GetProcessedSize(); }
};
HRESULT CCoder::CodeReal(UInt64 rem, ICompressProgressInfo *progress)
{
const UInt32 kStep = 1 << 20;
@@ -76,7 +74,7 @@ HRESULT CCoder::CodeReal(UInt64 rem, ICompressProgressInfo *progress)
UInt64 packSize = _inBitStream.GetProcessedSize();
UInt64 pos = _outWindow.GetProcessedSize();
RINOK(progress->SetRatioInfo(&packSize, &pos));
RINOK(progress->SetRatioInfo(&packSize, &pos))
next = 0;
if (rem > kStep)
next = rem - kStep;
@@ -152,8 +150,8 @@ HRESULT CCoder::CodeReal(UInt64 rem, ICompressProgressInfo *progress)
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
Z7_COM7F_IMF(CCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress))
{
try
{
@@ -367,10 +365,10 @@ HRESULT CArcHeader::Parse(const Byte *p, unsigned size)
// LastChapter = p[29];
unsigned pos = headerSize;
unsigned size1 = size - pos;
RINOK(ReadString(p + pos, size1, Name));
RINOK(ReadString(p + pos, size1, Name))
pos += size1;
size1 = size - pos;
RINOK(ReadString(p + pos, size1, Comment));
RINOK(ReadString(p + pos, size1, Comment))
pos += size1;
return S_OK;
}
@@ -477,10 +475,10 @@ HRESULT CItem::Parse(const Byte *p, unsigned size)
unsigned pos = headerSize;
unsigned size1 = size - pos;
RINOK(ReadString(p + pos, size1, Name));
RINOK(ReadString(p + pos, size1, Name))
pos += size1;
size1 = size - pos;
RINOK(ReadString(p + pos, size1, Comment));
RINOK(ReadString(p + pos, size1, Comment))
pos += size1;
return S_OK;
@@ -570,7 +568,7 @@ HRESULT CArc::ReadBlock(bool &filled, CExtendedInfo *extendedInfo)
if (extendedInfo)
extendedInfo->Size += _blockSize;
READ_STREAM(_block, readSize);
READ_STREAM(_block, readSize)
if (Get32(_block + _blockSize) != CrcCalc(_block, _blockSize))
{
if (extendedInfo)
@@ -591,28 +589,28 @@ HRESULT CArc::SkipExtendedHeaders(CExtendedInfo &extendedInfo)
for (UInt32 i = 0;; i++)
{
bool filled;
RINOK(ReadBlock(filled, &extendedInfo));
RINOK(ReadBlock(filled, &extendedInfo))
if (!filled)
return S_OK;
if (Callback && (i & 0xFF) == 0)
RINOK(Callback->SetCompleted(&NumFiles, &Processed));
RINOK(Callback->SetCompleted(&NumFiles, &Processed))
}
}
HRESULT CArc::Open()
{
bool filled;
RINOK(ReadBlock(filled, NULL)); // (extendedInfo = NULL)
RINOK(ReadBlock(filled, NULL)) // (extendedInfo = NULL)
if (!filled)
return S_FALSE;
RINOK(Header.Parse(_block, _blockSize));
RINOK(Header.Parse(_block, _blockSize))
IsArc = true;
return SkipExtendedHeaders(ExtendedInfo);
}
HRESULT CArc::GetNextItem(CItem &item, bool &filled)
{
RINOK(ReadBlock(filled, NULL)); // (extendedInfo = NULL)
RINOK(ReadBlock(filled, NULL)) // (extendedInfo = NULL)
if (!filled)
return S_OK;
filled = false;
@@ -627,23 +625,18 @@ HRESULT CArc::GetNextItem(CItem &item, bool &filled)
extraData = GetUi32(_block + pos);
*/
RINOK(SkipExtendedHeaders(item.ExtendedInfo));
RINOK(SkipExtendedHeaders(item.ExtendedInfo))
filled = true;
return S_OK;
}
class CHandler:
public IInArchive,
public CMyUnknownImp
{
Z7_CLASS_IMP_CHandler_IInArchive_0
CObjectVector<CItem> _items;
CMyComPtr<IInStream> _stream;
UInt64 _phySize;
CArc _arc;
public:
MY_UNKNOWN_IMP1(IInArchive)
INTERFACE_IInArchive(;)
HRESULT Open2(IInStream *inStream, IArchiveOpenCallback *callback);
};
@@ -696,7 +689,7 @@ static void SetUnicodeString(const AString &s, NCOM::CPropVariant &prop)
prop = MultiByteToUnicodeString(s, CP_OEMCP);
}
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -717,7 +710,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
case k_ErrorType_UnexpectedEnd: v |= kpv_ErrorFlags_UnexpectedEnd; break;
case k_ErrorType_Corrupted: v |= kpv_ErrorFlags_HeadersError; break;
case k_ErrorType_OK:
default:
// default:
break;
}
prop = v;
@@ -730,13 +723,13 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
COM_TRY_END
}
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
{
*numItems = _items.Size();
return S_OK;
}
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -766,16 +759,15 @@ HRESULT CHandler::Open2(IInStream *inStream, IArchiveOpenCallback *callback)
{
Close();
UInt64 endPos = 0;
RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));
RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
UInt64 endPos;
RINOK(InStream_AtBegin_GetSize(inStream, endPos))
_arc.Stream = inStream;
_arc.Callback = callback;
_arc.NumFiles = 0;
_arc.Processed = 0;
RINOK(_arc.Open());
RINOK(_arc.Open())
_phySize = _arc.Processed;
if (_arc.Header.ArchiveSize != 0)
@@ -787,7 +779,7 @@ HRESULT CHandler::Open2(IInStream *inStream, IArchiveOpenCallback *callback)
bool filled;
_arc.Error = k_ErrorType_OK;
RINOK(_arc.GetNextItem(item, filled));
RINOK(_arc.GetNextItem(item, filled))
if (_arc.Error != k_ErrorType_OK)
break;
@@ -811,20 +803,20 @@ HRESULT CHandler::Open2(IInStream *inStream, IArchiveOpenCallback *callback)
break;
}
RINOK(inStream->Seek(pos, STREAM_SEEK_SET, NULL));
RINOK(InStream_SeekSet(inStream, pos))
_arc.NumFiles = _items.Size();
_arc.Processed = pos;
if (callback && (_items.Size() & 0xFF) == 0)
{
RINOK(callback->SetCompleted(&_arc.NumFiles, &_arc.Processed));
RINOK(callback->SetCompleted(&_arc.NumFiles, &_arc.Processed))
}
}
return S_OK;
}
STDMETHODIMP CHandler::Open(IInStream *inStream,
const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *callback)
Z7_COM7F_IMF(CHandler::Open(IInStream *inStream,
const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *callback))
{
COM_TRY_BEGIN
HRESULT res;
@@ -840,7 +832,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
COM_TRY_END
}
STDMETHODIMP CHandler::Close()
Z7_COM7F_IMF(CHandler::Close())
{
_arc.Close();
_phySize = 0;
@@ -849,12 +841,12 @@ STDMETHODIMP CHandler::Close()
return S_OK;
}
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback)
Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback))
{
COM_TRY_BEGIN
UInt64 totalUnpacked = 0, totalPacked = 0;
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
if (allFilesMode)
numItems = _items.Size();
if (numItems == 0)
@@ -892,24 +884,24 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
{
lps->InSize = totalPacked;
lps->OutSize = totalUnpacked;
RINOK(lps->SetCur());
RINOK(lps->SetCur())
curUnpacked = curPacked = 0;
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode = testMode ?
const Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
Int32 index = allFilesMode ? i : indices[i];
const UInt32 index = allFilesMode ? i : indices[i];
const CItem &item = _items[index];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
if (item.IsDir())
{
// if (!testMode)
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
RINOK(extractCallback->PrepareOperation(askMode))
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
}
continue;
}
@@ -917,7 +909,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (!testMode && !realOutStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->PrepareOperation(askMode))
curUnpacked = item.Size;
curPacked = item.PackSize;
@@ -930,8 +922,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
inStreamSpec->Init(item.PackSize);
UInt64 pos;
_stream->Seek(item.DataPosition, STREAM_SEEK_SET, &pos);
RINOK(InStream_SeekSet(_stream, item.DataPosition))
HRESULT result = S_OK;
Int32 opRes = NExtract::NOperationResult::kOK;
@@ -990,7 +981,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
opRes = NExtract::NOperationResult::kDataError;
else
{
RINOK(result);
RINOK(result)
opRes = (outStreamSpec->GetCRC() == item.FileCRC) ?
NExtract::NOperationResult::kOK:
NExtract::NOperationResult::kCRCError;
@@ -998,7 +989,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
}
outStream.Release();
RINOK(extractCallback->SetOperationResult(opRes));
RINOK(extractCallback->SetOperationResult(opRes))
}
}
@@ -1009,7 +1000,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
static const Byte k_Signature[] = { kSig0, kSig1 };
REGISTER_ARC_I(
"Arj", "arj", 0, 4,
"Arj", "arj", NULL, 4,
k_Signature,
0,
0,