本文整理汇总了C++中CLimitedSequentialInStream类的典型用法代码示例。如果您正苦于以下问题:C++ CLimitedSequentialInStream类的具体用法?C++ CLimitedSequentialInStream怎么用?C++ CLimitedSequentialInStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CLimitedSequentialInStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UInt32
STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
{
COM_TRY_BEGIN
bool testMode = (_aTestMode != 0);
bool allFilesMode = (numItems == UInt32(-1));
if (allFilesMode)
numItems = _sections.Size();
if (numItems == 0)
return S_OK;
UInt64 totalSize = 0;
UInt32 i;
for (i = 0; i < numItems; i++)
totalSize += _sections[allFilesMode ? i : indices[i]].GetPackSize();
extractCallback->SetTotal(totalSize);
UInt64 currentTotalSize = 0;
UInt64 currentItemSize;
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
CLocalProgress *lps = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> progress = lps;
lps->Init(extractCallback, false);
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> inStream(streamSpec);
streamSpec->SetStream(_inStream);
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
{
lps->InSize = lps->OutSize = currentTotalSize;
RINOK(lps->SetCur());
Int32 askMode = testMode ?
NArchive::NExtract::NAskMode::kTest :
NArchive::NExtract::NAskMode::kExtract;
UInt32 index = allFilesMode ? i : indices[i];
const CSection &item = _sections[index];
currentItemSize = item.GetPackSize();
CMyComPtr<ISequentialOutStream> outStream;
RINOK(extractCallback->GetStream(index, &outStream, askMode));
if (!testMode && !outStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(_inStream->Seek(item.Pa, STREAM_SEEK_SET, NULL));
streamSpec->Init(currentItemSize);
RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
outStream.Release();
RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == currentItemSize ?
NArchive::NExtract::NOperationResult::kOK:
NArchive::NExtract::NOperationResult::kDataError));
}
return S_OK;
COM_TRY_END
}
示例2: RINOK
HRESULT CHandler::Open2(IInStream *stream)
{
UInt64 archiveStartPos;
RINOK(stream->Seek(0, STREAM_SEEK_SET, &archiveStartPos));
const UInt32 kHeaderSize = 0x1C;
Byte buf[kHeaderSize];
RINOK(ReadStream_FALSE(stream, buf, kHeaderSize));
UInt32 size = Get16(buf + 4);
// UInt32 ver = Get16(buf + 6); // == 0
if (Get32(buf) != 0x78617221 || size != kHeaderSize)
return S_FALSE;
UInt64 packSize = Get64(buf + 8);
UInt64 unpackSize = Get64(buf + 0x10);
// UInt32 checkSumAlogo = Get32(buf + 0x18);
if (unpackSize >= kXmlSizeMax)
return S_FALSE;
_dataStartPos = archiveStartPos + kHeaderSize + packSize;
char *ss = _xml.GetBuffer((int)unpackSize + 1);
NCompress::NZlib::CDecoder *zlibCoderSpec = new NCompress::NZlib::CDecoder();
CMyComPtr<ICompressCoder> zlibCoder = zlibCoderSpec;
CLimitedSequentialInStream *inStreamLimSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> inStreamLim(inStreamLimSpec);
inStreamLimSpec->SetStream(stream);
inStreamLimSpec->Init(packSize);
CBufPtrSeqOutStream *outStreamLimSpec = new CBufPtrSeqOutStream;
CMyComPtr<ISequentialOutStream> outStreamLim(outStreamLimSpec);
outStreamLimSpec->Init((Byte *)ss, (size_t)unpackSize);
RINOK(zlibCoder->Code(inStreamLim, outStreamLim, NULL, NULL, NULL));
if (outStreamLimSpec->GetPos() != (size_t)unpackSize)
return S_FALSE;
ss[(size_t)unpackSize] = 0;
_xml.ReleaseBuffer();
CXml xml;
if (!xml.Parse(_xml))
return S_FALSE;
if (!xml.Root.IsTagged("xar") || xml.Root.SubItems.Size() != 1)
return S_FALSE;
const CXmlItem &toc = xml.Root.SubItems[0];
if (!toc.IsTagged("toc"))
return S_FALSE;
if (!AddItem(toc, _files, -1))
return S_FALSE;
return S_OK;
}
示例3: CreateLimitedStream
ISequentialInStream* CInArchive::CreateLimitedStream(UInt64 position, UInt64 size)
{
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> stream(streamSpec);
Stream->Seek(ArcInfo.Base + position, STREAM_SEEK_SET, NULL);
streamSpec->SetStream(Stream);
streamSpec->Init(size);
return stream.Detach();
}
示例4: RINOK
HRESULT CInArchive::ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size)
{
RINOK(inStream->Seek(pos, STREAM_SEEK_SET, NULL));
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> limitedStream(streamSpec);
streamSpec->SetStream(inStream);
streamSpec->Init(size);
m_InStreamRef = limitedStream;
_inBuffer.SetStream(limitedStream);
_inBuffer.Init();
return S_OK;
}
示例5: WriteRange
static HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream,
UInt64 position, UInt64 size, ICompressProgressInfo *progress)
{
RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);
streamSpec->SetStream(inStream);
streamSpec->Init(size);
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));
return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);
}
示例6: RINOK
HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unpackSize,
ISequentialOutStream *realOutStream, ICompressProgressInfo *progress,
UInt32 &packSizeRes, UInt32 &unpackSizeRes)
{
CLimitedSequentialInStream *limitedStreamSpec = NULL;
CMyComPtr<ISequentialInStream> limitedStream;
packSizeRes = 0;
unpackSizeRes = 0;
if (Solid)
{
Byte temp[4];
size_t processedSize = 4;
RINOK(Read(temp, &processedSize));
if (processedSize != 4)
return S_FALSE;
StreamPos += processedSize;
UInt32 size = Get32(temp);
if (unpackSizeDefined && size != unpackSize)
return S_FALSE;
unpackSize = size;
unpackSizeDefined = true;
}
else
{
Byte temp[4];
RINOK(ReadStream_FALSE(InputStream, temp, 4));
StreamPos += 4;
UInt32 size = Get32(temp);
if ((size & kMask_IsCompressed) == 0)
{
if (unpackSizeDefined && size != unpackSize)
return S_FALSE;
packSizeRes = size;
if (outBuf)
outBuf->Alloc(size);
UInt64 offset = 0;
while (size > 0)
{
UInt32 curSize = (UInt32)MyMin((size_t)size, Buffer.Size());
UInt32 processedSize;
RINOK(InputStream->Read(Buffer, curSize, &processedSize));
if (processedSize == 0)
return S_FALSE;
if (outBuf)
memcpy((Byte *)*outBuf + (size_t)offset, Buffer, processedSize);
offset += processedSize;
size -= processedSize;
StreamPos += processedSize;
unpackSizeRes += processedSize;
if (realOutStream)
RINOK(WriteStream(realOutStream, Buffer, processedSize));
RINOK(progress->SetRatioInfo(&offset, &offset));
}
return S_OK;
}
size &= ~kMask_IsCompressed;
packSizeRes = size;
limitedStreamSpec = new CLimitedSequentialInStream;
limitedStream = limitedStreamSpec;
limitedStreamSpec->SetStream(InputStream);
limitedStreamSpec->Init(size);
{
bool useFilter;
RINOK(Init(limitedStream, useFilter));
}
}
if (outBuf)
{
if (!unpackSizeDefined)
return S_FALSE;
outBuf->Alloc(unpackSize);
}
UInt64 inSizeStart = 0;
if (_lzmaDecoder)
inSizeStart = _lzmaDecoder->GetInputProcessedSize();
// we don't allow files larger than 4 GB;
if (!unpackSizeDefined)
unpackSize = 0xFFFFFFFF;
UInt32 offset = 0;
for (;;)
{
size_t rem = unpackSize - offset;
if (rem == 0)
break;
size_t size = Buffer.Size();
if (size > rem)
size = rem;
RINOK(Read(Buffer, &size));
if (size == 0)
{
//.........这里部分代码省略.........
示例7: UInt32
STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
{
COM_TRY_BEGIN
bool testMode = (_aTestMode != 0);
bool allFilesMode = (numItems == UInt32(-1));
if (allFilesMode)
numItems = _archive.Refs.Size();
if(numItems == 0)
return S_OK;
UInt64 totalSize = 0;
UInt32 i;
for(i = 0; i < numItems; i++)
{
UInt32 index = (allFilesMode ? i : indices[i]);
if (index < (UInt32)_archive.Refs.Size())
{
const CRef &ref = _archive.Refs[index];
const CDir &item = ref.Dir->_subItems[ref.Index];
totalSize += item.DataLength;
}
else
{
totalSize += _archive.GetBootItemSize(index - _archive.Refs.Size());
}
}
extractCallback->SetTotal(totalSize);
UInt64 currentTotalSize = 0;
UInt64 currentItemSize;
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
CLocalProgress *lps = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> progress = lps;
lps->Init(extractCallback, false);
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> inStream(streamSpec);
streamSpec->SetStream(_inStream);
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
{
lps->InSize = lps->OutSize = currentTotalSize;
RINOK(lps->SetCur());
currentItemSize = 0;
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode;
askMode = testMode ? NArchive::NExtract::NAskMode::kTest : NArchive::NExtract::NAskMode::kExtract;
UInt32 index = allFilesMode ? i : indices[i];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
UInt64 blockIndex;
if (index < (UInt32)_archive.Refs.Size())
{
const CRef &ref = _archive.Refs[index];
const CDir &item = ref.Dir->_subItems[ref.Index];
if(item.IsDir())
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
continue;
}
currentItemSize = item.DataLength;
blockIndex = item.ExtentLocation;
}
else
{
int bootIndex = index - _archive.Refs.Size();
const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
currentItemSize = _archive.GetBootItemSize(bootIndex);
blockIndex = be.LoadRBA;
}
if (!testMode && (!realOutStream))
continue;
RINOK(extractCallback->PrepareOperation(askMode));
if (testMode)
{
RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
continue;
}
RINOK(_inStream->Seek(blockIndex * _archive.BlockSize, STREAM_SEEK_SET, NULL));
streamSpec->Init(currentItemSize);
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
realOutStream.Release();
RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == currentItemSize) ?
NArchive::NExtract::NOperationResult::kOK:
NArchive::NExtract::NOperationResult::kDataError));
}
return S_OK;
COM_TRY_END
}
示例8: RINOK
HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unpackSize,
ISequentialOutStream *realOutStream, ICompressProgressInfo *progress,
UInt32 &packSizeRes, UInt32 &unpackSizeRes)
{
CLimitedSequentialInStream *limitedStreamSpec = NULL;
CMyComPtr<ISequentialInStream> limitedStream;
packSizeRes = 0;
unpackSizeRes = 0;
if (Solid)
{
Byte temp[4];
size_t processedSize = 4;
RINOK(Read(temp, &processedSize));
StreamPos += processedSize;
if (processedSize != 4)
return S_FALSE;
UInt32 size = Get32(temp);
if (unpackSizeDefined && size != unpackSize)
return S_FALSE;
unpackSize = size;
unpackSizeDefined = true;
}
else
{
Byte temp[4];
{
size_t processedSize = 4;
RINOK(ReadStream(InputStream, temp, &processedSize));
StreamPos += processedSize;
if (processedSize != 4)
return S_FALSE;
}
UInt32 size = Get32(temp);
if ((size & kMask_IsCompressed) == 0)
{
if (unpackSizeDefined && size != unpackSize)
return S_FALSE;
packSizeRes = size;
if (outBuf)
outBuf->Alloc(size);
UInt64 offset = 0;
while (size > 0)
{
UInt32 curSize = (UInt32)MyMin((size_t)size, Buffer.Size());
UInt32 processedSize;
RINOK(InputStream->Read(Buffer, curSize, &processedSize));
if (processedSize == 0)
return S_FALSE;
if (outBuf)
memcpy((Byte *)*outBuf + (size_t)offset, Buffer, processedSize);
offset += processedSize;
size -= processedSize;
StreamPos += processedSize;
unpackSizeRes += processedSize;
if (realOutStream)
RINOK(WriteStream(realOutStream, Buffer, processedSize));
RINOK(progress->SetRatioInfo(&offset, &offset));
}
return S_OK;
}
size &= ~kMask_IsCompressed;
packSizeRes = size;
limitedStreamSpec = new CLimitedSequentialInStream;
limitedStream = limitedStreamSpec;
limitedStreamSpec->SetStream(InputStream);
limitedStreamSpec->Init(size);
{
bool useFilter;
RINOK(Init(limitedStream, useFilter));
}
}
if (outBuf)
{
if (unpackSizeDefined)
outBuf->Alloc(unpackSize);
}
const UInt64 inSizeStart = GetInputProcessedSize();
// we don't allow files larger than 4 GB;
if (!unpackSizeDefined)
unpackSize = 0xFFFFFFFF;
UInt32 offset = 0;
HRESULT res = S_OK;
for (;;)
{
size_t rem = unpackSize - offset;
if (rem == 0)
break;
size_t size = Buffer.Size();
if (size > rem)
//.........这里部分代码省略.........
示例9: RINOK
HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource, bool lzxMode,
ISequentialOutStream *outStream, ICompressProgressInfo *progress)
{
RINOK(inStream->Seek(resource.Offset, STREAM_SEEK_SET, NULL));
CLimitedSequentialInStream *limitedStreamSpec = new CLimitedSequentialInStream();
CMyComPtr<ISequentialInStream> limitedStream = limitedStreamSpec;
limitedStreamSpec->SetStream(inStream);
if (!copyCoder)
{
copyCoderSpec = new NCompress::CCopyCoder;
copyCoder = copyCoderSpec;
}
if (!resource.IsCompressed())
{
if (resource.PackSize != resource.UnpackSize)
return S_FALSE;
limitedStreamSpec->Init(resource.PackSize);
return copyCoder->Code(limitedStreamSpec, outStream, NULL, NULL, progress);
}
if (resource.UnpackSize == 0)
return S_OK;
UInt64 numChunks = (resource.UnpackSize + kChunkSize - 1) >> kChunkSizeBits;
unsigned entrySize = ((resource.UnpackSize > (UInt64)1 << 32) ? 8 : 4);
UInt64 sizesBufSize64 = entrySize * (numChunks - 1);
size_t sizesBufSize = (size_t)sizesBufSize64;
if (sizesBufSize != sizesBufSize64)
return E_OUTOFMEMORY;
if (sizesBufSize > sizesBuf.GetCapacity())
{
sizesBuf.Free();
sizesBuf.SetCapacity(sizesBufSize);
}
RINOK(ReadStream_FALSE(inStream, (Byte *)sizesBuf, sizesBufSize));
const Byte *p = (const Byte *)sizesBuf;
if (lzxMode && !lzxDecoder)
{
lzxDecoderSpec = new NCompress::NLzx::CDecoder(true);
lzxDecoder = lzxDecoderSpec;
RINOK(lzxDecoderSpec->SetParams(kChunkSizeBits));
}
UInt64 baseOffset = resource.Offset + sizesBufSize64;
UInt64 outProcessed = 0;
for (UInt32 i = 0; i < (UInt32)numChunks; i++)
{
UInt64 offset = 0;
if (i > 0)
{
offset = (entrySize == 4) ? Get32(p): Get64(p);
p += entrySize;
}
UInt64 nextOffset = resource.PackSize - sizesBufSize64;
if (i + 1 < (UInt32)numChunks)
nextOffset = (entrySize == 4) ? Get32(p): Get64(p);
if (nextOffset < offset)
return S_FALSE;
RINOK(inStream->Seek(baseOffset + offset, STREAM_SEEK_SET, NULL));
UInt64 inSize = nextOffset - offset;
limitedStreamSpec->Init(inSize);
if (progress)
{
RINOK(progress->SetRatioInfo(&offset, &outProcessed));
}
UInt32 outSize = kChunkSize;
if (outProcessed + outSize > resource.UnpackSize)
outSize = (UInt32)(resource.UnpackSize - outProcessed);
UInt64 outSize64 = outSize;
if (inSize == outSize)
{
RINOK(copyCoder->Code(limitedStreamSpec, outStream, NULL, &outSize64, NULL));
}
else
{
if (lzxMode)
{
lzxDecoderSpec->SetKeepHistory(false);
RINOK(lzxDecoder->Code(limitedStreamSpec, outStream, NULL, &outSize64, NULL));
}
else
{
RINOK(xpressDecoder.Code(limitedStreamSpec, outStream, outSize));
}
}
outProcessed += outSize;
}
return S_OK;
}
示例10: Decode
HRESULT CDecoder::Decode(
DECL_EXTERNAL_CODECS_LOC_VARS
IInStream *inStream,
UInt64 startPos,
const UInt64 *packSizes,
const CFolder &folderInfo,
ISequentialOutStream *outStream,
ICompressProgressInfo *compressProgress
#ifndef _NO_CRYPTO
, ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
#endif
#ifdef COMPRESS_MT
, bool mtMode, UInt32 numThreads
#endif
)
{
if (!folderInfo.CheckStructure())
return E_NOTIMPL;
#ifndef _NO_CRYPTO
passwordIsDefined = false;
#endif
CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;
CLockedInStream lockedInStream;
lockedInStream.Init(inStream);
for (int j = 0; j < folderInfo.PackStreams.Size(); j++)
{
CLockedSequentialInStreamImp *lockedStreamImpSpec = new
CLockedSequentialInStreamImp;
CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;
lockedStreamImpSpec->Init(&lockedInStream, startPos);
startPos += packSizes[j];
CLimitedSequentialInStream *streamSpec = new
CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> inStream = streamSpec;
streamSpec->SetStream(lockedStreamImp);
streamSpec->Init(packSizes[j]);
inStreams.Add(inStream);
}
int numCoders = folderInfo.Coders.Size();
CBindInfoEx bindInfo;
ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);
bool createNewCoders;
if (!_bindInfoExPrevIsDefined)
createNewCoders = true;
else
createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);
if (createNewCoders)
{
int i;
_decoders.Clear();
// _decoders2.Clear();
_mixerCoder.Release();
if (_multiThread)
{
_mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;
_mixerCoder = _mixerCoderMTSpec;
_mixerCoderCommon = _mixerCoderMTSpec;
}
else
{
#ifdef _ST_MODE
_mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;
_mixerCoder = _mixerCoderSTSpec;
_mixerCoderCommon = _mixerCoderSTSpec;
#endif
}
RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));
for (i = 0; i < numCoders; i++)
{
const CCoderInfo &coderInfo = folderInfo.Coders[i];
CMyComPtr<ICompressCoder> decoder;
CMyComPtr<ICompressCoder2> decoder2;
RINOK(CreateCoder(
EXTERNAL_CODECS_LOC_VARS
coderInfo.MethodID, decoder, decoder2, false));
CMyComPtr<IUnknown> decoderUnknown;
if (coderInfo.IsSimpleCoder())
{
if (decoder == 0)
return E_NOTIMPL;
decoderUnknown = (IUnknown *)decoder;
if (_multiThread)
_mixerCoderMTSpec->AddCoder(decoder);
#ifdef _ST_MODE
else
_mixerCoderSTSpec->AddCoder(decoder, false);
#endif
}
//.........这里部分代码省略.........
示例11: UpdateArchive
HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
const CObjectVector<NArchive::NTar::CItemEx> &inputItems,
const CObjectVector<CUpdateItem> &updateItems,
UINT codePage,
IArchiveUpdateCallback *updateCallback)
{
COutArchive outArchive;
outArchive.Create(outStream);
outArchive.Pos = 0;
CMyComPtr<IOutStream> outSeekStream;
outStream->QueryInterface(IID_IOutStream, (void **)&outSeekStream);
UInt64 complexity = 0;
unsigned i;
for (i = 0; i < updateItems.Size(); i++)
{
const CUpdateItem &ui = updateItems[i];
if (ui.NewData)
complexity += ui.Size;
else
complexity += inputItems[ui.IndexInArchive].GetFullSize();
}
RINOK(updateCallback->SetTotal(complexity));
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
CLocalProgress *lps = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> progress = lps;
lps->Init(updateCallback, true);
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);
streamSpec->SetStream(inStream);
complexity = 0;
for (i = 0; i < updateItems.Size(); i++)
{
lps->InSize = lps->OutSize = complexity;
RINOK(lps->SetCur());
const CUpdateItem &ui = updateItems[i];
CItem item;
if (ui.NewProps)
{
item.Mode = ui.Mode;
item.Name = ui.Name;
item.User = ui.User;
item.Group = ui.Group;
if (ui.IsDir)
{
item.LinkFlag = NFileHeader::NLinkFlag::kDirectory;
item.PackSize = 0;
}
else
{
item.LinkFlag = NFileHeader::NLinkFlag::kNormal;
item.PackSize = ui.Size;
}
item.MTime = ui.MTime;
item.DeviceMajorDefined = false;
item.DeviceMinorDefined = false;
item.UID = 0;
item.GID = 0;
memcpy(item.Magic, NFileHeader::NMagic::kUsTar_00, 8);
}
else
item = inputItems[ui.IndexInArchive];
AString symLink;
if (ui.NewData || ui.NewProps)
{
RINOK(GetPropString(updateCallback, ui.IndexInClient, kpidSymLink, symLink, codePage, true));
if (!symLink.IsEmpty())
{
item.LinkFlag = NFileHeader::NLinkFlag::kSymLink;
item.LinkName = symLink;
}
}
if (ui.NewData)
{
item.SparseBlocks.Clear();
item.PackSize = ui.Size;
item.Size = ui.Size;
if (ui.Size == (UInt64)(Int64)-1)
return E_INVALIDARG;
CMyComPtr<ISequentialInStream> fileInStream;
bool needWrite = true;
if (!symLink.IsEmpty())
{
item.PackSize = 0;
item.Size = 0;
}
//.........这里部分代码省略.........
示例12: RINOK
HRESULT CHandler::Open2(IInStream *stream)
{
const UInt32 kHeaderSize = 0x1C;
Byte buf[kHeaderSize];
RINOK(ReadStream_FALSE(stream, buf, kHeaderSize));
UInt32 size = Get16(buf + 4);
// UInt32 ver = Get16(buf + 6); // == 1
if (Get32(buf) != 0x78617221 || size != kHeaderSize)
return S_FALSE;
UInt64 packSize = Get64(buf + 8);
UInt64 unpackSize = Get64(buf + 0x10);
// _checkSumAlgo = Get32(buf + 0x18);
if (packSize >= kXmlPackSizeMax ||
unpackSize >= kXmlSizeMax)
return S_FALSE;
_dataStartPos = kHeaderSize + packSize;
_phySize = _dataStartPos;
_xml.Alloc((size_t)unpackSize + 1);
_xmlLen = (size_t)unpackSize;
NCompress::NZlib::CDecoder *zlibCoderSpec = new NCompress::NZlib::CDecoder();
CMyComPtr<ICompressCoder> zlibCoder = zlibCoderSpec;
CLimitedSequentialInStream *inStreamLimSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> inStreamLim(inStreamLimSpec);
inStreamLimSpec->SetStream(stream);
inStreamLimSpec->Init(packSize);
CBufPtrSeqOutStream *outStreamLimSpec = new CBufPtrSeqOutStream;
CMyComPtr<ISequentialOutStream> outStreamLim(outStreamLimSpec);
outStreamLimSpec->Init(_xml, (size_t)unpackSize);
RINOK(zlibCoder->Code(inStreamLim, outStreamLim, NULL, NULL, NULL));
if (outStreamLimSpec->GetPos() != (size_t)unpackSize)
return S_FALSE;
_xml[(size_t)unpackSize] = 0;
if (strlen((const char *)(const Byte *)_xml) != unpackSize) return S_FALSE;
CXml xml;
if (!xml.Parse((const char *)(const Byte *)_xml))
return S_FALSE;
if (!xml.Root.IsTagged("xar") || xml.Root.SubItems.Size() != 1)
return S_FALSE;
const CXmlItem &toc = xml.Root.SubItems[0];
if (!toc.IsTagged("toc"))
return S_FALSE;
if (!AddItem(toc, _files, -1))
return S_FALSE;
UInt64 totalPackSize = 0;
unsigned numMainFiles = 0;
FOR_VECTOR (i, _files)
{
const CFile &file = _files[i];
file.UpdateTotalPackSize(totalPackSize);
if (file.Name == "Payload" || file.Name == "Content")
{
_mainSubfile = i;
numMainFiles++;
}
else if (file.Name == "PackageInfo")
_is_pkg = true;
}
if (numMainFiles > 1)
_mainSubfile = -1;
_phySize = _dataStartPos + totalPackSize;
return S_OK;
}
示例13: Extract
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
{
COM_TRY_BEGIN
bool allFilesMode = (numItems == (UInt32)-1);
if (allFilesMode)
numItems = m_Database.NewFormat ? 1:
(m_Database.LowLevel ?
m_Database.Items.Size():
m_Database.Indices.Size());
if (numItems == 0)
return S_OK;
bool testMode = (testModeSpec != 0);
UInt64 currentTotalSize = 0;
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
UInt32 i;
CLocalProgress *lps = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> progress = lps;
lps->Init(extractCallback, false);
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> inStream(streamSpec);
streamSpec->SetStream(m_Stream);
if (m_Database.LowLevel)
{
UInt64 currentItemSize = 0;
UInt64 totalSize = 0;
if (m_Database.NewFormat)
totalSize = m_Database.NewFormatString.Length();
else
for (i = 0; i < numItems; i++)
totalSize += m_Database.Items[allFilesMode ? i : indices[i]].Size;
extractCallback->SetTotal(totalSize);
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
{
currentItemSize = 0;
lps->InSize = currentTotalSize; // Change it
lps->OutSize = currentTotalSize;
RINOK(lps->SetCur());
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode= testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
Int32 index = allFilesMode ? i : indices[i];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
if (m_Database.NewFormat)
{
if (index != 0)
return E_FAIL;
if (!testMode && !realOutStream)
continue;
if (!testMode)
{
UInt32 size = m_Database.NewFormatString.Length();
RINOK(WriteStream(realOutStream, (const char *)m_Database.NewFormatString, size));
}
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
continue;
}
const CItem &item = m_Database.Items[index];
currentItemSize = item.Size;
if (!testMode && !realOutStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
if (item.Section != 0)
{
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
continue;
}
if (testMode)
{
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
continue;
}
RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL));
streamSpec->Init(item.Size);
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
realOutStream.Release();
RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ?
NExtract::NOperationResult::kOK:
NExtract::NOperationResult::kDataError));
}
return S_OK;
}
UInt64 lastFolderIndex = ((UInt64)0 - 1);
//.........这里部分代码省略.........
示例14: Extract
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback)
{
COM_TRY_BEGIN
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
if (allFilesMode)
numItems = _archive.Refs.Size();
if (numItems == 0)
return S_OK;
UInt64 totalSize = 0;
UInt32 i;
for (i = 0; i < numItems; i++)
{
UInt32 index = (allFilesMode ? i : indices[i]);
if (index < (UInt32)_archive.Refs.Size())
{
const CRef &ref = _archive.Refs[index];
const CDir &item = ref.Dir->_subItems[ref.Index];
if (!item.IsDir())
totalSize += ref.TotalSize;
}
else
totalSize += _archive.GetBootItemSize(index - _archive.Refs.Size());
}
extractCallback->SetTotal(totalSize);
UInt64 currentTotalSize = 0;
UInt64 currentItemSize;
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
CLocalProgress *lps = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> progress = lps;
lps->Init(extractCallback, false);
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<ISequentialInStream> inStream(streamSpec);
streamSpec->SetStream(_stream);
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
{
lps->InSize = lps->OutSize = currentTotalSize;
RINOK(lps->SetCur());
currentItemSize = 0;
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
UInt32 index = allFilesMode ? i : indices[i];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
UInt64 blockIndex;
if (index < (UInt32)_archive.Refs.Size())
{
const CRef &ref = _archive.Refs[index];
const CDir &item = ref.Dir->_subItems[ref.Index];
if (item.IsDir())
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
continue;
}
currentItemSize = ref.TotalSize;
blockIndex = item.ExtentLocation;
}
else
{
unsigned bootIndex = index - _archive.Refs.Size();
const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
currentItemSize = _archive.GetBootItemSize(bootIndex);
blockIndex = be.LoadRBA;
}
if (!testMode && !realOutStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
bool isOK = true;
if (index < (UInt32)_archive.Refs.Size())
{
const CRef &ref = _archive.Refs[index];
UInt64 offset = 0;
for (UInt32 e = 0; e < ref.NumExtents; e++)
{
lps->InSize = lps->OutSize = currentTotalSize + offset;
const CDir &item2 = ref.Dir->_subItems[ref.Index + e];
RINOK(_stream->Seek((UInt64)item2.ExtentLocation * kBlockSize, STREAM_SEEK_SET, NULL));
streamSpec->Init(item2.Size);
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
if (copyCoderSpec->TotalSize != item2.Size)
{
isOK = false;
break;
}
offset += item2.Size;
}
//.........这里部分代码省略.........
示例15: UpdateArchive
//.........这里部分代码省略.........
for(i = 0; i < updateItems.Size(); i++)
{
RINOK(updateCallback->SetCompleted(&complexity));
CLocalProgress *localProgressSpec = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> localProgress = localProgressSpec;
localProgressSpec->Init(updateCallback, true);
CLocalCompressProgressInfo *localCompressProgressSpec = new CLocalCompressProgressInfo;
CMyComPtr<ICompressProgressInfo> compressProgress = localCompressProgressSpec;
localCompressProgressSpec->Init(localProgress, &complexity, NULL);
const CUpdateItemInfo &updateItem = updateItems[i];
CItem item;
if (updateItem.NewProperties)
{
item.Mode = 0777;
item.Name = (updateItem.Name);
if (updateItem.IsDirectory)
{
item.LinkFlag = NFileHeader::NLinkFlag::kDirectory;
item.Size = 0;
}
else
{
item.LinkFlag = NFileHeader::NLinkFlag::kNormal;
item.Size = updateItem.Size;
}
item.ModificationTime = updateItem.Time;
item.DeviceMajorDefined = false;
item.DeviceMinorDefined = false;
item.UID = 0;
item.GID = 0;
memmove(item.Magic, NFileHeader::NMagic::kEmpty, 8);
}
else
{
const CItemEx &existItemInfo = inputItems[updateItem.IndexInArchive];
item = existItemInfo;
}
if (updateItem.NewData)
{
item.Size = updateItem.Size;
if (item.Size == UInt64(Int64(-1)))
return E_INVALIDARG;
}
else
{
const CItemEx &existItemInfo = inputItems[updateItem.IndexInArchive];
item.Size = existItemInfo.Size;
}
if (updateItem.NewData)
{
CMyComPtr<ISequentialInStream> fileInStream;
HRESULT res = updateCallback->GetStream(updateItem.IndexInClient, &fileInStream);
if (res != S_FALSE)
{
RINOK(res);
RINOK(outArchive.WriteHeader(item));
if (!updateItem.IsDirectory)
{
UInt64 totalSize;
RINOK(CopyBlock(fileInStream, outStream, compressProgress, &totalSize));
if (totalSize != item.Size)
return E_FAIL;
RINOK(outArchive.FillDataResidual(item.Size));
}
}
complexity += updateItem.Size;
RINOK(updateCallback->SetOperationResult(
NArchive::NUpdate::NOperationResult::kOK));
}
else
{
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);
const CItemEx &existItemInfo = inputItems[updateItem.IndexInArchive];
if (updateItem.NewProperties)
{
RINOK(outArchive.WriteHeader(item));
RINOK(inStream->Seek(existItemInfo.GetDataPosition(),
STREAM_SEEK_SET, NULL));
streamSpec->Init(inStream, existItemInfo.Size);
}
else
{
RINOK(inStream->Seek(existItemInfo.HeaderPosition,
STREAM_SEEK_SET, NULL));
streamSpec->Init(inStream, existItemInfo.GetFullSize());
}
RINOK(CopyBlock(inStreamLimited, outStream, compressProgress));
RINOK(outArchive.FillDataResidual(existItemInfo.Size));
complexity += existItemInfo.GetFullSize();
}
complexity += kOneItemComplexity;
}
return outArchive.WriteFinishHeader();
}