3 * Copyright (C) 2004 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.
19 /* COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS text-mode setup
21 * FILE: base/setup/usetup/settings.c
22 * PURPOSE: Device settings support functions
23 * PROGRAMMERS: Colin Finck
26 /* INCLUDES *****************************************************************/
39 /* GLOBALS ******************************************************************/
41 static ULONG DefaultLanguageIndex
= 0;
43 /* FUNCTIONS ****************************************************************/
49 UNICODE_STRING MultiKeyPathU
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter");
50 UNICODE_STRING IdentifierU
= RTL_CONSTANT_STRING(L
"Identifier");
51 UNICODE_STRING AcpiBiosIdentifier
= RTL_CONSTANT_STRING(L
"ACPI BIOS");
52 OBJECT_ATTRIBUTES ObjectAttributes
;
53 PKEY_BASIC_INFORMATION pDeviceInformation
= NULL
;
54 ULONG DeviceInfoLength
= sizeof(KEY_BASIC_INFORMATION
) + 50 * sizeof(WCHAR
);
55 PKEY_VALUE_PARTIAL_INFORMATION pValueInformation
= NULL
;
56 ULONG ValueInfoLength
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + 50 * sizeof(WCHAR
);
58 ULONG IndexDevice
= 0;
59 UNICODE_STRING DeviceName
, ValueName
;
60 HANDLE hDevicesKey
= NULL
;
61 HANDLE hDeviceKey
= NULL
;
65 InitializeObjectAttributes(&ObjectAttributes
,
70 Status
= NtOpenKey(&hDevicesKey
,
71 KEY_ENUMERATE_SUB_KEYS
,
73 if (!NT_SUCCESS(Status
))
75 DPRINT("NtOpenKey() failed with status 0x%08lx\n", Status
);
79 pDeviceInformation
= RtlAllocateHeap(RtlGetProcessHeap(), 0, DeviceInfoLength
);
80 if (!pDeviceInformation
)
82 DPRINT("RtlAllocateHeap() failed\n");
83 Status
= STATUS_NO_MEMORY
;
87 pValueInformation
= RtlAllocateHeap(RtlGetProcessHeap(), 0, ValueInfoLength
);
88 if (!pValueInformation
)
90 DPRINT("RtlAllocateHeap() failed\n");
91 Status
= STATUS_NO_MEMORY
;
97 Status
= NtEnumerateKey(hDevicesKey
,
103 if (Status
== STATUS_NO_MORE_ENTRIES
)
105 else if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
107 RtlFreeHeap(RtlGetProcessHeap(), 0, pDeviceInformation
);
108 DeviceInfoLength
= RequiredSize
;
109 pDeviceInformation
= RtlAllocateHeap(RtlGetProcessHeap(), 0, DeviceInfoLength
);
110 if (!pDeviceInformation
)
112 DPRINT("RtlAllocateHeap() failed\n");
113 Status
= STATUS_NO_MEMORY
;
116 Status
= NtEnumerateKey(hDevicesKey
,
123 if (!NT_SUCCESS(Status
))
125 DPRINT("NtEnumerateKey() failed with status 0x%08lx\n", Status
);
130 /* Open device key */
131 DeviceName
.Length
= DeviceName
.MaximumLength
= pDeviceInformation
->NameLength
;
132 DeviceName
.Buffer
= pDeviceInformation
->Name
;
133 InitializeObjectAttributes(&ObjectAttributes
,
135 OBJ_CASE_INSENSITIVE
,
138 Status
= NtOpenKey(&hDeviceKey
,
141 if (!NT_SUCCESS(Status
))
143 DPRINT("NtOpenKey() failed with status 0x%08lx\n", Status
);
147 /* Read identifier */
148 Status
= NtQueryValueKey(hDeviceKey
,
150 KeyValuePartialInformation
,
154 if (Status
== STATUS_BUFFER_OVERFLOW
|| Status
== STATUS_BUFFER_TOO_SMALL
)
156 RtlFreeHeap(RtlGetProcessHeap(), 0, pValueInformation
);
157 ValueInfoLength
= RequiredSize
;
158 pValueInformation
= RtlAllocateHeap(RtlGetProcessHeap(), 0, ValueInfoLength
);
159 if (!pValueInformation
)
161 DPRINT("RtlAllocateHeap() failed\n");
162 Status
= STATUS_NO_MEMORY
;
165 Status
= NtQueryValueKey(hDeviceKey
,
167 KeyValuePartialInformation
,
172 if (!NT_SUCCESS(Status
))
174 DPRINT("NtQueryValueKey() failed with status 0x%08lx\n", Status
);
177 else if (pValueInformation
->Type
!= REG_SZ
)
179 DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation
->Type
, REG_SZ
);
183 ValueName
.Length
= ValueName
.MaximumLength
= pValueInformation
->DataLength
;
184 ValueName
.Buffer
= (PWCHAR
)pValueInformation
->Data
;
185 if (ValueName
.Length
>= sizeof(WCHAR
) && ValueName
.Buffer
[ValueName
.Length
/ sizeof(WCHAR
) - 1] == UNICODE_NULL
)
186 ValueName
.Length
-= sizeof(WCHAR
);
187 if (RtlEqualUnicodeString(&ValueName
, &AcpiBiosIdentifier
, FALSE
))
189 DPRINT("Found ACPI BIOS\n");
200 if (pDeviceInformation
)
201 RtlFreeHeap(RtlGetProcessHeap(), 0, pDeviceInformation
);
202 if (pValueInformation
)
203 RtlFreeHeap(RtlGetProcessHeap(), 0, pValueInformation
);
205 NtClose(hDevicesKey
);
213 GetComputerIdentifier(
214 OUT PWSTR Identifier
,
215 IN ULONG IdentifierLength
)
217 OBJECT_ATTRIBUTES ObjectAttributes
;
218 UNICODE_STRING KeyName
;
219 LPCWSTR ComputerIdentifier
;
220 HANDLE ProcessorsKey
;
221 PKEY_FULL_INFORMATION pFullInfo
;
222 ULONG Size
, SizeNeeded
;
225 DPRINT("GetComputerIdentifier() called\n");
227 Size
= sizeof(KEY_FULL_INFORMATION
);
228 pFullInfo
= (PKEY_FULL_INFORMATION
)RtlAllocateHeap(RtlGetProcessHeap(), 0, Size
);
231 DPRINT("RtlAllocateHeap() failed\n");
235 /* Open the processors key */
236 RtlInitUnicodeString(&KeyName
,
237 L
"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor");
238 InitializeObjectAttributes(&ObjectAttributes
,
240 OBJ_CASE_INSENSITIVE
,
244 Status
= NtOpenKey(&ProcessorsKey
,
247 if (!NT_SUCCESS(Status
))
249 DPRINT("NtOpenKey() failed (Status 0x%lx)\n", Status
);
250 RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo
);
254 /* Get number of subkeys */
255 Status
= NtQueryKey(ProcessorsKey
,
260 NtClose(ProcessorsKey
);
261 if (!NT_SUCCESS(Status
) && Status
!= STATUS_BUFFER_OVERFLOW
)
263 DPRINT("NtQueryKey() failed (Status 0x%lx)\n", Status
);
264 RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo
);
268 /* Find computer identifier */
269 if (pFullInfo
->SubKeys
== 0)
271 /* Something strange happened. No processor detected */
272 RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo
);
276 if (IsAcpiComputer())
278 if (pFullInfo
->SubKeys
== 1)
280 /* Computer is mono-CPU */
281 ComputerIdentifier
= L
"ACPI UP";
285 /* Computer is multi-CPUs */
286 ComputerIdentifier
= L
"ACPI MP";
291 if (pFullInfo
->SubKeys
== 1)
293 /* Computer is mono-CPU */
294 ComputerIdentifier
= L
"PC UP";
298 /* Computer is multi-CPUs */
299 ComputerIdentifier
= L
"PC MP";
303 RtlFreeHeap(RtlGetProcessHeap(), 0, pFullInfo
);
305 /* Copy computer identifier to return buffer */
306 SizeNeeded
= (wcslen(ComputerIdentifier
) + 1) * sizeof(WCHAR
);
307 if (SizeNeeded
> IdentifierLength
)
310 RtlCopyMemory(Identifier
, ComputerIdentifier
, SizeNeeded
);
318 * 0x00: Failure, stop the enumeration;
319 * 0x01: Add the entry and continue the enumeration;
320 * 0x02: Skip the entry but continue the enumeration.
323 (NTAPI
*PPROCESS_ENTRY_ROUTINE
)(
326 OUT PWCHAR DisplayText
,
327 IN SIZE_T DisplayTextSize
,
329 OUT PBOOLEAN Current
,
330 IN PVOID Parameter OPTIONAL
);
333 AddEntriesFromInfSection(
334 IN OUT PGENERIC_LIST List
,
336 IN PCWSTR SectionName
,
337 IN PINFCONTEXT pContext
,
338 IN PPROCESS_ENTRY_ROUTINE ProcessEntry
,
339 IN PVOID Parameter OPTIONAL
)
347 WCHAR DisplayText
[128];
349 if (!SetupFindFirstLineW(InfFile
, SectionName
, NULL
, pContext
))
355 * NOTE: Do not use INF_GetData() as it expects INF entries of exactly
356 * two fields ("key = value"); however we expect to be able to deal with
357 * entries having more than two fields, the only requirement being that
358 * the second field (field number 1) contains the field description.
360 if (!INF_GetDataField(pContext
, 0, &KeyName
))
362 DPRINT("INF_GetDataField() failed\n");
366 if (!INF_GetDataField(pContext
, 1, &KeyValue
))
368 DPRINT("INF_GetDataField() failed\n");
369 INF_FreeData(KeyName
);
375 RetVal
= ProcessEntry(KeyName
,
382 INF_FreeData(KeyName
);
383 INF_FreeData(KeyValue
);
387 DPRINT("ProcessEntry() failed\n");
390 else if (RetVal
== 1)
392 AppendGenericListEntry(List
, DisplayText
, UserData
, Current
);
395 // else if (RetVal == 2), skip the entry.
397 } while (SetupFindNextLine(pContext
, pContext
));
407 OUT PWCHAR DisplayText
,
408 IN SIZE_T DisplayTextSize
,
410 OUT PBOOLEAN Current
,
411 IN PVOID Parameter OPTIONAL
)
413 PWSTR CompareKey
= (PWSTR
)Parameter
;
415 *UserData
= RtlAllocateHeap(ProcessHeap
, 0,
416 (wcslen(KeyName
) + 1) * sizeof(WCHAR
));
417 if (*UserData
== NULL
)
419 /* Failure, stop enumeration */
420 DPRINT1("RtlAllocateHeap() failed\n");
424 wcscpy((PWCHAR
)*UserData
, KeyName
);
425 RtlStringCbCopyW(DisplayText
, DisplayTextSize
, KeyValue
);
427 *Current
= (CompareKey
? !_wcsicmp(KeyName
, CompareKey
) : FALSE
);
435 CreateComputerTypeList(
442 WCHAR ComputerIdentifier
[128];
443 WCHAR ComputerKey
[32];
445 /* Get the computer identification */
446 if (!GetComputerIdentifier(ComputerIdentifier
, 128))
448 ComputerIdentifier
[0] = 0;
451 DPRINT("Computer identifier: '%S'\n", ComputerIdentifier
);
453 /* Search for matching device identifier */
454 if (!SetupFindFirstLineW(InfFile
, L
"Map.Computer", NULL
, &Context
))
456 /* FIXME: error message */
464 if (!INF_GetDataField(&Context
, 1, &KeyValue
))
466 /* FIXME: Handle error! */
467 DPRINT("INF_GetDataField() failed\n");
471 DPRINT("KeyValue: %S\n", KeyValue
);
472 FoundId
= !!wcsstr(ComputerIdentifier
, KeyValue
);
473 INF_FreeData(KeyValue
);
478 if (!INF_GetDataField(&Context
, 0, &KeyName
))
480 /* FIXME: Handle error! */
481 DPRINT("INF_GetDataField() failed\n");
485 DPRINT("Computer key: %S\n", KeyName
);
486 RtlStringCchCopyW(ComputerKey
, ARRAYSIZE(ComputerKey
), KeyName
);
487 INF_FreeData(KeyName
);
488 } while (SetupFindNextLine(&Context
, &Context
));
490 List
= CreateGenericList();
494 if (AddEntriesFromInfSection(List
,
501 DestroyGenericList(List
, TRUE
);
510 GetDisplayIdentifier(
511 OUT PWSTR Identifier
,
512 IN ULONG IdentifierLength
)
514 OBJECT_ATTRIBUTES ObjectAttributes
;
515 UNICODE_STRING KeyName
;
518 HANDLE BusInstanceKey
;
519 HANDLE ControllerKey
;
520 HANDLE ControllerInstanceKey
;
522 ULONG ControllerInstance
;
524 ULONG ReturnedLength
;
525 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo
;
528 DPRINT("GetDisplayIdentifier() called\n");
530 /* Open the bus key */
531 RtlInitUnicodeString(&KeyName
,
532 L
"\\Registry\\Machine\\HARDWARE\\Description\\System\\MultifunctionAdapter");
533 InitializeObjectAttributes(&ObjectAttributes
,
535 OBJ_CASE_INSENSITIVE
,
539 Status
= NtOpenKey(&BusKey
,
540 KEY_ENUMERATE_SUB_KEYS
,
542 if (!NT_SUCCESS(Status
))
544 DPRINT("NtOpenKey() failed (Status %lx)\n", Status
);
551 RtlStringCchPrintfW(Buffer
, ARRAYSIZE(Buffer
), L
"%lu", BusInstance
);
552 RtlInitUnicodeString(&KeyName
, Buffer
);
553 InitializeObjectAttributes(&ObjectAttributes
,
555 OBJ_CASE_INSENSITIVE
,
559 Status
= NtOpenKey(&BusInstanceKey
,
560 KEY_ENUMERATE_SUB_KEYS
,
562 if (!NT_SUCCESS(Status
))
564 DPRINT("NtOpenKey() failed (Status %lx)\n", Status
);
569 /* Open the controller type key */
570 RtlInitUnicodeString(&KeyName
, L
"DisplayController");
571 InitializeObjectAttributes(&ObjectAttributes
,
573 OBJ_CASE_INSENSITIVE
,
577 Status
= NtOpenKey(&ControllerKey
,
578 KEY_ENUMERATE_SUB_KEYS
,
580 if (NT_SUCCESS(Status
))
582 ControllerInstance
= 0;
586 /* Open the pointer controller instance key */
587 RtlStringCchPrintfW(Buffer
, ARRAYSIZE(Buffer
), L
"%lu", ControllerInstance
);
588 RtlInitUnicodeString(&KeyName
, Buffer
);
589 InitializeObjectAttributes(&ObjectAttributes
,
591 OBJ_CASE_INSENSITIVE
,
595 Status
= NtOpenKey(&ControllerInstanceKey
,
598 if (!NT_SUCCESS(Status
))
600 DPRINT("NtOpenKey() failed (Status %lx)\n", Status
);
601 NtClose(ControllerKey
);
602 NtClose(BusInstanceKey
);
607 /* Get controller identifier */
608 RtlInitUnicodeString(&KeyName
, L
"Identifier");
610 BufferLength
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) +
612 ValueInfo
= (KEY_VALUE_PARTIAL_INFORMATION
*) RtlAllocateHeap(RtlGetProcessHeap(),
615 if (ValueInfo
== NULL
)
617 DPRINT("RtlAllocateHeap() failed\n");
618 NtClose(ControllerInstanceKey
);
619 NtClose(ControllerKey
);
620 NtClose(BusInstanceKey
);
625 Status
= NtQueryValueKey(ControllerInstanceKey
,
627 KeyValuePartialInformation
,
631 if (NT_SUCCESS(Status
))
633 DPRINT("Identifier: %S\n", (PWSTR
)ValueInfo
->Data
);
635 BufferLength
= min(ValueInfo
->DataLength
/ sizeof(WCHAR
), IdentifierLength
);
636 RtlCopyMemory(Identifier
,
638 BufferLength
* sizeof(WCHAR
));
639 Identifier
[BufferLength
] = 0;
641 RtlFreeHeap(RtlGetProcessHeap(),
645 NtClose(ControllerInstanceKey
);
646 NtClose(ControllerKey
);
647 NtClose(BusInstanceKey
);
652 NtClose(ControllerInstanceKey
);
654 ControllerInstance
++;
657 NtClose(ControllerKey
);
660 NtClose(BusInstanceKey
);
671 CreateDisplayDriverList(
678 WCHAR DisplayIdentifier
[128];
679 WCHAR DisplayKey
[32];
681 /* Get the display identification */
682 if (!GetDisplayIdentifier(DisplayIdentifier
, 128))
684 DisplayIdentifier
[0] = 0;
687 DPRINT("Display identifier: '%S'\n", DisplayIdentifier
);
689 /* Search for matching device identifier */
690 if (!SetupFindFirstLineW(InfFile
, L
"Map.Display", NULL
, &Context
))
692 /* FIXME: error message */
700 if (!INF_GetDataField(&Context
, 1, &KeyValue
))
702 /* FIXME: Handle error! */
703 DPRINT("INF_GetDataField() failed\n");
707 DPRINT("KeyValue: %S\n", KeyValue
);
708 FoundId
= !!wcsstr(DisplayIdentifier
, KeyValue
);
709 INF_FreeData(KeyValue
);
714 if (!INF_GetDataField(&Context
, 0, &KeyName
))
716 /* FIXME: Handle error! */
717 DPRINT("INF_GetDataField() failed\n");
721 DPRINT("Display key: %S\n", KeyName
);
722 RtlStringCchCopyW(DisplayKey
, ARRAYSIZE(DisplayKey
), KeyName
);
723 INF_FreeData(KeyName
);
724 } while (SetupFindNextLine(&Context
, &Context
));
726 List
= CreateGenericList();
730 if (AddEntriesFromInfSection(List
,
737 DestroyGenericList(List
, TRUE
);
742 AppendGenericListEntry(List
, L
"Other display driver", NULL
, TRUE
);
750 ProcessComputerFiles(
752 IN PGENERIC_LIST List
,
753 OUT PWSTR
* AdditionalSectionName
)
755 PGENERIC_LIST_ENTRY Entry
;
756 static WCHAR SectionName
[128];
758 DPRINT("ProcessComputerFiles() called\n");
760 Entry
= GetCurrentListEntry(List
);
763 DPRINT("GetCurrentListEntry() failed\n");
767 RtlStringCchPrintfW(SectionName
, ARRAYSIZE(SectionName
),
768 L
"Files.%s", (PCWSTR
)GetListEntryUserData(Entry
));
769 *AdditionalSectionName
= SectionName
;
775 ProcessDisplayRegistry(
777 IN PGENERIC_LIST List
)
780 PGENERIC_LIST_ENTRY Entry
;
785 ULONG Width
, Height
, Bpp
;
786 OBJECT_ATTRIBUTES ObjectAttributes
;
787 UNICODE_STRING KeyName
;
791 DPRINT("ProcessDisplayRegistry() called\n");
793 Entry
= GetCurrentListEntry(List
);
796 DPRINT1("GetCurrentListEntry() failed\n");
800 if (!SetupFindFirstLineW(InfFile
, L
"Display", (WCHAR
*)GetListEntryUserData(Entry
), &Context
))
802 DPRINT1("SetupFindFirstLineW() failed\n");
806 /* Enable the correct driver */
807 if (!INF_GetDataField(&Context
, 3, &ServiceName
))
809 DPRINT1("INF_GetDataField() failed\n");
813 ASSERT(wcslen(ServiceName
) < 10);
814 DPRINT1("Service name: '%S'\n", ServiceName
);
816 RtlStringCchPrintfW(RegPath
, ARRAYSIZE(RegPath
),
817 L
"System\\CurrentControlSet\\Services\\%s",
819 RtlInitUnicodeString(&KeyName
, RegPath
);
820 InitializeObjectAttributes(&ObjectAttributes
,
822 OBJ_CASE_INSENSITIVE
,
823 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
825 Status
= NtOpenKey(&KeyHandle
,
828 if (!NT_SUCCESS(Status
))
830 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
835 Status
= RtlWriteRegistryValue(RTL_REGISTRY_HANDLE
, KeyHandle
,
841 if (!NT_SUCCESS(Status
))
843 DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status
);
847 /* Set the resolution */
849 if (!INF_GetDataField(&Context
, 4, &Buffer
))
851 DPRINT1("INF_GetDataField() failed\n");
855 RtlStringCchPrintfW(RegPath
, ARRAYSIZE(RegPath
),
856 L
"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0",
858 DPRINT1("RegPath: '%S'\n", RegPath
);
859 RtlInitUnicodeString(&KeyName
, RegPath
);
860 InitializeObjectAttributes(&ObjectAttributes
,
862 OBJ_CASE_INSENSITIVE
,
863 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
865 Status
= NtOpenKey(&KeyHandle
,
868 if (!NT_SUCCESS(Status
))
870 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
874 Width
= wcstoul(Buffer
, NULL
, 10);
875 Status
= RtlWriteRegistryValue(RTL_REGISTRY_HANDLE
, KeyHandle
,
876 L
"DefaultSettings.XResolution",
880 if (!NT_SUCCESS(Status
))
882 DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status
);
887 if (!INF_GetDataField(&Context
, 5, &Buffer
))
889 DPRINT1("INF_GetDataField() failed\n");
894 Height
= wcstoul(Buffer
, 0, 0);
895 Status
= RtlWriteRegistryValue(RTL_REGISTRY_HANDLE
, KeyHandle
,
896 L
"DefaultSettings.YResolution",
900 if (!NT_SUCCESS(Status
))
902 DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status
);
907 if (!INF_GetDataField(&Context
, 6, &Buffer
))
909 DPRINT1("INF_GetDataField() failed\n");
914 Bpp
= wcstoul(Buffer
, 0, 0);
915 Status
= RtlWriteRegistryValue(RTL_REGISTRY_HANDLE
, KeyHandle
,
916 L
"DefaultSettings.BitsPerPel",
920 if (!NT_SUCCESS(Status
))
922 DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status
);
929 DPRINT("ProcessDisplayRegistry() done\n");
935 ProcessLocaleRegistry(
936 IN PGENERIC_LIST List
)
938 PGENERIC_LIST_ENTRY Entry
;
940 OBJECT_ATTRIBUTES ObjectAttributes
;
941 UNICODE_STRING KeyName
;
942 UNICODE_STRING ValueName
;
947 Entry
= GetCurrentListEntry(List
);
951 LanguageId
= (PWCHAR
)GetListEntryUserData(Entry
);
952 if (LanguageId
== NULL
)
955 DPRINT("LanguageId: %S\n", LanguageId
);
957 /* Open the default users locale key */
958 RtlInitUnicodeString(&KeyName
,
959 L
".DEFAULT\\Control Panel\\International");
961 InitializeObjectAttributes(&ObjectAttributes
,
963 OBJ_CASE_INSENSITIVE
,
964 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
967 Status
= NtOpenKey(&KeyHandle
,
970 if (!NT_SUCCESS(Status
))
972 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
976 /* Set default user locale */
977 RtlInitUnicodeString(&ValueName
, L
"Locale");
978 Status
= NtSetValueKey(KeyHandle
,
983 (wcslen(LanguageId
) + 1) * sizeof(WCHAR
));
985 if (!NT_SUCCESS(Status
))
987 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
991 /* Skip first 4 zeroes */
992 if (wcslen(LanguageId
) >= 4)
995 /* Open the NLS language key */
996 RtlInitUnicodeString(&KeyName
,
997 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\Language");
999 InitializeObjectAttributes(&ObjectAttributes
,
1001 OBJ_CASE_INSENSITIVE
,
1002 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
1005 Status
= NtOpenKey(&KeyHandle
,
1008 if (!NT_SUCCESS(Status
))
1010 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
1014 /* Set default language */
1015 RtlInitUnicodeString(&ValueName
, L
"Default");
1016 Status
= NtSetValueKey(KeyHandle
,
1021 (wcslen(LanguageId
) + 1) * sizeof(WCHAR
));
1022 if (!NT_SUCCESS(Status
))
1024 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
1029 /* Set install language */
1030 RtlInitUnicodeString(&ValueName
, L
"InstallLanguage");
1031 Status
= NtSetValueKey(KeyHandle
,
1036 (wcslen(LanguageId
) + 1) * sizeof(WCHAR
));
1038 if (!NT_SUCCESS(Status
))
1040 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
1049 CreateKeyboardDriverList(
1055 List
= CreateGenericList();
1059 if (AddEntriesFromInfSection(List
,
1063 DefaultProcessEntry
,
1066 DestroyGenericList(List
, TRUE
);
1075 GetDefaultLanguageIndex(VOID
)
1077 return DefaultLanguageIndex
;
1080 typedef struct _LANG_ENTRY_PARAM
1083 PWCHAR DefaultLanguage
;
1084 } LANG_ENTRY_PARAM
, *PLANG_ENTRY_PARAM
;
1091 OUT PWCHAR DisplayText
,
1092 IN SIZE_T DisplayTextSize
,
1093 OUT PVOID
* UserData
,
1094 OUT PBOOLEAN Current
,
1095 IN PVOID Parameter OPTIONAL
)
1097 PLANG_ENTRY_PARAM LangEntryParam
= (PLANG_ENTRY_PARAM
)Parameter
;
1099 if (!IsLanguageAvailable(KeyName
))
1101 /* The specified language is unavailable, skip the entry */
1105 *UserData
= RtlAllocateHeap(ProcessHeap
, 0,
1106 (wcslen(KeyName
) + 1) * sizeof(WCHAR
));
1107 if (*UserData
== NULL
)
1109 /* Failure, stop enumeration */
1110 DPRINT1("RtlAllocateHeap() failed\n");
1114 wcscpy((PWCHAR
)*UserData
, KeyName
);
1115 RtlStringCbCopyW(DisplayText
, DisplayTextSize
, KeyValue
);
1119 if (!_wcsicmp(KeyName
, LangEntryParam
->DefaultLanguage
))
1120 DefaultLanguageIndex
= LangEntryParam
->uIndex
;
1122 LangEntryParam
->uIndex
++;
1131 OUT PWSTR DefaultLanguage
)
1137 LANG_ENTRY_PARAM LangEntryParam
;
1139 LangEntryParam
.uIndex
= 0;
1140 LangEntryParam
.DefaultLanguage
= DefaultLanguage
;
1142 /* Get default language id */
1143 if (!SetupFindFirstLineW(InfFile
, L
"NLS", L
"DefaultLanguage", &Context
))
1146 if (!INF_GetData(&Context
, NULL
, &KeyValue
))
1149 wcscpy(DefaultLanguage
, KeyValue
);
1151 List
= CreateGenericList();
1155 if (AddEntriesFromInfSection(List
,
1160 &LangEntryParam
) == -1)
1162 DestroyGenericList(List
, TRUE
);
1166 /* Only one language available, make it the default one */
1167 if (LangEntryParam
.uIndex
== 1)
1169 DefaultLanguageIndex
= 0;
1170 wcscpy(DefaultLanguage
,
1171 (PWSTR
)GetListEntryUserData(GetFirstListEntry(List
)));
1179 CreateKeyboardLayoutList(
1181 IN PCWSTR LanguageId
,
1182 OUT PWSTR DefaultKBLayout
)
1187 const MUI_LAYOUTS
* LayoutsList
;
1190 /* Get default layout id */
1191 if (!SetupFindFirstLineW(InfFile
, L
"NLS", L
"DefaultLayout", &Context
))
1194 if (!INF_GetData(&Context
, NULL
, &KeyValue
))
1197 wcscpy(DefaultKBLayout
, KeyValue
);
1199 List
= CreateGenericList();
1203 LayoutsList
= MUIGetLayoutsList(LanguageId
);
1207 // NOTE: See https://svn.reactos.org/svn/reactos?view=revision&revision=68354
1208 if (AddEntriesFromInfSection(List
,
1212 DefaultProcessEntry
,
1213 DefaultKBLayout
) == -1)
1215 DestroyGenericList(List
, TRUE
);
1221 } while (LayoutsList
[uIndex
].LangID
!= NULL
);
1223 /* Check whether some keyboard layouts have been found */
1224 /* FIXME: Handle this case */
1225 if (GetNumberOfListEntries(List
) == 0)
1227 DPRINT1("No keyboard layouts have been found\n");
1228 DestroyGenericList(List
, TRUE
);
1237 ProcessKeyboardLayoutRegistry(
1238 IN PGENERIC_LIST List
,
1239 IN PCWSTR LanguageId
)
1241 PGENERIC_LIST_ENTRY Entry
;
1243 const MUI_LAYOUTS
* LayoutsList
;
1244 MUI_LAYOUTS NewLayoutsList
[20];
1248 Entry
= GetCurrentListEntry(List
);
1252 LayoutId
= (PWCHAR
)GetListEntryUserData(Entry
);
1253 if (LayoutId
== NULL
)
1256 LayoutsList
= MUIGetLayoutsList(LanguageId
);
1258 if (_wcsicmp(LayoutsList
[0].LayoutID
, LayoutId
) == 0)
1261 for (uIndex
= 1; LayoutsList
[uIndex
].LangID
!= NULL
; uIndex
++)
1263 if (_wcsicmp(LayoutsList
[uIndex
].LayoutID
, LayoutId
) == 0)
1269 NewLayoutsList
[uIndex
].LangID
= LayoutsList
[uIndex
].LangID
;
1270 NewLayoutsList
[uIndex
].LayoutID
= LayoutsList
[uIndex
].LayoutID
;
1273 NewLayoutsList
[uIndex
].LangID
= NULL
;
1274 NewLayoutsList
[uIndex
].LayoutID
= NULL
;
1275 NewLayoutsList
[uOldPos
].LangID
= LayoutsList
[0].LangID
;
1276 NewLayoutsList
[uOldPos
].LayoutID
= LayoutsList
[0].LayoutID
;
1277 NewLayoutsList
[0].LangID
= LayoutsList
[uOldPos
].LangID
;
1278 NewLayoutsList
[0].LayoutID
= LayoutsList
[uOldPos
].LayoutID
;
1280 return AddKbLayoutsToRegistry(NewLayoutsList
);
1285 ProcessKeyboardLayoutFiles(
1286 IN PGENERIC_LIST List
)
1297 OBJECT_ATTRIBUTES ObjectAttributes
;
1298 UNICODE_STRING Name
;
1301 RtlInitUnicodeString(&Name
,
1302 L
".DEFAULT\\Control Panel\\International\\Geo");
1303 InitializeObjectAttributes(&ObjectAttributes
,
1305 OBJ_CASE_INSENSITIVE
,
1306 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
1308 Status
= NtOpenKey(&KeyHandle
,
1311 if (!NT_SUCCESS(Status
))
1313 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
1317 RtlInitUnicodeString(&Name
, L
"Nation");
1318 Status
= NtSetValueKey(KeyHandle
,
1323 (wcslen(Id
) + 1) * sizeof(WCHAR
));
1325 if (!NT_SUCCESS(Status
))
1327 DPRINT1("NtSetValueKey() failed (Status = %lx)\n", Status
);
1341 OBJECT_ATTRIBUTES ObjectAttributes
;
1342 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management");
1343 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"PagingFiles");
1344 WCHAR ValueBuffer
[] = L
"?:\\pagefile.sys 0 0\0";
1346 InitializeObjectAttributes(&ObjectAttributes
,
1348 OBJ_CASE_INSENSITIVE
,
1349 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
1351 Status
= NtOpenKey(&KeyHandle
,
1354 if (!NT_SUCCESS(Status
))
1357 ValueBuffer
[0] = Drive
;
1359 NtSetValueKey(KeyHandle
,
1363 (PVOID
)&ValueBuffer
,
1364 sizeof(ValueBuffer
));