2 * PROJECT: System setup
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PROGRAMMER: Eric Kohl
7 /* INCLUDES *****************************************************************/
10 #define WIN32_NO_STATUS
17 #include <pseh/pseh.h>
18 #define NTOS_MODE_USER
19 #include <ndk/ntndk.h>
21 #include <syssetup/syssetup.h>
31 #define PM_REGISTRATION_NOTIFY (WM_APP + 1)
32 /* Private Message used to communicate progress from the background
33 registration thread to the main thread.
34 wParam = 0 Registration in progress
35 = 1 Registration completed
36 lParam = Pointer to a REGISTRATIONNOTIFY structure */
38 typedef struct _REGISTRATIONNOTIFY
44 } REGISTRATIONNOTIFY
, *PREGISTRATIONNOTIFY
;
46 typedef struct _REGISTRATIONDATA
52 } REGISTRATIONDATA
, *PREGISTRATIONDATA
;
54 /* GLOBALS ******************************************************************/
56 static SETUPDATA SetupData
;
59 /* FUNCTIONS ****************************************************************/
63 RunVMWInstall(HWND hWnd
)
65 PROCESS_INFORMATION ProcInfo
;
69 WCHAR InstallName
[] = L
"vmwinst.exe";
71 si
.cb
= sizeof(STARTUPINFO
);
73 if(CreateProcess(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
74 NULL
, NULL
, &si
, &ProcInfo
))
76 EnableWindow(hWnd
, FALSE
);
79 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
81 if (msg
.message
== WM_QUIT
)
83 TranslateMessage(&msg
);
84 DispatchMessage(&msg
);
87 ret
= MsgWaitForMultipleObjects(1, &ProcInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
| QS_ALLINPUT
);
88 if (ret
== WAIT_OBJECT_0
)
92 EnableWindow(hWnd
, TRUE
);
94 CloseHandle(ProcInfo
.hThread
);
95 CloseHandle(ProcInfo
.hProcess
);
103 CenterWindow(HWND hWnd
)
109 hWndParent
= GetParent(hWnd
);
110 if (hWndParent
== NULL
)
111 hWndParent
= GetDesktopWindow();
113 GetWindowRect(hWndParent
, &rcParent
);
114 GetWindowRect(hWnd
, &rcWindow
);
118 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
119 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
127 CreateTitleFont(VOID
)
129 NONCLIENTMETRICS ncm
;
135 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
136 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
138 LogFont
= ncm
.lfMessageFont
;
139 LogFont
.lfWeight
= FW_BOLD
;
140 _tcscpy(LogFont
.lfFaceName
, _T("MS Shell Dlg"));
144 LogFont
.lfHeight
= 0 - GetDeviceCaps (hdc
, LOGPIXELSY
) * FontSize
/ 72;
145 hFont
= CreateFontIndirect(&LogFont
);
146 ReleaseDC(NULL
, hdc
);
152 static INT_PTR CALLBACK
153 GplDlgProc(HWND hwndDlg
,
158 HRSRC GplTextResource
;
168 GplTextResource
= FindResource(hDllInstance
, MAKEINTRESOURCE(IDR_GPL
), _T("RT_TEXT"));
169 if (NULL
== GplTextResource
)
173 Size
= SizeofResource(hDllInstance
, GplTextResource
);
178 GplText
= HeapAlloc(GetProcessHeap(), 0, Size
+ 1);
183 GplTextMem
= LoadResource(hDllInstance
, GplTextResource
);
184 if (NULL
== GplTextMem
)
186 HeapFree(GetProcessHeap(), 0, GplText
);
189 GplTextLocked
= LockResource(GplTextMem
);
190 if (NULL
== GplTextLocked
)
192 HeapFree(GetProcessHeap(), 0, GplText
);
195 memcpy(GplText
, GplTextLocked
, Size
);
196 GplText
[Size
] = '\0';
197 SendMessageA(GetDlgItem(hwndDlg
, IDC_GPL_TEXT
), WM_SETTEXT
, 0, (LPARAM
) GplText
);
198 HeapFree(GetProcessHeap(), 0, GplText
);
199 SetFocus(GetDlgItem(hwndDlg
, IDOK
));
203 EndDialog(hwndDlg
, IDCANCEL
);
207 if (HIWORD(wParam
) == BN_CLICKED
&& IDOK
== LOWORD(wParam
))
209 EndDialog(hwndDlg
, IDOK
);
221 static INT_PTR CALLBACK
222 WelcomeDlgProc(HWND hwndDlg
,
231 PSETUPDATA SetupData
;
235 /* Get pointer to the global setup data */
236 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
238 hwndControl
= GetParent(hwndDlg
);
240 /* Center the wizard window */
241 CenterWindow (hwndControl
);
243 /* Hide the system menu */
244 dwStyle
= GetWindowLong(hwndControl
, GWL_STYLE
);
245 SetWindowLong(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
247 /* Hide and disable the 'Cancel' button */
248 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
249 ShowWindow (hwndControl
, SW_HIDE
);
250 EnableWindow (hwndControl
, FALSE
);
253 SendDlgItemMessage(hwndDlg
,
256 (WPARAM
)SetupData
->hTitleFont
,
264 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
269 /* Enable the Next button */
270 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
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
= LoadString(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
);
356 lpnm
= (LPNMHDR
)lParam
;
361 /* Enable the Back and Next buttons */
362 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
379 static INT_PTR CALLBACK
380 OwnerPageDlgProc(HWND hwndDlg
,
386 TCHAR OwnerOrganization
[51];
394 SendDlgItemMessage(hwndDlg
, IDC_OWNERNAME
, EM_LIMITTEXT
, 50, 0);
395 SendDlgItemMessage(hwndDlg
, IDC_OWNERORGANIZATION
, EM_LIMITTEXT
, 50, 0);
397 /* Set focus to owner name */
398 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
405 lpnm
= (LPNMHDR
)lParam
;
410 /* Enable the Back and Next buttons */
411 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
416 if (GetDlgItemText(hwndDlg
, IDC_OWNERNAME
, OwnerName
, 50) == 0)
419 _T("Setup cannot continue until you enter your name."),
421 MB_ICONERROR
| MB_OK
);
422 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
426 OwnerOrganization
[0] = 0;
427 GetDlgItemTextW(hwndDlg
, IDC_OWNERORGANIZATION
, OwnerOrganization
, 50);
429 RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
430 _T("Software\\Microsoft\\Windows NT\\CurrentVersion"),
434 /* FIXME: check error code */
437 _T("RegisteredOwner"),
441 (_tcslen(OwnerName
) + 1) * sizeof(TCHAR
));
442 /* FIXME: check error code */
445 _T("RegisteredOrganization"),
448 (LPBYTE
)OwnerOrganization
,
449 (_tcslen(OwnerOrganization
) + 1) * sizeof(TCHAR
));
450 /* FIXME: check error code */
469 static INT_PTR CALLBACK
470 ComputerPageDlgProc(HWND hwndDlg
,
475 TCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
485 /* Retrieve current computer name */
486 Length
= MAX_COMPUTERNAME_LENGTH
+ 1;
487 GetComputerName(ComputerName
, &Length
);
489 /* Display current computer name */
490 SetDlgItemText(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
492 /* Set text limits */
493 SendDlgItemMessage(hwndDlg
, IDC_COMPUTERNAME
, EM_LIMITTEXT
, 64, 0);
494 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD1
, EM_LIMITTEXT
, 14, 0);
495 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD2
, EM_LIMITTEXT
, 14, 0);
497 /* Set focus to computer name */
498 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
505 lpnm
= (LPNMHDR
)lParam
;
510 /* Enable the Back and Next buttons */
511 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
515 if (GetDlgItemText(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, 64) == 0)
518 _T("Setup cannot continue until you enter the name of your computer."),
520 MB_ICONERROR
| MB_OK
);
521 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
525 /* FIXME: check computer name for invalid characters */
527 if (!SetComputerName(ComputerName
))
530 _T("Setup failed to set the computer name."),
532 MB_ICONERROR
| MB_OK
);
533 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
536 /* Try to also set DNS hostname */
537 SetComputerNameEx(ComputerNamePhysicalDnsHostname
, ComputerName
);
539 /* Check admin passwords */
540 GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15);
541 GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15);
542 if (_tcscmp(Password1
, Password2
))
545 _T("The passwords you entered do not match. Please enter "\
546 "the desired password again."),
548 MB_ICONERROR
| MB_OK
);
549 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
553 /* FIXME: check password for invalid characters */
555 /* FIXME: Set admin password */
573 SetKeyboardLayoutName(HWND hwnd
)
576 TCHAR szLayoutPath
[256];
577 TCHAR szLocaleName
[32];
581 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
582 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
588 dwValueSize
= 16 * sizeof(TCHAR
);
589 if (RegQueryValueEx(hKey
,
600 _tcscpy(szLayoutPath
,
601 _T("SYSTEM\\CurrentControlSet\\Control\\KeyboardLayouts\\"));
602 _tcscat(szLayoutPath
,
605 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
612 dwValueSize
= 32 * sizeof(TCHAR
);
613 if (RegQueryValueEx(hKey
,
630 RunInputLocalePage(HWND hwnd
)
632 PROPSHEETPAGE psp
= {0};
633 PROPSHEETHEADER psh
= {0};
635 // TCHAR Caption[256];
637 hDll
= LoadLibrary(_T("intl.cpl"));
641 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
642 psp
.dwFlags
= PSP_DEFAULT
;
643 psp
.hInstance
= hDll
;
644 psp
.pszTemplate
= MAKEINTRESOURCE(105); /* IDD_LOCALEPAGE from intl.cpl */
645 psp
.pfnDlgProc
= GetProcAddress(hDll
, "LocalePageProc");
647 // LoadString(hDll, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
649 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
650 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
;
651 // psh.hwndParent = hwnd;
652 // psh.hInstance = hDll;
653 // psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
654 psh
.pszCaption
= _T("Title"); //Caption;
665 static INT_PTR CALLBACK
666 LocalePageDlgProc(HWND hwndDlg
,
671 PSETUPDATA SetupData
;
673 /* Retrieve pointer to the global setup data */
674 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
680 /* Save pointer to the global setup data */
681 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
682 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
685 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
691 if (HIWORD(wParam
) == BN_CLICKED
)
693 switch (LOWORD(wParam
))
695 case IDC_CUSTOMLOCALE
:
697 RunInputLocalePage(hwndDlg
);
698 /* FIXME: Update input locale name */
702 case IDC_CUSTOMLAYOUT
:
704 // RunKeyboardLayoutControlPanel(hwndDlg);
713 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
718 /* Enable the Back and Next buttons */
719 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
739 static PTIMEZONE_ENTRY
740 GetLargerTimeZoneEntry(PSETUPDATA SetupData
, DWORD Index
)
742 PTIMEZONE_ENTRY Entry
;
744 Entry
= SetupData
->TimeZoneListHead
;
745 while (Entry
!= NULL
)
747 if (Entry
->Index
>= Index
)
758 CreateTimeZoneList(PSETUPDATA SetupData
)
760 TCHAR szKeyName
[256];
768 PTIMEZONE_ENTRY Entry
;
769 PTIMEZONE_ENTRY Current
;
771 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
772 _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"),
781 dwNameSize
= 256 * sizeof(TCHAR
);
782 lError
= RegEnumKeyEx(hZonesKey
,
790 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
793 if (RegOpenKeyEx(hZonesKey
,
800 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
803 RegCloseKey(hZoneKey
);
807 dwValueSize
= 64 * sizeof(TCHAR
);
808 if (RegQueryValueEx(hZoneKey
,
812 (LPBYTE
)&Entry
->Description
,
815 RegCloseKey(hZoneKey
);
819 dwValueSize
= 32 * sizeof(TCHAR
);
820 if (RegQueryValueEx(hZoneKey
,
824 (LPBYTE
)&Entry
->StandardName
,
827 RegCloseKey(hZoneKey
);
831 dwValueSize
= 32 * sizeof(WCHAR
);
832 if (RegQueryValueEx(hZoneKey
,
836 (LPBYTE
)&Entry
->DaylightName
,
839 RegCloseKey(hZoneKey
);
843 dwValueSize
= sizeof(DWORD
);
844 if (RegQueryValueEx(hZoneKey
,
848 (LPBYTE
)&Entry
->Index
,
851 RegCloseKey(hZoneKey
);
855 dwValueSize
= sizeof(TZ_INFO
);
856 if (RegQueryValueEx(hZoneKey
,
860 (LPBYTE
)&Entry
->TimezoneInfo
,
863 RegCloseKey(hZoneKey
);
867 RegCloseKey(hZoneKey
);
869 if (SetupData
->TimeZoneListHead
== NULL
&&
870 SetupData
->TimeZoneListTail
== NULL
)
874 SetupData
->TimeZoneListHead
= Entry
;
875 SetupData
->TimeZoneListTail
= Entry
;
879 Current
= GetLargerTimeZoneEntry(SetupData
, Entry
->Index
);
882 if (Current
== SetupData
->TimeZoneListHead
)
884 /* Prepend to head */
886 Entry
->Next
= SetupData
->TimeZoneListHead
;
887 SetupData
->TimeZoneListHead
->Prev
= Entry
;
888 SetupData
->TimeZoneListHead
= Entry
;
892 /* Insert before current */
893 Entry
->Prev
= Current
->Prev
;
894 Entry
->Next
= Current
;
895 Current
->Prev
->Next
= Entry
;
896 Current
->Prev
= Entry
;
902 Entry
->Prev
= SetupData
->TimeZoneListTail
;
904 SetupData
->TimeZoneListTail
->Next
= Entry
;
905 SetupData
->TimeZoneListTail
= Entry
;
912 RegCloseKey(hZonesKey
);
917 DestroyTimeZoneList(PSETUPDATA SetupData
)
919 PTIMEZONE_ENTRY Entry
;
921 while (SetupData
->TimeZoneListHead
!= NULL
)
923 Entry
= SetupData
->TimeZoneListHead
;
925 SetupData
->TimeZoneListHead
= Entry
->Next
;
926 if (SetupData
->TimeZoneListHead
!= NULL
)
928 SetupData
->TimeZoneListHead
->Prev
= NULL
;
931 HeapFree(GetProcessHeap(), 0, Entry
);
934 SetupData
->TimeZoneListTail
= NULL
;
939 GetTimeZoneListIndex(LPDWORD lpIndex
)
941 TCHAR szLanguageIdString
[9];
950 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
951 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"),
957 dwValueSize
= 9 * sizeof(TCHAR
);
958 if (RegQueryValueEx(hKey
,
962 (LPBYTE
)szLanguageIdString
,
971 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
972 _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"),
979 if (RegQueryValueEx(hKey
,
990 Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
997 if (RegQueryValueEx(hKey
,
1004 HeapFree(GetProcessHeap(), 0, Buffer
);
1014 Length
= _tcslen(Ptr
);
1015 if (_tcsicmp(Ptr
, szLanguageIdString
) == 0)
1018 Ptr
= Ptr
+ Length
+ 1;
1022 Length
= _tcslen(Ptr
);
1026 *lpIndex
= _tcstoul(Ptr
, &End
, 10);
1027 HeapFree(GetProcessHeap(), 0, Buffer
);
1031 Ptr
= Ptr
+ Length
+ 1;
1034 HeapFree(GetProcessHeap(), 0, Buffer
);
1042 ShowTimeZoneList(HWND hwnd
, PSETUPDATA SetupData
)
1044 PTIMEZONE_ENTRY Entry
;
1046 DWORD dwEntryIndex
= 0;
1050 GetTimeZoneListIndex(&dwEntryIndex
);
1052 dwEntryIndex
= 85; /* GMT time zone */
1054 Entry
= SetupData
->TimeZoneListHead
;
1055 while (Entry
!= NULL
)
1057 dwCount
= SendMessage(hwnd
,
1060 (LPARAM
)Entry
->Description
);
1062 if (dwEntryIndex
!= 0 && dwEntryIndex
== Entry
->Index
)
1065 Entry
= Entry
->Next
;
1076 SetLocalTimeZone(HWND hwnd
, PSETUPDATA SetupData
)
1078 TIME_ZONE_INFORMATION TimeZoneInformation
;
1079 PTIMEZONE_ENTRY Entry
;
1083 dwIndex
= SendMessage(hwnd
,
1089 Entry
= SetupData
->TimeZoneListHead
;
1096 Entry
= Entry
->Next
;
1099 _tcscpy(TimeZoneInformation
.StandardName
,
1100 Entry
->StandardName
);
1101 _tcscpy(TimeZoneInformation
.DaylightName
,
1102 Entry
->DaylightName
);
1104 TimeZoneInformation
.Bias
= Entry
->TimezoneInfo
.Bias
;
1105 TimeZoneInformation
.StandardBias
= Entry
->TimezoneInfo
.StandardBias
;
1106 TimeZoneInformation
.DaylightBias
= Entry
->TimezoneInfo
.DaylightBias
;
1108 memcpy(&TimeZoneInformation
.StandardDate
,
1109 &Entry
->TimezoneInfo
.StandardDate
,
1110 sizeof(SYSTEMTIME
));
1111 memcpy(&TimeZoneInformation
.DaylightDate
,
1112 &Entry
->TimezoneInfo
.DaylightDate
,
1113 sizeof(SYSTEMTIME
));
1115 /* Set time zone information */
1116 SetTimeZoneInformation(&TimeZoneInformation
);
1121 GetLocalSystemTime(HWND hwnd
, PSETUPDATA SetupData
)
1126 if (DateTime_GetSystemTime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) != GDT_VALID
)
1131 if (DateTime_GetSystemTime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) != GDT_VALID
)
1136 SetupData
->SystemTime
.wYear
= Date
.wYear
;
1137 SetupData
->SystemTime
.wMonth
= Date
.wMonth
;
1138 SetupData
->SystemTime
.wDayOfWeek
= Date
.wDayOfWeek
;
1139 SetupData
->SystemTime
.wDay
= Date
.wDay
;
1140 SetupData
->SystemTime
.wHour
= Time
.wHour
;
1141 SetupData
->SystemTime
.wMinute
= Time
.wMinute
;
1142 SetupData
->SystemTime
.wSecond
= Time
.wSecond
;
1143 SetupData
->SystemTime
.wMilliseconds
= Time
.wMilliseconds
;
1150 SetAutoDaylightInfo(HWND hwnd
)
1155 if (SendMessage(hwnd
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
)
1157 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
1158 _T("SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"),
1165 _T("DisableAutoDaylightTimeSet"),
1176 SetSystemLocalTime(HWND hwnd
, PSETUPDATA SetupData
)
1180 TOKEN_PRIVILEGES priv
, previouspriv
;
1184 * enable the SeSystemtimePrivilege privilege
1187 if(OpenProcessToken(GetCurrentProcess(),
1188 TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
,
1191 priv
.PrivilegeCount
= 1;
1192 priv
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1194 if(LookupPrivilegeValue(NULL
,
1196 &priv
.Privileges
[0].Luid
))
1198 if(AdjustTokenPrivileges(hToken
,
1201 sizeof(previouspriv
),
1204 GetLastError() == ERROR_SUCCESS
)
1207 * we successfully enabled it, we're permitted to change the system time
1209 Ret
= SetLocalTime(&SetupData
->SystemTime
);
1212 * for the sake of security, restore the previous status again
1214 if(previouspriv
.PrivilegeCount
> 0)
1216 AdjustTokenPrivileges(hToken
,
1225 CloseHandle(hToken
);
1232 static INT_PTR CALLBACK
1233 DateTimePageDlgProc(HWND hwndDlg
,
1238 PSETUPDATA SetupData
;
1240 /* Retrieve pointer to the global setup data */
1241 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1247 /* Save pointer to the global setup data */
1248 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1249 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1251 CreateTimeZoneList(SetupData
);
1253 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1256 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1263 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1268 /* Enable the Back and Next buttons */
1269 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
1274 GetLocalSystemTime(hwndDlg
, SetupData
);
1275 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1277 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1278 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1281 _T("Setup was unable to set the local time."),
1282 _T("ReactOS Setup"),
1283 MB_ICONWARNING
| MB_OK
);
1295 DestroyTimeZoneList(SetupData
);
1306 static UINT CALLBACK
1307 RegistrationNotificationProc(PVOID Context
,
1312 PREGISTRATIONDATA RegistrationData
;
1313 REGISTRATIONNOTIFY RegistrationNotify
;
1314 PSP_REGISTER_CONTROL_STATUSW StatusInfo
;
1316 WCHAR ErrorMessage
[128];
1318 RegistrationData
= (PREGISTRATIONDATA
) Context
;
1320 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
||
1321 SPFILENOTIFY_ENDREGISTRATION
== Notification
)
1323 StatusInfo
= (PSP_REGISTER_CONTROL_STATUSW
) Param1
;
1324 RegistrationNotify
.CurrentItem
= wcsrchr(StatusInfo
->FileName
, L
'\\');
1325 if (NULL
== RegistrationNotify
.CurrentItem
)
1327 RegistrationNotify
.CurrentItem
= StatusInfo
->FileName
;
1331 RegistrationNotify
.CurrentItem
++;
1334 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
)
1336 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1337 StatusInfo
->FileName
);
1338 RegistrationNotify
.ErrorMessage
= NULL
;
1339 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1343 DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
1344 StatusInfo
->FileName
);
1345 DPRINT("Win32Error %u FailureCode %u\n", StatusInfo
->Win32Error
,
1346 StatusInfo
->FailureCode
);
1347 if (SPREG_SUCCESS
!= StatusInfo
->FailureCode
)
1349 switch(StatusInfo
->FailureCode
)
1351 case SPREG_LOADLIBRARY
:
1352 MessageID
= IDS_LOADLIBRARY_FAILED
;
1354 case SPREG_GETPROCADDR
:
1355 MessageID
= IDS_GETPROCADDR_FAILED
;
1358 MessageID
= IDS_REGSVR_FAILED
;
1360 case SPREG_DLLINSTALL
:
1361 MessageID
= IDS_DLLINSTALL_FAILED
;
1364 MessageID
= IDS_TIMEOUT
;
1367 MessageID
= IDS_REASON_UNKNOWN
;
1370 if (0 == LoadStringW(hDllInstance
, MessageID
,
1372 sizeof(ErrorMessage
) /
1373 sizeof(ErrorMessage
[0])))
1375 ErrorMessage
[0] = L
'\0';
1377 if (SPREG_TIMEOUT
!= StatusInfo
->FailureCode
)
1379 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
1380 StatusInfo
->Win32Error
, 0,
1381 ErrorMessage
+ wcslen(ErrorMessage
),
1382 sizeof(ErrorMessage
) / sizeof(ErrorMessage
[0]) -
1383 wcslen(ErrorMessage
), NULL
);
1385 RegistrationNotify
.ErrorMessage
= ErrorMessage
;
1389 RegistrationNotify
.ErrorMessage
= NULL
;
1391 if (RegistrationData
->Registered
< RegistrationData
->DllCount
)
1393 RegistrationData
->Registered
++;
1397 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1398 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1399 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1400 0, (LPARAM
) &RegistrationNotify
);
1406 DPRINT1("Received unexpected notification %u\n", Notification
);
1407 return SetupDefaultQueueCallback(RegistrationData
->DefaultContext
,
1408 Notification
, Param1
, Param2
);
1413 static DWORD CALLBACK
1414 RegistrationProc(LPVOID Parameter
)
1416 PREGISTRATIONDATA RegistrationData
;
1417 REGISTRATIONNOTIFY RegistrationNotify
;
1418 DWORD LastError
= NO_ERROR
;
1419 WCHAR UnknownError
[84];
1421 RegistrationData
= (PREGISTRATIONDATA
) Parameter
;
1422 RegistrationData
->Registered
= 0;
1423 RegistrationData
->DefaultContext
= SetupInitDefaultQueueCallback(RegistrationData
->hwndDlg
);
1427 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData
->hwndDlg
),
1429 L
"RegistrationPhase2",
1431 SPINST_REGISTERCALLBACKAWARE
|
1436 RegistrationNotificationProc
,
1441 LastError
= GetLastError();
1446 DPRINT("Catching exception\n");
1447 LastError
= RtlNtStatusToDosError(_SEH_GetExceptionCode());
1451 if (NO_ERROR
== LastError
)
1453 RegistrationNotify
.ErrorMessage
= NULL
;
1457 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1459 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1460 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, LastError
, 0,
1461 (LPWSTR
) &RegistrationNotify
.ErrorMessage
, 0,
1464 if (0 == LoadStringW(hDllInstance
, IDS_UNKNOWN_ERROR
,
1466 sizeof(UnknownError
) / sizeof(UnknownError
[0] -
1469 wcscpy(UnknownError
, L
"Unknown error");
1471 wcscat(UnknownError
, L
" ");
1472 _ultow(LastError
, UnknownError
+ wcslen(UnknownError
), 10);
1473 RegistrationNotify
.ErrorMessage
= UnknownError
;
1477 RegistrationNotify
.Progress
= RegistrationData
->DllCount
;
1478 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1479 RegistrationNotify
.CurrentItem
= NULL
;
1480 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1481 1, (LPARAM
) &RegistrationNotify
);
1482 if (NULL
!= RegistrationNotify
.ErrorMessage
&&
1483 UnknownError
!= RegistrationNotify
.ErrorMessage
)
1485 LocalFree((PVOID
) RegistrationNotify
.ErrorMessage
);
1488 SetupTermDefaultQueueCallback(RegistrationData
->DefaultContext
);
1489 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1496 StartComponentRegistration(HWND hwndDlg
, PULONG MaxProgress
)
1498 HANDLE RegistrationThread
;
1501 WCHAR SectionName
[512];
1502 PREGISTRATIONDATA RegistrationData
;
1505 if (! SetupFindFirstLineW(hSysSetupInf
, L
"RegistrationPhase2",
1506 L
"RegisterDlls", &Context
))
1508 DPRINT1("No RegistrationPhase2 section found\n");
1511 if (! SetupGetStringFieldW(&Context
, 1, SectionName
,
1512 sizeof(SectionName
) / sizeof(SectionName
[0]),
1515 DPRINT1("Unable to retrieve section name\n");
1518 DllCount
= SetupGetLineCountW(hSysSetupInf
, SectionName
);
1519 DPRINT("SectionName %S DllCount %ld\n", SectionName
, DllCount
);
1522 SetLastError(STATUS_NOT_FOUND
);
1526 *MaxProgress
= (ULONG
) DllCount
;
1529 * Create a background thread to do the actual registrations, so the
1530 * main thread can just run its message loop.
1532 RegistrationThread
= NULL
;
1533 RegistrationData
= HeapAlloc(GetProcessHeap(), 0,
1534 sizeof(REGISTRATIONDATA
));
1535 if (NULL
!= RegistrationData
)
1537 RegistrationData
->hwndDlg
= hwndDlg
;
1538 RegistrationData
->DllCount
= DllCount
;
1539 RegistrationThread
= CreateThread(NULL
, 0, RegistrationProc
,
1540 (LPVOID
) RegistrationData
, 0, NULL
);
1541 if (NULL
!= RegistrationThread
)
1543 CloseHandle(RegistrationThread
);
1547 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1553 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1561 static INT_PTR CALLBACK
1562 ProcessPageDlgProc(HWND hwndDlg
,
1567 PSETUPDATA SetupData
;
1568 PREGISTRATIONNOTIFY RegistrationNotify
;
1571 /* Retrieve pointer to the global setup data */
1572 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1578 /* Save pointer to the global setup data */
1579 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1580 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1586 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1587 ULONG MaxProgress
= 0;
1592 /* Disable the Back and Next buttons */
1593 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
1595 StartComponentRegistration(hwndDlg
, &MaxProgress
);
1597 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
,
1598 0, MAKELPARAM(0, MaxProgress
));
1599 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1612 case PM_REGISTRATION_NOTIFY
:
1615 RegistrationNotify
= (PREGISTRATIONNOTIFY
) lParam
;
1616 if (0 != LoadStringW(hDllInstance
, RegistrationNotify
->ActivityID
,
1618 sizeof(Activity
) / sizeof(Activity
[0])))
1620 SendDlgItemMessageW(hwndDlg
, IDC_ACTIVITY
, WM_SETTEXT
,
1621 0, (LPARAM
) Activity
);
1623 SendDlgItemMessageW(hwndDlg
, IDC_ITEM
, WM_SETTEXT
, 0,
1624 (LPARAM
)(NULL
== RegistrationNotify
->CurrentItem
?
1625 L
"" : RegistrationNotify
->CurrentItem
));
1626 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1627 RegistrationNotify
->Progress
, 0);
1628 if (NULL
!= RegistrationNotify
->ErrorMessage
)
1630 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
,
1631 Title
, sizeof(Title
) / sizeof(Title
[0])))
1633 wcscpy(Title
, L
"ReactOS Setup");
1635 MessageBoxW(hwndDlg
, RegistrationNotify
->ErrorMessage
,
1636 Title
, MB_ICONERROR
| MB_OK
);
1643 RunVMWInstall(GetParent(hwndDlg
));
1646 /* Enable the Back and Next buttons */
1647 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
1648 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
1662 SetupIsActive( DWORD dw
)
1665 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE
, _T("SYSTEM\\Setup"), 0, KEY_WRITE
, &hKey
) == ERROR_SUCCESS
) {
1666 RegSetValueEx( hKey
, _T("SystemSetupInProgress"), 0, REG_DWORD
, (CONST BYTE
*)&dw
, sizeof(dw
) );
1667 RegCloseKey( hKey
);
1672 static INT_PTR CALLBACK
1673 FinishDlgProc(HWND hwndDlg
,
1683 PSETUPDATA SetupData
;
1685 /* Get pointer to the global setup data */
1686 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1688 /* Set title font */
1689 SendDlgItemMessage(hwndDlg
,
1692 (WPARAM
)SetupData
->hTitleFont
,
1706 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
1707 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
1708 if (Position
== 300)
1710 KillTimer(hwndDlg
, 1);
1711 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
1715 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
1722 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1727 /* Enable the correct buttons on for the active page */
1728 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_FINISH
);
1730 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
1731 MAKELPARAM(0, 300));
1732 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETPOS
, 0, 0);
1733 SetTimer(hwndDlg
, 1, 50, NULL
);
1737 /* Handle a Back button click, if necessary */
1738 KillTimer(hwndDlg
, 1);
1740 /* Skip the progress page */
1741 PropSheet_SetCurSelByID(GetParent(hwndDlg
), IDD_DATETIMEPAGE
);
1742 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, -1);
1746 /* Handle a Finish button click, if necessary */
1766 PROPSHEETHEADER psh
;
1767 HPROPSHEETPAGE ahpsp
[8];
1768 PROPSHEETPAGE psp
= {0};
1771 /* Clear setup data */
1772 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
1774 /* Create the Welcome page */
1775 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1776 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
1777 psp
.hInstance
= hDllInstance
;
1778 psp
.lParam
= (LPARAM
)&SetupData
;
1779 psp
.pfnDlgProc
= WelcomeDlgProc
;
1780 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
1781 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1783 /* Create the Acknowledgements page */
1784 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1785 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_ACKTITLE
);
1786 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_ACKSUBTITLE
);
1787 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_ACKPAGE
);
1788 psp
.pfnDlgProc
= AckPageDlgProc
;
1789 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1791 /* Create the Owner page */
1792 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1793 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_OWNERTITLE
);
1794 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_OWNERSUBTITLE
);
1795 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_OWNERPAGE
);
1796 psp
.pfnDlgProc
= OwnerPageDlgProc
;
1797 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1799 /* Create the Computer page */
1800 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1801 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_COMPUTERTITLE
);
1802 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE
);
1803 psp
.pfnDlgProc
= ComputerPageDlgProc
;
1804 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_COMPUTERPAGE
);
1805 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1808 /* Create the Locale page */
1809 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1810 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LOCALETITLE
);
1811 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LOCALESUBTITLE
);
1812 psp
.pfnDlgProc
= LocalePageDlgProc
;
1813 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
1814 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1817 /* Create the DateTime page */
1818 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1819 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DATETIMETITLE
);
1820 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DATETIMESUBTITLE
);
1821 psp
.pfnDlgProc
= DateTimePageDlgProc
;
1822 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DATETIMEPAGE
);
1823 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1826 /* Create the Process page */
1827 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1828 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
1829 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
1830 psp
.pfnDlgProc
= ProcessPageDlgProc
;
1831 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
1832 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1835 /* Create the Finish page */
1836 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
1837 psp
.pfnDlgProc
= FinishDlgProc
;
1838 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
1839 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1841 /* Create the property sheet */
1842 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
1843 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
;
1844 psh
.hInstance
= hDllInstance
;
1845 psh
.hwndParent
= NULL
;
1846 psh
.nPages
= nPages
;
1849 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
1850 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
1852 /* Create title font */
1853 SetupData
.hTitleFont
= CreateTitleFont();
1855 /* Display the wizard */
1856 PropertySheet(&psh
);
1858 DeleteObject(SetupData
.hTitleFont
);