From b02dd8eb22764267d2645a0ed5823029cf7892c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 15 Feb 2024 23:10:55 +0100 Subject: [PATCH] [SETUPLIB] Make the settings' Process* functions take an actual value instead of a GENERIC_LIST The reason is to avoid enforcing the usage of a specific list container by the users of the setup library. This is a departure of what I originally thought would be the best, in commits 92692eae3 (r74553), 8f2c4f7a6 (r75700) This should actually make some parts of the GUI setup code simpler (e.g. using the win32 comboboxes to store the list contents). --- base/setup/lib/install.c | 10 +++++- base/setup/lib/settings.c | 65 +++++++++++---------------------------- base/setup/lib/settings.h | 20 ++++++------ base/setup/lib/setuplib.c | 54 ++++++++++++++++++++------------ base/setup/lib/setuplib.h | 7 +++++ 5 files changed, 79 insertions(+), 77 deletions(-) diff --git a/base/setup/lib/install.c b/base/setup/lib/install.c index 46a36d2fa08..72f3ea92181 100644 --- a/base/setup/lib/install.c +++ b/base/setup/lib/install.c @@ -538,8 +538,16 @@ PrepareCopyInfFile( } /* Add specific files depending of computer type */ - if (!ProcessComputerFiles(InfFile, pSetupData->ComputerList, &AdditionalSectionName)) + { + PGENERIC_LIST_ENTRY Entry; + Entry = GetCurrentListEntry(pSetupData->ComputerList); + ASSERT(Entry); + pSetupData->ComputerType = ((PGENENTRY)GetListEntryData(Entry))->Id; + ASSERT(pSetupData->ComputerType); + + if (!ProcessComputerFiles(InfFile, pSetupData->ComputerType, &AdditionalSectionName)) return FALSE; + } if (AdditionalSectionName && !AddSectionToCopyQueue(pSetupData, InfFile, diff --git a/base/setup/lib/settings.c b/base/setup/lib/settings.c index 09d3c240fb4..44f3c97368f 100644 --- a/base/setup/lib/settings.c +++ b/base/setup/lib/settings.c @@ -785,33 +785,29 @@ CreateDisplayDriverList( BOOLEAN ProcessComputerFiles( - IN HINF InfFile, - IN PGENERIC_LIST List, - OUT PWSTR* AdditionalSectionName) + _In_ HINF InfFile, + _In_ PCWSTR ComputerType, + _Out_ PWSTR* AdditionalSectionName) { - PGENERIC_LIST_ENTRY Entry; static WCHAR SectionName[128]; - DPRINT("ProcessComputerFiles() called\n"); + DPRINT("ProcessComputerFiles(%S) called\n", ComputerType); - Entry = GetCurrentListEntry(List); - if (Entry == NULL) - return FALSE; - - RtlStringCchPrintfW(SectionName, ARRAYSIZE(SectionName), - L"Files.%s", ((PGENENTRY)GetListEntryData(Entry))->Id); + RtlStringCchPrintfW(SectionName, _countof(SectionName), + L"Files.%s", ComputerType); *AdditionalSectionName = SectionName; + // TODO: More things to do? + return TRUE; } BOOLEAN ProcessDisplayRegistry( - IN HINF InfFile, - IN PGENERIC_LIST List) + _In_ HINF InfFile, + _In_ PCWSTR DisplayType) { NTSTATUS Status; - PGENERIC_LIST_ENTRY Entry; INFCONTEXT Context; PCWSTR Buffer; PCWSTR ServiceName; @@ -822,15 +818,9 @@ ProcessDisplayRegistry( HANDLE KeyHandle; WCHAR RegPath[255]; - DPRINT("ProcessDisplayRegistry() called\n"); + DPRINT("ProcessDisplayRegistry(%S) called\n", DisplayType); - Entry = GetCurrentListEntry(List); - if (Entry == NULL) - return FALSE; - - if (!SpInfFindFirstLine(InfFile, L"Display", - ((PGENENTRY)GetListEntryData(Entry))->Id, - &Context)) + if (!SpInfFindFirstLine(InfFile, L"Display", DisplayType, &Context)) { DPRINT1("SpInfFindFirstLine() failed\n"); return FALSE; @@ -935,7 +925,7 @@ ProcessDisplayRegistry( return FALSE; } - Height = wcstoul(Buffer, 0, 0); + Height = wcstoul(Buffer, NULL, 10); Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE, KeyHandle, L"DefaultSettings.YResolution", REG_DWORD, @@ -955,7 +945,7 @@ ProcessDisplayRegistry( return FALSE; } - Bpp = wcstoul(Buffer, 0, 0); + Bpp = wcstoul(Buffer, NULL, 10); Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE, KeyHandle, L"DefaultSettings.BitsPerPel", REG_DWORD, @@ -977,25 +967,14 @@ ProcessDisplayRegistry( BOOLEAN ProcessLocaleRegistry( - IN PGENERIC_LIST List) + _In_ PCWSTR LanguageId) { - PGENERIC_LIST_ENTRY Entry; - PCWSTR LanguageId; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; - HANDLE KeyHandle; NTSTATUS Status; - Entry = GetCurrentListEntry(List); - if (Entry == NULL) - return FALSE; - - LanguageId = ((PGENENTRY)GetListEntryData(Entry))->Id; - if (LanguageId == NULL) - return FALSE; - DPRINT("LanguageId: %S\n", LanguageId); /* Open the default users locale key */ @@ -1286,22 +1265,15 @@ CreateKeyboardLayoutList( BOOLEAN ProcessKeyboardLayoutRegistry( - IN PGENERIC_LIST List, - IN PCWSTR LanguageId) + _In_ PCWSTR pszLayoutId, + _In_ PCWSTR LanguageId) { - PGENERIC_LIST_ENTRY Entry; - PCWSTR pszLayoutId; KLID LayoutId; const MUI_LAYOUTS* LayoutsList; MUI_LAYOUTS NewLayoutsList[20]; // HACK: Hardcoded fixed size "20" is a hack. Please verify against lang/*.h ULONG uIndex; ULONG uOldPos = 0; - Entry = GetCurrentListEntry(List); - if (Entry == NULL) - return FALSE; - - pszLayoutId = ((PGENENTRY)GetListEntryData(Entry))->Id; LayoutId = (KLID)(pszLayoutId ? wcstoul(pszLayoutId, NULL, 16) : 0); if (LayoutId == 0) return FALSE; @@ -1394,10 +1366,9 @@ SetGeoID( return TRUE; } - BOOLEAN SetDefaultPagefile( - IN WCHAR Drive) + _In_ WCHAR Drive) { NTSTATUS Status; HANDLE KeyHandle; diff --git a/base/setup/lib/settings.h b/base/setup/lib/settings.h index e77f15684c0..da6c7f2acd2 100644 --- a/base/setup/lib/settings.h +++ b/base/setup/lib/settings.h @@ -43,14 +43,14 @@ CreateDisplayDriverList( BOOLEAN ProcessComputerFiles( - IN HINF InfFile, - IN PGENERIC_LIST List, - OUT PWSTR* AdditionalSectionName); + _In_ HINF InfFile, + _In_ PCWSTR ComputerType, + _Out_ PWSTR* AdditionalSectionName); BOOLEAN ProcessDisplayRegistry( - IN HINF InfFile, - IN PGENERIC_LIST List); + _In_ HINF InfFile, + _In_ PCWSTR DisplayType); PGENERIC_LIST CreateKeyboardDriverList( @@ -72,16 +72,18 @@ GetDefaultLanguageIndex(VOID); BOOLEAN ProcessKeyboardLayoutRegistry( - IN PGENERIC_LIST List, - IN PCWSTR LanguageId); + _In_ PCWSTR pszLayoutId, + _In_ PCWSTR LanguageId); +#if 0 BOOLEAN ProcessKeyboardLayoutFiles( IN PGENERIC_LIST List); +#endif BOOLEAN ProcessLocaleRegistry( - IN PGENERIC_LIST List); + _In_ PCWSTR LanguageId); BOOLEAN SetGeoID( @@ -89,6 +91,6 @@ SetGeoID( BOOLEAN SetDefaultPagefile( - IN WCHAR Drive); + _In_ WCHAR Drive); /* EOF */ diff --git a/base/setup/lib/setuplib.c b/base/setup/lib/setuplib.c index 40e8c13b36f..4e3c5efe04a 100644 --- a/base/setup/lib/setuplib.c +++ b/base/setup/lib/setuplib.c @@ -789,12 +789,6 @@ InitializeSetup( { RtlZeroMemory(pSetupData, sizeof(*pSetupData)); - // pSetupData->ComputerList = NULL; - // pSetupData->DisplayList = NULL; - // pSetupData->KeyboardList = NULL; - // pSetupData->LayoutList = NULL; - // pSetupData->LanguageList = NULL; - /* Initialize error handling */ pSetupData->LastErrorNumber = ERROR_SUCCESS; pSetupData->ErrorRoutine = NULL; @@ -1059,23 +1053,36 @@ DoUpdate: { /* See the explanation for this test above */ + PGENERIC_LIST_ENTRY Entry; + PCWSTR LanguageId; // LocaleID; + + Entry = GetCurrentListEntry(pSetupData->DisplayList); + ASSERT(Entry); + pSetupData->DisplayType = ((PGENENTRY)GetListEntryData(Entry))->Id; + ASSERT(pSetupData->DisplayType); + /* Update display registry settings */ if (StatusRoutine) StatusRoutine(DisplaySettingsUpdate); - if (!ProcessDisplayRegistry(pSetupData->SetupInf, pSetupData->DisplayList)) + if (!ProcessDisplayRegistry(pSetupData->SetupInf, pSetupData->DisplayType)) { ErrorNumber = ERROR_UPDATE_DISPLAY_SETTINGS; goto Cleanup; } + Entry = GetCurrentListEntry(pSetupData->LanguageList); + ASSERT(Entry); + LanguageId = ((PGENENTRY)GetListEntryData(Entry))->Id; + ASSERT(LanguageId); + /* Set the locale */ if (StatusRoutine) StatusRoutine(LocaleSettingsUpdate); - if (!ProcessLocaleRegistry(pSetupData->LanguageList)) + if (!ProcessLocaleRegistry(/*pSetupData->*/LanguageId)) { ErrorNumber = ERROR_UPDATE_LOCALESETTINGS; goto Cleanup; } - /* Add keyboard layouts */ + /* Add the keyboard layouts for the given language (without user override) */ if (StatusRoutine) StatusRoutine(KeybLayouts); if (!AddKeyboardLayouts(SelectedLanguageId)) { @@ -1083,6 +1090,24 @@ DoUpdate: goto Cleanup; } + if (!IsUnattendedSetup) + { + Entry = GetCurrentListEntry(pSetupData->LayoutList); + ASSERT(Entry); + pSetupData->LayoutId = ((PGENENTRY)GetListEntryData(Entry))->Id; + ASSERT(pSetupData->LayoutId); + + /* Update keyboard layout settings with user-overridden values */ + // FIXME: Wouldn't it be better to do it all at once + // with the AddKeyboardLayouts() step? + if (StatusRoutine) StatusRoutine(KeybSettingsUpdate); + if (!ProcessKeyboardLayoutRegistry(pSetupData->LayoutId, SelectedLanguageId)) + { + ErrorNumber = ERROR_UPDATE_KBSETTINGS; + goto Cleanup; + } + } + /* Set GeoID */ if (!SetGeoID(MUIGetGeoID(SelectedLanguageId))) { @@ -1090,17 +1115,6 @@ DoUpdate: goto Cleanup; } - if (!IsUnattendedSetup) - { - /* Update keyboard layout settings */ - if (StatusRoutine) StatusRoutine(KeybSettingsUpdate); - if (!ProcessKeyboardLayoutRegistry(pSetupData->LayoutList, SelectedLanguageId)) - { - ErrorNumber = ERROR_UPDATE_KBSETTINGS; - goto Cleanup; - } - } - /* Add codepage information to registry */ if (StatusRoutine) StatusRoutine(CodePageInfoUpdate); if (!AddCodePage(SelectedLanguageId)) diff --git a/base/setup/lib/setuplib.h b/base/setup/lib/setuplib.h index 5d643ec3458..8988035f37d 100644 --- a/base/setup/lib/setuplib.h +++ b/base/setup/lib/setuplib.h @@ -122,6 +122,13 @@ typedef struct _USETUP_DATA PGENERIC_LIST LayoutList; PGENERIC_LIST LanguageList; +/* Settings *****/ + PCWSTR ComputerType; + PCWSTR DisplayType; + // PCWSTR KeyboardDriver; + // PCWSTR MouseDriver; + PCWSTR LayoutId; // DefaultKBLayout + /* Other stuff *****/ WCHAR LocaleID[9]; LANGID LanguageId;