📄 wizard.c
字号:
/*
Legal Notice: Some portions of the source code contained in this file were
derived from the source code of Encryption for the Masses 2.02a, which is
Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
Agreement for Encryption for the Masses'. Modifications and additions to
the original source code (contained in this file) and all other portions of
this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed
by the TrueCrypt License 2.6 the full text of which is contained in the
file License.txt included in TrueCrypt binary and source code distribution
packages. */
#include "Tcdefs.h"
#include "SelfExtract.h"
#include "Wizard.h"
#include "Dlgcode.h"
#include "Language.h"
#include "Common/Resource.h"
#include "Resource.h"
enum wizard_pages
{
INTRO_PAGE,
WIZARD_MODE_PAGE,
INSTALL_OPTIONS_PAGE,
INSTALL_PROGRESS_PAGE,
EXTRACTION_OPTIONS_PAGE,
EXTRACTION_PROGRESS_PAGE
};
HWND hCurPage = NULL; /* Handle to current wizard page */
int nCurPageNo = -1; /* The current wizard page */
char WizardDestInstallPath [TC_MAX_PATH];
char WizardDestExtractPath [TC_MAX_PATH];
char SelfFile [TC_MAX_PATH];
HBITMAP hbmWizardBitmapRescaled = NULL;
BOOL bExtractOnly = FALSE;
BOOL bLicenseAccepted = FALSE;
BOOL bOpenContainingFolder = TRUE;
BOOL bExtractionSuccessful = FALSE;
BOOL bStartInstall = FALSE;
BOOL bStartExtraction = FALSE;
BOOL bInProgress = FALSE;
int nPbar = 0; /* Control ID of progress bar */
void localcleanupwiz (void)
{
/* Delete buffered bitmaps (if any) */
if (hbmWizardBitmapRescaled != NULL)
{
DeleteObject ((HGDIOBJ) hbmWizardBitmapRescaled);
hbmWizardBitmapRescaled = NULL;
}
}
static void InitWizardDestInstallPath (void)
{
if (strlen (WizardDestInstallPath) < 2)
{
strcpy (WizardDestInstallPath, InstallationPath);
if (WizardDestInstallPath [strlen (WizardDestInstallPath) - 1] != '\\')
{
strcat (WizardDestInstallPath, "\\");
}
}
}
void LoadPage (HWND hwndDlg, int nPageNo)
{
RECT rD, rW;
if (hCurPage != NULL)
{
DestroyWindow (hCurPage);
}
GetWindowRect (GetDlgItem (hwndDlg, IDC_POS_BOX), &rW);
nCurPageNo = nPageNo;
switch (nPageNo)
{
case INTRO_PAGE:
hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INTRO_PAGE_DLG), hwndDlg,
(DLGPROC) PageDialogProc);
break;
case WIZARD_MODE_PAGE:
hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_WIZARD_MODE_PAGE_DLG), hwndDlg,
(DLGPROC) PageDialogProc);
break;
case INSTALL_OPTIONS_PAGE:
hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INSTALL_OPTIONS_PAGE_DLG), hwndDlg,
(DLGPROC) PageDialogProc);
break;
case INSTALL_PROGRESS_PAGE:
hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PROGRESS_PAGE_DLG), hwndDlg,
(DLGPROC) PageDialogProc);
break;
case EXTRACTION_OPTIONS_PAGE:
hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_EXTRACTION_OPTIONS_PAGE_DLG), hwndDlg,
(DLGPROC) PageDialogProc);
break;
case EXTRACTION_PROGRESS_PAGE:
hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PROGRESS_PAGE_DLG), hwndDlg,
(DLGPROC) PageDialogProc);
break;
}
rD.left = 15;
rD.top = 45;
rD.right = 0;
rD.bottom = 0;
MapDialogRect (hwndDlg, &rD);
if (hCurPage != NULL)
{
MoveWindow (hCurPage, rD.left, rD.top, rW.right - rW.left, rW.bottom - rW.top, TRUE);
ShowWindow (hCurPage, SW_SHOWNORMAL);
}
/* Refresh the graphics (white background of some texts, etc.) */
RefreshUIGFX ();
}
/* Except in response to the WM_INITDIALOG message, the dialog box procedure
should return nonzero if it processes the message, and zero if it does
not. - see DialogProc */
BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static char PageDebugId[128];
WORD lw = LOWORD (wParam);
WORD hw = HIWORD (wParam);
hCurPage = hwndDlg;
switch (uMsg)
{
case WM_INITDIALOG:
LocalizeDialog (hwndDlg, "IDD_INSTL_DLG");
sprintf (PageDebugId, "SETUP_WIZARD_PAGE_%d", nCurPageNo);
LastDialogId = PageDebugId;
switch (nCurPageNo)
{
case INTRO_PAGE:
{
char *licenseText = NULL;
licenseText = GetLegalNotices ();
if (licenseText != NULL)
{
SetWindowText (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), licenseText);
free (licenseText);
}
else
{
Error("CANNOT_DISPLAY_LICENSE");
exit (1);
}
/* Some of the following texts cannot be localized by third parties for legal reasons. */
SetCheckBox (hwndDlg, IDC_AGREE, bLicenseAccepted);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), L"License");
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), L"You must accept these license terms before you can use, extract, or install TrueCrypt.");
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), L"IMPORTANT: By checking the checkbox below and clicking Accept, you accept these license terms and agree to be bound by and to comply with them. Click the 'arrow down' icon to see the rest of the license.");
//SendMessage (GetDlgItem (hwndDlg, IDC_BOX_HELP), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
SetWindowTextW (GetDlgItem (hwndDlg, IDC_AGREE), L"I a&ccept and agree to be bound by the license terms");
//SetWindowTextW (GetDlgItem (hwndDlg, IDC_DISAGREE), L"I &do not accept the license terms");
//SendMessage (GetDlgItem (hwndDlg, IDC_AGREE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
//SendMessage (GetDlgItem (hwndDlg, IDC_DISAGREE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
EnableWindow (GetDlgItem (hwndDlg, IDC_AGREE), TRUE);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), L"&Accept"); // Cannot be localized by third parties for legal reasons.
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), bLicenseAccepted);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), bLicenseAccepted);
// Left margin for license text
SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), EM_SETMARGINS, (WPARAM) EC_LEFTMARGIN, (LPARAM) CompensateXDPI (4));
}
return 1;
case WIZARD_MODE_PAGE:
if (bRepairMode)
{
SetWindowTextW (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), GetString ("REPAIR_REINSTALL"));
bExtractOnly = FALSE;
}
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_MODE_TITLE"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_MODE_INFO"));
SendMessage (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
SendMessage (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_EXTRACT_ONLY), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
CheckButton (GetDlgItem (hwndDlg, bExtractOnly ? IDC_WIZARD_MODE_EXTRACT_ONLY : IDC_WIZARD_MODE_INSTALL));
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SETUP_MODE_HELP_EXTRACT"));
if (!bRepairMode)
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP2), GetString ("SETUP_MODE_HELP_INSTALL"));
EnableWindow (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_EXTRACT_ONLY), !bRepairMode);
EnableWindow (GetDlgItem (hwndDlg, IDC_BOX_HELP), !bRepairMode);
EnableWindow (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), TRUE);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
return 1;
case EXTRACTION_OPTIONS_PAGE:
if (strlen(WizardDestExtractPath) < 2)
{
strcpy (WizardDestExtractPath, SetupFilesDir);
strncat (WizardDestExtractPath, "TrueCrypt\\", sizeof (WizardDestExtractPath) - strlen (WizardDestExtractPath) - 1);
}
SendMessage (GetDlgItem (hwndDlg, IDC_DESTINATION), EM_LIMITTEXT, TC_MAX_PATH - 1, 0);
SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestExtractPath);
SetCheckBox (hwndDlg, IDC_OPEN_CONTAINING_FOLDER, bOpenContainingFolder);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("EXTRACTION_OPTIONS_TITLE"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("EXTRACTION_OPTIONS_INFO"));
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AUTO_FOLDER_CREATION"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("EXTRACT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
return 1;
case EXTRACTION_PROGRESS_PAGE:
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("EXTRACTING_VERB"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("EXTRACTION_PROGRESS_INFO"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
if (bStartExtraction)
{
/* Start extraction */
LastDialogId = "EXTRACTION_IN_PROGRESS";
WaitCursor ();
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), FALSE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), FALSE);
if (WizardDestExtractPath [strlen(WizardDestExtractPath)-1] != '\\')
strcat (WizardDestExtractPath, "\\");
strcpy (DestExtractPath, WizardDestExtractPath);
InitProgressBar ();
bInProgress = TRUE;
bStartExtraction = FALSE;
_beginthread (ExtractAllFilesThread, 0, (void *) hwndDlg);
}
else
{
NormalCursor ();
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
}
return 1;
case INSTALL_OPTIONS_PAGE:
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_OPTIONS_TITLE"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_OPTIONS_INFO"));
SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AUTO_FOLDER_CREATION"));
InitWizardDestInstallPath ();
SendMessage (GetDlgItem (hwndDlg, IDC_DESTINATION), EM_LIMITTEXT, TC_MAX_PATH - 1, 0);
SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestInstallPath);
// System Restore
SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
if (SystemRestoreDll == 0)
{
SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
}
#if 0
// Swap files
SetCheckBox (hwndDlg, IDC_DISABLE_PAGING_FILES, bDisableSwapFiles);
if (nCurrentOS == WIN_2000)
{
bDisableSwapFiles = FALSE;
SetCheckBox (hwndDlg, IDC_DISABLE_PAGING_FILES, FALSE);
EnableWindow (GetDlgItem (hwndDlg, IDC_DISABLE_PAGING_FILES), FALSE);
}
#endif // 0
SetCheckBox (hwndDlg, IDC_ALL_USERS, bForAllUsers);
SetCheckBox (hwndDlg, IDC_FILE_TYPE, bRegisterFileExt);
SetCheckBox (hwndDlg, IDC_PROG_GROUP, bAddToStartMenu);
SetCheckBox (hwndDlg, IDC_DESKTOP_ICON, bDesktopIcon);
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("INSTALL"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
return 1;
case INSTALL_PROGRESS_PAGE:
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_PROGRESS_TITLE"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_PROGRESS_INFO"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
if (bStartInstall)
{
/* Start install */
LastDialogId = "INSTALL_IN_PROGRESS";
SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), FALSE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), FALSE);
InitProgressBar ();
if (WizardDestInstallPath [strlen(WizardDestInstallPath)-1] != '\\')
strcat (WizardDestInstallPath, "\\");
strcpy (InstallationPath, WizardDestInstallPath);
WaitCursor ();
bInProgress = TRUE;
bStartInstall = FALSE;
_beginthread (DoInstall, 0, (void *) hwndDlg);
}
else
{
NormalCursor ();
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
}
return 1;
}
return 0;
case WM_HELP:
if (bLicenseAccepted)
OpenPageHelp (GetParent (hwndDlg), nCurPageNo);
return 1;
case WM_ENDSESSION:
EndDialog (MainDlg, 0);
localcleanup ();
return 0;
case WM_COMMAND:
if (lw == IDC_AGREE && nCurPageNo == INTRO_PAGE)
{
EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), IsButtonChecked (GetDlgItem (hwndDlg, IDC_AGREE)));
return 1;
}
if (lw == IDC_WIZARD_MODE_EXTRACT_ONLY && nCurPageNo == WIZARD_MODE_PAGE)
{
bExtractOnly = TRUE;
return 1;
}
if (lw == IDC_WIZARD_MODE_INSTALL && nCurPageNo == WIZARD_MODE_PAGE)
{
bExtractOnly = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -