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