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