Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Archive/Zip/ZipUpdate.cpp')
-rw-r--r--CPP/7zip/Archive/Zip/ZipUpdate.cpp80
1 files changed, 66 insertions, 14 deletions
diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
index 97cce5ac..9a9526cc 100644
--- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp
+++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
@@ -65,6 +65,7 @@ static void SetFileHeader(
COutArchive &archive,
const CCompressionMethodMode &options,
const CUpdateItem &ui,
+ // bool isSeqMode,
CItemOut &item)
{
item.Size = ui.Size;
@@ -95,6 +96,8 @@ static void SetFileHeader(
item.InternalAttrib = 0; // test it
item.SetEncrypted(!isDir && options.PasswordIsDefined);
+ // item.SetDescriptorMode(isSeqMode);
+
if (isDir)
{
item.ExtractVersion.Version = NFileHeader::NCompressionMethod::kExtractVersion_Dir;
@@ -156,12 +159,14 @@ struct CThreadInfo
bool IsFree;
UInt32 UpdateIndex;
+ UInt32 FileTime;
CThreadInfo(const CCompressionMethodMode &options):
ExitThread(false),
ProgressSpec(0),
OutStreamSpec(0),
- Coder(options)
+ Coder(options),
+ FileTime(0)
{}
HRESULT CreateEvents()
@@ -192,9 +197,11 @@ void CThreadInfo::WaitAndCode()
CompressEvent.Lock();
if (ExitThread)
return;
+
Result = Coder.Compress(
EXTERNAL_CODECS_LOC_VARS
- InStream, OutStream, Progress, CompressingResult);
+ InStream, OutStream, FileTime, Progress, CompressingResult);
+
if (Result == S_OK && Progress)
Result = Progress->SetRatioInfo(&CompressingResult.UnpackSize, &CompressingResult.PackSize);
CompressionCompletedEvent.Set();
@@ -254,7 +261,7 @@ public:
MY_UNKNOWN_IMP
void Create(IProgress *progress, bool inSizeIsMain);
void SetProgressOffset(UInt64 progressOffset);
- HRESULT SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize);
+ HRESULT SetRatioInfo(unsigned index, const UInt64 *inSize, const UInt64 *outSize);
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
};
@@ -274,16 +281,16 @@ void CMtProgressMixer2::SetProgressOffset(UInt64 progressOffset)
CriticalSection.Leave();
}
-HRESULT CMtProgressMixer2::SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize)
+HRESULT CMtProgressMixer2::SetRatioInfo(unsigned index, const UInt64 *inSize, const UInt64 *outSize)
{
NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection);
if (index == 0 && RatioProgress)
{
RINOK(RatioProgress->SetRatioInfo(inSize, outSize));
}
- if (inSize != 0)
+ if (inSize)
InSizes[index] = *inSize;
- if (outSize != 0)
+ if (outSize)
OutSizes[index] = *outSize;
UInt64 v = ProgressOffset + (_inSizeIsMain ?
(InSizes[0] + InSizes[1]) :
@@ -332,8 +339,16 @@ static HRESULT UpdateItemOldData(
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())
@@ -396,7 +411,8 @@ static HRESULT Update2St(
const CObjectVector<CUpdateItem> &updateItems,
const CCompressionMethodMode *options,
const CByteBuffer *comment,
- IArchiveUpdateCallback *updateCallback)
+ IArchiveUpdateCallback *updateCallback,
+ IArchiveUpdateCallbackFile *opCallback)
{
CLocalProgress *lps = new CLocalProgress;
CMyComPtr<ICompressProgressInfo> progress = lps;
@@ -445,15 +461,37 @@ static HRESULT Update2St(
if (!fileInStream)
return E_INVALIDARG;
+ // bool isSeqMode = false;
+ /*
+ {
+ CMyComPtr<IInStream> inStream2;
+ fileInStream->QueryInterface(IID_IInStream, (void **)&inStream2);
+ isSeqMode = (inStream2 == NULL);
+ }
+ */
+
// file Size can be 64-bit !!!
SetFileHeader(archive, *options, ui, item);
archive.PrepareWriteCompressedData(item.Name.Len(), ui.Size, options->IsRealAesMode());
CCompressingResult compressingResult;
CMyComPtr<IOutStream> outStream;
archive.CreateStreamForCompressing(&outStream);
+
RINOK(compressor.Compress(
EXTERNAL_CODECS_LOC_VARS
- fileInStream, outStream, progress, compressingResult));
+ fileInStream, outStream,
+ ui.Time,
+ progress, compressingResult));
+
+ if (compressingResult.FileTimeWasUsed)
+ {
+ /*
+ if (!item.HasDescriptor())
+ return E_FAIL;
+ */
+ item.SetDescriptorMode(true);
+ }
+
SetItemInfoFromCompressingResult(compressingResult, options->IsRealAesMode(), options->AesKeyMode, item);
archive.WriteLocalHeader_And_SeekToNextFile(item);
RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
@@ -465,13 +503,14 @@ static HRESULT Update2St(
{
UInt64 complexity = 0;
lps->SendRatio = false;
- RINOK(UpdateItemOldData(archive, inArchive, itemEx, ui, item, progress, complexity));
+ RINOK(UpdateItemOldData(archive, inArchive, itemEx, ui, item, progress, opCallback, complexity));
lps->SendRatio = true;
lps->ProgressOffset += complexity;
}
items.Add(item);
lps->ProgressOffset += kLocalHeaderSize;
}
+
lps->InSize = unpackSizeTotal;
lps->OutSize = packSizeTotal;
RINOK(lps->SetCur());
@@ -489,6 +528,9 @@ static HRESULT Update2(
const CByteBuffer *comment,
IArchiveUpdateCallback *updateCallback)
{
+ CMyComPtr<IArchiveUpdateCallbackFile> opCallback;
+ updateCallback->QueryInterface(IID_IArchiveUpdateCallbackFile, (void **)&opCallback);
+
UInt64 complexity = 0;
UInt64 numFilesToCompress = 0;
UInt64 numBytesToCompress = 0;
@@ -542,6 +584,7 @@ static HRESULT Update2(
numThreads = MAXIMUM_WAIT_OBJECTS;
if (numThreads < 1)
numThreads = 1;
+
const size_t kMemPerThread = (1 << 25);
const size_t kBlockSize = 1 << 16;
@@ -558,7 +601,7 @@ static HRESULT Update2(
{
// fixed for 9.31. bzip2 default is just one thread.
if (options2.NumThreadsWasChanged || method == NFileHeader::NCompressionMethod::kBZip2)
- options2.MethodInfo.AddNumThreadsProp(numThreads);
+ options2.MethodInfo.AddProp_NumThreads(numThreads);
}
}
else
@@ -577,7 +620,7 @@ static HRESULT Update2(
numBZip2Threads = 32;
if (averageNumberOfBlocks < numBZip2Threads)
numBZip2Threads = (UInt32)averageNumberOfBlocks;
- options2.MethodInfo.AddNumThreadsProp(numBZip2Threads);
+ options2.MethodInfo.AddProp_NumThreads(numBZip2Threads);
}
numThreads /= numBZip2Threads;
}
@@ -599,7 +642,7 @@ static HRESULT Update2(
return Update2St(
EXTERNAL_CODECS_LOC_VARS
archive, inArchive,
- inputItems, updateItems, &options2, comment, updateCallback);
+ inputItems, updateItems, &options2, comment, updateCallback, opCallback);
#ifndef _7ZIP_ST
@@ -643,6 +686,7 @@ static HRESULT Update2(
threadInfo.ProgressSpec = new CMtCompressProgress();
threadInfo.Progress = threadInfo.ProgressSpec;
threadInfo.ProgressSpec->Init(&mtCompressProgressMixer, (int)i);
+ threadInfo.FileTime = 0; // fix it !
RINOK(threadInfo.CreateThread());
}
}
@@ -784,7 +828,15 @@ static HRESULT Update2(
DWORD result = ::WaitForMultipleObjects(compressingCompletedEvents.Size(),
&compressingCompletedEvents.Front(), FALSE, INFINITE);
- int t = (int)(result - WAIT_OBJECT_0);
+ if (result == WAIT_FAILED)
+ {
+ DWORD lastError = GetLastError();
+ return lastError != 0 ? lastError : E_FAIL;
+ }
+ unsigned t = (unsigned)(result - WAIT_OBJECT_0);
+ if (t >= compressingCompletedEvents.Size())
+ return E_FAIL;
+
CThreadInfo &threadInfo = threads.Threads[threadIndices[t]];
threadInfo.InStream.Release();
threadInfo.IsFree = true;
@@ -813,7 +865,7 @@ static HRESULT Update2(
}
else
{
- RINOK(UpdateItemOldData(archive, inArchive, itemEx, ui, item, progress, complexity));
+ RINOK(UpdateItemOldData(archive, inArchive, itemEx, ui, item, progress, opCallback, complexity));
}
items.Add(item);
complexity += kLocalHeaderSize;