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
,
43 FindLanguageIndex(VOID
)
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 MUIClearPage(IN ULONG page
)
129 const MUI_ENTRY
* entry
;
132 entry
= FindMUIEntriesOfPage(page
);
135 PopupError("Error: Failed to find translated page",
145 CONSOLE_ClearStyledText(entry
[index
].X
,
148 strlen(entry
[index
].Buffer
));
151 while (entry
[index
].Buffer
!= NULL
);
155 MUIDisplayPage(IN ULONG page
)
157 const MUI_ENTRY
* entry
;
160 entry
= FindMUIEntriesOfPage(page
);
163 PopupError("Error: Failed to find translated page",
173 CONSOLE_SetStyledText(entry
[index
].X
,
176 entry
[index
].Buffer
);
180 while (entry
[index
].Buffer
!= NULL
);
184 MUIDisplayError(IN ULONG ErrorNum
, OUT PINPUT_RECORD Ir
, IN ULONG WaitEvent
)
186 const MUI_ERROR
* entry
;
188 if (ErrorNum
>= ERROR_LAST_ERROR_CODE
)
190 PopupError("Invalid error number provided",
191 "Press ENTER to continue",
198 entry
= FindMUIErrorEntries();
201 PopupError("Error: Failed to find translated error message",
208 PopupError(entry
[ErrorNum
].ErrorText
,
209 entry
[ErrorNum
].ErrorStatus
,
215 MUIGetString(ULONG Number
)
218 const MUI_STRING
* entry
;
221 entry
= FindMUIStringEntries();
224 for (i
= 0; entry
[i
].Number
!= 0; i
++)
226 if (entry
[i
].Number
== Number
)
228 return entry
[i
].String
;
233 sprintf(szErr
, "Error: failed find string id %lu for language index %lu\n", Number
, FindLanguageIndex());
244 AddHotkeySettings(IN LPCWSTR Hotkey
, IN LPCWSTR LangHotkey
, IN LPCWSTR LayoutHotkey
)
246 OBJECT_ATTRIBUTES ObjectAttributes
;
247 UNICODE_STRING KeyName
;
248 UNICODE_STRING ValueName
;
253 RtlInitUnicodeString(&KeyName
,
254 L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Toggle");
255 InitializeObjectAttributes(&ObjectAttributes
,
257 OBJ_CASE_INSENSITIVE
,
261 Status
= NtCreateKey(&KeyHandle
,
269 if(!NT_SUCCESS(Status
))
271 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
275 RtlInitUnicodeString(&ValueName
,
278 Status
= NtSetValueKey(KeyHandle
,
283 (1 + 1) * sizeof(WCHAR
));
284 if (!NT_SUCCESS(Status
))
286 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
291 RtlInitUnicodeString(&ValueName
,
294 Status
= NtSetValueKey(KeyHandle
,
299 (1 + 1) * sizeof(WCHAR
));
300 if (!NT_SUCCESS(Status
))
302 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
307 RtlInitUnicodeString(&ValueName
,
310 Status
= NtSetValueKey(KeyHandle
,
315 (1 + 1) * sizeof(WCHAR
));
316 if (!NT_SUCCESS(Status
))
318 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
328 AddKbLayoutsToRegistry(IN
const MUI_LAYOUTS
* MuiLayouts
)
330 OBJECT_ATTRIBUTES ObjectAttributes
;
331 UNICODE_STRING KeyName
;
332 UNICODE_STRING ValueName
;
339 WCHAR szKeyName
[48] = L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout";
340 WCHAR szValueName
[3 + 1];
341 WCHAR szLangID
[8 + 1];
343 // Open the keyboard layout key
344 RtlInitUnicodeString(&KeyName
,
346 InitializeObjectAttributes(&ObjectAttributes
,
348 OBJ_CASE_INSENSITIVE
,
352 Status
= NtCreateKey(&KeyHandle
,
360 if(NT_SUCCESS(Status
))
364 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
368 KeyName
.MaximumLength
= sizeof(szKeyName
);
369 Status
= RtlAppendUnicodeToString(&KeyName
, L
"\\Preload");
371 if(!NT_SUCCESS(Status
))
373 DPRINT1("RtlAppend failed! (%lx)\n", Status
);
374 DPRINT1("String is %wZ\n", &KeyName
);
378 InitializeObjectAttributes(&ObjectAttributes
,
380 OBJ_CASE_INSENSITIVE
,
384 Status
= NtCreateKey(&KeyHandle
,
392 if (!NT_SUCCESS(Status
))
394 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
398 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Substitutes");
399 InitializeObjectAttributes(&ObjectAttributes
,
401 OBJ_CASE_INSENSITIVE
,
405 Status
= NtCreateKey(&SubKeyHandle
,
413 if(!NT_SUCCESS(Status
))
415 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
416 NtClose(SubKeyHandle
);
423 if (uIndex
> 19) break;
425 swprintf(szValueName
, L
"%u", uIndex
+ 1);
426 RtlInitUnicodeString(&ValueName
, szValueName
);
428 swprintf(szLangID
, L
"0000%s", MuiLayouts
[uIndex
].LangID
);
430 if (_wcsicmp(szLangID
, MuiLayouts
[uIndex
].LayoutID
) == 0)
432 Status
= NtSetValueKey(KeyHandle
,
436 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
437 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
438 if (!NT_SUCCESS(Status
))
440 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
441 NtClose(SubKeyHandle
);
448 swprintf(szLangID
, L
"d%03u%s", uCount
, MuiLayouts
[uIndex
].LangID
);
449 Status
= NtSetValueKey(KeyHandle
,
454 (wcslen(szLangID
)+1) * sizeof(WCHAR
));
455 if (!NT_SUCCESS(Status
))
457 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
458 NtClose(SubKeyHandle
);
463 RtlInitUnicodeString(&ValueName
, szLangID
);
465 Status
= NtSetValueKey(SubKeyHandle
,
469 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
470 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
471 if (!NT_SUCCESS(Status
))
473 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status
, uIndex
);
474 NtClose(SubKeyHandle
);
484 while (MuiLayouts
[uIndex
].LangID
!= NULL
);
487 AddHotkeySettings(L
"2", L
"2", L
"1");
489 AddHotkeySettings(L
"3", L
"3", L
"3");
491 NtClose(SubKeyHandle
);
497 AddKeyboardLayouts(VOID
)
502 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
504 return AddKbLayoutsToRegistry(LanguageList
[lngIndex
].MuiLayouts
);
509 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
515 AddCodepageToRegistry(IN LPCWSTR ACPage
, IN LPCWSTR OEMCPage
, IN LPCWSTR MACCPage
)
517 OBJECT_ATTRIBUTES ObjectAttributes
;
518 UNICODE_STRING KeyName
;
519 UNICODE_STRING ValueName
;
523 // Open the nls codepage key
524 RtlInitUnicodeString(&KeyName
,
525 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
526 InitializeObjectAttributes(&ObjectAttributes
,
528 OBJ_CASE_INSENSITIVE
,
531 Status
= NtOpenKey(&KeyHandle
,
534 if (!NT_SUCCESS(Status
))
536 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
541 RtlInitUnicodeString(&ValueName
, L
"ACP");
542 Status
= NtSetValueKey(KeyHandle
,
547 (wcslen(ACPage
)+1) * sizeof(WCHAR
));
548 if (!NT_SUCCESS(Status
))
550 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
556 RtlInitUnicodeString(&ValueName
, L
"OEMCP");
557 Status
= NtSetValueKey(KeyHandle
,
562 (wcslen(OEMCPage
)+1) * sizeof(WCHAR
));
563 if (!NT_SUCCESS(Status
))
565 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
571 RtlInitUnicodeString(&ValueName
, L
"MACCP");
572 Status
= NtSetValueKey(KeyHandle
,
577 (wcslen(MACCPage
)+1) * sizeof(WCHAR
));
578 if (!NT_SUCCESS(Status
))
580 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
591 AddFontsSettingsToRegistry(IN
const MUI_SUBFONT
* MuiSubFonts
)
593 OBJECT_ATTRIBUTES ObjectAttributes
;
594 UNICODE_STRING KeyName
;
595 UNICODE_STRING ValueName
;
600 RtlInitUnicodeString(&KeyName
,
601 L
"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SysFontSubstitutes");
602 InitializeObjectAttributes(&ObjectAttributes
,
604 OBJ_CASE_INSENSITIVE
,
607 Status
= NtOpenKey(&KeyHandle
,
610 if (!NT_SUCCESS(Status
))
612 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
618 RtlInitUnicodeString(&ValueName
, MuiSubFonts
[uIndex
].FontName
);
619 Status
= NtSetValueKey(KeyHandle
,
623 (PVOID
)MuiSubFonts
[uIndex
].SubFontName
,
624 (wcslen(MuiSubFonts
[uIndex
].SubFontName
)+1) * sizeof(WCHAR
));
625 if (!NT_SUCCESS(Status
))
627 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
634 while (MuiSubFonts
[uIndex
].FontName
!= NULL
);
647 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
649 if (AddCodepageToRegistry(LanguageList
[lngIndex
].ACPage
,
650 LanguageList
[lngIndex
].OEMCPage
,
651 LanguageList
[lngIndex
].MACCPage
)&&
652 AddFontsSettingsToRegistry(LanguageList
[lngIndex
].MuiSubFonts
))
664 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
670 SetConsoleCodePage(VOID
)
677 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
679 wCodePage
= (UINT
) wcstoul(LanguageList
[lngIndex
].OEMCPage
, NULL
, 10);
680 SetConsoleOutputCP(wCodePage
);
686 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);