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
;
59 WCHAR InstallName
[] = L
"vmwinst.exe";
61 ZeroMemory(&si
, sizeof(si
));
64 if(CreateProcessW(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
65 NULL
, NULL
, &si
, &ProcInfo
))
67 EnableWindow(hWnd
, FALSE
);
70 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
72 if (msg
.message
== WM_QUIT
)
74 TranslateMessage(&msg
);
75 DispatchMessage(&msg
);
78 ret
= MsgWaitForMultipleObjects(1, &ProcInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
| QS_ALLINPUT
);
79 if (ret
== WAIT_OBJECT_0
)
83 EnableWindow(hWnd
, TRUE
);
85 CloseHandle(ProcInfo
.hThread
);
86 CloseHandle(ProcInfo
.hProcess
);
94 CenterWindow(HWND hWnd
)
100 hWndParent
= GetParent(hWnd
);
101 if (hWndParent
== NULL
)
102 hWndParent
= GetDesktopWindow();
104 GetWindowRect(hWndParent
, &rcParent
);
105 GetWindowRect(hWnd
, &rcWindow
);
109 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
110 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
118 CreateTitleFont(VOID
)
120 NONCLIENTMETRICSW ncm
;
126 ncm
.cbSize
= sizeof(NONCLIENTMETRICSW
);
127 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
129 LogFont
= ncm
.lfMessageFont
;
130 LogFont
.lfWeight
= FW_BOLD
;
131 wcscpy(LogFont
.lfFaceName
, L
"MS Shell Dlg");
135 LogFont
.lfHeight
= 0 - GetDeviceCaps(hdc
, LOGPIXELSY
) * FontSize
/ 72;
136 hFont
= CreateFontIndirectW(&LogFont
);
137 ReleaseDC(NULL
, hdc
);
143 static INT_PTR CALLBACK
144 GplDlgProc(HWND hwndDlg
,
149 HRSRC GplTextResource
;
159 GplTextResource
= FindResourceW(hDllInstance
, MAKEINTRESOURCE(IDR_GPL
), L
"RT_TEXT");
160 if (NULL
== GplTextResource
)
164 Size
= SizeofResource(hDllInstance
, GplTextResource
);
169 GplText
= HeapAlloc(GetProcessHeap(), 0, Size
+ 1);
174 GplTextMem
= LoadResource(hDllInstance
, GplTextResource
);
175 if (NULL
== GplTextMem
)
177 HeapFree(GetProcessHeap(), 0, GplText
);
180 GplTextLocked
= LockResource(GplTextMem
);
181 if (NULL
== GplTextLocked
)
183 HeapFree(GetProcessHeap(), 0, GplText
);
186 memcpy(GplText
, GplTextLocked
, Size
);
187 GplText
[Size
] = '\0';
188 SendMessageA(GetDlgItem(hwndDlg
, IDC_GPL_TEXT
), WM_SETTEXT
, 0, (LPARAM
) GplText
);
189 HeapFree(GetProcessHeap(), 0, GplText
);
190 SetFocus(GetDlgItem(hwndDlg
, IDOK
));
194 EndDialog(hwndDlg
, IDCANCEL
);
198 if (HIWORD(wParam
) == BN_CLICKED
&& IDOK
== LOWORD(wParam
))
200 EndDialog(hwndDlg
, IDOK
);
212 static INT_PTR CALLBACK
213 WelcomeDlgProc(HWND hwndDlg
,
222 PSETUPDATA SetupData
;
226 /* Get pointer to the global setup data */
227 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
229 hwndControl
= GetParent(hwndDlg
);
231 /* Center the wizard window */
232 CenterWindow (hwndControl
);
234 /* Hide the system menu */
235 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
236 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
238 /* Hide and disable the 'Cancel' button */
239 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
240 ShowWindow (hwndControl
, SW_HIDE
);
241 EnableWindow (hwndControl
, FALSE
);
244 SendDlgItemMessage(hwndDlg
,
247 (WPARAM
)SetupData
->hTitleFont
,
255 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
260 /* Enable the Next button */
261 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
262 if (SetupData
.UnattendSetup
)
264 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_ACKPAGE
);
270 SetupData
.UnattendSetup
= FALSE
;
287 static INT_PTR CALLBACK
288 AckPageDlgProc(HWND hwndDlg
,
295 PWCHAR End
, CurrentProject
;
296 INT ProjectsSize
, ProjectsCount
;
306 Projects
= HeapAlloc(GetProcessHeap(), 0, ProjectsSize
* sizeof(WCHAR
));
307 if (NULL
== Projects
)
311 ProjectsCount
= LoadStringW(hDllInstance
, IDS_ACKPROJECTS
, Projects
, ProjectsSize
);
312 if (0 == ProjectsCount
)
314 HeapFree(GetProcessHeap(), 0, Projects
);
317 if (ProjectsCount
< ProjectsSize
- 1)
321 HeapFree(GetProcessHeap(), 0, Projects
);
325 CurrentProject
= Projects
;
326 while (L
'\0' != *CurrentProject
)
328 End
= wcschr(CurrentProject
, L
'\n');
333 (void)ListBox_AddString(GetDlgItem(hwndDlg
, IDC_PROJECTS
), CurrentProject
);
336 CurrentProject
= End
+ 1;
340 CurrentProject
+= wcslen(CurrentProject
);
343 HeapFree(GetProcessHeap(), 0, Projects
);
348 if (HIWORD(wParam
) == BN_CLICKED
&& IDC_VIEWGPL
== LOWORD(wParam
))
350 DialogBox(hDllInstance
, MAKEINTRESOURCE(IDD_GPL
), NULL
, GplDlgProc
);
351 SetForegroundWindow(GetParent(hwndDlg
));
357 lpnm
= (LPNMHDR
)lParam
;
362 /* Enable the Back and Next buttons */
363 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
364 if (SetupData
.UnattendSetup
)
366 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_OWNERPAGE
);
372 SetupData
.UnattendSetup
= FALSE
;
390 WriteOwnerSettings(WCHAR
* OwnerName
,
391 WCHAR
* OwnerOrganization
)
398 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
399 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
404 if (res
!= ERROR_SUCCESS
)
409 res
= RegSetValueExW(hKey
,
414 (wcslen(OwnerName
) + 1) * sizeof(WCHAR
));
416 if (res
!= ERROR_SUCCESS
)
422 res
= RegSetValueExW(hKey
,
423 L
"RegisteredOrganization",
426 (LPBYTE
)OwnerOrganization
,
427 (wcslen(OwnerOrganization
) + 1) * sizeof(WCHAR
));
430 return (res
== ERROR_SUCCESS
);
433 static INT_PTR CALLBACK
434 OwnerPageDlgProc(HWND hwndDlg
,
440 WCHAR OwnerOrganization
[51];
442 WCHAR ErrorName
[256];
449 SendDlgItemMessage(hwndDlg
, IDC_OWNERNAME
, EM_LIMITTEXT
, 50, 0);
450 SendDlgItemMessage(hwndDlg
, IDC_OWNERORGANIZATION
, EM_LIMITTEXT
, 50, 0);
452 /* Set focus to owner name */
453 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
460 lpnm
= (LPNMHDR
)lParam
;
465 /* Enable the Back and Next buttons */
466 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
467 if (SetupData
.UnattendSetup
)
469 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerName
);
470 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERORGANIZATION
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerOrganization
);
471 if (WriteOwnerSettings(SetupData
.OwnerName
, SetupData
.OwnerOrganization
))
473 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_COMPUTERPAGE
);
481 if (GetDlgItemTextW(hwndDlg
, IDC_OWNERNAME
, OwnerName
, 50) == 0)
483 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
485 wcscpy(Title
, L
"ReactOS Setup");
487 if (0 == LoadStringW(hDllInstance
, IDS_WZD_NAME
, ErrorName
, sizeof(ErrorName
) / sizeof(ErrorName
[0])))
489 wcscpy(ErrorName
, L
"Setup cannot continue until you enter your name.");
491 MessageBoxW(hwndDlg
, ErrorName
, Title
, MB_ICONERROR
| MB_OK
);
493 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
494 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
499 OwnerOrganization
[0] = 0;
500 GetDlgItemTextW(hwndDlg
, IDC_OWNERORGANIZATION
, OwnerOrganization
, 50);
502 if (!WriteOwnerSettings(OwnerName
, OwnerOrganization
))
504 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
505 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
510 SetupData
.UnattendSetup
= FALSE
;
528 WriteComputerSettings(WCHAR
* ComputerName
, HWND hwndDlg
)
531 WCHAR ErrorComputerName
[256];
532 if (!SetComputerNameW(ComputerName
))
534 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
536 wcscpy(Title
, L
"ReactOS Setup");
538 if (0 == LoadStringW(hDllInstance
, IDS_WZD_SETCOMPUTERNAME
, ErrorComputerName
,
539 sizeof(ErrorComputerName
) / sizeof(ErrorComputerName
[0])))
541 wcscpy(ErrorComputerName
, L
"Setup failed to set the computer name.");
543 MessageBoxW(hwndDlg
, ErrorComputerName
, Title
, MB_ICONERROR
| MB_OK
);
548 /* Try to also set DNS hostname */
549 SetComputerNameExW(ComputerNamePhysicalDnsHostname
, ComputerName
);
551 /* Set the account domain name */
552 SetAccountDomain(ComputerName
, NULL
);
557 /* lpBuffer will be filled with a 15-char string (plus the null terminator) */
559 GenerateComputerName(LPWSTR lpBuffer
)
561 static const WCHAR Chars
[] = L
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
562 static const unsigned cChars
= sizeof(Chars
) / sizeof(WCHAR
) - 1;
565 wcscpy(lpBuffer
, L
"REACTOS-");
567 srand(GetTickCount());
569 /* fill in 7 characters */
570 for (i
= 8; i
< 15; i
++)
571 lpBuffer
[i
] = Chars
[rand() % cChars
];
573 lpBuffer
[15] = UNICODE_NULL
; /* NULL-terminate */
576 static INT_PTR CALLBACK
577 ComputerPageDlgProc(HWND hwndDlg
,
582 WCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
587 WCHAR EmptyComputerName
[256], NotMatchPassword
[256], WrongPassword
[256];
590 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
592 wcscpy(Title
, L
"ReactOS Setup");
599 /* Generate a new pseudo-random computer name */
600 GenerateComputerName(ComputerName
);
602 /* Display current computer name */
603 SetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
605 /* Set text limits */
606 SendDlgItemMessage(hwndDlg
, IDC_COMPUTERNAME
, EM_LIMITTEXT
, MAX_COMPUTERNAME_LENGTH
, 0);
607 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD1
, EM_LIMITTEXT
, 14, 0);
608 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD2
, EM_LIMITTEXT
, 14, 0);
610 /* Set focus to computer name */
611 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
612 if (SetupData
.UnattendSetup
)
614 SendMessage(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.ComputerName
);
615 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD1
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
616 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD2
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
625 lpnm
= (LPNMHDR
)lParam
;
630 /* Enable the Back and Next buttons */
631 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
632 if (SetupData
.UnattendSetup
&& WriteComputerSettings(SetupData
.ComputerName
, hwndDlg
))
634 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_LOCALEPAGE
);
640 if (0 == GetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, MAX_COMPUTERNAME_LENGTH
+ 1))
642 if (0 == LoadStringW(hDllInstance
, IDS_WZD_COMPUTERNAME
, EmptyComputerName
,
643 sizeof(EmptyComputerName
) / sizeof(EmptyComputerName
[0])))
645 wcscpy(EmptyComputerName
, L
"Setup cannot continue until you enter the name of your computer.");
647 MessageBoxW(hwndDlg
, EmptyComputerName
, Title
, MB_ICONERROR
| MB_OK
);
648 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
649 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
653 /* No need to check computer name for invalid characters,
654 * SetComputerName() will do it for us */
656 if (!WriteComputerSettings(ComputerName
, hwndDlg
))
658 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
659 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
664 /* Check if admin passwords have been entered */
665 if ((GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15) == 0) ||
666 (GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15) == 0))
668 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDEMPTY
, EmptyPassword
,
669 sizeof(EmptyPassword
) / sizeof(EmptyPassword
[0])))
671 wcscpy(EmptyPassword
, L
"You must enter a password !");
673 MessageBoxW(hwndDlg
, EmptyPassword
, Title
, MB_ICONERROR
| MB_OK
);
674 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
678 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15);
679 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15);
681 /* Check if passwords match */
682 if (wcscmp(Password1
, Password2
))
684 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDMATCH
, NotMatchPassword
,
685 sizeof(NotMatchPassword
) / sizeof(NotMatchPassword
[0])))
687 wcscpy(NotMatchPassword
, L
"The passwords you entered do not match. Please enter the desired password again.");
689 MessageBoxW(hwndDlg
, NotMatchPassword
, Title
, MB_ICONERROR
| MB_OK
);
690 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
694 /* Check password for invalid characters */
695 Password
= (PWCHAR
)Password1
;
698 if (!isprint(*Password
))
700 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDCHAR
, WrongPassword
,
701 sizeof(WrongPassword
) / sizeof(WrongPassword
[0])))
703 wcscpy(WrongPassword
, L
"The password you entered contains invalid characters. Please enter a cleaned password.");
705 MessageBoxW(hwndDlg
, WrongPassword
, Title
, MB_ICONERROR
| MB_OK
);
706 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
712 /* FIXME: Set admin password */
716 SetupData
.UnattendSetup
= FALSE
;
734 SetKeyboardLayoutName(HWND hwnd
)
737 TCHAR szLayoutPath
[256];
738 TCHAR szLocaleName
[32];
742 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
743 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
749 dwValueSize
= 16 * sizeof(TCHAR
);
750 if (RegQueryValueEx(hKey
,
761 _tcscpy(szLayoutPath
,
762 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"));
763 _tcscat(szLayoutPath
,
766 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
773 dwValueSize
= 32 * sizeof(TCHAR
);
774 if (RegQueryValueEx(hKey
,
791 RunControlPanelApplet(HWND hwnd
, PCWSTR pwszCPLParameters
)
793 if (pwszCPLParameters
)
795 STARTUPINFOW StartupInfo
;
796 PROCESS_INFORMATION ProcessInformation
;
797 WCHAR CmdLine
[MAX_PATH
] = L
"rundll32.exe shell32.dll,Control_RunDLL ";
799 ZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
800 StartupInfo
.cb
= sizeof(StartupInfo
);
802 ASSERT(_countof(CmdLine
) > wcslen(CmdLine
) + wcslen(pwszCPLParameters
));
803 wcscat(CmdLine
, pwszCPLParameters
);
805 if (!CreateProcessW(NULL
,
814 &ProcessInformation
))
816 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
820 WaitForSingleObject(ProcessInformation
.hProcess
, INFINITE
);
821 CloseHandle(ProcessInformation
.hThread
);
822 CloseHandle(ProcessInformation
.hProcess
);
827 MessageBoxW(hwnd
, L
"Error: Failed to launch the Control Panel Applet.", NULL
, MB_ICONERROR
);
833 WriteUserLocale(VOID
)
839 lcid
= GetSystemDefaultLCID();
841 if (GetLocaleInfoW(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_ILANGUAGE
, Locale
, sizeof(Locale
) / sizeof(Locale
[0])) != 0)
843 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Control Panel\\International",
844 0, NULL
, REG_OPTION_NON_VOLATILE
,
845 KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
847 RegSetValueExW(hKey
, L
"Locale", 0, REG_SZ
, (LPBYTE
)Locale
, (wcslen(Locale
) + 1) * sizeof(WCHAR
));
853 static INT_PTR CALLBACK
854 LocalePageDlgProc(HWND hwndDlg
,
859 PSETUPDATA SetupData
;
861 /* Retrieve pointer to the global setup data */
862 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
868 /* Save pointer to the global setup data */
869 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
870 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
873 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
878 if (HIWORD(wParam
) == BN_CLICKED
)
880 switch (LOWORD(wParam
))
882 case IDC_CUSTOMLOCALE
:
883 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,5");
884 /* FIXME: Update input locale name */
887 case IDC_CUSTOMLAYOUT
:
888 RunControlPanelApplet(hwndDlg
, L
"input.dll,@1");
896 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
901 /* Enable the Back and Next buttons */
902 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
903 if (SetupData
->UnattendSetup
)
905 WCHAR wszPath
[MAX_PATH
];
906 if (GetRosInstallCD(wszPath
, _countof(wszPath
)))
908 WCHAR wszParams
[1024];
909 swprintf(wszParams
, L
"intl.cpl,,/f:\"%sreactos\\unattend.inf\"", wszPath
);
910 RunControlPanelApplet(hwndDlg
, wszParams
);
914 RunControlPanelApplet(hwndDlg
, L
"intl.cpl,,/f:\"unattend.inf\"");
917 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_DATETIMEPAGE
);
926 SetupData
->UnattendSetup
= FALSE
;
943 static PTIMEZONE_ENTRY
944 GetLargerTimeZoneEntry(PSETUPDATA SetupData
, DWORD Index
)
946 PTIMEZONE_ENTRY Entry
;
948 Entry
= SetupData
->TimeZoneListHead
;
949 while (Entry
!= NULL
)
951 if (Entry
->Index
>= Index
)
962 CreateTimeZoneList(PSETUPDATA SetupData
)
964 WCHAR szKeyName
[256];
972 PTIMEZONE_ENTRY Entry
;
973 PTIMEZONE_ENTRY Current
;
975 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
976 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
985 dwNameSize
= 256 * sizeof(WCHAR
);
986 lError
= RegEnumKeyExW(hZonesKey
,
994 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
997 if (RegOpenKeyExW(hZonesKey
,
1004 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
1007 RegCloseKey(hZoneKey
);
1011 dwValueSize
= 64 * sizeof(WCHAR
);
1012 if (RegQueryValueExW(hZoneKey
,
1016 (LPBYTE
)&Entry
->Description
,
1019 RegCloseKey(hZoneKey
);
1023 dwValueSize
= 32 * sizeof(WCHAR
);
1024 if (RegQueryValueExW(hZoneKey
,
1028 (LPBYTE
)&Entry
->StandardName
,
1031 RegCloseKey(hZoneKey
);
1035 dwValueSize
= 32 * sizeof(WCHAR
);
1036 if (RegQueryValueExW(hZoneKey
,
1040 (LPBYTE
)&Entry
->DaylightName
,
1043 RegCloseKey(hZoneKey
);
1047 dwValueSize
= sizeof(DWORD
);
1048 if (RegQueryValueExW(hZoneKey
,
1052 (LPBYTE
)&Entry
->Index
,
1055 RegCloseKey(hZoneKey
);
1059 dwValueSize
= sizeof(TZ_INFO
);
1060 if (RegQueryValueExW(hZoneKey
,
1064 (LPBYTE
)&Entry
->TimezoneInfo
,
1067 RegCloseKey(hZoneKey
);
1071 RegCloseKey(hZoneKey
);
1073 if (SetupData
->TimeZoneListHead
== NULL
&&
1074 SetupData
->TimeZoneListTail
== NULL
)
1078 SetupData
->TimeZoneListHead
= Entry
;
1079 SetupData
->TimeZoneListTail
= Entry
;
1083 Current
= GetLargerTimeZoneEntry(SetupData
, Entry
->Index
);
1084 if (Current
!= NULL
)
1086 if (Current
== SetupData
->TimeZoneListHead
)
1088 /* Prepend to head */
1090 Entry
->Next
= SetupData
->TimeZoneListHead
;
1091 SetupData
->TimeZoneListHead
->Prev
= Entry
;
1092 SetupData
->TimeZoneListHead
= Entry
;
1096 /* Insert before current */
1097 Entry
->Prev
= Current
->Prev
;
1098 Entry
->Next
= Current
;
1099 Current
->Prev
->Next
= Entry
;
1100 Current
->Prev
= Entry
;
1105 /* Append to tail */
1106 Entry
->Prev
= SetupData
->TimeZoneListTail
;
1108 SetupData
->TimeZoneListTail
->Next
= Entry
;
1109 SetupData
->TimeZoneListTail
= Entry
;
1116 RegCloseKey(hZonesKey
);
1121 DestroyTimeZoneList(PSETUPDATA SetupData
)
1123 PTIMEZONE_ENTRY Entry
;
1125 while (SetupData
->TimeZoneListHead
!= NULL
)
1127 Entry
= SetupData
->TimeZoneListHead
;
1129 SetupData
->TimeZoneListHead
= Entry
->Next
;
1130 if (SetupData
->TimeZoneListHead
!= NULL
)
1132 SetupData
->TimeZoneListHead
->Prev
= NULL
;
1135 HeapFree(GetProcessHeap(), 0, Entry
);
1138 SetupData
->TimeZoneListTail
= NULL
;
1142 GetTimeZoneListIndex(LPDWORD lpIndex
)
1144 WCHAR szLanguageIdString
[9];
1151 BOOL bFound
= FALSE
;
1152 unsigned long iLanguageID
;
1154 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1155 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
1161 dwValueSize
= 9 * sizeof(WCHAR
);
1162 if (RegQueryValueExW(hKey
,
1166 (LPBYTE
)szLanguageIdString
,
1173 iLanguageID
= wcstoul(szLanguageIdString
, NULL
, 16);
1176 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1177 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1184 if (RegQueryValueExW(hKey
,
1195 Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
1202 if (RegQueryValueExW(hKey
,
1209 HeapFree(GetProcessHeap(), 0, Buffer
);
1219 Length
= wcslen(Ptr
);
1220 if (wcstoul(Ptr
, NULL
, 16) == iLanguageID
)
1223 Ptr
= Ptr
+ Length
+ 1;
1229 *lpIndex
= wcstoul(Ptr
, &End
, 10);
1230 HeapFree(GetProcessHeap(), 0, Buffer
);
1234 Length
= wcslen(Ptr
);
1235 Ptr
= Ptr
+ Length
+ 1;
1238 HeapFree(GetProcessHeap(), 0, Buffer
);
1245 ShowTimeZoneList(HWND hwnd
, PSETUPDATA SetupData
, DWORD dwEntryIndex
)
1247 PTIMEZONE_ENTRY Entry
;
1251 GetTimeZoneListIndex(&dwEntryIndex
);
1253 Entry
= SetupData
->TimeZoneListHead
;
1254 while (Entry
!= NULL
)
1256 dwCount
= SendMessage(hwnd
,
1259 (LPARAM
)Entry
->Description
);
1261 if (dwEntryIndex
!= 0 && dwEntryIndex
== Entry
->Index
)
1264 Entry
= Entry
->Next
;
1275 SetLocalTimeZone(HWND hwnd
, PSETUPDATA SetupData
)
1277 TIME_ZONE_INFORMATION TimeZoneInformation
;
1278 PTIMEZONE_ENTRY Entry
;
1282 dwIndex
= SendMessage(hwnd
,
1288 Entry
= SetupData
->TimeZoneListHead
;
1295 Entry
= Entry
->Next
;
1298 wcscpy(TimeZoneInformation
.StandardName
,
1299 Entry
->StandardName
);
1300 wcscpy(TimeZoneInformation
.DaylightName
,
1301 Entry
->DaylightName
);
1303 TimeZoneInformation
.Bias
= Entry
->TimezoneInfo
.Bias
;
1304 TimeZoneInformation
.StandardBias
= Entry
->TimezoneInfo
.StandardBias
;
1305 TimeZoneInformation
.DaylightBias
= Entry
->TimezoneInfo
.DaylightBias
;
1307 memcpy(&TimeZoneInformation
.StandardDate
,
1308 &Entry
->TimezoneInfo
.StandardDate
,
1309 sizeof(SYSTEMTIME
));
1310 memcpy(&TimeZoneInformation
.DaylightDate
,
1311 &Entry
->TimezoneInfo
.DaylightDate
,
1312 sizeof(SYSTEMTIME
));
1314 /* Set time zone information */
1315 SetTimeZoneInformation(&TimeZoneInformation
);
1320 GetLocalSystemTime(HWND hwnd
, PSETUPDATA SetupData
)
1325 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) != GDT_VALID
)
1330 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) != GDT_VALID
)
1335 SetupData
->SystemTime
.wYear
= Date
.wYear
;
1336 SetupData
->SystemTime
.wMonth
= Date
.wMonth
;
1337 SetupData
->SystemTime
.wDayOfWeek
= Date
.wDayOfWeek
;
1338 SetupData
->SystemTime
.wDay
= Date
.wDay
;
1339 SetupData
->SystemTime
.wHour
= Time
.wHour
;
1340 SetupData
->SystemTime
.wMinute
= Time
.wMinute
;
1341 SetupData
->SystemTime
.wSecond
= Time
.wSecond
;
1342 SetupData
->SystemTime
.wMilliseconds
= Time
.wMilliseconds
;
1349 SetAutoDaylightInfo(HWND hwnd
)
1354 if (SendMessage(hwnd
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
)
1356 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1357 L
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
1363 RegSetValueExW(hKey
,
1364 L
"DisableAutoDaylightTimeSet",
1375 SetSystemLocalTime(HWND hwnd
, PSETUPDATA SetupData
)
1379 TOKEN_PRIVILEGES priv
, previouspriv
;
1383 * enable the SeSystemtimePrivilege privilege
1386 if(OpenProcessToken(GetCurrentProcess(),
1387 TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
,
1390 priv
.PrivilegeCount
= 1;
1391 priv
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1393 if(LookupPrivilegeValue(NULL
,
1395 &priv
.Privileges
[0].Luid
))
1397 if(AdjustTokenPrivileges(hToken
,
1400 sizeof(previouspriv
),
1403 GetLastError() == ERROR_SUCCESS
)
1406 * We successfully enabled it, we're permitted to change the system time
1407 * Call SetLocalTime twice to ensure correct results
1409 Ret
= SetLocalTime(&SetupData
->SystemTime
) &&
1410 SetLocalTime(&SetupData
->SystemTime
);
1413 * for the sake of security, restore the previous status again
1415 if(previouspriv
.PrivilegeCount
> 0)
1417 AdjustTokenPrivileges(hToken
,
1426 CloseHandle(hToken
);
1433 WriteDateTimeSettings(HWND hwndDlg
, PSETUPDATA SetupData
)
1436 WCHAR ErrorLocalTime
[256];
1437 GetLocalSystemTime(hwndDlg
, SetupData
);
1438 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1441 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1442 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1444 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
1446 wcscpy(Title
, L
"ReactOS Setup");
1448 if (0 == LoadStringW(hDllInstance
, IDS_WZD_LOCALTIME
, ErrorLocalTime
,
1449 sizeof(ErrorLocalTime
) / sizeof(ErrorLocalTime
[0])))
1451 wcscpy(ErrorLocalTime
, L
"Setup was unable to set the local time.");
1453 MessageBoxW(hwndDlg
, ErrorLocalTime
, Title
, MB_ICONWARNING
| MB_OK
);
1460 static INT_PTR CALLBACK
1461 DateTimePageDlgProc(HWND hwndDlg
,
1466 PSETUPDATA SetupData
;
1468 /* Retrieve pointer to the global setup data */
1469 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1475 /* Save pointer to the global setup data */
1476 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1477 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1479 CreateTimeZoneList(SetupData
);
1481 if (SetupData
->UnattendSetup
)
1483 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1484 SetupData
, SetupData
->TimeZoneIndex
);
1486 if (!SetupData
->DisableAutoDaylightTimeSet
)
1488 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1493 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1494 SetupData
, 85 /* GMT time zone */);
1496 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1505 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1510 /* Enable the Back and Next buttons */
1511 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
1512 if (SetupData
->UnattendSetup
&& WriteDateTimeSettings(hwndDlg
, SetupData
))
1514 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_PROCESSPAGE
);
1521 WriteDateTimeSettings(hwndDlg
, SetupData
);
1526 SetupData
->UnattendSetup
= FALSE
;
1536 DestroyTimeZoneList(SetupData
);
1547 static UINT CALLBACK
1548 RegistrationNotificationProc(PVOID Context
,
1553 PREGISTRATIONDATA RegistrationData
;
1554 REGISTRATIONNOTIFY RegistrationNotify
;
1555 PSP_REGISTER_CONTROL_STATUSW StatusInfo
;
1557 WCHAR ErrorMessage
[128];
1559 RegistrationData
= (PREGISTRATIONDATA
) Context
;
1561 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
||
1562 SPFILENOTIFY_ENDREGISTRATION
== Notification
)
1564 StatusInfo
= (PSP_REGISTER_CONTROL_STATUSW
) Param1
;
1565 RegistrationNotify
.CurrentItem
= wcsrchr(StatusInfo
->FileName
, L
'\\');
1566 if (NULL
== RegistrationNotify
.CurrentItem
)
1568 RegistrationNotify
.CurrentItem
= StatusInfo
->FileName
;
1572 RegistrationNotify
.CurrentItem
++;
1575 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
)
1577 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1578 StatusInfo
->FileName
);
1579 RegistrationNotify
.ErrorMessage
= NULL
;
1580 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1584 DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
1585 StatusInfo
->FileName
);
1586 DPRINT("Win32Error %u FailureCode %u\n", StatusInfo
->Win32Error
,
1587 StatusInfo
->FailureCode
);
1588 if (SPREG_SUCCESS
!= StatusInfo
->FailureCode
)
1590 switch(StatusInfo
->FailureCode
)
1592 case SPREG_LOADLIBRARY
:
1593 MessageID
= IDS_LOADLIBRARY_FAILED
;
1595 case SPREG_GETPROCADDR
:
1596 MessageID
= IDS_GETPROCADDR_FAILED
;
1599 MessageID
= IDS_REGSVR_FAILED
;
1601 case SPREG_DLLINSTALL
:
1602 MessageID
= IDS_DLLINSTALL_FAILED
;
1605 MessageID
= IDS_TIMEOUT
;
1608 MessageID
= IDS_REASON_UNKNOWN
;
1611 if (0 == LoadStringW(hDllInstance
, MessageID
,
1613 sizeof(ErrorMessage
) /
1614 sizeof(ErrorMessage
[0])))
1616 ErrorMessage
[0] = L
'\0';
1618 if (SPREG_TIMEOUT
!= StatusInfo
->FailureCode
)
1620 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
1621 StatusInfo
->Win32Error
, 0,
1622 ErrorMessage
+ wcslen(ErrorMessage
),
1623 sizeof(ErrorMessage
) / sizeof(ErrorMessage
[0]) -
1624 wcslen(ErrorMessage
), NULL
);
1626 RegistrationNotify
.ErrorMessage
= ErrorMessage
;
1630 RegistrationNotify
.ErrorMessage
= NULL
;
1632 if (RegistrationData
->Registered
< RegistrationData
->DllCount
)
1634 RegistrationData
->Registered
++;
1638 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1639 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1640 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1641 0, (LPARAM
) &RegistrationNotify
);
1647 DPRINT1("Received unexpected notification %u\n", Notification
);
1648 return SetupDefaultQueueCallback(RegistrationData
->DefaultContext
,
1649 Notification
, Param1
, Param2
);
1654 static DWORD CALLBACK
1655 RegistrationProc(LPVOID Parameter
)
1657 PREGISTRATIONDATA RegistrationData
;
1658 REGISTRATIONNOTIFY RegistrationNotify
;
1659 DWORD LastError
= NO_ERROR
;
1660 WCHAR UnknownError
[84];
1662 RegistrationData
= (PREGISTRATIONDATA
) Parameter
;
1663 RegistrationData
->Registered
= 0;
1664 RegistrationData
->DefaultContext
= SetupInitDefaultQueueCallback(RegistrationData
->hwndDlg
);
1668 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData
->hwndDlg
),
1670 L
"RegistrationPhase2",
1672 SPINST_REGISTERCALLBACKAWARE
|
1677 RegistrationNotificationProc
,
1682 LastError
= GetLastError();
1685 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1687 DPRINT("Catching exception\n");
1688 LastError
= RtlNtStatusToDosError(_SEH2_GetExceptionCode());
1692 if (NO_ERROR
== LastError
)
1694 RegistrationNotify
.ErrorMessage
= NULL
;
1698 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1700 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1701 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, LastError
, 0,
1702 (LPWSTR
) &RegistrationNotify
.ErrorMessage
, 0,
1705 if (0 == LoadStringW(hDllInstance
, IDS_UNKNOWN_ERROR
,
1707 sizeof(UnknownError
) / sizeof(UnknownError
[0]) -
1710 wcscpy(UnknownError
, L
"Unknown error");
1712 wcscat(UnknownError
, L
" ");
1713 _ultow(LastError
, UnknownError
+ wcslen(UnknownError
), 10);
1714 RegistrationNotify
.ErrorMessage
= UnknownError
;
1718 RegistrationNotify
.Progress
= RegistrationData
->DllCount
;
1719 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1720 RegistrationNotify
.CurrentItem
= NULL
;
1721 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1722 1, (LPARAM
) &RegistrationNotify
);
1723 if (NULL
!= RegistrationNotify
.ErrorMessage
&&
1724 UnknownError
!= RegistrationNotify
.ErrorMessage
)
1726 LocalFree((PVOID
) RegistrationNotify
.ErrorMessage
);
1729 SetupTermDefaultQueueCallback(RegistrationData
->DefaultContext
);
1730 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1732 // FIXME: Move this call to a separate cleanup page!
1733 RtlCreateBootStatusDataFile();
1740 StartComponentRegistration(HWND hwndDlg
, PULONG MaxProgress
)
1742 HANDLE RegistrationThread
;
1745 WCHAR SectionName
[512];
1746 PREGISTRATIONDATA RegistrationData
;
1749 if (! SetupFindFirstLineW(hSysSetupInf
, L
"RegistrationPhase2",
1750 L
"RegisterDlls", &Context
))
1752 DPRINT1("No RegistrationPhase2 section found\n");
1755 if (! SetupGetStringFieldW(&Context
, 1, SectionName
,
1756 sizeof(SectionName
) / sizeof(SectionName
[0]),
1759 DPRINT1("Unable to retrieve section name\n");
1762 DllCount
= SetupGetLineCountW(hSysSetupInf
, SectionName
);
1763 DPRINT("SectionName %S DllCount %ld\n", SectionName
, DllCount
);
1766 SetLastError(STATUS_NOT_FOUND
);
1770 *MaxProgress
= (ULONG
) DllCount
;
1773 * Create a background thread to do the actual registrations, so the
1774 * main thread can just run its message loop.
1776 RegistrationThread
= NULL
;
1777 RegistrationData
= HeapAlloc(GetProcessHeap(), 0,
1778 sizeof(REGISTRATIONDATA
));
1779 if (RegistrationData
!= NULL
)
1781 RegistrationData
->hwndDlg
= hwndDlg
;
1782 RegistrationData
->DllCount
= DllCount
;
1783 RegistrationThread
= CreateThread(NULL
, 0, RegistrationProc
,
1784 (LPVOID
) RegistrationData
, 0, NULL
);
1785 if (RegistrationThread
!= NULL
)
1787 CloseHandle(RegistrationThread
);
1791 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1792 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1798 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1806 static INT_PTR CALLBACK
1807 ProcessPageDlgProc(HWND hwndDlg
,
1812 PSETUPDATA SetupData
;
1813 PREGISTRATIONNOTIFY RegistrationNotify
;
1814 static UINT oldActivityID
= -1;
1817 /* Retrieve pointer to the global setup data */
1818 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1824 /* Save pointer to the global setup data */
1825 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1826 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1832 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1833 ULONG MaxProgress
= 0;
1838 /* Disable the Back and Next buttons */
1839 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
1841 StartComponentRegistration(hwndDlg
, &MaxProgress
);
1843 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
,
1844 0, MAKELPARAM(0, MaxProgress
));
1845 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1853 SetupData
->UnattendSetup
= FALSE
;
1862 case PM_REGISTRATION_NOTIFY
:
1865 RegistrationNotify
= (PREGISTRATIONNOTIFY
) lParam
;
1866 // update if necessary only
1867 if (oldActivityID
!= RegistrationNotify
->ActivityID
)
1869 if (0 != LoadStringW(hDllInstance
, RegistrationNotify
->ActivityID
,
1871 sizeof(Activity
) / sizeof(Activity
[0])))
1873 SendDlgItemMessageW(hwndDlg
, IDC_ACTIVITY
, WM_SETTEXT
,
1874 0, (LPARAM
) Activity
);
1876 oldActivityID
= RegistrationNotify
->ActivityID
;
1878 SendDlgItemMessageW(hwndDlg
, IDC_ITEM
, WM_SETTEXT
, 0,
1879 (LPARAM
)(NULL
== RegistrationNotify
->CurrentItem
?
1880 L
"" : RegistrationNotify
->CurrentItem
));
1881 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1882 RegistrationNotify
->Progress
, 0);
1883 if (NULL
!= RegistrationNotify
->ErrorMessage
)
1885 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
,
1886 Title
, sizeof(Title
) / sizeof(Title
[0])))
1888 wcscpy(Title
, L
"ReactOS Setup");
1890 MessageBoxW(hwndDlg
, RegistrationNotify
->ErrorMessage
,
1891 Title
, MB_ICONERROR
| MB_OK
);
1898 if(!SetupData
->UnattendSetup
&& !SetupData
->DisableVmwInst
)
1899 RunVMWInstall(GetParent(hwndDlg
));
1902 /* Enable the Back and Next buttons */
1903 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
1904 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
1918 SetInstallationCompleted(VOID
)
1921 DWORD InProgress
= 0;
1924 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1928 &hKey
) == ERROR_SUCCESS
)
1930 RegSetValueExW( hKey
, L
"SystemSetupInProgress", 0, REG_DWORD
, (LPBYTE
)&InProgress
, sizeof(InProgress
) );
1931 RegCloseKey( hKey
);
1934 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1935 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
1938 &hKey
) == ERROR_SUCCESS
)
1940 InstallDate
= (DWORD
)time(NULL
);
1941 RegSetValueExW( hKey
, L
"InstallDate", 0, REG_DWORD
, (LPBYTE
)&InstallDate
, sizeof(InstallDate
) );
1942 RegCloseKey( hKey
);
1947 static INT_PTR CALLBACK
1948 FinishDlgProc(HWND hwndDlg
,
1958 PSETUPDATA SetupData
;
1960 /* Get pointer to the global setup data */
1961 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1963 /* Set title font */
1964 SendDlgItemMessage(hwndDlg
,
1967 (WPARAM
)SetupData
->hTitleFont
,
1969 if (SetupData
->UnattendSetup
)
1971 KillTimer(hwndDlg
, 1);
1972 SetInstallationCompleted();
1980 SetInstallationCompleted();
1990 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
1991 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
1992 if (Position
== 300)
1994 KillTimer(hwndDlg
, 1);
1995 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
1999 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
2006 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
2011 /* Enable the correct buttons on for the active page */
2012 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
2014 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
2015 MAKELPARAM(0, 300));
2016 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETPOS
, 0, 0);
2017 SetTimer(hwndDlg
, 1, 50, NULL
);
2021 DestroyWindow(GetParent(hwndDlg
));
2039 ProcessUnattendInf(HINF hUnattendedInf
)
2041 INFCONTEXT InfContext
;
2043 WCHAR szValue
[MAX_PATH
];
2047 if (!SetupFindFirstLineW(hUnattendedInf
,
2049 L
"UnattendSetupEnabled",
2052 DPRINT1("Error: Cant find UnattendSetupEnabled Key! %d\n", GetLastError());
2056 if (!SetupGetStringFieldW(&InfContext
,
2059 sizeof(szValue
) / sizeof(WCHAR
),
2062 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2066 if (wcscmp(szValue
, L
"yes") != 0)
2068 DPRINT("Unattend setup was disabled by UnattendSetupEnabled key.\n");
2072 if (!SetupFindFirstLineW(hUnattendedInf
,
2077 DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError());
2084 if (!SetupGetStringFieldW(&InfContext
,
2087 sizeof(szName
) / sizeof(WCHAR
),
2090 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2094 if (!SetupGetStringFieldW(&InfContext
,
2097 sizeof(szValue
) / sizeof(WCHAR
),
2100 DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
2103 DPRINT1("Name %S Value %S\n", szName
, szValue
);
2104 if (!wcscmp(szName
, L
"FullName"))
2106 if ((sizeof(SetupData
.OwnerName
) / sizeof(TCHAR
)) > LineLength
)
2108 wcscpy(SetupData
.OwnerName
, szValue
);
2111 else if (!wcscmp(szName
, L
"OrgName"))
2113 if ((sizeof(SetupData
.OwnerOrganization
) / sizeof(WCHAR
)) > LineLength
)
2115 wcscpy(SetupData
.OwnerOrganization
, szValue
);
2118 else if (!wcscmp(szName
, L
"ComputerName"))
2120 if ((sizeof(SetupData
.ComputerName
) / sizeof(WCHAR
)) > LineLength
)
2122 wcscpy(SetupData
.ComputerName
, szValue
);
2125 else if (!wcscmp(szName
, L
"AdminPassword"))
2127 if ((sizeof(SetupData
.AdminPassword
) / sizeof(WCHAR
)) > LineLength
)
2129 wcscpy(SetupData
.AdminPassword
, szValue
);
2132 else if (!wcscmp(szName
, L
"TimeZoneIndex"))
2134 SetupData
.TimeZoneIndex
= _wtoi(szValue
);
2136 else if (!wcscmp(szName
, L
"DisableAutoDaylightTimeSet"))
2138 SetupData
.DisableAutoDaylightTimeSet
= _wtoi(szValue
);
2140 else if (!wcscmp(szName
, L
"DisableVmwInst"))
2142 if(!wcscmp(szValue
, L
"yes"))
2143 SetupData
.DisableVmwInst
= 1;
2145 SetupData
.DisableVmwInst
= 0;
2149 while (SetupFindNextLine(&InfContext
, &InfContext
));
2151 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
2152 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
2155 &hKey
) != ERROR_SUCCESS
)
2157 DPRINT1("Error: failed to open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\n");
2162 if (SetupFindFirstLineW(hUnattendedInf
,
2171 if(SetupGetStringFieldW(&InfContext
,
2174 sizeof(szValue
) / sizeof(WCHAR
),
2177 WCHAR szPath
[MAX_PATH
];
2178 swprintf(szName
, L
"%d", i
);
2179 DPRINT("szName %S szValue %S\n", szName
, szValue
);
2181 if (ExpandEnvironmentStringsW(szValue
, szPath
, MAX_PATH
))
2183 DPRINT("value %S\n", szPath
);
2184 if (RegSetValueExW(hKey
,
2188 (const BYTE
*)szPath
,
2189 (wcslen(szPath
) + 1) * sizeof(WCHAR
)) == ERROR_SUCCESS
)
2195 } while(SetupFindNextLine(&InfContext
, &InfContext
));
2203 * GetRosInstallCD should find the path to ros installation medium
2205 * If there are more than one CDDrive in it containing a ReactOS
2206 * installation cd, then it will pick the first one regardless if
2207 * it is really the installation cd
2209 * The best way to implement this is to set the key
2210 * HKLM\Software\Microsoft\Windows NT\CurrentVersion\SourcePath (REG_SZ)
2214 GetRosInstallCD(WCHAR
*pwszPath
, DWORD cchPathMax
)
2216 WCHAR wszDrives
[512];
2220 cchDrives
= GetLogicalDriveStringsW(_countof(wszDrives
) - 1, wszDrives
);
2221 if (cchDrives
== 0 || cchDrives
>= _countof(wszDrives
))
2223 /* buffer too small or failure */
2224 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"GetLogicalDriveStringsW failed");
2228 for (pwszDrive
= wszDrives
; pwszDrive
[0]; pwszDrive
+= wcslen(pwszDrive
) + 1)
2230 if (GetDriveTypeW(pwszDrive
) == DRIVE_CDROM
)
2232 WCHAR wszBuf
[MAX_PATH
];
2233 wsprintf(wszBuf
, L
"%sreactos\\system32\\ntoskrnl.exe", pwszDrive
);
2234 LogItem(SYSSETUP_SEVERITY_INFORMATION
, wszBuf
);
2235 if (GetFileAttributesW(wszBuf
) != INVALID_FILE_ATTRIBUTES
)
2237 /* the file exists, so this is the right drive */
2238 wcsncpy(pwszPath
, pwszDrive
, cchPathMax
);
2239 OutputDebugStringW(L
"GetRosInstallCD: ");OutputDebugStringW(pwszPath
);OutputDebugStringW(L
"\n");
2249 ProcessUnattendSetup(VOID
)
2251 WCHAR szPath
[MAX_PATH
];
2252 HINF hUnattendedInf
;
2255 if (!GetRosInstallCD(szPath
, MAX_PATH
))
2257 /* no cd drive found */
2261 dwLength
= wcslen(szPath
);
2262 if (dwLength
+ 21 > MAX_PATH
)
2265 * allocate bigger buffer
2270 wcscat(szPath
, L
"reactos\\unattend.inf");
2272 hUnattendedInf
= SetupOpenInfFileW(szPath
,
2277 if (hUnattendedInf
!= INVALID_HANDLE_VALUE
)
2279 SetupData
.UnattendSetup
= ProcessUnattendInf(hUnattendedInf
);
2280 SetupCloseInfFile(hUnattendedInf
);
2288 PROPSHEETHEADER psh
;
2289 HPROPSHEETPAGE ahpsp
[8];
2290 PROPSHEETPAGE psp
= {0};
2295 /* Clear setup data */
2296 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
2298 ProcessUnattendSetup();
2300 /* Create the Welcome page */
2301 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
2302 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2303 psp
.hInstance
= hDllInstance
;
2304 psp
.lParam
= (LPARAM
)&SetupData
;
2305 psp
.pfnDlgProc
= WelcomeDlgProc
;
2306 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
2307 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2309 /* Create the Acknowledgements page */
2310 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2311 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_ACKTITLE
);
2312 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_ACKSUBTITLE
);
2313 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_ACKPAGE
);
2314 psp
.pfnDlgProc
= AckPageDlgProc
;
2315 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2317 /* Create the Owner page */
2318 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2319 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_OWNERTITLE
);
2320 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_OWNERSUBTITLE
);
2321 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_OWNERPAGE
);
2322 psp
.pfnDlgProc
= OwnerPageDlgProc
;
2323 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2325 /* Create the Computer page */
2326 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2327 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_COMPUTERTITLE
);
2328 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE
);
2329 psp
.pfnDlgProc
= ComputerPageDlgProc
;
2330 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_COMPUTERPAGE
);
2331 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2334 /* Create the Locale page */
2335 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2336 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LOCALETITLE
);
2337 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LOCALESUBTITLE
);
2338 psp
.pfnDlgProc
= LocalePageDlgProc
;
2339 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
2340 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2343 /* Create the DateTime page */
2344 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2345 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DATETIMETITLE
);
2346 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DATETIMESUBTITLE
);
2347 psp
.pfnDlgProc
= DateTimePageDlgProc
;
2348 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DATETIMEPAGE
);
2349 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2352 /* Create the Process page */
2353 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2354 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
2355 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
2356 psp
.pfnDlgProc
= ProcessPageDlgProc
;
2357 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
2358 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2361 /* Create the Finish page */
2362 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2363 psp
.pfnDlgProc
= FinishDlgProc
;
2364 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
2365 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2367 /* Create the property sheet */
2368 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2369 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
| PSH_MODELESS
;
2370 psh
.hInstance
= hDllInstance
;
2371 psh
.hwndParent
= NULL
;
2372 psh
.nPages
= nPages
;
2375 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
2376 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
2378 /* Create title font */
2379 SetupData
.hTitleFont
= CreateTitleFont();
2381 /* Display the wizard */
2382 hWnd
= (HWND
)PropertySheet(&psh
);
2383 ShowWindow(hWnd
, SW_SHOW
);
2385 while (GetMessage(&msg
, NULL
, 0, 0))
2387 if(!IsDialogMessage(hWnd
, &msg
))
2389 TranslateMessage(&msg
);
2390 DispatchMessage(&msg
);
2394 DeleteObject(SetupData
.hTitleFont
);