mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-11 12:07:12 -06:00
23.01
This commit is contained in:
@@ -354,7 +354,7 @@ HRESULT CItem::ReadHeader(NDecoder::CCOMCoder *stream)
|
||||
// UInt32 crc = CRC_INIT_VAL;
|
||||
Byte buf[10];
|
||||
|
||||
RINOK(ReadBytes(stream, buf, 10));
|
||||
RINOK(ReadBytes(stream, buf, 10))
|
||||
|
||||
if (buf[0] != kSignature_0 ||
|
||||
buf[1] != kSignature_1 ||
|
||||
@@ -374,22 +374,22 @@ HRESULT CItem::ReadHeader(NDecoder::CCOMCoder *stream)
|
||||
if (ExtraFieldIsPresent())
|
||||
{
|
||||
UInt32 xlen;
|
||||
RINOK(ReadUInt16(stream, xlen /* , crc */));
|
||||
RINOK(SkipBytes(stream, xlen));
|
||||
RINOK(ReadUInt16(stream, xlen /* , crc */))
|
||||
RINOK(SkipBytes(stream, xlen))
|
||||
// Extra.SetCapacity(xlen);
|
||||
// RINOK(ReadStream_FALSE(stream, Extra, xlen));
|
||||
// crc = CrcUpdate(crc, Extra, xlen);
|
||||
}
|
||||
if (NameIsPresent())
|
||||
RINOK(ReadString(stream, Name, kNameMaxLen /* , crc */));
|
||||
RINOK(ReadString(stream, Name, kNameMaxLen /* , crc */))
|
||||
if (CommentIsPresent())
|
||||
RINOK(ReadString(stream, Comment, kCommentMaxLen /* , crc */));
|
||||
RINOK(ReadString(stream, Comment, kCommentMaxLen /* , crc */))
|
||||
|
||||
if (HeaderCrcIsPresent())
|
||||
{
|
||||
UInt32 headerCRC;
|
||||
// UInt32 dummy = 0;
|
||||
RINOK(ReadUInt16(stream, headerCRC /* , dummy */));
|
||||
RINOK(ReadUInt16(stream, headerCRC /* , dummy */))
|
||||
/*
|
||||
if ((UInt16)CRC_GET_DIGEST(crc) != headerCRC)
|
||||
return S_FALSE;
|
||||
@@ -401,7 +401,7 @@ HRESULT CItem::ReadHeader(NDecoder::CCOMCoder *stream)
|
||||
HRESULT CItem::ReadFooter1(NDecoder::CCOMCoder *stream)
|
||||
{
|
||||
Byte buf[8];
|
||||
RINOK(ReadBytes(stream, buf, 8));
|
||||
RINOK(ReadBytes(stream, buf, 8))
|
||||
Crc = Get32(buf);
|
||||
Size32 = Get32(buf + 4);
|
||||
return stream->InputEofError() ? S_FALSE : S_OK;
|
||||
@@ -410,7 +410,7 @@ HRESULT CItem::ReadFooter1(NDecoder::CCOMCoder *stream)
|
||||
HRESULT CItem::ReadFooter2(ISequentialInStream *stream)
|
||||
{
|
||||
Byte buf[8];
|
||||
RINOK(ReadStream_FALSE(stream, buf, 8));
|
||||
RINOK(ReadStream_FALSE(stream, buf, 8))
|
||||
Crc = Get32(buf);
|
||||
Size32 = Get32(buf + 4);
|
||||
return S_OK;
|
||||
@@ -424,15 +424,15 @@ HRESULT CItem::WriteHeader(ISequentialOutStream *stream)
|
||||
buf[2] = kSignature_2;
|
||||
buf[3] = (Byte)(Flags & NFlags::kName);
|
||||
// buf[3] |= NFlags::kCrc;
|
||||
SetUi32(buf + 4, Time);
|
||||
SetUi32(buf + 4, Time)
|
||||
buf[8] = ExtraFlags;
|
||||
buf[9] = HostOS;
|
||||
RINOK(WriteStream(stream, buf, 10));
|
||||
RINOK(WriteStream(stream, buf, 10))
|
||||
// crc = CrcUpdate(CRC_INIT_VAL, buf, 10);
|
||||
if (NameIsPresent())
|
||||
{
|
||||
// crc = CrcUpdate(crc, (const char *)Name, Name.Len() + 1);
|
||||
RINOK(WriteStream(stream, (const char *)Name, Name.Len() + 1));
|
||||
RINOK(WriteStream(stream, (const char *)Name, Name.Len() + 1))
|
||||
}
|
||||
// SetUi16(buf, (UInt16)CRC_GET_DIGEST(crc));
|
||||
// RINOK(WriteStream(stream, buf, 2));
|
||||
@@ -442,18 +442,16 @@ HRESULT CItem::WriteHeader(ISequentialOutStream *stream)
|
||||
HRESULT CItem::WriteFooter(ISequentialOutStream *stream)
|
||||
{
|
||||
Byte buf[8];
|
||||
SetUi32(buf, Crc);
|
||||
SetUi32(buf + 4, Size32);
|
||||
SetUi32(buf, Crc)
|
||||
SetUi32(buf + 4, Size32)
|
||||
return WriteStream(stream, buf, 8);
|
||||
}
|
||||
|
||||
class CHandler:
|
||||
public IInArchive,
|
||||
public IArchiveOpenSeq,
|
||||
public IOutArchive,
|
||||
public ISetProperties,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
Z7_CLASS_IMP_CHandler_IInArchive_3(
|
||||
IArchiveOpenSeq,
|
||||
IOutArchive,
|
||||
ISetProperties
|
||||
)
|
||||
CItem _item;
|
||||
|
||||
bool _isArc;
|
||||
@@ -478,16 +476,6 @@ class CHandler:
|
||||
CHandlerTimeOptions _timeOptions;
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP4(
|
||||
IInArchive,
|
||||
IArchiveOpenSeq,
|
||||
IOutArchive,
|
||||
ISetProperties)
|
||||
INTERFACE_IInArchive(;)
|
||||
INTERFACE_IOutArchive(;)
|
||||
STDMETHOD(OpenSeq)(ISequentialInStream *stream);
|
||||
STDMETHOD(SetProperties)(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps);
|
||||
|
||||
CHandler():
|
||||
_isArc(false),
|
||||
_decoderSpec(NULL)
|
||||
@@ -523,7 +511,7 @@ static const Byte kArcProps[] =
|
||||
IMP_IInArchive_Props
|
||||
IMP_IInArchive_ArcProps
|
||||
|
||||
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
@@ -557,13 +545,13 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
|
||||
{
|
||||
*numItems = 1;
|
||||
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;
|
||||
@@ -605,19 +593,17 @@ STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIAN
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
class CCompressProgressInfoImp:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
Z7_CLASS_IMP_COM_1(
|
||||
CCompressProgressInfoImp,
|
||||
ICompressProgressInfo
|
||||
)
|
||||
CMyComPtr<IArchiveOpenCallback> Callback;
|
||||
public:
|
||||
UInt64 Offset;
|
||||
MY_UNKNOWN_IMP1(ICompressProgressInfo)
|
||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
|
||||
void Init(IArchiveOpenCallback *callback) { Callback = callback; }
|
||||
};
|
||||
|
||||
STDMETHODIMP CCompressProgressInfoImp::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */)
|
||||
Z7_COM7F_IMF(CCompressProgressInfoImp::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */))
|
||||
{
|
||||
if (Callback)
|
||||
{
|
||||
@@ -631,15 +617,15 @@ STDMETHODIMP CCompressProgressInfoImp::SetRatioInfo(const UInt64 *inSize, const
|
||||
/*
|
||||
*/
|
||||
|
||||
STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *)
|
||||
Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
RINOK(OpenSeq(stream));
|
||||
RINOK(OpenSeq(stream))
|
||||
_isArc = false;
|
||||
UInt64 endPos;
|
||||
RINOK(stream->Seek(-8, STREAM_SEEK_END, &endPos));
|
||||
RINOK(stream->Seek(-8, STREAM_SEEK_END, &endPos))
|
||||
_packSize = endPos + 8;
|
||||
RINOK(_item.ReadFooter2(stream));
|
||||
RINOK(_item.ReadFooter2(stream))
|
||||
_stream = stream;
|
||||
_isArc = true;
|
||||
_needSeekToStart = true;
|
||||
@@ -647,7 +633,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
|
||||
Z7_COM7F_IMF(CHandler::OpenSeq(ISequentialInStream *stream))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
try
|
||||
@@ -656,7 +642,7 @@ STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
|
||||
CreateDecoder();
|
||||
_decoderSpec->SetInStream(stream);
|
||||
_decoderSpec->InitInStream(true);
|
||||
RINOK(_item.ReadHeader(_decoderSpec));
|
||||
RINOK(_item.ReadHeader(_decoderSpec))
|
||||
if (_decoderSpec->InputEofError())
|
||||
return S_FALSE;
|
||||
_headerSize = _decoderSpec->GetInputProcessedSize();
|
||||
@@ -667,7 +653,7 @@ STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Close()
|
||||
Z7_COM7F_IMF(CHandler::Close())
|
||||
{
|
||||
_isArc = false;
|
||||
_needSeekToStart = false;
|
||||
@@ -687,8 +673,8 @@ 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
|
||||
if (numItems == 0)
|
||||
@@ -701,10 +687,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
// UInt64 currentTotalPacked = 0;
|
||||
// RINOK(extractCallback->SetCompleted(¤tTotalPacked));
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
Int32 askMode = testMode ?
|
||||
const Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
|
||||
RINOK(extractCallback->GetStream(0, &realOutStream, askMode))
|
||||
if (!testMode && !realOutStream)
|
||||
return S_OK;
|
||||
|
||||
@@ -728,7 +714,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
if (!_stream)
|
||||
return E_FAIL;
|
||||
RINOK(_stream->Seek(0, STREAM_SEEK_SET, NULL));
|
||||
RINOK(InStream_SeekToBegin(_stream))
|
||||
_decoderSpec->InitInStream(true);
|
||||
// printf("\nSeek");
|
||||
}
|
||||
@@ -754,7 +740,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
lps->InSize = packSize;
|
||||
lps->OutSize = unpackedSize;
|
||||
|
||||
RINOK(lps->SetCur());
|
||||
RINOK(lps->SetCur())
|
||||
|
||||
CItem item;
|
||||
|
||||
@@ -954,14 +940,15 @@ static HRESULT UpdateArchive(
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> fileInStream;
|
||||
|
||||
RINOK(updateCallback->GetStream(0, &fileInStream));
|
||||
RINOK(updateCallback->GetStream(0, &fileInStream))
|
||||
|
||||
if (!fileInStream)
|
||||
return S_FALSE;
|
||||
|
||||
{
|
||||
CMyComPtr<IStreamGetProps> getProps;
|
||||
fileInStream->QueryInterface(IID_IStreamGetProps, (void **)&getProps);
|
||||
Z7_DECL_CMyComPtr_QI_FROM(
|
||||
IStreamGetProps,
|
||||
getProps, fileInStream)
|
||||
if (getProps)
|
||||
{
|
||||
FILETIME mTime;
|
||||
@@ -976,8 +963,8 @@ static HRESULT UpdateArchive(
|
||||
}
|
||||
|
||||
UInt64 complexity = 0;
|
||||
RINOK(updateCallback->SetTotal(unpackSize));
|
||||
RINOK(updateCallback->SetCompleted(&complexity));
|
||||
RINOK(updateCallback->SetTotal(unpackSize))
|
||||
RINOK(updateCallback->SetCompleted(&complexity))
|
||||
|
||||
CSequentialInStreamWithCRC *inStreamSpec = new CSequentialInStreamWithCRC;
|
||||
CMyComPtr<ISequentialInStream> crcStream(inStreamSpec);
|
||||
@@ -994,17 +981,17 @@ static HRESULT UpdateArchive(
|
||||
|
||||
item.HostOS = kHostOS;
|
||||
|
||||
RINOK(item.WriteHeader(outStream));
|
||||
RINOK(item.WriteHeader(outStream))
|
||||
|
||||
NEncoder::CCOMCoder *deflateEncoderSpec = new NEncoder::CCOMCoder;
|
||||
CMyComPtr<ICompressCoder> deflateEncoder = deflateEncoderSpec;
|
||||
RINOK(props.SetCoderProps(deflateEncoderSpec, NULL));
|
||||
RINOK(deflateEncoder->Code(crcStream, outStream, NULL, NULL, progress));
|
||||
RINOK(props.SetCoderProps(deflateEncoderSpec, NULL))
|
||||
RINOK(deflateEncoder->Code(crcStream, outStream, NULL, NULL, progress))
|
||||
|
||||
item.Crc = inStreamSpec->GetCRC();
|
||||
unpackSizeReal = inStreamSpec->GetSize();
|
||||
item.Size32 = (UInt32)unpackSizeReal;
|
||||
RINOK(item.WriteFooter(outStream));
|
||||
RINOK(item.WriteFooter(outStream))
|
||||
}
|
||||
/*
|
||||
if (reportArcProp)
|
||||
@@ -1020,7 +1007,7 @@ static HRESULT UpdateArchive(
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::GetFileTimeType(UInt32 *timeType)
|
||||
Z7_COM7F_IMF(CHandler::GetFileTimeType(UInt32 *timeType))
|
||||
{
|
||||
/*
|
||||
if (_item.Time != 0)
|
||||
@@ -1049,24 +1036,29 @@ STDMETHODIMP CHandler::GetFileTimeType(UInt32 *timeType)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
|
||||
IArchiveUpdateCallback *updateCallback)
|
||||
Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
|
||||
IArchiveUpdateCallback *updateCallback))
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
|
||||
if (numItems != 1)
|
||||
return E_INVALIDARG;
|
||||
|
||||
{
|
||||
Z7_DECL_CMyComPtr_QI_FROM(
|
||||
IStreamSetRestriction,
|
||||
setRestriction, outStream)
|
||||
if (setRestriction)
|
||||
RINOK(setRestriction->SetRestriction(0, 0))
|
||||
}
|
||||
|
||||
Int32 newData, newProps;
|
||||
UInt32 indexInArchive;
|
||||
if (!updateCallback)
|
||||
return E_FAIL;
|
||||
RINOK(updateCallback->GetUpdateItemInfo(0, &newData, &newProps, &indexInArchive));
|
||||
RINOK(updateCallback->GetUpdateItemInfo(0, &newData, &newProps, &indexInArchive))
|
||||
|
||||
/*
|
||||
CMyComPtr<IArchiveUpdateCallbackArcProp> reportArcProp;
|
||||
updateCallback->QueryInterface(IID_IArchiveUpdateCallbackArcProp, (void **)&reportArcProp);
|
||||
*/
|
||||
// Z7_DECL_CMyComPtr_QI_FROM(IArchiveUpdateCallbackArcProp, reportArcProp, updateCallback)
|
||||
|
||||
CItem newItem;
|
||||
|
||||
@@ -1080,7 +1072,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
if (_timeOptions.Write_MTime.Val)
|
||||
{
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(updateCallback->GetProperty(0, kpidMTime, &prop));
|
||||
RINOK(updateCallback->GetProperty(0, kpidMTime, &prop))
|
||||
if (prop.vt == VT_FILETIME)
|
||||
NTime::FileTime_To_UnixTime(prop.filetime, newItem.Time);
|
||||
else if (prop.vt == VT_EMPTY)
|
||||
@@ -1090,7 +1082,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
}
|
||||
{
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(updateCallback->GetProperty(0, kpidPath, &prop));
|
||||
RINOK(updateCallback->GetProperty(0, kpidPath, &prop))
|
||||
if (prop.vt == VT_BSTR)
|
||||
{
|
||||
UString name = prop.bstrVal;
|
||||
@@ -1106,7 +1098,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
}
|
||||
{
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(updateCallback->GetProperty(0, kpidIsDir, &prop));
|
||||
RINOK(updateCallback->GetProperty(0, kpidIsDir, &prop))
|
||||
if (prop.vt != VT_EMPTY)
|
||||
if (prop.vt != VT_BOOL || prop.boolVal != VARIANT_FALSE)
|
||||
return E_INVALIDARG;
|
||||
@@ -1118,7 +1110,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
UInt64 size;
|
||||
{
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(updateCallback->GetProperty(0, kpidSize, &prop));
|
||||
RINOK(updateCallback->GetProperty(0, kpidSize, &prop))
|
||||
if (prop.vt != VT_UI8)
|
||||
return E_INVALIDARG;
|
||||
size = prop.uhVal.QuadPart;
|
||||
@@ -1136,8 +1128,9 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(updateCallback, true);
|
||||
|
||||
CMyComPtr<IArchiveUpdateCallbackFile> opCallback;
|
||||
updateCallback->QueryInterface(IID_IArchiveUpdateCallbackFile, (void **)&opCallback);
|
||||
Z7_DECL_CMyComPtr_QI_FROM(
|
||||
IArchiveUpdateCallbackFile,
|
||||
opCallback, updateCallback)
|
||||
if (opCallback)
|
||||
{
|
||||
RINOK(opCallback->ReportOperation(
|
||||
@@ -1153,7 +1146,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
newItem.WriteHeader(outStream);
|
||||
offset += _headerSize;
|
||||
}
|
||||
RINOK(_stream->Seek((Int64)offset, STREAM_SEEK_SET, NULL));
|
||||
RINOK(InStream_SeekSet(_stream, offset))
|
||||
|
||||
/*
|
||||
if (reportArcProp)
|
||||
@@ -1168,7 +1161,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps)
|
||||
Z7_COM7F_IMF(CHandler::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps))
|
||||
{
|
||||
_timeOptions.Init();
|
||||
_props.Init();
|
||||
@@ -1182,7 +1175,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVAR
|
||||
const PROPVARIANT &value = values[i];
|
||||
{
|
||||
bool processed = false;
|
||||
RINOK(_timeOptions.Parse(name, value, processed));
|
||||
RINOK(_timeOptions.Parse(name, value, processed))
|
||||
if (processed)
|
||||
{
|
||||
if (_timeOptions.Write_CTime.Val ||
|
||||
@@ -1197,7 +1190,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVAR
|
||||
continue;
|
||||
}
|
||||
}
|
||||
RINOK(_props.SetProperty(name, value));
|
||||
RINOK(_props.SetProperty(name, value))
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user