#include "precomp.h"
#include "genlist.h"
#include "infsupp.h"
+#include "mui.h"
#include "registry.h"
#include "settings.h"
/* GLOBALS ******************************************************************/
-#if 0 // FIXME: Disabled for now because it uses MUI* functions from usetup
-ULONG DefaultLanguageIndex = 0;
-#endif
+static ULONG DefaultLanguageIndex = 0;
/* FUNCTIONS ****************************************************************/
static
BOOLEAN
GetComputerIdentifier(
- PWSTR Identifier,
- ULONG IdentifierLength)
+ OUT PWSTR Identifier,
+ IN ULONG IdentifierLength)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
}
-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,
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
Current = FALSE;
RetVal = ProcessEntry(KeyName,
KeyValue,
- DisplayText,
- sizeof(DisplayText),
&UserData,
&Current,
Parameter);
}
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))
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
{
/* FIXME: Handle error! */
DPRINT("INF_GetDataField() failed\n");
- return NULL;
+ return FALSE;
}
DPRINT("KeyValue: %S\n", KeyValue);
{
/* 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;
static
BOOLEAN
GetDisplayIdentifier(
- PWSTR Identifier,
- ULONG IdentifierLength)
+ OUT PWSTR Identifier,
+ IN ULONG IdentifierLength)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
BusInstance = 0;
while (TRUE)
{
- swprintf(Buffer, L"%lu", BusInstance);
+ RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", BusInstance);
RtlInitUnicodeString(&KeyName, Buffer);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
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,
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];
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;
}
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)
}
#if 0
- AppendGenericListEntry(List, "Other display driver", NULL, TRUE);
+ AppendGenericListEntry(List, L"Other display driver", NULL, TRUE);
#endif
return List;
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];
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;
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;
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;
}
}
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,
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,
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;
if (Entry == NULL)
return FALSE;
- LanguageId = (PWCHAR)GetListEntryUserData(Entry);
+ LanguageId = ((PGENENTRY)GetListEntryData(Entry))->Id;
if (LanguageId == NULL)
return FALSE;
PGENERIC_LIST
CreateKeyboardDriverList(
- HINF InfFile)
+ IN HINF InfFile)
{
PGENERIC_LIST List;
INFCONTEXT Context;
}
-#if 0 // FIXME: Disabled for now because it uses MUI* functions from usetup
-
ULONG
GetDefaultLanguageIndex(VOID)
{
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;
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;
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)
{
DefaultLanguageIndex = 0;
wcscpy(DefaultLanguage,
- (PWSTR)GetListEntryUserData(GetFirstListEntry(List)));
+ ((PGENENTRY)GetListEntryData(GetFirstListEntry(List)))->Id);
}
return List;
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))
if (List == NULL)
return NULL;
- LayoutsList = MUIGetLayoutsList();
+ LayoutsList = MUIGetLayoutsList(LanguageId);
do
{
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;
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;
}
BOOLEAN
SetGeoID(
- PWCHAR Id)
+ IN PCWSTR Id)
{
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
BOOLEAN
SetDefaultPagefile(
- WCHAR Drive)
+ IN WCHAR Drive)
{
NTSTATUS Status;
HANDLE KeyHandle;