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], szCurrentLayoutId
[9];
306 WCHAR KeyName
[MAX_PATH
];
313 if (!GetKeyboardLayoutNameW(szCurrentLayoutId
))
314 wcscpy(szCurrentLayoutId
, L
"00000409");
316 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
317 L
"System\\CurrentControlSet\\Control\\Keyboard Layouts",
319 KEY_ENUMERATE_SUB_KEYS
,
321 if (lError
!= ERROR_SUCCESS
)
326 dwSize
= sizeof(szLayoutId
) / sizeof(WCHAR
);
328 lError
= RegEnumKeyExW(hKey
,
336 if (lError
!= ERROR_SUCCESS
)
339 GetLayoutName(szLayoutId
, KeyName
);
341 iIndex
= (INT
)SendMessageW(hItemsList
, CB_ADDSTRING
, 0, (LPARAM
)KeyName
);
343 ulLayoutId
= wcstoul(szLayoutId
, NULL
, 16);
344 SendMessageW(hItemsList
, CB_SETITEMDATA
, iIndex
, (LPARAM
)ulLayoutId
);
346 if (wcscmp(szLayoutId
, szCurrentLayoutId
) == 0)
348 SendMessageW(hItemsList
, CB_SETCURSEL
, (WPARAM
)iIndex
, (LPARAM
)0);
360 InitializeDefaultUserLocale(
371 struct {LCTYPE LCType
; PWSTR pValue
;} LocaleData
[] = {
373 {LOCALE_SDECIMAL
, L
"sDecimal"},
374 {LOCALE_STHOUSAND
, L
"sThousand"},
375 {LOCALE_SNEGATIVESIGN
, L
"sNegativeSign"},
376 {LOCALE_SPOSITIVESIGN
, L
"sPositiveSign"},
377 {LOCALE_SGROUPING
, L
"sGrouping"},
378 {LOCALE_SLIST
, L
"sList"},
379 {LOCALE_SNATIVEDIGITS
, L
"sNativeDigits"},
380 {LOCALE_INEGNUMBER
, L
"iNegNumber"},
381 {LOCALE_IDIGITS
, L
"iDigits"},
382 {LOCALE_ILZERO
, L
"iLZero"},
383 {LOCALE_IMEASURE
, L
"iMeasure"},
384 {LOCALE_IDIGITSUBSTITUTION
, L
"NumShape"},
387 {LOCALE_SCURRENCY
, L
"sCurrency"},
388 {LOCALE_SMONDECIMALSEP
, L
"sMonDecimalSep"},
389 {LOCALE_SMONTHOUSANDSEP
, L
"sMonThousandSep"},
390 {LOCALE_SMONGROUPING
, L
"sMonGrouping"},
391 {LOCALE_ICURRENCY
, L
"iCurrency"},
392 {LOCALE_INEGCURR
, L
"iNegCurr"},
393 {LOCALE_ICURRDIGITS
, L
"iCurrDigits"},
396 {LOCALE_STIMEFORMAT
, L
"sTimeFormat"},
397 {LOCALE_STIME
, L
"sTime"},
398 {LOCALE_S1159
, L
"s1159"},
399 {LOCALE_S2359
, L
"s2359"},
400 {LOCALE_ITIME
, L
"iTime"},
401 {LOCALE_ITIMEMARKPOSN
, L
"iTimePrefix"},
402 {LOCALE_ITLZERO
, L
"iTLZero"},
405 {LOCALE_SLONGDATE
, L
"sLongDate"},
406 {LOCALE_SSHORTDATE
, L
"sShortDate"},
407 {LOCALE_SDATE
, L
"sDate"},
408 {LOCALE_IFIRSTDAYOFWEEK
, L
"iFirstDayOfWeek"},
409 {LOCALE_IFIRSTWEEKOFYEAR
, L
"iFirstWeekOfYear"},
410 {LOCALE_IDATE
, L
"iDate"},
411 {LOCALE_ICALENDARTYPE
, L
"iCalendarType"},
414 {LOCALE_SCOUNTRY
, L
"sCountry"},
415 {LOCALE_SLANGUAGE
, L
"sLanguage"},
416 {LOCALE_ICOUNTRY
, L
"iCountry"},
419 ret
= RegOpenKeyExW(HKEY_USERS
,
420 L
".DEFAULT\\Control Panel\\International",
422 KEY_READ
| KEY_WRITE
,
424 if (ret
!= ERROR_SUCCESS
)
429 if (pNewLcid
== NULL
)
431 dwSize
= 9 * sizeof(WCHAR
);
432 ret
= RegQueryValueExW(hLocaleKey
,
438 if (ret
!= ERROR_SUCCESS
)
441 lcid
= (LCID
)wcstoul(szBuffer
, &ptr
, 16);
449 swprintf(szBuffer
, L
"%08lx", lcid
);
450 RegSetValueExW(hLocaleKey
,
455 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
459 while (LocaleData
[i
].pValue
!= NULL
)
461 if (GetLocaleInfo(lcid
,
462 LocaleData
[i
].LCType
| LOCALE_NOUSEROVERRIDE
,
464 sizeof(szBuffer
) / sizeof(WCHAR
)))
466 RegSetValueExW(hLocaleKey
,
467 LocaleData
[i
].pValue
,
471 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
478 RegCloseKey(hLocaleKey
);
483 CenterWindow(HWND hWnd
)
489 hWndParent
= GetParent(hWnd
);
490 if (hWndParent
== NULL
)
491 hWndParent
= GetDesktopWindow();
493 GetWindowRect(hWndParent
, &rcParent
);
494 GetWindowRect(hWnd
, &rcWindow
);
498 ((rcParent
.right
- rcParent
.left
) - (rcWindow
.right
- rcWindow
.left
)) / 2,
499 ((rcParent
.bottom
- rcParent
.top
) - (rcWindow
.bottom
- rcWindow
.top
)) / 2,
509 LPDRAWITEMSTRUCT lpDrawItem
,
516 if (lpDrawItem
->CtlID
== uCtlID
)
518 /* position image in centre of dialog */
519 left
= (lpDrawItem
->rcItem
.right
- pState
->ImageInfo
.cxSource
) / 2;
521 hdcMem
= CreateCompatibleDC(lpDrawItem
->hDC
);
524 SelectObject(hdcMem
, pState
->ImageInfo
.hBitmap
);
525 BitBlt(lpDrawItem
->hDC
,
527 lpDrawItem
->rcItem
.top
,
528 lpDrawItem
->rcItem
.right
- lpDrawItem
->rcItem
.left
,
529 lpDrawItem
->rcItem
.bottom
- lpDrawItem
->rcItem
.top
,
551 /* Retrieve pointer to the state */
552 pState
= (PSTATE
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
557 /* Save pointer to the global state */
558 pState
= (PSTATE
)lParam
;
559 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)pState
);
561 /* Center the dialog window */
562 CenterWindow (hwndDlg
);
564 /* Fill the language and keyboard layout lists */
565 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
566 CreateKeyboardLayoutList(GetDlgItem(hwndDlg
, IDC_LAYOUTLIST
));
568 /* Disable the 'Cancel' button*/
569 EnableWindow(GetDlgItem(hwndDlg
, IDCANCEL
), FALSE
);
573 OnDrawItem((LPDRAWITEMSTRUCT
)lParam
,
579 switch (LOWORD(wParam
))
581 case IDC_LANGUAGELIST
:
582 if (HIWORD(wParam
) == CBN_SELCHANGE
)
587 iCurSel
= SendDlgItemMessageW(hwndDlg
,
592 if (iCurSel
== CB_ERR
)
595 NewLcid
= SendDlgItemMessageW(hwndDlg
,
600 if (NewLcid
== (LCID
)CB_ERR
)
603 TRACE("LCID: 0x%08lx\n", NewLcid
);
604 SelectKeyboardForLanguage(GetDlgItem(hwndDlg
, IDC_LAYOUTLIST
),
610 if (HIWORD(wParam
) == BN_CLICKED
)
615 iCurSel
= SendDlgItemMessageW(hwndDlg
,
620 if (iCurSel
== CB_ERR
)
623 NewLcid
= SendDlgItemMessageW(hwndDlg
,
628 if (NewLcid
== (LCID
)CB_ERR
)
631 /* Set the locale for the current thread */
632 NtSetDefaultLocale(TRUE
, NewLcid
);
634 /* Store the locale setings in the registry */
635 InitializeDefaultUserLocale(&NewLcid
);
637 SetKeyboardLayout(GetDlgItem(hwndDlg
, IDC_LAYOUTLIST
));
639 pState
->NextPage
= STARTPAGE
;
640 EndDialog(hwndDlg
, 0);
668 /* Retrieve pointer to the state */
669 pState
= (PSTATE
)GetWindowLongPtr (hwndDlg
, GWL_USERDATA
);
674 /* Save pointer to the state */
675 pState
= (PSTATE
)lParam
;
676 SetWindowLongPtr(hwndDlg
, GWL_USERDATA
, (DWORD_PTR
)pState
);
678 /* Center the dialog window */
679 CenterWindow(hwndDlg
);
681 EnableWindow(GetDlgItem(hwndDlg
, IDCANCEL
), FALSE
);
685 OnDrawItem((LPDRAWITEMSTRUCT
)lParam
,
691 if (HIWORD(wParam
) == BN_CLICKED
)
693 switch (LOWORD(wParam
))
696 pState
->NextPage
= DONE
;
698 EndDialog(hwndDlg
, 0);
702 pState
->NextPage
= DONE
;
703 pState
->Run
= INSTALLER
;
704 EndDialog(hwndDlg
, 0);
708 pState
->NextPage
= LOCALEPAGE
;
709 EndDialog(hwndDlg
, 0);
730 InitImageInfo(&pState
->ImageInfo
);
732 while (pState
->NextPage
!= DONE
)
734 switch (pState
->NextPage
)
737 DialogBoxParam(hInstance
,
738 MAKEINTRESOURCE(IDD_LOCALEPAGE
),
745 DialogBoxParam(hInstance
,
746 MAKEINTRESOURCE(IDD_STARTPAGE
),
757 DeleteObject(pState
->ImageInfo
.hBitmap
);