Create a branch for header work.
[reactos.git] / base / applications / dxdiag / system.c
1 /*
2 * PROJECT: ReactX Diagnosis Application
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/dxdiag/system.c
5 * PURPOSE: ReactX diagnosis system page
6 * COPYRIGHT: Copyright 2008 Johannes Anderwald
7 *
8 */
9
10 #include "precomp.h"
11
12 BOOL
13 GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR Result, DWORD Size)
14 {
15 HKEY hKey;
16 LONG res;
17 DWORD dwType;
18 DWORD dwSize;
19
20
21 if (RegOpenKeyExW(hBaseKey, SubKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
22 return FALSE;
23
24 dwSize = Size;
25 res = RegQueryValueExW(hKey, ValueName, NULL, &dwType, (LPBYTE)Result, &dwSize);
26 RegCloseKey(hKey);
27
28 if (dwType != Type)
29 return FALSE;
30
31 if (res != ERROR_SUCCESS)
32 return FALSE;
33
34 if (Size == sizeof(DWORD))
35 return TRUE;
36
37 Result[(Size / sizeof(WCHAR))-1] = L'\0';
38 return TRUE;
39 }
40
41
42 static
43 BOOL
44 GetDirectXVersion(WCHAR * szBuffer)
45 {
46 WCHAR szVer[20];
47
48 if (!GetRegValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX", L"Version", REG_SZ, szVer, sizeof(szVer)))
49 return FALSE;
50
51 if(!wcscmp(szVer, L"4.02.0095"))
52 wcscpy(szBuffer, L"1.0");
53 else if (!wcscmp(szVer, L"4.03.00.1096"))
54 wcscpy(szBuffer, L"2.0");
55 else if (!wcscmp(szVer, L"4.04.0068"))
56 wcscpy(szBuffer, L"3.0");
57 else if (!wcscmp(szVer, L"4.04.0069"))
58 wcscpy(szBuffer, L"3.0");
59 else if (!wcscmp(szVer, L"4.05.00.0155"))
60 wcscpy(szBuffer, L"5.0");
61 else if (!wcscmp(szVer, L"4.05.01.1721"))
62 wcscpy(szBuffer, L"5.0");
63 else if (!wcscmp(szVer, L"4.05.01.1998"))
64 wcscpy(szBuffer, L"5.0");
65 else if (!wcscmp(szVer, L"4.06.02.0436"))
66 wcscpy(szBuffer, L"6.0");
67 else if (!wcscmp(szVer, L"4.07.00.0700"))
68 wcscpy(szBuffer, L"7.0");
69 else if (!wcscmp(szVer, L"4.07.00.0716"))
70 wcscpy(szBuffer, L"7.0a");
71 else if (!wcscmp(szVer, L"4.08.00.0400"))
72 wcscpy(szBuffer, L"8.0");
73 else if (!wcscmp(szVer, L"4.08.01.0881"))
74 wcscpy(szBuffer, L"8.1");
75 else if (!wcscmp(szVer, L"4.08.01.0810"))
76 wcscpy(szBuffer, L"8.1");
77 else if (!wcscmp(szVer, L"4.09.0000.0900"))
78 wcscpy(szBuffer, L"9.0");
79 else if (!wcscmp(szVer, L"4.09.00.0900"))
80 wcscpy(szBuffer, L"9.0");
81 else if (!wcscmp(szVer, L"4.09.0000.0901"))
82 wcscpy(szBuffer, L"9.0a");
83 else if (!wcscmp(szVer, L"4.09.00.0901"))
84 wcscpy(szBuffer, L"9.0a");
85 else if (!wcscmp(szVer, L"4.09.0000.0902"))
86 wcscpy(szBuffer, L"9.0b");
87 else if (!wcscmp(szVer, L"4.09.00.0902"))
88 wcscpy(szBuffer, L"9.0b");
89 else if (!wcscmp(szVer, L"4.09.00.0904"))
90 wcscpy(szBuffer, L"9.0c");
91 else if (!wcscmp(szVer, L"4.09.0000.0904"))
92 wcscpy(szBuffer, L"9.0c");
93 else
94 return FALSE;
95
96 return TRUE;
97 }
98
99 #if 0
100 static
101 BOOL
102 GetVistaVersion(WCHAR * szBuffer)
103 {
104 DWORD Length;
105
106 if (GetProductInfo(6, 0, 0, 0, &Length))
107 {
108 switch(Length)
109 {
110 case PRODUCT_ULTIMATE:
111 wsprintfW(szBuffer, L"Windows Vista Ultimate (6.0, Build %04u)", info.dwBuildNumber);
112 return TRUE;
113 case PRODUCT_HOME_BASIC:
114 wsprintfW(szBuffer, L"Windows Vista Home Basic (6.0, Build %04u)", info.dwBuildNumber);
115 return TRUE;
116 case PRODUCT_HOME_PREMIUM:
117 wsprintfW(szBuffer, L"Windows Vista Home Premimum (6.0, Build %04u)", info.dwBuildNumber);
118 return TRUE;
119 case PRODUCT_ENTERPRISE:
120 wsprintfW(szBuffer, L"Windows Vista Enterprise (6.0, Build %04u)", info.dwBuildNumber);
121 return TRUE;
122 case PRODUCT_HOME_BASIC_N:
123 wsprintfW(szBuffer, L"Windows Vista Home Basic N(6.0, Build %04u)", info.dwBuildNumber);
124 return TRUE;
125 case PRODUCT_BUSINESS:
126 wsprintfW(szBuffer, L"Windows Vista Business(6.0, Build %04u)", info.dwBuildNumber);
127 return TRUE;
128 case PRODUCT_STARTER:
129 wsprintfW(szBuffer, L"Windows Vista Starter(6.0, Build %04u)", info.dwBuildNumber);
130 return TRUE;
131 case PRODUCT_BUSINESS_N:
132 wsprintfW(szBuffer, L"Windows Vista Business N(6.0, Build %04u)", info.dwBuildNumber);
133 return TRUE;
134 default:
135 return FALSE;
136 }
137 }
138 }
139
140 #endif
141
142
143 static
144 BOOL
145 GetOSVersion(WCHAR * szBuffer)
146 {
147 OSVERSIONINFOEXW info;
148
149 ZeroMemory(&info, sizeof(info));
150 info.dwOSVersionInfoSize = sizeof(info);
151 if (GetVersionExW((LPOSVERSIONINFO)&info))
152 {
153 /* FIXME retrieve ReactOS version*/
154 if (info.dwMajorVersion == 4)
155 {
156 wcscpy(szBuffer, L"Windows NT 4.0");
157 if (info.szCSDVersion[0])
158 {
159 wcscat(szBuffer, L" ");
160 wcscat(szBuffer, info.szCSDVersion);
161 }
162 return TRUE;
163 }
164
165 if (info.dwMajorVersion == 5 && info.dwMinorVersion == 0)
166 {
167 wcscpy(szBuffer, L"Windows 2000");
168 if (info.szCSDVersion[0])
169 {
170 wcscat(szBuffer, L" ");
171 wcscat(szBuffer, info.szCSDVersion);
172 }
173 return TRUE;
174 }
175
176 if (info.dwMajorVersion == 5 && info.dwMinorVersion == 1)
177 {
178 wcscpy(szBuffer, L"Windows XP");
179 if (info.szCSDVersion[0])
180 {
181 wcscat(szBuffer, L" ");
182 wcscat(szBuffer, info.szCSDVersion);
183 }
184 return TRUE;
185 }
186
187 if (info.dwMajorVersion == 6 && info.dwMinorVersion == 0)
188 {
189 // if (GetVistaVersion(szBuffer))
190 // return TRUE;
191
192 wsprintfW(szBuffer, L"Windows Vista (6.0, Build %04u)", info.dwBuildNumber);
193 return TRUE;
194 }
195 }
196
197 return FALSE;
198 }
199
200 static
201 VOID
202 InitializeSystemPage(HWND hwndDlg)
203 {
204 WCHAR szTime[200];
205 DWORD Length;
206 DWORDLONG AvailableBytes, UsedBytes;
207 MEMORYSTATUSEX mem;
208 WCHAR szFormat[40];
209 WCHAR szDesc[50];
210 SYSTEM_INFO SysInfo;
211
212 /* set date/time */
213 szTime[0] = L'\0';
214 Length = GetDateFormat(LOCALE_SYSTEM_DEFAULT, DATE_LONGDATE, NULL, NULL, szTime, sizeof(szTime) / sizeof(WCHAR));
215 if (Length)
216 {
217 szTime[Length-1] = L',';
218 szTime[Length++] = L' ';
219 }
220 Length = GetTimeFormatW(LOCALE_SYSTEM_DEFAULT, TIME_FORCE24HOURFORMAT|LOCALE_NOUSEROVERRIDE, NULL, NULL, &szTime[Length], (sizeof(szTime) / sizeof(WCHAR)));
221 szTime[199] = L'\0';
222 SendDlgItemMessageW(hwndDlg, IDC_STATIC_TIME, WM_SETTEXT, 0, (LPARAM)szTime);
223
224 /* set computer name */
225 szTime[0] = L'\0';
226 Length = sizeof(szTime) / sizeof(WCHAR);
227 if (GetComputerNameW(szTime, &Length))
228 SendDlgItemMessageW(hwndDlg, IDC_STATIC_COMPUTER, WM_SETTEXT, 0, (LPARAM)szTime);
229
230 /* set product name */
231 if (GetOSVersion(szTime))
232 {
233 SendDlgItemMessage(hwndDlg, IDC_STATIC_OS, WM_SETTEXT, 0, (LPARAM)szTime);
234 }
235 else
236 {
237 if (LoadStringW(hInst, IDS_VERSION_UNKNOWN, szTime, sizeof(szTime) / sizeof(WCHAR)))
238 {
239 szTime[(sizeof(szTime) / sizeof(WCHAR))-1] = L'\0';
240 SendDlgItemMessage(hwndDlg, IDC_STATIC_VERSION, WM_SETTEXT, 0, (LPARAM)szTime);
241 }
242 }
243
244 /* FIXME set product language/local language */
245 if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SLANGUAGE , szTime, sizeof(szTime) / sizeof(WCHAR)))
246 SendDlgItemMessageW(hwndDlg, IDC_STATIC_LANG, WM_SETTEXT, 0, (LPARAM)szTime);
247
248 /* set system manufacturer */
249 szTime[0] = L'\0';
250 if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"SystemManufacturer", REG_SZ, szTime, sizeof(szTime)))
251 {
252 szTime[199] = L'\0';
253 SendDlgItemMessageW(hwndDlg, IDC_STATIC_MANU, WM_SETTEXT, 0, (LPARAM)szTime);
254 }
255
256 /* set motherboard model */
257 szTime[0] = L'\0';
258 if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"SystemProductName", REG_SZ, szTime, sizeof(szTime)))
259 {
260 SendDlgItemMessageW(hwndDlg, IDC_STATIC_MODEL, WM_SETTEXT, 0, (LPARAM)szTime);
261 }
262
263 /* set bios model */
264 szTime[0] = L'\0';
265 if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"BIOSVendor", REG_SZ, szTime, sizeof(szTime)))
266 {
267 DWORD Index;
268 DWORD StrLength = (sizeof(szTime) / sizeof(WCHAR));
269
270 Index = wcslen(szTime);
271 StrLength -= Index;
272
273 if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"BIOSReleaseDate", REG_SZ, &szTime[Index], StrLength))
274 {
275 if (Index + StrLength > (sizeof(szTime)/sizeof(WCHAR))- 15)
276 {
277 //FIXME retrieve BiosMajorRelease, BiosMinorRelease
278 //StrLength = wcslen(&szTime[Index]);
279 //szTime[Index+StrLength] = L' ';
280 //wcscpy(&szTime[Index+StrLength], L"Ver: "); //FIXME NON-NLS
281 //szTime[(sizeof(szTime)/sizeof(WCHAR))-1] = L'\0';
282 }
283 SendDlgItemMessageW(hwndDlg, IDC_STATIC_BIOS, WM_SETTEXT, 0, (LPARAM)szTime);
284 }
285 }
286 /* set processor string */
287 if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\CentralProcessor\\0", L"ProcessorNameString", REG_SZ, szDesc, sizeof(szDesc)))
288 {
289 /* FIXME retrieve current speed */
290 szFormat[0] = L'\0';
291 GetSystemInfo(&SysInfo);
292 if (SysInfo.dwNumberOfProcessors > 1)
293 LoadStringW(hInst, IDS_FORMAT_MPPROC, szFormat, sizeof(szFormat) / sizeof(WCHAR));
294 else
295 LoadStringW(hInst, IDS_FORMAT_UNIPROC, szFormat, sizeof(szFormat) / sizeof(WCHAR));
296
297 szFormat[(sizeof(szFormat)/sizeof(WCHAR))-1] = L'\0';
298 wsprintfW(szTime, szFormat, szDesc, SysInfo.dwNumberOfProcessors);
299 SendDlgItemMessageW(hwndDlg, IDC_STATIC_PROC, WM_SETTEXT, 0, (LPARAM)szTime);
300 }
301
302 /* retrieve available memory */
303 ZeroMemory(&mem, sizeof(mem));
304 mem.dwLength = sizeof(mem);
305 if (GlobalMemoryStatusEx(&mem))
306 {
307 if (LoadStringW(hInst, IDS_FORMAT_MB, szFormat, sizeof(szFormat) / sizeof(WCHAR)))
308 {
309 /* set total mem string */
310 szFormat[(sizeof(szFormat) / sizeof(WCHAR))-1] = L'\0';
311 wsprintfW(szTime, szFormat, (mem.ullTotalPhys/1048576));
312 SendDlgItemMessageW(hwndDlg, IDC_STATIC_MEM, WM_SETTEXT, 0, (LPARAM)szTime);
313 }
314
315 if (LoadStringW(hInst, IDS_FORMAT_SWAP, szFormat, sizeof(szFormat) / sizeof(WCHAR)))
316 {
317 /* set swap string */
318 AvailableBytes = (mem.ullTotalPageFile-mem.ullTotalPhys)/1048576;
319 UsedBytes = (mem.ullTotalPageFile-mem.ullAvailPageFile)/1048576;
320
321 szFormat[(sizeof(szFormat) / sizeof(WCHAR))-1] = L'\0';
322 wsprintfW(szTime, szFormat, (UsedBytes), (AvailableBytes));
323 SendDlgItemMessageW(hwndDlg, IDC_STATIC_SWAP, WM_SETTEXT, 0, (LPARAM)szTime);
324 }
325 }
326 /* set directx version string */
327 wcscpy(szTime, L"ReactX ");
328 if (GetDirectXVersion(&szTime[7]))
329 {
330 SendDlgItemMessage(hwndDlg, IDC_STATIC_VERSION, WM_SETTEXT, 0, (LPARAM)szTime);
331 }
332 else
333 {
334 if (LoadStringW(hInst, IDS_VERSION_UNKNOWN, szTime, sizeof(szTime) / sizeof(WCHAR)))
335 {
336 szTime[(sizeof(szTime) / sizeof(WCHAR))-1] = L'\0';
337 SendDlgItemMessage(hwndDlg, IDC_STATIC_VERSION, WM_SETTEXT, 0, (LPARAM)szTime);
338 }
339 }
340 }
341
342
343 INT_PTR CALLBACK
344 SystemPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
345 {
346 UNREFERENCED_PARAMETER(lParam);
347 UNREFERENCED_PARAMETER(wParam);
348 switch (message)
349 {
350 case WM_INITDIALOG:
351 {
352 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
353 InitializeSystemPage(hDlg);
354 return TRUE;
355 }
356 }
357
358 return FALSE;
359 }