diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2007-05-25 04:00:00 +0400 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:15:51 +0300 |
commit | c574fc0f4bba94e693b0e22f730d355b75d4f4ce (patch) | |
tree | da4ebd90c776d508ac679d50492f29461db80be0 | |
parent | a145bfc7cf17f7bbcfae8f0064333c8ea75b455c (diff) |
4.46 beta
191 files changed, 1297 insertions, 833 deletions
diff --git a/C/7zCrcT8.c b/C/7zCrcT8.c index 0619e21c..83aa95f7 100755 --- a/C/7zCrcT8.c +++ b/C/7zCrcT8.c @@ -1,4 +1,4 @@ -/* 7zCrc.c */ +/* 7zCrcT8.c */ #include "7zCrc.h" @@ -1,4 +1,4 @@ -// Common/Alloc.c +/* Alloc.c */ #ifdef _WIN32 #include <windows.h> @@ -7,7 +7,7 @@ #include "Alloc.h" -// #define _SZ_ALLOC_DEBUG +/* #define _SZ_ALLOC_DEBUG */ /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ #ifdef _SZ_ALLOC_DEBUG @@ -1,4 +1,4 @@ -// Common/Alloc.h +/* Alloc.h */ #ifndef __COMMON_ALLOC_H #define __COMMON_ALLOC_H diff --git a/C/Archive/7z/7zMain.c b/C/Archive/7z/7zMain.c index efd3624d..74f0afd5 100755 --- a/C/Archive/7z/7zMain.c +++ b/C/Archive/7z/7zMain.c @@ -46,10 +46,12 @@ void ConvertNumberToString(CFileSize value, char *s) #ifdef USE_WINDOWS_FUNCTIONS -// ReadFile and WriteFile functions in Windows have BUG: -// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) -// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES -// (Insufficient system resources exist to complete the requested service). +/* + ReadFile and WriteFile functions in Windows have BUG: + If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) + from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES + (Insufficient system resources exist to complete the requested service). +*/ #define kChunkSizeMax (1 << 24) #endif @@ -161,7 +163,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) value.LowPart = (DWORD)pos; value.HighPart = (LONG)((UInt64)pos >> 32); #ifdef _SZ_FILE_SIZE_32 - // VC 6.0 has bug with >> 32 shifts. + /* VC 6.0 has bug with >> 32 shifts. */ value.HighPart = 0; #endif value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN); @@ -354,7 +356,7 @@ int main(int numargs, char *args[]) printf("\nEverything is Ok\n"); return 0; } - if (res == SZE_OUTOFMEMORY) + if (res == (SZ_RESULT)SZE_OUTOFMEMORY) PrintError("can not allocate memory"); else printf("\nERROR #%d\n", res); diff --git a/C/Compress/Branch/BranchARM.h b/C/Compress/Branch/BranchARM.h index 02eb1b47..3b4d63e1 100755 --- a/C/Compress/Branch/BranchARM.h +++ b/C/Compress/Branch/BranchARM.h @@ -1,4 +1,4 @@ -// BranchARM.h +/* BranchARM.h */ #ifndef __BRANCH_ARM_H #define __BRANCH_ARM_H diff --git a/C/Compress/Branch/BranchARMThumb.h b/C/Compress/Branch/BranchARMThumb.h index d67e6e5a..304699ce 100755 --- a/C/Compress/Branch/BranchARMThumb.h +++ b/C/Compress/Branch/BranchARMThumb.h @@ -1,4 +1,4 @@ -// BranchARMThumb.h +/* BranchARMThumb.h */ #ifndef __BRANCH_ARM_THUMB_H #define __BRANCH_ARM_THUMB_H diff --git a/C/Compress/Branch/BranchIA64.h b/C/Compress/Branch/BranchIA64.h index b7757fe9..8213cb50 100755 --- a/C/Compress/Branch/BranchIA64.h +++ b/C/Compress/Branch/BranchIA64.h @@ -1,4 +1,4 @@ -// BranchIA64.h +/* BranchIA64.h */ #ifndef __BRANCH_IA64_H #define __BRANCH_IA64_H diff --git a/C/Compress/Branch/BranchPPC.h b/C/Compress/Branch/BranchPPC.h index c02bba19..05e2a377 100755 --- a/C/Compress/Branch/BranchPPC.h +++ b/C/Compress/Branch/BranchPPC.h @@ -1,4 +1,4 @@ -// BranchPPC.h +/* BranchPPC.h */ #ifndef __BRANCH_PPC_H #define __BRANCH_PPC_H diff --git a/C/Compress/Branch/BranchSPARC.h b/C/Compress/Branch/BranchSPARC.h index 67f44411..f3f83206 100755 --- a/C/Compress/Branch/BranchSPARC.h +++ b/C/Compress/Branch/BranchSPARC.h @@ -1,4 +1,4 @@ -// BranchSPARC.h +/* BranchSPARC.h */ #ifndef __BRANCH_SPARC_H #define __BRANCH_SPARC_H diff --git a/C/Compress/Huffman/HuffmanEncode.c b/C/Compress/Huffman/HuffmanEncode.c index 3168db2d..f27607e6 100755 --- a/C/Compress/Huffman/HuffmanEncode.c +++ b/C/Compress/Huffman/HuffmanEncode.c @@ -1,4 +1,4 @@ -// Compression/HuffmanEncode.c +/* Compress/HuffmanEncode.c */ #include "HuffmanEncode.h" #include "../../Sort.h" @@ -9,13 +9,13 @@ #define NUM_COUNTERS 64 -// use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M +/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M */ #define HUFFMAN_SPEED_OPT void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen) { UInt32 num = 0; - // if (maxLen > 10) maxLen = 10; + /* if (maxLen > 10) maxLen = 10; */ { UInt32 i; @@ -133,7 +133,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb for (len = 1; len <= kMaxLen; len++) nextCodes[len] = code = (code + lenCounters[len - 1]) << 1; } - // if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; + /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */ { UInt32 i; diff --git a/C/Compress/Huffman/HuffmanEncode.h b/C/Compress/Huffman/HuffmanEncode.h index dfd2f0ab..e59c86ad 100755 --- a/C/Compress/Huffman/HuffmanEncode.h +++ b/C/Compress/Huffman/HuffmanEncode.h @@ -1,4 +1,4 @@ -// Compress/HuffmanEncode.h +/* Compress/HuffmanEncode.h */ #ifndef __COMPRESS_HUFFMANENCODE_H #define __COMPRESS_HUFFMANENCODE_H diff --git a/C/Compress/Lz/MatchFinder.c b/C/Compress/Lz/MatchFinder.c index 4580c52b..f34447bd 100755 --- a/C/Compress/Lz/MatchFinder.c +++ b/C/Compress/Lz/MatchFinder.c @@ -163,7 +163,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, sizeReserv = historySize >> 1; if (historySize > ((UInt32)2 << 30)) sizeReserv = historySize >> 2; - sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 12); + sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19); p->keepSizeBefore = historySize + keepAddBufferBefore + 1; p->keepSizeAfter = matchMaxLen + keepAddBufferAfter; @@ -622,6 +622,19 @@ UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) MOVE_POS_RET } +UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +{ + UInt32 offset; + GET_MATCHES_HEADER(3) + HASH_ZIP_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, p->pos, p->buffer, p->son, + p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue, + distances, 2) - (distances)); + MOVE_POS_RET +} + void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) { do @@ -696,6 +709,20 @@ void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) while (--num != 0); } +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +{ + do + { + SKIP_HEADER(3) + HASH_ZIP_CALC; + curMatch = p->hash[hashValue]; + p->hash[hashValue] = p->pos; + p->son[p->cyclicBufferPos] = curMatch; + MOVE_POS + } + while (--num != 0); +} + void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) { vTable->Init = (Mf_Init_Func)MatchFinder_Init; diff --git a/C/Compress/Lz/MatchFinder.h b/C/Compress/Lz/MatchFinder.h index 43906312..f334bdbc 100755 --- a/C/Compress/Lz/MatchFinder.h +++ b/C/Compress/Lz/MatchFinder.h @@ -98,6 +98,8 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); void MatchFinder_Init(CMatchFinder *p); UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); +UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); #endif diff --git a/C/Compress/Lz/MatchFinderMt.c b/C/Compress/Lz/MatchFinderMt.c index 69ac686a..95c7e7a0 100755 --- a/C/Compress/Lz/MatchFinderMt.c +++ b/C/Compress/Lz/MatchFinderMt.c @@ -1,6 +1,17 @@ /* MatchFinderMt.c */ +#ifdef _WIN32 +#define USE_ALLOCA +#endif + +#ifdef USE_ALLOCA +#ifdef _WIN32 #include <malloc.h> +#else +#include <stdlib.h> +#endif +#endif + #include "../../7zCrc.h" #include "LzHash.h" @@ -460,7 +471,14 @@ void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc) #define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks) static unsigned StdCall HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; } -static unsigned StdCall BtThreadFunc2(void *p) { alloca(0x180); BtThreadFunc((CMatchFinderMt *)p); return 0; } +static unsigned StdCall BtThreadFunc2(void *p) +{ + #ifdef USE_ALLOCA + alloca(0x180); + #endif + BtThreadFunc((CMatchFinderMt *)p); + return 0; +} HRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc) diff --git a/C/Compress/Lz/MatchFinderMt.h b/C/Compress/Lz/MatchFinderMt.h index a9d9372f..0283463a 100755 --- a/C/Compress/Lz/MatchFinderMt.h +++ b/C/Compress/Lz/MatchFinderMt.h @@ -71,9 +71,9 @@ typedef struct _CMatchFinderMt UInt32 matchMaxLen; UInt32 numHashBytes; UInt32 pos; - Byte *buffer; // Pointer to virtual Buffer begin + Byte *buffer; /* Pointer to virtual Buffer begin */ UInt32 cyclicBufferPos; - UInt32 cyclicBufferSize; // it must be historySize + 1 + UInt32 cyclicBufferSize; /* it must be historySize + 1 */ UInt32 cutValue; /* BT + Hash */ diff --git a/C/IStream.h b/C/IStream.h index 29c46f5f..58218487 100755 --- a/C/IStream.h +++ b/C/IStream.h @@ -1,4 +1,4 @@ -// IStream.h +/* IStream.h */ #ifndef __C_ISTREAM_H #define __C_ISTREAM_H diff --git a/C/Threads.c b/C/Threads.c index dcf63dcf..def48175 100755 --- a/C/Threads.c +++ b/C/Threads.c @@ -21,12 +21,12 @@ HRes MyCloseHandle(HANDLE *h) return SZ_OK; } -HRes Thread_Create(CThread *thread, unsigned (StdCall *startAddress)(void *), LPVOID parameter) +HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) { - /* DWORD threadId; */ + unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ thread->handle = /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */ - (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, NULL); + (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId); /* maybe we must use errno here, but probably GetLastError() is also OK. */ return BoolToHRes(thread->handle != 0); } @@ -48,13 +48,22 @@ HRes Thread_Close(CThread *thread) return MyCloseHandle(&thread->handle); } -HRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled) +HRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled) { - p->handle = CreateEvent(NULL, FALSE, (initialSignaled ? TRUE : FALSE), NULL); + p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL); return BoolToHRes(p->handle != 0); } -HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); } +HRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled) + { return Event_Create(p, TRUE, initialSignaled); } +HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) + { return ManualResetEvent_Create(p, 0); } + +HRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled) + { return Event_Create(p, FALSE, initialSignaled); } +HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) + { return AutoResetEvent_Create(p, 0); } + HRes Event_Set(CEvent *p) { return BOOLToHRes(SetEvent(p->handle)); } HRes Event_Reset(CEvent *p) { return BOOLToHRes(ResetEvent(p->handle)); } HRes Event_Wait(CEvent *p) { return WaitObject(p->handle); } @@ -71,9 +80,9 @@ HRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) { return BOOLToHRes(ReleaseSemaphore(p->handle, releaseCount, previousCount)); } -HRes Semaphore_ReleaseN(CSemaphore *p, LONG releaseCount) +HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount) { - return Semaphore_Release(p, releaseCount, NULL); + return Semaphore_Release(p, (LONG)releaseCount, NULL); } HRes Semaphore_Release1(CSemaphore *p) { @@ -89,7 +98,7 @@ HRes CriticalSection_Init(CCriticalSection *p) __try { InitializeCriticalSection(p); - // InitializeCriticalSectionAndSpinCount(p, 0); + /* InitializeCriticalSectionAndSpinCount(p, 0); */ } __except (EXCEPTION_EXECUTE_HANDLER) { return SZE_OUTOFMEMORY; } return SZ_OK; diff --git a/C/Threads.h b/C/Threads.h index fec9e6d5..c024dcc6 100755 --- a/C/Threads.h +++ b/C/Threads.h @@ -1,4 +1,4 @@ -/* Thresds.h */ +/* Threads.h */ #ifndef __7Z_THRESDS_H #define __7Z_THRESDS_H @@ -15,7 +15,11 @@ typedef struct _CThread #define Thread_Construct(thread) (thread)->handle = NULL #define Thread_WasCreated(thread) ((thread)->handle != NULL) -HRes Thread_Create(CThread *thread, unsigned (StdCall *startAddress)(void *), LPVOID parameter); +typedef unsigned THREAD_FUNC_RET_TYPE; +#define THREAD_FUNC_CALL_TYPE StdCall +#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE + +HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter); HRes Thread_Wait(CThread *thread); HRes Thread_Close(CThread *thread); @@ -25,9 +29,13 @@ typedef struct _CEvent } CEvent; typedef CEvent CAutoResetEvent; +typedef CEvent CManualResetEvent; #define Event_Construct(event) (event)->handle = NULL +#define Event_IsCreated(event) ((event)->handle != NULL) +HRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled); +HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event); HRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled); HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event); HRes Event_Set(CEvent *event); @@ -44,6 +52,7 @@ typedef struct _CSemaphore #define Semaphore_Construct(p) (p)->handle = NULL HRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount); +HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); HRes Semaphore_Release1(CSemaphore *p); HRes Semaphore_Wait(CSemaphore *p); HRes Semaphore_Close(CSemaphore *p); diff --git a/CPP/7zip/Archive/7z/7zCompressionMode.h b/CPP/7zip/Archive/7z/7zCompressionMode.h index 4c4527f2..65e573d1 100755 --- a/CPP/7zip/Archive/7z/7zCompressionMode.h +++ b/CPP/7zip/Archive/7z/7zCompressionMode.h @@ -7,7 +7,7 @@ #include "../../../Windows/PropVariant.h" -#include "../../Common/MethodID.h" +#include "../../Common/MethodId.h" namespace NArchive { namespace N7z { diff --git a/CPP/7zip/Archive/7z/7zDecode.cpp b/CPP/7zip/Archive/7z/7zDecode.cpp index bce9b009..19b08b78 100755 --- a/CPP/7zip/Archive/7z/7zDecode.cpp +++ b/CPP/7zip/Archive/7z/7zDecode.cpp @@ -157,7 +157,7 @@ HRESULT CDecoder::Decode( _mixerCoderCommon = _mixerCoderSTSpec; #endif } - _mixerCoderCommon->SetBindInfo(bindInfo); + RINOK(_mixerCoderCommon->SetBindInfo(bindInfo)); for (i = 0; i < numCoders; i++) { diff --git a/CPP/7zip/Archive/7z/7zEncode.cpp b/CPP/7zip/Archive/7z/7zEncode.cpp index ef0b757b..ef74b9bf 100755 --- a/CPP/7zip/Archive/7z/7zEncode.cpp +++ b/CPP/7zip/Archive/7z/7zEncode.cpp @@ -56,7 +56,7 @@ HRESULT CEncoder::CreateMixerCoder( { _mixerCoderSpec = new NCoderMixer2::CCoderMixer2MT; _mixerCoder = _mixerCoderSpec; - _mixerCoderSpec->SetBindInfo(_bindInfo); + RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo)); for (int i = 0; i < _options.Methods.Size(); i++) { const CMethodFull &methodFull = _options.Methods[i]; diff --git a/CPP/7zip/Archive/7z/7zHandler.cpp b/CPP/7zip/Archive/7z/7zHandler.cpp index abccdce9..dc0a6505 100755 --- a/CPP/7zip/Archive/7z/7zHandler.cpp +++ b/CPP/7zip/Archive/7z/7zHandler.cpp @@ -143,10 +143,12 @@ static inline UString GetHex2(Byte value) static const UInt64 k_AES = 0x06F10701; +#ifndef _SFX static inline UInt32 GetUInt32FromMemLE(const Byte *p) { return p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24); } +#endif bool CHandler::IsEncrypted(UInt32 index2) const { @@ -393,11 +395,11 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va COM_TRY_END } +#ifdef _7Z_VOL + static const wchar_t *kExt = L"7z"; static const wchar_t *kAfterPart = L".7z"; -#ifdef _7Z_VOL - class CVolumeName { bool _first; diff --git a/CPP/7zip/Archive/7z/7zHandler.h b/CPP/7zip/Archive/7z/7zHandler.h index 26675b78..77e4d25c 100755 --- a/CPP/7zip/Archive/7z/7zHandler.h +++ b/CPP/7zip/Archive/7z/7zHandler.h @@ -85,8 +85,7 @@ class CHandler: public CMyUnknownImp { public: - MY_QUERYINTERFACE_BEGIN - MY_QUERYINTERFACE_ENTRY(IInArchive) + MY_QUERYINTERFACE_BEGIN2(IInArchive) #ifdef _7Z_VOL MY_QUERYINTERFACE_ENTRY(IInArchiveGetStream) #endif diff --git a/CPP/7zip/Archive/7z/7zHandlerOut.cpp b/CPP/7zip/Archive/7z/7zHandlerOut.cpp index 2508e518..80d63931 100755 --- a/CPP/7zip/Archive/7z/7zHandlerOut.cpp +++ b/CPP/7zip/Archive/7z/7zHandlerOut.cpp @@ -54,6 +54,9 @@ static const UInt32 kPpmdOrderX5 = 6; static const UInt32 kPpmdOrderX7 = 16; static const UInt32 kPpmdOrderX9 = 32; +static const UInt32 kDeflateAlgoX1 = 0; +static const UInt32 kDeflateAlgoX5 = 1; + static const UInt32 kDeflateFastBytesX1 = 32; static const UInt32 kDeflateFastBytesX7 = 64; static const UInt32 kDeflateFastBytesX9 = 128; @@ -323,7 +326,11 @@ HRESULT CHandler::SetCompressionMethod( (level >= 9 ? kDeflatePassesX9 : (level >= 7 ? kDeflatePassesX7 : kDeflatePassesX1)); + UInt32 algo = + (level >= 5 ? kDeflateAlgoX5 : + kDeflateAlgoX1); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo); SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes); SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses); } diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp index 6c709b89..d1ad9da8 100755 --- a/CPP/7zip/Archive/7z/7zIn.cpp +++ b/CPP/7zip/Archive/7z/7zIn.cpp @@ -1238,7 +1238,7 @@ HRESULT CInArchive::ReadDatabase( UInt64 nextHeaderSize; UInt32 nextHeaderCRC; UInt32 crc = CRC_INIT_VAL; - UInt32 temp; + UInt32 temp = 0; RINOK(SafeReadDirectUInt32(crcFromArchive, temp)); RINOK(SafeReadDirectUInt64(nextHeaderOffset, crc)); RINOK(SafeReadDirectUInt64(nextHeaderSize, crc)); diff --git a/CPP/7zip/Archive/7z/7zItem.h b/CPP/7zip/Archive/7z/7zItem.h index c4f9dc13..cad88dc1 100755 --- a/CPP/7zip/Archive/7z/7zItem.h +++ b/CPP/7zip/Archive/7z/7zItem.h @@ -5,7 +5,7 @@ #include "../../../Common/Buffer.h" #include "../../../Common/String.h" -#include "../../Common/MethodID.h" +#include "../../Common/MethodId.h" #include "7zHeader.h" namespace NArchive { diff --git a/CPP/7zip/Archive/7z/7zProperties.h b/CPP/7zip/Archive/7z/7zProperties.h index a09839bb..4da85f04 100755 --- a/CPP/7zip/Archive/7z/7zProperties.h +++ b/CPP/7zip/Archive/7z/7zProperties.h @@ -8,13 +8,13 @@ namespace NArchive { namespace N7z { -enum // PropID +enum { kpidPackedSize0 = kpidUserDefined, kpidPackedSize1, kpidPackedSize2, kpidPackedSize3, - kpidPackedSize4, + kpidPackedSize4 }; }} diff --git a/CPP/7zip/Archive/7z/7zUpdate.cpp b/CPP/7zip/Archive/7z/7zUpdate.cpp index 30b97632..2b197adb 100755 --- a/CPP/7zip/Archive/7z/7zUpdate.cpp +++ b/CPP/7zip/Archive/7z/7zUpdate.cpp @@ -350,7 +350,6 @@ static bool IsExeFile(const UString &ext) return false; } -static const UInt64 k_Copy = 0x0; static const UInt64 k_LZMA = 0x030101; static const UInt64 k_BCJ = 0x03030103; static const UInt64 k_BCJ2 = 0x0303011B; @@ -843,6 +842,8 @@ static HRESULT Update2( #ifdef _7Z_VOL +static const UInt64 k_Copy = 0x0; + static HRESULT WriteVolumeHeader(COutArchive &archive, CFileItem &file, const CUpdateOptions &options) { CCoderInfo coder; diff --git a/CPP/7zip/Archive/7z/7zUpdate.h b/CPP/7zip/Archive/7z/7zUpdate.h index e19d7a2d..ac1b5b65 100755 --- a/CPP/7zip/Archive/7z/7zUpdate.h +++ b/CPP/7zip/Archive/7z/7zUpdate.h @@ -35,7 +35,7 @@ struct CUpdateItem bool IsLastAccessTimeDefined; bool AttributesAreDefined; - const bool HasStream() const + bool HasStream() const { return !IsDirectory && !IsAnti && Size != 0; } CUpdateItem(): IsAnti(false), diff --git a/CPP/7zip/Archive/Arj/ArjHandler.h b/CPP/7zip/Archive/Arj/ArjHandler.h index a1e69ba6..58e67401 100755 --- a/CPP/7zip/Archive/Arj/ArjHandler.h +++ b/CPP/7zip/Archive/Arj/ArjHandler.h @@ -15,7 +15,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *inStream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Arj/ArjHeader.h b/CPP/7zip/Archive/Arj/ArjHeader.h index 58ee8c27..7aca1b98 100755 --- a/CPP/7zip/Archive/Arj/ArjHeader.h +++ b/CPP/7zip/Archive/Arj/ArjHeader.h @@ -51,7 +51,7 @@ namespace NFileHeader kCompressed1c = 3, kCompressed2 = 4, kNoDataNoCRC = 8, - kNoData = 9, + kNoData = 9 }; } namespace NFileType @@ -62,7 +62,7 @@ namespace NFileHeader k7BitText = 1, kDirectory = 3, kVolumeLablel = 4, - kChapterLabel = 5, + kChapterLabel = 5 }; } namespace NFlags diff --git a/CPP/7zip/Archive/BZip2/BZip2Handler.h b/CPP/7zip/Archive/BZip2/BZip2Handler.h index c7049d2f..96854eca 100755 --- a/CPP/7zip/Archive/BZip2/BZip2Handler.h +++ b/CPP/7zip/Archive/BZip2/BZip2Handler.h @@ -46,8 +46,7 @@ class CHandler: } public: - MY_QUERYINTERFACE_BEGIN - MY_QUERYINTERFACE_ENTRY(IInArchive) + MY_QUERYINTERFACE_BEGIN2(IInArchive) MY_QUERYINTERFACE_ENTRY(IOutArchive) MY_QUERYINTERFACE_ENTRY(ISetProperties) QUERY_ENTRY_ISetCompressCodecsInfo diff --git a/CPP/7zip/Archive/Cab/CabHandler.cpp b/CPP/7zip/Archive/Cab/CabHandler.cpp index f23484f7..1c0e2feb 100755 --- a/CPP/7zip/Archive/Cab/CabHandler.cpp +++ b/CPP/7zip/Archive/Cab/CabHandler.cpp @@ -54,8 +54,6 @@ STATPROPSTG kProperties[] = #endif }; -static const int kNumProperties = sizeof(kProperties) / sizeof(kProperties[0]); - static const wchar_t *kMethods[] = { L"None", diff --git a/CPP/7zip/Archive/Cab/CabHandler.h b/CPP/7zip/Archive/Cab/CabHandler.h index 245586b6..f5b6e39c 100755 --- a/CPP/7zip/Archive/Cab/CabHandler.h +++ b/CPP/7zip/Archive/Cab/CabHandler.h @@ -15,7 +15,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Cab/CabIn.h b/CPP/7zip/Archive/Cab/CabIn.h index aa3008f1..ebeead87 100755 --- a/CPP/7zip/Archive/Cab/CabIn.h +++ b/CPP/7zip/Archive/Cab/CabIn.h @@ -18,7 +18,7 @@ public: { kUnexpectedEndOfArchive = 0, kIncorrectArchive, - kUnsupported, + kUnsupported } Cause; CInArchiveException(CCauseType cause) : Cause(cause) {} }; diff --git a/CPP/7zip/Archive/Chm/ChmHandler.cpp b/CPP/7zip/Archive/Chm/ChmHandler.cpp index 6b37c73e..5de871da 100755 --- a/CPP/7zip/Archive/Chm/ChmHandler.cpp +++ b/CPP/7zip/Archive/Chm/ChmHandler.cpp @@ -55,8 +55,6 @@ STATPROPSTG kProperties[] = #endif }; -static const int kNumProperties = sizeof(kProperties) / sizeof(kProperties[0]); - STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; diff --git a/CPP/7zip/Archive/Chm/ChmHandler.h b/CPP/7zip/Archive/Chm/ChmHandler.h index dd0692ba..82eeb290 100755 --- a/CPP/7zip/Archive/Chm/ChmHandler.h +++ b/CPP/7zip/Archive/Chm/ChmHandler.h @@ -15,7 +15,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Common/CoderMixer2.h b/CPP/7zip/Archive/Common/CoderMixer2.h index 78a3f280..597a7b60 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2.h +++ b/CPP/7zip/Archive/Common/CoderMixer2.h @@ -158,7 +158,7 @@ struct CCoderInfo class CCoderMixer2 { public: - virtual void SetBindInfo(const CBindInfo &bindInfo) = 0; + virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0; virtual void ReInit() = 0; virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0; }; diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp index c3b37f2d..8a37a10d 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp +++ b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp @@ -12,8 +12,6 @@ namespace NCoderMixer2 { CThreadCoderInfo::CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams): ExitEvent(NULL), - CompressEvent(NULL), - CompressionCompletedEvent(NULL), CCoderInfo(numInStreams, numOutStreams) { InStreams.Reserve(NumInStreams); @@ -22,20 +20,6 @@ CThreadCoderInfo::CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams): OutStreamPointers.Reserve(NumOutStreams); } -void CThreadCoderInfo::CreateEvents() -{ - CompressEvent = new CAutoResetEvent(false); - CompressionCompletedEvent = new CAutoResetEvent(false); -} - -CThreadCoderInfo::~CThreadCoderInfo() -{ - if (CompressEvent != NULL) - delete CompressEvent; - if (CompressionCompletedEvent != NULL) - delete CompressionCompletedEvent; -} - class CCoderInfoFlusher2 { CThreadCoderInfo *m_CoderInfo; @@ -48,13 +32,13 @@ public: m_CoderInfo->InStreams[i].Release(); for (i = 0; i < m_CoderInfo->OutStreams.Size(); i++) m_CoderInfo->OutStreams[i].Release(); - m_CoderInfo->CompressionCompletedEvent->Set(); + m_CoderInfo->CompressionCompletedEvent.Set(); } }; bool CThreadCoderInfo::WaitAndCode() { - HANDLE events[2] = { ExitEvent, *CompressEvent }; + HANDLE events[2] = { ExitEvent, CompressEvent }; DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE); if (waitResult == WAIT_OBJECT_0 + 0) return false; @@ -123,7 +107,7 @@ void CThreadCoderInfo::SetCoderInfo(const UInt64 **inSizes, SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams); } -static DWORD WINAPI CoderThread(void *threadCoderInfo) +static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo) { for (;;) { @@ -135,7 +119,7 @@ static DWORD WINAPI CoderThread(void *threadCoderInfo) ////////////////////////////////////// // CCoderMixer2MT -static DWORD WINAPI MainCoderThread(void *threadCoderInfo) +static THREAD_FUNC_DECL MainCoderThread(void *threadCoderInfo) { for (;;) { @@ -146,7 +130,9 @@ static DWORD WINAPI MainCoderThread(void *threadCoderInfo) CCoderMixer2MT::CCoderMixer2MT() { - if (!_mainThread.Create(MainCoderThread, this)) + if (CreateEvents() != S_OK) + throw 271824; + if (_mainThread.Create(MainCoderThread, this) != S_OK) throw 271825; } @@ -161,15 +147,16 @@ CCoderMixer2MT::~CCoderMixer2MT() } } -void CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo) +HRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo) { _bindInfo = bindInfo; _streamBinders.Clear(); for(int i = 0; i < _bindInfo.BindPairs.Size(); i++) { _streamBinders.Add(CStreamBinder()); - _streamBinders.Back().CreateEvents(); + RINOK(_streamBinders.Back().CreateEvents()); } + return S_OK; } void CCoderMixer2MT::AddCoderCommon() @@ -180,13 +167,13 @@ void CCoderMixer2MT::AddCoderCommon() CThreadCoderInfo threadCoderInfo(CoderStreamsInfo.NumInStreams, CoderStreamsInfo.NumOutStreams); _coderInfoVector.Add(threadCoderInfo); - _coderInfoVector.Back().CreateEvents(); - _coderInfoVector.Back().ExitEvent = _exitEvent; - _compressingCompletedEvents.Add(*_coderInfoVector.Back().CompressionCompletedEvent); + CThreadCoderInfo *tci = &_coderInfoVector.Back(); + tci->CreateEvents(); + tci->ExitEvent = _exitEvent; NWindows::CThread newThread; _threads.Add(newThread); - if (!_threads.Back().Create(CoderThread, &_coderInfoVector.Back())) + if (_threads.Back().Create(CoderThread, tci) != S_OK) throw 271824; } @@ -282,13 +269,13 @@ bool CCoderMixer2MT::MyCode() if (waitResult == WAIT_OBJECT_0 + 0) return false; - for(int i = 0; i < _coderInfoVector.Size(); i++) - _coderInfoVector[i].CompressEvent->Set(); - /* DWORD result = */ ::WaitForMultipleObjects(_compressingCompletedEvents.Size(), - &_compressingCompletedEvents.Front(), TRUE, INFINITE); - - _compressingFinishedEvent.Set(); + int i; + for(i = 0; i < _coderInfoVector.Size(); i++) + _coderInfoVector[i].CompressEvent.Set(); + for (i = 0; i < _coderInfoVector.Size(); i++) + _coderInfoVector[i].CompressionCompletedEvent.Lock(); + _compressingFinishedEvent.Set(); return true; } @@ -311,6 +298,7 @@ STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams, CCrossThreadProgress *progressSpec = new CCrossThreadProgress; CMyComPtr<ICompressProgressInfo> crossProgress = progressSpec; + RINOK(progressSpec->Create()); progressSpec->Init(); _coderInfoVector[_progressCoderIndex].Progress = crossProgress; diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.h b/CPP/7zip/Archive/Common/CoderMixer2MT.h index 78d752de..67c0c8a5 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2MT.h +++ b/CPP/7zip/Archive/Common/CoderMixer2MT.h @@ -20,9 +20,9 @@ namespace NCoderMixer2 { struct CThreadCoderInfo: public CCoderInfo { - NWindows::NSynchronization::CAutoResetEvent *CompressEvent; + NWindows::NSynchronization::CAutoResetEvent CompressEvent; HANDLE ExitEvent; - NWindows::NSynchronization::CAutoResetEvent *CompressionCompletedEvent; + NWindows::NSynchronization::CAutoResetEvent CompressionCompletedEvent; CObjectVector< CMyComPtr<ISequentialInStream> > InStreams; CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams; @@ -35,9 +35,12 @@ struct CThreadCoderInfo: public CCoderInfo CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams); void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes, ICompressProgressInfo *progress); - ~CThreadCoderInfo(); bool WaitAndCode(); - void CreateEvents(); + HRes CreateEvents() + { + RINOK(CompressEvent.CreateIfNotCreated()); + return CompressionCompletedEvent.CreateIfNotCreated(); + } }; @@ -105,14 +108,20 @@ private: NWindows::CThread _mainThread; NWindows::NSynchronization::CAutoResetEvent _startCompressingEvent; - CRecordVector<HANDLE> _compressingCompletedEvents; NWindows::NSynchronization::CAutoResetEvent _compressingFinishedEvent; NWindows::NSynchronization::CManualResetEvent _exitEvent; UInt32 _progressCoderIndex; + HRes CreateEvents() + { + RINOK(_startCompressingEvent.CreateIfNotCreated()); + RINOK(_compressingFinishedEvent.CreateIfNotCreated()); + return _exitEvent.CreateIfNotCreated(); + } + public: - void SetBindInfo(const CBindInfo &bindInfo); + HRESULT SetBindInfo(const CBindInfo &bindInfo); }; diff --git a/CPP/7zip/Archive/Common/CoderMixer2ST.cpp b/CPP/7zip/Archive/Common/CoderMixer2ST.cpp index c01b776d..6bcab0dd 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2ST.cpp +++ b/CPP/7zip/Archive/Common/CoderMixer2ST.cpp @@ -10,9 +10,10 @@ CCoderMixer2ST::CCoderMixer2ST() {} CCoderMixer2ST::~CCoderMixer2ST(){ } -void CCoderMixer2ST::SetBindInfo(const CBindInfo &bindInfo) +HRESULT CCoderMixer2ST::SetBindInfo(const CBindInfo &bindInfo) { _bindInfo = bindInfo; + return S_OK; } void CCoderMixer2ST::AddCoderCommon(bool isMain) diff --git a/CPP/7zip/Archive/Common/CoderMixer2ST.h b/CPP/7zip/Archive/Common/CoderMixer2ST.h index 3144918b..ea5a53e3 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2ST.h +++ b/CPP/7zip/Archive/Common/CoderMixer2ST.h @@ -79,7 +79,7 @@ private: CObjectVector<CSTCoderInfo> _coders; int _mainCoderIndex; public: - void SetBindInfo(const CBindInfo &bindInfo); + HRESULT SetBindInfo(const CBindInfo &bindInfo); }; diff --git a/CPP/7zip/Archive/Common/CrossThreadProgress.h b/CPP/7zip/Archive/Common/CrossThreadProgress.h index 5dd339dc..b5422a31 100755 --- a/CPP/7zip/Archive/Common/CrossThreadProgress.h +++ b/CPP/7zip/Archive/Common/CrossThreadProgress.h @@ -17,6 +17,12 @@ public: HRESULT Result; NWindows::NSynchronization::CAutoResetEvent ProgressEvent; NWindows::NSynchronization::CAutoResetEvent WaitEvent; + + HRes Create() + { + RINOK(ProgressEvent.CreateIfNotCreated()); + return WaitEvent.CreateIfNotCreated(); + } void Init() { ProgressEvent.Reset(); diff --git a/CPP/7zip/Archive/Cpio/CpioHandler.h b/CPP/7zip/Archive/Cpio/CpioHandler.h index 39702541..eed1a06a 100755 --- a/CPP/7zip/Archive/Cpio/CpioHandler.h +++ b/CPP/7zip/Archive/Cpio/CpioHandler.h @@ -16,7 +16,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Deb/DebHandler.h b/CPP/7zip/Archive/Deb/DebHandler.h index 47de0224..4419dcdd 100755 --- a/CPP/7zip/Archive/Deb/DebHandler.h +++ b/CPP/7zip/Archive/Deb/DebHandler.h @@ -16,7 +16,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/DllExports2.cpp b/CPP/7zip/Archive/DllExports2.cpp index cdf00346..216afdb1 100755 --- a/CPP/7zip/Archive/DllExports2.cpp +++ b/CPP/7zip/Archive/DllExports2.cpp @@ -19,6 +19,7 @@ extern "C" HINSTANCE g_hInstance; #ifndef _UNICODE +#ifdef _WIN32 bool g_IsNT = false; static bool IsItWindowsNT() { @@ -29,6 +30,7 @@ static bool IsItWindowsNT() return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); } #endif +#endif extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) @@ -37,8 +39,10 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) { g_hInstance = hInstance; #ifndef _UNICODE + #ifdef _WIN32 g_IsNT = IsItWindowsNT(); #endif + #endif #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES) SetLargePageSize(); #endif diff --git a/CPP/7zip/Archive/GZip/GZipHandler.h b/CPP/7zip/Archive/GZip/GZipHandler.h index ace3c657..c1f8968b 100755 --- a/CPP/7zip/Archive/GZip/GZipHandler.h +++ b/CPP/7zip/Archive/GZip/GZipHandler.h @@ -23,8 +23,7 @@ class CHandler: public CMyUnknownImp { public: - MY_QUERYINTERFACE_BEGIN - MY_QUERYINTERFACE_ENTRY(IInArchive) + MY_QUERYINTERFACE_BEGIN2(IInArchive) MY_QUERYINTERFACE_ENTRY(IOutArchive) MY_QUERYINTERFACE_ENTRY(ISetProperties) QUERY_ENTRY_ISetCompressCodecsInfo @@ -79,7 +78,8 @@ private: void InitMethodProperties() { m_Method.NumMatchFinderCyclesDefined = false; - m_Level = m_Method.NumPasses = m_Method.NumFastBytes = m_Method.NumMatchFinderCycles = 0xFFFFFFFF; + m_Level = m_Method.NumPasses = m_Method.NumFastBytes = + m_Method.NumMatchFinderCycles = m_Method.Algo = 0xFFFFFFFF; } }; diff --git a/CPP/7zip/Archive/GZip/GZipHandlerOut.cpp b/CPP/7zip/Archive/GZip/GZipHandlerOut.cpp index 906a324a..76cfd642 100755 --- a/CPP/7zip/Archive/GZip/GZipHandlerOut.cpp +++ b/CPP/7zip/Archive/GZip/GZipHandlerOut.cpp @@ -21,6 +21,9 @@ using namespace NTime; namespace NArchive { namespace NGZip { +static const UInt32 kAlgoX1 = 0; +static const UInt32 kAlgoX5 = 1; + static const UInt32 kNumPassesX1 = 1; static const UInt32 kNumPassesX7 = 3; static const UInt32 kNumPassesX9 = 10; @@ -137,6 +140,10 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt m_Method.NumFastBytes = (level >= 9 ? kNumFastBytesX9 : (level >= 7 ? kNumFastBytesX7 : kNumFastBytesX1)); + if (m_Method.Algo == 0xFFFFFFFF) + m_Method.Algo = + (level >= 5 ? kAlgoX5 : + kAlgoX1); return UpdateArchive( EXTERNAL_CODECS_VARS @@ -193,6 +200,12 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v m_Method.NumMatchFinderCycles = num; m_Method.NumMatchFinderCyclesDefined = true; } + else if (name.Left(1) == L"A") + { + UInt32 num = kAlgoX5; + RINOK(ParsePropValue(name.Mid(1), prop, num)); + m_Method.Algo = num; + } else return E_INVALIDARG; } diff --git a/CPP/7zip/Archive/GZip/GZipIn.cpp b/CPP/7zip/Archive/GZip/GZipIn.cpp index 69eb491e..44ed62f6 100755 --- a/CPP/7zip/Archive/GZip/GZipIn.cpp +++ b/CPP/7zip/Archive/GZip/GZipIn.cpp @@ -30,9 +30,9 @@ HRESULT CInArchive::ReadBytes(ISequentialInStream *inStream, void *data, UInt32 HRESULT CInArchive::ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc) { - HRESULT res = ReadBytes(inStream, &value, 1); + RINOK(ReadBytes(inStream, &value, 1)); crc = CRC_UPDATE_BYTE(crc, value); - return res; + return S_OK; } HRESULT CInArchive::ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc) diff --git a/CPP/7zip/Archive/GZip/GZipUpdate.cpp b/CPP/7zip/Archive/GZip/GZipUpdate.cpp index c9567245..17e27c9f 100755 --- a/CPP/7zip/Archive/GZip/GZipUpdate.cpp +++ b/CPP/7zip/Archive/GZip/GZipUpdate.cpp @@ -83,12 +83,14 @@ HRESULT UpdateArchive( NWindows::NCOM::CPropVariant properties[] = { + compressionMethod.Algo, compressionMethod.NumPasses, compressionMethod.NumFastBytes, compressionMethod.NumMatchFinderCycles }; PROPID propIDs[] = { + NCoderPropID::kAlgorithm, NCoderPropID::kNumPasses, NCoderPropID::kNumFastBytes, NCoderPropID::kMatchFinderCycles diff --git a/CPP/7zip/Archive/GZip/GZipUpdate.h b/CPP/7zip/Archive/GZip/GZipUpdate.h index 7ab92848..27a396bf 100755 --- a/CPP/7zip/Archive/GZip/GZipUpdate.h +++ b/CPP/7zip/Archive/GZip/GZipUpdate.h @@ -17,6 +17,7 @@ struct CCompressionMethodMode { UInt32 NumPasses; UInt32 NumFastBytes; + UInt32 Algo; bool NumMatchFinderCyclesDefined; UInt32 NumMatchFinderCycles; }; diff --git a/CPP/7zip/Archive/IArchive.h b/CPP/7zip/Archive/IArchive.h index d6cbe804..3ef26a75 100755 --- a/CPP/7zip/Archive/IArchive.h +++ b/CPP/7zip/Archive/IArchive.h @@ -48,7 +48,7 @@ namespace NArchive { kExtract = 0, kTest, - kSkip, + kSkip }; } namespace NOperationResult @@ -58,7 +58,7 @@ namespace NArchive kOK = 0, kUnSupportedMethod, kDataError, - kCRCError, + kCRCError }; } } @@ -69,7 +69,7 @@ namespace NArchive enum { kOK = 0, - kError, + kError }; } } diff --git a/CPP/7zip/Archive/Iso/IsoHandler.h b/CPP/7zip/Archive/Iso/IsoHandler.h index e545d2a7..07d75844 100755 --- a/CPP/7zip/Archive/Iso/IsoHandler.h +++ b/CPP/7zip/Archive/Iso/IsoHandler.h @@ -1,4 +1,4 @@ -// Tar/Handler.h +// Iso/Handler.h #ifndef __ISO_HANDLER_H #define __ISO_HANDLER_H diff --git a/CPP/7zip/Archive/Lzh/LzhHandler.h b/CPP/7zip/Archive/Lzh/LzhHandler.h index 2dc89494..35929793 100755 --- a/CPP/7zip/Archive/Lzh/LzhHandler.h +++ b/CPP/7zip/Archive/Lzh/LzhHandler.h @@ -15,7 +15,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *inStream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Nsis/NsisHandler.h b/CPP/7zip/Archive/Nsis/NsisHandler.h index e57cbad8..e180f70d 100755 --- a/CPP/7zip/Archive/Nsis/NsisHandler.h +++ b/CPP/7zip/Archive/Nsis/NsisHandler.h @@ -27,8 +27,7 @@ class CHandler: bool GetCompressedSize(int index, UInt32 &size); public: - MY_QUERYINTERFACE_BEGIN - MY_QUERYINTERFACE_ENTRY(IInArchive) + MY_QUERYINTERFACE_BEGIN2(IInArchive) QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_END MY_ADDREF_RELEASE diff --git a/CPP/7zip/Archive/Nsis/NsisIn.cpp b/CPP/7zip/Archive/Nsis/NsisIn.cpp index f14bf47c..8797a8e7 100755 --- a/CPP/7zip/Archive/Nsis/NsisIn.cpp +++ b/CPP/7zip/Archive/Nsis/NsisIn.cpp @@ -23,7 +23,9 @@ public: SignatureInitializer() { kSignature[0]--; }; } g_SignatureInitializer; +#ifdef NSIS_SCRIPT static const char *kCrLf = "\x0D\x0A"; +#endif UInt32 GetUInt32FromMemLE(const Byte *p) { @@ -245,6 +247,7 @@ enum EW_LOCKWINDOW }; +#ifdef NSIS_SCRIPT static CCommandPair kCommandPairs[] = { { 0, "Invalid" }, @@ -324,6 +327,7 @@ static CCommandPair kCommandPairs[] = { 6, "LockWindow" } }; +#endif static const char *kShellStrings[] = { diff --git a/CPP/7zip/Archive/RPM/RpmHandler.h b/CPP/7zip/Archive/RPM/RpmHandler.h index 484c6c54..ed0717f3 100755 --- a/CPP/7zip/Archive/RPM/RpmHandler.h +++ b/CPP/7zip/Archive/RPM/RpmHandler.h @@ -14,7 +14,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Rar/RarHandler.cpp b/CPP/7zip/Archive/Rar/RarHandler.cpp index 5cd3c15d..7dbcee3d 100755 --- a/CPP/7zip/Archive/Rar/RarHandler.cpp +++ b/CPP/7zip/Archive/Rar/RarHandler.cpp @@ -14,7 +14,7 @@ #include "../../IPassword.h" #include "../../Common/ProgressUtils.h" #include "../../Common/CreateCoder.h" -#include "../../Common/MethodID.h" +#include "../../Common/MethodId.h" #include "../../Common/FilterCoder.h" #include "../../Compress/Copy/CopyCoder.h" #include "../../Crypto/Rar20/Rar20Cipher.h" diff --git a/CPP/7zip/Archive/Rar/RarHandler.h b/CPP/7zip/Archive/Rar/RarHandler.h index d54fd4e5..96d5d241 100755 --- a/CPP/7zip/Archive/Rar/RarHandler.h +++ b/CPP/7zip/Archive/Rar/RarHandler.h @@ -18,7 +18,7 @@ class CHandler: public CMyUnknownImp { public: - MY_QUERYINTERFACE_BEGIN + MY_QUERYINTERFACE_BEGIN2(IInArchive) QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_END MY_ADDREF_RELEASE diff --git a/CPP/7zip/Archive/Rar/RarIn.cpp b/CPP/7zip/Archive/Rar/RarIn.cpp index b87199ce..7340cc1f 100755 --- a/CPP/7zip/Archive/Rar/RarIn.cpp +++ b/CPP/7zip/Archive/Rar/RarIn.cpp @@ -17,8 +17,6 @@ extern "C" namespace NArchive { namespace NRar { -static const char kEndOfString = '\0'; - void CInArchive::ThrowExceptionWithCode( CInArchiveException::CCauseType cause) { diff --git a/CPP/7zip/Archive/Rar/RarIn.h b/CPP/7zip/Archive/Rar/RarIn.h index 22262a74..83a4d193 100755 --- a/CPP/7zip/Archive/Rar/RarIn.h +++ b/CPP/7zip/Archive/Rar/RarIn.h @@ -24,7 +24,7 @@ public: kUnexpectedEndOfArchive = 0, kArchiveHeaderCRCError, kFileHeaderCRCError, - kIncorrectArchive, + kIncorrectArchive } Cause; CInArchiveException(CCauseType cause) : Cause(cause) {} diff --git a/CPP/7zip/Archive/Split/SplitHandler.h b/CPP/7zip/Archive/Split/SplitHandler.h index 8b3fcb70..a98dc0a6 100755 --- a/CPP/7zip/Archive/Split/SplitHandler.h +++ b/CPP/7zip/Archive/Split/SplitHandler.h @@ -17,7 +17,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP1(IInArchiveGetStream) + MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream) STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Z/ZHandler.h b/CPP/7zip/Archive/Z/ZHandler.h index 7abba29f..21165390 100755 --- a/CPP/7zip/Archive/Z/ZHandler.h +++ b/CPP/7zip/Archive/Z/ZHandler.h @@ -14,7 +14,7 @@ class CHandler: public CMyUnknownImp { public: - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(IInArchive) STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, diff --git a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp index 9d8737d8..0344f776 100755 --- a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp +++ b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp @@ -166,12 +166,14 @@ HRESULT CAddCommon::Compress( { NWindows::NCOM::CPropVariant properties[] = { + _options.Algo, _options.NumPasses, _options.NumFastBytes, _options.NumMatchFinderCycles }; PROPID propIDs[] = { + NCoderPropID::kAlgorithm, NCoderPropID::kNumPasses, NCoderPropID::kNumFastBytes, NCoderPropID::kMatchFinderCycles diff --git a/CPP/7zip/Archive/Zip/ZipCompressionMode.h b/CPP/7zip/Archive/Zip/ZipCompressionMode.h index f1c79918..650d4f35 100755 --- a/CPP/7zip/Archive/Zip/ZipCompressionMode.h +++ b/CPP/7zip/Archive/Zip/ZipCompressionMode.h @@ -13,6 +13,7 @@ struct CCompressionMethodMode { CRecordVector<Byte> MethodSequence; // bool MaximizeRatio; + UInt32 Algo; UInt32 NumPasses; UInt32 NumFastBytes; bool NumMatchFinderCyclesDefined; diff --git a/CPP/7zip/Archive/Zip/ZipHandler.cpp b/CPP/7zip/Archive/Zip/ZipHandler.cpp index 7f906999..c1185363 100755 --- a/CPP/7zip/Archive/Zip/ZipHandler.cpp +++ b/CPP/7zip/Archive/Zip/ZipHandler.cpp @@ -37,7 +37,7 @@ using namespace NTime; namespace NArchive { namespace NZip { -static const CMethodId kMethodId_Store = 0; +// static const CMethodId kMethodId_Store = 0; static const CMethodId kMethodId_ZipBase = 0x040100; static const CMethodId kMethodId_BZip2 = 0x040202; diff --git a/CPP/7zip/Archive/Zip/ZipHandler.h b/CPP/7zip/Archive/Zip/ZipHandler.h index 45dc8ad6..f7bf4cf1 100755 --- a/CPP/7zip/Archive/Zip/ZipHandler.h +++ b/CPP/7zip/Archive/Zip/ZipHandler.h @@ -27,8 +27,7 @@ class CHandler: public CMyUnknownImp { public: - MY_QUERYINTERFACE_BEGIN - MY_QUERYINTERFACE_ENTRY(IInArchive) + MY_QUERYINTERFACE_BEGIN2(IInArchive) MY_QUERYINTERFACE_ENTRY(IOutArchive) MY_QUERYINTERFACE_ENTRY(ISetProperties) QUERY_ENTRY_ISetCompressCodecsInfo @@ -73,6 +72,7 @@ private: int m_Level; int m_MainMethod; UInt32 m_DicSize; + UInt32 m_Algo; UInt32 m_NumPasses; UInt32 m_NumFastBytes; UInt32 m_NumMatchFinderCycles; @@ -91,6 +91,7 @@ private: { m_Level = -1; m_MainMethod = -1; + m_Algo = m_DicSize = m_NumPasses = m_NumFastBytes = diff --git a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp index ba5199dc..0ccd3727 100755 --- a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp +++ b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp @@ -24,6 +24,9 @@ using namespace NTime; namespace NArchive { namespace NZip { +static const UInt32 kDeflateAlgoX1 = 0; +static const UInt32 kDeflateAlgoX5 = 1; + static const UInt32 kDeflateNumPassesX1 = 1; static const UInt32 kDeflateNumPassesX7 = 3; static const UInt32 kDeflateNumPassesX9 = 10; @@ -238,6 +241,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt options.NumFastBytes = m_NumFastBytes; options.NumMatchFinderCycles = m_NumMatchFinderCycles; options.NumMatchFinderCyclesDefined = m_NumMatchFinderCyclesDefined; + options.Algo = m_Algo; #ifdef COMPRESS_MT options.NumThreads = _numThreads; #endif @@ -251,6 +255,10 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt options.NumFastBytes = (level >= 9 ? kNumFastBytesX9 : (level >= 7 ? kNumFastBytesX7 : kNumFastBytesX1)); + if (options.Algo == 0xFFFFFFFF) + options.Algo = + (level >= 5 ? kDeflateAlgoX5 : + kDeflateAlgoX1); } if (isBZip2) { @@ -386,6 +394,12 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v RINOK(ParseMtProp(name.Mid(2), prop, numProcessors, _numThreads)); #endif } + else if (name.Left(1) == L"A") + { + UInt32 num = kDeflateAlgoX5; + RINOK(ParsePropValue(name.Mid(1), prop, num)); + m_Algo = num; + } else return E_INVALIDARG; } diff --git a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp index 1934c357..86c2764b 100755 --- a/CPP/7zip/Archive/Zip/ZipItem.cpp +++ b/CPP/7zip/Archive/Zip/ZipItem.cpp @@ -38,8 +38,6 @@ bool CLocalItem::IsImplodeLiteralsOn() const return (Flags & NFileHeader::NFlags::kImplodeLiteralsOnMask) != 0; } -static const char *kUnknownAttributes = "Unknown file attributes"; - bool CLocalItem::IsDirectory() const { return NItemName::HasTailSlash(Name, GetCodePage()); diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp index e14cd693..8caa1409 100755 --- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp +++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp @@ -30,16 +30,6 @@ using namespace NSynchronization; namespace NArchive { namespace NZip { -class CCriticalSectionLock2 -{ - CCriticalSection *_object; - void Unlock() { if (_object != 0) _object->Leave(); } -public: - CCriticalSectionLock2(): _object(0) {} - void Set(CCriticalSection &object) { _object = &object; _object->Enter(); } - ~CCriticalSectionLock2() { Unlock(); } -}; - static const Byte kMadeByHostOS = NFileHeader::NHostOS::kFAT; static const Byte kExtractHostOS = NFileHeader::NHostOS::kFAT; @@ -135,7 +125,7 @@ static void SetItemInfoFromCompressingResult(const CCompressingResult &compressi #ifdef COMPRESS_MT -static DWORD WINAPI CoderThread(void *threadCoderInfo); +static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo); struct CThreadInfo { @@ -145,8 +135,8 @@ struct CThreadInfo #endif NWindows::CThread Thread; - CAutoResetEvent *CompressEvent; - CAutoResetEvent *CompressionCompletedEvent; + NWindows::NSynchronization::CAutoResetEvent CompressEvent; + NWindows::NSynchronization::CAutoResetEvent CompressionCompletedEvent; bool ExitThread; CMtCompressProgress *ProgressSpec; @@ -164,21 +154,18 @@ struct CThreadInfo UInt32 UpdateIndex; CThreadInfo(const CCompressionMethodMode &options): - CompressEvent(NULL), - CompressionCompletedEvent(NULL), ExitThread(false), ProgressSpec(0), OutStreamSpec(0), Coder(options) {} - void CreateEvents() + HRESULT CreateEvents() { - CompressEvent = new CAutoResetEvent(false); - CompressionCompletedEvent = new CAutoResetEvent(false); + RINOK(CompressEvent.CreateIfNotCreated()); + return CompressionCompletedEvent.CreateIfNotCreated(); } - bool CreateThread() { return Thread.Create(CoderThread, this); } - ~CThreadInfo(); + HRes CreateThread() { return Thread.Create(CoderThread, this); } void WaitAndCode(); void StopWaitClose() @@ -186,27 +173,19 @@ struct CThreadInfo ExitThread = true; if (OutStreamSpec != 0) OutStreamSpec->StopWriting(E_ABORT); - if (CompressEvent != NULL) - CompressEvent->Set(); + if (CompressEvent.IsCreated()) + CompressEvent.Set(); Thread.Wait(); Thread.Close(); } }; -CThreadInfo::~CThreadInfo() -{ - if (CompressEvent != NULL) - delete CompressEvent; - if (CompressionCompletedEvent != NULL) - delete CompressionCompletedEvent; -} - void CThreadInfo::WaitAndCode() { for (;;) { - CompressEvent->Lock(); + CompressEvent.Lock(); if (ExitThread) return; Result = Coder.Compress( @@ -216,11 +195,11 @@ void CThreadInfo::WaitAndCode() InStream, OutStream, Progress, CompressingResult); if (Result == S_OK && Progress) Result = Progress->SetRatioInfo(&CompressingResult.UnpackSize, &CompressingResult.PackSize); - CompressionCompletedEvent->Set(); + CompressionCompletedEvent.Set(); } } -static DWORD WINAPI CoderThread(void *threadCoderInfo) +static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo) { ((CThreadInfo *)threadCoderInfo)->WaitAndCode(); return 0; @@ -518,8 +497,7 @@ static HRESULT Update2( CRecordVector<int> threadIndices; // list threads in order of updateItems { - if (!memManager.AllocateSpaceAlways((size_t)numThreads * (kMemPerThread / kBlockSize))) - return E_OUTOFMEMORY; + RINOK(memManager.AllocateSpaceAlways((size_t)numThreads * (kMemPerThread / kBlockSize))); for(i = 0; i < updateItems.Size(); i++) refs.Refs.Add(CMemBlocks2()); @@ -534,15 +512,15 @@ static HRESULT Update2( threadInfo._codecsInfo = codecsInfo; threadInfo._externalCodecs = externalCodecs; #endif - threadInfo.CreateEvents(); + RINOK(threadInfo.CreateEvents()); threadInfo.OutStreamSpec = new COutMemStream(&memManager); + RINOK(threadInfo.OutStreamSpec->CreateEvents()); threadInfo.OutStream = threadInfo.OutStreamSpec; threadInfo.IsFree = true; threadInfo.ProgressSpec = new CMtCompressProgress(); threadInfo.Progress = threadInfo.ProgressSpec; threadInfo.ProgressSpec->Init(&mtCompressProgressMixer, (int)i); - if (!threadInfo.CreateThread()) - return ::GetLastError(); + RINOK(threadInfo.CreateThread()); } } int mtItemIndex = 0; @@ -601,10 +579,10 @@ static HRESULT Update2( threadInfo.OutStreamSpec->Init(); threadInfo.ProgressSpec->Reinit(); - threadInfo.CompressEvent->Set(); + threadInfo.CompressEvent.Set(); threadInfo.UpdateIndex = mtItemIndex - 1; - compressingCompletedEvents.Add(*threadInfo.CompressionCompletedEvent); + compressingCompletedEvents.Add(threadInfo.CompressionCompletedEvent); threadIndices.Add(i); break; } diff --git a/CPP/7zip/Bundles/Format7zExtract/makefile b/CPP/7zip/Bundles/Format7zExtract/makefile index a8549741..5926949f 100755 --- a/CPP/7zip/Bundles/Format7zExtract/makefile +++ b/CPP/7zip/Bundles/Format7zExtract/makefile @@ -126,6 +126,7 @@ CRYPTO_HASH_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\Threads.obj \ C_BRANCH_OBJS = \ $O\BranchARM.obj \ diff --git a/CPP/7zip/Bundles/Format7zExtractR/makefile b/CPP/7zip/Bundles/Format7zExtractR/makefile index 17a836dc..e2c1b838 100755 --- a/CPP/7zip/Bundles/Format7zExtractR/makefile +++ b/CPP/7zip/Bundles/Format7zExtractR/makefile @@ -95,7 +95,8 @@ LZMA_OPT_OBJS = \ C_OBJS = \ $O\Alloc.obj \ - $O\7zCrc.obj + $O\7zCrc.obj \ + $O\Threads.obj \ C_BRANCH_OBJS = \ $O\BranchARM.obj \ diff --git a/CPP/7zip/Bundles/Format7zF/Format7z.dsp b/CPP/7zip/Bundles/Format7zF/Format7z.dsp index 164fc24b..7a4bafb2 100755 --- a/CPP/7zip/Bundles/Format7zF/Format7z.dsp +++ b/CPP/7zip/Bundles/Format7zF/Format7z.dsp @@ -236,6 +236,10 @@ SOURCE=..\..\..\Windows\Synchronization.cpp SOURCE=..\..\..\Windows\Synchronization.h # End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Thread.h +# End Source File # End Group # Begin Group "Compress" @@ -785,14 +789,6 @@ SOURCE=..\..\Compress\Quantum\QuantumDecoder.h # PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Compress\Lzh\Lzh1Decoder.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Compress\Lzh\Lzh1Decoder.h -# End Source File -# Begin Source File - SOURCE=..\..\Compress\Lzh\LzhDecoder.cpp # End Source File # Begin Source File @@ -2346,5 +2342,61 @@ SOURCE=..\..\IPassword.h SOURCE=..\..\IProgress.h # End Source File # End Group +# Begin Source File + +SOURCE=..\..\Archive\Arj\arj.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\BZip2\bz2.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Cab\cab.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Cpio\cpio.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Deb\deb.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\GZip\gz.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Iso\Iso.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Lzh\lzh.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Rar\rar.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\RPM\rpm.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Split\Split.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Tar\tar.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Z\Z.ico +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Zip\zip.ico +# End Source File # End Target # End Project diff --git a/CPP/7zip/Bundles/SFXCon/Main.cpp b/CPP/7zip/Bundles/SFXCon/Main.cpp index 97efd2b8..c3122cd1 100755 --- a/CPP/7zip/Bundles/SFXCon/Main.cpp +++ b/CPP/7zip/Bundles/SFXCon/Main.cpp @@ -123,9 +123,7 @@ static const NRecursedType::EEnum kCommandRecursedDefault[kNumCommandForms] = // static const bool kTestExtractRecursedDefault = true; // static const bool kAddRecursedDefault = false; -static const int kMaxCmdLineSize = 1000; static const wchar_t *kUniversalWildcard = L"*"; -// static const int kMinNonSwitchWords = 1; static const int kCommandIndex = 0; static const char *kHelpString = @@ -416,13 +414,19 @@ int Main2( } else { + UInt64 numErrors = 0; HRESULT result = ListArchives( codecs, v1, v2, wildcardCensorHead, true, false, passwordEnabled, - password); + password, numErrors); + if (numErrors > 0) + { + g_StdOut << endl << "Errors: " << numErrors; + return NExitCode::kFatalError; + } if (result != S_OK) throw CSystemException(result); } diff --git a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp index 17ffd0df..abf7f22c 100755 --- a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp +++ b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp @@ -67,7 +67,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /W3 /Gm /GX /ZI /Od /I "..\..\..\..\\" /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "EXTRACT_ONLY" /D "_SFX" /D "NO_READ_FROM_CODER" /Yu"StdAfx.h" /FD /GZ /c +# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\..\\" /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "EXTRACT_ONLY" /D "_SFX" /D "NO_READ_FROM_CODER" /Yu"StdAfx.h" /FD /GZ /c # ADD BASE RSC /l 0x419 /d "_DEBUG" # ADD RSC /l 0x419 /d "_DEBUG" BSC32=bscmake.exe @@ -125,14 +125,6 @@ SOURCE=..\..\Archive\Common\CoderMixer2MT.h # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\CoderMixer2ST.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Archive\Common\CoderMixer2ST.h -# End Source File -# Begin Source File - SOURCE=..\..\Archive\Common\CrossThreadProgress.cpp # End Source File # Begin Source File @@ -801,6 +793,15 @@ SOURCE=..\..\..\..\C\Alloc.c SOURCE=..\..\..\..\C\Alloc.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # Begin Source File diff --git a/CPP/7zip/Bundles/SFXCon/makefile b/CPP/7zip/Bundles/SFXCon/makefile index 61edd86b..33bd52c4 100755 --- a/CPP/7zip/Bundles/SFXCon/makefile +++ b/CPP/7zip/Bundles/SFXCon/makefile @@ -118,6 +118,7 @@ CRYPTO_HASH_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\Threads.obj \ C_BRANCH_OBJS = \ $O\BranchX86.obj \ diff --git a/CPP/7zip/Bundles/SFXSetup/ExtractEngine.cpp b/CPP/7zip/Bundles/SFXSetup/ExtractEngine.cpp index a0df3042..210e52ae 100755 --- a/CPP/7zip/Bundles/SFXSetup/ExtractEngine.cpp +++ b/CPP/7zip/Bundles/SFXSetup/ExtractEngine.cpp @@ -40,7 +40,7 @@ struct CThreadExtracting ExtractCallbackSpec->ProgressDialog.MyClose(); return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadExtracting *)param)->Process(); } @@ -115,9 +115,8 @@ HRESULT ExtractArchive( if (showProgress) { - CThread thread; - if (!thread.Create(CThreadExtracting::MyThreadFunction, &extracter)) - throw 271824; + NWindows::CThread thread; + RINOK(thread.Create(CThreadExtracting::MyThreadFunction, &extracter)); UString title; #ifdef LANG diff --git a/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp b/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp index bf0194b9..b09dce22 100755 --- a/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp +++ b/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp @@ -710,6 +710,15 @@ SOURCE=..\..\..\..\C\Alloc.c SOURCE=..\..\..\..\C\Alloc.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # Begin Source File diff --git a/CPP/7zip/Bundles/SFXSetup/makefile b/CPP/7zip/Bundles/SFXSetup/makefile index 129d60cf..a93d0379 100755 --- a/CPP/7zip/Bundles/SFXSetup/makefile +++ b/CPP/7zip/Bundles/SFXSetup/makefile @@ -100,6 +100,7 @@ LZMA_OPT_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\Threads.obj \ C_BRANCH_OBJS = \ $O\BranchX86.obj \ diff --git a/CPP/7zip/Bundles/SFXWin/Main.cpp b/CPP/7zip/Bundles/SFXWin/Main.cpp index 9c85d6b7..39ca5306 100755 --- a/CPP/7zip/Bundles/SFXWin/Main.cpp +++ b/CPP/7zip/Bundles/SFXWin/Main.cpp @@ -15,6 +15,7 @@ #include "../../IPassword.h" #include "../../Archive/IArchive.h" #include "../../UI/Common/Extract.h" +#include "../../UI/Common/ExitCode.h" #include "../../UI/Explorer/MyMessages.h" #include "../../UI/GUI/ExtractGUI.h" @@ -31,13 +32,11 @@ static inline bool IsItWindowsNT() } #endif -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */) -{ - g_hInstance = (HINSTANCE)hInstance; - #ifndef _UNICODE - g_IsNT = IsItWindowsNT(); - #endif +static const wchar_t *kMemoryExceptionMessage = L"ERROR: Can't allocate required memory!"; +static const wchar_t *kUnknownExceptionMessage = L"ERROR: Unknown Error!"; +int APIENTRY WinMain2() +{ UString password; bool assumeYes = false; bool outputFolderDefined = false; @@ -116,9 +115,38 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR / outputFolderDefined ? outputFolder : fullPath.Left(fileNamePartStartIndex)); */ + if (result == S_OK) + { + return 0; + } + if (result == E_ABORT) + return NExitCode::kUserBreak; if (result == S_FALSE) - MyMessageBox(L"Archive is not supported"); - else if (result != S_OK && result != E_ABORT) + MyMessageBox(L"Error in archive"); + else ShowErrorMessage(0, result); - return 0; + return NExitCode::kFatalError; +} + +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */) +{ + g_hInstance = (HINSTANCE)hInstance; + #ifndef _UNICODE + g_IsNT = IsItWindowsNT(); + #endif + try + { + return WinMain2(); + } + catch(const CNewException &) + { + MyMessageBox(kMemoryExceptionMessage); + return (NExitCode::kMemoryError); + } + catch(...) + { + MyMessageBox(kUnknownExceptionMessage); + return NExitCode::kFatalError; + } } + diff --git a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp index 3e9b5c33..06c0020e 100755 --- a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp +++ b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp @@ -71,7 +71,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_SFXWIN32" /D "_WINDOWS" /D "_MBCS" /D "EXTRACT_ONLY" /D "NO_REGISTRY" /D "NO_READ_FROM_CODER" /D "_SFX" /Yu"StdAfx.h" /FD /GZ /c +# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_SFXWIN32" /D "_WINDOWS" /D "_MBCS" /D "EXTRACT_ONLY" /D "NO_REGISTRY" /D "NO_READ_FROM_CODER" /D "_SFX" /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" @@ -712,6 +712,14 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\NewHandler.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\NewHandler.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\String.cpp # End Source File # Begin Source File @@ -881,6 +889,15 @@ SOURCE=..\..\..\..\C\Alloc.c SOURCE=..\..\..\..\C\Alloc.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # Begin Source File diff --git a/CPP/7zip/Bundles/SFXWin/makefile b/CPP/7zip/Bundles/SFXWin/makefile index b883bcf5..a7e52be2 100755 --- a/CPP/7zip/Bundles/SFXWin/makefile +++ b/CPP/7zip/Bundles/SFXWin/makefile @@ -123,6 +123,7 @@ CRYPTO_HASH_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\Threads.obj \ C_BRANCH_OBJS = \ $O\BranchX86.obj \ diff --git a/CPP/7zip/Common/FileStreams.cpp b/CPP/7zip/Common/FileStreams.cpp index 8a000e4e..bd90ce79 100755 --- a/CPP/7zip/Common/FileStreams.cpp +++ b/CPP/7zip/Common/FileStreams.cpp @@ -25,7 +25,7 @@ bool CInFileStream::Open(LPCTSTR fileName) return File.Open(fileName); } -#ifdef _WIN32 +#ifdef USE_WIN_FILE #ifndef _UNICODE bool CInFileStream::Open(LPCWSTR fileName) { @@ -34,9 +34,23 @@ bool CInFileStream::Open(LPCWSTR fileName) #endif #endif +bool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite) +{ + return File.OpenShared(fileName, shareForWrite); +} + +#ifdef USE_WIN_FILE +#ifndef _UNICODE +bool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite) +{ + return File.OpenShared(fileName, shareForWrite); +} +#endif +#endif + STDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize) { - #ifdef _WIN32 + #ifdef USE_WIN_FILE UInt32 realProcessedSize; bool result = File.ReadPart(data, size, realProcessedSize); @@ -98,7 +112,7 @@ STDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, if(seekOrigin >= 3) return STG_E_INVALIDFUNCTION; - #ifdef _WIN32 + #ifdef USE_WIN_FILE UInt64 realNewPosition; bool result = File.Seek(offset, seekOrigin, realNewPosition); @@ -132,7 +146,7 @@ bool COutFileStream::Create(LPCTSTR fileName, bool createAlways) return File.Create(fileName, createAlways); } -#ifdef _WIN32 +#ifdef USE_WIN_FILE #ifndef _UNICODE bool COutFileStream::Create(LPCWSTR fileName, bool createAlways) { @@ -143,7 +157,7 @@ bool COutFileStream::Create(LPCWSTR fileName, bool createAlways) STDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize) { - #ifdef _WIN32 + #ifdef USE_WIN_FILE UInt32 realProcessedSize; bool result = File.WritePart(data, size, realProcessedSize); @@ -170,7 +184,7 @@ STDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, { if(seekOrigin >= 3) return STG_E_INVALIDFUNCTION; - #ifdef _WIN32 + #ifdef USE_WIN_FILE UInt64 realNewPosition; bool result = File.Seek(offset, seekOrigin, realNewPosition); @@ -192,7 +206,7 @@ STDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, STDMETHODIMP COutFileStream::SetSize(Int64 newSize) { - #ifdef _WIN32 + #ifdef USE_WIN_FILE UInt64 currentPos; if(!File.Seek(0, FILE_CURRENT, currentPos)) return E_FAIL; diff --git a/CPP/7zip/Common/FileStreams.h b/CPP/7zip/Common/FileStreams.h index 9326372a..a65c96e1 100755 --- a/CPP/7zip/Common/FileStreams.h +++ b/CPP/7zip/Common/FileStreams.h @@ -4,6 +4,10 @@ #define __FILESTREAMS_H #ifdef _WIN32 +#define USE_WIN_FILE +#endif + +#ifdef USE_WIN_FILE #include "../../Windows/FileIO.h" #else #include "../../Common/C_FileIO.h" @@ -18,7 +22,7 @@ class CInFileStream: public CMyUnknownImp { public: - #ifdef _WIN32 + #ifdef USE_WIN_FILE NWindows::NFile::NIO::CInFile File; #else NC::NFile::NIO::CInFile File; @@ -27,12 +31,19 @@ public: virtual ~CInFileStream() {} bool Open(LPCTSTR fileName); - #ifdef _WIN32 + #ifdef USE_WIN_FILE #ifndef _UNICODE bool Open(LPCWSTR fileName); #endif #endif + bool OpenShared(LPCTSTR fileName, bool shareForWrite); + #ifdef USE_WIN_FILE + #ifndef _UNICODE + bool OpenShared(LPCWSTR fileName, bool shareForWrite); + #endif + #endif + MY_UNKNOWN_IMP2(IInStream, IStreamGetSize) STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); @@ -62,14 +73,14 @@ class COutFileStream: public CMyUnknownImp { public: - #ifdef _WIN32 + #ifdef USE_WIN_FILE NWindows::NFile::NIO::COutFile File; #else NC::NFile::NIO::COutFile File; #endif virtual ~COutFileStream() {} bool Create(LPCTSTR fileName, bool createAlways); - #ifdef _WIN32 + #ifdef USE_WIN_FILE #ifndef _UNICODE bool Create(LPCWSTR fileName, bool createAlways); #endif diff --git a/CPP/7zip/Common/InMemStream.cpp b/CPP/7zip/Common/InMemStream.cpp index 036ef3bd..7deef250 100755 --- a/CPP/7zip/Common/InMemStream.cpp +++ b/CPP/7zip/Common/InMemStream.cpp @@ -108,13 +108,13 @@ HRESULT CInMemStreamMt::Read() } } -static DWORD WINAPI CoderThread(void *threadCoderInfo) +static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo) { ((CInMemStreamMt *)threadCoderInfo)->ReadResult = ((CInMemStreamMt *)threadCoderInfo)->Read(); return 0; } -bool CInMemStreamMt::StartReadThread() +HRes CInMemStreamMt::StartReadThread() { // _stopReading = false; NWindows::CThread Thread; diff --git a/CPP/7zip/Common/InMemStream.h b/CPP/7zip/Common/InMemStream.h index fcd0092d..73f344ee 100755 --- a/CPP/7zip/Common/InMemStream.h +++ b/CPP/7zip/Common/InMemStream.h @@ -82,11 +82,12 @@ class CResourceListMt: public CResourceList public: NWindows::NSynchronization::CSemaphore Semaphore; - bool AllocateList(int numItems) + HRes AllocateList(int numItems) { if (!CResourceList::AllocateList(numItems)) return false; - return Semaphore.Create((LONG)numItems, (LONG)numItems); + Semaphore.Close(); + return Semaphore.Create(numItems, numItems); } int AllocateItem() @@ -118,15 +119,15 @@ public: CIntQueueMt(): _numItems(0), _head(0), _cur(0) {} NWindows::NSynchronization::CSemaphore Semaphore; - bool AllocateList(int numItems) + HRes AllocateList(int numItems) { FreeList(); if (numItems == 0) - return true; + return S_OK; if (!CIntListCheck::AllocateList(numItems)) - return false; + return E_OUTOFMEMORY; _numItems = numItems; - return Semaphore.Create((LONG)0, (LONG)numItems); + return Semaphore.Create(0, numItems); } void FreeList() @@ -142,10 +143,8 @@ public: _data[_head++] = value; if (_head == _numItems) _head = 0; - LONG previousCount; - Semaphore.Release(1, &previousCount); + Semaphore.Release(); // printf("\nRelease prev = %d\n", previousCount); - } int GetItem() @@ -253,7 +252,7 @@ public: // to stop reading you must implement // returning Error in IInMemStreamMtCallback::AllocateBlock // and then you must free at least one substream - bool StartReadThread(); + HRes StartReadThread(); void Free(); diff --git a/CPP/7zip/Common/LSBFEncoder.cpp b/CPP/7zip/Common/LSBFEncoder.cpp index 6322cae3..7809a8f6 100755 --- a/CPP/7zip/Common/LSBFEncoder.cpp +++ b/CPP/7zip/Common/LSBFEncoder.cpp @@ -8,22 +8,4 @@ namespace NStream { namespace NLSBF { -void CEncoder::WriteBits(UInt32 value, int numBits) -{ - while(numBits > 0) - { - if (numBits < m_BitPos) - { - m_CurByte |= (value & ((1 << numBits) - 1)) << (8 - m_BitPos); - m_BitPos -= numBits; - return; - } - numBits -= m_BitPos; - m_Stream.WriteByte((Byte)(m_CurByte | (value << (8 - m_BitPos)))); - value >>= m_BitPos; - m_BitPos = 8; - m_CurByte = 0; - } -} - }} diff --git a/CPP/7zip/Common/LSBFEncoder.h b/CPP/7zip/Common/LSBFEncoder.h index 72c84d9f..d50aef0b 100755 --- a/CPP/7zip/Common/LSBFEncoder.h +++ b/CPP/7zip/Common/LSBFEncoder.h @@ -38,7 +38,23 @@ public: m_CurByte = 0; } - void WriteBits(UInt32 value, int numBits); + void WriteBits(UInt32 value, int numBits) + { + while(numBits > 0) + { + if (numBits < m_BitPos) + { + m_CurByte |= (value & ((1 << numBits) - 1)) << (8 - m_BitPos); + m_BitPos -= numBits; + return; + } + numBits -= m_BitPos; + m_Stream.WriteByte((Byte)(m_CurByte | (value << (8 - m_BitPos)))); + value >>= m_BitPos; + m_BitPos = 8; + m_CurByte = 0; + } + } UInt32 GetBitPosition() const { return (8 - m_BitPos); } UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; } diff --git a/CPP/7zip/Common/MemBlocks.cpp b/CPP/7zip/Common/MemBlocks.cpp index d2b79a70..15702957 100755 --- a/CPP/7zip/Common/MemBlocks.cpp +++ b/CPP/7zip/Common/MemBlocks.cpp @@ -51,26 +51,27 @@ void CMemBlockManager::FreeBlock(void *p) } -bool CMemBlockManagerMt::AllocateSpace(size_t numBlocks, size_t numNoLockBlocks) +HRes CMemBlockManagerMt::AllocateSpace(size_t numBlocks, size_t numNoLockBlocks) { if (numNoLockBlocks > numBlocks) - return false; + return E_INVALIDARG; if (!CMemBlockManager::AllocateSpace(numBlocks)) - return false; + return E_OUTOFMEMORY; size_t numLockBlocks = numBlocks - numNoLockBlocks; + Semaphore.Close(); return Semaphore.Create((LONG)numLockBlocks, (LONG)numLockBlocks); } -bool CMemBlockManagerMt::AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks) +HRes CMemBlockManagerMt::AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks) { if (numNoLockBlocks > desiredNumberOfBlocks) - return false; + return E_INVALIDARG; for (;;) { - if (AllocateSpace(desiredNumberOfBlocks, numNoLockBlocks)) - return true; + if (AllocateSpace(desiredNumberOfBlocks, numNoLockBlocks) == 0) + return 0; if (desiredNumberOfBlocks == numNoLockBlocks) - return false; + return E_OUTOFMEMORY; desiredNumberOfBlocks = numNoLockBlocks + ((desiredNumberOfBlocks - numNoLockBlocks) >> 1); } } @@ -152,16 +153,17 @@ void CMemLockBlocks::Free(CMemBlockManagerMt *memManager) TotalSize = 0; } -bool CMemLockBlocks::SwitchToNoLockMode(CMemBlockManagerMt *memManager) +HRes CMemLockBlocks::SwitchToNoLockMode(CMemBlockManagerMt *memManager) { if (LockMode) { if (Blocks.Size() > 0) - if (!memManager->ReleaseLockedBlocks(Blocks.Size())) - return false; + { + RINOK(memManager->ReleaseLockedBlocks(Blocks.Size())); + } LockMode = false; } - return true; + return 0; } void CMemLockBlocks::Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager) diff --git a/CPP/7zip/Common/MemBlocks.h b/CPP/7zip/Common/MemBlocks.h index c33f712c..b93f6398 100755 --- a/CPP/7zip/Common/MemBlocks.h +++ b/CPP/7zip/Common/MemBlocks.h @@ -41,12 +41,12 @@ public: CMemBlockManagerMt(size_t blockSize = (1 << 20)): CMemBlockManager(blockSize) {} ~CMemBlockManagerMt() { FreeSpace(); } - bool AllocateSpace(size_t numBlocks, size_t numNoLockBlocks = 0); - bool AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks = 0); + HRes AllocateSpace(size_t numBlocks, size_t numNoLockBlocks = 0); + HRes AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks = 0); void FreeSpace(); void *AllocateBlock(); void FreeBlock(void *p, bool lockMode = true); - bool ReleaseLockedBlocks(int number) { return Semaphore.Release(number); } + HRes ReleaseLockedBlocks(int number) { return Semaphore.Release(number); } }; @@ -70,7 +70,7 @@ struct CMemLockBlocks: public CMemBlocks CMemLockBlocks(): LockMode(true) {}; void Free(CMemBlockManagerMt *memManager); void FreeBlock(int index, CMemBlockManagerMt *memManager); - bool SwitchToNoLockMode(CMemBlockManagerMt *memManager); + HRes SwitchToNoLockMode(CMemBlockManagerMt *memManager); void Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager); }; diff --git a/CPP/7zip/Common/MethodId.cpp b/CPP/7zip/Common/MethodId.cpp index 5a0c80aa..1eed8fc1 100755 --- a/CPP/7zip/Common/MethodId.cpp +++ b/CPP/7zip/Common/MethodId.cpp @@ -1,8 +1,8 @@ -// MethodID.cpp +// MethodId.cpp #include "StdAfx.h" -#include "MethodID.h" +#include "MethodId.h" #include "../../Common/String.h" static inline wchar_t GetHex(Byte value) diff --git a/CPP/7zip/Common/MethodId.h b/CPP/7zip/Common/MethodId.h index 42306326..54ebc9f7 100755 --- a/CPP/7zip/Common/MethodId.h +++ b/CPP/7zip/Common/MethodId.h @@ -1,4 +1,4 @@ -// MethodID.h +// MethodId.h #ifndef __7Z_METHOD_ID_H #define __7Z_METHOD_ID_H diff --git a/CPP/7zip/Common/OutMemStream.h b/CPP/7zip/Common/OutMemStream.h index a8bd1711..5ffcea2f 100755 --- a/CPP/7zip/Common/OutMemStream.h +++ b/CPP/7zip/Common/OutMemStream.h @@ -30,6 +30,12 @@ class COutMemStream: public: + HRes CreateEvents() + { + RINOK(StopWritingEvent.CreateIfNotCreated()); + return WriteToRealStreamEvent.CreateIfNotCreated(); + } + void SetOutStream(IOutStream *outStream) { OutStream = outStream; diff --git a/CPP/7zip/Common/RegisterCodec.h b/CPP/7zip/Common/RegisterCodec.h index 6ce4a7f8..1f1cd4df 100755 --- a/CPP/7zip/Common/RegisterCodec.h +++ b/CPP/7zip/Common/RegisterCodec.h @@ -3,7 +3,7 @@ #ifndef __REGISTERCODEC_H #define __REGISTERCODEC_H -#include "../Common/MethodID.h" +#include "../Common/MethodId.h" typedef void * (*CreateCodecP)(); struct CCodecInfo diff --git a/CPP/7zip/Common/StreamBinder.cpp b/CPP/7zip/Common/StreamBinder.cpp index f83939cb..5db9d01f 100755 --- a/CPP/7zip/Common/StreamBinder.cpp +++ b/CPP/7zip/Common/StreamBinder.cpp @@ -51,31 +51,20 @@ STDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, // CStreamBinder // (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished. -void CStreamBinder::CreateEvents() +HRes CStreamBinder::CreateEvents() { - _allBytesAreWritenEvent = new CManualResetEvent(true); - _thereAreBytesToReadEvent = new CManualResetEvent(false); - _readStreamIsClosedEvent = new CManualResetEvent(false); + RINOK(_allBytesAreWritenEvent.Create(true)); + RINOK(_thereAreBytesToReadEvent.Create()); + return _readStreamIsClosedEvent.Create(); } void CStreamBinder::ReInit() { - _thereAreBytesToReadEvent->Reset(); - _readStreamIsClosedEvent->Reset(); + _thereAreBytesToReadEvent.Reset(); + _readStreamIsClosedEvent.Reset(); ProcessedSize = 0; } -CStreamBinder::~CStreamBinder() -{ - if (_allBytesAreWritenEvent != NULL) - delete _allBytesAreWritenEvent; - if (_thereAreBytesToReadEvent != NULL) - delete _thereAreBytesToReadEvent; - if (_readStreamIsClosedEvent != NULL) - delete _readStreamIsClosedEvent; -} - - void CStreamBinder::CreateStreams(ISequentialInStream **inStream, @@ -103,8 +92,7 @@ HRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize) UInt32 sizeToRead = size; if (size > 0) { - if(!_thereAreBytesToReadEvent->Lock()) - return E_FAIL; + RINOK(_thereAreBytesToReadEvent.Lock()); sizeToRead = MyMin(_bufferSize, size); if (_bufferSize > 0) { @@ -113,8 +101,8 @@ HRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize) _bufferSize -= sizeToRead; if (_bufferSize == 0) { - _thereAreBytesToReadEvent->Reset(); - _allBytesAreWritenEvent->Set(); + _thereAreBytesToReadEvent.Reset(); + _allBytesAreWritenEvent.Set(); } } } @@ -126,7 +114,7 @@ HRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize) void CStreamBinder::CloseRead() { - _readStreamIsClosedEvent->Set(); + _readStreamIsClosedEvent.Set(); } HRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize) @@ -135,12 +123,12 @@ HRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSiz { _buffer = data; _bufferSize = size; - _allBytesAreWritenEvent->Reset(); - _thereAreBytesToReadEvent->Set(); + _allBytesAreWritenEvent.Reset(); + _thereAreBytesToReadEvent.Set(); HANDLE events[2]; - events[0] = *_allBytesAreWritenEvent; - events[1] = *_readStreamIsClosedEvent; + events[0] = _allBytesAreWritenEvent; + events[1] = _readStreamIsClosedEvent; DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE); if (waitResult != WAIT_OBJECT_0 + 0) { @@ -158,5 +146,5 @@ HRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSiz void CStreamBinder::CloseWrite() { // _bufferSize must be = 0 - _thereAreBytesToReadEvent->Set(); + _thereAreBytesToReadEvent.Set(); } diff --git a/CPP/7zip/Common/StreamBinder.h b/CPP/7zip/Common/StreamBinder.h index a66c3acb..1de2372a 100755 --- a/CPP/7zip/Common/StreamBinder.h +++ b/CPP/7zip/Common/StreamBinder.h @@ -8,21 +8,16 @@ class CStreamBinder { - NWindows::NSynchronization::CManualResetEvent *_allBytesAreWritenEvent; - NWindows::NSynchronization::CManualResetEvent *_thereAreBytesToReadEvent; - NWindows::NSynchronization::CManualResetEvent *_readStreamIsClosedEvent; + NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent; + NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent; + NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent; UInt32 _bufferSize; const void *_buffer; public: // bool ReadingWasClosed; UInt64 ProcessedSize; - CStreamBinder(): - _allBytesAreWritenEvent(NULL), - _thereAreBytesToReadEvent(NULL), - _readStreamIsClosedEvent(NULL) - {} - ~CStreamBinder(); - void CreateEvents(); + CStreamBinder() {} + HRes CreateEvents(); void CreateStreams(ISequentialInStream **inStream, ISequentialOutStream **outStream); diff --git a/CPP/7zip/Compress/Arj/ArjDecoder1.cpp b/CPP/7zip/Compress/Arj/ArjDecoder1.cpp index 7f720807..dda3721a 100755 --- a/CPP/7zip/Compress/Arj/ArjDecoder1.cpp +++ b/CPP/7zip/Compress/Arj/ArjDecoder1.cpp @@ -14,7 +14,7 @@ static const UInt32 kHistorySize = 26624; static const UInt32 kMatchMaxLen = 256; static const UInt32 kMatchMinLen = 3; -static const UInt32 kNC = 255 + kMatchMaxLen + 2 - kMatchMinLen; +// static const UInt32 kNC = 255 + kMatchMaxLen + 2 - kMatchMinLen; void CCoder::MakeTable(int nchar, Byte *bitlen, int tablebits, UInt32 *table, int tablesize) diff --git a/CPP/7zip/Compress/Arj/ArjDecoder2.cpp b/CPP/7zip/Compress/Arj/ArjDecoder2.cpp index a734d1b4..24c101d1 100755 --- a/CPP/7zip/Compress/Arj/ArjDecoder2.cpp +++ b/CPP/7zip/Compress/Arj/ArjDecoder2.cpp @@ -9,7 +9,7 @@ namespace NArj { namespace NDecoder2 { static const UInt32 kHistorySize = 26624; -static const UInt32 kMatchMaxLen = 256; +// static const UInt32 kMatchMaxLen = 256; static const UInt32 kMatchMinLen = 3; STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp index 703d528b..354ed03e 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp +++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp @@ -420,7 +420,7 @@ static UInt32 NO_INLINE DecodeBlock2Rand(const UInt32 *tt, UInt32 blockSize, UIn #ifdef COMPRESS_BZIP2_MT -static DWORD WINAPI MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; } +static THREAD_FUNC_DECL MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; } CDecoder::CDecoder(): m_States(0) @@ -434,35 +434,40 @@ CDecoder::~CDecoder() Free(); } -bool CDecoder::Create() +HRes CDecoder::Create() { + RINOK(CanProcessEvent.CreateIfNotCreated()); + RINOK(CanStartWaitingEvent.CreateIfNotCreated()); + if (m_States != 0 && m_NumThreadsPrev == NumThreads) + return true; + Free(); + MtMode = (NumThreads > 1); + m_NumThreadsPrev = NumThreads; try { - if (m_States != 0 && m_NumThreadsPrev == NumThreads) - return true; - Free(); - MtMode = (NumThreads > 1); - m_NumThreadsPrev = NumThreads; m_States = new CState[NumThreads]; if (m_States == 0) - return false; - #ifdef COMPRESS_BZIP2_MT - for (UInt32 t = 0; t < NumThreads; t++) + return E_OUTOFMEMORY; + } + catch(...) { return E_OUTOFMEMORY; } + #ifdef COMPRESS_BZIP2_MT + for (UInt32 t = 0; t < NumThreads; t++) + { + CState &ti = m_States[t]; + ti.Decoder = this; + if (MtMode) { - CState &ti = m_States[t]; - ti.Decoder = this; - if (MtMode) - if (!ti.Thread.Create(MFThread, &ti)) - { - NumThreads = t; - Free(); - return false; - } + HRes res = ti.Thread.Create(MFThread, &ti); + if (res != S_OK) + { + NumThreads = t; + Free(); + return res; + } } - #endif } - catch(...) { return false; } - return true; + #endif + return S_OK; } void CDecoder::Free() @@ -517,13 +522,13 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress) { #ifdef COMPRESS_BZIP2_MT Progress = progress; - if (!Create()) - return E_FAIL; + RINOK(Create()); for (UInt32 t = 0; t < NumThreads; t++) { CState &s = m_States[t]; if (!s.Alloc()) return E_OUTOFMEMORY; + RINOK(s.Create()); s.StreamWasFinishedEvent.Reset(); s.WaitingWasStartedEvent.Reset(); s.CanWriteEvent.Reset(); diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.h b/CPP/7zip/Compress/BZip2/BZip2Decoder.h index f7a1c6bb..d38ababe 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Decoder.h +++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.h @@ -53,6 +53,12 @@ struct CState void FinishStream(); void ThreadFunc(); + HRes Create() + { + RINOK(StreamWasFinishedEvent.CreateIfNotCreated()); + RINOK(WaitingWasStartedEvent.CreateIfNotCreated()); + return CanWriteEvent.CreateIfNotCreated(); + } #endif CState(): Counters(0) {} @@ -125,7 +131,7 @@ public: UInt32 BlockSizeMax; CDecoder(); ~CDecoder(); - bool Create(); + HRes Create(); void Free(); #else diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp index 5e555813..f1e53cd6 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp +++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp @@ -26,14 +26,14 @@ const int kMaxHuffmanLenForEncoding = 16; // it must be < kMaxHuffmanLen = 20 static const UInt32 kBufferSize = (1 << 17); static const int kNumHuffPasses = 4; -bool CThreadInfo::Create() +bool CThreadInfo::Alloc() { - if (m_BlockSorterIndex != 0) - return true; - m_BlockSorterIndex = (UInt32 *)::BigAlloc(BLOCK_SORT_BUF_SIZE(kBlockSizeMax) * sizeof(UInt32)); if (m_BlockSorterIndex == 0) - return false; - + { + m_BlockSorterIndex = (UInt32 *)::BigAlloc(BLOCK_SORT_BUF_SIZE(kBlockSizeMax) * sizeof(UInt32)); + if (m_BlockSorterIndex == 0) + return false; + } if (m_Block == 0) { @@ -111,7 +111,7 @@ DWORD CThreadInfo::ThreadFunc() } } -static DWORD WINAPI MFThread(void *threadCoderInfo) +static THREAD_FUNC_DECL MFThread(void *threadCoderInfo) { return ((CThreadInfo *)threadCoderInfo)->ThreadFunc(); } @@ -135,33 +135,38 @@ CEncoder::~CEncoder() Free(); } -bool CEncoder::Create() +HRes CEncoder::Create() { + RINOK(CanProcessEvent.CreateIfNotCreated()); + RINOK(CanStartWaitingEvent.CreateIfNotCreated()); + if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads) + return S_OK; try { - if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads) - return true; Free(); MtMode = (NumThreads > 1); m_NumThreadsPrev = NumThreads; ThreadsInfo = new CThreadInfo[NumThreads]; if (ThreadsInfo == 0) - return false; - for (UInt32 t = 0; t < NumThreads; t++) + return E_OUTOFMEMORY; + } + catch(...) { return E_OUTOFMEMORY; } + for (UInt32 t = 0; t < NumThreads; t++) + { + CThreadInfo &ti = ThreadsInfo[t]; + ti.Encoder = this; + if (MtMode) { - CThreadInfo &ti = ThreadsInfo[t]; - ti.Encoder = this; - if (MtMode) - if (!ti.Thread.Create(MFThread, &ti)) - { - NumThreads = t; - Free(); - return false; - } + HRes res = ti.Thread.Create(MFThread, &ti); + if (res != S_OK) + { + NumThreads = t; + Free(); + return res; + } } } - catch(...) { return false; } - return true; + return S_OK; } void CEncoder::Free() @@ -712,8 +717,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, { #ifdef COMPRESS_BZIP2_MT Progress = progress; - if (!Create()) - return E_FAIL; + RINOK(Create()); for (UInt32 t = 0; t < NumThreads; t++) #endif { @@ -729,8 +733,9 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, ti.m_OptimizeNumTables = m_OptimizeNumTables; - if (!ti.Create()) + if (!ti.Alloc()) return E_OUTOFMEMORY; + RINOK(ti.Create()); } diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.h b/CPP/7zip/Compress/BZip2/BZip2Encoder.h index c05a0481..eff93bc7 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Encoder.h +++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.h @@ -130,11 +130,17 @@ public: UInt64 m_PackSize; Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size. + HRes Create() + { + RINOK(StreamWasFinishedEvent.Create()); + RINOK(WaitingWasStartedEvent.Create()); + return CanWriteEvent.Create(); + } #endif CThreadInfo(): m_BlockSorterIndex(0), m_Block(0) {} ~CThreadInfo() { Free(); } - bool Create(); + bool Alloc(); void Free(); HRESULT EncodeBlock3(UInt32 blockSize); @@ -189,7 +195,7 @@ public: void WriteCRC(UInt32 v); #ifdef COMPRESS_BZIP2_MT - bool Create(); + HRes Create(); void Free(); #endif diff --git a/CPP/7zip/Compress/Branch/x86_2.cpp b/CPP/7zip/Compress/Branch/x86_2.cpp index 6f3a2f3c..178587b6 100755 --- a/CPP/7zip/Compress/Branch/x86_2.cpp +++ b/CPP/7zip/Compress/Branch/x86_2.cpp @@ -8,8 +8,6 @@ extern "C" #include "../../../../C/Alloc.h" } -static const int kBufferSize = 1 << 17; - inline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); @@ -17,6 +15,8 @@ inline bool IsJcc(Byte b0, Byte b1) #ifndef EXTRACT_ONLY +static const int kBufferSize = 1 << 17; + static bool inline Test86MSByte(Byte b) { return (b == 0 || b == 0xFF); diff --git a/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp b/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp index a574fa3c..ac68ff35 100755 --- a/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp +++ b/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp @@ -104,6 +104,8 @@ CCoder::CCoder(bool deflate64Mode): m_NumPasses(1), m_NumDivPasses(1), m_NumFastBytes(32), + _fastMode(false), + _btMode(true), m_OnePosMatchesMemory(0), m_DistanceMemory(0), m_Created(false), @@ -157,7 +159,7 @@ HRESULT CCoder::Create() if (!m_Created) { - _lzInWindow.btMode = 1; + _lzInWindow.btMode = _btMode ? 1 : 0; _lzInWindow.numHashBytes = 3; if (!MatchFinder_Create(&_lzInWindow, m_Deflate64Mode ? kHistorySize64 : kHistorySize32, @@ -213,6 +215,15 @@ HRESULT CCoder::BaseSetEncoderProperties2(const PROPID *propIDs, m_MatchFinderCycles = prop.ulVal; break; } + case NCoderPropID::kAlgorithm: + { + if (prop.vt != VT_UI4) + return E_INVALIDARG; + UInt32 maximize = prop.ulVal; + _fastMode = (maximize == 0); + _btMode = !_fastMode; + break; + } default: return E_INVALIDARG; } @@ -238,7 +249,7 @@ CCoder::~CCoder() MatchFinder_Free(&_lzInWindow, &g_Alloc); } -void CCoder::GetMatches() +NO_INLINE void CCoder::GetMatches() { if (m_IsMultiPass) { @@ -252,7 +263,10 @@ void CCoder::GetMatches() UInt32 distanceTmp[kMatchMaxLen * 2 + 3]; - UInt32 numPairs = Bt3Zip_MatchFinder_GetMatches(&_lzInWindow, distanceTmp); + UInt32 numPairs = (_btMode) ? + Bt3Zip_MatchFinder_GetMatches(&_lzInWindow, distanceTmp): + Hc3Zip_MatchFinder_GetMatches(&_lzInWindow, distanceTmp); + *m_MatchDistances = (UInt16)numPairs; if (numPairs > 0) @@ -285,7 +299,10 @@ void CCoder::MovePos(UInt32 num) { if (!m_SecondPass && num > 0) { - Bt3Zip_MatchFinder_Skip(&_lzInWindow, num); + if (_btMode) + Bt3Zip_MatchFinder_Skip(&_lzInWindow, num); + else + Hc3Zip_MatchFinder_Skip(&_lzInWindow, num); m_AdditionalOffset += num; } } @@ -420,6 +437,18 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes) } } +UInt32 CCoder::GetOptimalFast(UInt32 &backRes) +{ + GetMatches(); + UInt32 numDistancePairs = m_MatchDistances[0]; + if (numDistancePairs == 0) + return 1; + UInt32 lenMain = m_MatchDistances[numDistancePairs - 1]; + backRes = m_MatchDistances[numDistancePairs]; + MovePos(lenMain - 1); + return lenMain; +} + void CTables::InitStructures() { UInt32 i; @@ -489,8 +518,13 @@ NO_INLINE void CCoder::LevelTableDummy(const Byte *levels, int numLevels, UInt32 } } +NO_INLINE void CCoder::WriteBits(UInt32 value, int numBits) +{ + m_OutStream.WriteBits(value, numBits); +} + #define WRITE_HF2(codes, lens, i) m_OutStream.WriteBits(codes[i], lens[i]) -#define WRITE_HF(i) m_OutStream.WriteBits(codes[i], lens[i]) +#define WRITE_HF(i) WriteBits(codes[i], lens[i]) NO_INLINE void CCoder::LevelTableCode(const Byte *levels, int numLevels, const Byte *lens, const UInt32 *codes) { @@ -523,17 +557,17 @@ NO_INLINE void CCoder::LevelTableCode(const Byte *levels, int numLevels, const B count--; } WRITE_HF(kTableLevelRepNumber); - m_OutStream.WriteBits(count - 3, 2); + WriteBits(count - 3, 2); } else if (count <= 10) { WRITE_HF(kTableLevel0Number); - m_OutStream.WriteBits(count - 3, 3); + WriteBits(count - 3, 3); } else { WRITE_HF(kTableLevel0Number2); - m_OutStream.WriteBits(count - 11, 7); + WriteBits(count - 11, 7); } count = 0; @@ -602,7 +636,11 @@ NO_INLINE void CCoder::TryBlock() break; } UInt32 pos; - UInt32 len = GetOptimal(pos); + UInt32 len; + if (_fastMode) + len = GetOptimalFast(pos); + else + len = GetOptimal(pos); CCodeValue &codeValue = m_Values[m_ValueIndex++]; if (len >= kMatchMinLen) { @@ -629,6 +667,8 @@ NO_INLINE void CCoder::TryBlock() NO_INLINE void CCoder::SetPrices(const CLevels &levels) { + if (_fastMode) + return; UInt32 i; for(i = 0; i < 256; i++) { @@ -709,11 +749,11 @@ void CCoder::WriteStoreBlock(UInt32 blockSize, UInt32 additionalOffset, bool fin { UInt32 curBlockSize = (blockSize < (1 << 16)) ? blockSize : (1 << 16) - 1; blockSize -= curBlockSize; - m_OutStream.WriteBits((finalBlock && (blockSize == 0) ? NFinalBlockField::kFinalBlock: NFinalBlockField::kNotFinalBlock), kFinalBlockFieldSize); - m_OutStream.WriteBits(NBlockType::kStored, kBlockTypeFieldSize); + WriteBits((finalBlock && (blockSize == 0) ? NFinalBlockField::kFinalBlock: NFinalBlockField::kNotFinalBlock), kFinalBlockFieldSize); + WriteBits(NBlockType::kStored, kBlockTypeFieldSize); m_OutStream.FlushByte(); - m_OutStream.WriteBits((UInt16)curBlockSize, kStoredBlockLengthFieldSize); - m_OutStream.WriteBits((UInt16)~curBlockSize, kStoredBlockLengthFieldSize); + WriteBits((UInt16)curBlockSize, kStoredBlockLengthFieldSize); + WriteBits((UInt16)~curBlockSize, kStoredBlockLengthFieldSize); const Byte *data = Inline_MatchFinder_GetPointerToCurrentPos(&_lzInWindow)- additionalOffset; for(UInt32 i = 0; i < curBlockSize; i++) m_OutStream.WriteByte(data[i]); @@ -847,10 +887,10 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock) WriteStoreBlock(t.BlockSizeRes, m_AdditionalOffset, finalBlock); else { - m_OutStream.WriteBits((finalBlock ? NFinalBlockField::kFinalBlock: NFinalBlockField::kNotFinalBlock), kFinalBlockFieldSize); + WriteBits((finalBlock ? NFinalBlockField::kFinalBlock: NFinalBlockField::kNotFinalBlock), kFinalBlockFieldSize); if (t.StaticMode) { - m_OutStream.WriteBits(NBlockType::kFixedHuffman, kBlockTypeFieldSize); + WriteBits(NBlockType::kFixedHuffman, kBlockTypeFieldSize); TryFixedBlock(tableIndex); int i; for (i = 0; i < kFixedMainTableSize; i++) @@ -863,13 +903,13 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock) { if (m_NumDivPasses > 1 || m_CheckStatic) TryDynBlock(tableIndex, 1); - m_OutStream.WriteBits(NBlockType::kDynamicHuffman, kBlockTypeFieldSize); - m_OutStream.WriteBits(m_NumLitLenLevels - kNumLitLenCodesMin, kNumLenCodesFieldSize); - m_OutStream.WriteBits(m_NumDistLevels - kNumDistCodesMin, kNumDistCodesFieldSize); - m_OutStream.WriteBits(m_NumLevelCodes - kNumLevelCodesMin, kNumLevelCodesFieldSize); + WriteBits(NBlockType::kDynamicHuffman, kBlockTypeFieldSize); + WriteBits(m_NumLitLenLevels - kNumLitLenCodesMin, kNumLenCodesFieldSize); + WriteBits(m_NumDistLevels - kNumDistCodesMin, kNumDistCodesFieldSize); + WriteBits(m_NumLevelCodes - kNumLevelCodesMin, kNumLevelCodesFieldSize); for (UInt32 i = 0; i < m_NumLevelCodes; i++) - m_OutStream.WriteBits(m_LevelLevels[i], kLevelFieldSize); + WriteBits(m_LevelLevels[i], kLevelFieldSize); Huffman_ReverseBits(levelCodes, levelLens, kLevelTableSize); LevelTableCode(m_NewLevels.litLenLevels, m_NumLitLenLevels, levelLens, levelCodes); diff --git a/CPP/7zip/Compress/Deflate/DeflateEncoder.h b/CPP/7zip/Compress/Deflate/DeflateEncoder.h index 86eede6f..a7b2bb5b 100755 --- a/CPP/7zip/Compress/Deflate/DeflateEncoder.h +++ b/CPP/7zip/Compress/Deflate/DeflateEncoder.h @@ -24,7 +24,7 @@ struct CCodeValue UInt16 Len; UInt16 Pos; void SetAsLiteral() { Len = (1 << 15); } - bool IsLiteral() const { return ((Len & (1 << 15)) != 0); } + bool IsLiteral() const { return (Len >= (1 << 15)); } }; struct COptimal @@ -67,6 +67,8 @@ public: UInt16 *m_MatchDistances; UInt32 m_NumFastBytes; + bool _fastMode; + bool _btMode; UInt16 *m_OnePosMatchesMemory; UInt16 *m_DistanceMemory; @@ -123,8 +125,11 @@ public: void MovePos(UInt32 num); UInt32 Backward(UInt32 &backRes, UInt32 cur); UInt32 GetOptimal(UInt32 &backRes); + UInt32 GetOptimalFast(UInt32 &backRes); void LevelTableDummy(const Byte *levels, int numLevels, UInt32 *freqs); + + void WriteBits(UInt32 value, int numBits); void LevelTableCode(const Byte *levels, int numLevels, const Byte *lens, const UInt32 *codes); void MakeTables(); diff --git a/CPP/7zip/Compress/Implode/ImplodeDecoder.cpp b/CPP/7zip/Compress/Implode/ImplodeDecoder.cpp index 326afc0d..692f7c20 100755 --- a/CPP/7zip/Compress/Implode/ImplodeDecoder.cpp +++ b/CPP/7zip/Compress/Implode/ImplodeDecoder.cpp @@ -24,7 +24,7 @@ static const int kNumDistanceLowDirectBitsForSmallDict = 6; static const int kNumBitsInByte = 8; -static const int kLevelStructuresNumberFieldSize = kNumBitsInByte; +// static const int kLevelStructuresNumberFieldSize = kNumBitsInByte; static const int kLevelStructuresNumberAdditionalValue = 1; static const int kNumLevelStructureLevelBits = 4; @@ -51,8 +51,7 @@ static const UInt32 kMatchMinLenWhenLiteralsOff = 2; static const UInt32 kMatchMinLenMax = MyMax(kMatchMinLenWhenLiteralsOn, kMatchMinLenWhenLiteralsOff); // 3 -static const UInt32 kMatchMaxLenMax = kMatchMinLenMax + - (kLengthTableSize - 1) + (1 << kNumAdditionalLengthBits) - 1; // or 2 +// static const UInt32 kMatchMaxLenMax = kMatchMinLenMax + (kLengthTableSize - 1) + (1 << kNumAdditionalLengthBits) - 1; // or 2 enum { diff --git a/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp b/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp index a57b2a74..c2e2acbe 100755 --- a/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp +++ b/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp @@ -3,7 +3,18 @@ #include "StdAfx.h" #include <stdio.h> + +#ifdef _WIN32 +#define USE_ALLOCA +#endif + +#ifdef USE_ALLOCA +#ifdef _WIN32 #include <malloc.h> +#else +#include <stdlib.h> +#endif +#endif #include "../../../Common/Defs.h" #include "../../Common/StreamUtils.h" @@ -1266,8 +1277,10 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, { // _needReleaseMFStream = false; #ifdef COMPRESS_MF_MT + #ifdef USE_ALLOCA alloca(0x300); #endif + #endif CCoderReleaser coderReleaser(this); RINOK(SetStreams(inStream, outStream, inSize, outSize)); for (;;) diff --git a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp index dbfa6b59..9cea4cb1 100755 --- a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp +++ b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp @@ -265,6 +265,14 @@ SOURCE=..\..\..\Windows\Defs.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\IntToString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\IntToString.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\MyCom.h # End Source File # Begin Source File diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp index e8816184..b0f01099 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp @@ -5,10 +5,28 @@ #include "LzmaBench.h" #ifndef _WIN32 +#define USE_POSIX_TIME +#define USE_POSIX_TIME2 +#endif + +#ifdef USE_POSIX_TIME #include <time.h> +#ifdef USE_POSIX_TIME2 +#include <sys/time.h> +#endif +#endif + +#ifdef _WIN32 +#define USE_ALLOCA #endif +#ifdef USE_ALLOCA +#ifdef _WIN32 #include <malloc.h> +#else +#include <stdlib.h> +#endif +#endif extern "C" { @@ -35,12 +53,12 @@ static const UInt32 kAdditionalSize = (1 << 16); static const UInt32 kCompressedAdditionalSize = (1 << 10); static const UInt32 kMaxLzmaPropSize = 5; -class CRandomGenerator +class CBaseRandomGenerator { UInt32 A1; UInt32 A2; public: - CRandomGenerator() { Init(); } + CBaseRandomGenerator() { Init(); } void Init() { A1 = 362436069; A2 = 521288629;} UInt32 GetRnd() { @@ -75,9 +93,9 @@ public: class CBenchRandomGenerator: public CBenchBuffer { - CRandomGenerator *RG; + CBaseRandomGenerator *RG; public: - void Set(CRandomGenerator *rg) { RG = rg; } + void Set(CBaseRandomGenerator *rg) { RG = rg; } UInt32 GetVal(UInt32 &res, int numBits) { UInt32 val = res & (((UInt32)1 << numBits) - 1); @@ -217,49 +235,64 @@ STDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *process static UInt64 GetTimeCount() { - #ifdef _WIN32 + #ifdef USE_POSIX_TIME + #ifdef USE_POSIX_TIME2 + timeval v; + if (gettimeofday(&v, 0) == 0) + return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec; + return (UInt64)time(NULL) * 1000000; + #else + return time(NULL); + #endif + #else /* LARGE_INTEGER value; if (::QueryPerformanceCounter(&value)) return value.QuadPart; */ return GetTickCount(); - #else - return clock(); #endif } static UInt64 GetFreq() { - #ifdef _WIN32 + #ifdef USE_POSIX_TIME + #ifdef USE_POSIX_TIME2 + return 1000000; + #else + return 1; + #endif + #else /* LARGE_INTEGER value; if (::QueryPerformanceFrequency(&value)) return value.QuadPart; */ return 1000; - #else - return CLOCKS_PER_SEC; #endif } -UInt64 GetUserTime() +#ifndef USE_POSIX_TIME +static inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; } +#endif +static UInt64 GetUserTime() { - #ifdef _WIN32 - FILETIME creationTime, exitTime, kernelTime, userTime; - ::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime); - return ((UInt64)userTime.dwHighDateTime << 32) | userTime.dwLowDateTime; - #else + #ifdef USE_POSIX_TIME return clock(); + #else + FILETIME creationTime, exitTime, kernelTime, userTime; + if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0) + return GetTime64(userTime) + GetTime64(kernelTime); + return (UInt64)GetTickCount() * 10000; #endif } static UInt64 GetUserFreq() { - #ifdef _WIN32 - return 10000000; - #else + #ifdef USE_POSIX_TIME return CLOCKS_PER_SEC; + #else + return 10000000; #endif } @@ -435,13 +468,17 @@ struct CEncoderInfo CBenchProgressInfo *progressInfoSpec[2]; CMyComPtr<ICompressProgressInfo> progressInfo[2]; UInt32 NumIterations; + #ifdef USE_ALLOCA size_t AllocaSize; + #endif struct CDecoderInfo { CEncoderInfo *Encoder; UInt32 DecoderIndex; + #ifdef USE_ALLOCA size_t AllocaSize; + #endif bool CallbackMode; }; CDecoderInfo decodersInfo[2]; @@ -457,17 +494,19 @@ struct CEncoderInfo CBenchRandomGenerator rg; CBenchmarkOutStream *propStreamSpec; CMyComPtr<ISequentialOutStream> propStream; - HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CRandomGenerator *rg); + HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg); HRESULT Encode(); HRESULT Decode(UInt32 decoderIndex); CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {} #ifdef BENCH_MT - static DWORD WINAPI EncodeThreadFunction(void *param) + static THREAD_FUNC_DECL EncodeThreadFunction(void *param) { CEncoderInfo *encoder = (CEncoderInfo *)param; + #ifdef USE_ALLOCA alloca(encoder->AllocaSize); + #endif HRESULT res = encoder->Encode(); encoder->Results[0] = res; if (res != S_OK) @@ -475,38 +514,41 @@ struct CEncoderInfo return 0; } - static DWORD WINAPI DecodeThreadFunction(void *param) + static THREAD_FUNC_DECL DecodeThreadFunction(void *param) { CDecoderInfo *decoder = (CDecoderInfo *)param; + #ifdef USE_ALLOCA alloca(decoder->AllocaSize); + #endif CEncoderInfo *encoder = decoder->Encoder; encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex); return 0; } - HRESULT CreateEncoderThread(size_t allocaSize) + HRESULT CreateEncoderThread() { - AllocaSize = allocaSize; - if (!thread[0].Create(EncodeThreadFunction, this)) - return ::GetLastError(); - return 0; + return thread[0].Create(EncodeThreadFunction, this); } - HRESULT CreateDecoderThread(int index, bool callbackMode, size_t allocaSize) + HRESULT CreateDecoderThread(int index, bool callbackMode + #ifdef USE_ALLOCA + , size_t allocaSize + #endif + ) { CDecoderInfo &decoder = decodersInfo[index]; decoder.DecoderIndex = index; decoder.Encoder = this; + #ifdef USE_ALLOCA decoder.AllocaSize = allocaSize; + #endif decoder.CallbackMode = callbackMode; - if (!thread[index].Create(DecodeThreadFunction, &decoder)) - return ::GetLastError(); - return 0; + return thread[index].Create(DecodeThreadFunction, &decoder); } #endif }; -HRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CRandomGenerator *rgLoc) +HRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc) { rg.Set(rgLoc); kBufferSize = dictionarySize + kAdditionalSize; @@ -670,7 +712,7 @@ HRESULT LzmaBench( } } - CRandomGenerator rg; + CBaseRandomGenerator rg; rg.Init(); for (i = 0; i < numEncoderThreads; i++) { @@ -699,8 +741,10 @@ HRESULT LzmaBench( #ifdef BENCH_MT if (numEncoderThreads > 1) { - size_t allocaSize = (i * 16 * 21) & 0x7FF; - RINOK(encoder.CreateEncoderThread(allocaSize)) + #ifdef USE_ALLOCA + encoder.AllocaSize = (i * 16 * 21) & 0x7FF; + #endif + RINOK(encoder.CreateEncoderThread()) } else #endif @@ -753,7 +797,12 @@ HRESULT LzmaBench( for (UInt32 j = 0; j < numSubDecoderThreads; j++) { size_t allocaSize = ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF; - RINOK(encoder.CreateDecoderThread(j, (i == 0 && j == 0), allocaSize)) + HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0) + #ifdef USE_ALLOCA + , allocaSize + #endif + ); + RINOK(res); } } else @@ -842,7 +891,7 @@ struct CCrcInfo } }; -static DWORD WINAPI CrcThreadFunction(void *param) +static THREAD_FUNC_DECL CrcThreadFunction(void *param) { CCrcInfo *p = (CCrcInfo *)param; p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc); @@ -876,13 +925,13 @@ static UInt32 CrcCalc1(const Byte *buf, UInt32 size) return CRC_GET_DIGEST(crc); } -static void RandGen(Byte *buf, UInt32 size, CRandomGenerator &RG) +static void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG) { for (UInt32 i = 0; i < size; i++) buf[i] = (Byte)RG.GetRnd(); } -static UInt32 RandGenCrc(Byte *buf, UInt32 size, CRandomGenerator &RG) +static UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG) { RandGen(buf, size, RG); return CrcCalc1(buf, size); @@ -903,7 +952,7 @@ bool CrcInternalTest() UInt32 crc1 = CrcCalc1(buf, kBufferSize0); if (crc1 != 0x29058C73) return false; - CRandomGenerator RG; + CBaseRandomGenerator RG; RandGen(buf + kBufferSize0, kBufferSize1, RG); for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++) for (UInt32 j = 0; j < kCheckSize; j++) @@ -925,7 +974,7 @@ HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed) return E_OUTOFMEMORY; Byte *buf = buffer.Buffer; - CRandomGenerator RG; + CBaseRandomGenerator RG; UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1; UInt64 timeVal; @@ -948,8 +997,7 @@ HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed) for (i = 0; i < numThreads; i++) { CCrcInfo &info = threads.Items[i]; - if (!info.Thread.Create(CrcThreadFunction, &info)) - return ::GetLastError(); + RINOK(info.Thread.Create(CrcThreadFunction, &info)); threads.NumThreads++; } threads.WaitAll(); diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp index 669cbf98..fef5a9ad 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp @@ -6,6 +6,7 @@ #include "LzmaBench.h" #include "LzmaBenchCon.h" +#include "Common/IntToString.h" #if defined(BENCH_MT) || defined(_WIN32) #include "Windows/System.h" @@ -71,14 +72,24 @@ static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq) return value * freq / elTime; } +static void PrintNumber(FILE *f, UInt64 value, int size) +{ + char s[32]; + ConvertUInt64ToString(value, s); + fprintf(f, " "); + for (int len = (int)strlen(s); len < size; len++) + fprintf(f, " "); + fprintf(f, "%s", s); +} + static void PrintRating(FILE *f, UInt64 rating) { - fprintf(f, " %6d", (unsigned int)(rating / 1000000)); + PrintNumber(f, rating / 1000000, 6); } static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating) { - fprintf(f, " %5d", (usage + 5000) / 10000); + PrintNumber(f, (usage + 5000) / 10000, 5); PrintRating(f, rpu); PrintRating(f, rating); } @@ -87,7 +98,7 @@ static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating) static void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res) { UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq); - fprintf(f, "%7d", (unsigned int)(speed / 1024)); + PrintNumber(f, speed / 1024, 7); UInt64 usage = GetUsage(info); UInt64 rpu = GetRatingPerUsage(info, rating); PrintResults(f, usage, rpu, rating); @@ -119,7 +130,7 @@ HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final) return S_OK; } -static const char *kSep = " | "; +static const char *kSep = " | "; HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final) @@ -133,17 +144,19 @@ HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final) UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations); fprintf(f, kSep); CBenchInfo info2 = info; - info2.GlobalTime /= info.NumIterations; - info2.UserTime /= info.NumIterations; + info2.UnpackSize *= info2.NumIterations; + info2.PackSize *= info2.NumIterations; + info2.NumIterations = 1; PrintResults(f, info2, rating, DecodeRes); } return S_OK; } -static void PtintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads) +static void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads) { - fprintf(f, "\nRAM %s %5d MB, # %s %3d", sizeString, - (unsigned int)(size >> 20), threadsString, (unsigned int)numThreads); + fprintf(f, "\nRAM %s ", sizeString); + PrintNumber(f, (size >> 20), 5); + fprintf(f, " MB, # %s %3d", threadsString, (unsigned int)numThreads); } HRESULT LzmaBenchCon( @@ -157,7 +170,7 @@ HRESULT LzmaBenchCon( #ifdef BENCH_MT UInt64 ramSize = NWindows::NSystem::GetRamSize(); // UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors(); - PtintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs); + PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs); if (numThreads == (UInt32)-1) numThreads = numCPUs; if (numThreads > 1) @@ -176,24 +189,24 @@ HRESULT LzmaBenchCon( numThreads = 1; #endif - PtintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads); + PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads); CBenchCallback callback; callback.Init(); callback.f = f; - fprintf(f, "\n\nDict Compressing | Decompressing\n "); + fprintf(f, "\n\nDict Compressing | Decompressing\n "); int j; for (j = 0; j < 2; j++) { - fprintf(f, " Speed Usage R/U Rating"); + fprintf(f, " Speed Usage R/U Rating"); if (j == 0) fprintf(f, kSep); } - fprintf(f, "\n "); + fprintf(f, "\n "); for (j = 0; j < 2; j++) { - fprintf(f, " KB/s %% MIPS MIPS"); + fprintf(f, " KB/s %% MIPS MIPS"); if (j == 0) fprintf(f, kSep); } @@ -206,7 +219,7 @@ HRESULT LzmaBenchCon( pow--; for (; ((UInt32)1 << pow) <= dictionary; pow++) { - fprintf(f, "%2d: ", pow); + fprintf(f, "%2d:", pow); callback.dictionarySize = (UInt32)1 << pow; HRESULT res = LzmaBench( #ifdef EXTERNAL_LZMA @@ -245,7 +258,7 @@ HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dic #ifdef BENCH_MT UInt64 ramSize = NWindows::NSystem::GetRamSize(); UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors(); - PtintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs); + PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs); if (numThreads == (UInt32)-1) numThreads = numCPUs; #else @@ -280,7 +293,7 @@ HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dic return E_ABORT; #endif RINOK(CrcBench(ti + 1, bufSize, speed)); - fprintf(f, " %5d", (unsigned int)(speed >> 20)); + PrintNumber(f, (speed >> 20), 5); speedTotals.Values[ti] += speed; } fprintf(f, "\n"); @@ -291,7 +304,7 @@ HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dic { fprintf(f, "\nAvg:"); for (UInt32 ti = 0; ti < numThreads; ti++) - fprintf(f, " %5d", (unsigned int)((speedTotals.Values[ti] / numSteps) >> 20)); + PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5); fprintf(f, "\n"); } return S_OK; diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile b/CPP/7zip/Compress/LZMA_Alone/makefile index a41a3c53..b7e6ca0e 100755 --- a/CPP/7zip/Compress/LZMA_Alone/makefile +++ b/CPP/7zip/Compress/LZMA_Alone/makefile @@ -52,6 +52,7 @@ LZMA_OPT_OBJS = \ COMMON_OBJS = \ $O\CommandLineParser.obj \ $O\CRC.obj \ + $O\IntToString.obj \ $O\String.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc index 0c52cdc8..7696021e 100755 --- a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc +++ b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc @@ -10,27 +10,28 @@ OBJS = \ LzmaBench.o \ LzmaBenchCon.o \ LzmaRam.o \ - LzmaRamDecode.o \ - LzmaDecode.o \ - BranchX86.o \ LZMADecoder.o \ LZMAEncoder.o \ - 7zCrc.o \ - MatchFinder.o \ LZOutWindow.o \ RangeCoderBit.o \ InBuffer.o \ OutBuffer.o \ FileStreams.o \ StreamUtils.o \ - Alloc.o \ C_FileIO.o \ CommandLineParser.o \ CRC.o \ + IntToString.o \ String.o \ StringConvert.o \ StringToInt.o \ Vector.o \ + 7zCrc.o \ + Alloc.o \ + BranchX86.o \ + MatchFinder.o \ + LzmaDecode.o \ + LzmaRamDecode.o \ all: $(PROG) @@ -50,31 +51,12 @@ LzmaBenchCon.o: LzmaBenchCon.cpp LzmaRam.o: LzmaRam.cpp $(CXX) $(CFLAGS) LzmaRam.cpp -LzmaRamDecode.o: LzmaRamDecode.c - $(CXX_C) $(CFLAGS) LzmaRamDecode.c - -LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c - $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c - -BranchX86.o: ../../../../C/Compress/Branch/BranchX86.c - $(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c - LZMADecoder.o: ../LZMA/LZMADecoder.cpp $(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp $(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp -MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c - $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c - -7zCrc.o: ../../../../C/7zCrc.c - $(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c - -Alloc.o: ../../../../Alloc.cpp - $(CXX) $(CFLAGS) ../../../../Alloc.c - - LZOutWindow.o: ../LZ/LZOutWindow.cpp $(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp @@ -105,6 +87,9 @@ CRC.o: ../../../Common/CRC.cpp MyWindows.o: ../../../Common/MyWindows.cpp $(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp +IntToString.o: ../../../Common/IntToString.cpp + $(CXX) $(CFLAGS) ../../../Common/IntToString.cpp + String.o: ../../../Common/String.cpp $(CXX) $(CFLAGS) ../../../Common/String.cpp @@ -117,6 +102,24 @@ StringToInt.o: ../../../Common/StringToInt.cpp Vector.o: ../../../Common/Vector.cpp $(CXX) $(CFLAGS) ../../../Common/Vector.cpp +7zCrc.o: ../../../../C/7zCrc.c + $(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c + +Alloc.o: ../../../../C/Alloc.c + $(CXX_C) $(CFLAGS) ../../../../C/Alloc.c + +BranchX86.o: ../../../../C/Compress/Branch/BranchX86.c + $(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c + +MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c + $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c + +LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c + $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c + +LzmaRamDecode.o: LzmaRamDecode.c + $(CXX_C) $(CFLAGS) LzmaRamDecode.c + clean: -$(RM) $(PROG) $(OBJS) diff --git a/CPP/7zip/Compress/Lzh/LzhDecoder.cpp b/CPP/7zip/Compress/Lzh/LzhDecoder.cpp index 5a661047..36adf657 100755 --- a/CPP/7zip/Compress/Lzh/LzhDecoder.cpp +++ b/CPP/7zip/Compress/Lzh/LzhDecoder.cpp @@ -186,16 +186,20 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, m_OutWindowStream.PutByte((Byte)c); pos++; } - else + else if (c >= kNumCSymbols) + return S_FALSE; + else { // offset = (interface->method == LARC_METHOD_NUM) ? 0x100 - 2 : 0x100 - 3; UInt32 len = c - 256 + kMinMatch; UInt32 distance = m_PHuffmanDecoder.Decode(&m_InBitStream); if (distance != 0) distance = (1 << (distance - 1)) + ReadBits(distance - 1); - pos += len; if (distance >= pos) - throw 1; + return S_FALSE; + if (pos + len > *outSize) + len = (UInt32)(*outSize - pos); + pos += len; m_OutWindowStream.CopyBlock(distance, len); } } diff --git a/CPP/7zip/Compress/PPMD/PPMDContext.h b/CPP/7zip/Compress/PPMD/PPMDContext.h index a6a8dd60..2e955d32 100755 --- a/CPP/7zip/Compress/PPMD/PPMDContext.h +++ b/CPP/7zip/Compress/PPMD/PPMDContext.h @@ -135,14 +135,14 @@ struct CInfo SEE2Cont[i][k].init(5*i+10); } - void StartModelRare(int MaxOrder) + void StartModelRare(int maxOrder) { int i, k, m ,Step; EscCount=PrintCount=1; - if (MaxOrder < 2) + if (maxOrder < 2) { memset(CharMask,0,sizeof(CharMask)); - OrderFall = this->MaxOrder; + OrderFall = MaxOrder; MinContext = MaxContext; while (MinContext->Suffix != 0) { @@ -154,7 +154,7 @@ struct CInfo } else { - this->MaxOrder = MaxOrder; + MaxOrder = maxOrder; RestartModelRare(); NS2BSIndx[0] = 2 * 0; NS2BSIndx[1] = 2 * 1; diff --git a/CPP/7zip/Compress/Quantum/QuantumDecoder.cpp b/CPP/7zip/Compress/Quantum/QuantumDecoder.cpp index 5cf863bb..e870292d 100755 --- a/CPP/7zip/Compress/Quantum/QuantumDecoder.cpp +++ b/CPP/7zip/Compress/Quantum/QuantumDecoder.cpp @@ -8,7 +8,7 @@ namespace NCompress { namespace NQuantum { -const UInt32 kDictionarySizeMax = (1 << 21); +// const UInt32 kDictionarySizeMax = (1 << 21); const int kLenIdNeedInit = -2; diff --git a/CPP/7zip/Compress/Rar/Rar3Vm.h b/CPP/7zip/Compress/Rar/Rar3Vm.h index d0a4f82c..cc8bbcd7 100755 --- a/CPP/7zip/Compress/Rar/Rar3Vm.h +++ b/CPP/7zip/Compress/Rar/Rar3Vm.h @@ -79,7 +79,7 @@ namespace NGlobalOffset const UInt32 kBlockPos = 0x20; const UInt32 kExecCount = 0x2C; const UInt32 kGlobalMemOutSize = 0x30; -}; +} enum ECommand { diff --git a/CPP/7zip/Crypto/Rar20/Rar20Cipher.cpp b/CPP/7zip/Crypto/Rar20/Rar20Cipher.cpp index 27ccc493..333ab61c 100755 --- a/CPP/7zip/Crypto/Rar20/Rar20Cipher.cpp +++ b/CPP/7zip/Crypto/Rar20/Rar20Cipher.cpp @@ -8,8 +8,6 @@ namespace NCrypto { namespace NRar20 { -static const int kBufferSize = 1 << 17; - STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size) { _coder.SetPassword(data, size); @@ -34,43 +32,4 @@ STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size) return i; } -/* -STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, - ICompressProgressInfo *progress) -{ - UInt64 nowPos = 0; - UInt32 bufferPos = 0; - UInt32 processedSize; - for (;;) - { - UInt32 size = kBufferSize - bufferPos; - RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize)); - - UInt32 anEndPos = bufferPos + processedSize; - for (;bufferPos + 16 <= anEndPos; bufferPos += 16) - _coder.DecryptBlock(_buffer + bufferPos); - - if (bufferPos == 0) - return S_OK; - - if (outSize != NULL && nowPos + bufferPos > *outSize) - bufferPos = UInt32(*outSize - nowPos); - - RINOK(outStream->Write(_buffer, bufferPos, &processedSize)); - if (bufferPos != processedSize) - return E_FAIL; - - nowPos += processedSize; - if (outSize != NULL && nowPos == *outSize) - return S_OK; - - int i = 0; - while(bufferPos < anEndPos) - _buffer[i++] = _buffer[bufferPos++]; - bufferPos = i; - } -} -*/ - }} diff --git a/CPP/7zip/Crypto/RarAES/RarAES.cpp b/CPP/7zip/Crypto/RarAES/RarAES.cpp index bf14d65d..9adeedc5 100755 --- a/CPP/7zip/Crypto/RarAES/RarAES.cpp +++ b/CPP/7zip/Crypto/RarAES/RarAES.cpp @@ -4,7 +4,7 @@ #include "StdAfx.h" #include "RarAES.h" -#include "../../Common/MethodID.h" +#include "../../Common/MethodId.h" #include "../Hash/Sha1.h" #include "../AES/MyAES.h" diff --git a/CPP/7zip/FileManager/FM.dsp b/CPP/7zip/FileManager/FM.dsp index f84d19d1..5265a961 100755 --- a/CPP/7zip/FileManager/FM.dsp +++ b/CPP/7zip/FileManager/FM.dsp @@ -680,6 +680,15 @@ SOURCE=..\..\..\C\Sort.c SOURCE=..\..\..\C\Sort.h # End Source File +# Begin Source File + +SOURCE=..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\C\Threads.h +# End Source File # End Group # Begin Group "Windows" diff --git a/CPP/7zip/FileManager/PanelCopy.cpp b/CPP/7zip/FileManager/PanelCopy.cpp index 4b62b878..88a6a669 100755 --- a/CPP/7zip/FileManager/PanelCopy.cpp +++ b/CPP/7zip/FileManager/PanelCopy.cpp @@ -41,7 +41,7 @@ struct CThreadExtractInArchive2 return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadExtractInArchive2 *)param)->Extract(); } @@ -84,9 +84,8 @@ HRESULT CPanel::CopyTo(const CRecordVector<UInt32> &indices, const UString &fold extracter.FolderOperations = folderOperations; extracter.MoveMode = moveMode; - CThread extractThread; - if (!extractThread.Create(CThreadExtractInArchive2::MyThreadFunction, &extracter)) - throw 271824; + NWindows::CThread extractThread; + RINOK(extractThread.Create(CThreadExtractInArchive2::MyThreadFunction, &extracter)); extracter.ExtractCallbackSpec->StartProgressDialog(title); if (messages != 0) @@ -118,7 +117,7 @@ struct CThreadUpdate return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadUpdate *)param)->Process(); } @@ -161,9 +160,8 @@ HRESULT CPanel::CopyFrom(const UString &folderPrefix, const UStringVector &fileP for(i = 0; i < updater.FileNames.Size(); i++) updater.FileNamePointers.Add(updater.FileNames[i]); - CThread thread; - if (!thread.Create(CThreadUpdate::MyThreadFunction, &updater)) - throw 271824; + NWindows::CThread thread; + RINOK(thread.Create(CThreadUpdate::MyThreadFunction, &updater)); updater.UpdateCallbackSpec->StartProgressDialog(title); if (messages != 0) diff --git a/CPP/7zip/FileManager/PanelCrc.cpp b/CPP/7zip/FileManager/PanelCrc.cpp index 7a190840..5e49390f 100755 --- a/CPP/7zip/FileManager/PanelCrc.cpp +++ b/CPP/7zip/FileManager/PanelCrc.cpp @@ -253,7 +253,7 @@ struct CThreadCrc return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadCrc *)param)->Process(); } @@ -303,9 +303,9 @@ void CApp::CalculateCrc() progressDialog.MainTitle = progressWindowTitle; progressDialog.MainAddTitle = title + UString(L" "); - CThread thread; - if (!thread.Create(CThreadCrc::MyThreadFunction, &combiner)) - throw 271824; + NWindows::CThread thread; + if (thread.Create(CThreadCrc::MyThreadFunction, &combiner) != S_OK) + return; progressDialog.Create(title, _window); if (combiner.Result != S_OK) diff --git a/CPP/7zip/FileManager/PanelItemOpen.cpp b/CPP/7zip/FileManager/PanelItemOpen.cpp index be2d9024..25de271a 100755 --- a/CPP/7zip/FileManager/PanelItemOpen.cpp +++ b/CPP/7zip/FileManager/PanelItemOpen.cpp @@ -380,12 +380,16 @@ public: class CExitEventLauncher { public: - CManualResetEvent _exitEvent; - CExitEventLauncher(): _exitEvent(false) {}; + NWindows::NSynchronization::CManualResetEvent _exitEvent; + CExitEventLauncher() + { + if (_exitEvent.Create(false) != S_OK) + throw 9387173; + }; ~CExitEventLauncher() { _exitEvent.Set(); } } g_ExitEventLauncher; -static DWORD WINAPI MyThreadFunction(void *param) +static THREAD_FUNC_DECL MyThreadFunction(void *param) { CMyAutoPtr<CTmpProcessInfo> tmpProcessInfoPtr((CTmpProcessInfo *)param); CTmpProcessInfo *tmpProcessInfo = tmpProcessInfoPtr.get(); @@ -502,8 +506,8 @@ void CPanel::OpenItemInArchive(int index, bool tryInternal, bool tryExternal, tmpProcessInfo->ItemName = name; tmpProcessInfo->ProcessHandle = hProcess; - CThread thread; - if (!thread.Create(MyThreadFunction, tmpProcessInfo)) + NWindows::CThread thread; + if (thread.Create(MyThreadFunction, tmpProcessInfo) != S_OK) throw 271824; tempDirectory.DisableDeleting(); tmpProcessInfoPtr.release(); diff --git a/CPP/7zip/FileManager/PanelOperations.cpp b/CPP/7zip/FileManager/PanelOperations.cpp index 66993f39..40c03c13 100755 --- a/CPP/7zip/FileManager/PanelOperations.cpp +++ b/CPP/7zip/FileManager/PanelOperations.cpp @@ -45,7 +45,7 @@ struct CThreadDelete return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadDelete *)param)->Process(); } @@ -211,8 +211,8 @@ void CPanel::DeleteItemsInternal(CRecordVector<UInt32> &indices) deleter.FolderOperations = folderOperations; deleter.Indices = indices; - CThread thread; - if (!thread.Create(CThreadDelete::MyThreadFunction, &deleter)) + NWindows::CThread thread; + if (thread.Create(CThreadDelete::MyThreadFunction, &deleter) != S_OK) throw 271824; deleter.UpdateCallbackSpec->StartProgressDialog(progressTitle); diff --git a/CPP/7zip/FileManager/PanelSplitFile.cpp b/CPP/7zip/FileManager/PanelSplitFile.cpp index 7d4309d8..ac06623b 100755 --- a/CPP/7zip/FileManager/PanelSplitFile.cpp +++ b/CPP/7zip/FileManager/PanelSplitFile.cpp @@ -181,7 +181,7 @@ struct CThreadSplit return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadSplit *)param)->Process(); } @@ -280,8 +280,8 @@ void CApp::Split() // CPanel::CDisableTimerProcessing disableTimerProcessing1(srcPanel); // CPanel::CDisableTimerProcessing disableTimerProcessing2(destPanel); - CThread thread; - if (!thread.Create(CThreadSplit::MyThreadFunction, &spliter)) + NWindows::CThread thread; + if (thread.Create(CThreadSplit::MyThreadFunction, &spliter) != S_OK) throw 271824; progressDialog.Create(title, _window); @@ -395,7 +395,7 @@ struct CThreadCombine return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadCombine *)param)->Process(); } @@ -467,8 +467,8 @@ void CApp::Combine() // CPanel::CDisableTimerProcessing disableTimerProcessing1(srcPanel); // CPanel::CDisableTimerProcessing disableTimerProcessing2(destPanel); - CThread thread; - if (!thread.Create(CThreadCombine::MyThreadFunction, &combiner)) + NWindows::CThread thread; + if (thread.Create(CThreadCombine::MyThreadFunction, &combiner) != S_OK) throw 271824; progressDialog.Create(title, _window); diff --git a/CPP/7zip/FileManager/RegistryUtils.cpp b/CPP/7zip/FileManager/RegistryUtils.cpp index 22869c46..e9c13d19 100755 --- a/CPP/7zip/FileManager/RegistryUtils.cpp +++ b/CPP/7zip/FileManager/RegistryUtils.cpp @@ -10,7 +10,7 @@ using namespace NRegistry; static const TCHAR *kCUBasePath = TEXT("Software\\7-ZIP"); static const TCHAR *kCU_FMPath = TEXT("Software\\7-ZIP\\FM"); -static const TCHAR *kLM_Path = TEXT("Software\\7-ZIP\\FM"); +// static const TCHAR *kLM_Path = TEXT("Software\\7-ZIP\\FM"); static const WCHAR *kLangValueName = L"Lang"; static const WCHAR *kEditor = L"Editor"; @@ -21,7 +21,7 @@ static const TCHAR *kShowSystemMenu = TEXT("ShowSystemMenu"); static const TCHAR *kFullRow = TEXT("FullRow"); static const TCHAR *kShowGrid = TEXT("ShowGrid"); static const TCHAR *kAlternativeSelection = TEXT("AlternativeSelection"); -static const TCHAR *kLockMemoryAdd = TEXT("LockMemoryAdd"); +// static const TCHAR *kLockMemoryAdd = TEXT("LockMemoryAdd"); static const TCHAR *kLargePagesEnable = TEXT("LargePages"); // static const TCHAR *kSingleClick = TEXT("SingleClick"); // static const TCHAR *kUnderline = TEXT("Underline"); diff --git a/CPP/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.h b/CPP/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.h index e11ffc51..07f0d859 100755 --- a/CPP/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.h +++ b/CPP/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.h @@ -105,7 +105,10 @@ public: #ifndef _SFX ,MainWindow(0) #endif - {} + { + if (_dialogCreatedEvent.Create() != S_OK) + throw 1334987; + } void WaitCreating() { _dialogCreatedEvent.Lock(); } diff --git a/CPP/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.h b/CPP/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.h index 0625eadd..cd53c76e 100755 --- a/CPP/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.h +++ b/CPP/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.h @@ -163,7 +163,10 @@ public: #ifndef _SFX ,MainWindow(0) #endif - {} + { + if (_dialogCreatedEvent.Create() != S_OK) + throw 1334987; + } void WaitCreating() { _dialogCreatedEvent.Lock(); } diff --git a/CPP/7zip/FileManager/makefile b/CPP/7zip/FileManager/makefile index da745fe2..3a15cf2e 100755 --- a/CPP/7zip/FileManager/makefile +++ b/CPP/7zip/FileManager/makefile @@ -108,8 +108,9 @@ UI_COMMON_OBJS = \ $O\PropIDUtils.obj \ C_OBJS = \ - $O\Sort.obj \ $O\Alloc.obj \ + $O\Sort.obj \ + $O\Threads.obj \ !include "../Crc2.mak" diff --git a/CPP/7zip/MyVersion.h b/CPP/7zip/MyVersion.h index 3c47b2ab..d0bf2759 100755 --- a/CPP/7zip/MyVersion.h +++ b/CPP/7zip/MyVersion.h @@ -1,8 +1,8 @@ #define MY_VER_MAJOR 4 -#define MY_VER_MINOR 45 -#define MY_VER_BUILD 3 -#define MY_VERSION "4.45 beta" -#define MY_7ZIP_VERSION "7-Zip 4.45 beta" -#define MY_DATE "2007-04-17" +#define MY_VER_MINOR 46 +#define MY_VER_BUILD 2 +#define MY_VERSION "4.46 beta" +#define MY_7ZIP_VERSION "7-Zip 4.46 beta" +#define MY_DATE "2007-05-25" #define MY_COPYRIGHT "Copyright (c) 1999-2007 Igor Pavlov" #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE diff --git a/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp b/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp index 01eb4fed..5f62dc9c 100755 --- a/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp +++ b/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp @@ -8,8 +8,6 @@ #include "../Common/OpenArchive.h" -static const UInt64 kMaxCheckStartPosition = 1 << 20; - static inline UINT GetCurrentFileCodePage() { return AreFileApisANSI() ? CP_ACP : CP_OEMCP; } diff --git a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp index f9548024..17b04e12 100755 --- a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp @@ -2,7 +2,9 @@ #include "StdAfx.h" +#ifdef _WIN32 #include <io.h> +#endif #include <stdio.h> #include "Common/ListFileUtils.h" @@ -26,8 +28,6 @@ using namespace NCommandLineParser; using namespace NWindows; using namespace NFile; -static const int kNumSwitches = 28; - namespace NKey { enum Enum { @@ -58,7 +58,8 @@ enum Enum kShowDialog, kLargePages, kCharSet, - kTechMode + kTechMode, + kShareForWrite }; } @@ -92,7 +93,7 @@ NExtract::NOverwriteMode::EEnum k_OverwriteModes[] = NExtract::NOverwriteMode::kAutoRenameExisting }; -static const CSwitchForm kSwitchForms[kNumSwitches] = +static const CSwitchForm kSwitchForms[] = { { L"?", NSwitchType::kSimple, false }, { L"H", NSwitchType::kSimple, false }, @@ -121,10 +122,10 @@ static const CSwitchForm kSwitchForms[kNumSwitches] = { L"AD", NSwitchType::kSimple, false }, { L"SLP", NSwitchType::kUnLimitedPostString, false, 0}, { L"SCS", NSwitchType::kUnLimitedPostString, false, 0}, - { L"SLT", NSwitchType::kSimple, false } + { L"SLT", NSwitchType::kSimple, false }, + { L"SSW", NSwitchType::kSimple, false } }; - static const CCommandForm g_CommandForms[] = { { L"A", false }, @@ -140,7 +141,6 @@ static const CCommandForm g_CommandForms[] = static const int kNumCommandForms = sizeof(g_CommandForms) / sizeof(g_CommandForms[0]); -static const int kMaxCmdLineSize = 1000; static const wchar_t *kUniversalWildcard = L"*"; static const int kMinNonSwitchWords = 1; static const int kCommandIndex = 0; @@ -250,7 +250,7 @@ static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, return true; } -static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } +static inline UINT GetCurrentCodePage() { return AreFileApisANSI() ? CP_ACP : CP_OEMCP; } static void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor, LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage) @@ -346,9 +346,9 @@ static void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor, } { - NSynchronization::CEvent event; - event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)); - event.Set(); + NSynchronization::CManualResetEvent event; + if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK) + event.Set(); } } #endif @@ -666,7 +666,8 @@ static void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &pr } } -CArchiveCommandLineParser::CArchiveCommandLineParser(): parser(kNumSwitches) {} +CArchiveCommandLineParser::CArchiveCommandLineParser(): + parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {} void CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options) @@ -680,9 +681,9 @@ void CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings, ThrowUserErrorException(); } - options.IsInTerminal = (_isatty(_fileno(stdin)) != 0); - options.IsStdOutTerminal = (_isatty(_fileno(stdout)) != 0); - options.IsStdErrTerminal = (_isatty(_fileno(stderr)) != 0); + options.IsInTerminal = (isatty(fileno(stdin)) != 0); + options.IsStdOutTerminal = (isatty(fileno(stdout)) != 0); + options.IsStdErrTerminal = (isatty(fileno(stderr)) != 0); options.StdOutMode = parser[NKey::kStdOut].ThereIs; options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs; options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs || parser[NKey::kHelp3].ThereIs; @@ -895,6 +896,9 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) SetMethodOptions(parser, updateOptions.MethodMode.Properties); + if (parser[NKey::kShareForWrite].ThereIs) + updateOptions.OpenShareForWrite = true; + options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs; if (options.EnablePercents) diff --git a/CPP/7zip/UI/Common/CompressCall.cpp b/CPP/7zip/UI/Common/CompressCall.cpp index 8b858bd3..ccf4e287 100755 --- a/CPP/7zip/UI/Common/CompressCall.cpp +++ b/CPP/7zip/UI/Common/CompressCall.cpp @@ -39,7 +39,7 @@ static void AddLagePagesSwitch(UString ¶ms) HRESULT MyCreateProcess(const UString ¶ms, LPCWSTR curDir, bool waitFinish, - NWindows::NSynchronization::CEvent *event) + NWindows::NSynchronization::CBaseEvent *event) { const UString params2 = params; PROCESS_INFORMATION processInformation; @@ -114,9 +114,28 @@ static UString Get7zGuiPath() return GetQuotedString(path); } +static HRESULT CreateTempEvent(const wchar_t *name, + NSynchronization::CManualResetEvent &event, UString &eventName) +{ + CRandom random; + random.Init(GetTickCount()); + for (;;) + { + int number = random.Generate(); + wchar_t temp[32]; + ConvertUInt64ToString((UInt32)number, temp); + eventName = name; + eventName += temp; + RINOK(event.CreateWithName(false, GetSystemString(eventName))); + if (::GetLastError() != ERROR_ALREADY_EXISTS) + return S_OK; + event.Close(); + } +} + static HRESULT CreateMap(const UStringVector &names, const UString &id, - CFileMapping &fileMapping, NSynchronization::CEvent &event, + CFileMapping &fileMapping, NSynchronization::CManualResetEvent &event, UString ¶ms) { UInt32 extraSize = 2; @@ -126,7 +145,6 @@ static HRESULT CreateMap(const UStringVector &names, UInt32 totalSize = extraSize + dataSize; UString mappingName; - UString eventName; CRandom random; random.Init(GetTickCount()); @@ -146,20 +164,8 @@ static HRESULT CreateMap(const UStringVector &names, fileMapping.Close(); } - for (;;) - { - int number = random.Generate(); - wchar_t temp[32]; - ConvertUInt64ToString(UInt32(number), temp); - eventName = id; - eventName += L"MappingEndEvent"; - eventName += temp; - if (!event.Create(true, false, GetSystemString(eventName))) - return E_FAIL; - if (::GetLastError() != ERROR_ALREADY_EXISTS) - break; - event.Close(); - } + UString eventName; + RINOK(CreateTempEvent(id + L"MappingEndEvent", event, eventName)); params += mappingName; params += L":"; @@ -218,7 +224,6 @@ HRESULT CompressFiles( UInt32 totalSize = extraSize + dataSize; UString mappingName; - UString eventName; CFileMapping fileMapping; CRandom random; @@ -241,23 +246,9 @@ HRESULT CompressFiles( fileMapping.Close(); } - NSynchronization::CEvent event; - for (;;) - { - int number = random.Generate(); - wchar_t temp[32]; - ConvertUInt64ToString(UInt32(number), temp); - eventName = L"7zCompressMappingEndEvent"; - eventName += temp; - if (!event.Create(true, false, GetSystemString(eventName))) - { - // MyMessageBox(IDS_ERROR, 0x02000605); - return E_FAIL; - } - if (::GetLastError() != ERROR_ALREADY_EXISTS) - break; - event.Close(); - } + NSynchronization::CManualResetEvent event; + UString eventName; + RINOK(CreateTempEvent(L"7zCompressMappingEndEvent", event, eventName)); params += mappingName; params += L":"; @@ -337,7 +328,7 @@ static HRESULT ExtractGroupCommand(const UStringVector &archivePaths, params2 += kArchiveNoNameSwitch; params2 += kArchiveMapSwitch; CFileMapping fileMapping; - NSynchronization::CEvent event; + NSynchronization::CManualResetEvent event; RINOK(CreateMap(archivePaths, L"7zExtract", fileMapping, event, params2)); return MyCreateProcess(params2, 0, false, &event); } diff --git a/CPP/7zip/UI/Common/CompressCall.h b/CPP/7zip/UI/Common/CompressCall.h index 23e68838..db7e3647 100755 --- a/CPP/7zip/UI/Common/CompressCall.h +++ b/CPP/7zip/UI/Common/CompressCall.h @@ -8,7 +8,7 @@ HRESULT MyCreateProcess(const UString ¶ms, LPCWSTR lpCurrentDirectory, bool waitFinish, - NWindows::NSynchronization::CEvent *event); + NWindows::NSynchronization::CBaseEvent *event); HRESULT CompressFiles( const UString &curDir, diff --git a/CPP/7zip/UI/Common/IFileExtractCallback.h b/CPP/7zip/UI/Common/IFileExtractCallback.h index c70d7021..6268f758 100755 --- a/CPP/7zip/UI/Common/IFileExtractCallback.h +++ b/CPP/7zip/UI/Common/IFileExtractCallback.h @@ -14,7 +14,7 @@ namespace NOverwriteAnswer kNo, kNoToAll, kAutoRename, - kCancel, + kCancel }; } diff --git a/CPP/7zip/UI/Common/LoadCodecs.cpp b/CPP/7zip/UI/Common/LoadCodecs.cpp index bb6b9696..63b59045 100755 --- a/CPP/7zip/UI/Common/LoadCodecs.cpp +++ b/CPP/7zip/UI/Common/LoadCodecs.cpp @@ -58,6 +58,8 @@ static bool ReadPathFromRegistry(HKEY baseKey, CSysString &path) return false; } +#endif + CSysString GetBaseFolderPrefixFromRegistry() { CSysString moduleFolderPrefix = GetLibraryFolderPrefix(); @@ -71,8 +73,8 @@ CSysString GetBaseFolderPrefixFromRegistry() if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fileInfo)) if (fileInfo.IsDirectory()) return moduleFolderPrefix; - CSysString path; #ifdef _WIN32 + CSysString path; if (ReadPathFromRegistry(HKEY_CURRENT_USER, path)) return path; if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path)) @@ -81,9 +83,6 @@ CSysString GetBaseFolderPrefixFromRegistry() return moduleFolderPrefix; } -#endif - - typedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods); typedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats); typedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value); diff --git a/CPP/7zip/UI/Common/OpenArchive.h b/CPP/7zip/UI/Common/OpenArchive.h index d43c22b3..ebd89ceb 100755 --- a/CPP/7zip/UI/Common/OpenArchive.h +++ b/CPP/7zip/UI/Common/OpenArchive.h @@ -97,7 +97,7 @@ struct CArchiveLink IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; } UString GetDefaultItemName() { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; } - const int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; } + int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; } HRESULT Close(); void Release(); }; diff --git a/CPP/7zip/UI/Common/SortUtils.cpp b/CPP/7zip/UI/Common/SortUtils.cpp index c0111581..54d88adc 100755 --- a/CPP/7zip/UI/Common/SortUtils.cpp +++ b/CPP/7zip/UI/Common/SortUtils.cpp @@ -67,6 +67,7 @@ void SortStringsToIndices(const UStringVector &strings, CIntVector &indices) // TSort(&indices.Front(), indices.Size(), CompareStrings, (void *)&strings); } +/* void SortStrings(const UStringVector &src, UStringVector &dest) { CIntVector indices; @@ -76,3 +77,4 @@ void SortStrings(const UStringVector &src, UStringVector &dest) for (int i = 0; i < indices.Size(); i++) dest.Add(src[indices[i]]); } +*/
\ No newline at end of file diff --git a/CPP/7zip/UI/Common/SortUtils.h b/CPP/7zip/UI/Common/SortUtils.h index 5b9af264..b30bc6ca 100755 --- a/CPP/7zip/UI/Common/SortUtils.h +++ b/CPP/7zip/UI/Common/SortUtils.h @@ -6,6 +6,6 @@ #include "Common/String.h" void SortStringsToIndices(const UStringVector &strings, CIntVector &indices); -void SortStrings(const UStringVector &src, UStringVector &dest); +// void SortStrings(const UStringVector &src, UStringVector &dest); #endif diff --git a/CPP/7zip/UI/Common/Update.cpp b/CPP/7zip/UI/Common/Update.cpp index 3772b676..3c292754 100755 --- a/CPP/7zip/UI/Common/Update.cpp +++ b/CPP/7zip/UI/Common/Update.cpp @@ -46,11 +46,8 @@ using namespace NCOM; using namespace NFile; using namespace NName; -static const wchar_t *kTempArchiveFilePrefixString = L"7zi"; static const wchar_t *kTempFolderPrefix = L"7zE"; -static const char *kIllegalFileNameMessage = "Illegal file name for temp archive"; - using namespace NUpdateArchive; static HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream) @@ -277,6 +274,7 @@ static HRESULT Compress( const CCompressionMethodMode &compressionMethod, CArchivePath &archivePath, const CObjectVector<CArchiveItem> &archiveItems, + bool shareForWrite, bool stdInMode, /* const UString & stdInFileName, */ bool stdOutMode, @@ -338,6 +336,7 @@ static HRESULT Compress( CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec ); + updateCallbackSpec->ShareForWrite = shareForWrite; updateCallbackSpec->StdInMode = stdInMode; updateCallbackSpec->Callback = callback; updateCallbackSpec->DirItems = &dirItems; @@ -518,6 +517,7 @@ static HRESULT UpdateWithItemLists( options.MethodMode, command.ArchivePath, archiveItems, + options.OpenShareForWrite, options.StdInMode, /* options.StdInFileName, */ options.StdOutMode, diff --git a/CPP/7zip/UI/Common/Update.h b/CPP/7zip/UI/Common/Update.h index 284f8657..33f4eecd 100755 --- a/CPP/7zip/UI/Common/Update.h +++ b/CPP/7zip/UI/Common/Update.h @@ -99,6 +99,8 @@ struct CUpdateOptions bool SfxMode; UString SfxModule; + bool OpenShareForWrite; + bool StdInMode; UString StdInFileName; bool StdOutMode; @@ -117,7 +119,8 @@ struct CUpdateOptions StdInMode(false), StdOutMode(false), EMailMode(false), - EMailRemoveAfter(false) + EMailRemoveAfter(false), + OpenShareForWrite(false) {}; CRecordVector<UInt64> VolumesSizes; }; diff --git a/CPP/7zip/UI/Common/UpdateCallback.cpp b/CPP/7zip/UI/Common/UpdateCallback.cpp index db3bf805..6fc4242d 100755 --- a/CPP/7zip/UI/Common/UpdateCallback.cpp +++ b/CPP/7zip/UI/Common/UpdateCallback.cpp @@ -17,6 +17,7 @@ using namespace NWindows; CArchiveUpdateCallback::CArchiveUpdateCallback(): Callback(0), + ShareForWrite(false), StdInMode(false), DirItems(0), ArchiveItems(0), @@ -202,7 +203,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream CInFileStream *inStreamSpec = new CInFileStream; CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec); UString path = DirPrefix + dirItem.FullPath; - if(!inStreamSpec->Open(path)) + if(!inStreamSpec->OpenShared(path, ShareForWrite)) { return Callback->OpenFileError(path, ::GetLastError()); } diff --git a/CPP/7zip/UI/Common/UpdateCallback.h b/CPP/7zip/UI/Common/UpdateCallback.h index 8b14a9dc..cc4e2649 100755 --- a/CPP/7zip/UI/Common/UpdateCallback.h +++ b/CPP/7zip/UI/Common/UpdateCallback.h @@ -58,6 +58,7 @@ public: IUpdateCallbackUI *Callback; UString DirPrefix; + bool ShareForWrite; bool StdInMode; const CObjectVector<CDirItem> *DirItems; const CObjectVector<CArchiveItem> *ArchiveItems; diff --git a/CPP/7zip/UI/Common/ZipRegistry.cpp b/CPP/7zip/UI/Common/ZipRegistry.cpp index 8969a4ab..1f076caf 100755 --- a/CPP/7zip/UI/Common/ZipRegistry.cpp +++ b/CPP/7zip/UI/Common/ZipRegistry.cpp @@ -126,8 +126,8 @@ static const TCHAR *kCompressionShowPasswordValueName = TEXT("ShowPassword"); static const TCHAR *kCompressionEncryptHeadersValueName = TEXT("EncryptHeaders"); static const TCHAR *kCompressionOptionsKeyName = TEXT("Options"); -static const TCHAR *kSolid = TEXT("Solid"); -static const TCHAR *kMultiThread = TEXT("Multithread"); +// static const TCHAR *kSolid = TEXT("Solid"); +// static const TCHAR *kMultiThread = TEXT("Multithread"); static const WCHAR *kCompressionOptions = L"Options"; static const TCHAR *kCompressionLevel = TEXT("Level"); diff --git a/CPP/7zip/UI/Console/Console.dsp b/CPP/7zip/UI/Console/Console.dsp index 75c71330..64cac741 100755 --- a/CPP/7zip/UI/Console/Console.dsp +++ b/CPP/7zip/UI/Console/Console.dsp @@ -704,6 +704,15 @@ SOURCE=..\..\..\..\C\Alloc.c SOURCE=..\..\..\..\C\Alloc.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # End Target # End Project diff --git a/CPP/7zip/UI/Console/ConsoleClose.cpp b/CPP/7zip/UI/Console/ConsoleClose.cpp index a514c12a..d18b39e6 100755 --- a/CPP/7zip/UI/Console/ConsoleClose.cpp +++ b/CPP/7zip/UI/Console/ConsoleClose.cpp @@ -2,8 +2,6 @@ #include "StdAfx.h" -#include <stdio.h> - #include "ConsoleClose.h" static int g_BreakCounter = 0; diff --git a/CPP/7zip/UI/Console/List.cpp b/CPP/7zip/UI/Console/List.cpp index 3d7001d2..7891d5f3 100755 --- a/CPP/7zip/UI/Console/List.cpp +++ b/CPP/7zip/UI/Console/List.cpp @@ -396,15 +396,15 @@ HRESULT ListArchives( CCodecs *codecs, UStringVector &archivePaths, UStringVector &archivePathsFull, const NWildcard::CCensorNode &wildcardCensor, - bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password) + bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &numErrors) { + numErrors = 0; CFieldPrinter fieldPrinter; if (!techMode) fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0])); UInt64 numFiles2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0; UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0; - int numErrors = 0; for (int i = 0; i < archivePaths.Size(); i++) { const UString &archiveName = archivePaths[i]; @@ -528,7 +528,5 @@ HRESULT ListArchives( g_StdOut << endl; g_StdOut << "Archives: " << archivePaths.Size() << endl; } - if (numErrors > 0) - g_StdOut << endl << "Errors: " << numErrors; return S_OK; } diff --git a/CPP/7zip/UI/Console/List.h b/CPP/7zip/UI/Console/List.h index 2827bceb..6e9fa240 100755 --- a/CPP/7zip/UI/Console/List.h +++ b/CPP/7zip/UI/Console/List.h @@ -10,7 +10,7 @@ HRESULT ListArchives( CCodecs *codecs, UStringVector &archivePaths, UStringVector &archivePathsFull, const NWildcard::CCensorNode &wildcardCensor, - bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password); + bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &errors); #endif diff --git a/CPP/7zip/UI/Console/Main.cpp b/CPP/7zip/UI/Console/Main.cpp index 392bef03..4f0061b2 100755 --- a/CPP/7zip/UI/Console/Main.cpp +++ b/CPP/7zip/UI/Console/Main.cpp @@ -2,8 +2,6 @@ #include "StdAfx.h" -#include <io.h> - #include "Common/MyInitGuid.h" #include "Common/CommandLineParser.h" @@ -108,6 +106,7 @@ static const char *kHelpString = " -si[{name}]: read data from stdin\n" " -slt: show technical information for l (List) command\n" " -so: write data to stdout\n" + " -ssw: compress shared files\n" " -t{Type}: Set type of archive\n" " -v{Size}[b|k|m|g]: Create volumes\n" " -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\n" @@ -118,7 +117,6 @@ static const char *kHelpString = // --------------------------- // exception messages -static const char *kProcessArchiveMessage = " archive: "; static const char *kEverythingIsOk = "Everything is Ok"; static const char *kUserErrorMessage = "Incorrect command line"; // NExitCode::kUserError @@ -151,13 +149,7 @@ static void GetArguments(int numArguments, const char *arguments[], UStringVecto static void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp) { s << kCopyrightString; - /* - UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors(); - s << "System configuration: " << (UInt64)numCPUs << " CPU"; - if (numCPUs > 1) - s << "s"; - s << "\n"; - */ + // s << "# CPUs: " << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << "\n"; if (needHelp) s << kHelpString; } @@ -439,6 +431,7 @@ int Main2( } else { + UInt64 numErrors = 0; HRESULT result = ListArchives( codecs, options.ArchivePathsSorted, @@ -447,7 +440,12 @@ int Main2( options.EnableHeaders, options.TechMode, options.PasswordEnabled, - options.Password); + options.Password, numErrors); + if (numErrors > 0) + { + g_StdOut << endl << "Errors: " << numErrors; + return NExitCode::kFatalError; + } if (result != S_OK) throw CSystemException(result); } diff --git a/CPP/7zip/UI/Console/MainAr.cpp b/CPP/7zip/UI/Console/MainAr.cpp index 06f602ce..75fae190 100755 --- a/CPP/7zip/UI/Console/MainAr.cpp +++ b/CPP/7zip/UI/Console/MainAr.cpp @@ -19,9 +19,21 @@ using namespace NWindows; CStdOutStream *g_StdStream = 0; +#ifdef _WIN32 #ifndef _UNICODE bool g_IsNT = false; #endif +#if !defined(_UNICODE) || !defined(_WIN64) +static inline bool IsItWindowsNT() +{ + OSVERSIONINFO versionInfo; + versionInfo.dwOSVersionInfoSize = sizeof(versionInfo); + if (!::GetVersionEx(&versionInfo)) + return false; + return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); +} +#endif +#endif extern int Main2( #ifndef _WIN32 @@ -36,15 +48,6 @@ static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n"; static const char *kInternalExceptionMessage = "\n\nInternal Error #"; -static inline bool IsItWindowsNT() -{ - OSVERSIONINFO versionInfo; - versionInfo.dwOSVersionInfoSize = sizeof(versionInfo); - if (!::GetVersionEx(&versionInfo)) - return false; - return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); -} - int #ifdef _MSC_VER __cdecl @@ -57,15 +60,21 @@ int numArguments, const char *arguments[] ) { g_StdStream = &g_StdOut; + #ifdef _WIN32 + #ifdef _UNICODE + #ifndef _WIN64 if (!IsItWindowsNT()) { - (*g_StdStream) << "This program requires Windows NT/2000/XP/2003"; + (*g_StdStream) << "This program requires Windows NT/2000/XP/2003/Vista"; return NExitCode::kFatalError; } + #endif #else g_IsNT = IsItWindowsNT(); #endif + + #endif // setlocale(LC_COLLATE, ".OCP"); NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter; diff --git a/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp b/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp index 5cbc11c0..b060b196 100755 --- a/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp +++ b/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp @@ -26,8 +26,6 @@ static const wchar_t *kEmptyFileAlias = L"[Content]"; static const char *kCreatingArchiveMessage = "Creating archive "; static const char *kUpdatingArchiveMessage = "Updating archive "; static const char *kScanningMessage = "Scanning"; -static const char *kNoFilesScannedMessage = "No files scanned"; -static const char *kTotalFilesAddedMessage = "Total files added to archive: "; HRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result) diff --git a/CPP/7zip/UI/Console/UserInputUtils.h b/CPP/7zip/UI/Console/UserInputUtils.h index 75c85ee6..408e93e6 100755 --- a/CPP/7zip/UI/Console/UserInputUtils.h +++ b/CPP/7zip/UI/Console/UserInputUtils.h @@ -14,7 +14,7 @@ enum EEnum kYesAll, kNoAll, kAutoRename, - kQuit, + kQuit }; } diff --git a/CPP/7zip/UI/Console/makefile b/CPP/7zip/UI/Console/makefile index 466e5c56..02abe851 100755 --- a/CPP/7zip/UI/Console/makefile +++ b/CPP/7zip/UI/Console/makefile @@ -79,6 +79,7 @@ LZMA_BENCH_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\Threads.obj \ !include "../../Crc2.mak" diff --git a/CPP/7zip/UI/Explorer/ContextMenu.cpp b/CPP/7zip/UI/Explorer/ContextMenu.cpp index 01305fba..53f778cc 100755 --- a/CPP/7zip/UI/Explorer/ContextMenu.cpp +++ b/CPP/7zip/UI/Explorer/ContextMenu.cpp @@ -42,8 +42,6 @@ using namespace NWindows; -static LPCTSTR kFileClassIDString = TEXT("SevenZip"); - /////////////////////////////// // IShellExtInit diff --git a/CPP/7zip/UI/Explorer/Explorer.dsp b/CPP/7zip/UI/Explorer/Explorer.dsp index 724ed0d9..3fbf3064 100755 --- a/CPP/7zip/UI/Explorer/Explorer.dsp +++ b/CPP/7zip/UI/Explorer/Explorer.dsp @@ -534,6 +534,15 @@ SOURCE=..\..\..\..\C\Sort.c SOURCE=..\..\..\..\C\Sort.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # Begin Group "Common" diff --git a/CPP/7zip/UI/Explorer/makefile b/CPP/7zip/UI/Explorer/makefile index 21ace854..cf6321fa 100755 --- a/CPP/7zip/UI/Explorer/makefile +++ b/CPP/7zip/UI/Explorer/makefile @@ -93,6 +93,7 @@ FM_COMMON_OBJS = \ C_OBJS = \ $O\Alloc.obj \ $O\Sort.obj \ + $O\Threads.obj \ OBJS = \ $O\StdAfx.obj \ diff --git a/CPP/7zip/UI/Far/ExtractEngine.cpp b/CPP/7zip/UI/Far/ExtractEngine.cpp index 15548949..a71d22b8 100755 --- a/CPP/7zip/UI/Far/ExtractEngine.cpp +++ b/CPP/7zip/UI/Far/ExtractEngine.cpp @@ -147,8 +147,8 @@ STDMETHODIMP CExtractCallBackImp::SetOperationResult(INT32 operationResult, bool return E_FAIL; } char buffer[512]; - sprintf(buffer, g_StartupInfo.GetMsgString(idMessage), - GetSystemString(m_CurrentFilePath, m_CodePage)); + const AString s = GetSystemString(m_CurrentFilePath, m_CodePage); + sprintf(buffer, g_StartupInfo.GetMsgString(idMessage), (const char *)s); if (g_StartupInfo.ShowMessage(buffer) == -1) return E_ABORT; } diff --git a/CPP/7zip/UI/Far/Far.dsp b/CPP/7zip/UI/Far/Far.dsp index fa540ed2..327574dd 100755 --- a/CPP/7zip/UI/Far/Far.dsp +++ b/CPP/7zip/UI/Far/Far.dsp @@ -570,6 +570,15 @@ SOURCE=..\..\..\..\C\Sort.c SOURCE=..\..\..\..\C\Sort.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # End Target # End Project diff --git a/CPP/7zip/UI/Far/Main.cpp b/CPP/7zip/UI/Far/Main.cpp index 70d9117c..0409855d 100755 --- a/CPP/7zip/UI/Far/Main.cpp +++ b/CPP/7zip/UI/Far/Main.cpp @@ -33,8 +33,6 @@ using namespace NFar; static const char *kCommandPrefix = "7-zip"; -static const int kDescriptionMaxSize = 256; - static const char *kRegisrtryMainKeyName = ""; static const char *kRegisrtryValueNameEnabled = "UsedByDefault3"; diff --git a/CPP/7zip/UI/Far/OverwriteDialog.cpp b/CPP/7zip/UI/Far/OverwriteDialog.cpp index 028fff4e..1594a350 100755 --- a/CPP/7zip/UI/Far/OverwriteDialog.cpp +++ b/CPP/7zip/UI/Far/OverwriteDialog.cpp @@ -21,8 +21,6 @@ using namespace NFar; namespace NOverwriteDialog { -static const char *kHelpTopic = "OverwriteDialog"; - struct CFileInfoStrings { CSysString Size; diff --git a/CPP/7zip/UI/Far/PluginWrite.cpp b/CPP/7zip/UI/Far/PluginWrite.cpp index a159a476..79fdbf8f 100755 --- a/CPP/7zip/UI/Far/PluginWrite.cpp +++ b/CPP/7zip/UI/Far/PluginWrite.cpp @@ -421,8 +421,10 @@ HRESULT CompressFiles(const CObjectVector<PluginPanelItem> &pluginPanelItems) const CArcInfoEx &arcInfo = codecs->Formats[archiverIndex]; char updateAddToArchiveString[512]; + const AString s = GetSystemString(arcInfo.Name, CP_OEMCP); + sprintf(updateAddToArchiveString, - g_StartupInfo.GetMsgString(NMessageID::kUpdateAddToArchive), GetSystemString(arcInfo.Name), CP_OEMCP); + g_StartupInfo.GetMsgString(NMessageID::kUpdateAddToArchive), (const char *)s); int methodIndex = 0; int i; @@ -534,7 +536,6 @@ HRESULT CompressFiles(const CObjectVector<PluginPanelItem> &pluginPanelItems) if (archiveName.Right(prevExtensionLen).CompareNoCase(prevExtension) == 0) { int pos = archiveName.Length() - prevExtensionLen; - UString temp = archiveName.Left(pos); if (pos > 1) { int dotPos = archiveName.ReverseFind('.'); diff --git a/CPP/7zip/UI/Far/makefile b/CPP/7zip/UI/Far/makefile index 42c5a0a7..142226a4 100755 --- a/CPP/7zip/UI/Far/makefile +++ b/CPP/7zip/UI/Far/makefile @@ -71,6 +71,7 @@ AGENT_OBJS = \ C_OBJS = \ $O\Alloc.obj \ $O\Sort.obj \ + $O\Threads.obj \ OBJS = \ $O\StdAfx.obj \ diff --git a/CPP/7zip/UI/GUI/CompressDialog.cpp b/CPP/7zip/UI/GUI/CompressDialog.cpp index de182923..3591b14f 100755 --- a/CPP/7zip/UI/GUI/CompressDialog.cpp +++ b/CPP/7zip/UI/GUI/CompressDialog.cpp @@ -53,6 +53,7 @@ static CIDLangPair kIDLangPairs[] = { IDC_STATIC_COMPRESS_UPDATE_MODE, 0x02000D02 }, { IDC_STATIC_COMPRESS_OPTIONS, 0x02000D07 }, { IDC_COMPRESS_SFX, 0x02000D08 }, + { IDC_COMPRESS_SHARED, 0x02000D16 }, { IDC_COMPRESS_ENCRYPTION, 0x02000D10 }, { IDC_STATIC_COMPRESS_PASSWORD1, 0x02000B01 }, @@ -194,7 +195,7 @@ static const CFormatInfo g_Formats[] = }, { L"GZip", - (1 << 5) | (1 << 7) | (1 << 9), + (1 << 1) | (1 << 5) | (1 << 7) | (1 << 9), g_GZipMethods, MY_SIZE_OF_ARRAY(g_GZipMethods), false, false, false, false, false, false }, @@ -301,6 +302,7 @@ bool CCompressDialog::OnInit() SetItemText(IDC_COMPRESS_HARDWARE_THREADS, s); CheckButton(IDC_COMPRESS_SFX, Info.SFXMode); + CheckButton(IDC_COMPRESS_SHARED, Info.OpenShareForWrite); CheckControlsEnable(); @@ -539,6 +541,8 @@ void CCompressDialog::OnOK() Info.EncryptionMethod = GetEncryptionMethodSpec(); Info.ArchiverInfoIndex = m_Format.GetCurSel(); Info.SFXMode = IsSFX(); + Info.OpenShareForWrite = IsButtonCheckedBool(IDC_COMPRESS_SHARED); + m_RegistryInfo.EncryptHeaders = Info.EncryptHeaders = IsButtonCheckedBool(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES); m_Params.GetText(Info.Options); diff --git a/CPP/7zip/UI/GUI/CompressDialog.h b/CPP/7zip/UI/GUI/CompressDialog.h index 1ff20cd0..cf479f0a 100755 --- a/CPP/7zip/UI/GUI/CompressDialog.h +++ b/CPP/7zip/UI/GUI/CompressDialog.h @@ -43,6 +43,8 @@ namespace NCompressDialog UString EncryptionMethod; bool SFXMode; + bool OpenShareForWrite; + UString ArchiveName; // in: Relative for ; out: abs UString CurrentDirPrefix; diff --git a/CPP/7zip/UI/GUI/ExtractDialog.cpp b/CPP/7zip/UI/GUI/ExtractDialog.cpp index 55c871ad..3345b7df 100755 --- a/CPP/7zip/UI/GUI/ExtractDialog.cpp +++ b/CPP/7zip/UI/GUI/ExtractDialog.cpp @@ -36,6 +36,8 @@ static const int kPathModeButtons[] = IDC_EXTRACT_RADIO_NO_PATHNAMES }; +#ifndef _SFX + static const NExtract::NPathMode::EEnum kPathModeButtonsVals[] = { NExtract::NPathMode::kFullPathnames, @@ -74,7 +76,6 @@ static const int kFilesButtons[] = static const int kNumFilesButtons = sizeof(kFilesButtons) / sizeof(kFilesButtons[0]); */ -#ifndef _SFX void CExtractDialog::GetPathMode() { for (int i = 0; i < kNumPathnamesButtons; i++) @@ -169,7 +170,9 @@ static CIDLangPair kIDLangPairs[] = // static const int kWildcardsButtonIndex = 2; +#ifndef NO_REGISTRY static const int kHistorySize = 8; +#endif bool CExtractDialog::OnInit() { diff --git a/CPP/7zip/UI/GUI/ExtractGUI.cpp b/CPP/7zip/UI/GUI/ExtractGUI.cpp index 3edb1229..b73f9870 100755 --- a/CPP/7zip/UI/GUI/ExtractGUI.cpp +++ b/CPP/7zip/UI/GUI/ExtractGUI.cpp @@ -72,7 +72,7 @@ struct CThreadExtracting ExtractCallbackSpec->ProgressDialog.MyClose(); return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadExtracting *)param)->Process(); } @@ -154,9 +154,8 @@ HRESULT ExtractGUI( extracter.Options = &options; extracter.OpenCallback = openCallback; - CThread thread; - if (!thread.Create(CThreadExtracting::MyThreadFunction, &extracter)) - throw 271824; + NWindows::CThread thread; + RINOK(thread.Create(CThreadExtracting::MyThreadFunction, &extracter)); extracter.ExtractCallbackSpec->StartProgressDialog(title); if (extracter.Result == S_OK && options.TestMode && extracter.ExtractCallbackSpec->Messages.IsEmpty() && diff --git a/CPP/7zip/UI/GUI/GUI.cpp b/CPP/7zip/UI/GUI/GUI.cpp index ad58a451..2d401fc8 100755 --- a/CPP/7zip/UI/GUI/GUI.cpp +++ b/CPP/7zip/UI/GUI/GUI.cpp @@ -46,14 +46,13 @@ HINSTANCE g_hInstance; bool g_IsNT = false; #endif -static const wchar_t *kExceptionErrorMessage = L"Error:"; -static const wchar_t *kUserBreak = L"Break signaled"; +// static const wchar_t *kExceptionErrorMessage = L"Error:"; +// static const wchar_t *kUserBreak = L"Break signaled"; static const wchar_t *kMemoryExceptionMessage = L"ERROR: Can't allocate required memory!"; static const wchar_t *kUnknownExceptionMessage = L"Unknown Error"; -static const wchar_t *kInternalExceptionMessage = L"Internal Error #"; - -static const wchar_t *kIncorrectCommandMessage = L"Incorrect command"; +// static const wchar_t *kInternalExceptionMessage = L"Internal Error #"; +// static const wchar_t *kIncorrectCommandMessage = L"Incorrect command"; static void ErrorMessage(const wchar_t *message) { diff --git a/CPP/7zip/UI/GUI/GUI.dsp b/CPP/7zip/UI/GUI/GUI.dsp index ccfe98ab..9586eebf 100755 --- a/CPP/7zip/UI/GUI/GUI.dsp +++ b/CPP/7zip/UI/GUI/GUI.dsp @@ -684,6 +684,15 @@ SOURCE=..\..\..\..\C\Alloc.c SOURCE=..\..\..\..\C\Alloc.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # Begin Group "Common" diff --git a/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp b/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp index 15d6ee39..894faefb 100755 --- a/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp +++ b/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp @@ -76,8 +76,6 @@ static const UInt32 kMaxDicSize = (1 << 27); #endif -static const int kDefaultDictionary = 22; - bool CBenchmarkDialog::OnInit() { #ifdef LANG @@ -423,7 +421,7 @@ struct CThreadBenchmark HRESULT Process(); HRESULT Result; - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { ((CThreadBenchmark *)param)->Result = ((CThreadBenchmark *)param)->Process(); return 0; @@ -465,8 +463,9 @@ HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final) if (info2.NumIterations == 0) info2.NumIterations = 1; - info2.GlobalTime /= info2.NumIterations; - info2.UserTime /= info2.NumIterations; + info2.UnpackSize *= info2.NumIterations; + info2.PackSize *= info2.NumIterations; + info2.NumIterations = 1; if (final && SyncInfo->DecompressingInfo.GlobalTime == 0) { @@ -575,10 +574,8 @@ HRESULT Benchmark( benchmarkDialog._syncInfo.NumThreads = numThreads; benchmarker.SyncInfo = &benchmarkDialog._syncInfo; - CThread thread; - if (!thread.Create(CThreadBenchmark::MyThreadFunction, &benchmarker)) - return E_FAIL; + NWindows::CThread thread; + RINOK(thread.Create(CThreadBenchmark::MyThreadFunction, &benchmarker)); benchmarkDialog.Create(0); - thread.Wait(); - return S_OK; + return thread.Wait(); } diff --git a/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.h b/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.h index 716d0f55..9474c5b8 100755 --- a/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.h +++ b/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.h @@ -39,6 +39,11 @@ public: CBenchInfo2 DecompressingInfoTemp; CBenchInfo2 DecompressingInfo; + CProgressSyncInfo() + { + if (_startEvent.Create() != S_OK) + throw 3986437; + } void Init() { Changed = false; diff --git a/CPP/7zip/UI/GUI/UpdateGUI.cpp b/CPP/7zip/UI/GUI/UpdateGUI.cpp index 1150804e..b446b4c5 100755 --- a/CPP/7zip/UI/GUI/UpdateGUI.cpp +++ b/CPP/7zip/UI/GUI/UpdateGUI.cpp @@ -30,7 +30,7 @@ using namespace NWindows; using namespace NFile; -static const wchar_t *kIncorrectOutDir = L"Incorrect output directory path"; +// static const wchar_t *kIncorrectOutDir = L"Incorrect output directory path"; static const wchar_t *kDefaultSfxModule = L"7z.sfx"; static const wchar_t *kSFXExtension = L"exe"; @@ -76,7 +76,7 @@ struct CThreadUpdating UpdateCallbackGUI->ProgressDialog.MyClose(); return 0; } - static DWORD WINAPI MyThreadFunction(void *param) + static THREAD_FUNC_DECL MyThreadFunction(void *param) { return ((CThreadUpdating *)param)->Process(); } @@ -273,6 +273,7 @@ static HRESULT ShowDialog( di.CurrentDirPrefix = currentDirPrefix; di.SFXMode = options.SfxMode; + di.OpenShareForWrite = options.OpenShareForWrite; if (callback->PasswordIsDefined) di.Password = callback->Password; @@ -334,6 +335,7 @@ static HRESULT ShowDialog( di.EncryptHeadersIsAllowed, di.EncryptHeaders, di.SFXMode); + options.OpenShareForWrite = di.OpenShareForWrite; ParseAndAddPropertires(options.MethodMode.Properties, di.Options); if (di.SFXMode) @@ -388,9 +390,8 @@ HRESULT UpdateGUI( tu.OpenCallback = openCallback; tu.ErrorInfo = &errorInfo; - CThread thread; - if (!thread.Create(CThreadUpdating::MyThreadFunction, &tu)) - throw 271824; + NWindows::CThread thread; + RINOK(thread.Create(CThreadUpdating::MyThreadFunction, &tu)) tu.UpdateCallbackGUI->StartProgressDialog(LangString(IDS_PROGRESS_COMPRESSING, 0x02000DC0)); return tu.Result; } diff --git a/CPP/7zip/UI/GUI/makefile b/CPP/7zip/UI/GUI/makefile index cac56df0..cd1536fe 100755 --- a/CPP/7zip/UI/GUI/makefile +++ b/CPP/7zip/UI/GUI/makefile @@ -100,6 +100,7 @@ FM_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\Threads.obj \ !include "../../Crc2.mak" diff --git a/CPP/7zip/UI/Resource/CompressDialog/resource.h b/CPP/7zip/UI/Resource/CompressDialog/resource.h index a7401e2f..beedde4e 100755 --- a/CPP/7zip/UI/Resource/CompressDialog/resource.h +++ b/CPP/7zip/UI/Resource/CompressDialog/resource.h @@ -48,3 +48,5 @@ #define IDC_COMPRESS_COMBO_ENCRYPTION_METHOD 1121 #define IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES 1122 + +#define IDC_COMPRESS_SHARED 1130 diff --git a/CPP/7zip/UI/Resource/CompressDialog/resource.rc b/CPP/7zip/UI/Resource/CompressDialog/resource.rc index 109c7e14..0c31d37d 100755 --- a/CPP/7zip/UI/Resource/CompressDialog/resource.rc +++ b/CPP/7zip/UI/Resource/CompressDialog/resource.rc @@ -1,7 +1,7 @@ #include "resource.h" #include "../../../GuiCommon.rc" -#define xSize2 380 +#define xSize2 400 #define ySize2 305 #define xSize (xSize2 + marg + marg) @@ -24,22 +24,25 @@ #undef bXPos3 #undef bYPos -#define gSize 180 +#define gSize 190 #define gSpace 24 -#define g0XSize 100 +#define g1XSize 90 +#define g0XSize (gSize - g1XSize) #define g1XPos (marg + g0XSize) -#define g1XSize (gSize - g0XSize) -#define g2XSize 122 +#define g3XSize 40 +#define g2XSize (gSize - g3XSize) #define g3XPos (marg + g2XSize) -#define g3XSize (gSize - g2XSize) #define g4XPos (marg + gSize + gSpace) #define g4XPos2 (g4XPos + 7) #define g4XSize (xSize2 - gSize - gSpace) #define g4XSize2 (g4XSize - 14) +#define OptYPos 73 +#define PswYPos 128 + #define bXPos1 (xSize - marg - bXSize) #define bXPos2 (bXPos1 - 10 - bXSize) #define bXPos3 (bXPos2 - 10 - bXSize) @@ -93,25 +96,27 @@ BEGIN LTEXT "&Update mode:",IDC_STATIC_COMPRESS_UPDATE_MODE, g4XPos, 39, g4XSize, 8 COMBOBOX IDC_COMPRESS_COMBO_UPDATE_MODE, g4XPos, 51, g4XSize, 80, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - GROUPBOX "Options",IDC_STATIC_COMPRESS_OPTIONS, g4XPos, 73, g4XSize, 32 + GROUPBOX "Options",IDC_STATIC_COMPRESS_OPTIONS, g4XPos, OptYPos, g4XSize, 48 CONTROL "Create SF&X archive",IDC_COMPRESS_SFX, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, - g4XPos2, 87, g4XSize2, 10 + g4XPos2, OptYPos + 14, g4XSize2, 10 + CONTROL "Compress shared files",IDC_COMPRESS_SHARED, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, + g4XPos2, OptYPos + 30, g4XSize2, 10 - GROUPBOX "Encryption",IDC_COMPRESS_ENCRYPTION, g4XPos, 113, g4XSize, 127 + GROUPBOX "Encryption",IDC_COMPRESS_ENCRYPTION, g4XPos, PswYPos, g4XSize, 127 - LTEXT "Enter password:",IDC_STATIC_COMPRESS_PASSWORD1, g4XPos2, 127, g4XSize2, 8 - EDITTEXT IDC_COMPRESS_EDIT_PASSWORD1, g4XPos2, 139, g4XSize2, 14, ES_PASSWORD | ES_AUTOHSCROLL - LTEXT "Reenter password:",IDC_STATIC_COMPRESS_PASSWORD2, g4XPos2, 159, g4XSize2, 8 - EDITTEXT IDC_COMPRESS_EDIT_PASSWORD2, g4XPos2, 171, g4XSize2, 14, ES_PASSWORD | ES_AUTOHSCROLL + LTEXT "Enter password:",IDC_STATIC_COMPRESS_PASSWORD1, g4XPos2, PswYPos + 14, g4XSize2, 8 + EDITTEXT IDC_COMPRESS_EDIT_PASSWORD1, g4XPos2, PswYPos + 26, g4XSize2, 14, ES_PASSWORD | ES_AUTOHSCROLL + LTEXT "Reenter password:",IDC_STATIC_COMPRESS_PASSWORD2, g4XPos2, PswYPos + 46, g4XSize2, 8 + EDITTEXT IDC_COMPRESS_EDIT_PASSWORD2, g4XPos2, PswYPos + 58, g4XSize2, 14, ES_PASSWORD | ES_AUTOHSCROLL CONTROL "Show Password",IDC_COMPRESS_CHECK_SHOW_PASSWORD,"Button", BS_AUTOCHECKBOX | WS_TABSTOP, - g4XPos2, 192, g4XSize2, 10 + g4XPos2, PswYPos + 79, g4XSize2, 10 - LTEXT "&Encryption method:",IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, g4XPos2, 208, 80, 8 - COMBOBOX IDC_COMPRESS_COMBO_ENCRYPTION_METHOD, g4XPos2 + 90, 206, g4XSize2 - 90, 198, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "&Encryption method:",IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, g4XPos2, PswYPos + 95, 100, 8 + COMBOBOX IDC_COMPRESS_COMBO_ENCRYPTION_METHOD, g4XPos2 + 100, PswYPos + 93, g4XSize2 - 100, 198, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Encrypt file &names", IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, - g4XPos2, 224, g4XSize2, 10 + g4XPos2, PswYPos + 111, g4XSize2, 10 DEFPUSHBUTTON "OK", IDOK, bXPos3, bYPos, bXSize, bYSize, WS_GROUP PUSHBUTTON "Cancel", IDCANCEL, bXPos2, bYPos, bXSize, bYSize diff --git a/CPP/Common/C_FileIO.cpp b/CPP/Common/C_FileIO.cpp index 7d9e00d0..28a1378c 100755 --- a/CPP/Common/C_FileIO.cpp +++ b/CPP/Common/C_FileIO.cpp @@ -51,6 +51,11 @@ bool CInFile::Open(const char *name) return CFileBase::OpenBinary(name, O_RDONLY); } +bool CInFile::OpenShared(const char *name, bool) +{ + return Open(name); +} + ssize_t CInFile::Read(void *data, size_t size) { return read(_handle, data, size); diff --git a/CPP/Common/C_FileIO.h b/CPP/Common/C_FileIO.h index 2ad07167..29378dfa 100755 --- a/CPP/Common/C_FileIO.h +++ b/CPP/Common/C_FileIO.h @@ -30,6 +30,7 @@ class CInFile: public CFileBase { public: bool Open(const char *name); + bool OpenShared(const char *name, bool shareForWrite); ssize_t Read(void *data, size_t size); }; diff --git a/CPP/Common/CommandLineParser.h b/CPP/Common/CommandLineParser.h index f59d8e4c..af698db8 100755 --- a/CPP/Common/CommandLineParser.h +++ b/CPP/Common/CommandLineParser.h @@ -3,7 +3,7 @@ #ifndef __COMMON_COMMANDLINEPARSER_H #define __COMMON_COMMANDLINEPARSER_H -#include "String.h" +#include "Common/String.h" namespace NCommandLineParser { diff --git a/CPP/Common/ListFileUtils.cpp b/CPP/Common/ListFileUtils.cpp index ea4cde38..349622ed 100755 --- a/CPP/Common/ListFileUtils.cpp +++ b/CPP/Common/ListFileUtils.cpp @@ -24,12 +24,14 @@ bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &resultStrings, UINT AString s; file.ReadToString(s); UString u; + #ifdef CP_UTF8 if (codePage == CP_UTF8) { if (!ConvertUTF8ToUnicode(s, u)) return false; } else + #endif u = MultiByteToUnicodeString(s, codePage); if (!u.IsEmpty()) { diff --git a/CPP/Common/MyCom.h b/CPP/Common/MyCom.h index 07e8fb66..dcc94f14 100755 --- a/CPP/Common/MyCom.h +++ b/CPP/Common/MyCom.h @@ -154,6 +154,13 @@ public: #define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \ { *outObject = (void *)(i *)this; AddRef(); return S_OK; } +#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \ + { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; } + +#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \ + MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ + MY_QUERYINTERFACE_ENTRY(i) + #define MY_QUERYINTERFACE_END return E_NOINTERFACE; } #define MY_ADDREF_RELEASE \ @@ -168,26 +175,31 @@ STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \ MY_ADDREF_RELEASE -#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \ +#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \ + MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \ MY_QUERYINTERFACE_END \ MY_ADDREF_RELEASE #define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \ + MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \ MY_QUERYINTERFACE_ENTRY(i) \ ) #define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \ + MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ MY_QUERYINTERFACE_ENTRY(i1) \ MY_QUERYINTERFACE_ENTRY(i2) \ ) #define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \ + MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ MY_QUERYINTERFACE_ENTRY(i1) \ MY_QUERYINTERFACE_ENTRY(i2) \ MY_QUERYINTERFACE_ENTRY(i3) \ ) #define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \ + MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ MY_QUERYINTERFACE_ENTRY(i1) \ MY_QUERYINTERFACE_ENTRY(i2) \ MY_QUERYINTERFACE_ENTRY(i3) \ @@ -195,6 +207,7 @@ STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0) \ ) #define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \ + MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \ MY_QUERYINTERFACE_ENTRY(i1) \ MY_QUERYINTERFACE_ENTRY(i2) \ MY_QUERYINTERFACE_ENTRY(i3) \ diff --git a/CPP/Common/MyInitGuid.h b/CPP/Common/MyInitGuid.h index 5bdfeed5..4fc15565 100755 --- a/CPP/Common/MyInitGuid.h +++ b/CPP/Common/MyInitGuid.h @@ -8,6 +8,8 @@ #else #define INITGUID #include "MyGuidDef.h" +DEFINE_GUID(IID_IUnknown, +0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); #endif #endif diff --git a/CPP/Common/MyWindows.h b/CPP/Common/MyWindows.h index a93d750a..e388fb02 100755 --- a/CPP/Common/MyWindows.h +++ b/CPP/Common/MyWindows.h @@ -99,6 +99,10 @@ typedef LONG SCODE; #define MIDL_INTERFACE(x) struct +#ifdef __cplusplus + +DEFINE_GUID(IID_IUnknown, +0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); struct IUnknown { STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE; @@ -111,6 +115,8 @@ struct IUnknown typedef IUnknown *LPUNKNOWN; +#endif + #define VARIANT_TRUE ((VARIANT_BOOL)-1) #define VARIANT_FALSE ((VARIANT_BOOL)0) @@ -149,6 +155,8 @@ typedef WORD PROPVAR_PAD1; typedef WORD PROPVAR_PAD2; typedef WORD PROPVAR_PAD3; +#ifdef __cplusplus + typedef struct tagPROPVARIANT { VARTYPE vt; @@ -178,6 +186,11 @@ typedef PROPVARIANT tagVARIANT; typedef tagVARIANT VARIANT; typedef VARIANT VARIANTARG; +MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop); +MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src); + +#endif + MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len); MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz); MY_EXTERN_C void SysFreeString(BSTR bstr); @@ -185,8 +198,6 @@ MY_EXTERN_C UINT SysStringByteLen(BSTR bstr); MY_EXTERN_C UINT SysStringLen(BSTR bstr); MY_EXTERN_C DWORD GetLastError(); -MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop); -MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src); MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2); #define CP_ACP 0 diff --git a/CPP/Common/Wildcard.cpp b/CPP/Common/Wildcard.cpp index ddadc7b1..2e938375 100755 --- a/CPP/Common/Wildcard.cpp +++ b/CPP/Common/Wildcard.cpp @@ -4,7 +4,6 @@ #include "Wildcard.h" -static const wchar_t kPeriodChar = L'.'; static const wchar_t kAnyCharsChar = L'*'; static const wchar_t kAnyCharChar = L'?'; @@ -20,8 +19,6 @@ static const UString kIllegalWildCardFileNameChars= L"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F" L"\"/:<>\\|"; -static const UString kIllegalFileNameChars = kIllegalWildCardFileNameChars + - kWildCardCharSet; static inline bool IsCharDirLimiter(wchar_t c) { @@ -147,11 +144,6 @@ bool DoesNameContainWildCard(const UString &path) namespace NWildcard { -static inline int BoolToIndex(bool value) -{ - return value ? 1: 0; -} - /* M = MaskParts.Size(); diff --git a/CPP/Windows/Defs.h b/CPP/Windows/Defs.h index f8c6daaa..898be8d7 100755 --- a/CPP/Windows/Defs.h +++ b/CPP/Windows/Defs.h @@ -6,8 +6,10 @@ inline bool BOOLToBool(BOOL value) { return (value != FALSE); } +#ifdef _WIN32 inline bool LRESULTToBool(LRESULT value) { return (value != FALSE); } +#endif inline BOOL BoolToBOOL(bool value) { return (value ? TRUE: FALSE); } diff --git a/CPP/Windows/FileIO.cpp b/CPP/Windows/FileIO.cpp index efad8582..b5f7593c 100755 --- a/CPP/Windows/FileIO.cpp +++ b/CPP/Windows/FileIO.cpp @@ -180,15 +180,21 @@ bool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const bool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes) { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); } +bool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite) +{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); } + bool CInFile::Open(LPCTSTR fileName) - { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); } + { return OpenShared(fileName, false); } #ifndef _UNICODE bool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes) { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); } +bool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite) +{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); } + bool CInFile::Open(LPCWSTR fileName) - { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); } + { return OpenShared(fileName, false); } #endif // ReadFile and WriteFile functions in Windows have BUG: @@ -196,7 +202,11 @@ bool CInFile::Open(LPCWSTR fileName) // from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES // (Insufficient system resources exist to complete the requested service). -static UInt32 kChunkSizeMax = (1 << 24); +// Probably in some version of Windows there are problems with other sizes: +// for 32 MB (maybe also for 16 MB). +// And message can be "Network connection was lost" + +static UInt32 kChunkSizeMax = (1 << 22); bool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize) { diff --git a/CPP/Windows/FileIO.h b/CPP/Windows/FileIO.h index ec936ac6..05c8bc16 100755 --- a/CPP/Windows/FileIO.h +++ b/CPP/Windows/FileIO.h @@ -53,9 +53,11 @@ class CInFile: public CFileBase { public: bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); + bool OpenShared(LPCTSTR fileName, bool shareForWrite); bool Open(LPCTSTR fileName); #ifndef _UNICODE bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); + bool OpenShared(LPCWSTR fileName, bool shareForWrite); bool Open(LPCWSTR fileName); #endif bool ReadPart(void *data, UInt32 size, UInt32 &processedSize); diff --git a/CPP/Windows/ResourceString.cpp b/CPP/Windows/ResourceString.cpp index 42cc477e..8d043b13 100755 --- a/CPP/Windows/ResourceString.cpp +++ b/CPP/Windows/ResourceString.cpp @@ -51,7 +51,7 @@ UString MyLoadStringW(HINSTANCE hInstance, UINT resourceID) s.ReleaseBuffer(); return s; } - return GetUnicodeString(MyLoadString(resourceID)); + return GetUnicodeString(MyLoadString(hInstance, resourceID)); } UString MyLoadStringW(UINT resourceID) diff --git a/CPP/Windows/Synchronization.cpp b/CPP/Windows/Synchronization.cpp index 64b811da..5f86d1eb 100755 --- a/CPP/Windows/Synchronization.cpp +++ b/CPP/Windows/Synchronization.cpp @@ -7,11 +7,4 @@ namespace NWindows { namespace NSynchronization { -CEvent::CEvent(bool manualReset, bool initiallyOwn, LPCTSTR name, - LPSECURITY_ATTRIBUTES securityAttributes) -{ - if (!Create(manualReset, initiallyOwn, name, securityAttributes)) - throw "CreateEvent error"; -} - }} diff --git a/CPP/Windows/Synchronization.h b/CPP/Windows/Synchronization.h index 89450276..c16f7b4d 100755 --- a/CPP/Windows/Synchronization.h +++ b/CPP/Windows/Synchronization.h @@ -4,81 +4,120 @@ #define __WINDOWS_SYNCHRONIZATION_H #include "Defs.h" + +extern "C" +{ +#include "../../C/Threads.h" +} + +#ifdef _WIN32 #include "Handle.h" +#endif namespace NWindows { namespace NSynchronization { -class CObject: public CHandle -{ -public: - bool Lock(DWORD timeoutInterval = INFINITE) - { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0); } -}; - -class CBaseEvent: public CObject +class CBaseEvent { +protected: + ::CEvent _object; public: - bool Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL, + bool IsCreated() { return Event_IsCreated(&_object) != 0; } + operator HANDLE() { return _object.handle; } + CBaseEvent() { Event_Construct(&_object); } + ~CBaseEvent() { Close(); } + HRes Close() { return Event_Close(&_object); } + #ifdef _WIN32 + HRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL, LPSECURITY_ATTRIBUTES securityAttributes = NULL) { - _handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset), + _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset), BoolToBOOL(initiallyOwn), name); - return (_handle != 0); + if (_object.handle != 0) + return 0; + return ::GetLastError(); } - - bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) + HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) { - _handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name); - return (_handle != 0); + _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name); + if (_object.handle != 0) + return 0; + return ::GetLastError(); } + #endif - bool Set() { return BOOLToBool(::SetEvent(_handle)); } - bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); } - bool Reset() { return BOOLToBool(::ResetEvent(_handle)); } + HRes Set() { return Event_Set(&_object); } + // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); } + HRes Reset() { return Event_Reset(&_object); } + HRes Lock() { return Event_Wait(&_object); } }; -class CEvent: public CBaseEvent +class CManualResetEvent: public CBaseEvent { public: - CEvent() {}; - CEvent(bool manualReset, bool initiallyOwn, - LPCTSTR name = NULL, LPSECURITY_ATTRIBUTES securityAttributes = NULL); + HRes Create(bool initiallyOwn = false) + { + return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0); + } + HRes CreateIfNotCreated() + { + if (IsCreated()) + return 0; + return ManualResetEvent_CreateNotSignaled(&_object); + } + #ifdef _WIN32 + HRes CreateWithName(bool initiallyOwn, LPCTSTR name) + { + return CBaseEvent::Create(true, initiallyOwn, name); + } + #endif }; -class CManualResetEvent: public CEvent +class CAutoResetEvent: public CBaseEvent { public: - CManualResetEvent(bool initiallyOwn = false, LPCTSTR name = NULL, - LPSECURITY_ATTRIBUTES securityAttributes = NULL): - CEvent(true, initiallyOwn, name, securityAttributes) {}; + HRes Create() + { + return AutoResetEvent_CreateNotSignaled(&_object); + } + HRes CreateIfNotCreated() + { + if (IsCreated()) + return 0; + return AutoResetEvent_CreateNotSignaled(&_object); + } }; -class CAutoResetEvent: public CEvent +#ifdef _WIN32 +class CObject: public CHandle { public: - CAutoResetEvent(bool initiallyOwn = false, LPCTSTR name = NULL, - LPSECURITY_ATTRIBUTES securityAttributes = NULL): - CEvent(false, initiallyOwn, name, securityAttributes) {}; + HRes Lock(DWORD timeoutInterval = INFINITE) + { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); } }; - class CMutex: public CObject { public: - bool Create(bool initiallyOwn, LPCTSTR name = NULL, + HRes Create(bool initiallyOwn, LPCTSTR name = NULL, LPSECURITY_ATTRIBUTES securityAttributes = NULL) { _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name); - return (_handle != 0); + if (_handle != 0) + return 0; + return ::GetLastError(); } - bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) + HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) { _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name); - return (_handle != 0); + if (_handle != 0) + return 0; + return ::GetLastError(); + } + HRes Release() + { + return ::ReleaseMutex(_handle) ? 0 : ::GetLastError(); } - bool Release() { return BOOLToBool(::ReleaseMutex(_handle)); } }; - class CMutexLock { CMutex *_object; @@ -86,37 +125,33 @@ public: CMutexLock(CMutex &object): _object(&object) { _object->Lock(); } ~CMutexLock() { _object->Release(); } }; +#endif -class CSemaphore: public CObject +class CSemaphore { + ::CSemaphore _object; public: - bool Create(LONG initiallyCount, LONG maxCount, LPCTSTR name = NULL, - LPSECURITY_ATTRIBUTES securityAttributes = NULL) + CSemaphore() { Semaphore_Construct(&_object); } + ~CSemaphore() { Close(); } + HRes Close() { return Semaphore_Close(&_object); } + operator HANDLE() { return _object.handle; } + HRes Create(UInt32 initiallyCount, UInt32 maxCount) { - _handle = ::CreateSemaphore(securityAttributes, initiallyCount, maxCount, name); - return (_handle != 0); - } - bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) - { - _handle = ::OpenSemaphore(desiredAccess, BoolToBOOL(inheritHandle), name); - return (_handle != 0); - } - bool Release(LONG releaseCount = 1, LPLONG previousCount = NULL) - { - return BOOLToBool(::ReleaseSemaphore(_handle, releaseCount, previousCount)); + return Semaphore_Create(&_object, initiallyCount, maxCount); } + HRes Release() { return Semaphore_Release1(&_object); } + HRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); } + HRes Lock() { return Semaphore_Wait(&_object); } }; class CCriticalSection { - CRITICAL_SECTION _object; - // void Initialize() { ::InitializeCriticalSection(&_object); } - // void Delete() { ::DeleteCriticalSection(&_object); } + ::CCriticalSection _object; public: - CCriticalSection() { ::InitializeCriticalSection(&_object); } - ~CCriticalSection() { ::DeleteCriticalSection(&_object); } - void Enter() { ::EnterCriticalSection(&_object); } - void Leave() { ::LeaveCriticalSection(&_object); } + CCriticalSection() { CriticalSection_Init(&_object); } + ~CCriticalSection() { CriticalSection_Delete(&_object); } + void Enter() { CriticalSection_Enter(&_object); } + void Leave() { CriticalSection_Leave(&_object); } }; class CCriticalSectionLock diff --git a/CPP/Windows/Thread.h b/CPP/Windows/Thread.h index 5b676027..044ec9a3 100755 --- a/CPP/Windows/Thread.h +++ b/CPP/Windows/Thread.h @@ -3,47 +3,35 @@ #ifndef __WINDOWS_THREAD_H #define __WINDOWS_THREAD_H -// #include <process.h> +#include <process.h> -#include "Handle.h" #include "Defs.h" +extern "C" +{ +#include "../../C/Threads.h" +} + namespace NWindows { -class CThread: public CHandle +class CThread { - bool IsOpen() const { return _handle != 0; } + ::CThread thread; public: - bool Create(LPSECURITY_ATTRIBUTES threadAttributes, - SIZE_T stackSize, LPTHREAD_START_ROUTINE startAddress, - LPVOID parameter, DWORD creationFlags, LPDWORD threadId) - { - _handle = ::CreateThread(threadAttributes, stackSize, startAddress, - parameter, creationFlags, threadId); - return (_handle != NULL); - } - bool Create(LPTHREAD_START_ROUTINE startAddress, LPVOID parameter) - { - DWORD threadId; - return Create(NULL, 0, startAddress, parameter, 0, &threadId); - /* - _handle = (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, NULL); - return (_handle != NULL); - */ - } - - DWORD Resume() { return ::ResumeThread(_handle); } - DWORD Suspend() { return ::SuspendThread(_handle); } - bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(_handle, exitCode)); } - int GetPriority() { return ::GetThreadPriority(_handle); } - bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(_handle, priority)); } - - bool Wait() - { - if (!IsOpen()) - return true; - return (::WaitForSingleObject(_handle, INFINITE) == WAIT_OBJECT_0); - } + CThread() { Thread_Construct(&thread); } + ~CThread() { Close(); } + HRes Close() { return Thread_Close(&thread); } + HRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) + { return Thread_Create(&thread, startAddress, parameter); } + HRes Wait() { return Thread_Wait(&thread); } + + #ifdef _WIN32 + DWORD Resume() { return ::ResumeThread(thread.handle); } + DWORD Suspend() { return ::SuspendThread(thread.handle); } + bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); } + int GetPriority() { return ::GetThreadPriority(thread.handle); } + bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); } + #endif }; } diff --git a/DOC/7zip.nsi b/DOC/7zip.nsi index d2903602..76f1bb0f 100755 --- a/DOC/7zip.nsi +++ b/DOC/7zip.nsi @@ -2,7 +2,7 @@ ;Defines !define VERSION_MAJOR 4 -!define VERSION_MINOR 45 +!define VERSION_MINOR 46 !define VERSION_POSTFIX_FULL " beta" !ifdef WIN64 !ifdef IA64 @@ -151,6 +151,8 @@ Section RMDir $INSTDIR\Formats + Delete $INSTDIR\Lang\no.txt + # install files SetOutPath "$INSTDIR" @@ -227,7 +229,8 @@ Section File ms.txt File ne.txt File nl.txt - File no.txt + File nb.txt + File nn.txt File pl.txt File pt.txt File pt-br.txt @@ -410,7 +413,8 @@ Section "Uninstall" Delete $INSTDIR\Lang\ms.txt Delete $INSTDIR\Lang\ne.txt Delete $INSTDIR\Lang\nl.txt - Delete $INSTDIR\Lang\no.txt + Delete $INSTDIR\Lang\nb.txt + Delete $INSTDIR\Lang\nn.txt Delete $INSTDIR\Lang\pl.txt Delete $INSTDIR\Lang\pt.txt Delete $INSTDIR\Lang\pt-br.txt diff --git a/DOC/7zip.wxs b/DOC/7zip.wxs index 4d3a9107..45ec9fde 100755 --- a/DOC/7zip.wxs +++ b/DOC/7zip.wxs @@ -1,8 +1,8 @@ <?xml version="1.0"?> <?define VerMajor = "4" ?> -<?define VerMinor = "45" ?> -<?define VerBuild = "03" ?> +<?define VerMinor = "46" ?> +<?define VerBuild = "00" ?> <?define MmVer = "$(var.VerMajor).$(var.VerMinor)" ?> <?define MmHex = "0$(var.VerMajor)$(var.VerMinor)" ?> <?define MmmmVer = "$(var.MmVer).$(var.VerBuild).0" ?> @@ -279,7 +279,8 @@ <File Id="ms.txt" Name="ms.txt" /> <File Id="ne.txt" Name="ne.txt" /> <File Id="nl.txt" Name="nl.txt" /> - <File Id="no.txt" Name="no.txt" /> + <File Id="nb.txt" Name="nb.txt" /> + <File Id="nn.txt" Name="nn.txt" /> <File Id="pl.txt" Name="pl.txt" /> <File Id="pt.txt" Name="pt.txt" /> <File Id="pt_br.txt" Name="pt-br.txt" /> diff --git a/DOC/readme.txt b/DOC/readme.txt index 88a6a366..28a2cf65 100755 --- a/DOC/readme.txt +++ b/DOC/readme.txt @@ -1,4 +1,4 @@ -7-Zip 4.44 Sources +7-Zip 4.46 Sources ------------------ 7-Zip is a file archiver for Windows 95/98/ME/NT/2000/2003/XP/Vista. |