From: Hermès Bélusca-Maïto Date: Fri, 30 Jun 2017 19:02:35 +0000 (+0000) Subject: [USETUP] Moving around some code. X-Git-Tag: 0.4.12-dev~437 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=397faf62bfc71249ac9ee39f54720d5465494d3c [USETUP] Moving around some code. - As GetSourcePaths() is used once in USETUP to initialize global UNICODE_STRING path strings once, move it out of drivesup.c and put it in usetup.c. Then remove drivesup.c : 1 file less! - Move some INF file prototype declarations out of usetup.h and inside inffile.h where they should better be, as inffile.h and .c is the glue code for the INF library, defining similar functions as the ones in setupapi.dll. - I rename our local SetupOpenInfFileW() into SetupOpenInfFileExW() because the latter one takes an extra user-provided LCID parameter, and this is this one that we use in USETUP. - Make 'UNICODE_STRING SourcePath;' visible only inside usetup.c (not used elsewhere). - Implement installation path validity check in case we are either in repair/update, or unattended setup mode. If the path is detected as invalid, then we fall back into manual path specification (for now...; note that we could instead fail the installation too). svn path=/branches/setup_improvements/; revision=75246 --- diff --git a/base/setup/usetup/CMakeLists.txt b/base/setup/usetup/CMakeLists.txt index db5b7d713b3..21d15544f44 100644 --- a/base/setup/usetup/CMakeLists.txt +++ b/base/setup/usetup/CMakeLists.txt @@ -17,7 +17,6 @@ list(APPEND SOURCE console.c consup.c devinst.c - drivesup.c filesup.c filequeue.c format.c diff --git a/base/setup/usetup/drivesup.c b/base/setup/usetup/drivesup.c deleted file mode 100644 index b8561d77ed1..00000000000 --- a/base/setup/usetup/drivesup.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS text-mode setup - * FILE: base/setup/usetup/drivesup.c - * PURPOSE: Drive support functions - * PROGRAMMER: - */ - -/* INCLUDES *****************************************************************/ - -#include "usetup.h" - -#define NDEBUG -#include - -/* FUNCTIONS ****************************************************************/ - -NTSTATUS -GetSourcePaths( - OUT PUNICODE_STRING SourcePath, - OUT PUNICODE_STRING SourceRootPath, - OUT PUNICODE_STRING SourceRootDir) -{ - NTSTATUS Status; - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING LinkName = RTL_CONSTANT_STRING(L"\\SystemRoot"); - UNICODE_STRING SourceName; - WCHAR SourceBuffer[MAX_PATH] = L""; - HANDLE Handle; - ULONG Length; - PWCHAR Ptr; - - InitializeObjectAttributes(&ObjectAttributes, - &LinkName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - - Status = NtOpenSymbolicLinkObject(&Handle, - SYMBOLIC_LINK_ALL_ACCESS, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - return Status; - - RtlInitEmptyUnicodeString(&SourceName, SourceBuffer, sizeof(SourceBuffer)); - - Status = NtQuerySymbolicLinkObject(Handle, - &SourceName, - &Length); - NtClose(Handle); - - if (!NT_SUCCESS(Status)) - return Status; - - RtlCreateUnicodeString(SourcePath, - SourceName.Buffer); - - /* Strip trailing directory */ - Ptr = wcsrchr(SourceName.Buffer, OBJ_NAME_PATH_SEPARATOR); - if (Ptr) - { - RtlCreateUnicodeString(SourceRootDir, Ptr); - *Ptr = UNICODE_NULL; - } - else - { - RtlCreateUnicodeString(SourceRootDir, L""); - } - - RtlCreateUnicodeString(SourceRootPath, - SourceName.Buffer); - - return STATUS_SUCCESS; -} - -/* EOF */ diff --git a/base/setup/usetup/drivesup.h b/base/setup/usetup/drivesup.h deleted file mode 100644 index 01b38a3c575..00000000000 --- a/base/setup/usetup/drivesup.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS text-mode setup - * FILE: base/setup/usetup/drivesup.h - * PURPOSE: Drive support functions - * PROGRAMMER: - */ - -#pragma once - -NTSTATUS -GetSourcePaths( - OUT PUNICODE_STRING SourcePath, - OUT PUNICODE_STRING SourceRootPath, - OUT PUNICODE_STRING SourceRootDir); - -/* EOF */ diff --git a/base/setup/usetup/inffile.h b/base/setup/usetup/inffile.h index 9ce8ce0b2c6..610c9e23a3b 100644 --- a/base/setup/usetup/inffile.h +++ b/base/setup/usetup/inffile.h @@ -28,10 +28,39 @@ #include +extern VOID InfSetHeap(PVOID Heap); +extern VOID InfCloseFile(HINF InfHandle); +extern BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn, + PINFCONTEXT ContextOut); +extern BOOLEAN InfGetBinaryField(PINFCONTEXT Context, + ULONG FieldIndex, + PUCHAR ReturnBuffer, + ULONG ReturnBufferSize, + PULONG RequiredSize); +extern BOOLEAN InfGetMultiSzField(PINFCONTEXT Context, + ULONG FieldIndex, + PWSTR ReturnBuffer, + ULONG ReturnBufferSize, + PULONG RequiredSize); +extern BOOLEAN InfGetStringField(PINFCONTEXT Context, + ULONG FieldIndex, + PWSTR ReturnBuffer, + ULONG ReturnBufferSize, + PULONG RequiredSize); + +#define SetupCloseInfFile InfCloseFile +#define SetupFindNextLine InfFindNextLine +#define SetupGetBinaryField InfGetBinaryField +#define SetupGetMultiSzFieldW InfGetMultiSzField +#define SetupGetStringFieldW InfGetStringField + + #define SetupFindFirstLineW InfpFindFirstLineW #define SetupGetFieldCount InfGetFieldCount #define SetupGetIntField InfGetIntField -#define SetupOpenInfFileW InfpOpenInfFileW + +// SetupOpenInfFileW with support for a user-provided LCID +#define SetupOpenInfFileExW InfpOpenInfFileW #define INF_STYLE_WIN4 0x00000002 diff --git a/base/setup/usetup/registry.c b/base/setup/usetup/registry.c index 50fbb31d1d9..749835c3d72 100644 --- a/base/setup/usetup/registry.c +++ b/base/setup/usetup/registry.c @@ -618,6 +618,7 @@ registry_callback(HINF hInf, PCWSTR Section, BOOLEAN Delete) BOOLEAN ImportRegistryFile( + PCWSTR SourcePath, PWSTR Filename, PWSTR Section, LCID LocaleId, @@ -629,13 +630,13 @@ ImportRegistryFile( /* Load inf file from install media. */ CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2, - SourcePath.Buffer, Filename); + SourcePath, Filename); - hInf = SetupOpenInfFileW(FileNameBuffer, - NULL, - INF_STYLE_WIN4, - LocaleId, - &ErrorLine); + hInf = SetupOpenInfFileExW(FileNameBuffer, + NULL, + INF_STYLE_WIN4, + LocaleId, + &ErrorLine); if (hInf == INVALID_HANDLE_VALUE) { DPRINT1("SetupOpenInfFile() failed\n"); diff --git a/base/setup/usetup/registry.h b/base/setup/usetup/registry.h index 0548061a35e..b48777a126d 100644 --- a/base/setup/usetup/registry.h +++ b/base/setup/usetup/registry.h @@ -38,6 +38,7 @@ GetRootKeyByName( BOOLEAN ImportRegistryFile( + PCWSTR SourcePath, PWSTR Filename, PWSTR Section, LCID LocaleId, diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index e1a382eafce..79b89824306 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -32,7 +32,6 @@ #include "chkdsk.h" #include "cmdcons.h" #include "format.h" -#include "drivesup.h" #include "settings.h" #define NDEBUG @@ -48,7 +47,7 @@ HANDLE ProcessHeap; static UNICODE_STRING SourceRootPath; static UNICODE_STRING SourceRootDir; -/* static */ UNICODE_STRING SourcePath; +static UNICODE_STRING SourcePath; BOOLEAN IsUnattendedSetup = FALSE; LONG UnattendDestinationDiskNumber; @@ -73,6 +72,10 @@ static FORMATMACHINESTATE FormatState = Start; static PFILE_SYSTEM_LIST FileSystemList = NULL; +/* + * NOTE: Technically only used for the COPYCONTEXT InstallPath member + * for the filequeue functionality. + */ static UNICODE_STRING InstallPath; /* @@ -90,7 +93,7 @@ static UNICODE_STRING InstallPath; */ static UNICODE_STRING SystemRootPath; -/* Path to the install directory inside the ReactOS boot partition */ +/* Path to the installation directory inside the ReactOS boot partition */ static UNICODE_STRING DestinationPath; static UNICODE_STRING DestinationArcPath; static UNICODE_STRING DestinationRootPath; @@ -445,15 +448,15 @@ CheckUnattendedSetup(VOID) } /* Load 'unattend.inf' from install media. */ - UnattendInf = SetupOpenInfFileW(UnattendInfPath, - NULL, - INF_STYLE_WIN4, - LanguageId, - &ErrorLine); + UnattendInf = SetupOpenInfFileExW(UnattendInfPath, + NULL, + INF_STYLE_WIN4, + LanguageId, + &ErrorLine); if (UnattendInf == INVALID_HANDLE_VALUE) { - DPRINT("SetupOpenInfFileW() failed\n"); + DPRINT("SetupOpenInfFileExW() failed\n"); return; } @@ -774,6 +777,65 @@ LanguagePage(PINPUT_RECORD Ir) } +static NTSTATUS +GetSourcePaths( + OUT PUNICODE_STRING SourcePath, + OUT PUNICODE_STRING SourceRootPath, + OUT PUNICODE_STRING SourceRootDir) +{ + NTSTATUS Status; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING LinkName = RTL_CONSTANT_STRING(L"\\SystemRoot"); + UNICODE_STRING SourceName; + WCHAR SourceBuffer[MAX_PATH] = L""; + HANDLE Handle; + ULONG Length; + PWCHAR Ptr; + + InitializeObjectAttributes(&ObjectAttributes, + &LinkName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenSymbolicLinkObject(&Handle, + SYMBOLIC_LINK_ALL_ACCESS, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + return Status; + + RtlInitEmptyUnicodeString(&SourceName, SourceBuffer, sizeof(SourceBuffer)); + + Status = NtQuerySymbolicLinkObject(Handle, + &SourceName, + &Length); + NtClose(Handle); + + if (!NT_SUCCESS(Status)) + return Status; + + RtlCreateUnicodeString(SourcePath, + SourceName.Buffer); + + /* Strip trailing directory */ + Ptr = wcsrchr(SourceName.Buffer, OBJ_NAME_PATH_SEPARATOR); + if (Ptr) + { + RtlCreateUnicodeString(SourceRootDir, Ptr); + *Ptr = UNICODE_NULL; + } + else + { + RtlCreateUnicodeString(SourceRootDir, L""); + } + + RtlCreateUnicodeString(SourceRootPath, + SourceName.Buffer); + + return STATUS_SUCCESS; +} + + /* * Start page * @@ -826,11 +888,11 @@ SetupStartPage(PINPUT_RECORD Ir) /* Load txtsetup.sif from install media. */ CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2, SourcePath.Buffer, L"txtsetup.sif"); - SetupInf = SetupOpenInfFileW(FileNameBuffer, - NULL, - INF_STYLE_WIN4, - LanguageId, - &ErrorLine); + SetupInf = SetupOpenInfFileExW(FileNameBuffer, + NULL, + INF_STYLE_WIN4, + LanguageId, + &ErrorLine); if (SetupInf == INVALID_HANDLE_VALUE) { @@ -3376,6 +3438,7 @@ BuildInstallPaths(PWSTR InstallDir, { WCHAR PathBuffer[MAX_PATH]; +/** Equivalent of 'NTOS_INSTALLATION::PathComponent' **/ /* Create 'InstallPath' string */ RtlFreeUnicodeString(&InstallPath); RtlCreateUnicodeString(&InstallPath, InstallDir); @@ -3389,12 +3452,14 @@ BuildInstallPaths(PWSTR InstallDir, RtlCreateUnicodeString(&DestinationRootPath, PathBuffer); DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath); +/** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/ /* Create 'DestinationPath' string */ RtlFreeUnicodeString(&DestinationPath); CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2, DestinationRootPath.Buffer, InstallDir); RtlCreateUnicodeString(&DestinationPath, PathBuffer); +/** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/ /* Create 'DestinationArcPath' */ RtlFreeUnicodeString(&DestinationArcPath); StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), @@ -3428,7 +3493,7 @@ InstallDirectoryPage(PINPUT_RECORD Ir) WCHAR c; ULONG Length, Pos; - /* We do not need the filesystem list any more */ + /* We do not need the filesystem list anymore */ if (FileSystemList != NULL) { DestroyFileSystemList(FileSystemList); @@ -3446,43 +3511,36 @@ InstallDirectoryPage(PINPUT_RECORD Ir) DiskEntry = PartitionList->CurrentDisk; PartEntry = PartitionList->CurrentPartition; - if (RepairUpdateFlag) - { - if (!IsValidPath(CurrentInstallation->PathComponent)) // SystemNtPath - { - /* FIXME: Log the error? */ - return QUIT_PAGE; - } - - BuildInstallPaths(CurrentInstallation->PathComponent, // SystemNtPath - DiskEntry, - PartEntry); - - return PREPARE_COPY_PAGE; - } if (IsUnattendedSetup) - { - if (!IsValidPath(UnattendInstallationDirectory)) - { - /* FIXME: Log the error? */ - return QUIT_PAGE; - } + wcscpy(InstallDir, UnattendInstallationDirectory); + else if (RepairUpdateFlag) + wcscpy(InstallDir, CurrentInstallation->PathComponent); // SystemNtPath + else + wcscpy(InstallDir, L"\\ReactOS"); - BuildInstallPaths(UnattendInstallationDirectory, + /* + * Check the validity of the predefined 'InstallDir'. If we are either + * in unattended setup or in update/repair mode, and the installation path + * is valid, just perform the installation. Otherwise (either in the case + * of an invalid path, or we are in regular setup), display the UI and allow + * the user to specify a new installation path. + */ + if ((RepairUpdateFlag || IsUnattendedSetup) && IsValidPath(InstallDir)) + { + BuildInstallPaths(InstallDir, DiskEntry, PartEntry); return PREPARE_COPY_PAGE; } - wcscpy(InstallDir, L"\\ReactOS"); - Length = wcslen(InstallDir); Pos = Length; + + MUIDisplayPage(INSTALL_DIRECTORY_PAGE); CONSOLE_SetInputTextXY(8, 11, 51, InstallDir); CONSOLE_SetCursorXY(8 + Pos, 11); CONSOLE_SetCursorType(TRUE, TRUE); - MUIDisplayPage(INSTALL_DIRECTORY_PAGE); while (TRUE) { @@ -4336,7 +4394,7 @@ DoUpdate: CONSOLE_SetStatusText(MUIGetString(STRING_IMPORTFILE), File); - if (!ImportRegistryFile(File, Section, LanguageId, Delete)) + if (!ImportRegistryFile(SourcePath.Buffer, File, Section, LanguageId, Delete)) { DPRINT1("Importing %S failed\n", File); MUIDisplayError(ERROR_IMPORT_HIVE, Ir, POPUP_WAIT_ENTER); diff --git a/base/setup/usetup/usetup.h b/base/setup/usetup/usetup.h index d0ce275f75a..6e95582ce7a 100644 --- a/base/setup/usetup/usetup.h +++ b/base/setup/usetup/usetup.h @@ -72,36 +72,9 @@ #include "mui.h" extern HANDLE ProcessHeap; -extern UNICODE_STRING SourcePath; extern BOOLEAN IsUnattendedSetup; extern PWCHAR SelectedLanguageId; -extern VOID InfSetHeap(PVOID Heap); -extern VOID InfCloseFile(HINF InfHandle); -extern BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn, - PINFCONTEXT ContextOut); -extern BOOLEAN InfGetBinaryField(PINFCONTEXT Context, - ULONG FieldIndex, - PUCHAR ReturnBuffer, - ULONG ReturnBufferSize, - PULONG RequiredSize); -extern BOOLEAN InfGetMultiSzField(PINFCONTEXT Context, - ULONG FieldIndex, - PWSTR ReturnBuffer, - ULONG ReturnBufferSize, - PULONG RequiredSize); -extern BOOLEAN InfGetStringField(PINFCONTEXT Context, - ULONG FieldIndex, - PWSTR ReturnBuffer, - ULONG ReturnBufferSize, - PULONG RequiredSize); - -#define SetupCloseInfFile InfCloseFile -#define SetupFindNextLine InfFindNextLine -#define SetupGetBinaryField InfGetBinaryField -#define SetupGetMultiSzFieldW InfGetMultiSzField -#define SetupGetStringFieldW InfGetStringField - typedef enum _PAGE_NUMBER { LANGUAGE_PAGE,