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>
10 /* INCLUDES *****************************************************************/
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 */
31 typedef struct _REGISTRATIONNOTIFY
37 } REGISTRATIONNOTIFY
, *PREGISTRATIONNOTIFY
;
39 typedef struct _REGISTRATIONDATA
45 } REGISTRATIONDATA
, *PREGISTRATIONDATA
;
47 /* GLOBALS ******************************************************************/
52 /* FUNCTIONS ****************************************************************/
54 extern void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
);
57 GetRosInstallCD(WCHAR
*pwszPath
, DWORD cchPathMax
);
61 RunVMWInstall(HWND hWnd
)
63 PROCESS_INFORMATION ProcInfo
;
67 WCHAR InstallName
[] = L
"vmwinst.exe";
69 ZeroMemory(&si
, sizeof(si
));
72 if(CreateProcessW(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
73 NULL
, NULL
, &si
, &ProcInfo
))
75 EnableWindow(hWnd
, FALSE
);
78 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
80 if (msg
.message
== WM_QUIT
)
82 TranslateMessage(&msg
);
83 DispatchMessage(&msg
);
86 ret
= MsgWaitForMultipleObjects(1, &ProcInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
| QS_ALLINPUT
);
87 if (ret
== WAIT_OBJECT_0
)
91 EnableWindow(hWnd
, TRUE
);
93 CloseHandle(ProcInfo
.hThread
);
94 CloseHandle(ProcInfo
.hProcess
);
102 CenterWindow(HWND hWnd
)
108 hWndParent
= GetParent(hWnd
);
109 if (hWndParent
== NULL
)
110 hWndParent
= GetDesktopWindow();
112 GetWindowRect(hWndParent
, &rcParent
);
113 GetWindowRect(hWnd
, &rcWindow
);
117 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
118 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
126 CreateTitleFont(VOID
)
128 NONCLIENTMETRICSW ncm
;
134 ncm
.cbSize
= sizeof(NONCLIENTMETRICSW
);
135 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
137 LogFont
= ncm
.lfMessageFont
;
138 LogFont
.lfWeight
= FW_BOLD
;
139 wcscpy(LogFont
.lfFaceName
, L
"MS Shell Dlg");
143 LogFont
.lfHeight
= 0 - GetDeviceCaps(hdc
, LOGPIXELSY
) * FontSize
/ 72;
144 hFont
= CreateFontIndirectW(&LogFont
);
145 ReleaseDC(NULL
, hdc
);
151 static INT_PTR CALLBACK
152 GplDlgProc(HWND hwndDlg
,
157 HRSRC GplTextResource
;
167 GplTextResource
= FindResourceW(hDllInstance
, MAKEINTRESOURCE(IDR_GPL
), L
"RT_TEXT");
168 if (NULL
== GplTextResource
)
172 Size
= SizeofResource(hDllInstance
, GplTextResource
);
177 GplText
= HeapAlloc(GetProcessHeap(), 0, Size
+ 1);
182 GplTextMem
= LoadResource(hDllInstance
, GplTextResource
);
183 if (NULL
== GplTextMem
)
185 HeapFree(GetProcessHeap(), 0, GplText
);
188 GplTextLocked
= LockResource(GplTextMem
);
189 if (NULL
== GplTextLocked
)
191 HeapFree(GetProcessHeap(), 0, GplText
);
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
));
202 EndDialog(hwndDlg
, IDCANCEL
);
206 if (HIWORD(wParam
) == BN_CLICKED
&& IDOK
== LOWORD(wParam
))
208 EndDialog(hwndDlg
, IDOK
);
220 static INT_PTR CALLBACK
221 WelcomeDlgProc(HWND hwndDlg
,
230 PSETUPDATA SetupData
;
234 /* Get pointer to the global setup data */
235 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
237 hwndControl
= GetParent(hwndDlg
);
239 /* Center the wizard window */
240 CenterWindow (hwndControl
);
242 /* Hide the system menu */
243 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
244 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
246 /* Hide and disable the 'Cancel' button */
247 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
248 ShowWindow (hwndControl
, SW_HIDE
);
249 EnableWindow (hwndControl
, FALSE
);
252 SendDlgItemMessage(hwndDlg
,
255 (WPARAM
)SetupData
->hTitleFont
,
263 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
268 /* Enable the Next button */
269 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
270 if (SetupData
.UnattendSetup
)
272 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_ACKPAGE
);
278 SetupData
.UnattendSetup
= FALSE
;
295 static INT_PTR CALLBACK
296 AckPageDlgProc(HWND hwndDlg
,
303 PWCHAR End
, CurrentProject
;
304 INT ProjectsSize
, ProjectsCount
;
314 Projects
= HeapAlloc(GetProcessHeap(), 0, ProjectsSize
* sizeof(WCHAR
));
315 if (NULL
== Projects
)
319 ProjectsCount
= LoadStringW(hDllInstance
, IDS_ACKPROJECTS
, Projects
, ProjectsSize
);
320 if (0 == ProjectsCount
)
322 HeapFree(GetProcessHeap(), 0, Projects
);
325 if (ProjectsCount
< ProjectsSize
- 1)
329 HeapFree(GetProcessHeap(), 0, Projects
);
333 CurrentProject
= Projects
;
334 while (L
'\0' != *CurrentProject
)
336 End
= wcschr(CurrentProject
, L
'\n');
341 (void)ListBox_AddString(GetDlgItem(hwndDlg
, IDC_PROJECTS
), CurrentProject
);
344 CurrentProject
= End
+ 1;
348 CurrentProject
+= wcslen(CurrentProject
);
351 HeapFree(GetProcessHeap(), 0, Projects
);
356 if (HIWORD(wParam
) == BN_CLICKED
&& IDC_VIEWGPL
== LOWORD(wParam
))
358 DialogBox(hDllInstance
, MAKEINTRESOURCE(IDD_GPL
), NULL
, GplDlgProc
);
359 SetForegroundWindow(GetParent(hwndDlg
));
365 lpnm
= (LPNMHDR
)lParam
;
370 /* Enable the Back and Next buttons */
371 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
372 if (SetupData
.UnattendSetup
)
374 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_LOCALEPAGE
);
380 SetupData
.UnattendSetup
= FALSE
;
398 WriteOwnerSettings(WCHAR
* OwnerName
,
399 WCHAR
* OwnerOrganization
)
406 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
407 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
412 if (res
!= ERROR_SUCCESS
)
417 res
= RegSetValueExW(hKey
,
422 (wcslen(OwnerName
) + 1) * sizeof(WCHAR
));
424 if (res
!= ERROR_SUCCESS
)
430 res
= RegSetValueExW(hKey
,
431 L
"RegisteredOrganization",
434 (LPBYTE
)OwnerOrganization
,
435 (wcslen(OwnerOrganization
) + 1) * sizeof(WCHAR
));
438 return (res
== ERROR_SUCCESS
);
441 static INT_PTR CALLBACK
442 OwnerPageDlgProc(HWND hwndDlg
,
448 WCHAR OwnerOrganization
[51];
450 WCHAR ErrorName
[256];
457 SendDlgItemMessage(hwndDlg
, IDC_OWNERNAME
, EM_LIMITTEXT
, 50, 0);
458 SendDlgItemMessage(hwndDlg
, IDC_OWNERORGANIZATION
, EM_LIMITTEXT
, 50, 0);
460 /* Set focus to owner name */
461 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
468 lpnm
= (LPNMHDR
)lParam
;
473 /* Enable the Back and Next buttons */
474 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
475 if (SetupData
.UnattendSetup
)
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
))
481 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_COMPUTERPAGE
);
489 if (GetDlgItemTextW(hwndDlg
, IDC_OWNERNAME
, OwnerName
, 50) == 0)
491 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
493 wcscpy(Title
, L
"ReactOS Setup");
495 if (0 == LoadStringW(hDllInstance
, IDS_WZD_NAME
, ErrorName
, sizeof(ErrorName
) / sizeof(ErrorName
[0])))
497 wcscpy(ErrorName
, L
"Setup cannot continue until you enter your name.");
499 MessageBoxW(hwndDlg
, ErrorName
, Title
, MB_ICONERROR
| MB_OK
);
501 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
502 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
507 OwnerOrganization
[0] = 0;
508 GetDlgItemTextW(hwndDlg
, IDC_OWNERORGANIZATION
, OwnerOrganization
, 50);
510 if (!WriteOwnerSettings(OwnerName
, OwnerOrganization
))
512 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
513 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
518 SetupData
.UnattendSetup
= FALSE
;
536 WriteComputerSettings(WCHAR
* ComputerName
, HWND hwndDlg
)
539 WCHAR ErrorComputerName
[256];
541 if (!SetComputerNameW(ComputerName
))
545 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
547 wcscpy(Title
, L
"ReactOS Setup");
549 if (0 == LoadStringW(hDllInstance
, IDS_WZD_SETCOMPUTERNAME
, ErrorComputerName
,
550 sizeof(ErrorComputerName
) / sizeof(ErrorComputerName
[0])))
552 wcscpy(ErrorComputerName
, L
"Setup failed to set the computer name.");
554 MessageBoxW(hwndDlg
, ErrorComputerName
, Title
, MB_ICONERROR
| MB_OK
);
560 /* Try to also set DNS hostname */
561 SetComputerNameExW(ComputerNamePhysicalDnsHostname
, ComputerName
);
563 /* Set the account domain name */
564 SetAccountDomain(ComputerName
, NULL
);
572 WriteDefaultLogonData(LPWSTR Domain
)
574 WCHAR szAdministratorName
[256];
578 if (LoadStringW(hDllInstance
,
579 IDS_ADMINISTRATOR_NAME
,
581 sizeof(szAdministratorName
) / sizeof(WCHAR
)) == 0)
583 wcscpy(szAdministratorName
, L
"Administrator");
586 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
587 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
591 if (lError
!= ERROR_SUCCESS
)
594 lError
= RegSetValueEx(hKey
,
599 (wcslen(Domain
)+ 1) * sizeof(WCHAR
));
600 if (lError
!= ERROR_SUCCESS
)
602 DPRINT1("RegSetValueEx(\"DefaultDomain\") failed!\n");
605 lError
= RegSetValueEx(hKey
,
609 (LPBYTE
)szAdministratorName
,
610 (wcslen(szAdministratorName
)+ 1) * sizeof(WCHAR
));
611 if (lError
!= ERROR_SUCCESS
)
613 DPRINT1("RegSetValueEx(\"DefaultUserName\") failed!\n");
622 /* lpBuffer will be filled with a 15-char string (plus the null terminator) */
624 GenerateComputerName(LPWSTR lpBuffer
)
626 static const WCHAR Chars
[] = L
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
627 static const unsigned cChars
= sizeof(Chars
) / sizeof(WCHAR
) - 1;
630 wcscpy(lpBuffer
, L
"REACTOS-");
632 srand(GetTickCount());
634 /* fill in 7 characters */
635 for (i
= 8; i
< 15; i
++)
636 lpBuffer
[i
] = Chars
[rand() % cChars
];
638 lpBuffer
[15] = UNICODE_NULL
; /* NULL-terminate */
641 static INT_PTR CALLBACK
642 ComputerPageDlgProc(HWND hwndDlg
,
647 WCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
648 WCHAR Password1
[128];
649 WCHAR Password2
[128];
652 WCHAR EmptyComputerName
[256], NotMatchPassword
[256], WrongPassword
[256];
655 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
657 wcscpy(Title
, L
"ReactOS Setup");
663 /* Generate a new pseudo-random computer name */
664 GenerateComputerName(ComputerName
);
666 /* Display current computer name */
667 SetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
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);
674 /* Set focus to computer name */
675 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
676 if (SetupData
.UnattendSetup
)
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
);
685 /* Store the administrator account name as the default user name */
686 WriteDefaultLogonData(SetupData
.ComputerName
);
692 lpnm
= (LPNMHDR
)lParam
;
697 /* Enable the Back and Next buttons */
698 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
699 if (SetupData
.UnattendSetup
&& WriteComputerSettings(SetupData
.ComputerName
, hwndDlg
))
701 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_DATETIMEPAGE
);
707 if (0 == GetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, MAX_COMPUTERNAME_LENGTH
+ 1))
709 if (0 == LoadStringW(hDllInstance
, IDS_WZD_COMPUTERNAME
, EmptyComputerName
,
710 sizeof(EmptyComputerName
) / sizeof(EmptyComputerName
[0])))
712 wcscpy(EmptyComputerName
, L
"Setup cannot continue until you enter the name of your computer.");
714 MessageBoxW(hwndDlg
, EmptyComputerName
, Title
, MB_ICONERROR
| MB_OK
);
715 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
716 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
720 /* No need to check computer name for invalid characters,
721 * SetComputerName() will do it for us */
723 if (!WriteComputerSettings(ComputerName
, hwndDlg
))
725 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
726 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
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))
735 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDEMPTY
, EmptyPassword
,
736 sizeof(EmptyPassword
) / sizeof(EmptyPassword
[0])))
738 wcscpy(EmptyPassword
, L
"You must enter a password !");
740 MessageBoxW(hwndDlg
, EmptyPassword
, Title
, MB_ICONERROR
| MB_OK
);
741 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
745 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 128);
746 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 128);
748 /* Check if passwords match */
749 if (wcscmp(Password1
, Password2
))
751 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDMATCH
, NotMatchPassword
,
752 sizeof(NotMatchPassword
) / sizeof(NotMatchPassword
[0])))
754 wcscpy(NotMatchPassword
, L
"The passwords you entered do not match. Please enter the desired password again.");
756 MessageBoxW(hwndDlg
, NotMatchPassword
, Title
, MB_ICONERROR
| MB_OK
);
757 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
761 /* Check password for invalid characters */
762 Password
= (PWCHAR
)Password1
;
765 if (!isprint(*Password
))
767 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDCHAR
, WrongPassword
,
768 sizeof(WrongPassword
) / sizeof(WrongPassword
[0])))
770 wcscpy(WrongPassword
, L
"The password you entered contains invalid characters. Please enter a cleaned password.");
772 MessageBoxW(hwndDlg
, WrongPassword
, Title
, MB_ICONERROR
| MB_OK
);
773 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
779 /* Set admin password */
780 SetAdministratorPassword(Password1
);
784 SetupData
.UnattendSetup
= FALSE
;
802 SetKeyboardLayoutName(HWND hwnd
)
805 TCHAR szLayoutPath
[256];
806 TCHAR szLocaleName
[32];
810 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
811 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
817 dwValueSize
= 16 * sizeof(TCHAR
);
818 if (RegQueryValueEx(hKey
,
829 _tcscpy(szLayoutPath
,
830 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"));
831 _tcscat(szLayoutPath
,
834 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
841 dwValueSize
= 32 * sizeof(TCHAR
);
842 if (RegQueryValueEx(hKey
,
859 RunControlPanelApplet(HWND hwnd
, PCWSTR pwszCPLParameters
)
861 if (pwszCPLParameters
)
863 STARTUPINFOW StartupInfo
;
864 PROCESS_INFORMATION ProcessInformation
;
865 WCHAR CmdLine
[MAX_PATH
] = L
"rundll32.exe shell32.dll,Control_RunDLL ";
867 ZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
868 StartupInfo
.cb
= sizeof(StartupInfo
);
870 ASSERT(_countof(CmdLine
) > wcslen(CmdLine
) + wcslen(pwszCPLParameters
));
871 wcscat(CmdLine
, pwszCPLParameters
);
873 if (!CreateProcessW(NULL
,
882 &ProcessInformation
))
884 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
888 WaitForSingleObject(ProcessInformation
.hProcess
, INFINITE
);
889 CloseHandle(ProcessInformation
.hThread
);
890 CloseHandle(ProcessInformation
.hProcess
);
895 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
901 WriteUserLocale(VOID
)
907 lcid
= GetSystemDefaultLCID();
909 if (GetLocaleInfoW(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_ILANGUAGE
, Locale
, sizeof(Locale
) / sizeof(Locale
[0])) != 0)
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
)
915 RegSetValueExW(hKey
, L
"Locale", 0, REG_SZ
, (LPBYTE
)Locale
, (wcslen(Locale
) + 1) * sizeof(WCHAR
));
921 static INT_PTR CALLBACK
922 LocalePageDlgProc(HWND hwndDlg
,
927 PSETUPDATA SetupData
;
929 /* Retrieve pointer to the global setup data */
930 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
936 /* Save pointer to the global setup data */
937 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
938 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
941 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
946 if (HIWORD(wParam
) == BN_CLICKED
)
948 switch (LOWORD(wParam
))
950 case IDC_CUSTOMLOCALE
:
951 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,5");
952 /* FIXME: Update input locale name */
955 case IDC_CUSTOMLAYOUT
:
956 RunControlPanelApplet(hwndDlg
, L
"input.dll,@1");
964 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
969 /* Enable the Back and Next buttons */
970 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
971 if (SetupData
->UnattendSetup
)
973 WCHAR wszPath
[MAX_PATH
];
974 if (GetRosInstallCD(wszPath
, _countof(wszPath
)))
976 WCHAR wszParams
[1024];
977 swprintf(wszParams
, L
"intl.cpl,,/f:\"%sreactos\\unattend.inf\"", wszPath
);
978 RunControlPanelApplet(hwndDlg
, wszParams
);
982 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,/f:\"unattend.inf\"");
985 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_OWNERPAGE
);
994 SetupData
->UnattendSetup
= FALSE
;
1011 static PTIMEZONE_ENTRY
1012 GetLargerTimeZoneEntry(PSETUPDATA SetupData
, DWORD Index
)
1014 PTIMEZONE_ENTRY Entry
;
1016 Entry
= SetupData
->TimeZoneListHead
;
1017 while (Entry
!= NULL
)
1019 if (Entry
->Index
>= Index
)
1022 Entry
= Entry
->Next
;
1030 CreateTimeZoneList(PSETUPDATA SetupData
)
1032 WCHAR szKeyName
[256];
1040 PTIMEZONE_ENTRY Entry
;
1041 PTIMEZONE_ENTRY Current
;
1043 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1044 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1053 dwNameSize
= 256 * sizeof(WCHAR
);
1054 lError
= RegEnumKeyExW(hZonesKey
,
1062 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
1065 if (RegOpenKeyExW(hZonesKey
,
1072 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
1075 RegCloseKey(hZoneKey
);
1079 dwValueSize
= 64 * sizeof(WCHAR
);
1080 if (RegQueryValueExW(hZoneKey
,
1084 (LPBYTE
)&Entry
->Description
,
1087 RegCloseKey(hZoneKey
);
1091 dwValueSize
= 32 * sizeof(WCHAR
);
1092 if (RegQueryValueExW(hZoneKey
,
1096 (LPBYTE
)&Entry
->StandardName
,
1099 RegCloseKey(hZoneKey
);
1103 dwValueSize
= 32 * sizeof(WCHAR
);
1104 if (RegQueryValueExW(hZoneKey
,
1108 (LPBYTE
)&Entry
->DaylightName
,
1111 RegCloseKey(hZoneKey
);
1115 dwValueSize
= sizeof(DWORD
);
1116 if (RegQueryValueExW(hZoneKey
,
1120 (LPBYTE
)&Entry
->Index
,
1123 RegCloseKey(hZoneKey
);
1127 dwValueSize
= sizeof(TZ_INFO
);
1128 if (RegQueryValueExW(hZoneKey
,
1132 (LPBYTE
)&Entry
->TimezoneInfo
,
1135 RegCloseKey(hZoneKey
);
1139 RegCloseKey(hZoneKey
);
1141 if (SetupData
->TimeZoneListHead
== NULL
&&
1142 SetupData
->TimeZoneListTail
== NULL
)
1146 SetupData
->TimeZoneListHead
= Entry
;
1147 SetupData
->TimeZoneListTail
= Entry
;
1151 Current
= GetLargerTimeZoneEntry(SetupData
, Entry
->Index
);
1152 if (Current
!= NULL
)
1154 if (Current
== SetupData
->TimeZoneListHead
)
1156 /* Prepend to head */
1158 Entry
->Next
= SetupData
->TimeZoneListHead
;
1159 SetupData
->TimeZoneListHead
->Prev
= Entry
;
1160 SetupData
->TimeZoneListHead
= Entry
;
1164 /* Insert before current */
1165 Entry
->Prev
= Current
->Prev
;
1166 Entry
->Next
= Current
;
1167 Current
->Prev
->Next
= Entry
;
1168 Current
->Prev
= Entry
;
1173 /* Append to tail */
1174 Entry
->Prev
= SetupData
->TimeZoneListTail
;
1176 SetupData
->TimeZoneListTail
->Next
= Entry
;
1177 SetupData
->TimeZoneListTail
= Entry
;
1184 RegCloseKey(hZonesKey
);
1189 DestroyTimeZoneList(PSETUPDATA SetupData
)
1191 PTIMEZONE_ENTRY Entry
;
1193 while (SetupData
->TimeZoneListHead
!= NULL
)
1195 Entry
= SetupData
->TimeZoneListHead
;
1197 SetupData
->TimeZoneListHead
= Entry
->Next
;
1198 if (SetupData
->TimeZoneListHead
!= NULL
)
1200 SetupData
->TimeZoneListHead
->Prev
= NULL
;
1203 HeapFree(GetProcessHeap(), 0, Entry
);
1206 SetupData
->TimeZoneListTail
= NULL
;
1210 GetTimeZoneListIndex(LPDWORD lpIndex
)
1212 WCHAR szLanguageIdString
[9];
1219 BOOL bFound
= FALSE
;
1220 unsigned long iLanguageID
;
1222 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1223 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
1229 dwValueSize
= 9 * sizeof(WCHAR
);
1230 if (RegQueryValueExW(hKey
,
1234 (LPBYTE
)szLanguageIdString
,
1241 iLanguageID
= wcstoul(szLanguageIdString
, NULL
, 16);
1244 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1245 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1252 if (RegQueryValueExW(hKey
,
1263 Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
1270 if (RegQueryValueExW(hKey
,
1277 HeapFree(GetProcessHeap(), 0, Buffer
);
1287 Length
= wcslen(Ptr
);
1288 if (wcstoul(Ptr
, NULL
, 16) == iLanguageID
)
1291 Ptr
= Ptr
+ Length
+ 1;
1297 *lpIndex
= wcstoul(Ptr
, &End
, 10);
1298 HeapFree(GetProcessHeap(), 0, Buffer
);
1302 Length
= wcslen(Ptr
);
1303 Ptr
= Ptr
+ Length
+ 1;
1306 HeapFree(GetProcessHeap(), 0, Buffer
);
1313 ShowTimeZoneList(HWND hwnd
, PSETUPDATA SetupData
, DWORD dwEntryIndex
)
1315 PTIMEZONE_ENTRY Entry
;
1319 GetTimeZoneListIndex(&dwEntryIndex
);
1321 Entry
= SetupData
->TimeZoneListHead
;
1322 while (Entry
!= NULL
)
1324 dwCount
= SendMessage(hwnd
,
1327 (LPARAM
)Entry
->Description
);
1329 if (dwEntryIndex
!= 0 && dwEntryIndex
== Entry
->Index
)
1332 Entry
= Entry
->Next
;
1343 SetLocalTimeZone(HWND hwnd
, PSETUPDATA SetupData
)
1345 TIME_ZONE_INFORMATION TimeZoneInformation
;
1346 PTIMEZONE_ENTRY Entry
;
1350 dwIndex
= SendMessage(hwnd
,
1356 Entry
= SetupData
->TimeZoneListHead
;
1363 Entry
= Entry
->Next
;
1366 wcscpy(TimeZoneInformation
.StandardName
,
1367 Entry
->StandardName
);
1368 wcscpy(TimeZoneInformation
.DaylightName
,
1369 Entry
->DaylightName
);
1371 TimeZoneInformation
.Bias
= Entry
->TimezoneInfo
.Bias
;
1372 TimeZoneInformation
.StandardBias
= Entry
->TimezoneInfo
.StandardBias
;
1373 TimeZoneInformation
.DaylightBias
= Entry
->TimezoneInfo
.DaylightBias
;
1375 memcpy(&TimeZoneInformation
.StandardDate
,
1376 &Entry
->TimezoneInfo
.StandardDate
,
1377 sizeof(SYSTEMTIME
));
1378 memcpy(&TimeZoneInformation
.DaylightDate
,
1379 &Entry
->TimezoneInfo
.DaylightDate
,
1380 sizeof(SYSTEMTIME
));
1382 /* Set time zone information */
1383 SetTimeZoneInformation(&TimeZoneInformation
);
1388 GetLocalSystemTime(HWND hwnd
, PSETUPDATA SetupData
)
1393 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) != GDT_VALID
)
1398 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) != GDT_VALID
)
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
;
1417 SetAutoDaylightInfo(HWND hwnd
)
1422 if (SendMessage(hwnd
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
)
1424 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1425 L
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
1431 RegSetValueExW(hKey
,
1432 L
"DisableAutoDaylightTimeSet",
1443 SetSystemLocalTime(HWND hwnd
, PSETUPDATA SetupData
)
1448 * Call SetLocalTime twice to ensure correct results
1450 Ret
= SetLocalTime(&SetupData
->SystemTime
) &&
1451 SetLocalTime(&SetupData
->SystemTime
);
1457 WriteDateTimeSettings(HWND hwndDlg
, PSETUPDATA SetupData
)
1460 WCHAR ErrorLocalTime
[256];
1461 GetLocalSystemTime(hwndDlg
, SetupData
);
1462 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1465 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1466 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1468 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
1470 wcscpy(Title
, L
"ReactOS Setup");
1472 if (0 == LoadStringW(hDllInstance
, IDS_WZD_LOCALTIME
, ErrorLocalTime
,
1473 sizeof(ErrorLocalTime
) / sizeof(ErrorLocalTime
[0])))
1475 wcscpy(ErrorLocalTime
, L
"Setup was unable to set the local time.");
1477 MessageBoxW(hwndDlg
, ErrorLocalTime
, Title
, MB_ICONWARNING
| MB_OK
);
1484 static INT_PTR CALLBACK
1485 DateTimePageDlgProc(HWND hwndDlg
,
1490 PSETUPDATA SetupData
;
1492 /* Retrieve pointer to the global setup data */
1493 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1499 /* Save pointer to the global setup data */
1500 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1501 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1503 CreateTimeZoneList(SetupData
);
1505 if (SetupData
->UnattendSetup
)
1507 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1508 SetupData
, SetupData
->TimeZoneIndex
);
1510 if (!SetupData
->DisableAutoDaylightTimeSet
)
1512 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1517 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1518 SetupData
, 85 /* GMT time zone */);
1520 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1529 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1534 /* Enable the Back and Next buttons */
1535 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
1536 if (SetupData
->UnattendSetup
&& WriteDateTimeSettings(hwndDlg
, SetupData
))
1538 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_PROCESSPAGE
);
1545 WriteDateTimeSettings(hwndDlg
, SetupData
);
1550 SetupData
->UnattendSetup
= FALSE
;
1560 DestroyTimeZoneList(SetupData
);
1571 static UINT CALLBACK
1572 RegistrationNotificationProc(PVOID Context
,
1577 PREGISTRATIONDATA RegistrationData
;
1578 REGISTRATIONNOTIFY RegistrationNotify
;
1579 PSP_REGISTER_CONTROL_STATUSW StatusInfo
;
1581 WCHAR ErrorMessage
[128];
1583 RegistrationData
= (PREGISTRATIONDATA
) Context
;
1585 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
||
1586 SPFILENOTIFY_ENDREGISTRATION
== Notification
)
1588 StatusInfo
= (PSP_REGISTER_CONTROL_STATUSW
) Param1
;
1589 RegistrationNotify
.CurrentItem
= wcsrchr(StatusInfo
->FileName
, L
'\\');
1590 if (NULL
== RegistrationNotify
.CurrentItem
)
1592 RegistrationNotify
.CurrentItem
= StatusInfo
->FileName
;
1596 RegistrationNotify
.CurrentItem
++;
1599 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
)
1601 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1602 StatusInfo
->FileName
);
1603 RegistrationNotify
.ErrorMessage
= NULL
;
1604 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
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
)
1614 switch(StatusInfo
->FailureCode
)
1616 case SPREG_LOADLIBRARY
:
1617 MessageID
= IDS_LOADLIBRARY_FAILED
;
1619 case SPREG_GETPROCADDR
:
1620 MessageID
= IDS_GETPROCADDR_FAILED
;
1623 MessageID
= IDS_REGSVR_FAILED
;
1625 case SPREG_DLLINSTALL
:
1626 MessageID
= IDS_DLLINSTALL_FAILED
;
1629 MessageID
= IDS_TIMEOUT
;
1632 MessageID
= IDS_REASON_UNKNOWN
;
1635 if (0 == LoadStringW(hDllInstance
, MessageID
,
1637 sizeof(ErrorMessage
) /
1638 sizeof(ErrorMessage
[0])))
1640 ErrorMessage
[0] = L
'\0';
1642 if (SPREG_TIMEOUT
!= StatusInfo
->FailureCode
)
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
);
1650 RegistrationNotify
.ErrorMessage
= ErrorMessage
;
1654 RegistrationNotify
.ErrorMessage
= NULL
;
1656 if (RegistrationData
->Registered
< RegistrationData
->DllCount
)
1658 RegistrationData
->Registered
++;
1662 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1663 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1664 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1665 0, (LPARAM
) &RegistrationNotify
);
1671 DPRINT1("Received unexpected notification %u\n", Notification
);
1672 return SetupDefaultQueueCallback(RegistrationData
->DefaultContext
,
1673 Notification
, Param1
, Param2
);
1678 static DWORD CALLBACK
1679 RegistrationProc(LPVOID Parameter
)
1681 PREGISTRATIONDATA RegistrationData
;
1682 REGISTRATIONNOTIFY RegistrationNotify
;
1683 DWORD LastError
= NO_ERROR
;
1684 WCHAR UnknownError
[84];
1686 RegistrationData
= (PREGISTRATIONDATA
) Parameter
;
1687 RegistrationData
->Registered
= 0;
1688 RegistrationData
->DefaultContext
= SetupInitDefaultQueueCallback(RegistrationData
->hwndDlg
);
1692 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData
->hwndDlg
),
1694 L
"RegistrationPhase2",
1696 SPINST_REGISTERCALLBACKAWARE
|
1701 RegistrationNotificationProc
,
1706 LastError
= GetLastError();
1709 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1711 DPRINT("Catching exception\n");
1712 LastError
= RtlNtStatusToDosError(_SEH2_GetExceptionCode());
1716 if (NO_ERROR
== LastError
)
1718 RegistrationNotify
.ErrorMessage
= NULL
;
1722 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1724 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1725 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, LastError
, 0,
1726 (LPWSTR
) &RegistrationNotify
.ErrorMessage
, 0,
1729 if (0 == LoadStringW(hDllInstance
, IDS_UNKNOWN_ERROR
,
1731 sizeof(UnknownError
) / sizeof(UnknownError
[0]) -
1734 wcscpy(UnknownError
, L
"Unknown error");
1736 wcscat(UnknownError
, L
" ");
1737 _ultow(LastError
, UnknownError
+ wcslen(UnknownError
), 10);
1738 RegistrationNotify
.ErrorMessage
= UnknownError
;
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
)
1750 LocalFree((PVOID
) RegistrationNotify
.ErrorMessage
);
1753 SetupTermDefaultQueueCallback(RegistrationData
->DefaultContext
);
1754 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1756 RegisterTypeLibraries(hSysSetupInf
, L
"TypeLibraries");
1758 // FIXME: Move this call to a separate cleanup page!
1759 RtlCreateBootStatusDataFile();
1766 StartComponentRegistration(HWND hwndDlg
, PULONG MaxProgress
)
1768 HANDLE RegistrationThread
;
1771 WCHAR SectionName
[512];
1772 PREGISTRATIONDATA RegistrationData
;
1775 if (! SetupFindFirstLineW(hSysSetupInf
, L
"RegistrationPhase2",
1776 L
"RegisterDlls", &Context
))
1778 DPRINT1("No RegistrationPhase2 section found\n");
1781 if (! SetupGetStringFieldW(&Context
, 1, SectionName
,
1782 sizeof(SectionName
) / sizeof(SectionName
[0]),
1785 DPRINT1("Unable to retrieve section name\n");
1788 DllCount
= SetupGetLineCountW(hSysSetupInf
, SectionName
);
1789 DPRINT("SectionName %S DllCount %ld\n", SectionName
, DllCount
);
1792 SetLastError(STATUS_NOT_FOUND
);
1796 *MaxProgress
= (ULONG
) DllCount
;
1799 * Create a background thread to do the actual registrations, so the
1800 * main thread can just run its message loop.
1802 RegistrationThread
= NULL
;
1803 RegistrationData
= HeapAlloc(GetProcessHeap(), 0,
1804 sizeof(REGISTRATIONDATA
));
1805 if (RegistrationData
!= NULL
)
1807 RegistrationData
->hwndDlg
= hwndDlg
;
1808 RegistrationData
->DllCount
= DllCount
;
1809 RegistrationThread
= CreateThread(NULL
, 0, RegistrationProc
,
1810 (LPVOID
) RegistrationData
, 0, NULL
);
1811 if (RegistrationThread
!= NULL
)
1813 CloseHandle(RegistrationThread
);
1817 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1818 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1824 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1832 static INT_PTR CALLBACK
1833 ProcessPageDlgProc(HWND hwndDlg
,
1838 PSETUPDATA SetupData
;
1839 PREGISTRATIONNOTIFY RegistrationNotify
;
1840 static UINT oldActivityID
= -1;
1843 /* Retrieve pointer to the global setup data */
1844 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1850 /* Save pointer to the global setup data */
1851 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1852 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1858 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1859 ULONG MaxProgress
= 0;
1864 /* Disable the Back and Next buttons */
1865 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
1867 StartComponentRegistration(hwndDlg
, &MaxProgress
);
1869 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
,
1870 0, MAKELPARAM(0, MaxProgress
));
1871 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1879 SetupData
->UnattendSetup
= FALSE
;
1888 case PM_REGISTRATION_NOTIFY
:
1891 RegistrationNotify
= (PREGISTRATIONNOTIFY
) lParam
;
1892 // update if necessary only
1893 if (oldActivityID
!= RegistrationNotify
->ActivityID
)
1895 if (0 != LoadStringW(hDllInstance
, RegistrationNotify
->ActivityID
,
1897 sizeof(Activity
) / sizeof(Activity
[0])))
1899 SendDlgItemMessageW(hwndDlg
, IDC_ACTIVITY
, WM_SETTEXT
,
1900 0, (LPARAM
) Activity
);
1902 oldActivityID
= RegistrationNotify
->ActivityID
;
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
)
1911 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
,
1912 Title
, sizeof(Title
) / sizeof(Title
[0])))
1914 wcscpy(Title
, L
"ReactOS Setup");
1916 MessageBoxW(hwndDlg
, RegistrationNotify
->ErrorMessage
,
1917 Title
, MB_ICONERROR
| MB_OK
);
1924 if(!SetupData
->UnattendSetup
&& !SetupData
->DisableVmwInst
)
1925 RunVMWInstall(GetParent(hwndDlg
));
1928 /* Enable the Back and Next buttons */
1929 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
1930 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
1944 SetInstallationCompleted(VOID
)
1947 DWORD InProgress
= 0;
1950 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1954 &hKey
) == ERROR_SUCCESS
)
1956 RegSetValueExW( hKey
, L
"SystemSetupInProgress", 0, REG_DWORD
, (LPBYTE
)&InProgress
, sizeof(InProgress
) );
1957 RegCloseKey( hKey
);
1960 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1961 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
1964 &hKey
) == ERROR_SUCCESS
)
1966 InstallDate
= (DWORD
)time(NULL
);
1967 RegSetValueExW( hKey
, L
"InstallDate", 0, REG_DWORD
, (LPBYTE
)&InstallDate
, sizeof(InstallDate
) );
1968 RegCloseKey( hKey
);
1972 static INT_PTR CALLBACK
1973 FinishDlgProc(HWND hwndDlg
,
1983 /* Get pointer to the global setup data */
1984 PSETUPDATA SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1986 /* Run the Wine Gecko prompt */
1987 Control_RunDLLW(GetDesktopWindow(), 0, L
"appwiz.cpl install_gecko", SW_SHOW
);
1989 /* Set title font */
1990 SendDlgItemMessage(hwndDlg
,
1993 (WPARAM
)SetupData
->hTitleFont
,
1995 if (SetupData
->UnattendSetup
)
1997 KillTimer(hwndDlg
, 1);
1998 SetInstallationCompleted();
2006 SetInstallationCompleted();
2016 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
2017 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
2018 if (Position
== 300)
2020 KillTimer(hwndDlg
, 1);
2021 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
2025 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
2032 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
2037 /* Enable the correct buttons on for the active page */
2038 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
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
);
2047 DestroyWindow(GetParent(hwndDlg
));
2065 ProcessUnattendInf(HINF hUnattendedInf
)
2067 INFCONTEXT InfContext
;
2069 WCHAR szValue
[MAX_PATH
];
2073 if (!SetupFindFirstLineW(hUnattendedInf
,
2075 L
"UnattendSetupEnabled",
2078 DPRINT1("Error: Cant find UnattendSetupEnabled Key! %d\n", GetLastError());
2082 if (!SetupGetStringFieldW(&InfContext
,
2085 sizeof(szValue
) / sizeof(WCHAR
),
2088 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2092 if (wcscmp(szValue
, L
"yes") != 0)
2094 DPRINT("Unattend setup was disabled by UnattendSetupEnabled key.\n");
2098 if (!SetupFindFirstLineW(hUnattendedInf
,
2103 DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError());
2110 if (!SetupGetStringFieldW(&InfContext
,
2113 sizeof(szName
) / sizeof(WCHAR
),
2116 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2120 if (!SetupGetStringFieldW(&InfContext
,
2123 sizeof(szValue
) / sizeof(WCHAR
),
2126 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2129 DPRINT1("Name %S Value %S\n", szName
, szValue
);
2130 if (!wcscmp(szName
, L
"FullName"))
2132 if ((sizeof(SetupData
.OwnerName
) / sizeof(TCHAR
)) > LineLength
)
2134 wcscpy(SetupData
.OwnerName
, szValue
);
2137 else if (!wcscmp(szName
, L
"OrgName"))
2139 if ((sizeof(SetupData
.OwnerOrganization
) / sizeof(WCHAR
)) > LineLength
)
2141 wcscpy(SetupData
.OwnerOrganization
, szValue
);
2144 else if (!wcscmp(szName
, L
"ComputerName"))
2146 if ((sizeof(SetupData
.ComputerName
) / sizeof(WCHAR
)) > LineLength
)
2148 wcscpy(SetupData
.ComputerName
, szValue
);
2151 else if (!wcscmp(szName
, L
"AdminPassword"))
2153 if ((sizeof(SetupData
.AdminPassword
) / sizeof(WCHAR
)) > LineLength
)
2155 wcscpy(SetupData
.AdminPassword
, szValue
);
2158 else if (!wcscmp(szName
, L
"TimeZoneIndex"))
2160 SetupData
.TimeZoneIndex
= _wtoi(szValue
);
2162 else if (!wcscmp(szName
, L
"DisableAutoDaylightTimeSet"))
2164 SetupData
.DisableAutoDaylightTimeSet
= _wtoi(szValue
);
2166 else if (!wcscmp(szName
, L
"DisableVmwInst"))
2168 if(!wcscmp(szValue
, L
"yes"))
2169 SetupData
.DisableVmwInst
= 1;
2171 SetupData
.DisableVmwInst
= 0;
2175 while (SetupFindNextLine(&InfContext
, &InfContext
));
2177 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
2178 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
2181 &hKey
) != ERROR_SUCCESS
)
2183 DPRINT1("Error: failed to open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\n");
2188 if (SetupFindFirstLineW(hUnattendedInf
,
2197 if(SetupGetStringFieldW(&InfContext
,
2200 sizeof(szValue
) / sizeof(WCHAR
),
2203 WCHAR szPath
[MAX_PATH
];
2204 swprintf(szName
, L
"%d", i
);
2205 DPRINT("szName %S szValue %S\n", szName
, szValue
);
2207 if (ExpandEnvironmentStringsW(szValue
, szPath
, MAX_PATH
))
2209 DPRINT("value %S\n", szPath
);
2210 if (RegSetValueExW(hKey
,
2214 (const BYTE
*)szPath
,
2215 (wcslen(szPath
) + 1) * sizeof(WCHAR
)) == ERROR_SUCCESS
)
2221 } while(SetupFindNextLine(&InfContext
, &InfContext
));
2229 * GetRosInstallCD should find the path to ros installation medium
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
2235 * The best way to implement this is to set the key
2236 * HKLM\Software\Microsoft\Windows NT\CurrentVersion\SourcePath (REG_SZ)
2240 GetRosInstallCD(WCHAR
*pwszPath
, DWORD cchPathMax
)
2242 WCHAR wszDrives
[512];
2246 cchDrives
= GetLogicalDriveStringsW(_countof(wszDrives
) - 1, wszDrives
);
2247 if (cchDrives
== 0 || cchDrives
>= _countof(wszDrives
))
2249 /* buffer too small or failure */
2250 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"GetLogicalDriveStringsW failed");
2254 for (pwszDrive
= wszDrives
; pwszDrive
[0]; pwszDrive
+= wcslen(pwszDrive
) + 1)
2256 if (GetDriveTypeW(pwszDrive
) == DRIVE_CDROM
)
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
)
2263 /* the file exists, so this is the right drive */
2264 wcsncpy(pwszPath
, pwszDrive
, cchPathMax
);
2265 OutputDebugStringW(L
"GetRosInstallCD: ");OutputDebugStringW(pwszPath
);OutputDebugStringW(L
"\n");
2275 ProcessUnattendSetup(VOID
)
2277 WCHAR szPath
[MAX_PATH
];
2278 HINF hUnattendedInf
;
2281 if (!GetRosInstallCD(szPath
, MAX_PATH
))
2283 /* no cd drive found */
2287 dwLength
= wcslen(szPath
);
2288 if (dwLength
+ 21 > MAX_PATH
)
2291 * allocate bigger buffer
2296 wcscat(szPath
, L
"reactos\\unattend.inf");
2298 hUnattendedInf
= SetupOpenInfFileW(szPath
,
2303 if (hUnattendedInf
!= INVALID_HANDLE_VALUE
)
2305 SetupData
.UnattendSetup
= ProcessUnattendInf(hUnattendedInf
);
2306 SetupCloseInfFile(hUnattendedInf
);
2314 PROPSHEETHEADER psh
;
2315 HPROPSHEETPAGE ahpsp
[8];
2316 PROPSHEETPAGE psp
= {0};
2321 /* Clear setup data */
2322 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
2324 ProcessUnattendSetup();
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
;
2401 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
2402 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
2404 /* Create title font */
2405 SetupData
.hTitleFont
= CreateTitleFont();
2407 /* Display the wizard */
2408 hWnd
= (HWND
)PropertySheet(&psh
);
2409 ShowWindow(hWnd
, SW_SHOW
);
2411 while (GetMessage(&msg
, NULL
, 0, 0))
2413 if(!IsDialogMessage(hWnd
, &msg
))
2415 TranslateMessage(&msg
);
2416 DispatchMessage(&msg
);
2420 DeleteObject(SetupData
.hTitleFont
);