diff options
Diffstat (limited to '3rdparty/lzma/C/Util')
-rw-r--r-- | 3rdparty/lzma/C/Util/7z/7z.dsp | 8 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/7z/7zMain.c | 486 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/7z/Precomp.h | 10 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/7z/makefile | 2 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/7z/makefile.gcc | 107 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/Lzma/LzmaUtil.c | 177 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/Lzma/LzmaUtil.dsp | 26 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/Lzma/Precomp.h | 14 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/Lzma/makefile | 2 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/Lzma/makefile.gcc | 59 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/LzmaLib/LzmaLib.dsp | 24 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/LzmaLib/LzmaLibExports.c | 13 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/LzmaLib/Precomp.c | 4 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/LzmaLib/Precomp.h | 14 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/LzmaLib/makefile | 24 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/SfxSetup/Precomp.h | 10 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c | 86 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/SfxSetup/makefile | 4 | ||||
-rw-r--r-- | 3rdparty/lzma/C/Util/SfxSetup/makefile_con | 5 |
19 files changed, 752 insertions, 323 deletions
diff --git a/3rdparty/lzma/C/Util/7z/7z.dsp b/3rdparty/lzma/C/Util/7z/7z.dsp index be0f0a74376..11e1b03e504 100644 --- a/3rdparty/lzma/C/Util/7z/7z.dsp +++ b/3rdparty/lzma/C/Util/7z/7z.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FAcs /Yu"Precomp.h" /FD /c +# ADD CPP /nologo /MD /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /D "Z7_PPMD_SUPPORT" /FAcs /Yu"Precomp.h" /FD /c # ADD BASE RSC /l 0x419 /d "NDEBUG" # ADD RSC /l 0x419 /d "NDEBUG" BSC32=bscmake.exe @@ -67,7 +67,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W4 /WX /Gm /GX /ZI /Od /D "_DEBUG" /D "_SZ_ALLOC_DEBUG2" /D "_SZ_NO_INT_64_A" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Yu"Precomp.h" /FD /GZ /c +# ADD CPP /nologo /W4 /WX /Gm /GX /ZI /Od /D "_DEBUG" /D "_SZ_ALLOC_DEBUG2" /D "_SZ_NO_INT_64_A" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /D "Z7_PPMD_SUPPORT" /Yu"Precomp.h" /FD /GZ /c # ADD BASE RSC /l 0x419 /d "_DEBUG" # ADD RSC /l 0x419 /d "_DEBUG" BSC32=bscmake.exe @@ -145,6 +145,10 @@ SOURCE=..\..\7zTypes.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 diff --git a/3rdparty/lzma/C/Util/7z/7zMain.c b/3rdparty/lzma/C/Util/7z/7zMain.c index 1837e9d606a..547920ac31f 100644 --- a/3rdparty/lzma/C/Util/7z/7zMain.c +++ b/3rdparty/lzma/C/Util/7z/7zMain.c @@ -1,11 +1,13 @@ /* 7zMain.c - Test application for 7z Decoder -2016-05-16 : Igor Pavlov : Public domain */ +2023-04-04 : Igor Pavlov : Public domain */ #include "Precomp.h" #include <stdio.h> #include <string.h> +#include "../../CpuArch.h" + #include "../../7z.h" #include "../../7zAlloc.h" #include "../../7zBuf.h" @@ -18,12 +20,29 @@ #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 #endif -static ISzAlloc g_Alloc = { SzAlloc, SzFree }; +#define kInputBufSize ((size_t)1 << 18) + +static const ISzAlloc g_Alloc = { SzAlloc, SzFree }; +// static const ISzAlloc g_Alloc_temp = { SzAllocTemp, SzFreeTemp }; + + +static void Print(const char *s) +{ + fputs(s, stdout); +} + static int Buf_EnsureSize(CBuf *dest, size_t size) { @@ -34,19 +53,19 @@ static int Buf_EnsureSize(CBuf *dest, size_t size) } #ifndef _WIN32 -#define _USE_UTF8 +#define MY_USE_UTF8 #endif -/* #define _USE_UTF8 */ +/* #define MY_USE_UTF8 */ -#ifdef _USE_UTF8 +#ifdef MY_USE_UTF8 -#define _UTF8_START(n) (0x100 - (1 << (7 - (n)))) +#define MY_UTF8_START(n) (0x100 - (1 << (7 - (n)))) -#define _UTF8_RANGE(n) (((UInt32)1) << ((n) * 5 + 6)) +#define MY_UTF8_RANGE(n) (((UInt32)1) << ((n) * 5 + 6)) -#define _UTF8_HEAD(n, val) ((Byte)(_UTF8_START(n) + (val >> (6 * (n))))) -#define _UTF8_CHAR(n, val) ((Byte)(0x80 + (((val) >> (6 * (n))) & 0x3F))) +#define MY_UTF8_HEAD(n, val) ((Byte)(MY_UTF8_START(n) + (val >> (6 * (n))))) +#define MY_UTF8_CHAR(n, val) ((Byte)(0x80 + (((val) >> (6 * (n))) & 0x3F))) static size_t Utf16_To_Utf8_Calc(const UInt16 *src, const UInt16 *srcLim) { @@ -63,7 +82,7 @@ static size_t Utf16_To_Utf8_Calc(const UInt16 *src, const UInt16 *srcLim) if (val < 0x80) continue; - if (val < _UTF8_RANGE(1)) + if (val < MY_UTF8_RANGE(1)) { size++; continue; @@ -71,7 +90,7 @@ static size_t Utf16_To_Utf8_Calc(const UInt16 *src, const UInt16 *srcLim) if (val >= 0xD800 && val < 0xDC00 && src != srcLim) { - UInt32 c2 = *src; + const UInt32 c2 = *src; if (c2 >= 0xDC00 && c2 < 0xE000) { src++; @@ -96,37 +115,37 @@ static Byte *Utf16_To_Utf8(Byte *dest, const UInt16 *src, const UInt16 *srcLim) if (val < 0x80) { - *dest++ = (char)val; + *dest++ = (Byte)val; continue; } - if (val < _UTF8_RANGE(1)) + if (val < MY_UTF8_RANGE(1)) { - dest[0] = _UTF8_HEAD(1, val); - dest[1] = _UTF8_CHAR(0, val); + dest[0] = MY_UTF8_HEAD(1, val); + dest[1] = MY_UTF8_CHAR(0, val); dest += 2; continue; } if (val >= 0xD800 && val < 0xDC00 && src != srcLim) { - UInt32 c2 = *src; + const UInt32 c2 = *src; if (c2 >= 0xDC00 && c2 < 0xE000) { src++; val = (((val - 0xD800) << 10) | (c2 - 0xDC00)) + 0x10000; - dest[0] = _UTF8_HEAD(3, val); - dest[1] = _UTF8_CHAR(2, val); - dest[2] = _UTF8_CHAR(1, val); - dest[3] = _UTF8_CHAR(0, val); + dest[0] = MY_UTF8_HEAD(3, val); + dest[1] = MY_UTF8_CHAR(2, val); + dest[2] = MY_UTF8_CHAR(1, val); + dest[3] = MY_UTF8_CHAR(0, val); dest += 4; continue; } } - dest[0] = _UTF8_HEAD(2, val); - dest[1] = _UTF8_CHAR(1, val); - dest[2] = _UTF8_CHAR(0, val); + dest[0] = MY_UTF8_HEAD(2, val); + dest[1] = MY_UTF8_CHAR(1, val); + dest[2] = MY_UTF8_CHAR(0, val); dest += 3; } } @@ -144,27 +163,27 @@ static SRes Utf16_To_Utf8Buf(CBuf *dest, const UInt16 *src, size_t srcLen) #endif static SRes Utf16_To_Char(CBuf *buf, const UInt16 *s - #ifndef _USE_UTF8 + #ifndef MY_USE_UTF8 , UINT codePage #endif ) { unsigned len = 0; - for (len = 0; s[len] != 0; len++); + for (len = 0; s[len] != 0; len++) {} - #ifndef _USE_UTF8 + #ifndef MY_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, 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; @@ -180,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 @@ -190,14 +209,14 @@ static WRes MyCreateDir(const UInt16 *name) { #ifdef USE_WINDOWS_FILE - return CreateDirectoryW(name, NULL) ? 0 : GetLastError(); + return CreateDirectoryW((LPCWSTR)name, NULL) ? 0 : GetLastError(); #else CBuf buf; WRes res; Buf_Init(&buf); - RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)); + RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)) res = #ifdef _WIN32 @@ -215,35 +234,36 @@ static WRes MyCreateDir(const UInt16 *name) static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name) { #ifdef USE_WINDOWS_FILE - return OutFile_OpenW(p, name); + return OutFile_OpenW(p, (LPCWSTR)name); #else CBuf buf; WRes res; Buf_Init(&buf); - RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)); + RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)) res = OutFile_Open(p, (const char *)buf.data); Buf_Free(&buf, &g_Alloc); return res; #endif } + static SRes PrintString(const UInt16 *s) { CBuf buf; SRes res; Buf_Init(&buf); res = Utf16_To_Char(&buf, s - #ifndef _USE_UTF8 + #ifndef MY_USE_UTF8 , CP_OEMCP #endif ); if (res == SZ_OK) - fputs((const char *)buf.data, stdout); + Print((const char *)buf.data); Buf_Free(&buf, &g_Alloc); return res; } -static void UInt64ToStr(UInt64 value, char *s) +static void UInt64ToStr(UInt64 value, char *s, int numDigits) { char temp[32]; int pos = 0; @@ -253,6 +273,10 @@ static void UInt64ToStr(UInt64 value, char *s) value /= 10; } while (value != 0); + + for (numDigits -= pos; numDigits > 0; numDigits--) + *s++ = ' '; + do *s++ = temp[--pos]; while (pos); @@ -266,8 +290,10 @@ static char *UIntToStr(char *s, unsigned value, int numDigits) do temp[pos++] = (char)('0' + (value % 10)); while (value /= 10); + for (numDigits -= pos; numDigits > 0; numDigits--) *s++ = '0'; + do *s++ = temp[--pos]; while (pos); @@ -281,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() +{ + const time_t utc = time(NULL); + struct tm *ptm = localtime(&utc); + const int localdaylight = ptm->tm_isdst; /* daylight for local timezone */ + ptm = gmtime(&utc); + ptm->tm_isdst = localdaylight; /* use local daylight, not that of Greenwich */ + const 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) +{ + const 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; + const 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, ×[0]); + FILETIME_To_timespec(mTime, ×[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; @@ -310,7 +461,7 @@ static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s) ms[1] = 29; for (mon = 0;; mon++) { - unsigned d = ms[mon]; + const unsigned d = ms[mon]; if (v < d) break; v -= d; @@ -323,12 +474,56 @@ static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s) UIntToStr_2(s, sec); s[2] = 0; } -void PrintError(char *sz) +static void PrintLF(void) +{ + Print("\n"); +} + +static void PrintError(char *s) +{ + Print("\nERROR: "); + Print(s); + PrintLF(); +} + +static void PrintError_WRes(const char *message, WRes wres) { - printf("\nERROR: %s\n", sz); + 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, Bool isDir, char *s) +static void GetAttribString(UInt32 wa, BoolInt isDir, char *s) { #ifdef USE_WINDOWS_FILE s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.'); @@ -343,25 +538,27 @@ static void GetAttribString(UInt32 wa, Bool isDir, char *s) #endif } + // #define NUM_PARENTS_MAX 128 -int MY_CDECL main(int numargs, char *args[]) +int Z7_CDECL main(int numargs, char *args[]) { + ISzAlloc allocImp; + ISzAlloc allocTempImp; + CFileInStream archiveStream; - CLookToRead lookStream; + CLookToRead2 lookStream; CSzArEx db; SRes res; - ISzAlloc allocImp; - ISzAlloc allocTempImp; UInt16 *temp = NULL; size_t tempSize = 0; // UInt32 parents[NUM_PARENTS_MAX]; - printf("\n7z ANSI-C Decoder " MY_VERSION_COPYRIGHT_DATE "\n\n"); + Print("\n7z Decoder " MY_VERSION_CPU " : " MY_COPYRIGHT_DATE "\n\n"); if (numargs == 1) { - printf( + Print( "Usage: 7zDec <command> <archive_name>\n\n" "<Commands>\n" " e: Extract files from archive (without using directory names)\n" @@ -370,7 +567,7 @@ int MY_CDECL main(int numargs, char *args[]) " x: eXtract files with full paths\n"); return 0; } - + if (numargs < 3) { PrintError("incorrect command"); @@ -381,33 +578,52 @@ int MY_CDECL main(int numargs, char *args[]) g_FileCodePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; #endif - allocImp.Alloc = SzAlloc; - allocImp.Free = SzFree; - allocTempImp.Alloc = SzAllocTemp; - allocTempImp.Free = SzFreeTemp; + allocImp = g_Alloc; + allocTempImp = g_Alloc; + // allocTempImp = g_Alloc_temp; - #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); - LookToRead_CreateVTable(&lookStream, False); - - lookStream.realStream = &archiveStream.s; - LookToRead_Init(&lookStream); + archiveStream.wres = 0; + LookToRead2_CreateVTable(&lookStream, False); + lookStream.buf = NULL; - CrcGenerateTable(); + res = SZ_OK; + { + lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize); + if (!lookStream.buf) + res = SZ_ERROR_MEM; + else + { + lookStream.bufSize = kInputBufSize; + lookStream.realStream = &archiveStream.vt; + LookToRead2_INIT(&lookStream) + } + } + + CrcGenerateTable(); + SzArEx_Init(&db); - - res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp); + + if (res == SZ_OK) + { + res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp); + } if (res == SZ_OK) { @@ -442,7 +658,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); @@ -477,7 +693,7 @@ int MY_CDECL main(int numargs, char *args[]) GetAttribString(SzBitWithVals_Check(&db.Attribs, i) ? db.Attribs.Vals[i] : 0, isDir, attr); fileSize = SzArEx_GetFileSize(&db, i); - UInt64ToStr(fileSize, s); + UInt64ToStr(fileSize, s, 10); if (SzBitWithVals_Check(&db.MTime, i)) ConvertFileTimeToString(&db.MTime.Vals[i], t); @@ -489,29 +705,33 @@ int MY_CDECL main(int numargs, char *args[]) t[j] = '\0'; } - printf("%s %s %10s ", t, attr, s); + Print(t); + Print(" "); + Print(attr); + Print(" "); + Print(s); + Print(" "); res = PrintString(temp); if (res != SZ_OK) break; if (isDir) - printf("/"); - printf("\n"); + Print("/"); + PrintLF(); continue; } - fputs(testCommand ? - "Testing ": - "Extracting ", - stdout); + Print(testCommand ? + "T ": + "- "); res = PrintString(temp); if (res != SZ_OK) break; if (isDir) - printf("/"); + Print("/"); else { - res = SzArEx_Extract(&db, &lookStream.s, i, + res = SzArEx_Extract(&db, &lookStream.vt, i, &blockIndex, &outBuffer, &outBufferSize, &offset, &outSizeProcessed, &allocImp, &allocTempImp); @@ -543,62 +763,126 @@ int MY_CDECL main(int numargs, char *args[]) if (isDir) { MyCreateDir(destPath); - printf("\n"); + PrintLF(); continue; } - else if (OutFile_OpenUtf16(&outFile, destPath)) + else { - PrintError("can not open output file"); - res = SZ_ERROR_FAIL; - break; + const 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; + const 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; + } } - - if (File_Close(&outFile)) + { - PrintError("can not close output file"); - res = SZ_ERROR_FAIL; - break; + FILETIME mtime; + FILETIME *mtimePtr = NULL; + + #ifdef USE_WINDOWS_FILE + FILETIME ctime; + FILETIME *ctimePtr = NULL; + #endif + + if (SzBitWithVals_Check(&db.MTime, i)) + { + const CNtfsFileTime *t = &db.MTime.Vals[i]; + mtime.dwLowDateTime = (DWORD)(t->Low); + mtime.dwHighDateTime = (DWORD)(t->High); + mtimePtr = &mtime; + } + + #ifdef USE_WINDOWS_FILE + if (SzBitWithVals_Check(&db.CTime, i)) + { + const CNtfsFileTime *t = &db.CTime.Vals[i]; + ctime.dwLowDateTime = (DWORD)(t->Low); + ctime.dwHighDateTime = (DWORD)(t->High); + ctimePtr = &ctime; + } + + if (mtimePtr || ctimePtr) + SetFileTime(outFile.handle, ctimePtr, NULL, mtimePtr); + #endif + + { + const 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 if (SzBitWithVals_Check(&db.Attribs, i)) - SetFileAttributesW(destPath, db.Attribs.Vals[i]); + { + UInt32 attrib = db.Attribs.Vals[i]; + /* p7zip stores posix attributes in high 16 bits and adds 0x8000 as marker. + We remove posix bits, if we detect posix mode field */ + if ((attrib & 0xF0000000) != 0) + attrib &= 0x7FFF; + SetFileAttributesW((LPCWSTR)destPath, attrib); + } #endif } - printf("\n"); + PrintLF(); } - IAlloc_Free(&allocImp, outBuffer); + ISzAlloc_Free(&allocImp, outBuffer); } } - SzArEx_Free(&db, &allocImp); SzFree(NULL, temp); + SzArEx_Free(&db, &allocImp); + ISzAlloc_Free(&allocImp, lookStream.buf); File_Close(&archiveStream.file); if (res == SZ_OK) { - printf("\nEverything is Ok\n"); + Print("\nEverything is Ok\n"); return 0; } 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 - printf("\nERROR #%d\n", res); + { + char s[32]; + UInt64ToStr((unsigned)res, s, 0); + PrintError(s); + } return 1; } diff --git a/3rdparty/lzma/C/Util/7z/Precomp.h b/3rdparty/lzma/C/Util/7z/Precomp.h index 588a66f7eb8..bc8fa219b58 100644 --- a/3rdparty/lzma/C/Util/7z/Precomp.h +++ b/3rdparty/lzma/C/Util/7z/Precomp.h @@ -1,8 +1,12 @@ /* Precomp.h -- StdAfx -2013-06-16 : 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" diff --git a/3rdparty/lzma/C/Util/7z/makefile b/3rdparty/lzma/C/Util/7z/makefile index 9a49fd515a6..dfc560e9255 100644 --- a/3rdparty/lzma/C/Util/7z/makefile +++ b/3rdparty/lzma/C/Util/7z/makefile @@ -1,4 +1,4 @@ -CFLAGS = $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT +CFLAGS = $(CFLAGS) -DZ7_PPMD_SUPPORT -DZ7_EXTRACT_ONLY PROG = 7zDec.exe diff --git a/3rdparty/lzma/C/Util/7z/makefile.gcc b/3rdparty/lzma/C/Util/7z/makefile.gcc index 51053bad65c..f48d36211d0 100644 --- a/3rdparty/lzma/C/Util/7z/makefile.gcc +++ b/3rdparty/lzma/C/Util/7z/makefile.gcc @@ -1,75 +1,32 @@ -PROG = 7zDec -CXX = gcc -LIB = -RM = rm -f -CFLAGS = -c -O2 -Wall - -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 - -all: $(PROG) - -$(PROG): $(OBJS) - $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) - -7zMain.o: 7zMain.c - $(CXX) $(CFLAGS) 7zMain.c - -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) +PROG = 7zdec + +LOCAL_FLAGS = -DZ7_PPMD_SUPPORT -DZ7_EXTRACT_ONLY + +include ../../../CPP/7zip/LzmaDec_gcc.mak + + +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/7zAlloc.o \ + $O/7zArcIn.o \ + $O/7zBuf.o \ + $O/7zBuf2.o \ + $O/7zDec.o \ + $O/7zMain.o \ + $O/7zFile.o \ + $O/7zStream.o \ + + +include ../../7zip_gcc_c.mak diff --git a/3rdparty/lzma/C/Util/Lzma/LzmaUtil.c b/3rdparty/lzma/C/Util/Lzma/LzmaUtil.c index e5857ceff09..b9b974bd1bb 100644 --- a/3rdparty/lzma/C/Util/Lzma/LzmaUtil.c +++ b/3rdparty/lzma/C/Util/Lzma/LzmaUtil.c @@ -1,57 +1,111 @@ /* LzmaUtil.c -- Test application for LZMA compression -2015-11-08 : Igor Pavlov : Public domain */ +2023-03-07 : Igor Pavlov : Public domain */ -#include "../../Precomp.h" +#include "Precomp.h" #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "../../CpuArch.h" + #include "../../Alloc.h" #include "../../7zFile.h" #include "../../7zVersion.h" +#include "../../LzFind.h" #include "../../LzmaDec.h" #include "../../LzmaEnc.h" -const char *kCantReadMessage = "Can not read input file"; -const char *kCantWriteMessage = "Can not write output file"; -const char *kCantAllocateMessage = "Can not allocate memory"; -const char *kDataErrorMessage = "Data error"; +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"; -void PrintHelp(char *buffer) +static void Print(const char *s) { - strcat(buffer, "\nLZMA Utility " MY_VERSION_COPYRIGHT_DATE "\n" - "\nUsage: lzma <e|d> inputFile outputFile\n" - " e: encode file\n" - " d: decode file\n"); + fputs(s, stdout); } -int PrintError(char *buffer, const char *message) +static void PrintHelp(void) +{ + Print( + "\n" "LZMA-C " MY_VERSION_CPU " : " MY_COPYRIGHT_DATE + "\n" + "\n" "Usage: lzma <e|d> inputFile outputFile" + "\n" " e: encode file" + "\n" " d: decode file" + "\n"); +} + +static int PrintError(const char *message) +{ + Print("\nError: "); + Print(message); + Print("\n"); + return 1; +} + +#define CONVERT_INT_TO_STR(charType, tempSize) \ + unsigned char temp[tempSize]; unsigned i = 0; \ + while (val >= 10) { temp[i++] = (unsigned char)('0' + (unsigned)(val % 10)); val /= 10; } \ + *s++ = (charType)('0' + (unsigned)val); \ + while (i != 0) { i--; *s++ = (charType)temp[i]; } \ + *s = 0; \ + return s; + +static char * Convert_unsigned_To_str(unsigned val, char *s) { - strcat(buffer, "\nError: "); - strcat(buffer, message); - strcat(buffer, "\n"); + CONVERT_INT_TO_STR(char, 32) +} + +static void Print_unsigned(unsigned code) +{ + char str[32]; + Convert_unsigned_To_str(code, str); + Print(str); +} + +static int PrintError_WRes(const char *message, WRes wres) +{ + PrintError(message); + Print("\nSystem error code: "); + Print_unsigned((unsigned)wres); + #ifndef _WIN32 + { + const char *s = strerror(wres); + if (s) + { + Print(" : "); + Print(s); + } + } + #endif + Print("\n"); return 1; } -int PrintErrorNumber(char *buffer, SRes val) +static int PrintErrorNumber(SRes val) { - sprintf(buffer + strlen(buffer), "\nError code: %x\n", (unsigned)val); + Print("\n7-Zip error code: "); + Print_unsigned((unsigned)val); + Print("\n"); return 1; } -int PrintUserError(char *buffer) +static int PrintUserError(void) { - return PrintError(buffer, "Incorrect command"); + return PrintError("Incorrect command"); } + #define IN_BUF_SIZE (1 << 16) #define OUT_BUF_SIZE (1 << 16) -static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream, + +static SRes Decode2(CLzmaDec *state, ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, UInt64 unpackSize) { - int thereIsSize = (unpackSize != (UInt64)(Int64)-1); + const int thereIsSize = (unpackSize != (UInt64)(Int64)-1); Byte inBuf[IN_BUF_SIZE]; Byte outBuf[OUT_BUF_SIZE]; size_t inPos = 0, inSize = 0, outPos = 0; @@ -61,7 +115,7 @@ static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inS if (inPos == inSize) { inSize = IN_BUF_SIZE; - RINOK(inStream->Read(inStream, inBuf, &inSize)); + RINOK(inStream->Read(inStream, inBuf, &inSize)) inPos = 0; } { @@ -101,7 +155,8 @@ static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inS } } -static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream) + +static SRes Decode(ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream) { UInt64 unpackSize; int i; @@ -114,27 +169,29 @@ static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream) /* Read and parse header */ - RINOK(SeqInStream_Read(inStream, header, sizeof(header))); - + { + size_t size = sizeof(header); + RINOK(SeqInStream_ReadMax(inStream, header, &size)) + if (size != sizeof(header)) + return SZ_ERROR_INPUT_EOF; + } unpackSize = 0; for (i = 0; i < 8; i++) unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8); - LzmaDec_Construct(&state); - RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc)); + LzmaDec_CONSTRUCT(&state) + RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc)) res = Decode2(&state, outStream, inStream, unpackSize); LzmaDec_Free(&state, &g_Alloc); return res; } -static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs) +static SRes Encode(ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, UInt64 fileSize) { CLzmaEncHandle enc; SRes res; CLzmaEncProps props; - UNUSED_VAR(rs); - enc = LzmaEnc_Create(&g_Alloc); if (enc == 0) return SZ_ERROR_MEM; @@ -163,63 +220,77 @@ static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 file return res; } -int main2(int numArgs, const char *args[], char *rs) + +int Z7_CDECL main(int numArgs, const char *args[]) { CFileSeqInStream inStream; CFileOutStream outStream; char c; int res; int encodeMode; - Bool useOutFile = False; + BoolInt useOutFile = False; + + LzFindPrepare(); FileSeqInStream_CreateVTable(&inStream); File_Construct(&inStream.file); + inStream.wres = 0; FileOutStream_CreateVTable(&outStream); File_Construct(&outStream.file); + outStream.wres = 0; if (numArgs == 1) { - PrintHelp(rs); + PrintHelp(); return 0; } if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1) - return PrintUserError(rs); + return PrintUserError(); c = args[1][0]; encodeMode = (c == 'e' || c == 'E'); if (!encodeMode && c != 'd' && c != 'D') - return PrintUserError(rs); + return PrintUserError(); + /* { size_t t4 = sizeof(UInt32); size_t t8 = sizeof(UInt64); if (t4 != 4 || t8 != 8) - return PrintError(rs, "Incorrect UInt32 or UInt64"); + return PrintError("Incorrect UInt32 or UInt64"); } + */ - if (InFile_Open(&inStream.file, args[2]) != 0) - return PrintError(rs, "Can not open input file"); + { + const WRes wres = InFile_Open(&inStream.file, args[2]); + if (wres != 0) + return PrintError_WRes("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("Cannot open output file", wres); } else if (encodeMode) - PrintUserError(rs); + PrintUserError(); if (encodeMode) { UInt64 fileSize; - File_GetLength(&inStream.file, &fileSize); - res = Encode(&outStream.s, &inStream.s, fileSize, rs); + const WRes wres = File_GetLength(&inStream.file, &fileSize); + if (wres != 0) + return PrintError_WRes("Cannot get file length", wres); + res = Encode(&outStream.vt, &inStream.vt, fileSize); } else { - res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL); + res = Decode(&outStream.vt, useOutFile ? &inStream.vt : NULL); } if (useOutFile) @@ -229,22 +300,14 @@ int main2(int numArgs, const char *args[], char *rs) if (res != SZ_OK) { if (res == SZ_ERROR_MEM) - return PrintError(rs, kCantAllocateMessage); + return PrintError(kCantAllocateMessage); else if (res == SZ_ERROR_DATA) - return PrintError(rs, kDataErrorMessage); + return PrintError(kDataErrorMessage); else if (res == SZ_ERROR_WRITE) - return PrintError(rs, kCantWriteMessage); + return PrintError_WRes(kCantWriteMessage, outStream.wres); else if (res == SZ_ERROR_READ) - return PrintError(rs, kCantReadMessage); - return PrintErrorNumber(rs, res); + return PrintError_WRes(kCantReadMessage, inStream.wres); + return PrintErrorNumber(res); } return 0; } - -int MY_CDECL main(int numArgs, const char *args[]) -{ - char rs[800] = { 0 }; - int res = main2(numArgs, args, rs); - fputs(rs, stdout); - return res; -} diff --git a/3rdparty/lzma/C/Util/Lzma/LzmaUtil.dsp b/3rdparty/lzma/C/Util/Lzma/LzmaUtil.dsp index 43b8e176b22..e2e7d428296 100644 --- a/3rdparty/lzma/C/Util/Lzma/LzmaUtil.dsp +++ b/3rdparty/lzma/C/Util/Lzma/LzmaUtil.dsp @@ -98,10 +98,18 @@ SOURCE=..\..\7zStream.c # End Source File # Begin Source File +SOURCE=..\..\7zTypes.h +# End Source File +# Begin Source File + SOURCE=..\..\7zVersion.h # End Source File # Begin Source File +SOURCE=..\..\7zWindows.h +# End Source File +# Begin Source File + SOURCE=..\..\Alloc.c # End Source File # Begin Source File @@ -110,6 +118,10 @@ SOURCE=..\..\Alloc.h # End Source File # Begin Source File +SOURCE=..\..\Compiler.h +# End Source File +# Begin Source File + SOURCE=..\..\CpuArch.h # End Source File # Begin Source File @@ -130,6 +142,10 @@ SOURCE=..\..\LzFindMt.h # End Source File # Begin Source File +SOURCE=..\..\LzFindOpt.c +# End Source File +# Begin Source File + SOURCE=..\..\LzHash.h # End Source File # Begin Source File @@ -154,15 +170,19 @@ SOURCE=.\LzmaUtil.c # End Source File # Begin Source File -SOURCE=..\..\Threads.c +SOURCE=..\..\Precomp.h # End Source File # Begin Source File -SOURCE=..\..\Threads.h +SOURCE=.\Precomp.h # End Source File # Begin Source File -SOURCE=..\..\Types.h +SOURCE=..\..\Threads.c +# End Source File +# Begin Source File + +SOURCE=..\..\Threads.h # End Source File # End Target # End Project diff --git a/3rdparty/lzma/C/Util/Lzma/Precomp.h b/3rdparty/lzma/C/Util/Lzma/Precomp.h new file mode 100644 index 00000000000..bc8fa219b58 --- /dev/null +++ b/3rdparty/lzma/C/Util/Lzma/Precomp.h @@ -0,0 +1,14 @@ +/* Precomp.h -- StdAfx +2023-03-04 : Igor Pavlov : Public domain */ + +#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 diff --git a/3rdparty/lzma/C/Util/Lzma/makefile b/3rdparty/lzma/C/Util/Lzma/makefile index 4795322786b..7813bdb059d 100644 --- a/3rdparty/lzma/C/Util/Lzma/makefile +++ b/3rdparty/lzma/C/Util/Lzma/makefile @@ -8,8 +8,10 @@ LIB_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\CpuArch.obj \ $O\LzFind.obj \ $O\LzFindMt.obj \ + $O\LzFindOpt.obj \ $O\LzmaDec.obj \ $O\LzmaEnc.obj \ $O\7zFile.obj \ diff --git a/3rdparty/lzma/C/Util/Lzma/makefile.gcc b/3rdparty/lzma/C/Util/Lzma/makefile.gcc index 67aa8b17957..2acb0b808d2 100644 --- a/3rdparty/lzma/C/Util/Lzma/makefile.gcc +++ b/3rdparty/lzma/C/Util/Lzma/makefile.gcc @@ -1,44 +1,21 @@ -PROG = lzma -CXX = g++ -LIB = -RM = rm -f -CFLAGS = -c -O2 -Wall -D_7ZIP_ST +PROG = 7lzma -OBJS = \ - LzmaUtil.o \ - Alloc.o \ - LzFind.o \ - LzmaDec.o \ - LzmaEnc.o \ - 7zFile.o \ - 7zStream.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 +include ../../../CPP/7zip/LzmaDec_gcc.mak -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) +OBJS = \ + $(LZMA_DEC_OPT_OBJS) \ + $O/7zFile.o \ + $O/7zStream.o \ + $O/Alloc.o \ + $O/CpuArch.o \ + $O/LzFind.o \ + $O/LzFindMt.o \ + $O/LzFindOpt.o \ + $O/LzmaDec.o \ + $O/LzmaEnc.o \ + $O/LzmaUtil.o \ + $O/Threads.o \ + + +include ../../7zip_gcc_c.mak diff --git a/3rdparty/lzma/C/Util/LzmaLib/LzmaLib.dsp b/3rdparty/lzma/C/Util/LzmaLib/LzmaLib.dsp index 3421de83a1d..bacd9679324 100644 --- a/3rdparty/lzma/C/Util/LzmaLib/LzmaLib.dsp +++ b/3rdparty/lzma/C/Util/LzmaLib/LzmaLib.dsp @@ -101,6 +101,10 @@ SOURCE=.\LzmaLib.def SOURCE=.\LzmaLibExports.c # End Source File +# Begin Source File + +SOURCE=.\Precomp.h +# End Source File # End Group # Begin Source File @@ -108,6 +112,10 @@ SOURCE=..\..\7zTypes.h # End Source File # Begin Source File +SOURCE=..\..\7zWindows.h +# End Source File +# Begin Source File + SOURCE=..\..\Alloc.c # End Source File # Begin Source File @@ -116,6 +124,14 @@ SOURCE=..\..\Alloc.h # End Source File # Begin Source File +SOURCE=..\..\Compiler.h +# End Source File +# Begin Source File + +SOURCE=..\..\CpuArch.h +# End Source File +# Begin Source File + SOURCE=..\..\IStream.h # End Source File # Begin Source File @@ -136,6 +152,10 @@ SOURCE=..\..\LzFindMt.h # End Source File # Begin Source File +SOURCE=..\..\LzFindOpt.c +# End Source File +# Begin Source File + SOURCE=..\..\LzHash.h # End Source File # Begin Source File @@ -164,6 +184,10 @@ SOURCE=..\..\LzmaLib.h # End Source File # Begin Source File +SOURCE=..\..\Precomp.h +# End Source File +# Begin Source File + SOURCE=.\resource.rc # End Source File # Begin Source File diff --git a/3rdparty/lzma/C/Util/LzmaLib/LzmaLibExports.c b/3rdparty/lzma/C/Util/LzmaLib/LzmaLibExports.c index 4a28a9a6b34..a46c9a80732 100644 --- a/3rdparty/lzma/C/Util/LzmaLib/LzmaLibExports.c +++ b/3rdparty/lzma/C/Util/LzmaLib/LzmaLibExports.c @@ -1,14 +1,15 @@ /* LzmaLibExports.c -- LZMA library DLL Entry point -2015-11-08 : Igor Pavlov : Public domain */ +2023-03-05 : Igor Pavlov : Public domain */ -#include "../../Precomp.h" +#include "Precomp.h" -#include <windows.h> +#include "../../7zWindows.h" +BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved); BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { - UNUSED_VAR(hInstance); - UNUSED_VAR(dwReason); - UNUSED_VAR(lpReserved); + UNUSED_VAR(hInstance) + UNUSED_VAR(dwReason) + UNUSED_VAR(lpReserved) return TRUE; } diff --git a/3rdparty/lzma/C/Util/LzmaLib/Precomp.c b/3rdparty/lzma/C/Util/LzmaLib/Precomp.c new file mode 100644 index 00000000000..01605e3c261 --- /dev/null +++ b/3rdparty/lzma/C/Util/LzmaLib/Precomp.c @@ -0,0 +1,4 @@ +/* Precomp.c -- StdAfx +2013-01-21 : Igor Pavlov : Public domain */ + +#include "Precomp.h" diff --git a/3rdparty/lzma/C/Util/LzmaLib/Precomp.h b/3rdparty/lzma/C/Util/LzmaLib/Precomp.h new file mode 100644 index 00000000000..bc8fa219b58 --- /dev/null +++ b/3rdparty/lzma/C/Util/LzmaLib/Precomp.h @@ -0,0 +1,14 @@ +/* Precomp.h -- StdAfx +2023-03-04 : Igor Pavlov : Public domain */ + +#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 diff --git a/3rdparty/lzma/C/Util/LzmaLib/makefile b/3rdparty/lzma/C/Util/LzmaLib/makefile index 74103bb0540..b8e054efca3 100644 --- a/3rdparty/lzma/C/Util/LzmaLib/makefile +++ b/3rdparty/lzma/C/Util/LzmaLib/makefile @@ -11,14 +11,17 @@ LIB_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\CpuArch.obj \ $O\LzFind.obj \ $O\LzFindMt.obj \ + $O\LzFindOpt.obj \ $O\LzmaDec.obj \ $O\LzmaEnc.obj \ $O\LzmaLib.obj \ $O\Threads.obj \ OBJS = \ + $O\Precomp.obj \ $(LIB_OBJS) \ $(C_OBJS) \ $O\resource.res @@ -28,7 +31,24 @@ OBJS = \ $(SLIBPATH): $O $(OBJS) lib -out:$(SLIBPATH) $(OBJS) $(LIBS) + +MAK_SINGLE_FILE = 1 + +$O\Precomp.obj: Precomp.c + $(CCOMPL_PCH) + +!IFDEF MAK_SINGLE_FILE + $(LIB_OBJS): $(*B).c - $(COMPL_O2) + $(CCOMPL_USE) $(C_OBJS): ../../$(*B).c - $(COMPL_O2) + $(CCOMPL_USE) + +!ELSE + +{.}.c{$O}.obj:: + $(CCOMPLB_USE) +{../../../C}.c{$O}.obj:: + $(CCOMPLB_USE) + +!ENDIF diff --git a/3rdparty/lzma/C/Util/SfxSetup/Precomp.h b/3rdparty/lzma/C/Util/SfxSetup/Precomp.h index 588a66f7eb8..bc8fa219b58 100644 --- a/3rdparty/lzma/C/Util/SfxSetup/Precomp.h +++ b/3rdparty/lzma/C/Util/SfxSetup/Precomp.h @@ -1,8 +1,12 @@ /* Precomp.h -- StdAfx -2013-06-16 : 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" diff --git a/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c b/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c index 57e73d86528..7304a0be40d 100644 --- a/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c +++ b/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c @@ -1,5 +1,5 @@ /* SfxSetup.c - 7z SFX Setup -2016-05-16 : Igor Pavlov : Public domain */ +2019-02-02 : Igor Pavlov : Public domain */ #include "Precomp.h" @@ -24,6 +24,14 @@ #define k_EXE_ExtIndex 2 +#define kInputBufSize ((size_t)1 << 18) + + +#define wcscat lstrcatW +#define wcslen (size_t)lstrlenW +#define wcscpy lstrcpyW +// wcsncpy() and lstrcpynW() work differently. We don't use them. + static const char * const kExts[] = { "bat" @@ -62,7 +70,7 @@ static unsigned FindExt(const wchar_t *s, unsigned *extLen) return len; } -#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 unsigned FindItem(const char * const *items, unsigned num, const wchar_t *s, unsigned len) { @@ -70,13 +78,13 @@ static unsigned FindItem(const char * const *items, unsigned num, const wchar_t for (i = 0; i < num; i++) { const char *item = items[i]; - unsigned itemLen = (unsigned)strlen(item); + const unsigned itemLen = (unsigned)strlen(item); unsigned j; if (len != itemLen) continue; for (j = 0; j < len; j++) { - unsigned c = (Byte)item[j]; + const unsigned c = (Byte)item[j]; if (c != s[j] && MAKE_CHAR_UPPER(c) != s[j]) break; } @@ -94,10 +102,20 @@ static BOOL WINAPI HandlerRoutine(DWORD ctrlType) } #endif + +#ifdef _CONSOLE +static void PrintStr(const char *s) +{ + fputs(s, stdout); +} +#endif + static void PrintErrorMessage(const char *message) { #ifdef _CONSOLE - printf("\n7-Zip Error: %s\n", message); + PrintStr("\n7-Zip Error: "); + PrintStr(message); + PrintStr("\n"); #else #ifdef UNDER_CE WCHAR messageW[256 + 4]; @@ -125,7 +143,7 @@ static WRes MyCreateDir(const WCHAR *name) #define kSignatureSearchLimit (1 << 22) -static Bool FindSignature(CSzFile *stream, UInt64 *resPos) +static BoolInt FindSignature(CSzFile *stream, UInt64 *resPos) { Byte buf[kBufferSize]; size_t numPrevBytes = 0; @@ -161,7 +179,7 @@ static Bool FindSignature(CSzFile *stream, UInt64 *resPos) } } -static Bool DoesFileOrDirExist(const WCHAR *path) +static BoolInt DoesFileOrDirExist(const WCHAR *path) { WIN32_FIND_DATAW fd; HANDLE handle; @@ -177,7 +195,7 @@ static WRes RemoveDirWithSubItems(WCHAR *path) WIN32_FIND_DATAW fd; HANDLE handle; WRes res = 0; - size_t len = wcslen(path); + const size_t len = wcslen(path); wcscpy(path + len, L"*"); handle = FindFirstFileW(path, &fd); path[len] = L'\0'; @@ -226,7 +244,7 @@ static WRes RemoveDirWithSubItems(WCHAR *path) } #ifdef _CONSOLE -int MY_CDECL main() +int Z7_CDECL main(void) #else int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, #ifdef UNDER_CE @@ -238,7 +256,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, #endif { CFileInStream archiveStream; - CLookToRead lookStream; + CLookToRead2 lookStream; CSzArEx db; SRes res = SZ_OK; ISzAlloc allocImp; @@ -252,7 +270,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, DWORD winRes; const wchar_t *cmdLineParams; const char *errorMessage = NULL; - Bool useShellExecute = True; + BoolInt useShellExecute = True; DWORD exitCode = 0; LoadSecurityDlls(); @@ -275,7 +293,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, allocTempImp.Free = SzFreeTemp; FileInStream_CreateVTable(&archiveStream); - LookToRead_CreateVTable(&lookStream, False); + LookToRead2_CreateVTable(&lookStream, False); + lookStream.buf = NULL; winRes = GetModuleFileNameW(NULL, sfxPath, MAX_PATH); if (winRes == 0 || winRes > MAX_PATH) @@ -284,10 +303,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, cmdLineParams = GetCommandLineW(); #ifndef UNDER_CE { - Bool quoteMode = False; + BoolInt quoteMode = False; for (;; cmdLineParams++) { - wchar_t c = *cmdLineParams; + const wchar_t c = *cmdLineParams; if (c == L'\"') quoteMode = !quoteMode; else if (c == 0 || (c == L' ' && !quoteMode)) @@ -321,7 +340,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, unsigned k; for (k = 0; k < 8; k++) { - unsigned t = value & 0xF; + const unsigned t = value & 0xF; value >>= 4; s[7 - k] = (wchar_t)((t < 10) ? ('0' + t) : ('A' + (t - 10))); } @@ -376,14 +395,22 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if (res == SZ_OK) { - lookStream.realStream = &archiveStream.s; - LookToRead_Init(&lookStream); + lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize); + if (!lookStream.buf) + res = SZ_ERROR_MEM; + else + { + lookStream.bufSize = kInputBufSize; + lookStream.realStream = &archiveStream.vt; + LookToRead2_INIT(&lookStream) + } } SzArEx_Init(&db); + if (res == SZ_OK) { - res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp); + res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp); } if (res == SZ_OK) @@ -409,9 +436,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, temp = path + pathLen; - SzArEx_GetFileNameUtf16(&db, i, temp); + SzArEx_GetFileNameUtf16(&db, i, (UInt16 *)temp); { - res = SzArEx_Extract(&db, &lookStream.s, i, + res = SzArEx_Extract(&db, &lookStream.vt, i, &blockIndex, &outBuffer, &outBufferSize, &offset, &outSizeProcessed, &allocImp, &allocTempImp); @@ -444,11 +471,11 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, unsigned extLen; const WCHAR *name = temp + nameStartPos; unsigned len = (unsigned)wcslen(name); - unsigned nameLen = FindExt(temp + nameStartPos, &extLen); - unsigned extPrice = FindItem(kExts, sizeof(kExts) / sizeof(kExts[0]), name + len - extLen, extLen); - unsigned namePrice = FindItem(kNames, sizeof(kNames) / sizeof(kNames[0]), name, nameLen); + const unsigned nameLen = FindExt(temp + nameStartPos, &extLen); + const unsigned extPrice = FindItem(kExts, sizeof(kExts) / sizeof(kExts[0]), name + len - extLen, extLen); + const unsigned namePrice = FindItem(kNames, sizeof(kNames) / sizeof(kNames[0]), name, nameLen); - unsigned price = namePrice + extPrice * 64 + (nameStartPos == 0 ? 0 : (1 << 12)); + const unsigned price = namePrice + extPrice * 64 + (nameStartPos == 0 ? 0 : (1 << 12)); if (minPrice > price) { minPrice = price; @@ -489,7 +516,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, #endif { - SRes res2 = File_Close(&outFile); + const SRes res2 = File_Close(&outFile); if (res != SZ_OK) break; if (res2 != SZ_OK) @@ -516,16 +543,19 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, { WCHAR *temp = path + pathLen; UInt32 j; - SzArEx_GetFileNameUtf16(&db, executeFileIndex, temp); + SzArEx_GetFileNameUtf16(&db, executeFileIndex, (UInt16 *)temp); for (j = 0; temp[j] != 0; j++) if (temp[j] == '/') temp[j] = CHAR_PATH_SEPARATOR; } } - IAlloc_Free(&allocImp, outBuffer); + ISzAlloc_Free(&allocImp, outBuffer); } + SzArEx_Free(&db, &allocImp); + ISzAlloc_Free(&allocImp, lookStream.buf); + File_Close(&archiveStream.file); if (res == SZ_OK) @@ -536,7 +566,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WCHAR oldCurDir[MAX_PATH + 2]; oldCurDir[0] = 0; { - DWORD needLen = GetCurrentDirectory(MAX_PATH + 1, oldCurDir); + const DWORD needLen = GetCurrentDirectory(MAX_PATH + 1, oldCurDir); if (needLen == 0 || needLen > MAX_PATH) oldCurDir[0] = 0; SetCurrentDirectory(workCurDir); diff --git a/3rdparty/lzma/C/Util/SfxSetup/makefile b/3rdparty/lzma/C/Util/SfxSetup/makefile index 76cd9112464..bc0cf8bc71c 100644 --- a/3rdparty/lzma/C/Util/SfxSetup/makefile +++ b/3rdparty/lzma/C/Util/SfxSetup/makefile @@ -1,4 +1,8 @@ PROG = 7zS2.sfx +MY_FIXED = 1 + +CFLAGS = $(CFLAGS) \ + -DZ7_EXTRACT_ONLY \ C_OBJS = \ $O\7zAlloc.obj \ diff --git a/3rdparty/lzma/C/Util/SfxSetup/makefile_con b/3rdparty/lzma/C/Util/SfxSetup/makefile_con index ed9174d3b20..9f4b91669ca 100644 --- a/3rdparty/lzma/C/Util/SfxSetup/makefile_con +++ b/3rdparty/lzma/C/Util/SfxSetup/makefile_con @@ -1,5 +1,8 @@ PROG = 7zS2con.sfx -CFLAGS = $(CFLAGS) -D_CONSOLE +MY_FIXED = 1 + +CFLAGS = $(CFLAGS) -D_CONSOLE \ + -DZ7_EXTRACT_ONLY \ C_OBJS = \ $O\7zAlloc.obj \ |