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