https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9c64b57dc9bc55cdf73db…
commit 9c64b57dc9bc55cdf73db0ea2ff1ac202d7c608c
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Fri Jan 5 01:56:23 2018 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Oct 28 18:17:34 2018 +0100
[SETUPLIB][USETUP] Move the remaining (directory-creation) functions from usetup's
filesup to setuplib.
They will be used later in the library.
---
base/setup/lib/utils/filesup.c | 130 ++++++++++++++++++++++++++-
base/setup/lib/utils/filesup.h | 7 +-
base/setup/usetup/CMakeLists.txt | 1 -
base/setup/usetup/filesup.c | 186 ---------------------------------------
base/setup/usetup/filesup.h | 19 ----
base/setup/usetup/usetup.c | 46 ++++++++++
base/setup/usetup/usetup.h | 1 -
7 files changed, 178 insertions(+), 212 deletions(-)
diff --git a/base/setup/lib/utils/filesup.c b/base/setup/lib/utils/filesup.c
index 7755ad38fc..5b16799a6a 100644
--- a/base/setup/lib/utils/filesup.c
+++ b/base/setup/lib/utils/filesup.c
@@ -2,7 +2,8 @@
* PROJECT: ReactOS Setup Library
* LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: File support functions.
- * COPYRIGHT: Copyright 2017-2018 Hermes Belusca-Maito
+ * COPYRIGHT: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
+ * Copyright 2017-2018 Hermes Belusca-Maito
*/
/* INCLUDES *****************************************************************/
@@ -23,7 +24,128 @@
/* FUNCTIONS ****************************************************************/
-// TODO: Move SetupCreateDirectory later...
+static
+NTSTATUS
+SetupCreateSingleDirectory(
+ IN PCWSTR DirectoryName)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ UNICODE_STRING PathName;
+ HANDLE DirectoryHandle;
+ NTSTATUS Status;
+
+ if (!RtlCreateUnicodeString(&PathName, DirectoryName))
+ return STATUS_NO_MEMORY;
+
+ if (PathName.Length > sizeof(WCHAR) &&
+ PathName.Buffer[PathName.Length / sizeof(WCHAR) - 2] == L'\\' &&
+ PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'.')
+ {
+ PathName.Length -= sizeof(WCHAR);
+ PathName.Buffer[PathName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+ }
+
+ if (PathName.Length > sizeof(WCHAR) &&
+ PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'\\')
+ {
+ PathName.Length -= sizeof(WCHAR);
+ PathName.Buffer[PathName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+ }
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &PathName,
+ OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
+ NULL,
+ NULL);
+
+ Status = NtCreateFile(&DirectoryHandle,
+ FILE_LIST_DIRECTORY | SYNCHRONIZE,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ NULL,
+ FILE_ATTRIBUTE_DIRECTORY,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ FILE_OPEN_IF,
+ FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE,
+ NULL,
+ 0);
+ if (NT_SUCCESS(Status))
+ {
+ NtClose(DirectoryHandle);
+ }
+
+ RtlFreeUnicodeString(&PathName);
+
+ return Status;
+}
+
+NTSTATUS
+SetupCreateDirectory(
+ IN PCWSTR PathName)
+{
+ NTSTATUS Status = STATUS_SUCCESS;
+ PWCHAR PathBuffer = NULL;
+ PWCHAR Ptr, EndPtr;
+ ULONG BackslashCount;
+ ULONG Size;
+
+ 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 (!DoesDirExist(NULL, PathBuffer))
+ {
+ DPRINT("Create: %S\n", PathBuffer);
+ Status = SetupCreateSingleDirectory(PathBuffer);
+ if (!NT_SUCCESS(Status))
+ goto done;
+ }
+
+ *Ptr = L'\\';
+ }
+
+ Ptr++;
+ }
+
+ if (!DoesDirExist(NULL, 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;
+}
NTSTATUS
SetupDeleteFile(
@@ -184,8 +306,8 @@ SetupCopyFile(
FileHandleSource);
if (!NT_SUCCESS(Status))
{
- DPRINT1("NtCreateSection failed: %x, %S\n", Status, SourceFileName);
- goto closesrc;
+ DPRINT1("NtCreateSection failed: %x, %S\n", Status, SourceFileName);
+ goto closesrc;
}
Status = NtMapViewOfSection(SourceFileSection,
diff --git a/base/setup/lib/utils/filesup.h b/base/setup/lib/utils/filesup.h
index ae0a30c241..44a2f1810a 100644
--- a/base/setup/lib/utils/filesup.h
+++ b/base/setup/lib/utils/filesup.h
@@ -2,11 +2,16 @@
* PROJECT: ReactOS Setup Library
* LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: File support functions.
- * COPYRIGHT: Copyright 2017-2018 Hermes Belusca-Maito
+ * COPYRIGHT: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
+ * Copyright 2017-2018 Hermes Belusca-Maito
*/
#pragma once
+NTSTATUS
+SetupCreateDirectory(
+ IN PCWSTR DirectoryName);
+
NTSTATUS
SetupDeleteFile(
IN PCWSTR FileName,
diff --git a/base/setup/usetup/CMakeLists.txt b/base/setup/usetup/CMakeLists.txt
index 0d83835a36..19314bfe7a 100644
--- a/base/setup/usetup/CMakeLists.txt
+++ b/base/setup/usetup/CMakeLists.txt
@@ -16,7 +16,6 @@ list(APPEND SOURCE
console.c
consup.c
devinst.c
- filesup.c
filequeue.c
format.c
fslist.c
diff --git a/base/setup/usetup/filesup.c b/base/setup/usetup/filesup.c
deleted file mode 100644
index b648471084..0000000000
--- a/base/setup/usetup/filesup.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS text-mode setup
- * FILE: base/setup/usetup/filesup.c
- * PURPOSE: File support functions
- * PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
- */
-
-/* INCLUDES *****************************************************************/
-
-#include "usetup.h"
-
-#define NDEBUG
-#include <debug.h>
-
-/* FUNCTIONS ****************************************************************/
-
-static
-NTSTATUS
-SetupCreateSingleDirectory(
- PWCHAR DirectoryName)
-{
- OBJECT_ATTRIBUTES ObjectAttributes;
- IO_STATUS_BLOCK IoStatusBlock;
- UNICODE_STRING PathName;
- HANDLE DirectoryHandle;
- NTSTATUS Status;
-
- if (!RtlCreateUnicodeString(&PathName, DirectoryName))
- return STATUS_NO_MEMORY;
-
- if (PathName.Length > sizeof(WCHAR) &&
- PathName.Buffer[PathName.Length / sizeof(WCHAR) - 2] == L'\\' &&
- PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'.')
- {
- PathName.Length -= sizeof(WCHAR);
- PathName.Buffer[PathName.Length / sizeof(WCHAR)] = 0;
- }
-
- if (PathName.Length > sizeof(WCHAR) &&
- PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'\\')
- {
- PathName.Length -= sizeof(WCHAR);
- PathName.Buffer[PathName.Length / sizeof(WCHAR)] = 0;
- }
-
- InitializeObjectAttributes(&ObjectAttributes,
- &PathName,
- OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
- NULL,
- NULL);
-
- Status = NtCreateFile(&DirectoryHandle,
- FILE_LIST_DIRECTORY | SYNCHRONIZE,
- &ObjectAttributes,
- &IoStatusBlock,
- NULL,
- FILE_ATTRIBUTE_DIRECTORY,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- FILE_OPEN_IF,
- FILE_OPEN_FOR_BACKUP_INTENT | FILE_DIRECTORY_FILE,
- NULL,
- 0);
- if (NT_SUCCESS(Status))
- {
- NtClose(DirectoryHandle);
- }
-
- RtlFreeUnicodeString(&PathName);
-
- return Status;
-}
-
-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 (!DoesDirExist(NULL, PathBuffer))
- {
- DPRINT("Create: %S\n", PathBuffer);
- Status = SetupCreateSingleDirectory(PathBuffer);
- if (!NT_SUCCESS(Status))
- goto done;
- }
-
- *Ptr = L'\\';
- }
-
- Ptr++;
- }
-
- if (!DoesDirExist(NULL, 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;
-}
-
-BOOLEAN
-IsValidPath(
- IN PCWSTR InstallDir)
-{
- UINT i, Length;
-
- Length = wcslen(InstallDir);
-
- // TODO: Add check for 8.3 too.
-
- /* Path must be at least 2 characters long */
-// if (Length < 2)
-// return FALSE;
-
- /* Path must start with a backslash */
-// if (InstallDir[0] != L'\\')
-// return FALSE;
-
- /* Path must not end with a backslash */
- if (InstallDir[Length - 1] == L'\\')
- return FALSE;
-
- /* Path must not contain whitespace characters */
- for (i = 0; i < Length; i++)
- {
- if (iswspace(InstallDir[i]))
- return FALSE;
- }
-
- /* Path component must not end with a dot */
- for (i = 0; i < Length; i++)
- {
- if (InstallDir[i] == L'\\' && i > 0)
- {
- if (InstallDir[i - 1] == L'.')
- return FALSE;
- }
- }
-
- if (InstallDir[Length - 1] == L'.')
- return FALSE;
-
- return TRUE;
-}
-
-/* EOF */
diff --git a/base/setup/usetup/filesup.h b/base/setup/usetup/filesup.h
deleted file mode 100644
index a441ea4451..0000000000
--- a/base/setup/usetup/filesup.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS text-mode setup
- * FILE: base/setup/usetup/filesup.h
- * PURPOSE: File support functions
- * PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
- */
-
-#pragma once
-
-NTSTATUS
-SetupCreateDirectory(
- PWCHAR DirectoryName);
-
-BOOLEAN
-IsValidPath(
- IN PCWSTR InstallDir);
-
-/* EOF */
diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c
index 46cb244565..1461528b88 100644
--- a/base/setup/usetup/usetup.c
+++ b/base/setup/usetup/usetup.c
@@ -3262,6 +3262,52 @@ BuildInstallPaths(PWSTR InstallDir,
}
+static BOOLEAN
+IsValidPath(
+ IN PCWSTR InstallDir)
+{
+ UINT i, Length;
+
+ Length = wcslen(InstallDir);
+
+ // TODO: Add check for 8.3 too.
+
+ /* Path must be at least 2 characters long */
+// if (Length < 2)
+// return FALSE;
+
+ /* Path must start with a backslash */
+// if (InstallDir[0] != L'\\')
+// return FALSE;
+
+ /* Path must not end with a backslash */
+ if (InstallDir[Length - 1] == L'\\')
+ return FALSE;
+
+ /* Path must not contain whitespace characters */
+ for (i = 0; i < Length; i++)
+ {
+ if (iswspace(InstallDir[i]))
+ return FALSE;
+ }
+
+ /* Path component must not end with a dot */
+ for (i = 0; i < Length; i++)
+ {
+ if (InstallDir[i] == L'\\' && i > 0)
+ {
+ if (InstallDir[i - 1] == L'.')
+ return FALSE;
+ }
+ }
+
+ if (InstallDir[Length - 1] == L'.')
+ return FALSE;
+
+ return TRUE;
+}
+
+
/*
* Displays the InstallDirectoryPage.
*
diff --git a/base/setup/usetup/usetup.h b/base/setup/usetup/usetup.h
index f9ff6f4f16..39a5c6a168 100644
--- a/base/setup/usetup/usetup.h
+++ b/base/setup/usetup/usetup.h
@@ -65,7 +65,6 @@
#include "fslist.h"
#include "partlist.h"
#include "cabinet.h"
-#include "filesup.h"
#include "genlist.h"
#include "mui.h"