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
25 int WINAPI
IsNetDrive(int drive
);
28 /* Get a function pointer from a DLL handle */
29 #define GET_FUNC(func, module, name, fail) \
32 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
33 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
34 if (!func) return fail; \
38 /* DLL handles for late bound calls */
39 static HMODULE SHLWAPI_hshell32
;
41 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
42 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
43 static fnpIsNetDrive pIsNetDrive
;
45 #endif /* __REACTOS__ */
48 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
50 static inline WCHAR
* heap_strdupAtoW(LPCSTR str
)
56 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
57 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
59 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
65 /*************************************************************************
66 * PathAppendA [SHLWAPI.@]
68 * Append one path to another.
71 * lpszPath [I/O] Initial part of path, and destination for output
72 * lpszAppend [I] Path to append
75 * Success: TRUE. lpszPath contains the newly created path.
76 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
79 * lpszAppend must contain at least one backslash ('\') if not NULL.
80 * Because PathCombineA() is used to join the paths, the resulting
81 * path is also canonicalized.
83 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
85 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
87 if (lpszPath
&& lpszAppend
)
89 if (!PathIsUNCA(lpszAppend
))
90 while (*lpszAppend
== '\\')
92 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
98 /*************************************************************************
99 * PathAppendW [SHLWAPI.@]
103 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
105 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
107 if (lpszPath
&& lpszAppend
)
109 if (!PathIsUNCW(lpszAppend
))
110 while (*lpszAppend
== '\\')
112 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
118 /*************************************************************************
119 * PathCombineA [SHLWAPI.@]
121 * Combine two paths together.
124 * lpszDest [O] Destination for combined path
125 * lpszDir [I] Directory path
126 * lpszFile [I] File path
129 * Success: The output path
130 * Failure: NULL, if inputs are invalid.
133 * lpszDest should be at least MAX_PATH in size, and may point to the same
134 * memory location as lpszDir. The combined path is canonicalised.
136 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
138 WCHAR szDest
[MAX_PATH
];
139 WCHAR szDir
[MAX_PATH
];
140 WCHAR szFile
[MAX_PATH
];
141 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
143 /* Invalid parameters */
146 if (!lpszDir
&& !lpszFile
)
150 if (!MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
))
154 if (!MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
))
157 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
158 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
166 /*************************************************************************
167 * PathCombineW [SHLWAPI.@]
171 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
173 WCHAR szTemp
[MAX_PATH
];
174 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
176 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
178 /* Invalid parameters */
181 if (!lpszDir
&& !lpszFile
)
187 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
190 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
192 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
194 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
197 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
210 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
213 PathStripToRootW(szTemp
);
214 lpszFile
++; /* Skip '\' */
216 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
221 strcatW(szTemp
, lpszFile
);
224 PathCanonicalizeW(lpszDest
, szTemp
);
228 /*************************************************************************
229 * PathAddBackslashA [SHLWAPI.@]
231 * Append a backslash ('\') to a path if one doesn't exist.
234 * lpszPath [I/O] The path to append a backslash to.
237 * Success: The position of the last backslash in the path.
238 * Failure: NULL, if lpszPath is NULL or the path is too large.
240 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
243 LPSTR prev
= lpszPath
;
245 TRACE("(%s)\n",debugstr_a(lpszPath
));
247 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
253 lpszPath
= CharNextA(prev
);
266 /*************************************************************************
267 * PathAddBackslashW [SHLWAPI.@]
269 * See PathAddBackslashA.
271 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
275 TRACE("(%s)\n",debugstr_w(lpszPath
));
277 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
283 if (lpszPath
[-1] != '\\')
292 /*************************************************************************
293 * PathBuildRootA [SHLWAPI.@]
295 * Create a root drive string (e.g. "A:\") from a drive number.
298 * lpszPath [O] Destination for the drive string
304 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
306 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
308 TRACE("(%p,%d)\n", lpszPath
, drive
);
310 if (lpszPath
&& drive
>= 0 && drive
< 26)
312 lpszPath
[0] = 'A' + drive
;
320 /*************************************************************************
321 * PathBuildRootW [SHLWAPI.@]
323 * See PathBuildRootA.
325 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
327 TRACE("(%p,%d)\n", lpszPath
, drive
);
329 if (lpszPath
&& drive
>= 0 && drive
< 26)
331 lpszPath
[0] = 'A' + drive
;
339 /*************************************************************************
340 * PathFindFileNameA [SHLWAPI.@]
342 * Locate the start of the file name in a path
345 * lpszPath [I] Path to search
348 * A pointer to the first character of the file name
350 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
352 LPCSTR lastSlash
= lpszPath
;
354 TRACE("(%s)\n",debugstr_a(lpszPath
));
356 while (lpszPath
&& *lpszPath
)
358 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
359 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
360 lastSlash
= lpszPath
+ 1;
361 lpszPath
= CharNextA(lpszPath
);
363 return (LPSTR
)lastSlash
;
366 /*************************************************************************
367 * PathFindFileNameW [SHLWAPI.@]
369 * See PathFindFileNameA.
371 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
373 LPCWSTR lastSlash
= lpszPath
;
375 TRACE("(%s)\n",debugstr_w(lpszPath
));
377 while (lpszPath
&& *lpszPath
)
379 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
380 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
381 lastSlash
= lpszPath
+ 1;
384 return (LPWSTR
)lastSlash
;
387 /*************************************************************************
388 * PathFindExtensionA [SHLWAPI.@]
390 * Locate the start of the file extension in a path
393 * lpszPath [I] The path to search
396 * A pointer to the first character of the extension, the end of
397 * the string if the path has no extension, or NULL If lpszPath is NULL
399 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
401 LPCSTR lastpoint
= NULL
;
403 TRACE("(%s)\n", debugstr_a(lpszPath
));
409 if (*lpszPath
== '\\' || *lpszPath
==' ')
411 else if (*lpszPath
== '.')
412 lastpoint
= lpszPath
;
413 lpszPath
= CharNextA(lpszPath
);
416 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
419 /*************************************************************************
420 * PathFindExtensionW [SHLWAPI.@]
422 * See PathFindExtensionA.
424 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
426 LPCWSTR lastpoint
= NULL
;
428 TRACE("(%s)\n", debugstr_w(lpszPath
));
434 if (*lpszPath
== '\\' || *lpszPath
==' ')
436 else if (*lpszPath
== '.')
437 lastpoint
= lpszPath
;
441 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
444 /*************************************************************************
445 * PathGetArgsA [SHLWAPI.@]
447 * Find the next argument in a string delimited by spaces.
450 * lpszPath [I] The string to search for arguments in
453 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
456 * Spaces in quoted strings are ignored as delimiters.
458 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
460 BOOL bSeenQuote
= FALSE
;
462 TRACE("(%s)\n",debugstr_a(lpszPath
));
468 if ((*lpszPath
==' ') && !bSeenQuote
)
469 return (LPSTR
)lpszPath
+ 1;
470 if (*lpszPath
== '"')
471 bSeenQuote
= !bSeenQuote
;
472 lpszPath
= CharNextA(lpszPath
);
475 return (LPSTR
)lpszPath
;
478 /*************************************************************************
479 * PathGetArgsW [SHLWAPI.@]
483 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
485 BOOL bSeenQuote
= FALSE
;
487 TRACE("(%s)\n",debugstr_w(lpszPath
));
493 if ((*lpszPath
==' ') && !bSeenQuote
)
494 return (LPWSTR
)lpszPath
+ 1;
495 if (*lpszPath
== '"')
496 bSeenQuote
= !bSeenQuote
;
500 return (LPWSTR
)lpszPath
;
503 /*************************************************************************
504 * PathGetDriveNumberA [SHLWAPI.@]
506 * Return the drive number from a path
509 * lpszPath [I] Path to get the drive number from
512 * Success: The drive number corresponding to the drive in the path
513 * Failure: -1, if lpszPath contains no valid drive
515 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
517 TRACE ("(%s)\n",debugstr_a(lpszPath
));
519 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
520 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
521 return tolower(*lpszPath
) - 'a';
525 /*************************************************************************
526 * PathGetDriveNumberW [SHLWAPI.@]
528 * See PathGetDriveNumberA.
530 int WINAPI
PathGetDriveNumberW(const WCHAR
*path
)
534 static const WCHAR nt_prefixW
[] = {'\\','\\','?','\\'};
536 TRACE("(%s)\n", debugstr_w(path
));
541 if (!strncmpW(path
, nt_prefixW
, 4))
544 drive
= tolowerW(path
[0]);
545 if (drive
< 'a' || drive
> 'z' || path
[1] != ':')
551 /*************************************************************************
552 * PathRemoveFileSpecA [SHLWAPI.@]
554 * Remove the file specification from a path.
557 * lpszPath [I/O] Path to remove the file spec from
560 * TRUE If the path was valid and modified
563 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
565 LPSTR lpszFileSpec
= lpszPath
;
566 BOOL bModified
= FALSE
;
568 TRACE("(%s)\n",debugstr_a(lpszPath
));
572 /* Skip directory or UNC path */
573 if (*lpszPath
== '\\')
574 lpszFileSpec
= ++lpszPath
;
575 if (*lpszPath
== '\\')
576 lpszFileSpec
= ++lpszPath
;
580 if(*lpszPath
== '\\')
581 lpszFileSpec
= lpszPath
; /* Skip dir */
582 else if(*lpszPath
== ':')
584 lpszFileSpec
= ++lpszPath
; /* Skip drive */
585 if (*lpszPath
== '\\')
588 if (!(lpszPath
= CharNextA(lpszPath
)))
594 *lpszFileSpec
= '\0';
601 /*************************************************************************
602 * PathRemoveFileSpecW [SHLWAPI.@]
604 * See PathRemoveFileSpecA.
606 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
608 LPWSTR lpszFileSpec
= lpszPath
;
609 BOOL bModified
= FALSE
;
611 TRACE("(%s)\n",debugstr_w(lpszPath
));
615 /* Skip directory or UNC path */
616 if (*lpszPath
== '\\')
617 lpszFileSpec
= ++lpszPath
;
618 if (*lpszPath
== '\\')
619 lpszFileSpec
= ++lpszPath
;
623 if(*lpszPath
== '\\')
624 lpszFileSpec
= lpszPath
; /* Skip dir */
625 else if(*lpszPath
== ':')
627 lpszFileSpec
= ++lpszPath
; /* Skip drive */
628 if (*lpszPath
== '\\')
636 *lpszFileSpec
= '\0';
643 /*************************************************************************
644 * PathStripPathA [SHLWAPI.@]
646 * Remove the initial path from the beginning of a filename
649 * lpszPath [I/O] Path to remove the initial path from
654 void WINAPI
PathStripPathA(LPSTR lpszPath
)
656 TRACE("(%s)\n", debugstr_a(lpszPath
));
660 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
661 if(lpszFileName
!= lpszPath
)
662 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
666 /*************************************************************************
667 * PathStripPathW [SHLWAPI.@]
669 * See PathStripPathA.
671 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
675 TRACE("(%s)\n", debugstr_w(lpszPath
));
676 lpszFileName
= PathFindFileNameW(lpszPath
);
677 if(lpszFileName
!= lpszPath
)
678 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
681 /*************************************************************************
682 * PathStripToRootA [SHLWAPI.@]
684 * Reduce a path to its root.
687 * lpszPath [I/O] the path to reduce
690 * Success: TRUE if the stripped path is a root path
691 * Failure: FALSE if the path cannot be stripped or is NULL
693 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
695 TRACE("(%s)\n", debugstr_a(lpszPath
));
699 while(!PathIsRootA(lpszPath
))
700 if (!PathRemoveFileSpecA(lpszPath
))
705 /*************************************************************************
706 * PathStripToRootW [SHLWAPI.@]
708 * See PathStripToRootA.
710 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
712 TRACE("(%s)\n", debugstr_w(lpszPath
));
716 while(!PathIsRootW(lpszPath
))
717 if (!PathRemoveFileSpecW(lpszPath
))
722 /*************************************************************************
723 * PathRemoveArgsA [SHLWAPI.@]
725 * Strip space separated arguments from a path.
728 * lpszPath [I/O] Path to remove arguments from
733 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
735 TRACE("(%s)\n",debugstr_a(lpszPath
));
739 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
744 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
745 if(*lpszLastChar
== ' ')
746 *lpszLastChar
= '\0';
751 /*************************************************************************
752 * PathRemoveArgsW [SHLWAPI.@]
754 * See PathRemoveArgsA.
756 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
758 TRACE("(%s)\n",debugstr_w(lpszPath
));
762 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
763 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
768 /*************************************************************************
769 * PathRemoveExtensionA [SHLWAPI.@]
771 * Remove the file extension from a path
774 * lpszPath [I/O] Path to remove the extension from
777 * The NUL terminator must be written only if extension exists
778 * and if the pointed character is not already NUL.
783 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
785 TRACE("(%s)\n", debugstr_a(lpszPath
));
789 lpszPath
= PathFindExtensionA(lpszPath
);
790 if (lpszPath
&& *lpszPath
!= '\0')
795 /*************************************************************************
796 * PathRemoveExtensionW [SHLWAPI.@]
798 * See PathRemoveExtensionA.
800 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
802 TRACE("(%s)\n", debugstr_w(lpszPath
));
806 lpszPath
= PathFindExtensionW(lpszPath
);
807 if (lpszPath
&& *lpszPath
!= '\0')
812 /*************************************************************************
813 * PathRemoveBackslashA [SHLWAPI.@]
815 * Remove a trailing backslash from a path.
818 * lpszPath [I/O] Path to remove backslash from
821 * Success: A pointer to the end of the path
822 * Failure: NULL, if lpszPath is NULL
824 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
828 TRACE("(%s)\n", debugstr_a(lpszPath
));
832 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
833 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
839 /*************************************************************************
840 * PathRemoveBackslashW [SHLWAPI.@]
842 * See PathRemoveBackslashA.
844 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
846 LPWSTR szTemp
= NULL
;
848 TRACE("(%s)\n", debugstr_w(lpszPath
));
852 szTemp
= lpszPath
+ strlenW(lpszPath
);
853 if (szTemp
> lpszPath
) szTemp
--;
854 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
860 /*************************************************************************
861 * PathRemoveBlanksA [SHLWAPI.@]
863 * Remove Spaces from the start and end of a path.
866 * lpszPath [I/O] Path to strip blanks from
871 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
873 TRACE("(%s)\n", debugstr_a(lpszPath
));
875 if(lpszPath
&& *lpszPath
)
877 LPSTR start
= lpszPath
;
879 while (*lpszPath
== ' ')
880 lpszPath
= CharNextA(lpszPath
);
883 *start
++ = *lpszPath
++;
885 if (start
!= lpszPath
)
886 while (start
[-1] == ' ')
892 /*************************************************************************
893 * PathRemoveBlanksW [SHLWAPI.@]
895 * See PathRemoveBlanksA.
897 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
899 TRACE("(%s)\n", debugstr_w(lpszPath
));
901 if(lpszPath
&& *lpszPath
)
903 LPWSTR start
= lpszPath
;
905 while (*lpszPath
== ' ')
909 *start
++ = *lpszPath
++;
911 if (start
!= lpszPath
)
912 while (start
[-1] == ' ')
918 /*************************************************************************
919 * PathQuoteSpacesA [SHLWAPI.@]
921 * Surround a path containing spaces in quotes.
924 * lpszPath [I/O] Path to quote
930 * The path is not changed if it is invalid or has no spaces.
932 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
934 TRACE("(%s)\n", debugstr_a(lpszPath
));
936 if(lpszPath
&& StrChrA(lpszPath
,' '))
938 size_t iLen
= strlen(lpszPath
) + 1;
940 if (iLen
+ 2 < MAX_PATH
)
942 memmove(lpszPath
+ 1, lpszPath
, iLen
);
944 lpszPath
[iLen
] = '"';
945 lpszPath
[iLen
+ 1] = '\0';
950 /*************************************************************************
951 * PathQuoteSpacesW [SHLWAPI.@]
953 * See PathQuoteSpacesA.
955 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
957 TRACE("(%s)\n", debugstr_w(lpszPath
));
959 if(lpszPath
&& StrChrW(lpszPath
,' '))
961 int iLen
= strlenW(lpszPath
) + 1;
963 if (iLen
+ 2 < MAX_PATH
)
965 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
967 lpszPath
[iLen
] = '"';
968 lpszPath
[iLen
+ 1] = '\0';
973 /*************************************************************************
974 * PathUnquoteSpacesA [SHLWAPI.@]
976 * Remove quotes ("") from around a path, if present.
979 * lpszPath [I/O] Path to strip quotes from
985 * If the path contains a single quote only, an empty string will result.
986 * Otherwise quotes are only removed if they appear at the start and end
989 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
991 TRACE("(%s)\n", debugstr_a(lpszPath
));
993 if (lpszPath
&& *lpszPath
== '"')
995 DWORD dwLen
= strlen(lpszPath
) - 1;
997 if (lpszPath
[dwLen
] == '"')
999 lpszPath
[dwLen
] = '\0';
1000 for (; *lpszPath
; lpszPath
++)
1001 *lpszPath
= lpszPath
[1];
1006 /*************************************************************************
1007 * PathUnquoteSpacesW [SHLWAPI.@]
1009 * See PathUnquoteSpacesA.
1011 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
1013 TRACE("(%s)\n", debugstr_w(lpszPath
));
1015 if (lpszPath
&& *lpszPath
== '"')
1017 DWORD dwLen
= strlenW(lpszPath
) - 1;
1019 if (lpszPath
[dwLen
] == '"')
1021 lpszPath
[dwLen
] = '\0';
1022 for (; *lpszPath
; lpszPath
++)
1023 *lpszPath
= lpszPath
[1];
1028 /*************************************************************************
1029 * PathParseIconLocationA [SHLWAPI.@]
1031 * Parse the location of an icon from a path.
1034 * lpszPath [I/O] The path to parse the icon location from.
1037 * Success: The number of the icon
1038 * Failure: 0 if the path does not contain an icon location or is NULL
1041 * The path has surrounding quotes and spaces removed regardless
1042 * of whether the call succeeds or not.
1044 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1049 TRACE("(%s)\n", debugstr_a(lpszPath
));
1053 if ((lpszComma
= strchr(lpszPath
, ',')))
1055 *lpszComma
++ = '\0';
1056 iRet
= StrToIntA(lpszComma
);
1058 PathUnquoteSpacesA(lpszPath
);
1059 PathRemoveBlanksA(lpszPath
);
1064 /*************************************************************************
1065 * PathParseIconLocationW [SHLWAPI.@]
1067 * See PathParseIconLocationA.
1069 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1074 TRACE("(%s)\n", debugstr_w(lpszPath
));
1078 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1080 *lpszComma
++ = '\0';
1081 iRet
= StrToIntW(lpszComma
);
1083 PathUnquoteSpacesW(lpszPath
);
1084 PathRemoveBlanksW(lpszPath
);
1089 /*************************************************************************
1092 * Unicode version of PathFileExistsDefExtA.
1094 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1096 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1097 { '.', 'c', 'o', 'm', 0},
1098 { '.', 'e', 'x', 'e', 0},
1099 { '.', 'b', 'a', 't', 0},
1100 { '.', 'l', 'n', 'k', 0},
1101 { '.', 'c', 'm', 'd', 0},
1104 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1106 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1111 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1112 if (!*szExt
|| dwWhich
& 0x40)
1115 int iLen
= lstrlenW(lpszPath
);
1116 if (iLen
> (MAX_PATH
- 5))
1118 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1120 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1121 if (PathFileExistsW(lpszPath
))
1126 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1130 return PathFileExistsW(lpszPath
);
1133 /*************************************************************************
1136 * Determine if a file exists locally and is of an executable type.
1139 * lpszPath [I/O] File to search for
1140 * dwWhich [I] Type of executable to search for
1143 * TRUE If the file was found. lpszPath contains the file name.
1147 * lpszPath is modified in place and must be at least MAX_PATH in length.
1148 * If the function returns FALSE, the path is modified to its original state.
1149 * If the given path contains an extension or dwWhich is 0, executable
1150 * extensions are not checked.
1152 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1153 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1154 * their own developers exclusive use. Monopoly, anyone?
1156 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1160 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1164 WCHAR szPath
[MAX_PATH
];
1165 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1166 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1168 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1173 /*************************************************************************
1174 * SHLWAPI_PathFindInOtherDirs
1176 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1178 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1180 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1181 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1185 WCHAR buff
[MAX_PATH
];
1187 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1189 /* Try system directories */
1190 GetSystemDirectoryW(buff
, MAX_PATH
);
1191 if (!PathAppendW(buff
, lpszFile
))
1193 if (PathFileExistsDefExtW(buff
, dwWhich
))
1195 strcpyW(lpszFile
, buff
);
1198 GetWindowsDirectoryW(buff
, MAX_PATH
);
1199 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1201 if (PathFileExistsDefExtW(buff
, dwWhich
))
1203 strcpyW(lpszFile
, buff
);
1206 GetWindowsDirectoryW(buff
, MAX_PATH
);
1207 if (!PathAppendW(buff
, lpszFile
))
1209 if (PathFileExistsDefExtW(buff
, dwWhich
))
1211 strcpyW(lpszFile
, buff
);
1214 /* Try dirs listed in %PATH% */
1215 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1217 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1220 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1221 lpszCurr
= lpszPATH
;
1224 LPCWSTR lpszEnd
= lpszCurr
;
1225 LPWSTR pBuff
= buff
;
1227 while (*lpszEnd
== ' ')
1229 while (*lpszEnd
&& *lpszEnd
!= ';')
1230 *pBuff
++ = *lpszEnd
++;
1234 lpszCurr
= lpszEnd
+ 1;
1236 lpszCurr
= NULL
; /* Last Path, terminate after this */
1238 if (!PathAppendW(buff
, lpszFile
))
1240 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1243 if (PathFileExistsDefExtW(buff
, dwWhich
))
1245 strcpyW(lpszFile
, buff
);
1246 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1250 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1254 /*************************************************************************
1257 * Search a range of paths for a specific type of executable.
1260 * lpszFile [I/O] File to search for
1261 * lppszOtherDirs [I] Other directories to look in
1262 * dwWhich [I] Type of executable to search for
1265 * Success: TRUE. The path to the executable is stored in lpszFile.
1266 * Failure: FALSE. The path to the executable is unchanged.
1268 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1270 WCHAR szFile
[MAX_PATH
];
1271 WCHAR buff
[MAX_PATH
];
1273 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1275 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1278 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1280 /* Search provided directories first */
1281 if (lppszOtherDirs
&& *lppszOtherDirs
)
1283 WCHAR szOther
[MAX_PATH
];
1284 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1286 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1288 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1289 PathCombineW(buff
, szOther
, szFile
);
1290 if (PathFileExistsDefExtW(buff
, dwWhich
))
1292 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1298 /* Not found, try system and path dirs */
1299 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1301 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1307 /*************************************************************************
1310 * Unicode version of PathFindOnPathExA.
1312 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1314 WCHAR buff
[MAX_PATH
];
1316 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1318 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1321 /* Search provided directories first */
1322 if (lppszOtherDirs
&& *lppszOtherDirs
)
1324 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1325 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1327 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1328 if (PathFileExistsDefExtW(buff
, dwWhich
))
1330 strcpyW(lpszFile
, buff
);
1336 /* Not found, try system and path dirs */
1337 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1340 /*************************************************************************
1341 * PathFindOnPathA [SHLWAPI.@]
1343 * Search a range of paths for an executable.
1346 * lpszFile [I/O] File to search for
1347 * lppszOtherDirs [I] Other directories to look in
1350 * Success: TRUE. The path to the executable is stored in lpszFile.
1351 * Failure: FALSE. The path to the executable is unchanged.
1353 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1355 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1356 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1359 /*************************************************************************
1360 * PathFindOnPathW [SHLWAPI.@]
1362 * See PathFindOnPathA.
1364 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1366 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1367 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1370 /*************************************************************************
1371 * PathCompactPathExA [SHLWAPI.@]
1373 * Compact a path into a given number of characters.
1376 * lpszDest [O] Destination for compacted path
1377 * lpszPath [I] Source path
1378 * cchMax [I] Maximum size of compacted path
1379 * dwFlags [I] Reserved
1382 * Success: TRUE. The compacted path is written to lpszDest.
1383 * Failure: FALSE. lpszPath is undefined.
1386 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1388 * The Win32 version of this function contains a bug: When cchMax == 7,
1389 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1392 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1393 * because Win32 will insert a "\" in lpszDest, even if one is
1394 * not present in the original path.
1396 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1397 UINT cchMax
, DWORD dwFlags
)
1401 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1403 if (lpszPath
&& lpszDest
)
1405 WCHAR szPath
[MAX_PATH
];
1406 WCHAR szDest
[MAX_PATH
];
1408 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1410 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1411 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1416 /*************************************************************************
1417 * PathCompactPathExW [SHLWAPI.@]
1419 * See PathCompactPathExA.
1421 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1422 UINT cchMax
, DWORD dwFlags
)
1424 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1426 DWORD dwLen
, dwFileLen
= 0;
1428 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1435 WARN("Invalid lpszDest would crash under Win32!\n");
1444 dwLen
= strlenW(lpszPath
) + 1;
1448 /* Don't need to compact */
1449 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1453 /* Path must be compacted to fit into lpszDest */
1454 lpszFile
= PathFindFileNameW(lpszPath
);
1455 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1457 if (dwFileLen
== dwLen
)
1459 /* No root in psth */
1462 while (--cchMax
> 0) /* No room left for anything but ellipses */
1467 /* Compact the file name with ellipses at the end */
1469 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1470 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1473 /* We have a root in the path */
1474 lpszFile
--; /* Start compacted filename with the path separator */
1477 if (dwFileLen
+ 3 > cchMax
)
1479 /* Compact the file name */
1482 while (--cchMax
> 0) /* No room left for anything but ellipses */
1487 strcpyW(lpszDest
, szEllipses
);
1490 *lpszDest
++ = *lpszFile
++;
1493 while (--cchMax
> 0) /* No room left for anything but ellipses */
1499 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1500 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1504 /* Only the root needs to be Compacted */
1505 dwLen
= cchMax
- dwFileLen
- 3;
1506 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1507 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1508 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1512 /*************************************************************************
1513 * PathIsRelativeA [SHLWAPI.@]
1515 * Determine if a path is a relative path.
1518 * lpszPath [I] Path to check
1521 * TRUE: The path is relative, or is invalid.
1522 * FALSE: The path is not relative.
1524 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1526 TRACE("(%s)\n",debugstr_a(lpszPath
));
1528 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1530 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1535 /*************************************************************************
1536 * PathIsRelativeW [SHLWAPI.@]
1538 * See PathIsRelativeA.
1540 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1542 TRACE("(%s)\n",debugstr_w(lpszPath
));
1544 if (!lpszPath
|| !*lpszPath
)
1546 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1551 /*************************************************************************
1552 * PathIsRootA [SHLWAPI.@]
1554 * Determine if a path is a root path.
1557 * lpszPath [I] Path to check
1560 * TRUE If lpszPath is valid and a root path,
1563 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1565 TRACE("(%s)\n", debugstr_a(lpszPath
));
1567 if (lpszPath
&& *lpszPath
)
1569 if (*lpszPath
== '\\')
1572 return TRUE
; /* \ */
1573 else if (lpszPath
[1]=='\\')
1575 BOOL bSeenSlash
= FALSE
;
1578 /* Check for UNC root path */
1581 if (*lpszPath
== '\\')
1587 lpszPath
= CharNextA(lpszPath
);
1592 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1593 return TRUE
; /* X:\ */
1598 /*************************************************************************
1599 * PathIsRootW [SHLWAPI.@]
1603 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1605 TRACE("(%s)\n", debugstr_w(lpszPath
));
1607 if (lpszPath
&& *lpszPath
)
1609 if (*lpszPath
== '\\')
1612 return TRUE
; /* \ */
1613 else if (lpszPath
[1]=='\\')
1615 BOOL bSeenSlash
= FALSE
;
1618 /* Check for UNC root path */
1621 if (*lpszPath
== '\\')
1632 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1633 return TRUE
; /* X:\ */
1638 /*************************************************************************
1639 * PathIsDirectoryA [SHLWAPI.@]
1641 * Determine if a path is a valid directory
1644 * lpszPath [I] Path to check.
1647 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1648 * FALSE if lpszPath is invalid or not a directory.
1651 * Although this function is prototyped as returning a BOOL, it returns
1652 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1654 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1659 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1663 TRACE("(%s)\n", debugstr_a(lpszPath
));
1665 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1668 if (PathIsUNCServerShareA(lpszPath
))
1670 FIXME("UNC Server Share not yet supported - FAILING\n");
1674 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1676 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1679 /*************************************************************************
1680 * PathIsDirectoryW [SHLWAPI.@]
1682 * See PathIsDirectoryA.
1684 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1688 TRACE("(%s)\n", debugstr_w(lpszPath
));
1690 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1693 if (PathIsUNCServerShareW(lpszPath
))
1695 FIXME("UNC Server Share not yet supported - FAILING\n");
1699 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1701 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1704 /*************************************************************************
1705 * PathFileExistsA [SHLWAPI.@]
1707 * Determine if a file exists.
1710 * lpszPath [I] Path to check
1713 * TRUE If the file exists and is readable
1716 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1721 TRACE("(%s)\n",debugstr_a(lpszPath
));
1726 /* Prevent a dialog box if path is on a disk that has been ejected. */
1727 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1728 dwAttr
= GetFileAttributesA(lpszPath
);
1729 SetErrorMode(iPrevErrMode
);
1730 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1733 /*************************************************************************
1734 * PathFileExistsW [SHLWAPI.@]
1736 * See PathFileExistsA.
1738 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1743 TRACE("(%s)\n",debugstr_w(lpszPath
));
1748 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1749 dwAttr
= GetFileAttributesW(lpszPath
);
1750 SetErrorMode(iPrevErrMode
);
1751 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1754 /*************************************************************************
1755 * PathFileExistsAndAttributesA [SHLWAPI.445]
1757 * Determine if a file exists.
1760 * lpszPath [I] Path to check
1761 * dwAttr [O] attributes of file
1764 * TRUE If the file exists and is readable
1767 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1772 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1775 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1780 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1781 dwVal
= GetFileAttributesA(lpszPath
);
1782 SetErrorMode(iPrevErrMode
);
1785 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1788 /*************************************************************************
1789 * PathFileExistsAndAttributesW [SHLWAPI.446]
1791 * See PathFileExistsA.
1793 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1798 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1803 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1804 dwVal
= GetFileAttributesW(lpszPath
);
1805 SetErrorMode(iPrevErrMode
);
1808 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1811 /*************************************************************************
1812 * PathMatchSingleMaskA [internal]
1814 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1816 while (*name
&& *mask
&& *mask
!=';')
1822 if (PathMatchSingleMaskA(name
,mask
+1))
1823 return TRUE
; /* try substrings */
1828 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1831 name
= CharNextA(name
);
1832 mask
= CharNextA(mask
);
1837 while (*mask
== '*')
1839 if (!*mask
|| *mask
== ';')
1845 /*************************************************************************
1846 * PathMatchSingleMaskW [internal]
1848 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1850 while (*name
&& *mask
&& *mask
!= ';')
1856 if (PathMatchSingleMaskW(name
,mask
+1))
1857 return TRUE
; /* try substrings */
1862 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1870 while (*mask
== '*')
1872 if (!*mask
|| *mask
== ';')
1878 /*************************************************************************
1879 * PathMatchSpecA [SHLWAPI.@]
1881 * Determine if a path matches one or more search masks.
1884 * lpszPath [I] Path to check
1885 * lpszMask [I] Search mask(s)
1888 * TRUE If lpszPath is valid and is matched
1892 * Multiple search masks may be given if they are separated by ";". The
1893 * pattern "*.*" is treated specially in that it matches all paths (for
1894 * backwards compatibility with DOS).
1896 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1898 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1900 if (!lstrcmpA(lpszMask
, "*.*"))
1901 return TRUE
; /* Matches every path */
1905 while (*lpszMask
== ' ')
1906 lpszMask
++; /* Eat leading spaces */
1908 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1909 return TRUE
; /* Matches the current mask */
1911 while (*lpszMask
&& *lpszMask
!= ';')
1912 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1914 if (*lpszMask
== ';')
1920 /*************************************************************************
1921 * PathMatchSpecW [SHLWAPI.@]
1923 * See PathMatchSpecA.
1925 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1927 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1929 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1931 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1932 return TRUE
; /* Matches every path */
1936 while (*lpszMask
== ' ')
1937 lpszMask
++; /* Eat leading spaces */
1939 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1940 return TRUE
; /* Matches the current path */
1942 while (*lpszMask
&& *lpszMask
!= ';')
1943 lpszMask
++; /* masks separated by ';' */
1945 if (*lpszMask
== ';')
1951 /*************************************************************************
1952 * PathIsSameRootA [SHLWAPI.@]
1954 * Determine if two paths share the same root.
1957 * lpszPath1 [I] Source path
1958 * lpszPath2 [I] Path to compare with
1961 * TRUE If both paths are valid and share the same root.
1962 * FALSE If either path is invalid or the paths do not share the same root.
1964 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1969 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1971 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1974 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1975 if (lpszStart
- lpszPath1
> dwLen
)
1976 return FALSE
; /* Paths not common up to length of the root */
1980 /*************************************************************************
1981 * PathIsSameRootW [SHLWAPI.@]
1983 * See PathIsSameRootA.
1985 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1990 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1992 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1995 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1996 if (lpszStart
- lpszPath1
> dwLen
)
1997 return FALSE
; /* Paths not common up to length of the root */
2001 /*************************************************************************
2002 * PathIsContentTypeA [SHLWAPI.@]
2004 * Determine if a file is of a given registered content type.
2007 * lpszPath [I] File to check
2008 * lpszContentType [I] Content type to check for
2011 * TRUE If lpszPath is a given registered content type,
2015 * This function looks up the registered content type for lpszPath. If
2016 * a content type is registered, it is compared (case insensitively) to
2017 * lpszContentType. Only if this matches does the function succeed.
2019 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2023 char szBuff
[MAX_PATH
];
2025 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2027 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2028 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2029 REG_NONE
, szBuff
, &dwDummy
) &&
2030 !strcasecmp(lpszContentType
, szBuff
))
2037 /*************************************************************************
2038 * PathIsContentTypeW [SHLWAPI.@]
2040 * See PathIsContentTypeA.
2042 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2044 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2047 WCHAR szBuff
[MAX_PATH
];
2049 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2051 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2052 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2053 REG_NONE
, szBuff
, &dwDummy
) &&
2054 !strcmpiW(lpszContentType
, szBuff
))
2061 /*************************************************************************
2062 * PathIsFileSpecA [SHLWAPI.@]
2064 * Determine if a path is a file specification.
2067 * lpszPath [I] Path to check
2070 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2073 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2075 TRACE("(%s)\n", debugstr_a(lpszPath
));
2082 if (*lpszPath
== '\\' || *lpszPath
== ':')
2084 lpszPath
= CharNextA(lpszPath
);
2089 /*************************************************************************
2090 * PathIsFileSpecW [SHLWAPI.@]
2092 * See PathIsFileSpecA.
2094 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2096 TRACE("(%s)\n", debugstr_w(lpszPath
));
2103 if (*lpszPath
== '\\' || *lpszPath
== ':')
2110 /*************************************************************************
2111 * PathIsPrefixA [SHLWAPI.@]
2113 * Determine if a path is a prefix of another.
2116 * lpszPrefix [I] Prefix
2117 * lpszPath [I] Path to check
2120 * TRUE If lpszPath has lpszPrefix as its prefix,
2121 * FALSE If either path is NULL or lpszPrefix is not a prefix
2123 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2125 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2127 if (lpszPrefix
&& lpszPath
&&
2128 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2133 /*************************************************************************
2134 * PathIsPrefixW [SHLWAPI.@]
2136 * See PathIsPrefixA.
2138 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2140 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2142 if (lpszPrefix
&& lpszPath
&&
2143 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2148 /*************************************************************************
2149 * PathIsSystemFolderA [SHLWAPI.@]
2151 * Determine if a path or file attributes are a system folder.
2154 * lpszPath [I] Path to check.
2155 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2158 * TRUE If lpszPath or dwAttrib are a system folder.
2159 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2161 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2163 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2165 if (lpszPath
&& *lpszPath
)
2166 dwAttrib
= GetFileAttributesA(lpszPath
);
2168 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2169 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2174 /*************************************************************************
2175 * PathIsSystemFolderW [SHLWAPI.@]
2177 * See PathIsSystemFolderA.
2179 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2181 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2183 if (lpszPath
&& *lpszPath
)
2184 dwAttrib
= GetFileAttributesW(lpszPath
);
2186 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2187 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2192 /*************************************************************************
2193 * PathIsUNCA [SHLWAPI.@]
2195 * Determine if a path is in UNC format.
2198 * lpszPath [I] Path to check
2201 * TRUE: The path is UNC.
2202 * FALSE: The path is not UNC or is NULL.
2204 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2206 TRACE("(%s)\n",debugstr_a(lpszPath
));
2209 * On Windows 2003, tests show that strings starting with "\\?" are
2210 * considered UNC, while on Windows Vista+ this is not the case anymore.
2212 // #ifdef __REACTOS__
2213 #if (WINVER >= _WIN32_WINNT_VISTA)
2214 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2216 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2222 /*************************************************************************
2223 * PathIsUNCW [SHLWAPI.@]
2227 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2229 TRACE("(%s)\n",debugstr_w(lpszPath
));
2232 * On Windows 2003, tests show that strings starting with "\\?" are
2233 * considered UNC, while on Windows Vista+ this is not the case anymore.
2235 // #ifdef __REACTOS__
2236 #if (WINVER >= _WIN32_WINNT_VISTA)
2237 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2239 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2245 /*************************************************************************
2246 * PathIsUNCServerA [SHLWAPI.@]
2248 * Determine if a path is a UNC server name ("\\SHARENAME").
2251 * lpszPath [I] Path to check.
2254 * TRUE If lpszPath is a valid UNC server name.
2258 * This routine is bug compatible with Win32: Server names with a
2259 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2260 * Fixing this bug may break other shlwapi functions!
2262 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2264 TRACE("(%s)\n", debugstr_a(lpszPath
));
2266 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2270 if (*lpszPath
== '\\')
2272 lpszPath
= CharNextA(lpszPath
);
2279 /*************************************************************************
2280 * PathIsUNCServerW [SHLWAPI.@]
2282 * See PathIsUNCServerA.
2284 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2286 TRACE("(%s)\n", debugstr_w(lpszPath
));
2288 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2290 return !strchrW( lpszPath
+ 2, '\\' );
2295 /*************************************************************************
2296 * PathIsUNCServerShareA [SHLWAPI.@]
2298 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2301 * lpszPath [I] Path to check.
2304 * TRUE If lpszPath is a valid UNC server share.
2308 * This routine is bug compatible with Win32: Server shares with a
2309 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2310 * Fixing this bug may break other shlwapi functions!
2312 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2314 TRACE("(%s)\n", debugstr_a(lpszPath
));
2316 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2318 BOOL bSeenSlash
= FALSE
;
2321 if (*lpszPath
== '\\')
2327 lpszPath
= CharNextA(lpszPath
);
2334 /*************************************************************************
2335 * PathIsUNCServerShareW [SHLWAPI.@]
2337 * See PathIsUNCServerShareA.
2339 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2341 TRACE("(%s)\n", debugstr_w(lpszPath
));
2343 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2345 BOOL bSeenSlash
= FALSE
;
2348 if (*lpszPath
== '\\')
2361 /*************************************************************************
2362 * PathCanonicalizeA [SHLWAPI.@]
2364 * Convert a path to its canonical form.
2367 * lpszBuf [O] Output path
2368 * lpszPath [I] Path to canonicalize
2371 * Success: TRUE. lpszBuf contains the output path,
2372 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2374 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2378 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2383 if (!lpszBuf
|| !lpszPath
)
2384 SetLastError(ERROR_INVALID_PARAMETER
);
2387 WCHAR szPath
[MAX_PATH
];
2388 WCHAR szBuff
[MAX_PATH
];
2389 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2392 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2395 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2396 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2402 /*************************************************************************
2403 * PathCanonicalizeW [SHLWAPI.@]
2405 * See PathCanonicalizeA.
2407 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2409 LPWSTR lpszDst
= lpszBuf
;
2410 LPCWSTR lpszSrc
= lpszPath
;
2412 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2417 if (!lpszBuf
|| !lpszPath
)
2419 SetLastError(ERROR_INVALID_PARAMETER
);
2430 /* Copy path root */
2431 if (*lpszSrc
== '\\')
2433 *lpszDst
++ = *lpszSrc
++;
2435 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2438 *lpszDst
++ = *lpszSrc
++;
2439 *lpszDst
++ = *lpszSrc
++;
2440 if (*lpszSrc
== '\\')
2441 *lpszDst
++ = *lpszSrc
++;
2444 /* Canonicalize the rest of the path */
2447 if (*lpszSrc
== '.')
2449 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2451 lpszSrc
+= 2; /* Skip .\ */
2453 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2455 /* \.. backs up a directory, over the root if it has no \ following X:.
2456 * .. is ignored if it would remove a UNC server name or initial \\
2458 if (lpszDst
!= lpszBuf
)
2460 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2461 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2462 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2464 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2467 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2469 if (*lpszDst
== '\\')
2470 lpszDst
++; /* Reset to last '\' */
2472 lpszDst
= lpszBuf
; /* Start path again from new root */
2474 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2477 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2479 if (lpszDst
== lpszBuf
)
2485 lpszSrc
+= 2; /* Skip .. in src path */
2488 *lpszDst
++ = *lpszSrc
++;
2491 *lpszDst
++ = *lpszSrc
++;
2493 /* Append \ to naked drive specs */
2494 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2500 /*************************************************************************
2501 * PathFindNextComponentA [SHLWAPI.@]
2503 * Find the next component in a path.
2506 * lpszPath [I] Path to find next component in
2509 * Success: A pointer to the next component, or the end of the string.
2510 * Failure: NULL, If lpszPath is invalid
2513 * A 'component' is either a backslash character (\) or UNC marker (\\).
2514 * Because of this, relative paths (e.g "c:foo") are regarded as having
2515 * only one component.
2517 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2521 TRACE("(%s)\n", debugstr_a(lpszPath
));
2523 if(!lpszPath
|| !*lpszPath
)
2526 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2528 if (lpszSlash
[1] == '\\')
2530 return lpszSlash
+ 1;
2532 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2535 /*************************************************************************
2536 * PathFindNextComponentW [SHLWAPI.@]
2538 * See PathFindNextComponentA.
2540 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2544 TRACE("(%s)\n", debugstr_w(lpszPath
));
2546 if(!lpszPath
|| !*lpszPath
)
2549 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2551 if (lpszSlash
[1] == '\\')
2553 return lpszSlash
+ 1;
2555 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2558 /*************************************************************************
2559 * PathAddExtensionA [SHLWAPI.@]
2561 * Add a file extension to a path
2564 * lpszPath [I/O] Path to add extension to
2565 * lpszExtension [I] Extension to add to lpszPath
2568 * TRUE If the path was modified,
2569 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2570 * extension already, or the new path length is too big.
2573 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2574 * does not do this, so the behaviour was removed.
2576 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2580 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2582 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2585 dwLen
= strlen(lpszPath
);
2587 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2590 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2594 /*************************************************************************
2595 * PathAddExtensionW [SHLWAPI.@]
2597 * See PathAddExtensionA.
2599 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2603 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2605 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2608 dwLen
= strlenW(lpszPath
);
2610 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2613 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2617 /*************************************************************************
2618 * PathMakePrettyA [SHLWAPI.@]
2620 * Convert an uppercase DOS filename into lowercase.
2623 * lpszPath [I/O] Path to convert.
2626 * TRUE If the path was an uppercase DOS path and was converted,
2629 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2631 LPSTR pszIter
= lpszPath
;
2633 TRACE("(%s)\n", debugstr_a(lpszPath
));
2642 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2643 return FALSE
; /* Not DOS path */
2646 pszIter
= lpszPath
+ 1;
2649 *pszIter
= tolower(*pszIter
);
2656 /*************************************************************************
2657 * PathMakePrettyW [SHLWAPI.@]
2659 * See PathMakePrettyA.
2661 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2663 LPWSTR pszIter
= lpszPath
;
2665 TRACE("(%s)\n", debugstr_w(lpszPath
));
2674 if (islowerW(*pszIter
))
2675 return FALSE
; /* Not DOS path */
2678 pszIter
= lpszPath
+ 1;
2681 *pszIter
= tolowerW(*pszIter
);
2688 /*************************************************************************
2689 * PathCommonPrefixA [SHLWAPI.@]
2691 * Determine the length of the common prefix between two paths.
2694 * lpszFile1 [I] First path for comparison
2695 * lpszFile2 [I] Second path for comparison
2696 * achPath [O] Destination for common prefix string
2699 * The length of the common prefix. This is 0 if there is no common
2700 * prefix between the paths or if any parameters are invalid. If the prefix
2701 * is non-zero and achPath is not NULL, achPath is filled with the common
2702 * part of the prefix and NUL terminated.
2705 * A common prefix of 2 is always returned as 3. It is thus possible for
2706 * the length returned to be invalid (i.e. Longer than one or both of the
2707 * strings given as parameters). This Win32 behaviour has been implemented
2708 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2709 * To work around this when using this function, always check that the byte
2710 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2712 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2715 LPCSTR lpszIter1
= lpszFile1
;
2716 LPCSTR lpszIter2
= lpszFile2
;
2718 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2723 if (!lpszFile1
|| !lpszFile2
)
2726 /* Handle roots first */
2727 if (PathIsUNCA(lpszFile1
))
2729 if (!PathIsUNCA(lpszFile2
))
2734 else if (PathIsUNCA(lpszFile2
))
2735 return 0; /* Know already lpszFile1 is not UNC */
2740 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2741 (!*lpszIter2
|| *lpszIter2
== '\\'))
2742 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2744 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2745 break; /* Strings differ at this point */
2752 iLen
++; /* Feature/Bug compatible with Win32 */
2754 if (iLen
&& achPath
)
2756 memcpy(achPath
,lpszFile1
,iLen
);
2757 achPath
[iLen
] = '\0';
2762 /*************************************************************************
2763 * PathCommonPrefixW [SHLWAPI.@]
2765 * See PathCommonPrefixA.
2767 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2770 LPCWSTR lpszIter1
= lpszFile1
;
2771 LPCWSTR lpszIter2
= lpszFile2
;
2773 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2778 if (!lpszFile1
|| !lpszFile2
)
2781 /* Handle roots first */
2782 if (PathIsUNCW(lpszFile1
))
2784 if (!PathIsUNCW(lpszFile2
))
2789 else if (PathIsUNCW(lpszFile2
))
2790 return 0; /* Know already lpszFile1 is not UNC */
2795 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2796 (!*lpszIter2
|| *lpszIter2
== '\\'))
2797 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2799 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2800 break; /* Strings differ at this point */
2807 iLen
++; /* Feature/Bug compatible with Win32 */
2809 if (iLen
&& achPath
)
2811 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2812 achPath
[iLen
] = '\0';
2817 /*************************************************************************
2818 * PathCompactPathA [SHLWAPI.@]
2820 * Make a path fit into a given width when printed to a DC.
2823 * hDc [I] Destination DC
2824 * lpszPath [I/O] Path to be printed to hDc
2825 * dx [I] Desired width
2828 * TRUE If the path was modified/went well.
2831 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2835 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2839 WCHAR szPath
[MAX_PATH
];
2840 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2841 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2842 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2847 /*************************************************************************
2848 * PathCompactPathW [SHLWAPI.@]
2850 * See PathCompactPathA.
2852 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2854 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2857 WCHAR buff
[MAX_PATH
];
2861 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2867 hdc
= hDC
= GetDC(0);
2869 /* Get the length of the whole path */
2870 dwLen
= strlenW(lpszPath
);
2871 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2873 if ((UINT
)size
.cx
> dx
)
2875 /* Path too big, must reduce it */
2877 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2879 sFile
= PathFindFileNameW(lpszPath
);
2880 if (sFile
!= lpszPath
) sFile
--;
2882 /* Get the size of ellipses */
2883 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2884 dwEllipsesLen
= size
.cx
;
2885 /* Get the size of the file name */
2886 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2887 dwPathLen
= size
.cx
;
2889 if (sFile
!= lpszPath
)
2891 LPWSTR sPath
= sFile
;
2892 BOOL bEllipses
= FALSE
;
2894 /* The path includes a file name. Include as much of the path prior to
2895 * the file name as possible, allowing for the ellipses, e.g:
2896 * c:\some very long path\filename ==> c:\some v...\filename
2898 lstrcpynW(buff
, sFile
, MAX_PATH
);
2902 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2904 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2905 dwTotalLen
+= size
.cx
;
2906 if (dwTotalLen
<= dx
)
2914 } while (sPath
> lpszPath
);
2916 if (sPath
> lpszPath
)
2920 strcpyW(sPath
, szEllipses
);
2921 strcpyW(sPath
+3, buff
);
2926 strcpyW(lpszPath
, szEllipses
);
2927 strcpyW(lpszPath
+3, buff
);
2932 /* Trim the path by adding ellipses to the end, e.g:
2933 * A very long file name.txt ==> A very...
2935 dwLen
= strlenW(lpszPath
);
2937 if (dwLen
> MAX_PATH
- 3)
2938 dwLen
= MAX_PATH
- 3;
2939 lstrcpynW(buff
, sFile
, dwLen
);
2943 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2944 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2948 DWORD dwWritten
= 0;
2950 dwEllipsesLen
/= 3; /* Size of a single '.' */
2952 /* Write as much of the Ellipses string as possible */
2953 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2956 dwWritten
+= dwEllipsesLen
;
2964 strcpyW(buff
+ dwLen
, szEllipses
);
2965 strcpyW(lpszPath
, buff
);
2976 /*************************************************************************
2977 * PathGetCharTypeA [SHLWAPI.@]
2979 * Categorise a character from a file path.
2982 * ch [I] Character to get the type of
2985 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2987 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2989 return PathGetCharTypeW(ch
);
2992 /*************************************************************************
2993 * PathGetCharTypeW [SHLWAPI.@]
2995 * See PathGetCharTypeA.
2997 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
3001 TRACE("(%d)\n", ch
);
3003 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
3004 ch
== '"' || ch
== '|' || ch
== '/')
3005 flags
= GCT_INVALID
; /* Invalid */
3006 else if (ch
== '*' || ch
=='?')
3007 flags
= GCT_WILD
; /* Wildchars */
3008 else if ((ch
== '\\') || (ch
== ':'))
3009 return GCT_SEPARATOR
; /* Path separators */
3014 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
3015 ch
== '.' || ch
== '@' || ch
== '^' ||
3016 ch
== '\'' || ch
== 130 || ch
== '`')
3017 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
3020 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
3021 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
3026 /*************************************************************************
3027 * SHLWAPI_UseSystemForSystemFolders
3029 * Internal helper for PathMakeSystemFolderW.
3031 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3033 static BOOL bCheckedReg
= FALSE
;
3034 static BOOL bUseSystemForSystemFolders
= FALSE
;
3040 /* Key tells Win what file attributes to use on system folders */
3041 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3042 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3043 "UseSystemForSystemFolders", 0, 0, 0))
3044 bUseSystemForSystemFolders
= TRUE
;
3046 return bUseSystemForSystemFolders
;
3049 /*************************************************************************
3050 * PathMakeSystemFolderA [SHLWAPI.@]
3052 * Set system folder attribute for a path.
3055 * lpszPath [I] The path to turn into a system folder
3058 * TRUE If the path was changed to/already was a system folder
3059 * FALSE If the path is invalid or SetFileAttributesA() fails
3061 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3065 TRACE("(%s)\n", debugstr_a(lpszPath
));
3067 if (lpszPath
&& *lpszPath
)
3069 WCHAR szPath
[MAX_PATH
];
3070 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3071 bRet
= PathMakeSystemFolderW(szPath
);
3076 /*************************************************************************
3077 * PathMakeSystemFolderW [SHLWAPI.@]
3079 * See PathMakeSystemFolderA.
3081 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3083 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3084 WCHAR buff
[MAX_PATH
];
3086 TRACE("(%s)\n", debugstr_w(lpszPath
));
3088 if (!lpszPath
|| !*lpszPath
)
3091 /* If the directory is already a system directory, don't do anything */
3092 GetSystemDirectoryW(buff
, MAX_PATH
);
3093 if (!strcmpW(buff
, lpszPath
))
3096 GetWindowsDirectoryW(buff
, MAX_PATH
);
3097 if (!strcmpW(buff
, lpszPath
))
3100 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3101 if (SHLWAPI_UseSystemForSystemFolders())
3102 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3104 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3107 /* Change file attributes to system attributes */
3108 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3109 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3112 /*************************************************************************
3113 * PathRenameExtensionA [SHLWAPI.@]
3115 * Swap the file extension in a path with another extension.
3118 * lpszPath [I/O] Path to swap the extension in
3119 * lpszExt [I] The new extension
3122 * TRUE if lpszPath was modified,
3123 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3125 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3127 LPSTR lpszExtension
;
3129 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3131 lpszExtension
= PathFindExtensionA(lpszPath
);
3133 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3136 strcpy(lpszExtension
, lpszExt
);
3140 /*************************************************************************
3141 * PathRenameExtensionW [SHLWAPI.@]
3143 * See PathRenameExtensionA.
3145 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3147 LPWSTR lpszExtension
;
3149 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3151 lpszExtension
= PathFindExtensionW(lpszPath
);
3153 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3156 strcpyW(lpszExtension
, lpszExt
);
3160 /*************************************************************************
3161 * PathSearchAndQualifyA [SHLWAPI.@]
3163 * Determine if a given path is correct and fully qualified.
3166 * lpszPath [I] Path to check
3167 * lpszBuf [O] Output for correct path
3168 * cchBuf [I] Size of lpszBuf
3173 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3175 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3177 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3179 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3182 /*************************************************************************
3183 * PathSearchAndQualifyW [SHLWAPI.@]
3185 * See PathSearchAndQualifyA.
3187 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3189 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3191 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3193 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3196 /*************************************************************************
3197 * PathSkipRootA [SHLWAPI.@]
3199 * Return the portion of a path following the drive letter or mount point.
3202 * lpszPath [I] The path to skip on
3205 * Success: A pointer to the next character after the root.
3206 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3208 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3210 TRACE("(%s)\n", debugstr_a(lpszPath
));
3212 if (!lpszPath
|| !*lpszPath
)
3215 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3217 /* Network share: skip share server and mount point */
3219 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3220 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3222 return (LPSTR
)lpszPath
;
3225 if (IsDBCSLeadByte(*lpszPath
))
3229 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3230 return (LPSTR
)lpszPath
+ 3;
3234 /*************************************************************************
3235 * PathSkipRootW [SHLWAPI.@]
3237 * See PathSkipRootA.
3239 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3241 TRACE("(%s)\n", debugstr_w(lpszPath
));
3243 if (!lpszPath
|| !*lpszPath
)
3246 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3248 /* Network share: skip share server and mount point */
3250 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3251 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3253 return (LPWSTR
)lpszPath
;
3257 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3258 return (LPWSTR
)lpszPath
+ 3;
3262 /*************************************************************************
3263 * PathCreateFromUrlA [SHLWAPI.@]
3265 * See PathCreateFromUrlW
3267 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3268 LPDWORD pcchPath
, DWORD dwReserved
)
3270 WCHAR bufW
[MAX_PATH
];
3271 WCHAR
*pathW
= bufW
;
3272 UNICODE_STRING urlW
;
3274 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3276 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3277 return E_INVALIDARG
;
3279 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3280 return E_INVALIDARG
;
3281 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3282 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3283 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3286 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3287 if(*pcchPath
> lenA
) {
3288 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3292 *pcchPath
= lenA
+ 1;
3296 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3297 RtlFreeUnicodeString(&urlW
);
3301 /*************************************************************************
3302 * PathCreateFromUrlW [SHLWAPI.@]
3304 * Create a path from a URL
3307 * lpszUrl [I] URL to convert into a path
3308 * lpszPath [O] Output buffer for the resulting Path
3309 * pcchPath [I] Length of lpszPath
3310 * dwFlags [I] Flags controlling the conversion
3313 * Success: S_OK. lpszPath contains the URL in path format,
3314 * Failure: An HRESULT error code such as E_INVALIDARG.
3316 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3317 LPDWORD pcchPath
, DWORD dwReserved
)
3319 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3320 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3321 DWORD nslashes
, unescape
, len
;
3326 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3328 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3329 return E_INVALIDARG
;
3331 if (lstrlenW(pszUrl
) < 5)
3332 return E_INVALIDARG
;
3334 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3335 file_colon
, 5) != CSTR_EQUAL
)
3336 return E_INVALIDARG
;
3342 while (*src
== '/' || *src
== '\\') {
3347 /* We need a temporary buffer so we can compute what size to ask for.
3348 * We know that the final string won't be longer than the current pszUrl
3349 * plus at most two backslashes. All the other transformations make it
3352 len
= 2 + lstrlenW(pszUrl
) + 1;
3353 if (*pcchPath
< len
)
3354 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3364 /* 'file:' + escaped DOS path */
3367 /* 'file:/' + escaped DOS path */
3370 /* 'file:///' (implied localhost) + escaped DOS path */
3371 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3375 if (lstrlenW(src
) >= 10 && CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
,
3376 src
, 9, localhost
, 9) == CSTR_EQUAL
&& (src
[9] == '/' || src
[9] == '\\'))
3378 /* 'file://localhost/' + escaped DOS path */
3381 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3383 /* 'file://' + unescaped DOS path */
3388 /* 'file://hostname:port/path' (where path is escaped)
3389 * or 'file:' + escaped UNC path (\\server\share\path)
3390 * The second form is clearly specific to Windows and it might
3391 * even be doing a network lookup to try to figure it out.
3393 while (*src
&& *src
!= '/' && *src
!= '\\')
3396 StrCpyNW(dst
, pszUrl
, len
+ 1);
3398 if (*src
&& isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3400 /* 'Forget' to add a trailing '/', just like Windows */
3406 /* 'file://' + unescaped UNC path (\\server\share\path) */
3408 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3412 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3416 /* Copy the remainder of the path */
3417 len
+= lstrlenW(src
);
3420 /* First do the Windows-specific path conversions */
3421 for (dst
= tpath
; *dst
; dst
++)
3422 if (*dst
== '/') *dst
= '\\';
3423 if (isalphaW(*tpath
) && tpath
[1] == '|')
3424 tpath
[1] = ':'; /* c| -> c: */
3426 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3429 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3432 /* When working in-place UrlUnescapeW() does not set len */
3433 len
= lstrlenW(tpath
);
3437 if (*pcchPath
< len
+ 1)
3440 *pcchPath
= len
+ 1;
3445 if (tpath
!= pszPath
)
3446 StrCpyW(pszPath
, tpath
);
3448 if (tpath
!= pszPath
)
3449 HeapFree(GetProcessHeap(), 0, tpath
);
3451 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3455 /*************************************************************************
3456 * PathCreateFromUrlAlloc [SHLWAPI.@]
3458 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3461 WCHAR pathW
[MAX_PATH
];
3466 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3469 /* Yes, this is supposed to crash if pszPath is NULL */
3470 *pszPath
= StrDupW(pathW
);
3475 /*************************************************************************
3476 * PathRelativePathToA [SHLWAPI.@]
3478 * Create a relative path from one path to another.
3481 * lpszPath [O] Destination for relative path
3482 * lpszFrom [I] Source path
3483 * dwAttrFrom [I] File attribute of source path
3484 * lpszTo [I] Destination path
3485 * dwAttrTo [I] File attributes of destination path
3488 * TRUE If a relative path can be formed. lpszPath contains the new path
3489 * FALSE If the paths are not relative or any parameters are invalid
3492 * lpszTo should be at least MAX_PATH in length.
3494 * Calling this function with relative paths for lpszFrom or lpszTo may
3495 * give erroneous results.
3497 * The Win32 version of this function contains a bug where the lpszTo string
3498 * may be referenced 1 byte beyond the end of the string. As a result random
3499 * garbage may be written to the output path, depending on what lies beyond
3500 * the last byte of the string. This bug occurs because of the behaviour of
3501 * PathCommonPrefix() (see notes for that function), and no workaround seems
3502 * possible with Win32.
3504 * This bug has been fixed here, so for example the relative path from "\\"
3505 * to "\\" is correctly determined as "." in this implementation.
3507 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3508 LPCSTR lpszTo
, DWORD dwAttrTo
)
3512 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3513 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3515 if(lpszPath
&& lpszFrom
&& lpszTo
)
3517 WCHAR szPath
[MAX_PATH
];
3518 WCHAR szFrom
[MAX_PATH
];
3519 WCHAR szTo
[MAX_PATH
];
3520 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3521 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3522 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3523 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3528 /*************************************************************************
3529 * PathRelativePathToW [SHLWAPI.@]
3531 * See PathRelativePathToA.
3533 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3534 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3536 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3537 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3538 WCHAR szFrom
[MAX_PATH
];
3539 WCHAR szTo
[MAX_PATH
];
3542 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3543 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3545 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3549 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3550 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3552 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3553 PathRemoveFileSpecW(szFrom
);
3554 if(!(dwAttrTo
& FILE_ATTRIBUTE_DIRECTORY
))
3555 PathRemoveFileSpecW(szTo
);
3557 /* Paths can only be relative if they have a common root */
3558 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3561 /* Strip off lpszFrom components to the root, by adding "..\" */
3562 lpszFrom
= szFrom
+ dwLen
;
3568 if (*lpszFrom
== '\\')
3573 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3574 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3577 /* From the root add the components of lpszTo */
3579 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3582 if (*lpszTo
&& lpszTo
[-1])
3584 if (*lpszTo
!= '\\')
3586 dwLen
= strlenW(lpszPath
);
3587 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3592 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3597 /*************************************************************************
3598 * PathUnmakeSystemFolderA [SHLWAPI.@]
3600 * Remove the system folder attributes from a path.
3603 * lpszPath [I] The path to remove attributes from
3607 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3608 * SetFileAttributesA() fails.
3610 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3614 TRACE("(%s)\n", debugstr_a(lpszPath
));
3616 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3617 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3620 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3621 return SetFileAttributesA(lpszPath
, dwAttr
);
3624 /*************************************************************************
3625 * PathUnmakeSystemFolderW [SHLWAPI.@]
3627 * See PathUnmakeSystemFolderA.
3629 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3633 TRACE("(%s)\n", debugstr_w(lpszPath
));
3635 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3636 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3639 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3640 return SetFileAttributesW(lpszPath
, dwAttr
);
3644 /*************************************************************************
3645 * PathSetDlgItemPathA [SHLWAPI.@]
3647 * Set the text of a dialog item to a path, shrinking the path to fit
3648 * if it is too big for the item.
3651 * hDlg [I] Dialog handle
3652 * id [I] ID of item in the dialog
3653 * lpszPath [I] Path to set as the items text
3659 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3660 * window text is erased).
3662 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3664 WCHAR szPath
[MAX_PATH
];
3666 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3669 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3672 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3675 /*************************************************************************
3676 * PathSetDlgItemPathW [SHLWAPI.@]
3678 * See PathSetDlgItemPathA.
3680 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3682 WCHAR path
[MAX_PATH
+ 1];
3688 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3690 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3694 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3698 GetClientRect(hwItem
, &rect
);
3700 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3704 PathCompactPathW(hdc
, path
, rect
.right
);
3705 SelectObject(hdc
, hPrevObj
);
3708 ReleaseDC(hDlg
, hdc
);
3709 SetWindowTextW(hwItem
, path
);
3712 /*************************************************************************
3713 * PathIsNetworkPathA [SHLWAPI.@]
3715 * Determine if the given path is a network path.
3718 * lpszPath [I] Path to check
3721 * TRUE If lpszPath is a UNC share or mapped network drive, or
3722 * FALSE If lpszPath is a local drive or cannot be determined
3724 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3728 TRACE("(%s)\n",debugstr_a(lpszPath
));
3732 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3734 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3735 if (dwDriveNum
== -1)
3738 return IsNetDrive(dwDriveNum
);
3740 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3741 return pIsNetDrive(dwDriveNum
);
3745 /*************************************************************************
3746 * PathIsNetworkPathW [SHLWAPI.@]
3748 * See PathIsNetworkPathA.
3750 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3754 TRACE("(%s)\n", debugstr_w(lpszPath
));
3758 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3760 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3761 if (dwDriveNum
== -1)
3764 return IsNetDrive(dwDriveNum
);
3766 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3767 return pIsNetDrive(dwDriveNum
);
3771 /*************************************************************************
3772 * PathIsLFNFileSpecA [SHLWAPI.@]
3774 * Determine if the given path is a long file name
3777 * lpszPath [I] Path to check
3780 * TRUE If path is a long file name,
3781 * FALSE If path is a valid DOS short file name
3783 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3785 DWORD dwNameLen
= 0, dwExtLen
= 0;
3787 TRACE("(%s)\n",debugstr_a(lpszPath
));
3794 if (*lpszPath
== ' ')
3795 return TRUE
; /* DOS names cannot have spaces */
3796 if (*lpszPath
== '.')
3799 return TRUE
; /* DOS names have only one dot */
3806 return TRUE
; /* DOS extensions are <= 3 chars*/
3812 return TRUE
; /* DOS names are <= 8 chars */
3814 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3816 return FALSE
; /* Valid DOS path */
3819 /*************************************************************************
3820 * PathIsLFNFileSpecW [SHLWAPI.@]
3822 * See PathIsLFNFileSpecA.
3824 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3826 DWORD dwNameLen
= 0, dwExtLen
= 0;
3828 TRACE("(%s)\n",debugstr_w(lpszPath
));
3835 if (*lpszPath
== ' ')
3836 return TRUE
; /* DOS names cannot have spaces */
3837 if (*lpszPath
== '.')
3840 return TRUE
; /* DOS names have only one dot */
3847 return TRUE
; /* DOS extensions are <= 3 chars*/
3853 return TRUE
; /* DOS names are <= 8 chars */
3857 return FALSE
; /* Valid DOS path */
3860 /*************************************************************************
3861 * PathIsDirectoryEmptyA [SHLWAPI.@]
3863 * Determine if a given directory is empty.
3866 * lpszPath [I] Directory to check
3869 * TRUE If the directory exists and contains no files,
3872 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3876 TRACE("(%s)\n",debugstr_a(lpszPath
));
3880 WCHAR szPath
[MAX_PATH
];
3881 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3882 bRet
= PathIsDirectoryEmptyW(szPath
);
3887 /*************************************************************************
3888 * PathIsDirectoryEmptyW [SHLWAPI.@]
3890 * See PathIsDirectoryEmptyA.
3892 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3894 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3895 WCHAR szSearch
[MAX_PATH
];
3899 WIN32_FIND_DATAW find_data
;
3901 TRACE("(%s)\n",debugstr_w(lpszPath
));
3903 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3906 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3907 PathAddBackslashW(szSearch
);
3908 dwLen
= strlenW(szSearch
);
3909 if (dwLen
> MAX_PATH
- 4)
3912 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3913 hfind
= FindFirstFileW(szSearch
, &find_data
);
3914 if (hfind
== INVALID_HANDLE_VALUE
)
3919 if (find_data
.cFileName
[0] == '.')
3921 if (find_data
.cFileName
[1] == '\0') continue;
3922 if (find_data
.cFileName
[1] == '.' && find_data
.cFileName
[2] == '\0') continue;
3928 while (FindNextFileW(hfind
, &find_data
));
3935 /*************************************************************************
3936 * PathFindSuffixArrayA [SHLWAPI.@]
3938 * Find a suffix string in an array of suffix strings
3941 * lpszSuffix [I] Suffix string to search for
3942 * lppszArray [I] Array of suffix strings to search
3943 * dwCount [I] Number of elements in lppszArray
3946 * Success: The index of the position of lpszSuffix in lppszArray
3947 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3950 * The search is case sensitive.
3951 * The match is made against the end of the suffix string, so for example:
3952 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3954 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3959 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3961 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3963 dwLen
= strlen(lpszSuffix
);
3965 while (dwRet
< dwCount
)
3967 size_t dwCompareLen
= strlen(*lppszArray
);
3968 if (dwCompareLen
< dwLen
)
3970 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3971 return *lppszArray
; /* Found */
3980 /*************************************************************************
3981 * PathFindSuffixArrayW [SHLWAPI.@]
3983 * See PathFindSuffixArrayA.
3985 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3990 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3992 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3994 dwLen
= strlenW(lpszSuffix
);
3996 while (dwRet
< dwCount
)
3998 size_t dwCompareLen
= strlenW(*lppszArray
);
3999 if (dwCompareLen
< dwLen
)
4001 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
4002 return *lppszArray
; /* Found */
4011 /*************************************************************************
4012 * PathUndecorateA [SHLWAPI.@]
4014 * Undecorate a file path
4017 * lpszPath [I/O] Path to remove any decoration from
4023 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
4025 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
4027 TRACE("(%s)\n",debugstr_a(lpszPath
));
4031 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
4032 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4034 LPSTR lpszSkip
= lpszExt
- 2;
4035 if (*lpszSkip
== '[')
4036 lpszSkip
++; /* [] (no number) */
4038 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
4040 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4042 /* remove the [n] */
4045 *lpszSkip
++ = *lpszExt
++;
4052 /*************************************************************************
4053 * PathUndecorateW [SHLWAPI.@]
4055 * See PathUndecorateA.
4057 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4059 TRACE("(%s)\n",debugstr_w(lpszPath
));
4063 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4064 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4066 LPWSTR lpszSkip
= lpszExt
- 2;
4067 if (*lpszSkip
== '[')
4068 lpszSkip
++; /* [] (no number) */
4070 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4072 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4074 /* remove the [n] */
4077 *lpszSkip
++ = *lpszExt
++;
4084 /*************************************************************************
4085 * PathUnExpandEnvStringsA [SHLWAPI.@]
4087 * Substitute folder names in a path with their corresponding environment
4091 * path [I] Buffer containing the path to unexpand.
4092 * buffer [O] Buffer to receive the unexpanded path.
4093 * buf_len [I] Size of pszBuf in characters.
4099 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4101 WCHAR bufferW
[MAX_PATH
], *pathW
;
4105 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4107 pathW
= heap_strdupAtoW(path
);
4108 if (!pathW
) return FALSE
;
4110 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4111 HeapFree(GetProcessHeap(), 0, pathW
);
4112 if (!ret
) return FALSE
;
4114 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4115 if (buf_len
< len
+ 1) return FALSE
;
4117 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4121 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4122 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4123 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4124 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4125 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4126 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4132 WCHAR path
[MAX_PATH
];
4136 static void init_envvars_map(struct envvars_map
*map
)
4140 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4141 /* exclude null from length */
4142 if (map
->len
) map
->len
--;
4147 /*************************************************************************
4148 * PathUnExpandEnvStringsW [SHLWAPI.@]
4150 * Unicode version of PathUnExpandEnvStringsA.
4152 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4154 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4155 struct envvars_map
*match
= &null_var
, *cur
;
4156 struct envvars_map envvars
[] = {
4157 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4158 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4159 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4160 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4161 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4162 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4168 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4170 pathlen
= strlenW(path
);
4171 init_envvars_map(envvars
);
4175 /* path can't contain expanded value or value wasn't retrieved */
4176 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4182 if (cur
->len
> match
->len
)
4187 /* 'varlen' includes NULL termination char */
4188 needed
= match
->varlen
+ pathlen
- match
->len
;
4189 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4191 strcpyW(buffer
, match
->var
);
4192 strcatW(buffer
, &path
[match
->len
]);
4193 TRACE("ret %s\n", debugstr_w(buffer
));
4198 /*************************************************************************
4201 * Find localised or default web content in "%WINDOWS%\web\".
4204 * lpszFile [I] File name containing content to look for
4205 * lpszPath [O] Buffer to contain the full path to the file
4206 * dwPathLen [I] Length of lpszPath
4209 * Success: S_OK. lpszPath contains the full path to the content.
4210 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4212 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4214 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4217 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4219 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4221 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4222 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4226 /*************************************************************************
4229 * Unicode version of SHGetWebFolderFilePathA.
4231 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4233 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4234 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4235 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4236 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4237 DWORD dwLen
, dwFileLen
;
4238 LANGID lidSystem
, lidUser
;
4240 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4242 /* Get base directory for web content */
4243 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4244 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4247 dwFileLen
= strlenW(lpszFile
);
4249 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4250 return E_FAIL
; /* lpszPath too short */
4252 strcpyW(lpszPath
+dwLen
, szWeb
);
4254 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4256 lidSystem
= GetSystemDefaultUILanguage();
4257 lidUser
= GetUserDefaultUILanguage();
4259 if (lidSystem
!= lidUser
)
4261 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4263 /* Use localised content in the users UI language if present */
4264 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4265 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4266 if (PathFileExistsW(lpszPath
))
4271 /* Fall back to OS default installed content */
4272 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4273 if (PathFileExistsW(lpszPath
))
4278 #define PATH_CHAR_CLASS_LETTER 0x00000001
4279 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4280 #define PATH_CHAR_CLASS_DOT 0x00000004
4281 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4282 #define PATH_CHAR_CLASS_COLON 0x00000010
4283 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4284 #define PATH_CHAR_CLASS_COMMA 0x00000040
4285 #define PATH_CHAR_CLASS_SPACE 0x00000080
4286 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4287 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4289 #define PATH_CHAR_CLASS_INVALID 0x00000000
4290 #define PATH_CHAR_CLASS_ANY 0xffffffff
4292 static const DWORD SHELL_charclass
[] =
4294 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4295 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4296 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4297 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4298 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4299 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4300 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4301 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4302 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4303 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4304 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4305 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4306 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4307 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4308 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4309 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4310 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4311 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4312 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4313 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4314 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4315 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4316 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4317 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4318 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4319 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4320 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4321 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4322 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4323 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4324 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4325 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4326 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4327 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4328 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4329 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4330 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4331 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4332 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4333 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4334 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4335 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4336 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4337 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4338 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4339 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4340 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4341 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4342 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4343 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4344 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4345 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4346 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4347 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4348 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4349 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4350 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4351 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4352 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4353 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4354 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4355 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4356 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4357 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4360 /*************************************************************************
4363 * Check if an ASCII char is of a certain class
4365 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4367 if ((unsigned)c
> 0x7e)
4368 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4370 return class & SHELL_charclass
[(unsigned)c
];
4373 /*************************************************************************
4376 * Check if a Unicode char is of a certain class
4378 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4381 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4383 return class & SHELL_charclass
[c
];