From 1fbaf0aac5000ca563a1ee2bb15ba6821a08e468 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Mon, 14 Dec 2009 00:00:00 +0000 Subject: 9.09 beta --- CPP/7zip/Archive/Zip/ZipAddCommon.cpp | 60 +++++++++++++++--------- CPP/7zip/Archive/Zip/ZipAddCommon.h | 5 +- CPP/7zip/Archive/Zip/ZipCompressionMode.h | 6 +-- CPP/7zip/Archive/Zip/ZipHandler.cpp | 77 +++++++++++++++---------------- CPP/7zip/Archive/Zip/ZipHandler.h | 6 +-- CPP/7zip/Archive/Zip/ZipHandlerOut.cpp | 6 +-- CPP/7zip/Archive/Zip/ZipHeader.h | 13 ++++-- CPP/7zip/Archive/Zip/ZipOut.cpp | 19 ++++++-- CPP/7zip/Archive/Zip/ZipUpdate.cpp | 11 ++--- 9 files changed, 113 insertions(+), 90 deletions(-) (limited to 'CPP/7zip/Archive/Zip') diff --git a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp index 9157deeb..8800270b 100755 --- a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp +++ b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp @@ -102,7 +102,7 @@ static HRESULT GetStreamCRC(ISequentialInStream *inStream, UInt32 &resultCRC) HRESULT CAddCommon::Compress( DECL_EXTERNAL_CODECS_LOC_VARS ISequentialInStream *inStream, IOutStream *outStream, - ICompressProgressInfo *progress, CCompressingResult &operationResult) + ICompressProgressInfo *progress, CCompressingResult &opRes) { CSequentialInStreamWithCRC *inSecCrcStreamSpec = 0; CInStreamWithCRC *inCrcStreamSpec = 0; @@ -139,13 +139,17 @@ HRESULT CAddCommon::Compress( } Byte method = 0; COutStreamReleaser outStreamReleaser; + opRes.ExtractVersion = NFileHeader::NCompressionMethod::kExtractVersion_Default; for (int i = 0; i < numTestMethods; i++) { + opRes.ExtractVersion = NFileHeader::NCompressionMethod::kExtractVersion_Default; if (inCrcStreamSpec != 0) RINOK(inCrcStreamSpec->Seek(0, STREAM_SEEK_SET, NULL)); RINOK(outStream->Seek(0, STREAM_SEEK_SET, NULL)); if (_options.PasswordIsDefined) { + opRes.ExtractVersion = NFileHeader::NCompressionMethod::kExtractVersion_ZipCrypto; + if (!_cryptoStream) { _cryptoStreamSpec = new CFilterCoder; @@ -153,17 +157,24 @@ HRESULT CAddCommon::Compress( } if (_options.IsAesMode) { - _cryptoStreamSpec->Filter = _aesFilter = _filterAesSpec = new NCrypto::NWzAes::CEncoder; - _filterAesSpec->SetKeyMode(_options.AesKeyMode); - RINOK(_filterAesSpec->CryptoSetPassword( + opRes.ExtractVersion = NFileHeader::NCompressionMethod::kExtractVersion_Aes; + if (!_cryptoStreamSpec->Filter) + { + _cryptoStreamSpec->Filter = _filterAesSpec = new NCrypto::NWzAes::CEncoder; + _filterAesSpec->SetKeyMode(_options.AesKeyMode); + RINOK(_filterAesSpec->CryptoSetPassword( (const Byte *)(const char *)_options.Password, _options.Password.Length())); + } RINOK(_filterAesSpec->WriteHeader(outStream)); } else { - _cryptoStreamSpec->Filter = _zipCryptoFilter = _filterSpec = new NCrypto::NZip::CEncoder; - RINOK(_filterSpec->CryptoSetPassword( + if (!_cryptoStreamSpec->Filter) + { + _cryptoStreamSpec->Filter = _filterSpec = new NCrypto::NZip::CEncoder; + RINOK(_filterSpec->CryptoSetPassword( (const Byte *)(const char *)_options.Password, _options.Password.Length())); + } UInt32 crc = 0; RINOK(GetStreamCRC(inStream, crc)); RINOK(inCrcStreamSpec->Seek(0, STREAM_SEEK_SET, NULL)); @@ -190,7 +201,6 @@ HRESULT CAddCommon::Compress( else outStreamNew = outStream; RINOK(_copyCoder->Code(inCrcStream, outStreamNew, NULL, NULL, progress)); - operationResult.ExtractVersion = NFileHeader::NCompressionMethod::kStoreExtractVersion; break; } default: @@ -199,11 +209,12 @@ HRESULT CAddCommon::Compress( { if (method == NFileHeader::NCompressionMethod::kLZMA) { + _compressExtractVersion = NFileHeader::NCompressionMethod::kExtractVersion_LZMA; CLzmaEncoder *_lzmaEncoder = new CLzmaEncoder(); _compressEncoder = _lzmaEncoder; NWindows::NCOM::CPropVariant props[] = { - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST _options.NumThreads, #endif _options.Algo, @@ -214,7 +225,7 @@ HRESULT CAddCommon::Compress( }; PROPID propIDs[] = { - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST NCoderPropID::kNumThreads, #endif NCoderPropID::kAlgorithm, @@ -235,8 +246,12 @@ HRESULT CAddCommon::Compress( { case NFileHeader::NCompressionMethod::kBZip2: methodId = kMethodId_BZip2; + _compressExtractVersion = NFileHeader::NCompressionMethod::kExtractVersion_BZip2; break; default: + _compressExtractVersion = ((method == NFileHeader::NCompressionMethod::kDeflated64) ? + NFileHeader::NCompressionMethod::kExtractVersion_Deflate64 : + NFileHeader::NCompressionMethod::kExtractVersion_Deflate); methodId = kMethodId_ZipBase + method; break; } @@ -279,7 +294,7 @@ HRESULT CAddCommon::Compress( { _options.DicSize, _options.NumPasses - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST , _options.NumThreads #endif }; @@ -287,7 +302,7 @@ HRESULT CAddCommon::Compress( { NCoderPropID::kDictionarySize, NCoderPropID::kNumPasses - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST , NCoderPropID::kNumThreads #endif }; @@ -305,41 +320,42 @@ HRESULT CAddCommon::Compress( outStreamNew = _cryptoStream; else outStreamNew = outStream; + if (_compressExtractVersion > opRes.ExtractVersion) + opRes.ExtractVersion = _compressExtractVersion; RINOK(_compressEncoder->Code(inCrcStream, outStreamNew, NULL, NULL, progress)); - operationResult.ExtractVersion = NFileHeader::NCompressionMethod::kDeflateExtractVersion; break; } } - RINOK(outStream->Seek(0, STREAM_SEEK_CUR, &operationResult.PackSize)); + RINOK(outStream->Seek(0, STREAM_SEEK_CUR, &opRes.PackSize)); if (inCrcStreamSpec != 0) { - operationResult.CRC = inCrcStreamSpec->GetCRC(); - operationResult.UnpackSize = inCrcStreamSpec->GetSize(); + opRes.CRC = inCrcStreamSpec->GetCRC(); + opRes.UnpackSize = inCrcStreamSpec->GetSize(); } else { - operationResult.CRC = inSecCrcStreamSpec->GetCRC(); - operationResult.UnpackSize = inSecCrcStreamSpec->GetSize(); + opRes.CRC = inSecCrcStreamSpec->GetCRC(); + opRes.UnpackSize = inSecCrcStreamSpec->GetSize(); } if (_options.PasswordIsDefined) { - if (operationResult.PackSize < operationResult.UnpackSize + + if (opRes.PackSize < opRes.UnpackSize + (_options.IsAesMode ? _filterAesSpec->GetHeaderSize() : NCrypto::NZip::kHeaderSize)) break; } - else if (operationResult.PackSize < operationResult.UnpackSize) + else if (opRes.PackSize < opRes.UnpackSize) break; } if (_options.IsAesMode) { RINOK(_filterAesSpec->WriteFooter(outStream)); - RINOK(outStream->Seek(0, STREAM_SEEK_CUR, &operationResult.PackSize)); + RINOK(outStream->Seek(0, STREAM_SEEK_CUR, &opRes.PackSize)); } - operationResult.Method = method; - return outStream->SetSize(operationResult.PackSize); + opRes.Method = method; + return outStream->SetSize(opRes.PackSize); } }} diff --git a/CPP/7zip/Archive/Zip/ZipAddCommon.h b/CPP/7zip/Archive/Zip/ZipAddCommon.h index 8f5b568d..e4c02db3 100755 --- a/CPP/7zip/Archive/Zip/ZipAddCommon.h +++ b/CPP/7zip/Archive/Zip/ZipAddCommon.h @@ -35,6 +35,7 @@ class CAddCommon CMyComPtr _copyCoder; CMyComPtr _compressEncoder; + Byte _compressExtractVersion; CFilterCoder *_cryptoStreamSpec; CMyComPtr _cryptoStream; @@ -42,10 +43,6 @@ class CAddCommon NCrypto::NZip::CEncoder *_filterSpec; NCrypto::NWzAes::CEncoder *_filterAesSpec; - CMyComPtr _zipCryptoFilter; - CMyComPtr _aesFilter; - - public: CAddCommon(const CCompressionMethodMode &options); HRESULT Compress( diff --git a/CPP/7zip/Archive/Zip/ZipCompressionMode.h b/CPP/7zip/Archive/Zip/ZipCompressionMode.h index de5f5ccd..e5acfa6b 100755 --- a/CPP/7zip/Archive/Zip/ZipCompressionMode.h +++ b/CPP/7zip/Archive/Zip/ZipCompressionMode.h @@ -1,7 +1,7 @@ // CompressionMode.h -#ifndef __ZIP_COMPRESSIONMETHOD_H -#define __ZIP_COMPRESSIONMETHOD_H +#ifndef __ZIP_COMPRESSION_MODE_H +#define __ZIP_COMPRESSION_MODE_H #include "Common/MyString.h" @@ -18,7 +18,7 @@ struct CCompressionMethodMode bool NumMatchFinderCyclesDefined; UInt32 NumMatchFinderCycles; UInt32 DicSize; - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST UInt32 NumThreads; #endif bool PasswordIsDefined; diff --git a/CPP/7zip/Archive/Zip/ZipHandler.cpp b/CPP/7zip/Archive/Zip/ZipHandler.cpp index 2e551931..df1ca20b 100755 --- a/CPP/7zip/Archive/Zip/ZipHandler.cpp +++ b/CPP/7zip/Archive/Zip/ZipHandler.cpp @@ -63,30 +63,7 @@ static const char *kHostOS[] = static const char *kUnknownOS = "Unknown"; -STATPROPSTG kProps[] = -{ - { NULL, kpidPath, VT_BSTR}, - { NULL, kpidIsDir, VT_BOOL}, - { NULL, kpidSize, VT_UI8}, - { NULL, kpidPackSize, VT_UI8}, - { NULL, kpidMTime, VT_FILETIME}, - { NULL, kpidCTime, VT_FILETIME}, - { NULL, kpidATime, VT_FILETIME}, - - { NULL, kpidAttrib, VT_UI4}, - - { NULL, kpidEncrypted, VT_BOOL}, - { NULL, kpidComment, VT_BSTR}, - - { NULL, kpidCRC, VT_UI4}, - - { NULL, kpidMethod, VT_BSTR}, - { NULL, kpidHostOS, VT_BSTR} - - // { NULL, kpidUnpackVer, VT_UI1}, -}; - -const char *kMethods[] = +static const char *kMethods[] = { "Store", "Shrink", @@ -101,23 +78,20 @@ const char *kMethods[] = "PKImploding" }; -const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]); -const char *kBZip2Method = "BZip2"; -const char *kLZMAMethod = "LZMA"; -const char *kJpegMethod = "Jpeg"; -const char *kWavPackMethod = "WavPack"; -const char *kPPMdMethod = "PPMd"; -const char *kAESMethod = "AES"; -const char *kZipCryptoMethod = "ZipCrypto"; -const char *kStrongCryptoMethod = "StrongCrypto"; - -struct CStrongCryptoPair +static const char *kBZip2Method = "BZip2"; +static const char *kLZMAMethod = "LZMA"; +static const char *kJpegMethod = "Jpeg"; +static const char *kWavPackMethod = "WavPack"; +static const char *kPPMdMethod = "PPMd"; +static const char *kAESMethod = "AES"; +static const char *kZipCryptoMethod = "ZipCrypto"; +static const char *kStrongCryptoMethod = "StrongCrypto"; + +static struct CStrongCryptoPair { UInt16 Id; const char *Name; -}; - -CStrongCryptoPair g_StrongCryptoPairs[] = +} g_StrongCryptoPairs[] = { { NStrongCryptoFlags::kDES, "DES" }, { NStrongCryptoFlags::kRC2old, "RC2a" }, @@ -132,7 +106,25 @@ CStrongCryptoPair g_StrongCryptoPairs[] = { NStrongCryptoFlags::kRC4, "RC4" } }; -STATPROPSTG kArcProps[] = +static STATPROPSTG kProps[] = +{ + { NULL, kpidPath, VT_BSTR}, + { NULL, kpidIsDir, VT_BOOL}, + { NULL, kpidSize, VT_UI8}, + { NULL, kpidPackSize, VT_UI8}, + { NULL, kpidMTime, VT_FILETIME}, + { NULL, kpidCTime, VT_FILETIME}, + { NULL, kpidATime, VT_FILETIME}, + { NULL, kpidAttrib, VT_UI4}, + { NULL, kpidEncrypted, VT_BOOL}, + { NULL, kpidComment, VT_BSTR}, + { NULL, kpidCRC, VT_UI4}, + { NULL, kpidMethod, VT_BSTR}, + { NULL, kpidHostOS, VT_BSTR}, + { NULL, kpidUnpackVer, VT_UI4} +}; + +static STATPROPSTG kArcProps[] = { { NULL, kpidBit64, VT_BOOL}, { NULL, kpidComment, VT_BSTR} @@ -289,7 +281,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val method += ' '; } } - if (methodId < kNumMethods) + if (methodId < sizeof(kMethods) / sizeof(kMethods[0])) method += kMethods[methodId]; else switch (methodId) { @@ -316,6 +308,9 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val prop = (item.MadeByVersion.HostOS < sizeof(kHostOS) / sizeof(kHostOS[0])) ? (kHostOS[item.MadeByVersion.HostOS]) : kUnknownOS; break; + case kpidUnpackVer: + prop = (UInt32)item.ExtractVersion.Version; + break; } prop.Detach(value); return S_OK; @@ -637,7 +632,7 @@ HRESULT CZipDecoder::Decode( } } - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST { CMyComPtr setCoderMt; coder->QueryInterface(IID_ICompressSetCoderMt, (void **)&setCoderMt); diff --git a/CPP/7zip/Archive/Zip/ZipHandler.h b/CPP/7zip/Archive/Zip/ZipHandler.h index 1a3a441a..6236b20c 100755 --- a/CPP/7zip/Archive/Zip/ZipHandler.h +++ b/CPP/7zip/Archive/Zip/ZipHandler.h @@ -12,7 +12,7 @@ #include "ZipIn.h" #include "ZipCompressionMode.h" -#ifdef COMPRESS_MT +#ifndef _7ZIP_ST #include "../../../Windows/System.h" #endif @@ -63,7 +63,7 @@ private: bool m_ForseLocal; bool m_ForseUtf8; - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST UInt32 _numThreads; #endif @@ -85,7 +85,7 @@ private: m_WriteNtfsTimeExtra = false; m_ForseLocal = false; m_ForseUtf8 = false; - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST _numThreads = NWindows::NSystem::GetNumberOfProcessors();; #endif } diff --git a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp index 22d8eeea..3571fdeb 100755 --- a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp +++ b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp @@ -297,7 +297,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt options.NumMatchFinderCycles = m_NumMatchFinderCycles; options.NumMatchFinderCyclesDefined = m_NumMatchFinderCyclesDefined; options.Algo = m_Algo; - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST options.NumThreads = _numThreads; #endif if (isLz) @@ -357,7 +357,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) { - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST const UInt32 numProcessors = NSystem::GetNumberOfProcessors(); _numThreads = numProcessors; #endif @@ -467,7 +467,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v } else if (name.Left(2) == L"MT") { - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST RINOK(ParseMtProp(name.Mid(2), prop, numProcessors, _numThreads)); #endif } diff --git a/CPP/7zip/Archive/Zip/ZipHeader.h b/CPP/7zip/Archive/Zip/ZipHeader.h index 4839f554..1233af6c 100755 --- a/CPP/7zip/Archive/Zip/ZipHeader.h +++ b/CPP/7zip/Archive/Zip/ZipHeader.h @@ -80,10 +80,17 @@ namespace NFileHeader const int kNumCompressionMethods = 11; const Byte kMadeByProgramVersion = 20; - const Byte kDeflateExtractVersion = 20; - const Byte kStoreExtractVersion = 10; + const Byte kExtractVersion_Default = 10; + const Byte kExtractVersion_Dir = 20; + const Byte kExtractVersion_ZipCrypto = 20; + const Byte kExtractVersion_Deflate = 20; + const Byte kExtractVersion_Deflate64 = 21; + const Byte kExtractVersion_Zip64 = 45; + const Byte kExtractVersion_BZip2 = 46; + const Byte kExtractVersion_Aes = 51; + const Byte kExtractVersion_LZMA = 63; - const Byte kSupportedVersion = 20; + // const Byte kSupportedVersion = 20; } namespace NExtraID diff --git a/CPP/7zip/Archive/Zip/ZipOut.cpp b/CPP/7zip/Archive/Zip/ZipOut.cpp index 5b1bdeee..0807369c 100755 --- a/CPP/7zip/Archive/Zip/ZipOut.cpp +++ b/CPP/7zip/Archive/Zip/ZipOut.cpp @@ -2,10 +2,9 @@ #include "StdAfx.h" -#include "ZipOut.h" -#include "Common/StringConvert.h" #include "../../Common/OffsetStream.h" -#include "../../Common/StreamUtils.h" + +#include "ZipOut.h" namespace NArchive { namespace NZip { @@ -115,7 +114,12 @@ void COutArchive::WriteLocalHeader(const CLocalItem &item) bool isZip64 = m_IsZip64 || item.PackSize >= 0xFFFFFFFF || item.UnPackSize >= 0xFFFFFFFF; WriteUInt32(NSignature::kLocalFileHeader); - WriteByte(item.ExtractVersion.Version); + { + Byte ver = item.ExtractVersion.Version; + if (isZip64 && ver < NFileHeader::NCompressionMethod::kExtractVersion_Zip64) + ver = NFileHeader::NCompressionMethod::kExtractVersion_Zip64; + WriteByte(ver); + } WriteByte(item.ExtractVersion.HostOS); WriteUInt16(item.Flags); WriteUInt16(item.CompressionMethod); @@ -162,7 +166,12 @@ void COutArchive::WriteCentralHeader(const CItem &item) WriteUInt32(NSignature::kCentralFileHeader); WriteByte(item.MadeByVersion.Version); WriteByte(item.MadeByVersion.HostOS); - WriteByte(item.ExtractVersion.Version); + { + Byte ver = item.ExtractVersion.Version; + if (isZip64 && ver < NFileHeader::NCompressionMethod::kExtractVersion_Zip64) + ver = NFileHeader::NCompressionMethod::kExtractVersion_Zip64; + WriteByte(ver); + } WriteByte(item.ExtractVersion.HostOS); WriteUInt16(item.Flags); WriteUInt16(item.CompressionMethod); diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp index 056a8cd2..004e67f8 100755 --- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp +++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp @@ -13,7 +13,7 @@ #include "../../Common/LimitedStreams.h" #include "../../Common/OutMemStream.h" #include "../../Common/ProgressUtils.h" -#ifdef COMPRESS_MT +#ifndef _7ZIP_ST #include "../../Common/ProgressMt.h" #endif @@ -40,7 +40,6 @@ static const Byte kMadeByHostOS = kHostOS; static const Byte kExtractHostOS = kHostOS; static const Byte kMethodForDirectory = NFileHeader::NCompressionMethod::kStored; -static const Byte kExtractVersionForDirectory = NFileHeader::NCompressionMethod::kStoreExtractVersion; static HRESULT CopyBlockToArchive(ISequentialInStream *inStream, COutArchive &outArchive, ICompressProgressInfo *progress) @@ -101,7 +100,7 @@ static void SetFileHeader( item.SetEncrypted(!isDir && options.PasswordIsDefined); if (isDir) { - item.ExtractVersion.Version = kExtractVersionForDirectory; + item.ExtractVersion.Version = NFileHeader::NCompressionMethod::kExtractVersion_Dir; item.CompressionMethod = kMethodForDirectory; item.PackSize = 0; item.FileCRC = 0; // test it @@ -134,7 +133,7 @@ static void SetItemInfoFromCompressingResult(const CCompressingResult &compressi } } -#ifdef COMPRESS_MT +#ifndef _7ZIP_ST static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo); @@ -525,7 +524,7 @@ static HRESULT Update2( complexity = 0; - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST const size_t kNumMaxThreads = (1 << 10); UInt32 numThreads = options->NumThreads; @@ -584,7 +583,7 @@ static HRESULT Update2( inputItems, updateItems, options, comment, updateCallback); - #ifdef COMPRESS_MT + #ifndef _7ZIP_ST CObjectVector items; -- cgit v1.2.3