summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp937
1 files changed, 544 insertions, 393 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp
index bf3b982e44e..a501b86d4b1 100644
--- a/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/OpenArchive.cpp
@@ -14,6 +14,7 @@
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
#include "../../../Common/StringToInt.h"
+#include "../../../Common/UTFConvert.h"
#include "../../../Common/Wildcard.h"
#include "../../../Windows/FileDir.h"
@@ -28,15 +29,17 @@
#include "DefaultName.h"
#include "OpenArchive.h"
-#ifndef _SFX
+#ifndef Z7_SFX
#include "SetProperties.h"
#endif
+#ifndef Z7_SFX
#ifdef SHOW_DEBUG_INFO
#define PRF(x) x
#else
#define PRF(x)
#endif
+#endif
// increase it, if you need to support larger SFX stubs
static const UInt64 kMaxCheckStartPosition = 1 << 23;
@@ -64,7 +67,7 @@ Open:
- open FAIL:
Try to open with all other types from offset 0 only.
If some open type is OK and physical archive size is uequal or larger
- than file size, then return that archive with warning that can not be open as [extension type].
+ than file size, then return that archive with warning that cannot be open as [extension type].
If extension was EXE, it will try to open as unknown_extension case
- file has unknown extension (like a.hhh)
It tries to open via parser code.
@@ -92,7 +95,7 @@ Open:
using namespace NWindows;
/*
-#ifdef _SFX
+#ifdef Z7_SFX
#define OPEN_PROPS_PARAM
#else
#define OPEN_PROPS_PARAM , props
@@ -108,7 +111,7 @@ CArc::~CArc()
}
*/
-#ifndef _SFX
+#ifndef Z7_SFX
namespace NArchive {
namespace NParser {
@@ -141,14 +144,14 @@ struct CParseItem
bool LenIsUnknown;
CParseItem():
- LenIsUnknown(false),
+ // OkSize(0),
FileTime_Defined(false),
UnpackSize_Defined(false),
- NumSubFiles_Defined(false),
NumSubDirs_Defined(false),
+ NumSubFiles_Defined(false),
IsSelfExe(false),
- IsNotArcType(false)
- // OkSize(0)
+ IsNotArcType(false),
+ LenIsUnknown(false)
{}
/*
@@ -169,23 +172,14 @@ struct CParseItem
}
};
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
+Z7_CLASS_IMP_CHandler_IInArchive_1(
+ IInArchiveGetStream
+)
public:
CObjectVector<CParseItem> _items;
UInt64 _maxEndOffset;
CMyComPtr<IInStream> _stream;
- MY_UNKNOWN_IMP2(
- IInArchive,
- IInArchiveGetStream)
-
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-
UInt64 GetLastEnd() const
{
if (_items.IsEmpty())
@@ -206,23 +200,25 @@ int CHandler::FindInsertPos(const CParseItem &item) const
unsigned left = 0, right = _items.Size();
while (left != right)
{
- unsigned mid = (left + right) / 2;
- const CParseItem & midItem = _items[mid];
+ const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
+ const CParseItem &midItem = _items[mid];
if (item.Offset < midItem.Offset)
right = mid;
else if (item.Offset > midItem.Offset)
left = mid + 1;
else if (item.Size < midItem.Size)
right = mid;
+ /*
else if (item.Size > midItem.Size)
left = mid + 1;
+ */
else
{
left = mid + 1;
// return -1;
}
}
- return left;
+ return (int)left;
}
void CHandler::AddUnknownItem(UInt64 next)
@@ -257,10 +253,10 @@ void CHandler::AddUnknownItem(UInt64 next)
void CHandler::AddItem(const CParseItem &item)
{
AddUnknownItem(item.Offset);
- int pos = FindInsertPos(item);
- if (pos >= 0)
+ const int pos = FindInsertPos(item);
+ if (pos != -1)
{
- _items.Insert(pos, item);
+ _items.Insert((unsigned)pos, item);
UInt64 next = item.Offset + item.Size;
if (_maxEndOffset < next)
_maxEndOffset = next;
@@ -295,7 +291,7 @@ static const Byte kProps[] =
IMP_IInArchive_Props
IMP_IInArchive_ArcProps_NO
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback * /* openArchiveCallback */)
+Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback * /* openArchiveCallback */))
{
COM_TRY_BEGIN
{
@@ -306,20 +302,20 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb
COM_TRY_END
}
-STDMETHODIMP CHandler::Close()
+Z7_COM7F_IMF(CHandler::Close())
{
_items.Clear();
_stream.Release();
return S_OK;
}
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
{
*numItems = _items.Size();
return S_OK;
}
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -330,17 +326,17 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
{
case kpidPath:
{
- wchar_t sz[32];
+ char sz[32];
ConvertUInt32ToString(index + 1, sz);
- UString s = sz;
+ UString s(sz);
if (!item.Name.IsEmpty())
{
- s += L'.';
+ s.Add_Dot();
s += item.Name;
}
if (!item.Extension.IsEmpty())
{
- s += L'.';
+ s.Add_Dot();
s += item.Extension;
}
prop = s; break;
@@ -360,12 +356,12 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
COM_TRY_END
}
-HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
+Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+ Int32 testMode, IArchiveExtractCallback *extractCallback))
{
COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)(Int32)-1);
+ const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
if (allFilesMode)
numItems = _items.Size();
if (_stream && numItems == 0)
@@ -396,35 +392,35 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
{
lps->InSize = totalSize;
lps->OutSize = totalSize;
- RINOK(lps->SetCur());
+ RINOK(lps->SetCur())
CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
+ const Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
+ const UInt32 index = allFilesMode ? i : indices[i];
const CParseItem &item = _items[index];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+ RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
UInt64 unpackSize = item.Size;
totalSize += unpackSize;
bool skipMode = false;
if (!testMode && !realOutStream)
continue;
- RINOK(extractCallback->PrepareOperation(askMode));
+ RINOK(extractCallback->PrepareOperation(askMode))
outStreamSpec->SetStream(realOutStream);
realOutStream.Release();
outStreamSpec->Init(skipMode ? 0 : unpackSize, true);
Int32 opRes = NExtract::NOperationResult::kOK;
- RINOK(_stream->Seek(item.Offset, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekSet(_stream, item.Offset))
streamSpec->Init(unpackSize);
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
+ RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress))
if (outStreamSpec->GetRem() != 0)
opRes = NExtract::NOperationResult::kDataError;
outStreamSpec->ReleaseStream();
- RINOK(extractCallback->SetOperationResult(opRes));
+ RINOK(extractCallback->SetOperationResult(opRes))
}
return S_OK;
@@ -433,7 +429,7 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
}
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
+Z7_COM7F_IMF(CHandler::GetStream(UInt32 index, ISequentialInStream **stream))
{
COM_TRY_BEGIN
const CParseItem &item = _items[index];
@@ -449,7 +445,7 @@ HRESULT Archive_GetItemBoolProp(IInArchive *arc, UInt32 index, PROPID propID, bo
{
NCOM::CPropVariant prop;
result = false;
- RINOK(arc->GetProperty(index, propID, &prop));
+ RINOK(arc->GetProperty(index, propID, &prop))
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt != VT_EMPTY)
@@ -477,11 +473,11 @@ HRESULT Archive_IsItem_Deleted(IInArchive *arc, UInt32 index, bool &result) thro
return Archive_GetItemBoolProp(arc, index, kpidIsDeleted, result);
}
-static HRESULT Archive_GetArcBoolProp(IInArchive *arc, PROPID propid, bool &result) throw()
+static HRESULT Archive_GetArcProp_Bool(IInArchive *arc, PROPID propid, bool &result) throw()
{
NCOM::CPropVariant prop;
result = false;
- RINOK(arc->GetArchiveProperty(propid, &prop));
+ RINOK(arc->GetArchiveProperty(propid, &prop))
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt != VT_EMPTY)
@@ -493,16 +489,17 @@ static HRESULT Archive_GetArcProp_UInt(IInArchive *arc, PROPID propid, UInt64 &r
{
defined = false;
NCOM::CPropVariant prop;
- RINOK(arc->GetArchiveProperty(propid, &prop));
+ RINOK(arc->GetArchiveProperty(propid, &prop))
switch (prop.vt)
{
- case VT_UI4: result = prop.ulVal; defined = true; break;
- case VT_I4: result = (Int64)prop.lVal; defined = true; break;
- case VT_UI8: result = (UInt64)prop.uhVal.QuadPart; defined = true; break;
- case VT_I8: result = (UInt64)prop.hVal.QuadPart; defined = true; break;
- case VT_EMPTY: break;
+ case VT_UI4: result = prop.ulVal; break;
+ case VT_I4: result = (UInt64)(Int64)prop.lVal; break;
+ case VT_UI8: result = (UInt64)prop.uhVal.QuadPart; break;
+ case VT_I8: result = (UInt64)prop.hVal.QuadPart; break;
+ case VT_EMPTY: return S_OK;
default: return E_FAIL;
}
+ defined = true;
return S_OK;
}
@@ -510,22 +507,23 @@ static HRESULT Archive_GetArcProp_Int(IInArchive *arc, PROPID propid, Int64 &res
{
defined = false;
NCOM::CPropVariant prop;
- RINOK(arc->GetArchiveProperty(propid, &prop));
+ RINOK(arc->GetArchiveProperty(propid, &prop))
switch (prop.vt)
{
- case VT_UI4: result = prop.ulVal; defined = true; break;
- case VT_I4: result = prop.lVal; defined = true; break;
- case VT_UI8: result = (Int64)prop.uhVal.QuadPart; defined = true; break;
- case VT_I8: result = (Int64)prop.hVal.QuadPart; defined = true; break;
- case VT_EMPTY: break;
+ case VT_UI4: result = prop.ulVal; break;
+ case VT_I4: result = prop.lVal; break;
+ case VT_UI8: result = (Int64)prop.uhVal.QuadPart; break;
+ case VT_I8: result = (Int64)prop.hVal.QuadPart; break;
+ case VT_EMPTY: return S_OK;
default: return E_FAIL;
}
+ defined = true;
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
-HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &parts) const
+HRESULT CArc::GetItem_PathToParent(UInt32 index, UInt32 parent, UStringVector &parts) const
{
if (!GetRawProps)
return E_FAIL;
@@ -543,14 +541,14 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
const void *p;
UInt32 size;
UInt32 propType;
- RINOK(GetRawProps->GetRawProp(curIndex, kpidName, &p, &size, &propType));
+ RINOK(GetRawProps->GetRawProp(curIndex, kpidName, &p, &size, &propType))
if (p && propType == PROP_DATA_TYPE_wchar_t_PTR_Z_LE)
s = (const wchar_t *)p;
else
#endif
{
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(curIndex, kpidName, &prop));
+ RINOK(Archive->GetProperty(curIndex, kpidName, &prop))
if (prop.vt == VT_BSTR && prop.bstrVal)
s.SetFromBstr(prop.bstrVal);
else if (prop.vt == VT_EMPTY)
@@ -561,8 +559,10 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
UInt32 curParent = (UInt32)(Int32)-1;
UInt32 parentType = 0;
- RINOK(GetRawProps->GetParent(curIndex, &curParent, &parentType));
+ RINOK(GetRawProps->GetParent(curIndex, &curParent, &parentType))
+ // 18.06: fixed : we don't want to split name to parts
+ /*
if (parentType != NParentType::kAltStream)
{
for (;;)
@@ -576,6 +576,7 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
s.DeleteFrom(pos);
}
}
+ */
parts.Insert(0, s);
@@ -583,7 +584,7 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
{
{
UString &s2 = parts[parts.Size() - 2];
- s2 += L':';
+ s2 += ':';
s2 += parts.Back();
}
parts.DeleteBack();
@@ -604,7 +605,9 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
#endif
-HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
+
+
+HRESULT CArc::GetItem_Path(UInt32 index, UString &result) const
{
#ifdef MY_CPU_LE
if (GetRawProps)
@@ -618,19 +621,42 @@ HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
propType == NPropDataType::kUtf16z)
{
unsigned len = size / 2 - 1;
+ // (len) doesn't include null terminator
+
+ /*
+ #if WCHAR_MAX > 0xffff
+ len = (unsigned)Utf16LE__Get_Num_WCHARs(p, len);
+
+ wchar_t *s = result.GetBuf(len);
+ wchar_t *sEnd = Utf16LE__To_WCHARs_Sep(p, len, s);
+ if (s + len != sEnd) return E_FAIL;
+ *sEnd = 0;
+
+ #else
+ */
+
wchar_t *s = result.GetBuf(len);
for (unsigned i = 0; i < len; i++)
{
wchar_t c = GetUi16(p);
p = (const void *)((const Byte *)p + 2);
+
#if WCHAR_PATH_SEPARATOR != L'/'
if (c == L'/')
c = WCHAR_PATH_SEPARATOR;
+ else if (c == L'\\')
+ c = WCHAR_IN_FILE_NAME_BACKSLASH_REPLACEMENT; // WSL scheme
#endif
+
*s++ = c;
}
*s = 0;
+
+ // #endif
+
result.ReleaseBuf_SetLen(len);
+
+ Convert_UnicodeEsc16_To_UnicodeEscHigh(result);
if (len != 0)
return S_OK;
}
@@ -707,7 +733,7 @@ HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
{
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(index, kpidPath, &prop));
+ RINOK(Archive->GetProperty(index, kpidPath, &prop))
if (prop.vt == VT_BSTR && prop.bstrVal)
result.SetFromBstr(prop.bstrVal);
else if (prop.vt == VT_EMPTY)
@@ -717,23 +743,25 @@ HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
}
if (result.IsEmpty())
- return GetDefaultItemPath(index, result);
+ return GetItem_DefaultPath(index, result);
+
+ Convert_UnicodeEsc16_To_UnicodeEscHigh(result);
return S_OK;
}
-HRESULT CArc::GetDefaultItemPath(UInt32 index, UString &result) const
+HRESULT CArc::GetItem_DefaultPath(UInt32 index, UString &result) const
{
result.Empty();
bool isDir;
- RINOK(Archive_IsItem_Dir(Archive, index, isDir));
+ RINOK(Archive_IsItem_Dir(Archive, index, isDir))
if (!isDir)
{
result = DefaultName;
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(index, kpidExtension, &prop));
+ RINOK(Archive->GetProperty(index, kpidExtension, &prop))
if (prop.vt == VT_BSTR)
{
- result += L'.';
+ result.Add_Dot();
result += prop.bstrVal;
}
else if (prop.vt != VT_EMPTY)
@@ -742,13 +770,13 @@ HRESULT CArc::GetDefaultItemPath(UInt32 index, UString &result) const
return S_OK;
}
-HRESULT CArc::GetItemPath2(UInt32 index, UString &result) const
+HRESULT CArc::GetItem_Path2(UInt32 index, UString &result) const
{
- RINOK(GetItemPath(index, result));
+ RINOK(GetItem_Path(index, result))
if (Ask_Deleted)
{
bool isDeleted = false;
- RINOK(Archive_IsItem_Deleted(Archive, index, isDeleted));
+ RINOK(Archive_IsItem_Deleted(Archive, index, isDeleted))
if (isDeleted)
result.Insert(0, L"[DELETED]" WSTRING_PATH_SEPARATOR);
}
@@ -769,7 +797,7 @@ int FindAltStreamColon_in_Path(const wchar_t *path)
if (c == ':')
{
if (colonPos < 0)
- colonPos = i;
+ colonPos = (int)i;
continue;
}
if (c == WCHAR_PATH_SEPARATOR)
@@ -793,12 +821,12 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
item.PathParts.Clear();
- RINOK(Archive_IsItem_Dir(Archive, index, item.IsDir));
+ RINOK(Archive_IsItem_Dir(Archive, index, item.IsDir))
item.MainIsDir = item.IsDir;
- RINOK(GetItemPath2(index, item.Path));
+ RINOK(GetItem_Path2(index, item.Path))
- #ifndef _SFX
+ #ifndef Z7_SFX
UInt32 mainIndex = index;
#endif
@@ -807,7 +835,7 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
item.MainPath = item.Path;
if (Ask_AltStream)
{
- RINOK(Archive_IsItem_AltStream(Archive, index, item.IsAltStream));
+ RINOK(Archive_IsItem_AltStream(Archive, index, item.IsAltStream))
}
bool needFindAltStream = false;
@@ -819,11 +847,11 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
{
UInt32 parentType = 0;
UInt32 parentIndex;
- RINOK(GetRawProps->GetParent(index, &parentIndex, &parentType));
+ RINOK(GetRawProps->GetParent(index, &parentIndex, &parentType))
if (parentType == NParentType::kAltStream)
{
NCOM::CPropVariant prop;
- RINOK(Archive->GetProperty(index, kpidName, &prop));
+ RINOK(Archive->GetProperty(index, kpidName, &prop))
if (prop.vt == VT_BSTR && prop.bstrVal)
item.AltStreamName.SetFromBstr(prop.bstrVal);
else if (prop.vt != VT_EMPTY)
@@ -848,8 +876,8 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
}
else
{
- RINOK(GetItemPath2(parentIndex, item.MainPath));
- RINOK(Archive_IsItem_Dir(Archive, parentIndex, item.MainIsDir));
+ RINOK(GetItem_Path2(parentIndex, item.MainPath))
+ RINOK(Archive_IsItem_Dir(Archive, parentIndex, item.MainIsDir))
}
}
}
@@ -857,13 +885,13 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
if (item.WriteToAltStreamIfColon || needFindAltStream)
{
- /* Good handler must support GetRawProps::GetParent for alt streams./
+ /* Good handler must support GetRawProps::GetParent for alt streams.
So the following code currently is not used */
int colon = FindAltStreamColon_in_Path(item.Path);
if (colon >= 0)
{
- item.MainPath.DeleteFrom(colon);
- item.AltStreamName = item.Path.Ptr(colon + 1);
+ item.MainPath.DeleteFrom((unsigned)colon);
+ item.AltStreamName = item.Path.Ptr((unsigned)(colon + 1));
item.MainIsDir = (colon == 0 || IsPathSepar(item.Path[(unsigned)colon - 1]));
item.IsAltStream = true;
}
@@ -871,10 +899,10 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
#endif
- #ifndef _SFX
+ #ifndef Z7_SFX
if (item._use_baseParentFolder_mode)
{
- RINOK(GetItemPathToParent(mainIndex, item._baseParentFolder, item.PathParts));
+ RINOK(GetItem_PathToParent(mainIndex, (unsigned)item._baseParentFolder, item.PathParts))
#ifdef SUPPORT_ALT_STREAMS
if ((item.WriteToAltStreamIfColon || needFindAltStream) && !item.PathParts.IsEmpty())
@@ -885,10 +913,10 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
colon = FindAltStreamColon_in_Path(s);
if (colon >= 0)
{
- item.AltStreamName = s.Ptr(colon + 1);
+ item.AltStreamName = s.Ptr((unsigned)(colon + 1));
item.MainIsDir = (colon == 0 || IsPathSepar(s[(unsigned)colon - 1]));
item.IsAltStream = true;
- s.DeleteFrom(colon);
+ s.DeleteFrom((unsigned)colon);
}
}
if (colon == 0)
@@ -910,14 +938,14 @@ HRESULT CArc::GetItem(UInt32 index, CReadArcItem &item) const
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
static HRESULT Archive_GetItem_Size(IInArchive *archive, UInt32 index, UInt64 &size, bool &defined)
{
NCOM::CPropVariant prop;
defined = false;
size = 0;
- RINOK(archive->GetProperty(index, kpidSize, &prop));
+ RINOK(archive->GetProperty(index, kpidSize, &prop))
switch (prop.vt)
{
case VT_UI1: size = prop.bVal; break;
@@ -933,12 +961,12 @@ static HRESULT Archive_GetItem_Size(IInArchive *archive, UInt32 index, UInt64 &s
#endif
-HRESULT CArc::GetItemSize(UInt32 index, UInt64 &size, bool &defined) const
+HRESULT CArc::GetItem_Size(UInt32 index, UInt64 &size, bool &defined) const
{
NCOM::CPropVariant prop;
defined = false;
size = 0;
- RINOK(Archive->GetProperty(index, kpidSize, &prop));
+ RINOK(Archive->GetProperty(index, kpidSize, &prop))
switch (prop.vt)
{
case VT_UI1: size = prop.bVal; break;
@@ -952,28 +980,56 @@ HRESULT CArc::GetItemSize(UInt32 index, UInt64 &size, bool &defined) const
return S_OK;
}
-HRESULT CArc::GetItemMTime(UInt32 index, FILETIME &ft, bool &defined) const
+HRESULT CArc::GetItem_MTime(UInt32 index, CArcTime &at) const
{
+ at.Clear();
NCOM::CPropVariant prop;
- defined = false;
- ft.dwHighDateTime = ft.dwLowDateTime = 0;
- RINOK(Archive->GetProperty(index, kpidMTime, &prop));
+ RINOK(Archive->GetProperty(index, kpidMTime, &prop))
+
if (prop.vt == VT_FILETIME)
{
- ft = prop.filetime;
- defined = true;
+ /*
+ // for debug
+ if (FILETIME_IsZero(prop.at) && MTime.Def)
+ {
+ at = MTime;
+ return S_OK;
+ }
+ */
+ at.Set_From_Prop(prop);
+ if (at.Prec == 0)
+ {
+ // (at.Prec == 0) before version 22.
+ // so kpidTimeType is required for that code
+ prop.Clear();
+ RINOK(Archive->GetProperty(index, kpidTimeType, &prop))
+ if (prop.vt == VT_UI4)
+ {
+ UInt32 val = prop.ulVal;
+ if (val == NFileTimeType::kWindows)
+ val = k_PropVar_TimePrec_100ns;
+ /*
+ else if (val > k_PropVar_TimePrec_1ns)
+ {
+ val = k_PropVar_TimePrec_100ns;
+ // val = k_PropVar_TimePrec_1ns;
+ // return E_FAIL; // for debug
+ }
+ */
+ at.Prec = (UInt16)val;
+ }
+ }
+ return S_OK;
}
- else if (prop.vt != VT_EMPTY)
+
+ if (prop.vt != VT_EMPTY)
return E_FAIL;
- else if (MTimeDefined)
- {
- ft = MTime;
- defined = true;
- }
+ if (MTime.Def)
+ at = MTime;
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
static inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)
{
@@ -983,52 +1039,52 @@ static inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)
return true;
}
+
static void MakeCheckOrder(CCodecs *codecs,
CIntVector &orderIndices, unsigned numTypes, CIntVector &orderIndices2,
const Byte *data, size_t dataSize)
{
for (unsigned i = 0; i < numTypes; i++)
{
- int index = orderIndices[i];
+ const int index = orderIndices[i];
if (index < 0)
continue;
- const CArcInfoEx &ai = codecs->Formats[index];
- if (ai.SignatureOffset != 0)
- {
- orderIndices2.Add(index);
- orderIndices[i] = -1;
- continue;
- }
-
- const CObjectVector<CByteBuffer> &sigs = ai.Signatures;
- FOR_VECTOR (k, sigs)
+ const CArcInfoEx &ai = codecs->Formats[(unsigned)index];
+ if (ai.SignatureOffset == 0)
{
- const CByteBuffer &sig = sigs[k];
- if (sig.Size() == 0 && dataSize == 0 ||
- sig.Size() != 0 && sig.Size() <= dataSize &&
- TestSignature(data, sig, sig.Size()))
+ if (ai.Signatures.IsEmpty())
{
- orderIndices2.Add(index);
- orderIndices[i] = -1;
- break;
+ if (dataSize != 0) // 21.04: no Signature means Empty Signature
+ continue;
+ }
+ else
+ {
+ unsigned k;
+ const CObjectVector<CByteBuffer> &sigs = ai.Signatures;
+ for (k = 0; k < sigs.Size(); k++)
+ {
+ const CByteBuffer &sig = sigs[k];
+ if (sig.Size() <= dataSize && TestSignature(data, sig, sig.Size()))
+ break;
+ }
+ if (k == sigs.Size())
+ continue;
}
}
+ orderIndices2.Add(index);
+ orderIndices[i] = -1;
}
}
-#endif
-
#ifdef UNDER_CE
static const unsigned kNumHashBytes = 1;
- #define HASH_VAL(buf, pos) ((buf)[pos])
+ #define HASH_VAL(buf) ((buf)[0])
#else
static const unsigned kNumHashBytes = 2;
- #define HASH_VAL(buf, pos) ((buf)[pos] | ((UInt32)(buf)[pos + 1] << 8))
+ // #define HASH_VAL(buf) ((buf)[0] | ((UInt32)(buf)[1] << 8))
+ #define HASH_VAL(buf) GetUi16(buf)
#endif
-
-#ifndef _SFX
-
static bool IsExeExt(const UString &ext)
{
return ext.IsEqualTo_Ascii_NoCase("exe");
@@ -1056,7 +1112,7 @@ static bool IsPreArcFormat(const CArcInfoEx &ai)
{
if (ai.Flags_PreArc())
return true;
- return IsNameFromList(ai.Name, k_PreArcFormats, ARRAY_SIZE(k_PreArcFormats));
+ return IsNameFromList(ai.Name, k_PreArcFormats, Z7_ARRAY_SIZE(k_PreArcFormats));
}
static const char * const k_Formats_with_simple_signuature[] =
@@ -1078,44 +1134,46 @@ static bool IsNewStyleSignature(const CArcInfoEx &ai)
// if (ai.Version >= 0x91F)
if (ai.NewInterface)
return true;
- return IsNameFromList(ai.Name, k_Formats_with_simple_signuature, ARRAY_SIZE(k_Formats_with_simple_signuature));
+ return IsNameFromList(ai.Name, k_Formats_with_simple_signuature, Z7_ARRAY_SIZE(k_Formats_with_simple_signuature));
}
-class CArchiveOpenCallback_Offset:
+
+
+class CArchiveOpenCallback_Offset Z7_final:
public IArchiveOpenCallback,
public IArchiveOpenVolumeCallback,
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
public ICryptoGetTextPassword,
- #endif
+ #endif
public CMyUnknownImp
{
+ Z7_COM_QI_BEGIN2(IArchiveOpenCallback)
+ Z7_COM_QI_ENTRY(IArchiveOpenVolumeCallback)
+ #ifndef Z7_NO_CRYPTO
+ Z7_COM_QI_ENTRY(ICryptoGetTextPassword)
+ #endif
+ Z7_COM_QI_END
+ Z7_COM_ADDREF_RELEASE
+
+ Z7_IFACE_COM7_IMP(IArchiveOpenCallback)
+ Z7_IFACE_COM7_IMP(IArchiveOpenVolumeCallback)
+ #ifndef Z7_NO_CRYPTO
+ Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
+ #endif
+
public:
CMyComPtr<IArchiveOpenCallback> Callback;
CMyComPtr<IArchiveOpenVolumeCallback> OpenVolumeCallback;
UInt64 Files;
UInt64 Offset;
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
CMyComPtr<ICryptoGetTextPassword> GetTextPassword;
#endif
-
- MY_QUERYINTERFACE_BEGIN2(IArchiveOpenCallback)
- MY_QUERYINTERFACE_ENTRY(IArchiveOpenVolumeCallback)
- #ifndef _NO_CRYPTO
- MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)
- #endif
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IArchiveOpenCallback(;)
- INTERFACE_IArchiveOpenVolumeCallback(;)
- #ifndef _NO_CRYPTO
- STDMETHOD(CryptoGetTextPassword)(BSTR *password);
- #endif
};
-#ifndef _NO_CRYPTO
-STDMETHODIMP CArchiveOpenCallback_Offset::CryptoGetTextPassword(BSTR *password)
+#ifndef Z7_NO_CRYPTO
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::CryptoGetTextPassword(BSTR *password))
{
COM_TRY_BEGIN
if (GetTextPassword)
@@ -1125,12 +1183,12 @@ STDMETHODIMP CArchiveOpenCallback_Offset::CryptoGetTextPassword(BSTR *password)
}
#endif
-STDMETHODIMP CArchiveOpenCallback_Offset::SetTotal(const UInt64 *, const UInt64 *)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::SetTotal(const UInt64 *, const UInt64 *))
{
return S_OK;
}
-STDMETHODIMP CArchiveOpenCallback_Offset::SetCompleted(const UInt64 *, const UInt64 *bytes)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::SetCompleted(const UInt64 *, const UInt64 *bytes))
{
if (!Callback)
return S_OK;
@@ -1140,7 +1198,7 @@ STDMETHODIMP CArchiveOpenCallback_Offset::SetCompleted(const UInt64 *, const UIn
return Callback->SetCompleted(&Files, &value);
}
-STDMETHODIMP CArchiveOpenCallback_Offset::GetProperty(PROPID propID, PROPVARIANT *value)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::GetProperty(PROPID propID, PROPVARIANT *value))
{
if (OpenVolumeCallback)
return OpenVolumeCallback->GetProperty(propID, value);
@@ -1149,7 +1207,7 @@ STDMETHODIMP CArchiveOpenCallback_Offset::GetProperty(PROPID propID, PROPVARIANT
// return E_NOTIMPL;
}
-STDMETHODIMP CArchiveOpenCallback_Offset::GetStream(const wchar_t *name, IInStream **inStream)
+Z7_COM7F_IMF(CArchiveOpenCallback_Offset::GetStream(const wchar_t *name, IInStream **inStream))
{
if (OpenVolumeCallback)
return OpenVolumeCallback->GetStream(name, inStream);
@@ -1193,7 +1251,7 @@ void CArcErrorInfo::ClearErrors()
HRESULT CArc::ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openRes)
{
// OkPhySize_Defined = false;
- PhySizeDefined = false;
+ PhySize_Defined = false;
PhySize = 0;
Offset = 0;
AvailPhySize = FileSize - startPos;
@@ -1201,49 +1259,49 @@ HRESULT CArc::ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openR
ErrorInfo.ClearErrors();
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidErrorFlags, &prop));
+ RINOK(archive->GetArchiveProperty(kpidErrorFlags, &prop))
ErrorInfo.ErrorFlags = GetOpenArcErrorFlags(prop, &ErrorInfo.ErrorFlags_Defined);
}
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidWarningFlags, &prop));
+ RINOK(archive->GetArchiveProperty(kpidWarningFlags, &prop))
ErrorInfo.WarningFlags = GetOpenArcErrorFlags(prop);
}
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidError, &prop));
+ RINOK(archive->GetArchiveProperty(kpidError, &prop))
if (prop.vt != VT_EMPTY)
ErrorInfo.ErrorMessage = (prop.vt == VT_BSTR ? prop.bstrVal : L"Unknown error");
}
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidWarning, &prop));
+ RINOK(archive->GetArchiveProperty(kpidWarning, &prop))
if (prop.vt != VT_EMPTY)
ErrorInfo.WarningMessage = (prop.vt == VT_BSTR ? prop.bstrVal : L"Unknown warning");
}
if (openRes == S_OK || ErrorInfo.IsArc_After_NonOpen())
{
- RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, PhySize, PhySizeDefined));
+ RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, PhySize, PhySize_Defined))
/*
RINOK(Archive_GetArcProp_UInt(archive, kpidOkPhySize, OkPhySize, OkPhySize_Defined));
if (!OkPhySize_Defined)
{
- OkPhySize_Defined = PhySizeDefined;
+ OkPhySize_Defined = PhySize_Defined;
OkPhySize = PhySize;
}
*/
bool offsetDefined;
- RINOK(Archive_GetArcProp_Int(archive, kpidOffset, Offset, offsetDefined));
+ RINOK(Archive_GetArcProp_Int(archive, kpidOffset, Offset, offsetDefined))
- Int64 globalOffset = startPos + Offset;
- AvailPhySize = FileSize - globalOffset;
- if (PhySizeDefined)
+ Int64 globalOffset = (Int64)startPos + Offset;
+ AvailPhySize = (UInt64)((Int64)FileSize - globalOffset);
+ if (PhySize_Defined)
{
- UInt64 endPos = globalOffset + PhySize;
+ UInt64 endPos = (UInt64)(globalOffset + (Int64)PhySize);
if (endPos < FileSize)
{
AvailPhySize = PhySize;
@@ -1259,11 +1317,12 @@ HRESULT CArc::ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openR
}
/*
-static PrintNumber(const char *s, int n)
+static void PrintNumber(const char *s, int n)
{
char temp[100];
sprintf(temp, "%s %d", s, n);
- OutputDebugStringA(temp);
+ // OutputDebugStringA(temp);
+ printf(temp);
}
*/
@@ -1272,31 +1331,31 @@ HRESULT CArc::PrepareToOpen(const COpenOptions &op, unsigned formatIndex, CMyCom
// OutputDebugStringA("a1");
// PrintNumber("formatIndex", formatIndex);
- RINOK(op.codecs->CreateInArchive(formatIndex, archive));
+ RINOK(op.codecs->CreateInArchive(formatIndex, archive))
// OutputDebugStringA("a2");
if (!archive)
return S_OK;
- #ifdef EXTERNAL_CODECS
+ #ifdef Z7_EXTERNAL_CODECS
if (op.codecs->NeedSetLibCodecs)
{
const CArcInfoEx &ai = op.codecs->Formats[formatIndex];
if (ai.LibIndex >= 0 ?
- !op.codecs->Libs[ai.LibIndex].SetCodecs :
+ !op.codecs->Libs[(unsigned)ai.LibIndex].SetCodecs :
!op.codecs->Libs.IsEmpty())
{
CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
if (setCompressCodecsInfo)
{
- RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(op.codecs));
+ RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(op.codecs))
}
}
}
#endif
- #ifndef _SFX
+ #ifndef Z7_SFX
const CArcInfoEx &ai = op.codecs->Formats[formatIndex];
@@ -1326,14 +1385,14 @@ HRESULT CArc::PrepareToOpen(const COpenOptions &op, unsigned formatIndex, CMyCom
}
}
*/
- RINOK(SetProperties(archive, *op.props));
+ RINOK(SetProperties(archive, *op.props))
}
#endif
return S_OK;
}
-#ifndef _SFX
+#ifndef Z7_SFX
static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NArchive::NParser::CParseItem &pi)
{
@@ -1341,14 +1400,14 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
pi.FileTime_Defined = false;
pi.ArcType = ai.Name;
- RINOK(Archive_GetArcBoolProp(archive, kpidIsNotArcType, pi.IsNotArcType));
+ RINOK(Archive_GetArcProp_Bool(archive, kpidIsNotArcType, pi.IsNotArcType))
- // RINOK(Archive_GetArcBoolProp(archive, kpidIsSelfExe, pi.IsSelfExe));
+ // RINOK(Archive_GetArcProp_Bool(archive, kpidIsSelfExe, pi.IsSelfExe));
pi.IsSelfExe = ai.Flags_PreArc();
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidMTime, &prop));
+ RINOK(archive->GetArchiveProperty(kpidMTime, &prop))
if (prop.vt == VT_FILETIME)
{
pi.FileTime_Defined = true;
@@ -1359,7 +1418,7 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
if (!pi.FileTime_Defined)
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidCTime, &prop));
+ RINOK(archive->GetArchiveProperty(kpidCTime, &prop))
if (prop.vt == VT_FILETIME)
{
pi.FileTime_Defined = true;
@@ -1369,7 +1428,7 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidName, &prop));
+ RINOK(archive->GetArchiveProperty(kpidName, &prop))
if (prop.vt == VT_BSTR)
{
pi.Name.SetFromBstr(prop.bstrVal);
@@ -1377,7 +1436,7 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
}
else
{
- RINOK(archive->GetArchiveProperty(kpidExtension, &prop));
+ RINOK(archive->GetArchiveProperty(kpidExtension, &prop))
if (prop.vt == VT_BSTR)
pi.Extension.SetFromBstr(prop.bstrVal);
}
@@ -1385,14 +1444,14 @@ static HRESULT ReadParseItemProps(IInArchive *archive, const CArcInfoEx &ai, NAr
{
NCOM::CPropVariant prop;
- RINOK(archive->GetArchiveProperty(kpidShortComment, &prop));
+ RINOK(archive->GetArchiveProperty(kpidShortComment, &prop))
if (prop.vt == VT_BSTR)
pi.Comment.SetFromBstr(prop.bstrVal);
}
UInt32 numItems;
- RINOK(archive->GetNumberOfItems(&numItems));
+ RINOK(archive->GetNumberOfItems(&numItems))
// pi.NumSubFiles = numItems;
// RINOK(Archive_GetArcProp_UInt(archive, kpidUnpackSize, pi.UnpackSize, pi.UnpackSize_Defined));
@@ -1433,14 +1492,14 @@ HRESULT CArc::CheckZerosTail(const COpenOptions &op, UInt64 offset)
{
if (!op.stream)
return S_OK;
- RINOK(op.stream->Seek(offset, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekSet(op.stream, offset))
const UInt32 kBufSize = 1 << 11;
Byte buf[kBufSize];
for (;;)
{
UInt32 processed = 0;
- RINOK(op.stream->Read(buf, kBufSize, &processed));
+ RINOK(op.stream->Read(buf, kBufSize, &processed))
if (processed == 0)
{
// ErrorInfo.NonZerosTail = false;
@@ -1459,21 +1518,21 @@ HRESULT CArc::CheckZerosTail(const COpenOptions &op, UInt64 offset)
}
}
-#ifndef _SFX
-class CExtractCallback_To_OpenCallback:
- public IArchiveExtractCallback,
- public ICompressProgressInfo,
- public CMyUnknownImp
-{
+
+#ifndef Z7_SFX
+
+Z7_CLASS_IMP_COM_2(
+ CExtractCallback_To_OpenCallback
+ , IArchiveExtractCallback
+ , ICompressProgressInfo
+)
+ Z7_IFACE_COM7_IMP(IProgress)
public:
CMyComPtr<IArchiveOpenCallback> Callback;
UInt64 Files;
UInt64 Offset;
- MY_UNKNOWN_IMP2(IArchiveExtractCallback, ICompressProgressInfo)
- INTERFACE_IArchiveExtractCallback(;)
- STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
void Init(IArchiveOpenCallback *callback)
{
Callback = callback;
@@ -1482,17 +1541,17 @@ public:
}
};
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetTotal(UInt64 /* size */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetTotal(UInt64 /* size */))
{
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetCompleted(const UInt64 * /* completeValue */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetCompleted(const UInt64 * /* completeValue */))
{
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */))
{
if (Callback)
{
@@ -1504,22 +1563,23 @@ STDMETHODIMP CExtractCallback_To_OpenCallback::SetRatioInfo(const UInt64 *inSize
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::GetStream(UInt32 /* index */, ISequentialOutStream **outStream, Int32 /* askExtractMode */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::GetStream(UInt32 /* index */, ISequentialOutStream **outStream, Int32 /* askExtractMode */))
{
- *outStream = 0;
+ *outStream = NULL;
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::PrepareOperation(Int32 /* askExtractMode */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::PrepareOperation(Int32 /* askExtractMode */))
{
return S_OK;
}
-STDMETHODIMP CExtractCallback_To_OpenCallback::SetOperationResult(Int32 /* operationResult */)
+Z7_COM7F_IMF(CExtractCallback_To_OpenCallback::SetOperationResult(Int32 /* operationResult */))
{
return S_OK;
}
+
static HRESULT OpenArchiveSpec(IInArchive *archive, bool needPhySize,
IInStream *stream, const UInt64 *maxCheckStartPosition,
IArchiveOpenCallback *openCallback,
@@ -1528,37 +1588,48 @@ static HRESULT OpenArchiveSpec(IInArchive *archive, bool needPhySize,
/*
if (needPhySize)
{
- CMyComPtr<IArchiveOpen2> open2;
- archive->QueryInterface(IID_IArchiveOpen2, (void **)&open2);
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveOpen2,
+ open2, archive)
if (open2)
return open2->ArcOpen2(stream, kOpenFlags_RealPhySize, openCallback);
}
*/
- RINOK(archive->Open(stream, maxCheckStartPosition, openCallback));
+ RINOK(archive->Open(stream, maxCheckStartPosition, openCallback))
if (needPhySize)
{
bool phySize_Defined = false;
UInt64 phySize = 0;
- RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, phySize, phySize_Defined));
+ RINOK(Archive_GetArcProp_UInt(archive, kpidPhySize, phySize, phySize_Defined))
if (phySize_Defined)
return S_OK;
- bool phySizeCantBeDetected = false;;
- RINOK(Archive_GetArcBoolProp(archive, kpidPhySizeCantBeDetected, phySizeCantBeDetected));
+ bool phySizeCantBeDetected = false;
+ RINOK(Archive_GetArcProp_Bool(archive, kpidPhySizeCantBeDetected, phySizeCantBeDetected))
if (!phySizeCantBeDetected)
{
- RINOK(archive->Extract(0, (UInt32)(Int32)-1, BoolToInt(true), extractCallback));
+ PRF(printf("\n-- !phySize_Defined after Open, call archive->Extract()"));
+ // It's for bzip2/gz and some xz archives, where Open operation doesn't know phySize.
+ // But the Handler will know phySize after full archive testing.
+ RINOK(archive->Extract(NULL, (UInt32)(Int32)-1, BoolToInt(true), extractCallback))
+ PRF(printf("\n-- OK"));
}
}
return S_OK;
}
+
+
static int FindFormatForArchiveType(CCodecs *codecs, CIntVector orderIndices, const char *name)
{
FOR_VECTOR (i, orderIndices)
- if (StringsAreEqualNoCase_Ascii(codecs->Formats[orderIndices[i]].Name, name))
- return i;
+ {
+ int oi = orderIndices[i];
+ if (oi >= 0)
+ if (StringsAreEqualNoCase_Ascii(codecs->Formats[(unsigned)oi].Name, name))
+ return (int)i;
+ }
return -1;
}
@@ -1584,15 +1655,15 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const UString fileName = ExtractFileNameFromPath(Path);
UString extension;
{
- int dotPos = fileName.ReverseFind_Dot();
+ const int dotPos = fileName.ReverseFind_Dot();
if (dotPos >= 0)
- extension = fileName.Ptr(dotPos + 1);
+ extension = fileName.Ptr((unsigned)(dotPos + 1));
}
CIntVector orderIndices;
bool searchMarkerInHandler = false;
- #ifdef _SFX
+ #ifdef Z7_SFX
searchMarkerInHandler = true;
#endif
@@ -1602,22 +1673,27 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
isMainFormatArr[i] = false;
}
- UInt64 maxStartOffset =
+ const UInt64 maxStartOffset =
op.openType.MaxStartOffset_Defined ?
op.openType.MaxStartOffset :
kMaxCheckStartPosition;
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isUnknownExt = false;
#endif
+ #ifndef Z7_SFX
bool isForced = false;
+ #endif
+
unsigned numMainTypes = 0;
- int formatIndex = op.openType.FormatIndex;
+ const int formatIndex = op.openType.FormatIndex;
if (formatIndex >= 0)
{
+ #ifndef Z7_SFX
isForced = true;
+ #endif
orderIndices.Add(formatIndex);
numMainTypes = 1;
isMainFormatArr[(unsigned)formatIndex] = true;
@@ -1627,12 +1703,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
else
{
unsigned numFinded = 0;
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isPrearcExt = false;
#endif
{
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isZip = false;
bool isRar = false;
@@ -1654,10 +1730,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
isNumber = true;
}
if (isNumber)
+ {
if (c == 'z' || c == 'Z')
isZip = true;
else
isRar = true;
+ }
}
#endif
@@ -1667,29 +1745,29 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const CArcInfoEx &ai = op.codecs->Formats[i];
if (IgnoreSplit || !op.openType.CanReturnArc)
- if (ai.IsSplit())
+ if (ai.Is_Split())
continue;
- if (op.excludedFormats->FindInSorted(i) >= 0)
+ if (op.excludedFormats->FindInSorted((int)i) >= 0)
continue;
- #ifndef _SFX
+ #ifndef Z7_SFX
if (IsPreArcFormat(ai))
isPrearcExt = true;
#endif
if (ai.FindExtension(extension) >= 0
- #ifndef _SFX
- || isZip && StringsAreEqualNoCase_Ascii(ai.Name, "zip")
- || isRar && StringsAreEqualNoCase_Ascii(ai.Name, "rar")
+ #ifndef Z7_SFX
+ || (isZip && ai.Is_Zip())
+ || (isRar && ai.Is_Rar())
#endif
)
{
// PrintNumber("orderIndices.Insert", i);
- orderIndices.Insert(numFinded++, i);
+ orderIndices.Insert(numFinded++, (int)i);
isMainFormatArr[i] = true;
}
else
- orderIndices.Add(i);
+ orderIndices.Add((int)i);
}
}
@@ -1709,11 +1787,11 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
*/
- #ifndef _SFX
+ #ifndef Z7_SFX
if (op.stream && orderIndices.Size() >= 2)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
CByteBuffer byteBuffer;
CIntVector orderIndices2;
if (numFinded == 0 || IsExeExt(extension))
@@ -1722,21 +1800,21 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
else if (extension.IsEqualTo("000") || extension.IsEqualTo("001"))
{
- int i = FindFormatForArchiveType(op.codecs, orderIndices, "rar");
+ const int i = FindFormatForArchiveType(op.codecs, orderIndices, "rar");
if (i >= 0)
{
const size_t kBufSize = (1 << 10);
byteBuffer.Alloc(kBufSize);
size_t processedSize = kBufSize;
- RINOK(ReadStream(op.stream, byteBuffer, &processedSize));
+ RINOK(ReadStream(op.stream, byteBuffer, &processedSize))
if (processedSize >= 16)
{
const Byte *buf = byteBuffer;
const Byte kRarHeader[] = { 0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 };
if (TestSignature(buf, kRarHeader, 7) && buf[9] == 0x73 && (buf[10] & 1) != 0)
{
- orderIndices2.Add(orderIndices[i]);
- orderIndices[i] = -1;
+ orderIndices2.Add(orderIndices[(unsigned)i]);
+ orderIndices[(unsigned)i] = -1;
if (i >= (int)numFinded)
numFinded++;
}
@@ -1748,17 +1826,33 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const size_t kBufSize = (1 << 10);
byteBuffer.Alloc(kBufSize);
size_t processedSize = kBufSize;
- RINOK(ReadStream(op.stream, byteBuffer, &processedSize));
+ RINOK(ReadStream(op.stream, byteBuffer, &processedSize))
if (processedSize == 0)
return S_FALSE;
/*
check type order:
- 1) matched extension, no signuature
- 2) matched extension, matched signuature
+ 0) matched_extension && Backward
+ 1) matched_extension && (no_signuature || SignatureOffset != 0)
+ 2) matched_extension && (matched_signature)
// 3) no signuature
// 4) matched signuature
*/
+ // we move index from orderIndices to orderIndices2 for priority handlers.
+
+ for (unsigned i = 0; i < numFinded; i++)
+ {
+ const int index = orderIndices[i];
+ if (index < 0)
+ continue;
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)index];
+ if (ai.Flags_BackwardOpen())
+ {
+ // backward doesn't need start signatures
+ orderIndices2.Add(index);
+ orderIndices[i] = -1;
+ }
+ }
MakeCheckOrder(op.codecs, orderIndices, numFinded, orderIndices2, NULL, 0);
MakeCheckOrder(op.codecs, orderIndices, numFinded, orderIndices2, byteBuffer, processedSize);
@@ -1768,7 +1862,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
FOR_VECTOR (i, orderIndices)
{
- int val = orderIndices[i];
+ const int val = orderIndices[i];
if (val != -1)
orderIndices2.Add(val);
}
@@ -1777,21 +1871,21 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (orderIndices.Size() >= 2)
{
- int iIso = FindFormatForArchiveType(op.codecs, orderIndices, "iso");
- int iUdf = FindFormatForArchiveType(op.codecs, orderIndices, "udf");
+ const int iIso = FindFormatForArchiveType(op.codecs, orderIndices, "iso");
+ const int iUdf = FindFormatForArchiveType(op.codecs, orderIndices, "udf");
if (iUdf > iIso && iIso >= 0)
{
- int isoIndex = orderIndices[iIso];
- int udfIndex = orderIndices[iUdf];
- orderIndices[iUdf] = isoIndex;
- orderIndices[iIso] = udfIndex;
+ const int isoIndex = orderIndices[(unsigned)iIso];
+ const int udfIndex = orderIndices[(unsigned)iUdf];
+ orderIndices[(unsigned)iUdf] = isoIndex;
+ orderIndices[(unsigned)iIso] = udfIndex;
}
}
numMainTypes = numFinded;
isUnknownExt = (numMainTypes == 0) || isPrearcExt;
- #else // _SFX
+ #else // Z7_SFX
numMainTypes = orderIndices.Size();
@@ -1805,13 +1899,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
UInt64 fileSize = 0;
if (op.stream)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_END, &fileSize));
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_GetSize_SeekToBegin(op.stream, fileSize))
}
FileSize = fileSize;
- #ifndef _SFX
+ #ifndef Z7_SFX
CBoolArr skipFrontalFormat(op.codecs->Formats.Size());
{
@@ -1838,15 +1931,18 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
for (unsigned i = 0; i < numCheckTypes; i++)
{
FormatIndex = orderIndices[i];
+
+ // orderIndices[] item cannot be negative here
bool exactOnly = false;
- #ifndef _SFX
+ #ifndef Z7_SFX
- const CArcInfoEx &ai = op.codecs->Formats[FormatIndex];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)FormatIndex];
// OutputDebugStringW(ai.Name);
if (i >= numMainTypes)
{
+ // here we allow mismatched extension only for backward handlers
if (!ai.Flags_BackwardOpen()
// && !ai.Flags_PureStartOpen()
)
@@ -1858,16 +1954,16 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// Some handlers do not set total bytes. So we set it here
if (op.callback)
- RINOK(op.callback->SetTotal(NULL, &fileSize));
+ RINOK(op.callback->SetTotal(NULL, &fileSize))
if (op.stream)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
}
CMyComPtr<IInArchive> archive;
- RINOK(PrepareToOpen(op, FormatIndex, archive));
+ RINOK(PrepareToOpen(op, (unsigned)FormatIndex, archive))
if (!archive)
continue;
@@ -1886,13 +1982,13 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
result = openSeq->OpenSeq(op.seqStream);
}
- RINOK(ReadBasicProps(archive, 0, result));
+ RINOK(ReadBasicProps(archive, 0, result))
if (result == S_FALSE)
{
bool isArc = ErrorInfo.IsArc_After_NonOpen();
- #ifndef _SFX
+ #ifndef Z7_SFX
// if it's archive, we allow another open attempt for parser
if (!mode.CanReturnParser || !isArc)
skipFrontalFormat[(unsigned)FormatIndex] = true;
@@ -1912,7 +2008,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// if (formatIndex < 0 && !searchMarkerInHandler)
{
// if bad archive was detected, we don't need additional open attempts
- #ifndef _SFX
+ #ifndef Z7_SFX
if (!IsPreArcFormat(ai) /* || !mode.SkipSfxStub */)
#endif
return S_FALSE;
@@ -1921,7 +2017,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
/*
- #ifndef _SFX
+ #ifndef Z7_SFX
if (IsExeExt(extension) || ai.Flags_PreArc())
{
// openOnlyFullArc = false;
@@ -1934,9 +2030,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
}
- RINOK(result);
+ RINOK(result)
- #ifndef _SFX
+ #ifndef Z7_SFX
bool isMainFormat = isMainFormatArr[(unsigned)FormatIndex];
const COpenSpecFlags &specFlags = mode.GetSpec(isForced, isMainFormat, isUnknownExt);
@@ -1944,7 +2040,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
bool thereIsTail = ErrorInfo.ThereIsTail;
if (thereIsTail && mode.ZerosTailIsAllowed)
{
- RINOK(CheckZerosTail(op, Offset + PhySize));
+ RINOK(CheckZerosTail(op, (UInt64)(Offset + (Int64)PhySize)))
if (ErrorInfo.IgnoreTail)
thereIsTail = false;
}
@@ -1998,7 +2094,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
- #ifndef _SFX
+ #ifndef Z7_SFX
if (!op.stream)
return S_FALSE;
@@ -2012,7 +2108,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
else
{
- const CArcInfoEx &ai = op.codecs->Formats[formatIndex];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)formatIndex];
if (ai.FindExtension(extension) >= 0)
{
if (ai.Flags_FindSignature() && searchMarkerInHandler)
@@ -2043,9 +2139,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
endOfFile = true;
}
byteBuffer.Alloc(bufSize);
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
processedSize = bufSize;
- RINOK(ReadStream(op.stream, byteBuffer, &processedSize));
+ RINOK(ReadStream(op.stream, byteBuffer, &processedSize))
if (processedSize == 0)
return S_FALSE;
if (processedSize < bufSize)
@@ -2059,16 +2155,22 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
for (i = 0; i < orderIndices.Size(); i++)
{
- unsigned form = orderIndices[i];
+ // orderIndices[] item cannot be negative here
+ unsigned form = (unsigned)orderIndices[i];
if (skipFrontalFormat[form])
continue;
+
const CArcInfoEx &ai = op.codecs->Formats[form];
- if (ai.IsSplit())
+
+ if (ai.Is_Split())
{
- splitIndex = form;
+ splitIndex = (int)form;
continue;
}
+ if (ai.Flags_ByExtOnlyOpen())
+ continue;
+
if (ai.IsArcFunc)
{
UInt32 isArcRes = ai.IsArcFunc(byteBuffer, processedSize);
@@ -2081,7 +2183,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
}
- bool isNewStyleSignature = IsNewStyleSignature(ai);
+ const bool isNewStyleSignature = IsNewStyleSignature(ai);
bool needCheck = !isNewStyleSignature
|| ai.Signatures.IsEmpty()
|| ai.Flags_PureStartOpen()
@@ -2094,13 +2196,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
for (k = 0; k < ai.Signatures.Size(); k++)
{
const CByteBuffer &sig = ai.Signatures[k];
- UInt32 signatureEnd = ai.SignatureOffset + (UInt32)sig.Size();
- if (processedSize < signatureEnd)
+ if (processedSize < ai.SignatureOffset + sig.Size())
{
if (!endOfFile)
needCheck = true;
}
- else if (memcmp(sig, byteBuffer + ai.SignatureOffset, sig.Size()) == 0)
+ else if (TestSignature(sig, byteBuffer + ai.SignatureOffset, sig.Size()))
break;
}
if (k != ai.Signatures.Size())
@@ -2114,20 +2215,20 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
if (splitIndex >= 0)
- sortedFormats.Insert(0, splitIndex);
+ sortedFormats.Insert(0, (unsigned)splitIndex);
for (i = 0; i < sortedFormats.Size(); i++)
{
- FormatIndex = sortedFormats[i];
- const CArcInfoEx &ai = op.codecs->Formats[FormatIndex];
+ FormatIndex = (int)sortedFormats[i];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)FormatIndex];
if (op.callback)
- RINOK(op.callback->SetTotal(NULL, &fileSize));
+ RINOK(op.callback->SetTotal(NULL, &fileSize))
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
CMyComPtr<IInArchive> archive;
- RINOK(PrepareToOpen(op, FormatIndex, archive));
+ RINOK(PrepareToOpen(op, (unsigned)FormatIndex, archive))
if (!archive)
continue;
@@ -2140,7 +2241,10 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
result = archive->Open(op.stream, &searchLimit, op.callback);
else
*/
- result = OpenArchiveSpec(archive, !mode.CanReturnArc, op.stream, &searchLimit, op.callback, extractCallback_To_OpenCallback);
+ // if (!CanReturnArc), it's ParserMode, and we need phy size
+ result = OpenArchiveSpec(archive,
+ !mode.CanReturnArc, // needPhySize
+ op.stream, &searchLimit, op.callback, extractCallback_To_OpenCallback);
}
if (result == S_FALSE)
@@ -2150,9 +2254,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// printf(" OpenForSize Error");
continue;
}
- RINOK(result);
+ RINOK(result)
- RINOK(ReadBasicProps(archive, 0, result));
+ RINOK(ReadBasicProps(archive, 0, result))
if (Offset > 0)
{
@@ -2162,12 +2266,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
NArchive::NParser::CParseItem pi;
- pi.Offset = Offset;
+ pi.Offset = (UInt64)Offset;
pi.Size = AvailPhySize;
// bool needScan = false;
- if (!PhySizeDefined)
+ if (!PhySize_Defined)
{
// it's for Z format
pi.LenIsUnknown = true;
@@ -2189,7 +2293,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (mode.CanReturnArc)
{
- bool isMainFormat = isMainFormatArr[(unsigned)FormatIndex];
+ const bool isMainFormat = isMainFormatArr[(unsigned)FormatIndex];
const COpenSpecFlags &specFlags = mode.GetSpec(isForced, isMainFormat, isUnknownExt);
bool openCur = false;
@@ -2199,7 +2303,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
{
if (mode.ZerosTailIsAllowed)
{
- RINOK(CheckZerosTail(op, Offset + PhySize));
+ RINOK(CheckZerosTail(op, (UInt64)(Offset + (Int64)PhySize)))
if (ErrorInfo.IgnoreTail)
openCur = true;
}
@@ -2239,7 +2343,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
// printf("\nAdd offset = %d", (int)pi.Offset);
- RINOK(ReadParseItemProps(archive, ai, pi));
+ RINOK(ReadParseItemProps(archive, ai, pi))
handlerSpec->AddItem(pi);
}
}
@@ -2294,7 +2398,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
int index = orderIndices[i];
if (index < 0)
continue;
- const CArcInfoEx &ai = op.codecs->Formats[index];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)index];
+ if (ai.Flags_ByExtOnlyOpen())
+ continue;
bool isDifficult = false;
// if (ai.Version < 0x91F) // we don't use parser with old DLL (before 9.31)
if (!ai.NewInterface)
@@ -2317,7 +2423,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
continue;
}
thereAreHandlersForSearch = true;
- UInt32 v = HASH_VAL(sig, 0);
+ UInt32 v = HASH_VAL(sig);
unsigned sigIndex = arc2sig[(unsigned)index] + k;
prevs[sigIndex] = hash[v];
hash[v] = (Byte)sigIndex;
@@ -2325,8 +2431,8 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
if (isDifficult)
{
- difficultFormats.Add(index);
- difficultBools[index] = true;
+ difficultFormats.Add((unsigned)index);
+ difficultBools[(unsigned)index] = true;
}
}
@@ -2336,7 +2442,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// canReturnTailArc = true;
}
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
CLimitedCachedInStream *limitedStreamSpec = new CLimitedCachedInStream;
CMyComPtr<IInStream> limitedStream = limitedStreamSpec;
@@ -2350,13 +2456,13 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
openCallback_Offset = openCallback_Offset_Spec;
openCallback_Offset_Spec->Callback = op.callback;
openCallback_Offset_Spec->Callback.QueryInterface(IID_IArchiveOpenVolumeCallback, &openCallback_Offset_Spec->OpenVolumeCallback);
- #ifndef _NO_CRYPTO
+ #ifndef Z7_NO_CRYPTO
openCallback_Offset_Spec->Callback.QueryInterface(IID_ICryptoGetTextPassword, &openCallback_Offset_Spec->GetTextPassword);
#endif
}
if (op.callback)
- RINOK(op.callback->SetTotal(NULL, &fileSize));
+ RINOK(op.callback->SetTotal(NULL, &fileSize))
CByteBuffer &byteBuffer = limitedStreamSpec->Buffer;
byteBuffer.Alloc(kBufSize);
@@ -2394,8 +2500,8 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
size_t processedSize = kBufSize - bytesInBuf;
// printf("\nRead ask = %d", (unsigned)processedSize);
UInt64 seekPos = bufPhyPos + bytesInBuf;
- RINOK(op.stream->Seek(bufPhyPos + bytesInBuf, STREAM_SEEK_SET, NULL));
- RINOK(ReadStream(op.stream, byteBuffer + bytesInBuf, &processedSize));
+ RINOK(InStream_SeekSet(op.stream, bufPhyPos + bytesInBuf))
+ RINOK(ReadStream(op.stream, byteBuffer + bytesInBuf, &processedSize))
// printf(" processed = %d", (unsigned)processedSize);
if (processedSize == 0)
{
@@ -2440,6 +2546,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
}
+ if (bytesInBuf <= (size_t)posInBuf)
+ break;
+
bool useOffsetCallback = false;
if (openCallback_Offset)
{
@@ -2450,7 +2559,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (pos >= callbackPrev + (1 << 23))
{
- RINOK(openCallback_Offset_Spec->SetCompleted(NULL, NULL));
+ RINOK(openCallback_Offset->SetCompleted(NULL, NULL))
callbackPrev = pos;
}
}
@@ -2464,7 +2573,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
}
- size_t availSize = bytesInBuf - (size_t)posInBuf;
+ const size_t availSize = bytesInBuf - (size_t)posInBuf;
if (availSize < kNumHashBytes)
break;
size_t scanSize = availSize -
@@ -2489,17 +2598,19 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
scanSize++;
const Byte *buf = byteBuffer + (size_t)posInBuf;
+ const Byte *bufLimit = buf + scanSize;
size_t ppp = 0;
if (!needCheckStartOpen)
{
- for (; ppp < scanSize && hash[HASH_VAL(buf, ppp)] == 0xFF; ppp++);
+ for (; buf < bufLimit && hash[HASH_VAL(buf)] == 0xFF; buf++);
+ ppp = (size_t)(buf - (byteBuffer + (size_t)posInBuf));
pos += ppp;
- if (ppp == scanSize)
+ if (buf == bufLimit)
continue;
}
- UInt32 v = HASH_VAL(buf, ppp);
+ UInt32 v = HASH_VAL(buf);
bool nextNeedCheckStartOpen = true;
unsigned i = hash[v];
unsigned indexOfDifficult = 0;
@@ -2539,7 +2650,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
const CByteBuffer &sig = ai.Signatures[sigIndex];
if (ppp + sig.Size() > availSize
- || !TestSignature(buf + ppp, sig, sig.Size()))
+ || !TestSignature(buf, sig, sig.Size()))
continue;
// printf("\nSignature OK: %10S %8x %5d", (const wchar_t *)ai.Name, (int)pos, (int)(pos - prevPos));
// prevPos = pos;
@@ -2571,10 +2682,10 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (ai.IsArcFunc && startArcPos >= bufPhyPos)
{
- size_t offsetInBuf = (size_t)(startArcPos - bufPhyPos);
+ const size_t offsetInBuf = (size_t)(startArcPos - bufPhyPos);
if (offsetInBuf < bytesInBuf)
{
- UInt32 isArcRes = ai.IsArcFunc(byteBuffer + offsetInBuf, bytesInBuf - offsetInBuf);
+ const UInt32 isArcRes = ai.IsArcFunc(byteBuffer + offsetInBuf, bytesInBuf - offsetInBuf);
if (isArcRes == k_IsArc_Res_NO)
continue;
if (isArcRes == k_IsArc_Res_NEED_MORE && endOfFile)
@@ -2590,34 +2701,30 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
// printf("\nIsArc OK: %S", (const wchar_t *)ai.Name);
}
- /*
- if (pos == 67109888)
- pos = pos;
- */
PRF(printf("\npos = %9I64d : %S", pos, (const wchar_t *)ai.Name));
- bool isMainFormat = isMainFormatArr[index];
+ const bool isMainFormat = isMainFormatArr[index];
const COpenSpecFlags &specFlags = mode.GetSpec(isForced, isMainFormat, isUnknownExt);
CMyComPtr<IInArchive> archive;
- RINOK(PrepareToOpen(op, index, archive));
+ RINOK(PrepareToOpen(op, index, archive))
if (!archive)
return E_FAIL;
// OutputDebugStringW(ai.Name);
- UInt64 rem = fileSize - startArcPos;
+ const UInt64 rem = fileSize - startArcPos;
UInt64 arcStreamOffset = 0;
if (ai.Flags_UseGlobalOffset())
{
- limitedStreamSpec->InitAndSeek(0, fileSize);
- limitedStream->Seek(startArcPos, STREAM_SEEK_SET, NULL);
+ RINOK(limitedStreamSpec->InitAndSeek(0, fileSize))
+ RINOK(InStream_SeekSet(limitedStream, startArcPos))
}
else
{
- limitedStreamSpec->InitAndSeek(startArcPos, rem);
+ RINOK(limitedStreamSpec->InitAndSeek(startArcPos, rem))
arcStreamOffset = startArcPos;
}
@@ -2633,33 +2740,42 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
extractCallback_To_OpenCallback_Spec->Files = 0;
extractCallback_To_OpenCallback_Spec->Offset = startArcPos;
- HRESULT result = OpenArchiveSpec(archive, true, limitedStream, &maxCheckStartPosition,
+ HRESULT result = OpenArchiveSpec(archive,
+ true, // needPhySize
+ limitedStream, &maxCheckStartPosition,
useOffsetCallback ? (IArchiveOpenCallback *)openCallback_Offset : (IArchiveOpenCallback *)op.callback,
extractCallback_To_OpenCallback);
- RINOK(ReadBasicProps(archive, ai.Flags_UseGlobalOffset() ? 0 : startArcPos, result));
+ RINOK(ReadBasicProps(archive, ai.Flags_UseGlobalOffset() ? 0 : startArcPos, result))
bool isOpen = false;
+
if (result == S_FALSE)
{
if (!mode.CanReturnParser)
{
if (formatIndex < 0 && ErrorInfo.IsArc_After_NonOpen())
{
- ErrorInfo.ErrorFormatIndex = index;
+ ErrorInfo.ErrorFormatIndex = (int)index;
NonOpen_ErrorInfo = ErrorInfo;
// if archive was detected, we don't need additional open attempts
return S_FALSE;
}
continue;
}
- if (!ErrorInfo.IsArc_After_NonOpen() || !PhySizeDefined || PhySize == 0)
+ if (!ErrorInfo.IsArc_After_NonOpen() || !PhySize_Defined || PhySize == 0)
continue;
}
else
{
+ if (PhySize_Defined && PhySize == 0)
+ {
+ PRF(printf(" phySize_Defined && PhySize == 0 "));
+ // we skip that epmty archive case with unusual unexpected (PhySize == 0) from Code function.
+ continue;
+ }
isOpen = true;
- RINOK(result);
+ RINOK(result)
PRF(printf(" OK "));
}
@@ -2671,13 +2787,14 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
pi.Offset = startArcPos;
if (ai.Flags_UseGlobalOffset())
- pi.Offset = Offset;
+ pi.Offset = (UInt64)Offset;
else if (Offset != 0)
return E_FAIL;
- UInt64 arcRem = FileSize - pi.Offset;
+
+ const UInt64 arcRem = FileSize - pi.Offset;
UInt64 phySize = arcRem;
- bool phySizeDefined = PhySizeDefined;
- if (phySizeDefined)
+ const bool phySize_Defined = PhySize_Defined;
+ if (phySize_Defined)
{
if (pi.Offset + PhySize > FileSize)
{
@@ -2703,9 +2820,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
bool needScan = false;
- if (isOpen && !phySizeDefined)
+ if (isOpen && !phySize_Defined)
{
- // it's for Z format
+ // it's for Z format, or bzip2,gz,xz with phySize that was not detected
pi.LenIsUnknown = true;
needScan = true;
phySize = arcRem;
@@ -2722,7 +2839,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
/*
if (needSkipFullArc)
- if (pi.Offset == 0 && phySizeDefined && pi.Size >= fileSize)
+ if (pi.Offset == 0 && phySize_Defined && pi.Size >= fileSize)
continue;
*/
if (pi.Offset == 0 && !pi.LenIsUnknown && pi.Size >= FileSize)
@@ -2748,9 +2865,9 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
pos = pi.Offset + pi.Size;
- RINOK(ReadParseItemProps(archive, ai, pi));
+ RINOK(ReadParseItemProps(archive, ai, pi))
- if (pi.Offset < startArcPos && !mode.EachPos /* && phySizeDefined */)
+ if (pi.Offset < startArcPos && !mode.EachPos /* && phySize_Defined */)
{
/* It's for DMG format.
This code deletes all previous items that are included to current item */
@@ -2769,7 +2886,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
- if (isOpen && mode.CanReturnArc && phySizeDefined)
+ if (isOpen && mode.CanReturnArc && phySize_Defined)
{
// if (pi.Offset + pi.Size >= fileSize)
bool openCur = false;
@@ -2777,7 +2894,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
bool thereIsTail = ErrorInfo.ThereIsTail;
if (thereIsTail && mode.ZerosTailIsAllowed)
{
- RINOK(CheckZerosTail(op, arcStreamOffset + Offset + PhySize));
+ RINOK(CheckZerosTail(op, (UInt64)((Int64)arcStreamOffset + Offset + (Int64)PhySize)))
if (ErrorInfo.IgnoreTail)
thereIsTail = false;
}
@@ -2785,10 +2902,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
if (pi.Offset != 0)
{
if (!pi.IsNotArcType)
+ {
if (thereIsTail)
openCur = specFlags.CanReturnMid;
else
openCur = specFlags.CanReturnTail;
+ }
}
else
{
@@ -2796,11 +2915,11 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
openCur = true;
else
openCur = specFlags.CanReturnFrontal;
-
if (formatIndex >= -2)
openCur = true;
}
+
if (formatIndex < 0 && pi.IsSelfExe /* && mode.SkipSfxStub */)
openCur = false;
@@ -2827,7 +2946,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
{
InStream = op.stream;
Archive = archive;
- FormatIndex = index;
+ FormatIndex = (int)index;
ArcStreamOffset = arcStreamOffset;
return S_OK;
}
@@ -2841,7 +2960,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
*/
- pi.FormatIndex = index;
+ pi.FormatIndex = (int)index;
// printf("\nAdd offset = %d", (int)pi.Offset);
handlerSpec->AddItem(pi);
@@ -2896,9 +3015,12 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
return S_OK;
}
+
+
+
HRESULT CArc::OpenStream(const COpenOptions &op)
{
- RINOK(OpenStream2(op));
+ RINOK(OpenStream2(op))
// PrintNumber("op.formatIndex 3", op.formatIndex);
if (Archive)
@@ -2908,25 +3030,25 @@ HRESULT CArc::OpenStream(const COpenOptions &op)
Archive->QueryInterface(IID_IArchiveGetRawProps, (void **)&GetRawProps);
Archive->QueryInterface(IID_IArchiveGetRootProps, (void **)&GetRootProps);
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsTree, IsTree));
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsDeleted, Ask_Deleted));
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsAltStream, Ask_AltStream));
- RINOK(Archive_GetArcBoolProp(Archive, kpidIsAux, Ask_Aux));
- RINOK(Archive_GetArcBoolProp(Archive, kpidINode, Ask_INode));
- RINOK(Archive_GetArcBoolProp(Archive, kpidReadOnly, IsReadOnly));
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsTree, IsTree))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsDeleted, Ask_Deleted))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsAltStream, Ask_AltStream))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidIsAux, Ask_Aux))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidINode, Ask_INode))
+ RINOK(Archive_GetArcProp_Bool(Archive, kpidReadOnly, IsReadOnly))
const UString fileName = ExtractFileNameFromPath(Path);
UString extension;
{
int dotPos = fileName.ReverseFind_Dot();
if (dotPos >= 0)
- extension = fileName.Ptr(dotPos + 1);
+ extension = fileName.Ptr((unsigned)(dotPos + 1));
}
DefaultName.Empty();
if (FormatIndex >= 0)
{
- const CArcInfoEx &ai = op.codecs->Formats[FormatIndex];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)FormatIndex];
if (ai.Exts.Size() == 0)
DefaultName = GetDefaultName2(fileName, UString(), UString());
else
@@ -2934,7 +3056,7 @@ HRESULT CArc::OpenStream(const COpenOptions &op)
int subExtIndex = ai.FindExtension(extension);
if (subExtIndex < 0)
subExtIndex = 0;
- const CArcExtInfo &extInfo = ai.Exts[subExtIndex];
+ const CArcExtInfo &extInfo = ai.Exts[(unsigned)subExtIndex];
DefaultName = GetDefaultName2(fileName, extInfo.Ext, extInfo.AddExt);
}
}
@@ -2943,13 +3065,13 @@ HRESULT CArc::OpenStream(const COpenOptions &op)
return S_OK;
}
-#ifdef _SFX
+#ifdef Z7_SFX
#ifdef _WIN32
- static const char *k_ExeExt = ".exe";
+ #define k_ExeExt ".exe"
static const unsigned k_ExeExt_Len = 4;
#else
- static const char *k_ExeExt = "";
+ #define k_ExeExt ""
static const unsigned k_ExeExt_Len = 0;
#endif
@@ -2972,11 +3094,9 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
fileStream = fileStreamSpec;
Path = filePath;
if (!fileStreamSpec->Open(us2fs(Path)))
- {
- return GetLastError();
- }
+ return GetLastError_noZero_HRESULT();
op.stream = fileStream;
- #ifdef _SFX
+ #ifdef Z7_SFX
IgnoreSplit = true;
#endif
}
@@ -2985,7 +3105,7 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
if (callback)
{
UInt64 fileSize;
- RINOK(op.stream->Seek(0, STREAM_SEEK_END, &fileSize));
+ RINOK(InStream_GetSize_SeekToEnd(op.stream, fileSize));
RINOK(op.callback->SetTotal(NULL, &fileSize))
}
*/
@@ -2993,7 +3113,7 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
HRESULT res = OpenStream(op);
IgnoreSplit = false;
- #ifdef _SFX
+ #ifdef Z7_SFX
if (res != S_FALSE
|| !fileStreamSpec
@@ -3009,13 +3129,13 @@ HRESULT CArc::OpenStreamOrFile(COpenOptions &op)
FOR_VECTOR (i, op.codecs->Formats)
{
const CArcInfoEx &ai = op.codecs->Formats[i];
- if (ai.IsSplit())
+ if (ai.Is_Split())
continue;
UString path3 = path2;
- path3 += L'.';
+ path3.Add_Dot();
path3 += ai.GetMainExt(); // "7z" for SFX.
Path = path3;
- Path.AddAscii(".001");
+ Path += ".001";
bool isOk = op.callbackSpec->SetSecondFileInfo(us2fs(Path));
if (!isOk)
{
@@ -3058,7 +3178,7 @@ HRESULT CArchiveLink::Close()
for (unsigned i = Arcs.Size(); i != 0;)
{
i--;
- RINOK(Arcs[i].Close());
+ RINOK(Arcs[i].Close())
}
IsOpen = false;
// ErrorsText.Empty();
@@ -3191,13 +3311,13 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
UInt32 mainSubfile;
{
NCOM::CPropVariant prop;
- RINOK(arc.Archive->GetArchiveProperty(kpidMainSubfile, &prop));
+ RINOK(arc.Archive->GetArchiveProperty(kpidMainSubfile, &prop))
if (prop.vt == VT_UI4)
mainSubfile = prop.ulVal;
else
break;
UInt32 numItems;
- RINOK(arc.Archive->GetNumberOfItems(&numItems));
+ RINOK(arc.Archive->GetNumberOfItems(&numItems))
if (mainSubfile >= numItems)
break;
}
@@ -3216,16 +3336,17 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
break;
CArc arc2;
- RINOK(arc.GetItemPath(mainSubfile, arc2.Path));
+ RINOK(arc.GetItem_Path(mainSubfile, arc2.Path))
bool zerosTailIsAllowed;
- RINOK(Archive_GetItemBoolProp(arc.Archive, mainSubfile, kpidZerosTailIsAllowed, zerosTailIsAllowed));
+ RINOK(Archive_GetItemBoolProp(arc.Archive, mainSubfile, kpidZerosTailIsAllowed, zerosTailIsAllowed))
if (op.callback)
{
- CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;
- op.callback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);
+ Z7_DECL_CMyComPtr_QI_FROM(
+ IArchiveOpenSetSubArchiveName,
+ setSubArchiveName, op.callback)
if (setSubArchiveName)
setSubArchiveName->SetSubArchiveName(arc2.Path);
}
@@ -3236,7 +3357,7 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
CIntVector excl;
COpenOptions op2;
- #ifndef _SFX
+ #ifndef Z7_SFX
op2.props = op.props;
#endif
op2.codecs = op.codecs;
@@ -3259,8 +3380,8 @@ HRESULT CArchiveLink::Open(COpenOptions &op)
NonOpen_ArcPath = arc2.Path;
break;
}
- RINOK(result);
- RINOK(arc.GetItemMTime(mainSubfile, arc2.MTime, arc2.MTimeDefined));
+ RINOK(result)
+ RINOK(arc.GetItem_MTime(mainSubfile, arc2.MTime))
Arcs.Add(arc2);
}
IsOpen = !Arcs.IsEmpty();
@@ -3279,7 +3400,7 @@ HRESULT CArchiveLink::Open2(COpenOptions &op, IOpenCallbackUI *callbackUI)
if (!op.stream && !op.stdInMode)
{
NFile::NDir::GetFullPathAndSplit(us2fs(op.filePath), prefix, name);
- openCallbackSpec->Init(prefix, name);
+ RINOK(openCallbackSpec->Init2(prefix, name))
}
else
{
@@ -3294,7 +3415,7 @@ HRESULT CArchiveLink::Open2(COpenOptions &op, IOpenCallbackUI *callbackUI)
PasswordWasAsked = openCallbackSpec->PasswordWasAsked;
// Password = openCallbackSpec->Password;
- RINOK(res);
+ RINOK(res)
// VolumePaths.Add(fs2us(prefix + name));
FOR_VECTOR (i, openCallbackSpec->FileNames_WasUsed)
@@ -3309,7 +3430,7 @@ HRESULT CArchiveLink::Open2(COpenOptions &op, IOpenCallbackUI *callbackUI)
return S_OK;
}
-HRESULT CArc::ReOpen(const COpenOptions &op)
+HRESULT CArc::ReOpen(const COpenOptions &op, IArchiveOpenCallback *openCallback_Additional)
{
ErrorInfo.ClearErrors();
ErrorInfo.ErrorFormatIndex = -1;
@@ -3317,8 +3438,9 @@ HRESULT CArc::ReOpen(const COpenOptions &op)
UInt64 fileSize = 0;
if (op.stream)
{
- RINOK(op.stream->Seek(0, STREAM_SEEK_END, &fileSize));
- RINOK(op.stream->Seek(0, STREAM_SEEK_SET, NULL));
+ RINOK(InStream_SeekToBegin(op.stream))
+ RINOK(InStream_AtBegin_GetSize(op.stream, fileSize))
+ // RINOK(InStream_GetSize_SeekToBegin(op.stream, fileSize))
}
FileSize = fileSize;
@@ -3331,20 +3453,23 @@ HRESULT CArc::ReOpen(const COpenOptions &op)
CTailInStream *tailStreamSpec = new CTailInStream;
stream2 = tailStreamSpec;
tailStreamSpec->Stream = op.stream;
- tailStreamSpec->Offset = globalOffset;
+ tailStreamSpec->Offset = (UInt64)globalOffset;
tailStreamSpec->Init();
- RINOK(tailStreamSpec->SeekToStart());
+ RINOK(tailStreamSpec->SeekToStart())
}
// There are archives with embedded STUBs (like ZIP), so we must support signature scanning
// But for another archives we can use 0 here. So the code can be fixed !!!
UInt64 maxStartPosition = kMaxCheckStartPosition;
- HRESULT res = Archive->Open(stream2, &maxStartPosition, op.callback);
+ IArchiveOpenCallback *openCallback = openCallback_Additional;
+ if (!openCallback)
+ openCallback = op.callback;
+ HRESULT res = Archive->Open(stream2, &maxStartPosition, openCallback);
if (res == S_OK)
{
- RINOK(ReadBasicProps(Archive, globalOffset, res));
- ArcStreamOffset = globalOffset;
+ RINOK(ReadBasicProps(Archive, (UInt64)globalOffset, res))
+ ArcStreamOffset = (UInt64)globalOffset;
if (ArcStreamOffset != 0)
InStream = op.stream;
}
@@ -3356,7 +3481,7 @@ HRESULT CArchiveLink::Open3(COpenOptions &op, IOpenCallbackUI *callbackUI)
HRESULT res = Open2(op, callbackUI);
if (callbackUI)
{
- RINOK(callbackUI->Open_Finished());
+ RINOK(callbackUI->Open_Finished())
}
return res;
}
@@ -3376,6 +3501,8 @@ HRESULT CArchiveLink::ReOpen(COpenOptions &op)
if (Arcs.Size() == 0) // ???
return Open2(op, NULL);
+ /* if archive is multivolume (unsupported here still)
+ COpenCallbackImp object will exist after Open stage. */
COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;
CMyComPtr<IArchiveOpenCallback> openCallbackNew = openCallbackSpec;
@@ -3384,18 +3511,20 @@ HRESULT CArchiveLink::ReOpen(COpenOptions &op)
{
FString dirPrefix, fileName;
NFile::NDir::GetFullPathAndSplit(us2fs(op.filePath), dirPrefix, fileName);
- openCallbackSpec->Init(dirPrefix, fileName);
+ RINOK(openCallbackSpec->Init2(dirPrefix, fileName))
}
CInFileStream *fileStreamSpec = new CInFileStream;
CMyComPtr<IInStream> stream(fileStreamSpec);
if (!fileStreamSpec->Open(us2fs(op.filePath)))
- return GetLastError();
+ return GetLastError_noZero_HRESULT();
op.stream = stream;
CArc &arc = Arcs[0];
- HRESULT res = arc.ReOpen(op);
+ const HRESULT res = arc.ReOpen(op, openCallbackNew);
+
+ openCallbackSpec->ReOpenCallback = NULL;
PasswordWasAsked = openCallbackSpec->PasswordWasAsked;
// Password = openCallbackSpec->Password;
@@ -3404,8 +3533,9 @@ HRESULT CArchiveLink::ReOpen(COpenOptions &op)
return res;
}
-#ifndef _SFX
+#ifndef Z7_SFX
+bool ParseComplexSize(const wchar_t *s, UInt64 &result);
bool ParseComplexSize(const wchar_t *s, UInt64 &result)
{
result = 0;
@@ -3463,7 +3593,7 @@ static bool ParseTypeParams(const UString &s, COpenType &type)
return false;
}
-bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
+static bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
{
int pos2 = s.Find(L':');
@@ -3472,11 +3602,11 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
if (pos2 < 0)
{
name = s;
- pos2 = s.Len();
+ pos2 = (int)s.Len();
}
else
{
- name = s.Left(pos2);
+ name = s.Left((unsigned)pos2);
pos2++;
}
@@ -3497,6 +3627,12 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
type.CanReturnArc = false;
type.CanReturnParser = true;
}
+ else if (name.IsEqualTo_Ascii_NoCase("hash"))
+ {
+ // type.CanReturnArc = false;
+ // type.CanReturnParser = false;
+ type.IsHashType = true;
+ }
else
return false;
}
@@ -3505,17 +3641,17 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
}
- for (unsigned i = pos2; i < s.Len();)
+ for (unsigned i = (unsigned)pos2; i < s.Len();)
{
int next = s.Find(L':', i);
if (next < 0)
- next = s.Len();
- const UString name = s.Mid(i, next - i);
+ next = (int)s.Len();
+ const UString name = s.Mid(i, (unsigned)next - i);
if (name.IsEmpty())
return false;
if (!ParseTypeParams(name, type))
return false;
- i = next + 1;
+ i = (unsigned)next + 1;
}
return true;
@@ -3524,21 +3660,36 @@ bool ParseType(CCodecs &codecs, const UString &s, COpenType &type)
bool ParseOpenTypes(CCodecs &codecs, const UString &s, CObjectVector<COpenType> &types)
{
types.Clear();
+ bool isHashType = false;
for (unsigned pos = 0; pos < s.Len();)
{
int pos2 = s.Find(L'.', pos);
if (pos2 < 0)
- pos2 = s.Len();
- UString name = s.Mid(pos, pos2 - pos);
+ pos2 = (int)s.Len();
+ UString name = s.Mid(pos, (unsigned)pos2 - pos);
if (name.IsEmpty())
return false;
COpenType type;
if (!ParseType(codecs, name, type))
return false;
+ if (isHashType)
+ return false;
+ if (type.IsHashType)
+ isHashType = true;
types.Add(type);
- pos = pos2 + 1;
+ pos = (unsigned)pos2 + 1;
}
return true;
}
+/*
+bool IsHashType(const CObjectVector<COpenType> &types)
+{
+ if (types.Size() != 1)
+ return false;
+ return types[0].IsHashType;
+}
+*/
+
+
#endif