本文整理汇总了C++中CItemEx类的典型用法代码示例。如果您正苦于以下问题:C++ CItemEx类的具体用法?C++ CItemEx怎么用?C++ CItemEx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CItemEx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadLocalItemAfterCdItemFull
HRESULT CInArchive::ReadLocalItemAfterCdItemFull(CItemEx &item)
{
if (item.FromLocal)
return S_OK;
try
{
RINOK(ReadLocalItemAfterCdItem(item));
if (item.HasDescriptor())
{
RINOK(Seek(ArcInfo.Base + item.GetDataPosition() + item.PackSize));
if (ReadUInt32() != NSignature::kDataDescriptor)
return S_FALSE;
UInt32 crc = ReadUInt32();
UInt64 packSize, unpackSize;
/*
if (IsZip64)
{
packSize = ReadUInt64();
unpackSize = ReadUInt64();
}
else
*/
{
packSize = ReadUInt32();
unpackSize = ReadUInt32();
}
if (crc != item.Crc || item.PackSize != packSize || item.Size != unpackSize)
return S_FALSE;
}
}
catch(...) { return S_FALSE; }
return S_OK;
}
示例2: ReadHeaderReal
void CInArchive::ReadHeaderReal(CItemEx &item)
{
item.Flags = m_BlockHeader.Flags;
item.PackSize = ReadUInt32();
item.Size = ReadUInt32();
item.HostOS = ReadByte();
item.FileCRC = ReadUInt32();
item.MTime.DosTime = ReadUInt32();
item.UnPackVersion = ReadByte();
item.Method = ReadByte();
int nameSize = ReadUInt16();
item.Attrib = ReadUInt32();
item.MTime.LowSecond = 0;
item.MTime.SubTime[0] =
item.MTime.SubTime[1] =
item.MTime.SubTime[2] = 0;
if((item.Flags & NHeader::NFile::kSize64Bits) != 0)
{
item.PackSize |= ((UInt64)ReadUInt32() << 32);
item.Size |= ((UInt64)ReadUInt32() << 32);
}
ReadName(item, nameSize);
if (item.HasSalt())
for (int i = 0; i < sizeof(item.Salt); i++)
item.Salt[i] = ReadByte();
// some rar archives have HasExtTime flag without field.
if (m_CurPos < m_PosLimit && item.HasExtTime())
{
Byte accessMask = (Byte)(ReadByte() >> 4);
Byte b = ReadByte();
Byte modifMask = (Byte)(b >> 4);
Byte createMask = (Byte)(b & 0xF);
if ((modifMask & 8) != 0)
ReadTime(modifMask, item.MTime);
item.CTimeDefined = ((createMask & 8) != 0);
if (item.CTimeDefined)
{
item.CTime.DosTime = ReadUInt32();
ReadTime(createMask, item.CTime);
}
item.ATimeDefined = ((accessMask & 8) != 0);
if (item.ATimeDefined)
{
item.ATime.DosTime = ReadUInt32();
ReadTime(accessMask, item.ATime);
}
}
示例3: UpdateItemOldData
static HRESULT UpdateItemOldData(
COutArchive &archive,
CInArchive *inArchive,
const CItemEx &itemEx,
const CUpdateItem &ui,
CItemOut &item,
/* bool izZip64, */
ICompressProgressInfo *progress,
UInt64 &complexity)
{
if (ui.NewProps)
{
if (item.HasDescriptor())
return E_NOTIMPL;
// use old name size.
// CUpdateRange range(item.GetLocalExtraPosition(), item.LocalExtraSize + item.PackSize);
CUpdateRange range(inArchive->GetOffsetInStream(itemEx.GetDataPosition()), itemEx.PackSize);
// we keep ExternalAttrib and some another properties from old archive
// item.ExternalAttrib = ui.Attrib;
item.Name = ui.Name;
item.SetUtf8(ui.IsUtf8);
item.Time = ui.Time;
item.Ntfs_MTime = ui.Ntfs_MTime;
item.Ntfs_ATime = ui.Ntfs_ATime;
item.Ntfs_CTime = ui.Ntfs_CTime;
item.NtfsTimeIsDefined = ui.NtfsTimeIsDefined;
item.CentralExtra.RemoveUnknownSubBlocks();
item.LocalExtra.RemoveUnknownSubBlocks();
item.LocalHeaderPos = archive.GetCurPos();
archive.PrepareWriteCompressedData2(item.Name.Len(), item.Size, item.PackSize, item.LocalExtra.HasWzAes());
archive.WriteLocalHeader(item);
RINOK(WriteRange(inArchive->Stream, archive, range, progress));
complexity += range.Size;
}
else
{
CUpdateRange range(inArchive->GetOffsetInStream(itemEx.LocalHeaderPos), itemEx.GetLocalFullSize());
// set new header position
item.LocalHeaderPos = archive.GetCurPos();
RINOK(WriteRange(inArchive->Stream, archive, range, progress));
complexity += range.Size;
archive.MoveCurPos(range.Size);
}
return S_OK;
}
示例4: ReadName
void CInArchive::ReadName(CItemEx &item, int nameSize)
{
item.UnicodeName.Empty();
if (nameSize > 0)
{
m_NameBuffer.EnsureCapacity(nameSize + 1);
char *buffer = (char *)m_NameBuffer;
for (int i = 0; i < nameSize; i++)
buffer[i] = ReadByte();
int mainLen;
for (mainLen = 0; mainLen < nameSize; mainLen++)
if (buffer[mainLen] == '\0')
break;
buffer[mainLen] = '\0';
item.Name = buffer;
if(item.HasUnicodeName())
{
if(mainLen < nameSize)
{
int unicodeNameSizeMax = MyMin(nameSize, (0x400));
_unicodeNameBuffer.EnsureCapacity(unicodeNameSizeMax + 1);
DecodeUnicodeFileName(buffer, (const Byte *)buffer + mainLen + 1,
nameSize - (mainLen + 1), _unicodeNameBuffer, unicodeNameSizeMax);
item.UnicodeName = _unicodeNameBuffer;
}
else if (!ConvertUTF8ToUnicode(item.Name, item.UnicodeName))
item.UnicodeName.Empty();
}
}
else
item.Name.Empty();
}
示例5: while
HRESULT CInArchive::ReadLocals(
CObjectVector<CItemEx> &items, CProgressVirt *progress)
{
items.Clear();
while (m_Signature == NSignature::kLocalFileHeader)
{
CItemEx item;
item.LocalHeaderPos = m_Position - 4 - ArcInfo.MarkerPos;
// we write ralative LocalHeaderPos here. Later we can correct it to real Base.
try
{
ReadLocalItem(item);
item.FromLocal = true;
if (item.HasDescriptor())
ReadLocalItemDescriptor(item);
else
{
RINOK(IncreaseRealPosition(item.PackSize));
}
items.Add(item);
m_Signature = ReadUInt32();
}
catch (CUnexpectEnd &)
{
if (items.IsEmpty() || items.Size() == 1 && IsStrangeItem(items[0]))
return S_FALSE;
throw;
}
if (progress && items.Size() % 1 == 0)
RINOK(progress->SetCompletedLocal(items.Size(), item.LocalHeaderPos));
}
if (items.Size() == 1 && m_Signature != NSignature::kCentralFileHeader)
if (IsStrangeItem(items[0]))
return S_FALSE;
return S_OK;
}
示例6: AreItemsEqual
static bool AreItemsEqual(const CItemEx &localItem, const CItemEx &cdItem)
{
if (!FlagsAreSame(cdItem, localItem))
return false;
if (!localItem.HasDescriptor())
{
if (cdItem.Crc != localItem.Crc ||
cdItem.PackSize != localItem.PackSize ||
cdItem.Size != localItem.Size)
return false;
}
/* pkzip 2.50 creates incorrect archives. It uses
- WIN encoding for name in local header
- OEM encoding for name in central header
We don't support these strange items. */
/* if (cdItem.Name.Len() != localItem.Name.Len())
return false;
*/
if (cdItem.Name != localItem.Name)
return false;
return true;
}
示例7: RINOK
HRESULT CHandler::Open2(IInStream *stream,
const UInt64 *maxCheckStartPosition,
IArchiveOpenCallback *openArchiveCallback)
{
{
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
CMyComPtr<ICryptoGetTextPassword> getTextPassword;
CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;
CVolumeName seqName;
UInt64 totalBytes = 0;
UInt64 curBytes = 0;
if (openArchiveCallback != NULL)
{
openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);
openArchiveCallbackWrap.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
}
for (;;)
{
CMyComPtr<IInStream> inStream;
if (!_archives.IsEmpty())
{
if (!openVolumeCallback)
break;
if (_archives.Size() == 1)
{
if (!_archiveInfo.IsVolume())
break;
UString baseName;
{
NCOM::CPropVariant prop;
RINOK(openVolumeCallback->GetProperty(kpidName, &prop));
if (prop.vt != VT_BSTR)
break;
baseName = prop.bstrVal;
}
seqName.InitName(baseName, _archiveInfo.HaveNewVolumeName());
}
UString fullName = seqName.GetNextName();
HRESULT result = openVolumeCallback->GetStream(fullName, &inStream);
if (result == S_FALSE)
break;
if (result != S_OK)
return result;
if (!stream)
break;
}
else
inStream = stream;
UInt64 endPos = 0;
if (openArchiveCallback != NULL)
{
RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
totalBytes += endPos;
RINOK(openArchiveCallback->SetTotal(NULL, &totalBytes));
}
NArchive::NRar::CInArchive archive;
RINOK(archive.Open(inStream, maxCheckStartPosition));
if (_archives.IsEmpty())
archive.GetArchiveInfo(_archiveInfo);
CItemEx item;
for (;;)
{
bool decryptionError;
HRESULT result = archive.GetNextItem(item, getTextPassword, decryptionError);
if (result == S_FALSE)
{
if (decryptionError && _items.IsEmpty())
return S_FALSE;
break;
}
RINOK(result);
if (item.IgnoreItem())
continue;
bool needAdd = true;
if (item.IsSplitBefore())
{
if (!_refItems.IsEmpty())
{
CRefItem &refItem = _refItems.Back();
refItem.NumItems++;
needAdd = false;
}
}
if (needAdd)
{
CRefItem refItem;
refItem.ItemIndex = _items.Size();
refItem.NumItems = 1;
//.........这里部分代码省略.........
示例8: UInt32
STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
{
COM_TRY_BEGIN
CZipDecoder myDecoder;
bool testMode = (_aTestMode != 0);
UInt64 totalUnPacked = 0, totalPacked = 0;
bool allFilesMode = (numItems == UInt32(-1));
if (allFilesMode)
numItems = m_Items.Size();
if(numItems == 0)
return S_OK;
UInt32 i;
for(i = 0; i < numItems; i++)
{
const CItemEx &item = m_Items[allFilesMode ? i : indices[i]];
totalUnPacked += item.UnPackSize;
totalPacked += item.PackSize;
}
RINOK(extractCallback->SetTotal(totalUnPacked));
UInt64 currentTotalUnPacked = 0, currentTotalPacked = 0;
UInt64 currentItemUnPacked, currentItemPacked;
CLocalProgress *lps = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> progress = lps;
lps->Init(extractCallback, false);
for (i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked,
currentTotalPacked += currentItemPacked)
{
currentItemUnPacked = 0;
currentItemPacked = 0;
lps->InSize = currentTotalPacked;
lps->OutSize = currentTotalUnPacked;
RINOK(lps->SetCur());
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode = testMode ?
NArchive::NExtract::NAskMode::kTest :
NArchive::NExtract::NAskMode::kExtract;
Int32 index = allFilesMode ? i : indices[i];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
CItemEx item = m_Items[index];
if (!item.FromLocal)
{
HRESULT res = m_Archive.ReadLocalItemAfterCdItem(item);
if (res == S_FALSE)
{
if (item.IsDir() || realOutStream || testMode)
{
RINOK(extractCallback->PrepareOperation(askMode));
realOutStream.Release();
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
}
continue;
}
RINOK(res);
}
if (item.IsDir() || item.IgnoreItem())
{
// if (!testMode)
{
RINOK(extractCallback->PrepareOperation(askMode));
realOutStream.Release();
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
}
continue;
}
currentItemUnPacked = item.UnPackSize;
currentItemPacked = item.PackSize;
if (!testMode && (!realOutStream))
continue;
RINOK(extractCallback->PrepareOperation(askMode));
Int32 res;
RINOK(myDecoder.Decode(
EXTERNAL_CODECS_VARS
m_Archive, item, realOutStream, extractCallback,
progress, _numThreads, res));
realOutStream.Release();
RINOK(extractCallback->SetOperationResult(res))
}
return S_OK;
COM_TRY_END
}
示例9: Decode
HRESULT CZipDecoder::Decode(
DECL_EXTERNAL_CODECS_LOC_VARS
CInArchive &archive, const CItemEx &item,
ISequentialOutStream *realOutStream,
IArchiveExtractCallback *extractCallback,
ICompressProgressInfo *compressProgress,
UInt32 numThreads, Int32 &res)
{
res = NArchive::NExtract::NOperationResult::kDataError;
CInStreamReleaser inStreamReleaser;
bool needCRC = true;
bool wzAesMode = false;
bool pkAesMode = false;
UInt16 methodId = item.CompressionMethod;
if (item.IsEncrypted())
{
if (item.IsStrongEncrypted())
{
CStrongCryptoField f;
if (item.CentralExtra.GetStrongCryptoField(f))
{
pkAesMode = true;
}
if (!pkAesMode)
{
res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
return S_OK;
}
}
if (methodId == NFileHeader::NCompressionMethod::kWzAES)
{
CWzAesExtraField aesField;
if (item.CentralExtra.GetWzAesField(aesField))
{
wzAesMode = true;
needCRC = aesField.NeedCrc();
}
}
}
COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
outStreamSpec->SetStream(realOutStream);
outStreamSpec->Init(needCRC);
UInt64 authenticationPos;
CMyComPtr<ISequentialInStream> inStream;
{
UInt64 packSize = item.PackSize;
if (wzAesMode)
{
if (packSize < NCrypto::NWzAes::kMacSize)
return S_OK;
packSize -= NCrypto::NWzAes::kMacSize;
}
UInt64 dataPos = item.GetDataPosition();
inStream.Attach(archive.CreateLimitedStream(dataPos, packSize));
authenticationPos = dataPos + packSize;
}
CMyComPtr<ICompressFilter> cryptoFilter;
if (item.IsEncrypted())
{
if (wzAesMode)
{
CWzAesExtraField aesField;
if (!item.CentralExtra.GetWzAesField(aesField))
return S_OK;
methodId = aesField.Method;
if (!_wzAesDecoder)
{
_wzAesDecoderSpec = new NCrypto::NWzAes::CDecoder;
_wzAesDecoder = _wzAesDecoderSpec;
}
cryptoFilter = _wzAesDecoder;
Byte properties = aesField.Strength;
RINOK(_wzAesDecoderSpec->SetDecoderProperties2(&properties, 1));
}
else if (pkAesMode)
{
if (!_pkAesDecoder)
{
_pkAesDecoderSpec = new NCrypto::NZipStrong::CDecoder;
_pkAesDecoder = _pkAesDecoderSpec;
}
cryptoFilter = _pkAesDecoder;
}
else
{
if (!_zipCryptoDecoder)
{
_zipCryptoDecoderSpec = new NCrypto::NZip::CDecoder;
_zipCryptoDecoder = _zipCryptoDecoderSpec;
}
cryptoFilter = _zipCryptoDecoder;
}
CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
RINOK(cryptoFilter.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword));
//.........这里部分代码省略.........
示例10: kungFuGrip
STDMETHODIMP CHandler::Extract(const quint32* indices, quint32 numItems,
qint32 _aTestMode, IArchiveExtractCallback *extractCallback)
{
RefPtr<IArchiveExtractCallback> kungFuGrip(extractCallback);
CZipDecoder myDecoder;
bool testMode = (_aTestMode != 0);
quint64 totalUnPacked = 0, totalPacked = 0;
bool allFilesMode = (numItems == quint32(-1));
if (allFilesMode)
numItems = m_Items.size();
if (numItems == 0)
return S_OK;
quint32 i;
for (i = 0; i < numItems; i++) {
const CItemEx &item = *m_Items[allFilesMode ? i : indices[i]];
totalUnPacked += item.UnPackSize;
totalPacked += item.PackSize;
}
RINOK(extractCallback->SetTotal(totalUnPacked));
quint64 currentTotalUnPacked = 0, currentTotalPacked = 0;
quint64 currentItemUnPacked, currentItemPacked;
for (i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked,
currentTotalPacked += currentItemPacked) {
currentItemUnPacked = 0;
currentItemPacked = 0;
qint32 askMode = testMode ?
NArchive::NExtract::NAskMode::kTest :
NArchive::NExtract::NAskMode::kExtract;
qint32 index = allFilesMode ? i : indices[i];
ISequentialOutStream *prealOutStream;
RINOK(extractCallback->GetStream(index, &prealOutStream, askMode));
RefPtr<ISequentialOutStream> realOutStream(prealOutStream);
CItemEx item = *m_Items[index];
if (!item.FromLocal) {
HRESULT res = m_Archive.ReadLocalItemAfterCdItem(item);
if (res == S_FALSE) {
if (item.IsDirectory() || realOutStream || testMode) {
RINOK(extractCallback->PrepareOperation(askMode));
realOutStream = 0;
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
}
continue;
}
RINOK(res);
}
if (item.IsDirectory() || item.IgnoreItem()) {
// if (!testMode)
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
}
continue;
}
currentItemUnPacked = item.UnPackSize;
currentItemPacked = item.PackSize;
if (!testMode && (!realOutStream))
continue;
RINOK(extractCallback->PrepareOperation(askMode));
qint32 res;
RINOK(myDecoder.Decode(
m_Archive, item, realOutStream, extractCallback,
_numThreads, res));
RINOK(extractCallback->SetOperationResult(res))
}
return S_OK;
}
示例11: Decode
HRESULT CZipDecoder::Decode(
CInArchive &archive, const CItemEx &item,
ISequentialOutStream *realOutStream,
IArchiveExtractCallback *_extractCallback,
quint32 numThreads, qint32 &res)
{
RefPtr<IArchiveExtractCallback> extractCallback(_extractCallback);
res = NArchive::NExtract::NOperationResult::kDataError;
CInStreamReleaser inStreamReleaser;
bool needCRC = true;
bool aesMode = false;
#ifdef ZIP_STRONG_SUPORT
bool pkAesMode = false;
#endif
quint16 methodId = item.CompressionMethod;
if (item.IsEncrypted()) {
if (item.IsStrongEncrypted()) {
#ifdef ZIP_STRONG_SUPORT
CStrongCryptoField f;
if (item.CentralExtra.GetStrongCryptoField(f)) {
pkAesMode = true;
}
if (!pkAesMode)
#endif
{
res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
return S_OK;
}
}
if (methodId == NFileHeader::NCompressionMethod::kWzAES) {
CWzAesExtraField aesField;
if (item.CentralExtra.GetWzAesField(aesField)) {
aesMode = true;
needCRC = aesField.NeedCrc();
}
}
}
COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
RefPtr<ISequentialOutStream> outStream = outStreamSpec;
outStreamSpec->SetStream(realOutStream);
outStreamSpec->Init(needCRC);
quint64 authenticationPos;
RefPtr<ISequentialInStream> inStream;
{
quint64 packSize = item.PackSize;
if (aesMode) {
if (packSize < NCrypto::NWzAES::kMacSize)
return S_OK;
packSize -= NCrypto::NWzAES::kMacSize;
}
quint64 dataPos = item.GetDataPosition();
inStream = archive.CreateLimitedStream(dataPos, packSize);
authenticationPos = dataPos + packSize;
}
RefPtr<ICompressFilter> cryptoFilter;
if (item.IsEncrypted()) {
if (aesMode) {
CWzAesExtraField aesField;
if (!item.CentralExtra.GetWzAesField(aesField))
return S_OK;
methodId = aesField.Method;
if (!_aesDecoder) {
_aesDecoderSpec = new NCrypto::NWzAES::CDecoder;
_aesDecoder = _aesDecoderSpec;
}
cryptoFilter = _aesDecoder;
quint8 properties = aesField.Strength;
RINOK(_aesDecoderSpec->SetDecoderProperties2(&properties, 1));
}
#ifdef ZIP_STRONG_SUPORT
else if (pkAesMode) {
if (!_zsDecoder) {
_zsDecoderSpec = new NCrypto::NZipStrong::CDecoder;
_zsDecoder = _zsDecoderSpec;
}
cryptoFilter = _zsDecoder;
}
#endif
else {
if (!_zipCryptoDecoder) {
_zipCryptoDecoderSpec = new NCrypto::NZip::CDecoder;
_zipCryptoDecoder = _zipCryptoDecoderSpec;
}
cryptoFilter = _zipCryptoDecoder;
}
RefPtr<ICryptoSetPassword> cryptoSetPassword;
RINOK(cryptoFilter.QueryInterface(&cryptoSetPassword));
if (!getTextPassword)
extractCallback.QueryInterface(&getTextPassword);
if (getTextPassword) {
QString password;
RINOK(getTextPassword->CryptoGetTextPassword(&password));
//.........这里部分代码省略.........
示例12: RINOK
HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
{
UInt64 endPos = 0;
{
RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
}
_phySizeDefined = true;
for (;;)
{
CItemEx item;
bool filled;
RINOK(ReadItem2(stream, filled, item));
if (!filled)
break;
_items.Add(item);
RINOK(stream->Seek(item.GetPackSizeAligned(), STREAM_SEEK_CUR, &_phySize));
if (_phySize > endPos)
{
_errorMessage = kUnexpectedEnd;
break;
}
/*
if (_phySize == endPos)
{
_errorMessage = "There are no trailing zero-filled records";
break;
}
*/
if (callback != NULL)
{
if (_items.Size() == 1)
{
RINOK(callback->SetTotal(NULL, &endPos));
}
if (_items.Size() % 100 == 0)
{
UInt64 numFiles = _items.Size();
RINOK(callback->SetCompleted(&numFiles, &_phySize));
}
}
}
if (_items.Size() == 0)
{
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
if (!callback)
return S_FALSE;
callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
if (!openVolumeCallback)
return S_FALSE;
NCOM::CPropVariant prop;
if (openVolumeCallback->GetProperty(kpidName, &prop) != S_OK)
return S_FALSE;
if (prop.vt != VT_BSTR)
return S_FALSE;
UString baseName = prop.bstrVal;
baseName = baseName.Right(4);
if (baseName.CompareNoCase(L".tar") != 0)
return S_FALSE;
}
return S_OK;
}
示例13: GetNextItem
HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
{
filled = false;
UInt32 processedSize;
Byte startHeader[2];
RINOK(ReadBytes(startHeader, 2, processedSize))
if (processedSize == 0)
return S_OK;
if (processedSize == 1)
return (startHeader[0] == 0) ? S_OK: S_FALSE;
if (startHeader[0] == 0 && startHeader[1] == 0)
return S_OK;
Byte header[256];
const UInt32 kBasicPartSize = 22;
RINOK(ReadBytes(header, kBasicPartSize, processedSize));
if (processedSize != kBasicPartSize)
return (startHeader[0] == 0) ? S_OK: S_FALSE;
const Byte *p = header;
memmove(item.Method, p, kMethodIdSize);
if (!item.IsValidMethod())
return S_OK;
p += kMethodIdSize;
p = ReadUInt32(p, item.PackSize);
p = ReadUInt32(p, item.Size);
p = ReadUInt32(p, item.ModifiedTime);
item.Attributes = *p++;
item.Level = *p++;
if (item.Level > 2)
return S_FALSE;
UInt32 headerSize;
if (item.Level < 2)
{
headerSize = startHeader[0];
if (headerSize < kBasicPartSize)
return S_FALSE;
UInt32 remain = headerSize - kBasicPartSize;
RINOK(CheckReadBytes(header + kBasicPartSize, remain));
if (startHeader[1] != CalcSum(header, headerSize))
return S_FALSE;
size_t nameLength = *p++;
if ((p - header) + nameLength + 2 > headerSize)
return S_FALSE;
p = ReadString(p, nameLength, item.Name);
}
else
headerSize = startHeader[0] | ((UInt32)startHeader[1] << 8);
p = ReadUInt16(p, item.CRC);
if (item.Level != 0)
{
if (item.Level == 2)
{
RINOK(CheckReadBytes(header + kBasicPartSize, 2));
}
if ((size_t)(p - header) + 3 > headerSize)
return S_FALSE;
item.OsId = *p++;
UInt16 nextSize;
p = ReadUInt16(p, nextSize);
while (nextSize != 0)
{
if (nextSize < 3)
return S_FALSE;
if (item.Level == 1)
{
if (item.PackSize < nextSize)
return S_FALSE;
item.PackSize -= nextSize;
}
CExtension ext;
RINOK(CheckReadBytes(&ext.Type, 1))
nextSize -= 3;
ext.Data.SetCapacity(nextSize);
RINOK(CheckReadBytes((Byte *)ext.Data, nextSize))
item.Extensions.Add(ext);
Byte hdr2[2];
RINOK(CheckReadBytes(hdr2, 2));
ReadUInt16(hdr2, nextSize);
}
}
item.DataPosition = m_Position;
filled = true;
return S_OK;
}
示例14: UpdateItemOldData
static HRESULT UpdateItemOldData(
COutArchive &archive,
CInArchive *inArchive,
const CItemEx &itemEx,
const CUpdateItem &ui,
CItemOut &item,
/* bool izZip64, */
ICompressProgressInfo *progress,
IArchiveUpdateCallbackFile *opCallback,
UInt64 &complexity)
{
if (opCallback)
{
RINOK(opCallback->ReportOperation(
NEventIndexType::kInArcIndex, (UInt32)ui.IndexInArc,
NUpdateNotifyOp::kReplicate))
}
if (ui.NewProps)
{
if (item.HasDescriptor())
return E_NOTIMPL;
// use old name size.
CMyComPtr<ISequentialInStream> packStream;
RINOK(inArchive->GetItemStream(itemEx, true, packStream));
if (!packStream)
return E_NOTIMPL;
// we keep ExternalAttrib and some another properties from old archive
// item.ExternalAttrib = ui.Attrib;
item.Name = ui.Name;
item.SetUtf8(ui.IsUtf8);
item.Time = ui.Time;
item.Ntfs_MTime = ui.Ntfs_MTime;
item.Ntfs_ATime = ui.Ntfs_ATime;
item.Ntfs_CTime = ui.Ntfs_CTime;
item.NtfsTimeIsDefined = ui.NtfsTimeIsDefined;
item.CentralExtra.RemoveUnknownSubBlocks();
item.LocalExtra.RemoveUnknownSubBlocks();
item.LocalHeaderPos = archive.GetCurPos();
archive.PrepareWriteCompressedData2(item.Name.Len(), item.Size, item.PackSize, item.LocalExtra.HasWzAes());
archive.WriteLocalHeader(item);
RINOK(CopyBlockToArchive(packStream, itemEx.PackSize, archive, progress));
complexity += itemEx.PackSize;
}
else
{
CMyComPtr<ISequentialInStream> packStream;
RINOK(inArchive->GetItemStream(itemEx, false, packStream));
if (!packStream)
return E_NOTIMPL;
// set new header position
item.LocalHeaderPos = archive.GetCurPos();
const UInt64 rangeSize = itemEx.GetLocalFullSize();
RINOK(CopyBlockToArchive(packStream, rangeSize, archive, progress));
complexity += rangeSize;
archive.MoveCurPos(rangeSize);
}
return S_OK;
}
示例15: RINOK
HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
{
UInt64 endPos = 0;
{
RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
}
_phySizeDefined = true;
bool utf8_OK = true;
if (!_forceCodePage)
{
if (!utf8_OK)
_curCodePage = k_DefaultCodePage;
}
for (;;)
{
CItemEx item;
bool filled;
RINOK(ReadItem2(stream, filled, item));
if (!filled)
break;
_isArc = true;
_items.Add(item);
if (!_forceCodePage)
{
if (utf8_OK) utf8_OK = CheckUTF8(item.Name, item.NameCouldBeReduced);
if (utf8_OK) utf8_OK = CheckUTF8(item.LinkName, item.LinkNameCouldBeReduced);
if (utf8_OK) utf8_OK = CheckUTF8(item.User);
if (utf8_OK) utf8_OK = CheckUTF8(item.Group);
}
RINOK(stream->Seek(item.GetPackSizeAligned(), STREAM_SEEK_CUR, &_phySize));
if (_phySize > endPos)
{
_error = k_ErrorType_UnexpectedEnd;
break;
}
/*
if (_phySize == endPos)
{
_errorMessage = "There are no trailing zero-filled records";
break;
}
*/
if (callback)
{
if (_items.Size() == 1)
{
RINOK(callback->SetTotal(NULL, &endPos));
}
if ((_items.Size() & 0x3FF) == 0)
{
UInt64 numFiles = _items.Size();
RINOK(callback->SetCompleted(&numFiles, &_phySize));
}
}
}
if (!_forceCodePage)
{
if (!utf8_OK)
_curCodePage = k_DefaultCodePage;
}
_openCodePage = _curCodePage;
if (_items.Size() == 0)
{
if (_error != k_ErrorType_OK)
{
_isArc = false;
return S_FALSE;
}
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
if (!callback)
return S_FALSE;
callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
if (!openVolumeCallback)
return S_FALSE;
NCOM::CPropVariant prop;
if (openVolumeCallback->GetProperty(kpidName, &prop) != S_OK)
return S_FALSE;
if (prop.vt != VT_BSTR)
return S_FALSE;
unsigned len = MyStringLen(prop.bstrVal);
if (len < 4 || MyStringCompareNoCase(prop.bstrVal + len - 4, L".tar") != 0)
return S_FALSE;
}
_isArc = true;
return S_OK;
}