2002-11-13 18:25:18 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2002 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2002-11-13 18:25:18 +00:00
|
|
|
*/
|
2006-11-10 21:00:24 +00:00
|
|
|
/* COPYRIGHT: See COPYING in the top level directory
|
2002-11-13 18:25:18 +00:00
|
|
|
* PROJECT: ReactOS text-mode setup
|
|
|
|
* FILE: subsys/system/usetup/filesup.c
|
|
|
|
* PURPOSE: File support functions
|
|
|
|
* PROGRAMMER: Eric Kohl
|
2003-08-24 10:36:07 +00:00
|
|
|
* Casper S. Hornstrup (chorns@users.sourceforge.net)
|
2002-11-13 18:25:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2006-08-31 09:13:03 +00:00
|
|
|
#include "usetup.h"
|
2002-11-13 18:25:18 +00:00
|
|
|
|
2010-06-07 21:38:49 +00:00
|
|
|
#define NDEBUG
|
2003-12-01 18:28:54 +00:00
|
|
|
#include <debug.h>
|
2002-11-13 18:25:18 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2003-08-24 10:36:07 +00:00
|
|
|
static BOOLEAN HasCurrentCabinet = FALSE;
|
|
|
|
static WCHAR CurrentCabinetName[MAX_PATH];
|
2011-12-09 14:51:57 +00:00
|
|
|
static CAB_SEARCH Search;
|
2003-08-24 10:36:07 +00:00
|
|
|
|
2014-07-15 21:34:12 +00:00
|
|
|
static
|
2002-11-13 18:25:18 +00:00
|
|
|
NTSTATUS
|
2014-07-15 21:34:12 +00:00
|
|
|
SetupCreateSingleDirectory(
|
2014-05-12 14:17:37 +00:00
|
|
|
PWCHAR DirectoryName)
|
2002-11-13 18:25:18 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
UNICODE_STRING PathName;
|
|
|
|
HANDLE DirectoryHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
RtlCreateUnicodeString(&PathName,
|
|
|
|
DirectoryName);
|
|
|
|
if (PathName.Length > sizeof(WCHAR) &&
|
|
|
|
PathName.Buffer[PathName.Length / sizeof(WCHAR) - 2] == L'\\' &&
|
|
|
|
PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'.')
|
2004-01-18 22:34:40 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
PathName.Length -= sizeof(WCHAR);
|
|
|
|
PathName.Buffer[PathName.Length / sizeof(WCHAR)] = 0;
|
2004-01-18 22:34:40 +00:00
|
|
|
}
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
if (PathName.Length > sizeof(WCHAR) &&
|
|
|
|
PathName.Buffer[PathName.Length / sizeof(WCHAR) - 1] == L'\\')
|
2004-01-18 22:34:40 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
PathName.Length -= sizeof(WCHAR);
|
|
|
|
PathName.Buffer[PathName.Length / sizeof(WCHAR)] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&PathName,
|
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateFile(&DirectoryHandle,
|
|
|
|
DIRECTORY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
|
|
|
NULL,
|
|
|
|
FILE_ATTRIBUTE_DIRECTORY,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_OPEN_IF,
|
|
|
|
FILE_DIRECTORY_FILE,
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
if (NT_SUCCESS(Status))
|
2002-11-13 18:25:18 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
NtClose(DirectoryHandle);
|
2002-11-13 18:25:18 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
RtlFreeUnicodeString(&PathName);
|
2002-11-13 18:25:18 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
return Status;
|
2002-11-13 18:25:18 +00:00
|
|
|
}
|
|
|
|
|
2002-11-23 01:55:27 +00:00
|
|
|
|
2014-07-15 21:34:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-23 01:55:27 +00:00
|
|
|
NTSTATUS
|
2014-05-12 14:17:37 +00:00
|
|
|
SetupCopyFile(
|
|
|
|
PWCHAR SourceFileName,
|
|
|
|
PWCHAR DestinationFileName)
|
2002-11-23 01:55:27 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE FileHandleSource;
|
|
|
|
HANDLE FileHandleDest;
|
|
|
|
static IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
FILE_STANDARD_INFORMATION FileStandard;
|
|
|
|
FILE_BASIC_INFORMATION FileBasic;
|
|
|
|
ULONG RegionSize;
|
|
|
|
UNICODE_STRING FileName;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PVOID SourceFileMap = 0;
|
|
|
|
HANDLE SourceFileSection;
|
|
|
|
SIZE_T SourceSectionSize = 0;
|
|
|
|
LARGE_INTEGER ByteOffset;
|
2002-11-23 01:55:27 +00:00
|
|
|
|
2006-11-10 21:00:24 +00:00
|
|
|
#ifdef __REACTOS__
|
2014-05-12 14:17:37 +00:00
|
|
|
RtlInitUnicodeString(&FileName,
|
|
|
|
SourceFileName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&FileName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtOpenFile(&FileHandleSource,
|
|
|
|
GENERIC_READ,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
FILE_SEQUENTIAL_ONLY);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-02-08 00:19:32 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtOpenFile failed: %x, %wZ\n", Status, &FileName);
|
|
|
|
goto done;
|
2003-02-08 00:19:32 +00:00
|
|
|
}
|
2006-11-10 21:00:24 +00:00
|
|
|
#else
|
2014-05-12 14:17:37 +00:00
|
|
|
FileHandleSource = CreateFileW(SourceFileName,
|
|
|
|
GENERIC_READ,
|
|
|
|
FILE_SHARE_READ,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (FileHandleSource == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
goto done;
|
|
|
|
}
|
2006-11-10 21:00:24 +00:00
|
|
|
#endif
|
2002-11-23 01:55:27 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
Status = NtQueryInformationFile(FileHandleSource,
|
|
|
|
&IoStatusBlock,
|
|
|
|
&FileStandard,
|
|
|
|
sizeof(FILE_STANDARD_INFORMATION),
|
|
|
|
FileStandardInformation);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-02-08 00:19:32 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtQueryInformationFile failed: %x\n", Status);
|
|
|
|
goto closesrc;
|
2003-02-08 00:19:32 +00:00
|
|
|
}
|
2014-05-12 14:17:37 +00:00
|
|
|
|
|
|
|
Status = NtQueryInformationFile(FileHandleSource,
|
|
|
|
&IoStatusBlock,&FileBasic,
|
|
|
|
sizeof(FILE_BASIC_INFORMATION),
|
|
|
|
FileBasicInformation);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-05-19 00:59:40 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtQueryInformationFile failed: %x\n", Status);
|
|
|
|
goto closesrc;
|
2005-05-19 00:59:40 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
Status = NtCreateSection(&SourceFileSection,
|
|
|
|
SECTION_MAP_READ,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
PAGE_READONLY,
|
|
|
|
SEC_COMMIT,
|
|
|
|
FileHandleSource);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-05-19 00:59:40 +00:00
|
|
|
{
|
2013-11-13 16:45:22 +00:00
|
|
|
DPRINT1("NtCreateSection failed: %x, %S\n", Status, SourceFileName);
|
2005-05-19 00:59:40 +00:00
|
|
|
goto closesrc;
|
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
Status = NtMapViewOfSection(SourceFileSection,
|
|
|
|
NtCurrentProcess(),
|
|
|
|
&SourceFileMap,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&SourceSectionSize,
|
|
|
|
ViewUnmap,
|
|
|
|
0,
|
|
|
|
PAGE_READONLY );
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-02-08 00:19:32 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtMapViewOfSection failed: %x, %S\n", Status, SourceFileName);
|
|
|
|
goto closesrcsec;
|
2003-02-08 00:19:32 +00:00
|
|
|
}
|
2002-11-23 01:55:27 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
RtlInitUnicodeString(&FileName,
|
|
|
|
DestinationFileName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&FileName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateFile(&FileHandleDest,
|
|
|
|
GENERIC_WRITE | SYNCHRONIZE,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&IoStatusBlock,
|
|
|
|
NULL,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
0,
|
|
|
|
FILE_OVERWRITE_IF,
|
|
|
|
FILE_NO_INTERMEDIATE_BUFFERING |
|
|
|
|
FILE_SEQUENTIAL_ONLY |
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT,
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-02-08 00:19:32 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtCreateFile failed: %x\n", Status);
|
|
|
|
goto unmapsrcsec;
|
2003-02-08 00:19:32 +00:00
|
|
|
}
|
2002-11-23 01:55:27 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
RegionSize = (ULONG)PAGE_ROUND_UP(FileStandard.EndOfFile.u.LowPart);
|
|
|
|
IoStatusBlock.Status = 0;
|
|
|
|
ByteOffset.QuadPart = 0;
|
|
|
|
Status = NtWriteFile(FileHandleDest,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&IoStatusBlock,
|
|
|
|
SourceFileMap,
|
|
|
|
RegionSize,
|
|
|
|
&ByteOffset,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-02-08 00:19:32 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtWriteFile failed: %x:%x, iosb: %p src: %p, size: %x\n", Status, IoStatusBlock.Status, &IoStatusBlock, SourceFileMap, RegionSize);
|
|
|
|
goto closedest;
|
2003-02-08 00:19:32 +00:00
|
|
|
}
|
2014-05-12 14:17:37 +00:00
|
|
|
|
|
|
|
/* Copy file date/time from source file */
|
|
|
|
Status = NtSetInformationFile(FileHandleDest,
|
|
|
|
&IoStatusBlock,
|
|
|
|
&FileBasic,
|
|
|
|
sizeof(FILE_BASIC_INFORMATION),
|
|
|
|
FileBasicInformation);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-02-08 00:19:32 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtSetInformationFile failed: %x\n", Status);
|
|
|
|
goto closedest;
|
2003-02-08 00:19:32 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
/* shorten the file back to it's real size after completing the write */
|
|
|
|
Status = NtSetInformationFile(FileHandleDest,
|
|
|
|
&IoStatusBlock,
|
|
|
|
&FileStandard.EndOfFile,
|
|
|
|
sizeof(FILE_END_OF_FILE_INFORMATION),
|
|
|
|
FileEndOfFileInformation);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2007-10-16 14:59:09 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT1("NtSetInformationFile failed: %x\n", Status);
|
2007-10-16 14:59:09 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
closedest:
|
|
|
|
NtClose(FileHandleDest);
|
|
|
|
|
|
|
|
unmapsrcsec:
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), SourceFileMap);
|
|
|
|
|
|
|
|
closesrcsec:
|
|
|
|
NtClose(SourceFileSection);
|
|
|
|
|
|
|
|
closesrc:
|
|
|
|
NtClose(FileHandleSource);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return Status;
|
2002-11-23 01:55:27 +00:00
|
|
|
}
|
|
|
|
|
2006-11-10 21:00:24 +00:00
|
|
|
#ifdef __REACTOS__
|
2003-08-24 10:36:07 +00:00
|
|
|
NTSTATUS
|
2014-05-12 14:17:37 +00:00
|
|
|
SetupExtractFile(
|
|
|
|
PWCHAR CabinetFileName,
|
|
|
|
PWCHAR SourceFileName,
|
|
|
|
PWCHAR DestinationPathName)
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
ULONG CabStatus;
|
2003-08-24 10:36:07 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT("SetupExtractFile(CabinetFileName %S, SourceFileName %S, DestinationPathName %S)\n",
|
|
|
|
CabinetFileName, SourceFileName, DestinationPathName);
|
2003-08-24 10:36:07 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
if (HasCurrentCabinet)
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT("CurrentCabinetName: %S\n", CurrentCabinetName);
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
if ((HasCurrentCabinet) && (wcscmp(CabinetFileName, CurrentCabinetName) == 0))
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT("Using same cabinet as last time\n");
|
|
|
|
|
|
|
|
/* Use our last location because the files should be sequential */
|
|
|
|
CabStatus = CabinetFindNextFileSequential(SourceFileName, &Search);
|
|
|
|
if (CabStatus != CAB_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
DPRINT("Sequential miss on file: %S\n", SourceFileName);
|
|
|
|
|
|
|
|
/* Looks like we got unlucky */
|
|
|
|
CabStatus = CabinetFindFirst(SourceFileName, &Search);
|
|
|
|
}
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
2014-05-12 14:17:37 +00:00
|
|
|
else
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT("Using new cabinet\n");
|
2003-08-24 10:36:07 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
if (HasCurrentCabinet)
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
CabinetCleanup();
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
wcscpy(CurrentCabinetName, CabinetFileName);
|
2003-08-24 10:36:07 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
CabinetInitialize();
|
|
|
|
CabinetSetEventHandlers(NULL, NULL, NULL);
|
|
|
|
CabinetSetCabinetName(CabinetFileName);
|
2003-08-24 10:36:07 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
CabStatus = CabinetOpen();
|
|
|
|
if (CabStatus == CAB_STATUS_SUCCESS)
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT("Opened cabinet %S\n", CabinetGetCabinetName());
|
|
|
|
HasCurrentCabinet = TRUE;
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
2014-05-12 14:17:37 +00:00
|
|
|
else
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT("Cannot open cabinet (%d)\n", CabStatus);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
2014-05-12 14:17:37 +00:00
|
|
|
|
|
|
|
/* We have to start at the beginning here */
|
|
|
|
CabStatus = CabinetFindFirst(SourceFileName, &Search);
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
2014-05-12 14:17:37 +00:00
|
|
|
|
|
|
|
if (CabStatus != CAB_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
DPRINT1("Unable to find '%S' in cabinet '%S'\n", SourceFileName, CabinetGetCabinetName());
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CabinetSetDestinationPath(DestinationPathName);
|
|
|
|
CabStatus = CabinetExtractFile(&Search);
|
|
|
|
if (CabStatus != CAB_STATUS_SUCCESS)
|
2003-08-24 10:36:07 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
DPRINT("Cannot extract file %S (%d)\n", SourceFileName, CabStatus);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
2003-08-24 10:36:07 +00:00
|
|
|
}
|
2006-11-10 21:00:24 +00:00
|
|
|
#endif
|
2003-08-24 10:36:07 +00:00
|
|
|
|
2003-01-17 13:18:15 +00:00
|
|
|
BOOLEAN
|
2014-05-12 14:17:37 +00:00
|
|
|
DoesFileExist(
|
|
|
|
PWSTR PathName,
|
|
|
|
PWSTR FileName)
|
2003-01-17 13:18:15 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
UNICODE_STRING Name;
|
|
|
|
WCHAR FullName[MAX_PATH];
|
|
|
|
HANDLE FileHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
wcscpy(FullName, PathName);
|
|
|
|
if (FileName != NULL)
|
2003-01-17 13:18:15 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
if (FileName[0] != L'\\')
|
|
|
|
wcscat(FullName, L"\\");
|
|
|
|
wcscat(FullName, FileName);
|
2003-01-17 13:18:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
RtlInitUnicodeString(&Name,
|
|
|
|
FullName);
|
|
|
|
|
|
|
|
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))
|
2003-02-08 00:19:32 +00:00
|
|
|
{
|
2014-05-12 14:17:37 +00:00
|
|
|
return FALSE;
|
2003-02-08 00:19:32 +00:00
|
|
|
}
|
2003-01-17 13:18:15 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
NtClose(FileHandle);
|
2003-01-17 13:18:15 +00:00
|
|
|
|
2014-05-12 14:17:37 +00:00
|
|
|
return TRUE;
|
2003-01-17 13:18:15 +00:00
|
|
|
}
|
|
|
|
|
2002-11-13 18:25:18 +00:00
|
|
|
/* EOF */
|