From cbedcd59e550411766214b07e97f9c2fada8eed5 Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Wed, 1 Sep 2021 12:19:56 +0200 Subject: [PATCH] +chg: minor corrections --- src/DynStrg.c | 14 +++---- src/DynStrg.h | 2 +- src/PathLib.c | 101 +++++++++++++++++++++++++++++++++----------------- src/PathLib.h | 13 ++++--- 4 files changed, 82 insertions(+), 48 deletions(-) diff --git a/src/DynStrg.c b/src/DynStrg.c index 3ba2fe383..2af2e94de 100644 --- a/src/DynStrg.c +++ b/src/DynStrg.c @@ -466,6 +466,13 @@ const wchar_t* STRAPI StrgGet(const HSTRINGW hstr) // ---------------------------------------------------------------------------- +int STRAPI StrgIsEmpty(const HSTRINGW hstr) +{ + return (StrgGetLength(hstr) == 0); +} +// ---------------------------------------------------------------------------- + + size_t STRAPI StrgGetLength(const HSTRINGW hstr) { STRINGW* pstr = ToWStrg(hstr); @@ -486,13 +493,6 @@ size_t STRAPI StrgGetAllocLength(const HSTRINGW hstr) // ---------------------------------------------------------------------------- -int STRAPI StrgIsEmpty(const HSTRINGW hstr) -{ - return StrgGetLength(hstr) == 0; -} -// ---------------------------------------------------------------------------- - - void STRAPI StrgFreeExtra(HSTRINGW hstr) { STRINGW* pstr = ToWStrg(hstr); diff --git a/src/DynStrg.h b/src/DynStrg.h index b70b1fb26..528f8ac2e 100644 --- a/src/DynStrg.h +++ b/src/DynStrg.h @@ -37,9 +37,9 @@ DECLARE_HANDLE(HSTRINGW); HSTRINGW STRAPI StrgCreate(); void STRAPI StrgDestroy(HSTRINGW hstr); +int STRAPI StrgIsEmpty(const HSTRINGW hstr); size_t STRAPI StrgGetLength(const HSTRINGW hstr); size_t STRAPI StrgGetAllocLength(const HSTRINGW hstr); -int STRAPI StrgIsEmpty(const HSTRINGW hstr); void STRAPI StrgFreeExtra(HSTRINGW hstr); void STRAPI StrgEmpty(HSTRINGW hstr); diff --git a/src/PathLib.c b/src/PathLib.c index 5929febd3..016fb63fd 100644 --- a/src/PathLib.c +++ b/src/PathLib.c @@ -368,6 +368,27 @@ bool PTHAPI Path_Canonicalize(HPATHL hpth_out, const HPATHL hpth_in) // ---------------------------------------------------------------------------- +bool PTHAPI Path_IsValidUNC(const HPATHL hpth, HSTRINGW server_name_out) +{ + HSTRINGW hstr = ToHStrgW(hpth); + if (!hstr) + return false; + + //PrependLongPathPrefix(hpth, false); + + wchar_t const buffer[1024] = { L'\0' }; + const wchar_t* server_name = (server_name_out ? buffer : NULL); + + bool const res = PathIsUNCEx(PathGet(hpth), &server_name); + + if (server_name) { + StrgSet(server_name_out, server_name); + } + return res; +} +// ---------------------------------------------------------------------------- + + bool PTHAPI Path_RemoveFileSpec(HPATHL hpth) { HSTRINGW hstr = ToHStrgW(hpth); @@ -389,7 +410,6 @@ bool PTHAPI Path_RemoveFileSpec(HPATHL hpth) // ---------------------------------------------------------------------------- - bool PTHAPI Path_StripPath(HPATHL hpth) // get filename only { HSTRINGW hstr = ToHStrgW(hpth); @@ -406,7 +426,6 @@ bool PTHAPI Path_StripPath(HPATHL hpth) // get filename only // ---------------------------------------------------------------------------- - bool PTHAPI Path_RenameExtension(HPATHL hpth, const wchar_t* ext) { HSTRINGW hstr = ToHStrgW(hpth); @@ -425,7 +444,6 @@ bool PTHAPI Path_RenameExtension(HPATHL hpth, const wchar_t* ext) return bOK; } - // ---------------------------------------------------------------------------- @@ -440,38 +458,6 @@ void PTHAPI Path_ExpandEnvStrings(HPATHL hpth) // ---------------------------------------------------------------------------- -bool PTHAPI Path_IsExistingFile(const HPATHL hpth) -{ - HSTRINGW hstr = ToHStrgW(hpth); - if (!hstr) - return false; - - HPATHL hxpth = Path_Allocate(StrgGet(hstr)); - PrependLongPathPrefix(hxpth, false); - DWORD const dwFileAttrib = GetFileAttributesW(PathGet(hxpth)); - Path_Release(hxpth); - - ///bool const bAccessOK = (dwFileAttrib != INVALID_FILE_ATTRIBUTES); - ///if (!bAccessOK) { - /// DWORD const dwError = GetLastError(); - /// switch (dwError) { - /// case ERROR_FILE_NOT_FOUND: - /// break; - /// case ERROR_PATH_NOT_FOUND: - /// break; - /// case ERROR_ACCESS_DENIED: - /// break; - /// default: - /// break; - /// } - ///} - ///bool const bIsDirectory = (dwFileAttrib & FILE_ATTRIBUTE_DIRECTORY); - - return IsExistingFile(dwFileAttrib); -} -// ---------------------------------------------------------------------------- - - void PTHAPI Path_GetModuleFileName(HPATHL hpth_out) { HSTRINGW hmod_str = ToHStrgW(hpth_out); @@ -537,6 +523,51 @@ size_t PTHAPI Path_CommonPrefix(const HPATHL hpth1, const HPATHL hpth2, HPATHL h // ============================================================================ +//============================================================================= +// +// PathIsExistingFile() +// +bool PTHAPI Path_IsExistingFile(const HPATHL hpth) +{ + HSTRINGW hstr = ToHStrgW(hpth); + if (!hstr) + return false; + + HPATHL hxpth = Path_Allocate(StrgGet(hstr)); + PrependLongPathPrefix(hxpth, false); + DWORD const dwFileAttrib = GetFileAttributesW(PathGet(hxpth)); + Path_Release(hxpth); + + ///bool const bAccessOK = (dwFileAttrib != INVALID_FILE_ATTRIBUTES); + ///if (!bAccessOK) { + /// DWORD const dwError = GetLastError(); + /// switch (dwError) { + /// case ERROR_FILE_NOT_FOUND: + /// break; + /// case ERROR_PATH_NOT_FOUND: + /// break; + /// case ERROR_ACCESS_DENIED: + /// break; + /// default: + /// break; + /// } + ///} + ///bool const bIsDirectory = (dwFileAttrib & FILE_ATTRIBUTE_DIRECTORY); + + return IsExistingFile(dwFileAttrib); +} + + +bool PTHAPI PathIsExistingFile(LPCWSTR pszPath) +{ + //return (PathFileExists(pszPath) && !PathIsDirectory(pszPath)); + HPATHL const hpth = Path_Allocate(pszPath); + bool const res = Path_IsExistingFile(hpth); + Path_Release(hpth); + return res; +} + + //============================================================================= // // ExpandEnvironmentStringsEx() diff --git a/src/PathLib.h b/src/PathLib.h index f579673f6..19c83f939 100644 --- a/src/PathLib.h +++ b/src/PathLib.h @@ -39,10 +39,10 @@ int PTHAPI Path_Reset(HPATHL hpth, const wchar_t* path); size_t PTHAPI Path_GetLength(HPATHL hpth); bool PTHAPI Path_Append(HPATHL hpth, HPATHL hmore); bool PTHAPI Path_Canonicalize(HPATHL hpth_out, const HPATHL hpth_in); +bool PTHAPI Path_IsValidUNC(const HPATHL hpth, HSTRINGW server_name_out); bool PTHAPI Path_RemoveFileSpec(HPATHL hpth); bool PTHAPI Path_RenameExtension(HPATHL hpth, const wchar_t* ext); void PTHAPI Path_ExpandEnvStrings(HPATHL hpth); -bool PTHAPI Path_IsExistingFile(const HPATHL hpth); void PTHAPI Path_GetModuleFileName(HPATHL hpth_out); bool PTHAPI Path_IsPrefix(const HPATHL hprefix, const HPATHL hpth); @@ -62,19 +62,19 @@ wchar_t* PTHAPI Path_WriteAccessBuf(HPATHL hpth, size_t len); // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- -inline bool IsReadOnly(const DWORD dwFileAttr) +__forceinline bool IsReadOnly(const DWORD dwFileAttr) { return ((dwFileAttr != INVALID_FILE_ATTRIBUTES) && (dwFileAttr & FILE_ATTRIBUTE_READONLY)); } -inline bool IsExistingFile(const DWORD dwFileAttr) +__forceinline bool IsExistingFile(const DWORD dwFileAttr) { return ((dwFileAttr != INVALID_FILE_ATTRIBUTES) && !(dwFileAttr & FILE_ATTRIBUTE_DIRECTORY)); } -inline bool PathIsExistingFile(LPCWSTR pszPath) +__forceinline bool IsExistingDirectory(const DWORD dwFileAttr) { - return (PathFileExists(pszPath) && !PathIsDirectory(pszPath)); + return ((dwFileAttr != INVALID_FILE_ATTRIBUTES) && (dwFileAttr & FILE_ATTRIBUTE_DIRECTORY)); } @@ -82,6 +82,9 @@ inline bool PathIsExistingFile(LPCWSTR pszPath) // Duplicates for INTERMEDIATE DEV // ============================================================================ +bool PTHAPI Path_IsExistingFile(const HPATHL hpth); +bool PTHAPI PathIsExistingFile(LPCWSTR pszPath); + void PTHAPI ExpandEnvironmentStrg(HSTRINGW hstr); void PTHAPI ExpandEnvironmentStringsEx(LPWSTR lpSrc, size_t cchSrc);