4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2001, 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
29 #include "wine/unicode.h"
36 #define NO_SHLWAPI_STREAM
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 /* Get a function pointer from a DLL handle */
43 #define GET_FUNC(func, module, name, fail) \
46 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
47 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
48 if (!func) return fail; \
52 /* DLL handles for late bound calls */
53 static HMODULE SHLWAPI_hshell32
;
55 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
56 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
57 static fnpIsNetDrive pIsNetDrive
;
59 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
61 /*************************************************************************
62 * PathAppendA [SHLWAPI.@]
64 * Append one path to another.
67 * lpszPath [I/O] Initial part of path, and destination for output
68 * lpszAppend [I] Path to append
71 * Success: TRUE. lpszPath contains the newly created path.
72 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
75 * lpszAppend must contain at least one backslash ('\') if not NULL.
76 * Because PathCombineA() is used to join the paths, the resulting
77 * path is also canonicalized.
79 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
81 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
83 if (lpszPath
&& lpszAppend
)
85 if (!PathIsUNCA(lpszAppend
))
86 while (*lpszAppend
== '\\')
88 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
94 /*************************************************************************
95 * PathAppendW [SHLWAPI.@]
99 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
101 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
103 if (lpszPath
&& lpszAppend
)
105 if (!PathIsUNCW(lpszAppend
))
106 while (*lpszAppend
== '\\')
108 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
114 /*************************************************************************
115 * PathCombineA [SHLWAPI.@]
117 * Combine two paths together.
120 * lpszDest [O] Destination for combined path
121 * lpszDir [I] Directory path
122 * lpszFile [I] File path
125 * Success: The output path
126 * Failure: NULL, if inputs are invalid.
129 * lpszDest should be at least MAX_PATH in size, and may point to the same
130 * memory location as lpszDir. The combined path is canonicalised.
132 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
134 WCHAR szDest
[MAX_PATH
];
135 WCHAR szDir
[MAX_PATH
];
136 WCHAR szFile
[MAX_PATH
];
137 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
139 /* Invalid parameters */
142 if (!lpszDir
&& !lpszFile
)
149 MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
);
151 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
153 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
154 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
161 /*************************************************************************
162 * PathCombineW [SHLWAPI.@]
166 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
168 WCHAR szTemp
[MAX_PATH
];
169 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
171 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
173 /* Invalid parameters */
176 if (!lpszDir
&& !lpszFile
)
182 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
185 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
187 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
189 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
192 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
205 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
208 PathStripToRootW(szTemp
);
209 lpszFile
++; /* Skip '\' */
211 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
216 strcatW(szTemp
, lpszFile
);
219 PathCanonicalizeW(lpszDest
, szTemp
);
223 /*************************************************************************
224 * PathAddBackslashA [SHLWAPI.@]
226 * Append a backslash ('\') to a path if one doesn't exist.
229 * lpszPath [I/O] The path to append a backslash to.
232 * Success: The position of the last backslash in the path.
233 * Failure: NULL, if lpszPath is NULL or the path is too large.
235 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
239 TRACE("(%s)\n",debugstr_a(lpszPath
));
241 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
247 if (lpszPath
[-1] != '\\')
256 /*************************************************************************
257 * PathAddBackslashW [SHLWAPI.@]
259 * See PathAddBackslashA.
261 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
265 TRACE("(%s)\n",debugstr_w(lpszPath
));
267 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
273 if (lpszPath
[-1] != '\\')
282 /*************************************************************************
283 * PathBuildRootA [SHLWAPI.@]
285 * Create a root drive string (e.g. "A:\") from a drive number.
288 * lpszPath [O] Destination for the drive string
294 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
296 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
298 TRACE("(%p,%d)\n", lpszPath
, drive
);
300 if (lpszPath
&& drive
>= 0 && drive
< 26)
302 lpszPath
[0] = 'A' + drive
;
310 /*************************************************************************
311 * PathBuildRootW [SHLWAPI.@]
313 * See PathBuildRootA.
315 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
317 TRACE("(%p,%d)\n", lpszPath
, drive
);
319 if (lpszPath
&& drive
>= 0 && drive
< 26)
321 lpszPath
[0] = 'A' + drive
;
329 /*************************************************************************
330 * PathFindFileNameA [SHLWAPI.@]
332 * Locate the start of the file name in a path
335 * lpszPath [I] Path to search
338 * A pointer to the first character of the file name
340 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
342 LPCSTR lastSlash
= lpszPath
;
344 TRACE("(%s)\n",debugstr_a(lpszPath
));
346 while (lpszPath
&& *lpszPath
)
348 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
349 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
350 lastSlash
= lpszPath
+ 1;
351 lpszPath
= CharNextA(lpszPath
);
353 return (LPSTR
)lastSlash
;
356 /*************************************************************************
357 * PathFindFileNameW [SHLWAPI.@]
359 * See PathFindFileNameA.
361 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
363 LPCWSTR lastSlash
= lpszPath
;
365 TRACE("(%s)\n",debugstr_w(lpszPath
));
367 while (lpszPath
&& *lpszPath
)
369 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
370 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
371 lastSlash
= lpszPath
+ 1;
372 lpszPath
= CharNextW(lpszPath
);
374 return (LPWSTR
)lastSlash
;
377 /*************************************************************************
378 * PathFindExtensionA [SHLWAPI.@]
380 * Locate the start of the file extension in a path
383 * lpszPath [I] The path to search
386 * A pointer to the first character of the extension, the end of
387 * the string if the path has no extension, or NULL If lpszPath is NULL
389 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
391 LPCSTR lastpoint
= NULL
;
393 TRACE("(%s)\n", debugstr_a(lpszPath
));
399 if (*lpszPath
== '\\' || *lpszPath
==' ')
401 else if (*lpszPath
== '.')
402 lastpoint
= lpszPath
;
403 lpszPath
= CharNextA(lpszPath
);
406 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
409 /*************************************************************************
410 * PathFindExtensionW [SHLWAPI.@]
412 * See PathFindExtensionA.
414 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
416 LPCWSTR lastpoint
= NULL
;
418 TRACE("(%s)\n", debugstr_w(lpszPath
));
424 if (*lpszPath
== '\\' || *lpszPath
==' ')
426 else if (*lpszPath
== '.')
427 lastpoint
= lpszPath
;
428 lpszPath
= CharNextW(lpszPath
);
431 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
434 /*************************************************************************
435 * PathGetArgsA [SHLWAPI.@]
437 * Find the next argument in a string delimited by spaces.
440 * lpszPath [I] The string to search for arguments in
443 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
446 * Spaces in quoted strings are ignored as delimiters.
448 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
450 BOOL bSeenQuote
= FALSE
;
452 TRACE("(%s)\n",debugstr_a(lpszPath
));
458 if ((*lpszPath
==' ') && !bSeenQuote
)
459 return (LPSTR
)lpszPath
+ 1;
460 if (*lpszPath
== '"')
461 bSeenQuote
= !bSeenQuote
;
462 lpszPath
= CharNextA(lpszPath
);
465 return (LPSTR
)lpszPath
;
468 /*************************************************************************
469 * PathGetArgsW [SHLWAPI.@]
473 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
475 BOOL bSeenQuote
= FALSE
;
477 TRACE("(%s)\n",debugstr_w(lpszPath
));
483 if ((*lpszPath
==' ') && !bSeenQuote
)
484 return (LPWSTR
)lpszPath
+ 1;
485 if (*lpszPath
== '"')
486 bSeenQuote
= !bSeenQuote
;
487 lpszPath
= CharNextW(lpszPath
);
490 return (LPWSTR
)lpszPath
;
493 /*************************************************************************
494 * PathGetDriveNumberA [SHLWAPI.@]
496 * Return the drive number from a path
499 * lpszPath [I] Path to get the drive number from
502 * Success: The drive number corresponding to the drive in the path
503 * Failure: -1, if lpszPath contains no valid drive
505 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
507 TRACE ("(%s)\n",debugstr_a(lpszPath
));
509 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
510 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
511 return tolower(*lpszPath
) - 'a';
515 /*************************************************************************
516 * PathGetDriveNumberW [SHLWAPI.@]
518 * See PathGetDriveNumberA.
520 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
522 TRACE ("(%s)\n",debugstr_w(lpszPath
));
526 WCHAR tl
= tolowerW(lpszPath
[0]);
527 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
533 /*************************************************************************
534 * PathRemoveFileSpecA [SHLWAPI.@]
536 * Remove the file specification from a path.
539 * lpszPath [I/O] Path to remove the file spec from
542 * TRUE If the path was valid and modified
545 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
547 LPSTR lpszFileSpec
= lpszPath
;
548 BOOL bModified
= FALSE
;
550 TRACE("(%s)\n",debugstr_a(lpszPath
));
554 /* Skip directory or UNC path */
555 if (*lpszPath
== '\\')
556 lpszFileSpec
= ++lpszPath
;
557 if (*lpszPath
== '\\')
558 lpszFileSpec
= ++lpszPath
;
562 if(*lpszPath
== '\\')
563 lpszFileSpec
= lpszPath
; /* Skip dir */
564 else if(*lpszPath
== ':')
566 lpszFileSpec
= ++lpszPath
; /* Skip drive */
567 if (*lpszPath
== '\\')
570 if (!(lpszPath
= CharNextA(lpszPath
)))
576 *lpszFileSpec
= '\0';
583 /*************************************************************************
584 * PathRemoveFileSpecW [SHLWAPI.@]
586 * See PathRemoveFileSpecA.
588 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
590 LPWSTR lpszFileSpec
= lpszPath
;
591 BOOL bModified
= FALSE
;
593 TRACE("(%s)\n",debugstr_w(lpszPath
));
597 /* Skip directory or UNC path */
598 if (*lpszPath
== '\\')
599 lpszFileSpec
= ++lpszPath
;
600 if (*lpszPath
== '\\')
601 lpszFileSpec
= ++lpszPath
;
605 if(*lpszPath
== '\\')
606 lpszFileSpec
= lpszPath
; /* Skip dir */
607 else if(*lpszPath
== ':')
609 lpszFileSpec
= ++lpszPath
; /* Skip drive */
610 if (*lpszPath
== '\\')
613 if (!(lpszPath
= CharNextW(lpszPath
)))
619 *lpszFileSpec
= '\0';
626 /*************************************************************************
627 * PathStripPathA [SHLWAPI.@]
629 * Remove the initial path from the beginning of a filename
632 * lpszPath [I/O] Path to remove the initial path from
637 void WINAPI
PathStripPathA(LPSTR lpszPath
)
639 TRACE("(%s)\n", debugstr_a(lpszPath
));
643 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
645 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
649 /*************************************************************************
650 * PathStripPathW [SHLWAPI.@]
652 * See PathStripPathA.
654 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
658 TRACE("(%s)\n", debugstr_w(lpszPath
));
659 lpszFileName
= PathFindFileNameW(lpszPath
);
661 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
664 /*************************************************************************
665 * PathStripToRootA [SHLWAPI.@]
667 * Reduce a path to its root.
670 * lpszPath [I/O] the path to reduce
673 * Success: TRUE if the stripped path is a root path
674 * Failure: FALSE if the path cannot be stripped or is NULL
676 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
678 TRACE("(%s)\n", debugstr_a(lpszPath
));
682 while(!PathIsRootA(lpszPath
))
683 if (!PathRemoveFileSpecA(lpszPath
))
688 /*************************************************************************
689 * PathStripToRootW [SHLWAPI.@]
691 * See PathStripToRootA.
693 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
695 TRACE("(%s)\n", debugstr_w(lpszPath
));
699 while(!PathIsRootW(lpszPath
))
700 if (!PathRemoveFileSpecW(lpszPath
))
705 /*************************************************************************
706 * PathRemoveArgsA [SHLWAPI.@]
708 * Strip space separated arguments from a path.
711 * lpszPath [I/O] Path to remove arguments from
716 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
718 TRACE("(%s)\n",debugstr_a(lpszPath
));
722 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
727 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
728 if(*lpszLastChar
== ' ')
729 *lpszLastChar
= '\0';
734 /*************************************************************************
735 * PathRemoveArgsW [SHLWAPI.@]
737 * See PathRemoveArgsA.
739 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
741 TRACE("(%s)\n",debugstr_w(lpszPath
));
745 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
750 LPWSTR lpszLastChar
= CharPrevW(lpszPath
, lpszArgs
);
751 if(*lpszLastChar
== ' ')
752 *lpszLastChar
= '\0';
757 /*************************************************************************
758 * PathRemoveExtensionA [SHLWAPI.@]
760 * Remove the file extension from a path
763 * lpszPath [I/O] Path to remove the extension from
768 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
770 TRACE("(%s)\n", debugstr_a(lpszPath
));
774 lpszPath
= PathFindExtensionA(lpszPath
);
779 /*************************************************************************
780 * PathRemoveExtensionW [SHLWAPI.@]
782 * See PathRemoveExtensionA.
784 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
786 TRACE("(%s)\n", debugstr_w(lpszPath
));
790 lpszPath
= PathFindExtensionW(lpszPath
);
795 /*************************************************************************
796 * PathRemoveBackslashA [SHLWAPI.@]
798 * Remove a trailing backslash from a path.
801 * lpszPath [I/O] Path to remove backslash from
804 * Success: A pointer to the end of the path
805 * Failure: NULL, if lpszPath is NULL
807 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
811 TRACE("(%s)\n", debugstr_a(lpszPath
));
815 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
816 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
822 /*************************************************************************
823 * PathRemoveBackslashW [SHLWAPI.@]
825 * See PathRemoveBackslashA.
827 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
829 LPWSTR szTemp
= NULL
;
831 TRACE("(%s)\n", debugstr_w(lpszPath
));
835 szTemp
= CharPrevW(lpszPath
, lpszPath
+ strlenW(lpszPath
));
836 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
842 /*************************************************************************
843 * PathRemoveBlanksA [SHLWAPI.@]
845 * Remove Spaces from the start and end of a path.
848 * lpszPath [I/O] Path to strip blanks from
853 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
855 TRACE("(%s)\n", debugstr_a(lpszPath
));
857 if(lpszPath
&& *lpszPath
)
859 LPSTR start
= lpszPath
;
861 while (*lpszPath
== ' ')
862 lpszPath
= CharNextA(lpszPath
);
865 *start
++ = *lpszPath
++;
867 if (start
!= lpszPath
)
868 while (start
[-1] == ' ')
874 /*************************************************************************
875 * PathRemoveBlanksW [SHLWAPI.@]
877 * See PathRemoveBlanksA.
879 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
881 TRACE("(%s)\n", debugstr_w(lpszPath
));
883 if(lpszPath
&& *lpszPath
)
885 LPWSTR start
= lpszPath
;
887 while (*lpszPath
== ' ')
891 *start
++ = *lpszPath
++;
893 if (start
!= lpszPath
)
894 while (start
[-1] == ' ')
900 /*************************************************************************
901 * PathQuoteSpacesA [SHLWAPI.@]
903 * Surround a path containg spaces in quotes.
906 * lpszPath [I/O] Path to quote
912 * The path is not changed if it is invalid or has no spaces.
914 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
916 TRACE("(%s)\n", debugstr_a(lpszPath
));
918 if(lpszPath
&& StrChrA(lpszPath
,' '))
920 size_t iLen
= strlen(lpszPath
) + 1;
922 if (iLen
+ 2 < MAX_PATH
)
924 memmove(lpszPath
+ 1, lpszPath
, iLen
);
926 lpszPath
[iLen
] = '"';
927 lpszPath
[iLen
+ 1] = '\0';
932 /*************************************************************************
933 * PathQuoteSpacesW [SHLWAPI.@]
935 * See PathQuoteSpacesA.
937 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
939 TRACE("(%s)\n", debugstr_w(lpszPath
));
941 if(lpszPath
&& StrChrW(lpszPath
,' '))
943 int iLen
= strlenW(lpszPath
) + 1;
945 if (iLen
+ 2 < MAX_PATH
)
947 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
949 lpszPath
[iLen
] = '"';
950 lpszPath
[iLen
+ 1] = '\0';
955 /*************************************************************************
956 * PathUnquoteSpacesA [SHLWAPI.@]
958 * Remove quotes ("") from around a path, if present.
961 * lpszPath [I/O] Path to strip quotes from
967 * If the path contains a single quote only, an empty string will result.
968 * Otherwise quotes are only removed if they appear at the start and end
971 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
973 TRACE("(%s)\n", debugstr_a(lpszPath
));
975 if (lpszPath
&& *lpszPath
== '"')
977 DWORD dwLen
= strlen(lpszPath
) - 1;
979 if (lpszPath
[dwLen
] == '"')
981 lpszPath
[dwLen
] = '\0';
982 for (; *lpszPath
; lpszPath
++)
983 *lpszPath
= lpszPath
[1];
988 /*************************************************************************
989 * PathUnquoteSpacesW [SHLWAPI.@]
991 * See PathUnquoteSpacesA.
993 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
995 TRACE("(%s)\n", debugstr_w(lpszPath
));
997 if (lpszPath
&& *lpszPath
== '"')
999 DWORD dwLen
= strlenW(lpszPath
) - 1;
1001 if (lpszPath
[dwLen
] == '"')
1003 lpszPath
[dwLen
] = '\0';
1004 for (; *lpszPath
; lpszPath
++)
1005 *lpszPath
= lpszPath
[1];
1010 /*************************************************************************
1011 * PathParseIconLocationA [SHLWAPI.@]
1013 * Parse the location of an icon from a path.
1016 * lpszPath [I/O] The path to parse the icon location from.
1019 * Success: The number of the icon
1020 * Failure: 0 if the path does not contain an icon location or is NULL
1023 * The path has surrounding quotes and spaces removed regardless
1024 * of whether the call succeeds or not.
1026 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1031 TRACE("(%s)\n", debugstr_a(lpszPath
));
1035 if ((lpszComma
= strchr(lpszPath
, ',')))
1037 *lpszComma
++ = '\0';
1038 iRet
= StrToIntA(lpszComma
);
1040 PathUnquoteSpacesA(lpszPath
);
1041 PathRemoveBlanksA(lpszPath
);
1046 /*************************************************************************
1047 * PathParseIconLocationW [SHLWAPI.@]
1049 * See PathParseIconLocationA.
1051 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1056 TRACE("(%s)\n", debugstr_w(lpszPath
));
1060 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1062 *lpszComma
++ = '\0';
1063 iRet
= StrToIntW(lpszComma
);
1065 PathUnquoteSpacesW(lpszPath
);
1066 PathRemoveBlanksW(lpszPath
);
1071 /*************************************************************************
1074 * Unicode version of PathFileExistsDefExtA.
1076 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1078 static const WCHAR pszExts
[7][5] = { { '.', 'p', 'i', 'f', 0},
1079 { '.', 'c', 'o', 'm', 0},
1080 { '.', 'e', 'x', 'e', 0},
1081 { '.', 'b', 'a', 't', 0},
1082 { '.', 'l', 'n', 'k', 0},
1083 { '.', 'c', 'm', 'd', 0},
1086 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1088 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1093 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1094 if (!*szExt
|| dwWhich
& 0x40)
1097 int iLen
= lstrlenW(lpszPath
);
1098 if (iLen
> (MAX_PATH
- 5))
1100 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1102 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1103 if (PathFileExistsW(lpszPath
))
1108 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1112 return PathFileExistsW(lpszPath
);
1115 /*************************************************************************
1118 * Determine if a file exists locally and is of an executable type.
1121 * lpszPath [I/O] File to search for
1122 * dwWhich [I] Type of executable to search for
1125 * TRUE If the file was found. lpszPath contains the file name.
1129 * lpszPath is modified in place and must be at least MAX_PATH in length.
1130 * If the function returns FALSE, the path is modified to its original state.
1131 * If the given path contains an extension or dwWhich is 0, executable
1132 * extensions are not checked.
1134 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1135 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1136 * their own developers exclusive use. Monopoly, anyone?
1138 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1142 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1146 WCHAR szPath
[MAX_PATH
];
1147 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1148 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1150 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1155 /*************************************************************************
1156 * SHLWAPI_PathFindInOtherDirs
1158 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1160 static BOOL WINAPI
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1162 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1163 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1167 WCHAR buff
[MAX_PATH
];
1169 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1171 /* Try system directories */
1172 GetSystemDirectoryW(buff
, MAX_PATH
);
1173 if (!PathAppendW(buff
, lpszFile
))
1175 if (PathFileExistsDefExtW(buff
, dwWhich
))
1177 strcpyW(lpszFile
, buff
);
1180 GetWindowsDirectoryW(buff
, MAX_PATH
);
1181 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1183 if (PathFileExistsDefExtW(buff
, dwWhich
))
1185 strcpyW(lpszFile
, buff
);
1188 GetWindowsDirectoryW(buff
, MAX_PATH
);
1189 if (!PathAppendW(buff
, lpszFile
))
1191 if (PathFileExistsDefExtW(buff
, dwWhich
))
1193 strcpyW(lpszFile
, buff
);
1196 /* Try dirs listed in %PATH% */
1197 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1199 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1202 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1203 lpszCurr
= lpszPATH
;
1206 LPCWSTR lpszEnd
= lpszCurr
;
1207 LPWSTR pBuff
= buff
;
1209 while (*lpszEnd
== ' ')
1211 while (*lpszEnd
&& *lpszEnd
!= ';')
1212 *pBuff
++ = *lpszEnd
++;
1216 lpszCurr
= lpszEnd
+ 1;
1218 lpszCurr
= NULL
; /* Last Path, terminate after this */
1220 if (!PathAppendW(buff
, lpszFile
))
1222 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1225 if (PathFileExistsDefExtW(buff
, dwWhich
))
1227 strcpyW(lpszFile
, buff
);
1228 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1232 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1236 /*************************************************************************
1239 * Search a range of paths for a specific type of executable.
1242 * lpszFile [I/O] File to search for
1243 * lppszOtherDirs [I] Other directories to look in
1244 * dwWhich [I] Type of executable to search for
1247 * Success: TRUE. The path to the executable is stored in lpszFile.
1248 * Failure: FALSE. The path to the executable is unchanged.
1250 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1252 WCHAR szFile
[MAX_PATH
];
1253 WCHAR buff
[MAX_PATH
];
1255 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1257 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1260 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1262 /* Search provided directories first */
1263 if (lppszOtherDirs
&& *lppszOtherDirs
)
1265 WCHAR szOther
[MAX_PATH
];
1266 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1268 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1270 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1271 PathCombineW(buff
, szOther
, szFile
);
1272 if (PathFileExistsDefExtW(buff
, dwWhich
))
1274 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1280 /* Not found, try system and path dirs */
1281 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1283 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1289 /*************************************************************************
1292 * Unicode version of PathFindOnPathExA.
1294 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1296 WCHAR buff
[MAX_PATH
];
1298 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1300 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1303 /* Search provided directories first */
1304 if (lppszOtherDirs
&& *lppszOtherDirs
)
1306 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1307 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1309 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1310 if (PathFileExistsDefExtW(buff
, dwWhich
))
1312 strcpyW(lpszFile
, buff
);
1318 /* Not found, try system and path dirs */
1319 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1322 /*************************************************************************
1323 * PathFindOnPathA [SHLWAPI.@]
1325 * Search a range of paths for an executable.
1328 * lpszFile [I/O] File to search for
1329 * lppszOtherDirs [I] Other directories to look in
1332 * Success: TRUE. The path to the executable is stored in lpszFile.
1333 * Failure: FALSE. The path to the executable is unchanged.
1335 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1337 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1338 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1341 /*************************************************************************
1342 * PathFindOnPathW [SHLWAPI.@]
1344 * See PathFindOnPathA.
1346 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1348 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1349 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1352 /*************************************************************************
1353 * PathCompactPathExA [SHLWAPI.@]
1355 * Compact a path into a given number of characters.
1358 * lpszDest [O] Destination for compacted path
1359 * lpszPath [I] Source path
1360 * cchMax [I] Maximum size of compacted path
1361 * dwFlags [I] Reserved
1364 * Success: TRUE. The compacted path is written to lpszDest.
1365 * Failure: FALSE. lpszPath is undefined.
1368 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1370 * The Win32 version of this function contains a bug: When cchMax == 7,
1371 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1374 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1375 * because Win32 will insert a "\" in lpszDest, even if one is
1376 * not present in the original path.
1378 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1379 UINT cchMax
, DWORD dwFlags
)
1383 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1385 if (lpszPath
&& lpszDest
)
1387 WCHAR szPath
[MAX_PATH
];
1388 WCHAR szDest
[MAX_PATH
];
1390 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1392 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1393 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1398 /*************************************************************************
1399 * PathCompactPathExW [SHLWAPI.@]
1401 * See PathCompactPathExA.
1403 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1404 UINT cchMax
, DWORD dwFlags
)
1406 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1408 DWORD dwLen
, dwFileLen
= 0;
1410 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1417 WARN("Invalid lpszDest would crash under Win32!\n");
1426 dwLen
= strlenW(lpszPath
) + 1;
1430 /* Don't need to compact */
1431 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1435 /* Path must be compacted to fit into lpszDest */
1436 lpszFile
= PathFindFileNameW(lpszPath
);
1437 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1439 if (dwFileLen
== dwLen
)
1441 /* No root in psth */
1444 while (--cchMax
> 0) /* No room left for anything but ellipses */
1449 /* Compact the file name with ellipses at the end */
1451 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1452 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1455 /* We have a root in the path */
1456 lpszFile
--; /* Start compacted filename with the path separator */
1459 if (dwFileLen
+ 3 > cchMax
)
1461 /* Compact the file name */
1464 while (--cchMax
> 0) /* No room left for anything but ellipses */
1469 strcpyW(lpszDest
, szEllipses
);
1472 *lpszDest
++ = *lpszFile
++;
1475 while (--cchMax
> 0) /* No room left for anything but ellipses */
1481 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1482 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1486 /* Only the root needs to be Compacted */
1487 dwLen
= cchMax
- dwFileLen
- 3;
1488 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1489 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1490 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1494 /*************************************************************************
1495 * PathIsRelativeA [SHLWAPI.@]
1497 * Determine if a path is a relative path.
1500 * lpszPath [I] Path to check
1503 * TRUE: The path is relative, or is invalid.
1504 * FALSE: The path is not relative.
1506 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1508 TRACE("(%s)\n",debugstr_a(lpszPath
));
1510 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1512 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1517 /*************************************************************************
1518 * PathIsRelativeW [SHLWAPI.@]
1520 * See PathIsRelativeA.
1522 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1524 TRACE("(%s)\n",debugstr_w(lpszPath
));
1526 if (!lpszPath
|| !*lpszPath
)
1528 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1533 /*************************************************************************
1534 * PathIsRootA [SHLWAPI.@]
1536 * Determine if a path is a root path.
1539 * lpszPath [I] Path to check
1542 * TRUE If lpszPath is valid and a root path,
1545 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1547 TRACE("(%s)\n", debugstr_a(lpszPath
));
1549 if (lpszPath
&& *lpszPath
)
1551 if (*lpszPath
== '\\')
1554 return TRUE
; /* \ */
1555 else if (lpszPath
[1]=='\\')
1557 BOOL bSeenSlash
= FALSE
;
1560 /* Check for UNC root path */
1563 if (*lpszPath
== '\\')
1569 lpszPath
= CharNextA(lpszPath
);
1574 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1575 return TRUE
; /* X:\ */
1580 /*************************************************************************
1581 * PathIsRootW [SHLWAPI.@]
1585 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1587 TRACE("(%s)\n", debugstr_w(lpszPath
));
1589 if (lpszPath
&& *lpszPath
)
1591 if (*lpszPath
== '\\')
1594 return TRUE
; /* \ */
1595 else if (lpszPath
[1]=='\\')
1597 BOOL bSeenSlash
= FALSE
;
1600 /* Check for UNC root path */
1603 if (*lpszPath
== '\\')
1609 lpszPath
= CharNextW(lpszPath
);
1614 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1615 return TRUE
; /* X:\ */
1620 /*************************************************************************
1621 * PathIsDirectoryA [SHLWAPI.@]
1623 * Determine if a path is a valid directory
1626 * lpszPath [I] Path to check.
1629 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1630 * FALSE if lpszPath is invalid or not a directory.
1633 * Although this function is prototyped as returning a BOOL, it returns
1634 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1636 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1641 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1645 TRACE("(%s)\n", debugstr_a(lpszPath
));
1647 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1650 if (PathIsUNCServerShareA(lpszPath
))
1652 FIXME("UNC Server Share not yet supported - FAILING\n");
1656 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1658 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1661 /*************************************************************************
1662 * PathIsDirectoryW [SHLWAPI.@]
1664 * See PathIsDirectoryA.
1666 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1670 TRACE("(%s)\n", debugstr_w(lpszPath
));
1672 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1675 if (PathIsUNCServerShareW(lpszPath
))
1677 FIXME("UNC Server Share not yet supported - FAILING\n");
1681 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1683 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1686 /*************************************************************************
1687 * PathFileExistsA [SHLWAPI.@]
1689 * Determine if a file exists.
1692 * lpszPath [I] Path to check
1695 * TRUE If the file exists and is readable
1698 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1703 TRACE("(%s)\n",debugstr_a(lpszPath
));
1708 /* Prevent a dialog box if path is on a disk that has been ejected. */
1709 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1710 dwAttr
= GetFileAttributesA(lpszPath
);
1711 SetErrorMode(iPrevErrMode
);
1712 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1715 /*************************************************************************
1716 * PathFileExistsW [SHLWAPI.@]
1718 * See PathFileExistsA.
1720 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1725 TRACE("(%s)\n",debugstr_w(lpszPath
));
1730 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1731 dwAttr
= GetFileAttributesW(lpszPath
);
1732 SetErrorMode(iPrevErrMode
);
1733 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1736 /*************************************************************************
1737 * PathFileExistsAndAttributesA [SHLWAPI.445]
1739 * Determine if a file exists.
1742 * lpszPath [I] Path to check
1743 * dwAttr [O] attributes of file
1746 * TRUE If the file exists and is readable
1749 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1754 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1757 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1762 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1763 dwVal
= GetFileAttributesA(lpszPath
);
1764 SetErrorMode(iPrevErrMode
);
1767 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1770 /*************************************************************************
1771 * PathFileExistsAndAttributesW [SHLWAPI.446]
1773 * See PathFileExistsA.
1775 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1780 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1785 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1786 dwVal
= GetFileAttributesW(lpszPath
);
1787 SetErrorMode(iPrevErrMode
);
1790 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1793 /*************************************************************************
1794 * PathMatchSingleMaskA [internal]
1796 static BOOL WINAPI
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1798 while (*name
&& *mask
&& *mask
!=';')
1804 if (PathMatchSingleMaskA(name
,mask
+1))
1805 return TRUE
; /* try substrings */
1810 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1813 name
= CharNextA(name
);
1814 mask
= CharNextA(mask
);
1819 while (*mask
== '*')
1821 if (!*mask
|| *mask
== ';')
1827 /*************************************************************************
1828 * PathMatchSingleMaskW [internal]
1830 static BOOL WINAPI
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1832 while (*name
&& *mask
&& *mask
!= ';')
1838 if (PathMatchSingleMaskW(name
,mask
+1))
1839 return TRUE
; /* try substrings */
1844 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1847 name
= CharNextW(name
);
1848 mask
= CharNextW(mask
);
1852 while (*mask
== '*')
1854 if (!*mask
|| *mask
== ';')
1860 /*************************************************************************
1861 * PathMatchSpecA [SHLWAPI.@]
1863 * Determine if a path matches one or more search masks.
1866 * lpszPath [I] Path to check
1867 * lpszMask [I] Search mask(s)
1870 * TRUE If lpszPath is valid and is matched
1874 * Multiple search masks may be given if they are separated by ";". The
1875 * pattern "*.*" is treated specially in that it matches all paths (for
1876 * backwards compatibility with DOS).
1878 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1880 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1882 if (!lstrcmpA(lpszMask
, "*.*"))
1883 return TRUE
; /* Matches every path */
1887 while (*lpszMask
== ' ')
1888 lpszMask
++; /* Eat leading spaces */
1890 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1891 return TRUE
; /* Matches the current mask */
1893 while (*lpszMask
&& *lpszMask
!= ';')
1894 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1896 if (*lpszMask
== ';')
1902 /*************************************************************************
1903 * PathMatchSpecW [SHLWAPI.@]
1905 * See PathMatchSpecA.
1907 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1909 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1911 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1913 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1914 return TRUE
; /* Matches every path */
1918 while (*lpszMask
== ' ')
1919 lpszMask
++; /* Eat leading spaces */
1921 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1922 return TRUE
; /* Matches the current path */
1924 while (*lpszMask
&& *lpszMask
!= ';')
1925 lpszMask
++; /* masks separated by ';' */
1927 if (*lpszMask
== ';')
1933 /*************************************************************************
1934 * PathIsSameRootA [SHLWAPI.@]
1936 * Determine if two paths share the same root.
1939 * lpszPath1 [I] Source path
1940 * lpszPath2 [I] Path to compare with
1943 * TRUE If both paths are valid and share the same root.
1944 * FALSE If either path is invalid or the paths do not share the same root.
1946 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1951 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1953 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1956 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1957 if (lpszStart
- lpszPath1
> dwLen
)
1958 return FALSE
; /* Paths not common up to length of the root */
1962 /*************************************************************************
1963 * PathIsSameRootW [SHLWAPI.@]
1965 * See PathIsSameRootA.
1967 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1972 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1974 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1977 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1978 if (lpszStart
- lpszPath1
> dwLen
)
1979 return FALSE
; /* Paths not common up to length of the root */
1983 /*************************************************************************
1984 * PathIsContentTypeA [SHLWAPI.@]
1986 * Determine if a file is of a given registered content type.
1989 * lpszPath [I] File to check
1990 * lpszContentType [I] Content type to check for
1993 * TRUE If lpszPath is a given registered content type,
1997 * This function looks up the registered content type for lpszPath. If
1998 * a content type is registered, it is compared (case insensitively) to
1999 * lpszContentType. Only if this matches does the function succeed.
2001 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2005 char szBuff
[MAX_PATH
];
2007 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2009 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2010 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2011 REG_NONE
, szBuff
, &dwDummy
) &&
2012 !strcasecmp(lpszContentType
, szBuff
))
2019 /*************************************************************************
2020 * PathIsContentTypeW [SHLWAPI.@]
2022 * See PathIsContentTypeA.
2024 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2026 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2029 WCHAR szBuff
[MAX_PATH
];
2031 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2033 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2034 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2035 REG_NONE
, szBuff
, &dwDummy
) &&
2036 !strcmpiW(lpszContentType
, szBuff
))
2043 /*************************************************************************
2044 * PathIsFileSpecA [SHLWAPI.@]
2046 * Determine if a path is a file specification.
2049 * lpszPath [I] Path to chack
2052 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2055 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2057 TRACE("(%s)\n", debugstr_a(lpszPath
));
2064 if (*lpszPath
== '\\' || *lpszPath
== ':')
2066 lpszPath
= CharNextA(lpszPath
);
2071 /*************************************************************************
2072 * PathIsFileSpecW [SHLWAPI.@]
2074 * See PathIsFileSpecA.
2076 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2078 TRACE("(%s)\n", debugstr_w(lpszPath
));
2085 if (*lpszPath
== '\\' || *lpszPath
== ':')
2087 lpszPath
= CharNextW(lpszPath
);
2092 /*************************************************************************
2093 * PathIsPrefixA [SHLWAPI.@]
2095 * Determine if a path is a prefix of another.
2098 * lpszPrefix [I] Prefix
2099 * lpszPath [I] Path to check
2102 * TRUE If lpszPath has lpszPrefix as its prefix,
2103 * FALSE If either path is NULL or lpszPrefix is not a prefix
2105 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2107 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2109 if (lpszPrefix
&& lpszPath
&&
2110 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2115 /*************************************************************************
2116 * PathIsPrefixW [SHLWAPI.@]
2118 * See PathIsPrefixA.
2120 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2122 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2124 if (lpszPrefix
&& lpszPath
&&
2125 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2130 /*************************************************************************
2131 * PathIsSystemFolderA [SHLWAPI.@]
2133 * Determine if a path or file attributes are a system folder.
2136 * lpszPath [I] Path to check.
2137 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2140 * TRUE If lpszPath or dwAttrib are a system folder.
2141 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2143 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2145 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2147 if (lpszPath
&& *lpszPath
)
2148 dwAttrib
= GetFileAttributesA(lpszPath
);
2150 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2151 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2156 /*************************************************************************
2157 * PathIsSystemFolderW [SHLWAPI.@]
2159 * See PathIsSystemFolderA.
2161 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2163 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2165 if (lpszPath
&& *lpszPath
)
2166 dwAttrib
= GetFileAttributesW(lpszPath
);
2168 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2169 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2174 /*************************************************************************
2175 * PathIsUNCA [SHLWAPI.@]
2177 * Determine if a path is in UNC format.
2180 * lpszPath [I] Path to check
2183 * TRUE: The path is UNC.
2184 * FALSE: The path is not UNC or is NULL.
2186 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2188 TRACE("(%s)\n",debugstr_a(lpszPath
));
2190 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2195 /*************************************************************************
2196 * PathIsUNCW [SHLWAPI.@]
2200 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2202 TRACE("(%s)\n",debugstr_w(lpszPath
));
2204 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2209 /*************************************************************************
2210 * PathIsUNCServerA [SHLWAPI.@]
2212 * Determine if a path is a UNC server name ("\\SHARENAME").
2215 * lpszPath [I] Path to check.
2218 * TRUE If lpszPath is a valid UNC server name.
2222 * This routine is bug compatible with Win32: Server names with a
2223 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2224 * Fixing this bug may break other shlwapi functions!
2226 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2228 TRACE("(%s)\n", debugstr_a(lpszPath
));
2230 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2234 if (*lpszPath
== '\\')
2236 lpszPath
= CharNextA(lpszPath
);
2243 /*************************************************************************
2244 * PathIsUNCServerW [SHLWAPI.@]
2246 * See PathIsUNCServerA.
2248 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2250 TRACE("(%s)\n", debugstr_w(lpszPath
));
2252 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2256 if (*lpszPath
== '\\')
2258 lpszPath
= CharNextW(lpszPath
);
2265 /*************************************************************************
2266 * PathIsUNCServerShareA [SHLWAPI.@]
2268 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2271 * lpszPath [I] Path to check.
2274 * TRUE If lpszPath is a valid UNC server share.
2278 * This routine is bug compatible with Win32: Server shares with a
2279 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2280 * Fixing this bug may break other shlwapi functions!
2282 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2284 TRACE("(%s)\n", debugstr_a(lpszPath
));
2286 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2288 BOOL bSeenSlash
= FALSE
;
2291 if (*lpszPath
== '\\')
2297 lpszPath
= CharNextA(lpszPath
);
2304 /*************************************************************************
2305 * PathIsUNCServerShareW [SHLWAPI.@]
2307 * See PathIsUNCServerShareA.
2309 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2311 TRACE("(%s)\n", debugstr_w(lpszPath
));
2313 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2315 BOOL bSeenSlash
= FALSE
;
2318 if (*lpszPath
== '\\')
2324 lpszPath
= CharNextW(lpszPath
);
2331 /*************************************************************************
2332 * PathCanonicalizeA [SHLWAPI.@]
2334 * Convert a path to its canonical form.
2337 * lpszBuf [O] Output path
2338 * lpszPath [I] Path to cnonicalize
2341 * Success: TRUE. lpszBuf contains the output path,
2342 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2344 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2348 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2353 if (!lpszBuf
|| !lpszPath
)
2354 SetLastError(ERROR_INVALID_PARAMETER
);
2357 WCHAR szPath
[MAX_PATH
];
2358 WCHAR szBuff
[MAX_PATH
];
2359 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2360 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2361 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2367 /*************************************************************************
2368 * PathCanonicalizeW [SHLWAPI.@]
2370 * See PathCanonicalizeA.
2372 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2374 LPWSTR lpszDst
= lpszBuf
;
2375 LPCWSTR lpszSrc
= lpszPath
;
2377 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2382 if (!lpszBuf
|| !lpszPath
)
2384 SetLastError(ERROR_INVALID_PARAMETER
);
2395 /* Copy path root */
2396 if (*lpszSrc
== '\\')
2398 *lpszDst
++ = *lpszSrc
++;
2400 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2403 *lpszDst
++ = *lpszSrc
++;
2404 *lpszDst
++ = *lpszSrc
++;
2405 if (*lpszSrc
== '\\')
2406 *lpszDst
++ = *lpszSrc
++;
2409 /* Canonicalize the rest of the path */
2412 if (*lpszSrc
== '.')
2414 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2416 lpszSrc
+= 2; /* Skip .\ */
2418 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2420 /* \.. backs up a directory, over the root if it has no \ following X:.
2421 * .. is ignored if it would remove a UNC server name or inital \\
2423 if (lpszDst
!= lpszBuf
)
2425 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2426 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2427 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2429 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2432 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2434 if (*lpszDst
== '\\')
2435 lpszDst
++; /* Reset to last '\' */
2437 lpszDst
= lpszBuf
; /* Start path again from new root */
2439 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2442 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2444 if (lpszDst
== lpszBuf
)
2450 lpszSrc
+= 2; /* Skip .. in src path */
2453 *lpszDst
++ = *lpszSrc
++;
2456 *lpszDst
++ = *lpszSrc
++;
2458 /* Append \ to naked drive specs */
2459 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2465 /*************************************************************************
2466 * PathFindNextComponentA [SHLWAPI.@]
2468 * Find the next component in a path.
2471 * lpszPath [I] Path to find next component in
2474 * Success: A pointer to the next component, or the end of the string.
2475 * Failure: NULL, If lpszPath is invalid
2478 * A 'component' is either a backslash character (\) or UNC marker (\\).
2479 * Because of this, relative paths (e.g "c:foo") are regarded as having
2480 * only one component.
2482 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2486 TRACE("(%s)\n", debugstr_a(lpszPath
));
2488 if(!lpszPath
|| !*lpszPath
)
2491 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2493 if (lpszSlash
[1] == '\\')
2495 return lpszSlash
+ 1;
2497 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2500 /*************************************************************************
2501 * PathFindNextComponentW [SHLWAPI.@]
2503 * See PathFindNextComponentA.
2505 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2509 TRACE("(%s)\n", debugstr_w(lpszPath
));
2511 if(!lpszPath
|| !*lpszPath
)
2514 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2516 if (lpszSlash
[1] == '\\')
2518 return lpszSlash
+ 1;
2520 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2523 /*************************************************************************
2524 * PathAddExtensionA [SHLWAPI.@]
2526 * Add a file extension to a path
2529 * lpszPath [I/O] Path to add extension to
2530 * lpszExtension [I] Extension to add to lpszPath
2533 * TRUE If the path was modified,
2534 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2535 * extension already, or the new path length is too big.
2538 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2539 * does not do this, so the behaviour was removed.
2541 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2545 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2547 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2550 dwLen
= strlen(lpszPath
);
2552 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2555 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2559 /*************************************************************************
2560 * PathAddExtensionW [SHLWAPI.@]
2562 * See PathAddExtensionA.
2564 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2568 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2570 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2573 dwLen
= strlenW(lpszPath
);
2575 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2578 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2582 /*************************************************************************
2583 * PathMakePrettyA [SHLWAPI.@]
2585 * Convert an uppercase DOS filename into lowercase.
2588 * lpszPath [I/O] Path to convert.
2591 * TRUE If the path was an uppercase DOS path and was converted,
2594 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2596 LPSTR pszIter
= lpszPath
;
2598 TRACE("(%s)\n", debugstr_a(lpszPath
));
2607 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2608 return FALSE
; /* Not DOS path */
2611 pszIter
= lpszPath
+ 1;
2614 *pszIter
= tolower(*pszIter
);
2621 /*************************************************************************
2622 * PathMakePrettyW [SHLWAPI.@]
2624 * See PathMakePrettyA.
2626 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2628 LPWSTR pszIter
= lpszPath
;
2630 TRACE("(%s)\n", debugstr_w(lpszPath
));
2639 if (islowerW(*pszIter
))
2640 return FALSE
; /* Not DOS path */
2643 pszIter
= lpszPath
+ 1;
2646 *pszIter
= tolowerW(*pszIter
);
2653 /*************************************************************************
2654 * PathCommonPrefixA [SHLWAPI.@]
2656 * Determine the length of the common prefix between two paths.
2659 * lpszFile1 [I] First path for comparison
2660 * lpszFile2 [I] Second path for comparison
2661 * achPath [O] Destination for common prefix string
2664 * The length of the common prefix. This is 0 if there is no common
2665 * prefix between the paths or if any parameters are invalid. If the prefix
2666 * is non-zero and achPath is not NULL, achPath is filled with the common
2667 * part of the prefix and NUL terminated.
2670 * A common prefix of 2 is always returned as 3. It is thus possible for
2671 * the length returned to be invalid (i.e. Longer than one or both of the
2672 * strings given as parameters). This Win32 behaviour has been implemented
2673 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2674 * To work around this when using this function, always check that the byte
2675 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2677 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2680 LPCSTR lpszIter1
= lpszFile1
;
2681 LPCSTR lpszIter2
= lpszFile2
;
2683 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2688 if (!lpszFile1
|| !lpszFile2
)
2691 /* Handle roots first */
2692 if (PathIsUNCA(lpszFile1
))
2694 if (!PathIsUNCA(lpszFile2
))
2699 else if (PathIsUNCA(lpszFile2
))
2700 return 0; /* Know already lpszFile1 is not UNC */
2705 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2706 (!*lpszIter2
|| *lpszIter2
== '\\'))
2707 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2709 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2710 break; /* Strings differ at this point */
2717 iLen
++; /* Feature/Bug compatible with Win32 */
2719 if (iLen
&& achPath
)
2721 memcpy(achPath
,lpszFile1
,iLen
);
2722 achPath
[iLen
] = '\0';
2727 /*************************************************************************
2728 * PathCommonPrefixW [SHLWAPI.@]
2730 * See PathCommonPrefixA.
2732 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2735 LPCWSTR lpszIter1
= lpszFile1
;
2736 LPCWSTR lpszIter2
= lpszFile2
;
2738 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2743 if (!lpszFile1
|| !lpszFile2
)
2746 /* Handle roots first */
2747 if (PathIsUNCW(lpszFile1
))
2749 if (!PathIsUNCW(lpszFile2
))
2754 else if (PathIsUNCW(lpszFile2
))
2755 return 0; /* Know already lpszFile1 is not UNC */
2760 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2761 (!*lpszIter2
|| *lpszIter2
== '\\'))
2762 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2764 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2765 break; /* Strings differ at this point */
2772 iLen
++; /* Feature/Bug compatible with Win32 */
2774 if (iLen
&& achPath
)
2776 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2777 achPath
[iLen
] = '\0';
2782 /*************************************************************************
2783 * PathCompactPathA [SHLWAPI.@]
2785 * Make a path fit into a given width when printed to a DC.
2788 * hDc [I] Destination DC
2789 * lpszPath [I/O] Path to be printed to hDc
2790 * dx [I] Desired width
2793 * TRUE If the path was modified/went well.
2796 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2800 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2804 WCHAR szPath
[MAX_PATH
];
2805 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2806 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2807 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2812 /*************************************************************************
2813 * PathCompactPathW [SHLWAPI.@]
2815 * See PathCompactPathA.
2817 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2819 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2822 WCHAR buff
[MAX_PATH
];
2826 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2832 hdc
= hDC
= GetDC(0);
2834 /* Get the length of the whole path */
2835 dwLen
= strlenW(lpszPath
);
2836 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2838 if ((UINT
)size
.cx
> dx
)
2840 /* Path too big, must reduce it */
2842 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2844 sFile
= PathFindFileNameW(lpszPath
);
2845 if (sFile
!= lpszPath
)
2846 sFile
= CharPrevW(lpszPath
, sFile
);
2848 /* Get the size of ellipses */
2849 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2850 dwEllipsesLen
= size
.cx
;
2851 /* Get the size of the file name */
2852 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2853 dwPathLen
= size
.cx
;
2855 if (sFile
!= lpszPath
)
2857 LPWSTR sPath
= sFile
;
2858 BOOL bEllipses
= FALSE
;
2860 /* The path includes a file name. Include as much of the path prior to
2861 * the file name as possible, allowing for the ellipses, e.g:
2862 * c:\some very long path\filename ==> c:\some v...\filename
2864 lstrcpynW(buff
, sFile
, MAX_PATH
);
2868 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2870 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2871 dwTotalLen
+= size
.cx
;
2872 if (dwTotalLen
<= dx
)
2874 sPath
= CharPrevW(lpszPath
, sPath
);
2878 sPath
= CharPrevW(lpszPath
, sPath
);
2879 sPath
= CharPrevW(lpszPath
, sPath
);
2881 } while (sPath
> lpszPath
);
2883 if (sPath
> lpszPath
)
2887 strcpyW(sPath
, szEllipses
);
2888 strcpyW(sPath
+3, buff
);
2893 strcpyW(lpszPath
, szEllipses
);
2894 strcpyW(lpszPath
+3, buff
);
2899 /* Trim the path by adding ellipses to the end, e.g:
2900 * A very long file name.txt ==> A very...
2902 dwLen
= strlenW(lpszPath
);
2904 if (dwLen
> MAX_PATH
- 3)
2905 dwLen
= MAX_PATH
- 3;
2906 lstrcpynW(buff
, sFile
, dwLen
);
2910 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2911 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2915 DWORD dwWritten
= 0;
2917 dwEllipsesLen
/= 3; /* Size of a single '.' */
2919 /* Write as much of the Ellipses string as possible */
2920 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2923 dwWritten
+= dwEllipsesLen
;
2931 strcpyW(buff
+ dwLen
, szEllipses
);
2932 strcpyW(lpszPath
, buff
);
2943 /*************************************************************************
2944 * PathGetCharTypeA [SHLWAPI.@]
2946 * Categorise a character from a file path.
2949 * ch [I] Character to get the type of
2952 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2954 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2956 return PathGetCharTypeW(ch
);
2959 /*************************************************************************
2960 * PathGetCharTypeW [SHLWAPI.@]
2962 * See PathGetCharTypeA.
2964 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2968 TRACE("(%d)\n", ch
);
2970 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2971 ch
== '"' || ch
== '|' || ch
== '/')
2972 flags
= GCT_INVALID
; /* Invalid */
2973 else if (ch
== '*' || ch
=='?')
2974 flags
= GCT_WILD
; /* Wildchars */
2975 else if ((ch
== '\\') || (ch
== ':'))
2976 return GCT_SEPARATOR
; /* Path separators */
2981 if ((ch
& 0x1 && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2982 ch
== '.' || ch
== '@' || ch
== '^' ||
2983 ch
== '\'' || ch
== 130 || ch
== '`')
2984 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2987 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2988 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2993 /*************************************************************************
2994 * SHLWAPI_UseSystemForSystemFolders
2996 * Internal helper for PathMakeSystemFolderW.
2998 static BOOL WINAPI
SHLWAPI_UseSystemForSystemFolders(void)
3000 static BOOL bCheckedReg
= FALSE
;
3001 static BOOL bUseSystemForSystemFolders
= FALSE
;
3007 /* Key tells Win what file attributes to use on system folders */
3008 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3009 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3010 "UseSystemForSystemFolders", 0, 0, 0))
3011 bUseSystemForSystemFolders
= TRUE
;
3013 return bUseSystemForSystemFolders
;
3016 /*************************************************************************
3017 * PathMakeSystemFolderA [SHLWAPI.@]
3019 * Set system folder attribute for a path.
3022 * lpszPath [I] The path to turn into a system folder
3025 * TRUE If the path was changed to/already was a system folder
3026 * FALSE If the path is invalid or SetFileAttributesA() fails
3028 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3032 TRACE("(%s)\n", debugstr_a(lpszPath
));
3034 if (lpszPath
&& *lpszPath
)
3036 WCHAR szPath
[MAX_PATH
];
3037 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3038 bRet
= PathMakeSystemFolderW(szPath
);
3043 /*************************************************************************
3044 * PathMakeSystemFolderW [SHLWAPI.@]
3046 * See PathMakeSystemFolderA.
3048 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3050 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3051 WCHAR buff
[MAX_PATH
];
3053 TRACE("(%s)\n", debugstr_w(lpszPath
));
3055 if (!lpszPath
|| !*lpszPath
)
3058 /* If the directory is already a system directory, don't do anything */
3059 GetSystemDirectoryW(buff
, MAX_PATH
);
3060 if (!strcmpW(buff
, lpszPath
))
3063 GetWindowsDirectoryW(buff
, MAX_PATH
);
3064 if (!strcmpW(buff
, lpszPath
))
3067 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3068 if (SHLWAPI_UseSystemForSystemFolders())
3069 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3071 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3074 /* Change file attributes to system attributes */
3075 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3076 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3079 /*************************************************************************
3080 * PathRenameExtensionA [SHLWAPI.@]
3082 * Swap the file extension in a path with another extension.
3085 * lpszPath [I/O] Path to swap the extension in
3086 * lpszExt [I] The new extension
3089 * TRUE if lpszPath was modified,
3090 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3092 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3094 LPSTR lpszExtension
;
3096 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3098 lpszExtension
= PathFindExtensionA(lpszPath
);
3100 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3103 strcpy(lpszExtension
, lpszExt
);
3107 /*************************************************************************
3108 * PathRenameExtensionW [SHLWAPI.@]
3110 * See PathRenameExtensionA.
3112 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3114 LPWSTR lpszExtension
;
3116 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3118 lpszExtension
= PathFindExtensionW(lpszPath
);
3120 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3123 strcpyW(lpszExtension
, lpszExt
);
3127 /*************************************************************************
3128 * PathSearchAndQualifyA [SHLWAPI.@]
3130 * Determine if a given path is correct and fully qualified.
3133 * lpszPath [I] Path to check
3134 * lpszBuf [O] Output for correct path
3135 * cchBuf [I] Size of lpszBuf
3140 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3142 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3144 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3146 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3149 /*************************************************************************
3150 * PathSearchAndQualifyW [SHLWAPI.@]
3152 * See PathSearchAndQualifyA.
3154 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3156 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3158 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3160 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3163 /*************************************************************************
3164 * PathSkipRootA [SHLWAPI.@]
3166 * Return the portion of a path following the drive letter or mount point.
3169 * lpszPath [I] The path to skip on
3172 * Success: A pointer to the next character after the root.
3173 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3175 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3177 TRACE("(%s)\n", debugstr_a(lpszPath
));
3179 if (!lpszPath
|| !*lpszPath
)
3182 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3184 /* Network share: skip share server and mount point */
3186 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3187 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3189 return (LPSTR
)lpszPath
;
3192 if (IsDBCSLeadByte(*lpszPath
))
3196 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3197 return (LPSTR
)lpszPath
+ 3;
3201 /*************************************************************************
3202 * PathSkipRootW [SHLWAPI.@]
3204 * See PathSkipRootA.
3206 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3208 TRACE("(%s)\n", debugstr_w(lpszPath
));
3210 if (!lpszPath
|| !*lpszPath
)
3213 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3215 /* Network share: skip share server and mount point */
3217 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3218 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3220 return (LPWSTR
)lpszPath
;
3224 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3225 return (LPWSTR
)lpszPath
+ 3;
3229 /*************************************************************************
3230 * PathCreateFromUrlA [SHLWAPI.@]
3232 * See PathCreateFromUrlW
3234 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3235 LPDWORD pcchPath
, DWORD dwReserved
)
3237 WCHAR bufW
[MAX_PATH
];
3238 WCHAR
*pathW
= bufW
;
3239 UNICODE_STRING urlW
;
3241 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3243 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3244 return E_INVALIDARG
;
3245 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3246 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3247 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3250 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3251 if(*pcchPath
> lenA
) {
3252 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3256 *pcchPath
= lenA
+ 1;
3260 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3261 RtlFreeUnicodeString(&urlW
);
3265 /*************************************************************************
3266 * PathCreateFromUrlW [SHLWAPI.@]
3268 * Create a path from a URL
3271 * lpszUrl [I] URL to convert into a path
3272 * lpszPath [O] Output buffer for the resulting Path
3273 * pcchPath [I] Length of lpszPath
3274 * dwFlags [I] Flags controlling the conversion
3277 * Success: S_OK. lpszPath contains the URL in path format,
3278 * Failure: An HRESULT error code such as E_INVALIDARG.
3280 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3281 LPDWORD pcchPath
, DWORD dwReserved
)
3283 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3288 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3290 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3291 return E_INVALIDARG
;
3294 if (strncmpW(pszUrl
, file_colon
, 5))
3295 return E_INVALIDARG
;
3298 while(*pszUrl
== '/' || *pszUrl
== '\\') {
3303 if(isalphaW(*pszUrl
) && (pszUrl
[1] == ':' || pszUrl
[1] == '|') && (pszUrl
[2] == '/' || pszUrl
[2] == '\\'))
3317 hr
= UrlUnescapeW((LPWSTR
)pszUrl
, pszPath
, pcchPath
, 0);
3318 if(hr
!= S_OK
) return hr
;
3320 for(ptr
= pszPath
; *ptr
; ptr
++)
3321 if(*ptr
== '/') *ptr
= '\\';
3323 while(*pszPath
== '\\')
3326 if(isalphaW(*pszPath
) && pszPath
[1] == '|' && pszPath
[2] == '\\') /* c|\ -> c:\ */
3329 if(nslashes
== 2 && (ptr
= strchrW(pszPath
, '\\'))) { /* \\host\c:\ -> \\hostc:\ */
3331 if(isalphaW(*ptr
) && (ptr
[1] == ':' || ptr
[1] == '|') && ptr
[2] == '\\') {
3332 memmove(ptr
- 1, ptr
, (strlenW(ptr
) + 1) * sizeof(WCHAR
));
3337 TRACE("Returning %s\n",debugstr_w(pszPath
));
3342 /*************************************************************************
3343 * PathRelativePathToA [SHLWAPI.@]
3345 * Create a relative path from one path to another.
3348 * lpszPath [O] Destination for relative path
3349 * lpszFrom [I] Source path
3350 * dwAttrFrom [I] File attribute of source path
3351 * lpszTo [I] Destination path
3352 * dwAttrTo [I] File attributes of destination path
3355 * TRUE If a relative path can be formed. lpszPath contains the new path
3356 * FALSE If the paths are not relavtive or any parameters are invalid
3359 * lpszTo should be at least MAX_PATH in length.
3361 * Calling this function with relative paths for lpszFrom or lpszTo may
3362 * give erroneous results.
3364 * The Win32 version of this function contains a bug where the lpszTo string
3365 * may be referenced 1 byte beyond the end of the string. As a result random
3366 * garbage may be written to the output path, depending on what lies beyond
3367 * the last byte of the string. This bug occurs because of the behaviour of
3368 * PathCommonPrefix() (see notes for that function), and no workaround seems
3369 * possible with Win32.
3371 * This bug has been fixed here, so for example the relative path from "\\"
3372 * to "\\" is correctly determined as "." in this implementation.
3374 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3375 LPCSTR lpszTo
, DWORD dwAttrTo
)
3379 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3380 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3382 if(lpszPath
&& lpszFrom
&& lpszTo
)
3384 WCHAR szPath
[MAX_PATH
];
3385 WCHAR szFrom
[MAX_PATH
];
3386 WCHAR szTo
[MAX_PATH
];
3387 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3388 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3389 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3390 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3395 /*************************************************************************
3396 * PathRelativePathToW [SHLWAPI.@]
3398 * See PathRelativePathToA.
3400 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3401 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3403 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3404 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3405 WCHAR szFrom
[MAX_PATH
];
3406 WCHAR szTo
[MAX_PATH
];
3409 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3410 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3412 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3416 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3417 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3419 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3420 PathRemoveFileSpecW(szFrom
);
3421 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3422 PathRemoveFileSpecW(szTo
);
3424 /* Paths can only be relative if they have a common root */
3425 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3428 /* Strip off lpszFrom components to the root, by adding "..\" */
3429 lpszFrom
= szFrom
+ dwLen
;
3435 if (*lpszFrom
== '\\')
3440 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3441 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3444 /* From the root add the components of lpszTo */
3446 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3449 if (*lpszTo
&& lpszTo
[-1])
3451 if (*lpszTo
!= '\\')
3453 dwLen
= strlenW(lpszPath
);
3454 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3459 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3464 /*************************************************************************
3465 * PathUnmakeSystemFolderA [SHLWAPI.@]
3467 * Remove the system folder attributes from a path.
3470 * lpszPath [I] The path to remove attributes from
3474 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3475 * SetFileAttributesA() fails.
3477 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3481 TRACE("(%s)\n", debugstr_a(lpszPath
));
3483 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3484 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3487 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3488 return SetFileAttributesA(lpszPath
, dwAttr
);
3491 /*************************************************************************
3492 * PathUnmakeSystemFolderW [SHLWAPI.@]
3494 * See PathUnmakeSystemFolderA.
3496 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3500 TRACE("(%s)\n", debugstr_w(lpszPath
));
3502 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3503 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3506 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3507 return SetFileAttributesW(lpszPath
, dwAttr
);
3511 /*************************************************************************
3512 * PathSetDlgItemPathA [SHLWAPI.@]
3514 * Set the text of a dialog item to a path, shrinking the path to fit
3515 * if it is too big for the item.
3518 * hDlg [I] Dialog handle
3519 * id [I] ID of item in the dialog
3520 * lpszPath [I] Path to set as the items text
3526 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3527 * window text is erased).
3529 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3531 WCHAR szPath
[MAX_PATH
];
3533 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3536 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3539 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3542 /*************************************************************************
3543 * PathSetDlgItemPathW [SHLWAPI.@]
3545 * See PathSetDlgItemPathA.
3547 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3549 WCHAR path
[MAX_PATH
+ 1];
3555 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3557 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3561 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3565 GetClientRect(hwItem
, &rect
);
3567 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3571 PathCompactPathW(hdc
, path
, rect
.right
);
3572 SelectObject(hdc
, hPrevObj
);
3575 ReleaseDC(hDlg
, hdc
);
3576 SetWindowTextW(hwItem
, path
);
3579 /*************************************************************************
3580 * PathIsNetworkPathA [SHLWAPI.@]
3582 * Determine if the given path is a network path.
3585 * lpszPath [I] Path to check
3588 * TRUE If lpszPath is a UNC share or mapped network drive, or
3589 * FALSE If lpszPath is a local drive or cannot be determined
3591 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3595 TRACE("(%s)\n",debugstr_a(lpszPath
));
3599 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3601 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3602 if (dwDriveNum
== -1)
3604 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3605 return pIsNetDrive(dwDriveNum
);
3608 /*************************************************************************
3609 * PathIsNetworkPathW [SHLWAPI.@]
3611 * See PathIsNetworkPathA.
3613 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3617 TRACE("(%s)\n", debugstr_w(lpszPath
));
3621 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3623 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3624 if (dwDriveNum
== -1)
3626 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3627 return pIsNetDrive(dwDriveNum
);
3630 /*************************************************************************
3631 * PathIsLFNFileSpecA [SHLWAPI.@]
3633 * Determine if the given path is a long file name
3636 * lpszPath [I] Path to check
3639 * TRUE If path is a long file name,
3640 * FALSE If path is a valid DOS short file name
3642 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3644 DWORD dwNameLen
= 0, dwExtLen
= 0;
3646 TRACE("(%s)\n",debugstr_a(lpszPath
));
3653 if (*lpszPath
== ' ')
3654 return TRUE
; /* DOS names cannot have spaces */
3655 if (*lpszPath
== '.')
3658 return TRUE
; /* DOS names have only one dot */
3665 return TRUE
; /* DOS extensions are <= 3 chars*/
3671 return TRUE
; /* DOS names are <= 8 chars */
3673 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3675 return FALSE
; /* Valid DOS path */
3678 /*************************************************************************
3679 * PathIsLFNFileSpecW [SHLWAPI.@]
3681 * See PathIsLFNFileSpecA.
3683 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3685 DWORD dwNameLen
= 0, dwExtLen
= 0;
3687 TRACE("(%s)\n",debugstr_w(lpszPath
));
3694 if (*lpszPath
== ' ')
3695 return TRUE
; /* DOS names cannot have spaces */
3696 if (*lpszPath
== '.')
3699 return TRUE
; /* DOS names have only one dot */
3706 return TRUE
; /* DOS extensions are <= 3 chars*/
3712 return TRUE
; /* DOS names are <= 8 chars */
3716 return FALSE
; /* Valid DOS path */
3719 /*************************************************************************
3720 * PathIsDirectoryEmptyA [SHLWAPI.@]
3722 * Determine if a given directory is empty.
3725 * lpszPath [I] Directory to check
3728 * TRUE If the directory exists and contains no files,
3731 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3735 TRACE("(%s)\n",debugstr_a(lpszPath
));
3739 WCHAR szPath
[MAX_PATH
];
3740 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3741 bRet
= PathIsDirectoryEmptyW(szPath
);
3746 /*************************************************************************
3747 * PathIsDirectoryEmptyW [SHLWAPI.@]
3749 * See PathIsDirectoryEmptyA.
3751 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3753 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3754 WCHAR szSearch
[MAX_PATH
];
3757 BOOL retVal
= FALSE
;
3758 WIN32_FIND_DATAW find_data
;
3760 TRACE("(%s)\n",debugstr_w(lpszPath
));
3762 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3765 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3766 PathAddBackslashW(szSearch
);
3767 dwLen
= strlenW(szSearch
);
3768 if (dwLen
> MAX_PATH
- 4)
3771 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3772 hfind
= FindFirstFileW(szSearch
, &find_data
);
3774 if (hfind
!= INVALID_HANDLE_VALUE
&&
3775 find_data
.cFileName
[0] == '.' &&
3776 find_data
.cFileName
[1] == '.')
3778 /* The only directory entry should be the parent */
3779 if (!FindNextFileW(hfind
, &find_data
))
3787 /*************************************************************************
3788 * PathFindSuffixArrayA [SHLWAPI.@]
3790 * Find a suffix string in an array of suffix strings
3793 * lpszSuffix [I] Suffix string to search for
3794 * lppszArray [I] Array of suffix strings to search
3795 * dwCount [I] Number of elements in lppszArray
3798 * Success: The index of the position of lpszSuffix in lppszArray
3799 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3802 * The search is case sensitive.
3803 * The match is made against the end of the suffix string, so for example:
3804 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3806 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3811 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3813 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3815 dwLen
= strlen(lpszSuffix
);
3817 while (dwRet
< dwCount
)
3819 size_t dwCompareLen
= strlen(*lppszArray
);
3820 if (dwCompareLen
< dwLen
)
3822 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3823 return *lppszArray
; /* Found */
3832 /*************************************************************************
3833 * PathFindSuffixArrayW [SHLWAPI.@]
3835 * See PathFindSuffixArrayA.
3837 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3842 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3844 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3846 dwLen
= strlenW(lpszSuffix
);
3848 while (dwRet
< dwCount
)
3850 size_t dwCompareLen
= strlenW(*lppszArray
);
3851 if (dwCompareLen
< dwLen
)
3853 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3854 return *lppszArray
; /* Found */
3863 /*************************************************************************
3864 * PathUndecorateA [SHLWAPI.@]
3866 * Undecorate a file path
3869 * lpszPath [I/O] Path to remove any decoration from
3875 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3877 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3879 TRACE("(%s)\n",debugstr_a(lpszPath
));
3883 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3884 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3886 LPSTR lpszSkip
= lpszExt
- 2;
3887 if (*lpszSkip
== '[')
3888 lpszSkip
++; /* [] (no number) */
3890 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3892 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3894 /* remove the [n] */
3897 *lpszSkip
++ = *lpszExt
++;
3904 /*************************************************************************
3905 * PathUndecorateW [SHLWAPI.@]
3907 * See PathUndecorateA.
3909 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3911 TRACE("(%s)\n",debugstr_w(lpszPath
));
3915 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3916 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3918 LPWSTR lpszSkip
= lpszExt
- 2;
3919 if (*lpszSkip
== '[')
3920 lpszSkip
++; /* [] (no number) */
3922 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3924 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3926 /* remove the [n] */
3929 *lpszSkip
++ = *lpszExt
++;
3936 /*************************************************************************
3937 * PathUnExpandEnvStringsA [SHLWAPI.@]
3939 * Substitute folder names in a path with their corresponding environment
3943 * pszPath [I] Buffer containing the path to unexpand.
3944 * pszBuf [O] Buffer to receive the unexpanded path.
3945 * cchBuf [I] Size of pszBuf in characters.
3951 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR pszPath
, LPSTR pszBuf
, UINT cchBuf
)
3953 FIXME("(%s,%s,0x%08x)\n", debugstr_a(pszPath
), debugstr_a(pszBuf
), cchBuf
);
3957 /*************************************************************************
3958 * PathUnExpandEnvStringsW [SHLWAPI.@]
3960 * Unicode version of PathUnExpandEnvStringsA.
3962 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR pszPath
, LPWSTR pszBuf
, UINT cchBuf
)
3964 FIXME("(%s,%s,0x%08x)\n", debugstr_w(pszPath
), debugstr_w(pszBuf
), cchBuf
);
3968 /*************************************************************************
3971 * Find localised or default web content in "%WINDOWS%\web\".
3974 * lpszFile [I] File name containing content to look for
3975 * lpszPath [O] Buffer to contain the full path to the file
3976 * dwPathLen [I] Length of lpszPath
3979 * Success: S_OK. lpszPath contains the full path to the content.
3980 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
3982 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
3984 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
3987 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
3989 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
3991 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
3992 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
3996 /*************************************************************************
3999 * Unicode version of SHGetWebFolderFilePathA.
4001 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4003 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4004 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4005 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4006 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4007 DWORD dwLen
, dwFileLen
;
4008 LANGID lidSystem
, lidUser
;
4010 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4012 /* Get base directory for web content */
4013 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4014 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4017 dwFileLen
= strlenW(lpszFile
);
4019 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4020 return E_FAIL
; /* lpszPath too short */
4022 strcpyW(lpszPath
+dwLen
, szWeb
);
4024 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4026 lidSystem
= GetSystemDefaultUILanguage();
4027 lidUser
= GetUserDefaultUILanguage();
4029 if (lidSystem
!= lidUser
)
4031 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4033 /* Use localised content in the users UI language if present */
4034 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4035 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4036 if (PathFileExistsW(lpszPath
))
4041 /* Fall back to OS default installed content */
4042 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4043 if (PathFileExistsW(lpszPath
))
4048 #define PATH_CHAR_CLASS_LETTER 0x00000001
4049 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4050 #define PATH_CHAR_CLASS_DOT 0x00000004
4051 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4052 #define PATH_CHAR_CLASS_COLON 0x00000010
4053 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4054 #define PATH_CHAR_CLASS_COMMA 0x00000040
4055 #define PATH_CHAR_CLASS_SPACE 0x00000080
4056 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4057 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4059 #define PATH_CHAR_CLASS_INVALID 0x00000000
4060 #define PATH_CHAR_CLASS_ANY 0xffffffff
4062 static const DWORD SHELL_charclass
[] =
4064 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4065 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4066 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4067 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4068 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4069 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4070 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4071 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4072 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4073 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4074 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4075 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4076 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4077 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4078 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4079 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4080 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4081 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4082 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4083 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4084 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4085 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4086 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4087 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4088 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4089 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4090 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4091 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4092 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4093 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4094 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4095 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4096 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4097 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4098 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4099 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4100 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4101 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4102 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4103 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4104 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4105 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4106 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4107 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4108 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4109 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4110 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4111 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4112 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4113 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4114 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4115 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4116 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4117 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4118 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4119 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4120 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4121 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4122 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4123 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4124 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4125 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4126 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4127 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4130 /*************************************************************************
4133 * Check if an ASCII char is of a certain class
4135 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4137 if ((unsigned)c
> 0x7e)
4138 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4140 return class & SHELL_charclass
[(unsigned)c
];
4143 /*************************************************************************
4146 * Check if a Unicode char is of a certain class
4148 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4151 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4153 return class & SHELL_charclass
[c
];