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
* szPath
, DWORD dwPathLength
);
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
;
525 WriteComputerSettings(WCHAR
* ComputerName
, HWND hwndDlg
)
528 WCHAR ErrorComputerName
[256];
529 if (!SetComputerNameW(ComputerName
))
531 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
533 wcscpy(Title
, L
"ReactOS Setup");
535 if (0 == LoadStringW(hDllInstance
, IDS_WZD_SETCOMPUTERNAME
, ErrorComputerName
,
536 sizeof(ErrorComputerName
) / sizeof(ErrorComputerName
[0])))
538 wcscpy(ErrorComputerName
, L
"Setup failed to set the computer name.");
540 MessageBoxW(hwndDlg
, ErrorComputerName
, Title
, MB_ICONERROR
| MB_OK
);
545 /* Try to also set DNS hostname */
546 SetComputerNameExW(ComputerNamePhysicalDnsHostname
, ComputerName
);
551 /* lpBuffer will be filled with a 15-char string (plus the null terminator) */
553 GenerateComputerName(LPWSTR lpBuffer
)
555 static const WCHAR Chars
[] = L
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
556 static const unsigned cChars
= sizeof(Chars
) / sizeof(WCHAR
) - 1;
559 wcscpy(lpBuffer
, L
"REACTOS-");
561 srand(GetTickCount());
563 /* fill in 7 characters */
564 for (i
= 8; i
< 15; i
++)
565 lpBuffer
[i
] = Chars
[rand() % cChars
];
567 lpBuffer
[15] = UNICODE_NULL
; /* NULL-terminate */
570 static INT_PTR CALLBACK
571 ComputerPageDlgProc(HWND hwndDlg
,
576 WCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
581 WCHAR EmptyComputerName
[256], NotMatchPassword
[256], WrongPassword
[256];
584 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
586 wcscpy(Title
, L
"ReactOS Setup");
593 /* Generate a new pseudo-random computer name */
594 GenerateComputerName(ComputerName
);
596 /* Display current computer name */
597 SetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
599 /* Set text limits */
600 SendDlgItemMessage(hwndDlg
, IDC_COMPUTERNAME
, EM_LIMITTEXT
, MAX_COMPUTERNAME_LENGTH
, 0);
601 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD1
, EM_LIMITTEXT
, 14, 0);
602 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD2
, EM_LIMITTEXT
, 14, 0);
604 /* Set focus to computer name */
605 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
606 if (SetupData
.UnattendSetup
)
608 SendMessage(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.ComputerName
);
609 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD1
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
610 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD2
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
619 lpnm
= (LPNMHDR
)lParam
;
624 /* Enable the Back and Next buttons */
625 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
626 if (SetupData
.UnattendSetup
&& WriteComputerSettings(SetupData
.ComputerName
, hwndDlg
))
628 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_LOCALEPAGE
);
634 if (0 == GetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, MAX_COMPUTERNAME_LENGTH
+ 1))
636 if (0 == LoadStringW(hDllInstance
, IDS_WZD_COMPUTERNAME
, EmptyComputerName
,
637 sizeof(EmptyComputerName
) / sizeof(EmptyComputerName
[0])))
639 wcscpy(EmptyComputerName
, L
"Setup cannot continue until you enter the name of your computer.");
641 MessageBoxW(hwndDlg
, EmptyComputerName
, Title
, MB_ICONERROR
| MB_OK
);
642 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
643 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
647 /* No need to check computer name for invalid characters,
648 * SetComputerName() will do it for us */
650 if (!WriteComputerSettings(ComputerName
, hwndDlg
))
652 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
653 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
658 /* Check if admin passwords have been entered */
659 if ((GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15) == 0) ||
660 (GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15) == 0))
662 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDEMPTY
, EmptyPassword
,
663 sizeof(EmptyPassword
) / sizeof(EmptyPassword
[0])))
665 wcscpy(EmptyPassword
, L
"You must enter a password !");
667 MessageBoxW(hwndDlg
, EmptyPassword
, Title
, MB_ICONERROR
| MB_OK
);
668 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
672 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15);
673 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15);
675 /* Check if passwords match */
676 if (wcscmp(Password1
, Password2
))
678 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDMATCH
, NotMatchPassword
,
679 sizeof(NotMatchPassword
) / sizeof(NotMatchPassword
[0])))
681 wcscpy(NotMatchPassword
, L
"The passwords you entered do not match. Please enter the desired password again.");
683 MessageBoxW(hwndDlg
, NotMatchPassword
, Title
, MB_ICONERROR
| MB_OK
);
684 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
688 /* Check password for invalid characters */
689 Password
= (PWCHAR
)Password1
;
692 if (!isprint(*Password
))
694 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDCHAR
, WrongPassword
,
695 sizeof(WrongPassword
) / sizeof(WrongPassword
[0])))
697 wcscpy(WrongPassword
, L
"The password you entered contains invalid characters. Please enter a cleaned password.");
699 MessageBoxW(hwndDlg
, WrongPassword
, Title
, MB_ICONERROR
| MB_OK
);
700 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
707 /* FIXME: Set admin password */
711 SetupData
.UnattendSetup
= FALSE
;
729 SetKeyboardLayoutName(HWND hwnd
)
732 TCHAR szLayoutPath
[256];
733 TCHAR szLocaleName
[32];
737 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
738 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
744 dwValueSize
= 16 * sizeof(TCHAR
);
745 if (RegQueryValueEx(hKey
,
756 _tcscpy(szLayoutPath
,
757 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"));
758 _tcscat(szLayoutPath
,
761 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
768 dwValueSize
= 32 * sizeof(TCHAR
);
769 if (RegQueryValueEx(hKey
,
786 RunControlPanelApplet(HWND hwnd
, WCHAR
*lpCommandLine
)
788 STARTUPINFOW StartupInfo
;
789 PROCESS_INFORMATION ProcessInformation
;
791 ZeroMemory(&StartupInfo
, sizeof(STARTUPINFOW
));
792 StartupInfo
.cb
= sizeof(STARTUPINFOW
);
794 if (!CreateProcessW(NULL
,
803 &ProcessInformation
))
805 MessageBoxW(hwnd
, L
"Error: failed to launch rundll32", NULL
, MB_ICONERROR
);
809 WaitForSingleObject(ProcessInformation
.hProcess
, INFINITE
);
810 CloseHandle(ProcessInformation
.hThread
);
811 CloseHandle(ProcessInformation
.hProcess
);
816 WriteUserLocale(VOID
)
822 lcid
= GetSystemDefaultLCID();
824 if (GetLocaleInfoW(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_ILANGUAGE
, Locale
, sizeof(Locale
) / sizeof(Locale
[0])) != 0)
826 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Control Panel\\International",
827 0, NULL
, REG_OPTION_NON_VOLATILE
,
828 KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
830 RegSetValueExW(hKey
, L
"Locale", 0, REG_SZ
, (LPBYTE
)Locale
, (wcslen(Locale
)+1) * sizeof(WCHAR
));
836 static INT_PTR CALLBACK
837 LocalePageDlgProc(HWND hwndDlg
,
842 PSETUPDATA SetupData
;
843 WCHAR szBuffer
[1024];
845 /* Retrieve pointer to the global setup data */
846 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
852 /* Save pointer to the global setup data */
853 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
854 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
857 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
862 if (HIWORD(wParam
) == BN_CLICKED
)
864 switch (LOWORD(wParam
))
866 case IDC_CUSTOMLOCALE
:
868 wcscpy(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,5");
869 RunControlPanelApplet(hwndDlg
, szBuffer
);
870 /* FIXME: Update input locale name */
874 case IDC_CUSTOMLAYOUT
:
876 wcscpy(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL input.dll,@1");
877 RunControlPanelApplet(hwndDlg
, szBuffer
);
886 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
891 /* Enable the Back and Next buttons */
892 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
893 if (SetupData
->UnattendSetup
)
895 WCHAR szPath
[MAX_PATH
];
896 if (GetRosInstallCD(szPath
, MAX_PATH
))
898 swprintf(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,/f:\"%S\\reactos\\unattend.inf\"", szPath
);
902 wcscpy(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,/f:\"unattend.inf\"");
905 RunControlPanelApplet(hwndDlg
, szBuffer
);
906 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_DATETIMEPAGE
);
915 SetupData
->UnattendSetup
= FALSE
;
932 static PTIMEZONE_ENTRY
933 GetLargerTimeZoneEntry(PSETUPDATA SetupData
, DWORD Index
)
935 PTIMEZONE_ENTRY Entry
;
937 Entry
= SetupData
->TimeZoneListHead
;
938 while (Entry
!= NULL
)
940 if (Entry
->Index
>= Index
)
951 CreateTimeZoneList(PSETUPDATA SetupData
)
953 WCHAR szKeyName
[256];
961 PTIMEZONE_ENTRY Entry
;
962 PTIMEZONE_ENTRY Current
;
964 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
965 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
974 dwNameSize
= 256 * sizeof(WCHAR
);
975 lError
= RegEnumKeyExW(hZonesKey
,
983 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
986 if (RegOpenKeyExW(hZonesKey
,
993 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
996 RegCloseKey(hZoneKey
);
1000 dwValueSize
= 64 * sizeof(TCHAR
);
1001 if (RegQueryValueExW(hZoneKey
,
1005 (LPBYTE
)&Entry
->Description
,
1008 RegCloseKey(hZoneKey
);
1012 dwValueSize
= 32 * sizeof(TCHAR
);
1013 if (RegQueryValueExW(hZoneKey
,
1017 (LPBYTE
)&Entry
->StandardName
,
1020 RegCloseKey(hZoneKey
);
1024 dwValueSize
= 32 * sizeof(WCHAR
);
1025 if (RegQueryValueExW(hZoneKey
,
1029 (LPBYTE
)&Entry
->DaylightName
,
1032 RegCloseKey(hZoneKey
);
1036 dwValueSize
= sizeof(DWORD
);
1037 if (RegQueryValueExW(hZoneKey
,
1041 (LPBYTE
)&Entry
->Index
,
1044 RegCloseKey(hZoneKey
);
1048 dwValueSize
= sizeof(TZ_INFO
);
1049 if (RegQueryValueExW(hZoneKey
,
1053 (LPBYTE
)&Entry
->TimezoneInfo
,
1056 RegCloseKey(hZoneKey
);
1060 RegCloseKey(hZoneKey
);
1062 if (SetupData
->TimeZoneListHead
== NULL
&&
1063 SetupData
->TimeZoneListTail
== NULL
)
1067 SetupData
->TimeZoneListHead
= Entry
;
1068 SetupData
->TimeZoneListTail
= Entry
;
1072 Current
= GetLargerTimeZoneEntry(SetupData
, Entry
->Index
);
1073 if (Current
!= NULL
)
1075 if (Current
== SetupData
->TimeZoneListHead
)
1077 /* Prepend to head */
1079 Entry
->Next
= SetupData
->TimeZoneListHead
;
1080 SetupData
->TimeZoneListHead
->Prev
= Entry
;
1081 SetupData
->TimeZoneListHead
= Entry
;
1085 /* Insert before current */
1086 Entry
->Prev
= Current
->Prev
;
1087 Entry
->Next
= Current
;
1088 Current
->Prev
->Next
= Entry
;
1089 Current
->Prev
= Entry
;
1094 /* Append to tail */
1095 Entry
->Prev
= SetupData
->TimeZoneListTail
;
1097 SetupData
->TimeZoneListTail
->Next
= Entry
;
1098 SetupData
->TimeZoneListTail
= Entry
;
1105 RegCloseKey(hZonesKey
);
1110 DestroyTimeZoneList(PSETUPDATA SetupData
)
1112 PTIMEZONE_ENTRY Entry
;
1114 while (SetupData
->TimeZoneListHead
!= NULL
)
1116 Entry
= SetupData
->TimeZoneListHead
;
1118 SetupData
->TimeZoneListHead
= Entry
->Next
;
1119 if (SetupData
->TimeZoneListHead
!= NULL
)
1121 SetupData
->TimeZoneListHead
->Prev
= NULL
;
1124 HeapFree(GetProcessHeap(), 0, Entry
);
1127 SetupData
->TimeZoneListTail
= NULL
;
1131 GetTimeZoneListIndex(LPDWORD lpIndex
)
1133 WCHAR szLanguageIdString
[9];
1140 BOOL bFound
= FALSE
;
1141 unsigned long iLanguageID
;
1143 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1144 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
1150 dwValueSize
= 9 * sizeof(TCHAR
);
1151 if (RegQueryValueExW(hKey
,
1155 (LPBYTE
)szLanguageIdString
,
1162 iLanguageID
= wcstoul(szLanguageIdString
, NULL
, 16);
1165 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1166 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1173 if (RegQueryValueExW(hKey
,
1184 Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
1191 if (RegQueryValueExW(hKey
,
1198 HeapFree(GetProcessHeap(), 0, Buffer
);
1208 Length
= wcslen(Ptr
);
1209 if (wcstoul(Ptr
, NULL
, 16) == iLanguageID
)
1212 Ptr
= Ptr
+ Length
+ 1;
1218 *lpIndex
= wcstoul(Ptr
, &End
, 10);
1219 HeapFree(GetProcessHeap(), 0, Buffer
);
1223 Length
= wcslen(Ptr
);
1224 Ptr
= Ptr
+ Length
+ 1;
1227 HeapFree(GetProcessHeap(), 0, Buffer
);
1234 ShowTimeZoneList(HWND hwnd
, PSETUPDATA SetupData
, DWORD dwEntryIndex
)
1236 PTIMEZONE_ENTRY Entry
;
1240 GetTimeZoneListIndex(&dwEntryIndex
);
1242 Entry
= SetupData
->TimeZoneListHead
;
1243 while (Entry
!= NULL
)
1245 dwCount
= SendMessage(hwnd
,
1248 (LPARAM
)Entry
->Description
);
1250 if (dwEntryIndex
!= 0 && dwEntryIndex
== Entry
->Index
)
1253 Entry
= Entry
->Next
;
1264 SetLocalTimeZone(HWND hwnd
, PSETUPDATA SetupData
)
1266 TIME_ZONE_INFORMATION TimeZoneInformation
;
1267 PTIMEZONE_ENTRY Entry
;
1271 dwIndex
= SendMessage(hwnd
,
1277 Entry
= SetupData
->TimeZoneListHead
;
1284 Entry
= Entry
->Next
;
1287 wcscpy(TimeZoneInformation
.StandardName
,
1288 Entry
->StandardName
);
1289 wcscpy(TimeZoneInformation
.DaylightName
,
1290 Entry
->DaylightName
);
1292 TimeZoneInformation
.Bias
= Entry
->TimezoneInfo
.Bias
;
1293 TimeZoneInformation
.StandardBias
= Entry
->TimezoneInfo
.StandardBias
;
1294 TimeZoneInformation
.DaylightBias
= Entry
->TimezoneInfo
.DaylightBias
;
1296 memcpy(&TimeZoneInformation
.StandardDate
,
1297 &Entry
->TimezoneInfo
.StandardDate
,
1298 sizeof(SYSTEMTIME
));
1299 memcpy(&TimeZoneInformation
.DaylightDate
,
1300 &Entry
->TimezoneInfo
.DaylightDate
,
1301 sizeof(SYSTEMTIME
));
1303 /* Set time zone information */
1304 SetTimeZoneInformation(&TimeZoneInformation
);
1309 GetLocalSystemTime(HWND hwnd
, PSETUPDATA SetupData
)
1314 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) != GDT_VALID
)
1319 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) != GDT_VALID
)
1324 SetupData
->SystemTime
.wYear
= Date
.wYear
;
1325 SetupData
->SystemTime
.wMonth
= Date
.wMonth
;
1326 SetupData
->SystemTime
.wDayOfWeek
= Date
.wDayOfWeek
;
1327 SetupData
->SystemTime
.wDay
= Date
.wDay
;
1328 SetupData
->SystemTime
.wHour
= Time
.wHour
;
1329 SetupData
->SystemTime
.wMinute
= Time
.wMinute
;
1330 SetupData
->SystemTime
.wSecond
= Time
.wSecond
;
1331 SetupData
->SystemTime
.wMilliseconds
= Time
.wMilliseconds
;
1338 SetAutoDaylightInfo(HWND hwnd
)
1343 if (SendMessage(hwnd
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
)
1345 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1346 L
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
1352 RegSetValueExW(hKey
,
1353 L
"DisableAutoDaylightTimeSet",
1364 SetSystemLocalTime(HWND hwnd
, PSETUPDATA SetupData
)
1368 TOKEN_PRIVILEGES priv
, previouspriv
;
1372 * enable the SeSystemtimePrivilege privilege
1375 if(OpenProcessToken(GetCurrentProcess(),
1376 TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
,
1379 priv
.PrivilegeCount
= 1;
1380 priv
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1382 if(LookupPrivilegeValue(NULL
,
1384 &priv
.Privileges
[0].Luid
))
1386 if(AdjustTokenPrivileges(hToken
,
1389 sizeof(previouspriv
),
1392 GetLastError() == ERROR_SUCCESS
)
1395 * We successfully enabled it, we're permitted to change the system time
1396 * Call SetLocalTime twice to ensure correct results
1398 Ret
= SetLocalTime(&SetupData
->SystemTime
) &&
1399 SetLocalTime(&SetupData
->SystemTime
);
1402 * for the sake of security, restore the previous status again
1404 if(previouspriv
.PrivilegeCount
> 0)
1406 AdjustTokenPrivileges(hToken
,
1415 CloseHandle(hToken
);
1422 WriteDateTimeSettings(HWND hwndDlg
, PSETUPDATA SetupData
)
1425 WCHAR ErrorLocalTime
[256];
1426 GetLocalSystemTime(hwndDlg
, SetupData
);
1427 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1430 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1431 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1433 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
1435 wcscpy(Title
, L
"ReactOS Setup");
1437 if (0 == LoadStringW(hDllInstance
, IDS_WZD_LOCALTIME
, ErrorLocalTime
,
1438 sizeof(ErrorLocalTime
) / sizeof(ErrorLocalTime
[0])))
1440 wcscpy(ErrorLocalTime
, L
"Setup was unable to set the local time.");
1442 MessageBoxW(hwndDlg
, ErrorLocalTime
, Title
, MB_ICONWARNING
| MB_OK
);
1449 static INT_PTR CALLBACK
1450 DateTimePageDlgProc(HWND hwndDlg
,
1455 PSETUPDATA SetupData
;
1457 /* Retrieve pointer to the global setup data */
1458 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1464 /* Save pointer to the global setup data */
1465 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1466 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1468 CreateTimeZoneList(SetupData
);
1470 if (SetupData
->UnattendSetup
)
1472 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1473 SetupData
, SetupData
->TimeZoneIndex
);
1475 if (!SetupData
->DisableAutoDaylightTimeSet
)
1477 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1482 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1483 SetupData
, 85 /* GMT time zone */);
1485 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1494 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1499 /* Enable the Back and Next buttons */
1500 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
1501 if (SetupData
->UnattendSetup
&& WriteDateTimeSettings(hwndDlg
, SetupData
))
1503 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_PROCESSPAGE
);
1510 WriteDateTimeSettings(hwndDlg
, SetupData
);
1515 SetupData
->UnattendSetup
= FALSE
;
1525 DestroyTimeZoneList(SetupData
);
1536 static UINT CALLBACK
1537 RegistrationNotificationProc(PVOID Context
,
1542 PREGISTRATIONDATA RegistrationData
;
1543 REGISTRATIONNOTIFY RegistrationNotify
;
1544 PSP_REGISTER_CONTROL_STATUSW StatusInfo
;
1546 WCHAR ErrorMessage
[128];
1548 RegistrationData
= (PREGISTRATIONDATA
) Context
;
1550 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
||
1551 SPFILENOTIFY_ENDREGISTRATION
== Notification
)
1553 StatusInfo
= (PSP_REGISTER_CONTROL_STATUSW
) Param1
;
1554 RegistrationNotify
.CurrentItem
= wcsrchr(StatusInfo
->FileName
, L
'\\');
1555 if (NULL
== RegistrationNotify
.CurrentItem
)
1557 RegistrationNotify
.CurrentItem
= StatusInfo
->FileName
;
1561 RegistrationNotify
.CurrentItem
++;
1564 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
)
1566 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1567 StatusInfo
->FileName
);
1568 RegistrationNotify
.ErrorMessage
= NULL
;
1569 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1573 DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
1574 StatusInfo
->FileName
);
1575 DPRINT("Win32Error %u FailureCode %u\n", StatusInfo
->Win32Error
,
1576 StatusInfo
->FailureCode
);
1577 if (SPREG_SUCCESS
!= StatusInfo
->FailureCode
)
1579 switch(StatusInfo
->FailureCode
)
1581 case SPREG_LOADLIBRARY
:
1582 MessageID
= IDS_LOADLIBRARY_FAILED
;
1584 case SPREG_GETPROCADDR
:
1585 MessageID
= IDS_GETPROCADDR_FAILED
;
1588 MessageID
= IDS_REGSVR_FAILED
;
1590 case SPREG_DLLINSTALL
:
1591 MessageID
= IDS_DLLINSTALL_FAILED
;
1594 MessageID
= IDS_TIMEOUT
;
1597 MessageID
= IDS_REASON_UNKNOWN
;
1600 if (0 == LoadStringW(hDllInstance
, MessageID
,
1602 sizeof(ErrorMessage
) /
1603 sizeof(ErrorMessage
[0])))
1605 ErrorMessage
[0] = L
'\0';
1607 if (SPREG_TIMEOUT
!= StatusInfo
->FailureCode
)
1609 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
1610 StatusInfo
->Win32Error
, 0,
1611 ErrorMessage
+ wcslen(ErrorMessage
),
1612 sizeof(ErrorMessage
) / sizeof(ErrorMessage
[0]) -
1613 wcslen(ErrorMessage
), NULL
);
1615 RegistrationNotify
.ErrorMessage
= ErrorMessage
;
1619 RegistrationNotify
.ErrorMessage
= NULL
;
1621 if (RegistrationData
->Registered
< RegistrationData
->DllCount
)
1623 RegistrationData
->Registered
++;
1627 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1628 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1629 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1630 0, (LPARAM
) &RegistrationNotify
);
1636 DPRINT1("Received unexpected notification %u\n", Notification
);
1637 return SetupDefaultQueueCallback(RegistrationData
->DefaultContext
,
1638 Notification
, Param1
, Param2
);
1643 static DWORD CALLBACK
1644 RegistrationProc(LPVOID Parameter
)
1646 PREGISTRATIONDATA RegistrationData
;
1647 REGISTRATIONNOTIFY RegistrationNotify
;
1648 DWORD LastError
= NO_ERROR
;
1649 WCHAR UnknownError
[84];
1651 RegistrationData
= (PREGISTRATIONDATA
) Parameter
;
1652 RegistrationData
->Registered
= 0;
1653 RegistrationData
->DefaultContext
= SetupInitDefaultQueueCallback(RegistrationData
->hwndDlg
);
1657 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData
->hwndDlg
),
1659 L
"RegistrationPhase2",
1661 SPINST_REGISTERCALLBACKAWARE
|
1666 RegistrationNotificationProc
,
1671 LastError
= GetLastError();
1674 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1676 DPRINT("Catching exception\n");
1677 LastError
= RtlNtStatusToDosError(_SEH2_GetExceptionCode());
1681 if (NO_ERROR
== LastError
)
1683 RegistrationNotify
.ErrorMessage
= NULL
;
1687 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1689 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1690 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, LastError
, 0,
1691 (LPWSTR
) &RegistrationNotify
.ErrorMessage
, 0,
1694 if (0 == LoadStringW(hDllInstance
, IDS_UNKNOWN_ERROR
,
1696 sizeof(UnknownError
) / sizeof(UnknownError
[0] -
1699 wcscpy(UnknownError
, L
"Unknown error");
1701 wcscat(UnknownError
, L
" ");
1702 _ultow(LastError
, UnknownError
+ wcslen(UnknownError
), 10);
1703 RegistrationNotify
.ErrorMessage
= UnknownError
;
1707 RegistrationNotify
.Progress
= RegistrationData
->DllCount
;
1708 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1709 RegistrationNotify
.CurrentItem
= NULL
;
1710 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1711 1, (LPARAM
) &RegistrationNotify
);
1712 if (NULL
!= RegistrationNotify
.ErrorMessage
&&
1713 UnknownError
!= RegistrationNotify
.ErrorMessage
)
1715 LocalFree((PVOID
) RegistrationNotify
.ErrorMessage
);
1718 SetupTermDefaultQueueCallback(RegistrationData
->DefaultContext
);
1719 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1726 StartComponentRegistration(HWND hwndDlg
, PULONG MaxProgress
)
1728 HANDLE RegistrationThread
;
1731 WCHAR SectionName
[512];
1732 PREGISTRATIONDATA RegistrationData
;
1735 if (! SetupFindFirstLineW(hSysSetupInf
, L
"RegistrationPhase2",
1736 L
"RegisterDlls", &Context
))
1738 DPRINT1("No RegistrationPhase2 section found\n");
1741 if (! SetupGetStringFieldW(&Context
, 1, SectionName
,
1742 sizeof(SectionName
) / sizeof(SectionName
[0]),
1745 DPRINT1("Unable to retrieve section name\n");
1748 DllCount
= SetupGetLineCountW(hSysSetupInf
, SectionName
);
1749 DPRINT("SectionName %S DllCount %ld\n", SectionName
, DllCount
);
1752 SetLastError(STATUS_NOT_FOUND
);
1756 *MaxProgress
= (ULONG
) DllCount
;
1759 * Create a background thread to do the actual registrations, so the
1760 * main thread can just run its message loop.
1762 RegistrationThread
= NULL
;
1763 RegistrationData
= HeapAlloc(GetProcessHeap(), 0,
1764 sizeof(REGISTRATIONDATA
));
1765 if (NULL
!= RegistrationData
)
1767 RegistrationData
->hwndDlg
= hwndDlg
;
1768 RegistrationData
->DllCount
= DllCount
;
1769 RegistrationThread
= CreateThread(NULL
, 0, RegistrationProc
,
1770 (LPVOID
) RegistrationData
, 0, NULL
);
1771 if (NULL
!= RegistrationThread
)
1773 CloseHandle(RegistrationThread
);
1777 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1783 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1791 static INT_PTR CALLBACK
1792 ProcessPageDlgProc(HWND hwndDlg
,
1797 PSETUPDATA SetupData
;
1798 PREGISTRATIONNOTIFY RegistrationNotify
;
1799 static UINT oldActivityID
= -1;
1802 /* Retrieve pointer to the global setup data */
1803 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1809 /* Save pointer to the global setup data */
1810 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1811 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1817 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1818 ULONG MaxProgress
= 0;
1823 /* Disable the Back and Next buttons */
1824 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
1826 StartComponentRegistration(hwndDlg
, &MaxProgress
);
1828 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
,
1829 0, MAKELPARAM(0, MaxProgress
));
1830 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1838 SetupData
->UnattendSetup
= FALSE
;
1847 case PM_REGISTRATION_NOTIFY
:
1850 RegistrationNotify
= (PREGISTRATIONNOTIFY
) lParam
;
1851 // update if necessary only
1852 if (oldActivityID
!= RegistrationNotify
->ActivityID
)
1854 if (0 != LoadStringW(hDllInstance
, RegistrationNotify
->ActivityID
,
1856 sizeof(Activity
) / sizeof(Activity
[0])))
1858 SendDlgItemMessageW(hwndDlg
, IDC_ACTIVITY
, WM_SETTEXT
,
1859 0, (LPARAM
) Activity
);
1861 oldActivityID
= RegistrationNotify
->ActivityID
;
1863 SendDlgItemMessageW(hwndDlg
, IDC_ITEM
, WM_SETTEXT
, 0,
1864 (LPARAM
)(NULL
== RegistrationNotify
->CurrentItem
?
1865 L
"" : RegistrationNotify
->CurrentItem
));
1866 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1867 RegistrationNotify
->Progress
, 0);
1868 if (NULL
!= RegistrationNotify
->ErrorMessage
)
1870 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
,
1871 Title
, sizeof(Title
) / sizeof(Title
[0])))
1873 wcscpy(Title
, L
"ReactOS Setup");
1875 MessageBoxW(hwndDlg
, RegistrationNotify
->ErrorMessage
,
1876 Title
, MB_ICONERROR
| MB_OK
);
1883 if(!SetupData
->UnattendSetup
&& !SetupData
->DisableVmwInst
)
1884 RunVMWInstall(GetParent(hwndDlg
));
1887 /* Enable the Back and Next buttons */
1888 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
1889 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
1903 SetInstallationCompleted(VOID
)
1906 DWORD InProgress
= 0;
1909 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1913 &hKey
) == ERROR_SUCCESS
)
1915 RegSetValueExW( hKey
, L
"SystemSetupInProgress", 0, REG_DWORD
, (LPBYTE
)&InProgress
, sizeof(InProgress
) );
1916 RegCloseKey( hKey
);
1919 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1920 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
1923 &hKey
) == ERROR_SUCCESS
)
1925 InstallDate
= (DWORD
)time(NULL
);
1926 RegSetValueExW( hKey
, L
"InstallDate", 0, REG_DWORD
, (LPBYTE
)&InstallDate
, sizeof(InstallDate
) );
1927 RegCloseKey( hKey
);
1932 static INT_PTR CALLBACK
1933 FinishDlgProc(HWND hwndDlg
,
1943 PSETUPDATA SetupData
;
1945 /* Get pointer to the global setup data */
1946 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1948 /* Set title font */
1949 SendDlgItemMessage(hwndDlg
,
1952 (WPARAM
)SetupData
->hTitleFont
,
1954 if (SetupData
->UnattendSetup
)
1956 KillTimer(hwndDlg
, 1);
1957 SetInstallationCompleted();
1965 SetInstallationCompleted();
1975 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
1976 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
1977 if (Position
== 300)
1979 KillTimer(hwndDlg
, 1);
1980 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
1984 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
1991 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1996 /* Enable the correct buttons on for the active page */
1997 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
1999 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
2000 MAKELPARAM(0, 300));
2001 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETPOS
, 0, 0);
2002 SetTimer(hwndDlg
, 1, 50, NULL
);
2006 DestroyWindow(GetParent(hwndDlg
));
2022 ProcessUnattendInf(HINF hUnattendedInf
)
2024 INFCONTEXT InfContext
;
2026 WCHAR szValue
[MAX_PATH
];
2030 if (!SetupFindFirstLineW(hUnattendedInf
,
2032 L
"UnattendSetupEnabled",
2035 DPRINT1("Error: Cant find UnattendSetupEnabled Key! %d\n", GetLastError());
2039 if (!SetupGetStringFieldW(&InfContext
,
2042 sizeof(szValue
) / sizeof(WCHAR
),
2045 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2049 if (wcscmp(szValue
, L
"yes") != 0)
2051 DPRINT("Unattend setup was disabled by UnattendSetupEnabled key.\n");
2055 if (!SetupFindFirstLineW(hUnattendedInf
,
2060 DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError());
2067 if (!SetupGetStringFieldW(&InfContext
,
2070 sizeof(szName
) / sizeof(WCHAR
),
2073 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2077 if (!SetupGetStringFieldW(&InfContext
,
2080 sizeof(szValue
) / sizeof(WCHAR
),
2083 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2086 DPRINT1("Name %S Value %S\n",szName
, szValue
);
2087 if (!wcscmp(szName
, L
"FullName"))
2089 if ((sizeof(SetupData
.OwnerName
) / sizeof(TCHAR
)) > LineLength
)
2091 wcscpy(SetupData
.OwnerName
, szValue
);
2094 else if (!wcscmp(szName
, L
"OrgName"))
2096 if ((sizeof(SetupData
.OwnerOrganization
) / sizeof(WCHAR
)) > LineLength
)
2098 wcscpy(SetupData
.OwnerOrganization
, szValue
);
2101 else if (!wcscmp(szName
, L
"ComputerName"))
2103 if ((sizeof(SetupData
.ComputerName
) / sizeof(WCHAR
)) > LineLength
)
2105 wcscpy(SetupData
.ComputerName
, szValue
);
2108 else if (!wcscmp(szName
, L
"AdminPassword"))
2110 if ((sizeof(SetupData
.AdminPassword
) / sizeof(WCHAR
)) > LineLength
)
2112 wcscpy(SetupData
.AdminPassword
, szValue
);
2115 else if (!wcscmp(szName
, L
"TimeZoneIndex"))
2117 SetupData
.TimeZoneIndex
= _wtoi(szValue
);
2119 else if (!wcscmp(szName
, L
"DisableAutoDaylightTimeSet"))
2121 SetupData
.DisableAutoDaylightTimeSet
= _wtoi(szValue
);
2123 else if (!wcscmp(szName
, L
"DisableVmwInst"))
2125 if(!wcscmp(szValue
, L
"yes"))
2126 SetupData
.DisableVmwInst
= 1;
2128 SetupData
.DisableVmwInst
= 0;
2132 while (SetupFindNextLine(&InfContext
, &InfContext
));
2134 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
2135 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
2138 &hKey
) != ERROR_SUCCESS
)
2140 DPRINT1("Error: failed to open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\n");
2145 if (SetupFindFirstLineW(hUnattendedInf
,
2154 if(SetupGetStringFieldW(&InfContext
,
2157 sizeof(szValue
) / sizeof(WCHAR
),
2160 WCHAR szPath
[MAX_PATH
];
2161 swprintf(szName
, L
"%d", i
);
2162 DPRINT("szName %S szValue %S\n", szName
, szValue
);
2164 if (ExpandEnvironmentStringsW(szValue
, szPath
, MAX_PATH
))
2166 DPRINT("value %S\n", szPath
);
2167 if (RegSetValueExW(hKey
,
2171 (const BYTE
*)szPath
,
2172 (wcslen(szPath
)+1) * sizeof(WCHAR
)) == ERROR_SUCCESS
)
2178 }while(SetupFindNextLine(&InfContext
, &InfContext
));
2186 * GetRosInstallCD should find the path to ros installation medium
2188 * If there are more than one CDDrive in it containing a ReactOS
2189 * installation cd, then it will pick the first one regardless if
2190 * it is really the installation cd
2192 * The best way to implement this is to set the key
2193 * HKLM\Software\Microsoft\Windows NT\CurrentVersion\SourcePath (REG_SZ)
2197 GetRosInstallCD(WCHAR
* szPath
, DWORD dwPathLength
)
2199 WCHAR szDrives
[512];
2200 WCHAR szDrive
[] = L
"D:\\";
2201 DWORD dwLength
, dwIndex
;
2203 dwLength
= GetLogicalDriveStringsW(sizeof(szDrives
) / sizeof(WCHAR
), szDrives
);
2205 if (dwLength
> (sizeof(szDrives
) / sizeof(WCHAR
)) || dwLength
== 0)
2207 /* buffer too small or failure */
2208 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"GetLogicalDriveStringsW failed");
2213 for (dwIndex
= 0; dwIndex
< dwLength
; dwIndex
++)
2215 szDrive
[0] = pDrive
[dwIndex
];
2216 if (GetDriveTypeW(szDrive
) == DRIVE_CDROM
)
2218 WCHAR szBuffer
[MAX_PATH
];
2219 wcscpy(szBuffer
, szDrive
);
2220 wcscat(szBuffer
, L
"reactos\\system32\\ntoskrnl.exe");
2221 LogItem(SYSSETUP_SEVERITY_INFORMATION
, szBuffer
);
2222 if (FileExists(szBuffer
, NULL
))
2224 wcsncpy(szPath
, szDrive
, dwPathLength
);
2233 ProcessUnattendSetup()
2235 WCHAR szPath
[MAX_PATH
];
2236 HINF hUnattendedInf
;
2239 if (!GetRosInstallCD(szPath
, MAX_PATH
))
2241 /* no cd drive found */
2245 dwLength
= wcslen(szPath
);
2246 if (dwLength
+ 21 > MAX_PATH
)
2249 * allocate bigger buffer
2254 wcscat(szPath
, L
"reactos\\unattend.inf");
2256 hUnattendedInf
= SetupOpenInfFileW(szPath
,
2261 if (hUnattendedInf
!= INVALID_HANDLE_VALUE
)
2263 SetupData
.UnattendSetup
= ProcessUnattendInf(hUnattendedInf
);
2264 SetupCloseInfFile(hUnattendedInf
);
2272 PROPSHEETHEADER psh
;
2273 HPROPSHEETPAGE ahpsp
[8];
2274 PROPSHEETPAGE psp
= {0};
2279 /* Clear setup data */
2280 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
2282 ProcessUnattendSetup();
2285 /* Create the Welcome page */
2286 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
2287 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2288 psp
.hInstance
= hDllInstance
;
2289 psp
.lParam
= (LPARAM
)&SetupData
;
2290 psp
.pfnDlgProc
= WelcomeDlgProc
;
2291 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
2292 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2294 /* Create the Acknowledgements page */
2295 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2296 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_ACKTITLE
);
2297 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_ACKSUBTITLE
);
2298 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_ACKPAGE
);
2299 psp
.pfnDlgProc
= AckPageDlgProc
;
2300 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2302 /* Create the Owner page */
2303 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2304 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_OWNERTITLE
);
2305 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_OWNERSUBTITLE
);
2306 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_OWNERPAGE
);
2307 psp
.pfnDlgProc
= OwnerPageDlgProc
;
2308 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2310 /* Create the Computer page */
2311 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2312 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_COMPUTERTITLE
);
2313 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE
);
2314 psp
.pfnDlgProc
= ComputerPageDlgProc
;
2315 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_COMPUTERPAGE
);
2316 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2319 /* Create the Locale page */
2320 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2321 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LOCALETITLE
);
2322 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LOCALESUBTITLE
);
2323 psp
.pfnDlgProc
= LocalePageDlgProc
;
2324 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
2325 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2328 /* Create the DateTime page */
2329 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2330 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DATETIMETITLE
);
2331 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DATETIMESUBTITLE
);
2332 psp
.pfnDlgProc
= DateTimePageDlgProc
;
2333 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DATETIMEPAGE
);
2334 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2337 /* Create the Process page */
2338 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2339 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
2340 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
2341 psp
.pfnDlgProc
= ProcessPageDlgProc
;
2342 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
2343 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2346 /* Create the Finish page */
2347 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2348 psp
.pfnDlgProc
= FinishDlgProc
;
2349 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
2350 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2352 /* Create the property sheet */
2353 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2354 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
| PSH_MODELESS
;
2355 psh
.hInstance
= hDllInstance
;
2356 psh
.hwndParent
= NULL
;
2357 psh
.nPages
= nPages
;
2360 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
2361 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
2363 /* Create title font */
2364 SetupData
.hTitleFont
= CreateTitleFont();
2366 /* Display the wizard */
2367 hWnd
= (HWND
)PropertySheet(&psh
);
2368 ShowWindow(hWnd
, SW_SHOW
);
2370 while (GetMessage(&msg
, NULL
, 0, 0))
2372 if(!IsDialogMessage(hWnd
, &msg
))
2374 TranslateMessage(&msg
);
2375 DispatchMessage(&msg
);
2379 DeleteObject(SetupData
.hTitleFont
);