2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Userinit Logon Application
4 * FILE: base/system/userinit/livecd.c
5 * PROGRAMMERS: Eric Kohl
15 InitImageInfo(PIMGINFO ImgInfo
)
19 ZeroMemory(ImgInfo
, sizeof(*ImgInfo
));
21 ImgInfo
->hBitmap
= LoadImage(hInstance
,
22 MAKEINTRESOURCE(IDB_ROSLOGO
),
28 if (ImgInfo
->hBitmap
!= NULL
)
30 GetObject(ImgInfo
->hBitmap
, sizeof(BITMAP
), &bitmap
);
32 ImgInfo
->cxSource
= bitmap
.bmWidth
;
33 ImgInfo
->cySource
= bitmap
.bmHeight
;
41 HKEY ControlKey
= NULL
;
42 LPWSTR SystemStartOptions
= NULL
;
43 LPWSTR CurrentOption
, NextOption
; /* Pointers into SystemStartOptions */
47 TRACE("IsLiveCD()\n");
49 rc
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
50 REGSTR_PATH_CURRENT_CONTROL_SET
,
54 if (rc
!= ERROR_SUCCESS
)
56 WARN("RegOpenKeyEx() failed with error %lu\n", rc
);
60 rc
= ReadRegSzKey(ControlKey
, L
"SystemStartOptions", &SystemStartOptions
);
61 if (rc
!= ERROR_SUCCESS
)
63 WARN("ReadRegSzKey() failed with error %lu\n", rc
);
67 /* Check for CONSOLE switch in SystemStartOptions */
68 CurrentOption
= SystemStartOptions
;
71 NextOption
= wcschr(CurrentOption
, L
' ');
74 if (_wcsicmp(CurrentOption
, L
"MININT") == 0)
76 TRACE("Found 'MININT' boot option\n");
80 CurrentOption
= NextOption
? NextOption
+ 1 : NULL
;
84 if (ControlKey
!= NULL
)
85 RegCloseKey(ControlKey
);
86 HeapFree(GetProcessHeap(), 0, SystemStartOptions
);
88 TRACE("IsLiveCD() returning %d\n", ret
);
95 LocalesEnumProc(LPTSTR lpLocale
)
100 BOOL bNoShow
= FALSE
;
102 lcid
= wcstoul(lpLocale
, NULL
, 16);
104 /* Display only languages with installed support */
105 if (!IsValidLocale(lcid
, LCID_INSTALLED
))
108 if (lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH
), SORT_DEFAULT
) ||
109 lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH_MODERN
), SORT_DEFAULT
))
113 LoadStringW(hInstance
, IDS_SPAIN
, lang
, 255);
123 GetLocaleInfoW(lcid
, LOCALE_SLANGUAGE
, lang
, sizeof(lang
)/sizeof(WCHAR
));
126 if (bNoShow
== FALSE
)
128 index
= SendMessageW(hList
,
144 CreateLanguagesList(HWND hwnd
)
150 EnumSystemLocalesW(LocalesEnumProc
, LCID_SUPPORTED
);
152 /* Select current locale */
153 /* or should it be System and not user? */
154 GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_SLANGUAGE
, langSel
, sizeof(langSel
)/sizeof(WCHAR
));
171 WCHAR szBuf
[MAX_PATH
], szDispName
[MAX_PATH
], szIndex
[MAX_PATH
], szPath
[MAX_PATH
];
175 wsprintf(szBuf
, L
"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s", szLCID
);
177 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, (LPCTSTR
)szBuf
, 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
179 dwBufLen
= sizeof(szBuf
);
181 if (RegQueryValueExW(hKey
, L
"Layout Display Name", NULL
, NULL
, (LPBYTE
)szDispName
, &dwBufLen
) == ERROR_SUCCESS
)
183 if (szDispName
[0] == '@')
185 for (i
= 0; i
< wcslen(szDispName
); i
++)
187 if ((szDispName
[i
] == ',') && (szDispName
[i
+ 1] == '-'))
189 for (j
= i
+ 2, k
= 0; j
< wcslen(szDispName
)+1; j
++, k
++)
191 szIndex
[k
] = szDispName
[j
];
193 szDispName
[i
- 1] = '\0';
197 szDispName
[i
] = szDispName
[i
+ 1];
200 if (ExpandEnvironmentStringsW(szDispName
, szPath
, MAX_PATH
))
202 hLib
= LoadLibraryW(szPath
);
205 if (LoadStringW(hLib
, _wtoi(szIndex
), szPath
, sizeof(szPath
) / sizeof(WCHAR
)) != 0)
207 wcscpy(szName
, szPath
);
217 dwBufLen
= sizeof(szBuf
);
219 if (RegQueryValueExW(hKey
, L
"Layout Text", NULL
, NULL
, (LPBYTE
)szName
, &dwBufLen
) == ERROR_SUCCESS
)
240 iCurSel
= SendMessageW(hwnd
, CB_GETCURSEL
, 0, 0);
241 if (iCurSel
== CB_ERR
)
244 ulLayoutId
= (ULONG
)SendMessageW(hwnd
, CB_GETITEMDATA
, iCurSel
, 0);
245 if (ulLayoutId
== (ULONG
)CB_ERR
)
248 swprintf(szLayoutId
, L
"%08lx", ulLayoutId
);
250 hKl
= LoadKeyboardLayoutW(szLayoutId
, KLF_ACTIVATE
| KLF_REPLACELANG
| KLF_SETFORPROCESS
);
251 SystemParametersInfoW(SPI_SETDEFAULTINPUTLANG
, 0, &hKl
, SPIF_SENDWININICHANGE
);
257 SelectKeyboardForLanguage(
264 TRACE("LCID: %08lx\n", lcid
);
265 TRACE("LangID: %04lx\n", LANGIDFROMLCID(lcid
));
267 nCount
= SendMessageW(hwnd
, CB_GETCOUNT
, 0, 0);
269 for (i
= 0; i
< nCount
; i
++)
271 LayoutId
= (LCID
)SendMessageW(hwnd
, CB_GETITEMDATA
, i
, 0);
272 TRACE("Layout: %08lx\n", LayoutId
);
274 if (LANGIDFROMLCID(LayoutId
) == LANGIDFROMLCID(lcid
))
276 TRACE("Found 1: %08lx --> %08lx\n", LayoutId
, lcid
);
277 SendMessageW(hwnd
, CB_SETCURSEL
, i
, 0);
282 for (i
= 0; i
< nCount
; i
++)
284 LayoutId
= (LCID
)SendMessageW(hwnd
, CB_GETITEMDATA
, i
, 0);
285 TRACE("Layout: %08lx\n", LayoutId
);
287 if (PRIMARYLANGID(LayoutId
) == PRIMARYLANGID(lcid
))
289 TRACE("Found 2: %08lx --> %08lx\n", LayoutId
, lcid
);
290 SendMessageW(hwnd
, CB_SETCURSEL
, i
, 0);
295 TRACE("No match found!\n");
301 CreateKeyboardLayoutList(
305 WCHAR szLayoutID
[9], KeyName
[MAX_PATH
];
312 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
313 L
"System\\CurrentControlSet\\Control\\Keyboard Layouts",
315 KEY_ENUMERATE_SUB_KEYS
,
317 if (lError
!= ERROR_SUCCESS
)
322 dwSize
= sizeof(szLayoutID
) / sizeof(WCHAR
);
324 lError
= RegEnumKeyExW(hKey
,
332 if (lError
!= ERROR_SUCCESS
)
335 GetLayoutName(szLayoutID
, KeyName
);
337 iIndex
= (INT
)SendMessageW(hItemsList
, CB_ADDSTRING
, 0, (LPARAM
)KeyName
);
339 ulLayoutID
= wcstoul(szLayoutID
, NULL
, 16);
340 SendMessageW(hItemsList
, CB_SETITEMDATA
, iIndex
, (LPARAM
)ulLayoutID
);
343 if (wcscmp(szLayoutID
, L
"00000409") == 0)
345 SendMessageW(hItemsList
, CB_SETCURSEL
, (WPARAM
)iIndex
, (LPARAM
)0);
357 InitializeDefaultUserLocale(
368 struct {LCTYPE LCType
; PWSTR pValue
;} LocaleData
[] = {
370 {LOCALE_SDECIMAL
, L
"sDecimal"},
371 {LOCALE_STHOUSAND
, L
"sThousand"},
372 {LOCALE_SNEGATIVESIGN
, L
"sNegativeSign"},
373 {LOCALE_SPOSITIVESIGN
, L
"sPositiveSign"},
374 {LOCALE_SGROUPING
, L
"sGrouping"},
375 {LOCALE_SLIST
, L
"sList"},
376 {LOCALE_SNATIVEDIGITS
, L
"sNativeDigits"},
377 {LOCALE_INEGNUMBER
, L
"iNegNumber"},
378 {LOCALE_IDIGITS
, L
"iDigits"},
379 {LOCALE_ILZERO
, L
"iLZero"},
380 {LOCALE_IMEASURE
, L
"iMeasure"},
381 {LOCALE_IDIGITSUBSTITUTION
, L
"NumShape"},
384 {LOCALE_SCURRENCY
, L
"sCurrency"},
385 {LOCALE_SMONDECIMALSEP
, L
"sMonDecimalSep"},
386 {LOCALE_SMONTHOUSANDSEP
, L
"sMonThousandSep"},
387 {LOCALE_SMONGROUPING
, L
"sMonGrouping"},
388 {LOCALE_ICURRENCY
, L
"iCurrency"},
389 {LOCALE_INEGCURR
, L
"iNegCurr"},
390 {LOCALE_ICURRDIGITS
, L
"iCurrDigits"},
393 {LOCALE_STIMEFORMAT
, L
"sTimeFormat"},
394 {LOCALE_STIME
, L
"sTime"},
395 {LOCALE_S1159
, L
"s1159"},
396 {LOCALE_S2359
, L
"s2359"},
397 {LOCALE_ITIME
, L
"iTime"},
398 {LOCALE_ITIMEMARKPOSN
, L
"iTimePrefix"},
399 {LOCALE_ITLZERO
, L
"iTLZero"},
402 {LOCALE_SLONGDATE
, L
"sLongDate"},
403 {LOCALE_SSHORTDATE
, L
"sShortDate"},
404 {LOCALE_SDATE
, L
"sDate"},
405 {LOCALE_IFIRSTDAYOFWEEK
, L
"iFirstDayOfWeek"},
406 {LOCALE_IFIRSTWEEKOFYEAR
, L
"iFirstWeekOfYear"},
407 {LOCALE_IDATE
, L
"iDate"},
408 {LOCALE_ICALENDARTYPE
, L
"iCalendarType"},
411 {LOCALE_SCOUNTRY
, L
"sCountry"},
412 {LOCALE_SLANGUAGE
, L
"sLanguage"},
413 {LOCALE_ICOUNTRY
, L
"iCountry"},
416 ret
= RegOpenKeyExW(HKEY_USERS
,
417 L
".DEFAULT\\Control Panel\\International",
419 KEY_READ
| KEY_WRITE
,
421 if (ret
!= ERROR_SUCCESS
)
426 if (pNewLcid
== NULL
)
428 dwSize
= 9 * sizeof(WCHAR
);
429 ret
= RegQueryValueExW(hLocaleKey
,
435 if (ret
!= ERROR_SUCCESS
)
438 lcid
= (LCID
)wcstoul(szBuffer
, &ptr
, 16);
446 swprintf(szBuffer
, L
"%08lx", lcid
);
447 RegSetValueExW(hLocaleKey
,
452 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
456 while (LocaleData
[i
].pValue
!= NULL
)
458 if (GetLocaleInfo(lcid
,
459 LocaleData
[i
].LCType
| LOCALE_NOUSEROVERRIDE
,
461 sizeof(szBuffer
) / sizeof(WCHAR
)))
463 RegSetValueExW(hLocaleKey
,
464 LocaleData
[i
].pValue
,
468 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
475 RegCloseKey(hLocaleKey
);
480 CenterWindow(HWND hWnd
)
486 hWndParent
= GetParent(hWnd
);
487 if (hWndParent
== NULL
)
488 hWndParent
= GetDesktopWindow();
490 GetWindowRect(hWndParent
, &rcParent
);
491 GetWindowRect(hWnd
, &rcWindow
);
495 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
496 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
506 LPDRAWITEMSTRUCT lpDrawItem
,
513 if (lpDrawItem
->CtlID
== uCtlID
)
515 /* position image in centre of dialog */
516 left
= (lpDrawItem
->rcItem
.right
- pState
->ImageInfo
.cxSource
) / 2;
518 hdcMem
= CreateCompatibleDC(lpDrawItem
->hDC
);
521 SelectObject(hdcMem
, pState
->ImageInfo
.hBitmap
);
522 BitBlt(lpDrawItem
->hDC
,
524 lpDrawItem
->rcItem
.top
,
525 lpDrawItem
->rcItem
.right
- lpDrawItem
->rcItem
.left
,
526 lpDrawItem
->rcItem
.bottom
- lpDrawItem
->rcItem
.top
,
548 /* Retrieve pointer to the state */
549 pState
= (PSTATE
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
554 /* Save pointer to the global state */
555 pState
= (PSTATE
)lParam
;
556 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)pState
);
558 /* Center the dialog window */
559 CenterWindow (hwndDlg
);
561 /* Fill the language and keyboard layout lists */
562 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
563 CreateKeyboardLayoutList(GetDlgItem(hwndDlg
, IDC_LAYOUTLIST
));
565 /* Disable the 'Cancel' button*/
566 EnableWindow(GetDlgItem(hwndDlg
, IDCANCEL
), FALSE
);
570 OnDrawItem((LPDRAWITEMSTRUCT
)lParam
,
576 switch (LOWORD(wParam
))
578 case IDC_LANGUAGELIST
:
579 if (HIWORD(wParam
) == CBN_SELCHANGE
)
584 iCurSel
= SendDlgItemMessageW(hwndDlg
,
589 if (iCurSel
== CB_ERR
)
592 NewLcid
= SendDlgItemMessageW(hwndDlg
,
597 if (NewLcid
== (LCID
)CB_ERR
)
600 TRACE("LCID: 0x%08lx\n", NewLcid
);
601 SelectKeyboardForLanguage(GetDlgItem(hwndDlg
, IDC_LAYOUTLIST
),
607 if (HIWORD(wParam
) == BN_CLICKED
)
612 iCurSel
= SendDlgItemMessageW(hwndDlg
,
617 if (iCurSel
== CB_ERR
)
620 NewLcid
= SendDlgItemMessageW(hwndDlg
,
625 if (NewLcid
== (LCID
)CB_ERR
)
628 /* Set the locale for the current thread */
629 NtSetDefaultLocale(TRUE
, NewLcid
);
631 /* Store the locale setings in the registry */
632 InitializeDefaultUserLocale(&NewLcid
);
634 SetKeyboardLayout(GetDlgItem(hwndDlg
, IDC_LAYOUTLIST
));
636 pState
->NextPage
= STARTPAGE
;
637 EndDialog(hwndDlg
, 0);
665 /* Retrieve pointer to the state */
666 pState
= (PSTATE
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
671 /* Save pointer to the state */
672 pState
= (PSTATE
)lParam
;
673 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)pState
);
675 /* Center the dialog window */
676 CenterWindow(hwndDlg
);
678 EnableWindow(GetDlgItem(hwndDlg
, IDCANCEL
), FALSE
);
682 OnDrawItem((LPDRAWITEMSTRUCT
)lParam
,
688 if (HIWORD(wParam
) == BN_CLICKED
)
690 switch (LOWORD(wParam
))
693 pState
->NextPage
= DONE
;
695 EndDialog(hwndDlg
, 0);
699 pState
->NextPage
= DONE
;
700 pState
->Run
= INSTALLER
;
701 EndDialog(hwndDlg
, 0);
705 pState
->NextPage
= LOCALEPAGE
;
706 EndDialog(hwndDlg
, 0);
727 InitImageInfo(&pState
->ImageInfo
);
729 while (pState
->NextPage
!= DONE
)
731 switch (pState
->NextPage
)
734 DialogBoxParam(hInstance
,
735 MAKEINTRESOURCE(IDD_LOCALEPAGE
),
742 DialogBoxParam(hInstance
,
743 MAKEINTRESOURCE(IDD_STARTPAGE
),
754 DeleteObject(pState
->ImageInfo
.hBitmap
);