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 *****************************************************************/
19 #define PM_REGISTRATION_NOTIFY (WM_APP + 1)
20 /* Private Message used to communicate progress from the background
21 registration thread to the main thread.
22 wParam = 0 Registration in progress
23 = 1 Registration completed
24 lParam = Pointer to a REGISTRATIONNOTIFY structure */
26 typedef struct _REGISTRATIONNOTIFY
32 } REGISTRATIONNOTIFY
, *PREGISTRATIONNOTIFY
;
34 typedef struct _REGISTRATIONDATA
40 } REGISTRATIONDATA
, *PREGISTRATIONDATA
;
42 /* GLOBALS ******************************************************************/
47 /* FUNCTIONS ****************************************************************/
49 extern void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
);
52 GetRosInstallCD(WCHAR
*pwszPath
, DWORD cchPathMax
);
56 RunVMWInstall(HWND hWnd
)
58 PROCESS_INFORMATION ProcInfo
;
62 WCHAR InstallName
[] = L
"vmwinst.exe";
64 ZeroMemory(&si
, sizeof(si
));
67 if(CreateProcessW(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
68 NULL
, NULL
, &si
, &ProcInfo
))
70 EnableWindow(hWnd
, FALSE
);
73 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
75 if (msg
.message
== WM_QUIT
)
77 TranslateMessage(&msg
);
78 DispatchMessage(&msg
);
81 ret
= MsgWaitForMultipleObjects(1, &ProcInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
| QS_ALLINPUT
);
82 if (ret
== WAIT_OBJECT_0
)
86 EnableWindow(hWnd
, TRUE
);
88 CloseHandle(ProcInfo
.hThread
);
89 CloseHandle(ProcInfo
.hProcess
);
97 CenterWindow(HWND hWnd
)
103 hWndParent
= GetParent(hWnd
);
104 if (hWndParent
== NULL
)
105 hWndParent
= GetDesktopWindow();
107 GetWindowRect(hWndParent
, &rcParent
);
108 GetWindowRect(hWnd
, &rcWindow
);
112 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
113 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
121 CreateTitleFont(VOID
)
123 NONCLIENTMETRICSW ncm
;
129 ncm
.cbSize
= sizeof(NONCLIENTMETRICSW
);
130 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
132 LogFont
= ncm
.lfMessageFont
;
133 LogFont
.lfWeight
= FW_BOLD
;
134 wcscpy(LogFont
.lfFaceName
, L
"MS Shell Dlg");
138 LogFont
.lfHeight
= 0 - GetDeviceCaps(hdc
, LOGPIXELSY
) * FontSize
/ 72;
139 hFont
= CreateFontIndirectW(&LogFont
);
140 ReleaseDC(NULL
, hdc
);
146 static INT_PTR CALLBACK
147 GplDlgProc(HWND hwndDlg
,
152 HRSRC GplTextResource
;
162 GplTextResource
= FindResourceW(hDllInstance
, MAKEINTRESOURCE(IDR_GPL
), L
"RT_TEXT");
163 if (NULL
== GplTextResource
)
167 Size
= SizeofResource(hDllInstance
, GplTextResource
);
172 GplText
= HeapAlloc(GetProcessHeap(), 0, Size
+ 1);
177 GplTextMem
= LoadResource(hDllInstance
, GplTextResource
);
178 if (NULL
== GplTextMem
)
180 HeapFree(GetProcessHeap(), 0, GplText
);
183 GplTextLocked
= LockResource(GplTextMem
);
184 if (NULL
== GplTextLocked
)
186 HeapFree(GetProcessHeap(), 0, GplText
);
189 memcpy(GplText
, GplTextLocked
, Size
);
190 GplText
[Size
] = '\0';
191 SendMessageA(GetDlgItem(hwndDlg
, IDC_GPL_TEXT
), WM_SETTEXT
, 0, (LPARAM
) GplText
);
192 HeapFree(GetProcessHeap(), 0, GplText
);
193 SetFocus(GetDlgItem(hwndDlg
, IDOK
));
197 EndDialog(hwndDlg
, IDCANCEL
);
201 if (HIWORD(wParam
) == BN_CLICKED
&& IDOK
== LOWORD(wParam
))
203 EndDialog(hwndDlg
, IDOK
);
215 static INT_PTR CALLBACK
216 WelcomeDlgProc(HWND hwndDlg
,
225 PSETUPDATA SetupData
;
229 /* Get pointer to the global setup data */
230 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
232 hwndControl
= GetParent(hwndDlg
);
234 /* Center the wizard window */
235 CenterWindow (hwndControl
);
237 /* Hide the system menu */
238 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
239 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
241 /* Hide and disable the 'Cancel' button */
242 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
243 ShowWindow (hwndControl
, SW_HIDE
);
244 EnableWindow (hwndControl
, FALSE
);
247 SendDlgItemMessage(hwndDlg
,
250 (WPARAM
)SetupData
->hTitleFont
,
258 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
263 /* Enable the Next button */
264 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
265 if (SetupData
.UnattendSetup
)
267 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_ACKPAGE
);
273 SetupData
.UnattendSetup
= FALSE
;
290 static INT_PTR CALLBACK
291 AckPageDlgProc(HWND hwndDlg
,
298 PWCHAR End
, CurrentProject
;
299 INT ProjectsSize
, ProjectsCount
;
309 Projects
= HeapAlloc(GetProcessHeap(), 0, ProjectsSize
* sizeof(WCHAR
));
310 if (NULL
== Projects
)
314 ProjectsCount
= LoadStringW(hDllInstance
, IDS_ACKPROJECTS
, Projects
, ProjectsSize
);
315 if (0 == ProjectsCount
)
317 HeapFree(GetProcessHeap(), 0, Projects
);
320 if (ProjectsCount
< ProjectsSize
- 1)
324 HeapFree(GetProcessHeap(), 0, Projects
);
328 CurrentProject
= Projects
;
329 while (L
'\0' != *CurrentProject
)
331 End
= wcschr(CurrentProject
, L
'\n');
336 (void)ListBox_AddString(GetDlgItem(hwndDlg
, IDC_PROJECTS
), CurrentProject
);
339 CurrentProject
= End
+ 1;
343 CurrentProject
+= wcslen(CurrentProject
);
346 HeapFree(GetProcessHeap(), 0, Projects
);
351 if (HIWORD(wParam
) == BN_CLICKED
&& IDC_VIEWGPL
== LOWORD(wParam
))
353 DialogBox(hDllInstance
, MAKEINTRESOURCE(IDD_GPL
), NULL
, GplDlgProc
);
354 SetForegroundWindow(GetParent(hwndDlg
));
360 lpnm
= (LPNMHDR
)lParam
;
365 /* Enable the Back and Next buttons */
366 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
367 if (SetupData
.UnattendSetup
)
369 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_LOCALEPAGE
);
375 SetupData
.UnattendSetup
= FALSE
;
393 WriteOwnerSettings(WCHAR
* OwnerName
,
394 WCHAR
* OwnerOrganization
)
401 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
402 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
407 if (res
!= ERROR_SUCCESS
)
412 res
= RegSetValueExW(hKey
,
417 (wcslen(OwnerName
) + 1) * sizeof(WCHAR
));
419 if (res
!= ERROR_SUCCESS
)
425 res
= RegSetValueExW(hKey
,
426 L
"RegisteredOrganization",
429 (LPBYTE
)OwnerOrganization
,
430 (wcslen(OwnerOrganization
) + 1) * sizeof(WCHAR
));
433 return (res
== ERROR_SUCCESS
);
436 static INT_PTR CALLBACK
437 OwnerPageDlgProc(HWND hwndDlg
,
443 WCHAR OwnerOrganization
[51];
445 WCHAR ErrorName
[256];
452 SendDlgItemMessage(hwndDlg
, IDC_OWNERNAME
, EM_LIMITTEXT
, 50, 0);
453 SendDlgItemMessage(hwndDlg
, IDC_OWNERORGANIZATION
, EM_LIMITTEXT
, 50, 0);
455 /* Set focus to owner name */
456 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
463 lpnm
= (LPNMHDR
)lParam
;
468 /* Enable the Back and Next buttons */
469 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
470 if (SetupData
.UnattendSetup
)
472 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerName
);
473 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERORGANIZATION
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerOrganization
);
474 if (WriteOwnerSettings(SetupData
.OwnerName
, SetupData
.OwnerOrganization
))
476 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_COMPUTERPAGE
);
484 if (GetDlgItemTextW(hwndDlg
, IDC_OWNERNAME
, OwnerName
, 50) == 0)
486 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
488 wcscpy(Title
, L
"ReactOS Setup");
490 if (0 == LoadStringW(hDllInstance
, IDS_WZD_NAME
, ErrorName
, sizeof(ErrorName
) / sizeof(ErrorName
[0])))
492 wcscpy(ErrorName
, L
"Setup cannot continue until you enter your name.");
494 MessageBoxW(hwndDlg
, ErrorName
, Title
, MB_ICONERROR
| MB_OK
);
496 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
497 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
502 OwnerOrganization
[0] = 0;
503 GetDlgItemTextW(hwndDlg
, IDC_OWNERORGANIZATION
, OwnerOrganization
, 50);
505 if (!WriteOwnerSettings(OwnerName
, OwnerOrganization
))
507 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
508 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
513 SetupData
.UnattendSetup
= FALSE
;
531 WriteComputerSettings(WCHAR
* ComputerName
, HWND hwndDlg
)
534 WCHAR ErrorComputerName
[256];
535 if (!SetComputerNameW(ComputerName
))
537 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
539 wcscpy(Title
, L
"ReactOS Setup");
541 if (0 == LoadStringW(hDllInstance
, IDS_WZD_SETCOMPUTERNAME
, ErrorComputerName
,
542 sizeof(ErrorComputerName
) / sizeof(ErrorComputerName
[0])))
544 wcscpy(ErrorComputerName
, L
"Setup failed to set the computer name.");
546 MessageBoxW(hwndDlg
, ErrorComputerName
, Title
, MB_ICONERROR
| MB_OK
);
551 /* Try to also set DNS hostname */
552 SetComputerNameExW(ComputerNamePhysicalDnsHostname
, ComputerName
);
554 /* Set the account domain name */
555 SetAccountDomain(ComputerName
, NULL
);
560 /* lpBuffer will be filled with a 15-char string (plus the null terminator) */
562 GenerateComputerName(LPWSTR lpBuffer
)
564 static const WCHAR Chars
[] = L
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
565 static const unsigned cChars
= sizeof(Chars
) / sizeof(WCHAR
) - 1;
568 wcscpy(lpBuffer
, L
"REACTOS-");
570 srand(GetTickCount());
572 /* fill in 7 characters */
573 for (i
= 8; i
< 15; i
++)
574 lpBuffer
[i
] = Chars
[rand() % cChars
];
576 lpBuffer
[15] = UNICODE_NULL
; /* NULL-terminate */
579 static INT_PTR CALLBACK
580 ComputerPageDlgProc(HWND hwndDlg
,
585 WCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
590 WCHAR EmptyComputerName
[256], NotMatchPassword
[256], WrongPassword
[256];
593 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
595 wcscpy(Title
, L
"ReactOS Setup");
602 /* Generate a new pseudo-random computer name */
603 GenerateComputerName(ComputerName
);
605 /* Display current computer name */
606 SetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
608 /* Set text limits */
609 SendDlgItemMessage(hwndDlg
, IDC_COMPUTERNAME
, EM_LIMITTEXT
, MAX_COMPUTERNAME_LENGTH
, 0);
610 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD1
, EM_LIMITTEXT
, 14, 0);
611 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD2
, EM_LIMITTEXT
, 14, 0);
613 /* Set focus to computer name */
614 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
615 if (SetupData
.UnattendSetup
)
617 SendMessage(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.ComputerName
);
618 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD1
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
619 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD2
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
620 SetAdministratorPassword(SetupData
.AdminPassword
);
629 lpnm
= (LPNMHDR
)lParam
;
634 /* Enable the Back and Next buttons */
635 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
636 if (SetupData
.UnattendSetup
&& WriteComputerSettings(SetupData
.ComputerName
, hwndDlg
))
638 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_DATETIMEPAGE
);
644 if (0 == GetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, MAX_COMPUTERNAME_LENGTH
+ 1))
646 if (0 == LoadStringW(hDllInstance
, IDS_WZD_COMPUTERNAME
, EmptyComputerName
,
647 sizeof(EmptyComputerName
) / sizeof(EmptyComputerName
[0])))
649 wcscpy(EmptyComputerName
, L
"Setup cannot continue until you enter the name of your computer.");
651 MessageBoxW(hwndDlg
, EmptyComputerName
, Title
, MB_ICONERROR
| MB_OK
);
652 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
653 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
657 /* No need to check computer name for invalid characters,
658 * SetComputerName() will do it for us */
660 if (!WriteComputerSettings(ComputerName
, hwndDlg
))
662 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
663 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
668 /* Check if admin passwords have been entered */
669 if ((GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15) == 0) ||
670 (GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15) == 0))
672 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDEMPTY
, EmptyPassword
,
673 sizeof(EmptyPassword
) / sizeof(EmptyPassword
[0])))
675 wcscpy(EmptyPassword
, L
"You must enter a password !");
677 MessageBoxW(hwndDlg
, EmptyPassword
, Title
, MB_ICONERROR
| MB_OK
);
678 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
682 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15);
683 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15);
685 /* Check if passwords match */
686 if (wcscmp(Password1
, Password2
))
688 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDMATCH
, NotMatchPassword
,
689 sizeof(NotMatchPassword
) / sizeof(NotMatchPassword
[0])))
691 wcscpy(NotMatchPassword
, L
"The passwords you entered do not match. Please enter the desired password again.");
693 MessageBoxW(hwndDlg
, NotMatchPassword
, Title
, MB_ICONERROR
| MB_OK
);
694 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
698 /* Check password for invalid characters */
699 Password
= (PWCHAR
)Password1
;
702 if (!isprint(*Password
))
704 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDCHAR
, WrongPassword
,
705 sizeof(WrongPassword
) / sizeof(WrongPassword
[0])))
707 wcscpy(WrongPassword
, L
"The password you entered contains invalid characters. Please enter a cleaned password.");
709 MessageBoxW(hwndDlg
, WrongPassword
, Title
, MB_ICONERROR
| MB_OK
);
710 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
716 /* Set admin password */
717 SetAdministratorPassword(Password1
);
721 SetupData
.UnattendSetup
= FALSE
;
739 SetKeyboardLayoutName(HWND hwnd
)
742 TCHAR szLayoutPath
[256];
743 TCHAR szLocaleName
[32];
747 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
748 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
754 dwValueSize
= 16 * sizeof(TCHAR
);
755 if (RegQueryValueEx(hKey
,
766 _tcscpy(szLayoutPath
,
767 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"));
768 _tcscat(szLayoutPath
,
771 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
778 dwValueSize
= 32 * sizeof(TCHAR
);
779 if (RegQueryValueEx(hKey
,
796 RunControlPanelApplet(HWND hwnd
, PCWSTR pwszCPLParameters
)
798 if (pwszCPLParameters
)
800 STARTUPINFOW StartupInfo
;
801 PROCESS_INFORMATION ProcessInformation
;
802 WCHAR CmdLine
[MAX_PATH
] = L
"rundll32.exe shell32.dll,Control_RunDLL ";
804 ZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
805 StartupInfo
.cb
= sizeof(StartupInfo
);
807 ASSERT(_countof(CmdLine
) > wcslen(CmdLine
) + wcslen(pwszCPLParameters
));
808 wcscat(CmdLine
, pwszCPLParameters
);
810 if (!CreateProcessW(NULL
,
819 &ProcessInformation
))
821 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
825 WaitForSingleObject(ProcessInformation
.hProcess
, INFINITE
);
826 CloseHandle(ProcessInformation
.hThread
);
827 CloseHandle(ProcessInformation
.hProcess
);
832 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
838 WriteUserLocale(VOID
)
844 lcid
= GetSystemDefaultLCID();
846 if (GetLocaleInfoW(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_ILANGUAGE
, Locale
, sizeof(Locale
) / sizeof(Locale
[0])) != 0)
848 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Control Panel\\International",
849 0, NULL
, REG_OPTION_NON_VOLATILE
,
850 KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
852 RegSetValueExW(hKey
, L
"Locale", 0, REG_SZ
, (LPBYTE
)Locale
, (wcslen(Locale
) + 1) * sizeof(WCHAR
));
858 static INT_PTR CALLBACK
859 LocalePageDlgProc(HWND hwndDlg
,
864 PSETUPDATA SetupData
;
866 /* Retrieve pointer to the global setup data */
867 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
873 /* Save pointer to the global setup data */
874 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
875 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
878 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
883 if (HIWORD(wParam
) == BN_CLICKED
)
885 switch (LOWORD(wParam
))
887 case IDC_CUSTOMLOCALE
:
888 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,5");
889 /* FIXME: Update input locale name */
892 case IDC_CUSTOMLAYOUT
:
893 RunControlPanelApplet(hwndDlg
, L
"input.dll,@1");
901 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
906 /* Enable the Back and Next buttons */
907 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
908 if (SetupData
->UnattendSetup
)
910 WCHAR wszPath
[MAX_PATH
];
911 if (GetRosInstallCD(wszPath
, _countof(wszPath
)))
913 WCHAR wszParams
[1024];
914 swprintf(wszParams
, L
"intl.cpl,,/f:\"%sreactos\\unattend.inf\"", wszPath
);
915 RunControlPanelApplet(hwndDlg
, wszParams
);
919 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,/f:\"unattend.inf\"");
922 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_OWNERPAGE
);
931 SetupData
->UnattendSetup
= FALSE
;
948 static PTIMEZONE_ENTRY
949 GetLargerTimeZoneEntry(PSETUPDATA SetupData
, DWORD Index
)
951 PTIMEZONE_ENTRY Entry
;
953 Entry
= SetupData
->TimeZoneListHead
;
954 while (Entry
!= NULL
)
956 if (Entry
->Index
>= Index
)
967 CreateTimeZoneList(PSETUPDATA SetupData
)
969 WCHAR szKeyName
[256];
977 PTIMEZONE_ENTRY Entry
;
978 PTIMEZONE_ENTRY Current
;
980 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
981 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
990 dwNameSize
= 256 * sizeof(WCHAR
);
991 lError
= RegEnumKeyExW(hZonesKey
,
999 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
1002 if (RegOpenKeyExW(hZonesKey
,
1009 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
1012 RegCloseKey(hZoneKey
);
1016 dwValueSize
= 64 * sizeof(WCHAR
);
1017 if (RegQueryValueExW(hZoneKey
,
1021 (LPBYTE
)&Entry
->Description
,
1024 RegCloseKey(hZoneKey
);
1028 dwValueSize
= 32 * sizeof(WCHAR
);
1029 if (RegQueryValueExW(hZoneKey
,
1033 (LPBYTE
)&Entry
->StandardName
,
1036 RegCloseKey(hZoneKey
);
1040 dwValueSize
= 32 * sizeof(WCHAR
);
1041 if (RegQueryValueExW(hZoneKey
,
1045 (LPBYTE
)&Entry
->DaylightName
,
1048 RegCloseKey(hZoneKey
);
1052 dwValueSize
= sizeof(DWORD
);
1053 if (RegQueryValueExW(hZoneKey
,
1057 (LPBYTE
)&Entry
->Index
,
1060 RegCloseKey(hZoneKey
);
1064 dwValueSize
= sizeof(TZ_INFO
);
1065 if (RegQueryValueExW(hZoneKey
,
1069 (LPBYTE
)&Entry
->TimezoneInfo
,
1072 RegCloseKey(hZoneKey
);
1076 RegCloseKey(hZoneKey
);
1078 if (SetupData
->TimeZoneListHead
== NULL
&&
1079 SetupData
->TimeZoneListTail
== NULL
)
1083 SetupData
->TimeZoneListHead
= Entry
;
1084 SetupData
->TimeZoneListTail
= Entry
;
1088 Current
= GetLargerTimeZoneEntry(SetupData
, Entry
->Index
);
1089 if (Current
!= NULL
)
1091 if (Current
== SetupData
->TimeZoneListHead
)
1093 /* Prepend to head */
1095 Entry
->Next
= SetupData
->TimeZoneListHead
;
1096 SetupData
->TimeZoneListHead
->Prev
= Entry
;
1097 SetupData
->TimeZoneListHead
= Entry
;
1101 /* Insert before current */
1102 Entry
->Prev
= Current
->Prev
;
1103 Entry
->Next
= Current
;
1104 Current
->Prev
->Next
= Entry
;
1105 Current
->Prev
= Entry
;
1110 /* Append to tail */
1111 Entry
->Prev
= SetupData
->TimeZoneListTail
;
1113 SetupData
->TimeZoneListTail
->Next
= Entry
;
1114 SetupData
->TimeZoneListTail
= Entry
;
1121 RegCloseKey(hZonesKey
);
1126 DestroyTimeZoneList(PSETUPDATA SetupData
)
1128 PTIMEZONE_ENTRY Entry
;
1130 while (SetupData
->TimeZoneListHead
!= NULL
)
1132 Entry
= SetupData
->TimeZoneListHead
;
1134 SetupData
->TimeZoneListHead
= Entry
->Next
;
1135 if (SetupData
->TimeZoneListHead
!= NULL
)
1137 SetupData
->TimeZoneListHead
->Prev
= NULL
;
1140 HeapFree(GetProcessHeap(), 0, Entry
);
1143 SetupData
->TimeZoneListTail
= NULL
;
1147 GetTimeZoneListIndex(LPDWORD lpIndex
)
1149 WCHAR szLanguageIdString
[9];
1156 BOOL bFound
= FALSE
;
1157 unsigned long iLanguageID
;
1159 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1160 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
1166 dwValueSize
= 9 * sizeof(WCHAR
);
1167 if (RegQueryValueExW(hKey
,
1171 (LPBYTE
)szLanguageIdString
,
1178 iLanguageID
= wcstoul(szLanguageIdString
, NULL
, 16);
1181 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1182 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1189 if (RegQueryValueExW(hKey
,
1200 Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
1207 if (RegQueryValueExW(hKey
,
1214 HeapFree(GetProcessHeap(), 0, Buffer
);
1224 Length
= wcslen(Ptr
);
1225 if (wcstoul(Ptr
, NULL
, 16) == iLanguageID
)
1228 Ptr
= Ptr
+ Length
+ 1;
1234 *lpIndex
= wcstoul(Ptr
, &End
, 10);
1235 HeapFree(GetProcessHeap(), 0, Buffer
);
1239 Length
= wcslen(Ptr
);
1240 Ptr
= Ptr
+ Length
+ 1;
1243 HeapFree(GetProcessHeap(), 0, Buffer
);
1250 ShowTimeZoneList(HWND hwnd
, PSETUPDATA SetupData
, DWORD dwEntryIndex
)
1252 PTIMEZONE_ENTRY Entry
;
1256 GetTimeZoneListIndex(&dwEntryIndex
);
1258 Entry
= SetupData
->TimeZoneListHead
;
1259 while (Entry
!= NULL
)
1261 dwCount
= SendMessage(hwnd
,
1264 (LPARAM
)Entry
->Description
);
1266 if (dwEntryIndex
!= 0 && dwEntryIndex
== Entry
->Index
)
1269 Entry
= Entry
->Next
;
1280 SetLocalTimeZone(HWND hwnd
, PSETUPDATA SetupData
)
1282 TIME_ZONE_INFORMATION TimeZoneInformation
;
1283 PTIMEZONE_ENTRY Entry
;
1287 dwIndex
= SendMessage(hwnd
,
1293 Entry
= SetupData
->TimeZoneListHead
;
1300 Entry
= Entry
->Next
;
1303 wcscpy(TimeZoneInformation
.StandardName
,
1304 Entry
->StandardName
);
1305 wcscpy(TimeZoneInformation
.DaylightName
,
1306 Entry
->DaylightName
);
1308 TimeZoneInformation
.Bias
= Entry
->TimezoneInfo
.Bias
;
1309 TimeZoneInformation
.StandardBias
= Entry
->TimezoneInfo
.StandardBias
;
1310 TimeZoneInformation
.DaylightBias
= Entry
->TimezoneInfo
.DaylightBias
;
1312 memcpy(&TimeZoneInformation
.StandardDate
,
1313 &Entry
->TimezoneInfo
.StandardDate
,
1314 sizeof(SYSTEMTIME
));
1315 memcpy(&TimeZoneInformation
.DaylightDate
,
1316 &Entry
->TimezoneInfo
.DaylightDate
,
1317 sizeof(SYSTEMTIME
));
1319 /* Set time zone information */
1320 SetTimeZoneInformation(&TimeZoneInformation
);
1325 GetLocalSystemTime(HWND hwnd
, PSETUPDATA SetupData
)
1330 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) != GDT_VALID
)
1335 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) != GDT_VALID
)
1340 SetupData
->SystemTime
.wYear
= Date
.wYear
;
1341 SetupData
->SystemTime
.wMonth
= Date
.wMonth
;
1342 SetupData
->SystemTime
.wDayOfWeek
= Date
.wDayOfWeek
;
1343 SetupData
->SystemTime
.wDay
= Date
.wDay
;
1344 SetupData
->SystemTime
.wHour
= Time
.wHour
;
1345 SetupData
->SystemTime
.wMinute
= Time
.wMinute
;
1346 SetupData
->SystemTime
.wSecond
= Time
.wSecond
;
1347 SetupData
->SystemTime
.wMilliseconds
= Time
.wMilliseconds
;
1354 SetAutoDaylightInfo(HWND hwnd
)
1359 if (SendMessage(hwnd
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
)
1361 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1362 L
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
1368 RegSetValueExW(hKey
,
1369 L
"DisableAutoDaylightTimeSet",
1380 SetSystemLocalTime(HWND hwnd
, PSETUPDATA SetupData
)
1385 * Call SetLocalTime twice to ensure correct results
1387 Ret
= SetLocalTime(&SetupData
->SystemTime
) &&
1388 SetLocalTime(&SetupData
->SystemTime
);
1394 WriteDateTimeSettings(HWND hwndDlg
, PSETUPDATA SetupData
)
1397 WCHAR ErrorLocalTime
[256];
1398 GetLocalSystemTime(hwndDlg
, SetupData
);
1399 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1402 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1403 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1405 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
1407 wcscpy(Title
, L
"ReactOS Setup");
1409 if (0 == LoadStringW(hDllInstance
, IDS_WZD_LOCALTIME
, ErrorLocalTime
,
1410 sizeof(ErrorLocalTime
) / sizeof(ErrorLocalTime
[0])))
1412 wcscpy(ErrorLocalTime
, L
"Setup was unable to set the local time.");
1414 MessageBoxW(hwndDlg
, ErrorLocalTime
, Title
, MB_ICONWARNING
| MB_OK
);
1421 static INT_PTR CALLBACK
1422 DateTimePageDlgProc(HWND hwndDlg
,
1427 PSETUPDATA SetupData
;
1429 /* Retrieve pointer to the global setup data */
1430 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1436 /* Save pointer to the global setup data */
1437 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1438 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1440 CreateTimeZoneList(SetupData
);
1442 if (SetupData
->UnattendSetup
)
1444 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1445 SetupData
, SetupData
->TimeZoneIndex
);
1447 if (!SetupData
->DisableAutoDaylightTimeSet
)
1449 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1454 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1455 SetupData
, 85 /* GMT time zone */);
1457 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1466 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1471 /* Enable the Back and Next buttons */
1472 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
1473 if (SetupData
->UnattendSetup
&& WriteDateTimeSettings(hwndDlg
, SetupData
))
1475 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_PROCESSPAGE
);
1482 WriteDateTimeSettings(hwndDlg
, SetupData
);
1487 SetupData
->UnattendSetup
= FALSE
;
1497 DestroyTimeZoneList(SetupData
);
1508 static UINT CALLBACK
1509 RegistrationNotificationProc(PVOID Context
,
1514 PREGISTRATIONDATA RegistrationData
;
1515 REGISTRATIONNOTIFY RegistrationNotify
;
1516 PSP_REGISTER_CONTROL_STATUSW StatusInfo
;
1518 WCHAR ErrorMessage
[128];
1520 RegistrationData
= (PREGISTRATIONDATA
) Context
;
1522 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
||
1523 SPFILENOTIFY_ENDREGISTRATION
== Notification
)
1525 StatusInfo
= (PSP_REGISTER_CONTROL_STATUSW
) Param1
;
1526 RegistrationNotify
.CurrentItem
= wcsrchr(StatusInfo
->FileName
, L
'\\');
1527 if (NULL
== RegistrationNotify
.CurrentItem
)
1529 RegistrationNotify
.CurrentItem
= StatusInfo
->FileName
;
1533 RegistrationNotify
.CurrentItem
++;
1536 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
)
1538 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1539 StatusInfo
->FileName
);
1540 RegistrationNotify
.ErrorMessage
= NULL
;
1541 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1545 DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
1546 StatusInfo
->FileName
);
1547 DPRINT("Win32Error %u FailureCode %u\n", StatusInfo
->Win32Error
,
1548 StatusInfo
->FailureCode
);
1549 if (SPREG_SUCCESS
!= StatusInfo
->FailureCode
)
1551 switch(StatusInfo
->FailureCode
)
1553 case SPREG_LOADLIBRARY
:
1554 MessageID
= IDS_LOADLIBRARY_FAILED
;
1556 case SPREG_GETPROCADDR
:
1557 MessageID
= IDS_GETPROCADDR_FAILED
;
1560 MessageID
= IDS_REGSVR_FAILED
;
1562 case SPREG_DLLINSTALL
:
1563 MessageID
= IDS_DLLINSTALL_FAILED
;
1566 MessageID
= IDS_TIMEOUT
;
1569 MessageID
= IDS_REASON_UNKNOWN
;
1572 if (0 == LoadStringW(hDllInstance
, MessageID
,
1574 sizeof(ErrorMessage
) /
1575 sizeof(ErrorMessage
[0])))
1577 ErrorMessage
[0] = L
'\0';
1579 if (SPREG_TIMEOUT
!= StatusInfo
->FailureCode
)
1581 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
1582 StatusInfo
->Win32Error
, 0,
1583 ErrorMessage
+ wcslen(ErrorMessage
),
1584 sizeof(ErrorMessage
) / sizeof(ErrorMessage
[0]) -
1585 wcslen(ErrorMessage
), NULL
);
1587 RegistrationNotify
.ErrorMessage
= ErrorMessage
;
1591 RegistrationNotify
.ErrorMessage
= NULL
;
1593 if (RegistrationData
->Registered
< RegistrationData
->DllCount
)
1595 RegistrationData
->Registered
++;
1599 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1600 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1601 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1602 0, (LPARAM
) &RegistrationNotify
);
1608 DPRINT1("Received unexpected notification %u\n", Notification
);
1609 return SetupDefaultQueueCallback(RegistrationData
->DefaultContext
,
1610 Notification
, Param1
, Param2
);
1615 static DWORD CALLBACK
1616 RegistrationProc(LPVOID Parameter
)
1618 PREGISTRATIONDATA RegistrationData
;
1619 REGISTRATIONNOTIFY RegistrationNotify
;
1620 DWORD LastError
= NO_ERROR
;
1621 WCHAR UnknownError
[84];
1623 RegistrationData
= (PREGISTRATIONDATA
) Parameter
;
1624 RegistrationData
->Registered
= 0;
1625 RegistrationData
->DefaultContext
= SetupInitDefaultQueueCallback(RegistrationData
->hwndDlg
);
1629 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData
->hwndDlg
),
1631 L
"RegistrationPhase2",
1633 SPINST_REGISTERCALLBACKAWARE
|
1638 RegistrationNotificationProc
,
1643 LastError
= GetLastError();
1646 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1648 DPRINT("Catching exception\n");
1649 LastError
= RtlNtStatusToDosError(_SEH2_GetExceptionCode());
1653 if (NO_ERROR
== LastError
)
1655 RegistrationNotify
.ErrorMessage
= NULL
;
1659 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1661 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1662 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, LastError
, 0,
1663 (LPWSTR
) &RegistrationNotify
.ErrorMessage
, 0,
1666 if (0 == LoadStringW(hDllInstance
, IDS_UNKNOWN_ERROR
,
1668 sizeof(UnknownError
) / sizeof(UnknownError
[0]) -
1671 wcscpy(UnknownError
, L
"Unknown error");
1673 wcscat(UnknownError
, L
" ");
1674 _ultow(LastError
, UnknownError
+ wcslen(UnknownError
), 10);
1675 RegistrationNotify
.ErrorMessage
= UnknownError
;
1679 RegistrationNotify
.Progress
= RegistrationData
->DllCount
;
1680 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1681 RegistrationNotify
.CurrentItem
= NULL
;
1682 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1683 1, (LPARAM
) &RegistrationNotify
);
1684 if (NULL
!= RegistrationNotify
.ErrorMessage
&&
1685 UnknownError
!= RegistrationNotify
.ErrorMessage
)
1687 LocalFree((PVOID
) RegistrationNotify
.ErrorMessage
);
1690 SetupTermDefaultQueueCallback(RegistrationData
->DefaultContext
);
1691 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1693 RegisterTypeLibraries(hSysSetupInf
, L
"TypeLibraries");
1695 // FIXME: Move this call to a separate cleanup page!
1696 RtlCreateBootStatusDataFile();
1703 StartComponentRegistration(HWND hwndDlg
, PULONG MaxProgress
)
1705 HANDLE RegistrationThread
;
1708 WCHAR SectionName
[512];
1709 PREGISTRATIONDATA RegistrationData
;
1712 if (! SetupFindFirstLineW(hSysSetupInf
, L
"RegistrationPhase2",
1713 L
"RegisterDlls", &Context
))
1715 DPRINT1("No RegistrationPhase2 section found\n");
1718 if (! SetupGetStringFieldW(&Context
, 1, SectionName
,
1719 sizeof(SectionName
) / sizeof(SectionName
[0]),
1722 DPRINT1("Unable to retrieve section name\n");
1725 DllCount
= SetupGetLineCountW(hSysSetupInf
, SectionName
);
1726 DPRINT("SectionName %S DllCount %ld\n", SectionName
, DllCount
);
1729 SetLastError(STATUS_NOT_FOUND
);
1733 *MaxProgress
= (ULONG
) DllCount
;
1736 * Create a background thread to do the actual registrations, so the
1737 * main thread can just run its message loop.
1739 RegistrationThread
= NULL
;
1740 RegistrationData
= HeapAlloc(GetProcessHeap(), 0,
1741 sizeof(REGISTRATIONDATA
));
1742 if (RegistrationData
!= NULL
)
1744 RegistrationData
->hwndDlg
= hwndDlg
;
1745 RegistrationData
->DllCount
= DllCount
;
1746 RegistrationThread
= CreateThread(NULL
, 0, RegistrationProc
,
1747 (LPVOID
) RegistrationData
, 0, NULL
);
1748 if (RegistrationThread
!= NULL
)
1750 CloseHandle(RegistrationThread
);
1754 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1755 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1761 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1769 static INT_PTR CALLBACK
1770 ProcessPageDlgProc(HWND hwndDlg
,
1775 PSETUPDATA SetupData
;
1776 PREGISTRATIONNOTIFY RegistrationNotify
;
1777 static UINT oldActivityID
= -1;
1780 /* Retrieve pointer to the global setup data */
1781 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1787 /* Save pointer to the global setup data */
1788 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1789 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1795 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1796 ULONG MaxProgress
= 0;
1801 /* Disable the Back and Next buttons */
1802 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
1804 StartComponentRegistration(hwndDlg
, &MaxProgress
);
1806 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
,
1807 0, MAKELPARAM(0, MaxProgress
));
1808 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1816 SetupData
->UnattendSetup
= FALSE
;
1825 case PM_REGISTRATION_NOTIFY
:
1828 RegistrationNotify
= (PREGISTRATIONNOTIFY
) lParam
;
1829 // update if necessary only
1830 if (oldActivityID
!= RegistrationNotify
->ActivityID
)
1832 if (0 != LoadStringW(hDllInstance
, RegistrationNotify
->ActivityID
,
1834 sizeof(Activity
) / sizeof(Activity
[0])))
1836 SendDlgItemMessageW(hwndDlg
, IDC_ACTIVITY
, WM_SETTEXT
,
1837 0, (LPARAM
) Activity
);
1839 oldActivityID
= RegistrationNotify
->ActivityID
;
1841 SendDlgItemMessageW(hwndDlg
, IDC_ITEM
, WM_SETTEXT
, 0,
1842 (LPARAM
)(NULL
== RegistrationNotify
->CurrentItem
?
1843 L
"" : RegistrationNotify
->CurrentItem
));
1844 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1845 RegistrationNotify
->Progress
, 0);
1846 if (NULL
!= RegistrationNotify
->ErrorMessage
)
1848 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
,
1849 Title
, sizeof(Title
) / sizeof(Title
[0])))
1851 wcscpy(Title
, L
"ReactOS Setup");
1853 MessageBoxW(hwndDlg
, RegistrationNotify
->ErrorMessage
,
1854 Title
, MB_ICONERROR
| MB_OK
);
1861 if(!SetupData
->UnattendSetup
&& !SetupData
->DisableVmwInst
)
1862 RunVMWInstall(GetParent(hwndDlg
));
1865 /* Enable the Back and Next buttons */
1866 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
1867 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
1881 SetInstallationCompleted(VOID
)
1884 DWORD InProgress
= 0;
1887 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1891 &hKey
) == ERROR_SUCCESS
)
1893 RegSetValueExW( hKey
, L
"SystemSetupInProgress", 0, REG_DWORD
, (LPBYTE
)&InProgress
, sizeof(InProgress
) );
1894 RegCloseKey( hKey
);
1897 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1898 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
1901 &hKey
) == ERROR_SUCCESS
)
1903 InstallDate
= (DWORD
)time(NULL
);
1904 RegSetValueExW( hKey
, L
"InstallDate", 0, REG_DWORD
, (LPBYTE
)&InstallDate
, sizeof(InstallDate
) );
1905 RegCloseKey( hKey
);
1909 static INT_PTR CALLBACK
1910 FinishDlgProc(HWND hwndDlg
,
1920 /* Get pointer to the global setup data */
1921 PSETUPDATA SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1923 /* Run the Wine Gecko prompt */
1924 Control_RunDLLW(GetDesktopWindow(), 0, L
"appwiz.cpl install_gecko", SW_SHOW
);
1926 /* Set title font */
1927 SendDlgItemMessage(hwndDlg
,
1930 (WPARAM
)SetupData
->hTitleFont
,
1932 if (SetupData
->UnattendSetup
)
1934 KillTimer(hwndDlg
, 1);
1935 SetInstallationCompleted();
1943 SetInstallationCompleted();
1953 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
1954 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
1955 if (Position
== 300)
1957 KillTimer(hwndDlg
, 1);
1958 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
1962 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
1969 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1974 /* Enable the correct buttons on for the active page */
1975 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
1977 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
1978 MAKELPARAM(0, 300));
1979 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETPOS
, 0, 0);
1980 SetTimer(hwndDlg
, 1, 50, NULL
);
1984 DestroyWindow(GetParent(hwndDlg
));
2002 ProcessUnattendInf(HINF hUnattendedInf
)
2004 INFCONTEXT InfContext
;
2006 WCHAR szValue
[MAX_PATH
];
2010 if (!SetupFindFirstLineW(hUnattendedInf
,
2012 L
"UnattendSetupEnabled",
2015 DPRINT1("Error: Cant find UnattendSetupEnabled Key! %d\n", GetLastError());
2019 if (!SetupGetStringFieldW(&InfContext
,
2022 sizeof(szValue
) / sizeof(WCHAR
),
2025 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2029 if (wcscmp(szValue
, L
"yes") != 0)
2031 DPRINT("Unattend setup was disabled by UnattendSetupEnabled key.\n");
2035 if (!SetupFindFirstLineW(hUnattendedInf
,
2040 DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError());
2047 if (!SetupGetStringFieldW(&InfContext
,
2050 sizeof(szName
) / sizeof(WCHAR
),
2053 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2057 if (!SetupGetStringFieldW(&InfContext
,
2060 sizeof(szValue
) / sizeof(WCHAR
),
2063 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2066 DPRINT1("Name %S Value %S\n", szName
, szValue
);
2067 if (!wcscmp(szName
, L
"FullName"))
2069 if ((sizeof(SetupData
.OwnerName
) / sizeof(TCHAR
)) > LineLength
)
2071 wcscpy(SetupData
.OwnerName
, szValue
);
2074 else if (!wcscmp(szName
, L
"OrgName"))
2076 if ((sizeof(SetupData
.OwnerOrganization
) / sizeof(WCHAR
)) > LineLength
)
2078 wcscpy(SetupData
.OwnerOrganization
, szValue
);
2081 else if (!wcscmp(szName
, L
"ComputerName"))
2083 if ((sizeof(SetupData
.ComputerName
) / sizeof(WCHAR
)) > LineLength
)
2085 wcscpy(SetupData
.ComputerName
, szValue
);
2088 else if (!wcscmp(szName
, L
"AdminPassword"))
2090 if ((sizeof(SetupData
.AdminPassword
) / sizeof(WCHAR
)) > LineLength
)
2092 wcscpy(SetupData
.AdminPassword
, szValue
);
2095 else if (!wcscmp(szName
, L
"TimeZoneIndex"))
2097 SetupData
.TimeZoneIndex
= _wtoi(szValue
);
2099 else if (!wcscmp(szName
, L
"DisableAutoDaylightTimeSet"))
2101 SetupData
.DisableAutoDaylightTimeSet
= _wtoi(szValue
);
2103 else if (!wcscmp(szName
, L
"DisableVmwInst"))
2105 if(!wcscmp(szValue
, L
"yes"))
2106 SetupData
.DisableVmwInst
= 1;
2108 SetupData
.DisableVmwInst
= 0;
2112 while (SetupFindNextLine(&InfContext
, &InfContext
));
2114 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
2115 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
2118 &hKey
) != ERROR_SUCCESS
)
2120 DPRINT1("Error: failed to open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\n");
2125 if (SetupFindFirstLineW(hUnattendedInf
,
2134 if(SetupGetStringFieldW(&InfContext
,
2137 sizeof(szValue
) / sizeof(WCHAR
),
2140 WCHAR szPath
[MAX_PATH
];
2141 swprintf(szName
, L
"%d", i
);
2142 DPRINT("szName %S szValue %S\n", szName
, szValue
);
2144 if (ExpandEnvironmentStringsW(szValue
, szPath
, MAX_PATH
))
2146 DPRINT("value %S\n", szPath
);
2147 if (RegSetValueExW(hKey
,
2151 (const BYTE
*)szPath
,
2152 (wcslen(szPath
) + 1) * sizeof(WCHAR
)) == ERROR_SUCCESS
)
2158 } while(SetupFindNextLine(&InfContext
, &InfContext
));
2166 * GetRosInstallCD should find the path to ros installation medium
2168 * If there are more than one CDDrive in it containing a ReactOS
2169 * installation cd, then it will pick the first one regardless if
2170 * it is really the installation cd
2172 * The best way to implement this is to set the key
2173 * HKLM\Software\Microsoft\Windows NT\CurrentVersion\SourcePath (REG_SZ)
2177 GetRosInstallCD(WCHAR
*pwszPath
, DWORD cchPathMax
)
2179 WCHAR wszDrives
[512];
2183 cchDrives
= GetLogicalDriveStringsW(_countof(wszDrives
) - 1, wszDrives
);
2184 if (cchDrives
== 0 || cchDrives
>= _countof(wszDrives
))
2186 /* buffer too small or failure */
2187 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"GetLogicalDriveStringsW failed");
2191 for (pwszDrive
= wszDrives
; pwszDrive
[0]; pwszDrive
+= wcslen(pwszDrive
) + 1)
2193 if (GetDriveTypeW(pwszDrive
) == DRIVE_CDROM
)
2195 WCHAR wszBuf
[MAX_PATH
];
2196 wsprintf(wszBuf
, L
"%sreactos\\system32\\ntoskrnl.exe", pwszDrive
);
2197 LogItem(SYSSETUP_SEVERITY_INFORMATION
, wszBuf
);
2198 if (GetFileAttributesW(wszBuf
) != INVALID_FILE_ATTRIBUTES
)
2200 /* the file exists, so this is the right drive */
2201 wcsncpy(pwszPath
, pwszDrive
, cchPathMax
);
2202 OutputDebugStringW(L
"GetRosInstallCD: ");OutputDebugStringW(pwszPath
);OutputDebugStringW(L
"\n");
2212 ProcessUnattendSetup(VOID
)
2214 WCHAR szPath
[MAX_PATH
];
2215 HINF hUnattendedInf
;
2218 if (!GetRosInstallCD(szPath
, MAX_PATH
))
2220 /* no cd drive found */
2224 dwLength
= wcslen(szPath
);
2225 if (dwLength
+ 21 > MAX_PATH
)
2228 * allocate bigger buffer
2233 wcscat(szPath
, L
"reactos\\unattend.inf");
2235 hUnattendedInf
= SetupOpenInfFileW(szPath
,
2240 if (hUnattendedInf
!= INVALID_HANDLE_VALUE
)
2242 SetupData
.UnattendSetup
= ProcessUnattendInf(hUnattendedInf
);
2243 SetupCloseInfFile(hUnattendedInf
);
2251 PROPSHEETHEADER psh
;
2252 HPROPSHEETPAGE ahpsp
[8];
2253 PROPSHEETPAGE psp
= {0};
2258 /* Clear setup data */
2259 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
2261 ProcessUnattendSetup();
2263 /* Create the Welcome page */
2264 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
2265 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2266 psp
.hInstance
= hDllInstance
;
2267 psp
.lParam
= (LPARAM
)&SetupData
;
2268 psp
.pfnDlgProc
= WelcomeDlgProc
;
2269 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
2270 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2272 /* Create the Acknowledgements page */
2273 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2274 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_ACKTITLE
);
2275 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_ACKSUBTITLE
);
2276 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_ACKPAGE
);
2277 psp
.pfnDlgProc
= AckPageDlgProc
;
2278 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2280 /* Create the Locale page */
2281 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2282 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LOCALETITLE
);
2283 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LOCALESUBTITLE
);
2284 psp
.pfnDlgProc
= LocalePageDlgProc
;
2285 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
2286 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2289 /* Create the Owner page */
2290 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2291 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_OWNERTITLE
);
2292 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_OWNERSUBTITLE
);
2293 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_OWNERPAGE
);
2294 psp
.pfnDlgProc
= OwnerPageDlgProc
;
2295 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2297 /* Create the Computer page */
2298 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2299 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_COMPUTERTITLE
);
2300 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE
);
2301 psp
.pfnDlgProc
= ComputerPageDlgProc
;
2302 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_COMPUTERPAGE
);
2303 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2306 /* Create the DateTime page */
2307 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2308 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DATETIMETITLE
);
2309 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DATETIMESUBTITLE
);
2310 psp
.pfnDlgProc
= DateTimePageDlgProc
;
2311 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DATETIMEPAGE
);
2312 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2315 /* Create the Process page */
2316 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2317 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
2318 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
2319 psp
.pfnDlgProc
= ProcessPageDlgProc
;
2320 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
2321 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2324 /* Create the Finish page */
2325 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2326 psp
.pfnDlgProc
= FinishDlgProc
;
2327 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
2328 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2330 /* Create the property sheet */
2331 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2332 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
| PSH_MODELESS
;
2333 psh
.hInstance
= hDllInstance
;
2334 psh
.hwndParent
= NULL
;
2335 psh
.nPages
= nPages
;
2338 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
2339 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
2341 /* Create title font */
2342 SetupData
.hTitleFont
= CreateTitleFont();
2344 /* Display the wizard */
2345 hWnd
= (HWND
)PropertySheet(&psh
);
2346 ShowWindow(hWnd
, SW_SHOW
);
2348 while (GetMessage(&msg
, NULL
, 0, 0))
2350 if(!IsDialogMessage(hWnd
, &msg
))
2352 TranslateMessage(&msg
);
2353 DispatchMessage(&msg
);
2357 DeleteObject(SetupData
.hTitleFont
);