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
27 #include "wine/unicode.h"
32 #define NO_SHLWAPI_STREAM
34 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell);
39 /* function pointers for GET_FUNC macro; these need to be global because of gcc bug */
40 static BOOL (WINAPI *pIsNetDrive)(DWORD);
42 /*************************************************************************
43 * PathAppendA [SHLWAPI.@]
45 * Append one path to another.
48 * lpszPath [O] Initial part of path
49 * lpszAppend [I] Path to append
52 * Success: TRUE. lpszPath contains the newly created path.
53 * Failure: FALSE, if either path is NULL, or PathCombineA fails.
56 * lpszAppend must contain at least one backslash ('\') if not NULL.
57 * Because PathCombineA is used to join the paths, the resulting
58 * path is also canonicalized.
60 BOOL WINAPI PathAppendA (LPSTR lpszPath, LPCSTR lpszAppend)
62 TRACE("(%s,%s)\n",debugstr_a(lpszPath), debugstr_a(lpszAppend));
64 if (lpszPath && lpszAppend)
66 if (!PathIsUNCA(lpszAppend))
67 while (*lpszAppend == '\\')
69 if (PathCombineA(lpszPath, lpszPath, lpszAppend))
75 /*************************************************************************
76 * PathAppendW [SHLWAPI.@]
80 BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
82 TRACE("(%s,%s)\n",debugstr_w(lpszPath), debugstr_w(lpszAppend));
84 if (lpszPath && lpszAppend)
86 if (!PathIsUNCW(lpszAppend))
87 while (*lpszAppend == '\\')
89 if (PathCombineW(lpszPath, lpszPath, lpszAppend))
95 /*************************************************************************
96 * PathCombineA [SHLWAPI.@]
98 * Combine two paths together.
101 * lpszDest [O] Destination for combined path
102 * lpszDir [I] Directory path
103 * liszFile [I] File path
106 * Success: The output path
107 * Failure: NULL, if inputs are invalid.
110 * lpszDest should be at least MAX_PATH in size, and may point to the same
111 * memory location as lpszDir. The combined path is canonicalised.
113 LPSTR WINAPI PathCombineA(LPSTR lpszDest, LPCSTR lpszDir, LPCSTR lpszFile)
115 TRACE("(%p,%s,%s)\n", lpszDest, debugstr_a(lpszDir), debugstr_a(lpszFile));
117 if (!lpszDest || (!lpszDir && !lpszFile))
118 return NULL; /* Invalid parameters */
121 WCHAR szDest[MAX_PATH];
122 WCHAR szDir[MAX_PATH];
123 WCHAR szFile[MAX_PATH];
125 MultiByteToWideChar(0,0,lpszDir,-1,szDir,MAX_PATH);
127 MultiByteToWideChar(0,0,lpszFile,-1,szFile,MAX_PATH);
128 PathCombineW(szDest, lpszDir ? szDir : NULL, lpszFile ? szFile : NULL);
129 WideCharToMultiByte(0,0,szDest,-1,lpszDest,MAX_PATH,0,0);
134 /*************************************************************************
135 * PathCombineW [SHLWAPI.@]
139 LPWSTR WINAPI PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile)
141 WCHAR szTemp[MAX_PATH];
142 BOOL bUseBoth = FALSE, bStrip = FALSE;
144 TRACE("(%p,%s,%s)\n", lpszDest, debugstr_w(lpszDir), debugstr_w(lpszFile));
146 if (!lpszDest || (!lpszDir && !lpszFile))
147 return lpszDest; /* Invalid parameters */
149 if (!lpszFile || !*lpszFile)
152 strncpyW(szTemp, lpszDir, MAX_PATH);
154 else if (!lpszDir || !*lpszDir || !PathIsRelativeW(lpszFile))
156 if (!lpszDir || !*lpszDir || *lpszFile != '\\' || PathIsUNCW(lpszFile))
159 strncpyW(szTemp, lpszFile, MAX_PATH);
172 strncpyW(szTemp, lpszDir, MAX_PATH);
175 PathStripToRootW(szTemp);
176 lpszFile++; /* Skip '\' */
178 if (!PathAddBackslashW(szTemp))
180 if (strlenW(szTemp) + strlenW(lpszFile) >= MAX_PATH)
182 strcatW(szTemp, lpszFile);
185 PathCanonicalizeW(lpszDest, szTemp);
189 /*************************************************************************
190 * PathAddBackslashA [SHLWAPI.@]
192 * Append a backslash ('\') to a path if one doesn't exist.
195 * lpszPath [O] The path to append a backslash to.
198 * Success: The position of the last backslash in the path.
199 * Failure: NULL, if lpszPath is NULL or the path is too large.
201 LPSTR WINAPI PathAddBackslashA(LPSTR lpszPath)
205 TRACE("(%s)\n",debugstr_a(lpszPath));
207 if (!lpszPath || (iLen = strlen(lpszPath)) >= MAX_PATH)
213 if (lpszPath[-1] != '\\')
222 /*************************************************************************
223 * PathAddBackslashW [SHLWAPI.@]
225 * See PathAddBackslashA.
227 LPWSTR WINAPI PathAddBackslashW( LPWSTR lpszPath )
231 TRACE("(%s)\n",debugstr_w(lpszPath));
233 if (!lpszPath || (iLen = strlenW(lpszPath)) >= MAX_PATH)
239 if (lpszPath[-1] != '\\')
248 /*************************************************************************
249 * PathBuildRootA [SHLWAPI.@]
251 * Create a root drive string (e.g. "A:\") from a drive number.
254 * lpszPath [O] Destination for the drive string
260 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
262 LPSTR WINAPI PathBuildRootA(LPSTR lpszPath, int drive)
264 TRACE("(%p,%d)\n", debugstr_a(lpszPath), drive);
266 if (lpszPath && drive >= 0 && drive < 26)
268 lpszPath[0] = 'A' + drive;
276 /*************************************************************************
277 * PathBuildRootW [SHLWAPI.@]
279 * See PathBuildRootA.
281 LPWSTR WINAPI PathBuildRootW(LPWSTR lpszPath, int drive)
283 TRACE("(%p,%d)\n",debugstr_w(lpszPath), drive);
285 if (lpszPath && drive >= 0 && drive < 26)
287 lpszPath[0] = 'A' + drive;
295 /*************************************************************************
296 * PathFindFileNameA [SHLWAPI.@]
298 * Locate the start of the file name in a path
301 * lpszPath [I] Path to search
304 * A pointer to the first character of the file name
306 LPSTR WINAPI PathFindFileNameA(LPCSTR lpszPath)
308 LPCSTR lastSlash = lpszPath;
310 TRACE("(%s)\n",debugstr_a(lpszPath));
312 while (lpszPath && *lpszPath)
314 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
315 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
316 lastSlash = lpszPath + 1;
317 lpszPath = CharNextA(lpszPath);
319 return (LPSTR)lastSlash;
322 /*************************************************************************
323 * PathFindFileNameW [SHLWAPI.@]
325 * See PathFindFileNameA.
327 LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
329 LPCWSTR lastSlash = lpszPath;
331 TRACE("(%s)\n",debugstr_w(lpszPath));
333 while (lpszPath && *lpszPath)
335 if ((*lpszPath == '\\' || *lpszPath == '/' || *lpszPath == ':') &&
336 lpszPath[1] && lpszPath[1] != '\\' && lpszPath[1] != '/')
337 lastSlash = lpszPath + 1;
338 lpszPath = CharNextW(lpszPath);
340 return (LPWSTR)lastSlash;
343 /*************************************************************************
344 * PathFindExtensionA [SHLWAPI.@]
346 * Locate the start of the file extension in a path
349 * lpszPath [I] The path to search
352 * A pointer to the first character of the extension, the end of
353 * the string if the path has no extension, or NULL If lpszPath is NULL
355 LPSTR WINAPI PathFindExtensionA( LPCSTR lpszPath )
357 LPCSTR lastpoint = NULL;
359 TRACE("(%s)\n", debugstr_a(lpszPath));
365 if (*lpszPath == '\\' || *lpszPath==' ')
367 else if (*lpszPath == '.')
368 lastpoint = lpszPath;
369 lpszPath = CharNextA(lpszPath);
372 return (LPSTR)(lastpoint ? lastpoint : lpszPath);
375 /*************************************************************************
376 * PathFindExtensionW [SHLWAPI.@]
378 * See PathFindExtensionA.
380 LPWSTR WINAPI PathFindExtensionW( LPCWSTR lpszPath )
382 LPCWSTR lastpoint = NULL;
384 TRACE("(%s)\n", debugstr_w(lpszPath));
390 if (*lpszPath == '\\' || *lpszPath==' ')
392 else if (*lpszPath == '.')
393 lastpoint = lpszPath;
394 lpszPath = CharNextW(lpszPath);
397 return (LPWSTR)(lastpoint ? lastpoint : lpszPath);
400 /*************************************************************************
401 * PathGetArgsA [SHLWAPI.@]
403 * Find the next argument in a string delimited by spaces.
406 * lpszPath [I] The string to search for arguments in
409 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
412 * Spaces in quoted strings are ignored as delimiters.
414 LPSTR WINAPI PathGetArgsA(LPCSTR lpszPath)
416 BOOL bSeenQuote = FALSE;
418 TRACE("(%s)\n",debugstr_a(lpszPath));
424 if ((*lpszPath==' ') && !bSeenQuote)
425 return (LPSTR)lpszPath + 1;
426 if (*lpszPath == '"')
427 bSeenQuote = !bSeenQuote;
428 lpszPath = CharNextA(lpszPath);
431 return (LPSTR)lpszPath;
434 /*************************************************************************
435 * PathGetArgsW [SHLWAPI.@]
439 LPWSTR WINAPI PathGetArgsW(LPCWSTR lpszPath)
441 BOOL bSeenQuote = FALSE;
443 TRACE("(%s)\n",debugstr_w(lpszPath));
449 if ((*lpszPath==' ') && !bSeenQuote)
450 return (LPWSTR)lpszPath + 1;
451 if (*lpszPath == '"')
452 bSeenQuote = !bSeenQuote;
453 lpszPath = CharNextW(lpszPath);
456 return (LPWSTR)lpszPath;
459 /*************************************************************************
460 * PathGetDriveNumberA [SHLWAPI.@]
462 * Return the drive number from a path
465 * lpszPath [I] Path to get the drive number from
468 * Success: The drive number corresponding to the drive in the path
469 * Failure: -1, if lpszPath contains no valid drive
471 int WINAPI PathGetDriveNumberA(LPCSTR lpszPath)
473 TRACE ("(%s)\n",debugstr_a(lpszPath));
475 if (lpszPath && !IsDBCSLeadByte(*lpszPath) && lpszPath[1] == ':' &&
476 tolower(*lpszPath) >= 'a' && tolower(*lpszPath) <= 'z')
477 return tolower(*lpszPath) - 'a';
481 /*************************************************************************
482 * PathGetDriveNumberW [SHLWAPI.@]
484 * See PathGetDriveNumberA.
486 int WINAPI PathGetDriveNumberW(LPCWSTR lpszPath)
488 TRACE ("(%s)\n",debugstr_w(lpszPath));
490 if (lpszPath && lpszPath[1] == ':' &&
491 tolowerW(*lpszPath) >= 'a' && tolowerW(*lpszPath) <= 'z')
492 return tolowerW(*lpszPath) - 'a';
496 /*************************************************************************
497 * PathRemoveFileSpecA [SHLWAPI.@]
499 * Remove the file specification from a path.
502 * lpszPath [O] Path to remove the file spec from
505 * TRUE If the path was valid and modified
508 BOOL WINAPI PathRemoveFileSpecA(LPSTR lpszPath)
510 LPSTR lpszFileSpec = lpszPath;
511 BOOL bModified = FALSE;
513 TRACE("(%s)\n",debugstr_a(lpszPath));
517 /* Skip directory or UNC path */
518 if (*lpszPath == '\\')
519 lpszFileSpec = ++lpszPath;
520 if (*lpszPath == '\\')
521 lpszFileSpec = ++lpszPath;
525 if(*lpszPath == '\\')
526 lpszFileSpec = lpszPath; /* Skip dir */
527 else if(*lpszPath == ':')
529 lpszFileSpec = ++lpszPath; /* Skip drive */
530 if (*lpszPath == '\\')
533 if (!(lpszPath = CharNextA(lpszPath)))
539 *lpszFileSpec = '\0';
546 /*************************************************************************
547 * PathRemoveFileSpecW [SHLWAPI.@]
549 * See PathRemoveFileSpecA.
551 BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
553 LPWSTR lpszFileSpec = lpszPath;
554 BOOL bModified = FALSE;
556 TRACE("(%s)\n",debugstr_w(lpszPath));
560 /* Skip directory or UNC path */
561 if (*lpszPath == '\\')
562 lpszFileSpec = ++lpszPath;
563 if (*lpszPath == '\\')
564 lpszFileSpec = ++lpszPath;
568 if(*lpszPath == '\\')
569 lpszFileSpec = lpszPath; /* Skip dir */
570 else if(*lpszPath == ':')
572 lpszFileSpec = ++lpszPath; /* Skip drive */
573 if (*lpszPath == '\\')
576 if (!(lpszPath = CharNextW(lpszPath)))
582 *lpszFileSpec = '\0';
589 /*************************************************************************
590 * PathStripPathA [SHLWAPI.@]
592 * Remove the initial path from the beginning of a filename
595 * lpszPath [O] Path to remove the initial path from
600 void WINAPI PathStripPathA(LPSTR lpszPath)
602 TRACE("(%s)\n", debugstr_a(lpszPath));
606 LPSTR lpszFileName = PathFindFileNameA(lpszPath);
608 RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1);
612 /*************************************************************************
613 * PathStripPathW [SHLWAPI.@]
615 * See PathStripPathA.
617 void WINAPI PathStripPathW(LPWSTR lpszPath)
621 TRACE("(%s)\n", debugstr_w(lpszPath));
622 lpszFileName = PathFindFileNameW(lpszPath);
624 RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR));
627 /*************************************************************************
628 * PathStripToRootA [SHLWAPI.@]
630 * Reduce a path to its root.
633 * lpszPath [O] the path to reduce
636 * Success: TRUE if the stripped path is a root path
637 * Failure: FALSE if the path cannot be stripped or is NULL
639 BOOL WINAPI PathStripToRootA(LPSTR lpszPath)
641 TRACE("(%s)\n", debugstr_a(lpszPath));
645 while(!PathIsRootA(lpszPath))
646 if (!PathRemoveFileSpecA(lpszPath))
651 /*************************************************************************
652 * PathStripToRootW [SHLWAPI.@]
654 * See PathStripToRootA.
656 BOOL WINAPI PathStripToRootW(LPWSTR lpszPath)
658 TRACE("(%s)\n", debugstr_w(lpszPath));
662 while(!PathIsRootW(lpszPath))
663 if (!PathRemoveFileSpecW(lpszPath))
668 /*************************************************************************
669 * PathRemoveArgsA [SHLWAPI.@]
671 * Strip space seperated arguments from a path.
674 * lpszPath [I] Path to remove arguments from
679 void WINAPI PathRemoveArgsA(LPSTR lpszPath)
681 TRACE("(%s)\n",debugstr_a(lpszPath));
685 LPSTR lpszArgs = PathGetArgsA(lpszPath);
690 LPSTR lpszLastChar = CharPrevA(lpszPath, lpszArgs);
691 if(*lpszLastChar == ' ')
692 *lpszLastChar = '\0';
697 /*************************************************************************
698 * PathRemoveArgsW [SHLWAPI.@]
700 * See PathRemoveArgsA.
702 void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
704 TRACE("(%s)\n",debugstr_w(lpszPath));
708 LPWSTR lpszArgs = PathGetArgsW(lpszPath);
713 LPWSTR lpszLastChar = CharPrevW(lpszPath, lpszArgs);
714 if(*lpszLastChar == ' ')
715 *lpszLastChar = '\0';
720 /*************************************************************************
721 * PathRemoveExtensionA [SHLWAPI.@]
723 * Remove the file extension from a path
726 * lpszPath [O] Path to remove the extension from
731 void WINAPI PathRemoveExtensionA(LPSTR lpszPath)
733 TRACE("(%s)\n", debugstr_a(lpszPath));
737 lpszPath = PathFindExtensionA(lpszPath);
742 /*************************************************************************
743 * PathRemoveExtensionW [SHLWAPI.@]
745 * See PathRemoveExtensionA.
747 void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
749 TRACE("(%s)\n", debugstr_w(lpszPath));
753 lpszPath = PathFindExtensionW(lpszPath);
758 /*************************************************************************
759 * PathRemoveBackslashA [SHLWAPI.@]
761 * Remove a trailing backslash from a path.
764 * lpszPath [O] Path to remove backslash from
767 * Success: A pointer to the end of the path
768 * Failure: NULL, if lpszPath is NULL
770 LPSTR WINAPI PathRemoveBackslashA( LPSTR lpszPath )
774 TRACE("(%s)\n", debugstr_a(lpszPath));
778 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
779 if (!PathIsRootA(lpszPath) && *szTemp == '\\')
785 /*************************************************************************
786 * PathRemoveBackslashW [SHLWAPI.@]
788 * See PathRemoveBackslashA.
790 LPWSTR WINAPI PathRemoveBackslashW( LPWSTR lpszPath )
792 LPWSTR szTemp = NULL;
794 TRACE("(%s)\n", debugstr_w(lpszPath));
798 szTemp = CharPrevW(lpszPath, lpszPath + strlenW(lpszPath));
799 if (!PathIsRootW(lpszPath) && *szTemp == '\\')
805 /*************************************************************************
806 * PathRemoveBlanksA [SHLWAPI.@]
808 * Remove Spaces from the start and end of a path.
811 * lpszPath [O] Path to strip blanks from
816 VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
818 TRACE("(%s)\n", debugstr_a(lpszPath));
820 if(lpszPath && *lpszPath)
822 LPSTR start = lpszPath;
824 while (*lpszPath == ' ')
825 lpszPath = CharNextA(lpszPath);
828 *start++ = *lpszPath++;
830 if (start != lpszPath)
831 while (start[-1] == ' ')
837 /*************************************************************************
838 * PathRemoveBlanksW [SHLWAPI.@]
840 * See PathRemoveBlanksA.
842 VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
844 TRACE("(%s)\n", debugstr_w(lpszPath));
846 if(lpszPath && *lpszPath)
848 LPWSTR start = lpszPath;
850 while (*lpszPath == ' ')
854 *start++ = *lpszPath++;
856 if (start != lpszPath)
857 while (start[-1] == ' ')
863 /*************************************************************************
864 * PathQuoteSpacesA [SHLWAPI.@]
866 * Surround a path containg spaces in quotes.
869 * lpszPath [O] Path to quote
875 * The path is not changed if it is invalid or has no spaces.
877 VOID WINAPI PathQuoteSpacesA(LPSTR lpszPath)
879 TRACE("(%s)\n", debugstr_a(lpszPath));
881 if(lpszPath && StrChrA(lpszPath,' '))
883 int iLen = strlen(lpszPath) + 1;
885 if (iLen + 2 < MAX_PATH)
887 memmove(lpszPath + 1, lpszPath, iLen);
889 lpszPath[iLen] = '"';
890 lpszPath[iLen + 1] = '\0';
895 /*************************************************************************
896 * PathQuoteSpacesW [SHLWAPI.@]
898 * See PathQuoteSpacesA.
900 VOID WINAPI PathQuoteSpacesW(LPWSTR lpszPath)
902 TRACE("(%s)\n", debugstr_w(lpszPath));
904 if(lpszPath && StrChrW(lpszPath,' '))
906 int iLen = strlenW(lpszPath) + 1;
908 if (iLen + 2 < MAX_PATH)
910 memmove(lpszPath + 1, lpszPath, iLen * sizeof(WCHAR));
912 lpszPath[iLen] = '"';
913 lpszPath[iLen + 1] = '\0';
918 /*************************************************************************
919 * PathUnquoteSpacesA [SHLWAPI.@]
921 * Remove quotes ("") from around a path, if present.
924 * lpszPath [O] Path to strip quotes from
930 * If the path contains a single quote only, an empty string will result.
931 * Otherwise quotes are only removed if they appear at the start and end
934 VOID WINAPI PathUnquoteSpacesA(LPSTR lpszPath)
936 TRACE("(%s)\n", debugstr_a(lpszPath));
938 if (lpszPath && *lpszPath == '"')
940 DWORD dwLen = strlen(lpszPath) - 1;
942 if (lpszPath[dwLen] == '"')
944 lpszPath[dwLen] = '\0';
945 for (; *lpszPath; lpszPath++)
946 *lpszPath = lpszPath[1];
951 /*************************************************************************
952 * PathUnquoteSpacesW [SHLWAPI.@]
954 * See PathUnquoteSpacesA.
956 VOID WINAPI PathUnquoteSpacesW(LPWSTR lpszPath)
958 TRACE("(%s)\n", debugstr_w(lpszPath));
960 if (lpszPath && *lpszPath == '"')
962 DWORD dwLen = strlenW(lpszPath) - 1;
964 if (lpszPath[dwLen] == '"')
966 lpszPath[dwLen] = '\0';
967 for (; *lpszPath; lpszPath++)
968 *lpszPath = lpszPath[1];
973 /*************************************************************************
974 * PathParseIconLocationA [SHLWAPI.@]
976 * Parse the location of an icon from a path.
979 * lpszPath [O] The path to parse the icon location from.
982 * Success: The number of the icon
983 * Failure: 0 if the path does not contain an icon location or is NULL
986 * The path has surrounding quotes and spaces removed regardless
987 * of whether the call succeeds or not.
989 int WINAPI PathParseIconLocationA(LPSTR lpszPath)
994 TRACE("(%s)\n", debugstr_a(lpszPath));
998 if ((lpszComma = strchr(lpszPath, ',')))
1000 *lpszComma++ = '\0';
1001 iRet = StrToIntA(lpszComma);
1003 PathUnquoteSpacesA(lpszPath);
1004 PathRemoveBlanksA(lpszPath);
1009 /*************************************************************************
1010 * PathParseIconLocationW [SHLWAPI.@]
1012 * See PathParseIconLocationA.
1014 int WINAPI PathParseIconLocationW(LPWSTR lpszPath)
1019 TRACE("(%s)\n", debugstr_w(lpszPath));
1023 if ((lpszComma = StrChrW(lpszPath, ',')))
1025 *lpszComma++ = '\0';
1026 iRet = StrToIntW(lpszComma);
1028 PathUnquoteSpacesW(lpszPath);
1029 PathRemoveBlanksW(lpszPath);
1034 /*************************************************************************
1035 * SHLWAPI_PathFindLocalExeA
1037 * Internal implementation of SHLWAPI_3.
1039 BOOL WINAPI SHLWAPI_PathFindLocalExeA (LPSTR lpszPath, DWORD dwWhich)
1043 TRACE("(%s,%ld)\n", debugstr_a(lpszPath), dwWhich);
1047 WCHAR szPath[MAX_PATH];
1048 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
1049 bRet = SHLWAPI_PathFindLocalExeW(szPath, dwWhich);
1051 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
1056 /*************************************************************************
1057 * SHLWAPI_PathFindLocalExeW
1059 * Internal implementation of SHLWAPI_4.
1061 BOOL WINAPI SHLWAPI_PathFindLocalExeW (LPWSTR lpszPath, DWORD dwWhich)
1063 static const WCHAR pszExts[7][5] = { { '.', 'p', 'i', 'f', '0'},
1064 { '.', 'c', 'o', 'm', '0'},
1065 { '.', 'e', 'x', 'e', '0'},
1066 { '.', 'b', 'a', 't', '0'},
1067 { '.', 'l', 'n', 'k', '0'},
1068 { '.', 'c', 'm', 'd', '0'},
1069 { '0', '0', '0', '0', '0'} };
1071 TRACE("(%s,%ld)\n", debugstr_w(lpszPath), dwWhich);
1073 if (!lpszPath || PathIsUNCServerW(lpszPath) || PathIsUNCServerShareW(lpszPath))
1078 LPCWSTR szExt = PathFindExtensionW(lpszPath);
1079 if (!*szExt || dwWhich & 0x40)
1082 int iLen = lstrlenW(lpszPath);
1083 if (iLen > (MAX_PATH - 5))
1085 while (dwWhich & 0x1 && iChoose < sizeof(pszExts))
1087 lstrcpyW(lpszPath + iLen, pszExts[iChoose]);
1088 if (PathFileExistsW(lpszPath))
1093 *(lpszPath + iLen) = (WCHAR)'\0';
1097 return PathFileExistsW(lpszPath);
1100 /*************************************************************************
1101 * SHLWAPI_PathFindInOtherDirs
1103 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1105 static BOOL WINAPI SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile, DWORD dwWhich)
1107 static WCHAR szSystem[] = { 'S','y','s','t','e','m','\0'};
1108 static WCHAR szPath[] = { 'P','A','T','H','\0'};
1112 WCHAR buff[MAX_PATH];
1114 TRACE("(%s,%08lx)\n", debugstr_w(lpszFile), dwWhich);
1116 /* Try system directories */
1117 GetSystemDirectoryW(buff, MAX_PATH);
1118 if (!PathAppendW(buff, lpszFile))
1120 if (SHLWAPI_PathFindLocalExeW(buff, dwWhich))
1122 strcpyW(lpszFile, buff);
1125 GetWindowsDirectoryW(buff, MAX_PATH);
1126 if (!PathAppendW(buff, szSystem ) || !PathAppendW(buff, lpszFile))
1128 if (SHLWAPI_PathFindLocalExeW(buff, dwWhich))
1130 strcpyW(lpszFile, buff);
1133 GetWindowsDirectoryW(buff, MAX_PATH);
1134 if (!PathAppendW(buff, lpszFile))
1136 if (SHLWAPI_PathFindLocalExeW(buff, dwWhich))
1138 strcpyW(lpszFile, buff);
1141 /* Try dirs listed in %PATH% */
1142 dwLenPATH = GetEnvironmentVariableW(szPath, buff, MAX_PATH);
1144 if (!dwLenPATH || !(lpszPATH = malloc((dwLenPATH + 1) * sizeof (WCHAR))))
1147 GetEnvironmentVariableW(szPath, lpszPATH, dwLenPATH + 1);
1148 lpszCurr = lpszPATH;
1151 LPCWSTR lpszEnd = lpszCurr;
1152 LPWSTR pBuff = buff;
1154 while (*lpszEnd == ' ')
1156 while (*lpszEnd && *lpszEnd != ';')
1157 *pBuff++ = *lpszEnd++;
1161 lpszCurr = lpszEnd + 1;
1163 lpszCurr = NULL; /* Last Path, terminate after this */
1165 if (!PathAppendW(buff, lpszFile))
1167 if (SHLWAPI_PathFindLocalExeW(buff, dwWhich))
1169 strcpyW(lpszFile, buff);
1179 /*************************************************************************
1180 * SHLWAPI_PathFindOnPathExA
1182 * Internal implementation of SHLWAPI_5
1184 BOOL WINAPI SHLWAPI_PathFindOnPathExA(LPSTR lpszFile, LPCSTR *lppszOtherDirs, DWORD dwWhich)
1186 WCHAR szFile[MAX_PATH];
1187 WCHAR buff[MAX_PATH];
1189 TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile), lppszOtherDirs, dwWhich);
1191 if (!lpszFile || !PathIsFileSpecA(lpszFile))
1194 MultiByteToWideChar(0,0,lpszFile,-1,szFile,MAX_PATH);
1196 /* Search provided directories first */
1197 if (lppszOtherDirs && *lppszOtherDirs)
1199 WCHAR szOther[MAX_PATH];
1200 LPCSTR *lpszOtherPath = lppszOtherDirs;
1202 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1204 MultiByteToWideChar(0,0,*lpszOtherPath,-1,szOther,MAX_PATH);
1205 PathCombineW(buff, szOther, szFile);
1206 if (SHLWAPI_PathFindLocalExeW(buff, dwWhich))
1208 WideCharToMultiByte(0,0,buff,-1,lpszFile,MAX_PATH,0,0);
1214 /* Not found, try system and path dirs */
1215 if (SHLWAPI_PathFindInOtherDirs(szFile, dwWhich))
1217 WideCharToMultiByte(0,0,szFile,-1,lpszFile,MAX_PATH,0,0);
1223 /*************************************************************************
1224 * SHLWAPI_PathFindOnPathExW
1226 * Internal implementation of SHLWAPI_6.
1228 BOOL WINAPI SHLWAPI_PathFindOnPathExW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs, DWORD dwWhich)
1230 WCHAR buff[MAX_PATH];
1232 TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile), lppszOtherDirs, dwWhich);
1234 if (!lpszFile || !PathIsFileSpecW(lpszFile))
1237 /* Search provided directories first */
1238 if (lppszOtherDirs && *lppszOtherDirs)
1240 LPCWSTR *lpszOtherPath = lppszOtherDirs;
1241 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1243 PathCombineW(buff, *lpszOtherPath, lpszFile);
1244 if (SHLWAPI_PathFindLocalExeW(buff, dwWhich))
1246 strcpyW(lpszFile, buff);
1252 /* Not found, try system and path dirs */
1253 return SHLWAPI_PathFindInOtherDirs(lpszFile, dwWhich);
1256 /*************************************************************************
1257 * PathFindOnPathA [SHLWAPI.@]
1259 * Search a range of paths for an executable.
1262 * lpszFile [O] File to search for
1263 * lppszOtherDirs [I] Other directories to look in
1266 * Success: TRUE. The path to the executable is stored in lpszFile.
1267 * Failure: FALSE. The path to the executable is unchanged.
1269 BOOL WINAPI PathFindOnPathA(LPSTR lpszFile, LPCSTR *lppszOtherDirs)
1271 TRACE("(%s,%p)\n", debugstr_a(lpszFile), lppszOtherDirs);
1272 return SHLWAPI_PathFindOnPathExA(lpszFile, lppszOtherDirs, 0);
1275 /*************************************************************************
1276 * PathFindOnPathW [SHLWAPI.@]
1278 * See PathFindOnPathA.
1280 BOOL WINAPI PathFindOnPathW (LPWSTR lpszFile, LPCWSTR *lppszOtherDirs)
1282 TRACE("(%s,%p)\n", debugstr_w(lpszFile), lppszOtherDirs);
1283 return SHLWAPI_PathFindOnPathExW(lpszFile,lppszOtherDirs, 0);
1286 /*************************************************************************
1287 * PathCompactPathExA [SHLWAPI.@]
1289 * Compact a path into a given number of characters.
1292 * lpszDest [O] Destination for compacted path
1293 * lpszPath [I] Source path
1294 * cchMax [I[ Maximum size of compacted path
1295 * dwFlags [I] Reserved
1298 * Success: TRUE. The compacted path is written to lpszDest.
1299 * Failure: FALSE. lpszPath is undefined.
1302 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1303 * The Win32 version of this function contains a bug: When cchMax == 7,
1304 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1306 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1307 * because Win32 will insert a \ in the compact filename, even if one is
1308 * not present in the original path.
1310 BOOL WINAPI PathCompactPathExA(LPSTR lpszDest, LPCSTR lpszPath,
1311 UINT cchMax, DWORD dwFlags)
1315 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest, debugstr_a(lpszPath), cchMax, dwFlags);
1317 if (lpszPath && lpszDest)
1319 WCHAR szPath[MAX_PATH];
1320 WCHAR szDest[MAX_PATH];
1322 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
1324 bRet = PathCompactPathExW(szDest, szPath, cchMax, dwFlags);
1325 WideCharToMultiByte(0,0,szDest,-1,lpszDest,MAX_PATH,0,0);
1330 /*************************************************************************
1331 * PathCompactPathExW [SHLWAPI.@]
1333 * See PathCompactPathExA.
1335 BOOL WINAPI PathCompactPathExW(LPWSTR lpszDest, LPCWSTR lpszPath,
1336 UINT cchMax, DWORD dwFlags)
1338 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
1340 DWORD dwLen, dwFileLen = 0;
1342 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest, debugstr_w(lpszPath), cchMax, dwFlags);
1349 WARN("Invalid lpszDest would crash under Win32!\n");
1358 dwLen = strlenW(lpszPath) + 1;
1362 /* Don't need to compact */
1363 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1367 /* Path must be compacted to fit into lpszDest */
1368 lpszFile = PathFindFileNameW(lpszPath);
1369 dwFileLen = lpszPath + dwLen - lpszFile;
1371 if (dwFileLen == dwLen)
1373 /* No root in psth */
1376 while (--cchMax > 0) /* No room left for anything but ellipses */
1381 /* Compact the file name with ellipses at the end */
1383 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1384 strcpyW(lpszDest + cchMax, szEllipses);
1387 /* We have a root in the path */
1388 lpszFile--; /* Start compacted filename with the path seperator */
1391 if (dwFileLen + 3 > cchMax)
1393 /* Compact the file name */
1396 while (--cchMax > 0) /* No room left for anything but ellipses */
1401 strcpyW(lpszDest, szEllipses);
1404 *lpszDest++ = *lpszFile++;
1407 while (--cchMax > 0) /* No room left for anything but ellipses */
1413 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1414 strcpyW(lpszDest + cchMax, szEllipses);
1418 /* Only the root needs to be Compacted */
1419 dwLen = cchMax - dwFileLen - 3;
1420 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1421 strcpyW(lpszDest + dwLen, szEllipses);
1422 strcpyW(lpszDest + dwLen + 3, lpszFile);
1426 /*************************************************************************
1427 * PathIsRelativeA [SHLWAPI.@]
1429 * Determine if a path is a relative path.
1432 * lpszPath [I] Path to check
1435 * TRUE: The path is relative, or is invalid.
1436 * FALSE: The path is not relative.
1438 BOOL WINAPI PathIsRelativeA (LPCSTR lpszPath)
1440 TRACE("(%s)\n",debugstr_a(lpszPath));
1442 if (!lpszPath || !*lpszPath || IsDBCSLeadByte(*lpszPath))
1444 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1449 /*************************************************************************
1450 * PathIsRelativeW [SHLWAPI.@]
1452 * See PathIsRelativeA.
1454 BOOL WINAPI PathIsRelativeW (LPCWSTR lpszPath)
1456 TRACE("(%s)\n",debugstr_w(lpszPath));
1458 if (!lpszPath || !*lpszPath)
1460 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1465 /*************************************************************************
1466 * PathIsRootA [SHLWAPI.@]
1468 * Determine if a path is a root path.
1471 * lpszPath [I] Path to check
1474 * TRUE If lpszPath is valid and a root path
1477 BOOL WINAPI PathIsRootA(LPCSTR lpszPath)
1479 TRACE("(%s)\n", debugstr_a(lpszPath));
1481 if (lpszPath && *lpszPath)
1483 if (*lpszPath == '\\')
1486 return TRUE; /* \ */
1487 else if (lpszPath[1]=='\\')
1489 BOOL bSeenSlash = FALSE;
1492 /* Check for UNC root path */
1495 if (*lpszPath == '\\')
1501 lpszPath = CharNextA(lpszPath);
1506 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1507 return TRUE; /* X:\ */
1512 /*************************************************************************
1513 * PathIsRootW [SHLWAPI.@]
1517 BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
1519 TRACE("(%s)\n", debugstr_w(lpszPath));
1521 if (lpszPath && *lpszPath)
1523 if (*lpszPath == '\\')
1526 return TRUE; /* \ */
1527 else if (lpszPath[1]=='\\')
1529 BOOL bSeenSlash = FALSE;
1532 /* Check for UNC root path */
1535 if (*lpszPath == '\\')
1541 lpszPath = CharNextW(lpszPath);
1546 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1547 return TRUE; /* X:\ */
1552 /*************************************************************************
1553 * PathIsDirectoryA [SHLWAPI.@]
1555 * Determine if a path is a valid directory
1558 * lpszPath [I] Path to check.
1561 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1562 * FALSE if lpszPath is invalid or not a directory.
1565 * Although this function is prototyped as returning a BOOL, it returns
1566 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1568 * if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1573 BOOL WINAPI PathIsDirectoryA(LPCSTR lpszPath)
1577 TRACE("(%s)\n", debugstr_a(lpszPath));
1579 if (!lpszPath || PathIsUNCServerA(lpszPath))
1582 if (PathIsUNCServerShareA(lpszPath))
1584 FIXME("UNC Server Share not yet supported - FAILING\n");
1588 if ((dwAttr = GetFileAttributesA(lpszPath)) == -1u)
1590 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1593 /*************************************************************************
1594 * PathIsDirectoryW [SHLWAPI.@]
1596 * See PathIsDirectoryA.
1598 BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
1602 TRACE("(%s)\n", debugstr_w(lpszPath));
1604 if (!lpszPath || PathIsUNCServerW(lpszPath))
1607 if (PathIsUNCServerShareW(lpszPath))
1609 FIXME("UNC Server Share not yet supported - FAILING\n");
1613 if ((dwAttr = GetFileAttributesW(lpszPath)) == -1u)
1615 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1618 /*************************************************************************
1619 * PathFileExistsA [SHLWAPI.@]
1621 * Determine if a file exists.
1624 * lpszPath [I] Path to check
1627 * TRUE If the file exists and is readable
1630 BOOL WINAPI PathFileExistsA(LPCSTR lpszPath)
1635 TRACE("(%s)\n",debugstr_a(lpszPath));
1640 iPrevErrMode = SetErrorMode(1);
1641 dwAttr = GetFileAttributesA(lpszPath);
1642 SetErrorMode(iPrevErrMode);
1643 return dwAttr == -1u ? FALSE : TRUE;
1646 /*************************************************************************
1647 * PathFileExistsW [SHLWAPI.@]
1649 * See PathFileExistsA
1651 BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
1656 TRACE("(%s)\n",debugstr_w(lpszPath));
1661 iPrevErrMode = SetErrorMode(1);
1662 dwAttr = GetFileAttributesW(lpszPath);
1663 SetErrorMode(iPrevErrMode);
1664 return dwAttr == -1u ? FALSE : TRUE;
1667 /*************************************************************************
1668 * PathMatchSingleMaskA [internal]
1671 * internal (used by PathMatchSpec)
1673 static BOOL PathMatchSingleMaskA(LPCSTR name, LPCSTR mask)
1675 while (*name && *mask && *mask!=';')
1681 if (PathMatchSingleMaskA(name,mask+1)) return 1; /* try substrings */
1685 if (toupper(*mask)!=toupper(*name) && *mask!='?') return 0;
1686 name = CharNextA(name);
1687 mask = CharNextA(mask);
1691 while (*mask=='*') mask++;
1692 if (!*mask || *mask==';') return 1;
1697 /*************************************************************************
1698 * PathMatchSingleMaskW [internal]
1700 static BOOL PathMatchSingleMaskW(LPCWSTR name, LPCWSTR mask)
1702 while (*name && *mask && *mask!=';')
1708 if (PathMatchSingleMaskW(name,mask+1)) return 1; /* try substrings */
1712 if (toupperW(*mask)!=toupperW(*name) && *mask!='?') return 0;
1713 name = CharNextW(name);
1714 mask = CharNextW(mask);
1718 while (*mask=='*') mask++;
1719 if (!*mask || *mask==';') return 1;
1724 /*************************************************************************
1725 * PathMatchSpecA [SHLWAPI.@]
1727 * Determine if a path matches one or more search masks.
1730 * lpszPath [I] Path to check
1731 * lpszMask [I} Search mask(s)
1734 * TRUE If lpszPath is valid and is matched
1738 * Multiple search masks may be given if they are seperated by ";". The
1739 * pattern "*.*" is treated specially in that it matches all paths (for
1740 * backwards compatability with DOS).
1742 BOOL WINAPI PathMatchSpecA(LPCSTR name, LPCSTR mask)
1744 TRACE("%s %s\n",name,mask);
1746 if (!lstrcmpA( mask, "*.*" )) return 1; /* we don't require a period */
1750 if (PathMatchSingleMaskA(name,mask)) return 1; /* helper function */
1751 while (*mask && *mask!=';') mask = CharNextA(mask);
1755 while (*mask==' ') mask++; /* masks may be separated by "; " */
1761 /*************************************************************************
1762 * PathMatchSpecW [SHLWAPI.@]
1764 * See PathMatchSpecA.
1766 BOOL WINAPI PathMatchSpecW(LPCWSTR name, LPCWSTR mask)
1768 static const WCHAR stemp[] = { '*','.','*',0 };
1769 TRACE("%s %s\n",debugstr_w(name),debugstr_w(mask));
1771 if (!lstrcmpW( mask, stemp )) return 1; /* we don't require a period */
1775 if (PathMatchSingleMaskW(name,mask)) return 1; /* helper function */
1776 while (*mask && *mask!=';') mask = CharNextW(mask);
1780 while (*mask==' ') mask++; /* masks may be separated by "; " */
1786 /*************************************************************************
1787 * PathIsSameRootA [SHLWAPI.@]
1789 * Determine if two paths share the same root.
1792 * lpszPath1 [I] Source path
1793 * lpszPath2 [I] Path to compare with
1796 * TRUE If both paths are valid and share the same root.
1797 * FALSE If either path is invalid or the paths do not share the same root.
1799 BOOL WINAPI PathIsSameRootA(LPCSTR lpszPath1, LPCSTR lpszPath2)
1804 TRACE("(%s,%s)\n", debugstr_a(lpszPath1), debugstr_a(lpszPath2));
1806 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootA(lpszPath1)))
1809 dwLen = PathCommonPrefixA(lpszPath1, lpszPath2, NULL) + 1;
1810 if (lpszStart - lpszPath1 > dwLen)
1811 return FALSE; /* Paths not common up to length of the root */
1815 /*************************************************************************
1816 * PathIsSameRootW [SHLWAPI.@]
1818 * See PathIsSameRootA.
1820 BOOL WINAPI PathIsSameRootW(LPCWSTR lpszPath1, LPCWSTR lpszPath2)
1825 TRACE("(%s,%s)\n", debugstr_w(lpszPath1), debugstr_w(lpszPath2));
1827 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootW(lpszPath1)))
1830 dwLen = PathCommonPrefixW(lpszPath1, lpszPath2, NULL) + 1;
1831 if (lpszStart - lpszPath1 > dwLen)
1832 return FALSE; /* Paths not common up to length of the root */
1836 /*************************************************************************
1837 * PathIsURLA [SHLWAPI.@]
1839 * Check if the given path is a URL.
1842 * lpszPath [I] Path to check.
1845 * TRUE if lpszPath is a URL.
1846 * FALSE if lpszPath is NULL or not a URL.
1848 BOOL WINAPI PathIsURLA(LPCSTR lpstrPath)
1850 UNKNOWN_SHLWAPI_1 base;
1853 if (!lpstrPath || !*lpstrPath) return FALSE;
1856 base.size = sizeof(base);
1857 res1 = SHLWAPI_1(lpstrPath, &base);
1858 return (base.fcncde) ? TRUE : FALSE;
1861 /*************************************************************************
1862 * PathIsURLW [SHLWAPI.@]
1864 BOOL WINAPI PathIsURLW(LPCWSTR lpstrPath)
1866 UNKNOWN_SHLWAPI_2 base;
1869 if (!lpstrPath || !*lpstrPath) return FALSE;
1872 base.size = sizeof(base);
1873 res1 = SHLWAPI_2(lpstrPath, &base);
1874 return (base.fcncde) ? TRUE : FALSE;
1877 /*************************************************************************
1878 * PathIsContentTypeA [SHLWAPI.@]
1880 * Determine if a file is of a given registered content type.
1883 * lpszPath [I] file to check
1886 * TRUE If lpszPath is a given registered content type
1890 * This function looks up the registered content type for lpszPath. If
1891 * a content type is registered, it is compared (case insensitively) to
1892 * lpszContentType. Only if this matches does the function succeed.
1894 BOOL WINAPI PathIsContentTypeA(LPCSTR lpszPath, LPCSTR lpszContentType)
1898 char szBuff[MAX_PATH];
1900 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszContentType));
1902 if (lpszPath && (szExt = PathFindExtensionA(lpszPath)) && *szExt &&
1903 !SHGetValueA(HKEY_CLASSES_ROOT, szExt, "Content Type",
1904 REG_NONE, szBuff, &dwDummy) &&
1905 !strcasecmp(lpszContentType, szBuff))
1912 /*************************************************************************
1913 * PathIsContentTypeW [SHLWAPI.@]
1915 * See PathIsContentTypeA.
1917 BOOL WINAPI PathIsContentTypeW(LPCWSTR lpszPath, LPCWSTR lpszContentType)
1919 static const WCHAR szContentType[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
1922 WCHAR szBuff[MAX_PATH];
1924 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszContentType));
1926 if (lpszPath && (szExt = PathFindExtensionW(lpszPath)) && *szExt &&
1927 !SHGetValueW(HKEY_CLASSES_ROOT, szExt, szContentType,
1928 REG_NONE, szBuff, &dwDummy) &&
1929 !strcmpiW(lpszContentType, szBuff))
1936 /*************************************************************************
1937 * PathIsFileSpecA [SHLWAPI.@]
1939 * Determine if a path is a file specification.
1942 * lpszPath [I] Path to chack
1945 * TRUE If lpszPath is a file spec (contains no directories).
1948 BOOL WINAPI PathIsFileSpecA(LPCSTR lpszPath)
1950 TRACE("(%s)\n", debugstr_a(lpszPath));
1957 if (*lpszPath == '\\' || *lpszPath == ':')
1959 lpszPath = CharNextA(lpszPath);
1964 /*************************************************************************
1965 * PathIsFileSpecW [SHLWAPI.@]
1967 * See PathIsFileSpecA.
1969 BOOL WINAPI PathIsFileSpecW(LPCWSTR lpszPath)
1971 TRACE("(%s)\n", debugstr_w(lpszPath));
1978 if (*lpszPath == '\\' || *lpszPath == ':')
1980 lpszPath = CharNextW(lpszPath);
1985 /*************************************************************************
1986 * PathIsPrefixA [SHLWAPI.@]
1988 * Determine if a path is a prefix of another.
1991 * lpszPrefix [I] Prefix
1992 * lpszPath [i] Path to check
1995 * TRUE If lpszPath has lpszPrefix as its prefix
1996 * FALSE If either path is NULL or lpszPrefix is not a prefix
1998 BOOL WINAPI PathIsPrefixA (LPCSTR lpszPrefix, LPCSTR lpszPath)
2000 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix), debugstr_a(lpszPath));
2002 if (lpszPrefix && lpszPath &&
2003 PathCommonPrefixA(lpszPath, lpszPrefix, NULL) == (int)strlen(lpszPrefix))
2008 /*************************************************************************
2009 * PathIsPrefixW [SHLWAPI.@]
2011 * See PathIsPrefixA.
2013 BOOL WINAPI PathIsPrefixW(LPCWSTR lpszPrefix, LPCWSTR lpszPath)
2015 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix), debugstr_w(lpszPath));
2017 if (lpszPrefix && lpszPath &&
2018 PathCommonPrefixW(lpszPath, lpszPrefix, NULL) == (int)strlenW(lpszPrefix))
2023 /*************************************************************************
2024 * PathIsSystemFolderA [SHLWAPI.@]
2026 * Determine if a path or file attributes are a system folder.
2029 * lpszPath [I] Path to check.
2030 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2033 * TRUE If lpszPath or dwAttrib are a system folder.
2034 * FALSE If GetFileAttributesA fails or neither parameter is a system folder.
2036 BOOL WINAPI PathIsSystemFolderA(LPCSTR lpszPath, DWORD dwAttrib)
2038 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath), dwAttrib);
2040 if (lpszPath && *lpszPath)
2041 dwAttrib = GetFileAttributesA(lpszPath);
2043 if (dwAttrib == -1u || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2044 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2049 /*************************************************************************
2050 * PathIsSystemFolderW [SHLWAPI.@]
2052 * See PathIsSystemFolderA.
2054 BOOL WINAPI PathIsSystemFolderW(LPCWSTR lpszPath, DWORD dwAttrib)
2056 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath), dwAttrib);
2058 if (lpszPath && *lpszPath)
2059 dwAttrib = GetFileAttributesW(lpszPath);
2061 if (dwAttrib == -1u || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2062 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2067 /*************************************************************************
2068 * PathIsUNCA [SHLWAPI.@]
2070 * Determine if a path is in UNC format.
2073 * lpszPath [I] Path to check
2076 * TRUE: The path is UNC.
2077 * FALSE: The path is not UNC or is NULL.
2079 BOOL WINAPI PathIsUNCA(LPCSTR lpszPath)
2081 TRACE("(%s)\n",debugstr_a(lpszPath));
2083 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2088 /*************************************************************************
2089 * PathIsUNCW [SHLWAPI.@]
2093 BOOL WINAPI PathIsUNCW(LPCWSTR lpszPath)
2095 TRACE("(%s)\n",debugstr_w(lpszPath));
2097 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2102 /*************************************************************************
2103 * PathIsUNCServerA [SHLWAPI.@]
2105 * Determine if a path is a UNC server name ("\\SHARENAME").
2108 * lpszPath [I] Path to check.
2111 * TRUE If lpszPath is a valid UNC server name.
2115 * This routine is bug compatible with Win32: Server names with a
2116 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2117 * Fixing this bug may break other shlwapi functions!
2119 BOOL WINAPI PathIsUNCServerA(LPCSTR lpszPath)
2121 TRACE("(%s)\n", debugstr_a(lpszPath));
2123 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2127 if (*lpszPath == '\\')
2129 lpszPath = CharNextA(lpszPath);
2136 /*************************************************************************
2137 * PathIsUNCServerW [SHLWAPI.@]
2139 * See PathIsUNCServerA.
2141 BOOL WINAPI PathIsUNCServerW(LPCWSTR lpszPath)
2143 TRACE("(%s)\n", debugstr_w(lpszPath));
2145 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2149 if (*lpszPath == '\\')
2151 lpszPath = CharNextW(lpszPath);
2158 /*************************************************************************
2159 * PathIsUNCServerShareA [SHLWAPI.@]
2161 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2164 * lpszPath [I] Path to check.
2167 * TRUE If lpszPath is a valid UNC server share.
2171 * This routine is bug compatible with Win32: Server shares with a
2172 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2173 * Fixing this bug may break other shlwapi functions!
2175 BOOL WINAPI PathIsUNCServerShareA(LPCSTR lpszPath)
2177 TRACE("(%s)\n", debugstr_a(lpszPath));
2179 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2181 BOOL bSeenSlash = FALSE;
2184 if (*lpszPath == '\\')
2190 lpszPath = CharNextA(lpszPath);
2197 /*************************************************************************
2198 * PathIsUNCServerShareW [SHLWAPI.@]
2200 * See PathIsUNCServerShareA.
2202 BOOL WINAPI PathIsUNCServerShareW(LPCWSTR lpszPath)
2204 TRACE("(%s)\n", debugstr_w(lpszPath));
2206 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2208 BOOL bSeenSlash = FALSE;
2211 if (*lpszPath == '\\')
2217 lpszPath = CharNextW(lpszPath);
2224 /*************************************************************************
2225 * PathCanonicalizeA [SHLWAPI.@]
2227 * Convert a path to its canonical form.
2230 * lpszBuf [O] Output path
2231 * lpszPath [I] Path to cnonicalize
2234 * Success: TRUE. lpszBuf contains the output path
2235 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2237 BOOL WINAPI PathCanonicalizeA(LPSTR lpszBuf, LPCSTR lpszPath)
2241 TRACE("(%p,%s)\n", lpszBuf, debugstr_a(lpszPath));
2246 if (!lpszBuf || !lpszPath)
2247 SetLastError(ERROR_INVALID_PARAMETER);
2250 WCHAR szPath[MAX_PATH];
2251 WCHAR szBuff[MAX_PATH];
2252 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2253 bRet = PathCanonicalizeW(szBuff, szPath);
2254 WideCharToMultiByte(0,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
2260 /*************************************************************************
2261 * PathCanonicalizeW [SHLWAPI.@]
2263 * See PathCanonicalizeA.
2265 BOOL WINAPI PathCanonicalizeW(LPWSTR lpszBuf, LPCWSTR lpszPath)
2267 LPWSTR lpszDst = lpszBuf;
2268 LPCWSTR lpszSrc = lpszPath;
2270 TRACE("(%p,%s)\n", lpszBuf, debugstr_w(lpszPath));
2275 if (!lpszBuf || !lpszPath)
2277 SetLastError(ERROR_INVALID_PARAMETER);
2288 /* Copy path root */
2289 if (*lpszSrc == '\\')
2291 *lpszDst++ = *lpszSrc++;
2293 else if (*lpszSrc && lpszSrc[1] == ':')
2296 *lpszDst++ = *lpszSrc++;
2297 *lpszDst++ = *lpszSrc++;
2298 if (*lpszSrc == '\\')
2299 *lpszDst++ = *lpszSrc++;
2302 /* Canonicalize the rest of the path */
2305 if (*lpszSrc == '.')
2307 if (lpszSrc[1] == '\\' && (lpszSrc == lpszPath || lpszSrc[-1] == '\\' || lpszSrc[-1] == ':'))
2309 lpszSrc += 2; /* Skip .\ */
2311 else if (lpszSrc[1] == '.' && (lpszDst == lpszBuf || lpszDst[-1] == '\\'))
2313 /* \.. backs up a directory, over the root if it has no \ following X:.
2314 * .. is ignored if it would remove a UNC server name or inital \\
2316 if (lpszDst != lpszBuf)
2318 *lpszDst = '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2319 if (lpszDst > lpszBuf+1 && lpszDst[-1] == '\\' &&
2320 (lpszDst[-2] != '\\' || lpszDst > lpszBuf+2))
2322 if (lpszDst[-2] == ':' && (lpszDst > lpszBuf+3 || lpszDst[-3] == ':'))
2325 while (lpszDst > lpszBuf && *lpszDst != '\\')
2327 if (*lpszDst == '\\')
2328 lpszDst++; /* Reset to last '\' */
2330 lpszDst = lpszBuf; /* Start path again from new root */
2332 else if (lpszDst[-2] != ':' && !PathIsUNCServerShareW(lpszBuf))
2335 while (lpszDst > lpszBuf && *lpszDst != '\\')
2337 if (lpszDst == lpszBuf)
2343 lpszSrc += 2; /* Skip .. in src path */
2346 *lpszDst++ = *lpszSrc++;
2349 *lpszDst++ = *lpszSrc++;
2351 /* Append \ to naked drive specs */
2352 if (lpszDst - lpszBuf == 2 && lpszDst[-1] == ':')
2358 /*************************************************************************
2359 * PathFindNextComponentA [SHLWAPI.@]
2361 * Find the next component in a path.
2364 * lpszPath [I] Path to find next component in
2367 * Success: A pointer to the next component, or the end of the string
2368 * Failure: NULL, If lpszPath is invalid
2371 * A 'component' is either a backslash character (\) or UNC marker (\\).
2372 * Because of this, relative paths (e.g "c:foo") are regarded as having
2373 * only one component.
2375 LPSTR WINAPI PathFindNextComponentA(LPCSTR lpszPath)
2379 TRACE("(%s)\n", debugstr_a(lpszPath));
2381 if(!lpszPath || !*lpszPath)
2384 if ((lpszSlash = StrChrA(lpszPath, '\\')))
2386 if (lpszSlash[1] == '\\')
2388 return lpszSlash + 1;
2390 return (LPSTR)lpszPath + strlen(lpszPath);
2393 /*************************************************************************
2394 * PathFindNextComponentW [SHLWAPI.@]
2396 * See PathFindNextComponentA.
2398 LPWSTR WINAPI PathFindNextComponentW(LPCWSTR lpszPath)
2402 TRACE("(%s)\n", debugstr_w(lpszPath));
2404 if(!lpszPath || !*lpszPath)
2407 if ((lpszSlash = StrChrW(lpszPath, '\\')))
2409 if (lpszSlash[1] == '\\')
2411 return lpszSlash + 1;
2413 return (LPWSTR)lpszPath + strlenW(lpszPath);
2416 /*************************************************************************
2417 * PathAddExtensionA [SHLWAPI.@]
2419 * Add a file extension to a path
2422 * lpszPath [O] Path to add extension to
2423 * lpszExtension [I} Extension to add to lpszPath
2426 * TRUE If the path was modified
2427 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2428 * extension allready, or the new path length is too big.
2431 * What version of shlwapi.dll adds "exe" if pszExtension is NULL? Win2k
2432 * does not do this, so the behaviour was removed.
2434 BOOL WINAPI PathAddExtensionA(LPSTR lpszPath, LPCSTR lpszExtension)
2438 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExtension));
2440 if (!lpszPath || !lpszExtension || *(PathFindExtensionA(lpszPath)))
2443 dwLen = strlen(lpszPath);
2445 if (dwLen + strlen(lpszExtension) >= MAX_PATH)
2448 strcpy(lpszPath + dwLen, lpszExtension);
2452 /*************************************************************************
2453 * PathAddExtensionW [SHLWAPI.@]
2455 * See PathAddExtensionA.
2457 BOOL WINAPI PathAddExtensionW(LPWSTR lpszPath, LPCWSTR lpszExtension)
2461 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExtension));
2463 if (!lpszPath || !lpszExtension || *(PathFindExtensionW(lpszPath)))
2466 dwLen = strlenW(lpszPath);
2468 if (dwLen + strlenW(lpszExtension) >= MAX_PATH)
2471 strcpyW(lpszPath + dwLen, lpszExtension);
2475 /*************************************************************************
2476 * PathMakePrettyA [SHLWAPI.@]
2478 * Convert an uppercase DOS filename into lowercase.
2481 * lpszPath [O] Path to convert.
2484 * TRUE If the path was an uppercase DOS path and was converted
2487 BOOL WINAPI PathMakePrettyA(LPSTR lpszPath)
2489 LPSTR pszIter = lpszPath;
2491 TRACE("(%s)\n", debugstr_a(lpszPath));
2493 if (!pszIter || !*pszIter)
2498 if (islower(*pszIter) || IsDBCSLeadByte(*pszIter))
2499 return FALSE; /* Not DOS path */
2502 pszIter = lpszPath + 1;
2505 *pszIter = tolower(*pszIter);
2511 /*************************************************************************
2512 * PathMakePrettyW [SHLWAPI.@]
2514 * See PathMakePrettyA
2516 BOOL WINAPI PathMakePrettyW(LPWSTR lpszPath)
2518 LPWSTR pszIter = lpszPath;
2520 TRACE("(%s)\n", debugstr_w(lpszPath));
2522 if (!pszIter || !*pszIter)
2527 if (islowerW(*pszIter))
2528 return FALSE; /* Not DOS path */
2531 pszIter = lpszPath + 1;
2534 *pszIter = tolowerW(*pszIter);
2540 /*************************************************************************
2541 * PathCommonPrefixA [SHLWAPI.@]
2543 * Determine the length of the common prefix between two paths.
2546 * lpszFile1 [I] First path for comparason
2547 * lpszFile2 [I] Second path for comparason
2548 * achPath [O] Destination for common prefix string
2551 * The length of the common prefix. This is 0 if there is no common
2552 * prefix between the paths or if any parameters are invalid. If the prefix
2553 * is non-zero and achPath is not NULL, achPath is filled with the common
2554 * part of the prefix and NUL terminated.
2557 * A common prefix of 2 is always returned as 3. It is thus possible for
2558 * the length returned to be invalid (i.e. Longer than one or both of the
2559 * strings given as parameters). This Win32 behaviour has been implimented
2560 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2561 * To work around this when using this function, always check that the byte
2562 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2564 int WINAPI PathCommonPrefixA(LPCSTR lpszFile1, LPCSTR lpszFile2, LPSTR achPath)
2567 LPCSTR lpszIter1 = lpszFile1;
2568 LPCSTR lpszIter2 = lpszFile2;
2570 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1), debugstr_a(lpszFile2), achPath);
2575 if (!lpszFile1 || !lpszFile2)
2578 /* Handle roots first */
2579 if (PathIsUNCA(lpszFile1))
2581 if (!PathIsUNCA(lpszFile2))
2586 else if (PathIsUNCA(lpszFile2))
2587 return 0; /* Know already lpszFile1 is not UNC */
2592 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2593 (!*lpszIter2 || *lpszIter2 == '\\'))
2594 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2596 if (!*lpszIter1 || (tolower(*lpszIter1) != tolower(*lpszIter2)))
2597 break; /* Strings differ at this point */
2604 iLen++; /* Feature/Bug compatable with Win32 */
2606 if (iLen && achPath)
2608 memcpy(achPath,lpszFile1,iLen);
2609 achPath[iLen] = '\0';
2614 /*************************************************************************
2615 * PathCommonPrefixW [SHLWAPI.@]
2617 * See PathCommonPrefixA.
2619 int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPath)
2622 LPCWSTR lpszIter1 = lpszFile1;
2623 LPCWSTR lpszIter2 = lpszFile2;
2625 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1), debugstr_w(lpszFile2), achPath);
2630 if (!lpszFile1 || !lpszFile2)
2633 /* Handle roots first */
2634 if (PathIsUNCW(lpszFile1))
2636 if (!PathIsUNCW(lpszFile2))
2641 else if (PathIsUNCW(lpszFile2))
2642 return 0; /* Know already lpszFile1 is not UNC */
2647 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2648 (!*lpszIter2 || *lpszIter2 == '\\'))
2649 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2651 if (!*lpszIter1 || (tolowerW(*lpszIter1) != tolowerW(*lpszIter2)))
2652 break; /* Strings differ at this point */
2659 iLen++; /* Feature/Bug compatable with Win32 */
2661 if (iLen && achPath)
2663 memcpy(achPath,lpszFile1,iLen * sizeof(WCHAR));
2664 achPath[iLen] = '\0';
2669 /*************************************************************************
2670 * PathCompactPathA [SHLWAPI.@]
2672 * Make a path fit into a given width when printed to a DC.
2675 * hDc [I] Destination DC
2676 * lpszPath [O] Path to be printed to hDc
2677 * dx [i] Desired width
2680 * TRUE If the path was modified.
2683 BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx)
2687 TRACE("(%08x,%s,%d)\n", hDC, debugstr_a(lpszPath), dx);
2691 WCHAR szPath[MAX_PATH];
2692 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2693 bRet = PathCompactPathW(hDC, szPath, dx);
2694 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
2699 /*************************************************************************
2700 * PathCompactPathW [SHLWAPI.@]
2702 * See PathCompactPathA.
2704 BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
2706 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
2709 WCHAR buff[MAX_PATH];
2713 TRACE("(%08x,%s,%d)\n", hDC, debugstr_w(lpszPath), dx);
2719 hdc = hDC = GetDC(0);
2721 /* Get the length of the whole path */
2722 dwLen = strlenW(lpszPath);
2723 GetTextExtentPointW(hDC, lpszPath, dwLen, &size);
2725 if ((UINT)size.cx > dx)
2727 /* Path too big, must reduce it */
2729 DWORD dwEllipsesLen = 0, dwPathLen = 0;
2731 sFile = PathFindFileNameW(lpszPath);
2732 if (sFile != lpszPath)
2733 sFile = CharPrevW(lpszPath, sFile);
2735 /* Get the size of ellipses */
2736 GetTextExtentPointW(hDC, szEllipses, 3, &size);
2737 dwEllipsesLen = size.cx;
2738 /* Get the size of the file name */
2739 GetTextExtentPointW(hDC, sFile, strlenW(sFile), &size);
2740 dwPathLen = size.cx;
2742 if (sFile != lpszPath)
2744 LPWSTR sPath = sFile;
2745 BOOL bEllipses = FALSE;
2747 /* The path includes a file name. Include as much of the path prior to
2748 * the file name as possible, allowing for the ellipses, e.g:
2749 * c:\some very long path\filename ==> c:\some v...\filename
2751 strncpyW(buff, sFile, MAX_PATH);
2755 DWORD dwTotalLen = bEllipses? dwPathLen + dwEllipsesLen : dwPathLen;
2757 GetTextExtentPointW(hDC, lpszPath, sPath - lpszPath, &size);
2758 dwTotalLen += size.cx;
2759 if (dwTotalLen <= dx)
2761 sPath = CharPrevW(lpszPath, sPath);
2765 sPath = CharPrevW(lpszPath, sPath);
2766 sPath = CharPrevW(lpszPath, sPath);
2768 } while (sPath > lpszPath);
2770 if (sPath > lpszPath)
2774 strcpyW(sPath, szEllipses);
2775 strcpyW(sPath+3, buff);
2781 strcpyW(lpszPath, szEllipses);
2782 strcpyW(lpszPath+3, buff);
2786 /* Trim the path by adding ellipses to the end, e.g:
2787 * A very long file name.txt ==> A very...
2789 dwLen = strlenW(lpszPath);
2791 if (dwLen > MAX_PATH - 3)
2792 dwLen = MAX_PATH - 3;
2793 strncpyW(buff, sFile, dwLen);
2797 GetTextExtentPointW(hDC, buff, dwLen, &size);
2798 } while (dwLen && size.cx + dwEllipsesLen > dx);
2802 DWORD dwWritten = 0;
2804 dwEllipsesLen /= 3; /* Size of a single '.' */
2806 /* Write as much of the Ellipses string as possible */
2807 while (dwWritten + dwEllipsesLen < dx && dwLen < 3)
2810 dwWritten += dwEllipsesLen;
2818 strcpyW(buff + dwLen, szEllipses);
2819 strcpyW(lpszPath, buff);
2829 /*************************************************************************
2830 * PathGetCharTypeA [SHLWAPI.@]
2832 * Categorise a character from a file path.
2835 * ch [I] Character to get the type of
2838 * A set of GCT_ bit flags (from shlwapi.h) indicating the character type.
2840 UINT WINAPI PathGetCharTypeA(UCHAR ch)
2842 return PathGetCharTypeW(ch);
2845 /*************************************************************************
2846 * PathGetCharTypeW [SHLWAPI.@]
2848 * See PathGetCharTypeA.
2850 UINT WINAPI PathGetCharTypeW(WCHAR ch)
2854 TRACE("(%d)\n", ch);
2856 if (!ch || ch < ' ' || ch == '<' || ch == '>' ||
2857 ch == '"' || ch == '|' || ch == '/')
2858 flags = GCT_INVALID; /* Invalid */
2859 else if (ch == '*' || ch=='?')
2860 flags = GCT_WILD; /* Wildchars */
2861 else if ((ch == '\\') || (ch == ':'))
2862 return GCT_SEPARATOR; /* Path separators */
2867 if ((ch & 0x1 && ch != ';') || !ch || isalnum(ch) || ch == '$' || ch == '&' || ch == '(' ||
2868 ch == '.' || ch == '@' || ch == '^' ||
2869 ch == '\'' || ch == 130 || ch == '`')
2870 flags |= GCT_SHORTCHAR; /* All these are valid for DOS */
2873 flags |= GCT_SHORTCHAR; /* Bug compatable with win32 */
2874 flags |= GCT_LFNCHAR; /* Valid for long file names */
2879 /*************************************************************************
2880 * SHLWAPI_UseSystemForSystemFolders
2882 * Internal helper for PathMakeSystemFolderW.
2884 static BOOL SHLWAPI_UseSystemForSystemFolders()
2886 static BOOL bCheckedReg = FALSE;
2887 static BOOL bUseSystemForSystemFolders = FALSE;
2893 /* Key tells Win what file attributes to use on system folders */
2894 if (SHGetValueA(HKEY_LOCAL_MACHINE,
2895 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2896 "UseSystemForSystemFolders", 0, 0, 0))
2897 bUseSystemForSystemFolders = TRUE;
2899 return bUseSystemForSystemFolders;
2902 /*************************************************************************
2903 * PathMakeSystemFolderA [SHLWAPI.@]
2905 * Set system folder attribute for a path.
2908 * lpszPath [I] The path to turn into a system folder
2911 * TRUE If the path was changed to/already was a system folder
2912 * FALSE If the path is invalid or SetFileAttributesA fails
2914 BOOL WINAPI PathMakeSystemFolderA(LPCSTR lpszPath)
2918 TRACE("(%s)\n", debugstr_a(lpszPath));
2920 if (lpszPath && *lpszPath)
2922 WCHAR szPath[MAX_PATH];
2923 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2924 bRet = PathMakeSystemFolderW(szPath);
2929 /*************************************************************************
2930 * PathMakeSystemFolderW [SHLWAPI.@]
2932 * See PathMakeSystemFolderA.
2934 BOOL WINAPI PathMakeSystemFolderW(LPCWSTR lpszPath)
2936 DWORD dwDefaultAttr = FILE_ATTRIBUTE_READONLY, dwAttr;
2937 WCHAR buff[MAX_PATH];
2939 TRACE("(%s)\n", debugstr_w(lpszPath));
2941 if (!lpszPath || !*lpszPath)
2944 /* If the directory is already a system directory, dont do anything */
2945 GetSystemDirectoryW(buff, MAX_PATH);
2946 if (!strcmpW(buff, lpszPath))
2949 GetWindowsDirectoryW(buff, MAX_PATH);
2950 if (!strcmpW(buff, lpszPath))
2953 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
2954 if (SHLWAPI_UseSystemForSystemFolders())
2955 dwDefaultAttr = FILE_ATTRIBUTE_SYSTEM;
2957 if ((dwAttr = GetFileAttributesW(lpszPath)) == -1u)
2960 /* Change file attributes to system attributes */
2961 dwAttr &= ~(FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_READONLY);
2962 return SetFileAttributesW(lpszPath, dwAttr | dwDefaultAttr);
2965 /*************************************************************************
2966 * PathRenameExtensionA [SHLWAPI.@]
2968 * Swap the file extension in a path with another extension.
2971 * pszPath [O] Path to swap the extension in
2972 * pszExt [I] The new extension
2975 * TRUE if pszPath was modified
2976 * FALSE if pszPath or pszExt is NULL, or the new path is too long
2978 BOOL WINAPI PathRenameExtensionA(LPSTR lpszPath, LPCSTR lpszExt)
2980 LPSTR lpszExtension;
2982 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExt));
2984 lpszExtension = PathFindExtensionA(lpszPath);
2986 if (!lpszExtension || (lpszExtension - lpszPath + strlen(lpszExt) >= MAX_PATH))
2989 strcpy(lpszExtension, lpszExt);
2993 /*************************************************************************
2994 * PathRenameExtensionW [SHLWAPI.@]
2996 * See PathRenameExtensionA.
2998 BOOL WINAPI PathRenameExtensionW(LPWSTR lpszPath, LPCWSTR lpszExt)
3000 LPWSTR lpszExtension;
3002 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExt));
3004 lpszExtension = PathFindExtensionW(lpszPath);
3006 if (!lpszExtension || (lpszExtension - lpszPath + strlenW(lpszExt) >= MAX_PATH))
3009 strcpyW(lpszExtension, lpszExt);
3013 /*************************************************************************
3014 * PathSearchAndQualifyA [SHLWAPI.@]
3016 * Determine if a given path is correct and fully qualified.
3019 * lpszPath [I] Path to check
3020 * lpszBuf [O] Output for correct path
3021 * cchBuf [I] Size of lpszBuf
3026 BOOL WINAPI PathSearchAndQualifyA(LPCSTR lpszPath, LPSTR lpszBuf, UINT cchBuf)
3028 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath), lpszBuf, cchBuf);
3032 /*************************************************************************
3033 * PathSearchAndQualifyW [SHLWAPI.@]
3035 * See PathSearchAndQualifyA
3037 BOOL WINAPI PathSearchAndQualifyW(LPCWSTR lpszPath, LPWSTR lpszBuf, UINT cchBuf)
3039 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath), lpszBuf, cchBuf);
3043 /*************************************************************************
3044 * PathSkipRootA [SHLWAPI.@]
3046 * Return the portion of a path following the drive letter or mount point.
3049 * lpszPath [I] The path to skip on
3052 * Success: A pointer to the next character after the root.
3053 * Failure: NULL, if lpszPath is invalid, has no root or is a MB string.
3055 LPSTR WINAPI PathSkipRootA(LPCSTR lpszPath)
3057 TRACE("(%s)\n", debugstr_a(lpszPath));
3059 if (!lpszPath || !*lpszPath)
3062 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3064 /* Network share: skip share server and mount point */
3066 if ((lpszPath = StrChrA(lpszPath, '\\')) &&
3067 (lpszPath = StrChrA(lpszPath + 1, '\\')))
3069 return (LPSTR)lpszPath;
3072 if (IsDBCSLeadByte(*lpszPath))
3076 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3077 return (LPSTR)lpszPath + 3;
3081 /*************************************************************************
3082 * PathSkipRootW [SHLWAPI.@]
3084 * See PathSkipRootA.
3086 LPWSTR WINAPI PathSkipRootW(LPCWSTR lpszPath)
3088 TRACE("(%s)\n", debugstr_w(lpszPath));
3090 if (!lpszPath || !*lpszPath)
3093 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3095 /* Network share: skip share server and mount point */
3097 if ((lpszPath = StrChrW(lpszPath, '\\')) &&
3098 (lpszPath = StrChrW(lpszPath + 1, '\\')))
3100 return (LPWSTR)lpszPath;
3104 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3105 return (LPWSTR)lpszPath + 3;
3109 /*************************************************************************
3110 * PathCreateFromUrlA [SHLWAPI.@]
3112 * Create a path from a URL
3115 * lpszUrl [I] URL to convert into a path
3116 * lpszPath [O] Output buffer for the resulting Path
3117 * pcchPath [I] Length of lpszPath
3118 * dwFlags [I] Flags controlling the conversion
3121 * Success: S_OK. lpszPath contains the URL in path format
3122 * Failure: An HRESULT error code such as E_INVALIDARG.
3124 HRESULT WINAPI PathCreateFromUrlA(LPCSTR lpszUrl, LPSTR lpszPath,
3125 LPDWORD pcchPath, DWORD dwFlags)
3127 FIXME("(%s,%p,%p,0x%08lx)-stub\n", debugstr_a(lpszUrl), lpszPath, pcchPath, dwFlags);
3129 if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
3130 return E_INVALIDARG;
3132 /* extracts thing prior to : in pszURL and checks against:
3136 * about - if match returns E_INVALIDARG
3142 /*************************************************************************
3143 * PathCreateFromUrlW [SHLWAPI.@]
3145 * See PathCreateFromUrlA.
3147 HRESULT WINAPI PathCreateFromUrlW(LPCWSTR lpszUrl, LPWSTR lpszPath,
3148 LPDWORD pcchPath, DWORD dwFlags)
3150 FIXME("(%s,%p,%p,0x%08lx)-stub\n", debugstr_w(lpszUrl), lpszPath, pcchPath, dwFlags);
3152 if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
3153 return E_INVALIDARG;
3158 /*************************************************************************
3159 * PathRelativePathToA [SHLWAPI.@]
3161 * Create a relative path from one path to another.
3164 * lpszPath [O] Destination for relative path
3165 * lpszFrom [I] Source path
3166 * dwAttrFrom [I] File attribute of source path
3167 * lpszTo [I] Destination path
3168 * dwAttrTo [I] File attributes of destination path
3171 * TRUE If a relative path can be formed. lpszPath contains the new path
3172 * FALSE If the paths are not relavtive or any parameters are invalid
3175 * lpszTo should be at least MAX_PATH in length.
3176 * Calling this function with relative paths for lpszFrom or lpszTo may
3177 * give erroneous results.
3179 * The Win32 version of this function contains a bug where the lpszTo string
3180 * may be referenced 1 byte beyond the end of the string. As a result random
3181 * garbage may be written to the output path, depending on what lies beyond
3182 * the last byte of the string. This bug occurs because of the behaviour of
3183 * PathCommonPrefix (see notes for that function), and no workaround seems
3184 * possible with Win32.
3185 * This bug has been fixed here, so for example the relative path from "\\"
3186 * to "\\" is correctly determined as "." in this implementation.
3188 BOOL WINAPI PathRelativePathToA(LPSTR lpszPath, LPCSTR lpszFrom, DWORD dwAttrFrom,
3189 LPCSTR lpszTo, DWORD dwAttrTo)
3193 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_a(lpszFrom),
3194 dwAttrFrom, debugstr_a(lpszTo), dwAttrTo);
3196 if(lpszPath && lpszFrom && lpszTo)
3198 WCHAR szPath[MAX_PATH];
3199 WCHAR szFrom[MAX_PATH];
3200 WCHAR szTo[MAX_PATH];
3201 MultiByteToWideChar(0,0,lpszFrom,-1,szFrom,MAX_PATH);
3202 MultiByteToWideChar(0,0,lpszTo,-1,szTo,MAX_PATH);
3203 bRet = PathRelativePathToW(szPath,szFrom,dwAttrFrom,szTo,dwAttrTo);
3204 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
3209 /*************************************************************************
3210 * PathRelativePathToW [SHLWAPI.@]
3212 * See PathRelativePathToA.
3214 BOOL WINAPI PathRelativePathToW(LPWSTR lpszPath, LPCWSTR lpszFrom, DWORD dwAttrFrom,
3215 LPCWSTR lpszTo, DWORD dwAttrTo)
3217 static const WCHAR szPrevDirSlash[] = { '.', '.', '\\', '\0' };
3218 static const WCHAR szPrevDir[] = { '.', '.', '\0' };
3219 WCHAR szFrom[MAX_PATH];
3220 WCHAR szTo[MAX_PATH];
3223 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_w(lpszFrom),
3224 dwAttrFrom, debugstr_w(lpszTo), dwAttrTo);
3226 if(!lpszPath || !lpszFrom || !lpszTo)
3230 strncpyW(szFrom, lpszFrom, MAX_PATH);
3231 strncpyW(szTo, lpszTo, MAX_PATH);
3233 if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
3234 PathRemoveFileSpecW(szFrom);
3235 if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
3236 PathRemoveFileSpecW(szTo);
3238 /* Paths can only be relative if they have a common root */
3239 if(!(dwLen = PathCommonPrefixW(szFrom, szTo, 0)))
3242 /* Strip off lpszFrom components to the root, by adding "..\" */
3243 lpszFrom = szFrom + dwLen;
3249 if (*lpszFrom == '\\')
3254 lpszFrom = PathFindNextComponentW(lpszFrom);
3255 strcatW(lpszPath, *lpszFrom ? szPrevDirSlash : szPrevDir);
3258 /* From the root add the components of lpszTo */
3260 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3263 if (*lpszTo && lpszTo[-1])
3265 if (*lpszTo != '\\')
3267 dwLen = strlenW(lpszPath);
3268 if (dwLen + strlenW(lpszTo) >= MAX_PATH)
3273 strcpyW(lpszPath + dwLen, lpszTo);
3278 /*************************************************************************
3279 * PathUnmakeSystemFolderA [SHLWAPI.@]
3281 * Remove the system folder attributes from a path.
3284 * lpszPath [I] The path to remove attributes from
3288 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3289 * SetFileAttributesA fails.
3291 BOOL WINAPI PathUnmakeSystemFolderA(LPCSTR lpszPath)
3295 TRACE("(%s)\n", debugstr_a(lpszPath));
3297 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesA(lpszPath)) == -1u ||
3298 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3301 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3302 return SetFileAttributesA(lpszPath, dwAttr);
3305 /*************************************************************************
3306 * PathUnmakeSystemFolderW [SHLWAPI.@]
3308 * See PathUnmakeSystemFolderA.
3310 BOOL WINAPI PathUnmakeSystemFolderW(LPCWSTR lpszPath)
3314 TRACE("(%s)\n", debugstr_w(lpszPath));
3316 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesW(lpszPath)) == -1u ||
3317 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3320 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3321 return SetFileAttributesW(lpszPath, dwAttr);
3325 /*************************************************************************
3326 * PathSetDlgItemPathA [SHLWAPI.@]
3328 * Set the text of a dialog item to a path, shrinking the path to fit
3329 * if it is too big for the item.
3332 * hDlg [I] Dialog handle
3333 * id [I] ID of item in the dialog
3334 * lpszPath [I] Path to set as the items text
3340 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3341 * window text is erased).
3343 VOID WINAPI PathSetDlgItemPathA(HWND hDlg, int id, LPCSTR lpszPath)
3345 WCHAR szPath[MAX_PATH];
3347 TRACE("(%8x,%8x,%s)\n",hDlg, id, debugstr_a(lpszPath));
3350 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
3353 PathSetDlgItemPathW(hDlg, id, szPath);
3356 /*************************************************************************
3357 * PathSetDlgItemPathW [SHLWAPI.@]
3359 * See PathSetDlgItemPathA.
3361 VOID WINAPI PathSetDlgItemPathW(HWND hDlg, int id, LPCWSTR lpszPath)
3363 WCHAR path[MAX_PATH + 1];
3369 TRACE("(%8x,%8x,%s)\n",hDlg, id, debugstr_w(lpszPath));
3371 if (!(hwItem = GetDlgItem(hDlg, id)))
3375 strncpyW(path, lpszPath, sizeof(path));
3379 GetClientRect(hwItem, &rect);
3381 hPrevObj = SelectObject(hdc, (HGDIOBJ)SendMessageW(hwItem,WM_GETFONT,0,0));
3385 PathCompactPathW(hdc, path, rect.right);
3386 SelectObject(hdc, hPrevObj);
3389 ReleaseDC(hDlg, hdc);
3390 SetWindowTextW(hwItem, path);
3393 /*************************************************************************
3394 * PathIsNetworkPathA [SHLWAPI.@]
3396 * Determine if the given path is a network path.
3399 * lpszPath [I] Path to check
3402 * TRUE If path is a UNC share or mapped network drive
3403 * FALSE If path is a local drive or cannot be determined
3405 BOOL WINAPI PathIsNetworkPathA(LPCSTR lpszPath)
3409 TRACE("(%s)\n",debugstr_a(lpszPath));
3413 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3415 dwDriveNum = PathGetDriveNumberA(lpszPath);
3416 if (dwDriveNum == -1u)
3418 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3419 return pIsNetDrive(dwDriveNum);
3422 /*************************************************************************
3423 * PathIsNetworkPathW [SHLWAPI.@]
3425 * See PathIsNetworkPathA.
3427 BOOL WINAPI PathIsNetworkPathW(LPCWSTR lpszPath)
3431 TRACE("(%s)\n", debugstr_w(lpszPath));
3435 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3437 dwDriveNum = PathGetDriveNumberW(lpszPath);
3438 if (dwDriveNum == -1u)
3440 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3441 return pIsNetDrive(dwDriveNum);
3444 /*************************************************************************
3445 * PathIsLFNFileSpecA [SHLWAPI.@]
3447 * Determine if the given path is a long file name
3450 * lpszPath [I] Path to check
3453 * TRUE If path is a long file name
3454 * FALSE If path is a valid DOS 8.3 file name
3456 BOOL WINAPI PathIsLFNFileSpecA(LPCSTR lpszPath)
3458 DWORD dwNameLen = 0, dwExtLen = 0;
3460 TRACE("(%s)\n",debugstr_a(lpszPath));
3467 if (*lpszPath == ' ')
3468 return TRUE; /* DOS names cannot have spaces */
3469 if (*lpszPath == '.')
3472 return TRUE; /* DOS names have only one dot */
3479 return TRUE; /* DOS extensions are <= 3 chars*/
3485 return TRUE; /* DOS names are <= 8 chars */
3487 lpszPath += IsDBCSLeadByte(*lpszPath) ? 2 : 1;
3489 return FALSE; /* Valid DOS path */
3492 /*************************************************************************
3493 * PathIsLFNFileSpecW [SHLWAPI.@]
3495 * See PathIsLFNFileSpecA.
3497 BOOL WINAPI PathIsLFNFileSpecW(LPCWSTR lpszPath)
3499 DWORD dwNameLen = 0, dwExtLen = 0;
3501 TRACE("(%s)\n",debugstr_w(lpszPath));
3508 if (*lpszPath == ' ')
3509 return TRUE; /* DOS names cannot have spaces */
3510 if (*lpszPath == '.')
3513 return TRUE; /* DOS names have only one dot */
3520 return TRUE; /* DOS extensions are <= 3 chars*/
3526 return TRUE; /* DOS names are <= 8 chars */
3530 return FALSE; /* Valid DOS path */
3533 /*************************************************************************
3534 * PathIsDirectoryEmptyA [SHLWAPI.@]
3536 * Determine if a given directory is empty.
3539 * lpszPath [I] Directory to check
3542 * TRUE If the directory exists and contains no files
3545 BOOL WINAPI PathIsDirectoryEmptyA(LPCSTR lpszPath)
3549 TRACE("(%s)\n",debugstr_a(lpszPath));
3553 WCHAR szPath[MAX_PATH];
3554 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
3555 bRet = PathIsDirectoryEmptyW(szPath);
3560 /*************************************************************************
3561 * PathIsDirectoryEmptyW [SHLWAPI.@]
3563 * See PathIsDirectoryEmptyA.
3565 BOOL WINAPI PathIsDirectoryEmptyW(LPCWSTR lpszPath)
3567 static const WCHAR szAllFiles[] = { '*', '.', '*', '\0' };
3568 WCHAR szSearch[MAX_PATH];
3571 BOOL retVal = FALSE;
3572 WIN32_FIND_DATAW find_data;
3574 TRACE("(%s)\n",debugstr_w(lpszPath));
3576 if (!lpszPath || !PathIsDirectoryW(lpszPath))
3579 strncpyW(szSearch, lpszPath, MAX_PATH);
3580 PathAddBackslashW(szSearch);
3581 dwLen = strlenW(szSearch);
3582 if (dwLen > MAX_PATH - 4)
3585 strcpyW(szSearch + dwLen, szAllFiles);
3586 hfind = FindFirstFileW(szSearch, &find_data);
3588 if (hfind != INVALID_HANDLE_VALUE &&
3589 find_data.cFileName[0] == '.' &&
3590 find_data.cFileName[1] == '.')
3592 /* The only directory entry should be the parent */
3593 if (!FindNextFileW(hfind, &find_data))
3601 /*************************************************************************
3602 * PathFindSuffixArrayA [SHLWAPI.@]
3604 * Find a suffix string in an array of suffix strings
3607 * lpszSuffix [I] Suffix string to search for
3608 * lppszArray [I] Array of suffix strings to search
3609 * dwCount [I] Number of elements in lppszArray
3612 * Success The index of the position of lpszSuffix in lppszArray
3613 * Failure 0, if any parameters are invalid or lpszSuffix is not found
3616 * The search is case sensitive.
3617 * The match is made against the end of the suffix string, so for example:
3618 * lpszSuffix=fooBAR matches BAR, but lpszSuffix=fooBARfoo does not.
3620 int WINAPI PathFindSuffixArrayA(LPCSTR lpszSuffix, LPCSTR *lppszArray, int dwCount)
3625 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix), lppszArray, dwCount);
3627 if (lpszSuffix && lppszArray && dwCount > 0)
3629 dwLen = strlen(lpszSuffix);
3631 while (dwRet < dwCount)
3633 DWORD dwCompareLen = strlen(*lppszArray);
3634 if (dwCompareLen < dwLen)
3636 if (!strcmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3637 return dwRet; /* Found */
3646 /*************************************************************************
3647 * PathFindSuffixArrayW [SHLWAPI.@]
3649 * See PathFindSuffixArrayA.
3651 int WINAPI PathFindSuffixArrayW(LPCWSTR lpszSuffix, LPCWSTR *lppszArray, int dwCount)
3656 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix), lppszArray, dwCount);
3658 if (lpszSuffix && lppszArray && dwCount > 0)
3660 dwLen = strlenW(lpszSuffix);
3662 while (dwRet < dwCount)
3664 DWORD dwCompareLen = strlenW(*lppszArray);
3665 if (dwCompareLen < dwLen)
3667 if (!strcmpW(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3668 return dwRet; /* Found */
3677 /*************************************************************************
3678 * PathUndecorateA [SHLWAPI.@]
3680 * Undecorate a file path
3683 * lpszPath [O] Path to undecorate
3689 * A decorations form is "path[n].ext" where n is an optional decimal number.
3691 VOID WINAPI PathUndecorateA(LPSTR lpszPath)
3693 TRACE("(%s)\n",debugstr_a(lpszPath));
3697 LPSTR lpszExt = PathFindExtensionA(lpszPath);
3698 if (lpszExt > lpszPath && lpszExt[-1] == ']')
3700 LPSTR lpszSkip = lpszExt - 2;
3701 if (*lpszSkip == '[')
3702 lpszSkip++; /* [] (no number) */
3704 while (lpszSkip > lpszPath && isdigit(lpszSkip[-1]))
3706 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
3708 /* remove the [n] */
3711 *lpszSkip++ = *lpszExt++;
3718 /*************************************************************************
3719 * PathUndecorateW [SHLWAPI.@]
3721 * See PathUndecorateA.
3723 VOID WINAPI PathUndecorateW(LPWSTR lpszPath)
3725 TRACE("(%s)\n",debugstr_w(lpszPath));
3729 LPWSTR lpszExt = PathFindExtensionW(lpszPath);
3730 if (lpszExt > lpszPath && lpszExt[-1] == ']')
3732 LPWSTR lpszSkip = lpszExt - 2;
3733 if (*lpszSkip == '[')
3734 lpszSkip++; /* [] (no number) */
3736 while (lpszSkip > lpszPath && isdigitW(lpszSkip[-1]))
3738 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
3740 /* remove the [n] */
3743 *lpszSkip++ = *lpszExt++;