[SETUPLIB][USETUP] Transform the existing ConcatPaths() function into a variadic function, and derive a CombinePaths() from it (plus their equivalent taking va_list).

This allows building concatenated paths with an arbitrary number of separated components.
- Use the newly-introduced CombinePaths() and ConcatPaths() functions.
- Fix also few comments, and place some UNICODE_NULLs here & there.

svn path=/branches/setup_improvements/; revision=74637
svn path=/branches/setup_improvements/; revision=74640
This commit is contained in:
Hermès Bélusca-Maïto 2017-05-23 22:30:54 +00:00
parent 92b99b865e
commit d27ef70aab
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
8 changed files with 201 additions and 167 deletions

View file

@ -798,7 +798,7 @@ ArcPathToNtPath(
*/ */
if (BeginOfPath && *BeginOfPath) if (BeginOfPath && *BeginOfPath)
{ {
Status = ConcatPaths(NtPath->Buffer, NtPath->MaximumLength / sizeof(WCHAR), BeginOfPath); Status = ConcatPaths(NtPath->Buffer, NtPath->MaximumLength / sizeof(WCHAR), 1, BeginOfPath);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Buffer not large enough, or whatever...: just bail out */ /* Buffer not large enough, or whatever...: just bail out */

View file

@ -13,36 +13,113 @@
#include <debug.h> #include <debug.h>
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
NTSTATUS NTSTATUS
ConcatPaths( ConcatPathsV(
IN OUT PWSTR PathElem1, IN OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize, IN SIZE_T cchPathSize,
IN PCWSTR PathElem2 OPTIONAL) IN ULONG NumberOfPathComponents,
IN va_list PathComponentsList)
{ {
NTSTATUS Status; NTSTATUS Status = STATUS_SUCCESS;
SIZE_T cchPathLen; SIZE_T cchPathLen;
PCWSTR PathComponent;
if (!PathElem2) if (cchPathSize < 1)
return STATUS_SUCCESS;
if (cchPathSize <= 1)
return STATUS_SUCCESS; return STATUS_SUCCESS;
cchPathLen = min(cchPathSize, wcslen(PathElem1)); while (NumberOfPathComponents--)
if (PathElem2[0] != L'\\' && cchPathLen > 0 && PathElem1[cchPathLen-1] != L'\\')
{ {
/* PathElem2 does not start with '\' and PathElem1 does not end with '\' */ PathComponent = va_arg(PathComponentsList, PCWSTR);
Status = RtlStringCchCatW(PathElem1, cchPathSize, L"\\"); if (!PathComponent)
continue;
cchPathLen = min(cchPathSize, wcslen(PathBuffer));
if (cchPathLen >= cchPathSize)
return STATUS_BUFFER_OVERFLOW;
if (PathComponent[0] != OBJ_NAME_PATH_SEPARATOR &&
cchPathLen > 0 && PathBuffer[cchPathLen-1] != OBJ_NAME_PATH_SEPARATOR)
{
/* PathComponent does not start with '\' and PathBuffer does not end with '\' */
Status = RtlStringCchCatW(PathBuffer, cchPathSize, L"\\");
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
} }
else if (PathElem2[0] == L'\\' && cchPathLen > 0 && PathElem1[cchPathLen-1] == L'\\') else if (PathComponent[0] == OBJ_NAME_PATH_SEPARATOR &&
cchPathLen > 0 && PathBuffer[cchPathLen-1] == OBJ_NAME_PATH_SEPARATOR)
{ {
/* PathElem2 starts with '\' and PathElem1 ends with '\' */ /* PathComponent starts with '\' and PathBuffer ends with '\' */
while (*PathElem2 == L'\\') while (*PathComponent == OBJ_NAME_PATH_SEPARATOR)
++PathElem2; // Skip any backslash ++PathComponent; // Skip any backslash
} }
Status = RtlStringCchCatW(PathElem1, cchPathSize, PathElem2); Status = RtlStringCchCatW(PathBuffer, cchPathSize, PathComponent);
if (!NT_SUCCESS(Status))
return Status;
}
return Status;
}
NTSTATUS
CombinePathsV(
OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
IN ULONG NumberOfPathComponents,
IN va_list PathComponentsList)
{
if (cchPathSize < 1)
return STATUS_SUCCESS;
*PathBuffer = UNICODE_NULL;
return ConcatPathsV(PathBuffer, cchPathSize,
NumberOfPathComponents,
PathComponentsList);
}
NTSTATUS
ConcatPaths(
IN OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
IN ULONG NumberOfPathComponents,
IN /* PCWSTR */ ...)
{
NTSTATUS Status;
va_list PathComponentsList;
if (cchPathSize < 1)
return STATUS_SUCCESS;
va_start(PathComponentsList, NumberOfPathComponents);
Status = ConcatPathsV(PathBuffer, cchPathSize,
NumberOfPathComponents,
PathComponentsList);
va_end(PathComponentsList);
return Status;
}
NTSTATUS
CombinePaths(
OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
IN ULONG NumberOfPathComponents,
IN /* PCWSTR */ ...)
{
NTSTATUS Status;
va_list PathComponentsList;
if (cchPathSize < 1)
return STATUS_SUCCESS;
*PathBuffer = UNICODE_NULL;
va_start(PathComponentsList, NumberOfPathComponents);
Status = CombinePathsV(PathBuffer, cchPathSize,
NumberOfPathComponents,
PathComponentsList);
va_end(PathComponentsList);
return Status; return Status;
} }
@ -95,14 +172,7 @@ DoesFileExist(
UNICODE_STRING Name; UNICODE_STRING Name;
WCHAR FullName[MAX_PATH]; WCHAR FullName[MAX_PATH];
if (PathName) CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName);
RtlStringCchCopyW(FullName, ARRAYSIZE(FullName), PathName);
else
FullName[0] = UNICODE_NULL;
if (FileName)
ConcatPaths(FullName, ARRAYSIZE(FullName), FileName);
RtlInitUnicodeString(&Name, FullName); RtlInitUnicodeString(&Name, FullName);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
@ -243,14 +313,7 @@ OpenAndMapFile(
UNICODE_STRING Name; UNICODE_STRING Name;
WCHAR FullName[MAX_PATH]; WCHAR FullName[MAX_PATH];
if (PathName) CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName);
RtlStringCchCopyW(FullName, ARRAYSIZE(FullName), PathName);
else
FullName[0] = UNICODE_NULL;
if (FileName)
ConcatPaths(FullName, ARRAYSIZE(FullName), FileName);
RtlInitUnicodeString(&Name, FullName); RtlInitUnicodeString(&Name, FullName);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,

View file

@ -16,10 +16,32 @@ IsValidPath(
#endif #endif
NTSTATUS NTSTATUS
ConcatPaths( ConcatPathsV(
IN OUT PWSTR PathElem1, IN OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize, IN SIZE_T cchPathSize,
IN PCWSTR PathElem2 OPTIONAL); IN ULONG NumberOfPathComponents,
IN va_list PathComponentsList);
NTSTATUS
CombinePathsV(
OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
IN ULONG NumberOfPathComponents,
IN va_list PathComponentsList);
NTSTATUS
ConcatPaths(
IN OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
IN ULONG NumberOfPathComponents,
IN /* PCWSTR */ ...);
NTSTATUS
CombinePaths(
OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
IN ULONG NumberOfPathComponents,
IN /* PCWSTR */ ...);
BOOLEAN BOOLEAN
DoesPathExist( DoesPathExist(

View file

@ -1269,7 +1269,10 @@ InstallMbrBootCodeToDisk(
return Status; return Status;
} }
/* Copy partition table from old MBR to new */ /*
* Copy the disk signature, the reserved fields and
* the partition table from the old MBR to the new one.
*/
RtlCopyMemory(&NewBootSector->Signature, RtlCopyMemory(&NewBootSector->Signature,
&OrigBootSector->Signature, &OrigBootSector->Signature,
sizeof(PARTITION_SECTOR) - offsetof(PARTITION_SECTOR, Signature) /* Length of partition table */); sizeof(PARTITION_SECTOR) - offsetof(PARTITION_SECTOR, Signature) /* Length of partition table */);
@ -2258,10 +2261,8 @@ InstallFatBootcodeToPartition(
DPRINT("System path: '%wZ'\n", SystemRootPath); DPRINT("System path: '%wZ'\n", SystemRootPath);
/* Copy FreeLoader to the system partition */ /* Copy FreeLoader to the system partition */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
wcscat(SrcPath, L"\\loader\\freeldr.sys"); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.sys");
wcscpy(DstPath, SystemRootPath->Buffer);
wcscat(DstPath, L"\\freeldr.sys");
DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
Status = SetupCopyFile(SrcPath, DstPath); Status = SetupCopyFile(SrcPath, DstPath);
@ -2272,10 +2273,9 @@ InstallFatBootcodeToPartition(
} }
/* Prepare for possibly copying 'freeldr.ini' */ /* Prepare for possibly copying 'freeldr.ini' */
wcscpy(DstPath, SystemRootPath->Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
wcscat(DstPath, L"\\freeldr.ini");
DoesFreeLdrExist = DoesFileExist(NULL, SystemRootPath->Buffer, L"freeldr.ini"); DoesFreeLdrExist = DoesFileExist(NULL, NULL, DstPath);
if (DoesFreeLdrExist) if (DoesFreeLdrExist)
{ {
/* Update existing 'freeldr.ini' */ /* Update existing 'freeldr.ini' */
@ -2303,8 +2303,7 @@ InstallFatBootcodeToPartition(
{ {
/* Create new 'freeldr.ini' */ /* Create new 'freeldr.ini' */
DPRINT1("Create new 'freeldr.ini'\n"); DPRINT1("Create new 'freeldr.ini'\n");
// wcscpy(DstPath, SystemRootPath->Buffer); // CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
// wcscat(DstPath, L"\\freeldr.ini");
Status = CreateFreeLoaderIniForReactOS(DstPath, DestinationArcPath->Buffer); Status = CreateFreeLoaderIniForReactOS(DstPath, DestinationArcPath->Buffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -2314,15 +2313,13 @@ InstallFatBootcodeToPartition(
} }
/* Install new bootcode into a file */ /* Install new bootcode into a file */
wcscpy(DstPath, SystemRootPath->Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\bootsect.ros");
wcscat(DstPath, L"\\bootsect.ros");
if (PartitionType == PARTITION_FAT32 || if (PartitionType == PARTITION_FAT32 ||
PartitionType == PARTITION_FAT32_XINT13) PartitionType == PARTITION_FAT32_XINT13)
{ {
/* Install FAT32 bootcode */ /* Install FAT32 bootcode */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat32.bin");
wcscat(SrcPath, L"\\loader\\fat32.bin");
DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath, DstPath); DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath, DstPath);
Status = InstallFat32BootCodeToFile(SrcPath, DstPath, Status = InstallFat32BootCodeToFile(SrcPath, DstPath,
@ -2336,8 +2333,7 @@ InstallFatBootcodeToPartition(
else else
{ {
/* Install FAT16 bootcode */ /* Install FAT16 bootcode */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat.bin");
wcscat(SrcPath, L"\\loader\\fat.bin");
DPRINT1("Install FAT bootcode: %S ==> %S\n", SrcPath, DstPath); DPRINT1("Install FAT bootcode: %S ==> %S\n", SrcPath, DstPath);
Status = InstallFat16BootCodeToFile(SrcPath, DstPath, Status = InstallFat16BootCodeToFile(SrcPath, DstPath,
@ -2351,8 +2347,7 @@ InstallFatBootcodeToPartition(
} }
/* Update 'boot.ini' */ /* Update 'boot.ini' */
wcscpy(DstPath, SystemRootPath->Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\boot.ini");
wcscat(DstPath, L"\\boot.ini");
DPRINT1("Update 'boot.ini': %S\n", DstPath); DPRINT1("Update 'boot.ini': %S\n", DstPath);
Status = UpdateBootIni(DstPath, Status = UpdateBootIni(DstPath,
@ -2422,8 +2417,7 @@ InstallFatBootcodeToPartition(
{ {
/* Create new 'freeldr.ini' */ /* Create new 'freeldr.ini' */
DPRINT1("Create new 'freeldr.ini'\n"); DPRINT1("Create new 'freeldr.ini'\n");
// wcscpy(DstPath, SystemRootPath->Buffer); // CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
// wcscat(DstPath, L"\\freeldr.ini");
if (IsThereAValidBootSector(SystemRootPath->Buffer)) if (IsThereAValidBootSector(SystemRootPath->Buffer))
{ {
@ -2438,8 +2432,7 @@ InstallFatBootcodeToPartition(
} }
/* Save current bootsector */ /* Save current bootsector */
wcscpy(DstPath, SystemRootPath->Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, BootSectorFileName);
wcscat(DstPath, BootSectorFileName);
DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath); DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath);
Status = SaveBootSector(SystemRootPath->Buffer, DstPath, SECTORSIZE); Status = SaveBootSector(SystemRootPath->Buffer, DstPath, SECTORSIZE);
@ -2464,8 +2457,7 @@ InstallFatBootcodeToPartition(
PartitionType == PARTITION_FAT32_XINT13) PartitionType == PARTITION_FAT32_XINT13)
{ {
/* Install FAT32 bootcode */ /* Install FAT32 bootcode */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat32.bin");
wcscat(SrcPath, L"\\loader\\fat32.bin");
DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer); DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
Status = InstallFat32BootCodeToDisk(SrcPath, SystemRootPath->Buffer); Status = InstallFat32BootCodeToDisk(SrcPath, SystemRootPath->Buffer);
@ -2478,8 +2470,7 @@ InstallFatBootcodeToPartition(
else else
{ {
/* Install FAT16 bootcode */ /* Install FAT16 bootcode */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat.bin");
wcscat(SrcPath, L"\\loader\\fat.bin");
DPRINT1("Install FAT16 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer); DPRINT1("Install FAT16 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
Status = InstallFat16BootCodeToDisk(SrcPath, SystemRootPath->Buffer); Status = InstallFat16BootCodeToDisk(SrcPath, SystemRootPath->Buffer);
@ -2512,10 +2503,8 @@ InstallExt2BootcodeToPartition(
DPRINT("System path: '%wZ'\n", SystemRootPath); DPRINT("System path: '%wZ'\n", SystemRootPath);
/* Copy FreeLoader to the system partition */ /* Copy FreeLoader to the system partition */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
wcscat(SrcPath, L"\\loader\\freeldr.sys"); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.sys");
wcscpy(DstPath, SystemRootPath->Buffer);
wcscat(DstPath, L"\\freeldr.sys");
DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
Status = SetupCopyFile(SrcPath, DstPath); Status = SetupCopyFile(SrcPath, DstPath);
@ -2526,10 +2515,9 @@ InstallExt2BootcodeToPartition(
} }
/* Prepare for possibly copying 'freeldr.ini' */ /* Prepare for possibly copying 'freeldr.ini' */
wcscpy(DstPath, SystemRootPath->Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
wcscat(DstPath, L"\\freeldr.ini");
DoesFreeLdrExist = DoesFileExist(NULL, SystemRootPath->Buffer, L"freeldr.ini"); DoesFreeLdrExist = DoesFileExist(NULL, NULL, DstPath);
if (DoesFreeLdrExist) if (DoesFreeLdrExist)
{ {
/* Update existing 'freeldr.ini' */ /* Update existing 'freeldr.ini' */
@ -2550,8 +2538,7 @@ InstallExt2BootcodeToPartition(
{ {
/* Create new 'freeldr.ini' */ /* Create new 'freeldr.ini' */
DPRINT1("Create new 'freeldr.ini'\n"); DPRINT1("Create new 'freeldr.ini'\n");
wcscpy(DstPath, SystemRootPath->Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
wcscat(DstPath, L"\\freeldr.ini");
/* Certainly SysLinux, GRUB, LILO... or an unknown boot loader */ /* Certainly SysLinux, GRUB, LILO... or an unknown boot loader */
DPRINT1("*nix or unknown boot loader found\n"); DPRINT1("*nix or unknown boot loader found\n");
@ -2569,8 +2556,7 @@ InstallExt2BootcodeToPartition(
} }
/* Save current bootsector */ /* Save current bootsector */
wcscpy(DstPath, SystemRootPath->Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\bootsect.old");
wcscat(DstPath, L"\\bootsect.old");
DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath); DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath);
Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(EXT2_BOOTSECTOR)); Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(EXT2_BOOTSECTOR));
@ -2594,8 +2580,7 @@ InstallExt2BootcodeToPartition(
// if (PartitionType == PARTITION_EXT2) // if (PartitionType == PARTITION_EXT2)
{ {
/* Install EXT2 bootcode */ /* Install EXT2 bootcode */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\ext2.bin");
wcscat(SrcPath, L"\\loader\\ext2.bin");
DPRINT1("Install EXT2 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer); DPRINT1("Install EXT2 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
Status = InstallExt2BootCodeToDisk(SrcPath, SystemRootPath->Buffer); Status = InstallExt2BootCodeToDisk(SrcPath, SystemRootPath->Buffer);
@ -2684,10 +2669,9 @@ InstallFatBootcodeToFloppy(
} }
/* Copy FreeLoader to the boot partition */ /* Copy FreeLoader to the boot partition */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
wcscat(SrcPath, L"\\loader\\freeldr.sys");
wcscpy(DstPath, L"\\Device\\Floppy0\\freeldr.sys"); RtlStringCchCopyW(DstPath, ARRAYSIZE(DstPath), L"\\Device\\Floppy0\\freeldr.sys");
DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath); DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
Status = SetupCopyFile(SrcPath, DstPath); Status = SetupCopyFile(SrcPath, DstPath);
@ -2698,7 +2682,7 @@ InstallFatBootcodeToFloppy(
} }
/* Create new 'freeldr.ini' */ /* Create new 'freeldr.ini' */
wcscpy(DstPath, L"\\Device\\Floppy0\\freeldr.ini"); RtlStringCchCopyW(DstPath, ARRAYSIZE(DstPath), L"\\Device\\Floppy0\\freeldr.ini");
DPRINT("Create new 'freeldr.ini'\n"); DPRINT("Create new 'freeldr.ini'\n");
Status = CreateFreeLoaderIniForReactOS(DstPath, DestinationArcPath->Buffer); Status = CreateFreeLoaderIniForReactOS(DstPath, DestinationArcPath->Buffer);
@ -2709,10 +2693,9 @@ InstallFatBootcodeToFloppy(
} }
/* Install FAT12/16 boosector */ /* Install FAT12/16 boosector */
wcscpy(SrcPath, SourceRootPath->Buffer); CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat.bin");
wcscat(SrcPath, L"\\loader\\fat.bin");
wcscpy(DstPath, L"\\Device\\Floppy0"); RtlStringCchCopyW(DstPath, ARRAYSIZE(DstPath), L"\\Device\\Floppy0");
DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath, DstPath); DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath, DstPath);
Status = InstallFat12BootCodeToFloppy(SrcPath, DstPath); Status = InstallFat12BootCodeToFloppy(SrcPath, DstPath);

View file

@ -50,13 +50,13 @@ InstallDriver(
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hService; HANDLE hService;
INFCONTEXT Context; INFCONTEXT Context;
LPWSTR Driver, ClassGuid, ImagePath, FullImagePath; PWSTR Driver, ClassGuid, ImagePath, FullImagePath;
ULONG dwValue; ULONG dwValue;
ULONG Disposition; ULONG Disposition;
NTSTATUS Status; NTSTATUS Status;
BOOLEAN deviceInstalled = FALSE; BOOLEAN deviceInstalled = FALSE;
UNICODE_STRING UpperFiltersU = RTL_CONSTANT_STRING(L"UpperFilters"); UNICODE_STRING UpperFiltersU = RTL_CONSTANT_STRING(L"UpperFilters");
LPWSTR keyboardClass = L"kbdclass\0"; PWSTR keyboardClass = L"kbdclass\0";
/* Check if we know the hardware */ /* Check if we know the hardware */
if (!SetupFindFirstLineW(hInf, L"HardwareIdsDatabase", HardwareId, &Context)) if (!SetupFindFirstLineW(hInf, L"HardwareIdsDatabase", HardwareId, &Context))
@ -84,14 +84,14 @@ InstallDriver(
/* Prepare full driver path */ /* Prepare full driver path */
dwValue = PathPrefix.MaximumLength + wcslen(ImagePath) * sizeof(WCHAR); dwValue = PathPrefix.MaximumLength + wcslen(ImagePath) * sizeof(WCHAR);
FullImagePath = (LPWSTR)RtlAllocateHeap(ProcessHeap, 0, dwValue); FullImagePath = (PWSTR)RtlAllocateHeap(ProcessHeap, 0, dwValue);
if (!FullImagePath) if (!FullImagePath)
{ {
DPRINT1("RtlAllocateHeap() failed\n"); DPRINT1("RtlAllocateHeap() failed\n");
return FALSE; return FALSE;
} }
RtlCopyMemory(FullImagePath, PathPrefix.Buffer, PathPrefix.MaximumLength); RtlCopyMemory(FullImagePath, PathPrefix.Buffer, PathPrefix.MaximumLength);
wcscat(FullImagePath, ImagePath); ConcatPaths(FullImagePath, dwValue / sizeof(WCHAR), 1, ImagePath);
DPRINT1("Using driver '%S' for device '%S'\n", ImagePath, DeviceId); DPRINT1("Using driver '%S' for device '%S'\n", ImagePath, DeviceId);

View file

@ -368,46 +368,32 @@ SetupCommitFileQueueW(
while (Entry != NULL) while (Entry != NULL)
{ {
/* Build the full source path */ /* Build the full source path */
wcscpy(FileSrcPath, Entry->SourceRootPath); CombinePaths(FileSrcPath, ARRAYSIZE(FileSrcPath), 3,
if (Entry->SourcePath != NULL) Entry->SourceRootPath, Entry->SourcePath,
wcscat(FileSrcPath, Entry->SourcePath); Entry->SourceFilename);
wcscat(FileSrcPath, L"\\");
wcscat(FileSrcPath, Entry->SourceFilename);
/* Build the full target path */ /* Build the full target path */
wcscpy(FileDstPath, TargetRootPath); wcscpy(FileDstPath, TargetRootPath);
if (Entry->TargetDirectory[0] == 0) if (Entry->TargetDirectory[0] == UNICODE_NULL)
{ {
/* Installation path */ /* Installation path */
/* Add the installation path */ /* Add the installation path */
if (TargetPath != NULL) ConcatPaths(FileDstPath, ARRAYSIZE(FileDstPath), 1, TargetPath);
{
if (TargetPath[0] != L'\\')
wcscat(FileDstPath, L"\\");
wcscat(FileDstPath, TargetPath);
}
} }
else if (Entry->TargetDirectory[0] == L'\\') else if (Entry->TargetDirectory[0] == L'\\')
{ {
/* Absolute path */ /* Absolute path */
if (Entry->TargetDirectory[1] != 0) if (Entry->TargetDirectory[1] != UNICODE_NULL)
wcscat(FileDstPath, Entry->TargetDirectory); ConcatPaths(FileDstPath, ARRAYSIZE(FileDstPath), 1, Entry->TargetDirectory);
} }
else // if (Entry->TargetDirectory[0] != L'\\') else // if (Entry->TargetDirectory[0] != L'\\')
{ {
/* Path relative to the installation path */ /* Path relative to the installation path */
/* Add the installation path */ /* Add the installation path */
if (TargetPath != NULL) ConcatPaths(FileDstPath, ARRAYSIZE(FileDstPath), 2,
{ TargetPath, Entry->TargetDirectory);
if (TargetPath[0] != L'\\')
wcscat(FileDstPath, L"\\");
wcscat(FileDstPath, TargetPath);
}
wcscat(FileDstPath, L"\\");
wcscat(FileDstPath, Entry->TargetDirectory);
} }
/* /*
@ -416,11 +402,10 @@ SetupCommitFileQueueW(
*/ */
if (Entry->SourceCabinet == NULL) if (Entry->SourceCabinet == NULL)
{ {
wcscat(FileDstPath, L"\\");
if (Entry->TargetFilename != NULL) if (Entry->TargetFilename != NULL)
wcscat(FileDstPath, Entry->TargetFilename); ConcatPaths(FileDstPath, ARRAYSIZE(FileDstPath), 1, Entry->TargetFilename);
else else
wcscat(FileDstPath, Entry->SourceFilename); ConcatPaths(FileDstPath, ARRAYSIZE(FileDstPath), 1, Entry->SourceFilename);
} }
/* FIXME: Do it! */ /* FIXME: Do it! */
@ -434,11 +419,9 @@ SetupCommitFileQueueW(
if (Entry->SourceCabinet != NULL) if (Entry->SourceCabinet != NULL)
{ {
/* Extract the file */ /* Extract the file */
wcscpy(CabinetName, Entry->SourceRootPath); CombinePaths(CabinetName, ARRAYSIZE(CabinetName), 3,
if (Entry->SourcePath != NULL) Entry->SourceRootPath, Entry->SourcePath,
wcscat(CabinetName, Entry->SourcePath); Entry->SourceCabinet);
wcscat(CabinetName, L"\\");
wcscat(CabinetName, Entry->SourceCabinet);
Status = SetupExtractFile(CabinetName, Entry->SourceFilename, FileDstPath); Status = SetupExtractFile(CabinetName, Entry->SourceFilename, FileDstPath);
} }
else else

View file

@ -584,9 +584,8 @@ ImportRegistryFile(
UINT ErrorLine; UINT ErrorLine;
/* Load inf file from install media. */ /* Load inf file from install media. */
wcscpy(FileNameBuffer, SourcePath.Buffer); CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2,
wcscat(FileNameBuffer, L"\\"); SourcePath.Buffer, Filename);
wcscat(FileNameBuffer, Filename);
hInf = SetupOpenInfFileW(FileNameBuffer, hInf = SetupOpenInfFileW(FileNameBuffer,
NULL, NULL,

View file

@ -427,15 +427,14 @@ CheckUnattendedSetup(VOID)
INT IntValue; INT IntValue;
PWCHAR Value; PWCHAR Value;
if (DoesFileExist(NULL, SourcePath.Buffer, L"unattend.inf") == FALSE) CombinePaths(UnattendInfPath, ARRAYSIZE(UnattendInfPath), 2, SourcePath.Buffer, L"\\unattend.inf");
if (DoesFileExist(NULL, NULL, UnattendInfPath) == FALSE)
{ {
DPRINT("Does not exist: %S\\%S\n", SourcePath.Buffer, L"unattend.inf"); DPRINT("Does not exist: %S\n", UnattendInfPath);
return; return;
} }
wcscpy(UnattendInfPath, SourcePath.Buffer);
wcscat(UnattendInfPath, L"\\unattend.inf");
/* Load 'unattend.inf' from install media. */ /* Load 'unattend.inf' from install media. */
UnattendInf = SetupOpenInfFileW(UnattendInfPath, UnattendInf = SetupOpenInfFileW(UnattendInfPath,
NULL, NULL,
@ -527,7 +526,7 @@ CheckUnattendedSetup(VOID)
return; return;
} }
UnattendDestinationPartitionNumber = IntValue; UnattendDestinationPartitionNumber = (LONG)IntValue;
/* Search for 'InstallationDirectory' in the 'Unattend' section */ /* Search for 'InstallationDirectory' in the 'Unattend' section */
if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"InstallationDirectory", &Context)) if (!SetupFindFirstLineW(UnattendInf, L"Unattend", L"InstallationDirectory", &Context))
@ -824,9 +823,7 @@ SetupStartPage(PINPUT_RECORD Ir)
#endif #endif
/* Load txtsetup.sif from install media. */ /* Load txtsetup.sif from install media. */
wcscpy(FileNameBuffer, SourcePath.Buffer); CombinePaths(FileNameBuffer, ARRAYSIZE(FileNameBuffer), 2, SourcePath.Buffer, L"\\txtsetup.sif");
wcscat(FileNameBuffer, L"\\txtsetup.sif");
SetupInf = SetupOpenInfFileW(FileNameBuffer, SetupInf = SetupOpenInfFileW(FileNameBuffer,
NULL, NULL,
INF_STYLE_WIN4, INF_STYLE_WIN4,
@ -3203,12 +3200,8 @@ BuildInstallPaths(PWCHAR InstallDir,
/* Create 'DestinationPath' string */ /* Create 'DestinationPath' string */
RtlFreeUnicodeString(&DestinationPath); RtlFreeUnicodeString(&DestinationPath);
wcscpy(PathBuffer, DestinationRootPath.Buffer); CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
DestinationRootPath.Buffer, InstallDir);
if (InstallDir[0] != L'\\')
wcscat(PathBuffer, L"\\");
wcscat(PathBuffer, InstallDir);
RtlCreateUnicodeString(&DestinationPath, PathBuffer); RtlCreateUnicodeString(&DestinationPath, PathBuffer);
/* Create 'DestinationArcPath' */ /* Create 'DestinationArcPath' */
@ -3217,11 +3210,7 @@ BuildInstallPaths(PWCHAR InstallDir,
L"multi(0)disk(0)rdisk(%lu)partition(%lu)", L"multi(0)disk(0)rdisk(%lu)partition(%lu)",
DiskEntry->BiosDiskNumber, DiskEntry->BiosDiskNumber,
PartEntry->PartitionNumber); PartEntry->PartitionNumber);
ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallDir);
if (InstallDir[0] != L'\\')
wcscat(PathBuffer, L"\\");
wcscat(PathBuffer, InstallDir);
RtlCreateUnicodeString(&DestinationArcPath, PathBuffer); RtlCreateUnicodeString(&DestinationArcPath, PathBuffer);
} }
@ -3558,7 +3547,7 @@ AddSectionToCopyQueue(HINF InfFile,
break; break;
} }
if ((DirKeyValue[0] == 0) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == 0)) if ((DirKeyValue[0] == UNICODE_NULL) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == UNICODE_NULL))
{ {
/* Installation path */ /* Installation path */
wcscpy(CompleteOrigDirName, SourceRootDir.Buffer); wcscpy(CompleteOrigDirName, SourceRootDir.Buffer);
@ -3571,16 +3560,15 @@ AddSectionToCopyQueue(HINF InfFile,
else // if (DirKeyValue[0] != L'\\') else // if (DirKeyValue[0] != L'\\')
{ {
/* Path relative to the installation path */ /* Path relative to the installation path */
wcscpy(CompleteOrigDirName, SourceRootDir.Buffer); CombinePaths(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), 2,
wcscat(CompleteOrigDirName, L"\\"); SourceRootDir.Buffer, DirKeyValue);
wcscat(CompleteOrigDirName, DirKeyValue);
} }
/* Remove trailing backslash */ /* Remove trailing backslash */
Length = wcslen(CompleteOrigDirName); Length = wcslen(CompleteOrigDirName);
if ((Length > 0) && (CompleteOrigDirName[Length - 1] == L'\\')) if ((Length > 0) && (CompleteOrigDirName[Length - 1] == L'\\'))
{ {
CompleteOrigDirName[Length - 1] = 0; CompleteOrigDirName[Length - 1] = UNICODE_NULL;
} }
if (!SetupQueueCopy(SetupFileQueue, if (!SetupQueueCopy(SetupFileQueue,
@ -3647,7 +3635,7 @@ PrepareCopyPageInfFile(HINF InfFile,
Length = wcslen(PathBuffer); Length = wcslen(PathBuffer);
if ((Length > 0) && (PathBuffer[Length - 1] == L'\\')) if ((Length > 0) && (PathBuffer[Length - 1] == L'\\'))
{ {
PathBuffer[Length - 1] = 0; PathBuffer[Length - 1] = UNICODE_NULL;
} }
/* Create the install directory */ /* Create the install directory */
@ -3683,7 +3671,7 @@ PrepareCopyPageInfFile(HINF InfFile,
break; break;
} }
if ((DirKeyValue[0] == 0) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == 0)) if ((DirKeyValue[0] == UNICODE_NULL) || (DirKeyValue[0] == L'\\' && DirKeyValue[1] == UNICODE_NULL))
{ {
/* Installation path */ /* Installation path */
DPRINT("InstallationPath: '%S'\n", DirKeyValue); DPRINT("InstallationPath: '%S'\n", DirKeyValue);
@ -3697,14 +3685,14 @@ PrepareCopyPageInfFile(HINF InfFile,
/* Absolute path */ /* Absolute path */
DPRINT("Absolute Path: '%S'\n", DirKeyValue); DPRINT("Absolute Path: '%S'\n", DirKeyValue);
wcscpy(PathBuffer, DestinationRootPath.Buffer); CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
wcscat(PathBuffer, DirKeyValue); DestinationRootPath.Buffer, DirKeyValue);
/* Remove trailing backslash */ /* Remove trailing backslash */
Length = wcslen(PathBuffer); Length = wcslen(PathBuffer);
if ((Length > 0) && (PathBuffer[Length - 1] == L'\\')) if ((Length > 0) && (PathBuffer[Length - 1] == L'\\'))
{ {
PathBuffer[Length - 1] = 0; PathBuffer[Length - 1] = UNICODE_NULL;
} }
DPRINT("FullPath: '%S'\n", PathBuffer); DPRINT("FullPath: '%S'\n", PathBuffer);
@ -3722,15 +3710,14 @@ PrepareCopyPageInfFile(HINF InfFile,
/* Path relative to the installation path */ /* Path relative to the installation path */
DPRINT("RelativePath: '%S'\n", DirKeyValue); DPRINT("RelativePath: '%S'\n", DirKeyValue);
wcscpy(PathBuffer, DestinationPath.Buffer); CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
wcscat(PathBuffer, L"\\"); DestinationPath.Buffer, DirKeyValue);
wcscat(PathBuffer, DirKeyValue);
/* Remove trailing backslash */ /* Remove trailing backslash */
Length = wcslen(PathBuffer); Length = wcslen(PathBuffer);
if ((Length > 0) && (PathBuffer[Length - 1] == L'\\')) if ((Length > 0) && (PathBuffer[Length - 1] == L'\\'))
{ {
PathBuffer[Length - 1] = 0; PathBuffer[Length - 1] = UNICODE_NULL;
} }
DPRINT("FullPath: '%S'\n", PathBuffer); DPRINT("FullPath: '%S'\n", PathBuffer);
@ -3805,9 +3792,8 @@ PrepareCopyPage(PINPUT_RECORD Ir)
if (!INF_GetData(&CabinetsContext, NULL, &KeyValue)) if (!INF_GetData(&CabinetsContext, NULL, &KeyValue))
break; break;
wcscpy(PathBuffer, SourcePath.Buffer); CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2,
wcscat(PathBuffer, L"\\"); SourcePath.Buffer, KeyValue);
wcscat(PathBuffer, KeyValue);
CabinetInitialize(); CabinetInitialize();
CabinetSetEventHandlers(NULL, NULL, NULL); CabinetSetEventHandlers(NULL, NULL, NULL);
@ -4387,7 +4373,7 @@ BootLoaderFloppyPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */ else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
{ {
if (DoesFileExist(NULL, L"\\Device\\Floppy0", L"\\") == FALSE) if (DoesPathExist(NULL, L"\\Device\\Floppy0\\") == FALSE)
{ {
MUIDisplayError(ERROR_NO_FLOPPY, Ir, POPUP_WAIT_ENTER); MUIDisplayError(ERROR_NO_FLOPPY, Ir, POPUP_WAIT_ENTER);
return BOOT_LOADER_FLOPPY_PAGE; return BOOT_LOADER_FLOPPY_PAGE;
@ -4484,14 +4470,12 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
L"\\Device\\Harddisk%d\\Partition0", L"\\Device\\Harddisk%d\\Partition0",
PartitionList->SystemPartition->DiskEntry->DiskNumber); PartitionList->SystemPartition->DiskEntry->DiskNumber);
wcscpy(SourceMbrPathBuffer, SourceRootPath.Buffer); CombinePaths(SourceMbrPathBuffer, ARRAYSIZE(SourceMbrPathBuffer), 2, SourceRootPath.Buffer, L"\\loader\\dosmbr.bin");
wcscat(SourceMbrPathBuffer, L"\\loader\\dosmbr.bin");
if (IsThereAValidBootSector(DestinationDevicePathBuffer)) if (IsThereAValidBootSector(DestinationDevicePathBuffer))
{ {
/* Save current MBR */ /* Save current MBR */
wcscpy(DstPath, SystemRootPath.Buffer); CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath.Buffer, L"\\mbr.old");
wcscat(DstPath, L"\\mbr.old");
DPRINT1("Save MBR: %S ==> %S\n", DestinationDevicePathBuffer, DstPath); DPRINT1("Save MBR: %S ==> %S\n", DestinationDevicePathBuffer, DstPath);
Status = SaveBootSector(DestinationDevicePathBuffer, DstPath, sizeof(PARTITION_SECTOR)); Status = SaveBootSector(DestinationDevicePathBuffer, DstPath, sizeof(PARTITION_SECTOR));