3 * Copyright (C) 2004-2008 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS GUI first stage setup application
23 * FILE: base/setup/reactos/reactos.c
24 * PROGRAMMERS: Eric Kohl
26 * Dmitry Chapyshev (dmitry@reactos.org)
35 #include <wine/unicode.h>
39 /* GLOBALS ******************************************************************/
49 typedef struct _KBLAYOUT
52 TCHAR LayoutName
[128];
54 } KBLAYOUT
, *PKBLAYOUT
;
57 // generic entries with simple 1:1 mapping
58 typedef struct _GENENTRY
62 } GENENTRY
, *PGENENTRY
;
67 LONG DestDiskNumber
; // physical disk
68 LONG DestPartNumber
; // partition on disk
69 LONG DestPartSize
; // if partition doesn't exist, size of partition
70 LONG FSType
; // file system type on partition
71 LONG MBRInstallType
; // install bootloader
72 LONG FormatPart
; // type of format the partition
73 LONG SelectedLangId
; // selected language (table index)
74 LONG SelectedKBLayout
; // selected keyboard layout (table index)
75 TCHAR InstallDir
[MAX_PATH
]; // installation directory on hdd
76 LONG SelectedComputer
; // selected computer type (table index)
77 LONG SelectedDisplay
; // selected display type (table index)
78 LONG SelectedKeyboard
; // selected keyboard type (table index)
79 BOOLEAN RepairUpdateFlag
; // flag for update/repair an installed reactos
81 LONG DefaultLang
; // default language (table index)
84 LONG DefaultKBLayout
; // default keyboard layout (table index)
95 typedef struct _IMGINFO
100 } IMGINFO
, *PIMGINFO
;
102 TCHAR abort_msg
[512], abort_title
[64];
106 LONG
LoadGenentry(HINF hinf
,PCTSTR name
,PGENENTRY
*gen
,PINFCONTEXT context
);
108 /* FUNCTIONS ****************************************************************/
111 CenterWindow(HWND hWnd
)
117 hWndParent
= GetParent(hWnd
);
118 if (hWndParent
== NULL
)
119 hWndParent
= GetDesktopWindow();
121 GetWindowRect(hWndParent
, &rcParent
);
122 GetWindowRect(hWnd
, &rcWindow
);
126 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
127 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
134 CreateTitleFont(VOID
)
136 NONCLIENTMETRICS ncm
;
142 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
143 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
145 LogFont
= ncm
.lfMessageFont
;
146 LogFont
.lfWeight
= FW_BOLD
;
147 _tcscpy(LogFont
.lfFaceName
, _T("MS Shell Dlg"));
151 LogFont
.lfHeight
= 0 - GetDeviceCaps (hdc
, LOGPIXELSY
) * FontSize
/ 72;
152 hFont
= CreateFontIndirect(&LogFont
);
153 ReleaseDC(NULL
, hdc
);
159 InitImageInfo(PIMGINFO ImgInfo
)
163 ZeroMemory(ImgInfo
, sizeof(*ImgInfo
));
165 ImgInfo
->hBitmap
= LoadImage(hInstance
,
166 MAKEINTRESOURCE(IDB_ROSLOGO
),
172 if (ImgInfo
->hBitmap
!= NULL
)
174 GetObject(ImgInfo
->hBitmap
, sizeof(BITMAP
), &bitmap
);
176 ImgInfo
->cxSource
= bitmap
.bmWidth
;
177 ImgInfo
->cySource
= bitmap
.bmHeight
;
181 static INT_PTR CALLBACK
182 StartDlgProc(HWND hwndDlg
,
194 hwndControl
= GetParent(hwndDlg
);
196 /* Center the wizard window */
197 CenterWindow (hwndControl
);
199 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
200 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
202 /* Hide and disable the 'Cancel' button at the moment,
203 * we use this button to cancel the setup process
206 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
207 ShowWindow (hwndControl
, SW_HIDE
);
208 EnableWindow (hwndControl
, FALSE
);
211 SendDlgItemMessage(hwndDlg
,
221 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
226 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
242 static INT_PTR CALLBACK
243 LangSelDlgProc(HWND hwndDlg
,
253 pImgInfo
= (PIMGINFO
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
262 hwndControl
= GetParent(hwndDlg
);
264 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
265 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
267 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
268 ShowWindow (hwndControl
, SW_SHOW
);
269 EnableWindow (hwndControl
, TRUE
);
271 pImgInfo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IMGINFO
));
272 if (pImgInfo
== NULL
)
274 EndDialog(hwndDlg
, 0);
278 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pImgInfo
);
280 InitImageInfo(pImgInfo
);
283 /*SendDlgItemMessage(hwndDlg,
289 hList
= GetDlgItem(hwndDlg
, IDC_LANGUAGES
);
291 for (i
=0; i
< SetupData
.LangCount
; i
++)
293 tindex
= SendMessage(hList
, CB_ADDSTRING
, (WPARAM
) 0, (LPARAM
) SetupData
.pLanguages
[i
].LangName
);
294 SendMessage(hList
, CB_SETITEMDATA
, tindex
, i
);
295 if (SetupData
.DefaultLang
== i
)
296 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
) tindex
,(LPARAM
) 0);
299 hList
= GetDlgItem(hwndDlg
, IDC_KEYLAYOUT
);
301 for (i
=0; i
< SetupData
.KbLayoutCount
; i
++)
303 tindex
= SendMessage(hList
, CB_ADDSTRING
, (WPARAM
) 0, (LPARAM
)SetupData
.pKbLayouts
[i
].LayoutName
);
304 SendMessage(hList
, CB_SETITEMDATA
, tindex
, i
);
305 if (SetupData
.DefaultKBLayout
== i
)
306 SendMessage(hList
,CB_SETCURSEL
,(WPARAM
)tindex
,(LPARAM
)0);
313 LPDRAWITEMSTRUCT lpDrawItem
;
314 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
316 if (lpDrawItem
->CtlID
== IDB_ROSLOGO
)
321 /* position image in centre of dialog */
322 left
= (lpDrawItem
->rcItem
.right
- pImgInfo
->cxSource
) / 2;
324 hdcMem
= CreateCompatibleDC(lpDrawItem
->hDC
);
327 SelectObject(hdcMem
, pImgInfo
->hBitmap
);
328 BitBlt(lpDrawItem
->hDC
,
330 lpDrawItem
->rcItem
.top
,
331 lpDrawItem
->rcItem
.right
- lpDrawItem
->rcItem
.left
,
332 lpDrawItem
->rcItem
.bottom
- lpDrawItem
->rcItem
.top
,
345 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
350 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
353 case PSN_QUERYCANCEL
:
354 SetWindowLongPtr(hwndDlg
,
356 MessageBox(GetParent(hwndDlg
),
359 MB_YESNO
| MB_ICONQUESTION
) != IDYES
);
362 case PSN_WIZNEXT
: // set the selected data
364 hList
=GetDlgItem(hwndDlg
, IDC_LANGUAGES
);
365 tindex
= SendMessage(hList
,CB_GETCURSEL
, (WPARAM
)0, (LPARAM
)0);
367 if (tindex
!= CB_ERR
)
370 SetupData
.SelectedLangId
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
) tindex
, (LPARAM
) 0);
371 LangID
= _tcstol(SetupData
.pLanguages
[SetupData
.SelectedLangId
].LangId
, NULL
, 16);
372 SetThreadLocale(MAKELCID(LangID
, SORT_DEFAULT
));
373 // FIXME: need to reload all resource to force
374 // the new language setting
377 hList
= GetDlgItem(hwndDlg
, IDC_KEYLAYOUT
);
378 tindex
= SendMessage(hList
,CB_GETCURSEL
, (WPARAM
)0, (LPARAM
)0);
379 if (tindex
!= CB_ERR
)
381 SetupData
.SelectedKBLayout
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
) tindex
, (LPARAM
) 0);
399 static INT_PTR CALLBACK
400 TypeDlgProc(HWND hwndDlg
,
412 hwndControl
= GetParent(hwndDlg
);
414 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
415 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
417 CheckDlgButton(hwndDlg
, IDC_INSTALL
, BST_CHECKED
);
420 /*SendDlgItemMessage(hwndDlg,
430 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
435 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
438 case PSN_QUERYCANCEL
:
439 SetWindowLongPtr(hwndDlg
,
441 MessageBox(GetParent(hwndDlg
),
444 MB_YESNO
| MB_ICONQUESTION
) != IDYES
);
447 case PSN_WIZNEXT
: // set the selected data
448 SetupData
.RepairUpdateFlag
= !(SendMessage(GetDlgItem(hwndDlg
, IDC_INSTALL
),
451 (LPARAM
) 0) == BST_CHECKED
);
467 static INT_PTR CALLBACK
468 DeviceDlgProc(HWND hwndDlg
,
484 hwndControl
= GetParent(hwndDlg
);
486 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
487 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
490 /*SendDlgItemMessage(hwndDlg,
496 hList
= GetDlgItem(hwndDlg
, IDC_COMPUTER
);
498 for (i
=0; i
< SetupData
.CompCount
; i
++)
500 tindex
= SendMessage(hList
, CB_ADDSTRING
, (WPARAM
) 0, (LPARAM
) SetupData
.pComputers
[i
].Value
);
501 SendMessage(hList
, CB_SETITEMDATA
, tindex
, i
);
503 SendMessage(hList
, CB_SETCURSEL
, 0, 0); // set first as default
505 hList
= GetDlgItem(hwndDlg
, IDC_DISPLAY
);
507 for (i
=0; i
< SetupData
.DispCount
; i
++)
509 tindex
= SendMessage(hList
, CB_ADDSTRING
, (WPARAM
) 0, (LPARAM
) SetupData
.pDisplays
[i
].Value
);
510 SendMessage(hList
, CB_SETITEMDATA
, tindex
, i
);
512 SendMessage(hList
, CB_SETCURSEL
, 0, 0); // set first as default
514 hList
= GetDlgItem(hwndDlg
, IDC_KEYBOARD
);
516 for (i
=0; i
< SetupData
.KeybCount
; i
++)
518 tindex
= SendMessage(hList
,CB_ADDSTRING
,(WPARAM
)0,(LPARAM
)SetupData
.pKeyboards
[i
].Value
);
519 SendMessage(hList
,CB_SETITEMDATA
,tindex
,i
);
521 SendMessage(hList
,CB_SETCURSEL
,0,0); // set first as default
527 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
532 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
535 case PSN_QUERYCANCEL
:
536 SetWindowLongPtr(hwndDlg
,
538 MessageBox(GetParent(hwndDlg
),
541 MB_YESNO
| MB_ICONQUESTION
) != IDYES
);
544 case PSN_WIZNEXT
: // set the selected data
546 hList
= GetDlgItem(hwndDlg
, IDC_COMPUTER
);
548 tindex
= SendMessage(hList
, CB_GETCURSEL
, (WPARAM
) 0, (LPARAM
) 0);
549 if (tindex
!= CB_ERR
)
551 SetupData
.SelectedComputer
= SendMessage(hList
,
557 hList
= GetDlgItem(hwndDlg
, IDC_DISPLAY
);
559 tindex
= SendMessage(hList
, CB_GETCURSEL
, (WPARAM
) 0, (LPARAM
) 0);
560 if (tindex
!= CB_ERR
)
562 SetupData
.SelectedDisplay
= SendMessage(hList
,
568 hList
=GetDlgItem(hwndDlg
, IDC_KEYBOARD
);
570 tindex
= SendMessage(hList
, CB_GETCURSEL
, (WPARAM
) 0, (LPARAM
) 0);
571 if (tindex
!= CB_ERR
)
573 SetupData
.SelectedKeyboard
= SendMessage(hList
,
594 static INT_PTR CALLBACK
595 MoreOptDlgProc(HWND hwndDlg
,
604 CheckDlgButton(hwndDlg
, IDC_INSTFREELDR
, BST_CHECKED
);
605 SendMessage(GetDlgItem(hwndDlg
, IDC_PATH
),
608 (LPARAM
) SetupData
.InstallDir
);
614 switch(LOWORD(wParam
))
618 SendMessage(GetDlgItem(hwndDlg
, IDC_PATH
),
620 (WPARAM
) sizeof(SetupData
.InstallDir
) / sizeof(TCHAR
),
621 (LPARAM
) SetupData
.InstallDir
);
623 EndDialog(hwndDlg
, IDOK
);
629 EndDialog(hwndDlg
, IDCANCEL
);
639 static INT_PTR CALLBACK
640 PartitionDlgProc(HWND hwndDlg
,
651 switch(LOWORD(wParam
))
654 EndDialog(hwndDlg
, IDOK
);
657 EndDialog(hwndDlg
, IDCANCEL
);
665 static INT_PTR CALLBACK
666 DriveDlgProc(HWND hwndDlg
,
674 SP_DEVINFO_DATA DevInfoData
;
684 hwndControl
= GetParent(hwndDlg
);
686 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
687 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
690 /*SendDlgItemMessage(hwndDlg,
696 h
= SetupDiGetClassDevs(&GUID_DEVCLASS_DISKDRIVE
, NULL
, NULL
, DIGCF_PRESENT
);
697 if (h
!= INVALID_HANDLE_VALUE
)
699 hList
=GetDlgItem(hwndDlg
, IDC_PARTITION
);
700 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
701 for (i
=0; SetupDiEnumDeviceInfo(h
, i
, &DevInfoData
); i
++)
704 LPTSTR buffer
= NULL
;
705 DWORD buffersize
= 0;
707 while (!SetupDiGetDeviceRegistryProperty(h
,
715 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
717 if (buffer
) LocalFree(buffer
);
718 buffer
= LocalAlloc(LPTR
, buffersize
* 2);
725 SendMessage(hList
, LB_ADDSTRING
, (WPARAM
) 0, (LPARAM
) buffer
);
729 SetupDiDestroyDeviceInfoList(h
);
737 switch(LOWORD(wParam
))
739 case IDC_PARTMOREOPTS
:
741 MAKEINTRESOURCE(IDD_BOOTOPTIONS
),
743 (DLGPROC
) MoreOptDlgProc
);
747 MAKEINTRESOURCE(IDD_PARTITION
),
749 (DLGPROC
) PartitionDlgProc
);
759 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
764 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
767 case PSN_QUERYCANCEL
:
768 SetWindowLongPtr(hwndDlg
,
770 MessageBox(GetParent(hwndDlg
),
773 MB_YESNO
| MB_ICONQUESTION
) != IDYES
);
790 static INT_PTR CALLBACK
791 SummaryDlgProc(HWND hwndDlg
,
803 hwndControl
= GetParent(hwndDlg
);
805 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
806 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
809 /*SendDlgItemMessage(hwndDlg,
819 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
824 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
827 case PSN_QUERYCANCEL
:
828 SetWindowLongPtr(hwndDlg
,
830 MessageBox(GetParent(hwndDlg
),
833 MB_YESNO
| MB_ICONQUESTION
) != IDYES
);
848 static INT_PTR CALLBACK
849 ProcessDlgProc(HWND hwndDlg
,
861 hwndControl
= GetParent(hwndDlg
);
863 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
864 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
867 /*SendDlgItemMessage(hwndDlg,
877 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
882 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
883 // disable all buttons during installation process
884 // PropSheet_SetWizButtons(GetParent(hwndDlg), 0 );
886 case PSN_QUERYCANCEL
:
887 SetWindowLongPtr(hwndDlg
,
889 MessageBox(GetParent(hwndDlg
),
892 MB_YESNO
| MB_ICONQUESTION
) != IDYES
);
908 static INT_PTR CALLBACK
909 RestartDlgProc(HWND hwndDlg
,
921 hwndControl
= GetParent(hwndDlg
);
923 dwStyle
= GetWindowLongPtr(hwndControl
, GWL_STYLE
);
924 SetWindowLongPtr(hwndControl
, GWL_STYLE
, dwStyle
& ~WS_SYSMENU
);
926 hwndControl
= GetDlgItem(GetParent(hwndDlg
), IDCANCEL
);
927 ShowWindow(hwndControl
, SW_HIDE
);
928 EnableWindow(hwndControl
, FALSE
);
931 /*SendDlgItemMessage(hwndDlg,
944 hWndProgress
= GetDlgItem(hwndDlg
, IDC_RESTART_PROGRESS
);
945 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
948 KillTimer(hwndDlg
, 1);
949 PropSheet_PressButton(GetParent(hwndDlg
), PSBTN_FINISH
);
953 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
963 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
967 case PSN_SETACTIVE
: // Only "Finish" for closing the App
969 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
970 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0, MAKELPARAM(0, 300));
971 SendDlgItemMessage(hwndDlg
, IDC_RESTART_PROGRESS
, PBM_SETPOS
, 0, 0);
972 SetTimer(hwndDlg
, 1, 50, NULL
);
992 WCHAR szPath
[MAX_PATH
];
996 INFCONTEXT InfContext
;
997 //TCHAR szValue[MAX_PATH];
1001 GetModuleFileNameW(NULL
,szPath
,MAX_PATH
);
1002 ch
= strrchrW(szPath
,L
'\\');
1006 wcscat(szPath
, L
"\\txtsetup.sif");
1007 hTxtsetupSif
= SetupOpenInfFileW(szPath
, NULL
, INF_STYLE_OLDNT
, NULL
);
1008 if (hTxtsetupSif
!= INVALID_HANDLE_VALUE
)
1010 // get language list
1011 SetupData
.LangCount
= SetupGetLineCount(hTxtsetupSif
, _T("Language"));
1012 if (SetupData
.LangCount
> 0)
1014 SetupData
.pLanguages
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LANG
) * SetupData
.LangCount
);
1015 if (SetupData
.pLanguages
!= NULL
)
1018 if (SetupFindFirstLine(hTxtsetupSif
, _T("Language"), NULL
, &InfContext
))
1022 SetupGetStringField(&InfContext
,
1024 SetupData
.pLanguages
[Count
].LangId
,
1025 sizeof(SetupData
.pLanguages
[Count
].LangId
) / sizeof(TCHAR
),
1028 SetupGetStringField(&InfContext
,
1030 SetupData
.pLanguages
[Count
].LangName
,
1031 sizeof(SetupData
.pLanguages
[Count
].LangName
) / sizeof(TCHAR
),
1035 while (SetupFindNextLine(&InfContext
, &InfContext
) && Count
< SetupData
.LangCount
);
1040 // get keyboard layout list
1041 SetupData
.KbLayoutCount
= SetupGetLineCount(hTxtsetupSif
, _T("KeyboardLayout"));
1042 if (SetupData
.KbLayoutCount
> 0)
1044 SetupData
.pKbLayouts
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(KBLAYOUT
) * SetupData
.KbLayoutCount
);
1045 if (SetupData
.pKbLayouts
!= NULL
)
1048 if (SetupFindFirstLine(hTxtsetupSif
, _T("KeyboardLayout"), NULL
, &InfContext
))
1052 SetupGetStringField(&InfContext
,
1054 SetupData
.pKbLayouts
[Count
].LayoutId
,
1055 sizeof(SetupData
.pKbLayouts
[Count
].LayoutId
) / sizeof(TCHAR
),
1058 SetupGetStringField(&InfContext
,
1060 SetupData
.pKbLayouts
[Count
].LayoutName
,
1061 sizeof(SetupData
.pKbLayouts
[Count
].LayoutName
) / sizeof(TCHAR
),
1065 while (SetupFindNextLine(&InfContext
, &InfContext
) && Count
< SetupData
.KbLayoutCount
);
1070 // get default for keyboard and language
1071 SetupData
.DefaultKBLayout
= -1;
1072 SetupData
.DefaultLang
= -1;
1074 // TODO: get defaults from underlaying running system
1075 if (SetupFindFirstLine(hTxtsetupSif
, _T("NLS"), _T("DefaultLayout"), &InfContext
))
1077 SetupGetStringField(&InfContext
, 1, tmp
, sizeof(tmp
) / sizeof(TCHAR
), &LineLength
);
1078 for (Count
= 0; Count
< SetupData
.KbLayoutCount
; Count
++)
1079 if (_tcscmp(tmp
, SetupData
.pKbLayouts
[Count
].LayoutId
) == 0)
1081 SetupData
.DefaultKBLayout
= Count
;
1086 if (SetupFindFirstLine(hTxtsetupSif
, _T("NLS"), _T("DefaultLanguage"), &InfContext
))
1088 SetupGetStringField(&InfContext
, 1, tmp
, sizeof(tmp
) / sizeof(TCHAR
), &LineLength
);
1089 for (Count
= 0; Count
< SetupData
.LangCount
; Count
++)
1090 if (_tcscmp(tmp
, SetupData
.pLanguages
[Count
].LangId
) == 0)
1092 SetupData
.DefaultLang
= Count
;
1097 // get computers list
1098 SetupData
.CompCount
= LoadGenentry(hTxtsetupSif
,_T("Computer"),&SetupData
.pComputers
,&InfContext
);
1101 SetupData
.DispCount
= LoadGenentry(hTxtsetupSif
,_T("Display"),&SetupData
.pDisplays
,&InfContext
);
1103 // get keyboard list
1104 SetupData
.KeybCount
= LoadGenentry(hTxtsetupSif
, _T("Keyboard"),&SetupData
.pKeyboards
,&InfContext
);
1106 // get install directory
1107 if (SetupFindFirstLine(hTxtsetupSif
, _T("SetupData"), _T("DefaultPath"), &InfContext
))
1109 SetupGetStringField(&InfContext
,
1111 SetupData
.InstallDir
,
1112 sizeof(SetupData
.InstallDir
) / sizeof(TCHAR
),
1115 SetupCloseInfFile(hTxtsetupSif
);
1119 LONG
LoadGenentry(HINF hinf
,PCTSTR name
,PGENENTRY
*gen
,PINFCONTEXT context
)
1124 TotalCount
= SetupGetLineCount(hinf
, name
);
1127 *gen
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GENENTRY
) * TotalCount
);
1130 if (SetupFindFirstLine(hinf
, name
, NULL
, context
))
1135 SetupGetStringField(context
,
1138 sizeof((*gen
)[Count
].Id
) / sizeof(TCHAR
),
1141 SetupGetStringField(context
,
1143 (*gen
)[Count
].Value
,
1144 sizeof((*gen
)[Count
].Value
) / sizeof(TCHAR
),
1148 while (SetupFindNextLine(context
, context
) && Count
< TotalCount
);
1156 BOOL
isUnattendSetup()
1158 WCHAR szPath
[MAX_PATH
];
1160 HINF hUnattendedInf
;
1161 INFCONTEXT InfContext
;
1162 TCHAR szValue
[MAX_PATH
];
1167 GetModuleFileNameW(NULL
, szPath
, MAX_PATH
);
1168 ch
= strrchrW(szPath
, L
'\\');
1172 wcscat(szPath
, L
"\\unattend.inf");
1173 hUnattendedInf
= SetupOpenInfFileW(szPath
, NULL
, INF_STYLE_OLDNT
, NULL
);
1175 if (hUnattendedInf
!= INVALID_HANDLE_VALUE
)
1177 if (SetupFindFirstLine(hUnattendedInf
, _T("Unattend"), _T("UnattendSetupEnabled"),&InfContext
))
1179 if (SetupGetStringField(&InfContext
,
1182 sizeof(szValue
) / sizeof(TCHAR
),
1183 &LineLength
) && (_tcsicmp(szValue
, _T("yes")) == 0))
1185 result
= 1; // unattendSetup enabled
1186 // read values and store in SetupData
1189 SetupCloseInfFile(hUnattendedInf
);
1196 _tWinMain(HINSTANCE hInst
,
1197 HINSTANCE hPrevInstance
,
1201 PROPSHEETHEADER psh
;
1202 HPROPSHEETPAGE ahpsp
[8];
1203 PROPSHEETPAGE psp
= {0};
1206 isUnattend
= isUnattendSetup();
1208 LoadString(hInst
,IDS_ABORTSETUP
, abort_msg
, sizeof(abort_msg
)/sizeof(TCHAR
));
1209 LoadString(hInst
,IDS_ABORTSETUP2
, abort_title
,sizeof(abort_title
)/sizeof(TCHAR
));
1215 /* Create the Start page, until setup is working */
1216 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1217 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
1218 psp
.hInstance
= hInst
;
1220 psp
.pfnDlgProc
= StartDlgProc
;
1221 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_STARTPAGE
);
1222 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1224 /* Create language selection page */
1225 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1226 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1227 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_LANGTITLE
);
1228 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_LANGSUBTITLE
);
1229 psp
.hInstance
= hInst
;
1231 psp
.pfnDlgProc
= LangSelDlgProc
;
1232 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_LANGSELPAGE
);
1233 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1235 /* Create install type selection page */
1236 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1237 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1238 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_TYPETITLE
);
1239 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_TYPESUBTITLE
);
1240 psp
.hInstance
= hInst
;
1242 psp
.pfnDlgProc
= TypeDlgProc
;
1243 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_TYPEPAGE
);
1244 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1246 /* Create device settings page */
1247 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1248 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1249 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DEVICETITLE
);
1250 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DEVICESUBTITLE
);
1251 psp
.hInstance
= hInst
;
1253 psp
.pfnDlgProc
= DeviceDlgProc
;
1254 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DEVICEPAGE
);
1255 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1257 /* Create install device settings page / boot method / install directory */
1258 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1259 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1260 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_DRIVETITLE
);
1261 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_DRIVESUBTITLE
);
1262 psp
.hInstance
= hInst
;
1264 psp
.pfnDlgProc
= DriveDlgProc
;
1265 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_DRIVEPAGE
);
1266 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1268 /* Create summary page */
1269 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1270 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1271 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_SUMMARYTITLE
);
1272 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_SUMMARYSUBTITLE
);
1273 psp
.hInstance
= hInst
;
1275 psp
.pfnDlgProc
= SummaryDlgProc
;
1276 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_SUMMARYPAGE
);
1277 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1280 /* Create installation progress page */
1281 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1282 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1283 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROCESSTITLE
);
1284 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_PROCESSSUBTITLE
);
1285 psp
.hInstance
= hInst
;
1287 psp
.pfnDlgProc
= ProcessDlgProc
;
1288 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROCESSPAGE
);
1289 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1291 /* Create finish to reboot page */
1292 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
1293 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
1294 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_RESTARTTITLE
);
1295 psp
.pszHeaderSubTitle
= MAKEINTRESOURCE(IDS_RESTARTSUBTITLE
);
1296 psp
.hInstance
= hInst
;
1298 psp
.pfnDlgProc
= RestartDlgProc
;
1299 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_RESTARTPAGE
);
1300 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
1302 /* Create the property sheet */
1303 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
1304 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
;
1305 psh
.hInstance
= hInst
;
1306 psh
.hwndParent
= NULL
;
1307 psh
.nPages
= nPages
;
1310 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
1311 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
1313 /* Create title font */
1314 hTitleFont
= CreateTitleFont();
1316 /* Display the wizard */
1317 PropertySheet(&psh
);
1319 DeleteObject(hTitleFont
);