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