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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
2001-12-11 01:30:17 +01:00
|
|
|
#include <stdlib.h>
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/unicode.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"
|
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; \
|
|
|
|
if (!(func = (void*)GetProcAddress(SHLWAPI_h##module, name))) return fail; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* DLL handles for late bound calls */
|
|
|
|
extern HMODULE SHLWAPI_hshell32;
|
|
|
|
|
|
|
|
/* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
|
2002-04-03 04:43:03 +02:00
|
|
|
static BOOL (WINAPI *pIsNetDrive)(DWORD);
|
|
|
|
|
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
|
|
|
|
* lpszPath [O] Initial part of path
|
|
|
|
* lpszAppend [I] Path to append
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE. lpszPath contains the newly created path.
|
|
|
|
* Failure: FALSE, if either path is NULL, or PathCombineA fails.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpszAppend must contain at least one backslash ('\') if not NULL.
|
|
|
|
* Because PathCombineA is used to join the paths, the resulting
|
|
|
|
* 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
|
|
|
|
* liszFile [I] File path
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
MultiByteToWideChar(0,0,lpszDir,-1,szDir,MAX_PATH);
|
|
|
|
if (lpszFile)
|
|
|
|
MultiByteToWideChar(0,0,lpszFile,-1,szFile,MAX_PATH);
|
|
|
|
PathCombineW(szDest, lpszDir ? szDir : NULL, lpszFile ? szFile : NULL);
|
|
|
|
WideCharToMultiByte(0,0,szDest,-1,lpszDest,MAX_PATH,0,0);
|
|
|
|
}
|
|
|
|
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))
|
|
|
|
return lpszDest; /* Invalid parameters */
|
|
|
|
|
|
|
|
if (!lpszFile || !*lpszFile)
|
|
|
|
{
|
|
|
|
/* Use dir only */
|
|
|
|
strncpyW(szTemp, lpszDir, MAX_PATH);
|
|
|
|
}
|
|
|
|
else if (!lpszDir || !*lpszDir || !PathIsRelativeW(lpszFile))
|
|
|
|
{
|
|
|
|
if (!lpszDir || !*lpszDir || *lpszFile != '\\' || PathIsUNCW(lpszFile))
|
|
|
|
{
|
|
|
|
/* Use file only */
|
|
|
|
strncpyW(szTemp, lpszFile, MAX_PATH);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bUseBoth = TRUE;
|
|
|
|
bStrip = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bUseBoth = TRUE;
|
|
|
|
|
|
|
|
if (bUseBoth)
|
|
|
|
{
|
|
|
|
strncpyW(szTemp, lpszDir, MAX_PATH);
|
|
|
|
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
|
|
|
|
* lpszPath [O] The path to append a backslash to.
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
int 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
int 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%p,%d)\n", debugstr_a(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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%p,%d)\n",debugstr_w(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
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && lpszPath[1] == ':' &&
|
|
|
|
tolowerW(*lpszPath) >= 'a' && tolowerW(*lpszPath) <= 'z')
|
|
|
|
return tolowerW(*lpszPath) - 'a';
|
|
|
|
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
|
|
|
|
* lpszPath [O] Path to remove the file spec from
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] Path to remove the initial path from
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] the path to reduce
|
|
|
|
*
|
|
|
|
* 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.@]
|
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* Strip space seperated arguments from a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to remove arguments from
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] Path to remove the extension from
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] Path to remove backslash from
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] Path to strip blanks from
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] Path to quote
|
|
|
|
*
|
|
|
|
* 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,' '))
|
|
|
|
{
|
|
|
|
int iLen = strlen(lpszPath) + 1;
|
|
|
|
|
|
|
|
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
|
|
|
|
* lpszPath [O] Path to strip quotes from
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] The path to parse the icon location from.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
2002-09-20 21:41:08 +02:00
|
|
|
* Unicode version of SHLWAPI_3.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-09-20 21:41:08 +02:00
|
|
|
BOOL WINAPI SHLWAPI_4(LPWSTR lpszPath,DWORD dwWhich)
|
2002-03-20 02:33:19 +01: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'} };
|
|
|
|
|
|
|
|
TRACE("(%s,%ld)\n", debugstr_w(lpszPath), dwWhich);
|
|
|
|
|
|
|
|
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;
|
|
|
|
while (dwWhich & 0x1 && iChoose < sizeof(pszExts))
|
|
|
|
{
|
|
|
|
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
|
|
|
|
* lpszPath [O] File to search for
|
|
|
|
* dwWhich [I] Type of executable to search for
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If the file was found. lpszFile contains the file name.
|
|
|
|
* FALSE Otherwise.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpszPath is modified in place and must be at least MAX_PATH in length.
|
|
|
|
* If the function returns FALSE, the path is modified to its orginal state.
|
|
|
|
* 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
|
|
|
|
* users (here through PathFindOnPath) and keeping advanced functionality for
|
|
|
|
* their own developers exclusive use. Monopoly, anyone?
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SHLWAPI_3(LPSTR lpszPath,DWORD dwWhich)
|
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s,%ld)\n", debugstr_a(lpszPath), dwWhich);
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
bRet = SHLWAPI_4(szPath, dwWhich);
|
|
|
|
if (bRet)
|
|
|
|
WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
static WCHAR szSystem[] = { 'S','y','s','t','e','m','\0'};
|
|
|
|
static WCHAR szPath[] = { 'P','A','T','H','\0'};
|
|
|
|
DWORD dwLenPATH;
|
|
|
|
LPCWSTR lpszCurr;
|
|
|
|
WCHAR *lpszPATH;
|
|
|
|
WCHAR buff[MAX_PATH];
|
|
|
|
|
|
|
|
TRACE("(%s,%08lx)\n", debugstr_w(lpszFile), dwWhich);
|
|
|
|
|
|
|
|
/* Try system directories */
|
|
|
|
GetSystemDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!PathAppendW(buff, lpszFile))
|
|
|
|
return FALSE;
|
2002-09-20 21:41:08 +02:00
|
|
|
if (SHLWAPI_4(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;
|
2002-09-20 21:41:08 +02:00
|
|
|
if (SHLWAPI_4(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;
|
2002-09-20 21:41:08 +02:00
|
|
|
if (SHLWAPI_4(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);
|
|
|
|
|
|
|
|
if (!dwLenPATH || !(lpszPATH = malloc((dwLenPATH + 1) * sizeof (WCHAR))))
|
|
|
|
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))
|
|
|
|
return FALSE;
|
2002-09-20 21:41:08 +02:00
|
|
|
if (SHLWAPI_4(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
strcpyW(lpszFile, buff);
|
|
|
|
free(lpszPATH);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(lpszPATH);
|
|
|
|
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
|
|
|
|
* lpszFile [O] File to search for
|
|
|
|
* lppszOtherDirs [I] Other directories to look in
|
|
|
|
* dwWhich [I] Type of executable to search for
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE. The path to the executable is stored in sFile.
|
|
|
|
* Failure: FALSE. The path to the executable is unchanged.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-09-20 21:41:08 +02:00
|
|
|
BOOL WINAPI SHLWAPI_5(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];
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile), lppszOtherDirs, dwWhich);
|
|
|
|
|
|
|
|
if (!lpszFile || !PathIsFileSpecA(lpszFile))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
MultiByteToWideChar(0,0,lpszFile,-1,szFile,MAX_PATH);
|
|
|
|
|
|
|
|
/* Search provided directories first */
|
|
|
|
if (lppszOtherDirs && *lppszOtherDirs)
|
|
|
|
{
|
|
|
|
WCHAR szOther[MAX_PATH];
|
|
|
|
LPCSTR *lpszOtherPath = lppszOtherDirs;
|
|
|
|
|
|
|
|
while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(0,0,*lpszOtherPath,-1,szOther,MAX_PATH);
|
|
|
|
PathCombineW(buff, szOther, szFile);
|
2002-09-20 21:41:08 +02:00
|
|
|
if (SHLWAPI_4(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
WideCharToMultiByte(0,0,buff,-1,lpszFile,MAX_PATH,0,0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
lpszOtherPath++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Not found, try system and path dirs */
|
|
|
|
if (SHLWAPI_PathFindInOtherDirs(szFile, dwWhich))
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(0,0,szFile,-1,lpszFile,MAX_PATH,0,0);
|
|
|
|
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
|
|
|
*
|
2002-09-20 21:41:08 +02:00
|
|
|
* Unicode version of SHLWAPI_5.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-09-20 21:41:08 +02:00
|
|
|
BOOL WINAPI SHLWAPI_6(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];
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile), lppszOtherDirs, dwWhich);
|
|
|
|
|
|
|
|
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);
|
2002-09-20 21:41:08 +02:00
|
|
|
if (SHLWAPI_4(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
|
|
|
|
* lpszFile [O] File to search for
|
|
|
|
* lppszOtherDirs [I] Other directories to look in
|
|
|
|
*
|
|
|
|
* 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);
|
2002-09-20 21:41:08 +02:00
|
|
|
return SHLWAPI_5(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);
|
2002-09-20 21:41:08 +02:00
|
|
|
return SHLWAPI_6(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
|
2002-07-24 20:58:57 +02:00
|
|
|
* cchMax [I[ Maximum size of compacted path
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* Some relative paths will be different when cchMax == 5 or 6. This occurs
|
|
|
|
* because Win32 will insert a \ in the compact filename, even if one is
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest, debugstr_a(lpszPath), cchMax, dwFlags);
|
|
|
|
|
|
|
|
if (lpszPath && lpszDest)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WCHAR szDest[MAX_PATH];
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
szDest[0] = '\0';
|
|
|
|
bRet = PathCompactPathExW(szDest, szPath, cchMax, dwFlags);
|
|
|
|
WideCharToMultiByte(0,0,szDest,-1,lpszDest,MAX_PATH,0,0);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
TRACE("(%p,%s,%d,0x%08lx)\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 */
|
|
|
|
lpszFile--; /* Start compacted filename with the path seperator */
|
|
|
|
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
|
|
|
|
* TRUE If lpszPath is valid and a root path
|
|
|
|
* 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:
|
|
|
|
*
|
|
|
|
* if (PathIsDirectoryA("c:\\windows\\") == TRUE)
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
if (PathIsUNCServerShareA(lpszPath))
|
|
|
|
{
|
|
|
|
FIXME("UNC Server Share not yet supported - FAILING\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if ((dwAttr = GetFileAttributesA(lpszPath)) == -1u)
|
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;
|
|
|
|
|
|
|
|
if (PathIsUNCServerShareW(lpszPath))
|
|
|
|
{
|
|
|
|
FIXME("UNC Server Share not yet supported - FAILING\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if ((dwAttr = GetFileAttributesW(lpszPath)) == -1u)
|
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;
|
|
|
|
|
|
|
|
iPrevErrMode = SetErrorMode(1);
|
|
|
|
dwAttr = GetFileAttributesA(lpszPath);
|
|
|
|
SetErrorMode(iPrevErrMode);
|
2002-07-24 20:58:57 +02:00
|
|
|
return dwAttr == -1u ? FALSE : TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathFileExistsW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01: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;
|
|
|
|
|
|
|
|
iPrevErrMode = SetErrorMode(1);
|
|
|
|
dwAttr = GetFileAttributesW(lpszPath);
|
|
|
|
SetErrorMode(iPrevErrMode);
|
2002-07-24 20:58:57 +02:00
|
|
|
return dwAttr == -1u ? FALSE : TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathMatchSingleMaskA [internal]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2000-07-26 19:51:32 +02:00
|
|
|
* NOTES
|
|
|
|
* internal (used by PathMatchSpec)
|
|
|
|
*/
|
|
|
|
static BOOL PathMatchSingleMaskA(LPCSTR name, LPCSTR mask)
|
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
while (*name && *mask && *mask!=';')
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
if (*mask=='*')
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
do
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
if (PathMatchSingleMaskA(name,mask+1)) return 1; /* try substrings */
|
|
|
|
} while (*name++);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (toupper(*mask)!=toupper(*name) && *mask!='?') return 0;
|
|
|
|
name = CharNextA(name);
|
|
|
|
mask = CharNextA(mask);
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
if (!*name)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
while (*mask=='*') mask++;
|
|
|
|
if (!*mask || *mask==';') return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathMatchSingleMaskW [internal]
|
|
|
|
*/
|
|
|
|
static BOOL PathMatchSingleMaskW(LPCWSTR name, LPCWSTR mask)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
while (*name && *mask && *mask!=';')
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if (*mask=='*')
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
do
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
if (PathMatchSingleMaskW(name,mask+1)) return 1; /* try substrings */
|
|
|
|
} while (*name++);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (toupperW(*mask)!=toupperW(*name) && *mask!='?') return 0;
|
|
|
|
name = CharNextW(name);
|
|
|
|
mask = CharNextW(mask);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!*name)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
while (*mask=='*') mask++;
|
|
|
|
if (!*mask || *mask==';') return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
|
* lpszMask [I} Search mask(s)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If lpszPath is valid and is matched
|
|
|
|
* FALSE Otherwise
|
|
|
|
*
|
2000-07-26 19:51:32 +02:00
|
|
|
* NOTES
|
2002-03-20 02:33:19 +01:00
|
|
|
* Multiple search masks may be given if they are seperated by ";". The
|
|
|
|
* pattern "*.*" is treated specially in that it matches all paths (for
|
|
|
|
* backwards compatability with DOS).
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathMatchSpecA(LPCSTR name, LPCSTR mask)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
TRACE("%s %s\n",name,mask);
|
|
|
|
|
|
|
|
if (!lstrcmpA( mask, "*.*" )) return 1; /* we don't require a period */
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
while (*mask)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
if (PathMatchSingleMaskA(name,mask)) return 1; /* helper function */
|
|
|
|
while (*mask && *mask!=';') mask = CharNextA(mask);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (*mask==';')
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
mask++;
|
|
|
|
while (*mask==' ') mask++; /* masks may be separated by "; " */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathMatchSpecW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* See PathMatchSpecA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathMatchSpecW(LPCWSTR name, LPCWSTR mask)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2000-11-28 23:40:56 +01:00
|
|
|
static const WCHAR stemp[] = { '*','.','*',0 };
|
2000-07-26 19:51:32 +02:00
|
|
|
TRACE("%s %s\n",debugstr_w(name),debugstr_w(mask));
|
|
|
|
|
|
|
|
if (!lstrcmpW( mask, stemp )) return 1; /* we don't require a period */
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
while (*mask)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
if (PathMatchSingleMaskW(name,mask)) return 1; /* helper function */
|
|
|
|
while (*mask && *mask!=';') mask = CharNextW(mask);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (*mask==';')
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
|
|
|
mask++;
|
|
|
|
while (*mask==' ') mask++; /* masks may be separated by "; " */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* 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
|
2002-07-24 20:58:57 +02:00
|
|
|
* lpszPath [I] file to check
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2002-07-24 20:58:57 +02: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
|
|
|
|
* TRUE If lpszPath is a file spec (contains no directories).
|
|
|
|
* 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
|
|
|
|
* lpszPath [i] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If lpszPath has lpszPrefix as its prefix
|
|
|
|
* 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.
|
|
|
|
* 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath), dwAttrib);
|
|
|
|
|
|
|
|
if (lpszPath && *lpszPath)
|
|
|
|
dwAttrib = GetFileAttributesA(lpszPath);
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if (dwAttrib == -1u || !(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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath), dwAttrib);
|
|
|
|
|
|
|
|
if (lpszPath && *lpszPath)
|
|
|
|
dwAttrib = GetFileAttributesW(lpszPath);
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if (dwAttrib == -1u || !(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
|
|
|
|
* Success: TRUE. lpszBuf contains the output path
|
|
|
|
* 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];
|
|
|
|
MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
bRet = PathCanonicalizeW(szBuff, szPath);
|
|
|
|
WideCharToMultiByte(0,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
* Success: A pointer to the next component, or the end of the string
|
|
|
|
* 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
|
|
|
|
* lpszPath [O] Path to add extension to
|
|
|
|
* lpszExtension [I} Extension to add to lpszPath
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If the path was modified
|
|
|
|
* FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
|
|
|
|
* extension allready, or the new path length is too big.
|
|
|
|
*
|
|
|
|
* FIXME
|
|
|
|
* What version of shlwapi.dll adds "exe" if pszExtension is NULL? Win2k
|
|
|
|
* 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD 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
|
|
|
|
* lpszPath [O] Path to convert.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If the path was an uppercase DOS path and was converted
|
|
|
|
* 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));
|
|
|
|
|
|
|
|
if (!pszIter || !*pszIter)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
|
|
|
if (islower(*pszIter) || IsDBCSLeadByte(*pszIter))
|
|
|
|
return FALSE; /* Not DOS path */
|
|
|
|
pszIter++;
|
|
|
|
}
|
|
|
|
pszIter = lpszPath + 1;
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
|
|
|
*pszIter = tolower(*pszIter);
|
|
|
|
pszIter++;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathMakePrettyW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* 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));
|
|
|
|
|
|
|
|
if (!pszIter || !*pszIter)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
|
|
|
if (islowerW(*pszIter))
|
|
|
|
return FALSE; /* Not DOS path */
|
|
|
|
pszIter++;
|
|
|
|
}
|
|
|
|
pszIter = lpszPath + 1;
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
|
|
|
*pszIter = tolowerW(*pszIter);
|
|
|
|
pszIter++;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
* lpszFile1 [I] First path for comparason
|
|
|
|
* lpszFile2 [I] Second path for comparason
|
|
|
|
* 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
|
|
|
|
* the length returned to be invalid (i.e. Longer than one or both of the
|
|
|
|
* strings given as parameters). This Win32 behaviour has been implimented
|
|
|
|
* 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
int iLen = 0;
|
|
|
|
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)
|
|
|
|
iLen++; /* Feature/Bug compatable with Win32 */
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
int iLen = 0;
|
|
|
|
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)
|
|
|
|
iLen++; /* Feature/Bug compatable with Win32 */
|
|
|
|
|
|
|
|
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
|
|
|
|
* hDc [I] Destination DC
|
|
|
|
* lpszPath [O] Path to be printed to hDc
|
|
|
|
* dx [i] Desired width
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE If the path was modified.
|
|
|
|
* 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];
|
|
|
|
MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
bRet = PathCompactPathW(hDC, szPath, dx);
|
|
|
|
WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
return bRet;
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
strncpyW(buff, sFile, MAX_PATH);
|
|
|
|
|
|
|
|
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;
|
|
|
|
strncpyW(buff, sFile, dwLen);
|
|
|
|
|
|
|
|
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
|
|
|
|
* 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
|
2002-07-24 20:58:57 +02:00
|
|
|
flags |= GCT_SHORTCHAR; /* Bug compatable 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.
|
|
|
|
*/
|
|
|
|
static BOOL SHLWAPI_UseSystemForSystemFolders()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
* 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];
|
|
|
|
MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* If the directory is already a system directory, dont do anything */
|
|
|
|
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;
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if ((dwAttr = GetFileAttributesW(lpszPath)) == -1u)
|
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
|
|
|
|
* pszPath [O] Path to swap the extension in
|
|
|
|
* pszExt [I] The new extension
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if pszPath was modified
|
|
|
|
* FALSE if pszPath or pszExt 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath), lpszBuf, cchBuf);
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSearchAndQualifyW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath), lpszBuf, cchBuf);
|
|
|
|
return FALSE;
|
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.
|
|
|
|
* Failure: NULL, if lpszPath is invalid, has no root or is a MB 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.@]
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Success: S_OK. lpszPath contains the URL in path format
|
|
|
|
* Failure: An HRESULT error code such as E_INVALIDARG.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
HRESULT WINAPI PathCreateFromUrlA(LPCSTR lpszUrl, LPSTR lpszPath,
|
|
|
|
LPDWORD pcchPath, DWORD dwFlags)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-12-19 05:16:54 +01:00
|
|
|
LPSTR pszPathPart;
|
|
|
|
TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_a(lpszUrl), lpszPath, pcchPath, dwFlags);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2002-12-19 05:16:54 +01:00
|
|
|
pszPathPart = StrChrA(lpszUrl, ':');
|
|
|
|
if ((((pszPathPart - lpszUrl) == 1) && isalpha(*lpszUrl)) ||
|
|
|
|
!lstrcmpA(lpszUrl, "file:"))
|
|
|
|
{
|
|
|
|
return UrlUnescapeA(pszPathPart, lpszPath, pcchPath, dwFlags);
|
|
|
|
}
|
2002-01-29 03:47:46 +01:00
|
|
|
/* extracts thing prior to : in pszURL and checks against:
|
|
|
|
* https
|
|
|
|
* shell
|
|
|
|
* local
|
|
|
|
* about - if match returns E_INVALIDARG
|
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2002-12-19 05:16:54 +01:00
|
|
|
return E_INVALIDARG;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathCreateFromUrlW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathCreateFromUrlA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
HRESULT WINAPI PathCreateFromUrlW(LPCWSTR lpszUrl, LPWSTR lpszPath,
|
|
|
|
LPDWORD pcchPath, DWORD dwFlags)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-01-09 01:50:17 +01:00
|
|
|
static const WCHAR stemp[] = { 'f','i','l','e',':','/','/',0 };
|
|
|
|
LPWSTR pwszPathPart;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_w(lpszUrl), lpszPath, pcchPath, dwFlags);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2003-01-09 01:50:17 +01:00
|
|
|
/* Path of the form file://... */
|
|
|
|
if (!strncmpW(lpszUrl, stemp, 7))
|
|
|
|
{
|
|
|
|
lpszUrl += 7;
|
|
|
|
}
|
|
|
|
/* Path of the form file:... */
|
|
|
|
else if (!strncmpW(lpszUrl, stemp, 5))
|
|
|
|
{
|
|
|
|
lpszUrl += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure that path is of the form c:... or c|... */
|
|
|
|
if (lpszUrl[1] != ':' && lpszUrl[1] != '|' && isalphaW(*lpszUrl))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = UrlUnescapeW(lpszUrl, lpszPath, pcchPath, dwFlags);
|
|
|
|
if (lpszPath[1] == '|')
|
|
|
|
lpszPath[1] = ':';
|
|
|
|
|
|
|
|
for (pwszPathPart = lpszPath; *pwszPathPart; pwszPathPart++)
|
|
|
|
if (*pwszPathPart == '/')
|
|
|
|
*pwszPathPart = '\\';
|
|
|
|
|
|
|
|
TRACE("Returning %s\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
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.
|
|
|
|
* 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
|
|
|
|
* PathCommonPrefix (see notes for that function), and no workaround seems
|
|
|
|
* possible with Win32.
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_a(lpszFrom),
|
|
|
|
dwAttrFrom, debugstr_a(lpszTo), dwAttrTo);
|
|
|
|
|
|
|
|
if(lpszPath && lpszFrom && lpszTo)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WCHAR szFrom[MAX_PATH];
|
|
|
|
WCHAR szTo[MAX_PATH];
|
|
|
|
MultiByteToWideChar(0,0,lpszFrom,-1,szFrom,MAX_PATH);
|
|
|
|
MultiByteToWideChar(0,0,lpszTo,-1,szTo,MAX_PATH);
|
|
|
|
bRet = PathRelativePathToW(szPath,szFrom,dwAttrFrom,szTo,dwAttrTo);
|
|
|
|
WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_w(lpszFrom),
|
|
|
|
dwAttrFrom, debugstr_w(lpszTo), dwAttrTo);
|
|
|
|
|
|
|
|
if(!lpszPath || !lpszFrom || !lpszTo)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*lpszPath = '\0';
|
|
|
|
strncpyW(szFrom, lpszFrom, MAX_PATH);
|
|
|
|
strncpyW(szTo, lpszTo, MAX_PATH);
|
|
|
|
|
|
|
|
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
|
|
|
|
* 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));
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesA(lpszPath)) == -1u ||
|
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));
|
|
|
|
|
2002-07-24 20:58:57 +02:00
|
|
|
if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesW(lpszPath)) == -1u ||
|
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)
|
|
|
|
MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
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)
|
|
|
|
strncpyW(path, lpszPath, sizeof(path));
|
|
|
|
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
|
|
|
|
* TRUE If path is a UNC share or mapped network drive
|
|
|
|
* FALSE If path is a local drive or cannot be determined
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsNetworkPathA(LPCSTR lpszPath)
|
|
|
|
{
|
|
|
|
DWORD dwDriveNum;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
return TRUE;
|
|
|
|
dwDriveNum = PathGetDriveNumberA(lpszPath);
|
2002-07-24 20:58:57 +02:00
|
|
|
if (dwDriveNum == -1u)
|
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)
|
|
|
|
{
|
|
|
|
DWORD dwDriveNum;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
return TRUE;
|
|
|
|
dwDriveNum = PathGetDriveNumberW(lpszPath);
|
2002-07-24 20:58:57 +02:00
|
|
|
if (dwDriveNum == -1u)
|
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
|
|
|
|
* TRUE If path is a long file name
|
|
|
|
* FALSE If path is a valid DOS 8.3 file name
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
* TRUE If the directory exists and contains no files
|
|
|
|
* FALSE Otherwise
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsDirectoryEmptyA(LPCSTR lpszPath)
|
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
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;
|
|
|
|
|
|
|
|
strncpyW(szSearch, lpszPath, MAX_PATH);
|
|
|
|
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
|
|
|
|
* 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:
|
|
|
|
* lpszSuffix=fooBAR matches BAR, but lpszSuffix=fooBARfoo does not.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
int WINAPI PathFindSuffixArrayA(LPCSTR lpszSuffix, LPCSTR *lppszArray, int dwCount)
|
|
|
|
{
|
|
|
|
DWORD dwLen;
|
|
|
|
int dwRet = 0;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix), lppszArray, dwCount);
|
|
|
|
|
|
|
|
if (lpszSuffix && lppszArray && dwCount > 0)
|
|
|
|
{
|
|
|
|
dwLen = strlen(lpszSuffix);
|
|
|
|
|
|
|
|
while (dwRet < dwCount)
|
|
|
|
{
|
|
|
|
DWORD dwCompareLen = strlen(*lppszArray);
|
|
|
|
if (dwCompareLen < dwLen)
|
|
|
|
{
|
|
|
|
if (!strcmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
|
|
|
|
return dwRet; /* Found */
|
|
|
|
}
|
|
|
|
dwRet++;
|
|
|
|
lppszArray++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
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
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
int WINAPI PathFindSuffixArrayW(LPCWSTR lpszSuffix, LPCWSTR *lppszArray, int dwCount)
|
|
|
|
{
|
|
|
|
DWORD dwLen;
|
|
|
|
int dwRet = 0;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix), lppszArray, dwCount);
|
|
|
|
|
|
|
|
if (lpszSuffix && lppszArray && dwCount > 0)
|
|
|
|
{
|
|
|
|
dwLen = strlenW(lpszSuffix);
|
|
|
|
|
|
|
|
while (dwRet < dwCount)
|
|
|
|
{
|
|
|
|
DWORD dwCompareLen = strlenW(*lppszArray);
|
|
|
|
if (dwCompareLen < dwLen)
|
|
|
|
{
|
|
|
|
if (!strcmpW(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
|
|
|
|
return dwRet; /* Found */
|
|
|
|
}
|
|
|
|
dwRet++;
|
|
|
|
lppszArray++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUndecorateA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Undecorate a file path
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [O] Path to undecorate
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* A decorations form is "path[n].ext" where n is an optional decimal number.
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|