f031a7d8fad872ee3a138357016c8499a62bfc72
[reactos.git] / reactos / lib / syssetup / wizard.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: wizard.c,v 1.6 2004/08/28 11:08:50 ekohl Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * PURPOSE: System setup
24 * FILE: lib/syssetup/wizard.c
25 * PROGRAMER: Eric Kohl
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include <windows.h>
31 #include <commctrl.h>
32
33 #include <string.h>
34 #include <tchar.h>
35 #include <setupapi.h>
36
37 #include <syssetup.h>
38
39
40 #include "globals.h"
41 #include "resource.h"
42
43
44 /* GLOBALS ******************************************************************/
45
46 static SETUPDATA SetupData;
47
48
49 /* FUNCTIONS ****************************************************************/
50
51 static VOID
52 CenterWindow(HWND hWnd)
53 {
54 HWND hWndParent;
55 RECT rcParent;
56 RECT rcWindow;
57
58 hWndParent = GetParent(hWnd);
59 if (hWndParent == NULL)
60 hWndParent = GetDesktopWindow();
61
62 GetWindowRect(hWndParent, &rcParent);
63 GetWindowRect(hWnd, &rcWindow);
64
65 SetWindowPos(hWnd,
66 HWND_TOP,
67 ((rcParent.right - rcParent.left) - (rcWindow.right - rcWindow.left)) / 2,
68 ((rcParent.bottom - rcParent.top) - (rcWindow.bottom - rcWindow.top)) / 2,
69 0,
70 0,
71 SWP_NOSIZE);
72 }
73
74
75 BOOL CALLBACK
76 WelcomeDlgProc(HWND hwndDlg,
77 UINT uMsg,
78 WPARAM wParam,
79 LPARAM lParam)
80 {
81 switch (uMsg)
82 {
83 case WM_INITDIALOG:
84 {
85 HWND hwndControl;
86 DWORD dwStyle;
87
88 hwndControl = GetParent(hwndDlg);
89
90 /* Center the wizard window */
91 CenterWindow (hwndControl);
92
93 /* Hide the system menu */
94 dwStyle = GetWindowLong(hwndControl, GWL_STYLE);
95 SetWindowLong(hwndControl, GWL_STYLE, dwStyle & ~WS_SYSMENU);
96
97 /* Hide and disable the 'Cancel' button */
98 hwndControl = GetDlgItem(GetParent(hwndDlg), IDCANCEL);
99 ShowWindow (hwndControl, SW_HIDE);
100 EnableWindow (hwndControl, FALSE);
101 }
102 break;
103
104
105 case WM_NOTIFY:
106 {
107 LPNMHDR lpnm = (LPNMHDR)lParam;
108
109 switch (lpnm->code)
110 {
111 case PSN_SETACTIVE:
112 /* Enable the Next button */
113 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
114 break;
115
116 default:
117 break;
118 }
119 }
120 break;
121
122 default:
123 break;
124 }
125
126 return FALSE;
127 }
128
129
130 BOOL CALLBACK
131 OwnerPageDlgProc(HWND hwndDlg,
132 UINT uMsg,
133 WPARAM wParam,
134 LPARAM lParam)
135 {
136 TCHAR OwnerName[51];
137 TCHAR OwnerOrganization[51];
138 HKEY hKey;
139 LPNMHDR lpnm;
140
141 switch (uMsg)
142 {
143 case WM_INITDIALOG:
144 {
145 SendDlgItemMessage(hwndDlg, IDC_OWNERNAME, EM_LIMITTEXT, 50, 0);
146 SendDlgItemMessage(hwndDlg, IDC_OWNERORGANIZATION, EM_LIMITTEXT, 50, 0);
147
148 /* Set focus to owner name */
149 SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
150 }
151 break;
152
153
154 case WM_NOTIFY:
155 {
156 lpnm = (LPNMHDR)lParam;
157
158 switch (lpnm->code)
159 {
160 case PSN_SETACTIVE:
161 /* Enable the Back and Next buttons */
162 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
163 break;
164
165 case PSN_WIZNEXT:
166 OwnerName[0] = 0;
167 if (GetDlgItemText(hwndDlg, IDC_OWNERNAME, OwnerName, 50) == 0)
168 {
169 MessageBox(hwndDlg,
170 _T("Setup cannot continue until you enter your name."),
171 _T("ReactOS Setup"),
172 MB_ICONERROR | MB_OK);
173 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
174 return TRUE;
175 }
176
177 OwnerOrganization[0] = 0;
178 GetDlgItemText(hwndDlg, IDC_OWNERORGANIZATION, OwnerOrganization, 50);
179
180 RegOpenKeyEx(HKEY_LOCAL_MACHINE,
181 _T("Software\\Microsoft\\Windows NT\\CurrentVersion"),
182 0,
183 KEY_ALL_ACCESS,
184 &hKey);
185 /* FIXME: check error code */
186
187 RegSetValueEx(hKey,
188 _T("RegisteredOwner"),
189 0,
190 REG_SZ,
191 OwnerName,
192 (_tcslen(OwnerName) + 1) * sizeof(TCHAR));
193 /* FIXME: check error code */
194
195 RegSetValueEx(hKey,
196 _T("RegisteredOrganization"),
197 0,
198 REG_SZ,
199 OwnerOrganization,
200 (_tcslen(OwnerOrganization) + 1) * sizeof(TCHAR));
201 /* FIXME: check error code */
202
203 RegCloseKey(hKey);
204 break;
205
206 default:
207 break;
208 }
209 }
210 break;
211
212 default:
213 break;
214 }
215
216 return FALSE;
217 }
218
219
220 BOOL CALLBACK
221 ComputerPageDlgProc(HWND hwndDlg,
222 UINT uMsg,
223 WPARAM wParam,
224 LPARAM lParam)
225 {
226 TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
227 TCHAR Password1[15];
228 TCHAR Password2[15];
229 DWORD Length;
230 LPNMHDR lpnm;
231
232 switch (uMsg)
233 {
234 case WM_INITDIALOG:
235 {
236 /* Retrieve current computer name */
237 Length = MAX_COMPUTERNAME_LENGTH + 1;
238 GetComputerName(ComputerName, &Length);
239
240 /* Display current computer name */
241 SetDlgItemText(hwndDlg, IDC_COMPUTERNAME, ComputerName);
242
243 /* Set text limits */
244 SendDlgItemMessage(hwndDlg, IDC_COMPUTERNAME, EM_LIMITTEXT, 64, 0);
245 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD1, EM_LIMITTEXT, 14, 0);
246 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD2, EM_LIMITTEXT, 14, 0);
247
248 /* Set focus to computer name */
249 SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
250 }
251 break;
252
253
254 case WM_NOTIFY:
255 {
256 lpnm = (LPNMHDR)lParam;
257
258 switch (lpnm->code)
259 {
260 case PSN_SETACTIVE:
261 /* Enable the Back and Next buttons */
262 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
263 break;
264
265 case PSN_WIZNEXT:
266 if (GetDlgItemText(hwndDlg, IDC_COMPUTERNAME, ComputerName, 64) == 0)
267 {
268 MessageBox(hwndDlg,
269 _T("Setup cannot continue until you enter the name of your computer."),
270 _T("ReactOS Setup"),
271 MB_ICONERROR | MB_OK);
272 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
273 return TRUE;
274 }
275
276 /* FIXME: check computer name for invalid characters */
277
278 if (!SetComputerName(ComputerName))
279 {
280 MessageBox(hwndDlg,
281 _T("Setup failed to set the computer name."),
282 _T("ReactOS Setup"),
283 MB_ICONERROR | MB_OK);
284 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
285 return TRUE;
286 }
287
288 /* Check admin passwords */
289 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD1, Password1, 15);
290 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD2, Password2, 15);
291 if (_tcscmp(Password1, Password2))
292 {
293 MessageBox(hwndDlg,
294 _T("The passwords you entered do not match. Please enter "\
295 "the desired password again."),
296 _T("ReactOS Setup"),
297 MB_ICONERROR | MB_OK);
298 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
299 return TRUE;
300 }
301
302 /* FIXME: check password for invalid characters */
303
304 /* FIXME: Set admin password */
305 break;
306
307 default:
308 break;
309 }
310 }
311 break;
312
313 default:
314 break;
315 }
316
317 return FALSE;
318 }
319
320
321 BOOL CALLBACK
322 LocalePageDlgProc(HWND hwndDlg,
323 UINT uMsg,
324 WPARAM wParam,
325 LPARAM lParam)
326 {
327 PSETUPDATA SetupData;
328
329 /* Retrieve pointer to the global setup data */
330 SetupData = (PSETUPDATA)GetWindowLong (hwndDlg, GWL_USERDATA);
331
332 switch (uMsg)
333 {
334 case WM_INITDIALOG:
335 {
336 /* Save pointer to the global setup data */
337 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
338 SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)SetupData);
339
340 }
341 break;
342
343
344 case WM_NOTIFY:
345 {
346 LPNMHDR lpnm = (LPNMHDR)lParam;
347
348 switch (lpnm->code)
349 {
350 case PSN_SETACTIVE:
351 /* Enable the Back and Next buttons */
352 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
353 break;
354
355 case PSN_WIZNEXT:
356 break;
357
358 default:
359 break;
360 }
361 }
362 break;
363
364 default:
365 break;
366 }
367
368 return FALSE;
369 }
370
371
372 BOOL CALLBACK
373 FinishDlgProc(HWND hwndDlg,
374 UINT uMsg,
375 WPARAM wParam,
376 LPARAM lParam)
377 {
378
379 switch (uMsg)
380 {
381 case WM_INITDIALOG:
382 break;
383
384 case WM_NOTIFY:
385 {
386 LPNMHDR lpnm = (LPNMHDR)lParam;
387
388 switch (lpnm->code)
389 {
390 case PSN_SETACTIVE:
391 /* Enable the correct buttons on for the active page */
392 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
393 break;
394
395 case PSN_WIZBACK:
396 /* Handle a Back button click, if necessary */
397 break;
398
399 case PSN_WIZFINISH:
400 /* Handle a Finish button click, if necessary */
401 break;
402
403 default:
404 break;
405 }
406 }
407 break;
408
409 default:
410 break;
411 }
412
413 return FALSE;
414 }
415
416
417 VOID
418 InstallWizard(VOID)
419 {
420 PROPSHEETHEADER psh;
421 HPROPSHEETPAGE ahpsp[5];
422 PROPSHEETPAGE psp;
423 // SHAREDWIZDATA wizdata;
424
425 /* Clear setup data */
426 ZeroMemory(&SetupData, sizeof(SETUPDATA));
427
428 /* Create the Welcome page */
429 ZeroMemory (&psp, sizeof(PROPSHEETPAGE));
430 psp.dwSize = sizeof(PROPSHEETPAGE);
431 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
432 psp.hInstance = hDllInstance;
433 psp.lParam = (LPARAM)&SetupData;
434 psp.pfnDlgProc = WelcomeDlgProc;
435 psp.pszTemplate = MAKEINTRESOURCE(IDD_WELCOMEPAGE);
436 ahpsp[0] = CreatePropertySheetPage(&psp);
437
438 /* Create the Owner page */
439 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
440 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_OWNERTITLE);
441 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_OWNERSUBTITLE);
442 psp.pszTemplate = MAKEINTRESOURCE(IDD_OWNERPAGE);
443 psp.pfnDlgProc = OwnerPageDlgProc;
444 ahpsp[1] = CreatePropertySheetPage(&psp);
445
446 /* Create the Computer page */
447 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
448 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_COMPUTERTITLE);
449 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE);
450 psp.pfnDlgProc = ComputerPageDlgProc;
451 psp.pszTemplate = MAKEINTRESOURCE(IDD_COMPUTERPAGE);
452 ahpsp[2] = CreatePropertySheetPage(&psp);
453
454
455 /* Create the Locale page */
456 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
457 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_LOCALETITLE);
458 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_LOCALESUBTITLE);
459 psp.pfnDlgProc = LocalePageDlgProc;
460 psp.pszTemplate = MAKEINTRESOURCE(IDD_LOCALEPAGE);
461 ahpsp[3] = CreatePropertySheetPage(&psp);
462
463
464 /* Create the Finish page */
465 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
466 psp.pfnDlgProc = FinishDlgProc;
467 psp.pszTemplate = MAKEINTRESOURCE(IDD_FINISHPAGE);
468 ahpsp[4] = CreatePropertySheetPage(&psp);
469
470 /* Create the property sheet */
471 psh.dwSize = sizeof(PROPSHEETHEADER);
472 psh.dwFlags = PSH_WIZARD; //97 | PSH_WATERMARK | PSH_HEADER;
473 psh.hInstance = hDllInstance;
474 psh.hwndParent = NULL;
475 psh.nPages = 5;
476 psh.nStartPage = 0;
477 psh.phpage = ahpsp;
478 // psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
479 // psh.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
480
481 /* Display the wizard */
482 PropertySheet(&psh);
483 }
484
485 /* EOF */