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