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))
1203 if (PathFileExistsDefExtW(buff, dwWhich))
1205 strcpyW(lpszFile, buff);
1214 /*************************************************************************
1217 * Search a range of paths for a specific type of executable.
1220 * lpszFile [I/O] File to search for
1221 * lppszOtherDirs [I] Other directories to look in
1222 * dwWhich [I] Type of executable to search for
1225 * Success: TRUE. The path to the executable is stored in lpszFile.
1226 * Failure: FALSE. The path to the executable is unchanged.
1228 BOOL WINAPI PathFindOnPathExA(LPSTR lpszFile,LPCSTR *lppszOtherDirs,DWORD dwWhich)
1230 WCHAR szFile[MAX_PATH];
1231 WCHAR buff[MAX_PATH];
1233 TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile), lppszOtherDirs, dwWhich);
1235 if (!lpszFile || !PathIsFileSpecA(lpszFile))
1238 MultiByteToWideChar(0,0,lpszFile,-1,szFile,MAX_PATH);
1240 /* Search provided directories first */
1241 if (lppszOtherDirs && *lppszOtherDirs)
1243 WCHAR szOther[MAX_PATH];
1244 LPCSTR *lpszOtherPath = lppszOtherDirs;
1246 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1248 MultiByteToWideChar(0,0,*lpszOtherPath,-1,szOther,MAX_PATH);
1249 PathCombineW(buff, szOther, szFile);
1250 if (PathFileExistsDefExtW(buff, dwWhich))
1252 WideCharToMultiByte(0,0,buff,-1,lpszFile,MAX_PATH,0,0);
1258 /* Not found, try system and path dirs */
1259 if (SHLWAPI_PathFindInOtherDirs(szFile, dwWhich))
1261 WideCharToMultiByte(0,0,szFile,-1,lpszFile,MAX_PATH,0,0);
1267 /*************************************************************************
1270 * Unicode version of PathFindOnPathExA.
1272 BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile,LPCWSTR *lppszOtherDirs,DWORD dwWhich)
1274 WCHAR buff[MAX_PATH];
1276 TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile), lppszOtherDirs, dwWhich);
1278 if (!lpszFile || !PathIsFileSpecW(lpszFile))
1281 /* Search provided directories first */
1282 if (lppszOtherDirs && *lppszOtherDirs)
1284 LPCWSTR *lpszOtherPath = lppszOtherDirs;
1285 while (lpszOtherPath && *lpszOtherPath && (*lpszOtherPath)[0])
1287 PathCombineW(buff, *lpszOtherPath, lpszFile);
1288 if (PathFileExistsDefExtW(buff, dwWhich))
1290 strcpyW(lpszFile, buff);
1296 /* Not found, try system and path dirs */
1297 return SHLWAPI_PathFindInOtherDirs(lpszFile, dwWhich);
1300 /*************************************************************************
1301 * PathFindOnPathA [SHLWAPI.@]
1303 * Search a range of paths for an executable.
1306 * lpszFile [I/O] File to search for
1307 * lppszOtherDirs [I] Other directories to look in
1310 * Success: TRUE. The path to the executable is stored in lpszFile.
1311 * Failure: FALSE. The path to the executable is unchanged.
1313 BOOL WINAPI PathFindOnPathA(LPSTR lpszFile, LPCSTR *lppszOtherDirs)
1315 TRACE("(%s,%p)\n", debugstr_a(lpszFile), lppszOtherDirs);
1316 return PathFindOnPathExA(lpszFile, lppszOtherDirs, 0);
1319 /*************************************************************************
1320 * PathFindOnPathW [SHLWAPI.@]
1322 * See PathFindOnPathA.
1324 BOOL WINAPI PathFindOnPathW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs)
1326 TRACE("(%s,%p)\n", debugstr_w(lpszFile), lppszOtherDirs);
1327 return PathFindOnPathExW(lpszFile,lppszOtherDirs, 0);
1330 /*************************************************************************
1331 * PathCompactPathExA [SHLWAPI.@]
1333 * Compact a path into a given number of characters.
1336 * lpszDest [O] Destination for compacted path
1337 * lpszPath [I] Source path
1338 * cchMax [I] Maximum size of compacted path
1339 * dwFlags [I] Reserved
1342 * Success: TRUE. The compacted path is written to lpszDest.
1343 * Failure: FALSE. lpszPath is undefined.
1346 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1348 * The Win32 version of this function contains a bug: When cchMax == 7,
1349 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1352 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1353 * because Win32 will insert a "\" in lpszDest, even if one is
1354 * not present in the original path.
1356 BOOL WINAPI PathCompactPathExA(LPSTR lpszDest, LPCSTR lpszPath,
1357 UINT cchMax, DWORD dwFlags)
1361 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest, debugstr_a(lpszPath), cchMax, dwFlags);
1363 if (lpszPath && lpszDest)
1365 WCHAR szPath[MAX_PATH];
1366 WCHAR szDest[MAX_PATH];
1368 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
1370 bRet = PathCompactPathExW(szDest, szPath, cchMax, dwFlags);
1371 WideCharToMultiByte(0,0,szDest,-1,lpszDest,MAX_PATH,0,0);
1376 /*************************************************************************
1377 * PathCompactPathExW [SHLWAPI.@]
1379 * See PathCompactPathExA.
1381 BOOL WINAPI PathCompactPathExW(LPWSTR lpszDest, LPCWSTR lpszPath,
1382 UINT cchMax, DWORD dwFlags)
1384 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
1386 DWORD dwLen, dwFileLen = 0;
1388 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest, debugstr_w(lpszPath), cchMax, dwFlags);
1395 WARN("Invalid lpszDest would crash under Win32!\n");
1404 dwLen = strlenW(lpszPath) + 1;
1408 /* Don't need to compact */
1409 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1413 /* Path must be compacted to fit into lpszDest */
1414 lpszFile = PathFindFileNameW(lpszPath);
1415 dwFileLen = lpszPath + dwLen - lpszFile;
1417 if (dwFileLen == dwLen)
1419 /* No root in psth */
1422 while (--cchMax > 0) /* No room left for anything but ellipses */
1427 /* Compact the file name with ellipses at the end */
1429 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1430 strcpyW(lpszDest + cchMax, szEllipses);
1433 /* We have a root in the path */
1434 lpszFile--; /* Start compacted filename with the path separator */
1437 if (dwFileLen + 3 > cchMax)
1439 /* Compact the file name */
1442 while (--cchMax > 0) /* No room left for anything but ellipses */
1447 strcpyW(lpszDest, szEllipses);
1450 *lpszDest++ = *lpszFile++;
1453 while (--cchMax > 0) /* No room left for anything but ellipses */
1459 memcpy(lpszDest, lpszFile, cchMax * sizeof(WCHAR));
1460 strcpyW(lpszDest + cchMax, szEllipses);
1464 /* Only the root needs to be Compacted */
1465 dwLen = cchMax - dwFileLen - 3;
1466 memcpy(lpszDest, lpszPath, dwLen * sizeof(WCHAR));
1467 strcpyW(lpszDest + dwLen, szEllipses);
1468 strcpyW(lpszDest + dwLen + 3, lpszFile);
1472 /*************************************************************************
1473 * PathIsRelativeA [SHLWAPI.@]
1475 * Determine if a path is a relative path.
1478 * lpszPath [I] Path to check
1481 * TRUE: The path is relative, or is invalid.
1482 * FALSE: The path is not relative.
1484 BOOL WINAPI PathIsRelativeA (LPCSTR lpszPath)
1486 TRACE("(%s)\n",debugstr_a(lpszPath));
1488 if (!lpszPath || !*lpszPath || IsDBCSLeadByte(*lpszPath))
1490 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1495 /*************************************************************************
1496 * PathIsRelativeW [SHLWAPI.@]
1498 * See PathIsRelativeA.
1500 BOOL WINAPI PathIsRelativeW (LPCWSTR lpszPath)
1502 TRACE("(%s)\n",debugstr_w(lpszPath));
1504 if (!lpszPath || !*lpszPath)
1506 if (*lpszPath == '\\' || (*lpszPath && lpszPath[1] == ':'))
1511 /*************************************************************************
1512 * PathIsRootA [SHLWAPI.@]
1514 * Determine if a path is a root path.
1517 * lpszPath [I] Path to check
1520 * TRUE If lpszPath is valid and a root path,
1523 BOOL WINAPI PathIsRootA(LPCSTR lpszPath)
1525 TRACE("(%s)\n", debugstr_a(lpszPath));
1527 if (lpszPath && *lpszPath)
1529 if (*lpszPath == '\\')
1532 return TRUE; /* \ */
1533 else if (lpszPath[1]=='\\')
1535 BOOL bSeenSlash = FALSE;
1538 /* Check for UNC root path */
1541 if (*lpszPath == '\\')
1547 lpszPath = CharNextA(lpszPath);
1552 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1553 return TRUE; /* X:\ */
1558 /*************************************************************************
1559 * PathIsRootW [SHLWAPI.@]
1563 BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
1565 TRACE("(%s)\n", debugstr_w(lpszPath));
1567 if (lpszPath && *lpszPath)
1569 if (*lpszPath == '\\')
1572 return TRUE; /* \ */
1573 else if (lpszPath[1]=='\\')
1575 BOOL bSeenSlash = FALSE;
1578 /* Check for UNC root path */
1581 if (*lpszPath == '\\')
1587 lpszPath = CharNextW(lpszPath);
1592 else if (lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1593 return TRUE; /* X:\ */
1598 /*************************************************************************
1599 * PathIsDirectoryA [SHLWAPI.@]
1601 * Determine if a path is a valid directory
1604 * lpszPath [I] Path to check.
1607 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1608 * FALSE if lpszPath is invalid or not a directory.
1611 * Although this function is prototyped as returning a BOOL, it returns
1612 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1614 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1619 BOOL WINAPI PathIsDirectoryA(LPCSTR lpszPath)
1623 TRACE("(%s)\n", debugstr_a(lpszPath));
1625 if (!lpszPath || PathIsUNCServerA(lpszPath))
1628 if (PathIsUNCServerShareA(lpszPath))
1630 FIXME("UNC Server Share not yet supported - FAILING\n");
1634 if ((dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES)
1636 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1639 /*************************************************************************
1640 * PathIsDirectoryW [SHLWAPI.@]
1642 * See PathIsDirectoryA.
1644 BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
1648 TRACE("(%s)\n", debugstr_w(lpszPath));
1650 if (!lpszPath || PathIsUNCServerW(lpszPath))
1653 if (PathIsUNCServerShareW(lpszPath))
1655 FIXME("UNC Server Share not yet supported - FAILING\n");
1659 if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
1661 return dwAttr & FILE_ATTRIBUTE_DIRECTORY;
1664 /*************************************************************************
1665 * PathFileExistsA [SHLWAPI.@]
1667 * Determine if a file exists.
1670 * lpszPath [I] Path to check
1673 * TRUE If the file exists and is readable
1676 BOOL WINAPI PathFileExistsA(LPCSTR lpszPath)
1681 TRACE("(%s)\n",debugstr_a(lpszPath));
1686 iPrevErrMode = SetErrorMode(1);
1687 dwAttr = GetFileAttributesA(lpszPath);
1688 SetErrorMode(iPrevErrMode);
1689 return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
1692 /*************************************************************************
1693 * PathFileExistsW [SHLWAPI.@]
1695 * See PathFileExistsA.
1697 BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
1702 TRACE("(%s)\n",debugstr_w(lpszPath));
1707 iPrevErrMode = SetErrorMode(1);
1708 dwAttr = GetFileAttributesW(lpszPath);
1709 SetErrorMode(iPrevErrMode);
1710 return dwAttr == INVALID_FILE_ATTRIBUTES ? FALSE : TRUE;
1713 /*************************************************************************
1714 * PathMatchSingleMaskA [internal]
1716 static BOOL WINAPI PathMatchSingleMaskA(LPCSTR name, LPCSTR mask)
1718 while (*name && *mask && *mask!=';')
1724 if (PathMatchSingleMaskA(name,mask+1))
1725 return TRUE; /* try substrings */
1730 if (toupper(*mask) != toupper(*name) && *mask != '?')
1733 name = CharNextA(name);
1734 mask = CharNextA(mask);
1739 while (*mask == '*')
1741 if (!*mask || *mask == ';')
1747 /*************************************************************************
1748 * PathMatchSingleMaskW [internal]
1750 static BOOL WINAPI PathMatchSingleMaskW(LPCWSTR name, LPCWSTR mask)
1752 while (*name && *mask && *mask != ';')
1758 if (PathMatchSingleMaskW(name,mask+1))
1759 return TRUE; /* try substrings */
1764 if (toupperW(*mask) != toupperW(*name) && *mask != '?')
1767 name = CharNextW(name);
1768 mask = CharNextW(mask);
1772 while (*mask == '*')
1774 if (!*mask || *mask == ';')
1780 /*************************************************************************
1781 * PathMatchSpecA [SHLWAPI.@]
1783 * Determine if a path matches one or more search masks.
1786 * lpszPath [I] Path to check
1787 * lpszMask [I] Search mask(s)
1790 * TRUE If lpszPath is valid and is matched
1794 * Multiple search masks may be given if they are separated by ";". The
1795 * pattern "*.*" is treated specially in that it matches all paths (for
1796 * backwards compatibility with DOS).
1798 BOOL WINAPI PathMatchSpecA(LPCSTR lpszPath, LPCSTR lpszMask)
1800 TRACE("(%s,%s)\n", lpszPath, lpszMask);
1802 if (!lstrcmpA(lpszMask, "*.*"))
1803 return TRUE; /* Matches every path */
1807 if (PathMatchSingleMaskA(lpszPath, lpszMask))
1808 return TRUE; /* Matches the current mask */
1810 while (*lpszMask && *lpszMask != ';')
1811 lpszMask = CharNextA(lpszMask);
1813 if (*lpszMask == ';')
1816 while (*lpszMask == ' ')
1817 lpszMask++; /* masks may be separated by "; " */
1823 /*************************************************************************
1824 * PathMatchSpecW [SHLWAPI.@]
1826 * See PathMatchSpecA.
1828 BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
1830 static const WCHAR szStarDotStar[] = { '*', '.', '*', '\0' };
1832 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszMask));
1834 if (!lstrcmpW(lpszMask, szStarDotStar))
1835 return TRUE; /* Matches every path */
1839 if (PathMatchSingleMaskW(lpszPath, lpszMask))
1840 return TRUE; /* Matches the current path */
1842 while (*lpszMask && *lpszMask != ';')
1845 if (*lpszMask == ';')
1848 while (*lpszMask == ' ')
1849 lpszMask++; /* Masks may be separated by "; " */
1855 /*************************************************************************
1856 * PathIsSameRootA [SHLWAPI.@]
1858 * Determine if two paths share the same root.
1861 * lpszPath1 [I] Source path
1862 * lpszPath2 [I] Path to compare with
1865 * TRUE If both paths are valid and share the same root.
1866 * FALSE If either path is invalid or the paths do not share the same root.
1868 BOOL WINAPI PathIsSameRootA(LPCSTR lpszPath1, LPCSTR lpszPath2)
1873 TRACE("(%s,%s)\n", debugstr_a(lpszPath1), debugstr_a(lpszPath2));
1875 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootA(lpszPath1)))
1878 dwLen = PathCommonPrefixA(lpszPath1, lpszPath2, NULL) + 1;
1879 if (lpszStart - lpszPath1 > dwLen)
1880 return FALSE; /* Paths not common up to length of the root */
1884 /*************************************************************************
1885 * PathIsSameRootW [SHLWAPI.@]
1887 * See PathIsSameRootA.
1889 BOOL WINAPI PathIsSameRootW(LPCWSTR lpszPath1, LPCWSTR lpszPath2)
1894 TRACE("(%s,%s)\n", debugstr_w(lpszPath1), debugstr_w(lpszPath2));
1896 if (!lpszPath1 || !lpszPath2 || !(lpszStart = PathSkipRootW(lpszPath1)))
1899 dwLen = PathCommonPrefixW(lpszPath1, lpszPath2, NULL) + 1;
1900 if (lpszStart - lpszPath1 > dwLen)
1901 return FALSE; /* Paths not common up to length of the root */
1905 /*************************************************************************
1906 * PathIsContentTypeA [SHLWAPI.@]
1908 * Determine if a file is of a given registered content type.
1911 * lpszPath [I] File to check
1912 * lpszContentType [I] Content type to check for
1915 * TRUE If lpszPath is a given registered content type,
1919 * This function looks up the registered content type for lpszPath. If
1920 * a content type is registered, it is compared (case insensitively) to
1921 * lpszContentType. Only if this matches does the function succeed.
1923 BOOL WINAPI PathIsContentTypeA(LPCSTR lpszPath, LPCSTR lpszContentType)
1927 char szBuff[MAX_PATH];
1929 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszContentType));
1931 if (lpszPath && (szExt = PathFindExtensionA(lpszPath)) && *szExt &&
1932 !SHGetValueA(HKEY_CLASSES_ROOT, szExt, "Content Type",
1933 REG_NONE, szBuff, &dwDummy) &&
1934 !strcasecmp(lpszContentType, szBuff))
1941 /*************************************************************************
1942 * PathIsContentTypeW [SHLWAPI.@]
1944 * See PathIsContentTypeA.
1946 BOOL WINAPI PathIsContentTypeW(LPCWSTR lpszPath, LPCWSTR lpszContentType)
1948 static const WCHAR szContentType[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
1951 WCHAR szBuff[MAX_PATH];
1953 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszContentType));
1955 if (lpszPath && (szExt = PathFindExtensionW(lpszPath)) && *szExt &&
1956 !SHGetValueW(HKEY_CLASSES_ROOT, szExt, szContentType,
1957 REG_NONE, szBuff, &dwDummy) &&
1958 !strcmpiW(lpszContentType, szBuff))
1965 /*************************************************************************
1966 * PathIsFileSpecA [SHLWAPI.@]
1968 * Determine if a path is a file specification.
1971 * lpszPath [I] Path to chack
1974 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
1977 BOOL WINAPI PathIsFileSpecA(LPCSTR lpszPath)
1979 TRACE("(%s)\n", debugstr_a(lpszPath));
1986 if (*lpszPath == '\\' || *lpszPath == ':')
1988 lpszPath = CharNextA(lpszPath);
1993 /*************************************************************************
1994 * PathIsFileSpecW [SHLWAPI.@]
1996 * See PathIsFileSpecA.
1998 BOOL WINAPI PathIsFileSpecW(LPCWSTR lpszPath)
2000 TRACE("(%s)\n", debugstr_w(lpszPath));
2007 if (*lpszPath == '\\' || *lpszPath == ':')
2009 lpszPath = CharNextW(lpszPath);
2014 /*************************************************************************
2015 * PathIsPrefixA [SHLWAPI.@]
2017 * Determine if a path is a prefix of another.
2020 * lpszPrefix [I] Prefix
2021 * lpszPath [I] Path to check
2024 * TRUE If lpszPath has lpszPrefix as its prefix,
2025 * FALSE If either path is NULL or lpszPrefix is not a prefix
2027 BOOL WINAPI PathIsPrefixA (LPCSTR lpszPrefix, LPCSTR lpszPath)
2029 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix), debugstr_a(lpszPath));
2031 if (lpszPrefix && lpszPath &&
2032 PathCommonPrefixA(lpszPath, lpszPrefix, NULL) == (int)strlen(lpszPrefix))
2037 /*************************************************************************
2038 * PathIsPrefixW [SHLWAPI.@]
2040 * See PathIsPrefixA.
2042 BOOL WINAPI PathIsPrefixW(LPCWSTR lpszPrefix, LPCWSTR lpszPath)
2044 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix), debugstr_w(lpszPath));
2046 if (lpszPrefix && lpszPath &&
2047 PathCommonPrefixW(lpszPath, lpszPrefix, NULL) == (int)strlenW(lpszPrefix))
2052 /*************************************************************************
2053 * PathIsSystemFolderA [SHLWAPI.@]
2055 * Determine if a path or file attributes are a system folder.
2058 * lpszPath [I] Path to check.
2059 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2062 * TRUE If lpszPath or dwAttrib are a system folder.
2063 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2065 BOOL WINAPI PathIsSystemFolderA(LPCSTR lpszPath, DWORD dwAttrib)
2067 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath), dwAttrib);
2069 if (lpszPath && *lpszPath)
2070 dwAttrib = GetFileAttributesA(lpszPath);
2072 if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2073 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2078 /*************************************************************************
2079 * PathIsSystemFolderW [SHLWAPI.@]
2081 * See PathIsSystemFolderA.
2083 BOOL WINAPI PathIsSystemFolderW(LPCWSTR lpszPath, DWORD dwAttrib)
2085 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath), dwAttrib);
2087 if (lpszPath && *lpszPath)
2088 dwAttrib = GetFileAttributesW(lpszPath);
2090 if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) ||
2091 !(dwAttrib & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)))
2096 /*************************************************************************
2097 * PathIsUNCA [SHLWAPI.@]
2099 * Determine if a path is in UNC format.
2102 * lpszPath [I] Path to check
2105 * TRUE: The path is UNC.
2106 * FALSE: The path is not UNC or is NULL.
2108 BOOL WINAPI PathIsUNCA(LPCSTR lpszPath)
2110 TRACE("(%s)\n",debugstr_a(lpszPath));
2112 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2117 /*************************************************************************
2118 * PathIsUNCW [SHLWAPI.@]
2122 BOOL WINAPI PathIsUNCW(LPCWSTR lpszPath)
2124 TRACE("(%s)\n",debugstr_w(lpszPath));
2126 if (lpszPath && (lpszPath[0]=='\\') && (lpszPath[1]=='\\'))
2131 /*************************************************************************
2132 * PathIsUNCServerA [SHLWAPI.@]
2134 * Determine if a path is a UNC server name ("\\SHARENAME").
2137 * lpszPath [I] Path to check.
2140 * TRUE If lpszPath is a valid UNC server name.
2144 * This routine is bug compatible with Win32: Server names with a
2145 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2146 * Fixing this bug may break other shlwapi functions!
2148 BOOL WINAPI PathIsUNCServerA(LPCSTR lpszPath)
2150 TRACE("(%s)\n", debugstr_a(lpszPath));
2152 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2156 if (*lpszPath == '\\')
2158 lpszPath = CharNextA(lpszPath);
2165 /*************************************************************************
2166 * PathIsUNCServerW [SHLWAPI.@]
2168 * See PathIsUNCServerA.
2170 BOOL WINAPI PathIsUNCServerW(LPCWSTR lpszPath)
2172 TRACE("(%s)\n", debugstr_w(lpszPath));
2174 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2178 if (*lpszPath == '\\')
2180 lpszPath = CharNextW(lpszPath);
2187 /*************************************************************************
2188 * PathIsUNCServerShareA [SHLWAPI.@]
2190 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2193 * lpszPath [I] Path to check.
2196 * TRUE If lpszPath is a valid UNC server share.
2200 * This routine is bug compatible with Win32: Server shares with a
2201 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2202 * Fixing this bug may break other shlwapi functions!
2204 BOOL WINAPI PathIsUNCServerShareA(LPCSTR lpszPath)
2206 TRACE("(%s)\n", debugstr_a(lpszPath));
2208 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2210 BOOL bSeenSlash = FALSE;
2213 if (*lpszPath == '\\')
2219 lpszPath = CharNextA(lpszPath);
2226 /*************************************************************************
2227 * PathIsUNCServerShareW [SHLWAPI.@]
2229 * See PathIsUNCServerShareA.
2231 BOOL WINAPI PathIsUNCServerShareW(LPCWSTR lpszPath)
2233 TRACE("(%s)\n", debugstr_w(lpszPath));
2235 if (lpszPath && *lpszPath++ == '\\' && *lpszPath++ == '\\')
2237 BOOL bSeenSlash = FALSE;
2240 if (*lpszPath == '\\')
2246 lpszPath = CharNextW(lpszPath);
2253 /*************************************************************************
2254 * PathCanonicalizeA [SHLWAPI.@]
2256 * Convert a path to its canonical form.
2259 * lpszBuf [O] Output path
2260 * lpszPath [I] Path to cnonicalize
2263 * Success: TRUE. lpszBuf contains the output path,
2264 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2266 BOOL WINAPI PathCanonicalizeA(LPSTR lpszBuf, LPCSTR lpszPath)
2270 TRACE("(%p,%s)\n", lpszBuf, debugstr_a(lpszPath));
2275 if (!lpszBuf || !lpszPath)
2276 SetLastError(ERROR_INVALID_PARAMETER);
2279 WCHAR szPath[MAX_PATH];
2280 WCHAR szBuff[MAX_PATH];
2281 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2282 bRet = PathCanonicalizeW(szBuff, szPath);
2283 WideCharToMultiByte(0,0,szBuff,-1,lpszBuf,MAX_PATH,0,0);
2289 /*************************************************************************
2290 * PathCanonicalizeW [SHLWAPI.@]
2292 * See PathCanonicalizeA.
2294 BOOL WINAPI PathCanonicalizeW(LPWSTR lpszBuf, LPCWSTR lpszPath)
2296 LPWSTR lpszDst = lpszBuf;
2297 LPCWSTR lpszSrc = lpszPath;
2299 TRACE("(%p,%s)\n", lpszBuf, debugstr_w(lpszPath));
2304 if (!lpszBuf || !lpszPath)
2306 SetLastError(ERROR_INVALID_PARAMETER);
2317 /* Copy path root */
2318 if (*lpszSrc == '\\')
2320 *lpszDst++ = *lpszSrc++;
2322 else if (*lpszSrc && lpszSrc[1] == ':')
2325 *lpszDst++ = *lpszSrc++;
2326 *lpszDst++ = *lpszSrc++;
2327 if (*lpszSrc == '\\')
2328 *lpszDst++ = *lpszSrc++;
2331 /* Canonicalize the rest of the path */
2334 if (*lpszSrc == '.')
2336 if (lpszSrc[1] == '\\' && (lpszSrc == lpszPath || lpszSrc[-1] == '\\' || lpszSrc[-1] == ':'))
2338 lpszSrc += 2; /* Skip .\ */
2340 else if (lpszSrc[1] == '.' && (lpszDst == lpszBuf || lpszDst[-1] == '\\'))
2342 /* \.. backs up a directory, over the root if it has no \ following X:.
2343 * .. is ignored if it would remove a UNC server name or inital \\
2345 if (lpszDst != lpszBuf)
2347 *lpszDst = '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2348 if (lpszDst > lpszBuf+1 && lpszDst[-1] == '\\' &&
2349 (lpszDst[-2] != '\\' || lpszDst > lpszBuf+2))
2351 if (lpszDst[-2] == ':' && (lpszDst > lpszBuf+3 || lpszDst[-3] == ':'))
2354 while (lpszDst > lpszBuf && *lpszDst != '\\')
2356 if (*lpszDst == '\\')
2357 lpszDst++; /* Reset to last '\' */
2359 lpszDst = lpszBuf; /* Start path again from new root */
2361 else if (lpszDst[-2] != ':' && !PathIsUNCServerShareW(lpszBuf))
2364 while (lpszDst > lpszBuf && *lpszDst != '\\')
2366 if (lpszDst == lpszBuf)
2372 lpszSrc += 2; /* Skip .. in src path */
2375 *lpszDst++ = *lpszSrc++;
2378 *lpszDst++ = *lpszSrc++;
2380 /* Append \ to naked drive specs */
2381 if (lpszDst - lpszBuf == 2 && lpszDst[-1] == ':')
2387 /*************************************************************************
2388 * PathFindNextComponentA [SHLWAPI.@]
2390 * Find the next component in a path.
2393 * lpszPath [I] Path to find next component in
2396 * Success: A pointer to the next component, or the end of the string.
2397 * Failure: NULL, If lpszPath is invalid
2400 * A 'component' is either a backslash character (\) or UNC marker (\\).
2401 * Because of this, relative paths (e.g "c:foo") are regarded as having
2402 * only one component.
2404 LPSTR WINAPI PathFindNextComponentA(LPCSTR lpszPath)
2408 TRACE("(%s)\n", debugstr_a(lpszPath));
2410 if(!lpszPath || !*lpszPath)
2413 if ((lpszSlash = StrChrA(lpszPath, '\\')))
2415 if (lpszSlash[1] == '\\')
2417 return lpszSlash + 1;
2419 return (LPSTR)lpszPath + strlen(lpszPath);
2422 /*************************************************************************
2423 * PathFindNextComponentW [SHLWAPI.@]
2425 * See PathFindNextComponentA.
2427 LPWSTR WINAPI PathFindNextComponentW(LPCWSTR lpszPath)
2431 TRACE("(%s)\n", debugstr_w(lpszPath));
2433 if(!lpszPath || !*lpszPath)
2436 if ((lpszSlash = StrChrW(lpszPath, '\\')))
2438 if (lpszSlash[1] == '\\')
2440 return lpszSlash + 1;
2442 return (LPWSTR)lpszPath + strlenW(lpszPath);
2445 /*************************************************************************
2446 * PathAddExtensionA [SHLWAPI.@]
2448 * Add a file extension to a path
2451 * lpszPath [I/O] Path to add extension to
2452 * lpszExtension [I] Extension to add to lpszPath
2455 * TRUE If the path was modified,
2456 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2457 * extension allready, or the new path length is too big.
2460 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2461 * does not do this, so the behaviour was removed.
2463 BOOL WINAPI PathAddExtensionA(LPSTR lpszPath, LPCSTR lpszExtension)
2467 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExtension));
2469 if (!lpszPath || !lpszExtension || *(PathFindExtensionA(lpszPath)))
2472 dwLen = strlen(lpszPath);
2474 if (dwLen + strlen(lpszExtension) >= MAX_PATH)
2477 strcpy(lpszPath + dwLen, lpszExtension);
2481 /*************************************************************************
2482 * PathAddExtensionW [SHLWAPI.@]
2484 * See PathAddExtensionA.
2486 BOOL WINAPI PathAddExtensionW(LPWSTR lpszPath, LPCWSTR lpszExtension)
2490 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExtension));
2492 if (!lpszPath || !lpszExtension || *(PathFindExtensionW(lpszPath)))
2495 dwLen = strlenW(lpszPath);
2497 if (dwLen + strlenW(lpszExtension) >= MAX_PATH)
2500 strcpyW(lpszPath + dwLen, lpszExtension);
2504 /*************************************************************************
2505 * PathMakePrettyA [SHLWAPI.@]
2507 * Convert an uppercase DOS filename into lowercase.
2510 * lpszPath [I/O] Path to convert.
2513 * TRUE If the path was an uppercase DOS path and was converted,
2516 BOOL WINAPI PathMakePrettyA(LPSTR lpszPath)
2518 LPSTR pszIter = lpszPath;
2520 TRACE("(%s)\n", debugstr_a(lpszPath));
2522 if (!pszIter || !*pszIter)
2527 if (islower(*pszIter) || IsDBCSLeadByte(*pszIter))
2528 return FALSE; /* Not DOS path */
2531 pszIter = lpszPath + 1;
2534 *pszIter = tolower(*pszIter);
2540 /*************************************************************************
2541 * PathMakePrettyW [SHLWAPI.@]
2543 * See PathMakePrettyA.
2545 BOOL WINAPI PathMakePrettyW(LPWSTR lpszPath)
2547 LPWSTR pszIter = lpszPath;
2549 TRACE("(%s)\n", debugstr_w(lpszPath));
2551 if (!pszIter || !*pszIter)
2556 if (islowerW(*pszIter))
2557 return FALSE; /* Not DOS path */
2560 pszIter = lpszPath + 1;
2563 *pszIter = tolowerW(*pszIter);
2569 /*************************************************************************
2570 * PathCommonPrefixA [SHLWAPI.@]
2572 * Determine the length of the common prefix between two paths.
2575 * lpszFile1 [I] First path for comparison
2576 * lpszFile2 [I] Second path for comparison
2577 * achPath [O] Destination for common prefix string
2580 * The length of the common prefix. This is 0 if there is no common
2581 * prefix between the paths or if any parameters are invalid. If the prefix
2582 * is non-zero and achPath is not NULL, achPath is filled with the common
2583 * part of the prefix and NUL terminated.
2586 * A common prefix of 2 is always returned as 3. It is thus possible for
2587 * the length returned to be invalid (i.e. Longer than one or both of the
2588 * strings given as parameters). This Win32 behaviour has been implemented
2589 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2590 * To work around this when using this function, always check that the byte
2591 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2593 int WINAPI PathCommonPrefixA(LPCSTR lpszFile1, LPCSTR lpszFile2, LPSTR achPath)
2596 LPCSTR lpszIter1 = lpszFile1;
2597 LPCSTR lpszIter2 = lpszFile2;
2599 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1), debugstr_a(lpszFile2), achPath);
2604 if (!lpszFile1 || !lpszFile2)
2607 /* Handle roots first */
2608 if (PathIsUNCA(lpszFile1))
2610 if (!PathIsUNCA(lpszFile2))
2615 else if (PathIsUNCA(lpszFile2))
2616 return 0; /* Know already lpszFile1 is not UNC */
2621 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2622 (!*lpszIter2 || *lpszIter2 == '\\'))
2623 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2625 if (!*lpszIter1 || (tolower(*lpszIter1) != tolower(*lpszIter2)))
2626 break; /* Strings differ at this point */
2633 iLen++; /* Feature/Bug compatible with Win32 */
2635 if (iLen && achPath)
2637 memcpy(achPath,lpszFile1,iLen);
2638 achPath[iLen] = '\0';
2643 /*************************************************************************
2644 * PathCommonPrefixW [SHLWAPI.@]
2646 * See PathCommonPrefixA.
2648 int WINAPI PathCommonPrefixW(LPCWSTR lpszFile1, LPCWSTR lpszFile2, LPWSTR achPath)
2651 LPCWSTR lpszIter1 = lpszFile1;
2652 LPCWSTR lpszIter2 = lpszFile2;
2654 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1), debugstr_w(lpszFile2), achPath);
2659 if (!lpszFile1 || !lpszFile2)
2662 /* Handle roots first */
2663 if (PathIsUNCW(lpszFile1))
2665 if (!PathIsUNCW(lpszFile2))
2670 else if (PathIsUNCW(lpszFile2))
2671 return 0; /* Know already lpszFile1 is not UNC */
2676 if ((!*lpszIter1 || *lpszIter1 == '\\') &&
2677 (!*lpszIter2 || *lpszIter2 == '\\'))
2678 iLen = lpszIter1 - lpszFile1; /* Common to this point */
2680 if (!*lpszIter1 || (tolowerW(*lpszIter1) != tolowerW(*lpszIter2)))
2681 break; /* Strings differ at this point */
2688 iLen++; /* Feature/Bug compatible with Win32 */
2690 if (iLen && achPath)
2692 memcpy(achPath,lpszFile1,iLen * sizeof(WCHAR));
2693 achPath[iLen] = '\0';
2698 /*************************************************************************
2699 * PathCompactPathA [SHLWAPI.@]
2701 * Make a path fit into a given width when printed to a DC.
2704 * hDc [I] Destination DC
2705 * lpszPath [I/O] Path to be printed to hDc
2706 * dx [I] Desired width
2709 * TRUE If the path was modified.
2712 BOOL WINAPI PathCompactPathA(HDC hDC, LPSTR lpszPath, UINT dx)
2716 TRACE("(%p,%s,%d)\n", hDC, debugstr_a(lpszPath), dx);
2720 WCHAR szPath[MAX_PATH];
2721 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2722 bRet = PathCompactPathW(hDC, szPath, dx);
2723 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
2728 /*************************************************************************
2729 * PathCompactPathW [SHLWAPI.@]
2731 * See PathCompactPathA.
2733 BOOL WINAPI PathCompactPathW(HDC hDC, LPWSTR lpszPath, UINT dx)
2735 static const WCHAR szEllipses[] = { '.', '.', '.', '\0' };
2738 WCHAR buff[MAX_PATH];
2742 TRACE("(%p,%s,%d)\n", hDC, debugstr_w(lpszPath), dx);
2748 hdc = hDC = GetDC(0);
2750 /* Get the length of the whole path */
2751 dwLen = strlenW(lpszPath);
2752 GetTextExtentPointW(hDC, lpszPath, dwLen, &size);
2754 if ((UINT)size.cx > dx)
2756 /* Path too big, must reduce it */
2758 DWORD dwEllipsesLen = 0, dwPathLen = 0;
2760 sFile = PathFindFileNameW(lpszPath);
2761 if (sFile != lpszPath)
2762 sFile = CharPrevW(lpszPath, sFile);
2764 /* Get the size of ellipses */
2765 GetTextExtentPointW(hDC, szEllipses, 3, &size);
2766 dwEllipsesLen = size.cx;
2767 /* Get the size of the file name */
2768 GetTextExtentPointW(hDC, sFile, strlenW(sFile), &size);
2769 dwPathLen = size.cx;
2771 if (sFile != lpszPath)
2773 LPWSTR sPath = sFile;
2774 BOOL bEllipses = FALSE;
2776 /* The path includes a file name. Include as much of the path prior to
2777 * the file name as possible, allowing for the ellipses, e.g:
2778 * c:\some very long path\filename ==> c:\some v...\filename
2780 strncpyW(buff, sFile, MAX_PATH);
2784 DWORD dwTotalLen = bEllipses? dwPathLen + dwEllipsesLen : dwPathLen;
2786 GetTextExtentPointW(hDC, lpszPath, sPath - lpszPath, &size);
2787 dwTotalLen += size.cx;
2788 if (dwTotalLen <= dx)
2790 sPath = CharPrevW(lpszPath, sPath);
2794 sPath = CharPrevW(lpszPath, sPath);
2795 sPath = CharPrevW(lpszPath, sPath);
2797 } while (sPath > lpszPath);
2799 if (sPath > lpszPath)
2803 strcpyW(sPath, szEllipses);
2804 strcpyW(sPath+3, buff);
2809 strcpyW(lpszPath, szEllipses);
2810 strcpyW(lpszPath+3, buff);
2815 /* Trim the path by adding ellipses to the end, e.g:
2816 * A very long file name.txt ==> A very...
2818 dwLen = strlenW(lpszPath);
2820 if (dwLen > MAX_PATH - 3)
2821 dwLen = MAX_PATH - 3;
2822 strncpyW(buff, sFile, dwLen);
2826 GetTextExtentPointW(hDC, buff, dwLen, &size);
2827 } while (dwLen && size.cx + dwEllipsesLen > dx);
2831 DWORD dwWritten = 0;
2833 dwEllipsesLen /= 3; /* Size of a single '.' */
2835 /* Write as much of the Ellipses string as possible */
2836 while (dwWritten + dwEllipsesLen < dx && dwLen < 3)
2839 dwWritten += dwEllipsesLen;
2847 strcpyW(buff + dwLen, szEllipses);
2848 strcpyW(lpszPath, buff);
2859 /*************************************************************************
2860 * PathGetCharTypeA [SHLWAPI.@]
2862 * Categorise a character from a file path.
2865 * ch [I] Character to get the type of
2868 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2870 UINT WINAPI PathGetCharTypeA(UCHAR ch)
2872 return PathGetCharTypeW(ch);
2875 /*************************************************************************
2876 * PathGetCharTypeW [SHLWAPI.@]
2878 * See PathGetCharTypeA.
2880 UINT WINAPI PathGetCharTypeW(WCHAR ch)
2884 TRACE("(%d)\n", ch);
2886 if (!ch || ch < ' ' || ch == '<' || ch == '>' ||
2887 ch == '"' || ch == '|' || ch == '/')
2888 flags = GCT_INVALID; /* Invalid */
2889 else if (ch == '*' || ch=='?')
2890 flags = GCT_WILD; /* Wildchars */
2891 else if ((ch == '\\') || (ch == ':'))
2892 return GCT_SEPARATOR; /* Path separators */
2897 if ((ch & 0x1 && ch != ';') || !ch || isalnum(ch) || ch == '$' || ch == '&' || ch == '(' ||
2898 ch == '.' || ch == '@' || ch == '^' ||
2899 ch == '\'' || ch == 130 || ch == '`')
2900 flags |= GCT_SHORTCHAR; /* All these are valid for DOS */
2903 flags |= GCT_SHORTCHAR; /* Bug compatible with win32 */
2904 flags |= GCT_LFNCHAR; /* Valid for long file names */
2909 /*************************************************************************
2910 * SHLWAPI_UseSystemForSystemFolders
2912 * Internal helper for PathMakeSystemFolderW.
2914 static BOOL WINAPI SHLWAPI_UseSystemForSystemFolders()
2916 static BOOL bCheckedReg = FALSE;
2917 static BOOL bUseSystemForSystemFolders = FALSE;
2923 /* Key tells Win what file attributes to use on system folders */
2924 if (SHGetValueA(HKEY_LOCAL_MACHINE,
2925 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2926 "UseSystemForSystemFolders", 0, 0, 0))
2927 bUseSystemForSystemFolders = TRUE;
2929 return bUseSystemForSystemFolders;
2932 /*************************************************************************
2933 * PathMakeSystemFolderA [SHLWAPI.@]
2935 * Set system folder attribute for a path.
2938 * lpszPath [I] The path to turn into a system folder
2941 * TRUE If the path was changed to/already was a system folder
2942 * FALSE If the path is invalid or SetFileAttributesA() fails
2944 BOOL WINAPI PathMakeSystemFolderA(LPCSTR lpszPath)
2948 TRACE("(%s)\n", debugstr_a(lpszPath));
2950 if (lpszPath && *lpszPath)
2952 WCHAR szPath[MAX_PATH];
2953 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
2954 bRet = PathMakeSystemFolderW(szPath);
2959 /*************************************************************************
2960 * PathMakeSystemFolderW [SHLWAPI.@]
2962 * See PathMakeSystemFolderA.
2964 BOOL WINAPI PathMakeSystemFolderW(LPCWSTR lpszPath)
2966 DWORD dwDefaultAttr = FILE_ATTRIBUTE_READONLY, dwAttr;
2967 WCHAR buff[MAX_PATH];
2969 TRACE("(%s)\n", debugstr_w(lpszPath));
2971 if (!lpszPath || !*lpszPath)
2974 /* If the directory is already a system directory, dont do anything */
2975 GetSystemDirectoryW(buff, MAX_PATH);
2976 if (!strcmpW(buff, lpszPath))
2979 GetWindowsDirectoryW(buff, MAX_PATH);
2980 if (!strcmpW(buff, lpszPath))
2983 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
2984 if (SHLWAPI_UseSystemForSystemFolders())
2985 dwDefaultAttr = FILE_ATTRIBUTE_SYSTEM;
2987 if ((dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES)
2990 /* Change file attributes to system attributes */
2991 dwAttr &= ~(FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_READONLY);
2992 return SetFileAttributesW(lpszPath, dwAttr | dwDefaultAttr);
2995 /*************************************************************************
2996 * PathRenameExtensionA [SHLWAPI.@]
2998 * Swap the file extension in a path with another extension.
3001 * lpszPath [I/O] Path to swap the extension in
3002 * lpszExt [I] The new extension
3005 * TRUE if lpszPath was modified,
3006 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3008 BOOL WINAPI PathRenameExtensionA(LPSTR lpszPath, LPCSTR lpszExt)
3010 LPSTR lpszExtension;
3012 TRACE("(%s,%s)\n", debugstr_a(lpszPath), debugstr_a(lpszExt));
3014 lpszExtension = PathFindExtensionA(lpszPath);
3016 if (!lpszExtension || (lpszExtension - lpszPath + strlen(lpszExt) >= MAX_PATH))
3019 strcpy(lpszExtension, lpszExt);
3023 /*************************************************************************
3024 * PathRenameExtensionW [SHLWAPI.@]
3026 * See PathRenameExtensionA.
3028 BOOL WINAPI PathRenameExtensionW(LPWSTR lpszPath, LPCWSTR lpszExt)
3030 LPWSTR lpszExtension;
3032 TRACE("(%s,%s)\n", debugstr_w(lpszPath), debugstr_w(lpszExt));
3034 lpszExtension = PathFindExtensionW(lpszPath);
3036 if (!lpszExtension || (lpszExtension - lpszPath + strlenW(lpszExt) >= MAX_PATH))
3039 strcpyW(lpszExtension, lpszExt);
3043 /*************************************************************************
3044 * PathSearchAndQualifyA [SHLWAPI.@]
3046 * Determine if a given path is correct and fully qualified.
3049 * lpszPath [I] Path to check
3050 * lpszBuf [O] Output for correct path
3051 * cchBuf [I] Size of lpszBuf
3056 BOOL WINAPI PathSearchAndQualifyA(LPCSTR lpszPath, LPSTR lpszBuf, UINT cchBuf)
3058 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath), lpszBuf, cchBuf);
3062 /*************************************************************************
3063 * PathSearchAndQualifyW [SHLWAPI.@]
3065 * See PathSearchAndQualifyA.
3067 BOOL WINAPI PathSearchAndQualifyW(LPCWSTR lpszPath, LPWSTR lpszBuf, UINT cchBuf)
3069 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath), lpszBuf, cchBuf);
3073 /*************************************************************************
3074 * PathSkipRootA [SHLWAPI.@]
3076 * Return the portion of a path following the drive letter or mount point.
3079 * lpszPath [I] The path to skip on
3082 * Success: A pointer to the next character after the root.
3083 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3085 LPSTR WINAPI PathSkipRootA(LPCSTR lpszPath)
3087 TRACE("(%s)\n", debugstr_a(lpszPath));
3089 if (!lpszPath || !*lpszPath)
3092 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3094 /* Network share: skip share server and mount point */
3096 if ((lpszPath = StrChrA(lpszPath, '\\')) &&
3097 (lpszPath = StrChrA(lpszPath + 1, '\\')))
3099 return (LPSTR)lpszPath;
3102 if (IsDBCSLeadByte(*lpszPath))
3106 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3107 return (LPSTR)lpszPath + 3;
3111 /*************************************************************************
3112 * PathSkipRootW [SHLWAPI.@]
3114 * See PathSkipRootA.
3116 LPWSTR WINAPI PathSkipRootW(LPCWSTR lpszPath)
3118 TRACE("(%s)\n", debugstr_w(lpszPath));
3120 if (!lpszPath || !*lpszPath)
3123 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3125 /* Network share: skip share server and mount point */
3127 if ((lpszPath = StrChrW(lpszPath, '\\')) &&
3128 (lpszPath = StrChrW(lpszPath + 1, '\\')))
3130 return (LPWSTR)lpszPath;
3134 if (lpszPath[0] && lpszPath[1] == ':' && lpszPath[2] == '\\')
3135 return (LPWSTR)lpszPath + 3;
3139 /*************************************************************************
3140 * PathCreateFromUrlA [SHLWAPI.@]
3142 * Create a path from a URL
3145 * lpszUrl [I] URL to convert into a path
3146 * lpszPath [O] Output buffer for the resulting Path
3147 * pcchPath [I] Length of lpszPath
3148 * dwFlags [I] Flags controlling the conversion
3151 * Success: S_OK. lpszPath contains the URL in path format,
3152 * Failure: An HRESULT error code such as E_INVALIDARG.
3154 HRESULT WINAPI PathCreateFromUrlA(LPCSTR lpszUrl, LPSTR lpszPath,
3155 LPDWORD pcchPath, DWORD dwFlags)
3158 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_a(lpszUrl), lpszPath, pcchPath, dwFlags);
3160 if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
3161 return E_INVALIDARG;
3163 pszPathPart = StrChrA(lpszUrl, ':');
3164 if ((((pszPathPart - lpszUrl) == 1) && isalpha(*lpszUrl)) ||
3165 !lstrcmpA(lpszUrl, "file:"))
3167 return UrlUnescapeA(pszPathPart, lpszPath, pcchPath, dwFlags);
3169 /* extracts thing prior to : in pszURL and checks against:
3173 * about - if match returns E_INVALIDARG
3176 return E_INVALIDARG;
3179 /*************************************************************************
3180 * PathCreateFromUrlW [SHLWAPI.@]
3182 * See PathCreateFromUrlA.
3184 HRESULT WINAPI PathCreateFromUrlW(LPCWSTR lpszUrl, LPWSTR lpszPath,
3185 LPDWORD pcchPath, DWORD dwFlags)
3187 static const WCHAR stemp[] = { 'f','i','l','e',':','/','/',0 };
3188 LPWSTR pwszPathPart;
3191 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_w(lpszUrl), lpszPath, pcchPath, dwFlags);
3193 if (!lpszUrl || !lpszPath || !pcchPath || !*pcchPath)
3194 return E_INVALIDARG;
3196 /* Path of the form file://... */
3197 if (!strncmpW(lpszUrl, stemp, 7))
3201 /* Path of the form file:... */
3202 else if (!strncmpW(lpszUrl, stemp, 5))
3207 /* Ensure that path is of the form c:... or c|... */
3208 if (lpszUrl[1] != ':' && lpszUrl[1] != '|' && isalphaW(*lpszUrl))
3209 return E_INVALIDARG;
3211 hr = UrlUnescapeW(lpszUrl, lpszPath, pcchPath, dwFlags);
3212 if (lpszPath[1] == '|')
3215 for (pwszPathPart = lpszPath; *pwszPathPart; pwszPathPart++)
3216 if (*pwszPathPart == '/')
3217 *pwszPathPart = '\\';
3219 TRACE("Returning %s\n",debugstr_w(lpszPath));
3224 /*************************************************************************
3225 * PathRelativePathToA [SHLWAPI.@]
3227 * Create a relative path from one path to another.
3230 * lpszPath [O] Destination for relative path
3231 * lpszFrom [I] Source path
3232 * dwAttrFrom [I] File attribute of source path
3233 * lpszTo [I] Destination path
3234 * dwAttrTo [I] File attributes of destination path
3237 * TRUE If a relative path can be formed. lpszPath contains the new path
3238 * FALSE If the paths are not relavtive or any parameters are invalid
3241 * lpszTo should be at least MAX_PATH in length.
3243 * Calling this function with relative paths for lpszFrom or lpszTo may
3244 * give erroneous results.
3246 * The Win32 version of this function contains a bug where the lpszTo string
3247 * may be referenced 1 byte beyond the end of the string. As a result random
3248 * garbage may be written to the output path, depending on what lies beyond
3249 * the last byte of the string. This bug occurs because of the behaviour of
3250 * PathCommonPrefix() (see notes for that function), and no workaround seems
3251 * possible with Win32.
3253 * This bug has been fixed here, so for example the relative path from "\\"
3254 * to "\\" is correctly determined as "." in this implementation.
3256 BOOL WINAPI PathRelativePathToA(LPSTR lpszPath, LPCSTR lpszFrom, DWORD dwAttrFrom,
3257 LPCSTR lpszTo, DWORD dwAttrTo)
3261 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_a(lpszFrom),
3262 dwAttrFrom, debugstr_a(lpszTo), dwAttrTo);
3264 if(lpszPath && lpszFrom && lpszTo)
3266 WCHAR szPath[MAX_PATH];
3267 WCHAR szFrom[MAX_PATH];
3268 WCHAR szTo[MAX_PATH];
3269 MultiByteToWideChar(0,0,lpszFrom,-1,szFrom,MAX_PATH);
3270 MultiByteToWideChar(0,0,lpszTo,-1,szTo,MAX_PATH);
3271 bRet = PathRelativePathToW(szPath,szFrom,dwAttrFrom,szTo,dwAttrTo);
3272 WideCharToMultiByte(0,0,szPath,-1,lpszPath,MAX_PATH,0,0);
3277 /*************************************************************************
3278 * PathRelativePathToW [SHLWAPI.@]
3280 * See PathRelativePathToA.
3282 BOOL WINAPI PathRelativePathToW(LPWSTR lpszPath, LPCWSTR lpszFrom, DWORD dwAttrFrom,
3283 LPCWSTR lpszTo, DWORD dwAttrTo)
3285 static const WCHAR szPrevDirSlash[] = { '.', '.', '\\', '\0' };
3286 static const WCHAR szPrevDir[] = { '.', '.', '\0' };
3287 WCHAR szFrom[MAX_PATH];
3288 WCHAR szTo[MAX_PATH];
3291 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath, debugstr_w(lpszFrom),
3292 dwAttrFrom, debugstr_w(lpszTo), dwAttrTo);
3294 if(!lpszPath || !lpszFrom || !lpszTo)
3298 strncpyW(szFrom, lpszFrom, MAX_PATH);
3299 strncpyW(szTo, lpszTo, MAX_PATH);
3301 if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
3302 PathRemoveFileSpecW(szFrom);
3303 if(!(dwAttrFrom & FILE_ATTRIBUTE_DIRECTORY))
3304 PathRemoveFileSpecW(szTo);
3306 /* Paths can only be relative if they have a common root */
3307 if(!(dwLen = PathCommonPrefixW(szFrom, szTo, 0)))
3310 /* Strip off lpszFrom components to the root, by adding "..\" */
3311 lpszFrom = szFrom + dwLen;
3317 if (*lpszFrom == '\\')
3322 lpszFrom = PathFindNextComponentW(lpszFrom);
3323 strcatW(lpszPath, *lpszFrom ? szPrevDirSlash : szPrevDir);
3326 /* From the root add the components of lpszTo */
3328 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3331 if (*lpszTo && lpszTo[-1])
3333 if (*lpszTo != '\\')
3335 dwLen = strlenW(lpszPath);
3336 if (dwLen + strlenW(lpszTo) >= MAX_PATH)
3341 strcpyW(lpszPath + dwLen, lpszTo);
3346 /*************************************************************************
3347 * PathUnmakeSystemFolderA [SHLWAPI.@]
3349 * Remove the system folder attributes from a path.
3352 * lpszPath [I] The path to remove attributes from
3356 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3357 * SetFileAttributesA() fails.
3359 BOOL WINAPI PathUnmakeSystemFolderA(LPCSTR lpszPath)
3363 TRACE("(%s)\n", debugstr_a(lpszPath));
3365 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesA(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
3366 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3369 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3370 return SetFileAttributesA(lpszPath, dwAttr);
3373 /*************************************************************************
3374 * PathUnmakeSystemFolderW [SHLWAPI.@]
3376 * See PathUnmakeSystemFolderA.
3378 BOOL WINAPI PathUnmakeSystemFolderW(LPCWSTR lpszPath)
3382 TRACE("(%s)\n", debugstr_w(lpszPath));
3384 if (!lpszPath || !*lpszPath || (dwAttr = GetFileAttributesW(lpszPath)) == INVALID_FILE_ATTRIBUTES ||
3385 !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
3388 dwAttr &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
3389 return SetFileAttributesW(lpszPath, dwAttr);
3393 /*************************************************************************
3394 * PathSetDlgItemPathA [SHLWAPI.@]
3396 * Set the text of a dialog item to a path, shrinking the path to fit
3397 * if it is too big for the item.
3400 * hDlg [I] Dialog handle
3401 * id [I] ID of item in the dialog
3402 * lpszPath [I] Path to set as the items text
3408 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3409 * window text is erased).
3411 VOID WINAPI PathSetDlgItemPathA(HWND hDlg, int id, LPCSTR lpszPath)
3413 WCHAR szPath[MAX_PATH];
3415 TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_a(lpszPath));
3418 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
3421 PathSetDlgItemPathW(hDlg, id, szPath);
3424 /*************************************************************************
3425 * PathSetDlgItemPathW [SHLWAPI.@]
3427 * See PathSetDlgItemPathA.
3429 VOID WINAPI PathSetDlgItemPathW(HWND hDlg, int id, LPCWSTR lpszPath)
3431 WCHAR path[MAX_PATH + 1];
3437 TRACE("(%p,%8x,%s)\n",hDlg, id, debugstr_w(lpszPath));
3439 if (!(hwItem = GetDlgItem(hDlg, id)))
3443 strncpyW(path, lpszPath, sizeof(path));
3447 GetClientRect(hwItem, &rect);
3449 hPrevObj = SelectObject(hdc, (HGDIOBJ)SendMessageW(hwItem,WM_GETFONT,0,0));
3453 PathCompactPathW(hdc, path, rect.right);
3454 SelectObject(hdc, hPrevObj);
3457 ReleaseDC(hDlg, hdc);
3458 SetWindowTextW(hwItem, path);
3461 /*************************************************************************
3462 * PathIsNetworkPathA [SHLWAPI.@]
3464 * Determine if the given path is a network path.
3467 * lpszPath [I] Path to check
3470 * TRUE If lpszPath is a UNC share or mapped network drive, or
3471 * FALSE If lpszPath is a local drive or cannot be determined
3473 BOOL WINAPI PathIsNetworkPathA(LPCSTR lpszPath)
3477 TRACE("(%s)\n",debugstr_a(lpszPath));
3481 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3483 dwDriveNum = PathGetDriveNumberA(lpszPath);
3484 if (dwDriveNum == -1)
3486 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3487 return pIsNetDrive(dwDriveNum);
3490 /*************************************************************************
3491 * PathIsNetworkPathW [SHLWAPI.@]
3493 * See PathIsNetworkPathA.
3495 BOOL WINAPI PathIsNetworkPathW(LPCWSTR lpszPath)
3499 TRACE("(%s)\n", debugstr_w(lpszPath));
3503 if (*lpszPath == '\\' && lpszPath[1] == '\\')
3505 dwDriveNum = PathGetDriveNumberW(lpszPath);
3506 if (dwDriveNum == -1)
3508 GET_FUNC(pIsNetDrive, shell32, (LPCSTR)66, FALSE); /* ord 66 = shell32.IsNetDrive */
3509 return pIsNetDrive(dwDriveNum);
3512 /*************************************************************************
3513 * PathIsLFNFileSpecA [SHLWAPI.@]
3515 * Determine if the given path is a long file name
3518 * lpszPath [I] Path to check
3521 * TRUE If path is a long file name,
3522 * FALSE If path is a valid DOS short file name
3524 BOOL WINAPI PathIsLFNFileSpecA(LPCSTR lpszPath)
3526 DWORD dwNameLen = 0, dwExtLen = 0;
3528 TRACE("(%s)\n",debugstr_a(lpszPath));
3535 if (*lpszPath == ' ')
3536 return TRUE; /* DOS names cannot have spaces */
3537 if (*lpszPath == '.')
3540 return TRUE; /* DOS names have only one dot */
3547 return TRUE; /* DOS extensions are <= 3 chars*/
3553 return TRUE; /* DOS names are <= 8 chars */
3555 lpszPath += IsDBCSLeadByte(*lpszPath) ? 2 : 1;
3557 return FALSE; /* Valid DOS path */
3560 /*************************************************************************
3561 * PathIsLFNFileSpecW [SHLWAPI.@]
3563 * See PathIsLFNFileSpecA.
3565 BOOL WINAPI PathIsLFNFileSpecW(LPCWSTR lpszPath)
3567 DWORD dwNameLen = 0, dwExtLen = 0;
3569 TRACE("(%s)\n",debugstr_w(lpszPath));
3576 if (*lpszPath == ' ')
3577 return TRUE; /* DOS names cannot have spaces */
3578 if (*lpszPath == '.')
3581 return TRUE; /* DOS names have only one dot */
3588 return TRUE; /* DOS extensions are <= 3 chars*/
3594 return TRUE; /* DOS names are <= 8 chars */
3598 return FALSE; /* Valid DOS path */
3601 /*************************************************************************
3602 * PathIsDirectoryEmptyA [SHLWAPI.@]
3604 * Determine if a given directory is empty.
3607 * lpszPath [I] Directory to check
3610 * TRUE If the directory exists and contains no files,
3613 BOOL WINAPI PathIsDirectoryEmptyA(LPCSTR lpszPath)
3617 TRACE("(%s)\n",debugstr_a(lpszPath));
3621 WCHAR szPath[MAX_PATH];
3622 MultiByteToWideChar(0,0,lpszPath,-1,szPath,MAX_PATH);
3623 bRet = PathIsDirectoryEmptyW(szPath);
3628 /*************************************************************************
3629 * PathIsDirectoryEmptyW [SHLWAPI.@]
3631 * See PathIsDirectoryEmptyA.
3633 BOOL WINAPI PathIsDirectoryEmptyW(LPCWSTR lpszPath)
3635 static const WCHAR szAllFiles[] = { '*', '.', '*', '\0' };
3636 WCHAR szSearch[MAX_PATH];
3639 BOOL retVal = FALSE;
3640 WIN32_FIND_DATAW find_data;
3642 TRACE("(%s)\n",debugstr_w(lpszPath));
3644 if (!lpszPath || !PathIsDirectoryW(lpszPath))
3647 strncpyW(szSearch, lpszPath, MAX_PATH);
3648 PathAddBackslashW(szSearch);
3649 dwLen = strlenW(szSearch);
3650 if (dwLen > MAX_PATH - 4)
3653 strcpyW(szSearch + dwLen, szAllFiles);
3654 hfind = FindFirstFileW(szSearch, &find_data);
3656 if (hfind != INVALID_HANDLE_VALUE &&
3657 find_data.cFileName[0] == '.' &&
3658 find_data.cFileName[1] == '.')
3660 /* The only directory entry should be the parent */
3661 if (!FindNextFileW(hfind, &find_data))
3669 /*************************************************************************
3670 * PathFindSuffixArrayA [SHLWAPI.@]
3672 * Find a suffix string in an array of suffix strings
3675 * lpszSuffix [I] Suffix string to search for
3676 * lppszArray [I] Array of suffix strings to search
3677 * dwCount [I] Number of elements in lppszArray
3680 * Success: The index of the position of lpszSuffix in lppszArray
3681 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3684 * The search is case sensitive.
3685 * The match is made against the end of the suffix string, so for example:
3686 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3688 int WINAPI PathFindSuffixArrayA(LPCSTR lpszSuffix, LPCSTR *lppszArray, int dwCount)
3693 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix), lppszArray, dwCount);
3695 if (lpszSuffix && lppszArray && dwCount > 0)
3697 dwLen = strlen(lpszSuffix);
3699 while (dwRet < dwCount)
3701 size_t dwCompareLen = strlen(*lppszArray);
3702 if (dwCompareLen < dwLen)
3704 if (!strcmp(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3705 return dwRet; /* Found */
3714 /*************************************************************************
3715 * PathFindSuffixArrayW [SHLWAPI.@]
3717 * See PathFindSuffixArrayA.
3719 int WINAPI PathFindSuffixArrayW(LPCWSTR lpszSuffix, LPCWSTR *lppszArray, int dwCount)
3724 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix), lppszArray, dwCount);
3726 if (lpszSuffix && lppszArray && dwCount > 0)
3728 dwLen = strlenW(lpszSuffix);
3730 while (dwRet < dwCount)
3732 size_t dwCompareLen = strlenW(*lppszArray);
3733 if (dwCompareLen < dwLen)
3735 if (!strcmpW(lpszSuffix + dwLen - dwCompareLen, *lppszArray))
3736 return dwRet; /* Found */
3745 /*************************************************************************
3746 * PathUndecorateA [SHLWAPI.@]
3748 * Undecorate a file path
3751 * lpszPath [I/O] Path to remove any decoration from
3757 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3759 VOID WINAPI PathUndecorateA(LPSTR lpszPath)
3761 TRACE("(%s)\n",debugstr_a(lpszPath));
3765 LPSTR lpszExt = PathFindExtensionA(lpszPath);
3766 if (lpszExt > lpszPath && lpszExt[-1] == ']')
3768 LPSTR lpszSkip = lpszExt - 2;
3769 if (*lpszSkip == '[')
3770 lpszSkip++; /* [] (no number) */
3772 while (lpszSkip > lpszPath && isdigit(lpszSkip[-1]))
3774 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
3776 /* remove the [n] */
3779 *lpszSkip++ = *lpszExt++;
3786 /*************************************************************************
3787 * PathUndecorateW [SHLWAPI.@]
3789 * See PathUndecorateA.
3791 VOID WINAPI PathUndecorateW(LPWSTR lpszPath)
3793 TRACE("(%s)\n",debugstr_w(lpszPath));
3797 LPWSTR lpszExt = PathFindExtensionW(lpszPath);
3798 if (lpszExt > lpszPath && lpszExt[-1] == ']')
3800 LPWSTR lpszSkip = lpszExt - 2;
3801 if (*lpszSkip == '[')
3802 lpszSkip++; /* [] (no number) */
3804 while (lpszSkip > lpszPath && isdigitW(lpszSkip[-1]))
3806 if (lpszSkip > lpszPath && lpszSkip[-1] == '[' && lpszSkip[-2] != '\\')
3808 /* remove the [n] */
3811 *lpszSkip++ = *lpszExt++;
3818 /*************************************************************************
3821 * Find localised or default web content in "%WINDOWS%\web\".
3824 * lpszFile [I] File name containing content to look for
3825 * lpszPath [O] Buffer to contain the full path to the file
3826 * dwPathLen [I] Length of lpszPath
3829 * Success: S_OK. lpszPath contains the full path to the content.
3830 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
3832 HRESULT WINAPI SHGetWebFolderFilePathA(LPCSTR lpszFile, LPSTR lpszPath, DWORD dwPathLen)
3834 WCHAR szFile[MAX_PATH], szPath[MAX_PATH];
3837 TRACE("(%s,%p,%ld)\n", lpszFile, lpszPath, dwPathLen);
3839 MultiByteToWideChar(0, 0, lpszFile, -1, szFile, MAX_PATH);
3841 hRet = SHGetWebFolderFilePathW(szFile, szPath, dwPathLen);
3842 WideCharToMultiByte(0, 0, szPath, -1, lpszPath, dwPathLen, 0, 0);
3846 /*************************************************************************
3849 * Unicode version of SHGetWebFolderFilePathA.
3851 HRESULT WINAPI SHGetWebFolderFilePathW(LPCWSTR lpszFile, LPWSTR lpszPath, DWORD dwPathLen)
3853 static const WCHAR szWeb[] = {'\\','W','e','b','\\','\0'};
3854 static const WCHAR szWebMui[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
3855 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
3856 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
3857 DWORD dwLen, dwFileLen;
3858 LANGID lidSystem, lidUser;
3860 TRACE("(%s,%p,%ld)\n", debugstr_w(lpszFile), lpszPath, dwPathLen);
3862 /* Get base directory for web content */
3863 dwLen = GetSystemWindowsDirectoryW(lpszPath, dwPathLen);
3864 if (dwLen > 0 && lpszPath[dwLen-1] == '\\')
3867 dwFileLen = strlenW(lpszFile);
3869 if (dwLen + dwFileLen + szWebLen >= dwPathLen)
3870 return E_FAIL; /* lpszPath too short */
3872 strcpyW(lpszPath+dwLen, szWeb);
3874 dwPathLen = dwPathLen - dwLen; /* Remaining space */
3876 lidSystem = GetSystemDefaultUILanguage();
3877 lidUser = GetUserDefaultUILanguage();
3879 if (lidSystem != lidUser)
3881 if (dwFileLen + szWebMuiLen < dwPathLen)
3883 /* Use localised content in the users UI language if present */
3884 wsprintfW(lpszPath + dwLen, szWebMui, lidUser);
3885 strcpyW(lpszPath + dwLen + szWebMuiLen, lpszFile);
3886 if (PathFileExistsW(lpszPath))
3891 /* Fall back to OS default installed content */
3892 strcpyW(lpszPath + dwLen, lpszFile);
3893 if (PathFileExistsW(lpszPath))