📄 path.c
字号:
{
TRACE("(%s)\n", debugstr_a(lpszPath));
if (lpszPath && *lpszPath)
{
if (*lpszPath == '\\')
{
if (!lpszPath[1])
return TRUE; /* \ */
else if (lpszPath[1]=='\\')
{
BOOL bSeenSlash = FALSE;
lpszPath += 2;
/* Check for UNC root path */
while (*lpszPath)
{
if (*lpszPath == '\\')
{
if (bSeenSlash)
return FALSE;
bSeenSlash = TRUE;
}
lpszPath = CharNextA(lpszPath);
}
return TRUE;
}
}
else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
return TRUE; /* X:\ */
}
return FALSE;
}
/*************************************************************************
* PathIsRootW [SHLWAPI.@]
*
* See PathIsRootA.
*/
BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
{
TRACE("(%s)\n", debugstr_w(lpszPath));
if (lpszPath && *lpszPath)
{
if (*lpszPath == '\\')
{
if (!lpszPath[1])
return TRUE; /* \ */
else if (lpszPath[1]=='\\')
{
BOOL bSeenSlash = FALSE;
lpszPath += 2;
/* Check for UNC root path */
while (*lpszPath)
{
if (*lpszPath == '\\')
{
if (bSeenSlash)
return FALSE;
bSeenSlash = TRUE;
}
lpszPath++;
}
return TRUE;
}
}
else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
return TRUE; /* X:\ */
}
return FALSE;
}
/*************************************************************************
* PathIsDirectoryA [SHLWAPI.@]
*
* Determine if a path is a valid directory
*
* PARAMS
* lpszPath [I] Path to check.
*
* RETURNS
* FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
* FALSE if lpszPath is invalid or not a directory.
*
* NOTES
* Although this function is prototyped as returning a BOOL, it returns
* FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
*
*| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
*| ...
*
* will always fail.
*/
BOOL WINAPI PathIsDirectoryA(LPCSTR lpszPath)
{
DWORD dwAttr;
TRACE("(%s)\n", debugstr_a(lpszPath));
if (!lpszPath || PathIsUNCServerA(lpszPath))
return FALSE;
if (PathIsUNCServerShareA(lpszPath))
{
FIXME("UNC Server Share not yet supported - FAILING\n");
return FALSE;
}
if ((dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES)
return FALSE;
return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
}
/*************************************************************************
* PathIsDirectoryW [SHLWAPI.@]
*
* See PathIsDirectoryA.
*/
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
{
DWORD dwAttr;
TRACE("(%s)\n", debugstr_w(lpszPath));
if (!lpszPath || PathIsUNCServerW(lpszPath))
return FALSE;
if (PathIsUNCServerShareW(lpszPath))
{
FIXME("UNC Server Share not yet supported - FAILING\n");
return FALSE;
}
if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
return FALSE;
return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
}
/*************************************************************************
* PathFileExistsA [SHLWAPI.@]
*
* Determine if a file exists.
*
* PARAMS
* lpszPath [I] Path to check
*
* RETURNS
* TRUE If the file exists and is readable
* FALSE Otherwise
*/
BOOL WINAPI PathFileExistsA(LPCSTR lpszPath)
{
UINT iPrevErrMode;
DWORD dwAttr;
TRACE("(%s)\n",debugstr_a(lpszPath));
if (!lpszPath)
return FALSE;
/* Prevent a dialog box if path is on a disk that has been ejected. */
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
dwAttr = GetFileAttributesA(lpszPath);
SetErrorMode(iPrevErrMode);
return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
}
/*************************************************************************
* PathFileExistsW [SHLWAPI.@]
*
* See PathFileExistsA.
*/
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
{
UINT iPrevErrMode;
DWORD dwAttr;
TRACE("(%s)\n",debugstr_w(lpszPath));
if (!lpszPath)
return FALSE;
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
dwAttr = GetFileAttributesW(lpszPath);
SetErrorMode(iPrevErrMode);
return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
}
/*************************************************************************
* PathFileExistsAndAttributesA [SHLWAPI.445]
*
* Determine if a file exists.
*
* PARAMS
* lpszPath [I] Path to check
* dwAttr [O] attributes of file
*
* RETURNS
* TRUE If the file exists and is readable
* FALSE Otherwise
*/
BOOL WINAPI PathFileExistsAndAttributesA(LPCSTR lpszPath, DWORD *dwAttr)
{
UINT iPrevErrMode;
DWORD dwVal = 0;
TRACE("(%s %p)\n", debugstr_a(lpszPath), dwAttr);
if (dwAttr)
*dwAttr = INVALID_FILE_ATTRIBUTES;
if (!lpszPath)
return FALSE;
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
dwVal = GetFileAttributesA(lpszPath);
SetErrorMode(iPrevErrMode);
if (dwAttr)
*dwAttr = dwVal;
return (dwVal != INVALID_FILE_ATTRIBUTES);
}
/*************************************************************************
* PathFileExistsAndAttributesW [SHLWAPI.446]
*
* See PathFileExistsA.
*/
BOOL WINAPI PathFileExistsAndAttributesW(LPCWSTR lpszPath, DWORD *dwAttr)
{
UINT iPrevErrMode;
DWORD dwVal;
TRACE("(%s %p)\n", debugstr_w(lpszPath), dwAttr);
if (!lpszPath)
return FALSE;
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
dwVal = GetFileAttributesW(lpszPath);
SetErrorMode(iPrevErrMode);
if (dwAttr)
*dwAttr = dwVal;
return (dwVal != INVALID_FILE_ATTRIBUTES);
}
/*************************************************************************
* PathMatchSingleMaskA [internal]
*/
static BOOL WINAPI PathMatchSingleMaskA(LPCSTR name, LPCSTR mask)
{
while (*name && *mask && *mask!=';')
{
if (*mask == '*')
{
do
{
if (PathMatchSingleMaskA(name,mask+1))
return TRUE; /* try substrings */
} while (*name++);
return FALSE;
}
if (toupper(*mask) != toupper(*name) && *mask != '?')
return FALSE;
name = CharNextA(name);
mask = CharNextA(mask);
}
if (!*name)
{
while (*mask == '*')
mask++;
if (!*mask || *mask == ';')
return TRUE;
}
return FALSE;
}
/*************************************************************************
* PathMatchSingleMaskW [internal]
*/
static BOOL WINAPI PathMatchSingleMaskW(LPCWSTR name, LPCWSTR mask)
{
while (*name && *mask && *mask != ';')
{
if (*mask == '*')
{
do
{
if (PathMatchSingleMaskW(name,mask+1))
return TRUE; /* try substrings */
} while (*name++);
return FALSE;
}
if (toupperW(*mask) != toupperW(*name) && *mask != '?')
return FALSE;
name++;
mask++;
}
if (!*name)
{
while (*mask == '*')
mask++;
if (!*mask || *mask == ';')
return TRUE;
}
return FALSE;
}
/*************************************************************************
* PathMatchSpecA [SHLWAPI.@]
*
* Determine if a path matches one or more search masks.
*
* PARAMS
* lpszPath [I] Path to check
* lpszMask [I] Search mask(s)
*
* RETURNS
* TRUE If lpszPath is valid and is matched
* FALSE Otherwise
*
* NOTES
* Multiple search masks may be given if they are separated by ";". The
* pattern "*.*" is treated specially in that it matches all paths (for
* backwards compatibility with DOS).
*/
BOOL WINAPI PathMatchSpecA(LPCSTR lpszPath, LPCSTR lpszMask)
{
TRACE("(%s,%s)\n", lpszPath, lpszMask);
if (!lstrcmpA(lpszMask, "*.*"))
return TRUE; /* Matches every path */
while (*lpszMask)
{
while (*lpszMask == ' ')
lpszMask++; /* Eat leading spaces */
if (PathMatchSingleMaskA(lpszPath, lpszMask))
return TRUE; /* Matches the current mask */
while (*lpszMask && *lpszMask != ';')
lpszMask = CharNextA(lpszMask); /* masks separated by ';' */
if (*lpszMask == ';')
lpszMask++;
}
return FALSE;
}
/*************************************************************************
* PathMatchSpecW [SHLWAPI.@]
*
* See PathMatchSpecA.
*/
BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
{
static const WCHAR szStarDotStar[] = { '*', '.', '*', '\0' };
TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszMask));
if (!lstrcmpW(lpszMask, szStarDotStar))
return TRUE; /* Matches every path */
while (*lpszMask)
{
while (*lpszMask == ' ')
lpszMask++; /* Eat leading spaces */
if (PathMatchSingleMaskW(lpszPath, lpszMask))
return TRUE; /* Matches the current path */
while (*lpszMask && *lpszMask != ';')
lpszMask++; /* masks separated by ';' */
if (*lpszMask == ';')
lpszMask++;
}
return FALSE;
}
/*************************************************************************
* PathIsSameRootA [SHLWAPI.@]
*
* Determine if two paths share the same root.
*
* PARAMS
* lpszPath1 [I] Source path
* lpszPath2 [I] Path to compare with
*
* RETURNS
* TRUE If both paths are valid and share the same root.
* FALSE If either path is invalid or the paths do not share the same root.
*/
BOOL WINAPI PathIsSameRootA(LPCSTR lpszPath1, LPCSTR lpszPath2)
{
LPCSTR lpszStart;
int dwLen;
TRACE("(%s,%s)\n", debugstr_a(lpszPath1), debugstr_a(lpszPath2));
if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootA(lpszPath1)))
return FALSE;
dwLen = PathCommonPrefixA(lpszPath1, lpszPath2, NULL) + 1;
if (lpszStart - lpszPath1 > dwLen)
return FALSE; /* Paths not common up to length of the root */
return TRUE;
}
/*************************************************************************
* PathIsSameRootW [SHLWAPI.@]
*
* See PathIsSameRootA.
*/
BOOL WINAPI PathIsSameRootW(LPCWSTR lpszPath1, LPCWSTR lpszPath2)
{
LPCWSTR lpszStart;
int dwLen;
TRACE("(%s,%s)\n", debugstr_w(lpszPath1), debugstr_w(lpszPath2));
if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootW(lpszPath1)))
return FALSE;
dwLen = PathCommonPrefixW(lpszPath1, lpszPath2, NULL) + 1;
if (lpszStart - lpszPath1 > dwLen)
return FALSE; /* Paths not common up to length of the root */
return TRUE;
}
/*************************************************************************
* PathIsContentTypeA [SHLWAPI.@]
*
* Determine if a file is of a given registered content type.
*
* PARAMS
* lpszPath [I] File to check
* lpszContentType [I] Content type to check for
*
* RETURNS
* TRUE If lpszPath is a given registered content type,
* FALSE Otherwise.
*
* NOTES
* This function looks up the registered content type for lpszPath. If
* a content type is registered, it is compared (case insensitively) to
* lpszContentType. Only if this matches does the function succeed.
*/
BOOL WINAPI PathIsContentTypeA(LPCSTR lpszPath, LPCSTR lpszContentType)
{
LPCSTR szExt;
DWORD dwDummy;
char szBuff[MAX_PATH];
TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszContentType));
if (lpszPath && (szExt = PathFindExtensionA(lpszPath)) && *szExt &&
!SHGetValueA(HKEY_CLASSES_ROOT, szExt, "Content Type",
REG_NONE, szBuff, &dwDummy) &&
!strcasecmp(lpszContentType, szBuff))
{
return TRUE;
}
return FALSE;
}
/*************************************************************************
* PathIsContentTypeW [SHLWAPI.@]
*
* See PathIsContentTypeA.
*/
BOOL WINAPI PathIsContentTypeW(LPCWSTR lpszPath, LPCWSTR lpszContentType)
{
static const WCHAR szContentType[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
LPCWSTR szExt;
DWORD dwDummy;
WCHAR szBuff[MAX_PATH];
TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszContentType));
if (lpszPath && (szExt = PathFindExtensionW(lpszPath)) && *szExt &&
!SHGetValueW(HKEY_CLASSES_ROOT, szExt, szContentType,
REG_NONE, szBuff, &dwDummy) &&
!strcmpiW(lpszContentType, szBuff))
{
return TRUE;
}
return FALSE;
}
/*************************************************************************
* PathIsFileSpecA [SHLWAPI.@]
*
* Determine if a path is a file specification.
*
* PARAMS
* lpszPath [I] Path to chack
*
* RETURNS
* TRUE If lpszPath is a file specification (i.e. Contains no directories).
* FALSE Otherwise.
*/
BOOL WINAPI PathIsFileSpecA(LPCSTR lpszPath)
{
TRACE("(%s)\n", debugstr_a(lpszPath));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -