4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2001, 2002 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
29 #include "wine/unicode.h"
36 #define NO_SHLWAPI_STREAM
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 /* Get a function pointer from a DLL handle */
43 #define GET_FUNC(func, module, name, fail) \
46 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
47 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
48 if (!func) return fail; \
52 /* DLL handles for late bound calls */
53 static HMODULE SHLWAPI_hshell32
;
55 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
56 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
57 static fnpIsNetDrive pIsNetDrive
;
59 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
61 static inline WCHAR
* heap_strdupAtoW(LPCSTR str
)
67 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
68 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
70 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
76 /*************************************************************************
77 * PathAppendA [SHLWAPI.@]
79 * Append one path to another.
82 * lpszPath [I/O] Initial part of path, and destination for output
83 * lpszAppend [I] Path to append
86 * Success: TRUE. lpszPath contains the newly created path.
87 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
90 * lpszAppend must contain at least one backslash ('\') if not NULL.
91 * Because PathCombineA() is used to join the paths, the resulting
92 * path is also canonicalized.
94 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
96 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
98 if (lpszPath
&& lpszAppend
)
100 if (!PathIsUNCA(lpszAppend
))
101 while (*lpszAppend
== '\\')
103 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
109 /*************************************************************************
110 * PathAppendW [SHLWAPI.@]
114 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
116 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
118 if (lpszPath
&& lpszAppend
)
120 if (!PathIsUNCW(lpszAppend
))
121 while (*lpszAppend
== '\\')
123 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
129 /*************************************************************************
130 * PathCombineA [SHLWAPI.@]
132 * Combine two paths together.
135 * lpszDest [O] Destination for combined path
136 * lpszDir [I] Directory path
137 * lpszFile [I] File path
140 * Success: The output path
141 * Failure: NULL, if inputs are invalid.
144 * lpszDest should be at least MAX_PATH in size, and may point to the same
145 * memory location as lpszDir. The combined path is canonicalised.
147 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
149 WCHAR szDest
[MAX_PATH
];
150 WCHAR szDir
[MAX_PATH
];
151 WCHAR szFile
[MAX_PATH
];
152 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
154 /* Invalid parameters */
157 if (!lpszDir
&& !lpszFile
)
164 MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
);
166 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
168 if (PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
))
169 if (WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0))
176 /*************************************************************************
177 * PathCombineW [SHLWAPI.@]
181 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
183 WCHAR szTemp
[MAX_PATH
];
184 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
186 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
188 /* Invalid parameters */
191 if (!lpszDir
&& !lpszFile
)
197 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
200 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
202 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
204 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
207 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
220 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
223 PathStripToRootW(szTemp
);
224 lpszFile
++; /* Skip '\' */
226 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
231 strcatW(szTemp
, lpszFile
);
234 PathCanonicalizeW(lpszDest
, szTemp
);
238 /*************************************************************************
239 * PathAddBackslashA [SHLWAPI.@]
241 * Append a backslash ('\') to a path if one doesn't exist.
244 * lpszPath [I/O] The path to append a backslash to.
247 * Success: The position of the last backslash in the path.
248 * Failure: NULL, if lpszPath is NULL or the path is too large.
250 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
253 LPSTR prev
= lpszPath
;
255 TRACE("(%s)\n",debugstr_a(lpszPath
));
257 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
263 lpszPath
= CharNextA(prev
);
276 /*************************************************************************
277 * PathAddBackslashW [SHLWAPI.@]
279 * See PathAddBackslashA.
281 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
285 TRACE("(%s)\n",debugstr_w(lpszPath
));
287 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
293 if (lpszPath
[-1] != '\\')
302 /*************************************************************************
303 * PathBuildRootA [SHLWAPI.@]
305 * Create a root drive string (e.g. "A:\") from a drive number.
308 * lpszPath [O] Destination for the drive string
314 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
316 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
318 TRACE("(%p,%d)\n", lpszPath
, drive
);
320 if (lpszPath
&& drive
>= 0 && drive
< 26)
322 lpszPath
[0] = 'A' + drive
;
330 /*************************************************************************
331 * PathBuildRootW [SHLWAPI.@]
333 * See PathBuildRootA.
335 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
337 TRACE("(%p,%d)\n", lpszPath
, drive
);
339 if (lpszPath
&& drive
>= 0 && drive
< 26)
341 lpszPath
[0] = 'A' + drive
;
349 /*************************************************************************
350 * PathFindFileNameA [SHLWAPI.@]
352 * Locate the start of the file name in a path
355 * lpszPath [I] Path to search
358 * A pointer to the first character of the file name
360 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
362 LPCSTR lastSlash
= lpszPath
;
364 TRACE("(%s)\n",debugstr_a(lpszPath
));
366 while (lpszPath
&& *lpszPath
)
368 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
369 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
370 lastSlash
= lpszPath
+ 1;
371 lpszPath
= CharNextA(lpszPath
);
373 return (LPSTR
)lastSlash
;
376 /*************************************************************************
377 * PathFindFileNameW [SHLWAPI.@]
379 * See PathFindFileNameA.
381 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
383 LPCWSTR lastSlash
= lpszPath
;
385 TRACE("(%s)\n",debugstr_w(lpszPath
));
387 while (lpszPath
&& *lpszPath
)
389 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
390 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
391 lastSlash
= lpszPath
+ 1;
394 return (LPWSTR
)lastSlash
;
397 /*************************************************************************
398 * PathFindExtensionA [SHLWAPI.@]
400 * Locate the start of the file extension in a path
403 * lpszPath [I] The path to search
406 * A pointer to the first character of the extension, the end of
407 * the string if the path has no extension, or NULL If lpszPath is NULL
409 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
411 LPCSTR lastpoint
= NULL
;
413 TRACE("(%s)\n", debugstr_a(lpszPath
));
419 if (*lpszPath
== '\\' || *lpszPath
==' ')
421 else if (*lpszPath
== '.')
422 lastpoint
= lpszPath
;
423 lpszPath
= CharNextA(lpszPath
);
426 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
429 /*************************************************************************
430 * PathFindExtensionW [SHLWAPI.@]
432 * See PathFindExtensionA.
434 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
436 LPCWSTR lastpoint
= NULL
;
438 TRACE("(%s)\n", debugstr_w(lpszPath
));
444 if (*lpszPath
== '\\' || *lpszPath
==' ')
446 else if (*lpszPath
== '.')
447 lastpoint
= lpszPath
;
451 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
454 /*************************************************************************
455 * PathGetArgsA [SHLWAPI.@]
457 * Find the next argument in a string delimited by spaces.
460 * lpszPath [I] The string to search for arguments in
463 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
466 * Spaces in quoted strings are ignored as delimiters.
468 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
470 BOOL bSeenQuote
= FALSE
;
472 TRACE("(%s)\n",debugstr_a(lpszPath
));
478 if ((*lpszPath
==' ') && !bSeenQuote
)
479 return (LPSTR
)lpszPath
+ 1;
480 if (*lpszPath
== '"')
481 bSeenQuote
= !bSeenQuote
;
482 lpszPath
= CharNextA(lpszPath
);
485 return (LPSTR
)lpszPath
;
488 /*************************************************************************
489 * PathGetArgsW [SHLWAPI.@]
493 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
495 BOOL bSeenQuote
= FALSE
;
497 TRACE("(%s)\n",debugstr_w(lpszPath
));
503 if ((*lpszPath
==' ') && !bSeenQuote
)
504 return (LPWSTR
)lpszPath
+ 1;
505 if (*lpszPath
== '"')
506 bSeenQuote
= !bSeenQuote
;
510 return (LPWSTR
)lpszPath
;
513 /*************************************************************************
514 * PathGetDriveNumberA [SHLWAPI.@]
516 * Return the drive number from a path
519 * lpszPath [I] Path to get the drive number from
522 * Success: The drive number corresponding to the drive in the path
523 * Failure: -1, if lpszPath contains no valid drive
525 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
527 TRACE ("(%s)\n",debugstr_a(lpszPath
));
529 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
530 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
531 return tolower(*lpszPath
) - 'a';
535 /*************************************************************************
536 * PathGetDriveNumberW [SHLWAPI.@]
538 * See PathGetDriveNumberA.
540 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
542 TRACE ("(%s)\n",debugstr_w(lpszPath
));
546 WCHAR tl
= tolowerW(lpszPath
[0]);
547 if (tl
>= 'a' && tl
<= 'z' && lpszPath
[1] == ':')
553 /*************************************************************************
554 * PathRemoveFileSpecA [SHLWAPI.@]
556 * Remove the file specification from a path.
559 * lpszPath [I/O] Path to remove the file spec from
562 * TRUE If the path was valid and modified
565 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
567 LPSTR lpszFileSpec
= lpszPath
;
568 BOOL bModified
= FALSE
;
570 TRACE("(%s)\n",debugstr_a(lpszPath
));
574 /* Skip directory or UNC path */
575 if (*lpszPath
== '\\')
576 lpszFileSpec
= ++lpszPath
;
577 if (*lpszPath
== '\\')
578 lpszFileSpec
= ++lpszPath
;
582 if(*lpszPath
== '\\')
583 lpszFileSpec
= lpszPath
; /* Skip dir */
584 else if(*lpszPath
== ':')
586 lpszFileSpec
= ++lpszPath
; /* Skip drive */
587 if (*lpszPath
== '\\')
590 if (!(lpszPath
= CharNextA(lpszPath
)))
596 *lpszFileSpec
= '\0';
603 /*************************************************************************
604 * PathRemoveFileSpecW [SHLWAPI.@]
606 * See PathRemoveFileSpecA.
608 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
610 LPWSTR lpszFileSpec
= lpszPath
;
611 BOOL bModified
= FALSE
;
613 TRACE("(%s)\n",debugstr_w(lpszPath
));
617 /* Skip directory or UNC path */
618 if (*lpszPath
== '\\')
619 lpszFileSpec
= ++lpszPath
;
620 if (*lpszPath
== '\\')
621 lpszFileSpec
= ++lpszPath
;
625 if(*lpszPath
== '\\')
626 lpszFileSpec
= lpszPath
; /* Skip dir */
627 else if(*lpszPath
== ':')
629 lpszFileSpec
= ++lpszPath
; /* Skip drive */
630 if (*lpszPath
== '\\')
638 *lpszFileSpec
= '\0';
645 /*************************************************************************
646 * PathStripPathA [SHLWAPI.@]
648 * Remove the initial path from the beginning of a filename
651 * lpszPath [I/O] Path to remove the initial path from
656 void WINAPI
PathStripPathA(LPSTR lpszPath
)
658 TRACE("(%s)\n", debugstr_a(lpszPath
));
662 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
664 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
668 /*************************************************************************
669 * PathStripPathW [SHLWAPI.@]
671 * See PathStripPathA.
673 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
677 TRACE("(%s)\n", debugstr_w(lpszPath
));
678 lpszFileName
= PathFindFileNameW(lpszPath
);
680 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
683 /*************************************************************************
684 * PathStripToRootA [SHLWAPI.@]
686 * Reduce a path to its root.
689 * lpszPath [I/O] the path to reduce
692 * Success: TRUE if the stripped path is a root path
693 * Failure: FALSE if the path cannot be stripped or is NULL
695 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
697 TRACE("(%s)\n", debugstr_a(lpszPath
));
701 while(!PathIsRootA(lpszPath
))
702 if (!PathRemoveFileSpecA(lpszPath
))
707 /*************************************************************************
708 * PathStripToRootW [SHLWAPI.@]
710 * See PathStripToRootA.
712 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
714 TRACE("(%s)\n", debugstr_w(lpszPath
));
718 while(!PathIsRootW(lpszPath
))
719 if (!PathRemoveFileSpecW(lpszPath
))
724 /*************************************************************************
725 * PathRemoveArgsA [SHLWAPI.@]
727 * Strip space separated arguments from a path.
730 * lpszPath [I/O] Path to remove arguments from
735 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
737 TRACE("(%s)\n",debugstr_a(lpszPath
));
741 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
746 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
747 if(*lpszLastChar
== ' ')
748 *lpszLastChar
= '\0';
753 /*************************************************************************
754 * PathRemoveArgsW [SHLWAPI.@]
756 * See PathRemoveArgsA.
758 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
760 TRACE("(%s)\n",debugstr_w(lpszPath
));
764 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
765 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
770 /*************************************************************************
771 * PathRemoveExtensionA [SHLWAPI.@]
773 * Remove the file extension from a path
776 * lpszPath [I/O] Path to remove the extension from
779 * The NUL terminator must be written only if extension exists
780 * and if the pointed character is not already NUL.
785 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
787 TRACE("(%s)\n", debugstr_a(lpszPath
));
791 lpszPath
= PathFindExtensionA(lpszPath
);
792 if (lpszPath
&& *lpszPath
!= '\0')
797 /*************************************************************************
798 * PathRemoveExtensionW [SHLWAPI.@]
800 * See PathRemoveExtensionA.
802 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
804 TRACE("(%s)\n", debugstr_w(lpszPath
));
808 lpszPath
= PathFindExtensionW(lpszPath
);
809 if (lpszPath
&& *lpszPath
!= '\0')
814 /*************************************************************************
815 * PathRemoveBackslashA [SHLWAPI.@]
817 * Remove a trailing backslash from a path.
820 * lpszPath [I/O] Path to remove backslash from
823 * Success: A pointer to the end of the path
824 * Failure: NULL, if lpszPath is NULL
826 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
830 TRACE("(%s)\n", debugstr_a(lpszPath
));
834 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
835 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
841 /*************************************************************************
842 * PathRemoveBackslashW [SHLWAPI.@]
844 * See PathRemoveBackslashA.
846 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
848 LPWSTR szTemp
= NULL
;
850 TRACE("(%s)\n", debugstr_w(lpszPath
));
854 szTemp
= lpszPath
+ strlenW(lpszPath
);
855 if (szTemp
> lpszPath
) szTemp
--;
856 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
862 /*************************************************************************
863 * PathRemoveBlanksA [SHLWAPI.@]
865 * Remove Spaces from the start and end of a path.
868 * lpszPath [I/O] Path to strip blanks from
873 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
875 TRACE("(%s)\n", debugstr_a(lpszPath
));
877 if(lpszPath
&& *lpszPath
)
879 LPSTR start
= lpszPath
;
881 while (*lpszPath
== ' ')
882 lpszPath
= CharNextA(lpszPath
);
885 *start
++ = *lpszPath
++;
887 if (start
!= lpszPath
)
888 while (start
[-1] == ' ')
894 /*************************************************************************
895 * PathRemoveBlanksW [SHLWAPI.@]
897 * See PathRemoveBlanksA.
899 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
901 TRACE("(%s)\n", debugstr_w(lpszPath
));
903 if(lpszPath
&& *lpszPath
)
905 LPWSTR start
= lpszPath
;
907 while (*lpszPath
== ' ')
911 *start
++ = *lpszPath
++;
913 if (start
!= lpszPath
)
914 while (start
[-1] == ' ')
920 /*************************************************************************
921 * PathQuoteSpacesA [SHLWAPI.@]
923 * Surround a path containing spaces in quotes.
926 * lpszPath [I/O] Path to quote
932 * The path is not changed if it is invalid or has no spaces.
934 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
936 TRACE("(%s)\n", debugstr_a(lpszPath
));
938 if(lpszPath
&& StrChrA(lpszPath
,' '))
940 size_t iLen
= strlen(lpszPath
) + 1;
942 if (iLen
+ 2 < MAX_PATH
)
944 memmove(lpszPath
+ 1, lpszPath
, iLen
);
946 lpszPath
[iLen
] = '"';
947 lpszPath
[iLen
+ 1] = '\0';
952 /*************************************************************************
953 * PathQuoteSpacesW [SHLWAPI.@]
955 * See PathQuoteSpacesA.
957 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
959 TRACE("(%s)\n", debugstr_w(lpszPath
));
961 if(lpszPath
&& StrChrW(lpszPath
,' '))
963 int iLen
= strlenW(lpszPath
) + 1;
965 if (iLen
+ 2 < MAX_PATH
)
967 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
969 lpszPath
[iLen
] = '"';
970 lpszPath
[iLen
+ 1] = '\0';
975 /*************************************************************************
976 * PathUnquoteSpacesA [SHLWAPI.@]
978 * Remove quotes ("") from around a path, if present.
981 * lpszPath [I/O] Path to strip quotes from
987 * If the path contains a single quote only, an empty string will result.
988 * Otherwise quotes are only removed if they appear at the start and end
991 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
993 TRACE("(%s)\n", debugstr_a(lpszPath
));
995 if (lpszPath
&& *lpszPath
== '"')
997 DWORD dwLen
= strlen(lpszPath
) - 1;
999 if (lpszPath
[dwLen
] == '"')
1001 lpszPath
[dwLen
] = '\0';
1002 for (; *lpszPath
; lpszPath
++)
1003 *lpszPath
= lpszPath
[1];
1008 /*************************************************************************
1009 * PathUnquoteSpacesW [SHLWAPI.@]
1011 * See PathUnquoteSpacesA.
1013 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
1015 TRACE("(%s)\n", debugstr_w(lpszPath
));
1017 if (lpszPath
&& *lpszPath
== '"')
1019 DWORD dwLen
= strlenW(lpszPath
) - 1;
1021 if (lpszPath
[dwLen
] == '"')
1023 lpszPath
[dwLen
] = '\0';
1024 for (; *lpszPath
; lpszPath
++)
1025 *lpszPath
= lpszPath
[1];
1030 /*************************************************************************
1031 * PathParseIconLocationA [SHLWAPI.@]
1033 * Parse the location of an icon from a path.
1036 * lpszPath [I/O] The path to parse the icon location from.
1039 * Success: The number of the icon
1040 * Failure: 0 if the path does not contain an icon location or is NULL
1043 * The path has surrounding quotes and spaces removed regardless
1044 * of whether the call succeeds or not.
1046 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1051 TRACE("(%s)\n", debugstr_a(lpszPath
));
1055 if ((lpszComma
= strchr(lpszPath
, ',')))
1057 *lpszComma
++ = '\0';
1058 iRet
= StrToIntA(lpszComma
);
1060 PathUnquoteSpacesA(lpszPath
);
1061 PathRemoveBlanksA(lpszPath
);
1066 /*************************************************************************
1067 * PathParseIconLocationW [SHLWAPI.@]
1069 * See PathParseIconLocationA.
1071 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1076 TRACE("(%s)\n", debugstr_w(lpszPath
));
1080 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1082 *lpszComma
++ = '\0';
1083 iRet
= StrToIntW(lpszComma
);
1085 PathUnquoteSpacesW(lpszPath
);
1086 PathRemoveBlanksW(lpszPath
);
1091 /*************************************************************************
1094 * Unicode version of PathFileExistsDefExtA.
1096 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1098 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1099 { '.', 'c', 'o', 'm', 0},
1100 { '.', 'e', 'x', 'e', 0},
1101 { '.', 'b', 'a', 't', 0},
1102 { '.', 'l', 'n', 'k', 0},
1103 { '.', 'c', 'm', 'd', 0},
1106 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1108 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1113 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1114 if (!*szExt
|| dwWhich
& 0x40)
1117 int iLen
= lstrlenW(lpszPath
);
1118 if (iLen
> (MAX_PATH
- 5))
1120 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1122 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1123 if (PathFileExistsW(lpszPath
))
1128 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1132 return PathFileExistsW(lpszPath
);
1135 /*************************************************************************
1138 * Determine if a file exists locally and is of an executable type.
1141 * lpszPath [I/O] File to search for
1142 * dwWhich [I] Type of executable to search for
1145 * TRUE If the file was found. lpszPath contains the file name.
1149 * lpszPath is modified in place and must be at least MAX_PATH in length.
1150 * If the function returns FALSE, the path is modified to its original state.
1151 * If the given path contains an extension or dwWhich is 0, executable
1152 * extensions are not checked.
1154 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1155 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1156 * their own developers exclusive use. Monopoly, anyone?
1158 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1162 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1166 WCHAR szPath
[MAX_PATH
];
1167 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1168 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1170 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1175 /*************************************************************************
1176 * SHLWAPI_PathFindInOtherDirs
1178 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1180 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1182 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1183 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1187 WCHAR buff
[MAX_PATH
];
1189 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1191 /* Try system directories */
1192 GetSystemDirectoryW(buff
, MAX_PATH
);
1193 if (!PathAppendW(buff
, lpszFile
))
1195 if (PathFileExistsDefExtW(buff
, dwWhich
))
1197 strcpyW(lpszFile
, buff
);
1200 GetWindowsDirectoryW(buff
, MAX_PATH
);
1201 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1203 if (PathFileExistsDefExtW(buff
, dwWhich
))
1205 strcpyW(lpszFile
, buff
);
1208 GetWindowsDirectoryW(buff
, MAX_PATH
);
1209 if (!PathAppendW(buff
, lpszFile
))
1211 if (PathFileExistsDefExtW(buff
, dwWhich
))
1213 strcpyW(lpszFile
, buff
);
1216 /* Try dirs listed in %PATH% */
1217 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1219 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1222 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1223 lpszCurr
= lpszPATH
;
1226 LPCWSTR lpszEnd
= lpszCurr
;
1227 LPWSTR pBuff
= buff
;
1229 while (*lpszEnd
== ' ')
1231 while (*lpszEnd
&& *lpszEnd
!= ';')
1232 *pBuff
++ = *lpszEnd
++;
1236 lpszCurr
= lpszEnd
+ 1;
1238 lpszCurr
= NULL
; /* Last Path, terminate after this */
1240 if (!PathAppendW(buff
, lpszFile
))
1242 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1245 if (PathFileExistsDefExtW(buff
, dwWhich
))
1247 strcpyW(lpszFile
, buff
);
1248 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1252 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1256 /*************************************************************************
1259 * Search a range of paths for a specific type of executable.
1262 * lpszFile [I/O] File to search for
1263 * lppszOtherDirs [I] Other directories to look in
1264 * dwWhich [I] Type of executable to search for
1267 * Success: TRUE. The path to the executable is stored in lpszFile.
1268 * Failure: FALSE. The path to the executable is unchanged.
1270 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1272 WCHAR szFile
[MAX_PATH
];
1273 WCHAR buff
[MAX_PATH
];
1275 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1277 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1280 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1282 /* Search provided directories first */
1283 if (lppszOtherDirs
&& *lppszOtherDirs
)
1285 WCHAR szOther
[MAX_PATH
];
1286 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1288 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1290 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1291 PathCombineW(buff
, szOther
, szFile
);
1292 if (PathFileExistsDefExtW(buff
, dwWhich
))
1294 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1300 /* Not found, try system and path dirs */
1301 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1303 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1309 /*************************************************************************
1312 * Unicode version of PathFindOnPathExA.
1314 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1316 WCHAR buff
[MAX_PATH
];
1318 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1320 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1323 /* Search provided directories first */
1324 if (lppszOtherDirs
&& *lppszOtherDirs
)
1326 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1327 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1329 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1330 if (PathFileExistsDefExtW(buff
, dwWhich
))
1332 strcpyW(lpszFile
, buff
);
1338 /* Not found, try system and path dirs */
1339 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1342 /*************************************************************************
1343 * PathFindOnPathA [SHLWAPI.@]
1345 * Search a range of paths for an executable.
1348 * lpszFile [I/O] File to search for
1349 * lppszOtherDirs [I] Other directories to look in
1352 * Success: TRUE. The path to the executable is stored in lpszFile.
1353 * Failure: FALSE. The path to the executable is unchanged.
1355 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1357 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1358 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1361 /*************************************************************************
1362 * PathFindOnPathW [SHLWAPI.@]
1364 * See PathFindOnPathA.
1366 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1368 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1369 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1372 /*************************************************************************
1373 * PathCompactPathExA [SHLWAPI.@]
1375 * Compact a path into a given number of characters.
1378 * lpszDest [O] Destination for compacted path
1379 * lpszPath [I] Source path
1380 * cchMax [I] Maximum size of compacted path
1381 * dwFlags [I] Reserved
1384 * Success: TRUE. The compacted path is written to lpszDest.
1385 * Failure: FALSE. lpszPath is undefined.
1388 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1390 * The Win32 version of this function contains a bug: When cchMax == 7,
1391 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1394 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1395 * because Win32 will insert a "\" in lpszDest, even if one is
1396 * not present in the original path.
1398 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1399 UINT cchMax
, DWORD dwFlags
)
1403 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1405 if (lpszPath
&& lpszDest
)
1407 WCHAR szPath
[MAX_PATH
];
1408 WCHAR szDest
[MAX_PATH
];
1410 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1412 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1413 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1418 /*************************************************************************
1419 * PathCompactPathExW [SHLWAPI.@]
1421 * See PathCompactPathExA.
1423 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1424 UINT cchMax
, DWORD dwFlags
)
1426 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1428 DWORD dwLen
, dwFileLen
= 0;
1430 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1437 WARN("Invalid lpszDest would crash under Win32!\n");
1446 dwLen
= strlenW(lpszPath
) + 1;
1450 /* Don't need to compact */
1451 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1455 /* Path must be compacted to fit into lpszDest */
1456 lpszFile
= PathFindFileNameW(lpszPath
);
1457 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1459 if (dwFileLen
== dwLen
)
1461 /* No root in psth */
1464 while (--cchMax
> 0) /* No room left for anything but ellipses */
1469 /* Compact the file name with ellipses at the end */
1471 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1472 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1475 /* We have a root in the path */
1476 lpszFile
--; /* Start compacted filename with the path separator */
1479 if (dwFileLen
+ 3 > cchMax
)
1481 /* Compact the file name */
1484 while (--cchMax
> 0) /* No room left for anything but ellipses */
1489 strcpyW(lpszDest
, szEllipses
);
1492 *lpszDest
++ = *lpszFile
++;
1495 while (--cchMax
> 0) /* No room left for anything but ellipses */
1501 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1502 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1506 /* Only the root needs to be Compacted */
1507 dwLen
= cchMax
- dwFileLen
- 3;
1508 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1509 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1510 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1514 /*************************************************************************
1515 * PathIsRelativeA [SHLWAPI.@]
1517 * Determine if a path is a relative path.
1520 * lpszPath [I] Path to check
1523 * TRUE: The path is relative, or is invalid.
1524 * FALSE: The path is not relative.
1526 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1528 TRACE("(%s)\n",debugstr_a(lpszPath
));
1530 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1532 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1537 /*************************************************************************
1538 * PathIsRelativeW [SHLWAPI.@]
1540 * See PathIsRelativeA.
1542 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1544 TRACE("(%s)\n",debugstr_w(lpszPath
));
1546 if (!lpszPath
|| !*lpszPath
)
1548 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1553 /*************************************************************************
1554 * PathIsRootA [SHLWAPI.@]
1556 * Determine if a path is a root path.
1559 * lpszPath [I] Path to check
1562 * TRUE If lpszPath is valid and a root path,
1565 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1567 TRACE("(%s)\n", debugstr_a(lpszPath
));
1569 if (lpszPath
&& *lpszPath
)
1571 if (*lpszPath
== '\\')
1574 return TRUE
; /* \ */
1575 else if (lpszPath
[1]=='\\')
1577 BOOL bSeenSlash
= FALSE
;
1580 /* Check for UNC root path */
1583 if (*lpszPath
== '\\')
1589 lpszPath
= CharNextA(lpszPath
);
1594 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1595 return TRUE
; /* X:\ */
1600 /*************************************************************************
1601 * PathIsRootW [SHLWAPI.@]
1605 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1607 TRACE("(%s)\n", debugstr_w(lpszPath
));
1609 if (lpszPath
&& *lpszPath
)
1611 if (*lpszPath
== '\\')
1614 return TRUE
; /* \ */
1615 else if (lpszPath
[1]=='\\')
1617 BOOL bSeenSlash
= FALSE
;
1620 /* Check for UNC root path */
1623 if (*lpszPath
== '\\')
1634 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1635 return TRUE
; /* X:\ */
1640 /*************************************************************************
1641 * PathIsDirectoryA [SHLWAPI.@]
1643 * Determine if a path is a valid directory
1646 * lpszPath [I] Path to check.
1649 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1650 * FALSE if lpszPath is invalid or not a directory.
1653 * Although this function is prototyped as returning a BOOL, it returns
1654 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1656 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1661 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1665 TRACE("(%s)\n", debugstr_a(lpszPath
));
1667 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1670 if (PathIsUNCServerShareA(lpszPath
))
1672 FIXME("UNC Server Share not yet supported - FAILING\n");
1676 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1678 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1681 /*************************************************************************
1682 * PathIsDirectoryW [SHLWAPI.@]
1684 * See PathIsDirectoryA.
1686 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1690 TRACE("(%s)\n", debugstr_w(lpszPath
));
1692 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1695 if (PathIsUNCServerShareW(lpszPath
))
1697 FIXME("UNC Server Share not yet supported - FAILING\n");
1701 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1703 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1706 /*************************************************************************
1707 * PathFileExistsA [SHLWAPI.@]
1709 * Determine if a file exists.
1712 * lpszPath [I] Path to check
1715 * TRUE If the file exists and is readable
1718 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1723 TRACE("(%s)\n",debugstr_a(lpszPath
));
1728 /* Prevent a dialog box if path is on a disk that has been ejected. */
1729 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1730 dwAttr
= GetFileAttributesA(lpszPath
);
1731 SetErrorMode(iPrevErrMode
);
1732 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1735 /*************************************************************************
1736 * PathFileExistsW [SHLWAPI.@]
1738 * See PathFileExistsA.
1740 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1745 TRACE("(%s)\n",debugstr_w(lpszPath
));
1750 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1751 dwAttr
= GetFileAttributesW(lpszPath
);
1752 SetErrorMode(iPrevErrMode
);
1753 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1756 /*************************************************************************
1757 * PathFileExistsAndAttributesA [SHLWAPI.445]
1759 * Determine if a file exists.
1762 * lpszPath [I] Path to check
1763 * dwAttr [O] attributes of file
1766 * TRUE If the file exists and is readable
1769 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1774 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1777 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1782 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1783 dwVal
= GetFileAttributesA(lpszPath
);
1784 SetErrorMode(iPrevErrMode
);
1787 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1790 /*************************************************************************
1791 * PathFileExistsAndAttributesW [SHLWAPI.446]
1793 * See PathFileExistsA.
1795 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1800 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1805 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1806 dwVal
= GetFileAttributesW(lpszPath
);
1807 SetErrorMode(iPrevErrMode
);
1810 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1813 /*************************************************************************
1814 * PathMatchSingleMaskA [internal]
1816 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1818 while (*name
&& *mask
&& *mask
!=';')
1824 if (PathMatchSingleMaskA(name
,mask
+1))
1825 return TRUE
; /* try substrings */
1830 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1833 name
= CharNextA(name
);
1834 mask
= CharNextA(mask
);
1839 while (*mask
== '*')
1841 if (!*mask
|| *mask
== ';')
1847 /*************************************************************************
1848 * PathMatchSingleMaskW [internal]
1850 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1852 while (*name
&& *mask
&& *mask
!= ';')
1858 if (PathMatchSingleMaskW(name
,mask
+1))
1859 return TRUE
; /* try substrings */
1864 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1872 while (*mask
== '*')
1874 if (!*mask
|| *mask
== ';')
1880 /*************************************************************************
1881 * PathMatchSpecA [SHLWAPI.@]
1883 * Determine if a path matches one or more search masks.
1886 * lpszPath [I] Path to check
1887 * lpszMask [I] Search mask(s)
1890 * TRUE If lpszPath is valid and is matched
1894 * Multiple search masks may be given if they are separated by ";". The
1895 * pattern "*.*" is treated specially in that it matches all paths (for
1896 * backwards compatibility with DOS).
1898 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1900 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1902 if (!lstrcmpA(lpszMask
, "*.*"))
1903 return TRUE
; /* Matches every path */
1907 while (*lpszMask
== ' ')
1908 lpszMask
++; /* Eat leading spaces */
1910 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1911 return TRUE
; /* Matches the current mask */
1913 while (*lpszMask
&& *lpszMask
!= ';')
1914 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1916 if (*lpszMask
== ';')
1922 /*************************************************************************
1923 * PathMatchSpecW [SHLWAPI.@]
1925 * See PathMatchSpecA.
1927 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1929 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1931 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1933 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1934 return TRUE
; /* Matches every path */
1938 while (*lpszMask
== ' ')
1939 lpszMask
++; /* Eat leading spaces */
1941 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1942 return TRUE
; /* Matches the current path */
1944 while (*lpszMask
&& *lpszMask
!= ';')
1945 lpszMask
++; /* masks separated by ';' */
1947 if (*lpszMask
== ';')
1953 /*************************************************************************
1954 * PathIsSameRootA [SHLWAPI.@]
1956 * Determine if two paths share the same root.
1959 * lpszPath1 [I] Source path
1960 * lpszPath2 [I] Path to compare with
1963 * TRUE If both paths are valid and share the same root.
1964 * FALSE If either path is invalid or the paths do not share the same root.
1966 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1971 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1973 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1976 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1977 if (lpszStart
- lpszPath1
> dwLen
)
1978 return FALSE
; /* Paths not common up to length of the root */
1982 /*************************************************************************
1983 * PathIsSameRootW [SHLWAPI.@]
1985 * See PathIsSameRootA.
1987 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1992 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1994 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1997 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1998 if (lpszStart
- lpszPath1
> dwLen
)
1999 return FALSE
; /* Paths not common up to length of the root */
2003 /*************************************************************************
2004 * PathIsContentTypeA [SHLWAPI.@]
2006 * Determine if a file is of a given registered content type.
2009 * lpszPath [I] File to check
2010 * lpszContentType [I] Content type to check for
2013 * TRUE If lpszPath is a given registered content type,
2017 * This function looks up the registered content type for lpszPath. If
2018 * a content type is registered, it is compared (case insensitively) to
2019 * lpszContentType. Only if this matches does the function succeed.
2021 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2025 char szBuff
[MAX_PATH
];
2027 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2029 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2030 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2031 REG_NONE
, szBuff
, &dwDummy
) &&
2032 !strcasecmp(lpszContentType
, szBuff
))
2039 /*************************************************************************
2040 * PathIsContentTypeW [SHLWAPI.@]
2042 * See PathIsContentTypeA.
2044 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2046 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2049 WCHAR szBuff
[MAX_PATH
];
2051 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2053 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2054 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2055 REG_NONE
, szBuff
, &dwDummy
) &&
2056 !strcmpiW(lpszContentType
, szBuff
))
2063 /*************************************************************************
2064 * PathIsFileSpecA [SHLWAPI.@]
2066 * Determine if a path is a file specification.
2069 * lpszPath [I] Path to check
2072 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2075 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2077 TRACE("(%s)\n", debugstr_a(lpszPath
));
2084 if (*lpszPath
== '\\' || *lpszPath
== ':')
2086 lpszPath
= CharNextA(lpszPath
);
2091 /*************************************************************************
2092 * PathIsFileSpecW [SHLWAPI.@]
2094 * See PathIsFileSpecA.
2096 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2098 TRACE("(%s)\n", debugstr_w(lpszPath
));
2105 if (*lpszPath
== '\\' || *lpszPath
== ':')
2112 /*************************************************************************
2113 * PathIsPrefixA [SHLWAPI.@]
2115 * Determine if a path is a prefix of another.
2118 * lpszPrefix [I] Prefix
2119 * lpszPath [I] Path to check
2122 * TRUE If lpszPath has lpszPrefix as its prefix,
2123 * FALSE If either path is NULL or lpszPrefix is not a prefix
2125 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2127 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2129 if (lpszPrefix
&& lpszPath
&&
2130 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2135 /*************************************************************************
2136 * PathIsPrefixW [SHLWAPI.@]
2138 * See PathIsPrefixA.
2140 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2142 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2144 if (lpszPrefix
&& lpszPath
&&
2145 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2150 /*************************************************************************
2151 * PathIsSystemFolderA [SHLWAPI.@]
2153 * Determine if a path or file attributes are a system folder.
2156 * lpszPath [I] Path to check.
2157 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2160 * TRUE If lpszPath or dwAttrib are a system folder.
2161 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2163 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2165 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2167 if (lpszPath
&& *lpszPath
)
2168 dwAttrib
= GetFileAttributesA(lpszPath
);
2170 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2171 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2176 /*************************************************************************
2177 * PathIsSystemFolderW [SHLWAPI.@]
2179 * See PathIsSystemFolderA.
2181 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2183 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2185 if (lpszPath
&& *lpszPath
)
2186 dwAttrib
= GetFileAttributesW(lpszPath
);
2188 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2189 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2194 /*************************************************************************
2195 * PathIsUNCA [SHLWAPI.@]
2197 * Determine if a path is in UNC format.
2200 * lpszPath [I] Path to check
2203 * TRUE: The path is UNC.
2204 * FALSE: The path is not UNC or is NULL.
2206 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2208 TRACE("(%s)\n",debugstr_a(lpszPath
));
2210 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2215 /*************************************************************************
2216 * PathIsUNCW [SHLWAPI.@]
2220 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2222 TRACE("(%s)\n",debugstr_w(lpszPath
));
2224 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2229 /*************************************************************************
2230 * PathIsUNCServerA [SHLWAPI.@]
2232 * Determine if a path is a UNC server name ("\\SHARENAME").
2235 * lpszPath [I] Path to check.
2238 * TRUE If lpszPath is a valid UNC server name.
2242 * This routine is bug compatible with Win32: Server names with a
2243 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2244 * Fixing this bug may break other shlwapi functions!
2246 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2248 TRACE("(%s)\n", debugstr_a(lpszPath
));
2250 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2254 if (*lpszPath
== '\\')
2256 lpszPath
= CharNextA(lpszPath
);
2263 /*************************************************************************
2264 * PathIsUNCServerW [SHLWAPI.@]
2266 * See PathIsUNCServerA.
2268 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2270 TRACE("(%s)\n", debugstr_w(lpszPath
));
2272 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2274 return !strchrW( lpszPath
+ 2, '\\' );
2279 /*************************************************************************
2280 * PathIsUNCServerShareA [SHLWAPI.@]
2282 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2285 * lpszPath [I] Path to check.
2288 * TRUE If lpszPath is a valid UNC server share.
2292 * This routine is bug compatible with Win32: Server shares with a
2293 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2294 * Fixing this bug may break other shlwapi functions!
2296 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2298 TRACE("(%s)\n", debugstr_a(lpszPath
));
2300 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2302 BOOL bSeenSlash
= FALSE
;
2305 if (*lpszPath
== '\\')
2311 lpszPath
= CharNextA(lpszPath
);
2318 /*************************************************************************
2319 * PathIsUNCServerShareW [SHLWAPI.@]
2321 * See PathIsUNCServerShareA.
2323 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2325 TRACE("(%s)\n", debugstr_w(lpszPath
));
2327 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2329 BOOL bSeenSlash
= FALSE
;
2332 if (*lpszPath
== '\\')
2345 /*************************************************************************
2346 * PathCanonicalizeA [SHLWAPI.@]
2348 * Convert a path to its canonical form.
2351 * lpszBuf [O] Output path
2352 * lpszPath [I] Path to canonicalize
2355 * Success: TRUE. lpszBuf contains the output path,
2356 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2358 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2362 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2367 if (!lpszBuf
|| !lpszPath
)
2368 SetLastError(ERROR_INVALID_PARAMETER
);
2371 WCHAR szPath
[MAX_PATH
];
2372 WCHAR szBuff
[MAX_PATH
];
2373 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2376 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2379 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2380 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2386 /*************************************************************************
2387 * PathCanonicalizeW [SHLWAPI.@]
2389 * See PathCanonicalizeA.
2391 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2393 LPWSTR lpszDst
= lpszBuf
;
2394 LPCWSTR lpszSrc
= lpszPath
;
2396 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2401 if (!lpszBuf
|| !lpszPath
)
2403 SetLastError(ERROR_INVALID_PARAMETER
);
2414 /* Copy path root */
2415 if (*lpszSrc
== '\\')
2417 *lpszDst
++ = *lpszSrc
++;
2419 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2422 *lpszDst
++ = *lpszSrc
++;
2423 *lpszDst
++ = *lpszSrc
++;
2424 if (*lpszSrc
== '\\')
2425 *lpszDst
++ = *lpszSrc
++;
2428 /* Canonicalize the rest of the path */
2431 if (*lpszSrc
== '.')
2433 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2435 lpszSrc
+= 2; /* Skip .\ */
2437 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2439 /* \.. backs up a directory, over the root if it has no \ following X:.
2440 * .. is ignored if it would remove a UNC server name or initial \\
2442 if (lpszDst
!= lpszBuf
)
2444 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2445 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2446 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2448 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2451 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2453 if (*lpszDst
== '\\')
2454 lpszDst
++; /* Reset to last '\' */
2456 lpszDst
= lpszBuf
; /* Start path again from new root */
2458 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2461 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2463 if (lpszDst
== lpszBuf
)
2469 lpszSrc
+= 2; /* Skip .. in src path */
2472 *lpszDst
++ = *lpszSrc
++;
2475 *lpszDst
++ = *lpszSrc
++;
2477 /* Append \ to naked drive specs */
2478 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2484 /*************************************************************************
2485 * PathFindNextComponentA [SHLWAPI.@]
2487 * Find the next component in a path.
2490 * lpszPath [I] Path to find next component in
2493 * Success: A pointer to the next component, or the end of the string.
2494 * Failure: NULL, If lpszPath is invalid
2497 * A 'component' is either a backslash character (\) or UNC marker (\\).
2498 * Because of this, relative paths (e.g "c:foo") are regarded as having
2499 * only one component.
2501 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2505 TRACE("(%s)\n", debugstr_a(lpszPath
));
2507 if(!lpszPath
|| !*lpszPath
)
2510 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2512 if (lpszSlash
[1] == '\\')
2514 return lpszSlash
+ 1;
2516 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2519 /*************************************************************************
2520 * PathFindNextComponentW [SHLWAPI.@]
2522 * See PathFindNextComponentA.
2524 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2528 TRACE("(%s)\n", debugstr_w(lpszPath
));
2530 if(!lpszPath
|| !*lpszPath
)
2533 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2535 if (lpszSlash
[1] == '\\')
2537 return lpszSlash
+ 1;
2539 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2542 /*************************************************************************
2543 * PathAddExtensionA [SHLWAPI.@]
2545 * Add a file extension to a path
2548 * lpszPath [I/O] Path to add extension to
2549 * lpszExtension [I] Extension to add to lpszPath
2552 * TRUE If the path was modified,
2553 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2554 * extension already, or the new path length is too big.
2557 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2558 * does not do this, so the behaviour was removed.
2560 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2564 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2566 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2569 dwLen
= strlen(lpszPath
);
2571 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2574 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2578 /*************************************************************************
2579 * PathAddExtensionW [SHLWAPI.@]
2581 * See PathAddExtensionA.
2583 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2587 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2589 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2592 dwLen
= strlenW(lpszPath
);
2594 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2597 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2601 /*************************************************************************
2602 * PathMakePrettyA [SHLWAPI.@]
2604 * Convert an uppercase DOS filename into lowercase.
2607 * lpszPath [I/O] Path to convert.
2610 * TRUE If the path was an uppercase DOS path and was converted,
2613 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2615 LPSTR pszIter
= lpszPath
;
2617 TRACE("(%s)\n", debugstr_a(lpszPath
));
2626 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2627 return FALSE
; /* Not DOS path */
2630 pszIter
= lpszPath
+ 1;
2633 *pszIter
= tolower(*pszIter
);
2640 /*************************************************************************
2641 * PathMakePrettyW [SHLWAPI.@]
2643 * See PathMakePrettyA.
2645 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2647 LPWSTR pszIter
= lpszPath
;
2649 TRACE("(%s)\n", debugstr_w(lpszPath
));
2658 if (islowerW(*pszIter
))
2659 return FALSE
; /* Not DOS path */
2662 pszIter
= lpszPath
+ 1;
2665 *pszIter
= tolowerW(*pszIter
);
2672 /*************************************************************************
2673 * PathCommonPrefixA [SHLWAPI.@]
2675 * Determine the length of the common prefix between two paths.
2678 * lpszFile1 [I] First path for comparison
2679 * lpszFile2 [I] Second path for comparison
2680 * achPath [O] Destination for common prefix string
2683 * The length of the common prefix. This is 0 if there is no common
2684 * prefix between the paths or if any parameters are invalid. If the prefix
2685 * is non-zero and achPath is not NULL, achPath is filled with the common
2686 * part of the prefix and NUL terminated.
2689 * A common prefix of 2 is always returned as 3. It is thus possible for
2690 * the length returned to be invalid (i.e. Longer than one or both of the
2691 * strings given as parameters). This Win32 behaviour has been implemented
2692 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2693 * To work around this when using this function, always check that the byte
2694 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2696 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2699 LPCSTR lpszIter1
= lpszFile1
;
2700 LPCSTR lpszIter2
= lpszFile2
;
2702 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2707 if (!lpszFile1
|| !lpszFile2
)
2710 /* Handle roots first */
2711 if (PathIsUNCA(lpszFile1
))
2713 if (!PathIsUNCA(lpszFile2
))
2718 else if (PathIsUNCA(lpszFile2
))
2719 return 0; /* Know already lpszFile1 is not UNC */
2724 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2725 (!*lpszIter2
|| *lpszIter2
== '\\'))
2726 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2728 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2729 break; /* Strings differ at this point */
2736 iLen
++; /* Feature/Bug compatible with Win32 */
2738 if (iLen
&& achPath
)
2740 memcpy(achPath
,lpszFile1
,iLen
);
2741 achPath
[iLen
] = '\0';
2746 /*************************************************************************
2747 * PathCommonPrefixW [SHLWAPI.@]
2749 * See PathCommonPrefixA.
2751 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2754 LPCWSTR lpszIter1
= lpszFile1
;
2755 LPCWSTR lpszIter2
= lpszFile2
;
2757 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2762 if (!lpszFile1
|| !lpszFile2
)
2765 /* Handle roots first */
2766 if (PathIsUNCW(lpszFile1
))
2768 if (!PathIsUNCW(lpszFile2
))
2773 else if (PathIsUNCW(lpszFile2
))
2774 return 0; /* Know already lpszFile1 is not UNC */
2779 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2780 (!*lpszIter2
|| *lpszIter2
== '\\'))
2781 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2783 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2784 break; /* Strings differ at this point */
2791 iLen
++; /* Feature/Bug compatible with Win32 */
2793 if (iLen
&& achPath
)
2795 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2796 achPath
[iLen
] = '\0';
2801 /*************************************************************************
2802 * PathCompactPathA [SHLWAPI.@]
2804 * Make a path fit into a given width when printed to a DC.
2807 * hDc [I] Destination DC
2808 * lpszPath [I/O] Path to be printed to hDc
2809 * dx [I] Desired width
2812 * TRUE If the path was modified/went well.
2815 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2819 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2823 WCHAR szPath
[MAX_PATH
];
2824 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2825 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2826 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2831 /*************************************************************************
2832 * PathCompactPathW [SHLWAPI.@]
2834 * See PathCompactPathA.
2836 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2838 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2841 WCHAR buff
[MAX_PATH
];
2845 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2851 hdc
= hDC
= GetDC(0);
2853 /* Get the length of the whole path */
2854 dwLen
= strlenW(lpszPath
);
2855 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2857 if ((UINT
)size
.cx
> dx
)
2859 /* Path too big, must reduce it */
2861 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2863 sFile
= PathFindFileNameW(lpszPath
);
2864 if (sFile
!= lpszPath
) sFile
--;
2866 /* Get the size of ellipses */
2867 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2868 dwEllipsesLen
= size
.cx
;
2869 /* Get the size of the file name */
2870 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2871 dwPathLen
= size
.cx
;
2873 if (sFile
!= lpszPath
)
2875 LPWSTR sPath
= sFile
;
2876 BOOL bEllipses
= FALSE
;
2878 /* The path includes a file name. Include as much of the path prior to
2879 * the file name as possible, allowing for the ellipses, e.g:
2880 * c:\some very long path\filename ==> c:\some v...\filename
2882 lstrcpynW(buff
, sFile
, MAX_PATH
);
2886 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2888 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2889 dwTotalLen
+= size
.cx
;
2890 if (dwTotalLen
<= dx
)
2898 } while (sPath
> lpszPath
);
2900 if (sPath
> lpszPath
)
2904 strcpyW(sPath
, szEllipses
);
2905 strcpyW(sPath
+3, buff
);
2910 strcpyW(lpszPath
, szEllipses
);
2911 strcpyW(lpszPath
+3, buff
);
2916 /* Trim the path by adding ellipses to the end, e.g:
2917 * A very long file name.txt ==> A very...
2919 dwLen
= strlenW(lpszPath
);
2921 if (dwLen
> MAX_PATH
- 3)
2922 dwLen
= MAX_PATH
- 3;
2923 lstrcpynW(buff
, sFile
, dwLen
);
2927 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2928 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2932 DWORD dwWritten
= 0;
2934 dwEllipsesLen
/= 3; /* Size of a single '.' */
2936 /* Write as much of the Ellipses string as possible */
2937 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2940 dwWritten
+= dwEllipsesLen
;
2948 strcpyW(buff
+ dwLen
, szEllipses
);
2949 strcpyW(lpszPath
, buff
);
2960 /*************************************************************************
2961 * PathGetCharTypeA [SHLWAPI.@]
2963 * Categorise a character from a file path.
2966 * ch [I] Character to get the type of
2969 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2971 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2973 return PathGetCharTypeW(ch
);
2976 /*************************************************************************
2977 * PathGetCharTypeW [SHLWAPI.@]
2979 * See PathGetCharTypeA.
2981 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2985 TRACE("(%d)\n", ch
);
2987 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2988 ch
== '"' || ch
== '|' || ch
== '/')
2989 flags
= GCT_INVALID
; /* Invalid */
2990 else if (ch
== '*' || ch
=='?')
2991 flags
= GCT_WILD
; /* Wildchars */
2992 else if ((ch
== '\\') || (ch
== ':'))
2993 return GCT_SEPARATOR
; /* Path separators */
2998 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2999 ch
== '.' || ch
== '@' || ch
== '^' ||
3000 ch
== '\'' || ch
== 130 || ch
== '`')
3001 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
3004 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
3005 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
3010 /*************************************************************************
3011 * SHLWAPI_UseSystemForSystemFolders
3013 * Internal helper for PathMakeSystemFolderW.
3015 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3017 static BOOL bCheckedReg
= FALSE
;
3018 static BOOL bUseSystemForSystemFolders
= FALSE
;
3024 /* Key tells Win what file attributes to use on system folders */
3025 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3026 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3027 "UseSystemForSystemFolders", 0, 0, 0))
3028 bUseSystemForSystemFolders
= TRUE
;
3030 return bUseSystemForSystemFolders
;
3033 /*************************************************************************
3034 * PathMakeSystemFolderA [SHLWAPI.@]
3036 * Set system folder attribute for a path.
3039 * lpszPath [I] The path to turn into a system folder
3042 * TRUE If the path was changed to/already was a system folder
3043 * FALSE If the path is invalid or SetFileAttributesA() fails
3045 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3049 TRACE("(%s)\n", debugstr_a(lpszPath
));
3051 if (lpszPath
&& *lpszPath
)
3053 WCHAR szPath
[MAX_PATH
];
3054 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3055 bRet
= PathMakeSystemFolderW(szPath
);
3060 /*************************************************************************
3061 * PathMakeSystemFolderW [SHLWAPI.@]
3063 * See PathMakeSystemFolderA.
3065 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3067 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3068 WCHAR buff
[MAX_PATH
];
3070 TRACE("(%s)\n", debugstr_w(lpszPath
));
3072 if (!lpszPath
|| !*lpszPath
)
3075 /* If the directory is already a system directory, don't do anything */
3076 GetSystemDirectoryW(buff
, MAX_PATH
);
3077 if (!strcmpW(buff
, lpszPath
))
3080 GetWindowsDirectoryW(buff
, MAX_PATH
);
3081 if (!strcmpW(buff
, lpszPath
))
3084 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3085 if (SHLWAPI_UseSystemForSystemFolders())
3086 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3088 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3091 /* Change file attributes to system attributes */
3092 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3093 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3096 /*************************************************************************
3097 * PathRenameExtensionA [SHLWAPI.@]
3099 * Swap the file extension in a path with another extension.
3102 * lpszPath [I/O] Path to swap the extension in
3103 * lpszExt [I] The new extension
3106 * TRUE if lpszPath was modified,
3107 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3109 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3111 LPSTR lpszExtension
;
3113 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3115 lpszExtension
= PathFindExtensionA(lpszPath
);
3117 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3120 strcpy(lpszExtension
, lpszExt
);
3124 /*************************************************************************
3125 * PathRenameExtensionW [SHLWAPI.@]
3127 * See PathRenameExtensionA.
3129 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3131 LPWSTR lpszExtension
;
3133 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3135 lpszExtension
= PathFindExtensionW(lpszPath
);
3137 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3140 strcpyW(lpszExtension
, lpszExt
);
3144 /*************************************************************************
3145 * PathSearchAndQualifyA [SHLWAPI.@]
3147 * Determine if a given path is correct and fully qualified.
3150 * lpszPath [I] Path to check
3151 * lpszBuf [O] Output for correct path
3152 * cchBuf [I] Size of lpszBuf
3157 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3159 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3161 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3163 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3166 /*************************************************************************
3167 * PathSearchAndQualifyW [SHLWAPI.@]
3169 * See PathSearchAndQualifyA.
3171 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3173 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3175 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3177 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3180 /*************************************************************************
3181 * PathSkipRootA [SHLWAPI.@]
3183 * Return the portion of a path following the drive letter or mount point.
3186 * lpszPath [I] The path to skip on
3189 * Success: A pointer to the next character after the root.
3190 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3192 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3194 TRACE("(%s)\n", debugstr_a(lpszPath
));
3196 if (!lpszPath
|| !*lpszPath
)
3199 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3201 /* Network share: skip share server and mount point */
3203 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3204 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3206 return (LPSTR
)lpszPath
;
3209 if (IsDBCSLeadByte(*lpszPath
))
3213 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3214 return (LPSTR
)lpszPath
+ 3;
3218 /*************************************************************************
3219 * PathSkipRootW [SHLWAPI.@]
3221 * See PathSkipRootA.
3223 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3225 TRACE("(%s)\n", debugstr_w(lpszPath
));
3227 if (!lpszPath
|| !*lpszPath
)
3230 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3232 /* Network share: skip share server and mount point */
3234 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3235 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3237 return (LPWSTR
)lpszPath
;
3241 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3242 return (LPWSTR
)lpszPath
+ 3;
3246 /*************************************************************************
3247 * PathCreateFromUrlA [SHLWAPI.@]
3249 * See PathCreateFromUrlW
3251 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3252 LPDWORD pcchPath
, DWORD dwReserved
)
3254 WCHAR bufW
[MAX_PATH
];
3255 WCHAR
*pathW
= bufW
;
3256 UNICODE_STRING urlW
;
3258 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3260 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3261 return E_INVALIDARG
;
3263 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3264 return E_INVALIDARG
;
3265 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3266 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3267 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3270 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3271 if(*pcchPath
> lenA
) {
3272 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3276 *pcchPath
= lenA
+ 1;
3280 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3281 RtlFreeUnicodeString(&urlW
);
3285 /*************************************************************************
3286 * PathCreateFromUrlW [SHLWAPI.@]
3288 * Create a path from a URL
3291 * lpszUrl [I] URL to convert into a path
3292 * lpszPath [O] Output buffer for the resulting Path
3293 * pcchPath [I] Length of lpszPath
3294 * dwFlags [I] Flags controlling the conversion
3297 * Success: S_OK. lpszPath contains the URL in path format,
3298 * Failure: An HRESULT error code such as E_INVALIDARG.
3300 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3301 LPDWORD pcchPath
, DWORD dwReserved
)
3303 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3304 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3305 DWORD nslashes
, unescape
, len
;
3310 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3312 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3313 return E_INVALIDARG
;
3315 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3316 file_colon
, 5) != CSTR_EQUAL
)
3317 return E_INVALIDARG
;
3323 while (*src
== '/' || *src
== '\\') {
3328 /* We need a temporary buffer so we can compute what size to ask for.
3329 * We know that the final string won't be longer than the current pszUrl
3330 * plus at most two backslashes. All the other transformations make it
3333 len
= 2 + lstrlenW(pszUrl
) + 1;
3334 if (*pcchPath
< len
)
3335 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3345 /* 'file:' + escaped DOS path */
3348 /* 'file:/' + escaped DOS path */
3351 /* 'file:///' (implied localhost) + escaped DOS path */
3352 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3356 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, src
, 9,
3357 localhost
, 9) == CSTR_EQUAL
&&
3358 (src
[9] == '/' || src
[9] == '\\'))
3360 /* 'file://localhost/' + escaped DOS path */
3363 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3365 /* 'file://' + unescaped DOS path */
3370 /* 'file://hostname:port/path' (where path is escaped)
3371 * or 'file:' + escaped UNC path (\\server\share\path)
3372 * The second form is clearly specific to Windows and it might
3373 * even be doing a network lookup to try to figure it out.
3375 while (*src
&& *src
!= '/' && *src
!= '\\')
3378 StrCpyNW(dst
, pszUrl
, len
+ 1);
3380 if (isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3382 /* 'Forget' to add a trailing '/', just like Windows */
3388 /* 'file://' + unescaped UNC path (\\server\share\path) */
3390 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3394 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3398 /* Copy the remainder of the path */
3399 len
+= lstrlenW(src
);
3402 /* First do the Windows-specific path conversions */
3403 for (dst
= tpath
; *dst
; dst
++)
3404 if (*dst
== '/') *dst
= '\\';
3405 if (isalphaW(*tpath
) && tpath
[1] == '|')
3406 tpath
[1] = ':'; /* c| -> c: */
3408 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3411 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3414 /* When working in-place UrlUnescapeW() does not set len */
3415 len
= lstrlenW(tpath
);
3419 if (*pcchPath
< len
+ 1)
3422 *pcchPath
= len
+ 1;
3427 if (tpath
!= pszPath
)
3428 StrCpyW(pszPath
, tpath
);
3430 if (tpath
!= pszPath
)
3431 HeapFree(GetProcessHeap(), 0, tpath
);
3433 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3437 /*************************************************************************
3438 * PathCreateFromUrlAlloc [SHLWAPI.@]
3440 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3443 WCHAR pathW
[MAX_PATH
];
3448 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3451 /* Yes, this is supposed to crash if pszPath is NULL */
3452 *pszPath
= StrDupW(pathW
);
3457 /*************************************************************************
3458 * PathRelativePathToA [SHLWAPI.@]
3460 * Create a relative path from one path to another.
3463 * lpszPath [O] Destination for relative path
3464 * lpszFrom [I] Source path
3465 * dwAttrFrom [I] File attribute of source path
3466 * lpszTo [I] Destination path
3467 * dwAttrTo [I] File attributes of destination path
3470 * TRUE If a relative path can be formed. lpszPath contains the new path
3471 * FALSE If the paths are not relative or any parameters are invalid
3474 * lpszTo should be at least MAX_PATH in length.
3476 * Calling this function with relative paths for lpszFrom or lpszTo may
3477 * give erroneous results.
3479 * The Win32 version of this function contains a bug where the lpszTo string
3480 * may be referenced 1 byte beyond the end of the string. As a result random
3481 * garbage may be written to the output path, depending on what lies beyond
3482 * the last byte of the string. This bug occurs because of the behaviour of
3483 * PathCommonPrefix() (see notes for that function), and no workaround seems
3484 * possible with Win32.
3486 * This bug has been fixed here, so for example the relative path from "\\"
3487 * to "\\" is correctly determined as "." in this implementation.
3489 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3490 LPCSTR lpszTo
, DWORD dwAttrTo
)
3494 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3495 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3497 if(lpszPath
&& lpszFrom
&& lpszTo
)
3499 WCHAR szPath
[MAX_PATH
];
3500 WCHAR szFrom
[MAX_PATH
];
3501 WCHAR szTo
[MAX_PATH
];
3502 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3503 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3504 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3505 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3510 /*************************************************************************
3511 * PathRelativePathToW [SHLWAPI.@]
3513 * See PathRelativePathToA.
3515 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3516 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3518 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3519 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3520 WCHAR szFrom
[MAX_PATH
];
3521 WCHAR szTo
[MAX_PATH
];
3524 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3525 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3527 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3531 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3532 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3534 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3535 PathRemoveFileSpecW(szFrom
);
3536 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3537 PathRemoveFileSpecW(szTo
);
3539 /* Paths can only be relative if they have a common root */
3540 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3543 /* Strip off lpszFrom components to the root, by adding "..\" */
3544 lpszFrom
= szFrom
+ dwLen
;
3550 if (*lpszFrom
== '\\')
3555 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3556 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3559 /* From the root add the components of lpszTo */
3561 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3564 if (*lpszTo
&& lpszTo
[-1])
3566 if (*lpszTo
!= '\\')
3568 dwLen
= strlenW(lpszPath
);
3569 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3574 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3579 /*************************************************************************
3580 * PathUnmakeSystemFolderA [SHLWAPI.@]
3582 * Remove the system folder attributes from a path.
3585 * lpszPath [I] The path to remove attributes from
3589 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3590 * SetFileAttributesA() fails.
3592 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3596 TRACE("(%s)\n", debugstr_a(lpszPath
));
3598 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3599 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3602 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3603 return SetFileAttributesA(lpszPath
, dwAttr
);
3606 /*************************************************************************
3607 * PathUnmakeSystemFolderW [SHLWAPI.@]
3609 * See PathUnmakeSystemFolderA.
3611 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3615 TRACE("(%s)\n", debugstr_w(lpszPath
));
3617 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3618 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3621 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3622 return SetFileAttributesW(lpszPath
, dwAttr
);
3626 /*************************************************************************
3627 * PathSetDlgItemPathA [SHLWAPI.@]
3629 * Set the text of a dialog item to a path, shrinking the path to fit
3630 * if it is too big for the item.
3633 * hDlg [I] Dialog handle
3634 * id [I] ID of item in the dialog
3635 * lpszPath [I] Path to set as the items text
3641 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3642 * window text is erased).
3644 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3646 WCHAR szPath
[MAX_PATH
];
3648 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3651 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3654 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3657 /*************************************************************************
3658 * PathSetDlgItemPathW [SHLWAPI.@]
3660 * See PathSetDlgItemPathA.
3662 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3664 WCHAR path
[MAX_PATH
+ 1];
3670 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3672 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3676 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3680 GetClientRect(hwItem
, &rect
);
3682 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3686 PathCompactPathW(hdc
, path
, rect
.right
);
3687 SelectObject(hdc
, hPrevObj
);
3690 ReleaseDC(hDlg
, hdc
);
3691 SetWindowTextW(hwItem
, path
);
3694 /*************************************************************************
3695 * PathIsNetworkPathA [SHLWAPI.@]
3697 * Determine if the given path is a network path.
3700 * lpszPath [I] Path to check
3703 * TRUE If lpszPath is a UNC share or mapped network drive, or
3704 * FALSE If lpszPath is a local drive or cannot be determined
3706 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3710 TRACE("(%s)\n",debugstr_a(lpszPath
));
3714 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3716 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3717 if (dwDriveNum
== -1)
3719 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3720 return pIsNetDrive(dwDriveNum
);
3723 /*************************************************************************
3724 * PathIsNetworkPathW [SHLWAPI.@]
3726 * See PathIsNetworkPathA.
3728 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3732 TRACE("(%s)\n", debugstr_w(lpszPath
));
3736 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3738 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3739 if (dwDriveNum
== -1)
3741 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3742 return pIsNetDrive(dwDriveNum
);
3745 /*************************************************************************
3746 * PathIsLFNFileSpecA [SHLWAPI.@]
3748 * Determine if the given path is a long file name
3751 * lpszPath [I] Path to check
3754 * TRUE If path is a long file name,
3755 * FALSE If path is a valid DOS short file name
3757 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3759 DWORD dwNameLen
= 0, dwExtLen
= 0;
3761 TRACE("(%s)\n",debugstr_a(lpszPath
));
3768 if (*lpszPath
== ' ')
3769 return TRUE
; /* DOS names cannot have spaces */
3770 if (*lpszPath
== '.')
3773 return TRUE
; /* DOS names have only one dot */
3780 return TRUE
; /* DOS extensions are <= 3 chars*/
3786 return TRUE
; /* DOS names are <= 8 chars */
3788 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3790 return FALSE
; /* Valid DOS path */
3793 /*************************************************************************
3794 * PathIsLFNFileSpecW [SHLWAPI.@]
3796 * See PathIsLFNFileSpecA.
3798 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3800 DWORD dwNameLen
= 0, dwExtLen
= 0;
3802 TRACE("(%s)\n",debugstr_w(lpszPath
));
3809 if (*lpszPath
== ' ')
3810 return TRUE
; /* DOS names cannot have spaces */
3811 if (*lpszPath
== '.')
3814 return TRUE
; /* DOS names have only one dot */
3821 return TRUE
; /* DOS extensions are <= 3 chars*/
3827 return TRUE
; /* DOS names are <= 8 chars */
3831 return FALSE
; /* Valid DOS path */
3834 /*************************************************************************
3835 * PathIsDirectoryEmptyA [SHLWAPI.@]
3837 * Determine if a given directory is empty.
3840 * lpszPath [I] Directory to check
3843 * TRUE If the directory exists and contains no files,
3846 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3850 TRACE("(%s)\n",debugstr_a(lpszPath
));
3854 WCHAR szPath
[MAX_PATH
];
3855 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3856 bRet
= PathIsDirectoryEmptyW(szPath
);
3861 /*************************************************************************
3862 * PathIsDirectoryEmptyW [SHLWAPI.@]
3864 * See PathIsDirectoryEmptyA.
3866 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3868 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3869 WCHAR szSearch
[MAX_PATH
];
3872 BOOL retVal
= FALSE
;
3873 WIN32_FIND_DATAW find_data
;
3875 TRACE("(%s)\n",debugstr_w(lpszPath
));
3877 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3880 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3881 PathAddBackslashW(szSearch
);
3882 dwLen
= strlenW(szSearch
);
3883 if (dwLen
> MAX_PATH
- 4)
3886 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3887 hfind
= FindFirstFileW(szSearch
, &find_data
);
3889 if (hfind
!= INVALID_HANDLE_VALUE
&&
3890 find_data
.cFileName
[0] == '.' &&
3891 find_data
.cFileName
[1] == '.')
3893 /* The only directory entry should be the parent */
3894 if (!FindNextFileW(hfind
, &find_data
))
3902 /*************************************************************************
3903 * PathFindSuffixArrayA [SHLWAPI.@]
3905 * Find a suffix string in an array of suffix strings
3908 * lpszSuffix [I] Suffix string to search for
3909 * lppszArray [I] Array of suffix strings to search
3910 * dwCount [I] Number of elements in lppszArray
3913 * Success: The index of the position of lpszSuffix in lppszArray
3914 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3917 * The search is case sensitive.
3918 * The match is made against the end of the suffix string, so for example:
3919 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3921 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3926 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3928 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3930 dwLen
= strlen(lpszSuffix
);
3932 while (dwRet
< dwCount
)
3934 size_t dwCompareLen
= strlen(*lppszArray
);
3935 if (dwCompareLen
< dwLen
)
3937 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3938 return *lppszArray
; /* Found */
3947 /*************************************************************************
3948 * PathFindSuffixArrayW [SHLWAPI.@]
3950 * See PathFindSuffixArrayA.
3952 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3957 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3959 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3961 dwLen
= strlenW(lpszSuffix
);
3963 while (dwRet
< dwCount
)
3965 size_t dwCompareLen
= strlenW(*lppszArray
);
3966 if (dwCompareLen
< dwLen
)
3968 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3969 return *lppszArray
; /* Found */
3978 /*************************************************************************
3979 * PathUndecorateA [SHLWAPI.@]
3981 * Undecorate a file path
3984 * lpszPath [I/O] Path to remove any decoration from
3990 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3992 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3994 TRACE("(%s)\n",debugstr_a(lpszPath
));
3998 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3999 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4001 LPSTR lpszSkip
= lpszExt
- 2;
4002 if (*lpszSkip
== '[')
4003 lpszSkip
++; /* [] (no number) */
4005 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
4007 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4009 /* remove the [n] */
4012 *lpszSkip
++ = *lpszExt
++;
4019 /*************************************************************************
4020 * PathUndecorateW [SHLWAPI.@]
4022 * See PathUndecorateA.
4024 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4026 TRACE("(%s)\n",debugstr_w(lpszPath
));
4030 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4031 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4033 LPWSTR lpszSkip
= lpszExt
- 2;
4034 if (*lpszSkip
== '[')
4035 lpszSkip
++; /* [] (no number) */
4037 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4039 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4041 /* remove the [n] */
4044 *lpszSkip
++ = *lpszExt
++;
4051 /*************************************************************************
4052 * PathUnExpandEnvStringsA [SHLWAPI.@]
4054 * Substitute folder names in a path with their corresponding environment
4058 * path [I] Buffer containing the path to unexpand.
4059 * buffer [O] Buffer to receive the unexpanded path.
4060 * buf_len [I] Size of pszBuf in characters.
4066 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4068 WCHAR bufferW
[MAX_PATH
], *pathW
;
4072 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4074 pathW
= heap_strdupAtoW(path
);
4075 if (!pathW
) return FALSE
;
4077 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4078 HeapFree(GetProcessHeap(), 0, pathW
);
4079 if (!ret
) return FALSE
;
4081 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4082 if (buf_len
< len
+ 1) return FALSE
;
4084 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4088 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4089 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4090 static const WCHAR computernameW
[] = {'%','C','O','M','P','U','T','E','R','N','A','M','E','%',0};
4091 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4092 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4093 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4094 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4100 WCHAR path
[MAX_PATH
];
4104 static void init_envvars_map(struct envvars_map
*map
)
4108 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4109 /* exclude null from length */
4110 if (map
->len
) map
->len
--;
4115 /*************************************************************************
4116 * PathUnExpandEnvStringsW [SHLWAPI.@]
4118 * Unicode version of PathUnExpandEnvStringsA.
4120 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4122 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4123 struct envvars_map
*match
= &null_var
, *cur
;
4124 struct envvars_map envvars
[] = {
4125 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4126 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4127 { computernameW
, sizeof(computernameW
)/sizeof(WCHAR
) },
4128 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4129 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4130 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4131 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4137 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4139 pathlen
= strlenW(path
);
4140 init_envvars_map(envvars
);
4144 /* path can't contain expanded value or value wasn't retrieved */
4145 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4151 if (cur
->len
> match
->len
)
4156 /* 'varlen' includes NULL termination char */
4157 needed
= match
->varlen
+ pathlen
- match
->len
;
4158 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4160 strcpyW(buffer
, match
->var
);
4161 strcatW(buffer
, &path
[match
->len
]);
4162 TRACE("ret %s\n", debugstr_w(buffer
));
4167 /*************************************************************************
4170 * Find localised or default web content in "%WINDOWS%\web\".
4173 * lpszFile [I] File name containing content to look for
4174 * lpszPath [O] Buffer to contain the full path to the file
4175 * dwPathLen [I] Length of lpszPath
4178 * Success: S_OK. lpszPath contains the full path to the content.
4179 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4181 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4183 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4186 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4188 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4190 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4191 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4195 /*************************************************************************
4198 * Unicode version of SHGetWebFolderFilePathA.
4200 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4202 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4203 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4204 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4205 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4206 DWORD dwLen
, dwFileLen
;
4207 LANGID lidSystem
, lidUser
;
4209 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4211 /* Get base directory for web content */
4212 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4213 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4216 dwFileLen
= strlenW(lpszFile
);
4218 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4219 return E_FAIL
; /* lpszPath too short */
4221 strcpyW(lpszPath
+dwLen
, szWeb
);
4223 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4225 lidSystem
= GetSystemDefaultUILanguage();
4226 lidUser
= GetUserDefaultUILanguage();
4228 if (lidSystem
!= lidUser
)
4230 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4232 /* Use localised content in the users UI language if present */
4233 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4234 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4235 if (PathFileExistsW(lpszPath
))
4240 /* Fall back to OS default installed content */
4241 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4242 if (PathFileExistsW(lpszPath
))
4247 #define PATH_CHAR_CLASS_LETTER 0x00000001
4248 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4249 #define PATH_CHAR_CLASS_DOT 0x00000004
4250 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4251 #define PATH_CHAR_CLASS_COLON 0x00000010
4252 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4253 #define PATH_CHAR_CLASS_COMMA 0x00000040
4254 #define PATH_CHAR_CLASS_SPACE 0x00000080
4255 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4256 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4258 #define PATH_CHAR_CLASS_INVALID 0x00000000
4259 #define PATH_CHAR_CLASS_ANY 0xffffffff
4261 static const DWORD SHELL_charclass
[] =
4263 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4264 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4265 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4266 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4267 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4268 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4269 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4270 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4271 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4272 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4273 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4274 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4275 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4276 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4277 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4278 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4279 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4280 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4281 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4282 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4283 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4284 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4285 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4286 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4287 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4288 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4289 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4290 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4291 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4292 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4293 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4294 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
4295 /* '@' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'A' */ PATH_CHAR_CLASS_ANY
,
4296 /* 'B' */ PATH_CHAR_CLASS_ANY
, /* 'C' */ PATH_CHAR_CLASS_ANY
,
4297 /* 'D' */ PATH_CHAR_CLASS_ANY
, /* 'E' */ PATH_CHAR_CLASS_ANY
,
4298 /* 'F' */ PATH_CHAR_CLASS_ANY
, /* 'G' */ PATH_CHAR_CLASS_ANY
,
4299 /* 'H' */ PATH_CHAR_CLASS_ANY
, /* 'I' */ PATH_CHAR_CLASS_ANY
,
4300 /* 'J' */ PATH_CHAR_CLASS_ANY
, /* 'K' */ PATH_CHAR_CLASS_ANY
,
4301 /* 'L' */ PATH_CHAR_CLASS_ANY
, /* 'M' */ PATH_CHAR_CLASS_ANY
,
4302 /* 'N' */ PATH_CHAR_CLASS_ANY
, /* 'O' */ PATH_CHAR_CLASS_ANY
,
4303 /* 'P' */ PATH_CHAR_CLASS_ANY
, /* 'Q' */ PATH_CHAR_CLASS_ANY
,
4304 /* 'R' */ PATH_CHAR_CLASS_ANY
, /* 'S' */ PATH_CHAR_CLASS_ANY
,
4305 /* 'T' */ PATH_CHAR_CLASS_ANY
, /* 'U' */ PATH_CHAR_CLASS_ANY
,
4306 /* 'V' */ PATH_CHAR_CLASS_ANY
, /* 'W' */ PATH_CHAR_CLASS_ANY
,
4307 /* 'X' */ PATH_CHAR_CLASS_ANY
, /* 'Y' */ PATH_CHAR_CLASS_ANY
,
4308 /* 'Z' */ PATH_CHAR_CLASS_ANY
, /* '[' */ PATH_CHAR_CLASS_OTHER_VALID
,
4309 /* '\\' */ PATH_CHAR_CLASS_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4310 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4311 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4312 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4313 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4314 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4315 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4316 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4317 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4318 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4319 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4320 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4321 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4322 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4323 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4324 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4325 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4326 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4329 /*************************************************************************
4332 * Check if an ASCII char is of a certain class
4334 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4336 if ((unsigned)c
> 0x7e)
4337 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4339 return class & SHELL_charclass
[(unsigned)c
];
4342 /*************************************************************************
4345 * Check if a Unicode char is of a certain class
4347 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4350 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4352 return class & SHELL_charclass
[c
];