diff options
Diffstat (limited to 'src/Setup/Wizard.c')
-rw-r--r-- | src/Setup/Wizard.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/Setup/Wizard.c b/src/Setup/Wizard.c index 7de3ef0c..abf76f69 100644 --- a/src/Setup/Wizard.c +++ b/src/Setup/Wizard.c @@ -18,62 +18,62 @@ #include <stdio.h> #include <time.h> #include "SelfExtract.h" #include "Wizard.h" #include "Dlgcode.h" #include "Language.h" #include "Common/Resource.h" #include "Resource.h" #include "Setup.h" #include "Registry.h" #include <tchar.h> #include <Strsafe.h> using namespace std; enum wizard_pages { INTRO_PAGE, #ifndef PORTABLE WIZARD_MODE_PAGE, INSTALL_OPTIONS_PAGE, INSTALL_PROGRESS_PAGE, #endif EXTRACTION_OPTIONS_PAGE, EXTRACTION_PROGRESS_PAGE, DONATIONS_PAGE }; HWND hCurPage = NULL; /* Handle to current wizard page */ int nCurPageNo = -1; /* The current wizard page */ -wchar_t WizardDestInstallPath [TC_MAX_PATH]; -wchar_t WizardDestExtractPath [TC_MAX_PATH]; +wchar_t WizardDestInstallPath [TC_MAX_PATH] = { 0 }; +wchar_t WizardDestExtractPath [TC_MAX_PATH] = { 0 }; wchar_t 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; BOOL bPromptTutorial = FALSE; BOOL bPromptReleaseNotes = FALSE; BOOL bPromptFastStartup = FALSE; extern BOOL bUserSetLanguage; int nPbar = 0; /* Control ID of progress bar */ static HFONT hDonTextFont; static BOOL OsPrngAvailable; static HCRYPTPROV hCryptProv; static int DonColorSchemeId; static COLORREF DonTextColor; static COLORREF DonBkgColor; wstring DonText = L""; void localcleanupwiz (void) { @@ -185,60 +185,61 @@ void LoadPage (HWND hwndDlg, int nPageNo) static int GetDonVal (int minVal, int maxVal) { static BOOL prngInitialized = FALSE; static unsigned __int8 buffer [2]; if (!prngInitialized) { if (!CryptAcquireContext (&hCryptProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) OsPrngAvailable = FALSE; else OsPrngAvailable = TRUE; prngInitialized = TRUE; } if (OsPrngAvailable && CryptGenRandom (hCryptProv, sizeof (buffer), buffer) != 0) { return ((int) ((double) *((uint16 *) buffer) / (0xFFFF+1) * (maxVal + 1 - minVal)) + minVal); } else return maxVal; } /* 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]; + static HWND hDisableMemProtectionTooltipWnd = NULL; WORD lw = LOWORD (wParam); WORD hw = HIWORD (wParam); hCurPage = hwndDlg; switch (uMsg) { case WM_INITDIALOG: LocalizeDialog (hwndDlg, "IDD_INSTL_DLG"); StringCbPrintfA (PageDebugId, sizeof(PageDebugId), "SETUP_WIZARD_PAGE_%d", nCurPageNo); LastDialogId = PageDebugId; switch (nCurPageNo) { case INTRO_PAGE: { char *licenseText = NULL; #ifdef PORTABLE bExtractOnly = TRUE; #endif // increase size limit of rich edit control SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), EM_EXLIMITTEXT, 0, -1); // Left margin for license text SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), EM_SETMARGINS, (WPARAM) EC_LEFTMARGIN, (LPARAM) CompensateXDPI (4)); licenseText = GetLegalNotices (); if (licenseText != NULL) @@ -412,63 +413,70 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa 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); if (bUpgrade) { SetWindowTextW (GetDlgItem (hwndDlg, IDT_INSTALL_DESTINATION), GetString ("SETUP_UPGRADE_DESTINATION")); EnableWindow (GetDlgItem (hwndDlg, IDC_DESTINATION), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_BROWSE), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_ALL_USERS), FALSE); wchar_t path[MAX_PATH]; SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0); bForAllUsers = (_waccess ((wstring (path) + L"\\" _T(TC_APP_NAME)).c_str(), 0) == 0); } // System Restore SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore); if (SystemRestoreDll == 0) { SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE); EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE); } + hDisableMemProtectionTooltipWnd = CreateToolTip (IDC_DISABLE_MEMORY_PROTECTION, hwndDlg, "DISABLE_MEMORY_PROTECTION_WARNING"); + // make IDC_DISABLE_MEMORY_PROTECTION control fit the text so that the tooltip is shown only when mouse is over the text + AccommodateCheckBoxTextWidth(hwndDlg, IDC_DISABLE_MEMORY_PROTECTION); + // make the help button adjacent to the checkbox + MakeControlsContiguous(hwndDlg, IDC_DISABLE_MEMORY_PROTECTION, IDC_DISABLE_MEMORY_PROTECTION_HELP); + SetCheckBox (hwndDlg, IDC_ALL_USERS, bForAllUsers); SetCheckBox (hwndDlg, IDC_FILE_TYPE, bRegisterFileExt); SetCheckBox (hwndDlg, IDC_PROG_GROUP, bAddToStartMenu); + SetCheckBox (hwndDlg, IDC_DISABLE_MEMORY_PROTECTION, bDisableMemoryProtection); SetCheckBox (hwndDlg, IDC_DESKTOP_ICON, bDesktopIcon); SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString (bUpgrade ? "UPGRADE" : "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); @@ -619,99 +627,111 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa #ifndef PORTABLE 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; return 1; } #endif if ( nCurPageNo == EXTRACTION_OPTIONS_PAGE && hw == EN_CHANGE ) { EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hCurPage, IDC_DESTINATION)) > 1)); return 1; } #ifndef PORTABLE if ( nCurPageNo == INSTALL_OPTIONS_PAGE && hw == EN_CHANGE ) { EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hCurPage, IDC_DESTINATION)) > 1)); return 1; } #endif if ( nCurPageNo == EXTRACTION_OPTIONS_PAGE ) { switch (lw) { case IDC_BROWSE: - if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestExtractPath)) + if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestExtractPath, WizardDestExtractPath)) { if (WizardDestExtractPath [wcslen(WizardDestExtractPath)-1] != L'\\') { StringCbCatW (WizardDestExtractPath, sizeof(WizardDestExtractPath), L"\\"); } SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestExtractPath); } return 1; case IDC_OPEN_CONTAINING_FOLDER: bOpenContainingFolder = IsButtonChecked (GetDlgItem (hCurPage, IDC_OPEN_CONTAINING_FOLDER)); return 1; } } #ifndef PORTABLE if ( nCurPageNo == INSTALL_OPTIONS_PAGE ) { switch (lw) { case IDC_BROWSE: - if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestInstallPath)) + if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestInstallPath, WizardDestInstallPath)) { if (WizardDestInstallPath [wcslen(WizardDestInstallPath)-1] != L'\\') { StringCbCatW (WizardDestInstallPath, sizeof(WizardDestInstallPath), L"\\"); } SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestInstallPath); } return 1; case IDC_SYSTEM_RESTORE: bSystemRestore = IsButtonChecked (GetDlgItem (hCurPage, IDC_SYSTEM_RESTORE)); return 1; case IDC_ALL_USERS: bForAllUsers = IsButtonChecked (GetDlgItem (hCurPage, IDC_ALL_USERS)); return 1; + case IDC_DISABLE_MEMORY_PROTECTION: + bDisableMemoryProtection = IsButtonChecked (GetDlgItem (hCurPage, IDC_DISABLE_MEMORY_PROTECTION)); + if (bDisableMemoryProtection) + { + Warning ("DISABLE_MEMORY_PROTECTION_WARNING", hwndDlg); + } + return 1; + + case IDC_DISABLE_MEMORY_PROTECTION_HELP: + Applink("memoryprotection"); + return 1; + case IDC_FILE_TYPE: bRegisterFileExt = IsButtonChecked (GetDlgItem (hCurPage, IDC_FILE_TYPE)); return 1; case IDC_PROG_GROUP: bAddToStartMenu = IsButtonChecked (GetDlgItem (hCurPage, IDC_PROG_GROUP)); return 1; case IDC_DESKTOP_ICON: bDesktopIcon = IsButtonChecked (GetDlgItem (hCurPage, IDC_DESKTOP_ICON)); return 1; } } #endif if (nCurPageNo == DONATIONS_PAGE) { switch (lw) { case IDC_DONATE: { Applink ("donate"); } return 1; } } return 0; @@ -733,60 +753,70 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa if (tmpBrush == NULL) AbortProcessSilent (); RECT trect; trect.left = 0; trect.right = CompensateXDPI (526); trect.top = 0; trect.bottom = CompensateYDPI (246); FillRect (hdc, &trect, tmpBrush); SetTextColor (hdc, DonTextColor); SetBkColor (hdc, DonBkgColor); } SetTextAlign(hdc, TA_CENTER); TextOutW (hdc, CompensateXDPI (258), CompensateYDPI (70), DonText.c_str(), DonText.length()); EndPaint (hCurPage, &tmpPaintStruct); ReleaseDC (hCurPage, hdc); } return 0; + case WM_DESTROY: + + if (hDisableMemProtectionTooltipWnd != NULL) + { + DestroyWindow (hDisableMemProtectionTooltipWnd); + hDisableMemProtectionTooltipWnd = NULL; + } + + break; + } return 0; } void InitProgressBar (void) { HWND hProgressBar = GetDlgItem (hCurPage, nPbar); SendMessage (hProgressBar, PBM_SETRANGE32, 0, 100); SendMessage (hProgressBar, PBM_SETSTEP, 1, 0); InvalidateRect (hProgressBar, NULL, TRUE); } // Must always return TRUE BOOL UpdateProgressBarProc (int nPercent) { HWND hProgressBar = GetDlgItem (hCurPage, nPbar); SendMessage (hProgressBar, PBM_SETPOS, (int) (100.0 * nPercent / 100), 0); InvalidateRect (hProgressBar, NULL, TRUE); ShowWindow(hProgressBar, SW_HIDE); ShowWindow(hProgressBar, SW_SHOW); // Prevent the IDC_LOG_WINDOW item from partially disappearing at higher DPIs ShowWindow(GetDlgItem (hCurPage, IDC_LOG_WINDOW), SW_HIDE); ShowWindow(GetDlgItem (hCurPage, IDC_LOG_WINDOW), SW_SHOW); RefreshUIGFX(); return TRUE; } void RefreshUIGFX (void) { @@ -826,60 +856,63 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa if (!CreateAppSetupMutex ()) AbortProcess ("TC_INSTALLER_IS_RUNNING"); InitDialog (hwndDlg); LocalizeDialog (hwndDlg, "IDD_INSTL_DLG"); // Resize the bitmap if the user has a non-default DPI if (ScreenDPI != USER_DEFAULT_SCREEN_DPI) { hbmWizardBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_SETUP_WIZARD), GetDlgItem (hwndDlg, IDC_BITMAP_SETUP_WIZARD), 0, 0, 0, 0, FALSE, TRUE); } // Gfx area background (must not keep aspect ratio; must retain Windows-imposed distortion) GetClientRect (GetDlgItem (hwndDlg, IDC_SETUP_WIZARD_GFX_AREA), &rec); SetWindowPos (GetDlgItem (hwndDlg, IDC_SETUP_WIZARD_BKG), HWND_TOP, 0, 0, rec.right, rec.bottom, SWP_NOMOVE); nPbar = IDC_PROGRESS_BAR; SendMessage (GetDlgItem (hwndDlg, IDC_BOX_TITLE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE); #ifndef PORTABLE SetWindowText (hwndDlg, L"VeraCrypt Setup " _T(VERSION_STRING) _T(VERSION_STRING_SUFFIX)); #else SetWindowText (hwndDlg, L"VeraCrypt Portable " _T(VERSION_STRING) _T(VERSION_STRING_SUFFIX)); #endif DonColorSchemeId = GetDonVal (2, 9); + // get the initial value of bDisableMemoryProtection by reading the registry + bDisableMemoryProtection = bOriginalDisableMemoryProtection = ReadMemoryProtectionConfig()? FALSE : TRUE; + if (bDevm) { InitWizardDestInstallPath (); bSystemRestore = FALSE; bRegisterFileExt = FALSE; bAddToStartMenu = FALSE; bDesktopIcon = TRUE; bLicenseAccepted = TRUE; bStartInstall = TRUE; #ifdef PORTABLE bExtractOnly = TRUE; LoadPage (hwndDlg, EXTRACTION_PROGRESS_PAGE); #else LoadPage (hwndDlg, INSTALL_PROGRESS_PAGE); #endif } else LoadPage (hwndDlg, INTRO_PAGE); } return 0; case WM_SYSCOMMAND: if (lw == IDC_ABOUT) { if (bLicenseAccepted) DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc); return 1; } |