9.09 beta

This commit is contained in:
Igor Pavlov
2009-12-14 00:00:00 +00:00
committed by Kornel Lesiński
parent 2fed872194
commit 1fbaf0aac5
179 changed files with 3365 additions and 2136 deletions

View File

@@ -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);
}
}}

View File

@@ -35,6 +35,7 @@ class CAddCommon
CMyComPtr<ICompressCoder> _copyCoder;
CMyComPtr<ICompressCoder> _compressEncoder;
Byte _compressExtractVersion;
CFilterCoder *_cryptoStreamSpec;
CMyComPtr<ISequentialOutStream> _cryptoStream;
@@ -42,10 +43,6 @@ class CAddCommon
NCrypto::NZip::CEncoder *_filterSpec;
NCrypto::NWzAes::CEncoder *_filterAesSpec;
CMyComPtr<ICompressFilter> _zipCryptoFilter;
CMyComPtr<ICompressFilter> _aesFilter;
public:
CAddCommon(const CCompressionMethodMode &options);
HRESULT Compress(

View File

@@ -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;

View File

@@ -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";
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";
struct CStrongCryptoPair
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<ICompressSetCoderMt> setCoderMt;
coder->QueryInterface(IID_ICompressSetCoderMt, (void **)&setCoderMt);

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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<CItem> items;