ReactOS 0.4.16-dev-1025-gd3456f5
CDrivesFolder.cpp File Reference
#include <precomp.h>
#include <process.h>
Include dependency graph for CDrivesFolder.cpp:

Go to the source code of this file.

Classes

class  CDrivesFolderEnum
 

Macros

#define RETRY_COUNT   3
 
#define RETRY_SLEEP   250
 
#define CMDID_FORMAT   1
 
#define CMDID_EJECT   2
 
#define CMDID_DISCONNECT   3
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
BOOL IsDriveFloppyA (LPCSTR pszDriveRoot)
 
BOOL IsDriveFloppyW (LPCWSTR pszDriveRoot)
 
static const CLSIDIsRegItem (PCUITEMID_CHILD pidl)
 
static bool IsRegItem (PCUITEMID_CHILD pidl, REFCLSID clsid)
 
static INT8 GetDriveNumber (PCUITEMID_CHILD pidl)
 
template<class T >
static TGetDrivePath (PCUITEMID_CHILD pidl, T *Path)
 
static UINT _ILGetRemovableTypeId (LPCITEMIDLIST pidl)
 
BOOL _ILGetDriveType (LPCITEMIDLIST pidl)
 
BOOL SHELL32_IsShellFolderNamespaceItemHidden (LPCWSTR SubKey, REFCLSID Clsid)
 
static BOOL TryToLockOrUnlockDrive (HANDLE hDrive, BOOL bLock)
 
static BOOL DoEjectDrive (const WCHAR *physical, UINT nDriveType, INT *pnStringID)
 
static DWORD CALLBACK DoFormatDriveThread (LPVOID args)
 
static HRESULT DoFormatDriveAsync (HWND hwnd, UINT nDrive)
 
HRESULT CALLBACK DrivesContextMenuCallback (IShellFolder *psf, HWND hwnd, IDataObject *pdtobj, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
HRESULT CDrivesContextMenu_CreateInstance (PCIDLIST_ABSOLUTE pidlFolder, HWND hwnd, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IShellFolder *psf, IContextMenu **ppcm)
 
static HRESULT getIconLocationForDrive (IShellFolder *psf, PCITEMID_CHILD pidl, UINT uFlags, LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
 
static HRESULT getLabelForDriveFromAutoRun (PCWSTR wszPath, LPWSTR szLabel, UINT cchMax)
 
static HRESULT GetRawDriveLabel (PCWSTR DrivePath, LPWSTR szLabel, UINT cchMax)
 
static HRESULT GetDriveLabel (PCWSTR DrivePath, LPWSTR szLabel, UINT cchMax)
 
HRESULT CDrivesExtractIcon_CreateInstance (IShellFolder *psf, LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppvOut)
 

Variables

static int iDriveIconIds [7]
 
static int iDriveTypeIds [7]
 
static const REQUIREDREGITEM g_RequiredItems []
 
static const REGFOLDERINFO g_RegFolderInfo
 
static const shvheader MyComputerSFHeader []
 
static const DWORD dwComputerAttributes
 
static const DWORD dwControlPanelAttributes
 
static const DWORD dwDriveAttributes
 

Macro Definition Documentation

◆ CMDID_DISCONNECT

#define CMDID_DISCONNECT   3

◆ CMDID_EJECT

#define CMDID_EJECT   2

◆ CMDID_FORMAT

#define CMDID_FORMAT   1

◆ RETRY_COUNT

#define RETRY_COUNT   3

Definition at line 144 of file CDrivesFolder.cpp.

◆ RETRY_SLEEP

#define RETRY_SLEEP   250

Definition at line 145 of file CDrivesFolder.cpp.

Function Documentation

◆ _ILGetDriveType()

BOOL _ILGetDriveType ( LPCITEMIDLIST  pidl)

Definition at line 119 of file CDrivesFolder.cpp.

120{
121 WCHAR szDrive[8];
122 if (!_ILGetDrive(pidl, szDrive, _countof(szDrive)))
123 {
124 ERR("pidl %p is not a drive\n", pidl);
125 return DRIVE_UNKNOWN;
126 }
127 return ::GetDriveTypeW(szDrive);
128}
#define ERR(fmt,...)
Definition: precomp.h:57
DWORD _ILGetDrive(LPCITEMIDLIST pidl, LPWSTR pOut, UINT uSize)
Definition: pidl.c:2045
#define _countof(array)
Definition: sndvol32.h:70
#define DRIVE_UNKNOWN
Definition: winbase.h:282
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CDrivesFolder::GetAttributesOf(), and CDrivesFolder::GetDetailsEx().

◆ _ILGetRemovableTypeId()

static UINT _ILGetRemovableTypeId ( LPCITEMIDLIST  pidl)
inlinestatic

Definition at line 111 of file CDrivesFolder.cpp.

112{
113 WCHAR buf[8];
114 if (GetDrivePath(pidl, buf) && IsDriveFloppyW(buf))
115 return SHDID_COMPUTER_DRIVE35; // TODO: 3.5-inch vs 5.25-inch
117}
static T * GetDrivePath(PCUITEMID_CHILD pidl, T *Path)
BOOL IsDriveFloppyW(LPCWSTR pszDriveRoot)
Definition: drvdefext.cpp:320
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define SHDID_COMPUTER_REMOVABLE
Definition: shlobj.h:1470
#define SHDID_COMPUTER_DRIVE35
Definition: shlobj.h:1468

Referenced by CDrivesFolder::GetDetailsEx().

◆ CDrivesContextMenu_CreateInstance()

HRESULT CDrivesContextMenu_CreateInstance ( PCIDLIST_ABSOLUTE  pidlFolder,
HWND  hwnd,
UINT  cidl,
PCUITEMID_CHILD_ARRAY  apidl,
IShellFolder psf,
IContextMenu **  ppcm 
)

Definition at line 397 of file CDrivesFolder.cpp.

403{
404 HKEY hKeys[2];
405 UINT cKeys = 0;
406 AddClassKeyToArray(L"Drive", hKeys, &cKeys);
407 AddClassKeyToArray(L"Folder", hKeys, &cKeys);
408
409 return CDefFolderMenu_Create2(pidlFolder, hwnd, cidl, apidl, psf, DrivesContextMenuCallback, cKeys, hKeys, ppcm);
410}
HRESULT WINAPI CDefFolderMenu_Create2(PCIDLIST_ABSOLUTE pidlFolder, HWND hwnd, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IShellFolder *psf, LPFNDFMCALLBACK lpfn, UINT nKeys, const HKEY *ahkeyClsKeys, IContextMenu **ppcm)
HRESULT CALLBACK DrivesContextMenuCallback(IShellFolder *psf, HWND hwnd, IDataObject *pdtobj, UINT uMsg, WPARAM wParam, LPARAM lParam)
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
LSTATUS AddClassKeyToArray(const WCHAR *szClass, HKEY *array, UINT *cKeys)
Definition: shlfolder.cpp:408
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by CDrivesFolder::GetUIObjectOf().

◆ CDrivesExtractIcon_CreateInstance()

HRESULT CDrivesExtractIcon_CreateInstance ( IShellFolder psf,
LPCITEMIDLIST  pidl,
REFIID  riid,
LPVOID ppvOut 
)

Definition at line 490 of file CDrivesFolder.cpp.

491{
492 CComPtr<IDefaultExtractIconInit> initIcon;
495 return hr;
496
497 CHAR* pszDrive = _ILGetDataPointer(pidl)->u.drive.szDriveName;
498 UINT DriveType = GetDriveTypeA(pszDrive);
501
502 WCHAR wTemp[MAX_PATH];
503 int icon_idx, reg_idx;
504 UINT flags = 0;
505
506 switch (DriveType)
507 {
508 case DRIVE_FIXED:
509 case DRIVE_UNKNOWN:
510 reg_idx = IDI_SHELL_DRIVE;
511 break;
512 case DRIVE_CDROM:
513 reg_idx = IDI_SHELL_CDROM;
514 break;
515 case DRIVE_REMOTE:
516 reg_idx = IDI_SHELL_NETDRIVE;
517 break;
518 case DRIVE_REMOVABLE:
519 if (!IsDriveFloppyA(pszDrive))
520 reg_idx = IDI_SHELL_REMOVEABLE;
521 else
522 reg_idx = IDI_SHELL_3_14_FLOPPY;
523 break;
524 case DRIVE_RAMDISK:
525 reg_idx = IDI_SHELL_RAMDISK;
526 break;
528 default:
529 reg_idx = IDI_SHELL_DOCUMENT;
530 break;
531 }
532
533 hr = getIconLocationForDrive(psf, pidl, 0, wTemp, _countof(wTemp),
534 &icon_idx, &flags);
535 if (SUCCEEDED(hr))
536 {
537 initIcon->SetNormalIcon(wTemp, icon_idx);
538 }
539 else if (HLM_GetIconW(reg_idx - 1, wTemp, _countof(wTemp), &icon_idx))
540 {
541 initIcon->SetNormalIcon(wTemp, icon_idx);
542 }
543 else if ((DriveType == DRIVE_FIXED || DriveType == DRIVE_UNKNOWN) &&
544 (HCR_GetIconW(L"Drive", wTemp, NULL, _countof(wTemp), &icon_idx)))
545 {
546 initIcon->SetNormalIcon(wTemp, icon_idx);
547 }
548 else
549 {
550 if (DriveType == DRIVE_REMOVABLE && !IsDriveFloppyA(pszDrive))
551 {
552 icon_idx = IDI_SHELL_REMOVEABLE;
553 }
554 else
555 {
556 icon_idx = iDriveIconIds[DriveType];
557 }
558 initIcon->SetNormalIcon(swShell32Name, -icon_idx);
559 }
560
561 return initIcon->QueryInterface(riid, ppvOut);
562}
static HRESULT getIconLocationForDrive(IShellFolder *psf, PCITEMID_CHILD pidl, UINT uFlags, LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
static int iDriveIconIds[7]
BOOL IsDriveFloppyA(LPCSTR pszDriveRoot)
Definition: drvdefext.cpp:386
HRESULT WINAPI SHCreateDefaultExtractIcon(REFIID riid, void **ppv)
UINT DriveType
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
#define FAILED_UNEXPECTEDLY(hr)
Definition: debug.h:83
UINT WINAPI GetDriveTypeA(IN LPCSTR lpRootPathName)
Definition: disk.c:468
WCHAR swShell32Name[MAX_PATH]
Definition: folders.cpp:22
GLbitfield flags
Definition: glext.h:7161
REFIID riid
Definition: atlbase.h:39
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define DRIVE_CDROM
Definition: machpc98.h:119
LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
Definition: pidl.c:2271
BOOL HCR_GetIconW(LPCWSTR szClass, LPWSTR szDest, LPCWSTR szName, DWORD len, int *picon_idx)
Definition: classes.c:314
HRESULT hr
Definition: shlfolder.c:183
#define IDI_SHELL_3_14_FLOPPY
Definition: shresdef.h:585
#define IDI_SHELL_NETDRIVE
Definition: shresdef.h:588
#define IDI_SHELL_DOCUMENT
Definition: shresdef.h:579
#define IDI_SHELL_CDROM
Definition: shresdef.h:590
#define IDI_SHELL_DRIVE
Definition: shresdef.h:587
#define IDI_SHELL_RAMDISK
Definition: shresdef.h:591
#define IDI_SHELL_REMOVEABLE
Definition: shresdef.h:586
struct tagDriveStruct drive
Definition: pidl.h:214
union tagPIDLDATA::@595 u
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:283
#define DRIVE_REMOTE
Definition: winbase.h:279
#define DRIVE_RAMDISK
Definition: winbase.h:281
#define DRIVE_FIXED
Definition: winbase.h:278
#define DRIVE_REMOVABLE
Definition: winbase.h:277
#define IID_PPV_ARG(Itype, ppType)
char CHAR
Definition: xmlstorage.h:175

Referenced by CDrivesFolder::GetUIObjectOf().

◆ DoEjectDrive()

static BOOL DoEjectDrive ( const WCHAR physical,
UINT  nDriveType,
INT pnStringID 
)
static

Definition at line 166 of file CDrivesFolder.cpp.

167{
168 /* GENERIC_WRITE isn't needed for umount */
169 DWORD dwAccessMode = GENERIC_READ;
170 DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
171
172 HANDLE hDrive = CreateFile(physical, dwAccessMode, dwShareMode, 0, OPEN_EXISTING, 0, NULL);
173 if (hDrive == INVALID_HANDLE_VALUE)
174 return FALSE;
175
176 BOOL bResult, bNeedUnlock = FALSE;
177 DWORD dwBytesReturned, dwError = NO_ERROR;
178 PREVENT_MEDIA_REMOVAL removal;
179 do
180 {
181 bResult = TryToLockOrUnlockDrive(hDrive, TRUE);
182 if (!bResult)
183 {
184 dwError = GetLastError();
185 *pnStringID = IDS_CANTLOCKVOLUME; /* Unable to lock volume */
186 break;
187 }
188 bResult = DeviceIoControl(hDrive, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
189 if (!bResult)
190 {
191 dwError = GetLastError();
192 *pnStringID = IDS_CANTDISMOUNTVOLUME; /* Unable to dismount volume */
193 bNeedUnlock = TRUE;
194 break;
195 }
196 removal.PreventMediaRemoval = FALSE;
197 bResult = DeviceIoControl(hDrive, IOCTL_STORAGE_MEDIA_REMOVAL, &removal, sizeof(removal), NULL,
198 0, &dwBytesReturned, NULL);
199 if (!bResult)
200 {
201 *pnStringID = IDS_CANTEJECTMEDIA; /* Unable to eject media */
202 dwError = GetLastError();
203 bNeedUnlock = TRUE;
204 break;
205 }
206 bResult = DeviceIoControl(hDrive, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
207 if (!bResult)
208 {
209 *pnStringID = IDS_CANTEJECTMEDIA; /* Unable to eject media */
210 dwError = GetLastError();
211 bNeedUnlock = TRUE;
212 break;
213 }
214 } while (0);
215
216 if (bNeedUnlock)
217 {
219 }
220
221 CloseHandle(hDrive);
222
223 SetLastError(dwError);
224 return bResult;
225}
static BOOL TryToLockOrUnlockDrive(HANDLE hDrive, BOOL bLock)
#define NO_ERROR
Definition: dderror.h:5
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
#define IOCTL_STORAGE_EJECT_MEDIA
Definition: ntddstor.h:107
#define IOCTL_STORAGE_MEDIA_REMOVAL
Definition: ntddstor.h:104
#define IDS_CANTDISMOUNTVOLUME
Definition: shresdef.h:148
#define IDS_CANTLOCKVOLUME
Definition: shresdef.h:147
#define IDS_CANTEJECTMEDIA
Definition: shresdef.h:149
BOOLEAN PreventMediaRemoval
Definition: ntddstor.h:343
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateFile
Definition: winbase.h:3780

Referenced by DrivesContextMenuCallback().

◆ DoFormatDriveAsync()

static HRESULT DoFormatDriveAsync ( HWND  hwnd,
UINT  nDrive 
)
static

Definition at line 239 of file CDrivesFolder.cpp.

240{
242 return succ ? S_OK : E_FAIL;
243}
static DWORD CALLBACK DoFormatDriveThread(LPVOID args)
#define E_FAIL
Definition: ddrawi.h:102
BOOL WINAPI SHCreateThread(LPTHREAD_START_ROUTINE pfnThreadProc, VOID *pData, DWORD dwFlags, LPTHREAD_START_ROUTINE pfnCallback)
Definition: thread.c:356
#define UlongToPtr(u)
Definition: config.h:106
#define S_OK
Definition: intsafe.h:52
#define CTF_PROCESS_REF
Definition: shlwapi.h:1980

Referenced by DrivesContextMenuCallback().

◆ DoFormatDriveThread()

static DWORD CALLBACK DoFormatDriveThread ( LPVOID  args)
static

Definition at line 227 of file CDrivesFolder.cpp.

228{
229 UINT nDrive = PtrToUlong(args);
230 WCHAR szPath[] = { LOWORD(L'A' + nDrive), L'\0' }; // Arbitrary, just needs to include nDrive
233 if (FAILED(hr))
234 return hr;
236 return stub.DestroyWindow();
237}
@ TYPE_FORMATDRIVE
Definition: precomp.h:208
DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
Definition: drive.cpp:762
#define PtrToUlong(u)
Definition: config.h:107
#define FAILED(hr)
Definition: intsafe.h:51
LPCWSTR szPath
Definition: env.c:37
#define LOWORD(l)
Definition: pedump.c:82
#define SHFMT_ID_DEFAULT
Definition: shlobj.h:332
Definition: stubgen.c:11
Definition: match.c:390
struct _stub stub

Referenced by DoFormatDriveAsync().

◆ DrivesContextMenuCallback()

HRESULT CALLBACK DrivesContextMenuCallback ( IShellFolder psf,
HWND  hwnd,
IDataObject pdtobj,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 245 of file CDrivesFolder.cpp.

251{
252 if (uMsg != DFM_MERGECONTEXTMENU && uMsg != DFM_INVOKECOMMAND)
253 return SHELL32_DefaultContextMenuCallBack(psf, pdtobj, uMsg);
254
255 PIDLIST_ABSOLUTE pidlFolder;
256 PUITEMID_CHILD *apidl;
257 UINT cidl;
258 UINT nDriveType;
260 HRESULT hr = SH_GetApidlFromDataObject(pdtobj, &pidlFolder, &apidl, &cidl);
262 return hr;
263
264 WCHAR szDrive[8] = {0};
265 if (!_ILGetDrive(apidl[0], szDrive, _countof(szDrive)))
266 {
267 ERR("pidl is not a drive\n");
268 SHFree(pidlFolder);
269 _ILFreeaPidl(apidl, cidl);
270 return E_FAIL;
271 }
272 nDriveType = GetDriveTypeW(szDrive);
273 if (!GetVolumeInformationW(szDrive, NULL, 0, NULL, NULL, &dwFlags, NULL, 0))
274 {
275 if (nDriveType >= DRIVE_REMOTE)
277 else
278 dwFlags = 0; // Assume drive with unknown filesystem, allow format
279 }
280
281// custom command IDs
282#if 0 // Disabled until our menu building system is fixed
283#define CMDID_FORMAT 0
284#define CMDID_EJECT 1
285#define CMDID_DISCONNECT 2
286#else
287/* FIXME: These IDs should start from 0, however there is difference
288 * between ours and Windows' menu building systems, which should be fixed. */
289#define CMDID_FORMAT 1
290#define CMDID_EJECT 2
291#define CMDID_DISCONNECT 3
292#endif
293
294 if (uMsg == DFM_MERGECONTEXTMENU)
295 {
296 QCMINFO *pqcminfo = (QCMINFO *)lParam;
297
298 UINT idCmdFirst = pqcminfo->idCmdFirst;
299 UINT idCmd = 0;
300 if (!(dwFlags & FILE_READ_ONLY_VOLUME) && nDriveType != DRIVE_REMOTE && cidl == 1)
301 {
302 /* add separator and Format */
303 idCmd = idCmdFirst + CMDID_FORMAT;
304 _InsertMenuItemW(pqcminfo->hmenu, pqcminfo->indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
306 }
307 if (nDriveType == DRIVE_REMOVABLE || nDriveType == DRIVE_CDROM)
308 {
309 /* add separator and Eject */
310 idCmd = idCmdFirst + CMDID_EJECT;
311 _InsertMenuItemW(pqcminfo->hmenu, pqcminfo->indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
313 }
314 if (nDriveType == DRIVE_REMOTE)
315 {
316 /* add separator and Disconnect */
317 idCmd = idCmdFirst + CMDID_DISCONNECT;
318 _InsertMenuItemW(pqcminfo->hmenu, pqcminfo->indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
320 }
321
322 if (idCmd)
323#if 0 // see FIXME above
324 pqcminfo->idCmdFirst = ++idCmd;
325#else
326 pqcminfo->idCmdFirst = (idCmd + 2);
327#endif
328 hr = S_OK;
329 }
330 else if (uMsg == DFM_INVOKECOMMAND)
331 {
332 WCHAR wszBuf[4] = L"A:\\";
333 wszBuf[0] = (WCHAR)szDrive[0];
334
335 INT nStringID = 0;
336 DWORD dwError = NO_ERROR;
337
339 {
340 ATLASSERT(pdtobj);
342 // Not setting nStringID because SHOpenPropSheet already displayed an error box
343 }
344 else
345 {
346 if (wParam == CMDID_FORMAT)
347 {
348 hr = DoFormatDriveAsync(hwnd, szDrive[0] - 'A');
349 }
350 else if (wParam == CMDID_EJECT)
351 {
352 /* do eject */
353 WCHAR physical[10];
354 wsprintfW(physical, _T("\\\\.\\%c:"), szDrive[0]);
355
356 if (DoEjectDrive(physical, nDriveType, &nStringID))
357 {
359 }
360 else
361 {
362 dwError = GetLastError();
363 }
364 }
365 else if (wParam == CMDID_DISCONNECT)
366 {
367 /* do disconnect */
368 wszBuf[2] = UNICODE_NULL;
369 dwError = WNetCancelConnection2W(wszBuf, 0, FALSE);
370 if (dwError == NO_ERROR)
371 {
373 }
374 else
375 {
376 nStringID = IDS_CANTDISCONNECT;
377 }
378 }
379 }
380
381 if (nStringID != 0)
382 {
383 /* show error message */
384 WCHAR szFormat[128], szMessage[128];
385 LoadStringW(shell32_hInstance, nStringID, szFormat, _countof(szFormat));
386 wsprintfW(szMessage, szFormat, dwError);
387 MessageBoxW(hwnd, szMessage, NULL, MB_ICONERROR);
388 }
389 }
390
391 SHFree(pidlFolder);
392 _ILFreeaPidl(apidl, cidl);
393
394 return hr;
395}
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
static HRESULT DoFormatDriveAsync(HWND hwnd, UINT nDrive)
#define CMDID_FORMAT
static BOOL DoEjectDrive(const WCHAR *physical, UINT nDriveType, INT *pnStringID)
#define CMDID_EJECT
#define CMDID_DISCONNECT
#define shell32_hInstance
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define DFM_MERGECONTEXTMENU
Definition: precomp.h:44
#define DFM_INVOKECOMMAND
Definition: precomp.h:45
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
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
HRESULT SHELL32_DefaultContextMenuCallBack(IShellFolder *psf, IDataObject *pdo, UINT msg)
Definition: shlfolder.cpp:613
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:326
#define FILE_READ_ONLY_VOLUME
Definition: from_kernel.h:246
HRESULT SHELL32_ShowFilesystemItemPropertiesDialogAsync(IDataObject *pDO)
Definition: item_prop.cpp:157
#define UNICODE_NULL
void _ILFreeaPidl(LPITEMIDLIST *apidl, UINT cidl)
Definition: pidl.c:2607
HRESULT SH_GetApidlFromDataObject(IDataObject *pDataObject, PIDLIST_ABSOLUTE *ppidlfolder, PUITEMID_CHILD **apidlItems, UINT *pcidl)
Definition: shlfolder.cpp:499
void WINAPI _InsertMenuItemW(HMENU hmenu, UINT indexMenu, BOOL fByPosition, UINT wID, UINT fType, LPCWSTR dwTypeData, UINT fState)
#define SHCNE_DRIVEREMOVED
Definition: shlobj.h:1905
#define SHCNE_MEDIAREMOVED
Definition: shlobj.h:1904
#define SHCNF_PATHW
Definition: shlobj.h:1933
#define DFM_CMD_PROPERTIES
Definition: shlobj.h:2620
#define SHCNF_FLUSHNOWAIT
Definition: shlobj.h:1937
#define IDS_DISCONNECT
Definition: shresdef.h:244
#define IDS_EJECT
Definition: shresdef.h:243
#define IDS_CANTDISCONNECT
Definition: shresdef.h:151
#define IDS_FORMATDRIVE
Definition: shresdef.h:229
ITEMID_CHILD UNALIGNED * PUITEMID_CHILD
Definition: shtypes.idl:68
HMENU hmenu
Definition: shlobj.h:1398
UINT idCmdFirst
Definition: shlobj.h:1400
UINT indexMenu
Definition: shlobj.h:1399
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define MFT_SEPARATOR
Definition: winuser.h:755
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:798
#define MFS_ENABLED
Definition: winuser.h:761
#define MFT_STRING
Definition: winuser.h:757
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
DWORD WINAPI WNetCancelConnection2W(LPCWSTR lpName, DWORD dwFlags, BOOL fForce)
Definition: wnet.c:2420

Referenced by CDrivesContextMenu_CreateInstance().

◆ GetDriveLabel()

static HRESULT GetDriveLabel ( PCWSTR  DrivePath,
LPWSTR  szLabel,
UINT  cchMax 
)
static

Definition at line 484 of file CDrivesFolder.cpp.

485{
486 HRESULT hr = getLabelForDriveFromAutoRun(DrivePath, szLabel, cchMax);
487 return hr == S_OK ? S_OK : GetRawDriveLabel(DrivePath, szLabel, cchMax);
488}
static HRESULT GetRawDriveLabel(PCWSTR DrivePath, LPWSTR szLabel, UINT cchMax)
static HRESULT getLabelForDriveFromAutoRun(PCWSTR wszPath, LPWSTR szLabel, UINT cchMax)
UINT cchMax

Referenced by CDrivesFolder::GetDisplayNameOf().

◆ GetDriveNumber()

static INT8 GetDriveNumber ( PCUITEMID_CHILD  pidl)
static

Definition at line 90 of file CDrivesFolder.cpp.

91{
92 if (!_ILIsDrive(pidl))
93 return -1;
94 BYTE letter = ((PIDLDATA*)pidl->mkid.abID)->u.drive.szDriveName[0];
95 BYTE number = (letter | 32) - 'a';
96 return number < 26 ? number : -1;
97}
static unsigned int number
Definition: dsound.c:1479
BOOL _ILIsDrive(LPCITEMIDLIST pidl)
Definition: pidl.c:2130
unsigned char BYTE
Definition: xxhash.c:193

Referenced by GetDrivePath(), and CDrivesFolder::MessageSFVCB().

◆ GetDrivePath()

template<class T >
static T * GetDrivePath ( PCUITEMID_CHILD  pidl,
T Path 
)
static

Definition at line 99 of file CDrivesFolder.cpp.

100{
101 int number = GetDriveNumber(pidl);
102 if (number < 0)
103 return NULL;
104 Path[0] = 'A' + number;
105 Path[1] = ':';
106 Path[2] = '\\';
107 Path[3] = '\0';
108 return Path;
109}
static INT8 GetDriveNumber(PCUITEMID_CHILD pidl)
PRTL_UNICODE_STRING_BUFFER Path

Referenced by _ILGetRemovableTypeId(), CDrivesFolder::GetDisplayNameOf(), and CDrivesFolder::SetNameOf().

◆ getIconLocationForDrive()

static HRESULT getIconLocationForDrive ( IShellFolder psf,
PCITEMID_CHILD  pidl,
UINT  uFlags,
LPWSTR  szIconFile,
UINT  cchMax,
int piIndex,
UINT pwFlags 
)
static

Definition at line 413 of file CDrivesFolder.cpp.

415{
416 WCHAR wszPath[MAX_PATH];
417 WCHAR wszAutoRunInfPath[MAX_PATH];
418 WCHAR wszValue[MAX_PATH], wszTemp[MAX_PATH];
419
420 // get path
421 if (!ILGetDisplayNameExW(psf, pidl, wszPath, 0))
422 return E_FAIL;
423 if (!PathIsDirectoryW(wszPath))
424 return E_FAIL;
425
426 // build the full path of autorun.inf
427 StringCchCopyW(wszAutoRunInfPath, _countof(wszAutoRunInfPath), wszPath);
428 PathAppendW(wszAutoRunInfPath, L"autorun.inf");
429
430 // autorun.inf --> wszValue
431 if (GetPrivateProfileStringW(L"autorun", L"icon", NULL, wszValue, _countof(wszValue),
432 wszAutoRunInfPath) && wszValue[0] != 0)
433 {
434 // wszValue --> wszTemp
435 ExpandEnvironmentStringsW(wszValue, wszTemp, _countof(wszTemp));
436
437 // parse the icon location
438 *piIndex = PathParseIconLocationW(wszTemp);
439
440 // wszPath + wszTemp --> wszPath
441 if (PathIsRelativeW(wszTemp))
442 PathAppendW(wszPath, wszTemp);
443 else
444 StringCchCopyW(wszPath, _countof(wszPath), wszTemp);
445
446 // wszPath --> szIconFile
447 GetFullPathNameW(wszPath, cchMax, szIconFile, NULL);
448
449 return S_OK;
450 }
451
452 return E_FAIL;
453}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
INT WINAPI GetPrivateProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR def_val, LPWSTR buffer, UINT len, LPCWSTR filename)
Definition: profile.c:1142
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1729
int WINAPI PathParseIconLocationW(LPWSTR lpszPath)
Definition: path.c:1098
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1585
#define PathAppendW
Definition: pathcch.h:309
BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
Definition: pidl.c:100
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149

Referenced by CDrivesExtractIcon_CreateInstance().

◆ getLabelForDriveFromAutoRun()

static HRESULT getLabelForDriveFromAutoRun ( PCWSTR  wszPath,
LPWSTR  szLabel,
UINT  cchMax 
)
static

Definition at line 456 of file CDrivesFolder.cpp.

457{
458 WCHAR wszAutoRunInfPath[MAX_PATH];
459 WCHAR wszTemp[MAX_PATH];
460
461 if (!PathIsDirectoryW(wszPath))
462 return E_FAIL;
463
464 StringCchCopyW(wszAutoRunInfPath, _countof(wszAutoRunInfPath), wszPath);
465 PathAppendW(wszAutoRunInfPath, L"autorun.inf");
466
467 if (GetPrivateProfileStringW(L"autorun", L"label", NULL, wszTemp, _countof(wszTemp),
468 wszAutoRunInfPath) && wszTemp[0] != 0)
469 {
470 StringCchCopyW(szLabel, cchMax, wszTemp);
471 return S_OK;
472 }
473
474 return E_FAIL;
475}

Referenced by GetDriveLabel().

◆ GetRawDriveLabel()

static HRESULT GetRawDriveLabel ( PCWSTR  DrivePath,
LPWSTR  szLabel,
UINT  cchMax 
)
inlinestatic

Definition at line 477 of file CDrivesFolder.cpp.

478{
479 if (GetVolumeInformationW(DrivePath, szLabel, cchMax, NULL, NULL, NULL, NULL, 0))
480 return *szLabel ? S_OK : S_FALSE;
482}
#define HResultFromWin32
Definition: loader.cpp:14
#define S_FALSE
Definition: winerror.h:2357

Referenced by GetDriveLabel().

◆ IsDriveFloppyA()

BOOL IsDriveFloppyA ( LPCSTR  pszDriveRoot)

Definition at line 386 of file drvdefext.cpp.

387{
388 WCHAR szRoot[8];
389 MultiByteToWideChar(CP_ACP, 0, pszDriveRoot, -1, szRoot, _countof(szRoot));
390 return IsDriveFloppyW(szRoot);
391}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
BOOL IsDriveFloppyW(LPCWSTR pszDriveRoot)
Definition: drvdefext.cpp:320

Referenced by CDrivesExtractIcon_CreateInstance(), and CDrivesFolder::GetDetailsOf().

◆ IsDriveFloppyW()

BOOL IsDriveFloppyW ( LPCWSTR  pszDriveRoot)

Definition at line 320 of file drvdefext.cpp.

321{
322 LPCWSTR RootPath = pszDriveRoot;
323 WCHAR szRoot[16], szDeviceName[16];
324 UINT uType;
325 HANDLE hDevice;
327 ULONG ulCharacteristics;
328 BOOL ret;
329
330 lstrcpynW(szRoot, RootPath, _countof(szRoot));
331
332 if (L'a' <= szRoot[0] && szRoot[0] <= 'z')
333 {
334 szRoot[0] += ('A' - 'a');
335 }
336
337 if ('A' <= szRoot[0] && szRoot[0] <= L'Z' &&
338 szRoot[1] == L':' && szRoot[2] == 0)
339 {
340 // 'C:' --> 'C:\'
341 szRoot[2] = L'\\';
342 szRoot[3] = 0;
343 }
344
345 if (!PathIsRootW(szRoot))
346 {
347 return FALSE;
348 }
349
350 uType = GetDriveTypeW(szRoot);
351 if (uType == DRIVE_REMOVABLE)
352 {
353 if (szRoot[0] == L'A' || szRoot[0] == L'B')
354 return TRUE;
355 }
356 else
357 {
358 return FALSE;
359 }
360
362 szDeviceName[4] = szRoot[0];
363 szDeviceName[5] = L':';
365
368 NULL, OPEN_EXISTING, 0, NULL);
369 if (hDevice == INVALID_HANDLE_VALUE)
370 {
371 return FALSE;
372 }
373
374 ret = FALSE;
375 if (GetDriveTypeAndCharacteristics(hDevice, &DeviceType, &ulCharacteristics))
376 {
377 if ((ulCharacteristics & FILE_FLOPPY_DISKETTE) == FILE_FLOPPY_DISKETTE)
378 ret = TRUE;
379 }
380
381 CloseHandle(hDevice);
382
383 return ret;
384}
static const WCHAR szDeviceName[]
Definition: provider.c:56
#define DEVICE_TYPE
Definition: guid.c:10
#define CreateFileW
Definition: compat.h:741
#define lstrcpynW
Definition: compat.h:738
BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
Definition: path.c:1648
static BOOL GetDriveTypeAndCharacteristics(HANDLE hDevice, DEVICE_TYPE *pDeviceType, ULONG *pCharacteristics)
Definition: drvdefext.cpp:301
DeviceType
Definition: mmdrv.h:42
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
uint32_t ULONG
Definition: typedefs.h:59
int ret
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by _ILGetRemovableTypeId(), and IsDriveFloppyA().

◆ IsRegItem() [1/2]

static const CLSID * IsRegItem ( PCUITEMID_CHILD  pidl)
static

Definition at line 74 of file CDrivesFolder.cpp.

75{
76 if (pidl && pidl->mkid.cb == 2 + 2 + sizeof(CLSID))
77 {
78 if (pidl->mkid.abID[0] == PT_SHELLEXT || pidl->mkid.abID[0] == PT_GUID) // FIXME: Remove PT_GUID when CRegFolder is fixed
79 return (const CLSID*)(&pidl->mkid.abID[2]);
80 }
81 return NULL;
82}
#define PT_GUID
Definition: pidl.h:87
#define PT_SHELLEXT
Definition: pidl.h:91

Referenced by IsRegItem().

◆ IsRegItem() [2/2]

static bool IsRegItem ( PCUITEMID_CHILD  pidl,
REFCLSID  clsid 
)
static

Definition at line 84 of file CDrivesFolder.cpp.

85{
86 const CLSID *pClass = IsRegItem(pidl);
87 return pClass && *pClass == clsid;
88}
static const CLSID * IsRegItem(PCUITEMID_CHILD pidl)
REFCLSID clsid
Definition: msctf.c:82

◆ SHELL32_IsShellFolderNamespaceItemHidden()

BOOL SHELL32_IsShellFolderNamespaceItemHidden ( LPCWSTR  SubKey,
REFCLSID  Clsid 
)

Definition at line 130 of file CDrivesFolder.cpp.

131{
132 // If this function returns true, the item should be hidden in DefView but not in the Explorer folder tree.
134 wsprintfW(path, L"%s\\%s", REGSTR_PATH_EXPLORER, SubKey);
136 DWORD data = 0, size = sizeof(data);
138}
#define CHARS_IN_GUID
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
#define RRF_RT_DWORD
Definition: driver.c:581
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
#define REGSTR_PATH_EXPLORER
Definition: regstr.h:33
static __inline int SHELL32_GUIDToStringW(REFGUID guid, LPWSTR str)
Definition: shfldr.h:162
Definition: name.c:39
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by CDesktopFolderViewCB::ShouldShow(), and CDrivesFolder::ShouldShow().

◆ TryToLockOrUnlockDrive()

static BOOL TryToLockOrUnlockDrive ( HANDLE  hDrive,
BOOL  bLock 
)
static

Definition at line 146 of file CDrivesFolder.cpp.

147{
148 DWORD dwError, dwBytesReturned;
149 DWORD dwCode = (bLock ? FSCTL_LOCK_VOLUME : FSCTL_UNLOCK_VOLUME);
150 for (DWORD i = 0; i < RETRY_COUNT; ++i)
151 {
152 if (DeviceIoControl(hDrive, dwCode, NULL, 0, NULL, 0, &dwBytesReturned, NULL))
153 return TRUE;
154
155 dwError = GetLastError();
156 if (dwError == ERROR_INVALID_FUNCTION)
157 break; /* don't sleep if function is not implemented */
158
160 }
161 SetLastError(dwError);
162 return FALSE;
163}
#define RETRY_COUNT
#define RETRY_SLEEP
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790

Referenced by DoEjectDrive().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )

Variable Documentation

◆ dwComputerAttributes

const DWORD dwComputerAttributes
static
Initial value:
=
SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET |
SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_CANLINK

Definition at line 606 of file CDrivesFolder.cpp.

Referenced by CDrivesFolder::GetAttributesOf().

◆ dwControlPanelAttributes

const DWORD dwControlPanelAttributes
static
Initial value:
=
SFGAO_HASSUBFOLDER | SFGAO_FOLDER | SFGAO_CANLINK

Definition at line 609 of file CDrivesFolder.cpp.

Referenced by CControlPanelFolder::GetAttributesOf(), and CDrivesFolder::GetAttributesOf().

◆ dwDriveAttributes

const DWORD dwDriveAttributes
static
Initial value:
=
SFGAO_HASSUBFOLDER | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR |
SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANRENAME | SFGAO_CANLINK | SFGAO_CANCOPY

Definition at line 611 of file CDrivesFolder.cpp.

Referenced by CDrivesFolder::GetAttributesOf().

◆ g_RegFolderInfo

const REGFOLDERINFO g_RegFolderInfo
static
Initial value:
=
{
CLSID_MyComputer,
L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
L"MyComputer",
}
static const REQUIREDREGITEM g_RequiredItems[]
#define PT_COMPUTER_REGITEM
Definition: lnktool.cpp:39

Definition at line 65 of file CDrivesFolder.cpp.

◆ g_RequiredItems

const REQUIREDREGITEM g_RequiredItems[]
static
Initial value:
=
{
{ CLSID_ControlPanel, 0, 0x50 },
}

Definition at line 61 of file CDrivesFolder.cpp.

◆ iDriveIconIds

◆ iDriveTypeIds

int iDriveTypeIds[7]
static
Initial value:
}
#define IDS_DRIVE_CDROM
Definition: shresdef.h:112
#define IDS_DRIVE_FIXED
Definition: shresdef.h:111
#define IDS_DRIVE_NETWORK
Definition: shresdef.h:113
#define IDS_DRIVE_FLOPPY
Definition: shresdef.h:114

Definition at line 52 of file CDrivesFolder.cpp.

Referenced by CDrivesFolder::GetDetailsOf().

◆ MyComputerSFHeader