|
|
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
3: additions to that source code contained in this file are Copyright (c) 2004
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: {
373: bResult = CopyFile (szFiles[i] + 1, szTmp, FALSE);
374: if (!bResult)
375: {
376: char s[256];
377: sprintf (s, "Setup Files\\%s", szFiles[i] + 1);
378: bResult = CopyFile (s, szTmp, FALSE);
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;
618: char szTmp[128];
619: int x;
620:
621: if (nCurrentOS != WIN_NT)
622: return TRUE;
623: else
624: memset (&status, 0, sizeof (status)); /* Keep VC6 quiet */
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:
677: try_delete:
678: sprintf (szTmp, "deleting %s", lpszService);
679: ServiceMessage (hwndDlg, szTmp);
680:
681: if (hService != NULL)
682: CloseServiceHandle (hService);
683:
684: if (hManager != NULL)
685: CloseServiceHandle (hManager);
686:
687: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
688: if (hManager == NULL)
689: goto error;
690:
691: hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
692: if (hService == NULL)
693: goto error;
694:
695: bRet = DeleteService (hService);
696: if (bRet == FALSE)
697: goto error;
698:
699: bOK = TRUE;
700:
701: error:
702: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
703: {
704: handleWin32Error (hwndDlg);
705: MessageBox (hwndDlg, "The uninstallation of the device driver has failed", lpszTitle, MB_ICONHAND);
706: }
707: else
708: bOK = TRUE;
709:
710: if (hService != NULL)
711: CloseServiceHandle (hService);
712:
713: if (hManager != NULL)
714: CloseServiceHandle (hManager);
715:
716: return bOK;
717: }
718:
719: BOOL
720: DoDriverUnload (HWND hwndDlg)
721: {
722: BOOL bOK = TRUE;
723: int status;
724:
725: status = DriverAttach ();
726: if (status != 0)
727: {
728: if (status == ERR_OS_ERROR && GetLastError ()!= ERROR_FILE_NOT_FOUND)
729: {
730: handleWin32Error (hwndDlg);
731: AbortProcess (IDS_NODRIVER);
732: }
733:
734: if (status != ERR_OS_ERROR)
735: {
736: handleError (NULL, status);
737: AbortProcess (IDS_NODRIVER);
738: }
739: }
740:
741: if (hDriver != INVALID_HANDLE_VALUE)
742: {
1.1.1.3 root 743: MOUNT_LIST_STRUCT driver;
744: DWORD dwResult;
745: BOOL bResult;
1.1 root 746:
1.1.1.3 root 747: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver,
748: sizeof (driver), &dwResult, NULL);
1.1 root 749:
1.1.1.3 root 750: if (bResult == TRUE)
1.1 root 751: {
1.1.1.3 root 752: if (driver.ulMountedDrives != 0)
1.1 root 753: {
754: bOK = FALSE;
1.1.1.5 ! root 755: MessageBox (hwndDlg, "Volumes are still mounted! All volumes must be dismounted before installation can continue.", lpszTitle, MB_ICONHAND);
1.1 root 756: }
757: }
758: else
759: {
1.1.1.3 root 760: bOK = FALSE;
761: handleWin32Error (hwndDlg);
1.1 root 762: }
763:
764: CloseHandle (hDriver);
765: hDriver = INVALID_HANDLE_VALUE;
766:
767: }
768:
769: return bOK;
770: }
771:
772:
773: BOOL
774: DoDriverInstall (HWND hwndDlg)
775: {
776: SC_HANDLE hManager, hService = NULL;
777: BOOL bOK = FALSE, bRet, bSlash;
778: char szDir[TC_MAX_PATH];
779: int x;
780:
781: if (nCurrentOS != WIN_NT)
782: return TRUE;
783:
784: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
785: if (hManager == NULL)
786: goto error;
787:
788: GetSystemDirectory (szDir, sizeof (szDir));
789:
790: x = strlen (szDir);
791: if (szDir[x - 1] == '\\')
792: bSlash = TRUE;
793: else
794: bSlash = FALSE;
795:
796: if (bSlash == FALSE)
797: strcat (szDir, "\\");
798:
799: strcat (szDir, "Drivers\\truecrypt.sys");
800:
801: ServiceMessage (hwndDlg, "installing TrueCrypt driver service");
802:
803: hService = CreateService (hManager, "truecrypt", "truecrypt",
804: SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
805: szDir, NULL, NULL, NULL, NULL, NULL
806: );
807: if (hService == NULL)
808: goto error;
809: else
810: CloseServiceHandle (hService);
811:
812: hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS);
813: if (hService == NULL)
814: goto error;
815:
816: ServiceMessage (hwndDlg, "starting TrueCrypt driver service");
817:
818: bRet = StartService (hService, 0, NULL);
819: if (bRet == FALSE)
820: goto error;
821:
822: bOK = TRUE;
823:
824: error:
825: if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_ALREADY_RUNNING)
826: {
827: handleWin32Error (hwndDlg);
828: MessageBox (hwndDlg, "The installation of the device driver has failed", lpszTitle, MB_ICONHAND);
829: }
830: else
831: bOK = TRUE;
832:
833: if (hService != NULL)
834: CloseServiceHandle (hService);
835:
836: if (hManager != NULL)
837: CloseServiceHandle (hManager);
838:
839: return bOK;
840: }
841:
842: BOOL
843: DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
844: {
845: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
846: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
847: BOOL bSlash, bOK = FALSE;
848: HRESULT hOle;
849: int x;
850: BOOL allUsers = FALSE;
851:
852: hOle = OleInitialize (NULL);
853:
854: // User start menu
855: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
856: x = strlen (szLinkDir);
857: if (szLinkDir[x - 1] == '\\')
858: bSlash = TRUE;
859: else
860: bSlash = FALSE;
861:
862: if (bSlash == FALSE)
863: strcat (szLinkDir, "\\");
864:
865: strcat (szLinkDir, "TrueCrypt");
866:
867: // Global start menu
868: if (nCurrentOS == WIN_NT)
869: {
870: struct _stat st;
871: char path[TC_MAX_PATH];
872:
873: SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
874: strcat (path, "\\TrueCrypt");
875:
876: if (_stat (path, &st) == 0)
877: {
878: strcpy (szLinkDir, path);
879: allUsers = TRUE;
880: }
881: }
882:
883: // Start menu entries
884: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
885: RemoveMessage (hwndDlg, szTmp2);
886: if (StatDeleteFile (szTmp2) == FALSE)
887: goto error;
888:
889: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
890: RemoveMessage (hwndDlg, szTmp2);
891: if (StatDeleteFile (szTmp2) == FALSE)
892: goto error;
893:
894: GetWindowsDirectory (szDir, sizeof (szDir));
895: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
896: RemoveMessage (hwndDlg, szTmp2);
897: if (StatDeleteFile (szTmp2) == FALSE)
898: goto error;
899:
900: // Start menu group
901: RemoveMessage ((HWND) hwndDlg, szLinkDir);
902: if (StatRemoveDirectory (szLinkDir) == FALSE)
903: {
904: handleWin32Error ((HWND) hwndDlg);
905: goto error;
906: }
907:
908: // Desktop icon
909:
910: if (allUsers)
911: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
912: else
913: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
914:
915: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
916:
917: RemoveMessage (hwndDlg, szTmp2);
918: if (StatDeleteFile (szTmp2) == FALSE)
919: goto error;
920:
921: bOK = TRUE;
922:
923: error:
924: OleUninitialize ();
925:
926: return bOK;
927: }
928:
929: BOOL
930: DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
931: {
932: char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
933: char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH];
934: BOOL bSlash, bOK = FALSE;
935: HRESULT hOle;
936: int x;
937:
938: if (bProgGroup == FALSE && bDesktopIcon == FALSE)
939: return TRUE;
940:
941: hOle = OleInitialize (NULL);
942:
943: GetProgramPath (hwndDlg, szLinkDir);
944:
945: x = strlen (szLinkDir);
946: if (szLinkDir[x - 1] == '\\')
947: bSlash = TRUE;
948: else
949: bSlash = FALSE;
950:
951: if (bSlash == FALSE)
952: strcat (szLinkDir, "\\");
953:
954: strcat (szLinkDir, "TrueCrypt");
955:
956: strcpy (szDir, szDestDir);
957: x = strlen (szDestDir);
958: if (szDestDir[x - 1] == '\\')
959: bSlash = TRUE;
960: else
961: bSlash = FALSE;
962:
963: if (bSlash == FALSE)
964: strcat (szDir, "\\");
965:
966: if (bProgGroup)
967: {
968: if (mkfulldir (szLinkDir, TRUE) != 0)
969: {
970: char szTmp[TC_MAX_PATH];
971: int x;
972:
973: //sprintf (szTmp, "The program folder '%s' does not exist. Do you want to create this folder?", szLinkDir);
974: //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
975: //if (x == IDNO)
976: //{
977: // goto error;
978: //}
979:
980: if (mkfulldir (szLinkDir, FALSE) != 0)
981: {
982: handleWin32Error (hwndDlg);
983: sprintf (szTmp, "The folder '%s' could not be created", szLinkDir);
984: MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
985: goto error;
986: }
987: }
988:
989: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
990: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
991:
992: IconMessage (hwndDlg, szTmp2);
993: if (CreateLink (szTmp, "", szTmp2) != S_OK)
994: goto error;
995:
996:
997: sprintf (szTmp, "%s%s", szDir, "TrueCrypt User Guide.pdf");
998: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
999:
1000: IconMessage (hwndDlg, szTmp2);
1001: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1002: goto error;
1003:
1004: GetWindowsDirectory (szDir, sizeof (szDir));
1005: x = strlen (szDir);
1006: if (szDir[x - 1] == '\\')
1007: bSlash = TRUE;
1008: else
1009: bSlash = FALSE;
1010:
1011: if (bSlash == FALSE)
1012: strcat (szDir, "\\");
1013:
1014: sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
1015: sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
1016:
1017: IconMessage (hwndDlg, szTmp2);
1018: if (CreateLink (szTmp, "/u", szTmp2) != S_OK)
1019: goto error;
1020:
1021: }
1022:
1023: if (bDesktopIcon)
1024: {
1025: strcpy (szDir, szDestDir);
1026: x = strlen (szDestDir);
1027: if (szDestDir[x - 1] == '\\')
1028: bSlash = TRUE;
1029: else
1030: bSlash = FALSE;
1031:
1032: if (bSlash == FALSE)
1033: strcat (szDir, "\\");
1034:
1035: if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
1036: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
1037: else
1038: SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
1039:
1040: sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
1041: sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
1042:
1043: IconMessage (hwndDlg, szTmp2);
1044:
1045: if (CreateLink (szTmp, "", szTmp2) != S_OK)
1046: goto error;
1047: }
1048:
1049: bOK = TRUE;
1050:
1051: error:
1052: OleUninitialize ();
1053:
1054: return bOK;
1055: }
1056:
1057:
1058: void
1059: RebootPrompt (HWND hwndDlg, BOOL bOK)
1060: {
1061: if (bOK == TRUE)
1062: {
1063: SetWindowText (GetDlgItem ((HWND) hwndDlg, IDOK), "E&xit");
1064:
1065: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
1066:
1067: bDone = TRUE;
1068:
1069: if (nCurrentOS == WIN_NT)
1070: {
1071: if (bUninstall == FALSE)
1072: MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.", lpszTitle, MB_ICONINFORMATION);
1073: else
1074: MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.", lpszTitle, MB_ICONINFORMATION);
1075: }
1076: else
1077: {
1078: int x;
1079:
1080: if (bUninstall == FALSE)
1081: x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.\nTo use TrueCrypt your system must be restarted.", lpszTitle, MB_ICONINFORMATION);
1082: else
1083: x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.\nYour system must be restarted.", lpszTitle, MB_ICONINFORMATION);
1084: }
1085: }
1086: else
1087: {
1088: if (bUninstall == FALSE)
1089: MessageBox ((HWND) hwndDlg, "The installation has failed!", lpszTitle, MB_ICONHAND);
1090: else
1091: MessageBox ((HWND) hwndDlg, "The uninstall has failed!", lpszTitle, MB_ICONHAND);
1092: }
1093: }
1094:
1095: static void SetSystemRestorePoint (void *hwndDlg, BOOL finalize)
1096: {
1097: static RESTOREPOINTINFO RestPtInfo;
1098: static STATEMGRSTATUS SMgrStatus;
1099: static BOOL failed = FALSE;
1100: static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
1101:
1102: if (!SystemRestoreDll) return;
1103:
1104: _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
1105: if (_SRSetRestorePoint == 0)
1106: {
1107: FreeLibrary (SystemRestoreDll);
1108: SystemRestoreDll = 0;
1109: return;
1110: }
1111:
1112: if (!finalize)
1113: {
1114: StatusMessage (hwndDlg, "%s", "Creating system restore point");
1115:
1116: // Initialize the RESTOREPOINTINFO structure
1117: RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
1118:
1119: // Notify the system that changes are about to be made.
1120: // An application is to be installed.
1121: RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
1122:
1123: // Set RestPtInfo.llSequenceNumber.
1124: RestPtInfo.llSequenceNumber = 0;
1125:
1126: // String to be displayed by System Restore for this restore point.
1127: strcpy(RestPtInfo.szDescription, "TrueCrypt installation");
1128:
1129: // Notify the system that changes are to be made and that
1130: // the beginning of the restore point should be marked.
1131: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
1132: {
1133: StatusMessage (hwndDlg, "%s", "Failed to create System Restore point!");
1134: failed = TRUE;
1135: }
1136:
1137: return;
1138: }
1139:
1140: if (failed) return;
1141:
1142: StatusMessage (hwndDlg, "%s", "Closing system restore point");
1143:
1144: // The application performs some installation operations here.
1145:
1146: // Re-initialize the RESTOREPOINTINFO structure to notify the
1147: // system that the operation is finished.
1148: RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
1149:
1150: // End the system change by returning the sequence number
1151: // received from the first call to SRSetRestorePoint.
1152: RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
1153:
1154: // Notify the system that the operation is done and that this
1155: // is the end of the restore point.
1156: if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
1157: {
1158: StatusMessage (hwndDlg, "%s", "Closing system restore point failed!");
1159: }
1160: else
1161: StatusMessage (hwndDlg, "%s", "System restore point created");
1162:
1163: }
1164:
1165: void
1166: DoUninstall (void *hwndDlg)
1167: {
1168: BOOL bOK = TRUE;
1169:
1170: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
1171:
1172: WaitCursor ();
1173:
1174: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
1175:
1176: if (DoDriverUnload (hwndDlg) == FALSE)
1177: {
1178: bOK = FALSE;
1179: }
1180: else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
1181: {
1182: bOK = FALSE;
1183: }
1184: else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1185: {
1186: bOK = FALSE;
1187: }
1188: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, FALSE) == FALSE)
1189: {
1190: bOK = FALSE;
1191: }
1192: else if (DoRegUninstall ((HWND) hwndDlg) == FALSE)
1193: {
1194: bOK = FALSE;
1195: }
1196: else if (DoShortcutsUninstall (hwndDlg, dlg_file_name) == FALSE)
1197: {
1198: bOK = FALSE;
1199: }
1200: else
1201: {
1202: RemoveMessage ((HWND) hwndDlg, dlg_file_name);
1203: if (StatRemoveDirectory (dlg_file_name) == FALSE)
1204: {
1205: handleWin32Error ((HWND) hwndDlg);
1206: bOK = FALSE;
1207: }
1208: }
1209:
1210: NormalCursor ();
1211:
1212: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
1213:
1214: RebootPrompt (hwndDlg, bOK);
1215:
1216: }
1217:
1218: void
1219: DoInstall (void *hwndDlg)
1220: {
1221: BOOL bOK = TRUE;
1222:
1223: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);
1224:
1225: WaitCursor ();
1226:
1227: SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);
1228:
1229: if (DoDriverUnload (hwndDlg) == FALSE)
1230: {
1.1.1.4 root 1231: NormalCursor ();
1232: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
1233: return;
1.1 root 1234: }
1.1.1.4 root 1235:
1236: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
1237: {
1238: SetSystemRestorePoint (hwndDlg, FALSE);
1239: }
1240:
1241: if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
1.1 root 1242: {
1243: bOK = FALSE;
1244: }
1245: else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
1246: {
1247: bOK = FALSE;
1248: }
1249: else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
1250: {
1251: bOK = FALSE;
1252: }
1253: else if (DoRegInstall ((HWND) hwndDlg, dlg_file_name,
1254: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_FILE_TYPE)),
1255: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL))) == FALSE)
1256: {
1257: bOK = FALSE;
1258: }
1259: else if (DoDriverInstall (hwndDlg) == FALSE)
1260: {
1261: bOK = FALSE;
1262: }
1263: else if (DoShortcutsInstall (hwndDlg, dlg_file_name,
1264: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_PROG_GROUP)),
1265: IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_DESKTOP_ICON))) == FALSE)
1266: {
1267: bOK = FALSE;
1268: }
1269:
1270: if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
1271: SetSystemRestorePoint (hwndDlg, TRUE);
1272:
1273: if (bOK)
1274: StatusMessage (hwndDlg, "%s", "Installation completed.");
1275:
1276: NormalCursor ();
1277:
1278: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
1279:
1280: RebootPrompt (hwndDlg, bOK);
1281: }
1282:
1283:
1284: BOOL WINAPI
1285: InstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1286: {
1287: WORD lw = LOWORD (wParam);
1288: if (lParam); /* remove warning */
1289:
1290: switch (msg)
1291: {
1292: case WM_INITDIALOG:
1293: SetDefaultUserFont (hwndDlg);
1294: InitDialog (hwndDlg);
1295:
1.1.1.3 root 1296: {
1297: char path[MAX_PATH+20];
1298: ITEMIDLIST *i;
1299: SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &i);
1300: SHGetPathFromIDList (i, path);
1301: strcat (path, "\\TrueCrypt");
1302: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), path);
1303: }
1.1 root 1304:
1305: if (bUninstall == FALSE)
1306: {
1307: SendMessage (GetDlgItem (hwndDlg, IDC_FILES), LB_ADDSTRING, 0, (LPARAM) "By clicking 'Install', you accept the license agreement.");
1308:
1309: LoadLicense (hwndDlg);
1310: }
1311:
1312: SendMessage (GetDlgItem (hwndDlg, IDC_ALL_USERS), BM_SETCHECK, BST_CHECKED, 0);
1313: if (nCurrentOS != WIN_NT)
1314: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_ALL_USERS), FALSE);
1315:
1316: SendMessage (GetDlgItem (hwndDlg, IDC_FILE_TYPE), BM_SETCHECK, BST_CHECKED, 0);
1317: SendMessage (GetDlgItem (hwndDlg, IDC_UNINSTALL), BM_SETCHECK, BST_CHECKED, 0);
1318: SendMessage (GetDlgItem (hwndDlg, IDC_PROG_GROUP), BM_SETCHECK, BST_CHECKED, 0);
1319: SendMessage (GetDlgItem (hwndDlg, IDC_DESKTOP_ICON), BM_SETCHECK, BST_CHECKED, 0);
1320:
1321: // System Restore
1322: SystemRestoreDll = LoadLibrary("srclient.dll");
1323:
1324: if (SystemRestoreDll != 0)
1325: SendMessage (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), BM_SETCHECK, BST_CHECKED, 0);
1326: else
1327: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
1328:
1329: SetWindowText (hwndDlg, lpszTitle);
1330: return 1;
1331:
1332: case WM_SYSCOMMAND:
1333: if (lw == IDC_ABOUT)
1334: {
1335: DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1336: return 1;
1337: }
1338: return 0;
1339:
1340: case WM_COMMAND:
1341: if (lw == IDOK)
1342: {
1343: char szDirname[TC_MAX_PATH];
1344:
1345: if (bDone == TRUE)
1346: {
1347: EndDialog (hwndDlg, IDOK);
1348: return 1;
1349: }
1350:
1351: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
1352:
1353: if (bUninstall == FALSE)
1354: {
1355: if (mkfulldir (szDirname, TRUE) != 0)
1356: {
1357: char szTmp[TC_MAX_PATH];
1358: int x;
1359:
1360: //sprintf (szTmp, "The directory '%s' does not exist. Do you want to create this directory?", szDirname);
1361: //x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
1362: //if (x == IDNO)
1363: //{
1364: // SetFocus (GetDlgItem (hwndDlg, IDC_DESTINATION));
1365: // return 1;
1366: //}
1367:
1368: if (mkfulldir (szDirname, FALSE) != 0)
1369: {
1370: handleWin32Error (hwndDlg);
1371: sprintf (szTmp, "The directory '%s' could not be created", szDirname);
1372: MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
1373: return 1;
1374: }
1375:
1376: }
1377: }
1378:
1379: strcpy (dlg_file_name, szDirname);
1380:
1381: if (bUninstall == FALSE)
1382: _beginthread (DoInstall, 16384, (void *) hwndDlg);
1383: else
1384: _beginthread (DoUninstall, 16384, (void *) hwndDlg);
1385:
1386: return 1;
1387: }
1388:
1389: if (lw == IDCANCEL)
1390: {
1391: EndDialog (hwndDlg, IDCANCEL);
1392: return 1;
1393: }
1394:
1395: if (lw == IDC_BROWSE)
1396: {
1397: char szDirname[TC_MAX_PATH];
1398:
1399: GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));
1400:
1401: if (BrowseFiles2 (hwndDlg, "Please select a folder", szDirname) == TRUE)
1402: SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname);
1403:
1404: return 1;
1405: }
1406:
1407: if (lw == IDC_DESTINATION && HIWORD (wParam) == EN_CHANGE && bDone == FALSE)
1408: {
1409: if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_DESTINATION)) <= 0)
1410: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
1411: else
1412: EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
1413: return 1;
1414: }
1415:
1416: return 0;
1417:
1418: case WM_CLOSE:
1419: EndDialog (hwndDlg, IDCANCEL);
1420: return 1;
1421: }
1422:
1423: return 0;
1424: }
1425:
1426:
1427: int WINAPI
1428: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
1429: int nCmdShow)
1430: {
1431: if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
1432:
1433: lpszTitle = "TrueCrypt Setup";
1434:
1435: /* Call InitApp to initialize the common code */
1436: InitApp (hInstance);
1437:
1.1.1.2 root 1438: if (CurrentOSMajor < 5)
1439: {
1440: MessageBox (NULL, "TrueCrypt requires at least Windows 2000 to run.", lpszTitle, MB_ICONSTOP);
1441: return 0;
1442: }
1443:
1.1 root 1444: if (nCurrentOS == WIN_NT && IsAdmin ()!= TRUE)
1.1.1.5 ! root 1445: if (MessageBox (NULL, "To successfully install/uninstall TrueCrypt you must have Administrator rights, "
1.1 root 1446: "do you still want to continue?", lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
1447: return 0;
1448:
1449: if (lpszCommandLine[0] == '/' && (lpszCommandLine[1] == 'u' || lpszCommandLine[1] == 'U'))
1450: {
1451: bUninstall = TRUE;
1452: }
1453:
1454: if (bUninstall == FALSE)
1455: {
1.1.1.4 root 1456: if (CurrentOSMajor == 5 && CurrentOSMinor == 0)
1457: MessageBox (NULL, "If you are upgrading from a previous version of TrueCrypt\nyou should first uninstall TrueCrypt and reboot system.", lpszTitle, MB_ICONINFORMATION);
1458:
1.1 root 1459: /* Create the main dialog box */
1460: DialogBox (hInstance, MAKEINTRESOURCE (IDD_INSTALL), NULL, (DLGPROC) InstallDlgProc);
1461: }
1462: else
1463: {
1464: /* Create the main dialog box */
1465: DialogBox (hInstance, MAKEINTRESOURCE (IDD_UNINSTALL), NULL, (DLGPROC) InstallDlgProc);
1466: }
1467:
1468: /* Terminate */
1469: return 0;
1470: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.