+chg: minor corrections

This commit is contained in:
METANEOCORTEX\Kotti 2021-09-01 12:19:56 +02:00
parent 592a25f139
commit cbedcd59e5
4 changed files with 82 additions and 48 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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()

View File

@ -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);