2000-07-26 19:51:32 +02:00
|
|
|
/*
|
|
|
|
* Path Functions
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 1999, 2000 Juergen Schmied
|
2002-03-20 02:33:19 +01:00
|
|
|
* Copyright 2001, 2002 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-07-26 19:51:32 +02:00
|
|
|
#include <string.h>
|
2001-12-11 01:30:17 +01:00
|
|
|
#include <stdlib.h>
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2001-01-07 22:50:52 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "winreg.h"
|
2004-10-05 20:07:14 +02:00
|
|
|
#include "winternl.h"
|
2001-12-11 01:30:17 +01:00
|
|
|
#define NO_SHLWAPI_STREAM
|
2000-07-26 19:51:32 +02:00
|
|
|
#include "shlwapi.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-01-07 22:50:52 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-09-20 21:41:08 +02:00
|
|
|
/* Get a function pointer from a DLL handle */
|
|
|
|
#define GET_FUNC(func, module, name, fail) \
|
|
|
|
do { \
|
|
|
|
if (!func) { \
|
|
|
|
if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
|
2003-07-19 05:12:36 +02:00
|
|
|
func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
|
|
|
|
if (!func) return fail; \
|
2002-09-20 21:41:08 +02:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* DLL handles for late bound calls */
|
2007-03-28 13:13:54 +02:00
|
|
|
static HMODULE SHLWAPI_hshell32;
|
2002-09-20 21:41:08 +02:00
|
|
|
|
|
|
|
/* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
|
2003-07-19 05:12:36 +02:00
|
|
|
typedef BOOL (WINAPI *fnpIsNetDrive)(int);
|
|
|
|
static fnpIsNetDrive pIsNetDrive;
|
|
|
|
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR,LPWSTR,DWORD);
|
2002-04-03 04:43:03 +02:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathAppendA [SHLWAPI.@]
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Append one path to another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Initial part of path, and destination for output
|
|
|
|
* lpszAppend [I] Path to append
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE. lpszPath contains the newly created path.
|
2003-03-18 19:35:48 +01:00
|
|
|
* Failure: FALSE, if either path is NULL, or PathCombineA() fails.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpszAppend must contain at least one backslash ('\') if not NULL.
|
2003-03-18 19:35:48 +01:00
|
|
|
* Because PathCombineA() is used to join the paths, the resulting
|
2002-03-20 02:33:19 +01:00
|
|
|
* path is also canonicalized.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathAppendA (LPSTR lpszPath, LPCSTR lpszAppend)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n",debugstr_a(lpszPath), debugstr_a(lpszAppend));
|
|
|
|
|
|
|
|
if (lpszPath && lpszAppend)
|
|
|
|
{
|
2002-07-24 20:58:57 +02:00
|
|
|
if (!PathIsUNCA(lpszAppend))
|
|
|
|
while (*lpszAppend == '\\')
|
|
|
|
lpszAppend++;
|
2002-03-20 02:33:19 +01:00
|
|
|
if (PathCombineA(lpszPath, lpszPath, lpszAppend))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathAppendW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathAppendA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n",debugstr_w(lpszPath), debugstr_w(lpszAppend));
|
|
|
|
|
|
|
|
if (lpszPath && lpszAppend)
|
|
|
|
{
|
2002-07-24 20:58:57 +02:00
|
|
|
if (!PathIsUNCW(lpszAppend))
|
|
|
|
while (*lpszAppend == '\\')
|
|
|
|
lpszAppend++;
|
2002-03-20 02:33:19 +01:00
|
|
|
if (PathCombineW(lpszPath, lpszPath, lpszAppend))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathCombineA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Combine two paths together.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszDest [O] Destination for combined path
|
|
|
|
* lpszDir [I] Directory path
|
2003-03-18 19:35:48 +01:00
|
|
|
* lpszFile [I] File path
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The output path
|
|
|
|
* Failure: NULL, if inputs are invalid.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpszDest should be at least MAX_PATH in size, and may point to the same
|
|
|
|
* memory location as lpszDir. The combined path is canonicalised.
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%s,%s)\n", lpszDest, debugstr_a(lpszDir), debugstr_a(lpszFile));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszDest || (!lpszDir && !lpszFile))
|
|
|
|
return NULL; /* Invalid parameters */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR szDest[MAX_PATH];
|
|
|
|
WCHAR szDir[MAX_PATH];
|
|
|
|
WCHAR szFile[MAX_PATH];
|
|
|
|
if (lpszDir)
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszDir,-1,szDir,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszFile)
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszFile,-1,szFile,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
PathCombineW(szDest, lpszDir ? szDir : NULL, lpszFile ? szFile : NULL);
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szDest,-1,lpszDest,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return lpszDest;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathCombineW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathCombineA.
|
|
|
|
*/
|
|
|
|
LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
|
|
|
|
{
|
|
|
|
WCHAR szTemp[MAX_PATH];
|
|
|
|
BOOL bUseBoth = FALSE, bStrip = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%p,%s,%s)\n", lpszDest, debugstr_w(lpszDir), debugstr_w(lpszFile));
|
|
|
|
|
|
|
|
if (!lpszDest || (!lpszDir && !lpszFile))
|
2006-06-23 15:21:02 +02:00
|
|
|
return NULL; /* Invalid parameters */
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2006-06-26 23:37:45 +02:00
|
|
|
if ((!lpszFile || !*lpszFile) && lpszDir)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
/* Use dir only */
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(szTemp, lpszDir, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
else if (!lpszDir || !*lpszDir || !PathIsRelativeW(lpszFile))
|
|
|
|
{
|
|
|
|
if (!lpszDir || !*lpszDir || *lpszFile != '\\' || PathIsUNCW(lpszFile))
|
|
|
|
{
|
|
|
|
/* Use file only */
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(szTemp, lpszFile, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bUseBoth = TRUE;
|
|
|
|
bStrip = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bUseBoth = TRUE;
|
|
|
|
|
|
|
|
if (bUseBoth)
|
|
|
|
{
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(szTemp, lpszDir, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (bStrip)
|
|
|
|
{
|
|
|
|
PathStripToRootW(szTemp);
|
|
|
|
lpszFile++; /* Skip '\' */
|
|
|
|
}
|
|
|
|
if (!PathAddBackslashW(szTemp))
|
|
|
|
return NULL;
|
|
|
|
if (strlenW(szTemp) + strlenW(lpszFile) >= MAX_PATH)
|
|
|
|
return NULL;
|
|
|
|
strcatW(szTemp, lpszFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
PathCanonicalizeW(lpszDest, szTemp);
|
|
|
|
return lpszDest;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathAddBackslashA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Append a backslash ('\') to a path if one doesn't exist.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] The path to append a backslash to.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The position of the last backslash in the path.
|
|
|
|
* Failure: NULL, if lpszPath is NULL or the path is too large.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
LPSTR WINAPI PathAddBackslashA(LPSTR lpszPath)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t iLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || (iLen = strlen(lpszPath)) >= MAX_PATH)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (iLen)
|
|
|
|
{
|
|
|
|
lpszPath += iLen;
|
|
|
|
if (lpszPath[-1] != '\\')
|
|
|
|
{
|
|
|
|
*lpszPath++ = '\\';
|
|
|
|
*lpszPath = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathAddBackslashW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathAddBackslashA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR WINAPI PathAddBackslashW( LPWSTR lpszPath )
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t iLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || (iLen = strlenW(lpszPath)) >= MAX_PATH)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (iLen)
|
|
|
|
{
|
|
|
|
lpszPath += iLen;
|
|
|
|
if (lpszPath[-1] != '\\')
|
|
|
|
{
|
|
|
|
*lpszPath++ = '\\';
|
|
|
|
*lpszPath = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathBuildRootA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Create a root drive string (e.g. "A:\") from a drive number.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [O] Destination for the drive string
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* lpszPath
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR WINAPI PathBuildRootA(LPSTR lpszPath, int drive)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
TRACE("(%p,%d)\n", lpszPath, drive);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && drive >= 0 && drive < 26)
|
|
|
|
{
|
|
|
|
lpszPath[0] = 'A' + drive;
|
|
|
|
lpszPath[1] = ':';
|
|
|
|
lpszPath[2] = '\\';
|
|
|
|
lpszPath[3] = '\0';
|
|
|
|
}
|
|
|
|
return lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathBuildRootW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathBuildRootA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR WINAPI PathBuildRootW(LPWSTR lpszPath, int drive)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
TRACE("(%p,%d)\n", lpszPath, drive);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && drive >= 0 && drive < 26)
|
|
|
|
{
|
|
|
|
lpszPath[0] = 'A' + drive;
|
|
|
|
lpszPath[1] = ':';
|
|
|
|
lpszPath[2] = '\\';
|
|
|
|
lpszPath[3] = '\0';
|
|
|
|
}
|
|
|
|
return lpszPath;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindFileNameA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Locate the start of the file name in a path
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to search
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* A pointer to the first character of the file name
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
LPSTR WINAPI PathFindFileNameA(LPCSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCSTR lastSlash = lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
while (lpszPath && *lpszPath)
|
|
|
|
{
|
|
|
|
if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
|
|
|
|
lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
|
|
|
|
lastSlash = lpszPath + 1;
|
|
|
|
lpszPath = CharNextA(lpszPath);
|
|
|
|
}
|
|
|
|
return (LPSTR)lastSlash;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindFileNameW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathFindFileNameA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCWSTR lastSlash = lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
while (lpszPath && *lpszPath)
|
|
|
|
{
|
|
|
|
if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
|
|
|
|
lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
|
|
|
|
lastSlash = lpszPath + 1;
|
|
|
|
lpszPath = CharNextW(lpszPath);
|
|
|
|
}
|
|
|
|
return (LPWSTR)lastSlash;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindExtensionA [SHLWAPI.@]
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Locate the start of the file extension in a path
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] The path to search
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* A pointer to the first character of the extension, the end of
|
|
|
|
* the string if the path has no extension, or NULL If lpszPath is NULL
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR WINAPI PathFindExtensionA( LPCSTR lpszPath )
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCSTR lastpoint = NULL;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\' || *lpszPath==' ')
|
|
|
|
lastpoint = NULL;
|
|
|
|
else if (*lpszPath == '.')
|
|
|
|
lastpoint = lpszPath;
|
|
|
|
lpszPath = CharNextA(lpszPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (LPSTR)(lastpoint ? lastpoint : lpszPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindExtensionW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathFindExtensionA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR WINAPI PathFindExtensionW( LPCWSTR lpszPath )
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCWSTR lastpoint = NULL;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\' || *lpszPath==' ')
|
|
|
|
lastpoint = NULL;
|
|
|
|
else if (*lpszPath == '.')
|
|
|
|
lastpoint = lpszPath;
|
|
|
|
lpszPath = CharNextW(lpszPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (LPWSTR)(lastpoint ? lastpoint : lpszPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathGetArgsA [SHLWAPI.@]
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Find the next argument in a string delimited by spaces.
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] The string to search for arguments in
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The start of the next argument in lpszPath, or NULL if lpszPath is NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Spaces in quoted strings are ignored as delimiters.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR WINAPI PathGetArgsA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL bSeenQuote = FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if ((*lpszPath==' ') && !bSeenQuote)
|
|
|
|
return (LPSTR)lpszPath + 1;
|
|
|
|
if (*lpszPath == '"')
|
|
|
|
bSeenQuote = !bSeenQuote;
|
|
|
|
lpszPath = CharNextA(lpszPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (LPSTR)lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathGetArgsW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathGetArgsA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR WINAPI PathGetArgsW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL bSeenQuote = FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if ((*lpszPath==' ') && !bSeenQuote)
|
|
|
|
return (LPWSTR)lpszPath + 1;
|
|
|
|
if (*lpszPath == '"')
|
|
|
|
bSeenQuote = !bSeenQuote;
|
|
|
|
lpszPath = CharNextW(lpszPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (LPWSTR)lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathGetDriveNumberA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Return the drive number from a path
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to get the drive number from
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The drive number corresponding to the drive in the path
|
|
|
|
* Failure: -1, if lpszPath contains no valid drive
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
int WINAPI PathGetDriveNumberA(LPCSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE ("(%s)\n",debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && !IsDBCSLeadByte(*lpszPath) && lpszPath[1] == ':' &&
|
|
|
|
tolower(*lpszPath) >= 'a' && tolower(*lpszPath) <= 'z')
|
|
|
|
return tolower(*lpszPath) - 'a';
|
|
|
|
return -1;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathGetDriveNumberW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathGetDriveNumberA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
int WINAPI PathGetDriveNumberW(LPCWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE ("(%s)\n",debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2006-02-22 12:04:02 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR tl = tolowerW(lpszPath[0]);
|
|
|
|
if (tl >= 'a' && tl <= 'z' && lpszPath[1] == ':')
|
|
|
|
return tl - 'a';
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
return -1;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveFileSpecA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Remove the file specification from a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to remove the file spec from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If the path was valid and modified
|
|
|
|
* FALSE Otherwise
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathRemoveFileSpecA(LPSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR lpszFileSpec = lpszPath;
|
|
|
|
BOOL bModified = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if(lpszPath)
|
|
|
|
{
|
|
|
|
/* Skip directory or UNC path */
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
lpszFileSpec = ++lpszPath;
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
lpszFileSpec = ++lpszPath;
|
|
|
|
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if(*lpszPath == '\\')
|
|
|
|
lpszFileSpec = lpszPath; /* Skip dir */
|
|
|
|
else if(*lpszPath == ':')
|
|
|
|
{
|
|
|
|
lpszFileSpec = ++lpszPath; /* Skip drive */
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
lpszFileSpec++;
|
|
|
|
}
|
|
|
|
if (!(lpszPath = CharNextA(lpszPath)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*lpszFileSpec)
|
|
|
|
{
|
|
|
|
*lpszFileSpec = '\0';
|
|
|
|
bModified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bModified;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveFileSpecW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathRemoveFileSpecA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR lpszFileSpec = lpszPath;
|
|
|
|
BOOL bModified = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if(lpszPath)
|
|
|
|
{
|
|
|
|
/* Skip directory or UNC path */
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
lpszFileSpec = ++lpszPath;
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
lpszFileSpec = ++lpszPath;
|
|
|
|
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if(*lpszPath == '\\')
|
|
|
|
lpszFileSpec = lpszPath; /* Skip dir */
|
|
|
|
else if(*lpszPath == ':')
|
|
|
|
{
|
|
|
|
lpszFileSpec = ++lpszPath; /* Skip drive */
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
lpszFileSpec++;
|
|
|
|
}
|
|
|
|
if (!(lpszPath = CharNextW(lpszPath)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*lpszFileSpec)
|
|
|
|
{
|
|
|
|
*lpszFileSpec = '\0';
|
|
|
|
bModified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bModified;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-11 22:16:11 +02:00
|
|
|
* PathStripPathA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Remove the initial path from the beginning of a filename
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to remove the initial path from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
void WINAPI PathStripPathA(LPSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
LPSTR lpszFileName = PathFindFileNameA(lpszPath);
|
|
|
|
if(lpszFileName)
|
|
|
|
RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1);
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-11 22:16:11 +02:00
|
|
|
* PathStripPathW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathStripPathA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
void WINAPI PathStripPathW(LPWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR lpszFileName;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
lpszFileName = PathFindFileNameW(lpszPath);
|
|
|
|
if(lpszFileName)
|
|
|
|
RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR));
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathStripToRootA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Reduce a path to its root.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] the path to reduce
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE if the stripped path is a root path
|
|
|
|
* Failure: FALSE if the path cannot be stripped or is NULL
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathStripToRootA(LPSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
while(!PathIsRootA(lpszPath))
|
|
|
|
if (!PathRemoveFileSpecA(lpszPath))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathStripToRootW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathStripToRootA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathStripToRootW(LPWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
while(!PathIsRootW(lpszPath))
|
|
|
|
if (!PathRemoveFileSpecW(lpszPath))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveArgsA [SHLWAPI.@]
|
|
|
|
*
|
2003-05-13 02:41:57 +02:00
|
|
|
* Strip space separated arguments from a path.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to remove arguments from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
void WINAPI PathRemoveArgsA(LPSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if(lpszPath)
|
|
|
|
{
|
|
|
|
LPSTR lpszArgs = PathGetArgsA(lpszPath);
|
|
|
|
if (*lpszArgs)
|
|
|
|
lpszArgs[-1] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPSTR lpszLastChar = CharPrevA(lpszPath, lpszArgs);
|
|
|
|
if(*lpszLastChar == ' ')
|
|
|
|
*lpszLastChar = '\0';
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveArgsW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathRemoveArgsA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(lpszPath)
|
|
|
|
{
|
|
|
|
LPWSTR lpszArgs = PathGetArgsW(lpszPath);
|
|
|
|
if (*lpszArgs)
|
|
|
|
lpszArgs[-1] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR lpszLastChar = CharPrevW(lpszPath, lpszArgs);
|
|
|
|
if(*lpszLastChar == ' ')
|
|
|
|
*lpszLastChar = '\0';
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveExtensionA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Remove the file extension from a path
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to remove the extension from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
void WINAPI PathRemoveExtensionA(LPSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
lpszPath = PathFindExtensionA(lpszPath);
|
|
|
|
*lpszPath = '\0';
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveExtensionW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathRemoveExtensionA.
|
|
|
|
*/
|
2000-07-26 19:51:32 +02:00
|
|
|
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
lpszPath = PathFindExtensionW(lpszPath);
|
|
|
|
*lpszPath = '\0';
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveBackslashA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Remove a trailing backslash from a path.
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to remove backslash from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A pointer to the end of the path
|
|
|
|
* Failure: NULL, if lpszPath is NULL
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
LPSTR WINAPI PathRemoveBackslashA( LPSTR lpszPath )
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR szTemp = NULL;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if(lpszPath)
|
|
|
|
{
|
|
|
|
szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
|
|
|
|
if (!PathIsRootA(lpszPath) && *szTemp == '\\')
|
|
|
|
*szTemp = '\0';
|
|
|
|
}
|
|
|
|
return szTemp;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveBackslashW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathRemoveBackslashA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
LPWSTR WINAPI PathRemoveBackslashW( LPWSTR lpszPath )
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR szTemp = NULL;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(lpszPath)
|
|
|
|
{
|
|
|
|
szTemp = CharPrevW(lpszPath, lpszPath + strlenW(lpszPath));
|
|
|
|
if (!PathIsRootW(lpszPath) && *szTemp == '\\')
|
|
|
|
*szTemp = '\0';
|
|
|
|
}
|
|
|
|
return szTemp;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveBlanksA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Remove Spaces from the start and end of a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to strip blanks from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(lpszPath && *lpszPath)
|
|
|
|
{
|
|
|
|
LPSTR start = lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
while (*lpszPath == ' ')
|
|
|
|
lpszPath = CharNextA(lpszPath);
|
|
|
|
|
|
|
|
while(*lpszPath)
|
|
|
|
*start++ = *lpszPath++;
|
|
|
|
|
|
|
|
if (start != lpszPath)
|
|
|
|
while (start[-1] == ' ')
|
|
|
|
start--;
|
|
|
|
*start = '\0';
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRemoveBlanksW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathRemoveBlanksA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(lpszPath && *lpszPath)
|
|
|
|
{
|
|
|
|
LPWSTR start = lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
while (*lpszPath == ' ')
|
|
|
|
lpszPath++;
|
|
|
|
|
|
|
|
while(*lpszPath)
|
|
|
|
*start++ = *lpszPath++;
|
|
|
|
|
|
|
|
if (start != lpszPath)
|
|
|
|
while (start[-1] == ' ')
|
|
|
|
start--;
|
|
|
|
*start = '\0';
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathQuoteSpacesA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Surround a path containg spaces in quotes.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to quote
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The path is not changed if it is invalid or has no spaces.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathQuoteSpacesA(LPSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(lpszPath && StrChrA(lpszPath,' '))
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t iLen = strlen(lpszPath) + 1;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (iLen + 2 < MAX_PATH)
|
|
|
|
{
|
|
|
|
memmove(lpszPath + 1, lpszPath, iLen);
|
|
|
|
lpszPath[0] = '"';
|
|
|
|
lpszPath[iLen] = '"';
|
|
|
|
lpszPath[iLen + 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathQuoteSpacesW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathQuoteSpacesA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathQuoteSpacesW(LPWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(lpszPath && StrChrW(lpszPath,' '))
|
|
|
|
{
|
|
|
|
int iLen = strlenW(lpszPath) + 1;
|
|
|
|
|
|
|
|
if (iLen + 2 < MAX_PATH)
|
|
|
|
{
|
|
|
|
memmove(lpszPath + 1, lpszPath, iLen * sizeof(WCHAR));
|
|
|
|
lpszPath[0] = '"';
|
|
|
|
lpszPath[iLen] = '"';
|
|
|
|
lpszPath[iLen + 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUnquoteSpacesA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Remove quotes ("") from around a path, if present.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to strip quotes from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
2000-07-26 19:51:32 +02:00
|
|
|
* NOTES
|
2002-03-20 02:33:19 +01:00
|
|
|
* If the path contains a single quote only, an empty string will result.
|
|
|
|
* Otherwise quotes are only removed if they appear at the start and end
|
|
|
|
* of the path.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathUnquoteSpacesA(LPSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && *lpszPath == '"')
|
|
|
|
{
|
|
|
|
DWORD dwLen = strlen(lpszPath) - 1;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath[dwLen] == '"')
|
|
|
|
{
|
|
|
|
lpszPath[dwLen] = '\0';
|
|
|
|
for (; *lpszPath; lpszPath++)
|
|
|
|
*lpszPath = lpszPath[1];
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUnquoteSpacesW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathUnquoteSpacesA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathUnquoteSpacesW(LPWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && *lpszPath == '"')
|
|
|
|
{
|
|
|
|
DWORD dwLen = strlenW(lpszPath) - 1;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath[dwLen] == '"')
|
|
|
|
{
|
|
|
|
lpszPath[dwLen] = '\0';
|
|
|
|
for (; *lpszPath; lpszPath++)
|
|
|
|
*lpszPath = lpszPath[1];
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathParseIconLocationA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Parse the location of an icon from a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] The path to parse the icon location from.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The number of the icon
|
|
|
|
* Failure: 0 if the path does not contain an icon location or is NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The path has surrounding quotes and spaces removed regardless
|
|
|
|
* of whether the call succeeds or not.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
int WINAPI PathParseIconLocationA(LPSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
int iRet = 0;
|
|
|
|
LPSTR lpszComma;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
if ((lpszComma = strchr(lpszPath, ',')))
|
|
|
|
{
|
|
|
|
*lpszComma++ = '\0';
|
|
|
|
iRet = StrToIntA(lpszComma);
|
|
|
|
}
|
|
|
|
PathUnquoteSpacesA(lpszPath);
|
|
|
|
PathRemoveBlanksA(lpszPath);
|
|
|
|
}
|
|
|
|
return iRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathParseIconLocationW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathParseIconLocationA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
int WINAPI PathParseIconLocationW(LPWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
int iRet = 0;
|
|
|
|
LPWSTR lpszComma;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
if ((lpszComma = StrChrW(lpszPath, ',')))
|
|
|
|
{
|
|
|
|
*lpszComma++ = '\0';
|
|
|
|
iRet = StrToIntW(lpszComma);
|
|
|
|
}
|
|
|
|
PathUnquoteSpacesW(lpszPath);
|
|
|
|
PathRemoveBlanksW(lpszPath);
|
|
|
|
}
|
|
|
|
return iRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
/*************************************************************************
|
2002-09-20 21:41:08 +02:00
|
|
|
* @ [SHLWAPI.4]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2003-09-11 04:56:15 +02:00
|
|
|
* Unicode version of PathFileExistsDefExtA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
BOOL WINAPI PathFileExistsDefExtW(LPWSTR lpszPath,DWORD dwWhich)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2003-03-30 05:05:55 +02:00
|
|
|
static const WCHAR pszExts[7][5] = { { '.', 'p', 'i', 'f', 0},
|
|
|
|
{ '.', 'c', 'o', 'm', 0},
|
|
|
|
{ '.', 'e', 'x', 'e', 0},
|
|
|
|
{ '.', 'b', 'a', 't', 0},
|
|
|
|
{ '.', 'l', 'n', 'k', 0},
|
|
|
|
{ '.', 'c', 'm', 'd', 0},
|
|
|
|
{ 0, 0, 0, 0, 0} };
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%d)\n", debugstr_w(lpszPath), dwWhich);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!lpszPath || PathIsUNCServerW(lpszPath) || PathIsUNCServerShareW(lpszPath))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (dwWhich)
|
|
|
|
{
|
|
|
|
LPCWSTR szExt = PathFindExtensionW(lpszPath);
|
|
|
|
if (!*szExt || dwWhich & 0x40)
|
|
|
|
{
|
2002-07-24 20:58:57 +02:00
|
|
|
size_t iChoose = 0;
|
2002-03-20 02:33:19 +01:00
|
|
|
int iLen = lstrlenW(lpszPath);
|
|
|
|
if (iLen > (MAX_PATH - 5))
|
|
|
|
return FALSE;
|
2004-09-03 03:02:18 +02:00
|
|
|
while ( (dwWhich & 0x1) && pszExts[iChoose][0] )
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
lstrcpyW(lpszPath + iLen, pszExts[iChoose]);
|
|
|
|
if (PathFileExistsW(lpszPath))
|
|
|
|
return TRUE;
|
|
|
|
iChoose++;
|
|
|
|
dwWhich >>= 1;
|
|
|
|
}
|
|
|
|
*(lpszPath + iLen) = (WCHAR)'\0';
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PathFileExistsW(lpszPath);
|
|
|
|
}
|
|
|
|
|
2002-09-20 21:41:08 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.3]
|
|
|
|
*
|
|
|
|
* Determine if a file exists locally and is of an executable type.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] File to search for
|
|
|
|
* dwWhich [I] Type of executable to search for
|
2002-09-20 21:41:08 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If the file was found. lpszPath contains the file name.
|
2002-09-20 21:41:08 +02:00
|
|
|
* FALSE Otherwise.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpszPath is modified in place and must be at least MAX_PATH in length.
|
2006-10-03 14:10:58 +02:00
|
|
|
* If the function returns FALSE, the path is modified to its original state.
|
2002-09-20 21:41:08 +02:00
|
|
|
* If the given path contains an extension or dwWhich is 0, executable
|
|
|
|
* extensions are not checked.
|
|
|
|
*
|
|
|
|
* Ordinals 3-6 are a classic case of MS exposing limited functionality to
|
2003-03-18 19:35:48 +01:00
|
|
|
* users (here through PathFindOnPathA()) and keeping advanced functionality for
|
2002-09-20 21:41:08 +02:00
|
|
|
* their own developers exclusive use. Monopoly, anyone?
|
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
BOOL WINAPI PathFileExistsDefExtA(LPSTR lpszPath,DWORD dwWhich)
|
2002-09-20 21:41:08 +02:00
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%d)\n", debugstr_a(lpszPath), dwWhich);
|
2002-09-20 21:41:08 +02:00
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2003-09-11 04:56:15 +02:00
|
|
|
bRet = PathFileExistsDefExtW(szPath, dwWhich);
|
2002-09-20 21:41:08 +02:00
|
|
|
if (bRet)
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
2002-09-20 21:41:08 +02:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* SHLWAPI_PathFindInOtherDirs
|
|
|
|
*
|
|
|
|
* Internal helper for SHLWAPI_PathFindOnPathExA/W.
|
|
|
|
*/
|
|
|
|
static BOOL WINAPI SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile, DWORD dwWhich)
|
|
|
|
{
|
2004-04-20 02:34:52 +02:00
|
|
|
static const WCHAR szSystem[] = { 'S','y','s','t','e','m','\0'};
|
|
|
|
static const WCHAR szPath[] = { 'P','A','T','H','\0'};
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwLenPATH;
|
|
|
|
LPCWSTR lpszCurr;
|
|
|
|
WCHAR *lpszPATH;
|
|
|
|
WCHAR buff[MAX_PATH];
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%08x)\n", debugstr_w(lpszFile), dwWhich);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
/* Try system directories */
|
|
|
|
GetSystemDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!PathAppendW(buff, lpszFile))
|
|
|
|
return FALSE;
|
2003-09-11 04:56:15 +02:00
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
strcpyW(lpszFile, buff);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
GetWindowsDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!PathAppendW(buff, szSystem ) || !PathAppendW(buff, lpszFile))
|
|
|
|
return FALSE;
|
2003-09-11 04:56:15 +02:00
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
strcpyW(lpszFile, buff);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
GetWindowsDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!PathAppendW(buff, lpszFile))
|
|
|
|
return FALSE;
|
2003-09-11 04:56:15 +02:00
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
strcpyW(lpszFile, buff);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* Try dirs listed in %PATH% */
|
|
|
|
dwLenPATH = GetEnvironmentVariableW(szPath, buff, MAX_PATH);
|
|
|
|
|
2007-03-23 20:49:00 +01:00
|
|
|
if (!dwLenPATH || !(lpszPATH = HeapAlloc(GetProcessHeap(), 0, (dwLenPATH + 1) * sizeof (WCHAR))))
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GetEnvironmentVariableW(szPath, lpszPATH, dwLenPATH + 1);
|
|
|
|
lpszCurr = lpszPATH;
|
|
|
|
while (lpszCurr)
|
|
|
|
{
|
|
|
|
LPCWSTR lpszEnd = lpszCurr;
|
|
|
|
LPWSTR pBuff = buff;
|
|
|
|
|
|
|
|
while (*lpszEnd == ' ')
|
|
|
|
lpszEnd++;
|
|
|
|
while (*lpszEnd && *lpszEnd != ';')
|
|
|
|
*pBuff++ = *lpszEnd++;
|
|
|
|
*pBuff = '\0';
|
|
|
|
|
|
|
|
if (*lpszEnd)
|
|
|
|
lpszCurr = lpszEnd + 1;
|
|
|
|
else
|
|
|
|
lpszCurr = NULL; /* Last Path, terminate after this */
|
|
|
|
|
|
|
|
if (!PathAppendW(buff, lpszFile))
|
2003-09-22 21:46:32 +02:00
|
|
|
{
|
2007-03-23 20:49:00 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
2003-09-22 21:46:32 +02:00
|
|
|
}
|
2003-09-11 04:56:15 +02:00
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
strcpyW(lpszFile, buff);
|
2007-03-23 20:49:00 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-03-23 20:49:00 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-09-20 21:41:08 +02:00
|
|
|
* @ [SHLWAPI.5]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2002-09-20 21:41:08 +02:00
|
|
|
* Search a range of paths for a specific type of executable.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszFile [I/O] File to search for
|
|
|
|
* lppszOtherDirs [I] Other directories to look in
|
|
|
|
* dwWhich [I] Type of executable to search for
|
2002-09-20 21:41:08 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* Success: TRUE. The path to the executable is stored in lpszFile.
|
2002-09-20 21:41:08 +02:00
|
|
|
* Failure: FALSE. The path to the executable is unchanged.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
BOOL WINAPI PathFindOnPathExA(LPSTR lpszFile,LPCSTR *lppszOtherDirs,DWORD dwWhich)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
WCHAR szFile[MAX_PATH];
|
|
|
|
WCHAR buff[MAX_PATH];
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile), lppszOtherDirs, dwWhich);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!lpszFile || !PathIsFileSpecA(lpszFile))
|
|
|
|
return FALSE;
|
|
|
|
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszFile,-1,szFile,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
/* Search provided directories first */
|
|
|
|
if (lppszOtherDirs && *lppszOtherDirs)
|
|
|
|
{
|
|
|
|
WCHAR szOther[MAX_PATH];
|
|
|
|
LPCSTR *lpszOtherPath = lppszOtherDirs;
|
|
|
|
|
|
|
|
while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
|
|
|
|
{
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,*lpszOtherPath,-1,szOther,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
PathCombineW(buff, szOther, szFile);
|
2003-09-11 04:56:15 +02:00
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,buff,-1,lpszFile,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
lpszOtherPath++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Not found, try system and path dirs */
|
|
|
|
if (SHLWAPI_PathFindInOtherDirs(szFile, dwWhich))
|
|
|
|
{
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szFile,-1,lpszFile,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-09-20 21:41:08 +02:00
|
|
|
* @ [SHLWAPI.6]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2003-09-11 04:56:15 +02:00
|
|
|
* Unicode version of PathFindOnPathExA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile,LPCWSTR *lppszOtherDirs,DWORD dwWhich)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
WCHAR buff[MAX_PATH];
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile), lppszOtherDirs, dwWhich);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!lpszFile || !PathIsFileSpecW(lpszFile))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Search provided directories first */
|
|
|
|
if (lppszOtherDirs && *lppszOtherDirs)
|
|
|
|
{
|
|
|
|
LPCWSTR *lpszOtherPath = lppszOtherDirs;
|
|
|
|
while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
|
|
|
|
{
|
|
|
|
PathCombineW(buff, *lpszOtherPath, lpszFile);
|
2003-09-11 04:56:15 +02:00
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
strcpyW(lpszFile, buff);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
lpszOtherPath++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Not found, try system and path dirs */
|
|
|
|
return SHLWAPI_PathFindInOtherDirs(lpszFile, dwWhich);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindOnPathA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Search a range of paths for an executable.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszFile [I/O] File to search for
|
|
|
|
* lppszOtherDirs [I] Other directories to look in
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE. The path to the executable is stored in lpszFile.
|
|
|
|
* Failure: FALSE. The path to the executable is unchanged.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathFindOnPathA(LPSTR lpszFile, LPCSTR *lppszOtherDirs)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%p)\n", debugstr_a(lpszFile), lppszOtherDirs);
|
2003-09-11 04:56:15 +02:00
|
|
|
return PathFindOnPathExA(lpszFile, lppszOtherDirs, 0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindOnPathW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathFindOnPathA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-09-20 21:41:08 +02:00
|
|
|
BOOL WINAPI PathFindOnPathW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%p)\n", debugstr_w(lpszFile), lppszOtherDirs);
|
2003-09-11 04:56:15 +02:00
|
|
|
return PathFindOnPathExW(lpszFile,lppszOtherDirs, 0);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCompactPathExA [SHLWAPI.@]
|
|
|
|
*
|
2002-07-24 20:58:57 +02:00
|
|
|
* Compact a path into a given number of characters.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszDest [O] Destination for compacted path
|
|
|
|
* lpszPath [I] Source path
|
2003-03-18 19:35:48 +01:00
|
|
|
* cchMax [I] Maximum size of compacted path
|
2002-07-24 20:58:57 +02:00
|
|
|
* dwFlags [I] Reserved
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2002-07-24 20:58:57 +02:00
|
|
|
* Success: TRUE. The compacted path is written to lpszDest.
|
|
|
|
* Failure: FALSE. lpszPath is undefined.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If cchMax is given as 0, lpszDest will still be NUL terminated.
|
2003-07-19 05:12:36 +02:00
|
|
|
*
|
2002-07-24 20:58:57 +02:00
|
|
|
* The Win32 version of this function contains a bug: When cchMax == 7,
|
|
|
|
* 8 bytes will be written to lpszDest. This bug is fixed in the Wine
|
|
|
|
* implementation.
|
2003-03-18 19:35:48 +01:00
|
|
|
*
|
2002-07-24 20:58:57 +02:00
|
|
|
* Some relative paths will be different when cchMax == 5 or 6. This occurs
|
2003-03-18 19:35:48 +01:00
|
|
|
* because Win32 will insert a "\" in lpszDest, even if one is
|
2002-07-24 20:58:57 +02:00
|
|
|
* not present in the original path.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathCompactPathExA(LPSTR lpszDest, LPCSTR lpszPath,
|
|
|
|
UINT cchMax, DWORD dwFlags)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%s,%d,0x%08x)\n", lpszDest, debugstr_a(lpszPath), cchMax, dwFlags);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (lpszPath && lpszDest)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WCHAR szDest[MAX_PATH];
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
szDest[0] = '\0';
|
|
|
|
bRet = PathCompactPathExW(szDest, szPath, cchMax, dwFlags);
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szDest,-1,lpszDest,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCompactPathExW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathCompactPathExA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathCompactPathExW(LPWSTR lpszDest, LPCWSTR lpszPath,
|
|
|
|
UINT cchMax, DWORD dwFlags)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-07-24 20:58:57 +02:00
|
|
|
static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
|
|
|
|
LPCWSTR lpszFile;
|
|
|
|
DWORD dwLen, dwFileLen = 0;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%s,%d,0x%08x)\n", lpszDest, debugstr_w(lpszPath), cchMax, dwFlags);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!lpszDest)
|
|
|
|
{
|
|
|
|
WARN("Invalid lpszDest would crash under Win32!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
*lpszDest = '\0';
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if (cchMax < 2)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
dwLen = strlenW(lpszPath) + 1;
|
|
|
|
|
|
|
|
if (dwLen < cchMax)
|
|
|
|
{
|
|
|
|
/* Don't need to compact */
|
|
|
|
memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Path must be compacted to fit into lpszDest */
|
|
|
|
lpszFile = PathFindFileNameW(lpszPath);
|
|
|
|
dwFileLen = lpszPath + dwLen - lpszFile;
|
|
|
|
|
|
|
|
if (dwFileLen == dwLen)
|
|
|
|
{
|
|
|
|
/* No root in psth */
|
|
|
|
if (cchMax <= 4)
|
|
|
|
{
|
|
|
|
while (--cchMax > 0) /* No room left for anything but ellipses */
|
|
|
|
*lpszDest++ = '.';
|
|
|
|
*lpszDest = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* Compact the file name with ellipses at the end */
|
|
|
|
cchMax -= 4;
|
|
|
|
memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
|
|
|
|
strcpyW(lpszDest + cchMax, szEllipses);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* We have a root in the path */
|
2003-06-18 05:30:39 +02:00
|
|
|
lpszFile--; /* Start compacted filename with the path separator */
|
2002-07-24 20:58:57 +02:00
|
|
|
dwFileLen++;
|
|
|
|
|
|
|
|
if (dwFileLen + 3 > cchMax)
|
|
|
|
{
|
|
|
|
/* Compact the file name */
|
|
|
|
if (cchMax <= 4)
|
|
|
|
{
|
|
|
|
while (--cchMax > 0) /* No room left for anything but ellipses */
|
|
|
|
*lpszDest++ = '.';
|
|
|
|
*lpszDest = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
strcpyW(lpszDest, szEllipses);
|
|
|
|
lpszDest += 3;
|
|
|
|
cchMax -= 4;
|
|
|
|
*lpszDest++ = *lpszFile++;
|
|
|
|
if (cchMax <= 4)
|
|
|
|
{
|
|
|
|
while (--cchMax > 0) /* No room left for anything but ellipses */
|
|
|
|
*lpszDest++ = '.';
|
|
|
|
*lpszDest = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
cchMax -= 4;
|
|
|
|
memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
|
|
|
|
strcpyW(lpszDest + cchMax, szEllipses);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only the root needs to be Compacted */
|
|
|
|
dwLen = cchMax - dwFileLen - 3;
|
|
|
|
memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
|
|
|
|
strcpyW(lpszDest + dwLen, szEllipses);
|
|
|
|
strcpyW(lpszDest + dwLen + 3, lpszFile);
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsRelativeA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a path is a relative path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE: The path is relative, or is invalid.
|
|
|
|
* FALSE: The path is not relative.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsRelativeA (LPCSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszPath || !*lpszPath || IsDBCSLeadByte(*lpszPath))
|
|
|
|
return TRUE;
|
|
|
|
if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsRelativeW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathIsRelativeA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsRelativeW (LPCWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszPath || !*lpszPath)
|
|
|
|
return TRUE;
|
|
|
|
if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsRootA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Determine if a path is a root path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If lpszPath is valid and a root path,
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE Otherwise
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsRootA(LPCSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
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;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsRootW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* 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 = CharNextW(lpszPath);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
|
|
|
|
return TRUE; /* X:\ */
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsDirectoryA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
*| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
|
|
|
|
*| ...
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* will always fail.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsDirectoryA(LPCSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwAttr;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszPath || PathIsUNCServerA(lpszPath))
|
|
|
|
return FALSE;
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (PathIsUNCServerShareA(lpszPath))
|
|
|
|
{
|
|
|
|
FIXME("UNC Server Share not yet supported - FAILING\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if ((dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsDirectoryW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathIsDirectoryA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwAttr;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || PathIsUNCServerW(lpszPath))
|
|
|
|
return FALSE;
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (PathIsUNCServerShareW(lpszPath))
|
|
|
|
{
|
|
|
|
FIXME("UNC Server Share not yet supported - FAILING\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathFileExistsA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Determine if a file exists.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If the file exists and is readable
|
|
|
|
* FALSE Otherwise
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathFileExistsA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
UINT iPrevErrMode;
|
|
|
|
DWORD dwAttr;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
2005-03-14 11:09:53 +01:00
|
|
|
/* Prevent a dialog box if path is on a disk that has been ejected. */
|
|
|
|
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
2002-03-20 02:33:19 +01:00
|
|
|
dwAttr = GetFileAttributesA(lpszPath);
|
|
|
|
SetErrorMode(iPrevErrMode);
|
2003-07-19 05:12:36 +02:00
|
|
|
return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathFileExistsW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2003-07-19 05:12:36 +02:00
|
|
|
* See PathFileExistsA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
UINT iPrevErrMode;
|
|
|
|
DWORD dwAttr;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
2005-03-14 11:09:53 +01:00
|
|
|
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
2002-03-20 02:33:19 +01:00
|
|
|
dwAttr = GetFileAttributesW(lpszPath);
|
|
|
|
SetErrorMode(iPrevErrMode);
|
2003-07-19 05:12:36 +02:00
|
|
|
return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2004-01-19 22:46:14 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* PathMatchSingleMaskA [internal]
|
2003-07-19 05:12:36 +02:00
|
|
|
*/
|
|
|
|
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;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathMatchSingleMaskW [internal]
|
|
|
|
*/
|
2003-07-19 05:12:36 +02:00
|
|
|
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 = CharNextW(name);
|
|
|
|
mask = CharNextW(mask);
|
|
|
|
}
|
|
|
|
if (!*name)
|
|
|
|
{
|
|
|
|
while (*mask == '*')
|
|
|
|
mask++;
|
|
|
|
if (!*mask || *mask == ';')
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* PathMatchSpecA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* Determine if a path matches one or more search masks.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
2003-03-18 19:35:48 +01:00
|
|
|
* lpszMask [I] Search mask(s)
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If lpszPath is valid and is matched
|
|
|
|
* FALSE Otherwise
|
|
|
|
*
|
2000-07-26 19:51:32 +02:00
|
|
|
* NOTES
|
2003-06-18 05:30:39 +02:00
|
|
|
* Multiple search masks may be given if they are separated by ";". The
|
2002-03-20 02:33:19 +01:00
|
|
|
* pattern "*.*" is treated specially in that it matches all paths (for
|
2003-05-13 02:41:57 +02:00
|
|
|
* backwards compatibility with DOS).
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2003-03-18 19:35:48 +01:00
|
|
|
BOOL WINAPI PathMatchSpecA(LPCSTR lpszPath, LPCSTR lpszMask)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
TRACE("(%s,%s)\n", lpszPath, lpszMask);
|
|
|
|
|
|
|
|
if (!lstrcmpA(lpszMask, "*.*"))
|
|
|
|
return TRUE; /* Matches every path */
|
|
|
|
|
|
|
|
while (*lpszMask)
|
|
|
|
{
|
2006-04-11 21:17:52 +02:00
|
|
|
while (*lpszMask == ' ')
|
|
|
|
lpszMask++; /* Eat leading spaces */
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (PathMatchSingleMaskA(lpszPath, lpszMask))
|
|
|
|
return TRUE; /* Matches the current mask */
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
while (*lpszMask && *lpszMask != ';')
|
2006-04-11 21:17:52 +02:00
|
|
|
lpszMask = CharNextA(lpszMask); /* masks separated by ';' */
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (*lpszMask == ';')
|
|
|
|
lpszMask++;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathMatchSpecW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathMatchSpecA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2003-07-19 05:12:36 +02:00
|
|
|
BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
static const WCHAR szStarDotStar[] = { '*', '.', '*', '\0' };
|
|
|
|
|
|
|
|
TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszMask));
|
|
|
|
|
|
|
|
if (!lstrcmpW(lpszMask, szStarDotStar))
|
|
|
|
return TRUE; /* Matches every path */
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
while (*lpszMask)
|
|
|
|
{
|
2006-04-11 21:17:52 +02:00
|
|
|
while (*lpszMask == ' ')
|
|
|
|
lpszMask++; /* Eat leading spaces */
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (PathMatchSingleMaskW(lpszPath, lpszMask))
|
|
|
|
return TRUE; /* Matches the current path */
|
|
|
|
|
|
|
|
while (*lpszMask && *lpszMask != ';')
|
2006-04-11 21:17:52 +02:00
|
|
|
lpszMask++; /* masks separated by ';' */
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (*lpszMask == ';')
|
|
|
|
lpszMask++;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsSameRootA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* 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.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsSameRootA(LPCSTR lpszPath1, LPCSTR lpszPath2)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCSTR lpszStart;
|
2002-07-24 20:58:57 +02:00
|
|
|
int dwLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n", debugstr_a(lpszPath1), debugstr_a(lpszPath2));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
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;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsSameRootW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathIsSameRootA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsSameRootW(LPCWSTR lpszPath1, LPCWSTR lpszPath2)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCWSTR lpszStart;
|
2002-07-24 20:58:57 +02:00
|
|
|
int dwLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n", debugstr_w(lpszPath1), debugstr_w(lpszPath2));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
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;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* PathIsContentTypeA [SHLWAPI.@]
|
|
|
|
*
|
2002-07-24 20:58:57 +02:00
|
|
|
* Determine if a file is of a given registered content type.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I] File to check
|
|
|
|
* lpszContentType [I] Content type to check for
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If lpszPath is a given registered content type,
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE Otherwise.
|
2002-07-24 20:58:57 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsContentTypeW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsContentTypeA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsContentTypeW(LPCWSTR lpszPath, LPCWSTR lpszContentType)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
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;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsFileSpecA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a path is a file specification.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to chack
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-07-19 05:12:36 +02:00
|
|
|
* TRUE If lpszPath is a file specification (i.e. Contains no directories).
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE Otherwise.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsFileSpecA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\' || *lpszPath == ':')
|
|
|
|
return FALSE;
|
|
|
|
lpszPath = CharNextA(lpszPath);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsFileSpecW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsFileSpecA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsFileSpecW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\' || *lpszPath == ':')
|
|
|
|
return FALSE;
|
|
|
|
lpszPath = CharNextW(lpszPath);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsPrefixA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a path is a prefix of another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPrefix [I] Prefix
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I] Path to check
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If lpszPath has lpszPrefix as its prefix,
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE If either path is NULL or lpszPrefix is not a prefix
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsPrefixA (LPCSTR lpszPrefix, LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n", debugstr_a(lpszPrefix), debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPrefix && lpszPath &&
|
2002-07-24 20:58:57 +02:00
|
|
|
PathCommonPrefixA(lpszPath, lpszPrefix, NULL) == (int)strlen(lpszPrefix))
|
2002-03-20 02:33:19 +01:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsPrefixW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsPrefixA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsPrefixW(LPCWSTR lpszPrefix, LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n", debugstr_w(lpszPrefix), debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPrefix && lpszPath &&
|
2002-07-24 20:58:57 +02:00
|
|
|
PathCommonPrefixW(lpszPath, lpszPrefix, NULL) == (int)strlenW(lpszPrefix))
|
2002-03-20 02:33:19 +01:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsSystemFolderA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a path or file attributes are a system folder.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check.
|
|
|
|
* dwAttrib [I] Attributes to check, if lpszPath is NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If lpszPath or dwAttrib are a system folder.
|
2003-03-18 19:35:48 +01:00
|
|
|
* FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsSystemFolderA(LPCSTR lpszPath, DWORD dwAttrib)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath), dwAttrib);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (lpszPath && *lpszPath)
|
|
|
|
dwAttrib = GetFileAttributesA(lpszPath);
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
|
2002-03-20 02:33:19 +01:00
|
|
|
!(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsSystemFolderW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsSystemFolderA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsSystemFolderW(LPCWSTR lpszPath, DWORD dwAttrib)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath), dwAttrib);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (lpszPath && *lpszPath)
|
|
|
|
dwAttrib = GetFileAttributesW(lpszPath);
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
|
2002-03-20 02:33:19 +01:00
|
|
|
!(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsUNCA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a path is in UNC format.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE: The path is UNC.
|
|
|
|
* FALSE: The path is not UNC or is NULL.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsUNCA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsUNCW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsUNCA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsUNCW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsUNCServerA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a path is a UNC server name ("\\SHARENAME").
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If lpszPath is a valid UNC server name.
|
|
|
|
* FALSE Otherwise.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This routine is bug compatible with Win32: Server names with a
|
|
|
|
* trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
|
|
|
|
* Fixing this bug may break other shlwapi functions!
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsUNCServerA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
|
|
|
|
{
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
return FALSE;
|
|
|
|
lpszPath = CharNextA(lpszPath);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsUNCServerW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsUNCServerA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsUNCServerW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
|
|
|
|
{
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
return FALSE;
|
|
|
|
lpszPath = CharNextW(lpszPath);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsUNCServerShareA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If lpszPath is a valid UNC server share.
|
|
|
|
* FALSE Otherwise.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This routine is bug compatible with Win32: Server shares with a
|
|
|
|
* trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
|
|
|
|
* Fixing this bug may break other shlwapi functions!
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsUNCServerShareA(LPCSTR lpszPath)
|
|
|
|
{
|
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
|
|
|
|
{
|
|
|
|
BOOL bSeenSlash = FALSE;
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
{
|
|
|
|
if (bSeenSlash)
|
|
|
|
return FALSE;
|
|
|
|
bSeenSlash = TRUE;
|
|
|
|
}
|
|
|
|
lpszPath = CharNextA(lpszPath);
|
|
|
|
}
|
|
|
|
return bSeenSlash;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsUNCServerShareW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsUNCServerShareA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathIsUNCServerShareW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
|
|
|
|
{
|
|
|
|
BOOL bSeenSlash = FALSE;
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == '\\')
|
|
|
|
{
|
|
|
|
if (bSeenSlash)
|
|
|
|
return FALSE;
|
|
|
|
bSeenSlash = TRUE;
|
|
|
|
}
|
|
|
|
lpszPath = CharNextW(lpszPath);
|
|
|
|
}
|
|
|
|
return bSeenSlash;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathCanonicalizeA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Convert a path to its canonical form.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszBuf [O] Output path
|
|
|
|
* lpszPath [I] Path to cnonicalize
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* Success: TRUE. lpszBuf contains the output path,
|
2002-03-20 02:33:19 +01:00
|
|
|
* Failure: FALSE, If input path is invalid. lpszBuf is undefined
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathCanonicalizeA(LPSTR lpszBuf, LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL bRet = FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%p,%s)\n", lpszBuf, debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszBuf)
|
|
|
|
*lpszBuf = '\0';
|
|
|
|
|
|
|
|
if (!lpszBuf || !lpszPath)
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WCHAR szBuff[MAX_PATH];
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
bRet = PathCanonicalizeW(szBuff, szPath);
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathCanonicalizeW [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* See PathCanonicalizeA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathCanonicalizeW(LPWSTR lpszBuf, LPCWSTR lpszPath)
|
|
|
|
{
|
|
|
|
LPWSTR lpszDst = lpszBuf;
|
|
|
|
LPCWSTR lpszSrc = lpszPath;
|
|
|
|
|
|
|
|
TRACE("(%p,%s)\n", lpszBuf, debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszBuf)
|
|
|
|
*lpszDst = '\0';
|
|
|
|
|
|
|
|
if (!lpszBuf || !lpszPath)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*lpszPath)
|
|
|
|
{
|
|
|
|
*lpszBuf++ = '\\';
|
|
|
|
*lpszBuf = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy path root */
|
|
|
|
if (*lpszSrc == '\\')
|
|
|
|
{
|
|
|
|
*lpszDst++ = *lpszSrc++;
|
|
|
|
}
|
|
|
|
else if (*lpszSrc && lpszSrc[1] == ':')
|
|
|
|
{
|
|
|
|
/* X:\ */
|
|
|
|
*lpszDst++ = *lpszSrc++;
|
|
|
|
*lpszDst++ = *lpszSrc++;
|
|
|
|
if (*lpszSrc == '\\')
|
|
|
|
*lpszDst++ = *lpszSrc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Canonicalize the rest of the path */
|
|
|
|
while (*lpszSrc)
|
|
|
|
{
|
|
|
|
if (*lpszSrc == '.')
|
|
|
|
{
|
|
|
|
if (lpszSrc[1] == '\\' && (lpszSrc == lpszPath || lpszSrc[-1] == '\\' || lpszSrc[-1] == ':'))
|
|
|
|
{
|
|
|
|
lpszSrc += 2; /* Skip .\ */
|
|
|
|
}
|
|
|
|
else if (lpszSrc[1] == '.' && (lpszDst == lpszBuf || lpszDst[-1] == '\\'))
|
|
|
|
{
|
|
|
|
/* \.. backs up a directory, over the root if it has no \ following X:.
|
|
|
|
* .. is ignored if it would remove a UNC server name or inital \\
|
|
|
|
*/
|
|
|
|
if (lpszDst != lpszBuf)
|
|
|
|
{
|
|
|
|
*lpszDst = '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
|
|
|
|
if (lpszDst > lpszBuf+1 && lpszDst[-1] == '\\' &&
|
|
|
|
(lpszDst[-2] != '\\' || lpszDst > lpszBuf+2))
|
|
|
|
{
|
|
|
|
if (lpszDst[-2] == ':' && (lpszDst > lpszBuf+3 || lpszDst[-3] == ':'))
|
|
|
|
{
|
|
|
|
lpszDst -= 2;
|
|
|
|
while (lpszDst > lpszBuf && *lpszDst != '\\')
|
|
|
|
lpszDst--;
|
|
|
|
if (*lpszDst == '\\')
|
|
|
|
lpszDst++; /* Reset to last '\' */
|
|
|
|
else
|
|
|
|
lpszDst = lpszBuf; /* Start path again from new root */
|
|
|
|
}
|
|
|
|
else if (lpszDst[-2] != ':' && !PathIsUNCServerShareW(lpszBuf))
|
|
|
|
lpszDst -= 2;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
while (lpszDst > lpszBuf && *lpszDst != '\\')
|
|
|
|
lpszDst--;
|
|
|
|
if (lpszDst == lpszBuf)
|
|
|
|
{
|
|
|
|
*lpszDst++ = '\\';
|
|
|
|
lpszSrc++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lpszSrc += 2; /* Skip .. in src path */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*lpszDst++ = *lpszSrc++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*lpszDst++ = *lpszSrc++;
|
|
|
|
}
|
|
|
|
/* Append \ to naked drive specs */
|
|
|
|
if (lpszDst - lpszBuf == 2 && lpszDst[-1] == ':')
|
|
|
|
*lpszDst++ = '\\';
|
|
|
|
*lpszDst++ = '\0';
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathFindNextComponentA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Find the next component in a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to find next component in
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-07-19 05:12:36 +02:00
|
|
|
* Success: A pointer to the next component, or the end of the string.
|
2002-03-20 02:33:19 +01:00
|
|
|
* Failure: NULL, If lpszPath is invalid
|
|
|
|
*
|
2000-07-26 19:51:32 +02:00
|
|
|
* NOTES
|
2002-03-20 02:33:19 +01:00
|
|
|
* A 'component' is either a backslash character (\) or UNC marker (\\).
|
|
|
|
* Because of this, relative paths (e.g "c:foo") are regarded as having
|
|
|
|
* only one component.
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI PathFindNextComponentA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR lpszSlash;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(!lpszPath || !*lpszPath)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((lpszSlash = StrChrA(lpszPath, '\\')))
|
|
|
|
{
|
|
|
|
if (lpszSlash[1] == '\\')
|
|
|
|
lpszSlash++;
|
|
|
|
return lpszSlash + 1;
|
|
|
|
}
|
|
|
|
return (LPSTR)lpszPath + strlen(lpszPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathFindNextComponentW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathFindNextComponentA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR WINAPI PathFindNextComponentW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR lpszSlash;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if(!lpszPath || !*lpszPath)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((lpszSlash = StrChrW(lpszPath, '\\')))
|
|
|
|
{
|
|
|
|
if (lpszSlash[1] == '\\')
|
|
|
|
lpszSlash++;
|
|
|
|
return lpszSlash + 1;
|
|
|
|
}
|
|
|
|
return (LPWSTR)lpszPath + strlenW(lpszPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathAddExtensionA [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Add a file extension to a path
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to add extension to
|
|
|
|
* lpszExtension [I] Extension to add to lpszPath
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If the path was modified,
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
|
2006-03-21 18:24:49 +01:00
|
|
|
* extension already, or the new path length is too big.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* FIXME
|
2003-03-18 19:35:48 +01:00
|
|
|
* What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
|
2002-03-20 02:33:19 +01:00
|
|
|
* does not do this, so the behaviour was removed.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathAddExtensionA(LPSTR lpszPath, LPCSTR lpszExtension)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExtension));
|
|
|
|
|
|
|
|
if (!lpszPath || !lpszExtension || *(PathFindExtensionA(lpszPath)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dwLen = strlen(lpszPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (dwLen + strlen(lpszExtension) >= MAX_PATH)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strcpy(lpszPath + dwLen, lpszExtension);
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathAddExtensionW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathAddExtensionA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathAddExtensionW(LPWSTR lpszPath, LPCWSTR lpszExtension)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExtension));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszPath || !lpszExtension || *(PathFindExtensionW(lpszPath)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dwLen = strlenW(lpszPath);
|
|
|
|
|
|
|
|
if (dwLen + strlenW(lpszExtension) >= MAX_PATH)
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
strcpyW(lpszPath + dwLen, lpszExtension);
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathMakePrettyA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Convert an uppercase DOS filename into lowercase.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to convert.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If the path was an uppercase DOS path and was converted,
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE Otherwise.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathMakePrettyA(LPSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR pszIter = lpszPath;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
2005-03-14 11:09:53 +01:00
|
|
|
if (!pszIter)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2005-03-14 11:09:53 +01:00
|
|
|
if (*pszIter)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2005-03-14 11:09:53 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (islower(*pszIter) || IsDBCSLeadByte(*pszIter))
|
|
|
|
return FALSE; /* Not DOS path */
|
|
|
|
pszIter++;
|
|
|
|
} while (*pszIter);
|
|
|
|
pszIter = lpszPath + 1;
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
|
|
|
*pszIter = tolower(*pszIter);
|
|
|
|
pszIter++;
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathMakePrettyW [SHLWAPI.@]
|
|
|
|
*
|
2003-07-19 05:12:36 +02:00
|
|
|
* See PathMakePrettyA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathMakePrettyW(LPWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR pszIter = lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
2005-03-14 11:09:53 +01:00
|
|
|
if (!pszIter)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2005-03-14 11:09:53 +01:00
|
|
|
if (*pszIter)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2005-03-14 11:09:53 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (islowerW(*pszIter))
|
|
|
|
return FALSE; /* Not DOS path */
|
|
|
|
pszIter++;
|
|
|
|
} while (*pszIter);
|
|
|
|
pszIter = lpszPath + 1;
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
|
|
|
*pszIter = tolowerW(*pszIter);
|
|
|
|
pszIter++;
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCommonPrefixA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine the length of the common prefix between two paths.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-04-02 03:23:43 +02:00
|
|
|
* lpszFile1 [I] First path for comparison
|
|
|
|
* lpszFile2 [I] Second path for comparison
|
2002-03-20 02:33:19 +01:00
|
|
|
* achPath [O] Destination for common prefix string
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The length of the common prefix. This is 0 if there is no common
|
|
|
|
* prefix between the paths or if any parameters are invalid. If the prefix
|
|
|
|
* is non-zero and achPath is not NULL, achPath is filled with the common
|
|
|
|
* part of the prefix and NUL terminated.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* A common prefix of 2 is always returned as 3. It is thus possible for
|
2003-07-19 05:12:36 +02:00
|
|
|
* the length returned to be invalid (i.e. Longer than one or both of the
|
2003-07-02 06:37:26 +02:00
|
|
|
* strings given as parameters). This Win32 behaviour has been implemented
|
2002-03-20 02:33:19 +01:00
|
|
|
* here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
|
|
|
|
* To work around this when using this function, always check that the byte
|
|
|
|
* at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
int WINAPI PathCommonPrefixA(LPCSTR lpszFile1, LPCSTR lpszFile2, LPSTR achPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t iLen = 0;
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCSTR lpszIter1 = lpszFile1;
|
|
|
|
LPCSTR lpszIter2 = lpszFile2;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1), debugstr_a(lpszFile2), achPath);
|
|
|
|
|
|
|
|
if (achPath)
|
|
|
|
*achPath = '\0';
|
|
|
|
|
|
|
|
if (!lpszFile1 || !lpszFile2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Handle roots first */
|
|
|
|
if (PathIsUNCA(lpszFile1))
|
|
|
|
{
|
|
|
|
if (!PathIsUNCA(lpszFile2))
|
|
|
|
return 0;
|
|
|
|
lpszIter1 += 2;
|
|
|
|
lpszIter2 += 2;
|
|
|
|
}
|
|
|
|
else if (PathIsUNCA(lpszFile2))
|
|
|
|
return 0; /* Know already lpszFile1 is not UNC */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Update len */
|
|
|
|
if ((!*lpszIter1 || *lpszIter1 == '\\') &&
|
|
|
|
(!*lpszIter2 || *lpszIter2 == '\\'))
|
|
|
|
iLen = lpszIter1 - lpszFile1; /* Common to this point */
|
|
|
|
|
|
|
|
if (!*lpszIter1 || (tolower(*lpszIter1) != tolower(*lpszIter2)))
|
|
|
|
break; /* Strings differ at this point */
|
|
|
|
|
|
|
|
lpszIter1++;
|
|
|
|
lpszIter2++;
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
if (iLen == 2)
|
2003-05-13 02:41:57 +02:00
|
|
|
iLen++; /* Feature/Bug compatible with Win32 */
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (iLen && achPath)
|
|
|
|
{
|
|
|
|
memcpy(achPath,lpszFile1,iLen);
|
|
|
|
achPath[iLen] = '\0';
|
|
|
|
}
|
|
|
|
return iLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCommonPrefixW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathCommonPrefixA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t iLen = 0;
|
2002-03-20 02:33:19 +01:00
|
|
|
LPCWSTR lpszIter1 = lpszFile1;
|
|
|
|
LPCWSTR lpszIter2 = lpszFile2;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1), debugstr_w(lpszFile2), achPath);
|
|
|
|
|
|
|
|
if (achPath)
|
|
|
|
*achPath = '\0';
|
|
|
|
|
|
|
|
if (!lpszFile1 || !lpszFile2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Handle roots first */
|
|
|
|
if (PathIsUNCW(lpszFile1))
|
|
|
|
{
|
|
|
|
if (!PathIsUNCW(lpszFile2))
|
|
|
|
return 0;
|
|
|
|
lpszIter1 += 2;
|
|
|
|
lpszIter2 += 2;
|
|
|
|
}
|
|
|
|
else if (PathIsUNCW(lpszFile2))
|
|
|
|
return 0; /* Know already lpszFile1 is not UNC */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Update len */
|
|
|
|
if ((!*lpszIter1 || *lpszIter1 == '\\') &&
|
|
|
|
(!*lpszIter2 || *lpszIter2 == '\\'))
|
|
|
|
iLen = lpszIter1 - lpszFile1; /* Common to this point */
|
|
|
|
|
|
|
|
if (!*lpszIter1 || (tolowerW(*lpszIter1) != tolowerW(*lpszIter2)))
|
|
|
|
break; /* Strings differ at this point */
|
|
|
|
|
|
|
|
lpszIter1++;
|
|
|
|
lpszIter2++;
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
if (iLen == 2)
|
2003-05-13 02:41:57 +02:00
|
|
|
iLen++; /* Feature/Bug compatible with Win32 */
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (iLen && achPath)
|
|
|
|
{
|
|
|
|
memcpy(achPath,lpszFile1,iLen * sizeof(WCHAR));
|
|
|
|
achPath[iLen] = '\0';
|
|
|
|
}
|
|
|
|
return iLen;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCompactPathA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Make a path fit into a given width when printed to a DC.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* hDc [I] Destination DC
|
|
|
|
* lpszPath [I/O] Path to be printed to hDc
|
|
|
|
* dx [I] Desired width
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2005-04-18 17:36:20 +02:00
|
|
|
* TRUE If the path was modified/went well.
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE Otherwise.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p,%s,%d)\n", hDC, debugstr_a(lpszPath), dx);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
bRet = PathCompactPathW(hDC, szPath, dx);
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCompactPathW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathCompactPathA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
|
|
|
|
{
|
|
|
|
static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
|
|
|
|
BOOL bRet = TRUE;
|
|
|
|
HDC hdc = 0;
|
|
|
|
WCHAR buff[MAX_PATH];
|
|
|
|
SIZE size;
|
|
|
|
DWORD dwLen;
|
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p,%s,%d)\n", hDC, debugstr_w(lpszPath), dx);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!lpszPath)
|
2005-04-18 17:36:20 +02:00
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!hDC)
|
|
|
|
hdc = hDC = GetDC(0);
|
|
|
|
|
|
|
|
/* Get the length of the whole path */
|
|
|
|
dwLen = strlenW(lpszPath);
|
|
|
|
GetTextExtentPointW(hDC, lpszPath, dwLen, &size);
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if ((UINT)size.cx > dx)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
/* Path too big, must reduce it */
|
|
|
|
LPWSTR sFile;
|
|
|
|
DWORD dwEllipsesLen = 0, dwPathLen = 0;
|
|
|
|
|
|
|
|
sFile = PathFindFileNameW(lpszPath);
|
|
|
|
if (sFile != lpszPath)
|
|
|
|
sFile = CharPrevW(lpszPath, sFile);
|
|
|
|
|
|
|
|
/* Get the size of ellipses */
|
|
|
|
GetTextExtentPointW(hDC, szEllipses, 3, &size);
|
|
|
|
dwEllipsesLen = size.cx;
|
|
|
|
/* Get the size of the file name */
|
|
|
|
GetTextExtentPointW(hDC, sFile, strlenW(sFile), &size);
|
|
|
|
dwPathLen = size.cx;
|
|
|
|
|
|
|
|
if (sFile != lpszPath)
|
|
|
|
{
|
|
|
|
LPWSTR sPath = sFile;
|
|
|
|
BOOL bEllipses = FALSE;
|
|
|
|
|
|
|
|
/* The path includes a file name. Include as much of the path prior to
|
|
|
|
* the file name as possible, allowing for the ellipses, e.g:
|
|
|
|
* c:\some very long path\filename ==> c:\some v...\filename
|
|
|
|
*/
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(buff, sFile, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
DWORD dwTotalLen = bEllipses? dwPathLen + dwEllipsesLen : dwPathLen;
|
|
|
|
|
|
|
|
GetTextExtentPointW(hDC, lpszPath, sPath - lpszPath, &size);
|
|
|
|
dwTotalLen += size.cx;
|
|
|
|
if (dwTotalLen <= dx)
|
|
|
|
break;
|
|
|
|
sPath = CharPrevW(lpszPath, sPath);
|
|
|
|
if (!bEllipses)
|
|
|
|
{
|
|
|
|
bEllipses = TRUE;
|
|
|
|
sPath = CharPrevW(lpszPath, sPath);
|
|
|
|
sPath = CharPrevW(lpszPath, sPath);
|
|
|
|
}
|
|
|
|
} while (sPath > lpszPath);
|
|
|
|
|
|
|
|
if (sPath > lpszPath)
|
|
|
|
{
|
|
|
|
if (bEllipses)
|
|
|
|
{
|
|
|
|
strcpyW(sPath, szEllipses);
|
|
|
|
strcpyW(sPath+3, buff);
|
|
|
|
}
|
2002-11-13 20:43:53 +01:00
|
|
|
bRet = TRUE;
|
|
|
|
goto end;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
strcpyW(lpszPath, szEllipses);
|
|
|
|
strcpyW(lpszPath+3, buff);
|
2002-11-13 20:43:53 +01:00
|
|
|
bRet = FALSE;
|
|
|
|
goto end;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Trim the path by adding ellipses to the end, e.g:
|
|
|
|
* A very long file name.txt ==> A very...
|
|
|
|
*/
|
|
|
|
dwLen = strlenW(lpszPath);
|
|
|
|
|
|
|
|
if (dwLen > MAX_PATH - 3)
|
|
|
|
dwLen = MAX_PATH - 3;
|
2005-04-18 17:36:20 +02:00
|
|
|
lstrcpynW(buff, sFile, dwLen);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
do {
|
|
|
|
dwLen--;
|
|
|
|
GetTextExtentPointW(hDC, buff, dwLen, &size);
|
|
|
|
} while (dwLen && size.cx + dwEllipsesLen > dx);
|
|
|
|
|
|
|
|
if (!dwLen)
|
|
|
|
{
|
|
|
|
DWORD dwWritten = 0;
|
|
|
|
|
|
|
|
dwEllipsesLen /= 3; /* Size of a single '.' */
|
|
|
|
|
|
|
|
/* Write as much of the Ellipses string as possible */
|
|
|
|
while (dwWritten + dwEllipsesLen < dx && dwLen < 3)
|
|
|
|
{
|
|
|
|
*lpszPath++ = '.';
|
|
|
|
dwWritten += dwEllipsesLen;
|
|
|
|
dwLen++;
|
|
|
|
}
|
|
|
|
*lpszPath = '\0';
|
|
|
|
bRet = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpyW(buff + dwLen, szEllipses);
|
|
|
|
strcpyW(lpszPath, buff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-13 20:43:53 +01:00
|
|
|
end:
|
2002-03-20 02:33:19 +01:00
|
|
|
if (hdc)
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
|
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathGetCharTypeA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Categorise a character from a file path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ch [I] Character to get the type of
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
UINT WINAPI PathGetCharTypeA(UCHAR ch)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
return PathGetCharTypeW(ch);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathGetCharTypeW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathGetCharTypeA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
UINT WINAPI PathGetCharTypeW(WCHAR ch)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
UINT flags = 0;
|
|
|
|
|
|
|
|
TRACE("(%d)\n", ch);
|
|
|
|
|
|
|
|
if (!ch || ch < ' ' || ch == '<' || ch == '>' ||
|
2002-07-24 20:58:57 +02:00
|
|
|
ch == '"' || ch == '|' || ch == '/')
|
2002-03-20 02:33:19 +01:00
|
|
|
flags = GCT_INVALID; /* Invalid */
|
|
|
|
else if (ch == '*' || ch=='?')
|
|
|
|
flags = GCT_WILD; /* Wildchars */
|
2002-07-24 20:58:57 +02:00
|
|
|
else if ((ch == '\\') || (ch == ':'))
|
2002-03-20 02:33:19 +01:00
|
|
|
return GCT_SEPARATOR; /* Path separators */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ch < 126)
|
|
|
|
{
|
2002-07-24 20:58:57 +02:00
|
|
|
if ((ch & 0x1 && ch != ';') || !ch || isalnum(ch) || ch == '$' || ch == '&' || ch == '(' ||
|
2002-03-20 02:33:19 +01:00
|
|
|
ch == '.' || ch == '@' || ch == '^' ||
|
|
|
|
ch == '\'' || ch == 130 || ch == '`')
|
|
|
|
flags |= GCT_SHORTCHAR; /* All these are valid for DOS */
|
|
|
|
}
|
|
|
|
else
|
2003-05-13 02:41:57 +02:00
|
|
|
flags |= GCT_SHORTCHAR; /* Bug compatible with win32 */
|
2002-03-20 02:33:19 +01:00
|
|
|
flags |= GCT_LFNCHAR; /* Valid for long file names */
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHLWAPI_UseSystemForSystemFolders
|
|
|
|
*
|
|
|
|
* Internal helper for PathMakeSystemFolderW.
|
|
|
|
*/
|
2005-06-21 22:53:13 +02:00
|
|
|
static BOOL WINAPI SHLWAPI_UseSystemForSystemFolders(void)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
static BOOL bCheckedReg = FALSE;
|
|
|
|
static BOOL bUseSystemForSystemFolders = FALSE;
|
|
|
|
|
|
|
|
if (!bCheckedReg)
|
|
|
|
{
|
|
|
|
bCheckedReg = TRUE;
|
|
|
|
|
|
|
|
/* Key tells Win what file attributes to use on system folders */
|
|
|
|
if (SHGetValueA(HKEY_LOCAL_MACHINE,
|
|
|
|
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
|
|
|
|
"UseSystemForSystemFolders", 0, 0, 0))
|
|
|
|
bUseSystemForSystemFolders = TRUE;
|
|
|
|
}
|
|
|
|
return bUseSystemForSystemFolders;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathMakeSystemFolderA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Set system folder attribute for a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] The path to turn into a system folder
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If the path was changed to/already was a system folder
|
2003-03-18 19:35:48 +01:00
|
|
|
* FALSE If the path is invalid or SetFileAttributesA() fails
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathMakeSystemFolderA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath && *lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
bRet = PathMakeSystemFolderW(szPath);
|
|
|
|
}
|
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathMakeSystemFolderW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathMakeSystemFolderA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathMakeSystemFolderW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwDefaultAttr = FILE_ATTRIBUTE_READONLY, dwAttr;
|
|
|
|
WCHAR buff[MAX_PATH];
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || !*lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-01-06 23:08:33 +01:00
|
|
|
/* If the directory is already a system directory, don't do anything */
|
2002-03-20 02:33:19 +01:00
|
|
|
GetSystemDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!strcmpW(buff, lpszPath))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
GetWindowsDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!strcmpW(buff, lpszPath))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* "UseSystemForSystemFolders" Tells Win what attributes to use */
|
|
|
|
if (SHLWAPI_UseSystemForSystemFolders())
|
|
|
|
dwDefaultAttr = FILE_ATTRIBUTE_SYSTEM;
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Change file attributes to system attributes */
|
|
|
|
dwAttr &= ~(FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_READONLY);
|
|
|
|
return SetFileAttributesW(lpszPath, dwAttr | dwDefaultAttr);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathRenameExtensionA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Swap the file extension in a path with another extension.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to swap the extension in
|
|
|
|
* lpszExt [I] The new extension
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE if lpszPath was modified,
|
|
|
|
* FALSE if lpszPath or lpszExt is NULL, or the new path is too long
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathRenameExtensionA(LPSTR lpszPath, LPCSTR lpszExt)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR lpszExtension;
|
|
|
|
|
|
|
|
TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExt));
|
|
|
|
|
|
|
|
lpszExtension = PathFindExtensionA(lpszPath);
|
2001-12-01 01:37:12 +01:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszExtension || (lpszExtension - lpszPath + strlen(lpszExt) >= MAX_PATH))
|
|
|
|
return FALSE;
|
2001-12-01 01:37:12 +01:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
strcpy(lpszExtension, lpszExt);
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathRenameExtensionW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathRenameExtensionA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathRenameExtensionW(LPWSTR lpszPath, LPCWSTR lpszExt)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR lpszExtension;
|
|
|
|
|
|
|
|
TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExt));
|
|
|
|
|
|
|
|
lpszExtension = PathFindExtensionW(lpszPath);
|
2001-12-01 01:37:12 +01:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!lpszExtension || (lpszExtension - lpszPath + strlenW(lpszExt) >= MAX_PATH))
|
|
|
|
return FALSE;
|
2001-12-01 01:37:12 +01:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
strcpyW(lpszExtension, lpszExt);
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSearchAndQualifyA [SHLWAPI.@]
|
|
|
|
*
|
2002-07-24 20:58:57 +02:00
|
|
|
* Determine if a given path is correct and fully qualified.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2002-07-24 20:58:57 +02:00
|
|
|
* lpszPath [I] Path to check
|
|
|
|
* lpszBuf [O] Output for correct path
|
2002-03-20 02:33:19 +01:00
|
|
|
* cchBuf [I] Size of lpszBuf
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Unknown.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathSearchAndQualifyA(LPCSTR lpszPath, LPSTR lpszBuf, UINT cchBuf)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2004-09-25 02:29:47 +02:00
|
|
|
TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath), lpszBuf, cchBuf);
|
|
|
|
|
|
|
|
if(SearchPathA(NULL, lpszPath, NULL, cchBuf, lpszBuf, NULL))
|
|
|
|
return TRUE;
|
|
|
|
return !!GetFullPathNameA(lpszPath, cchBuf, lpszBuf, NULL);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSearchAndQualifyW [SHLWAPI.@]
|
|
|
|
*
|
2003-07-19 05:12:36 +02:00
|
|
|
* See PathSearchAndQualifyA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathSearchAndQualifyW(LPCWSTR lpszPath, LPWSTR lpszBuf, UINT cchBuf)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2004-09-25 02:29:47 +02:00
|
|
|
TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath), lpszBuf, cchBuf);
|
|
|
|
|
|
|
|
if(SearchPathW(NULL, lpszPath, NULL, cchBuf, lpszBuf, NULL))
|
|
|
|
return TRUE;
|
|
|
|
return !!GetFullPathNameW(lpszPath, cchBuf, lpszBuf, NULL);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSkipRootA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Return the portion of a path following the drive letter or mount point.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] The path to skip on
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A pointer to the next character after the root.
|
2003-03-18 19:35:48 +01:00
|
|
|
* Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR WINAPI PathSkipRootA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || !*lpszPath)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
{
|
|
|
|
/* Network share: skip share server and mount point */
|
|
|
|
lpszPath += 2;
|
|
|
|
if ((lpszPath = StrChrA(lpszPath, '\\')) &&
|
|
|
|
(lpszPath = StrChrA(lpszPath + 1, '\\')))
|
|
|
|
lpszPath++;
|
|
|
|
return (LPSTR)lpszPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsDBCSLeadByte(*lpszPath))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Check x:\ */
|
|
|
|
if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
|
|
|
|
return (LPSTR)lpszPath + 3;
|
|
|
|
return NULL;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSkipRootW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathSkipRootA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR WINAPI PathSkipRootW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || !*lpszPath)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
{
|
|
|
|
/* Network share: skip share server and mount point */
|
|
|
|
lpszPath += 2;
|
|
|
|
if ((lpszPath = StrChrW(lpszPath, '\\')) &&
|
|
|
|
(lpszPath = StrChrW(lpszPath + 1, '\\')))
|
|
|
|
lpszPath++;
|
|
|
|
return (LPWSTR)lpszPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check x:\ */
|
|
|
|
if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
|
|
|
|
return (LPWSTR)lpszPath + 3;
|
|
|
|
return NULL;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCreateFromUrlA [SHLWAPI.@]
|
|
|
|
*
|
2004-10-05 20:07:14 +02:00
|
|
|
* See PathCreateFromUrlW
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI PathCreateFromUrlA(LPCSTR pszUrl, LPSTR pszPath,
|
|
|
|
LPDWORD pcchPath, DWORD dwReserved)
|
|
|
|
{
|
|
|
|
WCHAR bufW[MAX_PATH];
|
|
|
|
WCHAR *pathW = bufW;
|
|
|
|
UNICODE_STRING urlW;
|
|
|
|
HRESULT ret;
|
|
|
|
DWORD lenW = sizeof(bufW)/sizeof(WCHAR), lenA;
|
|
|
|
|
|
|
|
if(!RtlCreateUnicodeStringFromAsciiz(&urlW, pszUrl))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if((ret = PathCreateFromUrlW(urlW.Buffer, pathW, &lenW, dwReserved)) == E_POINTER) {
|
|
|
|
pathW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
|
|
|
|
ret = PathCreateFromUrlW(urlW.Buffer, pathW, &lenW, dwReserved);
|
|
|
|
}
|
|
|
|
if(ret == S_OK) {
|
|
|
|
RtlUnicodeToMultiByteSize(&lenA, pathW, lenW * sizeof(WCHAR));
|
|
|
|
if(*pcchPath > lenA) {
|
|
|
|
RtlUnicodeToMultiByteN(pszPath, *pcchPath - 1, &lenA, pathW, lenW * sizeof(WCHAR));
|
|
|
|
pszPath[lenA] = 0;
|
|
|
|
*pcchPath = lenA;
|
|
|
|
} else {
|
|
|
|
*pcchPath = lenA + 1;
|
|
|
|
ret = E_POINTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pathW != bufW) HeapFree(GetProcessHeap(), 0, pathW);
|
|
|
|
RtlFreeUnicodeString(&urlW);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathCreateFromUrlW [SHLWAPI.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Create a path from a URL
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszUrl [I] URL to convert into a path
|
|
|
|
* lpszPath [O] Output buffer for the resulting Path
|
|
|
|
* pcchPath [I] Length of lpszPath
|
|
|
|
* dwFlags [I] Flags controlling the conversion
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* Success: S_OK. lpszPath contains the URL in path format,
|
2002-03-20 02:33:19 +01:00
|
|
|
* Failure: An HRESULT error code such as E_INVALIDARG.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2004-10-05 20:07:14 +02:00
|
|
|
HRESULT WINAPI PathCreateFromUrlW(LPCWSTR pszUrl, LPWSTR pszPath,
|
|
|
|
LPDWORD pcchPath, DWORD dwReserved)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2004-10-05 20:07:14 +02:00
|
|
|
static const WCHAR file_colon[] = { 'f','i','l','e',':',0 };
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD nslashes = 0;
|
|
|
|
WCHAR *ptr;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl), pszPath, pcchPath, dwReserved);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
if (!pszUrl || !pszPath || !pcchPath || !*pcchPath)
|
|
|
|
return E_INVALIDARG;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
if (strncmpW(pszUrl, file_colon, 5))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
pszUrl += 5;
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
while(*pszUrl == '/' || *pszUrl == '\\') {
|
|
|
|
nslashes++;
|
|
|
|
pszUrl++;
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
if(isalphaW(*pszUrl) && (pszUrl[1] == ':' || pszUrl[1] == '|') && (pszUrl[2] == '/' || pszUrl[2] == '\\'))
|
|
|
|
nslashes = 0;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
switch(nslashes) {
|
|
|
|
case 2:
|
|
|
|
pszUrl -= 2;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pszUrl -= 1;
|
|
|
|
break;
|
|
|
|
}
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
hr = UrlUnescapeW((LPWSTR)pszUrl, pszPath, pcchPath, 0);
|
|
|
|
if(hr != S_OK) return hr;
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
for(ptr = pszPath; *ptr; ptr++)
|
|
|
|
if(*ptr == '/') *ptr = '\\';
|
|
|
|
|
|
|
|
while(*pszPath == '\\')
|
|
|
|
pszPath++;
|
|
|
|
|
|
|
|
if(isalphaW(*pszPath) && pszPath[1] == '|' && pszPath[2] == '\\') /* c|\ -> c:\ */
|
|
|
|
pszPath[1] = ':';
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
if(nslashes == 2 && (ptr = strchrW(pszPath, '\\'))) { /* \\host\c:\ -> \\hostc:\ */
|
|
|
|
ptr++;
|
|
|
|
if(isalphaW(*ptr) && (ptr[1] == ':' || ptr[1] == '|') && ptr[2] == '\\') {
|
|
|
|
memmove(ptr - 1, ptr, (strlenW(ptr) + 1) * sizeof(WCHAR));
|
|
|
|
(*pcchPath)--;
|
|
|
|
}
|
|
|
|
}
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
TRACE("Returning %s\n",debugstr_w(pszPath));
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2004-10-05 20:07:14 +02:00
|
|
|
return hr;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathRelativePathToA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Create a relative path from one path to another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [O] Destination for relative path
|
|
|
|
* lpszFrom [I] Source path
|
|
|
|
* dwAttrFrom [I] File attribute of source path
|
|
|
|
* lpszTo [I] Destination path
|
|
|
|
* dwAttrTo [I] File attributes of destination path
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If a relative path can be formed. lpszPath contains the new path
|
|
|
|
* FALSE If the paths are not relavtive or any parameters are invalid
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpszTo should be at least MAX_PATH in length.
|
2003-03-18 19:35:48 +01:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Calling this function with relative paths for lpszFrom or lpszTo may
|
|
|
|
* give erroneous results.
|
|
|
|
*
|
|
|
|
* The Win32 version of this function contains a bug where the lpszTo string
|
|
|
|
* may be referenced 1 byte beyond the end of the string. As a result random
|
|
|
|
* garbage may be written to the output path, depending on what lies beyond
|
|
|
|
* the last byte of the string. This bug occurs because of the behaviour of
|
2003-03-18 19:35:48 +01:00
|
|
|
* PathCommonPrefix() (see notes for that function), and no workaround seems
|
2002-03-20 02:33:19 +01:00
|
|
|
* possible with Win32.
|
2003-03-18 19:35:48 +01:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* This bug has been fixed here, so for example the relative path from "\\"
|
|
|
|
* to "\\" is correctly determined as "." in this implementation.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathRelativePathToA(LPSTR lpszPath, LPCSTR lpszFrom, DWORD dwAttrFrom,
|
|
|
|
LPCSTR lpszTo, DWORD dwAttrTo)
|
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath, debugstr_a(lpszFrom),
|
2002-03-20 02:33:19 +01:00
|
|
|
dwAttrFrom, debugstr_a(lpszTo), dwAttrTo);
|
|
|
|
|
|
|
|
if(lpszPath && lpszFrom && lpszTo)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WCHAR szFrom[MAX_PATH];
|
|
|
|
WCHAR szTo[MAX_PATH];
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszFrom,-1,szFrom,MAX_PATH);
|
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszTo,-1,szTo,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
bRet = PathRelativePathToW(szPath,szFrom,dwAttrFrom,szTo,dwAttrTo);
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathRelativePathToW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathRelativePathToA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathRelativePathToW(LPWSTR lpszPath, LPCWSTR lpszFrom, DWORD dwAttrFrom,
|
|
|
|
LPCWSTR lpszTo, DWORD dwAttrTo)
|
|
|
|
{
|
|
|
|
static const WCHAR szPrevDirSlash[] = { '.', '.', '\\', '\0' };
|
|
|
|
static const WCHAR szPrevDir[] = { '.', '.', '\0' };
|
|
|
|
WCHAR szFrom[MAX_PATH];
|
|
|
|
WCHAR szTo[MAX_PATH];
|
|
|
|
DWORD dwLen;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath, debugstr_w(lpszFrom),
|
2002-03-20 02:33:19 +01:00
|
|
|
dwAttrFrom, debugstr_w(lpszTo), dwAttrTo);
|
|
|
|
|
|
|
|
if(!lpszPath || !lpszFrom || !lpszTo)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*lpszPath = '\0';
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(szFrom, lpszFrom, MAX_PATH);
|
|
|
|
lstrcpynW(szTo, lpszTo, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
PathRemoveFileSpecW(szFrom);
|
|
|
|
if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
PathRemoveFileSpecW(szTo);
|
|
|
|
|
|
|
|
/* Paths can only be relative if they have a common root */
|
|
|
|
if(!(dwLen = PathCommonPrefixW(szFrom, szTo, 0)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Strip off lpszFrom components to the root, by adding "..\" */
|
|
|
|
lpszFrom = szFrom + dwLen;
|
|
|
|
if (!*lpszFrom)
|
|
|
|
{
|
|
|
|
lpszPath[0] = '.';
|
|
|
|
lpszPath[1] = '\0';
|
|
|
|
}
|
|
|
|
if (*lpszFrom == '\\')
|
|
|
|
lpszFrom++;
|
|
|
|
|
|
|
|
while (*lpszFrom)
|
|
|
|
{
|
|
|
|
lpszFrom = PathFindNextComponentW(lpszFrom);
|
|
|
|
strcatW(lpszPath, *lpszFrom ? szPrevDirSlash : szPrevDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* From the root add the components of lpszTo */
|
|
|
|
lpszTo += dwLen;
|
|
|
|
/* We check lpszTo[-1] to avoid skipping end of string. See the notes for
|
|
|
|
* this function.
|
|
|
|
*/
|
|
|
|
if (*lpszTo && lpszTo[-1])
|
|
|
|
{
|
|
|
|
if (*lpszTo != '\\')
|
|
|
|
lpszTo--;
|
|
|
|
dwLen = strlenW(lpszPath);
|
|
|
|
if (dwLen + strlenW(lpszTo) >= MAX_PATH)
|
|
|
|
{
|
|
|
|
*lpszPath = '\0';
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
strcpyW(lpszPath + dwLen, lpszTo);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUnmakeSystemFolderA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Remove the system folder attributes from a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] The path to remove attributes from
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
|
2003-03-18 19:35:48 +01:00
|
|
|
* SetFileAttributesA() fails.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathUnmakeSystemFolderA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwAttr;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
|
2002-03-20 02:33:19 +01:00
|
|
|
!(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
|
|
|
|
return SetFileAttributesA(lpszPath, dwAttr);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathUnmakeSystemFolderW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathUnmakeSystemFolderA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathUnmakeSystemFolderW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwAttr;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
|
2002-03-20 02:33:19 +01:00
|
|
|
!(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
|
|
|
|
return SetFileAttributesW(lpszPath, dwAttr);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSetDlgItemPathA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Set the text of a dialog item to a path, shrinking the path to fit
|
|
|
|
* if it is too big for the item.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hDlg [I] Dialog handle
|
|
|
|
* id [I] ID of item in the dialog
|
|
|
|
* lpszPath [I] Path to set as the items text
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If lpszPath is NULL, a blank string ("") is set (i.e. The previous
|
|
|
|
* window text is erased).
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathSetDlgItemPathA(HWND hDlg, int id, LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_a(lpszPath));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (lpszPath)
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
else
|
|
|
|
szPath[0] = '\0';
|
|
|
|
PathSetDlgItemPathW(hDlg, id, szPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSetDlgItemPathW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathSetDlgItemPathA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathSetDlgItemPathW(HWND hDlg, int id, LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
WCHAR path[MAX_PATH + 1];
|
|
|
|
HWND hwItem;
|
|
|
|
RECT rect;
|
|
|
|
HDC hdc;
|
|
|
|
HGDIOBJ hPrevObj;
|
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_w(lpszPath));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!(hwItem = GetDlgItem(hDlg, id)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (lpszPath)
|
2004-09-02 22:08:57 +02:00
|
|
|
lstrcpynW(path, lpszPath, sizeof(path) / sizeof(WCHAR));
|
2002-03-20 02:33:19 +01:00
|
|
|
else
|
|
|
|
path[0] = '\0';
|
|
|
|
|
|
|
|
GetClientRect(hwItem, &rect);
|
|
|
|
hdc = GetDC(hDlg);
|
|
|
|
hPrevObj = SelectObject(hdc, (HGDIOBJ)SendMessageW(hwItem,WM_GETFONT,0,0));
|
|
|
|
|
|
|
|
if (hPrevObj)
|
|
|
|
{
|
|
|
|
PathCompactPathW(hdc, path, rect.right);
|
|
|
|
SelectObject(hdc, hPrevObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseDC(hDlg, hdc);
|
|
|
|
SetWindowTextW(hwItem, path);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* PathIsNetworkPathA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if the given path is a network path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If lpszPath is a UNC share or mapped network drive, or
|
|
|
|
* FALSE If lpszPath is a local drive or cannot be determined
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsNetworkPathA(LPCSTR lpszPath)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
int dwDriveNum;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
return TRUE;
|
|
|
|
dwDriveNum = PathGetDriveNumberA(lpszPath);
|
2003-07-19 05:12:36 +02:00
|
|
|
if (dwDriveNum == -1)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
2002-04-03 04:43:03 +02:00
|
|
|
GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
|
|
|
|
return pIsNetDrive(dwDriveNum);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsNetworkPathW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsNetworkPathA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsNetworkPathW(LPCWSTR lpszPath)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
int dwDriveNum;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
return TRUE;
|
|
|
|
dwDriveNum = PathGetDriveNumberW(lpszPath);
|
2003-07-19 05:12:36 +02:00
|
|
|
if (dwDriveNum == -1)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
2002-04-03 04:43:03 +02:00
|
|
|
GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
|
|
|
|
return pIsNetDrive(dwDriveNum);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsLFNFileSpecA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if the given path is a long file name
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If path is a long file name,
|
2003-07-19 05:12:36 +02:00
|
|
|
* FALSE If path is a valid DOS short file name
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsLFNFileSpecA(LPCSTR lpszPath)
|
|
|
|
{
|
|
|
|
DWORD dwNameLen = 0, dwExtLen = 0;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == ' ')
|
|
|
|
return TRUE; /* DOS names cannot have spaces */
|
|
|
|
if (*lpszPath == '.')
|
|
|
|
{
|
|
|
|
if (dwExtLen)
|
|
|
|
return TRUE; /* DOS names have only one dot */
|
|
|
|
dwExtLen = 1;
|
|
|
|
}
|
|
|
|
else if (dwExtLen)
|
|
|
|
{
|
|
|
|
dwExtLen++;
|
|
|
|
if (dwExtLen > 4)
|
|
|
|
return TRUE; /* DOS extensions are <= 3 chars*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwNameLen++;
|
|
|
|
if (dwNameLen > 8)
|
|
|
|
return TRUE; /* DOS names are <= 8 chars */
|
|
|
|
}
|
|
|
|
lpszPath += IsDBCSLeadByte(*lpszPath) ? 2 : 1;
|
|
|
|
}
|
|
|
|
return FALSE; /* Valid DOS path */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsLFNFileSpecW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsLFNFileSpecA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsLFNFileSpecW(LPCWSTR lpszPath)
|
|
|
|
{
|
|
|
|
DWORD dwNameLen = 0, dwExtLen = 0;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*lpszPath)
|
|
|
|
{
|
|
|
|
if (*lpszPath == ' ')
|
|
|
|
return TRUE; /* DOS names cannot have spaces */
|
|
|
|
if (*lpszPath == '.')
|
|
|
|
{
|
|
|
|
if (dwExtLen)
|
|
|
|
return TRUE; /* DOS names have only one dot */
|
|
|
|
dwExtLen = 1;
|
|
|
|
}
|
|
|
|
else if (dwExtLen)
|
|
|
|
{
|
|
|
|
dwExtLen++;
|
|
|
|
if (dwExtLen > 4)
|
|
|
|
return TRUE; /* DOS extensions are <= 3 chars*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwNameLen++;
|
|
|
|
if (dwNameLen > 8)
|
|
|
|
return TRUE; /* DOS names are <= 8 chars */
|
|
|
|
}
|
|
|
|
lpszPath++;
|
|
|
|
}
|
|
|
|
return FALSE; /* Valid DOS path */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsDirectoryEmptyA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a given directory is empty.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Directory to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If the directory exists and contains no files,
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE Otherwise
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsDirectoryEmptyA(LPCSTR lpszPath)
|
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
bRet = PathIsDirectoryEmptyW(szPath);
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsDirectoryEmptyW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsDirectoryEmptyA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsDirectoryEmptyW(LPCWSTR lpszPath)
|
|
|
|
{
|
|
|
|
static const WCHAR szAllFiles[] = { '*', '.', '*', '\0' };
|
|
|
|
WCHAR szSearch[MAX_PATH];
|
|
|
|
DWORD dwLen;
|
|
|
|
HANDLE hfind;
|
|
|
|
BOOL retVal = FALSE;
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || !PathIsDirectoryW(lpszPath))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(szSearch, lpszPath, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
PathAddBackslashW(szSearch);
|
|
|
|
dwLen = strlenW(szSearch);
|
|
|
|
if (dwLen > MAX_PATH - 4)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strcpyW(szSearch + dwLen, szAllFiles);
|
|
|
|
hfind = FindFirstFileW(szSearch, &find_data);
|
|
|
|
|
|
|
|
if (hfind != INVALID_HANDLE_VALUE &&
|
|
|
|
find_data.cFileName[0] == '.' &&
|
|
|
|
find_data.cFileName[1] == '.')
|
|
|
|
{
|
|
|
|
/* The only directory entry should be the parent */
|
|
|
|
if (!FindNextFileW(hfind, &find_data))
|
|
|
|
retVal = TRUE;
|
|
|
|
FindClose(hfind);
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathFindSuffixArrayA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Find a suffix string in an array of suffix strings
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszSuffix [I] Suffix string to search for
|
|
|
|
* lppszArray [I] Array of suffix strings to search
|
|
|
|
* dwCount [I] Number of elements in lppszArray
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* Success: The index of the position of lpszSuffix in lppszArray
|
|
|
|
* Failure: 0, if any parameters are invalid or lpszSuffix is not found
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
2002-03-20 02:33:19 +01:00
|
|
|
* The search is case sensitive.
|
|
|
|
* The match is made against the end of the suffix string, so for example:
|
2003-03-18 19:35:48 +01:00
|
|
|
* lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2004-01-23 21:57:26 +01:00
|
|
|
LPCSTR WINAPI PathFindSuffixArrayA(LPCSTR lpszSuffix, LPCSTR *lppszArray, int dwCount)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwLen;
|
2002-03-20 02:33:19 +01:00
|
|
|
int dwRet = 0;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix), lppszArray, dwCount);
|
|
|
|
|
|
|
|
if (lpszSuffix && lppszArray && dwCount > 0)
|
|
|
|
{
|
|
|
|
dwLen = strlen(lpszSuffix);
|
|
|
|
|
|
|
|
while (dwRet < dwCount)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwCompareLen = strlen(*lppszArray);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (dwCompareLen < dwLen)
|
|
|
|
{
|
|
|
|
if (!strcmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
|
2004-01-23 21:57:26 +01:00
|
|
|
return *lppszArray; /* Found */
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
dwRet++;
|
|
|
|
lppszArray++;
|
|
|
|
}
|
|
|
|
}
|
2004-01-23 21:57:26 +01:00
|
|
|
return NULL;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindSuffixArrayW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathFindSuffixArrayA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2004-01-23 21:57:26 +01:00
|
|
|
LPCWSTR WINAPI PathFindSuffixArrayW(LPCWSTR lpszSuffix, LPCWSTR *lppszArray, int dwCount)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwLen;
|
2002-03-20 02:33:19 +01:00
|
|
|
int dwRet = 0;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix), lppszArray, dwCount);
|
|
|
|
|
|
|
|
if (lpszSuffix && lppszArray && dwCount > 0)
|
|
|
|
{
|
|
|
|
dwLen = strlenW(lpszSuffix);
|
|
|
|
|
|
|
|
while (dwRet < dwCount)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwCompareLen = strlenW(*lppszArray);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (dwCompareLen < dwLen)
|
|
|
|
{
|
|
|
|
if (!strcmpW(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
|
2004-01-23 21:57:26 +01:00
|
|
|
return *lppszArray; /* Found */
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
dwRet++;
|
|
|
|
lppszArray++;
|
|
|
|
}
|
|
|
|
}
|
2004-01-23 21:57:26 +01:00
|
|
|
return NULL;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUndecorateA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Undecorate a file path
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to remove any decoration from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
2003-03-18 19:35:48 +01:00
|
|
|
* A decorations form is "path[n].ext" where "n" is an optional decimal number.
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
|
|
|
VOID WINAPI PathUndecorateA(LPSTR lpszPath)
|
|
|
|
{
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
LPSTR lpszExt = PathFindExtensionA(lpszPath);
|
|
|
|
if (lpszExt > lpszPath && lpszExt[-1] == ']')
|
|
|
|
{
|
|
|
|
LPSTR lpszSkip = lpszExt - 2;
|
|
|
|
if (*lpszSkip == '[')
|
|
|
|
lpszSkip++; /* [] (no number) */
|
|
|
|
else
|
|
|
|
while (lpszSkip > lpszPath && isdigit(lpszSkip[-1]))
|
|
|
|
lpszSkip--;
|
|
|
|
if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
|
|
|
|
{
|
|
|
|
/* remove the [n] */
|
|
|
|
lpszSkip--;
|
|
|
|
while (*lpszExt)
|
|
|
|
*lpszSkip++ = *lpszExt++;
|
|
|
|
*lpszSkip = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUndecorateW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathUndecorateA.
|
|
|
|
*/
|
|
|
|
VOID WINAPI PathUndecorateW(LPWSTR lpszPath)
|
|
|
|
{
|
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
LPWSTR lpszExt = PathFindExtensionW(lpszPath);
|
|
|
|
if (lpszExt > lpszPath && lpszExt[-1] == ']')
|
|
|
|
{
|
|
|
|
LPWSTR lpszSkip = lpszExt - 2;
|
|
|
|
if (*lpszSkip == '[')
|
|
|
|
lpszSkip++; /* [] (no number) */
|
|
|
|
else
|
|
|
|
while (lpszSkip > lpszPath && isdigitW(lpszSkip[-1]))
|
|
|
|
lpszSkip--;
|
|
|
|
if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
|
|
|
|
{
|
|
|
|
/* remove the [n] */
|
|
|
|
lpszSkip--;
|
|
|
|
while (*lpszExt)
|
|
|
|
*lpszSkip++ = *lpszExt++;
|
|
|
|
*lpszSkip = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
2003-07-19 05:12:36 +02:00
|
|
|
|
2005-01-18 12:39:05 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* PathUnExpandEnvStringsA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Substitute folder names in a path with their corresponding environment
|
|
|
|
* strings.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pszPath [I] Buffer containing the path to unexpand.
|
|
|
|
* pszBuf [O] Buffer to receive the unexpanded path.
|
|
|
|
* cchBuf [I] Size of pszBuf in characters.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathUnExpandEnvStringsA(LPCSTR pszPath, LPSTR pszBuf, UINT cchBuf)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%s,0x%08x)\n", debugstr_a(pszPath), debugstr_a(pszBuf), cchBuf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUnExpandEnvStringsW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Unicode version of PathUnExpandEnvStringsA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathUnExpandEnvStringsW(LPCWSTR pszPath, LPWSTR pszBuf, UINT cchBuf)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%s,0x%08x)\n", debugstr_w(pszPath), debugstr_w(pszBuf), cchBuf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* @ [SHLWAPI.440]
|
2003-07-19 05:12:36 +02:00
|
|
|
*
|
|
|
|
* Find localised or default web content in "%WINDOWS%\web\".
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszFile [I] File name containing content to look for
|
|
|
|
* lpszPath [O] Buffer to contain the full path to the file
|
|
|
|
* dwPathLen [I] Length of lpszPath
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. lpszPath contains the full path to the content.
|
|
|
|
* Failure: E_FAIL. The content does not exist or lpszPath is too short.
|
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI SHGetWebFolderFilePathA(LPCSTR lpszFile, LPSTR lpszPath, DWORD dwPathLen)
|
2003-07-19 05:12:36 +02:00
|
|
|
{
|
|
|
|
WCHAR szFile[MAX_PATH], szPath[MAX_PATH];
|
|
|
|
HRESULT hRet;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%p,%d)\n", lpszFile, lpszPath, dwPathLen);
|
2003-07-19 05:12:36 +02:00
|
|
|
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, szFile, MAX_PATH);
|
2003-07-19 05:12:36 +02:00
|
|
|
szPath[0] = '\0';
|
2003-09-11 04:56:15 +02:00
|
|
|
hRet = SHGetWebFolderFilePathW(szFile, szPath, dwPathLen);
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, szPath, -1, lpszPath, dwPathLen, 0, 0);
|
2003-07-19 05:12:36 +02:00
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* @ [SHLWAPI.441]
|
2003-07-19 05:12:36 +02:00
|
|
|
*
|
2003-09-11 04:56:15 +02:00
|
|
|
* Unicode version of SHGetWebFolderFilePathA.
|
2003-07-19 05:12:36 +02:00
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR lpszFile, LPWSTR lpszPath, DWORD dwPathLen)
|
2003-07-19 05:12:36 +02:00
|
|
|
{
|
|
|
|
static const WCHAR szWeb[] = {'\\','W','e','b','\\','\0'};
|
|
|
|
static const WCHAR szWebMui[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
|
|
|
|
#define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
|
|
|
|
#define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
|
|
|
|
DWORD dwLen, dwFileLen;
|
|
|
|
LANGID lidSystem, lidUser;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile), lpszPath, dwPathLen);
|
2003-07-19 05:12:36 +02:00
|
|
|
|
|
|
|
/* Get base directory for web content */
|
|
|
|
dwLen = GetSystemWindowsDirectoryW(lpszPath, dwPathLen);
|
|
|
|
if (dwLen > 0 && lpszPath[dwLen-1] == '\\')
|
|
|
|
dwLen--;
|
|
|
|
|
|
|
|
dwFileLen = strlenW(lpszFile);
|
|
|
|
|
|
|
|
if (dwLen + dwFileLen + szWebLen >= dwPathLen)
|
|
|
|
return E_FAIL; /* lpszPath too short */
|
|
|
|
|
|
|
|
strcpyW(lpszPath+dwLen, szWeb);
|
|
|
|
dwLen += szWebLen;
|
|
|
|
dwPathLen = dwPathLen - dwLen; /* Remaining space */
|
|
|
|
|
|
|
|
lidSystem = GetSystemDefaultUILanguage();
|
|
|
|
lidUser = GetUserDefaultUILanguage();
|
|
|
|
|
|
|
|
if (lidSystem != lidUser)
|
|
|
|
{
|
|
|
|
if (dwFileLen + szWebMuiLen < dwPathLen)
|
|
|
|
{
|
|
|
|
/* Use localised content in the users UI language if present */
|
|
|
|
wsprintfW(lpszPath + dwLen, szWebMui, lidUser);
|
|
|
|
strcpyW(lpszPath + dwLen + szWebMuiLen, lpszFile);
|
|
|
|
if (PathFileExistsW(lpszPath))
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall back to OS default installed content */
|
|
|
|
strcpyW(lpszPath + dwLen, lpszFile);
|
|
|
|
if (PathFileExistsW(lpszPath))
|
|
|
|
return S_OK;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2005-02-03 14:34:05 +01:00
|
|
|
|
|
|
|
#define PATH_CHAR_CLASS_LETTER 0x00000001
|
|
|
|
#define PATH_CHAR_CLASS_ASTERIX 0x00000002
|
|
|
|
#define PATH_CHAR_CLASS_DOT 0x00000004
|
|
|
|
#define PATH_CHAR_CLASS_BACKSLASH 0x00000008
|
|
|
|
#define PATH_CHAR_CLASS_COLON 0x00000010
|
|
|
|
#define PATH_CHAR_CLASS_SEMICOLON 0x00000020
|
|
|
|
#define PATH_CHAR_CLASS_COMMA 0x00000040
|
|
|
|
#define PATH_CHAR_CLASS_SPACE 0x00000080
|
|
|
|
#define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
|
|
|
|
#define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
|
|
|
|
|
|
|
|
#define PATH_CHAR_CLASS_INVALID 0x00000000
|
|
|
|
#define PATH_CHAR_CLASS_ANY 0xffffffff
|
|
|
|
|
|
|
|
static const DWORD SHELL_charclass[] =
|
|
|
|
{
|
|
|
|
/* 0x00 */ PATH_CHAR_CLASS_INVALID, /* 0x01 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x02 */ PATH_CHAR_CLASS_INVALID, /* 0x03 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x04 */ PATH_CHAR_CLASS_INVALID, /* 0x05 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x06 */ PATH_CHAR_CLASS_INVALID, /* 0x07 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x08 */ PATH_CHAR_CLASS_INVALID, /* 0x09 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x0a */ PATH_CHAR_CLASS_INVALID, /* 0x0b */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x0c */ PATH_CHAR_CLASS_INVALID, /* 0x0d */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x0e */ PATH_CHAR_CLASS_INVALID, /* 0x0f */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x10 */ PATH_CHAR_CLASS_INVALID, /* 0x11 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x12 */ PATH_CHAR_CLASS_INVALID, /* 0x13 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x14 */ PATH_CHAR_CLASS_INVALID, /* 0x15 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x16 */ PATH_CHAR_CLASS_INVALID, /* 0x17 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x18 */ PATH_CHAR_CLASS_INVALID, /* 0x19 */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x1a */ PATH_CHAR_CLASS_INVALID, /* 0x1b */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x1c */ PATH_CHAR_CLASS_INVALID, /* 0x1d */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* 0x1e */ PATH_CHAR_CLASS_INVALID, /* 0x1f */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* ' ' */ PATH_CHAR_CLASS_SPACE, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '$' */ PATH_CHAR_CLASS_OTHER_VALID, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '&' */ PATH_CHAR_CLASS_OTHER_VALID, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '(' */ PATH_CHAR_CLASS_OTHER_VALID, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '*' */ PATH_CHAR_CLASS_ASTERIX, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* ',' */ PATH_CHAR_CLASS_COMMA, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '.' */ PATH_CHAR_CLASS_DOT, /* '/' */ PATH_CHAR_CLASS_INVALID,
|
|
|
|
/* '0' */ PATH_CHAR_CLASS_OTHER_VALID, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '2' */ PATH_CHAR_CLASS_OTHER_VALID, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '4' */ PATH_CHAR_CLASS_OTHER_VALID, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '6' */ PATH_CHAR_CLASS_OTHER_VALID, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '8' */ PATH_CHAR_CLASS_OTHER_VALID, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* ':' */ PATH_CHAR_CLASS_COLON, /* ';' */ PATH_CHAR_CLASS_SEMICOLON,
|
|
|
|
/* '<' */ PATH_CHAR_CLASS_INVALID, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '>' */ PATH_CHAR_CLASS_INVALID, /* '?' */ PATH_CHAR_CLASS_LETTER,
|
|
|
|
/* '@' */ PATH_CHAR_CLASS_OTHER_VALID, /* 'A' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'B' */ PATH_CHAR_CLASS_ANY, /* 'C' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'D' */ PATH_CHAR_CLASS_ANY, /* 'E' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'F' */ PATH_CHAR_CLASS_ANY, /* 'G' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'H' */ PATH_CHAR_CLASS_ANY, /* 'I' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'J' */ PATH_CHAR_CLASS_ANY, /* 'K' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'L' */ PATH_CHAR_CLASS_ANY, /* 'M' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'N' */ PATH_CHAR_CLASS_ANY, /* 'O' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'P' */ PATH_CHAR_CLASS_ANY, /* 'Q' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'R' */ PATH_CHAR_CLASS_ANY, /* 'S' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'T' */ PATH_CHAR_CLASS_ANY, /* 'U' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'V' */ PATH_CHAR_CLASS_ANY, /* 'W' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'X' */ PATH_CHAR_CLASS_ANY, /* 'Y' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'Z' */ PATH_CHAR_CLASS_ANY, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '\\' */ PATH_CHAR_CLASS_BACKSLASH, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '^' */ PATH_CHAR_CLASS_OTHER_VALID, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '`' */ PATH_CHAR_CLASS_OTHER_VALID, /* 'a' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'b' */ PATH_CHAR_CLASS_ANY, /* 'c' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'd' */ PATH_CHAR_CLASS_ANY, /* 'e' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'f' */ PATH_CHAR_CLASS_ANY, /* 'g' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'h' */ PATH_CHAR_CLASS_ANY, /* 'i' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'j' */ PATH_CHAR_CLASS_ANY, /* 'k' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'l' */ PATH_CHAR_CLASS_ANY, /* 'm' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'n' */ PATH_CHAR_CLASS_ANY, /* 'o' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'p' */ PATH_CHAR_CLASS_ANY, /* 'q' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'r' */ PATH_CHAR_CLASS_ANY, /* 's' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 't' */ PATH_CHAR_CLASS_ANY, /* 'u' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'v' */ PATH_CHAR_CLASS_ANY, /* 'w' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'x' */ PATH_CHAR_CLASS_ANY, /* 'y' */ PATH_CHAR_CLASS_ANY,
|
|
|
|
/* 'z' */ PATH_CHAR_CLASS_ANY, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '|' */ PATH_CHAR_CLASS_INVALID, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID,
|
|
|
|
/* '~' */ PATH_CHAR_CLASS_OTHER_VALID
|
|
|
|
};
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.455]
|
|
|
|
*
|
|
|
|
* Check if an ASCII char is of a certain class
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsValidCharA( char c, DWORD class )
|
|
|
|
{
|
|
|
|
if ((unsigned)c > 0x7e)
|
|
|
|
return class & PATH_CHAR_CLASS_OTHER_VALID;
|
|
|
|
|
|
|
|
return class & SHELL_charclass[(unsigned)c];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.456]
|
|
|
|
*
|
|
|
|
* Check if a Unicode char is of a certain class
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsValidCharW( WCHAR c, DWORD class )
|
|
|
|
{
|
|
|
|
if (c > 0x7e)
|
|
|
|
return class & PATH_CHAR_CLASS_OTHER_VALID;
|
|
|
|
|
|
|
|
return class & SHELL_charclass[c];
|
|
|
|
}
|