3 * Copyright (C) 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.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: subsys/system/usetup/mui.c
23 * PURPOSE: Text-mode setup
29 #include "muilanguages.h"
36 PopupError(IN PCCH Text
,
47 if (SelectedLanguageId
== NULL
)
49 /* default to english */
55 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
61 }while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
69 FindMUIEntriesOfPage(IN ULONG PageNumber
)
73 const MUI_PAGE
* Pages
= NULL
;
75 lngIndex
= max(FindLanguageIndex(), 0);
76 Pages
= LanguageList
[lngIndex
].MuiPages
;
80 if (Pages
[muiIndex
].Number
== PageNumber
)
81 return Pages
[muiIndex
].MuiEntry
;
84 }while (Pages
[muiIndex
].MuiEntry
!= NULL
);
91 FindMUIErrorEntries(VOID
)
93 ULONG lngIndex
= max(FindLanguageIndex(), 0);
94 return LanguageList
[lngIndex
].MuiErrors
;
99 FindMUIStringEntries(VOID
)
101 ULONG lngIndex
= max(FindLanguageIndex(), 0);
102 return LanguageList
[lngIndex
].MuiStrings
;
106 MUIDefaultKeyboardLayout(VOID
)
108 ULONG lngIndex
= max(FindLanguageIndex(), 0);
109 return LanguageList
[lngIndex
].MuiLayouts
[0].LayoutID
;
115 ULONG lngIndex
= max(FindLanguageIndex(), 0);
116 return LanguageList
[lngIndex
].GeoID
;
120 MUIGetLayoutsList(VOID
)
122 ULONG lngIndex
= max(FindLanguageIndex(), 0);
123 return LanguageList
[lngIndex
].MuiLayouts
;
127 MUIDisplayPage(IN ULONG page
)
129 const MUI_ENTRY
* entry
;
132 entry
= FindMUIEntriesOfPage(page
);
135 PopupError("Error: Failed to find translated page",
145 CONSOLE_SetStyledText (
149 entry
[index
].Buffer
);
153 while (entry
[index
].Buffer
!= NULL
);
157 MUIDisplayError(IN ULONG ErrorNum
, OUT PINPUT_RECORD Ir
, IN ULONG WaitEvent
)
159 const MUI_ERROR
* entry
;
161 if (ErrorNum
>= ERROR_LAST_ERROR_CODE
)
163 PopupError("Invalid error number provided",
164 "Press ENTER to continue",
171 entry
= FindMUIErrorEntries();
174 PopupError("Error: Failed to find translated error message",
181 PopupError(entry
[ErrorNum
].ErrorText
,
182 entry
[ErrorNum
].ErrorStatus
,
188 MUIGetString(ULONG Number
)
191 const MUI_STRING
* entry
;
194 entry
= FindMUIStringEntries();
197 for (i
= 0; entry
[i
].Number
!= 0; i
++)
199 if (entry
[i
].Number
== Number
)
201 return entry
[i
].String
;
206 sprintf(szErr
, "Error: failed find string id %lu for language index %lu\n", Number
, FindLanguageIndex());
217 AddHotkeySettings(IN LPCWSTR Hotkey
, IN LPCWSTR LangHotkey
, IN LPCWSTR LayoutHotkey
)
219 OBJECT_ATTRIBUTES ObjectAttributes
;
220 UNICODE_STRING KeyName
;
221 UNICODE_STRING ValueName
;
226 RtlInitUnicodeString(&KeyName
,
227 L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Toggle");
228 InitializeObjectAttributes(&ObjectAttributes
,
230 OBJ_CASE_INSENSITIVE
,
234 Status
= NtCreateKey(&KeyHandle
,
242 if(!NT_SUCCESS(Status
))
244 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
248 RtlInitUnicodeString(&ValueName
,
251 Status
= NtSetValueKey(KeyHandle
,
256 (1 + 1) * sizeof(WCHAR
));
257 if (!NT_SUCCESS(Status
))
259 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
264 RtlInitUnicodeString(&ValueName
,
267 Status
= NtSetValueKey(KeyHandle
,
272 (1 + 1) * sizeof(WCHAR
));
273 if (!NT_SUCCESS(Status
))
275 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
280 RtlInitUnicodeString(&ValueName
,
283 Status
= NtSetValueKey(KeyHandle
,
288 (1 + 1) * sizeof(WCHAR
));
289 if (!NT_SUCCESS(Status
))
291 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
301 AddKbLayoutsToRegistry(IN
const MUI_LAYOUTS
* MuiLayouts
)
303 OBJECT_ATTRIBUTES ObjectAttributes
;
304 UNICODE_STRING KeyName
;
305 UNICODE_STRING ValueName
;
312 WCHAR szKeyName
[48] = L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout";
313 WCHAR szValueName
[3 + 1];
314 WCHAR szLangID
[8 + 1];
316 // Open the keyboard layout key
317 RtlInitUnicodeString(&KeyName
,
319 InitializeObjectAttributes(&ObjectAttributes
,
321 OBJ_CASE_INSENSITIVE
,
325 Status
= NtCreateKey(&KeyHandle
,
333 if(NT_SUCCESS(Status
))
337 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
341 KeyName
.MaximumLength
= sizeof(szKeyName
);
342 Status
= RtlAppendUnicodeToString(&KeyName
, L
"\\Preload");
344 if(!NT_SUCCESS(Status
))
346 DPRINT1("RtlAppend failed! (%lx)\n", Status
);
347 DPRINT1("String is %wZ\n", &KeyName
);
351 InitializeObjectAttributes(&ObjectAttributes
,
353 OBJ_CASE_INSENSITIVE
,
357 Status
= NtCreateKey(&KeyHandle
,
365 if (!NT_SUCCESS(Status
))
367 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
371 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Substitutes");
372 InitializeObjectAttributes(&ObjectAttributes
,
374 OBJ_CASE_INSENSITIVE
,
378 Status
= NtCreateKey(&SubKeyHandle
,
386 if(!NT_SUCCESS(Status
))
388 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
389 NtClose(SubKeyHandle
);
396 if (uIndex
> 19) break;
398 swprintf(szValueName
, L
"%u", uIndex
+ 1);
399 RtlInitUnicodeString(&ValueName
, szValueName
);
401 swprintf(szLangID
, L
"0000%s", MuiLayouts
[uIndex
].LangID
);
403 if (_wcsicmp(szLangID
, MuiLayouts
[uIndex
].LayoutID
) == 0)
405 Status
= NtSetValueKey(KeyHandle
,
409 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
410 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
411 if (!NT_SUCCESS(Status
))
413 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
414 NtClose(SubKeyHandle
);
421 swprintf(szLangID
, L
"d%03u%s", uCount
, MuiLayouts
[uIndex
].LangID
);
422 Status
= NtSetValueKey(KeyHandle
,
427 (wcslen(szLangID
)+1) * sizeof(WCHAR
));
428 if (!NT_SUCCESS(Status
))
430 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
431 NtClose(SubKeyHandle
);
436 RtlInitUnicodeString(&ValueName
, szLangID
);
438 Status
= NtSetValueKey(SubKeyHandle
,
442 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
443 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
444 if (!NT_SUCCESS(Status
))
446 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status
, uIndex
);
447 NtClose(SubKeyHandle
);
457 while (MuiLayouts
[uIndex
].LangID
!= NULL
);
460 AddHotkeySettings(L
"2", L
"2", L
"1");
462 AddHotkeySettings(L
"3", L
"3", L
"3");
464 NtClose(SubKeyHandle
);
470 AddKeyboardLayouts(VOID
)
475 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
477 return AddKbLayoutsToRegistry(LanguageList
[lngIndex
].MuiLayouts
);
482 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
488 AddCodepageToRegistry(IN LPCWSTR ACPage
, IN LPCWSTR OEMCPage
, IN LPCWSTR MACCPage
)
490 OBJECT_ATTRIBUTES ObjectAttributes
;
491 UNICODE_STRING KeyName
;
492 UNICODE_STRING ValueName
;
496 // Open the nls codepage key
497 RtlInitUnicodeString(&KeyName
,
498 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
499 InitializeObjectAttributes(&ObjectAttributes
,
501 OBJ_CASE_INSENSITIVE
,
504 Status
= NtOpenKey(&KeyHandle
,
507 if (!NT_SUCCESS(Status
))
509 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
514 RtlInitUnicodeString(&ValueName
, L
"ACP");
515 Status
= NtSetValueKey(KeyHandle
,
520 (wcslen(ACPage
)+1) * sizeof(PWCHAR
));
521 if (!NT_SUCCESS(Status
))
523 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
529 RtlInitUnicodeString(&ValueName
, L
"OEMCP");
530 Status
= NtSetValueKey(KeyHandle
,
535 (wcslen(OEMCPage
)+1) * sizeof(PWCHAR
));
536 if (!NT_SUCCESS(Status
))
538 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
544 RtlInitUnicodeString(&ValueName
, L
"MACCP");
545 Status
= NtSetValueKey(KeyHandle
,
550 (wcslen(MACCPage
)+1) * sizeof(PWCHAR
));
551 if (!NT_SUCCESS(Status
))
553 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
564 AddFontsSettingsToRegistry(IN
const MUI_SUBFONT
* MuiSubFonts
)
566 OBJECT_ATTRIBUTES ObjectAttributes
;
567 UNICODE_STRING KeyName
;
568 UNICODE_STRING ValueName
;
573 RtlInitUnicodeString(&KeyName
,
574 L
"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SysFontSubstitutes");
575 InitializeObjectAttributes(&ObjectAttributes
,
577 OBJ_CASE_INSENSITIVE
,
580 Status
= NtOpenKey(&KeyHandle
,
583 if (!NT_SUCCESS(Status
))
585 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
591 RtlInitUnicodeString(&ValueName
, MuiSubFonts
[uIndex
].FontName
);
592 Status
= NtSetValueKey(KeyHandle
,
596 (PVOID
)MuiSubFonts
[uIndex
].SubFontName
,
597 (wcslen(MuiSubFonts
[uIndex
].SubFontName
)+1) * sizeof(WCHAR
));
598 if (!NT_SUCCESS(Status
))
600 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
607 while (MuiSubFonts
[uIndex
].FontName
!= NULL
);
620 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
622 if (AddCodepageToRegistry(LanguageList
[lngIndex
].ACPage
,
623 LanguageList
[lngIndex
].OEMCPage
,
624 LanguageList
[lngIndex
].MACCPage
)&&
625 AddFontsSettingsToRegistry(LanguageList
[lngIndex
].MuiSubFonts
))
637 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
643 SetConsoleCodePage(VOID
)
650 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
652 wCodePage
= (UINT
) wcstoul(LanguageList
[lngIndex
].OEMCPage
, NULL
, 10);
653 SetConsoleOutputCP(wCodePage
);
659 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);