1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * PROJECT: ReactX Diagnosis Application
3*c2c66affSColin Finck * LICENSE: LGPL - See COPYING in the top level directory
4*c2c66affSColin Finck * FILE: base/applications/dxdiag/network.c
5*c2c66affSColin Finck * PURPOSE: ReactX diagnosis network page
6*c2c66affSColin Finck * COPYRIGHT: Copyright 2008 Johannes Anderwald
7*c2c66affSColin Finck *
8*c2c66affSColin Finck */
9*c2c66affSColin Finck
10*c2c66affSColin Finck #include "precomp.h"
11*c2c66affSColin Finck
12*c2c66affSColin Finck #include <winver.h>
13*c2c66affSColin Finck
14*c2c66affSColin Finck typedef struct
15*c2c66affSColin Finck {
16*c2c66affSColin Finck WCHAR Guid[40];
17*c2c66affSColin Finck UINT ResourceID;
18*c2c66affSColin Finck }DIRECTPLAY_GUID;
19*c2c66affSColin Finck
20*c2c66affSColin Finck typedef struct _LANGANDCODEPAGE_
21*c2c66affSColin Finck {
22*c2c66affSColin Finck WORD lang;
23*c2c66affSColin Finck WORD code;
24*c2c66affSColin Finck } LANGANDCODEPAGE, *LPLANGANDCODEPAGE;
25*c2c66affSColin Finck
26*c2c66affSColin Finck static DIRECTPLAY_GUID DirectPlay8SP[] =
27*c2c66affSColin Finck {
28*c2c66affSColin Finck {
29*c2c66affSColin Finck L"{6D4A3650-628D-11D2-AE0F-006097B01411}",
30*c2c66affSColin Finck IDS_DIRECTPLAY8_MODEMSP
31*c2c66affSColin Finck },
32*c2c66affSColin Finck {
33*c2c66affSColin Finck L"{743B5D60-628D-11D2-AE0F-006097B01411}",
34*c2c66affSColin Finck IDS_DIRECTPLAY8_SERIALSP
35*c2c66affSColin Finck },
36*c2c66affSColin Finck {
37*c2c66affSColin Finck L"{53934290-628D-11D2-AE0F-006097B01411}",
38*c2c66affSColin Finck IDS_DIRECTPLAY8_IPXSP
39*c2c66affSColin Finck },
40*c2c66affSColin Finck {
41*c2c66affSColin Finck L"{EBFE7BA0-628D-11D2-AE0F-006097B01411}",
42*c2c66affSColin Finck IDS_DIRECTPLAY8_TCPSP
43*c2c66affSColin Finck }
44*c2c66affSColin Finck };
45*c2c66affSColin Finck
46*c2c66affSColin Finck static DIRECTPLAY_GUID DirectPlaySP[] =
47*c2c66affSColin Finck {
48*c2c66affSColin Finck {
49*c2c66affSColin Finck L"{36E95EE0-8577-11cf-960C-0080C7534E82}",
50*c2c66affSColin Finck IDS_DIRECTPLAY_TCPCONN
51*c2c66affSColin Finck },
52*c2c66affSColin Finck {
53*c2c66affSColin Finck L"685BC400-9D2C-11cf-A9CD-00AA006886E3",
54*c2c66affSColin Finck IDS_DIRECTPLAY_IPXCONN
55*c2c66affSColin Finck },
56*c2c66affSColin Finck {
57*c2c66affSColin Finck L"{44EAA760-CB68-11cf-9C4E-00A0C905425E}",
58*c2c66affSColin Finck IDS_DIRECTPLAY_MODEMCONN
59*c2c66affSColin Finck },
60*c2c66affSColin Finck {
61*c2c66affSColin Finck L"{0F1D6860-88D9-11cf-9C4E-00A0C905425E}",
62*c2c66affSColin Finck IDS_DIRECTPLAY_SERIALCONN
63*c2c66affSColin Finck }
64*c2c66affSColin Finck };
65*c2c66affSColin Finck
66*c2c66affSColin Finck static
67*c2c66affSColin Finck VOID
InitListViewColumns(HWND hDlgCtrl)68*c2c66affSColin Finck InitListViewColumns(HWND hDlgCtrl)
69*c2c66affSColin Finck {
70*c2c66affSColin Finck WCHAR szText[256];
71*c2c66affSColin Finck LVCOLUMNW lvcolumn;
72*c2c66affSColin Finck INT Index;
73*c2c66affSColin Finck
74*c2c66affSColin Finck ZeroMemory(&lvcolumn, sizeof(LVCOLUMNW));
75*c2c66affSColin Finck lvcolumn.pszText = szText;
76*c2c66affSColin Finck lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
77*c2c66affSColin Finck lvcolumn.fmt = LVCFMT_LEFT;
78*c2c66affSColin Finck lvcolumn.cx = 200;
79*c2c66affSColin Finck
80*c2c66affSColin Finck for(Index = 0; Index < 4; Index++)
81*c2c66affSColin Finck {
82*c2c66affSColin Finck szText[0] = L'\0';
83*c2c66affSColin Finck LoadStringW(hInst, IDS_DIRECTPLAY_COL_NAME1 + Index, szText, sizeof(szText) / sizeof(WCHAR));
84*c2c66affSColin Finck szText[(sizeof(szText) / sizeof(WCHAR))-1] = L'\0';
85*c2c66affSColin Finck if (Index)
86*c2c66affSColin Finck lvcolumn.cx = 98;
87*c2c66affSColin Finck if (SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, Index, (LPARAM)&lvcolumn) == -1)
88*c2c66affSColin Finck return;
89*c2c66affSColin Finck }
90*c2c66affSColin Finck }
91*c2c66affSColin Finck
92*c2c66affSColin Finck UINT
FindProviderIndex(LPCWSTR szGuid,DIRECTPLAY_GUID * PreDefProviders)93*c2c66affSColin Finck FindProviderIndex(LPCWSTR szGuid, DIRECTPLAY_GUID * PreDefProviders)
94*c2c66affSColin Finck {
95*c2c66affSColin Finck UINT Index;
96*c2c66affSColin Finck for(Index = 0; Index < 4; Index++)
97*c2c66affSColin Finck {
98*c2c66affSColin Finck if (!wcsncmp(PreDefProviders[Index].Guid, szGuid, 40))
99*c2c66affSColin Finck return Index;
100*c2c66affSColin Finck }
101*c2c66affSColin Finck return UINT_MAX;
102*c2c66affSColin Finck }
103*c2c66affSColin Finck
104*c2c66affSColin Finck BOOL
GetFileVersion(LPCWSTR szAppName,WCHAR * szVer,DWORD szVerSize)105*c2c66affSColin Finck GetFileVersion(LPCWSTR szAppName, WCHAR * szVer, DWORD szVerSize)
106*c2c66affSColin Finck {
107*c2c66affSColin Finck UINT VerSize;
108*c2c66affSColin Finck DWORD DummyHandle;
109*c2c66affSColin Finck LPVOID pBuf;
110*c2c66affSColin Finck WORD lang = 0;
111*c2c66affSColin Finck WORD code = 0;
112*c2c66affSColin Finck LPLANGANDCODEPAGE lplangcode;
113*c2c66affSColin Finck WCHAR szBuffer[100];
114*c2c66affSColin Finck WCHAR * pResult;
115*c2c66affSColin Finck BOOL bResult = FALSE;
116*c2c66affSColin Finck BOOL bVer;
117*c2c66affSColin Finck
118*c2c66affSColin Finck static const WCHAR wFormat[] = L"\\StringFileInfo\\%04x%04x\\FileVersion";
119*c2c66affSColin Finck static const WCHAR wTranslation[] = L"VarFileInfo\\Translation";
120*c2c66affSColin Finck
121*c2c66affSColin Finck /* query version info size */
122*c2c66affSColin Finck VerSize = GetFileVersionInfoSizeW(szAppName, &DummyHandle);
123*c2c66affSColin Finck if (!VerSize)
124*c2c66affSColin Finck return FALSE;
125*c2c66affSColin Finck
126*c2c66affSColin Finck
127*c2c66affSColin Finck /* allocate buffer */
128*c2c66affSColin Finck pBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, VerSize);
129*c2c66affSColin Finck if (!pBuf)
130*c2c66affSColin Finck return FALSE;
131*c2c66affSColin Finck
132*c2c66affSColin Finck
133*c2c66affSColin Finck /* query version info */
134*c2c66affSColin Finck if(!GetFileVersionInfoW(szAppName, 0, VerSize, pBuf))
135*c2c66affSColin Finck {
136*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, pBuf);
137*c2c66affSColin Finck return FALSE;
138*c2c66affSColin Finck }
139*c2c66affSColin Finck
140*c2c66affSColin Finck /* query lang code */
141*c2c66affSColin Finck if(VerQueryValueW(pBuf, wTranslation, (LPVOID *)&lplangcode, &VerSize))
142*c2c66affSColin Finck {
143*c2c66affSColin Finck /* FIXME find language from current locale / if not available,
144*c2c66affSColin Finck * default to english
145*c2c66affSColin Finck * for now default to first available language
146*c2c66affSColin Finck */
147*c2c66affSColin Finck lang = lplangcode->lang;
148*c2c66affSColin Finck code = lplangcode->code;
149*c2c66affSColin Finck }
150*c2c66affSColin Finck /* set up format */
151*c2c66affSColin Finck wsprintfW(szBuffer, wFormat, lang, code);
152*c2c66affSColin Finck /* query manufacturer */
153*c2c66affSColin Finck pResult = NULL;
154*c2c66affSColin Finck bVer = VerQueryValueW(pBuf, szBuffer, (LPVOID *)&pResult, &VerSize);
155*c2c66affSColin Finck
156*c2c66affSColin Finck if (VerSize < szVerSize && bVer && pResult)
157*c2c66affSColin Finck {
158*c2c66affSColin Finck wcscpy(szVer, pResult);
159*c2c66affSColin Finck pResult = wcschr(szVer, L' ');
160*c2c66affSColin Finck if (pResult)
161*c2c66affSColin Finck {
162*c2c66affSColin Finck /* cut off build info */
163*c2c66affSColin Finck VerSize = (pResult - szVer);
164*c2c66affSColin Finck }
165*c2c66affSColin Finck if (GetLocaleInfoW(MAKELCID(lang, SORT_DEFAULT), LOCALE_SLANGUAGE, &szVer[VerSize], szVerSize-VerSize))
166*c2c66affSColin Finck {
167*c2c66affSColin Finck szVer[VerSize-1] = L' ';
168*c2c66affSColin Finck szVer[szVerSize-1] = L'\0';
169*c2c66affSColin Finck }
170*c2c66affSColin Finck bResult = TRUE;
171*c2c66affSColin Finck }
172*c2c66affSColin Finck
173*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, pBuf);
174*c2c66affSColin Finck return bResult;
175*c2c66affSColin Finck }
176*c2c66affSColin Finck
177*c2c66affSColin Finck static
178*c2c66affSColin Finck BOOL
EnumerateServiceProviders(HKEY hKey,HWND hDlgCtrl,DIRECTPLAY_GUID * PreDefProviders)179*c2c66affSColin Finck EnumerateServiceProviders(HKEY hKey, HWND hDlgCtrl, DIRECTPLAY_GUID * PreDefProviders)
180*c2c66affSColin Finck {
181*c2c66affSColin Finck DWORD dwIndex = 0;
182*c2c66affSColin Finck LONG result;
183*c2c66affSColin Finck WCHAR szName[50];
184*c2c66affSColin Finck WCHAR szGUID[40];
185*c2c66affSColin Finck WCHAR szTemp[63];
186*c2c66affSColin Finck WCHAR szResult[MAX_PATH+20] = {0};
187*c2c66affSColin Finck DWORD RegProviders = 0;
188*c2c66affSColin Finck DWORD ProviderIndex;
189*c2c66affSColin Finck DWORD dwName;
190*c2c66affSColin Finck LVITEMW Item;
191*c2c66affSColin Finck INT ItemCount;
192*c2c66affSColin Finck LRESULT lResult;
193*c2c66affSColin Finck
194*c2c66affSColin Finck
195*c2c66affSColin Finck ItemCount = ListView_GetItemCount(hDlgCtrl);
196*c2c66affSColin Finck ZeroMemory(&Item, sizeof(LVITEMW));
197*c2c66affSColin Finck Item.mask = LVIF_TEXT;
198*c2c66affSColin Finck Item.pszText = szResult;
199*c2c66affSColin Finck Item.iItem = ItemCount;
200*c2c66affSColin Finck /* insert all predefined items first */
201*c2c66affSColin Finck for(dwIndex = 0; dwIndex < 4; dwIndex++)
202*c2c66affSColin Finck {
203*c2c66affSColin Finck Item.iItem = ItemCount + dwIndex;
204*c2c66affSColin Finck Item.iSubItem = 0;
205*c2c66affSColin Finck szResult[0] = L'\0';
206*c2c66affSColin Finck LoadStringW(hInst, PreDefProviders[dwIndex].ResourceID, szResult, sizeof(szResult)/sizeof(WCHAR));
207*c2c66affSColin Finck szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
208*c2c66affSColin Finck Item.iItem = SendMessageW(hDlgCtrl, LVM_INSERTITEM, 0, (LPARAM)&Item);
209*c2c66affSColin Finck Item.iSubItem = 1;
210*c2c66affSColin Finck szResult[0] = L'\0';
211*c2c66affSColin Finck LoadStringW(hInst, IDS_REG_FAIL, szResult, sizeof(szResult)/sizeof(WCHAR));
212*c2c66affSColin Finck szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
213*c2c66affSColin Finck SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
214*c2c66affSColin Finck }
215*c2c66affSColin Finck
216*c2c66affSColin Finck dwIndex = 0;
217*c2c66affSColin Finck do
218*c2c66affSColin Finck {
219*c2c66affSColin Finck dwName = sizeof(szName) / sizeof(WCHAR);
220*c2c66affSColin Finck result = RegEnumKeyEx(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL);
221*c2c66affSColin Finck if (result == ERROR_SUCCESS)
222*c2c66affSColin Finck {
223*c2c66affSColin Finck szName[(sizeof(szName)/sizeof(WCHAR))-1] = L'\0';
224*c2c66affSColin Finck
225*c2c66affSColin Finck ProviderIndex = UINT_MAX;
226*c2c66affSColin Finck if (GetRegValue(hKey, szName, L"GUID", REG_SZ, szGUID, sizeof(szGUID)))
227*c2c66affSColin Finck ProviderIndex = FindProviderIndex(szGUID, PreDefProviders);
228*c2c66affSColin Finck
229*c2c66affSColin Finck if (ProviderIndex == UINT_MAX)
230*c2c66affSColin Finck {
231*c2c66affSColin Finck /* a custom service provider was found */
232*c2c66affSColin Finck Item.iItem = ListView_GetItemCount(hDlgCtrl);
233*c2c66affSColin Finck
234*c2c66affSColin Finck /* FIXME
235*c2c66affSColin Finck * on Windows Vista we need to use RegLoadMUIString which is not available for older systems
236*c2c66affSColin Finck */
237*c2c66affSColin Finck if (!GetRegValue(hKey, szName, L"Friendly Name", REG_SZ, szResult, sizeof(szResult)))
238*c2c66affSColin Finck if (!GetRegValue(hKey, szName, L"DescriptionW", REG_SZ, szResult, sizeof(szResult)))
239*c2c66affSColin Finck szResult[0] = L'\0';
240*c2c66affSColin Finck
241*c2c66affSColin Finck /* insert the new provider */
242*c2c66affSColin Finck Item.iSubItem = 0;
243*c2c66affSColin Finck lResult = SendMessageW(hDlgCtrl, LVM_INSERTITEM, 0, (LPARAM)&Item);
244*c2c66affSColin Finck /* adjust index */
245*c2c66affSColin Finck ProviderIndex = lResult - ItemCount;
246*c2c66affSColin Finck }
247*c2c66affSColin Finck
248*c2c66affSColin Finck szResult[0] = L'\0';
249*c2c66affSColin Finck /* check if the 'Path' key is available */
250*c2c66affSColin Finck if (!GetRegValue(hKey, szName, L"Path", REG_SZ, szResult, sizeof(szResult)))
251*c2c66affSColin Finck {
252*c2c66affSColin Finck /* retrieve the path by lookup the CLSID */
253*c2c66affSColin Finck wcscpy(szTemp, L"CLSID\\");
254*c2c66affSColin Finck wcscpy(&szTemp[6], szGUID);
255*c2c66affSColin Finck wcscpy(&szTemp[44], L"\\InProcServer32");
256*c2c66affSColin Finck if (!GetRegValue(HKEY_CLASSES_ROOT, szTemp, NULL, REG_SZ, szResult, sizeof(szResult)))
257*c2c66affSColin Finck {
258*c2c66affSColin Finck szResult[0] = L'\0';
259*c2c66affSColin Finck ProviderIndex = UINT_MAX;
260*c2c66affSColin Finck }
261*c2c66affSColin Finck }
262*c2c66affSColin Finck if (szResult[0])
263*c2c66affSColin Finck {
264*c2c66affSColin Finck /* insert path name */
265*c2c66affSColin Finck Item.iSubItem = 2;
266*c2c66affSColin Finck Item.iItem = ProviderIndex + ItemCount;
267*c2c66affSColin Finck SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
268*c2c66affSColin Finck /* retrieve file version */
269*c2c66affSColin Finck if (!GetFileVersion(szResult, szTemp, sizeof(szTemp)/sizeof(WCHAR)))
270*c2c66affSColin Finck {
271*c2c66affSColin Finck szTemp[0] = L'\0';
272*c2c66affSColin Finck LoadStringW(hInst, IDS_VERSION_UNKNOWN, szTemp, sizeof(szTemp)/sizeof(WCHAR));
273*c2c66affSColin Finck szTemp[(sizeof(szTemp)/sizeof(WCHAR))-1] = L'\0';
274*c2c66affSColin Finck }
275*c2c66affSColin Finck Item.iSubItem = 3;
276*c2c66affSColin Finck Item.pszText = szTemp;
277*c2c66affSColin Finck SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
278*c2c66affSColin Finck Item.pszText = szResult;
279*c2c66affSColin Finck }
280*c2c66affSColin Finck
281*c2c66affSColin Finck if (ProviderIndex != UINT_MAX)
282*c2c66affSColin Finck {
283*c2c66affSColin Finck RegProviders |= (1 << ProviderIndex);
284*c2c66affSColin Finck szResult[0] = L'\0';
285*c2c66affSColin Finck LoadStringW(hInst, IDS_REG_SUCCESS, szResult, sizeof(szResult) / sizeof(WCHAR));
286*c2c66affSColin Finck Item.iSubItem = 1;
287*c2c66affSColin Finck
288*c2c66affSColin Finck Item.iItem = ProviderIndex + ItemCount;
289*c2c66affSColin Finck szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
290*c2c66affSColin Finck SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
291*c2c66affSColin Finck }
292*c2c66affSColin Finck }
293*c2c66affSColin Finck dwIndex++;
294*c2c66affSColin Finck }while(result != ERROR_NO_MORE_ITEMS);
295*c2c66affSColin Finck
296*c2c66affSColin Finck /* check if all providers have been registered */
297*c2c66affSColin Finck // if (RegProviders == 15)
298*c2c66affSColin Finck return TRUE;
299*c2c66affSColin Finck return FALSE;
300*c2c66affSColin Finck }
301*c2c66affSColin Finck
302*c2c66affSColin Finck
303*c2c66affSColin Finck
304*c2c66affSColin Finck static
305*c2c66affSColin Finck void
InitializeDirectPlayDialog(HWND hwndDlg)306*c2c66affSColin Finck InitializeDirectPlayDialog(HWND hwndDlg)
307*c2c66affSColin Finck {
308*c2c66affSColin Finck HKEY hKey;
309*c2c66affSColin Finck LONG result;
310*c2c66affSColin Finck HWND hDlgCtrl;
311*c2c66affSColin Finck
312*c2c66affSColin Finck /* open DirectPlay8 key */
313*c2c66affSColin Finck result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectPlay8\\Service Providers", 0, KEY_READ, &hKey);
314*c2c66affSColin Finck if (result != ERROR_SUCCESS)
315*c2c66affSColin Finck return;
316*c2c66affSColin Finck
317*c2c66affSColin Finck hDlgCtrl = GetDlgItem(hwndDlg, IDC_LIST_PROVIDER);
318*c2c66affSColin Finck
319*c2c66affSColin Finck /* Highlights the entire row instead of just the selected item in the first column */
320*c2c66affSColin Finck SendMessage(hDlgCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
321*c2c66affSColin Finck
322*c2c66affSColin Finck /* initialize list ctrl */
323*c2c66affSColin Finck InitListViewColumns(hDlgCtrl);
324*c2c66affSColin Finck
325*c2c66affSColin Finck /* enumerate providers */
326*c2c66affSColin Finck result = EnumerateServiceProviders(hKey, hDlgCtrl, DirectPlay8SP);
327*c2c66affSColin Finck RegCloseKey(hKey);
328*c2c66affSColin Finck if (!result)
329*c2c66affSColin Finck return;
330*c2c66affSColin Finck
331*c2c66affSColin Finck /* open DirectPlay key */
332*c2c66affSColin Finck result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectPlay\\Service Providers", 0, KEY_READ, &hKey);
333*c2c66affSColin Finck if (result != ERROR_SUCCESS)
334*c2c66affSColin Finck return;
335*c2c66affSColin Finck
336*c2c66affSColin Finck /* enumerate providers */
337*c2c66affSColin Finck EnumerateServiceProviders(hKey, hDlgCtrl, DirectPlaySP);
338*c2c66affSColin Finck RegCloseKey(hKey);
339*c2c66affSColin Finck }
340*c2c66affSColin Finck
341*c2c66affSColin Finck INT_PTR CALLBACK
NetworkPageWndProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)342*c2c66affSColin Finck NetworkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
343*c2c66affSColin Finck {
344*c2c66affSColin Finck UNREFERENCED_PARAMETER(lParam);
345*c2c66affSColin Finck UNREFERENCED_PARAMETER(wParam);
346*c2c66affSColin Finck switch (message) {
347*c2c66affSColin Finck case WM_INITDIALOG:
348*c2c66affSColin Finck {
349*c2c66affSColin Finck SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
350*c2c66affSColin Finck InitializeDirectPlayDialog(hDlg);
351*c2c66affSColin Finck return TRUE;
352*c2c66affSColin Finck }
353*c2c66affSColin Finck }
354*c2c66affSColin Finck
355*c2c66affSColin Finck return FALSE;
356*c2c66affSColin Finck }
357