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