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 GetRosInstallCD(WCHAR
*pwszPath
, DWORD cchPathMax
);
53 RunVMWInstall(HWND hWnd
)
55 PROCESS_INFORMATION ProcInfo
;
58 STARTUPINFOW si
= {0};
59 WCHAR InstallName
[] = L
"vmwinst.exe";
61 si
.cb
= sizeof(STARTUPINFO
);
63 if(CreateProcessW(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
64 NULL
, NULL
, &si
, &ProcInfo
))
66 EnableWindow(hWnd
, FALSE
);
69 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
71 if (msg
.message
== WM_QUIT
)
73 TranslateMessage(&msg
);
74 DispatchMessage(&msg
);
77 ret
= MsgWaitForMultipleObjects(1, &ProcInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
| QS_ALLINPUT
);
78 if (ret
== WAIT_OBJECT_0
)
82 EnableWindow(hWnd
, TRUE
);
84 CloseHandle(ProcInfo
.hThread
);
85 CloseHandle(ProcInfo
.hProcess
);
93 CenterWindow(HWND hWnd
)
99 hWndParent
= GetParent(hWnd
);
100 if (hWndParent
== NULL
)
101 hWndParent
= GetDesktopWindow();
103 GetWindowRect(hWndParent
, &rcParent
);
104 GetWindowRect(hWnd
, &rcWindow
);
108 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
109 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
117 CreateTitleFont(VOID
)
119 NONCLIENTMETRICSW ncm
;
125 ncm
.cbSize
= sizeof(NONCLIENTMETRICSW
);
126 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
128 LogFont
= ncm
.lfMessageFont
;
129 LogFont
.lfWeight
= FW_BOLD
;
130 wcscpy(LogFont
.lfFaceName
, L
"MS Shell Dlg");
134 LogFont
.lfHeight
= 0 - GetDeviceCaps(hdc
, LOGPIXELSY
) * FontSize
/ 72;
135 hFont
= CreateFontIndirectW(&LogFont
);
136 ReleaseDC(NULL
, hdc
);
142 static INT_PTR CALLBACK
143 GplDlgProc(HWND hwndDlg
,
148 HRSRC GplTextResource
;
158 GplTextResource
= FindResourceW(hDllInstance
, MAKEINTRESOURCE(IDR_GPL
), L
"RT_TEXT");
159 if (NULL
== GplTextResource
)
163 Size
= SizeofResource(hDllInstance
, GplTextResource
);
168 GplText
= HeapAlloc(GetProcessHeap(), 0, Size
+ 1);
173 GplTextMem
= LoadResource(hDllInstance
, GplTextResource
);
174 if (NULL
== GplTextMem
)
176 HeapFree(GetProcessHeap(), 0, GplText
);
179 GplTextLocked
= LockResource(GplTextMem
);
180 if (NULL
== GplTextLocked
)
182 HeapFree(GetProcessHeap(), 0, GplText
);
185 memcpy(GplText
, GplTextLocked
, Size
);
186 GplText
[Size
] = '\0';
187 SendMessageA(GetDlgItem(hwndDlg
, IDC_GPL_TEXT
), WM_SETTEXT
, 0, (LPARAM
) GplText
);
188 HeapFree(GetProcessHeap(), 0, GplText
);
189 SetFocus(GetDlgItem(hwndDlg
, IDOK
));
193 EndDialog(hwndDlg
, IDCANCEL
);
197 if (HIWORD(wParam
) == BN_CLICKED
&& IDOK
== LOWORD(wParam
))
199 EndDialog(hwndDlg
, IDOK
);
211 static INT_PTR CALLBACK
212 WelcomeDlgProc(HWND hwndDlg
,
221 PSETUPDATA SetupData
;
225 /* Get pointer to the global setup data */
226 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
228 hwndControl
= GetParent(hwndDlg
);
230 /* Center the wizard window */
231 CenterWindow (hwndControl
);
233 /* Hide the system menu */
234 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
235 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
237 /* Hide and disable the 'Cancel' button */
238 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
239 ShowWindow (hwndControl
, SW_HIDE
);
240 EnableWindow (hwndControl
, FALSE
);
243 SendDlgItemMessage(hwndDlg
,
246 (WPARAM
)SetupData
->hTitleFont
,
254 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
259 /* Enable the Next button */
260 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
261 if (SetupData
.UnattendSetup
)
263 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_ACKPAGE
);
269 SetupData
.UnattendSetup
= FALSE
;
286 static INT_PTR CALLBACK
287 AckPageDlgProc(HWND hwndDlg
,
294 PWCHAR End
, CurrentProject
;
295 INT ProjectsSize
, ProjectsCount
;
305 Projects
= HeapAlloc(GetProcessHeap(), 0, ProjectsSize
* sizeof(WCHAR
));
306 if (NULL
== Projects
)
310 ProjectsCount
= LoadStringW(hDllInstance
, IDS_ACKPROJECTS
, Projects
, ProjectsSize
);
311 if (0 == ProjectsCount
)
313 HeapFree(GetProcessHeap(), 0, Projects
);
316 if (ProjectsCount
< ProjectsSize
- 1)
320 HeapFree(GetProcessHeap(), 0, Projects
);
324 CurrentProject
= Projects
;
325 while (L
'\0' != *CurrentProject
)
327 End
= wcschr(CurrentProject
, L
'\n');
332 (void)ListBox_AddString(GetDlgItem(hwndDlg
, IDC_PROJECTS
), CurrentProject
);
335 CurrentProject
= End
+ 1;
339 CurrentProject
+= wcslen(CurrentProject
);
342 HeapFree(GetProcessHeap(), 0, Projects
);
347 if (HIWORD(wParam
) == BN_CLICKED
&& IDC_VIEWGPL
== LOWORD(wParam
))
349 DialogBox(hDllInstance
, MAKEINTRESOURCE(IDD_GPL
), NULL
, GplDlgProc
);
355 lpnm
= (LPNMHDR
)lParam
;
360 /* Enable the Back and Next buttons */
361 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
362 if (SetupData
.UnattendSetup
)
364 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_OWNERPAGE
);
370 SetupData
.UnattendSetup
= FALSE
;
388 WriteOwnerSettings(WCHAR
* OwnerName
,
389 WCHAR
* OwnerOrganization
)
396 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
397 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
402 if (res
!= ERROR_SUCCESS
)
407 res
= RegSetValueExW(hKey
,
412 (wcslen(OwnerName
) + 1) * sizeof(WCHAR
));
414 if (res
!= ERROR_SUCCESS
)
420 res
= RegSetValueExW(hKey
,
421 L
"RegisteredOrganization",
424 (LPBYTE
)OwnerOrganization
,
425 (wcslen(OwnerOrganization
) + 1) * sizeof(WCHAR
));
428 return (res
== ERROR_SUCCESS
);
431 static INT_PTR CALLBACK
432 OwnerPageDlgProc(HWND hwndDlg
,
438 WCHAR OwnerOrganization
[51];
440 WCHAR ErrorName
[256];
447 SendDlgItemMessage(hwndDlg
, IDC_OWNERNAME
, EM_LIMITTEXT
, 50, 0);
448 SendDlgItemMessage(hwndDlg
, IDC_OWNERORGANIZATION
, EM_LIMITTEXT
, 50, 0);
450 /* Set focus to owner name */
451 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
458 lpnm
= (LPNMHDR
)lParam
;
463 /* Enable the Back and Next buttons */
464 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
465 if (SetupData
.UnattendSetup
)
467 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerName
);
468 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERORGANIZATION
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerOrganization
);
469 if (WriteOwnerSettings(SetupData
.OwnerName
, SetupData
.OwnerOrganization
))
471 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_COMPUTERPAGE
);
479 if (GetDlgItemTextW(hwndDlg
, IDC_OWNERNAME
, OwnerName
, 50) == 0)
481 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
483 wcscpy(Title
, L
"ReactOS Setup");
485 if (0 == LoadStringW(hDllInstance
, IDS_WZD_NAME
, ErrorName
, sizeof(ErrorName
) / sizeof(ErrorName
[0])))
487 wcscpy(ErrorName
, L
"Setup cannot continue until you enter your name.");
489 MessageBoxW(hwndDlg
, ErrorName
, Title
, MB_ICONERROR
| MB_OK
);
491 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
492 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
497 OwnerOrganization
[0] = 0;
498 GetDlgItemTextW(hwndDlg
, IDC_OWNERORGANIZATION
, OwnerOrganization
, 50);
500 if (!WriteOwnerSettings(OwnerName
, OwnerOrganization
))
502 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
503 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
508 SetupData
.UnattendSetup
= FALSE
;
526 WriteComputerSettings(WCHAR
* ComputerName
, HWND hwndDlg
)
529 WCHAR ErrorComputerName
[256];
530 if (!SetComputerNameW(ComputerName
))
532 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
534 wcscpy(Title
, L
"ReactOS Setup");
536 if (0 == LoadStringW(hDllInstance
, IDS_WZD_SETCOMPUTERNAME
, ErrorComputerName
,
537 sizeof(ErrorComputerName
) / sizeof(ErrorComputerName
[0])))
539 wcscpy(ErrorComputerName
, L
"Setup failed to set the computer name.");
541 MessageBoxW(hwndDlg
, ErrorComputerName
, Title
, MB_ICONERROR
| MB_OK
);
546 /* Try to also set DNS hostname */
547 SetComputerNameExW(ComputerNamePhysicalDnsHostname
, ComputerName
);
549 /* Set the account domain name */
550 SetAccountDomain(ComputerName
, NULL
);
555 /* lpBuffer will be filled with a 15-char string (plus the null terminator) */
557 GenerateComputerName(LPWSTR lpBuffer
)
559 static const WCHAR Chars
[] = L
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
560 static const unsigned cChars
= sizeof(Chars
) / sizeof(WCHAR
) - 1;
563 wcscpy(lpBuffer
, L
"REACTOS-");
565 srand(GetTickCount());
567 /* fill in 7 characters */
568 for (i
= 8; i
< 15; i
++)
569 lpBuffer
[i
] = Chars
[rand() % cChars
];
571 lpBuffer
[15] = UNICODE_NULL
; /* NULL-terminate */
574 static INT_PTR CALLBACK
575 ComputerPageDlgProc(HWND hwndDlg
,
580 WCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
585 WCHAR EmptyComputerName
[256], NotMatchPassword
[256], WrongPassword
[256];
588 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
590 wcscpy(Title
, L
"ReactOS Setup");
597 /* Generate a new pseudo-random computer name */
598 GenerateComputerName(ComputerName
);
600 /* Display current computer name */
601 SetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
603 /* Set text limits */
604 SendDlgItemMessage(hwndDlg
, IDC_COMPUTERNAME
, EM_LIMITTEXT
, MAX_COMPUTERNAME_LENGTH
, 0);
605 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD1
, EM_LIMITTEXT
, 14, 0);
606 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD2
, EM_LIMITTEXT
, 14, 0);
608 /* Set focus to computer name */
609 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
610 if (SetupData
.UnattendSetup
)
612 SendMessage(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.ComputerName
);
613 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD1
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
614 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD2
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
623 lpnm
= (LPNMHDR
)lParam
;
628 /* Enable the Back and Next buttons */
629 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
630 if (SetupData
.UnattendSetup
&& WriteComputerSettings(SetupData
.ComputerName
, hwndDlg
))
632 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_LOCALEPAGE
);
638 if (0 == GetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, MAX_COMPUTERNAME_LENGTH
+ 1))
640 if (0 == LoadStringW(hDllInstance
, IDS_WZD_COMPUTERNAME
, EmptyComputerName
,
641 sizeof(EmptyComputerName
) / sizeof(EmptyComputerName
[0])))
643 wcscpy(EmptyComputerName
, L
"Setup cannot continue until you enter the name of your computer.");
645 MessageBoxW(hwndDlg
, EmptyComputerName
, Title
, MB_ICONERROR
| MB_OK
);
646 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
647 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
651 /* No need to check computer name for invalid characters,
652 * SetComputerName() will do it for us */
654 if (!WriteComputerSettings(ComputerName
, hwndDlg
))
656 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
657 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
662 /* Check if admin passwords have been entered */
663 if ((GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15) == 0) ||
664 (GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15) == 0))
666 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDEMPTY
, EmptyPassword
,
667 sizeof(EmptyPassword
) / sizeof(EmptyPassword
[0])))
669 wcscpy(EmptyPassword
, L
"You must enter a password !");
671 MessageBoxW(hwndDlg
, EmptyPassword
, Title
, MB_ICONERROR
| MB_OK
);
672 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
676 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15);
677 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15);
679 /* Check if passwords match */
680 if (wcscmp(Password1
, Password2
))
682 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDMATCH
, NotMatchPassword
,
683 sizeof(NotMatchPassword
) / sizeof(NotMatchPassword
[0])))
685 wcscpy(NotMatchPassword
, L
"The passwords you entered do not match. Please enter the desired password again.");
687 MessageBoxW(hwndDlg
, NotMatchPassword
, Title
, MB_ICONERROR
| MB_OK
);
688 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
692 /* Check password for invalid characters */
693 Password
= (PWCHAR
)Password1
;
696 if (!isprint(*Password
))
698 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDCHAR
, WrongPassword
,
699 sizeof(WrongPassword
) / sizeof(WrongPassword
[0])))
701 wcscpy(WrongPassword
, L
"The password you entered contains invalid characters. Please enter a cleaned password.");
703 MessageBoxW(hwndDlg
, WrongPassword
, Title
, MB_ICONERROR
| MB_OK
);
704 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
710 /* FIXME: Set admin password */
714 SetupData
.UnattendSetup
= FALSE
;
732 SetKeyboardLayoutName(HWND hwnd
)
735 TCHAR szLayoutPath
[256];
736 TCHAR szLocaleName
[32];
740 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
741 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
747 dwValueSize
= 16 * sizeof(TCHAR
);
748 if (RegQueryValueEx(hKey
,
759 _tcscpy(szLayoutPath
,
760 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"));
761 _tcscat(szLayoutPath
,
764 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
771 dwValueSize
= 32 * sizeof(TCHAR
);
772 if (RegQueryValueEx(hKey
,
789 RunControlPanelApplet(HWND hwnd
, PCWSTR pwszCPLParameters
)
791 if (pwszCPLParameters
)
793 STARTUPINFOW StartupInfo
;
794 PROCESS_INFORMATION ProcessInformation
;
795 WCHAR CmdLine
[MAX_PATH
] = L
"rundll32.exe shell32.dll,Control_RunDLL ";
797 ZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
798 StartupInfo
.cb
= sizeof(STARTUPINFOW
);
800 ASSERT(_countof(CmdLine
) > wcslen(CmdLine
) + wcslen(pwszCPLParameters
));
801 wcscat(CmdLine
, pwszCPLParameters
);
803 if (!CreateProcessW(NULL
,
812 &ProcessInformation
))
814 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
818 WaitForSingleObject(ProcessInformation
.hProcess
, INFINITE
);
819 CloseHandle(ProcessInformation
.hThread
);
820 CloseHandle(ProcessInformation
.hProcess
);
825 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
831 WriteUserLocale(VOID
)
837 lcid
= GetSystemDefaultLCID();
839 if (GetLocaleInfoW(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_ILANGUAGE
, Locale
, sizeof(Locale
) / sizeof(Locale
[0])) != 0)
841 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Control Panel\\International",
842 0, NULL
, REG_OPTION_NON_VOLATILE
,
843 KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
845 RegSetValueExW(hKey
, L
"Locale", 0, REG_SZ
, (LPBYTE
)Locale
, (wcslen(Locale
) + 1) * sizeof(WCHAR
));
851 static INT_PTR CALLBACK
852 LocalePageDlgProc(HWND hwndDlg
,
857 PSETUPDATA SetupData
;
859 /* Retrieve pointer to the global setup data */
860 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
866 /* Save pointer to the global setup data */
867 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
868 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
871 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
876 if (HIWORD(wParam
) == BN_CLICKED
)
878 switch (LOWORD(wParam
))
880 case IDC_CUSTOMLOCALE
:
881 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,5");
882 /* FIXME: Update input locale name */
885 case IDC_CUSTOMLAYOUT
:
886 RunControlPanelApplet(hwndDlg
, L
"input.dll,@1");
894 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
899 /* Enable the Back and Next buttons */
900 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
901 if (SetupData
->UnattendSetup
)
903 WCHAR wszPath
[MAX_PATH
];
904 if (GetRosInstallCD(wszPath
, _countof(wszPath
)))
906 WCHAR wszParams
[1024];
907 swprintf(wszParams
, L
"intl.cpl,,/f:\"%sreactos\\unattend.inf\"", wszPath
);
908 RunControlPanelApplet(hwndDlg
, wszParams
);
912 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,/f:\"unattend.inf\"");
915 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_DATETIMEPAGE
);
924 SetupData
->UnattendSetup
= FALSE
;
941 static PTIMEZONE_ENTRY
942 GetLargerTimeZoneEntry(PSETUPDATA SetupData
, DWORD Index
)
944 PTIMEZONE_ENTRY Entry
;
946 Entry
= SetupData
->TimeZoneListHead
;
947 while (Entry
!= NULL
)
949 if (Entry
->Index
>= Index
)
960 CreateTimeZoneList(PSETUPDATA SetupData
)
962 WCHAR szKeyName
[256];
970 PTIMEZONE_ENTRY Entry
;
971 PTIMEZONE_ENTRY Current
;
973 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
974 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
983 dwNameSize
= 256 * sizeof(WCHAR
);
984 lError
= RegEnumKeyExW(hZonesKey
,
992 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
995 if (RegOpenKeyExW(hZonesKey
,
1002 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
1005 RegCloseKey(hZoneKey
);
1009 dwValueSize
= 64 * sizeof(WCHAR
);
1010 if (RegQueryValueExW(hZoneKey
,
1014 (LPBYTE
)&Entry
->Description
,
1017 RegCloseKey(hZoneKey
);
1021 dwValueSize
= 32 * sizeof(WCHAR
);
1022 if (RegQueryValueExW(hZoneKey
,
1026 (LPBYTE
)&Entry
->StandardName
,
1029 RegCloseKey(hZoneKey
);
1033 dwValueSize
= 32 * sizeof(WCHAR
);
1034 if (RegQueryValueExW(hZoneKey
,
1038 (LPBYTE
)&Entry
->DaylightName
,
1041 RegCloseKey(hZoneKey
);
1045 dwValueSize
= sizeof(DWORD
);
1046 if (RegQueryValueExW(hZoneKey
,
1050 (LPBYTE
)&Entry
->Index
,
1053 RegCloseKey(hZoneKey
);
1057 dwValueSize
= sizeof(TZ_INFO
);
1058 if (RegQueryValueExW(hZoneKey
,
1062 (LPBYTE
)&Entry
->TimezoneInfo
,
1065 RegCloseKey(hZoneKey
);
1069 RegCloseKey(hZoneKey
);
1071 if (SetupData
->TimeZoneListHead
== NULL
&&
1072 SetupData
->TimeZoneListTail
== NULL
)
1076 SetupData
->TimeZoneListHead
= Entry
;
1077 SetupData
->TimeZoneListTail
= Entry
;
1081 Current
= GetLargerTimeZoneEntry(SetupData
, Entry
->Index
);
1082 if (Current
!= NULL
)
1084 if (Current
== SetupData
->TimeZoneListHead
)
1086 /* Prepend to head */
1088 Entry
->Next
= SetupData
->TimeZoneListHead
;
1089 SetupData
->TimeZoneListHead
->Prev
= Entry
;
1090 SetupData
->TimeZoneListHead
= Entry
;
1094 /* Insert before current */
1095 Entry
->Prev
= Current
->Prev
;
1096 Entry
->Next
= Current
;
1097 Current
->Prev
->Next
= Entry
;
1098 Current
->Prev
= Entry
;
1103 /* Append to tail */
1104 Entry
->Prev
= SetupData
->TimeZoneListTail
;
1106 SetupData
->TimeZoneListTail
->Next
= Entry
;
1107 SetupData
->TimeZoneListTail
= Entry
;
1114 RegCloseKey(hZonesKey
);
1119 DestroyTimeZoneList(PSETUPDATA SetupData
)
1121 PTIMEZONE_ENTRY Entry
;
1123 while (SetupData
->TimeZoneListHead
!= NULL
)
1125 Entry
= SetupData
->TimeZoneListHead
;
1127 SetupData
->TimeZoneListHead
= Entry
->Next
;
1128 if (SetupData
->TimeZoneListHead
!= NULL
)
1130 SetupData
->TimeZoneListHead
->Prev
= NULL
;
1133 HeapFree(GetProcessHeap(), 0, Entry
);
1136 SetupData
->TimeZoneListTail
= NULL
;
1140 GetTimeZoneListIndex(LPDWORD lpIndex
)
1142 WCHAR szLanguageIdString
[9];
1149 BOOL bFound
= FALSE
;
1150 unsigned long iLanguageID
;
1152 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1153 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
1159 dwValueSize
= 9 * sizeof(WCHAR
);
1160 if (RegQueryValueExW(hKey
,
1164 (LPBYTE
)szLanguageIdString
,
1171 iLanguageID
= wcstoul(szLanguageIdString
, NULL
, 16);
1174 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1175 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1182 if (RegQueryValueExW(hKey
,
1193 Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
1200 if (RegQueryValueExW(hKey
,
1207 HeapFree(GetProcessHeap(), 0, Buffer
);
1217 Length
= wcslen(Ptr
);
1218 if (wcstoul(Ptr
, NULL
, 16) == iLanguageID
)
1221 Ptr
= Ptr
+ Length
+ 1;
1227 *lpIndex
= wcstoul(Ptr
, &End
, 10);
1228 HeapFree(GetProcessHeap(), 0, Buffer
);
1232 Length
= wcslen(Ptr
);
1233 Ptr
= Ptr
+ Length
+ 1;
1236 HeapFree(GetProcessHeap(), 0, Buffer
);
1243 ShowTimeZoneList(HWND hwnd
, PSETUPDATA SetupData
, DWORD dwEntryIndex
)
1245 PTIMEZONE_ENTRY Entry
;
1249 GetTimeZoneListIndex(&dwEntryIndex
);
1251 Entry
= SetupData
->TimeZoneListHead
;
1252 while (Entry
!= NULL
)
1254 dwCount
= SendMessage(hwnd
,
1257 (LPARAM
)Entry
->Description
);
1259 if (dwEntryIndex
!= 0 && dwEntryIndex
== Entry
->Index
)
1262 Entry
= Entry
->Next
;
1273 SetLocalTimeZone(HWND hwnd
, PSETUPDATA SetupData
)
1275 TIME_ZONE_INFORMATION TimeZoneInformation
;
1276 PTIMEZONE_ENTRY Entry
;
1280 dwIndex
= SendMessage(hwnd
,
1286 Entry
= SetupData
->TimeZoneListHead
;
1293 Entry
= Entry
->Next
;
1296 wcscpy(TimeZoneInformation
.StandardName
,
1297 Entry
->StandardName
);
1298 wcscpy(TimeZoneInformation
.DaylightName
,
1299 Entry
->DaylightName
);
1301 TimeZoneInformation
.Bias
= Entry
->TimezoneInfo
.Bias
;
1302 TimeZoneInformation
.StandardBias
= Entry
->TimezoneInfo
.StandardBias
;
1303 TimeZoneInformation
.DaylightBias
= Entry
->TimezoneInfo
.DaylightBias
;
1305 memcpy(&TimeZoneInformation
.StandardDate
,
1306 &Entry
->TimezoneInfo
.StandardDate
,
1307 sizeof(SYSTEMTIME
));
1308 memcpy(&TimeZoneInformation
.DaylightDate
,
1309 &Entry
->TimezoneInfo
.DaylightDate
,
1310 sizeof(SYSTEMTIME
));
1312 /* Set time zone information */
1313 SetTimeZoneInformation(&TimeZoneInformation
);
1318 GetLocalSystemTime(HWND hwnd
, PSETUPDATA SetupData
)
1323 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) != GDT_VALID
)
1328 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) != GDT_VALID
)
1333 SetupData
->SystemTime
.wYear
= Date
.wYear
;
1334 SetupData
->SystemTime
.wMonth
= Date
.wMonth
;
1335 SetupData
->SystemTime
.wDayOfWeek
= Date
.wDayOfWeek
;
1336 SetupData
->SystemTime
.wDay
= Date
.wDay
;
1337 SetupData
->SystemTime
.wHour
= Time
.wHour
;
1338 SetupData
->SystemTime
.wMinute
= Time
.wMinute
;
1339 SetupData
->SystemTime
.wSecond
= Time
.wSecond
;
1340 SetupData
->SystemTime
.wMilliseconds
= Time
.wMilliseconds
;
1347 SetAutoDaylightInfo(HWND hwnd
)
1352 if (SendMessage(hwnd
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
)
1354 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1355 L
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
1361 RegSetValueExW(hKey
,
1362 L
"DisableAutoDaylightTimeSet",
1373 SetSystemLocalTime(HWND hwnd
, PSETUPDATA SetupData
)
1377 TOKEN_PRIVILEGES priv
, previouspriv
;
1381 * enable the SeSystemtimePrivilege privilege
1384 if(OpenProcessToken(GetCurrentProcess(),
1385 TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
,
1388 priv
.PrivilegeCount
= 1;
1389 priv
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1391 if(LookupPrivilegeValue(NULL
,
1393 &priv
.Privileges
[0].Luid
))
1395 if(AdjustTokenPrivileges(hToken
,
1398 sizeof(previouspriv
),
1401 GetLastError() == ERROR_SUCCESS
)
1404 * We successfully enabled it, we're permitted to change the system time
1405 * Call SetLocalTime twice to ensure correct results
1407 Ret
= SetLocalTime(&SetupData
->SystemTime
) &&
1408 SetLocalTime(&SetupData
->SystemTime
);
1411 * for the sake of security, restore the previous status again
1413 if(previouspriv
.PrivilegeCount
> 0)
1415 AdjustTokenPrivileges(hToken
,
1424 CloseHandle(hToken
);
1431 WriteDateTimeSettings(HWND hwndDlg
, PSETUPDATA SetupData
)
1434 WCHAR ErrorLocalTime
[256];
1435 GetLocalSystemTime(hwndDlg
, SetupData
);
1436 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1439 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1440 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1442 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
1444 wcscpy(Title
, L
"ReactOS Setup");
1446 if (0 == LoadStringW(hDllInstance
, IDS_WZD_LOCALTIME
, ErrorLocalTime
,
1447 sizeof(ErrorLocalTime
) / sizeof(ErrorLocalTime
[0])))
1449 wcscpy(ErrorLocalTime
, L
"Setup was unable to set the local time.");
1451 MessageBoxW(hwndDlg
, ErrorLocalTime
, Title
, MB_ICONWARNING
| MB_OK
);
1458 static INT_PTR CALLBACK
1459 DateTimePageDlgProc(HWND hwndDlg
,
1464 PSETUPDATA SetupData
;
1466 /* Retrieve pointer to the global setup data */
1467 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1473 /* Save pointer to the global setup data */
1474 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1475 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1477 CreateTimeZoneList(SetupData
);
1479 if (SetupData
->UnattendSetup
)
1481 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1482 SetupData
, SetupData
->TimeZoneIndex
);
1484 if (!SetupData
->DisableAutoDaylightTimeSet
)
1486 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1491 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1492 SetupData
, 85 /* GMT time zone */);
1494 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1503 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1508 /* Enable the Back and Next buttons */
1509 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
1510 if (SetupData
->UnattendSetup
&& WriteDateTimeSettings(hwndDlg
, SetupData
))
1512 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_PROCESSPAGE
);
1519 WriteDateTimeSettings(hwndDlg
, SetupData
);
1524 SetupData
->UnattendSetup
= FALSE
;
1534 DestroyTimeZoneList(SetupData
);
1545 static UINT CALLBACK
1546 RegistrationNotificationProc(PVOID Context
,
1551 PREGISTRATIONDATA RegistrationData
;
1552 REGISTRATIONNOTIFY RegistrationNotify
;
1553 PSP_REGISTER_CONTROL_STATUSW StatusInfo
;
1555 WCHAR ErrorMessage
[128];
1557 RegistrationData
= (PREGISTRATIONDATA
) Context
;
1559 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
||
1560 SPFILENOTIFY_ENDREGISTRATION
== Notification
)
1562 StatusInfo
= (PSP_REGISTER_CONTROL_STATUSW
) Param1
;
1563 RegistrationNotify
.CurrentItem
= wcsrchr(StatusInfo
->FileName
, L
'\\');
1564 if (NULL
== RegistrationNotify
.CurrentItem
)
1566 RegistrationNotify
.CurrentItem
= StatusInfo
->FileName
;
1570 RegistrationNotify
.CurrentItem
++;
1573 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
)
1575 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1576 StatusInfo
->FileName
);
1577 RegistrationNotify
.ErrorMessage
= NULL
;
1578 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1582 DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
1583 StatusInfo
->FileName
);
1584 DPRINT("Win32Error %u FailureCode %u\n", StatusInfo
->Win32Error
,
1585 StatusInfo
->FailureCode
);
1586 if (SPREG_SUCCESS
!= StatusInfo
->FailureCode
)
1588 switch(StatusInfo
->FailureCode
)
1590 case SPREG_LOADLIBRARY
:
1591 MessageID
= IDS_LOADLIBRARY_FAILED
;
1593 case SPREG_GETPROCADDR
:
1594 MessageID
= IDS_GETPROCADDR_FAILED
;
1597 MessageID
= IDS_REGSVR_FAILED
;
1599 case SPREG_DLLINSTALL
:
1600 MessageID
= IDS_DLLINSTALL_FAILED
;
1603 MessageID
= IDS_TIMEOUT
;
1606 MessageID
= IDS_REASON_UNKNOWN
;
1609 if (0 == LoadStringW(hDllInstance
, MessageID
,
1611 sizeof(ErrorMessage
) /
1612 sizeof(ErrorMessage
[0])))
1614 ErrorMessage
[0] = L
'\0';
1616 if (SPREG_TIMEOUT
!= StatusInfo
->FailureCode
)
1618 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
1619 StatusInfo
->Win32Error
, 0,
1620 ErrorMessage
+ wcslen(ErrorMessage
),
1621 sizeof(ErrorMessage
) / sizeof(ErrorMessage
[0]) -
1622 wcslen(ErrorMessage
), NULL
);
1624 RegistrationNotify
.ErrorMessage
= ErrorMessage
;
1628 RegistrationNotify
.ErrorMessage
= NULL
;
1630 if (RegistrationData
->Registered
< RegistrationData
->DllCount
)
1632 RegistrationData
->Registered
++;
1636 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1637 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1638 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1639 0, (LPARAM
) &RegistrationNotify
);
1645 DPRINT1("Received unexpected notification %u\n", Notification
);
1646 return SetupDefaultQueueCallback(RegistrationData
->DefaultContext
,
1647 Notification
, Param1
, Param2
);
1652 static DWORD CALLBACK
1653 RegistrationProc(LPVOID Parameter
)
1655 PREGISTRATIONDATA RegistrationData
;
1656 REGISTRATIONNOTIFY RegistrationNotify
;
1657 DWORD LastError
= NO_ERROR
;
1658 WCHAR UnknownError
[84];
1660 RegistrationData
= (PREGISTRATIONDATA
) Parameter
;
1661 RegistrationData
->Registered
= 0;
1662 RegistrationData
->DefaultContext
= SetupInitDefaultQueueCallback(RegistrationData
->hwndDlg
);
1666 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData
->hwndDlg
),
1668 L
"RegistrationPhase2",
1670 SPINST_REGISTERCALLBACKAWARE
|
1675 RegistrationNotificationProc
,
1680 LastError
= GetLastError();
1683 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1685 DPRINT("Catching exception\n");
1686 LastError
= RtlNtStatusToDosError(_SEH2_GetExceptionCode());
1690 if (NO_ERROR
== LastError
)
1692 RegistrationNotify
.ErrorMessage
= NULL
;
1696 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1698 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1699 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, LastError
, 0,
1700 (LPWSTR
) &RegistrationNotify
.ErrorMessage
, 0,
1703 if (0 == LoadStringW(hDllInstance
, IDS_UNKNOWN_ERROR
,
1705 sizeof(UnknownError
) / sizeof(UnknownError
[0]) -
1708 wcscpy(UnknownError
, L
"Unknown error");
1710 wcscat(UnknownError
, L
" ");
1711 _ultow(LastError
, UnknownError
+ wcslen(UnknownError
), 10);
1712 RegistrationNotify
.ErrorMessage
= UnknownError
;
1716 RegistrationNotify
.Progress
= RegistrationData
->DllCount
;
1717 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1718 RegistrationNotify
.CurrentItem
= NULL
;
1719 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1720 1, (LPARAM
) &RegistrationNotify
);
1721 if (NULL
!= RegistrationNotify
.ErrorMessage
&&
1722 UnknownError
!= RegistrationNotify
.ErrorMessage
)
1724 LocalFree((PVOID
) RegistrationNotify
.ErrorMessage
);
1727 SetupTermDefaultQueueCallback(RegistrationData
->DefaultContext
);
1728 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1730 // FIXME: Move this call to a separate cleanup page!
1731 RtlCreateBootStatusDataFile();
1738 StartComponentRegistration(HWND hwndDlg
, PULONG MaxProgress
)
1740 HANDLE RegistrationThread
;
1743 WCHAR SectionName
[512];
1744 PREGISTRATIONDATA RegistrationData
;
1747 if (! SetupFindFirstLineW(hSysSetupInf
, L
"RegistrationPhase2",
1748 L
"RegisterDlls", &Context
))
1750 DPRINT1("No RegistrationPhase2 section found\n");
1753 if (! SetupGetStringFieldW(&Context
, 1, SectionName
,
1754 sizeof(SectionName
) / sizeof(SectionName
[0]),
1757 DPRINT1("Unable to retrieve section name\n");
1760 DllCount
= SetupGetLineCountW(hSysSetupInf
, SectionName
);
1761 DPRINT("SectionName %S DllCount %ld\n", SectionName
, DllCount
);
1764 SetLastError(STATUS_NOT_FOUND
);
1768 *MaxProgress
= (ULONG
) DllCount
;
1771 * Create a background thread to do the actual registrations, so the
1772 * main thread can just run its message loop.
1774 RegistrationThread
= NULL
;
1775 RegistrationData
= HeapAlloc(GetProcessHeap(), 0,
1776 sizeof(REGISTRATIONDATA
));
1777 if (RegistrationData
!= NULL
)
1779 RegistrationData
->hwndDlg
= hwndDlg
;
1780 RegistrationData
->DllCount
= DllCount
;
1781 RegistrationThread
= CreateThread(NULL
, 0, RegistrationProc
,
1782 (LPVOID
) RegistrationData
, 0, NULL
);
1783 if (RegistrationThread
!= NULL
)
1785 CloseHandle(RegistrationThread
);
1789 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1790 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1796 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1804 static INT_PTR CALLBACK
1805 ProcessPageDlgProc(HWND hwndDlg
,
1810 PSETUPDATA SetupData
;
1811 PREGISTRATIONNOTIFY RegistrationNotify
;
1812 static UINT oldActivityID
= -1;
1815 /* Retrieve pointer to the global setup data */
1816 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1822 /* Save pointer to the global setup data */
1823 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1824 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1830 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1831 ULONG MaxProgress
= 0;
1836 /* Disable the Back and Next buttons */
1837 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
1839 StartComponentRegistration(hwndDlg
, &MaxProgress
);
1841 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
,
1842 0, MAKELPARAM(0, MaxProgress
));
1843 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1851 SetupData
->UnattendSetup
= FALSE
;
1860 case PM_REGISTRATION_NOTIFY
:
1863 RegistrationNotify
= (PREGISTRATIONNOTIFY
) lParam
;
1864 // update if necessary only
1865 if (oldActivityID
!= RegistrationNotify
->ActivityID
)
1867 if (0 != LoadStringW(hDllInstance
, RegistrationNotify
->ActivityID
,
1869 sizeof(Activity
) / sizeof(Activity
[0])))
1871 SendDlgItemMessageW(hwndDlg
, IDC_ACTIVITY
, WM_SETTEXT
,
1872 0, (LPARAM
) Activity
);
1874 oldActivityID
= RegistrationNotify
->ActivityID
;
1876 SendDlgItemMessageW(hwndDlg
, IDC_ITEM
, WM_SETTEXT
, 0,
1877 (LPARAM
)(NULL
== RegistrationNotify
->CurrentItem
?
1878 L
"" : RegistrationNotify
->CurrentItem
));
1879 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1880 RegistrationNotify
->Progress
, 0);
1881 if (NULL
!= RegistrationNotify
->ErrorMessage
)
1883 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
,
1884 Title
, sizeof(Title
) / sizeof(Title
[0])))
1886 wcscpy(Title
, L
"ReactOS Setup");
1888 MessageBoxW(hwndDlg
, RegistrationNotify
->ErrorMessage
,
1889 Title
, MB_ICONERROR
| MB_OK
);
1896 if(!SetupData
->UnattendSetup
&& !SetupData
->DisableVmwInst
)
1897 RunVMWInstall(GetParent(hwndDlg
));
1900 /* Enable the Back and Next buttons */
1901 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
1902 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
1916 SetInstallationCompleted(VOID
)
1919 DWORD InProgress
= 0;
1922 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1926 &hKey
) == ERROR_SUCCESS
)
1928 RegSetValueExW( hKey
, L
"SystemSetupInProgress", 0, REG_DWORD
, (LPBYTE
)&InProgress
, sizeof(InProgress
) );
1929 RegCloseKey( hKey
);
1932 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1933 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
1936 &hKey
) == ERROR_SUCCESS
)
1938 InstallDate
= (DWORD
)time(NULL
);
1939 RegSetValueExW( hKey
, L
"InstallDate", 0, REG_DWORD
, (LPBYTE
)&InstallDate
, sizeof(InstallDate
) );
1940 RegCloseKey( hKey
);
1945 static INT_PTR CALLBACK
1946 FinishDlgProc(HWND hwndDlg
,
1956 PSETUPDATA SetupData
;
1958 /* Get pointer to the global setup data */
1959 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1961 /* Set title font */
1962 SendDlgItemMessage(hwndDlg
,
1965 (WPARAM
)SetupData
->hTitleFont
,
1967 if (SetupData
->UnattendSetup
)
1969 KillTimer(hwndDlg
, 1);
1970 SetInstallationCompleted();
1978 SetInstallationCompleted();
1988 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
1989 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
1990 if (Position
== 300)
1992 KillTimer(hwndDlg
, 1);
1993 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
1997 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
2004 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
2009 /* Enable the correct buttons on for the active page */
2010 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
2012 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
2013 MAKELPARAM(0, 300));
2014 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETPOS
, 0, 0);
2015 SetTimer(hwndDlg
, 1, 50, NULL
);
2019 DestroyWindow(GetParent(hwndDlg
));
2037 ProcessUnattendInf(HINF hUnattendedInf
)
2039 INFCONTEXT InfContext
;
2041 WCHAR szValue
[MAX_PATH
];
2045 if (!SetupFindFirstLineW(hUnattendedInf
,
2047 L
"UnattendSetupEnabled",
2050 DPRINT1("Error: Cant find UnattendSetupEnabled Key! %d\n", GetLastError());
2054 if (!SetupGetStringFieldW(&InfContext
,
2057 sizeof(szValue
) / sizeof(WCHAR
),
2060 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2064 if (wcscmp(szValue
, L
"yes") != 0)
2066 DPRINT("Unattend setup was disabled by UnattendSetupEnabled key.\n");
2070 if (!SetupFindFirstLineW(hUnattendedInf
,
2075 DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError());
2082 if (!SetupGetStringFieldW(&InfContext
,
2085 sizeof(szName
) / sizeof(WCHAR
),
2088 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2092 if (!SetupGetStringFieldW(&InfContext
,
2095 sizeof(szValue
) / sizeof(WCHAR
),
2098 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2101 DPRINT1("Name %S Value %S\n", szName
, szValue
);
2102 if (!wcscmp(szName
, L
"FullName"))
2104 if ((sizeof(SetupData
.OwnerName
) / sizeof(TCHAR
)) > LineLength
)
2106 wcscpy(SetupData
.OwnerName
, szValue
);
2109 else if (!wcscmp(szName
, L
"OrgName"))
2111 if ((sizeof(SetupData
.OwnerOrganization
) / sizeof(WCHAR
)) > LineLength
)
2113 wcscpy(SetupData
.OwnerOrganization
, szValue
);
2116 else if (!wcscmp(szName
, L
"ComputerName"))
2118 if ((sizeof(SetupData
.ComputerName
) / sizeof(WCHAR
)) > LineLength
)
2120 wcscpy(SetupData
.ComputerName
, szValue
);
2123 else if (!wcscmp(szName
, L
"AdminPassword"))
2125 if ((sizeof(SetupData
.AdminPassword
) / sizeof(WCHAR
)) > LineLength
)
2127 wcscpy(SetupData
.AdminPassword
, szValue
);
2130 else if (!wcscmp(szName
, L
"TimeZoneIndex"))
2132 SetupData
.TimeZoneIndex
= _wtoi(szValue
);
2134 else if (!wcscmp(szName
, L
"DisableAutoDaylightTimeSet"))
2136 SetupData
.DisableAutoDaylightTimeSet
= _wtoi(szValue
);
2138 else if (!wcscmp(szName
, L
"DisableVmwInst"))
2140 if(!wcscmp(szValue
, L
"yes"))
2141 SetupData
.DisableVmwInst
= 1;
2143 SetupData
.DisableVmwInst
= 0;
2147 while (SetupFindNextLine(&InfContext
, &InfContext
));
2149 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
2150 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
2153 &hKey
) != ERROR_SUCCESS
)
2155 DPRINT1("Error: failed to open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\n");
2160 if (SetupFindFirstLineW(hUnattendedInf
,
2169 if(SetupGetStringFieldW(&InfContext
,
2172 sizeof(szValue
) / sizeof(WCHAR
),
2175 WCHAR szPath
[MAX_PATH
];
2176 swprintf(szName
, L
"%d", i
);
2177 DPRINT("szName %S szValue %S\n", szName
, szValue
);
2179 if (ExpandEnvironmentStringsW(szValue
, szPath
, MAX_PATH
))
2181 DPRINT("value %S\n", szPath
);
2182 if (RegSetValueExW(hKey
,
2186 (const BYTE
*)szPath
,
2187 (wcslen(szPath
) + 1) * sizeof(WCHAR
)) == ERROR_SUCCESS
)
2193 } while(SetupFindNextLine(&InfContext
, &InfContext
));
2201 * GetRosInstallCD should find the path to ros installation medium
2203 * If there are more than one CDDrive in it containing a ReactOS
2204 * installation cd, then it will pick the first one regardless if
2205 * it is really the installation cd
2207 * The best way to implement this is to set the key
2208 * HKLM\Software\Microsoft\Windows NT\CurrentVersion\SourcePath (REG_SZ)
2212 GetRosInstallCD(WCHAR
*pwszPath
, DWORD cchPathMax
)
2214 WCHAR wszDrives
[512];
2218 cchDrives
= GetLogicalDriveStringsW(_countof(wszDrives
) - 1, wszDrives
);
2219 if (cchDrives
== 0 || cchDrives
>= _countof(wszDrives
))
2221 /* buffer too small or failure */
2222 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"GetLogicalDriveStringsW failed");
2226 for (pwszDrive
= wszDrives
; pwszDrive
[0]; pwszDrive
+= wcslen(pwszDrive
) + 1)
2228 if (GetDriveTypeW(pwszDrive
) == DRIVE_CDROM
)
2230 WCHAR wszBuf
[MAX_PATH
];
2231 wsprintf(wszBuf
, L
"%sreactos\\system32\\ntoskrnl.exe", pwszDrive
);
2232 LogItem(SYSSETUP_SEVERITY_INFORMATION
, wszBuf
);
2233 if (GetFileAttributesW(wszBuf
) != INVALID_FILE_ATTRIBUTES
)
2235 /* the file exists, so this is the right drive */
2236 wcsncpy(pwszPath
, pwszDrive
, cchPathMax
);
2237 OutputDebugStringW(L
"GetRosInstallCD: ");OutputDebugStringW(pwszPath
);OutputDebugStringW(L
"\n");
2247 ProcessUnattendSetup(VOID
)
2249 WCHAR szPath
[MAX_PATH
];
2250 HINF hUnattendedInf
;
2253 if (!GetRosInstallCD(szPath
, MAX_PATH
))
2255 /* no cd drive found */
2259 dwLength
= wcslen(szPath
);
2260 if (dwLength
+ 21 > MAX_PATH
)
2263 * allocate bigger buffer
2268 wcscat(szPath
, L
"reactos\\unattend.inf");
2270 hUnattendedInf
= SetupOpenInfFileW(szPath
,
2275 if (hUnattendedInf
!= INVALID_HANDLE_VALUE
)
2277 SetupData
.UnattendSetup
= ProcessUnattendInf(hUnattendedInf
);
2278 SetupCloseInfFile(hUnattendedInf
);
2286 PROPSHEETHEADER psh
;
2287 HPROPSHEETPAGE ahpsp
[8];
2288 PROPSHEETPAGE psp
= {0};
2293 /* Clear setup data */
2294 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
2296 ProcessUnattendSetup();
2298 /* Create the Welcome page */
2299 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
2300 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2301 psp
.hInstance
= hDllInstance
;
2302 psp
.lParam
= (LPARAM
)&SetupData
;
2303 psp
.pfnDlgProc
= WelcomeDlgProc
;
2304 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
2305 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2307 /* Create the Acknowledgements page */
2308 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2309 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_ACKTITLE
);
2310 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_ACKSUBTITLE
);
2311 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_ACKPAGE
);
2312 psp
.pfnDlgProc
= AckPageDlgProc
;
2313 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2315 /* Create the Owner page */
2316 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2317 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_OWNERTITLE
);
2318 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_OWNERSUBTITLE
);
2319 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_OWNERPAGE
);
2320 psp
.pfnDlgProc
= OwnerPageDlgProc
;
2321 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2323 /* Create the Computer page */
2324 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2325 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_COMPUTERTITLE
);
2326 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE
);
2327 psp
.pfnDlgProc
= ComputerPageDlgProc
;
2328 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_COMPUTERPAGE
);
2329 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2332 /* Create the Locale page */
2333 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2334 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LOCALETITLE
);
2335 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LOCALESUBTITLE
);
2336 psp
.pfnDlgProc
= LocalePageDlgProc
;
2337 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
2338 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2341 /* Create the DateTime page */
2342 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2343 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DATETIMETITLE
);
2344 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DATETIMESUBTITLE
);
2345 psp
.pfnDlgProc
= DateTimePageDlgProc
;
2346 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DATETIMEPAGE
);
2347 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2350 /* Create the Process page */
2351 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2352 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
2353 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
2354 psp
.pfnDlgProc
= ProcessPageDlgProc
;
2355 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
2356 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2359 /* Create the Finish page */
2360 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2361 psp
.pfnDlgProc
= FinishDlgProc
;
2362 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
2363 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2365 /* Create the property sheet */
2366 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2367 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
| PSH_MODELESS
;
2368 psh
.hInstance
= hDllInstance
;
2369 psh
.hwndParent
= NULL
;
2370 psh
.nPages
= nPages
;
2373 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
2374 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
2376 /* Create title font */
2377 SetupData
.hTitleFont
= CreateTitleFont();
2379 /* Display the wizard */
2380 hWnd
= (HWND
)PropertySheet(&psh
);
2381 ShowWindow(hWnd
, SW_SHOW
);
2383 while (GetMessage(&msg
, NULL
, 0, 0))
2385 if(!IsDialogMessage(hWnd
, &msg
))
2387 TranslateMessage(&msg
);
2388 DispatchMessage(&msg
);
2392 DeleteObject(SetupData
.hTitleFont
);