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
22 #define WIN32_NO_STATUS
24 #define COM_NO_WINDOWS_H
27 //#include "wine/port.h"
33 #include <wine/unicode.h>
40 #define NO_SHLWAPI_STREAM
42 #include <wine/debug.h>
44 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
46 /* Get a function pointer from a DLL handle */
47 #define GET_FUNC(func, module, name, fail) \
50 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
51 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
52 if (!func) return fail; \
56 /* DLL handles for late bound calls */
57 static HMODULE SHLWAPI_hshell32
;
59 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
60 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
61 static fnpIsNetDrive pIsNetDrive
;
63 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
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
)
153 MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
);
155 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))
165 /*************************************************************************
166 * PathCombineW [SHLWAPI.@]
170 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
172 WCHAR szTemp
[MAX_PATH
];
173 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
175 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
177 /* Invalid parameters */
180 if (!lpszDir
&& !lpszFile
)
186 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
189 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
191 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
193 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
196 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
209 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
212 PathStripToRootW(szTemp
);
213 lpszFile
++; /* Skip '\' */
215 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
220 strcatW(szTemp
, lpszFile
);
223 PathCanonicalizeW(lpszDest
, szTemp
);
227 /*************************************************************************
228 * PathAddBackslashA [SHLWAPI.@]
230 * Append a backslash ('\') to a path if one doesn't exist.
233 * lpszPath [I/O] The path to append a backslash to.
236 * Success: The position of the last backslash in the path.
237 * Failure: NULL, if lpszPath is NULL or the path is too large.
239 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
242 LPSTR prev
= lpszPath
;
244 TRACE("(%s)\n",debugstr_a(lpszPath
));
246 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
252 lpszPath
= CharNextA(prev
);
265 /*************************************************************************
266 * PathAddBackslashW [SHLWAPI.@]
268 * See PathAddBackslashA.
270 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
274 TRACE("(%s)\n",debugstr_w(lpszPath
));
276 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
282 if (lpszPath
[-1] != '\\')
291 /*************************************************************************
292 * PathBuildRootA [SHLWAPI.@]
294 * Create a root drive string (e.g. "A:\") from a drive number.
297 * lpszPath [O] Destination for the drive string
303 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
305 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
307 TRACE("(%p,%d)\n", lpszPath
, drive
);
309 if (lpszPath
&& drive
>= 0 && drive
< 26)
311 lpszPath
[0] = 'A' + drive
;
319 /*************************************************************************
320 * PathBuildRootW [SHLWAPI.@]
322 * See PathBuildRootA.
324 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
326 TRACE("(%p,%d)\n", lpszPath
, drive
);
328 if (lpszPath
&& drive
>= 0 && drive
< 26)
330 lpszPath
[0] = 'A' + drive
;
338 /*************************************************************************
339 * PathFindFileNameA [SHLWAPI.@]
341 * Locate the start of the file name in a path
344 * lpszPath [I] Path to search
347 * A pointer to the first character of the file name
349 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
351 LPCSTR lastSlash
= lpszPath
;
353 TRACE("(%s)\n",debugstr_a(lpszPath
));
355 while (lpszPath
&& *lpszPath
)
357 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
358 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
359 lastSlash
= lpszPath
+ 1;
360 lpszPath
= CharNextA(lpszPath
);
362 return (LPSTR
)lastSlash
;
365 /*************************************************************************
366 * PathFindFileNameW [SHLWAPI.@]
368 * See PathFindFileNameA.
370 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
372 LPCWSTR lastSlash
= lpszPath
;
374 TRACE("(%s)\n",debugstr_w(lpszPath
));
376 while (lpszPath
&& *lpszPath
)
378 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
379 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
380 lastSlash
= lpszPath
+ 1;
383 return (LPWSTR
)lastSlash
;
386 /*************************************************************************
387 * PathFindExtensionA [SHLWAPI.@]
389 * Locate the start of the file extension in a path
392 * lpszPath [I] The path to search
395 * A pointer to the first character of the extension, the end of
396 * the string if the path has no extension, or NULL If lpszPath is NULL
398 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
400 LPCSTR lastpoint
= NULL
;
402 TRACE("(%s)\n", debugstr_a(lpszPath
));
408 if (*lpszPath
== '\\' || *lpszPath
==' ')
410 else if (*lpszPath
== '.')
411 lastpoint
= lpszPath
;
412 lpszPath
= CharNextA(lpszPath
);
415 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
418 /*************************************************************************
419 * PathFindExtensionW [SHLWAPI.@]
421 * See PathFindExtensionA.
423 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
425 LPCWSTR lastpoint
= NULL
;
427 TRACE("(%s)\n", debugstr_w(lpszPath
));
433 if (*lpszPath
== '\\' || *lpszPath
==' ')
435 else if (*lpszPath
== '.')
436 lastpoint
= lpszPath
;
440 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
443 /*************************************************************************
444 * PathGetArgsA [SHLWAPI.@]
446 * Find the next argument in a string delimited by spaces.
449 * lpszPath [I] The string to search for arguments in
452 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
455 * Spaces in quoted strings are ignored as delimiters.
457 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
459 BOOL bSeenQuote
= FALSE
;
461 TRACE("(%s)\n",debugstr_a(lpszPath
));
467 if ((*lpszPath
==' ') && !bSeenQuote
)
468 return (LPSTR
)lpszPath
+ 1;
469 if (*lpszPath
== '"')
470 bSeenQuote
= !bSeenQuote
;
471 lpszPath
= CharNextA(lpszPath
);
474 return (LPSTR
)lpszPath
;
477 /*************************************************************************
478 * PathGetArgsW [SHLWAPI.@]
482 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
484 BOOL bSeenQuote
= FALSE
;
486 TRACE("(%s)\n",debugstr_w(lpszPath
));
492 if ((*lpszPath
==' ') && !bSeenQuote
)
493 return (LPWSTR
)lpszPath
+ 1;
494 if (*lpszPath
== '"')
495 bSeenQuote
= !bSeenQuote
;
499 return (LPWSTR
)lpszPath
;
502 /*************************************************************************
503 * PathGetDriveNumberA [SHLWAPI.@]
505 * Return the drive number from a path
508 * lpszPath [I] Path to get the drive number from
511 * Success: The drive number corresponding to the drive in the path
512 * Failure: -1, if lpszPath contains no valid drive
514 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
516 TRACE ("(%s)\n",debugstr_a(lpszPath
));
518 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
519 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
520 return tolower(*lpszPath
) - 'a';
524 /*************************************************************************
525 * PathGetDriveNumberW [SHLWAPI.@]
527 * See PathGetDriveNumberA.
529 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
531 TRACE ("(%s)\n",debugstr_w(lpszPath
));
535 WCHAR tl
= tolowerW(lpszPath
[0]);
536 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
542 /*************************************************************************
543 * PathRemoveFileSpecA [SHLWAPI.@]
545 * Remove the file specification from a path.
548 * lpszPath [I/O] Path to remove the file spec from
551 * TRUE If the path was valid and modified
554 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
556 LPSTR lpszFileSpec
= lpszPath
;
557 BOOL bModified
= FALSE
;
559 TRACE("(%s)\n",debugstr_a(lpszPath
));
563 /* Skip directory or UNC path */
564 if (*lpszPath
== '\\')
565 lpszFileSpec
= ++lpszPath
;
566 if (*lpszPath
== '\\')
567 lpszFileSpec
= ++lpszPath
;
571 if(*lpszPath
== '\\')
572 lpszFileSpec
= lpszPath
; /* Skip dir */
573 else if(*lpszPath
== ':')
575 lpszFileSpec
= ++lpszPath
; /* Skip drive */
576 if (*lpszPath
== '\\')
579 if (!(lpszPath
= CharNextA(lpszPath
)))
585 *lpszFileSpec
= '\0';
592 /*************************************************************************
593 * PathRemoveFileSpecW [SHLWAPI.@]
595 * See PathRemoveFileSpecA.
597 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
599 LPWSTR lpszFileSpec
= lpszPath
;
600 BOOL bModified
= FALSE
;
602 TRACE("(%s)\n",debugstr_w(lpszPath
));
606 /* Skip directory or UNC path */
607 if (*lpszPath
== '\\')
608 lpszFileSpec
= ++lpszPath
;
609 if (*lpszPath
== '\\')
610 lpszFileSpec
= ++lpszPath
;
614 if(*lpszPath
== '\\')
615 lpszFileSpec
= lpszPath
; /* Skip dir */
616 else if(*lpszPath
== ':')
618 lpszFileSpec
= ++lpszPath
; /* Skip drive */
619 if (*lpszPath
== '\\')
627 *lpszFileSpec
= '\0';
634 /*************************************************************************
635 * PathStripPathA [SHLWAPI.@]
637 * Remove the initial path from the beginning of a filename
640 * lpszPath [I/O] Path to remove the initial path from
645 void WINAPI
PathStripPathA(LPSTR lpszPath
)
647 TRACE("(%s)\n", debugstr_a(lpszPath
));
651 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
653 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
657 /*************************************************************************
658 * PathStripPathW [SHLWAPI.@]
660 * See PathStripPathA.
662 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
666 TRACE("(%s)\n", debugstr_w(lpszPath
));
667 lpszFileName
= PathFindFileNameW(lpszPath
);
669 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
672 /*************************************************************************
673 * PathStripToRootA [SHLWAPI.@]
675 * Reduce a path to its root.
678 * lpszPath [I/O] the path to reduce
681 * Success: TRUE if the stripped path is a root path
682 * Failure: FALSE if the path cannot be stripped or is NULL
684 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
686 TRACE("(%s)\n", debugstr_a(lpszPath
));
690 while(!PathIsRootA(lpszPath
))
691 if (!PathRemoveFileSpecA(lpszPath
))
696 /*************************************************************************
697 * PathStripToRootW [SHLWAPI.@]
699 * See PathStripToRootA.
701 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
703 TRACE("(%s)\n", debugstr_w(lpszPath
));
707 while(!PathIsRootW(lpszPath
))
708 if (!PathRemoveFileSpecW(lpszPath
))
713 /*************************************************************************
714 * PathRemoveArgsA [SHLWAPI.@]
716 * Strip space separated arguments from a path.
719 * lpszPath [I/O] Path to remove arguments from
724 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
726 TRACE("(%s)\n",debugstr_a(lpszPath
));
730 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
735 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
736 if(*lpszLastChar
== ' ')
737 *lpszLastChar
= '\0';
742 /*************************************************************************
743 * PathRemoveArgsW [SHLWAPI.@]
745 * See PathRemoveArgsA.
747 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
749 TRACE("(%s)\n",debugstr_w(lpszPath
));
753 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
754 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
759 /*************************************************************************
760 * PathRemoveExtensionA [SHLWAPI.@]
762 * Remove the file extension from a path
765 * lpszPath [I/O] Path to remove the extension from
768 * The NUL terminator must be written only if extension exists
769 * and if the pointed character is not already NUL.
774 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
776 TRACE("(%s)\n", debugstr_a(lpszPath
));
780 lpszPath
= PathFindExtensionA(lpszPath
);
781 if (lpszPath
&& *lpszPath
!= '\0')
786 /*************************************************************************
787 * PathRemoveExtensionW [SHLWAPI.@]
789 * See PathRemoveExtensionA.
791 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
793 TRACE("(%s)\n", debugstr_w(lpszPath
));
797 lpszPath
= PathFindExtensionW(lpszPath
);
798 if (lpszPath
&& *lpszPath
!= '\0')
803 /*************************************************************************
804 * PathRemoveBackslashA [SHLWAPI.@]
806 * Remove a trailing backslash from a path.
809 * lpszPath [I/O] Path to remove backslash from
812 * Success: A pointer to the end of the path
813 * Failure: NULL, if lpszPath is NULL
815 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
819 TRACE("(%s)\n", debugstr_a(lpszPath
));
823 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
824 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
830 /*************************************************************************
831 * PathRemoveBackslashW [SHLWAPI.@]
833 * See PathRemoveBackslashA.
835 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
837 LPWSTR szTemp
= NULL
;
839 TRACE("(%s)\n", debugstr_w(lpszPath
));
843 szTemp
= lpszPath
+ strlenW(lpszPath
);
844 if (szTemp
> lpszPath
) szTemp
--;
845 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
851 /*************************************************************************
852 * PathRemoveBlanksA [SHLWAPI.@]
854 * Remove Spaces from the start and end of a path.
857 * lpszPath [I/O] Path to strip blanks from
862 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
864 TRACE("(%s)\n", debugstr_a(lpszPath
));
866 if(lpszPath
&& *lpszPath
)
868 LPSTR start
= lpszPath
;
870 while (*lpszPath
== ' ')
871 lpszPath
= CharNextA(lpszPath
);
874 *start
++ = *lpszPath
++;
876 if (start
!= lpszPath
)
877 while (start
[-1] == ' ')
883 /*************************************************************************
884 * PathRemoveBlanksW [SHLWAPI.@]
886 * See PathRemoveBlanksA.
888 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
890 TRACE("(%s)\n", debugstr_w(lpszPath
));
892 if(lpszPath
&& *lpszPath
)
894 LPWSTR start
= lpszPath
;
896 while (*lpszPath
== ' ')
900 *start
++ = *lpszPath
++;
902 if (start
!= lpszPath
)
903 while (start
[-1] == ' ')
909 /*************************************************************************
910 * PathQuoteSpacesA [SHLWAPI.@]
912 * Surround a path containing spaces in quotes.
915 * lpszPath [I/O] Path to quote
921 * The path is not changed if it is invalid or has no spaces.
923 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
925 TRACE("(%s)\n", debugstr_a(lpszPath
));
927 if(lpszPath
&& StrChrA(lpszPath
,' '))
929 size_t iLen
= strlen(lpszPath
) + 1;
931 if (iLen
+ 2 < MAX_PATH
)
933 memmove(lpszPath
+ 1, lpszPath
, iLen
);
935 lpszPath
[iLen
] = '"';
936 lpszPath
[iLen
+ 1] = '\0';
941 /*************************************************************************
942 * PathQuoteSpacesW [SHLWAPI.@]
944 * See PathQuoteSpacesA.
946 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
948 TRACE("(%s)\n", debugstr_w(lpszPath
));
950 if(lpszPath
&& StrChrW(lpszPath
,' '))
952 int iLen
= strlenW(lpszPath
) + 1;
954 if (iLen
+ 2 < MAX_PATH
)
956 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
958 lpszPath
[iLen
] = '"';
959 lpszPath
[iLen
+ 1] = '\0';
964 /*************************************************************************
965 * PathUnquoteSpacesA [SHLWAPI.@]
967 * Remove quotes ("") from around a path, if present.
970 * lpszPath [I/O] Path to strip quotes from
976 * If the path contains a single quote only, an empty string will result.
977 * Otherwise quotes are only removed if they appear at the start and end
980 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
982 TRACE("(%s)\n", debugstr_a(lpszPath
));
984 if (lpszPath
&& *lpszPath
== '"')
986 DWORD dwLen
= strlen(lpszPath
) - 1;
988 if (lpszPath
[dwLen
] == '"')
990 lpszPath
[dwLen
] = '\0';
991 for (; *lpszPath
; lpszPath
++)
992 *lpszPath
= lpszPath
[1];
997 /*************************************************************************
998 * PathUnquoteSpacesW [SHLWAPI.@]
1000 * See PathUnquoteSpacesA.
1002 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
1004 TRACE("(%s)\n", debugstr_w(lpszPath
));
1006 if (lpszPath
&& *lpszPath
== '"')
1008 DWORD dwLen
= strlenW(lpszPath
) - 1;
1010 if (lpszPath
[dwLen
] == '"')
1012 lpszPath
[dwLen
] = '\0';
1013 for (; *lpszPath
; lpszPath
++)
1014 *lpszPath
= lpszPath
[1];
1019 /*************************************************************************
1020 * PathParseIconLocationA [SHLWAPI.@]
1022 * Parse the location of an icon from a path.
1025 * lpszPath [I/O] The path to parse the icon location from.
1028 * Success: The number of the icon
1029 * Failure: 0 if the path does not contain an icon location or is NULL
1032 * The path has surrounding quotes and spaces removed regardless
1033 * of whether the call succeeds or not.
1035 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1040 TRACE("(%s)\n", debugstr_a(lpszPath
));
1044 if ((lpszComma
= strchr(lpszPath
, ',')))
1046 *lpszComma
++ = '\0';
1047 iRet
= StrToIntA(lpszComma
);
1049 PathUnquoteSpacesA(lpszPath
);
1050 PathRemoveBlanksA(lpszPath
);
1055 /*************************************************************************
1056 * PathParseIconLocationW [SHLWAPI.@]
1058 * See PathParseIconLocationA.
1060 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1065 TRACE("(%s)\n", debugstr_w(lpszPath
));
1069 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1071 *lpszComma
++ = '\0';
1072 iRet
= StrToIntW(lpszComma
);
1074 PathUnquoteSpacesW(lpszPath
);
1075 PathRemoveBlanksW(lpszPath
);
1080 /*************************************************************************
1083 * Unicode version of PathFileExistsDefExtA.
1085 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1087 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1088 { '.', 'c', 'o', 'm', 0},
1089 { '.', 'e', 'x', 'e', 0},
1090 { '.', 'b', 'a', 't', 0},
1091 { '.', 'l', 'n', 'k', 0},
1092 { '.', 'c', 'm', 'd', 0},
1095 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1097 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1102 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1103 if (!*szExt
|| dwWhich
& 0x40)
1106 int iLen
= lstrlenW(lpszPath
);
1107 if (iLen
> (MAX_PATH
- 5))
1109 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1111 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1112 if (PathFileExistsW(lpszPath
))
1117 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1121 return PathFileExistsW(lpszPath
);
1124 /*************************************************************************
1127 * Determine if a file exists locally and is of an executable type.
1130 * lpszPath [I/O] File to search for
1131 * dwWhich [I] Type of executable to search for
1134 * TRUE If the file was found. lpszPath contains the file name.
1138 * lpszPath is modified in place and must be at least MAX_PATH in length.
1139 * If the function returns FALSE, the path is modified to its original state.
1140 * If the given path contains an extension or dwWhich is 0, executable
1141 * extensions are not checked.
1143 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1144 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1145 * their own developers exclusive use. Monopoly, anyone?
1147 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1151 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1155 WCHAR szPath
[MAX_PATH
];
1156 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1157 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1159 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1164 /*************************************************************************
1165 * SHLWAPI_PathFindInOtherDirs
1167 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1169 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1171 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1172 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1176 WCHAR buff
[MAX_PATH
];
1178 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1180 /* Try system directories */
1181 GetSystemDirectoryW(buff
, MAX_PATH
);
1182 if (!PathAppendW(buff
, lpszFile
))
1184 if (PathFileExistsDefExtW(buff
, dwWhich
))
1186 strcpyW(lpszFile
, buff
);
1189 GetWindowsDirectoryW(buff
, MAX_PATH
);
1190 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1192 if (PathFileExistsDefExtW(buff
, dwWhich
))
1194 strcpyW(lpszFile
, buff
);
1197 GetWindowsDirectoryW(buff
, MAX_PATH
);
1198 if (!PathAppendW(buff
, lpszFile
))
1200 if (PathFileExistsDefExtW(buff
, dwWhich
))
1202 strcpyW(lpszFile
, buff
);
1205 /* Try dirs listed in %PATH% */
1206 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1208 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1211 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1212 lpszCurr
= lpszPATH
;
1215 LPCWSTR lpszEnd
= lpszCurr
;
1216 LPWSTR pBuff
= buff
;
1218 while (*lpszEnd
== ' ')
1220 while (*lpszEnd
&& *lpszEnd
!= ';')
1221 *pBuff
++ = *lpszEnd
++;
1225 lpszCurr
= lpszEnd
+ 1;
1227 lpszCurr
= NULL
; /* Last Path, terminate after this */
1229 if (!PathAppendW(buff
, lpszFile
))
1231 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1234 if (PathFileExistsDefExtW(buff
, dwWhich
))
1236 strcpyW(lpszFile
, buff
);
1237 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1241 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1245 /*************************************************************************
1248 * Search a range of paths for a specific type of executable.
1251 * lpszFile [I/O] File to search for
1252 * lppszOtherDirs [I] Other directories to look in
1253 * dwWhich [I] Type of executable to search for
1256 * Success: TRUE. The path to the executable is stored in lpszFile.
1257 * Failure: FALSE. The path to the executable is unchanged.
1259 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1261 WCHAR szFile
[MAX_PATH
];
1262 WCHAR buff
[MAX_PATH
];
1264 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1266 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1269 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1271 /* Search provided directories first */
1272 if (lppszOtherDirs
&& *lppszOtherDirs
)
1274 WCHAR szOther
[MAX_PATH
];
1275 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1277 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1279 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1280 PathCombineW(buff
, szOther
, szFile
);
1281 if (PathFileExistsDefExtW(buff
, dwWhich
))
1283 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1289 /* Not found, try system and path dirs */
1290 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1292 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1298 /*************************************************************************
1301 * Unicode version of PathFindOnPathExA.
1303 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1305 WCHAR buff
[MAX_PATH
];
1307 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1309 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1312 /* Search provided directories first */
1313 if (lppszOtherDirs
&& *lppszOtherDirs
)
1315 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1316 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1318 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1319 if (PathFileExistsDefExtW(buff
, dwWhich
))
1321 strcpyW(lpszFile
, buff
);
1327 /* Not found, try system and path dirs */
1328 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1331 /*************************************************************************
1332 * PathFindOnPathA [SHLWAPI.@]
1334 * Search a range of paths for an executable.
1337 * lpszFile [I/O] File to search for
1338 * lppszOtherDirs [I] Other directories to look in
1341 * Success: TRUE. The path to the executable is stored in lpszFile.
1342 * Failure: FALSE. The path to the executable is unchanged.
1344 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1346 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1347 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1350 /*************************************************************************
1351 * PathFindOnPathW [SHLWAPI.@]
1353 * See PathFindOnPathA.
1355 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1357 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1358 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1361 /*************************************************************************
1362 * PathCompactPathExA [SHLWAPI.@]
1364 * Compact a path into a given number of characters.
1367 * lpszDest [O] Destination for compacted path
1368 * lpszPath [I] Source path
1369 * cchMax [I] Maximum size of compacted path
1370 * dwFlags [I] Reserved
1373 * Success: TRUE. The compacted path is written to lpszDest.
1374 * Failure: FALSE. lpszPath is undefined.
1377 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1379 * The Win32 version of this function contains a bug: When cchMax == 7,
1380 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1383 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1384 * because Win32 will insert a "\" in lpszDest, even if one is
1385 * not present in the original path.
1387 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1388 UINT cchMax
, DWORD dwFlags
)
1392 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1394 if (lpszPath
&& lpszDest
)
1396 WCHAR szPath
[MAX_PATH
];
1397 WCHAR szDest
[MAX_PATH
];
1399 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1401 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1402 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1407 /*************************************************************************
1408 * PathCompactPathExW [SHLWAPI.@]
1410 * See PathCompactPathExA.
1412 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1413 UINT cchMax
, DWORD dwFlags
)
1415 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1417 DWORD dwLen
, dwFileLen
= 0;
1419 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1426 WARN("Invalid lpszDest would crash under Win32!\n");
1435 dwLen
= strlenW(lpszPath
) + 1;
1439 /* Don't need to compact */
1440 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1444 /* Path must be compacted to fit into lpszDest */
1445 lpszFile
= PathFindFileNameW(lpszPath
);
1446 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1448 if (dwFileLen
== dwLen
)
1450 /* No root in psth */
1453 while (--cchMax
> 0) /* No room left for anything but ellipses */
1458 /* Compact the file name with ellipses at the end */
1460 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1461 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1464 /* We have a root in the path */
1465 lpszFile
--; /* Start compacted filename with the path separator */
1468 if (dwFileLen
+ 3 > cchMax
)
1470 /* Compact the file name */
1473 while (--cchMax
> 0) /* No room left for anything but ellipses */
1478 strcpyW(lpszDest
, szEllipses
);
1481 *lpszDest
++ = *lpszFile
++;
1484 while (--cchMax
> 0) /* No room left for anything but ellipses */
1490 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1491 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1495 /* Only the root needs to be Compacted */
1496 dwLen
= cchMax
- dwFileLen
- 3;
1497 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1498 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1499 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1503 /*************************************************************************
1504 * PathIsRelativeA [SHLWAPI.@]
1506 * Determine if a path is a relative path.
1509 * lpszPath [I] Path to check
1512 * TRUE: The path is relative, or is invalid.
1513 * FALSE: The path is not relative.
1515 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1517 TRACE("(%s)\n",debugstr_a(lpszPath
));
1519 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1521 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1526 /*************************************************************************
1527 * PathIsRelativeW [SHLWAPI.@]
1529 * See PathIsRelativeA.
1531 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1533 TRACE("(%s)\n",debugstr_w(lpszPath
));
1535 if (!lpszPath
|| !*lpszPath
)
1537 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1542 /*************************************************************************
1543 * PathIsRootA [SHLWAPI.@]
1545 * Determine if a path is a root path.
1548 * lpszPath [I] Path to check
1551 * TRUE If lpszPath is valid and a root path,
1554 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1556 TRACE("(%s)\n", debugstr_a(lpszPath
));
1558 if (lpszPath
&& *lpszPath
)
1560 if (*lpszPath
== '\\')
1563 return TRUE
; /* \ */
1564 else if (lpszPath
[1]=='\\')
1566 BOOL bSeenSlash
= FALSE
;
1569 /* Check for UNC root path */
1572 if (*lpszPath
== '\\')
1578 lpszPath
= CharNextA(lpszPath
);
1583 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1584 return TRUE
; /* X:\ */
1589 /*************************************************************************
1590 * PathIsRootW [SHLWAPI.@]
1594 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1596 TRACE("(%s)\n", debugstr_w(lpszPath
));
1598 if (lpszPath
&& *lpszPath
)
1600 if (*lpszPath
== '\\')
1603 return TRUE
; /* \ */
1604 else if (lpszPath
[1]=='\\')
1606 BOOL bSeenSlash
= FALSE
;
1609 /* Check for UNC root path */
1612 if (*lpszPath
== '\\')
1623 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1624 return TRUE
; /* X:\ */
1629 /*************************************************************************
1630 * PathIsDirectoryA [SHLWAPI.@]
1632 * Determine if a path is a valid directory
1635 * lpszPath [I] Path to check.
1638 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1639 * FALSE if lpszPath is invalid or not a directory.
1642 * Although this function is prototyped as returning a BOOL, it returns
1643 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1645 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1650 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1654 TRACE("(%s)\n", debugstr_a(lpszPath
));
1656 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1659 if (PathIsUNCServerShareA(lpszPath
))
1661 FIXME("UNC Server Share not yet supported - FAILING\n");
1665 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1667 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1670 /*************************************************************************
1671 * PathIsDirectoryW [SHLWAPI.@]
1673 * See PathIsDirectoryA.
1675 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1679 TRACE("(%s)\n", debugstr_w(lpszPath
));
1681 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1684 if (PathIsUNCServerShareW(lpszPath
))
1686 FIXME("UNC Server Share not yet supported - FAILING\n");
1690 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1692 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1695 /*************************************************************************
1696 * PathFileExistsA [SHLWAPI.@]
1698 * Determine if a file exists.
1701 * lpszPath [I] Path to check
1704 * TRUE If the file exists and is readable
1707 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1712 TRACE("(%s)\n",debugstr_a(lpszPath
));
1717 /* Prevent a dialog box if path is on a disk that has been ejected. */
1718 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1719 dwAttr
= GetFileAttributesA(lpszPath
);
1720 SetErrorMode(iPrevErrMode
);
1721 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1724 /*************************************************************************
1725 * PathFileExistsW [SHLWAPI.@]
1727 * See PathFileExistsA.
1729 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1734 TRACE("(%s)\n",debugstr_w(lpszPath
));
1739 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1740 dwAttr
= GetFileAttributesW(lpszPath
);
1741 SetErrorMode(iPrevErrMode
);
1742 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1745 /*************************************************************************
1746 * PathFileExistsAndAttributesA [SHLWAPI.445]
1748 * Determine if a file exists.
1751 * lpszPath [I] Path to check
1752 * dwAttr [O] attributes of file
1755 * TRUE If the file exists and is readable
1758 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1763 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1766 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1771 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1772 dwVal
= GetFileAttributesA(lpszPath
);
1773 SetErrorMode(iPrevErrMode
);
1776 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1779 /*************************************************************************
1780 * PathFileExistsAndAttributesW [SHLWAPI.446]
1782 * See PathFileExistsA.
1784 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1789 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1794 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1795 dwVal
= GetFileAttributesW(lpszPath
);
1796 SetErrorMode(iPrevErrMode
);
1799 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1802 /*************************************************************************
1803 * PathMatchSingleMaskA [internal]
1805 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1807 while (*name
&& *mask
&& *mask
!=';')
1813 if (PathMatchSingleMaskA(name
,mask
+1))
1814 return TRUE
; /* try substrings */
1819 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1822 name
= CharNextA(name
);
1823 mask
= CharNextA(mask
);
1828 while (*mask
== '*')
1830 if (!*mask
|| *mask
== ';')
1836 /*************************************************************************
1837 * PathMatchSingleMaskW [internal]
1839 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1841 while (*name
&& *mask
&& *mask
!= ';')
1847 if (PathMatchSingleMaskW(name
,mask
+1))
1848 return TRUE
; /* try substrings */
1853 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1861 while (*mask
== '*')
1863 if (!*mask
|| *mask
== ';')
1869 /*************************************************************************
1870 * PathMatchSpecA [SHLWAPI.@]
1872 * Determine if a path matches one or more search masks.
1875 * lpszPath [I] Path to check
1876 * lpszMask [I] Search mask(s)
1879 * TRUE If lpszPath is valid and is matched
1883 * Multiple search masks may be given if they are separated by ";". The
1884 * pattern "*.*" is treated specially in that it matches all paths (for
1885 * backwards compatibility with DOS).
1887 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1889 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1891 if (!lstrcmpA(lpszMask
, "*.*"))
1892 return TRUE
; /* Matches every path */
1896 while (*lpszMask
== ' ')
1897 lpszMask
++; /* Eat leading spaces */
1899 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1900 return TRUE
; /* Matches the current mask */
1902 while (*lpszMask
&& *lpszMask
!= ';')
1903 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1905 if (*lpszMask
== ';')
1911 /*************************************************************************
1912 * PathMatchSpecW [SHLWAPI.@]
1914 * See PathMatchSpecA.
1916 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1918 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1920 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1922 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1923 return TRUE
; /* Matches every path */
1927 while (*lpszMask
== ' ')
1928 lpszMask
++; /* Eat leading spaces */
1930 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1931 return TRUE
; /* Matches the current path */
1933 while (*lpszMask
&& *lpszMask
!= ';')
1934 lpszMask
++; /* masks separated by ';' */
1936 if (*lpszMask
== ';')
1942 /*************************************************************************
1943 * PathIsSameRootA [SHLWAPI.@]
1945 * Determine if two paths share the same root.
1948 * lpszPath1 [I] Source path
1949 * lpszPath2 [I] Path to compare with
1952 * TRUE If both paths are valid and share the same root.
1953 * FALSE If either path is invalid or the paths do not share the same root.
1955 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1960 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1962 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1965 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1966 if (lpszStart
- lpszPath1
> dwLen
)
1967 return FALSE
; /* Paths not common up to length of the root */
1971 /*************************************************************************
1972 * PathIsSameRootW [SHLWAPI.@]
1974 * See PathIsSameRootA.
1976 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1981 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1983 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1986 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1987 if (lpszStart
- lpszPath1
> dwLen
)
1988 return FALSE
; /* Paths not common up to length of the root */
1992 /*************************************************************************
1993 * PathIsContentTypeA [SHLWAPI.@]
1995 * Determine if a file is of a given registered content type.
1998 * lpszPath [I] File to check
1999 * lpszContentType [I] Content type to check for
2002 * TRUE If lpszPath is a given registered content type,
2006 * This function looks up the registered content type for lpszPath. If
2007 * a content type is registered, it is compared (case insensitively) to
2008 * lpszContentType. Only if this matches does the function succeed.
2010 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2014 char szBuff
[MAX_PATH
];
2016 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2018 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2019 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2020 REG_NONE
, szBuff
, &dwDummy
) &&
2021 !strcasecmp(lpszContentType
, szBuff
))
2028 /*************************************************************************
2029 * PathIsContentTypeW [SHLWAPI.@]
2031 * See PathIsContentTypeA.
2033 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2035 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2038 WCHAR szBuff
[MAX_PATH
];
2040 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2042 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2043 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2044 REG_NONE
, szBuff
, &dwDummy
) &&
2045 !strcmpiW(lpszContentType
, szBuff
))
2052 /*************************************************************************
2053 * PathIsFileSpecA [SHLWAPI.@]
2055 * Determine if a path is a file specification.
2058 * lpszPath [I] Path to check
2061 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2064 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2066 TRACE("(%s)\n", debugstr_a(lpszPath
));
2073 if (*lpszPath
== '\\' || *lpszPath
== ':')
2075 lpszPath
= CharNextA(lpszPath
);
2080 /*************************************************************************
2081 * PathIsFileSpecW [SHLWAPI.@]
2083 * See PathIsFileSpecA.
2085 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2087 TRACE("(%s)\n", debugstr_w(lpszPath
));
2094 if (*lpszPath
== '\\' || *lpszPath
== ':')
2101 /*************************************************************************
2102 * PathIsPrefixA [SHLWAPI.@]
2104 * Determine if a path is a prefix of another.
2107 * lpszPrefix [I] Prefix
2108 * lpszPath [I] Path to check
2111 * TRUE If lpszPath has lpszPrefix as its prefix,
2112 * FALSE If either path is NULL or lpszPrefix is not a prefix
2114 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2116 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2118 if (lpszPrefix
&& lpszPath
&&
2119 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2124 /*************************************************************************
2125 * PathIsPrefixW [SHLWAPI.@]
2127 * See PathIsPrefixA.
2129 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2131 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2133 if (lpszPrefix
&& lpszPath
&&
2134 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2139 /*************************************************************************
2140 * PathIsSystemFolderA [SHLWAPI.@]
2142 * Determine if a path or file attributes are a system folder.
2145 * lpszPath [I] Path to check.
2146 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2149 * TRUE If lpszPath or dwAttrib are a system folder.
2150 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2152 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2154 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2156 if (lpszPath
&& *lpszPath
)
2157 dwAttrib
= GetFileAttributesA(lpszPath
);
2159 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2160 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2165 /*************************************************************************
2166 * PathIsSystemFolderW [SHLWAPI.@]
2168 * See PathIsSystemFolderA.
2170 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2172 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2174 if (lpszPath
&& *lpszPath
)
2175 dwAttrib
= GetFileAttributesW(lpszPath
);
2177 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2178 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2183 /*************************************************************************
2184 * PathIsUNCA [SHLWAPI.@]
2186 * Determine if a path is in UNC format.
2189 * lpszPath [I] Path to check
2192 * TRUE: The path is UNC.
2193 * FALSE: The path is not UNC or is NULL.
2195 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2197 TRACE("(%s)\n",debugstr_a(lpszPath
));
2199 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2204 /*************************************************************************
2205 * PathIsUNCW [SHLWAPI.@]
2209 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2211 TRACE("(%s)\n",debugstr_w(lpszPath
));
2213 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\') && (lpszPath
[2]!='?'))
2218 /*************************************************************************
2219 * PathIsUNCServerA [SHLWAPI.@]
2221 * Determine if a path is a UNC server name ("\\SHARENAME").
2224 * lpszPath [I] Path to check.
2227 * TRUE If lpszPath is a valid UNC server name.
2231 * This routine is bug compatible with Win32: Server names with a
2232 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2233 * Fixing this bug may break other shlwapi functions!
2235 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2237 TRACE("(%s)\n", debugstr_a(lpszPath
));
2239 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2243 if (*lpszPath
== '\\')
2245 lpszPath
= CharNextA(lpszPath
);
2252 /*************************************************************************
2253 * PathIsUNCServerW [SHLWAPI.@]
2255 * See PathIsUNCServerA.
2257 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2259 TRACE("(%s)\n", debugstr_w(lpszPath
));
2261 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2263 return !strchrW( lpszPath
+ 2, '\\' );
2268 /*************************************************************************
2269 * PathIsUNCServerShareA [SHLWAPI.@]
2271 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2274 * lpszPath [I] Path to check.
2277 * TRUE If lpszPath is a valid UNC server share.
2281 * This routine is bug compatible with Win32: Server shares with a
2282 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2283 * Fixing this bug may break other shlwapi functions!
2285 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2287 TRACE("(%s)\n", debugstr_a(lpszPath
));
2289 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2291 BOOL bSeenSlash
= FALSE
;
2294 if (*lpszPath
== '\\')
2300 lpszPath
= CharNextA(lpszPath
);
2307 /*************************************************************************
2308 * PathIsUNCServerShareW [SHLWAPI.@]
2310 * See PathIsUNCServerShareA.
2312 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2314 TRACE("(%s)\n", debugstr_w(lpszPath
));
2316 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2318 BOOL bSeenSlash
= FALSE
;
2321 if (*lpszPath
== '\\')
2334 /*************************************************************************
2335 * PathCanonicalizeA [SHLWAPI.@]
2337 * Convert a path to its canonical form.
2340 * lpszBuf [O] Output path
2341 * lpszPath [I] Path to canonicalize
2344 * Success: TRUE. lpszBuf contains the output path,
2345 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2347 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2351 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2356 if (!lpszBuf
|| !lpszPath
)
2357 SetLastError(ERROR_INVALID_PARAMETER
);
2360 WCHAR szPath
[MAX_PATH
];
2361 WCHAR szBuff
[MAX_PATH
];
2362 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2365 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2368 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2369 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2375 /*************************************************************************
2376 * PathCanonicalizeW [SHLWAPI.@]
2378 * See PathCanonicalizeA.
2380 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2382 LPWSTR lpszDst
= lpszBuf
;
2383 LPCWSTR lpszSrc
= lpszPath
;
2385 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2390 if (!lpszBuf
|| !lpszPath
)
2392 SetLastError(ERROR_INVALID_PARAMETER
);
2403 /* Copy path root */
2404 if (*lpszSrc
== '\\')
2406 *lpszDst
++ = *lpszSrc
++;
2408 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2411 *lpszDst
++ = *lpszSrc
++;
2412 *lpszDst
++ = *lpszSrc
++;
2413 if (*lpszSrc
== '\\')
2414 *lpszDst
++ = *lpszSrc
++;
2417 /* Canonicalize the rest of the path */
2420 if (*lpszSrc
== '.')
2422 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2424 lpszSrc
+= 2; /* Skip .\ */
2426 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2428 /* \.. backs up a directory, over the root if it has no \ following X:.
2429 * .. is ignored if it would remove a UNC server name or initial \\
2431 if (lpszDst
!= lpszBuf
)
2433 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2434 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2435 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2437 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2440 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2442 if (*lpszDst
== '\\')
2443 lpszDst
++; /* Reset to last '\' */
2445 lpszDst
= lpszBuf
; /* Start path again from new root */
2447 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2450 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2452 if (lpszDst
== lpszBuf
)
2458 lpszSrc
+= 2; /* Skip .. in src path */
2461 *lpszDst
++ = *lpszSrc
++;
2464 *lpszDst
++ = *lpszSrc
++;
2466 /* Append \ to naked drive specs */
2467 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2473 /*************************************************************************
2474 * PathFindNextComponentA [SHLWAPI.@]
2476 * Find the next component in a path.
2479 * lpszPath [I] Path to find next component in
2482 * Success: A pointer to the next component, or the end of the string.
2483 * Failure: NULL, If lpszPath is invalid
2486 * A 'component' is either a backslash character (\) or UNC marker (\\).
2487 * Because of this, relative paths (e.g "c:foo") are regarded as having
2488 * only one component.
2490 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2494 TRACE("(%s)\n", debugstr_a(lpszPath
));
2496 if(!lpszPath
|| !*lpszPath
)
2499 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2501 if (lpszSlash
[1] == '\\')
2503 return lpszSlash
+ 1;
2505 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2508 /*************************************************************************
2509 * PathFindNextComponentW [SHLWAPI.@]
2511 * See PathFindNextComponentA.
2513 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2517 TRACE("(%s)\n", debugstr_w(lpszPath
));
2519 if(!lpszPath
|| !*lpszPath
)
2522 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2524 if (lpszSlash
[1] == '\\')
2526 return lpszSlash
+ 1;
2528 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2531 /*************************************************************************
2532 * PathAddExtensionA [SHLWAPI.@]
2534 * Add a file extension to a path
2537 * lpszPath [I/O] Path to add extension to
2538 * lpszExtension [I] Extension to add to lpszPath
2541 * TRUE If the path was modified,
2542 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2543 * extension already, or the new path length is too big.
2546 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2547 * does not do this, so the behaviour was removed.
2549 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2553 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2555 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2558 dwLen
= strlen(lpszPath
);
2560 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2563 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2567 /*************************************************************************
2568 * PathAddExtensionW [SHLWAPI.@]
2570 * See PathAddExtensionA.
2572 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2576 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2578 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2581 dwLen
= strlenW(lpszPath
);
2583 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2586 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2590 /*************************************************************************
2591 * PathMakePrettyA [SHLWAPI.@]
2593 * Convert an uppercase DOS filename into lowercase.
2596 * lpszPath [I/O] Path to convert.
2599 * TRUE If the path was an uppercase DOS path and was converted,
2602 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2604 LPSTR pszIter
= lpszPath
;
2606 TRACE("(%s)\n", debugstr_a(lpszPath
));
2615 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2616 return FALSE
; /* Not DOS path */
2619 pszIter
= lpszPath
+ 1;
2622 *pszIter
= tolower(*pszIter
);
2629 /*************************************************************************
2630 * PathMakePrettyW [SHLWAPI.@]
2632 * See PathMakePrettyA.
2634 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2636 LPWSTR pszIter
= lpszPath
;
2638 TRACE("(%s)\n", debugstr_w(lpszPath
));
2647 if (islowerW(*pszIter
))
2648 return FALSE
; /* Not DOS path */
2651 pszIter
= lpszPath
+ 1;
2654 *pszIter
= tolowerW(*pszIter
);
2661 /*************************************************************************
2662 * PathCommonPrefixA [SHLWAPI.@]
2664 * Determine the length of the common prefix between two paths.
2667 * lpszFile1 [I] First path for comparison
2668 * lpszFile2 [I] Second path for comparison
2669 * achPath [O] Destination for common prefix string
2672 * The length of the common prefix. This is 0 if there is no common
2673 * prefix between the paths or if any parameters are invalid. If the prefix
2674 * is non-zero and achPath is not NULL, achPath is filled with the common
2675 * part of the prefix and NUL terminated.
2678 * A common prefix of 2 is always returned as 3. It is thus possible for
2679 * the length returned to be invalid (i.e. Longer than one or both of the
2680 * strings given as parameters). This Win32 behaviour has been implemented
2681 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2682 * To work around this when using this function, always check that the byte
2683 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2685 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2688 LPCSTR lpszIter1
= lpszFile1
;
2689 LPCSTR lpszIter2
= lpszFile2
;
2691 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2696 if (!lpszFile1
|| !lpszFile2
)
2699 /* Handle roots first */
2700 if (PathIsUNCA(lpszFile1
))
2702 if (!PathIsUNCA(lpszFile2
))
2707 else if (PathIsUNCA(lpszFile2
))
2708 return 0; /* Know already lpszFile1 is not UNC */
2713 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2714 (!*lpszIter2
|| *lpszIter2
== '\\'))
2715 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2717 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2718 break; /* Strings differ at this point */
2725 iLen
++; /* Feature/Bug compatible with Win32 */
2727 if (iLen
&& achPath
)
2729 memcpy(achPath
,lpszFile1
,iLen
);
2730 achPath
[iLen
] = '\0';
2735 /*************************************************************************
2736 * PathCommonPrefixW [SHLWAPI.@]
2738 * See PathCommonPrefixA.
2740 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2743 LPCWSTR lpszIter1
= lpszFile1
;
2744 LPCWSTR lpszIter2
= lpszFile2
;
2746 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2751 if (!lpszFile1
|| !lpszFile2
)
2754 /* Handle roots first */
2755 if (PathIsUNCW(lpszFile1
))
2757 if (!PathIsUNCW(lpszFile2
))
2762 else if (PathIsUNCW(lpszFile2
))
2763 return 0; /* Know already lpszFile1 is not UNC */
2768 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2769 (!*lpszIter2
|| *lpszIter2
== '\\'))
2770 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2772 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2773 break; /* Strings differ at this point */
2780 iLen
++; /* Feature/Bug compatible with Win32 */
2782 if (iLen
&& achPath
)
2784 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2785 achPath
[iLen
] = '\0';
2790 /*************************************************************************
2791 * PathCompactPathA [SHLWAPI.@]
2793 * Make a path fit into a given width when printed to a DC.
2796 * hDc [I] Destination DC
2797 * lpszPath [I/O] Path to be printed to hDc
2798 * dx [I] Desired width
2801 * TRUE If the path was modified/went well.
2804 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2808 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2812 WCHAR szPath
[MAX_PATH
];
2813 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2814 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2815 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2820 /*************************************************************************
2821 * PathCompactPathW [SHLWAPI.@]
2823 * See PathCompactPathA.
2825 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2827 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2830 WCHAR buff
[MAX_PATH
];
2834 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2840 hdc
= hDC
= GetDC(0);
2842 /* Get the length of the whole path */
2843 dwLen
= strlenW(lpszPath
);
2844 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2846 if ((UINT
)size
.cx
> dx
)
2848 /* Path too big, must reduce it */
2850 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2852 sFile
= PathFindFileNameW(lpszPath
);
2853 if (sFile
!= lpszPath
) sFile
--;
2855 /* Get the size of ellipses */
2856 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2857 dwEllipsesLen
= size
.cx
;
2858 /* Get the size of the file name */
2859 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2860 dwPathLen
= size
.cx
;
2862 if (sFile
!= lpszPath
)
2864 LPWSTR sPath
= sFile
;
2865 BOOL bEllipses
= FALSE
;
2867 /* The path includes a file name. Include as much of the path prior to
2868 * the file name as possible, allowing for the ellipses, e.g:
2869 * c:\some very long path\filename ==> c:\some v...\filename
2871 lstrcpynW(buff
, sFile
, MAX_PATH
);
2875 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2877 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2878 dwTotalLen
+= size
.cx
;
2879 if (dwTotalLen
<= dx
)
2887 } while (sPath
> lpszPath
);
2889 if (sPath
> lpszPath
)
2893 strcpyW(sPath
, szEllipses
);
2894 strcpyW(sPath
+3, buff
);
2899 strcpyW(lpszPath
, szEllipses
);
2900 strcpyW(lpszPath
+3, buff
);
2905 /* Trim the path by adding ellipses to the end, e.g:
2906 * A very long file name.txt ==> A very...
2908 dwLen
= strlenW(lpszPath
);
2910 if (dwLen
> MAX_PATH
- 3)
2911 dwLen
= MAX_PATH
- 3;
2912 lstrcpynW(buff
, sFile
, dwLen
);
2916 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2917 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2921 DWORD dwWritten
= 0;
2923 dwEllipsesLen
/= 3; /* Size of a single '.' */
2925 /* Write as much of the Ellipses string as possible */
2926 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2929 dwWritten
+= dwEllipsesLen
;
2937 strcpyW(buff
+ dwLen
, szEllipses
);
2938 strcpyW(lpszPath
, buff
);
2949 /*************************************************************************
2950 * PathGetCharTypeA [SHLWAPI.@]
2952 * Categorise a character from a file path.
2955 * ch [I] Character to get the type of
2958 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2960 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2962 return PathGetCharTypeW(ch
);
2965 /*************************************************************************
2966 * PathGetCharTypeW [SHLWAPI.@]
2968 * See PathGetCharTypeA.
2970 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2974 TRACE("(%d)\n", ch
);
2976 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2977 ch
== '"' || ch
== '|' || ch
== '/')
2978 flags
= GCT_INVALID
; /* Invalid */
2979 else if (ch
== '*' || ch
=='?')
2980 flags
= GCT_WILD
; /* Wildchars */
2981 else if ((ch
== '\\') || (ch
== ':'))
2982 return GCT_SEPARATOR
; /* Path separators */
2987 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2988 ch
== '.' || ch
== '@' || ch
== '^' ||
2989 ch
== '\'' || ch
== 130 || ch
== '`')
2990 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2993 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2994 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2999 /*************************************************************************
3000 * SHLWAPI_UseSystemForSystemFolders
3002 * Internal helper for PathMakeSystemFolderW.
3004 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3006 static BOOL bCheckedReg
= FALSE
;
3007 static BOOL bUseSystemForSystemFolders
= FALSE
;
3013 /* Key tells Win what file attributes to use on system folders */
3014 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3015 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3016 "UseSystemForSystemFolders", 0, 0, 0))
3017 bUseSystemForSystemFolders
= TRUE
;
3019 return bUseSystemForSystemFolders
;
3022 /*************************************************************************
3023 * PathMakeSystemFolderA [SHLWAPI.@]
3025 * Set system folder attribute for a path.
3028 * lpszPath [I] The path to turn into a system folder
3031 * TRUE If the path was changed to/already was a system folder
3032 * FALSE If the path is invalid or SetFileAttributesA() fails
3034 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3038 TRACE("(%s)\n", debugstr_a(lpszPath
));
3040 if (lpszPath
&& *lpszPath
)
3042 WCHAR szPath
[MAX_PATH
];
3043 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3044 bRet
= PathMakeSystemFolderW(szPath
);
3049 /*************************************************************************
3050 * PathMakeSystemFolderW [SHLWAPI.@]
3052 * See PathMakeSystemFolderA.
3054 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3056 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3057 WCHAR buff
[MAX_PATH
];
3059 TRACE("(%s)\n", debugstr_w(lpszPath
));
3061 if (!lpszPath
|| !*lpszPath
)
3064 /* If the directory is already a system directory, don't do anything */
3065 GetSystemDirectoryW(buff
, MAX_PATH
);
3066 if (!strcmpW(buff
, lpszPath
))
3069 GetWindowsDirectoryW(buff
, MAX_PATH
);
3070 if (!strcmpW(buff
, lpszPath
))
3073 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3074 if (SHLWAPI_UseSystemForSystemFolders())
3075 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3077 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3080 /* Change file attributes to system attributes */
3081 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3082 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3085 /*************************************************************************
3086 * PathRenameExtensionA [SHLWAPI.@]
3088 * Swap the file extension in a path with another extension.
3091 * lpszPath [I/O] Path to swap the extension in
3092 * lpszExt [I] The new extension
3095 * TRUE if lpszPath was modified,
3096 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3098 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3100 LPSTR lpszExtension
;
3102 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3104 lpszExtension
= PathFindExtensionA(lpszPath
);
3106 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3109 strcpy(lpszExtension
, lpszExt
);
3113 /*************************************************************************
3114 * PathRenameExtensionW [SHLWAPI.@]
3116 * See PathRenameExtensionA.
3118 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3120 LPWSTR lpszExtension
;
3122 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3124 lpszExtension
= PathFindExtensionW(lpszPath
);
3126 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3129 strcpyW(lpszExtension
, lpszExt
);
3133 /*************************************************************************
3134 * PathSearchAndQualifyA [SHLWAPI.@]
3136 * Determine if a given path is correct and fully qualified.
3139 * lpszPath [I] Path to check
3140 * lpszBuf [O] Output for correct path
3141 * cchBuf [I] Size of lpszBuf
3146 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3148 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3150 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3152 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3155 /*************************************************************************
3156 * PathSearchAndQualifyW [SHLWAPI.@]
3158 * See PathSearchAndQualifyA.
3160 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3162 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3164 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3166 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3169 /*************************************************************************
3170 * PathSkipRootA [SHLWAPI.@]
3172 * Return the portion of a path following the drive letter or mount point.
3175 * lpszPath [I] The path to skip on
3178 * Success: A pointer to the next character after the root.
3179 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3181 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3183 TRACE("(%s)\n", debugstr_a(lpszPath
));
3185 if (!lpszPath
|| !*lpszPath
)
3188 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3190 /* Network share: skip share server and mount point */
3192 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3193 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3195 return (LPSTR
)lpszPath
;
3198 if (IsDBCSLeadByte(*lpszPath
))
3202 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3203 return (LPSTR
)lpszPath
+ 3;
3207 /*************************************************************************
3208 * PathSkipRootW [SHLWAPI.@]
3210 * See PathSkipRootA.
3212 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3214 TRACE("(%s)\n", debugstr_w(lpszPath
));
3216 if (!lpszPath
|| !*lpszPath
)
3219 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3221 /* Network share: skip share server and mount point */
3223 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3224 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3226 return (LPWSTR
)lpszPath
;
3230 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3231 return (LPWSTR
)lpszPath
+ 3;
3235 /*************************************************************************
3236 * PathCreateFromUrlA [SHLWAPI.@]
3238 * See PathCreateFromUrlW
3240 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3241 LPDWORD pcchPath
, DWORD dwReserved
)
3243 WCHAR bufW
[MAX_PATH
];
3244 WCHAR
*pathW
= bufW
;
3245 UNICODE_STRING urlW
;
3247 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3249 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3250 return E_INVALIDARG
;
3252 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3253 return E_INVALIDARG
;
3254 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3255 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3256 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3259 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3260 if(*pcchPath
> lenA
) {
3261 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3265 *pcchPath
= lenA
+ 1;
3269 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3270 RtlFreeUnicodeString(&urlW
);
3274 /*************************************************************************
3275 * PathCreateFromUrlW [SHLWAPI.@]
3277 * Create a path from a URL
3280 * lpszUrl [I] URL to convert into a path
3281 * lpszPath [O] Output buffer for the resulting Path
3282 * pcchPath [I] Length of lpszPath
3283 * dwFlags [I] Flags controlling the conversion
3286 * Success: S_OK. lpszPath contains the URL in path format,
3287 * Failure: An HRESULT error code such as E_INVALIDARG.
3289 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3290 LPDWORD pcchPath
, DWORD dwReserved
)
3292 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3293 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3294 DWORD nslashes
, unescape
, len
;
3299 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3301 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3302 return E_INVALIDARG
;
3304 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3305 file_colon
, 5) != CSTR_EQUAL
)
3306 return E_INVALIDARG
;
3312 while (*src
== '/' || *src
== '\\') {
3317 /* We need a temporary buffer so we can compute what size to ask for.
3318 * We know that the final string won't be longer than the current pszUrl
3319 * plus at most two backslashes. All the other transformations make it
3322 len
= 2 + lstrlenW(pszUrl
) + 1;
3323 if (*pcchPath
< len
)
3324 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3334 /* 'file:' + escaped DOS path */
3337 /* 'file:/' + escaped DOS path */
3340 /* 'file:///' (implied localhost) + escaped DOS path */
3341 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3345 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, src
, 9,
3346 localhost
, 9) == CSTR_EQUAL
&&
3347 (src
[9] == '/' || src
[9] == '\\'))
3349 /* 'file://localhost/' + escaped DOS path */
3352 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3354 /* 'file://' + unescaped DOS path */
3359 /* 'file://hostname:port/path' (where path is escaped)
3360 * or 'file:' + escaped UNC path (\\server\share\path)
3361 * The second form is clearly specific to Windows and it might
3362 * even be doing a network lookup to try to figure it out.
3364 while (*src
&& *src
!= '/' && *src
!= '\\')
3367 StrCpyNW(dst
, pszUrl
, len
+ 1);
3369 if (isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3371 /* 'Forget' to add a trailing '/', just like Windows */
3377 /* 'file://' + unescaped UNC path (\\server\share\path) */
3379 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3383 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3387 /* Copy the remainder of the path */
3388 len
+= lstrlenW(src
);
3391 /* First do the Windows-specific path conversions */
3392 for (dst
= tpath
; *dst
; dst
++)
3393 if (*dst
== '/') *dst
= '\\';
3394 if (isalphaW(*tpath
) && tpath
[1] == '|')
3395 tpath
[1] = ':'; /* c| -> c: */
3397 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3400 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3403 /* When working in-place UrlUnescapeW() does not set len */
3404 len
= lstrlenW(tpath
);
3408 if (*pcchPath
< len
+ 1)
3411 *pcchPath
= len
+ 1;
3416 if (tpath
!= pszPath
)
3417 StrCpyW(pszPath
, tpath
);
3419 if (tpath
!= pszPath
)
3420 HeapFree(GetProcessHeap(), 0, tpath
);
3422 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3426 /*************************************************************************
3427 * PathCreateFromUrlAlloc [SHLWAPI.@]
3429 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3432 WCHAR pathW
[MAX_PATH
];
3437 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3440 /* Yes, this is supposed to crash if pszPath is NULL */
3441 *pszPath
= StrDupW(pathW
);
3446 /*************************************************************************
3447 * PathRelativePathToA [SHLWAPI.@]
3449 * Create a relative path from one path to another.
3452 * lpszPath [O] Destination for relative path
3453 * lpszFrom [I] Source path
3454 * dwAttrFrom [I] File attribute of source path
3455 * lpszTo [I] Destination path
3456 * dwAttrTo [I] File attributes of destination path
3459 * TRUE If a relative path can be formed. lpszPath contains the new path
3460 * FALSE If the paths are not relative or any parameters are invalid
3463 * lpszTo should be at least MAX_PATH in length.
3465 * Calling this function with relative paths for lpszFrom or lpszTo may
3466 * give erroneous results.
3468 * The Win32 version of this function contains a bug where the lpszTo string
3469 * may be referenced 1 byte beyond the end of the string. As a result random
3470 * garbage may be written to the output path, depending on what lies beyond
3471 * the last byte of the string. This bug occurs because of the behaviour of
3472 * PathCommonPrefix() (see notes for that function), and no workaround seems
3473 * possible with Win32.
3475 * This bug has been fixed here, so for example the relative path from "\\"
3476 * to "\\" is correctly determined as "." in this implementation.
3478 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3479 LPCSTR lpszTo
, DWORD dwAttrTo
)
3483 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3484 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3486 if(lpszPath
&& lpszFrom
&& lpszTo
)
3488 WCHAR szPath
[MAX_PATH
];
3489 WCHAR szFrom
[MAX_PATH
];
3490 WCHAR szTo
[MAX_PATH
];
3491 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3492 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3493 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3494 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3499 /*************************************************************************
3500 * PathRelativePathToW [SHLWAPI.@]
3502 * See PathRelativePathToA.
3504 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3505 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3507 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3508 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3509 WCHAR szFrom
[MAX_PATH
];
3510 WCHAR szTo
[MAX_PATH
];
3513 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3514 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3516 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3520 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3521 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3523 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3524 PathRemoveFileSpecW(szFrom
);
3525 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3526 PathRemoveFileSpecW(szTo
);
3528 /* Paths can only be relative if they have a common root */
3529 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3532 /* Strip off lpszFrom components to the root, by adding "..\" */
3533 lpszFrom
= szFrom
+ dwLen
;
3539 if (*lpszFrom
== '\\')
3544 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3545 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3548 /* From the root add the components of lpszTo */
3550 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3553 if (*lpszTo
&& lpszTo
[-1])
3555 if (*lpszTo
!= '\\')
3557 dwLen
= strlenW(lpszPath
);
3558 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3563 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3568 /*************************************************************************
3569 * PathUnmakeSystemFolderA [SHLWAPI.@]
3571 * Remove the system folder attributes from a path.
3574 * lpszPath [I] The path to remove attributes from
3578 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3579 * SetFileAttributesA() fails.
3581 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3585 TRACE("(%s)\n", debugstr_a(lpszPath
));
3587 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3588 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3591 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3592 return SetFileAttributesA(lpszPath
, dwAttr
);
3595 /*************************************************************************
3596 * PathUnmakeSystemFolderW [SHLWAPI.@]
3598 * See PathUnmakeSystemFolderA.
3600 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3604 TRACE("(%s)\n", debugstr_w(lpszPath
));
3606 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3607 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3610 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3611 return SetFileAttributesW(lpszPath
, dwAttr
);
3615 /*************************************************************************
3616 * PathSetDlgItemPathA [SHLWAPI.@]
3618 * Set the text of a dialog item to a path, shrinking the path to fit
3619 * if it is too big for the item.
3622 * hDlg [I] Dialog handle
3623 * id [I] ID of item in the dialog
3624 * lpszPath [I] Path to set as the items text
3630 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3631 * window text is erased).
3633 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3635 WCHAR szPath
[MAX_PATH
];
3637 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3640 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3643 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3646 /*************************************************************************
3647 * PathSetDlgItemPathW [SHLWAPI.@]
3649 * See PathSetDlgItemPathA.
3651 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3653 WCHAR path
[MAX_PATH
+ 1];
3659 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3661 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3665 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3669 GetClientRect(hwItem
, &rect
);
3671 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3675 PathCompactPathW(hdc
, path
, rect
.right
);
3676 SelectObject(hdc
, hPrevObj
);
3679 ReleaseDC(hDlg
, hdc
);
3680 SetWindowTextW(hwItem
, path
);
3683 /*************************************************************************
3684 * PathIsNetworkPathA [SHLWAPI.@]
3686 * Determine if the given path is a network path.
3689 * lpszPath [I] Path to check
3692 * TRUE If lpszPath is a UNC share or mapped network drive, or
3693 * FALSE If lpszPath is a local drive or cannot be determined
3695 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3699 TRACE("(%s)\n",debugstr_a(lpszPath
));
3703 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3705 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3706 if (dwDriveNum
== -1)
3708 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3709 return pIsNetDrive(dwDriveNum
);
3712 /*************************************************************************
3713 * PathIsNetworkPathW [SHLWAPI.@]
3715 * See PathIsNetworkPathA.
3717 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3721 TRACE("(%s)\n", debugstr_w(lpszPath
));
3725 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3727 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3728 if (dwDriveNum
== -1)
3730 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3731 return pIsNetDrive(dwDriveNum
);
3734 /*************************************************************************
3735 * PathIsLFNFileSpecA [SHLWAPI.@]
3737 * Determine if the given path is a long file name
3740 * lpszPath [I] Path to check
3743 * TRUE If path is a long file name,
3744 * FALSE If path is a valid DOS short file name
3746 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3748 DWORD dwNameLen
= 0, dwExtLen
= 0;
3750 TRACE("(%s)\n",debugstr_a(lpszPath
));
3757 if (*lpszPath
== ' ')
3758 return TRUE
; /* DOS names cannot have spaces */
3759 if (*lpszPath
== '.')
3762 return TRUE
; /* DOS names have only one dot */
3769 return TRUE
; /* DOS extensions are <= 3 chars*/
3775 return TRUE
; /* DOS names are <= 8 chars */
3777 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3779 return FALSE
; /* Valid DOS path */
3782 /*************************************************************************
3783 * PathIsLFNFileSpecW [SHLWAPI.@]
3785 * See PathIsLFNFileSpecA.
3787 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3789 DWORD dwNameLen
= 0, dwExtLen
= 0;
3791 TRACE("(%s)\n",debugstr_w(lpszPath
));
3798 if (*lpszPath
== ' ')
3799 return TRUE
; /* DOS names cannot have spaces */
3800 if (*lpszPath
== '.')
3803 return TRUE
; /* DOS names have only one dot */
3810 return TRUE
; /* DOS extensions are <= 3 chars*/
3816 return TRUE
; /* DOS names are <= 8 chars */
3820 return FALSE
; /* Valid DOS path */
3823 /*************************************************************************
3824 * PathIsDirectoryEmptyA [SHLWAPI.@]
3826 * Determine if a given directory is empty.
3829 * lpszPath [I] Directory to check
3832 * TRUE If the directory exists and contains no files,
3835 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3839 TRACE("(%s)\n",debugstr_a(lpszPath
));
3843 WCHAR szPath
[MAX_PATH
];
3844 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3845 bRet
= PathIsDirectoryEmptyW(szPath
);
3850 /*************************************************************************
3851 * PathIsDirectoryEmptyW [SHLWAPI.@]
3853 * See PathIsDirectoryEmptyA.
3855 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3857 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3858 WCHAR szSearch
[MAX_PATH
];
3861 BOOL retVal
= FALSE
;
3862 WIN32_FIND_DATAW find_data
;
3864 TRACE("(%s)\n",debugstr_w(lpszPath
));
3866 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3869 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3870 PathAddBackslashW(szSearch
);
3871 dwLen
= strlenW(szSearch
);
3872 if (dwLen
> MAX_PATH
- 4)
3875 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3876 hfind
= FindFirstFileW(szSearch
, &find_data
);
3878 if (hfind
!= INVALID_HANDLE_VALUE
&&
3879 find_data
.cFileName
[0] == '.' &&
3880 find_data
.cFileName
[1] == '.')
3882 /* The only directory entry should be the parent */
3883 if (!FindNextFileW(hfind
, &find_data
))
3891 /*************************************************************************
3892 * PathFindSuffixArrayA [SHLWAPI.@]
3894 * Find a suffix string in an array of suffix strings
3897 * lpszSuffix [I] Suffix string to search for
3898 * lppszArray [I] Array of suffix strings to search
3899 * dwCount [I] Number of elements in lppszArray
3902 * Success: The index of the position of lpszSuffix in lppszArray
3903 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3906 * The search is case sensitive.
3907 * The match is made against the end of the suffix string, so for example:
3908 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3910 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3915 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3917 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3919 dwLen
= strlen(lpszSuffix
);
3921 while (dwRet
< dwCount
)
3923 size_t dwCompareLen
= strlen(*lppszArray
);
3924 if (dwCompareLen
< dwLen
)
3926 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3927 return *lppszArray
; /* Found */
3936 /*************************************************************************
3937 * PathFindSuffixArrayW [SHLWAPI.@]
3939 * See PathFindSuffixArrayA.
3941 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3946 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3948 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3950 dwLen
= strlenW(lpszSuffix
);
3952 while (dwRet
< dwCount
)
3954 size_t dwCompareLen
= strlenW(*lppszArray
);
3955 if (dwCompareLen
< dwLen
)
3957 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3958 return *lppszArray
; /* Found */
3967 /*************************************************************************
3968 * PathUndecorateA [SHLWAPI.@]
3970 * Undecorate a file path
3973 * lpszPath [I/O] Path to remove any decoration from
3979 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3981 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3983 TRACE("(%s)\n",debugstr_a(lpszPath
));
3987 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3988 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3990 LPSTR lpszSkip
= lpszExt
- 2;
3991 if (*lpszSkip
== '[')
3992 lpszSkip
++; /* [] (no number) */
3994 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3996 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3998 /* remove the [n] */
4001 *lpszSkip
++ = *lpszExt
++;
4008 /*************************************************************************
4009 * PathUndecorateW [SHLWAPI.@]
4011 * See PathUndecorateA.
4013 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4015 TRACE("(%s)\n",debugstr_w(lpszPath
));
4019 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4020 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4022 LPWSTR lpszSkip
= lpszExt
- 2;
4023 if (*lpszSkip
== '[')
4024 lpszSkip
++; /* [] (no number) */
4026 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4028 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4030 /* remove the [n] */
4033 *lpszSkip
++ = *lpszExt
++;
4040 /*************************************************************************
4041 * PathUnExpandEnvStringsA [SHLWAPI.@]
4043 * Substitute folder names in a path with their corresponding environment
4047 * pszPath [I] Buffer containing the path to unexpand.
4048 * pszBuf [O] Buffer to receive the unexpanded path.
4049 * cchBuf [I] Size of pszBuf in characters.
4055 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR pszPath
, LPSTR pszBuf
, UINT cchBuf
)
4057 FIXME("(%s,%s,0x%08x)\n", debugstr_a(pszPath
), debugstr_a(pszBuf
), cchBuf
);
4061 /*************************************************************************
4062 * PathUnExpandEnvStringsW [SHLWAPI.@]
4064 * Unicode version of PathUnExpandEnvStringsA.
4066 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR pszPath
, LPWSTR pszBuf
, UINT cchBuf
)
4068 FIXME("(%s,%s,0x%08x)\n", debugstr_w(pszPath
), debugstr_w(pszBuf
), cchBuf
);
4072 /*************************************************************************
4075 * Find localised or default web content in "%WINDOWS%\web\".
4078 * lpszFile [I] File name containing content to look for
4079 * lpszPath [O] Buffer to contain the full path to the file
4080 * dwPathLen [I] Length of lpszPath
4083 * Success: S_OK. lpszPath contains the full path to the content.
4084 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4086 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4088 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4091 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4093 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4095 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4096 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4100 /*************************************************************************
4103 * Unicode version of SHGetWebFolderFilePathA.
4105 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4107 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4108 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4109 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4110 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4111 DWORD dwLen
, dwFileLen
;
4112 LANGID lidSystem
, lidUser
;
4114 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4116 /* Get base directory for web content */
4117 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4118 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4121 dwFileLen
= strlenW(lpszFile
);
4123 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4124 return E_FAIL
; /* lpszPath too short */
4126 strcpyW(lpszPath
+dwLen
, szWeb
);
4128 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4130 lidSystem
= GetSystemDefaultUILanguage();
4131 lidUser
= GetUserDefaultUILanguage();
4133 if (lidSystem
!= lidUser
)
4135 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4137 /* Use localised content in the users UI language if present */
4138 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4139 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4140 if (PathFileExistsW(lpszPath
))
4145 /* Fall back to OS default installed content */
4146 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4147 if (PathFileExistsW(lpszPath
))
4152 #define PATH_CHAR_CLASS_LETTER 0x00000001
4153 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4154 #define PATH_CHAR_CLASS_DOT 0x00000004
4155 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4156 #define PATH_CHAR_CLASS_COLON 0x00000010
4157 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4158 #define PATH_CHAR_CLASS_COMMA 0x00000040
4159 #define PATH_CHAR_CLASS_SPACE 0x00000080
4160 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4161 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4163 #define PATH_CHAR_CLASS_INVALID 0x00000000
4164 #define PATH_CHAR_CLASS_ANY 0xffffffff
4166 static const DWORD SHELL_charclass
[] =
4168 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4169 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4170 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4171 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4172 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4173 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4174 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4175 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4176 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4177 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4178 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4179 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4180 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4181 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4182 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4183 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4184 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4185 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4186 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4187 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4188 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4189 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4190 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4191 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4192 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4193 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4194 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4195 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4196 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4197 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4198 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4199 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4200 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4201 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4202 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4203 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4204 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4205 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4206 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4207 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4208 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4209 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4210 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4211 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4212 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4213 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4214 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4215 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4216 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4217 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4218 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4219 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4220 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4221 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4222 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4223 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4224 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4225 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4226 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4227 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4228 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4229 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4230 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4231 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4234 /*************************************************************************
4237 * Check if an ASCII char is of a certain class
4239 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4241 if ((unsigned)c
> 0x7e)
4242 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4244 return class & SHELL_charclass
[(unsigned)c
];
4247 /*************************************************************************
4250 * Check if a Unicode char is of a certain class
4252 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4255 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4257 return class & SHELL_charclass
[c
];