[DPLAYX] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / reactos / dll / directx / wine / dxdiagn / provider.c
1 /*
2 * IDxDiagProvider Implementation
3 *
4 * Copyright 2004-2005 Raphael Junqueira
5 * Copyright 2010 Andrew Nguyen
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 St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 */
22
23 #include "dxdiag_private.h"
24
25 #include <winver.h>
26 #include <uuids.h>
27 #include <d3d9.h>
28 #include <fil_data.h>
29 #include <psapi.h>
30 #include <wbemcli.h>
31
32 static const WCHAR szEmpty[] = {0};
33
34 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
35 static void free_information_tree(IDxDiagContainerImpl_Container *node);
36
37 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
38 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
39 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
40 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
41 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
42 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
43 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
44 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
45 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
46 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
47 static const WCHAR szDisplayMemoryLocalized[] = {'s','z','D','i','s','p','l','a','y','M','e','m','o','r','y','L','o','c','a','l','i','z','e','d',0};
48 static const WCHAR szDisplayMemoryEnglish[] = {'s','z','D','i','s','p','l','a','y','M','e','m','o','r','y','E','n','g','l','i','s','h',0};
49 static const WCHAR szDriverName[] = {'s','z','D','r','i','v','e','r','N','a','m','e',0};
50 static const WCHAR szDriverVersion[] = {'s','z','D','r','i','v','e','r','V','e','r','s','i','o','n',0};
51 static const WCHAR szSubSysId[] = {'s','z','S','u','b','S','y','s','I','d',0};
52 static const WCHAR szRevisionId[] = {'s','z','R','e','v','i','s','i','o','n','I','d',0};
53 static const WCHAR dwRefreshRate[] = {'d','w','R','e','f','r','e','s','h','R','a','t','e',0};
54 static const WCHAR szManufacturer[] = {'s','z','M','a','n','u','f','a','c','t','u','r','e','r',0};
55 static const WCHAR szChipType[] = {'s','z','C','h','i','p','T','y','p','e',0};
56 static const WCHAR szDACType[] = {'s','z','D','A','C','T','y','p','e',0};
57 static const WCHAR szRevision[] = {'s','z','R','e','v','i','s','i','o','n',0};
58
59 struct IDxDiagProviderImpl
60 {
61 IDxDiagProvider IDxDiagProvider_iface;
62 LONG ref;
63 BOOL init;
64 DXDIAG_INIT_PARAMS params;
65 IDxDiagContainerImpl_Container *info_root;
66 };
67
68 static inline IDxDiagProviderImpl *impl_from_IDxDiagProvider(IDxDiagProvider *iface)
69 {
70 return CONTAINING_RECORD(iface, IDxDiagProviderImpl, IDxDiagProvider_iface);
71 }
72
73 /* IDxDiagProvider IUnknown parts follow: */
74 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(IDxDiagProvider *iface, REFIID riid,
75 void **ppobj)
76 {
77 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
78
79 if (!ppobj) return E_INVALIDARG;
80
81 if (IsEqualGUID(riid, &IID_IUnknown)
82 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
83 IUnknown_AddRef(iface);
84 *ppobj = This;
85 return S_OK;
86 }
87
88 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
89 *ppobj = NULL;
90 return E_NOINTERFACE;
91 }
92
93 static ULONG WINAPI IDxDiagProviderImpl_AddRef(IDxDiagProvider *iface)
94 {
95 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
96 ULONG refCount = InterlockedIncrement(&This->ref);
97
98 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
99
100 DXDIAGN_LockModule();
101
102 return refCount;
103 }
104
105 static ULONG WINAPI IDxDiagProviderImpl_Release(IDxDiagProvider *iface)
106 {
107 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
108 ULONG refCount = InterlockedDecrement(&This->ref);
109
110 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
111
112 if (!refCount) {
113 free_information_tree(This->info_root);
114 HeapFree(GetProcessHeap(), 0, This);
115 }
116
117 DXDIAGN_UnlockModule();
118
119 return refCount;
120 }
121
122 /* IDxDiagProvider Interface follow: */
123 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(IDxDiagProvider *iface,
124 DXDIAG_INIT_PARAMS *pParams)
125 {
126 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
127 HRESULT hr;
128
129 TRACE("(%p,%p)\n", iface, pParams);
130
131 if (NULL == pParams) {
132 return E_POINTER;
133 }
134 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
135 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
136 return E_INVALIDARG;
137 }
138
139 if (!This->info_root)
140 {
141 hr = build_information_tree(&This->info_root);
142 if (FAILED(hr))
143 return hr;
144 }
145
146 This->init = TRUE;
147 memcpy(&This->params, pParams, pParams->dwSize);
148 return S_OK;
149 }
150
151 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(IDxDiagProvider *iface,
152 IDxDiagContainer **ppInstance)
153 {
154 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
155
156 TRACE("(%p,%p)\n", iface, ppInstance);
157
158 if (FALSE == This->init) {
159 return CO_E_NOTINITIALIZED;
160 }
161
162 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
163 &This->IDxDiagProvider_iface, (void **)ppInstance);
164 }
165
166 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
167 {
168 IDxDiagProviderImpl_QueryInterface,
169 IDxDiagProviderImpl_AddRef,
170 IDxDiagProviderImpl_Release,
171 IDxDiagProviderImpl_Initialize,
172 IDxDiagProviderImpl_GetRootContainer
173 };
174
175 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
176 IDxDiagProviderImpl* provider;
177
178 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
179
180 *ppobj = NULL;
181 if (punkOuter) return CLASS_E_NOAGGREGATION;
182
183 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
184 if (NULL == provider) return E_OUTOFMEMORY;
185 provider->IDxDiagProvider_iface.lpVtbl = &DxDiagProvider_Vtbl;
186 provider->ref = 0; /* will be inited with QueryInterface */
187 return IDxDiagProviderImpl_QueryInterface(&provider->IDxDiagProvider_iface, riid, ppobj);
188 }
189
190 static void free_property_information(IDxDiagContainerImpl_Property *prop)
191 {
192 VariantClear(&prop->vProp);
193 HeapFree(GetProcessHeap(), 0, prop->propName);
194 HeapFree(GetProcessHeap(), 0, prop);
195 }
196
197 static void free_information_tree(IDxDiagContainerImpl_Container *node)
198 {
199 IDxDiagContainerImpl_Container *ptr, *cursor2;
200
201 if (!node)
202 return;
203
204 HeapFree(GetProcessHeap(), 0, node->contName);
205
206 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
207 {
208 IDxDiagContainerImpl_Property *prop, *prop_cursor2;
209
210 LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
211 {
212 list_remove(&prop->entry);
213 free_property_information(prop);
214 }
215
216 list_remove(&ptr->entry);
217 free_information_tree(ptr);
218 }
219
220 HeapFree(GetProcessHeap(), 0, node);
221 }
222
223 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
224 {
225 IDxDiagContainerImpl_Container *ret;
226
227 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
228 if (!ret)
229 return NULL;
230
231 if (name)
232 {
233 ret->contName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
234 if (!ret->contName)
235 {
236 HeapFree(GetProcessHeap(), 0, ret);
237 return NULL;
238 }
239 strcpyW(ret->contName, name);
240 }
241
242 list_init(&ret->subContainers);
243 list_init(&ret->properties);
244
245 return ret;
246 }
247
248 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
249 {
250 IDxDiagContainerImpl_Property *ret;
251
252 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
253 if (!ret)
254 return NULL;
255
256 ret->propName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
257 if (!ret->propName)
258 {
259 HeapFree(GetProcessHeap(), 0, ret);
260 return NULL;
261 }
262 strcpyW(ret->propName, name);
263
264 return ret;
265 }
266
267 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
268 {
269 list_add_tail(&node->subContainers, &subCont->entry);
270 ++node->nSubContainers;
271 }
272
273 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
274 {
275 IDxDiagContainerImpl_Property *prop;
276 BSTR bstr;
277
278 prop = allocate_property_information(propName);
279 if (!prop)
280 return E_OUTOFMEMORY;
281
282 bstr = SysAllocString(str);
283 if (!bstr)
284 {
285 free_property_information(prop);
286 return E_OUTOFMEMORY;
287 }
288
289 V_VT(&prop->vProp) = VT_BSTR;
290 V_BSTR(&prop->vProp) = bstr;
291
292 list_add_tail(&node->properties, &prop->entry);
293 ++node->nProperties;
294
295 return S_OK;
296 }
297
298 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
299 {
300 IDxDiagContainerImpl_Property *prop;
301
302 prop = allocate_property_information(propName);
303 if (!prop)
304 return E_OUTOFMEMORY;
305
306 V_VT(&prop->vProp) = VT_UI4;
307 V_UI4(&prop->vProp) = data;
308
309 list_add_tail(&node->properties, &prop->entry);
310 ++node->nProperties;
311
312 return S_OK;
313 }
314
315 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
316 {
317 IDxDiagContainerImpl_Property *prop;
318
319 prop = allocate_property_information(propName);
320 if (!prop)
321 return E_OUTOFMEMORY;
322
323 V_VT(&prop->vProp) = VT_BOOL;
324 V_BOOL(&prop->vProp) = data;
325
326 list_add_tail(&node->properties, &prop->entry);
327 ++node->nProperties;
328
329 return S_OK;
330 }
331
332 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
333 {
334 IDxDiagContainerImpl_Property *prop;
335
336 prop = allocate_property_information(propName);
337 if (!prop)
338 return E_OUTOFMEMORY;
339
340 V_VT(&prop->vProp) = VT_UI8;
341 V_UI8(&prop->vProp) = data;
342
343 VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
344
345 list_add_tail(&node->properties, &prop->entry);
346 ++node->nProperties;
347
348 return S_OK;
349 }
350
351 /* Copied from programs/taskkill/taskkill.c. */
352 static DWORD *enumerate_processes(DWORD *list_count)
353 {
354 DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
355
356 pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
357 if (!pid_list)
358 return NULL;
359
360 for (;;)
361 {
362 DWORD *realloc_list;
363
364 if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
365 {
366 HeapFree(GetProcessHeap(), 0, pid_list);
367 return NULL;
368 }
369
370 /* EnumProcesses can't signal an insufficient buffer condition, so the
371 * only way to possibly determine whether a larger buffer is required
372 * is to see whether the written number of bytes is the same as the
373 * buffer size. If so, the buffer will be reallocated to twice the
374 * size. */
375 if (alloc_bytes != needed_bytes)
376 break;
377
378 alloc_bytes *= 2;
379 realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
380 if (!realloc_list)
381 {
382 HeapFree(GetProcessHeap(), 0, pid_list);
383 return NULL;
384 }
385 pid_list = realloc_list;
386 }
387
388 *list_count = needed_bytes / sizeof(*pid_list);
389 return pid_list;
390 }
391
392 /* Copied from programs/taskkill/taskkill.c. */
393 static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
394 {
395 HANDLE process;
396 HMODULE module;
397 DWORD required_size;
398
399 process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
400 if (!process)
401 return FALSE;
402
403 if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
404 {
405 CloseHandle(process);
406 return FALSE;
407 }
408
409 if (!GetModuleBaseNameW(process, module, buf, chars))
410 {
411 CloseHandle(process);
412 return FALSE;
413 }
414
415 CloseHandle(process);
416 return TRUE;
417 }
418
419 /* dxdiagn's detection scheme is simply to look for a process called conf.exe. */
420 static BOOL is_netmeeting_running(void)
421 {
422 static const WCHAR conf_exe[] = {'c','o','n','f','.','e','x','e',0};
423
424 DWORD list_count;
425 DWORD *pid_list = enumerate_processes(&list_count);
426
427 if (pid_list)
428 {
429 DWORD i;
430 WCHAR process_name[MAX_PATH];
431
432 for (i = 0; i < list_count; i++)
433 {
434 if (get_process_name_from_pid(pid_list[i], process_name, sizeof(process_name)/sizeof(WCHAR)) &&
435 !lstrcmpW(conf_exe, process_name))
436 {
437 HeapFree(GetProcessHeap(), 0, pid_list);
438 return TRUE;
439 }
440 }
441 HeapFree(GetProcessHeap(), 0, pid_list);
442 }
443
444 return FALSE;
445 }
446
447 static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
448 {
449 static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
450 static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
451 static const WCHAR szLanguagesLocalized[] = {'s','z','L','a','n','g','u','a','g','e','s','L','o','c','a','l','i','z','e','d',0};
452 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
453
454 WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
455 HRESULT hr;
456
457 /* szLanguagesLocalized */
458 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, sizeof(system_lang)/sizeof(WCHAR));
459 LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, sizeof(regional_setting)/sizeof(WCHAR));
460 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, sizeof(user_lang)/sizeof(WCHAR));
461
462 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting, user_lang);
463
464 hr = add_bstr_property(node, szLanguagesLocalized, language_str);
465 if (FAILED(hr))
466 return hr;
467
468 /* szLanguagesEnglish */
469 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, sizeof(system_lang)/sizeof(WCHAR));
470 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, sizeof(user_lang)/sizeof(WCHAR));
471
472 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting_engW, user_lang);
473
474 hr = add_bstr_property(node, szLanguagesEnglish, language_str);
475 if (FAILED(hr))
476 return hr;
477
478 return S_OK;
479 }
480
481 static HRESULT fill_datetime_information(IDxDiagContainerImpl_Container *node)
482 {
483 static const WCHAR date_fmtW[] = {'M','\'','/','\'','d','\'','/','\'','y','y','y','y',0};
484 static const WCHAR time_fmtW[] = {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
485 static const WCHAR datetime_fmtW[] = {'%','s',',',' ','%','s',0};
486 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
487 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
488
489 SYSTEMTIME curtime;
490 WCHAR date_str[80], time_str[80], datetime_str[200];
491 HRESULT hr;
492
493 GetLocalTime(&curtime);
494
495 GetTimeFormatW(LOCALE_NEUTRAL, 0, &curtime, time_fmtW, time_str, sizeof(time_str)/sizeof(WCHAR));
496
497 /* szTimeLocalized */
498 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &curtime, NULL, date_str, sizeof(date_str)/sizeof(WCHAR));
499
500 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
501
502 hr = add_bstr_property(node, szTimeLocalized, datetime_str);
503 if (FAILED(hr))
504 return hr;
505
506 /* szTimeEnglish */
507 GetDateFormatW(LOCALE_NEUTRAL, 0, &curtime, date_fmtW, date_str, sizeof(date_str)/sizeof(WCHAR));
508
509 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
510
511 hr = add_bstr_property(node, szTimeEnglish, datetime_str);
512 if (FAILED(hr))
513 return hr;
514
515 return S_OK;
516 }
517
518 static HRESULT fill_os_string_information(IDxDiagContainerImpl_Container *node, OSVERSIONINFOW *info)
519 {
520 static const WCHAR winxpW[] = {'W','i','n','d','o','w','s',' ','X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
521 static const WCHAR szOSLocalized[] = {'s','z','O','S','L','o','c','a','l','i','z','e','d',0};
522 static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
523 static const WCHAR szOSExLongLocalized[] = {'s','z','O','S','E','x','L','o','n','g','L','o','c','a','l','i','z','e','d',0};
524 static const WCHAR szOSEnglish[] = {'s','z','O','S','E','n','g','l','i','s','h',0};
525 static const WCHAR szOSExEnglish[] = {'s','z','O','S','E','x','E','n','g','l','i','s','h',0};
526 static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
527
528 static const WCHAR *prop_list[] = {szOSLocalized, szOSExLocalized, szOSExLongLocalized,
529 szOSEnglish, szOSExEnglish, szOSExLongEnglish};
530
531 size_t i;
532 HRESULT hr;
533
534 /* FIXME: OS detection should be performed, and localized OS strings
535 * should contain translated versions of the "build" phrase. */
536 for (i = 0; i < sizeof(prop_list)/sizeof(prop_list[0]); i++)
537 {
538 hr = add_bstr_property(node, prop_list[i], winxpW);
539 if (FAILED(hr))
540 return hr;
541 }
542
543 return S_OK;
544 }
545
546 static HRESULT fill_processor_information(IDxDiagContainerImpl_Container *node)
547 {
548 static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
549
550 static const WCHAR cimv2W[] = {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
551 static const WCHAR proc_classW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
552 static const WCHAR nameW[] = {'N','a','m','e',0};
553 static const WCHAR max_clock_speedW[] = {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
554 static const WCHAR cpu_noW[] = {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
555
556 static const WCHAR processor_fmtW[] = {'%','s','(','%','d',' ','C','P','U','s',')',',',' ','~','%','d','M','H','z',0};
557
558 IWbemLocator *wbem_locator;
559 IWbemServices *wbem_service;
560 IWbemClassObject *wbem_class;
561 IEnumWbemClassObject *wbem_enum;
562 VARIANT cpu_name, cpu_no, clock_speed;
563 WCHAR print_buf[200];
564 BSTR bstr;
565 ULONG no;
566 HRESULT hr;
567
568 hr = CoCreateInstance(&CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void**)&wbem_locator);
569 if(FAILED(hr))
570 return hr;
571
572 bstr = SysAllocString(cimv2W);
573 if(!bstr) {
574 IWbemLocator_Release(wbem_locator);
575 return E_OUTOFMEMORY;
576 }
577 hr = IWbemLocator_ConnectServer(wbem_locator, bstr, NULL, NULL, NULL, 0, NULL, NULL, &wbem_service);
578 IWbemLocator_Release(wbem_locator);
579 SysFreeString(bstr);
580 if(FAILED(hr))
581 return hr;
582
583 bstr = SysAllocString(proc_classW);
584 if(!bstr) {
585 IWbemServices_Release(wbem_service);
586 return E_OUTOFMEMORY;
587 }
588 hr = IWbemServices_CreateInstanceEnum(wbem_service, bstr, WBEM_FLAG_SYSTEM_ONLY, NULL, &wbem_enum);
589 IWbemServices_Release(wbem_service);
590 SysFreeString(bstr);
591 if(FAILED(hr))
592 return hr;
593
594 hr = IEnumWbemClassObject_Next(wbem_enum, 1000, 1, &wbem_class, &no);
595 IEnumWbemClassObject_Release(wbem_enum);
596 if(FAILED(hr))
597 return hr;
598
599 hr = IWbemClassObject_Get(wbem_class, cpu_noW, 0, &cpu_no, NULL, NULL);
600 if(FAILED(hr)) {
601 IWbemClassObject_Release(wbem_class);
602 return hr;
603 }
604 hr = IWbemClassObject_Get(wbem_class, max_clock_speedW, 0, &clock_speed, NULL, NULL);
605 if(FAILED(hr)) {
606 IWbemClassObject_Release(wbem_class);
607 return hr;
608 }
609 hr = IWbemClassObject_Get(wbem_class, nameW, 0, &cpu_name, NULL, NULL);
610 IWbemClassObject_Release(wbem_class);
611 if(FAILED(hr))
612 return hr;
613
614 sprintfW(print_buf, processor_fmtW, V_BSTR(&cpu_name), V_I4(&cpu_no), V_I4(&clock_speed));
615 VariantClear(&cpu_name);
616 VariantClear(&cpu_no);
617 VariantClear(&clock_speed);
618
619 return add_bstr_property(node, szProcessorEnglish, print_buf);
620 }
621
622 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
623 {
624 static const WCHAR dwDirectXVersionMajor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','a','j','o','r',0};
625 static const WCHAR dwDirectXVersionMinor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','i','n','o','r',0};
626 static const WCHAR szDirectXVersionLetter[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','e','t','t','e','r',0};
627 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
628 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
629 static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
630 static const WCHAR szDirectXVersionEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','E','n','g','l','i','s','h',0};
631 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
632 static const WCHAR szDirectXVersionLongEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','o','n','g','E','n','g','l','i','s','h',0};
633 static const WCHAR szDirectXVersionLongEnglish_v[] = {'=',' ','"','D','i','r','e','c','t','X',' ','9','.','0','c',' ','(','4','.','0','9','.','0','0','0','0','.','0','9','0','4',')',0};
634 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
635 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
636 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
637 static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
638 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
639 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
640 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
641 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
642 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
643 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
644 static const WCHAR szPhysicalMemoryEnglish[] = {'s','z','P','h','y','s','i','c','a','l','M','e','m','o','r','y','E','n','g','l','i','s','h',0};
645 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
646 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
647 static const WCHAR szMachineNameLocalized[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','L','o','c','a','l','i','z','e','d',0};
648 static const WCHAR szMachineNameEnglish[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','E','n','g','l','i','s','h',0};
649 static const WCHAR szSystemManufacturerEnglish[] = {'s','z','S','y','s','t','e','m','M','a','n','u','f','a','c','t','u','r','e','r','E','n','g','l','i','s','h',0};
650 static const WCHAR szSystemModelEnglish[] = {'s','z','S','y','s','t','e','m','M','o','d','e','l','E','n','g','l','i','s','h',0};
651 static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
652 static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
653 static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
654
655 static const WCHAR notpresentW[] = {'N','o','t',' ','p','r','e','s','e','n','t',0};
656
657 static const WCHAR pagefile_fmtW[] = {'%','u','M','B',' ','u','s','e','d',',',' ','%','u','M','B',' ','a','v','a','i','l','a','b','l','e',0};
658 static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
659
660 HRESULT hr;
661 MEMORYSTATUSEX msex;
662 OSVERSIONINFOW info;
663 DWORD count, usedpage_mb, availpage_mb;
664 WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
665 DWORD_PTR args[2];
666
667 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
668 if (FAILED(hr))
669 return hr;
670
671 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
672 if (FAILED(hr))
673 return hr;
674
675 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
676 if (FAILED(hr))
677 return hr;
678
679 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
680 if (FAILED(hr))
681 return hr;
682
683 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
684 if (FAILED(hr))
685 return hr;
686
687 hr = add_bool_property(node, bDebug, FALSE);
688 if (FAILED(hr))
689 return hr;
690
691 hr = add_bool_property(node, bNECPC98, FALSE);
692 if (FAILED(hr))
693 return hr;
694
695 msex.dwLength = sizeof(msex);
696 GlobalMemoryStatusEx(&msex);
697
698 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
699 if (FAILED(hr))
700 return hr;
701
702 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
703 if (FAILED(hr))
704 return hr;
705
706 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
707 if (FAILED(hr))
708 return hr;
709
710 hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
711 if (FAILED(hr))
712 return hr;
713
714 info.dwOSVersionInfoSize = sizeof(info);
715 GetVersionExW(&info);
716
717 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
718 if (FAILED(hr))
719 return hr;
720
721 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
722 if (FAILED(hr))
723 return hr;
724
725 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
726 if (FAILED(hr))
727 return hr;
728
729 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
730 if (FAILED(hr))
731 return hr;
732
733 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
734 if (FAILED(hr))
735 return hr;
736
737 /* FIXME: Roundoff should not be done with truncated division. */
738 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), physmem_fmtW, (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
739 hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
740 if (FAILED(hr))
741 return hr;
742
743 usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
744 availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
745 LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt, sizeof(localized_pagefile_fmt)/sizeof(WCHAR));
746 args[0] = usedpage_mb;
747 args[1] = availpage_mb;
748 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
749 localized_pagefile_fmt, 0, 0, print_buf,
750 sizeof(print_buf)/sizeof(*print_buf), (__ms_va_list*)args);
751
752 hr = add_bstr_property(node, szPageFileLocalized, print_buf);
753 if (FAILED(hr))
754 return hr;
755
756 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), pagefile_fmtW, usedpage_mb, availpage_mb);
757
758 hr = add_bstr_property(node, szPageFileEnglish, print_buf);
759 if (FAILED(hr))
760 return hr;
761
762 GetWindowsDirectoryW(buffer, MAX_PATH);
763
764 hr = add_bstr_property(node, szWindowsDir, buffer);
765 if (FAILED(hr))
766 return hr;
767
768 count = sizeof(computer_name)/sizeof(WCHAR);
769 if (!GetComputerNameW(computer_name, &count))
770 return E_FAIL;
771
772 hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
773 if (FAILED(hr))
774 return hr;
775
776 hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
777 if (FAILED(hr))
778 return hr;
779
780 hr = add_bstr_property(node, szSystemManufacturerEnglish, szEmpty);
781 if (FAILED(hr))
782 return hr;
783
784 hr = add_bstr_property(node, szSystemModelEnglish, szEmpty);
785 if (FAILED(hr))
786 return hr;
787
788 hr = add_bstr_property(node, szBIOSEnglish, szEmpty);
789 if (FAILED(hr))
790 return hr;
791
792 hr = fill_processor_information(node);
793 if (FAILED(hr))
794 return hr;
795
796 hr = add_bstr_property(node, szSetupParamEnglish, notpresentW);
797 if (FAILED(hr))
798 return hr;
799
800 hr = add_bstr_property(node, szDxDiagVersion, szEmpty);
801 if (FAILED(hr))
802 return hr;
803
804 hr = fill_language_information(node);
805 if (FAILED(hr))
806 return hr;
807
808 hr = fill_datetime_information(node);
809 if (FAILED(hr))
810 return hr;
811
812 hr = fill_os_string_information(node, &info);
813 if (FAILED(hr))
814 return hr;
815
816 return S_OK;
817 }
818
819 /* The logic from pixelformat_for_depth() in dlls/wined3d/utils.c is reversed. */
820 static DWORD depth_for_pixelformat(D3DFORMAT format)
821 {
822 switch (format)
823 {
824 case D3DFMT_P8: return 8;
825 case D3DFMT_X1R5G5B5: return 15;
826 case D3DFMT_R5G6B5: return 16;
827 /* This case will fail to distinguish an original bpp of 24. */
828 case D3DFMT_X8R8G8B8: return 32;
829 default:
830 FIXME("Unknown D3DFORMAT %d, returning 32 bpp\n", format);
831 return 32;
832 }
833 }
834
835 static BOOL get_texture_memory(GUID *adapter, DWORD *available_mem)
836 {
837 IDirectDraw7 *pDirectDraw;
838 HRESULT hr;
839 DDSCAPS2 dd_caps;
840
841 hr = DirectDrawCreateEx(adapter, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
842 if (SUCCEEDED(hr))
843 {
844 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
845 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
846 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, available_mem, NULL);
847 IDirectDraw7_Release(pDirectDraw);
848 if (SUCCEEDED(hr))
849 return TRUE;
850 }
851
852 return FALSE;
853 }
854
855 static const WCHAR *vendor_id_to_manufacturer_string(DWORD vendor_id)
856 {
857 static const WCHAR atiW[] = {'A','T','I',' ','T','e','c','h','n','o','l','o','g','i','e','s',' ','I','n','c','.',0};
858 static const WCHAR nvidiaW[] = {'N','V','I','D','I','A',0};
859 static const WCHAR intelW[] = {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
860 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
861
862 /* Enumeration copied from dlls/wined3d/wined3d_private.h and slightly modified. */
863 enum pci_vendor
864 {
865 HW_VENDOR_AMD = 0x1002,
866 HW_VENDOR_NVIDIA = 0x10de,
867 HW_VENDOR_INTEL = 0x8086,
868 };
869
870 switch (vendor_id)
871 {
872 case HW_VENDOR_AMD:
873 return atiW;
874 case HW_VENDOR_NVIDIA:
875 return nvidiaW;
876 case HW_VENDOR_INTEL:
877 return intelW;
878 default:
879 FIXME("Unknown PCI vendor ID 0x%04x\n", vendor_id);
880 return unknownW;
881 }
882 }
883
884 static HRESULT fill_display_information_d3d(IDxDiagContainerImpl_Container *node)
885 {
886 IDxDiagContainerImpl_Container *display_adapter;
887 HRESULT hr;
888 IDirect3D9 *pDirect3D9;
889 WCHAR buffer[256];
890 UINT index, count;
891
892 pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);
893 if (!pDirect3D9)
894 return E_FAIL;
895
896 count = IDirect3D9_GetAdapterCount(pDirect3D9);
897 for (index = 0; index < count; index++)
898 {
899 static const WCHAR adapterid_fmtW[] = {'%','u',0};
900 static const WCHAR driverversion_fmtW[] = {'%','u','.','%','u','.','%','0','4','u','.','%','0','4','u',0};
901 static const WCHAR id_fmtW[] = {'0','x','%','0','4','x',0};
902 static const WCHAR subsysid_fmtW[] = {'0','x','%','0','8','x',0};
903 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
904 static const WCHAR b3DAccelerationExists[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','x','i','s','t','s',0};
905 static const WCHAR b3DAccelerationEnabled[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
906 static const WCHAR bDDAccelerationEnabled[] = {'b','D','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
907 static const WCHAR bNoHardware[] = {'b','N','o','H','a','r','d','w','a','r','e',0};
908
909 D3DADAPTER_IDENTIFIER9 adapter_info;
910 D3DDISPLAYMODE adapter_mode;
911 D3DCAPS9 device_caps;
912 DWORD available_mem = 0;
913 BOOL hardware_accel;
914
915 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), adapterid_fmtW, index);
916 display_adapter = allocate_information_node(buffer);
917 if (!display_adapter)
918 {
919 hr = E_OUTOFMEMORY;
920 goto cleanup;
921 }
922
923 add_subcontainer(node, display_adapter);
924
925 hr = IDirect3D9_GetAdapterIdentifier(pDirect3D9, index, 0, &adapter_info);
926 if (SUCCEEDED(hr))
927 {
928 WCHAR driverW[sizeof(adapter_info.Driver)];
929 WCHAR descriptionW[sizeof(adapter_info.Description)];
930 WCHAR devicenameW[sizeof(adapter_info.DeviceName)];
931
932 MultiByteToWideChar(CP_ACP, 0, adapter_info.Driver, -1, driverW, sizeof(driverW)/sizeof(WCHAR));
933 MultiByteToWideChar(CP_ACP, 0, adapter_info.Description, -1, descriptionW, sizeof(descriptionW)/sizeof(WCHAR));
934 MultiByteToWideChar(CP_ACP, 0, adapter_info.DeviceName, -1, devicenameW, sizeof(devicenameW)/sizeof(WCHAR));
935
936 hr = add_bstr_property(display_adapter, szDriverName, driverW);
937 if (FAILED(hr))
938 goto cleanup;
939
940 hr = add_bstr_property(display_adapter, szDescription, descriptionW);
941 if (FAILED(hr))
942 goto cleanup;
943
944 hr = add_bstr_property(display_adapter, szDeviceName, devicenameW);
945 if (FAILED(hr))
946 goto cleanup;
947
948 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), driverversion_fmtW,
949 HIWORD(adapter_info.DriverVersion.u.HighPart), LOWORD(adapter_info.DriverVersion.u.HighPart),
950 HIWORD(adapter_info.DriverVersion.u.LowPart), LOWORD(adapter_info.DriverVersion.u.LowPart));
951
952 hr = add_bstr_property(display_adapter, szDriverVersion, buffer);
953 if (FAILED(hr))
954 goto cleanup;
955
956 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.VendorId);
957 hr = add_bstr_property(display_adapter, szVendorId, buffer);
958 if (FAILED(hr))
959 goto cleanup;
960
961 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.DeviceId);
962 hr = add_bstr_property(display_adapter, szDeviceId, buffer);
963 if (FAILED(hr))
964 goto cleanup;
965
966 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), subsysid_fmtW, adapter_info.SubSysId);
967 hr = add_bstr_property(display_adapter, szSubSysId, buffer);
968 if (FAILED(hr))
969 goto cleanup;
970
971 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.Revision);
972 hr = add_bstr_property(display_adapter, szRevisionId, buffer);
973 if (FAILED(hr))
974 goto cleanup;
975
976 StringFromGUID2(&adapter_info.DeviceIdentifier, buffer, 39);
977 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
978 if (FAILED(hr))
979 goto cleanup;
980
981 hr = add_bstr_property(display_adapter, szManufacturer, vendor_id_to_manufacturer_string(adapter_info.VendorId));
982 if (FAILED(hr))
983 goto cleanup;
984 }
985
986 hr = IDirect3D9_GetAdapterDisplayMode(pDirect3D9, index, &adapter_mode);
987 if (SUCCEEDED(hr))
988 {
989 hr = add_ui4_property(display_adapter, dwWidth, adapter_mode.Width);
990 if (FAILED(hr))
991 goto cleanup;
992
993 hr = add_ui4_property(display_adapter, dwHeight, adapter_mode.Height);
994 if (FAILED(hr))
995 goto cleanup;
996
997 hr = add_ui4_property(display_adapter, dwRefreshRate, adapter_mode.RefreshRate);
998 if (FAILED(hr))
999 goto cleanup;
1000
1001 hr = add_ui4_property(display_adapter, dwBpp, depth_for_pixelformat(adapter_mode.Format));
1002 if (FAILED(hr))
1003 goto cleanup;
1004 }
1005
1006 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
1007 if (FAILED(hr))
1008 goto cleanup;
1009
1010 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
1011 if (FAILED(hr))
1012 goto cleanup;
1013
1014 hr = add_bstr_property(display_adapter, szChipType, szEmpty);
1015 if (FAILED(hr))
1016 goto cleanup;
1017
1018 hr = add_bstr_property(display_adapter, szDACType, szEmpty);
1019 if (FAILED(hr))
1020 goto cleanup;
1021
1022 hr = add_bstr_property(display_adapter, szRevision, szEmpty);
1023 if (FAILED(hr))
1024 goto cleanup;
1025
1026 if (!get_texture_memory(&adapter_info.DeviceIdentifier, &available_mem))
1027 WARN("get_texture_memory helper failed\n");
1028
1029 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, available_mem / 1000000.0f);
1030
1031 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1032 if (FAILED(hr))
1033 goto cleanup;
1034
1035 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1036 if (FAILED(hr))
1037 goto cleanup;
1038
1039 hr = IDirect3D9_GetDeviceCaps(pDirect3D9, index, D3DDEVTYPE_HAL, &device_caps);
1040 hardware_accel = SUCCEEDED(hr);
1041
1042 hr = add_bool_property(display_adapter, b3DAccelerationEnabled, hardware_accel);
1043 if (FAILED(hr))
1044 goto cleanup;
1045
1046 hr = add_bool_property(display_adapter, b3DAccelerationExists, hardware_accel);
1047 if (FAILED(hr))
1048 goto cleanup;
1049
1050 hr = add_bool_property(display_adapter, bDDAccelerationEnabled, hardware_accel);
1051 if (FAILED(hr))
1052 goto cleanup;
1053
1054 hr = add_bool_property(display_adapter, bNoHardware, FALSE);
1055 if (FAILED(hr))
1056 goto cleanup;
1057 }
1058
1059 hr = S_OK;
1060 cleanup:
1061 IDirect3D9_Release(pDirect3D9);
1062 return hr;
1063 }
1064
1065 static HRESULT fill_display_information_fallback(IDxDiagContainerImpl_Container *node)
1066 {
1067 static const WCHAR szAdapterID[] = {'0',0};
1068 static const WCHAR *empty_properties[] = {szDeviceIdentifier, szVendorId, szDeviceId,
1069 szKeyDeviceKey, szKeyDeviceID, szDriverName,
1070 szDriverVersion, szSubSysId, szRevisionId,
1071 szManufacturer, szChipType, szDACType, szRevision};
1072
1073 IDxDiagContainerImpl_Container *display_adapter;
1074 HRESULT hr;
1075 IDirectDraw7 *pDirectDraw;
1076 DDSCAPS2 dd_caps;
1077 DISPLAY_DEVICEW disp_dev;
1078 DDSURFACEDESC2 surface_descr;
1079 DWORD tmp;
1080 WCHAR buffer[256];
1081
1082 display_adapter = allocate_information_node(szAdapterID);
1083 if (!display_adapter)
1084 return E_OUTOFMEMORY;
1085
1086 add_subcontainer(node, display_adapter);
1087
1088 disp_dev.cb = sizeof(disp_dev);
1089 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
1090 {
1091 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
1092 if (FAILED(hr))
1093 return hr;
1094
1095 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
1096 if (FAILED(hr))
1097 return hr;
1098 }
1099
1100 /* Silently ignore a failure from DirectDrawCreateEx. */
1101 hr = DirectDrawCreateEx(NULL, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
1102 if (FAILED(hr))
1103 return S_OK;
1104
1105 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
1106 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
1107 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
1108 if (SUCCEEDED(hr))
1109 {
1110 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
1111
1112 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, tmp / 1000000.0f);
1113
1114 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1115 if (FAILED(hr))
1116 goto cleanup;
1117
1118 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1119 if (FAILED(hr))
1120 goto cleanup;
1121 }
1122
1123 surface_descr.dwSize = sizeof(surface_descr);
1124 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
1125 if (SUCCEEDED(hr))
1126 {
1127 if (surface_descr.dwFlags & DDSD_WIDTH)
1128 {
1129 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
1130 if (FAILED(hr))
1131 goto cleanup;
1132 }
1133
1134 if (surface_descr.dwFlags & DDSD_HEIGHT)
1135 {
1136 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
1137 if (FAILED(hr))
1138 goto cleanup;
1139 }
1140
1141 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
1142 {
1143 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
1144 if (FAILED(hr))
1145 goto cleanup;
1146 }
1147 }
1148
1149 hr = add_ui4_property(display_adapter, dwRefreshRate, 60);
1150 if (FAILED(hr))
1151 goto cleanup;
1152
1153 for (tmp = 0; tmp < sizeof(empty_properties)/sizeof(empty_properties[0]); tmp++)
1154 {
1155 hr = add_bstr_property(display_adapter, empty_properties[tmp], szEmpty);
1156 if (FAILED(hr))
1157 goto cleanup;
1158 }
1159
1160 hr = S_OK;
1161 cleanup:
1162 IDirectDraw7_Release(pDirectDraw);
1163 return hr;
1164 }
1165
1166 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
1167 {
1168 HRESULT hr;
1169
1170 /* Try to use Direct3D to obtain the required information first. */
1171 hr = fill_display_information_d3d(node);
1172 if (hr != E_FAIL)
1173 return hr;
1174
1175 return fill_display_information_fallback(node);
1176 }
1177
1178 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
1179 {
1180 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
1181 static const WCHAR DxDiag_SoundCaptureDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','C','a','p','t','u','r','e','D','e','v','i','c','e','s',0};
1182
1183 IDxDiagContainerImpl_Container *cont;
1184
1185 cont = allocate_information_node(DxDiag_SoundDevices);
1186 if (!cont)
1187 return E_OUTOFMEMORY;
1188
1189 add_subcontainer(node, cont);
1190
1191 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
1192 if (!cont)
1193 return E_OUTOFMEMORY;
1194
1195 add_subcontainer(node, cont);
1196
1197 return S_OK;
1198 }
1199
1200 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
1201 {
1202 return S_OK;
1203 }
1204
1205 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
1206 {
1207 return S_OK;
1208 }
1209
1210 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
1211 {
1212 return S_OK;
1213 }
1214
1215 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
1216 {
1217 return S_OK;
1218 }
1219
1220 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
1221 {
1222 static const WCHAR szSlashSep[] = {'\\',0};
1223 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
1224 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1225 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
1226 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
1227 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
1228 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
1229 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
1230 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
1231 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
1232 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
1233
1234 /* Values */
1235 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
1236 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
1237 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
1238
1239 HRESULT hr;
1240 WCHAR *szFile;
1241 WCHAR szVersion_v[1024];
1242 DWORD retval, hdl;
1243 void *pVersionInfo = NULL;
1244 BOOL boolret = FALSE;
1245 UINT uiLength;
1246 VS_FIXEDFILEINFO *pFileInfo;
1247
1248 TRACE("Filling container %p for %s in %s\n", node,
1249 debugstr_w(szFileName), debugstr_w(szFilePath));
1250
1251 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
1252 lstrlenW(szFileName) + 2 /* slash + terminator */));
1253 if (!szFile)
1254 return E_OUTOFMEMORY;
1255
1256 lstrcpyW(szFile, szFilePath);
1257 lstrcatW(szFile, szSlashSep);
1258 lstrcatW(szFile, szFileName);
1259
1260 retval = GetFileVersionInfoSizeW(szFile, &hdl);
1261 if (retval)
1262 {
1263 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
1264 if (!pVersionInfo)
1265 {
1266 hr = E_OUTOFMEMORY;
1267 goto cleanup;
1268 }
1269
1270 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
1271 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
1272 boolret = TRUE;
1273 }
1274
1275 hr = add_bstr_property(node, szPath, szFile);
1276 if (FAILED(hr))
1277 goto cleanup;
1278
1279 hr = add_bstr_property(node, szName, szFileName);
1280 if (FAILED(hr))
1281 goto cleanup;
1282
1283 hr = add_bool_property(node, bExists, boolret);
1284 if (FAILED(hr))
1285 goto cleanup;
1286
1287 if (boolret)
1288 {
1289 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
1290 szVersionFormat,
1291 HIWORD(pFileInfo->dwFileVersionMS),
1292 LOWORD(pFileInfo->dwFileVersionMS),
1293 HIWORD(pFileInfo->dwFileVersionLS),
1294 LOWORD(pFileInfo->dwFileVersionLS));
1295
1296 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
1297
1298 hr = add_bstr_property(node, szVersion, szVersion_v);
1299 if (FAILED(hr))
1300 goto cleanup;
1301
1302 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
1303 if (FAILED(hr))
1304 goto cleanup;
1305
1306 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
1307 if (FAILED(hr))
1308 goto cleanup;
1309
1310 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
1311 if (FAILED(hr))
1312 goto cleanup;
1313
1314 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
1315 if (FAILED(hr))
1316 goto cleanup;
1317
1318 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
1319 if (FAILED(hr))
1320 goto cleanup;
1321
1322 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
1323 if (FAILED(hr))
1324 goto cleanup;
1325 }
1326
1327 hr = S_OK;
1328 cleanup:
1329 HeapFree(GetProcessHeap(), 0, pVersionInfo);
1330 HeapFree(GetProcessHeap(), 0, szFile);
1331
1332 return hr;
1333 }
1334 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
1335 {
1336 static const WCHAR dlls[][15] =
1337 {
1338 {'d','3','d','8','.','d','l','l',0},
1339 {'d','3','d','9','.','d','l','l',0},
1340 {'d','d','r','a','w','.','d','l','l',0},
1341 {'d','e','v','e','n','u','m','.','d','l','l',0},
1342 {'d','i','n','p','u','t','8','.','d','l','l',0},
1343 {'d','i','n','p','u','t','.','d','l','l',0},
1344 {'d','m','b','a','n','d','.','d','l','l',0},
1345 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
1346 {'d','m','i','m','e','.','d','l','l',0},
1347 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
1348 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
1349 {'d','m','s','t','y','l','e','.','d','l','l',0},
1350 {'d','m','s','y','n','t','h','.','d','l','l',0},
1351 {'d','m','u','s','i','c','.','d','l','l',0},
1352 {'d','p','l','a','y','x','.','d','l','l',0},
1353 {'d','p','n','e','t','.','d','l','l',0},
1354 {'d','s','o','u','n','d','.','d','l','l',0},
1355 {'d','s','w','a','v','e','.','d','l','l',0},
1356 {'d','x','d','i','a','g','n','.','d','l','l',0},
1357 {'q','u','a','r','t','z','.','d','l','l',0}
1358 };
1359
1360 HRESULT hr;
1361 WCHAR szFilePath[MAX_PATH];
1362 INT i;
1363
1364 GetSystemDirectoryW(szFilePath, MAX_PATH);
1365
1366 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
1367 {
1368 static const WCHAR szFormat[] = {'%','d',0};
1369
1370 WCHAR szFileID[5];
1371 IDxDiagContainerImpl_Container *file_container;
1372
1373 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
1374
1375 file_container = allocate_information_node(szFileID);
1376 if (!file_container)
1377 return E_OUTOFMEMORY;
1378
1379 hr = fill_file_description(file_container, szFilePath, dlls[i]);
1380 if (FAILED(hr))
1381 {
1382 free_information_tree(file_container);
1383 continue;
1384 }
1385
1386 add_subcontainer(node, file_container);
1387 }
1388
1389 return S_OK;
1390 }
1391
1392 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1393 {
1394 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1395 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1396
1397 HRESULT hr;
1398
1399 VariantInit(friendly_name);
1400 VariantInit(clsid_name);
1401
1402 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1403 if (FAILED(hr))
1404 return hr;
1405
1406 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1407 if (FAILED(hr))
1408 {
1409 VariantClear(friendly_name);
1410 return hr;
1411 }
1412
1413 return S_OK;
1414 }
1415
1416 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1417 {
1418 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1419 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1420 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1421 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1422 static const WCHAR szVersionFormat[] = {'v','%','d',0};
1423
1424 HRESULT hr;
1425 IFilterMapper2 *pFileMapper = NULL;
1426 IAMFilterData *pFilterData = NULL;
1427 BYTE *ppRF = NULL;
1428 REGFILTER2 *pRF = NULL;
1429 WCHAR bufferW[10];
1430 ULONG j;
1431 DWORD dwNOutputs = 0;
1432 DWORD dwNInputs = 0;
1433
1434 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1435 (void **)&pFileMapper);
1436 if (FAILED(hr))
1437 return hr;
1438
1439 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1440 if (FAILED(hr))
1441 goto cleanup;
1442
1443 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&ppRF);
1444 if (FAILED(hr))
1445 goto cleanup;
1446 pRF = ((REGFILTER2**)ppRF)[0];
1447
1448 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
1449 hr = add_bstr_property(subcont, szVersionW, bufferW);
1450 if (FAILED(hr))
1451 goto cleanup;
1452
1453 if (pRF->dwVersion == 1)
1454 {
1455 for (j = 0; j < pRF->u.s1.cPins; j++)
1456 if (pRF->u.s1.rgPins[j].bOutput)
1457 dwNOutputs++;
1458 else
1459 dwNInputs++;
1460 }
1461 else if (pRF->dwVersion == 2)
1462 {
1463 for (j = 0; j < pRF->u.s2.cPins2; j++)
1464 if (pRF->u.s2.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1465 dwNOutputs++;
1466 else
1467 dwNInputs++;
1468 }
1469
1470 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1471 if (FAILED(hr))
1472 goto cleanup;
1473
1474 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1475 if (FAILED(hr))
1476 goto cleanup;
1477
1478 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1479 if (FAILED(hr))
1480 goto cleanup;
1481
1482 hr = S_OK;
1483 cleanup:
1484 CoTaskMemFree(pRF);
1485 if (pFilterData) IAMFilterData_Release(pFilterData);
1486 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1487
1488 return hr;
1489 }
1490
1491 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1492 {
1493 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1494 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1495 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1496
1497 HRESULT hr;
1498 IPropertyBag *pPropFilterBag = NULL;
1499 BYTE *pData;
1500 VARIANT friendly_name;
1501 VARIANT clsid_name;
1502 VARIANT v;
1503
1504 VariantInit(&friendly_name);
1505 VariantInit(&clsid_name);
1506 VariantInit(&v);
1507
1508 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1509 if (FAILED(hr))
1510 return hr;
1511
1512 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1513 if (FAILED(hr))
1514 goto cleanup;
1515
1516 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1517 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1518
1519 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1520 if (FAILED(hr))
1521 goto cleanup;
1522
1523 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1524 if (FAILED(hr))
1525 goto cleanup;
1526
1527 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1528 if (FAILED(hr))
1529 goto cleanup;
1530
1531 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1532 if (FAILED(hr))
1533 goto cleanup;
1534
1535 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1536 SafeArrayUnaccessData(V_ARRAY(&v));
1537 if (FAILED(hr))
1538 goto cleanup;
1539
1540 hr = S_OK;
1541 cleanup:
1542 VariantClear(&v);
1543 VariantClear(&clsid_name);
1544 VariantClear(&friendly_name);
1545 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1546
1547 return hr;
1548 }
1549
1550 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1551 {
1552 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1553 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1554 static const WCHAR szIdFormat[] = {'%','d',0};
1555
1556 HRESULT hr;
1557 int i = 0;
1558 ICreateDevEnum *pCreateDevEnum;
1559 IEnumMoniker *pEmCat = NULL;
1560 IMoniker *pMCat = NULL;
1561 IEnumMoniker *pEnum = NULL;
1562
1563 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1564 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1565 if (FAILED(hr))
1566 return hr;
1567
1568 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1569 if (FAILED(hr))
1570 goto cleanup;
1571
1572 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1573 {
1574 VARIANT vCatName;
1575 VARIANT vCatClsid;
1576 IPropertyBag *pPropBag;
1577 CLSID clsidCat;
1578 IMoniker *pMoniker = NULL;
1579
1580 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1581 if (FAILED(hr))
1582 {
1583 IMoniker_Release(pMCat);
1584 break;
1585 }
1586
1587 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1588 IPropertyBag_Release(pPropBag);
1589 if (FAILED(hr))
1590 {
1591 IMoniker_Release(pMCat);
1592 break;
1593 }
1594
1595 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1596 if (FAILED(hr))
1597 {
1598 IMoniker_Release(pMCat);
1599 VariantClear(&vCatClsid);
1600 VariantClear(&vCatName);
1601 break;
1602 }
1603
1604 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1605 if (hr != S_OK)
1606 {
1607 IMoniker_Release(pMCat);
1608 VariantClear(&vCatClsid);
1609 VariantClear(&vCatName);
1610 continue;
1611 }
1612
1613 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1614
1615 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1616 {
1617 WCHAR bufferW[10];
1618 IDxDiagContainerImpl_Container *subcont;
1619
1620 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1621 subcont = allocate_information_node(bufferW);
1622 if (!subcont)
1623 {
1624 hr = E_OUTOFMEMORY;
1625 IMoniker_Release(pMoniker);
1626 break;
1627 }
1628
1629 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1630 if (FAILED(hr))
1631 {
1632 free_information_tree(subcont);
1633 IMoniker_Release(pMoniker);
1634 break;
1635 }
1636
1637 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1638 if (FAILED(hr))
1639 {
1640 free_information_tree(subcont);
1641 IMoniker_Release(pMoniker);
1642 break;
1643 }
1644
1645 hr = fill_filter_container(subcont, pMoniker);
1646 IMoniker_Release(pMoniker);
1647 if (FAILED(hr))
1648 {
1649 WARN("Skipping invalid filter\n");
1650 free_information_tree(subcont);
1651 hr = S_OK;
1652 continue;
1653 }
1654
1655 add_subcontainer(node, subcont);
1656 i++;
1657 }
1658
1659 IEnumMoniker_Release(pEnum);
1660 IMoniker_Release(pMCat);
1661 VariantClear(&vCatClsid);
1662 VariantClear(&vCatName);
1663
1664 if (FAILED(hr))
1665 break;
1666 }
1667
1668 cleanup:
1669 if (pEmCat) IEnumMoniker_Release(pEmCat);
1670 ICreateDevEnum_Release(pCreateDevEnum);
1671 return hr;
1672 }
1673
1674 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1675 {
1676 return S_OK;
1677 }
1678
1679 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1680 {
1681 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1682 static const WCHAR DxDiag_DisplayDevices[] = {'D','x','D','i','a','g','_','D','i','s','p','l','a','y','D','e','v','i','c','e','s',0};
1683 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1684 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1685 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1686 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1687 static const WCHAR DxDiag_SystemDevices[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','D','e','v','i','c','e','s',0};
1688 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1689 static const WCHAR DxDiag_DirectShowFilters[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','h','o','w','F','i','l','t','e','r','s',0};
1690 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1691
1692 static const struct
1693 {
1694 const WCHAR *name;
1695 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1696 } root_children[] =
1697 {
1698 {DxDiag_SystemInfo, build_systeminfo_tree},
1699 {DxDiag_DisplayDevices, build_displaydevices_tree},
1700 {DxDiag_DirectSound, build_directsound_tree},
1701 {DxDiag_DirectMusic, build_directmusic_tree},
1702 {DxDiag_DirectInput, build_directinput_tree},
1703 {DxDiag_DirectPlay, build_directplay_tree},
1704 {DxDiag_SystemDevices, build_systemdevices_tree},
1705 {DxDiag_DirectXFiles, build_directxfiles_tree},
1706 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1707 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1708 };
1709
1710 IDxDiagContainerImpl_Container *info_root;
1711 size_t index;
1712
1713 info_root = allocate_information_node(NULL);
1714 if (!info_root)
1715 return E_OUTOFMEMORY;
1716
1717 for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1718 {
1719 IDxDiagContainerImpl_Container *node;
1720 HRESULT hr;
1721
1722 node = allocate_information_node(root_children[index].name);
1723 if (!node)
1724 {
1725 free_information_tree(info_root);
1726 return E_OUTOFMEMORY;
1727 }
1728
1729 hr = root_children[index].initfunc(node);
1730 if (FAILED(hr))
1731 {
1732 free_information_tree(node);
1733 free_information_tree(info_root);
1734 return hr;
1735 }
1736
1737 add_subcontainer(info_root, node);
1738 }
1739
1740 *pinfo_root = info_root;
1741 return S_OK;
1742 }