[misc] remove no longer needed XP workarounds

This commit is contained in:
Pete Batard 2017-11-13 14:29:48 +00:00
parent c5f4e5a2ee
commit 903ac993f2
23 changed files with 299 additions and 937 deletions

View file

@ -47,14 +47,6 @@
#include "../res/grub/grub_version.h"
#include "../res/grub2/grub2_version.h"
// ImageList calls are unavailable on XP
PF_TYPE_DECL(WINAPI, HIMAGELIST, ImageList_Create, (int, int, UINT, int, int));
PF_TYPE_DECL(WINAPI, int, ImageList_AddIcon, (HIMAGELIST, HICON));
PF_TYPE_DECL(WINAPI, int, ImageList_ReplaceIcon, (HIMAGELIST, int, HICON));
PF_TYPE_DECL(WINAPI, BOOL, SHChangeNotifyDeregister, (ULONG));
PF_TYPE_DECL(WINAPI, ULONG, SHChangeNotifyRegister, (HWND, int, LONG, UINT, int, const MY_SHChangeNotifyEntry*));
const char* cmdline_hogger = "rufus.com";
const char* FileSystemLabel[FS_MAX] = { "FAT", "FAT32", "NTFS", "UDF", "exFAT", "ReFS" };
const char* ep_reg = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
@ -92,8 +84,7 @@ char msgbox[1024], msgbox_title[32], *ini_file = NULL;
OPENED_LIBRARIES_VARS;
HINSTANCE hMainInstance;
HWND hMainDialog, hLangToolbar = NULL, hUpdatesDlg = NULL;
MY_BUTTON_IMAGELIST bi_iso = { 0 }, bi_up = { 0 }, bi_down = { 0 };
GetTickCount64_t pfGetTickCount64 = NULL;
BUTTON_IMAGELIST bi_iso = { 0 }, bi_up = { 0 }, bi_down = { 0 };
char szFolderPath[MAX_PATH], app_dir[MAX_PATH], system_dir[MAX_PATH], temp_dir[MAX_PATH], sysnative_dir[MAX_PATH];
char* image_path = NULL;
float fScale = 1.0f;
@ -265,22 +256,18 @@ static BOOL DefineClusterSizes(void)
}
}
// exFAT (requires KB955704 installed on XP => don't bother)
if (nWindowsVersion > WINDOWS_XP) {
SelectedDrive.ClusterSize[FS_EXFAT].Allowed = 0x03FFFE00;
if (SelectedDrive.DiskSize < 256*MB) // < 256 MB
SelectedDrive.ClusterSize[FS_EXFAT].Default = 4*KB;
else if (SelectedDrive.DiskSize < 32*GB) // < 32 GB
SelectedDrive.ClusterSize[FS_EXFAT].Default = 32*KB;
else
SelectedDrive.ClusterSize[FS_EXFAT].Default = 128*KB;
}
// exFAT
SelectedDrive.ClusterSize[FS_EXFAT].Allowed = 0x03FFFE00;
if (SelectedDrive.DiskSize < 256*MB) // < 256 MB
SelectedDrive.ClusterSize[FS_EXFAT].Default = 4*KB;
else if (SelectedDrive.DiskSize < 32*GB) // < 32 GB
SelectedDrive.ClusterSize[FS_EXFAT].Default = 32*KB;
else
SelectedDrive.ClusterSize[FS_EXFAT].Default = 128*KB;
// UDF (only supported for Vista and later)
if (nWindowsVersion >= WINDOWS_VISTA) {
SelectedDrive.ClusterSize[FS_UDF].Allowed = SINGLE_CLUSTERSIZE_DEFAULT;
SelectedDrive.ClusterSize[FS_UDF].Default = 1;
}
// UDF
SelectedDrive.ClusterSize[FS_UDF].Allowed = SINGLE_CLUSTERSIZE_DEFAULT;
SelectedDrive.ClusterSize[FS_UDF].Default = 1;
// ReFS (only supported for Windows 8.1 and later and for fixed disks)
if (SelectedDrive.DiskSize >= 512*MB) {
@ -445,10 +432,7 @@ static BOOL SetDriveInfo(int ComboIndex)
}
for (i=0; i<3; i++) {
// Populate MBR/BIOS, MBR/UEFI and GPT/UEFI targets, with an exception
// for XP, as it doesn't support GPT at all
if ((i == 2) && (nWindowsVersion <= WINDOWS_XP))
continue;
// Populate MBR/BIOS, MBR/UEFI and GPT/UEFI targets
pt = (i==2)?PARTITION_STYLE_GPT:PARTITION_STYLE_MBR;
if (i==0) {
SetMBRForUEFI(FALSE);
@ -820,8 +804,8 @@ void UpdateProgress(int op, float percent)
}
// Reduce the refresh rate, to avoid weird effects on the sliding part of progress bar
if (_GetTickCount64() > LastRefresh + (2 * MAX_REFRESH)) {
LastRefresh = _GetTickCount64();
if (GetTickCount64() > LastRefresh + (2 * MAX_REFRESH)) {
LastRefresh = GetTickCount64();
SendMessage(hProgress, PBM_SETPOS, (WPARAM)pos, 0);
SetTaskbarProgressValue(pos, MAX_PROGRESS);
}
@ -1708,10 +1692,6 @@ static void InitDialog(HWND hDlg)
ShowWindow(GetDlgItem(hDlg, IDC_TEST), SW_SHOW);
#endif
PF_INIT(ImageList_Create, Comctl32);
PF_INIT(ImageList_AddIcon, Comctl32);
PF_INIT(ImageList_ReplaceIcon, Comctl32);
// Quite a burden to carry around as parameters
hMainDialog = hDlg;
MainThreadId = GetCurrentThreadId();
@ -1748,7 +1728,7 @@ static void InitDialog(HWND hDlg)
// Create the font and brush for the Info edit box
hInfoFont = CreateFontA(lfHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
0, 0, PROOF_QUALITY, 0, (nWindowsVersion >= WINDOWS_VISTA)?"Segoe UI":"Arial Unicode MS");
0, 0, PROOF_QUALITY, 0, "Segoe UI");
SendDlgItemMessageA(hDlg, IDC_INFO, WM_SETFONT, (WPARAM)hInfoFont, TRUE);
hInfoBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
HideCaret(hInfo);
@ -1853,22 +1833,15 @@ static void InitDialog(HWND hDlg)
hIconLang = (HICON)LoadImage(hINetCplDllInst, MAKEINTRESOURCE(1313), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED);
}
if (nWindowsVersion >= WINDOWS_VISTA) {
hIconDown = (HICON)LoadImage(hShell32DllInst, MAKEINTRESOURCE(16750), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED);
hIconUp = (HICON)LoadImage(hShell32DllInst, MAKEINTRESOURCE(16749), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED);
} else {
hIconDown = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_DOWN), IMAGE_ICON, 16, 16, 0);
hIconUp = (HICON)LoadImage(hMainInstance, MAKEINTRESOURCE(IDI_UP), IMAGE_ICON, 16, 16, 0);
}
hIconDown = (HICON)LoadImage(hShell32DllInst, MAKEINTRESOURCE(16750), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED);
hIconUp = (HICON)LoadImage(hShell32DllInst, MAKEINTRESOURCE(16749), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED);
// Create the language toolbar
hLangToolbar = CreateWindowExW(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_TABSTOP | TBSTYLE_TRANSPARENT | CCS_NOPARENTALIGN |
CCS_NORESIZE | CCS_NODIVIDER, 0, 0, 0, 0, hMainDialog, NULL, hMainInstance, NULL);
if ((pfImageList_Create != NULL) && (pfImageList_AddIcon != NULL)) {
hLangToolbarImageList = pfImageList_Create(i16, i16, ILC_COLOR32, 1, 0);
pfImageList_AddIcon(hLangToolbarImageList, hIconLang);
SendMessage(hLangToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hLangToolbarImageList);
}
hLangToolbarImageList = ImageList_Create(i16, i16, ILC_COLOR32, 1, 0);
ImageList_AddIcon(hLangToolbarImageList, hIconLang);
SendMessage(hLangToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hLangToolbarImageList);
SendMessage(hLangToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
memset(tbLangToolbarButtons, 0, sizeof(TBBUTTON));
tbLangToolbarButtons[0].idCommand = lang_button_id;
@ -1917,25 +1890,22 @@ static void InitDialog(HWND hDlg)
info_original_proc = (WNDPROC)SetWindowLongPtr(hInfo, GWLP_WNDPROC, (LONG_PTR)InfoCallback);
// Set the icons on the the buttons
if ((pfImageList_Create != NULL) && (pfImageList_ReplaceIcon != NULL)) {
bi_iso.himl = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
ImageList_ReplaceIcon(bi_iso.himl, -1, hIconDisc);
SetRect(&bi_iso.margin, 0, 1, 0, 0);
bi_iso.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
bi_down.himl = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
ImageList_ReplaceIcon(bi_down.himl, -1, hIconDown);
SetRect(&bi_down.margin, 0, 0, 0, 0);
bi_down.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
bi_up.himl = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
ImageList_ReplaceIcon(bi_up.himl, -1, hIconUp);
SetRect(&bi_up.margin, 0, 0, 0, 0);
bi_up.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
bi_iso.himl = pfImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
pfImageList_ReplaceIcon(bi_iso.himl, -1, hIconDisc);
SetRect(&bi_iso.margin, 0, 1, 0, 0);
bi_iso.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
bi_down.himl = pfImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
pfImageList_ReplaceIcon(bi_down.himl, -1, hIconDown);
SetRect(&bi_down.margin, 0, 0, 0, 0);
bi_down.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
bi_up.himl = pfImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0);
pfImageList_ReplaceIcon(bi_up.himl, -1, hIconUp);
SetRect(&bi_up.margin, 0, 0, 0, 0);
bi_up.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER;
SendMessage(hSelectISO, BCM_SETIMAGELIST, 0, (LPARAM)&bi_iso);
SendMessage(GetDlgItem(hDlg, IDC_ADVANCED), BCM_SETIMAGELIST, 0,
(LPARAM)(advanced_mode?&bi_up:&bi_down));
}
SendMessage(hSelectISO, BCM_SETIMAGELIST, 0, (LPARAM)&bi_iso);
SendMessage(GetDlgItem(hDlg, IDC_ADVANCED), BCM_SETIMAGELIST, 0,
(LPARAM)(advanced_mode?&bi_up:&bi_down));
// Set the various tooltips
CreateTooltip(hFileSystem, lmprintf(MSG_157), -1);
@ -1960,10 +1930,8 @@ static void InitDialog(HWND hDlg)
CreateTooltip(hLangToolbar, lmprintf(MSG_273), -1);
// Set a label for the Advanced Mode and Select Image button for screen readers
if (nWindowsVersion > WINDOWS_XP) {
SetWindowTextU(GetDlgItem(hDlg, IDC_ADVANCED), lmprintf(MSG_160));
SetWindowTextU(hSelectISO, lmprintf(MSG_165));
}
SetWindowTextU(GetDlgItem(hDlg, IDC_ADVANCED), lmprintf(MSG_160));
SetWindowTextU(hSelectISO, lmprintf(MSG_165));
if (!advanced_mode) // Hide as needed, since we display the advanced controls by default
ToggleAdvanced(FALSE);
@ -2195,7 +2163,7 @@ static BOOL CheckDriveAccess(DWORD dwTimeOut)
char *PhysicalPath = NULL, DevPath[MAX_PATH];
char drive_letter[27], drive_name[] = "?:";
char *message, title[128];
DWORD cur_time, end_time = GetTickCount() + dwTimeOut;
uint64_t cur_time, end_time = GetTickCount64() + dwTimeOut;
// Get the current selected device
DWORD DeviceNum = (DWORD)ComboBox_GetItemData(hDeviceList, ComboBox_GetCurSel(hDeviceList));
@ -2225,10 +2193,10 @@ static BOOL CheckDriveAccess(DWORD dwTimeOut)
drive_name[0] = drive_letter[i];
if (QueryDosDeviceA(drive_name, DevPath, sizeof(DevPath)) != 0) {
StrArrayClear(&BlockingProcess);
cur_time = GetTickCount();
cur_time = GetTickCount64();
if (cur_time >= end_time)
break;
access_mask = SearchProcess(DevPath, end_time - cur_time, TRUE, TRUE, TRUE);
access_mask = SearchProcess(DevPath, (DWORD)(end_time - cur_time), TRUE, TRUE, TRUE);
CHECK_FOR_USER_CANCEL;
// Ignore if all we have is read-only
if ((access_mask & 0x06) || (access_mask == 0x80)) {
@ -2272,7 +2240,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
static BOOL first_log_display = TRUE, isMarquee = FALSE, queued_hotplug_event = FALSE;
static ULONG ulRegister = 0;
static LPITEMIDLIST pidlDesktop = NULL;
static MY_SHChangeNotifyEntry NotifyEntry;
static SHChangeNotifyEntry NotifyEntry;
static DWORD_PTR thread_affinity[4];
DRAWITEMSTRUCT* pDI;
HDROP droppedFileInfo;
@ -2316,7 +2284,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
switch(LOWORD(wParam)) {
case IDOK: // close application
case IDCANCEL:
PF_INIT(SHChangeNotifyDeregister, Shell32);
EnableWindow(GetDlgItem(hDlg, IDCANCEL), FALSE);
if (format_thid != NULL) {
if ((no_confirmation_on_cancel) || (MessageBoxExU(hMainDialog, lmprintf(MSG_105), lmprintf(MSG_049),
@ -2343,8 +2310,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
PrintInfo(0, MSG_201);
return (INT_PTR)TRUE;
}
if ((pfSHChangeNotifyDeregister != NULL) && (ulRegister != 0))
pfSHChangeNotifyDeregister(ulRegister);
if (ulRegister != 0)
SHChangeNotifyDeregister(ulRegister);
PostQuitMessage(0);
StrArrayDestroy(&DriveID);
StrArrayDestroy(&DriveLabel);
@ -2711,7 +2678,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
case DBT_DEVICEARRIVAL:
case DBT_DEVICEREMOVECOMPLETE:
case DBT_CUSTOMEVENT: // Sent by our timer refresh function or for card reader media change
LastRefresh = _GetTickCount64();
LastRefresh = GetTickCount64();
KillTimer(hMainDialog, TID_REFRESH_TIMER);
if (!format_op_in_progress) {
queued_hotplug_event = FALSE;
@ -2724,8 +2691,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
return (INT_PTR)TRUE;
case DBT_DEVNODES_CHANGED:
// If it's been more than a second since last device refresh, arm a refresh timer
if (_GetTickCount64() > LastRefresh + 1000) {
LastRefresh = _GetTickCount64();
if (GetTickCount64() > LastRefresh + 1000) {
LastRefresh = GetTickCount64();
SetTimer(hMainDialog, TID_REFRESH_TIMER, 1000, RefreshTimer);
}
break;
@ -2736,7 +2703,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
break;
case WM_INITDIALOG:
PF_INIT(SHChangeNotifyRegister, shell32);
// Make sure fScale is set before the first call to apply localization, so that move/resize scale appropriately
hDC = GetDC(hDlg);
fScale = GetDeviceCaps(hDC, LOGPIXELSX) / 96.0f;
@ -2753,12 +2719,12 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
GetDevices(0);
CheckForUpdates(FALSE);
// Register MEDIA_INSERTED/MEDIA_REMOVED notifications for card readers
if ((pfSHChangeNotifyRegister != NULL) && (SUCCEEDED(SHGetSpecialFolderLocation(0, CSIDL_DESKTOP, &pidlDesktop)))) {
if (SUCCEEDED(SHGetSpecialFolderLocation(0, CSIDL_DESKTOP, &pidlDesktop))) {
NotifyEntry.pidl = pidlDesktop;
NotifyEntry.fRecursive = TRUE;
// NB: The following only works if the media is already formatted.
// If you insert a blank card, notifications will not be sent... :(
ulRegister = pfSHChangeNotifyRegister(hDlg, 0x0001 | 0x0002 | 0x8000,
ulRegister = SHChangeNotifyRegister(hDlg, 0x0001 | 0x0002 | 0x8000,
SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED, UM_MEDIA_CHANGE, 1, &NotifyEntry);
}
// Bring our Window on top. We have to go through all *THREE* of these, or Far Manager hides our window :(
@ -3039,7 +3005,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
char *tmp, *locale_name = NULL, **argv = NULL;
wchar_t **wenv, **wargv;
PF_TYPE_DECL(CDECL, int, __wgetmainargs, (int*, wchar_t***, wchar_t***, int, int*));
PF_TYPE_DECL(WINAPI, BOOL, ChangeWindowMessageFilter, (UINT message, DWORD dwFlag));
HANDLE mutex = NULL, hogmutex = NULL, hFile = NULL;
HWND hDlg = NULL;
HDC hDC;
@ -3058,7 +3023,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
SetDllDirectoryA("");
uprintf("*** " APPLICATION_NAME " init ***\n");
PF_INIT(GetTickCount64, kernel32);
// Reattach the console, if we were started from commandline
if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
@ -3239,6 +3203,19 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
selected_langid = get_language_id(selected_locale);
// Set the Windows version
GetWindowsVersion();
// ...and nothing of value was lost
if (nWindowsVersion < WINDOWS_7) {
// Load the translation before we print the error
get_loc_data_file(loc_file, selected_locale);
right_to_left_mode = ((selected_locale->ctrl_id) & LOC_RIGHT_TO_LEFT);
// Set MB_SYSTEMMODAL to prevent Far Manager from stealing focus...
MessageBoxExU(NULL, lmprintf(MSG_294), lmprintf(MSG_293), MB_ICONSTOP | MB_IS_RTL | MB_SYSTEMMODAL, selected_langid);
goto out;
}
// This is needed as there appears to be a *FLAW* in Windows allowing the app to run unelevated with some
// weirdly configured user accounts, even as we explicitly set 'requireAdministrator' in the manifest...
if (!IsCurrentProcessElevated()) {
@ -3280,9 +3257,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
uprintf("Could not load RichEdit library - some dialogs may not display: %s\n", WindowsErrorString());
}
// Set the Windows version
GetWindowsVersion();
// Increase the application privileges (SE_DEBUG_PRIVILEGE), so that we can report
// the Windows Services preventing access to the disk or volume we want to format.
EnablePrivileges();
@ -3291,16 +3265,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// 0x9e disables removable and fixed drive notifications
lgp_set = SetLGP(FALSE, &existing_key, ep_reg, "NoDriveTypeAutorun", 0x9e);
if (nWindowsVersion > WINDOWS_XP) {
// Re-enable AutoMount if needed
if (!GetAutoMount(&automount)) {
uprintf("Could not get AutoMount status");
automount = TRUE; // So that we don't try to change its status on exit
} else if (!automount) {
uprintf("AutoMount was detected as disabled - temporarily re-enabling it");
if (!SetAutoMount(TRUE))
uprintf("Failed to enable AutoMount");
}
// Re-enable AutoMount if needed
if (!GetAutoMount(&automount)) {
uprintf("Could not get AutoMount status");
automount = TRUE; // So that we don't try to change its status on exit
} else if (!automount) {
uprintf("AutoMount was detected as disabled - temporarily re-enabling it");
if (!SetAutoMount(TRUE))
uprintf("Failed to enable AutoMount");
}
relaunch:
@ -3329,18 +3301,11 @@ relaunch:
if ((relaunch_rc.left > -65536) && (relaunch_rc.top > -65536))
SetWindowPos(hDlg, HWND_TOP, relaunch_rc.left, relaunch_rc.top, 0, 0, SWP_NOSIZE);
// Enable drag-n-drop through the message filter (for Vista or later)
if (nWindowsVersion >= WINDOWS_VISTA) {
PF_INIT(ChangeWindowMessageFilter, user32);
if (pfChangeWindowMessageFilter != NULL) {
// NB: We use ChangeWindowMessageFilter() here because
// ChangeWindowMessageFilterEx() is not available on Vista
pfChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
pfChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
// CopyGlobalData is needed sine we are running elevated
pfChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);
}
}
// Enable drag-n-drop through the message filter
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
// CopyGlobalData is needed sine we are running elevated
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);
// Set the hook to automatically close Windows' "You need to format the disk in drive..." prompt
if (!SetFormatPromptHook())
@ -3596,7 +3561,7 @@ out:
}
if (lgp_set)
SetLGP(TRUE, &existing_key, ep_reg, "NoDriveTypeAutorun", 0);
if ((nWindowsVersion > WINDOWS_XP) && (!automount) && (!SetAutoMount(FALSE)))
if ((!automount) && (!SetAutoMount(FALSE)))
uprintf("Failed to restore AutoMount to disabled");
ubflush();
// Unconditional delete with retry, just in case...