Author: ekohl Date: Tue Jul 15 21:34:12 2014 New Revision: 63715
URL: http://svn.reactos.org/svn/reactos?rev=63715&view=rev Log: [USETUP] Reimplement SetupCreateDirectory in such a way, that a full directory path will be created, if needed. This enables us to install ReactOS in a sub-directory like for example '\OS\Test\Alpha\ReactOS'.
Modified: trunk/reactos/base/setup/usetup/filesup.c
Modified: trunk/reactos/base/setup/usetup/filesup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/filesup.c... ============================================================================== --- trunk/reactos/base/setup/usetup/filesup.c [iso-8859-1] (original) +++ trunk/reactos/base/setup/usetup/filesup.c [iso-8859-1] Tue Jul 15 21:34:12 2014 @@ -37,8 +37,9 @@ static WCHAR CurrentCabinetName[MAX_PATH]; static CAB_SEARCH Search;
+static NTSTATUS -SetupCreateDirectory( +SetupCreateSingleDirectory( PWCHAR DirectoryName) { OBJECT_ATTRIBUTES ObjectAttributes; @@ -87,6 +88,111 @@ }
RtlFreeUnicodeString(&PathName); + + return Status; +} + + +static +BOOLEAN +DoesPathExist( + PWSTR PathName) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING Name; + HANDLE FileHandle; + NTSTATUS Status; + + RtlInitUnicodeString(&Name, + PathName); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + GENERIC_READ | SYNCHRONIZE, + &ObjectAttributes, + &IoStatusBlock, + 0, + FILE_SYNCHRONOUS_IO_NONALERT); + if (!NT_SUCCESS(Status)) + { + return FALSE; + } + + NtClose(FileHandle); + + return TRUE; +} + + +NTSTATUS +SetupCreateDirectory( + PWCHAR PathName) +{ + PWCHAR PathBuffer = NULL; + PWCHAR Ptr, EndPtr; + ULONG BackslashCount; + ULONG Size; + NTSTATUS Status = STATUS_SUCCESS; + + Size = (wcslen(PathName) + 1) * sizeof(WCHAR); + PathBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Size); + if (PathBuffer == NULL) + return STATUS_INSUFFICIENT_RESOURCES; + + wcscpy(PathBuffer, PathName); + EndPtr = PathBuffer + wcslen(PathName); + + Ptr = PathBuffer; + + /* Skip the '\Device\HarddiskX\PartitionY\ part */ + BackslashCount = 0; + while (Ptr < EndPtr && BackslashCount < 4) + { + if (*Ptr == L'\') + BackslashCount++; + + Ptr++; + } + + while (Ptr < EndPtr) + { + if (*Ptr == L'\') + { + *Ptr = 0; + + DPRINT("PathBuffer: %S\n", PathBuffer); + if (!DoesPathExist(PathBuffer)) + { + DPRINT("Create: %S\n", PathBuffer); + Status = SetupCreateSingleDirectory(PathBuffer); + if (!NT_SUCCESS(Status)) + goto done; + } + + *Ptr = L'\'; + } + + Ptr++; + } + + if (!DoesPathExist(PathBuffer)) + { + DPRINT("Create: %S\n", PathBuffer); + Status = SetupCreateSingleDirectory(PathBuffer); + if (!NT_SUCCESS(Status)) + goto done; + } + +done: + DPRINT("Done.\n"); + if (PathBuffer != NULL) + RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
return Status; }