|
|
1.1.1.11! root 1: /* ! 2: Legal Notice: The source code contained in this file has been derived from ! 3: the source code of Encryption for the Masses 2.02a, which is Copyright (c) ! 4: Paul Le Roux and which is covered by the 'License Agreement for Encryption ! 5: for the Masses'. Modifications and additions to that source code contained ! 6: in this file are Copyright (c) TrueCrypt Foundation and are covered by the ! 7: TrueCrypt License 2.2 the full text of which is contained in the file ! 8: License.txt included in TrueCrypt binary and source code distribution ! 9: packages. */ 1.1 root 10: 1.1.1.7 root 11: #include "Tcdefs.h" 1.1 root 12: #include <SrRestorePtApi.h> 1.1.1.7 root 13: #include <sys/types.h> 14: #include <sys/stat.h> 1.1 root 15: 1.1.1.7 root 16: #include "Apidrvr.h" 17: #include "Combo.h" 1.1.1.11! root 18: #include "ComSetup.h" 1.1.1.7 root 19: #include "Dlgcode.h" 20: #include "Language.h" 21: #include "Registry.h" 22: #include "Resource.h" 1.1 root 23: 1.1.1.7 root 24: #include "Dir.h" 25: #include "Setup.h" 1.1 root 26: 1.1.1.7 root 27: #include "../Common/Resource.h" 28: #include "../Mount/Mount.h" 1.1 root 29: 30: #pragma warning( disable : 4201 ) 31: #pragma warning( disable : 4115 ) 32: 33: #include <shlobj.h> 34: 35: #pragma warning( default : 4201 ) 36: #pragma warning( default : 4115 ) 37: 38: char dlg_file_name[TC_MAX_PATH]; 1.1.1.8 root 39: char SetupFilesDir[TC_MAX_PATH]; 1.1.1.11! root 40: char UninstallBatch[MAX_PATH]; 1.1.1.8 root 41: 1.1 root 42: BOOL bUninstall = FALSE; 43: BOOL bDone = FALSE; 1.1.1.11! root 44: BOOL Rollback = FALSE; ! 45: BOOL bUpgrade = FALSE; ! 46: BOOL bFirstTimeInstall = FALSE; 1.1.1.7 root 47: char *UninstallPath; 1.1 root 48: 49: HMODULE SystemRestoreDll = 0; 50: 51: BOOL 52: StatDeleteFile (char *lpszFile) 53: { 54: struct __stat64 st; 55: 56: if (_stat64 (lpszFile, &st) == 0) 57: return DeleteFile (lpszFile); 58: else 59: return TRUE; 60: } 61: 62: BOOL 63: StatRemoveDirectory (char *lpszDir) 64: { 65: struct __stat64 st; 66: 67: if (_stat64 (lpszDir, &st) == 0) 68: return RemoveDirectory (lpszDir); 69: else 70: return TRUE; 71: } 72: 73: HRESULT 74: CreateLink (char *lpszPathObj, char *lpszArguments, 75: char *lpszPathLink) 76: { 77: HRESULT hres; 78: IShellLink *psl; 79: 80: /* Get a pointer to the IShellLink interface. */ 81: hres = CoCreateInstance (&CLSID_ShellLink, NULL, 82: CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl); 83: if (SUCCEEDED (hres)) 84: { 85: IPersistFile *ppf; 86: 87: /* Set the path to the shortcut target, and add the 88: description. */ 89: psl->lpVtbl->SetPath (psl, lpszPathObj); 90: psl->lpVtbl->SetArguments (psl, lpszArguments); 91: 92: /* Query IShellLink for the IPersistFile interface for saving 93: the shortcut in persistent storage. */ 94: hres = psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile, 95: &ppf); 96: 97: if (SUCCEEDED (hres)) 98: { 99: WORD wsz[TC_MAX_PATH]; 100: 101: /* Ensure that the string is ANSI. */ 102: MultiByteToWideChar (CP_ACP, 0, lpszPathLink, -1, 103: wsz, TC_MAX_PATH); 104: 105: /* Save the link by calling IPersistFile::Save. */ 106: hres = ppf->lpVtbl->Save (ppf, wsz, TRUE); 107: ppf->lpVtbl->Release (ppf); 108: } 109: psl->lpVtbl->Release (psl); 110: } 111: return hres; 112: } 113: 114: void 115: GetProgramPath (HWND hwndDlg, char *path) 116: { 117: ITEMIDLIST *i; 118: HRESULT res; 119: 1.1.1.7 root 120: if (IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS)) 1.1 root 121: res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i); 122: else 123: res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i); 124: 125: SHGetPathFromIDList (i, path); 126: } 127: 128: void 1.1.1.7 root 129: StatusMessage (HWND hwndDlg , char *stringId) 1.1 root 130: { 1.1.1.11! root 131: if (Rollback) ! 132: return; ! 133: 1.1.1.7 root 134: SendMessageW (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) GetString (stringId)); 1.1.1.11! root 135: 1.1 root 136: SendDlgItemMessage (hwndDlg, IDC_FILES, LB_SETTOPINDEX, 137: SendDlgItemMessage (hwndDlg, IDC_FILES, LB_GETCOUNT, 0, 0) - 1, 0); 138: } 139: 140: void 1.1.1.7 root 141: StatusMessageParam (HWND hwndDlg, char *stringId, char *param) 1.1 root 142: { 1.1.1.7 root 143: wchar_t szTmp[1024]; 1.1.1.11! root 144: ! 145: if (Rollback) ! 146: return; ! 147: 1.1.1.7 root 148: wsprintfW (szTmp, L"%s %hs", GetString (stringId), param); 149: SendMessageW (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) szTmp); 150: 151: SendDlgItemMessage (hwndDlg, IDC_FILES, LB_SETTOPINDEX, 152: SendDlgItemMessage (hwndDlg, IDC_FILES, LB_GETCOUNT, 0, 0) - 1, 0); 1.1 root 153: } 154: 155: void 1.1.1.7 root 156: RegMessage (HWND hwndDlg, char *txt) 1.1 root 157: { 1.1.1.7 root 158: StatusMessageParam (hwndDlg, "ADDING_REG", txt); 1.1 root 159: } 160: 161: void 1.1.1.7 root 162: CopyMessage (HWND hwndDlg, char *txt) 1.1 root 163: { 1.1.1.11! root 164: StatusMessageParam (hwndDlg, "INSTALLING", txt); 1.1 root 165: } 166: 167: void 1.1.1.7 root 168: RemoveMessage (HWND hwndDlg, char *txt) 1.1 root 169: { 1.1.1.11! root 170: if (!Rollback) ! 171: StatusMessageParam (hwndDlg, "REMOVING", txt); 1.1 root 172: } 173: 174: void 175: IconMessage (HWND hwndDlg, char *txt) 176: { 1.1.1.7 root 177: StatusMessageParam (hwndDlg, "ADDING_ICON", txt); 1.1 root 178: } 179: 180: 181: BOOL 1.1.1.11! root 182: DoFilesInstall (HWND hwndDlg, char *szDestDir) 1.1 root 183: { 184: char *szFiles[]= 185: { 1.1.1.11! root 186: "ATrueCrypt.exe", ! 187: "ATrueCrypt Format.exe", ! 188: "ATrueCrypt User Guide.pdf", ! 189: "ATrueCrypt Setup.exe", ! 190: "Atruecrypt.sys", ! 191: "Atruecrypt-x64.sys", ! 192: "ALicense.txt", ! 193: "Dtruecrypt.sys" 1.1 root 194: }; 195: 196: char szTmp[TC_MAX_PATH]; 197: BOOL bOK = TRUE; 1.1.1.11! root 198: int i, x; 1.1 root 199: 1.1.1.11! root 200: x = strlen (szDestDir); ! 201: if (x < 1) ! 202: return FALSE; ! 203: ! 204: if (szDestDir[x - 1] != '\\') ! 205: strcat (szDestDir, "\\"); 1.1 root 206: 207: for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++) 208: { 1.1.1.11! root 209: BOOL bResult; 1.1 root 210: char szDir[TC_MAX_PATH]; 211: 1.1.1.11! root 212: if (bUninstall && strstr (szFiles[i], "TrueCrypt Setup") != 0) 1.1 root 213: continue; 214: 215: if (*szFiles[i] == 'A') 216: strcpy (szDir, szDestDir); 217: else if (*szFiles[i] == 'D') 218: { 1.1.1.10 root 219: GetSystemDirectory (szDir, sizeof (szDir)); 1.1 root 220: 1.1.1.11! root 221: x = strlen (szDir); ! 222: if (szDir[x - 1] != '\\') 1.1 root 223: strcat (szDir, "\\"); 224: 1.1.1.11! root 225: strcat (szDir, "Drivers\\"); 1.1 root 226: } 227: else if (*szFiles[i] == 'W') 228: GetWindowsDirectory (szDir, sizeof (szDir)); 229: 1.1.1.7 root 230: if (*szFiles[i] == 'I') 1.1 root 231: continue; 232: 233: sprintf (szTmp, "%s%s", szDir, szFiles[i] + 1); 234: 235: if (bUninstall == FALSE) 236: CopyMessage (hwndDlg, szTmp); 237: else 238: RemoveMessage (hwndDlg, szTmp); 239: 240: if (bUninstall == FALSE) 241: { 1.1.1.8 root 242: SetCurrentDirectory (SetupFilesDir); 243: 1.1.1.6 root 244: bResult = TCCopyFile (szFiles[i] + 1, szTmp); 1.1 root 245: if (!bResult) 246: { 247: char s[256]; 1.1.1.7 root 248: 249: sprintf (s, "Setup Files\\%s", 250: (strcmp (szFiles[i], "Dtruecrypt.sys") == 0 && Is64BitOs ()) ? 251: "truecrypt-x64.sys" : szFiles[i] + 1); 252: 1.1.1.6 root 253: bResult = TCCopyFile (s, szTmp); 1.1 root 254: } 255: } 256: else 257: { 258: bResult = StatDeleteFile (szTmp); 259: } 260: 261: if (bResult == FALSE) 262: { 263: LPVOID lpMsgBuf; 264: DWORD dwError = GetLastError (); 1.1.1.7 root 265: wchar_t szTmp2[700]; 1.1 root 266: 267: FormatMessage ( 268: FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 269: NULL, 270: dwError, 271: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ 272: (char *) &lpMsgBuf, 273: 0, 274: NULL 275: ); 276: 277: 278: if (bUninstall == FALSE) 1.1.1.7 root 279: wsprintfW (szTmp2, GetString ("INSTALL_OF_FAILED"), szTmp, lpMsgBuf); 1.1 root 280: else 1.1.1.7 root 281: wsprintfW (szTmp2, GetString ("UNINSTALL_OF_FAILED"), szTmp, lpMsgBuf); 1.1 root 282: 283: LocalFree (lpMsgBuf); 284: 1.1.1.11! root 285: if (!Silent && MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES) 1.1 root 286: return FALSE; 287: } 1.1.1.7 root 288: } 1.1 root 289: 1.1.1.7 root 290: // Language pack 291: if (bUninstall == FALSE) 292: { 293: WIN32_FIND_DATA f; 1.1.1.8 root 294: HANDLE h; 295: 296: SetCurrentDirectory (SetupFilesDir); 297: h = FindFirstFile ("Language.*.xml", &f); 298: 1.1.1.7 root 299: if (h != INVALID_HANDLE_VALUE) 300: { 301: char d[MAX_PATH*2]; 1.1.1.11! root 302: sprintf (d, "%s%s", szDestDir, f.cFileName); 1.1.1.7 root 303: CopyMessage (hwndDlg, d); 304: TCCopyFile (f.cFileName, d); 305: FindClose (h); 306: } 1.1.1.8 root 307: 308: SetCurrentDirectory (SetupFilesDir); 309: SetCurrentDirectory ("Setup files"); 310: h = FindFirstFile ("TrueCrypt User Guide.*.pdf", &f); 311: if (h != INVALID_HANDLE_VALUE) 312: { 313: char d[MAX_PATH*2]; 1.1.1.11! root 314: sprintf (d, "%s%s", szDestDir, f.cFileName); 1.1.1.8 root 315: CopyMessage (hwndDlg, d); 316: TCCopyFile (f.cFileName, d); 317: FindClose (h); 318: } 319: SetCurrentDirectory (SetupFilesDir); 1.1 root 320: } 321: 322: return bOK; 323: } 324: 325: BOOL 1.1.1.11! root 326: DoRegInstall (HWND hwndDlg, char *szDestDir, BOOL bInstallType) 1.1 root 327: { 328: char szDir[TC_MAX_PATH], *key; 1.1.1.11! root 329: char szTmp[TC_MAX_PATH]; 1.1 root 330: HKEY hkey = 0; 331: BOOL bSlash, bOK = FALSE; 332: DWORD dw; 333: int x; 334: 335: strcpy (szDir, szDestDir); 336: x = strlen (szDestDir); 337: if (szDestDir[x - 1] == '\\') 338: bSlash = TRUE; 339: else 340: bSlash = FALSE; 341: 342: if (bSlash == FALSE) 343: strcat (szDir, "\\"); 344: 1.1.1.7 root 345: if (bInstallType) 1.1 root 346: { 347: 1.1.1.11! root 348: key = "Software\\Classes\\TrueCryptVolume"; 1.1 root 349: RegMessage (hwndDlg, key); 350: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, 351: key, 352: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS) 353: goto error; 354: 1.1.1.10 root 355: strcpy (szTmp, "TrueCrypt Volume"); 1.1 root 356: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) 357: goto error; 358: 359: RegCloseKey (hkey); 360: hkey = 0; 361: 1.1.1.11! root 362: key = "Software\\Classes\\TrueCryptVolume\\DefaultIcon"; 1.1 root 363: RegMessage (hwndDlg, key); 364: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, 365: key, 366: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS) 367: goto error; 368: 369: sprintf (szTmp, "%sTrueCrypt.exe,1", szDir); 370: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) 371: goto error; 372: 373: RegCloseKey (hkey); 374: hkey = 0; 375: 1.1.1.11! root 376: key = "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command"; 1.1 root 377: RegMessage (hwndDlg, key); 378: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, 379: key, 380: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS) 381: goto error; 382: 383: sprintf (szTmp, "\"%sTrueCrypt.exe\" /v \"%%1\"", szDir ); 384: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) 385: goto error; 386: 387: RegCloseKey (hkey); 388: hkey = 0; 389: 1.1.1.11! root 390: key = "Software\\Classes\\.tc"; 1.1 root 391: RegMessage (hwndDlg, key); 392: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, 393: key, 394: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS) 395: goto error; 396: 397: strcpy (szTmp, "TrueCryptVolume"); 398: if (RegSetValueEx (hkey, "", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) 399: goto error; 1.1.1.11! root 400: ! 401: RegCloseKey (hkey); ! 402: hkey = 0; 1.1 root 403: } 404: 1.1.1.11! root 405: key = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt"; ! 406: RegMessage (hwndDlg, key); ! 407: if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, ! 408: key, ! 409: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS) ! 410: goto error; 1.1 root 411: 1.1.1.11! root 412: sprintf (szTmp, "\"%sTrueCrypt Setup.exe\" /u %s", szDir, szDestDir); ! 413: if (RegSetValueEx (hkey, "UninstallString", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) ! 414: goto error; 1.1 root 415: 1.1.1.11! root 416: sprintf (szTmp, "\"%sTrueCrypt Setup.exe\"", szDir); ! 417: if (RegSetValueEx (hkey, "DisplayIcon", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) ! 418: goto error; 1.1 root 419: 1.1.1.11! root 420: strcpy (szTmp, "TrueCrypt"); ! 421: if (RegSetValueEx (hkey, "DisplayName", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) ! 422: goto error; 1.1 root 423: 1.1.1.11! root 424: strcpy (szTmp, "TrueCrypt Foundation"); ! 425: if (RegSetValueEx (hkey, "Publisher", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) ! 426: goto error; 1.1 root 427: 1.1.1.11! root 428: strcpy (szTmp, "http://www.truecrypt.org/"); ! 429: if (RegSetValueEx (hkey, "URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, strlen (szTmp) + 1) != ERROR_SUCCESS) ! 430: goto error; ! 431: 1.1 root 432: bOK = TRUE; 433: 1.1.1.11! root 434: error: 1.1 root 435: if (hkey != 0) 436: RegCloseKey (hkey); 437: 438: if (bOK == FALSE) 439: { 440: handleWin32Error (hwndDlg); 1.1.1.11! root 441: Error ("REG_INSTALL_FAILED"); ! 442: } ! 443: ! 444: // Register COM servers for UAC ! 445: if (nCurrentOS == WIN_VISTA_OR_LATER) ! 446: { ! 447: if (!RegisterComServers (szDir)) ! 448: { ! 449: Error ("COM_REG_FAILED"); ! 450: return FALSE; ! 451: } 1.1 root 452: } 453: 454: return bOK; 455: } 456: 457: BOOL 1.1.1.7 root 458: DoApplicationDataUninstall (HWND hwndDlg) 459: { 460: char path[MAX_PATH]; 461: char path2[MAX_PATH]; 462: BOOL bOK = TRUE; 463: 464: StatusMessage (hwndDlg, "REMOVING_APPDATA"); 465: 466: SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path); 467: strcat (path, "\\TrueCrypt\\"); 468: 469: // Delete favorite volumes file 470: sprintf (path2, "%s%s", path, FILE_FAVORITE_VOLUMES); 471: RemoveMessage (hwndDlg, path2); 472: StatDeleteFile (path2); 473: 474: // Delete keyfile defaults 475: sprintf (path2, "%s%s", path, FILE_DEFAULT_KEYFILES); 476: RemoveMessage (hwndDlg, path2); 477: StatDeleteFile (path2); 478: 479: // Delete history file 480: sprintf (path2, "%s%s", path, FILE_HISTORY); 481: RemoveMessage (hwndDlg, path2); 482: StatDeleteFile (path2); 483: 484: // Delete configuration file 485: sprintf (path2, "%s%s", path, FILE_CONFIGURATION); 486: RemoveMessage (hwndDlg, path2); 487: StatDeleteFile (path2); 488: 489: SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path); 490: strcat (path, "\\TrueCrypt"); 491: RemoveMessage (hwndDlg, path); 492: if (!StatRemoveDirectory (path)) 493: { 494: handleWin32Error (hwndDlg); 495: bOK = FALSE; 496: } 497: 498: return bOK; 499: } 500: 501: BOOL 502: DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated) 1.1 root 503: { 504: BOOL bOK = FALSE; 1.1.1.7 root 505: char regk [64]; 1.1 root 506: 1.1.1.11! root 507: // Unregister COM servers ! 508: if (!bRemoveDeprecated && nCurrentOS == WIN_VISTA_OR_LATER) ! 509: { ! 510: if (!UnregisterComServers (dlg_file_name)) ! 511: StatusMessage (hwndDlg, "COM_DEREG_FAILED"); ! 512: } ! 513: ! 514: if (!bRemoveDeprecated) ! 515: StatusMessage (hwndDlg, "REMOVING_REG"); 1.1 root 516: 1.1.1.11! root 517: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt"); ! 518: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open\\command"); ! 519: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell\\open"); ! 520: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\Shell"); ! 521: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume\\DefaultIcon"); ! 522: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\TrueCryptVolume"); ! 523: RegDeleteKey (HKEY_CURRENT_USER, "Software\\TrueCrypt"); 1.1.1.7 root 524: 525: if (!bRemoveDeprecated) 526: { 527: // Split the string in order to prevent some antivirus packages from falsely reporting 528: // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan). 529: sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run"); 530: DeleteRegistryValue (regk, "TrueCrypt"); 531: 1.1.1.11! root 532: RegDeleteKey (HKEY_LOCAL_MACHINE, "Software\\Classes\\.tc"); 1.1.1.7 root 533: } 1.1 root 534: 535: bOK = TRUE; 536: 537: if (bOK == FALSE && GetLastError ()!= ERROR_NO_TOKEN && GetLastError ()!= ERROR_FILE_NOT_FOUND 538: && GetLastError ()!= ERROR_PATH_NOT_FOUND) 539: { 540: handleWin32Error (hwndDlg); 541: } 542: else 543: bOK = TRUE; 544: 545: return bOK; 546: } 547: 1.1.1.11! root 548: 1.1 root 549: BOOL 550: DoServiceUninstall (HWND hwndDlg, char *lpszService) 551: { 552: SC_HANDLE hManager, hService = NULL; 553: BOOL bOK = FALSE, bRet; 554: SERVICE_STATUS status; 1.1.1.6 root 555: BOOL firstTry = TRUE; 1.1 root 556: int x; 557: 1.1.1.6 root 558: memset (&status, 0, sizeof (status)); /* Keep VC6 quiet */ 559: 560: retry: 1.1 root 561: 562: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS); 563: if (hManager == NULL) 564: goto error; 565: 566: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS); 567: if (hService == NULL) 568: goto error; 569: 1.1.1.7 root 570: if (strcmp ("truecrypt", lpszService) == 0) 571: StatusMessage (hwndDlg, "STOPPING_DRIVER"); 572: else 573: StatusMessageParam (hwndDlg, "STOPPING", lpszService); 1.1 root 574: 575: #define WAIT_PERIOD 3 576: 577: for (x = 0; x < WAIT_PERIOD; x++) 578: { 579: bRet = QueryServiceStatus (hService, &status); 580: if (bRet != TRUE) 581: goto error; 582: 583: if (status.dwCurrentState != SERVICE_START_PENDING && 584: status.dwCurrentState != SERVICE_STOP_PENDING && 585: status.dwCurrentState != SERVICE_CONTINUE_PENDING) 586: break; 587: 588: Sleep (1000); 589: } 590: 591: if (status.dwCurrentState != SERVICE_STOPPED) 592: { 593: bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status); 594: if (bRet == FALSE) 595: goto try_delete; 596: 597: for (x = 0; x < WAIT_PERIOD; x++) 598: { 599: bRet = QueryServiceStatus (hService, &status); 600: if (bRet != TRUE) 601: goto error; 602: 603: if (status.dwCurrentState != SERVICE_START_PENDING && 604: status.dwCurrentState != SERVICE_STOP_PENDING && 605: status.dwCurrentState != SERVICE_CONTINUE_PENDING) 606: break; 607: 608: Sleep (1000); 609: } 610: 611: if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING) 612: goto error; 613: } 614: 1.1.1.6 root 615: try_delete: 616: 1.1.1.7 root 617: if (strcmp ("truecrypt", lpszService) == 0) 618: StatusMessage (hwndDlg, "REMOVING_DRIVER"); 619: else 620: StatusMessageParam (hwndDlg, "REMOVING", lpszService); 1.1 root 621: 622: if (hService != NULL) 623: CloseServiceHandle (hService); 624: 625: if (hManager != NULL) 626: CloseServiceHandle (hManager); 627: 628: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS); 629: if (hManager == NULL) 630: goto error; 631: 632: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS); 633: if (hService == NULL) 634: goto error; 635: 636: bRet = DeleteService (hService); 637: if (bRet == FALSE) 1.1.1.6 root 638: { 639: if (firstTry && GetLastError () == ERROR_SERVICE_MARKED_FOR_DELETE) 640: { 641: // Second try for an eventual no-install driver instance 642: CloseServiceHandle (hService); 643: CloseServiceHandle (hManager); 644: 645: Sleep(1000); 646: firstTry = FALSE; 647: goto retry; 648: } 649: 1.1 root 650: goto error; 1.1.1.6 root 651: } 1.1 root 652: 653: bOK = TRUE; 654: 1.1.1.6 root 655: error: 656: 1.1 root 657: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST) 658: { 659: handleWin32Error (hwndDlg); 1.1.1.7 root 660: MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND); 1.1 root 661: } 662: else 663: bOK = TRUE; 664: 665: if (hService != NULL) 666: CloseServiceHandle (hService); 667: 668: if (hManager != NULL) 669: CloseServiceHandle (hManager); 670: 671: return bOK; 672: } 673: 1.1.1.7 root 674: 1.1 root 675: BOOL 676: DoDriverUnload (HWND hwndDlg) 677: { 678: BOOL bOK = TRUE; 679: int status; 680: 681: status = DriverAttach (); 682: if (status != 0) 683: { 1.1.1.11! root 684: if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND) 1.1 root 685: { 686: handleWin32Error (hwndDlg); 1.1.1.7 root 687: AbortProcess ("NODRIVER"); 1.1 root 688: } 689: 690: if (status != ERR_OS_ERROR) 691: { 692: handleError (NULL, status); 1.1.1.7 root 693: AbortProcess ("NODRIVER"); 1.1 root 694: } 695: } 696: 697: if (hDriver != INVALID_HANDLE_VALUE) 698: { 1.1.1.3 root 699: MOUNT_LIST_STRUCT driver; 1.1.1.11! root 700: LONG driverVersion = VERSION_NUM; 1.1.1.7 root 701: int refCount; 1.1.1.3 root 702: DWORD dwResult; 703: BOOL bResult; 1.1 root 704: 1.1.1.11! root 705: ! 706: // Try to determine if it's upgrade (and not reinstall, downgrade, or first-time install). ! 707: bUpgrade = (DeviceIoControl (hDriver, DRIVER_VERSION, &driverVersion, 4, &driverVersion, 4, &dwResult, NULL) ! 708: && driverVersion < VERSION_NUM); ! 709: ! 710: 1.1.1.3 root 711: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver, 712: sizeof (driver), &dwResult, NULL); 1.1 root 713: 1.1.1.7 root 714: if (bResult) 1.1 root 715: { 1.1.1.3 root 716: if (driver.ulMountedDrives != 0) 1.1 root 717: { 718: bOK = FALSE; 1.1.1.7 root 719: MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND); 1.1 root 720: } 721: } 722: else 723: { 1.1.1.3 root 724: bOK = FALSE; 725: handleWin32Error (hwndDlg); 1.1 root 726: } 1.1.1.7 root 727: 728: // Try to close all open TC windows 1.1.1.11! root 729: if (bOK) 1.1.1.7 root 730: { 731: BOOL TCWindowClosed = FALSE; 1.1.1.11! root 732: 1.1.1.7 root 733: EnumWindows (CloseTCWindowsEnum, (LPARAM) &TCWindowClosed); 1.1.1.11! root 734: ! 735: if (TCWindowClosed) ! 736: Sleep (2000); 1.1.1.7 root 737: } 738: 739: // Test for any applications attached to driver 740: bResult = DeviceIoControl (hDriver, DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount, 741: sizeof (refCount), &dwResult, NULL); 742: 743: if (bOK && bResult && refCount > 1) 744: { 745: MessageBoxW (hwndDlg, GetString ("CLOSE_TC_FIRST"), lpszTitle, MB_ICONSTOP); 746: bOK = FALSE; 747: } 1.1 root 748: 749: CloseHandle (hDriver); 750: hDriver = INVALID_HANDLE_VALUE; 751: } 1.1.1.11! root 752: else ! 753: { ! 754: bFirstTimeInstall = TRUE; ! 755: } 1.1 root 756: 757: return bOK; 758: } 759: 760: 761: BOOL 762: DoDriverInstall (HWND hwndDlg) 763: { 764: SC_HANDLE hManager, hService = NULL; 1.1.1.11! root 765: BOOL bOK = FALSE, bRet; 1.1 root 766: 767: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS); 768: if (hManager == NULL) 769: goto error; 770: 1.1.1.7 root 771: StatusMessage (hwndDlg, "INSTALLING_DRIVER"); 1.1 root 772: 773: hService = CreateService (hManager, "truecrypt", "truecrypt", 1.1.1.11! root 774: SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_SYSTEM_START, SERVICE_ERROR_NORMAL, ! 775: !Is64BitOs () ? "System32\\drivers\\truecrypt.sys" : "SysWOW64\\drivers\\truecrypt.sys", ! 776: NULL, NULL, NULL, NULL, NULL); ! 777: 1.1 root 778: if (hService == NULL) 779: goto error; 780: else 781: CloseServiceHandle (hService); 782: 783: hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS); 784: if (hService == NULL) 785: goto error; 786: 1.1.1.7 root 787: StatusMessage (hwndDlg, "STARTING_DRIVER"); 1.1 root 788: 789: bRet = StartService (hService, 0, NULL); 790: if (bRet == FALSE) 791: goto error; 792: 793: bOK = TRUE; 794: 1.1.1.11! root 795: error: ! 796: if (bOK == FALSE && GetLastError () != ERROR_SERVICE_ALREADY_RUNNING) 1.1 root 797: { 798: handleWin32Error (hwndDlg); 1.1.1.7 root 799: MessageBoxW (hwndDlg, GetString ("DRIVER_INSTALL_FAILED"), lpszTitle, MB_ICONHAND); 1.1 root 800: } 801: else 802: bOK = TRUE; 803: 804: if (hService != NULL) 805: CloseServiceHandle (hService); 806: 807: if (hManager != NULL) 808: CloseServiceHandle (hManager); 809: 810: return bOK; 811: } 812: 813: BOOL 814: DoShortcutsUninstall (HWND hwndDlg, char *szDestDir) 815: { 1.1.1.11! root 816: char szLinkDir[TC_MAX_PATH]; 1.1.1.7 root 817: char szTmp2[TC_MAX_PATH]; 1.1 root 818: BOOL bSlash, bOK = FALSE; 819: HRESULT hOle; 820: int x; 821: BOOL allUsers = FALSE; 822: 823: hOle = OleInitialize (NULL); 824: 825: // User start menu 826: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0); 827: x = strlen (szLinkDir); 828: if (szLinkDir[x - 1] == '\\') 829: bSlash = TRUE; 830: else 831: bSlash = FALSE; 832: 833: if (bSlash == FALSE) 834: strcat (szLinkDir, "\\"); 835: 836: strcat (szLinkDir, "TrueCrypt"); 837: 838: // Global start menu 839: { 840: struct _stat st; 841: char path[TC_MAX_PATH]; 842: 843: SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0); 844: strcat (path, "\\TrueCrypt"); 845: 846: if (_stat (path, &st) == 0) 847: { 848: strcpy (szLinkDir, path); 849: allUsers = TRUE; 850: } 851: } 852: 853: // Start menu entries 854: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk"); 855: RemoveMessage (hwndDlg, szTmp2); 856: if (StatDeleteFile (szTmp2) == FALSE) 857: goto error; 858: 1.1.1.11! root 859: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url"); 1.1 root 860: RemoveMessage (hwndDlg, szTmp2); 861: if (StatDeleteFile (szTmp2) == FALSE) 862: goto error; 863: 864: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk"); 865: RemoveMessage (hwndDlg, szTmp2); 866: if (StatDeleteFile (szTmp2) == FALSE) 867: goto error; 1.1.1.11! root 868: ! 869: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk"); ! 870: DeleteFile (szTmp2); 1.1 root 871: 872: // Start menu group 873: RemoveMessage ((HWND) hwndDlg, szLinkDir); 874: if (StatRemoveDirectory (szLinkDir) == FALSE) 875: handleWin32Error ((HWND) hwndDlg); 876: 877: // Desktop icon 878: 879: if (allUsers) 880: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0); 881: else 882: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0); 883: 884: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk"); 885: 886: RemoveMessage (hwndDlg, szTmp2); 887: if (StatDeleteFile (szTmp2) == FALSE) 888: goto error; 889: 890: bOK = TRUE; 891: 892: error: 893: OleUninitialize (); 894: 895: return bOK; 896: } 897: 898: BOOL 899: DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon) 900: { 901: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH]; 1.1.1.7 root 902: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH]; 1.1 root 903: BOOL bSlash, bOK = FALSE; 904: HRESULT hOle; 905: int x; 906: 907: if (bProgGroup == FALSE && bDesktopIcon == FALSE) 908: return TRUE; 909: 910: hOle = OleInitialize (NULL); 911: 912: GetProgramPath (hwndDlg, szLinkDir); 913: 914: x = strlen (szLinkDir); 915: if (szLinkDir[x - 1] == '\\') 916: bSlash = TRUE; 917: else 918: bSlash = FALSE; 919: 920: if (bSlash == FALSE) 921: strcat (szLinkDir, "\\"); 922: 923: strcat (szLinkDir, "TrueCrypt"); 924: 925: strcpy (szDir, szDestDir); 926: x = strlen (szDestDir); 927: if (szDestDir[x - 1] == '\\') 928: bSlash = TRUE; 929: else 930: bSlash = FALSE; 931: 932: if (bSlash == FALSE) 933: strcat (szDir, "\\"); 934: 935: if (bProgGroup) 936: { 1.1.1.11! root 937: FILE *f; ! 938: 1.1 root 939: if (mkfulldir (szLinkDir, TRUE) != 0) 940: { 1.1.1.7 root 941: wchar_t szTmp[TC_MAX_PATH]; 1.1 root 942: 943: if (mkfulldir (szLinkDir, FALSE) != 0) 944: { 945: handleWin32Error (hwndDlg); 1.1.1.7 root 946: wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szLinkDir); 947: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND); 1.1 root 948: goto error; 949: } 950: } 951: 952: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe"); 953: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk"); 954: 955: IconMessage (hwndDlg, szTmp2); 956: if (CreateLink (szTmp, "", szTmp2) != S_OK) 957: goto error; 958: 1.1.1.11! root 959: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url"); 1.1 root 960: IconMessage (hwndDlg, szTmp2); 1.1.1.11! root 961: f = fopen (szTmp2, "w"); ! 962: if (f) ! 963: { ! 964: fprintf (f, "[InternetShortcut]\nURL=%s&dest=index\n", TC_APPLINK); ! 965: fclose (f); ! 966: } 1.1 root 967: else 1.1.1.11! root 968: goto error; 1.1 root 969: 970: sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe"); 971: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk"); 1.1.1.7 root 972: sprintf (szTmp3, "/u %s", szDestDir); 1.1 root 973: 974: IconMessage (hwndDlg, szTmp2); 1.1.1.7 root 975: if (CreateLink (szTmp, szTmp3, szTmp2) != S_OK) 1.1 root 976: goto error; 977: 1.1.1.11! root 978: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk"); ! 979: DeleteFile (szTmp2); 1.1 root 980: } 981: 982: if (bDesktopIcon) 983: { 984: strcpy (szDir, szDestDir); 985: x = strlen (szDestDir); 986: if (szDestDir[x - 1] == '\\') 987: bSlash = TRUE; 988: else 989: bSlash = FALSE; 990: 991: if (bSlash == FALSE) 992: strcat (szDir, "\\"); 993: 1.1.1.7 root 994: if (IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS)) 1.1 root 995: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0); 996: else 997: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0); 998: 999: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe"); 1000: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk"); 1001: 1002: IconMessage (hwndDlg, szTmp2); 1003: 1004: if (CreateLink (szTmp, "", szTmp2) != S_OK) 1005: goto error; 1006: } 1007: 1008: bOK = TRUE; 1009: 1010: error: 1011: OleUninitialize (); 1012: 1013: return bOK; 1014: } 1015: 1016: 1017: void 1.1.1.11! root 1018: OutcomePrompt (HWND hwndDlg, BOOL bOK) 1.1 root 1019: { 1.1.1.7 root 1020: if (bOK) 1.1 root 1021: { 1022: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE); 1023: 1024: bDone = TRUE; 1025: 1.1.1.7 root 1026: if (bUninstall == FALSE) 1.1.1.11! root 1027: Info ("INSTALL_OK"); 1.1 root 1028: else 1.1.1.11! root 1029: { ! 1030: wchar_t str[4096]; ! 1031: ! 1032: swprintf (str, GetString ("UNINSTALL_OK"), dlg_file_name); ! 1033: MessageBoxW (hwndDlg, str, lpszTitle, MB_ICONASTERISK); ! 1034: } 1.1 root 1035: } 1036: else 1037: { 1038: if (bUninstall == FALSE) 1.1.1.11! root 1039: Error ("INSTALL_FAILED"); 1.1 root 1040: else 1.1.1.11! root 1041: Error ("UNINSTALL_FAILED"); 1.1 root 1042: } 1043: } 1044: 1045: static void SetSystemRestorePoint (void *hwndDlg, BOOL finalize) 1046: { 1047: static RESTOREPOINTINFO RestPtInfo; 1048: static STATEMGRSTATUS SMgrStatus; 1049: static BOOL failed = FALSE; 1050: static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS); 1051: 1052: if (!SystemRestoreDll) return; 1053: 1054: _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA"); 1055: if (_SRSetRestorePoint == 0) 1056: { 1057: FreeLibrary (SystemRestoreDll); 1058: SystemRestoreDll = 0; 1059: return; 1060: } 1061: 1062: if (!finalize) 1063: { 1.1.1.7 root 1064: StatusMessage (hwndDlg, "CREATING_SYS_RESTORE"); 1.1 root 1065: 1066: RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE; 1067: RestPtInfo.dwRestorePtType = APPLICATION_INSTALL; 1068: RestPtInfo.llSequenceNumber = 0; 1.1.1.7 root 1069: strcpy (RestPtInfo.szDescription, "TrueCrypt installation"); 1.1 root 1070: 1.1.1.7 root 1071: if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus)) 1.1 root 1072: { 1.1.1.7 root 1073: StatusMessage (hwndDlg, "FAILED_SYS_RESTORE"); 1.1 root 1074: failed = TRUE; 1075: } 1076: } 1.1.1.11! root 1077: else if (!failed) 1.1 root 1078: { 1.1.1.11! root 1079: RestPtInfo.dwEventType = END_SYSTEM_CHANGE; ! 1080: RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber; ! 1081: RestPtInfo.dwRestorePtType = CANCELLED_OPERATION; ! 1082: ! 1083: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) ! 1084: { ! 1085: StatusMessage (hwndDlg, "FAILED_SYS_RESTORE"); ! 1086: } ! 1087: else ! 1088: StatusMessage (hwndDlg, "SYS_RESTORE_CREATED"); 1.1 root 1089: } 1090: } 1091: 1092: void 1093: DoUninstall (void *hwndDlg) 1094: { 1095: BOOL bOK = TRUE; 1096: 1.1.1.11! root 1097: if (!Rollback) ! 1098: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE); 1.1 root 1099: 1100: WaitCursor (); 1101: 1.1.1.11! root 1102: if (!Rollback) ! 1103: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0); 1.1 root 1104: 1105: if (DoDriverUnload (hwndDlg) == FALSE) 1106: { 1107: bOK = FALSE; 1108: } 1109: else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE) 1110: { 1111: bOK = FALSE; 1112: } 1.1.1.11! root 1113: else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE) 1.1 root 1114: { 1115: bOK = FALSE; 1116: } 1.1.1.11! root 1117: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name) == FALSE) 1.1 root 1118: { 1119: bOK = FALSE; 1120: } 1121: else if (DoShortcutsUninstall (hwndDlg, dlg_file_name) == FALSE) 1122: { 1123: bOK = FALSE; 1124: } 1.1.1.7 root 1125: else if (!DoApplicationDataUninstall (hwndDlg)) 1126: { 1127: bOK = FALSE; 1128: } 1.1 root 1129: else 1130: { 1.1.1.11! root 1131: char temp[MAX_PATH]; ! 1132: FILE *f; ! 1133: ! 1134: // Deprecated service ! 1135: DoServiceUninstall (hwndDlg, "TrueCryptService"); ! 1136: ! 1137: GetTempPath (sizeof (temp), temp); ! 1138: _snprintf (UninstallBatch, sizeof (UninstallBatch), "%s\\TrueCrypt-Uninstall.bat", temp); ! 1139: ! 1140: // Create uninstall batch ! 1141: f = fopen (UninstallBatch, "w"); ! 1142: if (!f) ! 1143: bOK = FALSE; ! 1144: else 1.1 root 1145: { 1.1.1.11! root 1146: fprintf (f, ":loop\n" ! 1147: "del \"%s\\%s\"\n" ! 1148: "if exist \"%s\\%s\" goto loop\n" ! 1149: "rmdir \"%s\"\n" ! 1150: "del \"%s\"", ! 1151: dlg_file_name, "TrueCrypt Setup.exe", ! 1152: dlg_file_name, "TrueCrypt Setup.exe", ! 1153: dlg_file_name, ! 1154: UninstallBatch ! 1155: ); ! 1156: fclose (f); 1.1 root 1157: } 1158: } 1159: 1160: NormalCursor (); 1161: 1.1.1.11! root 1162: if (Rollback) ! 1163: return; ! 1164: 1.1.1.7 root 1165: if (bOK) 1.1.1.11! root 1166: PostMessage (hwndDlg, WM_APP + 2, 0, 0); 1.1.1.7 root 1167: 1168: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE); 1.1.1.11! root 1169: OutcomePrompt (hwndDlg, bOK); 1.1 root 1170: } 1171: 1172: void 1173: DoInstall (void *hwndDlg) 1174: { 1175: BOOL bOK = TRUE; 1.1.1.11! root 1176: char path[MAX_PATH]; 1.1 root 1177: 1.1.1.7 root 1178: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), FALSE); 1.1 root 1179: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0); 1180: 1181: if (DoDriverUnload (hwndDlg) == FALSE) 1182: { 1.1.1.4 root 1183: NormalCursor (); 1.1.1.7 root 1184: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), TRUE); 1.1.1.4 root 1185: return; 1.1 root 1186: } 1.1.1.4 root 1187: 1188: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE))) 1189: SetSystemRestorePoint (hwndDlg, FALSE); 1190: 1.1.1.11! root 1191: // Remove deprecated 1.1.1.7 root 1192: DoServiceUninstall (hwndDlg, "TrueCryptService"); 1.1.1.11! root 1193: 1.1.1.7 root 1194: DoRegUninstall ((HWND) hwndDlg, TRUE); 1195: 1.1.1.11! root 1196: GetWindowsDirectory (path, sizeof (path)); ! 1197: strcat_s (path, sizeof (path), "\\TrueCrypt Setup.exe"); ! 1198: DeleteFile (path); ! 1199: 1.1.1.7 root 1200: if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE) 1.1 root 1201: { 1202: bOK = FALSE; 1203: } 1.1.1.11! root 1204: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name) == FALSE) 1.1 root 1205: { 1206: bOK = FALSE; 1207: } 1208: else if (DoRegInstall ((HWND) hwndDlg, dlg_file_name, 1.1.1.11! root 1209: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_FILE_TYPE))) == FALSE) 1.1 root 1210: { 1211: bOK = FALSE; 1212: } 1213: else if (DoDriverInstall (hwndDlg) == FALSE) 1214: { 1215: bOK = FALSE; 1216: } 1217: else if (DoShortcutsInstall (hwndDlg, dlg_file_name, 1218: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_PROG_GROUP)), 1219: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_DESKTOP_ICON))) == FALSE) 1220: { 1221: bOK = FALSE; 1222: } 1223: 1224: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE))) 1225: SetSystemRestorePoint (hwndDlg, TRUE); 1226: 1.1.1.7 root 1227: if (bOK) 1228: { 1.1.1.11! root 1229: UninstallBatch[0] = 0; 1.1.1.7 root 1230: StatusMessage (hwndDlg, "INSTALL_COMPLETED"); 1.1.1.11! root 1231: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), TRUE); ! 1232: } ! 1233: else ! 1234: { ! 1235: bUninstall = TRUE; ! 1236: Rollback = TRUE; ! 1237: Silent = TRUE; ! 1238: ! 1239: DoUninstall (hwndDlg); ! 1240: ! 1241: bUninstall = FALSE; ! 1242: Rollback = FALSE; ! 1243: Silent = FALSE; ! 1244: ! 1245: StatusMessage (hwndDlg, "ROLLBACK"); 1.1.1.7 root 1246: } 1.1 root 1247: 1.1.1.11! root 1248: PostMessage (hwndDlg, WM_APP + 1, 0, 0); ! 1249: OutcomePrompt (hwndDlg, bOK); ! 1250: ! 1251: if (bOK && !bUninstall) ! 1252: { ! 1253: if (bUpgrade && (AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES") == IDYES)) ! 1254: { ! 1255: Applink ("releasenotes", TRUE, ""); ! 1256: } ! 1257: else if (bFirstTimeInstall && AskYesNo ("AFTER_INSTALL_TUTORIAL") == IDYES) ! 1258: { ! 1259: Applink ("beginnerstutorial", TRUE, ""); ! 1260: } ! 1261: } 1.1 root 1262: } 1263: 1264: 1265: BOOL WINAPI 1266: InstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 1267: { 1268: WORD lw = LOWORD (wParam); 1269: if (lParam); /* remove warning */ 1270: 1271: switch (msg) 1272: { 1273: case WM_INITDIALOG: 1.1.1.7 root 1274: MainDlg = hwndDlg; 1.1 root 1275: InitDialog (hwndDlg); 1.1.1.7 root 1276: LocalizeDialog (hwndDlg, NULL); 1.1 root 1277: 1.1.1.7 root 1278: if (UninstallPath == NULL) 1.1.1.3 root 1279: { 1280: char path[MAX_PATH+20]; 1281: ITEMIDLIST *i; 1282: SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &i); 1283: SHGetPathFromIDList (i, path); 1284: strcat (path, "\\TrueCrypt"); 1285: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), path); 1286: } 1.1.1.7 root 1287: else 1288: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), UninstallPath); 1.1 root 1289: 1290: if (bUninstall == FALSE) 1291: { 1.1.1.11! root 1292: char *licenseText; ! 1293: ! 1294: licenseText = GetLegalNotices (); ! 1295: if (licenseText != NULL) ! 1296: { ! 1297: SetWindowText (GetDlgItem (hwndDlg, IDC_LICENSE), licenseText); ! 1298: free (licenseText); ! 1299: } 1.1 root 1300: } 1301: 1302: SendMessage (GetDlgItem (hwndDlg, IDC_ALL_USERS), BM_SETCHECK, BST_CHECKED, 0); 1303: SendMessage (GetDlgItem (hwndDlg, IDC_FILE_TYPE), BM_SETCHECK, BST_CHECKED, 0); 1304: SendMessage (GetDlgItem (hwndDlg, IDC_PROG_GROUP), BM_SETCHECK, BST_CHECKED, 0); 1305: SendMessage (GetDlgItem (hwndDlg, IDC_DESKTOP_ICON), BM_SETCHECK, BST_CHECKED, 0); 1306: 1307: // System Restore 1.1.1.7 root 1308: SystemRestoreDll = LoadLibrary ("srclient.dll"); 1.1 root 1309: 1310: if (SystemRestoreDll != 0) 1311: SendMessage (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), BM_SETCHECK, BST_CHECKED, 0); 1312: else 1313: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE), FALSE); 1314: 1.1.1.7 root 1315: SetWindowTextW (hwndDlg, lpszTitle); 1.1.1.11! root 1316: 1.1 root 1317: return 1; 1318: 1319: case WM_SYSCOMMAND: 1320: if (lw == IDC_ABOUT) 1321: { 1.1.1.7 root 1322: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc); 1.1 root 1323: return 1; 1324: } 1325: return 0; 1326: 1327: case WM_COMMAND: 1.1.1.7 root 1328: if (lw == IDC_INSTALL || lw == IDC_UNINSTALL) 1.1 root 1329: { 1330: char szDirname[TC_MAX_PATH]; 1331: 1.1.1.7 root 1332: if (bDone) 1.1 root 1333: { 1.1.1.7 root 1334: EndDialog (hwndDlg, IDC_INSTALL); 1.1 root 1335: return 1; 1336: } 1337: 1338: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname)); 1339: 1340: if (bUninstall == FALSE) 1341: { 1342: if (mkfulldir (szDirname, TRUE) != 0) 1343: { 1.1.1.7 root 1344: wchar_t szTmp[TC_MAX_PATH]; 1.1 root 1345: 1346: if (mkfulldir (szDirname, FALSE) != 0) 1347: { 1348: handleWin32Error (hwndDlg); 1.1.1.7 root 1349: wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szDirname); 1350: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND); 1.1 root 1351: return 1; 1352: } 1353: } 1354: } 1355: 1356: strcpy (dlg_file_name, szDirname); 1357: 1.1.1.11! root 1358: WaitCursor (); ! 1359: 1.1 root 1360: if (bUninstall == FALSE) 1361: _beginthread (DoInstall, 16384, (void *) hwndDlg); 1362: else 1363: _beginthread (DoUninstall, 16384, (void *) hwndDlg); 1364: 1365: return 1; 1366: } 1367: 1368: if (lw == IDCANCEL) 1369: { 1370: EndDialog (hwndDlg, IDCANCEL); 1371: return 1; 1372: } 1373: 1374: if (lw == IDC_BROWSE) 1375: { 1376: char szDirname[TC_MAX_PATH]; 1377: 1378: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname)); 1379: 1.1.1.7 root 1380: if (BrowseDirectories (hwndDlg, "SELECT_INSTALL_DIR", szDirname)) 1.1 root 1381: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname); 1382: 1383: return 1; 1384: } 1385: 1386: if (lw == IDC_DESTINATION && HIWORD (wParam) == EN_CHANGE && bDone == FALSE) 1387: { 1388: if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_DESTINATION)) <= 0) 1.1.1.7 root 1389: EnableWindow (GetDlgItem (hwndDlg, IDC_INSTALL), FALSE); 1.1 root 1390: else 1.1.1.7 root 1391: EnableWindow (GetDlgItem (hwndDlg, IDC_INSTALL), TRUE); 1.1 root 1392: return 1; 1393: } 1394: 1395: return 0; 1396: 1.1.1.11! root 1397: case WM_APP + 1: 1.1.1.7 root 1398: SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_INSTALL), GetString ("EXIT")); 1.1.1.11! root 1399: NormalCursor (); 1.1.1.7 root 1400: break; 1401: 1.1.1.11! root 1402: case WM_APP + 2: ! 1403: SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("FINALIZE")); ! 1404: NormalCursor (); 1.1.1.7 root 1405: break; 1406: 1.1 root 1407: case WM_CLOSE: 1408: EndDialog (hwndDlg, IDCANCEL); 1409: return 1; 1410: } 1411: 1412: return 0; 1413: } 1414: 1415: 1416: int WINAPI 1417: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, 1418: int nCmdShow) 1419: { 1420: if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */ 1421: 1.1.1.7 root 1422: lpszTitle = L"TrueCrypt Setup"; 1.1 root 1423: 1424: /* Call InitApp to initialize the common code */ 1.1.1.11! root 1425: InitApp (hInstance, NULL); 1.1 root 1426: 1.1.1.7 root 1427: if (IsAdmin () != TRUE) 1428: if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES) 1.1.1.11! root 1429: exit (1); 1.1 root 1430: 1.1.1.8 root 1431: /* Setup directory */ 1432: { 1433: char *s; 1434: GetModuleFileName (NULL, SetupFilesDir, sizeof (SetupFilesDir)); 1435: s = strrchr (SetupFilesDir, '\\'); 1436: if (s) 1437: s[1] = 0; 1438: } 1439: 1.1.1.7 root 1440: if (lpszCommandLine[0] == '/' && lpszCommandLine[1] == 'u') 1.1 root 1441: { 1442: bUninstall = TRUE; 1.1.1.7 root 1443: if (lpszCommandLine[2] == ' ') 1444: UninstallPath = &lpszCommandLine[3]; 1.1 root 1445: } 1446: 1.1.1.11! root 1447: // Force uninstall or stop setup when files are missing ! 1448: if (!bUninstall) ! 1449: { ! 1450: WIN32_FIND_DATA fd; ! 1451: HANDLE fh; ! 1452: ! 1453: SetCurrentDirectory (SetupFilesDir); ! 1454: ! 1455: fh = FindFirstFile ("Setup Files", &fd); ! 1456: if (fh == INVALID_HANDLE_VALUE) ! 1457: { ! 1458: fh = FindFirstFile ("TrueCrypt.exe", &fd); ! 1459: if (fh == INVALID_HANDLE_VALUE) ! 1460: { ! 1461: Error ("SETUP_INCOMPLETE"); ! 1462: exit (1); ! 1463: } ! 1464: else ! 1465: { ! 1466: FindClose (fh); ! 1467: bUninstall = TRUE; ! 1468: UninstallPath = SetupFilesDir; ! 1469: } ! 1470: } ! 1471: else ! 1472: FindClose (fh); ! 1473: } ! 1474: 1.1 root 1475: if (bUninstall == FALSE) 1476: { 1477: /* Create the main dialog box */ 1.1.1.7 root 1478: DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_INSTALL), NULL, (DLGPROC) InstallDlgProc); 1.1 root 1479: } 1480: else 1481: { 1482: /* Create the main dialog box */ 1.1.1.7 root 1483: DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) InstallDlgProc); 1.1.1.11! root 1484: ! 1485: if (UninstallBatch[0]) ! 1486: { ! 1487: STARTUPINFO si; ! 1488: PROCESS_INFORMATION pi; ! 1489: ! 1490: ZeroMemory (&si, sizeof (si)); ! 1491: si.cb = sizeof (si); ! 1492: si.dwFlags = STARTF_USESHOWWINDOW; ! 1493: si.wShowWindow = SW_HIDE; ! 1494: ! 1495: if (!CreateProcess (UninstallBatch, NULL, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi)) ! 1496: DeleteFile (UninstallBatch); ! 1497: } 1.1 root 1498: } 1499: 1500: /* Terminate */ 1.1.1.10 root 1501: cleanup (); 1.1.1.11! root 1502: 1.1 root 1503: return 0; 1504: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.