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