diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /C/Util/7zipUninstall | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'C/Util/7zipUninstall')
-rw-r--r-- | C/Util/7zipUninstall/7zipUninstall.c | 1183 | ||||
-rw-r--r-- | C/Util/7zipUninstall/7zipUninstall.dsp | 124 | ||||
-rw-r--r-- | C/Util/7zipUninstall/7zipUninstall.dsw | 29 | ||||
-rw-r--r-- | C/Util/7zipUninstall/7zipUninstall.ico | bin | 0 -> 1078 bytes | |||
-rw-r--r-- | C/Util/7zipUninstall/7zipUninstall.manifest | 18 | ||||
-rw-r--r-- | C/Util/7zipUninstall/Precomp.c | 4 | ||||
-rw-r--r-- | C/Util/7zipUninstall/Precomp.h | 11 | ||||
-rw-r--r-- | C/Util/7zipUninstall/makefile | 18 | ||||
-rw-r--r-- | C/Util/7zipUninstall/resource.h | 9 | ||||
-rw-r--r-- | C/Util/7zipUninstall/resource.rc | 47 |
10 files changed, 1443 insertions, 0 deletions
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 | ||