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
24 int WINAPI
IsNetDrive(int drive
);
26 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
28 static inline WCHAR
* heap_strdupAtoW(LPCSTR str
)
34 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
35 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
37 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
43 /*************************************************************************
44 * PathAppendA [SHLWAPI.@]
46 * Append one path to another.
49 * lpszPath [I/O] Initial part of path, and destination for output
50 * lpszAppend [I] Path to append
53 * Success: TRUE. lpszPath contains the newly created path.
54 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
57 * lpszAppend must contain at least one backslash ('\') if not NULL.
58 * Because PathCombineA() is used to join the paths, the resulting
59 * path is also canonicalized.
61 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
63 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
65 if (lpszPath
&& lpszAppend
)
67 if (!PathIsUNCA(lpszAppend
))
68 while (*lpszAppend
== '\\')
70 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
76 /*************************************************************************
77 * PathAppendW [SHLWAPI.@]
81 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
83 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
85 if (lpszPath
&& lpszAppend
)
87 if (!PathIsUNCW(lpszAppend
))
88 while (*lpszAppend
== '\\')
90 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
96 /*************************************************************************
97 * PathCombineA [SHLWAPI.@]
99 * Combine two paths together.
102 * lpszDest [O] Destination for combined path
103 * lpszDir [I] Directory path
104 * lpszFile [I] File path
107 * Success: The output path
108 * Failure: NULL, if inputs are invalid.
111 * lpszDest should be at least MAX_PATH in size, and may point to the same
112 * memory location as lpszDir. The combined path is canonicalised.
114 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
116 WCHAR szDest
[MAX_PATH
];
117 WCHAR szDir
[MAX_PATH
];
118 WCHAR szFile
[MAX_PATH
];
119 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
121 /* Invalid parameters */
124 if (!lpszDir
&& !lpszFile
)
128 if (!MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
))
132 if (!MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
))
135 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
136 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
144 /*************************************************************************
145 * PathCombineW [SHLWAPI.@]
149 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
151 WCHAR szTemp
[MAX_PATH
];
152 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
154 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
156 /* Invalid parameters */
159 if (!lpszDir
&& !lpszFile
)
165 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
168 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
170 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
172 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
175 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
188 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
191 PathStripToRootW(szTemp
);
192 lpszFile
++; /* Skip '\' */
194 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
199 strcatW(szTemp
, lpszFile
);
202 PathCanonicalizeW(lpszDest
, szTemp
);
206 /*************************************************************************
207 * PathAddBackslashA [SHLWAPI.@]
209 * Append a backslash ('\') to a path if one doesn't exist.
212 * lpszPath [I/O] The path to append a backslash to.
215 * Success: The position of the last backslash in the path.
216 * Failure: NULL, if lpszPath is NULL or the path is too large.
218 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
221 LPSTR prev
= lpszPath
;
223 TRACE("(%s)\n",debugstr_a(lpszPath
));
225 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
231 lpszPath
= CharNextA(prev
);
244 /*************************************************************************
245 * PathAddBackslashW [SHLWAPI.@]
247 * See PathAddBackslashA.
249 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
253 TRACE("(%s)\n",debugstr_w(lpszPath
));
255 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
261 if (lpszPath
[-1] != '\\')
270 /*************************************************************************
271 * PathBuildRootA [SHLWAPI.@]
273 * Create a root drive string (e.g. "A:\") from a drive number.
276 * lpszPath [O] Destination for the drive string
282 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
284 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
286 TRACE("(%p,%d)\n", lpszPath
, drive
);
288 if (lpszPath
&& drive
>= 0 && drive
< 26)
290 lpszPath
[0] = 'A' + drive
;
298 /*************************************************************************
299 * PathBuildRootW [SHLWAPI.@]
301 * See PathBuildRootA.
303 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
305 TRACE("(%p,%d)\n", lpszPath
, drive
);
307 if (lpszPath
&& drive
>= 0 && drive
< 26)
309 lpszPath
[0] = 'A' + drive
;
317 /*************************************************************************
318 * PathFindFileNameA [SHLWAPI.@]
320 * Locate the start of the file name in a path
323 * lpszPath [I] Path to search
326 * A pointer to the first character of the file name
328 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
330 LPCSTR lastSlash
= lpszPath
;
332 TRACE("(%s)\n",debugstr_a(lpszPath
));
334 while (lpszPath
&& *lpszPath
)
336 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
337 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
338 lastSlash
= lpszPath
+ 1;
339 lpszPath
= CharNextA(lpszPath
);
341 return (LPSTR
)lastSlash
;
344 /*************************************************************************
345 * PathFindFileNameW [SHLWAPI.@]
347 * See PathFindFileNameA.
349 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
351 LPCWSTR lastSlash
= lpszPath
;
353 TRACE("(%s)\n",debugstr_w(lpszPath
));
355 while (lpszPath
&& *lpszPath
)
357 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
358 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
359 lastSlash
= lpszPath
+ 1;
362 return (LPWSTR
)lastSlash
;
365 /*************************************************************************
366 * PathFindExtensionA [SHLWAPI.@]
368 * Locate the start of the file extension in a path
371 * lpszPath [I] The path to search
374 * A pointer to the first character of the extension, the end of
375 * the string if the path has no extension, or NULL If lpszPath is NULL
377 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
379 LPCSTR lastpoint
= NULL
;
381 TRACE("(%s)\n", debugstr_a(lpszPath
));
387 if (*lpszPath
== '\\' || *lpszPath
==' ')
389 else if (*lpszPath
== '.')
390 lastpoint
= lpszPath
;
391 lpszPath
= CharNextA(lpszPath
);
394 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
397 /*************************************************************************
398 * PathFindExtensionW [SHLWAPI.@]
400 * See PathFindExtensionA.
402 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
404 LPCWSTR lastpoint
= NULL
;
406 TRACE("(%s)\n", debugstr_w(lpszPath
));
412 if (*lpszPath
== '\\' || *lpszPath
==' ')
414 else if (*lpszPath
== '.')
415 lastpoint
= lpszPath
;
419 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
422 /*************************************************************************
423 * PathGetArgsA [SHLWAPI.@]
425 * Find the next argument in a string delimited by spaces.
428 * lpszPath [I] The string to search for arguments in
431 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
434 * Spaces in quoted strings are ignored as delimiters.
436 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
438 BOOL bSeenQuote
= FALSE
;
440 TRACE("(%s)\n",debugstr_a(lpszPath
));
446 if ((*lpszPath
==' ') && !bSeenQuote
)
447 return (LPSTR
)lpszPath
+ 1;
448 if (*lpszPath
== '"')
449 bSeenQuote
= !bSeenQuote
;
450 lpszPath
= CharNextA(lpszPath
);
453 return (LPSTR
)lpszPath
;
456 /*************************************************************************
457 * PathGetArgsW [SHLWAPI.@]
461 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
463 BOOL bSeenQuote
= FALSE
;
465 TRACE("(%s)\n",debugstr_w(lpszPath
));
471 if ((*lpszPath
==' ') && !bSeenQuote
)
472 return (LPWSTR
)lpszPath
+ 1;
473 if (*lpszPath
== '"')
474 bSeenQuote
= !bSeenQuote
;
478 return (LPWSTR
)lpszPath
;
481 /*************************************************************************
482 * PathGetDriveNumberA [SHLWAPI.@]
484 * Return the drive number from a path
487 * lpszPath [I] Path to get the drive number from
490 * Success: The drive number corresponding to the drive in the path
491 * Failure: -1, if lpszPath contains no valid drive
493 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
495 TRACE ("(%s)\n",debugstr_a(lpszPath
));
497 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
498 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
499 return tolower(*lpszPath
) - 'a';
503 /*************************************************************************
504 * PathGetDriveNumberW [SHLWAPI.@]
506 * See PathGetDriveNumberA.
508 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
510 TRACE ("(%s)\n",debugstr_w(lpszPath
));
514 WCHAR tl
= tolowerW(lpszPath
[0]);
515 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
521 /*************************************************************************
522 * PathRemoveFileSpecA [SHLWAPI.@]
524 * Remove the file specification from a path.
527 * lpszPath [I/O] Path to remove the file spec from
530 * TRUE If the path was valid and modified
533 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
535 LPSTR lpszFileSpec
= lpszPath
;
536 BOOL bModified
= FALSE
;
538 TRACE("(%s)\n",debugstr_a(lpszPath
));
542 /* Skip directory or UNC path */
543 if (*lpszPath
== '\\')
544 lpszFileSpec
= ++lpszPath
;
545 if (*lpszPath
== '\\')
546 lpszFileSpec
= ++lpszPath
;
550 if(*lpszPath
== '\\')
551 lpszFileSpec
= lpszPath
; /* Skip dir */
552 else if(*lpszPath
== ':')
554 lpszFileSpec
= ++lpszPath
; /* Skip drive */
555 if (*lpszPath
== '\\')
558 if (!(lpszPath
= CharNextA(lpszPath
)))
564 *lpszFileSpec
= '\0';
571 /*************************************************************************
572 * PathRemoveFileSpecW [SHLWAPI.@]
574 * See PathRemoveFileSpecA.
576 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
578 LPWSTR lpszFileSpec
= lpszPath
;
579 BOOL bModified
= FALSE
;
581 TRACE("(%s)\n",debugstr_w(lpszPath
));
585 /* Skip directory or UNC path */
586 if (*lpszPath
== '\\')
587 lpszFileSpec
= ++lpszPath
;
588 if (*lpszPath
== '\\')
589 lpszFileSpec
= ++lpszPath
;
593 if(*lpszPath
== '\\')
594 lpszFileSpec
= lpszPath
; /* Skip dir */
595 else if(*lpszPath
== ':')
597 lpszFileSpec
= ++lpszPath
; /* Skip drive */
598 if (*lpszPath
== '\\')
606 *lpszFileSpec
= '\0';
613 /*************************************************************************
614 * PathStripPathA [SHLWAPI.@]
616 * Remove the initial path from the beginning of a filename
619 * lpszPath [I/O] Path to remove the initial path from
624 void WINAPI
PathStripPathA(LPSTR lpszPath
)
626 TRACE("(%s)\n", debugstr_a(lpszPath
));
630 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
632 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
636 /*************************************************************************
637 * PathStripPathW [SHLWAPI.@]
639 * See PathStripPathA.
641 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
645 TRACE("(%s)\n", debugstr_w(lpszPath
));
646 lpszFileName
= PathFindFileNameW(lpszPath
);
648 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
651 /*************************************************************************
652 * PathStripToRootA [SHLWAPI.@]
654 * Reduce a path to its root.
657 * lpszPath [I/O] the path to reduce
660 * Success: TRUE if the stripped path is a root path
661 * Failure: FALSE if the path cannot be stripped or is NULL
663 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
665 TRACE("(%s)\n", debugstr_a(lpszPath
));
669 while(!PathIsRootA(lpszPath
))
670 if (!PathRemoveFileSpecA(lpszPath
))
675 /*************************************************************************
676 * PathStripToRootW [SHLWAPI.@]
678 * See PathStripToRootA.
680 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
682 TRACE("(%s)\n", debugstr_w(lpszPath
));
686 while(!PathIsRootW(lpszPath
))
687 if (!PathRemoveFileSpecW(lpszPath
))
692 /*************************************************************************
693 * PathRemoveArgsA [SHLWAPI.@]
695 * Strip space separated arguments from a path.
698 * lpszPath [I/O] Path to remove arguments from
703 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
705 TRACE("(%s)\n",debugstr_a(lpszPath
));
709 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
714 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
715 if(*lpszLastChar
== ' ')
716 *lpszLastChar
= '\0';
721 /*************************************************************************
722 * PathRemoveArgsW [SHLWAPI.@]
724 * See PathRemoveArgsA.
726 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
728 TRACE("(%s)\n",debugstr_w(lpszPath
));
732 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
733 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
738 /*************************************************************************
739 * PathRemoveExtensionA [SHLWAPI.@]
741 * Remove the file extension from a path
744 * lpszPath [I/O] Path to remove the extension from
747 * The NUL terminator must be written only if extension exists
748 * and if the pointed character is not already NUL.
753 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
755 TRACE("(%s)\n", debugstr_a(lpszPath
));
759 lpszPath
= PathFindExtensionA(lpszPath
);
760 if (lpszPath
&& *lpszPath
!= '\0')
765 /*************************************************************************
766 * PathRemoveExtensionW [SHLWAPI.@]
768 * See PathRemoveExtensionA.
770 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
772 TRACE("(%s)\n", debugstr_w(lpszPath
));
776 lpszPath
= PathFindExtensionW(lpszPath
);
777 if (lpszPath
&& *lpszPath
!= '\0')
782 /*************************************************************************
783 * PathRemoveBackslashA [SHLWAPI.@]
785 * Remove a trailing backslash from a path.
788 * lpszPath [I/O] Path to remove backslash from
791 * Success: A pointer to the end of the path
792 * Failure: NULL, if lpszPath is NULL
794 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
798 TRACE("(%s)\n", debugstr_a(lpszPath
));
802 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
803 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
809 /*************************************************************************
810 * PathRemoveBackslashW [SHLWAPI.@]
812 * See PathRemoveBackslashA.
814 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
816 LPWSTR szTemp
= NULL
;
818 TRACE("(%s)\n", debugstr_w(lpszPath
));
822 szTemp
= lpszPath
+ strlenW(lpszPath
);
823 if (szTemp
> lpszPath
) szTemp
--;
824 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
830 /*************************************************************************
831 * PathRemoveBlanksA [SHLWAPI.@]
833 * Remove Spaces from the start and end of a path.
836 * lpszPath [I/O] Path to strip blanks from
841 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
843 TRACE("(%s)\n", debugstr_a(lpszPath
));
845 if(lpszPath
&& *lpszPath
)
847 LPSTR start
= lpszPath
;
849 while (*lpszPath
== ' ')
850 lpszPath
= CharNextA(lpszPath
);
853 *start
++ = *lpszPath
++;
855 if (start
!= lpszPath
)
856 while (start
[-1] == ' ')
862 /*************************************************************************
863 * PathRemoveBlanksW [SHLWAPI.@]
865 * See PathRemoveBlanksA.
867 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
869 TRACE("(%s)\n", debugstr_w(lpszPath
));
871 if(lpszPath
&& *lpszPath
)
873 LPWSTR start
= lpszPath
;
875 while (*lpszPath
== ' ')
879 *start
++ = *lpszPath
++;
881 if (start
!= lpszPath
)
882 while (start
[-1] == ' ')
888 /*************************************************************************
889 * PathQuoteSpacesA [SHLWAPI.@]
891 * Surround a path containing spaces in quotes.
894 * lpszPath [I/O] Path to quote
900 * The path is not changed if it is invalid or has no spaces.
902 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
904 TRACE("(%s)\n", debugstr_a(lpszPath
));
906 if(lpszPath
&& StrChrA(lpszPath
,' '))
908 size_t iLen
= strlen(lpszPath
) + 1;
910 if (iLen
+ 2 < MAX_PATH
)
912 memmove(lpszPath
+ 1, lpszPath
, iLen
);
914 lpszPath
[iLen
] = '"';
915 lpszPath
[iLen
+ 1] = '\0';
920 /*************************************************************************
921 * PathQuoteSpacesW [SHLWAPI.@]
923 * See PathQuoteSpacesA.
925 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
927 TRACE("(%s)\n", debugstr_w(lpszPath
));
929 if(lpszPath
&& StrChrW(lpszPath
,' '))
931 int iLen
= strlenW(lpszPath
) + 1;
933 if (iLen
+ 2 < MAX_PATH
)
935 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
937 lpszPath
[iLen
] = '"';
938 lpszPath
[iLen
+ 1] = '\0';
943 /*************************************************************************
944 * PathUnquoteSpacesA [SHLWAPI.@]
946 * Remove quotes ("") from around a path, if present.
949 * lpszPath [I/O] Path to strip quotes from
955 * If the path contains a single quote only, an empty string will result.
956 * Otherwise quotes are only removed if they appear at the start and end
959 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
961 TRACE("(%s)\n", debugstr_a(lpszPath
));
963 if (lpszPath
&& *lpszPath
== '"')
965 DWORD dwLen
= strlen(lpszPath
) - 1;
967 if (lpszPath
[dwLen
] == '"')
969 lpszPath
[dwLen
] = '\0';
970 for (; *lpszPath
; lpszPath
++)
971 *lpszPath
= lpszPath
[1];
976 /*************************************************************************
977 * PathUnquoteSpacesW [SHLWAPI.@]
979 * See PathUnquoteSpacesA.
981 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
983 TRACE("(%s)\n", debugstr_w(lpszPath
));
985 if (lpszPath
&& *lpszPath
== '"')
987 DWORD dwLen
= strlenW(lpszPath
) - 1;
989 if (lpszPath
[dwLen
] == '"')
991 lpszPath
[dwLen
] = '\0';
992 for (; *lpszPath
; lpszPath
++)
993 *lpszPath
= lpszPath
[1];
998 /*************************************************************************
999 * PathParseIconLocationA [SHLWAPI.@]
1001 * Parse the location of an icon from a path.
1004 * lpszPath [I/O] The path to parse the icon location from.
1007 * Success: The number of the icon
1008 * Failure: 0 if the path does not contain an icon location or is NULL
1011 * The path has surrounding quotes and spaces removed regardless
1012 * of whether the call succeeds or not.
1014 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1019 TRACE("(%s)\n", debugstr_a(lpszPath
));
1023 if ((lpszComma
= strchr(lpszPath
, ',')))
1025 *lpszComma
++ = '\0';
1026 iRet
= StrToIntA(lpszComma
);
1028 PathUnquoteSpacesA(lpszPath
);
1029 PathRemoveBlanksA(lpszPath
);
1034 /*************************************************************************
1035 * PathParseIconLocationW [SHLWAPI.@]
1037 * See PathParseIconLocationA.
1039 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1044 TRACE("(%s)\n", debugstr_w(lpszPath
));
1048 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1050 *lpszComma
++ = '\0';
1051 iRet
= StrToIntW(lpszComma
);
1053 PathUnquoteSpacesW(lpszPath
);
1054 PathRemoveBlanksW(lpszPath
);
1059 /*************************************************************************
1062 * Unicode version of PathFileExistsDefExtA.
1064 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1066 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1067 { '.', 'c', 'o', 'm', 0},
1068 { '.', 'e', 'x', 'e', 0},
1069 { '.', 'b', 'a', 't', 0},
1070 { '.', 'l', 'n', 'k', 0},
1071 { '.', 'c', 'm', 'd', 0},
1074 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1076 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1081 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1082 if (!*szExt
|| dwWhich
& 0x40)
1085 int iLen
= lstrlenW(lpszPath
);
1086 if (iLen
> (MAX_PATH
- 5))
1088 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1090 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1091 if (PathFileExistsW(lpszPath
))
1096 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1100 return PathFileExistsW(lpszPath
);
1103 /*************************************************************************
1106 * Determine if a file exists locally and is of an executable type.
1109 * lpszPath [I/O] File to search for
1110 * dwWhich [I] Type of executable to search for
1113 * TRUE If the file was found. lpszPath contains the file name.
1117 * lpszPath is modified in place and must be at least MAX_PATH in length.
1118 * If the function returns FALSE, the path is modified to its original state.
1119 * If the given path contains an extension or dwWhich is 0, executable
1120 * extensions are not checked.
1122 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1123 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1124 * their own developers exclusive use. Monopoly, anyone?
1126 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1130 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1134 WCHAR szPath
[MAX_PATH
];
1135 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1136 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1138 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1143 /*************************************************************************
1144 * SHLWAPI_PathFindInOtherDirs
1146 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1148 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1150 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1151 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1155 WCHAR buff
[MAX_PATH
];
1157 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1159 /* Try system directories */
1160 GetSystemDirectoryW(buff
, MAX_PATH
);
1161 if (!PathAppendW(buff
, lpszFile
))
1163 if (PathFileExistsDefExtW(buff
, dwWhich
))
1165 strcpyW(lpszFile
, buff
);
1168 GetWindowsDirectoryW(buff
, MAX_PATH
);
1169 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1171 if (PathFileExistsDefExtW(buff
, dwWhich
))
1173 strcpyW(lpszFile
, buff
);
1176 GetWindowsDirectoryW(buff
, MAX_PATH
);
1177 if (!PathAppendW(buff
, lpszFile
))
1179 if (PathFileExistsDefExtW(buff
, dwWhich
))
1181 strcpyW(lpszFile
, buff
);
1184 /* Try dirs listed in %PATH% */
1185 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1187 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1190 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1191 lpszCurr
= lpszPATH
;
1194 LPCWSTR lpszEnd
= lpszCurr
;
1195 LPWSTR pBuff
= buff
;
1197 while (*lpszEnd
== ' ')
1199 while (*lpszEnd
&& *lpszEnd
!= ';')
1200 *pBuff
++ = *lpszEnd
++;
1204 lpszCurr
= lpszEnd
+ 1;
1206 lpszCurr
= NULL
; /* Last Path, terminate after this */
1208 if (!PathAppendW(buff
, lpszFile
))
1210 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1213 if (PathFileExistsDefExtW(buff
, dwWhich
))
1215 strcpyW(lpszFile
, buff
);
1216 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1220 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1224 /*************************************************************************
1227 * Search a range of paths for a specific type of executable.
1230 * lpszFile [I/O] File to search for
1231 * lppszOtherDirs [I] Other directories to look in
1232 * dwWhich [I] Type of executable to search for
1235 * Success: TRUE. The path to the executable is stored in lpszFile.
1236 * Failure: FALSE. The path to the executable is unchanged.
1238 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1240 WCHAR szFile
[MAX_PATH
];
1241 WCHAR buff
[MAX_PATH
];
1243 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1245 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1248 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1250 /* Search provided directories first */
1251 if (lppszOtherDirs
&& *lppszOtherDirs
)
1253 WCHAR szOther
[MAX_PATH
];
1254 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1256 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1258 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1259 PathCombineW(buff
, szOther
, szFile
);
1260 if (PathFileExistsDefExtW(buff
, dwWhich
))
1262 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1268 /* Not found, try system and path dirs */
1269 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1271 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1277 /*************************************************************************
1280 * Unicode version of PathFindOnPathExA.
1282 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1284 WCHAR buff
[MAX_PATH
];
1286 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1288 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1291 /* Search provided directories first */
1292 if (lppszOtherDirs
&& *lppszOtherDirs
)
1294 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1295 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1297 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1298 if (PathFileExistsDefExtW(buff
, dwWhich
))
1300 strcpyW(lpszFile
, buff
);
1306 /* Not found, try system and path dirs */
1307 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1310 /*************************************************************************
1311 * PathFindOnPathA [SHLWAPI.@]
1313 * Search a range of paths for an executable.
1316 * lpszFile [I/O] File to search for
1317 * lppszOtherDirs [I] Other directories to look in
1320 * Success: TRUE. The path to the executable is stored in lpszFile.
1321 * Failure: FALSE. The path to the executable is unchanged.
1323 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1325 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1326 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1329 /*************************************************************************
1330 * PathFindOnPathW [SHLWAPI.@]
1332 * See PathFindOnPathA.
1334 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1336 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1337 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1340 /*************************************************************************
1341 * PathCompactPathExA [SHLWAPI.@]
1343 * Compact a path into a given number of characters.
1346 * lpszDest [O] Destination for compacted path
1347 * lpszPath [I] Source path
1348 * cchMax [I] Maximum size of compacted path
1349 * dwFlags [I] Reserved
1352 * Success: TRUE. The compacted path is written to lpszDest.
1353 * Failure: FALSE. lpszPath is undefined.
1356 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1358 * The Win32 version of this function contains a bug: When cchMax == 7,
1359 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1362 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1363 * because Win32 will insert a "\" in lpszDest, even if one is
1364 * not present in the original path.
1366 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1367 UINT cchMax
, DWORD dwFlags
)
1371 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1373 if (lpszPath
&& lpszDest
)
1375 WCHAR szPath
[MAX_PATH
];
1376 WCHAR szDest
[MAX_PATH
];
1378 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1380 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1381 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1386 /*************************************************************************
1387 * PathCompactPathExW [SHLWAPI.@]
1389 * See PathCompactPathExA.
1391 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1392 UINT cchMax
, DWORD dwFlags
)
1394 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1396 DWORD dwLen
, dwFileLen
= 0;
1398 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1405 WARN("Invalid lpszDest would crash under Win32!\n");
1414 dwLen
= strlenW(lpszPath
) + 1;
1418 /* Don't need to compact */
1419 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1423 /* Path must be compacted to fit into lpszDest */
1424 lpszFile
= PathFindFileNameW(lpszPath
);
1425 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1427 if (dwFileLen
== dwLen
)
1429 /* No root in psth */
1432 while (--cchMax
> 0) /* No room left for anything but ellipses */
1437 /* Compact the file name with ellipses at the end */
1439 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1440 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1443 /* We have a root in the path */
1444 lpszFile
--; /* Start compacted filename with the path separator */
1447 if (dwFileLen
+ 3 > cchMax
)
1449 /* Compact the file name */
1452 while (--cchMax
> 0) /* No room left for anything but ellipses */
1457 strcpyW(lpszDest
, szEllipses
);
1460 *lpszDest
++ = *lpszFile
++;
1463 while (--cchMax
> 0) /* No room left for anything but ellipses */
1469 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1470 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1474 /* Only the root needs to be Compacted */
1475 dwLen
= cchMax
- dwFileLen
- 3;
1476 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1477 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1478 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1482 /*************************************************************************
1483 * PathIsRelativeA [SHLWAPI.@]
1485 * Determine if a path is a relative path.
1488 * lpszPath [I] Path to check
1491 * TRUE: The path is relative, or is invalid.
1492 * FALSE: The path is not relative.
1494 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1496 TRACE("(%s)\n",debugstr_a(lpszPath
));
1498 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1500 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1505 /*************************************************************************
1506 * PathIsRelativeW [SHLWAPI.@]
1508 * See PathIsRelativeA.
1510 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1512 TRACE("(%s)\n",debugstr_w(lpszPath
));
1514 if (!lpszPath
|| !*lpszPath
)
1516 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1521 /*************************************************************************
1522 * PathIsRootA [SHLWAPI.@]
1524 * Determine if a path is a root path.
1527 * lpszPath [I] Path to check
1530 * TRUE If lpszPath is valid and a root path,
1533 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1535 TRACE("(%s)\n", debugstr_a(lpszPath
));
1537 if (lpszPath
&& *lpszPath
)
1539 if (*lpszPath
== '\\')
1542 return TRUE
; /* \ */
1543 else if (lpszPath
[1]=='\\')
1545 BOOL bSeenSlash
= FALSE
;
1548 /* Check for UNC root path */
1551 if (*lpszPath
== '\\')
1557 lpszPath
= CharNextA(lpszPath
);
1562 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1563 return TRUE
; /* X:\ */
1568 /*************************************************************************
1569 * PathIsRootW [SHLWAPI.@]
1573 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1575 TRACE("(%s)\n", debugstr_w(lpszPath
));
1577 if (lpszPath
&& *lpszPath
)
1579 if (*lpszPath
== '\\')
1582 return TRUE
; /* \ */
1583 else if (lpszPath
[1]=='\\')
1585 BOOL bSeenSlash
= FALSE
;
1588 /* Check for UNC root path */
1591 if (*lpszPath
== '\\')
1602 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1603 return TRUE
; /* X:\ */
1608 /*************************************************************************
1609 * PathIsDirectoryA [SHLWAPI.@]
1611 * Determine if a path is a valid directory
1614 * lpszPath [I] Path to check.
1617 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1618 * FALSE if lpszPath is invalid or not a directory.
1621 * Although this function is prototyped as returning a BOOL, it returns
1622 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1624 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1629 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1633 TRACE("(%s)\n", debugstr_a(lpszPath
));
1635 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1638 if (PathIsUNCServerShareA(lpszPath
))
1640 FIXME("UNC Server Share not yet supported - FAILING\n");
1644 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1646 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1649 /*************************************************************************
1650 * PathIsDirectoryW [SHLWAPI.@]
1652 * See PathIsDirectoryA.
1654 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1658 TRACE("(%s)\n", debugstr_w(lpszPath
));
1660 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1663 if (PathIsUNCServerShareW(lpszPath
))
1665 FIXME("UNC Server Share not yet supported - FAILING\n");
1669 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1671 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1674 /*************************************************************************
1675 * PathFileExistsA [SHLWAPI.@]
1677 * Determine if a file exists.
1680 * lpszPath [I] Path to check
1683 * TRUE If the file exists and is readable
1686 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1691 TRACE("(%s)\n",debugstr_a(lpszPath
));
1696 /* Prevent a dialog box if path is on a disk that has been ejected. */
1697 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1698 dwAttr
= GetFileAttributesA(lpszPath
);
1699 SetErrorMode(iPrevErrMode
);
1700 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1703 /*************************************************************************
1704 * PathFileExistsW [SHLWAPI.@]
1706 * See PathFileExistsA.
1708 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1713 TRACE("(%s)\n",debugstr_w(lpszPath
));
1718 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1719 dwAttr
= GetFileAttributesW(lpszPath
);
1720 SetErrorMode(iPrevErrMode
);
1721 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1724 /*************************************************************************
1725 * PathFileExistsAndAttributesA [SHLWAPI.445]
1727 * Determine if a file exists.
1730 * lpszPath [I] Path to check
1731 * dwAttr [O] attributes of file
1734 * TRUE If the file exists and is readable
1737 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1742 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1745 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1750 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1751 dwVal
= GetFileAttributesA(lpszPath
);
1752 SetErrorMode(iPrevErrMode
);
1755 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1758 /*************************************************************************
1759 * PathFileExistsAndAttributesW [SHLWAPI.446]
1761 * See PathFileExistsA.
1763 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1768 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1773 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1774 dwVal
= GetFileAttributesW(lpszPath
);
1775 SetErrorMode(iPrevErrMode
);
1778 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1781 /*************************************************************************
1782 * PathMatchSingleMaskA [internal]
1784 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1786 while (*name
&& *mask
&& *mask
!=';')
1792 if (PathMatchSingleMaskA(name
,mask
+1))
1793 return TRUE
; /* try substrings */
1798 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1801 name
= CharNextA(name
);
1802 mask
= CharNextA(mask
);
1807 while (*mask
== '*')
1809 if (!*mask
|| *mask
== ';')
1815 /*************************************************************************
1816 * PathMatchSingleMaskW [internal]
1818 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1820 while (*name
&& *mask
&& *mask
!= ';')
1826 if (PathMatchSingleMaskW(name
,mask
+1))
1827 return TRUE
; /* try substrings */
1832 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1840 while (*mask
== '*')
1842 if (!*mask
|| *mask
== ';')
1848 /*************************************************************************
1849 * PathMatchSpecA [SHLWAPI.@]
1851 * Determine if a path matches one or more search masks.
1854 * lpszPath [I] Path to check
1855 * lpszMask [I] Search mask(s)
1858 * TRUE If lpszPath is valid and is matched
1862 * Multiple search masks may be given if they are separated by ";". The
1863 * pattern "*.*" is treated specially in that it matches all paths (for
1864 * backwards compatibility with DOS).
1866 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1868 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1870 if (!lstrcmpA(lpszMask
, "*.*"))
1871 return TRUE
; /* Matches every path */
1875 while (*lpszMask
== ' ')
1876 lpszMask
++; /* Eat leading spaces */
1878 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1879 return TRUE
; /* Matches the current mask */
1881 while (*lpszMask
&& *lpszMask
!= ';')
1882 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1884 if (*lpszMask
== ';')
1890 /*************************************************************************
1891 * PathMatchSpecW [SHLWAPI.@]
1893 * See PathMatchSpecA.
1895 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1897 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1899 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1901 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1902 return TRUE
; /* Matches every path */
1906 while (*lpszMask
== ' ')
1907 lpszMask
++; /* Eat leading spaces */
1909 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1910 return TRUE
; /* Matches the current path */
1912 while (*lpszMask
&& *lpszMask
!= ';')
1913 lpszMask
++; /* masks separated by ';' */
1915 if (*lpszMask
== ';')
1921 /*************************************************************************
1922 * PathIsSameRootA [SHLWAPI.@]
1924 * Determine if two paths share the same root.
1927 * lpszPath1 [I] Source path
1928 * lpszPath2 [I] Path to compare with
1931 * TRUE If both paths are valid and share the same root.
1932 * FALSE If either path is invalid or the paths do not share the same root.
1934 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1939 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1941 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1944 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1945 if (lpszStart
- lpszPath1
> dwLen
)
1946 return FALSE
; /* Paths not common up to length of the root */
1950 /*************************************************************************
1951 * PathIsSameRootW [SHLWAPI.@]
1953 * See PathIsSameRootA.
1955 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1960 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1962 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1965 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1966 if (lpszStart
- lpszPath1
> dwLen
)
1967 return FALSE
; /* Paths not common up to length of the root */
1971 /*************************************************************************
1972 * PathIsContentTypeA [SHLWAPI.@]
1974 * Determine if a file is of a given registered content type.
1977 * lpszPath [I] File to check
1978 * lpszContentType [I] Content type to check for
1981 * TRUE If lpszPath is a given registered content type,
1985 * This function looks up the registered content type for lpszPath. If
1986 * a content type is registered, it is compared (case insensitively) to
1987 * lpszContentType. Only if this matches does the function succeed.
1989 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
1993 char szBuff
[MAX_PATH
];
1995 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
1997 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
1998 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
1999 REG_NONE
, szBuff
, &dwDummy
) &&
2000 !strcasecmp(lpszContentType
, szBuff
))
2007 /*************************************************************************
2008 * PathIsContentTypeW [SHLWAPI.@]
2010 * See PathIsContentTypeA.
2012 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2014 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2017 WCHAR szBuff
[MAX_PATH
];
2019 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2021 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2022 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2023 REG_NONE
, szBuff
, &dwDummy
) &&
2024 !strcmpiW(lpszContentType
, szBuff
))
2031 /*************************************************************************
2032 * PathIsFileSpecA [SHLWAPI.@]
2034 * Determine if a path is a file specification.
2037 * lpszPath [I] Path to check
2040 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2043 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2045 TRACE("(%s)\n", debugstr_a(lpszPath
));
2052 if (*lpszPath
== '\\' || *lpszPath
== ':')
2054 lpszPath
= CharNextA(lpszPath
);
2059 /*************************************************************************
2060 * PathIsFileSpecW [SHLWAPI.@]
2062 * See PathIsFileSpecA.
2064 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2066 TRACE("(%s)\n", debugstr_w(lpszPath
));
2073 if (*lpszPath
== '\\' || *lpszPath
== ':')
2080 /*************************************************************************
2081 * PathIsPrefixA [SHLWAPI.@]
2083 * Determine if a path is a prefix of another.
2086 * lpszPrefix [I] Prefix
2087 * lpszPath [I] Path to check
2090 * TRUE If lpszPath has lpszPrefix as its prefix,
2091 * FALSE If either path is NULL or lpszPrefix is not a prefix
2093 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2095 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2097 if (lpszPrefix
&& lpszPath
&&
2098 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2103 /*************************************************************************
2104 * PathIsPrefixW [SHLWAPI.@]
2106 * See PathIsPrefixA.
2108 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2110 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2112 if (lpszPrefix
&& lpszPath
&&
2113 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2118 /*************************************************************************
2119 * PathIsSystemFolderA [SHLWAPI.@]
2121 * Determine if a path or file attributes are a system folder.
2124 * lpszPath [I] Path to check.
2125 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2128 * TRUE If lpszPath or dwAttrib are a system folder.
2129 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2131 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2133 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2135 if (lpszPath
&& *lpszPath
)
2136 dwAttrib
= GetFileAttributesA(lpszPath
);
2138 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2139 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2144 /*************************************************************************
2145 * PathIsSystemFolderW [SHLWAPI.@]
2147 * See PathIsSystemFolderA.
2149 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2151 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2153 if (lpszPath
&& *lpszPath
)
2154 dwAttrib
= GetFileAttributesW(lpszPath
);
2156 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2157 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2162 /*************************************************************************
2163 * PathIsUNCA [SHLWAPI.@]
2165 * Determine if a path is in UNC format.
2168 * lpszPath [I] Path to check
2171 * TRUE: The path is UNC.
2172 * FALSE: The path is not UNC or is NULL.
2174 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2176 TRACE("(%s)\n",debugstr_a(lpszPath
));
2178 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2183 /*************************************************************************
2184 * PathIsUNCW [SHLWAPI.@]
2188 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2190 TRACE("(%s)\n",debugstr_w(lpszPath
));
2192 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2197 /*************************************************************************
2198 * PathIsUNCServerA [SHLWAPI.@]
2200 * Determine if a path is a UNC server name ("\\SHARENAME").
2203 * lpszPath [I] Path to check.
2206 * TRUE If lpszPath is a valid UNC server name.
2210 * This routine is bug compatible with Win32: Server names with a
2211 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2212 * Fixing this bug may break other shlwapi functions!
2214 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2216 TRACE("(%s)\n", debugstr_a(lpszPath
));
2218 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2222 if (*lpszPath
== '\\')
2224 lpszPath
= CharNextA(lpszPath
);
2231 /*************************************************************************
2232 * PathIsUNCServerW [SHLWAPI.@]
2234 * See PathIsUNCServerA.
2236 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2238 TRACE("(%s)\n", debugstr_w(lpszPath
));
2240 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2242 return !strchrW( lpszPath
+ 2, '\\' );
2247 /*************************************************************************
2248 * PathIsUNCServerShareA [SHLWAPI.@]
2250 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2253 * lpszPath [I] Path to check.
2256 * TRUE If lpszPath is a valid UNC server share.
2260 * This routine is bug compatible with Win32: Server shares with a
2261 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2262 * Fixing this bug may break other shlwapi functions!
2264 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2266 TRACE("(%s)\n", debugstr_a(lpszPath
));
2268 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2270 BOOL bSeenSlash
= FALSE
;
2273 if (*lpszPath
== '\\')
2279 lpszPath
= CharNextA(lpszPath
);
2286 /*************************************************************************
2287 * PathIsUNCServerShareW [SHLWAPI.@]
2289 * See PathIsUNCServerShareA.
2291 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2293 TRACE("(%s)\n", debugstr_w(lpszPath
));
2295 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2297 BOOL bSeenSlash
= FALSE
;
2300 if (*lpszPath
== '\\')
2313 /*************************************************************************
2314 * PathCanonicalizeA [SHLWAPI.@]
2316 * Convert a path to its canonical form.
2319 * lpszBuf [O] Output path
2320 * lpszPath [I] Path to canonicalize
2323 * Success: TRUE. lpszBuf contains the output path,
2324 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2326 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2330 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2335 if (!lpszBuf
|| !lpszPath
)
2336 SetLastError(ERROR_INVALID_PARAMETER
);
2339 WCHAR szPath
[MAX_PATH
];
2340 WCHAR szBuff
[MAX_PATH
];
2341 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2344 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2347 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2348 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2354 /*************************************************************************
2355 * PathCanonicalizeW [SHLWAPI.@]
2357 * See PathCanonicalizeA.
2359 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2361 LPWSTR lpszDst
= lpszBuf
;
2362 LPCWSTR lpszSrc
= lpszPath
;
2364 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2369 if (!lpszBuf
|| !lpszPath
)
2371 SetLastError(ERROR_INVALID_PARAMETER
);
2382 /* Copy path root */
2383 if (*lpszSrc
== '\\')
2385 *lpszDst
++ = *lpszSrc
++;
2387 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2390 *lpszDst
++ = *lpszSrc
++;
2391 *lpszDst
++ = *lpszSrc
++;
2392 if (*lpszSrc
== '\\')
2393 *lpszDst
++ = *lpszSrc
++;
2396 /* Canonicalize the rest of the path */
2399 if (*lpszSrc
== '.')
2401 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2403 lpszSrc
+= 2; /* Skip .\ */
2405 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2407 /* \.. backs up a directory, over the root if it has no \ following X:.
2408 * .. is ignored if it would remove a UNC server name or initial \\
2410 if (lpszDst
!= lpszBuf
)
2412 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2413 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2414 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2416 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2419 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2421 if (*lpszDst
== '\\')
2422 lpszDst
++; /* Reset to last '\' */
2424 lpszDst
= lpszBuf
; /* Start path again from new root */
2426 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2429 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2431 if (lpszDst
== lpszBuf
)
2437 lpszSrc
+= 2; /* Skip .. in src path */
2440 *lpszDst
++ = *lpszSrc
++;
2443 *lpszDst
++ = *lpszSrc
++;
2445 /* Append \ to naked drive specs */
2446 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2452 /*************************************************************************
2453 * PathFindNextComponentA [SHLWAPI.@]
2455 * Find the next component in a path.
2458 * lpszPath [I] Path to find next component in
2461 * Success: A pointer to the next component, or the end of the string.
2462 * Failure: NULL, If lpszPath is invalid
2465 * A 'component' is either a backslash character (\) or UNC marker (\\).
2466 * Because of this, relative paths (e.g "c:foo") are regarded as having
2467 * only one component.
2469 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2473 TRACE("(%s)\n", debugstr_a(lpszPath
));
2475 if(!lpszPath
|| !*lpszPath
)
2478 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2480 if (lpszSlash
[1] == '\\')
2482 return lpszSlash
+ 1;
2484 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2487 /*************************************************************************
2488 * PathFindNextComponentW [SHLWAPI.@]
2490 * See PathFindNextComponentA.
2492 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2496 TRACE("(%s)\n", debugstr_w(lpszPath
));
2498 if(!lpszPath
|| !*lpszPath
)
2501 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2503 if (lpszSlash
[1] == '\\')
2505 return lpszSlash
+ 1;
2507 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2510 /*************************************************************************
2511 * PathAddExtensionA [SHLWAPI.@]
2513 * Add a file extension to a path
2516 * lpszPath [I/O] Path to add extension to
2517 * lpszExtension [I] Extension to add to lpszPath
2520 * TRUE If the path was modified,
2521 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2522 * extension already, or the new path length is too big.
2525 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2526 * does not do this, so the behaviour was removed.
2528 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2532 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2534 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2537 dwLen
= strlen(lpszPath
);
2539 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2542 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2546 /*************************************************************************
2547 * PathAddExtensionW [SHLWAPI.@]
2549 * See PathAddExtensionA.
2551 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2555 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2557 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2560 dwLen
= strlenW(lpszPath
);
2562 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2565 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2569 /*************************************************************************
2570 * PathMakePrettyA [SHLWAPI.@]
2572 * Convert an uppercase DOS filename into lowercase.
2575 * lpszPath [I/O] Path to convert.
2578 * TRUE If the path was an uppercase DOS path and was converted,
2581 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2583 LPSTR pszIter
= lpszPath
;
2585 TRACE("(%s)\n", debugstr_a(lpszPath
));
2594 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2595 return FALSE
; /* Not DOS path */
2598 pszIter
= lpszPath
+ 1;
2601 *pszIter
= tolower(*pszIter
);
2608 /*************************************************************************
2609 * PathMakePrettyW [SHLWAPI.@]
2611 * See PathMakePrettyA.
2613 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2615 LPWSTR pszIter
= lpszPath
;
2617 TRACE("(%s)\n", debugstr_w(lpszPath
));
2626 if (islowerW(*pszIter
))
2627 return FALSE
; /* Not DOS path */
2630 pszIter
= lpszPath
+ 1;
2633 *pszIter
= tolowerW(*pszIter
);
2640 /*************************************************************************
2641 * PathCommonPrefixA [SHLWAPI.@]
2643 * Determine the length of the common prefix between two paths.
2646 * lpszFile1 [I] First path for comparison
2647 * lpszFile2 [I] Second path for comparison
2648 * achPath [O] Destination for common prefix string
2651 * The length of the common prefix. This is 0 if there is no common
2652 * prefix between the paths or if any parameters are invalid. If the prefix
2653 * is non-zero and achPath is not NULL, achPath is filled with the common
2654 * part of the prefix and NUL terminated.
2657 * A common prefix of 2 is always returned as 3. It is thus possible for
2658 * the length returned to be invalid (i.e. Longer than one or both of the
2659 * strings given as parameters). This Win32 behaviour has been implemented
2660 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2661 * To work around this when using this function, always check that the byte
2662 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2664 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2667 LPCSTR lpszIter1
= lpszFile1
;
2668 LPCSTR lpszIter2
= lpszFile2
;
2670 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2675 if (!lpszFile1
|| !lpszFile2
)
2678 /* Handle roots first */
2679 if (PathIsUNCA(lpszFile1
))
2681 if (!PathIsUNCA(lpszFile2
))
2686 else if (PathIsUNCA(lpszFile2
))
2687 return 0; /* Know already lpszFile1 is not UNC */
2692 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2693 (!*lpszIter2
|| *lpszIter2
== '\\'))
2694 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2696 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2697 break; /* Strings differ at this point */
2704 iLen
++; /* Feature/Bug compatible with Win32 */
2706 if (iLen
&& achPath
)
2708 memcpy(achPath
,lpszFile1
,iLen
);
2709 achPath
[iLen
] = '\0';
2714 /*************************************************************************
2715 * PathCommonPrefixW [SHLWAPI.@]
2717 * See PathCommonPrefixA.
2719 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2722 LPCWSTR lpszIter1
= lpszFile1
;
2723 LPCWSTR lpszIter2
= lpszFile2
;
2725 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2730 if (!lpszFile1
|| !lpszFile2
)
2733 /* Handle roots first */
2734 if (PathIsUNCW(lpszFile1
))
2736 if (!PathIsUNCW(lpszFile2
))
2741 else if (PathIsUNCW(lpszFile2
))
2742 return 0; /* Know already lpszFile1 is not UNC */
2747 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2748 (!*lpszIter2
|| *lpszIter2
== '\\'))
2749 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2751 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2752 break; /* Strings differ at this point */
2759 iLen
++; /* Feature/Bug compatible with Win32 */
2761 if (iLen
&& achPath
)
2763 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2764 achPath
[iLen
] = '\0';
2769 /*************************************************************************
2770 * PathCompactPathA [SHLWAPI.@]
2772 * Make a path fit into a given width when printed to a DC.
2775 * hDc [I] Destination DC
2776 * lpszPath [I/O] Path to be printed to hDc
2777 * dx [I] Desired width
2780 * TRUE If the path was modified/went well.
2783 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2787 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2791 WCHAR szPath
[MAX_PATH
];
2792 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2793 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2794 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2799 /*************************************************************************
2800 * PathCompactPathW [SHLWAPI.@]
2802 * See PathCompactPathA.
2804 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2806 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2809 WCHAR buff
[MAX_PATH
];
2813 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2819 hdc
= hDC
= GetDC(0);
2821 /* Get the length of the whole path */
2822 dwLen
= strlenW(lpszPath
);
2823 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2825 if ((UINT
)size
.cx
> dx
)
2827 /* Path too big, must reduce it */
2829 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2831 sFile
= PathFindFileNameW(lpszPath
);
2832 if (sFile
!= lpszPath
) sFile
--;
2834 /* Get the size of ellipses */
2835 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2836 dwEllipsesLen
= size
.cx
;
2837 /* Get the size of the file name */
2838 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2839 dwPathLen
= size
.cx
;
2841 if (sFile
!= lpszPath
)
2843 LPWSTR sPath
= sFile
;
2844 BOOL bEllipses
= FALSE
;
2846 /* The path includes a file name. Include as much of the path prior to
2847 * the file name as possible, allowing for the ellipses, e.g:
2848 * c:\some very long path\filename ==> c:\some v...\filename
2850 lstrcpynW(buff
, sFile
, MAX_PATH
);
2854 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2856 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2857 dwTotalLen
+= size
.cx
;
2858 if (dwTotalLen
<= dx
)
2866 } while (sPath
> lpszPath
);
2868 if (sPath
> lpszPath
)
2872 strcpyW(sPath
, szEllipses
);
2873 strcpyW(sPath
+3, buff
);
2878 strcpyW(lpszPath
, szEllipses
);
2879 strcpyW(lpszPath
+3, buff
);
2884 /* Trim the path by adding ellipses to the end, e.g:
2885 * A very long file name.txt ==> A very...
2887 dwLen
= strlenW(lpszPath
);
2889 if (dwLen
> MAX_PATH
- 3)
2890 dwLen
= MAX_PATH
- 3;
2891 lstrcpynW(buff
, sFile
, dwLen
);
2895 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2896 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2900 DWORD dwWritten
= 0;
2902 dwEllipsesLen
/= 3; /* Size of a single '.' */
2904 /* Write as much of the Ellipses string as possible */
2905 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2908 dwWritten
+= dwEllipsesLen
;
2916 strcpyW(buff
+ dwLen
, szEllipses
);
2917 strcpyW(lpszPath
, buff
);
2928 /*************************************************************************
2929 * PathGetCharTypeA [SHLWAPI.@]
2931 * Categorise a character from a file path.
2934 * ch [I] Character to get the type of
2937 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2939 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2941 return PathGetCharTypeW(ch
);
2944 /*************************************************************************
2945 * PathGetCharTypeW [SHLWAPI.@]
2947 * See PathGetCharTypeA.
2949 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2953 TRACE("(%d)\n", ch
);
2955 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2956 ch
== '"' || ch
== '|' || ch
== '/')
2957 flags
= GCT_INVALID
; /* Invalid */
2958 else if (ch
== '*' || ch
=='?')
2959 flags
= GCT_WILD
; /* Wildchars */
2960 else if ((ch
== '\\') || (ch
== ':'))
2961 return GCT_SEPARATOR
; /* Path separators */
2966 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2967 ch
== '.' || ch
== '@' || ch
== '^' ||
2968 ch
== '\'' || ch
== 130 || ch
== '`')
2969 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2972 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2973 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2978 /*************************************************************************
2979 * SHLWAPI_UseSystemForSystemFolders
2981 * Internal helper for PathMakeSystemFolderW.
2983 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
2985 static BOOL bCheckedReg
= FALSE
;
2986 static BOOL bUseSystemForSystemFolders
= FALSE
;
2992 /* Key tells Win what file attributes to use on system folders */
2993 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
2994 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2995 "UseSystemForSystemFolders", 0, 0, 0))
2996 bUseSystemForSystemFolders
= TRUE
;
2998 return bUseSystemForSystemFolders
;
3001 /*************************************************************************
3002 * PathMakeSystemFolderA [SHLWAPI.@]
3004 * Set system folder attribute for a path.
3007 * lpszPath [I] The path to turn into a system folder
3010 * TRUE If the path was changed to/already was a system folder
3011 * FALSE If the path is invalid or SetFileAttributesA() fails
3013 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3017 TRACE("(%s)\n", debugstr_a(lpszPath
));
3019 if (lpszPath
&& *lpszPath
)
3021 WCHAR szPath
[MAX_PATH
];
3022 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3023 bRet
= PathMakeSystemFolderW(szPath
);
3028 /*************************************************************************
3029 * PathMakeSystemFolderW [SHLWAPI.@]
3031 * See PathMakeSystemFolderA.
3033 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3035 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3036 WCHAR buff
[MAX_PATH
];
3038 TRACE("(%s)\n", debugstr_w(lpszPath
));
3040 if (!lpszPath
|| !*lpszPath
)
3043 /* If the directory is already a system directory, don't do anything */
3044 GetSystemDirectoryW(buff
, MAX_PATH
);
3045 if (!strcmpW(buff
, lpszPath
))
3048 GetWindowsDirectoryW(buff
, MAX_PATH
);
3049 if (!strcmpW(buff
, lpszPath
))
3052 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3053 if (SHLWAPI_UseSystemForSystemFolders())
3054 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3056 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3059 /* Change file attributes to system attributes */
3060 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3061 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3064 /*************************************************************************
3065 * PathRenameExtensionA [SHLWAPI.@]
3067 * Swap the file extension in a path with another extension.
3070 * lpszPath [I/O] Path to swap the extension in
3071 * lpszExt [I] The new extension
3074 * TRUE if lpszPath was modified,
3075 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3077 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3079 LPSTR lpszExtension
;
3081 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3083 lpszExtension
= PathFindExtensionA(lpszPath
);
3085 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3088 strcpy(lpszExtension
, lpszExt
);
3092 /*************************************************************************
3093 * PathRenameExtensionW [SHLWAPI.@]
3095 * See PathRenameExtensionA.
3097 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3099 LPWSTR lpszExtension
;
3101 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3103 lpszExtension
= PathFindExtensionW(lpszPath
);
3105 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3108 strcpyW(lpszExtension
, lpszExt
);
3112 /*************************************************************************
3113 * PathSearchAndQualifyA [SHLWAPI.@]
3115 * Determine if a given path is correct and fully qualified.
3118 * lpszPath [I] Path to check
3119 * lpszBuf [O] Output for correct path
3120 * cchBuf [I] Size of lpszBuf
3125 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3127 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3129 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3131 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3134 /*************************************************************************
3135 * PathSearchAndQualifyW [SHLWAPI.@]
3137 * See PathSearchAndQualifyA.
3139 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3141 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3143 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3145 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3148 /*************************************************************************
3149 * PathSkipRootA [SHLWAPI.@]
3151 * Return the portion of a path following the drive letter or mount point.
3154 * lpszPath [I] The path to skip on
3157 * Success: A pointer to the next character after the root.
3158 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3160 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3162 TRACE("(%s)\n", debugstr_a(lpszPath
));
3164 if (!lpszPath
|| !*lpszPath
)
3167 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3169 /* Network share: skip share server and mount point */
3171 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3172 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3174 return (LPSTR
)lpszPath
;
3177 if (IsDBCSLeadByte(*lpszPath
))
3181 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3182 return (LPSTR
)lpszPath
+ 3;
3186 /*************************************************************************
3187 * PathSkipRootW [SHLWAPI.@]
3189 * See PathSkipRootA.
3191 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3193 TRACE("(%s)\n", debugstr_w(lpszPath
));
3195 if (!lpszPath
|| !*lpszPath
)
3198 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3200 /* Network share: skip share server and mount point */
3202 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3203 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3205 return (LPWSTR
)lpszPath
;
3209 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3210 return (LPWSTR
)lpszPath
+ 3;
3214 /*************************************************************************
3215 * PathCreateFromUrlA [SHLWAPI.@]
3217 * See PathCreateFromUrlW
3219 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3220 LPDWORD pcchPath
, DWORD dwReserved
)
3222 WCHAR bufW
[MAX_PATH
];
3223 WCHAR
*pathW
= bufW
;
3224 UNICODE_STRING urlW
;
3226 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3228 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3229 return E_INVALIDARG
;
3231 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3232 return E_INVALIDARG
;
3233 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3234 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3235 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3238 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3239 if(*pcchPath
> lenA
) {
3240 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3244 *pcchPath
= lenA
+ 1;
3248 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3249 RtlFreeUnicodeString(&urlW
);
3253 /*************************************************************************
3254 * PathCreateFromUrlW [SHLWAPI.@]
3256 * Create a path from a URL
3259 * lpszUrl [I] URL to convert into a path
3260 * lpszPath [O] Output buffer for the resulting Path
3261 * pcchPath [I] Length of lpszPath
3262 * dwFlags [I] Flags controlling the conversion
3265 * Success: S_OK. lpszPath contains the URL in path format,
3266 * Failure: An HRESULT error code such as E_INVALIDARG.
3268 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3269 LPDWORD pcchPath
, DWORD dwReserved
)
3271 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3272 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3273 DWORD nslashes
, unescape
, len
;
3278 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3280 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3281 return E_INVALIDARG
;
3283 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3284 file_colon
, 5) != CSTR_EQUAL
)
3285 return E_INVALIDARG
;
3291 while (*src
== '/' || *src
== '\\') {
3296 /* We need a temporary buffer so we can compute what size to ask for.
3297 * We know that the final string won't be longer than the current pszUrl
3298 * plus at most two backslashes. All the other transformations make it
3301 len
= 2 + lstrlenW(pszUrl
) + 1;
3302 if (*pcchPath
< len
)
3303 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3313 /* 'file:' + escaped DOS path */
3316 /* 'file:/' + escaped DOS path */
3319 /* 'file:///' (implied localhost) + escaped DOS path */
3320 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3324 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, src
, 9,
3325 localhost
, 9) == CSTR_EQUAL
&&
3326 (src
[9] == '/' || src
[9] == '\\'))
3328 /* 'file://localhost/' + escaped DOS path */
3331 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3333 /* 'file://' + unescaped DOS path */
3338 /* 'file://hostname:port/path' (where path is escaped)
3339 * or 'file:' + escaped UNC path (\\server\share\path)
3340 * The second form is clearly specific to Windows and it might
3341 * even be doing a network lookup to try to figure it out.
3343 while (*src
&& *src
!= '/' && *src
!= '\\')
3346 StrCpyNW(dst
, pszUrl
, len
+ 1);
3348 if (*src
&& isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3350 /* 'Forget' to add a trailing '/', just like Windows */
3356 /* 'file://' + unescaped UNC path (\\server\share\path) */
3358 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3362 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3366 /* Copy the remainder of the path */
3367 len
+= lstrlenW(src
);
3370 /* First do the Windows-specific path conversions */
3371 for (dst
= tpath
; *dst
; dst
++)
3372 if (*dst
== '/') *dst
= '\\';
3373 if (isalphaW(*tpath
) && tpath
[1] == '|')
3374 tpath
[1] = ':'; /* c| -> c: */
3376 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3379 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3382 /* When working in-place UrlUnescapeW() does not set len */
3383 len
= lstrlenW(tpath
);
3387 if (*pcchPath
< len
+ 1)
3390 *pcchPath
= len
+ 1;
3395 if (tpath
!= pszPath
)
3396 StrCpyW(pszPath
, tpath
);
3398 if (tpath
!= pszPath
)
3399 HeapFree(GetProcessHeap(), 0, tpath
);
3401 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3405 /*************************************************************************
3406 * PathCreateFromUrlAlloc [SHLWAPI.@]
3408 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3411 WCHAR pathW
[MAX_PATH
];
3416 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3419 /* Yes, this is supposed to crash if pszPath is NULL */
3420 *pszPath
= StrDupW(pathW
);
3425 /*************************************************************************
3426 * PathRelativePathToA [SHLWAPI.@]
3428 * Create a relative path from one path to another.
3431 * lpszPath [O] Destination for relative path
3432 * lpszFrom [I] Source path
3433 * dwAttrFrom [I] File attribute of source path
3434 * lpszTo [I] Destination path
3435 * dwAttrTo [I] File attributes of destination path
3438 * TRUE If a relative path can be formed. lpszPath contains the new path
3439 * FALSE If the paths are not relative or any parameters are invalid
3442 * lpszTo should be at least MAX_PATH in length.
3444 * Calling this function with relative paths for lpszFrom or lpszTo may
3445 * give erroneous results.
3447 * The Win32 version of this function contains a bug where the lpszTo string
3448 * may be referenced 1 byte beyond the end of the string. As a result random
3449 * garbage may be written to the output path, depending on what lies beyond
3450 * the last byte of the string. This bug occurs because of the behaviour of
3451 * PathCommonPrefix() (see notes for that function), and no workaround seems
3452 * possible with Win32.
3454 * This bug has been fixed here, so for example the relative path from "\\"
3455 * to "\\" is correctly determined as "." in this implementation.
3457 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3458 LPCSTR lpszTo
, DWORD dwAttrTo
)
3462 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3463 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3465 if(lpszPath
&& lpszFrom
&& lpszTo
)
3467 WCHAR szPath
[MAX_PATH
];
3468 WCHAR szFrom
[MAX_PATH
];
3469 WCHAR szTo
[MAX_PATH
];
3470 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3471 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3472 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3473 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3478 /*************************************************************************
3479 * PathRelativePathToW [SHLWAPI.@]
3481 * See PathRelativePathToA.
3483 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3484 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3486 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3487 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3488 WCHAR szFrom
[MAX_PATH
];
3489 WCHAR szTo
[MAX_PATH
];
3492 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3493 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3495 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3499 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3500 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3502 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3503 PathRemoveFileSpecW(szFrom
);
3504 if(!(dwAttrTo
& FILE_ATTRIBUTE_DIRECTORY
))
3505 PathRemoveFileSpecW(szTo
);
3507 /* Paths can only be relative if they have a common root */
3508 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3511 /* Strip off lpszFrom components to the root, by adding "..\" */
3512 lpszFrom
= szFrom
+ dwLen
;
3518 if (*lpszFrom
== '\\')
3523 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3524 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3527 /* From the root add the components of lpszTo */
3529 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3532 if (*lpszTo
&& lpszTo
[-1])
3534 if (*lpszTo
!= '\\')
3536 dwLen
= strlenW(lpszPath
);
3537 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3542 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3547 /*************************************************************************
3548 * PathUnmakeSystemFolderA [SHLWAPI.@]
3550 * Remove the system folder attributes from a path.
3553 * lpszPath [I] The path to remove attributes from
3557 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3558 * SetFileAttributesA() fails.
3560 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3564 TRACE("(%s)\n", debugstr_a(lpszPath
));
3566 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3567 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3570 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3571 return SetFileAttributesA(lpszPath
, dwAttr
);
3574 /*************************************************************************
3575 * PathUnmakeSystemFolderW [SHLWAPI.@]
3577 * See PathUnmakeSystemFolderA.
3579 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3583 TRACE("(%s)\n", debugstr_w(lpszPath
));
3585 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3586 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3589 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3590 return SetFileAttributesW(lpszPath
, dwAttr
);
3594 /*************************************************************************
3595 * PathSetDlgItemPathA [SHLWAPI.@]
3597 * Set the text of a dialog item to a path, shrinking the path to fit
3598 * if it is too big for the item.
3601 * hDlg [I] Dialog handle
3602 * id [I] ID of item in the dialog
3603 * lpszPath [I] Path to set as the items text
3609 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3610 * window text is erased).
3612 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3614 WCHAR szPath
[MAX_PATH
];
3616 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3619 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3622 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3625 /*************************************************************************
3626 * PathSetDlgItemPathW [SHLWAPI.@]
3628 * See PathSetDlgItemPathA.
3630 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3632 WCHAR path
[MAX_PATH
+ 1];
3638 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3640 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3644 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3648 GetClientRect(hwItem
, &rect
);
3650 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3654 PathCompactPathW(hdc
, path
, rect
.right
);
3655 SelectObject(hdc
, hPrevObj
);
3658 ReleaseDC(hDlg
, hdc
);
3659 SetWindowTextW(hwItem
, path
);
3662 /*************************************************************************
3663 * PathIsNetworkPathA [SHLWAPI.@]
3665 * Determine if the given path is a network path.
3668 * lpszPath [I] Path to check
3671 * TRUE If lpszPath is a UNC share or mapped network drive, or
3672 * FALSE If lpszPath is a local drive or cannot be determined
3674 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3678 TRACE("(%s)\n",debugstr_a(lpszPath
));
3682 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3684 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3685 if (dwDriveNum
== -1)
3687 return IsNetDrive(dwDriveNum
);
3690 /*************************************************************************
3691 * PathIsNetworkPathW [SHLWAPI.@]
3693 * See PathIsNetworkPathA.
3695 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3699 TRACE("(%s)\n", debugstr_w(lpszPath
));
3703 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3705 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3706 if (dwDriveNum
== -1)
3708 return IsNetDrive(dwDriveNum
);
3711 /*************************************************************************
3712 * PathIsLFNFileSpecA [SHLWAPI.@]
3714 * Determine if the given path is a long file name
3717 * lpszPath [I] Path to check
3720 * TRUE If path is a long file name,
3721 * FALSE If path is a valid DOS short file name
3723 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3725 DWORD dwNameLen
= 0, dwExtLen
= 0;
3727 TRACE("(%s)\n",debugstr_a(lpszPath
));
3734 if (*lpszPath
== ' ')
3735 return TRUE
; /* DOS names cannot have spaces */
3736 if (*lpszPath
== '.')
3739 return TRUE
; /* DOS names have only one dot */
3746 return TRUE
; /* DOS extensions are <= 3 chars*/
3752 return TRUE
; /* DOS names are <= 8 chars */
3754 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3756 return FALSE
; /* Valid DOS path */
3759 /*************************************************************************
3760 * PathIsLFNFileSpecW [SHLWAPI.@]
3762 * See PathIsLFNFileSpecA.
3764 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3766 DWORD dwNameLen
= 0, dwExtLen
= 0;
3768 TRACE("(%s)\n",debugstr_w(lpszPath
));
3775 if (*lpszPath
== ' ')
3776 return TRUE
; /* DOS names cannot have spaces */
3777 if (*lpszPath
== '.')
3780 return TRUE
; /* DOS names have only one dot */
3787 return TRUE
; /* DOS extensions are <= 3 chars*/
3793 return TRUE
; /* DOS names are <= 8 chars */
3797 return FALSE
; /* Valid DOS path */
3800 /*************************************************************************
3801 * PathIsDirectoryEmptyA [SHLWAPI.@]
3803 * Determine if a given directory is empty.
3806 * lpszPath [I] Directory to check
3809 * TRUE If the directory exists and contains no files,
3812 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3816 TRACE("(%s)\n",debugstr_a(lpszPath
));
3820 WCHAR szPath
[MAX_PATH
];
3821 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3822 bRet
= PathIsDirectoryEmptyW(szPath
);
3827 /*************************************************************************
3828 * PathIsDirectoryEmptyW [SHLWAPI.@]
3830 * See PathIsDirectoryEmptyA.
3832 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3834 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3835 WCHAR szSearch
[MAX_PATH
];
3838 BOOL retVal
= FALSE
;
3839 WIN32_FIND_DATAW find_data
;
3841 TRACE("(%s)\n",debugstr_w(lpszPath
));
3843 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3846 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3847 PathAddBackslashW(szSearch
);
3848 dwLen
= strlenW(szSearch
);
3849 if (dwLen
> MAX_PATH
- 4)
3852 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3853 hfind
= FindFirstFileW(szSearch
, &find_data
);
3854 if (hfind
!= INVALID_HANDLE_VALUE
)
3856 if (find_data
.cFileName
[0] == '.' && find_data
.cFileName
[1] == '.')
3857 /* The only directory entry should be the parent */
3858 retVal
= !FindNextFileW(hfind
, &find_data
);
3866 /*************************************************************************
3867 * PathFindSuffixArrayA [SHLWAPI.@]
3869 * Find a suffix string in an array of suffix strings
3872 * lpszSuffix [I] Suffix string to search for
3873 * lppszArray [I] Array of suffix strings to search
3874 * dwCount [I] Number of elements in lppszArray
3877 * Success: The index of the position of lpszSuffix in lppszArray
3878 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3881 * The search is case sensitive.
3882 * The match is made against the end of the suffix string, so for example:
3883 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3885 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3890 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3892 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3894 dwLen
= strlen(lpszSuffix
);
3896 while (dwRet
< dwCount
)
3898 size_t dwCompareLen
= strlen(*lppszArray
);
3899 if (dwCompareLen
< dwLen
)
3901 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3902 return *lppszArray
; /* Found */
3911 /*************************************************************************
3912 * PathFindSuffixArrayW [SHLWAPI.@]
3914 * See PathFindSuffixArrayA.
3916 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3921 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3923 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3925 dwLen
= strlenW(lpszSuffix
);
3927 while (dwRet
< dwCount
)
3929 size_t dwCompareLen
= strlenW(*lppszArray
);
3930 if (dwCompareLen
< dwLen
)
3932 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3933 return *lppszArray
; /* Found */
3942 /*************************************************************************
3943 * PathUndecorateA [SHLWAPI.@]
3945 * Undecorate a file path
3948 * lpszPath [I/O] Path to remove any decoration from
3954 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3956 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3958 TRACE("(%s)\n",debugstr_a(lpszPath
));
3962 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3963 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3965 LPSTR lpszSkip
= lpszExt
- 2;
3966 if (*lpszSkip
== '[')
3967 lpszSkip
++; /* [] (no number) */
3969 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3971 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3973 /* remove the [n] */
3976 *lpszSkip
++ = *lpszExt
++;
3983 /*************************************************************************
3984 * PathUndecorateW [SHLWAPI.@]
3986 * See PathUndecorateA.
3988 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3990 TRACE("(%s)\n",debugstr_w(lpszPath
));
3994 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3995 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3997 LPWSTR lpszSkip
= lpszExt
- 2;
3998 if (*lpszSkip
== '[')
3999 lpszSkip
++; /* [] (no number) */
4001 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4003 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4005 /* remove the [n] */
4008 *lpszSkip
++ = *lpszExt
++;
4015 /*************************************************************************
4016 * PathUnExpandEnvStringsA [SHLWAPI.@]
4018 * Substitute folder names in a path with their corresponding environment
4022 * path [I] Buffer containing the path to unexpand.
4023 * buffer [O] Buffer to receive the unexpanded path.
4024 * buf_len [I] Size of pszBuf in characters.
4030 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4032 WCHAR bufferW
[MAX_PATH
], *pathW
;
4036 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4038 pathW
= heap_strdupAtoW(path
);
4039 if (!pathW
) return FALSE
;
4041 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4042 HeapFree(GetProcessHeap(), 0, pathW
);
4043 if (!ret
) return FALSE
;
4045 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4046 if (buf_len
< len
+ 1) return FALSE
;
4048 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4052 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4053 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4054 static const WCHAR computernameW
[] = {'%','C','O','M','P','U','T','E','R','N','A','M','E','%',0};
4055 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4056 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4057 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4058 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4064 WCHAR path
[MAX_PATH
];
4068 static void init_envvars_map(struct envvars_map
*map
)
4072 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4073 /* exclude null from length */
4074 if (map
->len
) map
->len
--;
4079 /*************************************************************************
4080 * PathUnExpandEnvStringsW [SHLWAPI.@]
4082 * Unicode version of PathUnExpandEnvStringsA.
4084 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4086 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4087 struct envvars_map
*match
= &null_var
, *cur
;
4088 struct envvars_map envvars
[] = {
4089 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4090 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4091 { computernameW
, sizeof(computernameW
)/sizeof(WCHAR
) },
4092 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4093 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4094 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4095 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4101 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4103 pathlen
= strlenW(path
);
4104 init_envvars_map(envvars
);
4108 /* path can't contain expanded value or value wasn't retrieved */
4109 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4115 if (cur
->len
> match
->len
)
4120 /* 'varlen' includes NULL termination char */
4121 needed
= match
->varlen
+ pathlen
- match
->len
;
4122 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4124 strcpyW(buffer
, match
->var
);
4125 strcatW(buffer
, &path
[match
->len
]);
4126 TRACE("ret %s\n", debugstr_w(buffer
));
4131 /*************************************************************************
4134 * Find localised or default web content in "%WINDOWS%\web\".
4137 * lpszFile [I] File name containing content to look for
4138 * lpszPath [O] Buffer to contain the full path to the file
4139 * dwPathLen [I] Length of lpszPath
4142 * Success: S_OK. lpszPath contains the full path to the content.
4143 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4145 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4147 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4150 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4152 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4154 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4155 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4159 /*************************************************************************
4162 * Unicode version of SHGetWebFolderFilePathA.
4164 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4166 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4167 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4168 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4169 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4170 DWORD dwLen
, dwFileLen
;
4171 LANGID lidSystem
, lidUser
;
4173 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4175 /* Get base directory for web content */
4176 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4177 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4180 dwFileLen
= strlenW(lpszFile
);
4182 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4183 return E_FAIL
; /* lpszPath too short */
4185 strcpyW(lpszPath
+dwLen
, szWeb
);
4187 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4189 lidSystem
= GetSystemDefaultUILanguage();
4190 lidUser
= GetUserDefaultUILanguage();
4192 if (lidSystem
!= lidUser
)
4194 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4196 /* Use localised content in the users UI language if present */
4197 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4198 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4199 if (PathFileExistsW(lpszPath
))
4204 /* Fall back to OS default installed content */
4205 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4206 if (PathFileExistsW(lpszPath
))
4211 #define PATH_CHAR_CLASS_LETTER 0x00000001
4212 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4213 #define PATH_CHAR_CLASS_DOT 0x00000004
4214 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4215 #define PATH_CHAR_CLASS_COLON 0x00000010
4216 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4217 #define PATH_CHAR_CLASS_COMMA 0x00000040
4218 #define PATH_CHAR_CLASS_SPACE 0x00000080
4219 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4220 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4222 #define PATH_CHAR_CLASS_INVALID 0x00000000
4223 #define PATH_CHAR_CLASS_ANY 0xffffffff
4225 static const DWORD SHELL_charclass
[] =
4227 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4228 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4229 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4230 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4231 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4232 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4233 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4234 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4235 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4236 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4237 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4238 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4239 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4240 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4241 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4242 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4243 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4244 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4245 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4246 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4247 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4248 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4249 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4250 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4251 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4252 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4253 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4254 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4255 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4256 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4257 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4258 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4259 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4260 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4261 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4262 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4263 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4264 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4265 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4266 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4267 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4268 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4269 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4270 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4271 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4272 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4273 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4274 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4275 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4276 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4277 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4278 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4279 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4280 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4281 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4282 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4283 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4284 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4285 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4286 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4287 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4288 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4289 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4290 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4293 /*************************************************************************
4296 * Check if an ASCII char is of a certain class
4298 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4300 if ((unsigned)c
> 0x7e)
4301 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4303 return class & SHELL_charclass
[(unsigned)c
];
4306 /*************************************************************************
4309 * Check if a Unicode char is of a certain class
4311 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4314 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4316 return class & SHELL_charclass
[c
];