[USETUP] Code formatting, making also the code closer to mkhive's one. Also, definitely remove the SetInstallPathValue() hack.

svn path=/branches/setup_improvements/; revision=74763
This commit is contained in:
Hermès Bélusca-Maïto 2017-06-03 15:20:09 +00:00
parent 8269478385
commit cd89e5b797
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -102,6 +102,7 @@ GetRootKey(
*
* Append a multisz string to a multisz registry value.
*/
// NOTE: Synced with setupapi/install.c ; see also mkhive/reginf.c
#if 0
static void
append_multi_sz_value (HANDLE hkey,
@ -115,7 +116,7 @@ append_multi_sz_value (HANDLE hkey,
if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return;
if (type != REG_MULTI_SZ) return;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size + str_size) * sizeof(WCHAR) ))) return;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size + str_size * sizeof(WCHAR) ))) return;
if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size )) goto done;
/* compare each string against all the existing ones */
@ -196,7 +197,7 @@ do_reg_operation(HANDLE KeyHandle,
PINFCONTEXT Context,
ULONG Flags)
{
WCHAR EmptyStr = (WCHAR)0;
WCHAR EmptyStr = 0;
ULONG Type;
ULONG Size;
@ -221,7 +222,7 @@ do_reg_operation(HANDLE KeyHandle,
#if 0
if (Flags & (FLG_ADDREG_NOCLOBBER | FLG_ADDREG_OVERWRITEONLY))
{
BOOL exists = !RegQueryValueExW( hkey, value, NULL, NULL, NULL, NULL );
BOOL exists = !RegQueryValueExW( hkey, ValueName, NULL, NULL, NULL, NULL );
if (exists && (flags & FLG_ADDREG_NOCLOBBER))
return TRUE;
if (!exists & (flags & FLG_ADDREG_OVERWRITEONLY))
@ -284,6 +285,7 @@ do_reg_operation(HANDLE KeyHandle,
if (Str == NULL)
return TRUE;
DPRINT1("append_multi_sz_value '%S' commented out, WHY??\n", ValueName);
// append_multi_sz_value( hkey, value, str, size );
RtlFreeHeap (ProcessHeap, 0, Str);
@ -474,35 +476,33 @@ CreateNestedKey (PHANDLE KeyHandle,
static BOOLEAN
registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete)
{
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR Buffer[MAX_INF_STRING_LENGTH];
UNICODE_STRING Name;
UNICODE_STRING Value;
PUNICODE_STRING ValuePtr;
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING Name, Value;
PUNICODE_STRING ValuePtr;
UINT Flags;
ULONG Length;
WCHAR Buffer[MAX_INF_STRING_LENGTH];
INFCONTEXT Context;
HANDLE KeyHandle;
BOOLEAN Ok;
Ok = SetupFindFirstLineW(hInf, Section, NULL, &Context);
if (!Ok)
return TRUE; /* Don't fail if the section isn't present */
if (Ok)
{
for (;Ok; Ok = SetupFindNextLine (&Context, &Context))
{
/* get root */
if (!SetupGetStringFieldW (&Context, 1, Buffer, MAX_INF_STRING_LENGTH, NULL))
if (!SetupGetStringFieldW(&Context, 1, Buffer, sizeof(Buffer)/sizeof(WCHAR), NULL))
continue;
if (!GetRootKey (Buffer))
continue;
/* get key */
Length = wcslen(Buffer);
if (!SetupGetStringFieldW (&Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - Length, NULL))
if (!SetupGetStringFieldW(&Context, 2, Buffer + Length, sizeof(Buffer)/sizeof(WCHAR) - Length, NULL))
*Buffer = 0;
DPRINT("KeyName: <%S>\n", Buffer);
@ -513,9 +513,7 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete)
DPRINT("Flags: %lx\n", Flags);
RtlInitUnicodeString (&Name,
Buffer);
RtlInitUnicodeString(&Name, Buffer);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_CASE_INSENSITIVE,
@ -546,10 +544,9 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete)
}
/* get value name */
if (SetupGetStringFieldW (&Context, 3, Buffer, MAX_INF_STRING_LENGTH, NULL))
if (SetupGetStringFieldW(&Context, 3, Buffer, sizeof(Buffer)/sizeof(WCHAR), NULL))
{
RtlInitUnicodeString (&Value,
Buffer);
RtlInitUnicodeString(&Value, Buffer);
ValuePtr = &Value;
}
else
@ -566,7 +563,6 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete)
NtClose(KeyHandle);
}
}
return TRUE;
}
@ -598,60 +594,30 @@ ImportRegistryFile(
return FALSE;
}
#if 0
if (!registry_callback(hInf, L"DelReg", FALSE))
{
DPRINT1("registry_callback() failed\n");
InfCloseFile(hInf);
return FALSE;
}
#endif
if (!registry_callback(hInf, L"AddReg", FALSE))
{
DPRINT1("registry_callback() failed\n");
InfCloseFile(hInf);
return FALSE;
}
if (!registry_callback(hInf, L"AddReg.NT" Architecture, FALSE))
{
DPRINT1("registry_callback() failed\n");
InfCloseFile(hInf);
return FALSE;
}
InfCloseFile(hInf);
return TRUE;
}
BOOLEAN
SetInstallPathValue(
PUNICODE_STRING InstallPath)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE");
UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath");
HANDLE KeyHandle;
NTSTATUS Status;
/* Create the 'secret' InstallPath key */
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;
}
Status = NtSetValueKey(KeyHandle,
&ValueName,
0,
REG_SZ,
(PVOID)InstallPath->Buffer,
InstallPath->Length + sizeof(WCHAR));
NtClose(KeyHandle);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
return FALSE;
}
return TRUE;
}