https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bd25333e248bb08d55315…
commit bd25333e248bb08d55315b219b5404f5a945e02c
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Tue Nov 26 18:26:25 2019 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Nov 26 18:26:25 2019 +0900
[SHELL32] Make SHFormatDrive multi-thread (#2080)
CORE-12756
---
dll/win32/shell32/dialogs/drive.cpp | 62 ++++++++++++++++++++++++++++++++++---
1 file changed, 57 insertions(+), 5 deletions(-)
diff --git a/dll/win32/shell32/dialogs/drive.cpp b/dll/win32/shell32/dialogs/drive.cpp
index 4742c50e201..674e81cb21b 100644
--- a/dll/win32/shell32/dialogs/drive.cpp
+++ b/dll/win32/shell32/dialogs/drive.cpp
@@ -20,6 +20,7 @@
*/
#include "precomp.h"
+#include <process.h>
WINE_DEFAULT_DEBUG_CHANNEL(shell);
@@ -28,6 +29,7 @@ typedef struct
WCHAR Drive;
UINT Options;
UINT Result;
+ BOOL bFormattingNow;
} FORMAT_DRIVE_CONTEXT, *PFORMAT_DRIVE_CONTEXT;
EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT
max_iface, IDataObject *pDataObj);
@@ -577,6 +579,36 @@ FormatDrive(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
}
}
+struct FORMAT_DRIVE_PARAMS
+{
+ HWND hwndDlg;
+ PFORMAT_DRIVE_CONTEXT pContext;
+};
+
+static unsigned __stdcall DoFormatDrive(void *args)
+{
+ FORMAT_DRIVE_PARAMS *pParams = reinterpret_cast<FORMAT_DRIVE_PARAMS *>(args);
+ HWND hwndDlg = pParams->hwndDlg;
+ PFORMAT_DRIVE_CONTEXT pContext = pParams->pContext;
+
+ HMENU hSysMenu = GetSystemMenu(hwndDlg, FALSE);
+ EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, 28677), FALSE);
+
+ FormatDrive(hwndDlg, pContext);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, 28677), TRUE);
+ EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
+ pContext->bFormattingNow = FALSE;
+
+ delete pParams;
+ return 0;
+}
+
static INT_PTR CALLBACK
FormatDriveDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
@@ -592,20 +624,40 @@ FormatDriveDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
lParam)
switch(LOWORD(wParam))
{
case IDOK:
- if (ShellMessageBoxW(shell32_hInstance, hwndDlg,
MAKEINTRESOURCEW(IDS_FORMAT_WARNING), MAKEINTRESOURCEW(IDS_FORMAT_TITLE), MB_OKCANCEL |
MB_ICONWARNING) == IDOK)
+ pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg,
DWLP_USER);
+ if (pContext->bFormattingNow)
+ break;
+
+ if (ShellMessageBoxW(shell32_hInstance, hwndDlg,
+ MAKEINTRESOURCEW(IDS_FORMAT_WARNING),
+ MAKEINTRESOURCEW(IDS_FORMAT_TITLE),
+ MB_OKCANCEL | MB_ICONWARNING) == IDOK)
{
- pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg,
DWLP_USER);
- FormatDrive(hwndDlg, pContext);
+ pContext->bFormattingNow = TRUE;
+
+ FORMAT_DRIVE_PARAMS *pParams = new FORMAT_DRIVE_PARAMS;
+ pParams->hwndDlg = hwndDlg;
+ pParams->pContext = pContext;
+
+ unsigned tid;
+ HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, DoFormatDrive,
pParams, 0, &tid);
+ CloseHandle(hThread);
}
break;
case IDCANCEL:
pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg,
DWLP_USER);
+ if (pContext->bFormattingNow)
+ break;
+
EndDialog(hwndDlg, pContext->Result);
break;
case 28677: // filesystem combo
if (HIWORD(wParam) == CBN_SELENDOK)
{
pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg,
DWLP_USER);
+ if (pContext->bFormattingNow)
+ break;
+
InsertDefaultClusterSizeForFs(hwndDlg, pContext);
}
break;
@@ -629,10 +681,10 @@ SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
Context.Drive = drive;
Context.Options = options;
+ Context.Result = FALSE;
+ Context.bFormattingNow = FALSE;
result = DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(IDD_FORMAT_DRIVE), hwnd,
FormatDriveDlg, (LPARAM)&Context);
return result;
}
-
-