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
766 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
768 TRACE("(%s)\n", debugstr_a(lpszPath
));
772 lpszPath
= PathFindExtensionA(lpszPath
);
777 /*************************************************************************
778 * PathRemoveExtensionW [SHLWAPI.@]
780 * See PathRemoveExtensionA.
782 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
784 TRACE("(%s)\n", debugstr_w(lpszPath
));
788 lpszPath
= PathFindExtensionW(lpszPath
);
793 /*************************************************************************
794 * PathRemoveBackslashA [SHLWAPI.@]
796 * Remove a trailing backslash from a path.
799 * lpszPath [I/O] Path to remove backslash from
802 * Success: A pointer to the end of the path
803 * Failure: NULL, if lpszPath is NULL
805 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
809 TRACE("(%s)\n", debugstr_a(lpszPath
));
813 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
814 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
820 /*************************************************************************
821 * PathRemoveBackslashW [SHLWAPI.@]
823 * See PathRemoveBackslashA.
825 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
827 LPWSTR szTemp
= NULL
;
829 TRACE("(%s)\n", debugstr_w(lpszPath
));
833 szTemp
= lpszPath
+ strlenW(lpszPath
);
834 if (szTemp
> lpszPath
) szTemp
--;
835 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
841 /*************************************************************************
842 * PathRemoveBlanksA [SHLWAPI.@]
844 * Remove Spaces from the start and end of a path.
847 * lpszPath [I/O] Path to strip blanks from
852 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
854 TRACE("(%s)\n", debugstr_a(lpszPath
));
856 if(lpszPath
&& *lpszPath
)
858 LPSTR start
= lpszPath
;
860 while (*lpszPath
== ' ')
861 lpszPath
= CharNextA(lpszPath
);
864 *start
++ = *lpszPath
++;
866 if (start
!= lpszPath
)
867 while (start
[-1] == ' ')
873 /*************************************************************************
874 * PathRemoveBlanksW [SHLWAPI.@]
876 * See PathRemoveBlanksA.
878 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
880 TRACE("(%s)\n", debugstr_w(lpszPath
));
882 if(lpszPath
&& *lpszPath
)
884 LPWSTR start
= lpszPath
;
886 while (*lpszPath
== ' ')
890 *start
++ = *lpszPath
++;
892 if (start
!= lpszPath
)
893 while (start
[-1] == ' ')
899 /*************************************************************************
900 * PathQuoteSpacesA [SHLWAPI.@]
902 * Surround a path containing spaces in quotes.
905 * lpszPath [I/O] Path to quote
911 * The path is not changed if it is invalid or has no spaces.
913 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
915 TRACE("(%s)\n", debugstr_a(lpszPath
));
917 if(lpszPath
&& StrChrA(lpszPath
,' '))
919 size_t iLen
= strlen(lpszPath
) + 1;
921 if (iLen
+ 2 < MAX_PATH
)
923 memmove(lpszPath
+ 1, lpszPath
, iLen
);
925 lpszPath
[iLen
] = '"';
926 lpszPath
[iLen
+ 1] = '\0';
931 /*************************************************************************
932 * PathQuoteSpacesW [SHLWAPI.@]
934 * See PathQuoteSpacesA.
936 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
938 TRACE("(%s)\n", debugstr_w(lpszPath
));
940 if(lpszPath
&& StrChrW(lpszPath
,' '))
942 int iLen
= strlenW(lpszPath
) + 1;
944 if (iLen
+ 2 < MAX_PATH
)
946 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
948 lpszPath
[iLen
] = '"';
949 lpszPath
[iLen
+ 1] = '\0';
954 /*************************************************************************
955 * PathUnquoteSpacesA [SHLWAPI.@]
957 * Remove quotes ("") from around a path, if present.
960 * lpszPath [I/O] Path to strip quotes from
966 * If the path contains a single quote only, an empty string will result.
967 * Otherwise quotes are only removed if they appear at the start and end
970 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
972 TRACE("(%s)\n", debugstr_a(lpszPath
));
974 if (lpszPath
&& *lpszPath
== '"')
976 DWORD dwLen
= strlen(lpszPath
) - 1;
978 if (lpszPath
[dwLen
] == '"')
980 lpszPath
[dwLen
] = '\0';
981 for (; *lpszPath
; lpszPath
++)
982 *lpszPath
= lpszPath
[1];
987 /*************************************************************************
988 * PathUnquoteSpacesW [SHLWAPI.@]
990 * See PathUnquoteSpacesA.
992 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
994 TRACE("(%s)\n", debugstr_w(lpszPath
));
996 if (lpszPath
&& *lpszPath
== '"')
998 DWORD dwLen
= strlenW(lpszPath
) - 1;
1000 if (lpszPath
[dwLen
] == '"')
1002 lpszPath
[dwLen
] = '\0';
1003 for (; *lpszPath
; lpszPath
++)
1004 *lpszPath
= lpszPath
[1];
1009 /*************************************************************************
1010 * PathParseIconLocationA [SHLWAPI.@]
1012 * Parse the location of an icon from a path.
1015 * lpszPath [I/O] The path to parse the icon location from.
1018 * Success: The number of the icon
1019 * Failure: 0 if the path does not contain an icon location or is NULL
1022 * The path has surrounding quotes and spaces removed regardless
1023 * of whether the call succeeds or not.
1025 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1030 TRACE("(%s)\n", debugstr_a(lpszPath
));
1034 if ((lpszComma
= strchr(lpszPath
, ',')))
1036 *lpszComma
++ = '\0';
1037 iRet
= StrToIntA(lpszComma
);
1039 PathUnquoteSpacesA(lpszPath
);
1040 PathRemoveBlanksA(lpszPath
);
1045 /*************************************************************************
1046 * PathParseIconLocationW [SHLWAPI.@]
1048 * See PathParseIconLocationA.
1050 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1055 TRACE("(%s)\n", debugstr_w(lpszPath
));
1059 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1061 *lpszComma
++ = '\0';
1062 iRet
= StrToIntW(lpszComma
);
1064 PathUnquoteSpacesW(lpszPath
);
1065 PathRemoveBlanksW(lpszPath
);
1070 /*************************************************************************
1073 * Unicode version of PathFileExistsDefExtA.
1075 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1077 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1078 { '.', 'c', 'o', 'm', 0},
1079 { '.', 'e', 'x', 'e', 0},
1080 { '.', 'b', 'a', 't', 0},
1081 { '.', 'l', 'n', 'k', 0},
1082 { '.', 'c', 'm', 'd', 0},
1085 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1087 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1092 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1093 if (!*szExt
|| dwWhich
& 0x40)
1096 int iLen
= lstrlenW(lpszPath
);
1097 if (iLen
> (MAX_PATH
- 5))
1099 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1101 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1102 if (PathFileExistsW(lpszPath
))
1107 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1111 return PathFileExistsW(lpszPath
);
1114 /*************************************************************************
1117 * Determine if a file exists locally and is of an executable type.
1120 * lpszPath [I/O] File to search for
1121 * dwWhich [I] Type of executable to search for
1124 * TRUE If the file was found. lpszPath contains the file name.
1128 * lpszPath is modified in place and must be at least MAX_PATH in length.
1129 * If the function returns FALSE, the path is modified to its original state.
1130 * If the given path contains an extension or dwWhich is 0, executable
1131 * extensions are not checked.
1133 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1134 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1135 * their own developers exclusive use. Monopoly, anyone?
1137 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1141 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1145 WCHAR szPath
[MAX_PATH
];
1146 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1147 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1149 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1154 /*************************************************************************
1155 * SHLWAPI_PathFindInOtherDirs
1157 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1159 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1161 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1162 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1166 WCHAR buff
[MAX_PATH
];
1168 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1170 /* Try system directories */
1171 GetSystemDirectoryW(buff
, MAX_PATH
);
1172 if (!PathAppendW(buff
, lpszFile
))
1174 if (PathFileExistsDefExtW(buff
, dwWhich
))
1176 strcpyW(lpszFile
, buff
);
1179 GetWindowsDirectoryW(buff
, MAX_PATH
);
1180 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1182 if (PathFileExistsDefExtW(buff
, dwWhich
))
1184 strcpyW(lpszFile
, buff
);
1187 GetWindowsDirectoryW(buff
, MAX_PATH
);
1188 if (!PathAppendW(buff
, lpszFile
))
1190 if (PathFileExistsDefExtW(buff
, dwWhich
))
1192 strcpyW(lpszFile
, buff
);
1195 /* Try dirs listed in %PATH% */
1196 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1198 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1201 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1202 lpszCurr
= lpszPATH
;
1205 LPCWSTR lpszEnd
= lpszCurr
;
1206 LPWSTR pBuff
= buff
;
1208 while (*lpszEnd
== ' ')
1210 while (*lpszEnd
&& *lpszEnd
!= ';')
1211 *pBuff
++ = *lpszEnd
++;
1215 lpszCurr
= lpszEnd
+ 1;
1217 lpszCurr
= NULL
; /* Last Path, terminate after this */
1219 if (!PathAppendW(buff
, lpszFile
))
1221 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1224 if (PathFileExistsDefExtW(buff
, dwWhich
))
1226 strcpyW(lpszFile
, buff
);
1227 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1231 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1235 /*************************************************************************
1238 * Search a range of paths for a specific type of executable.
1241 * lpszFile [I/O] File to search for
1242 * lppszOtherDirs [I] Other directories to look in
1243 * dwWhich [I] Type of executable to search for
1246 * Success: TRUE. The path to the executable is stored in lpszFile.
1247 * Failure: FALSE. The path to the executable is unchanged.
1249 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1251 WCHAR szFile
[MAX_PATH
];
1252 WCHAR buff
[MAX_PATH
];
1254 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1256 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1259 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1261 /* Search provided directories first */
1262 if (lppszOtherDirs
&& *lppszOtherDirs
)
1264 WCHAR szOther
[MAX_PATH
];
1265 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1267 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1269 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1270 PathCombineW(buff
, szOther
, szFile
);
1271 if (PathFileExistsDefExtW(buff
, dwWhich
))
1273 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1279 /* Not found, try system and path dirs */
1280 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1282 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1288 /*************************************************************************
1291 * Unicode version of PathFindOnPathExA.
1293 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1295 WCHAR buff
[MAX_PATH
];
1297 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1299 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1302 /* Search provided directories first */
1303 if (lppszOtherDirs
&& *lppszOtherDirs
)
1305 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1306 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1308 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1309 if (PathFileExistsDefExtW(buff
, dwWhich
))
1311 strcpyW(lpszFile
, buff
);
1317 /* Not found, try system and path dirs */
1318 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1321 /*************************************************************************
1322 * PathFindOnPathA [SHLWAPI.@]
1324 * Search a range of paths for an executable.
1327 * lpszFile [I/O] File to search for
1328 * lppszOtherDirs [I] Other directories to look in
1331 * Success: TRUE. The path to the executable is stored in lpszFile.
1332 * Failure: FALSE. The path to the executable is unchanged.
1334 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1336 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1337 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1340 /*************************************************************************
1341 * PathFindOnPathW [SHLWAPI.@]
1343 * See PathFindOnPathA.
1345 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1347 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1348 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1351 /*************************************************************************
1352 * PathCompactPathExA [SHLWAPI.@]
1354 * Compact a path into a given number of characters.
1357 * lpszDest [O] Destination for compacted path
1358 * lpszPath [I] Source path
1359 * cchMax [I] Maximum size of compacted path
1360 * dwFlags [I] Reserved
1363 * Success: TRUE. The compacted path is written to lpszDest.
1364 * Failure: FALSE. lpszPath is undefined.
1367 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1369 * The Win32 version of this function contains a bug: When cchMax == 7,
1370 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1373 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1374 * because Win32 will insert a "\" in lpszDest, even if one is
1375 * not present in the original path.
1377 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1378 UINT cchMax
, DWORD dwFlags
)
1382 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1384 if (lpszPath
&& lpszDest
)
1386 WCHAR szPath
[MAX_PATH
];
1387 WCHAR szDest
[MAX_PATH
];
1389 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1391 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1392 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1397 /*************************************************************************
1398 * PathCompactPathExW [SHLWAPI.@]
1400 * See PathCompactPathExA.
1402 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1403 UINT cchMax
, DWORD dwFlags
)
1405 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1407 DWORD dwLen
, dwFileLen
= 0;
1409 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1416 WARN("Invalid lpszDest would crash under Win32!\n");
1425 dwLen
= strlenW(lpszPath
) + 1;
1429 /* Don't need to compact */
1430 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1434 /* Path must be compacted to fit into lpszDest */
1435 lpszFile
= PathFindFileNameW(lpszPath
);
1436 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1438 if (dwFileLen
== dwLen
)
1440 /* No root in psth */
1443 while (--cchMax
> 0) /* No room left for anything but ellipses */
1448 /* Compact the file name with ellipses at the end */
1450 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1451 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1454 /* We have a root in the path */
1455 lpszFile
--; /* Start compacted filename with the path separator */
1458 if (dwFileLen
+ 3 > cchMax
)
1460 /* Compact the file name */
1463 while (--cchMax
> 0) /* No room left for anything but ellipses */
1468 strcpyW(lpszDest
, szEllipses
);
1471 *lpszDest
++ = *lpszFile
++;
1474 while (--cchMax
> 0) /* No room left for anything but ellipses */
1480 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1481 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1485 /* Only the root needs to be Compacted */
1486 dwLen
= cchMax
- dwFileLen
- 3;
1487 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1488 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1489 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1493 /*************************************************************************
1494 * PathIsRelativeA [SHLWAPI.@]
1496 * Determine if a path is a relative path.
1499 * lpszPath [I] Path to check
1502 * TRUE: The path is relative, or is invalid.
1503 * FALSE: The path is not relative.
1505 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1507 TRACE("(%s)\n",debugstr_a(lpszPath
));
1509 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1511 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1516 /*************************************************************************
1517 * PathIsRelativeW [SHLWAPI.@]
1519 * See PathIsRelativeA.
1521 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1523 TRACE("(%s)\n",debugstr_w(lpszPath
));
1525 if (!lpszPath
|| !*lpszPath
)
1527 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1532 /*************************************************************************
1533 * PathIsRootA [SHLWAPI.@]
1535 * Determine if a path is a root path.
1538 * lpszPath [I] Path to check
1541 * TRUE If lpszPath is valid and a root path,
1544 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1546 TRACE("(%s)\n", debugstr_a(lpszPath
));
1548 if (lpszPath
&& *lpszPath
)
1550 if (*lpszPath
== '\\')
1553 return TRUE
; /* \ */
1554 else if (lpszPath
[1]=='\\')
1556 BOOL bSeenSlash
= FALSE
;
1559 /* Check for UNC root path */
1562 if (*lpszPath
== '\\')
1568 lpszPath
= CharNextA(lpszPath
);
1573 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1574 return TRUE
; /* X:\ */
1579 /*************************************************************************
1580 * PathIsRootW [SHLWAPI.@]
1584 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1586 TRACE("(%s)\n", debugstr_w(lpszPath
));
1588 if (lpszPath
&& *lpszPath
)
1590 if (*lpszPath
== '\\')
1593 return TRUE
; /* \ */
1594 else if (lpszPath
[1]=='\\')
1596 BOOL bSeenSlash
= FALSE
;
1599 /* Check for UNC root path */
1602 if (*lpszPath
== '\\')
1613 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1614 return TRUE
; /* X:\ */
1619 /*************************************************************************
1620 * PathIsDirectoryA [SHLWAPI.@]
1622 * Determine if a path is a valid directory
1625 * lpszPath [I] Path to check.
1628 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1629 * FALSE if lpszPath is invalid or not a directory.
1632 * Although this function is prototyped as returning a BOOL, it returns
1633 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1635 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1640 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1644 TRACE("(%s)\n", debugstr_a(lpszPath
));
1646 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1649 if (PathIsUNCServerShareA(lpszPath
))
1651 FIXME("UNC Server Share not yet supported - FAILING\n");
1655 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1657 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1660 /*************************************************************************
1661 * PathIsDirectoryW [SHLWAPI.@]
1663 * See PathIsDirectoryA.
1665 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1669 TRACE("(%s)\n", debugstr_w(lpszPath
));
1671 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1674 if (PathIsUNCServerShareW(lpszPath
))
1676 FIXME("UNC Server Share not yet supported - FAILING\n");
1680 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1682 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1685 /*************************************************************************
1686 * PathFileExistsA [SHLWAPI.@]
1688 * Determine if a file exists.
1691 * lpszPath [I] Path to check
1694 * TRUE If the file exists and is readable
1697 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1702 TRACE("(%s)\n",debugstr_a(lpszPath
));
1707 /* Prevent a dialog box if path is on a disk that has been ejected. */
1708 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1709 dwAttr
= GetFileAttributesA(lpszPath
);
1710 SetErrorMode(iPrevErrMode
);
1711 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1714 /*************************************************************************
1715 * PathFileExistsW [SHLWAPI.@]
1717 * See PathFileExistsA.
1719 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1724 TRACE("(%s)\n",debugstr_w(lpszPath
));
1729 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1730 dwAttr
= GetFileAttributesW(lpszPath
);
1731 SetErrorMode(iPrevErrMode
);
1732 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1735 /*************************************************************************
1736 * PathFileExistsAndAttributesA [SHLWAPI.445]
1738 * Determine if a file exists.
1741 * lpszPath [I] Path to check
1742 * dwAttr [O] attributes of file
1745 * TRUE If the file exists and is readable
1748 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1753 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1756 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1761 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1762 dwVal
= GetFileAttributesA(lpszPath
);
1763 SetErrorMode(iPrevErrMode
);
1766 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1769 /*************************************************************************
1770 * PathFileExistsAndAttributesW [SHLWAPI.446]
1772 * See PathFileExistsA.
1774 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1779 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1784 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1785 dwVal
= GetFileAttributesW(lpszPath
);
1786 SetErrorMode(iPrevErrMode
);
1789 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1792 /*************************************************************************
1793 * PathMatchSingleMaskA [internal]
1795 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1797 while (*name
&& *mask
&& *mask
!=';')
1803 if (PathMatchSingleMaskA(name
,mask
+1))
1804 return TRUE
; /* try substrings */
1809 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1812 name
= CharNextA(name
);
1813 mask
= CharNextA(mask
);
1818 while (*mask
== '*')
1820 if (!*mask
|| *mask
== ';')
1826 /*************************************************************************
1827 * PathMatchSingleMaskW [internal]
1829 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1831 while (*name
&& *mask
&& *mask
!= ';')
1837 if (PathMatchSingleMaskW(name
,mask
+1))
1838 return TRUE
; /* try substrings */
1843 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1851 while (*mask
== '*')
1853 if (!*mask
|| *mask
== ';')
1859 /*************************************************************************
1860 * PathMatchSpecA [SHLWAPI.@]
1862 * Determine if a path matches one or more search masks.
1865 * lpszPath [I] Path to check
1866 * lpszMask [I] Search mask(s)
1869 * TRUE If lpszPath is valid and is matched
1873 * Multiple search masks may be given if they are separated by ";". The
1874 * pattern "*.*" is treated specially in that it matches all paths (for
1875 * backwards compatibility with DOS).
1877 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1879 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1881 if (!lstrcmpA(lpszMask
, "*.*"))
1882 return TRUE
; /* Matches every path */
1886 while (*lpszMask
== ' ')
1887 lpszMask
++; /* Eat leading spaces */
1889 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1890 return TRUE
; /* Matches the current mask */
1892 while (*lpszMask
&& *lpszMask
!= ';')
1893 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1895 if (*lpszMask
== ';')
1901 /*************************************************************************
1902 * PathMatchSpecW [SHLWAPI.@]
1904 * See PathMatchSpecA.
1906 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1908 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1910 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1912 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1913 return TRUE
; /* Matches every path */
1917 while (*lpszMask
== ' ')
1918 lpszMask
++; /* Eat leading spaces */
1920 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1921 return TRUE
; /* Matches the current path */
1923 while (*lpszMask
&& *lpszMask
!= ';')
1924 lpszMask
++; /* masks separated by ';' */
1926 if (*lpszMask
== ';')
1932 /*************************************************************************
1933 * PathIsSameRootA [SHLWAPI.@]
1935 * Determine if two paths share the same root.
1938 * lpszPath1 [I] Source path
1939 * lpszPath2 [I] Path to compare with
1942 * TRUE If both paths are valid and share the same root.
1943 * FALSE If either path is invalid or the paths do not share the same root.
1945 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1950 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1952 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1955 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1956 if (lpszStart
- lpszPath1
> dwLen
)
1957 return FALSE
; /* Paths not common up to length of the root */
1961 /*************************************************************************
1962 * PathIsSameRootW [SHLWAPI.@]
1964 * See PathIsSameRootA.
1966 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1971 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1973 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1976 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1977 if (lpszStart
- lpszPath1
> dwLen
)
1978 return FALSE
; /* Paths not common up to length of the root */
1982 /*************************************************************************
1983 * PathIsContentTypeA [SHLWAPI.@]
1985 * Determine if a file is of a given registered content type.
1988 * lpszPath [I] File to check
1989 * lpszContentType [I] Content type to check for
1992 * TRUE If lpszPath is a given registered content type,
1996 * This function looks up the registered content type for lpszPath. If
1997 * a content type is registered, it is compared (case insensitively) to
1998 * lpszContentType. Only if this matches does the function succeed.
2000 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2004 char szBuff
[MAX_PATH
];
2006 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2008 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2009 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2010 REG_NONE
, szBuff
, &dwDummy
) &&
2011 !strcasecmp(lpszContentType
, szBuff
))
2018 /*************************************************************************
2019 * PathIsContentTypeW [SHLWAPI.@]
2021 * See PathIsContentTypeA.
2023 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2025 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2028 WCHAR szBuff
[MAX_PATH
];
2030 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2032 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2033 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2034 REG_NONE
, szBuff
, &dwDummy
) &&
2035 !strcmpiW(lpszContentType
, szBuff
))
2042 /*************************************************************************
2043 * PathIsFileSpecA [SHLWAPI.@]
2045 * Determine if a path is a file specification.
2048 * lpszPath [I] Path to check
2051 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2054 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2056 TRACE("(%s)\n", debugstr_a(lpszPath
));
2063 if (*lpszPath
== '\\' || *lpszPath
== ':')
2065 lpszPath
= CharNextA(lpszPath
);
2070 /*************************************************************************
2071 * PathIsFileSpecW [SHLWAPI.@]
2073 * See PathIsFileSpecA.
2075 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2077 TRACE("(%s)\n", debugstr_w(lpszPath
));
2084 if (*lpszPath
== '\\' || *lpszPath
== ':')
2091 /*************************************************************************
2092 * PathIsPrefixA [SHLWAPI.@]
2094 * Determine if a path is a prefix of another.
2097 * lpszPrefix [I] Prefix
2098 * lpszPath [I] Path to check
2101 * TRUE If lpszPath has lpszPrefix as its prefix,
2102 * FALSE If either path is NULL or lpszPrefix is not a prefix
2104 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2106 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2108 if (lpszPrefix
&& lpszPath
&&
2109 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2114 /*************************************************************************
2115 * PathIsPrefixW [SHLWAPI.@]
2117 * See PathIsPrefixA.
2119 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2121 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2123 if (lpszPrefix
&& lpszPath
&&
2124 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2129 /*************************************************************************
2130 * PathIsSystemFolderA [SHLWAPI.@]
2132 * Determine if a path or file attributes are a system folder.
2135 * lpszPath [I] Path to check.
2136 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2139 * TRUE If lpszPath or dwAttrib are a system folder.
2140 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2142 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2144 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2146 if (lpszPath
&& *lpszPath
)
2147 dwAttrib
= GetFileAttributesA(lpszPath
);
2149 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2150 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2155 /*************************************************************************
2156 * PathIsSystemFolderW [SHLWAPI.@]
2158 * See PathIsSystemFolderA.
2160 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2162 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2164 if (lpszPath
&& *lpszPath
)
2165 dwAttrib
= GetFileAttributesW(lpszPath
);
2167 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2168 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2173 /*************************************************************************
2174 * PathIsUNCA [SHLWAPI.@]
2176 * Determine if a path is in UNC format.
2179 * lpszPath [I] Path to check
2182 * TRUE: The path is UNC.
2183 * FALSE: The path is not UNC or is NULL.
2185 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2187 TRACE("(%s)\n",debugstr_a(lpszPath
));
2189 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2194 /*************************************************************************
2195 * PathIsUNCW [SHLWAPI.@]
2199 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2201 TRACE("(%s)\n",debugstr_w(lpszPath
));
2203 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2208 /*************************************************************************
2209 * PathIsUNCServerA [SHLWAPI.@]
2211 * Determine if a path is a UNC server name ("\\SHARENAME").
2214 * lpszPath [I] Path to check.
2217 * TRUE If lpszPath is a valid UNC server name.
2221 * This routine is bug compatible with Win32: Server names with a
2222 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2223 * Fixing this bug may break other shlwapi functions!
2225 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2227 TRACE("(%s)\n", debugstr_a(lpszPath
));
2229 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2233 if (*lpszPath
== '\\')
2235 lpszPath
= CharNextA(lpszPath
);
2242 /*************************************************************************
2243 * PathIsUNCServerW [SHLWAPI.@]
2245 * See PathIsUNCServerA.
2247 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2249 TRACE("(%s)\n", debugstr_w(lpszPath
));
2251 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2253 return !strchrW( lpszPath
+ 2, '\\' );
2258 /*************************************************************************
2259 * PathIsUNCServerShareA [SHLWAPI.@]
2261 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2264 * lpszPath [I] Path to check.
2267 * TRUE If lpszPath is a valid UNC server share.
2271 * This routine is bug compatible with Win32: Server shares with a
2272 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2273 * Fixing this bug may break other shlwapi functions!
2275 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2277 TRACE("(%s)\n", debugstr_a(lpszPath
));
2279 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2281 BOOL bSeenSlash
= FALSE
;
2284 if (*lpszPath
== '\\')
2290 lpszPath
= CharNextA(lpszPath
);
2297 /*************************************************************************
2298 * PathIsUNCServerShareW [SHLWAPI.@]
2300 * See PathIsUNCServerShareA.
2302 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2304 TRACE("(%s)\n", debugstr_w(lpszPath
));
2306 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2308 BOOL bSeenSlash
= FALSE
;
2311 if (*lpszPath
== '\\')
2324 /*************************************************************************
2325 * PathCanonicalizeA [SHLWAPI.@]
2327 * Convert a path to its canonical form.
2330 * lpszBuf [O] Output path
2331 * lpszPath [I] Path to canonicalize
2334 * Success: TRUE. lpszBuf contains the output path,
2335 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2337 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2341 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2346 if (!lpszBuf
|| !lpszPath
)
2347 SetLastError(ERROR_INVALID_PARAMETER
);
2350 WCHAR szPath
[MAX_PATH
];
2351 WCHAR szBuff
[MAX_PATH
];
2352 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2355 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2358 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2359 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2365 /*************************************************************************
2366 * PathCanonicalizeW [SHLWAPI.@]
2368 * See PathCanonicalizeA.
2370 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2372 LPWSTR lpszDst
= lpszBuf
;
2373 LPCWSTR lpszSrc
= lpszPath
;
2375 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2380 if (!lpszBuf
|| !lpszPath
)
2382 SetLastError(ERROR_INVALID_PARAMETER
);
2393 /* Copy path root */
2394 if (*lpszSrc
== '\\')
2396 *lpszDst
++ = *lpszSrc
++;
2398 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2401 *lpszDst
++ = *lpszSrc
++;
2402 *lpszDst
++ = *lpszSrc
++;
2403 if (*lpszSrc
== '\\')
2404 *lpszDst
++ = *lpszSrc
++;
2407 /* Canonicalize the rest of the path */
2410 if (*lpszSrc
== '.')
2412 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2414 lpszSrc
+= 2; /* Skip .\ */
2416 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2418 /* \.. backs up a directory, over the root if it has no \ following X:.
2419 * .. is ignored if it would remove a UNC server name or initial \\
2421 if (lpszDst
!= lpszBuf
)
2423 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2424 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2425 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2427 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2430 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2432 if (*lpszDst
== '\\')
2433 lpszDst
++; /* Reset to last '\' */
2435 lpszDst
= lpszBuf
; /* Start path again from new root */
2437 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2440 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2442 if (lpszDst
== lpszBuf
)
2448 lpszSrc
+= 2; /* Skip .. in src path */
2451 *lpszDst
++ = *lpszSrc
++;
2454 *lpszDst
++ = *lpszSrc
++;
2456 /* Append \ to naked drive specs */
2457 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2463 /*************************************************************************
2464 * PathFindNextComponentA [SHLWAPI.@]
2466 * Find the next component in a path.
2469 * lpszPath [I] Path to find next component in
2472 * Success: A pointer to the next component, or the end of the string.
2473 * Failure: NULL, If lpszPath is invalid
2476 * A 'component' is either a backslash character (\) or UNC marker (\\).
2477 * Because of this, relative paths (e.g "c:foo") are regarded as having
2478 * only one component.
2480 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2484 TRACE("(%s)\n", debugstr_a(lpszPath
));
2486 if(!lpszPath
|| !*lpszPath
)
2489 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2491 if (lpszSlash
[1] == '\\')
2493 return lpszSlash
+ 1;
2495 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2498 /*************************************************************************
2499 * PathFindNextComponentW [SHLWAPI.@]
2501 * See PathFindNextComponentA.
2503 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2507 TRACE("(%s)\n", debugstr_w(lpszPath
));
2509 if(!lpszPath
|| !*lpszPath
)
2512 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2514 if (lpszSlash
[1] == '\\')
2516 return lpszSlash
+ 1;
2518 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2521 /*************************************************************************
2522 * PathAddExtensionA [SHLWAPI.@]
2524 * Add a file extension to a path
2527 * lpszPath [I/O] Path to add extension to
2528 * lpszExtension [I] Extension to add to lpszPath
2531 * TRUE If the path was modified,
2532 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2533 * extension already, or the new path length is too big.
2536 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2537 * does not do this, so the behaviour was removed.
2539 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2543 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2545 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2548 dwLen
= strlen(lpszPath
);
2550 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2553 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2557 /*************************************************************************
2558 * PathAddExtensionW [SHLWAPI.@]
2560 * See PathAddExtensionA.
2562 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2566 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2568 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2571 dwLen
= strlenW(lpszPath
);
2573 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2576 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2580 /*************************************************************************
2581 * PathMakePrettyA [SHLWAPI.@]
2583 * Convert an uppercase DOS filename into lowercase.
2586 * lpszPath [I/O] Path to convert.
2589 * TRUE If the path was an uppercase DOS path and was converted,
2592 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2594 LPSTR pszIter
= lpszPath
;
2596 TRACE("(%s)\n", debugstr_a(lpszPath
));
2605 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2606 return FALSE
; /* Not DOS path */
2609 pszIter
= lpszPath
+ 1;
2612 *pszIter
= tolower(*pszIter
);
2619 /*************************************************************************
2620 * PathMakePrettyW [SHLWAPI.@]
2622 * See PathMakePrettyA.
2624 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2626 LPWSTR pszIter
= lpszPath
;
2628 TRACE("(%s)\n", debugstr_w(lpszPath
));
2637 if (islowerW(*pszIter
))
2638 return FALSE
; /* Not DOS path */
2641 pszIter
= lpszPath
+ 1;
2644 *pszIter
= tolowerW(*pszIter
);
2651 /*************************************************************************
2652 * PathCommonPrefixA [SHLWAPI.@]
2654 * Determine the length of the common prefix between two paths.
2657 * lpszFile1 [I] First path for comparison
2658 * lpszFile2 [I] Second path for comparison
2659 * achPath [O] Destination for common prefix string
2662 * The length of the common prefix. This is 0 if there is no common
2663 * prefix between the paths or if any parameters are invalid. If the prefix
2664 * is non-zero and achPath is not NULL, achPath is filled with the common
2665 * part of the prefix and NUL terminated.
2668 * A common prefix of 2 is always returned as 3. It is thus possible for
2669 * the length returned to be invalid (i.e. Longer than one or both of the
2670 * strings given as parameters). This Win32 behaviour has been implemented
2671 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2672 * To work around this when using this function, always check that the byte
2673 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2675 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2678 LPCSTR lpszIter1
= lpszFile1
;
2679 LPCSTR lpszIter2
= lpszFile2
;
2681 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2686 if (!lpszFile1
|| !lpszFile2
)
2689 /* Handle roots first */
2690 if (PathIsUNCA(lpszFile1
))
2692 if (!PathIsUNCA(lpszFile2
))
2697 else if (PathIsUNCA(lpszFile2
))
2698 return 0; /* Know already lpszFile1 is not UNC */
2703 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2704 (!*lpszIter2
|| *lpszIter2
== '\\'))
2705 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2707 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2708 break; /* Strings differ at this point */
2715 iLen
++; /* Feature/Bug compatible with Win32 */
2717 if (iLen
&& achPath
)
2719 memcpy(achPath
,lpszFile1
,iLen
);
2720 achPath
[iLen
] = '\0';
2725 /*************************************************************************
2726 * PathCommonPrefixW [SHLWAPI.@]
2728 * See PathCommonPrefixA.
2730 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2733 LPCWSTR lpszIter1
= lpszFile1
;
2734 LPCWSTR lpszIter2
= lpszFile2
;
2736 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2741 if (!lpszFile1
|| !lpszFile2
)
2744 /* Handle roots first */
2745 if (PathIsUNCW(lpszFile1
))
2747 if (!PathIsUNCW(lpszFile2
))
2752 else if (PathIsUNCW(lpszFile2
))
2753 return 0; /* Know already lpszFile1 is not UNC */
2758 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2759 (!*lpszIter2
|| *lpszIter2
== '\\'))
2760 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2762 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2763 break; /* Strings differ at this point */
2770 iLen
++; /* Feature/Bug compatible with Win32 */
2772 if (iLen
&& achPath
)
2774 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2775 achPath
[iLen
] = '\0';
2780 /*************************************************************************
2781 * PathCompactPathA [SHLWAPI.@]
2783 * Make a path fit into a given width when printed to a DC.
2786 * hDc [I] Destination DC
2787 * lpszPath [I/O] Path to be printed to hDc
2788 * dx [I] Desired width
2791 * TRUE If the path was modified/went well.
2794 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2798 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2802 WCHAR szPath
[MAX_PATH
];
2803 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2804 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2805 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2810 /*************************************************************************
2811 * PathCompactPathW [SHLWAPI.@]
2813 * See PathCompactPathA.
2815 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2817 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2820 WCHAR buff
[MAX_PATH
];
2824 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2830 hdc
= hDC
= GetDC(0);
2832 /* Get the length of the whole path */
2833 dwLen
= strlenW(lpszPath
);
2834 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2836 if ((UINT
)size
.cx
> dx
)
2838 /* Path too big, must reduce it */
2840 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2842 sFile
= PathFindFileNameW(lpszPath
);
2843 if (sFile
!= lpszPath
) sFile
--;
2845 /* Get the size of ellipses */
2846 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2847 dwEllipsesLen
= size
.cx
;
2848 /* Get the size of the file name */
2849 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2850 dwPathLen
= size
.cx
;
2852 if (sFile
!= lpszPath
)
2854 LPWSTR sPath
= sFile
;
2855 BOOL bEllipses
= FALSE
;
2857 /* The path includes a file name. Include as much of the path prior to
2858 * the file name as possible, allowing for the ellipses, e.g:
2859 * c:\some very long path\filename ==> c:\some v...\filename
2861 lstrcpynW(buff
, sFile
, MAX_PATH
);
2865 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2867 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2868 dwTotalLen
+= size
.cx
;
2869 if (dwTotalLen
<= dx
)
2877 } while (sPath
> lpszPath
);
2879 if (sPath
> lpszPath
)
2883 strcpyW(sPath
, szEllipses
);
2884 strcpyW(sPath
+3, buff
);
2889 strcpyW(lpszPath
, szEllipses
);
2890 strcpyW(lpszPath
+3, buff
);
2895 /* Trim the path by adding ellipses to the end, e.g:
2896 * A very long file name.txt ==> A very...
2898 dwLen
= strlenW(lpszPath
);
2900 if (dwLen
> MAX_PATH
- 3)
2901 dwLen
= MAX_PATH
- 3;
2902 lstrcpynW(buff
, sFile
, dwLen
);
2906 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2907 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2911 DWORD dwWritten
= 0;
2913 dwEllipsesLen
/= 3; /* Size of a single '.' */
2915 /* Write as much of the Ellipses string as possible */
2916 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2919 dwWritten
+= dwEllipsesLen
;
2927 strcpyW(buff
+ dwLen
, szEllipses
);
2928 strcpyW(lpszPath
, buff
);
2939 /*************************************************************************
2940 * PathGetCharTypeA [SHLWAPI.@]
2942 * Categorise a character from a file path.
2945 * ch [I] Character to get the type of
2948 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2950 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2952 return PathGetCharTypeW(ch
);
2955 /*************************************************************************
2956 * PathGetCharTypeW [SHLWAPI.@]
2958 * See PathGetCharTypeA.
2960 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2964 TRACE("(%d)\n", ch
);
2966 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2967 ch
== '"' || ch
== '|' || ch
== '/')
2968 flags
= GCT_INVALID
; /* Invalid */
2969 else if (ch
== '*' || ch
=='?')
2970 flags
= GCT_WILD
; /* Wildchars */
2971 else if ((ch
== '\\') || (ch
== ':'))
2972 return GCT_SEPARATOR
; /* Path separators */
2977 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2978 ch
== '.' || ch
== '@' || ch
== '^' ||
2979 ch
== '\'' || ch
== 130 || ch
== '`')
2980 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2983 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2984 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2989 /*************************************************************************
2990 * SHLWAPI_UseSystemForSystemFolders
2992 * Internal helper for PathMakeSystemFolderW.
2994 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
2996 static BOOL bCheckedReg
= FALSE
;
2997 static BOOL bUseSystemForSystemFolders
= FALSE
;
3003 /* Key tells Win what file attributes to use on system folders */
3004 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3005 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3006 "UseSystemForSystemFolders", 0, 0, 0))
3007 bUseSystemForSystemFolders
= TRUE
;
3009 return bUseSystemForSystemFolders
;
3012 /*************************************************************************
3013 * PathMakeSystemFolderA [SHLWAPI.@]
3015 * Set system folder attribute for a path.
3018 * lpszPath [I] The path to turn into a system folder
3021 * TRUE If the path was changed to/already was a system folder
3022 * FALSE If the path is invalid or SetFileAttributesA() fails
3024 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3028 TRACE("(%s)\n", debugstr_a(lpszPath
));
3030 if (lpszPath
&& *lpszPath
)
3032 WCHAR szPath
[MAX_PATH
];
3033 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3034 bRet
= PathMakeSystemFolderW(szPath
);
3039 /*************************************************************************
3040 * PathMakeSystemFolderW [SHLWAPI.@]
3042 * See PathMakeSystemFolderA.
3044 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3046 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3047 WCHAR buff
[MAX_PATH
];
3049 TRACE("(%s)\n", debugstr_w(lpszPath
));
3051 if (!lpszPath
|| !*lpszPath
)
3054 /* If the directory is already a system directory, don't do anything */
3055 GetSystemDirectoryW(buff
, MAX_PATH
);
3056 if (!strcmpW(buff
, lpszPath
))
3059 GetWindowsDirectoryW(buff
, MAX_PATH
);
3060 if (!strcmpW(buff
, lpszPath
))
3063 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3064 if (SHLWAPI_UseSystemForSystemFolders())
3065 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3067 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3070 /* Change file attributes to system attributes */
3071 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3072 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3075 /*************************************************************************
3076 * PathRenameExtensionA [SHLWAPI.@]
3078 * Swap the file extension in a path with another extension.
3081 * lpszPath [I/O] Path to swap the extension in
3082 * lpszExt [I] The new extension
3085 * TRUE if lpszPath was modified,
3086 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3088 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3090 LPSTR lpszExtension
;
3092 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3094 lpszExtension
= PathFindExtensionA(lpszPath
);
3096 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3099 strcpy(lpszExtension
, lpszExt
);
3103 /*************************************************************************
3104 * PathRenameExtensionW [SHLWAPI.@]
3106 * See PathRenameExtensionA.
3108 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3110 LPWSTR lpszExtension
;
3112 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3114 lpszExtension
= PathFindExtensionW(lpszPath
);
3116 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3119 strcpyW(lpszExtension
, lpszExt
);
3123 /*************************************************************************
3124 * PathSearchAndQualifyA [SHLWAPI.@]
3126 * Determine if a given path is correct and fully qualified.
3129 * lpszPath [I] Path to check
3130 * lpszBuf [O] Output for correct path
3131 * cchBuf [I] Size of lpszBuf
3136 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3138 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3140 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3142 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3145 /*************************************************************************
3146 * PathSearchAndQualifyW [SHLWAPI.@]
3148 * See PathSearchAndQualifyA.
3150 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3152 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3154 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3156 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3159 /*************************************************************************
3160 * PathSkipRootA [SHLWAPI.@]
3162 * Return the portion of a path following the drive letter or mount point.
3165 * lpszPath [I] The path to skip on
3168 * Success: A pointer to the next character after the root.
3169 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3171 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3173 TRACE("(%s)\n", debugstr_a(lpszPath
));
3175 if (!lpszPath
|| !*lpszPath
)
3178 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3180 /* Network share: skip share server and mount point */
3182 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3183 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3185 return (LPSTR
)lpszPath
;
3188 if (IsDBCSLeadByte(*lpszPath
))
3192 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3193 return (LPSTR
)lpszPath
+ 3;
3197 /*************************************************************************
3198 * PathSkipRootW [SHLWAPI.@]
3200 * See PathSkipRootA.
3202 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3204 TRACE("(%s)\n", debugstr_w(lpszPath
));
3206 if (!lpszPath
|| !*lpszPath
)
3209 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3211 /* Network share: skip share server and mount point */
3213 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3214 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3216 return (LPWSTR
)lpszPath
;
3220 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3221 return (LPWSTR
)lpszPath
+ 3;
3225 /*************************************************************************
3226 * PathCreateFromUrlA [SHLWAPI.@]
3228 * See PathCreateFromUrlW
3230 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3231 LPDWORD pcchPath
, DWORD dwReserved
)
3233 WCHAR bufW
[MAX_PATH
];
3234 WCHAR
*pathW
= bufW
;
3235 UNICODE_STRING urlW
;
3237 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3239 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3240 return E_INVALIDARG
;
3241 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3242 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3243 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3246 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3247 if(*pcchPath
> lenA
) {
3248 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3252 *pcchPath
= lenA
+ 1;
3256 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3257 RtlFreeUnicodeString(&urlW
);
3261 /*************************************************************************
3262 * PathCreateFromUrlW [SHLWAPI.@]
3264 * Create a path from a URL
3267 * lpszUrl [I] URL to convert into a path
3268 * lpszPath [O] Output buffer for the resulting Path
3269 * pcchPath [I] Length of lpszPath
3270 * dwFlags [I] Flags controlling the conversion
3273 * Success: S_OK. lpszPath contains the URL in path format,
3274 * Failure: An HRESULT error code such as E_INVALIDARG.
3276 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3277 LPDWORD pcchPath
, DWORD dwReserved
)
3279 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3284 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3286 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3287 return E_INVALIDARG
;
3290 if (strncmpW(pszUrl
, file_colon
, 5))
3291 return E_INVALIDARG
;
3294 while(*pszUrl
== '/' || *pszUrl
== '\\') {
3299 if(isalphaW(*pszUrl
) && (pszUrl
[1] == ':' || pszUrl
[1] == '|') && (pszUrl
[2] == '/' || pszUrl
[2] == '\\'))
3313 hr
= UrlUnescapeW((LPWSTR
)pszUrl
, pszPath
, pcchPath
, 0);
3314 if(hr
!= S_OK
) return hr
;
3316 for(ptr
= pszPath
; *ptr
; ptr
++)
3317 if(*ptr
== '/') *ptr
= '\\';
3319 while(*pszPath
== '\\')
3322 if(isalphaW(*pszPath
) && pszPath
[1] == '|' && pszPath
[2] == '\\') /* c|\ -> c:\ */
3325 if(nslashes
== 2 && (ptr
= strchrW(pszPath
, '\\'))) { /* \\host\c:\ -> \\hostc:\ */
3327 if(isalphaW(*ptr
) && (ptr
[1] == ':' || ptr
[1] == '|') && ptr
[2] == '\\') {
3328 memmove(ptr
- 1, ptr
, (strlenW(ptr
) + 1) * sizeof(WCHAR
));
3333 TRACE("Returning %s\n",debugstr_w(pszPath
));
3338 /*************************************************************************
3339 * PathRelativePathToA [SHLWAPI.@]
3341 * Create a relative path from one path to another.
3344 * lpszPath [O] Destination for relative path
3345 * lpszFrom [I] Source path
3346 * dwAttrFrom [I] File attribute of source path
3347 * lpszTo [I] Destination path
3348 * dwAttrTo [I] File attributes of destination path
3351 * TRUE If a relative path can be formed. lpszPath contains the new path
3352 * FALSE If the paths are not relative or any parameters are invalid
3355 * lpszTo should be at least MAX_PATH in length.
3357 * Calling this function with relative paths for lpszFrom or lpszTo may
3358 * give erroneous results.
3360 * The Win32 version of this function contains a bug where the lpszTo string
3361 * may be referenced 1 byte beyond the end of the string. As a result random
3362 * garbage may be written to the output path, depending on what lies beyond
3363 * the last byte of the string. This bug occurs because of the behaviour of
3364 * PathCommonPrefix() (see notes for that function), and no workaround seems
3365 * possible with Win32.
3367 * This bug has been fixed here, so for example the relative path from "\\"
3368 * to "\\" is correctly determined as "." in this implementation.
3370 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3371 LPCSTR lpszTo
, DWORD dwAttrTo
)
3375 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3376 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3378 if(lpszPath
&& lpszFrom
&& lpszTo
)
3380 WCHAR szPath
[MAX_PATH
];
3381 WCHAR szFrom
[MAX_PATH
];
3382 WCHAR szTo
[MAX_PATH
];
3383 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3384 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3385 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3386 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3391 /*************************************************************************
3392 * PathRelativePathToW [SHLWAPI.@]
3394 * See PathRelativePathToA.
3396 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3397 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3399 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3400 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3401 WCHAR szFrom
[MAX_PATH
];
3402 WCHAR szTo
[MAX_PATH
];
3405 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3406 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3408 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3412 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3413 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3415 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3416 PathRemoveFileSpecW(szFrom
);
3417 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3418 PathRemoveFileSpecW(szTo
);
3420 /* Paths can only be relative if they have a common root */
3421 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3424 /* Strip off lpszFrom components to the root, by adding "..\" */
3425 lpszFrom
= szFrom
+ dwLen
;
3431 if (*lpszFrom
== '\\')
3436 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3437 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3440 /* From the root add the components of lpszTo */
3442 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3445 if (*lpszTo
&& lpszTo
[-1])
3447 if (*lpszTo
!= '\\')
3449 dwLen
= strlenW(lpszPath
);
3450 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3455 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3460 /*************************************************************************
3461 * PathUnmakeSystemFolderA [SHLWAPI.@]
3463 * Remove the system folder attributes from a path.
3466 * lpszPath [I] The path to remove attributes from
3470 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3471 * SetFileAttributesA() fails.
3473 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3477 TRACE("(%s)\n", debugstr_a(lpszPath
));
3479 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3480 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3483 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3484 return SetFileAttributesA(lpszPath
, dwAttr
);
3487 /*************************************************************************
3488 * PathUnmakeSystemFolderW [SHLWAPI.@]
3490 * See PathUnmakeSystemFolderA.
3492 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3496 TRACE("(%s)\n", debugstr_w(lpszPath
));
3498 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3499 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3502 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3503 return SetFileAttributesW(lpszPath
, dwAttr
);
3507 /*************************************************************************
3508 * PathSetDlgItemPathA [SHLWAPI.@]
3510 * Set the text of a dialog item to a path, shrinking the path to fit
3511 * if it is too big for the item.
3514 * hDlg [I] Dialog handle
3515 * id [I] ID of item in the dialog
3516 * lpszPath [I] Path to set as the items text
3522 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3523 * window text is erased).
3525 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3527 WCHAR szPath
[MAX_PATH
];
3529 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3532 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3535 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3538 /*************************************************************************
3539 * PathSetDlgItemPathW [SHLWAPI.@]
3541 * See PathSetDlgItemPathA.
3543 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3545 WCHAR path
[MAX_PATH
+ 1];
3551 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3553 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3557 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3561 GetClientRect(hwItem
, &rect
);
3563 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3567 PathCompactPathW(hdc
, path
, rect
.right
);
3568 SelectObject(hdc
, hPrevObj
);
3571 ReleaseDC(hDlg
, hdc
);
3572 SetWindowTextW(hwItem
, path
);
3575 /*************************************************************************
3576 * PathIsNetworkPathA [SHLWAPI.@]
3578 * Determine if the given path is a network path.
3581 * lpszPath [I] Path to check
3584 * TRUE If lpszPath is a UNC share or mapped network drive, or
3585 * FALSE If lpszPath is a local drive or cannot be determined
3587 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3591 TRACE("(%s)\n",debugstr_a(lpszPath
));
3595 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3597 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3598 if (dwDriveNum
== -1)
3600 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3601 return pIsNetDrive(dwDriveNum
);
3604 /*************************************************************************
3605 * PathIsNetworkPathW [SHLWAPI.@]
3607 * See PathIsNetworkPathA.
3609 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3613 TRACE("(%s)\n", debugstr_w(lpszPath
));
3617 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3619 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3620 if (dwDriveNum
== -1)
3622 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3623 return pIsNetDrive(dwDriveNum
);
3626 /*************************************************************************
3627 * PathIsLFNFileSpecA [SHLWAPI.@]
3629 * Determine if the given path is a long file name
3632 * lpszPath [I] Path to check
3635 * TRUE If path is a long file name,
3636 * FALSE If path is a valid DOS short file name
3638 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3640 DWORD dwNameLen
= 0, dwExtLen
= 0;
3642 TRACE("(%s)\n",debugstr_a(lpszPath
));
3649 if (*lpszPath
== ' ')
3650 return TRUE
; /* DOS names cannot have spaces */
3651 if (*lpszPath
== '.')
3654 return TRUE
; /* DOS names have only one dot */
3661 return TRUE
; /* DOS extensions are <= 3 chars*/
3667 return TRUE
; /* DOS names are <= 8 chars */
3669 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3671 return FALSE
; /* Valid DOS path */
3674 /*************************************************************************
3675 * PathIsLFNFileSpecW [SHLWAPI.@]
3677 * See PathIsLFNFileSpecA.
3679 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3681 DWORD dwNameLen
= 0, dwExtLen
= 0;
3683 TRACE("(%s)\n",debugstr_w(lpszPath
));
3690 if (*lpszPath
== ' ')
3691 return TRUE
; /* DOS names cannot have spaces */
3692 if (*lpszPath
== '.')
3695 return TRUE
; /* DOS names have only one dot */
3702 return TRUE
; /* DOS extensions are <= 3 chars*/
3708 return TRUE
; /* DOS names are <= 8 chars */
3712 return FALSE
; /* Valid DOS path */
3715 /*************************************************************************
3716 * PathIsDirectoryEmptyA [SHLWAPI.@]
3718 * Determine if a given directory is empty.
3721 * lpszPath [I] Directory to check
3724 * TRUE If the directory exists and contains no files,
3727 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3731 TRACE("(%s)\n",debugstr_a(lpszPath
));
3735 WCHAR szPath
[MAX_PATH
];
3736 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3737 bRet
= PathIsDirectoryEmptyW(szPath
);
3742 /*************************************************************************
3743 * PathIsDirectoryEmptyW [SHLWAPI.@]
3745 * See PathIsDirectoryEmptyA.
3747 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3749 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3750 WCHAR szSearch
[MAX_PATH
];
3753 BOOL retVal
= FALSE
;
3754 WIN32_FIND_DATAW find_data
;
3756 TRACE("(%s)\n",debugstr_w(lpszPath
));
3758 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3761 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3762 PathAddBackslashW(szSearch
);
3763 dwLen
= strlenW(szSearch
);
3764 if (dwLen
> MAX_PATH
- 4)
3767 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3768 hfind
= FindFirstFileW(szSearch
, &find_data
);
3770 if (hfind
!= INVALID_HANDLE_VALUE
&&
3771 find_data
.cFileName
[0] == '.' &&
3772 find_data
.cFileName
[1] == '.')
3774 /* The only directory entry should be the parent */
3775 if (!FindNextFileW(hfind
, &find_data
))
3783 /*************************************************************************
3784 * PathFindSuffixArrayA [SHLWAPI.@]
3786 * Find a suffix string in an array of suffix strings
3789 * lpszSuffix [I] Suffix string to search for
3790 * lppszArray [I] Array of suffix strings to search
3791 * dwCount [I] Number of elements in lppszArray
3794 * Success: The index of the position of lpszSuffix in lppszArray
3795 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3798 * The search is case sensitive.
3799 * The match is made against the end of the suffix string, so for example:
3800 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3802 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3807 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3809 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3811 dwLen
= strlen(lpszSuffix
);
3813 while (dwRet
< dwCount
)
3815 size_t dwCompareLen
= strlen(*lppszArray
);
3816 if (dwCompareLen
< dwLen
)
3818 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3819 return *lppszArray
; /* Found */
3828 /*************************************************************************
3829 * PathFindSuffixArrayW [SHLWAPI.@]
3831 * See PathFindSuffixArrayA.
3833 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3838 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3840 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3842 dwLen
= strlenW(lpszSuffix
);
3844 while (dwRet
< dwCount
)
3846 size_t dwCompareLen
= strlenW(*lppszArray
);
3847 if (dwCompareLen
< dwLen
)
3849 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3850 return *lppszArray
; /* Found */
3859 /*************************************************************************
3860 * PathUndecorateA [SHLWAPI.@]
3862 * Undecorate a file path
3865 * lpszPath [I/O] Path to remove any decoration from
3871 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3873 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3875 TRACE("(%s)\n",debugstr_a(lpszPath
));
3879 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3880 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3882 LPSTR lpszSkip
= lpszExt
- 2;
3883 if (*lpszSkip
== '[')
3884 lpszSkip
++; /* [] (no number) */
3886 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3888 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3890 /* remove the [n] */
3893 *lpszSkip
++ = *lpszExt
++;
3900 /*************************************************************************
3901 * PathUndecorateW [SHLWAPI.@]
3903 * See PathUndecorateA.
3905 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3907 TRACE("(%s)\n",debugstr_w(lpszPath
));
3911 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3912 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3914 LPWSTR lpszSkip
= lpszExt
- 2;
3915 if (*lpszSkip
== '[')
3916 lpszSkip
++; /* [] (no number) */
3918 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3920 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3922 /* remove the [n] */
3925 *lpszSkip
++ = *lpszExt
++;
3932 /*************************************************************************
3933 * PathUnExpandEnvStringsA [SHLWAPI.@]
3935 * Substitute folder names in a path with their corresponding environment
3939 * pszPath [I] Buffer containing the path to unexpand.
3940 * pszBuf [O] Buffer to receive the unexpanded path.
3941 * cchBuf [I] Size of pszBuf in characters.
3947 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR pszPath
, LPSTR pszBuf
, UINT cchBuf
)
3949 FIXME("(%s,%s,0x%08x)\n", debugstr_a(pszPath
), debugstr_a(pszBuf
), cchBuf
);
3953 /*************************************************************************
3954 * PathUnExpandEnvStringsW [SHLWAPI.@]
3956 * Unicode version of PathUnExpandEnvStringsA.
3958 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR pszPath
, LPWSTR pszBuf
, UINT cchBuf
)
3960 FIXME("(%s,%s,0x%08x)\n", debugstr_w(pszPath
), debugstr_w(pszBuf
), cchBuf
);
3964 /*************************************************************************
3967 * Find localised or default web content in "%WINDOWS%\web\".
3970 * lpszFile [I] File name containing content to look for
3971 * lpszPath [O] Buffer to contain the full path to the file
3972 * dwPathLen [I] Length of lpszPath
3975 * Success: S_OK. lpszPath contains the full path to the content.
3976 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
3978 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
3980 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
3983 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
3985 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
3987 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
3988 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
3992 /*************************************************************************
3995 * Unicode version of SHGetWebFolderFilePathA.
3997 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
3999 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4000 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4001 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4002 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4003 DWORD dwLen
, dwFileLen
;
4004 LANGID lidSystem
, lidUser
;
4006 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4008 /* Get base directory for web content */
4009 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4010 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4013 dwFileLen
= strlenW(lpszFile
);
4015 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4016 return E_FAIL
; /* lpszPath too short */
4018 strcpyW(lpszPath
+dwLen
, szWeb
);
4020 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4022 lidSystem
= GetSystemDefaultUILanguage();
4023 lidUser
= GetUserDefaultUILanguage();
4025 if (lidSystem
!= lidUser
)
4027 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4029 /* Use localised content in the users UI language if present */
4030 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4031 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4032 if (PathFileExistsW(lpszPath
))
4037 /* Fall back to OS default installed content */
4038 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4039 if (PathFileExistsW(lpszPath
))
4044 #define PATH_CHAR_CLASS_LETTER 0x00000001
4045 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4046 #define PATH_CHAR_CLASS_DOT 0x00000004
4047 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4048 #define PATH_CHAR_CLASS_COLON 0x00000010
4049 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4050 #define PATH_CHAR_CLASS_COMMA 0x00000040
4051 #define PATH_CHAR_CLASS_SPACE 0x00000080
4052 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4053 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4055 #define PATH_CHAR_CLASS_INVALID 0x00000000
4056 #define PATH_CHAR_CLASS_ANY 0xffffffff
4058 static const DWORD SHELL_charclass
[] =
4060 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4061 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4062 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4063 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4064 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4065 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4066 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4067 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4068 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4069 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4070 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4071 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4072 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4073 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4074 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4075 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4076 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4077 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4078 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4079 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4080 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4081 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4082 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4083 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4084 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4085 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4086 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4087 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4088 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4089 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4090 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4091 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4092 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4093 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4094 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4095 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4096 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4097 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4098 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4099 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4100 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4101 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4102 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4103 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4104 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4105 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4106 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4107 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4108 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4109 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4110 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4111 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4112 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4113 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4114 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4115 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4116 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4117 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4118 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4119 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4120 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4121 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4122 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4123 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4126 /*************************************************************************
4129 * Check if an ASCII char is of a certain class
4131 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4133 if ((unsigned)c
> 0x7e)
4134 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4136 return class & SHELL_charclass
[(unsigned)c
];
4139 /*************************************************************************
4142 * Check if a Unicode char is of a certain class
4144 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4147 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4149 return class & SHELL_charclass
[c
];