diff options
Diffstat (limited to '')
47 files changed, 6554 insertions, 0 deletions
diff --git a/C/Util/7z/7z.dsp b/C/Util/7z/7z.dsp new file mode 100644 index 0000000..be0f0a7 --- /dev/null +++ b/C/Util/7z/7z.dsp | |||
| @@ -0,0 +1,241 @@ | |||
| 1 | # Microsoft Developer Studio Project File - Name="7z" - Package Owner=<4> | ||
| 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 | ||
| 3 | # ** DO NOT EDIT ** | ||
| 4 | |||
| 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 | ||
| 6 | |||
| 7 | CFG=7z - Win32 Debug | ||
| 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, | ||
| 9 | !MESSAGE use the Export Makefile command and run | ||
| 10 | !MESSAGE | ||
| 11 | !MESSAGE NMAKE /f "7z.mak". | ||
| 12 | !MESSAGE | ||
| 13 | !MESSAGE You can specify a configuration when running NMAKE | ||
| 14 | !MESSAGE by defining the macro CFG on the command line. For example: | ||
| 15 | !MESSAGE | ||
| 16 | !MESSAGE NMAKE /f "7z.mak" CFG="7z - Win32 Debug" | ||
| 17 | !MESSAGE | ||
| 18 | !MESSAGE Possible choices for configuration are: | ||
| 19 | !MESSAGE | ||
| 20 | !MESSAGE "7z - Win32 Release" (based on "Win32 (x86) Console Application") | ||
| 21 | !MESSAGE "7z - Win32 Debug" (based on "Win32 (x86) Console Application") | ||
| 22 | !MESSAGE | ||
| 23 | |||
| 24 | # Begin Project | ||
| 25 | # PROP AllowPerConfigDependencies 0 | ||
| 26 | # PROP Scc_ProjName "" | ||
| 27 | # PROP Scc_LocalPath "" | ||
| 28 | CPP=cl.exe | ||
| 29 | RSC=rc.exe | ||
| 30 | |||
| 31 | !IF "$(CFG)" == "7z - Win32 Release" | ||
| 32 | |||
| 33 | # PROP BASE Use_MFC 0 | ||
| 34 | # PROP BASE Use_Debug_Libraries 0 | ||
| 35 | # PROP BASE Output_Dir "Release" | ||
| 36 | # PROP BASE Intermediate_Dir "Release" | ||
| 37 | # PROP BASE Target_Dir "" | ||
| 38 | # PROP Use_MFC 0 | ||
| 39 | # PROP Use_Debug_Libraries 0 | ||
| 40 | # PROP Output_Dir "Release" | ||
| 41 | # PROP Intermediate_Dir "Release" | ||
| 42 | # PROP Ignore_Export_Lib 0 | ||
| 43 | # PROP Target_Dir "" | ||
| 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c | ||
| 45 | # ADD CPP /nologo /MD /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FAcs /Yu"Precomp.h" /FD /c | ||
| 46 | # ADD BASE RSC /l 0x419 /d "NDEBUG" | ||
| 47 | # ADD RSC /l 0x419 /d "NDEBUG" | ||
| 48 | BSC32=bscmake.exe | ||
| 49 | # ADD BASE BSC32 /nologo | ||
| 50 | # ADD BSC32 /nologo | ||
| 51 | LINK32=link.exe | ||
| 52 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 | ||
| 53 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\util\7zDec.exe" /opt:NOWIN98 | ||
| 54 | # SUBTRACT LINK32 /pdb:none | ||
| 55 | |||
| 56 | !ELSEIF "$(CFG)" == "7z - Win32 Debug" | ||
| 57 | |||
| 58 | # PROP BASE Use_MFC 0 | ||
| 59 | # PROP BASE Use_Debug_Libraries 1 | ||
| 60 | # PROP BASE Output_Dir "Debug" | ||
| 61 | # PROP BASE Intermediate_Dir "Debug" | ||
| 62 | # PROP BASE Target_Dir "" | ||
| 63 | # PROP Use_MFC 0 | ||
| 64 | # PROP Use_Debug_Libraries 1 | ||
| 65 | # PROP Output_Dir "Debug" | ||
| 66 | # PROP Intermediate_Dir "Debug" | ||
| 67 | # PROP Ignore_Export_Lib 0 | ||
| 68 | # PROP Target_Dir "" | ||
| 69 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c | ||
| 70 | # 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 | ||
| 71 | # ADD BASE RSC /l 0x419 /d "_DEBUG" | ||
| 72 | # ADD RSC /l 0x419 /d "_DEBUG" | ||
| 73 | BSC32=bscmake.exe | ||
| 74 | # ADD BASE BSC32 /nologo | ||
| 75 | # ADD BSC32 /nologo | ||
| 76 | LINK32=link.exe | ||
| 77 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept | ||
| 78 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\util\7zDec.exe" /pdbtype:sept | ||
| 79 | |||
| 80 | !ENDIF | ||
| 81 | |||
| 82 | # Begin Target | ||
| 83 | |||
| 84 | # Name "7z - Win32 Release" | ||
| 85 | # Name "7z - Win32 Debug" | ||
| 86 | # Begin Group "Common" | ||
| 87 | |||
| 88 | # PROP Default_Filter "" | ||
| 89 | # Begin Source File | ||
| 90 | |||
| 91 | SOURCE=..\..\7z.h | ||
| 92 | # End Source File | ||
| 93 | # Begin Source File | ||
| 94 | |||
| 95 | SOURCE=..\..\7zAlloc.c | ||
| 96 | # End Source File | ||
| 97 | # Begin Source File | ||
| 98 | |||
| 99 | SOURCE=..\..\7zAlloc.h | ||
| 100 | # End Source File | ||
| 101 | # Begin Source File | ||
| 102 | |||
| 103 | SOURCE=..\..\7zArcIn.c | ||
| 104 | # End Source File | ||
| 105 | # Begin Source File | ||
| 106 | |||
| 107 | SOURCE=..\..\7zBuf.c | ||
| 108 | # End Source File | ||
| 109 | # Begin Source File | ||
| 110 | |||
| 111 | SOURCE=..\..\7zBuf.h | ||
| 112 | # End Source File | ||
| 113 | # Begin Source File | ||
| 114 | |||
| 115 | SOURCE=..\..\7zCrc.c | ||
| 116 | # End Source File | ||
| 117 | # Begin Source File | ||
| 118 | |||
| 119 | SOURCE=..\..\7zCrc.h | ||
| 120 | # End Source File | ||
| 121 | # Begin Source File | ||
| 122 | |||
| 123 | SOURCE=..\..\7zCrcOpt.c | ||
| 124 | # End Source File | ||
| 125 | # Begin Source File | ||
| 126 | |||
| 127 | SOURCE=..\..\7zDec.c | ||
| 128 | # ADD CPP /D "_7ZIP_PPMD_SUPPPORT" | ||
| 129 | # End Source File | ||
| 130 | # Begin Source File | ||
| 131 | |||
| 132 | SOURCE=..\..\7zFile.c | ||
| 133 | # End Source File | ||
| 134 | # Begin Source File | ||
| 135 | |||
| 136 | SOURCE=..\..\7zFile.h | ||
| 137 | # End Source File | ||
| 138 | # Begin Source File | ||
| 139 | |||
| 140 | SOURCE=..\..\7zStream.c | ||
| 141 | # End Source File | ||
| 142 | # Begin Source File | ||
| 143 | |||
| 144 | SOURCE=..\..\7zTypes.h | ||
| 145 | # End Source File | ||
| 146 | # Begin Source File | ||
| 147 | |||
| 148 | SOURCE=..\..\Bcj2.c | ||
| 149 | # End Source File | ||
| 150 | # Begin Source File | ||
| 151 | |||
| 152 | SOURCE=..\..\Bcj2.h | ||
| 153 | # End Source File | ||
| 154 | # Begin Source File | ||
| 155 | |||
| 156 | SOURCE=..\..\Bra.c | ||
| 157 | # End Source File | ||
| 158 | # Begin Source File | ||
| 159 | |||
| 160 | SOURCE=..\..\Bra.h | ||
| 161 | # End Source File | ||
| 162 | # Begin Source File | ||
| 163 | |||
| 164 | SOURCE=..\..\Bra86.c | ||
| 165 | # End Source File | ||
| 166 | # Begin Source File | ||
| 167 | |||
| 168 | SOURCE=..\..\BraIA64.c | ||
| 169 | # End Source File | ||
| 170 | # Begin Source File | ||
| 171 | |||
| 172 | SOURCE=..\..\CpuArch.c | ||
| 173 | # End Source File | ||
| 174 | # Begin Source File | ||
| 175 | |||
| 176 | SOURCE=..\..\CpuArch.h | ||
| 177 | # End Source File | ||
| 178 | # Begin Source File | ||
| 179 | |||
| 180 | SOURCE=..\..\Delta.c | ||
| 181 | # End Source File | ||
| 182 | # Begin Source File | ||
| 183 | |||
| 184 | SOURCE=..\..\Delta.h | ||
| 185 | # End Source File | ||
| 186 | # Begin Source File | ||
| 187 | |||
| 188 | SOURCE=..\..\Lzma2Dec.c | ||
| 189 | # End Source File | ||
| 190 | # Begin Source File | ||
| 191 | |||
| 192 | SOURCE=..\..\Lzma2Dec.h | ||
| 193 | # End Source File | ||
| 194 | # Begin Source File | ||
| 195 | |||
| 196 | SOURCE=..\..\LzmaDec.c | ||
| 197 | # End Source File | ||
| 198 | # Begin Source File | ||
| 199 | |||
| 200 | SOURCE=..\..\LzmaDec.h | ||
| 201 | # End Source File | ||
| 202 | # Begin Source File | ||
| 203 | |||
| 204 | SOURCE=..\..\Ppmd.h | ||
| 205 | # End Source File | ||
| 206 | # Begin Source File | ||
| 207 | |||
| 208 | SOURCE=..\..\Ppmd7.c | ||
| 209 | # End Source File | ||
| 210 | # Begin Source File | ||
| 211 | |||
| 212 | SOURCE=..\..\Ppmd7.h | ||
| 213 | # End Source File | ||
| 214 | # Begin Source File | ||
| 215 | |||
| 216 | SOURCE=..\..\Ppmd7Dec.c | ||
| 217 | # End Source File | ||
| 218 | # End Group | ||
| 219 | # Begin Group "Spec" | ||
| 220 | |||
| 221 | # PROP Default_Filter "" | ||
| 222 | # Begin Source File | ||
| 223 | |||
| 224 | SOURCE=..\..\Compiler.h | ||
| 225 | # End Source File | ||
| 226 | # Begin Source File | ||
| 227 | |||
| 228 | SOURCE=.\Precomp.c | ||
| 229 | # ADD CPP /Yc"Precomp.h" | ||
| 230 | # End Source File | ||
| 231 | # Begin Source File | ||
| 232 | |||
| 233 | SOURCE=.\Precomp.h | ||
| 234 | # End Source File | ||
| 235 | # End Group | ||
| 236 | # Begin Source File | ||
| 237 | |||
| 238 | SOURCE=.\7zMain.c | ||
| 239 | # End Source File | ||
| 240 | # End Target | ||
| 241 | # End Project | ||
diff --git a/C/Util/7z/7z.dsw b/C/Util/7z/7z.dsw new file mode 100644 index 0000000..848d13c --- /dev/null +++ b/C/Util/7z/7z.dsw | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 | ||
| 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! | ||
| 3 | |||
| 4 | ############################################################################### | ||
| 5 | |||
| 6 | Project: "7z"=.\7z.dsp - Package Owner=<4> | ||
| 7 | |||
| 8 | Package=<5> | ||
| 9 | {{{ | ||
| 10 | }}} | ||
| 11 | |||
| 12 | Package=<4> | ||
| 13 | {{{ | ||
| 14 | }}} | ||
| 15 | |||
| 16 | ############################################################################### | ||
| 17 | |||
| 18 | Global: | ||
| 19 | |||
| 20 | Package=<5> | ||
| 21 | {{{ | ||
| 22 | }}} | ||
| 23 | |||
| 24 | Package=<3> | ||
| 25 | {{{ | ||
| 26 | }}} | ||
| 27 | |||
| 28 | ############################################################################### | ||
| 29 | |||
diff --git a/C/Util/7z/7zMain.c b/C/Util/7z/7zMain.c new file mode 100644 index 0000000..9d55509 --- /dev/null +++ b/C/Util/7z/7zMain.c | |||
| @@ -0,0 +1,887 @@ | |||
| 1 | /* 7zMain.c - Test application for 7z Decoder | ||
| 2 | 2021-04-29 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | #include "../../CpuArch.h" | ||
| 10 | |||
| 11 | #include "../../7z.h" | ||
| 12 | #include "../../7zAlloc.h" | ||
| 13 | #include "../../7zBuf.h" | ||
| 14 | #include "../../7zCrc.h" | ||
| 15 | #include "../../7zFile.h" | ||
| 16 | #include "../../7zVersion.h" | ||
| 17 | |||
| 18 | #ifndef USE_WINDOWS_FILE | ||
| 19 | /* for mkdir */ | ||
| 20 | #ifdef _WIN32 | ||
| 21 | #include <direct.h> | ||
| 22 | #else | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <time.h> | ||
| 25 | #ifdef __GNUC__ | ||
| 26 | #include <sys/time.h> | ||
| 27 | #endif | ||
| 28 | #include <fcntl.h> | ||
| 29 | // #include <utime.h> | ||
| 30 | #include <sys/stat.h> | ||
| 31 | #include <errno.h> | ||
| 32 | #endif | ||
| 33 | #endif | ||
| 34 | |||
| 35 | |||
| 36 | #define kInputBufSize ((size_t)1 << 18) | ||
| 37 | |||
| 38 | static const ISzAlloc g_Alloc = { SzAlloc, SzFree }; | ||
| 39 | |||
| 40 | |||
| 41 | static void Print(const char *s) | ||
| 42 | { | ||
| 43 | fputs(s, stdout); | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | static int Buf_EnsureSize(CBuf *dest, size_t size) | ||
| 48 | { | ||
| 49 | if (dest->size >= size) | ||
| 50 | return 1; | ||
| 51 | Buf_Free(dest, &g_Alloc); | ||
| 52 | return Buf_Create(dest, size, &g_Alloc); | ||
| 53 | } | ||
| 54 | |||
| 55 | #ifndef _WIN32 | ||
| 56 | #define _USE_UTF8 | ||
| 57 | #endif | ||
| 58 | |||
| 59 | /* #define _USE_UTF8 */ | ||
| 60 | |||
| 61 | #ifdef _USE_UTF8 | ||
| 62 | |||
| 63 | #define _UTF8_START(n) (0x100 - (1 << (7 - (n)))) | ||
| 64 | |||
| 65 | #define _UTF8_RANGE(n) (((UInt32)1) << ((n) * 5 + 6)) | ||
| 66 | |||
| 67 | #define _UTF8_HEAD(n, val) ((Byte)(_UTF8_START(n) + (val >> (6 * (n))))) | ||
| 68 | #define _UTF8_CHAR(n, val) ((Byte)(0x80 + (((val) >> (6 * (n))) & 0x3F))) | ||
| 69 | |||
| 70 | static size_t Utf16_To_Utf8_Calc(const UInt16 *src, const UInt16 *srcLim) | ||
| 71 | { | ||
| 72 | size_t size = 0; | ||
| 73 | for (;;) | ||
| 74 | { | ||
| 75 | UInt32 val; | ||
| 76 | if (src == srcLim) | ||
| 77 | return size; | ||
| 78 | |||
| 79 | size++; | ||
| 80 | val = *src++; | ||
| 81 | |||
| 82 | if (val < 0x80) | ||
| 83 | continue; | ||
| 84 | |||
| 85 | if (val < _UTF8_RANGE(1)) | ||
| 86 | { | ||
| 87 | size++; | ||
| 88 | continue; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (val >= 0xD800 && val < 0xDC00 && src != srcLim) | ||
| 92 | { | ||
| 93 | UInt32 c2 = *src; | ||
| 94 | if (c2 >= 0xDC00 && c2 < 0xE000) | ||
| 95 | { | ||
| 96 | src++; | ||
| 97 | size += 3; | ||
| 98 | continue; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | size += 2; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | static Byte *Utf16_To_Utf8(Byte *dest, const UInt16 *src, const UInt16 *srcLim) | ||
| 107 | { | ||
| 108 | for (;;) | ||
| 109 | { | ||
| 110 | UInt32 val; | ||
| 111 | if (src == srcLim) | ||
| 112 | return dest; | ||
| 113 | |||
| 114 | val = *src++; | ||
| 115 | |||
| 116 | if (val < 0x80) | ||
| 117 | { | ||
| 118 | *dest++ = (Byte)val; | ||
| 119 | continue; | ||
| 120 | } | ||
| 121 | |||
| 122 | if (val < _UTF8_RANGE(1)) | ||
| 123 | { | ||
| 124 | dest[0] = _UTF8_HEAD(1, val); | ||
| 125 | dest[1] = _UTF8_CHAR(0, val); | ||
| 126 | dest += 2; | ||
| 127 | continue; | ||
| 128 | } | ||
| 129 | |||
| 130 | if (val >= 0xD800 && val < 0xDC00 && src != srcLim) | ||
| 131 | { | ||
| 132 | UInt32 c2 = *src; | ||
| 133 | if (c2 >= 0xDC00 && c2 < 0xE000) | ||
| 134 | { | ||
| 135 | src++; | ||
| 136 | val = (((val - 0xD800) << 10) | (c2 - 0xDC00)) + 0x10000; | ||
| 137 | dest[0] = _UTF8_HEAD(3, val); | ||
| 138 | dest[1] = _UTF8_CHAR(2, val); | ||
| 139 | dest[2] = _UTF8_CHAR(1, val); | ||
| 140 | dest[3] = _UTF8_CHAR(0, val); | ||
| 141 | dest += 4; | ||
| 142 | continue; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | dest[0] = _UTF8_HEAD(2, val); | ||
| 147 | dest[1] = _UTF8_CHAR(1, val); | ||
| 148 | dest[2] = _UTF8_CHAR(0, val); | ||
| 149 | dest += 3; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | static SRes Utf16_To_Utf8Buf(CBuf *dest, const UInt16 *src, size_t srcLen) | ||
| 154 | { | ||
| 155 | size_t destLen = Utf16_To_Utf8_Calc(src, src + srcLen); | ||
| 156 | destLen += 1; | ||
| 157 | if (!Buf_EnsureSize(dest, destLen)) | ||
| 158 | return SZ_ERROR_MEM; | ||
| 159 | *Utf16_To_Utf8(dest->data, src, src + srcLen) = 0; | ||
| 160 | return SZ_OK; | ||
| 161 | } | ||
| 162 | |||
| 163 | #endif | ||
| 164 | |||
| 165 | static SRes Utf16_To_Char(CBuf *buf, const UInt16 *s | ||
| 166 | #ifndef _USE_UTF8 | ||
| 167 | , UINT codePage | ||
| 168 | #endif | ||
| 169 | ) | ||
| 170 | { | ||
| 171 | unsigned len = 0; | ||
| 172 | for (len = 0; s[len] != 0; len++) {} | ||
| 173 | |||
| 174 | #ifndef _USE_UTF8 | ||
| 175 | { | ||
| 176 | const unsigned size = len * 3 + 100; | ||
| 177 | if (!Buf_EnsureSize(buf, size)) | ||
| 178 | return SZ_ERROR_MEM; | ||
| 179 | { | ||
| 180 | buf->data[0] = 0; | ||
| 181 | if (len != 0) | ||
| 182 | { | ||
| 183 | const char defaultChar = '_'; | ||
| 184 | BOOL defUsed; | ||
| 185 | const unsigned numChars = (unsigned)WideCharToMultiByte( | ||
| 186 | codePage, 0, (LPCWSTR)s, (int)len, (char *)buf->data, (int)size, &defaultChar, &defUsed); | ||
| 187 | if (numChars == 0 || numChars >= size) | ||
| 188 | return SZ_ERROR_FAIL; | ||
| 189 | buf->data[numChars] = 0; | ||
| 190 | } | ||
| 191 | return SZ_OK; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | #else | ||
| 195 | return Utf16_To_Utf8Buf(buf, s, len); | ||
| 196 | #endif | ||
| 197 | } | ||
| 198 | |||
| 199 | #ifdef _WIN32 | ||
| 200 | #ifndef USE_WINDOWS_FILE | ||
| 201 | static UINT g_FileCodePage = CP_ACP; | ||
| 202 | #define MY_FILE_CODE_PAGE_PARAM ,g_FileCodePage | ||
| 203 | #endif | ||
| 204 | #else | ||
| 205 | #define MY_FILE_CODE_PAGE_PARAM | ||
| 206 | #endif | ||
| 207 | |||
| 208 | static WRes MyCreateDir(const UInt16 *name) | ||
| 209 | { | ||
| 210 | #ifdef USE_WINDOWS_FILE | ||
| 211 | |||
| 212 | return CreateDirectoryW((LPCWSTR)name, NULL) ? 0 : GetLastError(); | ||
| 213 | |||
| 214 | #else | ||
| 215 | |||
| 216 | CBuf buf; | ||
| 217 | WRes res; | ||
| 218 | Buf_Init(&buf); | ||
| 219 | RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)); | ||
| 220 | |||
| 221 | res = | ||
| 222 | #ifdef _WIN32 | ||
| 223 | _mkdir((const char *)buf.data) | ||
| 224 | #else | ||
| 225 | mkdir((const char *)buf.data, 0777) | ||
| 226 | #endif | ||
| 227 | == 0 ? 0 : errno; | ||
| 228 | Buf_Free(&buf, &g_Alloc); | ||
| 229 | return res; | ||
| 230 | |||
| 231 | #endif | ||
| 232 | } | ||
| 233 | |||
| 234 | static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name) | ||
| 235 | { | ||
| 236 | #ifdef USE_WINDOWS_FILE | ||
| 237 | return OutFile_OpenW(p, (LPCWSTR)name); | ||
| 238 | #else | ||
| 239 | CBuf buf; | ||
| 240 | WRes res; | ||
| 241 | Buf_Init(&buf); | ||
| 242 | RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)); | ||
| 243 | res = OutFile_Open(p, (const char *)buf.data); | ||
| 244 | Buf_Free(&buf, &g_Alloc); | ||
| 245 | return res; | ||
| 246 | #endif | ||
| 247 | } | ||
| 248 | |||
| 249 | |||
| 250 | static SRes PrintString(const UInt16 *s) | ||
| 251 | { | ||
| 252 | CBuf buf; | ||
| 253 | SRes res; | ||
| 254 | Buf_Init(&buf); | ||
| 255 | res = Utf16_To_Char(&buf, s | ||
| 256 | #ifndef _USE_UTF8 | ||
| 257 | , CP_OEMCP | ||
| 258 | #endif | ||
| 259 | ); | ||
| 260 | if (res == SZ_OK) | ||
| 261 | Print((const char *)buf.data); | ||
| 262 | Buf_Free(&buf, &g_Alloc); | ||
| 263 | return res; | ||
| 264 | } | ||
| 265 | |||
| 266 | static void UInt64ToStr(UInt64 value, char *s, int numDigits) | ||
| 267 | { | ||
| 268 | char temp[32]; | ||
| 269 | int pos = 0; | ||
| 270 | do | ||
| 271 | { | ||
| 272 | temp[pos++] = (char)('0' + (unsigned)(value % 10)); | ||
| 273 | value /= 10; | ||
| 274 | } | ||
| 275 | while (value != 0); | ||
| 276 | |||
| 277 | for (numDigits -= pos; numDigits > 0; numDigits--) | ||
| 278 | *s++ = ' '; | ||
| 279 | |||
| 280 | do | ||
| 281 | *s++ = temp[--pos]; | ||
| 282 | while (pos); | ||
| 283 | *s = '\0'; | ||
| 284 | } | ||
| 285 | |||
| 286 | static char *UIntToStr(char *s, unsigned value, int numDigits) | ||
| 287 | { | ||
| 288 | char temp[16]; | ||
| 289 | int pos = 0; | ||
| 290 | do | ||
| 291 | temp[pos++] = (char)('0' + (value % 10)); | ||
| 292 | while (value /= 10); | ||
| 293 | |||
| 294 | for (numDigits -= pos; numDigits > 0; numDigits--) | ||
| 295 | *s++ = '0'; | ||
| 296 | |||
| 297 | do | ||
| 298 | *s++ = temp[--pos]; | ||
| 299 | while (pos); | ||
| 300 | *s = '\0'; | ||
| 301 | return s; | ||
| 302 | } | ||
| 303 | |||
| 304 | static void UIntToStr_2(char *s, unsigned value) | ||
| 305 | { | ||
| 306 | s[0] = (char)('0' + (value / 10)); | ||
| 307 | s[1] = (char)('0' + (value % 10)); | ||
| 308 | } | ||
| 309 | |||
| 310 | |||
| 311 | #define PERIOD_4 (4 * 365 + 1) | ||
| 312 | #define PERIOD_100 (PERIOD_4 * 25 - 1) | ||
| 313 | #define PERIOD_400 (PERIOD_100 * 4 + 1) | ||
| 314 | |||
| 315 | |||
| 316 | |||
| 317 | #ifndef _WIN32 | ||
| 318 | |||
| 319 | // MS uses long for BOOL, but long is 32-bit in MS. So we use int. | ||
| 320 | // typedef long BOOL; | ||
| 321 | typedef int BOOL; | ||
| 322 | |||
| 323 | typedef struct _FILETIME | ||
| 324 | { | ||
| 325 | DWORD dwLowDateTime; | ||
| 326 | DWORD dwHighDateTime; | ||
| 327 | } FILETIME; | ||
| 328 | |||
| 329 | static LONG TIME_GetBias() | ||
| 330 | { | ||
| 331 | time_t utc = time(NULL); | ||
| 332 | struct tm *ptm = localtime(&utc); | ||
| 333 | int localdaylight = ptm->tm_isdst; /* daylight for local timezone */ | ||
| 334 | ptm = gmtime(&utc); | ||
| 335 | ptm->tm_isdst = localdaylight; /* use local daylight, not that of Greenwich */ | ||
| 336 | LONG bias = (int)(mktime(ptm)-utc); | ||
| 337 | return bias; | ||
| 338 | } | ||
| 339 | |||
| 340 | #define TICKS_PER_SEC 10000000 | ||
| 341 | |||
| 342 | #define GET_TIME_64(pft) ((pft)->dwLowDateTime | ((UInt64)(pft)->dwHighDateTime << 32)) | ||
| 343 | |||
| 344 | #define SET_FILETIME(ft, v64) \ | ||
| 345 | (ft)->dwLowDateTime = (DWORD)v64; \ | ||
| 346 | (ft)->dwHighDateTime = (DWORD)(v64 >> 32); | ||
| 347 | |||
| 348 | #define WINAPI | ||
| 349 | #define TRUE 1 | ||
| 350 | |||
| 351 | static BOOL WINAPI FileTimeToLocalFileTime(const FILETIME *fileTime, FILETIME *localFileTime) | ||
| 352 | { | ||
| 353 | UInt64 v = GET_TIME_64(fileTime); | ||
| 354 | v = (UInt64)((Int64)v - (Int64)TIME_GetBias() * TICKS_PER_SEC); | ||
| 355 | SET_FILETIME(localFileTime, v); | ||
| 356 | return TRUE; | ||
| 357 | } | ||
| 358 | |||
| 359 | static const UInt32 kNumTimeQuantumsInSecond = 10000000; | ||
| 360 | static const UInt32 kFileTimeStartYear = 1601; | ||
| 361 | static const UInt32 kUnixTimeStartYear = 1970; | ||
| 362 | static const UInt64 kUnixTimeOffset = | ||
| 363 | (UInt64)60 * 60 * 24 * (89 + 365 * (kUnixTimeStartYear - kFileTimeStartYear)); | ||
| 364 | |||
| 365 | static Int64 Time_FileTimeToUnixTime64(const FILETIME *ft) | ||
| 366 | { | ||
| 367 | UInt64 winTime = GET_TIME_64(ft); | ||
| 368 | return (Int64)(winTime / kNumTimeQuantumsInSecond) - (Int64)kUnixTimeOffset; | ||
| 369 | } | ||
| 370 | |||
| 371 | #if defined(_AIX) | ||
| 372 | #define MY_ST_TIMESPEC st_timespec | ||
| 373 | #else | ||
| 374 | #define MY_ST_TIMESPEC timespec | ||
| 375 | #endif | ||
| 376 | |||
| 377 | static void FILETIME_To_timespec(const FILETIME *ft, struct MY_ST_TIMESPEC *ts) | ||
| 378 | { | ||
| 379 | if (ft) | ||
| 380 | { | ||
| 381 | const Int64 sec = Time_FileTimeToUnixTime64(ft); | ||
| 382 | // time_t is long | ||
| 383 | const time_t sec2 = (time_t)sec; | ||
| 384 | if (sec2 == sec) | ||
| 385 | { | ||
| 386 | ts->tv_sec = sec2; | ||
| 387 | UInt64 winTime = GET_TIME_64(ft); | ||
| 388 | ts->tv_nsec = (long)((winTime % 10000000) * 100);; | ||
| 389 | return; | ||
| 390 | } | ||
| 391 | } | ||
| 392 | // else | ||
| 393 | { | ||
| 394 | ts->tv_sec = 0; | ||
| 395 | // ts.tv_nsec = UTIME_NOW; // set to the current time | ||
| 396 | ts->tv_nsec = UTIME_OMIT; // keep old timesptamp | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 | static WRes Set_File_FILETIME(const UInt16 *name, const FILETIME *mTime) | ||
| 401 | { | ||
| 402 | struct timespec times[2]; | ||
| 403 | |||
| 404 | const int flags = 0; // follow link | ||
| 405 | // = AT_SYMLINK_NOFOLLOW; // don't follow link | ||
| 406 | |||
| 407 | CBuf buf; | ||
| 408 | int res; | ||
| 409 | Buf_Init(&buf); | ||
| 410 | RINOK(Utf16_To_Char(&buf, name MY_FILE_CODE_PAGE_PARAM)); | ||
| 411 | FILETIME_To_timespec(NULL, ×[0]); | ||
| 412 | FILETIME_To_timespec(mTime, ×[1]); | ||
| 413 | res = utimensat(AT_FDCWD, (const char *)buf.data, times, flags); | ||
| 414 | Buf_Free(&buf, &g_Alloc); | ||
| 415 | if (res == 0) | ||
| 416 | return 0; | ||
| 417 | return errno; | ||
| 418 | } | ||
| 419 | |||
| 420 | #endif | ||
| 421 | |||
| 422 | static void NtfsFileTime_to_FILETIME(const CNtfsFileTime *t, FILETIME *ft) | ||
| 423 | { | ||
| 424 | ft->dwLowDateTime = (DWORD)(t->Low); | ||
| 425 | ft->dwHighDateTime = (DWORD)(t->High); | ||
| 426 | } | ||
| 427 | |||
| 428 | static void ConvertFileTimeToString(const CNtfsFileTime *nTime, char *s) | ||
| 429 | { | ||
| 430 | unsigned year, mon, hour, min, sec; | ||
| 431 | Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | ||
| 432 | unsigned t; | ||
| 433 | UInt32 v; | ||
| 434 | // UInt64 v64 = nt->Low | ((UInt64)nt->High << 32); | ||
| 435 | UInt64 v64; | ||
| 436 | { | ||
| 437 | FILETIME fileTime, locTime; | ||
| 438 | NtfsFileTime_to_FILETIME(nTime, &fileTime); | ||
| 439 | if (!FileTimeToLocalFileTime(&fileTime, &locTime)) | ||
| 440 | { | ||
| 441 | locTime.dwHighDateTime = | ||
| 442 | locTime.dwLowDateTime = 0; | ||
| 443 | } | ||
| 444 | v64 = locTime.dwLowDateTime | ((UInt64)locTime.dwHighDateTime << 32); | ||
| 445 | } | ||
| 446 | v64 /= 10000000; | ||
| 447 | sec = (unsigned)(v64 % 60); v64 /= 60; | ||
| 448 | min = (unsigned)(v64 % 60); v64 /= 60; | ||
| 449 | hour = (unsigned)(v64 % 24); v64 /= 24; | ||
| 450 | |||
| 451 | v = (UInt32)v64; | ||
| 452 | |||
| 453 | year = (unsigned)(1601 + v / PERIOD_400 * 400); | ||
| 454 | v %= PERIOD_400; | ||
| 455 | |||
| 456 | t = v / PERIOD_100; if (t == 4) t = 3; year += t * 100; v -= t * PERIOD_100; | ||
| 457 | t = v / PERIOD_4; if (t == 25) t = 24; year += t * 4; v -= t * PERIOD_4; | ||
| 458 | t = v / 365; if (t == 4) t = 3; year += t; v -= t * 365; | ||
| 459 | |||
| 460 | if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) | ||
| 461 | ms[1] = 29; | ||
| 462 | for (mon = 0;; mon++) | ||
| 463 | { | ||
| 464 | unsigned d = ms[mon]; | ||
| 465 | if (v < d) | ||
| 466 | break; | ||
| 467 | v -= d; | ||
| 468 | } | ||
| 469 | s = UIntToStr(s, year, 4); *s++ = '-'; | ||
| 470 | UIntToStr_2(s, mon + 1); s[2] = '-'; s += 3; | ||
| 471 | UIntToStr_2(s, (unsigned)v + 1); s[2] = ' '; s += 3; | ||
| 472 | UIntToStr_2(s, hour); s[2] = ':'; s += 3; | ||
| 473 | UIntToStr_2(s, min); s[2] = ':'; s += 3; | ||
| 474 | UIntToStr_2(s, sec); s[2] = 0; | ||
| 475 | } | ||
| 476 | |||
| 477 | static void PrintLF() | ||
| 478 | { | ||
| 479 | Print("\n"); | ||
| 480 | } | ||
| 481 | |||
| 482 | static void PrintError(char *s) | ||
| 483 | { | ||
| 484 | Print("\nERROR: "); | ||
| 485 | Print(s); | ||
| 486 | PrintLF(); | ||
| 487 | } | ||
| 488 | |||
| 489 | static void PrintError_WRes(const char *message, WRes wres) | ||
| 490 | { | ||
| 491 | Print("\nERROR: "); | ||
| 492 | Print(message); | ||
| 493 | PrintLF(); | ||
| 494 | { | ||
| 495 | char s[32]; | ||
| 496 | UIntToStr(s, (unsigned)wres, 1); | ||
| 497 | Print("System error code: "); | ||
| 498 | Print(s); | ||
| 499 | } | ||
| 500 | // sprintf(buffer + strlen(buffer), "\nSystem error code: %d", (unsigned)wres); | ||
| 501 | #ifdef _WIN32 | ||
| 502 | { | ||
| 503 | char *s = NULL; | ||
| 504 | if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | | ||
| 505 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | ||
| 506 | NULL, wres, 0, (LPSTR) &s, 0, NULL) != 0 && s) | ||
| 507 | { | ||
| 508 | Print(" : "); | ||
| 509 | Print(s); | ||
| 510 | LocalFree(s); | ||
| 511 | } | ||
| 512 | } | ||
| 513 | #else | ||
| 514 | { | ||
| 515 | const char *s = strerror(wres); | ||
| 516 | if (s) | ||
| 517 | { | ||
| 518 | Print(" : "); | ||
| 519 | Print(s); | ||
| 520 | } | ||
| 521 | } | ||
| 522 | #endif | ||
| 523 | PrintLF(); | ||
| 524 | } | ||
| 525 | |||
| 526 | static void GetAttribString(UInt32 wa, BoolInt isDir, char *s) | ||
| 527 | { | ||
| 528 | #ifdef USE_WINDOWS_FILE | ||
| 529 | s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.'); | ||
| 530 | s[1] = (char)(((wa & FILE_ATTRIBUTE_READONLY ) != 0) ? 'R': '.'); | ||
| 531 | s[2] = (char)(((wa & FILE_ATTRIBUTE_HIDDEN ) != 0) ? 'H': '.'); | ||
| 532 | s[3] = (char)(((wa & FILE_ATTRIBUTE_SYSTEM ) != 0) ? 'S': '.'); | ||
| 533 | s[4] = (char)(((wa & FILE_ATTRIBUTE_ARCHIVE ) != 0) ? 'A': '.'); | ||
| 534 | s[5] = 0; | ||
| 535 | #else | ||
| 536 | s[0] = (char)(((wa & (1 << 4)) != 0 || isDir) ? 'D' : '.'); | ||
| 537 | s[1] = 0; | ||
| 538 | #endif | ||
| 539 | } | ||
| 540 | |||
| 541 | |||
| 542 | // #define NUM_PARENTS_MAX 128 | ||
| 543 | |||
| 544 | int MY_CDECL main(int numargs, char *args[]) | ||
| 545 | { | ||
| 546 | ISzAlloc allocImp; | ||
| 547 | ISzAlloc allocTempImp; | ||
| 548 | |||
| 549 | CFileInStream archiveStream; | ||
| 550 | CLookToRead2 lookStream; | ||
| 551 | CSzArEx db; | ||
| 552 | SRes res; | ||
| 553 | UInt16 *temp = NULL; | ||
| 554 | size_t tempSize = 0; | ||
| 555 | // UInt32 parents[NUM_PARENTS_MAX]; | ||
| 556 | |||
| 557 | Print("\n7z Decoder " MY_VERSION_CPU " : " MY_COPYRIGHT_DATE "\n\n"); | ||
| 558 | |||
| 559 | if (numargs == 1) | ||
| 560 | { | ||
| 561 | Print( | ||
| 562 | "Usage: 7zDec <command> <archive_name>\n\n" | ||
| 563 | "<Commands>\n" | ||
| 564 | " e: Extract files from archive (without using directory names)\n" | ||
| 565 | " l: List contents of archive\n" | ||
| 566 | " t: Test integrity of archive\n" | ||
| 567 | " x: eXtract files with full paths\n"); | ||
| 568 | return 0; | ||
| 569 | } | ||
| 570 | |||
| 571 | if (numargs < 3) | ||
| 572 | { | ||
| 573 | PrintError("incorrect command"); | ||
| 574 | return 1; | ||
| 575 | } | ||
| 576 | |||
| 577 | #if defined(_WIN32) && !defined(USE_WINDOWS_FILE) && !defined(UNDER_CE) | ||
| 578 | g_FileCodePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; | ||
| 579 | #endif | ||
| 580 | |||
| 581 | |||
| 582 | allocImp = g_Alloc; | ||
| 583 | allocTempImp = g_Alloc; | ||
| 584 | |||
| 585 | { | ||
| 586 | WRes wres = | ||
| 587 | #ifdef UNDER_CE | ||
| 588 | InFile_OpenW(&archiveStream.file, L"\test.7z"); // change it | ||
| 589 | #else | ||
| 590 | InFile_Open(&archiveStream.file, args[2]); | ||
| 591 | #endif | ||
| 592 | if (wres != 0) | ||
| 593 | { | ||
| 594 | PrintError_WRes("cannot open input file", wres); | ||
| 595 | return 1; | ||
| 596 | } | ||
| 597 | } | ||
| 598 | |||
| 599 | FileInStream_CreateVTable(&archiveStream); | ||
| 600 | archiveStream.wres = 0; | ||
| 601 | LookToRead2_CreateVTable(&lookStream, False); | ||
| 602 | lookStream.buf = NULL; | ||
| 603 | |||
| 604 | res = SZ_OK; | ||
| 605 | |||
| 606 | { | ||
| 607 | lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize); | ||
| 608 | if (!lookStream.buf) | ||
| 609 | res = SZ_ERROR_MEM; | ||
| 610 | else | ||
| 611 | { | ||
| 612 | lookStream.bufSize = kInputBufSize; | ||
| 613 | lookStream.realStream = &archiveStream.vt; | ||
| 614 | LookToRead2_Init(&lookStream); | ||
| 615 | } | ||
| 616 | } | ||
| 617 | |||
| 618 | CrcGenerateTable(); | ||
| 619 | |||
| 620 | SzArEx_Init(&db); | ||
| 621 | |||
| 622 | if (res == SZ_OK) | ||
| 623 | { | ||
| 624 | res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp); | ||
| 625 | } | ||
| 626 | |||
| 627 | if (res == SZ_OK) | ||
| 628 | { | ||
| 629 | char *command = args[1]; | ||
| 630 | int listCommand = 0, testCommand = 0, fullPaths = 0; | ||
| 631 | |||
| 632 | if (strcmp(command, "l") == 0) listCommand = 1; | ||
| 633 | else if (strcmp(command, "t") == 0) testCommand = 1; | ||
| 634 | else if (strcmp(command, "e") == 0) { } | ||
| 635 | else if (strcmp(command, "x") == 0) { fullPaths = 1; } | ||
| 636 | else | ||
| 637 | { | ||
| 638 | PrintError("incorrect command"); | ||
| 639 | res = SZ_ERROR_FAIL; | ||
| 640 | } | ||
| 641 | |||
| 642 | if (res == SZ_OK) | ||
| 643 | { | ||
| 644 | UInt32 i; | ||
| 645 | |||
| 646 | /* | ||
| 647 | if you need cache, use these 3 variables. | ||
| 648 | if you use external function, you can make these variable as static. | ||
| 649 | */ | ||
| 650 | UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ | ||
| 651 | Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */ | ||
| 652 | size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ | ||
| 653 | |||
| 654 | for (i = 0; i < db.NumFiles; i++) | ||
| 655 | { | ||
| 656 | size_t offset = 0; | ||
| 657 | size_t outSizeProcessed = 0; | ||
| 658 | // const CSzFileItem *f = db.Files + i; | ||
| 659 | size_t len; | ||
| 660 | const BoolInt isDir = SzArEx_IsDir(&db, i); | ||
| 661 | if (listCommand == 0 && isDir && !fullPaths) | ||
| 662 | continue; | ||
| 663 | len = SzArEx_GetFileNameUtf16(&db, i, NULL); | ||
| 664 | // len = SzArEx_GetFullNameLen(&db, i); | ||
| 665 | |||
| 666 | if (len > tempSize) | ||
| 667 | { | ||
| 668 | SzFree(NULL, temp); | ||
| 669 | tempSize = len; | ||
| 670 | temp = (UInt16 *)SzAlloc(NULL, tempSize * sizeof(temp[0])); | ||
| 671 | if (!temp) | ||
| 672 | { | ||
| 673 | res = SZ_ERROR_MEM; | ||
| 674 | break; | ||
| 675 | } | ||
| 676 | } | ||
| 677 | |||
| 678 | SzArEx_GetFileNameUtf16(&db, i, temp); | ||
| 679 | /* | ||
| 680 | if (SzArEx_GetFullNameUtf16_Back(&db, i, temp + len) != temp) | ||
| 681 | { | ||
| 682 | res = SZ_ERROR_FAIL; | ||
| 683 | break; | ||
| 684 | } | ||
| 685 | */ | ||
| 686 | |||
| 687 | if (listCommand) | ||
| 688 | { | ||
| 689 | char attr[8], s[32], t[32]; | ||
| 690 | UInt64 fileSize; | ||
| 691 | |||
| 692 | GetAttribString(SzBitWithVals_Check(&db.Attribs, i) ? db.Attribs.Vals[i] : 0, isDir, attr); | ||
| 693 | |||
| 694 | fileSize = SzArEx_GetFileSize(&db, i); | ||
| 695 | UInt64ToStr(fileSize, s, 10); | ||
| 696 | |||
| 697 | if (SzBitWithVals_Check(&db.MTime, i)) | ||
| 698 | ConvertFileTimeToString(&db.MTime.Vals[i], t); | ||
| 699 | else | ||
| 700 | { | ||
| 701 | size_t j; | ||
| 702 | for (j = 0; j < 19; j++) | ||
| 703 | t[j] = ' '; | ||
| 704 | t[j] = '\0'; | ||
| 705 | } | ||
| 706 | |||
| 707 | Print(t); | ||
| 708 | Print(" "); | ||
| 709 | Print(attr); | ||
| 710 | Print(" "); | ||
| 711 | Print(s); | ||
| 712 | Print(" "); | ||
| 713 | res = PrintString(temp); | ||
| 714 | if (res != SZ_OK) | ||
| 715 | break; | ||
| 716 | if (isDir) | ||
| 717 | Print("/"); | ||
| 718 | PrintLF(); | ||
| 719 | continue; | ||
| 720 | } | ||
| 721 | |||
| 722 | Print(testCommand ? | ||
| 723 | "T ": | ||
| 724 | "- "); | ||
| 725 | res = PrintString(temp); | ||
| 726 | if (res != SZ_OK) | ||
| 727 | break; | ||
| 728 | |||
| 729 | if (isDir) | ||
| 730 | Print("/"); | ||
| 731 | else | ||
| 732 | { | ||
| 733 | res = SzArEx_Extract(&db, &lookStream.vt, i, | ||
| 734 | &blockIndex, &outBuffer, &outBufferSize, | ||
| 735 | &offset, &outSizeProcessed, | ||
| 736 | &allocImp, &allocTempImp); | ||
| 737 | if (res != SZ_OK) | ||
| 738 | break; | ||
| 739 | } | ||
| 740 | |||
| 741 | if (!testCommand) | ||
| 742 | { | ||
| 743 | CSzFile outFile; | ||
| 744 | size_t processedSize; | ||
| 745 | size_t j; | ||
| 746 | UInt16 *name = (UInt16 *)temp; | ||
| 747 | const UInt16 *destPath = (const UInt16 *)name; | ||
| 748 | |||
| 749 | for (j = 0; name[j] != 0; j++) | ||
| 750 | if (name[j] == '/') | ||
| 751 | { | ||
| 752 | if (fullPaths) | ||
| 753 | { | ||
| 754 | name[j] = 0; | ||
| 755 | MyCreateDir(name); | ||
| 756 | name[j] = CHAR_PATH_SEPARATOR; | ||
| 757 | } | ||
| 758 | else | ||
| 759 | destPath = name + j + 1; | ||
| 760 | } | ||
| 761 | |||
| 762 | if (isDir) | ||
| 763 | { | ||
| 764 | MyCreateDir(destPath); | ||
| 765 | PrintLF(); | ||
| 766 | continue; | ||
| 767 | } | ||
| 768 | else | ||
| 769 | { | ||
| 770 | WRes wres = OutFile_OpenUtf16(&outFile, destPath); | ||
| 771 | if (wres != 0) | ||
| 772 | { | ||
| 773 | PrintError_WRes("cannot open output file", wres); | ||
| 774 | res = SZ_ERROR_FAIL; | ||
| 775 | break; | ||
| 776 | } | ||
| 777 | } | ||
| 778 | |||
| 779 | processedSize = outSizeProcessed; | ||
| 780 | |||
| 781 | { | ||
| 782 | WRes wres = File_Write(&outFile, outBuffer + offset, &processedSize); | ||
| 783 | if (wres != 0 || processedSize != outSizeProcessed) | ||
| 784 | { | ||
| 785 | PrintError_WRes("cannot write output file", wres); | ||
| 786 | res = SZ_ERROR_FAIL; | ||
| 787 | break; | ||
| 788 | } | ||
| 789 | } | ||
| 790 | |||
| 791 | { | ||
| 792 | FILETIME mtime; | ||
| 793 | FILETIME *mtimePtr = NULL; | ||
| 794 | |||
| 795 | #ifdef USE_WINDOWS_FILE | ||
| 796 | FILETIME ctime; | ||
| 797 | FILETIME *ctimePtr = NULL; | ||
| 798 | #endif | ||
| 799 | |||
| 800 | if (SzBitWithVals_Check(&db.MTime, i)) | ||
| 801 | { | ||
| 802 | const CNtfsFileTime *t = &db.MTime.Vals[i]; | ||
| 803 | mtime.dwLowDateTime = (DWORD)(t->Low); | ||
| 804 | mtime.dwHighDateTime = (DWORD)(t->High); | ||
| 805 | mtimePtr = &mtime; | ||
| 806 | } | ||
| 807 | |||
| 808 | #ifdef USE_WINDOWS_FILE | ||
| 809 | if (SzBitWithVals_Check(&db.CTime, i)) | ||
| 810 | { | ||
| 811 | const CNtfsFileTime *t = &db.CTime.Vals[i]; | ||
| 812 | ctime.dwLowDateTime = (DWORD)(t->Low); | ||
| 813 | ctime.dwHighDateTime = (DWORD)(t->High); | ||
| 814 | ctimePtr = &ctime; | ||
| 815 | } | ||
| 816 | |||
| 817 | if (mtimePtr || ctimePtr) | ||
| 818 | SetFileTime(outFile.handle, ctimePtr, NULL, mtimePtr); | ||
| 819 | #endif | ||
| 820 | |||
| 821 | { | ||
| 822 | WRes wres = File_Close(&outFile); | ||
| 823 | if (wres != 0) | ||
| 824 | { | ||
| 825 | PrintError_WRes("cannot close output file", wres); | ||
| 826 | res = SZ_ERROR_FAIL; | ||
| 827 | break; | ||
| 828 | } | ||
| 829 | } | ||
| 830 | |||
| 831 | #ifndef USE_WINDOWS_FILE | ||
| 832 | #ifdef _WIN32 | ||
| 833 | mtimePtr = mtimePtr; | ||
| 834 | #else | ||
| 835 | if (mtimePtr) | ||
| 836 | Set_File_FILETIME(destPath, mtimePtr); | ||
| 837 | #endif | ||
| 838 | #endif | ||
| 839 | } | ||
| 840 | |||
| 841 | #ifdef USE_WINDOWS_FILE | ||
| 842 | if (SzBitWithVals_Check(&db.Attribs, i)) | ||
| 843 | { | ||
| 844 | UInt32 attrib = db.Attribs.Vals[i]; | ||
| 845 | /* p7zip stores posix attributes in high 16 bits and adds 0x8000 as marker. | ||
| 846 | We remove posix bits, if we detect posix mode field */ | ||
| 847 | if ((attrib & 0xF0000000) != 0) | ||
| 848 | attrib &= 0x7FFF; | ||
| 849 | SetFileAttributesW((LPCWSTR)destPath, attrib); | ||
| 850 | } | ||
| 851 | #endif | ||
| 852 | } | ||
| 853 | PrintLF(); | ||
| 854 | } | ||
| 855 | ISzAlloc_Free(&allocImp, outBuffer); | ||
| 856 | } | ||
| 857 | } | ||
| 858 | |||
| 859 | SzFree(NULL, temp); | ||
| 860 | SzArEx_Free(&db, &allocImp); | ||
| 861 | ISzAlloc_Free(&allocImp, lookStream.buf); | ||
| 862 | |||
| 863 | File_Close(&archiveStream.file); | ||
| 864 | |||
| 865 | if (res == SZ_OK) | ||
| 866 | { | ||
| 867 | Print("\nEverything is Ok\n"); | ||
| 868 | return 0; | ||
| 869 | } | ||
| 870 | |||
| 871 | if (res == SZ_ERROR_UNSUPPORTED) | ||
| 872 | PrintError("decoder doesn't support this archive"); | ||
| 873 | else if (res == SZ_ERROR_MEM) | ||
| 874 | PrintError("cannot allocate memory"); | ||
| 875 | else if (res == SZ_ERROR_CRC) | ||
| 876 | PrintError("CRC error"); | ||
| 877 | else if (res == SZ_ERROR_READ /* || archiveStream.Res != 0 */) | ||
| 878 | PrintError_WRes("Read Error", archiveStream.wres); | ||
| 879 | else | ||
| 880 | { | ||
| 881 | char s[32]; | ||
| 882 | UInt64ToStr((unsigned)res, s, 0); | ||
| 883 | PrintError(s); | ||
| 884 | } | ||
| 885 | |||
| 886 | return 1; | ||
| 887 | } | ||
diff --git a/C/Util/7z/Precomp.c b/C/Util/7z/Precomp.c new file mode 100644 index 0000000..01605e3 --- /dev/null +++ b/C/Util/7z/Precomp.c | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | /* Precomp.c -- StdAfx | ||
| 2 | 2013-01-21 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
diff --git a/C/Util/7z/Precomp.h b/C/Util/7z/Precomp.h new file mode 100644 index 0000000..588a66f --- /dev/null +++ b/C/Util/7z/Precomp.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | /* Precomp.h -- StdAfx | ||
| 2 | 2013-06-16 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #ifndef __7Z_PRECOMP_H | ||
| 5 | #define __7Z_PRECOMP_H | ||
| 6 | |||
| 7 | #include "../../Compiler.h" | ||
| 8 | #include "../../7zTypes.h" | ||
| 9 | |||
| 10 | #endif | ||
diff --git a/C/Util/7z/makefile b/C/Util/7z/makefile new file mode 100644 index 0000000..9a49fd5 --- /dev/null +++ b/C/Util/7z/makefile | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | CFLAGS = $(CFLAGS) -D_7ZIP_PPMD_SUPPPORT | ||
| 2 | |||
| 3 | PROG = 7zDec.exe | ||
| 4 | |||
| 5 | C_OBJS = \ | ||
| 6 | $O\7zAlloc.obj \ | ||
| 7 | $O\7zBuf.obj \ | ||
| 8 | $O\7zCrc.obj \ | ||
| 9 | $O\7zCrcOpt.obj \ | ||
| 10 | $O\7zFile.obj \ | ||
| 11 | $O\7zDec.obj \ | ||
| 12 | $O\7zArcIn.obj \ | ||
| 13 | $O\7zStream.obj \ | ||
| 14 | $O\Bcj2.obj \ | ||
| 15 | $O\Bra.obj \ | ||
| 16 | $O\Bra86.obj \ | ||
| 17 | $O\BraIA64.obj \ | ||
| 18 | $O\CpuArch.obj \ | ||
| 19 | $O\Delta.obj \ | ||
| 20 | $O\Lzma2Dec.obj \ | ||
| 21 | $O\LzmaDec.obj \ | ||
| 22 | $O\Ppmd7.obj \ | ||
| 23 | $O\Ppmd7Dec.obj \ | ||
| 24 | |||
| 25 | 7Z_OBJS = \ | ||
| 26 | $O\7zMain.obj \ | ||
| 27 | |||
| 28 | OBJS = \ | ||
| 29 | $O\Precomp.obj \ | ||
| 30 | $(7Z_OBJS) \ | ||
| 31 | $(C_OBJS) \ | ||
| 32 | |||
| 33 | !include "../../../CPP/Build.mak" | ||
| 34 | |||
| 35 | $(7Z_OBJS): $(*B).c | ||
| 36 | $(CCOMPL_USE) | ||
| 37 | $(C_OBJS): ../../$(*B).c | ||
| 38 | $(CCOMPL_USE) | ||
| 39 | $O\Precomp.obj: Precomp.c | ||
| 40 | $(CCOMPL_PCH) | ||
diff --git a/C/Util/7z/makefile.gcc b/C/Util/7z/makefile.gcc new file mode 100644 index 0000000..4263d67 --- /dev/null +++ b/C/Util/7z/makefile.gcc | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | PROG = 7zdec | ||
| 2 | |||
| 3 | LOCAL_FLAGS = -D_7ZIP_PPMD_SUPPPORT | ||
| 4 | |||
| 5 | include ../../../CPP/7zip/LzmaDec_gcc.mak | ||
| 6 | |||
| 7 | |||
| 8 | OBJS = \ | ||
| 9 | $(LZMA_DEC_OPT_OBJS) \ | ||
| 10 | $O/Bcj2.o \ | ||
| 11 | $O/Bra.o \ | ||
| 12 | $O/Bra86.o \ | ||
| 13 | $O/BraIA64.o \ | ||
| 14 | $O/CpuArch.o \ | ||
| 15 | $O/Delta.o \ | ||
| 16 | $O/Lzma2Dec.o \ | ||
| 17 | $O/LzmaDec.o \ | ||
| 18 | $O/Ppmd7.o \ | ||
| 19 | $O/Ppmd7Dec.o \ | ||
| 20 | $O/7zCrc.o \ | ||
| 21 | $O/7zCrcOpt.o \ | ||
| 22 | $O/Sha256.o \ | ||
| 23 | $O/Sha256Opt.o \ | ||
| 24 | $O/7zAlloc.o \ | ||
| 25 | $O/7zArcIn.o \ | ||
| 26 | $O/7zBuf.o \ | ||
| 27 | $O/7zBuf2.o \ | ||
| 28 | $O/7zDec.o \ | ||
| 29 | $O/7zMain.o \ | ||
| 30 | $O/7zFile.o \ | ||
| 31 | $O/7zStream.o \ | ||
| 32 | |||
| 33 | |||
| 34 | include ../../7zip_gcc_c.mak | ||
diff --git a/C/Util/7zipInstall/7zip.ico b/C/Util/7zipInstall/7zip.ico new file mode 100644 index 0000000..47ffb78 --- /dev/null +++ b/C/Util/7zipInstall/7zip.ico | |||
| Binary files differ | |||
diff --git a/C/Util/7zipInstall/7zipInstall.c b/C/Util/7zipInstall/7zipInstall.c new file mode 100644 index 0000000..00d0f41 --- /dev/null +++ b/C/Util/7zipInstall/7zipInstall.c | |||
| @@ -0,0 +1,1666 @@ | |||
| 1 | /* 7zipInstall.c - 7-Zip Installer | ||
| 2 | 2021-09-02 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
| 5 | |||
| 6 | #define SZ_ERROR_ABORT 100 | ||
| 7 | |||
| 8 | #ifdef _MSC_VER | ||
| 9 | #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <windows.h> | ||
| 13 | #include <ShlObj.h> | ||
| 14 | |||
| 15 | #include "../../7z.h" | ||
| 16 | #include "../../7zAlloc.h" | ||
| 17 | #include "../../7zCrc.h" | ||
| 18 | #include "../../7zFile.h" | ||
| 19 | #include "../../7zVersion.h" | ||
| 20 | #include "../../CpuArch.h" | ||
| 21 | #include "../../DllSecur.h" | ||
| 22 | |||
| 23 | #include "resource.h" | ||
| 24 | |||
| 25 | #define LLL_(quote) L##quote | ||
| 26 | #define LLL(quote) LLL_(quote) | ||
| 27 | |||
| 28 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | ||
| 29 | |||
| 30 | #define wcscat lstrcatW | ||
| 31 | #define wcslen lstrlenW | ||
| 32 | #define wcscpy lstrcpyW | ||
| 33 | // wcsncpy() and lstrcpynW() work differently. We don't use them. | ||
| 34 | |||
| 35 | |||
| 36 | #define kInputBufSize ((size_t)1 << 18) | ||
| 37 | |||
| 38 | |||
| 39 | #define _7ZIP_CUR_VER ((MY_VER_MAJOR << 16) | MY_VER_MINOR) | ||
| 40 | #define _7ZIP_DLL_VER_COMPAT ((16 << 16) | 3) | ||
| 41 | |||
| 42 | static LPCSTR const k_7zip = "7-Zip"; | ||
| 43 | |||
| 44 | static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip"; | ||
| 45 | |||
| 46 | // #define _64BIT_INSTALLER 1 | ||
| 47 | |||
| 48 | #ifdef _WIN64 | ||
| 49 | #define _64BIT_INSTALLER 1 | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #define k_7zip_with_Ver_base L"7-Zip " LLL(MY_VERSION) | ||
| 53 | |||
| 54 | #ifdef _64BIT_INSTALLER | ||
| 55 | |||
| 56 | // #define USE_7ZIP_32_DLL | ||
| 57 | |||
| 58 | #if defined(_M_ARM64) || defined(_M_ARM) | ||
| 59 | #define k_Postfix L" (arm64)" | ||
| 60 | #else | ||
| 61 | #define k_Postfix L" (x64)" | ||
| 62 | #define USE_7ZIP_32_DLL | ||
| 63 | #endif | ||
| 64 | #else | ||
| 65 | #if defined(_M_ARM64) || defined(_M_ARM) | ||
| 66 | #define k_Postfix L" (arm)" | ||
| 67 | #else | ||
| 68 | // #define k_Postfix L" (x86)" | ||
| 69 | #define k_Postfix | ||
| 70 | #endif | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #define k_7zip_with_Ver k_7zip_with_Ver_base k_Postfix | ||
| 74 | |||
| 75 | |||
| 76 | static LPCWSTR const k_7zip_with_Ver_str = k_7zip_with_Ver; | ||
| 77 | |||
| 78 | static LPCWSTR const k_7zip_Setup = k_7zip_with_Ver L" Setup"; | ||
| 79 | |||
| 80 | static LPCWSTR const k_Reg_Path = L"Path"; | ||
| 81 | |||
| 82 | static LPCWSTR const k_Reg_Path32 = L"Path" | ||
| 83 | #ifdef _64BIT_INSTALLER | ||
| 84 | L"64" | ||
| 85 | #else | ||
| 86 | L"32" | ||
| 87 | #endif | ||
| 88 | ; | ||
| 89 | |||
| 90 | #if defined(_64BIT_INSTALLER) && !defined(_WIN64) | ||
| 91 | #define k_Reg_WOW_Flag KEY_WOW64_64KEY | ||
| 92 | #else | ||
| 93 | #define k_Reg_WOW_Flag 0 | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #ifdef _WIN64 | ||
| 97 | #define k_Reg_WOW_Flag_32 KEY_WOW64_32KEY | ||
| 98 | #else | ||
| 99 | #define k_Reg_WOW_Flag_32 0 | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #define k_7zip_CLSID L"{23170F69-40C1-278A-1000-000100020000}" | ||
| 103 | |||
| 104 | static LPCWSTR const k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID; | ||
| 105 | static LPCWSTR const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32"; | ||
| 106 | |||
| 107 | #define g_AllUsers True | ||
| 108 | |||
| 109 | static BoolInt g_Install_was_Pressed; | ||
| 110 | static BoolInt g_Finished; | ||
| 111 | static BoolInt g_SilentMode; | ||
| 112 | |||
| 113 | static HWND g_HWND; | ||
| 114 | static HWND g_Path_HWND; | ||
| 115 | static HWND g_InfoLine_HWND; | ||
| 116 | static HWND g_Progress_HWND; | ||
| 117 | |||
| 118 | static DWORD g_TotalSize; | ||
| 119 | |||
| 120 | static WCHAR cmd[MAX_PATH + 4]; | ||
| 121 | static WCHAR cmdError[MAX_PATH + 4]; | ||
| 122 | static WCHAR path[MAX_PATH * 2 + 40]; | ||
| 123 | |||
| 124 | |||
| 125 | // #define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c))) | ||
| 126 | |||
| 127 | |||
| 128 | static void CpyAscii(wchar_t *dest, const char *s) | ||
| 129 | { | ||
| 130 | for (;;) | ||
| 131 | { | ||
| 132 | Byte b = (Byte)*s++; | ||
| 133 | *dest++ = b; | ||
| 134 | if (b == 0) | ||
| 135 | return; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | static void CatAscii(wchar_t *dest, const char *s) | ||
| 140 | { | ||
| 141 | dest += wcslen(dest); | ||
| 142 | CpyAscii(dest, s); | ||
| 143 | } | ||
| 144 | |||
| 145 | static void PrintErrorMessage(const char *s1, const wchar_t *s2) | ||
| 146 | { | ||
| 147 | WCHAR m[MAX_PATH + 512]; | ||
| 148 | m[0] = 0; | ||
| 149 | CatAscii(m, "ERROR:"); | ||
| 150 | if (s1) | ||
| 151 | { | ||
| 152 | CatAscii(m, "\n"); | ||
| 153 | CatAscii(m, s1); | ||
| 154 | } | ||
| 155 | if (s2) | ||
| 156 | { | ||
| 157 | CatAscii(m, "\n"); | ||
| 158 | wcscat(m, s2); | ||
| 159 | } | ||
| 160 | MessageBoxW(g_HWND, m, k_7zip_with_Ver_str, MB_ICONERROR | MB_OK); | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | typedef DWORD (WINAPI * Func_GetFileVersionInfoSizeW)(LPCWSTR lptstrFilename, LPDWORD lpdwHandle); | ||
| 165 | typedef BOOL (WINAPI * Func_GetFileVersionInfoW)(LPCWSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData); | ||
| 166 | typedef BOOL (WINAPI * Func_VerQueryValueW)(const LPVOID pBlock, LPWSTR lpSubBlock, LPVOID * lplpBuffer, PUINT puLen); | ||
| 167 | |||
| 168 | static HMODULE g_version_dll_hModule; | ||
| 169 | |||
| 170 | static DWORD GetFileVersion(LPCWSTR s) | ||
| 171 | { | ||
| 172 | DWORD size = 0; | ||
| 173 | void *vi = NULL; | ||
| 174 | DWORD version = 0; | ||
| 175 | |||
| 176 | Func_GetFileVersionInfoSizeW my_GetFileVersionInfoSizeW; | ||
| 177 | Func_GetFileVersionInfoW my_GetFileVersionInfoW; | ||
| 178 | Func_VerQueryValueW my_VerQueryValueW; | ||
| 179 | |||
| 180 | if (!g_version_dll_hModule) | ||
| 181 | { | ||
| 182 | wchar_t buf[MAX_PATH + 100]; | ||
| 183 | { | ||
| 184 | unsigned len = GetSystemDirectoryW(buf, MAX_PATH + 2); | ||
| 185 | if (len == 0 || len > MAX_PATH) | ||
| 186 | return 0; | ||
| 187 | } | ||
| 188 | { | ||
| 189 | unsigned pos = (unsigned)lstrlenW(buf); | ||
| 190 | if (buf[pos - 1] != '\\') | ||
| 191 | buf[pos++] = '\\'; | ||
| 192 | lstrcpyW(buf + pos, L"version.dll"); | ||
| 193 | } | ||
| 194 | g_version_dll_hModule = LoadLibraryW(buf); | ||
| 195 | if (!g_version_dll_hModule) | ||
| 196 | return 0; | ||
| 197 | } | ||
| 198 | |||
| 199 | my_GetFileVersionInfoSizeW = (Func_GetFileVersionInfoSizeW)GetProcAddress(g_version_dll_hModule, "GetFileVersionInfoSizeW"); | ||
| 200 | my_GetFileVersionInfoW = (Func_GetFileVersionInfoW)GetProcAddress(g_version_dll_hModule, "GetFileVersionInfoW"); | ||
| 201 | my_VerQueryValueW = (Func_VerQueryValueW)GetProcAddress(g_version_dll_hModule, "VerQueryValueW"); | ||
| 202 | |||
| 203 | if (!my_GetFileVersionInfoSizeW | ||
| 204 | || !my_GetFileVersionInfoW | ||
| 205 | || !my_VerQueryValueW) | ||
| 206 | return 0; | ||
| 207 | |||
| 208 | size = my_GetFileVersionInfoSizeW(s, NULL); | ||
| 209 | if (size == 0) | ||
| 210 | return 0; | ||
| 211 | |||
| 212 | vi = malloc(size); | ||
| 213 | if (!vi) | ||
| 214 | return 0; | ||
| 215 | |||
| 216 | if (my_GetFileVersionInfoW(s, 0, size, vi)) | ||
| 217 | { | ||
| 218 | VS_FIXEDFILEINFO *fi = NULL; | ||
| 219 | UINT fiLen = 0; | ||
| 220 | if (my_VerQueryValueW(vi, L"\\", (LPVOID *)&fi, &fiLen)) | ||
| 221 | version = fi->dwFileVersionMS; | ||
| 222 | } | ||
| 223 | |||
| 224 | free(vi); | ||
| 225 | return version; | ||
| 226 | } | ||
| 227 | |||
| 228 | |||
| 229 | static WRes MyCreateDir(LPCWSTR name) | ||
| 230 | { | ||
| 231 | return CreateDirectoryW(name, NULL) ? 0 : GetLastError(); | ||
| 232 | } | ||
| 233 | |||
| 234 | #define IS_SEPAR(c) (c == WCHAR_PATH_SEPARATOR) | ||
| 235 | #define IS_LETTER_CHAR(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) | ||
| 236 | #define IS_DRIVE_PATH(s) (IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2])) | ||
| 237 | |||
| 238 | static int ReverseFind_PathSepar(const wchar_t *s) | ||
| 239 | { | ||
| 240 | int separ = -1; | ||
| 241 | int i; | ||
| 242 | for (i = 0;; i++) | ||
| 243 | { | ||
| 244 | wchar_t c = s[i]; | ||
| 245 | if (c == 0) | ||
| 246 | return separ; | ||
| 247 | if (IS_SEPAR(c)) | ||
| 248 | separ = i; | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | static WRes CreateComplexDir() | ||
| 253 | { | ||
| 254 | WCHAR s[MAX_PATH + 10]; | ||
| 255 | |||
| 256 | unsigned prefixSize = 0; | ||
| 257 | WRes wres; | ||
| 258 | |||
| 259 | { | ||
| 260 | size_t len = wcslen(path); | ||
| 261 | if (len > MAX_PATH) | ||
| 262 | return ERROR_INVALID_NAME; | ||
| 263 | wcscpy(s, path); | ||
| 264 | } | ||
| 265 | |||
| 266 | if (IS_DRIVE_PATH(s)) | ||
| 267 | prefixSize = 3; | ||
| 268 | else if (IS_SEPAR(s[0]) && IS_SEPAR(s[1])) | ||
| 269 | prefixSize = 2; | ||
| 270 | else | ||
| 271 | return ERROR_INVALID_NAME; | ||
| 272 | |||
| 273 | { | ||
| 274 | DWORD attrib = GetFileAttributesW(s); | ||
| 275 | if (attrib != INVALID_FILE_ATTRIBUTES) | ||
| 276 | return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ? 0 : ERROR_ALREADY_EXISTS; | ||
| 277 | } | ||
| 278 | |||
| 279 | wres = MyCreateDir(s); | ||
| 280 | if (wres == 0 || wres == ERROR_ALREADY_EXISTS) | ||
| 281 | return 0; | ||
| 282 | |||
| 283 | { | ||
| 284 | size_t len = wcslen(s); | ||
| 285 | { | ||
| 286 | int pos = ReverseFind_PathSepar(s); | ||
| 287 | if (pos < 0) | ||
| 288 | return wres; | ||
| 289 | if ((unsigned)pos < prefixSize) | ||
| 290 | return wres; | ||
| 291 | if ((unsigned)pos == len - 1) | ||
| 292 | { | ||
| 293 | if (len == 1) | ||
| 294 | return 0; | ||
| 295 | s[pos] = 0; | ||
| 296 | len = pos; | ||
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 | for (;;) | ||
| 301 | { | ||
| 302 | int pos; | ||
| 303 | wres = MyCreateDir(s); | ||
| 304 | if (wres == 0) | ||
| 305 | break; | ||
| 306 | if (wres == ERROR_ALREADY_EXISTS) | ||
| 307 | { | ||
| 308 | DWORD attrib = GetFileAttributesW(s); | ||
| 309 | if (attrib != INVALID_FILE_ATTRIBUTES) | ||
| 310 | if ((attrib & FILE_ATTRIBUTE_DIRECTORY) == 0) | ||
| 311 | return ERROR_ALREADY_EXISTS; | ||
| 312 | break; | ||
| 313 | } | ||
| 314 | pos = ReverseFind_PathSepar(s); | ||
| 315 | if (pos < 0 || pos == 0 || (unsigned)pos < prefixSize) | ||
| 316 | return wres; | ||
| 317 | s[pos] = 0; | ||
| 318 | } | ||
| 319 | |||
| 320 | for (;;) | ||
| 321 | { | ||
| 322 | size_t pos = wcslen(s); | ||
| 323 | if (pos >= len) | ||
| 324 | return 0; | ||
| 325 | s[pos] = CHAR_PATH_SEPARATOR; | ||
| 326 | wres = MyCreateDir(s); | ||
| 327 | if (wres != 0) | ||
| 328 | return wres; | ||
| 329 | } | ||
| 330 | } | ||
| 331 | } | ||
| 332 | |||
| 333 | |||
| 334 | static int MyRegistry_QueryString(HKEY hKey, LPCWSTR name, LPWSTR dest) | ||
| 335 | { | ||
| 336 | DWORD cnt = MAX_PATH * sizeof(name[0]); | ||
| 337 | DWORD type = 0; | ||
| 338 | LONG res = RegQueryValueExW(hKey, name, NULL, &type, (LPBYTE)dest, (DWORD *)&cnt); | ||
| 339 | if (type != REG_SZ) | ||
| 340 | return False; | ||
| 341 | return res == ERROR_SUCCESS; | ||
| 342 | } | ||
| 343 | |||
| 344 | static int MyRegistry_QueryString2(HKEY hKey, LPCWSTR keyName, LPCWSTR valName, LPWSTR dest) | ||
| 345 | { | ||
| 346 | HKEY key = 0; | ||
| 347 | LONG res = RegOpenKeyExW(hKey, keyName, 0, KEY_READ | k_Reg_WOW_Flag, &key); | ||
| 348 | if (res != ERROR_SUCCESS) | ||
| 349 | return False; | ||
| 350 | { | ||
| 351 | BoolInt res2 = MyRegistry_QueryString(key, valName, dest); | ||
| 352 | RegCloseKey(key); | ||
| 353 | return res2; | ||
| 354 | } | ||
| 355 | } | ||
| 356 | |||
| 357 | static LONG MyRegistry_SetString(HKEY hKey, LPCWSTR name, LPCWSTR val) | ||
| 358 | { | ||
| 359 | return RegSetValueExW(hKey, name, 0, REG_SZ, | ||
| 360 | (const BYTE *)val, (DWORD)(wcslen(val) + 1) * sizeof(val[0])); | ||
| 361 | } | ||
| 362 | |||
| 363 | static LONG MyRegistry_SetDWORD(HKEY hKey, LPCWSTR name, DWORD val) | ||
| 364 | { | ||
| 365 | return RegSetValueExW(hKey, name, 0, REG_DWORD, (const BYTE *)&val, sizeof(DWORD)); | ||
| 366 | } | ||
| 367 | |||
| 368 | |||
| 369 | static LONG MyRegistry_CreateKey(HKEY parentKey, LPCWSTR name, HKEY *destKey) | ||
| 370 | { | ||
| 371 | return RegCreateKeyExW(parentKey, name, 0, NULL, | ||
| 372 | REG_OPTION_NON_VOLATILE, | ||
| 373 | KEY_ALL_ACCESS | k_Reg_WOW_Flag, | ||
| 374 | NULL, destKey, NULL); | ||
| 375 | } | ||
| 376 | |||
| 377 | static LONG MyRegistry_CreateKeyAndVal(HKEY parentKey, LPCWSTR keyName, LPCWSTR valName, LPCWSTR val) | ||
| 378 | { | ||
| 379 | HKEY destKey = 0; | ||
| 380 | LONG res = MyRegistry_CreateKey(parentKey, keyName, &destKey); | ||
| 381 | if (res == ERROR_SUCCESS) | ||
| 382 | { | ||
| 383 | res = MyRegistry_SetString(destKey, valName, val); | ||
| 384 | /* res = */ RegCloseKey(destKey); | ||
| 385 | } | ||
| 386 | return res; | ||
| 387 | } | ||
| 388 | |||
| 389 | |||
| 390 | #ifdef USE_7ZIP_32_DLL | ||
| 391 | |||
| 392 | static LONG MyRegistry_CreateKey_32(HKEY parentKey, LPCWSTR name, HKEY *destKey) | ||
| 393 | { | ||
| 394 | return RegCreateKeyExW(parentKey, name, 0, NULL, | ||
| 395 | REG_OPTION_NON_VOLATILE, | ||
| 396 | KEY_ALL_ACCESS | k_Reg_WOW_Flag_32, | ||
| 397 | NULL, destKey, NULL); | ||
| 398 | } | ||
| 399 | |||
| 400 | static LONG MyRegistry_CreateKeyAndVal_32(HKEY parentKey, LPCWSTR keyName, LPCWSTR valName, LPCWSTR val) | ||
| 401 | { | ||
| 402 | HKEY destKey = 0; | ||
| 403 | LONG res = MyRegistry_CreateKey_32(parentKey, keyName, &destKey); | ||
| 404 | if (res == ERROR_SUCCESS) | ||
| 405 | { | ||
| 406 | res = MyRegistry_SetString(destKey, valName, val); | ||
| 407 | /* res = */ RegCloseKey(destKey); | ||
| 408 | } | ||
| 409 | return res; | ||
| 410 | } | ||
| 411 | |||
| 412 | #endif | ||
| 413 | |||
| 414 | |||
| 415 | |||
| 416 | #ifdef UNDER_CE | ||
| 417 | #define kBufSize (1 << 13) | ||
| 418 | #else | ||
| 419 | #define kBufSize (1 << 15) | ||
| 420 | #endif | ||
| 421 | |||
| 422 | #define kSignatureSearchLimit (1 << 22) | ||
| 423 | |||
| 424 | static BoolInt FindSignature(CSzFile *stream, UInt64 *resPos) | ||
| 425 | { | ||
| 426 | Byte buf[kBufSize]; | ||
| 427 | size_t numPrevBytes = 0; | ||
| 428 | *resPos = 0; | ||
| 429 | |||
| 430 | for (;;) | ||
| 431 | { | ||
| 432 | size_t processed, pos; | ||
| 433 | if (*resPos > kSignatureSearchLimit) | ||
| 434 | return False; | ||
| 435 | processed = kBufSize - numPrevBytes; | ||
| 436 | if (File_Read(stream, buf + numPrevBytes, &processed) != 0) | ||
| 437 | return False; | ||
| 438 | processed += numPrevBytes; | ||
| 439 | if (processed < k7zStartHeaderSize || | ||
| 440 | (processed == k7zStartHeaderSize && numPrevBytes != 0)) | ||
| 441 | return False; | ||
| 442 | processed -= k7zStartHeaderSize; | ||
| 443 | for (pos = 0; pos <= processed; pos++) | ||
| 444 | { | ||
| 445 | for (; pos <= processed && buf[pos] != '7'; pos++); | ||
| 446 | if (pos > processed) | ||
| 447 | break; | ||
| 448 | if (memcmp(buf + pos, k7zSignature, k7zSignatureSize) == 0) | ||
| 449 | if (CrcCalc(buf + pos + 12, 20) == GetUi32(buf + pos + 8)) | ||
| 450 | { | ||
| 451 | *resPos += pos; | ||
| 452 | return True; | ||
| 453 | } | ||
| 454 | } | ||
| 455 | *resPos += processed; | ||
| 456 | numPrevBytes = k7zStartHeaderSize; | ||
| 457 | memmove(buf, buf + processed, k7zStartHeaderSize); | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | static void HexToString(UInt32 val, WCHAR *s) | ||
| 462 | { | ||
| 463 | UInt64 v = val; | ||
| 464 | unsigned i; | ||
| 465 | for (i = 1;; i++) | ||
| 466 | { | ||
| 467 | v >>= 4; | ||
| 468 | if (v == 0) | ||
| 469 | break; | ||
| 470 | } | ||
| 471 | s[i] = 0; | ||
| 472 | do | ||
| 473 | { | ||
| 474 | unsigned t = (unsigned)((val & 0xF)); | ||
| 475 | val >>= 4; | ||
| 476 | s[--i] = (WCHAR)(unsigned)((t < 10) ? ('0' + t) : ('A' + (t - 10))); | ||
| 477 | } | ||
| 478 | while (i); | ||
| 479 | } | ||
| 480 | |||
| 481 | |||
| 482 | #ifndef UNDER_CE | ||
| 483 | |||
| 484 | static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM data) | ||
| 485 | { | ||
| 486 | UNUSED_VAR(lp) | ||
| 487 | UNUSED_VAR(data) | ||
| 488 | UNUSED_VAR(hwnd) | ||
| 489 | |||
| 490 | switch (uMsg) | ||
| 491 | { | ||
| 492 | case BFFM_INITIALIZED: | ||
| 493 | { | ||
| 494 | SendMessage(hwnd, BFFM_SETSELECTIONW, TRUE, data); | ||
| 495 | break; | ||
| 496 | } | ||
| 497 | case BFFM_SELCHANGED: | ||
| 498 | { | ||
| 499 | // show selected path for BIF_STATUSTEXT | ||
| 500 | WCHAR dir[MAX_PATH]; | ||
| 501 | if (!SHGetPathFromIDListW((LPITEMIDLIST)lp, dir)) | ||
| 502 | dir[0] = 0; | ||
| 503 | SendMessage(hwnd, BFFM_SETSTATUSTEXTW, 0, (LPARAM)dir); | ||
| 504 | break; | ||
| 505 | } | ||
| 506 | default: | ||
| 507 | break; | ||
| 508 | } | ||
| 509 | return 0; | ||
| 510 | } | ||
| 511 | |||
| 512 | static BoolInt MyBrowseForFolder(HWND owner, LPCWSTR title, UINT ulFlags, | ||
| 513 | LPCWSTR initialFolder, LPWSTR resultPath) | ||
| 514 | { | ||
| 515 | WCHAR displayName[MAX_PATH]; | ||
| 516 | BROWSEINFOW browseInfo; | ||
| 517 | |||
| 518 | displayName[0] = 0; | ||
| 519 | browseInfo.hwndOwner = owner; | ||
| 520 | browseInfo.pidlRoot = NULL; | ||
| 521 | |||
| 522 | // there are Unicode/Astring problems in some WinCE SDK ? | ||
| 523 | browseInfo.pszDisplayName = displayName; | ||
| 524 | browseInfo.lpszTitle = title; | ||
| 525 | browseInfo.ulFlags = ulFlags; | ||
| 526 | browseInfo.lpfn = (initialFolder != NULL) ? BrowseCallbackProc : NULL; | ||
| 527 | browseInfo.lParam = (LPARAM)initialFolder; | ||
| 528 | { | ||
| 529 | LPITEMIDLIST idlist = SHBrowseForFolderW(&browseInfo); | ||
| 530 | if (idlist) | ||
| 531 | { | ||
| 532 | SHGetPathFromIDListW(idlist, resultPath); | ||
| 533 | // free idlist | ||
| 534 | // CoTaskMemFree(idlist); | ||
| 535 | return True; | ||
| 536 | } | ||
| 537 | return False; | ||
| 538 | } | ||
| 539 | } | ||
| 540 | |||
| 541 | #endif | ||
| 542 | |||
| 543 | static void NormalizePrefix(WCHAR *s) | ||
| 544 | { | ||
| 545 | size_t i = 0; | ||
| 546 | |||
| 547 | for (;; i++) | ||
| 548 | { | ||
| 549 | wchar_t c = s[i]; | ||
| 550 | if (c == 0) | ||
| 551 | break; | ||
| 552 | if (c == '/') | ||
| 553 | s[i] = WCHAR_PATH_SEPARATOR; | ||
| 554 | } | ||
| 555 | |||
| 556 | if (i != 0 && s[i - 1] != WCHAR_PATH_SEPARATOR) | ||
| 557 | { | ||
| 558 | s[i] = WCHAR_PATH_SEPARATOR; | ||
| 559 | s[i + 1] = 0; | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | static char MyCharLower_Ascii(char c) | ||
| 564 | { | ||
| 565 | if (c >= 'A' && c <= 'Z') | ||
| 566 | return (char)((unsigned char)c + 0x20); | ||
| 567 | return c; | ||
| 568 | } | ||
| 569 | |||
| 570 | static wchar_t MyWCharLower_Ascii(wchar_t c) | ||
| 571 | { | ||
| 572 | if (c >= 'A' && c <= 'Z') | ||
| 573 | return (wchar_t)(c + 0x20); | ||
| 574 | return c; | ||
| 575 | } | ||
| 576 | |||
| 577 | static LPCWSTR FindSubString(LPCWSTR s1, const char *s2) | ||
| 578 | { | ||
| 579 | for (;;) | ||
| 580 | { | ||
| 581 | unsigned i; | ||
| 582 | if (*s1 == 0) | ||
| 583 | return NULL; | ||
| 584 | for (i = 0;; i++) | ||
| 585 | { | ||
| 586 | Byte b = s2[i]; | ||
| 587 | if (b == 0) | ||
| 588 | return s1; | ||
| 589 | if (MyWCharLower_Ascii(s1[i]) != (Byte)MyCharLower_Ascii(b)) | ||
| 590 | { | ||
| 591 | s1++; | ||
| 592 | break; | ||
| 593 | } | ||
| 594 | } | ||
| 595 | } | ||
| 596 | } | ||
| 597 | |||
| 598 | static void Set7zipPostfix(WCHAR *s) | ||
| 599 | { | ||
| 600 | NormalizePrefix(s); | ||
| 601 | if (FindSubString(s, "7-Zip")) | ||
| 602 | return; | ||
| 603 | CatAscii(s, "7-Zip\\"); | ||
| 604 | } | ||
| 605 | |||
| 606 | |||
| 607 | static int Install(void); | ||
| 608 | |||
| 609 | static void OnClose() | ||
| 610 | { | ||
| 611 | if (g_Install_was_Pressed && !g_Finished) | ||
| 612 | { | ||
| 613 | if (MessageBoxW(g_HWND, | ||
| 614 | L"Do you want to cancel " k_7zip_with_Ver L" installation?", | ||
| 615 | k_7zip_with_Ver, | ||
| 616 | MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES) | ||
| 617 | return; | ||
| 618 | } | ||
| 619 | DestroyWindow(g_HWND); | ||
| 620 | g_HWND = NULL; | ||
| 621 | } | ||
| 622 | |||
| 623 | static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 624 | { | ||
| 625 | // UNUSED_VAR(hwnd) | ||
| 626 | UNUSED_VAR(lParam) | ||
| 627 | |||
| 628 | switch (message) | ||
| 629 | { | ||
| 630 | case WM_INITDIALOG: | ||
| 631 | g_Path_HWND = GetDlgItem(hwnd, IDE_EXTRACT_PATH); | ||
| 632 | g_InfoLine_HWND = GetDlgItem(hwnd, IDT_CUR_FILE); | ||
| 633 | g_Progress_HWND = GetDlgItem(hwnd, IDC_PROGRESS); | ||
| 634 | |||
| 635 | SetWindowTextW(hwnd, k_7zip_Setup); | ||
| 636 | SetDlgItemTextW(hwnd, IDE_EXTRACT_PATH, path); | ||
| 637 | |||
| 638 | ShowWindow(g_Progress_HWND, SW_HIDE); | ||
| 639 | ShowWindow(g_InfoLine_HWND, SW_HIDE); | ||
| 640 | |||
| 641 | break; | ||
| 642 | |||
| 643 | case WM_COMMAND: | ||
| 644 | switch (LOWORD(wParam)) | ||
| 645 | { | ||
| 646 | case IDOK: | ||
| 647 | { | ||
| 648 | if (g_Finished) | ||
| 649 | { | ||
| 650 | OnClose(); | ||
| 651 | break; | ||
| 652 | } | ||
| 653 | if (!g_Install_was_Pressed) | ||
| 654 | { | ||
| 655 | SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(hwnd, IDCANCEL), TRUE); | ||
| 656 | |||
| 657 | EnableWindow(g_Path_HWND, FALSE); | ||
| 658 | EnableWindow(GetDlgItem(hwnd, IDB_EXTRACT_SET_PATH), FALSE); | ||
| 659 | EnableWindow(GetDlgItem(hwnd, IDOK), FALSE); | ||
| 660 | |||
| 661 | g_Install_was_Pressed = True; | ||
| 662 | return TRUE; | ||
| 663 | } | ||
| 664 | break; | ||
| 665 | } | ||
| 666 | |||
| 667 | case IDCANCEL: | ||
| 668 | { | ||
| 669 | OnClose(); | ||
| 670 | break; | ||
| 671 | } | ||
| 672 | |||
| 673 | case IDB_EXTRACT_SET_PATH: | ||
| 674 | { | ||
| 675 | #ifndef UNDER_CE | ||
| 676 | |||
| 677 | WCHAR s[MAX_PATH]; | ||
| 678 | WCHAR s2[MAX_PATH]; | ||
| 679 | GetDlgItemTextW(hwnd, IDE_EXTRACT_PATH, s, MAX_PATH); | ||
| 680 | if (MyBrowseForFolder(hwnd, L"Select the folder for installation:" , | ||
| 681 | 0 | ||
| 682 | | BIF_NEWDIALOGSTYLE // 5.0 of ?.dll ? | ||
| 683 | | BIF_RETURNONLYFSDIRS | ||
| 684 | // | BIF_STATUSTEXT // doesn't work for BIF_NEWDIALOGSTYLE | ||
| 685 | , s, s2)) | ||
| 686 | { | ||
| 687 | Set7zipPostfix(s2); | ||
| 688 | SetDlgItemTextW(hwnd, IDE_EXTRACT_PATH, s2); | ||
| 689 | } | ||
| 690 | |||
| 691 | #endif | ||
| 692 | break; | ||
| 693 | } | ||
| 694 | |||
| 695 | default: return FALSE; | ||
| 696 | } | ||
| 697 | break; | ||
| 698 | |||
| 699 | case WM_CLOSE: | ||
| 700 | OnClose(); | ||
| 701 | break; | ||
| 702 | /* | ||
| 703 | case WM_DESTROY: | ||
| 704 | PostQuitMessage(0); | ||
| 705 | return TRUE; | ||
| 706 | */ | ||
| 707 | default: | ||
| 708 | return FALSE; | ||
| 709 | } | ||
| 710 | |||
| 711 | return TRUE; | ||
| 712 | } | ||
| 713 | |||
| 714 | |||
| 715 | |||
| 716 | static LONG SetRegKey_Path2(HKEY parentKey) | ||
| 717 | { | ||
| 718 | HKEY destKey = 0; | ||
| 719 | LONG res = MyRegistry_CreateKey(parentKey, k_Reg_Software_7zip, &destKey); | ||
| 720 | if (res == ERROR_SUCCESS) | ||
| 721 | { | ||
| 722 | res = MyRegistry_SetString(destKey, k_Reg_Path32, path); | ||
| 723 | /* res = */ MyRegistry_SetString(destKey, k_Reg_Path, path); | ||
| 724 | /* res = */ RegCloseKey(destKey); | ||
| 725 | } | ||
| 726 | return res; | ||
| 727 | } | ||
| 728 | |||
| 729 | static void SetRegKey_Path() | ||
| 730 | { | ||
| 731 | SetRegKey_Path2(HKEY_CURRENT_USER); | ||
| 732 | SetRegKey_Path2(HKEY_LOCAL_MACHINE); | ||
| 733 | } | ||
| 734 | |||
| 735 | |||
| 736 | static HRESULT CreateShellLink(LPCWSTR srcPath, LPCWSTR targetPath) | ||
| 737 | { | ||
| 738 | IShellLinkW* sl; | ||
| 739 | |||
| 740 | // CoInitialize has already been called. | ||
| 741 | HRESULT hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID*)&sl); | ||
| 742 | |||
| 743 | if (SUCCEEDED(hres)) | ||
| 744 | { | ||
| 745 | IPersistFile* pf; | ||
| 746 | |||
| 747 | sl->lpVtbl->SetPath(sl, targetPath); | ||
| 748 | // sl->lpVtbl->SetDescription(sl, description); | ||
| 749 | hres = sl->lpVtbl->QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf); | ||
| 750 | |||
| 751 | if (SUCCEEDED(hres)) | ||
| 752 | { | ||
| 753 | hres = pf->lpVtbl->Save(pf, srcPath, TRUE); | ||
| 754 | pf->lpVtbl->Release(pf); | ||
| 755 | } | ||
| 756 | sl->lpVtbl->Release(sl); | ||
| 757 | } | ||
| 758 | |||
| 759 | return hres; | ||
| 760 | } | ||
| 761 | |||
| 762 | static void SetShellProgramsGroup(HWND hwndOwner) | ||
| 763 | { | ||
| 764 | #ifdef UNDER_CE | ||
| 765 | |||
| 766 | // CpyAscii(link, "\\Program Files\\"); | ||
| 767 | UNUSED_VAR(hwndOwner) | ||
| 768 | |||
| 769 | #else | ||
| 770 | |||
| 771 | unsigned i = (g_AllUsers ? 0 : 2); | ||
| 772 | |||
| 773 | for (; i < 3; i++) | ||
| 774 | { | ||
| 775 | BoolInt isOK = True; | ||
| 776 | WCHAR link[MAX_PATH + 40]; | ||
| 777 | WCHAR destPath[MAX_PATH + 40]; | ||
| 778 | |||
| 779 | link[0] = 0; | ||
| 780 | |||
| 781 | if (SHGetFolderPathW(hwndOwner, | ||
| 782 | i == 1 ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, | ||
| 783 | NULL, SHGFP_TYPE_CURRENT, link) != S_OK) | ||
| 784 | continue; | ||
| 785 | |||
| 786 | NormalizePrefix(link); | ||
| 787 | CatAscii(link, k_7zip); | ||
| 788 | // CatAscii(link, "2"); | ||
| 789 | |||
| 790 | if (i != 0) | ||
| 791 | MyCreateDir(link); | ||
| 792 | |||
| 793 | NormalizePrefix(link); | ||
| 794 | |||
| 795 | { | ||
| 796 | unsigned baseLen = (unsigned)wcslen(link); | ||
| 797 | unsigned k; | ||
| 798 | |||
| 799 | for (k = 0; k < 2; k++) | ||
| 800 | { | ||
| 801 | CpyAscii(link + baseLen, k == 0 ? | ||
| 802 | "7-Zip File Manager.lnk" : | ||
| 803 | "7-Zip Help.lnk" | ||
| 804 | ); | ||
| 805 | wcscpy(destPath, path); | ||
| 806 | CatAscii(destPath, k == 0 ? | ||
| 807 | "7zFM.exe" : | ||
| 808 | "7-zip.chm"); | ||
| 809 | |||
| 810 | if (i == 0) | ||
| 811 | DeleteFileW(link); | ||
| 812 | else if (CreateShellLink(link, destPath) != S_OK) | ||
| 813 | isOK = False; | ||
| 814 | } | ||
| 815 | } | ||
| 816 | |||
| 817 | if (i != 0 && isOK) | ||
| 818 | break; | ||
| 819 | } | ||
| 820 | |||
| 821 | #endif | ||
| 822 | } | ||
| 823 | |||
| 824 | static LPCWSTR const k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"; | ||
| 825 | static LPCWSTR const k_7zip_ShellExtension = L"7-Zip Shell Extension"; | ||
| 826 | |||
| 827 | static void WriteCLSID() | ||
| 828 | { | ||
| 829 | HKEY destKey; | ||
| 830 | LONG res; | ||
| 831 | |||
| 832 | #ifdef USE_7ZIP_32_DLL | ||
| 833 | |||
| 834 | MyRegistry_CreateKeyAndVal_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip, NULL, k_7zip_ShellExtension); | ||
| 835 | |||
| 836 | res = MyRegistry_CreateKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc, &destKey); | ||
| 837 | |||
| 838 | if (res == ERROR_SUCCESS) | ||
| 839 | { | ||
| 840 | WCHAR destPath[MAX_PATH + 40]; | ||
| 841 | wcscpy(destPath, path); | ||
| 842 | CatAscii(destPath, "7-zip32.dll"); | ||
| 843 | /* res = */ MyRegistry_SetString(destKey, NULL, destPath); | ||
| 844 | /* res = */ MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment"); | ||
| 845 | // DeleteRegValue(destKey, L"InprocServer32"); | ||
| 846 | /* res = */ RegCloseKey(destKey); | ||
| 847 | } | ||
| 848 | |||
| 849 | #endif | ||
| 850 | |||
| 851 | |||
| 852 | MyRegistry_CreateKeyAndVal(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip, NULL, k_7zip_ShellExtension); | ||
| 853 | |||
| 854 | destKey = 0; | ||
| 855 | res = MyRegistry_CreateKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc, &destKey); | ||
| 856 | |||
| 857 | if (res == ERROR_SUCCESS) | ||
| 858 | { | ||
| 859 | WCHAR destPath[MAX_PATH + 40]; | ||
| 860 | wcscpy(destPath, path); | ||
| 861 | CatAscii(destPath, "7-zip.dll"); | ||
| 862 | /* res = */ MyRegistry_SetString(destKey, NULL, destPath); | ||
| 863 | /* res = */ MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment"); | ||
| 864 | // DeleteRegValue(destKey, L"InprocServer32"); | ||
| 865 | /* res = */ RegCloseKey(destKey); | ||
| 866 | } | ||
| 867 | } | ||
| 868 | |||
| 869 | static LPCSTR const k_ShellEx_Items[] = | ||
| 870 | { | ||
| 871 | "*\\shellex\\ContextMenuHandlers" | ||
| 872 | , "Directory\\shellex\\ContextMenuHandlers" | ||
| 873 | , "Folder\\shellex\\ContextMenuHandlers" | ||
| 874 | , "Directory\\shellex\\DragDropHandlers" | ||
| 875 | , "Drive\\shellex\\DragDropHandlers" | ||
| 876 | }; | ||
| 877 | |||
| 878 | static void WriteShellEx() | ||
| 879 | { | ||
| 880 | unsigned i; | ||
| 881 | WCHAR destPath[MAX_PATH + 40]; | ||
| 882 | |||
| 883 | for (i = 0; i < ARRAY_SIZE(k_ShellEx_Items); i++) | ||
| 884 | { | ||
| 885 | CpyAscii(destPath, k_ShellEx_Items[i]); | ||
| 886 | CatAscii(destPath, "\\7-Zip"); | ||
| 887 | |||
| 888 | #ifdef USE_7ZIP_32_DLL | ||
| 889 | MyRegistry_CreateKeyAndVal_32(HKEY_CLASSES_ROOT, destPath, NULL, k_7zip_CLSID); | ||
| 890 | #endif | ||
| 891 | MyRegistry_CreateKeyAndVal (HKEY_CLASSES_ROOT, destPath, NULL, k_7zip_CLSID); | ||
| 892 | } | ||
| 893 | |||
| 894 | #ifdef USE_7ZIP_32_DLL | ||
| 895 | MyRegistry_CreateKeyAndVal_32(HKEY_LOCAL_MACHINE, k_Shell_Approved, k_7zip_CLSID, k_7zip_ShellExtension); | ||
| 896 | #endif | ||
| 897 | MyRegistry_CreateKeyAndVal (HKEY_LOCAL_MACHINE, k_Shell_Approved, k_7zip_CLSID, k_7zip_ShellExtension); | ||
| 898 | |||
| 899 | |||
| 900 | wcscpy(destPath, path); | ||
| 901 | CatAscii(destPath, "7zFM.exe"); | ||
| 902 | |||
| 903 | { | ||
| 904 | HKEY destKey = 0; | ||
| 905 | LONG res = MyRegistry_CreateKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\7zFM.exe", &destKey); | ||
| 906 | if (res == ERROR_SUCCESS) | ||
| 907 | { | ||
| 908 | MyRegistry_SetString(destKey, NULL, destPath); | ||
| 909 | MyRegistry_SetString(destKey, L"Path", path); | ||
| 910 | RegCloseKey(destKey); | ||
| 911 | } | ||
| 912 | |||
| 913 | } | ||
| 914 | |||
| 915 | { | ||
| 916 | HKEY destKey = 0; | ||
| 917 | LONG res = MyRegistry_CreateKey(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\7-Zip", &destKey); | ||
| 918 | if (res == ERROR_SUCCESS) | ||
| 919 | { | ||
| 920 | MyRegistry_SetString(destKey, L"DisplayName", k_7zip_with_Ver_str); | ||
| 921 | MyRegistry_SetString(destKey, L"DisplayVersion", LLL(MY_VERSION_NUMBERS)); | ||
| 922 | MyRegistry_SetString(destKey, L"DisplayIcon", destPath); | ||
| 923 | MyRegistry_SetString(destKey, L"InstallLocation", path); | ||
| 924 | |||
| 925 | destPath[0] = '\"'; | ||
| 926 | wcscpy(destPath + 1, path); | ||
| 927 | CatAscii(destPath, "Uninstall.exe\""); | ||
| 928 | MyRegistry_SetString(destKey, L"UninstallString", destPath); | ||
| 929 | |||
| 930 | CatAscii(destPath, " /S"); | ||
| 931 | MyRegistry_SetString(destKey, L"QuietUninstallString", destPath); | ||
| 932 | |||
| 933 | MyRegistry_SetDWORD(destKey, L"NoModify", 1); | ||
| 934 | MyRegistry_SetDWORD(destKey, L"NoRepair", 1); | ||
| 935 | |||
| 936 | MyRegistry_SetDWORD(destKey, L"EstimatedSize", g_TotalSize >> 10); | ||
| 937 | |||
| 938 | MyRegistry_SetDWORD(destKey, L"VersionMajor", MY_VER_MAJOR); | ||
| 939 | MyRegistry_SetDWORD(destKey, L"VersionMinor", MY_VER_MINOR); | ||
| 940 | |||
| 941 | MyRegistry_SetString(destKey, L"Publisher", LLL(MY_AUTHOR_NAME)); | ||
| 942 | |||
| 943 | // MyRegistry_SetString(destKey, L"HelpLink", L"http://www.7-zip.org/support.html"); | ||
| 944 | // MyRegistry_SetString(destKey, L"URLInfoAbout", L"http://www.7-zip.org/"); | ||
| 945 | // MyRegistry_SetString(destKey, L"URLUpdateInfo", L"http://www.7-zip.org/"); | ||
| 946 | |||
| 947 | RegCloseKey(destKey); | ||
| 948 | } | ||
| 949 | } | ||
| 950 | } | ||
| 951 | |||
| 952 | |||
| 953 | static const wchar_t *GetCmdParam(const wchar_t *s) | ||
| 954 | { | ||
| 955 | unsigned pos = 0; | ||
| 956 | BoolInt quoteMode = False; | ||
| 957 | for (;; s++) | ||
| 958 | { | ||
| 959 | wchar_t c = *s; | ||
| 960 | if (c == 0 || (c == L' ' && !quoteMode)) | ||
| 961 | break; | ||
| 962 | if (c == L'\"') | ||
| 963 | { | ||
| 964 | quoteMode = !quoteMode; | ||
| 965 | continue; | ||
| 966 | } | ||
| 967 | if (pos >= ARRAY_SIZE(cmd) - 1) | ||
| 968 | exit(1); | ||
| 969 | cmd[pos++] = c; | ||
| 970 | } | ||
| 971 | cmd[pos] = 0; | ||
| 972 | return s; | ||
| 973 | } | ||
| 974 | |||
| 975 | |||
| 976 | static void RemoveQuotes(wchar_t *s) | ||
| 977 | { | ||
| 978 | const wchar_t *src = s; | ||
| 979 | for (;;) | ||
| 980 | { | ||
| 981 | wchar_t c = *src++; | ||
| 982 | if (c == '\"') | ||
| 983 | continue; | ||
| 984 | *s++ = c; | ||
| 985 | if (c == 0) | ||
| 986 | return; | ||
| 987 | } | ||
| 988 | } | ||
| 989 | |||
| 990 | // #define IS_LIMIT_CHAR(c) (c == 0 || c == ' ') | ||
| 991 | |||
| 992 | |||
| 993 | typedef BOOL (WINAPI *Func_IsWow64Process)(HANDLE, PBOOL); | ||
| 994 | |||
| 995 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, | ||
| 996 | #ifdef UNDER_CE | ||
| 997 | LPWSTR | ||
| 998 | #else | ||
| 999 | LPSTR | ||
| 1000 | #endif | ||
| 1001 | lpCmdLine, int nCmdShow) | ||
| 1002 | { | ||
| 1003 | |||
| 1004 | UNUSED_VAR(hPrevInstance) | ||
| 1005 | UNUSED_VAR(lpCmdLine) | ||
| 1006 | UNUSED_VAR(nCmdShow) | ||
| 1007 | |||
| 1008 | #ifndef UNDER_CE | ||
| 1009 | LoadSecurityDlls(); | ||
| 1010 | CoInitialize(NULL); | ||
| 1011 | #endif | ||
| 1012 | |||
| 1013 | CrcGenerateTable(); | ||
| 1014 | |||
| 1015 | { | ||
| 1016 | const wchar_t *s = GetCommandLineW(); | ||
| 1017 | |||
| 1018 | #ifndef UNDER_CE | ||
| 1019 | s = GetCmdParam(s); | ||
| 1020 | #endif | ||
| 1021 | |||
| 1022 | for (;;) | ||
| 1023 | { | ||
| 1024 | { | ||
| 1025 | wchar_t c = *s; | ||
| 1026 | if (c == 0) | ||
| 1027 | break; | ||
| 1028 | if (c == ' ') | ||
| 1029 | { | ||
| 1030 | s++; | ||
| 1031 | continue; | ||
| 1032 | } | ||
| 1033 | } | ||
| 1034 | |||
| 1035 | { | ||
| 1036 | const wchar_t *s2 = GetCmdParam(s); | ||
| 1037 | BoolInt error = True; | ||
| 1038 | if (cmd[0] == '/') | ||
| 1039 | { | ||
| 1040 | if (cmd[1] == 'S') | ||
| 1041 | { | ||
| 1042 | if (cmd[2] == 0) | ||
| 1043 | { | ||
| 1044 | g_SilentMode = True; | ||
| 1045 | error = False; | ||
| 1046 | } | ||
| 1047 | } | ||
| 1048 | else if (cmd[1] == 'D' && cmd[2] == '=') | ||
| 1049 | { | ||
| 1050 | wcscpy(path, cmd + 3); | ||
| 1051 | // RemoveQuotes(path); | ||
| 1052 | error = False; | ||
| 1053 | } | ||
| 1054 | } | ||
| 1055 | s = s2; | ||
| 1056 | if (error && cmdError[0] == 0) | ||
| 1057 | wcscpy(cmdError, cmd); | ||
| 1058 | } | ||
| 1059 | } | ||
| 1060 | |||
| 1061 | if (cmdError[0] != 0) | ||
| 1062 | { | ||
| 1063 | if (!g_SilentMode) | ||
| 1064 | PrintErrorMessage("Unsupported command:", cmdError); | ||
| 1065 | return 1; | ||
| 1066 | } | ||
| 1067 | } | ||
| 1068 | |||
| 1069 | #if defined(_64BIT_INSTALLER) && !defined(_WIN64) | ||
| 1070 | { | ||
| 1071 | BOOL isWow64 = FALSE; | ||
| 1072 | Func_IsWow64Process func_IsWow64Process = (Func_IsWow64Process) | ||
| 1073 | GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "IsWow64Process"); | ||
| 1074 | |||
| 1075 | if (func_IsWow64Process) | ||
| 1076 | func_IsWow64Process(GetCurrentProcess(), &isWow64); | ||
| 1077 | |||
| 1078 | if (!isWow64) | ||
| 1079 | { | ||
| 1080 | if (!g_SilentMode) | ||
| 1081 | PrintErrorMessage("This installation requires Windows " MY_CPU_NAME, NULL); | ||
| 1082 | return 1; | ||
| 1083 | } | ||
| 1084 | } | ||
| 1085 | #endif | ||
| 1086 | |||
| 1087 | |||
| 1088 | if (path[0] == 0) | ||
| 1089 | { | ||
| 1090 | HKEY key = 0; | ||
| 1091 | BoolInt ok = False; | ||
| 1092 | LONG res = RegOpenKeyExW(HKEY_CURRENT_USER, k_Reg_Software_7zip, 0, KEY_READ | k_Reg_WOW_Flag, &key); | ||
| 1093 | if (res == ERROR_SUCCESS) | ||
| 1094 | { | ||
| 1095 | ok = MyRegistry_QueryString(key, k_Reg_Path32, path); | ||
| 1096 | // ok = MyRegistry_QueryString(key, k_Reg_Path, path); | ||
| 1097 | RegCloseKey(key); | ||
| 1098 | } | ||
| 1099 | |||
| 1100 | // ok = False; | ||
| 1101 | if (!ok) | ||
| 1102 | { | ||
| 1103 | /* | ||
| 1104 | #ifdef UNDER_CE | ||
| 1105 | CpyAscii(path, "\\Program Files\\"); | ||
| 1106 | #else | ||
| 1107 | |||
| 1108 | #ifdef _64BIT_INSTALLER | ||
| 1109 | { | ||
| 1110 | DWORD ttt = GetEnvironmentVariableW(L"ProgramW6432", path, MAX_PATH); | ||
| 1111 | if (ttt == 0 || ttt > MAX_PATH) | ||
| 1112 | CpyAscii(path, "C:\\"); | ||
| 1113 | } | ||
| 1114 | #else | ||
| 1115 | if (!SHGetSpecialFolderPathW(0, path, CSIDL_PROGRAM_FILES, FALSE)) | ||
| 1116 | CpyAscii(path, "C:\\"); | ||
| 1117 | #endif | ||
| 1118 | #endif | ||
| 1119 | */ | ||
| 1120 | if (!MyRegistry_QueryString2(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion", L"ProgramFilesDir", path)) | ||
| 1121 | CpyAscii(path, | ||
| 1122 | #ifdef UNDER_CE | ||
| 1123 | "\\Program Files\\" | ||
| 1124 | #else | ||
| 1125 | "C:\\" | ||
| 1126 | #endif | ||
| 1127 | ); | ||
| 1128 | |||
| 1129 | Set7zipPostfix(path); | ||
| 1130 | } | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | NormalizePrefix(path); | ||
| 1134 | |||
| 1135 | if (g_SilentMode) | ||
| 1136 | return Install(); | ||
| 1137 | |||
| 1138 | { | ||
| 1139 | int retCode = 1; | ||
| 1140 | // INT_PTR res = DialogBox( | ||
| 1141 | g_HWND = CreateDialog( | ||
| 1142 | hInstance, | ||
| 1143 | // GetModuleHandle(NULL), | ||
| 1144 | MAKEINTRESOURCE(IDD_INSTALL), NULL, MyDlgProc); | ||
| 1145 | if (!g_HWND) | ||
| 1146 | return 1; | ||
| 1147 | |||
| 1148 | { | ||
| 1149 | HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); | ||
| 1150 | // SendMessage(g_HWND, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon); | ||
| 1151 | SendMessage(g_HWND, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon); | ||
| 1152 | } | ||
| 1153 | |||
| 1154 | |||
| 1155 | { | ||
| 1156 | BOOL bRet; | ||
| 1157 | MSG msg; | ||
| 1158 | |||
| 1159 | // we need messages for all thread windows (including EDITTEXT window in dialog) | ||
| 1160 | while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) | ||
| 1161 | { | ||
| 1162 | if (bRet == -1) | ||
| 1163 | return retCode; | ||
| 1164 | if (!g_HWND) | ||
| 1165 | return retCode; | ||
| 1166 | |||
| 1167 | if (!IsDialogMessage(g_HWND, &msg)) | ||
| 1168 | { | ||
| 1169 | TranslateMessage(&msg); | ||
| 1170 | DispatchMessage(&msg); | ||
| 1171 | } | ||
| 1172 | if (!g_HWND) | ||
| 1173 | return retCode; | ||
| 1174 | |||
| 1175 | if (g_Install_was_Pressed && !g_Finished) | ||
| 1176 | { | ||
| 1177 | retCode = Install(); | ||
| 1178 | g_Finished = True; | ||
| 1179 | if (retCode != 0) | ||
| 1180 | break; | ||
| 1181 | if (!g_HWND) | ||
| 1182 | break; | ||
| 1183 | { | ||
| 1184 | SetDlgItemTextW(g_HWND, IDOK, L"Close"); | ||
| 1185 | EnableWindow(GetDlgItem(g_HWND, IDOK), TRUE); | ||
| 1186 | EnableWindow(GetDlgItem(g_HWND, IDCANCEL), FALSE); | ||
| 1187 | SendMessage(g_HWND, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(g_HWND, IDOK), TRUE); | ||
| 1188 | } | ||
| 1189 | } | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | if (g_HWND) | ||
| 1193 | { | ||
| 1194 | DestroyWindow(g_HWND); | ||
| 1195 | g_HWND = NULL; | ||
| 1196 | } | ||
| 1197 | } | ||
| 1198 | |||
| 1199 | return retCode; | ||
| 1200 | } | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | |||
| 1204 | static BoolInt GetErrorMessage(DWORD errorCode, WCHAR *message) | ||
| 1205 | { | ||
| 1206 | LPWSTR msgBuf; | ||
| 1207 | if (FormatMessageW( | ||
| 1208 | FORMAT_MESSAGE_ALLOCATE_BUFFER | ||
| 1209 | | FORMAT_MESSAGE_FROM_SYSTEM | ||
| 1210 | | FORMAT_MESSAGE_IGNORE_INSERTS, | ||
| 1211 | NULL, errorCode, 0, (LPWSTR) &msgBuf, 0, NULL) == 0) | ||
| 1212 | return False; | ||
| 1213 | wcscpy(message, msgBuf); | ||
| 1214 | LocalFree(msgBuf); | ||
| 1215 | return True; | ||
| 1216 | } | ||
| 1217 | |||
| 1218 | |||
| 1219 | |||
| 1220 | static int Install(void) | ||
| 1221 | { | ||
| 1222 | CFileInStream archiveStream; | ||
| 1223 | CLookToRead2 lookStream; | ||
| 1224 | CSzArEx db; | ||
| 1225 | |||
| 1226 | SRes res = SZ_OK; | ||
| 1227 | WRes winRes = 0; | ||
| 1228 | const char *errorMessage = NULL; | ||
| 1229 | |||
| 1230 | ISzAlloc allocImp; | ||
| 1231 | ISzAlloc allocTempImp; | ||
| 1232 | WCHAR sfxPath[MAX_PATH + 2]; | ||
| 1233 | |||
| 1234 | int needRebootLevel = 0; | ||
| 1235 | |||
| 1236 | allocImp.Alloc = SzAlloc; | ||
| 1237 | allocImp.Free = SzFree; | ||
| 1238 | |||
| 1239 | allocTempImp.Alloc = SzAllocTemp; | ||
| 1240 | allocTempImp.Free = SzFreeTemp; | ||
| 1241 | |||
| 1242 | { | ||
| 1243 | DWORD len = GetModuleFileNameW(NULL, sfxPath, MAX_PATH); | ||
| 1244 | if (len == 0 || len > MAX_PATH) | ||
| 1245 | return 1; | ||
| 1246 | } | ||
| 1247 | |||
| 1248 | winRes = InFile_OpenW(&archiveStream.file, sfxPath); | ||
| 1249 | |||
| 1250 | if (winRes == 0) | ||
| 1251 | { | ||
| 1252 | UInt64 pos = 0; | ||
| 1253 | if (!FindSignature(&archiveStream.file, &pos)) | ||
| 1254 | errorMessage = "Can't find 7z archive"; | ||
| 1255 | else | ||
| 1256 | winRes = File_Seek(&archiveStream.file, (Int64 *)&pos, SZ_SEEK_SET); | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | if (winRes != 0) | ||
| 1260 | res = SZ_ERROR_FAIL; | ||
| 1261 | |||
| 1262 | if (errorMessage) | ||
| 1263 | res = SZ_ERROR_FAIL; | ||
| 1264 | |||
| 1265 | if (res == SZ_OK) | ||
| 1266 | { | ||
| 1267 | size_t pathLen; | ||
| 1268 | if (!g_SilentMode) | ||
| 1269 | { | ||
| 1270 | GetDlgItemTextW(g_HWND, IDE_EXTRACT_PATH, path, MAX_PATH); | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | FileInStream_CreateVTable(&archiveStream); | ||
| 1274 | LookToRead2_CreateVTable(&lookStream, False); | ||
| 1275 | lookStream.buf = NULL; | ||
| 1276 | |||
| 1277 | RemoveQuotes(path); | ||
| 1278 | { | ||
| 1279 | // Remove post spaces | ||
| 1280 | unsigned endPos = 0; | ||
| 1281 | unsigned i = 0; | ||
| 1282 | |||
| 1283 | for (;;) | ||
| 1284 | { | ||
| 1285 | wchar_t c = path[i++]; | ||
| 1286 | if (c == 0) | ||
| 1287 | break; | ||
| 1288 | if (c != ' ') | ||
| 1289 | endPos = i; | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | path[endPos] = 0; | ||
| 1293 | if (path[0] == 0) | ||
| 1294 | { | ||
| 1295 | PrintErrorMessage("Incorrect path", NULL); | ||
| 1296 | return 1; | ||
| 1297 | } | ||
| 1298 | } | ||
| 1299 | |||
| 1300 | NormalizePrefix(path); | ||
| 1301 | winRes = CreateComplexDir(); | ||
| 1302 | |||
| 1303 | if (winRes != 0) | ||
| 1304 | res = SZ_ERROR_FAIL; | ||
| 1305 | |||
| 1306 | pathLen = wcslen(path); | ||
| 1307 | |||
| 1308 | if (res == SZ_OK) | ||
| 1309 | { | ||
| 1310 | lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize); | ||
| 1311 | if (!lookStream.buf) | ||
| 1312 | res = SZ_ERROR_MEM; | ||
| 1313 | else | ||
| 1314 | { | ||
| 1315 | lookStream.bufSize = kInputBufSize; | ||
| 1316 | lookStream.realStream = &archiveStream.vt; | ||
| 1317 | LookToRead2_Init(&lookStream); | ||
| 1318 | } | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | SzArEx_Init(&db); | ||
| 1322 | |||
| 1323 | if (res == SZ_OK) | ||
| 1324 | { | ||
| 1325 | res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp); | ||
| 1326 | } | ||
| 1327 | |||
| 1328 | if (res == SZ_OK) | ||
| 1329 | { | ||
| 1330 | UInt32 i; | ||
| 1331 | UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call, if (!outBuf) */ | ||
| 1332 | Byte *outBuf = NULL; /* it must be NULL before first call for each new archive. */ | ||
| 1333 | size_t outBufSize = 0; /* it can have any value before first call, if (!outBuf) */ | ||
| 1334 | |||
| 1335 | g_TotalSize = 0; | ||
| 1336 | |||
| 1337 | if (!g_SilentMode) | ||
| 1338 | { | ||
| 1339 | ShowWindow(g_Progress_HWND, SW_SHOW); | ||
| 1340 | ShowWindow(g_InfoLine_HWND, SW_SHOW); | ||
| 1341 | SendMessage(g_Progress_HWND, PBM_SETRANGE32, 0, db.NumFiles); | ||
| 1342 | } | ||
| 1343 | |||
| 1344 | for (i = 0; i < db.NumFiles; i++) | ||
| 1345 | { | ||
| 1346 | size_t offset = 0; | ||
| 1347 | size_t outSizeProcessed = 0; | ||
| 1348 | WCHAR *temp; | ||
| 1349 | |||
| 1350 | if (!g_SilentMode) | ||
| 1351 | { | ||
| 1352 | MSG msg; | ||
| 1353 | |||
| 1354 | // g_HWND | ||
| 1355 | while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) | ||
| 1356 | { | ||
| 1357 | if (!IsDialogMessage(g_HWND, &msg)) | ||
| 1358 | { | ||
| 1359 | TranslateMessage(&msg); | ||
| 1360 | DispatchMessage(&msg); | ||
| 1361 | } | ||
| 1362 | if (!g_HWND) | ||
| 1363 | return 1; | ||
| 1364 | } | ||
| 1365 | |||
| 1366 | // Sleep(10); | ||
| 1367 | SendMessage(g_Progress_HWND, PBM_SETPOS, i, 0); | ||
| 1368 | } | ||
| 1369 | |||
| 1370 | { | ||
| 1371 | size_t len = SzArEx_GetFileNameUtf16(&db, i, NULL); | ||
| 1372 | if (len >= MAX_PATH) | ||
| 1373 | { | ||
| 1374 | res = SZ_ERROR_FAIL; | ||
| 1375 | break; | ||
| 1376 | } | ||
| 1377 | } | ||
| 1378 | |||
| 1379 | temp = path + pathLen; | ||
| 1380 | |||
| 1381 | SzArEx_GetFileNameUtf16(&db, i, (UInt16 *)temp); | ||
| 1382 | |||
| 1383 | if (!g_SilentMode) | ||
| 1384 | SetWindowTextW(g_InfoLine_HWND, temp); | ||
| 1385 | |||
| 1386 | { | ||
| 1387 | res = SzArEx_Extract(&db, &lookStream.vt, i, | ||
| 1388 | &blockIndex, &outBuf, &outBufSize, | ||
| 1389 | &offset, &outSizeProcessed, | ||
| 1390 | &allocImp, &allocTempImp); | ||
| 1391 | if (res != SZ_OK) | ||
| 1392 | break; | ||
| 1393 | } | ||
| 1394 | |||
| 1395 | { | ||
| 1396 | CSzFile outFile; | ||
| 1397 | size_t processedSize; | ||
| 1398 | size_t j; | ||
| 1399 | // size_t nameStartPos = 0; | ||
| 1400 | UInt32 tempIndex = 0; | ||
| 1401 | int fileLevel = 1 << 2; | ||
| 1402 | WCHAR origPath[MAX_PATH * 2 + 10]; | ||
| 1403 | |||
| 1404 | for (j = 0; temp[j] != 0; j++) | ||
| 1405 | { | ||
| 1406 | if (temp[j] == '/') | ||
| 1407 | { | ||
| 1408 | temp[j] = 0; | ||
| 1409 | MyCreateDir(path); | ||
| 1410 | temp[j] = CHAR_PATH_SEPARATOR; | ||
| 1411 | // nameStartPos = j + 1; | ||
| 1412 | } | ||
| 1413 | } | ||
| 1414 | |||
| 1415 | if (SzArEx_IsDir(&db, i)) | ||
| 1416 | { | ||
| 1417 | MyCreateDir(path); | ||
| 1418 | continue; | ||
| 1419 | } | ||
| 1420 | |||
| 1421 | { | ||
| 1422 | // BoolInt skipFile = False; | ||
| 1423 | |||
| 1424 | wcscpy(origPath, path); | ||
| 1425 | |||
| 1426 | for (;;) | ||
| 1427 | { | ||
| 1428 | WRes openRes; | ||
| 1429 | |||
| 1430 | if (tempIndex != 0) | ||
| 1431 | { | ||
| 1432 | if (tempIndex > 100) | ||
| 1433 | { | ||
| 1434 | res = SZ_ERROR_FAIL; | ||
| 1435 | break; | ||
| 1436 | } | ||
| 1437 | wcscpy(path, origPath); | ||
| 1438 | CatAscii(path, ".tmp"); | ||
| 1439 | if (tempIndex > 1) | ||
| 1440 | HexToString(tempIndex, path + wcslen(path)); | ||
| 1441 | if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES) | ||
| 1442 | { | ||
| 1443 | tempIndex++; | ||
| 1444 | continue; | ||
| 1445 | } | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | { | ||
| 1449 | SetFileAttributesW(path, 0); | ||
| 1450 | openRes = OutFile_OpenW(&outFile, path); | ||
| 1451 | if (openRes == 0) | ||
| 1452 | break; | ||
| 1453 | } | ||
| 1454 | |||
| 1455 | if (tempIndex != 0) | ||
| 1456 | { | ||
| 1457 | tempIndex++; | ||
| 1458 | continue; | ||
| 1459 | } | ||
| 1460 | |||
| 1461 | if (FindSubString(temp, "7-zip.dll") | ||
| 1462 | #ifdef USE_7ZIP_32_DLL | ||
| 1463 | || FindSubString(temp, "7-zip32.dll") | ||
| 1464 | #endif | ||
| 1465 | ) | ||
| 1466 | { | ||
| 1467 | DWORD ver = GetFileVersion(path); | ||
| 1468 | fileLevel = ((ver < _7ZIP_DLL_VER_COMPAT || ver > _7ZIP_CUR_VER) ? 2 : 1); | ||
| 1469 | tempIndex++; | ||
| 1470 | continue; | ||
| 1471 | } | ||
| 1472 | |||
| 1473 | if (g_SilentMode) | ||
| 1474 | { | ||
| 1475 | tempIndex++; | ||
| 1476 | continue; | ||
| 1477 | } | ||
| 1478 | { | ||
| 1479 | WCHAR message[MAX_PATH * 3 + 100]; | ||
| 1480 | int mbRes; | ||
| 1481 | |||
| 1482 | CpyAscii(message, "Can't open file\n"); | ||
| 1483 | wcscat(message, path); | ||
| 1484 | CatAscii(message, "\n"); | ||
| 1485 | |||
| 1486 | GetErrorMessage(openRes, message + wcslen(message)); | ||
| 1487 | |||
| 1488 | mbRes = MessageBoxW(g_HWND, message, L"Error", MB_ICONERROR | MB_ABORTRETRYIGNORE | MB_DEFBUTTON3); | ||
| 1489 | if (mbRes == IDABORT) | ||
| 1490 | { | ||
| 1491 | res = SZ_ERROR_ABORT; | ||
| 1492 | tempIndex = 0; | ||
| 1493 | break; | ||
| 1494 | } | ||
| 1495 | if (mbRes == IDIGNORE) | ||
| 1496 | { | ||
| 1497 | // skipFile = True; | ||
| 1498 | tempIndex++; | ||
| 1499 | } | ||
| 1500 | } | ||
| 1501 | } | ||
| 1502 | |||
| 1503 | if (res != SZ_OK) | ||
| 1504 | break; | ||
| 1505 | |||
| 1506 | /* | ||
| 1507 | if (skipFile) | ||
| 1508 | continue; | ||
| 1509 | */ | ||
| 1510 | } | ||
| 1511 | |||
| 1512 | // if (res == SZ_OK) | ||
| 1513 | { | ||
| 1514 | processedSize = outSizeProcessed; | ||
| 1515 | winRes = File_Write(&outFile, outBuf + offset, &processedSize); | ||
| 1516 | if (winRes != 0 || processedSize != outSizeProcessed) | ||
| 1517 | { | ||
| 1518 | errorMessage = "Can't write output file"; | ||
| 1519 | res = SZ_ERROR_FAIL; | ||
| 1520 | } | ||
| 1521 | |||
| 1522 | g_TotalSize += (DWORD)outSizeProcessed; | ||
| 1523 | |||
| 1524 | #ifdef USE_WINDOWS_FILE | ||
| 1525 | if (SzBitWithVals_Check(&db.MTime, i)) | ||
| 1526 | { | ||
| 1527 | const CNtfsFileTime *t = db.MTime.Vals + i; | ||
| 1528 | FILETIME mTime; | ||
| 1529 | mTime.dwLowDateTime = t->Low; | ||
| 1530 | mTime.dwHighDateTime = t->High; | ||
| 1531 | SetFileTime(outFile.handle, NULL, NULL, &mTime); | ||
| 1532 | } | ||
| 1533 | #endif | ||
| 1534 | |||
| 1535 | { | ||
| 1536 | SRes winRes2 = File_Close(&outFile); | ||
| 1537 | if (res != SZ_OK) | ||
| 1538 | break; | ||
| 1539 | if (winRes2 != 0) | ||
| 1540 | { | ||
| 1541 | winRes = winRes2; | ||
| 1542 | break; | ||
| 1543 | } | ||
| 1544 | } | ||
| 1545 | |||
| 1546 | #ifdef USE_WINDOWS_FILE | ||
| 1547 | if (SzBitWithVals_Check(&db.Attribs, i)) | ||
| 1548 | SetFileAttributesW(path, db.Attribs.Vals[i]); | ||
| 1549 | #endif | ||
| 1550 | } | ||
| 1551 | |||
| 1552 | if (tempIndex != 0) | ||
| 1553 | { | ||
| 1554 | // is it supported at win2000 ? | ||
| 1555 | #ifndef UNDER_CE | ||
| 1556 | if (!MoveFileExW(path, origPath, MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING)) | ||
| 1557 | { | ||
| 1558 | winRes = GetLastError(); | ||
| 1559 | break; | ||
| 1560 | } | ||
| 1561 | needRebootLevel |= fileLevel; | ||
| 1562 | #endif | ||
| 1563 | } | ||
| 1564 | |||
| 1565 | } | ||
| 1566 | } | ||
| 1567 | |||
| 1568 | ISzAlloc_Free(&allocImp, outBuf); | ||
| 1569 | |||
| 1570 | if (!g_SilentMode) | ||
| 1571 | SendMessage(g_Progress_HWND, PBM_SETPOS, i, 0); | ||
| 1572 | |||
| 1573 | path[pathLen] = 0; | ||
| 1574 | |||
| 1575 | if (i == db.NumFiles) | ||
| 1576 | { | ||
| 1577 | SetRegKey_Path(); | ||
| 1578 | WriteCLSID(); | ||
| 1579 | WriteShellEx(); | ||
| 1580 | |||
| 1581 | SetShellProgramsGroup(g_HWND); | ||
| 1582 | if (!g_SilentMode) | ||
| 1583 | SetWindowTextW(g_InfoLine_HWND, k_7zip_with_Ver L" is installed"); | ||
| 1584 | } | ||
| 1585 | } | ||
| 1586 | |||
| 1587 | SzArEx_Free(&db, &allocImp); | ||
| 1588 | |||
| 1589 | ISzAlloc_Free(&allocImp, lookStream.buf); | ||
| 1590 | |||
| 1591 | File_Close(&archiveStream.file); | ||
| 1592 | |||
| 1593 | } | ||
| 1594 | |||
| 1595 | if (winRes != 0) | ||
| 1596 | res = SZ_ERROR_FAIL; | ||
| 1597 | |||
| 1598 | if (res == SZ_OK) | ||
| 1599 | { | ||
| 1600 | if (!g_SilentMode && needRebootLevel > 1) | ||
| 1601 | { | ||
| 1602 | if (MessageBoxW(g_HWND, L"You must restart your system to complete the installation.\nRestart now?", | ||
| 1603 | k_7zip_Setup, MB_YESNO | MB_DEFBUTTON2) == IDYES) | ||
| 1604 | { | ||
| 1605 | #ifndef UNDER_CE | ||
| 1606 | |||
| 1607 | // Get a token for this process. | ||
| 1608 | HANDLE hToken; | ||
| 1609 | |||
| 1610 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) | ||
| 1611 | { | ||
| 1612 | TOKEN_PRIVILEGES tkp; | ||
| 1613 | // Get the LUID for the shutdown privilege. | ||
| 1614 | LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); | ||
| 1615 | tkp.PrivilegeCount = 1; // one privilege to set | ||
| 1616 | tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | ||
| 1617 | // Get the shutdown privilege for this process. | ||
| 1618 | AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); | ||
| 1619 | |||
| 1620 | if (GetLastError() == ERROR_SUCCESS) | ||
| 1621 | { | ||
| 1622 | if (!ExitWindowsEx(EWX_REBOOT, 0)) | ||
| 1623 | { | ||
| 1624 | } | ||
| 1625 | } | ||
| 1626 | } | ||
| 1627 | |||
| 1628 | #endif | ||
| 1629 | } | ||
| 1630 | } | ||
| 1631 | |||
| 1632 | if (res == SZ_OK) | ||
| 1633 | return 0; | ||
| 1634 | } | ||
| 1635 | |||
| 1636 | if (!g_SilentMode) | ||
| 1637 | { | ||
| 1638 | if (winRes != 0) | ||
| 1639 | { | ||
| 1640 | WCHAR m[MAX_PATH + 100]; | ||
| 1641 | m[0] = 0; | ||
| 1642 | GetErrorMessage(winRes, m); | ||
| 1643 | PrintErrorMessage(NULL, m); | ||
| 1644 | } | ||
| 1645 | else | ||
| 1646 | { | ||
| 1647 | if (res == SZ_ERROR_ABORT) | ||
| 1648 | return 2; | ||
| 1649 | |||
| 1650 | if (res == SZ_ERROR_UNSUPPORTED) | ||
| 1651 | errorMessage = "Decoder doesn't support this archive"; | ||
| 1652 | else if (res == SZ_ERROR_MEM) | ||
| 1653 | errorMessage = "Can't allocate required memory"; | ||
| 1654 | else if (res == SZ_ERROR_CRC) | ||
| 1655 | errorMessage = "CRC error"; | ||
| 1656 | else if (res == SZ_ERROR_DATA) | ||
| 1657 | errorMessage = "Data error"; | ||
| 1658 | |||
| 1659 | if (!errorMessage) | ||
| 1660 | errorMessage = "ERROR"; | ||
| 1661 | PrintErrorMessage(errorMessage, NULL); | ||
| 1662 | } | ||
| 1663 | } | ||
| 1664 | |||
| 1665 | return 1; | ||
| 1666 | } | ||
diff --git a/C/Util/7zipInstall/7zipInstall.dsp b/C/Util/7zipInstall/7zipInstall.dsp new file mode 100644 index 0000000..d3b5c4c --- /dev/null +++ b/C/Util/7zipInstall/7zipInstall.dsp | |||
| @@ -0,0 +1,240 @@ | |||
| 1 | # Microsoft Developer Studio Project File - Name="7zipInstall" - Package Owner=<4> | ||
| 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 | ||
| 3 | # ** DO NOT EDIT ** | ||
| 4 | |||
| 5 | # TARGTYPE "Win32 (x86) Application" 0x0101 | ||
| 6 | |||
| 7 | CFG=7zipInstall - Win32 Debug | ||
| 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, | ||
| 9 | !MESSAGE use the Export Makefile command and run | ||
| 10 | !MESSAGE | ||
| 11 | !MESSAGE NMAKE /f "7zipInstall.mak". | ||
| 12 | !MESSAGE | ||
| 13 | !MESSAGE You can specify a configuration when running NMAKE | ||
| 14 | !MESSAGE by defining the macro CFG on the command line. For example: | ||
| 15 | !MESSAGE | ||
| 16 | !MESSAGE NMAKE /f "7zipInstall.mak" CFG="7zipInstall - Win32 Debug" | ||
| 17 | !MESSAGE | ||
| 18 | !MESSAGE Possible choices for configuration are: | ||
| 19 | !MESSAGE | ||
| 20 | !MESSAGE "7zipInstall - Win32 Release" (based on "Win32 (x86) Application") | ||
| 21 | !MESSAGE "7zipInstall - Win32 Debug" (based on "Win32 (x86) Application") | ||
| 22 | !MESSAGE | ||
| 23 | |||
| 24 | # Begin Project | ||
| 25 | # PROP AllowPerConfigDependencies 0 | ||
| 26 | # PROP Scc_ProjName "" | ||
| 27 | # PROP Scc_LocalPath "" | ||
| 28 | CPP=cl.exe | ||
| 29 | MTL=midl.exe | ||
| 30 | RSC=rc.exe | ||
| 31 | |||
| 32 | !IF "$(CFG)" == "7zipInstall - Win32 Release" | ||
| 33 | |||
| 34 | # PROP BASE Use_MFC 0 | ||
| 35 | # PROP BASE Use_Debug_Libraries 0 | ||
| 36 | # PROP BASE Output_Dir "Release" | ||
| 37 | # PROP BASE Intermediate_Dir "Release" | ||
| 38 | # PROP BASE Target_Dir "" | ||
| 39 | # PROP Use_MFC 0 | ||
| 40 | # PROP Use_Debug_Libraries 0 | ||
| 41 | # PROP Output_Dir "Release" | ||
| 42 | # PROP Intermediate_Dir "Release" | ||
| 43 | # PROP Ignore_Export_Lib 0 | ||
| 44 | # PROP Target_Dir "" | ||
| 45 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c | ||
| 46 | # ADD CPP /nologo /Gr /MD /W4 /WX /GX /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /Yu"Precomp.h" /FD /c | ||
| 47 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 48 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 49 | # ADD BASE RSC /l 0x419 /d "NDEBUG" | ||
| 50 | # ADD RSC /l 0x419 /d "NDEBUG" | ||
| 51 | BSC32=bscmake.exe | ||
| 52 | # ADD BASE BSC32 /nologo | ||
| 53 | # ADD BSC32 /nologo | ||
| 54 | LINK32=link.exe | ||
| 55 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 | ||
| 56 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib version.lib /nologo /subsystem:windows /machine:I386 | ||
| 57 | |||
| 58 | !ELSEIF "$(CFG)" == "7zipInstall - Win32 Debug" | ||
| 59 | |||
| 60 | # PROP BASE Use_MFC 0 | ||
| 61 | # PROP BASE Use_Debug_Libraries 1 | ||
| 62 | # PROP BASE Output_Dir "Debug" | ||
| 63 | # PROP BASE Intermediate_Dir "Debug" | ||
| 64 | # PROP BASE Target_Dir "" | ||
| 65 | # PROP Use_MFC 0 | ||
| 66 | # PROP Use_Debug_Libraries 1 | ||
| 67 | # PROP Output_Dir "Debug" | ||
| 68 | # PROP Intermediate_Dir "Debug" | ||
| 69 | # PROP Ignore_Export_Lib 0 | ||
| 70 | # PROP Target_Dir "" | ||
| 71 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c | ||
| 72 | # ADD CPP /nologo /W4 /WX /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /Yu"Precomp.h" /FD /GZ /c | ||
| 73 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 74 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 75 | # ADD BASE RSC /l 0x419 /d "_DEBUG" | ||
| 76 | # ADD RSC /l 0x419 /d "_DEBUG" | ||
| 77 | BSC32=bscmake.exe | ||
| 78 | # ADD BASE BSC32 /nologo | ||
| 79 | # ADD BSC32 /nologo | ||
| 80 | LINK32=link.exe | ||
| 81 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept | ||
| 82 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib version.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept | ||
| 83 | |||
| 84 | !ENDIF | ||
| 85 | |||
| 86 | # Begin Target | ||
| 87 | |||
| 88 | # Name "7zipInstall - Win32 Release" | ||
| 89 | # Name "7zipInstall - Win32 Debug" | ||
| 90 | # Begin Group "Common" | ||
| 91 | |||
| 92 | # PROP Default_Filter "" | ||
| 93 | # Begin Source File | ||
| 94 | |||
| 95 | SOURCE=..\..\7z.h | ||
| 96 | # End Source File | ||
| 97 | # Begin Source File | ||
| 98 | |||
| 99 | SOURCE=..\..\7zAlloc.c | ||
| 100 | # End Source File | ||
| 101 | # Begin Source File | ||
| 102 | |||
| 103 | SOURCE=..\..\7zAlloc.h | ||
| 104 | # End Source File | ||
| 105 | # Begin Source File | ||
| 106 | |||
| 107 | SOURCE=..\..\7zArcIn.c | ||
| 108 | # End Source File | ||
| 109 | # Begin Source File | ||
| 110 | |||
| 111 | SOURCE=..\..\7zBuf.c | ||
| 112 | # End Source File | ||
| 113 | # Begin Source File | ||
| 114 | |||
| 115 | SOURCE=..\..\7zBuf.h | ||
| 116 | # End Source File | ||
| 117 | # Begin Source File | ||
| 118 | |||
| 119 | SOURCE=..\..\7zCrc.c | ||
| 120 | # End Source File | ||
| 121 | # Begin Source File | ||
| 122 | |||
| 123 | SOURCE=..\..\7zCrc.h | ||
| 124 | # End Source File | ||
| 125 | # Begin Source File | ||
| 126 | |||
| 127 | SOURCE=..\..\7zCrcOpt.c | ||
| 128 | # End Source File | ||
| 129 | # Begin Source File | ||
| 130 | |||
| 131 | SOURCE=..\..\7zDec.c | ||
| 132 | # End Source File | ||
| 133 | # Begin Source File | ||
| 134 | |||
| 135 | SOURCE=..\..\7zFile.c | ||
| 136 | # End Source File | ||
| 137 | # Begin Source File | ||
| 138 | |||
| 139 | SOURCE=..\..\7zFile.h | ||
| 140 | # End Source File | ||
| 141 | # Begin Source File | ||
| 142 | |||
| 143 | SOURCE=..\..\7zStream.c | ||
| 144 | # End Source File | ||
| 145 | # Begin Source File | ||
| 146 | |||
| 147 | SOURCE=..\..\7zTypes.h | ||
| 148 | # End Source File | ||
| 149 | # Begin Source File | ||
| 150 | |||
| 151 | SOURCE=..\..\7zVersion.h | ||
| 152 | # End Source File | ||
| 153 | # Begin Source File | ||
| 154 | |||
| 155 | SOURCE=..\..\Bcj2.c | ||
| 156 | # End Source File | ||
| 157 | # Begin Source File | ||
| 158 | |||
| 159 | SOURCE=..\..\Bcj2.h | ||
| 160 | # End Source File | ||
| 161 | # Begin Source File | ||
| 162 | |||
| 163 | SOURCE=..\..\Bra.c | ||
| 164 | # End Source File | ||
| 165 | # Begin Source File | ||
| 166 | |||
| 167 | SOURCE=..\..\Bra.h | ||
| 168 | # End Source File | ||
| 169 | # Begin Source File | ||
| 170 | |||
| 171 | SOURCE=..\..\Bra86.c | ||
| 172 | # End Source File | ||
| 173 | # Begin Source File | ||
| 174 | |||
| 175 | SOURCE=..\..\BraIA64.c | ||
| 176 | # End Source File | ||
| 177 | # Begin Source File | ||
| 178 | |||
| 179 | SOURCE=..\..\CpuArch.c | ||
| 180 | # End Source File | ||
| 181 | # Begin Source File | ||
| 182 | |||
| 183 | SOURCE=..\..\CpuArch.h | ||
| 184 | # End Source File | ||
| 185 | # Begin Source File | ||
| 186 | |||
| 187 | SOURCE=..\..\Delta.c | ||
| 188 | # End Source File | ||
| 189 | # Begin Source File | ||
| 190 | |||
| 191 | SOURCE=..\..\Delta.h | ||
| 192 | # End Source File | ||
| 193 | # Begin Source File | ||
| 194 | |||
| 195 | SOURCE=..\..\DllSecur.c | ||
| 196 | # End Source File | ||
| 197 | # Begin Source File | ||
| 198 | |||
| 199 | SOURCE=..\..\DllSecur.h | ||
| 200 | # End Source File | ||
| 201 | # Begin Source File | ||
| 202 | |||
| 203 | SOURCE=..\..\Lzma2Dec.c | ||
| 204 | # End Source File | ||
| 205 | # Begin Source File | ||
| 206 | |||
| 207 | SOURCE=..\..\Lzma2Dec.h | ||
| 208 | # End Source File | ||
| 209 | # Begin Source File | ||
| 210 | |||
| 211 | SOURCE=..\..\LzmaDec.c | ||
| 212 | # End Source File | ||
| 213 | # Begin Source File | ||
| 214 | |||
| 215 | SOURCE=..\..\LzmaDec.h | ||
| 216 | # End Source File | ||
| 217 | # End Group | ||
| 218 | # Begin Group "Spec" | ||
| 219 | |||
| 220 | # PROP Default_Filter "" | ||
| 221 | # Begin Source File | ||
| 222 | |||
| 223 | SOURCE=.\Precomp.c | ||
| 224 | # ADD CPP /Yc"Precomp.h" | ||
| 225 | # End Source File | ||
| 226 | # Begin Source File | ||
| 227 | |||
| 228 | SOURCE=.\Precomp.h | ||
| 229 | # End Source File | ||
| 230 | # End Group | ||
| 231 | # Begin Source File | ||
| 232 | |||
| 233 | SOURCE=.\7zipInstall.c | ||
| 234 | # End Source File | ||
| 235 | # Begin Source File | ||
| 236 | |||
| 237 | SOURCE=.\resource.rc | ||
| 238 | # End Source File | ||
| 239 | # End Target | ||
| 240 | # End Project | ||
diff --git a/C/Util/7zipInstall/7zipInstall.dsw b/C/Util/7zipInstall/7zipInstall.dsw new file mode 100644 index 0000000..b7db73f --- /dev/null +++ b/C/Util/7zipInstall/7zipInstall.dsw | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 | ||
| 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! | ||
| 3 | |||
| 4 | ############################################################################### | ||
| 5 | |||
| 6 | Project: "7zipInstall"=.\7zipInstall.dsp - Package Owner=<4> | ||
| 7 | |||
| 8 | Package=<5> | ||
| 9 | {{{ | ||
| 10 | }}} | ||
| 11 | |||
| 12 | Package=<4> | ||
| 13 | {{{ | ||
| 14 | }}} | ||
| 15 | |||
| 16 | ############################################################################### | ||
| 17 | |||
| 18 | Global: | ||
| 19 | |||
| 20 | Package=<5> | ||
| 21 | {{{ | ||
| 22 | }}} | ||
| 23 | |||
| 24 | Package=<3> | ||
| 25 | {{{ | ||
| 26 | }}} | ||
| 27 | |||
| 28 | ############################################################################### | ||
| 29 | |||
diff --git a/C/Util/7zipInstall/7zipInstall.manifest b/C/Util/7zipInstall/7zipInstall.manifest new file mode 100644 index 0000000..f5c3ae5 --- /dev/null +++ b/C/Util/7zipInstall/7zipInstall.manifest | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| 2 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"> | ||
| 3 | <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="7-Zip.7-Zip.7zipInstall" type="win32"/> | ||
| 4 | <description>7-Zip Installer</description> | ||
| 5 | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges> | ||
| 6 | <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> | ||
| 7 | </requestedPrivileges></security></trustInfo> | ||
| 8 | <dependency><dependentAssembly><assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/></dependentAssembly></dependency> | ||
| 9 | <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application> | ||
| 10 | <!-- Vista --> <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> | ||
| 11 | <!-- Win 7 --> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> | ||
| 12 | <!-- Win 8 --> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> | ||
| 13 | <!-- Win 8.1 --> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> | ||
| 14 | <!-- Win 10 --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> | ||
| 15 | </application></compatibility> | ||
| 16 | <asmv3:application><asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"> | ||
| 17 | <dpiAware>true</dpiAware></asmv3:windowsSettings></asmv3:application> | ||
| 18 | </assembly> | ||
diff --git a/C/Util/7zipInstall/Precomp.c b/C/Util/7zipInstall/Precomp.c new file mode 100644 index 0000000..01605e3 --- /dev/null +++ b/C/Util/7zipInstall/Precomp.c | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | /* Precomp.c -- StdAfx | ||
| 2 | 2013-01-21 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
diff --git a/C/Util/7zipInstall/Precomp.h b/C/Util/7zipInstall/Precomp.h new file mode 100644 index 0000000..4c90d47 --- /dev/null +++ b/C/Util/7zipInstall/Precomp.h | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | /* Precomp.h -- StdAfx | ||
| 2 | 2015-05-24 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #ifndef __7Z_PRECOMP_H | ||
| 5 | #define __7Z_PRECOMP_H | ||
| 6 | |||
| 7 | #include "../../Compiler.h" | ||
| 8 | |||
| 9 | #include "../../7zTypes.h" | ||
| 10 | |||
| 11 | #endif | ||
diff --git a/C/Util/7zipInstall/makefile b/C/Util/7zipInstall/makefile new file mode 100644 index 0000000..ab8893a --- /dev/null +++ b/C/Util/7zipInstall/makefile | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | PROG = 7zipInstall.exe | ||
| 2 | MY_FIXED = 1 | ||
| 3 | |||
| 4 | !IFDEF _64BIT_INSTALLER | ||
| 5 | CFLAGS = $(CFLAGS) -D_64BIT_INSTALLER | ||
| 6 | !ENDIF | ||
| 7 | |||
| 8 | CFLAGS = $(CFLAGS) -D_LZMA_SIZE_OPT | ||
| 9 | |||
| 10 | CFLAGS = $(CFLAGS) \ | ||
| 11 | -D_7Z_NO_METHOD_LZMA2 \ | ||
| 12 | -D_7Z_NO_METHODS_FILTERS | ||
| 13 | |||
| 14 | MAIN_OBJS = \ | ||
| 15 | $O\7zipInstall.obj \ | ||
| 16 | |||
| 17 | C_OBJS = \ | ||
| 18 | $O\7zAlloc.obj \ | ||
| 19 | $O\7zArcIn.obj \ | ||
| 20 | $O\7zBuf.obj \ | ||
| 21 | $O\7zBuf2.obj \ | ||
| 22 | $O\7zCrc.obj \ | ||
| 23 | $O\7zCrcOpt.obj \ | ||
| 24 | $O\7zFile.obj \ | ||
| 25 | $O\7zDec.obj \ | ||
| 26 | $O\7zStream.obj \ | ||
| 27 | $O\Bcj2.obj \ | ||
| 28 | $O\CpuArch.obj \ | ||
| 29 | $O\DllSecur.obj \ | ||
| 30 | $O\LzmaDec.obj \ | ||
| 31 | |||
| 32 | OBJS = \ | ||
| 33 | $(MAIN_OBJS) \ | ||
| 34 | $(C_OBJS) \ | ||
| 35 | $O\resource.res | ||
| 36 | |||
| 37 | !include "../../../CPP/Build.mak" | ||
| 38 | |||
| 39 | $(MAIN_OBJS): $(*B).c | ||
| 40 | $(COMPL_O1) | ||
| 41 | $(C_OBJS): ../../$(*B).c | ||
| 42 | $(COMPL_O1) | ||
diff --git a/C/Util/7zipInstall/resource.h b/C/Util/7zipInstall/resource.h new file mode 100644 index 0000000..63c6b4c --- /dev/null +++ b/C/Util/7zipInstall/resource.h | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #define IDD_INSTALL 100 | ||
| 2 | |||
| 3 | #define IDT_EXTRACT_EXTRACT_TO 110 | ||
| 4 | #define IDE_EXTRACT_PATH 111 | ||
| 5 | #define IDB_EXTRACT_SET_PATH 112 | ||
| 6 | #define IDT_CUR_FILE 113 | ||
| 7 | #define IDC_PROGRESS 114 | ||
| 8 | |||
| 9 | #define IDI_ICON 1 | ||
diff --git a/C/Util/7zipInstall/resource.rc b/C/Util/7zipInstall/resource.rc new file mode 100644 index 0000000..df6474e --- /dev/null +++ b/C/Util/7zipInstall/resource.rc | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #include <winnt.h> | ||
| 2 | #include <WinUser.h> | ||
| 3 | #include <CommCtrl.h> | ||
| 4 | |||
| 5 | #define USE_COPYRIGHT_CR | ||
| 6 | #include "../../7zVersion.rc" | ||
| 7 | #include "resource.h" | ||
| 8 | |||
| 9 | MY_VERSION_INFO(MY_VFT_APP, "7-Zip Installer", "7zipInstall", "7zipInstall.exe") | ||
| 10 | |||
| 11 | 1 ICON "7zip.ico" | ||
| 12 | |||
| 13 | #define xc 184 | ||
| 14 | #define yc 96 | ||
| 15 | |||
| 16 | #define m 8 | ||
| 17 | #define bxs 64 | ||
| 18 | #define bys 16 | ||
| 19 | #define bxsDots 20 | ||
| 20 | |||
| 21 | #define xs (xc + m + m) | ||
| 22 | #define ys (yc + m + m) | ||
| 23 | |||
| 24 | #define bx1 (xs - m - bxs) | ||
| 25 | #define bx2 (bx1 - m - bxs) | ||
| 26 | |||
| 27 | #define by (ys - m - bys) | ||
| 28 | |||
| 29 | IDD_INSTALL DIALOG 0, 0, xs, ys | ||
| 30 | STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | ||
| 31 | CAPTION "Install 7-Zip" | ||
| 32 | FONT 8, "MS Shell Dlg" | ||
| 33 | BEGIN | ||
| 34 | LTEXT "Destination folder:", IDT_EXTRACT_EXTRACT_TO, m, m, xc, 8 | ||
| 35 | EDITTEXT IDE_EXTRACT_PATH, m, 21, xc - bxsDots - 12, 14, ES_AUTOHSCROLL | ||
| 36 | PUSHBUTTON "...", IDB_EXTRACT_SET_PATH, xs - m - bxsDots, 20, bxsDots, bys, WS_GROUP | ||
| 37 | |||
| 38 | LTEXT "", IDT_CUR_FILE, m, 50, xc, 8 | ||
| 39 | CONTROL "", IDC_PROGRESS, "msctls_progress32", WS_BORDER, m, 64, xc, 10 | ||
| 40 | |||
| 41 | DEFPUSHBUTTON "&Install", IDOK, bx2, by, bxs, bys, WS_GROUP | ||
| 42 | PUSHBUTTON "Cancel", IDCANCEL, bx1, by, bxs, bys | ||
| 43 | END | ||
| 44 | |||
| 45 | #ifndef UNDER_CE | ||
| 46 | 1 24 MOVEABLE PURE "7zipInstall.manifest" | ||
| 47 | #endif | ||
diff --git a/C/Util/7zipUninstall/7zipUninstall.c b/C/Util/7zipUninstall/7zipUninstall.c new file mode 100644 index 0000000..b4c6ff5 --- /dev/null +++ b/C/Util/7zipUninstall/7zipUninstall.c | |||
| @@ -0,0 +1,1183 @@ | |||
| 1 | /* 7zipUninstall.c - 7-Zip Uninstaller | ||
| 2 | 2021-11-24 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
| 5 | |||
| 6 | #ifdef _MSC_VER | ||
| 7 | #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union | ||
| 8 | #pragma warning(disable : 4011) // vs2010: identifier truncated to _CRT_SECURE_CPP_OVERLOAD_SECURE | ||
| 9 | #endif | ||
| 10 | |||
| 11 | // #define SZ_ERROR_ABORT 100 | ||
| 12 | |||
| 13 | #include <windows.h> | ||
| 14 | #include <ShlObj.h> | ||
| 15 | |||
| 16 | #include "../../7zVersion.h" | ||
| 17 | |||
| 18 | #include "resource.h" | ||
| 19 | |||
| 20 | #define LLL_(quote) L##quote | ||
| 21 | #define LLL(quote) LLL_(quote) | ||
| 22 | |||
| 23 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | ||
| 24 | |||
| 25 | // static LPCWSTR const k_7zip = L"7-Zip"; | ||
| 26 | |||
| 27 | // #define _64BIT_INSTALLER 1 | ||
| 28 | |||
| 29 | #ifdef _WIN64 | ||
| 30 | #define _64BIT_INSTALLER 1 | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #define k_7zip_with_Ver_base L"7-Zip " LLL(MY_VERSION) | ||
| 34 | |||
| 35 | #ifdef _64BIT_INSTALLER | ||
| 36 | |||
| 37 | // #define USE_7ZIP_32_DLL | ||
| 38 | |||
| 39 | #if defined(_M_ARM64) || defined(_M_ARM) | ||
| 40 | #define k_Postfix L" (arm64)" | ||
| 41 | #else | ||
| 42 | #define k_Postfix L" (x64)" | ||
| 43 | #define USE_7ZIP_32_DLL | ||
| 44 | #endif | ||
| 45 | #else | ||
| 46 | #if defined(_M_ARM64) || defined(_M_ARM) | ||
| 47 | #define k_Postfix L" (arm)" | ||
| 48 | #else | ||
| 49 | // #define k_Postfix L" (x86)" | ||
| 50 | #define k_Postfix | ||
| 51 | #endif | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #define k_7zip_with_Ver k_7zip_with_Ver_base k_Postfix | ||
| 55 | |||
| 56 | static LPCWSTR const k_7zip_with_Ver_Uninstall = k_7zip_with_Ver L" Uninstall"; | ||
| 57 | |||
| 58 | static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip"; | ||
| 59 | |||
| 60 | static LPCWSTR const k_Reg_Path = L"Path"; | ||
| 61 | |||
| 62 | static LPCWSTR const k_Reg_Path32 = L"Path" | ||
| 63 | #ifdef _64BIT_INSTALLER | ||
| 64 | L"64" | ||
| 65 | #else | ||
| 66 | L"32" | ||
| 67 | #endif | ||
| 68 | ; | ||
| 69 | |||
| 70 | #if defined(_64BIT_INSTALLER) && !defined(_WIN64) | ||
| 71 | #define k_Reg_WOW_Flag KEY_WOW64_64KEY | ||
| 72 | #else | ||
| 73 | #define k_Reg_WOW_Flag 0 | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #ifdef _WIN64 | ||
| 77 | #define k_Reg_WOW_Flag_32 KEY_WOW64_32KEY | ||
| 78 | #else | ||
| 79 | #define k_Reg_WOW_Flag_32 0 | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #define k_7zip_CLSID L"{23170F69-40C1-278A-1000-000100020000}" | ||
| 83 | |||
| 84 | static LPCWSTR const k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID; | ||
| 85 | static LPCWSTR const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32"; | ||
| 86 | |||
| 87 | |||
| 88 | #define g_AllUsers True | ||
| 89 | |||
| 90 | static BoolInt g_Install_was_Pressed; | ||
| 91 | static BoolInt g_Finished; | ||
| 92 | static BoolInt g_SilentMode; | ||
| 93 | |||
| 94 | static HWND g_HWND; | ||
| 95 | static HWND g_Path_HWND; | ||
| 96 | static HWND g_InfoLine_HWND; | ||
| 97 | static HWND g_Progress_HWND; | ||
| 98 | |||
| 99 | // WINADVAPI | ||
| 100 | typedef LONG (APIENTRY *Func_RegDeleteKeyExW)(HKEY hKey, LPCWSTR lpSubKey, REGSAM samDesired, DWORD Reserved); | ||
| 101 | static Func_RegDeleteKeyExW func_RegDeleteKeyExW; | ||
| 102 | |||
| 103 | static WCHAR cmd[MAX_PATH + 4]; | ||
| 104 | static WCHAR cmdError[MAX_PATH + 4]; | ||
| 105 | static WCHAR path[MAX_PATH * 2 + 40]; | ||
| 106 | static WCHAR workDir[MAX_PATH + 10]; | ||
| 107 | static WCHAR modulePath[MAX_PATH + 10]; | ||
| 108 | static WCHAR modulePrefix[MAX_PATH + 10]; | ||
| 109 | static WCHAR tempPath[MAX_PATH * 2 + 40]; | ||
| 110 | static WCHAR cmdLine[MAX_PATH * 3 + 40]; | ||
| 111 | static WCHAR copyPath[MAX_PATH * 2 + 40]; | ||
| 112 | |||
| 113 | static LPCWSTR const kUninstallExe = L"Uninstall.exe"; | ||
| 114 | |||
| 115 | #define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c))) | ||
| 116 | |||
| 117 | |||
| 118 | static void CpyAscii(wchar_t *dest, const char *s) | ||
| 119 | { | ||
| 120 | for (;;) | ||
| 121 | { | ||
| 122 | Byte b = (Byte)*s++; | ||
| 123 | *dest++ = b; | ||
| 124 | if (b == 0) | ||
| 125 | return; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | static void CatAscii(wchar_t *dest, const char *s) | ||
| 130 | { | ||
| 131 | dest += wcslen(dest); | ||
| 132 | CpyAscii(dest, s); | ||
| 133 | } | ||
| 134 | |||
| 135 | static void PrintErrorMessage(const char *s1, const wchar_t *s2) | ||
| 136 | { | ||
| 137 | WCHAR m[MAX_PATH + 512]; | ||
| 138 | m[0] = 0; | ||
| 139 | CatAscii(m, "ERROR:"); | ||
| 140 | if (s1) | ||
| 141 | { | ||
| 142 | CatAscii(m, "\n"); | ||
| 143 | CatAscii(m, s1); | ||
| 144 | } | ||
| 145 | if (s2) | ||
| 146 | { | ||
| 147 | CatAscii(m, "\n"); | ||
| 148 | wcscat(m, s2); | ||
| 149 | } | ||
| 150 | MessageBoxW(g_HWND, m, k_7zip_with_Ver_Uninstall, MB_ICONERROR | MB_OK); | ||
| 151 | } | ||
| 152 | |||
| 153 | |||
| 154 | static BoolInt AreStringsEqual_NoCase(const wchar_t *s1, const wchar_t *s2) | ||
| 155 | { | ||
| 156 | for (;;) | ||
| 157 | { | ||
| 158 | wchar_t c1 = *s1++; | ||
| 159 | wchar_t c2 = *s2++; | ||
| 160 | if (c1 != c2 && MAKE_CHAR_UPPER(c1) != MAKE_CHAR_UPPER(c2)) | ||
| 161 | return False; | ||
| 162 | if (c2 == 0) | ||
| 163 | return True; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | static BoolInt IsString1PrefixedByString2_NoCase(const wchar_t *s1, const wchar_t *s2) | ||
| 168 | { | ||
| 169 | for (;;) | ||
| 170 | { | ||
| 171 | wchar_t c1; | ||
| 172 | wchar_t c2 = *s2++; | ||
| 173 | if (c2 == 0) | ||
| 174 | return True; | ||
| 175 | c1 = *s1++; | ||
| 176 | if (c1 != c2 && MAKE_CHAR_UPPER(c1) != MAKE_CHAR_UPPER(c2)) | ||
| 177 | return False; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | static void NormalizePrefix(WCHAR *s) | ||
| 182 | { | ||
| 183 | size_t len = wcslen(s); | ||
| 184 | if (len != 0) | ||
| 185 | if (s[len - 1] != WCHAR_PATH_SEPARATOR) | ||
| 186 | { | ||
| 187 | s[len] = WCHAR_PATH_SEPARATOR; | ||
| 188 | s[len + 1] = 0; | ||
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 192 | static int MyRegistry_QueryString(HKEY hKey, LPCWSTR name, LPWSTR dest) | ||
| 193 | { | ||
| 194 | DWORD cnt = MAX_PATH * sizeof(name[0]); | ||
| 195 | DWORD type = 0; | ||
| 196 | LONG res = RegQueryValueExW(hKey, name, NULL, &type, (LPBYTE)dest, (DWORD *)&cnt); | ||
| 197 | if (type != REG_SZ) | ||
| 198 | return False; | ||
| 199 | return res == ERROR_SUCCESS; | ||
| 200 | } | ||
| 201 | |||
| 202 | static int MyRegistry_QueryString2(HKEY hKey, LPCWSTR keyName, LPCWSTR valName, LPWSTR dest) | ||
| 203 | { | ||
| 204 | HKEY key = 0; | ||
| 205 | LONG res = RegOpenKeyExW(hKey, keyName, 0, KEY_READ | k_Reg_WOW_Flag, &key); | ||
| 206 | if (res != ERROR_SUCCESS) | ||
| 207 | return False; | ||
| 208 | { | ||
| 209 | BoolInt res2 = MyRegistry_QueryString(key, valName, dest); | ||
| 210 | RegCloseKey(key); | ||
| 211 | return res2; | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | static LONG MyRegistry_OpenKey_ReadWrite(HKEY parentKey, LPCWSTR name, HKEY *destKey) | ||
| 216 | { | ||
| 217 | return RegOpenKeyExW(parentKey, name, 0, KEY_READ | KEY_WRITE | k_Reg_WOW_Flag, destKey); | ||
| 218 | } | ||
| 219 | |||
| 220 | static LONG MyRegistry_DeleteKey(HKEY parentKey, LPCWSTR name) | ||
| 221 | { | ||
| 222 | #if k_Reg_WOW_Flag != 0 | ||
| 223 | if (func_RegDeleteKeyExW) | ||
| 224 | return func_RegDeleteKeyExW(parentKey, name, k_Reg_WOW_Flag, 0); | ||
| 225 | return E_FAIL; | ||
| 226 | #else | ||
| 227 | return RegDeleteKeyW(parentKey, name); | ||
| 228 | #endif | ||
| 229 | } | ||
| 230 | |||
| 231 | #ifdef USE_7ZIP_32_DLL | ||
| 232 | |||
| 233 | static int MyRegistry_QueryString2_32(HKEY hKey, LPCWSTR keyName, LPCWSTR valName, LPWSTR dest) | ||
| 234 | { | ||
| 235 | HKEY key = 0; | ||
| 236 | LONG res = RegOpenKeyExW(hKey, keyName, 0, KEY_READ | k_Reg_WOW_Flag_32, &key); | ||
| 237 | if (res != ERROR_SUCCESS) | ||
| 238 | return False; | ||
| 239 | { | ||
| 240 | BoolInt res2 = MyRegistry_QueryString(key, valName, dest); | ||
| 241 | RegCloseKey(key); | ||
| 242 | return res2; | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 246 | static LONG MyRegistry_OpenKey_ReadWrite_32(HKEY parentKey, LPCWSTR name, HKEY *destKey) | ||
| 247 | { | ||
| 248 | return RegOpenKeyExW(parentKey, name, 0, KEY_READ | KEY_WRITE | k_Reg_WOW_Flag_32, destKey); | ||
| 249 | } | ||
| 250 | |||
| 251 | static LONG MyRegistry_DeleteKey_32(HKEY parentKey, LPCWSTR name) | ||
| 252 | { | ||
| 253 | #if k_Reg_WOW_Flag_32 != 0 | ||
| 254 | if (func_RegDeleteKeyExW) | ||
| 255 | return func_RegDeleteKeyExW(parentKey, name, k_Reg_WOW_Flag_32, 0); | ||
| 256 | return E_FAIL; | ||
| 257 | #else | ||
| 258 | return RegDeleteKeyW(parentKey, name); | ||
| 259 | #endif | ||
| 260 | } | ||
| 261 | |||
| 262 | #endif | ||
| 263 | |||
| 264 | |||
| 265 | |||
| 266 | |||
| 267 | static void MyReg_DeleteVal_Path_if_Equal(HKEY hKey, LPCWSTR name) | ||
| 268 | { | ||
| 269 | WCHAR s[MAX_PATH + 10]; | ||
| 270 | if (MyRegistry_QueryString(hKey, name, s)) | ||
| 271 | { | ||
| 272 | NormalizePrefix(s); | ||
| 273 | if (AreStringsEqual_NoCase(s, path)) | ||
| 274 | RegDeleteValueW(hKey, name); | ||
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 | static void SetRegKey_Path2(HKEY parentKey) | ||
| 279 | { | ||
| 280 | HKEY key = 0; | ||
| 281 | LONG res = MyRegistry_OpenKey_ReadWrite(parentKey, k_Reg_Software_7zip, &key); | ||
| 282 | if (res == ERROR_SUCCESS) | ||
| 283 | { | ||
| 284 | MyReg_DeleteVal_Path_if_Equal(key, k_Reg_Path32); | ||
| 285 | MyReg_DeleteVal_Path_if_Equal(key, k_Reg_Path); | ||
| 286 | |||
| 287 | RegCloseKey(key); | ||
| 288 | // MyRegistry_DeleteKey(parentKey, k_Reg_Software_7zip); | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | static void SetRegKey_Path() | ||
| 293 | { | ||
| 294 | SetRegKey_Path2(HKEY_CURRENT_USER); | ||
| 295 | SetRegKey_Path2(HKEY_LOCAL_MACHINE); | ||
| 296 | } | ||
| 297 | |||
| 298 | static HRESULT CreateShellLink(LPCWSTR srcPath, LPCWSTR targetPath) | ||
| 299 | { | ||
| 300 | IShellLinkW *sl; | ||
| 301 | |||
| 302 | // CoInitialize has already been called. | ||
| 303 | HRESULT hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID*)&sl); | ||
| 304 | |||
| 305 | if (SUCCEEDED(hres)) | ||
| 306 | { | ||
| 307 | IPersistFile *pf; | ||
| 308 | |||
| 309 | hres = sl->lpVtbl->QueryInterface(sl, &IID_IPersistFile, (LPVOID *)&pf); | ||
| 310 | |||
| 311 | if (SUCCEEDED(hres)) | ||
| 312 | { | ||
| 313 | WCHAR s[MAX_PATH + 10]; | ||
| 314 | hres = pf->lpVtbl->Load(pf, srcPath, TRUE); | ||
| 315 | pf->lpVtbl->Release(pf); | ||
| 316 | |||
| 317 | if (SUCCEEDED(hres)) | ||
| 318 | { | ||
| 319 | hres = sl->lpVtbl->GetPath(sl, s, MAX_PATH, NULL, 0); // SLGP_RAWPATH | ||
| 320 | if (!AreStringsEqual_NoCase(s, targetPath)) | ||
| 321 | hres = S_FALSE; | ||
| 322 | } | ||
| 323 | } | ||
| 324 | |||
| 325 | sl->lpVtbl->Release(sl); | ||
| 326 | } | ||
| 327 | |||
| 328 | return hres; | ||
| 329 | } | ||
| 330 | |||
| 331 | static void SetShellProgramsGroup(HWND hwndOwner) | ||
| 332 | { | ||
| 333 | #ifdef UNDER_CE | ||
| 334 | |||
| 335 | UNUSED_VAR(hwndOwner) | ||
| 336 | |||
| 337 | #else | ||
| 338 | |||
| 339 | unsigned i = (g_AllUsers ? 1 : 2); | ||
| 340 | |||
| 341 | for (; i < 3; i++) | ||
| 342 | { | ||
| 343 | // BoolInt isOK = True; | ||
| 344 | WCHAR link[MAX_PATH + 40]; | ||
| 345 | WCHAR destPath[MAX_PATH + 40]; | ||
| 346 | |||
| 347 | link[0] = 0; | ||
| 348 | |||
| 349 | if (SHGetFolderPathW(hwndOwner, | ||
| 350 | i == 1 ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, | ||
| 351 | NULL, SHGFP_TYPE_CURRENT, link) != S_OK) | ||
| 352 | continue; | ||
| 353 | |||
| 354 | NormalizePrefix(link); | ||
| 355 | CatAscii(link, "7-Zip\\"); | ||
| 356 | |||
| 357 | { | ||
| 358 | const size_t baseLen = wcslen(link); | ||
| 359 | unsigned k; | ||
| 360 | BoolInt needDelete = False; | ||
| 361 | |||
| 362 | for (k = 0; k < 2; k++) | ||
| 363 | { | ||
| 364 | CpyAscii(link + baseLen, k == 0 ? | ||
| 365 | "7-Zip File Manager.lnk" : | ||
| 366 | "7-Zip Help.lnk"); | ||
| 367 | wcscpy(destPath, path); | ||
| 368 | CatAscii(destPath, k == 0 ? | ||
| 369 | "7zFM.exe" : | ||
| 370 | "7-zip.chm"); | ||
| 371 | |||
| 372 | if (CreateShellLink(link, destPath) == S_OK) | ||
| 373 | { | ||
| 374 | needDelete = True; | ||
| 375 | DeleteFileW(link); | ||
| 376 | } | ||
| 377 | } | ||
| 378 | |||
| 379 | if (needDelete) | ||
| 380 | { | ||
| 381 | link[baseLen] = 0; | ||
| 382 | RemoveDirectoryW(link); | ||
| 383 | } | ||
| 384 | } | ||
| 385 | } | ||
| 386 | |||
| 387 | #endif | ||
| 388 | } | ||
| 389 | |||
| 390 | |||
| 391 | static LPCSTR const k_ShellEx_Items[] = | ||
| 392 | { | ||
| 393 | "*\\shellex\\ContextMenuHandlers" | ||
| 394 | , "Directory\\shellex\\ContextMenuHandlers" | ||
| 395 | , "Folder\\shellex\\ContextMenuHandlers" | ||
| 396 | , "Directory\\shellex\\DragDropHandlers" | ||
| 397 | , "Drive\\shellex\\DragDropHandlers" | ||
| 398 | }; | ||
| 399 | |||
| 400 | static LPCWSTR const k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"; | ||
| 401 | |||
| 402 | static LPCWSTR const k_AppPaths_7zFm = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\7zFM.exe"; | ||
| 403 | #define k_REG_Uninstall L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" | ||
| 404 | static LPCWSTR const k_Uninstall_7zip = k_REG_Uninstall L"7-Zip"; | ||
| 405 | |||
| 406 | |||
| 407 | static void RemoveQuotes(wchar_t *s) | ||
| 408 | { | ||
| 409 | const size_t len = wcslen(s); | ||
| 410 | size_t i; | ||
| 411 | if (len == 0 || s[0] != '\"' || s[len - 1] != '\"') | ||
| 412 | return; | ||
| 413 | for (i = 0; i < len; i++) | ||
| 414 | s[i] = s[i + 1]; | ||
| 415 | s[len - 2] = 0; | ||
| 416 | } | ||
| 417 | |||
| 418 | static BoolInt AreEqual_Path_PrefixName(const wchar_t *s, const wchar_t *prefix, const wchar_t *name) | ||
| 419 | { | ||
| 420 | if (!IsString1PrefixedByString2_NoCase(s, prefix)) | ||
| 421 | return False; | ||
| 422 | return AreStringsEqual_NoCase(s + wcslen(prefix), name); | ||
| 423 | } | ||
| 424 | |||
| 425 | static void WriteCLSID() | ||
| 426 | { | ||
| 427 | WCHAR s[MAX_PATH + 30]; | ||
| 428 | |||
| 429 | if (MyRegistry_QueryString2(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc, NULL, s)) | ||
| 430 | { | ||
| 431 | if (AreEqual_Path_PrefixName(s, path, L"7-zip.dll")) | ||
| 432 | { | ||
| 433 | { | ||
| 434 | LONG res = MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc); | ||
| 435 | if (res == ERROR_SUCCESS) | ||
| 436 | MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip); | ||
| 437 | } | ||
| 438 | |||
| 439 | { | ||
| 440 | unsigned i; | ||
| 441 | for (i = 0; i < ARRAY_SIZE(k_ShellEx_Items); i++) | ||
| 442 | { | ||
| 443 | WCHAR destPath[MAX_PATH]; | ||
| 444 | CpyAscii(destPath, k_ShellEx_Items[i]); | ||
| 445 | CatAscii(destPath, "\\7-Zip"); | ||
| 446 | |||
| 447 | MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, destPath); | ||
| 448 | } | ||
| 449 | } | ||
| 450 | |||
| 451 | { | ||
| 452 | HKEY destKey = 0; | ||
| 453 | LONG res = MyRegistry_OpenKey_ReadWrite(HKEY_LOCAL_MACHINE, k_Shell_Approved, &destKey); | ||
| 454 | if (res == ERROR_SUCCESS) | ||
| 455 | { | ||
| 456 | RegDeleteValueW(destKey, k_7zip_CLSID); | ||
| 457 | /* res = */ RegCloseKey(destKey); | ||
| 458 | } | ||
| 459 | } | ||
| 460 | } | ||
| 461 | } | ||
| 462 | |||
| 463 | |||
| 464 | #ifdef USE_7ZIP_32_DLL | ||
| 465 | |||
| 466 | if (MyRegistry_QueryString2_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc, NULL, s)) | ||
| 467 | { | ||
| 468 | if (AreEqual_Path_PrefixName(s, path, L"7-zip32.dll")) | ||
| 469 | { | ||
| 470 | { | ||
| 471 | LONG res = MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc); | ||
| 472 | if (res == ERROR_SUCCESS) | ||
| 473 | MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip); | ||
| 474 | } | ||
| 475 | |||
| 476 | { | ||
| 477 | unsigned i; | ||
| 478 | for (i = 0; i < ARRAY_SIZE(k_ShellEx_Items); i++) | ||
| 479 | { | ||
| 480 | WCHAR destPath[MAX_PATH]; | ||
| 481 | CpyAscii(destPath, k_ShellEx_Items[i]); | ||
| 482 | CatAscii(destPath, "\\7-Zip"); | ||
| 483 | |||
| 484 | MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, destPath); | ||
| 485 | } | ||
| 486 | } | ||
| 487 | |||
| 488 | { | ||
| 489 | HKEY destKey = 0; | ||
| 490 | LONG res = MyRegistry_OpenKey_ReadWrite_32(HKEY_LOCAL_MACHINE, k_Shell_Approved, &destKey); | ||
| 491 | if (res == ERROR_SUCCESS) | ||
| 492 | { | ||
| 493 | RegDeleteValueW(destKey, k_7zip_CLSID); | ||
| 494 | /* res = */ RegCloseKey(destKey); | ||
| 495 | } | ||
| 496 | } | ||
| 497 | } | ||
| 498 | } | ||
| 499 | |||
| 500 | #endif | ||
| 501 | |||
| 502 | |||
| 503 | if (MyRegistry_QueryString2(HKEY_LOCAL_MACHINE, k_AppPaths_7zFm, NULL, s)) | ||
| 504 | { | ||
| 505 | // RemoveQuotes(s); | ||
| 506 | if (AreEqual_Path_PrefixName(s, path, L"7zFM.exe")) | ||
| 507 | MyRegistry_DeleteKey(HKEY_LOCAL_MACHINE, k_AppPaths_7zFm); | ||
| 508 | } | ||
| 509 | |||
| 510 | if (MyRegistry_QueryString2(HKEY_LOCAL_MACHINE, k_Uninstall_7zip, L"UninstallString", s)) | ||
| 511 | { | ||
| 512 | RemoveQuotes(s); | ||
| 513 | if (AreEqual_Path_PrefixName(s, path, kUninstallExe)) | ||
| 514 | MyRegistry_DeleteKey(HKEY_LOCAL_MACHINE, k_Uninstall_7zip); | ||
| 515 | } | ||
| 516 | } | ||
| 517 | |||
| 518 | |||
| 519 | static const wchar_t *GetCmdParam(const wchar_t *s) | ||
| 520 | { | ||
| 521 | unsigned pos = 0; | ||
| 522 | BoolInt quoteMode = False; | ||
| 523 | for (;; s++) | ||
| 524 | { | ||
| 525 | wchar_t c = *s; | ||
| 526 | if (c == 0 || (c == L' ' && !quoteMode)) | ||
| 527 | break; | ||
| 528 | if (c == L'\"') | ||
| 529 | { | ||
| 530 | quoteMode = !quoteMode; | ||
| 531 | continue; | ||
| 532 | } | ||
| 533 | if (pos >= ARRAY_SIZE(cmd) - 1) | ||
| 534 | exit(1); | ||
| 535 | cmd[pos++] = c; | ||
| 536 | } | ||
| 537 | cmd[pos] = 0; | ||
| 538 | return s; | ||
| 539 | } | ||
| 540 | |||
| 541 | /* | ||
| 542 | static void RemoveQuotes(wchar_t *s) | ||
| 543 | { | ||
| 544 | const wchar_t *src = s; | ||
| 545 | for (;;) | ||
| 546 | { | ||
| 547 | wchar_t c = *src++; | ||
| 548 | if (c == '\"') | ||
| 549 | continue; | ||
| 550 | *s++ = c; | ||
| 551 | if (c == 0) | ||
| 552 | return; | ||
| 553 | } | ||
| 554 | } | ||
| 555 | */ | ||
| 556 | |||
| 557 | static BoolInt DoesFileOrDirExist() | ||
| 558 | { | ||
| 559 | return (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES); | ||
| 560 | } | ||
| 561 | |||
| 562 | static BOOL RemoveFileAfterReboot2(const WCHAR *s) | ||
| 563 | { | ||
| 564 | #ifndef UNDER_CE | ||
| 565 | return MoveFileExW(s, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); | ||
| 566 | #else | ||
| 567 | UNUSED_VAR(s) | ||
| 568 | return TRUE; | ||
| 569 | #endif | ||
| 570 | } | ||
| 571 | |||
| 572 | static BOOL RemoveFileAfterReboot() | ||
| 573 | { | ||
| 574 | return RemoveFileAfterReboot2(path); | ||
| 575 | } | ||
| 576 | |||
| 577 | // #define IS_LIMIT_CHAR(c) (c == 0 || c == ' ') | ||
| 578 | |||
| 579 | static BoolInt IsThereSpace(const wchar_t *s) | ||
| 580 | { | ||
| 581 | for (;;) | ||
| 582 | { | ||
| 583 | wchar_t c = *s++; | ||
| 584 | if (c == 0) | ||
| 585 | return False; | ||
| 586 | if (c == ' ') | ||
| 587 | return True; | ||
| 588 | } | ||
| 589 | } | ||
| 590 | |||
| 591 | static void AddPathParam(wchar_t *dest, const wchar_t *src) | ||
| 592 | { | ||
| 593 | BoolInt needQuote = IsThereSpace(src); | ||
| 594 | if (needQuote) | ||
| 595 | CatAscii(dest, "\""); | ||
| 596 | wcscat(dest, src); | ||
| 597 | if (needQuote) | ||
| 598 | CatAscii(dest, "\""); | ||
| 599 | } | ||
| 600 | |||
| 601 | |||
| 602 | |||
| 603 | static BoolInt GetErrorMessage(DWORD errorCode, WCHAR *message) | ||
| 604 | { | ||
| 605 | LPWSTR msgBuf; | ||
| 606 | if (FormatMessageW( | ||
| 607 | FORMAT_MESSAGE_ALLOCATE_BUFFER | ||
| 608 | | FORMAT_MESSAGE_FROM_SYSTEM | ||
| 609 | | FORMAT_MESSAGE_IGNORE_INSERTS, | ||
| 610 | NULL, errorCode, 0, (LPWSTR) &msgBuf, 0, NULL) == 0) | ||
| 611 | return False; | ||
| 612 | wcscpy(message, msgBuf); | ||
| 613 | LocalFree(msgBuf); | ||
| 614 | return True; | ||
| 615 | } | ||
| 616 | |||
| 617 | static BOOL RemoveDir() | ||
| 618 | { | ||
| 619 | DWORD attrib = GetFileAttributesW(path); | ||
| 620 | if (attrib == INVALID_FILE_ATTRIBUTES) | ||
| 621 | return TRUE; | ||
| 622 | if (RemoveDirectoryW(path)) | ||
| 623 | return TRUE; | ||
| 624 | return RemoveFileAfterReboot(); | ||
| 625 | } | ||
| 626 | |||
| 627 | |||
| 628 | |||
| 629 | |||
| 630 | |||
| 631 | #define k_Lang "Lang" | ||
| 632 | |||
| 633 | // NUM_LANG_TXT_FILES files are placed before en.ttt | ||
| 634 | #define NUM_LANG_TXT_FILES 92 | ||
| 635 | |||
| 636 | #ifdef USE_7ZIP_32_DLL | ||
| 637 | #define NUM_EXTRA_FILES_64BIT 1 | ||
| 638 | #else | ||
| 639 | #define NUM_EXTRA_FILES_64BIT 0 | ||
| 640 | #endif | ||
| 641 | |||
| 642 | #define NUM_FILES (NUM_LANG_TXT_FILES + 1 + 13 + NUM_EXTRA_FILES_64BIT) | ||
| 643 | |||
| 644 | static const char * const k_Names = | ||
| 645 | "af an ar ast az ba be bg bn br ca co cs cy da de el eo es et eu ext" | ||
| 646 | " 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" | ||
| 647 | " lij lt lv mk mn mng mng2 mr ms nb ne nl nn pa-in pl ps pt pt-br ro ru" | ||
| 648 | " 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" | ||
| 649 | " en.ttt" | ||
| 650 | " descript.ion" | ||
| 651 | " History.txt" | ||
| 652 | " License.txt" | ||
| 653 | " readme.txt" | ||
| 654 | " 7-zip.chm" | ||
| 655 | " 7z.sfx" | ||
| 656 | " 7zCon.sfx" | ||
| 657 | " 7z.exe" | ||
| 658 | " 7zG.exe" | ||
| 659 | " 7z.dll" | ||
| 660 | " 7zFM.exe" | ||
| 661 | #ifdef USE_7ZIP_32_DLL | ||
| 662 | " 7-zip32.dll" | ||
| 663 | #endif | ||
| 664 | " 7-zip.dll" | ||
| 665 | " Uninstall.exe"; | ||
| 666 | |||
| 667 | |||
| 668 | |||
| 669 | static int Install() | ||
| 670 | { | ||
| 671 | SRes res = SZ_OK; | ||
| 672 | WRes winRes = 0; | ||
| 673 | |||
| 674 | // BoolInt needReboot = False; | ||
| 675 | const size_t pathLen = wcslen(path); | ||
| 676 | |||
| 677 | if (!g_SilentMode) | ||
| 678 | { | ||
| 679 | ShowWindow(g_Progress_HWND, SW_SHOW); | ||
| 680 | ShowWindow(g_InfoLine_HWND, SW_SHOW); | ||
| 681 | SendMessage(g_Progress_HWND, PBM_SETRANGE32, 0, NUM_FILES); | ||
| 682 | } | ||
| 683 | |||
| 684 | { | ||
| 685 | unsigned i; | ||
| 686 | const char *curName = k_Names; | ||
| 687 | |||
| 688 | for (i = 0; *curName != 0; i++) | ||
| 689 | { | ||
| 690 | WCHAR *temp; | ||
| 691 | |||
| 692 | if (!g_SilentMode) | ||
| 693 | { | ||
| 694 | MSG msg; | ||
| 695 | |||
| 696 | // g_HWND | ||
| 697 | while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) | ||
| 698 | { | ||
| 699 | if (!IsDialogMessage(g_HWND, &msg)) | ||
| 700 | { | ||
| 701 | TranslateMessage(&msg); | ||
| 702 | DispatchMessage(&msg); | ||
| 703 | } | ||
| 704 | if (!g_HWND) | ||
| 705 | return 1; | ||
| 706 | } | ||
| 707 | |||
| 708 | // Sleep(1); | ||
| 709 | SendMessage(g_Progress_HWND, PBM_SETPOS, i, 0); | ||
| 710 | } | ||
| 711 | |||
| 712 | path[pathLen] = 0; | ||
| 713 | temp = path + pathLen; | ||
| 714 | |||
| 715 | if (i <= NUM_LANG_TXT_FILES) | ||
| 716 | CpyAscii(temp, k_Lang "\\"); | ||
| 717 | |||
| 718 | { | ||
| 719 | WCHAR *dest = temp + wcslen(temp); | ||
| 720 | |||
| 721 | for (;;) | ||
| 722 | { | ||
| 723 | char c = *curName; | ||
| 724 | if (c == 0) | ||
| 725 | break; | ||
| 726 | curName++; | ||
| 727 | if (c == ' ') | ||
| 728 | break; | ||
| 729 | *dest++ = (Byte)c; | ||
| 730 | } | ||
| 731 | |||
| 732 | *dest = 0; | ||
| 733 | } | ||
| 734 | |||
| 735 | if (i < NUM_LANG_TXT_FILES) | ||
| 736 | CatAscii(temp, ".txt"); | ||
| 737 | |||
| 738 | if (!g_SilentMode) | ||
| 739 | SetWindowTextW(g_InfoLine_HWND, temp); | ||
| 740 | |||
| 741 | { | ||
| 742 | DWORD attrib = GetFileAttributesW(path); | ||
| 743 | if (attrib == INVALID_FILE_ATTRIBUTES) | ||
| 744 | continue; | ||
| 745 | if (attrib & FILE_ATTRIBUTE_READONLY) | ||
| 746 | SetFileAttributesW(path, 0); | ||
| 747 | if (!DeleteFileW(path)) | ||
| 748 | { | ||
| 749 | if (!RemoveFileAfterReboot()) | ||
| 750 | { | ||
| 751 | winRes = GetLastError(); | ||
| 752 | } | ||
| 753 | /* | ||
| 754 | else | ||
| 755 | needReboot = True; | ||
| 756 | */ | ||
| 757 | } | ||
| 758 | } | ||
| 759 | } | ||
| 760 | |||
| 761 | CpyAscii(path + pathLen, k_Lang); | ||
| 762 | RemoveDir(); | ||
| 763 | |||
| 764 | path[pathLen] = 0; | ||
| 765 | RemoveDir(); | ||
| 766 | |||
| 767 | if (!g_SilentMode) | ||
| 768 | SendMessage(g_Progress_HWND, PBM_SETPOS, i, 0); | ||
| 769 | |||
| 770 | if (*curName == 0) | ||
| 771 | { | ||
| 772 | SetRegKey_Path(); | ||
| 773 | WriteCLSID(); | ||
| 774 | SetShellProgramsGroup(g_HWND); | ||
| 775 | if (!g_SilentMode) | ||
| 776 | SetWindowTextW(g_InfoLine_HWND, k_7zip_with_Ver L" is uninstalled"); | ||
| 777 | } | ||
| 778 | } | ||
| 779 | |||
| 780 | if (winRes != 0) | ||
| 781 | res = SZ_ERROR_FAIL; | ||
| 782 | |||
| 783 | if (res == SZ_OK) | ||
| 784 | { | ||
| 785 | // if (!g_SilentMode && needReboot); | ||
| 786 | return 0; | ||
| 787 | } | ||
| 788 | |||
| 789 | if (!g_SilentMode) | ||
| 790 | { | ||
| 791 | WCHAR m[MAX_PATH + 100]; | ||
| 792 | m[0] = 0; | ||
| 793 | if (winRes == 0 || !GetErrorMessage(winRes, m)) | ||
| 794 | CpyAscii(m, "ERROR"); | ||
| 795 | PrintErrorMessage("System ERROR:", m); | ||
| 796 | } | ||
| 797 | |||
| 798 | return 1; | ||
| 799 | } | ||
| 800 | |||
| 801 | |||
| 802 | static void OnClose() | ||
| 803 | { | ||
| 804 | if (g_Install_was_Pressed && !g_Finished) | ||
| 805 | { | ||
| 806 | if (MessageBoxW(g_HWND, | ||
| 807 | L"Do you want to cancel uninstallation?", | ||
| 808 | k_7zip_with_Ver_Uninstall, | ||
| 809 | MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES) | ||
| 810 | return; | ||
| 811 | } | ||
| 812 | DestroyWindow(g_HWND); | ||
| 813 | g_HWND = NULL; | ||
| 814 | } | ||
| 815 | |||
| 816 | static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 817 | { | ||
| 818 | UNUSED_VAR(lParam) | ||
| 819 | |||
| 820 | switch (message) | ||
| 821 | { | ||
| 822 | case WM_INITDIALOG: | ||
| 823 | g_Path_HWND = GetDlgItem(hwnd, IDE_EXTRACT_PATH); | ||
| 824 | g_InfoLine_HWND = GetDlgItem(hwnd, IDT_CUR_FILE); | ||
| 825 | g_Progress_HWND = GetDlgItem(hwnd, IDC_PROGRESS); | ||
| 826 | |||
| 827 | SetWindowTextW(hwnd, k_7zip_with_Ver_Uninstall); | ||
| 828 | SetDlgItemTextW(hwnd, IDE_EXTRACT_PATH, path); | ||
| 829 | |||
| 830 | ShowWindow(g_Progress_HWND, SW_HIDE); | ||
| 831 | ShowWindow(g_InfoLine_HWND, SW_HIDE); | ||
| 832 | |||
| 833 | break; | ||
| 834 | |||
| 835 | case WM_COMMAND: | ||
| 836 | switch (LOWORD(wParam)) | ||
| 837 | { | ||
| 838 | case IDOK: | ||
| 839 | { | ||
| 840 | if (g_Finished) | ||
| 841 | { | ||
| 842 | OnClose(); | ||
| 843 | break; | ||
| 844 | } | ||
| 845 | if (!g_Install_was_Pressed) | ||
| 846 | { | ||
| 847 | SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(hwnd, IDCANCEL), TRUE); | ||
| 848 | |||
| 849 | EnableWindow(g_Path_HWND, FALSE); | ||
| 850 | EnableWindow(GetDlgItem(hwnd, IDOK), FALSE); | ||
| 851 | |||
| 852 | g_Install_was_Pressed = True; | ||
| 853 | return TRUE; | ||
| 854 | } | ||
| 855 | break; | ||
| 856 | } | ||
| 857 | |||
| 858 | case IDCANCEL: | ||
| 859 | { | ||
| 860 | OnClose(); | ||
| 861 | break; | ||
| 862 | } | ||
| 863 | |||
| 864 | default: return FALSE; | ||
| 865 | } | ||
| 866 | break; | ||
| 867 | |||
| 868 | case WM_CLOSE: | ||
| 869 | OnClose(); | ||
| 870 | break; | ||
| 871 | /* | ||
| 872 | case WM_DESTROY: | ||
| 873 | PostQuitMessage(0); | ||
| 874 | return TRUE; | ||
| 875 | */ | ||
| 876 | default: | ||
| 877 | return FALSE; | ||
| 878 | } | ||
| 879 | |||
| 880 | return TRUE; | ||
| 881 | } | ||
| 882 | |||
| 883 | |||
| 884 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, | ||
| 885 | #ifdef UNDER_CE | ||
| 886 | LPWSTR | ||
| 887 | #else | ||
| 888 | LPSTR | ||
| 889 | #endif | ||
| 890 | lpCmdLine, int nCmdShow) | ||
| 891 | { | ||
| 892 | const wchar_t *cmdParams; | ||
| 893 | BoolInt useTemp = True; | ||
| 894 | |||
| 895 | UNUSED_VAR(hPrevInstance) | ||
| 896 | UNUSED_VAR(lpCmdLine) | ||
| 897 | UNUSED_VAR(nCmdShow) | ||
| 898 | |||
| 899 | #ifndef UNDER_CE | ||
| 900 | CoInitialize(NULL); | ||
| 901 | #endif | ||
| 902 | |||
| 903 | #ifndef UNDER_CE | ||
| 904 | func_RegDeleteKeyExW = (Func_RegDeleteKeyExW) | ||
| 905 | GetProcAddress(GetModuleHandleW(L"advapi32.dll"), "RegDeleteKeyExW"); | ||
| 906 | #endif | ||
| 907 | |||
| 908 | { | ||
| 909 | const wchar_t *s = GetCommandLineW(); | ||
| 910 | |||
| 911 | #ifndef UNDER_CE | ||
| 912 | s = GetCmdParam(s); | ||
| 913 | #endif | ||
| 914 | |||
| 915 | cmdParams = s; | ||
| 916 | |||
| 917 | for (;;) | ||
| 918 | { | ||
| 919 | { | ||
| 920 | wchar_t c = *s; | ||
| 921 | if (c == 0) | ||
| 922 | break; | ||
| 923 | if (c == ' ') | ||
| 924 | { | ||
| 925 | s++; | ||
| 926 | continue; | ||
| 927 | } | ||
| 928 | } | ||
| 929 | |||
| 930 | { | ||
| 931 | const wchar_t *s2 = GetCmdParam(s); | ||
| 932 | BoolInt error = True; | ||
| 933 | if (cmd[0] == '/') | ||
| 934 | { | ||
| 935 | if (cmd[1] == 'S') | ||
| 936 | { | ||
| 937 | if (cmd[2] == 0) | ||
| 938 | { | ||
| 939 | g_SilentMode = True; | ||
| 940 | error = False; | ||
| 941 | } | ||
| 942 | } | ||
| 943 | else if (cmd[1] == 'N') | ||
| 944 | { | ||
| 945 | if (cmd[2] == 0) | ||
| 946 | { | ||
| 947 | useTemp = False; | ||
| 948 | error = False; | ||
| 949 | } | ||
| 950 | } | ||
| 951 | else if (cmd[1] == 'D' && cmd[2] == '=') | ||
| 952 | { | ||
| 953 | wcscpy(workDir, cmd + 3); | ||
| 954 | // RemoveQuotes(workDir); | ||
| 955 | useTemp = False; | ||
| 956 | error = False; | ||
| 957 | } | ||
| 958 | } | ||
| 959 | s = s2; | ||
| 960 | if (error && cmdError[0] == 0) | ||
| 961 | wcscpy(cmdError, cmd); | ||
| 962 | } | ||
| 963 | } | ||
| 964 | |||
| 965 | if (cmdError[0] != 0) | ||
| 966 | { | ||
| 967 | if (!g_SilentMode) | ||
| 968 | PrintErrorMessage("Unsupported command:", cmdError); | ||
| 969 | return 1; | ||
| 970 | } | ||
| 971 | } | ||
| 972 | |||
| 973 | { | ||
| 974 | wchar_t *name; | ||
| 975 | DWORD len = GetModuleFileNameW(NULL, modulePath, MAX_PATH); | ||
| 976 | if (len == 0 || len > MAX_PATH) | ||
| 977 | return 1; | ||
| 978 | |||
| 979 | name = NULL; | ||
| 980 | wcscpy(modulePrefix, modulePath); | ||
| 981 | |||
| 982 | { | ||
| 983 | wchar_t *s = modulePrefix; | ||
| 984 | for (;;) | ||
| 985 | { | ||
| 986 | wchar_t c = *s++; | ||
| 987 | if (c == 0) | ||
| 988 | break; | ||
| 989 | if (c == WCHAR_PATH_SEPARATOR) | ||
| 990 | name = s; | ||
| 991 | } | ||
| 992 | } | ||
| 993 | |||
| 994 | if (!name) | ||
| 995 | return 1; | ||
| 996 | |||
| 997 | if (!AreStringsEqual_NoCase(name, kUninstallExe)) | ||
| 998 | useTemp = False; | ||
| 999 | |||
| 1000 | *name = 0; // keep only prefix for modulePrefix | ||
| 1001 | } | ||
| 1002 | |||
| 1003 | |||
| 1004 | if (useTemp) | ||
| 1005 | { | ||
| 1006 | DWORD winRes = GetTempPathW(MAX_PATH, path); | ||
| 1007 | |||
| 1008 | // GetTempPath: the returned string ends with a backslash | ||
| 1009 | /* | ||
| 1010 | { | ||
| 1011 | WCHAR s[MAX_PATH + 1]; | ||
| 1012 | wcscpy(s, path); | ||
| 1013 | GetLongPathNameW(s, path, MAX_PATH); | ||
| 1014 | } | ||
| 1015 | */ | ||
| 1016 | |||
| 1017 | if (winRes != 0 && winRes <= MAX_PATH + 1 | ||
| 1018 | && !IsString1PrefixedByString2_NoCase(modulePrefix, path)) | ||
| 1019 | { | ||
| 1020 | unsigned i; | ||
| 1021 | DWORD d; | ||
| 1022 | |||
| 1023 | const size_t pathLen = wcslen(path); | ||
| 1024 | d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId(); | ||
| 1025 | |||
| 1026 | for (i = 0; i < 100; i++, d += GetTickCount()) | ||
| 1027 | { | ||
| 1028 | CpyAscii(path + pathLen, "7z"); | ||
| 1029 | |||
| 1030 | { | ||
| 1031 | wchar_t *s = path + wcslen(path); | ||
| 1032 | UInt32 value = d; | ||
| 1033 | unsigned k; | ||
| 1034 | for (k = 0; k < 8; k++) | ||
| 1035 | { | ||
| 1036 | unsigned t = value & 0xF; | ||
| 1037 | value >>= 4; | ||
| 1038 | s[7 - k] = (wchar_t)((t < 10) ? ('0' + t) : ('A' + (t - 10))); | ||
| 1039 | } | ||
| 1040 | s[k] = 0; | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | if (DoesFileOrDirExist()) | ||
| 1044 | continue; | ||
| 1045 | if (CreateDirectoryW(path, NULL)) | ||
| 1046 | { | ||
| 1047 | CatAscii(path, STRING_PATH_SEPARATOR); | ||
| 1048 | wcscpy(tempPath, path); | ||
| 1049 | break; | ||
| 1050 | } | ||
| 1051 | if (GetLastError() != ERROR_ALREADY_EXISTS) | ||
| 1052 | break; | ||
| 1053 | } | ||
| 1054 | |||
| 1055 | if (tempPath[0] != 0) | ||
| 1056 | { | ||
| 1057 | wcscpy(copyPath, tempPath); | ||
| 1058 | CatAscii(copyPath, "Uninst.exe"); // we need not "Uninstall.exe" here | ||
| 1059 | |||
| 1060 | if (CopyFileW(modulePath, copyPath, TRUE)) | ||
| 1061 | { | ||
| 1062 | RemoveFileAfterReboot2(copyPath); | ||
| 1063 | RemoveFileAfterReboot2(tempPath); | ||
| 1064 | |||
| 1065 | { | ||
| 1066 | STARTUPINFOW si; | ||
| 1067 | PROCESS_INFORMATION pi; | ||
| 1068 | cmdLine[0] = 0; | ||
| 1069 | |||
| 1070 | // maybe CreateProcess supports path with spaces even without quotes. | ||
| 1071 | AddPathParam(cmdLine, copyPath); | ||
| 1072 | CatAscii(cmdLine, " /N /D="); | ||
| 1073 | AddPathParam(cmdLine, modulePrefix); | ||
| 1074 | |||
| 1075 | if (cmdParams[0] != 0 && wcslen(cmdParams) < MAX_PATH * 2 + 10) | ||
| 1076 | wcscat(cmdLine, cmdParams); | ||
| 1077 | |||
| 1078 | memset(&si, 0, sizeof(si)); | ||
| 1079 | si.cb = sizeof(si); | ||
| 1080 | |||
| 1081 | if (CreateProcessW(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, tempPath, &si, &pi)) | ||
| 1082 | { | ||
| 1083 | CloseHandle(pi.hThread); | ||
| 1084 | if (pi.hProcess) | ||
| 1085 | { | ||
| 1086 | CloseHandle(pi.hProcess); | ||
| 1087 | return 0; | ||
| 1088 | } | ||
| 1089 | } | ||
| 1090 | } | ||
| 1091 | } | ||
| 1092 | } | ||
| 1093 | } | ||
| 1094 | } | ||
| 1095 | |||
| 1096 | wcscpy(path, modulePrefix); | ||
| 1097 | |||
| 1098 | if (workDir[0] != 0) | ||
| 1099 | { | ||
| 1100 | wcscpy(path, workDir); | ||
| 1101 | NormalizePrefix(path); | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | /* | ||
| 1105 | if (path[0] == 0) | ||
| 1106 | { | ||
| 1107 | HKEY key = 0; | ||
| 1108 | BoolInt ok = False; | ||
| 1109 | LONG res = RegOpenKeyExW(HKEY_CURRENT_USER, k_Reg_Software_7zip, 0, KEY_READ | k_Reg_WOW_Flag, &key); | ||
| 1110 | if (res == ERROR_SUCCESS) | ||
| 1111 | { | ||
| 1112 | ok = MyRegistry_QueryString(key, k_Reg_Path32, path); | ||
| 1113 | // ok = MyRegistry_QueryString(key, k_Reg_Path, path); | ||
| 1114 | RegCloseKey(key); | ||
| 1115 | } | ||
| 1116 | } | ||
| 1117 | */ | ||
| 1118 | |||
| 1119 | |||
| 1120 | if (g_SilentMode) | ||
| 1121 | return Install(); | ||
| 1122 | |||
| 1123 | { | ||
| 1124 | int retCode = 1; | ||
| 1125 | g_HWND = CreateDialog( | ||
| 1126 | hInstance, | ||
| 1127 | // GetModuleHandle(NULL), | ||
| 1128 | MAKEINTRESOURCE(IDD_INSTALL), NULL, MyDlgProc); | ||
| 1129 | if (!g_HWND) | ||
| 1130 | return 1; | ||
| 1131 | |||
| 1132 | { | ||
| 1133 | HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); | ||
| 1134 | // SendMessage(g_HWND, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon); | ||
| 1135 | SendMessage(g_HWND, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon); | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | { | ||
| 1139 | BOOL bRet; | ||
| 1140 | MSG msg; | ||
| 1141 | |||
| 1142 | while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) | ||
| 1143 | { | ||
| 1144 | if (bRet == -1) | ||
| 1145 | return retCode; | ||
| 1146 | if (!g_HWND) | ||
| 1147 | return retCode; | ||
| 1148 | |||
| 1149 | if (!IsDialogMessage(g_HWND, &msg)) | ||
| 1150 | { | ||
| 1151 | TranslateMessage(&msg); | ||
| 1152 | DispatchMessage(&msg); | ||
| 1153 | } | ||
| 1154 | if (!g_HWND) | ||
| 1155 | return retCode; | ||
| 1156 | |||
| 1157 | if (g_Install_was_Pressed && !g_Finished) | ||
| 1158 | { | ||
| 1159 | retCode = Install(); | ||
| 1160 | g_Finished = True; | ||
| 1161 | if (retCode != 0) | ||
| 1162 | break; | ||
| 1163 | if (!g_HWND) | ||
| 1164 | break; | ||
| 1165 | { | ||
| 1166 | SetDlgItemTextW(g_HWND, IDOK, L"Close"); | ||
| 1167 | EnableWindow(GetDlgItem(g_HWND, IDOK), TRUE); | ||
| 1168 | EnableWindow(GetDlgItem(g_HWND, IDCANCEL), FALSE); | ||
| 1169 | SendMessage(g_HWND, WM_NEXTDLGCTL, (WPARAM)(void *)GetDlgItem(g_HWND, IDOK), TRUE); | ||
| 1170 | } | ||
| 1171 | } | ||
| 1172 | } | ||
| 1173 | |||
| 1174 | if (g_HWND) | ||
| 1175 | { | ||
| 1176 | DestroyWindow(g_HWND); | ||
| 1177 | g_HWND = NULL; | ||
| 1178 | } | ||
| 1179 | } | ||
| 1180 | |||
| 1181 | return retCode; | ||
| 1182 | } | ||
| 1183 | } | ||
diff --git a/C/Util/7zipUninstall/7zipUninstall.dsp b/C/Util/7zipUninstall/7zipUninstall.dsp new file mode 100644 index 0000000..cc7b6b6 --- /dev/null +++ b/C/Util/7zipUninstall/7zipUninstall.dsp | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | # Microsoft Developer Studio Project File - Name="7zipUninstall" - Package Owner=<4> | ||
| 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 | ||
| 3 | # ** DO NOT EDIT ** | ||
| 4 | |||
| 5 | # TARGTYPE "Win32 (x86) Application" 0x0101 | ||
| 6 | |||
| 7 | CFG=7zipUninstall - Win32 Debug | ||
| 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, | ||
| 9 | !MESSAGE use the Export Makefile command and run | ||
| 10 | !MESSAGE | ||
| 11 | !MESSAGE NMAKE /f "7zipUninstall.mak". | ||
| 12 | !MESSAGE | ||
| 13 | !MESSAGE You can specify a configuration when running NMAKE | ||
| 14 | !MESSAGE by defining the macro CFG on the command line. For example: | ||
| 15 | !MESSAGE | ||
| 16 | !MESSAGE NMAKE /f "7zipUninstall.mak" CFG="7zipUninstall - Win32 Debug" | ||
| 17 | !MESSAGE | ||
| 18 | !MESSAGE Possible choices for configuration are: | ||
| 19 | !MESSAGE | ||
| 20 | !MESSAGE "7zipUninstall - Win32 Release" (based on "Win32 (x86) Application") | ||
| 21 | !MESSAGE "7zipUninstall - Win32 Debug" (based on "Win32 (x86) Application") | ||
| 22 | !MESSAGE | ||
| 23 | |||
| 24 | # Begin Project | ||
| 25 | # PROP AllowPerConfigDependencies 0 | ||
| 26 | # PROP Scc_ProjName "" | ||
| 27 | # PROP Scc_LocalPath "" | ||
| 28 | CPP=cl.exe | ||
| 29 | MTL=midl.exe | ||
| 30 | RSC=rc.exe | ||
| 31 | |||
| 32 | !IF "$(CFG)" == "7zipUninstall - Win32 Release" | ||
| 33 | |||
| 34 | # PROP BASE Use_MFC 0 | ||
| 35 | # PROP BASE Use_Debug_Libraries 0 | ||
| 36 | # PROP BASE Output_Dir "Release" | ||
| 37 | # PROP BASE Intermediate_Dir "Release" | ||
| 38 | # PROP BASE Target_Dir "" | ||
| 39 | # PROP Use_MFC 0 | ||
| 40 | # PROP Use_Debug_Libraries 0 | ||
| 41 | # PROP Output_Dir "Release" | ||
| 42 | # PROP Intermediate_Dir "Release" | ||
| 43 | # PROP Ignore_Export_Lib 0 | ||
| 44 | # PROP Target_Dir "" | ||
| 45 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c | ||
| 46 | # ADD CPP /nologo /Gr /MD /W4 /WX /GX /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /FAcs /Yu"Precomp.h" /FD /GF /c | ||
| 47 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 48 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 49 | # ADD BASE RSC /l 0x419 /d "NDEBUG" | ||
| 50 | # ADD RSC /l 0x419 /d "NDEBUG" | ||
| 51 | BSC32=bscmake.exe | ||
| 52 | # ADD BASE BSC32 /nologo | ||
| 53 | # ADD BSC32 /nologo | ||
| 54 | LINK32=link.exe | ||
| 55 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 | ||
| 56 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"Release/Uninstall.exe" | ||
| 57 | |||
| 58 | !ELSEIF "$(CFG)" == "7zipUninstall - Win32 Debug" | ||
| 59 | |||
| 60 | # PROP BASE Use_MFC 0 | ||
| 61 | # PROP BASE Use_Debug_Libraries 1 | ||
| 62 | # PROP BASE Output_Dir "Debug" | ||
| 63 | # PROP BASE Intermediate_Dir "Debug" | ||
| 64 | # PROP BASE Target_Dir "" | ||
| 65 | # PROP Use_MFC 0 | ||
| 66 | # PROP Use_Debug_Libraries 1 | ||
| 67 | # PROP Output_Dir "Debug" | ||
| 68 | # PROP Intermediate_Dir "Debug" | ||
| 69 | # PROP Ignore_Export_Lib 0 | ||
| 70 | # PROP Target_Dir "" | ||
| 71 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c | ||
| 72 | # ADD CPP /nologo /W4 /WX /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /Yu"Precomp.h" /FD /GZ /c | ||
| 73 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 74 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 75 | # ADD BASE RSC /l 0x419 /d "_DEBUG" | ||
| 76 | # ADD RSC /l 0x419 /d "_DEBUG" | ||
| 77 | BSC32=bscmake.exe | ||
| 78 | # ADD BASE BSC32 /nologo | ||
| 79 | # ADD BSC32 /nologo | ||
| 80 | LINK32=link.exe | ||
| 81 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept | ||
| 82 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /out:"Debug/Uninstall.exe" /pdbtype:sept | ||
| 83 | |||
| 84 | !ENDIF | ||
| 85 | |||
| 86 | # Begin Target | ||
| 87 | |||
| 88 | # Name "7zipUninstall - Win32 Release" | ||
| 89 | # Name "7zipUninstall - Win32 Debug" | ||
| 90 | # Begin Group "Common" | ||
| 91 | |||
| 92 | # PROP Default_Filter "" | ||
| 93 | # Begin Source File | ||
| 94 | |||
| 95 | SOURCE=..\..\7zTypes.h | ||
| 96 | # End Source File | ||
| 97 | # Begin Source File | ||
| 98 | |||
| 99 | SOURCE=..\..\7zVersion.h | ||
| 100 | # End Source File | ||
| 101 | # End Group | ||
| 102 | # Begin Group "Spec" | ||
| 103 | |||
| 104 | # PROP Default_Filter "" | ||
| 105 | # Begin Source File | ||
| 106 | |||
| 107 | SOURCE=.\Precomp.c | ||
| 108 | # ADD CPP /Yc"Precomp.h" | ||
| 109 | # End Source File | ||
| 110 | # Begin Source File | ||
| 111 | |||
| 112 | SOURCE=.\Precomp.h | ||
| 113 | # End Source File | ||
| 114 | # End Group | ||
| 115 | # Begin Source File | ||
| 116 | |||
| 117 | SOURCE=.\7zipUninstall.c | ||
| 118 | # End Source File | ||
| 119 | # Begin Source File | ||
| 120 | |||
| 121 | SOURCE=.\resource.rc | ||
| 122 | # End Source File | ||
| 123 | # End Target | ||
| 124 | # End Project | ||
diff --git a/C/Util/7zipUninstall/7zipUninstall.dsw b/C/Util/7zipUninstall/7zipUninstall.dsw new file mode 100644 index 0000000..2873eda --- /dev/null +++ b/C/Util/7zipUninstall/7zipUninstall.dsw | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 | ||
| 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! | ||
| 3 | |||
| 4 | ############################################################################### | ||
| 5 | |||
| 6 | Project: "7zipUninstall"=.\7zipUninstall.dsp - Package Owner=<4> | ||
| 7 | |||
| 8 | Package=<5> | ||
| 9 | {{{ | ||
| 10 | }}} | ||
| 11 | |||
| 12 | Package=<4> | ||
| 13 | {{{ | ||
| 14 | }}} | ||
| 15 | |||
| 16 | ############################################################################### | ||
| 17 | |||
| 18 | Global: | ||
| 19 | |||
| 20 | Package=<5> | ||
| 21 | {{{ | ||
| 22 | }}} | ||
| 23 | |||
| 24 | Package=<3> | ||
| 25 | {{{ | ||
| 26 | }}} | ||
| 27 | |||
| 28 | ############################################################################### | ||
| 29 | |||
diff --git a/C/Util/7zipUninstall/7zipUninstall.ico b/C/Util/7zipUninstall/7zipUninstall.ico new file mode 100644 index 0000000..19eb20c --- /dev/null +++ b/C/Util/7zipUninstall/7zipUninstall.ico | |||
| Binary files differ | |||
diff --git a/C/Util/7zipUninstall/7zipUninstall.manifest b/C/Util/7zipUninstall/7zipUninstall.manifest new file mode 100644 index 0000000..a601443 --- /dev/null +++ b/C/Util/7zipUninstall/7zipUninstall.manifest | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| 2 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"> | ||
| 3 | <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="7-Zip.7-Zip.Uninstall" type="win32"/> | ||
| 4 | <description>7-Zip Uninstaller</description> | ||
| 5 | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges> | ||
| 6 | <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> | ||
| 7 | </requestedPrivileges></security></trustInfo> | ||
| 8 | <dependency><dependentAssembly><assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/></dependentAssembly></dependency> | ||
| 9 | <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application> | ||
| 10 | <!-- Vista --> <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> | ||
| 11 | <!-- Win 7 --> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> | ||
| 12 | <!-- Win 8 --> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> | ||
| 13 | <!-- Win 8.1 --> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> | ||
| 14 | <!-- Win 10 --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> | ||
| 15 | </application></compatibility> | ||
| 16 | <asmv3:application><asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"> | ||
| 17 | <dpiAware>true</dpiAware></asmv3:windowsSettings></asmv3:application> | ||
| 18 | </assembly> | ||
diff --git a/C/Util/7zipUninstall/Precomp.c b/C/Util/7zipUninstall/Precomp.c new file mode 100644 index 0000000..01605e3 --- /dev/null +++ b/C/Util/7zipUninstall/Precomp.c | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | /* Precomp.c -- StdAfx | ||
| 2 | 2013-01-21 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
diff --git a/C/Util/7zipUninstall/Precomp.h b/C/Util/7zipUninstall/Precomp.h new file mode 100644 index 0000000..4c90d47 --- /dev/null +++ b/C/Util/7zipUninstall/Precomp.h | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | /* Precomp.h -- StdAfx | ||
| 2 | 2015-05-24 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #ifndef __7Z_PRECOMP_H | ||
| 5 | #define __7Z_PRECOMP_H | ||
| 6 | |||
| 7 | #include "../../Compiler.h" | ||
| 8 | |||
| 9 | #include "../../7zTypes.h" | ||
| 10 | |||
| 11 | #endif | ||
diff --git a/C/Util/7zipUninstall/makefile b/C/Util/7zipUninstall/makefile new file mode 100644 index 0000000..60c2fe2 --- /dev/null +++ b/C/Util/7zipUninstall/makefile | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | PROG = 7zipUninstall.exe | ||
| 2 | MY_FIXED = 1 | ||
| 3 | |||
| 4 | !IFDEF _64BIT_INSTALLER | ||
| 5 | CFLAGS = $(CFLAGS) -D_64BIT_INSTALLER | ||
| 6 | !ENDIF | ||
| 7 | |||
| 8 | MAIN_OBJS = \ | ||
| 9 | $O\7zipUninstall.obj \ | ||
| 10 | |||
| 11 | OBJS = \ | ||
| 12 | $(MAIN_OBJS) \ | ||
| 13 | $O\resource.res | ||
| 14 | |||
| 15 | !include "../../../CPP/Build.mak" | ||
| 16 | |||
| 17 | $(MAIN_OBJS): $(*B).c | ||
| 18 | $(COMPL_O1) | ||
diff --git a/C/Util/7zipUninstall/resource.h b/C/Util/7zipUninstall/resource.h new file mode 100644 index 0000000..b5c33ff --- /dev/null +++ b/C/Util/7zipUninstall/resource.h | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #define IDD_INSTALL 100 | ||
| 2 | |||
| 3 | #define IDT_EXTRACT_EXTRACT_TO 110 | ||
| 4 | #define IDE_EXTRACT_PATH 111 | ||
| 5 | |||
| 6 | #define IDT_CUR_FILE 113 | ||
| 7 | #define IDC_PROGRESS 114 | ||
| 8 | |||
| 9 | #define IDI_ICON 1 | ||
diff --git a/C/Util/7zipUninstall/resource.rc b/C/Util/7zipUninstall/resource.rc new file mode 100644 index 0000000..00bdcc0 --- /dev/null +++ b/C/Util/7zipUninstall/resource.rc | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #include <winnt.h> | ||
| 2 | #include <WinUser.h> | ||
| 3 | #include <CommCtrl.h> | ||
| 4 | |||
| 5 | #define USE_COPYRIGHT_CR | ||
| 6 | #include "../../7zVersion.rc" | ||
| 7 | #include "resource.h" | ||
| 8 | |||
| 9 | MY_VERSION_INFO(MY_VFT_APP, "7-Zip Uninstaller", "Uninstall", "Uninstall.exe") | ||
| 10 | |||
| 11 | 1 ICON "7zipUninstall.ico" | ||
| 12 | |||
| 13 | #define xc 184 | ||
| 14 | #define yc 96 | ||
| 15 | |||
| 16 | #define m 8 | ||
| 17 | #define bxs 64 | ||
| 18 | #define bys 16 | ||
| 19 | |||
| 20 | |||
| 21 | #define xs (xc + m + m) | ||
| 22 | #define ys (yc + m + m) | ||
| 23 | |||
| 24 | #define bx1 (xs - m - bxs) | ||
| 25 | #define bx2 (bx1 - m - bxs) | ||
| 26 | |||
| 27 | #define by (ys - m - bys) | ||
| 28 | |||
| 29 | IDD_INSTALL DIALOG 0, 0, xs, ys | ||
| 30 | STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | ||
| 31 | CAPTION "Uninstall 7-Zip" | ||
| 32 | FONT 8, "MS Shell Dlg" | ||
| 33 | BEGIN | ||
| 34 | LTEXT "Uninstall from:", IDT_EXTRACT_EXTRACT_TO, m, m, xc, 8 | ||
| 35 | EDITTEXT IDE_EXTRACT_PATH, m, 21, xc, 14, ES_AUTOHSCROLL | WS_DISABLED | ||
| 36 | |||
| 37 | |||
| 38 | LTEXT "", IDT_CUR_FILE, m, 50, xc, 8 | ||
| 39 | CONTROL "", IDC_PROGRESS, "msctls_progress32", WS_BORDER, m, 64, xc, 10 | ||
| 40 | |||
| 41 | DEFPUSHBUTTON "&Uninstall", IDOK, bx2, by, bxs, bys, WS_GROUP | ||
| 42 | PUSHBUTTON "Cancel", IDCANCEL, bx1, by, bxs, bys | ||
| 43 | END | ||
| 44 | |||
| 45 | #ifndef UNDER_CE | ||
| 46 | 1 24 MOVEABLE PURE "7zipUninstall.manifest" | ||
| 47 | #endif | ||
diff --git a/C/Util/Lzma/LzmaUtil.c b/C/Util/Lzma/LzmaUtil.c new file mode 100644 index 0000000..62a5907 --- /dev/null +++ b/C/Util/Lzma/LzmaUtil.c | |||
| @@ -0,0 +1,286 @@ | |||
| 1 | /* LzmaUtil.c -- Test application for LZMA compression | ||
| 2 | 2021-11-01 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "../../Precomp.h" | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <string.h> | ||
| 9 | |||
| 10 | #include "../../CpuArch.h" | ||
| 11 | |||
| 12 | #include "../../Alloc.h" | ||
| 13 | #include "../../7zFile.h" | ||
| 14 | #include "../../7zVersion.h" | ||
| 15 | #include "../../LzFind.h" | ||
| 16 | #include "../../LzmaDec.h" | ||
| 17 | #include "../../LzmaEnc.h" | ||
| 18 | |||
| 19 | static const char * const kCantReadMessage = "Cannot read input file"; | ||
| 20 | static const char * const kCantWriteMessage = "Cannot write output file"; | ||
| 21 | static const char * const kCantAllocateMessage = "Cannot allocate memory"; | ||
| 22 | static const char * const kDataErrorMessage = "Data error"; | ||
| 23 | |||
| 24 | static void PrintHelp(char *buffer) | ||
| 25 | { | ||
| 26 | strcat(buffer, | ||
| 27 | "\nLZMA-C " MY_VERSION_CPU " : " MY_COPYRIGHT_DATE "\n\n" | ||
| 28 | "Usage: lzma <e|d> inputFile outputFile\n" | ||
| 29 | " e: encode file\n" | ||
| 30 | " d: decode file\n"); | ||
| 31 | } | ||
| 32 | |||
| 33 | static int PrintError(char *buffer, const char *message) | ||
| 34 | { | ||
| 35 | strcat(buffer, "\nError: "); | ||
| 36 | strcat(buffer, message); | ||
| 37 | strcat(buffer, "\n"); | ||
| 38 | return 1; | ||
| 39 | } | ||
| 40 | |||
| 41 | static int PrintError_WRes(char *buffer, const char *message, WRes wres) | ||
| 42 | { | ||
| 43 | strcat(buffer, "\nError: "); | ||
| 44 | strcat(buffer, message); | ||
| 45 | sprintf(buffer + strlen(buffer), "\nSystem error code: %d", (unsigned)wres); | ||
| 46 | #ifndef _WIN32 | ||
| 47 | { | ||
| 48 | const char *s = strerror(wres); | ||
| 49 | if (s) | ||
| 50 | sprintf(buffer + strlen(buffer), " : %s", s); | ||
| 51 | } | ||
| 52 | #endif | ||
| 53 | strcat(buffer, "\n"); | ||
| 54 | return 1; | ||
| 55 | } | ||
| 56 | |||
| 57 | static int PrintErrorNumber(char *buffer, SRes val) | ||
| 58 | { | ||
| 59 | sprintf(buffer + strlen(buffer), "\n7-Zip error code: %d\n", (unsigned)val); | ||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | |||
| 63 | static int PrintUserError(char *buffer) | ||
| 64 | { | ||
| 65 | return PrintError(buffer, "Incorrect command"); | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | #define IN_BUF_SIZE (1 << 16) | ||
| 70 | #define OUT_BUF_SIZE (1 << 16) | ||
| 71 | |||
| 72 | |||
| 73 | static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream, | ||
| 74 | UInt64 unpackSize) | ||
| 75 | { | ||
| 76 | int thereIsSize = (unpackSize != (UInt64)(Int64)-1); | ||
| 77 | Byte inBuf[IN_BUF_SIZE]; | ||
| 78 | Byte outBuf[OUT_BUF_SIZE]; | ||
| 79 | size_t inPos = 0, inSize = 0, outPos = 0; | ||
| 80 | LzmaDec_Init(state); | ||
| 81 | for (;;) | ||
| 82 | { | ||
| 83 | if (inPos == inSize) | ||
| 84 | { | ||
| 85 | inSize = IN_BUF_SIZE; | ||
| 86 | RINOK(inStream->Read(inStream, inBuf, &inSize)); | ||
| 87 | inPos = 0; | ||
| 88 | } | ||
| 89 | { | ||
| 90 | SRes res; | ||
| 91 | SizeT inProcessed = inSize - inPos; | ||
| 92 | SizeT outProcessed = OUT_BUF_SIZE - outPos; | ||
| 93 | ELzmaFinishMode finishMode = LZMA_FINISH_ANY; | ||
| 94 | ELzmaStatus status; | ||
| 95 | if (thereIsSize && outProcessed > unpackSize) | ||
| 96 | { | ||
| 97 | outProcessed = (SizeT)unpackSize; | ||
| 98 | finishMode = LZMA_FINISH_END; | ||
| 99 | } | ||
| 100 | |||
| 101 | res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed, | ||
| 102 | inBuf + inPos, &inProcessed, finishMode, &status); | ||
| 103 | inPos += inProcessed; | ||
| 104 | outPos += outProcessed; | ||
| 105 | unpackSize -= outProcessed; | ||
| 106 | |||
| 107 | if (outStream) | ||
| 108 | if (outStream->Write(outStream, outBuf, outPos) != outPos) | ||
| 109 | return SZ_ERROR_WRITE; | ||
| 110 | |||
| 111 | outPos = 0; | ||
| 112 | |||
| 113 | if (res != SZ_OK || (thereIsSize && unpackSize == 0)) | ||
| 114 | return res; | ||
| 115 | |||
| 116 | if (inProcessed == 0 && outProcessed == 0) | ||
| 117 | { | ||
| 118 | if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK) | ||
| 119 | return SZ_ERROR_DATA; | ||
| 120 | return res; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream) | ||
| 128 | { | ||
| 129 | UInt64 unpackSize; | ||
| 130 | int i; | ||
| 131 | SRes res = 0; | ||
| 132 | |||
| 133 | CLzmaDec state; | ||
| 134 | |||
| 135 | /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */ | ||
| 136 | unsigned char header[LZMA_PROPS_SIZE + 8]; | ||
| 137 | |||
| 138 | /* Read and parse header */ | ||
| 139 | |||
| 140 | RINOK(SeqInStream_Read(inStream, header, sizeof(header))); | ||
| 141 | |||
| 142 | unpackSize = 0; | ||
| 143 | for (i = 0; i < 8; i++) | ||
| 144 | unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8); | ||
| 145 | |||
| 146 | LzmaDec_Construct(&state); | ||
| 147 | RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc)); | ||
| 148 | res = Decode2(&state, outStream, inStream, unpackSize); | ||
| 149 | LzmaDec_Free(&state, &g_Alloc); | ||
| 150 | return res; | ||
| 151 | } | ||
| 152 | |||
| 153 | static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs) | ||
| 154 | { | ||
| 155 | CLzmaEncHandle enc; | ||
| 156 | SRes res; | ||
| 157 | CLzmaEncProps props; | ||
| 158 | |||
| 159 | UNUSED_VAR(rs); | ||
| 160 | |||
| 161 | enc = LzmaEnc_Create(&g_Alloc); | ||
| 162 | if (enc == 0) | ||
| 163 | return SZ_ERROR_MEM; | ||
| 164 | |||
| 165 | LzmaEncProps_Init(&props); | ||
| 166 | res = LzmaEnc_SetProps(enc, &props); | ||
| 167 | |||
| 168 | if (res == SZ_OK) | ||
| 169 | { | ||
| 170 | Byte header[LZMA_PROPS_SIZE + 8]; | ||
| 171 | size_t headerSize = LZMA_PROPS_SIZE; | ||
| 172 | int i; | ||
| 173 | |||
| 174 | res = LzmaEnc_WriteProperties(enc, header, &headerSize); | ||
| 175 | for (i = 0; i < 8; i++) | ||
| 176 | header[headerSize++] = (Byte)(fileSize >> (8 * i)); | ||
| 177 | if (outStream->Write(outStream, header, headerSize) != headerSize) | ||
| 178 | res = SZ_ERROR_WRITE; | ||
| 179 | else | ||
| 180 | { | ||
| 181 | if (res == SZ_OK) | ||
| 182 | res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc); | ||
| 186 | return res; | ||
| 187 | } | ||
| 188 | |||
| 189 | |||
| 190 | static int main2(int numArgs, const char *args[], char *rs) | ||
| 191 | { | ||
| 192 | CFileSeqInStream inStream; | ||
| 193 | CFileOutStream outStream; | ||
| 194 | char c; | ||
| 195 | int res; | ||
| 196 | int encodeMode; | ||
| 197 | BoolInt useOutFile = False; | ||
| 198 | |||
| 199 | LzFindPrepare(); | ||
| 200 | |||
| 201 | FileSeqInStream_CreateVTable(&inStream); | ||
| 202 | File_Construct(&inStream.file); | ||
| 203 | inStream.wres = 0; | ||
| 204 | |||
| 205 | FileOutStream_CreateVTable(&outStream); | ||
| 206 | File_Construct(&outStream.file); | ||
| 207 | outStream.wres = 0; | ||
| 208 | |||
| 209 | if (numArgs == 1) | ||
| 210 | { | ||
| 211 | PrintHelp(rs); | ||
| 212 | return 0; | ||
| 213 | } | ||
| 214 | |||
| 215 | if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1) | ||
| 216 | return PrintUserError(rs); | ||
| 217 | |||
| 218 | c = args[1][0]; | ||
| 219 | encodeMode = (c == 'e' || c == 'E'); | ||
| 220 | if (!encodeMode && c != 'd' && c != 'D') | ||
| 221 | return PrintUserError(rs); | ||
| 222 | |||
| 223 | { | ||
| 224 | size_t t4 = sizeof(UInt32); | ||
| 225 | size_t t8 = sizeof(UInt64); | ||
| 226 | if (t4 != 4 || t8 != 8) | ||
| 227 | return PrintError(rs, "Incorrect UInt32 or UInt64"); | ||
| 228 | } | ||
| 229 | |||
| 230 | { | ||
| 231 | WRes wres = InFile_Open(&inStream.file, args[2]); | ||
| 232 | if (wres != 0) | ||
| 233 | return PrintError_WRes(rs, "Cannot open input file", wres); | ||
| 234 | } | ||
| 235 | |||
| 236 | if (numArgs > 3) | ||
| 237 | { | ||
| 238 | WRes wres; | ||
| 239 | useOutFile = True; | ||
| 240 | wres = OutFile_Open(&outStream.file, args[3]); | ||
| 241 | if (wres != 0) | ||
| 242 | return PrintError_WRes(rs, "Cannot open output file", wres); | ||
| 243 | } | ||
| 244 | else if (encodeMode) | ||
| 245 | PrintUserError(rs); | ||
| 246 | |||
| 247 | if (encodeMode) | ||
| 248 | { | ||
| 249 | UInt64 fileSize; | ||
| 250 | WRes wres = File_GetLength(&inStream.file, &fileSize); | ||
| 251 | if (wres != 0) | ||
| 252 | return PrintError_WRes(rs, "Cannot get file length", wres); | ||
| 253 | res = Encode(&outStream.vt, &inStream.vt, fileSize, rs); | ||
| 254 | } | ||
| 255 | else | ||
| 256 | { | ||
| 257 | res = Decode(&outStream.vt, useOutFile ? &inStream.vt : NULL); | ||
| 258 | } | ||
| 259 | |||
| 260 | if (useOutFile) | ||
| 261 | File_Close(&outStream.file); | ||
| 262 | File_Close(&inStream.file); | ||
| 263 | |||
| 264 | if (res != SZ_OK) | ||
| 265 | { | ||
| 266 | if (res == SZ_ERROR_MEM) | ||
| 267 | return PrintError(rs, kCantAllocateMessage); | ||
| 268 | else if (res == SZ_ERROR_DATA) | ||
| 269 | return PrintError(rs, kDataErrorMessage); | ||
| 270 | else if (res == SZ_ERROR_WRITE) | ||
| 271 | return PrintError_WRes(rs, kCantWriteMessage, outStream.wres); | ||
| 272 | else if (res == SZ_ERROR_READ) | ||
| 273 | return PrintError_WRes(rs, kCantReadMessage, inStream.wres); | ||
| 274 | return PrintErrorNumber(rs, res); | ||
| 275 | } | ||
| 276 | return 0; | ||
| 277 | } | ||
| 278 | |||
| 279 | |||
| 280 | int MY_CDECL main(int numArgs, const char *args[]) | ||
| 281 | { | ||
| 282 | char rs[1000] = { 0 }; | ||
| 283 | int res = main2(numArgs, args, rs); | ||
| 284 | fputs(rs, stdout); | ||
| 285 | return res; | ||
| 286 | } | ||
diff --git a/C/Util/Lzma/LzmaUtil.dsp b/C/Util/Lzma/LzmaUtil.dsp new file mode 100644 index 0000000..4e38e4a --- /dev/null +++ b/C/Util/Lzma/LzmaUtil.dsp | |||
| @@ -0,0 +1,172 @@ | |||
| 1 | # Microsoft Developer Studio Project File - Name="LzmaUtil" - Package Owner=<4> | ||
| 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 | ||
| 3 | # ** DO NOT EDIT ** | ||
| 4 | |||
| 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 | ||
| 6 | |||
| 7 | CFG=LzmaUtil - Win32 Debug | ||
| 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, | ||
| 9 | !MESSAGE use the Export Makefile command and run | ||
| 10 | !MESSAGE | ||
| 11 | !MESSAGE NMAKE /f "LzmaUtil.mak". | ||
| 12 | !MESSAGE | ||
| 13 | !MESSAGE You can specify a configuration when running NMAKE | ||
| 14 | !MESSAGE by defining the macro CFG on the command line. For example: | ||
| 15 | !MESSAGE | ||
| 16 | !MESSAGE NMAKE /f "LzmaUtil.mak" CFG="LzmaUtil - Win32 Debug" | ||
| 17 | !MESSAGE | ||
| 18 | !MESSAGE Possible choices for configuration are: | ||
| 19 | !MESSAGE | ||
| 20 | !MESSAGE "LzmaUtil - Win32 Release" (based on "Win32 (x86) Console Application") | ||
| 21 | !MESSAGE "LzmaUtil - Win32 Debug" (based on "Win32 (x86) Console Application") | ||
| 22 | !MESSAGE | ||
| 23 | |||
| 24 | # Begin Project | ||
| 25 | # PROP AllowPerConfigDependencies 0 | ||
| 26 | # PROP Scc_ProjName "" | ||
| 27 | # PROP Scc_LocalPath "" | ||
| 28 | CPP=cl.exe | ||
| 29 | RSC=rc.exe | ||
| 30 | |||
| 31 | !IF "$(CFG)" == "LzmaUtil - Win32 Release" | ||
| 32 | |||
| 33 | # PROP BASE Use_MFC 0 | ||
| 34 | # PROP BASE Use_Debug_Libraries 0 | ||
| 35 | # PROP BASE Output_Dir "Release" | ||
| 36 | # PROP BASE Intermediate_Dir "Release" | ||
| 37 | # PROP BASE Target_Dir "" | ||
| 38 | # PROP Use_MFC 0 | ||
| 39 | # PROP Use_Debug_Libraries 0 | ||
| 40 | # PROP Output_Dir "Release" | ||
| 41 | # PROP Intermediate_Dir "Release" | ||
| 42 | # PROP Ignore_Export_Lib 0 | ||
| 43 | # PROP Target_Dir "" | ||
| 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c | ||
| 45 | # ADD CPP /nologo /MT /W4 /WX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c | ||
| 46 | # SUBTRACT CPP /YX | ||
| 47 | # ADD BASE RSC /l 0x419 /d "NDEBUG" | ||
| 48 | # ADD RSC /l 0x419 /d "NDEBUG" | ||
| 49 | BSC32=bscmake.exe | ||
| 50 | # ADD BASE BSC32 /nologo | ||
| 51 | # ADD BSC32 /nologo | ||
| 52 | LINK32=link.exe | ||
| 53 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 | ||
| 54 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\util\7lzma.exe" | ||
| 55 | |||
| 56 | !ELSEIF "$(CFG)" == "LzmaUtil - Win32 Debug" | ||
| 57 | |||
| 58 | # PROP BASE Use_MFC 0 | ||
| 59 | # PROP BASE Use_Debug_Libraries 1 | ||
| 60 | # PROP BASE Output_Dir "Debug" | ||
| 61 | # PROP BASE Intermediate_Dir "Debug" | ||
| 62 | # PROP BASE Target_Dir "" | ||
| 63 | # PROP Use_MFC 0 | ||
| 64 | # PROP Use_Debug_Libraries 1 | ||
| 65 | # PROP Output_Dir "Debug" | ||
| 66 | # PROP Intermediate_Dir "Debug" | ||
| 67 | # PROP Ignore_Export_Lib 0 | ||
| 68 | # PROP Target_Dir "" | ||
| 69 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c | ||
| 70 | # ADD CPP /nologo /MTd /W4 /WX /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c | ||
| 71 | # SUBTRACT CPP /YX | ||
| 72 | # ADD BASE RSC /l 0x419 /d "_DEBUG" | ||
| 73 | # ADD RSC /l 0x419 /d "_DEBUG" | ||
| 74 | BSC32=bscmake.exe | ||
| 75 | # ADD BASE BSC32 /nologo | ||
| 76 | # ADD BSC32 /nologo | ||
| 77 | LINK32=link.exe | ||
| 78 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept | ||
| 79 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\util\7lzma.exe" /pdbtype:sept | ||
| 80 | |||
| 81 | !ENDIF | ||
| 82 | |||
| 83 | # Begin Target | ||
| 84 | |||
| 85 | # Name "LzmaUtil - Win32 Release" | ||
| 86 | # Name "LzmaUtil - Win32 Debug" | ||
| 87 | # Begin Source File | ||
| 88 | |||
| 89 | SOURCE=..\..\7zFile.c | ||
| 90 | # End Source File | ||
| 91 | # Begin Source File | ||
| 92 | |||
| 93 | SOURCE=..\..\7zFile.h | ||
| 94 | # End Source File | ||
| 95 | # Begin Source File | ||
| 96 | |||
| 97 | SOURCE=..\..\7zStream.c | ||
| 98 | # End Source File | ||
| 99 | # Begin Source File | ||
| 100 | |||
| 101 | SOURCE=..\..\7zTypes.h | ||
| 102 | # End Source File | ||
| 103 | # Begin Source File | ||
| 104 | |||
| 105 | SOURCE=..\..\7zVersion.h | ||
| 106 | # End Source File | ||
| 107 | # Begin Source File | ||
| 108 | |||
| 109 | SOURCE=..\..\Alloc.c | ||
| 110 | # End Source File | ||
| 111 | # Begin Source File | ||
| 112 | |||
| 113 | SOURCE=..\..\Alloc.h | ||
| 114 | # End Source File | ||
| 115 | # Begin Source File | ||
| 116 | |||
| 117 | SOURCE=..\..\CpuArch.h | ||
| 118 | # End Source File | ||
| 119 | # Begin Source File | ||
| 120 | |||
| 121 | SOURCE=..\..\LzFind.c | ||
| 122 | # End Source File | ||
| 123 | # Begin Source File | ||
| 124 | |||
| 125 | SOURCE=..\..\LzFind.h | ||
| 126 | # End Source File | ||
| 127 | # Begin Source File | ||
| 128 | |||
| 129 | SOURCE=..\..\LzFindMt.c | ||
| 130 | # End Source File | ||
| 131 | # Begin Source File | ||
| 132 | |||
| 133 | SOURCE=..\..\LzFindMt.h | ||
| 134 | # End Source File | ||
| 135 | # Begin Source File | ||
| 136 | |||
| 137 | SOURCE=..\..\LzFindOpt.c | ||
| 138 | # End Source File | ||
| 139 | # Begin Source File | ||
| 140 | |||
| 141 | SOURCE=..\..\LzHash.h | ||
| 142 | # End Source File | ||
| 143 | # Begin Source File | ||
| 144 | |||
| 145 | SOURCE=..\..\LzmaDec.c | ||
| 146 | # End Source File | ||
| 147 | # Begin Source File | ||
| 148 | |||
| 149 | SOURCE=..\..\LzmaDec.h | ||
| 150 | # End Source File | ||
| 151 | # Begin Source File | ||
| 152 | |||
| 153 | SOURCE=..\..\LzmaEnc.c | ||
| 154 | # End Source File | ||
| 155 | # Begin Source File | ||
| 156 | |||
| 157 | SOURCE=..\..\LzmaEnc.h | ||
| 158 | # End Source File | ||
| 159 | # Begin Source File | ||
| 160 | |||
| 161 | SOURCE=.\LzmaUtil.c | ||
| 162 | # End Source File | ||
| 163 | # Begin Source File | ||
| 164 | |||
| 165 | SOURCE=..\..\Threads.c | ||
| 166 | # End Source File | ||
| 167 | # Begin Source File | ||
| 168 | |||
| 169 | SOURCE=..\..\Threads.h | ||
| 170 | # End Source File | ||
| 171 | # End Target | ||
| 172 | # End Project | ||
diff --git a/C/Util/Lzma/LzmaUtil.dsw b/C/Util/Lzma/LzmaUtil.dsw new file mode 100644 index 0000000..c52eaf6 --- /dev/null +++ b/C/Util/Lzma/LzmaUtil.dsw | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 | ||
| 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! | ||
| 3 | |||
| 4 | ############################################################################### | ||
| 5 | |||
| 6 | Project: "LzmaUtil"=.\LzmaUtil.dsp - Package Owner=<4> | ||
| 7 | |||
| 8 | Package=<5> | ||
| 9 | {{{ | ||
| 10 | }}} | ||
| 11 | |||
| 12 | Package=<4> | ||
| 13 | {{{ | ||
| 14 | }}} | ||
| 15 | |||
| 16 | ############################################################################### | ||
| 17 | |||
| 18 | Global: | ||
| 19 | |||
| 20 | Package=<5> | ||
| 21 | {{{ | ||
| 22 | }}} | ||
| 23 | |||
| 24 | Package=<3> | ||
| 25 | {{{ | ||
| 26 | }}} | ||
| 27 | |||
| 28 | ############################################################################### | ||
| 29 | |||
diff --git a/C/Util/Lzma/makefile b/C/Util/Lzma/makefile new file mode 100644 index 0000000..7813bdb --- /dev/null +++ b/C/Util/Lzma/makefile | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | # MY_STATIC_LINK=1 | ||
| 2 | PROG = LZMAc.exe | ||
| 3 | |||
| 4 | CFLAGS = $(CFLAGS) \ | ||
| 5 | |||
| 6 | LIB_OBJS = \ | ||
| 7 | $O\LzmaUtil.obj \ | ||
| 8 | |||
| 9 | C_OBJS = \ | ||
| 10 | $O\Alloc.obj \ | ||
| 11 | $O\CpuArch.obj \ | ||
| 12 | $O\LzFind.obj \ | ||
| 13 | $O\LzFindMt.obj \ | ||
| 14 | $O\LzFindOpt.obj \ | ||
| 15 | $O\LzmaDec.obj \ | ||
| 16 | $O\LzmaEnc.obj \ | ||
| 17 | $O\7zFile.obj \ | ||
| 18 | $O\7zStream.obj \ | ||
| 19 | $O\Threads.obj \ | ||
| 20 | |||
| 21 | OBJS = \ | ||
| 22 | $(LIB_OBJS) \ | ||
| 23 | $(C_OBJS) \ | ||
| 24 | |||
| 25 | !include "../../../CPP/Build.mak" | ||
| 26 | |||
| 27 | $(LIB_OBJS): $(*B).c | ||
| 28 | $(COMPL_O2) | ||
| 29 | $(C_OBJS): ../../$(*B).c | ||
| 30 | $(COMPL_O2) | ||
diff --git a/C/Util/Lzma/makefile.gcc b/C/Util/Lzma/makefile.gcc new file mode 100644 index 0000000..2acb0b8 --- /dev/null +++ b/C/Util/Lzma/makefile.gcc | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | PROG = 7lzma | ||
| 2 | |||
| 3 | include ../../../CPP/7zip/LzmaDec_gcc.mak | ||
| 4 | |||
| 5 | |||
| 6 | OBJS = \ | ||
| 7 | $(LZMA_DEC_OPT_OBJS) \ | ||
| 8 | $O/7zFile.o \ | ||
| 9 | $O/7zStream.o \ | ||
| 10 | $O/Alloc.o \ | ||
| 11 | $O/CpuArch.o \ | ||
| 12 | $O/LzFind.o \ | ||
| 13 | $O/LzFindMt.o \ | ||
| 14 | $O/LzFindOpt.o \ | ||
| 15 | $O/LzmaDec.o \ | ||
| 16 | $O/LzmaEnc.o \ | ||
| 17 | $O/LzmaUtil.o \ | ||
| 18 | $O/Threads.o \ | ||
| 19 | |||
| 20 | |||
| 21 | include ../../7zip_gcc_c.mak | ||
diff --git a/C/Util/LzmaLib/LzmaLib.def b/C/Util/LzmaLib/LzmaLib.def new file mode 100644 index 0000000..8bc6add --- /dev/null +++ b/C/Util/LzmaLib/LzmaLib.def | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | EXPORTS | ||
| 2 | LzmaCompress | ||
| 3 | LzmaUncompress | ||
| 4 | |||
diff --git a/C/Util/LzmaLib/LzmaLib.dsp b/C/Util/LzmaLib/LzmaLib.dsp new file mode 100644 index 0000000..6ce91dc --- /dev/null +++ b/C/Util/LzmaLib/LzmaLib.dsp | |||
| @@ -0,0 +1,182 @@ | |||
| 1 | # Microsoft Developer Studio Project File - Name="LzmaLib" - Package Owner=<4> | ||
| 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 | ||
| 3 | # ** DO NOT EDIT ** | ||
| 4 | |||
| 5 | # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 | ||
| 6 | |||
| 7 | CFG=LzmaLib - Win32 Debug | ||
| 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, | ||
| 9 | !MESSAGE use the Export Makefile command and run | ||
| 10 | !MESSAGE | ||
| 11 | !MESSAGE NMAKE /f "LzmaLib.mak". | ||
| 12 | !MESSAGE | ||
| 13 | !MESSAGE You can specify a configuration when running NMAKE | ||
| 14 | !MESSAGE by defining the macro CFG on the command line. For example: | ||
| 15 | !MESSAGE | ||
| 16 | !MESSAGE NMAKE /f "LzmaLib.mak" CFG="LzmaLib - Win32 Debug" | ||
| 17 | !MESSAGE | ||
| 18 | !MESSAGE Possible choices for configuration are: | ||
| 19 | !MESSAGE | ||
| 20 | !MESSAGE "LzmaLib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") | ||
| 21 | !MESSAGE "LzmaLib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") | ||
| 22 | !MESSAGE | ||
| 23 | |||
| 24 | # Begin Project | ||
| 25 | # PROP AllowPerConfigDependencies 0 | ||
| 26 | # PROP Scc_ProjName "" | ||
| 27 | # PROP Scc_LocalPath "" | ||
| 28 | CPP=cl.exe | ||
| 29 | MTL=midl.exe | ||
| 30 | RSC=rc.exe | ||
| 31 | |||
| 32 | !IF "$(CFG)" == "LzmaLib - Win32 Release" | ||
| 33 | |||
| 34 | # PROP BASE Use_MFC 0 | ||
| 35 | # PROP BASE Use_Debug_Libraries 0 | ||
| 36 | # PROP BASE Output_Dir "Release" | ||
| 37 | # PROP BASE Intermediate_Dir "Release" | ||
| 38 | # PROP BASE Target_Dir "" | ||
| 39 | # PROP Use_MFC 0 | ||
| 40 | # PROP Use_Debug_Libraries 0 | ||
| 41 | # PROP Output_Dir "Release" | ||
| 42 | # PROP Intermediate_Dir "Release" | ||
| 43 | # PROP Ignore_Export_Lib 0 | ||
| 44 | # PROP Target_Dir "" | ||
| 45 | # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /c | ||
| 46 | # ADD CPP /nologo /Gr /MT /W3 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /FD /c | ||
| 47 | # SUBTRACT CPP /YX | ||
| 48 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 49 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 50 | # ADD BASE RSC /l 0x419 /d "NDEBUG" | ||
| 51 | # ADD RSC /l 0x419 /d "NDEBUG" | ||
| 52 | BSC32=bscmake.exe | ||
| 53 | # ADD BASE BSC32 /nologo | ||
| 54 | # ADD BSC32 /nologo | ||
| 55 | LINK32=link.exe | ||
| 56 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 | ||
| 57 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Util\LZMA.dll" /opt:NOWIN98 | ||
| 58 | # SUBTRACT LINK32 /pdb:none | ||
| 59 | |||
| 60 | !ELSEIF "$(CFG)" == "LzmaLib - Win32 Debug" | ||
| 61 | |||
| 62 | # PROP BASE Use_MFC 0 | ||
| 63 | # PROP BASE Use_Debug_Libraries 1 | ||
| 64 | # PROP BASE Output_Dir "Debug" | ||
| 65 | # PROP BASE Intermediate_Dir "Debug" | ||
| 66 | # PROP BASE Target_Dir "" | ||
| 67 | # PROP Use_MFC 0 | ||
| 68 | # PROP Use_Debug_Libraries 1 | ||
| 69 | # PROP Output_Dir "Debug" | ||
| 70 | # PROP Intermediate_Dir "Debug" | ||
| 71 | # PROP Ignore_Export_Lib 0 | ||
| 72 | # PROP Target_Dir "" | ||
| 73 | # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /YX /FD /GZ /c | ||
| 74 | # ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMALIB_EXPORTS" /D "COMPRESS_MF_MT" /FD /GZ /c | ||
| 75 | # SUBTRACT CPP /YX | ||
| 76 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 77 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 78 | # ADD BASE RSC /l 0x419 /d "_DEBUG" | ||
| 79 | # ADD RSC /l 0x419 /d "_DEBUG" | ||
| 80 | BSC32=bscmake.exe | ||
| 81 | # ADD BASE BSC32 /nologo | ||
| 82 | # ADD BSC32 /nologo | ||
| 83 | LINK32=link.exe | ||
| 84 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept | ||
| 85 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Util\LZMA.dll" /pdbtype:sept | ||
| 86 | |||
| 87 | !ENDIF | ||
| 88 | |||
| 89 | # Begin Target | ||
| 90 | |||
| 91 | # Name "LzmaLib - Win32 Release" | ||
| 92 | # Name "LzmaLib - Win32 Debug" | ||
| 93 | # Begin Group "Spec" | ||
| 94 | |||
| 95 | # PROP Default_Filter "" | ||
| 96 | # Begin Source File | ||
| 97 | |||
| 98 | SOURCE=.\LzmaLib.def | ||
| 99 | # End Source File | ||
| 100 | # Begin Source File | ||
| 101 | |||
| 102 | SOURCE=.\LzmaLibExports.c | ||
| 103 | # End Source File | ||
| 104 | # End Group | ||
| 105 | # Begin Source File | ||
| 106 | |||
| 107 | SOURCE=..\..\7zTypes.h | ||
| 108 | # End Source File | ||
| 109 | # Begin Source File | ||
| 110 | |||
| 111 | SOURCE=..\..\Alloc.c | ||
| 112 | # End Source File | ||
| 113 | # Begin Source File | ||
| 114 | |||
| 115 | SOURCE=..\..\Alloc.h | ||
| 116 | # End Source File | ||
| 117 | # Begin Source File | ||
| 118 | |||
| 119 | SOURCE=..\..\IStream.h | ||
| 120 | # End Source File | ||
| 121 | # Begin Source File | ||
| 122 | |||
| 123 | SOURCE=..\..\LzFind.c | ||
| 124 | # End Source File | ||
| 125 | # Begin Source File | ||
| 126 | |||
| 127 | SOURCE=..\..\LzFind.h | ||
| 128 | # End Source File | ||
| 129 | # Begin Source File | ||
| 130 | |||
| 131 | SOURCE=..\..\LzFindMt.c | ||
| 132 | # End Source File | ||
| 133 | # Begin Source File | ||
| 134 | |||
| 135 | SOURCE=..\..\LzFindMt.h | ||
| 136 | # End Source File | ||
| 137 | # Begin Source File | ||
| 138 | |||
| 139 | SOURCE=..\..\LzFindOpt.c | ||
| 140 | # End Source File | ||
| 141 | # Begin Source File | ||
| 142 | |||
| 143 | SOURCE=..\..\LzHash.h | ||
| 144 | # End Source File | ||
| 145 | # Begin Source File | ||
| 146 | |||
| 147 | SOURCE=..\..\LzmaDec.c | ||
| 148 | # End Source File | ||
| 149 | # Begin Source File | ||
| 150 | |||
| 151 | SOURCE=..\..\LzmaDec.h | ||
| 152 | # End Source File | ||
| 153 | # Begin Source File | ||
| 154 | |||
| 155 | SOURCE=..\..\LzmaEnc.c | ||
| 156 | # End Source File | ||
| 157 | # Begin Source File | ||
| 158 | |||
| 159 | SOURCE=..\..\LzmaEnc.h | ||
| 160 | # End Source File | ||
| 161 | # Begin Source File | ||
| 162 | |||
| 163 | SOURCE=..\..\LzmaLib.c | ||
| 164 | # End Source File | ||
| 165 | # Begin Source File | ||
| 166 | |||
| 167 | SOURCE=..\..\LzmaLib.h | ||
| 168 | # End Source File | ||
| 169 | # Begin Source File | ||
| 170 | |||
| 171 | SOURCE=.\resource.rc | ||
| 172 | # End Source File | ||
| 173 | # Begin Source File | ||
| 174 | |||
| 175 | SOURCE=..\..\Threads.c | ||
| 176 | # End Source File | ||
| 177 | # Begin Source File | ||
| 178 | |||
| 179 | SOURCE=..\..\Threads.h | ||
| 180 | # End Source File | ||
| 181 | # End Target | ||
| 182 | # End Project | ||
diff --git a/C/Util/LzmaLib/LzmaLib.dsw b/C/Util/LzmaLib/LzmaLib.dsw new file mode 100644 index 0000000..6faf333 --- /dev/null +++ b/C/Util/LzmaLib/LzmaLib.dsw | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 | ||
| 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! | ||
| 3 | |||
| 4 | ############################################################################### | ||
| 5 | |||
| 6 | Project: "LzmaLib"=.\LzmaLib.dsp - Package Owner=<4> | ||
| 7 | |||
| 8 | Package=<5> | ||
| 9 | {{{ | ||
| 10 | }}} | ||
| 11 | |||
| 12 | Package=<4> | ||
| 13 | {{{ | ||
| 14 | }}} | ||
| 15 | |||
| 16 | ############################################################################### | ||
| 17 | |||
| 18 | Global: | ||
| 19 | |||
| 20 | Package=<5> | ||
| 21 | {{{ | ||
| 22 | }}} | ||
| 23 | |||
| 24 | Package=<3> | ||
| 25 | {{{ | ||
| 26 | }}} | ||
| 27 | |||
| 28 | ############################################################################### | ||
| 29 | |||
diff --git a/C/Util/LzmaLib/LzmaLibExports.c b/C/Util/LzmaLib/LzmaLibExports.c new file mode 100644 index 0000000..4a28a9a --- /dev/null +++ b/C/Util/LzmaLib/LzmaLibExports.c | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | /* LzmaLibExports.c -- LZMA library DLL Entry point | ||
| 2 | 2015-11-08 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "../../Precomp.h" | ||
| 5 | |||
| 6 | #include <windows.h> | ||
| 7 | |||
| 8 | BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) | ||
| 9 | { | ||
| 10 | UNUSED_VAR(hInstance); | ||
| 11 | UNUSED_VAR(dwReason); | ||
| 12 | UNUSED_VAR(lpReserved); | ||
| 13 | return TRUE; | ||
| 14 | } | ||
diff --git a/C/Util/LzmaLib/makefile b/C/Util/LzmaLib/makefile new file mode 100644 index 0000000..b36f1de --- /dev/null +++ b/C/Util/LzmaLib/makefile | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | MY_STATIC_LINK=1 | ||
| 2 | SLIB = sLZMA.lib | ||
| 3 | PROG = LZMA.dll | ||
| 4 | SLIBPATH = $O\$(SLIB) | ||
| 5 | |||
| 6 | DEF_FILE = LzmaLib.def | ||
| 7 | CFLAGS = $(CFLAGS) \ | ||
| 8 | |||
| 9 | LIB_OBJS = \ | ||
| 10 | $O\LzmaLibExports.obj \ | ||
| 11 | |||
| 12 | C_OBJS = \ | ||
| 13 | $O\Alloc.obj \ | ||
| 14 | $O\CpuArch.obj \ | ||
| 15 | $O\LzFind.obj \ | ||
| 16 | $O\LzFindMt.obj \ | ||
| 17 | $O\LzFindOpt.obj \ | ||
| 18 | $O\LzmaDec.obj \ | ||
| 19 | $O\LzmaEnc.obj \ | ||
| 20 | $O\LzmaLib.obj \ | ||
| 21 | $O\Threads.obj \ | ||
| 22 | |||
| 23 | OBJS = \ | ||
| 24 | $(LIB_OBJS) \ | ||
| 25 | $(C_OBJS) \ | ||
| 26 | $O\resource.res | ||
| 27 | |||
| 28 | !include "../../../CPP/Build.mak" | ||
| 29 | |||
| 30 | $(SLIBPATH): $O $(OBJS) | ||
| 31 | lib -out:$(SLIBPATH) $(OBJS) $(LIBS) | ||
| 32 | |||
| 33 | $(LIB_OBJS): $(*B).c | ||
| 34 | $(COMPL_O2) | ||
| 35 | $(C_OBJS): ../../$(*B).c | ||
| 36 | $(COMPL_O2) | ||
diff --git a/C/Util/LzmaLib/resource.rc b/C/Util/LzmaLib/resource.rc new file mode 100644 index 0000000..674832e --- /dev/null +++ b/C/Util/LzmaLib/resource.rc | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | #include "../../7zVersion.rc" | ||
| 2 | |||
| 3 | MY_VERSION_INFO_DLL("LZMA library", "LZMA") | ||
diff --git a/C/Util/SfxSetup/Precomp.c b/C/Util/SfxSetup/Precomp.c new file mode 100644 index 0000000..01605e3 --- /dev/null +++ b/C/Util/SfxSetup/Precomp.c | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | /* Precomp.c -- StdAfx | ||
| 2 | 2013-01-21 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
diff --git a/C/Util/SfxSetup/Precomp.h b/C/Util/SfxSetup/Precomp.h new file mode 100644 index 0000000..588a66f --- /dev/null +++ b/C/Util/SfxSetup/Precomp.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | /* Precomp.h -- StdAfx | ||
| 2 | 2013-06-16 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #ifndef __7Z_PRECOMP_H | ||
| 5 | #define __7Z_PRECOMP_H | ||
| 6 | |||
| 7 | #include "../../Compiler.h" | ||
| 8 | #include "../../7zTypes.h" | ||
| 9 | |||
| 10 | #endif | ||
diff --git a/C/Util/SfxSetup/SfxSetup.c b/C/Util/SfxSetup/SfxSetup.c new file mode 100644 index 0000000..ef19aea --- /dev/null +++ b/C/Util/SfxSetup/SfxSetup.c | |||
| @@ -0,0 +1,640 @@ | |||
| 1 | /* SfxSetup.c - 7z SFX Setup | ||
| 2 | 2019-02-02 : Igor Pavlov : Public domain */ | ||
| 3 | |||
| 4 | #include "Precomp.h" | ||
| 5 | |||
| 6 | #ifndef UNICODE | ||
| 7 | #define UNICODE | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #ifndef _UNICODE | ||
| 11 | #define _UNICODE | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #ifdef _CONSOLE | ||
| 15 | #include <stdio.h> | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #include "../../7z.h" | ||
| 19 | #include "../../7zAlloc.h" | ||
| 20 | #include "../../7zCrc.h" | ||
| 21 | #include "../../7zFile.h" | ||
| 22 | #include "../../CpuArch.h" | ||
| 23 | #include "../../DllSecur.h" | ||
| 24 | |||
| 25 | #define k_EXE_ExtIndex 2 | ||
| 26 | |||
| 27 | #define kInputBufSize ((size_t)1 << 18) | ||
| 28 | |||
| 29 | static const char * const kExts[] = | ||
| 30 | { | ||
| 31 | "bat" | ||
| 32 | , "cmd" | ||
| 33 | , "exe" | ||
| 34 | , "inf" | ||
| 35 | , "msi" | ||
| 36 | #ifdef UNDER_CE | ||
| 37 | , "cab" | ||
| 38 | #endif | ||
| 39 | , "html" | ||
| 40 | , "htm" | ||
| 41 | }; | ||
| 42 | |||
| 43 | static const char * const kNames[] = | ||
| 44 | { | ||
| 45 | "setup" | ||
| 46 | , "install" | ||
| 47 | , "run" | ||
| 48 | , "start" | ||
| 49 | }; | ||
| 50 | |||
| 51 | static unsigned FindExt(const wchar_t *s, unsigned *extLen) | ||
| 52 | { | ||
| 53 | unsigned len = (unsigned)wcslen(s); | ||
| 54 | unsigned i; | ||
| 55 | for (i = len; i > 0; i--) | ||
| 56 | { | ||
| 57 | if (s[i - 1] == '.') | ||
| 58 | { | ||
| 59 | *extLen = len - i; | ||
| 60 | return i - 1; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | *extLen = 0; | ||
| 64 | return len; | ||
| 65 | } | ||
| 66 | |||
| 67 | #define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c))) | ||
| 68 | |||
| 69 | static unsigned FindItem(const char * const *items, unsigned num, const wchar_t *s, unsigned len) | ||
| 70 | { | ||
| 71 | unsigned i; | ||
| 72 | for (i = 0; i < num; i++) | ||
| 73 | { | ||
| 74 | const char *item = items[i]; | ||
| 75 | unsigned itemLen = (unsigned)strlen(item); | ||
| 76 | unsigned j; | ||
| 77 | if (len != itemLen) | ||
| 78 | continue; | ||
| 79 | for (j = 0; j < len; j++) | ||
| 80 | { | ||
| 81 | unsigned c = (Byte)item[j]; | ||
| 82 | if (c != s[j] && MAKE_CHAR_UPPER(c) != s[j]) | ||
| 83 | break; | ||
| 84 | } | ||
| 85 | if (j == len) | ||
| 86 | return i; | ||
| 87 | } | ||
| 88 | return i; | ||
| 89 | } | ||
| 90 | |||
| 91 | #ifdef _CONSOLE | ||
| 92 | static BOOL WINAPI HandlerRoutine(DWORD ctrlType) | ||
| 93 | { | ||
| 94 | UNUSED_VAR(ctrlType); | ||
| 95 | return TRUE; | ||
| 96 | } | ||
| 97 | #endif | ||
| 98 | |||
| 99 | static void PrintErrorMessage(const char *message) | ||
| 100 | { | ||
| 101 | #ifdef _CONSOLE | ||
| 102 | printf("\n7-Zip Error: %s\n", message); | ||
| 103 | #else | ||
| 104 | #ifdef UNDER_CE | ||
| 105 | WCHAR messageW[256 + 4]; | ||
| 106 | unsigned i; | ||
| 107 | for (i = 0; i < 256 && message[i] != 0; i++) | ||
| 108 | messageW[i] = message[i]; | ||
| 109 | messageW[i] = 0; | ||
| 110 | MessageBoxW(0, messageW, L"7-Zip Error", MB_ICONERROR); | ||
| 111 | #else | ||
| 112 | MessageBoxA(0, message, "7-Zip Error", MB_ICONERROR); | ||
| 113 | #endif | ||
| 114 | #endif | ||
| 115 | } | ||
| 116 | |||
| 117 | static WRes MyCreateDir(const WCHAR *name) | ||
| 118 | { | ||
| 119 | return CreateDirectoryW(name, NULL) ? 0 : GetLastError(); | ||
| 120 | } | ||
| 121 | |||
| 122 | #ifdef UNDER_CE | ||
| 123 | #define kBufferSize (1 << 13) | ||
| 124 | #else | ||
| 125 | #define kBufferSize (1 << 15) | ||
| 126 | #endif | ||
| 127 | |||
| 128 | #define kSignatureSearchLimit (1 << 22) | ||
| 129 | |||
| 130 | static BoolInt FindSignature(CSzFile *stream, UInt64 *resPos) | ||
| 131 | { | ||
| 132 | Byte buf[kBufferSize]; | ||
| 133 | size_t numPrevBytes = 0; | ||
| 134 | *resPos = 0; | ||
| 135 | for (;;) | ||
| 136 | { | ||
| 137 | size_t processed, pos; | ||
| 138 | if (*resPos > kSignatureSearchLimit) | ||
| 139 | return False; | ||
| 140 | processed = kBufferSize - numPrevBytes; | ||
| 141 | if (File_Read(stream, buf + numPrevBytes, &processed) != 0) | ||
| 142 | return False; | ||
| 143 | processed += numPrevBytes; | ||
| 144 | if (processed < k7zStartHeaderSize || | ||
| 145 | (processed == k7zStartHeaderSize && numPrevBytes != 0)) | ||
| 146 | return False; | ||
| 147 | processed -= k7zStartHeaderSize; | ||
| 148 | for (pos = 0; pos <= processed; pos++) | ||
| 149 | { | ||
| 150 | for (; pos <= processed && buf[pos] != '7'; pos++); | ||
| 151 | if (pos > processed) | ||
| 152 | break; | ||
| 153 | if (memcmp(buf + pos, k7zSignature, k7zSignatureSize) == 0) | ||
| 154 | if (CrcCalc(buf + pos + 12, 20) == GetUi32(buf + pos + 8)) | ||
| 155 | { | ||
| 156 | *resPos += pos; | ||
| 157 | return True; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | *resPos += processed; | ||
| 161 | numPrevBytes = k7zStartHeaderSize; | ||
| 162 | memmove(buf, buf + processed, k7zStartHeaderSize); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | static BoolInt DoesFileOrDirExist(const WCHAR *path) | ||
| 167 | { | ||
| 168 | WIN32_FIND_DATAW fd; | ||
| 169 | HANDLE handle; | ||
| 170 | handle = FindFirstFileW(path, &fd); | ||
| 171 | if (handle == INVALID_HANDLE_VALUE) | ||
| 172 | return False; | ||
| 173 | FindClose(handle); | ||
| 174 | return True; | ||
| 175 | } | ||
| 176 | |||
| 177 | static WRes RemoveDirWithSubItems(WCHAR *path) | ||
| 178 | { | ||
| 179 | WIN32_FIND_DATAW fd; | ||
| 180 | HANDLE handle; | ||
| 181 | WRes res = 0; | ||
| 182 | size_t len = wcslen(path); | ||
| 183 | wcscpy(path + len, L"*"); | ||
| 184 | handle = FindFirstFileW(path, &fd); | ||
| 185 | path[len] = L'\0'; | ||
| 186 | if (handle == INVALID_HANDLE_VALUE) | ||
| 187 | return GetLastError(); | ||
| 188 | |||
| 189 | for (;;) | ||
| 190 | { | ||
| 191 | if (wcscmp(fd.cFileName, L".") != 0 && | ||
| 192 | wcscmp(fd.cFileName, L"..") != 0) | ||
| 193 | { | ||
| 194 | wcscpy(path + len, fd.cFileName); | ||
| 195 | if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) | ||
| 196 | { | ||
| 197 | wcscat(path, WSTRING_PATH_SEPARATOR); | ||
| 198 | res = RemoveDirWithSubItems(path); | ||
| 199 | } | ||
| 200 | else | ||
| 201 | { | ||
| 202 | SetFileAttributesW(path, 0); | ||
| 203 | if (DeleteFileW(path) == 0) | ||
| 204 | res = GetLastError(); | ||
| 205 | } | ||
| 206 | |||
| 207 | if (res != 0) | ||
| 208 | break; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (!FindNextFileW(handle, &fd)) | ||
| 212 | { | ||
| 213 | res = GetLastError(); | ||
| 214 | if (res == ERROR_NO_MORE_FILES) | ||
| 215 | res = 0; | ||
| 216 | break; | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | path[len] = L'\0'; | ||
| 221 | FindClose(handle); | ||
| 222 | if (res == 0) | ||
| 223 | { | ||
| 224 | if (!RemoveDirectoryW(path)) | ||
| 225 | res = GetLastError(); | ||
| 226 | } | ||
| 227 | return res; | ||
| 228 | } | ||
| 229 | |||
| 230 | #ifdef _CONSOLE | ||
| 231 | int MY_CDECL main() | ||
| 232 | #else | ||
| 233 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, | ||
| 234 | #ifdef UNDER_CE | ||
| 235 | LPWSTR | ||
| 236 | #else | ||
| 237 | LPSTR | ||
| 238 | #endif | ||
| 239 | lpCmdLine, int nCmdShow) | ||
| 240 | #endif | ||
| 241 | { | ||
| 242 | CFileInStream archiveStream; | ||
| 243 | CLookToRead2 lookStream; | ||
| 244 | CSzArEx db; | ||
| 245 | SRes res = SZ_OK; | ||
| 246 | ISzAlloc allocImp; | ||
| 247 | ISzAlloc allocTempImp; | ||
| 248 | WCHAR sfxPath[MAX_PATH + 2]; | ||
| 249 | WCHAR path[MAX_PATH * 3 + 2]; | ||
| 250 | #ifndef UNDER_CE | ||
| 251 | WCHAR workCurDir[MAX_PATH + 32]; | ||
| 252 | #endif | ||
| 253 | size_t pathLen; | ||
| 254 | DWORD winRes; | ||
| 255 | const wchar_t *cmdLineParams; | ||
| 256 | const char *errorMessage = NULL; | ||
| 257 | BoolInt useShellExecute = True; | ||
| 258 | DWORD exitCode = 0; | ||
| 259 | |||
| 260 | LoadSecurityDlls(); | ||
| 261 | |||
| 262 | #ifdef _CONSOLE | ||
| 263 | SetConsoleCtrlHandler(HandlerRoutine, TRUE); | ||
| 264 | #else | ||
| 265 | UNUSED_VAR(hInstance); | ||
| 266 | UNUSED_VAR(hPrevInstance); | ||
| 267 | UNUSED_VAR(lpCmdLine); | ||
| 268 | UNUSED_VAR(nCmdShow); | ||
| 269 | #endif | ||
| 270 | |||
| 271 | CrcGenerateTable(); | ||
| 272 | |||
| 273 | allocImp.Alloc = SzAlloc; | ||
| 274 | allocImp.Free = SzFree; | ||
| 275 | |||
| 276 | allocTempImp.Alloc = SzAllocTemp; | ||
| 277 | allocTempImp.Free = SzFreeTemp; | ||
| 278 | |||
| 279 | FileInStream_CreateVTable(&archiveStream); | ||
| 280 | LookToRead2_CreateVTable(&lookStream, False); | ||
| 281 | lookStream.buf = NULL; | ||
| 282 | |||
| 283 | winRes = GetModuleFileNameW(NULL, sfxPath, MAX_PATH); | ||
| 284 | if (winRes == 0 || winRes > MAX_PATH) | ||
| 285 | return 1; | ||
| 286 | { | ||
| 287 | cmdLineParams = GetCommandLineW(); | ||
| 288 | #ifndef UNDER_CE | ||
| 289 | { | ||
| 290 | BoolInt quoteMode = False; | ||
| 291 | for (;; cmdLineParams++) | ||
| 292 | { | ||
| 293 | wchar_t c = *cmdLineParams; | ||
| 294 | if (c == L'\"') | ||
| 295 | quoteMode = !quoteMode; | ||
| 296 | else if (c == 0 || (c == L' ' && !quoteMode)) | ||
| 297 | break; | ||
| 298 | } | ||
| 299 | } | ||
| 300 | #endif | ||
| 301 | } | ||
| 302 | |||
| 303 | { | ||
| 304 | unsigned i; | ||
| 305 | DWORD d; | ||
| 306 | winRes = GetTempPathW(MAX_PATH, path); | ||
| 307 | if (winRes == 0 || winRes > MAX_PATH) | ||
| 308 | return 1; | ||
| 309 | pathLen = wcslen(path); | ||
| 310 | d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId(); | ||
| 311 | |||
| 312 | for (i = 0;; i++, d += GetTickCount()) | ||
| 313 | { | ||
| 314 | if (i >= 100) | ||
| 315 | { | ||
| 316 | res = SZ_ERROR_FAIL; | ||
| 317 | break; | ||
| 318 | } | ||
| 319 | wcscpy(path + pathLen, L"7z"); | ||
| 320 | |||
| 321 | { | ||
| 322 | wchar_t *s = path + wcslen(path); | ||
| 323 | UInt32 value = d; | ||
| 324 | unsigned k; | ||
| 325 | for (k = 0; k < 8; k++) | ||
| 326 | { | ||
| 327 | unsigned t = value & 0xF; | ||
| 328 | value >>= 4; | ||
| 329 | s[7 - k] = (wchar_t)((t < 10) ? ('0' + t) : ('A' + (t - 10))); | ||
| 330 | } | ||
| 331 | s[k] = '\0'; | ||
| 332 | } | ||
| 333 | |||
| 334 | if (DoesFileOrDirExist(path)) | ||
| 335 | continue; | ||
| 336 | if (CreateDirectoryW(path, NULL)) | ||
| 337 | { | ||
| 338 | wcscat(path, WSTRING_PATH_SEPARATOR); | ||
| 339 | pathLen = wcslen(path); | ||
| 340 | break; | ||
| 341 | } | ||
| 342 | if (GetLastError() != ERROR_ALREADY_EXISTS) | ||
| 343 | { | ||
| 344 | res = SZ_ERROR_FAIL; | ||
| 345 | break; | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | #ifndef UNDER_CE | ||
| 350 | wcscpy(workCurDir, path); | ||
| 351 | #endif | ||
| 352 | if (res != SZ_OK) | ||
| 353 | errorMessage = "Can't create temp folder"; | ||
| 354 | } | ||
| 355 | |||
| 356 | if (res != SZ_OK) | ||
| 357 | { | ||
| 358 | if (!errorMessage) | ||
| 359 | errorMessage = "Error"; | ||
| 360 | PrintErrorMessage(errorMessage); | ||
| 361 | return 1; | ||
| 362 | } | ||
| 363 | |||
| 364 | if (InFile_OpenW(&archiveStream.file, sfxPath) != 0) | ||
| 365 | { | ||
| 366 | errorMessage = "can not open input file"; | ||
| 367 | res = SZ_ERROR_FAIL; | ||
| 368 | } | ||
| 369 | else | ||
| 370 | { | ||
| 371 | UInt64 pos = 0; | ||
| 372 | if (!FindSignature(&archiveStream.file, &pos)) | ||
| 373 | res = SZ_ERROR_FAIL; | ||
| 374 | else if (File_Seek(&archiveStream.file, (Int64 *)&pos, SZ_SEEK_SET) != 0) | ||
| 375 | res = SZ_ERROR_FAIL; | ||
| 376 | if (res != 0) | ||
| 377 | errorMessage = "Can't find 7z archive"; | ||
| 378 | } | ||
| 379 | |||
| 380 | if (res == SZ_OK) | ||
| 381 | { | ||
| 382 | lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize); | ||
| 383 | if (!lookStream.buf) | ||
| 384 | res = SZ_ERROR_MEM; | ||
| 385 | else | ||
| 386 | { | ||
| 387 | lookStream.bufSize = kInputBufSize; | ||
| 388 | lookStream.realStream = &archiveStream.vt; | ||
| 389 | LookToRead2_Init(&lookStream); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | SzArEx_Init(&db); | ||
| 394 | |||
| 395 | if (res == SZ_OK) | ||
| 396 | { | ||
| 397 | res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp); | ||
| 398 | } | ||
| 399 | |||
| 400 | if (res == SZ_OK) | ||
| 401 | { | ||
| 402 | UInt32 executeFileIndex = (UInt32)(Int32)-1; | ||
| 403 | UInt32 minPrice = 1 << 30; | ||
| 404 | UInt32 i; | ||
| 405 | UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ | ||
| 406 | Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */ | ||
| 407 | size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ | ||
| 408 | |||
| 409 | for (i = 0; i < db.NumFiles; i++) | ||
| 410 | { | ||
| 411 | size_t offset = 0; | ||
| 412 | size_t outSizeProcessed = 0; | ||
| 413 | WCHAR *temp; | ||
| 414 | |||
| 415 | if (SzArEx_GetFileNameUtf16(&db, i, NULL) >= MAX_PATH) | ||
| 416 | { | ||
| 417 | res = SZ_ERROR_FAIL; | ||
| 418 | break; | ||
| 419 | } | ||
| 420 | |||
| 421 | temp = path + pathLen; | ||
| 422 | |||
| 423 | SzArEx_GetFileNameUtf16(&db, i, (UInt16 *)temp); | ||
| 424 | { | ||
| 425 | res = SzArEx_Extract(&db, &lookStream.vt, i, | ||
| 426 | &blockIndex, &outBuffer, &outBufferSize, | ||
| 427 | &offset, &outSizeProcessed, | ||
| 428 | &allocImp, &allocTempImp); | ||
| 429 | if (res != SZ_OK) | ||
| 430 | break; | ||
| 431 | } | ||
| 432 | { | ||
| 433 | CSzFile outFile; | ||
| 434 | size_t processedSize; | ||
| 435 | size_t j; | ||
| 436 | size_t nameStartPos = 0; | ||
| 437 | for (j = 0; temp[j] != 0; j++) | ||
| 438 | { | ||
| 439 | if (temp[j] == '/') | ||
| 440 | { | ||
| 441 | temp[j] = 0; | ||
| 442 | MyCreateDir(path); | ||
| 443 | temp[j] = CHAR_PATH_SEPARATOR; | ||
| 444 | nameStartPos = j + 1; | ||
| 445 | } | ||
| 446 | } | ||
| 447 | |||
| 448 | if (SzArEx_IsDir(&db, i)) | ||
| 449 | { | ||
| 450 | MyCreateDir(path); | ||
| 451 | continue; | ||
| 452 | } | ||
| 453 | else | ||
| 454 | { | ||
| 455 | unsigned extLen; | ||
| 456 | const WCHAR *name = temp + nameStartPos; | ||
| 457 | unsigned len = (unsigned)wcslen(name); | ||
| 458 | unsigned nameLen = FindExt(temp + nameStartPos, &extLen); | ||
| 459 | unsigned extPrice = FindItem(kExts, sizeof(kExts) / sizeof(kExts[0]), name + len - extLen, extLen); | ||
| 460 | unsigned namePrice = FindItem(kNames, sizeof(kNames) / sizeof(kNames[0]), name, nameLen); | ||
| 461 | |||
| 462 | unsigned price = namePrice + extPrice * 64 + (nameStartPos == 0 ? 0 : (1 << 12)); | ||
| 463 | if (minPrice > price) | ||
| 464 | { | ||
| 465 | minPrice = price; | ||
| 466 | executeFileIndex = i; | ||
| 467 | useShellExecute = (extPrice != k_EXE_ExtIndex); | ||
| 468 | } | ||
| 469 | |||
| 470 | if (DoesFileOrDirExist(path)) | ||
| 471 | { | ||
| 472 | errorMessage = "Duplicate file"; | ||
| 473 | res = SZ_ERROR_FAIL; | ||
| 474 | break; | ||
| 475 | } | ||
| 476 | if (OutFile_OpenW(&outFile, path)) | ||
| 477 | { | ||
| 478 | errorMessage = "Can't open output file"; | ||
| 479 | res = SZ_ERROR_FAIL; | ||
| 480 | break; | ||
| 481 | } | ||
| 482 | } | ||
| 483 | |||
| 484 | processedSize = outSizeProcessed; | ||
| 485 | if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed) | ||
| 486 | { | ||
| 487 | errorMessage = "Can't write output file"; | ||
| 488 | res = SZ_ERROR_FAIL; | ||
| 489 | } | ||
| 490 | |||
| 491 | #ifdef USE_WINDOWS_FILE | ||
| 492 | if (SzBitWithVals_Check(&db.MTime, i)) | ||
| 493 | { | ||
| 494 | const CNtfsFileTime *t = db.MTime.Vals + i; | ||
| 495 | FILETIME mTime; | ||
| 496 | mTime.dwLowDateTime = t->Low; | ||
| 497 | mTime.dwHighDateTime = t->High; | ||
| 498 | SetFileTime(outFile.handle, NULL, NULL, &mTime); | ||
| 499 | } | ||
| 500 | #endif | ||
| 501 | |||
| 502 | { | ||
| 503 | SRes res2 = File_Close(&outFile); | ||
| 504 | if (res != SZ_OK) | ||
| 505 | break; | ||
| 506 | if (res2 != SZ_OK) | ||
| 507 | { | ||
| 508 | res = res2; | ||
| 509 | break; | ||
| 510 | } | ||
| 511 | } | ||
| 512 | #ifdef USE_WINDOWS_FILE | ||
| 513 | if (SzBitWithVals_Check(&db.Attribs, i)) | ||
| 514 | SetFileAttributesW(path, db.Attribs.Vals[i]); | ||
| 515 | #endif | ||
| 516 | } | ||
| 517 | } | ||
| 518 | |||
| 519 | if (res == SZ_OK) | ||
| 520 | { | ||
| 521 | if (executeFileIndex == (UInt32)(Int32)-1) | ||
| 522 | { | ||
| 523 | errorMessage = "There is no file to execute"; | ||
| 524 | res = SZ_ERROR_FAIL; | ||
| 525 | } | ||
| 526 | else | ||
| 527 | { | ||
| 528 | WCHAR *temp = path + pathLen; | ||
| 529 | UInt32 j; | ||
| 530 | SzArEx_GetFileNameUtf16(&db, executeFileIndex, (UInt16 *)temp); | ||
| 531 | for (j = 0; temp[j] != 0; j++) | ||
| 532 | if (temp[j] == '/') | ||
| 533 | temp[j] = CHAR_PATH_SEPARATOR; | ||
| 534 | } | ||
| 535 | } | ||
| 536 | ISzAlloc_Free(&allocImp, outBuffer); | ||
| 537 | } | ||
| 538 | |||
| 539 | SzArEx_Free(&db, &allocImp); | ||
| 540 | |||
| 541 | ISzAlloc_Free(&allocImp, lookStream.buf); | ||
| 542 | |||
| 543 | File_Close(&archiveStream.file); | ||
| 544 | |||
| 545 | if (res == SZ_OK) | ||
| 546 | { | ||
| 547 | HANDLE hProcess = 0; | ||
| 548 | |||
| 549 | #ifndef UNDER_CE | ||
| 550 | WCHAR oldCurDir[MAX_PATH + 2]; | ||
| 551 | oldCurDir[0] = 0; | ||
| 552 | { | ||
| 553 | DWORD needLen = GetCurrentDirectory(MAX_PATH + 1, oldCurDir); | ||
| 554 | if (needLen == 0 || needLen > MAX_PATH) | ||
| 555 | oldCurDir[0] = 0; | ||
| 556 | SetCurrentDirectory(workCurDir); | ||
| 557 | } | ||
| 558 | #endif | ||
| 559 | |||
| 560 | if (useShellExecute) | ||
| 561 | { | ||
| 562 | SHELLEXECUTEINFO ei; | ||
| 563 | UINT32 executeRes; | ||
| 564 | BOOL success; | ||
| 565 | |||
| 566 | memset(&ei, 0, sizeof(ei)); | ||
| 567 | ei.cbSize = sizeof(ei); | ||
| 568 | ei.lpFile = path; | ||
| 569 | ei.fMask = SEE_MASK_NOCLOSEPROCESS | ||
| 570 | #ifndef UNDER_CE | ||
| 571 | | SEE_MASK_FLAG_DDEWAIT | ||
| 572 | #endif | ||
| 573 | /* | SEE_MASK_NO_CONSOLE */ | ||
| 574 | ; | ||
| 575 | if (wcslen(cmdLineParams) != 0) | ||
| 576 | ei.lpParameters = cmdLineParams; | ||
| 577 | ei.nShow = SW_SHOWNORMAL; /* SW_HIDE; */ | ||
| 578 | success = ShellExecuteEx(&ei); | ||
| 579 | executeRes = (UINT32)(UINT_PTR)ei.hInstApp; | ||
| 580 | if (!success || (executeRes <= 32 && executeRes != 0)) /* executeRes = 0 in Windows CE */ | ||
| 581 | res = SZ_ERROR_FAIL; | ||
| 582 | else | ||
| 583 | hProcess = ei.hProcess; | ||
| 584 | } | ||
| 585 | else | ||
| 586 | { | ||
| 587 | STARTUPINFOW si; | ||
| 588 | PROCESS_INFORMATION pi; | ||
| 589 | WCHAR cmdLine[MAX_PATH * 3]; | ||
| 590 | |||
| 591 | wcscpy(cmdLine, path); | ||
| 592 | wcscat(cmdLine, cmdLineParams); | ||
| 593 | memset(&si, 0, sizeof(si)); | ||
| 594 | si.cb = sizeof(si); | ||
| 595 | if (CreateProcessW(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == 0) | ||
| 596 | res = SZ_ERROR_FAIL; | ||
| 597 | else | ||
| 598 | { | ||
| 599 | CloseHandle(pi.hThread); | ||
| 600 | hProcess = pi.hProcess; | ||
| 601 | } | ||
| 602 | } | ||
| 603 | |||
| 604 | if (hProcess != 0) | ||
| 605 | { | ||
| 606 | WaitForSingleObject(hProcess, INFINITE); | ||
| 607 | if (!GetExitCodeProcess(hProcess, &exitCode)) | ||
| 608 | exitCode = 1; | ||
| 609 | CloseHandle(hProcess); | ||
| 610 | } | ||
| 611 | |||
| 612 | #ifndef UNDER_CE | ||
| 613 | SetCurrentDirectory(oldCurDir); | ||
| 614 | #endif | ||
| 615 | } | ||
| 616 | |||
| 617 | path[pathLen] = L'\0'; | ||
| 618 | RemoveDirWithSubItems(path); | ||
| 619 | |||
| 620 | if (res == SZ_OK) | ||
| 621 | return (int)exitCode; | ||
| 622 | |||
| 623 | { | ||
| 624 | if (res == SZ_ERROR_UNSUPPORTED) | ||
| 625 | errorMessage = "Decoder doesn't support this archive"; | ||
| 626 | else if (res == SZ_ERROR_MEM) | ||
| 627 | errorMessage = "Can't allocate required memory"; | ||
| 628 | else if (res == SZ_ERROR_CRC) | ||
| 629 | errorMessage = "CRC error"; | ||
| 630 | else | ||
| 631 | { | ||
| 632 | if (!errorMessage) | ||
| 633 | errorMessage = "ERROR"; | ||
| 634 | } | ||
| 635 | |||
| 636 | if (errorMessage) | ||
| 637 | PrintErrorMessage(errorMessage); | ||
| 638 | } | ||
| 639 | return 1; | ||
| 640 | } | ||
diff --git a/C/Util/SfxSetup/SfxSetup.dsp b/C/Util/SfxSetup/SfxSetup.dsp new file mode 100644 index 0000000..60439a6 --- /dev/null +++ b/C/Util/SfxSetup/SfxSetup.dsp | |||
| @@ -0,0 +1,231 @@ | |||
| 1 | # Microsoft Developer Studio Project File - Name="SfxSetup" - Package Owner=<4> | ||
| 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 | ||
| 3 | # ** DO NOT EDIT ** | ||
| 4 | |||
| 5 | # TARGTYPE "Win32 (x86) Application" 0x0101 | ||
| 6 | |||
| 7 | CFG=SfxSetup - Win32 Debug | ||
| 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, | ||
| 9 | !MESSAGE use the Export Makefile command and run | ||
| 10 | !MESSAGE | ||
| 11 | !MESSAGE NMAKE /f "SfxSetup.mak". | ||
| 12 | !MESSAGE | ||
| 13 | !MESSAGE You can specify a configuration when running NMAKE | ||
| 14 | !MESSAGE by defining the macro CFG on the command line. For example: | ||
| 15 | !MESSAGE | ||
| 16 | !MESSAGE NMAKE /f "SfxSetup.mak" CFG="SfxSetup - Win32 Debug" | ||
| 17 | !MESSAGE | ||
| 18 | !MESSAGE Possible choices for configuration are: | ||
| 19 | !MESSAGE | ||
| 20 | !MESSAGE "SfxSetup - Win32 Release" (based on "Win32 (x86) Application") | ||
| 21 | !MESSAGE "SfxSetup - Win32 Debug" (based on "Win32 (x86) Application") | ||
| 22 | !MESSAGE | ||
| 23 | |||
| 24 | # Begin Project | ||
| 25 | # PROP AllowPerConfigDependencies 0 | ||
| 26 | # PROP Scc_ProjName "" | ||
| 27 | # PROP Scc_LocalPath "" | ||
| 28 | CPP=cl.exe | ||
| 29 | MTL=midl.exe | ||
| 30 | RSC=rc.exe | ||
| 31 | |||
| 32 | !IF "$(CFG)" == "SfxSetup - Win32 Release" | ||
| 33 | |||
| 34 | # PROP BASE Use_MFC 0 | ||
| 35 | # PROP BASE Use_Debug_Libraries 0 | ||
| 36 | # PROP BASE Output_Dir "Release" | ||
| 37 | # PROP BASE Intermediate_Dir "Release" | ||
| 38 | # PROP BASE Target_Dir "" | ||
| 39 | # PROP Use_MFC 0 | ||
| 40 | # PROP Use_Debug_Libraries 0 | ||
| 41 | # PROP Output_Dir "Release" | ||
| 42 | # PROP Intermediate_Dir "Release" | ||
| 43 | # PROP Target_Dir "" | ||
| 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c | ||
| 45 | # ADD CPP /nologo /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Yu"Precomp.h" /FD /c | ||
| 46 | # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 47 | # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 | ||
| 48 | # ADD BASE RSC /l 0x419 /d "NDEBUG" | ||
| 49 | # ADD RSC /l 0x419 /d "NDEBUG" | ||
| 50 | BSC32=bscmake.exe | ||
| 51 | # ADD BASE BSC32 /nologo | ||
| 52 | # ADD BSC32 /nologo | ||
| 53 | LINK32=link.exe | ||
| 54 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 | ||
| 55 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 | ||
| 56 | |||
| 57 | !ELSEIF "$(CFG)" == "SfxSetup - Win32 Debug" | ||
| 58 | |||
| 59 | # PROP BASE Use_MFC 0 | ||
| 60 | # PROP BASE Use_Debug_Libraries 1 | ||
| 61 | # PROP BASE Output_Dir "Debug" | ||
| 62 | # PROP BASE Intermediate_Dir "Debug" | ||
| 63 | # PROP BASE Target_Dir "" | ||
| 64 | # PROP Use_MFC 0 | ||
| 65 | # PROP Use_Debug_Libraries 1 | ||
| 66 | # PROP Output_Dir "Debug" | ||
| 67 | # PROP Intermediate_Dir "Debug" | ||
| 68 | # PROP Ignore_Export_Lib 0 | ||
| 69 | # PROP Target_Dir "" | ||
| 70 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c | ||
| 71 | # ADD CPP /nologo /W4 /WX /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Yu"Precomp.h" /FD /GZ /c | ||
| 72 | # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 73 | # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 | ||
| 74 | # ADD BASE RSC /l 0x419 /d "_DEBUG" | ||
| 75 | # ADD RSC /l 0x419 /d "_DEBUG" | ||
| 76 | BSC32=bscmake.exe | ||
| 77 | # ADD BASE BSC32 /nologo | ||
| 78 | # ADD BSC32 /nologo | ||
| 79 | LINK32=link.exe | ||
| 80 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept | ||
| 81 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept | ||
| 82 | |||
| 83 | !ENDIF | ||
| 84 | |||
| 85 | # Begin Target | ||
| 86 | |||
| 87 | # Name "SfxSetup - Win32 Release" | ||
| 88 | # Name "SfxSetup - Win32 Debug" | ||
| 89 | # Begin Group "Common" | ||
| 90 | |||
| 91 | # PROP Default_Filter "" | ||
| 92 | # Begin Source File | ||
| 93 | |||
| 94 | SOURCE=..\..\7z.h | ||
| 95 | # End Source File | ||
| 96 | # Begin Source File | ||
| 97 | |||
| 98 | SOURCE=..\..\7zAlloc.c | ||
| 99 | # End Source File | ||
| 100 | # Begin Source File | ||
| 101 | |||
| 102 | SOURCE=..\..\7zAlloc.h | ||
| 103 | # End Source File | ||
| 104 | # Begin Source File | ||
| 105 | |||
| 106 | SOURCE=..\..\7zArcIn.c | ||
| 107 | # End Source File | ||
| 108 | # Begin Source File | ||
| 109 | |||
| 110 | SOURCE=..\..\7zBuf.c | ||
| 111 | # End Source File | ||
| 112 | # Begin Source File | ||
| 113 | |||
| 114 | SOURCE=..\..\7zBuf.h | ||
| 115 | # End Source File | ||
| 116 | # Begin Source File | ||
| 117 | |||
| 118 | SOURCE=..\..\7zCrc.c | ||
| 119 | # End Source File | ||
| 120 | # Begin Source File | ||
| 121 | |||
| 122 | SOURCE=..\..\7zCrc.h | ||
| 123 | # End Source File | ||
| 124 | # Begin Source File | ||
| 125 | |||
| 126 | SOURCE=..\..\7zCrcOpt.c | ||
| 127 | # End Source File | ||
| 128 | # Begin Source File | ||
| 129 | |||
| 130 | SOURCE=..\..\7zDec.c | ||
| 131 | # End Source File | ||
| 132 | # Begin Source File | ||
| 133 | |||
| 134 | SOURCE=..\..\7zFile.c | ||
| 135 | # End Source File | ||
| 136 | # Begin Source File | ||
| 137 | |||
| 138 | SOURCE=..\..\7zFile.h | ||
| 139 | # End Source File | ||
| 140 | # Begin Source File | ||
| 141 | |||
| 142 | SOURCE=..\..\7zStream.c | ||
| 143 | # End Source File | ||
| 144 | # Begin Source File | ||
| 145 | |||
| 146 | SOURCE=..\..\7zTypes.h | ||
| 147 | # End Source File | ||
| 148 | # Begin Source File | ||
| 149 | |||
| 150 | SOURCE=..\..\Bcj2.c | ||
| 151 | # End Source File | ||
| 152 | # Begin Source File | ||
| 153 | |||
| 154 | SOURCE=..\..\Bcj2.h | ||
| 155 | # End Source File | ||
| 156 | # Begin Source File | ||
| 157 | |||
| 158 | SOURCE=..\..\Bra.c | ||
| 159 | # End Source File | ||
| 160 | # Begin Source File | ||
| 161 | |||
| 162 | SOURCE=..\..\Bra.h | ||
| 163 | # End Source File | ||
| 164 | # Begin Source File | ||
| 165 | |||
| 166 | SOURCE=..\..\Bra86.c | ||
| 167 | # End Source File | ||
| 168 | # Begin Source File | ||
| 169 | |||
| 170 | SOURCE=..\..\BraIA64.c | ||
| 171 | # End Source File | ||
| 172 | # Begin Source File | ||
| 173 | |||
| 174 | SOURCE=..\..\CpuArch.c | ||
| 175 | # End Source File | ||
| 176 | # Begin Source File | ||
| 177 | |||
| 178 | SOURCE=..\..\CpuArch.h | ||
| 179 | # End Source File | ||
| 180 | # Begin Source File | ||
| 181 | |||
| 182 | SOURCE=..\..\Delta.c | ||
| 183 | # End Source File | ||
| 184 | # Begin Source File | ||
| 185 | |||
| 186 | SOURCE=..\..\Delta.h | ||
| 187 | # End Source File | ||
| 188 | # Begin Source File | ||
| 189 | |||
| 190 | SOURCE=..\..\DllSecur.c | ||
| 191 | # End Source File | ||
| 192 | # Begin Source File | ||
| 193 | |||
| 194 | SOURCE=..\..\DllSecur.h | ||
| 195 | # End Source File | ||
| 196 | # Begin Source File | ||
| 197 | |||
| 198 | SOURCE=..\..\Lzma2Dec.c | ||
| 199 | # End Source File | ||
| 200 | # Begin Source File | ||
| 201 | |||
| 202 | SOURCE=..\..\Lzma2Dec.h | ||
| 203 | # End Source File | ||
| 204 | # Begin Source File | ||
| 205 | |||
| 206 | SOURCE=..\..\LzmaDec.c | ||
| 207 | # End Source File | ||
| 208 | # Begin Source File | ||
| 209 | |||
| 210 | SOURCE=..\..\LzmaDec.h | ||
| 211 | # End Source File | ||
| 212 | # End Group | ||
| 213 | # Begin Group "Spec" | ||
| 214 | |||
| 215 | # PROP Default_Filter "" | ||
| 216 | # Begin Source File | ||
| 217 | |||
| 218 | SOURCE=.\Precomp.c | ||
| 219 | # ADD CPP /Yc"Precomp.h" | ||
| 220 | # End Source File | ||
| 221 | # Begin Source File | ||
| 222 | |||
| 223 | SOURCE=.\Precomp.h | ||
| 224 | # End Source File | ||
| 225 | # End Group | ||
| 226 | # Begin Source File | ||
| 227 | |||
| 228 | SOURCE=.\SfxSetup.c | ||
| 229 | # End Source File | ||
| 230 | # End Target | ||
| 231 | # End Project | ||
diff --git a/C/Util/SfxSetup/SfxSetup.dsw b/C/Util/SfxSetup/SfxSetup.dsw new file mode 100644 index 0000000..ea23111 --- /dev/null +++ b/C/Util/SfxSetup/SfxSetup.dsw | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 | ||
| 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! | ||
| 3 | |||
| 4 | ############################################################################### | ||
| 5 | |||
| 6 | Project: "SfxSetup"=.\SfxSetup.dsp - Package Owner=<4> | ||
| 7 | |||
| 8 | Package=<5> | ||
| 9 | {{{ | ||
| 10 | }}} | ||
| 11 | |||
| 12 | Package=<4> | ||
| 13 | {{{ | ||
| 14 | }}} | ||
| 15 | |||
| 16 | ############################################################################### | ||
| 17 | |||
| 18 | Global: | ||
| 19 | |||
| 20 | Package=<5> | ||
| 21 | {{{ | ||
| 22 | }}} | ||
| 23 | |||
| 24 | Package=<3> | ||
| 25 | {{{ | ||
| 26 | }}} | ||
| 27 | |||
| 28 | ############################################################################### | ||
| 29 | |||
diff --git a/C/Util/SfxSetup/makefile b/C/Util/SfxSetup/makefile new file mode 100644 index 0000000..544da67 --- /dev/null +++ b/C/Util/SfxSetup/makefile | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | PROG = 7zS2.sfx | ||
| 2 | MY_FIXED = 1 | ||
| 3 | |||
| 4 | C_OBJS = \ | ||
| 5 | $O\7zAlloc.obj \ | ||
| 6 | $O\7zArcIn.obj \ | ||
| 7 | $O\7zBuf.obj \ | ||
| 8 | $O\7zBuf2.obj \ | ||
| 9 | $O\7zCrc.obj \ | ||
| 10 | $O\7zCrcOpt.obj \ | ||
| 11 | $O\7zFile.obj \ | ||
| 12 | $O\7zDec.obj \ | ||
| 13 | $O\7zStream.obj \ | ||
| 14 | $O\Bcj2.obj \ | ||
| 15 | $O\Bra.obj \ | ||
| 16 | $O\Bra86.obj \ | ||
| 17 | $O\BraIA64.obj \ | ||
| 18 | $O\CpuArch.obj \ | ||
| 19 | $O\Delta.obj \ | ||
| 20 | $O\DllSecur.obj \ | ||
| 21 | $O\Lzma2Dec.obj \ | ||
| 22 | $O\LzmaDec.obj \ | ||
| 23 | |||
| 24 | 7Z_OBJS = \ | ||
| 25 | $O\SfxSetup.obj \ | ||
| 26 | |||
| 27 | OBJS = \ | ||
| 28 | $(7Z_OBJS) \ | ||
| 29 | $(C_OBJS) \ | ||
| 30 | $O\resource.res | ||
| 31 | |||
| 32 | !include "../../../CPP/Build.mak" | ||
| 33 | |||
| 34 | $(7Z_OBJS): $(*B).c | ||
| 35 | $(COMPL_O1) | ||
| 36 | $(C_OBJS): ../../$(*B).c | ||
| 37 | $(COMPL_O1) | ||
diff --git a/C/Util/SfxSetup/makefile_con b/C/Util/SfxSetup/makefile_con new file mode 100644 index 0000000..d0f8352 --- /dev/null +++ b/C/Util/SfxSetup/makefile_con | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | PROG = 7zS2con.sfx | ||
| 2 | MY_FIXED = 1 | ||
| 3 | CFLAGS = $(CFLAGS) -D_CONSOLE | ||
| 4 | |||
| 5 | C_OBJS = \ | ||
| 6 | $O\7zAlloc.obj \ | ||
| 7 | $O\7zArcIn.obj \ | ||
| 8 | $O\7zBuf.obj \ | ||
| 9 | $O\7zBuf2.obj \ | ||
| 10 | $O\7zCrc.obj \ | ||
| 11 | $O\7zCrcOpt.obj \ | ||
| 12 | $O\7zFile.obj \ | ||
| 13 | $O\7zDec.obj \ | ||
| 14 | $O\7zStream.obj \ | ||
| 15 | $O\Bcj2.obj \ | ||
| 16 | $O\Bra.obj \ | ||
| 17 | $O\Bra86.obj \ | ||
| 18 | $O\BraIA64.obj \ | ||
| 19 | $O\CpuArch.obj \ | ||
| 20 | $O\Delta.obj \ | ||
| 21 | $O\DllSecur.obj \ | ||
| 22 | $O\Lzma2Dec.obj \ | ||
| 23 | $O\LzmaDec.obj \ | ||
| 24 | |||
| 25 | 7Z_OBJS = \ | ||
| 26 | $O\SfxSetup.obj \ | ||
| 27 | |||
| 28 | OBJS = \ | ||
| 29 | $(7Z_OBJS) \ | ||
| 30 | $(C_OBJS) \ | ||
| 31 | $O\resource.res | ||
| 32 | |||
| 33 | !include "../../../CPP/Build.mak" | ||
| 34 | |||
| 35 | $(7Z_OBJS): $(*B).c | ||
| 36 | $(COMPL_O1) | ||
| 37 | $(C_OBJS): ../../$(*B).c | ||
| 38 | $(COMPL_O1) | ||
diff --git a/C/Util/SfxSetup/resource.rc b/C/Util/SfxSetup/resource.rc new file mode 100644 index 0000000..0c1637f --- /dev/null +++ b/C/Util/SfxSetup/resource.rc | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | #include "../../7zVersion.rc" | ||
| 2 | |||
| 3 | MY_VERSION_INFO_APP("7z Setup SFX small", "7zS2.sfx") | ||
| 4 | |||
| 5 | 1 ICON "setup.ico" | ||
diff --git a/C/Util/SfxSetup/setup.ico b/C/Util/SfxSetup/setup.ico new file mode 100644 index 0000000..dbb6ca8 --- /dev/null +++ b/C/Util/SfxSetup/setup.ico | |||
| Binary files differ | |||
