Don't set the default locale id.
[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: settings.c,v 1.6 2004/11/15 14:41:25 ekohl Exp $
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 "precomp.h"
30 #include <ntdll/rtl.h>
31 #include <ntos/minmax.h>
32
33 #include "usetup.h"
34 #include "infcache.h"
35 #include "genlist.h"
36 #include "settings.h"
37
38 #define NDEBUG
39 #include <debug.h>
40
41
42 /* FUNCTIONS ****************************************************************/
43
44 PGENERIC_LIST
45 CreateComputerTypeList(HINF InfFile)
46 {
47 CHAR Buffer[128];
48 PGENERIC_LIST List;
49 INFCONTEXT Context;
50 PWCHAR KeyName;
51 PWCHAR KeyValue;
52 PWCHAR UserData;
53
54 List = CreateGenericList();
55 if (List == NULL)
56 return NULL;
57
58 if (!InfFindFirstLine (InfFile, L"Computer", NULL, &Context))
59 {
60 DestroyGenericList(List, FALSE);
61 return NULL;
62 }
63
64 do
65 {
66 if (!InfGetData (&Context, &KeyName, &KeyValue))
67 {
68 /* FIXME: Handle error! */
69 DPRINT("InfGetData() failed\n");
70 break;
71 }
72
73 UserData = RtlAllocateHeap(ProcessHeap,
74 0,
75 (wcslen(KeyName) + 1) * sizeof(WCHAR));
76 if (UserData == NULL)
77 {
78 /* FIXME: Handle error! */
79 }
80
81 wcscpy(UserData, KeyName);
82
83 sprintf(Buffer, "%S", KeyValue);
84 AppendGenericListEntry(List, Buffer, UserData, FALSE);
85 }
86 while (InfFindNextLine(&Context, &Context));
87
88 return List;
89 }
90
91
92 static BOOLEAN
93 GetDisplayIdentifier(PWSTR Identifier,
94 ULONG IdentifierLength)
95 {
96 OBJECT_ATTRIBUTES ObjectAttributes;
97 UNICODE_STRING KeyName;
98 WCHAR Buffer[32];
99 HANDLE BusKey;
100 HANDLE BusInstanceKey;
101 HANDLE ControllerKey;
102 HANDLE ControllerInstanceKey;
103 ULONG BusInstance;
104 ULONG ControllerInstance;
105 ULONG BufferLength;
106 ULONG ReturnedLength;
107 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
108 NTSTATUS Status;
109
110 DPRINT("GetDisplayIdentifier() called\n");
111
112 /* Open the bus key */
113 RtlInitUnicodeString(&KeyName,
114 L"\\Registry\\Machine\\HARDWARE\\Description\\System\\MultifunctionAdapter");
115 InitializeObjectAttributes(&ObjectAttributes,
116 &KeyName,
117 OBJ_CASE_INSENSITIVE,
118 NULL,
119 NULL);
120 Status = NtOpenKey(&BusKey,
121 KEY_ALL_ACCESS,
122 &ObjectAttributes);
123 if (!NT_SUCCESS(Status))
124 {
125 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
126 return FALSE;
127 }
128
129 BusInstance = 0;
130 while (TRUE)
131 {
132 swprintf(Buffer, L"%lu", BusInstance);
133 RtlInitUnicodeString(&KeyName,
134 Buffer);
135 InitializeObjectAttributes(&ObjectAttributes,
136 &KeyName,
137 OBJ_CASE_INSENSITIVE,
138 BusKey,
139 NULL);
140 Status = NtOpenKey(&BusInstanceKey,
141 KEY_ALL_ACCESS,
142 &ObjectAttributes);
143 if (!NT_SUCCESS(Status))
144 {
145 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
146 NtClose(BusKey);
147 return FALSE;
148 }
149
150 /* Open the controller type key */
151 RtlInitUnicodeString(&KeyName,
152 L"DisplayController");
153 InitializeObjectAttributes(&ObjectAttributes,
154 &KeyName,
155 OBJ_CASE_INSENSITIVE,
156 BusInstanceKey,
157 NULL);
158 Status = NtOpenKey(&ControllerKey,
159 KEY_ALL_ACCESS,
160 &ObjectAttributes);
161 if (NT_SUCCESS(Status))
162 {
163 ControllerInstance = 0;
164 while (TRUE)
165 {
166 /* Open the pointer controller instance key */
167 swprintf(Buffer, L"%lu", ControllerInstance);
168 RtlInitUnicodeString(&KeyName,
169 Buffer);
170 InitializeObjectAttributes(&ObjectAttributes,
171 &KeyName,
172 OBJ_CASE_INSENSITIVE,
173 ControllerKey,
174 NULL);
175 Status = NtOpenKey(&ControllerInstanceKey,
176 KEY_ALL_ACCESS,
177 &ObjectAttributes);
178 if (!NT_SUCCESS(Status))
179 {
180 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
181 NtClose(ControllerKey);
182 NtClose(BusInstanceKey);
183 NtClose(BusKey);
184 return FALSE;
185 }
186
187 /* Get controller identifier */
188 RtlInitUnicodeString(&KeyName,
189 L"Identifier");
190
191 BufferLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
192 256 * sizeof(WCHAR);
193 ValueInfo = RtlAllocateHeap(RtlGetProcessHeap(),
194 0,
195 BufferLength);
196 if (ValueInfo == NULL)
197 {
198 DPRINT("RtlAllocateHeap() failed\n");
199 NtClose(ControllerInstanceKey);
200 NtClose(ControllerKey);
201 NtClose(BusInstanceKey);
202 NtClose(BusKey);
203 return FALSE;
204 }
205
206 Status = NtQueryValueKey(ControllerInstanceKey,
207 &KeyName,
208 KeyValuePartialInformation,
209 ValueInfo,
210 BufferLength,
211 &ReturnedLength);
212 if (NT_SUCCESS(Status))
213 {
214 DPRINT("Identifier: %S\n", (PWSTR)ValueInfo->Data);
215
216 BufferLength = min(ValueInfo->DataLength / sizeof(WCHAR), IdentifierLength);
217 RtlCopyMemory (Identifier,
218 ValueInfo->Data,
219 BufferLength * sizeof(WCHAR));
220 Identifier[BufferLength] = 0;
221
222 RtlFreeHeap(RtlGetProcessHeap(),
223 0,
224 ValueInfo);
225 NtClose(ControllerInstanceKey);
226 NtClose(ControllerKey);
227 NtClose(BusInstanceKey);
228 NtClose(BusKey);
229 return TRUE;
230 }
231
232 NtClose(ControllerInstanceKey);
233
234 ControllerInstance++;
235 }
236
237 NtClose(ControllerKey);
238 }
239
240 NtClose(BusInstanceKey);
241
242 BusInstance++;
243 }
244
245 NtClose(BusKey);
246
247 return FALSE;
248 }
249
250
251 PGENERIC_LIST
252 CreateDisplayDriverList(HINF InfFile)
253 {
254 CHAR Buffer[128];
255 PGENERIC_LIST List;
256 INFCONTEXT Context;
257 PWCHAR KeyName;
258 PWCHAR KeyValue;
259 PWCHAR UserData;
260 WCHAR DisplayIdentifier[128];
261 WCHAR DisplayKey[32];
262
263 /* Get the display identification */
264 if (!GetDisplayIdentifier(DisplayIdentifier, 128))
265 {
266 DisplayIdentifier[0] = 0;
267 }
268
269 DPRINT("Display identifier: '%S'\n", DisplayIdentifier);
270
271 /* Search for matching device identifier */
272 if (!InfFindFirstLine(InfFile, L"Map.Display", NULL, &Context))
273 {
274 /* FIXME: error message */
275 return NULL;
276 }
277
278 do
279 {
280 if (!InfGetDataField(&Context, 1, &KeyValue))
281 {
282 /* FIXME: Handle error! */
283 DPRINT("InfGetDataField() failed\n");
284 return NULL;
285 }
286
287 DPRINT("KeyValue: %S\n", KeyValue);
288 if (wcsstr(DisplayIdentifier, KeyValue))
289 {
290 if (!InfGetDataField(&Context, 0, &KeyName))
291 {
292 /* FIXME: Handle error! */
293 DPRINT("InfGetDataField() failed\n");
294 return NULL;
295 }
296
297 DPRINT("Display key: %S\n", KeyName);
298 wcscpy(DisplayKey, KeyName);
299 }
300 }
301 while (InfFindNextLine(&Context, &Context));
302
303
304 List = CreateGenericList();
305 if (List == NULL)
306 return NULL;
307
308 if (!InfFindFirstLine (InfFile, L"Display", NULL, &Context))
309 {
310 DestroyGenericList(List, FALSE);
311 return NULL;
312 }
313
314 do
315 {
316 if (!InfGetDataField(&Context, 0, &KeyName))
317 {
318 DPRINT1("InfGetDataField() failed\n");
319 break;
320 }
321
322 if (!InfGetDataField(&Context, 1, &KeyValue))
323 {
324 DPRINT1("InfGetDataField() failed\n");
325 break;
326 }
327
328 UserData = RtlAllocateHeap(ProcessHeap,
329 0,
330 (wcslen(KeyName) + 1) * sizeof(WCHAR));
331 if (UserData == NULL)
332 {
333 DPRINT1("RtlAllocateHeap() failed\n");
334 DestroyGenericList(List, TRUE);
335 return NULL;
336 }
337
338 wcscpy(UserData, KeyName);
339
340 sprintf(Buffer, "%S", KeyValue);
341 AppendGenericListEntry(List,
342 Buffer,
343 UserData,
344 _wcsicmp(KeyName, DisplayKey) ? FALSE : TRUE);
345 }
346 while (InfFindNextLine(&Context, &Context));
347
348 #if 0
349 AppendGenericListEntry(List, "Other display driver", NULL, TRUE);
350 #endif
351
352 return List;
353 }
354
355
356 BOOLEAN
357 ProcessDisplayRegistry(HINF InfFile, PGENERIC_LIST List)
358 {
359 PGENERIC_LIST_ENTRY Entry;
360 INFCONTEXT Context;
361 PWCHAR ServiceName;
362 ULONG StartValue;
363 NTSTATUS Status;
364
365 DPRINT("ProcessDisplayRegistry() called\n");
366
367 Entry = GetGenericListEntry(List);
368 if (Entry == NULL)
369 {
370 DPRINT("GetGenericListEntry() failed\n");
371 return FALSE;
372 }
373
374 if (!InfFindFirstLine(InfFile, L"Display", Entry->UserData, &Context))
375 {
376 DPRINT("InfFindFirstLine() failed\n");
377 return FALSE;
378 }
379
380 if (!InfGetDataField(&Context, 3, &ServiceName))
381 {
382 DPRINT("InfGetDataField() failed\n");
383 return FALSE;
384 }
385
386 DPRINT("Service name: %S\n", ServiceName);
387
388 StartValue = 1;
389 Status = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES,
390 ServiceName,
391 L"Start",
392 REG_DWORD,
393 &StartValue,
394 sizeof(ULONG));
395 if (!NT_SUCCESS(Status))
396 {
397 DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
398 return FALSE;
399 }
400
401 DPRINT("ProcessDisplayRegistry() done\n");
402
403 return TRUE;
404 }
405
406
407 PGENERIC_LIST
408 CreateKeyboardDriverList(HINF InfFile)
409 {
410 CHAR Buffer[128];
411 PGENERIC_LIST List;
412 INFCONTEXT Context;
413 PWCHAR KeyName;
414 PWCHAR KeyValue;
415 PWCHAR UserData;
416
417 List = CreateGenericList();
418 if (List == NULL)
419 return NULL;
420
421 if (!InfFindFirstLine (InfFile, L"Keyboard", NULL, &Context))
422 {
423 DestroyGenericList(List, FALSE);
424 return NULL;
425 }
426
427 do
428 {
429 if (!InfGetData (&Context, &KeyName, &KeyValue))
430 {
431 /* FIXME: Handle error! */
432 DPRINT("InfGetData() failed\n");
433 break;
434 }
435
436 UserData = RtlAllocateHeap(ProcessHeap,
437 0,
438 (wcslen(KeyName) + 1) * sizeof(WCHAR));
439 if (UserData == NULL)
440 {
441 /* FIXME: Handle error! */
442 }
443
444 wcscpy(UserData, KeyName);
445
446 sprintf(Buffer, "%S", KeyValue);
447 AppendGenericListEntry(List, Buffer, UserData, FALSE);
448 }
449 while (InfFindNextLine(&Context, &Context));
450
451 return List;
452 }
453
454
455 PGENERIC_LIST
456 CreateKeyboardLayoutList(HINF InfFile)
457 {
458 CHAR Buffer[128];
459 PGENERIC_LIST List;
460 INFCONTEXT Context;
461 PWCHAR KeyName;
462 PWCHAR KeyValue;
463 PWCHAR UserData;
464 WCHAR DefaultLayout[20];
465
466 /* Get default layout id */
467 if (!InfFindFirstLine (InfFile, L"NLS", L"DefaultLayout", &Context))
468 return NULL;
469
470 if (!InfGetData (&Context, NULL, &KeyValue))
471 return NULL;
472
473 wcscpy(DefaultLayout, KeyValue);
474
475 List = CreateGenericList();
476 if (List == NULL)
477 return NULL;
478
479 if (!InfFindFirstLine (InfFile, L"KeyboardLayout", NULL, &Context))
480 {
481 DestroyGenericList(List, FALSE);
482 return NULL;
483 }
484
485 do
486 {
487 if (!InfGetData (&Context, &KeyName, &KeyValue))
488 {
489 /* FIXME: Handle error! */
490 DPRINT("InfGetData() failed\n");
491 break;
492 }
493
494 UserData = RtlAllocateHeap(ProcessHeap,
495 0,
496 (wcslen(KeyName) + 1) * sizeof(WCHAR));
497 if (UserData == NULL)
498 {
499 /* FIXME: Handle error! */
500 }
501
502 wcscpy(UserData, KeyName);
503
504 sprintf(Buffer, "%S", KeyValue);
505 AppendGenericListEntry(List,
506 Buffer,
507 UserData,
508 _wcsicmp(KeyName, DefaultLayout) ? FALSE : TRUE);
509 }
510 while (InfFindNextLine(&Context, &Context));
511
512 return List;
513 }
514
515
516 BOOLEAN
517 ProcessKeyboardLayoutRegistry(PGENERIC_LIST List)
518 {
519 PGENERIC_LIST_ENTRY Entry;
520 PWCHAR LanguageId;
521 OBJECT_ATTRIBUTES ObjectAttributes;
522 UNICODE_STRING KeyName;
523 UNICODE_STRING ValueName;
524 HANDLE KeyHandle;
525 NTSTATUS Status;
526
527 Entry = GetGenericListEntry(List);
528 if (Entry == NULL)
529 return FALSE;
530
531 LanguageId = (PWCHAR)Entry->UserData;
532 if (LanguageId == NULL)
533 return FALSE;
534
535 /* Open the nls language key */
536 RtlInitUnicodeString(&KeyName,
537 L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language");
538 InitializeObjectAttributes(&ObjectAttributes,
539 &KeyName,
540 OBJ_CASE_INSENSITIVE,
541 NULL,
542 NULL);
543 Status = NtOpenKey(&KeyHandle,
544 KEY_ALL_ACCESS,
545 &ObjectAttributes);
546 if (!NT_SUCCESS(Status))
547 {
548 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status);
549 return FALSE;
550 }
551
552 /* Set default language */
553 RtlInitUnicodeString(&ValueName,
554 L"Default");
555 Status = NtSetValueKey (KeyHandle,
556 &ValueName,
557 0,
558 REG_SZ,
559 (PVOID)(LanguageId + 4),
560 8);
561 if (!NT_SUCCESS(Status))
562 {
563 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
564 NtClose(KeyHandle);
565 return FALSE;
566 }
567
568 /* Set install language */
569 RtlInitUnicodeString(&ValueName,
570 L"InstallLanguage");
571 Status = NtSetValueKey (KeyHandle,
572 &ValueName,
573 0,
574 REG_SZ,
575 (PVOID)(LanguageId + 4),
576 8);
577 if (!NT_SUCCESS(Status))
578 {
579 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
580 NtClose(KeyHandle);
581 return FALSE;
582 }
583
584 NtClose(KeyHandle);
585
586 return TRUE;
587 }
588
589
590 #if 0
591 BOOLEAN
592 ProcessKeyboardLayoutFiles(PGENERIC_LIST List)
593 {
594 return TRUE;
595 }
596 #endif
597
598
599 static BOOLEAN
600 GetMouseIdentifier(PWSTR ControllerType,
601 PWSTR Identifier,
602 ULONG IdentifierLength)
603 {
604 OBJECT_ATTRIBUTES ObjectAttributes;
605 UNICODE_STRING KeyName;
606 WCHAR Buffer[32];
607 HANDLE BusKey;
608 HANDLE BusInstanceKey;
609 HANDLE ControllerKey;
610 HANDLE ControllerInstanceKey;
611 HANDLE PeripheralKey;
612 HANDLE PeripheralInstanceKey;
613 ULONG BusInstance;
614 ULONG ControllerInstance;
615 ULONG PeripheralInstance;
616 ULONG BufferLength;
617 ULONG ReturnedLength;
618 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
619 NTSTATUS Status;
620
621 DPRINT("GetMouseIdentifier() called\n");
622
623 /* Open the bus key */
624 RtlInitUnicodeString(&KeyName,
625 L"\\Registry\\Machine\\HARDWARE\\Description\\System\\MultifunctionAdapter");
626 InitializeObjectAttributes(&ObjectAttributes,
627 &KeyName,
628 OBJ_CASE_INSENSITIVE,
629 NULL,
630 NULL);
631 Status = NtOpenKey(&BusKey,
632 KEY_ALL_ACCESS,
633 &ObjectAttributes);
634 if (!NT_SUCCESS(Status))
635 {
636 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
637 return FALSE;
638 }
639
640 BusInstance = 0;
641 while (TRUE)
642 {
643 swprintf(Buffer, L"%lu", BusInstance);
644 RtlInitUnicodeString(&KeyName,
645 Buffer);
646 InitializeObjectAttributes(&ObjectAttributes,
647 &KeyName,
648 OBJ_CASE_INSENSITIVE,
649 BusKey,
650 NULL);
651 Status = NtOpenKey(&BusInstanceKey,
652 KEY_ALL_ACCESS,
653 &ObjectAttributes);
654 if (!NT_SUCCESS(Status))
655 {
656 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
657 NtClose(BusKey);
658 return FALSE;
659 }
660
661 /* Open the controller type key */
662 RtlInitUnicodeString(&KeyName,
663 ControllerType);
664 InitializeObjectAttributes(&ObjectAttributes,
665 &KeyName,
666 OBJ_CASE_INSENSITIVE,
667 BusInstanceKey,
668 NULL);
669 Status = NtOpenKey(&ControllerKey,
670 KEY_ALL_ACCESS,
671 &ObjectAttributes);
672 if (NT_SUCCESS(Status))
673 {
674 ControllerInstance = 0;
675 while (TRUE)
676 {
677 /* Open the pointer controller instance key */
678 swprintf(Buffer, L"%lu", ControllerInstance);
679 RtlInitUnicodeString(&KeyName,
680 Buffer);
681 InitializeObjectAttributes(&ObjectAttributes,
682 &KeyName,
683 OBJ_CASE_INSENSITIVE,
684 ControllerKey,
685 NULL);
686 Status = NtOpenKey(&ControllerInstanceKey,
687 KEY_ALL_ACCESS,
688 &ObjectAttributes);
689 if (!NT_SUCCESS(Status))
690 {
691 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
692 NtClose(ControllerKey);
693 NtClose(BusInstanceKey);
694 NtClose(BusKey);
695 return FALSE;
696 }
697
698 /* Open the 'PointerPeripheral' key */
699 RtlInitUnicodeString(&KeyName,
700 L"PointerPeripheral");
701 InitializeObjectAttributes(&ObjectAttributes,
702 &KeyName,
703 OBJ_CASE_INSENSITIVE,
704 ControllerInstanceKey,
705 NULL);
706 Status = NtOpenKey(&PeripheralKey,
707 KEY_ALL_ACCESS,
708 &ObjectAttributes);
709 if (NT_SUCCESS(Status))
710 {
711 PeripheralInstance = 0;
712 while (TRUE)
713 {
714 /* Open the pointer peripheral instance key */
715 swprintf(Buffer, L"%lu", PeripheralInstance);
716 RtlInitUnicodeString(&KeyName,
717 Buffer);
718 InitializeObjectAttributes(&ObjectAttributes,
719 &KeyName,
720 OBJ_CASE_INSENSITIVE,
721 PeripheralKey,
722 NULL);
723 Status = NtOpenKey(&PeripheralInstanceKey,
724 KEY_ALL_ACCESS,
725 &ObjectAttributes);
726 if (!NT_SUCCESS(Status))
727 {
728 DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
729 NtClose(PeripheralKey);
730 NtClose(ControllerInstanceKey);
731 NtClose(ControllerKey);
732 NtClose(BusInstanceKey);
733 NtClose(BusKey);
734 return FALSE;
735 }
736
737 /* Get peripheral identifier */
738 RtlInitUnicodeString(&KeyName,
739 L"Identifier");
740
741 BufferLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
742 256 * sizeof(WCHAR);
743 ValueInfo = RtlAllocateHeap(RtlGetProcessHeap(),
744 0,
745 BufferLength);
746 if (ValueInfo == NULL)
747 {
748 DPRINT("RtlAllocateHeap() failed\n");
749 NtClose(PeripheralInstanceKey);
750 NtClose(PeripheralKey);
751 NtClose(ControllerInstanceKey);
752 NtClose(ControllerKey);
753 NtClose(BusInstanceKey);
754 NtClose(BusKey);
755 return FALSE;
756 }
757
758 Status = NtQueryValueKey(PeripheralInstanceKey,
759 &KeyName,
760 KeyValuePartialInformation,
761 ValueInfo,
762 BufferLength,
763 &ReturnedLength);
764 if (NT_SUCCESS(Status))
765 {
766 DPRINT("Identifier: %S\n", (PWSTR)ValueInfo->Data);
767
768 BufferLength = min(ValueInfo->DataLength / sizeof(WCHAR), IdentifierLength);
769 RtlCopyMemory (Identifier,
770 ValueInfo->Data,
771 BufferLength * sizeof(WCHAR));
772 Identifier[BufferLength] = 0;
773
774 RtlFreeHeap(RtlGetProcessHeap(),
775 0,
776 ValueInfo);
777 NtClose(PeripheralInstanceKey);
778 NtClose(PeripheralKey);
779 NtClose(ControllerInstanceKey);
780 NtClose(ControllerKey);
781 NtClose(BusInstanceKey);
782 NtClose(BusKey);
783 return TRUE;
784 }
785
786 RtlFreeHeap(RtlGetProcessHeap(),
787 0,
788 ValueInfo);
789
790 NtClose(PeripheralInstanceKey);
791
792 PeripheralInstance++;
793 }
794
795 NtClose(PeripheralKey);
796 }
797
798 NtClose(ControllerInstanceKey);
799
800 ControllerInstance++;
801 }
802
803 NtClose(ControllerKey);
804 }
805
806 NtClose(BusInstanceKey);
807
808 BusInstance++;
809 }
810
811 NtClose(BusKey);
812
813 return FALSE;
814 }
815
816
817 PGENERIC_LIST
818 CreateMouseDriverList(HINF InfFile)
819 {
820 CHAR Buffer[128];
821 PGENERIC_LIST List;
822 INFCONTEXT Context;
823 PWCHAR KeyName;
824 PWCHAR KeyValue;
825 PWCHAR UserData;
826 WCHAR MouseIdentifier[128];
827 WCHAR MouseKey[32];
828
829 /* Get the mouse identification */
830 if (!GetMouseIdentifier(L"SerialController", MouseIdentifier, 128))
831 {
832 if (!GetMouseIdentifier(L"PointerController", MouseIdentifier, 128))
833 {
834 wcscpy (MouseIdentifier, L"NO MOUSE");
835 }
836 }
837
838 DPRINT("Mouse identifier: '%S'\n", MouseIdentifier);
839
840 /* Search for matching device identifier */
841 if (!InfFindFirstLine(InfFile, L"Map.Mouse", NULL, &Context))
842 {
843 /* FIXME: error message */
844 return NULL;
845 }
846
847 do
848 {
849 if (!InfGetDataField(&Context, 1, &KeyValue))
850 {
851 /* FIXME: Handle error! */
852 DPRINT("InfGetDataField() failed\n");
853 return NULL;
854 }
855
856 DPRINT("KeyValue: %S\n", KeyValue);
857 if (wcsstr(MouseIdentifier, KeyValue))
858 {
859 if (!InfGetDataField(&Context, 0, &KeyName))
860 {
861 /* FIXME: Handle error! */
862 DPRINT("InfGetDataField() failed\n");
863 return NULL;
864 }
865
866 DPRINT("Mouse key: %S\n", KeyName);
867 wcscpy(MouseKey, KeyName);
868 }
869 }
870 while (InfFindNextLine(&Context, &Context));
871
872
873 List = CreateGenericList();
874 if (List == NULL)
875 return NULL;
876
877 if (!InfFindFirstLine(InfFile, L"Mouse", NULL, &Context))
878 {
879 DestroyGenericList(List, FALSE);
880 return NULL;
881 }
882
883 do
884 {
885 if (!InfGetDataField(&Context, 0, &KeyName))
886 {
887 DPRINT1("InfGetDataField() failed\n");
888 break;
889 }
890
891 if (!InfGetDataField(&Context, 1, &KeyValue))
892 {
893 DPRINT1("InfGetDataField() failed\n");
894 break;
895 }
896
897 UserData = RtlAllocateHeap(ProcessHeap,
898 0,
899 (wcslen(KeyName) + 1) * sizeof(WCHAR));
900 if (UserData == NULL)
901 {
902 DPRINT1("RtlAllocateHeap() failed\n");
903 DestroyGenericList(List, TRUE);
904 return NULL;
905 }
906
907 wcscpy(UserData, KeyName);
908
909 sprintf(Buffer, "%S", KeyValue);
910 AppendGenericListEntry(List,
911 Buffer,
912 UserData,
913 _wcsicmp(KeyName, MouseKey) ? FALSE : TRUE);
914 }
915 while (InfFindNextLine(&Context, &Context));
916
917 return List;
918 }
919
920
921 BOOLEAN
922 ProcessMouseRegistry(HINF InfFile, PGENERIC_LIST List)
923 {
924 PGENERIC_LIST_ENTRY Entry;
925 INFCONTEXT Context;
926 PWCHAR ServiceName;
927 ULONG StartValue;
928 NTSTATUS Status;
929
930 DPRINT("ProcessMouseRegistry() called\n");
931
932 Entry = GetGenericListEntry(List);
933 if (Entry == NULL)
934 {
935 DPRINT("GetGenericListEntry() failed\n");
936 return FALSE;
937 }
938
939 if (!InfFindFirstLine(InfFile, L"Mouse", Entry->UserData, &Context))
940 {
941 DPRINT("InfFindFirstLine() failed\n");
942 return FALSE;
943 }
944
945 if (!InfGetDataField(&Context, 3, &ServiceName))
946 {
947 DPRINT("InfGetDataField() failed\n");
948 return FALSE;
949 }
950
951 DPRINT("Service name: %S\n", ServiceName);
952
953 StartValue = 1;
954 Status = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES,
955 ServiceName,
956 L"Start",
957 REG_DWORD,
958 &StartValue,
959 sizeof(ULONG));
960 if (!NT_SUCCESS(Status))
961 {
962 DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
963 return FALSE;
964 }
965
966 DPRINT("ProcessMouseRegistry() done\n");
967
968 return TRUE;
969 }
970
971
972 #if 0
973 BOOLEAN
974 ProcessMouseFiles(PGENERIC_LIST List)
975 {
976 return TRUE;
977 }
978 #endif
979
980 /* EOF */