4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2001, 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* Get a function pointer from a DLL handle */
25 #define GET_FUNC(func, module, name, fail) \
28 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
29 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
30 if (!func) return fail; \
34 /* DLL handles for late bound calls */
35 static HMODULE SHLWAPI_hshell32
;
37 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
38 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
39 static fnpIsNetDrive pIsNetDrive
;
41 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
43 static inline WCHAR
* heap_strdupAtoW(LPCSTR str
)
49 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
50 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
52 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
58 /*************************************************************************
59 * PathAppendA [SHLWAPI.@]
61 * Append one path to another.
64 * lpszPath [I/O] Initial part of path, and destination for output
65 * lpszAppend [I] Path to append
68 * Success: TRUE. lpszPath contains the newly created path.
69 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
72 * lpszAppend must contain at least one backslash ('\') if not NULL.
73 * Because PathCombineA() is used to join the paths, the resulting
74 * path is also canonicalized.
76 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
78 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
80 if (lpszPath
&& lpszAppend
)
82 if (!PathIsUNCA(lpszAppend
))
83 while (*lpszAppend
== '\\')
85 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
91 /*************************************************************************
92 * PathAppendW [SHLWAPI.@]
96 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
98 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
100 if (lpszPath
&& lpszAppend
)
102 if (!PathIsUNCW(lpszAppend
))
103 while (*lpszAppend
== '\\')
105 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
111 /*************************************************************************
112 * PathCombineA [SHLWAPI.@]
114 * Combine two paths together.
117 * lpszDest [O] Destination for combined path
118 * lpszDir [I] Directory path
119 * lpszFile [I] File path
122 * Success: The output path
123 * Failure: NULL, if inputs are invalid.
126 * lpszDest should be at least MAX_PATH in size, and may point to the same
127 * memory location as lpszDir. The combined path is canonicalised.
129 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
131 WCHAR szDest
[MAX_PATH
];
132 WCHAR szDir
[MAX_PATH
];
133 WCHAR szFile
[MAX_PATH
];
134 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
136 /* Invalid parameters */
139 if (!lpszDir
&& !lpszFile
)
146 MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
);
148 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
150 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
151 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
158 /*************************************************************************
159 * PathCombineW [SHLWAPI.@]
163 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
165 WCHAR szTemp
[MAX_PATH
];
166 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
168 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
170 /* Invalid parameters */
173 if (!lpszDir
&& !lpszFile
)
179 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
182 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
184 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
186 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
189 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
202 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
205 PathStripToRootW(szTemp
);
206 lpszFile
++; /* Skip '\' */
208 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
213 strcatW(szTemp
, lpszFile
);
216 PathCanonicalizeW(lpszDest
, szTemp
);
220 /*************************************************************************
221 * PathAddBackslashA [SHLWAPI.@]
223 * Append a backslash ('\') to a path if one doesn't exist.
226 * lpszPath [I/O] The path to append a backslash to.
229 * Success: The position of the last backslash in the path.
230 * Failure: NULL, if lpszPath is NULL or the path is too large.
232 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
235 LPSTR prev
= lpszPath
;
237 TRACE("(%s)\n",debugstr_a(lpszPath
));
239 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
245 lpszPath
= CharNextA(prev
);
258 /*************************************************************************
259 * PathAddBackslashW [SHLWAPI.@]
261 * See PathAddBackslashA.
263 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
267 TRACE("(%s)\n",debugstr_w(lpszPath
));
269 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
275 if (lpszPath
[-1] != '\\')
284 /*************************************************************************
285 * PathBuildRootA [SHLWAPI.@]
287 * Create a root drive string (e.g. "A:\") from a drive number.
290 * lpszPath [O] Destination for the drive string
296 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
298 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
300 TRACE("(%p,%d)\n", lpszPath
, drive
);
302 if (lpszPath
&& drive
>= 0 && drive
< 26)
304 lpszPath
[0] = 'A' + drive
;
312 /*************************************************************************
313 * PathBuildRootW [SHLWAPI.@]
315 * See PathBuildRootA.
317 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
319 TRACE("(%p,%d)\n", lpszPath
, drive
);
321 if (lpszPath
&& drive
>= 0 && drive
< 26)
323 lpszPath
[0] = 'A' + drive
;
331 /*************************************************************************
332 * PathFindFileNameA [SHLWAPI.@]
334 * Locate the start of the file name in a path
337 * lpszPath [I] Path to search
340 * A pointer to the first character of the file name
342 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
344 LPCSTR lastSlash
= lpszPath
;
346 TRACE("(%s)\n",debugstr_a(lpszPath
));
348 while (lpszPath
&& *lpszPath
)
350 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
351 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
352 lastSlash
= lpszPath
+ 1;
353 lpszPath
= CharNextA(lpszPath
);
355 return (LPSTR
)lastSlash
;
358 /*************************************************************************
359 * PathFindFileNameW [SHLWAPI.@]
361 * See PathFindFileNameA.
363 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
365 LPCWSTR lastSlash
= lpszPath
;
367 TRACE("(%s)\n",debugstr_w(lpszPath
));
369 while (lpszPath
&& *lpszPath
)
371 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
372 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
373 lastSlash
= lpszPath
+ 1;
376 return (LPWSTR
)lastSlash
;
379 /*************************************************************************
380 * PathFindExtensionA [SHLWAPI.@]
382 * Locate the start of the file extension in a path
385 * lpszPath [I] The path to search
388 * A pointer to the first character of the extension, the end of
389 * the string if the path has no extension, or NULL If lpszPath is NULL
391 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
393 LPCSTR lastpoint
= NULL
;
395 TRACE("(%s)\n", debugstr_a(lpszPath
));
401 if (*lpszPath
== '\\' || *lpszPath
==' ')
403 else if (*lpszPath
== '.')
404 lastpoint
= lpszPath
;
405 lpszPath
= CharNextA(lpszPath
);
408 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
411 /*************************************************************************
412 * PathFindExtensionW [SHLWAPI.@]
414 * See PathFindExtensionA.
416 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
418 LPCWSTR lastpoint
= NULL
;
420 TRACE("(%s)\n", debugstr_w(lpszPath
));
426 if (*lpszPath
== '\\' || *lpszPath
==' ')
428 else if (*lpszPath
== '.')
429 lastpoint
= lpszPath
;
433 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
436 /*************************************************************************
437 * PathGetArgsA [SHLWAPI.@]
439 * Find the next argument in a string delimited by spaces.
442 * lpszPath [I] The string to search for arguments in
445 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
448 * Spaces in quoted strings are ignored as delimiters.
450 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
452 BOOL bSeenQuote
= FALSE
;
454 TRACE("(%s)\n",debugstr_a(lpszPath
));
460 if ((*lpszPath
==' ') && !bSeenQuote
)
461 return (LPSTR
)lpszPath
+ 1;
462 if (*lpszPath
== '"')
463 bSeenQuote
= !bSeenQuote
;
464 lpszPath
= CharNextA(lpszPath
);
467 return (LPSTR
)lpszPath
;
470 /*************************************************************************
471 * PathGetArgsW [SHLWAPI.@]
475 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
477 BOOL bSeenQuote
= FALSE
;
479 TRACE("(%s)\n",debugstr_w(lpszPath
));
485 if ((*lpszPath
==' ') && !bSeenQuote
)
486 return (LPWSTR
)lpszPath
+ 1;
487 if (*lpszPath
== '"')
488 bSeenQuote
= !bSeenQuote
;
492 return (LPWSTR
)lpszPath
;
495 /*************************************************************************
496 * PathGetDriveNumberA [SHLWAPI.@]
498 * Return the drive number from a path
501 * lpszPath [I] Path to get the drive number from
504 * Success: The drive number corresponding to the drive in the path
505 * Failure: -1, if lpszPath contains no valid drive
507 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
509 TRACE ("(%s)\n",debugstr_a(lpszPath
));
511 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
512 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
513 return tolower(*lpszPath
) - 'a';
517 /*************************************************************************
518 * PathGetDriveNumberW [SHLWAPI.@]
520 * See PathGetDriveNumberA.
522 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
524 TRACE ("(%s)\n",debugstr_w(lpszPath
));
528 WCHAR tl
= tolowerW(lpszPath
[0]);
529 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
535 /*************************************************************************
536 * PathRemoveFileSpecA [SHLWAPI.@]
538 * Remove the file specification from a path.
541 * lpszPath [I/O] Path to remove the file spec from
544 * TRUE If the path was valid and modified
547 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
549 LPSTR lpszFileSpec
= lpszPath
;
550 BOOL bModified
= FALSE
;
552 TRACE("(%s)\n",debugstr_a(lpszPath
));
556 /* Skip directory or UNC path */
557 if (*lpszPath
== '\\')
558 lpszFileSpec
= ++lpszPath
;
559 if (*lpszPath
== '\\')
560 lpszFileSpec
= ++lpszPath
;
564 if(*lpszPath
== '\\')
565 lpszFileSpec
= lpszPath
; /* Skip dir */
566 else if(*lpszPath
== ':')
568 lpszFileSpec
= ++lpszPath
; /* Skip drive */
569 if (*lpszPath
== '\\')
572 if (!(lpszPath
= CharNextA(lpszPath
)))
578 *lpszFileSpec
= '\0';
585 /*************************************************************************
586 * PathRemoveFileSpecW [SHLWAPI.@]
588 * See PathRemoveFileSpecA.
590 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
592 LPWSTR lpszFileSpec
= lpszPath
;
593 BOOL bModified
= FALSE
;
595 TRACE("(%s)\n",debugstr_w(lpszPath
));
599 /* Skip directory or UNC path */
600 if (*lpszPath
== '\\')
601 lpszFileSpec
= ++lpszPath
;
602 if (*lpszPath
== '\\')
603 lpszFileSpec
= ++lpszPath
;
607 if(*lpszPath
== '\\')
608 lpszFileSpec
= lpszPath
; /* Skip dir */
609 else if(*lpszPath
== ':')
611 lpszFileSpec
= ++lpszPath
; /* Skip drive */
612 if (*lpszPath
== '\\')
620 *lpszFileSpec
= '\0';
627 /*************************************************************************
628 * PathStripPathA [SHLWAPI.@]
630 * Remove the initial path from the beginning of a filename
633 * lpszPath [I/O] Path to remove the initial path from
638 void WINAPI
PathStripPathA(LPSTR lpszPath
)
640 TRACE("(%s)\n", debugstr_a(lpszPath
));
644 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
646 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
650 /*************************************************************************
651 * PathStripPathW [SHLWAPI.@]
653 * See PathStripPathA.
655 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
659 TRACE("(%s)\n", debugstr_w(lpszPath
));
660 lpszFileName
= PathFindFileNameW(lpszPath
);
662 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
665 /*************************************************************************
666 * PathStripToRootA [SHLWAPI.@]
668 * Reduce a path to its root.
671 * lpszPath [I/O] the path to reduce
674 * Success: TRUE if the stripped path is a root path
675 * Failure: FALSE if the path cannot be stripped or is NULL
677 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
679 TRACE("(%s)\n", debugstr_a(lpszPath
));
683 while(!PathIsRootA(lpszPath
))
684 if (!PathRemoveFileSpecA(lpszPath
))
689 /*************************************************************************
690 * PathStripToRootW [SHLWAPI.@]
692 * See PathStripToRootA.
694 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
696 TRACE("(%s)\n", debugstr_w(lpszPath
));
700 while(!PathIsRootW(lpszPath
))
701 if (!PathRemoveFileSpecW(lpszPath
))
706 /*************************************************************************
707 * PathRemoveArgsA [SHLWAPI.@]
709 * Strip space separated arguments from a path.
712 * lpszPath [I/O] Path to remove arguments from
717 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
719 TRACE("(%s)\n",debugstr_a(lpszPath
));
723 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
728 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
729 if(*lpszLastChar
== ' ')
730 *lpszLastChar
= '\0';
735 /*************************************************************************
736 * PathRemoveArgsW [SHLWAPI.@]
738 * See PathRemoveArgsA.
740 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
742 TRACE("(%s)\n",debugstr_w(lpszPath
));
746 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
747 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
752 /*************************************************************************
753 * PathRemoveExtensionA [SHLWAPI.@]
755 * Remove the file extension from a path
758 * lpszPath [I/O] Path to remove the extension from
761 * The NUL terminator must be written only if extension exists
762 * and if the pointed character is not already NUL.
767 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
769 TRACE("(%s)\n", debugstr_a(lpszPath
));
773 lpszPath
= PathFindExtensionA(lpszPath
);
774 if (lpszPath
&& *lpszPath
!= '\0')
779 /*************************************************************************
780 * PathRemoveExtensionW [SHLWAPI.@]
782 * See PathRemoveExtensionA.
784 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
786 TRACE("(%s)\n", debugstr_w(lpszPath
));
790 lpszPath
= PathFindExtensionW(lpszPath
);
791 if (lpszPath
&& *lpszPath
!= '\0')
796 /*************************************************************************
797 * PathRemoveBackslashA [SHLWAPI.@]
799 * Remove a trailing backslash from a path.
802 * lpszPath [I/O] Path to remove backslash from
805 * Success: A pointer to the end of the path
806 * Failure: NULL, if lpszPath is NULL
808 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
812 TRACE("(%s)\n", debugstr_a(lpszPath
));
816 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
817 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
823 /*************************************************************************
824 * PathRemoveBackslashW [SHLWAPI.@]
826 * See PathRemoveBackslashA.
828 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
830 LPWSTR szTemp
= NULL
;
832 TRACE("(%s)\n", debugstr_w(lpszPath
));
836 szTemp
= lpszPath
+ strlenW(lpszPath
);
837 if (szTemp
> lpszPath
) szTemp
--;
838 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
844 /*************************************************************************
845 * PathRemoveBlanksA [SHLWAPI.@]
847 * Remove Spaces from the start and end of a path.
850 * lpszPath [I/O] Path to strip blanks from
855 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
857 TRACE("(%s)\n", debugstr_a(lpszPath
));
859 if(lpszPath
&& *lpszPath
)
861 LPSTR start
= lpszPath
;
863 while (*lpszPath
== ' ')
864 lpszPath
= CharNextA(lpszPath
);
867 *start
++ = *lpszPath
++;
869 if (start
!= lpszPath
)
870 while (start
[-1] == ' ')
876 /*************************************************************************
877 * PathRemoveBlanksW [SHLWAPI.@]
879 * See PathRemoveBlanksA.
881 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
883 TRACE("(%s)\n", debugstr_w(lpszPath
));
885 if(lpszPath
&& *lpszPath
)
887 LPWSTR start
= lpszPath
;
889 while (*lpszPath
== ' ')
893 *start
++ = *lpszPath
++;
895 if (start
!= lpszPath
)
896 while (start
[-1] == ' ')
902 /*************************************************************************
903 * PathQuoteSpacesA [SHLWAPI.@]
905 * Surround a path containing spaces in quotes.
908 * lpszPath [I/O] Path to quote
914 * The path is not changed if it is invalid or has no spaces.
916 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
918 TRACE("(%s)\n", debugstr_a(lpszPath
));
920 if(lpszPath
&& StrChrA(lpszPath
,' '))
922 size_t iLen
= strlen(lpszPath
) + 1;
924 if (iLen
+ 2 < MAX_PATH
)
926 memmove(lpszPath
+ 1, lpszPath
, iLen
);
928 lpszPath
[iLen
] = '"';
929 lpszPath
[iLen
+ 1] = '\0';
934 /*************************************************************************
935 * PathQuoteSpacesW [SHLWAPI.@]
937 * See PathQuoteSpacesA.
939 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
941 TRACE("(%s)\n", debugstr_w(lpszPath
));
943 if(lpszPath
&& StrChrW(lpszPath
,' '))
945 int iLen
= strlenW(lpszPath
) + 1;
947 if (iLen
+ 2 < MAX_PATH
)
949 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
951 lpszPath
[iLen
] = '"';
952 lpszPath
[iLen
+ 1] = '\0';
957 /*************************************************************************
958 * PathUnquoteSpacesA [SHLWAPI.@]
960 * Remove quotes ("") from around a path, if present.
963 * lpszPath [I/O] Path to strip quotes from
969 * If the path contains a single quote only, an empty string will result.
970 * Otherwise quotes are only removed if they appear at the start and end
973 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
975 TRACE("(%s)\n", debugstr_a(lpszPath
));
977 if (lpszPath
&& *lpszPath
== '"')
979 DWORD dwLen
= strlen(lpszPath
) - 1;
981 if (lpszPath
[dwLen
] == '"')
983 lpszPath
[dwLen
] = '\0';
984 for (; *lpszPath
; lpszPath
++)
985 *lpszPath
= lpszPath
[1];
990 /*************************************************************************
991 * PathUnquoteSpacesW [SHLWAPI.@]
993 * See PathUnquoteSpacesA.
995 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
997 TRACE("(%s)\n", debugstr_w(lpszPath
));
999 if (lpszPath
&& *lpszPath
== '"')
1001 DWORD dwLen
= strlenW(lpszPath
) - 1;
1003 if (lpszPath
[dwLen
] == '"')
1005 lpszPath
[dwLen
] = '\0';
1006 for (; *lpszPath
; lpszPath
++)
1007 *lpszPath
= lpszPath
[1];
1012 /*************************************************************************
1013 * PathParseIconLocationA [SHLWAPI.@]
1015 * Parse the location of an icon from a path.
1018 * lpszPath [I/O] The path to parse the icon location from.
1021 * Success: The number of the icon
1022 * Failure: 0 if the path does not contain an icon location or is NULL
1025 * The path has surrounding quotes and spaces removed regardless
1026 * of whether the call succeeds or not.
1028 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1033 TRACE("(%s)\n", debugstr_a(lpszPath
));
1037 if ((lpszComma
= strchr(lpszPath
, ',')))
1039 *lpszComma
++ = '\0';
1040 iRet
= StrToIntA(lpszComma
);
1042 PathUnquoteSpacesA(lpszPath
);
1043 PathRemoveBlanksA(lpszPath
);
1048 /*************************************************************************
1049 * PathParseIconLocationW [SHLWAPI.@]
1051 * See PathParseIconLocationA.
1053 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1058 TRACE("(%s)\n", debugstr_w(lpszPath
));
1062 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1064 *lpszComma
++ = '\0';
1065 iRet
= StrToIntW(lpszComma
);
1067 PathUnquoteSpacesW(lpszPath
);
1068 PathRemoveBlanksW(lpszPath
);
1073 /*************************************************************************
1076 * Unicode version of PathFileExistsDefExtA.
1078 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1080 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1081 { '.', 'c', 'o', 'm', 0},
1082 { '.', 'e', 'x', 'e', 0},
1083 { '.', 'b', 'a', 't', 0},
1084 { '.', 'l', 'n', 'k', 0},
1085 { '.', 'c', 'm', 'd', 0},
1088 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1090 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1095 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1096 if (!*szExt
|| dwWhich
& 0x40)
1099 int iLen
= lstrlenW(lpszPath
);
1100 if (iLen
> (MAX_PATH
- 5))
1102 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1104 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1105 if (PathFileExistsW(lpszPath
))
1110 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1114 return PathFileExistsW(lpszPath
);
1117 /*************************************************************************
1120 * Determine if a file exists locally and is of an executable type.
1123 * lpszPath [I/O] File to search for
1124 * dwWhich [I] Type of executable to search for
1127 * TRUE If the file was found. lpszPath contains the file name.
1131 * lpszPath is modified in place and must be at least MAX_PATH in length.
1132 * If the function returns FALSE, the path is modified to its original state.
1133 * If the given path contains an extension or dwWhich is 0, executable
1134 * extensions are not checked.
1136 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1137 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1138 * their own developers exclusive use. Monopoly, anyone?
1140 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1144 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1148 WCHAR szPath
[MAX_PATH
];
1149 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1150 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1152 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1157 /*************************************************************************
1158 * SHLWAPI_PathFindInOtherDirs
1160 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1162 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1164 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1165 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1169 WCHAR buff
[MAX_PATH
];
1171 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1173 /* Try system directories */
1174 GetSystemDirectoryW(buff
, MAX_PATH
);
1175 if (!PathAppendW(buff
, lpszFile
))
1177 if (PathFileExistsDefExtW(buff
, dwWhich
))
1179 strcpyW(lpszFile
, buff
);
1182 GetWindowsDirectoryW(buff
, MAX_PATH
);
1183 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1185 if (PathFileExistsDefExtW(buff
, dwWhich
))
1187 strcpyW(lpszFile
, buff
);
1190 GetWindowsDirectoryW(buff
, MAX_PATH
);
1191 if (!PathAppendW(buff
, lpszFile
))
1193 if (PathFileExistsDefExtW(buff
, dwWhich
))
1195 strcpyW(lpszFile
, buff
);
1198 /* Try dirs listed in %PATH% */
1199 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1201 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1204 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1205 lpszCurr
= lpszPATH
;
1208 LPCWSTR lpszEnd
= lpszCurr
;
1209 LPWSTR pBuff
= buff
;
1211 while (*lpszEnd
== ' ')
1213 while (*lpszEnd
&& *lpszEnd
!= ';')
1214 *pBuff
++ = *lpszEnd
++;
1218 lpszCurr
= lpszEnd
+ 1;
1220 lpszCurr
= NULL
; /* Last Path, terminate after this */
1222 if (!PathAppendW(buff
, lpszFile
))
1224 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1227 if (PathFileExistsDefExtW(buff
, dwWhich
))
1229 strcpyW(lpszFile
, buff
);
1230 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1234 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1238 /*************************************************************************
1241 * Search a range of paths for a specific type of executable.
1244 * lpszFile [I/O] File to search for
1245 * lppszOtherDirs [I] Other directories to look in
1246 * dwWhich [I] Type of executable to search for
1249 * Success: TRUE. The path to the executable is stored in lpszFile.
1250 * Failure: FALSE. The path to the executable is unchanged.
1252 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1254 WCHAR szFile
[MAX_PATH
];
1255 WCHAR buff
[MAX_PATH
];
1257 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1259 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1262 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1264 /* Search provided directories first */
1265 if (lppszOtherDirs
&& *lppszOtherDirs
)
1267 WCHAR szOther
[MAX_PATH
];
1268 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1270 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1272 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1273 PathCombineW(buff
, szOther
, szFile
);
1274 if (PathFileExistsDefExtW(buff
, dwWhich
))
1276 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1282 /* Not found, try system and path dirs */
1283 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1285 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1291 /*************************************************************************
1294 * Unicode version of PathFindOnPathExA.
1296 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1298 WCHAR buff
[MAX_PATH
];
1300 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1302 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1305 /* Search provided directories first */
1306 if (lppszOtherDirs
&& *lppszOtherDirs
)
1308 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1309 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1311 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1312 if (PathFileExistsDefExtW(buff
, dwWhich
))
1314 strcpyW(lpszFile
, buff
);
1320 /* Not found, try system and path dirs */
1321 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1324 /*************************************************************************
1325 * PathFindOnPathA [SHLWAPI.@]
1327 * Search a range of paths for an executable.
1330 * lpszFile [I/O] File to search for
1331 * lppszOtherDirs [I] Other directories to look in
1334 * Success: TRUE. The path to the executable is stored in lpszFile.
1335 * Failure: FALSE. The path to the executable is unchanged.
1337 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1339 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1340 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1343 /*************************************************************************
1344 * PathFindOnPathW [SHLWAPI.@]
1346 * See PathFindOnPathA.
1348 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1350 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1351 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1354 /*************************************************************************
1355 * PathCompactPathExA [SHLWAPI.@]
1357 * Compact a path into a given number of characters.
1360 * lpszDest [O] Destination for compacted path
1361 * lpszPath [I] Source path
1362 * cchMax [I] Maximum size of compacted path
1363 * dwFlags [I] Reserved
1366 * Success: TRUE. The compacted path is written to lpszDest.
1367 * Failure: FALSE. lpszPath is undefined.
1370 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1372 * The Win32 version of this function contains a bug: When cchMax == 7,
1373 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1376 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1377 * because Win32 will insert a "\" in lpszDest, even if one is
1378 * not present in the original path.
1380 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1381 UINT cchMax
, DWORD dwFlags
)
1385 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1387 if (lpszPath
&& lpszDest
)
1389 WCHAR szPath
[MAX_PATH
];
1390 WCHAR szDest
[MAX_PATH
];
1392 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1394 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1395 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1400 /*************************************************************************
1401 * PathCompactPathExW [SHLWAPI.@]
1403 * See PathCompactPathExA.
1405 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1406 UINT cchMax
, DWORD dwFlags
)
1408 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1410 DWORD dwLen
, dwFileLen
= 0;
1412 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1419 WARN("Invalid lpszDest would crash under Win32!\n");
1428 dwLen
= strlenW(lpszPath
) + 1;
1432 /* Don't need to compact */
1433 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1437 /* Path must be compacted to fit into lpszDest */
1438 lpszFile
= PathFindFileNameW(lpszPath
);
1439 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1441 if (dwFileLen
== dwLen
)
1443 /* No root in psth */
1446 while (--cchMax
> 0) /* No room left for anything but ellipses */
1451 /* Compact the file name with ellipses at the end */
1453 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1454 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1457 /* We have a root in the path */
1458 lpszFile
--; /* Start compacted filename with the path separator */
1461 if (dwFileLen
+ 3 > cchMax
)
1463 /* Compact the file name */
1466 while (--cchMax
> 0) /* No room left for anything but ellipses */
1471 strcpyW(lpszDest
, szEllipses
);
1474 *lpszDest
++ = *lpszFile
++;
1477 while (--cchMax
> 0) /* No room left for anything but ellipses */
1483 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1484 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1488 /* Only the root needs to be Compacted */
1489 dwLen
= cchMax
- dwFileLen
- 3;
1490 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1491 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1492 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1496 /*************************************************************************
1497 * PathIsRelativeA [SHLWAPI.@]
1499 * Determine if a path is a relative path.
1502 * lpszPath [I] Path to check
1505 * TRUE: The path is relative, or is invalid.
1506 * FALSE: The path is not relative.
1508 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1510 TRACE("(%s)\n",debugstr_a(lpszPath
));
1512 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1514 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1519 /*************************************************************************
1520 * PathIsRelativeW [SHLWAPI.@]
1522 * See PathIsRelativeA.
1524 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1526 TRACE("(%s)\n",debugstr_w(lpszPath
));
1528 if (!lpszPath
|| !*lpszPath
)
1530 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1535 /*************************************************************************
1536 * PathIsRootA [SHLWAPI.@]
1538 * Determine if a path is a root path.
1541 * lpszPath [I] Path to check
1544 * TRUE If lpszPath is valid and a root path,
1547 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1549 TRACE("(%s)\n", debugstr_a(lpszPath
));
1551 if (lpszPath
&& *lpszPath
)
1553 if (*lpszPath
== '\\')
1556 return TRUE
; /* \ */
1557 else if (lpszPath
[1]=='\\')
1559 BOOL bSeenSlash
= FALSE
;
1562 /* Check for UNC root path */
1565 if (*lpszPath
== '\\')
1571 lpszPath
= CharNextA(lpszPath
);
1576 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1577 return TRUE
; /* X:\ */
1582 /*************************************************************************
1583 * PathIsRootW [SHLWAPI.@]
1587 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1589 TRACE("(%s)\n", debugstr_w(lpszPath
));
1591 if (lpszPath
&& *lpszPath
)
1593 if (*lpszPath
== '\\')
1596 return TRUE
; /* \ */
1597 else if (lpszPath
[1]=='\\')
1599 BOOL bSeenSlash
= FALSE
;
1602 /* Check for UNC root path */
1605 if (*lpszPath
== '\\')
1616 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1617 return TRUE
; /* X:\ */
1622 /*************************************************************************
1623 * PathIsDirectoryA [SHLWAPI.@]
1625 * Determine if a path is a valid directory
1628 * lpszPath [I] Path to check.
1631 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1632 * FALSE if lpszPath is invalid or not a directory.
1635 * Although this function is prototyped as returning a BOOL, it returns
1636 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1638 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1643 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1647 TRACE("(%s)\n", debugstr_a(lpszPath
));
1649 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1652 if (PathIsUNCServerShareA(lpszPath
))
1654 FIXME("UNC Server Share not yet supported - FAILING\n");
1658 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1660 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1663 /*************************************************************************
1664 * PathIsDirectoryW [SHLWAPI.@]
1666 * See PathIsDirectoryA.
1668 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1672 TRACE("(%s)\n", debugstr_w(lpszPath
));
1674 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1677 if (PathIsUNCServerShareW(lpszPath
))
1679 FIXME("UNC Server Share not yet supported - FAILING\n");
1683 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1685 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1688 /*************************************************************************
1689 * PathFileExistsA [SHLWAPI.@]
1691 * Determine if a file exists.
1694 * lpszPath [I] Path to check
1697 * TRUE If the file exists and is readable
1700 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1705 TRACE("(%s)\n",debugstr_a(lpszPath
));
1710 /* Prevent a dialog box if path is on a disk that has been ejected. */
1711 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1712 dwAttr
= GetFileAttributesA(lpszPath
);
1713 SetErrorMode(iPrevErrMode
);
1714 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1717 /*************************************************************************
1718 * PathFileExistsW [SHLWAPI.@]
1720 * See PathFileExistsA.
1722 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1727 TRACE("(%s)\n",debugstr_w(lpszPath
));
1732 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1733 dwAttr
= GetFileAttributesW(lpszPath
);
1734 SetErrorMode(iPrevErrMode
);
1735 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1738 /*************************************************************************
1739 * PathFileExistsAndAttributesA [SHLWAPI.445]
1741 * Determine if a file exists.
1744 * lpszPath [I] Path to check
1745 * dwAttr [O] attributes of file
1748 * TRUE If the file exists and is readable
1751 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1756 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1759 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1764 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1765 dwVal
= GetFileAttributesA(lpszPath
);
1766 SetErrorMode(iPrevErrMode
);
1769 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1772 /*************************************************************************
1773 * PathFileExistsAndAttributesW [SHLWAPI.446]
1775 * See PathFileExistsA.
1777 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1782 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1787 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1788 dwVal
= GetFileAttributesW(lpszPath
);
1789 SetErrorMode(iPrevErrMode
);
1792 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1795 /*************************************************************************
1796 * PathMatchSingleMaskA [internal]
1798 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1800 while (*name
&& *mask
&& *mask
!=';')
1806 if (PathMatchSingleMaskA(name
,mask
+1))
1807 return TRUE
; /* try substrings */
1812 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1815 name
= CharNextA(name
);
1816 mask
= CharNextA(mask
);
1821 while (*mask
== '*')
1823 if (!*mask
|| *mask
== ';')
1829 /*************************************************************************
1830 * PathMatchSingleMaskW [internal]
1832 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1834 while (*name
&& *mask
&& *mask
!= ';')
1840 if (PathMatchSingleMaskW(name
,mask
+1))
1841 return TRUE
; /* try substrings */
1846 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1854 while (*mask
== '*')
1856 if (!*mask
|| *mask
== ';')
1862 /*************************************************************************
1863 * PathMatchSpecA [SHLWAPI.@]
1865 * Determine if a path matches one or more search masks.
1868 * lpszPath [I] Path to check
1869 * lpszMask [I] Search mask(s)
1872 * TRUE If lpszPath is valid and is matched
1876 * Multiple search masks may be given if they are separated by ";". The
1877 * pattern "*.*" is treated specially in that it matches all paths (for
1878 * backwards compatibility with DOS).
1880 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1882 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1884 if (!lstrcmpA(lpszMask
, "*.*"))
1885 return TRUE
; /* Matches every path */
1889 while (*lpszMask
== ' ')
1890 lpszMask
++; /* Eat leading spaces */
1892 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1893 return TRUE
; /* Matches the current mask */
1895 while (*lpszMask
&& *lpszMask
!= ';')
1896 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1898 if (*lpszMask
== ';')
1904 /*************************************************************************
1905 * PathMatchSpecW [SHLWAPI.@]
1907 * See PathMatchSpecA.
1909 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1911 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1913 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1915 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1916 return TRUE
; /* Matches every path */
1920 while (*lpszMask
== ' ')
1921 lpszMask
++; /* Eat leading spaces */
1923 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1924 return TRUE
; /* Matches the current path */
1926 while (*lpszMask
&& *lpszMask
!= ';')
1927 lpszMask
++; /* masks separated by ';' */
1929 if (*lpszMask
== ';')
1935 /*************************************************************************
1936 * PathIsSameRootA [SHLWAPI.@]
1938 * Determine if two paths share the same root.
1941 * lpszPath1 [I] Source path
1942 * lpszPath2 [I] Path to compare with
1945 * TRUE If both paths are valid and share the same root.
1946 * FALSE If either path is invalid or the paths do not share the same root.
1948 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1953 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1955 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1958 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1959 if (lpszStart
- lpszPath1
> dwLen
)
1960 return FALSE
; /* Paths not common up to length of the root */
1964 /*************************************************************************
1965 * PathIsSameRootW [SHLWAPI.@]
1967 * See PathIsSameRootA.
1969 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1974 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1976 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1979 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1980 if (lpszStart
- lpszPath1
> dwLen
)
1981 return FALSE
; /* Paths not common up to length of the root */
1985 /*************************************************************************
1986 * PathIsContentTypeA [SHLWAPI.@]
1988 * Determine if a file is of a given registered content type.
1991 * lpszPath [I] File to check
1992 * lpszContentType [I] Content type to check for
1995 * TRUE If lpszPath is a given registered content type,
1999 * This function looks up the registered content type for lpszPath. If
2000 * a content type is registered, it is compared (case insensitively) to
2001 * lpszContentType. Only if this matches does the function succeed.
2003 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2007 char szBuff
[MAX_PATH
];
2009 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2011 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2012 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2013 REG_NONE
, szBuff
, &dwDummy
) &&
2014 !strcasecmp(lpszContentType
, szBuff
))
2021 /*************************************************************************
2022 * PathIsContentTypeW [SHLWAPI.@]
2024 * See PathIsContentTypeA.
2026 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2028 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2031 WCHAR szBuff
[MAX_PATH
];
2033 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2035 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2036 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2037 REG_NONE
, szBuff
, &dwDummy
) &&
2038 !strcmpiW(lpszContentType
, szBuff
))
2045 /*************************************************************************
2046 * PathIsFileSpecA [SHLWAPI.@]
2048 * Determine if a path is a file specification.
2051 * lpszPath [I] Path to check
2054 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2057 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2059 TRACE("(%s)\n", debugstr_a(lpszPath
));
2066 if (*lpszPath
== '\\' || *lpszPath
== ':')
2068 lpszPath
= CharNextA(lpszPath
);
2073 /*************************************************************************
2074 * PathIsFileSpecW [SHLWAPI.@]
2076 * See PathIsFileSpecA.
2078 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2080 TRACE("(%s)\n", debugstr_w(lpszPath
));
2087 if (*lpszPath
== '\\' || *lpszPath
== ':')
2094 /*************************************************************************
2095 * PathIsPrefixA [SHLWAPI.@]
2097 * Determine if a path is a prefix of another.
2100 * lpszPrefix [I] Prefix
2101 * lpszPath [I] Path to check
2104 * TRUE If lpszPath has lpszPrefix as its prefix,
2105 * FALSE If either path is NULL or lpszPrefix is not a prefix
2107 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2109 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2111 if (lpszPrefix
&& lpszPath
&&
2112 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2117 /*************************************************************************
2118 * PathIsPrefixW [SHLWAPI.@]
2120 * See PathIsPrefixA.
2122 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2124 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2126 if (lpszPrefix
&& lpszPath
&&
2127 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2132 /*************************************************************************
2133 * PathIsSystemFolderA [SHLWAPI.@]
2135 * Determine if a path or file attributes are a system folder.
2138 * lpszPath [I] Path to check.
2139 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2142 * TRUE If lpszPath or dwAttrib are a system folder.
2143 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2145 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2147 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2149 if (lpszPath
&& *lpszPath
)
2150 dwAttrib
= GetFileAttributesA(lpszPath
);
2152 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2153 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2158 /*************************************************************************
2159 * PathIsSystemFolderW [SHLWAPI.@]
2161 * See PathIsSystemFolderA.
2163 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2165 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2167 if (lpszPath
&& *lpszPath
)
2168 dwAttrib
= GetFileAttributesW(lpszPath
);
2170 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2171 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2176 /*************************************************************************
2177 * PathIsUNCA [SHLWAPI.@]
2179 * Determine if a path is in UNC format.
2182 * lpszPath [I] Path to check
2185 * TRUE: The path is UNC.
2186 * FALSE: The path is not UNC or is NULL.
2188 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2190 TRACE("(%s)\n",debugstr_a(lpszPath
));
2192 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2197 /*************************************************************************
2198 * PathIsUNCW [SHLWAPI.@]
2202 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2204 TRACE("(%s)\n",debugstr_w(lpszPath
));
2206 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2211 /*************************************************************************
2212 * PathIsUNCServerA [SHLWAPI.@]
2214 * Determine if a path is a UNC server name ("\\SHARENAME").
2217 * lpszPath [I] Path to check.
2220 * TRUE If lpszPath is a valid UNC server name.
2224 * This routine is bug compatible with Win32: Server names with a
2225 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2226 * Fixing this bug may break other shlwapi functions!
2228 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2230 TRACE("(%s)\n", debugstr_a(lpszPath
));
2232 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2236 if (*lpszPath
== '\\')
2238 lpszPath
= CharNextA(lpszPath
);
2245 /*************************************************************************
2246 * PathIsUNCServerW [SHLWAPI.@]
2248 * See PathIsUNCServerA.
2250 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2252 TRACE("(%s)\n", debugstr_w(lpszPath
));
2254 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2256 return !strchrW( lpszPath
+ 2, '\\' );
2261 /*************************************************************************
2262 * PathIsUNCServerShareA [SHLWAPI.@]
2264 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2267 * lpszPath [I] Path to check.
2270 * TRUE If lpszPath is a valid UNC server share.
2274 * This routine is bug compatible with Win32: Server shares with a
2275 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2276 * Fixing this bug may break other shlwapi functions!
2278 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2280 TRACE("(%s)\n", debugstr_a(lpszPath
));
2282 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2284 BOOL bSeenSlash
= FALSE
;
2287 if (*lpszPath
== '\\')
2293 lpszPath
= CharNextA(lpszPath
);
2300 /*************************************************************************
2301 * PathIsUNCServerShareW [SHLWAPI.@]
2303 * See PathIsUNCServerShareA.
2305 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2307 TRACE("(%s)\n", debugstr_w(lpszPath
));
2309 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2311 BOOL bSeenSlash
= FALSE
;
2314 if (*lpszPath
== '\\')
2327 /*************************************************************************
2328 * PathCanonicalizeA [SHLWAPI.@]
2330 * Convert a path to its canonical form.
2333 * lpszBuf [O] Output path
2334 * lpszPath [I] Path to canonicalize
2337 * Success: TRUE. lpszBuf contains the output path,
2338 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2340 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2344 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2349 if (!lpszBuf
|| !lpszPath
)
2350 SetLastError(ERROR_INVALID_PARAMETER
);
2353 WCHAR szPath
[MAX_PATH
];
2354 WCHAR szBuff
[MAX_PATH
];
2355 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2358 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2361 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2362 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2368 /*************************************************************************
2369 * PathCanonicalizeW [SHLWAPI.@]
2371 * See PathCanonicalizeA.
2373 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2375 LPWSTR lpszDst
= lpszBuf
;
2376 LPCWSTR lpszSrc
= lpszPath
;
2378 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2383 if (!lpszBuf
|| !lpszPath
)
2385 SetLastError(ERROR_INVALID_PARAMETER
);
2396 /* Copy path root */
2397 if (*lpszSrc
== '\\')
2399 *lpszDst
++ = *lpszSrc
++;
2401 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2404 *lpszDst
++ = *lpszSrc
++;
2405 *lpszDst
++ = *lpszSrc
++;
2406 if (*lpszSrc
== '\\')
2407 *lpszDst
++ = *lpszSrc
++;
2410 /* Canonicalize the rest of the path */
2413 if (*lpszSrc
== '.')
2415 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2417 lpszSrc
+= 2; /* Skip .\ */
2419 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2421 /* \.. backs up a directory, over the root if it has no \ following X:.
2422 * .. is ignored if it would remove a UNC server name or initial \\
2424 if (lpszDst
!= lpszBuf
)
2426 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2427 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2428 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2430 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2433 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2435 if (*lpszDst
== '\\')
2436 lpszDst
++; /* Reset to last '\' */
2438 lpszDst
= lpszBuf
; /* Start path again from new root */
2440 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2443 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2445 if (lpszDst
== lpszBuf
)
2451 lpszSrc
+= 2; /* Skip .. in src path */
2454 *lpszDst
++ = *lpszSrc
++;
2457 *lpszDst
++ = *lpszSrc
++;
2459 /* Append \ to naked drive specs */
2460 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2466 /*************************************************************************
2467 * PathFindNextComponentA [SHLWAPI.@]
2469 * Find the next component in a path.
2472 * lpszPath [I] Path to find next component in
2475 * Success: A pointer to the next component, or the end of the string.
2476 * Failure: NULL, If lpszPath is invalid
2479 * A 'component' is either a backslash character (\) or UNC marker (\\).
2480 * Because of this, relative paths (e.g "c:foo") are regarded as having
2481 * only one component.
2483 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2487 TRACE("(%s)\n", debugstr_a(lpszPath
));
2489 if(!lpszPath
|| !*lpszPath
)
2492 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2494 if (lpszSlash
[1] == '\\')
2496 return lpszSlash
+ 1;
2498 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2501 /*************************************************************************
2502 * PathFindNextComponentW [SHLWAPI.@]
2504 * See PathFindNextComponentA.
2506 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2510 TRACE("(%s)\n", debugstr_w(lpszPath
));
2512 if(!lpszPath
|| !*lpszPath
)
2515 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2517 if (lpszSlash
[1] == '\\')
2519 return lpszSlash
+ 1;
2521 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2524 /*************************************************************************
2525 * PathAddExtensionA [SHLWAPI.@]
2527 * Add a file extension to a path
2530 * lpszPath [I/O] Path to add extension to
2531 * lpszExtension [I] Extension to add to lpszPath
2534 * TRUE If the path was modified,
2535 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2536 * extension already, or the new path length is too big.
2539 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2540 * does not do this, so the behaviour was removed.
2542 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2546 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2548 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2551 dwLen
= strlen(lpszPath
);
2553 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2556 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2560 /*************************************************************************
2561 * PathAddExtensionW [SHLWAPI.@]
2563 * See PathAddExtensionA.
2565 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2569 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2571 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2574 dwLen
= strlenW(lpszPath
);
2576 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2579 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2583 /*************************************************************************
2584 * PathMakePrettyA [SHLWAPI.@]
2586 * Convert an uppercase DOS filename into lowercase.
2589 * lpszPath [I/O] Path to convert.
2592 * TRUE If the path was an uppercase DOS path and was converted,
2595 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2597 LPSTR pszIter
= lpszPath
;
2599 TRACE("(%s)\n", debugstr_a(lpszPath
));
2608 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2609 return FALSE
; /* Not DOS path */
2612 pszIter
= lpszPath
+ 1;
2615 *pszIter
= tolower(*pszIter
);
2622 /*************************************************************************
2623 * PathMakePrettyW [SHLWAPI.@]
2625 * See PathMakePrettyA.
2627 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2629 LPWSTR pszIter
= lpszPath
;
2631 TRACE("(%s)\n", debugstr_w(lpszPath
));
2640 if (islowerW(*pszIter
))
2641 return FALSE
; /* Not DOS path */
2644 pszIter
= lpszPath
+ 1;
2647 *pszIter
= tolowerW(*pszIter
);
2654 /*************************************************************************
2655 * PathCommonPrefixA [SHLWAPI.@]
2657 * Determine the length of the common prefix between two paths.
2660 * lpszFile1 [I] First path for comparison
2661 * lpszFile2 [I] Second path for comparison
2662 * achPath [O] Destination for common prefix string
2665 * The length of the common prefix. This is 0 if there is no common
2666 * prefix between the paths or if any parameters are invalid. If the prefix
2667 * is non-zero and achPath is not NULL, achPath is filled with the common
2668 * part of the prefix and NUL terminated.
2671 * A common prefix of 2 is always returned as 3. It is thus possible for
2672 * the length returned to be invalid (i.e. Longer than one or both of the
2673 * strings given as parameters). This Win32 behaviour has been implemented
2674 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2675 * To work around this when using this function, always check that the byte
2676 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2678 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2681 LPCSTR lpszIter1
= lpszFile1
;
2682 LPCSTR lpszIter2
= lpszFile2
;
2684 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2689 if (!lpszFile1
|| !lpszFile2
)
2692 /* Handle roots first */
2693 if (PathIsUNCA(lpszFile1
))
2695 if (!PathIsUNCA(lpszFile2
))
2700 else if (PathIsUNCA(lpszFile2
))
2701 return 0; /* Know already lpszFile1 is not UNC */
2706 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2707 (!*lpszIter2
|| *lpszIter2
== '\\'))
2708 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2710 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2711 break; /* Strings differ at this point */
2718 iLen
++; /* Feature/Bug compatible with Win32 */
2720 if (iLen
&& achPath
)
2722 memcpy(achPath
,lpszFile1
,iLen
);
2723 achPath
[iLen
] = '\0';
2728 /*************************************************************************
2729 * PathCommonPrefixW [SHLWAPI.@]
2731 * See PathCommonPrefixA.
2733 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2736 LPCWSTR lpszIter1
= lpszFile1
;
2737 LPCWSTR lpszIter2
= lpszFile2
;
2739 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2744 if (!lpszFile1
|| !lpszFile2
)
2747 /* Handle roots first */
2748 if (PathIsUNCW(lpszFile1
))
2750 if (!PathIsUNCW(lpszFile2
))
2755 else if (PathIsUNCW(lpszFile2
))
2756 return 0; /* Know already lpszFile1 is not UNC */
2761 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2762 (!*lpszIter2
|| *lpszIter2
== '\\'))
2763 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2765 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2766 break; /* Strings differ at this point */
2773 iLen
++; /* Feature/Bug compatible with Win32 */
2775 if (iLen
&& achPath
)
2777 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2778 achPath
[iLen
] = '\0';
2783 /*************************************************************************
2784 * PathCompactPathA [SHLWAPI.@]
2786 * Make a path fit into a given width when printed to a DC.
2789 * hDc [I] Destination DC
2790 * lpszPath [I/O] Path to be printed to hDc
2791 * dx [I] Desired width
2794 * TRUE If the path was modified/went well.
2797 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2801 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2805 WCHAR szPath
[MAX_PATH
];
2806 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2807 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2808 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2813 /*************************************************************************
2814 * PathCompactPathW [SHLWAPI.@]
2816 * See PathCompactPathA.
2818 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2820 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2823 WCHAR buff
[MAX_PATH
];
2827 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2833 hdc
= hDC
= GetDC(0);
2835 /* Get the length of the whole path */
2836 dwLen
= strlenW(lpszPath
);
2837 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2839 if ((UINT
)size
.cx
> dx
)
2841 /* Path too big, must reduce it */
2843 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2845 sFile
= PathFindFileNameW(lpszPath
);
2846 if (sFile
!= lpszPath
) sFile
--;
2848 /* Get the size of ellipses */
2849 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2850 dwEllipsesLen
= size
.cx
;
2851 /* Get the size of the file name */
2852 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2853 dwPathLen
= size
.cx
;
2855 if (sFile
!= lpszPath
)
2857 LPWSTR sPath
= sFile
;
2858 BOOL bEllipses
= FALSE
;
2860 /* The path includes a file name. Include as much of the path prior to
2861 * the file name as possible, allowing for the ellipses, e.g:
2862 * c:\some very long path\filename ==> c:\some v...\filename
2864 lstrcpynW(buff
, sFile
, MAX_PATH
);
2868 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2870 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2871 dwTotalLen
+= size
.cx
;
2872 if (dwTotalLen
<= dx
)
2880 } while (sPath
> lpszPath
);
2882 if (sPath
> lpszPath
)
2886 strcpyW(sPath
, szEllipses
);
2887 strcpyW(sPath
+3, buff
);
2892 strcpyW(lpszPath
, szEllipses
);
2893 strcpyW(lpszPath
+3, buff
);
2898 /* Trim the path by adding ellipses to the end, e.g:
2899 * A very long file name.txt ==> A very...
2901 dwLen
= strlenW(lpszPath
);
2903 if (dwLen
> MAX_PATH
- 3)
2904 dwLen
= MAX_PATH
- 3;
2905 lstrcpynW(buff
, sFile
, dwLen
);
2909 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2910 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2914 DWORD dwWritten
= 0;
2916 dwEllipsesLen
/= 3; /* Size of a single '.' */
2918 /* Write as much of the Ellipses string as possible */
2919 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2922 dwWritten
+= dwEllipsesLen
;
2930 strcpyW(buff
+ dwLen
, szEllipses
);
2931 strcpyW(lpszPath
, buff
);
2942 /*************************************************************************
2943 * PathGetCharTypeA [SHLWAPI.@]
2945 * Categorise a character from a file path.
2948 * ch [I] Character to get the type of
2951 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2953 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2955 return PathGetCharTypeW(ch
);
2958 /*************************************************************************
2959 * PathGetCharTypeW [SHLWAPI.@]
2961 * See PathGetCharTypeA.
2963 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2967 TRACE("(%d)\n", ch
);
2969 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2970 ch
== '"' || ch
== '|' || ch
== '/')
2971 flags
= GCT_INVALID
; /* Invalid */
2972 else if (ch
== '*' || ch
=='?')
2973 flags
= GCT_WILD
; /* Wildchars */
2974 else if ((ch
== '\\') || (ch
== ':'))
2975 return GCT_SEPARATOR
; /* Path separators */
2980 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2981 ch
== '.' || ch
== '@' || ch
== '^' ||
2982 ch
== '\'' || ch
== 130 || ch
== '`')
2983 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2986 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2987 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2992 /*************************************************************************
2993 * SHLWAPI_UseSystemForSystemFolders
2995 * Internal helper for PathMakeSystemFolderW.
2997 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
2999 static BOOL bCheckedReg
= FALSE
;
3000 static BOOL bUseSystemForSystemFolders
= FALSE
;
3006 /* Key tells Win what file attributes to use on system folders */
3007 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3008 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3009 "UseSystemForSystemFolders", 0, 0, 0))
3010 bUseSystemForSystemFolders
= TRUE
;
3012 return bUseSystemForSystemFolders
;
3015 /*************************************************************************
3016 * PathMakeSystemFolderA [SHLWAPI.@]
3018 * Set system folder attribute for a path.
3021 * lpszPath [I] The path to turn into a system folder
3024 * TRUE If the path was changed to/already was a system folder
3025 * FALSE If the path is invalid or SetFileAttributesA() fails
3027 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3031 TRACE("(%s)\n", debugstr_a(lpszPath
));
3033 if (lpszPath
&& *lpszPath
)
3035 WCHAR szPath
[MAX_PATH
];
3036 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3037 bRet
= PathMakeSystemFolderW(szPath
);
3042 /*************************************************************************
3043 * PathMakeSystemFolderW [SHLWAPI.@]
3045 * See PathMakeSystemFolderA.
3047 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3049 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3050 WCHAR buff
[MAX_PATH
];
3052 TRACE("(%s)\n", debugstr_w(lpszPath
));
3054 if (!lpszPath
|| !*lpszPath
)
3057 /* If the directory is already a system directory, don't do anything */
3058 GetSystemDirectoryW(buff
, MAX_PATH
);
3059 if (!strcmpW(buff
, lpszPath
))
3062 GetWindowsDirectoryW(buff
, MAX_PATH
);
3063 if (!strcmpW(buff
, lpszPath
))
3066 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3067 if (SHLWAPI_UseSystemForSystemFolders())
3068 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3070 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3073 /* Change file attributes to system attributes */
3074 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3075 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3078 /*************************************************************************
3079 * PathRenameExtensionA [SHLWAPI.@]
3081 * Swap the file extension in a path with another extension.
3084 * lpszPath [I/O] Path to swap the extension in
3085 * lpszExt [I] The new extension
3088 * TRUE if lpszPath was modified,
3089 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3091 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3093 LPSTR lpszExtension
;
3095 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3097 lpszExtension
= PathFindExtensionA(lpszPath
);
3099 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3102 strcpy(lpszExtension
, lpszExt
);
3106 /*************************************************************************
3107 * PathRenameExtensionW [SHLWAPI.@]
3109 * See PathRenameExtensionA.
3111 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3113 LPWSTR lpszExtension
;
3115 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3117 lpszExtension
= PathFindExtensionW(lpszPath
);
3119 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3122 strcpyW(lpszExtension
, lpszExt
);
3126 /*************************************************************************
3127 * PathSearchAndQualifyA [SHLWAPI.@]
3129 * Determine if a given path is correct and fully qualified.
3132 * lpszPath [I] Path to check
3133 * lpszBuf [O] Output for correct path
3134 * cchBuf [I] Size of lpszBuf
3139 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3141 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3143 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3145 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3148 /*************************************************************************
3149 * PathSearchAndQualifyW [SHLWAPI.@]
3151 * See PathSearchAndQualifyA.
3153 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3155 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3157 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3159 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3162 /*************************************************************************
3163 * PathSkipRootA [SHLWAPI.@]
3165 * Return the portion of a path following the drive letter or mount point.
3168 * lpszPath [I] The path to skip on
3171 * Success: A pointer to the next character after the root.
3172 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3174 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3176 TRACE("(%s)\n", debugstr_a(lpszPath
));
3178 if (!lpszPath
|| !*lpszPath
)
3181 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3183 /* Network share: skip share server and mount point */
3185 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3186 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3188 return (LPSTR
)lpszPath
;
3191 if (IsDBCSLeadByte(*lpszPath
))
3195 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3196 return (LPSTR
)lpszPath
+ 3;
3200 /*************************************************************************
3201 * PathSkipRootW [SHLWAPI.@]
3203 * See PathSkipRootA.
3205 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3207 TRACE("(%s)\n", debugstr_w(lpszPath
));
3209 if (!lpszPath
|| !*lpszPath
)
3212 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3214 /* Network share: skip share server and mount point */
3216 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3217 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3219 return (LPWSTR
)lpszPath
;
3223 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3224 return (LPWSTR
)lpszPath
+ 3;
3228 /*************************************************************************
3229 * PathCreateFromUrlA [SHLWAPI.@]
3231 * See PathCreateFromUrlW
3233 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3234 LPDWORD pcchPath
, DWORD dwReserved
)
3236 WCHAR bufW
[MAX_PATH
];
3237 WCHAR
*pathW
= bufW
;
3238 UNICODE_STRING urlW
;
3240 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3242 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3243 return E_INVALIDARG
;
3245 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3246 return E_INVALIDARG
;
3247 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3248 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3249 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3252 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3253 if(*pcchPath
> lenA
) {
3254 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3258 *pcchPath
= lenA
+ 1;
3262 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3263 RtlFreeUnicodeString(&urlW
);
3267 /*************************************************************************
3268 * PathCreateFromUrlW [SHLWAPI.@]
3270 * Create a path from a URL
3273 * lpszUrl [I] URL to convert into a path
3274 * lpszPath [O] Output buffer for the resulting Path
3275 * pcchPath [I] Length of lpszPath
3276 * dwFlags [I] Flags controlling the conversion
3279 * Success: S_OK. lpszPath contains the URL in path format,
3280 * Failure: An HRESULT error code such as E_INVALIDARG.
3282 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3283 LPDWORD pcchPath
, DWORD dwReserved
)
3285 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3286 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3287 DWORD nslashes
, unescape
, len
;
3292 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3294 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3295 return E_INVALIDARG
;
3297 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3298 file_colon
, 5) != CSTR_EQUAL
)
3299 return E_INVALIDARG
;
3305 while (*src
== '/' || *src
== '\\') {
3310 /* We need a temporary buffer so we can compute what size to ask for.
3311 * We know that the final string won't be longer than the current pszUrl
3312 * plus at most two backslashes. All the other transformations make it
3315 len
= 2 + lstrlenW(pszUrl
) + 1;
3316 if (*pcchPath
< len
)
3317 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3327 /* 'file:' + escaped DOS path */
3330 /* 'file:/' + escaped DOS path */
3333 /* 'file:///' (implied localhost) + escaped DOS path */
3334 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3338 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, src
, 9,
3339 localhost
, 9) == CSTR_EQUAL
&&
3340 (src
[9] == '/' || src
[9] == '\\'))
3342 /* 'file://localhost/' + escaped DOS path */
3345 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3347 /* 'file://' + unescaped DOS path */
3352 /* 'file://hostname:port/path' (where path is escaped)
3353 * or 'file:' + escaped UNC path (\\server\share\path)
3354 * The second form is clearly specific to Windows and it might
3355 * even be doing a network lookup to try to figure it out.
3357 while (*src
&& *src
!= '/' && *src
!= '\\')
3360 StrCpyNW(dst
, pszUrl
, len
+ 1);
3362 if (isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3364 /* 'Forget' to add a trailing '/', just like Windows */
3370 /* 'file://' + unescaped UNC path (\\server\share\path) */
3372 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3376 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3380 /* Copy the remainder of the path */
3381 len
+= lstrlenW(src
);
3384 /* First do the Windows-specific path conversions */
3385 for (dst
= tpath
; *dst
; dst
++)
3386 if (*dst
== '/') *dst
= '\\';
3387 if (isalphaW(*tpath
) && tpath
[1] == '|')
3388 tpath
[1] = ':'; /* c| -> c: */
3390 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3393 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3396 /* When working in-place UrlUnescapeW() does not set len */
3397 len
= lstrlenW(tpath
);
3401 if (*pcchPath
< len
+ 1)
3404 *pcchPath
= len
+ 1;
3409 if (tpath
!= pszPath
)
3410 StrCpyW(pszPath
, tpath
);
3412 if (tpath
!= pszPath
)
3413 HeapFree(GetProcessHeap(), 0, tpath
);
3415 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3419 /*************************************************************************
3420 * PathCreateFromUrlAlloc [SHLWAPI.@]
3422 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3425 WCHAR pathW
[MAX_PATH
];
3430 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3433 /* Yes, this is supposed to crash if pszPath is NULL */
3434 *pszPath
= StrDupW(pathW
);
3439 /*************************************************************************
3440 * PathRelativePathToA [SHLWAPI.@]
3442 * Create a relative path from one path to another.
3445 * lpszPath [O] Destination for relative path
3446 * lpszFrom [I] Source path
3447 * dwAttrFrom [I] File attribute of source path
3448 * lpszTo [I] Destination path
3449 * dwAttrTo [I] File attributes of destination path
3452 * TRUE If a relative path can be formed. lpszPath contains the new path
3453 * FALSE If the paths are not relative or any parameters are invalid
3456 * lpszTo should be at least MAX_PATH in length.
3458 * Calling this function with relative paths for lpszFrom or lpszTo may
3459 * give erroneous results.
3461 * The Win32 version of this function contains a bug where the lpszTo string
3462 * may be referenced 1 byte beyond the end of the string. As a result random
3463 * garbage may be written to the output path, depending on what lies beyond
3464 * the last byte of the string. This bug occurs because of the behaviour of
3465 * PathCommonPrefix() (see notes for that function), and no workaround seems
3466 * possible with Win32.
3468 * This bug has been fixed here, so for example the relative path from "\\"
3469 * to "\\" is correctly determined as "." in this implementation.
3471 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3472 LPCSTR lpszTo
, DWORD dwAttrTo
)
3476 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3477 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3479 if(lpszPath
&& lpszFrom
&& lpszTo
)
3481 WCHAR szPath
[MAX_PATH
];
3482 WCHAR szFrom
[MAX_PATH
];
3483 WCHAR szTo
[MAX_PATH
];
3484 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3485 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3486 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3487 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3492 /*************************************************************************
3493 * PathRelativePathToW [SHLWAPI.@]
3495 * See PathRelativePathToA.
3497 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3498 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3500 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3501 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3502 WCHAR szFrom
[MAX_PATH
];
3503 WCHAR szTo
[MAX_PATH
];
3506 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3507 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3509 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3513 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3514 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3516 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3517 PathRemoveFileSpecW(szFrom
);
3518 if(!(dwAttrTo
& FILE_ATTRIBUTE_DIRECTORY
))
3519 PathRemoveFileSpecW(szTo
);
3521 /* Paths can only be relative if they have a common root */
3522 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3525 /* Strip off lpszFrom components to the root, by adding "..\" */
3526 lpszFrom
= szFrom
+ dwLen
;
3532 if (*lpszFrom
== '\\')
3537 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3538 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3541 /* From the root add the components of lpszTo */
3543 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3546 if (*lpszTo
&& lpszTo
[-1])
3548 if (*lpszTo
!= '\\')
3550 dwLen
= strlenW(lpszPath
);
3551 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3556 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3561 /*************************************************************************
3562 * PathUnmakeSystemFolderA [SHLWAPI.@]
3564 * Remove the system folder attributes from a path.
3567 * lpszPath [I] The path to remove attributes from
3571 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3572 * SetFileAttributesA() fails.
3574 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3578 TRACE("(%s)\n", debugstr_a(lpszPath
));
3580 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3581 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3584 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3585 return SetFileAttributesA(lpszPath
, dwAttr
);
3588 /*************************************************************************
3589 * PathUnmakeSystemFolderW [SHLWAPI.@]
3591 * See PathUnmakeSystemFolderA.
3593 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3597 TRACE("(%s)\n", debugstr_w(lpszPath
));
3599 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3600 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3603 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3604 return SetFileAttributesW(lpszPath
, dwAttr
);
3608 /*************************************************************************
3609 * PathSetDlgItemPathA [SHLWAPI.@]
3611 * Set the text of a dialog item to a path, shrinking the path to fit
3612 * if it is too big for the item.
3615 * hDlg [I] Dialog handle
3616 * id [I] ID of item in the dialog
3617 * lpszPath [I] Path to set as the items text
3623 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3624 * window text is erased).
3626 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3628 WCHAR szPath
[MAX_PATH
];
3630 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3633 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3636 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3639 /*************************************************************************
3640 * PathSetDlgItemPathW [SHLWAPI.@]
3642 * See PathSetDlgItemPathA.
3644 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3646 WCHAR path
[MAX_PATH
+ 1];
3652 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3654 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3658 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3662 GetClientRect(hwItem
, &rect
);
3664 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3668 PathCompactPathW(hdc
, path
, rect
.right
);
3669 SelectObject(hdc
, hPrevObj
);
3672 ReleaseDC(hDlg
, hdc
);
3673 SetWindowTextW(hwItem
, path
);
3676 /*************************************************************************
3677 * PathIsNetworkPathA [SHLWAPI.@]
3679 * Determine if the given path is a network path.
3682 * lpszPath [I] Path to check
3685 * TRUE If lpszPath is a UNC share or mapped network drive, or
3686 * FALSE If lpszPath is a local drive or cannot be determined
3688 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3692 TRACE("(%s)\n",debugstr_a(lpszPath
));
3696 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3698 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3699 if (dwDriveNum
== -1)
3701 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3702 return pIsNetDrive(dwDriveNum
);
3705 /*************************************************************************
3706 * PathIsNetworkPathW [SHLWAPI.@]
3708 * See PathIsNetworkPathA.
3710 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3714 TRACE("(%s)\n", debugstr_w(lpszPath
));
3718 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3720 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3721 if (dwDriveNum
== -1)
3723 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3724 return pIsNetDrive(dwDriveNum
);
3727 /*************************************************************************
3728 * PathIsLFNFileSpecA [SHLWAPI.@]
3730 * Determine if the given path is a long file name
3733 * lpszPath [I] Path to check
3736 * TRUE If path is a long file name,
3737 * FALSE If path is a valid DOS short file name
3739 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3741 DWORD dwNameLen
= 0, dwExtLen
= 0;
3743 TRACE("(%s)\n",debugstr_a(lpszPath
));
3750 if (*lpszPath
== ' ')
3751 return TRUE
; /* DOS names cannot have spaces */
3752 if (*lpszPath
== '.')
3755 return TRUE
; /* DOS names have only one dot */
3762 return TRUE
; /* DOS extensions are <= 3 chars*/
3768 return TRUE
; /* DOS names are <= 8 chars */
3770 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3772 return FALSE
; /* Valid DOS path */
3775 /*************************************************************************
3776 * PathIsLFNFileSpecW [SHLWAPI.@]
3778 * See PathIsLFNFileSpecA.
3780 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3782 DWORD dwNameLen
= 0, dwExtLen
= 0;
3784 TRACE("(%s)\n",debugstr_w(lpszPath
));
3791 if (*lpszPath
== ' ')
3792 return TRUE
; /* DOS names cannot have spaces */
3793 if (*lpszPath
== '.')
3796 return TRUE
; /* DOS names have only one dot */
3803 return TRUE
; /* DOS extensions are <= 3 chars*/
3809 return TRUE
; /* DOS names are <= 8 chars */
3813 return FALSE
; /* Valid DOS path */
3816 /*************************************************************************
3817 * PathIsDirectoryEmptyA [SHLWAPI.@]
3819 * Determine if a given directory is empty.
3822 * lpszPath [I] Directory to check
3825 * TRUE If the directory exists and contains no files,
3828 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3832 TRACE("(%s)\n",debugstr_a(lpszPath
));
3836 WCHAR szPath
[MAX_PATH
];
3837 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3838 bRet
= PathIsDirectoryEmptyW(szPath
);
3843 /*************************************************************************
3844 * PathIsDirectoryEmptyW [SHLWAPI.@]
3846 * See PathIsDirectoryEmptyA.
3848 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3850 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3851 WCHAR szSearch
[MAX_PATH
];
3854 BOOL retVal
= FALSE
;
3855 WIN32_FIND_DATAW find_data
;
3857 TRACE("(%s)\n",debugstr_w(lpszPath
));
3859 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3862 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3863 PathAddBackslashW(szSearch
);
3864 dwLen
= strlenW(szSearch
);
3865 if (dwLen
> MAX_PATH
- 4)
3868 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3869 hfind
= FindFirstFileW(szSearch
, &find_data
);
3870 if (hfind
!= INVALID_HANDLE_VALUE
)
3872 if (find_data
.cFileName
[0] == '.' && find_data
.cFileName
[1] == '.')
3873 /* The only directory entry should be the parent */
3874 retVal
= !FindNextFileW(hfind
, &find_data
);
3882 /*************************************************************************
3883 * PathFindSuffixArrayA [SHLWAPI.@]
3885 * Find a suffix string in an array of suffix strings
3888 * lpszSuffix [I] Suffix string to search for
3889 * lppszArray [I] Array of suffix strings to search
3890 * dwCount [I] Number of elements in lppszArray
3893 * Success: The index of the position of lpszSuffix in lppszArray
3894 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3897 * The search is case sensitive.
3898 * The match is made against the end of the suffix string, so for example:
3899 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3901 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3906 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3908 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3910 dwLen
= strlen(lpszSuffix
);
3912 while (dwRet
< dwCount
)
3914 size_t dwCompareLen
= strlen(*lppszArray
);
3915 if (dwCompareLen
< dwLen
)
3917 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3918 return *lppszArray
; /* Found */
3927 /*************************************************************************
3928 * PathFindSuffixArrayW [SHLWAPI.@]
3930 * See PathFindSuffixArrayA.
3932 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3937 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3939 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3941 dwLen
= strlenW(lpszSuffix
);
3943 while (dwRet
< dwCount
)
3945 size_t dwCompareLen
= strlenW(*lppszArray
);
3946 if (dwCompareLen
< dwLen
)
3948 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3949 return *lppszArray
; /* Found */
3958 /*************************************************************************
3959 * PathUndecorateA [SHLWAPI.@]
3961 * Undecorate a file path
3964 * lpszPath [I/O] Path to remove any decoration from
3970 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3972 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3974 TRACE("(%s)\n",debugstr_a(lpszPath
));
3978 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3979 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3981 LPSTR lpszSkip
= lpszExt
- 2;
3982 if (*lpszSkip
== '[')
3983 lpszSkip
++; /* [] (no number) */
3985 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3987 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3989 /* remove the [n] */
3992 *lpszSkip
++ = *lpszExt
++;
3999 /*************************************************************************
4000 * PathUndecorateW [SHLWAPI.@]
4002 * See PathUndecorateA.
4004 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4006 TRACE("(%s)\n",debugstr_w(lpszPath
));
4010 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4011 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4013 LPWSTR lpszSkip
= lpszExt
- 2;
4014 if (*lpszSkip
== '[')
4015 lpszSkip
++; /* [] (no number) */
4017 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4019 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4021 /* remove the [n] */
4024 *lpszSkip
++ = *lpszExt
++;
4031 /*************************************************************************
4032 * PathUnExpandEnvStringsA [SHLWAPI.@]
4034 * Substitute folder names in a path with their corresponding environment
4038 * path [I] Buffer containing the path to unexpand.
4039 * buffer [O] Buffer to receive the unexpanded path.
4040 * buf_len [I] Size of pszBuf in characters.
4046 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4048 WCHAR bufferW
[MAX_PATH
], *pathW
;
4052 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4054 pathW
= heap_strdupAtoW(path
);
4055 if (!pathW
) return FALSE
;
4057 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4058 HeapFree(GetProcessHeap(), 0, pathW
);
4059 if (!ret
) return FALSE
;
4061 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4062 if (buf_len
< len
+ 1) return FALSE
;
4064 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4068 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4069 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4070 static const WCHAR computernameW
[] = {'%','C','O','M','P','U','T','E','R','N','A','M','E','%',0};
4071 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4072 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4073 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4074 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4080 WCHAR path
[MAX_PATH
];
4084 static void init_envvars_map(struct envvars_map
*map
)
4088 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4089 /* exclude null from length */
4090 if (map
->len
) map
->len
--;
4095 /*************************************************************************
4096 * PathUnExpandEnvStringsW [SHLWAPI.@]
4098 * Unicode version of PathUnExpandEnvStringsA.
4100 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4102 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4103 struct envvars_map
*match
= &null_var
, *cur
;
4104 struct envvars_map envvars
[] = {
4105 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4106 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4107 { computernameW
, sizeof(computernameW
)/sizeof(WCHAR
) },
4108 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4109 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4110 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4111 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4117 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4119 pathlen
= strlenW(path
);
4120 init_envvars_map(envvars
);
4124 /* path can't contain expanded value or value wasn't retrieved */
4125 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4131 if (cur
->len
> match
->len
)
4136 /* 'varlen' includes NULL termination char */
4137 needed
= match
->varlen
+ pathlen
- match
->len
;
4138 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4140 strcpyW(buffer
, match
->var
);
4141 strcatW(buffer
, &path
[match
->len
]);
4142 TRACE("ret %s\n", debugstr_w(buffer
));
4147 /*************************************************************************
4150 * Find localised or default web content in "%WINDOWS%\web\".
4153 * lpszFile [I] File name containing content to look for
4154 * lpszPath [O] Buffer to contain the full path to the file
4155 * dwPathLen [I] Length of lpszPath
4158 * Success: S_OK. lpszPath contains the full path to the content.
4159 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4161 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4163 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4166 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4168 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4170 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4171 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4175 /*************************************************************************
4178 * Unicode version of SHGetWebFolderFilePathA.
4180 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4182 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4183 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4184 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4185 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4186 DWORD dwLen
, dwFileLen
;
4187 LANGID lidSystem
, lidUser
;
4189 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4191 /* Get base directory for web content */
4192 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4193 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4196 dwFileLen
= strlenW(lpszFile
);
4198 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4199 return E_FAIL
; /* lpszPath too short */
4201 strcpyW(lpszPath
+dwLen
, szWeb
);
4203 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4205 lidSystem
= GetSystemDefaultUILanguage();
4206 lidUser
= GetUserDefaultUILanguage();
4208 if (lidSystem
!= lidUser
)
4210 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4212 /* Use localised content in the users UI language if present */
4213 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4214 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4215 if (PathFileExistsW(lpszPath
))
4220 /* Fall back to OS default installed content */
4221 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4222 if (PathFileExistsW(lpszPath
))
4227 #define PATH_CHAR_CLASS_LETTER 0x00000001
4228 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4229 #define PATH_CHAR_CLASS_DOT 0x00000004
4230 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4231 #define PATH_CHAR_CLASS_COLON 0x00000010
4232 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4233 #define PATH_CHAR_CLASS_COMMA 0x00000040
4234 #define PATH_CHAR_CLASS_SPACE 0x00000080
4235 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4236 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4238 #define PATH_CHAR_CLASS_INVALID 0x00000000
4239 #define PATH_CHAR_CLASS_ANY 0xffffffff
4241 static const DWORD SHELL_charclass
[] =
4243 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4244 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4245 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4246 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4247 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4248 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4249 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4250 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4251 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4252 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4253 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4254 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4255 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4256 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4257 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4258 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4259 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4260 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4261 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4262 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4263 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4264 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4265 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4266 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4267 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4268 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4269 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4270 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4271 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4272 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4273 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4274 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4275 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4276 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4277 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4278 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4279 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4280 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4281 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4282 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4283 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4284 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4285 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4286 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4287 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4288 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4289 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4290 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4291 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4292 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4293 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4294 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4295 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4296 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4297 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4298 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4299 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4300 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4301 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4302 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4303 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4304 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4305 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4306 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4309 /*************************************************************************
4312 * Check if an ASCII char is of a certain class
4314 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4316 if ((unsigned)c
> 0x7e)
4317 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4319 return class & SHELL_charclass
[(unsigned)c
];
4322 /*************************************************************************
4325 * Check if a Unicode char is of a certain class
4327 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4330 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4332 return class & SHELL_charclass
[c
];