|
|
1.1.1.11 root 1: /*
1.1.1.13 root 2: Legal Notice: Some portions of the source code contained in this file were
3: derived from the source code of Encryption for the Masses 2.02a, which is
4: Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
5: Agreement for Encryption for the Masses'. Modifications and additions to
6: the original source code (contained in this file) and all other portions of
7: this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed
8: by the TrueCrypt License 2.4 the full text of which is contained in the
9: file License.txt included in TrueCrypt binary and source code distribution
1.1.1.11 root 10: packages. */
1.1 root 11:
1.1.1.7 root 12: #include "Tcdefs.h"
1.1 root 13: #include <SrRestorePtApi.h>
1.1.1.7 root 14: #include <sys/types.h>
15: #include <sys/stat.h>
1.1 root 16:
1.1.1.7 root 17: #include "Apidrvr.h"
1.1.1.13 root 18: #include "BootEncryption.h"
1.1.1.7 root 19: #include "Combo.h"
1.1.1.11 root 20: #include "ComSetup.h"
1.1.1.7 root 21: #include "Dlgcode.h"
22: #include "Language.h"
23: #include "Registry.h"
24: #include "Resource.h"
1.1 root 25:
1.1.1.7 root 26: #include "Dir.h"
27: #include "Setup.h"
1.1.1.13 root 28: #include "SelfExtract.h"
29: #include "Wizard.h"
1.1 root 30:
1.1.1.7 root 31: #include "../Common/Resource.h"
32: #include "../Mount/Mount.h"
1.1 root 33:
1.1.1.13 root 34: using namespace TrueCrypt;
35:
1.1 root 36: #pragma warning( disable : 4201 )
37: #pragma warning( disable : 4115 )
38:
39: #include <shlobj.h>
40:
41: #pragma warning( default : 4201 )
42: #pragma warning( default : 4115 )
43:
1.1.1.13 root 44: char InstallationPath[TC_MAX_PATH];
1.1.1.8 root 45: char SetupFilesDir[TC_MAX_PATH];
1.1.1.11 root 46: char UninstallBatch[MAX_PATH];
1.1.1.8 root 47:
1.1 root 48: BOOL bUninstall = FALSE;
1.1.1.13 root 49: BOOL bMakePackage = FALSE;
1.1 root 50: BOOL bDone = FALSE;
1.1.1.11 root 51: BOOL Rollback = FALSE;
52: BOOL bUpgrade = FALSE;
1.1.1.14! root 53: BOOL SystemEncryptionUpgrade = FALSE;
1.1.1.13 root 54: BOOL bRepairMode = FALSE;
55: BOOL bChangeMode = FALSE;
56: BOOL bDevm = FALSE;
1.1.1.11 root 57: BOOL bFirstTimeInstall = FALSE;
1.1.1.13 root 58: BOOL bUninstallInProgress = FALSE;
59:
60: BOOL bSystemRestore = TRUE;
61: BOOL bForAllUsers = TRUE;
62: BOOL bRegisterFileExt = TRUE;
63: BOOL bAddToStartMenu = TRUE;
64: BOOL bDesktopIcon = TRUE;
1.1 root 65:
1.1.1.13 root 66: HMODULE volatile SystemRestoreDll = 0;
1.1 root 67:
68: BOOL
69: StatDeleteFile (char *lpszFile)
70: {
71: struct __stat64 st;
72:
73: if (_stat64 (lpszFile, &st) == 0)
74: return DeleteFile (lpszFile);
75: else
76: return TRUE;
77: }
78:
79: BOOL
80: StatRemoveDirectory (char *lpszDir)
81: {
82: struct __stat64 st;
83:
84: if (_stat64 (lpszDir, &st) == 0)
85: return RemoveDirectory (lpszDir);
86: else
87: return TRUE;
88: }
89:
90: HRESULT
91: CreateLink (char *lpszPathObj, char *lpszArguments,
92: char *lpszPathLink)
93: {
94: HRESULT hres;
95: IShellLink *psl;
96:
97: /* Get a pointer to the IShellLink interface. */
1.1.1.13 root 98: hres = CoCreateInstance (CLSID_ShellLink, NULL,
99: CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
1.1 root 100: if (SUCCEEDED (hres))
101: {
102: IPersistFile *ppf;
103:
104: /* Set the path to the shortcut target, and add the
105: description. */
1.1.1.13 root 106: psl->SetPath (lpszPathObj);
107: psl->SetArguments (lpszArguments);
1.1 root 108:
109: /* Query IShellLink for the IPersistFile interface for saving
110: the shortcut in persistent storage. */
1.1.1.13 root 111: hres = psl->QueryInterface (IID_IPersistFile,
112: (void **) &ppf);
1.1 root 113:
114: if (SUCCEEDED (hres))
115: {
1.1.1.13 root 116: wchar_t wsz[TC_MAX_PATH];
1.1 root 117:
118: /* Ensure that the string is ANSI. */
119: MultiByteToWideChar (CP_ACP, 0, lpszPathLink, -1,
120: wsz, TC_MAX_PATH);
121:
122: /* Save the link by calling IPersistFile::Save. */
1.1.1.13 root 123: hres = ppf->Save (wsz, TRUE);
124: ppf->Release ();
1.1 root 125: }
1.1.1.13 root 126: psl->Release ();
1.1 root 127: }
128: return hres;
129: }
130:
131: void
132: GetProgramPath (HWND hwndDlg, char *path)
133: {
134: ITEMIDLIST *i;
135: HRESULT res;
136:
1.1.1.13 root 137: if (bForAllUsers)
1.1 root 138: res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
139: else
140: res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);
141:
142: SHGetPathFromIDList (i, path);
143: }
144:
1.1.1.13 root 145: void
146: StatusMessage (HWND hwndDlg, char *stringId)
1.1 root 147: {
1.1.1.11 root 148: if (Rollback)
149: return;
150:
1.1.1.13 root 151: SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) GetString (stringId));
1.1.1.11 root 152:
1.1.1.13 root 153: SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX,
154: SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
1.1 root 155: }
156:
1.1.1.13 root 157: void
1.1.1.7 root 158: StatusMessageParam (HWND hwndDlg, char *stringId, char *param)
1.1 root 159: {
1.1.1.7 root 160: wchar_t szTmp[1024];
1.1.1.11 root 161:
162: if (Rollback)
163: return;
164:
1.1.1.7 root 165: wsprintfW (szTmp, L"%s %hs", GetString (stringId), param);
1.1.1.13 root 166: SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) szTmp);
1.1.1.7 root 167:
1.1.1.13 root 168: SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX,
169: SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
170: }
171:
172: void
173: ClearLogWindow (HWND hwndDlg)
174: {
175: SendMessage (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_RESETCONTENT, 0, 0);
1.1 root 176: }
177:
178: void
1.1.1.7 root 179: RegMessage (HWND hwndDlg, char *txt)
1.1 root 180: {
1.1.1.7 root 181: StatusMessageParam (hwndDlg, "ADDING_REG", txt);
1.1 root 182: }
183:
184: void
1.1.1.7 root 185: CopyMessage (HWND hwndDlg, char *txt)
1.1 root 186: {
1.1.1.11 root 187: StatusMessageParam (hwndDlg, "INSTALLING", txt);
1.1 root 188: }
189:
190: void
1.1.1.7 root 191: RemoveMessage (HWND hwndDlg, char *txt)
1.1 root 192: {
1.1.1.11 root 193: if (!Rollback)
194: StatusMessageParam (hwndDlg, "REMOVING", txt);
1.1 root 195: }
196:
197: void
198: IconMessage (HWND hwndDlg, char *txt)
199: {
1.1.1.7 root 200: StatusMessageParam (hwndDlg, "ADDING_ICON", txt);
1.1 root 201: }
202:
203:
1.1.1.13 root 204: BOOL DoFilesInstall (HWND hwndDlg, char *szDestDir)
1.1 root 205: {
1.1.1.13 root 206: /* WARNING: Note that, despite its name, this function is used during UNinstallation as well. */
1.1 root 207:
208: char szTmp[TC_MAX_PATH];
209: BOOL bOK = TRUE;
1.1.1.13 root 210: int i, x, fileNo;
211: char curFileName [TC_MAX_PATH] = {0};
212:
213: if (!bUninstall && !bDevm)
214: {
215: // Self-extract all files to memory
216:
217: GetModuleFileName (NULL, szTmp, sizeof (szTmp));
218:
219: if (!SelfExtractInMemory (szTmp))
220: return FALSE;
221: }
1.1 root 222:
1.1.1.11 root 223: x = strlen (szDestDir);
1.1.1.13 root 224: if (x < 2)
1.1.1.11 root 225: return FALSE;
226:
227: if (szDestDir[x - 1] != '\\')
228: strcat (szDestDir, "\\");
1.1 root 229:
230: for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
231: {
1.1.1.11 root 232: BOOL bResult;
1.1 root 233: char szDir[TC_MAX_PATH];
234:
1.1.1.13 root 235: if (strstr (szFiles[i], "TrueCrypt Setup") != 0)
236: {
237: if (bUninstall)
238: continue; // Prevent 'access denied' error
239:
240: if (bRepairMode)
241: continue; // Destination = target
242: }
1.1 root 243:
244: if (*szFiles[i] == 'A')
245: strcpy (szDir, szDestDir);
246: else if (*szFiles[i] == 'D')
247: {
1.1.1.10 root 248: GetSystemDirectory (szDir, sizeof (szDir));
1.1 root 249:
1.1.1.11 root 250: x = strlen (szDir);
251: if (szDir[x - 1] != '\\')
1.1 root 252: strcat (szDir, "\\");
253:
1.1.1.11 root 254: strcat (szDir, "Drivers\\");
1.1 root 255: }
256: else if (*szFiles[i] == 'W')
257: GetWindowsDirectory (szDir, sizeof (szDir));
258:
1.1.1.7 root 259: if (*szFiles[i] == 'I')
1.1 root 260: continue;
261:
262: sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1);
263:
264: if (bUninstall == FALSE)
265: CopyMessage (hwndDlg, szTmp);
266: else
267: RemoveMessage (hwndDlg, szTmp);
268:
269: if (bUninstall == FALSE)
270: {
1.1.1.8 root 271: SetCurrentDirectory (SetupFilesDir);
272:
1.1.1.13 root 273: if (strstr (szFiles[i], "TrueCrypt Setup") != 0)
1.1 root 274: {
1.1.1.13 root 275: // Copy ourselves (the distribution package) to the destination location as 'TrueCrypt Setup.exe'
1.1.1.7 root 276:
1.1.1.13 root 277: char mp[MAX_PATH];
1.1.1.7 root 278:
1.1.1.13 root 279: GetModuleFileName (NULL, mp, sizeof (mp));
280: bResult = TCCopyFile (mp, szTmp);
281: }
282: else
283: {
284: strncpy (curFileName, szFiles[i] + 1, strlen (szFiles[i]) - 1);
285: curFileName [strlen (szFiles[i]) - 1] = 0;
286:
287: if (Is64BitOs ()
288: && strcmp (szFiles[i], "Dtruecrypt.sys") == 0)
289: {
290: strncpy (curFileName, FILENAME_64BIT_DRIVER, sizeof (FILENAME_64BIT_DRIVER));
291: }
292:
293: if (!bDevm)
294: {
295: bResult = FALSE;
296:
297: // Find the correct decompressed file in memory
298: for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
299: {
300: // Write the file (stored in memory) directly to the destination location
301: // (there will be no temporary files).
302: if (memcmp (
303: curFileName,
304: Decompressed_Files[fileNo].fileName,
305: min (strlen (curFileName), (size_t) Decompressed_Files[fileNo].fileNameLength)) == 0)
306: {
307: bResult = SaveBufferToFile (
308: (char *) Decompressed_Files[fileNo].fileContent,
309: szTmp,
310: Decompressed_Files[fileNo].fileLength,
311: FALSE);
312:
313: break;
314: }
315: }
316: }
317: else
318: {
319: bResult = TCCopyFile (curFileName, szTmp);
320: }
1.1 root 321: }
322: }
323: else
324: {
325: bResult = StatDeleteFile (szTmp);
326: }
327:
328: if (bResult == FALSE)
329: {
330: LPVOID lpMsgBuf;
331: DWORD dwError = GetLastError ();
1.1.1.7 root 332: wchar_t szTmp2[700];
1.1 root 333:
334: FormatMessage (
335: FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
336: NULL,
337: dwError,
338: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
339: (char *) &lpMsgBuf,
340: 0,
341: NULL
342: );
343:
344:
345: if (bUninstall == FALSE)
1.1.1.7 root 346: wsprintfW (szTmp2, GetString ("INSTALL_OF_FAILED"), szTmp, lpMsgBuf);
1.1 root 347: else
1.1.1.7 root 348: wsprintfW (szTmp2, GetString ("UNINSTALL_OF_FAILED"), szTmp, lpMsgBuf);
1.1 root 349:
350: LocalFree (lpMsgBuf);
351:
1.1.1.11 root 352: if (!Silent && MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
1.1 root 353: return FALSE;
354: }
1.1.1.7 root 355: }
1.1 root 356:
1.1.1.7 root 357: // Language pack
358: if (bUninstall == FALSE)
359: {
360: WIN32_FIND_DATA f;
1.1.1.8 root 361: HANDLE h;
362:
363: SetCurrentDirectory (SetupFilesDir);
364: h = FindFirstFile ("Language.*.xml", &f);
365:
1.1.1.7 root 366: if (h != INVALID_HANDLE_VALUE)
367: {
368: char d[MAX_PATH*2];
1.1.1.11 root 369: sprintf (d, "%s%s", szDestDir, f.cFileName);
1.1.1.7 root 370: CopyMessage (hwndDlg, d);
371: TCCopyFile (f.cFileName, d);
372: FindClose (h);
373: }
1.1.1.8 root 374:
375: SetCurrentDirectory (SetupFilesDir);
376: SetCurrentDirectory ("Setup files");
377: h = FindFirstFile ("TrueCrypt User Guide.*.pdf", &f);
378: if (h != INVALID_HANDLE_VALUE)
379: {
380: char d[MAX_PATH*2];
1.1.1.11 root 381: sprintf (d, "%s%s", szDestDir, f.cFileName);
1.1.1.8 root 382: CopyMessage (hwndDlg, d);
383: TCCopyFile (f.cFileName, d);
384: FindClose (h);
385: }
386: SetCurrentDirectory (SetupFilesDir);
1.1 root 387: }
388:
389: return bOK;
390: }
391:
392: BOOL
1.1.1.11 root 393: DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType)
1.1 root 394: {
395: char szDir[TC_MAX_PATH], *key;
1.1.1.11 root 396: char szTmp[TC_MAX_PATH];
1.1 root 397: HKEY hkey = 0;
398: BOOL bSlash, bOK = FALSE;
399: DWORD dw;
400: int x;
401:
402: strcpy (szDir, szDestDir);
403: x = strlen (szDestDir);
404: if (szDestDir[x - 1] == '\\')
405: bSlash = TRUE;
406: else
407: bSlash = FALSE;
408:
409: if (bSlash == FALSE)
410: strcat (szDir, "\\");
411:
1.1.1.7 root 412: if (bInstallType)
1.1 root 413: {
414:
1.1.1.11 root 415: key = "Software\\Classes\\TrueCryptVolume";
1.1 root 416: RegMessage (hwndDlg, key);
417: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
418: key,
419: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
420: goto error;
421:
1.1.1.10 root 422: strcpy (szTmp, "TrueCrypt Volume");
1.1 root 423: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
424: goto error;
425:
426: RegCloseKey (hkey);
427: hkey = 0;
428:
1.1.1.11 root 429: key = "Software\\Classes\\TrueCryptVolume\\DefaultIcon";
1.1 root 430: RegMessage (hwndDlg, key);
431: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
432: key,
433: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
434: goto error;
435:
436: sprintf (szTmp, "%sTrueCrypt.exe,1", szDir);
437: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
438: goto error;
439:
440: RegCloseKey (hkey);
441: hkey = 0;
442:
1.1.1.11 root 443: key = "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command";
1.1 root 444: RegMessage (hwndDlg, key);
445: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
446: key,
447: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
448: goto error;
449:
450: sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir );
451: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
452: goto error;
453:
454: RegCloseKey (hkey);
455: hkey = 0;
456:
1.1.1.11 root 457: key = "Software\\Classes\\.tc";
1.1 root 458: RegMessage (hwndDlg, key);
459: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
460: key,
461: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
462: goto error;
463:
464: strcpy (szTmp, "TrueCryptVolume");
465: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
466: goto error;
1.1.1.11 root 467:
468: RegCloseKey (hkey);
469: hkey = 0;
1.1 root 470: }
471:
1.1.1.11 root 472: key = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt";
473: RegMessage (hwndDlg, key);
474: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
475: key,
476: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
477: goto error;
1.1 root 478:
1.1.1.13 root 479: /* IMPORTANT: IF YOU CHANGE THIS IN ANY WAY, REVISE AND UPDATE SetInstallationPath() ACCORDINGLY! */
480: sprintf (szTmp, "\"%sTrueCrypt Setup.exe\" /u", szDir);
1.1.1.11 root 481: if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
482: goto error;
1.1 root 483:
1.1.1.13 root 484: sprintf (szTmp, "\"%sTrueCrypt Setup.exe\" /c", szDir);
485: if (RegSetValueEx (hkey, "ModifyPath", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
486: goto error;
487:
1.1.1.11 root 488: sprintf (szTmp, "\"%sTrueCrypt Setup.exe\"", szDir);
489: if (RegSetValueEx (hkey, "DisplayIcon", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
490: goto error;
1.1 root 491:
1.1.1.13 root 492: strcpy (szTmp, VERSION_STRING);
493: if (RegSetValueEx (hkey, "DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
494: goto error;
495:
1.1.1.11 root 496: strcpy (szTmp, "TrueCrypt");
497: if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
498: goto error;
1.1 root 499:
1.1.1.11 root 500: strcpy (szTmp, "TrueCrypt Foundation");
501: if (RegSetValueEx (hkey, "Publisher", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
502: goto error;
1.1 root 503:
1.1.1.13 root 504: sprintf (szTmp, "%s&dest=index\n", TC_APPLINK);
1.1.1.11 root 505: if (RegSetValueEx (hkey, "URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS)
506: goto error;
507:
1.1 root 508: bOK = TRUE;
509:
1.1.1.11 root 510: error:
1.1 root 511: if (hkey != 0)
512: RegCloseKey (hkey);
513:
514: if (bOK == FALSE)
515: {
516: handleWin32Error (hwndDlg);
1.1.1.11 root 517: Error ("REG_INSTALL_FAILED");
518: }
519:
520: // Register COM servers for UAC
521: if (nCurrentOS == WIN_VISTA_OR_LATER)
522: {
523: if (!RegisterComServers (szDir))
524: {
525: Error ("COM_REG_FAILED");
526: return FALSE;
527: }
1.1 root 528: }
529:
530: return bOK;
531: }
532:
533: BOOL
1.1.1.7 root 534: DoApplicationDataUninstall (HWND hwndDlg)
535: {
536: char path[MAX_PATH];
537: char path2[MAX_PATH];
538: BOOL bOK = TRUE;
539:
540: StatusMessage (hwndDlg, "REMOVING_APPDATA");
541:
542: SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
543: strcat (path, "\\TrueCrypt\\");
544:
545: // Delete favorite volumes file
546: sprintf (path2, "%s%s", path, FILE_FAVORITE_VOLUMES);
547: RemoveMessage (hwndDlg, path2);
548: StatDeleteFile (path2);
549:
550: // Delete keyfile defaults
551: sprintf (path2, "%s%s", path, FILE_DEFAULT_KEYFILES);
552: RemoveMessage (hwndDlg, path2);
553: StatDeleteFile (path2);
554:
555: // Delete history file
556: sprintf (path2, "%s%s", path, FILE_HISTORY);
557: RemoveMessage (hwndDlg, path2);
558: StatDeleteFile (path2);
559:
560: // Delete configuration file
561: sprintf (path2, "%s%s", path, FILE_CONFIGURATION);
562: RemoveMessage (hwndDlg, path2);
563: StatDeleteFile (path2);
564:
1.1.1.13 root 565: // Delete system encryption configuration file
566: sprintf (path2, "%s%s", path, FILE_SYSTEM_ENCRYPTION_CFG);
567: RemoveMessage (hwndDlg, path2);
568: StatDeleteFile (path2);
569:
1.1.1.7 root 570: SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
571: strcat (path, "\\TrueCrypt");
572: RemoveMessage (hwndDlg, path);
573: if (!StatRemoveDirectory (path))
574: {
575: handleWin32Error (hwndDlg);
576: bOK = FALSE;
577: }
578:
579: return bOK;
580: }
581:
582: BOOL
583: DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated)
1.1 root 584: {
585: BOOL bOK = FALSE;
1.1.1.7 root 586: char regk [64];
1.1 root 587:
1.1.1.11 root 588: // Unregister COM servers
589: if (!bRemoveDeprecated && nCurrentOS == WIN_VISTA_OR_LATER)
590: {
1.1.1.13 root 591: if (!UnregisterComServers (InstallationPath))
1.1.1.11 root 592: StatusMessage (hwndDlg, "COM_DEREG_FAILED");
593: }
594:
595: if (!bRemoveDeprecated)
596: StatusMessage (hwndDlg, "REMOVING_REG");
1.1 root 597:
1.1.1.11 root 598: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt");
599: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command");
600: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open");
601: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell");
602: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\DefaultIcon");
603: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume");
604: RegDeleteKey (HKEY_CURRENT_USER, "Software\\TrueCrypt");
1.1.1.7 root 605:
606: if (!bRemoveDeprecated)
607: {
608: // Split the string in order to prevent some antivirus packages from falsely reporting
609: // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
610: sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
611: DeleteRegistryValue (regk, "TrueCrypt");
612:
1.1.1.11 root 613: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\.tc");
1.1.1.7 root 614: }
1.1 root 615:
616: bOK = TRUE;
617:
618: if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND
619: && GetLastError ()!= ERROR_PATH_NOT_FOUND)
620: {
621: handleWin32Error (hwndDlg);
622: }
623: else
624: bOK = TRUE;
625:
626: return bOK;
627: }
628:
1.1.1.11 root 629:
1.1 root 630: BOOL
631: DoServiceUninstall (HWND hwndDlg, char *lpszService)
632: {
633: SC_HANDLE hManager, hService = NULL;
634: BOOL bOK = FALSE, bRet;
635: SERVICE_STATUS status;
1.1.1.6 root 636: BOOL firstTry = TRUE;
1.1 root 637: int x;
638:
1.1.1.6 root 639: memset (&status, 0, sizeof (status)); /* Keep VC6 quiet */
640:
641: retry:
1.1 root 642:
643: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
644: if (hManager == NULL)
645: goto error;
646:
647: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
648: if (hService == NULL)
649: goto error;
650:
1.1.1.7 root 651: if (strcmp ("truecrypt", lpszService) == 0)
652: StatusMessage (hwndDlg, "STOPPING_DRIVER");
653: else
654: StatusMessageParam (hwndDlg, "STOPPING", lpszService);
1.1 root 655:
656: #define WAIT_PERIOD 3
657:
658: for (x = 0; x < WAIT_PERIOD; x++)
659: {
660: bRet = QueryServiceStatus (hService, &status);
661: if (bRet != TRUE)
662: goto error;
663:
664: if (status.dwCurrentState != SERVICE_START_PENDING &&
665: status.dwCurrentState != SERVICE_STOP_PENDING &&
666: status.dwCurrentState != SERVICE_CONTINUE_PENDING)
667: break;
668:
669: Sleep (1000);
670: }
671:
672: if (status.dwCurrentState != SERVICE_STOPPED)
673: {
674: bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
675: if (bRet == FALSE)
676: goto try_delete;
677:
678: for (x = 0; x < WAIT_PERIOD; x++)
679: {
680: bRet = QueryServiceStatus (hService, &status);
681: if (bRet != TRUE)
682: goto error;
683:
684: if (status.dwCurrentState != SERVICE_START_PENDING &&
685: status.dwCurrentState != SERVICE_STOP_PENDING &&
686: status.dwCurrentState != SERVICE_CONTINUE_PENDING)
687: break;
688:
689: Sleep (1000);
690: }
691:
692: if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
693: goto error;
694: }
695:
1.1.1.6 root 696: try_delete:
697:
1.1.1.7 root 698: if (strcmp ("truecrypt", lpszService) == 0)
699: StatusMessage (hwndDlg, "REMOVING_DRIVER");
700: else
701: StatusMessageParam (hwndDlg, "REMOVING", lpszService);
1.1 root 702:
703: if (hService != NULL)
704: CloseServiceHandle (hService);
705:
706: if (hManager != NULL)
707: CloseServiceHandle (hManager);
708:
709: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
710: if (hManager == NULL)
711: goto error;
712:
713: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
714: if (hService == NULL)
715: goto error;
716:
717: bRet = DeleteService (hService);
718: if (bRet == FALSE)
1.1.1.6 root 719: {
720: if (firstTry && GetLastError () == ERROR_SERVICE_MARKED_FOR_DELETE)
721: {
722: // Second try for an eventual no-install driver instance
723: CloseServiceHandle (hService);
724: CloseServiceHandle (hManager);
725:
726: Sleep(1000);
727: firstTry = FALSE;
728: goto retry;
729: }
730:
1.1 root 731: goto error;
1.1.1.6 root 732: }
1.1 root 733:
734: bOK = TRUE;
735:
1.1.1.6 root 736: error:
737:
1.1 root 738: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
739: {
740: handleWin32Error (hwndDlg);
1.1.1.7 root 741: MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1 root 742: }
743: else
744: bOK = TRUE;
745:
746: if (hService != NULL)
747: CloseServiceHandle (hService);
748:
749: if (hManager != NULL)
750: CloseServiceHandle (hManager);
751:
752: return bOK;
753: }
754:
1.1.1.7 root 755:
1.1 root 756: BOOL
757: DoDriverUnload (HWND hwndDlg)
758: {
759: BOOL bOK = TRUE;
760: int status;
761:
762: status = DriverAttach ();
763: if (status != 0)
764: {
1.1.1.11 root 765: if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND)
1.1 root 766: {
767: handleWin32Error (hwndDlg);
1.1.1.7 root 768: AbortProcess ("NODRIVER");
1.1 root 769: }
770:
771: if (status != ERR_OS_ERROR)
772: {
773: handleError (NULL, status);
1.1.1.7 root 774: AbortProcess ("NODRIVER");
1.1 root 775: }
776: }
777:
778: if (hDriver != INVALID_HANDLE_VALUE)
779: {
1.1.1.3 root 780: MOUNT_LIST_STRUCT driver;
1.1.1.11 root 781: LONG driverVersion = VERSION_NUM;
1.1.1.7 root 782: int refCount;
1.1.1.3 root 783: DWORD dwResult;
784: BOOL bResult;
1.1.1.13 root 785: int volumesMounted;
786:
1.1.1.14! root 787: // Try to determine if it's upgrade (and not reinstall, downgrade, or first-time install).
! 788: bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
! 789:
! 790: if (!bResult)
! 791: bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
! 792:
! 793: bUpgrade = bResult && driverVersion < VERSION_NUM;
! 794:
1.1.1.13 root 795: // Test for encrypted boot drive
796: try
797: {
798: BootEncryption bootEnc (hwndDlg);
799: if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
800: {
1.1.1.14! root 801: if (!bUpgrade || driverVersion < 0x500)
! 802: {
! 803: Error ("SETUP_FAILED_BOOT_DRIVE_ENCRYPTED");
! 804: return FALSE;
! 805: }
! 806:
! 807: SystemEncryptionUpgrade = TRUE;
1.1.1.13 root 808: }
809: }
810: catch (...) { }
1.1 root 811:
1.1.1.14! root 812: if (!SystemEncryptionUpgrade)
! 813: {
! 814: // Check mounted volumes
! 815: bResult = DeviceIoControl (hDriver, TC_IOCTL_IS_ANY_VOLUME_MOUNTED, NULL, 0, &volumesMounted, sizeof (volumesMounted), &dwResult, NULL);
1.1.1.13 root 816:
1.1.1.14! root 817: if (!bResult)
! 818: {
! 819: bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES, NULL, 0, &driver, sizeof (driver), &dwResult, NULL);
! 820: if (bResult)
! 821: volumesMounted = driver.ulMountedDrives;
! 822: }
1.1.1.13 root 823:
824: if (bResult)
1.1.1.14! root 825: {
! 826: if (volumesMounted != 0)
! 827: {
! 828: bOK = FALSE;
! 829: MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND);
! 830: }
! 831: }
! 832: else
1.1 root 833: {
834: bOK = FALSE;
1.1.1.14! root 835: handleWin32Error (hwndDlg);
1.1 root 836: }
837: }
1.1.1.14! root 838:
1.1.1.7 root 839: // Try to close all open TC windows
1.1.1.11 root 840: if (bOK)
1.1.1.7 root 841: {
842: BOOL TCWindowClosed = FALSE;
1.1.1.11 root 843:
1.1.1.7 root 844: EnumWindows (CloseTCWindowsEnum, (LPARAM) &TCWindowClosed);
1.1.1.11 root 845:
846: if (TCWindowClosed)
847: Sleep (2000);
1.1.1.7 root 848: }
849:
850: // Test for any applications attached to driver
1.1.1.13 root 851: bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount,
1.1.1.7 root 852: sizeof (refCount), &dwResult, NULL);
853:
854: if (bOK && bResult && refCount > 1)
855: {
856: MessageBoxW (hwndDlg, GetString ("CLOSE_TC_FIRST"), lpszTitle, MB_ICONSTOP);
857: bOK = FALSE;
858: }
1.1 root 859:
1.1.1.14! root 860: if (!bOK || !SystemEncryptionUpgrade)
! 861: {
! 862: CloseHandle (hDriver);
! 863: hDriver = INVALID_HANDLE_VALUE;
! 864: }
1.1 root 865: }
1.1.1.11 root 866: else
867: {
868: bFirstTimeInstall = TRUE;
869: }
1.1 root 870:
871: return bOK;
872: }
873:
874:
875: BOOL
876: DoDriverInstall (HWND hwndDlg)
877: {
1.1.1.14! root 878: if (SystemEncryptionUpgrade)
! 879: return TRUE;
! 880:
1.1 root 881: SC_HANDLE hManager, hService = NULL;
1.1.1.11 root 882: BOOL bOK = FALSE, bRet;
1.1 root 883:
884: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
885: if (hManager == NULL)
886: goto error;
887:
1.1.1.7 root 888: StatusMessage (hwndDlg, "INSTALLING_DRIVER");
1.1 root 889:
890: hService = CreateService (hManager, "truecrypt", "truecrypt",
1.1.1.11 root 891: SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_SYSTEM_START, SERVICE_ERROR_NORMAL,
892: !Is64BitOs () ? "System32\\drivers\\truecrypt.sys" : "SysWOW64\\drivers\\truecrypt.sys",
893: NULL, NULL, NULL, NULL, NULL);
894:
1.1 root 895: if (hService == NULL)
896: goto error;
897: else
898: CloseServiceHandle (hService);
899:
900: hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS);
901: if (hService == NULL)
902: goto error;
903:
1.1.1.7 root 904: StatusMessage (hwndDlg, "STARTING_DRIVER");
1.1 root 905:
906: bRet = StartService (hService, 0, NULL);
907: if (bRet == FALSE)
908: goto error;
909:
910: bOK = TRUE;
911:
1.1.1.11 root 912: error:
913: if (bOK == FALSE && GetLastError () != ERROR_SERVICE_ALREADY_RUNNING)
1.1 root 914: {
915: handleWin32Error (hwndDlg);
1.1.1.7 root 916: MessageBoxW (hwndDlg, GetString ("DRIVER_INSTALL_FAILED"), lpszTitle, MB_ICONHAND);
1.1 root 917: }
918: else
919: bOK = TRUE;
920:
921: if (hService != NULL)
922: CloseServiceHandle (hService);
923:
924: if (hManager != NULL)
925: CloseServiceHandle (hManager);
926:
927: return bOK;
928: }
929:
1.1.1.14! root 930:
! 931: BOOL UpgradeBootLoader (HWND hwndDlg)
! 932: {
! 933: if (!SystemEncryptionUpgrade)
! 934: return TRUE;
! 935:
! 936: try
! 937: {
! 938: BootEncryption bootEnc (hwndDlg);
! 939: if (bootEnc.GetInstalledBootLoaderVersion() < VERSION_NUM)
! 940: {
! 941: bootEnc.InstallBootLoader ();
! 942: Info ("BOOT_LOADER_UPGRADE_OK");
! 943: }
! 944: return TRUE;
! 945: }
! 946: catch (Exception &e)
! 947: {
! 948: e.Show (hwndDlg);
! 949: }
! 950: catch (...) { }
! 951:
! 952: Error ("BOOT_LOADER_UPGRADE_FAILED");
! 953: return FALSE;
! 954: }
! 955:
! 956:
1.1 root 957: BOOL
958: DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
959: {
1.1.1.11 root 960: char szLinkDir[TC_MAX_PATH];
1.1.1.7 root 961: char szTmp2[TC_MAX_PATH];
1.1 root 962: BOOL bSlash, bOK = FALSE;
963: HRESULT hOle;
964: int x;
965: BOOL allUsers = FALSE;
966:
967: hOle = OleInitialize (NULL);
968:
969: // User start menu
970: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
971: x = strlen (szLinkDir);
972: if (szLinkDir[x - 1] == '\\')
973: bSlash = TRUE;
974: else
975: bSlash = FALSE;
976:
977: if (bSlash == FALSE)
978: strcat (szLinkDir, "\\");
979:
980: strcat (szLinkDir, "TrueCrypt");
981:
982: // Global start menu
983: {
984: struct _stat st;
985: char path[TC_MAX_PATH];
986:
987: SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
988: strcat (path, "\\TrueCrypt");
989:
990: if (_stat (path, &st) == 0)
991: {
992: strcpy (szLinkDir, path);
993: allUsers = TRUE;
994: }
995: }
996:
997: // Start menu entries
998: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
999: RemoveMessage (hwndDlg, szTmp2);
1000: if (StatDeleteFile (szTmp2) == FALSE)
1001: goto error;
1002:
1.1.1.11 root 1003: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
1.1 root 1004: RemoveMessage (hwndDlg, szTmp2);
1005: if (StatDeleteFile (szTmp2) == FALSE)
1006: goto error;
1007:
1008: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1009: RemoveMessage (hwndDlg, szTmp2);
1010: if (StatDeleteFile (szTmp2) == FALSE)
1011: goto error;
1.1.1.11 root 1012:
1013: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
1014: DeleteFile (szTmp2);
1.1 root 1015:
1016: // Start menu group
1017: RemoveMessage ((HWND) hwndDlg, szLinkDir);
1018: if (StatRemoveDirectory (szLinkDir) == FALSE)
1019: handleWin32Error ((HWND) hwndDlg);
1020:
1021: // Desktop icon
1022:
1023: if (allUsers)
1024: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
1025: else
1026: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
1027:
1028: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1029:
1030: RemoveMessage (hwndDlg, szTmp2);
1031: if (StatDeleteFile (szTmp2) == FALSE)
1032: goto error;
1033:
1034: bOK = TRUE;
1035:
1036: error:
1037: OleUninitialize ();
1038:
1039: return bOK;
1040: }
1041:
1042: BOOL
1043: DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
1044: {
1045: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
1.1.1.7 root 1046: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH];
1.1 root 1047: BOOL bSlash, bOK = FALSE;
1048: HRESULT hOle;
1049: int x;
1050:
1051: if (bProgGroup == FALSE && bDesktopIcon == FALSE)
1052: return TRUE;
1053:
1054: hOle = OleInitialize (NULL);
1055:
1056: GetProgramPath (hwndDlg, szLinkDir);
1057:
1058: x = strlen (szLinkDir);
1059: if (szLinkDir[x - 1] == '\\')
1060: bSlash = TRUE;
1061: else
1062: bSlash = FALSE;
1063:
1064: if (bSlash == FALSE)
1065: strcat (szLinkDir, "\\");
1066:
1067: strcat (szLinkDir, "TrueCrypt");
1068:
1069: strcpy (szDir, szDestDir);
1070: x = strlen (szDestDir);
1071: if (szDestDir[x - 1] == '\\')
1072: bSlash = TRUE;
1073: else
1074: bSlash = FALSE;
1075:
1076: if (bSlash == FALSE)
1077: strcat (szDir, "\\");
1078:
1079: if (bProgGroup)
1080: {
1.1.1.11 root 1081: FILE *f;
1082:
1.1 root 1083: if (mkfulldir (szLinkDir, TRUE) != 0)
1084: {
1085: if (mkfulldir (szLinkDir, FALSE) != 0)
1086: {
1.1.1.13 root 1087: wchar_t szTmp[TC_MAX_PATH];
1088:
1.1 root 1089: handleWin32Error (hwndDlg);
1.1.1.7 root 1090: wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szLinkDir);
1091: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1.1 root 1092: goto error;
1093: }
1094: }
1095:
1096: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
1097: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1098:
1099: IconMessage (hwndDlg, szTmp2);
1100: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1101: goto error;
1102:
1.1.1.11 root 1103: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
1.1 root 1104: IconMessage (hwndDlg, szTmp2);
1.1.1.11 root 1105: f = fopen (szTmp2, "w");
1106: if (f)
1107: {
1108: fprintf (f, "[InternetShortcut]\nURL=%s&dest=index\n", TC_APPLINK);
1109: fclose (f);
1110: }
1.1 root 1111: else
1.1.1.11 root 1112: goto error;
1.1 root 1113:
1114: sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
1115: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1.1.1.13 root 1116: strcpy (szTmp3, "/u");
1.1 root 1117:
1118: IconMessage (hwndDlg, szTmp2);
1.1.1.7 root 1119: if (CreateLink (szTmp, szTmp3, szTmp2) != S_OK)
1.1 root 1120: goto error;
1121:
1.1.1.11 root 1122: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
1123: DeleteFile (szTmp2);
1.1 root 1124: }
1125:
1126: if (bDesktopIcon)
1127: {
1128: strcpy (szDir, szDestDir);
1129: x = strlen (szDestDir);
1130: if (szDestDir[x - 1] == '\\')
1131: bSlash = TRUE;
1132: else
1133: bSlash = FALSE;
1134:
1135: if (bSlash == FALSE)
1136: strcat (szDir, "\\");
1137:
1.1.1.13 root 1138: if (bForAllUsers)
1.1 root 1139: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
1140: else
1141: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
1142:
1143: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
1144: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1145:
1146: IconMessage (hwndDlg, szTmp2);
1147:
1148: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1149: goto error;
1150: }
1151:
1152: bOK = TRUE;
1153:
1154: error:
1155: OleUninitialize ();
1156:
1157: return bOK;
1158: }
1159:
1160:
1161: void
1.1.1.11 root 1162: OutcomePrompt (HWND hwndDlg, BOOL bOK)
1.1 root 1163: {
1.1.1.7 root 1164: if (bOK)
1.1 root 1165: {
1166: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
1167:
1168: bDone = TRUE;
1169:
1.1.1.7 root 1170: if (bUninstall == FALSE)
1.1.1.13 root 1171: {
1172: if (bDevm)
1173: PostMessage (MainDlg, WM_CLOSE, 0, 0);
1.1.1.14! root 1174: else if (!SystemEncryptionUpgrade)
1.1.1.13 root 1175: Info ("INSTALL_OK");
1176: }
1.1 root 1177: else
1.1.1.11 root 1178: {
1179: wchar_t str[4096];
1180:
1.1.1.13 root 1181: swprintf (str, GetString ("UNINSTALL_OK"), InstallationPath);
1.1.1.11 root 1182: MessageBoxW (hwndDlg, str, lpszTitle, MB_ICONASTERISK);
1183: }
1.1 root 1184: }
1185: else
1186: {
1187: if (bUninstall == FALSE)
1.1.1.11 root 1188: Error ("INSTALL_FAILED");
1.1 root 1189: else
1.1.1.11 root 1190: Error ("UNINSTALL_FAILED");
1.1 root 1191: }
1192: }
1193:
1.1.1.13 root 1194: static void SetSystemRestorePoint (HWND hwndDlg, BOOL finalize)
1.1 root 1195: {
1196: static RESTOREPOINTINFO RestPtInfo;
1197: static STATEMGRSTATUS SMgrStatus;
1198: static BOOL failed = FALSE;
1199: static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
1200:
1201: if (!SystemRestoreDll) return;
1202:
1203: _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
1204: if (_SRSetRestorePoint == 0)
1205: {
1206: FreeLibrary (SystemRestoreDll);
1207: SystemRestoreDll = 0;
1208: return;
1209: }
1210:
1211: if (!finalize)
1212: {
1.1.1.7 root 1213: StatusMessage (hwndDlg, "CREATING_SYS_RESTORE");
1.1 root 1214:
1215: RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
1216: RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
1217: RestPtInfo.llSequenceNumber = 0;
1.1.1.13 root 1218: strcpy (RestPtInfo.szDescription, bUninstall ? "TrueCrypt uninstallation" : "TrueCrypt installation");
1.1 root 1219:
1.1.1.7 root 1220: if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus))
1.1 root 1221: {
1.1.1.7 root 1222: StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
1.1 root 1223: failed = TRUE;
1224: }
1225: }
1.1.1.11 root 1226: else if (!failed)
1.1 root 1227: {
1.1.1.11 root 1228: RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
1229: RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
1230:
1231: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
1232: {
1233: StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
1234: }
1235: else
1236: StatusMessage (hwndDlg, "SYS_RESTORE_CREATED");
1.1 root 1237: }
1238: }
1239:
1240: void
1.1.1.13 root 1241: DoUninstall (void *arg)
1.1 root 1242: {
1.1.1.13 root 1243: HWND hwndDlg = (HWND) arg;
1.1 root 1244: BOOL bOK = TRUE;
1.1.1.13 root 1245: BOOL bTempSkipSysRestore = FALSE;
1.1 root 1246:
1.1.1.11 root 1247: if (!Rollback)
1248: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE);
1.1 root 1249:
1250: WaitCursor ();
1251:
1.1.1.11 root 1252: if (!Rollback)
1.1 root 1253: {
1.1.1.13 root 1254: ClearLogWindow (hwndDlg);
1.1 root 1255: }
1.1.1.13 root 1256:
1257: if (DoDriverUnload (hwndDlg) == FALSE)
1.1.1.7 root 1258: {
1259: bOK = FALSE;
1.1.1.13 root 1260: bTempSkipSysRestore = TRUE; // Volumes are possibly mounted; defer System Restore point creation for this uninstall attempt.
1.1.1.7 root 1261: }
1.1 root 1262: else
1263: {
1.1.1.13 root 1264: if (!Rollback && bSystemRestore && !bTempSkipSysRestore)
1265: SetSystemRestorePoint (hwndDlg, FALSE);
1.1.1.11 root 1266:
1.1.1.13 root 1267: if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1268: {
1.1.1.11 root 1269: bOK = FALSE;
1.1.1.13 root 1270: }
1271: else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE)
1272: {
1273: bOK = FALSE;
1274: }
1275: else if (DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
1276: {
1277: bOK = FALSE;
1278: }
1279: else if (DoShortcutsUninstall (hwndDlg, InstallationPath) == FALSE)
1280: {
1281: bOK = FALSE;
1282: }
1283: else if (!DoApplicationDataUninstall (hwndDlg))
1284: {
1285: bOK = FALSE;
1286: }
1.1.1.11 root 1287: else
1.1 root 1288: {
1.1.1.13 root 1289: char temp[MAX_PATH];
1290: FILE *f;
1291:
1292: // Deprecated service
1293: DoServiceUninstall (hwndDlg, "TrueCryptService");
1294:
1295: GetTempPath (sizeof (temp), temp);
1296: _snprintf (UninstallBatch, sizeof (UninstallBatch), "%s\\TrueCrypt-Uninstall.bat", temp);
1297:
1298: // Create uninstall batch
1299: f = fopen (UninstallBatch, "w");
1300: if (!f)
1301: bOK = FALSE;
1302: else
1303: {
1304: fprintf (f, ":loop\n"
1305: "del \"%s%s\"\n"
1306: "if exist \"%s%s\" goto loop\n"
1307: "rmdir \"%s\"\n"
1308: "del \"%s\"",
1309: InstallationPath, "TrueCrypt Setup.exe",
1310: InstallationPath, "TrueCrypt Setup.exe",
1311: InstallationPath,
1312: UninstallBatch
1313: );
1314: fclose (f);
1315: }
1.1 root 1316: }
1317: }
1318:
1319: NormalCursor ();
1320:
1.1.1.11 root 1321: if (Rollback)
1322: return;
1323:
1.1.1.13 root 1324: if (bSystemRestore && !bTempSkipSysRestore)
1325: SetSystemRestorePoint (hwndDlg, TRUE);
1326:
1.1.1.7 root 1327: if (bOK)
1.1.1.13 root 1328: PostMessage (hwndDlg, TC_APPMSG_UNINSTALL_SUCCESS, 0, 0);
1329: else
1330: bUninstallInProgress = FALSE;
1331:
1.1.1.7 root 1332: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE);
1.1.1.11 root 1333: OutcomePrompt (hwndDlg, bOK);
1.1 root 1334: }
1335:
1336: void
1.1.1.13 root 1337: DoInstall (void *arg)
1.1 root 1338: {
1.1.1.13 root 1339: HWND hwndDlg = (HWND) arg;
1.1 root 1340: BOOL bOK = TRUE;
1.1.1.11 root 1341: char path[MAX_PATH];
1.1 root 1342:
1.1.1.13 root 1343: // Refresh the main GUI (wizard thread)
1344: InvalidateRect (GetDlgItem (MainDlg, IDD_INSTL_DLG), NULL, TRUE);
1345:
1346: ClearLogWindow(hwndDlg);
1347:
1348: if (mkfulldir (InstallationPath, TRUE) != 0)
1349: {
1350: if (mkfulldir (InstallationPath, FALSE) != 0)
1351: {
1352: wchar_t szTmp[TC_MAX_PATH];
1353:
1354: handleWin32Error (hwndDlg);
1355: wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), InstallationPath);
1356: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1357: Error ("INSTALL_FAILED");
1358: PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
1359: return;
1360: }
1361: }
1362:
1363: UpdateProgressBarProc(2);
1.1 root 1364:
1365: if (DoDriverUnload (hwndDlg) == FALSE)
1366: {
1.1.1.4 root 1367: NormalCursor ();
1.1.1.13 root 1368: PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
1.1.1.4 root 1369: return;
1.1 root 1370: }
1.1.1.13 root 1371:
1372: UpdateProgressBarProc(12);
1.1.1.4 root 1373:
1.1.1.13 root 1374: if (bSystemRestore)
1.1.1.4 root 1375: SetSystemRestorePoint (hwndDlg, FALSE);
1376:
1.1.1.13 root 1377: UpdateProgressBarProc(50);
1378:
1.1.1.11 root 1379: // Remove deprecated
1.1.1.7 root 1380: DoServiceUninstall (hwndDlg, "TrueCryptService");
1.1.1.11 root 1381:
1.1.1.13 root 1382: UpdateProgressBarProc(55);
1383:
1.1.1.14! root 1384: if (!SystemEncryptionUpgrade)
! 1385: DoRegUninstall ((HWND) hwndDlg, TRUE);
1.1.1.7 root 1386:
1.1.1.13 root 1387: UpdateProgressBarProc(62);
1388:
1.1.1.11 root 1389: GetWindowsDirectory (path, sizeof (path));
1390: strcat_s (path, sizeof (path), "\\TrueCrypt Setup.exe");
1391: DeleteFile (path);
1392:
1.1.1.14! root 1393: if (UpdateProgressBarProc(63) && !SystemEncryptionUpgrade && DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1.1 root 1394: {
1395: bOK = FALSE;
1396: }
1.1.1.13 root 1397: else if (UpdateProgressBarProc(72) && DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
1.1 root 1398: {
1399: bOK = FALSE;
1400: }
1.1.1.14! root 1401: else if (UpdateProgressBarProc(80) && !SystemEncryptionUpgrade && DoRegInstall ((HWND) hwndDlg, InstallationPath, bRegisterFileExt ) == FALSE)
1.1 root 1402: {
1403: bOK = FALSE;
1404: }
1.1.1.14! root 1405: else if (UpdateProgressBarProc(85) && !SystemEncryptionUpgrade && DoDriverInstall (hwndDlg) == FALSE)
! 1406: {
! 1407: bOK = FALSE;
! 1408: }
! 1409: else if (SystemEncryptionUpgrade && UpgradeBootLoader (hwndDlg) == FALSE)
1.1 root 1410: {
1411: bOK = FALSE;
1412: }
1.1.1.13 root 1413: else if (UpdateProgressBarProc(93) && DoShortcutsInstall (hwndDlg, InstallationPath, bAddToStartMenu, bDesktopIcon) == FALSE)
1.1 root 1414: {
1415: bOK = FALSE;
1416: }
1417:
1.1.1.13 root 1418: if (bOK)
1419: UpdateProgressBarProc(97);
1420:
1421: if (bSystemRestore)
1.1 root 1422: SetSystemRestorePoint (hwndDlg, TRUE);
1423:
1.1.1.7 root 1424: if (bOK)
1425: {
1.1.1.13 root 1426: UpdateProgressBarProc(100);
1.1.1.11 root 1427: UninstallBatch[0] = 0;
1.1.1.7 root 1428: StatusMessage (hwndDlg, "INSTALL_COMPLETED");
1.1.1.13 root 1429: PostMessage (MainDlg, TC_APPMSG_INSTALL_SUCCESS, 0, 0);
1.1.1.11 root 1430: }
1431: else
1432: {
1.1.1.13 root 1433: UpdateProgressBarProc(0);
1.1.1.11 root 1434: bUninstall = TRUE;
1435: Rollback = TRUE;
1436: Silent = TRUE;
1437:
1.1.1.14! root 1438: if (!SystemEncryptionUpgrade)
! 1439: DoUninstall (hwndDlg);
1.1.1.11 root 1440:
1441: bUninstall = FALSE;
1442: Rollback = FALSE;
1443: Silent = FALSE;
1444:
1445: StatusMessage (hwndDlg, "ROLLBACK");
1.1.1.7 root 1446: }
1.1 root 1447:
1.1.1.11 root 1448: OutcomePrompt (hwndDlg, bOK);
1449:
1.1.1.13 root 1450: if (!bOK)
1451: {
1452: PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
1453: }
1454: else if (!bUninstall && !bDevm)
1.1.1.11 root 1455: {
1.1.1.14! root 1456: if (SystemEncryptionUpgrade)
1.1.1.11 root 1457: {
1.1.1.14! root 1458: if (AskYesNo ("UPGRADE_OK_REBOOT_REQUIRED") == IDYES)
! 1459: {
! 1460: BootEncryption bootEnc (hwndDlg);
! 1461: bootEnc.RestartComputer();
! 1462: }
1.1.1.11 root 1463: }
1.1.1.14! root 1464: else
1.1.1.11 root 1465: {
1.1.1.14! root 1466: if (bUpgrade && (AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES") == IDYES))
! 1467: {
! 1468: Applink ("releasenotes", TRUE, "");
! 1469: }
! 1470: else if (bFirstTimeInstall && AskYesNo ("AFTER_INSTALL_TUTORIAL") == IDYES)
! 1471: {
! 1472: Applink ("beginnerstutorial", TRUE, "");
! 1473: }
1.1.1.11 root 1474: }
1475: }
1.1 root 1476: }
1477:
1478:
1.1.1.13 root 1479: void SetInstallationPath (HWND hwndDlg)
1480: {
1481: HKEY hkey;
1482: BOOL bInstallPathDetermined = FALSE;
1483: char path[MAX_PATH+20];
1484: ITEMIDLIST *itemList;
1485:
1486: memset (InstallationPath, 0, sizeof (InstallationPath));
1487:
1488: // Determine if TrueCrypt is already installed and try to determine its "Program Files" location
1489: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
1490: {
1491: /* Default 'UninstallString' registry strings written by past versions of TrueCrypt:
1492: ------------------------------------------------------------------------------------
1493: 1.0 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1494: 1.0a C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1495: 2.0 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1496: 2.1 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1497: 2.1a C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1498: 3.0 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1499: 3.0a C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1500: 3.1 The UninstallString was NEVER written (fortunately, 3.1a replaced 3.1 after 2 weeks)
1501: 3.1a C:\WINDOWS\TrueCrypt Setup.exe /u
1502: 4.0 C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
1503: 4.1 C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
1504: 4.2 C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
1505: 4.2a C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
1506: 4.3 "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
1507: 4.3a "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
1508: 5.0 "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u
1509:
1510: Note: In versions 1.0-3.0a the user was able to choose whether to install the uninstaller.
1511: The default was to install it. If it wasn't installed, there was no UninstallString.
1512: */
1513:
1514: char rv[MAX_PATH*4];
1515: DWORD size = sizeof (rv);
1516: if (RegQueryValueEx (hkey, "UninstallString", 0, 0, (LPBYTE) &rv, &size) == ERROR_SUCCESS)
1517: {
1518: size_t len = 0;
1519:
1520: // Cut and paste the location (path) where TrueCrypt is installed to InstallationPath
1521: if (rv[0] == '"')
1522: {
1523: // 4.3 or later
1524:
1525: len = strrchr (rv, '/') - rv - 2;
1526: strncpy (InstallationPath, rv + 1, len);
1527: InstallationPath [len] = 0;
1528: bInstallPathDetermined = TRUE;
1529:
1530: if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
1531: {
1532: len = strrchr (InstallationPath, '\\') - InstallationPath;
1533: InstallationPath [len] = 0;
1534: }
1535: }
1536: else
1537: {
1538: // 1.0-4.2a (except 3.1)
1539:
1540: len = strrchr (rv, '/') - rv;
1541: if (rv[len+2] == ' ')
1542: {
1543: // 4.0-4.2a
1544:
1545: strncpy (InstallationPath, rv + len + 3, strlen (rv) - len - 3);
1546: InstallationPath [strlen (rv) - len - 3] = 0;
1547: bInstallPathDetermined = TRUE;
1548: }
1549: else
1550: {
1551: // 1.0-3.1a (except 3.1)
1552:
1553: // We know that TrueCrypt is installed but don't know where. It's not safe to continue installing
1554: // over the old version.
1555:
1556: Error ("UNINSTALL_OLD_VERSION_FIRST");
1557:
1558: len = strrchr (rv, '/') - rv - 1;
1559: strncpy (InstallationPath, rv, len); // Path and filename of the uninstaller
1560: InstallationPath [len] = 0;
1561: bInstallPathDetermined = FALSE;
1562:
1563: ShellExecute (NULL, "open", InstallationPath, "/u", NULL, SW_SHOWNORMAL);
1564: RegCloseKey (hkey);
1565: cleanup ();
1566: exit (1);
1567: }
1568: }
1569:
1570: }
1571: RegCloseKey (hkey);
1572: }
1573:
1574: if (bInstallPathDetermined)
1575: {
1576: char mp[MAX_PATH];
1577:
1578: // Determine whether we were launched from the folder where TrueCrypt is installed
1579: GetModuleFileName (NULL, mp, sizeof (mp));
1580: if (strncmp (InstallationPath, mp, min (strlen(InstallationPath), strlen(mp))) == 0)
1581: {
1582: // We were launched from the folder where TrueCrypt is installed
1583:
1584: if (!IsNonInstallMode() && !bDevm)
1585: bChangeMode = TRUE;
1586: }
1587: }
1588: else
1589: {
1590: /* TrueCypt is not installed or it wasn't possible to determine where it is installed. */
1591:
1592: // Default "Program Files" path.
1593: SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &itemList);
1594: SHGetPathFromIDList (itemList, path);
1595: strcat (path, "\\TrueCrypt\\");
1596: strcpy (InstallationPath, path);
1597: }
1598:
1599: // Make sure the path ends with a backslash
1600: if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
1601: {
1602: strcat (InstallationPath, "\\");
1603: }
1604: }
1605:
1606:
1607: // Handler for uninstall only (install is handled by the wizard)
1.1.1.12 root 1608: BOOL CALLBACK
1.1.1.13 root 1609: UninstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1 root 1610: {
1611: WORD lw = LOWORD (wParam);
1612:
1613: switch (msg)
1614: {
1615: case WM_INITDIALOG:
1.1.1.7 root 1616: MainDlg = hwndDlg;
1.1 root 1617: InitDialog (hwndDlg);
1.1.1.7 root 1618: LocalizeDialog (hwndDlg, NULL);
1.1 root 1619:
1.1.1.13 root 1620: SetWindowTextW (hwndDlg, lpszTitle);
1.1 root 1621:
1.1.1.13 root 1622: // System Restore
1623: SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
1624: if (SystemRestoreDll == 0)
1.1 root 1625: {
1.1.1.13 root 1626: SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
1627: EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
1.1 root 1628: }
1629:
1.1.1.13 root 1630: SetFocus (GetDlgItem (hwndDlg, IDC_UNINSTALL));
1.1.1.11 root 1631:
1.1 root 1632: return 1;
1633:
1634: case WM_SYSCOMMAND:
1635: if (lw == IDC_ABOUT)
1636: {
1.1.1.7 root 1637: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 1638: return 1;
1639: }
1640: return 0;
1641:
1642: case WM_COMMAND:
1.1.1.13 root 1643: if (lw == IDC_UNINSTALL)
1.1 root 1644: {
1.1.1.7 root 1645: if (bDone)
1.1 root 1646: {
1.1.1.13 root 1647: bUninstallInProgress = FALSE;
1648: PostMessage (hwndDlg, WM_CLOSE, 0, 0);
1.1 root 1649: return 1;
1650: }
1651:
1.1.1.13 root 1652: bUninstallInProgress = TRUE;
1.1 root 1653:
1.1.1.11 root 1654: WaitCursor ();
1655:
1.1.1.13 root 1656: if (bUninstall)
1.1 root 1657: _beginthread (DoUninstall, 16384, (void *) hwndDlg);
1658:
1659: return 1;
1660: }
1661:
1.1.1.13 root 1662: if (lw == IDC_SYSTEM_RESTORE)
1.1 root 1663: {
1.1.1.13 root 1664: bSystemRestore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE));
1.1 root 1665: return 1;
1666: }
1667:
1.1.1.13 root 1668: if (lw == IDCANCEL)
1.1 root 1669: {
1.1.1.13 root 1670: PostMessage (hwndDlg, WM_CLOSE, 0, 0);
1.1 root 1671: return 1;
1672: }
1673:
1674: return 0;
1675:
1.1.1.13 root 1676: case TC_APPMSG_UNINSTALL_SUCCESS:
1.1.1.11 root 1677: SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("FINALIZE"));
1678: NormalCursor ();
1.1.1.13 root 1679: return 1;
1.1.1.7 root 1680:
1.1 root 1681: case WM_CLOSE:
1.1.1.13 root 1682: if (bUninstallInProgress)
1683: {
1684: NormalCursor();
1685: if (AskNoYes("CONFIRM_EXIT_UNIVERSAL") == IDNO)
1686: {
1687: return 1;
1688: }
1689: WaitCursor ();
1690: }
1.1 root 1691: EndDialog (hwndDlg, IDCANCEL);
1692: return 1;
1693: }
1694:
1695: return 0;
1696: }
1697:
1698:
1699: int WINAPI
1700: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
1701: int nCmdShow)
1702: {
1.1.1.13 root 1703: SelfExtractStartupInit();
1.1 root 1704:
1.1.1.7 root 1705: lpszTitle = L"TrueCrypt Setup";
1.1 root 1706:
1707: /* Call InitApp to initialize the common code */
1.1.1.11 root 1708: InitApp (hInstance, NULL);
1.1 root 1709:
1.1.1.7 root 1710: if (IsAdmin () != TRUE)
1711: if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
1.1.1.13 root 1712: {
1713: cleanup ();
1.1.1.11 root 1714: exit (1);
1.1.1.13 root 1715: }
1.1 root 1716:
1.1.1.8 root 1717: /* Setup directory */
1718: {
1719: char *s;
1720: GetModuleFileName (NULL, SetupFilesDir, sizeof (SetupFilesDir));
1721: s = strrchr (SetupFilesDir, '\\');
1722: if (s)
1723: s[1] = 0;
1724: }
1725:
1.1.1.13 root 1726: /* Parse command line arguments */
1727:
1728: if (lpszCommandLine[0] == '/')
1.1 root 1729: {
1.1.1.13 root 1730: if (lpszCommandLine[1] == 'u')
1731: {
1732: // Uninstall: /u
1733:
1734: bUninstall = TRUE;
1735: }
1736: else if (lpszCommandLine[1] == 'c')
1737: {
1738: // Change: /c
1.1 root 1739:
1.1.1.13 root 1740: bChangeMode = TRUE;
1741: }
1742: else if (lpszCommandLine[1] == 'p')
1743: {
1744: // Create self-extracting package: /p
1745:
1746: bMakePackage = TRUE;
1747: }
1748: else if (lpszCommandLine[1] == 'd')
1749: {
1750: // Dev mode: /d
1751: bDevm = TRUE;
1752: }
1753: }
1754:
1755: if (bMakePackage)
1.1.1.11 root 1756: {
1.1.1.13 root 1757: /* Create self-extracting package */
1.1.1.11 root 1758:
1.1.1.13 root 1759: MakeSelfExtractingPackage (NULL, SetupFilesDir);
1760: }
1761: else
1762: {
1763: SetInstallationPath (NULL);
1.1.1.11 root 1764:
1.1.1.13 root 1765: if (!bUninstall)
1.1.1.11 root 1766: {
1.1.1.13 root 1767: if (IsSelfExtractingPackage())
1.1.1.11 root 1768: {
1.1.1.13 root 1769: if (!VerifyPackageIntegrity())
1.1.1.12 root 1770: {
1.1.1.13 root 1771: // Package corrupted
1772: cleanup ();
1773: exit (1);
1.1.1.12 root 1774: }
1.1.1.13 root 1775: bDevm = FALSE;
1.1.1.11 root 1776: }
1.1.1.13 root 1777: else if (!bDevm)
1.1.1.11 root 1778: {
1.1.1.13 root 1779: MessageBox (NULL, "Error: This installer file does not contain any compressed files.\n\nTo create a self-extracting installer package (with embedded compressed files), run 'TrueCrypt Setup.exe /p'.", "TrueCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
1780: cleanup ();
1.1.1.12 root 1781: exit (1);
1.1.1.11 root 1782: }
1.1.1.13 root 1783:
1784: if (bChangeMode)
1785: {
1786: /* TrueCrypt is already installed on this system and we were launched from the Program Files folder */
1787:
1788: char *tmpStr[] = {0, "SELECT_AN_ACTION", "REPAIR_REINSTALL", "UNINSTALL", "EXIT", 0};
1789:
1790: // Ask the user to select either Repair or Unistallation
1791: switch (AskMultiChoice ((void **) tmpStr))
1792: {
1793: case 1:
1794: bRepairMode = TRUE;
1795: break;
1796: case 2:
1797: bUninstall = TRUE;
1798: break;
1799: default:
1800: cleanup ();
1801: exit (1);
1802: }
1803: }
1.1.1.11 root 1804: }
1805:
1.1.1.13 root 1806: // System Restore
1807: SystemRestoreDll = LoadLibrary ("srclient.dll");
1808:
1809: if (!bUninstall)
1.1.1.11 root 1810: {
1.1.1.13 root 1811: /* Create the main dialog for install */
1.1.1.11 root 1812:
1.1.1.13 root 1813: DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTL_DLG), NULL, (DLGPROC) MainDialogProc,
1814: (LPARAM)lpszCommandLine);
1815: }
1816: else
1817: {
1818: /* Create the main dialog for uninstall */
1819:
1820: DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) UninstallDlgProc);
1.1.1.11 root 1821:
1.1.1.13 root 1822: if (UninstallBatch[0])
1823: {
1824: STARTUPINFO si;
1825: PROCESS_INFORMATION pi;
1826:
1827: ZeroMemory (&si, sizeof (si));
1828: si.cb = sizeof (si);
1829: si.dwFlags = STARTF_USESHOWWINDOW;
1830: si.wShowWindow = SW_HIDE;
1831:
1832: if (!CreateProcess (UninstallBatch, NULL, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi))
1833: DeleteFile (UninstallBatch);
1834: }
1.1.1.11 root 1835: }
1.1 root 1836: }
1837:
1838: /* Terminate */
1.1.1.10 root 1839: cleanup ();
1.1.1.11 root 1840:
1.1 root 1841: return 0;
1842: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.