From cc37199dfd615ee58843175e1a9c22feb1bffa64 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Mon, 21 Aug 2017 19:14:33 +0000 Subject: [PATCH] [SETUPLIB] Merge DoesPathExist() and DoesFileExist() into (temporarily called) DoesPathExistEx() function. And turn the previous two functions into macros. svn path=/branches/setup_improvements/; revision=75635 svn path=/branches/setup_improvements/; revision=75652 --- base/setup/lib/filesup.c | 59 ++++++++++++---------------------------- base/setup/lib/filesup.h | 14 ++++++---- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/base/setup/lib/filesup.c b/base/setup/lib/filesup.c index 03d1ad80031..44a869821a8 100644 --- a/base/setup/lib/filesup.c +++ b/base/setup/lib/filesup.c @@ -8,6 +8,7 @@ /* INCLUDES *****************************************************************/ #include "precomp.h" +#include "filesup.h" #define NDEBUG #include @@ -580,19 +581,17 @@ CombinePaths( return Status; } -// -// 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); @@ -603,48 +602,24 @@ DoesPathExist( 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); - if (NT_SUCCESS(Status)) - NtClose(FileHandle); - else - DPRINT("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); + FILE_SYNCHRONOUS_IO_NONALERT | + (IsDirectory ? FILE_DIRECTORY_FILE + : FILE_NON_DIRECTORY_FILE)); if (NT_SUCCESS(Status)) + { NtClose(FileHandle); + } else - DPRINT("Failed to open file '%wZ', Status 0x%08lx\n", &FileName, Status); + { + DPRINT("Failed to open %s '%wZ', Status 0x%08lx\n", + IsDirectory ? "directory" : "file", + &Name, Status); + } return NT_SUCCESS(Status); } diff --git a/base/setup/lib/filesup.h b/base/setup/lib/filesup.h index 0b820691857..a9fabf4b2c8 100644 --- a/base/setup/lib/filesup.h +++ b/base/setup/lib/filesup.h @@ -61,14 +61,16 @@ CombinePaths( 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 -- 2.17.1