ReactOS 0.4.15-dev-8408-g466a198
network.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactX Diagnosis Application
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/dxdiag/network.c
5 * PURPOSE: ReactX diagnosis network page
6 * COPYRIGHT: Copyright 2008 Johannes Anderwald
7 *
8 */
9
10#include "precomp.h"
11
12#include <winver.h>
13
14typedef struct
15{
19
20typedef struct _LANGANDCODEPAGE_
21 {
25
27{
28 {
29 L"{6D4A3650-628D-11D2-AE0F-006097B01411}",
31 },
32 {
33 L"{743B5D60-628D-11D2-AE0F-006097B01411}",
35 },
36 {
37 L"{53934290-628D-11D2-AE0F-006097B01411}",
39 },
40 {
41 L"{EBFE7BA0-628D-11D2-AE0F-006097B01411}",
43 }
44};
45
47{
48 {
49 L"{36E95EE0-8577-11cf-960C-0080C7534E82}",
51 },
52 {
53 L"685BC400-9D2C-11cf-A9CD-00AA006886E3",
55 },
56 {
57 L"{44EAA760-CB68-11cf-9C4E-00A0C905425E}",
59 },
60 {
61 L"{0F1D6860-88D9-11cf-9C4E-00A0C905425E}",
63 }
64};
65
66static
67VOID
69{
70 WCHAR szText[256];
71 LVCOLUMNW lvcolumn;
72 INT Index;
73
74 ZeroMemory(&lvcolumn, sizeof(LVCOLUMNW));
75 lvcolumn.pszText = szText;
77 lvcolumn.fmt = LVCFMT_LEFT;
78 lvcolumn.cx = 200;
79
80 for(Index = 0; Index < 4; Index++)
81 {
82 szText[0] = L'\0';
83 LoadStringW(hInst, IDS_DIRECTPLAY_COL_NAME1 + Index, szText, sizeof(szText) / sizeof(WCHAR));
84 szText[(sizeof(szText) / sizeof(WCHAR))-1] = L'\0';
85 if (Index)
86 lvcolumn.cx = 98;
87 if (SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, Index, (LPARAM)&lvcolumn) == -1)
88 return;
89 }
90}
91
92UINT
94{
95 UINT Index;
96 for(Index = 0; Index < 4; Index++)
97 {
98 if (!wcsncmp(PreDefProviders[Index].Guid, szGuid, 40))
99 return Index;
100 }
101 return UINT_MAX;
102}
103
104BOOL
106{
107 UINT VerSize;
108 DWORD DummyHandle;
109 LPVOID pBuf;
110 WORD lang = 0;
111 WORD code = 0;
112 LPLANGANDCODEPAGE lplangcode;
113 WCHAR szBuffer[100];
114 WCHAR * pResult;
115 BOOL bResult = FALSE;
116 BOOL bVer;
117
118 static const WCHAR wFormat[] = L"\\StringFileInfo\\%04x%04x\\FileVersion";
119 static const WCHAR wTranslation[] = L"VarFileInfo\\Translation";
120
121 /* query version info size */
122 VerSize = GetFileVersionInfoSizeW(szAppName, &DummyHandle);
123 if (!VerSize)
124 return FALSE;
125
126
127 /* allocate buffer */
128 pBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, VerSize);
129 if (!pBuf)
130 return FALSE;
131
132
133 /* query version info */
134 if(!GetFileVersionInfoW(szAppName, 0, VerSize, pBuf))
135 {
136 HeapFree(GetProcessHeap(), 0, pBuf);
137 return FALSE;
138 }
139
140 /* query lang code */
141 if(VerQueryValueW(pBuf, wTranslation, (LPVOID *)&lplangcode, &VerSize))
142 {
143 /* FIXME find language from current locale / if not available,
144 * default to english
145 * for now default to first available language
146 */
147 lang = lplangcode->lang;
148 code = lplangcode->code;
149 }
150 /* set up format */
151 wsprintfW(szBuffer, wFormat, lang, code);
152 /* query manufacturer */
153 pResult = NULL;
154 bVer = VerQueryValueW(pBuf, szBuffer, (LPVOID *)&pResult, &VerSize);
155
156 if (VerSize < szVerSize && bVer && pResult)
157 {
158 wcscpy(szVer, pResult);
159 pResult = wcschr(szVer, L' ');
160 if (pResult)
161 {
162 /* cut off build info */
163 VerSize = (pResult - szVer);
164 }
165 if (GetLocaleInfoW(MAKELCID(lang, SORT_DEFAULT), LOCALE_SLANGUAGE, &szVer[VerSize], szVerSize-VerSize))
166 {
167 szVer[VerSize-1] = L' ';
168 szVer[szVerSize-1] = L'\0';
169 }
170 bResult = TRUE;
171 }
172
173 HeapFree(GetProcessHeap(), 0, pBuf);
174 return bResult;
175}
176
177static
178BOOL
180{
181 DWORD dwIndex = 0;
182 LONG result;
183 WCHAR szName[50];
184 WCHAR szGUID[40];
185 WCHAR szTemp[63];
186 WCHAR szResult[MAX_PATH+20] = {0};
187 DWORD RegProviders = 0;
188 DWORD ProviderIndex;
189 DWORD dwName;
191 INT ItemCount;
192 LRESULT lResult;
193
194
195 ItemCount = ListView_GetItemCount(hDlgCtrl);
196 ZeroMemory(&Item, sizeof(LVITEMW));
197 Item.mask = LVIF_TEXT;
198 Item.pszText = szResult;
199 Item.iItem = ItemCount;
200 /* insert all predefined items first */
201 for(dwIndex = 0; dwIndex < 4; dwIndex++)
202 {
203 Item.iItem = ItemCount + dwIndex;
204 Item.iSubItem = 0;
205 szResult[0] = L'\0';
206 LoadStringW(hInst, PreDefProviders[dwIndex].ResourceID, szResult, sizeof(szResult)/sizeof(WCHAR));
207 szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
208 Item.iItem = SendMessageW(hDlgCtrl, LVM_INSERTITEM, 0, (LPARAM)&Item);
209 Item.iSubItem = 1;
210 szResult[0] = L'\0';
211 LoadStringW(hInst, IDS_REG_FAIL, szResult, sizeof(szResult)/sizeof(WCHAR));
212 szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
213 SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
214 }
215
216 dwIndex = 0;
217 do
218 {
219 dwName = sizeof(szName) / sizeof(WCHAR);
220 result = RegEnumKeyEx(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL);
221 if (result == ERROR_SUCCESS)
222 {
223 szName[(sizeof(szName)/sizeof(WCHAR))-1] = L'\0';
224
225 ProviderIndex = UINT_MAX;
226 if (GetRegValue(hKey, szName, L"GUID", REG_SZ, szGUID, sizeof(szGUID)))
227 ProviderIndex = FindProviderIndex(szGUID, PreDefProviders);
228
229 if (ProviderIndex == UINT_MAX)
230 {
231 /* a custom service provider was found */
232 Item.iItem = ListView_GetItemCount(hDlgCtrl);
233
234 /* FIXME
235 * on Windows Vista we need to use RegLoadMUIString which is not available for older systems
236 */
237 if (!GetRegValue(hKey, szName, L"Friendly Name", REG_SZ, szResult, sizeof(szResult)))
238 if (!GetRegValue(hKey, szName, L"DescriptionW", REG_SZ, szResult, sizeof(szResult)))
239 szResult[0] = L'\0';
240
241 /* insert the new provider */
242 Item.iSubItem = 0;
243 lResult = SendMessageW(hDlgCtrl, LVM_INSERTITEM, 0, (LPARAM)&Item);
244 /* adjust index */
245 ProviderIndex = lResult - ItemCount;
246 }
247
248 szResult[0] = L'\0';
249 /* check if the 'Path' key is available */
250 if (!GetRegValue(hKey, szName, L"Path", REG_SZ, szResult, sizeof(szResult)))
251 {
252 /* retrieve the path by lookup the CLSID */
253 wcscpy(szTemp, L"CLSID\\");
254 wcscpy(&szTemp[6], szGUID);
255 wcscpy(&szTemp[44], L"\\InProcServer32");
256 if (!GetRegValue(HKEY_CLASSES_ROOT, szTemp, NULL, REG_SZ, szResult, sizeof(szResult)))
257 {
258 szResult[0] = L'\0';
259 ProviderIndex = UINT_MAX;
260 }
261 }
262 if (szResult[0])
263 {
264 /* insert path name */
265 Item.iSubItem = 2;
266 Item.iItem = ProviderIndex + ItemCount;
267 SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
268 /* retrieve file version */
269 if (!GetFileVersion(szResult, szTemp, sizeof(szTemp)/sizeof(WCHAR)))
270 {
271 szTemp[0] = L'\0';
272 LoadStringW(hInst, IDS_VERSION_UNKNOWN, szTemp, sizeof(szTemp)/sizeof(WCHAR));
273 szTemp[(sizeof(szTemp)/sizeof(WCHAR))-1] = L'\0';
274 }
275 Item.iSubItem = 3;
276 Item.pszText = szTemp;
277 SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
278 Item.pszText = szResult;
279 }
280
281 if (ProviderIndex != UINT_MAX)
282 {
283 RegProviders |= (1 << ProviderIndex);
284 szResult[0] = L'\0';
285 LoadStringW(hInst, IDS_REG_SUCCESS, szResult, sizeof(szResult) / sizeof(WCHAR));
286 Item.iSubItem = 1;
287
288 Item.iItem = ProviderIndex + ItemCount;
289 szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
290 SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
291 }
292 }
293 dwIndex++;
294 }while(result != ERROR_NO_MORE_ITEMS);
295
296 /* check if all providers have been registered */
297// if (RegProviders == 15)
298 return TRUE;
299 return FALSE;
300}
301
302
303
304static
305void
307{
308 HKEY hKey;
309 LONG result;
310 HWND hDlgCtrl;
311
312 /* open DirectPlay8 key */
313 result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectPlay8\\Service Providers", 0, KEY_READ, &hKey);
314 if (result != ERROR_SUCCESS)
315 return;
316
317 hDlgCtrl = GetDlgItem(hwndDlg, IDC_LIST_PROVIDER);
318
319 /* Highlights the entire row instead of just the selected item in the first column */
321
322 /* initialize list ctrl */
323 InitListViewColumns(hDlgCtrl);
324
325 /* enumerate providers */
328 if (!result)
329 return;
330
331 /* open DirectPlay key */
332 result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectPlay\\Service Providers", 0, KEY_READ, &hKey);
333 if (result != ERROR_SUCCESS)
334 return;
335
336 /* enumerate providers */
339}
340
343{
346 switch (message) {
347 case WM_INITDIALOG:
348 {
351 return TRUE;
352 }
353 }
354
355 return FALSE;
356}
static BOOL EnumerateServiceProviders(HKEY hKey, HWND hDlgCtrl, DIRECTPLAY_GUID *PreDefProviders)
Definition: network.c:179
BOOL GetFileVersion(LPCWSTR szAppName, WCHAR *szVer, DWORD szVerSize)
Definition: network.c:105
INT_PTR CALLBACK NetworkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: network.c:342
struct _LANGANDCODEPAGE_ * LPLANGANDCODEPAGE
static DIRECTPLAY_GUID DirectPlay8SP[]
Definition: network.c:26
static VOID InitListViewColumns(HWND hDlgCtrl)
Definition: network.c:68
UINT FindProviderIndex(LPCWSTR szGuid, DIRECTPLAY_GUID *PreDefProviders)
Definition: network.c:93
struct _LANGANDCODEPAGE_ LANGANDCODEPAGE
static void InitializeDirectPlayDialog(HWND hwndDlg)
Definition: network.c:306
static DIRECTPLAY_GUID DirectPlaySP[]
Definition: network.c:46
BOOL GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR Result, DWORD Size)
Definition: system.c:15
#define IDS_VERSION_UNKNOWN
Definition: resource.h:115
#define IDS_REG_SUCCESS
Definition: resource.h:140
#define IDS_DIRECTPLAY_IPXCONN
Definition: resource.h:136
#define IDS_DIRECTPLAY_MODEMCONN
Definition: resource.h:137
#define IDS_DIRECTPLAY8_SERIALSP
Definition: resource.h:132
#define IDS_DIRECTPLAY_SERIALCONN
Definition: resource.h:138
#define IDS_DIRECTPLAY_COL_NAME1
Definition: resource.h:127
#define IDS_REG_FAIL
Definition: resource.h:139
#define IDC_LIST_PROVIDER
Definition: resource.h:95
#define IDS_DIRECTPLAY8_MODEMSP
Definition: resource.h:131
#define IDS_DIRECTPLAY8_TCPSP
Definition: resource.h:134
#define IDS_DIRECTPLAY_TCPCONN
Definition: resource.h:135
#define IDS_DIRECTPLAY8_IPXSP
Definition: resource.h:133
#define RegCloseKey(hKey)
Definition: registry.h:49
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1665
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:845
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1049
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:611
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
FxAutoRegKey hKey
GLuint64EXT * result
Definition: glext.h:11304
#define UINT_MAX
Definition: limits.h:41
#define REG_SZ
Definition: layer.c:22
static const WCHAR szGuid[]
Definition: rtlstr.c:1892
unsigned int UINT
Definition: ndis.h:50
#define KEY_READ
Definition: nt_native.h:1023
#define SORT_DEFAULT
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define MAKELCID(lgid, srtid)
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
static const WCHAR szName[]
Definition: powrprof.c:45
#define LVM_SETITEM
Definition: commctrl.h:2399
#define LVM_INSERTITEM
Definition: commctrl.h:2406
#define LVCF_WIDTH
Definition: commctrl.h:2587
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2734
#define ListView_GetItemCount(hwnd)
Definition: commctrl.h:2307
#define LVM_INSERTCOLUMNW
Definition: commctrl.h:2632
#define LVIF_TEXT
Definition: commctrl.h:2309
#define LVCF_FMT
Definition: commctrl.h:2586
#define LVCF_SUBITEM
Definition: commctrl.h:2589
#define LVCFMT_LEFT
Definition: commctrl.h:2598
#define LVCF_TEXT
Definition: commctrl.h:2588
#define LVM_SETEXTENDEDLISTVIEWSTYLE
Definition: commctrl.h:2724
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
TCHAR szAppName[128]
Definition: solitaire.cpp:18
UINT ResourceID
Definition: network.c:17
Definition: inflate.c:139
Definition: tftpd.h:60
LPWSTR pszText
Definition: commctrl.h:2567
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
static const WCHAR lang[]
Definition: wbemdisp.c:287
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
#define ZeroMemory
Definition: winbase.h:1712
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define LOCALE_SLANGUAGE
Definition: winnls.h:26
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegEnumKeyEx
Definition: winreg.h:510
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SWP_NOACTIVATE
Definition: winuser.h:1242
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOSIZE
Definition: winuser.h:1245
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define SendMessage
Definition: winuser.h:5852
#define SWP_NOOWNERZORDER
Definition: winuser.h:1249
#define SWP_NOZORDER
Definition: winuser.h:1247
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185