4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2001, 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #include "wine/unicode.h"
36 #define NO_SHLWAPI_STREAM
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 /* Get a function pointer from a DLL handle */
43 #define GET_FUNC(func, module, name, fail) \
46 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
47 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
48 if (!func) return fail; \
52 /* DLL handles for late bound calls */
53 extern HMODULE SHLWAPI_hshell32
;
55 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
56 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
57 static fnpIsNetDrive pIsNetDrive
;
59 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
61 /*************************************************************************
62 * PathAppendA [SHLWAPI.@]
64 * Append one path to another.
67 * lpszPath [I/O] Initial part of path, and destination for output
68 * lpszAppend [I] Path to append
71 * Success: TRUE. lpszPath contains the newly created path.
72 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
75 * lpszAppend must contain at least one backslash ('\') if not NULL.
76 * Because PathCombineA() is used to join the paths, the resulting
77 * path is also canonicalized.
79 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
81 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
83 if (lpszPath
&& lpszAppend
)
85 if (!PathIsUNCA(lpszAppend
))
86 while (*lpszAppend
== '\\')
88 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
94 /*************************************************************************
95 * PathAppendW [SHLWAPI.@]
99 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
101 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
103 if (lpszPath
&& lpszAppend
)
105 if (!PathIsUNCW(lpszAppend
))
106 while (*lpszAppend
== '\\')
108 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
114 /*************************************************************************
115 * PathCombineA [SHLWAPI.@]
117 * Combine two paths together.
120 * lpszDest [O] Destination for combined path
121 * lpszDir [I] Directory path
122 * lpszFile [I] File path
125 * Success: The output path
126 * Failure: NULL, if inputs are invalid.
129 * lpszDest should be at least MAX_PATH in size, and may point to the same
130 * memory location as lpszDir. The combined path is canonicalised.
132 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
134 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
136 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
137 return NULL
; /* Invalid parameters */
140 WCHAR szDest
[MAX_PATH
];
141 WCHAR szDir
[MAX_PATH
];
142 WCHAR szFile
[MAX_PATH
];
144 MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
);
146 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
147 PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
);
148 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
153 /*************************************************************************
154 * PathCombineW [SHLWAPI.@]
158 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
160 WCHAR szTemp
[MAX_PATH
];
161 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
163 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
165 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
166 return lpszDest
; /* Invalid parameters */
168 if (!lpszFile
|| !*lpszFile
)
171 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
173 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
175 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
178 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
191 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
194 PathStripToRootW(szTemp
);
195 lpszFile
++; /* Skip '\' */
197 if (!PathAddBackslashW(szTemp
))
199 if (strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
201 strcatW(szTemp
, lpszFile
);
204 PathCanonicalizeW(lpszDest
, szTemp
);
208 /*************************************************************************
209 * PathAddBackslashA [SHLWAPI.@]
211 * Append a backslash ('\') to a path if one doesn't exist.
214 * lpszPath [I/O] The path to append a backslash to.
217 * Success: The position of the last backslash in the path.
218 * Failure: NULL, if lpszPath is NULL or the path is too large.
220 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
224 TRACE("(%s)\n",debugstr_a(lpszPath
));
226 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
232 if (lpszPath
[-1] != '\\')
241 /*************************************************************************
242 * PathAddBackslashW [SHLWAPI.@]
244 * See PathAddBackslashA.
246 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
250 TRACE("(%s)\n",debugstr_w(lpszPath
));
252 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
258 if (lpszPath
[-1] != '\\')
267 /*************************************************************************
268 * PathBuildRootA [SHLWAPI.@]
270 * Create a root drive string (e.g. "A:\") from a drive number.
273 * lpszPath [O] Destination for the drive string
279 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
281 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
283 TRACE("(%p,%d)\n", lpszPath
, drive
);
285 if (lpszPath
&& drive
>= 0 && drive
< 26)
287 lpszPath
[0] = 'A' + drive
;
295 /*************************************************************************
296 * PathBuildRootW [SHLWAPI.@]
298 * See PathBuildRootA.
300 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
302 TRACE("(%p,%d)\n", lpszPath
, drive
);
304 if (lpszPath
&& drive
>= 0 && drive
< 26)
306 lpszPath
[0] = 'A' + drive
;
314 /*************************************************************************
315 * PathFindFileNameA [SHLWAPI.@]
317 * Locate the start of the file name in a path
320 * lpszPath [I] Path to search
323 * A pointer to the first character of the file name
325 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
327 LPCSTR lastSlash
= lpszPath
;
329 TRACE("(%s)\n",debugstr_a(lpszPath
));
331 while (lpszPath
&& *lpszPath
)
333 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
334 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
335 lastSlash
= lpszPath
+ 1;
336 lpszPath
= CharNextA(lpszPath
);
338 return (LPSTR
)lastSlash
;
341 /*************************************************************************
342 * PathFindFileNameW [SHLWAPI.@]
344 * See PathFindFileNameA.
346 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
348 LPCWSTR lastSlash
= lpszPath
;
350 TRACE("(%s)\n",debugstr_w(lpszPath
));
352 while (lpszPath
&& *lpszPath
)
354 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
355 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
356 lastSlash
= lpszPath
+ 1;
357 lpszPath
= CharNextW(lpszPath
);
359 return (LPWSTR
)lastSlash
;
362 /*************************************************************************
363 * PathFindExtensionA [SHLWAPI.@]
365 * Locate the start of the file extension in a path
368 * lpszPath [I] The path to search
371 * A pointer to the first character of the extension, the end of
372 * the string if the path has no extension, or NULL If lpszPath is NULL
374 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
376 LPCSTR lastpoint
= NULL
;
378 TRACE("(%s)\n", debugstr_a(lpszPath
));
384 if (*lpszPath
== '\\' || *lpszPath
==' ')
386 else if (*lpszPath
== '.')
387 lastpoint
= lpszPath
;
388 lpszPath
= CharNextA(lpszPath
);
391 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
394 /*************************************************************************
395 * PathFindExtensionW [SHLWAPI.@]
397 * See PathFindExtensionA.
399 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
401 LPCWSTR lastpoint
= NULL
;
403 TRACE("(%s)\n", debugstr_w(lpszPath
));
409 if (*lpszPath
== '\\' || *lpszPath
==' ')
411 else if (*lpszPath
== '.')
412 lastpoint
= lpszPath
;
413 lpszPath
= CharNextW(lpszPath
);
416 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
419 /*************************************************************************
420 * PathGetArgsA [SHLWAPI.@]
422 * Find the next argument in a string delimited by spaces.
425 * lpszPath [I] The string to search for arguments in
428 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
431 * Spaces in quoted strings are ignored as delimiters.
433 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
435 BOOL bSeenQuote
= FALSE
;
437 TRACE("(%s)\n",debugstr_a(lpszPath
));
443 if ((*lpszPath
==' ') && !bSeenQuote
)
444 return (LPSTR
)lpszPath
+ 1;
445 if (*lpszPath
== '"')
446 bSeenQuote
= !bSeenQuote
;
447 lpszPath
= CharNextA(lpszPath
);
450 return (LPSTR
)lpszPath
;
453 /*************************************************************************
454 * PathGetArgsW [SHLWAPI.@]
458 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
460 BOOL bSeenQuote
= FALSE
;
462 TRACE("(%s)\n",debugstr_w(lpszPath
));
468 if ((*lpszPath
==' ') && !bSeenQuote
)
469 return (LPWSTR
)lpszPath
+ 1;
470 if (*lpszPath
== '"')
471 bSeenQuote
= !bSeenQuote
;
472 lpszPath
= CharNextW(lpszPath
);
475 return (LPWSTR
)lpszPath
;
478 /*************************************************************************
479 * PathGetDriveNumberA [SHLWAPI.@]
481 * Return the drive number from a path
484 * lpszPath [I] Path to get the drive number from
487 * Success: The drive number corresponding to the drive in the path
488 * Failure: -1, if lpszPath contains no valid drive
490 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
492 TRACE ("(%s)\n",debugstr_a(lpszPath
));
494 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
495 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
496 return tolower(*lpszPath
) - 'a';
500 /*************************************************************************
501 * PathGetDriveNumberW [SHLWAPI.@]
503 * See PathGetDriveNumberA.
505 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
507 TRACE ("(%s)\n",debugstr_w(lpszPath
));
511 WCHAR tl
= tolowerW(lpszPath
[0]);
512 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
518 /*************************************************************************
519 * PathRemoveFileSpecA [SHLWAPI.@]
521 * Remove the file specification from a path.
524 * lpszPath [I/O] Path to remove the file spec from
527 * TRUE If the path was valid and modified
530 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
532 LPSTR lpszFileSpec
= lpszPath
;
533 BOOL bModified
= FALSE
;
535 TRACE("(%s)\n",debugstr_a(lpszPath
));
539 /* Skip directory or UNC path */
540 if (*lpszPath
== '\\')
541 lpszFileSpec
= ++lpszPath
;
542 if (*lpszPath
== '\\')
543 lpszFileSpec
= ++lpszPath
;
547 if(*lpszPath
== '\\')
548 lpszFileSpec
= lpszPath
; /* Skip dir */
549 else if(*lpszPath
== ':')
551 lpszFileSpec
= ++lpszPath
; /* Skip drive */
552 if (*lpszPath
== '\\')
555 if (!(lpszPath
= CharNextA(lpszPath
)))
561 *lpszFileSpec
= '\0';
568 /*************************************************************************
569 * PathRemoveFileSpecW [SHLWAPI.@]
571 * See PathRemoveFileSpecA.
573 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
575 LPWSTR lpszFileSpec
= lpszPath
;
576 BOOL bModified
= FALSE
;
578 TRACE("(%s)\n",debugstr_w(lpszPath
));
582 /* Skip directory or UNC path */
583 if (*lpszPath
== '\\')
584 lpszFileSpec
= ++lpszPath
;
585 if (*lpszPath
== '\\')
586 lpszFileSpec
= ++lpszPath
;
590 if(*lpszPath
== '\\')
591 lpszFileSpec
= lpszPath
; /* Skip dir */
592 else if(*lpszPath
== ':')
594 lpszFileSpec
= ++lpszPath
; /* Skip drive */
595 if (*lpszPath
== '\\')
598 if (!(lpszPath
= CharNextW(lpszPath
)))
604 *lpszFileSpec
= '\0';
611 /*************************************************************************
612 * PathStripPathA [SHLWAPI.@]
614 * Remove the initial path from the beginning of a filename
617 * lpszPath [I/O] Path to remove the initial path from
622 void WINAPI
PathStripPathA(LPSTR lpszPath
)
624 TRACE("(%s)\n", debugstr_a(lpszPath
));
628 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
630 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
634 /*************************************************************************
635 * PathStripPathW [SHLWAPI.@]
637 * See PathStripPathA.
639 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
643 TRACE("(%s)\n", debugstr_w(lpszPath
));
644 lpszFileName
= PathFindFileNameW(lpszPath
);
646 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
649 /*************************************************************************
650 * PathStripToRootA [SHLWAPI.@]
652 * Reduce a path to its root.
655 * lpszPath [I/O] the path to reduce
658 * Success: TRUE if the stripped path is a root path
659 * Failure: FALSE if the path cannot be stripped or is NULL
661 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
663 TRACE("(%s)\n", debugstr_a(lpszPath
));
667 while(!PathIsRootA(lpszPath
))
668 if (!PathRemoveFileSpecA(lpszPath
))
673 /*************************************************************************
674 * PathStripToRootW [SHLWAPI.@]
676 * See PathStripToRootA.
678 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
680 TRACE("(%s)\n", debugstr_w(lpszPath
));
684 while(!PathIsRootW(lpszPath
))
685 if (!PathRemoveFileSpecW(lpszPath
))
690 /*************************************************************************
691 * PathRemoveArgsA [SHLWAPI.@]
693 * Strip space separated arguments from a path.
696 * lpszPath [I/O] Path to remove arguments from
701 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
703 TRACE("(%s)\n",debugstr_a(lpszPath
));
707 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
712 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
713 if(*lpszLastChar
== ' ')
714 *lpszLastChar
= '\0';
719 /*************************************************************************
720 * PathRemoveArgsW [SHLWAPI.@]
722 * See PathRemoveArgsA.
724 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
726 TRACE("(%s)\n",debugstr_w(lpszPath
));
730 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
735 LPWSTR lpszLastChar
= CharPrevW(lpszPath
, lpszArgs
);
736 if(*lpszLastChar
== ' ')
737 *lpszLastChar
= '\0';
742 /*************************************************************************
743 * PathRemoveExtensionA [SHLWAPI.@]
745 * Remove the file extension from a path
748 * lpszPath [I/O] Path to remove the extension from
753 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
755 TRACE("(%s)\n", debugstr_a(lpszPath
));
759 lpszPath
= PathFindExtensionA(lpszPath
);
764 /*************************************************************************
765 * PathRemoveExtensionW [SHLWAPI.@]
767 * See PathRemoveExtensionA.
769 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
771 TRACE("(%s)\n", debugstr_w(lpszPath
));
775 lpszPath
= PathFindExtensionW(lpszPath
);
780 /*************************************************************************
781 * PathRemoveBackslashA [SHLWAPI.@]
783 * Remove a trailing backslash from a path.
786 * lpszPath [I/O] Path to remove backslash from
789 * Success: A pointer to the end of the path
790 * Failure: NULL, if lpszPath is NULL
792 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
796 TRACE("(%s)\n", debugstr_a(lpszPath
));
800 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
801 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
807 /*************************************************************************
808 * PathRemoveBackslashW [SHLWAPI.@]
810 * See PathRemoveBackslashA.
812 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
814 LPWSTR szTemp
= NULL
;
816 TRACE("(%s)\n", debugstr_w(lpszPath
));
820 szTemp
= CharPrevW(lpszPath
, lpszPath
+ strlenW(lpszPath
));
821 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
827 /*************************************************************************
828 * PathRemoveBlanksA [SHLWAPI.@]
830 * Remove Spaces from the start and end of a path.
833 * lpszPath [I/O] Path to strip blanks from
838 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
840 TRACE("(%s)\n", debugstr_a(lpszPath
));
842 if(lpszPath
&& *lpszPath
)
844 LPSTR start
= lpszPath
;
846 while (*lpszPath
== ' ')
847 lpszPath
= CharNextA(lpszPath
);
850 *start
++ = *lpszPath
++;
852 if (start
!= lpszPath
)
853 while (start
[-1] == ' ')
859 /*************************************************************************
860 * PathRemoveBlanksW [SHLWAPI.@]
862 * See PathRemoveBlanksA.
864 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
866 TRACE("(%s)\n", debugstr_w(lpszPath
));
868 if(lpszPath
&& *lpszPath
)
870 LPWSTR start
= lpszPath
;
872 while (*lpszPath
== ' ')
876 *start
++ = *lpszPath
++;
878 if (start
!= lpszPath
)
879 while (start
[-1] == ' ')
885 /*************************************************************************
886 * PathQuoteSpacesA [SHLWAPI.@]
888 * Surround a path containg spaces in quotes.
891 * lpszPath [I/O] Path to quote
897 * The path is not changed if it is invalid or has no spaces.
899 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
901 TRACE("(%s)\n", debugstr_a(lpszPath
));
903 if(lpszPath
&& StrChrA(lpszPath
,' '))
905 size_t iLen
= strlen(lpszPath
) + 1;
907 if (iLen
+ 2 < MAX_PATH
)
909 memmove(lpszPath
+ 1, lpszPath
, iLen
);
911 lpszPath
[iLen
] = '"';
912 lpszPath
[iLen
+ 1] = '\0';
917 /*************************************************************************
918 * PathQuoteSpacesW [SHLWAPI.@]
920 * See PathQuoteSpacesA.
922 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
924 TRACE("(%s)\n", debugstr_w(lpszPath
));
926 if(lpszPath
&& StrChrW(lpszPath
,' '))
928 int iLen
= strlenW(lpszPath
) + 1;
930 if (iLen
+ 2 < MAX_PATH
)
932 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
934 lpszPath
[iLen
] = '"';
935 lpszPath
[iLen
+ 1] = '\0';
940 /*************************************************************************
941 * PathUnquoteSpacesA [SHLWAPI.@]
943 * Remove quotes ("") from around a path, if present.
946 * lpszPath [I/O] Path to strip quotes from
952 * If the path contains a single quote only, an empty string will result.
953 * Otherwise quotes are only removed if they appear at the start and end
956 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
958 TRACE("(%s)\n", debugstr_a(lpszPath
));
960 if (lpszPath
&& *lpszPath
== '"')
962 DWORD dwLen
= strlen(lpszPath
) - 1;
964 if (lpszPath
[dwLen
] == '"')
966 lpszPath
[dwLen
] = '\0';
967 for (; *lpszPath
; lpszPath
++)
968 *lpszPath
= lpszPath
[1];
973 /*************************************************************************
974 * PathUnquoteSpacesW [SHLWAPI.@]
976 * See PathUnquoteSpacesA.
978 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
980 TRACE("(%s)\n", debugstr_w(lpszPath
));
982 if (lpszPath
&& *lpszPath
== '"')
984 DWORD dwLen
= strlenW(lpszPath
) - 1;
986 if (lpszPath
[dwLen
] == '"')
988 lpszPath
[dwLen
] = '\0';
989 for (; *lpszPath
; lpszPath
++)
990 *lpszPath
= lpszPath
[1];
995 /*************************************************************************
996 * PathParseIconLocationA [SHLWAPI.@]
998 * Parse the location of an icon from a path.
1001 * lpszPath [I/O] The path to parse the icon location from.
1004 * Success: The number of the icon
1005 * Failure: 0 if the path does not contain an icon location or is NULL
1008 * The path has surrounding quotes and spaces removed regardless
1009 * of whether the call succeeds or not.
1011 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1016 TRACE("(%s)\n", debugstr_a(lpszPath
));
1020 if ((lpszComma
= strchr(lpszPath
, ',')))
1022 *lpszComma
++ = '\0';
1023 iRet
= StrToIntA(lpszComma
);
1025 PathUnquoteSpacesA(lpszPath
);
1026 PathRemoveBlanksA(lpszPath
);
1031 /*************************************************************************
1032 * PathParseIconLocationW [SHLWAPI.@]
1034 * See PathParseIconLocationA.
1036 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1041 TRACE("(%s)\n", debugstr_w(lpszPath
));
1045 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1047 *lpszComma
++ = '\0';
1048 iRet
= StrToIntW(lpszComma
);
1050 PathUnquoteSpacesW(lpszPath
);
1051 PathRemoveBlanksW(lpszPath
);
1056 /*************************************************************************
1059 * Unicode version of PathFileExistsDefExtA.
1061 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1063 static const WCHAR pszExts
[7][5] = { { '.', 'p', 'i', 'f', 0},
1064 { '.', 'c', 'o', 'm', 0},
1065 { '.', 'e', 'x', 'e', 0},
1066 { '.', 'b', 'a', 't', 0},
1067 { '.', 'l', 'n', 'k', 0},
1068 { '.', 'c', 'm', 'd', 0},
1071 TRACE("(%s,%ld)\n", debugstr_w(lpszPath
), dwWhich
);
1073 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1078 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1079 if (!*szExt
|| dwWhich
& 0x40)
1082 int iLen
= lstrlenW(lpszPath
);
1083 if (iLen
> (MAX_PATH
- 5))
1085 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1087 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1088 if (PathFileExistsW(lpszPath
))
1093 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1097 return PathFileExistsW(lpszPath
);
1100 /*************************************************************************
1103 * Determine if a file exists locally and is of an executable type.
1106 * lpszPath [I/O] File to search for
1107 * dwWhich [I] Type of executable to search for
1110 * TRUE If the file was found. lpszPath contains the file name.
1114 * lpszPath is modified in place and must be at least MAX_PATH in length.
1115 * If the function returns FALSE, the path is modified to its orginal state.
1116 * If the given path contains an extension or dwWhich is 0, executable
1117 * extensions are not checked.
1119 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1120 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1121 * their own developers exclusive use. Monopoly, anyone?
1123 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1127 TRACE("(%s,%ld)\n", debugstr_a(lpszPath
), dwWhich
);
1131 WCHAR szPath
[MAX_PATH
];
1132 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1133 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1135 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1140 /*************************************************************************
1141 * SHLWAPI_PathFindInOtherDirs
1143 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1145 static BOOL WINAPI
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1147 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1148 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1152 WCHAR buff
[MAX_PATH
];
1154 TRACE("(%s,%08lx)\n", debugstr_w(lpszFile
), dwWhich
);
1156 /* Try system directories */
1157 GetSystemDirectoryW(buff
, MAX_PATH
);
1158 if (!PathAppendW(buff
, lpszFile
))
1160 if (PathFileExistsDefExtW(buff
, dwWhich
))
1162 strcpyW(lpszFile
, buff
);
1165 GetWindowsDirectoryW(buff
, MAX_PATH
);
1166 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1168 if (PathFileExistsDefExtW(buff
, dwWhich
))
1170 strcpyW(lpszFile
, buff
);
1173 GetWindowsDirectoryW(buff
, MAX_PATH
);
1174 if (!PathAppendW(buff
, lpszFile
))
1176 if (PathFileExistsDefExtW(buff
, dwWhich
))
1178 strcpyW(lpszFile
, buff
);
1181 /* Try dirs listed in %PATH% */
1182 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1184 if (!dwLenPATH
|| !(lpszPATH
= malloc((dwLenPATH
+ 1) * sizeof (WCHAR
))))
1187 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1188 lpszCurr
= lpszPATH
;
1191 LPCWSTR lpszEnd
= lpszCurr
;
1192 LPWSTR pBuff
= buff
;
1194 while (*lpszEnd
== ' ')
1196 while (*lpszEnd
&& *lpszEnd
!= ';')
1197 *pBuff
++ = *lpszEnd
++;
1201 lpszCurr
= lpszEnd
+ 1;
1203 lpszCurr
= NULL
; /* Last Path, terminate after this */
1205 if (!PathAppendW(buff
, lpszFile
))
1210 if (PathFileExistsDefExtW(buff
, dwWhich
))
1212 strcpyW(lpszFile
, buff
);
1221 /*************************************************************************
1224 * Search a range of paths for a specific type of executable.
1227 * lpszFile [I/O] File to search for
1228 * lppszOtherDirs [I] Other directories to look in
1229 * dwWhich [I] Type of executable to search for
1232 * Success: TRUE. The path to the executable is stored in lpszFile.
1233 * Failure: FALSE. The path to the executable is unchanged.
1235 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1237 WCHAR szFile
[MAX_PATH
];
1238 WCHAR buff
[MAX_PATH
];
1240 TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1242 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1245 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1247 /* Search provided directories first */
1248 if (lppszOtherDirs
&& *lppszOtherDirs
)
1250 WCHAR szOther
[MAX_PATH
];
1251 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1253 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1255 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1256 PathCombineW(buff
, szOther
, szFile
);
1257 if (PathFileExistsDefExtW(buff
, dwWhich
))
1259 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1265 /* Not found, try system and path dirs */
1266 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1268 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1274 /*************************************************************************
1277 * Unicode version of PathFindOnPathExA.
1279 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1281 WCHAR buff
[MAX_PATH
];
1283 TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1285 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1288 /* Search provided directories first */
1289 if (lppszOtherDirs
&& *lppszOtherDirs
)
1291 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1292 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1294 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1295 if (PathFileExistsDefExtW(buff
, dwWhich
))
1297 strcpyW(lpszFile
, buff
);
1303 /* Not found, try system and path dirs */
1304 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1307 /*************************************************************************
1308 * PathFindOnPathA [SHLWAPI.@]
1310 * Search a range of paths for an executable.
1313 * lpszFile [I/O] File to search for
1314 * lppszOtherDirs [I] Other directories to look in
1317 * Success: TRUE. The path to the executable is stored in lpszFile.
1318 * Failure: FALSE. The path to the executable is unchanged.
1320 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1322 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1323 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1326 /*************************************************************************
1327 * PathFindOnPathW [SHLWAPI.@]
1329 * See PathFindOnPathA.
1331 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1333 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1334 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1337 /*************************************************************************
1338 * PathCompactPathExA [SHLWAPI.@]
1340 * Compact a path into a given number of characters.
1343 * lpszDest [O] Destination for compacted path
1344 * lpszPath [I] Source path
1345 * cchMax [I] Maximum size of compacted path
1346 * dwFlags [I] Reserved
1349 * Success: TRUE. The compacted path is written to lpszDest.
1350 * Failure: FALSE. lpszPath is undefined.
1353 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1355 * The Win32 version of this function contains a bug: When cchMax == 7,
1356 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1359 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1360 * because Win32 will insert a "\" in lpszDest, even if one is
1361 * not present in the original path.
1363 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1364 UINT cchMax
, DWORD dwFlags
)
1368 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1370 if (lpszPath
&& lpszDest
)
1372 WCHAR szPath
[MAX_PATH
];
1373 WCHAR szDest
[MAX_PATH
];
1375 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1377 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1378 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1383 /*************************************************************************
1384 * PathCompactPathExW [SHLWAPI.@]
1386 * See PathCompactPathExA.
1388 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1389 UINT cchMax
, DWORD dwFlags
)
1391 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1393 DWORD dwLen
, dwFileLen
= 0;
1395 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1402 WARN("Invalid lpszDest would crash under Win32!\n");
1411 dwLen
= strlenW(lpszPath
) + 1;
1415 /* Don't need to compact */
1416 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1420 /* Path must be compacted to fit into lpszDest */
1421 lpszFile
= PathFindFileNameW(lpszPath
);
1422 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1424 if (dwFileLen
== dwLen
)
1426 /* No root in psth */
1429 while (--cchMax
> 0) /* No room left for anything but ellipses */
1434 /* Compact the file name with ellipses at the end */
1436 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1437 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1440 /* We have a root in the path */
1441 lpszFile
--; /* Start compacted filename with the path separator */
1444 if (dwFileLen
+ 3 > cchMax
)
1446 /* Compact the file name */
1449 while (--cchMax
> 0) /* No room left for anything but ellipses */
1454 strcpyW(lpszDest
, szEllipses
);
1457 *lpszDest
++ = *lpszFile
++;
1460 while (--cchMax
> 0) /* No room left for anything but ellipses */
1466 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1467 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1471 /* Only the root needs to be Compacted */
1472 dwLen
= cchMax
- dwFileLen
- 3;
1473 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1474 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1475 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1479 /*************************************************************************
1480 * PathIsRelativeA [SHLWAPI.@]
1482 * Determine if a path is a relative path.
1485 * lpszPath [I] Path to check
1488 * TRUE: The path is relative, or is invalid.
1489 * FALSE: The path is not relative.
1491 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1493 TRACE("(%s)\n",debugstr_a(lpszPath
));
1495 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1497 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1502 /*************************************************************************
1503 * PathIsRelativeW [SHLWAPI.@]
1505 * See PathIsRelativeA.
1507 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1509 TRACE("(%s)\n",debugstr_w(lpszPath
));
1511 if (!lpszPath
|| !*lpszPath
)
1513 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1518 /*************************************************************************
1519 * PathIsRootA [SHLWAPI.@]
1521 * Determine if a path is a root path.
1524 * lpszPath [I] Path to check
1527 * TRUE If lpszPath is valid and a root path,
1530 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1532 TRACE("(%s)\n", debugstr_a(lpszPath
));
1534 if (lpszPath
&& *lpszPath
)
1536 if (*lpszPath
== '\\')
1539 return TRUE
; /* \ */
1540 else if (lpszPath
[1]=='\\')
1542 BOOL bSeenSlash
= FALSE
;
1545 /* Check for UNC root path */
1548 if (*lpszPath
== '\\')
1554 lpszPath
= CharNextA(lpszPath
);
1559 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1560 return TRUE
; /* X:\ */
1565 /*************************************************************************
1566 * PathIsRootW [SHLWAPI.@]
1570 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1572 TRACE("(%s)\n", debugstr_w(lpszPath
));
1574 if (lpszPath
&& *lpszPath
)
1576 if (*lpszPath
== '\\')
1579 return TRUE
; /* \ */
1580 else if (lpszPath
[1]=='\\')
1582 BOOL bSeenSlash
= FALSE
;
1585 /* Check for UNC root path */
1588 if (*lpszPath
== '\\')
1594 lpszPath
= CharNextW(lpszPath
);
1599 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1600 return TRUE
; /* X:\ */
1605 /*************************************************************************
1606 * PathIsDirectoryA [SHLWAPI.@]
1608 * Determine if a path is a valid directory
1611 * lpszPath [I] Path to check.
1614 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1615 * FALSE if lpszPath is invalid or not a directory.
1618 * Although this function is prototyped as returning a BOOL, it returns
1619 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1621 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1626 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1630 TRACE("(%s)\n", debugstr_a(lpszPath
));
1632 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1635 if (PathIsUNCServerShareA(lpszPath
))
1637 FIXME("UNC Server Share not yet supported - FAILING\n");
1641 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1643 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1646 /*************************************************************************
1647 * PathIsDirectoryW [SHLWAPI.@]
1649 * See PathIsDirectoryA.
1651 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1655 TRACE("(%s)\n", debugstr_w(lpszPath
));
1657 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1660 if (PathIsUNCServerShareW(lpszPath
))
1662 FIXME("UNC Server Share not yet supported - FAILING\n");
1666 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1668 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1671 /*************************************************************************
1672 * PathFileExistsA [SHLWAPI.@]
1674 * Determine if a file exists.
1677 * lpszPath [I] Path to check
1680 * TRUE If the file exists and is readable
1683 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1688 TRACE("(%s)\n",debugstr_a(lpszPath
));
1693 /* Prevent a dialog box if path is on a disk that has been ejected. */
1694 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1695 dwAttr
= GetFileAttributesA(lpszPath
);
1696 SetErrorMode(iPrevErrMode
);
1697 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1700 /*************************************************************************
1701 * PathFileExistsW [SHLWAPI.@]
1703 * See PathFileExistsA.
1705 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1710 TRACE("(%s)\n",debugstr_w(lpszPath
));
1715 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1716 dwAttr
= GetFileAttributesW(lpszPath
);
1717 SetErrorMode(iPrevErrMode
);
1718 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1721 /*************************************************************************
1722 * PathFileExistsAndAttributesA [SHLWAPI.445]
1724 * Determine if a file exists.
1727 * lpszPath [I] Path to check
1728 * dwAttr [O] attributes of file
1731 * TRUE If the file exists and is readable
1734 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1739 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1742 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1747 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1748 dwVal
= GetFileAttributesA(lpszPath
);
1749 SetErrorMode(iPrevErrMode
);
1752 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1755 /*************************************************************************
1756 * PathFileExistsAndAttributesW [SHLWAPI.446]
1758 * See PathFileExistsA.
1760 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1765 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1770 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1771 dwVal
= GetFileAttributesW(lpszPath
);
1772 SetErrorMode(iPrevErrMode
);
1775 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1778 /*************************************************************************
1779 * PathMatchSingleMaskA [internal]
1781 static BOOL WINAPI
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1783 while (*name
&& *mask
&& *mask
!=';')
1789 if (PathMatchSingleMaskA(name
,mask
+1))
1790 return TRUE
; /* try substrings */
1795 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1798 name
= CharNextA(name
);
1799 mask
= CharNextA(mask
);
1804 while (*mask
== '*')
1806 if (!*mask
|| *mask
== ';')
1812 /*************************************************************************
1813 * PathMatchSingleMaskW [internal]
1815 static BOOL WINAPI
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1817 while (*name
&& *mask
&& *mask
!= ';')
1823 if (PathMatchSingleMaskW(name
,mask
+1))
1824 return TRUE
; /* try substrings */
1829 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1832 name
= CharNextW(name
);
1833 mask
= CharNextW(mask
);
1837 while (*mask
== '*')
1839 if (!*mask
|| *mask
== ';')
1845 /*************************************************************************
1846 * PathMatchSpecA [SHLWAPI.@]
1848 * Determine if a path matches one or more search masks.
1851 * lpszPath [I] Path to check
1852 * lpszMask [I] Search mask(s)
1855 * TRUE If lpszPath is valid and is matched
1859 * Multiple search masks may be given if they are separated by ";". The
1860 * pattern "*.*" is treated specially in that it matches all paths (for
1861 * backwards compatibility with DOS).
1863 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1865 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1867 if (!lstrcmpA(lpszMask
, "*.*"))
1868 return TRUE
; /* Matches every path */
1872 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1873 return TRUE
; /* Matches the current mask */
1875 while (*lpszMask
&& *lpszMask
!= ';')
1876 lpszMask
= CharNextA(lpszMask
);
1878 if (*lpszMask
== ';')
1881 while (*lpszMask
== ' ')
1882 lpszMask
++; /* masks may be separated by "; " */
1888 /*************************************************************************
1889 * PathMatchSpecW [SHLWAPI.@]
1891 * See PathMatchSpecA.
1893 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1895 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1897 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1899 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1900 return TRUE
; /* Matches every path */
1904 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1905 return TRUE
; /* Matches the current path */
1907 while (*lpszMask
&& *lpszMask
!= ';')
1910 if (*lpszMask
== ';')
1913 while (*lpszMask
== ' ')
1914 lpszMask
++; /* Masks may be separated by "; " */
1920 /*************************************************************************
1921 * PathIsSameRootA [SHLWAPI.@]
1923 * Determine if two paths share the same root.
1926 * lpszPath1 [I] Source path
1927 * lpszPath2 [I] Path to compare with
1930 * TRUE If both paths are valid and share the same root.
1931 * FALSE If either path is invalid or the paths do not share the same root.
1933 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1938 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1940 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1943 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1944 if (lpszStart
- lpszPath1
> dwLen
)
1945 return FALSE
; /* Paths not common up to length of the root */
1949 /*************************************************************************
1950 * PathIsSameRootW [SHLWAPI.@]
1952 * See PathIsSameRootA.
1954 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1959 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1961 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1964 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1965 if (lpszStart
- lpszPath1
> dwLen
)
1966 return FALSE
; /* Paths not common up to length of the root */
1970 /*************************************************************************
1971 * PathIsContentTypeA [SHLWAPI.@]
1973 * Determine if a file is of a given registered content type.
1976 * lpszPath [I] File to check
1977 * lpszContentType [I] Content type to check for
1980 * TRUE If lpszPath is a given registered content type,
1984 * This function looks up the registered content type for lpszPath. If
1985 * a content type is registered, it is compared (case insensitively) to
1986 * lpszContentType. Only if this matches does the function succeed.
1988 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
1992 char szBuff
[MAX_PATH
];
1994 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
1996 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
1997 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
1998 REG_NONE
, szBuff
, &dwDummy
) &&
1999 !strcasecmp(lpszContentType
, szBuff
))
2006 /*************************************************************************
2007 * PathIsContentTypeW [SHLWAPI.@]
2009 * See PathIsContentTypeA.
2011 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2013 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2016 WCHAR szBuff
[MAX_PATH
];
2018 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2020 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2021 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2022 REG_NONE
, szBuff
, &dwDummy
) &&
2023 !strcmpiW(lpszContentType
, szBuff
))
2030 /*************************************************************************
2031 * PathIsFileSpecA [SHLWAPI.@]
2033 * Determine if a path is a file specification.
2036 * lpszPath [I] Path to chack
2039 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2042 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2044 TRACE("(%s)\n", debugstr_a(lpszPath
));
2051 if (*lpszPath
== '\\' || *lpszPath
== ':')
2053 lpszPath
= CharNextA(lpszPath
);
2058 /*************************************************************************
2059 * PathIsFileSpecW [SHLWAPI.@]
2061 * See PathIsFileSpecA.
2063 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2065 TRACE("(%s)\n", debugstr_w(lpszPath
));
2072 if (*lpszPath
== '\\' || *lpszPath
== ':')
2074 lpszPath
= CharNextW(lpszPath
);
2079 /*************************************************************************
2080 * PathIsPrefixA [SHLWAPI.@]
2082 * Determine if a path is a prefix of another.
2085 * lpszPrefix [I] Prefix
2086 * lpszPath [I] Path to check
2089 * TRUE If lpszPath has lpszPrefix as its prefix,
2090 * FALSE If either path is NULL or lpszPrefix is not a prefix
2092 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2094 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2096 if (lpszPrefix
&& lpszPath
&&
2097 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2102 /*************************************************************************
2103 * PathIsPrefixW [SHLWAPI.@]
2105 * See PathIsPrefixA.
2107 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2109 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2111 if (lpszPrefix
&& lpszPath
&&
2112 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2117 /*************************************************************************
2118 * PathIsSystemFolderA [SHLWAPI.@]
2120 * Determine if a path or file attributes are a system folder.
2123 * lpszPath [I] Path to check.
2124 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2127 * TRUE If lpszPath or dwAttrib are a system folder.
2128 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2130 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2132 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath
), dwAttrib
);
2134 if (lpszPath
&& *lpszPath
)
2135 dwAttrib
= GetFileAttributesA(lpszPath
);
2137 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2138 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2143 /*************************************************************************
2144 * PathIsSystemFolderW [SHLWAPI.@]
2146 * See PathIsSystemFolderA.
2148 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2150 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath
), dwAttrib
);
2152 if (lpszPath
&& *lpszPath
)
2153 dwAttrib
= GetFileAttributesW(lpszPath
);
2155 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2156 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2161 /*************************************************************************
2162 * PathIsUNCA [SHLWAPI.@]
2164 * Determine if a path is in UNC format.
2167 * lpszPath [I] Path to check
2170 * TRUE: The path is UNC.
2171 * FALSE: The path is not UNC or is NULL.
2173 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2175 TRACE("(%s)\n",debugstr_a(lpszPath
));
2177 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2182 /*************************************************************************
2183 * PathIsUNCW [SHLWAPI.@]
2187 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2189 TRACE("(%s)\n",debugstr_w(lpszPath
));
2191 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2196 /*************************************************************************
2197 * PathIsUNCServerA [SHLWAPI.@]
2199 * Determine if a path is a UNC server name ("\\SHARENAME").
2202 * lpszPath [I] Path to check.
2205 * TRUE If lpszPath is a valid UNC server name.
2209 * This routine is bug compatible with Win32: Server names with a
2210 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2211 * Fixing this bug may break other shlwapi functions!
2213 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2215 TRACE("(%s)\n", debugstr_a(lpszPath
));
2217 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2221 if (*lpszPath
== '\\')
2223 lpszPath
= CharNextA(lpszPath
);
2230 /*************************************************************************
2231 * PathIsUNCServerW [SHLWAPI.@]
2233 * See PathIsUNCServerA.
2235 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2237 TRACE("(%s)\n", debugstr_w(lpszPath
));
2239 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2243 if (*lpszPath
== '\\')
2245 lpszPath
= CharNextW(lpszPath
);
2252 /*************************************************************************
2253 * PathIsUNCServerShareA [SHLWAPI.@]
2255 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2258 * lpszPath [I] Path to check.
2261 * TRUE If lpszPath is a valid UNC server share.
2265 * This routine is bug compatible with Win32: Server shares with a
2266 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2267 * Fixing this bug may break other shlwapi functions!
2269 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2271 TRACE("(%s)\n", debugstr_a(lpszPath
));
2273 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2275 BOOL bSeenSlash
= FALSE
;
2278 if (*lpszPath
== '\\')
2284 lpszPath
= CharNextA(lpszPath
);
2291 /*************************************************************************
2292 * PathIsUNCServerShareW [SHLWAPI.@]
2294 * See PathIsUNCServerShareA.
2296 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2298 TRACE("(%s)\n", debugstr_w(lpszPath
));
2300 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2302 BOOL bSeenSlash
= FALSE
;
2305 if (*lpszPath
== '\\')
2311 lpszPath
= CharNextW(lpszPath
);
2318 /*************************************************************************
2319 * PathCanonicalizeA [SHLWAPI.@]
2321 * Convert a path to its canonical form.
2324 * lpszBuf [O] Output path
2325 * lpszPath [I] Path to cnonicalize
2328 * Success: TRUE. lpszBuf contains the output path,
2329 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2331 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2335 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2340 if (!lpszBuf
|| !lpszPath
)
2341 SetLastError(ERROR_INVALID_PARAMETER
);
2344 WCHAR szPath
[MAX_PATH
];
2345 WCHAR szBuff
[MAX_PATH
];
2346 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
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 inital \\
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
)
2833 sFile
= CharPrevW(lpszPath
, sFile
);
2835 /* Get the size of ellipses */
2836 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2837 dwEllipsesLen
= size
.cx
;
2838 /* Get the size of the file name */
2839 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2840 dwPathLen
= size
.cx
;
2842 if (sFile
!= lpszPath
)
2844 LPWSTR sPath
= sFile
;
2845 BOOL bEllipses
= FALSE
;
2847 /* The path includes a file name. Include as much of the path prior to
2848 * the file name as possible, allowing for the ellipses, e.g:
2849 * c:\some very long path\filename ==> c:\some v...\filename
2851 lstrcpynW(buff
, sFile
, MAX_PATH
);
2855 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2857 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2858 dwTotalLen
+= size
.cx
;
2859 if (dwTotalLen
<= dx
)
2861 sPath
= CharPrevW(lpszPath
, sPath
);
2865 sPath
= CharPrevW(lpszPath
, sPath
);
2866 sPath
= CharPrevW(lpszPath
, sPath
);
2868 } while (sPath
> lpszPath
);
2870 if (sPath
> lpszPath
)
2874 strcpyW(sPath
, szEllipses
);
2875 strcpyW(sPath
+3, buff
);
2880 strcpyW(lpszPath
, szEllipses
);
2881 strcpyW(lpszPath
+3, buff
);
2886 /* Trim the path by adding ellipses to the end, e.g:
2887 * A very long file name.txt ==> A very...
2889 dwLen
= strlenW(lpszPath
);
2891 if (dwLen
> MAX_PATH
- 3)
2892 dwLen
= MAX_PATH
- 3;
2893 lstrcpynW(buff
, sFile
, dwLen
);
2897 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2898 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2902 DWORD dwWritten
= 0;
2904 dwEllipsesLen
/= 3; /* Size of a single '.' */
2906 /* Write as much of the Ellipses string as possible */
2907 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2910 dwWritten
+= dwEllipsesLen
;
2918 strcpyW(buff
+ dwLen
, szEllipses
);
2919 strcpyW(lpszPath
, buff
);
2930 /*************************************************************************
2931 * PathGetCharTypeA [SHLWAPI.@]
2933 * Categorise a character from a file path.
2936 * ch [I] Character to get the type of
2939 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2941 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2943 return PathGetCharTypeW(ch
);
2946 /*************************************************************************
2947 * PathGetCharTypeW [SHLWAPI.@]
2949 * See PathGetCharTypeA.
2951 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2955 TRACE("(%d)\n", ch
);
2957 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2958 ch
== '"' || ch
== '|' || ch
== '/')
2959 flags
= GCT_INVALID
; /* Invalid */
2960 else if (ch
== '*' || ch
=='?')
2961 flags
= GCT_WILD
; /* Wildchars */
2962 else if ((ch
== '\\') || (ch
== ':'))
2963 return GCT_SEPARATOR
; /* Path separators */
2968 if ((ch
& 0x1 && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2969 ch
== '.' || ch
== '@' || ch
== '^' ||
2970 ch
== '\'' || ch
== 130 || ch
== '`')
2971 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2974 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2975 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2980 /*************************************************************************
2981 * SHLWAPI_UseSystemForSystemFolders
2983 * Internal helper for PathMakeSystemFolderW.
2985 static BOOL WINAPI
SHLWAPI_UseSystemForSystemFolders(void)
2987 static BOOL bCheckedReg
= FALSE
;
2988 static BOOL bUseSystemForSystemFolders
= FALSE
;
2994 /* Key tells Win what file attributes to use on system folders */
2995 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
2996 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2997 "UseSystemForSystemFolders", 0, 0, 0))
2998 bUseSystemForSystemFolders
= TRUE
;
3000 return bUseSystemForSystemFolders
;
3003 /*************************************************************************
3004 * PathMakeSystemFolderA [SHLWAPI.@]
3006 * Set system folder attribute for a path.
3009 * lpszPath [I] The path to turn into a system folder
3012 * TRUE If the path was changed to/already was a system folder
3013 * FALSE If the path is invalid or SetFileAttributesA() fails
3015 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3019 TRACE("(%s)\n", debugstr_a(lpszPath
));
3021 if (lpszPath
&& *lpszPath
)
3023 WCHAR szPath
[MAX_PATH
];
3024 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3025 bRet
= PathMakeSystemFolderW(szPath
);
3030 /*************************************************************************
3031 * PathMakeSystemFolderW [SHLWAPI.@]
3033 * See PathMakeSystemFolderA.
3035 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3037 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3038 WCHAR buff
[MAX_PATH
];
3040 TRACE("(%s)\n", debugstr_w(lpszPath
));
3042 if (!lpszPath
|| !*lpszPath
)
3045 /* If the directory is already a system directory, don't do anything */
3046 GetSystemDirectoryW(buff
, MAX_PATH
);
3047 if (!strcmpW(buff
, lpszPath
))
3050 GetWindowsDirectoryW(buff
, MAX_PATH
);
3051 if (!strcmpW(buff
, lpszPath
))
3054 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3055 if (SHLWAPI_UseSystemForSystemFolders())
3056 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3058 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3061 /* Change file attributes to system attributes */
3062 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3063 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3066 /*************************************************************************
3067 * PathRenameExtensionA [SHLWAPI.@]
3069 * Swap the file extension in a path with another extension.
3072 * lpszPath [I/O] Path to swap the extension in
3073 * lpszExt [I] The new extension
3076 * TRUE if lpszPath was modified,
3077 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3079 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3081 LPSTR lpszExtension
;
3083 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3085 lpszExtension
= PathFindExtensionA(lpszPath
);
3087 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3090 strcpy(lpszExtension
, lpszExt
);
3094 /*************************************************************************
3095 * PathRenameExtensionW [SHLWAPI.@]
3097 * See PathRenameExtensionA.
3099 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3101 LPWSTR lpszExtension
;
3103 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3105 lpszExtension
= PathFindExtensionW(lpszPath
);
3107 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3110 strcpyW(lpszExtension
, lpszExt
);
3114 /*************************************************************************
3115 * PathSearchAndQualifyA [SHLWAPI.@]
3117 * Determine if a given path is correct and fully qualified.
3120 * lpszPath [I] Path to check
3121 * lpszBuf [O] Output for correct path
3122 * cchBuf [I] Size of lpszBuf
3127 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3129 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3131 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3133 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3136 /*************************************************************************
3137 * PathSearchAndQualifyW [SHLWAPI.@]
3139 * See PathSearchAndQualifyA.
3141 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3143 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3145 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3147 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3150 /*************************************************************************
3151 * PathSkipRootA [SHLWAPI.@]
3153 * Return the portion of a path following the drive letter or mount point.
3156 * lpszPath [I] The path to skip on
3159 * Success: A pointer to the next character after the root.
3160 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3162 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3164 TRACE("(%s)\n", debugstr_a(lpszPath
));
3166 if (!lpszPath
|| !*lpszPath
)
3169 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3171 /* Network share: skip share server and mount point */
3173 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3174 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3176 return (LPSTR
)lpszPath
;
3179 if (IsDBCSLeadByte(*lpszPath
))
3183 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3184 return (LPSTR
)lpszPath
+ 3;
3188 /*************************************************************************
3189 * PathSkipRootW [SHLWAPI.@]
3191 * See PathSkipRootA.
3193 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3195 TRACE("(%s)\n", debugstr_w(lpszPath
));
3197 if (!lpszPath
|| !*lpszPath
)
3200 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3202 /* Network share: skip share server and mount point */
3204 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3205 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3207 return (LPWSTR
)lpszPath
;
3211 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3212 return (LPWSTR
)lpszPath
+ 3;
3216 /*************************************************************************
3217 * PathCreateFromUrlA [SHLWAPI.@]
3219 * See PathCreateFromUrlW
3221 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3222 LPDWORD pcchPath
, DWORD dwReserved
)
3224 WCHAR bufW
[MAX_PATH
];
3225 WCHAR
*pathW
= bufW
;
3226 UNICODE_STRING urlW
;
3228 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3230 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3231 return E_INVALIDARG
;
3232 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3233 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3234 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3237 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3238 if(*pcchPath
> lenA
) {
3239 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3243 *pcchPath
= lenA
+ 1;
3247 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3248 RtlFreeUnicodeString(&urlW
);
3252 /*************************************************************************
3253 * PathCreateFromUrlW [SHLWAPI.@]
3255 * Create a path from a URL
3258 * lpszUrl [I] URL to convert into a path
3259 * lpszPath [O] Output buffer for the resulting Path
3260 * pcchPath [I] Length of lpszPath
3261 * dwFlags [I] Flags controlling the conversion
3264 * Success: S_OK. lpszPath contains the URL in path format,
3265 * Failure: An HRESULT error code such as E_INVALIDARG.
3267 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3268 LPDWORD pcchPath
, DWORD dwReserved
)
3270 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3275 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3277 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3278 return E_INVALIDARG
;
3281 if (strncmpW(pszUrl
, file_colon
, 5))
3282 return E_INVALIDARG
;
3285 while(*pszUrl
== '/' || *pszUrl
== '\\') {
3290 if(isalphaW(*pszUrl
) && (pszUrl
[1] == ':' || pszUrl
[1] == '|') && (pszUrl
[2] == '/' || pszUrl
[2] == '\\'))
3304 hr
= UrlUnescapeW((LPWSTR
)pszUrl
, pszPath
, pcchPath
, 0);
3305 if(hr
!= S_OK
) return hr
;
3307 for(ptr
= pszPath
; *ptr
; ptr
++)
3308 if(*ptr
== '/') *ptr
= '\\';
3310 while(*pszPath
== '\\')
3313 if(isalphaW(*pszPath
) && pszPath
[1] == '|' && pszPath
[2] == '\\') /* c|\ -> c:\ */
3316 if(nslashes
== 2 && (ptr
= strchrW(pszPath
, '\\'))) { /* \\host\c:\ -> \\hostc:\ */
3318 if(isalphaW(*ptr
) && (ptr
[1] == ':' || ptr
[1] == '|') && ptr
[2] == '\\') {
3319 memmove(ptr
- 1, ptr
, (strlenW(ptr
) + 1) * sizeof(WCHAR
));
3324 TRACE("Returning %s\n",debugstr_w(pszPath
));
3329 /*************************************************************************
3330 * PathRelativePathToA [SHLWAPI.@]
3332 * Create a relative path from one path to another.
3335 * lpszPath [O] Destination for relative path
3336 * lpszFrom [I] Source path
3337 * dwAttrFrom [I] File attribute of source path
3338 * lpszTo [I] Destination path
3339 * dwAttrTo [I] File attributes of destination path
3342 * TRUE If a relative path can be formed. lpszPath contains the new path
3343 * FALSE If the paths are not relavtive or any parameters are invalid
3346 * lpszTo should be at least MAX_PATH in length.
3348 * Calling this function with relative paths for lpszFrom or lpszTo may
3349 * give erroneous results.
3351 * The Win32 version of this function contains a bug where the lpszTo string
3352 * may be referenced 1 byte beyond the end of the string. As a result random
3353 * garbage may be written to the output path, depending on what lies beyond
3354 * the last byte of the string. This bug occurs because of the behaviour of
3355 * PathCommonPrefix() (see notes for that function), and no workaround seems
3356 * possible with Win32.
3358 * This bug has been fixed here, so for example the relative path from "\\"
3359 * to "\\" is correctly determined as "." in this implementation.
3361 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3362 LPCSTR lpszTo
, DWORD dwAttrTo
)
3366 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_a(lpszFrom
),
3367 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3369 if(lpszPath
&& lpszFrom
&& lpszTo
)
3371 WCHAR szPath
[MAX_PATH
];
3372 WCHAR szFrom
[MAX_PATH
];
3373 WCHAR szTo
[MAX_PATH
];
3374 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3375 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3376 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3377 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3382 /*************************************************************************
3383 * PathRelativePathToW [SHLWAPI.@]
3385 * See PathRelativePathToA.
3387 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3388 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3390 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3391 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3392 WCHAR szFrom
[MAX_PATH
];
3393 WCHAR szTo
[MAX_PATH
];
3396 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_w(lpszFrom
),
3397 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3399 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3403 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3404 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3406 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3407 PathRemoveFileSpecW(szFrom
);
3408 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3409 PathRemoveFileSpecW(szTo
);
3411 /* Paths can only be relative if they have a common root */
3412 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3415 /* Strip off lpszFrom components to the root, by adding "..\" */
3416 lpszFrom
= szFrom
+ dwLen
;
3422 if (*lpszFrom
== '\\')
3427 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3428 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3431 /* From the root add the components of lpszTo */
3433 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3436 if (*lpszTo
&& lpszTo
[-1])
3438 if (*lpszTo
!= '\\')
3440 dwLen
= strlenW(lpszPath
);
3441 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3446 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3451 /*************************************************************************
3452 * PathUnmakeSystemFolderA [SHLWAPI.@]
3454 * Remove the system folder attributes from a path.
3457 * lpszPath [I] The path to remove attributes from
3461 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3462 * SetFileAttributesA() fails.
3464 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3468 TRACE("(%s)\n", debugstr_a(lpszPath
));
3470 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3471 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3474 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3475 return SetFileAttributesA(lpszPath
, dwAttr
);
3478 /*************************************************************************
3479 * PathUnmakeSystemFolderW [SHLWAPI.@]
3481 * See PathUnmakeSystemFolderA.
3483 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3487 TRACE("(%s)\n", debugstr_w(lpszPath
));
3489 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3490 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3493 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3494 return SetFileAttributesW(lpszPath
, dwAttr
);
3498 /*************************************************************************
3499 * PathSetDlgItemPathA [SHLWAPI.@]
3501 * Set the text of a dialog item to a path, shrinking the path to fit
3502 * if it is too big for the item.
3505 * hDlg [I] Dialog handle
3506 * id [I] ID of item in the dialog
3507 * lpszPath [I] Path to set as the items text
3513 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3514 * window text is erased).
3516 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3518 WCHAR szPath
[MAX_PATH
];
3520 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3523 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3526 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3529 /*************************************************************************
3530 * PathSetDlgItemPathW [SHLWAPI.@]
3532 * See PathSetDlgItemPathA.
3534 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3536 WCHAR path
[MAX_PATH
+ 1];
3542 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3544 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3548 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3552 GetClientRect(hwItem
, &rect
);
3554 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3558 PathCompactPathW(hdc
, path
, rect
.right
);
3559 SelectObject(hdc
, hPrevObj
);
3562 ReleaseDC(hDlg
, hdc
);
3563 SetWindowTextW(hwItem
, path
);
3566 /*************************************************************************
3567 * PathIsNetworkPathA [SHLWAPI.@]
3569 * Determine if the given path is a network path.
3572 * lpszPath [I] Path to check
3575 * TRUE If lpszPath is a UNC share or mapped network drive, or
3576 * FALSE If lpszPath is a local drive or cannot be determined
3578 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3582 TRACE("(%s)\n",debugstr_a(lpszPath
));
3586 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3588 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3589 if (dwDriveNum
== -1)
3591 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3592 return pIsNetDrive(dwDriveNum
);
3595 /*************************************************************************
3596 * PathIsNetworkPathW [SHLWAPI.@]
3598 * See PathIsNetworkPathA.
3600 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3604 TRACE("(%s)\n", debugstr_w(lpszPath
));
3608 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3610 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3611 if (dwDriveNum
== -1)
3613 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3614 return pIsNetDrive(dwDriveNum
);
3617 /*************************************************************************
3618 * PathIsLFNFileSpecA [SHLWAPI.@]
3620 * Determine if the given path is a long file name
3623 * lpszPath [I] Path to check
3626 * TRUE If path is a long file name,
3627 * FALSE If path is a valid DOS short file name
3629 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3631 DWORD dwNameLen
= 0, dwExtLen
= 0;
3633 TRACE("(%s)\n",debugstr_a(lpszPath
));
3640 if (*lpszPath
== ' ')
3641 return TRUE
; /* DOS names cannot have spaces */
3642 if (*lpszPath
== '.')
3645 return TRUE
; /* DOS names have only one dot */
3652 return TRUE
; /* DOS extensions are <= 3 chars*/
3658 return TRUE
; /* DOS names are <= 8 chars */
3660 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3662 return FALSE
; /* Valid DOS path */
3665 /*************************************************************************
3666 * PathIsLFNFileSpecW [SHLWAPI.@]
3668 * See PathIsLFNFileSpecA.
3670 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3672 DWORD dwNameLen
= 0, dwExtLen
= 0;
3674 TRACE("(%s)\n",debugstr_w(lpszPath
));
3681 if (*lpszPath
== ' ')
3682 return TRUE
; /* DOS names cannot have spaces */
3683 if (*lpszPath
== '.')
3686 return TRUE
; /* DOS names have only one dot */
3693 return TRUE
; /* DOS extensions are <= 3 chars*/
3699 return TRUE
; /* DOS names are <= 8 chars */
3703 return FALSE
; /* Valid DOS path */
3706 /*************************************************************************
3707 * PathIsDirectoryEmptyA [SHLWAPI.@]
3709 * Determine if a given directory is empty.
3712 * lpszPath [I] Directory to check
3715 * TRUE If the directory exists and contains no files,
3718 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3722 TRACE("(%s)\n",debugstr_a(lpszPath
));
3726 WCHAR szPath
[MAX_PATH
];
3727 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3728 bRet
= PathIsDirectoryEmptyW(szPath
);
3733 /*************************************************************************
3734 * PathIsDirectoryEmptyW [SHLWAPI.@]
3736 * See PathIsDirectoryEmptyA.
3738 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3740 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3741 WCHAR szSearch
[MAX_PATH
];
3744 BOOL retVal
= FALSE
;
3745 WIN32_FIND_DATAW find_data
;
3747 TRACE("(%s)\n",debugstr_w(lpszPath
));
3749 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3752 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3753 PathAddBackslashW(szSearch
);
3754 dwLen
= strlenW(szSearch
);
3755 if (dwLen
> MAX_PATH
- 4)
3758 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3759 hfind
= FindFirstFileW(szSearch
, &find_data
);
3761 if (hfind
!= INVALID_HANDLE_VALUE
&&
3762 find_data
.cFileName
[0] == '.' &&
3763 find_data
.cFileName
[1] == '.')
3765 /* The only directory entry should be the parent */
3766 if (!FindNextFileW(hfind
, &find_data
))
3774 /*************************************************************************
3775 * PathFindSuffixArrayA [SHLWAPI.@]
3777 * Find a suffix string in an array of suffix strings
3780 * lpszSuffix [I] Suffix string to search for
3781 * lppszArray [I] Array of suffix strings to search
3782 * dwCount [I] Number of elements in lppszArray
3785 * Success: The index of the position of lpszSuffix in lppszArray
3786 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3789 * The search is case sensitive.
3790 * The match is made against the end of the suffix string, so for example:
3791 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3793 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3798 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3800 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3802 dwLen
= strlen(lpszSuffix
);
3804 while (dwRet
< dwCount
)
3806 size_t dwCompareLen
= strlen(*lppszArray
);
3807 if (dwCompareLen
< dwLen
)
3809 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3810 return *lppszArray
; /* Found */
3819 /*************************************************************************
3820 * PathFindSuffixArrayW [SHLWAPI.@]
3822 * See PathFindSuffixArrayA.
3824 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3829 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3831 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3833 dwLen
= strlenW(lpszSuffix
);
3835 while (dwRet
< dwCount
)
3837 size_t dwCompareLen
= strlenW(*lppszArray
);
3838 if (dwCompareLen
< dwLen
)
3840 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3841 return *lppszArray
; /* Found */
3850 /*************************************************************************
3851 * PathUndecorateA [SHLWAPI.@]
3853 * Undecorate a file path
3856 * lpszPath [I/O] Path to remove any decoration from
3862 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3864 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3866 TRACE("(%s)\n",debugstr_a(lpszPath
));
3870 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3871 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3873 LPSTR lpszSkip
= lpszExt
- 2;
3874 if (*lpszSkip
== '[')
3875 lpszSkip
++; /* [] (no number) */
3877 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3879 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3881 /* remove the [n] */
3884 *lpszSkip
++ = *lpszExt
++;
3891 /*************************************************************************
3892 * PathUndecorateW [SHLWAPI.@]
3894 * See PathUndecorateA.
3896 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3898 TRACE("(%s)\n",debugstr_w(lpszPath
));
3902 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3903 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3905 LPWSTR lpszSkip
= lpszExt
- 2;
3906 if (*lpszSkip
== '[')
3907 lpszSkip
++; /* [] (no number) */
3909 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3911 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3913 /* remove the [n] */
3916 *lpszSkip
++ = *lpszExt
++;
3923 /*************************************************************************
3924 * PathUnExpandEnvStringsA [SHLWAPI.@]
3926 * Substitute folder names in a path with their corresponding environment
3930 * pszPath [I] Buffer containing the path to unexpand.
3931 * pszBuf [O] Buffer to receive the unexpanded path.
3932 * cchBuf [I] Size of pszBuf in characters.
3938 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR pszPath
, LPSTR pszBuf
, UINT cchBuf
)
3940 FIXME("(%s,%s,0x%08x)\n", debugstr_a(pszPath
), debugstr_a(pszBuf
), cchBuf
);
3944 /*************************************************************************
3945 * PathUnExpandEnvStringsW [SHLWAPI.@]
3947 * Unicode version of PathUnExpandEnvStringsA.
3949 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR pszPath
, LPWSTR pszBuf
, UINT cchBuf
)
3951 FIXME("(%s,%s,0x%08x)\n", debugstr_w(pszPath
), debugstr_w(pszBuf
), cchBuf
);
3955 /*************************************************************************
3958 * Find localised or default web content in "%WINDOWS%\web\".
3961 * lpszFile [I] File name containing content to look for
3962 * lpszPath [O] Buffer to contain the full path to the file
3963 * dwPathLen [I] Length of lpszPath
3966 * Success: S_OK. lpszPath contains the full path to the content.
3967 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
3969 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
3971 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
3974 TRACE("(%s,%p,%ld)\n", lpszFile
, lpszPath
, dwPathLen
);
3976 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
3978 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
3979 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
3983 /*************************************************************************
3986 * Unicode version of SHGetWebFolderFilePathA.
3988 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
3990 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
3991 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
3992 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
3993 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
3994 DWORD dwLen
, dwFileLen
;
3995 LANGID lidSystem
, lidUser
;
3997 TRACE("(%s,%p,%ld)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
3999 /* Get base directory for web content */
4000 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4001 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4004 dwFileLen
= strlenW(lpszFile
);
4006 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4007 return E_FAIL
; /* lpszPath too short */
4009 strcpyW(lpszPath
+dwLen
, szWeb
);
4011 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4013 lidSystem
= GetSystemDefaultUILanguage();
4014 lidUser
= GetUserDefaultUILanguage();
4016 if (lidSystem
!= lidUser
)
4018 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4020 /* Use localised content in the users UI language if present */
4021 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4022 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4023 if (PathFileExistsW(lpszPath
))
4028 /* Fall back to OS default installed content */
4029 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4030 if (PathFileExistsW(lpszPath
))
4035 #define PATH_CHAR_CLASS_LETTER 0x00000001
4036 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4037 #define PATH_CHAR_CLASS_DOT 0x00000004
4038 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4039 #define PATH_CHAR_CLASS_COLON 0x00000010
4040 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4041 #define PATH_CHAR_CLASS_COMMA 0x00000040
4042 #define PATH_CHAR_CLASS_SPACE 0x00000080
4043 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4044 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4046 #define PATH_CHAR_CLASS_INVALID 0x00000000
4047 #define PATH_CHAR_CLASS_ANY 0xffffffff
4049 static const DWORD SHELL_charclass
[] =
4051 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4052 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4053 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4054 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4055 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4056 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4057 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4058 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4059 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4060 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4061 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4062 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4063 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4064 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4065 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4066 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4067 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4068 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4069 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4070 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4071 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4072 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4073 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4074 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4075 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4076 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4077 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4078 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4079 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4080 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4081 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4082 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4083 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4084 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4085 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4086 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4087 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4088 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4089 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4090 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4091 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4092 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4093 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4094 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4095 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4096 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4097 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4098 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4099 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4100 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4101 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4102 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4103 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4104 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4105 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4106 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4107 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4108 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4109 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4110 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4111 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4112 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4113 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4114 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4117 /*************************************************************************
4120 * Check if an ASCII char is of a certain class
4122 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4124 if ((unsigned)c
> 0x7e)
4125 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4127 return class & SHELL_charclass
[(unsigned)c
];
4130 /*************************************************************************
4133 * Check if a Unicode char is of a certain class
4135 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4138 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4140 return class & SHELL_charclass
[c
];