ReactOS 0.4.15-dev-8096-ga0eec98
setup.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Shell
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: ReactOS Networking Configuration
5 * COPYRIGHT: Copyright 2016 Eric Kohl
6 */
7
8#include "precomp.h"
9
10#include <syssetup/syssetup.h>
11
12
13#define NETWORK_SETUP_MAGIC 0x50515253
14
15typedef struct _NETWORKSETUPDATA
16{
19
20
23
24
25extern "C"
26{
27
28static
29VOID
31 HWND hwndDlg,
32 INT control,
33 PSETUPDATA pSetupData)
34{
35 SendDlgItemMessageW(hwndDlg, control, WM_SETFONT, (WPARAM)pSetupData->hBoldFont, MAKELPARAM(TRUE, 0));
36}
37
38
39static
42{
43 INetCfg *pNetCfg = NULL;
44 INetCfgLock *pNetCfgLock = NULL;
45 INetCfgComponent *pTcpipComponent = NULL;
46 INetCfgComponent *pNicComponent = NULL;
47 IEnumNetCfgComponent *pEnumNicComponents = NULL;
48 WCHAR *pszNicName;
49 BOOL fWriteLocked = FALSE, fInitialized = FALSE;
50 HRESULT hr;
51
52 TRACE("InstallTypicalNetworkSettings()\n");
53
55 if (hr != S_OK)
56 {
57 ERR("CoInitialize failed\n");
58 goto exit;
59 }
60
62 NULL,
63 CLSCTX_INPROC_SERVER,
65 (PVOID*)&pNetCfg);
66 if (hr != S_OK)
67 {
68 ERR("CoCreateInstance failed\n");
69 goto exit;
70 }
71
72 /* Acquire the write-lock */
74 (PVOID*)&pNetCfgLock);
75 if (hr != S_OK)
76 {
77 ERR("QueryInterface failed\n");
78 goto exit;
79 }
80
81 hr = pNetCfgLock->AcquireWriteLock(5000,
82 L"SysSetup",
83 NULL);
84 if (hr != S_OK)
85 {
86 ERR("AcquireWriteLock failed\n");
87 goto exit;
88 }
89
90 fWriteLocked = TRUE;
91
92 /* Initialize the network configuration */
93 hr = pNetCfg->Initialize(NULL);
94 if (hr != S_OK)
95 {
96 ERR("Initialize failed\n");
97 goto exit;
98 }
99
100 fInitialized = TRUE;
101
102 /* Find the TCP/IP driver */
103 hr = pNetCfg->FindComponent(L"ms_tcpip",
104 &pTcpipComponent);
105 if (hr == S_OK)
106 {
107 FIXME("Found the TCP/IP driver!\n");
108 }
109 else
110 {
111 ERR("Initialize failed\n");
112 goto exit;
113 }
114
115 hr = pNetCfg->EnumComponents(&GUID_DEVCLASS_NET,
116 &pEnumNicComponents);
117 if (hr != S_OK)
118 {
119 ERR("EnumComponents failed\n");
120 goto exit;
121 }
122
123 for (;;)
124 {
125 hr = pEnumNicComponents->Next(1,
126 &pNicComponent,
127 NULL);
128 if (hr != S_OK)
129 {
130 TRACE("EnumNicComponents done!\n");
131 break;
132 }
133
134 hr = pNicComponent->GetDisplayName(&pszNicName);
135 if (hr == S_OK)
136 {
137 FIXME("NIC name: %S\n", pszNicName);
138 CoTaskMemFree(pszNicName);
139 }
140
141 // FIXME Bind Tcpip to the NIC
142
143 pNicComponent->Release();
144 pNicComponent = NULL;
145 }
146
147 TRACE("Done!\n");
148exit:
149 if (pNicComponent != NULL)
150 pNicComponent->Release();
151
152 if (pEnumNicComponents != NULL)
153 pEnumNicComponents->Release();
154
155 if (pTcpipComponent != NULL)
156 pTcpipComponent->Release();
157
158 if (fInitialized)
159 pNetCfg->Uninitialize();
160
161 if (fWriteLocked)
162 pNetCfgLock->ReleaseWriteLock();
163
164 if (pNetCfgLock != NULL)
165 pNetCfgLock->Release();
166
167 if (pNetCfg != NULL)
168 pNetCfg->Release();
169
171
172 TRACE("InstallTypicalNetworkSettings() done!\n");
173
174 return hr;
175}
176
177
178static
182 HWND hwndDlg,
183 UINT uMsg,
186{
187 PNETWORKSETUPDATA pNetworkSetupData;
188 PSETUPDATA pSetupData;
189 LPNMHDR lpnm;
190
191 /* Retrieve pointer to the global setup data */
192 pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
193 if ((pNetworkSetupData != NULL) &&
194 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
195 pSetupData = pNetworkSetupData->pSetupData;
196
197 switch (uMsg)
198 {
199 case WM_INITDIALOG:
200 /* Save pointer to the global setup data */
201 pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
202 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
203 pSetupData = pNetworkSetupData->pSetupData;
204
205 /* Set the fonts of both the options to bold */
206 SetBoldText(hwndDlg, IDC_NETWORK_TYPICAL, pSetupData);
207 SetBoldText(hwndDlg, IDC_NETWORK_CUSTOM, pSetupData);
208
209 /* Set the typical settings option as the default */
211
212 if (pSetupData->UnattendSetup)
213 {
214 //...
215 }
216 break;
217
218 case WM_DESTROY:
219 /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
220 //...
221 break;
222
223 case WM_NOTIFY:
224 lpnm = (LPNMHDR)lParam;
225
226 switch (lpnm->code)
227 {
228 case PSN_SETACTIVE:
229 /* Enable the Back and Next buttons */
231 if (pSetupData->UnattendSetup)
232 {
234 return TRUE;
235 }
236 break;
237
238 case PSN_WIZNEXT:
239 pNetworkSetupData->bTypicalNetworkSetup = FALSE;
240
241 /* If the Typical Settings button is chosen, then skip to the Domain Page */
243 {
244 pNetworkSetupData->bTypicalNetworkSetup = TRUE;
245
247
249 return TRUE;
250 }
251 break;
252
253 case PSN_WIZBACK:
254 pSetupData->UnattendSetup = FALSE;
255 break;
256 }
257 break;
258
259 default:
260 break;
261 }
262
263 return FALSE;
264}
265
266static
270 HWND hwndDlg,
271 UINT uMsg,
274{
275 PNETWORKSETUPDATA pNetworkSetupData;
276 PSETUPDATA pSetupData;
277 LPNMHDR lpnm;
278
279 /* Retrieve pointer to the global setup data */
280 pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
281 if ((pNetworkSetupData != NULL) &&
282 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
283 pSetupData = pNetworkSetupData->pSetupData;
284
285 switch (uMsg)
286 {
287 case WM_INITDIALOG:
288 /* Save pointer to the global setup data */
289 pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
290 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
291 pSetupData = pNetworkSetupData->pSetupData;
292
293 SetBoldText(hwndDlg, IDC_NETWORK_DEVICE, pSetupData);
294
295 if (pSetupData->UnattendSetup)
296 {
297 //...
298 }
299 break;
300
301 case WM_DESTROY:
302 /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
303 //...
304 break;
305
306 case WM_NOTIFY:
307 lpnm = (LPNMHDR)lParam;
308
309 switch (lpnm->code)
310 {
311 case PSN_SETACTIVE:
312 /* Enable the Back and Next buttons */
314 if (pSetupData->UnattendSetup)
315 {
317 return TRUE;
318 }
319 break;
320
321 case PSN_WIZBACK:
322 pSetupData->UnattendSetup = FALSE;
323 break;
324 }
325 break;
326
327 default:
328 break;
329 }
330
331 return FALSE;
332}
333
334static
338 HWND hwndDlg,
339 UINT uMsg,
342{
343 PNETWORKSETUPDATA pNetworkSetupData;
344 PSETUPDATA pSetupData;
345 WCHAR DomainName[51];
346 WCHAR Title[64];
347 WCHAR ErrorName[256];
348 LPNMHDR lpnm;
349
350 /* Retrieve pointer to the global setup data */
351 pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
352 if ((pNetworkSetupData != NULL) &&
353 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
354 pSetupData = pNetworkSetupData->pSetupData;
355
356 switch (uMsg)
357 {
358 case WM_INITDIALOG:
359 /* Save pointer to the global setup data */
360 pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
361 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
362 pSetupData = pNetworkSetupData->pSetupData;
363
364 /* Set the workgroup option as the default */
366
367 wcscpy(DomainName, L"WORKGROUP");
368
369 /* Display current computer name */
370 SetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName);
371
372 /* Set focus to owner name */
374
375 if (pSetupData->UnattendSetup)
376 {
377 //...
378 }
379 break;
380
381 case WM_DESTROY:
382 //...
383 /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
384 if (pNetworkSetupData != NULL)
385 {
386 if ((!IsBadReadPtr(pNetworkSetupData, sizeof(NETWORKSETUPDATA))) &&
387 (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
388 HeapFree(GetProcessHeap(), 0, pNetworkSetupData);
389
391 }
392 break;
393
394 case WM_NOTIFY:
395 lpnm = (LPNMHDR)lParam;
396
397 switch (lpnm->code)
398 {
399 case PSN_SETACTIVE:
400 /* Enable the Back and Next buttons */
402 if (pSetupData->UnattendSetup)
403 {
405 return TRUE;
406 }
407 break;
408
409 case PSN_WIZNEXT:
410 DomainName[0] = 0;
411 if (GetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName, 50) == 0)
412 {
413 if (0 == LoadStringW(netshell_hInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
414 {
415 wcscpy(Title, L"ReactOS Setup");
416 }
417 if (0 == LoadStringW(netshell_hInstance, IDS_WZD_DOMAIN_NAME, ErrorName, sizeof(ErrorName) / sizeof(ErrorName[0])))
418 {
419 wcscpy(ErrorName, L"Setup cannot continue until you\nenter the name of your domain/workgroup.");
420 }
421 MessageBoxW(hwndDlg, ErrorName, Title, MB_ICONERROR | MB_OK);
422
424 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
425
426 //TODO: Implement setting the Domain/Workgroup
427
428 return TRUE;
429 }
430 break;
431
432 case PSN_WIZBACK:
433 pSetupData->UnattendSetup = FALSE;
434
435 /* If the Typical setup chosen, then skip back to the Settings Page */
436 if (pNetworkSetupData->bTypicalNetworkSetup == TRUE)
437 {
439 return TRUE;
440 }
441 break;
442 }
443 break;
444
445 default:
446 break;
447 }
448
449 return FALSE;
450}
451
452
453DWORD
454WINAPI
456 PDWORD pPageCount,
457 HPROPSHEETPAGE *pPages,
458 PSETUPDATA pSetupData)
459{
460 PNETWORKSETUPDATA pNetworkSetupData;
461 PROPSHEETPAGE psp = {0};
462 DWORD dwPageCount = 3;
463 INT nPage = 0;
464
465 if (pPageCount == NULL)
467
468 if (pPages == NULL)
469 {
470 *pPageCount = dwPageCount;
471 return ERROR_SUCCESS;
472 }
473
474 if (*pPageCount < dwPageCount)
476
478
480 if (pNetworkSetupData == NULL)
481 return ERROR_OUTOFMEMORY;
482
483 pNetworkSetupData->dwMagic = NETWORK_SETUP_MAGIC;
484 pNetworkSetupData->pSetupData = pSetupData;
485
486
487 /* Create the Network Settings page */
488 psp.dwSize = sizeof(PROPSHEETPAGE);
490 psp.lParam = (LPARAM)pNetworkSetupData;
491
492 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
493 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSTITLE);
494 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSSUBTITLE);
495 psp.pfnDlgProc = NetworkSettingsPageDlgProc;
496 psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKSETTINGSPAGE);
497 pPages[nPage++] = CreatePropertySheetPage(&psp);
498
499 /* Create the Network Components page */
500 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
501 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTTITLE);
502 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTSUBTITLE);
503 psp.pfnDlgProc = NetworkComponentPageDlgProc;
504 psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKCOMPONENTPAGE);
505 pPages[nPage++] = CreatePropertySheetPage(&psp);
506
507 /* Create the Domain/Workgroup page */
508 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
509 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINTITLE);
510 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINSUBTITLE);
511 psp.pfnDlgProc = NetworkDomainPageDlgProc;
512 psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKDOMAINPAGE);
513 pPages[nPage++] = CreatePropertySheetPage(&psp);
514
515 *pPageCount = dwPageCount;
516
517 return ERROR_SUCCESS;
518}
519
520} // extern "C"
#define FIXME(fmt,...)
Definition: debug.h:114
#define ERR(fmt,...)
Definition: debug.h:113
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#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
#define IDS_NETWORKCOMPONENTTITLE
Definition: resource.h:120
#define IDD_NETWORKCOMPONENTPAGE
Definition: resource.h:59
#define IDS_REACTOS_SETUP
Definition: resource.h:124
#define IDS_NETWORKSETTINGSTITLE
Definition: resource.h:118
#define IDD_NETWORKDOMAINPAGE
Definition: resource.h:66
#define IDD_NETWORKSETTINGSPAGE
Definition: resource.h:55
#define IDC_NETWORK_CUSTOM
Definition: resource.h:57
#define IDS_NETWORKSETTINGSSUBTITLE
Definition: resource.h:119
#define IDC_NETWORK_TYPICAL
Definition: resource.h:56
#define IDS_NETWORKDOMAINTITLE
Definition: resource.h:122
#define IDC_SELECT_WORKGROUP
Definition: resource.h:67
#define IDS_NETWORKDOMAINSUBTITLE
Definition: resource.h:123
#define IDS_WZD_DOMAIN_NAME
Definition: resource.h:125
#define IDC_NETWORK_DEVICE
Definition: resource.h:61
#define IDS_NETWORKCOMPONENTSUBTITLE
Definition: resource.h:121
#define IDC_DOMAIN_NAME
Definition: resource.h:69
static const WCHAR Title[]
Definition: oid.c:1259
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:805
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
unsigned int UINT
Definition: ndis.h:50
EXTERN_C const IID IID_INetCfgLock
Definition: netcfgx.h:17
EXTERN_C const GUID CLSID_CNetCfg
Definition: netcfgx.h:299
EXTERN_C const IID IID_INetCfg
Definition: netcfgx.h:300
HINSTANCE netshell_hInstance
Definition: netshell.cpp:12
#define L(x)
Definition: ntvdm.h:50
DWORD * PDWORD
Definition: pedump.c:68
#define CreatePropertySheetPage
Definition: prsht.h:399
#define PSN_WIZNEXT
Definition: prsht.h:121
#define PSP_DEFAULT
Definition: prsht.h:22
#define PSWIZB_NEXT
Definition: prsht.h:154
#define PSWIZB_BACK
Definition: prsht.h:153
#define PropSheet_SetWizButtons(d, f)
Definition: prsht.h:357
#define LPPROPSHEETPAGE
Definition: prsht.h:390
#define PSN_WIZBACK
Definition: prsht.h:120
#define PSN_SETACTIVE
Definition: prsht.h:115
#define PROPSHEETPAGE
Definition: prsht.h:389
#define WM_NOTIFY
Definition: richedit.h:61
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define exit(n)
Definition: config.h:202
struct _NETWORKSETUPDATA * PNETWORKSETUPDATA
static INT_PTR CALLBACK NetworkSettingsPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: setup.cpp:181
DWORD WINAPI NetSetupRequestWizardPages(PDWORD pPageCount, HPROPSHEETPAGE *pPages, PSETUPDATA pSetupData)
Definition: setup.cpp:455
static HRESULT InstallTypicalNetworkSettings(VOID)
Definition: setup.cpp:41
struct _NETWORKSETUPDATA NETWORKSETUPDATA
static INT_PTR CALLBACK NetworkDomainPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: setup.cpp:337
static INT_PTR CALLBACK NetworkComponentPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: setup.cpp:269
#define NETWORK_SETUP_MAGIC
Definition: setup.cpp:13
static VOID SetBoldText(HWND hwndDlg, INT control, PSETUPDATA pSetupData)
Definition: setup.cpp:30
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
BOOL bTypicalNetworkSetup
Definition: setup.cpp:18
PSETUPDATA pSetupData
Definition: setup.cpp:21
HINSTANCE hInstance
Definition: reactos.h:114
HFONT hBoldFont
Definition: syssetup.h:37
UINT uPostNetworkWizardPage
Definition: syssetup.h:59
UINT uFirstNetworkWizardPage
Definition: syssetup.h:58
BOOL UnattendSetup
Definition: syssetup.h:46
UINT code
Definition: winuser.h:3159
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
int32_t INT_PTR
Definition: typedefs.h:64
uint32_t DWORD_PTR
Definition: typedefs.h:65
int32_t INT
Definition: typedefs.h:58
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define MAKELPARAM(l, h)
Definition: winuser.h:4008
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1739
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define BM_SETCHECK
Definition: winuser.h:1921
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define MB_ICONERROR
Definition: winuser.h:787
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
HWND WINAPI SetFocus(_In_opt_ HWND)
#define WM_SETFONT
Definition: winuser.h:1650
struct tagNMHDR * LPNMHDR
#define MB_OK
Definition: winuser.h:790
HWND WINAPI GetParent(_In_ HWND)
#define DWLP_MSGRESULT
Definition: winuser.h:870
#define WM_DESTROY
Definition: winuser.h:1609
#define SendDlgItemMessage
Definition: winuser.h:5842
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define BST_CHECKED
Definition: winuser.h:197
__wchar_t WCHAR
Definition: xmlstorage.h:180