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