📄 settings.c
字号:
}
DPRINT("KeyValue: %S\n", KeyValue);
if (wcsstr(DisplayIdentifier, KeyValue))
{
if (!INF_GetDataField(&Context, 0, &KeyName))
{
/* FIXME: Handle error! */
DPRINT("INF_GetDataField() failed\n");
return NULL;
}
DPRINT("Display key: %S\n", KeyName);
wcscpy(DisplayKey, KeyName);
}
}
while (SetupFindNextLine(&Context, &Context));
List = CreateGenericList();
if (List == NULL)
return NULL;
if (!SetupFindFirstLineW (InfFile, L"Display", NULL, &Context))
{
DestroyGenericList(List, FALSE);
return NULL;
}
do
{
if (!INF_GetDataField(&Context, 0, &KeyName))
{
DPRINT1("INF_GetDataField() failed\n");
break;
}
if (!INF_GetDataField(&Context, 1, &KeyValue))
{
DPRINT1("INF_GetDataField() failed\n");
break;
}
UserData = (WCHAR*) RtlAllocateHeap(ProcessHeap,
0,
(wcslen(KeyName) + 1) * sizeof(WCHAR));
if (UserData == NULL)
{
DPRINT1("RtlAllocateHeap() failed\n");
DestroyGenericList(List, TRUE);
return NULL;
}
wcscpy(UserData, KeyName);
sprintf(Buffer, "%S", KeyValue);
AppendGenericListEntry(List,
Buffer,
UserData,
_wcsicmp(KeyName, DisplayKey) ? FALSE : TRUE);
}
while (SetupFindNextLine(&Context, &Context));
#if 0
AppendGenericListEntry(List, "Other display driver", NULL, TRUE);
#endif
return List;
}
BOOLEAN
ProcessComputerFiles(HINF InfFile, PGENERIC_LIST List, PWCHAR* AdditionalSectionName)
{
PGENERIC_LIST_ENTRY Entry;
static WCHAR SectionName[128];
DPRINT("ProcessComputerFiles() called\n");
Entry = GetGenericListEntry(List);
if (Entry == NULL)
{
DPRINT("GetGenericListEntry() failed\n");
return FALSE;
}
wcscpy(SectionName, L"Files.");
wcscat(SectionName, (const wchar_t*) Entry->UserData);
*AdditionalSectionName = SectionName;
return TRUE;
}
BOOLEAN
ProcessDisplayRegistry(HINF InfFile, PGENERIC_LIST List)
{
PGENERIC_LIST_ENTRY Entry;
INFCONTEXT Context;
PWCHAR ServiceName;
ULONG StartValue;
NTSTATUS Status;
WCHAR RegPath [255];
PWCHAR Buffer;
ULONG Width, Hight, Bpp;
DPRINT("ProcessDisplayRegistry() called\n");
Entry = GetGenericListEntry(List);
if (Entry == NULL)
{
DPRINT("GetGenericListEntry() failed\n");
return FALSE;
}
if (!SetupFindFirstLineW(InfFile, L"Display", (WCHAR*) Entry->UserData, &Context))
{
DPRINT("SetupFindFirstLineW() failed\n");
return FALSE;
}
/* Enable the right driver */
if (!INF_GetDataField(&Context, 3, &ServiceName))
{
DPRINT("INF_GetDataField() failed\n");
return FALSE;
}
ASSERT(wcslen(ServiceName) < 10);
DPRINT("Service name: %S\n", ServiceName);
StartValue = 1;
Status = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES,
ServiceName,
L"Start",
REG_DWORD,
&StartValue,
sizeof(ULONG));
if (!NT_SUCCESS(Status))
{
DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
return FALSE;
}
/* Set the resolution */
swprintf(RegPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", ServiceName);
if (!INF_GetDataField(&Context, 4, &Buffer))
{
DPRINT("INF_GetDataField() failed\n");
return FALSE;
}
Width = wcstoul(Buffer, NULL, 10);
Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
RegPath,
L"DefaultSettings.XResolution",
REG_DWORD,
&Width,
sizeof(ULONG));
if (!NT_SUCCESS(Status))
{
DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
return FALSE;
}
if (!INF_GetDataField(&Context, 5, &Buffer))
{
DPRINT("INF_GetDataField() failed\n");
return FALSE;
}
Hight = wcstoul(Buffer, 0, 0);
Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
RegPath,
L"DefaultSettings.YResolution",
REG_DWORD,
&Hight,
sizeof(ULONG));
if (!NT_SUCCESS(Status))
{
DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
return FALSE;
}
if (!INF_GetDataField(&Context, 6, &Buffer))
{
DPRINT("INF_GetDataField() failed\n");
return FALSE;
}
Bpp = wcstoul(Buffer, 0, 0);
Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
RegPath,
L"DefaultSettings.BitsPerPel",
REG_DWORD,
&Bpp,
sizeof(ULONG));
if (!NT_SUCCESS(Status))
{
DPRINT("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
return FALSE;
}
DPRINT("ProcessDisplayRegistry() done\n");
return TRUE;
}
PGENERIC_LIST
CreateKeyboardDriverList(HINF InfFile)
{
CHAR Buffer[128];
PGENERIC_LIST List;
INFCONTEXT Context;
PWCHAR KeyName;
PWCHAR KeyValue;
PWCHAR UserData;
List = CreateGenericList();
if (List == NULL)
return NULL;
if (!SetupFindFirstLineW (InfFile, L"Keyboard", NULL, &Context))
{
DestroyGenericList(List, FALSE);
return NULL;
}
do
{
if (!INF_GetData (&Context, &KeyName, &KeyValue))
{
/* FIXME: Handle error! */
DPRINT("INF_GetData() failed\n");
break;
}
UserData = (WCHAR*) RtlAllocateHeap(ProcessHeap,
0,
(wcslen(KeyName) + 1) * sizeof(WCHAR));
if (UserData == NULL)
{
/* FIXME: Handle error! */
}
wcscpy(UserData, KeyName);
sprintf(Buffer, "%S", KeyValue);
AppendGenericListEntry(List, Buffer, UserData, FALSE);
}
while (SetupFindNextLine(&Context, &Context));
return List;
}
PGENERIC_LIST
CreateKeyboardLayoutList(HINF InfFile)
{
CHAR Buffer[128];
PGENERIC_LIST List;
INFCONTEXT Context;
PWCHAR KeyName;
PWCHAR KeyValue;
PWCHAR UserData;
WCHAR DefaultLayout[20];
/* Get default layout id */
if (!SetupFindFirstLineW (InfFile, L"NLS", L"DefaultLayout", &Context))
return NULL;
if (!INF_GetData (&Context, NULL, &KeyValue))
return NULL;
wcscpy(DefaultLayout, KeyValue);
List = CreateGenericList();
if (List == NULL)
return NULL;
if (!SetupFindFirstLineW (InfFile, L"KeyboardLayout", NULL, &Context))
{
DestroyGenericList(List, FALSE);
return NULL;
}
do
{
if (!INF_GetData (&Context, &KeyName, &KeyValue))
{
/* FIXME: Handle error! */
DPRINT("INF_GetData() failed\n");
break;
}
UserData = (WCHAR*) RtlAllocateHeap(ProcessHeap,
0,
(wcslen(KeyName) + 1) * sizeof(WCHAR));
if (UserData == NULL)
{
/* FIXME: Handle error! */
}
wcscpy(UserData, KeyName);
sprintf(Buffer, "%S", KeyValue);
AppendGenericListEntry(List,
Buffer,
UserData,
_wcsicmp(KeyName, DefaultLayout) ? FALSE : TRUE);
}
while (SetupFindNextLine(&Context, &Context));
return List;
}
BOOLEAN
ProcessKeyboardLayoutRegistry(PGENERIC_LIST List)
{
PGENERIC_LIST_ENTRY Entry;
PWCHAR LanguageId;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
UNICODE_STRING ValueName;
HANDLE KeyHandle;
NTSTATUS Status;
Entry = GetGenericListEntry(List);
if (Entry == NULL)
return FALSE;
LanguageId = (PWCHAR)Entry->UserData;
if (LanguageId == NULL)
return FALSE;
/* Open the nls language key */
RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language");
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenKey(&KeyHandle,
KEY_ALL_ACCESS,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtOpenKey() failed (Status %lx)\n", Status);
return FALSE;
}
/* Set default language */
RtlInitUnicodeString(&ValueName,
L"Default");
Status = NtSetValueKey (KeyHandle,
&ValueName,
0,
REG_SZ,
(PVOID)(LanguageId + 4),
8);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
NtClose(KeyHandle);
return FALSE;
}
/* Set install language */
RtlInitUnicodeString(&ValueName,
L"InstallLanguage");
Status = NtSetValueKey (KeyHandle,
&ValueName,
0,
REG_SZ,
(PVOID)(LanguageId + 4),
8);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
NtClose(KeyHandle);
return FALSE;
}
NtClose(KeyHandle);
return TRUE;
}
#if 0
BOOLEAN
ProcessKeyboardLayoutFiles(PGENERIC_LIST List)
{
return TRUE;
}
#endif
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -