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