ddraw/tests: Use compare_uint() in compare_float() instead of abs().
[wine.git] / programs / dxdiag / information.c
blob99c1a6715b27ba13cb3e60b833a3bd053d5b2809
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 struct property_list
32 const WCHAR *property_name;
33 WCHAR **output;
36 static BOOL property_to_string(IDxDiagContainer *container, const WCHAR *property, WCHAR **output)
38 VARIANT var;
39 HRESULT hr;
40 BOOL ret = FALSE;
42 VariantInit(&var);
44 hr = IDxDiagContainer_GetProp(container, property, &var);
45 if (SUCCEEDED(hr))
47 if (V_VT(&var) == VT_BSTR)
49 WCHAR *bstr = V_BSTR(&var);
51 *output = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(bstr) + 1) * sizeof(WCHAR));
52 if (*output)
54 lstrcpyW(*output, bstr);
55 ret = TRUE;
60 VariantClear(&var);
61 return ret;
64 static void free_system_information(struct dxdiag_information *dxdiag_info)
66 struct system_information *system_info = &dxdiag_info->system_info;
68 HeapFree(GetProcessHeap(), 0, system_info->szTimeEnglish);
69 HeapFree(GetProcessHeap(), 0, system_info->szTimeLocalized);
70 HeapFree(GetProcessHeap(), 0, system_info->szMachineNameEnglish);
71 HeapFree(GetProcessHeap(), 0, system_info->szOSExLongEnglish);
72 HeapFree(GetProcessHeap(), 0, system_info->szOSExLocalized);
73 HeapFree(GetProcessHeap(), 0, system_info->szLanguagesEnglish);
74 HeapFree(GetProcessHeap(), 0, system_info->szLanguagesLocalized);
75 HeapFree(GetProcessHeap(), 0, system_info->szSystemManufacturerEnglish);
76 HeapFree(GetProcessHeap(), 0, system_info->szSystemModelEnglish);
77 HeapFree(GetProcessHeap(), 0, system_info->szBIOSEnglish);
78 HeapFree(GetProcessHeap(), 0, system_info->szProcessorEnglish);
79 HeapFree(GetProcessHeap(), 0, system_info->szPhysicalMemoryEnglish);
80 HeapFree(GetProcessHeap(), 0, system_info->szPageFileEnglish);
81 HeapFree(GetProcessHeap(), 0, system_info->szPageFileLocalized);
82 HeapFree(GetProcessHeap(), 0, system_info->szWindowsDir);
83 HeapFree(GetProcessHeap(), 0, system_info->szDirectXVersionLongEnglish);
84 HeapFree(GetProcessHeap(), 0, system_info->szSetupParamEnglish);
85 HeapFree(GetProcessHeap(), 0, system_info->szDxDiagVersion);
88 static inline void fill_system_property_list(struct dxdiag_information *dxdiag_info, struct property_list *list)
90 struct system_information *system_info = &dxdiag_info->system_info;
92 list[0].property_name = L"szTimeEnglish";
93 list[0].output = &system_info->szTimeEnglish;
94 list[1].property_name = L"szTimeLocalized";
95 list[1].output = &system_info->szTimeLocalized;
96 list[2].property_name = L"szMachineNameEnglish";
97 list[2].output = &system_info->szMachineNameEnglish;
98 list[3].property_name = L"szOSExLongEnglish";
99 list[3].output = &system_info->szOSExLongEnglish;
100 list[4].property_name = L"szOSExLocalized";
101 list[4].output = &system_info->szOSExLocalized;
102 list[5].property_name = L"szLanguagesEnglish";
103 list[5].output = &system_info->szLanguagesEnglish;
104 list[6].property_name = L"szLanguagesLocalized";
105 list[6].output = &system_info->szLanguagesLocalized;
106 list[7].property_name = L"szSystemManufacturerEnglish";
107 list[7].output = &system_info->szSystemManufacturerEnglish;
108 list[8].property_name = L"szSystemModelEnglish";
109 list[8].output = &system_info->szSystemModelEnglish;
110 list[9].property_name = L"szBIOSEnglish";
111 list[9].output = &system_info->szBIOSEnglish;
112 list[10].property_name = L"szProcessorEnglish";
113 list[10].output = &system_info->szProcessorEnglish;
114 list[11].property_name = L"szPhysicalMemoryEnglish";
115 list[11].output = &system_info->szPhysicalMemoryEnglish;
116 list[12].property_name = L"szPageFileEnglish";
117 list[12].output = &system_info->szPageFileEnglish;
118 list[13].property_name = L"szPageFileLocalized";
119 list[13].output = &system_info->szPageFileLocalized;
120 list[14].property_name = L"szWindowsDir";
121 list[14].output = &system_info->szWindowsDir;
122 list[15].property_name = L"szDirectXVersionLongEnglish";
123 list[15].output = &system_info->szDirectXVersionLongEnglish;
124 list[16].property_name = L"szSetupParamEnglish";
125 list[16].output = &system_info->szSetupParamEnglish;
126 list[17].property_name = L"szDxDiagVersion";
127 list[17].output = &system_info->szDxDiagVersion;
130 static BOOL fill_system_information(IDxDiagContainer *container, struct dxdiag_information *dxdiag_info)
132 struct system_information *system_info = &dxdiag_info->system_info;
133 size_t i;
134 struct property_list property_list[18];
136 fill_system_property_list(dxdiag_info, property_list);
138 for (i = 0; i < ARRAY_SIZE(property_list); i++)
140 if (!property_to_string(container, property_list[i].property_name, property_list[i].output))
142 WINE_ERR("Failed to retrieve property %s\n", wine_dbgstr_w(property_list[i].property_name));
143 return FALSE;
147 #ifdef _WIN64
148 system_info->win64 = TRUE;
149 #else
150 system_info->win64 = FALSE;
151 #endif
153 return TRUE;
156 static const struct information_fillers
158 const WCHAR *child_container_name;
159 BOOL (*fill_function)(IDxDiagContainer *, struct dxdiag_information *);
160 void (*free_function)(struct dxdiag_information *);
161 } filler_list[] =
163 {L"DxDiag_SystemInfo", fill_system_information, free_system_information},
166 void free_dxdiag_information(struct dxdiag_information *system_info)
168 size_t i;
170 if (!system_info)
171 return;
173 for (i = 0; i < ARRAY_SIZE(filler_list); i++)
174 filler_list[i].free_function(system_info);
176 HeapFree(GetProcessHeap(), 0, system_info);
179 struct dxdiag_information *collect_dxdiag_information(BOOL whql_check)
181 IDxDiagProvider *pddp = NULL;
182 IDxDiagContainer *root = NULL;
183 struct dxdiag_information *ret = NULL;
184 DXDIAG_INIT_PARAMS params = {sizeof(DXDIAG_INIT_PARAMS), DXDIAG_DX9_SDK_VERSION};
185 HRESULT hr;
186 size_t i;
188 /* Initialize the DxDiag COM instances. */
189 hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
190 &IID_IDxDiagProvider, (void **)&pddp);
191 if (FAILED(hr))
193 WINE_ERR("IDxDiagProvider instance creation failed with 0x%08lx\n", hr);
194 goto error;
197 params.bAllowWHQLChecks = whql_check;
198 hr = IDxDiagProvider_Initialize(pddp, &params);
199 if (FAILED(hr))
200 goto error;
202 hr = IDxDiagProvider_GetRootContainer(pddp, &root);
203 if (FAILED(hr))
204 goto error;
206 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
207 if (!ret)
208 goto error;
210 for (i = 0; i < ARRAY_SIZE(filler_list); i++)
212 IDxDiagContainer *child;
213 BOOL success;
215 hr = IDxDiagContainer_GetChildContainer(root, filler_list[i].child_container_name, &child);
216 if (FAILED(hr))
217 goto error;
219 success = filler_list[i].fill_function(child, ret);
220 IDxDiagContainer_Release(child);
221 if (!success)
222 goto error;
225 IDxDiagContainer_Release(root);
226 IDxDiagProvider_Release(pddp);
227 return ret;
229 error:
230 free_dxdiag_information(ret);
231 if (root) IDxDiagContainer_Release(root);
232 if (pddp) IDxDiagProvider_Release(pddp);
233 return NULL;