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

@@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /YX /FD /c
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "COMPRESS_MT" /D "EXTERNAL_CODECS" /Yu"StdAfx.h" /FD /c
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "EXTERNAL_CODECS" /Yu"StdAfx.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
@@ -70,7 +70,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "COMPRESS_MT" /D "EXTERNAL_CODECS" /Yu"StdAfx.h" /FD /GZ /c
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MY7Z_EXPORTS" /D "EXTERNAL_CODECS" /Yu"StdAfx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG"
@@ -619,6 +619,11 @@ SOURCE=..\..\..\..\C\7zCrc.h
# End Source File
# Begin Source File
SOURCE=..\..\..\..\C\7zCrcOpt.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
SOURCE=..\..\..\..\C\Alloc.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
@@ -628,6 +633,11 @@ SOURCE=..\..\..\..\C\Alloc.h
# End Source File
# Begin Source File
SOURCE=..\..\..\..\C\CpuArch.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File
# Begin Source File
SOURCE=..\..\..\..\C\Threads.c
# SUBTRACT CPP /YX /Yc /Yu
# End Source File

View File

@@ -31,7 +31,7 @@ struct CCompressionMethodMode
{
CObjectVector<CMethodFull> Methods;
CRecordVector<CBind> Binds;
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
UInt32 NumThreads;
#endif
bool PasswordIsDefined;
@@ -39,7 +39,7 @@ struct CCompressionMethodMode
bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }
CCompressionMethodMode(): PasswordIsDefined(false)
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, NumThreads(1)
#endif
{}

View File

@@ -97,7 +97,7 @@ HRESULT CDecoder::Decode(
#ifndef _NO_CRYPTO
, ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
#endif
#ifdef COMPRESS_MT
#if !defined(_7ZIP_ST) && !defined(_SFX)
, bool mtMode, UInt32 numThreads
#endif
)
@@ -239,7 +239,7 @@ HRESULT CDecoder::Decode(
}
}
#ifdef COMPRESS_MT
#if !defined(_7ZIP_ST) && !defined(_SFX)
if (mtMode)
{
CMyComPtr<ICompressSetCoderMt> setCoderMt;

View File

@@ -57,7 +57,7 @@ public:
#ifndef _NO_CRYPTO
, ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined
#endif
#ifdef COMPRESS_MT
#if !defined(_7ZIP_ST) && !defined(_SFX)
, bool mtMode, UInt32 numThreads
#endif
);

View File

@@ -15,7 +15,6 @@
static const UInt64 k_Delta = 0x03;
static const UInt64 k_BCJ = 0x03030103;
static const UInt64 k_BCJ2 = 0x0303011B;
static const UInt64 k_AES = 0x06F10701;
namespace NArchive {
namespace N7z {
@@ -76,7 +75,7 @@ HRESULT CEncoder::CreateMixerCoder(
CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
{
CMyComPtr<ICompressSetCoderMt> setCoderMt;
encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);

View File

@@ -237,7 +237,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
#ifndef _NO_CRYPTO
, getTextPassword, passwordIsDefined
#endif
#ifdef COMPRESS_MT
#if !defined(_7ZIP_ST) && !defined(_SFX)
, true, _numThreads
#endif
);

View File

@@ -7,7 +7,7 @@
#include "../../../Common/ComTry.h"
#include "../../../Common/IntToString.h"
#ifdef COMPRESS_MT
#ifndef __7Z_SET_PROPERTIES
#include "../../../Windows/System.h"
#endif
@@ -38,7 +38,7 @@ CHandler::CHandler()
#endif
#ifdef EXTRACT_ONLY
#ifdef COMPRESS_MT
#ifdef __7Z_SET_PROPERTIES
_numThreads = NSystem::GetNumberOfProcessors();
#endif
#else
@@ -190,18 +190,11 @@ static inline void AddHexToString(UString &res, Byte value)
#endif
static const UInt64 k_AES = 0x06F10701;
bool CHandler::IsEncrypted(UInt32 index2) const
{
CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
if (folderIndex != kNumNoIndex)
{
const CFolder &folderInfo = _db.Folders[folderIndex];
for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)
if (folderInfo.Coders[i].MethodID == k_AES)
return true;
}
return _db.Folders[folderIndex].IsEncrypted();
return false;
}
@@ -454,10 +447,8 @@ STDMETHODIMP CHandler::Close()
STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)
{
COM_TRY_BEGIN
#ifdef COMPRESS_MT
const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
_numThreads = numProcessors;
#endif
for (int i = 0; i < numProperties; i++)
{
@@ -472,9 +463,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
{
if(name.Left(2).CompareNoCase(L"MT") == 0)
{
#ifdef COMPRESS_MT
RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));
#endif
continue;
}
else

View File

@@ -21,7 +21,7 @@ namespace N7z {
#ifndef __7Z_SET_PROPERTIES
#ifdef EXTRACT_ONLY
#ifdef COMPRESS_MT
#if !defined(_7ZIP_ST) && !defined(_SFX)
#define __7Z_SET_PROPERTIES
#endif
#else
@@ -80,7 +80,7 @@ private:
#ifdef EXTRACT_ONLY
#ifdef COMPRESS_MT
#ifdef __7Z_SET_PROPERTIES
UInt32 _numThreads;
#endif
@@ -92,7 +92,7 @@ private:
HRESULT SetCompressionMethod(CCompressionMethodMode &method,
CObjectVector<COneMethodInfo> &methodsInfo
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, UInt32 numThreads
#endif
);

View File

@@ -51,7 +51,7 @@ HRESULT CHandler::SetCompressionMethod(
CCompressionMethodMode &headerMethod)
{
HRESULT res = SetCompressionMethod(methodMode, _methods
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, _numThreads
#endif
);
@@ -91,8 +91,8 @@ HRESULT CHandler::SetCompressionMethod(
}
headerMethodInfoVector.Add(oneMethodInfo);
HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector
#ifdef COMPRESS_MT
,1
#ifndef _7ZIP_ST
, 1
#endif
);
RINOK(res);
@@ -103,7 +103,7 @@ HRESULT CHandler::SetCompressionMethod(
HRESULT CHandler::SetCompressionMethod(
CCompressionMethodMode &methodMode,
CObjectVector<COneMethodInfo> &methodsInfo
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, UInt32 numThreads
#endif
)
@@ -122,7 +122,7 @@ HRESULT CHandler::SetCompressionMethod(
{
COneMethodInfo &oneMethodInfo = methodsInfo[i];
SetCompressionMethod2(oneMethodInfo
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, numThreads
#endif
);
@@ -327,7 +327,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
CCompressionMethodMode methodMode, headerMethod;
RINOK(SetCompressionMethod(methodMode, headerMethod));
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
methodMode.NumThreads = _numThreads;
headerMethod.NumThreads = 1;
#endif

View File

@@ -823,7 +823,7 @@ HRESULT CInArchive::ReadAndDecodePackedStreams(
#ifndef _NO_CRYPTO
, getTextPassword, passwordIsDefined
#endif
#ifdef COMPRESS_MT
#if !defined(_7ZIP_ST) && !defined(_SFX)
, false, 1
#endif
);

View File

@@ -13,6 +13,8 @@
namespace NArchive {
namespace N7z {
const UInt64 k_AES = 0x06F10701;
typedef UInt32 CNum;
const CNum kNumMax = 0x7FFFFFFF;
const CNum kNumNoIndex = 0xFFFFFFFF;
@@ -83,6 +85,14 @@ struct CFolder
return -1;
}
bool IsEncrypted() const
{
for (int i = Coders.Size() - 1; i >= 0; i--)
if (Coders[i].MethodID == k_AES)
return true;
return false;
}
bool CheckStructure() const;
};

View File

@@ -502,9 +502,11 @@ void COutArchive::SkipAlign(unsigned pos, unsigned alignSize)
}
*/
static inline unsigned Bv_GetSizeInBytes(const CBoolVector &v) { return ((unsigned)v.Size() + 7) / 8; }
void COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize)
{
const UInt64 bvSize = (numDefined == v.Size()) ? 0 : (v.Size() + 7) / 8;
const unsigned bvSize = (numDefined == v.Size()) ? 0 : Bv_GetSizeInBytes(v);
const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2;
SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize);
@@ -631,7 +633,7 @@ void COutArchive::WriteHeader(
if (numEmptyStreams > 0)
{
WriteByte(NID::kEmptyStream);
WriteNumber((emptyStreamVector.Size() + 7) / 8);
WriteNumber(Bv_GetSizeInBytes(emptyStreamVector));
WriteBoolVector(emptyStreamVector);
CBoolVector emptyFileVector, antiVector;
@@ -656,14 +658,14 @@ void COutArchive::WriteHeader(
if (numEmptyFiles > 0)
{
WriteByte(NID::kEmptyFile);
WriteNumber((emptyFileVector.Size() + 7) / 8);
WriteNumber(Bv_GetSizeInBytes(emptyFileVector));
WriteBoolVector(emptyFileVector);
}
if (numAntiItems > 0)
{
WriteByte(NID::kAnti);
WriteNumber((antiVector.Size() + 7) / 8);
WriteNumber(Bv_GetSizeInBytes(antiVector));
WriteBoolVector(antiVector);
}
}

View File

@@ -15,4 +15,4 @@ static IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler; }
static CArcInfo g_ArcInfo =
{ L"7z", L"7z", 0, 7, {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };
REGISTER_ARC_DEC_SIG(7z)
REGISTER_ARC(7z)

View File

@@ -27,7 +27,6 @@ namespace N7z {
static const UInt64 k_LZMA = 0x030101;
static const UInt64 k_BCJ = 0x03030103;
static const UInt64 k_BCJ2 = 0x0303011B;
static const UInt64 k_AES = 0x06F10701;
static const wchar_t *kMatchFinderForBCJ2_LZMA = L"BT2";
static const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;
@@ -580,7 +579,7 @@ public:
DECL_EXTERNAL_CODECS_VARS
CDecoder Decoder;
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
bool MtMode;
UInt32 NumThreads;
#endif
@@ -588,7 +587,7 @@ public:
CThreadDecoder():
Decoder(true)
{
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
MtMode = false;
NumThreads = 1;
#endif
@@ -617,7 +616,7 @@ void CThreadDecoder::Execute()
#ifndef _NO_CRYPTO
, GetTextPassword, passwordIsDefined
#endif
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, MtMode, NumThreads
#endif
);
@@ -642,17 +641,6 @@ bool static Is86FilteredFolder(const CFolder &f)
return false;
}
bool static IsEncryptedFolder(const CFolder &f)
{
for (int i = 0; i < f.Coders.Size(); i++)
{
CMethodId m = f.Coders[i].MethodID;
if (m == k_AES)
return true;
}
return false;
}
#ifndef _NO_CRYPTO
class CCryptoGetTextPassword:
@@ -760,7 +748,7 @@ HRESULT Update(
rep.FolderIndex = i;
rep.NumCopyFiles = numCopyItems;
const CFolder &f = db->Folders[i];
bool isEncrypted = IsEncryptedFolder(f);
bool isEncrypted = f.IsEncrypted();
rep.Group = GetGroupIndex(isEncrypted, Is86FilteredFolder(f));
folderRefs.Add(rep);
if (numCopyItems == numUnpackStreams)

View File

@@ -1,7 +1,6 @@
PROG = 7z.dll
DEF_FILE = ../Archive.def
CFLAGS = $(CFLAGS) -I ../../../ \
-DCOMPRESS_MT \
-DEXTERNAL_CODECS \
AR_OBJS = \
@@ -71,9 +70,10 @@ AR_COMMON_OBJS = \
C_OBJS = \
$O\Alloc.obj \
$O\CpuArch.obj \
$O\Threads.obj \
!include "../../Crc2.mak"
!include "../../Crc.mak"
OBJS = \
$O\StdAfx.obj \
@@ -85,7 +85,7 @@ OBJS = \
$(AR_COMMON_OBJS) \
$O\CopyCoder.obj \
$(C_OBJS) \
$(CRC_OBJS) \
$(ASM_OBJS) \
$O\resource.res
!include "../../../Build.mak"
@@ -106,4 +106,5 @@ $O\CopyCoder.obj: ../../Compress/$(*B).cpp
$(COMPL)
$(C_OBJS): ../../../../C/$(*B).c
$(COMPL_O2)
!include "../../Crc.mak"
!include "../../Asm.mak"

356
CPP/7zip/Archive/ApmHandler.cpp Executable file
View File

@@ -0,0 +1,356 @@
// ApmHandler.cpp
#include "StdAfx.h"
#include "../../../C/CpuArch.h"
#include "Common/ComTry.h"
#include "Common/IntToString.h"
#include "Common/MyString.h"
#include "Windows/PropVariant.h"
#include "../Common/LimitedStreams.h"
#include "../Common/ProgressUtils.h"
#include "../Common/RegisterArc.h"
#include "../Common/StreamUtils.h"
#include "../Compress/CopyCoder.h"
#define Get16(p) GetBe16(p)
#define Get32(p) GetBe32(p)
using namespace NWindows;
namespace NArchive {
namespace NApm {
struct CItem
{
UInt32 StartBlock;
UInt32 NumBlocks;
char Name[32];
char Type[32];
/*
UInt32 DataStartBlock;
UInt32 NumDataBlocks;
UInt32 Status;
UInt32 BootStartBlock;
UInt32 BootSize;
UInt32 BootAddr;
UInt32 BootEntry;
UInt32 BootChecksum;
char Processor[16];
*/
bool Parse(const Byte *p, UInt32 &numBlocksInMap)
{
if (p[0] != 0x50 || p[1] != 0x4D || p[2] != 0 || p[3] != 0)
return false;
numBlocksInMap = Get32(p + 4);
StartBlock = Get32(p + 8);
NumBlocks = Get32(p + 0xC);
memcpy(Name, p + 0x10, 32);
memcpy(Type, p + 0x30, 32);
/*
DataStartBlock = Get32(p + 0x50);
NumDataBlocks = Get32(p + 0x54);
Status = Get32(p + 0x58);
BootStartBlock = Get32(p + 0x5C);
BootSize = Get32(p + 0x60);
BootAddr = Get32(p + 0x64);
if (Get32(p + 0x68) != 0)
return false;
BootEntry = Get32(p + 0x6C);
if (Get32(p + 0x70) != 0)
return false;
BootChecksum = Get32(p + 0x74);
memcpy(Processor, p + 0x78, 16);
*/
return true;
}
};
class CHandler:
public IInArchive,
public IInArchiveGetStream,
public CMyUnknownImp
{
CMyComPtr<IInStream> _stream;
CRecordVector<CItem> _items;
int _blockSizeLog;
UInt32 _numBlocks;
HRESULT ReadTables(IInStream *stream);
UInt64 BlocksToBytes(UInt32 i) const { return (UInt64)i << _blockSizeLog; }
UInt64 GetItemSize(const CItem &item) { return BlocksToBytes(item.NumBlocks); }
public:
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
INTERFACE_IInArchive(;)
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
};
static inline int GetLog(UInt32 num)
{
for (int i = 0; i < 31; i++)
if (((UInt32)1 << i) == num)
return i;
return -1;
}
HRESULT CHandler::ReadTables(IInStream *stream)
{
const UInt32 kSectorSize = 512;
Byte buf[kSectorSize];
{
RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
if (buf[0] != 0x45 || buf[1] != 0x52)
return S_FALSE;
_blockSizeLog = GetLog(Get16(buf + 2));
if (_blockSizeLog < 9 || _blockSizeLog > 14)
return S_FALSE;
_numBlocks = Get32(buf + 4);
for (int i = 8; i < 16; i++)
if (buf[i] != 0)
return S_FALSE;
}
unsigned numSkips = (unsigned)1 << (_blockSizeLog - 9);
for (unsigned j = 1; j < numSkips; j++)
{
RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
}
UInt32 numBlocksInMap = 0;
for (unsigned i = 0;;)
{
RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
CItem item;
UInt32 numBlocksInMap2;
if (!item.Parse(buf, numBlocksInMap2))
return S_FALSE;
if (i == 0)
{
numBlocksInMap = numBlocksInMap2;
if (numBlocksInMap > (1 << 8))
return S_FALSE;
}
else if (numBlocksInMap2 != numBlocksInMap)
return S_FALSE;
UInt32 finish = item.StartBlock + item.NumBlocks;
if (finish < item.StartBlock)
return S_FALSE;
_numBlocks = MyMax(_numBlocks, finish);
_items.Add(item);
for (unsigned j = 1; j < numSkips; j++)
{
RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
}
if (++i == numBlocksInMap)
break;
}
return S_OK;
}
STDMETHODIMP CHandler::Open(IInStream *stream,
const UInt64 * /* maxCheckStartPosition */,
IArchiveOpenCallback * /* openArchiveCallback */)
{
COM_TRY_BEGIN
Close();
RINOK(ReadTables(stream));
_stream = stream;
return S_OK;
COM_TRY_END
}
STDMETHODIMP CHandler::Close()
{
_items.Clear();
_stream.Release();
return S_OK;
}
STATPROPSTG kProps[] =
{
{ NULL, kpidPath, VT_BSTR},
{ NULL, kpidSize, VT_UI8},
{ NULL, kpidOffset, VT_UI8}
};
STATPROPSTG kArcProps[] =
{
{ NULL, kpidClusterSize, VT_UI4},
{ NULL, kpidPhySize, VT_UI8}
};
IMP_IInArchive_Props
IMP_IInArchive_ArcProps
static AString GetString(const char *s)
{
AString res;
for (int i = 0; i < 32 && s[i] != 0; i++)
res += s[i];
return res;
}
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
switch(propID)
{
case kpidMainSubfile:
{
int mainIndex = -1;
for (int i = 0; i < _items.Size(); i++)
{
AString s = GetString(_items[i].Type);
if (s != "Apple_Free" &&
s != "Apple_partition_map")
{
if (mainIndex >= 0)
{
mainIndex = -1;
break;
}
mainIndex = i;
}
}
if (mainIndex >= 0)
prop = (UInt32)mainIndex;
break;
}
case kpidClusterSize: prop = (UInt32)1 << _blockSizeLog; break;
case kpidPhySize: prop = BlocksToBytes(_numBlocks); break;
}
prop.Detach(value);
return S_OK;
COM_TRY_END
}
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
{
*numItems = _items.Size();
return S_OK;
}
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
const CItem &item = _items[index];
switch(propID)
{
case kpidPath:
{
AString s = GetString(item.Name);
if (s.IsEmpty())
{
char s2[32];
ConvertUInt32ToString(index, s2);
s = s2;
}
AString type = GetString(item.Type);
if (type == "Apple_HFS")
type = "hfs";
if (!type.IsEmpty())
{
s += '.';
s += type;
}
prop = s;
break;
}
case kpidSize:
case kpidPackSize:
prop = GetItemSize(item);
break;
case kpidOffset: prop = BlocksToBytes(item.StartBlock); break;
}
prop.Detach(value);
return S_OK;
COM_TRY_END
}
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback)
{
COM_TRY_BEGIN
bool allFilesMode = (numItems == (UInt32)-1);
if (allFilesMode)
numItems = _items.Size();
if (numItems == 0)
return S_OK;
UInt64 totalSize = 0;
UInt32 i;
for (i = 0; i < numItems; i++)
totalSize += GetItemSize(_items[allFilesMode ? i : indices[i]]);
extractCallback->SetTotal(totalSize);
totalSize = 0;
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++)
{
lps->InSize = totalSize;
lps->OutSize = totalSize;
RINOK(lps->SetCur());
CMyComPtr<ISequentialOutStream> outStream;
Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
Int32 index = allFilesMode ? i : indices[i];
const CItem &item = _items[index];
RINOK(extractCallback->GetStream(index, &outStream, askMode));
UInt64 size = GetItemSize(item);
totalSize += size;
if (!testMode && !outStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(_stream->Seek(BlocksToBytes(item.StartBlock), STREAM_SEEK_SET, NULL));
streamSpec->Init(size);
RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
outStream.Release();
RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == size ?
NExtract::NOperationResult::kOK:
NExtract::NOperationResult::kDataError));
}
return S_OK;
COM_TRY_END
}
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
{
COM_TRY_BEGIN
const CItem &item = _items[index];
return CreateLimitedInStream(_stream, BlocksToBytes(item.StartBlock), GetItemSize(item), stream);
COM_TRY_END
}
static IInArchive *CreateArc() { return new CHandler; }
static CArcInfo g_ArcInfo =
{ L"APM", L"", 0, 0xD4, { 0x50, 0x4D, 0, 0, 0, 0, 0 }, 7, false, CreateArc, 0 };
REGISTER_ARC(Apm)
}}

View File

@@ -6,7 +6,7 @@
#include "Windows/PropVariant.h"
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
#include "../../Windows/System.h"
#endif
@@ -51,7 +51,7 @@ class CHandler:
UInt32 _level;
UInt32 _dicSize;
UInt32 _numPasses;
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
UInt32 _numThreads;
#endif
@@ -60,7 +60,7 @@ class CHandler:
_level = 5;
_dicSize =
_numPasses = 0xFFFFFFFF;
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
_numThreads = NWindows::NSystem::GetNumberOfProcessors();;
#endif
}
@@ -187,7 +187,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
decoderSpec->SetInStream(_seqStream);
#if defined( COMPRESS_MT) && defined( COMPRESS_BZIP2_MT)
#ifndef _7ZIP_ST
RINOK(decoderSpec->SetNumberOfThreads(_numThreads));
#endif
@@ -249,7 +249,7 @@ static HRESULT UpdateArchive(
int indexInClient,
UInt32 dictionary,
UInt32 numPasses,
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
UInt32 numThreads,
#endif
IArchiveUpdateCallback *updateCallback)
@@ -273,7 +273,7 @@ static HRESULT UpdateArchive(
{
dictionary,
numPasses
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, numThreads
#endif
};
@@ -281,7 +281,7 @@ static HRESULT UpdateArchive(
{
NCoderPropID::kDictionarySize,
NCoderPropID::kNumPasses
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, NCoderPropID::kNumThreads
#endif
};
@@ -351,7 +351,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
return UpdateArchive(
size, outStream, 0, dicSize, numPasses,
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
_numThreads,
#endif
updateCallback);
@@ -366,7 +366,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps)
{
InitMethodProperties();
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
_numThreads = numProcessors;
#endif
@@ -398,7 +398,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

@@ -233,17 +233,14 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
HRESULT res = S_FALSE;
CInArchive archive;
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
{
CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = callback;
openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);
}
callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
CMyComPtr<IInStream> nextStream = inStream;
bool prevChecked = false;
UInt64 numItems = 0;
try
{
while(nextStream != 0)
while (nextStream != 0)
{
CDatabaseEx db;
db.Stream = nextStream;
@@ -296,6 +293,9 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
if (!otherArchive)
break;
const UString fullName = MultiByteToUnicodeString(otherArchive->FileName, CP_ACP);
if (!openVolumeCallback)
break;
HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);
if (result == S_OK)
break;

View File

@@ -6,7 +6,7 @@
#include "../../../Windows/PropVariant.h"
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
#include "../../../Windows/System.h"
#endif
@@ -190,7 +190,7 @@ static void SetMethodProp(COneMethodInfo &m, PROPID propID, const NCOM::CPropVar
}
void COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, UInt32 numThreads
#endif
)
@@ -224,7 +224,7 @@ void COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo
SetMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);
SetMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);
SetMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
SetMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
#endif
}
@@ -262,7 +262,7 @@ void COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo
SetMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);
SetMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
SetMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
#endif
}
@@ -476,7 +476,7 @@ void COutHandler::Init()
WriteATime = false;
WriteMTime = true;
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
_numThreads = NSystem::GetNumberOfProcessors();
#endif
@@ -490,7 +490,7 @@ void COutHandler::Init()
void COutHandler::BeforeSetProperty()
{
Init();
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
numProcessors = NSystem::GetNumberOfProcessors();
#endif
@@ -538,7 +538,7 @@ HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &val
{
if(name.Left(2).CompareNoCase(L"MT") == 0)
{
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));
#endif
return S_OK;

View File

@@ -24,7 +24,7 @@ public:
HRESULT SetSolidSettings(const UString &s);
HRESULT SetSolidSettings(const PROPVARIANT &value);
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
UInt32 _numThreads;
#endif
@@ -55,7 +55,7 @@ public:
HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);
void SetCompressionMethod2(COneMethodInfo &oneMethodInfo
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, UInt32 numThreads
#endif
);

View File

@@ -188,8 +188,7 @@ class CHandler:
DECL_ISetCompressCodecsInfo
public:
MY_QUERYINTERFACE_BEGIN
MY_QUERYINTERFACE_ENTRY(IInArchive)
MY_QUERYINTERFACE_BEGIN2(IInArchive)
MY_QUERYINTERFACE_ENTRY(IArchiveOpenSeq)
QUERY_ENTRY_ISetCompressCodecsInfo
MY_QUERYINTERFACE_END

View File

@@ -70,7 +70,7 @@ bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
{
if (m_CryptoMode)
{
const Byte *bufData = (const Byte *)m_DecryptedData;
const Byte *bufData = m_DecryptedDataAligned;
UInt32 bufSize = m_DecryptedDataSize;
UInt32 i;
for (i = 0; i < size && m_CryptoPos < bufSize; i++)
@@ -423,13 +423,15 @@ HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPa
const UInt32 kDecryptedBufferSize = (1 << 12);
if (m_DecryptedData.GetCapacity() == 0)
{
m_DecryptedData.SetCapacity(kDecryptedBufferSize);
const UInt32 kAlign = 16;
m_DecryptedData.SetCapacity(kDecryptedBufferSize + kAlign);
m_DecryptedDataAligned = (Byte *)((ptrdiff_t)((Byte *)m_DecryptedData + kAlign - 1) & ~(ptrdiff_t)(kAlign - 1));
}
RINOK(m_RarAES->Init());
size_t decryptedDataSizeT = kDecryptedBufferSize;
RINOK(ReadStream(m_Stream, (Byte *)m_DecryptedData, &decryptedDataSizeT));
RINOK(ReadStream(m_Stream, m_DecryptedDataAligned, &decryptedDataSizeT));
m_DecryptedDataSize = (UInt32)decryptedDataSizeT;
m_DecryptedDataSize = m_RarAES->Filter((Byte *)m_DecryptedData, m_DecryptedDataSize);
m_DecryptedDataSize = m_RarAES->Filter(m_DecryptedDataAligned, m_DecryptedDataSize);
m_CryptoMode = true;
m_CryptoPos = 0;

View File

@@ -76,8 +76,6 @@ class CInArchive
void AddToSeekValue(UInt64 addValue);
protected:
CDynamicBuffer<Byte> m_FileHeaderData;
NHeader::NBlock::CBlock m_BlockHeader;
@@ -94,6 +92,7 @@ protected:
void ReadTime(Byte mask, CRarTime &rarTime);
CBuffer<Byte> m_DecryptedData;
Byte *m_DecryptedDataAligned;
UInt32 m_DecryptedDataSize;
bool m_CryptoMode;

View File

@@ -107,6 +107,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
if (prop.vt != VT_UI8)
return E_INVALIDARG;
ui.Size = prop.uhVal.QuadPart;
if (ui.Size >= ((UInt64)1 << 33))
return E_INVALIDARG;
}
updateItems.Add(ui);
}

View File

@@ -220,7 +220,6 @@ class CHandler:
HRESULT ReadPhy(UInt64 offset, void *data, UInt32 size);
bool NeedParent() const { return Footer.Type == kDiskType_Diff; }
UInt64 GetSize() const { return Footer.CurrentSize; }
UInt64 GetPackSize() const
{ return Footer.ThereIsDynamic() ? ((UInt64)NumUsedBlocks << Dyn.BlockSizeLog) : Footer.CurrentSize; }
@@ -317,7 +316,12 @@ HRESULT CHandler::Open3()
if (Dyn.NumBlocks >= (UInt32)1 << 31)
return S_FALSE;
if (GetSize() != ((UInt64)Dyn.NumBlocks << Dyn.BlockSizeLog))
if (Footer.CurrentSize == 0)
{
if (Dyn.NumBlocks != 0)
return S_FALSE;
}
else if (((Footer.CurrentSize - 1) >> Dyn.BlockSizeLog) + 1 != Dyn.NumBlocks)
return S_FALSE;
Bat.Reserve(Dyn.NumBlocks);
@@ -341,8 +345,11 @@ STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize)
{
if (processedSize != NULL)
*processedSize = 0;
if (_virtPos >= GetSize())
return (GetSize() == _virtPos) ? S_OK: E_FAIL;
if (_virtPos >= Footer.CurrentSize)
return (Footer.CurrentSize == _virtPos) ? S_OK: E_FAIL;
UInt64 rem = Footer.CurrentSize - _virtPos;
if (size > rem)
size = (UInt32)rem;
if (size == 0)
return S_OK;
UInt32 blockIndex = (UInt32)(_virtPos >> Dyn.BlockSizeLog);
@@ -406,7 +413,7 @@ STDMETHODIMP CHandler::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition
{
case STREAM_SEEK_SET: _virtPos = offset; break;
case STREAM_SEEK_CUR: _virtPos += offset; break;
case STREAM_SEEK_END: _virtPos = GetSize() + offset; break;
case STREAM_SEEK_END: _virtPos = Footer.CurrentSize + offset; break;
default: return STG_E_INVALIDFUNCTION;
}
if (newPosition)
@@ -627,7 +634,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIAN
switch(propID)
{
case kpidSize: prop = GetSize(); break;
case kpidSize: prop = Footer.CurrentSize; break;
case kpidPackSize: prop = GetPackSize(); break;
case kpidCTime: VhdTimeToFileTime(Footer.CTime, prop); break;
/*
@@ -650,7 +657,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (numItems != (UInt32)-1 && (numItems != 1 || indices[0] != 0))
return E_INVALIDARG;
RINOK(extractCallback->SetTotal(GetSize()));
RINOK(extractCallback->SetTotal(Footer.CurrentSize));
CMyComPtr<ISequentialOutStream> outStream;
Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
@@ -678,7 +685,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
HRESULT hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
if (hres == S_OK)
{
if (copyCoderSpec->TotalSize == GetSize())
if (copyCoderSpec->TotalSize == Footer.CurrentSize)
res = NExtract::NOperationResult::kOK;
}
else
@@ -703,7 +710,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 /* index */, ISequentialInStream **strea
CLimitedInStream *streamSpec = new CLimitedInStream;
CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
streamSpec->SetStream(Stream);
streamSpec->InitAndSeek(0, GetSize());
streamSpec->InitAndSeek(0, Footer.CurrentSize);
RINOK(streamSpec->SeekToStart());
*stream = streamTemp.Detach();
return S_OK;

View File

@@ -198,25 +198,28 @@ static bool AddItem(const CXmlItem &item, CObjectVector<CFile> &files, int paren
file.Sha1IsDefined = ParseSha1(dataItem, "extracted-checksum", file.Sha1);
// file.packSha1IsDefined = ParseSha1(dataItem, "archived-checksum", file.packSha1);
int encodingIndex = dataItem.FindSubTag("encoding");
const CXmlItem &encodingItem = dataItem.SubItems[encodingIndex];
if (encodingItem.IsTag)
if (encodingIndex >= 0)
{
AString s = encodingItem.GetPropertyValue("style");
if (s.Length() >= 0)
const CXmlItem &encodingItem = dataItem.SubItems[encodingIndex];
if (encodingItem.IsTag)
{
AString appl = "application/";
if (s.Left(appl.Length()) == appl)
AString s = encodingItem.GetPropertyValue("style");
if (s.Length() >= 0)
{
s = s.Mid(appl.Length());
AString xx = "x-";
if (s.Left(xx.Length()) == xx)
AString appl = "application/";
if (s.Left(appl.Length()) == appl)
{
s = s.Mid(xx.Length());
if (s == "gzip")
s = METHOD_NAME_ZLIB;
s = s.Mid(appl.Length());
AString xx = "x-";
if (s.Left(xx.Length()) == xx)
{
s = s.Mid(xx.Length());
if (s == "gzip")
s = METHOD_NAME_ZLIB;
}
}
file.Method = s;
}
file.Method = s;
}
}
}
@@ -359,7 +362,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidMethod:
{
UString name;
if (ConvertUTF8ToUnicode(item.Method, name))
if (!item.Method.IsEmpty() && ConvertUTF8ToUnicode(item.Method, name))
prop = name;
break;
}
@@ -521,7 +524,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
HRESULT res = S_OK;
ICompressCoder *coder = NULL;
if (item.Method == "octet-stream")
if (item.Method.IsEmpty() || item.Method == "octet-stream")
if (item.PackSize == item.Size)
coder = copyCoder;
else

View File

@@ -73,8 +73,7 @@ class CHandler:
HRESULT Open2(IInStream *inStream, IArchiveOpenCallback *callback);
public:
MY_QUERYINTERFACE_BEGIN
MY_QUERYINTERFACE_ENTRY(IInArchive)
MY_QUERYINTERFACE_BEGIN2(IInArchive)
MY_QUERYINTERFACE_ENTRY(IArchiveOpenSeq)
#ifndef EXTRACT_ONLY
MY_QUERYINTERFACE_ENTRY(IOutArchive)
@@ -644,7 +643,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
{
COneMethodInfo &m = _methods[i];
SetCompressionMethod2(m
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
, _numThreads
#endif
);
@@ -658,7 +657,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
}
}
#ifdef COMPRESS_MT
#ifndef _7ZIP_ST
lzma2Props.numTotalThreads = _numThreads;
#endif

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;