ReactOS 0.4.15-dev-8102-g108db8f
CSHEnumClassesOfCategories.cpp
Go to the documentation of this file.
1/*
2 * ReactOS Explorer
3 *
4 * Copyright 2016 Sylvain Deverre <deverre dot sylv at gmail dot com>
5 *
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.
10 *
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.
15 *
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
19 */
20
21/*
22 * Wraps the component categories manager enum
23 */
24
25#include "shellbars.h"
26
27#define REGPATH L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Discardable\\PostSetup\\Component Categories"
28#define IMPLEMENTING L"Implementing"
29#define REQUIRING L"Requiring"
30
31typedef struct categoryCacheHeader
32{
33 DWORD dwSize; // size of header only
34 DWORD version; // currently 1
35 SYSTEMTIME writeTime; // time we were written to registry
36 DWORD classCount; // number of classes following
38
39/*
40 * This class manages a cached explorer component categories items, writing cache if it
41 * doesn't exist yet.
42 * It is used by CSHEnumClassesOfCategories internally.
43 */
45{
46 public:
48 virtual ~CComCatCachedCategory();
50 HRESULT STDMETHODCALLTYPE Initialize(CATID &catID, BOOL reloadCache);
51 private:
57};
58
60{
61 fLocalDsa = DSA_Create(sizeof(GUID), 5);
62}
63
65{
66 HRESULT hr;
67
68 fCategory = catID;
69 if (reloadCache || !LoadFromRegistry())
70 {
73 return hr;
74
75 hr = CacheDSA();
77 return hr;
78 }
79 return S_OK;
80}
81
83{
85}
86
88{
89 WCHAR bufKey[MAX_PATH];
92 CComHeapPtr<CATCACHEHDR> buffer;
93 GUID *guidArray;
94
95 if (!fLocalDsa)
96 return FALSE;
97
98 dataSize = 0;
100 return FALSE;
101
102 wsprintf(bufKey, L"%s\\%s\\%s", REGPATH , guidStr, L"Enum");
103
104 // Try to read key and get proper value size
106 return FALSE;
107
109
111 guidArray = (GUID*)(buffer + 1);
112 for (i = 0; i < buffer->classCount; i++)
113 {
114 // Add class to cache
115 DSA_InsertItem(fLocalDsa, DSA_APPEND, guidArray + i);
116 }
117
118 return TRUE;
119}
120
122{
123 WCHAR bufKey[MAX_PATH];
125 UINT elemCount;
126 UINT i;
128 CComHeapPtr<CATCACHEHDR> buffer;
129 GUID *guidArray;
130 GUID *tmp;
131
132 elemCount = DSA_GetItemCount(fLocalDsa);
133 bufferSize = sizeof(CATCACHEHDR) + elemCount * sizeof(GUID);
135 return E_FAIL;
136
138 if (!buffer)
139 return E_OUTOFMEMORY;
140
141 // Correctly fill cache header
142 buffer->dwSize = sizeof(CATCACHEHDR);
143 buffer->version = 1;
144 GetSystemTime(&buffer->writeTime);
145 buffer->classCount = (DWORD)elemCount;
146
147 guidArray = (GUID*)(buffer + 1);
148 wsprintf(bufKey, L"%s\\%s\\%s", REGPATH , guidStr, L"Enum");
149
150 // Write DSA contents inside the memory buffer allocated
151 for(i = 0; i < elemCount; i++)
152 {
153 tmp = (GUID*)DSA_GetItemPtr(fLocalDsa, i);
154 if (tmp)
155 {
156 guidArray[i] = *tmp;
157 }
158 }
159
160 // Save items to registry
162
163 guidArray = NULL;
164 return S_OK;
165}
166
168{
169 HRESULT hr;
170 CComPtr<ICatInformation> pCatInformation;
171 CComPtr<IEnumGUID> pEnumGUID;
172 ULONG pFetched;
173 CLSID tmp;
174
175 // Get component categories manager instance
176 hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER,
177 IID_PPV_ARG(ICatInformation, &pCatInformation));
179 return hr;
180
181 // Get the proper enumerator
182 hr = pCatInformation->EnumClassesOfCategories(1, &fCategory, NULL, NULL, &pEnumGUID);
184 return hr;
185
186 // Enumerate elements
187 do
188 {
189 pFetched = 0;
190 pEnumGUID->Next(1, &tmp, &pFetched);
191 if (pFetched)
192 {
194 return E_OUTOFMEMORY;
195 }
196 }
197 while (pFetched > 0);
198 return S_OK;
199}
200
202{
203 INT i;
204 for(i = 0; i < DSA_GetItemCount(fLocalDsa); i++)
205 {
207 return E_OUTOFMEMORY;
208 }
209 return S_OK;
210}
211
213 public CComCoClass<CSHEnumClassesOfCategories>,
214 public CComObjectRootEx<CComMultiThreadModelNoCS>,
215 public IEnumGUID
216{
217 private:
218 CComPtr<ICatInformation> fCatInformation;
221
222 public:
225 STDMETHOD(Initialize)(ULONG cImplemented, CATID *pImplemented, ULONG cRequired, CATID *pRequired);
226
227 // *** IEnumGUID methods ***
228 STDMETHOD(Clone)(IEnumCLSID **ppvOut) override;
229 STDMETHOD(Next)(ULONG cElt, CLSID *pElts, ULONG *pFetched) override;
230 STDMETHOD(Reset)() override;
231 STDMETHOD(Skip)(ULONG nbElts) override;
232
234 COM_INTERFACE_ENTRY_IID(IID_IEnumGUID, IEnumGUID)
236};
237
239{
240 fCursor = 0;
241 fDsa = DSA_Create(sizeof(GUID), 5);
242}
243
245{
246 if (fDsa)
248}
249
250HRESULT CSHEnumClassesOfCategories::Initialize(ULONG cImplemented, CATID *pImplemented, ULONG cRequired, CATID *pRequired)
251{
252 UINT i;
253 HRESULT hr;
254
255 if (!fDsa)
256 return E_FAIL;
257
258 // Parameter validation:
259 // - We must have at least one category to manage.
260 // - The array pointers must not be NULL if there is a non-zero
261 // element count specified for them.
262 if (cImplemented == 0 && cRequired == 0)
263 return E_INVALIDARG;
264 if ((cImplemented && !pImplemented) || (cRequired && !pRequired))
265 return E_INVALIDARG;
266
267 // For each implemented category, create a cache and add it to our local DSA.
268 for (i = 0; i < cImplemented; i++)
269 {
270 CComCatCachedCategory cachedCat;
271 hr = cachedCat.Initialize(pImplemented[i], FALSE);
273 return hr;
274 cachedCat.WriteCacheToDSA(fDsa);
275 }
276
277 // TODO: Implement caching of the required categories.
278 if (cRequired > 0)
279 {
280 FIXME("Implement required categories class enumeration\n");
281
282 // Only fail in case we didn't look at the implemented categories.
283 if (cImplemented == 0)
284 return E_NOTIMPL;
285 }
286
287 return S_OK;
288}
289
290// *** IEnumGUID methods ***
291
293{
294 return E_NOTIMPL;
295}
296
298{
299 ULONG i;
300 ULONG read;
301 GUID *tmp;
302
303 if (!pElts)
304 return E_INVALIDARG;
305 read = 0;
306 for (i = 0; i < cElt && (fCursor < (ULONG)DSA_GetItemCount(fDsa)); i++)
307 {
308 tmp = (GUID*)DSA_GetItemPtr(fDsa, fCursor + i);
309 if (!tmp)
310 break;
311 pElts[i] = *tmp;
312 read++;
313 }
314 fCursor += read;
315 if (pFetched)
316 *pFetched = read;
317 return S_OK;
318}
319
321{
322 fCursor = 0;
323 return S_OK;
324}
325
327{
328 if (fCursor + nbElts >= (ULONG)DSA_GetItemCount(fDsa))
329 return E_INVALIDARG;
330 fCursor += nbElts;
331 return S_OK;
332}
333
334/*************************************************************************
335 * SHEnumClassesOfCategories [BROWSEUI.136]
336 */
337extern "C" HRESULT WINAPI SHEnumClassesOfCategories(ULONG cImplemented, CATID *pImplemented, ULONG cRequired, CATID *pRequired, IEnumGUID **out)
338{
339 HRESULT hr;
340
341 if (!out)
342 return E_INVALIDARG;
343
344 hr = ShellObjectCreatorInit<CSHEnumClassesOfCategories>(
345 cImplemented, pImplemented, cRequired, pRequired, IID_PPV_ARG(IEnumGUID, out));
347 return hr;
348 return S_OK;
349}
#define REGPATH
HRESULT WINAPI SHEnumClassesOfCategories(ULONG cImplemented, CATID *pImplemented, ULONG cRequired, CATID *pRequired, IEnumGUID **out)
struct categoryCacheHeader * PCATCACHEHDR
#define IMPLEMENTING
struct categoryCacheHeader CATCACHEHDR
#define read
Definition: acwin.h:96
#define STDMETHOD(m)
Definition: basetyps.h:62
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define FIXME(fmt,...)
Definition: debug.h:114
HRESULT STDMETHODCALLTYPE Initialize(CATID &catID, BOOL reloadCache)
STDMETHOD() Skip(ULONG nbElts) override
STDMETHOD() Initialize(ULONG cImplemented, CATID *pImplemented, ULONG cRequired, CATID *pRequired)
STDMETHOD() Next(ULONG cElt, CLSID *pElts, ULONG *pFetched) override
STDMETHOD() Clone(IEnumCLSID **ppvOut) override
CComPtr< ICatInformation > fCatInformation
#define IEnumCLSID
Definition: comcat.idl:40
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
VOID WINAPI GetSystemTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:327
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
LPVOID WINAPI DSA_GetItemPtr(HDSA hdsa, INT nIndex)
Definition: dsa.c:162
BOOL WINAPI DSA_Destroy(HDSA hdsa)
Definition: dsa.c:103
INT WINAPI DSA_InsertItem(HDSA hdsa, INT nIndex, LPVOID pSrc)
Definition: dsa.c:251
HDSA WINAPI DSA_Create(INT nSize, INT nGrow)
Definition: dsa.c:71
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
size_t bufferSize
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei dataSize
Definition: glext.h:11123
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
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
#define S_OK
Definition: intsafe.h:52
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define END_COM_MAP()
Definition: atlcom.h:592
static WCHAR guidStr[]
Definition: asn.c:531
unsigned int UINT
Definition: ndis.h:50
#define REG_BINARY
Definition: nt_native.h:1496
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define DSA_APPEND
Definition: commctrl.h:4787
#define DSA_GetItemCount(hdsa)
Definition: commctrl.h:4826
#define DSA_ERR
Definition: commctrl.h:4788
static FILE * out
Definition: regtests2xml.c:44
HRESULT hr
Definition: shlfolder.c:183
#define SHSetValue
Definition: shlwapi.h:92
#define SHGetValue
Definition: shlwapi.h:70
Definition: dsa.c:45
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define wsprintf
Definition: winuser.h:5865
static void Initialize()
Definition: xlate.c:212
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180