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