[SETUP] Add support for archtitcure specific inf sections and use it for x64 computer...
[reactos.git] / base / setup / lib / settings.c
index ab005d2..cafe247 100644 (file)
@@ -28,6 +28,7 @@
 #include "precomp.h"
 #include "genlist.h"
 #include "infsupp.h"
+#include "mui.h"
 #include "registry.h"
 
 #include "settings.h"
@@ -37,9 +38,7 @@
 
 /* GLOBALS ******************************************************************/
 
-#if 0 // FIXME: Disabled for now because it uses MUI* functions from usetup
-ULONG DefaultLanguageIndex = 0;
-#endif
+static ULONG DefaultLanguageIndex = 0;
 
 /* FUNCTIONS ****************************************************************/
 
@@ -212,8 +211,8 @@ cleanup:
 static
 BOOLEAN
 GetComputerIdentifier(
-    PWSTR Identifier,
-    ULONG IdentifierLength)
+    OUT PWSTR Identifier,
+    IN ULONG IdentifierLength)
 {
     OBJECT_ATTRIBUTES ObjectAttributes;
     UNICODE_STRING KeyName;
@@ -314,7 +313,21 @@ GetComputerIdentifier(
 }
 
 
-LONG
+/*
+ * Return values:
+ * 0x00: Failure, stop the enumeration;
+ * 0x01: Add the entry and continue the enumeration;
+ * 0x02: Skip the entry but continue the enumeration.
+ */
+typedef UCHAR
+(NTAPI *PPROCESS_ENTRY_ROUTINE)(
+    IN PCWSTR KeyName,
+    IN PCWSTR KeyValue,
+    OUT PVOID* UserData,
+    OUT PBOOLEAN Current,
+    IN PVOID Parameter OPTIONAL);
+
+static LONG
 AddEntriesFromInfSection(
     IN OUT PGENERIC_LIST List,
     IN HINF InfFile,
@@ -324,14 +337,13 @@ AddEntriesFromInfSection(
     IN PVOID Parameter OPTIONAL)
 {
     LONG TotalCount = 0;
-    PWCHAR KeyName;
-    PWCHAR KeyValue;
+    PCWSTR KeyName;
+    PCWSTR KeyValue;
     PVOID UserData;
     BOOLEAN Current;
     UCHAR RetVal;
-    CHAR DisplayText[128];
 
-    if (!SetupFindFirstLineW(InfFile, SectionName, NULL, pContext))
+    if (!SpInfFindFirstLine(InfFile, SectionName, NULL, pContext))
         return -1;
 
     do
@@ -359,8 +371,6 @@ AddEntriesFromInfSection(
         Current  = FALSE;
         RetVal = ProcessEntry(KeyName,
                               KeyValue,
-                              DisplayText,
-                              sizeof(DisplayText),
                               &UserData,
                               &Current,
                               Parameter);
@@ -374,58 +384,67 @@ AddEntriesFromInfSection(
         }
         else if (RetVal == 1)
         {
-            AppendGenericListEntry(List, DisplayText, UserData, Current);
+            AppendGenericListEntry(List, UserData, Current);
             ++TotalCount;
         }
         // else if (RetVal == 2), skip the entry.
 
-    } while (SetupFindNextLine(pContext, pContext));
+    } while (SpInfFindNextLine(pContext, pContext));
 
     return TotalCount;
 }
 
-UCHAR
+static UCHAR
 NTAPI
 DefaultProcessEntry(
-    IN PWCHAR KeyName,
-    IN PWCHAR KeyValue,
-    IN PCHAR DisplayText,
-    IN SIZE_T DisplayTextSize,
+    IN PCWSTR KeyName,
+    IN PCWSTR KeyValue,
     OUT PVOID* UserData,
     OUT PBOOLEAN Current,
     IN PVOID Parameter OPTIONAL)
 {
     PWSTR CompareKey = (PWSTR)Parameter;
 
-    *UserData = RtlAllocateHeap(ProcessHeap, 0,
-                                (wcslen(KeyName) + 1) * sizeof(WCHAR));
-    if (*UserData == NULL)
+    PGENENTRY GenEntry;
+    SIZE_T IdSize, ValueSize;
+
+    IdSize    = (wcslen(KeyName)  + 1) * sizeof(WCHAR);
+    ValueSize = (wcslen(KeyValue) + 1) * sizeof(WCHAR);
+
+    GenEntry = RtlAllocateHeap(ProcessHeap, 0,
+                               sizeof(*GenEntry) + IdSize + ValueSize);
+    if (GenEntry == NULL)
     {
         /* Failure, stop enumeration */
         DPRINT1("RtlAllocateHeap() failed\n");
         return 0;
     }
 
-    wcscpy((PWCHAR)*UserData, KeyName);
-    sprintf(DisplayText, "%S", KeyValue);
+    GenEntry->Id    = (PCWSTR)((ULONG_PTR)GenEntry + sizeof(*GenEntry));
+    GenEntry->Value = (PCWSTR)((ULONG_PTR)GenEntry + sizeof(*GenEntry) + IdSize);
+    RtlStringCbCopyW((PWSTR)GenEntry->Id, IdSize, KeyName);
+    RtlStringCbCopyW((PWSTR)GenEntry->Value, ValueSize, KeyValue);
 
-    *Current = (CompareKey ? !_wcsicmp(KeyName, CompareKey) : FALSE);
+    *UserData = GenEntry;
+    *Current  = (CompareKey ? !_wcsicmp(KeyName, CompareKey) : FALSE);
 
     /* Add the entry */
     return 1;
 }
 
 
-PGENERIC_LIST
-CreateComputerTypeList(
-    HINF InfFile)
+BOOLEAN
+AddComputerTypeEntries(
+    _In_ HINF InfFile,
+    PGENERIC_LIST List,
+    _In_ PWSTR SectionName)
 {
-    PGENERIC_LIST List;
     INFCONTEXT Context;
-    PWCHAR KeyName;
-    PWCHAR KeyValue;
+    PCWSTR KeyName;
+    PCWSTR KeyValue;
     WCHAR ComputerIdentifier[128];
     WCHAR ComputerKey[32];
+    ULONG Count1, Count2;
 
     /* Get the computer identification */
     if (!GetComputerIdentifier(ComputerIdentifier, 128))
@@ -436,10 +455,10 @@ CreateComputerTypeList(
     DPRINT("Computer identifier: '%S'\n", ComputerIdentifier);
 
     /* Search for matching device identifier */
-    if (!SetupFindFirstLineW(InfFile, L"Map.Computer", NULL, &Context))
+    if (!SpInfFindFirstLine(InfFile, SectionName, NULL, &Context))
     {
         /* FIXME: error message */
-        return NULL;
+        return FALSE;
     }
 
     do
@@ -450,7 +469,7 @@ CreateComputerTypeList(
         {
             /* FIXME: Handle error! */
             DPRINT("INF_GetDataField() failed\n");
-            return NULL;
+            return FALSE;
         }
 
         DPRINT("KeyValue: %S\n", KeyValue);
@@ -464,24 +483,48 @@ CreateComputerTypeList(
         {
             /* FIXME: Handle error! */
             DPRINT("INF_GetDataField() failed\n");
-            return NULL;
+            return FALSE;
         }
 
         DPRINT("Computer key: %S\n", KeyName);
-        wcscpy(ComputerKey, KeyName);
+        RtlStringCchCopyW(ComputerKey, ARRAYSIZE(ComputerKey), KeyName);
         INF_FreeData(KeyName);
-    } while (SetupFindNextLine(&Context, &Context));
+    } while (SpInfFindNextLine(&Context, &Context));
+
+    Count1 = AddEntriesFromInfSection(List,
+                                      InfFile,
+                                      L"Computer",
+                                      &Context,
+                                      DefaultProcessEntry,
+                                      ComputerKey);
+    Count2 = AddEntriesFromInfSection(List,
+                                      InfFile,
+                                      L"Computer.NT" INF_ARCH,
+                                      &Context,
+                                      DefaultProcessEntry,
+                                      ComputerKey);
+    if ((Count1 == -1) && (Count2 == -1))
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+PGENERIC_LIST
+CreateComputerTypeList(
+    IN HINF InfFile)
+{
+    PGENERIC_LIST List;
+    BOOLEAN Success;
 
     List = CreateGenericList();
     if (List == NULL)
         return NULL;
 
-    if (AddEntriesFromInfSection(List,
-                                 InfFile,
-                                 L"Computer",
-                                 &Context,
-                                 DefaultProcessEntry,
-                                 ComputerKey) == -1)
+    Success = AddComputerTypeEntries(InfFile, List, L"Map.Computer");
+    Success |= AddComputerTypeEntries(InfFile, List, L"Map.Computer.NT" INF_ARCH);
+    if (!Success)
     {
         DestroyGenericList(List, TRUE);
         return NULL;
@@ -493,8 +536,8 @@ CreateComputerTypeList(
 static
 BOOLEAN
 GetDisplayIdentifier(
-    PWSTR Identifier,
-    ULONG IdentifierLength)
+    OUT PWSTR Identifier,
+    IN ULONG IdentifierLength)
 {
     OBJECT_ATTRIBUTES ObjectAttributes;
     UNICODE_STRING KeyName;
@@ -533,7 +576,7 @@ GetDisplayIdentifier(
     BusInstance = 0;
     while (TRUE)
     {
-        swprintf(Buffer, L"%lu", BusInstance);
+        RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", BusInstance);
         RtlInitUnicodeString(&KeyName, Buffer);
         InitializeObjectAttributes(&ObjectAttributes,
                                    &KeyName,
@@ -569,7 +612,7 @@ GetDisplayIdentifier(
             while (TRUE)
             {
                 /* Open the pointer controller instance key */
-                swprintf(Buffer, L"%lu", ControllerInstance);
+                RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", ControllerInstance);
                 RtlInitUnicodeString(&KeyName, Buffer);
                 InitializeObjectAttributes(&ObjectAttributes,
                                            &KeyName,
@@ -654,12 +697,12 @@ GetDisplayIdentifier(
 
 PGENERIC_LIST
 CreateDisplayDriverList(
-    HINF InfFile)
+    IN HINF InfFile)
 {
     PGENERIC_LIST List;
     INFCONTEXT Context;
-    PWCHAR KeyName;
-    PWCHAR KeyValue;
+    PCWSTR KeyName;
+    PCWSTR KeyValue;
     WCHAR DisplayIdentifier[128];
     WCHAR DisplayKey[32];
 
@@ -672,7 +715,7 @@ CreateDisplayDriverList(
     DPRINT("Display identifier: '%S'\n", DisplayIdentifier);
 
     /* Search for matching device identifier */
-    if (!SetupFindFirstLineW(InfFile, L"Map.Display", NULL, &Context))
+    if (!SpInfFindFirstLine(InfFile, L"Map.Display", NULL, &Context))
     {
         /* FIXME: error message */
         return NULL;
@@ -704,9 +747,9 @@ CreateDisplayDriverList(
         }
 
         DPRINT("Display key: %S\n", KeyName);
-        wcscpy(DisplayKey, KeyName);
+        RtlStringCchCopyW(DisplayKey, ARRAYSIZE(DisplayKey), KeyName);
         INF_FreeData(KeyName);
-    } while (SetupFindNextLine(&Context, &Context));
+    } while (SpInfFindNextLine(&Context, &Context));
 
     List = CreateGenericList();
     if (List == NULL)
@@ -724,7 +767,7 @@ CreateDisplayDriverList(
     }
 
 #if 0
-    AppendGenericListEntry(List, "Other display driver", NULL, TRUE);
+    AppendGenericListEntry(List, L"Other display driver", NULL, TRUE);
 #endif
 
     return List;
@@ -733,9 +776,9 @@ CreateDisplayDriverList(
 
 BOOLEAN
 ProcessComputerFiles(
-    HINF InfFile,
-    PGENERIC_LIST List,
-    PWCHAR *AdditionalSectionName)
+    IN HINF InfFile,
+    IN PGENERIC_LIST List,
+    OUT PWSTR* AdditionalSectionName)
 {
     PGENERIC_LIST_ENTRY Entry;
     static WCHAR SectionName[128];
@@ -744,13 +787,10 @@ ProcessComputerFiles(
 
     Entry = GetCurrentListEntry(List);
     if (Entry == NULL)
-    {
-        DPRINT("GetCurrentListEntry() failed\n");
         return FALSE;
-    }
 
-    wcscpy(SectionName, L"Files.");
-    wcscat(SectionName, (const wchar_t*)GetListEntryUserData(Entry));
+    RtlStringCchPrintfW(SectionName, ARRAYSIZE(SectionName),
+                        L"Files.%s", ((PGENENTRY)GetListEntryData(Entry))->Id);
     *AdditionalSectionName = SectionName;
 
     return TRUE;
@@ -758,14 +798,14 @@ ProcessComputerFiles(
 
 BOOLEAN
 ProcessDisplayRegistry(
-    HINF InfFile,
-    PGENERIC_LIST List)
+    IN HINF InfFile,
+    IN PGENERIC_LIST List)
 {
     NTSTATUS Status;
     PGENERIC_LIST_ENTRY Entry;
     INFCONTEXT Context;
-    PWCHAR Buffer;
-    PWCHAR ServiceName;
+    PCWSTR Buffer;
+    PCWSTR ServiceName;
     ULONG StartValue;
     ULONG Width, Height, Bpp;
     OBJECT_ATTRIBUTES ObjectAttributes;
@@ -777,14 +817,13 @@ ProcessDisplayRegistry(
 
     Entry = GetCurrentListEntry(List);
     if (Entry == NULL)
-    {
-        DPRINT1("GetCurrentListEntry() failed\n");
         return FALSE;
-    }
 
-    if (!SetupFindFirstLineW(InfFile, L"Display", (WCHAR*)GetListEntryUserData(Entry), &Context))
+    if (!SpInfFindFirstLine(InfFile, L"Display",
+                            ((PGENENTRY)GetListEntryData(Entry))->Id,
+                            &Context))
     {
-        DPRINT1("SetupFindFirstLineW() failed\n");
+        DPRINT1("SpInfFindFirstLine() failed\n");
         return FALSE;
     }
 
@@ -796,9 +835,11 @@ ProcessDisplayRegistry(
     }
 
     ASSERT(wcslen(ServiceName) < 10);
-    DPRINT1("Service name: '%S'\n", ServiceName);
+    DPRINT("Service name: '%S'\n", ServiceName);
 
-    swprintf(RegPath, L"System\\CurrentControlSet\\Services\\%s", ServiceName);
+    RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath),
+                        L"System\\CurrentControlSet\\Services\\%s",
+                        ServiceName);
     RtlInitUnicodeString(&KeyName, RegPath);
     InitializeObjectAttributes(&ObjectAttributes,
                                &KeyName,
@@ -835,10 +876,10 @@ ProcessDisplayRegistry(
         return FALSE;
     }
 
-    swprintf(RegPath,
-             L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0",
-             ServiceName);
-    DPRINT1("RegPath: '%S'\n", RegPath);
+    RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath),
+                        L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0",
+                        ServiceName);
+    DPRINT("RegPath: '%S'\n", RegPath);
     RtlInitUnicodeString(&KeyName, RegPath);
     InitializeObjectAttributes(&ObjectAttributes,
                                &KeyName,
@@ -916,10 +957,10 @@ ProcessDisplayRegistry(
 
 BOOLEAN
 ProcessLocaleRegistry(
-    PGENERIC_LIST List)
+    IN PGENERIC_LIST List)
 {
     PGENERIC_LIST_ENTRY Entry;
-    PWCHAR LanguageId;
+    PCWSTR LanguageId;
     OBJECT_ATTRIBUTES ObjectAttributes;
     UNICODE_STRING KeyName;
     UNICODE_STRING ValueName;
@@ -931,7 +972,7 @@ ProcessLocaleRegistry(
     if (Entry == NULL)
         return FALSE;
 
-    LanguageId = (PWCHAR)GetListEntryUserData(Entry);
+    LanguageId = ((PGENENTRY)GetListEntryData(Entry))->Id;
     if (LanguageId == NULL)
         return FALSE;
 
@@ -1030,7 +1071,7 @@ ProcessLocaleRegistry(
 
 PGENERIC_LIST
 CreateKeyboardDriverList(
-    HINF InfFile)
+    IN HINF InfFile)
 {
     PGENERIC_LIST List;
     INFCONTEXT Context;
@@ -1054,8 +1095,6 @@ CreateKeyboardDriverList(
 }
 
 
-#if 0 // FIXME: Disabled for now because it uses MUI* functions from usetup
-
 ULONG
 GetDefaultLanguageIndex(VOID)
 {
@@ -1071,35 +1110,42 @@ typedef struct _LANG_ENTRY_PARAM
 static UCHAR
 NTAPI
 ProcessLangEntry(
-    IN PWCHAR KeyName,
-    IN PWCHAR KeyValue,
-    IN PCHAR DisplayText,
-    IN SIZE_T DisplayTextSize,
+    IN PCWSTR KeyName,
+    IN PCWSTR KeyValue,
     OUT PVOID* UserData,
     OUT PBOOLEAN Current,
     IN PVOID Parameter OPTIONAL)
 {
     PLANG_ENTRY_PARAM LangEntryParam = (PLANG_ENTRY_PARAM)Parameter;
 
+    PGENENTRY GenEntry;
+    SIZE_T IdSize, ValueSize;
+
     if (!IsLanguageAvailable(KeyName))
     {
         /* The specified language is unavailable, skip the entry */
         return 2;
     }
 
-    *UserData = RtlAllocateHeap(ProcessHeap, 0,
-                                (wcslen(KeyName) + 1) * sizeof(WCHAR));
-    if (*UserData == NULL)
+    IdSize    = (wcslen(KeyName)  + 1) * sizeof(WCHAR);
+    ValueSize = (wcslen(KeyValue) + 1) * sizeof(WCHAR);
+
+    GenEntry = RtlAllocateHeap(ProcessHeap, 0,
+                               sizeof(*GenEntry) + IdSize + ValueSize);
+    if (GenEntry == NULL)
     {
         /* Failure, stop enumeration */
         DPRINT1("RtlAllocateHeap() failed\n");
         return 0;
     }
 
-    wcscpy((PWCHAR)*UserData, KeyName);
-    sprintf(DisplayText, "%S", KeyValue);
+    GenEntry->Id    = (PCWSTR)((ULONG_PTR)GenEntry + sizeof(*GenEntry));
+    GenEntry->Value = (PCWSTR)((ULONG_PTR)GenEntry + sizeof(*GenEntry) + IdSize);
+    RtlStringCbCopyW((PWSTR)GenEntry->Id, IdSize, KeyName);
+    RtlStringCbCopyW((PWSTR)GenEntry->Value, ValueSize, KeyValue);
 
-    *Current = FALSE;
+    *UserData = GenEntry;
+    *Current  = FALSE;
 
     if (!_wcsicmp(KeyName, LangEntryParam->DefaultLanguage))
         DefaultLanguageIndex = LangEntryParam->uIndex;
@@ -1112,12 +1158,12 @@ ProcessLangEntry(
 
 PGENERIC_LIST
 CreateLanguageList(
-    HINF InfFile,
-    WCHAR *DefaultLanguage)
+    IN HINF InfFile,
+    OUT PWSTR DefaultLanguage)
 {
     PGENERIC_LIST List;
     INFCONTEXT Context;
-    PWCHAR KeyValue;
+    PCWSTR KeyValue;
 
     LANG_ENTRY_PARAM LangEntryParam;
 
@@ -1125,14 +1171,13 @@ CreateLanguageList(
     LangEntryParam.DefaultLanguage = DefaultLanguage;
 
     /* Get default language id */
-    if (!SetupFindFirstLineW(InfFile, L"NLS", L"DefaultLanguage", &Context))
+    if (!SpInfFindFirstLine(InfFile, L"NLS", L"DefaultLanguage", &Context))
         return NULL;
 
     if (!INF_GetData(&Context, NULL, &KeyValue))
         return NULL;
 
     wcscpy(DefaultLanguage, KeyValue);
-    SelectedLanguageId = KeyValue;
 
     List = CreateGenericList();
     if (List == NULL)
@@ -1154,7 +1199,7 @@ CreateLanguageList(
     {
         DefaultLanguageIndex = 0;
         wcscpy(DefaultLanguage,
-               (PWSTR)GetListEntryUserData(GetFirstListEntry(List)));
+               ((PGENENTRY)GetListEntryData(GetFirstListEntry(List)))->Id);
     }
 
     return List;
@@ -1163,17 +1208,18 @@ CreateLanguageList(
 
 PGENERIC_LIST
 CreateKeyboardLayoutList(
-    HINF InfFile,
-    WCHAR *DefaultKBLayout)
+    IN HINF InfFile,
+    IN PCWSTR LanguageId,
+    OUT PWSTR DefaultKBLayout)
 {
     PGENERIC_LIST List;
     INFCONTEXT Context;
-    PWCHAR KeyValue;
-    const MUI_LAYOUTS * LayoutsList;
+    PCWSTR KeyValue;
+    const MUI_LAYOUTS* LayoutsList;
     ULONG uIndex = 0;
 
     /* Get default layout id */
-    if (!SetupFindFirstLineW(InfFile, L"NLS", L"DefaultLayout", &Context))
+    if (!SpInfFindFirstLine(InfFile, L"NLS", L"DefaultLayout", &Context))
         return NULL;
 
     if (!INF_GetData(&Context, NULL, &KeyValue))
@@ -1185,7 +1231,7 @@ CreateKeyboardLayoutList(
     if (List == NULL)
         return NULL;
 
-    LayoutsList = MUIGetLayoutsList();
+    LayoutsList = MUIGetLayoutsList(LanguageId);
 
     do
     {
@@ -1220,11 +1266,12 @@ CreateKeyboardLayoutList(
 
 BOOLEAN
 ProcessKeyboardLayoutRegistry(
-    PGENERIC_LIST List)
+    IN PGENERIC_LIST List,
+    IN PCWSTR LanguageId)
 {
     PGENERIC_LIST_ENTRY Entry;
-    PWCHAR LayoutId;
-    const MUI_LAYOUTS * LayoutsList;
+    PCWSTR LayoutId;
+    const MUI_LAYOUTS* LayoutsList;
     MUI_LAYOUTS NewLayoutsList[20];
     ULONG uIndex;
     ULONG uOldPos = 0;
@@ -1233,45 +1280,41 @@ ProcessKeyboardLayoutRegistry(
     if (Entry == NULL)
         return FALSE;
 
-    LayoutId = (PWCHAR)GetListEntryUserData(Entry);
+    LayoutId = ((PGENENTRY)GetListEntryData(Entry))->Id;
     if (LayoutId == NULL)
         return FALSE;
 
-    LayoutsList = MUIGetLayoutsList();
+    LayoutsList = MUIGetLayoutsList(LanguageId);
 
-    if (_wcsicmp(LayoutsList[0].LayoutID, LayoutId) != 0)
+    if (_wcsicmp(LayoutsList[0].LayoutID, LayoutId) == 0)
+        return TRUE;
+
+    for (uIndex = 1; LayoutsList[uIndex].LangID != NULL; uIndex++)
     {
-        for (uIndex = 1; LayoutsList[uIndex].LangID != NULL; uIndex++)
+        if (_wcsicmp(LayoutsList[uIndex].LayoutID, LayoutId) == 0)
         {
-            if (_wcsicmp(LayoutsList[uIndex].LayoutID, LayoutId) == 0)
-            {
-                uOldPos = uIndex;
-                continue;
-            }
-
-            NewLayoutsList[uIndex].LangID   = LayoutsList[uIndex].LangID;
-            NewLayoutsList[uIndex].LayoutID = LayoutsList[uIndex].LayoutID;
+            uOldPos = uIndex;
+            continue;
         }
 
-        NewLayoutsList[uIndex].LangID    = NULL;
-        NewLayoutsList[uIndex].LayoutID  = NULL;
-        NewLayoutsList[uOldPos].LangID   = LayoutsList[0].LangID;
-        NewLayoutsList[uOldPos].LayoutID = LayoutsList[0].LayoutID;
-        NewLayoutsList[0].LangID         = LayoutsList[uOldPos].LangID;
-        NewLayoutsList[0].LayoutID       = LayoutsList[uOldPos].LayoutID;
-
-        return AddKbLayoutsToRegistry(NewLayoutsList);
+        NewLayoutsList[uIndex].LangID   = LayoutsList[uIndex].LangID;
+        NewLayoutsList[uIndex].LayoutID = LayoutsList[uIndex].LayoutID;
     }
 
-    return TRUE;
-}
+    NewLayoutsList[uIndex].LangID    = NULL;
+    NewLayoutsList[uIndex].LayoutID  = NULL;
+    NewLayoutsList[uOldPos].LangID   = LayoutsList[0].LangID;
+    NewLayoutsList[uOldPos].LayoutID = LayoutsList[0].LayoutID;
+    NewLayoutsList[0].LangID         = LayoutsList[uOldPos].LangID;
+    NewLayoutsList[0].LayoutID       = LayoutsList[uOldPos].LayoutID;
 
-#endif
+    return AddKbLayoutsToRegistry(NewLayoutsList);
+}
 
 #if 0
 BOOLEAN
 ProcessKeyboardLayoutFiles(
-    PGENERIC_LIST List)
+    IN PGENERIC_LIST List)
 {
     return TRUE;
 }
@@ -1279,7 +1322,7 @@ ProcessKeyboardLayoutFiles(
 
 BOOLEAN
 SetGeoID(
-    PWCHAR Id)
+    IN PCWSTR Id)
 {
     NTSTATUS Status;
     OBJECT_ATTRIBUTES ObjectAttributes;
@@ -1322,7 +1365,7 @@ SetGeoID(
 
 BOOLEAN
 SetDefaultPagefile(
-    WCHAR Drive)
+    IN WCHAR Drive)
 {
     NTSTATUS Status;
     HANDLE KeyHandle;