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
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/settings.c
23 * PURPOSE: Device settings support functions
24 * PROGRAMMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
34 /* FUNCTIONS ****************************************************************/
37 CreateComputerTypeList(HINF InfFile
)
46 List
= CreateGenericList();
50 if (!InfFindFirstLine (InfFile
, L
"Computer", NULL
, &Context
))
52 DestroyGenericList(List
, FALSE
);
58 if (!InfGetData (&Context
, &KeyName
, &KeyValue
))
60 /* FIXME: Handle error! */
61 DPRINT("InfGetData() failed\n");
65 UserData
= RtlAllocateHeap(ProcessHeap
,
67 (wcslen(KeyName
) + 1) * sizeof(WCHAR
));
70 /* FIXME: Handle error! */
73 wcscpy(UserData
, KeyName
);
75 sprintf(Buffer
, "%S", KeyValue
);
76 AppendGenericListEntry(List
, Buffer
, UserData
, FALSE
);
78 while (InfFindNextLine(&Context
, &Context
));
85 GetDisplayIdentifier(PWSTR Identifier
,
86 ULONG IdentifierLength
)
88 OBJECT_ATTRIBUTES ObjectAttributes
;
89 UNICODE_STRING KeyName
;
92 HANDLE BusInstanceKey
;
94 HANDLE ControllerInstanceKey
;
96 ULONG ControllerInstance
;
99 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo
;
102 DPRINT("GetDisplayIdentifier() called\n");
104 /* Open the bus key */
105 RtlInitUnicodeString(&KeyName
,
106 L
"\\Registry\\Machine\\HARDWARE\\Description\\System\\MultifunctionAdapter");
107 InitializeObjectAttributes(&ObjectAttributes
,
109 OBJ_CASE_INSENSITIVE
,
112 Status
= NtOpenKey(&BusKey
,
115 if (!NT_SUCCESS(Status
))
117 DPRINT("NtOpenKey() failed (Status %lx)\n", Status
);
124 swprintf(Buffer
, L
"%lu", BusInstance
);
125 RtlInitUnicodeString(&KeyName
,
127 InitializeObjectAttributes(&ObjectAttributes
,
129 OBJ_CASE_INSENSITIVE
,
132 Status
= NtOpenKey(&BusInstanceKey
,
135 if (!NT_SUCCESS(Status
))
137 DPRINT("NtOpenKey() failed (Status %lx)\n", Status
);
142 /* Open the controller type key */
143 RtlInitUnicodeString(&KeyName
,
144 L
"DisplayController");
145 InitializeObjectAttributes(&ObjectAttributes
,
147 OBJ_CASE_INSENSITIVE
,
150 Status
= NtOpenKey(&ControllerKey
,
153 if (NT_SUCCESS(Status
))
155 ControllerInstance
= 0;
158 /* Open the pointer controller instance key */
159 swprintf(Buffer
, L
"%lu", ControllerInstance
);
160 RtlInitUnicodeString(&KeyName
,
162 InitializeObjectAttributes(&ObjectAttributes
,
164 OBJ_CASE_INSENSITIVE
,
167 Status
= NtOpenKey(&ControllerInstanceKey
,
170 if (!NT_SUCCESS(Status
))
172 DPRINT("NtOpenKey() failed (Status %lx)\n", Status
);
173 NtClose(ControllerKey
);
174 NtClose(BusInstanceKey
);
179 /* Get controller identifier */
180 RtlInitUnicodeString(&KeyName
,
183 BufferLength
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) +
185 ValueInfo
= RtlAllocateHeap(RtlGetProcessHeap(),
188 if (ValueInfo
== NULL
)
190 DPRINT("RtlAllocateHeap() failed\n");
191 NtClose(ControllerInstanceKey
);
192 NtClose(ControllerKey
);
193 NtClose(BusInstanceKey
);
198 Status
= NtQueryValueKey(ControllerInstanceKey
,
200 KeyValuePartialInformation
,
204 if (NT_SUCCESS(Status
))
206 DPRINT("Identifier: %S\n", (PWSTR
)ValueInfo
->Data
);
208 BufferLength
= min(ValueInfo
->DataLength
/ sizeof(WCHAR
), IdentifierLength
);
209 RtlCopyMemory (Identifier
,
211 BufferLength
* sizeof(WCHAR
));
212 Identifier
[BufferLength
] = 0;
214 RtlFreeHeap(RtlGetProcessHeap(),
217 NtClose(ControllerInstanceKey
);
218 NtClose(ControllerKey
);
219 NtClose(BusInstanceKey
);
224 NtClose(ControllerInstanceKey
);
226 ControllerInstance
++;
229 NtClose(ControllerKey
);
232 NtClose(BusInstanceKey
);
244 CreateDisplayDriverList(HINF InfFile
)
252 WCHAR DisplayIdentifier
[128];
253 WCHAR DisplayKey
[32];
255 /* Get the display identification */
256 if (!GetDisplayIdentifier(DisplayIdentifier
, 128))
258 DisplayIdentifier
[0] = 0;
261 DPRINT("Display identifier: '%S'\n", DisplayIdentifier
);
263 /* Search for matching device identifier */
264 if (!InfFindFirstLine(InfFile
, L
"Map.Display", NULL
, &Context
))
266 /* FIXME: error message */
272 if (!InfGetDataField(&Context
, 1, &KeyValue
))
274 /* FIXME: Handle error! */
275 DPRINT("InfGetDataField() failed\n");
279 DPRINT("KeyValue: %S\n", KeyValue
);
280 if (wcsstr(DisplayIdentifier
, KeyValue
))
282 if (!InfGetDataField(&Context
, 0, &KeyName
))
284 /* FIXME: Handle error! */
285 DPRINT("InfGetDataField() failed\n");
289 DPRINT("Display key: %S\n", KeyName
);
290 wcscpy(DisplayKey
, KeyName
);
293 while (InfFindNextLine(&Context
, &Context
));
296 List
= CreateGenericList();
300 if (!InfFindFirstLine (InfFile
, L
"Display", NULL
, &Context
))
302 DestroyGenericList(List
, FALSE
);
308 if (!InfGetDataField(&Context
, 0, &KeyName
))
310 DPRINT1("InfGetDataField() failed\n");
314 if (!InfGetDataField(&Context
, 1, &KeyValue
))
316 DPRINT1("InfGetDataField() failed\n");
320 UserData
= RtlAllocateHeap(ProcessHeap
,
322 (wcslen(KeyName
) + 1) * sizeof(WCHAR
));
323 if (UserData
== NULL
)
325 DPRINT1("RtlAllocateHeap() failed\n");
326 DestroyGenericList(List
, TRUE
);
330 wcscpy(UserData
, KeyName
);
332 sprintf(Buffer
, "%S", KeyValue
);
333 AppendGenericListEntry(List
,
336 _wcsicmp(KeyName
, DisplayKey
) ? FALSE
: TRUE
);
338 while (InfFindNextLine(&Context
, &Context
));
341 AppendGenericListEntry(List
, "Other display driver", NULL
, TRUE
);
348 ProcessComputerFiles(HINF InfFile
, PGENERIC_LIST List
, PWCHAR
* AdditionalSectionName
)
350 PGENERIC_LIST_ENTRY Entry
;
351 static WCHAR SectionName
[128];
353 DPRINT("ProcessComputerFiles() called\n");
355 Entry
= GetGenericListEntry(List
);
358 DPRINT("GetGenericListEntry() failed\n");
362 wcscpy(SectionName
, L
"Files.");
363 wcscat(SectionName
, Entry
->UserData
);
364 *AdditionalSectionName
= SectionName
;
371 ProcessDisplayRegistry(HINF InfFile
, PGENERIC_LIST List
)
373 PGENERIC_LIST_ENTRY Entry
;
379 DPRINT("ProcessDisplayRegistry() called\n");
381 Entry
= GetGenericListEntry(List
);
384 DPRINT("GetGenericListEntry() failed\n");
388 if (!InfFindFirstLine(InfFile
, L
"Display", Entry
->UserData
, &Context
))
390 DPRINT("InfFindFirstLine() failed\n");
394 if (!InfGetDataField(&Context
, 3, &ServiceName
))
396 DPRINT("InfGetDataField() failed\n");
400 DPRINT("Service name: %S\n", ServiceName
);
403 Status
= RtlWriteRegistryValue(RTL_REGISTRY_SERVICES
,
409 if (!NT_SUCCESS(Status
))
411 DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status
);
415 DPRINT("ProcessDisplayRegistry() done\n");
422 CreateKeyboardDriverList(HINF InfFile
)
431 List
= CreateGenericList();
435 if (!InfFindFirstLine (InfFile
, L
"Keyboard", NULL
, &Context
))
437 DestroyGenericList(List
, FALSE
);
443 if (!InfGetData (&Context
, &KeyName
, &KeyValue
))
445 /* FIXME: Handle error! */
446 DPRINT("InfGetData() failed\n");
450 UserData
= RtlAllocateHeap(ProcessHeap
,
452 (wcslen(KeyName
) + 1) * sizeof(WCHAR
));
453 if (UserData
== NULL
)
455 /* FIXME: Handle error! */
458 wcscpy(UserData
, KeyName
);
460 sprintf(Buffer
, "%S", KeyValue
);
461 AppendGenericListEntry(List
, Buffer
, UserData
, FALSE
);
463 while (InfFindNextLine(&Context
, &Context
));
470 CreateKeyboardLayoutList(HINF InfFile
)
478 WCHAR DefaultLayout
[20];
480 /* Get default layout id */
481 if (!InfFindFirstLine (InfFile
, L
"NLS", L
"DefaultLayout", &Context
))
484 if (!InfGetData (&Context
, NULL
, &KeyValue
))
487 wcscpy(DefaultLayout
, KeyValue
);
489 List
= CreateGenericList();
493 if (!InfFindFirstLine (InfFile
, L
"KeyboardLayout", NULL
, &Context
))
495 DestroyGenericList(List
, FALSE
);
501 if (!InfGetData (&Context
, &KeyName
, &KeyValue
))
503 /* FIXME: Handle error! */
504 DPRINT("InfGetData() failed\n");
508 UserData
= RtlAllocateHeap(ProcessHeap
,
510 (wcslen(KeyName
) + 1) * sizeof(WCHAR
));
511 if (UserData
== NULL
)
513 /* FIXME: Handle error! */
516 wcscpy(UserData
, KeyName
);
518 sprintf(Buffer
, "%S", KeyValue
);
519 AppendGenericListEntry(List
,
522 _wcsicmp(KeyName
, DefaultLayout
) ? FALSE
: TRUE
);
524 while (InfFindNextLine(&Context
, &Context
));
531 ProcessKeyboardLayoutRegistry(PGENERIC_LIST List
)
533 PGENERIC_LIST_ENTRY Entry
;
535 OBJECT_ATTRIBUTES ObjectAttributes
;
536 UNICODE_STRING KeyName
;
537 UNICODE_STRING ValueName
;
541 Entry
= GetGenericListEntry(List
);
545 LanguageId
= (PWCHAR
)Entry
->UserData
;
546 if (LanguageId
== NULL
)
549 /* Open the nls language key */
550 RtlInitUnicodeString(&KeyName
,
551 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language");
552 InitializeObjectAttributes(&ObjectAttributes
,
554 OBJ_CASE_INSENSITIVE
,
557 Status
= NtOpenKey(&KeyHandle
,
560 if (!NT_SUCCESS(Status
))
562 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
566 /* Set default language */
567 RtlInitUnicodeString(&ValueName
,
569 Status
= NtSetValueKey (KeyHandle
,
573 (PVOID
)(LanguageId
+ 4),
575 if (!NT_SUCCESS(Status
))
577 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
582 /* Set install language */
583 RtlInitUnicodeString(&ValueName
,
585 Status
= NtSetValueKey (KeyHandle
,
589 (PVOID
)(LanguageId
+ 4),
591 if (!NT_SUCCESS(Status
))
593 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
606 ProcessKeyboardLayoutFiles(PGENERIC_LIST List
)