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
25 int WINAPI
IsNetDrive(int drive
);
28 /* Get a function pointer from a DLL handle */
29 #define GET_FUNC(func, module, name, fail) \
32 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
33 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
34 if (!func) return fail; \
38 /* DLL handles for late bound calls */
39 static HMODULE SHLWAPI_hshell32
;
41 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
42 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
43 static fnpIsNetDrive pIsNetDrive
;
45 #endif /* __REACTOS__ */
48 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
50 static inline WCHAR
* heap_strdupAtoW(LPCSTR str
)
56 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
57 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
59 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
65 /*************************************************************************
66 * PathAppendA [SHLWAPI.@]
68 * Append one path to another.
71 * lpszPath [I/O] Initial part of path, and destination for output
72 * lpszAppend [I] Path to append
75 * Success: TRUE. lpszPath contains the newly created path.
76 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
79 * lpszAppend must contain at least one backslash ('\') if not NULL.
80 * Because PathCombineA() is used to join the paths, the resulting
81 * path is also canonicalized.
83 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
85 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
87 if (lpszPath
&& lpszAppend
)
89 if (!PathIsUNCA(lpszAppend
))
90 while (*lpszAppend
== '\\')
92 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
98 /*************************************************************************
99 * PathAppendW [SHLWAPI.@]
103 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
105 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
107 if (lpszPath
&& lpszAppend
)
109 if (!PathIsUNCW(lpszAppend
))
110 while (*lpszAppend
== '\\')
112 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
118 /*************************************************************************
119 * PathCombineA [SHLWAPI.@]
121 * Combine two paths together.
124 * lpszDest [O] Destination for combined path
125 * lpszDir [I] Directory path
126 * lpszFile [I] File path
129 * Success: The output path
130 * Failure: NULL, if inputs are invalid.
133 * lpszDest should be at least MAX_PATH in size, and may point to the same
134 * memory location as lpszDir. The combined path is canonicalised.
136 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
138 WCHAR szDest
[MAX_PATH
];
139 WCHAR szDir
[MAX_PATH
];
140 WCHAR szFile
[MAX_PATH
];
141 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
143 /* Invalid parameters */
146 if (!lpszDir
&& !lpszFile
)
150 if (!MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
))
154 if (!MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
))
157 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
158 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
166 /*************************************************************************
167 * PathCombineW [SHLWAPI.@]
171 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
173 WCHAR szTemp
[MAX_PATH
];
174 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
176 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
178 /* Invalid parameters */
181 if (!lpszDir
&& !lpszFile
)
187 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
190 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
192 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
194 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
197 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
210 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
213 PathStripToRootW(szTemp
);
214 lpszFile
++; /* Skip '\' */
216 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
221 strcatW(szTemp
, lpszFile
);
224 PathCanonicalizeW(lpszDest
, szTemp
);
228 /*************************************************************************
229 * PathAddBackslashA [SHLWAPI.@]
231 * Append a backslash ('\') to a path if one doesn't exist.
234 * lpszPath [I/O] The path to append a backslash to.
237 * Success: The position of the last backslash in the path.
238 * Failure: NULL, if lpszPath is NULL or the path is too large.
240 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
243 LPSTR prev
= lpszPath
;
245 TRACE("(%s)\n",debugstr_a(lpszPath
));
247 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
253 lpszPath
= CharNextA(prev
);
266 /*************************************************************************
267 * PathAddBackslashW [SHLWAPI.@]
269 * See PathAddBackslashA.
271 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
275 TRACE("(%s)\n",debugstr_w(lpszPath
));
277 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
283 if (lpszPath
[-1] != '\\')
292 /*************************************************************************
293 * PathBuildRootA [SHLWAPI.@]
295 * Create a root drive string (e.g. "A:\") from a drive number.
298 * lpszPath [O] Destination for the drive string
304 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
306 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
308 TRACE("(%p,%d)\n", lpszPath
, drive
);
310 if (lpszPath
&& drive
>= 0 && drive
< 26)
312 lpszPath
[0] = 'A' + drive
;
320 /*************************************************************************
321 * PathBuildRootW [SHLWAPI.@]
323 * See PathBuildRootA.
325 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
327 TRACE("(%p,%d)\n", lpszPath
, drive
);
329 if (lpszPath
&& drive
>= 0 && drive
< 26)
331 lpszPath
[0] = 'A' + drive
;
339 /*************************************************************************
340 * PathFindFileNameA [SHLWAPI.@]
342 * Locate the start of the file name in a path
345 * lpszPath [I] Path to search
348 * A pointer to the first character of the file name
350 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
352 LPCSTR lastSlash
= lpszPath
;
354 TRACE("(%s)\n",debugstr_a(lpszPath
));
356 while (lpszPath
&& *lpszPath
)
358 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
359 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
360 lastSlash
= lpszPath
+ 1;
361 lpszPath
= CharNextA(lpszPath
);
363 return (LPSTR
)lastSlash
;
366 /*************************************************************************
367 * PathFindFileNameW [SHLWAPI.@]
369 * See PathFindFileNameA.
371 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
373 LPCWSTR lastSlash
= lpszPath
;
375 TRACE("(%s)\n",debugstr_w(lpszPath
));
377 while (lpszPath
&& *lpszPath
)
379 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
380 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
381 lastSlash
= lpszPath
+ 1;
384 return (LPWSTR
)lastSlash
;
387 /*************************************************************************
388 * PathFindExtensionA [SHLWAPI.@]
390 * Locate the start of the file extension in a path
393 * lpszPath [I] The path to search
396 * A pointer to the first character of the extension, the end of
397 * the string if the path has no extension, or NULL If lpszPath is NULL
399 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
401 LPCSTR lastpoint
= NULL
;
403 TRACE("(%s)\n", debugstr_a(lpszPath
));
409 if (*lpszPath
== '\\' || *lpszPath
==' ')
411 else if (*lpszPath
== '.')
412 lastpoint
= lpszPath
;
413 lpszPath
= CharNextA(lpszPath
);
416 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
419 /*************************************************************************
420 * PathFindExtensionW [SHLWAPI.@]
422 * See PathFindExtensionA.
424 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
426 LPCWSTR lastpoint
= NULL
;
428 TRACE("(%s)\n", debugstr_w(lpszPath
));
434 if (*lpszPath
== '\\' || *lpszPath
==' ')
436 else if (*lpszPath
== '.')
437 lastpoint
= lpszPath
;
441 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
444 /*************************************************************************
445 * PathGetArgsA [SHLWAPI.@]
447 * Find the next argument in a string delimited by spaces.
450 * lpszPath [I] The string to search for arguments in
453 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
456 * Spaces in quoted strings are ignored as delimiters.
458 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
460 BOOL bSeenQuote
= FALSE
;
462 TRACE("(%s)\n",debugstr_a(lpszPath
));
468 if ((*lpszPath
==' ') && !bSeenQuote
)
469 return (LPSTR
)lpszPath
+ 1;
470 if (*lpszPath
== '"')
471 bSeenQuote
= !bSeenQuote
;
472 lpszPath
= CharNextA(lpszPath
);
475 return (LPSTR
)lpszPath
;
478 /*************************************************************************
479 * PathGetArgsW [SHLWAPI.@]
483 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
485 BOOL bSeenQuote
= FALSE
;
487 TRACE("(%s)\n",debugstr_w(lpszPath
));
493 if ((*lpszPath
==' ') && !bSeenQuote
)
494 return (LPWSTR
)lpszPath
+ 1;
495 if (*lpszPath
== '"')
496 bSeenQuote
= !bSeenQuote
;
500 return (LPWSTR
)lpszPath
;
503 /*************************************************************************
504 * PathGetDriveNumberA [SHLWAPI.@]
506 * Return the drive number from a path
509 * lpszPath [I] Path to get the drive number from
512 * Success: The drive number corresponding to the drive in the path
513 * Failure: -1, if lpszPath contains no valid drive
515 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
517 TRACE ("(%s)\n",debugstr_a(lpszPath
));
519 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
520 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
521 return tolower(*lpszPath
) - 'a';
525 /*************************************************************************
526 * PathGetDriveNumberW [SHLWAPI.@]
528 * See PathGetDriveNumberA.
530 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
532 TRACE ("(%s)\n",debugstr_w(lpszPath
));
536 WCHAR tl
= tolowerW(lpszPath
[0]);
537 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
543 /*************************************************************************
544 * PathRemoveFileSpecA [SHLWAPI.@]
546 * Remove the file specification from a path.
549 * lpszPath [I/O] Path to remove the file spec from
552 * TRUE If the path was valid and modified
555 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
557 LPSTR lpszFileSpec
= lpszPath
;
558 BOOL bModified
= FALSE
;
560 TRACE("(%s)\n",debugstr_a(lpszPath
));
564 /* Skip directory or UNC path */
565 if (*lpszPath
== '\\')
566 lpszFileSpec
= ++lpszPath
;
567 if (*lpszPath
== '\\')
568 lpszFileSpec
= ++lpszPath
;
572 if(*lpszPath
== '\\')
573 lpszFileSpec
= lpszPath
; /* Skip dir */
574 else if(*lpszPath
== ':')
576 lpszFileSpec
= ++lpszPath
; /* Skip drive */
577 if (*lpszPath
== '\\')
580 if (!(lpszPath
= CharNextA(lpszPath
)))
586 *lpszFileSpec
= '\0';
593 /*************************************************************************
594 * PathRemoveFileSpecW [SHLWAPI.@]
596 * See PathRemoveFileSpecA.
598 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
600 LPWSTR lpszFileSpec
= lpszPath
;
601 BOOL bModified
= FALSE
;
603 TRACE("(%s)\n",debugstr_w(lpszPath
));
607 /* Skip directory or UNC path */
608 if (*lpszPath
== '\\')
609 lpszFileSpec
= ++lpszPath
;
610 if (*lpszPath
== '\\')
611 lpszFileSpec
= ++lpszPath
;
615 if(*lpszPath
== '\\')
616 lpszFileSpec
= lpszPath
; /* Skip dir */
617 else if(*lpszPath
== ':')
619 lpszFileSpec
= ++lpszPath
; /* Skip drive */
620 if (*lpszPath
== '\\')
628 *lpszFileSpec
= '\0';
635 /*************************************************************************
636 * PathStripPathA [SHLWAPI.@]
638 * Remove the initial path from the beginning of a filename
641 * lpszPath [I/O] Path to remove the initial path from
646 void WINAPI
PathStripPathA(LPSTR lpszPath
)
648 TRACE("(%s)\n", debugstr_a(lpszPath
));
652 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
653 if(lpszFileName
!= lpszPath
)
654 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
658 /*************************************************************************
659 * PathStripPathW [SHLWAPI.@]
661 * See PathStripPathA.
663 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
667 TRACE("(%s)\n", debugstr_w(lpszPath
));
668 lpszFileName
= PathFindFileNameW(lpszPath
);
669 if(lpszFileName
!= lpszPath
)
670 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
673 /*************************************************************************
674 * PathStripToRootA [SHLWAPI.@]
676 * Reduce a path to its root.
679 * lpszPath [I/O] the path to reduce
682 * Success: TRUE if the stripped path is a root path
683 * Failure: FALSE if the path cannot be stripped or is NULL
685 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
687 TRACE("(%s)\n", debugstr_a(lpszPath
));
691 while(!PathIsRootA(lpszPath
))
692 if (!PathRemoveFileSpecA(lpszPath
))
697 /*************************************************************************
698 * PathStripToRootW [SHLWAPI.@]
700 * See PathStripToRootA.
702 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
704 TRACE("(%s)\n", debugstr_w(lpszPath
));
708 while(!PathIsRootW(lpszPath
))
709 if (!PathRemoveFileSpecW(lpszPath
))
714 /*************************************************************************
715 * PathRemoveArgsA [SHLWAPI.@]
717 * Strip space separated arguments from a path.
720 * lpszPath [I/O] Path to remove arguments from
725 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
727 TRACE("(%s)\n",debugstr_a(lpszPath
));
731 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
736 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
737 if(*lpszLastChar
== ' ')
738 *lpszLastChar
= '\0';
743 /*************************************************************************
744 * PathRemoveArgsW [SHLWAPI.@]
746 * See PathRemoveArgsA.
748 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
750 TRACE("(%s)\n",debugstr_w(lpszPath
));
754 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
755 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
760 /*************************************************************************
761 * PathRemoveExtensionA [SHLWAPI.@]
763 * Remove the file extension from a path
766 * lpszPath [I/O] Path to remove the extension from
769 * The NUL terminator must be written only if extension exists
770 * and if the pointed character is not already NUL.
775 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
777 TRACE("(%s)\n", debugstr_a(lpszPath
));
781 lpszPath
= PathFindExtensionA(lpszPath
);
782 if (lpszPath
&& *lpszPath
!= '\0')
787 /*************************************************************************
788 * PathRemoveExtensionW [SHLWAPI.@]
790 * See PathRemoveExtensionA.
792 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
794 TRACE("(%s)\n", debugstr_w(lpszPath
));
798 lpszPath
= PathFindExtensionW(lpszPath
);
799 if (lpszPath
&& *lpszPath
!= '\0')
804 /*************************************************************************
805 * PathRemoveBackslashA [SHLWAPI.@]
807 * Remove a trailing backslash from a path.
810 * lpszPath [I/O] Path to remove backslash from
813 * Success: A pointer to the end of the path
814 * Failure: NULL, if lpszPath is NULL
816 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
820 TRACE("(%s)\n", debugstr_a(lpszPath
));
824 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
825 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
831 /*************************************************************************
832 * PathRemoveBackslashW [SHLWAPI.@]
834 * See PathRemoveBackslashA.
836 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
838 LPWSTR szTemp
= NULL
;
840 TRACE("(%s)\n", debugstr_w(lpszPath
));
844 szTemp
= lpszPath
+ strlenW(lpszPath
);
845 if (szTemp
> lpszPath
) szTemp
--;
846 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
852 /*************************************************************************
853 * PathRemoveBlanksA [SHLWAPI.@]
855 * Remove Spaces from the start and end of a path.
858 * lpszPath [I/O] Path to strip blanks from
863 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
865 TRACE("(%s)\n", debugstr_a(lpszPath
));
867 if(lpszPath
&& *lpszPath
)
869 LPSTR start
= lpszPath
;
871 while (*lpszPath
== ' ')
872 lpszPath
= CharNextA(lpszPath
);
875 *start
++ = *lpszPath
++;
877 if (start
!= lpszPath
)
878 while (start
[-1] == ' ')
884 /*************************************************************************
885 * PathRemoveBlanksW [SHLWAPI.@]
887 * See PathRemoveBlanksA.
889 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
891 TRACE("(%s)\n", debugstr_w(lpszPath
));
893 if(lpszPath
&& *lpszPath
)
895 LPWSTR start
= lpszPath
;
897 while (*lpszPath
== ' ')
901 *start
++ = *lpszPath
++;
903 if (start
!= lpszPath
)
904 while (start
[-1] == ' ')
910 /*************************************************************************
911 * PathQuoteSpacesA [SHLWAPI.@]
913 * Surround a path containing spaces in quotes.
916 * lpszPath [I/O] Path to quote
922 * The path is not changed if it is invalid or has no spaces.
924 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
926 TRACE("(%s)\n", debugstr_a(lpszPath
));
928 if(lpszPath
&& StrChrA(lpszPath
,' '))
930 size_t iLen
= strlen(lpszPath
) + 1;
932 if (iLen
+ 2 < MAX_PATH
)
934 memmove(lpszPath
+ 1, lpszPath
, iLen
);
936 lpszPath
[iLen
] = '"';
937 lpszPath
[iLen
+ 1] = '\0';
942 /*************************************************************************
943 * PathQuoteSpacesW [SHLWAPI.@]
945 * See PathQuoteSpacesA.
947 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
949 TRACE("(%s)\n", debugstr_w(lpszPath
));
951 if(lpszPath
&& StrChrW(lpszPath
,' '))
953 int iLen
= strlenW(lpszPath
) + 1;
955 if (iLen
+ 2 < MAX_PATH
)
957 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
959 lpszPath
[iLen
] = '"';
960 lpszPath
[iLen
+ 1] = '\0';
965 /*************************************************************************
966 * PathUnquoteSpacesA [SHLWAPI.@]
968 * Remove quotes ("") from around a path, if present.
971 * lpszPath [I/O] Path to strip quotes from
977 * If the path contains a single quote only, an empty string will result.
978 * Otherwise quotes are only removed if they appear at the start and end
981 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
983 TRACE("(%s)\n", debugstr_a(lpszPath
));
985 if (lpszPath
&& *lpszPath
== '"')
987 DWORD dwLen
= strlen(lpszPath
) - 1;
989 if (lpszPath
[dwLen
] == '"')
991 lpszPath
[dwLen
] = '\0';
992 for (; *lpszPath
; lpszPath
++)
993 *lpszPath
= lpszPath
[1];
998 /*************************************************************************
999 * PathUnquoteSpacesW [SHLWAPI.@]
1001 * See PathUnquoteSpacesA.
1003 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
1005 TRACE("(%s)\n", debugstr_w(lpszPath
));
1007 if (lpszPath
&& *lpszPath
== '"')
1009 DWORD dwLen
= strlenW(lpszPath
) - 1;
1011 if (lpszPath
[dwLen
] == '"')
1013 lpszPath
[dwLen
] = '\0';
1014 for (; *lpszPath
; lpszPath
++)
1015 *lpszPath
= lpszPath
[1];
1020 /*************************************************************************
1021 * PathParseIconLocationA [SHLWAPI.@]
1023 * Parse the location of an icon from a path.
1026 * lpszPath [I/O] The path to parse the icon location from.
1029 * Success: The number of the icon
1030 * Failure: 0 if the path does not contain an icon location or is NULL
1033 * The path has surrounding quotes and spaces removed regardless
1034 * of whether the call succeeds or not.
1036 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1041 TRACE("(%s)\n", debugstr_a(lpszPath
));
1045 if ((lpszComma
= strchr(lpszPath
, ',')))
1047 *lpszComma
++ = '\0';
1048 iRet
= StrToIntA(lpszComma
);
1050 PathUnquoteSpacesA(lpszPath
);
1051 PathRemoveBlanksA(lpszPath
);
1056 /*************************************************************************
1057 * PathParseIconLocationW [SHLWAPI.@]
1059 * See PathParseIconLocationA.
1061 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1066 TRACE("(%s)\n", debugstr_w(lpszPath
));
1070 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1072 *lpszComma
++ = '\0';
1073 iRet
= StrToIntW(lpszComma
);
1075 PathUnquoteSpacesW(lpszPath
);
1076 PathRemoveBlanksW(lpszPath
);
1081 /*************************************************************************
1084 * Unicode version of PathFileExistsDefExtA.
1086 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1088 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1089 { '.', 'c', 'o', 'm', 0},
1090 { '.', 'e', 'x', 'e', 0},
1091 { '.', 'b', 'a', 't', 0},
1092 { '.', 'l', 'n', 'k', 0},
1093 { '.', 'c', 'm', 'd', 0},
1096 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1098 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1103 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1104 if (!*szExt
|| dwWhich
& 0x40)
1107 int iLen
= lstrlenW(lpszPath
);
1108 if (iLen
> (MAX_PATH
- 5))
1110 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1112 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1113 if (PathFileExistsW(lpszPath
))
1118 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1122 return PathFileExistsW(lpszPath
);
1125 /*************************************************************************
1128 * Determine if a file exists locally and is of an executable type.
1131 * lpszPath [I/O] File to search for
1132 * dwWhich [I] Type of executable to search for
1135 * TRUE If the file was found. lpszPath contains the file name.
1139 * lpszPath is modified in place and must be at least MAX_PATH in length.
1140 * If the function returns FALSE, the path is modified to its original state.
1141 * If the given path contains an extension or dwWhich is 0, executable
1142 * extensions are not checked.
1144 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1145 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1146 * their own developers exclusive use. Monopoly, anyone?
1148 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1152 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1156 WCHAR szPath
[MAX_PATH
];
1157 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1158 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1160 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1165 /*************************************************************************
1166 * SHLWAPI_PathFindInOtherDirs
1168 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1170 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1172 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1173 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1177 WCHAR buff
[MAX_PATH
];
1179 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1181 /* Try system directories */
1182 GetSystemDirectoryW(buff
, MAX_PATH
);
1183 if (!PathAppendW(buff
, lpszFile
))
1185 if (PathFileExistsDefExtW(buff
, dwWhich
))
1187 strcpyW(lpszFile
, buff
);
1190 GetWindowsDirectoryW(buff
, MAX_PATH
);
1191 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1193 if (PathFileExistsDefExtW(buff
, dwWhich
))
1195 strcpyW(lpszFile
, buff
);
1198 GetWindowsDirectoryW(buff
, MAX_PATH
);
1199 if (!PathAppendW(buff
, lpszFile
))
1201 if (PathFileExistsDefExtW(buff
, dwWhich
))
1203 strcpyW(lpszFile
, buff
);
1206 /* Try dirs listed in %PATH% */
1207 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1209 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1212 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1213 lpszCurr
= lpszPATH
;
1216 LPCWSTR lpszEnd
= lpszCurr
;
1217 LPWSTR pBuff
= buff
;
1219 while (*lpszEnd
== ' ')
1221 while (*lpszEnd
&& *lpszEnd
!= ';')
1222 *pBuff
++ = *lpszEnd
++;
1226 lpszCurr
= lpszEnd
+ 1;
1228 lpszCurr
= NULL
; /* Last Path, terminate after this */
1230 if (!PathAppendW(buff
, lpszFile
))
1232 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1235 if (PathFileExistsDefExtW(buff
, dwWhich
))
1237 strcpyW(lpszFile
, buff
);
1238 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1242 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1246 /*************************************************************************
1249 * Search a range of paths for a specific type of executable.
1252 * lpszFile [I/O] File to search for
1253 * lppszOtherDirs [I] Other directories to look in
1254 * dwWhich [I] Type of executable to search for
1257 * Success: TRUE. The path to the executable is stored in lpszFile.
1258 * Failure: FALSE. The path to the executable is unchanged.
1260 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1262 WCHAR szFile
[MAX_PATH
];
1263 WCHAR buff
[MAX_PATH
];
1265 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1267 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1270 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1272 /* Search provided directories first */
1273 if (lppszOtherDirs
&& *lppszOtherDirs
)
1275 WCHAR szOther
[MAX_PATH
];
1276 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1278 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1280 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1281 PathCombineW(buff
, szOther
, szFile
);
1282 if (PathFileExistsDefExtW(buff
, dwWhich
))
1284 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1290 /* Not found, try system and path dirs */
1291 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1293 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1299 /*************************************************************************
1302 * Unicode version of PathFindOnPathExA.
1304 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1306 WCHAR buff
[MAX_PATH
];
1308 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1310 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1313 /* Search provided directories first */
1314 if (lppszOtherDirs
&& *lppszOtherDirs
)
1316 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1317 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1319 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1320 if (PathFileExistsDefExtW(buff
, dwWhich
))
1322 strcpyW(lpszFile
, buff
);
1328 /* Not found, try system and path dirs */
1329 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1332 /*************************************************************************
1333 * PathFindOnPathA [SHLWAPI.@]
1335 * Search a range of paths for an executable.
1338 * lpszFile [I/O] File to search for
1339 * lppszOtherDirs [I] Other directories to look in
1342 * Success: TRUE. The path to the executable is stored in lpszFile.
1343 * Failure: FALSE. The path to the executable is unchanged.
1345 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1347 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1348 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1351 /*************************************************************************
1352 * PathFindOnPathW [SHLWAPI.@]
1354 * See PathFindOnPathA.
1356 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1358 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1359 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1362 /*************************************************************************
1363 * PathCompactPathExA [SHLWAPI.@]
1365 * Compact a path into a given number of characters.
1368 * lpszDest [O] Destination for compacted path
1369 * lpszPath [I] Source path
1370 * cchMax [I] Maximum size of compacted path
1371 * dwFlags [I] Reserved
1374 * Success: TRUE. The compacted path is written to lpszDest.
1375 * Failure: FALSE. lpszPath is undefined.
1378 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1380 * The Win32 version of this function contains a bug: When cchMax == 7,
1381 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1384 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1385 * because Win32 will insert a "\" in lpszDest, even if one is
1386 * not present in the original path.
1388 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1389 UINT cchMax
, DWORD dwFlags
)
1393 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1395 if (lpszPath
&& lpszDest
)
1397 WCHAR szPath
[MAX_PATH
];
1398 WCHAR szDest
[MAX_PATH
];
1400 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1402 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1403 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1408 /*************************************************************************
1409 * PathCompactPathExW [SHLWAPI.@]
1411 * See PathCompactPathExA.
1413 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1414 UINT cchMax
, DWORD dwFlags
)
1416 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1418 DWORD dwLen
, dwFileLen
= 0;
1420 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1427 WARN("Invalid lpszDest would crash under Win32!\n");
1436 dwLen
= strlenW(lpszPath
) + 1;
1440 /* Don't need to compact */
1441 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1445 /* Path must be compacted to fit into lpszDest */
1446 lpszFile
= PathFindFileNameW(lpszPath
);
1447 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1449 if (dwFileLen
== dwLen
)
1451 /* No root in psth */
1454 while (--cchMax
> 0) /* No room left for anything but ellipses */
1459 /* Compact the file name with ellipses at the end */
1461 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1462 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1465 /* We have a root in the path */
1466 lpszFile
--; /* Start compacted filename with the path separator */
1469 if (dwFileLen
+ 3 > cchMax
)
1471 /* Compact the file name */
1474 while (--cchMax
> 0) /* No room left for anything but ellipses */
1479 strcpyW(lpszDest
, szEllipses
);
1482 *lpszDest
++ = *lpszFile
++;
1485 while (--cchMax
> 0) /* No room left for anything but ellipses */
1491 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1492 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1496 /* Only the root needs to be Compacted */
1497 dwLen
= cchMax
- dwFileLen
- 3;
1498 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1499 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1500 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1504 /*************************************************************************
1505 * PathIsRelativeA [SHLWAPI.@]
1507 * Determine if a path is a relative path.
1510 * lpszPath [I] Path to check
1513 * TRUE: The path is relative, or is invalid.
1514 * FALSE: The path is not relative.
1516 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1518 TRACE("(%s)\n",debugstr_a(lpszPath
));
1520 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1522 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1527 /*************************************************************************
1528 * PathIsRelativeW [SHLWAPI.@]
1530 * See PathIsRelativeA.
1532 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1534 TRACE("(%s)\n",debugstr_w(lpszPath
));
1536 if (!lpszPath
|| !*lpszPath
)
1538 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1543 /*************************************************************************
1544 * PathIsRootA [SHLWAPI.@]
1546 * Determine if a path is a root path.
1549 * lpszPath [I] Path to check
1552 * TRUE If lpszPath is valid and a root path,
1555 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1557 TRACE("(%s)\n", debugstr_a(lpszPath
));
1559 if (lpszPath
&& *lpszPath
)
1561 if (*lpszPath
== '\\')
1564 return TRUE
; /* \ */
1565 else if (lpszPath
[1]=='\\')
1567 BOOL bSeenSlash
= FALSE
;
1570 /* Check for UNC root path */
1573 if (*lpszPath
== '\\')
1579 lpszPath
= CharNextA(lpszPath
);
1584 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1585 return TRUE
; /* X:\ */
1590 /*************************************************************************
1591 * PathIsRootW [SHLWAPI.@]
1595 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1597 TRACE("(%s)\n", debugstr_w(lpszPath
));
1599 if (lpszPath
&& *lpszPath
)
1601 if (*lpszPath
== '\\')
1604 return TRUE
; /* \ */
1605 else if (lpszPath
[1]=='\\')
1607 BOOL bSeenSlash
= FALSE
;
1610 /* Check for UNC root path */
1613 if (*lpszPath
== '\\')
1624 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1625 return TRUE
; /* X:\ */
1630 /*************************************************************************
1631 * PathIsDirectoryA [SHLWAPI.@]
1633 * Determine if a path is a valid directory
1636 * lpszPath [I] Path to check.
1639 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1640 * FALSE if lpszPath is invalid or not a directory.
1643 * Although this function is prototyped as returning a BOOL, it returns
1644 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1646 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1651 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1655 TRACE("(%s)\n", debugstr_a(lpszPath
));
1657 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1660 if (PathIsUNCServerShareA(lpszPath
))
1662 FIXME("UNC Server Share not yet supported - FAILING\n");
1666 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1668 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1671 /*************************************************************************
1672 * PathIsDirectoryW [SHLWAPI.@]
1674 * See PathIsDirectoryA.
1676 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1680 TRACE("(%s)\n", debugstr_w(lpszPath
));
1682 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1685 if (PathIsUNCServerShareW(lpszPath
))
1687 FIXME("UNC Server Share not yet supported - FAILING\n");
1691 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1693 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1696 /*************************************************************************
1697 * PathFileExistsA [SHLWAPI.@]
1699 * Determine if a file exists.
1702 * lpszPath [I] Path to check
1705 * TRUE If the file exists and is readable
1708 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1713 TRACE("(%s)\n",debugstr_a(lpszPath
));
1718 /* Prevent a dialog box if path is on a disk that has been ejected. */
1719 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1720 dwAttr
= GetFileAttributesA(lpszPath
);
1721 SetErrorMode(iPrevErrMode
);
1722 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1725 /*************************************************************************
1726 * PathFileExistsW [SHLWAPI.@]
1728 * See PathFileExistsA.
1730 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1735 TRACE("(%s)\n",debugstr_w(lpszPath
));
1740 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1741 dwAttr
= GetFileAttributesW(lpszPath
);
1742 SetErrorMode(iPrevErrMode
);
1743 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1746 /*************************************************************************
1747 * PathFileExistsAndAttributesA [SHLWAPI.445]
1749 * Determine if a file exists.
1752 * lpszPath [I] Path to check
1753 * dwAttr [O] attributes of file
1756 * TRUE If the file exists and is readable
1759 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1764 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1767 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1772 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1773 dwVal
= GetFileAttributesA(lpszPath
);
1774 SetErrorMode(iPrevErrMode
);
1777 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1780 /*************************************************************************
1781 * PathFileExistsAndAttributesW [SHLWAPI.446]
1783 * See PathFileExistsA.
1785 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1790 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1795 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1796 dwVal
= GetFileAttributesW(lpszPath
);
1797 SetErrorMode(iPrevErrMode
);
1800 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1803 /*************************************************************************
1804 * PathMatchSingleMaskA [internal]
1806 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1808 while (*name
&& *mask
&& *mask
!=';')
1814 if (PathMatchSingleMaskA(name
,mask
+1))
1815 return TRUE
; /* try substrings */
1820 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1823 name
= CharNextA(name
);
1824 mask
= CharNextA(mask
);
1829 while (*mask
== '*')
1831 if (!*mask
|| *mask
== ';')
1837 /*************************************************************************
1838 * PathMatchSingleMaskW [internal]
1840 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1842 while (*name
&& *mask
&& *mask
!= ';')
1848 if (PathMatchSingleMaskW(name
,mask
+1))
1849 return TRUE
; /* try substrings */
1854 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1862 while (*mask
== '*')
1864 if (!*mask
|| *mask
== ';')
1870 /*************************************************************************
1871 * PathMatchSpecA [SHLWAPI.@]
1873 * Determine if a path matches one or more search masks.
1876 * lpszPath [I] Path to check
1877 * lpszMask [I] Search mask(s)
1880 * TRUE If lpszPath is valid and is matched
1884 * Multiple search masks may be given if they are separated by ";". The
1885 * pattern "*.*" is treated specially in that it matches all paths (for
1886 * backwards compatibility with DOS).
1888 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1890 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1892 if (!lstrcmpA(lpszMask
, "*.*"))
1893 return TRUE
; /* Matches every path */
1897 while (*lpszMask
== ' ')
1898 lpszMask
++; /* Eat leading spaces */
1900 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1901 return TRUE
; /* Matches the current mask */
1903 while (*lpszMask
&& *lpszMask
!= ';')
1904 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1906 if (*lpszMask
== ';')
1912 /*************************************************************************
1913 * PathMatchSpecW [SHLWAPI.@]
1915 * See PathMatchSpecA.
1917 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1919 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1921 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1923 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1924 return TRUE
; /* Matches every path */
1928 while (*lpszMask
== ' ')
1929 lpszMask
++; /* Eat leading spaces */
1931 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1932 return TRUE
; /* Matches the current path */
1934 while (*lpszMask
&& *lpszMask
!= ';')
1935 lpszMask
++; /* masks separated by ';' */
1937 if (*lpszMask
== ';')
1943 /*************************************************************************
1944 * PathIsSameRootA [SHLWAPI.@]
1946 * Determine if two paths share the same root.
1949 * lpszPath1 [I] Source path
1950 * lpszPath2 [I] Path to compare with
1953 * TRUE If both paths are valid and share the same root.
1954 * FALSE If either path is invalid or the paths do not share the same root.
1956 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1961 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1963 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1966 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1967 if (lpszStart
- lpszPath1
> dwLen
)
1968 return FALSE
; /* Paths not common up to length of the root */
1972 /*************************************************************************
1973 * PathIsSameRootW [SHLWAPI.@]
1975 * See PathIsSameRootA.
1977 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1982 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1984 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1987 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1988 if (lpszStart
- lpszPath1
> dwLen
)
1989 return FALSE
; /* Paths not common up to length of the root */
1993 /*************************************************************************
1994 * PathIsContentTypeA [SHLWAPI.@]
1996 * Determine if a file is of a given registered content type.
1999 * lpszPath [I] File to check
2000 * lpszContentType [I] Content type to check for
2003 * TRUE If lpszPath is a given registered content type,
2007 * This function looks up the registered content type for lpszPath. If
2008 * a content type is registered, it is compared (case insensitively) to
2009 * lpszContentType. Only if this matches does the function succeed.
2011 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2015 char szBuff
[MAX_PATH
];
2017 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2019 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2020 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2021 REG_NONE
, szBuff
, &dwDummy
) &&
2022 !strcasecmp(lpszContentType
, szBuff
))
2029 /*************************************************************************
2030 * PathIsContentTypeW [SHLWAPI.@]
2032 * See PathIsContentTypeA.
2034 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2036 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2039 WCHAR szBuff
[MAX_PATH
];
2041 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2043 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2044 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2045 REG_NONE
, szBuff
, &dwDummy
) &&
2046 !strcmpiW(lpszContentType
, szBuff
))
2053 /*************************************************************************
2054 * PathIsFileSpecA [SHLWAPI.@]
2056 * Determine if a path is a file specification.
2059 * lpszPath [I] Path to check
2062 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2065 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2067 TRACE("(%s)\n", debugstr_a(lpszPath
));
2074 if (*lpszPath
== '\\' || *lpszPath
== ':')
2076 lpszPath
= CharNextA(lpszPath
);
2081 /*************************************************************************
2082 * PathIsFileSpecW [SHLWAPI.@]
2084 * See PathIsFileSpecA.
2086 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2088 TRACE("(%s)\n", debugstr_w(lpszPath
));
2095 if (*lpszPath
== '\\' || *lpszPath
== ':')
2102 /*************************************************************************
2103 * PathIsPrefixA [SHLWAPI.@]
2105 * Determine if a path is a prefix of another.
2108 * lpszPrefix [I] Prefix
2109 * lpszPath [I] Path to check
2112 * TRUE If lpszPath has lpszPrefix as its prefix,
2113 * FALSE If either path is NULL or lpszPrefix is not a prefix
2115 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2117 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2119 if (lpszPrefix
&& lpszPath
&&
2120 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2125 /*************************************************************************
2126 * PathIsPrefixW [SHLWAPI.@]
2128 * See PathIsPrefixA.
2130 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2132 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2134 if (lpszPrefix
&& lpszPath
&&
2135 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2140 /*************************************************************************
2141 * PathIsSystemFolderA [SHLWAPI.@]
2143 * Determine if a path or file attributes are a system folder.
2146 * lpszPath [I] Path to check.
2147 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2150 * TRUE If lpszPath or dwAttrib are a system folder.
2151 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2153 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2155 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2157 if (lpszPath
&& *lpszPath
)
2158 dwAttrib
= GetFileAttributesA(lpszPath
);
2160 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2161 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2166 /*************************************************************************
2167 * PathIsSystemFolderW [SHLWAPI.@]
2169 * See PathIsSystemFolderA.
2171 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2173 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2175 if (lpszPath
&& *lpszPath
)
2176 dwAttrib
= GetFileAttributesW(lpszPath
);
2178 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2179 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2184 /*************************************************************************
2185 * PathIsUNCA [SHLWAPI.@]
2187 * Determine if a path is in UNC format.
2190 * lpszPath [I] Path to check
2193 * TRUE: The path is UNC.
2194 * FALSE: The path is not UNC or is NULL.
2196 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2198 TRACE("(%s)\n",debugstr_a(lpszPath
));
2201 * On Windows 2003, tests show that strings starting with "\\?" are
2202 * considered UNC, while on Windows Vista+ this is not the case anymore.
2204 // #ifdef __REACTOS__
2205 #if (WINVER >= _WIN32_WINNT_VISTA)
2206 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2208 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2214 /*************************************************************************
2215 * PathIsUNCW [SHLWAPI.@]
2219 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2221 TRACE("(%s)\n",debugstr_w(lpszPath
));
2224 * On Windows 2003, tests show that strings starting with "\\?" are
2225 * considered UNC, while on Windows Vista+ this is not the case anymore.
2227 // #ifdef __REACTOS__
2228 #if (WINVER >= _WIN32_WINNT_VISTA)
2229 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2231 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2237 /*************************************************************************
2238 * PathIsUNCServerA [SHLWAPI.@]
2240 * Determine if a path is a UNC server name ("\\SHARENAME").
2243 * lpszPath [I] Path to check.
2246 * TRUE If lpszPath is a valid UNC server name.
2250 * This routine is bug compatible with Win32: Server names with a
2251 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2252 * Fixing this bug may break other shlwapi functions!
2254 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2256 TRACE("(%s)\n", debugstr_a(lpszPath
));
2258 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2262 if (*lpszPath
== '\\')
2264 lpszPath
= CharNextA(lpszPath
);
2271 /*************************************************************************
2272 * PathIsUNCServerW [SHLWAPI.@]
2274 * See PathIsUNCServerA.
2276 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2278 TRACE("(%s)\n", debugstr_w(lpszPath
));
2280 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2282 return !strchrW( lpszPath
+ 2, '\\' );
2287 /*************************************************************************
2288 * PathIsUNCServerShareA [SHLWAPI.@]
2290 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2293 * lpszPath [I] Path to check.
2296 * TRUE If lpszPath is a valid UNC server share.
2300 * This routine is bug compatible with Win32: Server shares with a
2301 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2302 * Fixing this bug may break other shlwapi functions!
2304 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2306 TRACE("(%s)\n", debugstr_a(lpszPath
));
2308 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2310 BOOL bSeenSlash
= FALSE
;
2313 if (*lpszPath
== '\\')
2319 lpszPath
= CharNextA(lpszPath
);
2326 /*************************************************************************
2327 * PathIsUNCServerShareW [SHLWAPI.@]
2329 * See PathIsUNCServerShareA.
2331 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2333 TRACE("(%s)\n", debugstr_w(lpszPath
));
2335 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2337 BOOL bSeenSlash
= FALSE
;
2340 if (*lpszPath
== '\\')
2353 /*************************************************************************
2354 * PathCanonicalizeA [SHLWAPI.@]
2356 * Convert a path to its canonical form.
2359 * lpszBuf [O] Output path
2360 * lpszPath [I] Path to canonicalize
2363 * Success: TRUE. lpszBuf contains the output path,
2364 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2366 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2370 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2375 if (!lpszBuf
|| !lpszPath
)
2376 SetLastError(ERROR_INVALID_PARAMETER
);
2379 WCHAR szPath
[MAX_PATH
];
2380 WCHAR szBuff
[MAX_PATH
];
2381 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2384 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2387 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2388 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2394 /*************************************************************************
2395 * PathCanonicalizeW [SHLWAPI.@]
2397 * See PathCanonicalizeA.
2399 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2401 LPWSTR lpszDst
= lpszBuf
;
2402 LPCWSTR lpszSrc
= lpszPath
;
2404 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2409 if (!lpszBuf
|| !lpszPath
)
2411 SetLastError(ERROR_INVALID_PARAMETER
);
2422 /* Copy path root */
2423 if (*lpszSrc
== '\\')
2425 *lpszDst
++ = *lpszSrc
++;
2427 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2430 *lpszDst
++ = *lpszSrc
++;
2431 *lpszDst
++ = *lpszSrc
++;
2432 if (*lpszSrc
== '\\')
2433 *lpszDst
++ = *lpszSrc
++;
2436 /* Canonicalize the rest of the path */
2439 if (*lpszSrc
== '.')
2441 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2443 lpszSrc
+= 2; /* Skip .\ */
2445 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2447 /* \.. backs up a directory, over the root if it has no \ following X:.
2448 * .. is ignored if it would remove a UNC server name or initial \\
2450 if (lpszDst
!= lpszBuf
)
2452 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2453 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2454 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2456 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2459 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2461 if (*lpszDst
== '\\')
2462 lpszDst
++; /* Reset to last '\' */
2464 lpszDst
= lpszBuf
; /* Start path again from new root */
2466 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2469 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2471 if (lpszDst
== lpszBuf
)
2477 lpszSrc
+= 2; /* Skip .. in src path */
2480 *lpszDst
++ = *lpszSrc
++;
2483 *lpszDst
++ = *lpszSrc
++;
2485 /* Append \ to naked drive specs */
2486 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2492 /*************************************************************************
2493 * PathFindNextComponentA [SHLWAPI.@]
2495 * Find the next component in a path.
2498 * lpszPath [I] Path to find next component in
2501 * Success: A pointer to the next component, or the end of the string.
2502 * Failure: NULL, If lpszPath is invalid
2505 * A 'component' is either a backslash character (\) or UNC marker (\\).
2506 * Because of this, relative paths (e.g "c:foo") are regarded as having
2507 * only one component.
2509 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2513 TRACE("(%s)\n", debugstr_a(lpszPath
));
2515 if(!lpszPath
|| !*lpszPath
)
2518 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2520 if (lpszSlash
[1] == '\\')
2522 return lpszSlash
+ 1;
2524 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2527 /*************************************************************************
2528 * PathFindNextComponentW [SHLWAPI.@]
2530 * See PathFindNextComponentA.
2532 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2536 TRACE("(%s)\n", debugstr_w(lpszPath
));
2538 if(!lpszPath
|| !*lpszPath
)
2541 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2543 if (lpszSlash
[1] == '\\')
2545 return lpszSlash
+ 1;
2547 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2550 /*************************************************************************
2551 * PathAddExtensionA [SHLWAPI.@]
2553 * Add a file extension to a path
2556 * lpszPath [I/O] Path to add extension to
2557 * lpszExtension [I] Extension to add to lpszPath
2560 * TRUE If the path was modified,
2561 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2562 * extension already, or the new path length is too big.
2565 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2566 * does not do this, so the behaviour was removed.
2568 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2572 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2574 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2577 dwLen
= strlen(lpszPath
);
2579 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2582 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2586 /*************************************************************************
2587 * PathAddExtensionW [SHLWAPI.@]
2589 * See PathAddExtensionA.
2591 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2595 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2597 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2600 dwLen
= strlenW(lpszPath
);
2602 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2605 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2609 /*************************************************************************
2610 * PathMakePrettyA [SHLWAPI.@]
2612 * Convert an uppercase DOS filename into lowercase.
2615 * lpszPath [I/O] Path to convert.
2618 * TRUE If the path was an uppercase DOS path and was converted,
2621 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2623 LPSTR pszIter
= lpszPath
;
2625 TRACE("(%s)\n", debugstr_a(lpszPath
));
2634 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2635 return FALSE
; /* Not DOS path */
2638 pszIter
= lpszPath
+ 1;
2641 *pszIter
= tolower(*pszIter
);
2648 /*************************************************************************
2649 * PathMakePrettyW [SHLWAPI.@]
2651 * See PathMakePrettyA.
2653 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2655 LPWSTR pszIter
= lpszPath
;
2657 TRACE("(%s)\n", debugstr_w(lpszPath
));
2666 if (islowerW(*pszIter
))
2667 return FALSE
; /* Not DOS path */
2670 pszIter
= lpszPath
+ 1;
2673 *pszIter
= tolowerW(*pszIter
);
2680 /*************************************************************************
2681 * PathCommonPrefixA [SHLWAPI.@]
2683 * Determine the length of the common prefix between two paths.
2686 * lpszFile1 [I] First path for comparison
2687 * lpszFile2 [I] Second path for comparison
2688 * achPath [O] Destination for common prefix string
2691 * The length of the common prefix. This is 0 if there is no common
2692 * prefix between the paths or if any parameters are invalid. If the prefix
2693 * is non-zero and achPath is not NULL, achPath is filled with the common
2694 * part of the prefix and NUL terminated.
2697 * A common prefix of 2 is always returned as 3. It is thus possible for
2698 * the length returned to be invalid (i.e. Longer than one or both of the
2699 * strings given as parameters). This Win32 behaviour has been implemented
2700 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2701 * To work around this when using this function, always check that the byte
2702 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2704 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2707 LPCSTR lpszIter1
= lpszFile1
;
2708 LPCSTR lpszIter2
= lpszFile2
;
2710 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2715 if (!lpszFile1
|| !lpszFile2
)
2718 /* Handle roots first */
2719 if (PathIsUNCA(lpszFile1
))
2721 if (!PathIsUNCA(lpszFile2
))
2726 else if (PathIsUNCA(lpszFile2
))
2727 return 0; /* Know already lpszFile1 is not UNC */
2732 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2733 (!*lpszIter2
|| *lpszIter2
== '\\'))
2734 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2736 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2737 break; /* Strings differ at this point */
2744 iLen
++; /* Feature/Bug compatible with Win32 */
2746 if (iLen
&& achPath
)
2748 memcpy(achPath
,lpszFile1
,iLen
);
2749 achPath
[iLen
] = '\0';
2754 /*************************************************************************
2755 * PathCommonPrefixW [SHLWAPI.@]
2757 * See PathCommonPrefixA.
2759 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2762 LPCWSTR lpszIter1
= lpszFile1
;
2763 LPCWSTR lpszIter2
= lpszFile2
;
2765 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2770 if (!lpszFile1
|| !lpszFile2
)
2773 /* Handle roots first */
2774 if (PathIsUNCW(lpszFile1
))
2776 if (!PathIsUNCW(lpszFile2
))
2781 else if (PathIsUNCW(lpszFile2
))
2782 return 0; /* Know already lpszFile1 is not UNC */
2787 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2788 (!*lpszIter2
|| *lpszIter2
== '\\'))
2789 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2791 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2792 break; /* Strings differ at this point */
2799 iLen
++; /* Feature/Bug compatible with Win32 */
2801 if (iLen
&& achPath
)
2803 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2804 achPath
[iLen
] = '\0';
2809 /*************************************************************************
2810 * PathCompactPathA [SHLWAPI.@]
2812 * Make a path fit into a given width when printed to a DC.
2815 * hDc [I] Destination DC
2816 * lpszPath [I/O] Path to be printed to hDc
2817 * dx [I] Desired width
2820 * TRUE If the path was modified/went well.
2823 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2827 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2831 WCHAR szPath
[MAX_PATH
];
2832 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2833 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2834 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2839 /*************************************************************************
2840 * PathCompactPathW [SHLWAPI.@]
2842 * See PathCompactPathA.
2844 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2846 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2849 WCHAR buff
[MAX_PATH
];
2853 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2859 hdc
= hDC
= GetDC(0);
2861 /* Get the length of the whole path */
2862 dwLen
= strlenW(lpszPath
);
2863 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2865 if ((UINT
)size
.cx
> dx
)
2867 /* Path too big, must reduce it */
2869 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2871 sFile
= PathFindFileNameW(lpszPath
);
2872 if (sFile
!= lpszPath
) sFile
--;
2874 /* Get the size of ellipses */
2875 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2876 dwEllipsesLen
= size
.cx
;
2877 /* Get the size of the file name */
2878 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2879 dwPathLen
= size
.cx
;
2881 if (sFile
!= lpszPath
)
2883 LPWSTR sPath
= sFile
;
2884 BOOL bEllipses
= FALSE
;
2886 /* The path includes a file name. Include as much of the path prior to
2887 * the file name as possible, allowing for the ellipses, e.g:
2888 * c:\some very long path\filename ==> c:\some v...\filename
2890 lstrcpynW(buff
, sFile
, MAX_PATH
);
2894 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2896 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2897 dwTotalLen
+= size
.cx
;
2898 if (dwTotalLen
<= dx
)
2906 } while (sPath
> lpszPath
);
2908 if (sPath
> lpszPath
)
2912 strcpyW(sPath
, szEllipses
);
2913 strcpyW(sPath
+3, buff
);
2918 strcpyW(lpszPath
, szEllipses
);
2919 strcpyW(lpszPath
+3, buff
);
2924 /* Trim the path by adding ellipses to the end, e.g:
2925 * A very long file name.txt ==> A very...
2927 dwLen
= strlenW(lpszPath
);
2929 if (dwLen
> MAX_PATH
- 3)
2930 dwLen
= MAX_PATH
- 3;
2931 lstrcpynW(buff
, sFile
, dwLen
);
2935 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2936 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2940 DWORD dwWritten
= 0;
2942 dwEllipsesLen
/= 3; /* Size of a single '.' */
2944 /* Write as much of the Ellipses string as possible */
2945 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2948 dwWritten
+= dwEllipsesLen
;
2956 strcpyW(buff
+ dwLen
, szEllipses
);
2957 strcpyW(lpszPath
, buff
);
2968 /*************************************************************************
2969 * PathGetCharTypeA [SHLWAPI.@]
2971 * Categorise a character from a file path.
2974 * ch [I] Character to get the type of
2977 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2979 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2981 return PathGetCharTypeW(ch
);
2984 /*************************************************************************
2985 * PathGetCharTypeW [SHLWAPI.@]
2987 * See PathGetCharTypeA.
2989 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2993 TRACE("(%d)\n", ch
);
2995 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2996 ch
== '"' || ch
== '|' || ch
== '/')
2997 flags
= GCT_INVALID
; /* Invalid */
2998 else if (ch
== '*' || ch
=='?')
2999 flags
= GCT_WILD
; /* Wildchars */
3000 else if ((ch
== '\\') || (ch
== ':'))
3001 return GCT_SEPARATOR
; /* Path separators */
3006 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
3007 ch
== '.' || ch
== '@' || ch
== '^' ||
3008 ch
== '\'' || ch
== 130 || ch
== '`')
3009 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
3012 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
3013 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
3018 /*************************************************************************
3019 * SHLWAPI_UseSystemForSystemFolders
3021 * Internal helper for PathMakeSystemFolderW.
3023 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3025 static BOOL bCheckedReg
= FALSE
;
3026 static BOOL bUseSystemForSystemFolders
= FALSE
;
3032 /* Key tells Win what file attributes to use on system folders */
3033 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3034 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3035 "UseSystemForSystemFolders", 0, 0, 0))
3036 bUseSystemForSystemFolders
= TRUE
;
3038 return bUseSystemForSystemFolders
;
3041 /*************************************************************************
3042 * PathMakeSystemFolderA [SHLWAPI.@]
3044 * Set system folder attribute for a path.
3047 * lpszPath [I] The path to turn into a system folder
3050 * TRUE If the path was changed to/already was a system folder
3051 * FALSE If the path is invalid or SetFileAttributesA() fails
3053 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3057 TRACE("(%s)\n", debugstr_a(lpszPath
));
3059 if (lpszPath
&& *lpszPath
)
3061 WCHAR szPath
[MAX_PATH
];
3062 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3063 bRet
= PathMakeSystemFolderW(szPath
);
3068 /*************************************************************************
3069 * PathMakeSystemFolderW [SHLWAPI.@]
3071 * See PathMakeSystemFolderA.
3073 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3075 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3076 WCHAR buff
[MAX_PATH
];
3078 TRACE("(%s)\n", debugstr_w(lpszPath
));
3080 if (!lpszPath
|| !*lpszPath
)
3083 /* If the directory is already a system directory, don't do anything */
3084 GetSystemDirectoryW(buff
, MAX_PATH
);
3085 if (!strcmpW(buff
, lpszPath
))
3088 GetWindowsDirectoryW(buff
, MAX_PATH
);
3089 if (!strcmpW(buff
, lpszPath
))
3092 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3093 if (SHLWAPI_UseSystemForSystemFolders())
3094 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3096 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3099 /* Change file attributes to system attributes */
3100 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3101 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3104 /*************************************************************************
3105 * PathRenameExtensionA [SHLWAPI.@]
3107 * Swap the file extension in a path with another extension.
3110 * lpszPath [I/O] Path to swap the extension in
3111 * lpszExt [I] The new extension
3114 * TRUE if lpszPath was modified,
3115 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3117 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3119 LPSTR lpszExtension
;
3121 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3123 lpszExtension
= PathFindExtensionA(lpszPath
);
3125 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3128 strcpy(lpszExtension
, lpszExt
);
3132 /*************************************************************************
3133 * PathRenameExtensionW [SHLWAPI.@]
3135 * See PathRenameExtensionA.
3137 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3139 LPWSTR lpszExtension
;
3141 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3143 lpszExtension
= PathFindExtensionW(lpszPath
);
3145 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3148 strcpyW(lpszExtension
, lpszExt
);
3152 /*************************************************************************
3153 * PathSearchAndQualifyA [SHLWAPI.@]
3155 * Determine if a given path is correct and fully qualified.
3158 * lpszPath [I] Path to check
3159 * lpszBuf [O] Output for correct path
3160 * cchBuf [I] Size of lpszBuf
3165 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3167 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3169 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3171 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3174 /*************************************************************************
3175 * PathSearchAndQualifyW [SHLWAPI.@]
3177 * See PathSearchAndQualifyA.
3179 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3181 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3183 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3185 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3188 /*************************************************************************
3189 * PathSkipRootA [SHLWAPI.@]
3191 * Return the portion of a path following the drive letter or mount point.
3194 * lpszPath [I] The path to skip on
3197 * Success: A pointer to the next character after the root.
3198 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3200 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3202 TRACE("(%s)\n", debugstr_a(lpszPath
));
3204 if (!lpszPath
|| !*lpszPath
)
3207 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3209 /* Network share: skip share server and mount point */
3211 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3212 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3214 return (LPSTR
)lpszPath
;
3217 if (IsDBCSLeadByte(*lpszPath
))
3221 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3222 return (LPSTR
)lpszPath
+ 3;
3226 /*************************************************************************
3227 * PathSkipRootW [SHLWAPI.@]
3229 * See PathSkipRootA.
3231 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3233 TRACE("(%s)\n", debugstr_w(lpszPath
));
3235 if (!lpszPath
|| !*lpszPath
)
3238 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3240 /* Network share: skip share server and mount point */
3242 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3243 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3245 return (LPWSTR
)lpszPath
;
3249 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3250 return (LPWSTR
)lpszPath
+ 3;
3254 /*************************************************************************
3255 * PathCreateFromUrlA [SHLWAPI.@]
3257 * See PathCreateFromUrlW
3259 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3260 LPDWORD pcchPath
, DWORD dwReserved
)
3262 WCHAR bufW
[MAX_PATH
];
3263 WCHAR
*pathW
= bufW
;
3264 UNICODE_STRING urlW
;
3266 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3268 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3269 return E_INVALIDARG
;
3271 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3272 return E_INVALIDARG
;
3273 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3274 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3275 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3278 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3279 if(*pcchPath
> lenA
) {
3280 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3284 *pcchPath
= lenA
+ 1;
3288 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3289 RtlFreeUnicodeString(&urlW
);
3293 /*************************************************************************
3294 * PathCreateFromUrlW [SHLWAPI.@]
3296 * Create a path from a URL
3299 * lpszUrl [I] URL to convert into a path
3300 * lpszPath [O] Output buffer for the resulting Path
3301 * pcchPath [I] Length of lpszPath
3302 * dwFlags [I] Flags controlling the conversion
3305 * Success: S_OK. lpszPath contains the URL in path format,
3306 * Failure: An HRESULT error code such as E_INVALIDARG.
3308 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3309 LPDWORD pcchPath
, DWORD dwReserved
)
3311 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3312 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3313 DWORD nslashes
, unescape
, len
;
3318 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3320 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3321 return E_INVALIDARG
;
3323 if (lstrlenW(pszUrl
) < 5)
3324 return E_INVALIDARG
;
3326 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3327 file_colon
, 5) != CSTR_EQUAL
)
3328 return E_INVALIDARG
;
3334 while (*src
== '/' || *src
== '\\') {
3339 /* We need a temporary buffer so we can compute what size to ask for.
3340 * We know that the final string won't be longer than the current pszUrl
3341 * plus at most two backslashes. All the other transformations make it
3344 len
= 2 + lstrlenW(pszUrl
) + 1;
3345 if (*pcchPath
< len
)
3346 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3356 /* 'file:' + escaped DOS path */
3359 /* 'file:/' + escaped DOS path */
3362 /* 'file:///' (implied localhost) + escaped DOS path */
3363 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3367 if (lstrlenW(src
) >= 10 && CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
,
3368 src
, 9, localhost
, 9) == CSTR_EQUAL
&& (src
[9] == '/' || src
[9] == '\\'))
3370 /* 'file://localhost/' + escaped DOS path */
3373 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3375 /* 'file://' + unescaped DOS path */
3380 /* 'file://hostname:port/path' (where path is escaped)
3381 * or 'file:' + escaped UNC path (\\server\share\path)
3382 * The second form is clearly specific to Windows and it might
3383 * even be doing a network lookup to try to figure it out.
3385 while (*src
&& *src
!= '/' && *src
!= '\\')
3388 StrCpyNW(dst
, pszUrl
, len
+ 1);
3390 if (*src
&& isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3392 /* 'Forget' to add a trailing '/', just like Windows */
3398 /* 'file://' + unescaped UNC path (\\server\share\path) */
3400 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3404 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3408 /* Copy the remainder of the path */
3409 len
+= lstrlenW(src
);
3412 /* First do the Windows-specific path conversions */
3413 for (dst
= tpath
; *dst
; dst
++)
3414 if (*dst
== '/') *dst
= '\\';
3415 if (isalphaW(*tpath
) && tpath
[1] == '|')
3416 tpath
[1] = ':'; /* c| -> c: */
3418 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3421 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3424 /* When working in-place UrlUnescapeW() does not set len */
3425 len
= lstrlenW(tpath
);
3429 if (*pcchPath
< len
+ 1)
3432 *pcchPath
= len
+ 1;
3437 if (tpath
!= pszPath
)
3438 StrCpyW(pszPath
, tpath
);
3440 if (tpath
!= pszPath
)
3441 HeapFree(GetProcessHeap(), 0, tpath
);
3443 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3447 /*************************************************************************
3448 * PathCreateFromUrlAlloc [SHLWAPI.@]
3450 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3453 WCHAR pathW
[MAX_PATH
];
3458 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3461 /* Yes, this is supposed to crash if pszPath is NULL */
3462 *pszPath
= StrDupW(pathW
);
3467 /*************************************************************************
3468 * PathRelativePathToA [SHLWAPI.@]
3470 * Create a relative path from one path to another.
3473 * lpszPath [O] Destination for relative path
3474 * lpszFrom [I] Source path
3475 * dwAttrFrom [I] File attribute of source path
3476 * lpszTo [I] Destination path
3477 * dwAttrTo [I] File attributes of destination path
3480 * TRUE If a relative path can be formed. lpszPath contains the new path
3481 * FALSE If the paths are not relative or any parameters are invalid
3484 * lpszTo should be at least MAX_PATH in length.
3486 * Calling this function with relative paths for lpszFrom or lpszTo may
3487 * give erroneous results.
3489 * The Win32 version of this function contains a bug where the lpszTo string
3490 * may be referenced 1 byte beyond the end of the string. As a result random
3491 * garbage may be written to the output path, depending on what lies beyond
3492 * the last byte of the string. This bug occurs because of the behaviour of
3493 * PathCommonPrefix() (see notes for that function), and no workaround seems
3494 * possible with Win32.
3496 * This bug has been fixed here, so for example the relative path from "\\"
3497 * to "\\" is correctly determined as "." in this implementation.
3499 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3500 LPCSTR lpszTo
, DWORD dwAttrTo
)
3504 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3505 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3507 if(lpszPath
&& lpszFrom
&& lpszTo
)
3509 WCHAR szPath
[MAX_PATH
];
3510 WCHAR szFrom
[MAX_PATH
];
3511 WCHAR szTo
[MAX_PATH
];
3512 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3513 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3514 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3515 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3520 /*************************************************************************
3521 * PathRelativePathToW [SHLWAPI.@]
3523 * See PathRelativePathToA.
3525 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3526 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3528 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3529 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3530 WCHAR szFrom
[MAX_PATH
];
3531 WCHAR szTo
[MAX_PATH
];
3534 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3535 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3537 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3541 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3542 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3544 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3545 PathRemoveFileSpecW(szFrom
);
3546 if(!(dwAttrTo
& FILE_ATTRIBUTE_DIRECTORY
))
3547 PathRemoveFileSpecW(szTo
);
3549 /* Paths can only be relative if they have a common root */
3550 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3553 /* Strip off lpszFrom components to the root, by adding "..\" */
3554 lpszFrom
= szFrom
+ dwLen
;
3560 if (*lpszFrom
== '\\')
3565 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3566 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3569 /* From the root add the components of lpszTo */
3571 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3574 if (*lpszTo
&& lpszTo
[-1])
3576 if (*lpszTo
!= '\\')
3578 dwLen
= strlenW(lpszPath
);
3579 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3584 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3589 /*************************************************************************
3590 * PathUnmakeSystemFolderA [SHLWAPI.@]
3592 * Remove the system folder attributes from a path.
3595 * lpszPath [I] The path to remove attributes from
3599 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3600 * SetFileAttributesA() fails.
3602 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3606 TRACE("(%s)\n", debugstr_a(lpszPath
));
3608 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3609 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3612 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3613 return SetFileAttributesA(lpszPath
, dwAttr
);
3616 /*************************************************************************
3617 * PathUnmakeSystemFolderW [SHLWAPI.@]
3619 * See PathUnmakeSystemFolderA.
3621 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3625 TRACE("(%s)\n", debugstr_w(lpszPath
));
3627 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3628 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3631 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3632 return SetFileAttributesW(lpszPath
, dwAttr
);
3636 /*************************************************************************
3637 * PathSetDlgItemPathA [SHLWAPI.@]
3639 * Set the text of a dialog item to a path, shrinking the path to fit
3640 * if it is too big for the item.
3643 * hDlg [I] Dialog handle
3644 * id [I] ID of item in the dialog
3645 * lpszPath [I] Path to set as the items text
3651 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3652 * window text is erased).
3654 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3656 WCHAR szPath
[MAX_PATH
];
3658 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3661 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3664 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3667 /*************************************************************************
3668 * PathSetDlgItemPathW [SHLWAPI.@]
3670 * See PathSetDlgItemPathA.
3672 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3674 WCHAR path
[MAX_PATH
+ 1];
3680 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3682 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3686 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3690 GetClientRect(hwItem
, &rect
);
3692 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3696 PathCompactPathW(hdc
, path
, rect
.right
);
3697 SelectObject(hdc
, hPrevObj
);
3700 ReleaseDC(hDlg
, hdc
);
3701 SetWindowTextW(hwItem
, path
);
3704 /*************************************************************************
3705 * PathIsNetworkPathA [SHLWAPI.@]
3707 * Determine if the given path is a network path.
3710 * lpszPath [I] Path to check
3713 * TRUE If lpszPath is a UNC share or mapped network drive, or
3714 * FALSE If lpszPath is a local drive or cannot be determined
3716 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3720 TRACE("(%s)\n",debugstr_a(lpszPath
));
3724 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3726 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3727 if (dwDriveNum
== -1)
3730 return IsNetDrive(dwDriveNum
);
3732 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3733 return pIsNetDrive(dwDriveNum
);
3737 /*************************************************************************
3738 * PathIsNetworkPathW [SHLWAPI.@]
3740 * See PathIsNetworkPathA.
3742 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3746 TRACE("(%s)\n", debugstr_w(lpszPath
));
3750 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3752 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3753 if (dwDriveNum
== -1)
3756 return IsNetDrive(dwDriveNum
);
3758 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3759 return pIsNetDrive(dwDriveNum
);
3763 /*************************************************************************
3764 * PathIsLFNFileSpecA [SHLWAPI.@]
3766 * Determine if the given path is a long file name
3769 * lpszPath [I] Path to check
3772 * TRUE If path is a long file name,
3773 * FALSE If path is a valid DOS short file name
3775 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3777 DWORD dwNameLen
= 0, dwExtLen
= 0;
3779 TRACE("(%s)\n",debugstr_a(lpszPath
));
3786 if (*lpszPath
== ' ')
3787 return TRUE
; /* DOS names cannot have spaces */
3788 if (*lpszPath
== '.')
3791 return TRUE
; /* DOS names have only one dot */
3798 return TRUE
; /* DOS extensions are <= 3 chars*/
3804 return TRUE
; /* DOS names are <= 8 chars */
3806 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3808 return FALSE
; /* Valid DOS path */
3811 /*************************************************************************
3812 * PathIsLFNFileSpecW [SHLWAPI.@]
3814 * See PathIsLFNFileSpecA.
3816 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3818 DWORD dwNameLen
= 0, dwExtLen
= 0;
3820 TRACE("(%s)\n",debugstr_w(lpszPath
));
3827 if (*lpszPath
== ' ')
3828 return TRUE
; /* DOS names cannot have spaces */
3829 if (*lpszPath
== '.')
3832 return TRUE
; /* DOS names have only one dot */
3839 return TRUE
; /* DOS extensions are <= 3 chars*/
3845 return TRUE
; /* DOS names are <= 8 chars */
3849 return FALSE
; /* Valid DOS path */
3852 /*************************************************************************
3853 * PathIsDirectoryEmptyA [SHLWAPI.@]
3855 * Determine if a given directory is empty.
3858 * lpszPath [I] Directory to check
3861 * TRUE If the directory exists and contains no files,
3864 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3868 TRACE("(%s)\n",debugstr_a(lpszPath
));
3872 WCHAR szPath
[MAX_PATH
];
3873 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3874 bRet
= PathIsDirectoryEmptyW(szPath
);
3879 /*************************************************************************
3880 * PathIsDirectoryEmptyW [SHLWAPI.@]
3882 * See PathIsDirectoryEmptyA.
3884 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3886 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3887 WCHAR szSearch
[MAX_PATH
];
3891 WIN32_FIND_DATAW find_data
;
3893 TRACE("(%s)\n",debugstr_w(lpszPath
));
3895 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3898 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3899 PathAddBackslashW(szSearch
);
3900 dwLen
= strlenW(szSearch
);
3901 if (dwLen
> MAX_PATH
- 4)
3904 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3905 hfind
= FindFirstFileW(szSearch
, &find_data
);
3906 if (hfind
== INVALID_HANDLE_VALUE
)
3911 if (find_data
.cFileName
[0] == '.')
3913 if (find_data
.cFileName
[1] == '\0') continue;
3914 if (find_data
.cFileName
[1] == '.' && find_data
.cFileName
[2] == '\0') continue;
3920 while (FindNextFileW(hfind
, &find_data
));
3927 /*************************************************************************
3928 * PathFindSuffixArrayA [SHLWAPI.@]
3930 * Find a suffix string in an array of suffix strings
3933 * lpszSuffix [I] Suffix string to search for
3934 * lppszArray [I] Array of suffix strings to search
3935 * dwCount [I] Number of elements in lppszArray
3938 * Success: The index of the position of lpszSuffix in lppszArray
3939 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3942 * The search is case sensitive.
3943 * The match is made against the end of the suffix string, so for example:
3944 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3946 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3951 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3953 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3955 dwLen
= strlen(lpszSuffix
);
3957 while (dwRet
< dwCount
)
3959 size_t dwCompareLen
= strlen(*lppszArray
);
3960 if (dwCompareLen
< dwLen
)
3962 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3963 return *lppszArray
; /* Found */
3972 /*************************************************************************
3973 * PathFindSuffixArrayW [SHLWAPI.@]
3975 * See PathFindSuffixArrayA.
3977 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3982 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3984 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3986 dwLen
= strlenW(lpszSuffix
);
3988 while (dwRet
< dwCount
)
3990 size_t dwCompareLen
= strlenW(*lppszArray
);
3991 if (dwCompareLen
< dwLen
)
3993 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3994 return *lppszArray
; /* Found */
4003 /*************************************************************************
4004 * PathUndecorateA [SHLWAPI.@]
4006 * Undecorate a file path
4009 * lpszPath [I/O] Path to remove any decoration from
4015 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
4017 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
4019 TRACE("(%s)\n",debugstr_a(lpszPath
));
4023 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
4024 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4026 LPSTR lpszSkip
= lpszExt
- 2;
4027 if (*lpszSkip
== '[')
4028 lpszSkip
++; /* [] (no number) */
4030 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
4032 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4034 /* remove the [n] */
4037 *lpszSkip
++ = *lpszExt
++;
4044 /*************************************************************************
4045 * PathUndecorateW [SHLWAPI.@]
4047 * See PathUndecorateA.
4049 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4051 TRACE("(%s)\n",debugstr_w(lpszPath
));
4055 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4056 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4058 LPWSTR lpszSkip
= lpszExt
- 2;
4059 if (*lpszSkip
== '[')
4060 lpszSkip
++; /* [] (no number) */
4062 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4064 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4066 /* remove the [n] */
4069 *lpszSkip
++ = *lpszExt
++;
4076 /*************************************************************************
4077 * PathUnExpandEnvStringsA [SHLWAPI.@]
4079 * Substitute folder names in a path with their corresponding environment
4083 * path [I] Buffer containing the path to unexpand.
4084 * buffer [O] Buffer to receive the unexpanded path.
4085 * buf_len [I] Size of pszBuf in characters.
4091 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4093 WCHAR bufferW
[MAX_PATH
], *pathW
;
4097 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4099 pathW
= heap_strdupAtoW(path
);
4100 if (!pathW
) return FALSE
;
4102 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4103 HeapFree(GetProcessHeap(), 0, pathW
);
4104 if (!ret
) return FALSE
;
4106 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4107 if (buf_len
< len
+ 1) return FALSE
;
4109 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4113 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4114 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4115 static const WCHAR computernameW
[] = {'%','C','O','M','P','U','T','E','R','N','A','M','E','%',0};
4116 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4117 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4118 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4119 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4125 WCHAR path
[MAX_PATH
];
4129 static void init_envvars_map(struct envvars_map
*map
)
4133 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4134 /* exclude null from length */
4135 if (map
->len
) map
->len
--;
4140 /*************************************************************************
4141 * PathUnExpandEnvStringsW [SHLWAPI.@]
4143 * Unicode version of PathUnExpandEnvStringsA.
4145 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4147 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4148 struct envvars_map
*match
= &null_var
, *cur
;
4149 struct envvars_map envvars
[] = {
4150 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4151 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4152 { computernameW
, sizeof(computernameW
)/sizeof(WCHAR
) },
4153 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4154 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4155 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4156 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4162 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4164 pathlen
= strlenW(path
);
4165 init_envvars_map(envvars
);
4169 /* path can't contain expanded value or value wasn't retrieved */
4170 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4176 if (cur
->len
> match
->len
)
4181 /* 'varlen' includes NULL termination char */
4182 needed
= match
->varlen
+ pathlen
- match
->len
;
4183 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4185 strcpyW(buffer
, match
->var
);
4186 strcatW(buffer
, &path
[match
->len
]);
4187 TRACE("ret %s\n", debugstr_w(buffer
));
4192 /*************************************************************************
4195 * Find localised or default web content in "%WINDOWS%\web\".
4198 * lpszFile [I] File name containing content to look for
4199 * lpszPath [O] Buffer to contain the full path to the file
4200 * dwPathLen [I] Length of lpszPath
4203 * Success: S_OK. lpszPath contains the full path to the content.
4204 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4206 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4208 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4211 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4213 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4215 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4216 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4220 /*************************************************************************
4223 * Unicode version of SHGetWebFolderFilePathA.
4225 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4227 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4228 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4229 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4230 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4231 DWORD dwLen
, dwFileLen
;
4232 LANGID lidSystem
, lidUser
;
4234 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4236 /* Get base directory for web content */
4237 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4238 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4241 dwFileLen
= strlenW(lpszFile
);
4243 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4244 return E_FAIL
; /* lpszPath too short */
4246 strcpyW(lpszPath
+dwLen
, szWeb
);
4248 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4250 lidSystem
= GetSystemDefaultUILanguage();
4251 lidUser
= GetUserDefaultUILanguage();
4253 if (lidSystem
!= lidUser
)
4255 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4257 /* Use localised content in the users UI language if present */
4258 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4259 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4260 if (PathFileExistsW(lpszPath
))
4265 /* Fall back to OS default installed content */
4266 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4267 if (PathFileExistsW(lpszPath
))
4272 #define PATH_CHAR_CLASS_LETTER 0x00000001
4273 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4274 #define PATH_CHAR_CLASS_DOT 0x00000004
4275 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4276 #define PATH_CHAR_CLASS_COLON 0x00000010
4277 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4278 #define PATH_CHAR_CLASS_COMMA 0x00000040
4279 #define PATH_CHAR_CLASS_SPACE 0x00000080
4280 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4281 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4283 #define PATH_CHAR_CLASS_INVALID 0x00000000
4284 #define PATH_CHAR_CLASS_ANY 0xffffffff
4286 static const DWORD SHELL_charclass
[] =
4288 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4289 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4290 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4291 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4292 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4293 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4294 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4295 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4296 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4297 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4298 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4299 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4300 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4301 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4302 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4303 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4304 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4305 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4306 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4307 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4308 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4309 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4310 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4311 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4312 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4313 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4314 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4315 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4316 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4317 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4318 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4319 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4320 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4321 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4322 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4323 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4324 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4325 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4326 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4327 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4328 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4329 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4330 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4331 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4332 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4333 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4334 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4335 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4336 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4337 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4338 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4339 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4340 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4341 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4342 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4343 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4344 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4345 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4346 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4347 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4348 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4349 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4350 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4351 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4354 /*************************************************************************
4357 * Check if an ASCII char is of a certain class
4359 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4361 if ((unsigned)c
> 0x7e)
4362 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4364 return class & SHELL_charclass
[(unsigned)c
];
4367 /*************************************************************************
4370 * Check if a Unicode char is of a certain class
4372 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4375 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4377 return class & SHELL_charclass
[c
];