4.46 beta

This commit is contained in:
Igor Pavlov
2007-05-25 00:00:00 +00:00
committed by Kornel Lesiński
parent a145bfc7cf
commit c574fc0f4b
191 changed files with 1318 additions and 854 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
/* 7zCrc.c */
/* 7zCrcT8.c */
#include "7zCrc.h"
+2 -2
View File
@@ -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 -1
View File
@@ -1,4 +1,4 @@
// Common/Alloc.h
/* Alloc.h */
#ifndef __COMMON_ALLOC_H
#define __COMMON_ALLOC_H
+8 -6
View File
@@ -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);
+1 -1
View File
@@ -1,4 +1,4 @@
// BranchARM.h
/* BranchARM.h */
#ifndef __BRANCH_ARM_H
#define __BRANCH_ARM_H
+1 -1
View File
@@ -1,4 +1,4 @@
// BranchARMThumb.h
/* BranchARMThumb.h */
#ifndef __BRANCH_ARM_THUMB_H
#define __BRANCH_ARM_THUMB_H
+1 -1
View File
@@ -1,4 +1,4 @@
// BranchIA64.h
/* BranchIA64.h */
#ifndef __BRANCH_IA64_H
#define __BRANCH_IA64_H
+1 -1
View File
@@ -1,4 +1,4 @@
// BranchPPC.h
/* BranchPPC.h */
#ifndef __BRANCH_PPC_H
#define __BRANCH_PPC_H
+1 -1
View File
@@ -1,4 +1,4 @@
// BranchSPARC.h
/* BranchSPARC.h */
#ifndef __BRANCH_SPARC_H
#define __BRANCH_SPARC_H
+4 -4
View File
@@ -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;
+1 -1
View File
@@ -1,4 +1,4 @@
// Compress/HuffmanEncode.h
/* Compress/HuffmanEncode.h */
#ifndef __COMPRESS_HUFFMANENCODE_H
#define __COMPRESS_HUFFMANENCODE_H
+28 -1
View File
@@ -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;
+2
View File
@@ -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
+19 -1
View File
@@ -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)
+2 -2
View File
@@ -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 */
+1 -1
View File
@@ -1,4 +1,4 @@
// IStream.h
/* IStream.h */
#ifndef __C_ISTREAM_H
#define __C_ISTREAM_H
+18 -9
View File
@@ -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;
+11 -2
View File
@@ -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);
+1 -1
View File
@@ -7,7 +7,7 @@
#include "../../../Windows/PropVariant.h"
#include "../../Common/MethodID.h"
#include "../../Common/MethodId.h"
namespace NArchive {
namespace N7z {
+1 -1
View File
@@ -157,7 +157,7 @@ HRESULT CDecoder::Decode(
_mixerCoderCommon = _mixerCoderSTSpec;
#endif
}
_mixerCoderCommon->SetBindInfo(bindInfo);
RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));
for (i = 0; i < numCoders; i++)
{
+1 -1
View File
@@ -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];
+4 -2
View File
@@ -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;
+1 -2
View File
@@ -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
+7
View File
@@ -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);
}
+1 -1
View File
@@ -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));
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -8,13 +8,13 @@
namespace NArchive {
namespace N7z {
enum // PropID
enum
{
kpidPackedSize0 = kpidUserDefined,
kpidPackedSize1,
kpidPackedSize2,
kpidPackedSize3,
kpidPackedSize4,
kpidPackedSize4
};
}}
+2 -1
View File
@@ -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;
+1 -1
View File
@@ -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),
+1 -1
View File
@@ -15,7 +15,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *inStream,
const UInt64 *maxCheckStartPosition,
+2 -2
View File
@@ -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
+1 -2
View File
@@ -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
-2
View File
@@ -54,8 +54,6 @@ STATPROPSTG kProperties[] =
#endif
};
static const int kNumProperties = sizeof(kProperties) / sizeof(kProperties[0]);
static const wchar_t *kMethods[] =
{
L"None",
+1 -1
View File
@@ -15,7 +15,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *stream,
const UInt64 *maxCheckStartPosition,
+1 -1
View File
@@ -18,7 +18,7 @@ public:
{
kUnexpectedEndOfArchive = 0,
kIncorrectArchive,
kUnsupported,
kUnsupported
} Cause;
CInArchiveException(CCauseType cause) : Cause(cause) {}
};
-2
View File
@@ -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;
+1 -1
View File
@@ -15,7 +15,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *stream,
const UInt64 *maxCheckStartPosition,
+1 -1
View File
@@ -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;
};
+21 -33
View File
@@ -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;
+15 -6
View File
@@ -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);
};
+2 -1
View File
@@ -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)
+1 -1
View File
@@ -79,7 +79,7 @@ private:
CObjectVector<CSTCoderInfo> _coders;
int _mainCoderIndex;
public:
void SetBindInfo(const CBindInfo &bindInfo);
HRESULT SetBindInfo(const CBindInfo &bindInfo);
};
@@ -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();
+1 -1
View File
@@ -16,7 +16,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *stream,
const UInt64 *maxCheckStartPosition,
+1 -1
View File
@@ -16,7 +16,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *stream,
const UInt64 *maxCheckStartPosition,
+4
View File
@@ -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
+3 -3
View File
@@ -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;
}
};
+13
View File
@@ -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;
}
+2 -2
View File
@@ -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)
+2
View File
@@ -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
+1
View File
@@ -17,6 +17,7 @@ struct CCompressionMethodMode
{
UInt32 NumPasses;
UInt32 NumFastBytes;
UInt32 Algo;
bool NumMatchFinderCyclesDefined;
UInt32 NumMatchFinderCycles;
};
+3 -3
View File
@@ -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
};
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Tar/Handler.h
// Iso/Handler.h
#ifndef __ISO_HANDLER_H
#define __ISO_HANDLER_H
+1 -1
View File
@@ -15,7 +15,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *inStream,
const UInt64 *maxCheckStartPosition,
+1 -2
View File
@@ -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
+4
View File
@@ -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[] =
{
+1 -1
View File
@@ -14,7 +14,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *stream,
const UInt64 *maxCheckStartPosition,
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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
-2
View File
@@ -17,8 +17,6 @@ extern "C"
namespace NArchive {
namespace NRar {
static const char kEndOfString = '\0';
void CInArchive::ThrowExceptionWithCode(
CInArchiveException::CCauseType cause)
{
+1 -1
View File
@@ -24,7 +24,7 @@ public:
kUnexpectedEndOfArchive = 0,
kArchiveHeaderCRCError,
kFileHeaderCRCError,
kIncorrectArchive,
kIncorrectArchive
}
Cause;
CInArchiveException(CCauseType cause) : Cause(cause) {}
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -14,7 +14,7 @@ class CHandler:
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
MY_UNKNOWN_IMP1(IInArchive)
STDMETHOD(Open)(IInStream *stream,
const UInt64 *maxCheckStartPosition,
+2
View File
@@ -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
@@ -13,6 +13,7 @@ struct CCompressionMethodMode
{
CRecordVector<Byte> MethodSequence;
// bool MaximizeRatio;
UInt32 Algo;
UInt32 NumPasses;
UInt32 NumFastBytes;
bool NumMatchFinderCyclesDefined;
+1 -1
View File
@@ -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;
+3 -2
View File
@@ -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 =
+14
View File
@@ -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;
}
-2
View File
@@ -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());
+18 -40
View File
@@ -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;
}
@@ -126,6 +126,7 @@ CRYPTO_HASH_OBJS = \
C_OBJS = \
$O\Alloc.obj \
$O\Threads.obj \
C_BRANCH_OBJS = \
$O\BranchARM.obj \
+2 -1
View File
@@ -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 \
+60 -8
View File
@@ -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
+7 -3
View File
@@ -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);
}
+10 -9
View File
@@ -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
+1
View File
@@ -118,6 +118,7 @@ CRYPTO_HASH_OBJS = \
C_OBJS = \
$O\Alloc.obj \
$O\Threads.obj \
C_BRANCH_OBJS = \
$O\BranchX86.obj \
+3 -4
View File
@@ -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
+9
View File
@@ -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
+1
View File
@@ -100,6 +100,7 @@ LZMA_OPT_OBJS = \
C_OBJS = \
$O\Alloc.obj \
$O\Threads.obj \
C_BRANCH_OBJS = \
$O\BranchX86.obj \
+37 -9
View File
@@ -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;
}
}
+18 -1
View File
@@ -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
+1
View File
@@ -123,6 +123,7 @@ CRYPTO_HASH_OBJS = \
C_OBJS = \
$O\Alloc.obj \
$O\Threads.obj \
C_BRANCH_OBJS = \
$O\BranchX86.obj \
+21 -7
View File
@@ -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;
+15 -4
View File
@@ -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
+2 -2
View File
@@ -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;
+9 -10
View File
@@ -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();
-18
View File
@@ -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;
}
}
}}
+17 -1
View File
@@ -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; }
+14 -12
View File
@@ -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)
+4 -4
View File
@@ -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);
};
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -1,4 +1,4 @@
// MethodID.h
// MethodId.h
#ifndef __7Z_METHOD_ID_H
#define __7Z_METHOD_ID_H
+6
View File
@@ -30,6 +30,12 @@ class COutMemStream:
public:
HRes CreateEvents()
{
RINOK(StopWritingEvent.CreateIfNotCreated());
return WriteToRealStreamEvent.CreateIfNotCreated();
}
void SetOutStream(IOutStream *outStream)
{
OutStream = outStream;
+1 -1
View File
@@ -3,7 +3,7 @@
#ifndef __REGISTERCODEC_H
#define __REGISTERCODEC_H
#include "../Common/MethodID.h"
#include "../Common/MethodId.h"
typedef void * (*CreateCodecP)();
struct CCodecInfo
+15 -27
View File
@@ -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();
}
+5 -10
View File
@@ -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);
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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,
+31 -26
View File
@@ -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++)
{
CState &ti = m_States[t];
ti.Decoder = this;
if (MtMode)
if (!ti.Thread.Create(MFThread, &ti))
{
NumThreads = t;
Free();
return false;
}
}
#endif
return E_OUTOFMEMORY;
}
catch(...) { return false; }
return true;
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)
{
HRes res = ti.Thread.Create(MFThread, &ti);
if (res != S_OK)
{
NumThreads = t;
Free();
return res;
}
}
}
#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();
+7 -1
View File
@@ -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

Some files were not shown because too many files have changed in this diff Show More