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

@@ -1,5 +1,5 @@
/* 7zMain.c - Test application for 7z Decoder
2019-02-02 : Igor Pavlov : Public domain */
2021-04-29 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -20,6 +20,13 @@
#ifdef _WIN32
#include <direct.h>
#else
#include <stdlib.h>
#include <time.h>
#ifdef __GNUC__
#include <sys/time.h>
#endif
#include <fcntl.h>
// #include <utime.h>
#include <sys/stat.h>
#include <errno.h>
#endif
@@ -108,7 +115,7 @@ static Byte *Utf16_To_Utf8(Byte *dest, const UInt16 *src, const UInt16 *srcLim)
if (val < 0x80)
{
*dest++ = (char)val;
*dest++ = (Byte)val;
continue;
}
@@ -162,21 +169,21 @@ static SRes Utf16_To_Char(CBuf *buf, const UInt16 *s
)
{
unsigned len = 0;
for (len = 0; s[len] != 0; len++);
for (len = 0; s[len] != 0; len++) {}
#ifndef _USE_UTF8
{
unsigned size = len * 3 + 100;
const unsigned size = len * 3 + 100;
if (!Buf_EnsureSize(buf, size))
return SZ_ERROR_MEM;
{
buf->data[0] = 0;
if (len != 0)
{
char defaultChar = '_';
const char defaultChar = '_';
BOOL defUsed;
unsigned numChars = 0;
numChars = WideCharToMultiByte(codePage, 0, (LPCWSTR)s, len, (char *)buf->data, size, &defaultChar, &defUsed);
const unsigned numChars = (unsigned)WideCharToMultiByte(
codePage, 0, (LPCWSTR)s, (int)len, (char *)buf->data, (int)size, &defaultChar, &defUsed);
if (numChars == 0 || numChars >= size)
return SZ_ERROR_FAIL;
buf->data[numChars] = 0;
@@ -192,8 +199,8 @@ static SRes Utf16_To_Char(CBuf *buf, const UInt16 *s
#ifdef _WIN32
#ifndef USE_WINDOWS_FILE
static UINT g_FileCodePage = CP_ACP;
#define MY_FILE_CODE_PAGE_PARAM ,g_FileCodePage
#endif
#define MY_FILE_CODE_PAGE_PARAM ,g_FileCodePage
#else
#define MY_FILE_CODE_PAGE_PARAM
#endif
@@ -300,17 +307,142 @@ static void UIntToStr_2(char *s, unsigned value)
s[1] = (char)('0' + (value % 10));
}
#define PERIOD_4 (4 * 365 + 1)
#define PERIOD_100 (PERIOD_4 * 25 - 1)
#define PERIOD_400 (PERIOD_100 * 4 + 1)
static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s)
#ifndef _WIN32
// MS uses long for BOOL, but long is 32-bit in MS. So we use int.
// typedef long BOOL;
typedef int BOOL;
typedef struct _FILETIME
{
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
static LONG TIME_GetBias()
{
time_t utc = time(NULL);
struct tm *ptm = localtime(&utc);
int localdaylight = ptm->tm_isdst; /* daylight for local timezone */
ptm = gmtime(&utc);
ptm->tm_isdst = localdaylight; /* use local daylight, not that of Greenwich */
LONG bias = (int)(mktime(ptm)-utc);
return bias;
}
#define TICKS_PER_SEC 10000000
#define GET_TIME_64(pft) ((pft)->dwLowDateTime | ((UInt64)(pft)->dwHighDateTime << 32))
#define SET_FILETIME(ft, v64) \
(ft)->dwLowDateTime = (DWORD)v64; \
(ft)->dwHighDateTime = (DWORD)(v64 >> 32);
#define WINAPI
#define TRUE 1
static BOOL WINAPI FileTimeToLocalFileTime(const FILETIME *fileTime, FILETIME *localFileTime)
{
UInt64 v = GET_TIME_64(fileTime);
v = (UInt64)((Int64)v - (Int64)TIME_GetBias() * TICKS_PER_SEC);
SET_FILETIME(localFileTime, v);
return TRUE;
}
static const UInt32 kNumTimeQuantumsInSecond = 10000000;
static const UInt32 kFileTimeStartYear = 1601;
static const UInt32 kUnixTimeStartYear = 1970;
static const UInt64 kUnixTimeOffset =
(UInt64)60 * 60 * 24 * (89 + 365 * (kUnixTimeStartYear - kFileTimeStartYear));
static Int64 Time_FileTimeToUnixTime64(const FILETIME *ft)
{
UInt64 winTime = GET_TIME_64(ft);
return (Int64)(winTime / kNumTimeQuantumsInSecond) - (Int64)kUnixTimeOffset;
}
#if defined(_AIX)
#define MY_ST_TIMESPEC st_timespec
#else
#define MY_ST_TIMESPEC timespec
#endif
static void FILETIME_To_timespec(const FILETIME *ft, struct MY_ST_TIMESPEC *ts)
{
if (ft)
{
const Int64 sec = Time_FileTimeToUnixTime64(ft);
// time_t is long
const time_t sec2 = (time_t)sec;
if (sec2 == sec)
{
ts->tv_sec = sec2;
UInt64 winTime = GET_TIME_64(ft);
ts->tv_nsec = (long)((winTime % 10000000) * 100);;
return;
}
}
// else
{
ts->tv_sec = 0;
// ts.tv_nsec = UTIME_NOW; // set to the current time
ts->tv_nsec = UTIME_OMIT; // keep old timesptamp
}
}
static WRes Set_File_FILETIME(const UInt16 *name, const FILETIME *mTime)
{
struct timespec times[2];
const int flags = 0; // follow link
// = AT_SYMLINK_NOFOLLOW; // don't follow link
CBuf buf;
int res;
Buf_Init(&buf);
RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM));
FILETIME_To_timespec(NULL, &times[0]);
FILETIME_To_timespec(mTime, &times[1]);
res = utimensat(AT_FDCWD, (const char *)buf.data, times, flags);
Buf_Free(&buf, &g_Alloc);
if (res == 0)
return 0;
return errno;
}
#endif
static void NtfsFileTime_to_FILETIME(const CNtfsFileTime *t, FILETIME *ft)
{
ft->dwLowDateTime = (DWORD)(t->Low);
ft->dwHighDateTime = (DWORD)(t->High);
}
static void ConvertFileTimeToString(const CNtfsFileTime *nTime, char *s)
{
unsigned year, mon, hour, min, sec;
Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
unsigned t;
UInt32 v;
UInt64 v64 = nt->Low | ((UInt64)nt->High << 32);
// UInt64 v64 = nt->Low | ((UInt64)nt->High << 32);
UInt64 v64;
{
FILETIME fileTime, locTime;
NtfsFileTime_to_FILETIME(nTime, &fileTime);
if (!FileTimeToLocalFileTime(&fileTime, &locTime))
{
locTime.dwHighDateTime =
locTime.dwLowDateTime = 0;
}
v64 = locTime.dwLowDateTime | ((UInt64)locTime.dwHighDateTime << 32);
}
v64 /= 10000000;
sec = (unsigned)(v64 % 60); v64 /= 60;
min = (unsigned)(v64 % 60); v64 /= 60;
@@ -354,6 +486,43 @@ static void PrintError(char *s)
PrintLF();
}
static void PrintError_WRes(const char *message, WRes wres)
{
Print("\nERROR: ");
Print(message);
PrintLF();
{
char s[32];
UIntToStr(s, (unsigned)wres, 1);
Print("System error code: ");
Print(s);
}
// sprintf(buffer + strlen(buffer), "\nSystem error code: %d", (unsigned)wres);
#ifdef _WIN32
{
char *s = NULL;
if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, wres, 0, (LPSTR) &s, 0, NULL) != 0 && s)
{
Print(" : ");
Print(s);
LocalFree(s);
}
}
#else
{
const char *s = strerror(wres);
if (s)
{
Print(" : ");
Print(s);
}
}
#endif
PrintLF();
}
static void GetAttribString(UInt32 wa, BoolInt isDir, char *s)
{
#ifdef USE_WINDOWS_FILE
@@ -413,17 +582,22 @@ int MY_CDECL main(int numargs, char *args[])
allocImp = g_Alloc;
allocTempImp = g_Alloc;
#ifdef UNDER_CE
if (InFile_OpenW(&archiveStream.file, L"\test.7z"))
#else
if (InFile_Open(&archiveStream.file, args[2]))
#endif
{
PrintError("can not open input file");
return 1;
WRes wres =
#ifdef UNDER_CE
InFile_OpenW(&archiveStream.file, L"\test.7z"); // change it
#else
InFile_Open(&archiveStream.file, args[2]);
#endif
if (wres != 0)
{
PrintError_WRes("cannot open input file", wres);
return 1;
}
}
FileInStream_CreateVTable(&archiveStream);
archiveStream.wres = 0;
LookToRead2_CreateVTable(&lookStream, False);
lookStream.buf = NULL;
@@ -483,7 +657,7 @@ int MY_CDECL main(int numargs, char *args[])
size_t outSizeProcessed = 0;
// const CSzFileItem *f = db.Files + i;
size_t len;
unsigned isDir = SzArEx_IsDir(&db, i);
const BoolInt isDir = SzArEx_IsDir(&db, i);
if (listCommand == 0 && isDir && !fullPaths)
continue;
len = SzArEx_GetFileNameUtf16(&db, i, NULL);
@@ -546,8 +720,8 @@ int MY_CDECL main(int numargs, char *args[])
}
Print(testCommand ?
"Testing ":
"Extracting ");
"T ":
"- ");
res = PrintString(temp);
if (res != SZ_OK)
break;
@@ -591,27 +765,37 @@ int MY_CDECL main(int numargs, char *args[])
PrintLF();
continue;
}
else if (OutFile_OpenUtf16(&outFile, destPath))
else
{
PrintError("can not open output file");
res = SZ_ERROR_FAIL;
break;
WRes wres = OutFile_OpenUtf16(&outFile, destPath);
if (wres != 0)
{
PrintError_WRes("cannot open output file", wres);
res = SZ_ERROR_FAIL;
break;
}
}
processedSize = outSizeProcessed;
if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed)
{
PrintError("can not write output file");
res = SZ_ERROR_FAIL;
break;
WRes wres = File_Write(&outFile, outBuffer + offset, &processedSize);
if (wres != 0 || processedSize != outSizeProcessed)
{
PrintError_WRes("cannot write output file", wres);
res = SZ_ERROR_FAIL;
break;
}
}
#ifdef USE_WINDOWS_FILE
{
FILETIME mtime, ctime;
FILETIME mtime;
FILETIME *mtimePtr = NULL;
#ifdef USE_WINDOWS_FILE
FILETIME ctime;
FILETIME *ctimePtr = NULL;
#endif
if (SzBitWithVals_Check(&db.MTime, i))
{
@@ -620,6 +804,8 @@ int MY_CDECL main(int numargs, char *args[])
mtime.dwHighDateTime = (DWORD)(t->High);
mtimePtr = &mtime;
}
#ifdef USE_WINDOWS_FILE
if (SzBitWithVals_Check(&db.CTime, i))
{
const CNtfsFileTime *t = &db.CTime.Vals[i];
@@ -627,16 +813,29 @@ int MY_CDECL main(int numargs, char *args[])
ctime.dwHighDateTime = (DWORD)(t->High);
ctimePtr = &ctime;
}
if (mtimePtr || ctimePtr)
SetFileTime(outFile.handle, ctimePtr, NULL, mtimePtr);
}
#endif
#endif
if (File_Close(&outFile))
{
PrintError("can not close output file");
res = SZ_ERROR_FAIL;
break;
{
WRes wres = File_Close(&outFile);
if (wres != 0)
{
PrintError_WRes("cannot close output file", wres);
res = SZ_ERROR_FAIL;
break;
}
}
#ifndef USE_WINDOWS_FILE
#ifdef _WIN32
mtimePtr = mtimePtr;
#else
if (mtimePtr)
Set_File_FILETIME(destPath, mtimePtr);
#endif
#endif
}
#ifdef USE_WINDOWS_FILE
@@ -672,13 +871,15 @@ int MY_CDECL main(int numargs, char *args[])
if (res == SZ_ERROR_UNSUPPORTED)
PrintError("decoder doesn't support this archive");
else if (res == SZ_ERROR_MEM)
PrintError("can not allocate memory");
PrintError("cannot allocate memory");
else if (res == SZ_ERROR_CRC)
PrintError("CRC error");
else if (res == SZ_ERROR_READ /* || archiveStream.Res != 0 */)
PrintError_WRes("Read Error", archiveStream.wres);
else
{
char s[32];
UInt64ToStr(res, s, 0);
UInt64ToStr((unsigned)res, s, 0);
PrintError(s);
}

View File

@@ -1,75 +1,34 @@
PROG = 7zDec
CXX = gcc
LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall
PROG = 7zdec
OBJS = 7zMain.o 7zAlloc.o 7zArcIn.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zCrcOpt.o 7zDec.o CpuArch.o Delta.o LzmaDec.o Lzma2Dec.o Bra.o Bra86.o BraIA64.o Bcj2.o Ppmd7.o Ppmd7Dec.o 7zFile.o 7zStream.o
LOCAL_FLAGS = -D_7ZIP_PPMD_SUPPPORT
all: $(PROG)
include ../../../CPP/7zip/LzmaDec_gcc.mak
$(PROG): $(OBJS)
$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)
7zMain.o: 7zMain.c
$(CXX) $(CFLAGS) 7zMain.c
OBJS = \
$(LZMA_DEC_OPT_OBJS) \
$O/Bcj2.o \
$O/Bra.o \
$O/Bra86.o \
$O/BraIA64.o \
$O/CpuArch.o \
$O/Delta.o \
$O/Lzma2Dec.o \
$O/LzmaDec.o \
$O/Ppmd7.o \
$O/Ppmd7Dec.o \
$O/7zCrc.o \
$O/7zCrcOpt.o \
$O/Sha256.o \
$O/Sha256Opt.o \
$O/7zAlloc.o \
$O/7zArcIn.o \
$O/7zBuf.o \
$O/7zBuf2.o \
$O/7zDec.o \
$O/7zMain.o \
$O/7zFile.o \
$O/7zStream.o \
7zAlloc.o: ../../7zAlloc.c
$(CXX) $(CFLAGS) ../../7zAlloc.c
7zArcIn.o: ../../7zArcIn.c
$(CXX) $(CFLAGS) ../../7zArcIn.c
7zBuf.o: ../../7zBuf.c
$(CXX) $(CFLAGS) ../../7zBuf.c
7zBuf2.o: ../../7zBuf2.c
$(CXX) $(CFLAGS) ../../7zBuf2.c
7zCrc.o: ../../7zCrc.c
$(CXX) $(CFLAGS) ../../7zCrc.c
7zCrcOpt.o: ../../7zCrc.c
$(CXX) $(CFLAGS) ../../7zCrcOpt.c
7zDec.o: ../../7zDec.c
$(CXX) $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT ../../7zDec.c
CpuArch.o: ../../CpuArch.c
$(CXX) $(CFLAGS) ../../CpuArch.c
Delta.o: ../../Delta.c
$(CXX) $(CFLAGS) ../../Delta.c
LzmaDec.o: ../../LzmaDec.c
$(CXX) $(CFLAGS) ../../LzmaDec.c
Lzma2Dec.o: ../../Lzma2Dec.c
$(CXX) $(CFLAGS) ../../Lzma2Dec.c
Bra.o: ../../Bra.c
$(CXX) $(CFLAGS) ../../Bra.c
Bra86.o: ../../Bra86.c
$(CXX) $(CFLAGS) ../../Bra86.c
BraIA64.o: ../../BraIA64.c
$(CXX) $(CFLAGS) ../../BraIA64.c
Bcj2.o: ../../Bcj2.c
$(CXX) $(CFLAGS) ../../Bcj2.c
Ppmd7.o: ../../Ppmd7.c
$(CXX) $(CFLAGS) ../../Ppmd7.c
Ppmd7Dec.o: ../../Ppmd7Dec.c
$(CXX) $(CFLAGS) ../../Ppmd7Dec.c
7zFile.o: ../../7zFile.c
$(CXX) $(CFLAGS) ../../7zFile.c
7zStream.o: ../../7zStream.c
$(CXX) $(CFLAGS) ../../7zStream.c
clean:
-$(RM) $(PROG) $(OBJS)
include ../../7zip_gcc_c.mak

View File

@@ -1,5 +1,5 @@
/* 7zipInstall.c - 7-Zip Installer
2019-02-19 : Igor Pavlov : Public domain */
/* 7zipInstall.c - 7-Zip-Zstandard Installer
2021-02-23 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -12,9 +12,6 @@
#include <windows.h>
#include <ShlObj.h>
#define LLL_(quote) L##quote
#define LLL(quote) LLL_(quote)
#include "../../7z.h"
#include "../../7zAlloc.h"
#include "../../7zCrc.h"
@@ -25,11 +22,15 @@
#include "resource.h"
#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 wcscpy lstrcpyW
#define wcsncpy lstrcpynW
// wcsncpy() and lstrcpynW() work differently. We don't use them.
#define kInputBufSize ((size_t)1 << 18)
@@ -38,7 +39,7 @@
#define _7ZIP_CUR_VER ((MY_VER_MAJOR << 16) | MY_VER_MINOR)
#define _7ZIP_DLL_VER_COMPAT ((16 << 16) | 3)
static LPCWSTR const k_7zip = L"7-Zip-Zstandard";
static LPCSTR const k_7zip = "7-Zip-Zstandard";
static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip-Zstandard";
@@ -51,11 +52,27 @@ static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip-Zstandard";
#define k_7zip_with_Ver_base L"7-Zip ZS " LLL(MY_VERSION)
#ifdef _64BIT_INSTALLER
#define k_7zip_with_Ver k_7zip_with_Ver_base L" (x64)"
// #define USE_7ZIP_32_DLL
#if defined(_M_ARM64) || defined(_M_ARM)
#define k_Postfix L" (arm64)"
#else
#define k_Postfix L" (x64)"
#define USE_7ZIP_32_DLL
#endif
#else
#define k_7zip_with_Ver k_7zip_with_Ver_base
#if defined(_M_ARM64) || defined(_M_ARM)
#define k_Postfix L" (arm)"
#else
// #define k_Postfix L" (x86)"
#define k_Postfix
#endif
#endif
#define k_7zip_with_Ver k_7zip_with_Ver_base k_Postfix
static LPCWSTR const k_7zip_with_Ver_str = k_7zip_with_Ver;
static LPCWSTR const k_7zip_Setup = k_7zip_with_Ver L" Setup";
@@ -100,24 +117,47 @@ static HWND g_Progress_HWND;
static DWORD g_TotalSize;
static WCHAR cmd[MAX_PATH + 4];
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)))
// #define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c)))
static void PrintErrorMessage(const char *s)
static void CpyAscii(wchar_t *dest, const char *s)
{
WCHAR s2[256 + 4];
unsigned i;
for (i = 0; i < 256; i++)
for (;;)
{
Byte b = s[i];
Byte b = (Byte)*s++;
*dest++ = b;
if (b == 0)
break;
s2[i] = b;
return;
}
s2[i] = 0;
MessageBoxW(g_HWND, s2, k_7zip_with_Ver_str, MB_ICONERROR);
}
static void CatAscii(wchar_t *dest, const char *s)
{
dest += wcslen(dest);
CpyAscii(dest, s);
}
static void PrintErrorMessage(const char *s1, const wchar_t *s2)
{
WCHAR m[MAX_PATH + 512];
m[0] = 0;
CatAscii(m, "ERROR:");
if (s1)
{
CatAscii(m, "\n");
CatAscii(m, s1);
}
if (s2)
{
CatAscii(m, "\n");
wcscat(m, s2);
}
MessageBoxW(g_HWND, m, k_7zip_with_Ver_str, MB_ICONERROR | MB_OK);
}
@@ -347,7 +387,7 @@ static LONG MyRegistry_CreateKeyAndVal(HKEY parentKey, LPCWSTR keyName, LPCWSTR
}
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
static LONG MyRegistry_CreateKey_32(HKEY parentKey, LPCWSTR name, HKEY *destKey)
{
@@ -441,7 +481,7 @@ static void HexToString(UInt32 val, WCHAR *s)
#ifndef UNDER_CE
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM data)
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM data)
{
UNUSED_VAR(lp)
UNUSED_VAR(data)
@@ -560,11 +600,11 @@ static void Set7zipPostfix(WCHAR *s)
NormalizePrefix(s);
if (FindSubString(s, "7-Zip-Zstandard"))
return;
wcscat(s, L"7-Zip-Zstandard\\");
CatAscii(s, "7-Zip-Zstandard\\");
}
static int Install();
static int Install(void);
static void OnClose()
{
@@ -612,7 +652,7 @@ static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
}
if (!g_Install_was_Pressed)
{
SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDCANCEL), TRUE);
SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(hwnd, IDCANCEL), TRUE);
EnableWindow(g_Path_HWND, FALSE);
EnableWindow(GetDlgItem(hwnd, IDB_EXTRACT_SET_PATH), FALSE);
@@ -723,7 +763,7 @@ static void SetShellProgramsGroup(HWND hwndOwner)
{
#ifdef UNDER_CE
// wcscpy(link, L"\\Program Files\\");
// CpyAscii(link, "\\Program Files\\");
UNUSED_VAR(hwndOwner)
#else
@@ -744,8 +784,8 @@ static void SetShellProgramsGroup(HWND hwndOwner)
continue;
NormalizePrefix(link);
wcscat(link, k_7zip);
// wcscat(link, L"2");
CatAscii(link, k_7zip);
// CatAscii(link, "2");
if (i != 0)
MyCreateDir(link);
@@ -758,14 +798,14 @@ static void SetShellProgramsGroup(HWND hwndOwner)
for (k = 0; k < 2; k++)
{
wcscpy(link + baseLen, k == 0 ?
L"7-Zip File Manager.lnk" :
L"7-Zip Help.lnk"
CpyAscii(link + baseLen, k == 0 ?
"7-Zip File Manager.lnk" :
"7-Zip Help.lnk"
);
wcscpy(destPath, path);
wcscat(destPath, k == 0 ?
L"7zFM.exe" :
L"7-zip.chm");
CatAscii(destPath, k == 0 ?
"7zFM.exe" :
"7-zip.chm");
if (i == 0)
DeleteFileW(link);
@@ -789,7 +829,7 @@ static void WriteCLSID()
HKEY destKey;
LONG res;
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
MyRegistry_CreateKeyAndVal_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip, NULL, k_7zip_ShellExtension);
@@ -797,9 +837,9 @@ static void WriteCLSID()
if (res == ERROR_SUCCESS)
{
WCHAR destPath[MAX_PATH + 10];
WCHAR destPath[MAX_PATH + 40];
wcscpy(destPath, path);
wcscat(destPath, L"7-zip32.dll");
CatAscii(destPath, "7-zip32.dll");
/* res = */ MyRegistry_SetString(destKey, NULL, destPath);
/* res = */ MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment");
// DeleteRegValue(destKey, L"InprocServer32");
@@ -816,9 +856,9 @@ static void WriteCLSID()
if (res == ERROR_SUCCESS)
{
WCHAR destPath[MAX_PATH + 10];
WCHAR destPath[MAX_PATH + 40];
wcscpy(destPath, path);
wcscat(destPath, L"7-zip.dll");
CatAscii(destPath, "7-zip.dll");
/* res = */ MyRegistry_SetString(destKey, NULL, destPath);
/* res = */ MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment");
// DeleteRegValue(destKey, L"InprocServer32");
@@ -826,13 +866,13 @@ static void WriteCLSID()
}
}
static LPCWSTR const k_ShellEx_Items[] =
static LPCSTR const k_ShellEx_Items[] =
{
L"*\\shellex\\ContextMenuHandlers"
, L"Directory\\shellex\\ContextMenuHandlers"
, L"Folder\\shellex\\ContextMenuHandlers"
, L"Directory\\shellex\\DragDropHandlers"
, L"Drive\\shellex\\DragDropHandlers"
"*\\shellex\\ContextMenuHandlers"
, "Directory\\shellex\\ContextMenuHandlers"
, "Folder\\shellex\\ContextMenuHandlers"
, "Directory\\shellex\\DragDropHandlers"
, "Drive\\shellex\\DragDropHandlers"
};
static void WriteShellEx()
@@ -840,31 +880,31 @@ static void WriteShellEx()
unsigned i;
WCHAR destPath[MAX_PATH + 40];
for (i = 0; i < sizeof(k_ShellEx_Items) / sizeof(k_ShellEx_Items[0]); i++)
for (i = 0; i < ARRAY_SIZE(k_ShellEx_Items); i++)
{
wcscpy(destPath, k_ShellEx_Items[i]);
wcscat(destPath, L"\\7-Zip-Zstandard");
CpyAscii(destPath, k_ShellEx_Items[i]);
CatAscii(destPath, "\\7-Zip-Zstandard");
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
MyRegistry_CreateKeyAndVal_32(HKEY_CLASSES_ROOT, destPath, NULL, k_7zip_CLSID);
#endif
MyRegistry_CreateKeyAndVal (HKEY_CLASSES_ROOT, destPath, NULL, k_7zip_CLSID);
}
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
MyRegistry_CreateKeyAndVal_32(HKEY_LOCAL_MACHINE, k_Shell_Approved, k_7zip_CLSID, k_7zip_ShellExtension);
#endif
MyRegistry_CreateKeyAndVal (HKEY_LOCAL_MACHINE, k_Shell_Approved, k_7zip_CLSID, k_7zip_ShellExtension);
wcscpy(destPath, path);
CatAscii(destPath, "7zFM.exe");
{
HKEY destKey = 0;
LONG res = MyRegistry_CreateKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\7zFM.exe", &destKey);
if (res == ERROR_SUCCESS)
{
wcscpy(destPath, path);
wcscat(destPath, L"7zFM.exe");
MyRegistry_SetString(destKey, NULL, destPath);
MyRegistry_SetString(destKey, L"Path", path);
RegCloseKey(destKey);
@@ -877,17 +917,14 @@ static void WriteShellEx()
LONG res = MyRegistry_CreateKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\7-Zip-Zstandard", &destKey);
if (res == ERROR_SUCCESS)
{
// wcscpy(destPath, path);
// wcscat(destPath, L"7zFM.exe");
MyRegistry_SetString(destKey, L"DisplayName", k_7zip_with_Ver_str);
MyRegistry_SetString(destKey, L"DisplayVersion", LLL(MY_VERSION_NUMBERS));
MyRegistry_SetString(destKey, L"DisplayIcon", destPath);
MyRegistry_SetString(destKey, L"InstallLocation", path);
wcscpy(destPath, path);
MyRegistry_SetString(destKey, L"InstallLocation", destPath);
wcscat(destPath, L"Uninstall.exe");
// wcscat(destPath, L"\"");
destPath[0] = '\"';
wcscpy(destPath + 1, path);
CatAscii(destPath, "Uninstall.exe\"");
MyRegistry_SetString(destKey, L"UninstallString", destPath);
MyRegistry_SetDWORD(destKey, L"NoModify", 1);
@@ -912,17 +949,27 @@ static void WriteShellEx()
static const wchar_t *GetCmdParam(const wchar_t *s)
{
unsigned pos = 0;
BoolInt quoteMode = False;
for (;; s++)
{
wchar_t c = *s;
if (c == 0 || (c == L' ' && !quoteMode))
break;
if (c == L'\"')
{
quoteMode = !quoteMode;
else if (c == 0 || (c == L' ' && !quoteMode))
return s;
continue;
}
if (pos >= ARRAY_SIZE(cmd) - 1)
exit(1);
cmd[pos++] = c;
}
cmd[pos] = 0;
return s;
}
static void RemoveQuotes(wchar_t *s)
{
const wchar_t *src = s;
@@ -937,7 +984,7 @@ static void RemoveQuotes(wchar_t *s)
}
}
#define IS_LIMIT_CHAR(c) (c == 0 || c == ' ')
// #define IS_LIMIT_CHAR(c) (c == 0 || c == ' ')
typedef BOOL (WINAPI *Func_IsWow64Process)(HANDLE, PBOOL);
@@ -984,24 +1031,36 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
{
const wchar_t *s2 = GetCmdParam(s);
if (s[0] == '/')
BoolInt error = True;
if (cmd[0] == '/')
{
if (s[1] == 'S' && IS_LIMIT_CHAR(s[2]))
g_SilentMode = True;
else if (s[1] == 'D' && s[2] == '=')
if (cmd[1] == 'S')
{
size_t num;
s += 3;
num = s2 - s;
if (num > MAX_PATH)
num = MAX_PATH;
wcsncpy(path, s, (unsigned)num);
RemoveQuotes(path);
if (cmd[2] == 0)
{
g_SilentMode = True;
error = False;
}
}
else if (cmd[1] == 'D' && cmd[2] == '=')
{
wcscpy(path, cmd + 3);
// RemoveQuotes(path);
error = False;
}
}
s = s2;
if (error && cmdError[0] == 0)
wcscpy(cmdError, cmd);
}
}
if (cmdError[0] != 0)
{
if (!g_SilentMode)
PrintErrorMessage("Unsupported command:", cmdError);
return 1;
}
}
#if defined(_64BIT_INSTALLER) && !defined(_WIN64)
@@ -1016,7 +1075,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
if (!isWow64)
{
if (!g_SilentMode)
PrintErrorMessage("This installation requires Windows x64");
PrintErrorMessage("This installation requires Windows " MY_CPU_NAME, NULL);
return 1;
}
}
@@ -1040,27 +1099,27 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
{
/*
#ifdef UNDER_CE
wcscpy(path, L"\\Program Files\\");
CpyAscii(path, "\\Program Files\\");
#else
#ifdef _64BIT_INSTALLER
{
DWORD ttt = GetEnvironmentVariableW(L"ProgramW6432", path, MAX_PATH);
if (ttt == 0 || ttt > MAX_PATH)
wcscpy(path, L"C:\\");
CpyAscii(path, "C:\\");
}
#else
if (!SHGetSpecialFolderPathW(0, path, CSIDL_PROGRAM_FILES, FALSE))
wcscpy(path, L"C:\\");
CpyAscii(path, "C:\\");
#endif
#endif
*/
if (!MyRegistry_QueryString2(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion", L"ProgramFilesDir", path))
wcscpy(path,
CpyAscii(path,
#ifdef UNDER_CE
L"\\Program Files\\"
"\\Program Files\\"
#else
L"C:\\"
"C:\\"
#endif
);
@@ -1122,7 +1181,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
SetDlgItemTextW(g_HWND, IDOK, L"Close");
EnableWindow(GetDlgItem(g_HWND, IDOK), TRUE);
EnableWindow(GetDlgItem(g_HWND, IDCANCEL), FALSE);
SendMessage(g_HWND, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(g_HWND, IDOK), TRUE);
SendMessage(g_HWND, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(g_HWND, IDOK), TRUE);
}
}
}
@@ -1155,7 +1214,7 @@ static BoolInt GetErrorMessage(DWORD errorCode, WCHAR *message)
static int Install()
static int Install(void)
{
CFileInStream archiveStream;
CLookToRead2 lookStream;
@@ -1212,6 +1271,7 @@ if (res == SZ_OK)
LookToRead2_CreateVTable(&lookStream, False);
lookStream.buf = NULL;
RemoveQuotes(path);
{
// Remove post spaces
unsigned endPos = 0;
@@ -1227,6 +1287,11 @@ if (res == SZ_OK)
}
path[endPos] = 0;
if (path[0] == 0)
{
PrintErrorMessage("Incorrect path", NULL);
return 1;
}
}
NormalizePrefix(path);
@@ -1367,7 +1432,7 @@ if (res == SZ_OK)
break;
}
wcscpy(path, origPath);
wcscat(path, L".tmp");
CatAscii(path, ".tmp");
if (tempIndex > 1)
HexToString(tempIndex, path + wcslen(path));
if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
@@ -1391,7 +1456,7 @@ if (res == SZ_OK)
}
if (FindSubString(temp, "7-zip.dll")
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
|| FindSubString(temp, "7-zip32.dll")
#endif
)
@@ -1411,9 +1476,9 @@ if (res == SZ_OK)
WCHAR message[MAX_PATH * 3 + 100];
int mbRes;
wcscpy(message, L"Can't open file\n");
CpyAscii(message, "Can't open file\n");
wcscat(message, path);
wcscat(message, L"\n");
CatAscii(message, "\n");
GetErrorMessage(openRes, message + wcslen(message));
@@ -1572,7 +1637,7 @@ if (res == SZ_OK)
WCHAR m[MAX_PATH + 100];
m[0] = 0;
GetErrorMessage(winRes, m);
MessageBoxW(g_HWND, m, k_7zip_with_Ver_str, MB_ICONERROR);
PrintErrorMessage(NULL, m);
}
else
{
@@ -1590,7 +1655,7 @@ if (res == SZ_OK)
if (!errorMessage)
errorMessage = "ERROR";
PrintErrorMessage(errorMessage);
PrintErrorMessage(errorMessage, NULL);
}
}

View File

@@ -1,15 +1,15 @@
/* 7zipUninstall.c - 7-Zip Uninstaller
2019-02-02 : Igor Pavlov : Public domain */
2021-02-23 : Igor Pavlov : Public domain */
#include "Precomp.h"
#define SZ_ERROR_ABORT 100
#ifdef _MSC_VER
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
#pragma warning(disable : 4011) // vs2010: identifier truncated to _CRT_SECURE_CPP_OVERLOAD_SECURE
#endif
// #define SZ_ERROR_ABORT 100
#include <windows.h>
#include <ShlObj.h>
@@ -20,7 +20,9 @@
#define LLL_(quote) L##quote
#define LLL(quote) LLL_(quote)
// static const WCHAR * const k_7zip = L"7-Zip";
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
// static LPCWSTR const k_7zip = L"7-Zip-Zstandard";
// #define _64BIT_INSTALLER 1
@@ -31,18 +33,33 @@
#define k_7zip_with_Ver_base L"7-Zip ZS " LLL(MY_VERSION)
#ifdef _64BIT_INSTALLER
#define k_7zip_with_Ver k_7zip_with_Ver_base L" (x64)"
// #define USE_7ZIP_32_DLL
#if defined(_M_ARM64) || defined(_M_ARM)
#define k_Postfix L" (arm64)"
#else
#define k_Postfix L" (x64)"
#define USE_7ZIP_32_DLL
#endif
#else
#define k_7zip_with_Ver k_7zip_with_Ver_base
#if defined(_M_ARM64) || defined(_M_ARM)
#define k_Postfix L" (arm)"
#else
// #define k_Postfix L" (x86)"
#define k_Postfix
#endif
#endif
// static const WCHAR * const k_7zip_with_Ver_str = k_7zip_with_Ver;
#define k_7zip_with_Ver k_7zip_with_Ver_base k_Postfix
static const WCHAR * const k_Reg_Software_7zip = L"Software\\7-Zip-Zstandard";
static LPCWSTR const k_7zip_with_Ver_Uninstall = k_7zip_with_Ver L" Uninstall";
static const WCHAR * const k_Reg_Path = L"Path";
static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip-Zstandard";
static LPCWSTR const k_Reg_Path = L"Path";
static const WCHAR * const k_Reg_Path32 = L"Path"
static LPCWSTR const k_Reg_Path32 = L"Path"
#ifdef _64BIT_INSTALLER
L"64"
#else
@@ -64,8 +81,8 @@ static const WCHAR * const k_Reg_Path32 = L"Path"
#define k_7zip_CLSID L"{23170F69-20BB-278A-1000-000100020000}"
static const WCHAR * const k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID;
static const WCHAR * const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32";
static LPCWSTR const k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID;
static LPCWSTR const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32";
#define g_AllUsers True
@@ -79,9 +96,12 @@ static HWND g_Path_HWND;
static HWND g_InfoLine_HWND;
static HWND g_Progress_HWND;
typedef WINADVAPI LONG (APIENTRY *Func_RegDeleteKeyExW)(HKEY hKey, LPCWSTR lpSubKey, REGSAM samDesired, DWORD Reserved);
// WINADVAPI
typedef LONG (APIENTRY *Func_RegDeleteKeyExW)(HKEY hKey, LPCWSTR lpSubKey, REGSAM samDesired, DWORD Reserved);
static Func_RegDeleteKeyExW func_RegDeleteKeyExW;
static WCHAR cmd[MAX_PATH + 4];
static WCHAR cmdError[MAX_PATH + 4];
static WCHAR path[MAX_PATH * 2 + 40];
static WCHAR workDir[MAX_PATH + 10];
static WCHAR modulePath[MAX_PATH + 10];
@@ -90,10 +110,47 @@ static WCHAR tempPath[MAX_PATH * 2 + 40];
static WCHAR cmdLine[MAX_PATH * 3 + 40];
static WCHAR copyPath[MAX_PATH * 2 + 40];
static const WCHAR * const kUninstallExe = L"Uninstall.exe";
static LPCWSTR const kUninstallExe = L"Uninstall.exe";
#define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c)))
static void CpyAscii(wchar_t *dest, const char *s)
{
for (;;)
{
Byte b = (Byte)*s++;
*dest++ = b;
if (b == 0)
return;
}
}
static void CatAscii(wchar_t *dest, const char *s)
{
dest += wcslen(dest);
CpyAscii(dest, s);
}
static void PrintErrorMessage(const char *s1, const wchar_t *s2)
{
WCHAR m[MAX_PATH + 512];
m[0] = 0;
CatAscii(m, "ERROR:");
if (s1)
{
CatAscii(m, "\n");
CatAscii(m, s1);
}
if (s2)
{
CatAscii(m, "\n");
wcscat(m, s2);
}
MessageBoxW(g_HWND, m, k_7zip_with_Ver_Uninstall, MB_ICONERROR | MB_OK);
}
static BoolInt AreStringsEqual_NoCase(const wchar_t *s1, const wchar_t *s2)
{
for (;;)
@@ -171,7 +228,7 @@ static LONG MyRegistry_DeleteKey(HKEY parentKey, LPCWSTR name)
#endif
}
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
static int MyRegistry_QueryString2_32(HKEY hKey, LPCWSTR keyName, LPCWSTR valName, LPWSTR dest)
{
@@ -295,7 +352,7 @@ static void SetShellProgramsGroup(HWND hwndOwner)
continue;
NormalizePrefix(link);
wcscat(link, L"7-Zip-Zstandard\\");
CatAscii(link, "7-Zip-Zstandard\\");
{
const size_t baseLen = wcslen(link);
@@ -304,13 +361,13 @@ static void SetShellProgramsGroup(HWND hwndOwner)
for (k = 0; k < 2; k++)
{
wcscpy(link + baseLen, k == 0 ?
L"7-Zip File Manager.lnk" :
L"7-Zip Help.lnk");
CpyAscii(link + baseLen, k == 0 ?
"7-Zip File Manager.lnk" :
"7-Zip Help.lnk");
wcscpy(destPath, path);
wcscat(destPath, k == 0 ?
L"7zFM.exe" :
L"7-zip.chm");
CatAscii(destPath, k == 0 ?
"7zFM.exe" :
"7-zip.chm");
if (CreateShellLink(link, destPath) == S_OK)
{
@@ -331,20 +388,20 @@ static void SetShellProgramsGroup(HWND hwndOwner)
}
static const WCHAR * const k_ShellEx_Items[] =
static LPCSTR const k_ShellEx_Items[] =
{
L"*\\shellex\\ContextMenuHandlers"
, L"Directory\\shellex\\ContextMenuHandlers"
, L"Folder\\shellex\\ContextMenuHandlers"
, L"Directory\\shellex\\DragDropHandlers"
, L"Drive\\shellex\\DragDropHandlers"
"*\\shellex\\ContextMenuHandlers"
, "Directory\\shellex\\ContextMenuHandlers"
, "Folder\\shellex\\ContextMenuHandlers"
, "Directory\\shellex\\DragDropHandlers"
, "Drive\\shellex\\DragDropHandlers"
};
static const WCHAR * const k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
static LPCWSTR const k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
static const WCHAR * const k_AppPaths_7zFm = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\7zFM.exe";
static LPCWSTR const k_AppPaths_7zFm = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\7zFM.exe";
#define k_REG_Uninstall L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
static const WCHAR * const k_Uninstall_7zip = k_REG_Uninstall L"7-Zip-Zstandard";
static LPCWSTR const k_Uninstall_7zip = k_REG_Uninstall L"7-Zip-Zstandard";
static BoolInt AreEqual_Path_PrefixName(const wchar_t *s, const wchar_t *prefix, const wchar_t *name)
@@ -370,11 +427,11 @@ static void WriteCLSID()
{
unsigned i;
for (i = 0; i < sizeof(k_ShellEx_Items) / sizeof(k_ShellEx_Items[0]); i++)
for (i = 0; i < ARRAY_SIZE(k_ShellEx_Items); i++)
{
WCHAR destPath[MAX_PATH];
wcscpy(destPath, k_ShellEx_Items[i]);
wcscat(destPath, L"\\7-Zip-Zstandard");
CpyAscii(destPath, k_ShellEx_Items[i]);
CatAscii(destPath, "\\7-Zip-Zstandard");
MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, destPath);
}
@@ -393,7 +450,7 @@ static void WriteCLSID()
}
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
if (MyRegistry_QueryString2_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc, NULL, s))
{
@@ -407,11 +464,11 @@ static void WriteCLSID()
{
unsigned i;
for (i = 0; i < sizeof(k_ShellEx_Items) / sizeof(k_ShellEx_Items[0]); i++)
for (i = 0; i < ARRAY_SIZE(k_ShellEx_Items); i++)
{
WCHAR destPath[MAX_PATH];
wcscpy(destPath, k_ShellEx_Items[i]);
wcscat(destPath, L"\\7-Zip-Zstandard");
CpyAscii(destPath, k_ShellEx_Items[i]);
CatAscii(destPath, "\\7-Zip-Zstandard");
MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, destPath);
}
@@ -444,17 +501,27 @@ static void WriteCLSID()
static const wchar_t *GetCmdParam(const wchar_t *s)
{
unsigned pos = 0;
BoolInt quoteMode = False;
for (;; s++)
{
wchar_t c = *s;
if (c == 0 || (c == L' ' && !quoteMode))
break;
if (c == L'\"')
{
quoteMode = !quoteMode;
else if (c == 0 || (c == L' ' && !quoteMode))
return s;
continue;
}
if (pos >= ARRAY_SIZE(cmd) - 1)
exit(1);
cmd[pos++] = c;
}
cmd[pos] = 0;
return s;
}
/*
static void RemoveQuotes(wchar_t *s)
{
const wchar_t *src = s;
@@ -468,6 +535,7 @@ static void RemoveQuotes(wchar_t *s)
return;
}
}
*/
static BoolInt DoesFileOrDirExist()
{
@@ -489,7 +557,7 @@ static BOOL RemoveFileAfterReboot()
return RemoveFileAfterReboot2(path);
}
#define IS_LIMIT_CHAR(c) (c == 0 || c == ' ')
// #define IS_LIMIT_CHAR(c) (c == 0 || c == ' ')
static BoolInt IsThereSpace(const wchar_t *s)
{
@@ -507,10 +575,10 @@ static void AddPathParam(wchar_t *dest, const wchar_t *src)
{
BoolInt needQuote = IsThereSpace(src);
if (needQuote)
wcscat(dest, L"\"");
CatAscii(dest, "\"");
wcscat(dest, src);
if (needQuote)
wcscat(dest, L"\"");
CatAscii(dest, "\"");
}
@@ -543,12 +611,12 @@ static BOOL RemoveDir()
#define k_Lang L"Lang"
#define k_Lang "Lang"
// NUM_LANG_TXT_FILES files are placed before en.ttt
#define NUM_LANG_TXT_FILES 88
#define NUM_LANG_TXT_FILES 92
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
#define NUM_EXTRA_FILES_64BIT 1
#else
#define NUM_EXTRA_FILES_64BIT 0
@@ -560,7 +628,7 @@ static const char * const k_Names =
"af an ar ast az ba be bg bn br ca co cs cy da de el eo es et eu ext"
" fa fi fr fur fy ga gl gu he hi hr hu hy id io is it ja ka kaa kab kk ko ku ku-ckb ky"
" lij lt lv mk mn mng mng2 mr ms nb ne nl nn pa-in pl ps pt pt-br ro ru"
" sa si sk sl sq sr-spc sr-spl sv ta th tr tt ug uk uz va vi yo zh-cn zh-tw"
" sa si sk sl sq sr-spc sr-spl sv sw ta tg th tk tr tt ug uk uz uz-cyrl va vi yo zh-cn zh-tw"
" en.ttt"
" descript.ion"
" History.txt"
@@ -573,7 +641,7 @@ static const char * const k_Names =
" 7zG.exe"
" 7z.dll"
" 7zFM.exe"
#ifdef _64BIT_INSTALLER
#ifdef USE_7ZIP_32_DLL
" 7-zip32.dll"
#endif
" 7-zip.dll"
@@ -628,7 +696,7 @@ static int Install()
temp = path + pathLen;
if (i <= NUM_LANG_TXT_FILES)
wcscpy(temp, k_Lang L"\\");
CpyAscii(temp, k_Lang "\\");
{
WCHAR *dest = temp + wcslen(temp);
@@ -648,7 +716,7 @@ static int Install()
}
if (i < NUM_LANG_TXT_FILES)
wcscat(temp, L".txt");
CatAscii(temp, ".txt");
if (!g_SilentMode)
SetWindowTextW(g_InfoLine_HWND, temp);
@@ -673,7 +741,7 @@ static int Install()
}
}
wcscpy(path + pathLen, k_Lang);
CpyAscii(path + pathLen, k_Lang);
RemoveDir();
path[pathLen] = 0;
@@ -706,8 +774,8 @@ static int Install()
WCHAR m[MAX_PATH + 100];
m[0] = 0;
if (winRes == 0 || !GetErrorMessage(winRes, m))
wcscpy(m, L"ERROR");
MessageBoxW(g_HWND, m, L"Error", MB_ICONERROR | MB_OK);
CpyAscii(m, "ERROR");
PrintErrorMessage("System ERROR:", m);
}
return 1;
@@ -720,7 +788,7 @@ static void OnClose()
{
if (MessageBoxW(g_HWND,
L"Do you want to cancel uninstallation?",
k_7zip_with_Ver,
k_7zip_with_Ver_Uninstall,
MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES)
return;
}
@@ -739,7 +807,7 @@ static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
g_InfoLine_HWND = GetDlgItem(hwnd, IDT_CUR_FILE);
g_Progress_HWND = GetDlgItem(hwnd, IDC_PROGRESS);
SetWindowTextW(hwnd, k_7zip_with_Ver L" Uninstall");
SetWindowTextW(hwnd, k_7zip_with_Ver_Uninstall);
SetDlgItemTextW(hwnd, IDE_EXTRACT_PATH, path);
ShowWindow(g_Progress_HWND, SW_HIDE);
@@ -759,7 +827,7 @@ static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
}
if (!g_Install_was_Pressed)
{
SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDCANCEL), TRUE);
SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(hwnd, IDCANCEL), TRUE);
EnableWindow(g_Path_HWND, FALSE);
EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
@@ -822,7 +890,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
{
const wchar_t *s = GetCommandLineW();
#ifndef UNDER_CE
s = GetCmdParam(s);
#endif
@@ -844,32 +912,47 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
{
const wchar_t *s2 = GetCmdParam(s);
if (s[0] == '/')
BoolInt error = True;
if (cmd[0] == '/')
{
if (s[1] == 'S' && IS_LIMIT_CHAR(s[2]))
g_SilentMode = True;
else if (s[1] == 'N' && IS_LIMIT_CHAR(s[2]))
useTemp = False;
else if (s[1] == 'D' && s[2] == '=')
if (cmd[1] == 'S')
{
size_t num;
s += 3;
num = s2 - s;
if (num <= MAX_PATH)
if (cmd[2] == 0)
{
wcsncpy(workDir, s, num);
workDir[num] = 0;
RemoveQuotes(workDir);
useTemp = False;
g_SilentMode = True;
error = False;
}
}
else if (cmd[1] == 'N')
{
if (cmd[2] == 0)
{
useTemp = False;
error = False;
}
}
else if (cmd[1] == 'D' && cmd[2] == '=')
{
wcscpy(workDir, cmd + 3);
// RemoveQuotes(workDir);
useTemp = False;
error = False;
}
}
s = s2;
if (error && cmdError[0] == 0)
wcscpy(cmdError, cmd);
}
}
if (cmdError[0] != 0)
{
if (!g_SilentMode)
PrintErrorMessage("Unsupported command:", cmdError);
return 1;
}
}
{
wchar_t *name;
DWORD len = GetModuleFileNameW(NULL, modulePath, MAX_PATH);
@@ -925,7 +1008,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
for (i = 0; i < 100; i++, d += GetTickCount())
{
wcscpy(path + pathLen, L"7z");
CpyAscii(path + pathLen, "7z");
{
wchar_t *s = path + wcslen(path);
@@ -944,7 +1027,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
continue;
if (CreateDirectoryW(path, NULL))
{
wcscat(path, WSTRING_PATH_SEPARATOR);
CatAscii(path, STRING_PATH_SEPARATOR);
wcscpy(tempPath, path);
break;
}
@@ -955,7 +1038,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
if (tempPath[0] != 0)
{
wcscpy(copyPath, tempPath);
wcscat(copyPath, L"Uninst.exe"); // we need not "Uninstall.exe" here
CatAscii(copyPath, "Uninst.exe"); // we need not "Uninstall.exe" here
if (CopyFileW(modulePath, copyPath, TRUE))
{
@@ -969,7 +1052,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
// maybe CreateProcess supports path with spaces even without quotes.
AddPathParam(cmdLine, copyPath);
wcscat(cmdLine, L" /N /D=");
CatAscii(cmdLine, " /N /D=");
AddPathParam(cmdLine, modulePrefix);
if (cmdParams[0] != 0 && wcslen(cmdParams) < MAX_PATH * 2 + 10)
@@ -1066,7 +1149,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
SetDlgItemTextW(g_HWND, IDOK, L"Close");
EnableWindow(GetDlgItem(g_HWND, IDOK), TRUE);
EnableWindow(GetDlgItem(g_HWND, IDCANCEL), FALSE);
SendMessage(g_HWND, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(g_HWND, IDOK), TRUE);
SendMessage(g_HWND, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(g_HWND, IDOK), TRUE);
}
}
}

View File

@@ -1,5 +1,5 @@
/* LzmaUtil.c -- Test application for LZMA compression
2018-07-04 : Igor Pavlov : Public domain */
2021-02-15 : Igor Pavlov : Public domain */
#include "../../Precomp.h"
@@ -15,9 +15,9 @@
#include "../../LzmaDec.h"
#include "../../LzmaEnc.h"
static const char * const kCantReadMessage = "Can not read input file";
static const char * const kCantWriteMessage = "Can not write output file";
static const char * const kCantAllocateMessage = "Can not allocate memory";
static const char * const kCantReadMessage = "Cannot read input file";
static const char * const kCantWriteMessage = "Cannot write output file";
static const char * const kCantAllocateMessage = "Cannot allocate memory";
static const char * const kDataErrorMessage = "Data error";
static void PrintHelp(char *buffer)
@@ -37,9 +37,25 @@ static int PrintError(char *buffer, const char *message)
return 1;
}
static int PrintError_WRes(char *buffer, const char *message, WRes wres)
{
strcat(buffer, "\nError: ");
strcat(buffer, message);
sprintf(buffer + strlen(buffer), "\nSystem error code: %d", (unsigned)wres);
#ifndef _WIN32
{
const char *s = strerror(wres);
if (s)
sprintf(buffer + strlen(buffer), " : %s", s);
}
#endif
strcat(buffer, "\n");
return 1;
}
static int PrintErrorNumber(char *buffer, SRes val)
{
sprintf(buffer + strlen(buffer), "\nError code: %x\n", (unsigned)val);
sprintf(buffer + strlen(buffer), "\n7-Zip error code: %d\n", (unsigned)val);
return 1;
}
@@ -181,9 +197,11 @@ static int main2(int numArgs, const char *args[], char *rs)
FileSeqInStream_CreateVTable(&inStream);
File_Construct(&inStream.file);
inStream.wres = 0;
FileOutStream_CreateVTable(&outStream);
File_Construct(&outStream.file);
outStream.wres = 0;
if (numArgs == 1)
{
@@ -206,14 +224,19 @@ static int main2(int numArgs, const char *args[], char *rs)
return PrintError(rs, "Incorrect UInt32 or UInt64");
}
if (InFile_Open(&inStream.file, args[2]) != 0)
return PrintError(rs, "Can not open input file");
{
WRes wres = InFile_Open(&inStream.file, args[2]);
if (wres != 0)
return PrintError_WRes(rs, "Cannot open input file", wres);
}
if (numArgs > 3)
{
WRes wres;
useOutFile = True;
if (OutFile_Open(&outStream.file, args[3]) != 0)
return PrintError(rs, "Can not open output file");
wres = OutFile_Open(&outStream.file, args[3]);
if (wres != 0)
return PrintError_WRes(rs, "Cannot open output file", wres);
}
else if (encodeMode)
PrintUserError(rs);
@@ -221,7 +244,9 @@ static int main2(int numArgs, const char *args[], char *rs)
if (encodeMode)
{
UInt64 fileSize;
File_GetLength(&inStream.file, &fileSize);
WRes wres = File_GetLength(&inStream.file, &fileSize);
if (wres != 0)
return PrintError_WRes(rs, "Cannot get file length", wres);
res = Encode(&outStream.vt, &inStream.vt, fileSize, rs);
}
else
@@ -240,9 +265,9 @@ static int main2(int numArgs, const char *args[], char *rs)
else if (res == SZ_ERROR_DATA)
return PrintError(rs, kDataErrorMessage);
else if (res == SZ_ERROR_WRITE)
return PrintError(rs, kCantWriteMessage);
return PrintError_WRes(rs, kCantWriteMessage, outStream.wres);
else if (res == SZ_ERROR_READ)
return PrintError(rs, kCantReadMessage);
return PrintError_WRes(rs, kCantReadMessage, inStream.wres);
return PrintErrorNumber(rs, res);
}
return 0;

View File

@@ -1,44 +1,19 @@
PROG = lzma
CXX = g++
LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall -D_7ZIP_ST
PROG = 7lzma
include ../../../CPP/7zip/LzmaDec_gcc.mak
OBJS = \
LzmaUtil.o \
Alloc.o \
LzFind.o \
LzmaDec.o \
LzmaEnc.o \
7zFile.o \
7zStream.o \
$(LZMA_DEC_OPT_OBJS) \
$O/7zFile.o \
$O/7zStream.o \
$O/Alloc.o \
$O/LzFind.o \
$O/LzFindMt.o \
$O/LzmaDec.o \
$O/LzmaEnc.o \
$O/LzmaUtil.o \
$O/Threads.o \
all: $(PROG)
$(PROG): $(OBJS)
$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)
LzmaUtil.o: LzmaUtil.c
$(CXX) $(CFLAGS) LzmaUtil.c
Alloc.o: ../../Alloc.c
$(CXX) $(CFLAGS) ../../Alloc.c
LzFind.o: ../../LzFind.c
$(CXX) $(CFLAGS) ../../LzFind.c
LzmaDec.o: ../../LzmaDec.c
$(CXX) $(CFLAGS) ../../LzmaDec.c
LzmaEnc.o: ../../LzmaEnc.c
$(CXX) $(CFLAGS) ../../LzmaEnc.c
7zFile.o: ../../7zFile.c
$(CXX) $(CFLAGS) ../../7zFile.c
7zStream.o: ../../7zStream.c
$(CXX) $(CFLAGS) ../../7zStream.c
clean:
-$(RM) $(PROG) $(OBJS)
include ../../7zip_gcc_c.mak