mirror of
https://github.com/reactos/reactos.git
synced 2024-12-02 16:03:29 +08:00
[SETUPLIB][USETUP] Move the remaining (directory-creation) functions from usetup's filesup to setuplib.
They will be used later in the library.
This commit is contained in:
parent
c34fc6329f
commit
9c64b57dc9
@ -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 *****************************************************************/
|
||||
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -16,7 +16,6 @@ list(APPEND SOURCE
|
||||
console.c
|
||||
consup.c
|
||||
devinst.c
|
||||
filesup.c
|
||||
filequeue.c
|
||||
format.c
|
||||
fslist.c
|
||||
|
@ -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 */
|
@ -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 */
|
@ -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.
|
||||
*
|
||||
|
@ -65,7 +65,6 @@
|
||||
#include "fslist.h"
|
||||
#include "partlist.h"
|
||||
#include "cabinet.h"
|
||||
#include "filesup.h"
|
||||
#include "genlist.h"
|
||||
#include "mui.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user