ReactOS  0.4.14-dev-552-g2fad488
drive.cpp
Go to the documentation of this file.
1 /*
2  * Shell Library Functions
3  *
4  * Copyright 2005 Johannes Anderwald
5  * Copyright 2017 Katayama Hirofumi MZ
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "precomp.h"
23 #include <process.h>
24 
26 
27 typedef struct
28 {
34 
35 EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj);
37 
38 static BOOL
39 GetDefaultClusterSize(LPWSTR szFs, PDWORD pClusterSize, PULARGE_INTEGER TotalNumberOfBytes)
40 {
42 
43  if (!wcsicmp(szFs, L"FAT16") ||
44  !wcsicmp(szFs, L"FAT")) //REACTOS HACK
45  {
46  if (TotalNumberOfBytes->QuadPart <= (16 * 1024 * 1024))
47  ClusterSize = 2048;
48  else if (TotalNumberOfBytes->QuadPart <= (32 * 1024 * 1024))
49  ClusterSize = 512;
50  else if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
51  ClusterSize = 1024;
52  else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
53  ClusterSize = 2048;
54  else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
55  ClusterSize = 4096;
56  else if (TotalNumberOfBytes->QuadPart <= (512 * 1024 * 1024))
57  ClusterSize = 8192;
58  else if (TotalNumberOfBytes->QuadPart <= (1024 * 1024 * 1024))
59  ClusterSize = 16384;
60  else if (TotalNumberOfBytes->QuadPart <= (2048LL * 1024LL * 1024LL))
61  ClusterSize = 32768;
62  else if (TotalNumberOfBytes->QuadPart <= (4096LL * 1024LL * 1024LL))
63  ClusterSize = 8192;
64  else
65  return FALSE;
66  }
67  else if (!wcsicmp(szFs, L"FAT32"))
68  {
69  if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
70  ClusterSize = 512;
71  else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
72  ClusterSize = 1024;
73  else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
74  ClusterSize = 2048;
75  else if (TotalNumberOfBytes->QuadPart <= (8192LL * 1024LL * 1024LL))
76  ClusterSize = 2048;
77  else if (TotalNumberOfBytes->QuadPart <= (16384LL * 1024LL * 1024LL))
78  ClusterSize = 8192;
79  else if (TotalNumberOfBytes->QuadPart <= (32768LL * 1024LL * 1024LL))
80  ClusterSize = 16384;
81  else
82  return FALSE;
83  }
84  else if (!wcsicmp(szFs, L"NTFS"))
85  {
86  if (TotalNumberOfBytes->QuadPart <= (512 * 1024 * 1024))
87  ClusterSize = 512;
88  else if (TotalNumberOfBytes->QuadPart <= (1024 * 1024 * 1024))
89  ClusterSize = 1024;
90  else if (TotalNumberOfBytes->QuadPart <= (2048LL * 1024LL * 1024LL))
91  ClusterSize = 2048;
92  else
93  ClusterSize = 2048;
94  }
95  else if (!wcsicmp(szFs, L"EXT2"))
96  {
97  // auto block size calculation
98  ClusterSize = 0;
99  }
100  else if (!wcsicmp(szFs, L"BtrFS"))
101  {
102  // auto block size calculation
103  ClusterSize = 0;
104  }
105  else
106  return FALSE;
107 
108  *pClusterSize = ClusterSize;
109  return TRUE;
110 }
111 
112 typedef struct _DRIVE_PROP_PAGE
113 {
118 
119 HRESULT
121 {
122  HPSXA hpsx = NULL;
124  PROPSHEETHEADERW psh;
125  CComObject<CDrvDefExt> *pDrvDefExt = NULL;
126  WCHAR wszName[256];
127 
128  ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
129  psh.dwSize = sizeof(PROPSHEETHEADERW);
130  psh.dwFlags = 0; // FIXME: make it modeless
131  psh.hwndParent = NULL;
132  psh.nStartPage = 0;
133  psh.phpage = hpsp;
134 
135  LPITEMIDLIST completePidl = ILCombine(pidlFolder, apidl[0]);
136  if (!completePidl)
137  return E_OUTOFMEMORY;
138 
139  if (ILGetDisplayNameExW(NULL, completePidl, wszName, ILGDN_NORMAL))
140  {
141  psh.pszCaption = wszName;
142  psh.dwFlags |= PSH_PROPTITLE;
143  }
144 
145  ILFree(completePidl);
146 
147  CComPtr<IDataObject> pDataObj;
148  HRESULT hr = SHCreateDataObject(pidlFolder, 1, apidl, NULL, IID_PPV_ARG(IDataObject, &pDataObj));
149 
150  if (SUCCEEDED(hr))
151  {
152  hr = CComObject<CDrvDefExt>::CreateInstance(&pDrvDefExt);
153  if (SUCCEEDED(hr))
154  {
155  pDrvDefExt->AddRef(); // CreateInstance returns object with 0 ref count
156  hr = pDrvDefExt->Initialize(pidlFolder, pDataObj, NULL);
157  if (SUCCEEDED(hr))
158  {
159  hr = pDrvDefExt->AddPages(AddPropSheetPageCallback, (LPARAM)&psh);
160  if (FAILED(hr))
161  ERR("AddPages failed\n");
162  } else
163  ERR("Initialize failed\n");
164  }
165 
167  if (hpsx)
169  }
170 
171  // NOTE: Currently property sheet is modal. If we make it modeless, then it returns HWND.
172  INT_PTR ret = PropertySheetW(&psh);
173 
174  if (hpsx)
176  if (pDrvDefExt)
177  pDrvDefExt->Release();
178 
179  if (ret > 0)
180  return S_OK;
181  if (ret == 0)
182  return S_FALSE;
183  return E_FAIL;
184 }
185 
186 static VOID
188 {
189  WCHAR wszBuf[100] = {0};
190  WCHAR szDrive[] = L"C:\\";
191  INT iSelIndex;
192  ULARGE_INTEGER FreeBytesAvailableUser, TotalNumberOfBytes;
194  LRESULT lIndex;
195  HWND hDlgCtrl;
196 
197  hDlgCtrl = GetDlgItem(hwndDlg, 28677);
198  iSelIndex = SendMessage(hDlgCtrl, CB_GETCURSEL, 0, 0);
199  if (iSelIndex == CB_ERR)
200  return;
201 
202  if (SendMessageW(hDlgCtrl, CB_GETLBTEXT, iSelIndex, (LPARAM)wszBuf) == CB_ERR)
203  return;
204 
205  szDrive[0] = pContext->Drive + L'A';
206 
207  if (!GetDiskFreeSpaceExW(szDrive, &FreeBytesAvailableUser, &TotalNumberOfBytes, NULL))
208  return;
209 
210  if (!wcsicmp(wszBuf, L"FAT16") ||
211  !wcsicmp(wszBuf, L"FAT")) //REACTOS HACK
212  {
213  if (!GetDefaultClusterSize(wszBuf, &ClusterSize, &TotalNumberOfBytes))
214  {
215  TRACE("FAT16 is not supported on hdd larger than 4G current %lu\n", TotalNumberOfBytes.QuadPart);
216  SendMessageW(hDlgCtrl, CB_DELETESTRING, iSelIndex, 0);
217  return;
218  }
219 
221  {
222  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
223  SendMessageW(hDlgCtrl, CB_RESETCONTENT, 0, 0);
224  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszBuf);
225  if (lIndex != CB_ERR)
226  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
227  SendMessageW(hDlgCtrl, CB_SETCURSEL, 0, 0);
228  }
229 
230  SendMessageW(GetDlgItem(hwndDlg, 28675), BM_SETCHECK, BST_UNCHECKED, 0);
231  EnableWindow(GetDlgItem(hwndDlg, 28675), FALSE);
232  }
233  else if (!wcsicmp(wszBuf, L"FAT32"))
234  {
235  if (!GetDefaultClusterSize(wszBuf, &ClusterSize, &TotalNumberOfBytes))
236  {
237  TRACE("FAT32 is not supported on hdd larger than 32G current %lu\n", TotalNumberOfBytes.QuadPart);
238  SendMessageW(hDlgCtrl, CB_DELETESTRING, iSelIndex, 0);
239  return;
240  }
241 
243  {
244  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
245  SendMessageW(hDlgCtrl, CB_RESETCONTENT, 0, 0);
246  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszBuf);
247  if (lIndex != CB_ERR)
248  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
249  SendMessageW(hDlgCtrl, CB_SETCURSEL, 0, 0);
250  }
251 
252  SendMessageW(GetDlgItem(hwndDlg, 28675), BM_SETCHECK, BST_UNCHECKED, 0);
253  EnableWindow(GetDlgItem(hwndDlg, 28675), FALSE);
254  }
255  else if (!wcsicmp(wszBuf, L"NTFS"))
256  {
257  if (!GetDefaultClusterSize(wszBuf, &ClusterSize, &TotalNumberOfBytes))
258  {
259  TRACE("NTFS is not supported on hdd larger than 2TB current %lu\n", TotalNumberOfBytes.QuadPart);
260  SendMessageW(hDlgCtrl, CB_DELETESTRING, iSelIndex, 0);
261  return;
262  }
263 
264  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
266  {
267  SendMessageW(hDlgCtrl, CB_RESETCONTENT, 0, 0);
268  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszBuf);
269  if (lIndex != CB_ERR)
270  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
271  SendMessageW(hDlgCtrl, CB_SETCURSEL, 0, 0);
272  }
273  ClusterSize = 512;
274  for (lIndex = 0; lIndex < 4; lIndex++)
275  {
276  TotalNumberOfBytes.QuadPart = ClusterSize;
277  if (StrFormatByteSizeW(TotalNumberOfBytes.QuadPart, wszBuf, _countof(wszBuf)))
278  {
279  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszBuf);
280  if (lIndex != CB_ERR)
281  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
282  }
283  ClusterSize *= 2;
284  }
285 
286  EnableWindow(GetDlgItem(hwndDlg, 28675), TRUE);
287  }
288  else if (!wcsicmp(wszBuf, L"EXT2"))
289  {
290  if (!GetDefaultClusterSize(wszBuf, &ClusterSize, &TotalNumberOfBytes))
291  {
292  TRACE("EXT2 is not supported on hdd larger than 32T current %lu\n", TotalNumberOfBytes.QuadPart);
293  SendMessageW(hDlgCtrl, CB_DELETESTRING, iSelIndex, 0);
294  return;
295  }
296 
298  {
299  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
300  SendMessageW(hDlgCtrl, CB_RESETCONTENT, 0, 0);
301  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszBuf);
302  if (lIndex != CB_ERR)
303  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
304  SendMessageW(hDlgCtrl, CB_SETCURSEL, 0, 0);
305  }
306 
307  EnableWindow(GetDlgItem(hwndDlg, 28675), TRUE);
308  }
309  else if (!wcsicmp(wszBuf, L"BtrFS"))
310  {
311  if (!GetDefaultClusterSize(wszBuf, &ClusterSize, &TotalNumberOfBytes))
312  {
313  TRACE("BtrFS is not supported on hdd larger than 16E current %lu\n", TotalNumberOfBytes.QuadPart);
314  SendMessageW(hDlgCtrl, CB_DELETESTRING, iSelIndex, 0);
315  return;
316  }
317 
319  {
320  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
321  SendMessageW(hDlgCtrl, CB_RESETCONTENT, 0, 0);
322  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszBuf);
323  if (lIndex != CB_ERR)
324  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
325  SendMessageW(hDlgCtrl, CB_SETCURSEL, 0, 0);
326  }
327 
328  EnableWindow(GetDlgItem(hwndDlg, 28675), TRUE);
329  }
330  else
331  {
332  FIXME("unknown fs\n");
333  SendDlgItemMessageW(hwndDlg, 28680, CB_RESETCONTENT, iSelIndex, 0);
334  return;
335  }
336 }
337 
338 static VOID
340 {
341  WCHAR szText[120];
342  WCHAR szDrive[] = L"C:\\";
343  WCHAR szFs[30] = L"";
344  INT cchText;
345  ULARGE_INTEGER FreeBytesAvailableUser, TotalNumberOfBytes;
346  DWORD dwIndex, dwDefault;
347  UCHAR uMinor, uMajor;
348  BOOLEAN Latest;
349  HWND hwndFileSystems;
350 
351  cchText = GetWindowTextW(hwndDlg, szText, _countof(szText) - 1);
352  if (cchText < 0)
353  cchText = 0;
354  szText[cchText++] = L' ';
355  szDrive[0] = pContext->Drive + L'A';
356  if (GetVolumeInformationW(szDrive, &szText[cchText], _countof(szText) - cchText, NULL, NULL, NULL, szFs, _countof(szFs)))
357  {
358  if (szText[cchText] == UNICODE_NULL)
359  {
360  /* load default volume label */
362  }
363  else
364  {
365  /* set volume label */
366  SetDlgItemTextW(hwndDlg, 28679, &szText[cchText]);
368  }
369  }
370 
371  StringCchPrintfW(szText + cchText, _countof(szText) - cchText, L" (%c:)", szDrive[0]);
372 
373  /* set window text */
374  SetWindowTextW(hwndDlg, szText);
375 
376  if (GetDiskFreeSpaceExW(szDrive, &FreeBytesAvailableUser, &TotalNumberOfBytes, NULL))
377  {
378  if (StrFormatByteSizeW(TotalNumberOfBytes.QuadPart, szText, _countof(szText)))
379  {
380  /* add drive capacity */
381  SendDlgItemMessageW(hwndDlg, 28673, CB_ADDSTRING, 0, (LPARAM)szText);
382  SendDlgItemMessageW(hwndDlg, 28673, CB_SETCURSEL, 0, (LPARAM)0);
383  }
384  }
385 
386  if (pContext->Options & SHFMT_OPT_FULL)
387  {
388  /* check quick format button */
389  SendDlgItemMessageW(hwndDlg, 28674, BM_SETCHECK, BST_CHECKED, 0);
390  }
391 
392  /* enumerate all available filesystems */
393  dwIndex = 0;
394  dwDefault = 0;
395  hwndFileSystems = GetDlgItem(hwndDlg, 28677);
396 
397  while(QueryAvailableFileSystemFormat(dwIndex, szText, &uMajor, &uMinor, &Latest))
398  {
399  if (!wcsicmp(szText, szFs))
400  dwDefault = dwIndex;
401 
402  SendMessageW(hwndFileSystems, CB_ADDSTRING, 0, (LPARAM)szText);
403  dwIndex++;
404  }
405 
406  if (!dwIndex)
407  {
408  ERR("no filesystem providers\n");
409  return;
410  }
411 
412  /* select default filesys */
413  SendMessageW(hwndFileSystems, CB_SETCURSEL, dwDefault, 0);
414  /* setup cluster combo */
415  InsertDefaultClusterSizeForFs(hwndDlg, pContext);
416 }
417 
420 
421 static BOOLEAN NTAPI
424  IN ULONG SubAction,
425  IN PVOID ActionInfo)
426 {
427  PDWORD Progress;
428  PBOOLEAN pSuccess;
429  switch(Command)
430  {
431  case PROGRESS:
432  Progress = (PDWORD)ActionInfo;
433  SendDlgItemMessageW(FormatDrvDialog, 28678, PBM_SETPOS, (WPARAM)*Progress, 0);
434  break;
435  case DONE:
436  pSuccess = (PBOOLEAN)ActionInfo;
437  bSuccess = (*pSuccess);
440  break;
441 
442  case VOLUMEINUSE:
443  case INSUFFICIENTRIGHTS:
444  case FSNOTSUPPORTED:
445  case CLUSTERSIZETOOSMALL:
446  bSuccess = FALSE;
447  FIXME("\n");
448  break;
449 
450  default:
451  break;
452  }
453 
454  return TRUE;
455 }
456 
457 VOID
459 {
460  WCHAR szDrive[4] = { L'C', ':', '\\', 0 };
461  WCHAR szFileSys[40] = {0};
462  WCHAR szLabel[40] = {0};
463  INT iSelIndex;
464  UINT Length;
465  HWND hDlgCtrl;
469  FMIFS_MEDIA_FLAG MediaFlag = FMIFS_HARDDISK;
470 
471  /* set volume path */
472  szDrive[0] = pContext->Drive + L'A';
473 
474  /* get filesystem */
475  hDlgCtrl = GetDlgItem(hwndDlg, 28677);
476  iSelIndex = SendMessageW(hDlgCtrl, CB_GETCURSEL, 0, 0);
477  if (iSelIndex == CB_ERR)
478  {
479  FIXME("\n");
480  return;
481  }
482  Length = SendMessageW(hDlgCtrl, CB_GETLBTEXTLEN, iSelIndex, 0);
483  if ((int)Length == CB_ERR || Length + 1 > _countof(szFileSys))
484  {
485  FIXME("\n");
486  return;
487  }
488 
489  /* retrieve the file system */
490  SendMessageW(hDlgCtrl, CB_GETLBTEXT, iSelIndex, (LPARAM)szFileSys);
491  szFileSys[_countof(szFileSys)-1] = L'\0';
492 
493  /* retrieve the volume label */
494  hDlgCtrl = GetWindow(hwndDlg, 28679);
495  Length = SendMessageW(hDlgCtrl, WM_GETTEXTLENGTH, 0, 0);
496  if (Length + 1 > _countof(szLabel))
497  {
498  FIXME("\n");
499  return;
500  }
501  SendMessageW(hDlgCtrl, WM_GETTEXT, _countof(szLabel), (LPARAM)szLabel);
502  szLabel[(sizeof(szLabel)/sizeof(WCHAR))-1] = L'\0';
503 
504  /* check for quickformat */
505  if (SendDlgItemMessageW(hwndDlg, 28674, BM_GETCHECK, 0, 0) == BST_CHECKED)
506  QuickFormat = TRUE;
507  else
508  QuickFormat = FALSE;
509 
510  /* get the cluster size */
511  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
512  iSelIndex = SendMessageW(hDlgCtrl, CB_GETCURSEL, 0, 0);
513  if (iSelIndex == CB_ERR)
514  {
515  FIXME("\n");
516  return;
517  }
518  ClusterSize = SendMessageW(hDlgCtrl, CB_GETITEMDATA, iSelIndex, 0);
519  if ((int)ClusterSize == CB_ERR)
520  {
521  FIXME("\n");
522  return;
523  }
524 
525  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
526  SendMessageW(hDlgCtrl, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
527  bSuccess = FALSE;
528 
529  /* FIXME
530  * will cause display problems
531  * when performing more than one format
532  */
533  FormatDrvDialog = hwndDlg;
534 
535  /* See if the drive is removable or not */
536  DriveType = GetDriveTypeW(szDrive);
537  switch (DriveType)
538  {
539  case DRIVE_UNKNOWN:
540  case DRIVE_REMOTE:
541  case DRIVE_CDROM:
542  case DRIVE_NO_ROOT_DIR:
543  {
544  FIXME("\n");
545  return;
546  }
547 
548  case DRIVE_REMOVABLE:
549  MediaFlag = FMIFS_FLOPPY;
550  break;
551 
552  case DRIVE_FIXED:
553  case DRIVE_RAMDISK:
554  MediaFlag = FMIFS_HARDDISK;
555  break;
556  }
557 
558  /* Format the drive */
559  FormatEx(szDrive,
560  MediaFlag,
561  szFileSys,
562  szLabel,
563  QuickFormat,
564  ClusterSize,
565  FormatExCB);
566 
568  if (!bSuccess)
569  {
570  pContext->Result = SHFMT_ERROR;
571  }
572  else if (QuickFormat)
573  {
574  pContext->Result = SHFMT_OPT_FULL;
575  }
576  else
577  {
578  pContext->Result = FALSE;
579  }
580 }
581 
583 {
586 };
587 
588 static unsigned __stdcall DoFormatDrive(void *args)
589 {
590  FORMAT_DRIVE_PARAMS *pParams = reinterpret_cast<FORMAT_DRIVE_PARAMS *>(args);
591  HWND hwndDlg = pParams->hwndDlg;
592  PFORMAT_DRIVE_CONTEXT pContext = pParams->pContext;
593 
594  /* Disable controls during format */
595  HMENU hSysMenu = GetSystemMenu(hwndDlg, FALSE);
597  EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
599  EnableWindow(GetDlgItem(hwndDlg, 28673), FALSE);
600  EnableWindow(GetDlgItem(hwndDlg, 28677), FALSE);
601  EnableWindow(GetDlgItem(hwndDlg, 28680), FALSE);
602  EnableWindow(GetDlgItem(hwndDlg, 28679), FALSE);
603  EnableWindow(GetDlgItem(hwndDlg, 28674), FALSE);
604 
605  FormatDrive(hwndDlg, pContext);
606 
607  /* Re-enable controls after format */
608  EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
609  EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), TRUE);
610  EnableWindow(GetDlgItem(hwndDlg, 28673), TRUE);
611  EnableWindow(GetDlgItem(hwndDlg, 28677), TRUE);
612  EnableWindow(GetDlgItem(hwndDlg, 28680), TRUE);
613  EnableWindow(GetDlgItem(hwndDlg, 28679), TRUE);
614  EnableWindow(GetDlgItem(hwndDlg, 28674), TRUE);
616  pContext->bFormattingNow = FALSE;
617 
618  delete pParams;
619  return 0;
620 }
621 
622 static INT_PTR CALLBACK
624 {
625  PFORMAT_DRIVE_CONTEXT pContext;
626 
627  switch(uMsg)
628  {
629  case WM_INITDIALOG:
632  return TRUE;
633  case WM_COMMAND:
634  switch(LOWORD(wParam))
635  {
636  case IDOK:
637  pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
638  if (pContext->bFormattingNow)
639  break;
640 
641  if (ShellMessageBoxW(shell32_hInstance, hwndDlg,
645  {
646  pContext->bFormattingNow = TRUE;
647 
649  pParams->hwndDlg = hwndDlg;
650  pParams->pContext = pContext;
651 
652  unsigned tid;
653  HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, DoFormatDrive, pParams, 0, &tid);
655  }
656  break;
657  case IDCANCEL:
658  pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
659  if (pContext->bFormattingNow)
660  break;
661 
662  EndDialog(hwndDlg, pContext->Result);
663  break;
664  case 28677: // filesystem combo
665  if (HIWORD(wParam) == CBN_SELENDOK)
666  {
667  pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
668  if (pContext->bFormattingNow)
669  break;
670 
671  InsertDefaultClusterSizeForFs(hwndDlg, pContext);
672  }
673  break;
674  }
675  }
676  return FALSE;
677 }
678 
679 /*************************************************************************
680  * SHFormatDrive (SHELL32.@)
681  */
682 
683 DWORD
684 WINAPI
686 {
688  int result;
689 
690  TRACE("%p, 0x%08x, 0x%08x, 0x%08x - stub\n", hwnd, drive, fmtID, options);
691 
692  Context.Drive = drive;
693  Context.Options = options;
694  Context.Result = FALSE;
695  Context.bFormattingNow = FALSE;
696 
698 
699  return result;
700 }
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:1755
#define WM_GETTEXTLENGTH
Definition: winuser.h:1601
HWND hwndParent
Definition: prsht.h:277
LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
Definition: string.c:2376
#define CB_SETITEMDATA
Definition: winuser.h:1948
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
struct _DRIVE_PROP_PAGE DRIVE_PROP_PAGE
#define IN
Definition: typedefs.h:38
#define CB_GETLBTEXTLEN
Definition: winuser.h:1935
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define CloseHandle
Definition: compat.h:406
#define LL
Definition: tui.h:85
BOOL CALLBACK AddPropSheetPageCallback(HPROPSHEETPAGE hPage, LPARAM lParam)
Definition: precomp.h:113
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define MF_BYCOMMAND
Definition: winuser.h:202
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
HRESULT WINAPI SHCreateDataObject(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IDataObject *pdtInner, REFIID riid, void **ppv)
#define CB_GETLBTEXT
Definition: winuser.h:1934
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:1577
#define SHFMT_ERROR
Definition: shlobj.h:292
#define _countof(array)
Definition: fontsub.cpp:30
#define CB_GETITEMDATA
Definition: winuser.h:1932
#define WM_GETTEXT
Definition: winuser.h:1600
#define MAKELPARAM(l, h)
Definition: winuser.h:3983
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
#define DRIVE_RAMDISK
Definition: winbase.h:252
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define CALLBACK
Definition: compat.h:27
Definition: fmifs.h:68
UINT DriveType
#define ZeroMemory
Definition: winbase.h:1642
#define PBM_SETPOS
Definition: commctrl.h:2180
BOOL(CALLBACK * LPFNADDPROPSHEETPAGE)(HPROPSHEETPAGE, LPARAM)
Definition: prsht.h:309
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
struct _PROPSHEETHEADERW PROPSHEETHEADERW
Definition: shell.h:41
int32_t INT_PTR
Definition: typedefs.h:62
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
CALLBACKCOMMAND
Definition: fmifs.h:66
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
Definition: match.c:390
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
static BOOLEAN bSuccess
Definition: drive.cpp:419
#define SetWindowLongPtr
Definition: treelist.c:70
#define CB_GETCURSEL
Definition: winuser.h:1925
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define DRIVE_REMOVABLE
Definition: winbase.h:248
#define MB_ICONWARNING
Definition: winuser.h:780
static VOID InsertDefaultClusterSizeForFs(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:187
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
static HWND FormatDrvDialog
Definition: drive.cpp:418
#define PBM_SETRANGE
Definition: commctrl.h:2179
#define DRIVE_REMOTE
Definition: winbase.h:250
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define UNICODE_NULL
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
static const WCHAR szText[]
Definition: dialog.c:139
LPCWSTR pszCaption
Definition: prsht.h:283
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CBN_SELENDOK
Definition: winuser.h:1963
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
#define FIXME(fmt,...)
Definition: debug.h:110
#define S_FALSE
Definition: winerror.h:2357
#define CB_ADDSTRING
Definition: winuser.h:1918
unsigned char BOOLEAN
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
VOID FormatDrive(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:458
smooth NULL
Definition: ftsmooth.c:416
#define ILGDN_NORMAL
Definition: undocshell.h:69
LONG_PTR LPARAM
Definition: windef.h:208
#define MB_OKCANCEL
Definition: winuser.h:798
#define BM_GETCHECK
Definition: winuser.h:1900
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2905
const char * LPCSTR
Definition: xmlstorage.h:183
BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
Definition: pidl.c:91
BOOL QuickFormat
Definition: format.c:66
#define CB_RESETCONTENT
Definition: winuser.h:1941
int options
Definition: main.c:106
#define DRIVE_UNKNOWN
Definition: winbase.h:253
#define CB_ERR
Definition: winuser.h:2410
_In_ int cchText
Definition: winuser.h:4440
#define BM_SETCHECK
Definition: winuser.h:1903
#define TRACE(s)
Definition: solgame.cpp:4
#define IDS_DRIVE_FIXED
Definition: shresdef.h:105
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PSH_PROPTITLE
Definition: prsht.h:40
LONG HRESULT
Definition: typedefs.h:77
VOID NTAPI FormatEx(IN PWCHAR DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PWCHAR Format, IN PWCHAR Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
Definition: format.c:38
#define IDS_FORMAT_WARNING
Definition: shresdef.h:191
#define MF_ENABLED
Definition: winuser.h:128
static BOOLEAN NTAPI FormatExCB(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: drive.cpp:422
DWORD ClusterSize
Definition: format.c:67
#define WINAPI
Definition: msvc.h:8
int ShellMessageBoxW(HINSTANCE hInstance, HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,...)
Definition: shellord.c:337
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
#define __stdcall
Definition: typedefs.h:25
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
DWORD dwSize
Definition: prsht.h:275
DWORD dwFlags
Definition: prsht.h:276
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
static VOID InitializeFormatDriveDlg(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:339
#define IDS_FORMAT_TITLE
Definition: shresdef.h:190
#define MB_ICONINFORMATION
Definition: winuser.h:796
unsigned char UCHAR
Definition: xmlstorage.h:181
int ret
char * PBOOLEAN
Definition: retypes.h:11
HWND WINAPI GetWindow(_In_ HWND, _In_ UINT)
static const WCHAR L[]
Definition: oid.c:1250
#define IDD_FORMAT_DRIVE
Definition: shresdef.h:449
#define DWLP_USER
Definition: winuser.h:866
#define IDS_FORMAT_COMPLETE
Definition: shresdef.h:192
#define CB_SETCURSEL
Definition: winuser.h:1943
#define WM_COMMAND
Definition: winuser.h:1722
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
#define BST_UNCHECKED
Definition: winuser.h:199
#define wcsicmp
Definition: string.h:1152
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:254
#define DRIVE_FIXED
Definition: winbase.h:249
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2871
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HPROPSHEETPAGE * phpage
Definition: prsht.h:291
#define ERR(fmt,...)
Definition: debug.h:109
DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
Definition: drive.cpp:685
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
#define S_OK
Definition: intsafe.h:59
static char drive[2]
Definition: batch.c:28
HRESULT SH_ShowDriveProperties(WCHAR *pwszDrive, LPCITEMIDLIST pidlFolder, PCUITEMID_CHILD_ARRAY apidl)
Definition: drive.cpp:120
static INT_PTR CALLBACK FormatDriveDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: drive.cpp:623
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1408
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
PFORMAT_DRIVE_CONTEXT pContext
Definition: drive.cpp:585
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define DRIVE_CDROM
Definition: winbase.h:251
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
DLGPROC dlgproc
Definition: drive.cpp:115
unsigned int UINT
Definition: ndis.h:50
#define MB_OK
Definition: winuser.h:784
HANDLE hThread
Definition: wizard.c:27
DWORD * PDWORD
Definition: pedump.c:68
#define IDS_DEFAULT_CLUSTER_SIZE
Definition: shresdef.h:213
#define BST_CHECKED
Definition: winuser.h:197
#define SC_CLOSE
Definition: winuser.h:2567
#define SHFMT_OPT_FULL
Definition: shlobj.h:298
#define SendMessage
Definition: winuser.h:5818
struct FORMAT_DRIVE_CONTEXT * PFORMAT_DRIVE_CONTEXT
struct tagContext Context
Definition: acpixf.h:1030
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
static unsigned __stdcall DoFormatDrive(void *args)
Definition: drive.cpp:588
EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj)
#define DONE
Definition: rnr20lib.h:14
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: treelist.c:73
HPROPSHEETPAGE SH_CreatePropertySheetPage(LPCSTR resname, DLGPROC dlgproc, LPARAM lParam, LPWSTR szTitle)
#define MF_GRAYED
Definition: winuser.h:129
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDCANCEL
Definition: winuser.h:825
#define CB_DELETESTRING
Definition: winuser.h:1919
LONG_PTR LRESULT
Definition: windef.h:209
#define EXTERN_C
Definition: basetyps.h:12
GLuint64EXT * result
Definition: glext.h:11304
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPCSTR resname
Definition: drive.cpp:114
#define MAX_PROPERTY_SHEET_PAGE
static TfClientId tid
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static BOOL GetDefaultClusterSize(LPWSTR szFs, PDWORD pClusterSize, PULARGE_INTEGER TotalNumberOfBytes)
Definition: drive.cpp:39
#define SUCCEEDED(hr)
Definition: intsafe.h:57
BOOL WINAPI GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, OUT PULARGE_INTEGER lpFreeBytesAvailableToCaller, OUT PULARGE_INTEGER lpTotalNumberOfBytes, OUT PULARGE_INTEGER lpTotalNumberOfFreeBytes)
Definition: disk.c:342
WINE_DEFAULT_DEBUG_CHANNEL(shell)
FMIFS_MEDIA_FLAG
Definition: fmifs.h:37
BOOLEAN NTAPI QueryAvailableFileSystemFormat(IN DWORD Index, IN OUT PWCHAR FileSystem, OUT UCHAR *Major, OUT UCHAR *Minor, OUT BOOLEAN *LatestVersion)
Definition: query.c:14
UINT nStartPage
Definition: prsht.h:286