Revert "gdi32: Make AddFontToList skip adding a face into global lists if the font...
[wine] / dlls / dxdiagn / provider.c
1 /* 
2  * IDxDiagProvider Implementation
3  * 
4  * Copyright 2004-2005 Raphael Junqueira
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21
22 #include "config.h"
23
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"
39
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
43
44 static HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont);
45
46 /* IDxDiagProvider IUnknown parts follow: */
47 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
48 {
49     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
50
51     if (!ppobj) return E_INVALIDARG;
52
53     if (IsEqualGUID(riid, &IID_IUnknown)
54         || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
55         IUnknown_AddRef(iface);
56         *ppobj = This;
57         return S_OK;
58     }
59
60     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
61     *ppobj = NULL;
62     return E_NOINTERFACE;
63 }
64
65 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
66     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
67     ULONG refCount = InterlockedIncrement(&This->ref);
68
69     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
70
71     DXDIAGN_LockModule();
72
73     return refCount;
74 }
75
76 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
77     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
78     ULONG refCount = InterlockedDecrement(&This->ref);
79
80     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
81
82     if (!refCount) {
83         HeapFree(GetProcessHeap(), 0, This);
84     }
85
86     DXDIAGN_UnlockModule();
87     
88     return refCount;
89 }
90
91 /* IDxDiagProvider Interface follow: */
92 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
93     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
94     TRACE("(%p,%p)\n", iface, pParams);
95
96     if (NULL == pParams) {
97       return E_POINTER;
98     }
99     if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
100         pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
101       return E_INVALIDARG;
102     }
103
104     This->init = TRUE;
105     memcpy(&This->params, pParams, pParams->dwSize);
106     return S_OK;
107 }
108
109 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
110   HRESULT hr = S_OK;
111   IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
112   TRACE("(%p,%p)\n", iface, ppInstance);
113
114   if (FALSE == This->init) {
115     return CO_E_NOTINITIALIZED;
116   }
117   if (NULL == This->pRootContainer) {
118     hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &This->pRootContainer);
119     if (FAILED(hr)) {
120       return hr;
121     }
122     hr = DXDiag_InitRootDXDiagContainer(This->pRootContainer);
123   }
124   return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)This->pRootContainer, &IID_IDxDiagContainer, (void**) ppInstance);
125 }
126
127 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
128 {
129     IDxDiagProviderImpl_QueryInterface,
130     IDxDiagProviderImpl_AddRef,
131     IDxDiagProviderImpl_Release,
132     IDxDiagProviderImpl_Initialize,
133     IDxDiagProviderImpl_GetRootContainer
134 };
135
136 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
137   IDxDiagProviderImpl* provider;
138
139   TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
140
141   *ppobj = NULL;
142   if (punkOuter) return CLASS_E_NOAGGREGATION;
143
144   provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
145   if (NULL == provider) return E_OUTOFMEMORY;
146   provider->lpVtbl = &DxDiagProvider_Vtbl;
147   provider->ref = 0; /* will be inited with QueryInterface */
148   return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
149
150
151 static inline HRESULT add_prop_str( IDxDiagContainer* cont, LPCWSTR prop, LPCWSTR str )
152 {
153     HRESULT hr;
154     VARIANT var;
155
156     V_VT( &var ) = VT_BSTR;
157     V_BSTR( &var ) = SysAllocString( str );
158     hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
159     VariantClear( &var );
160
161     return hr;
162 }
163
164 static inline HRESULT add_prop_ui4( IDxDiagContainer* cont, LPCWSTR prop, DWORD data )
165 {
166     VARIANT var;
167
168     V_VT( &var ) = VT_UI4;
169     V_UI4( &var ) = data;
170     return IDxDiagContainerImpl_AddProp( cont, prop, &var );
171 }
172
173 static inline HRESULT add_prop_bool( IDxDiagContainer* cont, LPCWSTR prop, BOOL data )
174 {
175     VARIANT var;
176
177     V_VT( &var ) = VT_BOOL;
178     V_BOOL( &var ) = data;
179     return IDxDiagContainerImpl_AddProp( cont, prop, &var );
180 }
181
182 static inline HRESULT add_prop_ull_as_str( IDxDiagContainer* cont, LPCWSTR prop, ULONGLONG data )
183 {
184     HRESULT hr;
185     VARIANT var;
186
187     V_VT( &var ) = VT_UI8;
188     V_UI8( &var ) = data;
189     VariantChangeType( &var, &var, 0, VT_BSTR );
190     hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
191     VariantClear( &var );
192
193     return hr;
194 }
195
196 static void get_display_device_id(WCHAR *szIdentifierBuffer)
197 {
198     static const WCHAR szNA[] = {'n','/','a',0};
199
200     HRESULT hr = E_FAIL;
201
202     HMODULE                 d3d9_handle;
203     IDirect3D9             *(WINAPI *pDirect3DCreate9)(UINT) = NULL;
204     IDirect3D9             *pD3d = NULL;
205     D3DADAPTER_IDENTIFIER9  adapter_ident;
206
207     /* Retrieves the display device identifier from the d3d9 implementation. */
208     d3d9_handle = LoadLibraryA("d3d9.dll");
209     if(d3d9_handle)
210         pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
211     if(pDirect3DCreate9)
212         pD3d = pDirect3DCreate9(D3D_SDK_VERSION);
213     if(pD3d)
214         hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident);
215     if(SUCCEEDED(hr)) {
216         StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39);
217     } else {
218         memcpy(szIdentifierBuffer, szNA, sizeof(szNA));
219     }
220
221     if (pD3d)
222         IDirect3D9_Release(pD3d);
223     if (d3d9_handle)
224         FreeLibrary(d3d9_handle);
225 }
226
227 /**
228  * @param szFilePath: usually GetSystemDirectoryW
229  * @param szFileName: name of the dll without path
230  */
231 static HRESULT DXDiag_AddFileDescContainer(IDxDiagContainer* pSubCont, const WCHAR* szFilePath, const WCHAR* szFileName) {
232   HRESULT hr = S_OK;
233   /**/
234   static const WCHAR szSlashSep[] = {'\\',0};
235   static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
236   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
237   static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
238   static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
239   static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
240   static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
241   static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
242   static const WCHAR bBeta[] = {'b','B','e','t','a',0};
243   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
244   static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
245   /** values */
246   static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
247   static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
248   static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
249
250   WCHAR szFile[512];
251   WCHAR szVersion_v[1024];
252   DWORD retval, hdl;
253   LPVOID pVersionInfo;
254   BOOL boolret;
255   UINT uiLength;
256   VS_FIXEDFILEINFO* pFileInfo;
257
258   TRACE("(%p,%s)\n", pSubCont, debugstr_w(szFileName));
259
260   lstrcpyW(szFile, szFilePath);
261   lstrcatW(szFile, szSlashSep);
262   lstrcatW(szFile, szFileName);
263
264   retval = GetFileVersionInfoSizeW(szFile, &hdl);
265   pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
266   boolret = GetFileVersionInfoW(szFile, 0, retval, pVersionInfo);
267   boolret = VerQueryValueW(pVersionInfo, szSlashSep, (LPVOID) &pFileInfo, &uiLength);
268
269   add_prop_str(pSubCont, szPath, szFile);
270   add_prop_str(pSubCont, szName, szFileName);
271   add_prop_bool(pSubCont, bExists, boolret);
272
273   if (boolret) {
274     snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
275               szVersionFormat,
276               HIWORD(pFileInfo->dwFileVersionMS), 
277               LOWORD(pFileInfo->dwFileVersionMS),
278               HIWORD(pFileInfo->dwFileVersionLS),
279               LOWORD(pFileInfo->dwFileVersionLS));
280
281     TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
282
283     add_prop_str(pSubCont, szVersion,         szVersion_v);
284     add_prop_str(pSubCont, szAttributes,      szFinal_Retail_v);
285     add_prop_str(pSubCont, szLanguageEnglish, szEnglish_v);
286     add_prop_ui4(pSubCont, dwFileTimeHigh,    pFileInfo->dwFileDateMS);
287     add_prop_ui4(pSubCont, dwFileTimeLow,     pFileInfo->dwFileDateLS);
288     add_prop_bool(pSubCont, bBeta,  0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE));
289     add_prop_bool(pSubCont, bDebug, 0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG));
290   }
291
292   HeapFree(GetProcessHeap(), 0, pVersionInfo);
293
294   return hr;
295 }
296
297 static HRESULT DXDiag_InitDXDiagSystemInfoContainer(IDxDiagContainer* pSubCont) {
298   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};
299   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};
300   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};
301   static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
302   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
303   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};
304   static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
305   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};
306   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};
307   static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
308   static const WCHAR ullUsedPageFile[]   = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
309   static const WCHAR ullAvailPageFile[]  = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
310   /*static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};*/
311   static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
312   static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
313   static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
314   static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
315   static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
316   static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
317   MEMORYSTATUSEX msex;
318   OSVERSIONINFOW info;
319   WCHAR buffer[MAX_PATH];
320
321   add_prop_ui4(pSubCont, dwDirectXVersionMajor, 9);
322   add_prop_ui4(pSubCont, dwDirectXVersionMinor, 0);
323   add_prop_str(pSubCont, szDirectXVersionLetter, szDirectXVersionLetter_v);
324   add_prop_str(pSubCont, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
325   add_prop_str(pSubCont, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
326   add_prop_bool(pSubCont, bDebug, FALSE);
327
328   msex.dwLength = sizeof(msex);
329   GlobalMemoryStatusEx( &msex );
330   add_prop_ull_as_str(pSubCont, ullPhysicalMemory, msex.ullTotalPhys);
331   add_prop_ull_as_str(pSubCont, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
332   add_prop_ull_as_str(pSubCont, ullAvailPageFile, msex.ullAvailPageFile);
333
334   info.dwOSVersionInfoSize = sizeof(info);
335   GetVersionExW( &info );
336   add_prop_ui4(pSubCont, dwOSMajorVersion, info.dwMajorVersion);
337   add_prop_ui4(pSubCont, dwOSMinorVersion, info.dwMinorVersion);
338   add_prop_ui4(pSubCont, dwOSBuildNumber,  info.dwBuildNumber);
339   add_prop_ui4(pSubCont, dwOSPlatformID,   info.dwPlatformId);
340   add_prop_str(pSubCont, szCSDVersion,     info.szCSDVersion);
341
342   GetWindowsDirectoryW(buffer, MAX_PATH);
343   add_prop_str(pSubCont, szWindowsDir, buffer);
344
345   return S_OK;
346 }
347
348 static HRESULT DXDiag_InitDXDiagSystemDevicesContainer(IDxDiagContainer* pSubCont) {
349   HRESULT hr = S_OK;
350   /*
351   static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
352   static const WCHAR szDeviceID[] = {'s','z','D','e','v','i','c','e','I','D',0};
353
354   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
355
356   VARIANT v;
357   IDxDiagContainer* pDeviceSubCont = NULL;
358   IDxDiagContainer* pDriversCont = NULL;
359
360   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDeviceSubCont);
361   if (FAILED(hr)) { return hr; }
362   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
363   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDescription, &v);
364   VariantClear(&v);
365   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
366   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDeviceID, &v);
367   VariantClear(&v);
368
369   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "", pDeviceSubCont);
370   */
371
372   /*
373    * Drivers Cont contains Files Desc Containers
374    */
375   /*
376   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDriversCont);
377   if (FAILED(hr)) { return hr; }
378   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
379
380   */
381   return hr;
382 }
383
384 static HRESULT DXDiag_InitDXDiagLogicalDisksContainer(IDxDiagContainer* pSubCont) {
385   HRESULT hr = S_OK;
386   /*
387   static const WCHAR szDriveLetter[] = {'s','z','D','r','i','v','e','L','e','t','t','e','r',0};
388   static const WCHAR szFreeSpace[] = {'s','z','F','r','e','e','S','p','a','c','e',0};
389   static const WCHAR szMaxSpace[] = {'s','z','M','a','x','S','p','a','c','e',0};
390   static const WCHAR szFileSystem[] = {'s','z','F','i','l','e','S','y','s','t','e','m',0};
391   static const WCHAR szModel[] = {'s','z','M','o','d','e','l',0};
392   static const WCHAR szPNPDeviceID[] = {'s','z','P','N','P','D','e','v','i','c','e','I','D',0};
393   static const WCHAR dwHardDriveIndex[] = {'d','w','H','a','r','d','D','r','i','v','e','I','n','d','e','x',0};
394
395   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
396  
397   VARIANT v;
398   IDxDiagContainer* pDiskSubCont = NULL;
399   IDxDiagContainer* pDriversCont = NULL;
400
401   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDiskSubCont);
402   if (FAILED(hr)) { return hr; }
403   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "" , pDiskSubCont);
404   */
405   
406   /*
407    * Drivers Cont contains Files Desc Containers
408    */
409   /*
410   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDriversCont);
411   if (FAILED(hr)) { return hr; }
412   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
413   */
414   return hr;
415 }
416
417 static HRESULT DXDiag_InitDXDiagDirectXFilesContainer(IDxDiagContainer* pSubCont)
418 {
419     HRESULT hr = S_OK;
420     static const WCHAR dlls[][15] =
421     {
422         {'d','3','d','8','.','d','l','l',0},
423         {'d','3','d','9','.','d','l','l',0},
424         {'d','d','r','a','w','.','d','l','l',0},
425         {'d','e','v','e','n','u','m','.','d','l','l',0},
426         {'d','i','n','p','u','t','8','.','d','l','l',0},
427         {'d','i','n','p','u','t','.','d','l','l',0},
428         {'d','m','b','a','n','d','.','d','l','l',0},
429         {'d','m','c','o','m','p','o','s','.','d','l','l',0},
430         {'d','m','i','m','e','.','d','l','l',0},
431         {'d','m','l','o','a','d','e','r','.','d','l','l',0},
432         {'d','m','s','c','r','i','p','t','.','d','l','l',0},
433         {'d','m','s','t','y','l','e','.','d','l','l',0},
434         {'d','m','s','y','n','t','h','.','d','l','l',0},
435         {'d','m','u','s','i','c','.','d','l','l',0},
436         {'d','p','l','a','y','x','.','d','l','l',0},
437         {'d','p','n','e','t','.','d','l','l',0},
438         {'d','s','o','u','n','d','.','d','l','l',0},
439         {'d','s','w','a','v','e','.','d','l','l',0},
440         {'d','x','d','i','a','g','n','.','d','l','l',0},
441         {'q','u','a','r','t','z','.','d','l','l',0}
442     };
443     WCHAR szFilePath[MAX_PATH];
444     INT i;
445
446     GetSystemDirectoryW(szFilePath, MAX_PATH);
447
448     for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
449     {
450         static const WCHAR szFormat[] = {'%','d',0};
451         WCHAR szFileID[5];
452         IDxDiagContainer *pDXFileSubCont;
453
454         snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
455
456         hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDXFileSubCont);
457         if (FAILED(hr)) continue;
458
459         if (FAILED(DXDiag_AddFileDescContainer(pDXFileSubCont, szFilePath, dlls[i])) ||
460             FAILED(IDxDiagContainerImpl_AddChildContainer(pSubCont, szFileID, pDXFileSubCont)))
461         {
462             IUnknown_Release(pDXFileSubCont);
463             continue;
464         }
465     }
466     return hr;
467 }
468
469 static HRESULT DXDiag_InitDXDiagDisplayContainer(IDxDiagContainer* pSubCont)
470 {
471     static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
472     static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
473     static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
474     static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
475     static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
476     static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
477     static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
478     static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
479     static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
480     static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
481     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};
482     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};
483
484     static const WCHAR szAdapterID[] = {'0',0};
485     static const WCHAR szEmpty[] = {0};
486
487     HRESULT                 hr;
488     IDxDiagContainer       *pDisplayAdapterSubCont = NULL;
489
490     IDirectDraw7           *pDirectDraw;
491     DDSCAPS2                dd_caps;
492     DISPLAY_DEVICEW         disp_dev;
493     DDSURFACEDESC2          surface_descr;
494     DWORD                   tmp;
495     WCHAR                   buffer[256];
496
497     hr = DXDiag_CreateDXDiagContainer( &IID_IDxDiagContainer, (void**) &pDisplayAdapterSubCont );
498     if (FAILED( hr )) return hr;
499     hr = IDxDiagContainerImpl_AddChildContainer( pSubCont, szAdapterID, pDisplayAdapterSubCont );
500     if (FAILED( hr )) return hr;
501
502     disp_dev.cb = sizeof(disp_dev);
503     if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
504     {
505         add_prop_str( pDisplayAdapterSubCont, szDeviceName, disp_dev.DeviceName );
506         add_prop_str( pDisplayAdapterSubCont, szDescription, disp_dev.DeviceString );
507     }
508
509     hr = DirectDrawCreateEx( NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
510     if (FAILED( hr )) return hr;
511
512     dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
513     dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
514     hr = IDirectDraw7_GetAvailableVidMem( pDirectDraw, &dd_caps, &tmp, NULL );
515     if (SUCCEEDED(hr))
516     {
517         static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
518
519         snprintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0 );
520         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryLocalized, buffer );
521         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryEnglish, buffer );
522     }
523
524     surface_descr.dwSize = sizeof(surface_descr);
525     hr = IDirectDraw7_GetDisplayMode( pDirectDraw, &surface_descr );
526     if (SUCCEEDED(hr))
527     {
528         if (surface_descr.dwFlags & DDSD_WIDTH)
529             add_prop_ui4( pDisplayAdapterSubCont, dwWidth, surface_descr.dwWidth );
530         if (surface_descr.dwFlags & DDSD_HEIGHT)
531             add_prop_ui4( pDisplayAdapterSubCont, dwHeight, surface_descr.dwHeight );
532         if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
533             add_prop_ui4( pDisplayAdapterSubCont, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount );
534     }
535
536     get_display_device_id( buffer );
537     add_prop_str( pDisplayAdapterSubCont, szDeviceIdentifier, buffer );
538
539     add_prop_str( pDisplayAdapterSubCont, szVendorId, szEmpty );
540     add_prop_str( pDisplayAdapterSubCont, szDeviceId, szEmpty );
541     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceKey, szEmpty );
542     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceID, szEmpty );
543
544     IUnknown_Release( pDirectDraw );
545     return hr;
546 }
547
548 static HRESULT DXDiag_InitDXDiagDirectSoundContainer(IDxDiagContainer* pSubCont) {
549   HRESULT hr = S_OK;
550   static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
551   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};
552   IDxDiagContainer* pSubSubCont = NULL;
553
554   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
555   if (FAILED(hr)) { return hr; }
556   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundDevices, pSubSubCont);
557
558   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
559   if (FAILED(hr)) { return hr; }
560   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundCaptureDevices, pSubSubCont);
561
562   return hr;
563 }
564
565 static HRESULT DXDiag_InitDXDiagDirectMusicContainer(IDxDiagContainer* pSubCont) {
566   HRESULT hr = S_OK;
567   return hr;
568 }
569
570 static HRESULT DXDiag_InitDXDiagDirectInputContainer(IDxDiagContainer* pSubCont) {
571   HRESULT hr = S_OK;
572   return hr;
573 }
574
575 static HRESULT DXDiag_InitDXDiagDirectPlayContainer(IDxDiagContainer* pSubCont) {
576   HRESULT hr = S_OK;
577   return hr;
578 }
579
580 static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) {
581   HRESULT hr = S_OK;
582   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
583   static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
584   static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
585   static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
586   static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
587   static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
588   static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
589   static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
590   /*
591   static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0};
592   static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0};
593   */
594   VARIANT v;
595
596   static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
597   static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};  
598   static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
599
600   static const WCHAR szVersionFormat[] = {'v','%','d',0};
601   static const WCHAR szIdFormat[] = {'%','d',0};
602   int i = 0;
603
604
605   ICreateDevEnum* pCreateDevEnum = NULL;
606   IEnumMoniker* pEmCat = NULL;
607   IMoniker* pMCat = NULL;
608   /** */
609   hr = CoCreateInstance(&CLSID_SystemDeviceEnum, 
610                         NULL, 
611                         CLSCTX_INPROC_SERVER,
612                         &IID_ICreateDevEnum, 
613                         (void**) &pCreateDevEnum);
614   if (FAILED(hr)) return hr; 
615   
616   hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
617   if (FAILED(hr)) goto out_show_filters; 
618
619   VariantInit(&v);
620
621   while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) {
622     IPropertyBag* pPropBag = NULL;
623     CLSID clsidCat; 
624     hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag);
625     if (SUCCEEDED(hr)) {
626       WCHAR* wszCatName = NULL;
627       WCHAR* wszCatClsid = NULL;
628
629       hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0);
630       wszCatName = SysAllocString(V_BSTR(&v));
631       VariantClear(&v);
632
633       hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0);
634       wszCatClsid = SysAllocString(V_BSTR(&v));
635       hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat);
636       VariantClear(&v);
637
638       /*
639       hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0);
640       hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v);
641       VariantClear(&v);
642       */
643
644       if (SUCCEEDED(hr)) {
645         IEnumMoniker* pEnum = NULL;
646         IMoniker* pMoniker = NULL;
647         hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);        
648         TRACE("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum);
649         if (FAILED(hr) || pEnum == NULL) {
650           goto class_enum_failed;
651         }
652         while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) {          
653           IPropertyBag* pPropFilterBag = NULL;
654           TRACE("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker);
655           hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag);
656           if (SUCCEEDED(hr)) {
657             LPBYTE pData = NULL;
658             DWORD dwNOutputs = 0;
659             DWORD dwNInputs = 0;
660             DWORD dwMerit = 0;
661             WCHAR bufferW[10];
662             IDxDiagContainer *pDShowSubCont = NULL;
663             IFilterMapper2 *pFileMapper = NULL;
664             IAMFilterData *pFilterData = NULL;
665
666             snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
667             if (FAILED(DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDShowSubCont)) ||
668                 FAILED(IDxDiagContainerImpl_AddChildContainer(pSubCont, bufferW, pDShowSubCont)))
669             {
670               IPropertyBag_Release(pPropFilterBag);
671               if (pDShowSubCont) IUnknown_Release(pDShowSubCont);
672               continue;
673             }
674
675             bufferW[0] = 0;
676             hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0);
677             hr = IDxDiagContainerImpl_AddProp(pDShowSubCont, szName, &v);
678             TRACE("\tName:%s\n", debugstr_w(V_BSTR(&v)));
679             VariantClear(&v);
680
681             hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0);
682             TRACE("\tClsid:%s\n", debugstr_w(V_BSTR(&v)));
683             hr = IDxDiagContainerImpl_AddProp(pDShowSubCont, ClsidFilterW, &v);
684             VariantClear(&v);
685
686             hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
687                                   (LPVOID*)&pFileMapper);
688             if (SUCCEEDED(hr) &&
689                 SUCCEEDED(IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData)))
690             {
691               DWORD array_size;
692               REGFILTER2 *pRF;
693
694               if (SUCCEEDED(IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL)) &&
695                   SUCCEEDED(SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData)))
696               {
697                 ULONG j;
698                 array_size = V_UNION(&v, parray)->rgsabound->cElements;
699
700                 if (SUCCEEDED(IAMFilterData_ParseFilterData(pFilterData, pData, array_size, (BYTE **)&pRF)))
701                 {
702                   snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
703                   if (pRF->dwVersion == 1)
704                   {
705                     for (j = 0; j < pRF->u.s.cPins; j++)
706                       if (pRF->u.s.rgPins[j].bOutput)
707                         dwNOutputs++;
708                       else
709                         dwNInputs++;
710                   }
711                   else if (pRF->dwVersion == 2)
712                   {
713                     for (j = 0; j < pRF->u.s1.cPins2; j++)
714                       if (pRF->u.s1.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
715                         dwNOutputs++;
716                       else
717                         dwNInputs++;
718                   }
719
720                   dwMerit = pRF->dwMerit;
721                   CoTaskMemFree(pRF);
722                 }
723
724                 SafeArrayUnaccessData(V_UNION(&v, parray));
725                 VariantClear(&v);
726               }
727               IFilterMapper2_Release(pFilterData);
728             }
729             if (pFileMapper) IFilterMapper2_Release(pFileMapper);
730
731             add_prop_str(pDShowSubCont, szVersionW, bufferW);
732             add_prop_str(pDShowSubCont, szCatName, wszCatName);
733             add_prop_str(pDShowSubCont, ClsidCatW, wszCatClsid);
734             add_prop_ui4(pDShowSubCont, dwInputs,  dwNInputs);
735             add_prop_ui4(pDShowSubCont, dwOutputs, dwNOutputs);
736             add_prop_ui4(pDShowSubCont, dwMeritW, dwMerit);
737
738             i++;
739           }
740           IPropertyBag_Release(pPropFilterBag); pPropFilterBag = NULL;
741         }
742         IEnumMoniker_Release(pEnum); pEnum = NULL;
743       }
744 class_enum_failed:      
745       SysFreeString(wszCatName);
746       SysFreeString(wszCatClsid);
747       IPropertyBag_Release(pPropBag); pPropBag = NULL;
748     }
749     IEnumMoniker_Release(pMCat); pMCat = NULL;
750   }
751
752 out_show_filters:
753   if (NULL != pEmCat) { IEnumMoniker_Release(pEmCat); pEmCat = NULL; }
754   if (NULL != pCreateDevEnum) { ICreateDevEnum_Release(pCreateDevEnum); pCreateDevEnum = NULL; }
755   return hr;
756 }
757
758 static HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont) {
759   HRESULT hr = S_OK;
760   static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
761   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};
762   static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
763   static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
764   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};
765   static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
766   static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
767   static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
768   static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
769   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};
770   IDxDiagContainer* pSubCont = NULL;
771   
772   TRACE("(%p)\n", pRootCont);
773
774   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
775   if (FAILED(hr)) { return hr; }
776   hr = DXDiag_InitDXDiagSystemInfoContainer(pSubCont);
777   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemInfo, pSubCont);
778
779   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
780   if (FAILED(hr)) { return hr; }
781   hr = DXDiag_InitDXDiagSystemDevicesContainer(pSubCont);
782   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemDevices, pSubCont);
783
784   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
785   if (FAILED(hr)) { return hr; }
786   hr = DXDiag_InitDXDiagLogicalDisksContainer(pSubCont);
787   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_LogicalDisks, pSubCont);
788
789   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
790   if (FAILED(hr)) { return hr; }
791   hr = DXDiag_InitDXDiagDirectXFilesContainer(pSubCont);
792   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectXFiles, pSubCont);
793
794   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
795   if (FAILED(hr)) { return hr; }
796   hr = DXDiag_InitDXDiagDisplayContainer(pSubCont);
797   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DisplayDevices, pSubCont);
798
799   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
800   if (FAILED(hr)) { return hr; }
801   hr = DXDiag_InitDXDiagDirectSoundContainer(pSubCont);
802   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectSound, pSubCont);
803
804   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
805   if (FAILED(hr)) { return hr; }
806   hr = DXDiag_InitDXDiagDirectMusicContainer(pSubCont);
807   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectMusic, pSubCont);
808
809   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
810   if (FAILED(hr)) { return hr; }
811   hr = DXDiag_InitDXDiagDirectInputContainer(pSubCont);
812   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectInput, pSubCont);
813
814   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
815   if (FAILED(hr)) { return hr; }
816   hr = DXDiag_InitDXDiagDirectPlayContainer(pSubCont);
817   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectPlay, pSubCont);
818
819   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
820   if (FAILED(hr)) { return hr; }
821   hr = DXDiag_InitDXDiagDirectShowFiltersContainer(pSubCont);
822   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectShowFilters, pSubCont);
823
824   return hr;
825 }