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
);
75 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
79 }while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
92 const MUI_PAGE
* Pages
= NULL
;
94 lngIndex
= max(FindLanguageIndex(), 0);
95 Pages
= LanguageList
[lngIndex
].MuiPages
;
99 if (Pages
[muiIndex
].Number
== PageNumber
)
100 return Pages
[muiIndex
].MuiEntry
;
103 }while (Pages
[muiIndex
].MuiEntry
!= NULL
);
111 FindMUIErrorEntries(VOID
)
113 ULONG lngIndex
= max(FindLanguageIndex(), 0);
114 return LanguageList
[lngIndex
].MuiErrors
;
120 FindMUIStringEntries(VOID
)
122 ULONG lngIndex
= max(FindLanguageIndex(), 0);
123 return LanguageList
[lngIndex
].MuiStrings
;
128 MUIDefaultKeyboardLayout(VOID
)
130 ULONG lngIndex
= max(FindLanguageIndex(), 0);
131 return LanguageList
[lngIndex
].MuiLayouts
[0].LayoutID
;
138 ULONG lngIndex
= max(FindLanguageIndex(), 0);
139 return LanguageList
[lngIndex
].GeoID
;
144 MUIGetLayoutsList(VOID
)
146 ULONG lngIndex
= max(FindLanguageIndex(), 0);
147 return LanguageList
[lngIndex
].MuiLayouts
;
155 const MUI_ENTRY
* entry
;
158 entry
= FindMUIEntriesOfPage(page
);
161 PopupError("Error: Failed to find translated page",
171 CONSOLE_ClearStyledText(entry
[index
].X
,
174 strlen(entry
[index
].Buffer
));
177 while (entry
[index
].Buffer
!= NULL
);
185 const MUI_ENTRY
* entry
;
188 entry
= FindMUIEntriesOfPage(page
);
191 PopupError("Error: Failed to find translated page",
201 CONSOLE_SetStyledText(entry
[index
].X
,
204 entry
[index
].Buffer
);
208 while (entry
[index
].Buffer
!= NULL
);
215 OUT PINPUT_RECORD Ir
,
218 const MUI_ERROR
* entry
;
220 if (ErrorNum
>= ERROR_LAST_ERROR_CODE
)
222 PopupError("Invalid error number provided",
223 "Press ENTER to continue",
230 entry
= FindMUIErrorEntries();
233 PopupError("Error: Failed to find translated error message",
240 PopupError(entry
[ErrorNum
].ErrorText
,
241 entry
[ErrorNum
].ErrorStatus
,
252 const MUI_STRING
* entry
;
255 entry
= FindMUIStringEntries();
258 for (i
= 0; entry
[i
].Number
!= 0; i
++)
260 if (entry
[i
].Number
== Number
)
262 return entry
[i
].String
;
267 sprintf(szErr
, "Error: failed find string id %lu for language index %lu\n", Number
, FindLanguageIndex());
282 IN LPCWSTR LangHotkey
,
283 IN LPCWSTR LayoutHotkey
)
285 OBJECT_ATTRIBUTES ObjectAttributes
;
286 UNICODE_STRING KeyName
;
287 UNICODE_STRING ValueName
;
292 RtlInitUnicodeString(&KeyName
,
293 L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Toggle");
294 InitializeObjectAttributes(&ObjectAttributes
,
296 OBJ_CASE_INSENSITIVE
,
300 Status
= NtCreateKey(&KeyHandle
,
308 if(!NT_SUCCESS(Status
))
310 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
314 RtlInitUnicodeString(&ValueName
,
317 Status
= NtSetValueKey(KeyHandle
,
322 (1 + 1) * sizeof(WCHAR
));
323 if (!NT_SUCCESS(Status
))
325 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
330 RtlInitUnicodeString(&ValueName
,
333 Status
= NtSetValueKey(KeyHandle
,
338 (1 + 1) * sizeof(WCHAR
));
339 if (!NT_SUCCESS(Status
))
341 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
346 RtlInitUnicodeString(&ValueName
,
349 Status
= NtSetValueKey(KeyHandle
,
354 (1 + 1) * sizeof(WCHAR
));
355 if (!NT_SUCCESS(Status
))
357 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
368 AddKbLayoutsToRegistry(
369 IN
const MUI_LAYOUTS
*MuiLayouts
)
371 OBJECT_ATTRIBUTES ObjectAttributes
;
372 UNICODE_STRING KeyName
;
373 UNICODE_STRING ValueName
;
380 WCHAR szKeyName
[48] = L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout";
381 WCHAR szValueName
[3 + 1];
382 WCHAR szLangID
[8 + 1];
384 // Open the keyboard layout key
385 RtlInitUnicodeString(&KeyName
,
387 InitializeObjectAttributes(&ObjectAttributes
,
389 OBJ_CASE_INSENSITIVE
,
393 Status
= NtCreateKey(&KeyHandle
,
401 if(NT_SUCCESS(Status
))
405 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
409 KeyName
.MaximumLength
= sizeof(szKeyName
);
410 Status
= RtlAppendUnicodeToString(&KeyName
, L
"\\Preload");
412 if(!NT_SUCCESS(Status
))
414 DPRINT1("RtlAppend failed! (%lx)\n", Status
);
415 DPRINT1("String is %wZ\n", &KeyName
);
419 InitializeObjectAttributes(&ObjectAttributes
,
421 OBJ_CASE_INSENSITIVE
,
425 Status
= NtCreateKey(&KeyHandle
,
433 if (!NT_SUCCESS(Status
))
435 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
439 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Substitutes");
440 InitializeObjectAttributes(&ObjectAttributes
,
442 OBJ_CASE_INSENSITIVE
,
446 Status
= NtCreateKey(&SubKeyHandle
,
454 if(!NT_SUCCESS(Status
))
456 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
457 NtClose(SubKeyHandle
);
464 if (uIndex
> 19) break;
466 swprintf(szValueName
, L
"%u", uIndex
+ 1);
467 RtlInitUnicodeString(&ValueName
, szValueName
);
469 swprintf(szLangID
, L
"0000%s", MuiLayouts
[uIndex
].LangID
);
471 if (_wcsicmp(szLangID
, MuiLayouts
[uIndex
].LayoutID
) == 0)
473 Status
= NtSetValueKey(KeyHandle
,
477 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
478 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
479 if (!NT_SUCCESS(Status
))
481 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
482 NtClose(SubKeyHandle
);
489 swprintf(szLangID
, L
"d%03lu%s", uCount
, MuiLayouts
[uIndex
].LangID
);
490 Status
= NtSetValueKey(KeyHandle
,
495 (wcslen(szLangID
)+1) * sizeof(WCHAR
));
496 if (!NT_SUCCESS(Status
))
498 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
499 NtClose(SubKeyHandle
);
504 RtlInitUnicodeString(&ValueName
, szLangID
);
506 Status
= NtSetValueKey(SubKeyHandle
,
510 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
511 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
512 if (!NT_SUCCESS(Status
))
514 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status
, uIndex
);
515 NtClose(SubKeyHandle
);
525 while (MuiLayouts
[uIndex
].LangID
!= NULL
);
528 AddHotkeySettings(L
"2", L
"2", L
"1");
530 AddHotkeySettings(L
"3", L
"3", L
"3");
532 NtClose(SubKeyHandle
);
539 AddKeyboardLayouts(VOID
)
545 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
547 return AddKbLayoutsToRegistry(LanguageList
[lngIndex
].MuiLayouts
);
552 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
560 AddCodepageToRegistry(
565 OBJECT_ATTRIBUTES ObjectAttributes
;
566 UNICODE_STRING KeyName
;
567 UNICODE_STRING ValueName
;
571 // Open the nls codepage key
572 RtlInitUnicodeString(&KeyName
,
573 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
574 InitializeObjectAttributes(&ObjectAttributes
,
576 OBJ_CASE_INSENSITIVE
,
579 Status
= NtOpenKey(&KeyHandle
,
582 if (!NT_SUCCESS(Status
))
584 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
589 RtlInitUnicodeString(&ValueName
, L
"ACP");
590 Status
= NtSetValueKey(KeyHandle
,
595 (wcslen(ACPage
)+1) * sizeof(WCHAR
));
596 if (!NT_SUCCESS(Status
))
598 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
604 RtlInitUnicodeString(&ValueName
, L
"OEMCP");
605 Status
= NtSetValueKey(KeyHandle
,
610 (wcslen(OEMCPage
)+1) * sizeof(WCHAR
));
611 if (!NT_SUCCESS(Status
))
613 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
619 RtlInitUnicodeString(&ValueName
, L
"MACCP");
620 Status
= NtSetValueKey(KeyHandle
,
625 (wcslen(MACCPage
)+1) * sizeof(WCHAR
));
626 if (!NT_SUCCESS(Status
))
628 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
641 AddFontsSettingsToRegistry(
642 IN
const MUI_SUBFONT
* MuiSubFonts
)
644 OBJECT_ATTRIBUTES ObjectAttributes
;
645 UNICODE_STRING KeyName
;
646 UNICODE_STRING ValueName
;
651 RtlInitUnicodeString(&KeyName
,
652 L
"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
653 InitializeObjectAttributes(&ObjectAttributes
,
655 OBJ_CASE_INSENSITIVE
,
658 Status
= NtOpenKey(&KeyHandle
,
661 if (!NT_SUCCESS(Status
))
663 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
669 RtlInitUnicodeString(&ValueName
, MuiSubFonts
[uIndex
].FontName
);
670 Status
= NtSetValueKey(KeyHandle
,
674 (PVOID
)MuiSubFonts
[uIndex
].SubFontName
,
675 (wcslen(MuiSubFonts
[uIndex
].SubFontName
)+1) * sizeof(WCHAR
));
676 if (!NT_SUCCESS(Status
))
678 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
685 while (MuiSubFonts
[uIndex
].FontName
!= NULL
);
699 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
701 if (AddCodepageToRegistry(LanguageList
[lngIndex
].ACPage
,
702 LanguageList
[lngIndex
].OEMCPage
,
703 LanguageList
[lngIndex
].MACCPage
)&&
704 AddFontsSettingsToRegistry(LanguageList
[lngIndex
].MuiSubFonts
))
716 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);
723 SetConsoleCodePage(VOID
)
730 if (_wcsicmp(LanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
732 wCodePage
= (UINT
) wcstoul(LanguageList
[lngIndex
].OEMCPage
, NULL
, 10);
733 SetConsoleOutputCP(wCodePage
);
739 while (LanguageList
[lngIndex
].MuiPages
!= NULL
);