4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2001, 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #include "wine/unicode.h"
35 #define NO_SHLWAPI_STREAM
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 /* Get a function pointer from a DLL handle */
42 #define GET_FUNC(func, module, name, fail) \
45 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
46 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
47 if (!func) return fail; \
51 /* DLL handles for late bound calls */
52 extern HMODULE SHLWAPI_hshell32;
54 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
55 typedef BOOL (WINAPI *fnpIsNetDrive)(int);
56 static fnpIsNetDrive pIsNetDrive;
58 HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR,LPWSTR,DWORD);
60 /*************************************************************************
61 * PathAppendA [SHLWAPI.@]
63 * Append one path to another.
66 * lpszPath [I/O] Initial part of path, and destination for output
67 * lpszAppend [I] Path to append
70 * Success: TRUE. lpszPath contains the newly created path.
71 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
74 * lpszAppend must contain at least one backslash ('\') if not NULL.
75 * Because PathCombineA() is used to join the paths, the resulting
76 * path is also canonicalized.
78 BOOL WINAPI PathAppendA (LPSTR lpszPath, LPCSTR lpszAppend)
80 TRACE("(%s,%s)\n",debugstr_a(lpszPath), debugstr_a(lpszAppend));
82 if (lpszPath && lpszAppend)
84 if (!PathIsUNCA(lpszAppend))
85 while (*lpszAppend == '\\')
87 if (PathCombineA(lpszPath, lpszPath, lpszAppend))
93 /*************************************************************************
94 * PathAppendW [SHLWAPI.@]
98 BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
100 TRACE("(%s,%s)\n",debugstr_w(lpszPath), debugstr_w(lpszAppend));
102 if (lpszPath && lpszAppend)
104 if (!PathIsUNCW(lpszAppend))
105 while (*lpszAppend == '\\')
107 if (PathCombineW(lpszPath, lpszPath, lpszAppend))
113 /*************************************************************************
114 * PathCombineA [SHLWAPI.@]
116 * Combine two paths together.
119 * lpszDest [O] Destination for combined path
120 * lpszDir [I] Directory path
121 * lpszFile [I] File path
124 * Success: The output path
125 * Failure: NULL, if inputs are invalid.
128 * lpszDest should be at least MAX_PATH in size, and may point to the same
129 * memory location as lpszDir. The combined path is canonicalised.
131 LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
133 TRACE("(%p,%s,%s)\n", lpszDest, debugstr_a(lpszDir), debugstr_a(lpszFile));
135 if (!lpszDest || (!lpszDir && !lpszFile))
136 return NULL; /* Invalid parameters */
139 WCHAR szDest[MAX_PATH];
140 WCHAR szDir[MAX_PATH];
141 WCHAR szFile[MAX_PATH];
143 MultiByteToWideChar(0,0,lpszDir,-1,szDir,MAX_PATH);
145 MultiByteToWideChar(0,0,lpszFile,-1,szFile,MAX_PATH);
146 PathCombineW(szDest, lpszDir ? szDir : NULL, lpszFile ? szFile : NULL);
147 WideCharToMultiByte(0,0,szDest,-1,lpszDest,MAX_PATH,0,0);
152 /*************************************************************************
153 * PathCombineW [SHLWAPI.@]
157 LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
159 WCHAR szTemp[MAX_PATH];
160 BOOL bUseBoth = FALSE, bStrip = FALSE;
162 TRACE("(%p,%s,%s)\n", lpszDest, debugstr_w(lpszDir), debugstr_w(lpszFile));
164 if (!lpszDest || (!lpszDir && !lpszFile))
165 return lpszDest; /* Invalid parameters */
167 if (!lpszFile || !*lpszFile)
170 strncpyW(szTemp, lpszDir, MAX_PATH);
172 else if (!lpszDir || !*lpszDir || !PathIsRelativeW(lpszFile))
174 if (!lpszDir || !*lpszDir || *lpszFile != '\\' || PathIsUNCW(lpszFile))
177 strncpyW(szTemp, lpszFile, MAX_PATH);
190 strncpyW(szTemp, lpszDir, MAX_PATH);
193 PathStripToRootW(szTemp);
194 lpszFile++; /* Skip '\' */
196 if (!PathAddBackslashW(szTemp))
198 if (strlenW(szTemp) + strlenW(lpszFile) >= MAX_PATH)
200 strcatW(szTemp, lpszFile);
203 PathCanonicalizeW(lpszDest, szTemp);
207 /*************************************************************************
208 * PathAddBackslashA [SHLWAPI.@]
210 * Append a backslash ('\') to a path if one doesn't exist.
213 * lpszPath [I/O] The path to append a backslash to.
216 * Success: The position of the last backslash in the path.
217 * Failure: NULL, if lpszPath is NULL or the path is too large.
219 LPSTR WINAPI PathAddBackslashA(LPSTR lpszPath)
223 TRACE("(%s)\n",debugstr_a(lpszPath));
225 if (!lpszPath || (iLen = strlen(lpszPath)) >= MAX_PATH)
231 if (lpszPath[-1] != '\\')
240 /*************************************************************************
241 * PathAddBackslashW [SHLWAPI.@]
243 * See PathAddBackslashA.
245 LPWSTR WINAPI PathAddBackslashW( LPWSTR lpszPath )
249 TRACE("(%s)\n",debugstr_w(lpszPath));
251 if (!lpszPath || (iLen = strlenW(lpszPath)) >= MAX_PATH)
257 if (lpszPath[-1] != '\\')
266 /*************************************************************************
267 * PathBuildRootA [SHLWAPI.@]
269 * Create a root drive string (e.g. "A:\") from a drive number.
272 * lpszPath [O] Destination for the drive string
278 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
280 LPSTR WINAPI PathBuildRootA(LPSTR lpszPath, int drive)
282 TRACE("(%p,%d)\n", lpszPath, drive);
284 if (lpszPath && drive >= 0 && drive < 26)
286 lpszPath[0] = 'A' + drive;
294 /*************************************************************************
295 * PathBuildRootW [SHLWAPI.@]
297 * See PathBuildRootA.
299 LPWSTR WINAPI PathBuildRootW(LPWSTR lpszPath, int drive)
301 TRACE("(%p,%d)\n", lpszPath, drive);
303 if (lpszPath && drive >= 0 && drive < 26)
305 lpszPath[0] = 'A' + drive;
313 /*************************************************************************
314 * PathFindFileNameA [SHLWAPI.@]
316 * Locate the start of the file name in a path
319 * lpszPath [I] Path to search
322 * A pointer to the first character of the file name
324 LPSTR WINAPI PathFindFileNameA(LPCSTR lpszPath)
326 LPCSTR lastSlash = lpszPath;
328 TRACE("(%s)\n",debugstr_a(lpszPath));
330 while (lpszPath && *lpszPath)
332 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
333 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
334 lastSlash = lpszPath + 1;
335 lpszPath = CharNextA(lpszPath);
337 return (LPSTR)lastSlash;
340 /*************************************************************************
341 * PathFindFileNameW [SHLWAPI.@]
343 * See PathFindFileNameA.
345 LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
347 LPCWSTR lastSlash = lpszPath;
349 TRACE("(%s)\n",debugstr_w(lpszPath));
351 while (lpszPath && *lpszPath)
353 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
354 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
355 lastSlash = lpszPath + 1;
356 lpszPath = CharNextW(lpszPath);
358 return (LPWSTR)lastSlash;
361 /*************************************************************************
362 * PathFindExtensionA [SHLWAPI.@]
364 * Locate the start of the file extension in a path
367 * lpszPath [I] The path to search
370 * A pointer to the first character of the extension, the end of
371 * the string if the path has no extension, or NULL If lpszPath is NULL
373 LPSTR WINAPI PathFindExtensionA( LPCSTR lpszPath )
375 LPCSTR lastpoint = NULL;
377 TRACE("(%s)\n", debugstr_a(lpszPath));
383 if (*lpszPath == '\\' || *lpszPath==' ')
385 else if (*lpszPath == '.')
386 lastpoint = lpszPath;
387 lpszPath = CharNextA(lpszPath);
390 return (LPSTR)(lastpoint ? lastpoint : lpszPath);
393 /*************************************************************************
394 * PathFindExtensionW [SHLWAPI.@]
396 * See PathFindExtensionA.
398 LPWSTR WINAPI PathFindExtensionW( LPCWSTR lpszPath )
400 LPCWSTR lastpoint = NULL;
402 TRACE("(%s)\n", debugstr_w(lpszPath));
408 if (*lpszPath == '\\' || *lpszPath==' ')
410 else if (*lpszPath == '.')
411 lastpoint = lpszPath;
412 lpszPath = CharNextW(lpszPath);
415 return (LPWSTR)(lastpoint ? lastpoint : lpszPath);
418 /*************************************************************************
419 * PathGetArgsA [SHLWAPI.@]
421 * Find the next argument in a string delimited by spaces.
424 * lpszPath [I] The string to search for arguments in
427 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
430 * Spaces in quoted strings are ignored as delimiters.
432 LPSTR WINAPI PathGetArgsA(LPCSTR lpszPath)
434 BOOL bSeenQuote = FALSE;
436 TRACE("(%s)\n",debugstr_a(lpszPath));
442 if ((*lpszPath==' ') && !bSeenQuote)
443 return (LPSTR)lpszPath + 1;
444 if (*lpszPath == '"')
445 bSeenQuote = !bSeenQuote;
446 lpszPath = CharNextA(lpszPath);
449 return (LPSTR)lpszPath;
452 /*************************************************************************
453 * PathGetArgsW [SHLWAPI.@]
457 LPWSTR WINAPI PathGetArgsW(LPCWSTR lpszPath)
459 BOOL bSeenQuote = FALSE;
461 TRACE("(%s)\n",debugstr_w(lpszPath));
467 if ((*lpszPath==' ') && !bSeenQuote)
468 return (LPWSTR)lpszPath + 1;
469 if (*lpszPath == '"')
470 bSeenQuote = !bSeenQuote;
471 lpszPath = CharNextW(lpszPath);
474 return (LPWSTR)lpszPath;
477 /*************************************************************************
478 * PathGetDriveNumberA [SHLWAPI.@]
480 * Return the drive number from a path
483 * lpszPath [I] Path to get the drive number from
486 * Success: The drive number corresponding to the drive in the path
487 * Failure: -1, if lpszPath contains no valid drive
489 int WINAPI PathGetDriveNumberA(LPCSTR lpszPath)
491 TRACE ("(%s)\n",debugstr_a(lpszPath));
493 if (lpszPath && !IsDBCSLeadByte(*lpszPath) && lpszPath[1] == ':' &&
494 tolower(*lpszPath) >= 'a' && tolower(*lpszPath) <= 'z')
495 return tolower(*lpszPath) - 'a';
499 /*************************************************************************
500 * PathGetDriveNumberW [SHLWAPI.@]
502 * See PathGetDriveNumberA.
504 int WINAPI PathGetDriveNumberW(LPCWSTR lpszPath)
506 TRACE ("(%s)\n",debugstr_w(lpszPath));
508 if (lpszPath && lpszPath[1] == ':' &&
509 tolowerW(*lpszPath) >= 'a' && tolowerW(*lpszPath) <= 'z')
510 return tolowerW(*lpszPath) - 'a';
514 /*************************************************************************
515 * PathRemoveFileSpecA [SHLWAPI.@]
517 * Remove the file specification from a path.
520 * lpszPath [I/O] Path to remove the file spec from
523 * TRUE If the path was valid and modified
526 BOOL WINAPI PathRemoveFileSpecA(LPSTR lpszPath)
528 LPSTR lpszFileSpec = lpszPath;
529 BOOL bModified = FALSE;
531 TRACE("(%s)\n",debugstr_a(lpszPath));
535 /* Skip directory or UNC path */
536 if (*lpszPath == '\\')
537 lpszFileSpec = ++lpszPath;
538 if (*lpszPath == '\\')
539 lpszFileSpec = ++lpszPath;
543 if(*lpszPath == '\\')
544 lpszFileSpec = lpszPath; /* Skip dir */
545 else if(*lpszPath == ':')
547 lpszFileSpec = ++lpszPath; /* Skip drive */
548 if (*lpszPath == '\\')
551 if (!(lpszPath = CharNextA(lpszPath)))
557 *lpszFileSpec = '\0';
564 /*************************************************************************
565 * PathRemoveFileSpecW [SHLWAPI.@]
567 * See PathRemoveFileSpecA.
569 BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
571 LPWSTR lpszFileSpec = lpszPath;
572 BOOL bModified = FALSE;
574 TRACE("(%s)\n",debugstr_w(lpszPath));
578 /* Skip directory or UNC path */
579 if (*lpszPath == '\\')
580 lpszFileSpec = ++lpszPath;
581 if (*lpszPath == '\\')
582 lpszFileSpec = ++lpszPath;
586 if(*lpszPath == '\\')
587 lpszFileSpec = lpszPath; /* Skip dir */
588 else if(*lpszPath == ':')
590 lpszFileSpec = ++lpszPath; /* Skip drive */
591 if (*lpszPath == '\\')
594 if (!(lpszPath = CharNextW(lpszPath)))
600 *lpszFileSpec = '\0';
607 /*************************************************************************
608 * PathStripPathA [SHLWAPI.@]
610 * Remove the initial path from the beginning of a filename
613 * lpszPath [I/O] Path to remove the initial path from
618 void WINAPI PathStripPathA(LPSTR lpszPath)
620 TRACE("(%s)\n", debugstr_a(lpszPath));
624 LPSTR lpszFileName = PathFindFileNameA(lpszPath);
626 RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1);
630 /*************************************************************************
631 * PathStripPathW [SHLWAPI.@]
633 * See PathStripPathA.
635 void WINAPI PathStripPathW(LPWSTR lpszPath)
639 TRACE("(%s)\n", debugstr_w(lpszPath));
640 lpszFileName = PathFindFileNameW(lpszPath);
642 RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR));
645 /*************************************************************************
646 * PathStripToRootA [SHLWAPI.@]
648 * Reduce a path to its root.
651 * lpszPath [I/O] the path to reduce
654 * Success: TRUE if the stripped path is a root path
655 * Failure: FALSE if the path cannot be stripped or is NULL
657 BOOL WINAPI PathStripToRootA(LPSTR lpszPath)
659 TRACE("(%s)\n", debugstr_a(lpszPath));
663 while(!PathIsRootA(lpszPath))
664 if (!PathRemoveFileSpecA(lpszPath))
669 /*************************************************************************
670 * PathStripToRootW [SHLWAPI.@]
672 * See PathStripToRootA.
674 BOOL WINAPI PathStripToRootW(LPWSTR lpszPath)
676 TRACE("(%s)\n", debugstr_w(lpszPath));
680 while(!PathIsRootW(lpszPath))
681 if (!PathRemoveFileSpecW(lpszPath))
686 /*************************************************************************
687 * PathRemoveArgsA [SHLWAPI.@]
689 * Strip space separated arguments from a path.
692 * lpszPath [I/O] Path to remove arguments from
697 void WINAPI PathRemoveArgsA(LPSTR lpszPath)
699 TRACE("(%s)\n",debugstr_a(lpszPath));
703 LPSTR lpszArgs = PathGetArgsA(lpszPath);
708 LPSTR lpszLastChar = CharPrevA(lpszPath, lpszArgs);
709 if(*lpszLastChar == ' ')
710 *lpszLastChar = '\0';
715 /*************************************************************************
716 * PathRemoveArgsW [SHLWAPI.@]
718 * See PathRemoveArgsA.
720 void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
722 TRACE("(%s)\n",debugstr_w(lpszPath));
726 LPWSTR lpszArgs = PathGetArgsW(lpszPath);
731 LPWSTR lpszLastChar = CharPrevW(lpszPath, lpszArgs);
732 if(*lpszLastChar == ' ')
733 *lpszLastChar = '\0';
738 /*************************************************************************
739 * PathRemoveExtensionA [SHLWAPI.@]
741 * Remove the file extension from a path
744 * lpszPath [I/O] Path to remove the extension from
749 void WINAPI PathRemoveExtensionA(LPSTR lpszPath)
751 TRACE("(%s)\n", debugstr_a(lpszPath));
755 lpszPath = PathFindExtensionA(lpszPath);
760 /*************************************************************************
761 * PathRemoveExtensionW [SHLWAPI.@]
763 * See PathRemoveExtensionA.
765 void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
767 TRACE("(%s)\n", debugstr_w(lpszPath));
771 lpszPath = PathFindExtensionW(lpszPath);
776 /*************************************************************************
777 * PathRemoveBackslashA [SHLWAPI.@]
779 * Remove a trailing backslash from a path.
782 * lpszPath [I/O] Path to remove backslash from
785 * Success: A pointer to the end of the path
786 * Failure: NULL, if lpszPath is NULL
788 LPSTR WINAPI PathRemoveBackslashA( LPSTR lpszPath )
792 TRACE("(%s)\n", debugstr_a(lpszPath));
796 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
797 if (!PathIsRootA(lpszPath) && *szTemp == '\\')
803 /*************************************************************************
804 * PathRemoveBackslashW [SHLWAPI.@]
806 * See PathRemoveBackslashA.
808 LPWSTR WINAPI PathRemoveBackslashW( LPWSTR lpszPath )
810 LPWSTR szTemp = NULL;
812 TRACE("(%s)\n", debugstr_w(lpszPath));
816 szTemp = CharPrevW(lpszPath, lpszPath + strlenW(lpszPath));
817 if (!PathIsRootW(lpszPath) && *szTemp == '\\')
823 /*************************************************************************
824 * PathRemoveBlanksA [SHLWAPI.@]
826 * Remove Spaces from the start and end of a path.
829 * lpszPath [I/O] Path to strip blanks from
834 VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
836 TRACE("(%s)\n", debugstr_a(lpszPath));
838 if(lpszPath && *lpszPath)
840 LPSTR start = lpszPath;
842 while (*lpszPath == ' ')
843 lpszPath = CharNextA(lpszPath);
846 *start++ = *lpszPath++;
848 if (start != lpszPath)
849 while (start[-1] == ' ')
855 /*************************************************************************
856 * PathRemoveBlanksW [SHLWAPI.@]
858 * See PathRemoveBlanksA.
860 VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
862 TRACE("(%s)\n", debugstr_w(lpszPath));
864 if(lpszPath && *lpszPath)
866 LPWSTR start = lpszPath;
868 while (*lpszPath == ' ')
872 *start++ = *lpszPath++;
874 if (start != lpszPath)
875 while (start[-1] == ' ')
881 /*************************************************************************
882 * PathQuoteSpacesA [SHLWAPI.@]
884 * Surround a path containg spaces in quotes.
887 * lpszPath [I/O] Path to quote
893 * The path is not changed if it is invalid or has no spaces.
895 VOID WINAPI PathQuoteSpacesA(LPSTR lpszPath)
897 TRACE("(%s)\n", debugstr_a(lpszPath));
899 if(lpszPath && StrChrA(lpszPath,' '))
901 size_t iLen = strlen(lpszPath) + 1;
903 if (iLen + 2 < MAX_PATH)
905 memmove(lpszPath + 1, lpszPath, iLen);
907 lpszPath[iLen] = '"';
908 lpszPath[iLen + 1] = '\0';
913 /*************************************************************************
914 * PathQuoteSpacesW [SHLWAPI.@]
916 * See PathQuoteSpacesA.
918 VOID WINAPI PathQuoteSpacesW(LPWSTR lpszPath)
920 TRACE("(%s)\n", debugstr_w(lpszPath));
922 if(lpszPath && StrChrW(lpszPath,' '))
924 int iLen = strlenW(lpszPath) + 1;
926 if (iLen + 2 < MAX_PATH)
928 memmove(lpszPath + 1, lpszPath, iLen * sizeof(WCHAR));
930 lpszPath[iLen] = '"';
931 lpszPath[iLen + 1] = '\0';
936 /*************************************************************************
937 * PathUnquoteSpacesA [SHLWAPI.@]
939 * Remove quotes ("") from around a path, if present.
942 * lpszPath [I/O] Path to strip quotes from
948 * If the path contains a single quote only, an empty string will result.
949 * Otherwise quotes are only removed if they appear at the start and end
952 VOID WINAPI PathUnquoteSpacesA(LPSTR lpszPath)
954 TRACE("(%s)\n", debugstr_a(lpszPath));
956 if (lpszPath && *lpszPath == '"')
958 DWORD dwLen = strlen(lpszPath) - 1;
960 if (lpszPath[dwLen] == '"')
962 lpszPath[dwLen] = '\0';
963 for (; *lpszPath; lpszPath++)
964 *lpszPath = lpszPath[1];
969 /*************************************************************************
970 * PathUnquoteSpacesW [SHLWAPI.@]
972 * See PathUnquoteSpacesA.
974 VOID WINAPI PathUnquoteSpacesW(LPWSTR lpszPath)
976 TRACE("(%s)\n", debugstr_w(lpszPath));
978 if (lpszPath && *lpszPath == '"')
980 DWORD dwLen = strlenW(lpszPath) - 1;
982 if (lpszPath[dwLen] == '"')
984 lpszPath[dwLen] = '\0';
985 for (; *lpszPath; lpszPath++)
986 *lpszPath = lpszPath[1];
991 /*************************************************************************
992 * PathParseIconLocationA [SHLWAPI.@]
994 * Parse the location of an icon from a path.
997 * lpszPath [I/O] The path to parse the icon location from.
1000 * Success: The number of the icon
1001 * Failure: 0 if the path does not contain an icon location or is NULL
1004 * The path has surrounding quotes and spaces removed regardless
1005 * of whether the call succeeds or not.
1007 int WINAPI PathParseIconLocationA(LPSTR lpszPath)
1012 TRACE("(%s)\n", debugstr_a(lpszPath));
1016 if ((lpszComma = strchr(lpszPath, ',')))
1018 *lpszComma++ = '\0';
1019 iRet = StrToIntA(lpszComma);
1021 PathUnquoteSpacesA(lpszPath);
1022 PathRemoveBlanksA(lpszPath);
1027 /*************************************************************************
1028 * PathParseIconLocationW [SHLWAPI.@]
1030 * See PathParseIconLocationA.
1032 int WINAPI PathParseIconLocationW(LPWSTR lpszPath)
1037 TRACE("(%s)\n", debugstr_w(lpszPath));
1041 if ((lpszComma = StrChrW(lpszPath, ',')))
1043 *lpszComma++ = '\0';
1044 iRet = StrToIntW(lpszComma);
1046 PathUnquoteSpacesW(lpszPath);
1047 PathRemoveBlanksW(lpszPath);
1052 /*************************************************************************
1055 * Unicode version of PathFileExistsDefExtA.
1057 BOOL WINAPI PathFileExistsDefExtW(LPWSTR lpszPath,DWORD dwWhich)
1059 static const WCHAR pszExts[7][5] = { { '.', 'p', 'i', 'f', 0},
1060 { '.', 'c', 'o', 'm', 0},
1061 { '.', 'e', 'x', 'e', 0},
1062 { '.', 'b', 'a', 't', 0},
1063 { '.', 'l', 'n', 'k', 0},
1064 { '.', 'c', 'm', 'd', 0},
1067 TRACE("(%s,%ld)\n", debugstr_w(lpszPath), dwWhich);
1069 if (!lpszPath || PathIsUNCServerW(lpszPath) || PathIsUNCServerShareW(lpszPath))
1074 LPCWSTR szExt = PathFindExtensionW(lpszPath);
1075 if (!*szExt || dwWhich & 0x40)
1078 int iLen = lstrlenW(lpszPath);
1079 if (iLen > (MAX_PATH - 5))
1081 while (dwWhich & 0x1 && iChoose < sizeof(pszExts))
1083 lstrcpyW(lpszPath + iLen, pszExts[iChoose]);
1084 if (PathFileExistsW(lpszPath))
1089 *(lpszPath + iLen) = (WCHAR)'\0';
1093 return PathFileExistsW(lpszPath);
1096 /*************************************************************************
1099 * Determine if a file exists locally and is of an executable type.
1102 * lpszPath [I/O] File to search for
1103 * dwWhich [I] Type of executable to search for
1106 * TRUE If the file was found. lpszPath contains the file name.
1110 * lpszPath is modified in place and must be at least MAX_PATH in length.
1111 * If the function returns FALSE, the path is modified to its orginal state.
1112 * If the given path contains an extension or dwWhich is 0, executable
1113 * extensions are not checked.
1115 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1116 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1117 * their own developers exclusive use. Monopoly, anyone?
1119 BOOL WINAPI PathFileExistsDefExtA(LPSTR lpszPath,DWORD dwWhich)
1123 TRACE("(%s,%ld)\n", debugstr_a(lpszPath), dwWhich);
1127 WCHAR szPath[MAX_PATH];
1128 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
1129 bRet = PathFileExistsDefExtW(szPath, dwWhich);
1131 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
1136 /*************************************************************************
1137 * SHLWAPI_PathFindInOtherDirs
1139 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1141 static BOOL WINAPI SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile, DWORD dwWhich)
1143 static WCHAR szSystem[] = { 'S','y','s','t','e','m','\0'};
1144 static WCHAR szPath[] = { 'P','A','T','H','\0'};
1148 WCHAR buff[MAX_PATH];
1150 TRACE("(%s,%08lx)\n", debugstr_w(lpszFile), dwWhich);
1152 /* Try system directories */
1153 GetSystemDirectoryW(buff, MAX_PATH);
1154 if (!PathAppendW(buff, lpszFile))
1156 if (PathFileExistsDefExtW(buff, dwWhich))
1158 strcpyW(lpszFile, buff);
1161 GetWindowsDirectoryW(buff, MAX_PATH);
1162 if (!PathAppendW(buff, szSystem ) || !PathAppendW(buff, lpszFile))
1164 if (PathFileExistsDefExtW(buff, dwWhich))
1166 strcpyW(lpszFile, buff);
1169 GetWindowsDirectoryW(buff, MAX_PATH);
1170 if (!PathAppendW(buff, lpszFile))
1172 if (PathFileExistsDefExtW(buff, dwWhich))
1174 strcpyW(lpszFile, buff);
1177 /* Try dirs listed in %PATH% */
1178 dwLenPATH = GetEnvironmentVariableW(szPath, buff, MAX_PATH);
1180 if (!dwLenPATH || !(lpszPATH = malloc((dwLenPATH + 1) * sizeof (WCHAR))))
1183 GetEnvironmentVariableW(szPath, lpszPATH, dwLenPATH + 1);
1184 lpszCurr = lpszPATH;
1187 LPCWSTR lpszEnd = lpszCurr;
1188 LPWSTR pBuff = buff;
1190 while (*lpszEnd == ' ')
1192 while (*lpszEnd && *lpszEnd != ';')
1193 *pBuff++ = *lpszEnd++;
1197 lpszCurr = lpszEnd + 1;
1199 lpszCurr = NULL; /* Last Path, terminate after this */
1201 if (!PathAppendW(buff, lpszFile))
1206 if (PathFileExistsDefExtW(buff, dwWhich))
1208 strcpyW(lpszFile, buff);
1217 /*************************************************************************
1220 * Search a range of paths for a specific type of executable.
1223 * lpszFile [I/O] File to search for
1224 * lppszOtherDirs [I] Other directories to look in
1225 * dwWhich [I] Type of executable to search for
1228 * Success: TRUE. The path to the executable is stored in lpszFile.
1229 * Failure: FALSE. The path to the executable is unchanged.
1231 BOOL WINAPI PathFindOnPathExA(LPSTR lpszFile,LPCSTR *lppszOtherDirs,DWORD dwWhich)
1233 WCHAR szFile[MAX_PATH];
1234 WCHAR buff[MAX_PATH];
1236 TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile), lppszOtherDirs, dwWhich);
1238 if (!lpszFile || !PathIsFileSpecA(lpszFile))
1241 MultiByteToWideChar(0,0,lpszFile,-1,szFile,MAX_PATH);
1243 /* Search provided directories first */
1244 if (lppszOtherDirs && *lppszOtherDirs)
1246 WCHAR szOther[MAX_PATH];
1247 LPCSTR *lpszOtherPath = lppszOtherDirs;
1249 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1251 MultiByteToWideChar(0,0,*lpszOtherPath,-1,szOther,MAX_PATH);
1252 PathCombineW(buff, szOther, szFile);
1253 if (PathFileExistsDefExtW(buff, dwWhich))
1255 WideCharToMultiByte(0,0,buff,-1,lpszFile,MAX_PATH,0,0);
1261 /* Not found, try system and path dirs */
1262 if (SHLWAPI_PathFindInOtherDirs(szFile, dwWhich))
1264 WideCharToMultiByte(0,0,szFile,-1,lpszFile,MAX_PATH,0,0);
1270 /*************************************************************************
1273 * Unicode version of PathFindOnPathExA.
1275 BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile,LPCWSTR *lppszOtherDirs,DWORD dwWhich)
1277 WCHAR buff[MAX_PATH];
1279 TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile), lppszOtherDirs, dwWhich);
1281 if (!lpszFile || !PathIsFileSpecW(lpszFile))
1284 /* Search provided directories first */
1285 if (lppszOtherDirs && *lppszOtherDirs)
1287 LPCWSTR *lpszOtherPath = lppszOtherDirs;
1288 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1290 PathCombineW(buff, *lpszOtherPath, lpszFile);
1291 if (PathFileExistsDefExtW(buff, dwWhich))
1293 strcpyW(lpszFile, buff);
1299 /* Not found, try system and path dirs */
1300 return SHLWAPI_PathFindInOtherDirs(lpszFile, dwWhich);
1303 /*************************************************************************
1304 * PathFindOnPathA [SHLWAPI.@]
1306 * Search a range of paths for an executable.
1309 * lpszFile [I/O] File to search for
1310 * lppszOtherDirs [I] Other directories to look in
1313 * Success: TRUE. The path to the executable is stored in lpszFile.
1314 * Failure: FALSE. The path to the executable is unchanged.
1316 BOOL WINAPI PathFindOnPathA(LPSTR lpszFile, LPCSTR *lppszOtherDirs)
1318 TRACE("(%s,%p)\n", debugstr_a(lpszFile), lppszOtherDirs);
1319 return PathFindOnPathExA(lpszFile, lppszOtherDirs, 0);
1322 /*************************************************************************
1323 * PathFindOnPathW [SHLWAPI.@]
1325 * See PathFindOnPathA.
1327 BOOL WINAPI PathFindOnPathW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs)
1329 TRACE("(%s,%p)\n", debugstr_w(lpszFile), lppszOtherDirs);
1330 return PathFindOnPathExW(lpszFile,lppszOtherDirs, 0);
1333 /*************************************************************************
1334 * PathCompactPathExA [SHLWAPI.@]
1336 * Compact a path into a given number of characters.
1339 * lpszDest [O] Destination for compacted path
1340 * lpszPath [I] Source path
1341 * cchMax [I] Maximum size of compacted path
1342 * dwFlags [I] Reserved
1345 * Success: TRUE. The compacted path is written to lpszDest.
1346 * Failure: FALSE. lpszPath is undefined.
1349 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1351 * The Win32 version of this function contains a bug: When cchMax == 7,
1352 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1355 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1356 * because Win32 will insert a "\" in lpszDest, even if one is
1357 * not present in the original path.
1359 BOOL WINAPI PathCompactPathExA(LPSTR lpszDest, LPCSTR lpszPath,
1360 UINT cchMax, DWORD dwFlags)
1364 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest, debugstr_a(lpszPath), cchMax, dwFlags);
1366 if (lpszPath && lpszDest)
1368 WCHAR szPath[MAX_PATH];
1369 WCHAR szDest[MAX_PATH];
1371 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
1373 bRet = PathCompactPathExW(szDest, szPath, cchMax, dwFlags);
1374 WideCharToMultiByte(0,0,szDest,-1,lpszDest,MAX_PATH,0,0);
1379 /*************************************************************************
1380 * PathCompactPathExW [SHLWAPI.@]
1382 * See PathCompactPathExA.
1384 BOOL WINAPI PathCompactPathExW(LPWSTR lpszDest, LPCWSTR lpszPath,
1385 UINT cchMax, DWORD dwFlags)
1387 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
1389 DWORD dwLen, dwFileLen = 0;
1391 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest, debugstr_w(lpszPath), cchMax, dwFlags);
1398 WARN("Invalid lpszDest would crash under Win32!\n");
1407 dwLen = strlenW(lpszPath) + 1;
1411 /* Don't need to compact */
1412 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1416 /* Path must be compacted to fit into lpszDest */
1417 lpszFile = PathFindFileNameW(lpszPath);
1418 dwFileLen = lpszPath + dwLen - lpszFile;
1420 if (dwFileLen == dwLen)
1422 /* No root in psth */
1425 while (--cchMax > 0) /* No room left for anything but ellipses */
1430 /* Compact the file name with ellipses at the end */
1432 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1433 strcpyW(lpszDest + cchMax, szEllipses);
1436 /* We have a root in the path */
1437 lpszFile--; /* Start compacted filename with the path separator */
1440 if (dwFileLen + 3 > cchMax)
1442 /* Compact the file name */
1445 while (--cchMax > 0) /* No room left for anything but ellipses */
1450 strcpyW(lpszDest, szEllipses);
1453 *lpszDest++ = *lpszFile++;
1456 while (--cchMax > 0) /* No room left for anything but ellipses */
1462 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1463 strcpyW(lpszDest + cchMax, szEllipses);
1467 /* Only the root needs to be Compacted */
1468 dwLen = cchMax - dwFileLen - 3;
1469 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1470 strcpyW(lpszDest + dwLen, szEllipses);
1471 strcpyW(lpszDest + dwLen + 3, lpszFile);
1475 /*************************************************************************
1476 * PathIsRelativeA [SHLWAPI.@]
1478 * Determine if a path is a relative path.
1481 * lpszPath [I] Path to check
1484 * TRUE: The path is relative, or is invalid.
1485 * FALSE: The path is not relative.
1487 BOOL WINAPI PathIsRelativeA (LPCSTR lpszPath)
1489 TRACE("(%s)\n",debugstr_a(lpszPath));
1491 if (!lpszPath || !*lpszPath || IsDBCSLeadByte(*lpszPath))
1493 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1498 /*************************************************************************
1499 * PathIsRelativeW [SHLWAPI.@]
1501 * See PathIsRelativeA.
1503 BOOL WINAPI PathIsRelativeW (LPCWSTR lpszPath)
1505 TRACE("(%s)\n",debugstr_w(lpszPath));
1507 if (!lpszPath || !*lpszPath)
1509 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1514 /*************************************************************************
1515 * PathIsRootA [SHLWAPI.@]
1517 * Determine if a path is a root path.
1520 * lpszPath [I] Path to check
1523 * TRUE If lpszPath is valid and a root path,
1526 BOOL WINAPI PathIsRootA(LPCSTR lpszPath)
1528 TRACE("(%s)\n", debugstr_a(lpszPath));
1530 if (lpszPath && *lpszPath)
1532 if (*lpszPath == '\\')
1535 return TRUE; /* \ */
1536 else if (lpszPath[1]=='\\')
1538 BOOL bSeenSlash = FALSE;
1541 /* Check for UNC root path */
1544 if (*lpszPath == '\\')
1550 lpszPath = CharNextA(lpszPath);
1555 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1556 return TRUE; /* X:\ */
1561 /*************************************************************************
1562 * PathIsRootW [SHLWAPI.@]
1566 BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
1568 TRACE("(%s)\n", debugstr_w(lpszPath));
1570 if (lpszPath && *lpszPath)
1572 if (*lpszPath == '\\')
1575 return TRUE; /* \ */
1576 else if (lpszPath[1]=='\\')
1578 BOOL bSeenSlash = FALSE;
1581 /* Check for UNC root path */
1584 if (*lpszPath == '\\')
1590 lpszPath = CharNextW(lpszPath);
1595 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1596 return TRUE; /* X:\ */
1601 /*************************************************************************
1602 * PathIsDirectoryA [SHLWAPI.@]
1604 * Determine if a path is a valid directory
1607 * lpszPath [I] Path to check.
1610 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1611 * FALSE if lpszPath is invalid or not a directory.
1614 * Although this function is prototyped as returning a BOOL, it returns
1615 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1617 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1622 BOOL WINAPI PathIsDirectoryA(LPCSTR lpszPath)
1626 TRACE("(%s)\n", debugstr_a(lpszPath));
1628 if (!lpszPath || PathIsUNCServerA(lpszPath))
1631 if (PathIsUNCServerShareA(lpszPath))
1633 FIXME("UNC Server Share not yet supported - FAILING\n");
1637 if ((dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES)
1639 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1642 /*************************************************************************
1643 * PathIsDirectoryW [SHLWAPI.@]
1645 * See PathIsDirectoryA.
1647 BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
1651 TRACE("(%s)\n", debugstr_w(lpszPath));
1653 if (!lpszPath || PathIsUNCServerW(lpszPath))
1656 if (PathIsUNCServerShareW(lpszPath))
1658 FIXME("UNC Server Share not yet supported - FAILING\n");
1662 if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
1664 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1667 /*************************************************************************
1668 * PathFileExistsA [SHLWAPI.@]
1670 * Determine if a file exists.
1673 * lpszPath [I] Path to check
1676 * TRUE If the file exists and is readable
1679 BOOL WINAPI PathFileExistsA(LPCSTR lpszPath)
1684 TRACE("(%s)\n",debugstr_a(lpszPath));
1689 iPrevErrMode = SetErrorMode(1);
1690 dwAttr = GetFileAttributesA(lpszPath);
1691 SetErrorMode(iPrevErrMode);
1692 return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
1695 /*************************************************************************
1696 * PathFileExistsW [SHLWAPI.@]
1698 * See PathFileExistsA.
1700 BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
1705 TRACE("(%s)\n",debugstr_w(lpszPath));
1710 iPrevErrMode = SetErrorMode(1);
1711 dwAttr = GetFileAttributesW(lpszPath);
1712 SetErrorMode(iPrevErrMode);
1713 return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
1716 /*************************************************************************
1717 * PathFileExistsAndAttributesA [SHLWAPI.445]
1719 * Determine if a file exists.
1722 * lpszPath [I] Path to check
1723 * dwAttr [O] attributes of file
1726 * TRUE If the file exists and is readable
1729 BOOL WINAPI PathFileExistsAndAttributesA(LPCSTR lpszPath, DWORD *dwAttr)
1734 TRACE("(%s %p)\n", debugstr_a(lpszPath), dwAttr);
1737 *dwAttr = INVALID_FILE_ATTRIBUTES;
1742 iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
1743 dwVal = GetFileAttributesA(lpszPath);
1744 SetErrorMode(iPrevErrMode);
1747 return (dwVal != INVALID_FILE_ATTRIBUTES);
1750 /*************************************************************************
1751 * PathFileExistsAndAttributesW [SHLWAPI.446]
1753 * See PathFileExistsA.
1755 BOOL WINAPI PathFileExistsAndAttributesW(LPCWSTR lpszPath, DWORD *dwAttr)
1760 TRACE("(%s %p)\n", debugstr_w(lpszPath), dwAttr);
1765 iPrevErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
1766 dwVal = GetFileAttributesW(lpszPath);
1767 SetErrorMode(iPrevErrMode);
1770 return (dwVal != INVALID_FILE_ATTRIBUTES);
1773 /*************************************************************************
1774 * PathMatchSingleMaskA [internal]
1776 static BOOL WINAPI PathMatchSingleMaskA(LPCSTR name, LPCSTR mask)
1778 while (*name && *mask && *mask!=';')
1784 if (PathMatchSingleMaskA(name,mask+1))
1785 return TRUE; /* try substrings */
1790 if (toupper(*mask) != toupper(*name) && *mask != '?')
1793 name = CharNextA(name);
1794 mask = CharNextA(mask);
1799 while (*mask == '*')
1801 if (!*mask || *mask == ';')
1807 /*************************************************************************
1808 * PathMatchSingleMaskW [internal]
1810 static BOOL WINAPI PathMatchSingleMaskW(LPCWSTR name, LPCWSTR mask)
1812 while (*name && *mask && *mask != ';')
1818 if (PathMatchSingleMaskW(name,mask+1))
1819 return TRUE; /* try substrings */
1824 if (toupperW(*mask) != toupperW(*name) && *mask != '?')
1827 name = CharNextW(name);
1828 mask = CharNextW(mask);
1832 while (*mask == '*')
1834 if (!*mask || *mask == ';')
1840 /*************************************************************************
1841 * PathMatchSpecA [SHLWAPI.@]
1843 * Determine if a path matches one or more search masks.
1846 * lpszPath [I] Path to check
1847 * lpszMask [I] Search mask(s)
1850 * TRUE If lpszPath is valid and is matched
1854 * Multiple search masks may be given if they are separated by ";". The
1855 * pattern "*.*" is treated specially in that it matches all paths (for
1856 * backwards compatibility with DOS).
1858 BOOL WINAPI PathMatchSpecA(LPCSTR lpszPath, LPCSTR lpszMask)
1860 TRACE("(%s,%s)\n", lpszPath, lpszMask);
1862 if (!lstrcmpA(lpszMask, "*.*"))
1863 return TRUE; /* Matches every path */
1867 if (PathMatchSingleMaskA(lpszPath, lpszMask))
1868 return TRUE; /* Matches the current mask */
1870 while (*lpszMask && *lpszMask != ';')
1871 lpszMask = CharNextA(lpszMask);
1873 if (*lpszMask == ';')
1876 while (*lpszMask == ' ')
1877 lpszMask++; /* masks may be separated by "; " */
1883 /*************************************************************************
1884 * PathMatchSpecW [SHLWAPI.@]
1886 * See PathMatchSpecA.
1888 BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
1890 static const WCHAR szStarDotStar[] = { '*', '.', '*', '\0' };
1892 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszMask));
1894 if (!lstrcmpW(lpszMask, szStarDotStar))
1895 return TRUE; /* Matches every path */
1899 if (PathMatchSingleMaskW(lpszPath, lpszMask))
1900 return TRUE; /* Matches the current path */
1902 while (*lpszMask && *lpszMask != ';')
1905 if (*lpszMask == ';')
1908 while (*lpszMask == ' ')
1909 lpszMask++; /* Masks may be separated by "; " */
1915 /*************************************************************************
1916 * PathIsSameRootA [SHLWAPI.@]
1918 * Determine if two paths share the same root.
1921 * lpszPath1 [I] Source path
1922 * lpszPath2 [I] Path to compare with
1925 * TRUE If both paths are valid and share the same root.
1926 * FALSE If either path is invalid or the paths do not share the same root.
1928 BOOL WINAPI PathIsSameRootA(LPCSTR lpszPath1, LPCSTR lpszPath2)
1933 TRACE("(%s,%s)\n", debugstr_a(lpszPath1), debugstr_a(lpszPath2));
1935 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootA(lpszPath1)))
1938 dwLen = PathCommonPrefixA(lpszPath1, lpszPath2, NULL) + 1;
1939 if (lpszStart - lpszPath1 > dwLen)
1940 return FALSE; /* Paths not common up to length of the root */
1944 /*************************************************************************
1945 * PathIsSameRootW [SHLWAPI.@]
1947 * See PathIsSameRootA.
1949 BOOL WINAPI PathIsSameRootW(LPCWSTR lpszPath1, LPCWSTR lpszPath2)
1954 TRACE("(%s,%s)\n", debugstr_w(lpszPath1), debugstr_w(lpszPath2));
1956 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootW(lpszPath1)))
1959 dwLen = PathCommonPrefixW(lpszPath1, lpszPath2, NULL) + 1;
1960 if (lpszStart - lpszPath1 > dwLen)
1961 return FALSE; /* Paths not common up to length of the root */
1965 /*************************************************************************
1966 * PathIsContentTypeA [SHLWAPI.@]
1968 * Determine if a file is of a given registered content type.
1971 * lpszPath [I] File to check
1972 * lpszContentType [I] Content type to check for
1975 * TRUE If lpszPath is a given registered content type,
1979 * This function looks up the registered content type for lpszPath. If
1980 * a content type is registered, it is compared (case insensitively) to
1981 * lpszContentType. Only if this matches does the function succeed.
1983 BOOL WINAPI PathIsContentTypeA(LPCSTR lpszPath, LPCSTR lpszContentType)
1987 char szBuff[MAX_PATH];
1989 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszContentType));
1991 if (lpszPath && (szExt = PathFindExtensionA(lpszPath)) && *szExt &&
1992 !SHGetValueA(HKEY_CLASSES_ROOT, szExt, "Content Type",
1993 REG_NONE, szBuff, &dwDummy) &&
1994 !strcasecmp(lpszContentType, szBuff))
2001 /*************************************************************************
2002 * PathIsContentTypeW [SHLWAPI.@]
2004 * See PathIsContentTypeA.
2006 BOOL WINAPI PathIsContentTypeW(LPCWSTR lpszPath, LPCWSTR lpszContentType)
2008 static const WCHAR szContentType[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2011 WCHAR szBuff[MAX_PATH];
2013 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszContentType));
2015 if (lpszPath && (szExt = PathFindExtensionW(lpszPath)) && *szExt &&
2016 !SHGetValueW(HKEY_CLASSES_ROOT, szExt, szContentType,
2017 REG_NONE, szBuff, &dwDummy) &&
2018 !strcmpiW(lpszContentType, szBuff))
2025 /*************************************************************************
2026 * PathIsFileSpecA [SHLWAPI.@]
2028 * Determine if a path is a file specification.
2031 * lpszPath [I] Path to chack
2034 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2037 BOOL WINAPI PathIsFileSpecA(LPCSTR lpszPath)
2039 TRACE("(%s)\n", debugstr_a(lpszPath));
2046 if (*lpszPath == '\\' || *lpszPath == ':')
2048 lpszPath = CharNextA(lpszPath);
2053 /*************************************************************************
2054 * PathIsFileSpecW [SHLWAPI.@]
2056 * See PathIsFileSpecA.
2058 BOOL WINAPI PathIsFileSpecW(LPCWSTR lpszPath)
2060 TRACE("(%s)\n", debugstr_w(lpszPath));
2067 if (*lpszPath == '\\' || *lpszPath == ':')
2069 lpszPath = CharNextW(lpszPath);
2074 /*************************************************************************
2075 * PathIsPrefixA [SHLWAPI.@]
2077 * Determine if a path is a prefix of another.
2080 * lpszPrefix [I] Prefix
2081 * lpszPath [I] Path to check
2084 * TRUE If lpszPath has lpszPrefix as its prefix,
2085 * FALSE If either path is NULL or lpszPrefix is not a prefix
2087 BOOL WINAPI PathIsPrefixA (LPCSTR lpszPrefix, LPCSTR lpszPath)
2089 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix), debugstr_a(lpszPath));
2091 if (lpszPrefix && lpszPath &&
2092 PathCommonPrefixA(lpszPath, lpszPrefix, NULL) == (int)strlen(lpszPrefix))
2097 /*************************************************************************
2098 * PathIsPrefixW [SHLWAPI.@]
2100 * See PathIsPrefixA.
2102 BOOL WINAPI PathIsPrefixW(LPCWSTR lpszPrefix, LPCWSTR lpszPath)
2104 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix), debugstr_w(lpszPath));
2106 if (lpszPrefix && lpszPath &&
2107 PathCommonPrefixW(lpszPath, lpszPrefix, NULL) == (int)strlenW(lpszPrefix))
2112 /*************************************************************************
2113 * PathIsSystemFolderA [SHLWAPI.@]
2115 * Determine if a path or file attributes are a system folder.
2118 * lpszPath [I] Path to check.
2119 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2122 * TRUE If lpszPath or dwAttrib are a system folder.
2123 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2125 BOOL WINAPI PathIsSystemFolderA(LPCSTR lpszPath, DWORD dwAttrib)
2127 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath), dwAttrib);
2129 if (lpszPath && *lpszPath)
2130 dwAttrib = GetFileAttributesA(lpszPath);
2132 if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2133 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2138 /*************************************************************************
2139 * PathIsSystemFolderW [SHLWAPI.@]
2141 * See PathIsSystemFolderA.
2143 BOOL WINAPI PathIsSystemFolderW(LPCWSTR lpszPath, DWORD dwAttrib)
2145 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath), dwAttrib);
2147 if (lpszPath && *lpszPath)
2148 dwAttrib = GetFileAttributesW(lpszPath);
2150 if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2151 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2156 /*************************************************************************
2157 * PathIsUNCA [SHLWAPI.@]
2159 * Determine if a path is in UNC format.
2162 * lpszPath [I] Path to check
2165 * TRUE: The path is UNC.
2166 * FALSE: The path is not UNC or is NULL.
2168 BOOL WINAPI PathIsUNCA(LPCSTR lpszPath)
2170 TRACE("(%s)\n",debugstr_a(lpszPath));
2172 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2177 /*************************************************************************
2178 * PathIsUNCW [SHLWAPI.@]
2182 BOOL WINAPI PathIsUNCW(LPCWSTR lpszPath)
2184 TRACE("(%s)\n",debugstr_w(lpszPath));
2186 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2191 /*************************************************************************
2192 * PathIsUNCServerA [SHLWAPI.@]
2194 * Determine if a path is a UNC server name ("\\SHARENAME").
2197 * lpszPath [I] Path to check.
2200 * TRUE If lpszPath is a valid UNC server name.
2204 * This routine is bug compatible with Win32: Server names with a
2205 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2206 * Fixing this bug may break other shlwapi functions!
2208 BOOL WINAPI PathIsUNCServerA(LPCSTR lpszPath)
2210 TRACE("(%s)\n", debugstr_a(lpszPath));
2212 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2216 if (*lpszPath == '\\')
2218 lpszPath = CharNextA(lpszPath);
2225 /*************************************************************************
2226 * PathIsUNCServerW [SHLWAPI.@]
2228 * See PathIsUNCServerA.
2230 BOOL WINAPI PathIsUNCServerW(LPCWSTR lpszPath)
2232 TRACE("(%s)\n", debugstr_w(lpszPath));
2234 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2238 if (*lpszPath == '\\')
2240 lpszPath = CharNextW(lpszPath);
2247 /*************************************************************************
2248 * PathIsUNCServerShareA [SHLWAPI.@]
2250 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2253 * lpszPath [I] Path to check.
2256 * TRUE If lpszPath is a valid UNC server share.
2260 * This routine is bug compatible with Win32: Server shares with a
2261 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2262 * Fixing this bug may break other shlwapi functions!
2264 BOOL WINAPI PathIsUNCServerShareA(LPCSTR lpszPath)
2266 TRACE("(%s)\n", debugstr_a(lpszPath));
2268 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2270 BOOL bSeenSlash = FALSE;
2273 if (*lpszPath == '\\')
2279 lpszPath = CharNextA(lpszPath);
2286 /*************************************************************************
2287 * PathIsUNCServerShareW [SHLWAPI.@]
2289 * See PathIsUNCServerShareA.
2291 BOOL WINAPI PathIsUNCServerShareW(LPCWSTR lpszPath)
2293 TRACE("(%s)\n", debugstr_w(lpszPath));
2295 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2297 BOOL bSeenSlash = FALSE;
2300 if (*lpszPath == '\\')
2306 lpszPath = CharNextW(lpszPath);
2313 /*************************************************************************
2314 * PathCanonicalizeA [SHLWAPI.@]
2316 * Convert a path to its canonical form.
2319 * lpszBuf [O] Output path
2320 * lpszPath [I] Path to cnonicalize
2323 * Success: TRUE. lpszBuf contains the output path,
2324 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2326 BOOL WINAPI PathCanonicalizeA(LPSTR lpszBuf, LPCSTR lpszPath)
2330 TRACE("(%p,%s)\n", lpszBuf, debugstr_a(lpszPath));
2335 if (!lpszBuf || !lpszPath)
2336 SetLastError(ERROR_INVALID_PARAMETER);
2339 WCHAR szPath[MAX_PATH];
2340 WCHAR szBuff[MAX_PATH];
2341 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2342 bRet = PathCanonicalizeW(szBuff, szPath);
2343 WideCharToMultiByte(0,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
2349 /*************************************************************************
2350 * PathCanonicalizeW [SHLWAPI.@]
2352 * See PathCanonicalizeA.
2354 BOOL WINAPI PathCanonicalizeW(LPWSTR lpszBuf, LPCWSTR lpszPath)
2356 LPWSTR lpszDst = lpszBuf;
2357 LPCWSTR lpszSrc = lpszPath;
2359 TRACE("(%p,%s)\n", lpszBuf, debugstr_w(lpszPath));
2364 if (!lpszBuf || !lpszPath)
2366 SetLastError(ERROR_INVALID_PARAMETER);
2377 /* Copy path root */
2378 if (*lpszSrc == '\\')
2380 *lpszDst++ = *lpszSrc++;
2382 else if (*lpszSrc && lpszSrc[1] == ':')
2385 *lpszDst++ = *lpszSrc++;
2386 *lpszDst++ = *lpszSrc++;
2387 if (*lpszSrc == '\\')
2388 *lpszDst++ = *lpszSrc++;
2391 /* Canonicalize the rest of the path */
2394 if (*lpszSrc == '.')
2396 if (lpszSrc[1] == '\\' && (lpszSrc == lpszPath || lpszSrc[-1] == '\\' || lpszSrc[-1] == ':'))
2398 lpszSrc += 2; /* Skip .\ */
2400 else if (lpszSrc[1] == '.' && (lpszDst == lpszBuf || lpszDst[-1] == '\\'))
2402 /* \.. backs up a directory, over the root if it has no \ following X:.
2403 * .. is ignored if it would remove a UNC server name or inital \\
2405 if (lpszDst != lpszBuf)
2407 *lpszDst = '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2408 if (lpszDst > lpszBuf+1 && lpszDst[-1] == '\\' &&
2409 (lpszDst[-2] != '\\' || lpszDst > lpszBuf+2))
2411 if (lpszDst[-2] == ':' && (lpszDst > lpszBuf+3 || lpszDst[-3] == ':'))
2414 while (lpszDst > lpszBuf && *lpszDst != '\\')
2416 if (*lpszDst == '\\')
2417 lpszDst++; /* Reset to last '\' */
2419 lpszDst = lpszBuf; /* Start path again from new root */
2421 else if (lpszDst[-2] != ':' && !PathIsUNCServerShareW(lpszBuf))
2424 while (lpszDst > lpszBuf && *lpszDst != '\\')
2426 if (lpszDst == lpszBuf)
2432 lpszSrc += 2; /* Skip .. in src path */
2435 *lpszDst++ = *lpszSrc++;
2438 *lpszDst++ = *lpszSrc++;
2440 /* Append \ to naked drive specs */
2441 if (lpszDst - lpszBuf == 2 && lpszDst[-1] == ':')
2447 /*************************************************************************
2448 * PathFindNextComponentA [SHLWAPI.@]
2450 * Find the next component in a path.
2453 * lpszPath [I] Path to find next component in
2456 * Success: A pointer to the next component, or the end of the string.
2457 * Failure: NULL, If lpszPath is invalid
2460 * A 'component' is either a backslash character (\) or UNC marker (\\).
2461 * Because of this, relative paths (e.g "c:foo") are regarded as having
2462 * only one component.
2464 LPSTR WINAPI PathFindNextComponentA(LPCSTR lpszPath)
2468 TRACE("(%s)\n", debugstr_a(lpszPath));
2470 if(!lpszPath || !*lpszPath)
2473 if ((lpszSlash = StrChrA(lpszPath, '\\')))
2475 if (lpszSlash[1] == '\\')
2477 return lpszSlash + 1;
2479 return (LPSTR)lpszPath + strlen(lpszPath);
2482 /*************************************************************************
2483 * PathFindNextComponentW [SHLWAPI.@]
2485 * See PathFindNextComponentA.
2487 LPWSTR WINAPI PathFindNextComponentW(LPCWSTR lpszPath)
2491 TRACE("(%s)\n", debugstr_w(lpszPath));
2493 if(!lpszPath || !*lpszPath)
2496 if ((lpszSlash = StrChrW(lpszPath, '\\')))
2498 if (lpszSlash[1] == '\\')
2500 return lpszSlash + 1;
2502 return (LPWSTR)lpszPath + strlenW(lpszPath);
2505 /*************************************************************************
2506 * PathAddExtensionA [SHLWAPI.@]
2508 * Add a file extension to a path
2511 * lpszPath [I/O] Path to add extension to
2512 * lpszExtension [I] Extension to add to lpszPath
2515 * TRUE If the path was modified,
2516 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2517 * extension allready, or the new path length is too big.
2520 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2521 * does not do this, so the behaviour was removed.
2523 BOOL WINAPI PathAddExtensionA(LPSTR lpszPath, LPCSTR lpszExtension)
2527 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExtension));
2529 if (!lpszPath || !lpszExtension || *(PathFindExtensionA(lpszPath)))
2532 dwLen = strlen(lpszPath);
2534 if (dwLen + strlen(lpszExtension) >= MAX_PATH)
2537 strcpy(lpszPath + dwLen, lpszExtension);
2541 /*************************************************************************
2542 * PathAddExtensionW [SHLWAPI.@]
2544 * See PathAddExtensionA.
2546 BOOL WINAPI PathAddExtensionW(LPWSTR lpszPath, LPCWSTR lpszExtension)
2550 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExtension));
2552 if (!lpszPath || !lpszExtension || *(PathFindExtensionW(lpszPath)))
2555 dwLen = strlenW(lpszPath);
2557 if (dwLen + strlenW(lpszExtension) >= MAX_PATH)
2560 strcpyW(lpszPath + dwLen, lpszExtension);
2564 /*************************************************************************
2565 * PathMakePrettyA [SHLWAPI.@]
2567 * Convert an uppercase DOS filename into lowercase.
2570 * lpszPath [I/O] Path to convert.
2573 * TRUE If the path was an uppercase DOS path and was converted,
2576 BOOL WINAPI PathMakePrettyA(LPSTR lpszPath)
2578 LPSTR pszIter = lpszPath;
2580 TRACE("(%s)\n", debugstr_a(lpszPath));
2582 if (!pszIter || !*pszIter)
2587 if (islower(*pszIter) || IsDBCSLeadByte(*pszIter))
2588 return FALSE; /* Not DOS path */
2591 pszIter = lpszPath + 1;
2594 *pszIter = tolower(*pszIter);
2600 /*************************************************************************
2601 * PathMakePrettyW [SHLWAPI.@]
2603 * See PathMakePrettyA.
2605 BOOL WINAPI PathMakePrettyW(LPWSTR lpszPath)
2607 LPWSTR pszIter = lpszPath;
2609 TRACE("(%s)\n", debugstr_w(lpszPath));
2611 if (!pszIter || !*pszIter)
2616 if (islowerW(*pszIter))
2617 return FALSE; /* Not DOS path */
2620 pszIter = lpszPath + 1;
2623 *pszIter = tolowerW(*pszIter);
2629 /*************************************************************************
2630 * PathCommonPrefixA [SHLWAPI.@]
2632 * Determine the length of the common prefix between two paths.
2635 * lpszFile1 [I] First path for comparison
2636 * lpszFile2 [I] Second path for comparison
2637 * achPath [O] Destination for common prefix string
2640 * The length of the common prefix. This is 0 if there is no common
2641 * prefix between the paths or if any parameters are invalid. If the prefix
2642 * is non-zero and achPath is not NULL, achPath is filled with the common
2643 * part of the prefix and NUL terminated.
2646 * A common prefix of 2 is always returned as 3. It is thus possible for
2647 * the length returned to be invalid (i.e. Longer than one or both of the
2648 * strings given as parameters). This Win32 behaviour has been implemented
2649 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2650 * To work around this when using this function, always check that the byte
2651 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2653 int WINAPI PathCommonPrefixA(LPCSTR lpszFile1, LPCSTR lpszFile2, LPSTR achPath)
2656 LPCSTR lpszIter1 = lpszFile1;
2657 LPCSTR lpszIter2 = lpszFile2;
2659 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1), debugstr_a(lpszFile2), achPath);
2664 if (!lpszFile1 || !lpszFile2)
2667 /* Handle roots first */
2668 if (PathIsUNCA(lpszFile1))
2670 if (!PathIsUNCA(lpszFile2))
2675 else if (PathIsUNCA(lpszFile2))
2676 return 0; /* Know already lpszFile1 is not UNC */
2681 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2682 (!*lpszIter2 || *lpszIter2 == '\\'))
2683 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2685 if (!*lpszIter1 || (tolower(*lpszIter1) != tolower(*lpszIter2)))
2686 break; /* Strings differ at this point */
2693 iLen++; /* Feature/Bug compatible with Win32 */
2695 if (iLen && achPath)
2697 memcpy(achPath,lpszFile1,iLen);
2698 achPath[iLen] = '\0';
2703 /*************************************************************************
2704 * PathCommonPrefixW [SHLWAPI.@]
2706 * See PathCommonPrefixA.
2708 int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPath)
2711 LPCWSTR lpszIter1 = lpszFile1;
2712 LPCWSTR lpszIter2 = lpszFile2;
2714 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1), debugstr_w(lpszFile2), achPath);
2719 if (!lpszFile1 || !lpszFile2)
2722 /* Handle roots first */
2723 if (PathIsUNCW(lpszFile1))
2725 if (!PathIsUNCW(lpszFile2))
2730 else if (PathIsUNCW(lpszFile2))
2731 return 0; /* Know already lpszFile1 is not UNC */
2736 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2737 (!*lpszIter2 || *lpszIter2 == '\\'))
2738 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2740 if (!*lpszIter1 || (tolowerW(*lpszIter1) != tolowerW(*lpszIter2)))
2741 break; /* Strings differ at this point */
2748 iLen++; /* Feature/Bug compatible with Win32 */
2750 if (iLen && achPath)
2752 memcpy(achPath,lpszFile1,iLen * sizeof(WCHAR));
2753 achPath[iLen] = '\0';
2758 /*************************************************************************
2759 * PathCompactPathA [SHLWAPI.@]
2761 * Make a path fit into a given width when printed to a DC.
2764 * hDc [I] Destination DC
2765 * lpszPath [I/O] Path to be printed to hDc
2766 * dx [I] Desired width
2769 * TRUE If the path was modified.
2772 BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx)
2776 TRACE("(%p,%s,%d)\n", hDC, debugstr_a(lpszPath), dx);
2780 WCHAR szPath[MAX_PATH];
2781 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2782 bRet = PathCompactPathW(hDC, szPath, dx);
2783 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
2788 /*************************************************************************
2789 * PathCompactPathW [SHLWAPI.@]
2791 * See PathCompactPathA.
2793 BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
2795 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
2798 WCHAR buff[MAX_PATH];
2802 TRACE("(%p,%s,%d)\n", hDC, debugstr_w(lpszPath), dx);
2808 hdc = hDC = GetDC(0);
2810 /* Get the length of the whole path */
2811 dwLen = strlenW(lpszPath);
2812 GetTextExtentPointW(hDC, lpszPath, dwLen, &size);
2814 if ((UINT)size.cx > dx)
2816 /* Path too big, must reduce it */
2818 DWORD dwEllipsesLen = 0, dwPathLen = 0;
2820 sFile = PathFindFileNameW(lpszPath);
2821 if (sFile != lpszPath)
2822 sFile = CharPrevW(lpszPath, sFile);
2824 /* Get the size of ellipses */
2825 GetTextExtentPointW(hDC, szEllipses, 3, &size);
2826 dwEllipsesLen = size.cx;
2827 /* Get the size of the file name */
2828 GetTextExtentPointW(hDC, sFile, strlenW(sFile), &size);
2829 dwPathLen = size.cx;
2831 if (sFile != lpszPath)
2833 LPWSTR sPath = sFile;
2834 BOOL bEllipses = FALSE;
2836 /* The path includes a file name. Include as much of the path prior to
2837 * the file name as possible, allowing for the ellipses, e.g:
2838 * c:\some very long path\filename ==> c:\some v...\filename
2840 strncpyW(buff, sFile, MAX_PATH);
2844 DWORD dwTotalLen = bEllipses? dwPathLen + dwEllipsesLen : dwPathLen;
2846 GetTextExtentPointW(hDC, lpszPath, sPath - lpszPath, &size);
2847 dwTotalLen += size.cx;
2848 if (dwTotalLen <= dx)
2850 sPath = CharPrevW(lpszPath, sPath);
2854 sPath = CharPrevW(lpszPath, sPath);
2855 sPath = CharPrevW(lpszPath, sPath);
2857 } while (sPath > lpszPath);
2859 if (sPath > lpszPath)
2863 strcpyW(sPath, szEllipses);
2864 strcpyW(sPath+3, buff);
2869 strcpyW(lpszPath, szEllipses);
2870 strcpyW(lpszPath+3, buff);
2875 /* Trim the path by adding ellipses to the end, e.g:
2876 * A very long file name.txt ==> A very...
2878 dwLen = strlenW(lpszPath);
2880 if (dwLen > MAX_PATH - 3)
2881 dwLen = MAX_PATH - 3;
2882 strncpyW(buff, sFile, dwLen);
2886 GetTextExtentPointW(hDC, buff, dwLen, &size);
2887 } while (dwLen && size.cx + dwEllipsesLen > dx);
2891 DWORD dwWritten = 0;
2893 dwEllipsesLen /= 3; /* Size of a single '.' */
2895 /* Write as much of the Ellipses string as possible */
2896 while (dwWritten + dwEllipsesLen < dx && dwLen < 3)
2899 dwWritten += dwEllipsesLen;
2907 strcpyW(buff + dwLen, szEllipses);
2908 strcpyW(lpszPath, buff);
2919 /*************************************************************************
2920 * PathGetCharTypeA [SHLWAPI.@]
2922 * Categorise a character from a file path.
2925 * ch [I] Character to get the type of
2928 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2930 UINT WINAPI PathGetCharTypeA(UCHAR ch)
2932 return PathGetCharTypeW(ch);
2935 /*************************************************************************
2936 * PathGetCharTypeW [SHLWAPI.@]
2938 * See PathGetCharTypeA.
2940 UINT WINAPI PathGetCharTypeW(WCHAR ch)
2944 TRACE("(%d)\n", ch);
2946 if (!ch || ch < ' ' || ch == '<' || ch == '>' ||
2947 ch == '"' || ch == '|' || ch == '/')
2948 flags = GCT_INVALID; /* Invalid */
2949 else if (ch == '*' || ch=='?')
2950 flags = GCT_WILD; /* Wildchars */
2951 else if ((ch == '\\') || (ch == ':'))
2952 return GCT_SEPARATOR; /* Path separators */
2957 if ((ch & 0x1 && ch != ';') || !ch || isalnum(ch) || ch == '$' || ch == '&' || ch == '(' ||
2958 ch == '.' || ch == '@' || ch == '^' ||
2959 ch == '\'' || ch == 130 || ch == '`')
2960 flags |= GCT_SHORTCHAR; /* All these are valid for DOS */
2963 flags |= GCT_SHORTCHAR; /* Bug compatible with win32 */
2964 flags |= GCT_LFNCHAR; /* Valid for long file names */
2969 /*************************************************************************
2970 * SHLWAPI_UseSystemForSystemFolders
2972 * Internal helper for PathMakeSystemFolderW.
2974 static BOOL WINAPI SHLWAPI_UseSystemForSystemFolders()
2976 static BOOL bCheckedReg = FALSE;
2977 static BOOL bUseSystemForSystemFolders = FALSE;
2983 /* Key tells Win what file attributes to use on system folders */
2984 if (SHGetValueA(HKEY_LOCAL_MACHINE,
2985 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2986 "UseSystemForSystemFolders", 0, 0, 0))
2987 bUseSystemForSystemFolders = TRUE;
2989 return bUseSystemForSystemFolders;
2992 /*************************************************************************
2993 * PathMakeSystemFolderA [SHLWAPI.@]
2995 * Set system folder attribute for a path.
2998 * lpszPath [I] The path to turn into a system folder
3001 * TRUE If the path was changed to/already was a system folder
3002 * FALSE If the path is invalid or SetFileAttributesA() fails
3004 BOOL WINAPI PathMakeSystemFolderA(LPCSTR lpszPath)
3008 TRACE("(%s)\n", debugstr_a(lpszPath));
3010 if (lpszPath && *lpszPath)
3012 WCHAR szPath[MAX_PATH];
3013 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
3014 bRet = PathMakeSystemFolderW(szPath);
3019 /*************************************************************************
3020 * PathMakeSystemFolderW [SHLWAPI.@]
3022 * See PathMakeSystemFolderA.
3024 BOOL WINAPI PathMakeSystemFolderW(LPCWSTR lpszPath)
3026 DWORD dwDefaultAttr = FILE_ATTRIBUTE_READONLY, dwAttr;
3027 WCHAR buff[MAX_PATH];
3029 TRACE("(%s)\n", debugstr_w(lpszPath));
3031 if (!lpszPath || !*lpszPath)
3034 /* If the directory is already a system directory, don't do anything */
3035 GetSystemDirectoryW(buff, MAX_PATH);
3036 if (!strcmpW(buff, lpszPath))
3039 GetWindowsDirectoryW(buff, MAX_PATH);
3040 if (!strcmpW(buff, lpszPath))
3043 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3044 if (SHLWAPI_UseSystemForSystemFolders())
3045 dwDefaultAttr = FILE_ATTRIBUTE_SYSTEM;
3047 if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
3050 /* Change file attributes to system attributes */
3051 dwAttr &= ~(FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_READONLY);
3052 return SetFileAttributesW(lpszPath, dwAttr | dwDefaultAttr);
3055 /*************************************************************************
3056 * PathRenameExtensionA [SHLWAPI.@]
3058 * Swap the file extension in a path with another extension.
3061 * lpszPath [I/O] Path to swap the extension in
3062 * lpszExt [I] The new extension
3065 * TRUE if lpszPath was modified,
3066 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3068 BOOL WINAPI PathRenameExtensionA(LPSTR lpszPath, LPCSTR lpszExt)
3070 LPSTR lpszExtension;
3072 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExt));
3074 lpszExtension = PathFindExtensionA(lpszPath);
3076 if (!lpszExtension || (lpszExtension - lpszPath + strlen(lpszExt) >= MAX_PATH))
3079 strcpy(lpszExtension, lpszExt);
3083 /*************************************************************************
3084 * PathRenameExtensionW [SHLWAPI.@]
3086 * See PathRenameExtensionA.
3088 BOOL WINAPI PathRenameExtensionW(LPWSTR lpszPath, LPCWSTR lpszExt)
3090 LPWSTR lpszExtension;
3092 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExt));
3094 lpszExtension = PathFindExtensionW(lpszPath);
3096 if (!lpszExtension || (lpszExtension - lpszPath + strlenW(lpszExt) >= MAX_PATH))
3099 strcpyW(lpszExtension, lpszExt);
3103 /*************************************************************************
3104 * PathSearchAndQualifyA [SHLWAPI.@]
3106 * Determine if a given path is correct and fully qualified.
3109 * lpszPath [I] Path to check
3110 * lpszBuf [O] Output for correct path
3111 * cchBuf [I] Size of lpszBuf
3116 BOOL WINAPI PathSearchAndQualifyA(LPCSTR lpszPath, LPSTR lpszBuf, UINT cchBuf)
3118 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath), lpszBuf, cchBuf);
3122 /*************************************************************************
3123 * PathSearchAndQualifyW [SHLWAPI.@]
3125 * See PathSearchAndQualifyA.
3127 BOOL WINAPI PathSearchAndQualifyW(LPCWSTR lpszPath, LPWSTR lpszBuf, UINT cchBuf)
3129 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath), lpszBuf, cchBuf);
3133 /*************************************************************************
3134 * PathSkipRootA [SHLWAPI.@]
3136 * Return the portion of a path following the drive letter or mount point.
3139 * lpszPath [I] The path to skip on
3142 * Success: A pointer to the next character after the root.
3143 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3145 LPSTR WINAPI PathSkipRootA(LPCSTR lpszPath)
3147 TRACE("(%s)\n", debugstr_a(lpszPath));
3149 if (!lpszPath || !*lpszPath)
3152 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3154 /* Network share: skip share server and mount point */
3156 if ((lpszPath = StrChrA(lpszPath, '\\')) &&
3157 (lpszPath = StrChrA(lpszPath + 1, '\\')))
3159 return (LPSTR)lpszPath;
3162 if (IsDBCSLeadByte(*lpszPath))
3166 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3167 return (LPSTR)lpszPath + 3;
3171 /*************************************************************************
3172 * PathSkipRootW [SHLWAPI.@]
3174 * See PathSkipRootA.
3176 LPWSTR WINAPI PathSkipRootW(LPCWSTR lpszPath)
3178 TRACE("(%s)\n", debugstr_w(lpszPath));
3180 if (!lpszPath || !*lpszPath)
3183 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3185 /* Network share: skip share server and mount point */
3187 if ((lpszPath = StrChrW(lpszPath, '\\')) &&
3188 (lpszPath = StrChrW(lpszPath + 1, '\\')))
3190 return (LPWSTR)lpszPath;
3194 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3195 return (LPWSTR)lpszPath + 3;
3199 /*************************************************************************
3200 * PathCreateFromUrlA [SHLWAPI.@]
3202 * Create a path from a URL
3205 * lpszUrl [I] URL to convert into a path
3206 * lpszPath [O] Output buffer for the resulting Path
3207 * pcchPath [I] Length of lpszPath
3208 * dwFlags [I] Flags controlling the conversion
3211 * Success: S_OK. lpszPath contains the URL in path format,
3212 * Failure: An HRESULT error code such as E_INVALIDARG.
3214 HRESULT WINAPI PathCreateFromUrlA(LPCSTR lpszUrl, LPSTR lpszPath,
3215 LPDWORD pcchPath, DWORD dwFlags)
3218 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_a(lpszUrl), lpszPath, pcchPath, dwFlags);
3220 if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
3221 return E_INVALIDARG;
3223 pszPathPart = StrChrA(lpszUrl, ':');
3224 if ((((pszPathPart - lpszUrl) == 1) && isalpha(*lpszUrl)) ||
3225 !lstrcmpA(lpszUrl, "file:"))
3227 return UrlUnescapeA(pszPathPart, lpszPath, pcchPath, dwFlags);
3229 /* extracts thing prior to : in pszURL and checks against:
3233 * about - if match returns E_INVALIDARG
3236 return E_INVALIDARG;
3239 /*************************************************************************
3240 * PathCreateFromUrlW [SHLWAPI.@]
3242 * See PathCreateFromUrlA.
3244 HRESULT WINAPI PathCreateFromUrlW(LPCWSTR lpszUrl, LPWSTR lpszPath,
3245 LPDWORD pcchPath, DWORD dwFlags)
3247 static const WCHAR stemp[] = { 'f','i','l','e',':','/','/',0 };
3248 LPWSTR pwszPathPart;
3251 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_w(lpszUrl), lpszPath, pcchPath, dwFlags);
3253 if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
3254 return E_INVALIDARG;
3256 /* Path of the form file://... */
3257 if (!strncmpW(lpszUrl, stemp, 7))
3261 /* Path of the form file:... */
3262 else if (!strncmpW(lpszUrl, stemp, 5))
3267 /* Ensure that path is of the form c:... or c|... */
3268 if (lpszUrl[1] != ':' && lpszUrl[1] != '|' && isalphaW(*lpszUrl))
3269 return E_INVALIDARG;
3271 hr = UrlUnescapeW((LPWSTR) lpszUrl, lpszPath, pcchPath, dwFlags);
3272 if (lpszPath[1] == '|')
3275 for (pwszPathPart = lpszPath; *pwszPathPart; pwszPathPart++)
3276 if (*pwszPathPart == '/')
3277 *pwszPathPart = '\\';
3279 TRACE("Returning %s\n",debugstr_w(lpszPath));
3284 /*************************************************************************
3285 * PathRelativePathToA [SHLWAPI.@]
3287 * Create a relative path from one path to another.
3290 * lpszPath [O] Destination for relative path
3291 * lpszFrom [I] Source path
3292 * dwAttrFrom [I] File attribute of source path
3293 * lpszTo [I] Destination path
3294 * dwAttrTo [I] File attributes of destination path
3297 * TRUE If a relative path can be formed. lpszPath contains the new path
3298 * FALSE If the paths are not relavtive or any parameters are invalid
3301 * lpszTo should be at least MAX_PATH in length.
3303 * Calling this function with relative paths for lpszFrom or lpszTo may
3304 * give erroneous results.
3306 * The Win32 version of this function contains a bug where the lpszTo string
3307 * may be referenced 1 byte beyond the end of the string. As a result random
3308 * garbage may be written to the output path, depending on what lies beyond
3309 * the last byte of the string. This bug occurs because of the behaviour of
3310 * PathCommonPrefix() (see notes for that function), and no workaround seems
3311 * possible with Win32.
3313 * This bug has been fixed here, so for example the relative path from "\\"
3314 * to "\\" is correctly determined as "." in this implementation.
3316 BOOL WINAPI PathRelativePathToA(LPSTR lpszPath, LPCSTR lpszFrom, DWORD dwAttrFrom,
3317 LPCSTR lpszTo, DWORD dwAttrTo)
3321 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_a(lpszFrom),
3322 dwAttrFrom, debugstr_a(lpszTo), dwAttrTo);
3324 if(lpszPath && lpszFrom && lpszTo)
3326 WCHAR szPath[MAX_PATH];
3327 WCHAR szFrom[MAX_PATH];
3328 WCHAR szTo[MAX_PATH];
3329 MultiByteToWideChar(0,0,lpszFrom,-1,szFrom,MAX_PATH);
3330 MultiByteToWideChar(0,0,lpszTo,-1,szTo,MAX_PATH);
3331 bRet = PathRelativePathToW(szPath,szFrom,dwAttrFrom,szTo,dwAttrTo);
3332 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
3337 /*************************************************************************
3338 * PathRelativePathToW [SHLWAPI.@]
3340 * See PathRelativePathToA.
3342 BOOL WINAPI PathRelativePathToW(LPWSTR lpszPath, LPCWSTR lpszFrom, DWORD dwAttrFrom,
3343 LPCWSTR lpszTo, DWORD dwAttrTo)
3345 static const WCHAR szPrevDirSlash[] = { '.', '.', '\\', '\0' };
3346 static const WCHAR szPrevDir[] = { '.', '.', '\0' };
3347 WCHAR szFrom[MAX_PATH];
3348 WCHAR szTo[MAX_PATH];
3351 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_w(lpszFrom),
3352 dwAttrFrom, debugstr_w(lpszTo), dwAttrTo);
3354 if(!lpszPath || !lpszFrom || !lpszTo)
3358 strncpyW(szFrom, lpszFrom, MAX_PATH);
3359 strncpyW(szTo, lpszTo, MAX_PATH);
3361 if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
3362 PathRemoveFileSpecW(szFrom);
3363 if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
3364 PathRemoveFileSpecW(szTo);
3366 /* Paths can only be relative if they have a common root */
3367 if(!(dwLen = PathCommonPrefixW(szFrom, szTo, 0)))
3370 /* Strip off lpszFrom components to the root, by adding "..\" */
3371 lpszFrom = szFrom + dwLen;
3377 if (*lpszFrom == '\\')
3382 lpszFrom = PathFindNextComponentW(lpszFrom);
3383 strcatW(lpszPath, *lpszFrom ? szPrevDirSlash : szPrevDir);
3386 /* From the root add the components of lpszTo */
3388 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3391 if (*lpszTo && lpszTo[-1])
3393 if (*lpszTo != '\\')
3395 dwLen = strlenW(lpszPath);
3396 if (dwLen + strlenW(lpszTo) >= MAX_PATH)
3401 strcpyW(lpszPath + dwLen, lpszTo);
3406 /*************************************************************************
3407 * PathUnmakeSystemFolderA [SHLWAPI.@]
3409 * Remove the system folder attributes from a path.
3412 * lpszPath [I] The path to remove attributes from
3416 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3417 * SetFileAttributesA() fails.
3419 BOOL WINAPI PathUnmakeSystemFolderA(LPCSTR lpszPath)
3423 TRACE("(%s)\n", debugstr_a(lpszPath));
3425 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
3426 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3429 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3430 return SetFileAttributesA(lpszPath, dwAttr);
3433 /*************************************************************************
3434 * PathUnmakeSystemFolderW [SHLWAPI.@]
3436 * See PathUnmakeSystemFolderA.
3438 BOOL WINAPI PathUnmakeSystemFolderW(LPCWSTR lpszPath)
3442 TRACE("(%s)\n", debugstr_w(lpszPath));
3444 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
3445 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3448 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3449 return SetFileAttributesW(lpszPath, dwAttr);
3453 /*************************************************************************
3454 * PathSetDlgItemPathA [SHLWAPI.@]
3456 * Set the text of a dialog item to a path, shrinking the path to fit
3457 * if it is too big for the item.
3460 * hDlg [I] Dialog handle
3461 * id [I] ID of item in the dialog
3462 * lpszPath [I] Path to set as the items text
3468 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3469 * window text is erased).
3471 VOID WINAPI PathSetDlgItemPathA(HWND hDlg, int id, LPCSTR lpszPath)
3473 WCHAR szPath[MAX_PATH];
3475 TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_a(lpszPath));
3478 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
3481 PathSetDlgItemPathW(hDlg, id, szPath);
3484 /*************************************************************************
3485 * PathSetDlgItemPathW [SHLWAPI.@]
3487 * See PathSetDlgItemPathA.
3489 VOID WINAPI PathSetDlgItemPathW(HWND hDlg, int id, LPCWSTR lpszPath)
3491 WCHAR path[MAX_PATH + 1];
3497 TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_w(lpszPath));
3499 if (!(hwItem = GetDlgItem(hDlg, id)))
3503 strncpyW(path, lpszPath, sizeof(path));
3507 GetClientRect(hwItem, &rect);
3509 hPrevObj = SelectObject(hdc, (HGDIOBJ)SendMessageW(hwItem,WM_GETFONT,0,0));
3513 PathCompactPathW(hdc, path, rect.right);
3514 SelectObject(hdc, hPrevObj);
3517 ReleaseDC(hDlg, hdc);
3518 SetWindowTextW(hwItem, path);
3521 /*************************************************************************
3522 * PathIsNetworkPathA [SHLWAPI.@]
3524 * Determine if the given path is a network path.
3527 * lpszPath [I] Path to check
3530 * TRUE If lpszPath is a UNC share or mapped network drive, or
3531 * FALSE If lpszPath is a local drive or cannot be determined
3533 BOOL WINAPI PathIsNetworkPathA(LPCSTR lpszPath)
3537 TRACE("(%s)\n",debugstr_a(lpszPath));
3541 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3543 dwDriveNum = PathGetDriveNumberA(lpszPath);
3544 if (dwDriveNum == -1)
3546 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3547 return pIsNetDrive(dwDriveNum);
3550 /*************************************************************************
3551 * PathIsNetworkPathW [SHLWAPI.@]
3553 * See PathIsNetworkPathA.
3555 BOOL WINAPI PathIsNetworkPathW(LPCWSTR lpszPath)
3559 TRACE("(%s)\n", debugstr_w(lpszPath));
3563 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3565 dwDriveNum = PathGetDriveNumberW(lpszPath);
3566 if (dwDriveNum == -1)
3568 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3569 return pIsNetDrive(dwDriveNum);
3572 /*************************************************************************
3573 * PathIsLFNFileSpecA [SHLWAPI.@]
3575 * Determine if the given path is a long file name
3578 * lpszPath [I] Path to check
3581 * TRUE If path is a long file name,
3582 * FALSE If path is a valid DOS short file name
3584 BOOL WINAPI PathIsLFNFileSpecA(LPCSTR lpszPath)
3586 DWORD dwNameLen = 0, dwExtLen = 0;
3588 TRACE("(%s)\n",debugstr_a(lpszPath));
3595 if (*lpszPath == ' ')
3596 return TRUE; /* DOS names cannot have spaces */
3597 if (*lpszPath == '.')
3600 return TRUE; /* DOS names have only one dot */
3607 return TRUE; /* DOS extensions are <= 3 chars*/
3613 return TRUE; /* DOS names are <= 8 chars */
3615 lpszPath += IsDBCSLeadByte(*lpszPath) ? 2 : 1;
3617 return FALSE; /* Valid DOS path */
3620 /*************************************************************************
3621 * PathIsLFNFileSpecW [SHLWAPI.@]
3623 * See PathIsLFNFileSpecA.
3625 BOOL WINAPI PathIsLFNFileSpecW(LPCWSTR lpszPath)
3627 DWORD dwNameLen = 0, dwExtLen = 0;
3629 TRACE("(%s)\n",debugstr_w(lpszPath));
3636 if (*lpszPath == ' ')
3637 return TRUE; /* DOS names cannot have spaces */
3638 if (*lpszPath == '.')
3641 return TRUE; /* DOS names have only one dot */
3648 return TRUE; /* DOS extensions are <= 3 chars*/
3654 return TRUE; /* DOS names are <= 8 chars */
3658 return FALSE; /* Valid DOS path */
3661 /*************************************************************************
3662 * PathIsDirectoryEmptyA [SHLWAPI.@]
3664 * Determine if a given directory is empty.
3667 * lpszPath [I] Directory to check
3670 * TRUE If the directory exists and contains no files,
3673 BOOL WINAPI PathIsDirectoryEmptyA(LPCSTR lpszPath)
3677 TRACE("(%s)\n",debugstr_a(lpszPath));
3681 WCHAR szPath[MAX_PATH];
3682 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
3683 bRet = PathIsDirectoryEmptyW(szPath);
3688 /*************************************************************************
3689 * PathIsDirectoryEmptyW [SHLWAPI.@]
3691 * See PathIsDirectoryEmptyA.
3693 BOOL WINAPI PathIsDirectoryEmptyW(LPCWSTR lpszPath)
3695 static const WCHAR szAllFiles[] = { '*', '.', '*', '\0' };
3696 WCHAR szSearch[MAX_PATH];
3699 BOOL retVal = FALSE;
3700 WIN32_FIND_DATAW find_data;
3702 TRACE("(%s)\n",debugstr_w(lpszPath));
3704 if (!lpszPath || !PathIsDirectoryW(lpszPath))
3707 strncpyW(szSearch, lpszPath, MAX_PATH);
3708 PathAddBackslashW(szSearch);
3709 dwLen = strlenW(szSearch);
3710 if (dwLen > MAX_PATH - 4)
3713 strcpyW(szSearch + dwLen, szAllFiles);
3714 hfind = FindFirstFileW(szSearch, &find_data);
3716 if (hfind != INVALID_HANDLE_VALUE &&
3717 find_data.cFileName[0] == '.' &&
3718 find_data.cFileName[1] == '.')
3720 /* The only directory entry should be the parent */
3721 if (!FindNextFileW(hfind, &find_data))
3729 /*************************************************************************
3730 * PathFindSuffixArrayA [SHLWAPI.@]
3732 * Find a suffix string in an array of suffix strings
3735 * lpszSuffix [I] Suffix string to search for
3736 * lppszArray [I] Array of suffix strings to search
3737 * dwCount [I] Number of elements in lppszArray
3740 * Success: The index of the position of lpszSuffix in lppszArray
3741 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3744 * The search is case sensitive.
3745 * The match is made against the end of the suffix string, so for example:
3746 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3748 LPCSTR WINAPI PathFindSuffixArrayA(LPCSTR lpszSuffix, LPCSTR *lppszArray, int dwCount)
3753 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix), lppszArray, dwCount);
3755 if (lpszSuffix && lppszArray && dwCount > 0)
3757 dwLen = strlen(lpszSuffix);
3759 while (dwRet < dwCount)
3761 size_t dwCompareLen = strlen(*lppszArray);
3762 if (dwCompareLen < dwLen)
3764 if (!strcmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3765 return *lppszArray; /* Found */
3774 /*************************************************************************
3775 * PathFindSuffixArrayW [SHLWAPI.@]
3777 * See PathFindSuffixArrayA.
3779 LPCWSTR WINAPI PathFindSuffixArrayW(LPCWSTR lpszSuffix, LPCWSTR *lppszArray, int dwCount)
3784 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix), lppszArray, dwCount);
3786 if (lpszSuffix && lppszArray && dwCount > 0)
3788 dwLen = strlenW(lpszSuffix);
3790 while (dwRet < dwCount)
3792 size_t dwCompareLen = strlenW(*lppszArray);
3793 if (dwCompareLen < dwLen)
3795 if (!strcmpW(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3796 return *lppszArray; /* Found */
3805 /*************************************************************************
3806 * PathUndecorateA [SHLWAPI.@]
3808 * Undecorate a file path
3811 * lpszPath [I/O] Path to remove any decoration from
3817 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3819 VOID WINAPI PathUndecorateA(LPSTR lpszPath)
3821 TRACE("(%s)\n",debugstr_a(lpszPath));
3825 LPSTR lpszExt = PathFindExtensionA(lpszPath);
3826 if (lpszExt > lpszPath && lpszExt[-1] == ']')
3828 LPSTR lpszSkip = lpszExt - 2;
3829 if (*lpszSkip == '[')
3830 lpszSkip++; /* [] (no number) */
3832 while (lpszSkip > lpszPath && isdigit(lpszSkip[-1]))
3834 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
3836 /* remove the [n] */
3839 *lpszSkip++ = *lpszExt++;
3846 /*************************************************************************
3847 * PathUndecorateW [SHLWAPI.@]
3849 * See PathUndecorateA.
3851 VOID WINAPI PathUndecorateW(LPWSTR lpszPath)
3853 TRACE("(%s)\n",debugstr_w(lpszPath));
3857 LPWSTR lpszExt = PathFindExtensionW(lpszPath);
3858 if (lpszExt > lpszPath && lpszExt[-1] == ']')
3860 LPWSTR lpszSkip = lpszExt - 2;
3861 if (*lpszSkip == '[')
3862 lpszSkip++; /* [] (no number) */
3864 while (lpszSkip > lpszPath && isdigitW(lpszSkip[-1]))
3866 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
3868 /* remove the [n] */
3871 *lpszSkip++ = *lpszExt++;
3878 /*************************************************************************
3881 * Find localised or default web content in "%WINDOWS%\web\".
3884 * lpszFile [I] File name containing content to look for
3885 * lpszPath [O] Buffer to contain the full path to the file
3886 * dwPathLen [I] Length of lpszPath
3889 * Success: S_OK. lpszPath contains the full path to the content.
3890 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
3892 HRESULT WINAPI SHGetWebFolderFilePathA(LPCSTR lpszFile, LPSTR lpszPath, DWORD dwPathLen)
3894 WCHAR szFile[MAX_PATH], szPath[MAX_PATH];
3897 TRACE("(%s,%p,%ld)\n", lpszFile, lpszPath, dwPathLen);
3899 MultiByteToWideChar(0, 0, lpszFile, -1, szFile, MAX_PATH);
3901 hRet = SHGetWebFolderFilePathW(szFile, szPath, dwPathLen);
3902 WideCharToMultiByte(0, 0, szPath, -1, lpszPath, dwPathLen, 0, 0);
3906 /*************************************************************************
3909 * Unicode version of SHGetWebFolderFilePathA.
3911 HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR lpszFile, LPWSTR lpszPath, DWORD dwPathLen)
3913 static const WCHAR szWeb[] = {'\\','W','e','b','\\','\0'};
3914 static const WCHAR szWebMui[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
3915 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
3916 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
3917 DWORD dwLen, dwFileLen;
3918 LANGID lidSystem, lidUser;
3920 TRACE("(%s,%p,%ld)\n", debugstr_w(lpszFile), lpszPath, dwPathLen);
3922 /* Get base directory for web content */
3923 dwLen = GetSystemWindowsDirectoryW(lpszPath, dwPathLen);
3924 if (dwLen > 0 && lpszPath[dwLen-1] == '\\')
3927 dwFileLen = strlenW(lpszFile);
3929 if (dwLen + dwFileLen + szWebLen >= dwPathLen)
3930 return E_FAIL; /* lpszPath too short */
3932 strcpyW(lpszPath+dwLen, szWeb);
3934 dwPathLen = dwPathLen - dwLen; /* Remaining space */
3936 lidSystem = GetSystemDefaultUILanguage();
3937 lidUser = GetUserDefaultUILanguage();
3939 if (lidSystem != lidUser)
3941 if (dwFileLen + szWebMuiLen < dwPathLen)
3943 /* Use localised content in the users UI language if present */
3944 wsprintfW(lpszPath + dwLen, szWebMui, lidUser);
3945 strcpyW(lpszPath + dwLen + szWebMuiLen, lpszFile);
3946 if (PathFileExistsW(lpszPath))
3951 /* Fall back to OS default installed content */
3952 strcpyW(lpszPath + dwLen, lpszFile);
3953 if (PathFileExistsW(lpszPath))