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