Author: hbelusca
Date: Mon Aug 21 19:14:33 2017
New Revision: 75635
URL:
http://svn.reactos.org/svn/reactos?rev=75635&view=rev
Log:
[SETUPLIB]: Merge DoesPathExist() and DoesFileExist() into (temporarily called)
DoesPathExistEx() function, and turn the previous two functions into macros.
Modified:
branches/setup_improvements/base/setup/lib/filesup.c
branches/setup_improvements/base/setup/lib/filesup.h
Modified: branches/setup_improvements/base/setup/lib/filesup.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/filesup.c [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/filesup.c [iso-8859-1] Mon Aug 21 19:14:33
2017
@@ -516,19 +516,17 @@
return hr;
}
-//
-// NOTE: It may be possible to merge both DoesPathExist and DoesFileExist...
-//
BOOLEAN
-DoesPathExist(
+DoesPathExistEx(
IN HANDLE RootDirectory OPTIONAL,
- IN PCWSTR PathName)
+ IN PCWSTR PathName,
+ IN BOOLEAN IsDirectory)
{
NTSTATUS Status;
+ UNICODE_STRING Name;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
- UNICODE_STRING Name;
RtlInitUnicodeString(&Name, PathName);
@@ -539,48 +537,20 @@
NULL);
Status = NtOpenFile(&FileHandle,
- FILE_LIST_DIRECTORY | SYNCHRONIZE,
+ IsDirectory ? (FILE_LIST_DIRECTORY | SYNCHRONIZE)
+ : FILE_GENERIC_READ, // Contains SYNCHRONIZE
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_READ | FILE_SHARE_WRITE,
- FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE);
+ FILE_SYNCHRONOUS_IO_NONALERT |
+ (IsDirectory ? FILE_DIRECTORY_FILE
+ : FILE_NON_DIRECTORY_FILE));
if (NT_SUCCESS(Status))
NtClose(FileHandle);
else
- DPRINT1("Failed to open directory '%wZ', Status 0x%08lx\n",
&Name, Status);
-
- return NT_SUCCESS(Status);
-}
-
-BOOLEAN
-DoesFileExist(
- IN HANDLE RootDirectory OPTIONAL,
- IN PCWSTR PathNameToFile)
-{
- NTSTATUS Status;
- UNICODE_STRING FileName;
- HANDLE FileHandle;
- OBJECT_ATTRIBUTES ObjectAttributes;
- IO_STATUS_BLOCK IoStatusBlock;
-
- RtlInitUnicodeString(&FileName, PathNameToFile);
-
- InitializeObjectAttributes(&ObjectAttributes,
- &FileName,
- OBJ_CASE_INSENSITIVE,
- RootDirectory,
- NULL);
-
- Status = NtOpenFile(&FileHandle,
- FILE_GENERIC_READ, // Contains SYNCHRONIZE
- &ObjectAttributes,
- &IoStatusBlock,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
- if (NT_SUCCESS(Status))
- NtClose(FileHandle);
- else
- DPRINT1("Failed to open file '%wZ', Status 0x%08lx\n",
&FileName, Status);
+ DPRINT1("Failed to open %s '%wZ', Status 0x%08lx\n",
+ IsDirectory ? "directory" : "file",
+ &Name, Status);
return NT_SUCCESS(Status);
}
Modified: branches/setup_improvements/base/setup/lib/filesup.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/filesup.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/filesup.h [iso-8859-1] Mon Aug 21 19:14:33
2017
@@ -63,14 +63,16 @@
IN /* PCWSTR */ ...);
BOOLEAN
-DoesPathExist(
+DoesPathExistEx(
IN HANDLE RootDirectory OPTIONAL,
- IN PCWSTR PathName);
+ IN PCWSTR PathName,
+ IN BOOLEAN IsDirectory);
-BOOLEAN
-DoesFileExist(
- IN HANDLE RootDirectory OPTIONAL,
- IN PCWSTR PathNameToFile);
+#define DoesPathExist(RootDirectory, PathName) \
+ DoesPathExistEx((RootDirectory), (PathName), TRUE)
+
+#define DoesFileExist(RootDirectory, FileName) \
+ DoesPathExistEx((RootDirectory), (FileName), FALSE)
// FIXME: DEPRECATED! HACKish function that needs to be deprecated!
BOOLEAN