diff options
Diffstat (limited to 'C/Util/7zipInstall')
-rw-r--r-- | C/Util/7zipInstall/7zip.ico | bin | 0 -> 1078 bytes | |||
-rw-r--r-- | C/Util/7zipInstall/7zipInstall.c | 1666 | ||||
-rw-r--r-- | C/Util/7zipInstall/7zipInstall.dsp | 240 | ||||
-rw-r--r-- | C/Util/7zipInstall/7zipInstall.dsw | 29 | ||||
-rw-r--r-- | C/Util/7zipInstall/7zipInstall.manifest | 18 | ||||
-rw-r--r-- | C/Util/7zipInstall/Precomp.c | 4 | ||||
-rw-r--r-- | C/Util/7zipInstall/Precomp.h | 11 | ||||
-rw-r--r-- | C/Util/7zipInstall/makefile | 42 | ||||
-rw-r--r-- | C/Util/7zipInstall/resource.h | 9 | ||||
-rw-r--r-- | C/Util/7zipInstall/resource.rc | 47 |
10 files changed, 2066 insertions, 0 deletions
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 | ||