From 4d9795527d1b9fa77ceb0106f308a13f24e1fca4 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sun, 11 Jan 2015 11:16:04 +0100 Subject: different way to check for file existence --- src/shared/util.cpp | 24 ++++++------------------ src/shared/util.h | 1 + 2 files changed, 7 insertions(+), 18 deletions(-) (limited to 'src/shared') diff --git a/src/shared/util.cpp b/src/shared/util.cpp index d284b517..1cbf088b 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -32,28 +32,16 @@ namespace MOShared { bool FileExists(const std::string &filename) { - WIN32_FIND_DATAA findData; - ZeroMemory(&findData, sizeof(WIN32_FIND_DATAA)); - HANDLE search = ::FindFirstFileExA(filename.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, NULL, 0); - if (search == INVALID_HANDLE_VALUE) { - return false; - } else { - FindClose(search); - return true; - } + DWORD dwAttrib = ::GetFileAttributesA(filename.c_str()); + + return (dwAttrib != INVALID_FILE_ATTRIBUTES); } bool FileExists(const std::wstring &filename) { - WIN32_FIND_DATAW findData; - ZeroMemory(&findData, sizeof(WIN32_FIND_DATAW)); - HANDLE search = ::FindFirstFileExW(filename.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, NULL, 0); - if (search == INVALID_HANDLE_VALUE) { - return false; - } else { - FindClose(search); - return true; - } + DWORD dwAttrib = ::GetFileAttributesW(filename.c_str()); + + return (dwAttrib != INVALID_FILE_ATTRIBUTES); } bool FileExists(const std::wstring &searchPath, const std::wstring &filename) diff --git a/src/shared/util.h b/src/shared/util.h index 4af1fb1e..eba3fb3c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -30,6 +30,7 @@ namespace MOShared { static const int MAXPATH_UNICODE = 32767; +/// Test if a file (or directory) by the specified name exists bool FileExists(const std::string &filename); bool FileExists(const std::wstring &filename); -- cgit v1.3.1