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 *****************************************************************/
13 #define WIN32_NO_STATUS
19 #include <pseh/pseh2.h>
21 #define NTOS_MODE_USER
22 #include <ndk/ntndk.h>
25 #include <syssetup/syssetup.h>
35 #define PM_REGISTRATION_NOTIFY (WM_APP + 1)
36 /* Private Message used to communicate progress from the background
37 registration thread to the main thread.
38 wParam = 0 Registration in progress
39 = 1 Registration completed
40 lParam = Pointer to a REGISTRATIONNOTIFY structure */
42 typedef struct _REGISTRATIONNOTIFY
48 } REGISTRATIONNOTIFY
, *PREGISTRATIONNOTIFY
;
50 typedef struct _REGISTRATIONDATA
56 } REGISTRATIONDATA
, *PREGISTRATIONDATA
;
58 /* GLOBALS ******************************************************************/
63 /* FUNCTIONS ****************************************************************/
65 GetRosInstallCD(WCHAR
* szPath
, DWORD dwPathLength
);
69 RunVMWInstall(HWND hWnd
)
71 PROCESS_INFORMATION ProcInfo
;
74 STARTUPINFOW si
= {0};
75 WCHAR InstallName
[] = L
"vmwinst.exe";
77 si
.cb
= sizeof(STARTUPINFO
);
79 if(CreateProcessW(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
80 NULL
, NULL
, &si
, &ProcInfo
))
82 EnableWindow(hWnd
, FALSE
);
85 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
87 if (msg
.message
== WM_QUIT
)
89 TranslateMessage(&msg
);
90 DispatchMessage(&msg
);
93 ret
= MsgWaitForMultipleObjects(1, &ProcInfo
.hProcess
, FALSE
, INFINITE
, QS_ALLEVENTS
| QS_ALLINPUT
);
94 if (ret
== WAIT_OBJECT_0
)
98 EnableWindow(hWnd
, TRUE
);
100 CloseHandle(ProcInfo
.hThread
);
101 CloseHandle(ProcInfo
.hProcess
);
109 CenterWindow(HWND hWnd
)
115 hWndParent
= GetParent(hWnd
);
116 if (hWndParent
== NULL
)
117 hWndParent
= GetDesktopWindow();
119 GetWindowRect(hWndParent
, &rcParent
);
120 GetWindowRect(hWnd
, &rcWindow
);
124 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
125 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
133 CreateTitleFont(VOID
)
135 NONCLIENTMETRICSW ncm
;
141 ncm
.cbSize
= sizeof(NONCLIENTMETRICSW
);
142 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
144 LogFont
= ncm
.lfMessageFont
;
145 LogFont
.lfWeight
= FW_BOLD
;
146 wcscpy(LogFont
.lfFaceName
, L
"MS Shell Dlg");
150 LogFont
.lfHeight
= 0 - GetDeviceCaps(hdc
, LOGPIXELSY
) * FontSize
/ 72;
151 hFont
= CreateFontIndirectW(&LogFont
);
152 ReleaseDC(NULL
, hdc
);
158 static INT_PTR CALLBACK
159 GplDlgProc(HWND hwndDlg
,
164 HRSRC GplTextResource
;
174 GplTextResource
= FindResourceW(hDllInstance
, MAKEINTRESOURCE(IDR_GPL
), L
"RT_TEXT");
175 if (NULL
== GplTextResource
)
179 Size
= SizeofResource(hDllInstance
, GplTextResource
);
184 GplText
= HeapAlloc(GetProcessHeap(), 0, Size
+ 1);
189 GplTextMem
= LoadResource(hDllInstance
, GplTextResource
);
190 if (NULL
== GplTextMem
)
192 HeapFree(GetProcessHeap(), 0, GplText
);
195 GplTextLocked
= LockResource(GplTextMem
);
196 if (NULL
== GplTextLocked
)
198 HeapFree(GetProcessHeap(), 0, GplText
);
201 memcpy(GplText
, GplTextLocked
, Size
);
202 GplText
[Size
] = '\0';
203 SendMessageA(GetDlgItem(hwndDlg
, IDC_GPL_TEXT
), WM_SETTEXT
, 0, (LPARAM
) GplText
);
204 HeapFree(GetProcessHeap(), 0, GplText
);
205 SetFocus(GetDlgItem(hwndDlg
, IDOK
));
209 EndDialog(hwndDlg
, IDCANCEL
);
213 if (HIWORD(wParam
) == BN_CLICKED
&& IDOK
== LOWORD(wParam
))
215 EndDialog(hwndDlg
, IDOK
);
227 static INT_PTR CALLBACK
228 WelcomeDlgProc(HWND hwndDlg
,
237 PSETUPDATA SetupData
;
241 /* Get pointer to the global setup data */
242 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
244 hwndControl
= GetParent(hwndDlg
);
246 /* Center the wizard window */
247 CenterWindow (hwndControl
);
249 /* Hide the system menu */
250 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
251 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
253 /* Hide and disable the 'Cancel' button */
254 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
255 ShowWindow (hwndControl
, SW_HIDE
);
256 EnableWindow (hwndControl
, FALSE
);
259 SendDlgItemMessage(hwndDlg
,
262 (WPARAM
)SetupData
->hTitleFont
,
270 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
275 /* Enable the Next button */
276 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
277 if (SetupData
.UnattendSetup
)
279 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_ACKPAGE
);
285 SetupData
.UnattendSetup
= FALSE
;
302 static INT_PTR CALLBACK
303 AckPageDlgProc(HWND hwndDlg
,
310 PWCHAR End
, CurrentProject
;
311 INT ProjectsSize
, ProjectsCount
;
321 Projects
= HeapAlloc(GetProcessHeap(), 0, ProjectsSize
* sizeof(WCHAR
));
322 if (NULL
== Projects
)
326 ProjectsCount
= LoadStringW(hDllInstance
, IDS_ACKPROJECTS
, Projects
, ProjectsSize
);
327 if (0 == ProjectsCount
)
329 HeapFree(GetProcessHeap(), 0, Projects
);
332 if (ProjectsCount
< ProjectsSize
- 1)
336 HeapFree(GetProcessHeap(), 0, Projects
);
340 CurrentProject
= Projects
;
341 while (L
'\0' != *CurrentProject
)
343 End
= wcschr(CurrentProject
, L
'\n');
348 (void)ListBox_AddString(GetDlgItem(hwndDlg
, IDC_PROJECTS
), CurrentProject
);
351 CurrentProject
= End
+ 1;
355 CurrentProject
+= wcslen(CurrentProject
);
358 HeapFree(GetProcessHeap(), 0, Projects
);
363 if (HIWORD(wParam
) == BN_CLICKED
&& IDC_VIEWGPL
== LOWORD(wParam
))
365 DialogBox(hDllInstance
, MAKEINTRESOURCE(IDD_GPL
), NULL
, GplDlgProc
);
371 lpnm
= (LPNMHDR
)lParam
;
376 /* Enable the Back and Next buttons */
377 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
378 if (SetupData
.UnattendSetup
)
380 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_OWNERPAGE
);
386 SetupData
.UnattendSetup
= FALSE
;
404 WriteOwnerSettings(WCHAR
* OwnerName
,
405 WCHAR
* OwnerOrganization
)
412 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
413 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
418 if (res
!= ERROR_SUCCESS
)
423 res
= RegSetValueExW(hKey
,
428 (wcslen(OwnerName
) + 1) * sizeof(WCHAR
));
430 if (res
!= ERROR_SUCCESS
)
436 res
= RegSetValueExW(hKey
,
437 L
"RegisteredOrganization",
440 (LPBYTE
)OwnerOrganization
,
441 (wcslen(OwnerOrganization
) + 1) * sizeof(WCHAR
));
444 return (res
== ERROR_SUCCESS
);
447 static INT_PTR CALLBACK
448 OwnerPageDlgProc(HWND hwndDlg
,
454 WCHAR OwnerOrganization
[51];
456 WCHAR ErrorName
[256];
463 SendDlgItemMessage(hwndDlg
, IDC_OWNERNAME
, EM_LIMITTEXT
, 50, 0);
464 SendDlgItemMessage(hwndDlg
, IDC_OWNERORGANIZATION
, EM_LIMITTEXT
, 50, 0);
466 /* Set focus to owner name */
467 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
474 lpnm
= (LPNMHDR
)lParam
;
479 /* Enable the Back and Next buttons */
480 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
481 if (SetupData
.UnattendSetup
)
483 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerName
);
484 SendMessage(GetDlgItem(hwndDlg
, IDC_OWNERORGANIZATION
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.OwnerOrganization
);
485 if (WriteOwnerSettings(SetupData
.OwnerName
, SetupData
.OwnerOrganization
))
487 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_COMPUTERPAGE
);
495 if (GetDlgItemTextW(hwndDlg
, IDC_OWNERNAME
, OwnerName
, 50) == 0)
497 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
499 wcscpy(Title
, L
"ReactOS Setup");
501 if (0 == LoadStringW(hDllInstance
, IDS_WZD_NAME
, ErrorName
, sizeof(ErrorName
) / sizeof(ErrorName
[0])))
503 wcscpy(ErrorName
, L
"Setup cannot continue until you enter your name.");
505 MessageBoxW(hwndDlg
, ErrorName
, Title
, MB_ICONERROR
| MB_OK
);
507 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
508 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
513 OwnerOrganization
[0] = 0;
514 GetDlgItemTextW(hwndDlg
, IDC_OWNERORGANIZATION
, OwnerOrganization
, 50);
516 if (!WriteOwnerSettings(OwnerName
, OwnerOrganization
))
518 SetFocus(GetDlgItem(hwndDlg
, IDC_OWNERNAME
));
519 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
524 SetupData
.UnattendSetup
= FALSE
;
541 WriteComputerSettings(WCHAR
* ComputerName
, HWND hwndDlg
)
544 WCHAR ErrorComputerName
[256];
545 if (!SetComputerNameW(ComputerName
))
547 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
549 wcscpy(Title
, L
"ReactOS Setup");
551 if (0 == LoadStringW(hDllInstance
, IDS_WZD_SETCOMPUTERNAME
, ErrorComputerName
,
552 sizeof(ErrorComputerName
) / sizeof(ErrorComputerName
[0])))
554 wcscpy(ErrorComputerName
, L
"Setup failed to set the computer name.");
556 MessageBoxW(hwndDlg
, ErrorComputerName
, Title
, MB_ICONERROR
| MB_OK
);
561 /* Try to also set DNS hostname */
562 SetComputerNameExW(ComputerNamePhysicalDnsHostname
, ComputerName
);
567 static INT_PTR CALLBACK
568 ComputerPageDlgProc(HWND hwndDlg
,
573 WCHAR ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
578 WCHAR EmptyComputerName
[256], NotMatchPassword
[256], WrongPassword
[256];
582 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
584 wcscpy(Title
, L
"ReactOS Setup");
591 /* Retrieve current computer name */
592 Length
= MAX_COMPUTERNAME_LENGTH
+ 1;
593 GetComputerNameW(ComputerName
, &Length
);
595 /* Display current computer name */
596 SetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
);
598 /* Set text limits */
599 SendDlgItemMessage(hwndDlg
, IDC_COMPUTERNAME
, EM_LIMITTEXT
, MAX_COMPUTERNAME_LENGTH
, 0);
600 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD1
, EM_LIMITTEXT
, 14, 0);
601 SendDlgItemMessage(hwndDlg
, IDC_ADMINPASSWORD2
, EM_LIMITTEXT
, 14, 0);
603 /* Set focus to computer name */
604 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
605 if (SetupData
.UnattendSetup
)
607 SendMessage(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.ComputerName
);
608 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD1
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
609 SendMessage(GetDlgItem(hwndDlg
, IDC_ADMINPASSWORD2
), WM_SETTEXT
, 0, (LPARAM
)SetupData
.AdminPassword
);
618 lpnm
= (LPNMHDR
)lParam
;
623 /* Enable the Back and Next buttons */
624 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
625 if (SetupData
.UnattendSetup
&& WriteComputerSettings(SetupData
.ComputerName
, hwndDlg
))
627 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_LOCALEPAGE
);
633 if (0 == GetDlgItemTextW(hwndDlg
, IDC_COMPUTERNAME
, ComputerName
, MAX_COMPUTERNAME_LENGTH
+ 1))
635 if (0 == LoadStringW(hDllInstance
, IDS_WZD_COMPUTERNAME
, EmptyComputerName
,
636 sizeof(EmptyComputerName
) / sizeof(EmptyComputerName
[0])))
638 wcscpy(EmptyComputerName
, L
"Setup cannot continue until you enter the name of your computer.");
640 MessageBoxW(hwndDlg
, EmptyComputerName
, Title
, MB_ICONERROR
| MB_OK
);
641 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
642 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
646 /* No need to check computer name for invalid characters,
647 * SetComputerName() will do it for us */
649 if (!WriteComputerSettings(ComputerName
, hwndDlg
))
651 SetFocus(GetDlgItem(hwndDlg
, IDC_COMPUTERNAME
));
652 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
657 /* Check if admin passwords have been entered */
658 if ((GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15) == 0) ||
659 (GetDlgItemText(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15) == 0))
661 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDEMPTY
, EmptyPassword
,
662 sizeof(EmptyPassword
) / sizeof(EmptyPassword
[0])))
664 wcscpy(EmptyPassword
, L
"You must enter a password !");
666 MessageBoxW(hwndDlg
, EmptyPassword
, Title
, MB_ICONERROR
| MB_OK
);
667 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
671 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD1
, Password1
, 15);
672 GetDlgItemTextW(hwndDlg
, IDC_ADMINPASSWORD2
, Password2
, 15);
674 /* Check if passwords match */
675 if (wcscmp(Password1
, Password2
))
677 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDMATCH
, NotMatchPassword
,
678 sizeof(NotMatchPassword
) / sizeof(NotMatchPassword
[0])))
680 wcscpy(NotMatchPassword
, L
"The passwords you entered do not match. Please enter the desired password again.");
682 MessageBoxW(hwndDlg
, NotMatchPassword
, Title
, MB_ICONERROR
| MB_OK
);
683 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
687 /* Check password for invalid characters */
688 Password
= (PWCHAR
)Password1
;
691 if (!isprint(*Password
))
693 if (0 == LoadStringW(hDllInstance
, IDS_WZD_PASSWORDCHAR
, WrongPassword
,
694 sizeof(WrongPassword
) / sizeof(WrongPassword
[0])))
696 wcscpy(WrongPassword
, L
"The password you entered contains invalid characters. Please enter a cleaned password.");
698 MessageBoxW(hwndDlg
, WrongPassword
, Title
, MB_ICONERROR
| MB_OK
);
699 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, -1);
706 /* FIXME: Set admin password */
710 SetupData
.UnattendSetup
= FALSE
;
728 SetKeyboardLayoutName(HWND hwnd
)
731 TCHAR szLayoutPath
[256];
732 TCHAR szLocaleName
[32];
736 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
737 _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Locale"),
743 dwValueSize
= 16 * sizeof(TCHAR
);
744 if (RegQueryValueEx(hKey
,
755 _tcscpy(szLayoutPath
,
756 _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"));
757 _tcscat(szLayoutPath
,
760 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
767 dwValueSize
= 32 * sizeof(TCHAR
);
768 if (RegQueryValueEx(hKey
,
785 RunControlPanelApplet(HWND hwnd
, WCHAR
*lpCommandLine
)
787 STARTUPINFOW StartupInfo
;
788 PROCESS_INFORMATION ProcessInformation
;
790 ZeroMemory(&StartupInfo
, sizeof(STARTUPINFOW
));
791 StartupInfo
.cb
= sizeof(STARTUPINFOW
);
793 if (!CreateProcessW(NULL
,
802 &ProcessInformation
))
804 MessageBoxW(hwnd
, L
"Error: failed to launch rundll32", NULL
, MB_ICONERROR
);
808 WaitForSingleObject(ProcessInformation
.hProcess
, INFINITE
);
809 CloseHandle(ProcessInformation
.hThread
);
810 CloseHandle(ProcessInformation
.hProcess
);
815 WriteUserLocale(VOID
)
821 lcid
= GetSystemDefaultLCID();
823 if (GetLocaleInfoW(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_ILANGUAGE
, Locale
, sizeof(Locale
) / sizeof(Locale
[0])) != 0)
825 if (RegCreateKeyExW(HKEY_CURRENT_USER
, L
"Control Panel\\International",
826 0, NULL
, REG_OPTION_NON_VOLATILE
,
827 KEY_WRITE
, NULL
, &hKey
, NULL
) == ERROR_SUCCESS
)
829 RegSetValueExW(hKey
, L
"Locale", 0, REG_SZ
, (LPBYTE
)Locale
, (wcslen(Locale
)+1) * sizeof(WCHAR
));
835 static INT_PTR CALLBACK
836 LocalePageDlgProc(HWND hwndDlg
,
841 PSETUPDATA SetupData
;
842 WCHAR szBuffer
[1024];
844 /* Retrieve pointer to the global setup data */
845 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
851 /* Save pointer to the global setup data */
852 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
853 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
856 SetKeyboardLayoutName(GetDlgItem(hwndDlg
, IDC_LAYOUTTEXT
));
861 if (HIWORD(wParam
) == BN_CLICKED
)
863 switch (LOWORD(wParam
))
865 case IDC_CUSTOMLOCALE
:
867 wcscpy(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,5");
868 RunControlPanelApplet(hwndDlg
, szBuffer
);
869 /* FIXME: Update input locale name */
873 case IDC_CUSTOMLAYOUT
:
875 wcscpy(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL input.dll,@1");
876 RunControlPanelApplet(hwndDlg
, szBuffer
);
885 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
890 /* Enable the Back and Next buttons */
891 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
892 if (SetupData
->UnattendSetup
)
894 WCHAR szPath
[MAX_PATH
];
895 if (GetRosInstallCD(szPath
, MAX_PATH
))
897 swprintf(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,/f:\"%S\\reactos\\unattend.inf\"", szPath
);
901 wcscpy(szBuffer
, L
"rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,/f:\"unattend.inf\"");
904 RunControlPanelApplet(hwndDlg
, szBuffer
);
905 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_DATETIMEPAGE
);
914 SetupData
->UnattendSetup
= FALSE
;
931 static PTIMEZONE_ENTRY
932 GetLargerTimeZoneEntry(PSETUPDATA SetupData
, DWORD Index
)
934 PTIMEZONE_ENTRY Entry
;
936 Entry
= SetupData
->TimeZoneListHead
;
937 while (Entry
!= NULL
)
939 if (Entry
->Index
>= Index
)
950 CreateTimeZoneList(PSETUPDATA SetupData
)
952 WCHAR szKeyName
[256];
960 PTIMEZONE_ENTRY Entry
;
961 PTIMEZONE_ENTRY Current
;
963 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
964 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
973 dwNameSize
= 256 * sizeof(WCHAR
);
974 lError
= RegEnumKeyExW(hZonesKey
,
982 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
985 if (RegOpenKeyExW(hZonesKey
,
992 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
995 RegCloseKey(hZoneKey
);
999 dwValueSize
= 64 * sizeof(TCHAR
);
1000 if (RegQueryValueExW(hZoneKey
,
1004 (LPBYTE
)&Entry
->Description
,
1007 RegCloseKey(hZoneKey
);
1011 dwValueSize
= 32 * sizeof(TCHAR
);
1012 if (RegQueryValueExW(hZoneKey
,
1016 (LPBYTE
)&Entry
->StandardName
,
1019 RegCloseKey(hZoneKey
);
1023 dwValueSize
= 32 * sizeof(WCHAR
);
1024 if (RegQueryValueExW(hZoneKey
,
1028 (LPBYTE
)&Entry
->DaylightName
,
1031 RegCloseKey(hZoneKey
);
1035 dwValueSize
= sizeof(DWORD
);
1036 if (RegQueryValueExW(hZoneKey
,
1040 (LPBYTE
)&Entry
->Index
,
1043 RegCloseKey(hZoneKey
);
1047 dwValueSize
= sizeof(TZ_INFO
);
1048 if (RegQueryValueExW(hZoneKey
,
1052 (LPBYTE
)&Entry
->TimezoneInfo
,
1055 RegCloseKey(hZoneKey
);
1059 RegCloseKey(hZoneKey
);
1061 if (SetupData
->TimeZoneListHead
== NULL
&&
1062 SetupData
->TimeZoneListTail
== NULL
)
1066 SetupData
->TimeZoneListHead
= Entry
;
1067 SetupData
->TimeZoneListTail
= Entry
;
1071 Current
= GetLargerTimeZoneEntry(SetupData
, Entry
->Index
);
1072 if (Current
!= NULL
)
1074 if (Current
== SetupData
->TimeZoneListHead
)
1076 /* Prepend to head */
1078 Entry
->Next
= SetupData
->TimeZoneListHead
;
1079 SetupData
->TimeZoneListHead
->Prev
= Entry
;
1080 SetupData
->TimeZoneListHead
= Entry
;
1084 /* Insert before current */
1085 Entry
->Prev
= Current
->Prev
;
1086 Entry
->Next
= Current
;
1087 Current
->Prev
->Next
= Entry
;
1088 Current
->Prev
= Entry
;
1093 /* Append to tail */
1094 Entry
->Prev
= SetupData
->TimeZoneListTail
;
1096 SetupData
->TimeZoneListTail
->Next
= Entry
;
1097 SetupData
->TimeZoneListTail
= Entry
;
1104 RegCloseKey(hZonesKey
);
1109 DestroyTimeZoneList(PSETUPDATA SetupData
)
1111 PTIMEZONE_ENTRY Entry
;
1113 while (SetupData
->TimeZoneListHead
!= NULL
)
1115 Entry
= SetupData
->TimeZoneListHead
;
1117 SetupData
->TimeZoneListHead
= Entry
->Next
;
1118 if (SetupData
->TimeZoneListHead
!= NULL
)
1120 SetupData
->TimeZoneListHead
->Prev
= NULL
;
1123 HeapFree(GetProcessHeap(), 0, Entry
);
1126 SetupData
->TimeZoneListTail
= NULL
;
1130 GetTimeZoneListIndex(LPDWORD lpIndex
)
1132 WCHAR szLanguageIdString
[9];
1139 BOOL bFound
= FALSE
;
1140 unsigned long iLanguageID
;
1142 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1143 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
1149 dwValueSize
= 9 * sizeof(TCHAR
);
1150 if (RegQueryValueExW(hKey
,
1154 (LPBYTE
)szLanguageIdString
,
1161 iLanguageID
= wcstoul(szLanguageIdString
, NULL
, 16);
1164 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1165 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
1172 if (RegQueryValueExW(hKey
,
1183 Buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
1190 if (RegQueryValueExW(hKey
,
1197 HeapFree(GetProcessHeap(), 0, Buffer
);
1207 Length
= wcslen(Ptr
);
1208 if (wcstoul(Ptr
, NULL
, 16) == iLanguageID
)
1211 Ptr
= Ptr
+ Length
+ 1;
1217 *lpIndex
= wcstoul(Ptr
, &End
, 10);
1218 HeapFree(GetProcessHeap(), 0, Buffer
);
1222 Length
= wcslen(Ptr
);
1223 Ptr
= Ptr
+ Length
+ 1;
1226 HeapFree(GetProcessHeap(), 0, Buffer
);
1233 ShowTimeZoneList(HWND hwnd
, PSETUPDATA SetupData
, DWORD dwEntryIndex
)
1235 PTIMEZONE_ENTRY Entry
;
1239 GetTimeZoneListIndex(&dwEntryIndex
);
1241 Entry
= SetupData
->TimeZoneListHead
;
1242 while (Entry
!= NULL
)
1244 dwCount
= SendMessage(hwnd
,
1247 (LPARAM
)Entry
->Description
);
1249 if (dwEntryIndex
!= 0 && dwEntryIndex
== Entry
->Index
)
1252 Entry
= Entry
->Next
;
1263 SetLocalTimeZone(HWND hwnd
, PSETUPDATA SetupData
)
1265 TIME_ZONE_INFORMATION TimeZoneInformation
;
1266 PTIMEZONE_ENTRY Entry
;
1270 dwIndex
= SendMessage(hwnd
,
1276 Entry
= SetupData
->TimeZoneListHead
;
1283 Entry
= Entry
->Next
;
1286 wcscpy(TimeZoneInformation
.StandardName
,
1287 Entry
->StandardName
);
1288 wcscpy(TimeZoneInformation
.DaylightName
,
1289 Entry
->DaylightName
);
1291 TimeZoneInformation
.Bias
= Entry
->TimezoneInfo
.Bias
;
1292 TimeZoneInformation
.StandardBias
= Entry
->TimezoneInfo
.StandardBias
;
1293 TimeZoneInformation
.DaylightBias
= Entry
->TimezoneInfo
.DaylightBias
;
1295 memcpy(&TimeZoneInformation
.StandardDate
,
1296 &Entry
->TimezoneInfo
.StandardDate
,
1297 sizeof(SYSTEMTIME
));
1298 memcpy(&TimeZoneInformation
.DaylightDate
,
1299 &Entry
->TimezoneInfo
.DaylightDate
,
1300 sizeof(SYSTEMTIME
));
1302 /* Set time zone information */
1303 SetTimeZoneInformation(&TimeZoneInformation
);
1308 GetLocalSystemTime(HWND hwnd
, PSETUPDATA SetupData
)
1313 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_DATEPICKER
), &Date
) != GDT_VALID
)
1318 if (DateTime_GetSystemtime(GetDlgItem(hwnd
, IDC_TIMEPICKER
), &Time
) != GDT_VALID
)
1323 SetupData
->SystemTime
.wYear
= Date
.wYear
;
1324 SetupData
->SystemTime
.wMonth
= Date
.wMonth
;
1325 SetupData
->SystemTime
.wDayOfWeek
= Date
.wDayOfWeek
;
1326 SetupData
->SystemTime
.wDay
= Date
.wDay
;
1327 SetupData
->SystemTime
.wHour
= Time
.wHour
;
1328 SetupData
->SystemTime
.wMinute
= Time
.wMinute
;
1329 SetupData
->SystemTime
.wSecond
= Time
.wSecond
;
1330 SetupData
->SystemTime
.wMilliseconds
= Time
.wMilliseconds
;
1337 SetAutoDaylightInfo(HWND hwnd
)
1342 if (SendMessage(hwnd
, BM_GETCHECK
, 0, 0) == BST_UNCHECKED
)
1344 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1345 L
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
1351 RegSetValueExW(hKey
,
1352 L
"DisableAutoDaylightTimeSet",
1363 SetSystemLocalTime(HWND hwnd
, PSETUPDATA SetupData
)
1367 TOKEN_PRIVILEGES priv
, previouspriv
;
1371 * enable the SeSystemtimePrivilege privilege
1374 if(OpenProcessToken(GetCurrentProcess(),
1375 TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
,
1378 priv
.PrivilegeCount
= 1;
1379 priv
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1381 if(LookupPrivilegeValue(NULL
,
1383 &priv
.Privileges
[0].Luid
))
1385 if(AdjustTokenPrivileges(hToken
,
1388 sizeof(previouspriv
),
1391 GetLastError() == ERROR_SUCCESS
)
1394 * We successfully enabled it, we're permitted to change the system time
1395 * Call SetLocalTime twice to ensure correct results
1397 Ret
= SetLocalTime(&SetupData
->SystemTime
) &&
1398 SetLocalTime(&SetupData
->SystemTime
);
1401 * for the sake of security, restore the previous status again
1403 if(previouspriv
.PrivilegeCount
> 0)
1405 AdjustTokenPrivileges(hToken
,
1414 CloseHandle(hToken
);
1421 WriteDateTimeSettings(HWND hwndDlg
, PSETUPDATA SetupData
)
1424 WCHAR ErrorLocalTime
[256];
1425 GetLocalSystemTime(hwndDlg
, SetupData
);
1426 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1429 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1430 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1432 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
1434 wcscpy(Title
, L
"ReactOS Setup");
1436 if (0 == LoadStringW(hDllInstance
, IDS_WZD_LOCALTIME
, ErrorLocalTime
,
1437 sizeof(ErrorLocalTime
) / sizeof(ErrorLocalTime
[0])))
1439 wcscpy(ErrorLocalTime
, L
"Setup failed to set the computer name.");
1441 MessageBoxW(hwndDlg
, ErrorLocalTime
, Title
, MB_ICONWARNING
| MB_OK
);
1448 static INT_PTR CALLBACK
1449 DateTimePageDlgProc(HWND hwndDlg
,
1454 PSETUPDATA SetupData
;
1456 WCHAR ErrorLocalTime
[256];
1458 /* Retrieve pointer to the global setup data */
1459 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1465 /* Save pointer to the global setup data */
1466 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1467 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1469 CreateTimeZoneList(SetupData
);
1471 if (SetupData
->UnattendSetup
)
1473 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1474 SetupData
, SetupData
->TimeZoneIndex
);
1476 if (!SetupData
->DisableAutoDaylightTimeSet
)
1478 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1483 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1484 SetupData
, 85 /* GMT time zone */);
1486 SendDlgItemMessage(hwndDlg
, IDC_AUTODAYLIGHT
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
1495 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1500 /* Enable the Back and Next buttons */
1501 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_NEXT
);
1502 if (SetupData
->UnattendSetup
&& WriteDateTimeSettings(hwndDlg
, SetupData
))
1504 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, IDD_PROCESSPAGE
);
1511 GetLocalSystemTime(hwndDlg
, SetupData
);
1512 SetLocalTimeZone(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
),
1514 SetAutoDaylightInfo(GetDlgItem(hwndDlg
, IDC_AUTODAYLIGHT
));
1515 if(!SetSystemLocalTime(hwndDlg
, SetupData
))
1517 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
, Title
, sizeof(Title
) / sizeof(Title
[0])))
1519 wcscpy(Title
, L
"ReactOS Setup");
1521 if (0 == LoadStringW(hDllInstance
, IDS_WZD_LOCALTIME
, ErrorLocalTime
,
1522 sizeof(ErrorLocalTime
) / sizeof(ErrorLocalTime
[0])))
1524 wcscpy(ErrorLocalTime
, L
"Setup failed to set the computer name.");
1526 MessageBoxW(hwndDlg
, ErrorLocalTime
, Title
, MB_ICONWARNING
| MB_OK
);
1532 SetupData
->UnattendSetup
= FALSE
;
1542 DestroyTimeZoneList(SetupData
);
1553 static UINT CALLBACK
1554 RegistrationNotificationProc(PVOID Context
,
1559 PREGISTRATIONDATA RegistrationData
;
1560 REGISTRATIONNOTIFY RegistrationNotify
;
1561 PSP_REGISTER_CONTROL_STATUSW StatusInfo
;
1563 WCHAR ErrorMessage
[128];
1565 RegistrationData
= (PREGISTRATIONDATA
) Context
;
1567 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
||
1568 SPFILENOTIFY_ENDREGISTRATION
== Notification
)
1570 StatusInfo
= (PSP_REGISTER_CONTROL_STATUSW
) Param1
;
1571 RegistrationNotify
.CurrentItem
= wcsrchr(StatusInfo
->FileName
, L
'\\');
1572 if (NULL
== RegistrationNotify
.CurrentItem
)
1574 RegistrationNotify
.CurrentItem
= StatusInfo
->FileName
;
1578 RegistrationNotify
.CurrentItem
++;
1581 if (SPFILENOTIFY_STARTREGISTRATION
== Notification
)
1583 DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
1584 StatusInfo
->FileName
);
1585 RegistrationNotify
.ErrorMessage
= NULL
;
1586 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1590 DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
1591 StatusInfo
->FileName
);
1592 DPRINT("Win32Error %u FailureCode %u\n", StatusInfo
->Win32Error
,
1593 StatusInfo
->FailureCode
);
1594 if (SPREG_SUCCESS
!= StatusInfo
->FailureCode
)
1596 switch(StatusInfo
->FailureCode
)
1598 case SPREG_LOADLIBRARY
:
1599 MessageID
= IDS_LOADLIBRARY_FAILED
;
1601 case SPREG_GETPROCADDR
:
1602 MessageID
= IDS_GETPROCADDR_FAILED
;
1605 MessageID
= IDS_REGSVR_FAILED
;
1607 case SPREG_DLLINSTALL
:
1608 MessageID
= IDS_DLLINSTALL_FAILED
;
1611 MessageID
= IDS_TIMEOUT
;
1614 MessageID
= IDS_REASON_UNKNOWN
;
1617 if (0 == LoadStringW(hDllInstance
, MessageID
,
1619 sizeof(ErrorMessage
) /
1620 sizeof(ErrorMessage
[0])))
1622 ErrorMessage
[0] = L
'\0';
1624 if (SPREG_TIMEOUT
!= StatusInfo
->FailureCode
)
1626 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
1627 StatusInfo
->Win32Error
, 0,
1628 ErrorMessage
+ wcslen(ErrorMessage
),
1629 sizeof(ErrorMessage
) / sizeof(ErrorMessage
[0]) -
1630 wcslen(ErrorMessage
), NULL
);
1632 RegistrationNotify
.ErrorMessage
= ErrorMessage
;
1636 RegistrationNotify
.ErrorMessage
= NULL
;
1638 if (RegistrationData
->Registered
< RegistrationData
->DllCount
)
1640 RegistrationData
->Registered
++;
1644 RegistrationNotify
.Progress
= RegistrationData
->Registered
;
1645 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1646 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1647 0, (LPARAM
) &RegistrationNotify
);
1653 DPRINT1("Received unexpected notification %u\n", Notification
);
1654 return SetupDefaultQueueCallback(RegistrationData
->DefaultContext
,
1655 Notification
, Param1
, Param2
);
1660 static DWORD CALLBACK
1661 RegistrationProc(LPVOID Parameter
)
1663 PREGISTRATIONDATA RegistrationData
;
1664 REGISTRATIONNOTIFY RegistrationNotify
;
1665 DWORD LastError
= NO_ERROR
;
1666 WCHAR UnknownError
[84];
1668 RegistrationData
= (PREGISTRATIONDATA
) Parameter
;
1669 RegistrationData
->Registered
= 0;
1670 RegistrationData
->DefaultContext
= SetupInitDefaultQueueCallback(RegistrationData
->hwndDlg
);
1674 if (!SetupInstallFromInfSectionW(GetParent(RegistrationData
->hwndDlg
),
1676 L
"RegistrationPhase2",
1678 SPINST_REGISTERCALLBACKAWARE
|
1683 RegistrationNotificationProc
,
1688 LastError
= GetLastError();
1691 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1693 DPRINT("Catching exception\n");
1694 LastError
= RtlNtStatusToDosError(_SEH2_GetExceptionCode());
1698 if (NO_ERROR
== LastError
)
1700 RegistrationNotify
.ErrorMessage
= NULL
;
1704 DPRINT1("SetupInstallFromInfSection failed with error %u\n",
1706 if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1707 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, LastError
, 0,
1708 (LPWSTR
) &RegistrationNotify
.ErrorMessage
, 0,
1711 if (0 == LoadStringW(hDllInstance
, IDS_UNKNOWN_ERROR
,
1713 sizeof(UnknownError
) / sizeof(UnknownError
[0] -
1716 wcscpy(UnknownError
, L
"Unknown error");
1718 wcscat(UnknownError
, L
" ");
1719 _ultow(LastError
, UnknownError
+ wcslen(UnknownError
), 10);
1720 RegistrationNotify
.ErrorMessage
= UnknownError
;
1724 RegistrationNotify
.Progress
= RegistrationData
->DllCount
;
1725 RegistrationNotify
.ActivityID
= IDS_REGISTERING_COMPONENTS
;
1726 RegistrationNotify
.CurrentItem
= NULL
;
1727 SendMessage(RegistrationData
->hwndDlg
, PM_REGISTRATION_NOTIFY
,
1728 1, (LPARAM
) &RegistrationNotify
);
1729 if (NULL
!= RegistrationNotify
.ErrorMessage
&&
1730 UnknownError
!= RegistrationNotify
.ErrorMessage
)
1732 LocalFree((PVOID
) RegistrationNotify
.ErrorMessage
);
1735 SetupTermDefaultQueueCallback(RegistrationData
->DefaultContext
);
1736 HeapFree(GetProcessHeap(), 0, RegistrationData
);
1743 StartComponentRegistration(HWND hwndDlg
, PULONG MaxProgress
)
1745 HANDLE RegistrationThread
;
1748 WCHAR SectionName
[512];
1749 PREGISTRATIONDATA RegistrationData
;
1752 if (! SetupFindFirstLineW(hSysSetupInf
, L
"RegistrationPhase2",
1753 L
"RegisterDlls", &Context
))
1755 DPRINT1("No RegistrationPhase2 section found\n");
1758 if (! SetupGetStringFieldW(&Context
, 1, SectionName
,
1759 sizeof(SectionName
) / sizeof(SectionName
[0]),
1762 DPRINT1("Unable to retrieve section name\n");
1765 DllCount
= SetupGetLineCountW(hSysSetupInf
, SectionName
);
1766 DPRINT("SectionName %S DllCount %ld\n", SectionName
, DllCount
);
1769 SetLastError(STATUS_NOT_FOUND
);
1773 *MaxProgress
= (ULONG
) DllCount
;
1776 * Create a background thread to do the actual registrations, so the
1777 * main thread can just run its message loop.
1779 RegistrationThread
= NULL
;
1780 RegistrationData
= HeapAlloc(GetProcessHeap(), 0,
1781 sizeof(REGISTRATIONDATA
));
1782 if (NULL
!= RegistrationData
)
1784 RegistrationData
->hwndDlg
= hwndDlg
;
1785 RegistrationData
->DllCount
= DllCount
;
1786 RegistrationThread
= CreateThread(NULL
, 0, RegistrationProc
,
1787 (LPVOID
) RegistrationData
, 0, NULL
);
1788 if (NULL
!= RegistrationThread
)
1790 CloseHandle(RegistrationThread
);
1794 DPRINT1("CreateThread failed, error %u\n", GetLastError());
1800 DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
1808 static INT_PTR CALLBACK
1809 ProcessPageDlgProc(HWND hwndDlg
,
1814 PSETUPDATA SetupData
;
1815 PREGISTRATIONNOTIFY RegistrationNotify
;
1816 static UINT oldActivityID
= -1;
1819 /* Retrieve pointer to the global setup data */
1820 SetupData
= (PSETUPDATA
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
1826 /* Save pointer to the global setup data */
1827 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1828 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)SetupData
);
1834 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
1835 ULONG MaxProgress
= 0;
1840 /* Disable the Back and Next buttons */
1841 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
1843 StartComponentRegistration(hwndDlg
, &MaxProgress
);
1845 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETRANGE
,
1846 0, MAKELPARAM(0, MaxProgress
));
1847 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1855 SetupData
->UnattendSetup
= FALSE
;
1864 case PM_REGISTRATION_NOTIFY
:
1867 RegistrationNotify
= (PREGISTRATIONNOTIFY
) lParam
;
1868 // update if necessary only
1869 if (oldActivityID
!= RegistrationNotify
->ActivityID
)
1871 if (0 != LoadStringW(hDllInstance
, RegistrationNotify
->ActivityID
,
1873 sizeof(Activity
) / sizeof(Activity
[0])))
1875 SendDlgItemMessageW(hwndDlg
, IDC_ACTIVITY
, WM_SETTEXT
,
1876 0, (LPARAM
) Activity
);
1878 oldActivityID
= RegistrationNotify
->ActivityID
;
1880 SendDlgItemMessageW(hwndDlg
, IDC_ITEM
, WM_SETTEXT
, 0,
1881 (LPARAM
)(NULL
== RegistrationNotify
->CurrentItem
?
1882 L
"" : RegistrationNotify
->CurrentItem
));
1883 SendDlgItemMessage(hwndDlg
, IDC_PROCESSPROGRESS
, PBM_SETPOS
,
1884 RegistrationNotify
->Progress
, 0);
1885 if (NULL
!= RegistrationNotify
->ErrorMessage
)
1887 if (0 == LoadStringW(hDllInstance
, IDS_REACTOS_SETUP
,
1888 Title
, sizeof(Title
) / sizeof(Title
[0])))
1890 wcscpy(Title
, L
"ReactOS Setup");
1892 MessageBoxW(hwndDlg
, RegistrationNotify
->ErrorMessage
,
1893 Title
, MB_ICONERROR
| MB_OK
);
1900 if(!SetupData
->UnattendSetup
&& !SetupData
->DisableVmwInst
)
1901 RunVMWInstall(GetParent(hwndDlg
));
1904 /* Enable the Back and Next buttons */
1905 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
1906 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_NEXT
);
1920 SetInstallationCompleted(VOID
)
1923 DWORD InProgress
= 0;
1926 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1930 &hKey
) == ERROR_SUCCESS
)
1932 RegSetValueExW( hKey
, L
"SystemSetupInProgress", 0, REG_DWORD
, (LPBYTE
)&InProgress
, sizeof(InProgress
) );
1933 RegCloseKey( hKey
);
1936 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
,
1937 L
"Software\\Microsoft\\Windows NT\\CurrentVersion",
1940 &hKey
) == ERROR_SUCCESS
)
1942 InstallDate
= (DWORD
)time(NULL
);
1943 RegSetValueExW( hKey
, L
"InstallDate", 0, REG_DWORD
, (LPBYTE
)&InstallDate
, sizeof(InstallDate
) );
1944 RegCloseKey( hKey
);
1949 static INT_PTR CALLBACK
1950 FinishDlgProc(HWND hwndDlg
,
1960 PSETUPDATA SetupData
;
1962 /* Get pointer to the global setup data */
1963 SetupData
= (PSETUPDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
1965 /* Set title font */
1966 SendDlgItemMessage(hwndDlg
,
1969 (WPARAM
)SetupData
->hTitleFont
,
1971 if (SetupData
->UnattendSetup
)
1973 KillTimer(hwndDlg
, 1);
1974 SetInstallationCompleted();
1982 SetInstallationCompleted();
1992 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
1993 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
1994 if (Position
== 300)
1996 KillTimer(hwndDlg
, 1);
1997 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
2001 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
2008 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
2013 /* Enable the correct buttons on for the active page */
2014 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
2016 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
2017 MAKELPARAM(0, 300));
2018 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETPOS
, 0, 0);
2019 SetTimer(hwndDlg
, 1, 50, NULL
);
2023 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
* szPath
, DWORD dwPathLength
)
2216 WCHAR szDrives
[512];
2217 WCHAR szDrive
[] = L
"D:\\";
2218 DWORD dwLength
, dwIndex
;
2220 dwLength
= GetLogicalDriveStringsW(sizeof(szDrives
) / sizeof(WCHAR
), szDrives
);
2222 if (dwLength
> (sizeof(szDrives
) / sizeof(WCHAR
)) || dwLength
== 0)
2224 /* buffer too small or failure */
2225 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"GetLogicalDriveStringsW failed");
2230 for (dwIndex
= 0; dwIndex
< dwLength
; dwIndex
++)
2232 szDrive
[0] = pDrive
[dwIndex
];
2233 if (GetDriveTypeW(szDrive
) == DRIVE_CDROM
)
2235 WCHAR szBuffer
[MAX_PATH
];
2236 wcscpy(szBuffer
, szDrive
);
2237 wcscat(szBuffer
, L
"reactos\\ntoskrnl.exe");
2238 LogItem(SYSSETUP_SEVERITY_INFORMATION
, szBuffer
);
2239 if (FileExists(szBuffer
, NULL
))
2241 wcsncpy(szPath
, szDrive
, dwPathLength
);
2250 ProcessUnattendSetup()
2252 WCHAR szPath
[MAX_PATH
];
2253 HINF hUnattendedInf
;
2256 if (!GetRosInstallCD(szPath
, MAX_PATH
))
2258 /* no cd drive found */
2262 dwLength
= wcslen(szPath
);
2263 if (dwLength
+ 21 > MAX_PATH
)
2266 * allocate bigger buffer
2271 wcscat(szPath
, L
"reactos\\unattend.inf");
2273 hUnattendedInf
= SetupOpenInfFileW(szPath
,
2278 if (hUnattendedInf
!= INVALID_HANDLE_VALUE
)
2280 SetupData
.UnattendSetup
= ProcessUnattendInf(hUnattendedInf
);
2281 SetupCloseInfFile(hUnattendedInf
);
2289 PROPSHEETHEADER psh
;
2290 HPROPSHEETPAGE ahpsp
[8];
2291 PROPSHEETPAGE psp
= {0};
2296 /* Clear setup data */
2297 ZeroMemory(&SetupData
, sizeof(SETUPDATA
));
2299 ProcessUnattendSetup();
2302 /* Create the Welcome page */
2303 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
2304 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2305 psp
.hInstance
= hDllInstance
;
2306 psp
.lParam
= (LPARAM
)&SetupData
;
2307 psp
.pfnDlgProc
= WelcomeDlgProc
;
2308 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_WELCOMEPAGE
);
2309 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2311 /* Create the Acknowledgements page */
2312 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2313 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_ACKTITLE
);
2314 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_ACKSUBTITLE
);
2315 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_ACKPAGE
);
2316 psp
.pfnDlgProc
= AckPageDlgProc
;
2317 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2319 /* Create the Owner page */
2320 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2321 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_OWNERTITLE
);
2322 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_OWNERSUBTITLE
);
2323 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_OWNERPAGE
);
2324 psp
.pfnDlgProc
= OwnerPageDlgProc
;
2325 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2327 /* Create the Computer page */
2328 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2329 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_COMPUTERTITLE
);
2330 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_COMPUTERSUBTITLE
);
2331 psp
.pfnDlgProc
= ComputerPageDlgProc
;
2332 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_COMPUTERPAGE
);
2333 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2336 /* Create the Locale page */
2337 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2338 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LOCALETITLE
);
2339 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LOCALESUBTITLE
);
2340 psp
.pfnDlgProc
= LocalePageDlgProc
;
2341 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LOCALEPAGE
);
2342 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2345 /* Create the DateTime page */
2346 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2347 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DATETIMETITLE
);
2348 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DATETIMESUBTITLE
);
2349 psp
.pfnDlgProc
= DateTimePageDlgProc
;
2350 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DATETIMEPAGE
);
2351 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2354 /* Create the Process page */
2355 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
2356 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
2357 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
2358 psp
.pfnDlgProc
= ProcessPageDlgProc
;
2359 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
2360 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2363 /* Create the Finish page */
2364 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
2365 psp
.pfnDlgProc
= FinishDlgProc
;
2366 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
2367 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
2369 /* Create the property sheet */
2370 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
2371 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
| PSH_MODELESS
;
2372 psh
.hInstance
= hDllInstance
;
2373 psh
.hwndParent
= NULL
;
2374 psh
.nPages
= nPages
;
2377 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
2378 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
2380 /* Create title font */
2381 SetupData
.hTitleFont
= CreateTitleFont();
2383 /* Display the wizard */
2384 hWnd
= (HWND
)PropertySheet(&psh
);
2385 ShowWindow(hWnd
, SW_SHOW
);
2387 while (GetMessage(&msg
, NULL
, 0, 0))
2389 if(!IsDialogMessage(hWnd
, &msg
))
2391 TranslateMessage(&msg
);
2392 DispatchMessage(&msg
);
2396 DeleteObject(SetupData
.hTitleFont
);