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