[SYSSETUP][UNATTENDED] Add a way to disable Gecko install. Brought to you by V.
[reactos.git] / reactos / dll / win32 / syssetup / wizard.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: System setup
4 * FILE: dll/win32/syssetup/wizard.c
5 * PURPOSE: GUI controls
6 * PROGRAMMERS: Eric Kohl
7 * Pierre Schweitzer <heis_spiter@hotmail.com>
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include "precomp.h"
13
14 #include <stdlib.h>
15 #include <time.h>
16 #include <winnls.h>
17 #include <windowsx.h>
18
19 #define NDEBUG
20 #include <debug.h>
21
22 #undef VMWINST
23
24 #define PM_REGISTRATION_NOTIFY (WM_APP + 1)
25 /* Private Message used to communicate progress from the background
26 registration thread to the main thread.
27 wParam = 0 Registration in progress
28 = 1 Registration completed
29 lParam = Pointer to a REGISTRATIONNOTIFY structure */
30
31 typedef struct _REGISTRATIONNOTIFY
32 {
33 ULONG Progress;
34 UINT ActivityID;
35 LPCWSTR CurrentItem;
36 LPCWSTR ErrorMessage;
37 } REGISTRATIONNOTIFY, *PREGISTRATIONNOTIFY;
38
39 typedef struct _REGISTRATIONDATA
40 {
41 HWND hwndDlg;
42 ULONG DllCount;
43 ULONG Registered;
44 PVOID DefaultContext;
45 } REGISTRATIONDATA, *PREGISTRATIONDATA;
46
47 /* GLOBALS ******************************************************************/
48
49 SETUPDATA SetupData;
50
51
52 /* FUNCTIONS ****************************************************************/
53
54 extern void WINAPI Control_RunDLLW(HWND hWnd, HINSTANCE hInst, LPCWSTR cmd, DWORD nCmdShow);
55
56 BOOL
57 GetRosInstallCD(WCHAR *pwszPath, DWORD cchPathMax);
58
59 #ifdef VMWINST
60 static BOOL
61 RunVMWInstall(HWND hWnd)
62 {
63 PROCESS_INFORMATION ProcInfo;
64 MSG msg;
65 DWORD ret;
66 STARTUPINFOW si;
67 WCHAR InstallName[] = L"vmwinst.exe";
68
69 ZeroMemory(&si, sizeof(si));
70 si.cb = sizeof(si);
71
72 if(CreateProcessW(NULL, InstallName, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
73 NULL, NULL, &si, &ProcInfo))
74 {
75 EnableWindow(hWnd, FALSE);
76 for (;;)
77 {
78 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
79 {
80 if (msg.message == WM_QUIT)
81 goto done;
82 TranslateMessage(&msg);
83 DispatchMessage(&msg);
84 }
85
86 ret = MsgWaitForMultipleObjects(1, &ProcInfo.hProcess, FALSE, INFINITE, QS_ALLEVENTS | QS_ALLINPUT);
87 if (ret == WAIT_OBJECT_0)
88 break;
89 }
90 done:
91 EnableWindow(hWnd, TRUE);
92
93 CloseHandle(ProcInfo.hThread);
94 CloseHandle(ProcInfo.hProcess);
95 return TRUE;
96 }
97 return FALSE;
98 }
99 #endif
100
101 static VOID
102 CenterWindow(HWND hWnd)
103 {
104 HWND hWndParent;
105 RECT rcParent;
106 RECT rcWindow;
107
108 hWndParent = GetParent(hWnd);
109 if (hWndParent == NULL)
110 hWndParent = GetDesktopWindow();
111
112 GetWindowRect(hWndParent, &rcParent);
113 GetWindowRect(hWnd, &rcWindow);
114
115 SetWindowPos(hWnd,
116 HWND_TOP,
117 ((rcParent.right - rcParent.left) - (rcWindow.right - rcWindow.left)) / 2,
118 ((rcParent.bottom - rcParent.top) - (rcWindow.bottom - rcWindow.top)) / 2,
119 0,
120 0,
121 SWP_NOSIZE);
122 }
123
124
125 static HFONT
126 CreateTitleFont(VOID)
127 {
128 NONCLIENTMETRICSW ncm;
129 LOGFONTW LogFont;
130 HDC hdc;
131 INT FontSize;
132 HFONT hFont;
133
134 ncm.cbSize = sizeof(NONCLIENTMETRICSW);
135 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
136
137 LogFont = ncm.lfMessageFont;
138 LogFont.lfWeight = FW_BOLD;
139 wcscpy(LogFont.lfFaceName, L"MS Shell Dlg");
140
141 hdc = GetDC(NULL);
142 FontSize = 12;
143 LogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72;
144 hFont = CreateFontIndirectW(&LogFont);
145 ReleaseDC(NULL, hdc);
146
147 return hFont;
148 }
149
150
151 static INT_PTR CALLBACK
152 GplDlgProc(HWND hwndDlg,
153 UINT uMsg,
154 WPARAM wParam,
155 LPARAM lParam)
156 {
157 HRSRC GplTextResource;
158 HGLOBAL GplTextMem;
159 PVOID GplTextLocked;
160 PCHAR GplText;
161 DWORD Size;
162
163
164 switch (uMsg)
165 {
166 case WM_INITDIALOG:
167 GplTextResource = FindResourceW(hDllInstance, MAKEINTRESOURCE(IDR_GPL), L"RT_TEXT");
168 if (NULL == GplTextResource)
169 {
170 break;
171 }
172 Size = SizeofResource(hDllInstance, GplTextResource);
173 if (0 == Size)
174 {
175 break;
176 }
177 GplText = HeapAlloc(GetProcessHeap(), 0, Size + 1);
178 if (NULL == GplText)
179 {
180 break;
181 }
182 GplTextMem = LoadResource(hDllInstance, GplTextResource);
183 if (NULL == GplTextMem)
184 {
185 HeapFree(GetProcessHeap(), 0, GplText);
186 break;
187 }
188 GplTextLocked = LockResource(GplTextMem);
189 if (NULL == GplTextLocked)
190 {
191 HeapFree(GetProcessHeap(), 0, GplText);
192 break;
193 }
194 memcpy(GplText, GplTextLocked, Size);
195 GplText[Size] = '\0';
196 SendMessageA(GetDlgItem(hwndDlg, IDC_GPL_TEXT), WM_SETTEXT, 0, (LPARAM) GplText);
197 HeapFree(GetProcessHeap(), 0, GplText);
198 SetFocus(GetDlgItem(hwndDlg, IDOK));
199 return FALSE;
200
201 case WM_CLOSE:
202 EndDialog(hwndDlg, IDCANCEL);
203 break;
204
205 case WM_COMMAND:
206 if (HIWORD(wParam) == BN_CLICKED && IDOK == LOWORD(wParam))
207 {
208 EndDialog(hwndDlg, IDOK);
209 }
210 break;
211
212 default:
213 break;
214 }
215
216 return FALSE;
217 }
218
219
220 static INT_PTR CALLBACK
221 WelcomeDlgProc(HWND hwndDlg,
222 UINT uMsg,
223 WPARAM wParam,
224 LPARAM lParam)
225 {
226 switch (uMsg)
227 {
228 case WM_INITDIALOG:
229 {
230 PSETUPDATA SetupData;
231 HWND hwndControl;
232 DWORD dwStyle;
233
234 /* Get pointer to the global setup data */
235 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
236
237 hwndControl = GetParent(hwndDlg);
238
239 /* Center the wizard window */
240 CenterWindow (hwndControl);
241
242 /* Hide the system menu */
243 dwStyle = GetWindowLongPtr(hwndControl, GWL_STYLE);
244 SetWindowLongPtr(hwndControl, GWL_STYLE, dwStyle & ~WS_SYSMENU);
245
246 /* Hide and disable the 'Cancel' button */
247 hwndControl = GetDlgItem(GetParent(hwndDlg), IDCANCEL);
248 ShowWindow (hwndControl, SW_HIDE);
249 EnableWindow (hwndControl, FALSE);
250
251 /* Set title font */
252 SendDlgItemMessage(hwndDlg,
253 IDC_WELCOMETITLE,
254 WM_SETFONT,
255 (WPARAM)SetupData->hTitleFont,
256 (LPARAM)TRUE);
257 }
258 break;
259
260
261 case WM_NOTIFY:
262 {
263 LPNMHDR lpnm = (LPNMHDR)lParam;
264
265 switch (lpnm->code)
266 {
267 case PSN_SETACTIVE:
268 /* Enable the Next button */
269 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
270 if (SetupData.UnattendSetup)
271 {
272 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_ACKPAGE);
273 return TRUE;
274 }
275 break;
276
277 case PSN_WIZBACK:
278 SetupData.UnattendSetup = FALSE;
279 break;
280
281 default:
282 break;
283 }
284 }
285 break;
286
287 default:
288 break;
289 }
290
291 return FALSE;
292 }
293
294
295 static INT_PTR CALLBACK
296 AckPageDlgProc(HWND hwndDlg,
297 UINT uMsg,
298 WPARAM wParam,
299 LPARAM lParam)
300 {
301 LPNMHDR lpnm;
302 PWCHAR Projects;
303 PWCHAR End, CurrentProject;
304 INT ProjectsSize, ProjectsCount;
305
306 switch (uMsg)
307 {
308 case WM_INITDIALOG:
309 {
310 Projects = NULL;
311 ProjectsSize = 256;
312 do
313 {
314 Projects = HeapAlloc(GetProcessHeap(), 0, ProjectsSize * sizeof(WCHAR));
315 if (NULL == Projects)
316 {
317 return FALSE;
318 }
319 ProjectsCount = LoadStringW(hDllInstance, IDS_ACKPROJECTS, Projects, ProjectsSize);
320 if (0 == ProjectsCount)
321 {
322 HeapFree(GetProcessHeap(), 0, Projects);
323 return FALSE;
324 }
325 if (ProjectsCount < ProjectsSize - 1)
326 {
327 break;
328 }
329 HeapFree(GetProcessHeap(), 0, Projects);
330 ProjectsSize *= 2;
331 }
332 while (1);
333 CurrentProject = Projects;
334 while (L'\0' != *CurrentProject)
335 {
336 End = wcschr(CurrentProject, L'\n');
337 if (NULL != End)
338 {
339 *End = L'\0';
340 }
341 (void)ListBox_AddString(GetDlgItem(hwndDlg, IDC_PROJECTS), CurrentProject);
342 if (NULL != End)
343 {
344 CurrentProject = End + 1;
345 }
346 else
347 {
348 CurrentProject += wcslen(CurrentProject);
349 }
350 }
351 HeapFree(GetProcessHeap(), 0, Projects);
352 }
353 break;
354
355 case WM_COMMAND:
356 if (HIWORD(wParam) == BN_CLICKED && IDC_VIEWGPL == LOWORD(wParam))
357 {
358 DialogBox(hDllInstance, MAKEINTRESOURCE(IDD_GPL), NULL, GplDlgProc);
359 SetForegroundWindow(GetParent(hwndDlg));
360 }
361 break;
362
363 case WM_NOTIFY:
364 {
365 lpnm = (LPNMHDR)lParam;
366
367 switch (lpnm->code)
368 {
369 case PSN_SETACTIVE:
370 /* Enable the Back and Next buttons */
371 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
372 if (SetupData.UnattendSetup)
373 {
374 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_LOCALEPAGE);
375 return TRUE;
376 }
377 break;
378
379 case PSN_WIZBACK:
380 SetupData.UnattendSetup = FALSE;
381 break;
382
383 default:
384 break;
385 }
386 }
387 break;
388
389 default:
390 break;
391 }
392
393 return FALSE;
394 }
395
396 static
397 BOOL
398 WriteOwnerSettings(WCHAR * OwnerName,
399 WCHAR * OwnerOrganization)
400 {
401 HKEY hKey;
402 LONG res;
403
404
405
406 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
407 L"Software\\Microsoft\\Windows NT\\CurrentVersion",
408 0,
409 KEY_ALL_ACCESS,
410 &hKey);
411
412 if (res != ERROR_SUCCESS)
413 {
414 return FALSE;
415 }
416
417 res = RegSetValueExW(hKey,
418 L"RegisteredOwner",
419 0,
420 REG_SZ,
421 (LPBYTE)OwnerName,
422 (wcslen(OwnerName) + 1) * sizeof(WCHAR));
423
424 if (res != ERROR_SUCCESS)
425 {
426 RegCloseKey(hKey);
427 return FALSE;
428 }
429
430 res = RegSetValueExW(hKey,
431 L"RegisteredOrganization",
432 0,
433 REG_SZ,
434 (LPBYTE)OwnerOrganization,
435 (wcslen(OwnerOrganization) + 1) * sizeof(WCHAR));
436
437 RegCloseKey(hKey);
438 return (res == ERROR_SUCCESS);
439 }
440
441 static INT_PTR CALLBACK
442 OwnerPageDlgProc(HWND hwndDlg,
443 UINT uMsg,
444 WPARAM wParam,
445 LPARAM lParam)
446 {
447 WCHAR OwnerName[51];
448 WCHAR OwnerOrganization[51];
449 WCHAR Title[64];
450 WCHAR ErrorName[256];
451 LPNMHDR lpnm;
452
453 switch (uMsg)
454 {
455 case WM_INITDIALOG:
456 {
457 SendDlgItemMessage(hwndDlg, IDC_OWNERNAME, EM_LIMITTEXT, 50, 0);
458 SendDlgItemMessage(hwndDlg, IDC_OWNERORGANIZATION, EM_LIMITTEXT, 50, 0);
459
460 /* Set focus to owner name */
461 SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
462 }
463 break;
464
465
466 case WM_NOTIFY:
467 {
468 lpnm = (LPNMHDR)lParam;
469
470 switch (lpnm->code)
471 {
472 case PSN_SETACTIVE:
473 /* Enable the Back and Next buttons */
474 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
475 if (SetupData.UnattendSetup)
476 {
477 SendMessage(GetDlgItem(hwndDlg, IDC_OWNERNAME), WM_SETTEXT, 0, (LPARAM)SetupData.OwnerName);
478 SendMessage(GetDlgItem(hwndDlg, IDC_OWNERORGANIZATION), WM_SETTEXT, 0, (LPARAM)SetupData.OwnerOrganization);
479 if (WriteOwnerSettings(SetupData.OwnerName, SetupData.OwnerOrganization))
480 {
481 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_COMPUTERPAGE);
482 return TRUE;
483 }
484 }
485 break;
486
487 case PSN_WIZNEXT:
488 OwnerName[0] = 0;
489 if (GetDlgItemTextW(hwndDlg, IDC_OWNERNAME, OwnerName, 50) == 0)
490 {
491 if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
492 {
493 wcscpy(Title, L"ReactOS Setup");
494 }
495 if (0 == LoadStringW(hDllInstance, IDS_WZD_NAME, ErrorName, sizeof(ErrorName) / sizeof(ErrorName[0])))
496 {
497 wcscpy(ErrorName, L"Setup cannot continue until you enter your name.");
498 }
499 MessageBoxW(hwndDlg, ErrorName, Title, MB_ICONERROR | MB_OK);
500
501 SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
502 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
503
504 return TRUE;
505 }
506
507 OwnerOrganization[0] = 0;
508 GetDlgItemTextW(hwndDlg, IDC_OWNERORGANIZATION, OwnerOrganization, 50);
509
510 if (!WriteOwnerSettings(OwnerName, OwnerOrganization))
511 {
512 SetFocus(GetDlgItem(hwndDlg, IDC_OWNERNAME));
513 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
514 return TRUE;
515 }
516
517 case PSN_WIZBACK:
518 SetupData.UnattendSetup = FALSE;
519 break;
520
521 default:
522 break;
523 }
524 }
525 break;
526
527 default:
528 break;
529 }
530
531 return FALSE;
532 }
533
534 static
535 BOOL
536 WriteComputerSettings(WCHAR * ComputerName, HWND hwndDlg)
537 {
538 WCHAR Title[64];
539 WCHAR ErrorComputerName[256];
540
541 if (!SetComputerNameW(ComputerName))
542 {
543 if (hwndDlg != NULL)
544 {
545 if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
546 {
547 wcscpy(Title, L"ReactOS Setup");
548 }
549 if (0 == LoadStringW(hDllInstance, IDS_WZD_SETCOMPUTERNAME, ErrorComputerName,
550 sizeof(ErrorComputerName) / sizeof(ErrorComputerName[0])))
551 {
552 wcscpy(ErrorComputerName, L"Setup failed to set the computer name.");
553 }
554 MessageBoxW(hwndDlg, ErrorComputerName, Title, MB_ICONERROR | MB_OK);
555 }
556
557 return FALSE;
558 }
559
560 /* Try to also set DNS hostname */
561 SetComputerNameExW(ComputerNamePhysicalDnsHostname, ComputerName);
562
563 /* Set the account domain name */
564 SetAccountDomain(ComputerName, NULL);
565
566 return TRUE;
567 }
568
569
570 static
571 BOOL
572 WriteDefaultLogonData(LPWSTR Domain)
573 {
574 WCHAR szAdministratorName[256];
575 HKEY hKey = NULL;
576 LONG lError;
577
578 if (LoadStringW(hDllInstance,
579 IDS_ADMINISTRATOR_NAME,
580 szAdministratorName,
581 sizeof(szAdministratorName) / sizeof(WCHAR)) == 0)
582 {
583 wcscpy(szAdministratorName, L"Administrator");
584 }
585
586 lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
587 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
588 0,
589 KEY_SET_VALUE,
590 &hKey);
591 if (lError != ERROR_SUCCESS)
592 return FALSE;
593
594 lError = RegSetValueEx(hKey,
595 L"DefaultDomain",
596 0,
597 REG_SZ,
598 (LPBYTE)Domain,
599 (wcslen(Domain)+ 1) * sizeof(WCHAR));
600 if (lError != ERROR_SUCCESS)
601 {
602 DPRINT1("RegSetValueEx(\"DefaultDomain\") failed!\n");
603 }
604
605 lError = RegSetValueEx(hKey,
606 L"DefaultUserName",
607 0,
608 REG_SZ,
609 (LPBYTE)szAdministratorName,
610 (wcslen(szAdministratorName)+ 1) * sizeof(WCHAR));
611 if (lError != ERROR_SUCCESS)
612 {
613 DPRINT1("RegSetValueEx(\"DefaultUserName\") failed!\n");
614 }
615
616 RegCloseKey(hKey);
617
618 return TRUE;
619 }
620
621
622 /* lpBuffer will be filled with a 15-char string (plus the null terminator) */
623 static void
624 GenerateComputerName(LPWSTR lpBuffer)
625 {
626 static const WCHAR Chars[] = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
627 static const unsigned cChars = sizeof(Chars) / sizeof(WCHAR) - 1;
628 unsigned i;
629
630 wcscpy(lpBuffer, L"REACTOS-");
631
632 srand(GetTickCount());
633
634 /* fill in 7 characters */
635 for (i = 8; i < 15; i++)
636 lpBuffer[i] = Chars[rand() % cChars];
637
638 lpBuffer[15] = UNICODE_NULL; /* NULL-terminate */
639 }
640
641 static INT_PTR CALLBACK
642 ComputerPageDlgProc(HWND hwndDlg,
643 UINT uMsg,
644 WPARAM wParam,
645 LPARAM lParam)
646 {
647 WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
648 WCHAR Password1[128];
649 WCHAR Password2[128];
650 PWCHAR Password;
651 WCHAR Title[64];
652 WCHAR EmptyComputerName[256], NotMatchPassword[256], WrongPassword[256];
653 LPNMHDR lpnm;
654
655 if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
656 {
657 wcscpy(Title, L"ReactOS Setup");
658 }
659
660 switch (uMsg)
661 {
662 case WM_INITDIALOG:
663 /* Generate a new pseudo-random computer name */
664 GenerateComputerName(ComputerName);
665
666 /* Display current computer name */
667 SetDlgItemTextW(hwndDlg, IDC_COMPUTERNAME, ComputerName);
668
669 /* Set text limits */
670 SendDlgItemMessage(hwndDlg, IDC_COMPUTERNAME, EM_LIMITTEXT, MAX_COMPUTERNAME_LENGTH, 0);
671 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD1, EM_LIMITTEXT, 127, 0);
672 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD2, EM_LIMITTEXT, 127, 0);
673
674 /* Set focus to computer name */
675 SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
676 if (SetupData.UnattendSetup)
677 {
678 SendMessage(GetDlgItem(hwndDlg, IDC_COMPUTERNAME), WM_SETTEXT, 0, (LPARAM)SetupData.ComputerName);
679 SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD1), WM_SETTEXT, 0, (LPARAM)SetupData.AdminPassword);
680 SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD2), WM_SETTEXT, 0, (LPARAM)SetupData.AdminPassword);
681 WriteComputerSettings(SetupData.ComputerName, NULL);
682 SetAdministratorPassword(SetupData.AdminPassword);
683 }
684
685 /* Store the administrator account name as the default user name */
686 WriteDefaultLogonData(SetupData.ComputerName);
687 break;
688
689
690 case WM_NOTIFY:
691 {
692 lpnm = (LPNMHDR)lParam;
693
694 switch (lpnm->code)
695 {
696 case PSN_SETACTIVE:
697 /* Enable the Back and Next buttons */
698 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
699 if (SetupData.UnattendSetup && WriteComputerSettings(SetupData.ComputerName, hwndDlg))
700 {
701 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_DATETIMEPAGE);
702 return TRUE;
703 }
704 break;
705
706 case PSN_WIZNEXT:
707 if (0 == GetDlgItemTextW(hwndDlg, IDC_COMPUTERNAME, ComputerName, MAX_COMPUTERNAME_LENGTH + 1))
708 {
709 if (0 == LoadStringW(hDllInstance, IDS_WZD_COMPUTERNAME, EmptyComputerName,
710 sizeof(EmptyComputerName) / sizeof(EmptyComputerName[0])))
711 {
712 wcscpy(EmptyComputerName, L"Setup cannot continue until you enter the name of your computer.");
713 }
714 MessageBoxW(hwndDlg, EmptyComputerName, Title, MB_ICONERROR | MB_OK);
715 SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
716 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
717 return TRUE;
718 }
719
720 /* No need to check computer name for invalid characters,
721 * SetComputerName() will do it for us */
722
723 if (!WriteComputerSettings(ComputerName, hwndDlg))
724 {
725 SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
726 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
727 return TRUE;
728 }
729
730 #if 0
731 /* Check if admin passwords have been entered */
732 if ((GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD1, Password1, 128) == 0) ||
733 (GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD2, Password2, 128) == 0))
734 {
735 if (0 == LoadStringW(hDllInstance, IDS_WZD_PASSWORDEMPTY, EmptyPassword,
736 sizeof(EmptyPassword) / sizeof(EmptyPassword[0])))
737 {
738 wcscpy(EmptyPassword, L"You must enter a password !");
739 }
740 MessageBoxW(hwndDlg, EmptyPassword, Title, MB_ICONERROR | MB_OK);
741 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
742 return TRUE;
743 }
744 #else
745 GetDlgItemTextW(hwndDlg, IDC_ADMINPASSWORD1, Password1, 128);
746 GetDlgItemTextW(hwndDlg, IDC_ADMINPASSWORD2, Password2, 128);
747 #endif
748 /* Check if passwords match */
749 if (wcscmp(Password1, Password2))
750 {
751 if (0 == LoadStringW(hDllInstance, IDS_WZD_PASSWORDMATCH, NotMatchPassword,
752 sizeof(NotMatchPassword) / sizeof(NotMatchPassword[0])))
753 {
754 wcscpy(NotMatchPassword, L"The passwords you entered do not match. Please enter the desired password again.");
755 }
756 MessageBoxW(hwndDlg, NotMatchPassword, Title, MB_ICONERROR | MB_OK);
757 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
758 return TRUE;
759 }
760
761 /* Check password for invalid characters */
762 Password = (PWCHAR)Password1;
763 while (*Password)
764 {
765 if (!isprint(*Password))
766 {
767 if (0 == LoadStringW(hDllInstance, IDS_WZD_PASSWORDCHAR, WrongPassword,
768 sizeof(WrongPassword) / sizeof(WrongPassword[0])))
769 {
770 wcscpy(WrongPassword, L"The password you entered contains invalid characters. Please enter a cleaned password.");
771 }
772 MessageBoxW(hwndDlg, WrongPassword, Title, MB_ICONERROR | MB_OK);
773 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
774 return TRUE;
775 }
776 Password++;
777 }
778
779 /* Set admin password */
780 SetAdministratorPassword(Password1);
781 break;
782
783 case PSN_WIZBACK:
784 SetupData.UnattendSetup = FALSE;
785 break;
786
787 default:
788 break;
789 }
790 }
791 break;
792
793 default:
794 break;
795 }
796
797 return FALSE;
798 }
799
800
801 static VOID
802 SetKeyboardLayoutName(HWND hwnd)
803 {
804 #if 0
805 TCHAR szLayoutPath[256];
806 TCHAR szLocaleName[32];
807 DWORD dwLocaleSize;
808 HKEY hKey;
809
810 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
811 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
812 0,
813 KEY_ALL_ACCESS,
814 &hKey))
815 return;
816
817 dwValueSize = 16 * sizeof(TCHAR);
818 if (RegQueryValueEx(hKey,
819 NULL,
820 NULL,
821 NULL,
822 szLocaleName,
823 &dwLocaleSize))
824 {
825 RegCloseKey(hKey);
826 return;
827 }
828
829 _tcscpy(szLayoutPath,
830 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"));
831 _tcscat(szLayoutPath,
832 szLocaleName);
833
834 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
835 szLayoutPath,
836 0,
837 KEY_ALL_ACCESS,
838 &hKey))
839 return;
840
841 dwValueSize = 32 * sizeof(TCHAR);
842 if (RegQueryValueEx(hKey,
843 _T("Layout Text"),
844 NULL,
845 NULL,
846 szLocaleName,
847 &dwLocaleSize))
848 {
849 RegCloseKey(hKey);
850 return;
851 }
852
853 RegCloseKey(hKey);
854 #endif
855 }
856
857
858 static BOOL
859 RunControlPanelApplet(HWND hwnd, PCWSTR pwszCPLParameters)
860 {
861 if (pwszCPLParameters)
862 {
863 STARTUPINFOW StartupInfo;
864 PROCESS_INFORMATION ProcessInformation;
865 WCHAR CmdLine[MAX_PATH] = L"rundll32.exe shell32.dll,Control_RunDLL ";
866
867 ZeroMemory(&StartupInfo, sizeof(StartupInfo));
868 StartupInfo.cb = sizeof(StartupInfo);
869
870 ASSERT(_countof(CmdLine) > wcslen(CmdLine) + wcslen(pwszCPLParameters));
871 wcscat(CmdLine, pwszCPLParameters);
872
873 if (!CreateProcessW(NULL,
874 CmdLine,
875 NULL,
876 NULL,
877 FALSE,
878 0,
879 NULL,
880 NULL,
881 &StartupInfo,
882 &ProcessInformation))
883 {
884 MessageBoxW(hwnd, L"Error: Failed to launch the Control Panel Applet.", NULL, MB_ICONERROR);
885 return FALSE;
886 }
887
888 WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
889 CloseHandle(ProcessInformation.hThread);
890 CloseHandle(ProcessInformation.hProcess);
891 return TRUE;
892 }
893 else
894 {
895 MessageBoxW(hwnd, L"Error: Failed to launch the Control Panel Applet.", NULL, MB_ICONERROR);
896 return FALSE;
897 }
898 }
899
900 static VOID
901 WriteUserLocale(VOID)
902 {
903 HKEY hKey;
904 LCID lcid;
905 WCHAR Locale[12];
906
907 lcid = GetSystemDefaultLCID();
908
909 if (GetLocaleInfoW(MAKELCID(lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, Locale, sizeof(Locale) / sizeof(Locale[0])) != 0)
910 {
911 if (RegCreateKeyExW(HKEY_CURRENT_USER, L"Control Panel\\International",
912 0, NULL, REG_OPTION_NON_VOLATILE,
913 KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
914 {
915 RegSetValueExW(hKey, L"Locale", 0, REG_SZ, (LPBYTE)Locale, (wcslen(Locale) + 1) * sizeof(WCHAR));
916 RegCloseKey(hKey);
917 }
918 }
919 }
920
921 static INT_PTR CALLBACK
922 LocalePageDlgProc(HWND hwndDlg,
923 UINT uMsg,
924 WPARAM wParam,
925 LPARAM lParam)
926 {
927 PSETUPDATA SetupData;
928
929 /* Retrieve pointer to the global setup data */
930 SetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);
931
932 switch (uMsg)
933 {
934 case WM_INITDIALOG:
935 {
936 /* Save pointer to the global setup data */
937 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
938 SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)SetupData);
939 WriteUserLocale();
940
941 SetKeyboardLayoutName(GetDlgItem(hwndDlg, IDC_LAYOUTTEXT));
942 }
943 break;
944
945 case WM_COMMAND:
946 if (HIWORD(wParam) == BN_CLICKED)
947 {
948 switch (LOWORD(wParam))
949 {
950 case IDC_CUSTOMLOCALE:
951 RunControlPanelApplet(hwndDlg, L"intl.cpl,,5");
952 /* FIXME: Update input locale name */
953 break;
954
955 case IDC_CUSTOMLAYOUT:
956 RunControlPanelApplet(hwndDlg, L"input.dll,@1");
957 break;
958 }
959 }
960 break;
961
962 case WM_NOTIFY:
963 {
964 LPNMHDR lpnm = (LPNMHDR)lParam;
965
966 switch (lpnm->code)
967 {
968 case PSN_SETACTIVE:
969 /* Enable the Back and Next buttons */
970 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
971 if (SetupData->UnattendSetup)
972 {
973 WCHAR wszPath[MAX_PATH];
974 if (GetRosInstallCD(wszPath, _countof(wszPath)))
975 {
976 WCHAR wszParams[1024];
977 swprintf(wszParams, L"intl.cpl,,/f:\"%sreactos\\unattend.inf\"", wszPath);
978 RunControlPanelApplet(hwndDlg, wszParams);
979 }
980 else
981 {
982 RunControlPanelApplet(hwndDlg, L"intl.cpl,,/f:\"unattend.inf\"");
983 }
984
985 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_OWNERPAGE);
986 return TRUE;
987 }
988 break;
989
990 case PSN_WIZNEXT:
991 break;
992
993 case PSN_WIZBACK:
994 SetupData->UnattendSetup = FALSE;
995 break;
996
997 default:
998 break;
999 }
1000 }
1001 break;
1002
1003 default:
1004 break;
1005 }
1006
1007 return FALSE;
1008 }
1009
1010
1011 static PTIMEZONE_ENTRY
1012 GetLargerTimeZoneEntry(PSETUPDATA SetupData, DWORD Index)
1013 {
1014 PTIMEZONE_ENTRY Entry;
1015
1016 Entry = SetupData->TimeZoneListHead;
1017 while (Entry != NULL)
1018 {
1019 if (Entry->Index >= Index)
1020 return Entry;
1021
1022 Entry = Entry->Next;
1023 }
1024
1025 return NULL;
1026 }
1027
1028
1029 static VOID
1030 CreateTimeZoneList(PSETUPDATA SetupData)
1031 {
1032 WCHAR szKeyName[256];
1033 DWORD dwIndex;
1034 DWORD dwNameSize;
1035 DWORD dwValueSize;
1036 LONG lError;
1037 HKEY hZonesKey;
1038 HKEY hZoneKey;
1039
1040 PTIMEZONE_ENTRY Entry;
1041 PTIMEZONE_ENTRY Current;
1042
1043 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
1044 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1045 0,
1046 KEY_ALL_ACCESS,
1047 &hZonesKey))
1048 return;
1049
1050 dwIndex = 0;
1051 while (TRUE)
1052 {
1053 dwNameSize = 256 * sizeof(WCHAR);
1054 lError = RegEnumKeyExW(hZonesKey,
1055 dwIndex,
1056 szKeyName,
1057 &dwNameSize,
1058 NULL,
1059 NULL,
1060 NULL,
1061 NULL);
1062 if (lError != ERROR_SUCCESS && lError != ERROR_MORE_DATA)
1063 break;
1064
1065 if (RegOpenKeyExW(hZonesKey,
1066 szKeyName,
1067 0,
1068 KEY_ALL_ACCESS,
1069 &hZoneKey))
1070 break;
1071
1072 Entry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TIMEZONE_ENTRY));
1073 if (Entry == NULL)
1074 {
1075 RegCloseKey(hZoneKey);
1076 break;
1077 }
1078
1079 dwValueSize = 64 * sizeof(WCHAR);
1080 if (RegQueryValueExW(hZoneKey,
1081 L"Display",
1082 NULL,
1083 NULL,
1084 (LPBYTE)&Entry->Description,
1085 &dwValueSize))
1086 {
1087 RegCloseKey(hZoneKey);
1088 break;
1089 }
1090
1091 dwValueSize = 32 * sizeof(WCHAR);
1092 if (RegQueryValueExW(hZoneKey,
1093 L"Std",
1094 NULL,
1095 NULL,
1096 (LPBYTE)&Entry->StandardName,
1097 &dwValueSize))
1098 {
1099 RegCloseKey(hZoneKey);
1100 break;
1101 }
1102
1103 dwValueSize = 32 * sizeof(WCHAR);
1104 if (RegQueryValueExW(hZoneKey,
1105 L"Dlt",
1106 NULL,
1107 NULL,
1108 (LPBYTE)&Entry->DaylightName,
1109 &dwValueSize))
1110 {
1111 RegCloseKey(hZoneKey);
1112 break;
1113 }
1114
1115 dwValueSize = sizeof(DWORD);
1116 if (RegQueryValueExW(hZoneKey,
1117 L"Index",
1118 NULL,
1119 NULL,
1120 (LPBYTE)&Entry->Index,
1121 &dwValueSize))
1122 {
1123 RegCloseKey(hZoneKey);
1124 break;
1125 }
1126
1127 dwValueSize = sizeof(TZ_INFO);
1128 if (RegQueryValueExW(hZoneKey,
1129 L"TZI",
1130 NULL,
1131 NULL,
1132 (LPBYTE)&Entry->TimezoneInfo,
1133 &dwValueSize))
1134 {
1135 RegCloseKey(hZoneKey);
1136 break;
1137 }
1138
1139 RegCloseKey(hZoneKey);
1140
1141 if (SetupData->TimeZoneListHead == NULL &&
1142 SetupData->TimeZoneListTail == NULL)
1143 {
1144 Entry->Prev = NULL;
1145 Entry->Next = NULL;
1146 SetupData->TimeZoneListHead = Entry;
1147 SetupData->TimeZoneListTail = Entry;
1148 }
1149 else
1150 {
1151 Current = GetLargerTimeZoneEntry(SetupData, Entry->Index);
1152 if (Current != NULL)
1153 {
1154 if (Current == SetupData->TimeZoneListHead)
1155 {
1156 /* Prepend to head */
1157 Entry->Prev = NULL;
1158 Entry->Next = SetupData->TimeZoneListHead;
1159 SetupData->TimeZoneListHead->Prev = Entry;
1160 SetupData->TimeZoneListHead = Entry;
1161 }
1162 else
1163 {
1164 /* Insert before current */
1165 Entry->Prev = Current->Prev;
1166 Entry->Next = Current;
1167 Current->Prev->Next = Entry;
1168 Current->Prev = Entry;
1169 }
1170 }
1171 else
1172 {
1173 /* Append to tail */
1174 Entry->Prev = SetupData->TimeZoneListTail;
1175 Entry->Next = NULL;
1176 SetupData->TimeZoneListTail->Next = Entry;
1177 SetupData->TimeZoneListTail = Entry;
1178 }
1179 }
1180
1181 dwIndex++;
1182 }
1183
1184 RegCloseKey(hZonesKey);
1185 }
1186
1187
1188 static VOID
1189 DestroyTimeZoneList(PSETUPDATA SetupData)
1190 {
1191 PTIMEZONE_ENTRY Entry;
1192
1193 while (SetupData->TimeZoneListHead != NULL)
1194 {
1195 Entry = SetupData->TimeZoneListHead;
1196
1197 SetupData->TimeZoneListHead = Entry->Next;
1198 if (SetupData->TimeZoneListHead != NULL)
1199 {
1200 SetupData->TimeZoneListHead->Prev = NULL;
1201 }
1202
1203 HeapFree(GetProcessHeap(), 0, Entry);
1204 }
1205
1206 SetupData->TimeZoneListTail = NULL;
1207 }
1208
1209 static BOOL
1210 GetTimeZoneListIndex(LPDWORD lpIndex)
1211 {
1212 WCHAR szLanguageIdString[9];
1213 HKEY hKey;
1214 DWORD dwValueSize;
1215 DWORD Length;
1216 LPWSTR Buffer;
1217 LPWSTR Ptr;
1218 LPWSTR End;
1219 BOOL bFound = FALSE;
1220 unsigned long iLanguageID;
1221
1222 if (*lpIndex == -1)
1223 {
1224 *lpIndex = 85; /* fallback to GMT time zone */
1225
1226 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
1227 L"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
1228 0,
1229 KEY_ALL_ACCESS,
1230 &hKey))
1231 return FALSE;
1232
1233 dwValueSize = 9 * sizeof(WCHAR);
1234 if (RegQueryValueExW(hKey,
1235 L"Default",
1236 NULL,
1237 NULL,
1238 (LPBYTE)szLanguageIdString,
1239 &dwValueSize))
1240 {
1241 RegCloseKey(hKey);
1242 return FALSE;
1243 }
1244
1245 iLanguageID = wcstoul(szLanguageIdString, NULL, 16);
1246 RegCloseKey(hKey);
1247 }
1248 else
1249 {
1250 iLanguageID = *lpIndex;
1251 }
1252
1253 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
1254 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1255 0,
1256 KEY_ALL_ACCESS,
1257 &hKey))
1258 return FALSE;
1259
1260 dwValueSize = 0;
1261 if (RegQueryValueExW(hKey,
1262 L"IndexMapping",
1263 NULL,
1264 NULL,
1265 NULL,
1266 &dwValueSize))
1267 {
1268 RegCloseKey(hKey);
1269 return FALSE;
1270 }
1271
1272 Buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);
1273 if (Buffer == NULL)
1274 {
1275 RegCloseKey(hKey);
1276 return FALSE;
1277 }
1278
1279 if (RegQueryValueExW(hKey,
1280 L"IndexMapping",
1281 NULL,
1282 NULL,
1283 (LPBYTE)Buffer,
1284 &dwValueSize))
1285 {
1286 HeapFree(GetProcessHeap(), 0, Buffer);
1287 RegCloseKey(hKey);
1288 return FALSE;
1289 }
1290
1291 RegCloseKey(hKey);
1292
1293 Ptr = Buffer;
1294 while (*Ptr != 0)
1295 {
1296 Length = wcslen(Ptr);
1297 if (wcstoul(Ptr, NULL, 16) == iLanguageID)
1298 bFound = TRUE;
1299
1300 Ptr = Ptr + Length + 1;
1301 if (*Ptr == 0)
1302 break;
1303
1304 if (bFound)
1305 {
1306 *lpIndex = wcstoul(Ptr, &End, 10);
1307 HeapFree(GetProcessHeap(), 0, Buffer);
1308 return TRUE;
1309 }
1310
1311 Length = wcslen(Ptr);
1312 Ptr = Ptr + Length + 1;
1313 }
1314
1315 HeapFree(GetProcessHeap(), 0, Buffer);
1316
1317 return FALSE;
1318 }
1319
1320
1321 static VOID
1322 ShowTimeZoneList(HWND hwnd, PSETUPDATA SetupData, DWORD dwEntryIndex)
1323 {
1324 PTIMEZONE_ENTRY Entry;
1325 DWORD dwIndex = 0;
1326 DWORD dwCount;
1327
1328 GetTimeZoneListIndex(&dwEntryIndex);
1329
1330 Entry = SetupData->TimeZoneListHead;
1331 while (Entry != NULL)
1332 {
1333 dwCount = SendMessage(hwnd,
1334 CB_ADDSTRING,
1335 0,
1336 (LPARAM)Entry->Description);
1337
1338 if (dwEntryIndex != 0 && dwEntryIndex == Entry->Index)
1339 dwIndex = dwCount;
1340
1341 Entry = Entry->Next;
1342 }
1343
1344 SendMessage(hwnd,
1345 CB_SETCURSEL,
1346 (WPARAM)dwIndex,
1347 0);
1348 }
1349
1350
1351 static VOID
1352 SetLocalTimeZone(HWND hwnd, PSETUPDATA SetupData)
1353 {
1354 TIME_ZONE_INFORMATION TimeZoneInformation;
1355 PTIMEZONE_ENTRY Entry;
1356 DWORD dwIndex;
1357 DWORD i;
1358
1359 dwIndex = SendMessage(hwnd,
1360 CB_GETCURSEL,
1361 0,
1362 0);
1363
1364 i = 0;
1365 Entry = SetupData->TimeZoneListHead;
1366 while (i < dwIndex)
1367 {
1368 if (Entry == NULL)
1369 return;
1370
1371 i++;
1372 Entry = Entry->Next;
1373 }
1374
1375 wcscpy(TimeZoneInformation.StandardName,
1376 Entry->StandardName);
1377 wcscpy(TimeZoneInformation.DaylightName,
1378 Entry->DaylightName);
1379
1380 TimeZoneInformation.Bias = Entry->TimezoneInfo.Bias;
1381 TimeZoneInformation.StandardBias = Entry->TimezoneInfo.StandardBias;
1382 TimeZoneInformation.DaylightBias = Entry->TimezoneInfo.DaylightBias;
1383
1384 memcpy(&TimeZoneInformation.StandardDate,
1385 &Entry->TimezoneInfo.StandardDate,
1386 sizeof(SYSTEMTIME));
1387 memcpy(&TimeZoneInformation.DaylightDate,
1388 &Entry->TimezoneInfo.DaylightDate,
1389 sizeof(SYSTEMTIME));
1390
1391 /* Set time zone information */
1392 SetTimeZoneInformation(&TimeZoneInformation);
1393 }
1394
1395
1396 static BOOL
1397 GetLocalSystemTime(HWND hwnd, PSETUPDATA SetupData)
1398 {
1399 SYSTEMTIME Date;
1400 SYSTEMTIME Time;
1401
1402 if (DateTime_GetSystemtime(GetDlgItem(hwnd, IDC_DATEPICKER), &Date) != GDT_VALID)
1403 {
1404 return FALSE;
1405 }
1406
1407 if (DateTime_GetSystemtime(GetDlgItem(hwnd, IDC_TIMEPICKER), &Time) != GDT_VALID)
1408 {
1409 return FALSE;
1410 }
1411
1412 SetupData->SystemTime.wYear = Date.wYear;
1413 SetupData->SystemTime.wMonth = Date.wMonth;
1414 SetupData->SystemTime.wDayOfWeek = Date.wDayOfWeek;
1415 SetupData->SystemTime.wDay = Date.wDay;
1416 SetupData->SystemTime.wHour = Time.wHour;
1417 SetupData->SystemTime.wMinute = Time.wMinute;
1418 SetupData->SystemTime.wSecond = Time.wSecond;
1419 SetupData->SystemTime.wMilliseconds = Time.wMilliseconds;
1420
1421 return TRUE;
1422 }
1423
1424
1425 static VOID
1426 SetAutoDaylightInfo(HWND hwnd)
1427 {
1428 HKEY hKey;
1429 DWORD dwValue = 1;
1430
1431 if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
1432 {
1433 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
1434 L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
1435 0,
1436 KEY_SET_VALUE,
1437 &hKey))
1438 return;
1439
1440 RegSetValueExW(hKey,
1441 L"DisableAutoDaylightTimeSet",
1442 0,
1443 REG_DWORD,
1444 (LPBYTE)&dwValue,
1445 sizeof(DWORD));
1446 RegCloseKey(hKey);
1447 }
1448 }
1449
1450
1451 static BOOL
1452 SetSystemLocalTime(HWND hwnd, PSETUPDATA SetupData)
1453 {
1454 BOOL Ret = FALSE;
1455
1456 /*
1457 * Call SetLocalTime twice to ensure correct results
1458 */
1459 Ret = SetLocalTime(&SetupData->SystemTime) &&
1460 SetLocalTime(&SetupData->SystemTime);
1461
1462 return Ret;
1463 }
1464
1465 static BOOL
1466 WriteDateTimeSettings(HWND hwndDlg, PSETUPDATA SetupData)
1467 {
1468 WCHAR Title[64];
1469 WCHAR ErrorLocalTime[256];
1470 GetLocalSystemTime(hwndDlg, SetupData);
1471 SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST),
1472 SetupData);
1473
1474 SetAutoDaylightInfo(GetDlgItem(hwndDlg, IDC_AUTODAYLIGHT));
1475 if(!SetSystemLocalTime(hwndDlg, SetupData))
1476 {
1477 if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
1478 {
1479 wcscpy(Title, L"ReactOS Setup");
1480 }
1481 if (0 == LoadStringW(hDllInstance, IDS_WZD_LOCALTIME, ErrorLocalTime,
1482 sizeof(ErrorLocalTime) / sizeof(ErrorLocalTime[0])))
1483 {
1484 wcscpy(ErrorLocalTime, L"Setup was unable to set the local time.");
1485 }
1486 MessageBoxW(hwndDlg, ErrorLocalTime, Title, MB_ICONWARNING | MB_OK);
1487 return FALSE;
1488 }
1489
1490 return TRUE;
1491 }
1492
1493 static INT_PTR CALLBACK
1494 DateTimePageDlgProc(HWND hwndDlg,
1495 UINT uMsg,
1496 WPARAM wParam,
1497 LPARAM lParam)
1498 {
1499 PSETUPDATA SetupData;
1500
1501 /* Retrieve pointer to the global setup data */
1502 SetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);
1503
1504 switch (uMsg)
1505 {
1506 case WM_INITDIALOG:
1507 {
1508 /* Save pointer to the global setup data */
1509 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
1510 SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)SetupData);
1511
1512 CreateTimeZoneList(SetupData);
1513
1514 if (SetupData->UnattendSetup)
1515 {
1516 ShowTimeZoneList(GetDlgItem(hwndDlg, IDC_TIMEZONELIST),
1517 SetupData, SetupData->TimeZoneIndex);
1518
1519 if (!SetupData->DisableAutoDaylightTimeSet)
1520 {
1521 SendDlgItemMessage(hwndDlg, IDC_AUTODAYLIGHT, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
1522 }
1523 }
1524 else
1525 {
1526 ShowTimeZoneList(GetDlgItem(hwndDlg, IDC_TIMEZONELIST),
1527 SetupData, -1);
1528
1529 SendDlgItemMessage(hwndDlg, IDC_AUTODAYLIGHT, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
1530 }
1531
1532 }
1533 break;
1534
1535
1536 case WM_NOTIFY:
1537 {
1538 LPNMHDR lpnm = (LPNMHDR)lParam;
1539
1540 switch (lpnm->code)
1541 {
1542 case PSN_SETACTIVE:
1543 /* Enable the Back and Next buttons */
1544 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
1545 if (SetupData->UnattendSetup && WriteDateTimeSettings(hwndDlg, SetupData))
1546 {
1547 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_PROCESSPAGE);
1548 return TRUE;
1549 }
1550 break;
1551
1552 case PSN_WIZNEXT:
1553 {
1554 WriteDateTimeSettings(hwndDlg, SetupData);
1555 }
1556 break;
1557
1558 case PSN_WIZBACK:
1559 SetupData->UnattendSetup = FALSE;
1560 break;
1561
1562 default:
1563 break;
1564 }
1565 }
1566 break;
1567
1568 case WM_DESTROY:
1569 DestroyTimeZoneList(SetupData);
1570 break;
1571
1572 default:
1573 break;
1574 }
1575
1576 return FALSE;
1577 }
1578
1579
1580 static UINT CALLBACK
1581 RegistrationNotificationProc(PVOID Context,
1582 UINT Notification,
1583 UINT_PTR Param1,
1584 UINT_PTR Param2)
1585 {
1586 PREGISTRATIONDATA RegistrationData;
1587 REGISTRATIONNOTIFY RegistrationNotify;
1588 PSP_REGISTER_CONTROL_STATUSW StatusInfo;
1589 UINT MessageID;
1590 WCHAR ErrorMessage[128];
1591
1592 RegistrationData = (PREGISTRATIONDATA) Context;
1593
1594 if (SPFILENOTIFY_STARTREGISTRATION == Notification ||
1595 SPFILENOTIFY_ENDREGISTRATION == Notification)
1596 {
1597 StatusInfo = (PSP_REGISTER_CONTROL_STATUSW) Param1;
1598 RegistrationNotify.CurrentItem = wcsrchr(StatusInfo->FileName, L'\\');
1599 if (NULL == RegistrationNotify.CurrentItem)
1600 {
1601 RegistrationNotify.CurrentItem = StatusInfo->FileName;
1602 }
1603 else
1604 {
1605 RegistrationNotify.CurrentItem++;
1606 }
1607
1608 if (SPFILENOTIFY_STARTREGISTRATION == Notification)
1609 {
1610 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1611 StatusInfo->FileName);
1612 RegistrationNotify.ErrorMessage = NULL;
1613 RegistrationNotify.Progress = RegistrationData->Registered;
1614 }
1615 else
1616 {
1617 DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
1618 StatusInfo->FileName);
1619 DPRINT("Win32Error %u FailureCode %u\n", StatusInfo->Win32Error,
1620 StatusInfo->FailureCode);
1621 if (SPREG_SUCCESS != StatusInfo->FailureCode)
1622 {
1623 switch(StatusInfo->FailureCode)
1624 {
1625 case SPREG_LOADLIBRARY:
1626 MessageID = IDS_LOADLIBRARY_FAILED;
1627 break;
1628 case SPREG_GETPROCADDR:
1629 MessageID = IDS_GETPROCADDR_FAILED;
1630 break;
1631 case SPREG_REGSVR:
1632 MessageID = IDS_REGSVR_FAILED;
1633 break;
1634 case SPREG_DLLINSTALL:
1635 MessageID = IDS_DLLINSTALL_FAILED;
1636 break;
1637 case SPREG_TIMEOUT:
1638 MessageID = IDS_TIMEOUT;
1639 break;
1640 default:
1641 MessageID = IDS_REASON_UNKNOWN;
1642 break;
1643 }
1644 if (0 == LoadStringW(hDllInstance, MessageID,
1645 ErrorMessage,
1646 sizeof(ErrorMessage) /
1647 sizeof(ErrorMessage[0])))
1648 {
1649 ErrorMessage[0] = L'\0';
1650 }
1651 if (SPREG_TIMEOUT != StatusInfo->FailureCode)
1652 {
1653 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
1654 StatusInfo->Win32Error, 0,
1655 ErrorMessage + wcslen(ErrorMessage),
1656 sizeof(ErrorMessage) / sizeof(ErrorMessage[0]) -
1657 wcslen(ErrorMessage), NULL);
1658 }
1659 RegistrationNotify.ErrorMessage = ErrorMessage;
1660 }
1661 else
1662 {
1663 RegistrationNotify.ErrorMessage = NULL;
1664 }
1665 if (RegistrationData->Registered < RegistrationData->DllCount)
1666 {
1667 RegistrationData->Registered++;
1668 }
1669 }
1670
1671 RegistrationNotify.Progress = RegistrationData->Registered;
1672 RegistrationNotify.ActivityID = IDS_REGISTERING_COMPONENTS;
1673 SendMessage(RegistrationData->hwndDlg, PM_REGISTRATION_NOTIFY,
1674 0, (LPARAM) &RegistrationNotify);
1675
1676 return FILEOP_DOIT;
1677 }
1678 else
1679 {
1680 DPRINT1("Received unexpected notification %u\n", Notification);
1681 return SetupDefaultQueueCallback(RegistrationData->DefaultContext,
1682 Notification, Param1, Param2);
1683 }
1684 }
1685
1686
1687 static DWORD CALLBACK
1688 RegistrationProc(LPVOID Parameter)
1689 {
1690 PREGISTRATIONDATA RegistrationData;
1691 REGISTRATIONNOTIFY RegistrationNotify;
1692 DWORD LastError = NO_ERROR;
1693 WCHAR UnknownError[84];
1694
1695 RegistrationData = (PREGISTRATIONDATA) Parameter;
1696 RegistrationData->Registered = 0;
1697 RegistrationData->DefaultContext = SetupInitDefaultQueueCallback(RegistrationData->hwndDlg);
1698
1699 _SEH2_TRY
1700 {
1701 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData->hwndDlg),
1702 hSysSetupInf,
1703 L"RegistrationPhase2",
1704 SPINST_REGISTRY |
1705 SPINST_REGISTERCALLBACKAWARE |
1706 SPINST_REGSVR,
1707 0,
1708 NULL,
1709 0,
1710 RegistrationNotificationProc,
1711 RegistrationData,
1712 NULL,
1713 NULL))
1714 {
1715 LastError = GetLastError();
1716 }
1717 }
1718 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
1719 {
1720 DPRINT("Catching exception\n");
1721 LastError = RtlNtStatusToDosError(_SEH2_GetExceptionCode());
1722 }
1723 _SEH2_END;
1724
1725 if (NO_ERROR == LastError)
1726 {
1727 RegistrationNotify.ErrorMessage = NULL;
1728 }
1729 else
1730 {
1731 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1732 LastError);
1733 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1734 FORMAT_MESSAGE_FROM_SYSTEM, NULL, LastError, 0,
1735 (LPWSTR) &RegistrationNotify.ErrorMessage, 0,
1736 NULL))
1737 {
1738 if (0 == LoadStringW(hDllInstance, IDS_UNKNOWN_ERROR,
1739 UnknownError,
1740 sizeof(UnknownError) / sizeof(UnknownError[0]) -
1741 20))
1742 {
1743 wcscpy(UnknownError, L"Unknown error");
1744 }
1745 wcscat(UnknownError, L" ");
1746 _ultow(LastError, UnknownError + wcslen(UnknownError), 10);
1747 RegistrationNotify.ErrorMessage = UnknownError;
1748 }
1749 }
1750
1751 RegistrationNotify.Progress = RegistrationData->DllCount;
1752 RegistrationNotify.ActivityID = IDS_REGISTERING_COMPONENTS;
1753 RegistrationNotify.CurrentItem = NULL;
1754 SendMessage(RegistrationData->hwndDlg, PM_REGISTRATION_NOTIFY,
1755 1, (LPARAM) &RegistrationNotify);
1756 if (NULL != RegistrationNotify.ErrorMessage &&
1757 UnknownError != RegistrationNotify.ErrorMessage)
1758 {
1759 LocalFree((PVOID) RegistrationNotify.ErrorMessage);
1760 }
1761
1762 SetupTermDefaultQueueCallback(RegistrationData->DefaultContext);
1763 HeapFree(GetProcessHeap(), 0, RegistrationData);
1764
1765 RegisterTypeLibraries(hSysSetupInf, L"TypeLibraries");
1766
1767 // FIXME: Move this call to a separate cleanup page!
1768 RtlCreateBootStatusDataFile();
1769
1770 return 0;
1771 }
1772
1773
1774 static BOOL
1775 StartComponentRegistration(HWND hwndDlg, PULONG MaxProgress)
1776 {
1777 HANDLE RegistrationThread;
1778 LONG DllCount;
1779 INFCONTEXT Context;
1780 WCHAR SectionName[512];
1781 PREGISTRATIONDATA RegistrationData;
1782
1783 DllCount = -1;
1784 if (! SetupFindFirstLineW(hSysSetupInf, L"RegistrationPhase2",
1785 L"RegisterDlls", &Context))
1786 {
1787 DPRINT1("No RegistrationPhase2 section found\n");
1788 return FALSE;
1789 }
1790 if (! SetupGetStringFieldW(&Context, 1, SectionName,
1791 sizeof(SectionName) / sizeof(SectionName[0]),
1792 NULL))
1793 {
1794 DPRINT1("Unable to retrieve section name\n");
1795 return FALSE;
1796 }
1797 DllCount = SetupGetLineCountW(hSysSetupInf, SectionName);
1798 DPRINT("SectionName %S DllCount %ld\n", SectionName, DllCount);
1799 if (DllCount < 0)
1800 {
1801 SetLastError(STATUS_NOT_FOUND);
1802 return FALSE;
1803 }
1804
1805 *MaxProgress = (ULONG) DllCount;
1806
1807 /*
1808 * Create a background thread to do the actual registrations, so the
1809 * main thread can just run its message loop.
1810 */
1811 RegistrationThread = NULL;
1812 RegistrationData = HeapAlloc(GetProcessHeap(), 0,
1813 sizeof(REGISTRATIONDATA));
1814 if (RegistrationData != NULL)
1815 {
1816 RegistrationData->hwndDlg = hwndDlg;
1817 RegistrationData->DllCount = DllCount;
1818 RegistrationThread = CreateThread(NULL, 0, RegistrationProc,
1819 RegistrationData, 0, NULL);
1820 if (RegistrationThread != NULL)
1821 {
1822 CloseHandle(RegistrationThread);
1823 }
1824 else
1825 {
1826 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1827 HeapFree(GetProcessHeap(), 0, RegistrationData);
1828 return FALSE;
1829 }
1830 }
1831 else
1832 {
1833 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1834 return FALSE;
1835 }
1836
1837 return TRUE;
1838 }
1839
1840
1841 static INT_PTR CALLBACK
1842 ProcessPageDlgProc(HWND hwndDlg,
1843 UINT uMsg,
1844 WPARAM wParam,
1845 LPARAM lParam)
1846 {
1847 PSETUPDATA SetupData;
1848 PREGISTRATIONNOTIFY RegistrationNotify;
1849 static UINT oldActivityID = -1;
1850 WCHAR Title[64];
1851
1852 /* Retrieve pointer to the global setup data */
1853 SetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);
1854
1855 switch (uMsg)
1856 {
1857 case WM_INITDIALOG:
1858 {
1859 /* Save pointer to the global setup data */
1860 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
1861 SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)SetupData);
1862 }
1863 break;
1864
1865 case WM_NOTIFY:
1866 {
1867 LPNMHDR lpnm = (LPNMHDR)lParam;
1868 ULONG MaxProgress = 0;
1869
1870 switch (lpnm->code)
1871 {
1872 case PSN_SETACTIVE:
1873 /* Disable the Back and Next buttons */
1874 PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
1875
1876 StartComponentRegistration(hwndDlg, &MaxProgress);
1877
1878 SendDlgItemMessage(hwndDlg, IDC_PROCESSPROGRESS, PBM_SETRANGE,
1879 0, MAKELPARAM(0, MaxProgress));
1880 SendDlgItemMessage(hwndDlg, IDC_PROCESSPROGRESS, PBM_SETPOS,
1881 0, 0);
1882 break;
1883
1884 case PSN_WIZNEXT:
1885 break;
1886
1887 case PSN_WIZBACK:
1888 SetupData->UnattendSetup = FALSE;
1889 break;
1890
1891 default:
1892 break;
1893 }
1894 }
1895 break;
1896
1897 case PM_REGISTRATION_NOTIFY:
1898 {
1899 WCHAR Activity[64];
1900 RegistrationNotify = (PREGISTRATIONNOTIFY) lParam;
1901 // update if necessary only
1902 if (oldActivityID != RegistrationNotify->ActivityID)
1903 {
1904 if (0 != LoadStringW(hDllInstance, RegistrationNotify->ActivityID,
1905 Activity,
1906 sizeof(Activity) / sizeof(Activity[0])))
1907 {
1908 SendDlgItemMessageW(hwndDlg, IDC_ACTIVITY, WM_SETTEXT,
1909 0, (LPARAM) Activity);
1910 }
1911 oldActivityID = RegistrationNotify->ActivityID;
1912 }
1913 SendDlgItemMessageW(hwndDlg, IDC_ITEM, WM_SETTEXT, 0,
1914 (LPARAM)(NULL == RegistrationNotify->CurrentItem ?
1915 L"" : RegistrationNotify->CurrentItem));
1916 SendDlgItemMessage(hwndDlg, IDC_PROCESSPROGRESS, PBM_SETPOS,
1917 RegistrationNotify->Progress, 0);
1918 if (NULL != RegistrationNotify->ErrorMessage)
1919 {
1920 if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP,
1921 Title, sizeof(Title) / sizeof(Title[0])))
1922 {
1923 wcscpy(Title, L"ReactOS Setup");
1924 }
1925 MessageBoxW(hwndDlg, RegistrationNotify->ErrorMessage,
1926 Title, MB_ICONERROR | MB_OK);
1927
1928 }
1929
1930 if (wParam)
1931 {
1932 #ifdef VMWINST
1933 if(!SetupData->UnattendSetup && !SetupData->DisableVmwInst)
1934 RunVMWInstall(GetParent(hwndDlg));
1935 #endif
1936
1937 /* Enable the Back and Next buttons */
1938 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
1939 PropSheet_PressButton(GetParent(hwndDlg), PSBTN_NEXT);
1940 }
1941 }
1942 return TRUE;
1943
1944 default:
1945 break;
1946 }
1947
1948 return FALSE;
1949 }
1950
1951
1952 static VOID
1953 SetInstallationCompleted(VOID)
1954 {
1955 HKEY hKey = 0;
1956 DWORD InProgress = 0;
1957 DWORD InstallDate;
1958
1959 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE,
1960 L"SYSTEM\\Setup",
1961 0,
1962 KEY_WRITE,
1963 &hKey ) == ERROR_SUCCESS)
1964 {
1965 RegSetValueExW( hKey, L"SystemSetupInProgress", 0, REG_DWORD, (LPBYTE)&InProgress, sizeof(InProgress) );
1966 RegCloseKey( hKey );
1967 }
1968
1969 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE,
1970 L"Software\\Microsoft\\Windows NT\\CurrentVersion",
1971 0,
1972 KEY_WRITE,
1973 &hKey ) == ERROR_SUCCESS)
1974 {
1975 InstallDate = (DWORD)time(NULL);
1976 RegSetValueExW( hKey, L"InstallDate", 0, REG_DWORD, (LPBYTE)&InstallDate, sizeof(InstallDate) );
1977 RegCloseKey( hKey );
1978 }
1979 }
1980
1981 static INT_PTR CALLBACK
1982 FinishDlgProc(HWND hwndDlg,
1983 UINT uMsg,
1984 WPARAM wParam,
1985 LPARAM lParam)
1986 {
1987
1988 switch (uMsg)
1989 {
1990 case WM_INITDIALOG:
1991 {
1992 /* Get pointer to the global setup data */
1993 PSETUPDATA SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
1994
1995 if (!SetupData->UnattendSetup || !SetupData->DisableGeckoInst)
1996 {
1997 /* Run the Wine Gecko prompt */
1998 Control_RunDLLW(hwndDlg, 0, L"appwiz.cpl install_gecko", SW_SHOW);
1999 }
2000
2001 /* Set title font */
2002 SendDlgItemMessage(hwndDlg,
2003 IDC_FINISHTITLE,
2004 WM_SETFONT,
2005 (WPARAM)SetupData->hTitleFont,
2006 (LPARAM)TRUE);
2007 if (SetupData->UnattendSetup)
2008 {
2009 KillTimer(hwndDlg, 1);
2010 SetInstallationCompleted();
2011 PostQuitMessage(0);
2012 }
2013 }
2014 break;
2015
2016 case WM_DESTROY:
2017 {
2018 SetInstallationCompleted();
2019 PostQuitMessage(0);
2020 return TRUE;
2021 }
2022
2023 case WM_TIMER:
2024 {
2025 INT Position;
2026 HWND hWndProgress;
2027
2028 hWndProgress = GetDlgItem(hwndDlg, IDC_RESTART_PROGRESS);
2029 Position = SendMessage(hWndProgress, PBM_GETPOS, 0, 0);
2030 if (Position == 300)
2031 {
2032 KillTimer(hwndDlg, 1);
2033 PropSheet_PressButton(GetParent(hwndDlg), PSBTN_FINISH);
2034 }
2035 else
2036 {
2037 SendMessage(hWndProgress, PBM_SETPOS, Position + 1, 0);
2038 }
2039 }
2040 return TRUE;
2041
2042 case WM_NOTIFY:
2043 {
2044 LPNMHDR lpnm = (LPNMHDR)lParam;
2045
2046 switch (lpnm->code)
2047 {
2048 case PSN_SETACTIVE:
2049 /* Enable the correct buttons on for the active page */
2050 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_FINISH);
2051
2052 SendDlgItemMessage(hwndDlg, IDC_RESTART_PROGRESS, PBM_SETRANGE, 0,
2053 MAKELPARAM(0, 300));
2054 SendDlgItemMessage(hwndDlg, IDC_RESTART_PROGRESS, PBM_SETPOS, 0, 0);
2055 SetTimer(hwndDlg, 1, 50, NULL);
2056 break;
2057
2058 case PSN_WIZFINISH:
2059 DestroyWindow(GetParent(hwndDlg));
2060 break;
2061
2062 default:
2063 break;
2064 }
2065 }
2066 break;
2067
2068 default:
2069 break;
2070 }
2071
2072 return FALSE;
2073 }
2074
2075
2076 BOOL
2077 ProcessUnattendInf(HINF hUnattendedInf)
2078 {
2079 INFCONTEXT InfContext;
2080 WCHAR szName[256];
2081 WCHAR szValue[MAX_PATH];
2082 DWORD LineLength;
2083 HKEY hKey;
2084
2085 if (!SetupFindFirstLineW(hUnattendedInf,
2086 L"Unattend",
2087 L"UnattendSetupEnabled",
2088 &InfContext))
2089 {
2090 DPRINT1("Error: Cant find UnattendSetupEnabled Key! %d\n", GetLastError());
2091 return FALSE;
2092 }
2093
2094 if (!SetupGetStringFieldW(&InfContext,
2095 1,
2096 szValue,
2097 sizeof(szValue) / sizeof(WCHAR),
2098 &LineLength))
2099 {
2100 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2101 return FALSE;
2102 }
2103
2104 if (wcscmp(szValue, L"yes") != 0)
2105 {
2106 DPRINT("Unattend setup was disabled by UnattendSetupEnabled key.\n");
2107 return FALSE;
2108 }
2109
2110 if (!SetupFindFirstLineW(hUnattendedInf,
2111 L"Unattend",
2112 NULL,
2113 &InfContext))
2114 {
2115 DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError());
2116 return FALSE;
2117 }
2118
2119
2120 do
2121 {
2122 if (!SetupGetStringFieldW(&InfContext,
2123 0,
2124 szName,
2125 sizeof(szName) / sizeof(WCHAR),
2126 &LineLength))
2127 {
2128 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2129 return FALSE;
2130 }
2131
2132 if (!SetupGetStringFieldW(&InfContext,
2133 1,
2134 szValue,
2135 sizeof(szValue) / sizeof(WCHAR),
2136 &LineLength))
2137 {
2138 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2139 return FALSE;
2140 }
2141 DPRINT1("Name %S Value %S\n", szName, szValue);
2142 if (!wcscmp(szName, L"FullName"))
2143 {
2144 if ((sizeof(SetupData.OwnerName) / sizeof(TCHAR)) > LineLength)
2145 {
2146 wcscpy(SetupData.OwnerName, szValue);
2147 }
2148 }
2149 else if (!wcscmp(szName, L"OrgName"))
2150 {
2151 if ((sizeof(SetupData.OwnerOrganization) / sizeof(WCHAR)) > LineLength)
2152 {
2153 wcscpy(SetupData.OwnerOrganization, szValue);
2154 }
2155 }
2156 else if (!wcscmp(szName, L"ComputerName"))
2157 {
2158 if ((sizeof(SetupData.ComputerName) / sizeof(WCHAR)) > LineLength)
2159 {
2160 wcscpy(SetupData.ComputerName, szValue);
2161 }
2162 }
2163 else if (!wcscmp(szName, L"AdminPassword"))
2164 {
2165 if ((sizeof(SetupData.AdminPassword) / sizeof(WCHAR)) > LineLength)
2166 {
2167 wcscpy(SetupData.AdminPassword, szValue);
2168 }
2169 }
2170 else if (!wcscmp(szName, L"TimeZoneIndex"))
2171 {
2172 SetupData.TimeZoneIndex = _wtoi(szValue);
2173 }
2174 else if (!wcscmp(szName, L"DisableAutoDaylightTimeSet"))
2175 {
2176 SetupData.DisableAutoDaylightTimeSet = _wtoi(szValue);
2177 }
2178 else if (!wcscmp(szName, L"DisableVmwInst"))
2179 {
2180 if(!wcscmp(szValue, L"yes"))
2181 SetupData.DisableVmwInst = 1;
2182 else
2183 SetupData.DisableVmwInst = 0;
2184 }
2185 else if (!wcscmp(szName, L"DisableGeckoInst"))
2186 {
2187 if(!wcscmp(szValue, L"yes"))
2188 SetupData.DisableGeckoInst = 1;
2189 else
2190 SetupData.DisableGeckoInst = 0;
2191 }
2192
2193 }
2194 while (SetupFindNextLine(&InfContext, &InfContext));
2195 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
2196 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
2197 0,
2198 KEY_SET_VALUE,
2199 &hKey) != ERROR_SUCCESS)
2200 {
2201 DPRINT1("Error: failed to open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\n");
2202 return TRUE;
2203 }
2204
2205
2206 if (SetupFindFirstLineW(hUnattendedInf,
2207 L"GuiRunOnce",
2208 NULL,
2209 &InfContext))
2210 {
2211
2212 int i = 0;
2213 do
2214 {
2215 if(SetupGetStringFieldW(&InfContext,
2216 0,
2217 szValue,
2218 sizeof(szValue) / sizeof(WCHAR),
2219 NULL))
2220 {
2221 WCHAR szPath[MAX_PATH];
2222 swprintf(szName, L"%d", i);
2223 DPRINT("szName %S szValue %S\n", szName, szValue);
2224
2225 if (ExpandEnvironmentStringsW(szValue, szPath, MAX_PATH))
2226 {
2227 DPRINT("value %S\n", szPath);
2228 if (RegSetValueExW(hKey,
2229 szName,
2230 0,
2231 REG_SZ,
2232 (const BYTE*)szPath,
2233 (wcslen(szPath) + 1) * sizeof(WCHAR)) == ERROR_SUCCESS)
2234 {
2235 i++;
2236 }
2237 }
2238 }
2239 } while(SetupFindNextLine(&InfContext, &InfContext));
2240 }
2241
2242 RegCloseKey(hKey);
2243 return TRUE;
2244 }
2245
2246 /*
2247 * GetRosInstallCD should find the path to ros installation medium
2248 * BUG 1
2249 * If there are more than one CDDrive in it containing a ReactOS
2250 * installation cd, then it will pick the first one regardless if
2251 * it is really the installation cd
2252 *
2253 * The best way to implement this is to set the key
2254 * HKLM\Software\Microsoft\Windows NT\CurrentVersion\SourcePath (REG_SZ)
2255 */
2256
2257 BOOL
2258 GetRosInstallCD(WCHAR *pwszPath, DWORD cchPathMax)
2259 {
2260 WCHAR wszDrives[512];
2261 DWORD cchDrives;
2262 WCHAR *pwszDrive;
2263
2264 cchDrives = GetLogicalDriveStringsW(_countof(wszDrives) - 1, wszDrives);
2265 if (cchDrives == 0 || cchDrives >= _countof(wszDrives))
2266 {
2267 /* buffer too small or failure */
2268 LogItem(SYSSETUP_SEVERITY_INFORMATION, L"GetLogicalDriveStringsW failed");
2269 return FALSE;
2270 }
2271
2272 for (pwszDrive = wszDrives; pwszDrive[0]; pwszDrive += wcslen(pwszDrive) + 1)
2273 {
2274 if (GetDriveTypeW(pwszDrive) == DRIVE_CDROM)
2275 {
2276 WCHAR wszBuf[MAX_PATH];
2277 wsprintf(wszBuf, L"%sreactos\\system32\\ntoskrnl.exe", pwszDrive);
2278 LogItem(SYSSETUP_SEVERITY_INFORMATION, wszBuf);
2279 if (GetFileAttributesW(wszBuf) != INVALID_FILE_ATTRIBUTES)
2280 {
2281 /* the file exists, so this is the right drive */
2282 wcsncpy(pwszPath, pwszDrive, cchPathMax);
2283 OutputDebugStringW(L"GetRosInstallCD: ");OutputDebugStringW(pwszPath);OutputDebugStringW(L"\n");
2284 return TRUE;
2285 }
2286 }
2287 }
2288 return FALSE;
2289 }
2290
2291
2292 VOID
2293 ProcessUnattendSetup(VOID)
2294 {
2295 WCHAR szPath[MAX_PATH];
2296 HINF hUnattendedInf;
2297 DWORD dwLength;
2298
2299 if (!GetRosInstallCD(szPath, MAX_PATH))
2300 {
2301 /* no cd drive found */
2302 return;
2303 }
2304
2305 dwLength = wcslen(szPath);
2306 if (dwLength + 21 > MAX_PATH)
2307 {
2308 /* FIXME
2309 * allocate bigger buffer
2310 */
2311 return;
2312 }
2313
2314 wcscat(szPath, L"reactos\\unattend.inf");
2315
2316 hUnattendedInf = SetupOpenInfFileW(szPath,
2317 NULL,
2318 INF_STYLE_OLDNT,
2319 NULL);
2320
2321 if (hUnattendedInf != INVALID_HANDLE_VALUE)
2322 {
2323 SetupData.UnattendSetup = ProcessUnattendInf(hUnattendedInf);
2324 SetupCloseInfFile(hUnattendedInf);
2325 }
2326 }
2327
2328
2329 VOID
2330 InstallWizard(VOID)
2331 {
2332 PROPSHEETHEADER psh;
2333 HPROPSHEETPAGE ahpsp[8];
2334 PROPSHEETPAGE psp = {0};
2335 UINT nPages = 0;
2336 HWND hWnd;
2337 MSG msg;
2338
2339 /* Clear setup data */
2340 ZeroMemory(&SetupData, sizeof(SETUPDATA));
2341
2342 ProcessUnattendSetup();
2343
2344 /* Create the Welcome page */
2345 psp.dwSize = sizeof(PROPSHEETPAGE);
2346 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
2347 psp.hInstance = hDllInstance;
2348 psp.lParam = (LPARAM)&SetupData;
2349 psp.pfnDlgProc = WelcomeDlgProc;
2350 psp.pszTemplate = MAKEINTRESOURCE(IDD_WELCOMEPAGE);
2351 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2352
2353 /* Create the Acknowledgements page */
2354 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
2355 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_ACKTITLE);
2356 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_ACKSUBTITLE);
2357 psp.pszTemplate = MAKEINTRESOURCE(IDD_ACKPAGE);
2358 psp.pfnDlgProc = AckPageDlgProc;
2359 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2360
2361 /* Create the Locale page */
2362 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
2363 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_LOCALETITLE);
2364 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_LOCALESUBTITLE);
2365 psp.pfnDlgProc = LocalePageDlgProc;
2366 psp.pszTemplate = MAKEINTRESOURCE(IDD_LOCALEPAGE);
2367 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2368
2369
2370 /* Create the Owner page */
2371 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
2372 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_OWNERTITLE);
2373 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_OWNERSUBTITLE);
2374 psp.pszTemplate = MAKEINTRESOURCE(IDD_OWNERPAGE);
2375 psp.pfnDlgProc = OwnerPageDlgProc;
2376 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2377
2378 /* Create the Computer page */
2379 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
2380 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_COMPUTERTITLE);
2381 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE);
2382 psp.pfnDlgProc = ComputerPageDlgProc;
2383 psp.pszTemplate = MAKEINTRESOURCE(IDD_COMPUTERPAGE);
2384 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2385
2386
2387 /* Create the DateTime page */
2388 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
2389 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_DATETIMETITLE);
2390 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_DATETIMESUBTITLE);
2391 psp.pfnDlgProc = DateTimePageDlgProc;
2392 psp.pszTemplate = MAKEINTRESOURCE(IDD_DATETIMEPAGE);
2393 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2394
2395
2396 /* Create the Process page */
2397 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
2398 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_PROCESSTITLE);
2399 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_PROCESSSUBTITLE);
2400 psp.pfnDlgProc = ProcessPageDlgProc;
2401 psp.pszTemplate = MAKEINTRESOURCE(IDD_PROCESSPAGE);
2402 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2403
2404
2405 /* Create the Finish page */
2406 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
2407 psp.pfnDlgProc = FinishDlgProc;
2408 psp.pszTemplate = MAKEINTRESOURCE(IDD_FINISHPAGE);
2409 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
2410
2411 /* Create the property sheet */
2412 psh.dwSize = sizeof(PROPSHEETHEADER);
2413 psh.dwFlags = PSH_WIZARD97 | PSH_WATERMARK | PSH_HEADER | PSH_MODELESS;
2414 psh.hInstance = hDllInstance;
2415 psh.hwndParent = NULL;
2416 psh.nPages = nPages;
2417 psh.nStartPage = 0;
2418 psh.phpage = ahpsp;
2419 psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
2420 psh.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
2421
2422 /* Create title font */
2423 SetupData.hTitleFont = CreateTitleFont();
2424
2425 /* Display the wizard */
2426 hWnd = (HWND)PropertySheet(&psh);
2427 ShowWindow(hWnd, SW_SHOW);
2428
2429 while (GetMessage(&msg, NULL, 0, 0))
2430 {
2431 if (!IsDialogMessage(hWnd, &msg))
2432 {
2433 TranslateMessage(&msg);
2434 DispatchMessage(&msg);
2435 }
2436 }
2437
2438 DeleteObject(SetupData.hTitleFont);
2439 }
2440
2441 /* EOF */