ReactOS 0.4.16-dev-1142-g8029339
CRegFolder.cpp File Reference
#include <precomp.h>
Include dependency graph for CRegFolder.cpp:

Go to the source code of this file.

Classes

struct  CRegFolderInfo
 
class  CRegFolderEnum
 
class  CRegFolder
 

Enumerations

enum  REGFOLDERCOLUMNINDEX { COL_NAME = SHFSF_COL_NAME , COL_TYPE = SHFSF_COL_TYPE , COL_INFOTIP = SHFSF_COL_COMMENT , REGFOLDERCOLUMNCOUNT = max(COL_INFOTIP, COL_TYPE) + 1 }
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
static HRESULT CRegItemContextMenu_CreateInstance (PCIDLIST_ABSOLUTE pidlFolder, HWND hwnd, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IShellFolder *psf, IContextMenu **ppcm)
 
HRESULT FormatGUIDKey (LPWSTR KeyName, SIZE_T KeySize, LPCWSTR RegPath, const GUID *riid)
 
static DWORD SHELL_QueryCLSIDValue (_In_ REFCLSID clsid, _In_opt_ LPCWSTR SubKey, _In_opt_ LPCWSTR Value, _In_opt_ PVOID pData, _In_opt_ PDWORD pSize)
 
static bool HasCLSIDShellFolderValue (REFCLSID clsid, LPCWSTR Value)
 
static UINT GetRegItemCLSIDOffset (PIDLTYPE type)
 
static BYTE GetRegItemOrder (REFCLSID clsid)
 
static LPITEMIDLIST CreateRegItem (PIDLTYPE type, REFCLSID clsid, int order=-1)
 
static LPITEMIDLIST CreateRegItem (PIDLTYPE type, LPCWSTR clsidstr)
 
HRESULT CGuidItemExtractIcon_CreateInstance (LPCITEMIDLIST pidl, REFIID iid, LPVOID *ppvOut)
 
static HRESULT CALLBACK RegFolderContextMenuCallback (IShellFolder *psf, HWND hwnd, IDataObject *pdtobj, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
HRESULT CRegFolder_CreateInstance (PREGFOLDERINITDATA pInit, LPCITEMIDLIST pidlRoot, REFIID riid, void **ppv)
 

Enumeration Type Documentation

◆ REGFOLDERCOLUMNINDEX

Enumerator
COL_NAME 
COL_TYPE 
COL_INFOTIP 
REGFOLDERCOLUMNCOUNT 

Definition at line 313 of file CRegFolder.cpp.

314{
319};
@ REGFOLDERCOLUMNCOUNT
Definition: CRegFolder.cpp:318
@ COL_INFOTIP
Definition: CRegFolder.cpp:317
@ COL_NAME
Definition: CRegFolder.cpp:315
@ COL_TYPE
Definition: CRegFolder.cpp:316
#define SHFSF_COL_COMMENT
Definition: shfldr.h:49
#define SHFSF_COL_NAME
Definition: shfldr.h:44
#define SHFSF_COL_TYPE
Definition: shfldr.h:46
#define max(a, b)
Definition: svc.c:63

Function Documentation

◆ CGuidItemExtractIcon_CreateInstance()

HRESULT CGuidItemExtractIcon_CreateInstance ( LPCITEMIDLIST  pidl,
REFIID  iid,
LPVOID ppvOut 
)

Definition at line 141 of file CRegFolder.cpp.

142{
143 CComPtr<IDefaultExtractIconInit> initIcon;
144 HRESULT hr;
145 GUID const * riid;
146 int icon_idx;
147 WCHAR wTemp[MAX_PATH];
148
150 if (FAILED(hr))
151 return hr;
152
153 if (_ILIsDesktop(pidl))
154 {
155 initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DESKTOP);
156 return initIcon->QueryInterface(iid, ppvOut);
157 }
158
159 riid = _ILGetGUIDPointer(pidl);
160 if (!riid)
161 return E_FAIL;
162
163 /* Choose a correct icon for Recycle Bin (full or empty) */
164 const WCHAR* iconname = NULL;
165 if (_ILIsBitBucket(pidl))
166 {
167 CComPtr<IEnumIDList> EnumIDList;
169
170 CComPtr<IShellFolder2> psfRecycleBin;
171 CComPtr<IShellFolder> psfDesktop;
172 hr = SHGetDesktopFolder(&psfDesktop);
173
174 if (SUCCEEDED(hr))
175 hr = psfDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder2, &psfRecycleBin));
176 if (SUCCEEDED(hr))
177 hr = psfRecycleBin->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &EnumIDList);
178
179 ULONG itemcount;
180 LPITEMIDLIST pidl = NULL;
181 if (SUCCEEDED(hr) && (hr = EnumIDList->Next(1, &pidl, &itemcount)) == S_OK)
182 {
183 CoTaskMemFree(pidl);
184 iconname = L"Full";
185 } else {
186 iconname = L"Empty";
187 }
188 }
189
190 /* Prepare registry path for loading icons of My Computer and other shell extensions */
192
194 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\%s",
195 riid);
197 return hr;
198
199 /* Load icon for the current user */
200 BOOL ret = HCU_GetIconW(KeyName, wTemp, iconname, _countof(wTemp), &icon_idx);
201 if (!ret)
202 {
203 /* Failed, load default system-wide icon */
204 hr = FormatGUIDKey(KeyName, _countof(KeyName), L"CLSID\\%s", riid);
206 return hr;
207
208 ret = HCR_GetIconW(KeyName, wTemp, iconname, _countof(wTemp), &icon_idx);
209 }
210
211 if (ret)
212 {
213 /* Success, set loaded icon */
214 initIcon->SetNormalIcon(wTemp, icon_idx);
215 }
216 else
217 {
218 /* Everything has failed, set blank paper icon */
219 WARN("Failed to load an icon for the item, setting blank icon\n");
220 initIcon->SetNormalIcon(swShell32Name, IDI_SHELL_DOCUMENT - 1);
221 }
222
223 return initIcon->QueryInterface(iid, ppvOut);
224}
BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
Definition: CBandSite.h:24
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
HRESULT WINAPI SHCreateDefaultExtractIcon(REFIID riid, void **ppv)
HRESULT FormatGUIDKey(LPWSTR KeyName, SIZE_T KeySize, LPCWSTR RegPath, const GUID *riid)
Definition: CRegFolder.cpp:31
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:68
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
unsigned int BOOL
Definition: ntddk_ex.h:94
WCHAR swShell32Name[MAX_PATH]
Definition: folders.cpp:22
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
REFIID riid
Definition: atlbase.h:39
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define L(x)
Definition: ntvdm.h:50
BOOL _ILIsBitBucket(LPCITEMIDLIST pidl)
Definition: pidl.c:2108
IID * _ILGetGUIDPointer(LPCITEMIDLIST pidl)
Definition: pidl.c:2407
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_DESKTOP
Definition: shresdef.h:613
#define IDI_SHELL_DOCUMENT
Definition: shresdef.h:579
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define _countof(array)
Definition: sndvol32.h:70
uint32_t ULONG
Definition: typedefs.h:59
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CRegFolder::GetUIObjectOf().

◆ CreateRegItem() [1/2]

static LPITEMIDLIST CreateRegItem ( PIDLTYPE  type,
LPCWSTR  clsidstr 
)
static

Definition at line 90 of file CRegFolder.cpp.

91{
93 return SUCCEEDED(CLSIDFromString(clsidstr, &clsid)) ? CreateRegItem(type, clsid) : NULL;
94}
static LPITEMIDLIST CreateRegItem(PIDLTYPE type, REFCLSID clsid, int order=-1)
Definition: CRegFolder.cpp:70
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
REFCLSID clsid
Definition: msctf.c:82

◆ CreateRegItem() [2/2]

static LPITEMIDLIST CreateRegItem ( PIDLTYPE  type,
REFCLSID  clsid,
int  order = -1 
)
static

Definition at line 70 of file CRegFolder.cpp.

71{
72#if 1 // FIXME: CControlPanelFolder is not ready for this yet
73 if (type == PT_CONTROLS_NEWREGITEM)
74 type = PT_CONTROLS_OLDREGITEM;
75#endif
77 const UINT cb = offset + sizeof(CLSID), cbTotal = cb + sizeof(WORD);
78 LPITEMIDLIST pidl = (LPITEMIDLIST)SHAlloc(cbTotal);
79 if (pidl)
80 {
81 ZeroMemory(pidl, cbTotal); // Note: This also initializes the terminator WORD
82 pidl->mkid.cb = cb;
83 pidl->mkid.abID[0] = type;
84 pidl->mkid.abID[1] = order >= 0 ? (BYTE)order : GetRegItemOrder(clsid);
85 *(CLSID*)(SIZE_T(pidl) + offset) = clsid;
86 }
87 return pidl;
88}
static UINT GetRegItemCLSIDOffset(PIDLTYPE type)
Definition: CRegFolder.cpp:57
static BYTE GetRegItemOrder(REFCLSID clsid)
Definition: CRegFolder.cpp:62
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:304
unsigned short WORD
Definition: ntddk_ex.h:93
GLintptr offset
Definition: glext.h:5920
GLuint GLdouble GLdouble GLint GLint order
Definition: glext.h:11194
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
IID CLSID
Definition: mstsclib_i.c:62
unsigned int UINT
Definition: ndis.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ZeroMemory
Definition: winbase.h:1743
unsigned char BYTE
Definition: xxhash.c:193

Referenced by CRegFolderEnum::AddItemsFromKey(), CRegFolderInfo::CreateItem(), CreateRegItem(), and CRegFolder::ParseDisplayName().

◆ CRegFolder_CreateInstance()

HRESULT CRegFolder_CreateInstance ( PREGFOLDERINITDATA  pInit,
LPCITEMIDLIST  pidlRoot,
REFIID  riid,
void **  ppv 
)

Definition at line 1002 of file CRegFolder.cpp.

1003{
1004 return ShellObjectCreatorInit<CRegFolder>(pInit, pidlRoot, riid, ppv);
1005}
PWDFDEVICE_INIT pInit
REFIID LPVOID * ppv
Definition: atlbase.h:39

Referenced by CDesktopFolder::FinalConstruct(), CDrivesFolder::FinalConstruct(), and CControlPanelFolder::Initialize().

◆ CRegItemContextMenu_CreateInstance()

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

Definition at line 972 of file CRegFolder.cpp.

974{
975 HKEY hKeys[3];
976 UINT cKeys = 0;
977
978 const GUID *pGuid = _ILGetGUIDPointer(apidl[0]);
979 if (pGuid)
980 {
981 WCHAR key[sizeof("CLSID\\") + 38];
982 wcscpy(key, L"CLSID\\");
983 StringFromGUID2(*pGuid, &key[6], 39);
984 AddClassKeyToArray(key, hKeys, &cKeys);
985 }
986
987 // FIXME: CRegFolder should be aggregated by its outer folder and should
988 // provide the attributes for all required non-registry folders.
989 // It currently does not so we have to ask the outer folder ourself so
990 // that we get the correct attributes for My Computer etc.
991 CComPtr<IShellFolder> pOuterSF;
992 SHBindToObject(NULL, pidlFolder, IID_PPV_ARG(IShellFolder, &pOuterSF));
993
994 SFGAOF att = (psf && cidl) ? SHGetAttributes(pOuterSF ? pOuterSF.p : psf, apidl[0], SFGAO_FOLDER) : 0;
995 if ((att & SFGAO_FOLDER) && (!pGuid || !HasCLSIDShellFolderValue(*pGuid, L"HideFolderVerbs")))
996 AddClassKeyToArray(L"Folder", hKeys, &cKeys);
997
998 return CDefFolderMenu_Create2(pidlFolder, hwnd, cidl, apidl, psf, RegFolderContextMenuCallback, cKeys, hKeys, ppcm);
999}
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)
static HRESULT CALLBACK RegFolderContextMenuCallback(IShellFolder *psf, HWND hwnd, IDataObject *pdtobj, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: CRegFolder.cpp:922
static bool HasCLSIDShellFolderValue(REFCLSID clsid, LPCWSTR Value)
Definition: CRegFolder.cpp:52
wcscpy
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
DWORD SHGetAttributes(_In_ IShellFolder *psf, _In_ LPCITEMIDLIST pidl, _In_ DWORD dwAttributes)
Definition: utils.cpp:425
EXTERN_C HRESULT SHBindToObject(_In_opt_ IShellFolder *psf, _In_ LPCITEMIDLIST pidl, _In_ REFIID riid, _Out_ void **ppvObj)
Definition: utils.cpp:370
static IShellFolder IShellItem **static IBindCtx LPITEMIDLIST SFGAOF
Definition: ebrowser.c:83
LSTATUS AddClassKeyToArray(const WCHAR *szClass, HKEY *array, UINT *cKeys)
Definition: shlfolder.cpp:408
Definition: copy.c:22
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by CRegFolder::GetUIObjectOf().

◆ FormatGUIDKey()

HRESULT FormatGUIDKey ( LPWSTR  KeyName,
SIZE_T  KeySize,
LPCWSTR  RegPath,
const GUID riid 
)

Definition at line 31 of file CRegFolder.cpp.

32{
33 WCHAR xriid[CHARS_IN_GUID];
34 StringFromGUID2(*riid, xriid, _countof(xriid));
35 return StringCchPrintfW(KeyName, KeySize, RegPath, xriid);
36}
#define CHARS_IN_GUID
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530

Referenced by CGuidItemExtractIcon_CreateInstance(), and CRegFolder::SetNameOf().

◆ GetRegItemCLSIDOffset()

static UINT GetRegItemCLSIDOffset ( PIDLTYPE  type)
inlinestatic

Definition at line 57 of file CRegFolder.cpp.

58{
59 return type == PT_CONTROLS_NEWREGITEM ? 14 : 4;
60}

Referenced by CreateRegItem(), CRegFolderInfo::GetCLSIDOffset(), and CRegFolderInfo::IsRegItem().

◆ GetRegItemOrder()

static BYTE GetRegItemOrder ( REFCLSID  clsid)
static

Definition at line 62 of file CRegFolder.cpp.

63{
64 DWORD dwOrder, cb = sizeof(dwOrder);
65 if (SHELL_QueryCLSIDValue(clsid, NULL, L"SortOrderIndex", &dwOrder, &cb) || cb != sizeof(dwOrder))
66 dwOrder = REGITEMORDER_DEFAULT;
67 return (BYTE)dwOrder;
68}
static DWORD SHELL_QueryCLSIDValue(_In_ REFCLSID clsid, _In_opt_ LPCWSTR SubKey, _In_opt_ LPCWSTR Value, _In_opt_ PVOID pData, _In_opt_ PDWORD pSize)
Definition: CRegFolder.cpp:38
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by CreateRegItem().

◆ HasCLSIDShellFolderValue()

static bool HasCLSIDShellFolderValue ( REFCLSID  clsid,
LPCWSTR  Value 
)
static

Definition at line 52 of file CRegFolder.cpp.

53{
54 return SHELL_QueryCLSIDValue(clsid, L"ShellFolder", Value, NULL, NULL) == ERROR_SUCCESS;
55}
#define ERROR_SUCCESS
Definition: deptool.c:10
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by CRegItemContextMenu_CreateInstance().

◆ RegFolderContextMenuCallback()

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

Definition at line 922 of file CRegFolder.cpp.

924{
926 return SHELL32_DefaultContextMenuCallBack(psf, pdtobj, uMsg);
927
928 PIDLIST_ABSOLUTE pidlFolder;
929 PUITEMID_CHILD *apidl;
930 UINT cidl;
931 HRESULT hr = SH_GetApidlFromDataObject(pdtobj, &pidlFolder, &apidl, &cidl);
933 return hr;
934
935 const CLSID* pCLSID;
936 CRegFolder *pRegFolder = static_cast<CRegFolder*>(psf);
937 const REQUIREDREGITEM* pRequired = pRegFolder->IsRequiredItem(apidl[0]);
938 if (pRequired && pRequired->pszCpl)
939 {
941 wsprintfW(buf, L"%hs", const_cast<LPCSTR>(pRequired->pszCpl));
943 }
944#if 0 // Should never happen, CDesktopFolder.cpp handles this
945 else if (_ILIsDesktop(pidlFolder) && _ILIsDesktop(apidl[0]))
946 {
948 }
949#endif
950 else if ((pCLSID = pRegFolder->IsRegItem(apidl[0])) != NULL)
951 {
952 if (CLSID_MyDocuments != *pCLSID)
953 {
955 }
956 else
957 {
958 FIXME("ROS MyDocs must implement IShellPropSheetExt\n");
959 hr = S_FALSE; // Just display the filesystem properties
960 }
961 }
962 else
963 {
964 hr = S_FALSE; // Tell the caller to run the default action
965 }
966
967 SHFree(pidlFolder);
968 _ILFreeaPidl(apidl, cidl);
969 return hr;
970}
#define FIXME(fmt,...)
Definition: precomp.h:53
const REQUIREDREGITEM * IsRequiredItem(LPCITEMIDLIST pidl) const
Definition: CRegFolder.cpp:339
WPARAM wParam
Definition: combotst.c:138
#define DFM_INVOKECOMMAND
Definition: precomp.h:45
#define SHELL_ExecuteControlPanelCPL(hwnd, cpl)
Definition: precomp.h:188
HRESULT SHELL32_DefaultContextMenuCallBack(IShellFolder *psf, IDataObject *pdo, UINT msg)
Definition: shlfolder.cpp:613
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:326
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
HRESULT SHELL32_ShowShellExtensionProperties(const CLSID *pClsid, IDataObject *pDO)
Definition: item_prop.cpp:196
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
#define DFM_CMD_PROPERTIES
Definition: shlobj.h:2620
ITEMID_CHILD UNALIGNED * PUITEMID_CHILD
Definition: shtypes.idl:68
const CLSID * IsRegItem(LPCITEMIDLIST pidl) const
Definition: CRegFolder.cpp:105
LPCSTR pszCpl
Definition: shfldr.h:54
#define S_FALSE
Definition: winerror.h:2357
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by CRegItemContextMenu_CreateInstance().

◆ SHELL_QueryCLSIDValue()

static DWORD SHELL_QueryCLSIDValue ( _In_ REFCLSID  clsid,
_In_opt_ LPCWSTR  SubKey,
_In_opt_ LPCWSTR  Value,
_In_opt_ PVOID  pData,
_In_opt_ PDWORD  pSize 
)
static

Definition at line 38 of file CRegFolder.cpp.

39{
40 const UINT cchGuid = CHARS_IN_GUID - 1, cchClsidSlash = sizeof("CLSID\\") - 1;
41 WCHAR Path[200];
42 wcscpy(Path, L"CLSID\\");
44 if (SubKey)
45 {
46 *(Path + cchClsidSlash + cchGuid) = L'\\';
47 wcscpy(Path + cchClsidSlash + cchGuid + 1, SubKey);
48 }
50}
PRTL_UNICODE_STRING_BUFFER Path
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
#define RRF_RT_ANY
Definition: winreg.h:64
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10

Referenced by GetRegItemOrder(), and HasCLSIDShellFolderValue().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )