[ui] display a notice about Secure Boot when UEFI:NTFS is applied

This commit is contained in:
Pete Batard 2018-11-20 12:28:20 +00:00
parent 2ba62fa891
commit 15806de646
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
9 changed files with 98 additions and 37 deletions

View file

@ -31,6 +31,8 @@
#include <shlobj.h>
#include <commdlg.h>
#include <richedit.h>
#undef NDEBUG
#include <assert.h>
#include "rufus.h"
#include "missing.h"
@ -55,6 +57,7 @@ static WNDPROC pOrgBrowseWndproc;
static const SETTEXTEX friggin_microsoft_unicode_amateurs = {ST_DEFAULT, CP_UTF8};
static BOOL notification_is_question;
static const notification_info* notification_more_info;
static const char* notification_dont_display_setting;
static WNDPROC update_original_proc = NULL;
static HWINEVENTHOOK fp_weh = NULL;
static char *fp_title_str = "Microsoft Windows", *fp_button_str = "Format disk";
@ -659,11 +662,11 @@ INT_PTR CreateAboutBox(void)
INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT loc;
int i, dh;
int i, dh, cbh = 0;
// Prevent resizing
static LRESULT disabled[9] = { HTLEFT, HTRIGHT, HTTOP, HTBOTTOM, HTSIZE,
HTTOPLEFT, HTTOPRIGHT, HTBOTTOMLEFT, HTBOTTOMRIGHT };
static HBRUSH background_brush, separator_brush;
static HBRUSH background_brush, separator_brush, buttonface_brush;
// To use the system message font
NONCLIENTMETRICS ncm;
HFONT hDlgFont;
@ -677,9 +680,9 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
ncm.cbSize = sizeof(ncm);
// If we're compiling with the Vista SDK or later, the NONCLIENTMETRICS struct
// will be the wrong size for previous versions, so we need to adjust it.
#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
ncm.cbSize -= sizeof(ncm.iPaddedBorderWidth);
#endif
#endif
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
hDlgFont = CreateFontIndirect(&(ncm.lfMessageFont));
// Set the dialog to use the system message box font
@ -697,6 +700,7 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
apply_localization(IDD_NOTIFICATION, hDlg);
background_brush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
separator_brush = CreateSolidBrush(GetSysColor(COLOR_3DLIGHT));
buttonface_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
SetTitleBarIcon(hDlg);
CenterDialog(hDlg);
// Change the default icon
@ -713,6 +717,16 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
} else {
ShowWindow(GetDlgItem(hDlg, IDYES), SW_SHOW);
}
hCtrl = GetDlgItem(hDlg, IDC_DONT_DISPLAY_AGAIN);
if (notification_dont_display_setting != NULL) {
SetWindowTextU(hCtrl, lmprintf(MSG_127));
} else {
// Remove the "Don't display again" checkbox
ShowWindow(hCtrl, SW_HIDE);
GetWindowRect(hCtrl, &rc);
MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2);
cbh = rc.bottom - rc.top;
}
if ((notification_more_info != NULL) && (notification_more_info->callback != NULL)) {
hCtrl = GetDlgItem(hDlg, IDC_MORE_INFO);
// Resize the 'More information' button
@ -731,17 +745,16 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
GetWindowRect(hCtrl, &rc);
dh = rc.bottom - rc.top;
DrawTextU(hDC, szMessageText, -1, &rc, DT_CALCRECT | DT_WORDBREAK);
dh = rc.bottom - rc.top - dh + (int)(8.0f * fScale);
dh = max(rc.bottom - rc.top - dh + (int)(8.0f * fScale), 0);
safe_release_dc(hCtrl, hDC);
if (dh > 0) {
ResizeMoveCtrl(hDlg, hCtrl, 0, 0, 0, dh, 1.0f);
ResizeMoveCtrl(hDlg, hDlg, 0, 0, 0, dh, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, -1), 0, 0, 0, dh, 1.0f); // IDC_STATIC = -1
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDC_SELECTION_LINE), 0, dh, 0, 0, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDC_MORE_INFO), 0, dh, 0, 0, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDYES), 0, dh, 0, 0, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDNO), 0, dh, 0, 0, 1.0f);
}
ResizeMoveCtrl(hDlg, hCtrl, 0, 0, 0, dh, 1.0f);
ResizeMoveCtrl(hDlg, hDlg, 0, 0, 0, dh - cbh, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, -1), 0, 0, 0, dh, 1.0f); // IDC_STATIC = -1
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDC_SELECTION_LINE), 0, dh, 0, 0, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDC_DONT_DISPLAY_AGAIN), 0, dh, 0, 0, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDC_MORE_INFO), 0, dh - cbh, 0, 0, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDYES), 0, dh -cbh, 0, 0, 1.0f);
ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDNO), 0, dh -cbh, 0, 0, 1.0f);
}
return (INT_PTR)TRUE;
case WM_CTLCOLORSTATIC:
@ -750,6 +763,9 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
if ((HWND)lParam == GetDlgItem(hDlg, IDC_NOTIFICATION_LINE)) {
return (INT_PTR)separator_brush;
}
if ((HWND)lParam == GetDlgItem(hDlg, IDC_DONT_DISPLAY_AGAIN)) {
return (INT_PTR)buttonface_brush;
}
return (INT_PTR)background_brush;
case WM_NCHITTEST:
// Check coordinates to prevent resize actions
@ -766,11 +782,20 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
case IDCANCEL:
case IDYES:
case IDNO:
if (IsDlgButtonChecked(hDlg, IDC_DONT_DISPLAY_AGAIN) == BST_CHECKED) {
WriteSettingBool(SETTING_DISABLE_SECURE_BOOT_NOTICE, TRUE);
}
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
case IDC_MORE_INFO:
if (notification_more_info != NULL)
MyDialogBox(hMainInstance, notification_more_info->id, hDlg, notification_more_info->callback);
assert(notification_more_info->callback != NULL);
if (notification_more_info != NULL) {
if (notification_more_info->id == MORE_INFO_URL) {
ShellExecuteA(hDlg, "open", notification_more_info->url, NULL, NULL, SW_SHOWNORMAL);
} else {
MyDialogBox(hMainInstance, notification_more_info->id, hDlg, notification_more_info->callback);
}
}
break;
}
break;
@ -781,7 +806,7 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
/*
* Display a custom notification
*/
BOOL Notification(int type, const notification_info* more_info, char* title, char* format, ...)
BOOL Notification(int type, const char* dont_display_setting, const notification_info* more_info, char* title, char* format, ...)
{
BOOL ret;
va_list args;
@ -800,6 +825,7 @@ BOOL Notification(int type, const notification_info* more_info, char* title, cha
szMessageText[max_msg_size -1] = 0;
notification_more_info = more_info;
notification_is_question = FALSE;
notification_dont_display_setting = dont_display_setting;
switch(type) {
case MSG_WARNING_QUESTION:
@ -1478,7 +1504,6 @@ BOOL SetUpdateCheck(void)
{
BOOL enable_updates;
uint64_t commcheck = GetTickCount64();
notification_info more_info = { IDD_UPDATE_POLICY, UpdateCallback };
char filename[MAX_PATH] = "", exename[] = APPLICATION_NAME ".exe";
size_t fn_len, exe_len;
@ -1489,6 +1514,7 @@ BOOL SetUpdateCheck(void)
// If the update interval is not set, this is the first time we run so prompt the user
if (ReadSetting32(SETTING_UPDATE_INTERVAL) == 0) {
notification_info more_info;
// Add a hack for people who'd prefer the app not to prompt about update settings on first run.
// If the executable is called "rufus.exe", without version, we disable the prompt
@ -1501,7 +1527,9 @@ BOOL SetUpdateCheck(void)
enable_updates = TRUE;
} else {
#endif
enable_updates = Notification(MSG_QUESTION, &more_info, lmprintf(MSG_004), lmprintf(MSG_005));
more_info.id = IDD_UPDATE_POLICY;
more_info.callback = UpdateCallback;
enable_updates = Notification(MSG_QUESTION, NULL, &more_info, lmprintf(MSG_004), lmprintf(MSG_005));
#if !defined(_DEBUG)
}
#endif