4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2001, 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* Get a function pointer from a DLL handle */
25 #define GET_FUNC(func, module, name, fail) \
28 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
29 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
30 if (!func) return fail; \
34 /* DLL handles for late bound calls */
35 static HMODULE SHLWAPI_hshell32
;
37 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
38 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
39 static fnpIsNetDrive pIsNetDrive
;
41 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
43 /*************************************************************************
44 * PathAppendA [SHLWAPI.@]
46 * Append one path to another.
49 * lpszPath [I/O] Initial part of path, and destination for output
50 * lpszAppend [I] Path to append
53 * Success: TRUE. lpszPath contains the newly created path.
54 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
57 * lpszAppend must contain at least one backslash ('\') if not NULL.
58 * Because PathCombineA() is used to join the paths, the resulting
59 * path is also canonicalized.
61 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
63 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
65 if (lpszPath
&& lpszAppend
)
67 if (!PathIsUNCA(lpszAppend
))
68 while (*lpszAppend
== '\\')
70 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
76 /*************************************************************************
77 * PathAppendW [SHLWAPI.@]
81 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
83 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
85 if (lpszPath
&& lpszAppend
)
87 if (!PathIsUNCW(lpszAppend
))
88 while (*lpszAppend
== '\\')
90 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
96 /*************************************************************************
97 * PathCombineA [SHLWAPI.@]
99 * Combine two paths together.
102 * lpszDest [O] Destination for combined path
103 * lpszDir [I] Directory path
104 * lpszFile [I] File path
107 * Success: The output path
108 * Failure: NULL, if inputs are invalid.
111 * lpszDest should be at least MAX_PATH in size, and may point to the same
112 * memory location as lpszDir. The combined path is canonicalised.
114 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
116 WCHAR szDest
[MAX_PATH
];
117 WCHAR szDir
[MAX_PATH
];
118 WCHAR szFile
[MAX_PATH
];
119 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
121 /* Invalid parameters */
124 if (!lpszDir
&& !lpszFile
)
131 MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
);
133 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
135 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
136 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
143 /*************************************************************************
144 * PathCombineW [SHLWAPI.@]
148 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
150 WCHAR szTemp
[MAX_PATH
];
151 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
153 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
155 /* Invalid parameters */
158 if (!lpszDir
&& !lpszFile
)
164 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
167 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
169 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
171 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
174 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
187 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
190 PathStripToRootW(szTemp
);
191 lpszFile
++; /* Skip '\' */
193 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
198 strcatW(szTemp
, lpszFile
);
201 PathCanonicalizeW(lpszDest
, szTemp
);
205 /*************************************************************************
206 * PathAddBackslashA [SHLWAPI.@]
208 * Append a backslash ('\') to a path if one doesn't exist.
211 * lpszPath [I/O] The path to append a backslash to.
214 * Success: The position of the last backslash in the path.
215 * Failure: NULL, if lpszPath is NULL or the path is too large.
217 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
220 LPSTR prev
= lpszPath
;
222 TRACE("(%s)\n",debugstr_a(lpszPath
));
224 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
230 lpszPath
= CharNextA(prev
);
243 /*************************************************************************
244 * PathAddBackslashW [SHLWAPI.@]
246 * See PathAddBackslashA.
248 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
252 TRACE("(%s)\n",debugstr_w(lpszPath
));
254 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
260 if (lpszPath
[-1] != '\\')
269 /*************************************************************************
270 * PathBuildRootA [SHLWAPI.@]
272 * Create a root drive string (e.g. "A:\") from a drive number.
275 * lpszPath [O] Destination for the drive string
281 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
283 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
285 TRACE("(%p,%d)\n", lpszPath
, drive
);
287 if (lpszPath
&& drive
>= 0 && drive
< 26)
289 lpszPath
[0] = 'A' + drive
;
297 /*************************************************************************
298 * PathBuildRootW [SHLWAPI.@]
300 * See PathBuildRootA.
302 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
304 TRACE("(%p,%d)\n", lpszPath
, drive
);
306 if (lpszPath
&& drive
>= 0 && drive
< 26)
308 lpszPath
[0] = 'A' + drive
;
316 /*************************************************************************
317 * PathFindFileNameA [SHLWAPI.@]
319 * Locate the start of the file name in a path
322 * lpszPath [I] Path to search
325 * A pointer to the first character of the file name
327 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
329 LPCSTR lastSlash
= lpszPath
;
331 TRACE("(%s)\n",debugstr_a(lpszPath
));
333 while (lpszPath
&& *lpszPath
)
335 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
336 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
337 lastSlash
= lpszPath
+ 1;
338 lpszPath
= CharNextA(lpszPath
);
340 return (LPSTR
)lastSlash
;
343 /*************************************************************************
344 * PathFindFileNameW [SHLWAPI.@]
346 * See PathFindFileNameA.
348 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
350 LPCWSTR lastSlash
= lpszPath
;
352 TRACE("(%s)\n",debugstr_w(lpszPath
));
354 while (lpszPath
&& *lpszPath
)
356 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
357 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
358 lastSlash
= lpszPath
+ 1;
361 return (LPWSTR
)lastSlash
;
364 /*************************************************************************
365 * PathFindExtensionA [SHLWAPI.@]
367 * Locate the start of the file extension in a path
370 * lpszPath [I] The path to search
373 * A pointer to the first character of the extension, the end of
374 * the string if the path has no extension, or NULL If lpszPath is NULL
376 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
378 LPCSTR lastpoint
= NULL
;
380 TRACE("(%s)\n", debugstr_a(lpszPath
));
386 if (*lpszPath
== '\\' || *lpszPath
==' ')
388 else if (*lpszPath
== '.')
389 lastpoint
= lpszPath
;
390 lpszPath
= CharNextA(lpszPath
);
393 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
396 /*************************************************************************
397 * PathFindExtensionW [SHLWAPI.@]
399 * See PathFindExtensionA.
401 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
403 LPCWSTR lastpoint
= NULL
;
405 TRACE("(%s)\n", debugstr_w(lpszPath
));
411 if (*lpszPath
== '\\' || *lpszPath
==' ')
413 else if (*lpszPath
== '.')
414 lastpoint
= lpszPath
;
418 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
421 /*************************************************************************
422 * PathGetArgsA [SHLWAPI.@]
424 * Find the next argument in a string delimited by spaces.
427 * lpszPath [I] The string to search for arguments in
430 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
433 * Spaces in quoted strings are ignored as delimiters.
435 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
437 BOOL bSeenQuote
= FALSE
;
439 TRACE("(%s)\n",debugstr_a(lpszPath
));
445 if ((*lpszPath
==' ') && !bSeenQuote
)
446 return (LPSTR
)lpszPath
+ 1;
447 if (*lpszPath
== '"')
448 bSeenQuote
= !bSeenQuote
;
449 lpszPath
= CharNextA(lpszPath
);
452 return (LPSTR
)lpszPath
;
455 /*************************************************************************
456 * PathGetArgsW [SHLWAPI.@]
460 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
462 BOOL bSeenQuote
= FALSE
;
464 TRACE("(%s)\n",debugstr_w(lpszPath
));
470 if ((*lpszPath
==' ') && !bSeenQuote
)
471 return (LPWSTR
)lpszPath
+ 1;
472 if (*lpszPath
== '"')
473 bSeenQuote
= !bSeenQuote
;
477 return (LPWSTR
)lpszPath
;
480 /*************************************************************************
481 * PathGetDriveNumberA [SHLWAPI.@]
483 * Return the drive number from a path
486 * lpszPath [I] Path to get the drive number from
489 * Success: The drive number corresponding to the drive in the path
490 * Failure: -1, if lpszPath contains no valid drive
492 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
494 TRACE ("(%s)\n",debugstr_a(lpszPath
));
496 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
497 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
498 return tolower(*lpszPath
) - 'a';
502 /*************************************************************************
503 * PathGetDriveNumberW [SHLWAPI.@]
505 * See PathGetDriveNumberA.
507 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
509 TRACE ("(%s)\n",debugstr_w(lpszPath
));
513 WCHAR tl
= tolowerW(lpszPath
[0]);
514 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
520 /*************************************************************************
521 * PathRemoveFileSpecA [SHLWAPI.@]
523 * Remove the file specification from a path.
526 * lpszPath [I/O] Path to remove the file spec from
529 * TRUE If the path was valid and modified
532 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
534 LPSTR lpszFileSpec
= lpszPath
;
535 BOOL bModified
= FALSE
;
537 TRACE("(%s)\n",debugstr_a(lpszPath
));
541 /* Skip directory or UNC path */
542 if (*lpszPath
== '\\')
543 lpszFileSpec
= ++lpszPath
;
544 if (*lpszPath
== '\\')
545 lpszFileSpec
= ++lpszPath
;
549 if(*lpszPath
== '\\')
550 lpszFileSpec
= lpszPath
; /* Skip dir */
551 else if(*lpszPath
== ':')
553 lpszFileSpec
= ++lpszPath
; /* Skip drive */
554 if (*lpszPath
== '\\')
557 if (!(lpszPath
= CharNextA(lpszPath
)))
563 *lpszFileSpec
= '\0';
570 /*************************************************************************
571 * PathRemoveFileSpecW [SHLWAPI.@]
573 * See PathRemoveFileSpecA.
575 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
577 LPWSTR lpszFileSpec
= lpszPath
;
578 BOOL bModified
= FALSE
;
580 TRACE("(%s)\n",debugstr_w(lpszPath
));
584 /* Skip directory or UNC path */
585 if (*lpszPath
== '\\')
586 lpszFileSpec
= ++lpszPath
;
587 if (*lpszPath
== '\\')
588 lpszFileSpec
= ++lpszPath
;
592 if(*lpszPath
== '\\')
593 lpszFileSpec
= lpszPath
; /* Skip dir */
594 else if(*lpszPath
== ':')
596 lpszFileSpec
= ++lpszPath
; /* Skip drive */
597 if (*lpszPath
== '\\')
605 *lpszFileSpec
= '\0';
612 /*************************************************************************
613 * PathStripPathA [SHLWAPI.@]
615 * Remove the initial path from the beginning of a filename
618 * lpszPath [I/O] Path to remove the initial path from
623 void WINAPI
PathStripPathA(LPSTR lpszPath
)
625 TRACE("(%s)\n", debugstr_a(lpszPath
));
629 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
631 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
635 /*************************************************************************
636 * PathStripPathW [SHLWAPI.@]
638 * See PathStripPathA.
640 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
644 TRACE("(%s)\n", debugstr_w(lpszPath
));
645 lpszFileName
= PathFindFileNameW(lpszPath
);
647 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
650 /*************************************************************************
651 * PathStripToRootA [SHLWAPI.@]
653 * Reduce a path to its root.
656 * lpszPath [I/O] the path to reduce
659 * Success: TRUE if the stripped path is a root path
660 * Failure: FALSE if the path cannot be stripped or is NULL
662 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
664 TRACE("(%s)\n", debugstr_a(lpszPath
));
668 while(!PathIsRootA(lpszPath
))
669 if (!PathRemoveFileSpecA(lpszPath
))
674 /*************************************************************************
675 * PathStripToRootW [SHLWAPI.@]
677 * See PathStripToRootA.
679 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
681 TRACE("(%s)\n", debugstr_w(lpszPath
));
685 while(!PathIsRootW(lpszPath
))
686 if (!PathRemoveFileSpecW(lpszPath
))
691 /*************************************************************************
692 * PathRemoveArgsA [SHLWAPI.@]
694 * Strip space separated arguments from a path.
697 * lpszPath [I/O] Path to remove arguments from
702 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
704 TRACE("(%s)\n",debugstr_a(lpszPath
));
708 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
713 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
714 if(*lpszLastChar
== ' ')
715 *lpszLastChar
= '\0';
720 /*************************************************************************
721 * PathRemoveArgsW [SHLWAPI.@]
723 * See PathRemoveArgsA.
725 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
727 TRACE("(%s)\n",debugstr_w(lpszPath
));
731 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
732 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
737 /*************************************************************************
738 * PathRemoveExtensionA [SHLWAPI.@]
740 * Remove the file extension from a path
743 * lpszPath [I/O] Path to remove the extension from
746 * The NUL terminator must be written only if extension exists
747 * and if the pointed character is not already NUL.
752 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
754 TRACE("(%s)\n", debugstr_a(lpszPath
));
758 lpszPath
= PathFindExtensionA(lpszPath
);
759 if (lpszPath
&& *lpszPath
!= '\0')
764 /*************************************************************************
765 * PathRemoveExtensionW [SHLWAPI.@]
767 * See PathRemoveExtensionA.
769 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
771 TRACE("(%s)\n", debugstr_w(lpszPath
));
775 lpszPath
= PathFindExtensionW(lpszPath
);
776 if (lpszPath
&& *lpszPath
!= '\0')
781 /*************************************************************************
782 * PathRemoveBackslashA [SHLWAPI.@]
784 * Remove a trailing backslash from a path.
787 * lpszPath [I/O] Path to remove backslash from
790 * Success: A pointer to the end of the path
791 * Failure: NULL, if lpszPath is NULL
793 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
797 TRACE("(%s)\n", debugstr_a(lpszPath
));
801 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
802 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
808 /*************************************************************************
809 * PathRemoveBackslashW [SHLWAPI.@]
811 * See PathRemoveBackslashA.
813 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
815 LPWSTR szTemp
= NULL
;
817 TRACE("(%s)\n", debugstr_w(lpszPath
));
821 szTemp
= lpszPath
+ strlenW(lpszPath
);
822 if (szTemp
> lpszPath
) szTemp
--;
823 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
829 /*************************************************************************
830 * PathRemoveBlanksA [SHLWAPI.@]
832 * Remove Spaces from the start and end of a path.
835 * lpszPath [I/O] Path to strip blanks from
840 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
842 TRACE("(%s)\n", debugstr_a(lpszPath
));
844 if(lpszPath
&& *lpszPath
)
846 LPSTR start
= lpszPath
;
848 while (*lpszPath
== ' ')
849 lpszPath
= CharNextA(lpszPath
);
852 *start
++ = *lpszPath
++;
854 if (start
!= lpszPath
)
855 while (start
[-1] == ' ')
861 /*************************************************************************
862 * PathRemoveBlanksW [SHLWAPI.@]
864 * See PathRemoveBlanksA.
866 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
868 TRACE("(%s)\n", debugstr_w(lpszPath
));
870 if(lpszPath
&& *lpszPath
)
872 LPWSTR start
= lpszPath
;
874 while (*lpszPath
== ' ')
878 *start
++ = *lpszPath
++;
880 if (start
!= lpszPath
)
881 while (start
[-1] == ' ')
887 /*************************************************************************
888 * PathQuoteSpacesA [SHLWAPI.@]
890 * Surround a path containing spaces in quotes.
893 * lpszPath [I/O] Path to quote
899 * The path is not changed if it is invalid or has no spaces.
901 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
903 TRACE("(%s)\n", debugstr_a(lpszPath
));
905 if(lpszPath
&& StrChrA(lpszPath
,' '))
907 size_t iLen
= strlen(lpszPath
) + 1;
909 if (iLen
+ 2 < MAX_PATH
)
911 memmove(lpszPath
+ 1, lpszPath
, iLen
);
913 lpszPath
[iLen
] = '"';
914 lpszPath
[iLen
+ 1] = '\0';
919 /*************************************************************************
920 * PathQuoteSpacesW [SHLWAPI.@]
922 * See PathQuoteSpacesA.
924 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
926 TRACE("(%s)\n", debugstr_w(lpszPath
));
928 if(lpszPath
&& StrChrW(lpszPath
,' '))
930 int iLen
= strlenW(lpszPath
) + 1;
932 if (iLen
+ 2 < MAX_PATH
)
934 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
936 lpszPath
[iLen
] = '"';
937 lpszPath
[iLen
+ 1] = '\0';
942 /*************************************************************************
943 * PathUnquoteSpacesA [SHLWAPI.@]
945 * Remove quotes ("") from around a path, if present.
948 * lpszPath [I/O] Path to strip quotes from
954 * If the path contains a single quote only, an empty string will result.
955 * Otherwise quotes are only removed if they appear at the start and end
958 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
960 TRACE("(%s)\n", debugstr_a(lpszPath
));
962 if (lpszPath
&& *lpszPath
== '"')
964 DWORD dwLen
= strlen(lpszPath
) - 1;
966 if (lpszPath
[dwLen
] == '"')
968 lpszPath
[dwLen
] = '\0';
969 for (; *lpszPath
; lpszPath
++)
970 *lpszPath
= lpszPath
[1];
975 /*************************************************************************
976 * PathUnquoteSpacesW [SHLWAPI.@]
978 * See PathUnquoteSpacesA.
980 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
982 TRACE("(%s)\n", debugstr_w(lpszPath
));
984 if (lpszPath
&& *lpszPath
== '"')
986 DWORD dwLen
= strlenW(lpszPath
) - 1;
988 if (lpszPath
[dwLen
] == '"')
990 lpszPath
[dwLen
] = '\0';
991 for (; *lpszPath
; lpszPath
++)
992 *lpszPath
= lpszPath
[1];
997 /*************************************************************************
998 * PathParseIconLocationA [SHLWAPI.@]
1000 * Parse the location of an icon from a path.
1003 * lpszPath [I/O] The path to parse the icon location from.
1006 * Success: The number of the icon
1007 * Failure: 0 if the path does not contain an icon location or is NULL
1010 * The path has surrounding quotes and spaces removed regardless
1011 * of whether the call succeeds or not.
1013 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1018 TRACE("(%s)\n", debugstr_a(lpszPath
));
1022 if ((lpszComma
= strchr(lpszPath
, ',')))
1024 *lpszComma
++ = '\0';
1025 iRet
= StrToIntA(lpszComma
);
1027 PathUnquoteSpacesA(lpszPath
);
1028 PathRemoveBlanksA(lpszPath
);
1033 /*************************************************************************
1034 * PathParseIconLocationW [SHLWAPI.@]
1036 * See PathParseIconLocationA.
1038 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1043 TRACE("(%s)\n", debugstr_w(lpszPath
));
1047 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1049 *lpszComma
++ = '\0';
1050 iRet
= StrToIntW(lpszComma
);
1052 PathUnquoteSpacesW(lpszPath
);
1053 PathRemoveBlanksW(lpszPath
);
1058 /*************************************************************************
1061 * Unicode version of PathFileExistsDefExtA.
1063 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1065 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1066 { '.', 'c', 'o', 'm', 0},
1067 { '.', 'e', 'x', 'e', 0},
1068 { '.', 'b', 'a', 't', 0},
1069 { '.', 'l', 'n', 'k', 0},
1070 { '.', 'c', 'm', 'd', 0},
1073 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1075 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1080 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1081 if (!*szExt
|| dwWhich
& 0x40)
1084 int iLen
= lstrlenW(lpszPath
);
1085 if (iLen
> (MAX_PATH
- 5))
1087 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1089 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1090 if (PathFileExistsW(lpszPath
))
1095 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1099 return PathFileExistsW(lpszPath
);
1102 /*************************************************************************
1105 * Determine if a file exists locally and is of an executable type.
1108 * lpszPath [I/O] File to search for
1109 * dwWhich [I] Type of executable to search for
1112 * TRUE If the file was found. lpszPath contains the file name.
1116 * lpszPath is modified in place and must be at least MAX_PATH in length.
1117 * If the function returns FALSE, the path is modified to its original state.
1118 * If the given path contains an extension or dwWhich is 0, executable
1119 * extensions are not checked.
1121 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1122 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1123 * their own developers exclusive use. Monopoly, anyone?
1125 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1129 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1133 WCHAR szPath
[MAX_PATH
];
1134 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1135 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1137 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1142 /*************************************************************************
1143 * SHLWAPI_PathFindInOtherDirs
1145 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1147 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1149 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1150 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1154 WCHAR buff
[MAX_PATH
];
1156 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1158 /* Try system directories */
1159 GetSystemDirectoryW(buff
, MAX_PATH
);
1160 if (!PathAppendW(buff
, lpszFile
))
1162 if (PathFileExistsDefExtW(buff
, dwWhich
))
1164 strcpyW(lpszFile
, buff
);
1167 GetWindowsDirectoryW(buff
, MAX_PATH
);
1168 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1170 if (PathFileExistsDefExtW(buff
, dwWhich
))
1172 strcpyW(lpszFile
, buff
);
1175 GetWindowsDirectoryW(buff
, MAX_PATH
);
1176 if (!PathAppendW(buff
, lpszFile
))
1178 if (PathFileExistsDefExtW(buff
, dwWhich
))
1180 strcpyW(lpszFile
, buff
);
1183 /* Try dirs listed in %PATH% */
1184 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1186 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1189 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1190 lpszCurr
= lpszPATH
;
1193 LPCWSTR lpszEnd
= lpszCurr
;
1194 LPWSTR pBuff
= buff
;
1196 while (*lpszEnd
== ' ')
1198 while (*lpszEnd
&& *lpszEnd
!= ';')
1199 *pBuff
++ = *lpszEnd
++;
1203 lpszCurr
= lpszEnd
+ 1;
1205 lpszCurr
= NULL
; /* Last Path, terminate after this */
1207 if (!PathAppendW(buff
, lpszFile
))
1209 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1212 if (PathFileExistsDefExtW(buff
, dwWhich
))
1214 strcpyW(lpszFile
, buff
);
1215 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1219 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1223 /*************************************************************************
1226 * Search a range of paths for a specific type of executable.
1229 * lpszFile [I/O] File to search for
1230 * lppszOtherDirs [I] Other directories to look in
1231 * dwWhich [I] Type of executable to search for
1234 * Success: TRUE. The path to the executable is stored in lpszFile.
1235 * Failure: FALSE. The path to the executable is unchanged.
1237 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1239 WCHAR szFile
[MAX_PATH
];
1240 WCHAR buff
[MAX_PATH
];
1242 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1244 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1247 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1249 /* Search provided directories first */
1250 if (lppszOtherDirs
&& *lppszOtherDirs
)
1252 WCHAR szOther
[MAX_PATH
];
1253 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1255 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1257 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1258 PathCombineW(buff
, szOther
, szFile
);
1259 if (PathFileExistsDefExtW(buff
, dwWhich
))
1261 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1267 /* Not found, try system and path dirs */
1268 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1270 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1276 /*************************************************************************
1279 * Unicode version of PathFindOnPathExA.
1281 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1283 WCHAR buff
[MAX_PATH
];
1285 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1287 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1290 /* Search provided directories first */
1291 if (lppszOtherDirs
&& *lppszOtherDirs
)
1293 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1294 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1296 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1297 if (PathFileExistsDefExtW(buff
, dwWhich
))
1299 strcpyW(lpszFile
, buff
);
1305 /* Not found, try system and path dirs */
1306 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1309 /*************************************************************************
1310 * PathFindOnPathA [SHLWAPI.@]
1312 * Search a range of paths for an executable.
1315 * lpszFile [I/O] File to search for
1316 * lppszOtherDirs [I] Other directories to look in
1319 * Success: TRUE. The path to the executable is stored in lpszFile.
1320 * Failure: FALSE. The path to the executable is unchanged.
1322 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1324 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1325 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1328 /*************************************************************************
1329 * PathFindOnPathW [SHLWAPI.@]
1331 * See PathFindOnPathA.
1333 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1335 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1336 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1339 /*************************************************************************
1340 * PathCompactPathExA [SHLWAPI.@]
1342 * Compact a path into a given number of characters.
1345 * lpszDest [O] Destination for compacted path
1346 * lpszPath [I] Source path
1347 * cchMax [I] Maximum size of compacted path
1348 * dwFlags [I] Reserved
1351 * Success: TRUE. The compacted path is written to lpszDest.
1352 * Failure: FALSE. lpszPath is undefined.
1355 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1357 * The Win32 version of this function contains a bug: When cchMax == 7,
1358 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1361 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1362 * because Win32 will insert a "\" in lpszDest, even if one is
1363 * not present in the original path.
1365 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1366 UINT cchMax
, DWORD dwFlags
)
1370 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1372 if (lpszPath
&& lpszDest
)
1374 WCHAR szPath
[MAX_PATH
];
1375 WCHAR szDest
[MAX_PATH
];
1377 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1379 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1380 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1385 /*************************************************************************
1386 * PathCompactPathExW [SHLWAPI.@]
1388 * See PathCompactPathExA.
1390 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1391 UINT cchMax
, DWORD dwFlags
)
1393 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1395 DWORD dwLen
, dwFileLen
= 0;
1397 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1404 WARN("Invalid lpszDest would crash under Win32!\n");
1413 dwLen
= strlenW(lpszPath
) + 1;
1417 /* Don't need to compact */
1418 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1422 /* Path must be compacted to fit into lpszDest */
1423 lpszFile
= PathFindFileNameW(lpszPath
);
1424 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1426 if (dwFileLen
== dwLen
)
1428 /* No root in psth */
1431 while (--cchMax
> 0) /* No room left for anything but ellipses */
1436 /* Compact the file name with ellipses at the end */
1438 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1439 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1442 /* We have a root in the path */
1443 lpszFile
--; /* Start compacted filename with the path separator */
1446 if (dwFileLen
+ 3 > cchMax
)
1448 /* Compact the file name */
1451 while (--cchMax
> 0) /* No room left for anything but ellipses */
1456 strcpyW(lpszDest
, szEllipses
);
1459 *lpszDest
++ = *lpszFile
++;
1462 while (--cchMax
> 0) /* No room left for anything but ellipses */
1468 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1469 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1473 /* Only the root needs to be Compacted */
1474 dwLen
= cchMax
- dwFileLen
- 3;
1475 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1476 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1477 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1481 /*************************************************************************
1482 * PathIsRelativeA [SHLWAPI.@]
1484 * Determine if a path is a relative path.
1487 * lpszPath [I] Path to check
1490 * TRUE: The path is relative, or is invalid.
1491 * FALSE: The path is not relative.
1493 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1495 TRACE("(%s)\n",debugstr_a(lpszPath
));
1497 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1499 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1504 /*************************************************************************
1505 * PathIsRelativeW [SHLWAPI.@]
1507 * See PathIsRelativeA.
1509 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1511 TRACE("(%s)\n",debugstr_w(lpszPath
));
1513 if (!lpszPath
|| !*lpszPath
)
1515 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1520 /*************************************************************************
1521 * PathIsRootA [SHLWAPI.@]
1523 * Determine if a path is a root path.
1526 * lpszPath [I] Path to check
1529 * TRUE If lpszPath is valid and a root path,
1532 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1534 TRACE("(%s)\n", debugstr_a(lpszPath
));
1536 if (lpszPath
&& *lpszPath
)
1538 if (*lpszPath
== '\\')
1541 return TRUE
; /* \ */
1542 else if (lpszPath
[1]=='\\')
1544 BOOL bSeenSlash
= FALSE
;
1547 /* Check for UNC root path */
1550 if (*lpszPath
== '\\')
1556 lpszPath
= CharNextA(lpszPath
);
1561 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1562 return TRUE
; /* X:\ */
1567 /*************************************************************************
1568 * PathIsRootW [SHLWAPI.@]
1572 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1574 TRACE("(%s)\n", debugstr_w(lpszPath
));
1576 if (lpszPath
&& *lpszPath
)
1578 if (*lpszPath
== '\\')
1581 return TRUE
; /* \ */
1582 else if (lpszPath
[1]=='\\')
1584 BOOL bSeenSlash
= FALSE
;
1587 /* Check for UNC root path */
1590 if (*lpszPath
== '\\')
1601 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1602 return TRUE
; /* X:\ */
1607 /*************************************************************************
1608 * PathIsDirectoryA [SHLWAPI.@]
1610 * Determine if a path is a valid directory
1613 * lpszPath [I] Path to check.
1616 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1617 * FALSE if lpszPath is invalid or not a directory.
1620 * Although this function is prototyped as returning a BOOL, it returns
1621 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1623 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1628 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1632 TRACE("(%s)\n", debugstr_a(lpszPath
));
1634 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1637 if (PathIsUNCServerShareA(lpszPath
))
1639 FIXME("UNC Server Share not yet supported - FAILING\n");
1643 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1645 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1648 /*************************************************************************
1649 * PathIsDirectoryW [SHLWAPI.@]
1651 * See PathIsDirectoryA.
1653 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1657 TRACE("(%s)\n", debugstr_w(lpszPath
));
1659 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1662 if (PathIsUNCServerShareW(lpszPath
))
1664 FIXME("UNC Server Share not yet supported - FAILING\n");
1668 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1670 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1673 /*************************************************************************
1674 * PathFileExistsA [SHLWAPI.@]
1676 * Determine if a file exists.
1679 * lpszPath [I] Path to check
1682 * TRUE If the file exists and is readable
1685 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1690 TRACE("(%s)\n",debugstr_a(lpszPath
));
1695 /* Prevent a dialog box if path is on a disk that has been ejected. */
1696 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1697 dwAttr
= GetFileAttributesA(lpszPath
);
1698 SetErrorMode(iPrevErrMode
);
1699 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1702 /*************************************************************************
1703 * PathFileExistsW [SHLWAPI.@]
1705 * See PathFileExistsA.
1707 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1712 TRACE("(%s)\n",debugstr_w(lpszPath
));
1717 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1718 dwAttr
= GetFileAttributesW(lpszPath
);
1719 SetErrorMode(iPrevErrMode
);
1720 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1723 /*************************************************************************
1724 * PathFileExistsAndAttributesA [SHLWAPI.445]
1726 * Determine if a file exists.
1729 * lpszPath [I] Path to check
1730 * dwAttr [O] attributes of file
1733 * TRUE If the file exists and is readable
1736 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1741 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1744 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1749 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1750 dwVal
= GetFileAttributesA(lpszPath
);
1751 SetErrorMode(iPrevErrMode
);
1754 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1757 /*************************************************************************
1758 * PathFileExistsAndAttributesW [SHLWAPI.446]
1760 * See PathFileExistsA.
1762 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1767 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1772 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1773 dwVal
= GetFileAttributesW(lpszPath
);
1774 SetErrorMode(iPrevErrMode
);
1777 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1780 /*************************************************************************
1781 * PathMatchSingleMaskA [internal]
1783 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1785 while (*name
&& *mask
&& *mask
!=';')
1791 if (PathMatchSingleMaskA(name
,mask
+1))
1792 return TRUE
; /* try substrings */
1797 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1800 name
= CharNextA(name
);
1801 mask
= CharNextA(mask
);
1806 while (*mask
== '*')
1808 if (!*mask
|| *mask
== ';')
1814 /*************************************************************************
1815 * PathMatchSingleMaskW [internal]
1817 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1819 while (*name
&& *mask
&& *mask
!= ';')
1825 if (PathMatchSingleMaskW(name
,mask
+1))
1826 return TRUE
; /* try substrings */
1831 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1839 while (*mask
== '*')
1841 if (!*mask
|| *mask
== ';')
1847 /*************************************************************************
1848 * PathMatchSpecA [SHLWAPI.@]
1850 * Determine if a path matches one or more search masks.
1853 * lpszPath [I] Path to check
1854 * lpszMask [I] Search mask(s)
1857 * TRUE If lpszPath is valid and is matched
1861 * Multiple search masks may be given if they are separated by ";". The
1862 * pattern "*.*" is treated specially in that it matches all paths (for
1863 * backwards compatibility with DOS).
1865 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1867 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1869 if (!lstrcmpA(lpszMask
, "*.*"))
1870 return TRUE
; /* Matches every path */
1874 while (*lpszMask
== ' ')
1875 lpszMask
++; /* Eat leading spaces */
1877 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1878 return TRUE
; /* Matches the current mask */
1880 while (*lpszMask
&& *lpszMask
!= ';')
1881 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1883 if (*lpszMask
== ';')
1889 /*************************************************************************
1890 * PathMatchSpecW [SHLWAPI.@]
1892 * See PathMatchSpecA.
1894 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1896 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1898 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1900 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1901 return TRUE
; /* Matches every path */
1905 while (*lpszMask
== ' ')
1906 lpszMask
++; /* Eat leading spaces */
1908 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1909 return TRUE
; /* Matches the current path */
1911 while (*lpszMask
&& *lpszMask
!= ';')
1912 lpszMask
++; /* masks separated by ';' */
1914 if (*lpszMask
== ';')
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 check
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
== ':')
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%08x)\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%08x)\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]=='\\') && (lpszPath
[2]!='?'))
2182 /*************************************************************************
2183 * PathIsUNCW [SHLWAPI.@]
2187 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2189 TRACE("(%s)\n",debugstr_w(lpszPath
));
2191 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
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
[0] == '\\' && lpszPath
[1] == '\\')
2241 return !strchrW( lpszPath
+ 2, '\\' );
2246 /*************************************************************************
2247 * PathIsUNCServerShareA [SHLWAPI.@]
2249 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2252 * lpszPath [I] Path to check.
2255 * TRUE If lpszPath is a valid UNC server share.
2259 * This routine is bug compatible with Win32: Server shares with a
2260 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2261 * Fixing this bug may break other shlwapi functions!
2263 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2265 TRACE("(%s)\n", debugstr_a(lpszPath
));
2267 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2269 BOOL bSeenSlash
= FALSE
;
2272 if (*lpszPath
== '\\')
2278 lpszPath
= CharNextA(lpszPath
);
2285 /*************************************************************************
2286 * PathIsUNCServerShareW [SHLWAPI.@]
2288 * See PathIsUNCServerShareA.
2290 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2292 TRACE("(%s)\n", debugstr_w(lpszPath
));
2294 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2296 BOOL bSeenSlash
= FALSE
;
2299 if (*lpszPath
== '\\')
2312 /*************************************************************************
2313 * PathCanonicalizeA [SHLWAPI.@]
2315 * Convert a path to its canonical form.
2318 * lpszBuf [O] Output path
2319 * lpszPath [I] Path to canonicalize
2322 * Success: TRUE. lpszBuf contains the output path,
2323 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2325 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2329 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2334 if (!lpszBuf
|| !lpszPath
)
2335 SetLastError(ERROR_INVALID_PARAMETER
);
2338 WCHAR szPath
[MAX_PATH
];
2339 WCHAR szBuff
[MAX_PATH
];
2340 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2343 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2346 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2347 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2353 /*************************************************************************
2354 * PathCanonicalizeW [SHLWAPI.@]
2356 * See PathCanonicalizeA.
2358 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2360 LPWSTR lpszDst
= lpszBuf
;
2361 LPCWSTR lpszSrc
= lpszPath
;
2363 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2368 if (!lpszBuf
|| !lpszPath
)
2370 SetLastError(ERROR_INVALID_PARAMETER
);
2381 /* Copy path root */
2382 if (*lpszSrc
== '\\')
2384 *lpszDst
++ = *lpszSrc
++;
2386 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2389 *lpszDst
++ = *lpszSrc
++;
2390 *lpszDst
++ = *lpszSrc
++;
2391 if (*lpszSrc
== '\\')
2392 *lpszDst
++ = *lpszSrc
++;
2395 /* Canonicalize the rest of the path */
2398 if (*lpszSrc
== '.')
2400 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2402 lpszSrc
+= 2; /* Skip .\ */
2404 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2406 /* \.. backs up a directory, over the root if it has no \ following X:.
2407 * .. is ignored if it would remove a UNC server name or initial \\
2409 if (lpszDst
!= lpszBuf
)
2411 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2412 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2413 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2415 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2418 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2420 if (*lpszDst
== '\\')
2421 lpszDst
++; /* Reset to last '\' */
2423 lpszDst
= lpszBuf
; /* Start path again from new root */
2425 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2428 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2430 if (lpszDst
== lpszBuf
)
2436 lpszSrc
+= 2; /* Skip .. in src path */
2439 *lpszDst
++ = *lpszSrc
++;
2442 *lpszDst
++ = *lpszSrc
++;
2444 /* Append \ to naked drive specs */
2445 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2451 /*************************************************************************
2452 * PathFindNextComponentA [SHLWAPI.@]
2454 * Find the next component in a path.
2457 * lpszPath [I] Path to find next component in
2460 * Success: A pointer to the next component, or the end of the string.
2461 * Failure: NULL, If lpszPath is invalid
2464 * A 'component' is either a backslash character (\) or UNC marker (\\).
2465 * Because of this, relative paths (e.g "c:foo") are regarded as having
2466 * only one component.
2468 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2472 TRACE("(%s)\n", debugstr_a(lpszPath
));
2474 if(!lpszPath
|| !*lpszPath
)
2477 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2479 if (lpszSlash
[1] == '\\')
2481 return lpszSlash
+ 1;
2483 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2486 /*************************************************************************
2487 * PathFindNextComponentW [SHLWAPI.@]
2489 * See PathFindNextComponentA.
2491 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2495 TRACE("(%s)\n", debugstr_w(lpszPath
));
2497 if(!lpszPath
|| !*lpszPath
)
2500 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2502 if (lpszSlash
[1] == '\\')
2504 return lpszSlash
+ 1;
2506 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2509 /*************************************************************************
2510 * PathAddExtensionA [SHLWAPI.@]
2512 * Add a file extension to a path
2515 * lpszPath [I/O] Path to add extension to
2516 * lpszExtension [I] Extension to add to lpszPath
2519 * TRUE If the path was modified,
2520 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2521 * extension already, or the new path length is too big.
2524 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2525 * does not do this, so the behaviour was removed.
2527 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2531 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2533 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2536 dwLen
= strlen(lpszPath
);
2538 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2541 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2545 /*************************************************************************
2546 * PathAddExtensionW [SHLWAPI.@]
2548 * See PathAddExtensionA.
2550 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2554 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2556 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2559 dwLen
= strlenW(lpszPath
);
2561 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2564 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2568 /*************************************************************************
2569 * PathMakePrettyA [SHLWAPI.@]
2571 * Convert an uppercase DOS filename into lowercase.
2574 * lpszPath [I/O] Path to convert.
2577 * TRUE If the path was an uppercase DOS path and was converted,
2580 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2582 LPSTR pszIter
= lpszPath
;
2584 TRACE("(%s)\n", debugstr_a(lpszPath
));
2593 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2594 return FALSE
; /* Not DOS path */
2597 pszIter
= lpszPath
+ 1;
2600 *pszIter
= tolower(*pszIter
);
2607 /*************************************************************************
2608 * PathMakePrettyW [SHLWAPI.@]
2610 * See PathMakePrettyA.
2612 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2614 LPWSTR pszIter
= lpszPath
;
2616 TRACE("(%s)\n", debugstr_w(lpszPath
));
2625 if (islowerW(*pszIter
))
2626 return FALSE
; /* Not DOS path */
2629 pszIter
= lpszPath
+ 1;
2632 *pszIter
= tolowerW(*pszIter
);
2639 /*************************************************************************
2640 * PathCommonPrefixA [SHLWAPI.@]
2642 * Determine the length of the common prefix between two paths.
2645 * lpszFile1 [I] First path for comparison
2646 * lpszFile2 [I] Second path for comparison
2647 * achPath [O] Destination for common prefix string
2650 * The length of the common prefix. This is 0 if there is no common
2651 * prefix between the paths or if any parameters are invalid. If the prefix
2652 * is non-zero and achPath is not NULL, achPath is filled with the common
2653 * part of the prefix and NUL terminated.
2656 * A common prefix of 2 is always returned as 3. It is thus possible for
2657 * the length returned to be invalid (i.e. Longer than one or both of the
2658 * strings given as parameters). This Win32 behaviour has been implemented
2659 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2660 * To work around this when using this function, always check that the byte
2661 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2663 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2666 LPCSTR lpszIter1
= lpszFile1
;
2667 LPCSTR lpszIter2
= lpszFile2
;
2669 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2674 if (!lpszFile1
|| !lpszFile2
)
2677 /* Handle roots first */
2678 if (PathIsUNCA(lpszFile1
))
2680 if (!PathIsUNCA(lpszFile2
))
2685 else if (PathIsUNCA(lpszFile2
))
2686 return 0; /* Know already lpszFile1 is not UNC */
2691 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2692 (!*lpszIter2
|| *lpszIter2
== '\\'))
2693 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2695 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2696 break; /* Strings differ at this point */
2703 iLen
++; /* Feature/Bug compatible with Win32 */
2705 if (iLen
&& achPath
)
2707 memcpy(achPath
,lpszFile1
,iLen
);
2708 achPath
[iLen
] = '\0';
2713 /*************************************************************************
2714 * PathCommonPrefixW [SHLWAPI.@]
2716 * See PathCommonPrefixA.
2718 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2721 LPCWSTR lpszIter1
= lpszFile1
;
2722 LPCWSTR lpszIter2
= lpszFile2
;
2724 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2729 if (!lpszFile1
|| !lpszFile2
)
2732 /* Handle roots first */
2733 if (PathIsUNCW(lpszFile1
))
2735 if (!PathIsUNCW(lpszFile2
))
2740 else if (PathIsUNCW(lpszFile2
))
2741 return 0; /* Know already lpszFile1 is not UNC */
2746 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2747 (!*lpszIter2
|| *lpszIter2
== '\\'))
2748 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2750 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2751 break; /* Strings differ at this point */
2758 iLen
++; /* Feature/Bug compatible with Win32 */
2760 if (iLen
&& achPath
)
2762 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2763 achPath
[iLen
] = '\0';
2768 /*************************************************************************
2769 * PathCompactPathA [SHLWAPI.@]
2771 * Make a path fit into a given width when printed to a DC.
2774 * hDc [I] Destination DC
2775 * lpszPath [I/O] Path to be printed to hDc
2776 * dx [I] Desired width
2779 * TRUE If the path was modified/went well.
2782 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2786 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2790 WCHAR szPath
[MAX_PATH
];
2791 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2792 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2793 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2798 /*************************************************************************
2799 * PathCompactPathW [SHLWAPI.@]
2801 * See PathCompactPathA.
2803 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2805 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2808 WCHAR buff
[MAX_PATH
];
2812 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2818 hdc
= hDC
= GetDC(0);
2820 /* Get the length of the whole path */
2821 dwLen
= strlenW(lpszPath
);
2822 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2824 if ((UINT
)size
.cx
> dx
)
2826 /* Path too big, must reduce it */
2828 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2830 sFile
= PathFindFileNameW(lpszPath
);
2831 if (sFile
!= lpszPath
) sFile
--;
2833 /* Get the size of ellipses */
2834 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2835 dwEllipsesLen
= size
.cx
;
2836 /* Get the size of the file name */
2837 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2838 dwPathLen
= size
.cx
;
2840 if (sFile
!= lpszPath
)
2842 LPWSTR sPath
= sFile
;
2843 BOOL bEllipses
= FALSE
;
2845 /* The path includes a file name. Include as much of the path prior to
2846 * the file name as possible, allowing for the ellipses, e.g:
2847 * c:\some very long path\filename ==> c:\some v...\filename
2849 lstrcpynW(buff
, sFile
, MAX_PATH
);
2853 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2855 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2856 dwTotalLen
+= size
.cx
;
2857 if (dwTotalLen
<= dx
)
2865 } while (sPath
> lpszPath
);
2867 if (sPath
> lpszPath
)
2871 strcpyW(sPath
, szEllipses
);
2872 strcpyW(sPath
+3, buff
);
2877 strcpyW(lpszPath
, szEllipses
);
2878 strcpyW(lpszPath
+3, buff
);
2883 /* Trim the path by adding ellipses to the end, e.g:
2884 * A very long file name.txt ==> A very...
2886 dwLen
= strlenW(lpszPath
);
2888 if (dwLen
> MAX_PATH
- 3)
2889 dwLen
= MAX_PATH
- 3;
2890 lstrcpynW(buff
, sFile
, dwLen
);
2894 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2895 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2899 DWORD dwWritten
= 0;
2901 dwEllipsesLen
/= 3; /* Size of a single '.' */
2903 /* Write as much of the Ellipses string as possible */
2904 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2907 dwWritten
+= dwEllipsesLen
;
2915 strcpyW(buff
+ dwLen
, szEllipses
);
2916 strcpyW(lpszPath
, buff
);
2927 /*************************************************************************
2928 * PathGetCharTypeA [SHLWAPI.@]
2930 * Categorise a character from a file path.
2933 * ch [I] Character to get the type of
2936 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2938 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2940 return PathGetCharTypeW(ch
);
2943 /*************************************************************************
2944 * PathGetCharTypeW [SHLWAPI.@]
2946 * See PathGetCharTypeA.
2948 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2952 TRACE("(%d)\n", ch
);
2954 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2955 ch
== '"' || ch
== '|' || ch
== '/')
2956 flags
= GCT_INVALID
; /* Invalid */
2957 else if (ch
== '*' || ch
=='?')
2958 flags
= GCT_WILD
; /* Wildchars */
2959 else if ((ch
== '\\') || (ch
== ':'))
2960 return GCT_SEPARATOR
; /* Path separators */
2965 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2966 ch
== '.' || ch
== '@' || ch
== '^' ||
2967 ch
== '\'' || ch
== 130 || ch
== '`')
2968 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2971 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2972 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2977 /*************************************************************************
2978 * SHLWAPI_UseSystemForSystemFolders
2980 * Internal helper for PathMakeSystemFolderW.
2982 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
2984 static BOOL bCheckedReg
= FALSE
;
2985 static BOOL bUseSystemForSystemFolders
= FALSE
;
2991 /* Key tells Win what file attributes to use on system folders */
2992 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
2993 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2994 "UseSystemForSystemFolders", 0, 0, 0))
2995 bUseSystemForSystemFolders
= TRUE
;
2997 return bUseSystemForSystemFolders
;
3000 /*************************************************************************
3001 * PathMakeSystemFolderA [SHLWAPI.@]
3003 * Set system folder attribute for a path.
3006 * lpszPath [I] The path to turn into a system folder
3009 * TRUE If the path was changed to/already was a system folder
3010 * FALSE If the path is invalid or SetFileAttributesA() fails
3012 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3016 TRACE("(%s)\n", debugstr_a(lpszPath
));
3018 if (lpszPath
&& *lpszPath
)
3020 WCHAR szPath
[MAX_PATH
];
3021 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3022 bRet
= PathMakeSystemFolderW(szPath
);
3027 /*************************************************************************
3028 * PathMakeSystemFolderW [SHLWAPI.@]
3030 * See PathMakeSystemFolderA.
3032 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3034 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3035 WCHAR buff
[MAX_PATH
];
3037 TRACE("(%s)\n", debugstr_w(lpszPath
));
3039 if (!lpszPath
|| !*lpszPath
)
3042 /* If the directory is already a system directory, don't do anything */
3043 GetSystemDirectoryW(buff
, MAX_PATH
);
3044 if (!strcmpW(buff
, lpszPath
))
3047 GetWindowsDirectoryW(buff
, MAX_PATH
);
3048 if (!strcmpW(buff
, lpszPath
))
3051 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3052 if (SHLWAPI_UseSystemForSystemFolders())
3053 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3055 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3058 /* Change file attributes to system attributes */
3059 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3060 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3063 /*************************************************************************
3064 * PathRenameExtensionA [SHLWAPI.@]
3066 * Swap the file extension in a path with another extension.
3069 * lpszPath [I/O] Path to swap the extension in
3070 * lpszExt [I] The new extension
3073 * TRUE if lpszPath was modified,
3074 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3076 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3078 LPSTR lpszExtension
;
3080 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3082 lpszExtension
= PathFindExtensionA(lpszPath
);
3084 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3087 strcpy(lpszExtension
, lpszExt
);
3091 /*************************************************************************
3092 * PathRenameExtensionW [SHLWAPI.@]
3094 * See PathRenameExtensionA.
3096 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3098 LPWSTR lpszExtension
;
3100 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3102 lpszExtension
= PathFindExtensionW(lpszPath
);
3104 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3107 strcpyW(lpszExtension
, lpszExt
);
3111 /*************************************************************************
3112 * PathSearchAndQualifyA [SHLWAPI.@]
3114 * Determine if a given path is correct and fully qualified.
3117 * lpszPath [I] Path to check
3118 * lpszBuf [O] Output for correct path
3119 * cchBuf [I] Size of lpszBuf
3124 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3126 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3128 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3130 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3133 /*************************************************************************
3134 * PathSearchAndQualifyW [SHLWAPI.@]
3136 * See PathSearchAndQualifyA.
3138 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3140 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3142 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3144 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3147 /*************************************************************************
3148 * PathSkipRootA [SHLWAPI.@]
3150 * Return the portion of a path following the drive letter or mount point.
3153 * lpszPath [I] The path to skip on
3156 * Success: A pointer to the next character after the root.
3157 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3159 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3161 TRACE("(%s)\n", debugstr_a(lpszPath
));
3163 if (!lpszPath
|| !*lpszPath
)
3166 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3168 /* Network share: skip share server and mount point */
3170 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3171 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3173 return (LPSTR
)lpszPath
;
3176 if (IsDBCSLeadByte(*lpszPath
))
3180 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3181 return (LPSTR
)lpszPath
+ 3;
3185 /*************************************************************************
3186 * PathSkipRootW [SHLWAPI.@]
3188 * See PathSkipRootA.
3190 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3192 TRACE("(%s)\n", debugstr_w(lpszPath
));
3194 if (!lpszPath
|| !*lpszPath
)
3197 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3199 /* Network share: skip share server and mount point */
3201 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3202 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3204 return (LPWSTR
)lpszPath
;
3208 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3209 return (LPWSTR
)lpszPath
+ 3;
3213 /*************************************************************************
3214 * PathCreateFromUrlA [SHLWAPI.@]
3216 * See PathCreateFromUrlW
3218 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3219 LPDWORD pcchPath
, DWORD dwReserved
)
3221 WCHAR bufW
[MAX_PATH
];
3222 WCHAR
*pathW
= bufW
;
3223 UNICODE_STRING urlW
;
3225 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3227 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3228 return E_INVALIDARG
;
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 };
3271 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3272 DWORD nslashes
, unescape
, len
;
3277 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3279 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3280 return E_INVALIDARG
;
3282 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3283 file_colon
, 5) != CSTR_EQUAL
)
3284 return E_INVALIDARG
;
3290 while (*src
== '/' || *src
== '\\') {
3295 /* We need a temporary buffer so we can compute what size to ask for.
3296 * We know that the final string won't be longer than the current pszUrl
3297 * plus at most two backslashes. All the other transformations make it
3300 len
= 2 + lstrlenW(pszUrl
) + 1;
3301 if (*pcchPath
< len
)
3302 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3312 /* 'file:' + escaped DOS path */
3315 /* 'file:/' + escaped DOS path */
3318 /* 'file:///' (implied localhost) + escaped DOS path */
3319 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3323 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, src
, 9,
3324 localhost
, 9) == CSTR_EQUAL
&&
3325 (src
[9] == '/' || src
[9] == '\\'))
3327 /* 'file://localhost/' + escaped DOS path */
3330 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3332 /* 'file://' + unescaped DOS path */
3337 /* 'file://hostname:port/path' (where path is escaped)
3338 * or 'file:' + escaped UNC path (\\server\share\path)
3339 * The second form is clearly specific to Windows and it might
3340 * even be doing a network lookup to try to figure it out.
3342 while (*src
&& *src
!= '/' && *src
!= '\\')
3345 StrCpyNW(dst
, pszUrl
, len
+ 1);
3347 if (isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3349 /* 'Forget' to add a trailing '/', just like Windows */
3355 /* 'file://' + unescaped UNC path (\\server\share\path) */
3357 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3361 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3365 /* Copy the remainder of the path */
3366 len
+= lstrlenW(src
);
3369 /* First do the Windows-specific path conversions */
3370 for (dst
= tpath
; *dst
; dst
++)
3371 if (*dst
== '/') *dst
= '\\';
3372 if (isalphaW(*tpath
) && tpath
[1] == '|')
3373 tpath
[1] = ':'; /* c| -> c: */
3375 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3378 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3381 /* When working in-place UrlUnescapeW() does not set len */
3382 len
= lstrlenW(tpath
);
3386 if (*pcchPath
< len
+ 1)
3389 *pcchPath
= len
+ 1;
3394 if (tpath
!= pszPath
)
3395 StrCpyW(pszPath
, tpath
);
3397 if (tpath
!= pszPath
)
3398 HeapFree(GetProcessHeap(), 0, tpath
);
3400 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3404 /*************************************************************************
3405 * PathCreateFromUrlAlloc [SHLWAPI.@]
3407 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3410 WCHAR pathW
[MAX_PATH
];
3415 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3418 /* Yes, this is supposed to crash if pszPath is NULL */
3419 *pszPath
= StrDupW(pathW
);
3424 /*************************************************************************
3425 * PathRelativePathToA [SHLWAPI.@]
3427 * Create a relative path from one path to another.
3430 * lpszPath [O] Destination for relative path
3431 * lpszFrom [I] Source path
3432 * dwAttrFrom [I] File attribute of source path
3433 * lpszTo [I] Destination path
3434 * dwAttrTo [I] File attributes of destination path
3437 * TRUE If a relative path can be formed. lpszPath contains the new path
3438 * FALSE If the paths are not relative or any parameters are invalid
3441 * lpszTo should be at least MAX_PATH in length.
3443 * Calling this function with relative paths for lpszFrom or lpszTo may
3444 * give erroneous results.
3446 * The Win32 version of this function contains a bug where the lpszTo string
3447 * may be referenced 1 byte beyond the end of the string. As a result random
3448 * garbage may be written to the output path, depending on what lies beyond
3449 * the last byte of the string. This bug occurs because of the behaviour of
3450 * PathCommonPrefix() (see notes for that function), and no workaround seems
3451 * possible with Win32.
3453 * This bug has been fixed here, so for example the relative path from "\\"
3454 * to "\\" is correctly determined as "." in this implementation.
3456 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3457 LPCSTR lpszTo
, DWORD dwAttrTo
)
3461 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3462 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3464 if(lpszPath
&& lpszFrom
&& lpszTo
)
3466 WCHAR szPath
[MAX_PATH
];
3467 WCHAR szFrom
[MAX_PATH
];
3468 WCHAR szTo
[MAX_PATH
];
3469 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3470 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3471 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3472 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3477 /*************************************************************************
3478 * PathRelativePathToW [SHLWAPI.@]
3480 * See PathRelativePathToA.
3482 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3483 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3485 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3486 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3487 WCHAR szFrom
[MAX_PATH
];
3488 WCHAR szTo
[MAX_PATH
];
3491 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3492 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3494 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3498 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3499 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3501 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3502 PathRemoveFileSpecW(szFrom
);
3503 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3504 PathRemoveFileSpecW(szTo
);
3506 /* Paths can only be relative if they have a common root */
3507 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3510 /* Strip off lpszFrom components to the root, by adding "..\" */
3511 lpszFrom
= szFrom
+ dwLen
;
3517 if (*lpszFrom
== '\\')
3522 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3523 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3526 /* From the root add the components of lpszTo */
3528 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3531 if (*lpszTo
&& lpszTo
[-1])
3533 if (*lpszTo
!= '\\')
3535 dwLen
= strlenW(lpszPath
);
3536 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3541 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3546 /*************************************************************************
3547 * PathUnmakeSystemFolderA [SHLWAPI.@]
3549 * Remove the system folder attributes from a path.
3552 * lpszPath [I] The path to remove attributes from
3556 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3557 * SetFileAttributesA() fails.
3559 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3563 TRACE("(%s)\n", debugstr_a(lpszPath
));
3565 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3566 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3569 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3570 return SetFileAttributesA(lpszPath
, dwAttr
);
3573 /*************************************************************************
3574 * PathUnmakeSystemFolderW [SHLWAPI.@]
3576 * See PathUnmakeSystemFolderA.
3578 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3582 TRACE("(%s)\n", debugstr_w(lpszPath
));
3584 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3585 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3588 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3589 return SetFileAttributesW(lpszPath
, dwAttr
);
3593 /*************************************************************************
3594 * PathSetDlgItemPathA [SHLWAPI.@]
3596 * Set the text of a dialog item to a path, shrinking the path to fit
3597 * if it is too big for the item.
3600 * hDlg [I] Dialog handle
3601 * id [I] ID of item in the dialog
3602 * lpszPath [I] Path to set as the items text
3608 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3609 * window text is erased).
3611 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3613 WCHAR szPath
[MAX_PATH
];
3615 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3618 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3621 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3624 /*************************************************************************
3625 * PathSetDlgItemPathW [SHLWAPI.@]
3627 * See PathSetDlgItemPathA.
3629 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3631 WCHAR path
[MAX_PATH
+ 1];
3637 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3639 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3643 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3647 GetClientRect(hwItem
, &rect
);
3649 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3653 PathCompactPathW(hdc
, path
, rect
.right
);
3654 SelectObject(hdc
, hPrevObj
);
3657 ReleaseDC(hDlg
, hdc
);
3658 SetWindowTextW(hwItem
, path
);
3661 /*************************************************************************
3662 * PathIsNetworkPathA [SHLWAPI.@]
3664 * Determine if the given path is a network path.
3667 * lpszPath [I] Path to check
3670 * TRUE If lpszPath is a UNC share or mapped network drive, or
3671 * FALSE If lpszPath is a local drive or cannot be determined
3673 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3677 TRACE("(%s)\n",debugstr_a(lpszPath
));
3681 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3683 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3684 if (dwDriveNum
== -1)
3686 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3687 return pIsNetDrive(dwDriveNum
);
3690 /*************************************************************************
3691 * PathIsNetworkPathW [SHLWAPI.@]
3693 * See PathIsNetworkPathA.
3695 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3699 TRACE("(%s)\n", debugstr_w(lpszPath
));
3703 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3705 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3706 if (dwDriveNum
== -1)
3708 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3709 return pIsNetDrive(dwDriveNum
);
3712 /*************************************************************************
3713 * PathIsLFNFileSpecA [SHLWAPI.@]
3715 * Determine if the given path is a long file name
3718 * lpszPath [I] Path to check
3721 * TRUE If path is a long file name,
3722 * FALSE If path is a valid DOS short file name
3724 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3726 DWORD dwNameLen
= 0, dwExtLen
= 0;
3728 TRACE("(%s)\n",debugstr_a(lpszPath
));
3735 if (*lpszPath
== ' ')
3736 return TRUE
; /* DOS names cannot have spaces */
3737 if (*lpszPath
== '.')
3740 return TRUE
; /* DOS names have only one dot */
3747 return TRUE
; /* DOS extensions are <= 3 chars*/
3753 return TRUE
; /* DOS names are <= 8 chars */
3755 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3757 return FALSE
; /* Valid DOS path */
3760 /*************************************************************************
3761 * PathIsLFNFileSpecW [SHLWAPI.@]
3763 * See PathIsLFNFileSpecA.
3765 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3767 DWORD dwNameLen
= 0, dwExtLen
= 0;
3769 TRACE("(%s)\n",debugstr_w(lpszPath
));
3776 if (*lpszPath
== ' ')
3777 return TRUE
; /* DOS names cannot have spaces */
3778 if (*lpszPath
== '.')
3781 return TRUE
; /* DOS names have only one dot */
3788 return TRUE
; /* DOS extensions are <= 3 chars*/
3794 return TRUE
; /* DOS names are <= 8 chars */
3798 return FALSE
; /* Valid DOS path */
3801 /*************************************************************************
3802 * PathIsDirectoryEmptyA [SHLWAPI.@]
3804 * Determine if a given directory is empty.
3807 * lpszPath [I] Directory to check
3810 * TRUE If the directory exists and contains no files,
3813 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3817 TRACE("(%s)\n",debugstr_a(lpszPath
));
3821 WCHAR szPath
[MAX_PATH
];
3822 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3823 bRet
= PathIsDirectoryEmptyW(szPath
);
3828 /*************************************************************************
3829 * PathIsDirectoryEmptyW [SHLWAPI.@]
3831 * See PathIsDirectoryEmptyA.
3833 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3835 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3836 WCHAR szSearch
[MAX_PATH
];
3839 BOOL retVal
= FALSE
;
3840 WIN32_FIND_DATAW find_data
;
3842 TRACE("(%s)\n",debugstr_w(lpszPath
));
3844 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3847 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3848 PathAddBackslashW(szSearch
);
3849 dwLen
= strlenW(szSearch
);
3850 if (dwLen
> MAX_PATH
- 4)
3853 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3854 hfind
= FindFirstFileW(szSearch
, &find_data
);
3856 if (hfind
!= INVALID_HANDLE_VALUE
&&
3857 find_data
.cFileName
[0] == '.' &&
3858 find_data
.cFileName
[1] == '.')
3860 /* The only directory entry should be the parent */
3861 if (!FindNextFileW(hfind
, &find_data
))
3869 /*************************************************************************
3870 * PathFindSuffixArrayA [SHLWAPI.@]
3872 * Find a suffix string in an array of suffix strings
3875 * lpszSuffix [I] Suffix string to search for
3876 * lppszArray [I] Array of suffix strings to search
3877 * dwCount [I] Number of elements in lppszArray
3880 * Success: The index of the position of lpszSuffix in lppszArray
3881 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3884 * The search is case sensitive.
3885 * The match is made against the end of the suffix string, so for example:
3886 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3888 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3893 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3895 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3897 dwLen
= strlen(lpszSuffix
);
3899 while (dwRet
< dwCount
)
3901 size_t dwCompareLen
= strlen(*lppszArray
);
3902 if (dwCompareLen
< dwLen
)
3904 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3905 return *lppszArray
; /* Found */
3914 /*************************************************************************
3915 * PathFindSuffixArrayW [SHLWAPI.@]
3917 * See PathFindSuffixArrayA.
3919 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3924 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3926 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3928 dwLen
= strlenW(lpszSuffix
);
3930 while (dwRet
< dwCount
)
3932 size_t dwCompareLen
= strlenW(*lppszArray
);
3933 if (dwCompareLen
< dwLen
)
3935 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3936 return *lppszArray
; /* Found */
3945 /*************************************************************************
3946 * PathUndecorateA [SHLWAPI.@]
3948 * Undecorate a file path
3951 * lpszPath [I/O] Path to remove any decoration from
3957 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3959 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3961 TRACE("(%s)\n",debugstr_a(lpszPath
));
3965 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3966 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3968 LPSTR lpszSkip
= lpszExt
- 2;
3969 if (*lpszSkip
== '[')
3970 lpszSkip
++; /* [] (no number) */
3972 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3974 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3976 /* remove the [n] */
3979 *lpszSkip
++ = *lpszExt
++;
3986 /*************************************************************************
3987 * PathUndecorateW [SHLWAPI.@]
3989 * See PathUndecorateA.
3991 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3993 TRACE("(%s)\n",debugstr_w(lpszPath
));
3997 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3998 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4000 LPWSTR lpszSkip
= lpszExt
- 2;
4001 if (*lpszSkip
== '[')
4002 lpszSkip
++; /* [] (no number) */
4004 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4006 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4008 /* remove the [n] */
4011 *lpszSkip
++ = *lpszExt
++;
4018 /*************************************************************************
4019 * PathUnExpandEnvStringsA [SHLWAPI.@]
4021 * Substitute folder names in a path with their corresponding environment
4025 * pszPath [I] Buffer containing the path to unexpand.
4026 * pszBuf [O] Buffer to receive the unexpanded path.
4027 * cchBuf [I] Size of pszBuf in characters.
4033 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR pszPath
, LPSTR pszBuf
, UINT cchBuf
)
4035 FIXME("(%s,%s,0x%08x)\n", debugstr_a(pszPath
), debugstr_a(pszBuf
), cchBuf
);
4039 /*************************************************************************
4040 * PathUnExpandEnvStringsW [SHLWAPI.@]
4042 * Unicode version of PathUnExpandEnvStringsA.
4044 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR pszPath
, LPWSTR pszBuf
, UINT cchBuf
)
4046 FIXME("(%s,%s,0x%08x)\n", debugstr_w(pszPath
), debugstr_w(pszBuf
), cchBuf
);
4050 /*************************************************************************
4053 * Find localised or default web content in "%WINDOWS%\web\".
4056 * lpszFile [I] File name containing content to look for
4057 * lpszPath [O] Buffer to contain the full path to the file
4058 * dwPathLen [I] Length of lpszPath
4061 * Success: S_OK. lpszPath contains the full path to the content.
4062 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4064 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4066 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4069 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4071 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4073 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4074 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4078 /*************************************************************************
4081 * Unicode version of SHGetWebFolderFilePathA.
4083 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4085 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4086 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4087 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4088 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4089 DWORD dwLen
, dwFileLen
;
4090 LANGID lidSystem
, lidUser
;
4092 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4094 /* Get base directory for web content */
4095 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4096 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4099 dwFileLen
= strlenW(lpszFile
);
4101 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4102 return E_FAIL
; /* lpszPath too short */
4104 strcpyW(lpszPath
+dwLen
, szWeb
);
4106 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4108 lidSystem
= GetSystemDefaultUILanguage();
4109 lidUser
= GetUserDefaultUILanguage();
4111 if (lidSystem
!= lidUser
)
4113 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4115 /* Use localised content in the users UI language if present */
4116 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4117 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4118 if (PathFileExistsW(lpszPath
))
4123 /* Fall back to OS default installed content */
4124 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4125 if (PathFileExistsW(lpszPath
))
4130 #define PATH_CHAR_CLASS_LETTER 0x00000001
4131 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4132 #define PATH_CHAR_CLASS_DOT 0x00000004
4133 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4134 #define PATH_CHAR_CLASS_COLON 0x00000010
4135 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4136 #define PATH_CHAR_CLASS_COMMA 0x00000040
4137 #define PATH_CHAR_CLASS_SPACE 0x00000080
4138 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4139 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4141 #define PATH_CHAR_CLASS_INVALID 0x00000000
4142 #define PATH_CHAR_CLASS_ANY 0xffffffff
4144 static const DWORD SHELL_charclass
[] =
4146 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4147 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4148 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4149 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4150 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4151 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4152 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4153 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4154 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4155 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4156 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4157 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4158 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4159 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4160 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4161 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4162 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4163 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4164 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4165 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4166 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4167 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4168 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4169 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4170 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4171 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4172 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4173 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4174 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4175 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4176 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4177 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4178 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4179 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4180 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4181 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4182 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4183 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4184 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4185 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4186 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4187 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4188 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4189 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4190 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4191 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4192 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4193 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4194 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4195 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4196 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4197 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4198 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4199 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4200 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4201 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4202 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4203 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4204 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4205 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4206 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4207 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4208 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4209 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4212 /*************************************************************************
4215 * Check if an ASCII char is of a certain class
4217 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4219 if ((unsigned)c
> 0x7e)
4220 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4222 return class & SHELL_charclass
[(unsigned)c
];
4225 /*************************************************************************
4228 * Check if a Unicode char is of a certain class
4230 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4233 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4235 return class & SHELL_charclass
[c
];