2000-07-26 19:51:32 +02:00
|
|
|
/*
|
|
|
|
* Path Functions
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 1999, 2000 Juergen Schmied
|
2002-03-20 02:33:19 +01:00
|
|
|
* Copyright 2001, 2002 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-07-26 19:51:32 +02:00
|
|
|
#include <string.h>
|
2001-12-11 01:30:17 +01:00
|
|
|
#include <stdlib.h>
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2001-01-07 22:50:52 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "winreg.h"
|
2004-10-05 20:07:14 +02:00
|
|
|
#include "winternl.h"
|
2001-12-11 01:30:17 +01:00
|
|
|
#define NO_SHLWAPI_STREAM
|
2000-07-26 19:51:32 +02:00
|
|
|
#include "shlwapi.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-01-07 22:50:52 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-09-20 21:41:08 +02:00
|
|
|
/* Get a function pointer from a DLL handle */
|
|
|
|
#define GET_FUNC(func, module, name, fail) \
|
|
|
|
do { \
|
|
|
|
if (!func) { \
|
|
|
|
if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
|
2003-07-19 05:12:36 +02:00
|
|
|
func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
|
|
|
|
if (!func) return fail; \
|
2002-09-20 21:41:08 +02:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* DLL handles for late bound calls */
|
2007-03-28 13:13:54 +02:00
|
|
|
static HMODULE SHLWAPI_hshell32;
|
2002-09-20 21:41:08 +02:00
|
|
|
|
|
|
|
/* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
|
2003-07-19 05:12:36 +02:00
|
|
|
typedef BOOL (WINAPI *fnpIsNetDrive)(int);
|
|
|
|
static fnpIsNetDrive pIsNetDrive;
|
|
|
|
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR,LPWSTR,DWORD);
|
2002-04-03 04:43:03 +02:00
|
|
|
|
2013-11-04 10:39:09 +01:00
|
|
|
static inline WCHAR* heap_strdupAtoW(LPCSTR str)
|
|
|
|
{
|
|
|
|
WCHAR *ret = NULL;
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
if (ret)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathBuildRootA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Create a root drive string (e.g. "A:\") from a drive number.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [O] Destination for the drive string
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* lpszPath
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPSTR WINAPI PathBuildRootA(LPSTR lpszPath, int drive)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
TRACE("(%p,%d)\n", lpszPath, drive);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && drive >= 0 && drive < 26)
|
|
|
|
{
|
|
|
|
lpszPath[0] = 'A' + drive;
|
|
|
|
lpszPath[1] = ':';
|
|
|
|
lpszPath[2] = '\\';
|
|
|
|
lpszPath[3] = '\0';
|
|
|
|
}
|
|
|
|
return lpszPath;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathBuildRootW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathBuildRootA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
LPWSTR WINAPI PathBuildRootW(LPWSTR lpszPath, int drive)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
TRACE("(%p,%d)\n", lpszPath, drive);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath && drive >= 0 && drive < 26)
|
|
|
|
{
|
|
|
|
lpszPath[0] = 'A' + drive;
|
|
|
|
lpszPath[1] = ':';
|
|
|
|
lpszPath[2] = '\\';
|
|
|
|
lpszPath[3] = '\0';
|
|
|
|
}
|
|
|
|
return lpszPath;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathRemoveArgsA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Strip space separated arguments from a path.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I/O] Path to remove arguments from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* Nothing.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
void WINAPI PathRemoveArgsA(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
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if(lpszPath)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
LPSTR lpszArgs = PathGetArgsA(lpszPath);
|
|
|
|
if (*lpszArgs)
|
|
|
|
lpszArgs[-1] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPSTR lpszLastChar = CharPrevA(lpszPath, lpszArgs);
|
|
|
|
if(*lpszLastChar == ' ')
|
|
|
|
*lpszLastChar = '\0';
|
|
|
|
}
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathRemoveArgsW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathRemoveArgsA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if(lpszPath)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
LPWSTR lpszArgs = PathGetArgsW(lpszPath);
|
|
|
|
if (*lpszArgs || (lpszArgs > lpszPath && lpszArgs[-1] == ' '))
|
|
|
|
lpszArgs[-1] = '\0';
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* @ [SHLWAPI.4]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Unicode version of PathFileExistsDefExtA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFileExistsDefExtW(LPWSTR lpszPath,DWORD dwWhich)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
static const WCHAR pszExts[][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} };
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%d)\n", debugstr_w(lpszPath), dwWhich);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath || PathIsUNCServerW(lpszPath) || PathIsUNCServerShareW(lpszPath))
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwWhich)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
LPCWSTR szExt = PathFindExtensionW(lpszPath);
|
|
|
|
if (!*szExt || dwWhich & 0x40)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
size_t iChoose = 0;
|
|
|
|
int iLen = lstrlenW(lpszPath);
|
|
|
|
if (iLen > (MAX_PATH - 5))
|
|
|
|
return FALSE;
|
|
|
|
while ( (dwWhich & 0x1) && pszExts[iChoose][0] )
|
|
|
|
{
|
|
|
|
lstrcpyW(lpszPath + iLen, pszExts[iChoose]);
|
|
|
|
if (PathFileExistsW(lpszPath))
|
|
|
|
return TRUE;
|
|
|
|
iChoose++;
|
|
|
|
dwWhich >>= 1;
|
|
|
|
}
|
|
|
|
*(lpszPath + iLen) = (WCHAR)'\0';
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
return PathFileExistsW(lpszPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* @ [SHLWAPI.3]
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Determine if a file exists locally and is of an executable type.
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2002-03-20 02:33:19 +01:00
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I/O] File to search for
|
|
|
|
* dwWhich [I] Type of executable to search for
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* TRUE If the file was found. lpszPath contains the file name.
|
|
|
|
* FALSE Otherwise.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2019-06-20 09:12:37 +02:00
|
|
|
* 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 original 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 PathFindOnPathA()) and keeping advanced functionality for
|
|
|
|
* their own developers exclusive use. Monopoly, anyone?
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFileExistsDefExtA(LPSTR lpszPath,DWORD dwWhich)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL bRet = FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%d)\n", debugstr_a(lpszPath), dwWhich);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
if (lpszPath)
|
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
bRet = PathFileExistsDefExtW(szPath, dwWhich);
|
|
|
|
if (bRet)
|
|
|
|
WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* SHLWAPI_PathFindInOtherDirs
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Internal helper for SHLWAPI_PathFindOnPathExA/W.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
static BOOL SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile, DWORD dwWhich)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
static const WCHAR szSystem[] = { 'S','y','s','t','e','m','\0'};
|
|
|
|
static const WCHAR szPath[] = { 'P','A','T','H','\0'};
|
|
|
|
DWORD dwLenPATH;
|
|
|
|
LPCWSTR lpszCurr;
|
|
|
|
WCHAR *lpszPATH;
|
|
|
|
WCHAR buff[MAX_PATH];
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%08x)\n", debugstr_w(lpszFile), dwWhich);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Try system directories */
|
|
|
|
GetSystemDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!PathAppendW(buff, lpszFile))
|
|
|
|
return FALSE;
|
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszFile, buff);
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
GetWindowsDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!PathAppendW(buff, szSystem ) || !PathAppendW(buff, lpszFile))
|
|
|
|
return FALSE;
|
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszFile, buff);
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
GetWindowsDirectoryW(buff, MAX_PATH);
|
|
|
|
if (!PathAppendW(buff, lpszFile))
|
|
|
|
return FALSE;
|
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszFile, buff);
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* Try dirs listed in %PATH% */
|
|
|
|
dwLenPATH = GetEnvironmentVariableW(szPath, buff, MAX_PATH);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!dwLenPATH || !(lpszPATH = HeapAlloc(GetProcessHeap(), 0, (dwLenPATH + 1) * sizeof (WCHAR))))
|
|
|
|
return FALSE;
|
2017-10-09 23:57:53 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
GetEnvironmentVariableW(szPath, lpszPATH, dwLenPATH + 1);
|
|
|
|
lpszCurr = lpszPATH;
|
|
|
|
while (lpszCurr)
|
|
|
|
{
|
|
|
|
LPCWSTR lpszEnd = lpszCurr;
|
|
|
|
LPWSTR pBuff = buff;
|
2017-10-09 23:57:53 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
while (*lpszEnd == ' ')
|
|
|
|
lpszEnd++;
|
|
|
|
while (*lpszEnd && *lpszEnd != ';')
|
|
|
|
*pBuff++ = *lpszEnd++;
|
|
|
|
*pBuff = '\0';
|
2017-10-09 23:57:53 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (*lpszEnd)
|
|
|
|
lpszCurr = lpszEnd + 1;
|
|
|
|
else
|
|
|
|
lpszCurr = NULL; /* Last Path, terminate after this */
|
2017-10-09 23:57:53 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!PathAppendW(buff, lpszFile))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszFile, buff);
|
2019-06-20 09:12:37 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszPATH);
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* @ [SHLWAPI.5]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Search a range of paths for a specific type of executable.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszFile [I/O] File to search for
|
|
|
|
* lppszOtherDirs [I] Other directories to look in
|
|
|
|
* dwWhich [I] Type of executable to search for
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* 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
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFindOnPathExA(LPSTR lpszFile,LPCSTR *lppszOtherDirs,DWORD dwWhich)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WCHAR szFile[MAX_PATH];
|
|
|
|
WCHAR buff[MAX_PATH];
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile), lppszOtherDirs, dwWhich);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszFile || !PathIsFileSpecA(lpszFile))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszFile,-1,szFile,MAX_PATH);
|
|
|
|
|
|
|
|
/* Search provided directories first */
|
|
|
|
if (lppszOtherDirs && *lppszOtherDirs)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WCHAR szOther[MAX_PATH];
|
|
|
|
LPCSTR *lpszOtherPath = lppszOtherDirs;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,*lpszOtherPath,-1,szOther,MAX_PATH);
|
|
|
|
PathCombineW(buff, szOther, szFile);
|
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WideCharToMultiByte(CP_ACP,0,buff,-1,lpszFile,MAX_PATH,0,0);
|
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
lpszOtherPath++;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Not found, try system and path dirs */
|
|
|
|
if (SHLWAPI_PathFindInOtherDirs(szFile, dwWhich))
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP,0,szFile,-1,lpszFile,MAX_PATH,0,0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* @ [SHLWAPI.6]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Unicode version of PathFindOnPathExA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile,LPCWSTR *lppszOtherDirs,DWORD dwWhich)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WCHAR buff[MAX_PATH];
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile), lppszOtherDirs, dwWhich);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszFile || !PathIsFileSpecW(lpszFile))
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Search provided directories first */
|
|
|
|
if (lppszOtherDirs && *lppszOtherDirs)
|
|
|
|
{
|
|
|
|
LPCWSTR *lpszOtherPath = lppszOtherDirs;
|
|
|
|
while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
PathCombineW(buff, *lpszOtherPath, lpszFile);
|
|
|
|
if (PathFileExistsDefExtW(buff, dwWhich))
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszFile, buff);
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
lpszOtherPath++;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Not found, try system and path dirs */
|
|
|
|
return SHLWAPI_PathFindInOtherDirs(lpszFile, dwWhich);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathFindOnPathA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Search a range of paths for an executable.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszFile [I/O] File to search for
|
|
|
|
* lppszOtherDirs [I] Other directories to look in
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* 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
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFindOnPathA(LPSTR lpszFile, LPCSTR *lppszOtherDirs)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%p)\n", debugstr_a(lpszFile), lppszOtherDirs);
|
|
|
|
return PathFindOnPathExA(lpszFile, lppszOtherDirs, 0);
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathFindOnPathW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathFindOnPathA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFindOnPathW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%p)\n", debugstr_w(lpszFile), lppszOtherDirs);
|
|
|
|
return PathFindOnPathExW(lpszFile,lppszOtherDirs, 0);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathCompactPathExA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Compact a path into a given number of characters.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszDest [O] Destination for compacted path
|
|
|
|
* lpszPath [I] Source path
|
|
|
|
* cchMax [I] Maximum size of compacted path
|
|
|
|
* dwFlags [I] Reserved
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* Success: TRUE. The compacted path is written to lpszDest.
|
|
|
|
* Failure: FALSE. lpszPath is undefined.
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* NOTES
|
|
|
|
* If cchMax is given as 0, lpszDest will still be NUL terminated.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* The Win32 version of this function contains a bug: When cchMax == 7,
|
|
|
|
* 8 bytes will be written to lpszDest. This bug is fixed in the Wine
|
|
|
|
* implementation.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Some relative paths will be different when cchMax == 5 or 6. This occurs
|
|
|
|
* because Win32 will insert a "\" in lpszDest, even if one is
|
|
|
|
* not present in the original path.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathCompactPathExA(LPSTR lpszDest, LPCSTR lpszPath,
|
|
|
|
UINT cchMax, DWORD dwFlags)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL bRet = FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%p,%s,%d,0x%08x)\n", lpszDest, debugstr_a(lpszPath), cchMax, dwFlags);
|
|
|
|
|
|
|
|
if (lpszPath && lpszDest)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WCHAR szDest[MAX_PATH];
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
szDest[0] = '\0';
|
|
|
|
bRet = PathCompactPathExW(szDest, szPath, cchMax, dwFlags);
|
|
|
|
WideCharToMultiByte(CP_ACP,0,szDest,-1,lpszDest,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathCompactPathExW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathCompactPathExA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathCompactPathExW(LPWSTR lpszDest, LPCWSTR lpszPath,
|
|
|
|
UINT cchMax, DWORD dwFlags)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
|
|
|
|
LPCWSTR lpszFile;
|
|
|
|
DWORD dwLen, dwFileLen = 0;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%p,%s,%d,0x%08x)\n", lpszDest, debugstr_w(lpszPath), cchMax, dwFlags);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszDest)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WARN("Invalid lpszDest would crash under Win32!\n");
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
*lpszDest = '\0';
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (cchMax < 2)
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
dwLen = lstrlenW(lpszPath) + 1;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwLen < cchMax)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Don't need to compact */
|
|
|
|
memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
|
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Path must be compacted to fit into lpszDest */
|
|
|
|
lpszFile = PathFindFileNameW(lpszPath);
|
|
|
|
dwFileLen = lpszPath + dwLen - lpszFile;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwFileLen == dwLen)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
/* No root in psth */
|
|
|
|
if (cchMax <= 4)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
while (--cchMax > 0) /* No room left for anything but ellipses */
|
|
|
|
*lpszDest++ = '.';
|
|
|
|
*lpszDest = '\0';
|
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Compact the file name with ellipses at the end */
|
|
|
|
cchMax -= 4;
|
|
|
|
memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszDest + cchMax, szEllipses);
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
/* We have a root in the path */
|
|
|
|
lpszFile--; /* Start compacted filename with the path separator */
|
|
|
|
dwFileLen++;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwFileLen + 3 > cchMax)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Compact the file name */
|
|
|
|
if (cchMax <= 4)
|
|
|
|
{
|
|
|
|
while (--cchMax > 0) /* No room left for anything but ellipses */
|
|
|
|
*lpszDest++ = '.';
|
|
|
|
*lpszDest = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszDest, szEllipses);
|
2019-06-20 09:12:37 +02:00
|
|
|
lpszDest += 3;
|
|
|
|
cchMax -= 4;
|
|
|
|
*lpszDest++ = *lpszFile++;
|
|
|
|
if (cchMax <= 4)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
while (--cchMax > 0) /* No room left for anything but ellipses */
|
|
|
|
*lpszDest++ = '.';
|
|
|
|
*lpszDest = '\0';
|
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
cchMax -= 4;
|
|
|
|
memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszDest + cchMax, szEllipses);
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
|
|
|
|
/* Only the root needs to be Compacted */
|
|
|
|
dwLen = cchMax - dwFileLen - 3;
|
|
|
|
memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszDest + dwLen, szEllipses);
|
|
|
|
lstrcpyW(lpszDest + dwLen + 3, lpszFile);
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathIsDirectoryA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Determine if a path is a valid directory
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I] Path to check.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
|
|
|
|
* FALSE if lpszPath is invalid or not a directory.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2000-07-26 19:51:32 +02:00
|
|
|
* NOTES
|
2019-06-20 09:12:37 +02:00
|
|
|
* 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
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathIsDirectoryA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
DWORD dwAttr;
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath || PathIsUNCServerA(lpszPath))
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (PathIsUNCServerShareA(lpszPath))
|
|
|
|
{
|
|
|
|
FIXME("UNC Server Share not yet supported - FAILING\n");
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
|
|
|
|
if ((dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
return FALSE;
|
|
|
|
return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathIsDirectoryW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathIsDirectoryA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
DWORD dwAttr;
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath || PathIsUNCServerW(lpszPath))
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (PathIsUNCServerShareW(lpszPath))
|
|
|
|
{
|
|
|
|
FIXME("UNC Server Share not yet supported - FAILING\n");
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
|
|
|
|
if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
return FALSE;
|
|
|
|
return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathFileExistsAndAttributesA [SHLWAPI.445]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Determine if a file exists.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I] Path to check
|
|
|
|
* dwAttr [O] attributes of file
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* TRUE If the file exists and is readable
|
|
|
|
* FALSE Otherwise
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFileExistsAndAttributesA(LPCSTR lpszPath, DWORD *dwAttr)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
UINT iPrevErrMode;
|
|
|
|
DWORD dwVal = 0;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s %p)\n", debugstr_a(lpszPath), dwAttr);
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwAttr)
|
|
|
|
*dwAttr = INVALID_FILE_ATTRIBUTES;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
|
|
|
dwVal = GetFileAttributesA(lpszPath);
|
|
|
|
SetErrorMode(iPrevErrMode);
|
|
|
|
if (dwAttr)
|
|
|
|
*dwAttr = dwVal;
|
|
|
|
return (dwVal != INVALID_FILE_ATTRIBUTES);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathFileExistsAndAttributesW [SHLWAPI.446]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathFileExistsA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathFileExistsAndAttributesW(LPCWSTR lpszPath, DWORD *dwAttr)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
UINT iPrevErrMode;
|
|
|
|
DWORD dwVal;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s %p)\n", debugstr_w(lpszPath), dwAttr);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
|
|
|
dwVal = GetFileAttributesW(lpszPath);
|
|
|
|
SetErrorMode(iPrevErrMode);
|
|
|
|
if (dwAttr)
|
|
|
|
*dwAttr = dwVal;
|
|
|
|
return (dwVal != INVALID_FILE_ATTRIBUTES);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathIsContentTypeA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Determine if a file is of a given registered content type.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I] File to check
|
|
|
|
* lpszContentType [I] Content type to check for
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* TRUE If lpszPath is a given registered content type,
|
|
|
|
* FALSE Otherwise.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function looks up the registered content type for lpszPath. If
|
|
|
|
* a content type is registered, it is compared (case insensitively) to
|
|
|
|
* lpszContentType. Only if this matches does the function succeed.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathIsContentTypeA(LPCSTR path, LPCSTR content_type)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
char buf[MAX_PATH];
|
|
|
|
DWORD size = sizeof(buf);
|
|
|
|
LPCSTR ext;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%s)\n", debugstr_a(path), debugstr_a(content_type));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if(!path) return FALSE;
|
|
|
|
if(!(ext = PathFindExtensionA(path)) || !*ext) return FALSE;
|
|
|
|
if(SHGetValueA(HKEY_CLASSES_ROOT, ext, "Content Type", NULL, buf, &size)) return FALSE;
|
|
|
|
return !lstrcmpiA(content_type, buf);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathIsContentTypeW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathIsContentTypeA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathIsContentTypeW(LPCWSTR lpszPath, LPCWSTR lpszContentType)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02: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];
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszContentType));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (lpszPath && (szExt = PathFindExtensionW(lpszPath)) && *szExt &&
|
|
|
|
!SHGetValueW(HKEY_CLASSES_ROOT, szExt, szContentType,
|
|
|
|
REG_NONE, szBuff, &dwDummy) &&
|
2019-06-20 09:13:05 +02:00
|
|
|
!wcsicmp(lpszContentType, szBuff))
|
2019-06-20 09:12:37 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
return TRUE;
|
2019-06-20 09:12:37 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathIsSystemFolderA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Determine if a path or file attributes are a system folder.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I] Path to check.
|
|
|
|
* dwAttrib [I] Attributes to check, if lpszPath is NULL.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* 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
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathIsSystemFolderA(LPCSTR lpszPath, DWORD dwAttrib)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath), dwAttrib);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (lpszPath && *lpszPath)
|
|
|
|
dwAttrib = GetFileAttributesA(lpszPath);
|
2001-12-01 01:37:12 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
|
|
|
|
!(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathIsSystemFolderW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathIsSystemFolderA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathIsSystemFolderW(LPCWSTR lpszPath, DWORD dwAttrib)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath), dwAttrib);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (lpszPath && *lpszPath)
|
|
|
|
dwAttrib = GetFileAttributesW(lpszPath);
|
2001-12-01 01:37:12 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
|
|
|
|
!(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathMakePrettyA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Convert an uppercase DOS filename into lowercase.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I/O] Path to convert.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* TRUE If the path was an uppercase DOS path and was converted,
|
|
|
|
* FALSE Otherwise.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathMakePrettyA(LPSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
LPSTR pszIter = lpszPath;
|
2004-09-25 02:29:47 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!pszIter)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (*pszIter)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (islower(*pszIter) || IsDBCSLeadByte(*pszIter))
|
|
|
|
return FALSE; /* Not DOS path */
|
|
|
|
pszIter++;
|
|
|
|
} while (*pszIter);
|
|
|
|
pszIter = lpszPath + 1;
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
|
|
|
*pszIter = tolower(*pszIter);
|
|
|
|
pszIter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathMakePrettyW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathMakePrettyA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathMakePrettyW(LPWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
LPWSTR pszIter = lpszPath;
|
2004-09-25 02:29:47 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!pszIter)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (*pszIter)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
if (iswlower(*pszIter))
|
2019-06-20 09:12:37 +02:00
|
|
|
return FALSE; /* Not DOS path */
|
|
|
|
pszIter++;
|
|
|
|
} while (*pszIter);
|
|
|
|
pszIter = lpszPath + 1;
|
|
|
|
while (*pszIter)
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
*pszIter = towlower(*pszIter);
|
2019-06-20 09:12:37 +02:00
|
|
|
pszIter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathCompactPathA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Make a path fit into a given width when printed to a DC.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* hDc [I] Destination DC
|
|
|
|
* lpszPath [I/O] Path to be printed to hDc
|
|
|
|
* dx [I] Desired width
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* TRUE If the path was modified/went well.
|
|
|
|
* FALSE Otherwise.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL bRet = FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%p,%s,%d)\n", hDC, debugstr_a(lpszPath), dx);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (lpszPath)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
bRet = PathCompactPathW(hDC, szPath, dx);
|
|
|
|
WideCharToMultiByte(CP_ACP,0,szPath,-1,lpszPath,MAX_PATH,0,0);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathCompactPathW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathCompactPathA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
|
|
|
|
BOOL bRet = TRUE;
|
|
|
|
HDC hdc = 0;
|
|
|
|
WCHAR buff[MAX_PATH];
|
|
|
|
SIZE size;
|
|
|
|
DWORD dwLen;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%p,%s,%d)\n", hDC, debugstr_w(lpszPath), dx);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!hDC)
|
|
|
|
hdc = hDC = GetDC(0);
|
|
|
|
|
|
|
|
/* Get the length of the whole path */
|
2019-06-20 09:13:05 +02:00
|
|
|
dwLen = lstrlenW(lpszPath);
|
2019-06-20 09:12:37 +02:00
|
|
|
GetTextExtentPointW(hDC, lpszPath, dwLen, &size);
|
|
|
|
|
|
|
|
if ((UINT)size.cx > dx)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Path too big, must reduce it */
|
|
|
|
LPWSTR sFile;
|
|
|
|
DWORD dwEllipsesLen = 0, dwPathLen = 0;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
sFile = PathFindFileNameW(lpszPath);
|
|
|
|
if (sFile != lpszPath) sFile--;
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Get the size of ellipses */
|
|
|
|
GetTextExtentPointW(hDC, szEllipses, 3, &size);
|
|
|
|
dwEllipsesLen = size.cx;
|
|
|
|
/* Get the size of the file name */
|
2019-06-20 09:13:05 +02:00
|
|
|
GetTextExtentPointW(hDC, sFile, lstrlenW(sFile), &size);
|
2019-06-20 09:12:37 +02:00
|
|
|
dwPathLen = size.cx;
|
2004-10-05 20:07:14 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (sFile != lpszPath)
|
|
|
|
{
|
|
|
|
LPWSTR sPath = sFile;
|
|
|
|
BOOL bEllipses = FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
lstrcpynW(buff, sFile, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
DWORD dwTotalLen = bEllipses? dwPathLen + dwEllipsesLen : dwPathLen;
|
|
|
|
|
|
|
|
GetTextExtentPointW(hDC, lpszPath, sPath - lpszPath, &size);
|
|
|
|
dwTotalLen += size.cx;
|
|
|
|
if (dwTotalLen <= dx)
|
|
|
|
break;
|
|
|
|
sPath--;
|
|
|
|
if (!bEllipses)
|
2012-09-26 04:22:00 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
bEllipses = TRUE;
|
|
|
|
sPath -= 2;
|
2012-09-26 04:22:00 +02:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
} while (sPath > lpszPath);
|
|
|
|
|
|
|
|
if (sPath > lpszPath)
|
|
|
|
{
|
|
|
|
if (bEllipses)
|
2012-09-26 04:22:00 +02:00
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(sPath, szEllipses);
|
|
|
|
lstrcpyW(sPath+3, buff);
|
2012-09-26 04:22:00 +02:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
bRet = TRUE;
|
|
|
|
goto end;
|
|
|
|
}
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszPath, szEllipses);
|
|
|
|
lstrcpyW(lpszPath+3, buff);
|
2019-06-20 09:12:37 +02:00
|
|
|
bRet = FALSE;
|
|
|
|
goto end;
|
2004-10-05 20:07:14 +02:00
|
|
|
}
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Trim the path by adding ellipses to the end, e.g:
|
|
|
|
* A very long file name.txt ==> A very...
|
|
|
|
*/
|
2019-06-20 09:13:05 +02:00
|
|
|
dwLen = lstrlenW(lpszPath);
|
2004-10-05 20:07:14 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (dwLen > MAX_PATH - 3)
|
|
|
|
dwLen = MAX_PATH - 3;
|
|
|
|
lstrcpynW(buff, sFile, dwLen);
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
do {
|
|
|
|
dwLen--;
|
|
|
|
GetTextExtentPointW(hDC, buff, dwLen, &size);
|
|
|
|
} while (dwLen && size.cx + dwEllipsesLen > dx);
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
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
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(buff + dwLen, szEllipses);
|
|
|
|
lstrcpyW(lpszPath, buff);
|
2012-09-26 04:22:00 +02:00
|
|
|
}
|
2019-06-20 09:12:37 +02:00
|
|
|
}
|
2003-01-09 01:50:17 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
end:
|
|
|
|
if (hdc)
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
|
|
|
|
return bRet;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2012-10-01 03:29:55 +02:00
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* SHLWAPI_UseSystemForSystemFolders
|
|
|
|
*
|
|
|
|
* Internal helper for PathMakeSystemFolderW.
|
2012-10-01 03:29:55 +02:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
static BOOL SHLWAPI_UseSystemForSystemFolders(void)
|
2012-10-01 03:29:55 +02:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
static BOOL bCheckedReg = FALSE;
|
|
|
|
static BOOL bUseSystemForSystemFolders = FALSE;
|
2012-10-01 03:29:55 +02:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
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;
|
2012-10-01 03:29:55 +02:00
|
|
|
}
|
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathMakeSystemFolderA [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* Set system folder attribute for a path.
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
2019-06-20 09:12:37 +02:00
|
|
|
* lpszPath [I] The path to turn into a system folder
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2019-06-20 09:12:37 +02:00
|
|
|
* TRUE If the path was changed to/already was a system folder
|
|
|
|
* FALSE If the path is invalid or SetFileAttributesA() fails
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathMakeSystemFolderA(LPCSTR lpszPath)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (lpszPath && *lpszPath)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
2019-06-20 09:12:37 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
|
|
|
bRet = PathMakeSystemFolderW(szPath);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2019-06-20 09:12:37 +02:00
|
|
|
* PathMakeSystemFolderW [SHLWAPI.@]
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
2019-06-20 09:12:37 +02:00
|
|
|
* See PathMakeSystemFolderA.
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
2019-06-20 09:12:37 +02:00
|
|
|
BOOL WINAPI PathMakeSystemFolderW(LPCWSTR lpszPath)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2019-06-20 09:12:37 +02:00
|
|
|
DWORD dwDefaultAttr = FILE_ATTRIBUTE_READONLY, dwAttr;
|
|
|
|
WCHAR buff[MAX_PATH];
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if (!lpszPath || !*lpszPath)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* If the directory is already a system directory, don't do anything */
|
|
|
|
GetSystemDirectoryW(buff, MAX_PATH);
|
2019-06-20 09:13:05 +02:00
|
|
|
if (!wcscmp(buff, lpszPath))
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
GetWindowsDirectoryW(buff, MAX_PATH);
|
2019-06-20 09:13:05 +02:00
|
|
|
if (!wcscmp(buff, lpszPath))
|
2019-06-20 09:12:37 +02:00
|
|
|
return TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* "UseSystemForSystemFolders" Tells Win what attributes to use */
|
|
|
|
if (SHLWAPI_UseSystemForSystemFolders())
|
|
|
|
dwDefaultAttr = FILE_ATTRIBUTE_SYSTEM;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2019-06-20 09:12:37 +02:00
|
|
|
/* Change file attributes to system attributes */
|
|
|
|
dwAttr &= ~(FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_READONLY);
|
|
|
|
return SetFileAttributesW(lpszPath, dwAttr | dwDefaultAttr);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUnmakeSystemFolderA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Remove the system folder attributes from a path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] The path to remove attributes from
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
|
2003-03-18 19:35:48 +01:00
|
|
|
* SetFileAttributesA() fails.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathUnmakeSystemFolderA(LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwAttr;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_a(lpszPath));
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
|
2002-03-20 02:33:19 +01:00
|
|
|
!(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
|
|
|
|
return SetFileAttributesA(lpszPath, dwAttr);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathUnmakeSystemFolderW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathUnmakeSystemFolderA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
BOOL WINAPI PathUnmakeSystemFolderW(LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
DWORD dwAttr;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
2003-07-19 05:12:36 +02:00
|
|
|
if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
|
2002-03-20 02:33:19 +01:00
|
|
|
!(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
|
|
|
|
return SetFileAttributesW(lpszPath, dwAttr);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSetDlgItemPathA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Set the text of a dialog item to a path, shrinking the path to fit
|
|
|
|
* if it is too big for the item.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hDlg [I] Dialog handle
|
|
|
|
* id [I] ID of item in the dialog
|
|
|
|
* lpszPath [I] Path to set as the items text
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If lpszPath is NULL, a blank string ("") is set (i.e. The previous
|
|
|
|
* window text is erased).
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathSetDlgItemPathA(HWND hDlg, int id, LPCSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_a(lpszPath));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (lpszPath)
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
else
|
|
|
|
szPath[0] = '\0';
|
|
|
|
PathSetDlgItemPathW(hDlg, id, szPath);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathSetDlgItemPathW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathSetDlgItemPathA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2002-03-20 02:33:19 +01:00
|
|
|
VOID WINAPI PathSetDlgItemPathW(HWND hDlg, int id, LPCWSTR lpszPath)
|
2000-07-26 19:51:32 +02:00
|
|
|
{
|
2002-03-20 02:33:19 +01:00
|
|
|
WCHAR path[MAX_PATH + 1];
|
|
|
|
HWND hwItem;
|
|
|
|
RECT rect;
|
|
|
|
HDC hdc;
|
|
|
|
HGDIOBJ hPrevObj;
|
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_w(lpszPath));
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
if (!(hwItem = GetDlgItem(hDlg, id)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (lpszPath)
|
2018-09-15 00:10:31 +02:00
|
|
|
lstrcpynW(path, lpszPath, ARRAY_SIZE(path));
|
2002-03-20 02:33:19 +01:00
|
|
|
else
|
|
|
|
path[0] = '\0';
|
|
|
|
|
|
|
|
GetClientRect(hwItem, &rect);
|
|
|
|
hdc = GetDC(hDlg);
|
|
|
|
hPrevObj = SelectObject(hdc, (HGDIOBJ)SendMessageW(hwItem,WM_GETFONT,0,0));
|
|
|
|
|
|
|
|
if (hPrevObj)
|
|
|
|
{
|
|
|
|
PathCompactPathW(hdc, path, rect.right);
|
|
|
|
SelectObject(hdc, hPrevObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseDC(hDlg, hdc);
|
|
|
|
SetWindowTextW(hwItem, path);
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
2002-03-20 02:33:19 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* PathIsNetworkPathA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if the given path is a network path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If lpszPath is a UNC share or mapped network drive, or
|
|
|
|
* FALSE If lpszPath is a local drive or cannot be determined
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsNetworkPathA(LPCSTR lpszPath)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
int dwDriveNum;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
return TRUE;
|
|
|
|
dwDriveNum = PathGetDriveNumberA(lpszPath);
|
2003-07-19 05:12:36 +02:00
|
|
|
if (dwDriveNum == -1)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
2002-04-03 04:43:03 +02:00
|
|
|
GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
|
|
|
|
return pIsNetDrive(dwDriveNum);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathIsNetworkPathW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsNetworkPathA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsNetworkPathW(LPCWSTR lpszPath)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
int dwDriveNum;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath)
|
|
|
|
return FALSE;
|
|
|
|
if (*lpszPath == '\\' && lpszPath[1] == '\\')
|
|
|
|
return TRUE;
|
|
|
|
dwDriveNum = PathGetDriveNumberW(lpszPath);
|
2003-07-19 05:12:36 +02:00
|
|
|
if (dwDriveNum == -1)
|
2002-03-20 02:33:19 +01:00
|
|
|
return FALSE;
|
2002-04-03 04:43:03 +02:00
|
|
|
GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
|
|
|
|
return pIsNetDrive(dwDriveNum);
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsDirectoryEmptyA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Determine if a given directory is empty.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Directory to check
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* TRUE If the directory exists and contains no files,
|
2002-03-20 02:33:19 +01:00
|
|
|
* FALSE Otherwise
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsDirectoryEmptyA(LPCSTR lpszPath)
|
|
|
|
{
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszPath,-1,szPath,MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
bRet = PathIsDirectoryEmptyW(szPath);
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathIsDirectoryEmptyW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathIsDirectoryEmptyA.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PathIsDirectoryEmptyW(LPCWSTR lpszPath)
|
|
|
|
{
|
|
|
|
static const WCHAR szAllFiles[] = { '*', '.', '*', '\0' };
|
|
|
|
WCHAR szSearch[MAX_PATH];
|
|
|
|
DWORD dwLen;
|
|
|
|
HANDLE hfind;
|
2014-09-28 17:30:45 +02:00
|
|
|
BOOL retVal = TRUE;
|
2002-03-20 02:33:19 +01:00
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (!lpszPath || !PathIsDirectoryW(lpszPath))
|
2014-09-28 17:30:45 +02:00
|
|
|
return FALSE;
|
2002-03-20 02:33:19 +01:00
|
|
|
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(szSearch, lpszPath, MAX_PATH);
|
2002-03-20 02:33:19 +01:00
|
|
|
PathAddBackslashW(szSearch);
|
2019-06-20 09:13:05 +02:00
|
|
|
dwLen = lstrlenW(szSearch);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (dwLen > MAX_PATH - 4)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(szSearch + dwLen, szAllFiles);
|
2002-03-20 02:33:19 +01:00
|
|
|
hfind = FindFirstFileW(szSearch, &find_data);
|
2014-09-28 17:30:45 +02:00
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
do
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2014-09-28 17:30:45 +02:00
|
|
|
if (find_data.cFileName[0] == '.')
|
|
|
|
{
|
|
|
|
if (find_data.cFileName[1] == '\0') continue;
|
|
|
|
if (find_data.cFileName[1] == '.' && find_data.cFileName[2] == '\0') continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
retVal = FALSE;
|
|
|
|
break;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
2014-09-28 17:30:45 +02:00
|
|
|
while (FindNextFileW(hfind, &find_data));
|
2014-04-10 07:23:00 +02:00
|
|
|
|
2014-09-28 17:30:45 +02:00
|
|
|
FindClose(hfind);
|
2002-03-20 02:33:19 +01:00
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathFindSuffixArrayA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Find a suffix string in an array of suffix strings
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszSuffix [I] Suffix string to search for
|
|
|
|
* lppszArray [I] Array of suffix strings to search
|
|
|
|
* dwCount [I] Number of elements in lppszArray
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-18 19:35:48 +01:00
|
|
|
* Success: The index of the position of lpszSuffix in lppszArray
|
|
|
|
* Failure: 0, if any parameters are invalid or lpszSuffix is not found
|
2000-07-26 19:51:32 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
2002-03-20 02:33:19 +01:00
|
|
|
* The search is case sensitive.
|
|
|
|
* The match is made against the end of the suffix string, so for example:
|
2003-03-18 19:35:48 +01:00
|
|
|
* lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2004-01-23 21:57:26 +01:00
|
|
|
LPCSTR WINAPI PathFindSuffixArrayA(LPCSTR lpszSuffix, LPCSTR *lppszArray, int dwCount)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwLen;
|
2002-03-20 02:33:19 +01:00
|
|
|
int dwRet = 0;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix), lppszArray, dwCount);
|
|
|
|
|
|
|
|
if (lpszSuffix && lppszArray && dwCount > 0)
|
|
|
|
{
|
|
|
|
dwLen = strlen(lpszSuffix);
|
|
|
|
|
|
|
|
while (dwRet < dwCount)
|
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwCompareLen = strlen(*lppszArray);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (dwCompareLen < dwLen)
|
|
|
|
{
|
|
|
|
if (!strcmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
|
2004-01-23 21:57:26 +01:00
|
|
|
return *lppszArray; /* Found */
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
dwRet++;
|
|
|
|
lppszArray++;
|
|
|
|
}
|
|
|
|
}
|
2004-01-23 21:57:26 +01:00
|
|
|
return NULL;
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-03-20 02:33:19 +01:00
|
|
|
* PathFindSuffixArrayW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathFindSuffixArrayA.
|
2000-07-26 19:51:32 +02:00
|
|
|
*/
|
2004-01-23 21:57:26 +01:00
|
|
|
LPCWSTR WINAPI PathFindSuffixArrayW(LPCWSTR lpszSuffix, LPCWSTR *lppszArray, int dwCount)
|
2002-03-20 02:33:19 +01:00
|
|
|
{
|
2003-07-19 05:12:36 +02:00
|
|
|
size_t dwLen;
|
2002-03-20 02:33:19 +01:00
|
|
|
int dwRet = 0;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix), lppszArray, dwCount);
|
|
|
|
|
|
|
|
if (lpszSuffix && lppszArray && dwCount > 0)
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
dwLen = lstrlenW(lpszSuffix);
|
2002-03-20 02:33:19 +01:00
|
|
|
|
|
|
|
while (dwRet < dwCount)
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
size_t dwCompareLen = lstrlenW(*lppszArray);
|
2002-03-20 02:33:19 +01:00
|
|
|
if (dwCompareLen < dwLen)
|
|
|
|
{
|
2019-06-20 09:13:05 +02:00
|
|
|
if (!wcscmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
|
2004-01-23 21:57:26 +01:00
|
|
|
return *lppszArray; /* Found */
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
dwRet++;
|
|
|
|
lppszArray++;
|
|
|
|
}
|
|
|
|
}
|
2004-01-23 21:57:26 +01:00
|
|
|
return NULL;
|
2002-03-20 02:33:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUndecorateA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Undecorate a file path
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:12:36 +02:00
|
|
|
* lpszPath [I/O] Path to remove any decoration from
|
2002-03-20 02:33:19 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* NOTES
|
2003-03-18 19:35:48 +01:00
|
|
|
* A decorations form is "path[n].ext" where "n" is an optional decimal number.
|
2002-03-20 02:33:19 +01:00
|
|
|
*/
|
|
|
|
VOID WINAPI PathUndecorateA(LPSTR lpszPath)
|
|
|
|
{
|
|
|
|
TRACE("(%s)\n",debugstr_a(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
LPSTR lpszExt = PathFindExtensionA(lpszPath);
|
|
|
|
if (lpszExt > lpszPath && lpszExt[-1] == ']')
|
|
|
|
{
|
|
|
|
LPSTR lpszSkip = lpszExt - 2;
|
|
|
|
if (*lpszSkip == '[')
|
|
|
|
lpszSkip++; /* [] (no number) */
|
|
|
|
else
|
|
|
|
while (lpszSkip > lpszPath && isdigit(lpszSkip[-1]))
|
|
|
|
lpszSkip--;
|
|
|
|
if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
|
|
|
|
{
|
|
|
|
/* remove the [n] */
|
|
|
|
lpszSkip--;
|
|
|
|
while (*lpszExt)
|
|
|
|
*lpszSkip++ = *lpszExt++;
|
|
|
|
*lpszSkip = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* PathUndecorateW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See PathUndecorateA.
|
|
|
|
*/
|
|
|
|
VOID WINAPI PathUndecorateW(LPWSTR lpszPath)
|
|
|
|
{
|
|
|
|
TRACE("(%s)\n",debugstr_w(lpszPath));
|
|
|
|
|
|
|
|
if (lpszPath)
|
|
|
|
{
|
|
|
|
LPWSTR lpszExt = PathFindExtensionW(lpszPath);
|
|
|
|
if (lpszExt > lpszPath && lpszExt[-1] == ']')
|
|
|
|
{
|
|
|
|
LPWSTR lpszSkip = lpszExt - 2;
|
|
|
|
if (*lpszSkip == '[')
|
|
|
|
lpszSkip++; /* [] (no number) */
|
|
|
|
else
|
2019-06-20 09:13:05 +02:00
|
|
|
while (lpszSkip > lpszPath && iswdigit(lpszSkip[-1]))
|
2002-03-20 02:33:19 +01:00
|
|
|
lpszSkip--;
|
|
|
|
if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
|
|
|
|
{
|
|
|
|
/* remove the [n] */
|
|
|
|
lpszSkip--;
|
|
|
|
while (*lpszExt)
|
|
|
|
*lpszSkip++ = *lpszExt++;
|
|
|
|
*lpszSkip = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
}
|
2003-07-19 05:12:36 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* @ [SHLWAPI.440]
|
2003-07-19 05:12:36 +02:00
|
|
|
*
|
|
|
|
* Find localised or default web content in "%WINDOWS%\web\".
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszFile [I] File name containing content to look for
|
|
|
|
* lpszPath [O] Buffer to contain the full path to the file
|
|
|
|
* dwPathLen [I] Length of lpszPath
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. lpszPath contains the full path to the content.
|
|
|
|
* Failure: E_FAIL. The content does not exist or lpszPath is too short.
|
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI SHGetWebFolderFilePathA(LPCSTR lpszFile, LPSTR lpszPath, DWORD dwPathLen)
|
2003-07-19 05:12:36 +02:00
|
|
|
{
|
|
|
|
WCHAR szFile[MAX_PATH], szPath[MAX_PATH];
|
|
|
|
HRESULT hRet;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%p,%d)\n", lpszFile, lpszPath, dwPathLen);
|
2003-07-19 05:12:36 +02:00
|
|
|
|
2004-09-03 00:57:04 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, szFile, MAX_PATH);
|
2003-07-19 05:12:36 +02:00
|
|
|
szPath[0] = '\0';
|
2003-09-11 04:56:15 +02:00
|
|
|
hRet = SHGetWebFolderFilePathW(szFile, szPath, dwPathLen);
|
2004-09-03 00:57:04 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, szPath, -1, lpszPath, dwPathLen, 0, 0);
|
2003-07-19 05:12:36 +02:00
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* @ [SHLWAPI.441]
|
2003-07-19 05:12:36 +02:00
|
|
|
*
|
2003-09-11 04:56:15 +02:00
|
|
|
* Unicode version of SHGetWebFolderFilePathA.
|
2003-07-19 05:12:36 +02:00
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR lpszFile, LPWSTR lpszPath, DWORD dwPathLen)
|
2003-07-19 05:12:36 +02:00
|
|
|
{
|
|
|
|
static const WCHAR szWeb[] = {'\\','W','e','b','\\','\0'};
|
|
|
|
static const WCHAR szWebMui[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
|
|
|
|
DWORD dwLen, dwFileLen;
|
|
|
|
LANGID lidSystem, lidUser;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile), lpszPath, dwPathLen);
|
2003-07-19 05:12:36 +02:00
|
|
|
|
|
|
|
/* Get base directory for web content */
|
|
|
|
dwLen = GetSystemWindowsDirectoryW(lpszPath, dwPathLen);
|
|
|
|
if (dwLen > 0 && lpszPath[dwLen-1] == '\\')
|
|
|
|
dwLen--;
|
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
dwFileLen = lstrlenW(lpszFile);
|
2003-07-19 05:12:36 +02:00
|
|
|
|
2018-09-15 00:10:30 +02:00
|
|
|
if (dwLen + dwFileLen + ARRAY_SIZE(szWeb) >= dwPathLen)
|
2003-07-19 05:12:36 +02:00
|
|
|
return E_FAIL; /* lpszPath too short */
|
|
|
|
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszPath+dwLen, szWeb);
|
2018-09-15 00:10:30 +02:00
|
|
|
dwLen += ARRAY_SIZE(szWeb);
|
2003-07-19 05:12:36 +02:00
|
|
|
dwPathLen = dwPathLen - dwLen; /* Remaining space */
|
|
|
|
|
|
|
|
lidSystem = GetSystemDefaultUILanguage();
|
|
|
|
lidUser = GetUserDefaultUILanguage();
|
|
|
|
|
|
|
|
if (lidSystem != lidUser)
|
|
|
|
{
|
2018-09-15 00:10:30 +02:00
|
|
|
if (dwFileLen + ARRAY_SIZE(szWebMui) < dwPathLen)
|
2003-07-19 05:12:36 +02:00
|
|
|
{
|
|
|
|
/* Use localised content in the users UI language if present */
|
|
|
|
wsprintfW(lpszPath + dwLen, szWebMui, lidUser);
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszPath + dwLen + ARRAY_SIZE(szWebMui), lpszFile);
|
2003-07-19 05:12:36 +02:00
|
|
|
if (PathFileExistsW(lpszPath))
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall back to OS default installed content */
|
2019-06-20 09:13:05 +02:00
|
|
|
lstrcpyW(lpszPath + dwLen, lpszFile);
|
2003-07-19 05:12:36 +02:00
|
|
|
if (PathFileExistsW(lpszPath))
|
|
|
|
return S_OK;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|