This commit is contained in:
Igor Pavlov
2023-12-22 17:17:05 +00:00
committed by Kornel
parent ec44a8a070
commit a36c48cece
954 changed files with 42199 additions and 25482 deletions

View File

@@ -1,16 +1,31 @@
/* 7zipInstall.c - 7-Zip Installer
2021-09-02 : Igor Pavlov : Public domain */
2023-04-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
#define SZ_ERROR_ABORT 100
#ifdef _MSC_VER
#include "../../7zWindows.h"
#if defined(_MSC_VER) && _MSC_VER < 1600
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
#endif
#include <windows.h>
#ifdef Z7_OLD_WIN_SDK
struct IShellView;
#define SHFOLDERAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE
SHFOLDERAPI SHGetFolderPathW(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath);
#define BIF_NEWDIALOGSTYLE 0x0040 // Use the new dialog layout with the ability to resize
typedef enum {
SHGFP_TYPE_CURRENT = 0, // current value for user, verify it exists
SHGFP_TYPE_DEFAULT = 1, // default value, may not exist
} SHGFP_TYPE;
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#include <shlobj.h>
#else
#include <ShlObj.h>
#endif
#include "../../7z.h"
#include "../../7zAlloc.h"
@@ -22,36 +37,46 @@
#include "resource.h"
#if (defined(__GNUC__) && (__GNUC__ >= 8)) || defined(__clang__)
// #pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
#if defined(__clang__) || defined(__GNUC__)
typedef void (*Z7_voidFunction)(void);
#define MY_CAST_FUNC (Z7_voidFunction)
#elif defined(_MSC_VER) && _MSC_VER > 1920
#define MY_CAST_FUNC (void *)
// #pragma warning(disable : 4191) // 'type cast': unsafe conversion from 'FARPROC' to 'void (__cdecl *)()'
#else
#define MY_CAST_FUNC
#endif
#define LLL_(quote) L##quote
#define LLL(quote) LLL_(quote)
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define wcscat lstrcatW
#define wcslen lstrlenW
#define wcslen (size_t)lstrlenW
#define wcscpy lstrcpyW
// wcsncpy() and lstrcpynW() work differently. We don't use them.
#define kInputBufSize ((size_t)1 << 18)
#define _7ZIP_CUR_VER ((MY_VER_MAJOR << 16) | MY_VER_MINOR)
#define _7ZIP_DLL_VER_COMPAT ((16 << 16) | 3)
#define Z7_7ZIP_CUR_VER ((MY_VER_MAJOR << 16) | MY_VER_MINOR)
#define Z7_7ZIP_DLL_VER_COMPAT ((16 << 16) | 3)
static LPCSTR const k_7zip = "7-Zip";
static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip";
// #define _64BIT_INSTALLER 1
// #define Z7_64BIT_INSTALLER 1
#ifdef _WIN64
#define _64BIT_INSTALLER 1
#define Z7_64BIT_INSTALLER 1
#endif
#define k_7zip_with_Ver_base L"7-Zip " LLL(MY_VERSION)
#ifdef _64BIT_INSTALLER
#ifdef Z7_64BIT_INSTALLER
// #define USE_7ZIP_32_DLL
@@ -70,7 +95,7 @@ static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip";
#endif
#endif
#define k_7zip_with_Ver k_7zip_with_Ver_base k_Postfix
#define k_7zip_with_Ver k_7zip_with_Ver_base k_Postfix
static LPCWSTR const k_7zip_with_Ver_str = k_7zip_with_Ver;
@@ -80,14 +105,14 @@ static LPCWSTR const k_7zip_Setup = k_7zip_with_Ver L" Setup";
static LPCWSTR const k_Reg_Path = L"Path";
static LPCWSTR const k_Reg_Path32 = L"Path"
#ifdef _64BIT_INSTALLER
#ifdef Z7_64BIT_INSTALLER
L"64"
#else
L"32"
#endif
;
#if defined(_64BIT_INSTALLER) && !defined(_WIN64)
#if defined(Z7_64BIT_INSTALLER) && !defined(_WIN64)
#define k_Reg_WOW_Flag KEY_WOW64_64KEY
#else
#define k_Reg_WOW_Flag 0
@@ -122,8 +147,6 @@ static WCHAR cmdError[MAX_PATH + 4];
static WCHAR path[MAX_PATH * 2 + 40];
// #define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c)))
static void CpyAscii(wchar_t *dest, const char *s)
{
@@ -196,9 +219,12 @@ static DWORD GetFileVersion(LPCWSTR s)
return 0;
}
my_GetFileVersionInfoSizeW = (Func_GetFileVersionInfoSizeW)GetProcAddress(g_version_dll_hModule, "GetFileVersionInfoSizeW");
my_GetFileVersionInfoW = (Func_GetFileVersionInfoW)GetProcAddress(g_version_dll_hModule, "GetFileVersionInfoW");
my_VerQueryValueW = (Func_VerQueryValueW)GetProcAddress(g_version_dll_hModule, "VerQueryValueW");
my_GetFileVersionInfoSizeW = (Func_GetFileVersionInfoSizeW) MY_CAST_FUNC GetProcAddress(g_version_dll_hModule,
"GetFileVersionInfoSizeW");
my_GetFileVersionInfoW = (Func_GetFileVersionInfoW) MY_CAST_FUNC GetProcAddress(g_version_dll_hModule,
"GetFileVersionInfoW");
my_VerQueryValueW = (Func_VerQueryValueW) MY_CAST_FUNC GetProcAddress(g_version_dll_hModule,
"VerQueryValueW");
if (!my_GetFileVersionInfoSizeW
|| !my_GetFileVersionInfoW
@@ -249,7 +275,7 @@ static int ReverseFind_PathSepar(const wchar_t *s)
}
}
static WRes CreateComplexDir()
static WRes CreateComplexDir(void)
{
WCHAR s[MAX_PATH + 10];
@@ -283,7 +309,7 @@ static WRes CreateComplexDir()
{
size_t len = wcslen(s);
{
int pos = ReverseFind_PathSepar(s);
const int pos = ReverseFind_PathSepar(s);
if (pos < 0)
return wres;
if ((unsigned)pos < prefixSize)
@@ -293,7 +319,7 @@ static WRes CreateComplexDir()
if (len == 1)
return 0;
s[pos] = 0;
len = pos;
len = (unsigned)pos;
}
}
@@ -305,7 +331,7 @@ static WRes CreateComplexDir()
break;
if (wres == ERROR_ALREADY_EXISTS)
{
DWORD attrib = GetFileAttributesW(s);
const DWORD attrib = GetFileAttributesW(s);
if (attrib != INVALID_FILE_ATTRIBUTES)
if ((attrib & FILE_ATTRIBUTE_DIRECTORY) == 0)
return ERROR_ALREADY_EXISTS;
@@ -319,7 +345,7 @@ static WRes CreateComplexDir()
for (;;)
{
size_t pos = wcslen(s);
const size_t pos = wcslen(s);
if (pos >= len)
return 0;
s[pos] = CHAR_PATH_SEPARATOR;
@@ -335,7 +361,7 @@ static int MyRegistry_QueryString(HKEY hKey, LPCWSTR name, LPWSTR dest)
{
DWORD cnt = MAX_PATH * sizeof(name[0]);
DWORD type = 0;
LONG res = RegQueryValueExW(hKey, name, NULL, &type, (LPBYTE)dest, (DWORD *)&cnt);
const LONG res = RegQueryValueExW(hKey, name, NULL, &type, (LPBYTE)dest, &cnt);
if (type != REG_SZ)
return False;
return res == ERROR_SUCCESS;
@@ -344,11 +370,11 @@ static int MyRegistry_QueryString(HKEY hKey, LPCWSTR name, LPWSTR dest)
static int MyRegistry_QueryString2(HKEY hKey, LPCWSTR keyName, LPCWSTR valName, LPWSTR dest)
{
HKEY key = 0;
LONG res = RegOpenKeyExW(hKey, keyName, 0, KEY_READ | k_Reg_WOW_Flag, &key);
const LONG res = RegOpenKeyExW(hKey, keyName, 0, KEY_READ | k_Reg_WOW_Flag, &key);
if (res != ERROR_SUCCESS)
return False;
{
BoolInt res2 = MyRegistry_QueryString(key, valName, dest);
const BoolInt res2 = MyRegistry_QueryString(key, valName, dest);
RegCloseKey(key);
return res2;
}
@@ -546,7 +572,7 @@ static void NormalizePrefix(WCHAR *s)
for (;; i++)
{
wchar_t c = s[i];
const wchar_t c = s[i];
if (c == 0)
break;
if (c == '/')
@@ -583,7 +609,7 @@ static LPCWSTR FindSubString(LPCWSTR s1, const char *s2)
return NULL;
for (i = 0;; i++)
{
Byte b = s2[i];
const char b = s2[i];
if (b == 0)
return s1;
if (MyWCharLower_Ascii(s1[i]) != (Byte)MyCharLower_Ascii(b))
@@ -606,7 +632,7 @@ static void Set7zipPostfix(WCHAR *s)
static int Install(void);
static void OnClose()
static void OnClose(void)
{
if (g_Install_was_Pressed && !g_Finished)
{
@@ -620,7 +646,13 @@ static void OnClose()
g_HWND = NULL;
}
static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
static
#ifdef Z7_OLD_WIN_SDK
BOOL
#else
INT_PTR
#endif
CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// UNUSED_VAR(hwnd)
UNUSED_VAR(lParam)
@@ -726,7 +758,7 @@ static LONG SetRegKey_Path2(HKEY parentKey)
return res;
}
static void SetRegKey_Path()
static void SetRegKey_Path(void)
{
SetRegKey_Path2(HKEY_CURRENT_USER);
SetRegKey_Path2(HKEY_LOCAL_MACHINE);
@@ -824,7 +856,7 @@ static void SetShellProgramsGroup(HWND hwndOwner)
static LPCWSTR const k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
static LPCWSTR const k_7zip_ShellExtension = L"7-Zip Shell Extension";
static void WriteCLSID()
static void WriteCLSID(void)
{
HKEY destKey;
LONG res;
@@ -875,12 +907,12 @@ static LPCSTR const k_ShellEx_Items[] =
, "Drive\\shellex\\DragDropHandlers"
};
static void WriteShellEx()
static void WriteShellEx(void)
{
unsigned i;
WCHAR destPath[MAX_PATH + 40];
for (i = 0; i < ARRAY_SIZE(k_ShellEx_Items); i++)
for (i = 0; i < Z7_ARRAY_SIZE(k_ShellEx_Items); i++)
{
CpyAscii(destPath, k_ShellEx_Items[i]);
CatAscii(destPath, "\\7-Zip");
@@ -964,7 +996,7 @@ static const wchar_t *GetCmdParam(const wchar_t *s)
quoteMode = !quoteMode;
continue;
}
if (pos >= ARRAY_SIZE(cmd) - 1)
if (pos >= Z7_ARRAY_SIZE(cmd) - 1)
exit(1);
cmd[pos++] = c;
}
@@ -1022,7 +1054,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
for (;;)
{
{
wchar_t c = *s;
const wchar_t c = *s;
if (c == 0)
break;
if (c == ' ')
@@ -1066,11 +1098,12 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
}
}
#if defined(_64BIT_INSTALLER) && !defined(_WIN64)
#if defined(Z7_64BIT_INSTALLER) && !defined(_WIN64)
{
BOOL isWow64 = FALSE;
Func_IsWow64Process func_IsWow64Process = (Func_IsWow64Process)
GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "IsWow64Process");
const Func_IsWow64Process func_IsWow64Process = (Func_IsWow64Process)
MY_CAST_FUNC GetProcAddress(GetModuleHandleW(L"kernel32.dll"),
"IsWow64Process");
if (func_IsWow64Process)
func_IsWow64Process(GetCurrentProcess(), &isWow64);
@@ -1089,7 +1122,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
{
HKEY key = 0;
BoolInt ok = False;
LONG res = RegOpenKeyExW(HKEY_CURRENT_USER, k_Reg_Software_7zip, 0, KEY_READ | k_Reg_WOW_Flag, &key);
const LONG res = RegOpenKeyExW(HKEY_CURRENT_USER, k_Reg_Software_7zip, 0, KEY_READ | k_Reg_WOW_Flag, &key);
if (res == ERROR_SUCCESS)
{
ok = MyRegistry_QueryString(key, k_Reg_Path32, path);
@@ -1105,7 +1138,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
CpyAscii(path, "\\Program Files\\");
#else
#ifdef _64BIT_INSTALLER
#ifdef Z7_64BIT_INSTALLER
{
DWORD ttt = GetEnvironmentVariableW(L"ProgramW6432", path, MAX_PATH);
if (ttt == 0 || ttt > MAX_PATH)
@@ -1146,7 +1179,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
return 1;
{
HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
const HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
// SendMessage(g_HWND, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
SendMessage(g_HWND, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
}
@@ -1240,7 +1273,7 @@ static int Install(void)
allocTempImp.Free = SzFreeTemp;
{
DWORD len = GetModuleFileNameW(NULL, sfxPath, MAX_PATH);
const DWORD len = GetModuleFileNameW(NULL, sfxPath, MAX_PATH);
if (len == 0 || len > MAX_PATH)
return 1;
}
@@ -1282,7 +1315,7 @@ if (res == SZ_OK)
for (;;)
{
wchar_t c = path[i++];
const wchar_t c = path[i++];
if (c == 0)
break;
if (c != ' ')
@@ -1314,7 +1347,7 @@ if (res == SZ_OK)
{
lookStream.bufSize = kInputBufSize;
lookStream.realStream = &archiveStream.vt;
LookToRead2_Init(&lookStream);
LookToRead2_INIT(&lookStream)
}
}
@@ -1368,7 +1401,7 @@ if (res == SZ_OK)
}
{
size_t len = SzArEx_GetFileNameUtf16(&db, i, NULL);
const size_t len = SzArEx_GetFileNameUtf16(&db, i, NULL);
if (len >= MAX_PATH)
{
res = SZ_ERROR_FAIL;
@@ -1464,8 +1497,8 @@ if (res == SZ_OK)
#endif
)
{
DWORD ver = GetFileVersion(path);
fileLevel = ((ver < _7ZIP_DLL_VER_COMPAT || ver > _7ZIP_CUR_VER) ? 2 : 1);
const DWORD ver = GetFileVersion(path);
fileLevel = ((ver < Z7_7ZIP_DLL_VER_COMPAT || ver > Z7_7ZIP_CUR_VER) ? 2 : 1);
tempIndex++;
continue;
}
@@ -1533,7 +1566,7 @@ if (res == SZ_OK)
#endif
{
SRes winRes2 = File_Close(&outFile);
const WRes winRes2 = File_Close(&outFile);
if (res != SZ_OK)
break;
if (winRes2 != 0)

View File

@@ -152,6 +152,10 @@ SOURCE=..\..\7zVersion.h
# End Source File
# Begin Source File
SOURCE=..\..\7zWindows.h
# End Source File
# Begin Source File
SOURCE=..\..\Bcj2.c
# End Source File
# Begin Source File
@@ -220,6 +224,10 @@ SOURCE=..\..\LzmaDec.h
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Compiler.h
# End Source File
# Begin Source File
SOURCE=.\Precomp.c
# ADD CPP /Yc"Precomp.h"
# End Source File

View File

@@ -1,11 +1,14 @@
/* Precomp.h -- StdAfx
2015-05-24 : Igor Pavlov : Public domain */
2023-03-04 : Igor Pavlov : Public domain */
#ifndef __7Z_PRECOMP_H
#define __7Z_PRECOMP_H
#ifndef ZIP7_INC_PRECOMP_H
#define ZIP7_INC_PRECOMP_H
#if defined(_MSC_VER) && _MSC_VER >= 1800
#pragma warning(disable : 4464) // relative include path contains '..'
#endif
#include "../../Compiler.h"
#include "../../7zTypes.h"
#endif

View File

@@ -1,15 +1,16 @@
PROG = 7zipInstall.exe
MY_FIXED = 1
!IFDEF _64BIT_INSTALLER
CFLAGS = $(CFLAGS) -D_64BIT_INSTALLER
!IFDEF Z7_64BIT_INSTALLER
CFLAGS = $(CFLAGS) -DZ7_64BIT_INSTALLER
!ENDIF
CFLAGS = $(CFLAGS) -D_LZMA_SIZE_OPT
CFLAGS = $(CFLAGS) \
-D_7Z_NO_METHOD_LZMA2 \
-D_7Z_NO_METHODS_FILTERS
-DZ7_LZMA_SIZE_OPT \
-DZ7_NO_METHOD_LZMA2 \
-DZ7_NO_METHODS_FILTERS \
-DZ7_USE_NATIVE_BRANCH_FILTER \
-DZ7_EXTRACT_ONLY \
MAIN_OBJS = \
$O\7zipInstall.obj \
@@ -25,6 +26,7 @@ C_OBJS = \
$O\7zDec.obj \
$O\7zStream.obj \
$O\Bcj2.obj \
$O\Bra.obj \
$O\CpuArch.obj \
$O\DllSecur.obj \
$O\LzmaDec.obj \