Author: hbelusca Date: Wed May 31 02:19:08 2017 New Revision: 74717
URL: http://svn.reactos.org/svn/reactos?rev=74717&view=rev Log: [USETUP]: Diverse fixes: - Convert almost all swprintf into StringCchPrintfW, and wcscpy into StringCchCopyW; - Explicitly add a trailing path separator to the "\Device\HarddiskX\PartitionY()" paths when they refer to FS directories (and not to partition objects); - Remove useless (and half-buggy) "Remove trailing backslash" code; With that, it is possible to install ReactOS in e.g. C:\ReactOS (as usual), C:\ReactOS\dir1\dir2 (as many dirs as you wish), and also in C:\ (yes yes!). But in that latter case, a strange bug related to the registry arises...
Additionally: - Adjust some comments; - Add some debugging DPRINTs; - The SetInstallPathValue() is part of the big hack I've mentioned in r74709;
Modified: branches/setup_improvements/base/setup/usetup/interface/usetup.c branches/setup_improvements/base/setup/usetup/usetup.h
Modified: branches/setup_improvements/base/setup/usetup/interface/usetup.c URL: http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/us... ============================================================================== --- branches/setup_improvements/base/setup/usetup/interface/usetup.c [iso-8859-1] (original) +++ branches/setup_improvements/base/setup/usetup/interface/usetup.c [iso-8859-1] Wed May 31 02:19:08 2017 @@ -42,9 +42,9 @@ /* GLOBALS ******************************************************************/
HANDLE ProcessHeap; -UNICODE_STRING SourceRootPath; -UNICODE_STRING SourceRootDir; -UNICODE_STRING SourcePath; +static UNICODE_STRING SourceRootPath; +static UNICODE_STRING SourceRootDir; +/* static */ UNICODE_STRING SourcePath; BOOLEAN IsUnattendedSetup = FALSE; LONG UnattendDestinationDiskNumber; LONG UnattendDestinationPartitionNumber; @@ -430,7 +430,7 @@ INT IntValue; PWCHAR Value;
- CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2, SourcePath.Buffer, L"\unattend.inf"); + CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2, SourcePath.Buffer, L"unattend.inf");
if (DoesFileExist(NULL, UnattendInfPath) == FALSE) { @@ -583,7 +583,7 @@ if (INF_GetData(&Context, NULL, &Value)) { LONG Id = wcstol(Value, NULL, 16); - swprintf(LocaleID,L"%08lx", Id); + swprintf(LocaleID, L"%08lx", Id); } }
@@ -809,24 +809,18 @@ Status = GetSourcePaths(&SourcePath, &SourceRootPath, &SourceRootDir); - if (!NT_SUCCESS(Status)) { CONSOLE_PrintTextXY(6, 15, "GetSourcePaths() failed (Status 0x%08lx)", Status); MUIDisplayError(ERROR_NO_SOURCE_DRIVE, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } -#if 0 - else - { - CONSOLE_PrintTextXY(6, 15, "SourcePath: '%wZ'", &SourcePath); - CONSOLE_PrintTextXY(6, 16, "SourceRootPath: '%wZ'", &SourceRootPath); - CONSOLE_PrintTextXY(6, 17, "SourceRootDir: '%wZ'", &SourceRootDir); - } -#endif + DPRINT1("SourcePath: '%wZ'", &SourcePath); + DPRINT1("SourceRootPath: '%wZ'", &SourceRootPath); + DPRINT1("SourceRootDir: '%wZ'", &SourceRootDir);
/* Load txtsetup.sif from install media. */ - CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2, SourcePath.Buffer, L"\txtsetup.sif"); + CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2, SourcePath.Buffer, L"txtsetup.sif"); SetupInf = SetupOpenInfFileW(FileNameBuffer, NULL, INF_STYLE_WIN4, @@ -2717,6 +2711,13 @@ if (PartitionList->SystemPartition == NULL) { /* FIXME: show an error dialog */ + // + // Error dialog should say that we cannot find a suitable + // system partition and create one on the system. At this point, + // it may be nice to ask the user whether he wants to continue, + // or use an external drive as the system drive/partition + // (e.g. floppy, USB drive, etc...) + // return QUIT_PAGE; }
@@ -3106,12 +3107,11 @@ }
/* Set PartitionRootPath */ - swprintf(PathBuffer, - L"\Device\Harddisk%lu\Partition%lu", - DiskEntry->DiskNumber, - PartEntry->PartitionNumber); - RtlInitUnicodeString(&PartitionRootPath, - PathBuffer); + StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\Device\Harddisk%lu\Partition%lu", + DiskEntry->DiskNumber, + PartEntry->PartitionNumber); + RtlInitUnicodeString(&PartitionRootPath, PathBuffer); DPRINT("PartitionRootPath: %wZ\n", &PartitionRootPath);
/* Format the partition */ @@ -3180,10 +3180,10 @@ }
/* Set PartitionRootPath */ - swprintf(PathBuffer, - L"\Device\Harddisk%lu\Partition%lu", - DiskEntry->DiskNumber, - PartEntry->PartitionNumber); + StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\Device\Harddisk%lu\Partition%lu", + DiskEntry->DiskNumber, + PartEntry->PartitionNumber); RtlInitUnicodeString(&PartitionRootPath, PathBuffer); DPRINT("PartitionRootPath: %wZ\n", &PartitionRootPath);
@@ -3284,10 +3284,10 @@
/* Create 'DestinationRootPath' string */ RtlFreeUnicodeString(&DestinationRootPath); - swprintf(PathBuffer, - L"\Device\Harddisk%lu\Partition%lu", - DiskEntry->DiskNumber, - PartEntry->PartitionNumber); + StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\Device\Harddisk%lu\Partition%lu\", + DiskEntry->DiskNumber, + PartEntry->PartitionNumber); RtlCreateUnicodeString(&DestinationRootPath, PathBuffer); DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath);
@@ -3299,10 +3299,10 @@
/* Create 'DestinationArcPath' */ RtlFreeUnicodeString(&DestinationArcPath); - swprintf(PathBuffer, - L"multi(0)disk(0)rdisk(%lu)partition(%lu)", - DiskEntry->BiosDiskNumber, - PartEntry->PartitionNumber); + StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"multi(0)disk(0)rdisk(%lu)partition(%lu)\", + DiskEntry->BiosDiskNumber, + PartEntry->PartitionNumber); ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallDir); RtlCreateUnicodeString(&DestinationArcPath, PathBuffer);
@@ -3446,18 +3446,23 @@ PWCHAR DirKeyValue; PWCHAR TargetFileName;
+ /* + * This code enumerates the list of files in reactos.dff / reactos.inf + * that need to be extracted from reactos.cab and be installed in their + * respective directories. + */ + /* Search for the SectionName section */ if (!SetupFindFirstLineW(InfFile, SectionName, NULL, &FilesContext)) { - char Buffer[128]; + CHAR Buffer[128]; sprintf(Buffer, MUIGetString(STRING_TXTSETUPFAILED), SectionName); PopupError(Buffer, MUIGetString(STRING_REBOOTCOMPUTER), Ir, POPUP_WAIT_ENTER); return FALSE; }
/* - * Enumerate the files in the section - * and add them to the file queue. + * Enumerate the files in the section and add them to the file queue. */ do { @@ -3520,24 +3525,27 @@ PWCHAR FileKeyValue; PWCHAR DirKeyValue; PWCHAR TargetFileName; - ULONG Length; - WCHAR CompleteOrigDirName[512]; + WCHAR CompleteOrigDirName[512]; // FIXME: MAX_PATH is not enough?
if (SourceCabinet) return AddSectionToCopyQueueCab(InfFile, L"SourceFiles", SourceCabinet, DestinationPath, Ir);
+ /* + * This code enumerates the list of files in txtsetup.sif + * that need to be installed in their respective directories. + */ + /* Search for the SectionName section */ if (!SetupFindFirstLineW(InfFile, SectionName, NULL, &FilesContext)) { - char Buffer[128]; + CHAR Buffer[128]; sprintf(Buffer, MUIGetString(STRING_TXTSETUPFAILED), SectionName); PopupError(Buffer, MUIGetString(STRING_REBOOTCOMPUTER), Ir, POPUP_WAIT_ENTER); return FALSE; }
/* - * Enumerate the files in the section - * and add them to the file queue. + * Enumerate the files in the section and add them to the file queue. */ do { @@ -3583,25 +3591,32 @@ if ((DirKeyValue[0] == UNICODE_NULL) || (DirKeyValue[0] == L'\' && DirKeyValue[1] == UNICODE_NULL)) { /* Installation path */ - wcscpy(CompleteOrigDirName, SourceRootDir.Buffer); + DPRINT("InstallationPath: '%S'\n", DirKeyValue); + + StringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), + SourceRootDir.Buffer); + + DPRINT("InstallationPath(2): '%S'\n", CompleteOrigDirName); } else if (DirKeyValue[0] == L'\') { /* Absolute path */ - wcscpy(CompleteOrigDirName, DirKeyValue); + DPRINT("AbsolutePath: '%S'\n", DirKeyValue); + + StringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), + DirKeyValue); + + DPRINT("AbsolutePath(2): '%S'\n", CompleteOrigDirName); } else // if (DirKeyValue[0] != L'\') { /* Path relative to the installation path */ + DPRINT("RelativePath: '%S'\n", DirKeyValue); + CombinePaths(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), 2, SourceRootDir.Buffer, DirKeyValue); - } - - /* Remove trailing backslash */ - Length = wcslen(CompleteOrigDirName); - if ((Length > 0) && (CompleteOrigDirName[Length - 1] == L'\')) - { - CompleteOrigDirName[Length - 1] = UNICODE_NULL; + + DPRINT("RelativePath(2): '%S'\n", CompleteOrigDirName); }
if (!SetupQueueCopy(SetupFileQueue, @@ -3626,12 +3641,11 @@ PWCHAR SourceCabinet, PINPUT_RECORD Ir) { - WCHAR PathBuffer[MAX_PATH]; + NTSTATUS Status; INFCONTEXT DirContext; PWCHAR AdditionalSectionName = NULL; PWCHAR DirKeyValue; - ULONG Length; - NTSTATUS Status; + WCHAR PathBuffer[MAX_PATH];
/* Add common files */ if (!AddSectionToCopyQueue(InfFile, L"SourceDisksFiles", SourceCabinet, &DestinationPath, Ir)) @@ -3654,28 +3668,22 @@
/* * FIXME: - * - Install directories like '\reactos\test' are not handled yet. - * - Copying files to DestinationRootPath should be done from within - * the SystemPartitionFiles section. - * At the moment we check whether we specify paths like '\foo' or '\' for that. - * For installing to DestinationPath specify just '' . + * Copying files to DestinationRootPath should be done from within + * the SystemPartitionFiles section. + * At the moment we check whether we specify paths like '\foo' or '\' for that. + * For installing to DestinationPath specify just '' . */
/* Get destination path */ - wcscpy(PathBuffer, DestinationPath.Buffer); - - /* Remove trailing backslash */ - Length = wcslen(PathBuffer); - if ((Length > 0) && (PathBuffer[Length - 1] == L'\')) - { - PathBuffer[Length - 1] = UNICODE_NULL; - } + StringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), DestinationPath.Buffer); + + DPRINT("FullPath(1): '%S'\n", PathBuffer);
/* Create the install directory */ Status = SetupCreateDirectory(PathBuffer); if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION) { - DPRINT1("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status); + DPRINT1("Creating directory '%S' failed: Status = 0x%08lx\n", PathBuffer, Status); MUIDisplayError(ERROR_CREATE_INSTALL_DIR, Ir, POPUP_WAIT_ENTER); return FALSE; } @@ -3709,26 +3717,20 @@ /* Installation path */ DPRINT("InstallationPath: '%S'\n", DirKeyValue);
- wcscpy(PathBuffer, DestinationPath.Buffer); - - DPRINT("FullPath: '%S'\n", PathBuffer); + StringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), + DestinationPath.Buffer); + + DPRINT("InstallationPath(2): '%S'\n", PathBuffer); } else if (DirKeyValue[0] == L'\') { /* Absolute path */ - DPRINT("Absolute Path: '%S'\n", DirKeyValue); + DPRINT("AbsolutePath: '%S'\n", DirKeyValue);
CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2, DestinationRootPath.Buffer, DirKeyValue);
- /* Remove trailing backslash */ - Length = wcslen(PathBuffer); - if ((Length > 0) && (PathBuffer[Length - 1] == L'\')) - { - PathBuffer[Length - 1] = UNICODE_NULL; - } - - DPRINT("FullPath: '%S'\n", PathBuffer); + DPRINT("AbsolutePath(2): '%S'\n", PathBuffer);
Status = SetupCreateDirectory(PathBuffer); if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION) @@ -3746,14 +3748,7 @@ CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2, DestinationPath.Buffer, DirKeyValue);
- /* Remove trailing backslash */ - Length = wcslen(PathBuffer); - if ((Length > 0) && (PathBuffer[Length - 1] == L'\')) - { - PathBuffer[Length - 1] = UNICODE_NULL; - } - - DPRINT("FullPath: '%S'\n", PathBuffer); + DPRINT("RelativePath(2): '%S'\n", PathBuffer);
Status = SetupCreateDirectory(PathBuffer); if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION) @@ -4075,12 +4070,14 @@ return SUCCESS_PAGE; }
+ /************************ HACK!!!!!!!!!!! *********************************/ if (!SetInstallPathValue(&DestinationPath)) { DPRINT1("SetInstallPathValue() failed\n"); MUIDisplayError(ERROR_INITIALIZE_REGISTRY, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } + /************************ HACK!!!!!!!!!!! *********************************/
/* Create the default hives */ Status = NtInitializeRegistry(CM_BOOT_FLAG_SETUP); @@ -4230,10 +4227,10 @@ CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
RtlFreeUnicodeString(&SystemRootPath); - swprintf(PathBuffer, - L"\Device\Harddisk%lu\Partition%lu", - PartitionList->SystemPartition->DiskEntry->DiskNumber, - PartitionList->SystemPartition->PartitionNumber); + StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\Device\Harddisk%lu\Partition%lu\", + PartitionList->SystemPartition->DiskEntry->DiskNumber, + PartitionList->SystemPartition->PartitionNumber); RtlCreateUnicodeString(&SystemRootPath, PathBuffer); DPRINT1("SystemRootPath: %wZ\n", &SystemRootPath);
@@ -4472,7 +4469,7 @@ * * SIDEEFFECTS * Calls InstallVBRToPartition() - * CallsInstallMbrBootCodeToDisk() + * Calls InstallMbrBootCodeToDisk() * * RETURNS * Number of the next page. @@ -4497,16 +4494,16 @@ }
/* Step 2: Write the MBR */ - swprintf(DestinationDevicePathBuffer, - L"\Device\Harddisk%d\Partition0", - PartitionList->SystemPartition->DiskEntry->DiskNumber); + StringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), + L"\Device\Harddisk%d\Partition0", + PartitionList->SystemPartition->DiskEntry->DiskNumber);
CombinePaths(SourceMbrPathBuffer, ARRAYSIZE(SourceMbrPathBuffer), 2, SourceRootPath.Buffer, L"\loader\dosmbr.bin");
if (IsThereAValidBootSector(DestinationDevicePathBuffer)) { /* Save current MBR */ - CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath.Buffer, L"\mbr.old"); + CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath.Buffer, L"mbr.old");
DPRINT1("Save MBR: %S ==> %S\n", DestinationDevicePathBuffer, DstPath); Status = SaveBootSector(DestinationDevicePathBuffer, DstPath, sizeof(PARTITION_SECTOR));
Modified: branches/setup_improvements/base/setup/usetup/usetup.h URL: http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/us... ============================================================================== --- branches/setup_improvements/base/setup/usetup/usetup.h [iso-8859-1] (original) +++ branches/setup_improvements/base/setup/usetup/usetup.h [iso-8859-1] Wed May 31 02:19:08 2017 @@ -75,8 +75,6 @@ #include "mui.h"
extern HANDLE ProcessHeap; -extern UNICODE_STRING SourceRootPath; -extern UNICODE_STRING SourceRootDir; extern UNICODE_STRING SourcePath; extern BOOLEAN IsUnattendedSetup; extern PWCHAR SelectedLanguageId;