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
)
143 if (!MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
))
147 if (!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))
159 /*************************************************************************
160 * PathCombineW [SHLWAPI.@]
164 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
166 WCHAR szTemp
[MAX_PATH
];
167 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
169 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
171 /* Invalid parameters */
174 if (!lpszDir
&& !lpszFile
)
180 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
183 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
185 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
187 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
190 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
203 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
206 PathStripToRootW(szTemp
);
207 lpszFile
++; /* Skip '\' */
209 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
214 strcatW(szTemp
, lpszFile
);
217 PathCanonicalizeW(lpszDest
, szTemp
);
221 /*************************************************************************
222 * PathAddBackslashA [SHLWAPI.@]
224 * Append a backslash ('\') to a path if one doesn't exist.
227 * lpszPath [I/O] The path to append a backslash to.
230 * Success: The position of the last backslash in the path.
231 * Failure: NULL, if lpszPath is NULL or the path is too large.
233 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
236 LPSTR prev
= lpszPath
;
238 TRACE("(%s)\n",debugstr_a(lpszPath
));
240 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
246 lpszPath
= CharNextA(prev
);
259 /*************************************************************************
260 * PathAddBackslashW [SHLWAPI.@]
262 * See PathAddBackslashA.
264 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
268 TRACE("(%s)\n",debugstr_w(lpszPath
));
270 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
276 if (lpszPath
[-1] != '\\')
285 /*************************************************************************
286 * PathBuildRootA [SHLWAPI.@]
288 * Create a root drive string (e.g. "A:\") from a drive number.
291 * lpszPath [O] Destination for the drive string
297 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
299 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
301 TRACE("(%p,%d)\n", lpszPath
, drive
);
303 if (lpszPath
&& drive
>= 0 && drive
< 26)
305 lpszPath
[0] = 'A' + drive
;
313 /*************************************************************************
314 * PathBuildRootW [SHLWAPI.@]
316 * See PathBuildRootA.
318 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
320 TRACE("(%p,%d)\n", lpszPath
, drive
);
322 if (lpszPath
&& drive
>= 0 && drive
< 26)
324 lpszPath
[0] = 'A' + drive
;
332 /*************************************************************************
333 * PathFindFileNameA [SHLWAPI.@]
335 * Locate the start of the file name in a path
338 * lpszPath [I] Path to search
341 * A pointer to the first character of the file name
343 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
345 LPCSTR lastSlash
= lpszPath
;
347 TRACE("(%s)\n",debugstr_a(lpszPath
));
349 while (lpszPath
&& *lpszPath
)
351 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
352 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
353 lastSlash
= lpszPath
+ 1;
354 lpszPath
= CharNextA(lpszPath
);
356 return (LPSTR
)lastSlash
;
359 /*************************************************************************
360 * PathFindFileNameW [SHLWAPI.@]
362 * See PathFindFileNameA.
364 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
366 LPCWSTR lastSlash
= lpszPath
;
368 TRACE("(%s)\n",debugstr_w(lpszPath
));
370 while (lpszPath
&& *lpszPath
)
372 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
373 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
374 lastSlash
= lpszPath
+ 1;
377 return (LPWSTR
)lastSlash
;
380 /*************************************************************************
381 * PathFindExtensionA [SHLWAPI.@]
383 * Locate the start of the file extension in a path
386 * lpszPath [I] The path to search
389 * A pointer to the first character of the extension, the end of
390 * the string if the path has no extension, or NULL If lpszPath is NULL
392 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
394 LPCSTR lastpoint
= NULL
;
396 TRACE("(%s)\n", debugstr_a(lpszPath
));
402 if (*lpszPath
== '\\' || *lpszPath
==' ')
404 else if (*lpszPath
== '.')
405 lastpoint
= lpszPath
;
406 lpszPath
= CharNextA(lpszPath
);
409 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
412 /*************************************************************************
413 * PathFindExtensionW [SHLWAPI.@]
415 * See PathFindExtensionA.
417 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
419 LPCWSTR lastpoint
= NULL
;
421 TRACE("(%s)\n", debugstr_w(lpszPath
));
427 if (*lpszPath
== '\\' || *lpszPath
==' ')
429 else if (*lpszPath
== '.')
430 lastpoint
= lpszPath
;
434 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
437 /*************************************************************************
438 * PathGetArgsA [SHLWAPI.@]
440 * Find the next argument in a string delimited by spaces.
443 * lpszPath [I] The string to search for arguments in
446 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
449 * Spaces in quoted strings are ignored as delimiters.
451 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
453 BOOL bSeenQuote
= FALSE
;
455 TRACE("(%s)\n",debugstr_a(lpszPath
));
461 if ((*lpszPath
==' ') && !bSeenQuote
)
462 return (LPSTR
)lpszPath
+ 1;
463 if (*lpszPath
== '"')
464 bSeenQuote
= !bSeenQuote
;
465 lpszPath
= CharNextA(lpszPath
);
468 return (LPSTR
)lpszPath
;
471 /*************************************************************************
472 * PathGetArgsW [SHLWAPI.@]
476 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
478 BOOL bSeenQuote
= FALSE
;
480 TRACE("(%s)\n",debugstr_w(lpszPath
));
486 if ((*lpszPath
==' ') && !bSeenQuote
)
487 return (LPWSTR
)lpszPath
+ 1;
488 if (*lpszPath
== '"')
489 bSeenQuote
= !bSeenQuote
;
493 return (LPWSTR
)lpszPath
;
496 /*************************************************************************
497 * PathGetDriveNumberA [SHLWAPI.@]
499 * Return the drive number from a path
502 * lpszPath [I] Path to get the drive number from
505 * Success: The drive number corresponding to the drive in the path
506 * Failure: -1, if lpszPath contains no valid drive
508 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
510 TRACE ("(%s)\n",debugstr_a(lpszPath
));
512 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
513 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
514 return tolower(*lpszPath
) - 'a';
518 /*************************************************************************
519 * PathGetDriveNumberW [SHLWAPI.@]
521 * See PathGetDriveNumberA.
523 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
525 TRACE ("(%s)\n",debugstr_w(lpszPath
));
529 WCHAR tl
= tolowerW(lpszPath
[0]);
530 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
536 /*************************************************************************
537 * PathRemoveFileSpecA [SHLWAPI.@]
539 * Remove the file specification from a path.
542 * lpszPath [I/O] Path to remove the file spec from
545 * TRUE If the path was valid and modified
548 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
550 LPSTR lpszFileSpec
= lpszPath
;
551 BOOL bModified
= FALSE
;
553 TRACE("(%s)\n",debugstr_a(lpszPath
));
557 /* Skip directory or UNC path */
558 if (*lpszPath
== '\\')
559 lpszFileSpec
= ++lpszPath
;
560 if (*lpszPath
== '\\')
561 lpszFileSpec
= ++lpszPath
;
565 if(*lpszPath
== '\\')
566 lpszFileSpec
= lpszPath
; /* Skip dir */
567 else if(*lpszPath
== ':')
569 lpszFileSpec
= ++lpszPath
; /* Skip drive */
570 if (*lpszPath
== '\\')
573 if (!(lpszPath
= CharNextA(lpszPath
)))
579 *lpszFileSpec
= '\0';
586 /*************************************************************************
587 * PathRemoveFileSpecW [SHLWAPI.@]
589 * See PathRemoveFileSpecA.
591 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
593 LPWSTR lpszFileSpec
= lpszPath
;
594 BOOL bModified
= FALSE
;
596 TRACE("(%s)\n",debugstr_w(lpszPath
));
600 /* Skip directory or UNC path */
601 if (*lpszPath
== '\\')
602 lpszFileSpec
= ++lpszPath
;
603 if (*lpszPath
== '\\')
604 lpszFileSpec
= ++lpszPath
;
608 if(*lpszPath
== '\\')
609 lpszFileSpec
= lpszPath
; /* Skip dir */
610 else if(*lpszPath
== ':')
612 lpszFileSpec
= ++lpszPath
; /* Skip drive */
613 if (*lpszPath
== '\\')
621 *lpszFileSpec
= '\0';
628 /*************************************************************************
629 * PathStripPathA [SHLWAPI.@]
631 * Remove the initial path from the beginning of a filename
634 * lpszPath [I/O] Path to remove the initial path from
639 void WINAPI
PathStripPathA(LPSTR lpszPath
)
641 TRACE("(%s)\n", debugstr_a(lpszPath
));
645 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
647 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
651 /*************************************************************************
652 * PathStripPathW [SHLWAPI.@]
654 * See PathStripPathA.
656 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
660 TRACE("(%s)\n", debugstr_w(lpszPath
));
661 lpszFileName
= PathFindFileNameW(lpszPath
);
663 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
666 /*************************************************************************
667 * PathStripToRootA [SHLWAPI.@]
669 * Reduce a path to its root.
672 * lpszPath [I/O] the path to reduce
675 * Success: TRUE if the stripped path is a root path
676 * Failure: FALSE if the path cannot be stripped or is NULL
678 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
680 TRACE("(%s)\n", debugstr_a(lpszPath
));
684 while(!PathIsRootA(lpszPath
))
685 if (!PathRemoveFileSpecA(lpszPath
))
690 /*************************************************************************
691 * PathStripToRootW [SHLWAPI.@]
693 * See PathStripToRootA.
695 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
697 TRACE("(%s)\n", debugstr_w(lpszPath
));
701 while(!PathIsRootW(lpszPath
))
702 if (!PathRemoveFileSpecW(lpszPath
))
707 /*************************************************************************
708 * PathRemoveArgsA [SHLWAPI.@]
710 * Strip space separated arguments from a path.
713 * lpszPath [I/O] Path to remove arguments from
718 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
720 TRACE("(%s)\n",debugstr_a(lpszPath
));
724 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
729 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
730 if(*lpszLastChar
== ' ')
731 *lpszLastChar
= '\0';
736 /*************************************************************************
737 * PathRemoveArgsW [SHLWAPI.@]
739 * See PathRemoveArgsA.
741 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
743 TRACE("(%s)\n",debugstr_w(lpszPath
));
747 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
748 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
753 /*************************************************************************
754 * PathRemoveExtensionA [SHLWAPI.@]
756 * Remove the file extension from a path
759 * lpszPath [I/O] Path to remove the extension from
762 * The NUL terminator must be written only if extension exists
763 * and if the pointed character is not already NUL.
768 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
770 TRACE("(%s)\n", debugstr_a(lpszPath
));
774 lpszPath
= PathFindExtensionA(lpszPath
);
775 if (lpszPath
&& *lpszPath
!= '\0')
780 /*************************************************************************
781 * PathRemoveExtensionW [SHLWAPI.@]
783 * See PathRemoveExtensionA.
785 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
787 TRACE("(%s)\n", debugstr_w(lpszPath
));
791 lpszPath
= PathFindExtensionW(lpszPath
);
792 if (lpszPath
&& *lpszPath
!= '\0')
797 /*************************************************************************
798 * PathRemoveBackslashA [SHLWAPI.@]
800 * Remove a trailing backslash from a path.
803 * lpszPath [I/O] Path to remove backslash from
806 * Success: A pointer to the end of the path
807 * Failure: NULL, if lpszPath is NULL
809 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
813 TRACE("(%s)\n", debugstr_a(lpszPath
));
817 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
818 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
824 /*************************************************************************
825 * PathRemoveBackslashW [SHLWAPI.@]
827 * See PathRemoveBackslashA.
829 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
831 LPWSTR szTemp
= NULL
;
833 TRACE("(%s)\n", debugstr_w(lpszPath
));
837 szTemp
= lpszPath
+ strlenW(lpszPath
);
838 if (szTemp
> lpszPath
) szTemp
--;
839 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
845 /*************************************************************************
846 * PathRemoveBlanksA [SHLWAPI.@]
848 * Remove Spaces from the start and end of a path.
851 * lpszPath [I/O] Path to strip blanks from
856 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
858 TRACE("(%s)\n", debugstr_a(lpszPath
));
860 if(lpszPath
&& *lpszPath
)
862 LPSTR start
= lpszPath
;
864 while (*lpszPath
== ' ')
865 lpszPath
= CharNextA(lpszPath
);
868 *start
++ = *lpszPath
++;
870 if (start
!= lpszPath
)
871 while (start
[-1] == ' ')
877 /*************************************************************************
878 * PathRemoveBlanksW [SHLWAPI.@]
880 * See PathRemoveBlanksA.
882 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
884 TRACE("(%s)\n", debugstr_w(lpszPath
));
886 if(lpszPath
&& *lpszPath
)
888 LPWSTR start
= lpszPath
;
890 while (*lpszPath
== ' ')
894 *start
++ = *lpszPath
++;
896 if (start
!= lpszPath
)
897 while (start
[-1] == ' ')
903 /*************************************************************************
904 * PathQuoteSpacesA [SHLWAPI.@]
906 * Surround a path containing spaces in quotes.
909 * lpszPath [I/O] Path to quote
915 * The path is not changed if it is invalid or has no spaces.
917 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
919 TRACE("(%s)\n", debugstr_a(lpszPath
));
921 if(lpszPath
&& StrChrA(lpszPath
,' '))
923 size_t iLen
= strlen(lpszPath
) + 1;
925 if (iLen
+ 2 < MAX_PATH
)
927 memmove(lpszPath
+ 1, lpszPath
, iLen
);
929 lpszPath
[iLen
] = '"';
930 lpszPath
[iLen
+ 1] = '\0';
935 /*************************************************************************
936 * PathQuoteSpacesW [SHLWAPI.@]
938 * See PathQuoteSpacesA.
940 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
942 TRACE("(%s)\n", debugstr_w(lpszPath
));
944 if(lpszPath
&& StrChrW(lpszPath
,' '))
946 int iLen
= strlenW(lpszPath
) + 1;
948 if (iLen
+ 2 < MAX_PATH
)
950 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
952 lpszPath
[iLen
] = '"';
953 lpszPath
[iLen
+ 1] = '\0';
958 /*************************************************************************
959 * PathUnquoteSpacesA [SHLWAPI.@]
961 * Remove quotes ("") from around a path, if present.
964 * lpszPath [I/O] Path to strip quotes from
970 * If the path contains a single quote only, an empty string will result.
971 * Otherwise quotes are only removed if they appear at the start and end
974 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
976 TRACE("(%s)\n", debugstr_a(lpszPath
));
978 if (lpszPath
&& *lpszPath
== '"')
980 DWORD dwLen
= strlen(lpszPath
) - 1;
982 if (lpszPath
[dwLen
] == '"')
984 lpszPath
[dwLen
] = '\0';
985 for (; *lpszPath
; lpszPath
++)
986 *lpszPath
= lpszPath
[1];
991 /*************************************************************************
992 * PathUnquoteSpacesW [SHLWAPI.@]
994 * See PathUnquoteSpacesA.
996 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
998 TRACE("(%s)\n", debugstr_w(lpszPath
));
1000 if (lpszPath
&& *lpszPath
== '"')
1002 DWORD dwLen
= strlenW(lpszPath
) - 1;
1004 if (lpszPath
[dwLen
] == '"')
1006 lpszPath
[dwLen
] = '\0';
1007 for (; *lpszPath
; lpszPath
++)
1008 *lpszPath
= lpszPath
[1];
1013 /*************************************************************************
1014 * PathParseIconLocationA [SHLWAPI.@]
1016 * Parse the location of an icon from a path.
1019 * lpszPath [I/O] The path to parse the icon location from.
1022 * Success: The number of the icon
1023 * Failure: 0 if the path does not contain an icon location or is NULL
1026 * The path has surrounding quotes and spaces removed regardless
1027 * of whether the call succeeds or not.
1029 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1034 TRACE("(%s)\n", debugstr_a(lpszPath
));
1038 if ((lpszComma
= strchr(lpszPath
, ',')))
1040 *lpszComma
++ = '\0';
1041 iRet
= StrToIntA(lpszComma
);
1043 PathUnquoteSpacesA(lpszPath
);
1044 PathRemoveBlanksA(lpszPath
);
1049 /*************************************************************************
1050 * PathParseIconLocationW [SHLWAPI.@]
1052 * See PathParseIconLocationA.
1054 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1059 TRACE("(%s)\n", debugstr_w(lpszPath
));
1063 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1065 *lpszComma
++ = '\0';
1066 iRet
= StrToIntW(lpszComma
);
1068 PathUnquoteSpacesW(lpszPath
);
1069 PathRemoveBlanksW(lpszPath
);
1074 /*************************************************************************
1077 * Unicode version of PathFileExistsDefExtA.
1079 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1081 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1082 { '.', 'c', 'o', 'm', 0},
1083 { '.', 'e', 'x', 'e', 0},
1084 { '.', 'b', 'a', 't', 0},
1085 { '.', 'l', 'n', 'k', 0},
1086 { '.', 'c', 'm', 'd', 0},
1089 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1091 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1096 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1097 if (!*szExt
|| dwWhich
& 0x40)
1100 int iLen
= lstrlenW(lpszPath
);
1101 if (iLen
> (MAX_PATH
- 5))
1103 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1105 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1106 if (PathFileExistsW(lpszPath
))
1111 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1115 return PathFileExistsW(lpszPath
);
1118 /*************************************************************************
1121 * Determine if a file exists locally and is of an executable type.
1124 * lpszPath [I/O] File to search for
1125 * dwWhich [I] Type of executable to search for
1128 * TRUE If the file was found. lpszPath contains the file name.
1132 * lpszPath is modified in place and must be at least MAX_PATH in length.
1133 * If the function returns FALSE, the path is modified to its original state.
1134 * If the given path contains an extension or dwWhich is 0, executable
1135 * extensions are not checked.
1137 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1138 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1139 * their own developers exclusive use. Monopoly, anyone?
1141 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1145 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1149 WCHAR szPath
[MAX_PATH
];
1150 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1151 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1153 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1158 /*************************************************************************
1159 * SHLWAPI_PathFindInOtherDirs
1161 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1163 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1165 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1166 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1170 WCHAR buff
[MAX_PATH
];
1172 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1174 /* Try system directories */
1175 GetSystemDirectoryW(buff
, MAX_PATH
);
1176 if (!PathAppendW(buff
, lpszFile
))
1178 if (PathFileExistsDefExtW(buff
, dwWhich
))
1180 strcpyW(lpszFile
, buff
);
1183 GetWindowsDirectoryW(buff
, MAX_PATH
);
1184 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1186 if (PathFileExistsDefExtW(buff
, dwWhich
))
1188 strcpyW(lpszFile
, buff
);
1191 GetWindowsDirectoryW(buff
, MAX_PATH
);
1192 if (!PathAppendW(buff
, lpszFile
))
1194 if (PathFileExistsDefExtW(buff
, dwWhich
))
1196 strcpyW(lpszFile
, buff
);
1199 /* Try dirs listed in %PATH% */
1200 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1202 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1205 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1206 lpszCurr
= lpszPATH
;
1209 LPCWSTR lpszEnd
= lpszCurr
;
1210 LPWSTR pBuff
= buff
;
1212 while (*lpszEnd
== ' ')
1214 while (*lpszEnd
&& *lpszEnd
!= ';')
1215 *pBuff
++ = *lpszEnd
++;
1219 lpszCurr
= lpszEnd
+ 1;
1221 lpszCurr
= NULL
; /* Last Path, terminate after this */
1223 if (!PathAppendW(buff
, lpszFile
))
1225 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1228 if (PathFileExistsDefExtW(buff
, dwWhich
))
1230 strcpyW(lpszFile
, buff
);
1231 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1235 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1239 /*************************************************************************
1242 * Search a range of paths for a specific type of executable.
1245 * lpszFile [I/O] File to search for
1246 * lppszOtherDirs [I] Other directories to look in
1247 * dwWhich [I] Type of executable to search for
1250 * Success: TRUE. The path to the executable is stored in lpszFile.
1251 * Failure: FALSE. The path to the executable is unchanged.
1253 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1255 WCHAR szFile
[MAX_PATH
];
1256 WCHAR buff
[MAX_PATH
];
1258 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1260 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1263 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1265 /* Search provided directories first */
1266 if (lppszOtherDirs
&& *lppszOtherDirs
)
1268 WCHAR szOther
[MAX_PATH
];
1269 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1271 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1273 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1274 PathCombineW(buff
, szOther
, szFile
);
1275 if (PathFileExistsDefExtW(buff
, dwWhich
))
1277 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1283 /* Not found, try system and path dirs */
1284 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1286 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1292 /*************************************************************************
1295 * Unicode version of PathFindOnPathExA.
1297 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1299 WCHAR buff
[MAX_PATH
];
1301 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1303 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1306 /* Search provided directories first */
1307 if (lppszOtherDirs
&& *lppszOtherDirs
)
1309 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1310 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1312 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1313 if (PathFileExistsDefExtW(buff
, dwWhich
))
1315 strcpyW(lpszFile
, buff
);
1321 /* Not found, try system and path dirs */
1322 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1325 /*************************************************************************
1326 * PathFindOnPathA [SHLWAPI.@]
1328 * Search a range of paths for an executable.
1331 * lpszFile [I/O] File to search for
1332 * lppszOtherDirs [I] Other directories to look in
1335 * Success: TRUE. The path to the executable is stored in lpszFile.
1336 * Failure: FALSE. The path to the executable is unchanged.
1338 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1340 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1341 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1344 /*************************************************************************
1345 * PathFindOnPathW [SHLWAPI.@]
1347 * See PathFindOnPathA.
1349 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1351 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1352 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1355 /*************************************************************************
1356 * PathCompactPathExA [SHLWAPI.@]
1358 * Compact a path into a given number of characters.
1361 * lpszDest [O] Destination for compacted path
1362 * lpszPath [I] Source path
1363 * cchMax [I] Maximum size of compacted path
1364 * dwFlags [I] Reserved
1367 * Success: TRUE. The compacted path is written to lpszDest.
1368 * Failure: FALSE. lpszPath is undefined.
1371 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1373 * The Win32 version of this function contains a bug: When cchMax == 7,
1374 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1377 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1378 * because Win32 will insert a "\" in lpszDest, even if one is
1379 * not present in the original path.
1381 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1382 UINT cchMax
, DWORD dwFlags
)
1386 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1388 if (lpszPath
&& lpszDest
)
1390 WCHAR szPath
[MAX_PATH
];
1391 WCHAR szDest
[MAX_PATH
];
1393 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1395 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1396 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1401 /*************************************************************************
1402 * PathCompactPathExW [SHLWAPI.@]
1404 * See PathCompactPathExA.
1406 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1407 UINT cchMax
, DWORD dwFlags
)
1409 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1411 DWORD dwLen
, dwFileLen
= 0;
1413 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1420 WARN("Invalid lpszDest would crash under Win32!\n");
1429 dwLen
= strlenW(lpszPath
) + 1;
1433 /* Don't need to compact */
1434 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1438 /* Path must be compacted to fit into lpszDest */
1439 lpszFile
= PathFindFileNameW(lpszPath
);
1440 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1442 if (dwFileLen
== dwLen
)
1444 /* No root in psth */
1447 while (--cchMax
> 0) /* No room left for anything but ellipses */
1452 /* Compact the file name with ellipses at the end */
1454 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1455 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1458 /* We have a root in the path */
1459 lpszFile
--; /* Start compacted filename with the path separator */
1462 if (dwFileLen
+ 3 > cchMax
)
1464 /* Compact the file name */
1467 while (--cchMax
> 0) /* No room left for anything but ellipses */
1472 strcpyW(lpszDest
, szEllipses
);
1475 *lpszDest
++ = *lpszFile
++;
1478 while (--cchMax
> 0) /* No room left for anything but ellipses */
1484 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1485 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1489 /* Only the root needs to be Compacted */
1490 dwLen
= cchMax
- dwFileLen
- 3;
1491 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1492 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1493 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1497 /*************************************************************************
1498 * PathIsRelativeA [SHLWAPI.@]
1500 * Determine if a path is a relative path.
1503 * lpszPath [I] Path to check
1506 * TRUE: The path is relative, or is invalid.
1507 * FALSE: The path is not relative.
1509 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1511 TRACE("(%s)\n",debugstr_a(lpszPath
));
1513 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1515 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1520 /*************************************************************************
1521 * PathIsRelativeW [SHLWAPI.@]
1523 * See PathIsRelativeA.
1525 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1527 TRACE("(%s)\n",debugstr_w(lpszPath
));
1529 if (!lpszPath
|| !*lpszPath
)
1531 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1536 /*************************************************************************
1537 * PathIsRootA [SHLWAPI.@]
1539 * Determine if a path is a root path.
1542 * lpszPath [I] Path to check
1545 * TRUE If lpszPath is valid and a root path,
1548 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1550 TRACE("(%s)\n", debugstr_a(lpszPath
));
1552 if (lpszPath
&& *lpszPath
)
1554 if (*lpszPath
== '\\')
1557 return TRUE
; /* \ */
1558 else if (lpszPath
[1]=='\\')
1560 BOOL bSeenSlash
= FALSE
;
1563 /* Check for UNC root path */
1566 if (*lpszPath
== '\\')
1572 lpszPath
= CharNextA(lpszPath
);
1577 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1578 return TRUE
; /* X:\ */
1583 /*************************************************************************
1584 * PathIsRootW [SHLWAPI.@]
1588 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1590 TRACE("(%s)\n", debugstr_w(lpszPath
));
1592 if (lpszPath
&& *lpszPath
)
1594 if (*lpszPath
== '\\')
1597 return TRUE
; /* \ */
1598 else if (lpszPath
[1]=='\\')
1600 BOOL bSeenSlash
= FALSE
;
1603 /* Check for UNC root path */
1606 if (*lpszPath
== '\\')
1617 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1618 return TRUE
; /* X:\ */
1623 /*************************************************************************
1624 * PathIsDirectoryA [SHLWAPI.@]
1626 * Determine if a path is a valid directory
1629 * lpszPath [I] Path to check.
1632 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1633 * FALSE if lpszPath is invalid or not a directory.
1636 * Although this function is prototyped as returning a BOOL, it returns
1637 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1639 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1644 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1648 TRACE("(%s)\n", debugstr_a(lpszPath
));
1650 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1653 if (PathIsUNCServerShareA(lpszPath
))
1655 FIXME("UNC Server Share not yet supported - FAILING\n");
1659 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1661 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1664 /*************************************************************************
1665 * PathIsDirectoryW [SHLWAPI.@]
1667 * See PathIsDirectoryA.
1669 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1673 TRACE("(%s)\n", debugstr_w(lpszPath
));
1675 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1678 if (PathIsUNCServerShareW(lpszPath
))
1680 FIXME("UNC Server Share not yet supported - FAILING\n");
1684 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1686 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1689 /*************************************************************************
1690 * PathFileExistsA [SHLWAPI.@]
1692 * Determine if a file exists.
1695 * lpszPath [I] Path to check
1698 * TRUE If the file exists and is readable
1701 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1706 TRACE("(%s)\n",debugstr_a(lpszPath
));
1711 /* Prevent a dialog box if path is on a disk that has been ejected. */
1712 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1713 dwAttr
= GetFileAttributesA(lpszPath
);
1714 SetErrorMode(iPrevErrMode
);
1715 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1718 /*************************************************************************
1719 * PathFileExistsW [SHLWAPI.@]
1721 * See PathFileExistsA.
1723 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1728 TRACE("(%s)\n",debugstr_w(lpszPath
));
1733 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1734 dwAttr
= GetFileAttributesW(lpszPath
);
1735 SetErrorMode(iPrevErrMode
);
1736 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1739 /*************************************************************************
1740 * PathFileExistsAndAttributesA [SHLWAPI.445]
1742 * Determine if a file exists.
1745 * lpszPath [I] Path to check
1746 * dwAttr [O] attributes of file
1749 * TRUE If the file exists and is readable
1752 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1757 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1760 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1765 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1766 dwVal
= GetFileAttributesA(lpszPath
);
1767 SetErrorMode(iPrevErrMode
);
1770 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1773 /*************************************************************************
1774 * PathFileExistsAndAttributesW [SHLWAPI.446]
1776 * See PathFileExistsA.
1778 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1783 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1788 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1789 dwVal
= GetFileAttributesW(lpszPath
);
1790 SetErrorMode(iPrevErrMode
);
1793 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1796 /*************************************************************************
1797 * PathMatchSingleMaskA [internal]
1799 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1801 while (*name
&& *mask
&& *mask
!=';')
1807 if (PathMatchSingleMaskA(name
,mask
+1))
1808 return TRUE
; /* try substrings */
1813 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1816 name
= CharNextA(name
);
1817 mask
= CharNextA(mask
);
1822 while (*mask
== '*')
1824 if (!*mask
|| *mask
== ';')
1830 /*************************************************************************
1831 * PathMatchSingleMaskW [internal]
1833 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1835 while (*name
&& *mask
&& *mask
!= ';')
1841 if (PathMatchSingleMaskW(name
,mask
+1))
1842 return TRUE
; /* try substrings */
1847 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1855 while (*mask
== '*')
1857 if (!*mask
|| *mask
== ';')
1863 /*************************************************************************
1864 * PathMatchSpecA [SHLWAPI.@]
1866 * Determine if a path matches one or more search masks.
1869 * lpszPath [I] Path to check
1870 * lpszMask [I] Search mask(s)
1873 * TRUE If lpszPath is valid and is matched
1877 * Multiple search masks may be given if they are separated by ";". The
1878 * pattern "*.*" is treated specially in that it matches all paths (for
1879 * backwards compatibility with DOS).
1881 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1883 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1885 if (!lstrcmpA(lpszMask
, "*.*"))
1886 return TRUE
; /* Matches every path */
1890 while (*lpszMask
== ' ')
1891 lpszMask
++; /* Eat leading spaces */
1893 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1894 return TRUE
; /* Matches the current mask */
1896 while (*lpszMask
&& *lpszMask
!= ';')
1897 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1899 if (*lpszMask
== ';')
1905 /*************************************************************************
1906 * PathMatchSpecW [SHLWAPI.@]
1908 * See PathMatchSpecA.
1910 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1912 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1914 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1916 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1917 return TRUE
; /* Matches every path */
1921 while (*lpszMask
== ' ')
1922 lpszMask
++; /* Eat leading spaces */
1924 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1925 return TRUE
; /* Matches the current path */
1927 while (*lpszMask
&& *lpszMask
!= ';')
1928 lpszMask
++; /* masks separated by ';' */
1930 if (*lpszMask
== ';')
1936 /*************************************************************************
1937 * PathIsSameRootA [SHLWAPI.@]
1939 * Determine if two paths share the same root.
1942 * lpszPath1 [I] Source path
1943 * lpszPath2 [I] Path to compare with
1946 * TRUE If both paths are valid and share the same root.
1947 * FALSE If either path is invalid or the paths do not share the same root.
1949 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1954 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1956 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1959 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1960 if (lpszStart
- lpszPath1
> dwLen
)
1961 return FALSE
; /* Paths not common up to length of the root */
1965 /*************************************************************************
1966 * PathIsSameRootW [SHLWAPI.@]
1968 * See PathIsSameRootA.
1970 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1975 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1977 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1980 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1981 if (lpszStart
- lpszPath1
> dwLen
)
1982 return FALSE
; /* Paths not common up to length of the root */
1986 /*************************************************************************
1987 * PathIsContentTypeA [SHLWAPI.@]
1989 * Determine if a file is of a given registered content type.
1992 * lpszPath [I] File to check
1993 * lpszContentType [I] Content type to check for
1996 * TRUE If lpszPath is a given registered content type,
2000 * This function looks up the registered content type for lpszPath. If
2001 * a content type is registered, it is compared (case insensitively) to
2002 * lpszContentType. Only if this matches does the function succeed.
2004 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2008 char szBuff
[MAX_PATH
];
2010 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2012 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2013 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2014 REG_NONE
, szBuff
, &dwDummy
) &&
2015 !strcasecmp(lpszContentType
, szBuff
))
2022 /*************************************************************************
2023 * PathIsContentTypeW [SHLWAPI.@]
2025 * See PathIsContentTypeA.
2027 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2029 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2032 WCHAR szBuff
[MAX_PATH
];
2034 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2036 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2037 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2038 REG_NONE
, szBuff
, &dwDummy
) &&
2039 !strcmpiW(lpszContentType
, szBuff
))
2046 /*************************************************************************
2047 * PathIsFileSpecA [SHLWAPI.@]
2049 * Determine if a path is a file specification.
2052 * lpszPath [I] Path to check
2055 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2058 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2060 TRACE("(%s)\n", debugstr_a(lpszPath
));
2067 if (*lpszPath
== '\\' || *lpszPath
== ':')
2069 lpszPath
= CharNextA(lpszPath
);
2074 /*************************************************************************
2075 * PathIsFileSpecW [SHLWAPI.@]
2077 * See PathIsFileSpecA.
2079 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2081 TRACE("(%s)\n", debugstr_w(lpszPath
));
2088 if (*lpszPath
== '\\' || *lpszPath
== ':')
2095 /*************************************************************************
2096 * PathIsPrefixA [SHLWAPI.@]
2098 * Determine if a path is a prefix of another.
2101 * lpszPrefix [I] Prefix
2102 * lpszPath [I] Path to check
2105 * TRUE If lpszPath has lpszPrefix as its prefix,
2106 * FALSE If either path is NULL or lpszPrefix is not a prefix
2108 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2110 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2112 if (lpszPrefix
&& lpszPath
&&
2113 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2118 /*************************************************************************
2119 * PathIsPrefixW [SHLWAPI.@]
2121 * See PathIsPrefixA.
2123 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2125 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2127 if (lpszPrefix
&& lpszPath
&&
2128 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2133 /*************************************************************************
2134 * PathIsSystemFolderA [SHLWAPI.@]
2136 * Determine if a path or file attributes are a system folder.
2139 * lpszPath [I] Path to check.
2140 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2143 * TRUE If lpszPath or dwAttrib are a system folder.
2144 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2146 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2148 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2150 if (lpszPath
&& *lpszPath
)
2151 dwAttrib
= GetFileAttributesA(lpszPath
);
2153 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2154 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2159 /*************************************************************************
2160 * PathIsSystemFolderW [SHLWAPI.@]
2162 * See PathIsSystemFolderA.
2164 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2166 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2168 if (lpszPath
&& *lpszPath
)
2169 dwAttrib
= GetFileAttributesW(lpszPath
);
2171 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2172 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2177 /*************************************************************************
2178 * PathIsUNCA [SHLWAPI.@]
2180 * Determine if a path is in UNC format.
2183 * lpszPath [I] Path to check
2186 * TRUE: The path is UNC.
2187 * FALSE: The path is not UNC or is NULL.
2189 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2191 TRACE("(%s)\n",debugstr_a(lpszPath
));
2193 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2198 /*************************************************************************
2199 * PathIsUNCW [SHLWAPI.@]
2203 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2205 TRACE("(%s)\n",debugstr_w(lpszPath
));
2207 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2212 /*************************************************************************
2213 * PathIsUNCServerA [SHLWAPI.@]
2215 * Determine if a path is a UNC server name ("\\SHARENAME").
2218 * lpszPath [I] Path to check.
2221 * TRUE If lpszPath is a valid UNC server name.
2225 * This routine is bug compatible with Win32: Server names with a
2226 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2227 * Fixing this bug may break other shlwapi functions!
2229 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2231 TRACE("(%s)\n", debugstr_a(lpszPath
));
2233 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2237 if (*lpszPath
== '\\')
2239 lpszPath
= CharNextA(lpszPath
);
2246 /*************************************************************************
2247 * PathIsUNCServerW [SHLWAPI.@]
2249 * See PathIsUNCServerA.
2251 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2253 TRACE("(%s)\n", debugstr_w(lpszPath
));
2255 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2257 return !strchrW( lpszPath
+ 2, '\\' );
2262 /*************************************************************************
2263 * PathIsUNCServerShareA [SHLWAPI.@]
2265 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2268 * lpszPath [I] Path to check.
2271 * TRUE If lpszPath is a valid UNC server share.
2275 * This routine is bug compatible with Win32: Server shares with a
2276 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2277 * Fixing this bug may break other shlwapi functions!
2279 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2281 TRACE("(%s)\n", debugstr_a(lpszPath
));
2283 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2285 BOOL bSeenSlash
= FALSE
;
2288 if (*lpszPath
== '\\')
2294 lpszPath
= CharNextA(lpszPath
);
2301 /*************************************************************************
2302 * PathIsUNCServerShareW [SHLWAPI.@]
2304 * See PathIsUNCServerShareA.
2306 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2308 TRACE("(%s)\n", debugstr_w(lpszPath
));
2310 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2312 BOOL bSeenSlash
= FALSE
;
2315 if (*lpszPath
== '\\')
2328 /*************************************************************************
2329 * PathCanonicalizeA [SHLWAPI.@]
2331 * Convert a path to its canonical form.
2334 * lpszBuf [O] Output path
2335 * lpszPath [I] Path to canonicalize
2338 * Success: TRUE. lpszBuf contains the output path,
2339 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2341 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2345 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2350 if (!lpszBuf
|| !lpszPath
)
2351 SetLastError(ERROR_INVALID_PARAMETER
);
2354 WCHAR szPath
[MAX_PATH
];
2355 WCHAR szBuff
[MAX_PATH
];
2356 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2359 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2362 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2363 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2369 /*************************************************************************
2370 * PathCanonicalizeW [SHLWAPI.@]
2372 * See PathCanonicalizeA.
2374 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2376 LPWSTR lpszDst
= lpszBuf
;
2377 LPCWSTR lpszSrc
= lpszPath
;
2379 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2384 if (!lpszBuf
|| !lpszPath
)
2386 SetLastError(ERROR_INVALID_PARAMETER
);
2397 /* Copy path root */
2398 if (*lpszSrc
== '\\')
2400 *lpszDst
++ = *lpszSrc
++;
2402 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2405 *lpszDst
++ = *lpszSrc
++;
2406 *lpszDst
++ = *lpszSrc
++;
2407 if (*lpszSrc
== '\\')
2408 *lpszDst
++ = *lpszSrc
++;
2411 /* Canonicalize the rest of the path */
2414 if (*lpszSrc
== '.')
2416 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2418 lpszSrc
+= 2; /* Skip .\ */
2420 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2422 /* \.. backs up a directory, over the root if it has no \ following X:.
2423 * .. is ignored if it would remove a UNC server name or initial \\
2425 if (lpszDst
!= lpszBuf
)
2427 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2428 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2429 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2431 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2434 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2436 if (*lpszDst
== '\\')
2437 lpszDst
++; /* Reset to last '\' */
2439 lpszDst
= lpszBuf
; /* Start path again from new root */
2441 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2444 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2446 if (lpszDst
== lpszBuf
)
2452 lpszSrc
+= 2; /* Skip .. in src path */
2455 *lpszDst
++ = *lpszSrc
++;
2458 *lpszDst
++ = *lpszSrc
++;
2460 /* Append \ to naked drive specs */
2461 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2467 /*************************************************************************
2468 * PathFindNextComponentA [SHLWAPI.@]
2470 * Find the next component in a path.
2473 * lpszPath [I] Path to find next component in
2476 * Success: A pointer to the next component, or the end of the string.
2477 * Failure: NULL, If lpszPath is invalid
2480 * A 'component' is either a backslash character (\) or UNC marker (\\).
2481 * Because of this, relative paths (e.g "c:foo") are regarded as having
2482 * only one component.
2484 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2488 TRACE("(%s)\n", debugstr_a(lpszPath
));
2490 if(!lpszPath
|| !*lpszPath
)
2493 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2495 if (lpszSlash
[1] == '\\')
2497 return lpszSlash
+ 1;
2499 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2502 /*************************************************************************
2503 * PathFindNextComponentW [SHLWAPI.@]
2505 * See PathFindNextComponentA.
2507 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2511 TRACE("(%s)\n", debugstr_w(lpszPath
));
2513 if(!lpszPath
|| !*lpszPath
)
2516 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2518 if (lpszSlash
[1] == '\\')
2520 return lpszSlash
+ 1;
2522 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2525 /*************************************************************************
2526 * PathAddExtensionA [SHLWAPI.@]
2528 * Add a file extension to a path
2531 * lpszPath [I/O] Path to add extension to
2532 * lpszExtension [I] Extension to add to lpszPath
2535 * TRUE If the path was modified,
2536 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2537 * extension already, or the new path length is too big.
2540 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2541 * does not do this, so the behaviour was removed.
2543 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2547 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2549 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2552 dwLen
= strlen(lpszPath
);
2554 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2557 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2561 /*************************************************************************
2562 * PathAddExtensionW [SHLWAPI.@]
2564 * See PathAddExtensionA.
2566 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2570 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2572 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2575 dwLen
= strlenW(lpszPath
);
2577 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2580 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2584 /*************************************************************************
2585 * PathMakePrettyA [SHLWAPI.@]
2587 * Convert an uppercase DOS filename into lowercase.
2590 * lpszPath [I/O] Path to convert.
2593 * TRUE If the path was an uppercase DOS path and was converted,
2596 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2598 LPSTR pszIter
= lpszPath
;
2600 TRACE("(%s)\n", debugstr_a(lpszPath
));
2609 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2610 return FALSE
; /* Not DOS path */
2613 pszIter
= lpszPath
+ 1;
2616 *pszIter
= tolower(*pszIter
);
2623 /*************************************************************************
2624 * PathMakePrettyW [SHLWAPI.@]
2626 * See PathMakePrettyA.
2628 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2630 LPWSTR pszIter
= lpszPath
;
2632 TRACE("(%s)\n", debugstr_w(lpszPath
));
2641 if (islowerW(*pszIter
))
2642 return FALSE
; /* Not DOS path */
2645 pszIter
= lpszPath
+ 1;
2648 *pszIter
= tolowerW(*pszIter
);
2655 /*************************************************************************
2656 * PathCommonPrefixA [SHLWAPI.@]
2658 * Determine the length of the common prefix between two paths.
2661 * lpszFile1 [I] First path for comparison
2662 * lpszFile2 [I] Second path for comparison
2663 * achPath [O] Destination for common prefix string
2666 * The length of the common prefix. This is 0 if there is no common
2667 * prefix between the paths or if any parameters are invalid. If the prefix
2668 * is non-zero and achPath is not NULL, achPath is filled with the common
2669 * part of the prefix and NUL terminated.
2672 * A common prefix of 2 is always returned as 3. It is thus possible for
2673 * the length returned to be invalid (i.e. Longer than one or both of the
2674 * strings given as parameters). This Win32 behaviour has been implemented
2675 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2676 * To work around this when using this function, always check that the byte
2677 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2679 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2682 LPCSTR lpszIter1
= lpszFile1
;
2683 LPCSTR lpszIter2
= lpszFile2
;
2685 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2690 if (!lpszFile1
|| !lpszFile2
)
2693 /* Handle roots first */
2694 if (PathIsUNCA(lpszFile1
))
2696 if (!PathIsUNCA(lpszFile2
))
2701 else if (PathIsUNCA(lpszFile2
))
2702 return 0; /* Know already lpszFile1 is not UNC */
2707 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2708 (!*lpszIter2
|| *lpszIter2
== '\\'))
2709 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2711 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2712 break; /* Strings differ at this point */
2719 iLen
++; /* Feature/Bug compatible with Win32 */
2721 if (iLen
&& achPath
)
2723 memcpy(achPath
,lpszFile1
,iLen
);
2724 achPath
[iLen
] = '\0';
2729 /*************************************************************************
2730 * PathCommonPrefixW [SHLWAPI.@]
2732 * See PathCommonPrefixA.
2734 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2737 LPCWSTR lpszIter1
= lpszFile1
;
2738 LPCWSTR lpszIter2
= lpszFile2
;
2740 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2745 if (!lpszFile1
|| !lpszFile2
)
2748 /* Handle roots first */
2749 if (PathIsUNCW(lpszFile1
))
2751 if (!PathIsUNCW(lpszFile2
))
2756 else if (PathIsUNCW(lpszFile2
))
2757 return 0; /* Know already lpszFile1 is not UNC */
2762 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2763 (!*lpszIter2
|| *lpszIter2
== '\\'))
2764 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2766 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2767 break; /* Strings differ at this point */
2774 iLen
++; /* Feature/Bug compatible with Win32 */
2776 if (iLen
&& achPath
)
2778 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2779 achPath
[iLen
] = '\0';
2784 /*************************************************************************
2785 * PathCompactPathA [SHLWAPI.@]
2787 * Make a path fit into a given width when printed to a DC.
2790 * hDc [I] Destination DC
2791 * lpszPath [I/O] Path to be printed to hDc
2792 * dx [I] Desired width
2795 * TRUE If the path was modified/went well.
2798 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2802 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2806 WCHAR szPath
[MAX_PATH
];
2807 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2808 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2809 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2814 /*************************************************************************
2815 * PathCompactPathW [SHLWAPI.@]
2817 * See PathCompactPathA.
2819 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2821 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2824 WCHAR buff
[MAX_PATH
];
2828 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2834 hdc
= hDC
= GetDC(0);
2836 /* Get the length of the whole path */
2837 dwLen
= strlenW(lpszPath
);
2838 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2840 if ((UINT
)size
.cx
> dx
)
2842 /* Path too big, must reduce it */
2844 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2846 sFile
= PathFindFileNameW(lpszPath
);
2847 if (sFile
!= lpszPath
) sFile
--;
2849 /* Get the size of ellipses */
2850 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2851 dwEllipsesLen
= size
.cx
;
2852 /* Get the size of the file name */
2853 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2854 dwPathLen
= size
.cx
;
2856 if (sFile
!= lpszPath
)
2858 LPWSTR sPath
= sFile
;
2859 BOOL bEllipses
= FALSE
;
2861 /* The path includes a file name. Include as much of the path prior to
2862 * the file name as possible, allowing for the ellipses, e.g:
2863 * c:\some very long path\filename ==> c:\some v...\filename
2865 lstrcpynW(buff
, sFile
, MAX_PATH
);
2869 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2871 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2872 dwTotalLen
+= size
.cx
;
2873 if (dwTotalLen
<= dx
)
2881 } while (sPath
> lpszPath
);
2883 if (sPath
> lpszPath
)
2887 strcpyW(sPath
, szEllipses
);
2888 strcpyW(sPath
+3, buff
);
2893 strcpyW(lpszPath
, szEllipses
);
2894 strcpyW(lpszPath
+3, buff
);
2899 /* Trim the path by adding ellipses to the end, e.g:
2900 * A very long file name.txt ==> A very...
2902 dwLen
= strlenW(lpszPath
);
2904 if (dwLen
> MAX_PATH
- 3)
2905 dwLen
= MAX_PATH
- 3;
2906 lstrcpynW(buff
, sFile
, dwLen
);
2910 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2911 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2915 DWORD dwWritten
= 0;
2917 dwEllipsesLen
/= 3; /* Size of a single '.' */
2919 /* Write as much of the Ellipses string as possible */
2920 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2923 dwWritten
+= dwEllipsesLen
;
2931 strcpyW(buff
+ dwLen
, szEllipses
);
2932 strcpyW(lpszPath
, buff
);
2943 /*************************************************************************
2944 * PathGetCharTypeA [SHLWAPI.@]
2946 * Categorise a character from a file path.
2949 * ch [I] Character to get the type of
2952 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2954 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2956 return PathGetCharTypeW(ch
);
2959 /*************************************************************************
2960 * PathGetCharTypeW [SHLWAPI.@]
2962 * See PathGetCharTypeA.
2964 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2968 TRACE("(%d)\n", ch
);
2970 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2971 ch
== '"' || ch
== '|' || ch
== '/')
2972 flags
= GCT_INVALID
; /* Invalid */
2973 else if (ch
== '*' || ch
=='?')
2974 flags
= GCT_WILD
; /* Wildchars */
2975 else if ((ch
== '\\') || (ch
== ':'))
2976 return GCT_SEPARATOR
; /* Path separators */
2981 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2982 ch
== '.' || ch
== '@' || ch
== '^' ||
2983 ch
== '\'' || ch
== 130 || ch
== '`')
2984 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2987 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2988 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2993 /*************************************************************************
2994 * SHLWAPI_UseSystemForSystemFolders
2996 * Internal helper for PathMakeSystemFolderW.
2998 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3000 static BOOL bCheckedReg
= FALSE
;
3001 static BOOL bUseSystemForSystemFolders
= FALSE
;
3007 /* Key tells Win what file attributes to use on system folders */
3008 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3009 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3010 "UseSystemForSystemFolders", 0, 0, 0))
3011 bUseSystemForSystemFolders
= TRUE
;
3013 return bUseSystemForSystemFolders
;
3016 /*************************************************************************
3017 * PathMakeSystemFolderA [SHLWAPI.@]
3019 * Set system folder attribute for a path.
3022 * lpszPath [I] The path to turn into a system folder
3025 * TRUE If the path was changed to/already was a system folder
3026 * FALSE If the path is invalid or SetFileAttributesA() fails
3028 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3032 TRACE("(%s)\n", debugstr_a(lpszPath
));
3034 if (lpszPath
&& *lpszPath
)
3036 WCHAR szPath
[MAX_PATH
];
3037 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3038 bRet
= PathMakeSystemFolderW(szPath
);
3043 /*************************************************************************
3044 * PathMakeSystemFolderW [SHLWAPI.@]
3046 * See PathMakeSystemFolderA.
3048 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3050 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3051 WCHAR buff
[MAX_PATH
];
3053 TRACE("(%s)\n", debugstr_w(lpszPath
));
3055 if (!lpszPath
|| !*lpszPath
)
3058 /* If the directory is already a system directory, don't do anything */
3059 GetSystemDirectoryW(buff
, MAX_PATH
);
3060 if (!strcmpW(buff
, lpszPath
))
3063 GetWindowsDirectoryW(buff
, MAX_PATH
);
3064 if (!strcmpW(buff
, lpszPath
))
3067 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3068 if (SHLWAPI_UseSystemForSystemFolders())
3069 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3071 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3074 /* Change file attributes to system attributes */
3075 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3076 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3079 /*************************************************************************
3080 * PathRenameExtensionA [SHLWAPI.@]
3082 * Swap the file extension in a path with another extension.
3085 * lpszPath [I/O] Path to swap the extension in
3086 * lpszExt [I] The new extension
3089 * TRUE if lpszPath was modified,
3090 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3092 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3094 LPSTR lpszExtension
;
3096 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3098 lpszExtension
= PathFindExtensionA(lpszPath
);
3100 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3103 strcpy(lpszExtension
, lpszExt
);
3107 /*************************************************************************
3108 * PathRenameExtensionW [SHLWAPI.@]
3110 * See PathRenameExtensionA.
3112 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3114 LPWSTR lpszExtension
;
3116 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3118 lpszExtension
= PathFindExtensionW(lpszPath
);
3120 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3123 strcpyW(lpszExtension
, lpszExt
);
3127 /*************************************************************************
3128 * PathSearchAndQualifyA [SHLWAPI.@]
3130 * Determine if a given path is correct and fully qualified.
3133 * lpszPath [I] Path to check
3134 * lpszBuf [O] Output for correct path
3135 * cchBuf [I] Size of lpszBuf
3140 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3142 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3144 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3146 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3149 /*************************************************************************
3150 * PathSearchAndQualifyW [SHLWAPI.@]
3152 * See PathSearchAndQualifyA.
3154 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3156 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3158 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3160 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3163 /*************************************************************************
3164 * PathSkipRootA [SHLWAPI.@]
3166 * Return the portion of a path following the drive letter or mount point.
3169 * lpszPath [I] The path to skip on
3172 * Success: A pointer to the next character after the root.
3173 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3175 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3177 TRACE("(%s)\n", debugstr_a(lpszPath
));
3179 if (!lpszPath
|| !*lpszPath
)
3182 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3184 /* Network share: skip share server and mount point */
3186 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3187 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3189 return (LPSTR
)lpszPath
;
3192 if (IsDBCSLeadByte(*lpszPath
))
3196 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3197 return (LPSTR
)lpszPath
+ 3;
3201 /*************************************************************************
3202 * PathSkipRootW [SHLWAPI.@]
3204 * See PathSkipRootA.
3206 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3208 TRACE("(%s)\n", debugstr_w(lpszPath
));
3210 if (!lpszPath
|| !*lpszPath
)
3213 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3215 /* Network share: skip share server and mount point */
3217 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3218 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3220 return (LPWSTR
)lpszPath
;
3224 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3225 return (LPWSTR
)lpszPath
+ 3;
3229 /*************************************************************************
3230 * PathCreateFromUrlA [SHLWAPI.@]
3232 * See PathCreateFromUrlW
3234 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3235 LPDWORD pcchPath
, DWORD dwReserved
)
3237 WCHAR bufW
[MAX_PATH
];
3238 WCHAR
*pathW
= bufW
;
3239 UNICODE_STRING urlW
;
3241 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3243 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3244 return E_INVALIDARG
;
3246 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3247 return E_INVALIDARG
;
3248 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3249 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3250 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3253 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3254 if(*pcchPath
> lenA
) {
3255 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3259 *pcchPath
= lenA
+ 1;
3263 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3264 RtlFreeUnicodeString(&urlW
);
3268 /*************************************************************************
3269 * PathCreateFromUrlW [SHLWAPI.@]
3271 * Create a path from a URL
3274 * lpszUrl [I] URL to convert into a path
3275 * lpszPath [O] Output buffer for the resulting Path
3276 * pcchPath [I] Length of lpszPath
3277 * dwFlags [I] Flags controlling the conversion
3280 * Success: S_OK. lpszPath contains the URL in path format,
3281 * Failure: An HRESULT error code such as E_INVALIDARG.
3283 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3284 LPDWORD pcchPath
, DWORD dwReserved
)
3286 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3287 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3288 DWORD nslashes
, unescape
, len
;
3293 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3295 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3296 return E_INVALIDARG
;
3298 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3299 file_colon
, 5) != CSTR_EQUAL
)
3300 return E_INVALIDARG
;
3306 while (*src
== '/' || *src
== '\\') {
3311 /* We need a temporary buffer so we can compute what size to ask for.
3312 * We know that the final string won't be longer than the current pszUrl
3313 * plus at most two backslashes. All the other transformations make it
3316 len
= 2 + lstrlenW(pszUrl
) + 1;
3317 if (*pcchPath
< len
)
3318 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3328 /* 'file:' + escaped DOS path */
3331 /* 'file:/' + escaped DOS path */
3334 /* 'file:///' (implied localhost) + escaped DOS path */
3335 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3339 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, src
, 9,
3340 localhost
, 9) == CSTR_EQUAL
&&
3341 (src
[9] == '/' || src
[9] == '\\'))
3343 /* 'file://localhost/' + escaped DOS path */
3346 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3348 /* 'file://' + unescaped DOS path */
3353 /* 'file://hostname:port/path' (where path is escaped)
3354 * or 'file:' + escaped UNC path (\\server\share\path)
3355 * The second form is clearly specific to Windows and it might
3356 * even be doing a network lookup to try to figure it out.
3358 while (*src
&& *src
!= '/' && *src
!= '\\')
3361 StrCpyNW(dst
, pszUrl
, len
+ 1);
3363 if (isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3365 /* 'Forget' to add a trailing '/', just like Windows */
3371 /* 'file://' + unescaped UNC path (\\server\share\path) */
3373 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3377 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3381 /* Copy the remainder of the path */
3382 len
+= lstrlenW(src
);
3385 /* First do the Windows-specific path conversions */
3386 for (dst
= tpath
; *dst
; dst
++)
3387 if (*dst
== '/') *dst
= '\\';
3388 if (isalphaW(*tpath
) && tpath
[1] == '|')
3389 tpath
[1] = ':'; /* c| -> c: */
3391 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3394 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3397 /* When working in-place UrlUnescapeW() does not set len */
3398 len
= lstrlenW(tpath
);
3402 if (*pcchPath
< len
+ 1)
3405 *pcchPath
= len
+ 1;
3410 if (tpath
!= pszPath
)
3411 StrCpyW(pszPath
, tpath
);
3413 if (tpath
!= pszPath
)
3414 HeapFree(GetProcessHeap(), 0, tpath
);
3416 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3420 /*************************************************************************
3421 * PathCreateFromUrlAlloc [SHLWAPI.@]
3423 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3426 WCHAR pathW
[MAX_PATH
];
3431 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3434 /* Yes, this is supposed to crash if pszPath is NULL */
3435 *pszPath
= StrDupW(pathW
);
3440 /*************************************************************************
3441 * PathRelativePathToA [SHLWAPI.@]
3443 * Create a relative path from one path to another.
3446 * lpszPath [O] Destination for relative path
3447 * lpszFrom [I] Source path
3448 * dwAttrFrom [I] File attribute of source path
3449 * lpszTo [I] Destination path
3450 * dwAttrTo [I] File attributes of destination path
3453 * TRUE If a relative path can be formed. lpszPath contains the new path
3454 * FALSE If the paths are not relative or any parameters are invalid
3457 * lpszTo should be at least MAX_PATH in length.
3459 * Calling this function with relative paths for lpszFrom or lpszTo may
3460 * give erroneous results.
3462 * The Win32 version of this function contains a bug where the lpszTo string
3463 * may be referenced 1 byte beyond the end of the string. As a result random
3464 * garbage may be written to the output path, depending on what lies beyond
3465 * the last byte of the string. This bug occurs because of the behaviour of
3466 * PathCommonPrefix() (see notes for that function), and no workaround seems
3467 * possible with Win32.
3469 * This bug has been fixed here, so for example the relative path from "\\"
3470 * to "\\" is correctly determined as "." in this implementation.
3472 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3473 LPCSTR lpszTo
, DWORD dwAttrTo
)
3477 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3478 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3480 if(lpszPath
&& lpszFrom
&& lpszTo
)
3482 WCHAR szPath
[MAX_PATH
];
3483 WCHAR szFrom
[MAX_PATH
];
3484 WCHAR szTo
[MAX_PATH
];
3485 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3486 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3487 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3488 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3493 /*************************************************************************
3494 * PathRelativePathToW [SHLWAPI.@]
3496 * See PathRelativePathToA.
3498 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3499 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3501 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3502 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3503 WCHAR szFrom
[MAX_PATH
];
3504 WCHAR szTo
[MAX_PATH
];
3507 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3508 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3510 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3514 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3515 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3517 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3518 PathRemoveFileSpecW(szFrom
);
3519 if(!(dwAttrTo
& FILE_ATTRIBUTE_DIRECTORY
))
3520 PathRemoveFileSpecW(szTo
);
3522 /* Paths can only be relative if they have a common root */
3523 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3526 /* Strip off lpszFrom components to the root, by adding "..\" */
3527 lpszFrom
= szFrom
+ dwLen
;
3533 if (*lpszFrom
== '\\')
3538 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3539 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3542 /* From the root add the components of lpszTo */
3544 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3547 if (*lpszTo
&& lpszTo
[-1])
3549 if (*lpszTo
!= '\\')
3551 dwLen
= strlenW(lpszPath
);
3552 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3557 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3562 /*************************************************************************
3563 * PathUnmakeSystemFolderA [SHLWAPI.@]
3565 * Remove the system folder attributes from a path.
3568 * lpszPath [I] The path to remove attributes from
3572 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3573 * SetFileAttributesA() fails.
3575 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3579 TRACE("(%s)\n", debugstr_a(lpszPath
));
3581 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3582 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3585 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3586 return SetFileAttributesA(lpszPath
, dwAttr
);
3589 /*************************************************************************
3590 * PathUnmakeSystemFolderW [SHLWAPI.@]
3592 * See PathUnmakeSystemFolderA.
3594 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3598 TRACE("(%s)\n", debugstr_w(lpszPath
));
3600 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3601 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3604 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3605 return SetFileAttributesW(lpszPath
, dwAttr
);
3609 /*************************************************************************
3610 * PathSetDlgItemPathA [SHLWAPI.@]
3612 * Set the text of a dialog item to a path, shrinking the path to fit
3613 * if it is too big for the item.
3616 * hDlg [I] Dialog handle
3617 * id [I] ID of item in the dialog
3618 * lpszPath [I] Path to set as the items text
3624 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3625 * window text is erased).
3627 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3629 WCHAR szPath
[MAX_PATH
];
3631 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3634 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3637 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3640 /*************************************************************************
3641 * PathSetDlgItemPathW [SHLWAPI.@]
3643 * See PathSetDlgItemPathA.
3645 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3647 WCHAR path
[MAX_PATH
+ 1];
3653 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3655 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3659 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3663 GetClientRect(hwItem
, &rect
);
3665 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3669 PathCompactPathW(hdc
, path
, rect
.right
);
3670 SelectObject(hdc
, hPrevObj
);
3673 ReleaseDC(hDlg
, hdc
);
3674 SetWindowTextW(hwItem
, path
);
3677 /*************************************************************************
3678 * PathIsNetworkPathA [SHLWAPI.@]
3680 * Determine if the given path is a network path.
3683 * lpszPath [I] Path to check
3686 * TRUE If lpszPath is a UNC share or mapped network drive, or
3687 * FALSE If lpszPath is a local drive or cannot be determined
3689 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3693 TRACE("(%s)\n",debugstr_a(lpszPath
));
3697 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3699 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3700 if (dwDriveNum
== -1)
3702 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3703 return pIsNetDrive(dwDriveNum
);
3706 /*************************************************************************
3707 * PathIsNetworkPathW [SHLWAPI.@]
3709 * See PathIsNetworkPathA.
3711 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3715 TRACE("(%s)\n", debugstr_w(lpszPath
));
3719 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3721 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3722 if (dwDriveNum
== -1)
3724 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3725 return pIsNetDrive(dwDriveNum
);
3728 /*************************************************************************
3729 * PathIsLFNFileSpecA [SHLWAPI.@]
3731 * Determine if the given path is a long file name
3734 * lpszPath [I] Path to check
3737 * TRUE If path is a long file name,
3738 * FALSE If path is a valid DOS short file name
3740 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3742 DWORD dwNameLen
= 0, dwExtLen
= 0;
3744 TRACE("(%s)\n",debugstr_a(lpszPath
));
3751 if (*lpszPath
== ' ')
3752 return TRUE
; /* DOS names cannot have spaces */
3753 if (*lpszPath
== '.')
3756 return TRUE
; /* DOS names have only one dot */
3763 return TRUE
; /* DOS extensions are <= 3 chars*/
3769 return TRUE
; /* DOS names are <= 8 chars */
3771 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3773 return FALSE
; /* Valid DOS path */
3776 /*************************************************************************
3777 * PathIsLFNFileSpecW [SHLWAPI.@]
3779 * See PathIsLFNFileSpecA.
3781 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3783 DWORD dwNameLen
= 0, dwExtLen
= 0;
3785 TRACE("(%s)\n",debugstr_w(lpszPath
));
3792 if (*lpszPath
== ' ')
3793 return TRUE
; /* DOS names cannot have spaces */
3794 if (*lpszPath
== '.')
3797 return TRUE
; /* DOS names have only one dot */
3804 return TRUE
; /* DOS extensions are <= 3 chars*/
3810 return TRUE
; /* DOS names are <= 8 chars */
3814 return FALSE
; /* Valid DOS path */
3817 /*************************************************************************
3818 * PathIsDirectoryEmptyA [SHLWAPI.@]
3820 * Determine if a given directory is empty.
3823 * lpszPath [I] Directory to check
3826 * TRUE If the directory exists and contains no files,
3829 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3833 TRACE("(%s)\n",debugstr_a(lpszPath
));
3837 WCHAR szPath
[MAX_PATH
];
3838 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3839 bRet
= PathIsDirectoryEmptyW(szPath
);
3844 /*************************************************************************
3845 * PathIsDirectoryEmptyW [SHLWAPI.@]
3847 * See PathIsDirectoryEmptyA.
3849 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3851 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3852 WCHAR szSearch
[MAX_PATH
];
3855 BOOL retVal
= FALSE
;
3856 WIN32_FIND_DATAW find_data
;
3858 TRACE("(%s)\n",debugstr_w(lpszPath
));
3860 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3863 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3864 PathAddBackslashW(szSearch
);
3865 dwLen
= strlenW(szSearch
);
3866 if (dwLen
> MAX_PATH
- 4)
3869 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3870 hfind
= FindFirstFileW(szSearch
, &find_data
);
3871 if (hfind
!= INVALID_HANDLE_VALUE
)
3873 if (find_data
.cFileName
[0] == '.' && find_data
.cFileName
[1] == '.')
3874 /* The only directory entry should be the parent */
3875 retVal
= !FindNextFileW(hfind
, &find_data
);
3883 /*************************************************************************
3884 * PathFindSuffixArrayA [SHLWAPI.@]
3886 * Find a suffix string in an array of suffix strings
3889 * lpszSuffix [I] Suffix string to search for
3890 * lppszArray [I] Array of suffix strings to search
3891 * dwCount [I] Number of elements in lppszArray
3894 * Success: The index of the position of lpszSuffix in lppszArray
3895 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3898 * The search is case sensitive.
3899 * The match is made against the end of the suffix string, so for example:
3900 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3902 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3907 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3909 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3911 dwLen
= strlen(lpszSuffix
);
3913 while (dwRet
< dwCount
)
3915 size_t dwCompareLen
= strlen(*lppszArray
);
3916 if (dwCompareLen
< dwLen
)
3918 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3919 return *lppszArray
; /* Found */
3928 /*************************************************************************
3929 * PathFindSuffixArrayW [SHLWAPI.@]
3931 * See PathFindSuffixArrayA.
3933 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3938 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3940 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3942 dwLen
= strlenW(lpszSuffix
);
3944 while (dwRet
< dwCount
)
3946 size_t dwCompareLen
= strlenW(*lppszArray
);
3947 if (dwCompareLen
< dwLen
)
3949 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3950 return *lppszArray
; /* Found */
3959 /*************************************************************************
3960 * PathUndecorateA [SHLWAPI.@]
3962 * Undecorate a file path
3965 * lpszPath [I/O] Path to remove any decoration from
3971 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3973 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3975 TRACE("(%s)\n",debugstr_a(lpszPath
));
3979 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3980 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3982 LPSTR lpszSkip
= lpszExt
- 2;
3983 if (*lpszSkip
== '[')
3984 lpszSkip
++; /* [] (no number) */
3986 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3988 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3990 /* remove the [n] */
3993 *lpszSkip
++ = *lpszExt
++;
4000 /*************************************************************************
4001 * PathUndecorateW [SHLWAPI.@]
4003 * See PathUndecorateA.
4005 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4007 TRACE("(%s)\n",debugstr_w(lpszPath
));
4011 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4012 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4014 LPWSTR lpszSkip
= lpszExt
- 2;
4015 if (*lpszSkip
== '[')
4016 lpszSkip
++; /* [] (no number) */
4018 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4020 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4022 /* remove the [n] */
4025 *lpszSkip
++ = *lpszExt
++;
4032 /*************************************************************************
4033 * PathUnExpandEnvStringsA [SHLWAPI.@]
4035 * Substitute folder names in a path with their corresponding environment
4039 * path [I] Buffer containing the path to unexpand.
4040 * buffer [O] Buffer to receive the unexpanded path.
4041 * buf_len [I] Size of pszBuf in characters.
4047 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4049 WCHAR bufferW
[MAX_PATH
], *pathW
;
4053 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4055 pathW
= heap_strdupAtoW(path
);
4056 if (!pathW
) return FALSE
;
4058 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4059 HeapFree(GetProcessHeap(), 0, pathW
);
4060 if (!ret
) return FALSE
;
4062 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4063 if (buf_len
< len
+ 1) return FALSE
;
4065 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4069 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4070 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4071 static const WCHAR computernameW
[] = {'%','C','O','M','P','U','T','E','R','N','A','M','E','%',0};
4072 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4073 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4074 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4075 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4081 WCHAR path
[MAX_PATH
];
4085 static void init_envvars_map(struct envvars_map
*map
)
4089 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4090 /* exclude null from length */
4091 if (map
->len
) map
->len
--;
4096 /*************************************************************************
4097 * PathUnExpandEnvStringsW [SHLWAPI.@]
4099 * Unicode version of PathUnExpandEnvStringsA.
4101 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4103 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4104 struct envvars_map
*match
= &null_var
, *cur
;
4105 struct envvars_map envvars
[] = {
4106 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4107 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4108 { computernameW
, sizeof(computernameW
)/sizeof(WCHAR
) },
4109 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4110 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4111 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4112 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4118 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4120 pathlen
= strlenW(path
);
4121 init_envvars_map(envvars
);
4125 /* path can't contain expanded value or value wasn't retrieved */
4126 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4132 if (cur
->len
> match
->len
)
4137 /* 'varlen' includes NULL termination char */
4138 needed
= match
->varlen
+ pathlen
- match
->len
;
4139 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4141 strcpyW(buffer
, match
->var
);
4142 strcatW(buffer
, &path
[match
->len
]);
4143 TRACE("ret %s\n", debugstr_w(buffer
));
4148 /*************************************************************************
4151 * Find localised or default web content in "%WINDOWS%\web\".
4154 * lpszFile [I] File name containing content to look for
4155 * lpszPath [O] Buffer to contain the full path to the file
4156 * dwPathLen [I] Length of lpszPath
4159 * Success: S_OK. lpszPath contains the full path to the content.
4160 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4162 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4164 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4167 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4169 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4171 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4172 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4176 /*************************************************************************
4179 * Unicode version of SHGetWebFolderFilePathA.
4181 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4183 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4184 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4185 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4186 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4187 DWORD dwLen
, dwFileLen
;
4188 LANGID lidSystem
, lidUser
;
4190 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4192 /* Get base directory for web content */
4193 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4194 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4197 dwFileLen
= strlenW(lpszFile
);
4199 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4200 return E_FAIL
; /* lpszPath too short */
4202 strcpyW(lpszPath
+dwLen
, szWeb
);
4204 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4206 lidSystem
= GetSystemDefaultUILanguage();
4207 lidUser
= GetUserDefaultUILanguage();
4209 if (lidSystem
!= lidUser
)
4211 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4213 /* Use localised content in the users UI language if present */
4214 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4215 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4216 if (PathFileExistsW(lpszPath
))
4221 /* Fall back to OS default installed content */
4222 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4223 if (PathFileExistsW(lpszPath
))
4228 #define PATH_CHAR_CLASS_LETTER 0x00000001
4229 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4230 #define PATH_CHAR_CLASS_DOT 0x00000004
4231 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4232 #define PATH_CHAR_CLASS_COLON 0x00000010
4233 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4234 #define PATH_CHAR_CLASS_COMMA 0x00000040
4235 #define PATH_CHAR_CLASS_SPACE 0x00000080
4236 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4237 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4239 #define PATH_CHAR_CLASS_INVALID 0x00000000
4240 #define PATH_CHAR_CLASS_ANY 0xffffffff
4242 static const DWORD SHELL_charclass
[] =
4244 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4245 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4246 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4247 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4248 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4249 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4250 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4251 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4252 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4253 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4254 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4255 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4256 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4257 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4258 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4259 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4260 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4261 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ 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_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4265 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4266 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4267 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4268 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4269 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4270 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4271 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4272 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4273 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4274 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4275 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4276 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4277 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4278 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4279 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4280 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4281 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4282 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4283 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4284 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4285 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4286 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4287 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4288 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4289 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4290 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4291 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4292 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4293 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4294 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4295 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4296 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4297 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4298 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4299 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4300 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4301 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4302 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4303 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4304 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4305 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4306 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4307 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4310 /*************************************************************************
4313 * Check if an ASCII char is of a certain class
4315 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4317 if ((unsigned)c
> 0x7e)
4318 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4320 return class & SHELL_charclass
[(unsigned)c
];
4323 /*************************************************************************
4326 * Check if a Unicode char is of a certain class
4328 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4331 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4333 return class & SHELL_charclass
[c
];