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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
29 #include "wine/unicode.h"
36 #define NO_SHLWAPI_STREAM
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 /* Get a function pointer from a DLL handle */
43 #define GET_FUNC(func, module, name, fail) \
46 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
47 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
48 if (!func) return fail; \
52 /* DLL handles for late bound calls */
53 static HMODULE SHLWAPI_hshell32
;
55 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
56 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
57 static fnpIsNetDrive pIsNetDrive
;
59 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
61 static inline WCHAR
* heap_strdupAtoW(LPCSTR str
)
67 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
68 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
70 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
76 /*************************************************************************
77 * PathAppendA [SHLWAPI.@]
79 * Append one path to another.
82 * lpszPath [I/O] Initial part of path, and destination for output
83 * lpszAppend [I] Path to append
86 * Success: TRUE. lpszPath contains the newly created path.
87 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
90 * lpszAppend must contain at least one backslash ('\') if not NULL.
91 * Because PathCombineA() is used to join the paths, the resulting
92 * path is also canonicalized.
94 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
96 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
98 if (lpszPath
&& lpszAppend
)
100 if (!PathIsUNCA(lpszAppend
))
101 while (*lpszAppend
== '\\')
103 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
109 /*************************************************************************
110 * PathAppendW [SHLWAPI.@]
114 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
116 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
118 if (lpszPath
&& lpszAppend
)
120 if (!PathIsUNCW(lpszAppend
))
121 while (*lpszAppend
== '\\')
123 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
129 /*************************************************************************
130 * PathCombineA [SHLWAPI.@]
132 * Combine two paths together.
135 * lpszDest [O] Destination for combined path
136 * lpszDir [I] Directory path
137 * lpszFile [I] File path
140 * Success: The output path
141 * Failure: NULL, if inputs are invalid.
144 * lpszDest should be at least MAX_PATH in size, and may point to the same
145 * memory location as lpszDir. The combined path is canonicalised.
147 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
149 WCHAR szDest
[MAX_PATH
];
150 WCHAR szDir
[MAX_PATH
];
151 WCHAR szFile
[MAX_PATH
];
152 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
154 /* Invalid parameters */
157 if (!lpszDir
&& !lpszFile
)
161 if (!MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
))
165 if (!MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
))
168 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
169 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
177 /*************************************************************************
178 * PathCombineW [SHLWAPI.@]
182 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
184 WCHAR szTemp
[MAX_PATH
];
185 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
187 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
189 /* Invalid parameters */
192 if (!lpszDir
&& !lpszFile
)
198 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
201 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
203 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
205 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
208 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
221 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
224 PathStripToRootW(szTemp
);
225 lpszFile
++; /* Skip '\' */
227 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
232 strcatW(szTemp
, lpszFile
);
235 PathCanonicalizeW(lpszDest
, szTemp
);
239 /*************************************************************************
240 * PathAddBackslashA [SHLWAPI.@]
242 * Append a backslash ('\') to a path if one doesn't exist.
245 * lpszPath [I/O] The path to append a backslash to.
248 * Success: The position of the last backslash in the path.
249 * Failure: NULL, if lpszPath is NULL or the path is too large.
251 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
254 LPSTR prev
= lpszPath
;
256 TRACE("(%s)\n",debugstr_a(lpszPath
));
258 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
264 lpszPath
= CharNextA(prev
);
277 /*************************************************************************
278 * PathAddBackslashW [SHLWAPI.@]
280 * See PathAddBackslashA.
282 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
286 TRACE("(%s)\n",debugstr_w(lpszPath
));
288 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
294 if (lpszPath
[-1] != '\\')
303 /*************************************************************************
304 * PathBuildRootA [SHLWAPI.@]
306 * Create a root drive string (e.g. "A:\") from a drive number.
309 * lpszPath [O] Destination for the drive string
315 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
317 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
319 TRACE("(%p,%d)\n", lpszPath
, drive
);
321 if (lpszPath
&& drive
>= 0 && drive
< 26)
323 lpszPath
[0] = 'A' + drive
;
331 /*************************************************************************
332 * PathBuildRootW [SHLWAPI.@]
334 * See PathBuildRootA.
336 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
338 TRACE("(%p,%d)\n", lpszPath
, drive
);
340 if (lpszPath
&& drive
>= 0 && drive
< 26)
342 lpszPath
[0] = 'A' + drive
;
350 /*************************************************************************
351 * PathFindFileNameA [SHLWAPI.@]
353 * Locate the start of the file name in a path
356 * lpszPath [I] Path to search
359 * A pointer to the first character of the file name
361 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
363 LPCSTR lastSlash
= lpszPath
;
365 TRACE("(%s)\n",debugstr_a(lpszPath
));
367 while (lpszPath
&& *lpszPath
)
369 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
370 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
371 lastSlash
= lpszPath
+ 1;
372 lpszPath
= CharNextA(lpszPath
);
374 return (LPSTR
)lastSlash
;
377 /*************************************************************************
378 * PathFindFileNameW [SHLWAPI.@]
380 * See PathFindFileNameA.
382 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
384 LPCWSTR lastSlash
= lpszPath
;
386 TRACE("(%s)\n",debugstr_w(lpszPath
));
388 while (lpszPath
&& *lpszPath
)
390 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
391 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
392 lastSlash
= lpszPath
+ 1;
395 return (LPWSTR
)lastSlash
;
398 /*************************************************************************
399 * PathFindExtensionA [SHLWAPI.@]
401 * Locate the start of the file extension in a path
404 * lpszPath [I] The path to search
407 * A pointer to the first character of the extension, the end of
408 * the string if the path has no extension, or NULL If lpszPath is NULL
410 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
412 LPCSTR lastpoint
= NULL
;
414 TRACE("(%s)\n", debugstr_a(lpszPath
));
420 if (*lpszPath
== '\\' || *lpszPath
==' ')
422 else if (*lpszPath
== '.')
423 lastpoint
= lpszPath
;
424 lpszPath
= CharNextA(lpszPath
);
427 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
430 /*************************************************************************
431 * PathFindExtensionW [SHLWAPI.@]
433 * See PathFindExtensionA.
435 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
437 LPCWSTR lastpoint
= NULL
;
439 TRACE("(%s)\n", debugstr_w(lpszPath
));
445 if (*lpszPath
== '\\' || *lpszPath
==' ')
447 else if (*lpszPath
== '.')
448 lastpoint
= lpszPath
;
452 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
455 /*************************************************************************
456 * PathGetArgsA [SHLWAPI.@]
458 * Find the next argument in a string delimited by spaces.
461 * lpszPath [I] The string to search for arguments in
464 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
467 * Spaces in quoted strings are ignored as delimiters.
469 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
471 BOOL bSeenQuote
= FALSE
;
473 TRACE("(%s)\n",debugstr_a(lpszPath
));
479 if ((*lpszPath
==' ') && !bSeenQuote
)
480 return (LPSTR
)lpszPath
+ 1;
481 if (*lpszPath
== '"')
482 bSeenQuote
= !bSeenQuote
;
483 lpszPath
= CharNextA(lpszPath
);
486 return (LPSTR
)lpszPath
;
489 /*************************************************************************
490 * PathGetArgsW [SHLWAPI.@]
494 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
496 BOOL bSeenQuote
= FALSE
;
498 TRACE("(%s)\n",debugstr_w(lpszPath
));
504 if ((*lpszPath
==' ') && !bSeenQuote
)
505 return (LPWSTR
)lpszPath
+ 1;
506 if (*lpszPath
== '"')
507 bSeenQuote
= !bSeenQuote
;
511 return (LPWSTR
)lpszPath
;
514 /*************************************************************************
515 * PathGetDriveNumberA [SHLWAPI.@]
517 * Return the drive number from a path
520 * lpszPath [I] Path to get the drive number from
523 * Success: The drive number corresponding to the drive in the path
524 * Failure: -1, if lpszPath contains no valid drive
526 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
528 TRACE ("(%s)\n",debugstr_a(lpszPath
));
530 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
531 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
532 return tolower(*lpszPath
) - 'a';
536 /*************************************************************************
537 * PathGetDriveNumberW [SHLWAPI.@]
539 * See PathGetDriveNumberA.
541 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
543 TRACE ("(%s)\n",debugstr_w(lpszPath
));
547 WCHAR tl
= tolowerW(lpszPath
[0]);
548 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
554 /*************************************************************************
555 * PathRemoveFileSpecA [SHLWAPI.@]
557 * Remove the file specification from a path.
560 * lpszPath [I/O] Path to remove the file spec from
563 * TRUE If the path was valid and modified
566 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
568 LPSTR lpszFileSpec
= lpszPath
;
569 BOOL bModified
= FALSE
;
571 TRACE("(%s)\n",debugstr_a(lpszPath
));
575 /* Skip directory or UNC path */
576 if (*lpszPath
== '\\')
577 lpszFileSpec
= ++lpszPath
;
578 if (*lpszPath
== '\\')
579 lpszFileSpec
= ++lpszPath
;
583 if(*lpszPath
== '\\')
584 lpszFileSpec
= lpszPath
; /* Skip dir */
585 else if(*lpszPath
== ':')
587 lpszFileSpec
= ++lpszPath
; /* Skip drive */
588 if (*lpszPath
== '\\')
591 if (!(lpszPath
= CharNextA(lpszPath
)))
597 *lpszFileSpec
= '\0';
604 /*************************************************************************
605 * PathRemoveFileSpecW [SHLWAPI.@]
607 * See PathRemoveFileSpecA.
609 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
611 LPWSTR lpszFileSpec
= lpszPath
;
612 BOOL bModified
= FALSE
;
614 TRACE("(%s)\n",debugstr_w(lpszPath
));
618 /* Skip directory or UNC path */
619 if (*lpszPath
== '\\')
620 lpszFileSpec
= ++lpszPath
;
621 if (*lpszPath
== '\\')
622 lpszFileSpec
= ++lpszPath
;
626 if(*lpszPath
== '\\')
627 lpszFileSpec
= lpszPath
; /* Skip dir */
628 else if(*lpszPath
== ':')
630 lpszFileSpec
= ++lpszPath
; /* Skip drive */
631 if (*lpszPath
== '\\')
639 *lpszFileSpec
= '\0';
646 /*************************************************************************
647 * PathStripPathA [SHLWAPI.@]
649 * Remove the initial path from the beginning of a filename
652 * lpszPath [I/O] Path to remove the initial path from
657 void WINAPI
PathStripPathA(LPSTR lpszPath
)
659 TRACE("(%s)\n", debugstr_a(lpszPath
));
663 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
665 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
669 /*************************************************************************
670 * PathStripPathW [SHLWAPI.@]
672 * See PathStripPathA.
674 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
678 TRACE("(%s)\n", debugstr_w(lpszPath
));
679 lpszFileName
= PathFindFileNameW(lpszPath
);
681 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
684 /*************************************************************************
685 * PathStripToRootA [SHLWAPI.@]
687 * Reduce a path to its root.
690 * lpszPath [I/O] the path to reduce
693 * Success: TRUE if the stripped path is a root path
694 * Failure: FALSE if the path cannot be stripped or is NULL
696 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
698 TRACE("(%s)\n", debugstr_a(lpszPath
));
702 while(!PathIsRootA(lpszPath
))
703 if (!PathRemoveFileSpecA(lpszPath
))
708 /*************************************************************************
709 * PathStripToRootW [SHLWAPI.@]
711 * See PathStripToRootA.
713 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
715 TRACE("(%s)\n", debugstr_w(lpszPath
));
719 while(!PathIsRootW(lpszPath
))
720 if (!PathRemoveFileSpecW(lpszPath
))
725 /*************************************************************************
726 * PathRemoveArgsA [SHLWAPI.@]
728 * Strip space separated arguments from a path.
731 * lpszPath [I/O] Path to remove arguments from
736 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
738 TRACE("(%s)\n",debugstr_a(lpszPath
));
742 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
747 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
748 if(*lpszLastChar
== ' ')
749 *lpszLastChar
= '\0';
754 /*************************************************************************
755 * PathRemoveArgsW [SHLWAPI.@]
757 * See PathRemoveArgsA.
759 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
761 TRACE("(%s)\n",debugstr_w(lpszPath
));
765 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
766 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
771 /*************************************************************************
772 * PathRemoveExtensionA [SHLWAPI.@]
774 * Remove the file extension from a path
777 * lpszPath [I/O] Path to remove the extension from
780 * The NUL terminator must be written only if extension exists
781 * and if the pointed character is not already NUL.
786 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
788 TRACE("(%s)\n", debugstr_a(lpszPath
));
792 lpszPath
= PathFindExtensionA(lpszPath
);
793 if (lpszPath
&& *lpszPath
!= '\0')
798 /*************************************************************************
799 * PathRemoveExtensionW [SHLWAPI.@]
801 * See PathRemoveExtensionA.
803 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
805 TRACE("(%s)\n", debugstr_w(lpszPath
));
809 lpszPath
= PathFindExtensionW(lpszPath
);
810 if (lpszPath
&& *lpszPath
!= '\0')
815 /*************************************************************************
816 * PathRemoveBackslashA [SHLWAPI.@]
818 * Remove a trailing backslash from a path.
821 * lpszPath [I/O] Path to remove backslash from
824 * Success: A pointer to the end of the path
825 * Failure: NULL, if lpszPath is NULL
827 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
831 TRACE("(%s)\n", debugstr_a(lpszPath
));
835 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
836 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
842 /*************************************************************************
843 * PathRemoveBackslashW [SHLWAPI.@]
845 * See PathRemoveBackslashA.
847 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
849 LPWSTR szTemp
= NULL
;
851 TRACE("(%s)\n", debugstr_w(lpszPath
));
855 szTemp
= lpszPath
+ strlenW(lpszPath
);
856 if (szTemp
> lpszPath
) szTemp
--;
857 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
863 /*************************************************************************
864 * PathRemoveBlanksA [SHLWAPI.@]
866 * Remove Spaces from the start and end of a path.
869 * lpszPath [I/O] Path to strip blanks from
874 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
876 TRACE("(%s)\n", debugstr_a(lpszPath
));
878 if(lpszPath
&& *lpszPath
)
880 LPSTR start
= lpszPath
;
882 while (*lpszPath
== ' ')
883 lpszPath
= CharNextA(lpszPath
);
886 *start
++ = *lpszPath
++;
888 if (start
!= lpszPath
)
889 while (start
[-1] == ' ')
895 /*************************************************************************
896 * PathRemoveBlanksW [SHLWAPI.@]
898 * See PathRemoveBlanksA.
900 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
902 TRACE("(%s)\n", debugstr_w(lpszPath
));
904 if(lpszPath
&& *lpszPath
)
906 LPWSTR start
= lpszPath
;
908 while (*lpszPath
== ' ')
912 *start
++ = *lpszPath
++;
914 if (start
!= lpszPath
)
915 while (start
[-1] == ' ')
921 /*************************************************************************
922 * PathQuoteSpacesA [SHLWAPI.@]
924 * Surround a path containing spaces in quotes.
927 * lpszPath [I/O] Path to quote
933 * The path is not changed if it is invalid or has no spaces.
935 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
937 TRACE("(%s)\n", debugstr_a(lpszPath
));
939 if(lpszPath
&& StrChrA(lpszPath
,' '))
941 size_t iLen
= strlen(lpszPath
) + 1;
943 if (iLen
+ 2 < MAX_PATH
)
945 memmove(lpszPath
+ 1, lpszPath
, iLen
);
947 lpszPath
[iLen
] = '"';
948 lpszPath
[iLen
+ 1] = '\0';
953 /*************************************************************************
954 * PathQuoteSpacesW [SHLWAPI.@]
956 * See PathQuoteSpacesA.
958 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
960 TRACE("(%s)\n", debugstr_w(lpszPath
));
962 if(lpszPath
&& StrChrW(lpszPath
,' '))
964 int iLen
= strlenW(lpszPath
) + 1;
966 if (iLen
+ 2 < MAX_PATH
)
968 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
970 lpszPath
[iLen
] = '"';
971 lpszPath
[iLen
+ 1] = '\0';
976 /*************************************************************************
977 * PathUnquoteSpacesA [SHLWAPI.@]
979 * Remove quotes ("") from around a path, if present.
982 * lpszPath [I/O] Path to strip quotes from
988 * If the path contains a single quote only, an empty string will result.
989 * Otherwise quotes are only removed if they appear at the start and end
992 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
994 TRACE("(%s)\n", debugstr_a(lpszPath
));
996 if (lpszPath
&& *lpszPath
== '"')
998 DWORD dwLen
= strlen(lpszPath
) - 1;
1000 if (lpszPath
[dwLen
] == '"')
1002 lpszPath
[dwLen
] = '\0';
1003 for (; *lpszPath
; lpszPath
++)
1004 *lpszPath
= lpszPath
[1];
1009 /*************************************************************************
1010 * PathUnquoteSpacesW [SHLWAPI.@]
1012 * See PathUnquoteSpacesA.
1014 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
1016 TRACE("(%s)\n", debugstr_w(lpszPath
));
1018 if (lpszPath
&& *lpszPath
== '"')
1020 DWORD dwLen
= strlenW(lpszPath
) - 1;
1022 if (lpszPath
[dwLen
] == '"')
1024 lpszPath
[dwLen
] = '\0';
1025 for (; *lpszPath
; lpszPath
++)
1026 *lpszPath
= lpszPath
[1];
1031 /*************************************************************************
1032 * PathParseIconLocationA [SHLWAPI.@]
1034 * Parse the location of an icon from a path.
1037 * lpszPath [I/O] The path to parse the icon location from.
1040 * Success: The number of the icon
1041 * Failure: 0 if the path does not contain an icon location or is NULL
1044 * The path has surrounding quotes and spaces removed regardless
1045 * of whether the call succeeds or not.
1047 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1052 TRACE("(%s)\n", debugstr_a(lpszPath
));
1056 if ((lpszComma
= strchr(lpszPath
, ',')))
1058 *lpszComma
++ = '\0';
1059 iRet
= StrToIntA(lpszComma
);
1061 PathUnquoteSpacesA(lpszPath
);
1062 PathRemoveBlanksA(lpszPath
);
1067 /*************************************************************************
1068 * PathParseIconLocationW [SHLWAPI.@]
1070 * See PathParseIconLocationA.
1072 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1077 TRACE("(%s)\n", debugstr_w(lpszPath
));
1081 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1083 *lpszComma
++ = '\0';
1084 iRet
= StrToIntW(lpszComma
);
1086 PathUnquoteSpacesW(lpszPath
);
1087 PathRemoveBlanksW(lpszPath
);
1092 /*************************************************************************
1095 * Unicode version of PathFileExistsDefExtA.
1097 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1099 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1100 { '.', 'c', 'o', 'm', 0},
1101 { '.', 'e', 'x', 'e', 0},
1102 { '.', 'b', 'a', 't', 0},
1103 { '.', 'l', 'n', 'k', 0},
1104 { '.', 'c', 'm', 'd', 0},
1107 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1109 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1114 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1115 if (!*szExt
|| dwWhich
& 0x40)
1118 int iLen
= lstrlenW(lpszPath
);
1119 if (iLen
> (MAX_PATH
- 5))
1121 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1123 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1124 if (PathFileExistsW(lpszPath
))
1129 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1133 return PathFileExistsW(lpszPath
);
1136 /*************************************************************************
1139 * Determine if a file exists locally and is of an executable type.
1142 * lpszPath [I/O] File to search for
1143 * dwWhich [I] Type of executable to search for
1146 * TRUE If the file was found. lpszPath contains the file name.
1150 * lpszPath is modified in place and must be at least MAX_PATH in length.
1151 * If the function returns FALSE, the path is modified to its original state.
1152 * If the given path contains an extension or dwWhich is 0, executable
1153 * extensions are not checked.
1155 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1156 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1157 * their own developers exclusive use. Monopoly, anyone?
1159 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1163 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1167 WCHAR szPath
[MAX_PATH
];
1168 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1169 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1171 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1176 /*************************************************************************
1177 * SHLWAPI_PathFindInOtherDirs
1179 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1181 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1183 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1184 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1188 WCHAR buff
[MAX_PATH
];
1190 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1192 /* Try system directories */
1193 GetSystemDirectoryW(buff
, MAX_PATH
);
1194 if (!PathAppendW(buff
, lpszFile
))
1196 if (PathFileExistsDefExtW(buff
, dwWhich
))
1198 strcpyW(lpszFile
, buff
);
1201 GetWindowsDirectoryW(buff
, MAX_PATH
);
1202 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1204 if (PathFileExistsDefExtW(buff
, dwWhich
))
1206 strcpyW(lpszFile
, buff
);
1209 GetWindowsDirectoryW(buff
, MAX_PATH
);
1210 if (!PathAppendW(buff
, lpszFile
))
1212 if (PathFileExistsDefExtW(buff
, dwWhich
))
1214 strcpyW(lpszFile
, buff
);
1217 /* Try dirs listed in %PATH% */
1218 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1220 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1223 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1224 lpszCurr
= lpszPATH
;
1227 LPCWSTR lpszEnd
= lpszCurr
;
1228 LPWSTR pBuff
= buff
;
1230 while (*lpszEnd
== ' ')
1232 while (*lpszEnd
&& *lpszEnd
!= ';')
1233 *pBuff
++ = *lpszEnd
++;
1237 lpszCurr
= lpszEnd
+ 1;
1239 lpszCurr
= NULL
; /* Last Path, terminate after this */
1241 if (!PathAppendW(buff
, lpszFile
))
1243 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1246 if (PathFileExistsDefExtW(buff
, dwWhich
))
1248 strcpyW(lpszFile
, buff
);
1249 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1253 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1257 /*************************************************************************
1260 * Search a range of paths for a specific type of executable.
1263 * lpszFile [I/O] File to search for
1264 * lppszOtherDirs [I] Other directories to look in
1265 * dwWhich [I] Type of executable to search for
1268 * Success: TRUE. The path to the executable is stored in lpszFile.
1269 * Failure: FALSE. The path to the executable is unchanged.
1271 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1273 WCHAR szFile
[MAX_PATH
];
1274 WCHAR buff
[MAX_PATH
];
1276 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1278 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1281 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1283 /* Search provided directories first */
1284 if (lppszOtherDirs
&& *lppszOtherDirs
)
1286 WCHAR szOther
[MAX_PATH
];
1287 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1289 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1291 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1292 PathCombineW(buff
, szOther
, szFile
);
1293 if (PathFileExistsDefExtW(buff
, dwWhich
))
1295 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1301 /* Not found, try system and path dirs */
1302 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1304 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1310 /*************************************************************************
1313 * Unicode version of PathFindOnPathExA.
1315 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1317 WCHAR buff
[MAX_PATH
];
1319 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1321 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1324 /* Search provided directories first */
1325 if (lppszOtherDirs
&& *lppszOtherDirs
)
1327 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1328 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1330 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1331 if (PathFileExistsDefExtW(buff
, dwWhich
))
1333 strcpyW(lpszFile
, buff
);
1339 /* Not found, try system and path dirs */
1340 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1343 /*************************************************************************
1344 * PathFindOnPathA [SHLWAPI.@]
1346 * Search a range of paths for an executable.
1349 * lpszFile [I/O] File to search for
1350 * lppszOtherDirs [I] Other directories to look in
1353 * Success: TRUE. The path to the executable is stored in lpszFile.
1354 * Failure: FALSE. The path to the executable is unchanged.
1356 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1358 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1359 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1362 /*************************************************************************
1363 * PathFindOnPathW [SHLWAPI.@]
1365 * See PathFindOnPathA.
1367 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1369 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1370 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1373 /*************************************************************************
1374 * PathCompactPathExA [SHLWAPI.@]
1376 * Compact a path into a given number of characters.
1379 * lpszDest [O] Destination for compacted path
1380 * lpszPath [I] Source path
1381 * cchMax [I] Maximum size of compacted path
1382 * dwFlags [I] Reserved
1385 * Success: TRUE. The compacted path is written to lpszDest.
1386 * Failure: FALSE. lpszPath is undefined.
1389 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1391 * The Win32 version of this function contains a bug: When cchMax == 7,
1392 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1395 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1396 * because Win32 will insert a "\" in lpszDest, even if one is
1397 * not present in the original path.
1399 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1400 UINT cchMax
, DWORD dwFlags
)
1404 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1406 if (lpszPath
&& lpszDest
)
1408 WCHAR szPath
[MAX_PATH
];
1409 WCHAR szDest
[MAX_PATH
];
1411 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1413 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1414 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1419 /*************************************************************************
1420 * PathCompactPathExW [SHLWAPI.@]
1422 * See PathCompactPathExA.
1424 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1425 UINT cchMax
, DWORD dwFlags
)
1427 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1429 DWORD dwLen
, dwFileLen
= 0;
1431 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1438 WARN("Invalid lpszDest would crash under Win32!\n");
1447 dwLen
= strlenW(lpszPath
) + 1;
1451 /* Don't need to compact */
1452 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1456 /* Path must be compacted to fit into lpszDest */
1457 lpszFile
= PathFindFileNameW(lpszPath
);
1458 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1460 if (dwFileLen
== dwLen
)
1462 /* No root in psth */
1465 while (--cchMax
> 0) /* No room left for anything but ellipses */
1470 /* Compact the file name with ellipses at the end */
1472 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1473 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1476 /* We have a root in the path */
1477 lpszFile
--; /* Start compacted filename with the path separator */
1480 if (dwFileLen
+ 3 > cchMax
)
1482 /* Compact the file name */
1485 while (--cchMax
> 0) /* No room left for anything but ellipses */
1490 strcpyW(lpszDest
, szEllipses
);
1493 *lpszDest
++ = *lpszFile
++;
1496 while (--cchMax
> 0) /* No room left for anything but ellipses */
1502 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1503 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1507 /* Only the root needs to be Compacted */
1508 dwLen
= cchMax
- dwFileLen
- 3;
1509 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1510 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1511 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1515 /*************************************************************************
1516 * PathIsRelativeA [SHLWAPI.@]
1518 * Determine if a path is a relative path.
1521 * lpszPath [I] Path to check
1524 * TRUE: The path is relative, or is invalid.
1525 * FALSE: The path is not relative.
1527 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1529 TRACE("(%s)\n",debugstr_a(lpszPath
));
1531 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1533 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1538 /*************************************************************************
1539 * PathIsRelativeW [SHLWAPI.@]
1541 * See PathIsRelativeA.
1543 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1545 TRACE("(%s)\n",debugstr_w(lpszPath
));
1547 if (!lpszPath
|| !*lpszPath
)
1549 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1554 /*************************************************************************
1555 * PathIsRootA [SHLWAPI.@]
1557 * Determine if a path is a root path.
1560 * lpszPath [I] Path to check
1563 * TRUE If lpszPath is valid and a root path,
1566 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1568 TRACE("(%s)\n", debugstr_a(lpszPath
));
1570 if (lpszPath
&& *lpszPath
)
1572 if (*lpszPath
== '\\')
1575 return TRUE
; /* \ */
1576 else if (lpszPath
[1]=='\\')
1578 BOOL bSeenSlash
= FALSE
;
1581 /* Check for UNC root path */
1584 if (*lpszPath
== '\\')
1590 lpszPath
= CharNextA(lpszPath
);
1595 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1596 return TRUE
; /* X:\ */
1601 /*************************************************************************
1602 * PathIsRootW [SHLWAPI.@]
1606 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1608 TRACE("(%s)\n", debugstr_w(lpszPath
));
1610 if (lpszPath
&& *lpszPath
)
1612 if (*lpszPath
== '\\')
1615 return TRUE
; /* \ */
1616 else if (lpszPath
[1]=='\\')
1618 BOOL bSeenSlash
= FALSE
;
1621 /* Check for UNC root path */
1624 if (*lpszPath
== '\\')
1635 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1636 return TRUE
; /* X:\ */
1641 /*************************************************************************
1642 * PathIsDirectoryA [SHLWAPI.@]
1644 * Determine if a path is a valid directory
1647 * lpszPath [I] Path to check.
1650 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1651 * FALSE if lpszPath is invalid or not a directory.
1654 * Although this function is prototyped as returning a BOOL, it returns
1655 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1657 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1662 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1666 TRACE("(%s)\n", debugstr_a(lpszPath
));
1668 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1671 if (PathIsUNCServerShareA(lpszPath
))
1673 FIXME("UNC Server Share not yet supported - FAILING\n");
1677 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1679 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1682 /*************************************************************************
1683 * PathIsDirectoryW [SHLWAPI.@]
1685 * See PathIsDirectoryA.
1687 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1691 TRACE("(%s)\n", debugstr_w(lpszPath
));
1693 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1696 if (PathIsUNCServerShareW(lpszPath
))
1698 FIXME("UNC Server Share not yet supported - FAILING\n");
1702 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1704 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1707 /*************************************************************************
1708 * PathFileExistsA [SHLWAPI.@]
1710 * Determine if a file exists.
1713 * lpszPath [I] Path to check
1716 * TRUE If the file exists and is readable
1719 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1724 TRACE("(%s)\n",debugstr_a(lpszPath
));
1729 /* Prevent a dialog box if path is on a disk that has been ejected. */
1730 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1731 dwAttr
= GetFileAttributesA(lpszPath
);
1732 SetErrorMode(iPrevErrMode
);
1733 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1736 /*************************************************************************
1737 * PathFileExistsW [SHLWAPI.@]
1739 * See PathFileExistsA.
1741 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1746 TRACE("(%s)\n",debugstr_w(lpszPath
));
1751 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1752 dwAttr
= GetFileAttributesW(lpszPath
);
1753 SetErrorMode(iPrevErrMode
);
1754 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1757 /*************************************************************************
1758 * PathFileExistsAndAttributesA [SHLWAPI.445]
1760 * Determine if a file exists.
1763 * lpszPath [I] Path to check
1764 * dwAttr [O] attributes of file
1767 * TRUE If the file exists and is readable
1770 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1775 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1778 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1783 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1784 dwVal
= GetFileAttributesA(lpszPath
);
1785 SetErrorMode(iPrevErrMode
);
1788 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1791 /*************************************************************************
1792 * PathFileExistsAndAttributesW [SHLWAPI.446]
1794 * See PathFileExistsA.
1796 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1801 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1806 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1807 dwVal
= GetFileAttributesW(lpszPath
);
1808 SetErrorMode(iPrevErrMode
);
1811 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1814 /*************************************************************************
1815 * PathMatchSingleMaskA [internal]
1817 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1819 while (*name
&& *mask
&& *mask
!=';')
1825 if (PathMatchSingleMaskA(name
,mask
+1))
1826 return TRUE
; /* try substrings */
1831 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1834 name
= CharNextA(name
);
1835 mask
= CharNextA(mask
);
1840 while (*mask
== '*')
1842 if (!*mask
|| *mask
== ';')
1848 /*************************************************************************
1849 * PathMatchSingleMaskW [internal]
1851 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1853 while (*name
&& *mask
&& *mask
!= ';')
1859 if (PathMatchSingleMaskW(name
,mask
+1))
1860 return TRUE
; /* try substrings */
1865 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1873 while (*mask
== '*')
1875 if (!*mask
|| *mask
== ';')
1881 /*************************************************************************
1882 * PathMatchSpecA [SHLWAPI.@]
1884 * Determine if a path matches one or more search masks.
1887 * lpszPath [I] Path to check
1888 * lpszMask [I] Search mask(s)
1891 * TRUE If lpszPath is valid and is matched
1895 * Multiple search masks may be given if they are separated by ";". The
1896 * pattern "*.*" is treated specially in that it matches all paths (for
1897 * backwards compatibility with DOS).
1899 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1901 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1903 if (!lstrcmpA(lpszMask
, "*.*"))
1904 return TRUE
; /* Matches every path */
1908 while (*lpszMask
== ' ')
1909 lpszMask
++; /* Eat leading spaces */
1911 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1912 return TRUE
; /* Matches the current mask */
1914 while (*lpszMask
&& *lpszMask
!= ';')
1915 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1917 if (*lpszMask
== ';')
1923 /*************************************************************************
1924 * PathMatchSpecW [SHLWAPI.@]
1926 * See PathMatchSpecA.
1928 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1930 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1932 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1934 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1935 return TRUE
; /* Matches every path */
1939 while (*lpszMask
== ' ')
1940 lpszMask
++; /* Eat leading spaces */
1942 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1943 return TRUE
; /* Matches the current path */
1945 while (*lpszMask
&& *lpszMask
!= ';')
1946 lpszMask
++; /* masks separated by ';' */
1948 if (*lpszMask
== ';')
1954 /*************************************************************************
1955 * PathIsSameRootA [SHLWAPI.@]
1957 * Determine if two paths share the same root.
1960 * lpszPath1 [I] Source path
1961 * lpszPath2 [I] Path to compare with
1964 * TRUE If both paths are valid and share the same root.
1965 * FALSE If either path is invalid or the paths do not share the same root.
1967 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1972 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1974 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1977 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1978 if (lpszStart
- lpszPath1
> dwLen
)
1979 return FALSE
; /* Paths not common up to length of the root */
1983 /*************************************************************************
1984 * PathIsSameRootW [SHLWAPI.@]
1986 * See PathIsSameRootA.
1988 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1993 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1995 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1998 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1999 if (lpszStart
- lpszPath1
> dwLen
)
2000 return FALSE
; /* Paths not common up to length of the root */
2004 /*************************************************************************
2005 * PathIsContentTypeA [SHLWAPI.@]
2007 * Determine if a file is of a given registered content type.
2010 * lpszPath [I] File to check
2011 * lpszContentType [I] Content type to check for
2014 * TRUE If lpszPath is a given registered content type,
2018 * This function looks up the registered content type for lpszPath. If
2019 * a content type is registered, it is compared (case insensitively) to
2020 * lpszContentType. Only if this matches does the function succeed.
2022 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2026 char szBuff
[MAX_PATH
];
2028 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2030 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2031 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2032 REG_NONE
, szBuff
, &dwDummy
) &&
2033 !strcasecmp(lpszContentType
, szBuff
))
2040 /*************************************************************************
2041 * PathIsContentTypeW [SHLWAPI.@]
2043 * See PathIsContentTypeA.
2045 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2047 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2050 WCHAR szBuff
[MAX_PATH
];
2052 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2054 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2055 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2056 REG_NONE
, szBuff
, &dwDummy
) &&
2057 !strcmpiW(lpszContentType
, szBuff
))
2064 /*************************************************************************
2065 * PathIsFileSpecA [SHLWAPI.@]
2067 * Determine if a path is a file specification.
2070 * lpszPath [I] Path to check
2073 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2076 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2078 TRACE("(%s)\n", debugstr_a(lpszPath
));
2085 if (*lpszPath
== '\\' || *lpszPath
== ':')
2087 lpszPath
= CharNextA(lpszPath
);
2092 /*************************************************************************
2093 * PathIsFileSpecW [SHLWAPI.@]
2095 * See PathIsFileSpecA.
2097 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2099 TRACE("(%s)\n", debugstr_w(lpszPath
));
2106 if (*lpszPath
== '\\' || *lpszPath
== ':')
2113 /*************************************************************************
2114 * PathIsPrefixA [SHLWAPI.@]
2116 * Determine if a path is a prefix of another.
2119 * lpszPrefix [I] Prefix
2120 * lpszPath [I] Path to check
2123 * TRUE If lpszPath has lpszPrefix as its prefix,
2124 * FALSE If either path is NULL or lpszPrefix is not a prefix
2126 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2128 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2130 if (lpszPrefix
&& lpszPath
&&
2131 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2136 /*************************************************************************
2137 * PathIsPrefixW [SHLWAPI.@]
2139 * See PathIsPrefixA.
2141 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2143 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2145 if (lpszPrefix
&& lpszPath
&&
2146 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2151 /*************************************************************************
2152 * PathIsSystemFolderA [SHLWAPI.@]
2154 * Determine if a path or file attributes are a system folder.
2157 * lpszPath [I] Path to check.
2158 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2161 * TRUE If lpszPath or dwAttrib are a system folder.
2162 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2164 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2166 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2168 if (lpszPath
&& *lpszPath
)
2169 dwAttrib
= GetFileAttributesA(lpszPath
);
2171 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2172 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2177 /*************************************************************************
2178 * PathIsSystemFolderW [SHLWAPI.@]
2180 * See PathIsSystemFolderA.
2182 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2184 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2186 if (lpszPath
&& *lpszPath
)
2187 dwAttrib
= GetFileAttributesW(lpszPath
);
2189 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2190 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2195 /*************************************************************************
2196 * PathIsUNCA [SHLWAPI.@]
2198 * Determine if a path is in UNC format.
2201 * lpszPath [I] Path to check
2204 * TRUE: The path is UNC.
2205 * FALSE: The path is not UNC or is NULL.
2207 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2209 TRACE("(%s)\n",debugstr_a(lpszPath
));
2211 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2216 /*************************************************************************
2217 * PathIsUNCW [SHLWAPI.@]
2221 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2223 TRACE("(%s)\n",debugstr_w(lpszPath
));
2225 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2230 /*************************************************************************
2231 * PathIsUNCServerA [SHLWAPI.@]
2233 * Determine if a path is a UNC server name ("\\SHARENAME").
2236 * lpszPath [I] Path to check.
2239 * TRUE If lpszPath is a valid UNC server name.
2243 * This routine is bug compatible with Win32: Server names with a
2244 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2245 * Fixing this bug may break other shlwapi functions!
2247 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2249 TRACE("(%s)\n", debugstr_a(lpszPath
));
2251 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2255 if (*lpszPath
== '\\')
2257 lpszPath
= CharNextA(lpszPath
);
2264 /*************************************************************************
2265 * PathIsUNCServerW [SHLWAPI.@]
2267 * See PathIsUNCServerA.
2269 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2271 TRACE("(%s)\n", debugstr_w(lpszPath
));
2273 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2275 return !strchrW( lpszPath
+ 2, '\\' );
2280 /*************************************************************************
2281 * PathIsUNCServerShareA [SHLWAPI.@]
2283 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2286 * lpszPath [I] Path to check.
2289 * TRUE If lpszPath is a valid UNC server share.
2293 * This routine is bug compatible with Win32: Server shares with a
2294 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2295 * Fixing this bug may break other shlwapi functions!
2297 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2299 TRACE("(%s)\n", debugstr_a(lpszPath
));
2301 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2303 BOOL bSeenSlash
= FALSE
;
2306 if (*lpszPath
== '\\')
2312 lpszPath
= CharNextA(lpszPath
);
2319 /*************************************************************************
2320 * PathIsUNCServerShareW [SHLWAPI.@]
2322 * See PathIsUNCServerShareA.
2324 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2326 TRACE("(%s)\n", debugstr_w(lpszPath
));
2328 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2330 BOOL bSeenSlash
= FALSE
;
2333 if (*lpszPath
== '\\')
2346 /*************************************************************************
2347 * PathCanonicalizeA [SHLWAPI.@]
2349 * Convert a path to its canonical form.
2352 * lpszBuf [O] Output path
2353 * lpszPath [I] Path to canonicalize
2356 * Success: TRUE. lpszBuf contains the output path,
2357 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2359 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2363 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2368 if (!lpszBuf
|| !lpszPath
)
2369 SetLastError(ERROR_INVALID_PARAMETER
);
2372 WCHAR szPath
[MAX_PATH
];
2373 WCHAR szBuff
[MAX_PATH
];
2374 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2377 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2380 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2381 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2387 /*************************************************************************
2388 * PathCanonicalizeW [SHLWAPI.@]
2390 * See PathCanonicalizeA.
2392 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2394 LPWSTR lpszDst
= lpszBuf
;
2395 LPCWSTR lpszSrc
= lpszPath
;
2397 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2402 if (!lpszBuf
|| !lpszPath
)
2404 SetLastError(ERROR_INVALID_PARAMETER
);
2415 /* Copy path root */
2416 if (*lpszSrc
== '\\')
2418 *lpszDst
++ = *lpszSrc
++;
2420 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2423 *lpszDst
++ = *lpszSrc
++;
2424 *lpszDst
++ = *lpszSrc
++;
2425 if (*lpszSrc
== '\\')
2426 *lpszDst
++ = *lpszSrc
++;
2429 /* Canonicalize the rest of the path */
2432 if (*lpszSrc
== '.')
2434 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2436 lpszSrc
+= 2; /* Skip .\ */
2438 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2440 /* \.. backs up a directory, over the root if it has no \ following X:.
2441 * .. is ignored if it would remove a UNC server name or initial \\
2443 if (lpszDst
!= lpszBuf
)
2445 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2446 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2447 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2449 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2452 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2454 if (*lpszDst
== '\\')
2455 lpszDst
++; /* Reset to last '\' */
2457 lpszDst
= lpszBuf
; /* Start path again from new root */
2459 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2462 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2464 if (lpszDst
== lpszBuf
)
2470 lpszSrc
+= 2; /* Skip .. in src path */
2473 *lpszDst
++ = *lpszSrc
++;
2476 *lpszDst
++ = *lpszSrc
++;
2478 /* Append \ to naked drive specs */
2479 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2485 /*************************************************************************
2486 * PathFindNextComponentA [SHLWAPI.@]
2488 * Find the next component in a path.
2491 * lpszPath [I] Path to find next component in
2494 * Success: A pointer to the next component, or the end of the string.
2495 * Failure: NULL, If lpszPath is invalid
2498 * A 'component' is either a backslash character (\) or UNC marker (\\).
2499 * Because of this, relative paths (e.g "c:foo") are regarded as having
2500 * only one component.
2502 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2506 TRACE("(%s)\n", debugstr_a(lpszPath
));
2508 if(!lpszPath
|| !*lpszPath
)
2511 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2513 if (lpszSlash
[1] == '\\')
2515 return lpszSlash
+ 1;
2517 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2520 /*************************************************************************
2521 * PathFindNextComponentW [SHLWAPI.@]
2523 * See PathFindNextComponentA.
2525 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2529 TRACE("(%s)\n", debugstr_w(lpszPath
));
2531 if(!lpszPath
|| !*lpszPath
)
2534 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2536 if (lpszSlash
[1] == '\\')
2538 return lpszSlash
+ 1;
2540 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2543 /*************************************************************************
2544 * PathAddExtensionA [SHLWAPI.@]
2546 * Add a file extension to a path
2549 * lpszPath [I/O] Path to add extension to
2550 * lpszExtension [I] Extension to add to lpszPath
2553 * TRUE If the path was modified,
2554 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2555 * extension already, or the new path length is too big.
2558 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2559 * does not do this, so the behaviour was removed.
2561 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2565 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2567 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2570 dwLen
= strlen(lpszPath
);
2572 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2575 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2579 /*************************************************************************
2580 * PathAddExtensionW [SHLWAPI.@]
2582 * See PathAddExtensionA.
2584 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2588 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2590 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2593 dwLen
= strlenW(lpszPath
);
2595 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2598 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2602 /*************************************************************************
2603 * PathMakePrettyA [SHLWAPI.@]
2605 * Convert an uppercase DOS filename into lowercase.
2608 * lpszPath [I/O] Path to convert.
2611 * TRUE If the path was an uppercase DOS path and was converted,
2614 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2616 LPSTR pszIter
= lpszPath
;
2618 TRACE("(%s)\n", debugstr_a(lpszPath
));
2627 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2628 return FALSE
; /* Not DOS path */
2631 pszIter
= lpszPath
+ 1;
2634 *pszIter
= tolower(*pszIter
);
2641 /*************************************************************************
2642 * PathMakePrettyW [SHLWAPI.@]
2644 * See PathMakePrettyA.
2646 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2648 LPWSTR pszIter
= lpszPath
;
2650 TRACE("(%s)\n", debugstr_w(lpszPath
));
2659 if (islowerW(*pszIter
))
2660 return FALSE
; /* Not DOS path */
2663 pszIter
= lpszPath
+ 1;
2666 *pszIter
= tolowerW(*pszIter
);
2673 /*************************************************************************
2674 * PathCommonPrefixA [SHLWAPI.@]
2676 * Determine the length of the common prefix between two paths.
2679 * lpszFile1 [I] First path for comparison
2680 * lpszFile2 [I] Second path for comparison
2681 * achPath [O] Destination for common prefix string
2684 * The length of the common prefix. This is 0 if there is no common
2685 * prefix between the paths or if any parameters are invalid. If the prefix
2686 * is non-zero and achPath is not NULL, achPath is filled with the common
2687 * part of the prefix and NUL terminated.
2690 * A common prefix of 2 is always returned as 3. It is thus possible for
2691 * the length returned to be invalid (i.e. Longer than one or both of the
2692 * strings given as parameters). This Win32 behaviour has been implemented
2693 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2694 * To work around this when using this function, always check that the byte
2695 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2697 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2700 LPCSTR lpszIter1
= lpszFile1
;
2701 LPCSTR lpszIter2
= lpszFile2
;
2703 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2708 if (!lpszFile1
|| !lpszFile2
)
2711 /* Handle roots first */
2712 if (PathIsUNCA(lpszFile1
))
2714 if (!PathIsUNCA(lpszFile2
))
2719 else if (PathIsUNCA(lpszFile2
))
2720 return 0; /* Know already lpszFile1 is not UNC */
2725 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2726 (!*lpszIter2
|| *lpszIter2
== '\\'))
2727 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2729 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2730 break; /* Strings differ at this point */
2737 iLen
++; /* Feature/Bug compatible with Win32 */
2739 if (iLen
&& achPath
)
2741 memcpy(achPath
,lpszFile1
,iLen
);
2742 achPath
[iLen
] = '\0';
2747 /*************************************************************************
2748 * PathCommonPrefixW [SHLWAPI.@]
2750 * See PathCommonPrefixA.
2752 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2755 LPCWSTR lpszIter1
= lpszFile1
;
2756 LPCWSTR lpszIter2
= lpszFile2
;
2758 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2763 if (!lpszFile1
|| !lpszFile2
)
2766 /* Handle roots first */
2767 if (PathIsUNCW(lpszFile1
))
2769 if (!PathIsUNCW(lpszFile2
))
2774 else if (PathIsUNCW(lpszFile2
))
2775 return 0; /* Know already lpszFile1 is not UNC */
2780 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2781 (!*lpszIter2
|| *lpszIter2
== '\\'))
2782 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2784 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2785 break; /* Strings differ at this point */
2792 iLen
++; /* Feature/Bug compatible with Win32 */
2794 if (iLen
&& achPath
)
2796 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2797 achPath
[iLen
] = '\0';
2802 /*************************************************************************
2803 * PathCompactPathA [SHLWAPI.@]
2805 * Make a path fit into a given width when printed to a DC.
2808 * hDc [I] Destination DC
2809 * lpszPath [I/O] Path to be printed to hDc
2810 * dx [I] Desired width
2813 * TRUE If the path was modified/went well.
2816 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2820 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2824 WCHAR szPath
[MAX_PATH
];
2825 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2826 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2827 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2832 /*************************************************************************
2833 * PathCompactPathW [SHLWAPI.@]
2835 * See PathCompactPathA.
2837 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2839 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2842 WCHAR buff
[MAX_PATH
];
2846 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2852 hdc
= hDC
= GetDC(0);
2854 /* Get the length of the whole path */
2855 dwLen
= strlenW(lpszPath
);
2856 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2858 if ((UINT
)size
.cx
> dx
)
2860 /* Path too big, must reduce it */
2862 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2864 sFile
= PathFindFileNameW(lpszPath
);
2865 if (sFile
!= lpszPath
) sFile
--;
2867 /* Get the size of ellipses */
2868 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2869 dwEllipsesLen
= size
.cx
;
2870 /* Get the size of the file name */
2871 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2872 dwPathLen
= size
.cx
;
2874 if (sFile
!= lpszPath
)
2876 LPWSTR sPath
= sFile
;
2877 BOOL bEllipses
= FALSE
;
2879 /* The path includes a file name. Include as much of the path prior to
2880 * the file name as possible, allowing for the ellipses, e.g:
2881 * c:\some very long path\filename ==> c:\some v...\filename
2883 lstrcpynW(buff
, sFile
, MAX_PATH
);
2887 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2889 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2890 dwTotalLen
+= size
.cx
;
2891 if (dwTotalLen
<= dx
)
2899 } while (sPath
> lpszPath
);
2901 if (sPath
> lpszPath
)
2905 strcpyW(sPath
, szEllipses
);
2906 strcpyW(sPath
+3, buff
);
2911 strcpyW(lpszPath
, szEllipses
);
2912 strcpyW(lpszPath
+3, buff
);
2917 /* Trim the path by adding ellipses to the end, e.g:
2918 * A very long file name.txt ==> A very...
2920 dwLen
= strlenW(lpszPath
);
2922 if (dwLen
> MAX_PATH
- 3)
2923 dwLen
= MAX_PATH
- 3;
2924 lstrcpynW(buff
, sFile
, dwLen
);
2928 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2929 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2933 DWORD dwWritten
= 0;
2935 dwEllipsesLen
/= 3; /* Size of a single '.' */
2937 /* Write as much of the Ellipses string as possible */
2938 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2941 dwWritten
+= dwEllipsesLen
;
2949 strcpyW(buff
+ dwLen
, szEllipses
);
2950 strcpyW(lpszPath
, buff
);
2961 /*************************************************************************
2962 * PathGetCharTypeA [SHLWAPI.@]
2964 * Categorise a character from a file path.
2967 * ch [I] Character to get the type of
2970 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2972 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2974 return PathGetCharTypeW(ch
);
2977 /*************************************************************************
2978 * PathGetCharTypeW [SHLWAPI.@]
2980 * See PathGetCharTypeA.
2982 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2986 TRACE("(%d)\n", ch
);
2988 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2989 ch
== '"' || ch
== '|' || ch
== '/')
2990 flags
= GCT_INVALID
; /* Invalid */
2991 else if (ch
== '*' || ch
=='?')
2992 flags
= GCT_WILD
; /* Wildchars */
2993 else if ((ch
== '\\') || (ch
== ':'))
2994 return GCT_SEPARATOR
; /* Path separators */
2999 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
3000 ch
== '.' || ch
== '@' || ch
== '^' ||
3001 ch
== '\'' || ch
== 130 || ch
== '`')
3002 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
3005 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
3006 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
3011 /*************************************************************************
3012 * SHLWAPI_UseSystemForSystemFolders
3014 * Internal helper for PathMakeSystemFolderW.
3016 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3018 static BOOL bCheckedReg
= FALSE
;
3019 static BOOL bUseSystemForSystemFolders
= FALSE
;
3025 /* Key tells Win what file attributes to use on system folders */
3026 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3027 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3028 "UseSystemForSystemFolders", 0, 0, 0))
3029 bUseSystemForSystemFolders
= TRUE
;
3031 return bUseSystemForSystemFolders
;
3034 /*************************************************************************
3035 * PathMakeSystemFolderA [SHLWAPI.@]
3037 * Set system folder attribute for a path.
3040 * lpszPath [I] The path to turn into a system folder
3043 * TRUE If the path was changed to/already was a system folder
3044 * FALSE If the path is invalid or SetFileAttributesA() fails
3046 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3050 TRACE("(%s)\n", debugstr_a(lpszPath
));
3052 if (lpszPath
&& *lpszPath
)
3054 WCHAR szPath
[MAX_PATH
];
3055 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3056 bRet
= PathMakeSystemFolderW(szPath
);
3061 /*************************************************************************
3062 * PathMakeSystemFolderW [SHLWAPI.@]
3064 * See PathMakeSystemFolderA.
3066 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3068 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3069 WCHAR buff
[MAX_PATH
];
3071 TRACE("(%s)\n", debugstr_w(lpszPath
));
3073 if (!lpszPath
|| !*lpszPath
)
3076 /* If the directory is already a system directory, don't do anything */
3077 GetSystemDirectoryW(buff
, MAX_PATH
);
3078 if (!strcmpW(buff
, lpszPath
))
3081 GetWindowsDirectoryW(buff
, MAX_PATH
);
3082 if (!strcmpW(buff
, lpszPath
))
3085 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3086 if (SHLWAPI_UseSystemForSystemFolders())
3087 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3089 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3092 /* Change file attributes to system attributes */
3093 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3094 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3097 /*************************************************************************
3098 * PathRenameExtensionA [SHLWAPI.@]
3100 * Swap the file extension in a path with another extension.
3103 * lpszPath [I/O] Path to swap the extension in
3104 * lpszExt [I] The new extension
3107 * TRUE if lpszPath was modified,
3108 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3110 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3112 LPSTR lpszExtension
;
3114 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3116 lpszExtension
= PathFindExtensionA(lpszPath
);
3118 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3121 strcpy(lpszExtension
, lpszExt
);
3125 /*************************************************************************
3126 * PathRenameExtensionW [SHLWAPI.@]
3128 * See PathRenameExtensionA.
3130 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3132 LPWSTR lpszExtension
;
3134 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3136 lpszExtension
= PathFindExtensionW(lpszPath
);
3138 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3141 strcpyW(lpszExtension
, lpszExt
);
3145 /*************************************************************************
3146 * PathSearchAndQualifyA [SHLWAPI.@]
3148 * Determine if a given path is correct and fully qualified.
3151 * lpszPath [I] Path to check
3152 * lpszBuf [O] Output for correct path
3153 * cchBuf [I] Size of lpszBuf
3158 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3160 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3162 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3164 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3167 /*************************************************************************
3168 * PathSearchAndQualifyW [SHLWAPI.@]
3170 * See PathSearchAndQualifyA.
3172 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3174 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3176 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3178 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3181 /*************************************************************************
3182 * PathSkipRootA [SHLWAPI.@]
3184 * Return the portion of a path following the drive letter or mount point.
3187 * lpszPath [I] The path to skip on
3190 * Success: A pointer to the next character after the root.
3191 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3193 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3195 TRACE("(%s)\n", debugstr_a(lpszPath
));
3197 if (!lpszPath
|| !*lpszPath
)
3200 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3202 /* Network share: skip share server and mount point */
3204 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3205 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3207 return (LPSTR
)lpszPath
;
3210 if (IsDBCSLeadByte(*lpszPath
))
3214 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3215 return (LPSTR
)lpszPath
+ 3;
3219 /*************************************************************************
3220 * PathSkipRootW [SHLWAPI.@]
3222 * See PathSkipRootA.
3224 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3226 TRACE("(%s)\n", debugstr_w(lpszPath
));
3228 if (!lpszPath
|| !*lpszPath
)
3231 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3233 /* Network share: skip share server and mount point */
3235 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3236 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3238 return (LPWSTR
)lpszPath
;
3242 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3243 return (LPWSTR
)lpszPath
+ 3;
3247 /*************************************************************************
3248 * PathCreateFromUrlA [SHLWAPI.@]
3250 * See PathCreateFromUrlW
3252 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3253 LPDWORD pcchPath
, DWORD dwReserved
)
3255 WCHAR bufW
[MAX_PATH
];
3256 WCHAR
*pathW
= bufW
;
3257 UNICODE_STRING urlW
;
3259 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3261 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3262 return E_INVALIDARG
;
3264 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3265 return E_INVALIDARG
;
3266 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3267 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3268 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3271 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3272 if(*pcchPath
> lenA
) {
3273 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3277 *pcchPath
= lenA
+ 1;
3281 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3282 RtlFreeUnicodeString(&urlW
);
3286 /*************************************************************************
3287 * PathCreateFromUrlW [SHLWAPI.@]
3289 * Create a path from a URL
3292 * lpszUrl [I] URL to convert into a path
3293 * lpszPath [O] Output buffer for the resulting Path
3294 * pcchPath [I] Length of lpszPath
3295 * dwFlags [I] Flags controlling the conversion
3298 * Success: S_OK. lpszPath contains the URL in path format,
3299 * Failure: An HRESULT error code such as E_INVALIDARG.
3301 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3302 LPDWORD pcchPath
, DWORD dwReserved
)
3304 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3305 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3306 DWORD nslashes
, unescape
, len
;
3311 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3313 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3314 return E_INVALIDARG
;
3316 if (lstrlenW(pszUrl
) < 5)
3317 return E_INVALIDARG
;
3319 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3320 file_colon
, 5) != CSTR_EQUAL
)
3321 return E_INVALIDARG
;
3327 while (*src
== '/' || *src
== '\\') {
3332 /* We need a temporary buffer so we can compute what size to ask for.
3333 * We know that the final string won't be longer than the current pszUrl
3334 * plus at most two backslashes. All the other transformations make it
3337 len
= 2 + lstrlenW(pszUrl
) + 1;
3338 if (*pcchPath
< len
)
3339 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3349 /* 'file:' + escaped DOS path */
3352 /* 'file:/' + escaped DOS path */
3355 /* 'file:///' (implied localhost) + escaped DOS path */
3356 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3360 if (lstrlenW(src
) >= 10 && CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
,
3361 src
, 9, localhost
, 9) == CSTR_EQUAL
&& (src
[9] == '/' || src
[9] == '\\'))
3363 /* 'file://localhost/' + escaped DOS path */
3366 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3368 /* 'file://' + unescaped DOS path */
3373 /* 'file://hostname:port/path' (where path is escaped)
3374 * or 'file:' + escaped UNC path (\\server\share\path)
3375 * The second form is clearly specific to Windows and it might
3376 * even be doing a network lookup to try to figure it out.
3378 while (*src
&& *src
!= '/' && *src
!= '\\')
3381 StrCpyNW(dst
, pszUrl
, len
+ 1);
3383 if (*src
&& isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3385 /* 'Forget' to add a trailing '/', just like Windows */
3391 /* 'file://' + unescaped UNC path (\\server\share\path) */
3393 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3397 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3401 /* Copy the remainder of the path */
3402 len
+= lstrlenW(src
);
3405 /* First do the Windows-specific path conversions */
3406 for (dst
= tpath
; *dst
; dst
++)
3407 if (*dst
== '/') *dst
= '\\';
3408 if (isalphaW(*tpath
) && tpath
[1] == '|')
3409 tpath
[1] = ':'; /* c| -> c: */
3411 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3414 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3417 /* When working in-place UrlUnescapeW() does not set len */
3418 len
= lstrlenW(tpath
);
3422 if (*pcchPath
< len
+ 1)
3425 *pcchPath
= len
+ 1;
3430 if (tpath
!= pszPath
)
3431 StrCpyW(pszPath
, tpath
);
3433 if (tpath
!= pszPath
)
3434 HeapFree(GetProcessHeap(), 0, tpath
);
3436 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3440 /*************************************************************************
3441 * PathCreateFromUrlAlloc [SHLWAPI.@]
3443 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3446 WCHAR pathW
[MAX_PATH
];
3451 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3454 /* Yes, this is supposed to crash if pszPath is NULL */
3455 *pszPath
= StrDupW(pathW
);
3460 /*************************************************************************
3461 * PathRelativePathToA [SHLWAPI.@]
3463 * Create a relative path from one path to another.
3466 * lpszPath [O] Destination for relative path
3467 * lpszFrom [I] Source path
3468 * dwAttrFrom [I] File attribute of source path
3469 * lpszTo [I] Destination path
3470 * dwAttrTo [I] File attributes of destination path
3473 * TRUE If a relative path can be formed. lpszPath contains the new path
3474 * FALSE If the paths are not relative or any parameters are invalid
3477 * lpszTo should be at least MAX_PATH in length.
3479 * Calling this function with relative paths for lpszFrom or lpszTo may
3480 * give erroneous results.
3482 * The Win32 version of this function contains a bug where the lpszTo string
3483 * may be referenced 1 byte beyond the end of the string. As a result random
3484 * garbage may be written to the output path, depending on what lies beyond
3485 * the last byte of the string. This bug occurs because of the behaviour of
3486 * PathCommonPrefix() (see notes for that function), and no workaround seems
3487 * possible with Win32.
3489 * This bug has been fixed here, so for example the relative path from "\\"
3490 * to "\\" is correctly determined as "." in this implementation.
3492 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3493 LPCSTR lpszTo
, DWORD dwAttrTo
)
3497 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3498 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3500 if(lpszPath
&& lpszFrom
&& lpszTo
)
3502 WCHAR szPath
[MAX_PATH
];
3503 WCHAR szFrom
[MAX_PATH
];
3504 WCHAR szTo
[MAX_PATH
];
3505 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3506 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3507 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3508 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3513 /*************************************************************************
3514 * PathRelativePathToW [SHLWAPI.@]
3516 * See PathRelativePathToA.
3518 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3519 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3521 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3522 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3523 WCHAR szFrom
[MAX_PATH
];
3524 WCHAR szTo
[MAX_PATH
];
3527 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3528 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3530 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3534 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3535 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3537 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3538 PathRemoveFileSpecW(szFrom
);
3539 if(!(dwAttrTo
& FILE_ATTRIBUTE_DIRECTORY
))
3540 PathRemoveFileSpecW(szTo
);
3542 /* Paths can only be relative if they have a common root */
3543 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3546 /* Strip off lpszFrom components to the root, by adding "..\" */
3547 lpszFrom
= szFrom
+ dwLen
;
3553 if (*lpszFrom
== '\\')
3558 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3559 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3562 /* From the root add the components of lpszTo */
3564 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3567 if (*lpszTo
&& lpszTo
[-1])
3569 if (*lpszTo
!= '\\')
3571 dwLen
= strlenW(lpszPath
);
3572 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3577 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3582 /*************************************************************************
3583 * PathUnmakeSystemFolderA [SHLWAPI.@]
3585 * Remove the system folder attributes from a path.
3588 * lpszPath [I] The path to remove attributes from
3592 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3593 * SetFileAttributesA() fails.
3595 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3599 TRACE("(%s)\n", debugstr_a(lpszPath
));
3601 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3602 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3605 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3606 return SetFileAttributesA(lpszPath
, dwAttr
);
3609 /*************************************************************************
3610 * PathUnmakeSystemFolderW [SHLWAPI.@]
3612 * See PathUnmakeSystemFolderA.
3614 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3618 TRACE("(%s)\n", debugstr_w(lpszPath
));
3620 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3621 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3624 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3625 return SetFileAttributesW(lpszPath
, dwAttr
);
3629 /*************************************************************************
3630 * PathSetDlgItemPathA [SHLWAPI.@]
3632 * Set the text of a dialog item to a path, shrinking the path to fit
3633 * if it is too big for the item.
3636 * hDlg [I] Dialog handle
3637 * id [I] ID of item in the dialog
3638 * lpszPath [I] Path to set as the items text
3644 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3645 * window text is erased).
3647 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3649 WCHAR szPath
[MAX_PATH
];
3651 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3654 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3657 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3660 /*************************************************************************
3661 * PathSetDlgItemPathW [SHLWAPI.@]
3663 * See PathSetDlgItemPathA.
3665 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3667 WCHAR path
[MAX_PATH
+ 1];
3673 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3675 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3679 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3683 GetClientRect(hwItem
, &rect
);
3685 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3689 PathCompactPathW(hdc
, path
, rect
.right
);
3690 SelectObject(hdc
, hPrevObj
);
3693 ReleaseDC(hDlg
, hdc
);
3694 SetWindowTextW(hwItem
, path
);
3697 /*************************************************************************
3698 * PathIsNetworkPathA [SHLWAPI.@]
3700 * Determine if the given path is a network path.
3703 * lpszPath [I] Path to check
3706 * TRUE If lpszPath is a UNC share or mapped network drive, or
3707 * FALSE If lpszPath is a local drive or cannot be determined
3709 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3713 TRACE("(%s)\n",debugstr_a(lpszPath
));
3717 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3719 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3720 if (dwDriveNum
== -1)
3722 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3723 return pIsNetDrive(dwDriveNum
);
3726 /*************************************************************************
3727 * PathIsNetworkPathW [SHLWAPI.@]
3729 * See PathIsNetworkPathA.
3731 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3735 TRACE("(%s)\n", debugstr_w(lpszPath
));
3739 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3741 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3742 if (dwDriveNum
== -1)
3744 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3745 return pIsNetDrive(dwDriveNum
);
3748 /*************************************************************************
3749 * PathIsLFNFileSpecA [SHLWAPI.@]
3751 * Determine if the given path is a long file name
3754 * lpszPath [I] Path to check
3757 * TRUE If path is a long file name,
3758 * FALSE If path is a valid DOS short file name
3760 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3762 DWORD dwNameLen
= 0, dwExtLen
= 0;
3764 TRACE("(%s)\n",debugstr_a(lpszPath
));
3771 if (*lpszPath
== ' ')
3772 return TRUE
; /* DOS names cannot have spaces */
3773 if (*lpszPath
== '.')
3776 return TRUE
; /* DOS names have only one dot */
3783 return TRUE
; /* DOS extensions are <= 3 chars*/
3789 return TRUE
; /* DOS names are <= 8 chars */
3791 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3793 return FALSE
; /* Valid DOS path */
3796 /*************************************************************************
3797 * PathIsLFNFileSpecW [SHLWAPI.@]
3799 * See PathIsLFNFileSpecA.
3801 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3803 DWORD dwNameLen
= 0, dwExtLen
= 0;
3805 TRACE("(%s)\n",debugstr_w(lpszPath
));
3812 if (*lpszPath
== ' ')
3813 return TRUE
; /* DOS names cannot have spaces */
3814 if (*lpszPath
== '.')
3817 return TRUE
; /* DOS names have only one dot */
3824 return TRUE
; /* DOS extensions are <= 3 chars*/
3830 return TRUE
; /* DOS names are <= 8 chars */
3834 return FALSE
; /* Valid DOS path */
3837 /*************************************************************************
3838 * PathIsDirectoryEmptyA [SHLWAPI.@]
3840 * Determine if a given directory is empty.
3843 * lpszPath [I] Directory to check
3846 * TRUE If the directory exists and contains no files,
3849 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3853 TRACE("(%s)\n",debugstr_a(lpszPath
));
3857 WCHAR szPath
[MAX_PATH
];
3858 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3859 bRet
= PathIsDirectoryEmptyW(szPath
);
3864 /*************************************************************************
3865 * PathIsDirectoryEmptyW [SHLWAPI.@]
3867 * See PathIsDirectoryEmptyA.
3869 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3871 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3872 WCHAR szSearch
[MAX_PATH
];
3876 WIN32_FIND_DATAW find_data
;
3878 TRACE("(%s)\n",debugstr_w(lpszPath
));
3880 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3883 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3884 PathAddBackslashW(szSearch
);
3885 dwLen
= strlenW(szSearch
);
3886 if (dwLen
> MAX_PATH
- 4)
3889 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3890 hfind
= FindFirstFileW(szSearch
, &find_data
);
3891 if (hfind
== INVALID_HANDLE_VALUE
)
3896 if (find_data
.cFileName
[0] == '.')
3898 if (find_data
.cFileName
[1] == '\0') continue;
3899 if (find_data
.cFileName
[1] == '.' && find_data
.cFileName
[2] == '\0') continue;
3905 while (FindNextFileW(hfind
, &find_data
));
3912 /*************************************************************************
3913 * PathFindSuffixArrayA [SHLWAPI.@]
3915 * Find a suffix string in an array of suffix strings
3918 * lpszSuffix [I] Suffix string to search for
3919 * lppszArray [I] Array of suffix strings to search
3920 * dwCount [I] Number of elements in lppszArray
3923 * Success: The index of the position of lpszSuffix in lppszArray
3924 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3927 * The search is case sensitive.
3928 * The match is made against the end of the suffix string, so for example:
3929 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3931 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3936 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3938 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3940 dwLen
= strlen(lpszSuffix
);
3942 while (dwRet
< dwCount
)
3944 size_t dwCompareLen
= strlen(*lppszArray
);
3945 if (dwCompareLen
< dwLen
)
3947 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3948 return *lppszArray
; /* Found */
3957 /*************************************************************************
3958 * PathFindSuffixArrayW [SHLWAPI.@]
3960 * See PathFindSuffixArrayA.
3962 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3967 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3969 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3971 dwLen
= strlenW(lpszSuffix
);
3973 while (dwRet
< dwCount
)
3975 size_t dwCompareLen
= strlenW(*lppszArray
);
3976 if (dwCompareLen
< dwLen
)
3978 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3979 return *lppszArray
; /* Found */
3988 /*************************************************************************
3989 * PathUndecorateA [SHLWAPI.@]
3991 * Undecorate a file path
3994 * lpszPath [I/O] Path to remove any decoration from
4000 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
4002 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
4004 TRACE("(%s)\n",debugstr_a(lpszPath
));
4008 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
4009 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4011 LPSTR lpszSkip
= lpszExt
- 2;
4012 if (*lpszSkip
== '[')
4013 lpszSkip
++; /* [] (no number) */
4015 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
4017 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4019 /* remove the [n] */
4022 *lpszSkip
++ = *lpszExt
++;
4029 /*************************************************************************
4030 * PathUndecorateW [SHLWAPI.@]
4032 * See PathUndecorateA.
4034 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4036 TRACE("(%s)\n",debugstr_w(lpszPath
));
4040 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4041 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4043 LPWSTR lpszSkip
= lpszExt
- 2;
4044 if (*lpszSkip
== '[')
4045 lpszSkip
++; /* [] (no number) */
4047 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4049 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4051 /* remove the [n] */
4054 *lpszSkip
++ = *lpszExt
++;
4061 /*************************************************************************
4062 * PathUnExpandEnvStringsA [SHLWAPI.@]
4064 * Substitute folder names in a path with their corresponding environment
4068 * path [I] Buffer containing the path to unexpand.
4069 * buffer [O] Buffer to receive the unexpanded path.
4070 * buf_len [I] Size of pszBuf in characters.
4076 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4078 WCHAR bufferW
[MAX_PATH
], *pathW
;
4082 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4084 pathW
= heap_strdupAtoW(path
);
4085 if (!pathW
) return FALSE
;
4087 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4088 HeapFree(GetProcessHeap(), 0, pathW
);
4089 if (!ret
) return FALSE
;
4091 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4092 if (buf_len
< len
+ 1) return FALSE
;
4094 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4098 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4099 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4100 static const WCHAR computernameW
[] = {'%','C','O','M','P','U','T','E','R','N','A','M','E','%',0};
4101 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4102 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4103 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4104 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4110 WCHAR path
[MAX_PATH
];
4114 static void init_envvars_map(struct envvars_map
*map
)
4118 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4119 /* exclude null from length */
4120 if (map
->len
) map
->len
--;
4125 /*************************************************************************
4126 * PathUnExpandEnvStringsW [SHLWAPI.@]
4128 * Unicode version of PathUnExpandEnvStringsA.
4130 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4132 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4133 struct envvars_map
*match
= &null_var
, *cur
;
4134 struct envvars_map envvars
[] = {
4135 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4136 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4137 { computernameW
, sizeof(computernameW
)/sizeof(WCHAR
) },
4138 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4139 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4140 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4141 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4147 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4149 pathlen
= strlenW(path
);
4150 init_envvars_map(envvars
);
4154 /* path can't contain expanded value or value wasn't retrieved */
4155 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4161 if (cur
->len
> match
->len
)
4166 /* 'varlen' includes NULL termination char */
4167 needed
= match
->varlen
+ pathlen
- match
->len
;
4168 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4170 strcpyW(buffer
, match
->var
);
4171 strcatW(buffer
, &path
[match
->len
]);
4172 TRACE("ret %s\n", debugstr_w(buffer
));
4177 /*************************************************************************
4180 * Find localised or default web content in "%WINDOWS%\web\".
4183 * lpszFile [I] File name containing content to look for
4184 * lpszPath [O] Buffer to contain the full path to the file
4185 * dwPathLen [I] Length of lpszPath
4188 * Success: S_OK. lpszPath contains the full path to the content.
4189 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4191 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4193 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4196 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4198 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4200 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4201 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4205 /*************************************************************************
4208 * Unicode version of SHGetWebFolderFilePathA.
4210 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4212 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4213 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4214 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4215 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4216 DWORD dwLen
, dwFileLen
;
4217 LANGID lidSystem
, lidUser
;
4219 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4221 /* Get base directory for web content */
4222 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4223 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4226 dwFileLen
= strlenW(lpszFile
);
4228 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4229 return E_FAIL
; /* lpszPath too short */
4231 strcpyW(lpszPath
+dwLen
, szWeb
);
4233 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4235 lidSystem
= GetSystemDefaultUILanguage();
4236 lidUser
= GetUserDefaultUILanguage();
4238 if (lidSystem
!= lidUser
)
4240 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4242 /* Use localised content in the users UI language if present */
4243 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4244 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4245 if (PathFileExistsW(lpszPath
))
4250 /* Fall back to OS default installed content */
4251 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4252 if (PathFileExistsW(lpszPath
))
4257 #define PATH_CHAR_CLASS_LETTER 0x00000001
4258 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4259 #define PATH_CHAR_CLASS_DOT 0x00000004
4260 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4261 #define PATH_CHAR_CLASS_COLON 0x00000010
4262 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4263 #define PATH_CHAR_CLASS_COMMA 0x00000040
4264 #define PATH_CHAR_CLASS_SPACE 0x00000080
4265 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4266 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4268 #define PATH_CHAR_CLASS_INVALID 0x00000000
4269 #define PATH_CHAR_CLASS_ANY 0xffffffff
4271 static const DWORD SHELL_charclass
[] =
4273 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4274 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4275 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4276 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4277 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4278 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4279 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4280 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4281 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4282 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4283 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4284 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4285 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4286 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4287 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4288 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4289 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4290 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4291 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4292 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4293 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4294 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4295 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4296 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4297 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4298 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4299 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4300 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4301 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4302 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4303 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4304 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4305 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4306 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4307 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4308 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4309 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4310 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4311 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4312 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4313 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4314 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4315 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4316 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4317 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4318 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4319 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4320 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4321 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4322 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4323 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4324 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4325 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4326 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4327 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4328 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4329 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4330 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4331 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4332 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4333 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4334 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4335 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4336 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4339 /*************************************************************************
4342 * Check if an ASCII char is of a certain class
4344 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4346 if ((unsigned)c
> 0x7e)
4347 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4349 return class & SHELL_charclass
[(unsigned)c
];
4352 /*************************************************************************
4355 * Check if a Unicode char is of a certain class
4357 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4360 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4362 return class & SHELL_charclass
[c
];