Remove mouse type selection in usetup.
[reactos.git] / reactos / subsys / system / usetup / settings.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /* $Id$
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
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include "usetup.h"
30
31 #define NDEBUG
32 #include <debug.h>
33
34 /* FUNCTIONS ****************************************************************/
35
36 PGENERIC_LIST
37 CreateComputerTypeList(HINF InfFile)
38 {
39 CHAR Buffer[128];
40 PGENERIC_LIST List;
41 INFCONTEXT Context;
42 PWCHAR KeyName;
43 PWCHAR KeyValue;
44 PWCHAR UserData;
45
46 List = CreateGenericList();
47 if (List == NULL)
48 return NULL;
49
50 if (!InfFindFirstLine (InfFile, L"Computer", NULL, &Context))
51 {
52 DestroyGenericList(List, FALSE);
53 return NULL;
54 }
55
56 do
57 {
58 if (!InfGetData (&Context, &KeyName, &KeyValue))
59 {
60 /* FIXME: Handle error! */
61 DPRINT("InfGetData() failed\n");
62 break;
63 }
64
65 UserData = RtlAllocateHeap(ProcessHeap,
66 0,
67 (wcslen(KeyName) + 1) * sizeof(WCHAR));
68 if (UserData == NULL)
69 {
70 /* FIXME: Handle error! */
71 }
72
73 wcscpy(UserData, KeyName);
74
75 sprintf(Buffer, "%S", KeyValue);
76 AppendGenericListEntry(List, Buffer, UserData, FALSE);
77 }
78 while (InfFindNextLine(&Context, &Context));
79
80 return List;
81 }
82
83
84 static BOOLEAN
85 GetDisplayIdentifier(PWSTR Identifier,
86 ULONG IdentifierLength)
87 {
88 OBJECT_ATTRIBUTES ObjectAttributes;
89 UNICODE_STRING KeyName;
90 WCHAR Buffer[32];
91 HANDLE BusKey;
92 HANDLE BusInstanceKey;
93 HANDLE ControllerKey;
94 HANDLE ControllerInstanceKey;
95 ULONG BusInstance;
96 ULONG ControllerInstance;
97 ULONG BufferLength;
98 ULONG ReturnedLength;
99 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
100 NTSTATUS Status;
101
102 DPRINT("GetDisplayIdentifier() called\n");
103
104 /* Open the bus key */
105 RtlInitUnicodeString(&KeyName,
106 L"\\Registry\\Machine\\HARDWARE\\Description\\System\\MultifunctionAdapter");
107 InitializeObjectAttributes(&ObjectAttributes,
108 &KeyName,
109 OBJ_CASE_INSENSITIVE,
110 NULL,
111 NULL);
112 Status = NtOpenKey(&BusKey,
113 KEY_ALL_ACCESS,
114 &ObjectAttributes);
115 if (!NT_SUCCESS(Status))
116 {
117 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
118 return FALSE;
119 }
120
121 BusInstance = 0;
122 while (TRUE)
123 {
124 swprintf(Buffer, L"%lu", BusInstance);
125 RtlInitUnicodeString(&KeyName,
126 Buffer);
127 InitializeObjectAttributes(&ObjectAttributes,
128 &KeyName,
129 OBJ_CASE_INSENSITIVE,
130 BusKey,
131 NULL);
132 Status = NtOpenKey(&BusInstanceKey,
133 KEY_ALL_ACCESS,
134 &ObjectAttributes);
135 if (!NT_SUCCESS(Status))
136 {
137 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
138 NtClose(BusKey);
139 return FALSE;
140 }
141
142 /* Open the controller type key */
143 RtlInitUnicodeString(&KeyName,
144 L"DisplayController");
145 InitializeObjectAttributes(&ObjectAttributes,
146 &KeyName,
147 OBJ_CASE_INSENSITIVE,
148 BusInstanceKey,
149 NULL);
150 Status = NtOpenKey(&ControllerKey,
151 KEY_ALL_ACCESS,
152 &ObjectAttributes);
153 if (NT_SUCCESS(Status))
154 {
155 ControllerInstance = 0;
156 while (TRUE)
157 {
158 /* Open the pointer controller instance key */
159 swprintf(Buffer, L"%lu", ControllerInstance);
160 RtlInitUnicodeString(&KeyName,
161 Buffer);
162 InitializeObjectAttributes(&ObjectAttributes,
163 &KeyName,
164 OBJ_CASE_INSENSITIVE,
165 ControllerKey,
166 NULL);
167 Status = NtOpenKey(&ControllerInstanceKey,
168 KEY_ALL_ACCESS,
169 &ObjectAttributes);
170 if (!NT_SUCCESS(Status))
171 {
172 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
173 NtClose(ControllerKey);
174 NtClose(BusInstanceKey);
175 NtClose(BusKey);
176 return FALSE;
177 }
178
179 /* Get controller identifier */
180 RtlInitUnicodeString(&KeyName,
181 L"Identifier");
182
183 BufferLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
184 256 * sizeof(WCHAR);
185 ValueInfo = RtlAllocateHeap(RtlGetProcessHeap(),
186 0,
187 BufferLength);
188 if (ValueInfo == NULL)
189 {
190 DPRINT("RtlAllocateHeap() failed\n");
191 NtClose(ControllerInstanceKey);
192 NtClose(ControllerKey);
193 NtClose(BusInstanceKey);
194 NtClose(BusKey);
195 return FALSE;
196 }
197
198 Status = NtQueryValueKey(ControllerInstanceKey,
199 &KeyName,
200 KeyValuePartialInformation,
201 ValueInfo,
202 BufferLength,
203 &ReturnedLength);
204 if (NT_SUCCESS(Status))
205 {
206 DPRINT("Identifier: %S\n", (PWSTR)ValueInfo->Data);
207
208 BufferLength = min(ValueInfo->DataLength / sizeof(WCHAR), IdentifierLength);
209 RtlCopyMemory (Identifier,
210 ValueInfo->Data,
211 BufferLength * sizeof(WCHAR));
212 Identifier[BufferLength] = 0;
213
214 RtlFreeHeap(RtlGetProcessHeap(),
215 0,
216 ValueInfo);
217 NtClose(ControllerInstanceKey);
218 NtClose(ControllerKey);
219 NtClose(BusInstanceKey);
220 NtClose(BusKey);
221 return TRUE;
222 }
223
224 NtClose(ControllerInstanceKey);
225
226 ControllerInstance++;
227 }
228
229 NtClose(ControllerKey);
230 }
231
232 NtClose(BusInstanceKey);
233
234 BusInstance++;
235 }
236
237 NtClose(BusKey);
238
239 return FALSE;
240 }
241
242
243 PGENERIC_LIST
244 CreateDisplayDriverList(HINF InfFile)
245 {
246 CHAR Buffer[128];
247 PGENERIC_LIST List;
248 INFCONTEXT Context;
249 PWCHAR KeyName;
250 PWCHAR KeyValue;
251 PWCHAR UserData;
252 WCHAR DisplayIdentifier[128];
253 WCHAR DisplayKey[32];
254
255 /* Get the display identification */
256 if (!GetDisplayIdentifier(DisplayIdentifier, 128))
257 {
258 DisplayIdentifier[0] = 0;
259 }
260
261 DPRINT("Display identifier: '%S'\n", DisplayIdentifier);
262
263 /* Search for matching device identifier */
264 if (!InfFindFirstLine(InfFile, L"Map.Display", NULL, &Context))
265 {
266 /* FIXME: error message */
267 return NULL;
268 }
269
270 do
271 {
272 if (!InfGetDataField(&Context, 1, &KeyValue))
273 {
274 /* FIXME: Handle error! */
275 DPRINT("InfGetDataField() failed\n");
276 return NULL;
277 }
278
279 DPRINT("KeyValue: %S\n", KeyValue);
280 if (wcsstr(DisplayIdentifier, KeyValue))
281 {
282 if (!InfGetDataField(&Context, 0, &KeyName))
283 {
284 /* FIXME: Handle error! */
285 DPRINT("InfGetDataField() failed\n");
286 return NULL;
287 }
288
289 DPRINT("Display key: %S\n", KeyName);
290 wcscpy(DisplayKey, KeyName);
291 }
292 }
293 while (InfFindNextLine(&Context, &Context));
294
295
296 List = CreateGenericList();
297 if (List == NULL)
298 return NULL;
299
300 if (!InfFindFirstLine (InfFile, L"Display", NULL, &Context))
301 {
302 DestroyGenericList(List, FALSE);
303 return NULL;
304 }
305
306 do
307 {
308 if (!InfGetDataField(&Context, 0, &KeyName))
309 {
310 DPRINT1("InfGetDataField() failed\n");
311 break;
312 }
313
314 if (!InfGetDataField(&Context, 1, &KeyValue))
315 {
316 DPRINT1("InfGetDataField() failed\n");
317 break;
318 }
319
320 UserData = RtlAllocateHeap(ProcessHeap,
321 0,
322 (wcslen(KeyName) + 1) * sizeof(WCHAR));
323 if (UserData == NULL)
324 {
325 DPRINT1("RtlAllocateHeap() failed\n");
326 DestroyGenericList(List, TRUE);
327 return NULL;
328 }
329
330 wcscpy(UserData, KeyName);
331
332 sprintf(Buffer, "%S", KeyValue);
333 AppendGenericListEntry(List,
334 Buffer,
335 UserData,
336 _wcsicmp(KeyName, DisplayKey) ? FALSE : TRUE);
337 }
338 while (InfFindNextLine(&Context, &Context));
339
340 #if 0
341 AppendGenericListEntry(List, "Other display driver", NULL, TRUE);
342 #endif
343
344 return List;
345 }
346
347 BOOLEAN
348 ProcessComputerFiles(HINF InfFile, PGENERIC_LIST List, PWCHAR* AdditionalSectionName)
349 {
350 PGENERIC_LIST_ENTRY Entry;
351 static WCHAR SectionName[128];
352
353 DPRINT("ProcessComputerFiles() called\n");
354
355 Entry = GetGenericListEntry(List);
356 if (Entry == NULL)
357 {
358 DPRINT("GetGenericListEntry() failed\n");
359 return FALSE;
360 }
361
362 wcscpy(SectionName, L"Files.");
363 wcscat(SectionName, Entry->UserData);
364 *AdditionalSectionName = SectionName;
365
366 return TRUE;
367 }
368
369
370 BOOLEAN
371 ProcessDisplayRegistry(HINF InfFile, PGENERIC_LIST List)
372 {
373 PGENERIC_LIST_ENTRY Entry;
374 INFCONTEXT Context;
375 PWCHAR ServiceName;
376 ULONG StartValue;
377 NTSTATUS Status;
378
379 DPRINT("ProcessDisplayRegistry() called\n");
380
381 Entry = GetGenericListEntry(List);
382 if (Entry == NULL)
383 {
384 DPRINT("GetGenericListEntry() failed\n");
385 return FALSE;
386 }
387
388 if (!InfFindFirstLine(InfFile, L"Display", Entry->UserData, &Context))
389 {
390 DPRINT("InfFindFirstLine() failed\n");
391 return FALSE;
392 }
393
394 if (!InfGetDataField(&Context, 3, &ServiceName))
395 {
396 DPRINT("InfGetDataField() failed\n");
397 return FALSE;
398 }
399
400 DPRINT("Service name: %S\n", ServiceName);
401
402 StartValue = 1;
403 Status = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES,
404 ServiceName,
405 L"Start",
406 REG_DWORD,
407 &StartValue,
408 sizeof(ULONG));
409 if (!NT_SUCCESS(Status))
410 {
411 DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
412 return FALSE;
413 }
414
415 DPRINT("ProcessDisplayRegistry() done\n");
416
417 return TRUE;
418 }
419
420
421 PGENERIC_LIST
422 CreateKeyboardDriverList(HINF InfFile)
423 {
424 CHAR Buffer[128];
425 PGENERIC_LIST List;
426 INFCONTEXT Context;
427 PWCHAR KeyName;
428 PWCHAR KeyValue;
429 PWCHAR UserData;
430
431 List = CreateGenericList();
432 if (List == NULL)
433 return NULL;
434
435 if (!InfFindFirstLine (InfFile, L"Keyboard", NULL, &Context))
436 {
437 DestroyGenericList(List, FALSE);
438 return NULL;
439 }
440
441 do
442 {
443 if (!InfGetData (&Context, &KeyName, &KeyValue))
444 {
445 /* FIXME: Handle error! */
446 DPRINT("InfGetData() failed\n");
447 break;
448 }
449
450 UserData = RtlAllocateHeap(ProcessHeap,
451 0,
452 (wcslen(KeyName) + 1) * sizeof(WCHAR));
453 if (UserData == NULL)
454 {
455 /* FIXME: Handle error! */
456 }
457
458 wcscpy(UserData, KeyName);
459
460 sprintf(Buffer, "%S", KeyValue);
461 AppendGenericListEntry(List, Buffer, UserData, FALSE);
462 }
463 while (InfFindNextLine(&Context, &Context));
464
465 return List;
466 }
467
468
469 PGENERIC_LIST
470 CreateKeyboardLayoutList(HINF InfFile)
471 {
472 CHAR Buffer[128];
473 PGENERIC_LIST List;
474 INFCONTEXT Context;
475 PWCHAR KeyName;
476 PWCHAR KeyValue;
477 PWCHAR UserData;
478 WCHAR DefaultLayout[20];
479
480 /* Get default layout id */
481 if (!InfFindFirstLine (InfFile, L"NLS", L"DefaultLayout", &Context))
482 return NULL;
483
484 if (!InfGetData (&Context, NULL, &KeyValue))
485 return NULL;
486
487 wcscpy(DefaultLayout, KeyValue);
488
489 List = CreateGenericList();
490 if (List == NULL)
491 return NULL;
492
493 if (!InfFindFirstLine (InfFile, L"KeyboardLayout", NULL, &Context))
494 {
495 DestroyGenericList(List, FALSE);
496 return NULL;
497 }
498
499 do
500 {
501 if (!InfGetData (&Context, &KeyName, &KeyValue))
502 {
503 /* FIXME: Handle error! */
504 DPRINT("InfGetData() failed\n");
505 break;
506 }
507
508 UserData = RtlAllocateHeap(ProcessHeap,
509 0,
510 (wcslen(KeyName) + 1) * sizeof(WCHAR));
511 if (UserData == NULL)
512 {
513 /* FIXME: Handle error! */
514 }
515
516 wcscpy(UserData, KeyName);
517
518 sprintf(Buffer, "%S", KeyValue);
519 AppendGenericListEntry(List,
520 Buffer,
521 UserData,
522 _wcsicmp(KeyName, DefaultLayout) ? FALSE : TRUE);
523 }
524 while (InfFindNextLine(&Context, &Context));
525
526 return List;
527 }
528
529
530 BOOLEAN
531 ProcessKeyboardLayoutRegistry(PGENERIC_LIST List)
532 {
533 PGENERIC_LIST_ENTRY Entry;
534 PWCHAR LanguageId;
535 OBJECT_ATTRIBUTES ObjectAttributes;
536 UNICODE_STRING KeyName;
537 UNICODE_STRING ValueName;
538 HANDLE KeyHandle;
539 NTSTATUS Status;
540
541 Entry = GetGenericListEntry(List);
542 if (Entry == NULL)
543 return FALSE;
544
545 LanguageId = (PWCHAR)Entry->UserData;
546 if (LanguageId == NULL)
547 return FALSE;
548
549 /* Open the nls language key */
550 RtlInitUnicodeString(&KeyName,
551 L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language");
552 InitializeObjectAttributes(&ObjectAttributes,
553 &KeyName,
554 OBJ_CASE_INSENSITIVE,
555 NULL,
556 NULL);
557 Status = NtOpenKey(&KeyHandle,
558 KEY_ALL_ACCESS,
559 &ObjectAttributes);
560 if (!NT_SUCCESS(Status))
561 {
562 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status);
563 return FALSE;
564 }
565
566 /* Set default language */
567 RtlInitUnicodeString(&ValueName,
568 L"Default");
569 Status = NtSetValueKey (KeyHandle,
570 &ValueName,
571 0,
572 REG_SZ,
573 (PVOID)(LanguageId + 4),
574 8);
575 if (!NT_SUCCESS(Status))
576 {
577 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
578 NtClose(KeyHandle);
579 return FALSE;
580 }
581
582 /* Set install language */
583 RtlInitUnicodeString(&ValueName,
584 L"InstallLanguage");
585 Status = NtSetValueKey (KeyHandle,
586 &ValueName,
587 0,
588 REG_SZ,
589 (PVOID)(LanguageId + 4),
590 8);
591 if (!NT_SUCCESS(Status))
592 {
593 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
594 NtClose(KeyHandle);
595 return FALSE;
596 }
597
598 NtClose(KeyHandle);
599
600 return TRUE;
601 }
602
603
604 #if 0
605 BOOLEAN
606 ProcessKeyboardLayoutFiles(PGENERIC_LIST List)
607 {
608 return TRUE;
609 }
610 #endif
611
612 /* EOF */