kernelbase: Use IOCTL_CONDRV_GET_OUTPUT_INFO in GetConsoleCursorInfo.
[wine.git] / programs / dxdiag / information.c
blobe30aa891dbec4b392002defc1356791cc367bc49
1 /*
2 * DxDiag information collection
4 * Copyright 2011 Andrew Nguyen
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
21 #define WIN32_LEAN_AND_MEAN
22 #include <windows.h>
23 #include <dxdiag.h>
25 #include "wine/debug.h"
26 #include "dxdiag_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
30 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
31 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
32 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};
33 static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
34 static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
35 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
36 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};
37 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};
38 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};
39 static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
40 static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
41 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};
42 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
43 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
44 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
45 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};
46 static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
47 static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
49 struct property_list
51 const WCHAR *property_name;
52 WCHAR **output;
55 static BOOL property_to_string(IDxDiagContainer *container, const WCHAR *property, WCHAR **output)
57 VARIANT var;
58 HRESULT hr;
59 BOOL ret = FALSE;
61 VariantInit(&var);
63 hr = IDxDiagContainer_GetProp(container, property, &var);
64 if (SUCCEEDED(hr))
66 if (V_VT(&var) == VT_BSTR)
68 WCHAR *bstr = V_BSTR(&var);
70 *output = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(bstr) + 1) * sizeof(WCHAR));
71 if (*output)
73 lstrcpyW(*output, bstr);
74 ret = TRUE;
79 VariantClear(&var);
80 return ret;
83 static void free_system_information(struct dxdiag_information *dxdiag_info)
85 struct system_information *system_info = &dxdiag_info->system_info;
87 HeapFree(GetProcessHeap(), 0, system_info->szTimeEnglish);
88 HeapFree(GetProcessHeap(), 0, system_info->szTimeLocalized);
89 HeapFree(GetProcessHeap(), 0, system_info->szMachineNameEnglish);
90 HeapFree(GetProcessHeap(), 0, system_info->szOSExLongEnglish);
91 HeapFree(GetProcessHeap(), 0, system_info->szOSExLocalized);
92 HeapFree(GetProcessHeap(), 0, system_info->szLanguagesEnglish);
93 HeapFree(GetProcessHeap(), 0, system_info->szLanguagesLocalized);
94 HeapFree(GetProcessHeap(), 0, system_info->szSystemManufacturerEnglish);
95 HeapFree(GetProcessHeap(), 0, system_info->szSystemModelEnglish);
96 HeapFree(GetProcessHeap(), 0, system_info->szBIOSEnglish);
97 HeapFree(GetProcessHeap(), 0, system_info->szProcessorEnglish);
98 HeapFree(GetProcessHeap(), 0, system_info->szPhysicalMemoryEnglish);
99 HeapFree(GetProcessHeap(), 0, system_info->szPageFileEnglish);
100 HeapFree(GetProcessHeap(), 0, system_info->szPageFileLocalized);
101 HeapFree(GetProcessHeap(), 0, system_info->szWindowsDir);
102 HeapFree(GetProcessHeap(), 0, system_info->szDirectXVersionLongEnglish);
103 HeapFree(GetProcessHeap(), 0, system_info->szSetupParamEnglish);
104 HeapFree(GetProcessHeap(), 0, system_info->szDxDiagVersion);
107 static inline void fill_system_property_list(struct dxdiag_information *dxdiag_info, struct property_list *list)
109 struct system_information *system_info = &dxdiag_info->system_info;
111 list[0].property_name = szTimeEnglish;
112 list[0].output = &system_info->szTimeEnglish;
113 list[1].property_name = szTimeLocalized;
114 list[1].output = &system_info->szTimeLocalized;
115 list[2].property_name = szMachineNameEnglish;
116 list[2].output = &system_info->szMachineNameEnglish;
117 list[3].property_name = szOSExLongEnglish;
118 list[3].output = &system_info->szOSExLongEnglish;
119 list[4].property_name = szOSExLocalized;
120 list[4].output = &system_info->szOSExLocalized;
121 list[5].property_name = szLanguagesEnglish;
122 list[5].output = &system_info->szLanguagesEnglish;
123 list[6].property_name = szLanguagesLocalized;
124 list[6].output = &system_info->szLanguagesLocalized;
125 list[7].property_name = szSystemManufacturerEnglish;
126 list[7].output = &system_info->szSystemManufacturerEnglish;
127 list[8].property_name = szSystemModelEnglish;
128 list[8].output = &system_info->szSystemModelEnglish;
129 list[9].property_name = szBIOSEnglish;
130 list[9].output = &system_info->szBIOSEnglish;
131 list[10].property_name = szProcessorEnglish;
132 list[10].output = &system_info->szProcessorEnglish;
133 list[11].property_name = szPhysicalMemoryEnglish;
134 list[11].output = &system_info->szPhysicalMemoryEnglish;
135 list[12].property_name = szPageFileEnglish;
136 list[12].output = &system_info->szPageFileEnglish;
137 list[13].property_name = szPageFileLocalized;
138 list[13].output = &system_info->szPageFileLocalized;
139 list[14].property_name = szWindowsDir;
140 list[14].output = &system_info->szWindowsDir;
141 list[15].property_name = szDirectXVersionLongEnglish;
142 list[15].output = &system_info->szDirectXVersionLongEnglish;
143 list[16].property_name = szSetupParamEnglish;
144 list[16].output = &system_info->szSetupParamEnglish;
145 list[17].property_name = szDxDiagVersion;
146 list[17].output = &system_info->szDxDiagVersion;
149 static BOOL fill_system_information(IDxDiagContainer *container, struct dxdiag_information *dxdiag_info)
151 struct system_information *system_info = &dxdiag_info->system_info;
152 size_t i;
153 struct property_list property_list[18];
155 fill_system_property_list(dxdiag_info, property_list);
157 for (i = 0; i < ARRAY_SIZE(property_list); i++)
159 if (!property_to_string(container, property_list[i].property_name, property_list[i].output))
161 WINE_ERR("Failed to retrieve property %s\n", wine_dbgstr_w(property_list[i].property_name));
162 return FALSE;
166 #ifdef _WIN64
167 system_info->win64 = TRUE;
168 #else
169 system_info->win64 = FALSE;
170 #endif
172 return TRUE;
175 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
177 static const struct information_fillers
179 const WCHAR *child_container_name;
180 BOOL (*fill_function)(IDxDiagContainer *, struct dxdiag_information *);
181 void (*free_function)(struct dxdiag_information *);
182 } filler_list[] =
184 {DxDiag_SystemInfo, fill_system_information, free_system_information},
187 void free_dxdiag_information(struct dxdiag_information *system_info)
189 size_t i;
191 if (!system_info)
192 return;
194 for (i = 0; i < ARRAY_SIZE(filler_list); i++)
195 filler_list[i].free_function(system_info);
197 HeapFree(GetProcessHeap(), 0, system_info);
200 struct dxdiag_information *collect_dxdiag_information(BOOL whql_check)
202 IDxDiagProvider *pddp = NULL;
203 IDxDiagContainer *root = NULL;
204 struct dxdiag_information *ret = NULL;
205 DXDIAG_INIT_PARAMS params = {sizeof(DXDIAG_INIT_PARAMS), DXDIAG_DX9_SDK_VERSION};
206 HRESULT hr;
207 size_t i;
209 /* Initialize the DxDiag COM instances. */
210 hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
211 &IID_IDxDiagProvider, (void **)&pddp);
212 if (FAILED(hr))
214 WINE_ERR("IDxDiagProvider instance creation failed with 0x%08x\n", hr);
215 goto error;
218 params.bAllowWHQLChecks = whql_check;
219 hr = IDxDiagProvider_Initialize(pddp, &params);
220 if (FAILED(hr))
221 goto error;
223 hr = IDxDiagProvider_GetRootContainer(pddp, &root);
224 if (FAILED(hr))
225 goto error;
227 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
228 if (!ret)
229 goto error;
231 for (i = 0; i < ARRAY_SIZE(filler_list); i++)
233 IDxDiagContainer *child;
234 BOOL success;
236 hr = IDxDiagContainer_GetChildContainer(root, filler_list[i].child_container_name, &child);
237 if (FAILED(hr))
238 goto error;
240 success = filler_list[i].fill_function(child, ret);
241 IDxDiagContainer_Release(child);
242 if (!success)
243 goto error;
246 IDxDiagContainer_Release(root);
247 IDxDiagProvider_Release(pddp);
248 return ret;
250 error:
251 free_dxdiag_information(ret);
252 if (root) IDxDiagContainer_Release(root);
253 if (pddp) IDxDiagProvider_Release(pddp);
254 return NULL;