mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-08 16:07:04 -06:00
21.03
This commit is contained in:
@@ -67,7 +67,6 @@ HRes CMemBlockManagerMt::AllocateSpace(size_t numBlocks, size_t numNoLockBlocks)
|
||||
return E_OUTOFMEMORY;
|
||||
if (!CMemBlockManager::AllocateSpace_bool(numBlocks))
|
||||
return E_OUTOFMEMORY;
|
||||
Semaphore.Close();
|
||||
// we need (maxCount = 1), if we want to create non-use empty Semaphore
|
||||
if (maxCount == 0)
|
||||
maxCount = 1;
|
||||
@@ -75,12 +74,13 @@ HRes CMemBlockManagerMt::AllocateSpace(size_t numBlocks, size_t numNoLockBlocks)
|
||||
// printf("\n Synchro.Create() \n");
|
||||
WRes wres;
|
||||
#ifndef _WIN32
|
||||
Semaphore.Close();
|
||||
wres = Synchro.Create();
|
||||
if (wres != 0)
|
||||
return HRESULT_FROM_WIN32(wres);
|
||||
wres = Semaphore.Create(&Synchro, (UInt32)numLockBlocks, maxCount);
|
||||
#else
|
||||
wres = Semaphore.Create((UInt32)numLockBlocks, maxCount);
|
||||
wres = Semaphore.OptCreateInit((UInt32)numLockBlocks, maxCount);
|
||||
#endif
|
||||
|
||||
return HRESULT_FROM_WIN32(wres);
|
||||
|
||||
@@ -99,41 +99,65 @@ HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 default
|
||||
}
|
||||
|
||||
|
||||
static HRESULT SetLogSizeProp(UInt64 number, NCOM::CPropVariant &destProp)
|
||||
{
|
||||
if (number >= 64)
|
||||
return E_INVALIDARG;
|
||||
UInt32 val32;
|
||||
if (number < 32)
|
||||
val32 = (UInt32)1 << (unsigned)number;
|
||||
/*
|
||||
else if (number == 32 && reduce_4GB_to_32bits)
|
||||
val32 = (UInt32)(Int32)-1;
|
||||
*/
|
||||
else
|
||||
{
|
||||
destProp = (UInt64)((UInt64)1 << (unsigned)number);
|
||||
return S_OK;
|
||||
}
|
||||
destProp = (UInt32)val32;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
static HRESULT StringToDictSize(const UString &s, NCOM::CPropVariant &destProp)
|
||||
{
|
||||
/* if (reduce_4GB_to_32bits) we can reduce (4 GiB) property to (4 GiB - 1).
|
||||
to fit the value to UInt32 for clients that do not support 64-bit values */
|
||||
|
||||
const wchar_t *end;
|
||||
UInt32 number = ConvertStringToUInt32(s, &end);
|
||||
unsigned numDigits = (unsigned)(end - s.Ptr());
|
||||
const UInt64 number = ConvertStringToUInt64(s, &end);
|
||||
const unsigned numDigits = (unsigned)(end - s.Ptr());
|
||||
if (numDigits == 0 || s.Len() > numDigits + 1)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (s.Len() == numDigits)
|
||||
{
|
||||
if (number >= 64)
|
||||
return E_INVALIDARG;
|
||||
if (number < 32)
|
||||
destProp = (UInt32)((UInt32)1 << (unsigned)number);
|
||||
else
|
||||
destProp = (UInt64)((UInt64)1 << (unsigned)number);
|
||||
return S_OK;
|
||||
}
|
||||
return SetLogSizeProp(number, destProp);
|
||||
|
||||
unsigned numBits;
|
||||
|
||||
switch (MyCharLower_Ascii(s[numDigits]))
|
||||
{
|
||||
case 'b': destProp = number; return S_OK;
|
||||
case 'b': numBits = 0; break;
|
||||
case 'k': numBits = 10; break;
|
||||
case 'm': numBits = 20; break;
|
||||
case 'g': numBits = 30; break;
|
||||
default: return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (number < ((UInt32)1 << (32 - numBits)))
|
||||
destProp = (UInt32)(number << numBits);
|
||||
const UInt64 range4g = ((UInt64)1 << (32 - numBits));
|
||||
if (number < range4g)
|
||||
destProp = (UInt32)((UInt32)number << numBits);
|
||||
/*
|
||||
else if (number == range4g && reduce_4GB_to_32bits)
|
||||
destProp = (UInt32)(Int32)-1;
|
||||
*/
|
||||
else if (numBits == 0)
|
||||
destProp = (UInt64)number;
|
||||
else if (number >= ((UInt64)1 << (64 - numBits)))
|
||||
return E_INVALIDARG;
|
||||
else
|
||||
destProp = (UInt64)((UInt64)number << numBits);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -141,16 +165,8 @@ static HRESULT StringToDictSize(const UString &s, NCOM::CPropVariant &destProp)
|
||||
static HRESULT PROPVARIANT_to_DictSize(const PROPVARIANT &prop, NCOM::CPropVariant &destProp)
|
||||
{
|
||||
if (prop.vt == VT_UI4)
|
||||
{
|
||||
UInt32 v = prop.ulVal;
|
||||
if (v >= 64)
|
||||
return E_INVALIDARG;
|
||||
if (v < 32)
|
||||
destProp = (UInt32)((UInt32)1 << (unsigned)v);
|
||||
else
|
||||
destProp = (UInt64)((UInt64)1 << (unsigned)v);
|
||||
return S_OK;
|
||||
}
|
||||
return SetLogSizeProp(prop.ulVal, destProp);
|
||||
|
||||
if (prop.vt == VT_BSTR)
|
||||
{
|
||||
UString s;
|
||||
|
||||
@@ -64,23 +64,34 @@ public:
|
||||
unsigned GetLevel() const;
|
||||
int Get_NumThreads() const
|
||||
{
|
||||
int i = FindProp(NCoderPropID::kNumThreads);
|
||||
const int i = FindProp(NCoderPropID::kNumThreads);
|
||||
if (i >= 0)
|
||||
if (Props[(unsigned)i].Value.vt == VT_UI4)
|
||||
return (int)Props[(unsigned)i].Value.ulVal;
|
||||
{
|
||||
const NWindows::NCOM::CPropVariant &val = Props[(unsigned)i].Value;
|
||||
if (val.vt == VT_UI4)
|
||||
return (int)val.ulVal;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool Get_DicSize(UInt32 &res) const
|
||||
bool Get_DicSize(UInt64 &res) const
|
||||
{
|
||||
res = 0;
|
||||
int i = FindProp(NCoderPropID::kDictionarySize);
|
||||
const int i = FindProp(NCoderPropID::kDictionarySize);
|
||||
if (i >= 0)
|
||||
if (Props[(unsigned)i].Value.vt == VT_UI4)
|
||||
{
|
||||
const NWindows::NCOM::CPropVariant &val = Props[(unsigned)i].Value;
|
||||
if (val.vt == VT_UI4)
|
||||
{
|
||||
res = Props[(unsigned)i].Value.ulVal;
|
||||
res = val.ulVal;
|
||||
return true;
|
||||
}
|
||||
if (val.vt == VT_UI8)
|
||||
{
|
||||
res = val.uhVal.QuadPart;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -90,23 +101,26 @@ public:
|
||||
{
|
||||
int i = FindProp(NCoderPropID::kAlgorithm);
|
||||
if (i >= 0)
|
||||
if (Props[(unsigned)i].Value.vt == VT_UI4)
|
||||
return Props[(unsigned)i].Value.ulVal;
|
||||
{
|
||||
const NWindows::NCOM::CPropVariant &val = Props[(unsigned)i].Value;
|
||||
if (val.vt == VT_UI4)
|
||||
return val.ulVal;
|
||||
}
|
||||
return GetLevel() >= 5 ? 1 : 0;
|
||||
}
|
||||
|
||||
UInt32 Get_Lzma_DicSize() const
|
||||
UInt64 Get_Lzma_DicSize() const
|
||||
{
|
||||
int i = FindProp(NCoderPropID::kDictionarySize);
|
||||
if (i >= 0)
|
||||
if (Props[(unsigned)i].Value.vt == VT_UI4)
|
||||
return Props[(unsigned)i].Value.ulVal;
|
||||
unsigned level = GetLevel();
|
||||
return
|
||||
( level <= 3 ? (1 << (level * 2 + 16)) :
|
||||
( level <= 6 ? (1 << (level + 19)) :
|
||||
( level <= 7 ? (1 << 25) : (1 << 26)
|
||||
UInt64 v;
|
||||
if (Get_DicSize(v))
|
||||
return v;
|
||||
const unsigned level = GetLevel();
|
||||
const UInt32 dictSize =
|
||||
( level <= 3 ? ((UInt32)1 << (level * 2 + 16)) :
|
||||
( level <= 6 ? ((UInt32)1 << (level + 19)) :
|
||||
( level <= 7 ? ((UInt32)1 << 25) : ((UInt32)1 << 26)
|
||||
)));
|
||||
return dictSize;
|
||||
}
|
||||
|
||||
bool Get_Lzma_Eos() const
|
||||
@@ -152,7 +166,7 @@ public:
|
||||
|
||||
UInt64 GetProp_BlockSize(PROPID id) const
|
||||
{
|
||||
int i = FindProp(id);
|
||||
const int i = FindProp(id);
|
||||
if (i >= 0)
|
||||
{
|
||||
const NWindows::NCOM::CPropVariant &val = Props[(unsigned)i].Value;
|
||||
@@ -176,7 +190,7 @@ public:
|
||||
}
|
||||
const UInt32 kMinSize = (UInt32)1 << 20;
|
||||
const UInt32 kMaxSize = (UInt32)1 << 28;
|
||||
UInt32 dictSize = Get_Lzma_DicSize();
|
||||
const UInt64 dictSize = Get_Lzma_DicSize();
|
||||
UInt64 blockSize = (UInt64)dictSize << 2;
|
||||
if (blockSize < kMinSize) blockSize = kMinSize;
|
||||
if (blockSize > kMaxSize) blockSize = kMaxSize;
|
||||
@@ -204,29 +218,38 @@ public:
|
||||
|
||||
UInt32 Get_BZip2_BlockSize() const
|
||||
{
|
||||
int i = FindProp(NCoderPropID::kDictionarySize);
|
||||
const int i = FindProp(NCoderPropID::kDictionarySize);
|
||||
if (i >= 0)
|
||||
if (Props[(unsigned)i].Value.vt == VT_UI4)
|
||||
{
|
||||
const NWindows::NCOM::CPropVariant &val = Props[(unsigned)i].Value;
|
||||
if (val.vt == VT_UI4)
|
||||
{
|
||||
UInt32 blockSize = Props[(unsigned)i].Value.ulVal;
|
||||
UInt32 blockSize = val.ulVal;
|
||||
const UInt32 kDicSizeMin = 100000;
|
||||
const UInt32 kDicSizeMax = 900000;
|
||||
if (blockSize < kDicSizeMin) blockSize = kDicSizeMin;
|
||||
if (blockSize > kDicSizeMax) blockSize = kDicSizeMax;
|
||||
return blockSize;
|
||||
}
|
||||
unsigned level = GetLevel();
|
||||
}
|
||||
const unsigned level = GetLevel();
|
||||
return 100000 * (level >= 5 ? 9 : (level >= 1 ? level * 2 - 1: 1));
|
||||
}
|
||||
|
||||
UInt32 Get_Ppmd_MemSize() const
|
||||
UInt64 Get_Ppmd_MemSize() const
|
||||
{
|
||||
int i = FindProp(NCoderPropID::kUsedMemorySize);
|
||||
const int i = FindProp(NCoderPropID::kUsedMemorySize);
|
||||
if (i >= 0)
|
||||
if (Props[(unsigned)i].Value.vt == VT_UI4)
|
||||
return Props[(unsigned)i].Value.ulVal;
|
||||
unsigned level = GetLevel();
|
||||
return ((UInt32)1 << (level + 19));
|
||||
{
|
||||
const NWindows::NCOM::CPropVariant &val = Props[(unsigned)i].Value;
|
||||
if (val.vt == VT_UI4)
|
||||
return val.ulVal;
|
||||
if (val.vt == VT_UI8)
|
||||
return val.uhVal.QuadPart;
|
||||
}
|
||||
const unsigned level = GetLevel();
|
||||
const UInt32 mem = (UInt32)1 << (level + 19);
|
||||
return mem;
|
||||
}
|
||||
|
||||
void AddProp_Level(UInt32 level)
|
||||
|
||||
@@ -20,13 +20,13 @@ STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *proc
|
||||
|
||||
STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
|
||||
{
|
||||
UInt64 absoluteNewPosition;
|
||||
if (seekOrigin == STREAM_SEEK_SET)
|
||||
{
|
||||
if (offset < 0)
|
||||
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
|
||||
offset += _offset;
|
||||
}
|
||||
UInt64 absoluteNewPosition = 0; // =0 for gcc-10
|
||||
HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
|
||||
if (newPosition)
|
||||
*newPosition = absoluteNewPosition - _offset;
|
||||
|
||||
@@ -52,9 +52,9 @@ HRESULT CStreamBinder::Create_ReInit()
|
||||
RINOK(Event__Create_or_Reset(_canRead_Event));
|
||||
// RINOK(Event__Create_or_Reset(_canWrite_Event));
|
||||
|
||||
_canWrite_Semaphore.Close();
|
||||
// _canWrite_Semaphore.Close();
|
||||
// we need at least 3 items of maxCount: 1 for normal unlock in Read(), 2 items for unlock in CloseRead_CallOnce()
|
||||
_canWrite_Semaphore.Create(0, 3);
|
||||
_canWrite_Semaphore.OptCreateInit(0, 3);
|
||||
|
||||
// _readingWasClosed = false;
|
||||
_readingWasClosed2 = false;
|
||||
|
||||
Reference in New Issue
Block a user