Update to 7-Zip Version 21.02

This commit is contained in:
Tino Reichardt
2021-05-13 16:39:14 +02:00
parent 3724ecfedc
commit 48fa49f76c
620 changed files with 35032 additions and 10925 deletions

View File

@@ -39,6 +39,8 @@ EXPORT_CODECS
#include "../../../Common/StringToInt.h"
#include "../../../Common/StringConvert.h"
#include "../../../Windows/ErrorMsg.h"
#include "../../../Windows/FileIO.h"
#include "../../../Windows/PropVariant.h"
#include "LoadCodecs.h"
@@ -82,11 +84,11 @@ using namespace NFile;
static CFSTR const kMainDll =
// #ifdef _WIN32
#ifdef _WIN32
FTEXT("7z.dll");
// #else
// FTEXT("7z.so");
// #endif
#else
FTEXT("7z.so");
#endif
#ifdef _WIN32
@@ -110,7 +112,7 @@ static bool ReadPathFromRegistry(HKEY baseKey, LPCWSTR value, FString &path)
{
path = us2fs(pathU);
NName::NormalizeDirPathPrefix(path);
return NFind::DoesFileExist(path + kMainDll);
return NFind::DoesFileExist_Raw(path + kMainDll);
}
}
return false;
@@ -163,7 +165,7 @@ int CArcInfoEx::FindExtension(const UString &ext) const
{
FOR_VECTOR (i, Exts)
if (ext.IsEqualTo_NoCase(Exts[i].Ext))
return i;
return (int)i;
return -1;
}
@@ -206,15 +208,18 @@ static bool ParseSignatures(const Byte *data, unsigned size, CObjectVector<CByte
#endif // _SFX
// #include <stdio.h>
#ifdef EXTERNAL_CODECS
static FString GetBaseFolderPrefixFromRegistry()
{
FString moduleFolderPrefix = NDLL::GetModuleDirPrefix();
#ifdef _WIN32
if (!NFind::DoesFileExist(moduleFolderPrefix + kMainDll) &&
!NFind::DoesDirExist(moduleFolderPrefix + kCodecsFolderName) &&
!NFind::DoesDirExist(moduleFolderPrefix + kFormatsFolderName))
if ( !NFind::DoesFileOrDirExist(moduleFolderPrefix + kMainDll)
&& !NFind::DoesFileOrDirExist(moduleFolderPrefix + kCodecsFolderName)
&& !NFind::DoesFileOrDirExist(moduleFolderPrefix + kFormatsFolderName))
{
FString path;
if (ReadPathFromRegistry(HKEY_CURRENT_USER, kProgramPath2Value, path)) return path;
@@ -223,6 +228,8 @@ static FString GetBaseFolderPrefixFromRegistry()
if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, kProgramPathValue, path)) return path;
}
#endif
// printf("\nmoduleFolderPrefix = %s\n", (const char *)GetAnsiString(moduleFolderPrefix));
return moduleFolderPrefix;
}
@@ -238,25 +245,29 @@ static HRESULT GetCoderClass(Func_GetMethodProperty getMethodProperty, UInt32 in
if (::SysStringByteLen(prop.bstrVal) != sizeof(GUID))
return E_FAIL;
isAssigned = true;
clsId = *(const GUID *)prop.bstrVal;
clsId = *(const GUID *)(const void *)prop.bstrVal;
}
else if (prop.vt != VT_EMPTY)
return E_FAIL;
return S_OK;
}
#define MY_GET_FUNC(dest, type, func) *(void **)(&dest) = (func);
// #define MY_GET_FUNC(dest, type, func) dest = (type)(func);
HRESULT CCodecs::LoadCodecs()
{
CCodecLib &lib = Libs.Back();
lib.CreateDecoder = (Func_CreateDecoder)lib.Lib.GetProc("CreateDecoder");
lib.CreateEncoder = (Func_CreateEncoder)lib.Lib.GetProc("CreateEncoder");
lib.GetMethodProperty = (Func_GetMethodProperty)lib.Lib.GetProc("GetMethodProperty");
MY_GET_FUNC (lib.CreateDecoder, Func_CreateDecoder, lib.Lib.GetProc("CreateDecoder"));
MY_GET_FUNC (lib.CreateEncoder, Func_CreateEncoder, lib.Lib.GetProc("CreateEncoder"));
MY_GET_FUNC (lib.GetMethodProperty, Func_GetMethodProperty, lib.Lib.GetProc("GetMethodProperty"));
if (lib.GetMethodProperty)
{
UInt32 numMethods = 1;
Func_GetNumberOfMethods getNumberOfMethods = (Func_GetNumberOfMethods)lib.Lib.GetProc("GetNumberOfMethods");
Func_GetNumberOfMethods getNumberOfMethods;
MY_GET_FUNC (getNumberOfMethods, Func_GetNumberOfMethods, lib.Lib.GetProc("GetNumberOfMethods"));
if (getNumberOfMethods)
{
RINOK(getNumberOfMethods(&numMethods));
@@ -272,7 +283,8 @@ HRESULT CCodecs::LoadCodecs()
}
}
Func_GetHashers getHashers = (Func_GetHashers)lib.Lib.GetProc("GetHashers");
Func_GetHashers getHashers;
MY_GET_FUNC (getHashers, Func_GetHashers, lib.Lib.GetProc("GetHashers"));
if (getHashers)
{
RINOK(getHashers(&lib.ComHashers));
@@ -381,14 +393,17 @@ HRESULT CCodecs::LoadFormats()
const NDLL::CLibrary &lib = Libs.Back().Lib;
Func_GetHandlerProperty getProp = NULL;
Func_GetHandlerProperty2 getProp2 = (Func_GetHandlerProperty2)lib.GetProc("GetHandlerProperty2");
Func_GetIsArc getIsArc = (Func_GetIsArc)lib.GetProc("GetIsArc");
Func_GetHandlerProperty2 getProp2;
MY_GET_FUNC (getProp2, Func_GetHandlerProperty2, lib.GetProc("GetHandlerProperty2"));
Func_GetIsArc getIsArc;
MY_GET_FUNC (getIsArc, Func_GetIsArc, lib.GetProc("GetIsArc"));
UInt32 numFormats = 1;
if (getProp2)
{
Func_GetNumberOfFormats getNumberOfFormats = (Func_GetNumberOfFormats)lib.GetProc("GetNumberOfFormats");
Func_GetNumberOfFormats getNumberOfFormats;
MY_GET_FUNC (getNumberOfFormats, Func_GetNumberOfFormats, lib.GetProc("GetNumberOfFormats"));
if (getNumberOfFormats)
{
RINOK(getNumberOfFormats(&numFormats));
@@ -396,7 +411,7 @@ HRESULT CCodecs::LoadFormats()
}
else
{
getProp = (Func_GetHandlerProperty)lib.GetProc("GetHandlerProperty");
MY_GET_FUNC (getProp, Func_GetHandlerProperty, lib.GetProc("GetHandlerProperty"));
if (!getProp)
return S_OK;
}
@@ -404,7 +419,7 @@ HRESULT CCodecs::LoadFormats()
for (UInt32 i = 0; i < numFormats; i++)
{
CArcInfoEx item;
item.LibIndex = Libs.Size() - 1;
item.LibIndex = (int)(Libs.Size() - 1);
item.FormatIndex = i;
RINOK(GetProp_String(getProp, getProp2, i, NArchive::NHandlerPropID::kName, item.Name));
@@ -417,7 +432,7 @@ HRESULT CCodecs::LoadFormats()
continue;
if (::SysStringByteLen(prop.bstrVal) != sizeof(GUID))
return E_FAIL;
item.ClassID = *(const GUID *)prop.bstrVal;
item.ClassID = *(const GUID *)(const void *)prop.bstrVal;
prop.Clear();
}
@@ -473,23 +488,53 @@ extern "C"
}
#endif
void CCodecs::AddLastError(const FString &path)
{
HRESULT res = GetLastError_noZero_HRESULT();
CCodecError &error = Errors.AddNew();
error.Path = path;
error.ErrorCode = res;
}
HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll, bool *loadedOK)
{
if (loadedOK)
*loadedOK = false;
// needCheckDll = 1;
#ifdef _WIN32
if (needCheckDll)
{
NDLL::CLibrary lib;
if (!lib.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))
{
/* if is not win32
// %1 is not a valid Win32 application.
// #define ERROR_BAD_EXE_FORMAT 193L
*/
// return GetLastError_noZero_HRESULT();
DWORD lastError = GetLastError();
if (lastError != ERROR_BAD_EXE_FORMAT)
{
CCodecError &error = Errors.AddNew();
error.Path = dllPath;
error.Message = "cannot load file as datafile library";
error.ErrorCode = HRESULT_FROM_WIN32(lastError);
}
return S_OK;
}
}
#else
UNUSED_VAR(needCheckDll)
#endif
Libs.AddNew();
CCodecLib &lib = Libs.Back();
lib.Path = dllPath;
bool used = false;
HRESULT res = S_OK;
// HRESULT res = S_OK;
if (lib.Lib.Load(dllPath))
{
@@ -499,10 +544,28 @@ HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll, bool *loaded
lib.LoadIcons();
#endif
/*
{
Func_LibStartup _LibStartup;
MY_GET_FUNC (_LibStartup, Func_LibStartup, lib.Lib.GetProc("LibStartup"));
if (_LibStartup)
{
HRESULT res = _LibStartup();
if (res != 0)
{
CCodecError &error = Errors.AddNew();
error.Path = dllPath;
error.ErrorCode = res;
}
}
}
*/
#ifdef _7ZIP_LARGE_PAGES
if (g_LargePageSize != 0)
{
Func_SetLargePageMode setLargePageMode = (Func_SetLargePageMode)lib.Lib.GetProc("SetLargePageMode");
Func_SetLargePageMode setLargePageMode;
MY_GET_FUNC (setLargePageMode, Func_SetLargePageMode, lib.Lib.GetProc("SetLargePageMode"));
if (setLargePageMode)
setLargePageMode();
}
@@ -510,16 +573,18 @@ HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll, bool *loaded
if (CaseSensitiveChange)
{
Func_SetCaseSensitive setCaseSensitive = (Func_SetCaseSensitive)lib.Lib.GetProc("SetCaseSensitive");
Func_SetCaseSensitive setCaseSensitive;
MY_GET_FUNC (setCaseSensitive, Func_SetCaseSensitive, lib.Lib.GetProc("SetCaseSensitive"));
if (setCaseSensitive)
setCaseSensitive(CaseSensitive ? 1 : 0);
}
lib.CreateObject = (Func_CreateObject)lib.Lib.GetProc("CreateObject");
MY_GET_FUNC (lib.CreateObject, Func_CreateObject, lib.Lib.GetProc("CreateObject"));
{
unsigned startSize = Codecs.Size() + Hashers.Size();
res = LoadCodecs();
used = (startSize != Codecs.Size() + Hashers.Size());
HRESULT res = LoadCodecs();
if (startSize != Codecs.Size() + Hashers.Size())
used = true;
if (res == S_OK && lib.CreateObject)
{
startSize = Formats.Size();
@@ -527,22 +592,61 @@ HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll, bool *loaded
if (startSize != Formats.Size())
used = true;
}
if (res != S_OK)
{
CCodecError &error = Errors.AddNew();
error.Path = dllPath;
error.ErrorCode = res;
}
}
// plugins can use non-7-zip dlls, so we silently ignore non7zip DLLs
/*
if (!used)
{
CCodecError &error = Errors.AddNew();
error.Path = dllPath;
error.Message = "no 7-Zip code";
}
*/
}
else
{
AddLastError(dllPath);
}
if (!used)
Libs.DeleteBack();
return res;
return S_OK;
}
HRESULT CCodecs::LoadDllsFromFolder(const FString &folderPrefix)
HRESULT CCodecs::LoadDllsFromFolder(const FString &folderPath)
{
if (!NFile::NFind::DoesDirExist_FollowLink(folderPath))
// if (!NFile::NFind::DoesDirExist(folderPath))
{
// AddLastError(folderPath);
return S_OK;
}
FString folderPrefix = folderPath;
folderPrefix.Add_PathSepar();
NFile::NFind::CEnumerator enumerator;
enumerator.SetDirPrefix(folderPrefix);
NFile::NFind::CFileInfo fi;
while (enumerator.Next(fi))
NFile::NFind::CDirEntry fi;
for (;;)
{
bool found;
if (!enumerator.Next(fi, found))
{
// it can be wrong Symbolic link to folder here
AddLastError(folderPath);
break;
// return GetLastError_noZero_HRESULT();
}
if (!found)
break;
if (fi.IsDir())
continue;
RINOK(LoadDll(folderPrefix + fi.Name, true));
@@ -585,6 +689,7 @@ HRESULT CCodecs::Load()
Formats.Clear();
#ifdef EXTERNAL_CODECS
Errors.Clear();
MainDll_ErrorPath.Empty();
Codecs.Clear();
Hashers.Clear();
@@ -627,6 +732,8 @@ HRESULT CCodecs::Load()
Formats.Add(item);
}
// printf("\nLoad codecs \n");
#ifdef EXTERNAL_CODECS
const FString baseFolder = GetBaseFolderPrefixFromRegistry();
{
@@ -635,8 +742,8 @@ HRESULT CCodecs::Load()
if (!loadedOK)
MainDll_ErrorPath = kMainDll;
}
RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName FSTRING_PATH_SEPARATOR));
RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName FSTRING_PATH_SEPARATOR));
RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName));
RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName));
NeedSetLibCodecs = true;
@@ -659,7 +766,7 @@ HRESULT CCodecs::Load()
FOR_VECTOR(i, Libs)
{
CCodecLib &lib = Libs[i];
lib.SetCodecs = (Func_SetCodecs)lib.Lib.GetProc("SetCodecs");
MY_GET_FUNC (lib.SetCodecs, Func_SetCodecs, lib.Lib.GetProc("SetCodecs"));
if (lib.SetCodecs)
{
RINOK(lib.SetCodecs(this));
@@ -679,7 +786,7 @@ int CCodecs::FindFormatForArchiveName(const UString &arcPath) const
int dotPos = arcPath.ReverseFind_Dot();
if (dotPos <= arcPath.ReverseFind_PathSepar())
return -1;
const UString ext = arcPath.Ptr(dotPos + 1);
const UString ext = arcPath.Ptr((unsigned)(dotPos + 1));
if (ext.IsEmpty())
return -1;
if (ext.IsEqualTo_Ascii_NoCase("exe"))
@@ -692,7 +799,7 @@ int CCodecs::FindFormatForArchiveName(const UString &arcPath) const
continue;
*/
if (arc.FindExtension(ext) >= 0)
return i;
return (int)i;
}
return -1;
}
@@ -703,7 +810,7 @@ int CCodecs::FindFormatForExtension(const UString &ext) const
return -1;
FOR_VECTOR (i, Formats)
if (Formats[i].FindExtension(ext) >= 0)
return i;
return (int)i;
return -1;
}
@@ -711,7 +818,7 @@ int CCodecs::FindFormatForArchiveType(const UString &arcType) const
{
FOR_VECTOR (i, Formats)
if (Formats[i].Name.IsEqualTo_NoCase(arcType))
return i;
return (int)i;
return -1;
}
@@ -722,8 +829,8 @@ bool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &forma
{
int pos2 = arcType.Find(L'.', pos);
if (pos2 < 0)
pos2 = arcType.Len();
const UString name = arcType.Mid(pos, pos2 - pos);
pos2 = (int)arcType.Len();
const UString name = arcType.Mid(pos, (unsigned)pos2 - pos);
if (name.IsEmpty())
return false;
int index = FindFormatForArchiveType(name);
@@ -733,7 +840,7 @@ bool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &forma
return false;
}
formatIndices.Add(index);
pos = pos2 + 1;
pos = (unsigned)pos2 + 1;
}
return true;
}
@@ -756,19 +863,19 @@ void CCodecIcons::LoadIcons(HMODULE m)
CIconPair iconPair;
iconPair.IconIndex = -1;
if (pos < 0)
pos = s.Len();
pos = (int)s.Len();
else
{
UString num = s.Ptr(pos + 1);
const UString num = s.Ptr((unsigned)pos + 1);
if (!num.IsEmpty())
{
const wchar_t *end;
iconPair.IconIndex = ConvertStringToUInt32(num, &end);
iconPair.IconIndex = (int)ConvertStringToUInt32(num, &end);
if (*end != 0)
continue;
}
}
iconPair.Ext = s.Left(pos);
iconPair.Ext = s.Left((unsigned)pos);
IconPairs.Add(iconPair);
}
}
@@ -946,7 +1053,7 @@ int CCodecs::GetCodec_LibIndex(UInt32 index) const
#ifdef EXTERNAL_CODECS
const CDllCodecInfo &ci = Codecs[index - NUM_EXPORT_CODECS];
return ci.LibIndex;
return (int)ci.LibIndex;
#else
return -1;
#endif
@@ -961,7 +1068,7 @@ int CCodecs::GetHasherLibIndex(UInt32 index)
#ifdef EXTERNAL_CODECS
const CDllHasherInfo &ci = Hashers[index - NUM_EXPORT_HASHERS];
return ci.LibIndex;
return (int)ci.LibIndex;
#else
return -1;
#endif
@@ -1014,7 +1121,8 @@ bool CCodecs::GetCodec_EncoderIsAssigned(UInt32 index) const
UInt32 CCodecs::GetCodec_NumStreams(UInt32 index)
{
NCOM::CPropVariant prop;
RINOK(GetProperty(index, NMethodPropID::kPackStreams, &prop));
if (GetProperty(index, NMethodPropID::kPackStreams, &prop) != S_OK)
return 0;
if (prop.vt == VT_UI4)
return (UInt32)prop.ulVal;
if (prop.vt == VT_EMPTY)
@@ -1065,10 +1173,33 @@ AString CCodecs::GetHasherName(UInt32 index)
UInt32 CCodecs::GetHasherDigestSize(UInt32 index)
{
NCOM::CPropVariant prop;
RINOK(GetHasherProp(index, NMethodPropID::kDigestSize, &prop));
if (GetHasherProp(index, NMethodPropID::kDigestSize, &prop) != S_OK)
return 0;
if (prop.vt != VT_UI4)
return 0;
return prop.ulVal;
}
void CCodecs::GetCodecsErrorMessage(UString &s)
{
s.Empty();
FOR_VECTOR (i, Errors)
{
const CCodecError &ce = Errors[i];
s += "Codec Load Error: ";
s += fs2us(ce.Path);
if (ce.ErrorCode != 0)
{
s += " : ";
s += NWindows::NError::MyFormatMessage(ce.ErrorCode);
}
if (!ce.Message.IsEmpty())
{
s += " : ";
s += ce.Message;
}
s.Add_LF();
}
}
#endif // EXTERNAL_CODECS