dxdiagn: Add language properties to the DxDiag_SystemInfo container.
[wine/multimedia.git] / dlls / dxdiagn / provider.c
blob52819812d9a62530457a0e724178779ef7d44bbc
1 /*
2 * IDxDiagProvider Implementation
3 *
4 * Copyright 2004-2005 Raphael Junqueira
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "dxdiag_private.h"
28 #include "wine/unicode.h"
29 #include "winver.h"
30 #include "objidl.h"
31 #include "dshow.h"
32 #include "vfw.h"
33 #include "mmddk.h"
34 #include "ddraw.h"
35 #include "d3d9.h"
36 #include "strmif.h"
37 #include "initguid.h"
38 #include "fil_data.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
44 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
45 static void free_information_tree(IDxDiagContainerImpl_Container *node);
47 /* IDxDiagProvider IUnknown parts follow: */
48 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
50 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
52 if (!ppobj) return E_INVALIDARG;
54 if (IsEqualGUID(riid, &IID_IUnknown)
55 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
56 IUnknown_AddRef(iface);
57 *ppobj = This;
58 return S_OK;
61 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
62 *ppobj = NULL;
63 return E_NOINTERFACE;
66 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
67 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
68 ULONG refCount = InterlockedIncrement(&This->ref);
70 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
72 DXDIAGN_LockModule();
74 return refCount;
77 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
78 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
79 ULONG refCount = InterlockedDecrement(&This->ref);
81 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
83 if (!refCount) {
84 free_information_tree(This->info_root);
85 HeapFree(GetProcessHeap(), 0, This);
88 DXDIAGN_UnlockModule();
90 return refCount;
93 /* IDxDiagProvider Interface follow: */
94 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
95 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
96 HRESULT hr;
98 TRACE("(%p,%p)\n", iface, pParams);
100 if (NULL == pParams) {
101 return E_POINTER;
103 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
104 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
105 return E_INVALIDARG;
108 if (!This->info_root)
110 hr = build_information_tree(&This->info_root);
111 if (FAILED(hr))
112 return hr;
115 This->init = TRUE;
116 memcpy(&This->params, pParams, pParams->dwSize);
117 return S_OK;
120 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
121 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
123 TRACE("(%p,%p)\n", iface, ppInstance);
125 if (FALSE == This->init) {
126 return CO_E_NOTINITIALIZED;
129 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
130 (IDxDiagProvider *)This, (void **)ppInstance);
133 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
135 IDxDiagProviderImpl_QueryInterface,
136 IDxDiagProviderImpl_AddRef,
137 IDxDiagProviderImpl_Release,
138 IDxDiagProviderImpl_Initialize,
139 IDxDiagProviderImpl_GetRootContainer
142 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
143 IDxDiagProviderImpl* provider;
145 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
147 *ppobj = NULL;
148 if (punkOuter) return CLASS_E_NOAGGREGATION;
150 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
151 if (NULL == provider) return E_OUTOFMEMORY;
152 provider->lpVtbl = &DxDiagProvider_Vtbl;
153 provider->ref = 0; /* will be inited with QueryInterface */
154 return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
157 static void get_display_device_id(WCHAR *szIdentifierBuffer)
159 static const WCHAR szNA[] = {'n','/','a',0};
161 HRESULT hr = E_FAIL;
163 HMODULE d3d9_handle;
164 IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT) = NULL;
165 IDirect3D9 *pD3d = NULL;
166 D3DADAPTER_IDENTIFIER9 adapter_ident;
168 /* Retrieves the display device identifier from the d3d9 implementation. */
169 d3d9_handle = LoadLibraryA("d3d9.dll");
170 if(d3d9_handle)
171 pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
172 if(pDirect3DCreate9)
173 pD3d = pDirect3DCreate9(D3D_SDK_VERSION);
174 if(pD3d)
175 hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident);
176 if(SUCCEEDED(hr)) {
177 StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39);
178 } else {
179 memcpy(szIdentifierBuffer, szNA, sizeof(szNA));
182 if (pD3d)
183 IDirect3D9_Release(pD3d);
184 if (d3d9_handle)
185 FreeLibrary(d3d9_handle);
188 static void free_property_information(IDxDiagContainerImpl_Property *prop)
190 VariantClear(&prop->vProp);
191 HeapFree(GetProcessHeap(), 0, prop->propName);
192 HeapFree(GetProcessHeap(), 0, prop);
195 static void free_information_tree(IDxDiagContainerImpl_Container *node)
197 IDxDiagContainerImpl_Container *ptr, *cursor2;
199 if (!node)
200 return;
202 HeapFree(GetProcessHeap(), 0, node->contName);
204 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
206 IDxDiagContainerImpl_Property *prop, *prop_cursor2;
208 LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
210 list_remove(&prop->entry);
211 free_property_information(prop);
214 list_remove(&ptr->entry);
215 free_information_tree(ptr);
218 HeapFree(GetProcessHeap(), 0, node);
221 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
223 IDxDiagContainerImpl_Container *ret;
225 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
226 if (!ret)
227 return NULL;
229 if (name)
231 ret->contName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
232 if (!ret->contName)
234 HeapFree(GetProcessHeap(), 0, ret);
235 return NULL;
237 strcpyW(ret->contName, name);
240 list_init(&ret->subContainers);
241 list_init(&ret->properties);
243 return ret;
246 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
248 IDxDiagContainerImpl_Property *ret;
250 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
251 if (!ret)
252 return NULL;
254 ret->propName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
255 if (!ret->propName)
257 HeapFree(GetProcessHeap(), 0, ret);
258 return NULL;
260 strcpyW(ret->propName, name);
262 return ret;
265 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
267 list_add_tail(&node->subContainers, &subCont->entry);
268 ++node->nSubContainers;
271 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
273 IDxDiagContainerImpl_Property *prop;
274 BSTR bstr;
276 prop = allocate_property_information(propName);
277 if (!prop)
278 return E_OUTOFMEMORY;
280 bstr = SysAllocString(str);
281 if (!bstr)
283 free_property_information(prop);
284 return E_OUTOFMEMORY;
287 V_VT(&prop->vProp) = VT_BSTR;
288 V_BSTR(&prop->vProp) = bstr;
290 list_add_tail(&node->properties, &prop->entry);
291 ++node->nProperties;
293 return S_OK;
296 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
298 IDxDiagContainerImpl_Property *prop;
300 prop = allocate_property_information(propName);
301 if (!prop)
302 return E_OUTOFMEMORY;
304 V_VT(&prop->vProp) = VT_UI4;
305 V_UI4(&prop->vProp) = data;
307 list_add_tail(&node->properties, &prop->entry);
308 ++node->nProperties;
310 return S_OK;
313 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
315 IDxDiagContainerImpl_Property *prop;
317 prop = allocate_property_information(propName);
318 if (!prop)
319 return E_OUTOFMEMORY;
321 V_VT(&prop->vProp) = VT_BOOL;
322 V_BOOL(&prop->vProp) = data;
324 list_add_tail(&node->properties, &prop->entry);
325 ++node->nProperties;
327 return S_OK;
330 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
332 IDxDiagContainerImpl_Property *prop;
334 prop = allocate_property_information(propName);
335 if (!prop)
336 return E_OUTOFMEMORY;
338 V_VT(&prop->vProp) = VT_UI8;
339 V_UI8(&prop->vProp) = data;
341 VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
343 list_add_tail(&node->properties, &prop->entry);
344 ++node->nProperties;
346 return S_OK;
349 static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
351 static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
352 static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
353 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};
354 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
356 WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
357 HRESULT hr;
359 /* szLanguagesLocalized */
360 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, sizeof(system_lang)/sizeof(WCHAR));
361 LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, sizeof(regional_setting)/sizeof(WCHAR));
362 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, sizeof(user_lang)/sizeof(WCHAR));
364 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting, user_lang);
366 hr = add_bstr_property(node, szLanguagesLocalized, language_str);
367 if (FAILED(hr))
368 return hr;
370 /* szLanguagesEnglish */
371 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, sizeof(system_lang)/sizeof(WCHAR));
372 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, sizeof(user_lang)/sizeof(WCHAR));
374 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting_engW, user_lang);
376 hr = add_bstr_property(node, szLanguagesEnglish, language_str);
377 if (FAILED(hr))
378 return hr;
380 return S_OK;
383 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
385 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};
386 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};
387 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};
388 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
389 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
390 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};
391 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
392 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};
393 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};
394 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
395 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
396 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
397 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
398 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
399 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
400 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
401 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
402 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
403 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};
404 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};
406 HRESULT hr;
407 MEMORYSTATUSEX msex;
408 OSVERSIONINFOW info;
409 DWORD count;
410 WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1];
412 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
413 if (FAILED(hr))
414 return hr;
416 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
417 if (FAILED(hr))
418 return hr;
420 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
421 if (FAILED(hr))
422 return hr;
424 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
425 if (FAILED(hr))
426 return hr;
428 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
429 if (FAILED(hr))
430 return hr;
432 hr = add_bool_property(node, bDebug, FALSE);
433 if (FAILED(hr))
434 return hr;
436 msex.dwLength = sizeof(msex);
437 GlobalMemoryStatusEx(&msex);
439 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
440 if (FAILED(hr))
441 return hr;
443 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
444 if (FAILED(hr))
445 return hr;
447 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
448 if (FAILED(hr))
449 return hr;
451 info.dwOSVersionInfoSize = sizeof(info);
452 GetVersionExW(&info);
454 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
455 if (FAILED(hr))
456 return hr;
458 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
459 if (FAILED(hr))
460 return hr;
462 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
463 if (FAILED(hr))
464 return hr;
466 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
467 if (FAILED(hr))
468 return hr;
470 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
471 if (FAILED(hr))
472 return hr;
474 GetWindowsDirectoryW(buffer, MAX_PATH);
476 hr = add_bstr_property(node, szWindowsDir, buffer);
477 if (FAILED(hr))
478 return hr;
480 count = sizeof(computer_name)/sizeof(WCHAR);
481 if (!GetComputerNameW(computer_name, &count))
482 return E_FAIL;
484 hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
485 if (FAILED(hr))
486 return hr;
488 hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
489 if (FAILED(hr))
490 return hr;
492 hr = fill_language_information(node);
493 if (FAILED(hr))
494 return hr;
496 return S_OK;
499 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
501 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
502 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
503 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
504 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
505 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
506 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
507 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
508 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
509 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
510 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
511 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};
512 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};
514 static const WCHAR szAdapterID[] = {'0',0};
515 static const WCHAR szEmpty[] = {0};
517 IDxDiagContainerImpl_Container *display_adapter;
518 HRESULT hr;
519 IDirectDraw7 *pDirectDraw;
520 DDSCAPS2 dd_caps;
521 DISPLAY_DEVICEW disp_dev;
522 DDSURFACEDESC2 surface_descr;
523 DWORD tmp;
524 WCHAR buffer[256];
526 display_adapter = allocate_information_node(szAdapterID);
527 if (!display_adapter)
528 return E_OUTOFMEMORY;
530 add_subcontainer(node, display_adapter);
532 disp_dev.cb = sizeof(disp_dev);
533 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
535 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
536 if (FAILED(hr))
537 return hr;
539 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
540 if (FAILED(hr))
541 return hr;
544 /* For now, silently ignore a failure from DirectDrawCreateEx. */
545 hr = DirectDrawCreateEx(NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
546 if (FAILED(hr))
547 return S_OK;
549 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
550 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
551 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
552 if (SUCCEEDED(hr))
554 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
556 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0);
558 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
559 if (FAILED(hr))
560 goto cleanup;
562 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
563 if (FAILED(hr))
564 goto cleanup;
567 surface_descr.dwSize = sizeof(surface_descr);
568 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
569 if (SUCCEEDED(hr))
571 if (surface_descr.dwFlags & DDSD_WIDTH)
573 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
574 if (FAILED(hr))
575 goto cleanup;
578 if (surface_descr.dwFlags & DDSD_HEIGHT)
580 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
581 if (FAILED(hr))
582 goto cleanup;
585 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
587 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
588 if (FAILED(hr))
589 goto cleanup;
593 get_display_device_id(buffer);
595 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
596 if (FAILED(hr))
597 goto cleanup;
599 hr = add_bstr_property(display_adapter, szVendorId, szEmpty);
600 if (FAILED(hr))
601 goto cleanup;
603 hr = add_bstr_property(display_adapter, szDeviceId, szEmpty);
604 if (FAILED(hr))
605 goto cleanup;
607 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
608 if (FAILED(hr))
609 goto cleanup;
611 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
612 if (FAILED(hr))
613 goto cleanup;
615 hr = S_OK;
616 cleanup:
617 IDirectDraw7_Release(pDirectDraw);
618 return hr;
621 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
623 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
624 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};
626 IDxDiagContainerImpl_Container *cont;
628 cont = allocate_information_node(DxDiag_SoundDevices);
629 if (!cont)
630 return E_OUTOFMEMORY;
632 add_subcontainer(node, cont);
634 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
635 if (!cont)
636 return E_OUTOFMEMORY;
638 add_subcontainer(node, cont);
640 return S_OK;
643 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
645 return S_OK;
648 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
650 return S_OK;
653 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
655 return S_OK;
658 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
660 return S_OK;
663 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
665 static const WCHAR szSlashSep[] = {'\\',0};
666 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
667 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
668 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
669 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
670 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
671 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
672 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
673 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
674 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
675 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
677 /* Values */
678 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
679 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
680 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
682 HRESULT hr;
683 WCHAR *szFile;
684 WCHAR szVersion_v[1024];
685 DWORD retval, hdl;
686 void *pVersionInfo = NULL;
687 BOOL boolret = FALSE;
688 UINT uiLength;
689 VS_FIXEDFILEINFO *pFileInfo;
691 TRACE("Filling container %p for %s in %s\n", node,
692 debugstr_w(szFileName), debugstr_w(szFilePath));
694 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
695 lstrlenW(szFileName) + 2 /* slash + terminator */));
696 if (!szFile)
697 return E_OUTOFMEMORY;
699 lstrcpyW(szFile, szFilePath);
700 lstrcatW(szFile, szSlashSep);
701 lstrcatW(szFile, szFileName);
703 retval = GetFileVersionInfoSizeW(szFile, &hdl);
704 if (retval)
706 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
707 if (!pVersionInfo)
709 hr = E_OUTOFMEMORY;
710 goto cleanup;
713 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
714 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
715 boolret = TRUE;
718 hr = add_bstr_property(node, szPath, szFile);
719 if (FAILED(hr))
720 goto cleanup;
722 hr = add_bstr_property(node, szName, szFileName);
723 if (FAILED(hr))
724 goto cleanup;
726 hr = add_bool_property(node, bExists, boolret);
727 if (FAILED(hr))
728 goto cleanup;
730 if (boolret)
732 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
733 szVersionFormat,
734 HIWORD(pFileInfo->dwFileVersionMS),
735 LOWORD(pFileInfo->dwFileVersionMS),
736 HIWORD(pFileInfo->dwFileVersionLS),
737 LOWORD(pFileInfo->dwFileVersionLS));
739 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
741 hr = add_bstr_property(node, szVersion, szVersion_v);
742 if (FAILED(hr))
743 goto cleanup;
745 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
746 if (FAILED(hr))
747 goto cleanup;
749 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
750 if (FAILED(hr))
751 goto cleanup;
753 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
754 if (FAILED(hr))
755 goto cleanup;
757 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
758 if (FAILED(hr))
759 goto cleanup;
761 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
762 if (FAILED(hr))
763 goto cleanup;
765 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
766 if (FAILED(hr))
767 goto cleanup;
770 hr = S_OK;
771 cleanup:
772 HeapFree(GetProcessHeap(), 0, pVersionInfo);
773 HeapFree(GetProcessHeap(), 0, szFile);
775 return hr;
777 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
779 static const WCHAR dlls[][15] =
781 {'d','3','d','8','.','d','l','l',0},
782 {'d','3','d','9','.','d','l','l',0},
783 {'d','d','r','a','w','.','d','l','l',0},
784 {'d','e','v','e','n','u','m','.','d','l','l',0},
785 {'d','i','n','p','u','t','8','.','d','l','l',0},
786 {'d','i','n','p','u','t','.','d','l','l',0},
787 {'d','m','b','a','n','d','.','d','l','l',0},
788 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
789 {'d','m','i','m','e','.','d','l','l',0},
790 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
791 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
792 {'d','m','s','t','y','l','e','.','d','l','l',0},
793 {'d','m','s','y','n','t','h','.','d','l','l',0},
794 {'d','m','u','s','i','c','.','d','l','l',0},
795 {'d','p','l','a','y','x','.','d','l','l',0},
796 {'d','p','n','e','t','.','d','l','l',0},
797 {'d','s','o','u','n','d','.','d','l','l',0},
798 {'d','s','w','a','v','e','.','d','l','l',0},
799 {'d','x','d','i','a','g','n','.','d','l','l',0},
800 {'q','u','a','r','t','z','.','d','l','l',0}
803 HRESULT hr;
804 WCHAR szFilePath[MAX_PATH];
805 INT i;
807 GetSystemDirectoryW(szFilePath, MAX_PATH);
809 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
811 static const WCHAR szFormat[] = {'%','d',0};
813 WCHAR szFileID[5];
814 IDxDiagContainerImpl_Container *file_container;
816 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
818 file_container = allocate_information_node(szFileID);
819 if (!file_container)
820 return E_OUTOFMEMORY;
822 hr = fill_file_description(file_container, szFilePath, dlls[i]);
823 if (FAILED(hr))
825 free_information_tree(file_container);
826 continue;
829 add_subcontainer(node, file_container);
832 return S_OK;
835 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
837 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
838 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
840 HRESULT hr;
842 VariantInit(friendly_name);
843 VariantInit(clsid_name);
845 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
846 if (FAILED(hr))
847 return hr;
849 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
850 if (FAILED(hr))
852 VariantClear(friendly_name);
853 return hr;
856 return S_OK;
859 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
861 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
862 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
863 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
864 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
865 static const WCHAR szVersionFormat[] = {'v','%','d',0};
867 HRESULT hr;
868 IFilterMapper2 *pFileMapper = NULL;
869 IAMFilterData *pFilterData = NULL;
870 REGFILTER2 *pRF = NULL;
871 WCHAR bufferW[10];
872 ULONG j;
873 DWORD dwNOutputs = 0;
874 DWORD dwNInputs = 0;
876 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
877 (void **)&pFileMapper);
878 if (FAILED(hr))
879 return hr;
881 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
882 if (FAILED(hr))
883 goto cleanup;
885 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&pRF);
886 if (FAILED(hr))
887 goto cleanup;
889 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
890 hr = add_bstr_property(subcont, szVersionW, bufferW);
891 if (FAILED(hr))
892 goto cleanup;
894 if (pRF->dwVersion == 1)
896 for (j = 0; j < pRF->u.s.cPins; j++)
897 if (pRF->u.s.rgPins[j].bOutput)
898 dwNOutputs++;
899 else
900 dwNInputs++;
902 else if (pRF->dwVersion == 2)
904 for (j = 0; j < pRF->u.s1.cPins2; j++)
905 if (pRF->u.s1.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
906 dwNOutputs++;
907 else
908 dwNInputs++;
911 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
912 if (FAILED(hr))
913 goto cleanup;
915 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
916 if (FAILED(hr))
917 goto cleanup;
919 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
920 if (FAILED(hr))
921 goto cleanup;
923 hr = S_OK;
924 cleanup:
925 CoTaskMemFree(pRF);
926 if (pFilterData) IAMFilterData_Release(pFilterData);
927 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
929 return hr;
932 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
934 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
935 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
936 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
938 HRESULT hr;
939 IPropertyBag *pPropFilterBag = NULL;
940 BYTE *pData;
941 VARIANT friendly_name;
942 VARIANT clsid_name;
943 VARIANT v;
945 VariantInit(&friendly_name);
946 VariantInit(&clsid_name);
947 VariantInit(&v);
949 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
950 if (FAILED(hr))
951 return hr;
953 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
954 if (FAILED(hr))
955 goto cleanup;
957 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
958 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
960 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
961 if (FAILED(hr))
962 goto cleanup;
964 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
965 if (FAILED(hr))
966 goto cleanup;
968 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
969 if (FAILED(hr))
970 goto cleanup;
972 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
973 if (FAILED(hr))
974 goto cleanup;
976 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
977 SafeArrayUnaccessData(V_ARRAY(&v));
978 if (FAILED(hr))
979 goto cleanup;
981 hr = S_OK;
982 cleanup:
983 VariantClear(&v);
984 VariantClear(&clsid_name);
985 VariantClear(&friendly_name);
986 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
988 return hr;
991 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
993 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
994 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
995 static const WCHAR szIdFormat[] = {'%','d',0};
997 HRESULT hr;
998 int i = 0;
999 ICreateDevEnum *pCreateDevEnum;
1000 IEnumMoniker *pEmCat = NULL;
1001 IMoniker *pMCat = NULL;
1002 IEnumMoniker *pEnum = NULL;
1004 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1005 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1006 if (FAILED(hr))
1007 return hr;
1009 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1010 if (FAILED(hr))
1011 goto cleanup;
1013 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1015 VARIANT vCatName;
1016 VARIANT vCatClsid;
1017 IPropertyBag *pPropBag;
1018 CLSID clsidCat;
1019 IMoniker *pMoniker = NULL;
1021 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1022 if (FAILED(hr))
1024 IMoniker_Release(pMCat);
1025 break;
1028 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1029 IPropertyBag_Release(pPropBag);
1030 if (FAILED(hr))
1032 IMoniker_Release(pMCat);
1033 break;
1036 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1037 if (FAILED(hr))
1039 IMoniker_Release(pMCat);
1040 VariantClear(&vCatClsid);
1041 VariantClear(&vCatName);
1042 break;
1045 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1046 if (hr != S_OK)
1048 IMoniker_Release(pMCat);
1049 VariantClear(&vCatClsid);
1050 VariantClear(&vCatName);
1051 continue;
1054 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1056 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1058 WCHAR bufferW[10];
1059 IDxDiagContainerImpl_Container *subcont;
1061 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1062 subcont = allocate_information_node(bufferW);
1063 if (!subcont)
1065 hr = E_OUTOFMEMORY;
1066 IMoniker_Release(pMoniker);
1067 break;
1070 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1071 if (FAILED(hr))
1073 free_information_tree(subcont);
1074 IMoniker_Release(pMoniker);
1075 break;
1078 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1079 if (FAILED(hr))
1081 free_information_tree(subcont);
1082 IMoniker_Release(pMoniker);
1083 break;
1086 hr = fill_filter_container(subcont, pMoniker);
1087 if (FAILED(hr))
1089 free_information_tree(subcont);
1090 IMoniker_Release(pMoniker);
1091 break;
1094 add_subcontainer(node, subcont);
1095 i++;
1096 IMoniker_Release(pMoniker);
1099 IEnumMoniker_Release(pEnum);
1100 IMoniker_Release(pMCat);
1101 VariantClear(&vCatClsid);
1102 VariantClear(&vCatName);
1104 if (FAILED(hr))
1105 break;
1108 cleanup:
1109 if (pEmCat) IEnumMoniker_Release(pEmCat);
1110 ICreateDevEnum_Release(pCreateDevEnum);
1111 return hr;
1114 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1116 return S_OK;
1119 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1121 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1122 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};
1123 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1124 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1125 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1126 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1127 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};
1128 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1129 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};
1130 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1132 static const struct
1134 const WCHAR *name;
1135 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1136 } root_children[] =
1138 {DxDiag_SystemInfo, build_systeminfo_tree},
1139 {DxDiag_DisplayDevices, build_displaydevices_tree},
1140 {DxDiag_DirectSound, build_directsound_tree},
1141 {DxDiag_DirectMusic, build_directmusic_tree},
1142 {DxDiag_DirectInput, build_directinput_tree},
1143 {DxDiag_DirectPlay, build_directplay_tree},
1144 {DxDiag_SystemDevices, build_systemdevices_tree},
1145 {DxDiag_DirectXFiles, build_directxfiles_tree},
1146 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1147 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1150 IDxDiagContainerImpl_Container *info_root;
1151 size_t index;
1153 info_root = allocate_information_node(NULL);
1154 if (!info_root)
1155 return E_OUTOFMEMORY;
1157 for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1159 IDxDiagContainerImpl_Container *node;
1160 HRESULT hr;
1162 node = allocate_information_node(root_children[index].name);
1163 if (!node)
1165 free_information_tree(info_root);
1166 return E_OUTOFMEMORY;
1169 hr = root_children[index].initfunc(node);
1170 if (FAILED(hr))
1172 free_information_tree(node);
1173 free_information_tree(info_root);
1174 return hr;
1177 add_subcontainer(info_root, node);
1180 *pinfo_root = info_root;
1181 return S_OK;