[SETUPLIB][USETUP] Move the remaining (directory-creation) functions from usetup...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 5 Jan 2018 00:56:23 +0000 (01:56 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 28 Oct 2018 17:17:34 +0000 (18:17 +0100)
They will be used later in the library.

base/setup/lib/utils/filesup.c
base/setup/lib/utils/filesup.h
base/setup/usetup/CMakeLists.txt
base/setup/usetup/filesup.c [deleted file]
base/setup/usetup/filesup.h [deleted file]
base/setup/usetup/usetup.c
base/setup/usetup/usetup.h

index 7755ad3..5b16799 100644 (file)
@@ -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@users.sourceforge.net)
+ *              Copyright 2017-2018 Hermes Belusca-Maito
  */
 
 /* INCLUDES *****************************************************************/
 
 /* 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,
index ae0a30c..44a2f18 100644 (file)
@@ -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@users.sourceforge.net)
+ *              Copyright 2017-2018 Hermes Belusca-Maito
  */
 
 #pragma once
 
+NTSTATUS
+SetupCreateDirectory(
+    IN PCWSTR DirectoryName);
+
 NTSTATUS
 SetupDeleteFile(
     IN PCWSTR FileName,
index 0d83835..19314bf 100644 (file)
@@ -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 (file)
index b648471..0000000
+++ /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@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 (file)
index a441ea4..0000000
+++ /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@users.sourceforge.net)
- */
-
-#pragma once
-
-NTSTATUS
-SetupCreateDirectory(
-    PWCHAR DirectoryName);
-
-BOOLEAN
-IsValidPath(
-    IN PCWSTR InstallDir);
-
-/* EOF */
index 46cb244..1461528 100644 (file)
@@ -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.
  *
index f9ff6f4..39a5c6a 100644 (file)
@@ -65,7 +65,6 @@
 #include "fslist.h"
 #include "partlist.h"
 #include "cabinet.h"
-#include "filesup.h"
 #include "genlist.h"
 #include "mui.h"