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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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
28 #include "interface/consup.h"
29 #include "errorcode.h"
32 #include "muilanguages.h"
39 PopupError(IN PCCH Text
,
50 if (SelectedLanguageId
== NULL
)
52 /* default to english */
58 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
64 }while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
72 FindMUIEntriesOfPage(IN ULONG PageNumber
)
76 const MUI_PAGE
* Pages
= NULL
;
78 lngIndex
= max(FindLanguageIndex(), 0);
79 Pages
= LanguageList
[lngIndex
].MuiPages
;
83 if (Pages
[muiIndex
].Number
== PageNumber
)
84 return Pages
[muiIndex
].MuiEntry
;
87 }while (Pages
[muiIndex
].MuiEntry
!= NULL
);
94 FindMUIErrorEntries(VOID
)
96 ULONG lngIndex
= max(FindLanguageIndex(), 0);
97 return LanguageList
[lngIndex
].MuiErrors
;
102 FindMUIStringEntries(VOID
)
104 ULONG lngIndex
= max(FindLanguageIndex(), 0);
105 return LanguageList
[lngIndex
].MuiStrings
;
109 MUIDefaultKeyboardLayout(VOID
)
111 ULONG lngIndex
= max(FindLanguageIndex(), 0);
112 return LanguageList
[lngIndex
].MuiLayouts
[0].LayoutID
;
116 MUIGetLayoutsList(VOID
)
118 ULONG lngIndex
= max(FindLanguageIndex(), 0);
119 return LanguageList
[lngIndex
].MuiLayouts
;
123 MUIDisplayPage(IN ULONG page
)
125 const MUI_ENTRY
* entry
;
128 entry
= FindMUIEntriesOfPage(page
);
131 PopupError("Error: Failed to find translated page",
141 CONSOLE_SetStyledText (
145 entry
[index
].Buffer
);
149 while (entry
[index
].Buffer
!= NULL
);
153 MUIDisplayError(IN ULONG ErrorNum
, OUT PINPUT_RECORD Ir
, IN ULONG WaitEvent
)
155 const MUI_ERROR
* entry
;
157 if (ErrorNum
>= ERROR_LAST_ERROR_CODE
)
159 PopupError("Invalid error number provided",
160 "Press ENTER to continue",
167 entry
= FindMUIErrorEntries();
170 PopupError("Error: Failed to find translated error message",
177 PopupError(entry
[ErrorNum
].ErrorText
,
178 entry
[ErrorNum
].ErrorStatus
,
184 MUIGetString(ULONG Number
)
187 const MUI_STRING
* entry
;
190 entry
= FindMUIStringEntries();
193 for (i
= 0; entry
[i
].Number
!= 0; i
++)
195 if (entry
[i
].Number
== Number
)
197 return entry
[i
].String
;
202 sprintf(szErr
, "Error: failed find string id %lu for language index %lu\n", Number
, FindLanguageIndex());
213 AddHotkeySettings(IN LPCWSTR Hotkey
, IN LPCWSTR LangHotkey
, IN LPCWSTR LayoutHotkey
)
215 OBJECT_ATTRIBUTES ObjectAttributes
;
216 UNICODE_STRING KeyName
;
217 UNICODE_STRING ValueName
;
222 RtlInitUnicodeString(&KeyName
,
223 L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Toggle");
224 InitializeObjectAttributes(&ObjectAttributes
,
226 OBJ_CASE_INSENSITIVE
,
230 Status
= NtCreateKey(&KeyHandle
,
238 if(!NT_SUCCESS(Status
))
240 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
244 RtlInitUnicodeString(&ValueName
,
247 Status
= NtSetValueKey(KeyHandle
,
252 (1 + 1) * sizeof(WCHAR
));
253 if (!NT_SUCCESS(Status
))
255 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
260 RtlInitUnicodeString(&ValueName
,
263 Status
= NtSetValueKey(KeyHandle
,
268 (1 + 1) * sizeof(WCHAR
));
269 if (!NT_SUCCESS(Status
))
271 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
276 RtlInitUnicodeString(&ValueName
,
279 Status
= NtSetValueKey(KeyHandle
,
284 (1 + 1) * sizeof(WCHAR
));
285 if (!NT_SUCCESS(Status
))
287 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
297 AddKbLayoutsToRegistry(IN
const MUI_LAYOUTS
* MuiLayouts
)
299 OBJECT_ATTRIBUTES ObjectAttributes
;
300 UNICODE_STRING KeyName
;
301 UNICODE_STRING ValueName
;
308 WCHAR szKeyName
[48] = L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout";
309 WCHAR szValueName
[3 + 1];
310 WCHAR szLangID
[8 + 1];
312 // Open the keyboard layout key
313 RtlInitUnicodeString(&KeyName
,
315 InitializeObjectAttributes(&ObjectAttributes
,
317 OBJ_CASE_INSENSITIVE
,
321 Status
= NtCreateKey(&KeyHandle
,
329 if(NT_SUCCESS(Status
))
333 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
337 KeyName
.MaximumLength
= sizeof(szKeyName
);
338 Status
= RtlAppendUnicodeToString(&KeyName
, L
"\\Preload");
340 if(!NT_SUCCESS(Status
))
342 DPRINT1("RtlAppend failed! (%lx)\n", Status
);
343 DPRINT1("String is %wZ\n", &KeyName
);
347 InitializeObjectAttributes(&ObjectAttributes
,
349 OBJ_CASE_INSENSITIVE
,
353 Status
= NtCreateKey(&KeyHandle
,
361 if (!NT_SUCCESS(Status
))
363 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
367 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Substitutes");
368 InitializeObjectAttributes(&ObjectAttributes
,
370 OBJ_CASE_INSENSITIVE
,
374 Status
= NtCreateKey(&SubKeyHandle
,
382 if(!NT_SUCCESS(Status
))
384 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
385 NtClose(SubKeyHandle
);
392 if (uIndex
> 19) break;
394 swprintf(szValueName
, L
"%u", uIndex
+ 1);
395 RtlInitUnicodeString(&ValueName
, szValueName
);
397 swprintf(szLangID
, L
"0000%s", MuiLayouts
[uIndex
].LangID
);
399 if (_wcsicmp(szLangID
, MuiLayouts
[uIndex
].LayoutID
) == 0)
401 Status
= NtSetValueKey(KeyHandle
,
405 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
406 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
407 if (!NT_SUCCESS(Status
))
409 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
410 NtClose(SubKeyHandle
);
417 swprintf(szLangID
, L
"d%03u%s", uCount
, MuiLayouts
[uIndex
].LangID
);
418 Status
= NtSetValueKey(KeyHandle
,
423 (wcslen(szLangID
)+1) * sizeof(WCHAR
));
424 if (!NT_SUCCESS(Status
))
426 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
427 NtClose(SubKeyHandle
);
432 RtlInitUnicodeString(&ValueName
, szLangID
);
434 Status
= NtSetValueKey(SubKeyHandle
,
438 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
439 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
440 if (!NT_SUCCESS(Status
))
442 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status
, uIndex
);
443 NtClose(SubKeyHandle
);
453 while (MuiLayouts
[uIndex
].LangID
!= NULL
);
456 AddHotkeySettings(L
"2", L
"2", L
"1");
458 AddHotkeySettings(L
"3", L
"3", L
"3");
460 NtClose(SubKeyHandle
);
466 AddKeyboardLayouts(VOID
)
471 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
473 return AddKbLayoutsToRegistry(LanguageList
[lngIndex
].MuiLayouts
);
478 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
484 AddCodepageToRegistry(IN LPCWSTR ACPage
, IN LPCWSTR OEMCPage
, IN LPCWSTR MACCPage
)
486 OBJECT_ATTRIBUTES ObjectAttributes
;
487 UNICODE_STRING KeyName
;
488 UNICODE_STRING ValueName
;
492 // Open the nls codepage key
493 RtlInitUnicodeString(&KeyName
,
494 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
495 InitializeObjectAttributes(&ObjectAttributes
,
497 OBJ_CASE_INSENSITIVE
,
500 Status
= NtOpenKey(&KeyHandle
,
503 if (!NT_SUCCESS(Status
))
505 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
510 RtlInitUnicodeString(&ValueName
, L
"ACP");
511 Status
= NtSetValueKey(KeyHandle
,
516 (wcslen(ACPage
)+1) * sizeof(PWCHAR
));
517 if (!NT_SUCCESS(Status
))
519 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
525 RtlInitUnicodeString(&ValueName
, L
"OEMCP");
526 Status
= NtSetValueKey(KeyHandle
,
531 (wcslen(OEMCPage
)+1) * sizeof(PWCHAR
));
532 if (!NT_SUCCESS(Status
))
534 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
540 RtlInitUnicodeString(&ValueName
, L
"MACCP");
541 Status
= NtSetValueKey(KeyHandle
,
546 (wcslen(MACCPage
)+1) * sizeof(PWCHAR
));
547 if (!NT_SUCCESS(Status
))
549 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
560 AddFontsSettingsToRegistry(IN
const MUI_SUBFONT
* MuiSubFonts
)
562 OBJECT_ATTRIBUTES ObjectAttributes
;
563 UNICODE_STRING KeyName
;
564 UNICODE_STRING ValueName
;
569 RtlInitUnicodeString(&KeyName
,
570 L
"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SysFontSubstitutes");
571 InitializeObjectAttributes(&ObjectAttributes
,
573 OBJ_CASE_INSENSITIVE
,
576 Status
= NtOpenKey(&KeyHandle
,
579 if (!NT_SUCCESS(Status
))
581 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
587 RtlInitUnicodeString(&ValueName
, MuiSubFonts
[uIndex
].FontName
);
588 Status
= NtSetValueKey(KeyHandle
,
592 (PVOID
)MuiSubFonts
[uIndex
].SubFontName
,
593 (wcslen(MuiSubFonts
[uIndex
].SubFontName
)+1) * sizeof(WCHAR
));
594 if (!NT_SUCCESS(Status
))
596 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
603 while (MuiSubFonts
[uIndex
].FontName
!= NULL
);
616 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
618 if (AddCodepageToRegistry(LanguageList
[lngIndex
].ACPage
,
619 LanguageList
[lngIndex
].OEMCPage
,
620 LanguageList
[lngIndex
].MACCPage
)&&
621 AddFontsSettingsToRegistry(LanguageList
[lngIndex
].MuiSubFonts
))
633 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
639 SetConsoleCodePage(VOID
)
646 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
648 wCodePage
= (UINT
) wcstoul(LanguageList
[lngIndex
].OEMCPage
, NULL
, 10);
649 SetConsoleOutputCP(wCodePage
);
655 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);