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
27 /* INCLUDES *****************************************************************/
32 #include "muilanguages.h"
39 /* FUNCTIONS ****************************************************************/
48 if (LanguageId
== NULL
)
50 /* Default to en-US */
51 // return 0; // FIXME!!
52 LanguageId
= L
"00000409";
55 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
57 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
74 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
76 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
87 MUIDefaultKeyboardLayout(
90 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
91 return MUILanguageList
[lngIndex
].MuiLayouts
[0].LayoutID
;
98 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
99 return MUILanguageList
[lngIndex
].OEMCPage
;
104 IN PCWSTR LanguageId
)
106 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
107 return MUILanguageList
[lngIndex
].GeoID
;
112 IN PCWSTR LanguageId
)
114 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
115 return MUILanguageList
[lngIndex
].MuiLayouts
;
123 IN PCWSTR LangHotkey
,
124 IN PCWSTR LayoutHotkey
)
126 OBJECT_ATTRIBUTES ObjectAttributes
;
127 UNICODE_STRING KeyName
;
128 UNICODE_STRING ValueName
;
133 RtlInitUnicodeString(&KeyName
,
134 L
".DEFAULT\\Keyboard Layout\\Toggle");
135 InitializeObjectAttributes(&ObjectAttributes
,
137 OBJ_CASE_INSENSITIVE
,
138 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
141 Status
= NtCreateKey(&KeyHandle
,
146 REG_OPTION_NON_VOLATILE
,
148 if (!NT_SUCCESS(Status
))
150 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
154 RtlInitUnicodeString(&ValueName
,
157 Status
= NtSetValueKey(KeyHandle
,
162 (1 + 1) * sizeof(WCHAR
));
163 if (!NT_SUCCESS(Status
))
165 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
170 RtlInitUnicodeString(&ValueName
,
173 Status
= NtSetValueKey(KeyHandle
,
178 (1 + 1) * sizeof(WCHAR
));
179 if (!NT_SUCCESS(Status
))
181 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
186 RtlInitUnicodeString(&ValueName
,
189 Status
= NtSetValueKey(KeyHandle
,
194 (1 + 1) * sizeof(WCHAR
));
195 if (!NT_SUCCESS(Status
))
197 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
207 AddKbLayoutsToRegistry(
208 IN
const MUI_LAYOUTS
*MuiLayouts
)
210 OBJECT_ATTRIBUTES ObjectAttributes
;
211 UNICODE_STRING KeyName
;
212 UNICODE_STRING ValueName
;
219 WCHAR szKeyName
[48] = L
".DEFAULT\\Keyboard Layout";
220 WCHAR szValueName
[3 + 1];
221 WCHAR szLangID
[8 + 1];
223 // Open the keyboard layout key
224 RtlInitUnicodeString(&KeyName
, szKeyName
);
225 InitializeObjectAttributes(&ObjectAttributes
,
227 OBJ_CASE_INSENSITIVE
,
228 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
231 Status
= NtCreateKey(&KeyHandle
,
236 REG_OPTION_NON_VOLATILE
,
238 if (!NT_SUCCESS(Status
))
240 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
246 KeyName
.MaximumLength
= sizeof(szKeyName
);
247 Status
= RtlAppendUnicodeToString(&KeyName
, L
"\\Preload");
249 if (!NT_SUCCESS(Status
))
251 DPRINT1("RtlAppend failed! (%lx)\n", Status
);
252 DPRINT1("String is %wZ\n", &KeyName
);
256 InitializeObjectAttributes(&ObjectAttributes
,
258 OBJ_CASE_INSENSITIVE
,
259 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
262 Status
= NtCreateKey(&KeyHandle
,
267 REG_OPTION_NON_VOLATILE
,
269 if (!NT_SUCCESS(Status
))
271 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
275 RtlInitUnicodeString(&KeyName
, L
".DEFAULT\\Keyboard Layout\\Substitutes");
276 InitializeObjectAttributes(&ObjectAttributes
,
278 OBJ_CASE_INSENSITIVE
,
279 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
282 Status
= NtCreateKey(&SubKeyHandle
,
287 REG_OPTION_NON_VOLATILE
,
289 if (!NT_SUCCESS(Status
))
291 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
292 NtClose(SubKeyHandle
);
297 while (MuiLayouts
[uIndex
].LangID
!= NULL
)
299 if (uIndex
> 19) break;
301 swprintf(szValueName
, L
"%u", uIndex
+ 1);
302 RtlInitUnicodeString(&ValueName
, szValueName
);
304 swprintf(szLangID
, L
"0000%s", MuiLayouts
[uIndex
].LangID
);
306 if (_wcsicmp(szLangID
, MuiLayouts
[uIndex
].LayoutID
) == 0)
308 Status
= NtSetValueKey(KeyHandle
,
312 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
313 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
314 if (!NT_SUCCESS(Status
))
316 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
317 NtClose(SubKeyHandle
);
324 swprintf(szLangID
, L
"d%03lu%s", uCount
, MuiLayouts
[uIndex
].LangID
);
325 Status
= NtSetValueKey(KeyHandle
,
330 (wcslen(szLangID
)+1) * sizeof(WCHAR
));
331 if (!NT_SUCCESS(Status
))
333 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
334 NtClose(SubKeyHandle
);
339 RtlInitUnicodeString(&ValueName
, szLangID
);
341 Status
= NtSetValueKey(SubKeyHandle
,
345 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
346 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
347 if (!NT_SUCCESS(Status
))
349 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status
, uIndex
);
350 NtClose(SubKeyHandle
);
362 AddHotkeySettings(L
"2", L
"2", L
"1");
364 AddHotkeySettings(L
"3", L
"3", L
"3");
366 NtClose(SubKeyHandle
);
373 IN PCWSTR LanguageId
)
377 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
379 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
381 return AddKbLayoutsToRegistry(MUILanguageList
[lngIndex
].MuiLayouts
);
392 AddCodepageToRegistry(
397 OBJECT_ATTRIBUTES ObjectAttributes
;
398 UNICODE_STRING KeyName
;
399 UNICODE_STRING ValueName
;
403 // Open the nls codepage key
404 RtlInitUnicodeString(&KeyName
,
405 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
406 InitializeObjectAttributes(&ObjectAttributes
,
408 OBJ_CASE_INSENSITIVE
,
409 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
411 Status
= NtOpenKey(&KeyHandle
,
414 if (!NT_SUCCESS(Status
))
416 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
421 RtlInitUnicodeString(&ValueName
, L
"ACP");
422 Status
= NtSetValueKey(KeyHandle
,
427 (wcslen(ACPage
)+1) * sizeof(WCHAR
));
428 if (!NT_SUCCESS(Status
))
430 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
436 RtlInitUnicodeString(&ValueName
, L
"OEMCP");
437 Status
= NtSetValueKey(KeyHandle
,
442 (wcslen(OEMCPage
)+1) * sizeof(WCHAR
));
443 if (!NT_SUCCESS(Status
))
445 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
451 RtlInitUnicodeString(&ValueName
, L
"MACCP");
452 Status
= NtSetValueKey(KeyHandle
,
457 (wcslen(MACCPage
)+1) * sizeof(WCHAR
));
458 if (!NT_SUCCESS(Status
))
460 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
472 AddFontsSettingsToRegistry(
473 IN
const MUI_SUBFONT
* MuiSubFonts
)
475 OBJECT_ATTRIBUTES ObjectAttributes
;
476 UNICODE_STRING KeyName
;
477 UNICODE_STRING ValueName
;
482 RtlInitUnicodeString(&KeyName
,
483 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
484 InitializeObjectAttributes(&ObjectAttributes
,
486 OBJ_CASE_INSENSITIVE
,
487 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
489 Status
= NtOpenKey(&KeyHandle
,
492 if (!NT_SUCCESS(Status
))
494 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
498 while (MuiSubFonts
[uIndex
].FontName
!= NULL
)
500 RtlInitUnicodeString(&ValueName
, MuiSubFonts
[uIndex
].FontName
);
501 Status
= NtSetValueKey(KeyHandle
,
505 (PVOID
)MuiSubFonts
[uIndex
].SubFontName
,
506 (wcslen(MuiSubFonts
[uIndex
].SubFontName
)+1) * sizeof(WCHAR
));
507 if (!NT_SUCCESS(Status
))
509 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
524 IN PCWSTR LanguageId
)
528 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
530 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
532 if (AddCodepageToRegistry(MUILanguageList
[lngIndex
].ACPage
,
533 MUILanguageList
[lngIndex
].OEMCPage
,
534 MUILanguageList
[lngIndex
].MACCPage
) &&
535 AddFontsSettingsToRegistry(MUILanguageList
[lngIndex
].MuiSubFonts
))