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
)
238 LPSTR prev
= lpszPath
;
240 TRACE("(%s)\n",debugstr_a(lpszPath
));
242 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
248 lpszPath
= CharNextA(prev
);
261 /*************************************************************************
262 * PathAddBackslashW [SHLWAPI.@]
264 * See PathAddBackslashA.
266 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
270 TRACE("(%s)\n",debugstr_w(lpszPath
));
272 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
278 if (lpszPath
[-1] != '\\')
287 /*************************************************************************
288 * PathBuildRootA [SHLWAPI.@]
290 * Create a root drive string (e.g. "A:\") from a drive number.
293 * lpszPath [O] Destination for the drive string
299 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
301 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
303 TRACE("(%p,%d)\n", lpszPath
, drive
);
305 if (lpszPath
&& drive
>= 0 && drive
< 26)
307 lpszPath
[0] = 'A' + drive
;
315 /*************************************************************************
316 * PathBuildRootW [SHLWAPI.@]
318 * See PathBuildRootA.
320 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
322 TRACE("(%p,%d)\n", lpszPath
, drive
);
324 if (lpszPath
&& drive
>= 0 && drive
< 26)
326 lpszPath
[0] = 'A' + drive
;
334 /*************************************************************************
335 * PathFindFileNameA [SHLWAPI.@]
337 * Locate the start of the file name in a path
340 * lpszPath [I] Path to search
343 * A pointer to the first character of the file name
345 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
347 LPCSTR lastSlash
= lpszPath
;
349 TRACE("(%s)\n",debugstr_a(lpszPath
));
351 while (lpszPath
&& *lpszPath
)
353 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
354 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
355 lastSlash
= lpszPath
+ 1;
356 lpszPath
= CharNextA(lpszPath
);
358 return (LPSTR
)lastSlash
;
361 /*************************************************************************
362 * PathFindFileNameW [SHLWAPI.@]
364 * See PathFindFileNameA.
366 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
368 LPCWSTR lastSlash
= lpszPath
;
370 TRACE("(%s)\n",debugstr_w(lpszPath
));
372 while (lpszPath
&& *lpszPath
)
374 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
375 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
376 lastSlash
= lpszPath
+ 1;
379 return (LPWSTR
)lastSlash
;
382 /*************************************************************************
383 * PathFindExtensionA [SHLWAPI.@]
385 * Locate the start of the file extension in a path
388 * lpszPath [I] The path to search
391 * A pointer to the first character of the extension, the end of
392 * the string if the path has no extension, or NULL If lpszPath is NULL
394 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
396 LPCSTR lastpoint
= NULL
;
398 TRACE("(%s)\n", debugstr_a(lpszPath
));
404 if (*lpszPath
== '\\' || *lpszPath
==' ')
406 else if (*lpszPath
== '.')
407 lastpoint
= lpszPath
;
408 lpszPath
= CharNextA(lpszPath
);
411 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
414 /*************************************************************************
415 * PathFindExtensionW [SHLWAPI.@]
417 * See PathFindExtensionA.
419 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
421 LPCWSTR lastpoint
= NULL
;
423 TRACE("(%s)\n", debugstr_w(lpszPath
));
429 if (*lpszPath
== '\\' || *lpszPath
==' ')
431 else if (*lpszPath
== '.')
432 lastpoint
= lpszPath
;
436 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
439 /*************************************************************************
440 * PathGetArgsA [SHLWAPI.@]
442 * Find the next argument in a string delimited by spaces.
445 * lpszPath [I] The string to search for arguments in
448 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
451 * Spaces in quoted strings are ignored as delimiters.
453 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
455 BOOL bSeenQuote
= FALSE
;
457 TRACE("(%s)\n",debugstr_a(lpszPath
));
463 if ((*lpszPath
==' ') && !bSeenQuote
)
464 return (LPSTR
)lpszPath
+ 1;
465 if (*lpszPath
== '"')
466 bSeenQuote
= !bSeenQuote
;
467 lpszPath
= CharNextA(lpszPath
);
470 return (LPSTR
)lpszPath
;
473 /*************************************************************************
474 * PathGetArgsW [SHLWAPI.@]
478 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
480 BOOL bSeenQuote
= FALSE
;
482 TRACE("(%s)\n",debugstr_w(lpszPath
));
488 if ((*lpszPath
==' ') && !bSeenQuote
)
489 return (LPWSTR
)lpszPath
+ 1;
490 if (*lpszPath
== '"')
491 bSeenQuote
= !bSeenQuote
;
495 return (LPWSTR
)lpszPath
;
498 /*************************************************************************
499 * PathGetDriveNumberA [SHLWAPI.@]
501 * Return the drive number from a path
504 * lpszPath [I] Path to get the drive number from
507 * Success: The drive number corresponding to the drive in the path
508 * Failure: -1, if lpszPath contains no valid drive
510 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
512 TRACE ("(%s)\n",debugstr_a(lpszPath
));
514 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
515 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
516 return tolower(*lpszPath
) - 'a';
520 /*************************************************************************
521 * PathGetDriveNumberW [SHLWAPI.@]
523 * See PathGetDriveNumberA.
525 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
527 TRACE ("(%s)\n",debugstr_w(lpszPath
));
531 WCHAR tl
= tolowerW(lpszPath
[0]);
532 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
538 /*************************************************************************
539 * PathRemoveFileSpecA [SHLWAPI.@]
541 * Remove the file specification from a path.
544 * lpszPath [I/O] Path to remove the file spec from
547 * TRUE If the path was valid and modified
550 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
552 LPSTR lpszFileSpec
= lpszPath
;
553 BOOL bModified
= FALSE
;
555 TRACE("(%s)\n",debugstr_a(lpszPath
));
559 /* Skip directory or UNC path */
560 if (*lpszPath
== '\\')
561 lpszFileSpec
= ++lpszPath
;
562 if (*lpszPath
== '\\')
563 lpszFileSpec
= ++lpszPath
;
567 if(*lpszPath
== '\\')
568 lpszFileSpec
= lpszPath
; /* Skip dir */
569 else if(*lpszPath
== ':')
571 lpszFileSpec
= ++lpszPath
; /* Skip drive */
572 if (*lpszPath
== '\\')
575 if (!(lpszPath
= CharNextA(lpszPath
)))
581 *lpszFileSpec
= '\0';
588 /*************************************************************************
589 * PathRemoveFileSpecW [SHLWAPI.@]
591 * See PathRemoveFileSpecA.
593 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
595 LPWSTR lpszFileSpec
= lpszPath
;
596 BOOL bModified
= FALSE
;
598 TRACE("(%s)\n",debugstr_w(lpszPath
));
602 /* Skip directory or UNC path */
603 if (*lpszPath
== '\\')
604 lpszFileSpec
= ++lpszPath
;
605 if (*lpszPath
== '\\')
606 lpszFileSpec
= ++lpszPath
;
610 if(*lpszPath
== '\\')
611 lpszFileSpec
= lpszPath
; /* Skip dir */
612 else if(*lpszPath
== ':')
614 lpszFileSpec
= ++lpszPath
; /* Skip drive */
615 if (*lpszPath
== '\\')
623 *lpszFileSpec
= '\0';
630 /*************************************************************************
631 * PathStripPathA [SHLWAPI.@]
633 * Remove the initial path from the beginning of a filename
636 * lpszPath [I/O] Path to remove the initial path from
641 void WINAPI
PathStripPathA(LPSTR lpszPath
)
643 TRACE("(%s)\n", debugstr_a(lpszPath
));
647 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
649 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
653 /*************************************************************************
654 * PathStripPathW [SHLWAPI.@]
656 * See PathStripPathA.
658 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
662 TRACE("(%s)\n", debugstr_w(lpszPath
));
663 lpszFileName
= PathFindFileNameW(lpszPath
);
665 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
668 /*************************************************************************
669 * PathStripToRootA [SHLWAPI.@]
671 * Reduce a path to its root.
674 * lpszPath [I/O] the path to reduce
677 * Success: TRUE if the stripped path is a root path
678 * Failure: FALSE if the path cannot be stripped or is NULL
680 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
682 TRACE("(%s)\n", debugstr_a(lpszPath
));
686 while(!PathIsRootA(lpszPath
))
687 if (!PathRemoveFileSpecA(lpszPath
))
692 /*************************************************************************
693 * PathStripToRootW [SHLWAPI.@]
695 * See PathStripToRootA.
697 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
699 TRACE("(%s)\n", debugstr_w(lpszPath
));
703 while(!PathIsRootW(lpszPath
))
704 if (!PathRemoveFileSpecW(lpszPath
))
709 /*************************************************************************
710 * PathRemoveArgsA [SHLWAPI.@]
712 * Strip space separated arguments from a path.
715 * lpszPath [I/O] Path to remove arguments from
720 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
722 TRACE("(%s)\n",debugstr_a(lpszPath
));
726 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
731 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
732 if(*lpszLastChar
== ' ')
733 *lpszLastChar
= '\0';
738 /*************************************************************************
739 * PathRemoveArgsW [SHLWAPI.@]
741 * See PathRemoveArgsA.
743 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
745 TRACE("(%s)\n",debugstr_w(lpszPath
));
749 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
750 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
755 /*************************************************************************
756 * PathRemoveExtensionA [SHLWAPI.@]
758 * Remove the file extension from a path
761 * lpszPath [I/O] Path to remove the extension from
764 * The NUL terminator must be written only if extension exists
765 * and if the pointed character is not already NUL.
770 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
772 TRACE("(%s)\n", debugstr_a(lpszPath
));
776 lpszPath
= PathFindExtensionA(lpszPath
);
777 if (lpszPath
&& *lpszPath
!= '\0')
782 /*************************************************************************
783 * PathRemoveExtensionW [SHLWAPI.@]
785 * See PathRemoveExtensionA.
787 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
789 TRACE("(%s)\n", debugstr_w(lpszPath
));
793 lpszPath
= PathFindExtensionW(lpszPath
);
794 if (lpszPath
&& *lpszPath
!= '\0')
799 /*************************************************************************
800 * PathRemoveBackslashA [SHLWAPI.@]
802 * Remove a trailing backslash from a path.
805 * lpszPath [I/O] Path to remove backslash from
808 * Success: A pointer to the end of the path
809 * Failure: NULL, if lpszPath is NULL
811 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
815 TRACE("(%s)\n", debugstr_a(lpszPath
));
819 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
820 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
826 /*************************************************************************
827 * PathRemoveBackslashW [SHLWAPI.@]
829 * See PathRemoveBackslashA.
831 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
833 LPWSTR szTemp
= NULL
;
835 TRACE("(%s)\n", debugstr_w(lpszPath
));
839 szTemp
= lpszPath
+ strlenW(lpszPath
);
840 if (szTemp
> lpszPath
) szTemp
--;
841 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
847 /*************************************************************************
848 * PathRemoveBlanksA [SHLWAPI.@]
850 * Remove Spaces from the start and end of a path.
853 * lpszPath [I/O] Path to strip blanks from
858 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
860 TRACE("(%s)\n", debugstr_a(lpszPath
));
862 if(lpszPath
&& *lpszPath
)
864 LPSTR start
= lpszPath
;
866 while (*lpszPath
== ' ')
867 lpszPath
= CharNextA(lpszPath
);
870 *start
++ = *lpszPath
++;
872 if (start
!= lpszPath
)
873 while (start
[-1] == ' ')
879 /*************************************************************************
880 * PathRemoveBlanksW [SHLWAPI.@]
882 * See PathRemoveBlanksA.
884 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
886 TRACE("(%s)\n", debugstr_w(lpszPath
));
888 if(lpszPath
&& *lpszPath
)
890 LPWSTR start
= lpszPath
;
892 while (*lpszPath
== ' ')
896 *start
++ = *lpszPath
++;
898 if (start
!= lpszPath
)
899 while (start
[-1] == ' ')
905 /*************************************************************************
906 * PathQuoteSpacesA [SHLWAPI.@]
908 * Surround a path containing spaces in quotes.
911 * lpszPath [I/O] Path to quote
917 * The path is not changed if it is invalid or has no spaces.
919 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
921 TRACE("(%s)\n", debugstr_a(lpszPath
));
923 if(lpszPath
&& StrChrA(lpszPath
,' '))
925 size_t iLen
= strlen(lpszPath
) + 1;
927 if (iLen
+ 2 < MAX_PATH
)
929 memmove(lpszPath
+ 1, lpszPath
, iLen
);
931 lpszPath
[iLen
] = '"';
932 lpszPath
[iLen
+ 1] = '\0';
937 /*************************************************************************
938 * PathQuoteSpacesW [SHLWAPI.@]
940 * See PathQuoteSpacesA.
942 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
944 TRACE("(%s)\n", debugstr_w(lpszPath
));
946 if(lpszPath
&& StrChrW(lpszPath
,' '))
948 int iLen
= strlenW(lpszPath
) + 1;
950 if (iLen
+ 2 < MAX_PATH
)
952 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
954 lpszPath
[iLen
] = '"';
955 lpszPath
[iLen
+ 1] = '\0';
960 /*************************************************************************
961 * PathUnquoteSpacesA [SHLWAPI.@]
963 * Remove quotes ("") from around a path, if present.
966 * lpszPath [I/O] Path to strip quotes from
972 * If the path contains a single quote only, an empty string will result.
973 * Otherwise quotes are only removed if they appear at the start and end
976 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
978 TRACE("(%s)\n", debugstr_a(lpszPath
));
980 if (lpszPath
&& *lpszPath
== '"')
982 DWORD dwLen
= strlen(lpszPath
) - 1;
984 if (lpszPath
[dwLen
] == '"')
986 lpszPath
[dwLen
] = '\0';
987 for (; *lpszPath
; lpszPath
++)
988 *lpszPath
= lpszPath
[1];
993 /*************************************************************************
994 * PathUnquoteSpacesW [SHLWAPI.@]
996 * See PathUnquoteSpacesA.
998 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
1000 TRACE("(%s)\n", debugstr_w(lpszPath
));
1002 if (lpszPath
&& *lpszPath
== '"')
1004 DWORD dwLen
= strlenW(lpszPath
) - 1;
1006 if (lpszPath
[dwLen
] == '"')
1008 lpszPath
[dwLen
] = '\0';
1009 for (; *lpszPath
; lpszPath
++)
1010 *lpszPath
= lpszPath
[1];
1015 /*************************************************************************
1016 * PathParseIconLocationA [SHLWAPI.@]
1018 * Parse the location of an icon from a path.
1021 * lpszPath [I/O] The path to parse the icon location from.
1024 * Success: The number of the icon
1025 * Failure: 0 if the path does not contain an icon location or is NULL
1028 * The path has surrounding quotes and spaces removed regardless
1029 * of whether the call succeeds or not.
1031 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1036 TRACE("(%s)\n", debugstr_a(lpszPath
));
1040 if ((lpszComma
= strchr(lpszPath
, ',')))
1042 *lpszComma
++ = '\0';
1043 iRet
= StrToIntA(lpszComma
);
1045 PathUnquoteSpacesA(lpszPath
);
1046 PathRemoveBlanksA(lpszPath
);
1051 /*************************************************************************
1052 * PathParseIconLocationW [SHLWAPI.@]
1054 * See PathParseIconLocationA.
1056 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1061 TRACE("(%s)\n", debugstr_w(lpszPath
));
1065 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1067 *lpszComma
++ = '\0';
1068 iRet
= StrToIntW(lpszComma
);
1070 PathUnquoteSpacesW(lpszPath
);
1071 PathRemoveBlanksW(lpszPath
);
1076 /*************************************************************************
1079 * Unicode version of PathFileExistsDefExtA.
1081 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1083 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1084 { '.', 'c', 'o', 'm', 0},
1085 { '.', 'e', 'x', 'e', 0},
1086 { '.', 'b', 'a', 't', 0},
1087 { '.', 'l', 'n', 'k', 0},
1088 { '.', 'c', 'm', 'd', 0},
1091 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1093 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1098 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1099 if (!*szExt
|| dwWhich
& 0x40)
1102 int iLen
= lstrlenW(lpszPath
);
1103 if (iLen
> (MAX_PATH
- 5))
1105 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1107 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1108 if (PathFileExistsW(lpszPath
))
1113 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1117 return PathFileExistsW(lpszPath
);
1120 /*************************************************************************
1123 * Determine if a file exists locally and is of an executable type.
1126 * lpszPath [I/O] File to search for
1127 * dwWhich [I] Type of executable to search for
1130 * TRUE If the file was found. lpszPath contains the file name.
1134 * lpszPath is modified in place and must be at least MAX_PATH in length.
1135 * If the function returns FALSE, the path is modified to its original state.
1136 * If the given path contains an extension or dwWhich is 0, executable
1137 * extensions are not checked.
1139 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1140 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1141 * their own developers exclusive use. Monopoly, anyone?
1143 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1147 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1151 WCHAR szPath
[MAX_PATH
];
1152 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1153 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1155 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1160 /*************************************************************************
1161 * SHLWAPI_PathFindInOtherDirs
1163 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1165 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1167 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1168 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1172 WCHAR buff
[MAX_PATH
];
1174 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1176 /* Try system directories */
1177 GetSystemDirectoryW(buff
, MAX_PATH
);
1178 if (!PathAppendW(buff
, lpszFile
))
1180 if (PathFileExistsDefExtW(buff
, dwWhich
))
1182 strcpyW(lpszFile
, buff
);
1185 GetWindowsDirectoryW(buff
, MAX_PATH
);
1186 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1188 if (PathFileExistsDefExtW(buff
, dwWhich
))
1190 strcpyW(lpszFile
, buff
);
1193 GetWindowsDirectoryW(buff
, MAX_PATH
);
1194 if (!PathAppendW(buff
, lpszFile
))
1196 if (PathFileExistsDefExtW(buff
, dwWhich
))
1198 strcpyW(lpszFile
, buff
);
1201 /* Try dirs listed in %PATH% */
1202 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1204 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1207 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1208 lpszCurr
= lpszPATH
;
1211 LPCWSTR lpszEnd
= lpszCurr
;
1212 LPWSTR pBuff
= buff
;
1214 while (*lpszEnd
== ' ')
1216 while (*lpszEnd
&& *lpszEnd
!= ';')
1217 *pBuff
++ = *lpszEnd
++;
1221 lpszCurr
= lpszEnd
+ 1;
1223 lpszCurr
= NULL
; /* Last Path, terminate after this */
1225 if (!PathAppendW(buff
, lpszFile
))
1227 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1230 if (PathFileExistsDefExtW(buff
, dwWhich
))
1232 strcpyW(lpszFile
, buff
);
1233 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1237 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1241 /*************************************************************************
1244 * Search a range of paths for a specific type of executable.
1247 * lpszFile [I/O] File to search for
1248 * lppszOtherDirs [I] Other directories to look in
1249 * dwWhich [I] Type of executable to search for
1252 * Success: TRUE. The path to the executable is stored in lpszFile.
1253 * Failure: FALSE. The path to the executable is unchanged.
1255 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1257 WCHAR szFile
[MAX_PATH
];
1258 WCHAR buff
[MAX_PATH
];
1260 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1262 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1265 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1267 /* Search provided directories first */
1268 if (lppszOtherDirs
&& *lppszOtherDirs
)
1270 WCHAR szOther
[MAX_PATH
];
1271 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1273 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1275 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1276 PathCombineW(buff
, szOther
, szFile
);
1277 if (PathFileExistsDefExtW(buff
, dwWhich
))
1279 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1285 /* Not found, try system and path dirs */
1286 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1288 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1294 /*************************************************************************
1297 * Unicode version of PathFindOnPathExA.
1299 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1301 WCHAR buff
[MAX_PATH
];
1303 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1305 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1308 /* Search provided directories first */
1309 if (lppszOtherDirs
&& *lppszOtherDirs
)
1311 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1312 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1314 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1315 if (PathFileExistsDefExtW(buff
, dwWhich
))
1317 strcpyW(lpszFile
, buff
);
1323 /* Not found, try system and path dirs */
1324 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1327 /*************************************************************************
1328 * PathFindOnPathA [SHLWAPI.@]
1330 * Search a range of paths for an executable.
1333 * lpszFile [I/O] File to search for
1334 * lppszOtherDirs [I] Other directories to look in
1337 * Success: TRUE. The path to the executable is stored in lpszFile.
1338 * Failure: FALSE. The path to the executable is unchanged.
1340 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1342 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1343 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1346 /*************************************************************************
1347 * PathFindOnPathW [SHLWAPI.@]
1349 * See PathFindOnPathA.
1351 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1353 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1354 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1357 /*************************************************************************
1358 * PathCompactPathExA [SHLWAPI.@]
1360 * Compact a path into a given number of characters.
1363 * lpszDest [O] Destination for compacted path
1364 * lpszPath [I] Source path
1365 * cchMax [I] Maximum size of compacted path
1366 * dwFlags [I] Reserved
1369 * Success: TRUE. The compacted path is written to lpszDest.
1370 * Failure: FALSE. lpszPath is undefined.
1373 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1375 * The Win32 version of this function contains a bug: When cchMax == 7,
1376 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1379 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1380 * because Win32 will insert a "\" in lpszDest, even if one is
1381 * not present in the original path.
1383 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1384 UINT cchMax
, DWORD dwFlags
)
1388 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1390 if (lpszPath
&& lpszDest
)
1392 WCHAR szPath
[MAX_PATH
];
1393 WCHAR szDest
[MAX_PATH
];
1395 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1397 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1398 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1403 /*************************************************************************
1404 * PathCompactPathExW [SHLWAPI.@]
1406 * See PathCompactPathExA.
1408 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1409 UINT cchMax
, DWORD dwFlags
)
1411 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1413 DWORD dwLen
, dwFileLen
= 0;
1415 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1422 WARN("Invalid lpszDest would crash under Win32!\n");
1431 dwLen
= strlenW(lpszPath
) + 1;
1435 /* Don't need to compact */
1436 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1440 /* Path must be compacted to fit into lpszDest */
1441 lpszFile
= PathFindFileNameW(lpszPath
);
1442 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1444 if (dwFileLen
== dwLen
)
1446 /* No root in psth */
1449 while (--cchMax
> 0) /* No room left for anything but ellipses */
1454 /* Compact the file name with ellipses at the end */
1456 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1457 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1460 /* We have a root in the path */
1461 lpszFile
--; /* Start compacted filename with the path separator */
1464 if (dwFileLen
+ 3 > cchMax
)
1466 /* Compact the file name */
1469 while (--cchMax
> 0) /* No room left for anything but ellipses */
1474 strcpyW(lpszDest
, szEllipses
);
1477 *lpszDest
++ = *lpszFile
++;
1480 while (--cchMax
> 0) /* No room left for anything but ellipses */
1486 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1487 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1491 /* Only the root needs to be Compacted */
1492 dwLen
= cchMax
- dwFileLen
- 3;
1493 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1494 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1495 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1499 /*************************************************************************
1500 * PathIsRelativeA [SHLWAPI.@]
1502 * Determine if a path is a relative path.
1505 * lpszPath [I] Path to check
1508 * TRUE: The path is relative, or is invalid.
1509 * FALSE: The path is not relative.
1511 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1513 TRACE("(%s)\n",debugstr_a(lpszPath
));
1515 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1517 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1522 /*************************************************************************
1523 * PathIsRelativeW [SHLWAPI.@]
1525 * See PathIsRelativeA.
1527 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1529 TRACE("(%s)\n",debugstr_w(lpszPath
));
1531 if (!lpszPath
|| !*lpszPath
)
1533 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1538 /*************************************************************************
1539 * PathIsRootA [SHLWAPI.@]
1541 * Determine if a path is a root path.
1544 * lpszPath [I] Path to check
1547 * TRUE If lpszPath is valid and a root path,
1550 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1552 TRACE("(%s)\n", debugstr_a(lpszPath
));
1554 if (lpszPath
&& *lpszPath
)
1556 if (*lpszPath
== '\\')
1559 return TRUE
; /* \ */
1560 else if (lpszPath
[1]=='\\')
1562 BOOL bSeenSlash
= FALSE
;
1565 /* Check for UNC root path */
1568 if (*lpszPath
== '\\')
1574 lpszPath
= CharNextA(lpszPath
);
1579 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1580 return TRUE
; /* X:\ */
1585 /*************************************************************************
1586 * PathIsRootW [SHLWAPI.@]
1590 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1592 TRACE("(%s)\n", debugstr_w(lpszPath
));
1594 if (lpszPath
&& *lpszPath
)
1596 if (*lpszPath
== '\\')
1599 return TRUE
; /* \ */
1600 else if (lpszPath
[1]=='\\')
1602 BOOL bSeenSlash
= FALSE
;
1605 /* Check for UNC root path */
1608 if (*lpszPath
== '\\')
1619 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1620 return TRUE
; /* X:\ */
1625 /*************************************************************************
1626 * PathIsDirectoryA [SHLWAPI.@]
1628 * Determine if a path is a valid directory
1631 * lpszPath [I] Path to check.
1634 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1635 * FALSE if lpszPath is invalid or not a directory.
1638 * Although this function is prototyped as returning a BOOL, it returns
1639 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1641 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1646 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1650 TRACE("(%s)\n", debugstr_a(lpszPath
));
1652 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1655 if (PathIsUNCServerShareA(lpszPath
))
1657 FIXME("UNC Server Share not yet supported - FAILING\n");
1661 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1663 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1666 /*************************************************************************
1667 * PathIsDirectoryW [SHLWAPI.@]
1669 * See PathIsDirectoryA.
1671 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1675 TRACE("(%s)\n", debugstr_w(lpszPath
));
1677 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1680 if (PathIsUNCServerShareW(lpszPath
))
1682 FIXME("UNC Server Share not yet supported - FAILING\n");
1686 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1688 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1691 /*************************************************************************
1692 * PathFileExistsA [SHLWAPI.@]
1694 * Determine if a file exists.
1697 * lpszPath [I] Path to check
1700 * TRUE If the file exists and is readable
1703 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1708 TRACE("(%s)\n",debugstr_a(lpszPath
));
1713 /* Prevent a dialog box if path is on a disk that has been ejected. */
1714 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1715 dwAttr
= GetFileAttributesA(lpszPath
);
1716 SetErrorMode(iPrevErrMode
);
1717 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1720 /*************************************************************************
1721 * PathFileExistsW [SHLWAPI.@]
1723 * See PathFileExistsA.
1725 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1730 TRACE("(%s)\n",debugstr_w(lpszPath
));
1735 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1736 dwAttr
= GetFileAttributesW(lpszPath
);
1737 SetErrorMode(iPrevErrMode
);
1738 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1741 /*************************************************************************
1742 * PathFileExistsAndAttributesA [SHLWAPI.445]
1744 * Determine if a file exists.
1747 * lpszPath [I] Path to check
1748 * dwAttr [O] attributes of file
1751 * TRUE If the file exists and is readable
1754 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1759 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1762 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1767 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1768 dwVal
= GetFileAttributesA(lpszPath
);
1769 SetErrorMode(iPrevErrMode
);
1772 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1775 /*************************************************************************
1776 * PathFileExistsAndAttributesW [SHLWAPI.446]
1778 * See PathFileExistsA.
1780 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1785 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1790 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1791 dwVal
= GetFileAttributesW(lpszPath
);
1792 SetErrorMode(iPrevErrMode
);
1795 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1798 /*************************************************************************
1799 * PathMatchSingleMaskA [internal]
1801 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1803 while (*name
&& *mask
&& *mask
!=';')
1809 if (PathMatchSingleMaskA(name
,mask
+1))
1810 return TRUE
; /* try substrings */
1815 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1818 name
= CharNextA(name
);
1819 mask
= CharNextA(mask
);
1824 while (*mask
== '*')
1826 if (!*mask
|| *mask
== ';')
1832 /*************************************************************************
1833 * PathMatchSingleMaskW [internal]
1835 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1837 while (*name
&& *mask
&& *mask
!= ';')
1843 if (PathMatchSingleMaskW(name
,mask
+1))
1844 return TRUE
; /* try substrings */
1849 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1857 while (*mask
== '*')
1859 if (!*mask
|| *mask
== ';')
1865 /*************************************************************************
1866 * PathMatchSpecA [SHLWAPI.@]
1868 * Determine if a path matches one or more search masks.
1871 * lpszPath [I] Path to check
1872 * lpszMask [I] Search mask(s)
1875 * TRUE If lpszPath is valid and is matched
1879 * Multiple search masks may be given if they are separated by ";". The
1880 * pattern "*.*" is treated specially in that it matches all paths (for
1881 * backwards compatibility with DOS).
1883 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1885 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1887 if (!lstrcmpA(lpszMask
, "*.*"))
1888 return TRUE
; /* Matches every path */
1892 while (*lpszMask
== ' ')
1893 lpszMask
++; /* Eat leading spaces */
1895 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1896 return TRUE
; /* Matches the current mask */
1898 while (*lpszMask
&& *lpszMask
!= ';')
1899 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1901 if (*lpszMask
== ';')
1907 /*************************************************************************
1908 * PathMatchSpecW [SHLWAPI.@]
1910 * See PathMatchSpecA.
1912 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1914 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1916 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1918 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1919 return TRUE
; /* Matches every path */
1923 while (*lpszMask
== ' ')
1924 lpszMask
++; /* Eat leading spaces */
1926 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1927 return TRUE
; /* Matches the current path */
1929 while (*lpszMask
&& *lpszMask
!= ';')
1930 lpszMask
++; /* masks separated by ';' */
1932 if (*lpszMask
== ';')
1938 /*************************************************************************
1939 * PathIsSameRootA [SHLWAPI.@]
1941 * Determine if two paths share the same root.
1944 * lpszPath1 [I] Source path
1945 * lpszPath2 [I] Path to compare with
1948 * TRUE If both paths are valid and share the same root.
1949 * FALSE If either path is invalid or the paths do not share the same root.
1951 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1956 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1958 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1961 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1962 if (lpszStart
- lpszPath1
> dwLen
)
1963 return FALSE
; /* Paths not common up to length of the root */
1967 /*************************************************************************
1968 * PathIsSameRootW [SHLWAPI.@]
1970 * See PathIsSameRootA.
1972 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1977 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1979 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1982 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1983 if (lpszStart
- lpszPath1
> dwLen
)
1984 return FALSE
; /* Paths not common up to length of the root */
1988 /*************************************************************************
1989 * PathIsContentTypeA [SHLWAPI.@]
1991 * Determine if a file is of a given registered content type.
1994 * lpszPath [I] File to check
1995 * lpszContentType [I] Content type to check for
1998 * TRUE If lpszPath is a given registered content type,
2002 * This function looks up the registered content type for lpszPath. If
2003 * a content type is registered, it is compared (case insensitively) to
2004 * lpszContentType. Only if this matches does the function succeed.
2006 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2010 char szBuff
[MAX_PATH
];
2012 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2014 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2015 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2016 REG_NONE
, szBuff
, &dwDummy
) &&
2017 !strcasecmp(lpszContentType
, szBuff
))
2024 /*************************************************************************
2025 * PathIsContentTypeW [SHLWAPI.@]
2027 * See PathIsContentTypeA.
2029 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2031 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2034 WCHAR szBuff
[MAX_PATH
];
2036 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2038 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2039 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2040 REG_NONE
, szBuff
, &dwDummy
) &&
2041 !strcmpiW(lpszContentType
, szBuff
))
2048 /*************************************************************************
2049 * PathIsFileSpecA [SHLWAPI.@]
2051 * Determine if a path is a file specification.
2054 * lpszPath [I] Path to check
2057 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2060 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2062 TRACE("(%s)\n", debugstr_a(lpszPath
));
2069 if (*lpszPath
== '\\' || *lpszPath
== ':')
2071 lpszPath
= CharNextA(lpszPath
);
2076 /*************************************************************************
2077 * PathIsFileSpecW [SHLWAPI.@]
2079 * See PathIsFileSpecA.
2081 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2083 TRACE("(%s)\n", debugstr_w(lpszPath
));
2090 if (*lpszPath
== '\\' || *lpszPath
== ':')
2097 /*************************************************************************
2098 * PathIsPrefixA [SHLWAPI.@]
2100 * Determine if a path is a prefix of another.
2103 * lpszPrefix [I] Prefix
2104 * lpszPath [I] Path to check
2107 * TRUE If lpszPath has lpszPrefix as its prefix,
2108 * FALSE If either path is NULL or lpszPrefix is not a prefix
2110 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2112 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2114 if (lpszPrefix
&& lpszPath
&&
2115 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2120 /*************************************************************************
2121 * PathIsPrefixW [SHLWAPI.@]
2123 * See PathIsPrefixA.
2125 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2127 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2129 if (lpszPrefix
&& lpszPath
&&
2130 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2135 /*************************************************************************
2136 * PathIsSystemFolderA [SHLWAPI.@]
2138 * Determine if a path or file attributes are a system folder.
2141 * lpszPath [I] Path to check.
2142 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2145 * TRUE If lpszPath or dwAttrib are a system folder.
2146 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2148 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2150 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2152 if (lpszPath
&& *lpszPath
)
2153 dwAttrib
= GetFileAttributesA(lpszPath
);
2155 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2156 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2161 /*************************************************************************
2162 * PathIsSystemFolderW [SHLWAPI.@]
2164 * See PathIsSystemFolderA.
2166 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2168 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2170 if (lpszPath
&& *lpszPath
)
2171 dwAttrib
= GetFileAttributesW(lpszPath
);
2173 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2174 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2179 /*************************************************************************
2180 * PathIsUNCA [SHLWAPI.@]
2182 * Determine if a path is in UNC format.
2185 * lpszPath [I] Path to check
2188 * TRUE: The path is UNC.
2189 * FALSE: The path is not UNC or is NULL.
2191 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2193 TRACE("(%s)\n",debugstr_a(lpszPath
));
2195 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2200 /*************************************************************************
2201 * PathIsUNCW [SHLWAPI.@]
2205 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2207 TRACE("(%s)\n",debugstr_w(lpszPath
));
2209 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2214 /*************************************************************************
2215 * PathIsUNCServerA [SHLWAPI.@]
2217 * Determine if a path is a UNC server name ("\\SHARENAME").
2220 * lpszPath [I] Path to check.
2223 * TRUE If lpszPath is a valid UNC server name.
2227 * This routine is bug compatible with Win32: Server names with a
2228 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2229 * Fixing this bug may break other shlwapi functions!
2231 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2233 TRACE("(%s)\n", debugstr_a(lpszPath
));
2235 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2239 if (*lpszPath
== '\\')
2241 lpszPath
= CharNextA(lpszPath
);
2248 /*************************************************************************
2249 * PathIsUNCServerW [SHLWAPI.@]
2251 * See PathIsUNCServerA.
2253 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2255 TRACE("(%s)\n", debugstr_w(lpszPath
));
2257 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2259 return !strchrW( lpszPath
+ 2, '\\' );
2264 /*************************************************************************
2265 * PathIsUNCServerShareA [SHLWAPI.@]
2267 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2270 * lpszPath [I] Path to check.
2273 * TRUE If lpszPath is a valid UNC server share.
2277 * This routine is bug compatible with Win32: Server shares with a
2278 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2279 * Fixing this bug may break other shlwapi functions!
2281 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2283 TRACE("(%s)\n", debugstr_a(lpszPath
));
2285 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2287 BOOL bSeenSlash
= FALSE
;
2290 if (*lpszPath
== '\\')
2296 lpszPath
= CharNextA(lpszPath
);
2303 /*************************************************************************
2304 * PathIsUNCServerShareW [SHLWAPI.@]
2306 * See PathIsUNCServerShareA.
2308 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2310 TRACE("(%s)\n", debugstr_w(lpszPath
));
2312 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2314 BOOL bSeenSlash
= FALSE
;
2317 if (*lpszPath
== '\\')
2330 /*************************************************************************
2331 * PathCanonicalizeA [SHLWAPI.@]
2333 * Convert a path to its canonical form.
2336 * lpszBuf [O] Output path
2337 * lpszPath [I] Path to canonicalize
2340 * Success: TRUE. lpszBuf contains the output path,
2341 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2343 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2347 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2352 if (!lpszBuf
|| !lpszPath
)
2353 SetLastError(ERROR_INVALID_PARAMETER
);
2356 WCHAR szPath
[MAX_PATH
];
2357 WCHAR szBuff
[MAX_PATH
];
2358 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2361 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2364 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2365 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2371 /*************************************************************************
2372 * PathCanonicalizeW [SHLWAPI.@]
2374 * See PathCanonicalizeA.
2376 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2378 LPWSTR lpszDst
= lpszBuf
;
2379 LPCWSTR lpszSrc
= lpszPath
;
2381 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2386 if (!lpszBuf
|| !lpszPath
)
2388 SetLastError(ERROR_INVALID_PARAMETER
);
2399 /* Copy path root */
2400 if (*lpszSrc
== '\\')
2402 *lpszDst
++ = *lpszSrc
++;
2404 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2407 *lpszDst
++ = *lpszSrc
++;
2408 *lpszDst
++ = *lpszSrc
++;
2409 if (*lpszSrc
== '\\')
2410 *lpszDst
++ = *lpszSrc
++;
2413 /* Canonicalize the rest of the path */
2416 if (*lpszSrc
== '.')
2418 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2420 lpszSrc
+= 2; /* Skip .\ */
2422 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2424 /* \.. backs up a directory, over the root if it has no \ following X:.
2425 * .. is ignored if it would remove a UNC server name or initial \\
2427 if (lpszDst
!= lpszBuf
)
2429 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2430 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2431 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2433 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2436 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2438 if (*lpszDst
== '\\')
2439 lpszDst
++; /* Reset to last '\' */
2441 lpszDst
= lpszBuf
; /* Start path again from new root */
2443 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2446 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2448 if (lpszDst
== lpszBuf
)
2454 lpszSrc
+= 2; /* Skip .. in src path */
2457 *lpszDst
++ = *lpszSrc
++;
2460 *lpszDst
++ = *lpszSrc
++;
2462 /* Append \ to naked drive specs */
2463 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2469 /*************************************************************************
2470 * PathFindNextComponentA [SHLWAPI.@]
2472 * Find the next component in a path.
2475 * lpszPath [I] Path to find next component in
2478 * Success: A pointer to the next component, or the end of the string.
2479 * Failure: NULL, If lpszPath is invalid
2482 * A 'component' is either a backslash character (\) or UNC marker (\\).
2483 * Because of this, relative paths (e.g "c:foo") are regarded as having
2484 * only one component.
2486 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2490 TRACE("(%s)\n", debugstr_a(lpszPath
));
2492 if(!lpszPath
|| !*lpszPath
)
2495 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2497 if (lpszSlash
[1] == '\\')
2499 return lpszSlash
+ 1;
2501 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2504 /*************************************************************************
2505 * PathFindNextComponentW [SHLWAPI.@]
2507 * See PathFindNextComponentA.
2509 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2513 TRACE("(%s)\n", debugstr_w(lpszPath
));
2515 if(!lpszPath
|| !*lpszPath
)
2518 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2520 if (lpszSlash
[1] == '\\')
2522 return lpszSlash
+ 1;
2524 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2527 /*************************************************************************
2528 * PathAddExtensionA [SHLWAPI.@]
2530 * Add a file extension to a path
2533 * lpszPath [I/O] Path to add extension to
2534 * lpszExtension [I] Extension to add to lpszPath
2537 * TRUE If the path was modified,
2538 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2539 * extension already, or the new path length is too big.
2542 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2543 * does not do this, so the behaviour was removed.
2545 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2549 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2551 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2554 dwLen
= strlen(lpszPath
);
2556 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2559 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2563 /*************************************************************************
2564 * PathAddExtensionW [SHLWAPI.@]
2566 * See PathAddExtensionA.
2568 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2572 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2574 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2577 dwLen
= strlenW(lpszPath
);
2579 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2582 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2586 /*************************************************************************
2587 * PathMakePrettyA [SHLWAPI.@]
2589 * Convert an uppercase DOS filename into lowercase.
2592 * lpszPath [I/O] Path to convert.
2595 * TRUE If the path was an uppercase DOS path and was converted,
2598 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2600 LPSTR pszIter
= lpszPath
;
2602 TRACE("(%s)\n", debugstr_a(lpszPath
));
2611 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2612 return FALSE
; /* Not DOS path */
2615 pszIter
= lpszPath
+ 1;
2618 *pszIter
= tolower(*pszIter
);
2625 /*************************************************************************
2626 * PathMakePrettyW [SHLWAPI.@]
2628 * See PathMakePrettyA.
2630 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2632 LPWSTR pszIter
= lpszPath
;
2634 TRACE("(%s)\n", debugstr_w(lpszPath
));
2643 if (islowerW(*pszIter
))
2644 return FALSE
; /* Not DOS path */
2647 pszIter
= lpszPath
+ 1;
2650 *pszIter
= tolowerW(*pszIter
);
2657 /*************************************************************************
2658 * PathCommonPrefixA [SHLWAPI.@]
2660 * Determine the length of the common prefix between two paths.
2663 * lpszFile1 [I] First path for comparison
2664 * lpszFile2 [I] Second path for comparison
2665 * achPath [O] Destination for common prefix string
2668 * The length of the common prefix. This is 0 if there is no common
2669 * prefix between the paths or if any parameters are invalid. If the prefix
2670 * is non-zero and achPath is not NULL, achPath is filled with the common
2671 * part of the prefix and NUL terminated.
2674 * A common prefix of 2 is always returned as 3. It is thus possible for
2675 * the length returned to be invalid (i.e. Longer than one or both of the
2676 * strings given as parameters). This Win32 behaviour has been implemented
2677 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2678 * To work around this when using this function, always check that the byte
2679 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2681 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2684 LPCSTR lpszIter1
= lpszFile1
;
2685 LPCSTR lpszIter2
= lpszFile2
;
2687 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2692 if (!lpszFile1
|| !lpszFile2
)
2695 /* Handle roots first */
2696 if (PathIsUNCA(lpszFile1
))
2698 if (!PathIsUNCA(lpszFile2
))
2703 else if (PathIsUNCA(lpszFile2
))
2704 return 0; /* Know already lpszFile1 is not UNC */
2709 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2710 (!*lpszIter2
|| *lpszIter2
== '\\'))
2711 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2713 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2714 break; /* Strings differ at this point */
2721 iLen
++; /* Feature/Bug compatible with Win32 */
2723 if (iLen
&& achPath
)
2725 memcpy(achPath
,lpszFile1
,iLen
);
2726 achPath
[iLen
] = '\0';
2731 /*************************************************************************
2732 * PathCommonPrefixW [SHLWAPI.@]
2734 * See PathCommonPrefixA.
2736 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2739 LPCWSTR lpszIter1
= lpszFile1
;
2740 LPCWSTR lpszIter2
= lpszFile2
;
2742 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2747 if (!lpszFile1
|| !lpszFile2
)
2750 /* Handle roots first */
2751 if (PathIsUNCW(lpszFile1
))
2753 if (!PathIsUNCW(lpszFile2
))
2758 else if (PathIsUNCW(lpszFile2
))
2759 return 0; /* Know already lpszFile1 is not UNC */
2764 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2765 (!*lpszIter2
|| *lpszIter2
== '\\'))
2766 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2768 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2769 break; /* Strings differ at this point */
2776 iLen
++; /* Feature/Bug compatible with Win32 */
2778 if (iLen
&& achPath
)
2780 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2781 achPath
[iLen
] = '\0';
2786 /*************************************************************************
2787 * PathCompactPathA [SHLWAPI.@]
2789 * Make a path fit into a given width when printed to a DC.
2792 * hDc [I] Destination DC
2793 * lpszPath [I/O] Path to be printed to hDc
2794 * dx [I] Desired width
2797 * TRUE If the path was modified/went well.
2800 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2804 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2808 WCHAR szPath
[MAX_PATH
];
2809 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2810 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2811 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2816 /*************************************************************************
2817 * PathCompactPathW [SHLWAPI.@]
2819 * See PathCompactPathA.
2821 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2823 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2826 WCHAR buff
[MAX_PATH
];
2830 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2836 hdc
= hDC
= GetDC(0);
2838 /* Get the length of the whole path */
2839 dwLen
= strlenW(lpszPath
);
2840 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2842 if ((UINT
)size
.cx
> dx
)
2844 /* Path too big, must reduce it */
2846 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2848 sFile
= PathFindFileNameW(lpszPath
);
2849 if (sFile
!= lpszPath
) sFile
--;
2851 /* Get the size of ellipses */
2852 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2853 dwEllipsesLen
= size
.cx
;
2854 /* Get the size of the file name */
2855 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2856 dwPathLen
= size
.cx
;
2858 if (sFile
!= lpszPath
)
2860 LPWSTR sPath
= sFile
;
2861 BOOL bEllipses
= FALSE
;
2863 /* The path includes a file name. Include as much of the path prior to
2864 * the file name as possible, allowing for the ellipses, e.g:
2865 * c:\some very long path\filename ==> c:\some v...\filename
2867 lstrcpynW(buff
, sFile
, MAX_PATH
);
2871 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2873 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2874 dwTotalLen
+= size
.cx
;
2875 if (dwTotalLen
<= dx
)
2883 } while (sPath
> lpszPath
);
2885 if (sPath
> lpszPath
)
2889 strcpyW(sPath
, szEllipses
);
2890 strcpyW(sPath
+3, buff
);
2895 strcpyW(lpszPath
, szEllipses
);
2896 strcpyW(lpszPath
+3, buff
);
2901 /* Trim the path by adding ellipses to the end, e.g:
2902 * A very long file name.txt ==> A very...
2904 dwLen
= strlenW(lpszPath
);
2906 if (dwLen
> MAX_PATH
- 3)
2907 dwLen
= MAX_PATH
- 3;
2908 lstrcpynW(buff
, sFile
, dwLen
);
2912 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2913 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2917 DWORD dwWritten
= 0;
2919 dwEllipsesLen
/= 3; /* Size of a single '.' */
2921 /* Write as much of the Ellipses string as possible */
2922 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2925 dwWritten
+= dwEllipsesLen
;
2933 strcpyW(buff
+ dwLen
, szEllipses
);
2934 strcpyW(lpszPath
, buff
);
2945 /*************************************************************************
2946 * PathGetCharTypeA [SHLWAPI.@]
2948 * Categorise a character from a file path.
2951 * ch [I] Character to get the type of
2954 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2956 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2958 return PathGetCharTypeW(ch
);
2961 /*************************************************************************
2962 * PathGetCharTypeW [SHLWAPI.@]
2964 * See PathGetCharTypeA.
2966 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2970 TRACE("(%d)\n", ch
);
2972 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2973 ch
== '"' || ch
== '|' || ch
== '/')
2974 flags
= GCT_INVALID
; /* Invalid */
2975 else if (ch
== '*' || ch
=='?')
2976 flags
= GCT_WILD
; /* Wildchars */
2977 else if ((ch
== '\\') || (ch
== ':'))
2978 return GCT_SEPARATOR
; /* Path separators */
2983 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2984 ch
== '.' || ch
== '@' || ch
== '^' ||
2985 ch
== '\'' || ch
== 130 || ch
== '`')
2986 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2989 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2990 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2995 /*************************************************************************
2996 * SHLWAPI_UseSystemForSystemFolders
2998 * Internal helper for PathMakeSystemFolderW.
3000 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3002 static BOOL bCheckedReg
= FALSE
;
3003 static BOOL bUseSystemForSystemFolders
= FALSE
;
3009 /* Key tells Win what file attributes to use on system folders */
3010 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3011 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3012 "UseSystemForSystemFolders", 0, 0, 0))
3013 bUseSystemForSystemFolders
= TRUE
;
3015 return bUseSystemForSystemFolders
;
3018 /*************************************************************************
3019 * PathMakeSystemFolderA [SHLWAPI.@]
3021 * Set system folder attribute for a path.
3024 * lpszPath [I] The path to turn into a system folder
3027 * TRUE If the path was changed to/already was a system folder
3028 * FALSE If the path is invalid or SetFileAttributesA() fails
3030 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3034 TRACE("(%s)\n", debugstr_a(lpszPath
));
3036 if (lpszPath
&& *lpszPath
)
3038 WCHAR szPath
[MAX_PATH
];
3039 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3040 bRet
= PathMakeSystemFolderW(szPath
);
3045 /*************************************************************************
3046 * PathMakeSystemFolderW [SHLWAPI.@]
3048 * See PathMakeSystemFolderA.
3050 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3052 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3053 WCHAR buff
[MAX_PATH
];
3055 TRACE("(%s)\n", debugstr_w(lpszPath
));
3057 if (!lpszPath
|| !*lpszPath
)
3060 /* If the directory is already a system directory, don't do anything */
3061 GetSystemDirectoryW(buff
, MAX_PATH
);
3062 if (!strcmpW(buff
, lpszPath
))
3065 GetWindowsDirectoryW(buff
, MAX_PATH
);
3066 if (!strcmpW(buff
, lpszPath
))
3069 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3070 if (SHLWAPI_UseSystemForSystemFolders())
3071 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3073 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3076 /* Change file attributes to system attributes */
3077 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3078 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3081 /*************************************************************************
3082 * PathRenameExtensionA [SHLWAPI.@]
3084 * Swap the file extension in a path with another extension.
3087 * lpszPath [I/O] Path to swap the extension in
3088 * lpszExt [I] The new extension
3091 * TRUE if lpszPath was modified,
3092 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3094 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3096 LPSTR lpszExtension
;
3098 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3100 lpszExtension
= PathFindExtensionA(lpszPath
);
3102 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3105 strcpy(lpszExtension
, lpszExt
);
3109 /*************************************************************************
3110 * PathRenameExtensionW [SHLWAPI.@]
3112 * See PathRenameExtensionA.
3114 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3116 LPWSTR lpszExtension
;
3118 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3120 lpszExtension
= PathFindExtensionW(lpszPath
);
3122 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3125 strcpyW(lpszExtension
, lpszExt
);
3129 /*************************************************************************
3130 * PathSearchAndQualifyA [SHLWAPI.@]
3132 * Determine if a given path is correct and fully qualified.
3135 * lpszPath [I] Path to check
3136 * lpszBuf [O] Output for correct path
3137 * cchBuf [I] Size of lpszBuf
3142 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3144 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3146 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3148 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3151 /*************************************************************************
3152 * PathSearchAndQualifyW [SHLWAPI.@]
3154 * See PathSearchAndQualifyA.
3156 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3158 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3160 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3162 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3165 /*************************************************************************
3166 * PathSkipRootA [SHLWAPI.@]
3168 * Return the portion of a path following the drive letter or mount point.
3171 * lpszPath [I] The path to skip on
3174 * Success: A pointer to the next character after the root.
3175 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3177 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3179 TRACE("(%s)\n", debugstr_a(lpszPath
));
3181 if (!lpszPath
|| !*lpszPath
)
3184 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3186 /* Network share: skip share server and mount point */
3188 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3189 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3191 return (LPSTR
)lpszPath
;
3194 if (IsDBCSLeadByte(*lpszPath
))
3198 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3199 return (LPSTR
)lpszPath
+ 3;
3203 /*************************************************************************
3204 * PathSkipRootW [SHLWAPI.@]
3206 * See PathSkipRootA.
3208 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3210 TRACE("(%s)\n", debugstr_w(lpszPath
));
3212 if (!lpszPath
|| !*lpszPath
)
3215 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3217 /* Network share: skip share server and mount point */
3219 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3220 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3222 return (LPWSTR
)lpszPath
;
3226 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3227 return (LPWSTR
)lpszPath
+ 3;
3231 /*************************************************************************
3232 * PathCreateFromUrlA [SHLWAPI.@]
3234 * See PathCreateFromUrlW
3236 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3237 LPDWORD pcchPath
, DWORD dwReserved
)
3239 WCHAR bufW
[MAX_PATH
];
3240 WCHAR
*pathW
= bufW
;
3241 UNICODE_STRING urlW
;
3243 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3245 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3246 return E_INVALIDARG
;
3247 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3248 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3249 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3252 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3253 if(*pcchPath
> lenA
) {
3254 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3258 *pcchPath
= lenA
+ 1;
3262 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3263 RtlFreeUnicodeString(&urlW
);
3267 /*************************************************************************
3268 * PathCreateFromUrlW [SHLWAPI.@]
3270 * Create a path from a URL
3273 * lpszUrl [I] URL to convert into a path
3274 * lpszPath [O] Output buffer for the resulting Path
3275 * pcchPath [I] Length of lpszPath
3276 * dwFlags [I] Flags controlling the conversion
3279 * Success: S_OK. lpszPath contains the URL in path format,
3280 * Failure: An HRESULT error code such as E_INVALIDARG.
3282 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3283 LPDWORD pcchPath
, DWORD dwReserved
)
3285 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3290 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3292 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3293 return E_INVALIDARG
;
3296 if (strncmpW(pszUrl
, file_colon
, 5))
3297 return E_INVALIDARG
;
3300 while(*pszUrl
== '/' || *pszUrl
== '\\') {
3305 if(isalphaW(*pszUrl
) && (pszUrl
[1] == ':' || pszUrl
[1] == '|') && (pszUrl
[2] == '/' || pszUrl
[2] == '\\'))
3319 hr
= UrlUnescapeW((LPWSTR
)pszUrl
, pszPath
, pcchPath
, 0);
3320 if(hr
!= S_OK
) return hr
;
3322 for(ptr
= pszPath
; *ptr
; ptr
++)
3323 if(*ptr
== '/') *ptr
= '\\';
3325 while(*pszPath
== '\\')
3328 if(isalphaW(*pszPath
) && pszPath
[1] == '|' && pszPath
[2] == '\\') /* c|\ -> c:\ */
3331 if(nslashes
== 2 && (ptr
= strchrW(pszPath
, '\\'))) { /* \\host\c:\ -> \\hostc:\ */
3333 if(isalphaW(*ptr
) && (ptr
[1] == ':' || ptr
[1] == '|') && ptr
[2] == '\\') {
3334 memmove(ptr
- 1, ptr
, (strlenW(ptr
) + 1) * sizeof(WCHAR
));
3339 TRACE("Returning %s\n",debugstr_w(pszPath
));
3344 /*************************************************************************
3345 * PathRelativePathToA [SHLWAPI.@]
3347 * Create a relative path from one path to another.
3350 * lpszPath [O] Destination for relative path
3351 * lpszFrom [I] Source path
3352 * dwAttrFrom [I] File attribute of source path
3353 * lpszTo [I] Destination path
3354 * dwAttrTo [I] File attributes of destination path
3357 * TRUE If a relative path can be formed. lpszPath contains the new path
3358 * FALSE If the paths are not relative or any parameters are invalid
3361 * lpszTo should be at least MAX_PATH in length.
3363 * Calling this function with relative paths for lpszFrom or lpszTo may
3364 * give erroneous results.
3366 * The Win32 version of this function contains a bug where the lpszTo string
3367 * may be referenced 1 byte beyond the end of the string. As a result random
3368 * garbage may be written to the output path, depending on what lies beyond
3369 * the last byte of the string. This bug occurs because of the behaviour of
3370 * PathCommonPrefix() (see notes for that function), and no workaround seems
3371 * possible with Win32.
3373 * This bug has been fixed here, so for example the relative path from "\\"
3374 * to "\\" is correctly determined as "." in this implementation.
3376 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3377 LPCSTR lpszTo
, DWORD dwAttrTo
)
3381 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3382 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3384 if(lpszPath
&& lpszFrom
&& lpszTo
)
3386 WCHAR szPath
[MAX_PATH
];
3387 WCHAR szFrom
[MAX_PATH
];
3388 WCHAR szTo
[MAX_PATH
];
3389 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3390 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3391 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3392 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3397 /*************************************************************************
3398 * PathRelativePathToW [SHLWAPI.@]
3400 * See PathRelativePathToA.
3402 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3403 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3405 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3406 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3407 WCHAR szFrom
[MAX_PATH
];
3408 WCHAR szTo
[MAX_PATH
];
3411 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3412 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3414 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3418 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3419 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3421 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3422 PathRemoveFileSpecW(szFrom
);
3423 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3424 PathRemoveFileSpecW(szTo
);
3426 /* Paths can only be relative if they have a common root */
3427 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3430 /* Strip off lpszFrom components to the root, by adding "..\" */
3431 lpszFrom
= szFrom
+ dwLen
;
3437 if (*lpszFrom
== '\\')
3442 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3443 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3446 /* From the root add the components of lpszTo */
3448 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3451 if (*lpszTo
&& lpszTo
[-1])
3453 if (*lpszTo
!= '\\')
3455 dwLen
= strlenW(lpszPath
);
3456 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3461 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3466 /*************************************************************************
3467 * PathUnmakeSystemFolderA [SHLWAPI.@]
3469 * Remove the system folder attributes from a path.
3472 * lpszPath [I] The path to remove attributes from
3476 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3477 * SetFileAttributesA() fails.
3479 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3483 TRACE("(%s)\n", debugstr_a(lpszPath
));
3485 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3486 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3489 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3490 return SetFileAttributesA(lpszPath
, dwAttr
);
3493 /*************************************************************************
3494 * PathUnmakeSystemFolderW [SHLWAPI.@]
3496 * See PathUnmakeSystemFolderA.
3498 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3502 TRACE("(%s)\n", debugstr_w(lpszPath
));
3504 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3505 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3508 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3509 return SetFileAttributesW(lpszPath
, dwAttr
);
3513 /*************************************************************************
3514 * PathSetDlgItemPathA [SHLWAPI.@]
3516 * Set the text of a dialog item to a path, shrinking the path to fit
3517 * if it is too big for the item.
3520 * hDlg [I] Dialog handle
3521 * id [I] ID of item in the dialog
3522 * lpszPath [I] Path to set as the items text
3528 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3529 * window text is erased).
3531 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3533 WCHAR szPath
[MAX_PATH
];
3535 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3538 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3541 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3544 /*************************************************************************
3545 * PathSetDlgItemPathW [SHLWAPI.@]
3547 * See PathSetDlgItemPathA.
3549 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3551 WCHAR path
[MAX_PATH
+ 1];
3557 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3559 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3563 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3567 GetClientRect(hwItem
, &rect
);
3569 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3573 PathCompactPathW(hdc
, path
, rect
.right
);
3574 SelectObject(hdc
, hPrevObj
);
3577 ReleaseDC(hDlg
, hdc
);
3578 SetWindowTextW(hwItem
, path
);
3581 /*************************************************************************
3582 * PathIsNetworkPathA [SHLWAPI.@]
3584 * Determine if the given path is a network path.
3587 * lpszPath [I] Path to check
3590 * TRUE If lpszPath is a UNC share or mapped network drive, or
3591 * FALSE If lpszPath is a local drive or cannot be determined
3593 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3597 TRACE("(%s)\n",debugstr_a(lpszPath
));
3601 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3603 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3604 if (dwDriveNum
== -1)
3606 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3607 return pIsNetDrive(dwDriveNum
);
3610 /*************************************************************************
3611 * PathIsNetworkPathW [SHLWAPI.@]
3613 * See PathIsNetworkPathA.
3615 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3619 TRACE("(%s)\n", debugstr_w(lpszPath
));
3623 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3625 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3626 if (dwDriveNum
== -1)
3628 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3629 return pIsNetDrive(dwDriveNum
);
3632 /*************************************************************************
3633 * PathIsLFNFileSpecA [SHLWAPI.@]
3635 * Determine if the given path is a long file name
3638 * lpszPath [I] Path to check
3641 * TRUE If path is a long file name,
3642 * FALSE If path is a valid DOS short file name
3644 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3646 DWORD dwNameLen
= 0, dwExtLen
= 0;
3648 TRACE("(%s)\n",debugstr_a(lpszPath
));
3655 if (*lpszPath
== ' ')
3656 return TRUE
; /* DOS names cannot have spaces */
3657 if (*lpszPath
== '.')
3660 return TRUE
; /* DOS names have only one dot */
3667 return TRUE
; /* DOS extensions are <= 3 chars*/
3673 return TRUE
; /* DOS names are <= 8 chars */
3675 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3677 return FALSE
; /* Valid DOS path */
3680 /*************************************************************************
3681 * PathIsLFNFileSpecW [SHLWAPI.@]
3683 * See PathIsLFNFileSpecA.
3685 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3687 DWORD dwNameLen
= 0, dwExtLen
= 0;
3689 TRACE("(%s)\n",debugstr_w(lpszPath
));
3696 if (*lpszPath
== ' ')
3697 return TRUE
; /* DOS names cannot have spaces */
3698 if (*lpszPath
== '.')
3701 return TRUE
; /* DOS names have only one dot */
3708 return TRUE
; /* DOS extensions are <= 3 chars*/
3714 return TRUE
; /* DOS names are <= 8 chars */
3718 return FALSE
; /* Valid DOS path */
3721 /*************************************************************************
3722 * PathIsDirectoryEmptyA [SHLWAPI.@]
3724 * Determine if a given directory is empty.
3727 * lpszPath [I] Directory to check
3730 * TRUE If the directory exists and contains no files,
3733 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3737 TRACE("(%s)\n",debugstr_a(lpszPath
));
3741 WCHAR szPath
[MAX_PATH
];
3742 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3743 bRet
= PathIsDirectoryEmptyW(szPath
);
3748 /*************************************************************************
3749 * PathIsDirectoryEmptyW [SHLWAPI.@]
3751 * See PathIsDirectoryEmptyA.
3753 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3755 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3756 WCHAR szSearch
[MAX_PATH
];
3759 BOOL retVal
= FALSE
;
3760 WIN32_FIND_DATAW find_data
;
3762 TRACE("(%s)\n",debugstr_w(lpszPath
));
3764 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3767 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3768 PathAddBackslashW(szSearch
);
3769 dwLen
= strlenW(szSearch
);
3770 if (dwLen
> MAX_PATH
- 4)
3773 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3774 hfind
= FindFirstFileW(szSearch
, &find_data
);
3776 if (hfind
!= INVALID_HANDLE_VALUE
&&
3777 find_data
.cFileName
[0] == '.' &&
3778 find_data
.cFileName
[1] == '.')
3780 /* The only directory entry should be the parent */
3781 if (!FindNextFileW(hfind
, &find_data
))
3789 /*************************************************************************
3790 * PathFindSuffixArrayA [SHLWAPI.@]
3792 * Find a suffix string in an array of suffix strings
3795 * lpszSuffix [I] Suffix string to search for
3796 * lppszArray [I] Array of suffix strings to search
3797 * dwCount [I] Number of elements in lppszArray
3800 * Success: The index of the position of lpszSuffix in lppszArray
3801 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3804 * The search is case sensitive.
3805 * The match is made against the end of the suffix string, so for example:
3806 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3808 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3813 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3815 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3817 dwLen
= strlen(lpszSuffix
);
3819 while (dwRet
< dwCount
)
3821 size_t dwCompareLen
= strlen(*lppszArray
);
3822 if (dwCompareLen
< dwLen
)
3824 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3825 return *lppszArray
; /* Found */
3834 /*************************************************************************
3835 * PathFindSuffixArrayW [SHLWAPI.@]
3837 * See PathFindSuffixArrayA.
3839 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3844 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3846 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3848 dwLen
= strlenW(lpszSuffix
);
3850 while (dwRet
< dwCount
)
3852 size_t dwCompareLen
= strlenW(*lppszArray
);
3853 if (dwCompareLen
< dwLen
)
3855 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3856 return *lppszArray
; /* Found */
3865 /*************************************************************************
3866 * PathUndecorateA [SHLWAPI.@]
3868 * Undecorate a file path
3871 * lpszPath [I/O] Path to remove any decoration from
3877 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3879 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3881 TRACE("(%s)\n",debugstr_a(lpszPath
));
3885 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3886 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3888 LPSTR lpszSkip
= lpszExt
- 2;
3889 if (*lpszSkip
== '[')
3890 lpszSkip
++; /* [] (no number) */
3892 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3894 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3896 /* remove the [n] */
3899 *lpszSkip
++ = *lpszExt
++;
3906 /*************************************************************************
3907 * PathUndecorateW [SHLWAPI.@]
3909 * See PathUndecorateA.
3911 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3913 TRACE("(%s)\n",debugstr_w(lpszPath
));
3917 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3918 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3920 LPWSTR lpszSkip
= lpszExt
- 2;
3921 if (*lpszSkip
== '[')
3922 lpszSkip
++; /* [] (no number) */
3924 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3926 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3928 /* remove the [n] */
3931 *lpszSkip
++ = *lpszExt
++;
3938 /*************************************************************************
3939 * PathUnExpandEnvStringsA [SHLWAPI.@]
3941 * Substitute folder names in a path with their corresponding environment
3945 * pszPath [I] Buffer containing the path to unexpand.
3946 * pszBuf [O] Buffer to receive the unexpanded path.
3947 * cchBuf [I] Size of pszBuf in characters.
3953 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR pszPath
, LPSTR pszBuf
, UINT cchBuf
)
3955 FIXME("(%s,%s,0x%08x)\n", debugstr_a(pszPath
), debugstr_a(pszBuf
), cchBuf
);
3959 /*************************************************************************
3960 * PathUnExpandEnvStringsW [SHLWAPI.@]
3962 * Unicode version of PathUnExpandEnvStringsA.
3964 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR pszPath
, LPWSTR pszBuf
, UINT cchBuf
)
3966 FIXME("(%s,%s,0x%08x)\n", debugstr_w(pszPath
), debugstr_w(pszBuf
), cchBuf
);
3970 /*************************************************************************
3973 * Find localised or default web content in "%WINDOWS%\web\".
3976 * lpszFile [I] File name containing content to look for
3977 * lpszPath [O] Buffer to contain the full path to the file
3978 * dwPathLen [I] Length of lpszPath
3981 * Success: S_OK. lpszPath contains the full path to the content.
3982 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
3984 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
3986 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
3989 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
3991 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
3993 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
3994 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
3998 /*************************************************************************
4001 * Unicode version of SHGetWebFolderFilePathA.
4003 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4005 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4006 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4007 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4008 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4009 DWORD dwLen
, dwFileLen
;
4010 LANGID lidSystem
, lidUser
;
4012 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4014 /* Get base directory for web content */
4015 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4016 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4019 dwFileLen
= strlenW(lpszFile
);
4021 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4022 return E_FAIL
; /* lpszPath too short */
4024 strcpyW(lpszPath
+dwLen
, szWeb
);
4026 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4028 lidSystem
= GetSystemDefaultUILanguage();
4029 lidUser
= GetUserDefaultUILanguage();
4031 if (lidSystem
!= lidUser
)
4033 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4035 /* Use localised content in the users UI language if present */
4036 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4037 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4038 if (PathFileExistsW(lpszPath
))
4043 /* Fall back to OS default installed content */
4044 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4045 if (PathFileExistsW(lpszPath
))
4050 #define PATH_CHAR_CLASS_LETTER 0x00000001
4051 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4052 #define PATH_CHAR_CLASS_DOT 0x00000004
4053 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4054 #define PATH_CHAR_CLASS_COLON 0x00000010
4055 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4056 #define PATH_CHAR_CLASS_COMMA 0x00000040
4057 #define PATH_CHAR_CLASS_SPACE 0x00000080
4058 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4059 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4061 #define PATH_CHAR_CLASS_INVALID 0x00000000
4062 #define PATH_CHAR_CLASS_ANY 0xffffffff
4064 static const DWORD SHELL_charclass
[] =
4066 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4067 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4068 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4069 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4070 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4071 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4072 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4073 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4074 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4075 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4076 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4077 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4078 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4079 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4080 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4081 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4082 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4083 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4084 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4085 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4086 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4087 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4088 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4089 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4090 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4091 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4092 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4093 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4094 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4095 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4096 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4097 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4098 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4099 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4100 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4101 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4102 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4103 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4104 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4105 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4106 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4107 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4108 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4109 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4110 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4111 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4112 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4113 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4114 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4115 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4116 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4117 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4118 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4119 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4120 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4121 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4122 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4123 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4124 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4125 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4126 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4127 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4128 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4129 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4132 /*************************************************************************
4135 * Check if an ASCII char is of a certain class
4137 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4139 if ((unsigned)c
> 0x7e)
4140 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4142 return class & SHELL_charclass
[(unsigned)c
];
4145 /*************************************************************************
4148 * Check if a Unicode char is of a certain class
4150 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4153 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4155 return class & SHELL_charclass
[c
];