4.53 beta

This commit is contained in:
Igor Pavlov
2007-08-27 00:00:00 +00:00
committed by Kornel Lesiński
parent 33ccab7e72
commit 051769bbc5
360 changed files with 4658 additions and 5167 deletions

View File

@@ -13,23 +13,9 @@
#include "TarOut.h"
#include "TarUpdate.h"
static const UInt64 kOneItemComplexity = 512;
namespace NArchive {
namespace NTar {
static HRESULT CopyBlock(ISequentialInStream *inStream,
ISequentialOutStream *outStream, ICompressProgressInfo *progress,
UInt64 *totalSize = NULL)
{
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
HRESULT result = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
if (totalSize != NULL)
*totalSize = copyCoderSpec->TotalSize;
return result;
}
HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
const CObjectVector<NArchive::NTar::CItemEx> &inputItems,
const CObjectVector<CUpdateItemInfo> &updateItems,
@@ -48,25 +34,27 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
complexity += updateItem.Size;
else
complexity += inputItems[updateItem.IndexInArchive].GetFullSize();
complexity += kOneItemComplexity;
}
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++)
{
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);
lps->InSize = lps->OutSize = complexity;
RINOK(lps->SetCur());
const CUpdateItemInfo &updateItem = updateItems[i];
CItem item;
@@ -76,13 +64,13 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
item.Name = (updateItem.Name);
if (updateItem.IsDirectory)
{
item.LinkFlag = NFileHeader::NLinkFlag::kDirectory;
item.Size = 0;
item.LinkFlag = NFileHeader::NLinkFlag::kDirectory;
item.Size = 0;
}
else
{
item.LinkFlag = NFileHeader::NLinkFlag::kNormal;
item.Size = updateItem.Size;
item.LinkFlag = NFileHeader::NLinkFlag::kNormal;
item.Size = updateItem.Size;
}
item.ModificationTime = updateItem.Time;
item.DeviceMajorDefined = false;
@@ -118,45 +106,40 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
RINOK(outArchive.WriteHeader(item));
if (!updateItem.IsDirectory)
{
UInt64 totalSize;
RINOK(CopyBlock(fileInStream, outStream, compressProgress, &totalSize));
if (totalSize != item.Size)
RINOK(copyCoder->Code(fileInStream, outStream, NULL, NULL, progress));
if (copyCoderSpec->TotalSize != item.Size)
return E_FAIL;
RINOK(outArchive.FillDataResidual(item.Size));
}
}
complexity += updateItem.Size;
RINOK(updateCallback->SetOperationResult(
NArchive::NUpdate::NOperationResult::kOK));
RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
}
else
{
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);
const CItemEx &existItemInfo = inputItems[updateItem.IndexInArchive];
UInt64 size;
if (updateItem.NewProperties)
{
RINOK(outArchive.WriteHeader(item));
RINOK(inStream->Seek(existItemInfo.GetDataPosition(),
STREAM_SEEK_SET, NULL));
streamSpec->SetStream(inStream);
streamSpec->Init(existItemInfo.Size);
RINOK(inStream->Seek(existItemInfo.GetDataPosition(), STREAM_SEEK_SET, NULL));
size = existItemInfo.Size;
}
else
{
RINOK(inStream->Seek(existItemInfo.HeaderPosition,
STREAM_SEEK_SET, NULL));
streamSpec->SetStream(inStream);
streamSpec->Init(existItemInfo.GetFullSize());
RINOK(inStream->Seek(existItemInfo.HeaderPosition, STREAM_SEEK_SET, NULL));
size = existItemInfo.GetFullSize();
}
RINOK(CopyBlock(inStreamLimited, outStream, compressProgress));
streamSpec->Init(size);
RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));
if (copyCoderSpec->TotalSize != size)
return E_FAIL;
RINOK(outArchive.FillDataResidual(existItemInfo.Size));
complexity += existItemInfo.GetFullSize();
complexity += size;
}
complexity += kOneItemComplexity;
}
return outArchive.WriteFinishHeader();
}
}}