Import registry data from inf files which are listed in txtsetup.sif.

svn path=/trunk/; revision=4395
This commit is contained in:
Eric Kohl 2003-03-22 15:25:03 +00:00
parent 8b3c315dd9
commit c5b283562d
5 changed files with 76 additions and 191 deletions

View file

@ -904,11 +904,17 @@ ClearScreen(VOID)
VOID VOID
SetStatusText(PCHAR Text) SetStatusText(char* fmt, ...)
{ {
char Buffer[128];
va_list ap;
COORD coPos; COORD coPos;
ULONG Written; ULONG Written;
va_start(ap, fmt);
vsprintf(Buffer, fmt, ap);
va_end(ap);
coPos.X = 0; coPos.X = 0;
coPos.Y = yScreen - 1; coPos.Y = yScreen - 1;
@ -922,8 +928,8 @@ SetStatusText(PCHAR Text)
coPos, coPos,
&Written); &Written);
WriteConsoleOutputCharacters(Text, WriteConsoleOutputCharacters(Buffer,
strlen(Text), strlen(Buffer),
coPos); coPos);
} }

View file

@ -102,7 +102,7 @@ VOID
ClearScreen(VOID); ClearScreen(VOID);
VOID VOID
SetStatusText(PCHAR Text); SetStatusText(char* fmt, ...);
VOID VOID
SetTextXY(SHORT x, SHORT y, PCHAR Text); SetTextXY(SHORT x, SHORT y, PCHAR Text);

View file

@ -35,16 +35,12 @@
#define FLG_ADDREG_DELREG_BIT 0x00008000
#define FLG_ADDREG_BINVALUETYPE 0x00000001 #define FLG_ADDREG_BINVALUETYPE 0x00000001
#define FLG_ADDREG_NOCLOBBER 0x00000002 #define FLG_ADDREG_NOCLOBBER 0x00000002
#define FLG_ADDREG_DELVAL 0x00000004 #define FLG_ADDREG_DELVAL 0x00000004
#define FLG_ADDREG_APPEND 0x00000008 #define FLG_ADDREG_APPEND 0x00000008
#define FLG_ADDREG_KEYONLY 0x00000010 #define FLG_ADDREG_KEYONLY 0x00000010
#define FLG_ADDREG_OVERWRITEONLY 0x00000020 #define FLG_ADDREG_OVERWRITEONLY 0x00000020
#define FLG_ADDREG_64BITKEY 0x00001000
#define FLG_ADDREG_KEYONLY_COMMON 0x00002000
#define FLG_ADDREG_32BITKEY 0x00004000
#define FLG_ADDREG_TYPE_SZ 0x00000000 #define FLG_ADDREG_TYPE_SZ 0x00000000
#define FLG_ADDREG_TYPE_MULTI_SZ 0x00010000 #define FLG_ADDREG_TYPE_MULTI_SZ 0x00010000
#define FLG_ADDREG_TYPE_EXPAND_SZ 0x00020000 #define FLG_ADDREG_TYPE_EXPAND_SZ 0x00020000
@ -53,24 +49,9 @@
#define FLG_ADDREG_TYPE_NONE (0x00020000 | FLG_ADDREG_BINVALUETYPE) #define FLG_ADDREG_TYPE_NONE (0x00020000 | FLG_ADDREG_BINVALUETYPE)
#define FLG_ADDREG_TYPE_MASK (0xFFFF0000 | FLG_ADDREG_BINVALUETYPE) #define FLG_ADDREG_TYPE_MASK (0xFFFF0000 | FLG_ADDREG_BINVALUETYPE)
#define FLG_DELREG_VALUE (0x00000000)
#define FLG_DELREG_TYPE_MASK FLG_ADDREG_TYPE_MASK
#define FLG_DELREG_TYPE_SZ FLG_ADDREG_TYPE_SZ
#define FLG_DELREG_TYPE_MULTI_SZ FLG_ADDREG_TYPE_MULTI_SZ
#define FLG_DELREG_TYPE_EXPAND_SZ FLG_ADDREG_TYPE_EXPAND_SZ
#define FLG_DELREG_TYPE_BINARY FLG_ADDREG_TYPE_BINARY
#define FLG_DELREG_TYPE_DWORD FLG_ADDREG_TYPE_DWORD
#define FLG_DELREG_TYPE_NONE FLG_ADDREG_TYPE_NONE
#define FLG_DELREG_64BITKEY FLG_ADDREG_64BITKEY
#define FLG_DELREG_KEYONLY_COMMON FLG_ADDREG_KEYONLY_COMMON
#define FLG_DELREG_32BITKEY FLG_ADDREG_32BITKEY
#define FLG_DELREG_OPERATION_MASK (0x000000FE)
#define FLG_DELREG_MULTI_SZ_DELSTRING (FLG_DELREG_TYPE_MULTI_SZ | FLG_ADDREG_DELREG_BIT | 0x00000002)
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
static BOOLEAN static BOOLEAN
GetRootKey (PWCHAR Name) GetRootKey (PWCHAR Name)
{ {
@ -211,25 +192,12 @@ do_reg_operation(HANDLE KeyHandle,
ULONG Size; ULONG Size;
NTSTATUS Status; NTSTATUS Status;
if (Flags & (FLG_ADDREG_DELREG_BIT | FLG_ADDREG_DELVAL)) /* deletion */ if (Flags & FLG_ADDREG_DELVAL) /* deletion */
{ {
#if 0 #if 0
if (ValueName && !(flags & FLG_DELREG_KEYONLY_COMMON)) if (ValueName)
{ {
if ((Flags & FLG_DELREG_MULTI_SZ_DELSTRING) == FLG_DELREG_MULTI_SZ_DELSTRING) RegDeleteValueW( hkey, value );
{
WCHAR *str;
if (!SetupGetStringFieldW( context, 5, NULL, 0, &size ) || !size) return TRUE;
if (!(str = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
SetupGetStringFieldW( context, 5, str, size, NULL );
delete_multi_sz_value( hkey, value, str );
HeapFree( GetProcessHeap(), 0, str );
}
else
{
RegDeleteValueW( hkey, value );
}
} }
else else
{ {
@ -239,7 +207,7 @@ do_reg_operation(HANDLE KeyHandle,
return TRUE; return TRUE;
} }
if (Flags & (FLG_ADDREG_KEYONLY | FLG_ADDREG_KEYONLY_COMMON)) if (Flags & FLG_ADDREG_KEYONLY)
return TRUE; return TRUE;
#if 0 #if 0
@ -334,48 +302,36 @@ do_reg_operation(HANDLE KeyHandle,
{ {
ULONG dw = Str ? wcstol (Str, NULL, 0) : 0; ULONG dw = Str ? wcstol (Str, NULL, 0) : 0;
DPRINT1("setting dword %wZ to %lx\n", ValueName, dw); DPRINT("setting dword %wZ to %lx\n", ValueName, dw);
Status = NtSetValueKey (KeyHandle, NtSetValueKey (KeyHandle,
ValueName, ValueName,
0, 0,
Type, Type,
(PVOID)&dw, (PVOID)&dw,
sizeof(ULONG)); sizeof(ULONG));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
}
} }
else else
{ {
DPRINT1("setting value %wZ to %S\n", ValueName, Str); DPRINT("setting value %wZ to %S\n", ValueName, Str);
if (Str) if (Str)
{ {
Status = NtSetValueKey (KeyHandle, NtSetValueKey (KeyHandle,
ValueName, ValueName,
0, 0,
Type, Type,
(PVOID)Str, (PVOID)Str,
Size * sizeof(WCHAR)); Size * sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
}
} }
else else
{ {
Status = NtSetValueKey (KeyHandle, NtSetValueKey (KeyHandle,
ValueName, ValueName,
0, 0,
Type, Type,
(PVOID)&EmptyStr, (PVOID)&EmptyStr,
sizeof(WCHAR)); sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
}
} }
} }
RtlFreeHeap (ProcessHeap, 0, Str); RtlFreeHeap (ProcessHeap, 0, Str);
@ -393,20 +349,16 @@ do_reg_operation(HANDLE KeyHandle,
if (Data == NULL) if (Data == NULL)
return FALSE; return FALSE;
DPRINT1("setting binary data %wZ len %lu\n", ValueName, Size); DPRINT("setting binary data %wZ len %lu\n", ValueName, Size);
InfGetBinaryField (Context, 5, Data, Size, NULL); InfGetBinaryField (Context, 5, Data, Size, NULL);
} }
Status = NtSetValueKey (KeyHandle, NtSetValueKey (KeyHandle,
ValueName, ValueName,
0, 0,
Type, Type,
(PVOID)Data, (PVOID)Data,
Size); Size);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
}
RtlFreeHeap (ProcessHeap, 0, Data); RtlFreeHeap (ProcessHeap, 0, Data);
} }
@ -548,26 +500,13 @@ registry_callback (HINF hInf, PCWSTR Section, BOOLEAN Delete)
if (!InfGetStringField (&Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - Length, NULL)) if (!InfGetStringField (&Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH - Length, NULL))
*Buffer = 0; *Buffer = 0;
DPRINT1("KeyName: <%S>\n", Buffer); DPRINT("KeyName: <%S>\n", Buffer);
/* get flags */ /* get flags */
if (!InfGetIntField (&Context, 4, (PLONG)&Flags)) if (!InfGetIntField (&Context, 4, (PLONG)&Flags))
Flags = 0; Flags = 0;
DPRINT1("Flags: %lx\n", Flags); DPRINT("Flags: %lx\n", Flags);
if (!Delete)
{
if (Flags & FLG_ADDREG_DELREG_BIT)
continue; /* ignore this entry */
}
else
{
if (!Flags)
Flags = FLG_ADDREG_DELREG_BIT;
else if (!(Flags & FLG_ADDREG_DELREG_BIT))
continue; /* ignore this entry */
}
RtlInitUnicodeString (&Name, RtlInitUnicodeString (&Name,
Buffer); Buffer);
@ -585,7 +524,7 @@ registry_callback (HINF hInf, PCWSTR Section, BOOLEAN Delete)
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NtOpenKey(%wZ) failed (Status %lx)\n", &Name, Status); DPRINT("NtOpenKey(%wZ) failed (Status %lx)\n", &Name, Status);
continue; /* ignore if it doesn't exist */ continue; /* ignore if it doesn't exist */
} }
} }
@ -596,7 +535,7 @@ registry_callback (HINF hInf, PCWSTR Section, BOOLEAN Delete)
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("CreateNestedKey(%wZ) failed (Status %lx)\n", &Name, Status); DPRINT("CreateNestedKey(%wZ) failed (Status %lx)\n", &Name, Status);
continue; continue;
} }
} }
@ -628,7 +567,9 @@ registry_callback (HINF hInf, PCWSTR Section, BOOLEAN Delete)
BOOLEAN BOOLEAN
ImportRegistryData(PWSTR Filename) ImportRegistryFile(PWSTR Filename,
PWSTR Section,
BOOLEAN Delete)
{ {
WCHAR FileNameBuffer[MAX_PATH]; WCHAR FileNameBuffer[MAX_PATH];
UNICODE_STRING FileName; UNICODE_STRING FileName;
@ -664,80 +605,6 @@ ImportRegistryData(PWSTR Filename)
} }
NTSTATUS
SetupUpdateRegistry(VOID)
{
#if 0
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
UNICODE_STRING ValueName;
HANDLE KeyHandle;
NTSTATUS Status;
RtlInitUnicodeStringFromLiteral(&KeyName,
L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control");
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtCreateKey(&KeyHandle,
KEY_ALL_ACCESS,
&ObjectAttributes,
0,
NULL,
REG_OPTION_NON_VOLATILE,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtCreateKey() failed (Status %lx)\n", Status);
}
NtClose(KeyHandle);
/* Create '\Registry\Machine\System\Setup' key */
RtlInitUnicodeStringFromLiteral(&KeyName,
L"\\Registry\\Machine\\SYSTEM\\Setup");
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtCreateKey(&KeyHandle,
KEY_ALL_ACCESS,
&ObjectAttributes,
0,
NULL,
REG_OPTION_NON_VOLATILE,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtCreateKey() failed (Status %lx)\n", Status);
}
/* FIXME: Create value 'SetupType' */
/* FIXME: Create value 'SystemSetupInProgress' */
NtClose(KeyHandle);
#endif
SetStatusText(" Importing hivesys.inf...");
if (!ImportRegistryData (L"hivesys.inf"))
{
DPRINT1("ImportRegistryData (\"hivesys.inf\") failed\n");
}
SetStatusText(" Done...");
return STATUS_SUCCESS;
}
BOOLEAN BOOLEAN
SetInstallPathValue(PUNICODE_STRING InstallPath) SetInstallPathValue(PUNICODE_STRING InstallPath)
{ {

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: registry.h,v 1.3 2003/03/19 20:12:44 ekohl Exp $ /* $Id: registry.h,v 1.4 2003/03/22 15:25:03 ekohl Exp $
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup * PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/registry.h * FILE: subsys/system/usetup/registry.h
@ -27,12 +27,10 @@
#ifndef __REGISTRY_H__ #ifndef __REGISTRY_H__
#define __REGISTRY_H__ #define __REGISTRY_H__
NTSTATUS
SetupUpdateRegistry(VOID);
BOOLEAN BOOLEAN
ImportRegistryData(PWSTR Filename); ImportRegistryFile(PWSTR Filename,
PWSTR Section,
BOOLEAN Delete);
BOOLEAN BOOLEAN
SetInstallPathValue(PUNICODE_STRING InstallPath); SetInstallPathValue(PUNICODE_STRING InstallPath);

View file

@ -1270,6 +1270,7 @@ RegistryPage(PINPUT_RECORD Ir)
PWSTR Action; PWSTR Action;
PWSTR File; PWSTR File;
PWSTR Section; PWSTR Section;
BOOLEAN Delete;
SetTextXY(6, 8, "Setup is updating the system configuration"); SetTextXY(6, 8, "Setup is updating the system configuration");
@ -1278,6 +1279,7 @@ RegistryPage(PINPUT_RECORD Ir)
if (!SetInstallPathValue(&DestinationPath)) if (!SetInstallPathValue(&DestinationPath))
{ {
DPRINT("SetInstallPathValue() failed\n");
PopupError("Setup failed to set the initialize the registry.", PopupError("Setup failed to set the initialize the registry.",
"ENTER = Reboot computer"); "ENTER = Reboot computer");
@ -1296,7 +1298,7 @@ RegistryPage(PINPUT_RECORD Ir)
Status = NtInitializeRegistry(TRUE); Status = NtInitializeRegistry(TRUE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NtInitializeRegistry() failed (Status %lx)\n", Status); DPRINT("NtInitializeRegistry() failed (Status %lx)\n", Status);
PopupError("Setup failed to create the registry hives.", PopupError("Setup failed to create the registry hives.",
"ENTER = Reboot computer"); "ENTER = Reboot computer");
@ -1314,11 +1316,10 @@ RegistryPage(PINPUT_RECORD Ir)
/* Update registry */ /* Update registry */
SetStatusText(" Updating registry hives..."); SetStatusText(" Updating registry hives...");
#if 0
if (!InfFindFirstLine(SetupInf, L"HiveInfs.Install", NULL, &InfContext)) if (!InfFindFirstLine(SetupInf, L"HiveInfs.Install", NULL, &InfContext))
{ {
DPRINT1("InfFindFirstLine() failed\n"); DPRINT1("InfFindFirstLine() failed\n");
PopupError("Setup failed to find the registry hive inf-files.", PopupError("Setup failed to find the registry data files.",
"ENTER = Reboot computer"); "ENTER = Reboot computer");
while(TRUE) while(TRUE)
@ -1334,35 +1335,48 @@ RegistryPage(PINPUT_RECORD Ir)
do do
{ {
InfGetDataField (&InfContext, 0, &Action); InfGetDataField (&InfContext, 0, &Action);
InfGetDataField (&InfContext, 1, &File); InfGetDataField (&InfContext, 1, &File);
InfGetDataField (&InfContext, 2, &Section); InfGetDataField (&InfContext, 2, &Section);
DPRINT1("Action: %S File: %S Section %S\n", Action, File, Section); DPRINT1("Action: %S File: %S Section %S\n", Action, File, Section);
} if (!_wcsicmp (Action, L"AddReg"))
while (InfFindNextLine (&InfContext, &InfContext));
#endif
Status = SetupUpdateRegistry();
if (!NT_SUCCESS(Status))
{
DPRINT1("SetupUpdateRegistry() failed (Status %lx)\n", Status);
PopupError("Setup failed to update the registry.",
"ENTER = Reboot computer");
while(TRUE)
{ {
ConInKey(Ir); Delete = FALSE;
}
else if (!_wcsicmp (Action, L"DelReg"))
{
Delete = TRUE;
}
else
{
continue;
}
if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */ SetStatusText(" Importing %S...", File);
if (!ImportRegistryFile(File, Section, Delete))
{
DPRINT1("Importing %S failed\n", File);
PopupError("Setup failed to import a hive file.",
"ENTER = Reboot computer");
while(TRUE)
{ {
return(QUIT_PAGE); ConInKey(Ir);
if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
{
return(QUIT_PAGE);
}
} }
} }
} }
while (InfFindNextLine (&InfContext, &InfContext));
SetStatusText(" Done...");
return(BOOT_LOADER_PAGE); return(BOOT_LOADER_PAGE);
} }