2 * Shell Library Functions
4 * Copyright 2005 Johannes Anderwald
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
24 #define LARGEINT_PROTOS
25 #define LargeIntegerDivide RtlLargeIntegerDivide
26 #define ExtendedIntegerMultiply RtlExtendedIntegerMultiply
27 #define ConvertUlongToLargeInteger RtlConvertUlongToLargeInteger
28 #define LargeIntegerSubtract RtlLargeIntegerSubtract
39 #include "wine/debug.h"
44 #include "shell32_main.h"
46 #include "undocshell.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
57 HWPD_STANDARDLIST
= 0,
59 HWPD_MAX
= HWPD_LARGELIST
60 } HWPAGE_DISPLAYMODE
, *PHWPAGE_DISPLAYMODE
;
63 DeviceCreateHardwarePageEx(HWND hWndParent
,
66 HWPAGE_DISPLAYMODE DisplayMode
);
68 #define DRIVE_PROPERTY_PAGES (3)
73 GetFreeBytesShare(LARGE_INTEGER TotalNumberOfFreeBytes
, LARGE_INTEGER TotalNumberOfBytes
)
75 LARGE_INTEGER Temp
, Result
, Remainder
;
77 Temp
= LargeIntegerDivide(TotalNumberOfBytes
, ConvertUlongToLargeInteger(100), &Remainder
);
78 if (Temp
.QuadPart
>= TotalNumberOfFreeBytes
.QuadPart
)
80 Result
= ConvertUlongToLargeInteger(1);
83 Result
= LargeIntegerDivide(TotalNumberOfFreeBytes
, Temp
, &Remainder
);
91 PaintStaticControls(HWND hwndDlg
, LPDRAWITEMSTRUCT drawItem
)
95 if (drawItem
->CtlID
== 14013)
97 hBrush
= CreateSolidBrush(RGB(0, 0, 255));
100 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
101 DeleteObject((HGDIOBJ
)hBrush
);
103 }else if (drawItem
->CtlID
== 14014)
105 hBrush
= CreateSolidBrush(RGB(255, 0, 255));
108 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
109 DeleteObject((HGDIOBJ
)hBrush
);
112 else if (drawItem
->CtlID
== 14015)
118 LARGE_INTEGER Result
;
120 hBlueBrush
= CreateSolidBrush(RGB(0, 0, 255));
121 hMagBrush
= CreateSolidBrush(RGB(255, 0, 255));
123 Result
.QuadPart
= GetWindowLongPtr(hwndDlg
, DWLP_USER
);
125 CopyRect(&rect
, &drawItem
->rcItem
);
126 horzsize
= rect
.right
- rect
.left
;
127 Result
.QuadPart
= (Result
.QuadPart
* horzsize
) / 100;
129 rect
.right
= rect
.left
+ Result
.QuadPart
;
130 FillRect(drawItem
->hDC
, &rect
, hMagBrush
);
131 rect
.left
= rect
.right
;
132 rect
.right
= drawItem
->rcItem
.right
;
133 FillRect(drawItem
->hDC
, &rect
, hBlueBrush
);
134 DeleteObject(hBlueBrush
);
135 DeleteObject(hMagBrush
);
141 InitializeGeneralDriveDialog(HWND hwndDlg
, WCHAR
* szDrive
)
143 WCHAR szVolumeName
[MAX_PATH
+1] = {0};
144 DWORD MaxComponentLength
= 0;
145 DWORD FileSystemFlags
= 0;
146 WCHAR FileSystemName
[MAX_PATH
+1] = {0};
151 ULARGE_INTEGER FreeBytesAvailable
;
152 LARGE_INTEGER TotalNumberOfFreeBytes
;
153 LARGE_INTEGER TotalNumberOfBytes
;
155 ret
= GetVolumeInformationW(szDrive
, szVolumeName
, MAX_PATH
+1, NULL
, &MaxComponentLength
, &FileSystemFlags
, FileSystemName
, MAX_PATH
+1);
158 /* set volume label */
159 SendDlgItemMessageW(hwndDlg
, 14001, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)szVolumeName
);
161 /* set filesystem type */
162 SendDlgItemMessageW(hwndDlg
, 14003, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)FileSystemName
);
166 DriveType
= GetDriveTypeW(szDrive
);
167 if (DriveType
== DRIVE_FIXED
)
170 if(GetDiskFreeSpaceExW(szDrive
, &FreeBytesAvailable
, (PULARGE_INTEGER
)&TotalNumberOfBytes
, (PULARGE_INTEGER
)&TotalNumberOfFreeBytes
))
173 LARGE_INTEGER Result
;
174 #ifdef IOCTL_DISK_GET_LENGTH_INFO_IMPLEMENTED
176 DWORD BytesReturned
= 0;
178 sprintfW(szResult
, L
"\\\\.\\%c:", towupper(szDrive
[0]));
179 hVolume
= CreateFileW(szResult
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
180 if (hVolume
!= INVALID_HANDLE_VALUE
)
182 ret
= DeviceIoControl(hVolume
, IOCTL_DISK_GET_LENGTH_INFO
, NULL
, 0, (LPVOID
)&TotalNumberOfBytes
, sizeof(ULARGE_INTEGER
), &BytesReturned
, NULL
);
183 if (ret
&& StrFormatByteSizeW(LengthInformation
.Length
.QuadPart
, szResult
, sizeof(szResult
) / sizeof(WCHAR
)))
184 SendDlgItemMessageW(hwndDlg
, 14008, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)szResult
);
186 CloseHandle(hVolume
);
188 TRACE("szResult %s hVOlume %p ret %d LengthInformation %ul Bytesreturned %d\n", debugstr_w(szResult
), hVolume
, ret
, LengthInformation
.Length
.QuadPart
, BytesReturned
);
190 if (ret
&& StrFormatByteSizeW(TotalNumberOfBytes
.QuadPart
, szResult
, sizeof(szResult
) / sizeof(WCHAR
)))
191 SendDlgItemMessageW(hwndDlg
, 14008, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)szResult
);
194 if (StrFormatByteSizeW(TotalNumberOfBytes
.QuadPart
- FreeBytesAvailable
.QuadPart
, szResult
, sizeof(szResult
) / sizeof(WCHAR
)))
195 SendDlgItemMessageW(hwndDlg
, 14004, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)szResult
);
197 if (StrFormatByteSizeW(FreeBytesAvailable
.QuadPart
, szResult
, sizeof(szResult
) / sizeof(WCHAR
)))
198 SendDlgItemMessageW(hwndDlg
, 14006, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)szResult
);
200 Result
= GetFreeBytesShare(TotalNumberOfFreeBytes
, TotalNumberOfBytes
);
201 /* set free bytes percentage */
202 sprintfW(szResult
, L
"%02d%%", Result
.QuadPart
);
203 SendDlgItemMessageW(hwndDlg
, 14007, WM_SETTEXT
, (WPARAM
)0, (LPARAM
)szResult
);
204 /* store free share amount */
205 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)Result
.QuadPart
);
206 /* store used share amount */
207 Result
= LargeIntegerSubtract(ConvertUlongToLargeInteger(100), Result
);
208 sprintfW(szResult
, L
"%02d%%", Result
.QuadPart
);
209 SendDlgItemMessageW(hwndDlg
, 14005, WM_SETTEXT
, (WPARAM
)0, (LPARAM
)szResult
);
210 if (LoadStringW(shell32_hInstance
, IDS_DRIVE_FIXED
, szBuffer
, sizeof(szBuffer
) / sizeof(WCHAR
)))
211 SendDlgItemMessageW(hwndDlg
, 14002, WM_SETTEXT
, (WPARAM
)0, (LPARAM
)szBuffer
);
215 /* set drive description */
216 SendDlgItemMessageW(hwndDlg
, 14010, WM_GETTEXT
, (WPARAM
)50, (LPARAM
)szFormat
);
217 sprintfW(szBuffer
, szFormat
, szDrive
);
218 SendDlgItemMessageW(hwndDlg
, 14010, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)szBuffer
);
231 LPPROPSHEETPAGEW ppsp
;
232 LPDRAWITEMSTRUCT drawItem
;
238 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
241 TRACE("WM_INITDIALOG hwnd %p lParam %p ppsplParam %S\n",hwndDlg
, lParam
, ppsp
->lParam
);
243 lpstr
= (WCHAR
*)ppsp
->lParam
;
244 InitializeGeneralDriveDialog(hwndDlg
, lpstr
);
247 drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
248 if (drawItem
->CtlID
>= 14013 && drawItem
->CtlID
<= 14015)
250 PaintStaticControls(hwndDlg
, drawItem
);
270 PROCESS_INFORMATION pi
;
271 WCHAR szPath
[MAX_PATH
];
272 WCHAR szArg
[MAX_PATH
];
275 LPPROPSHEETPAGEW ppsp
;
280 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
281 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)ppsp
->lParam
);
284 ZeroMemory( &si
, sizeof(si
) );
286 ZeroMemory( &pi
, sizeof(pi
) );
287 if (!GetSystemDirectoryW(szPath
, MAX_PATH
))
289 szDrive
= (WCHAR
*)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
290 switch(LOWORD(wParam
))
295 /// show checkdsk dialog
300 wcscpy(&szArg
[1], szPath
);
301 wcscat(szPath
, L
"\\mmc.exe");
302 wcscat(szArg
, L
"\\dfrg.msc\" ");
303 length
= wcslen(szArg
);
304 szArg
[length
] = szDrive
[0];
305 szArg
[length
+1] = L
':';
306 szArg
[length
+2] = L
'\0';
307 if (CreateProcessW(szPath
, szArg
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
309 CloseHandle(pi
.hProcess
);
310 CloseHandle(pi
.hThread
);
314 wcscat(szPath
, L
"\\ntbackup.exe");
315 if (CreateProcessW(szPath
, NULL
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
317 CloseHandle(pi
.hProcess
);
318 CloseHandle(pi
.hThread
);
336 Guids
[0] = GUID_DEVCLASS_DISKDRIVE
;
338 UNREFERENCED_PARAMETER(lParam
);
339 UNREFERENCED_PARAMETER(wParam
);
344 /* create the hardware page */
345 DeviceCreateHardwarePageEx(hwndDlg
,
347 sizeof(Guids
) / sizeof(Guids
[0]),
363 { "DRIVE_GENERAL_DLG", DriveGeneralDlg
},
364 { "DRIVE_EXTRA_DLG", DriveExtraDlg
},
365 { "DRIVE_HARDWARE_DLG", DriveHardwareDlg
},
370 AddPropSheetPageProc(HPROPSHEETPAGE hpage
, LPARAM lParam
)
372 PROPSHEETHEADER
*ppsh
= (PROPSHEETHEADER
*)lParam
;
373 if (ppsh
!= NULL
&& ppsh
->nPages
< MAX_PROPERTY_SHEET_PAGE
)
375 ppsh
->phpage
[ppsh
->nPages
++] = hpage
;
382 SH_ShowDriveProperties(WCHAR
* drive
)
385 HPROPSHEETPAGE hpsp
[MAX_PROPERTY_SHEET_PAGE
];
386 PROPSHEETHEADERW psh
;
390 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
391 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
392 //psh.dwFlags = PSH_USECALLBACK | PSH_PROPTITLE;
393 psh
.hwndParent
= NULL
;
397 for (i
= 0; i
< DRIVE_PROPERTY_PAGES
; i
++)
399 HPROPSHEETPAGE hprop
= SH_CreatePropertySheetPage(PropPages
[i
].resname
, PropPages
[i
].dlgproc
, (LPARAM
)drive
);
402 hpsp
[psh
.nPages
] = hprop
;
407 hpsx
= SHCreatePropSheetExtArray(HKEY_CLASSES_ROOT
,
409 MAX_PROPERTY_SHEET_PAGE
-DRIVE_PROPERTY_PAGES
);
411 SHAddFromPropSheetExtArray(hpsx
,
412 (LPFNADDPROPSHEETPAGE
)AddPropSheetPageProc
,
415 ret
= PropertySheetW(&psh
);