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: base/setup/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(MUILanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
61 } while (MUILanguageList
[lngIndex
].MuiPages
!= NULL
);
75 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
79 } while (MUILanguageList
[lngIndex
].MuiPages
!= NULL
);
92 const MUI_PAGE
* Pages
= NULL
;
94 lngIndex
= max(FindLanguageIndex(), 0);
95 Pages
= MUILanguageList
[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 MUILanguageList
[lngIndex
].MuiErrors
;
120 FindMUIStringEntries(VOID
)
122 ULONG lngIndex
= max(FindLanguageIndex(), 0);
123 return MUILanguageList
[lngIndex
].MuiStrings
;
128 MUIDefaultKeyboardLayout(VOID
)
130 ULONG lngIndex
= max(FindLanguageIndex(), 0);
131 return MUILanguageList
[lngIndex
].MuiLayouts
[0].LayoutID
;
138 ULONG lngIndex
= max(FindLanguageIndex(), 0);
139 return MUILanguageList
[lngIndex
].GeoID
;
144 MUIGetLayoutsList(VOID
)
146 ULONG lngIndex
= max(FindLanguageIndex(), 0);
147 return MUILanguageList
[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
,
219 const MUI_ERROR
* entry
;
223 if (ErrorNum
>= ERROR_LAST_ERROR_CODE
)
225 PopupError("Invalid error number provided",
226 "Press ENTER to continue",
233 entry
= FindMUIErrorEntries();
236 PopupError("Error: Failed to find translated error message",
243 va_start(ap
, WaitEvent
);
244 vsprintf(Buffer
, entry
[ErrorNum
].ErrorText
, ap
);
248 entry
[ErrorNum
].ErrorStatus
,
259 const MUI_STRING
* entry
;
262 entry
= FindMUIStringEntries();
265 for (i
= 0; entry
[i
].Number
!= 0; i
++)
267 if (entry
[i
].Number
== Number
)
269 return entry
[i
].String
;
274 sprintf(szErr
, "Error: failed find string id %lu for language index %lu\n", Number
, FindLanguageIndex());
289 IN LPCWSTR LangHotkey
,
290 IN LPCWSTR LayoutHotkey
)
292 OBJECT_ATTRIBUTES ObjectAttributes
;
293 UNICODE_STRING KeyName
;
294 UNICODE_STRING ValueName
;
299 RtlInitUnicodeString(&KeyName
,
300 L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Toggle");
301 InitializeObjectAttributes(&ObjectAttributes
,
303 OBJ_CASE_INSENSITIVE
,
307 Status
= NtCreateKey(&KeyHandle
,
315 if(!NT_SUCCESS(Status
))
317 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
321 RtlInitUnicodeString(&ValueName
,
324 Status
= NtSetValueKey(KeyHandle
,
329 (1 + 1) * sizeof(WCHAR
));
330 if (!NT_SUCCESS(Status
))
332 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
337 RtlInitUnicodeString(&ValueName
,
340 Status
= NtSetValueKey(KeyHandle
,
345 (1 + 1) * sizeof(WCHAR
));
346 if (!NT_SUCCESS(Status
))
348 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
353 RtlInitUnicodeString(&ValueName
,
356 Status
= NtSetValueKey(KeyHandle
,
361 (1 + 1) * sizeof(WCHAR
));
362 if (!NT_SUCCESS(Status
))
364 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
375 AddKbLayoutsToRegistry(
376 IN
const MUI_LAYOUTS
*MuiLayouts
)
378 OBJECT_ATTRIBUTES ObjectAttributes
;
379 UNICODE_STRING KeyName
;
380 UNICODE_STRING ValueName
;
387 WCHAR szKeyName
[48] = L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout";
388 WCHAR szValueName
[3 + 1];
389 WCHAR szLangID
[8 + 1];
391 // Open the keyboard layout key
392 RtlInitUnicodeString(&KeyName
,
394 InitializeObjectAttributes(&ObjectAttributes
,
396 OBJ_CASE_INSENSITIVE
,
400 Status
= NtCreateKey(&KeyHandle
,
408 if(NT_SUCCESS(Status
))
412 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
416 KeyName
.MaximumLength
= sizeof(szKeyName
);
417 Status
= RtlAppendUnicodeToString(&KeyName
, L
"\\Preload");
419 if(!NT_SUCCESS(Status
))
421 DPRINT1("RtlAppend failed! (%lx)\n", Status
);
422 DPRINT1("String is %wZ\n", &KeyName
);
426 InitializeObjectAttributes(&ObjectAttributes
,
428 OBJ_CASE_INSENSITIVE
,
432 Status
= NtCreateKey(&KeyHandle
,
440 if (!NT_SUCCESS(Status
))
442 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
446 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\User\\.DEFAULT\\Keyboard Layout\\Substitutes");
447 InitializeObjectAttributes(&ObjectAttributes
,
449 OBJ_CASE_INSENSITIVE
,
453 Status
= NtCreateKey(&SubKeyHandle
,
461 if(!NT_SUCCESS(Status
))
463 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
464 NtClose(SubKeyHandle
);
471 if (uIndex
> 19) break;
473 swprintf(szValueName
, L
"%u", uIndex
+ 1);
474 RtlInitUnicodeString(&ValueName
, szValueName
);
476 swprintf(szLangID
, L
"0000%s", MuiLayouts
[uIndex
].LangID
);
478 if (_wcsicmp(szLangID
, MuiLayouts
[uIndex
].LayoutID
) == 0)
480 Status
= NtSetValueKey(KeyHandle
,
484 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
485 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
486 if (!NT_SUCCESS(Status
))
488 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
489 NtClose(SubKeyHandle
);
496 swprintf(szLangID
, L
"d%03lu%s", uCount
, MuiLayouts
[uIndex
].LangID
);
497 Status
= NtSetValueKey(KeyHandle
,
502 (wcslen(szLangID
)+1) * sizeof(WCHAR
));
503 if (!NT_SUCCESS(Status
))
505 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
506 NtClose(SubKeyHandle
);
511 RtlInitUnicodeString(&ValueName
, szLangID
);
513 Status
= NtSetValueKey(SubKeyHandle
,
517 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
518 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
519 if (!NT_SUCCESS(Status
))
521 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status
, uIndex
);
522 NtClose(SubKeyHandle
);
532 while (MuiLayouts
[uIndex
].LangID
!= NULL
);
535 AddHotkeySettings(L
"2", L
"2", L
"1");
537 AddHotkeySettings(L
"3", L
"3", L
"3");
539 NtClose(SubKeyHandle
);
546 AddKeyboardLayouts(VOID
)
552 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
554 return AddKbLayoutsToRegistry(MUILanguageList
[lngIndex
].MuiLayouts
);
559 while (MUILanguageList
[lngIndex
].MuiPages
!= NULL
);
567 AddCodepageToRegistry(
572 OBJECT_ATTRIBUTES ObjectAttributes
;
573 UNICODE_STRING KeyName
;
574 UNICODE_STRING ValueName
;
578 // Open the nls codepage key
579 RtlInitUnicodeString(&KeyName
,
580 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
581 InitializeObjectAttributes(&ObjectAttributes
,
583 OBJ_CASE_INSENSITIVE
,
586 Status
= NtOpenKey(&KeyHandle
,
589 if (!NT_SUCCESS(Status
))
591 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
596 RtlInitUnicodeString(&ValueName
, L
"ACP");
597 Status
= NtSetValueKey(KeyHandle
,
602 (wcslen(ACPage
)+1) * sizeof(WCHAR
));
603 if (!NT_SUCCESS(Status
))
605 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
611 RtlInitUnicodeString(&ValueName
, L
"OEMCP");
612 Status
= NtSetValueKey(KeyHandle
,
617 (wcslen(OEMCPage
)+1) * sizeof(WCHAR
));
618 if (!NT_SUCCESS(Status
))
620 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
626 RtlInitUnicodeString(&ValueName
, L
"MACCP");
627 Status
= NtSetValueKey(KeyHandle
,
632 (wcslen(MACCPage
)+1) * sizeof(WCHAR
));
633 if (!NT_SUCCESS(Status
))
635 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
648 AddFontsSettingsToRegistry(
649 IN
const MUI_SUBFONT
* MuiSubFonts
)
651 OBJECT_ATTRIBUTES ObjectAttributes
;
652 UNICODE_STRING KeyName
;
653 UNICODE_STRING ValueName
;
658 RtlInitUnicodeString(&KeyName
,
659 L
"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
660 InitializeObjectAttributes(&ObjectAttributes
,
662 OBJ_CASE_INSENSITIVE
,
665 Status
= NtOpenKey(&KeyHandle
,
668 if (!NT_SUCCESS(Status
))
670 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
676 RtlInitUnicodeString(&ValueName
, MuiSubFonts
[uIndex
].FontName
);
677 Status
= NtSetValueKey(KeyHandle
,
681 (PVOID
)MuiSubFonts
[uIndex
].SubFontName
,
682 (wcslen(MuiSubFonts
[uIndex
].SubFontName
)+1) * sizeof(WCHAR
));
683 if (!NT_SUCCESS(Status
))
685 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
692 while (MuiSubFonts
[uIndex
].FontName
!= NULL
);
706 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
708 if (AddCodepageToRegistry(MUILanguageList
[lngIndex
].ACPage
,
709 MUILanguageList
[lngIndex
].OEMCPage
,
710 MUILanguageList
[lngIndex
].MACCPage
)&&
711 AddFontsSettingsToRegistry(MUILanguageList
[lngIndex
].MuiSubFonts
))
723 while (MUILanguageList
[lngIndex
].MuiPages
!= NULL
);
730 SetConsoleCodePage(VOID
)
737 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, SelectedLanguageId
) == 0)
739 wCodePage
= (UINT
) wcstoul(MUILanguageList
[lngIndex
].OEMCPage
, NULL
, 10);
740 SetConsoleOutputCP(wCodePage
);
746 while (MUILanguageList
[lngIndex
].MuiPages
!= NULL
);