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
)
161 if (!MultiByteToWideChar(CP_ACP
,0,lpszDir
,-1,szDir
,MAX_PATH
))
165 if (!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))
177 /*************************************************************************
178 * PathCombineW [SHLWAPI.@]
182 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
184 WCHAR szTemp
[MAX_PATH
];
185 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
187 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
189 /* Invalid parameters */
192 if (!lpszDir
&& !lpszFile
)
198 if ((!lpszFile
|| !*lpszFile
) && lpszDir
)
201 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
203 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
205 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
208 lstrcpynW(szTemp
, lpszFile
, MAX_PATH
);
221 lstrcpynW(szTemp
, lpszDir
, MAX_PATH
);
224 PathStripToRootW(szTemp
);
225 lpszFile
++; /* Skip '\' */
227 if (!PathAddBackslashW(szTemp
) || strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
232 strcatW(szTemp
, lpszFile
);
235 PathCanonicalizeW(lpszDest
, szTemp
);
239 /*************************************************************************
240 * PathAddBackslashA [SHLWAPI.@]
242 * Append a backslash ('\') to a path if one doesn't exist.
245 * lpszPath [I/O] The path to append a backslash to.
248 * Success: The position of the last backslash in the path.
249 * Failure: NULL, if lpszPath is NULL or the path is too large.
251 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
254 LPSTR prev
= lpszPath
;
256 TRACE("(%s)\n",debugstr_a(lpszPath
));
258 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
264 lpszPath
= CharNextA(prev
);
277 /*************************************************************************
278 * PathAddBackslashW [SHLWAPI.@]
280 * See PathAddBackslashA.
282 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
286 TRACE("(%s)\n",debugstr_w(lpszPath
));
288 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
294 if (lpszPath
[-1] != '\\')
303 /*************************************************************************
304 * PathBuildRootA [SHLWAPI.@]
306 * Create a root drive string (e.g. "A:\") from a drive number.
309 * lpszPath [O] Destination for the drive string
315 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
317 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
319 TRACE("(%p,%d)\n", lpszPath
, drive
);
321 if (lpszPath
&& drive
>= 0 && drive
< 26)
323 lpszPath
[0] = 'A' + drive
;
331 /*************************************************************************
332 * PathBuildRootW [SHLWAPI.@]
334 * See PathBuildRootA.
336 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
338 TRACE("(%p,%d)\n", lpszPath
, drive
);
340 if (lpszPath
&& drive
>= 0 && drive
< 26)
342 lpszPath
[0] = 'A' + drive
;
350 /*************************************************************************
351 * PathFindFileNameA [SHLWAPI.@]
353 * Locate the start of the file name in a path
356 * lpszPath [I] Path to search
359 * A pointer to the first character of the file name
361 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
363 LPCSTR lastSlash
= lpszPath
;
365 TRACE("(%s)\n",debugstr_a(lpszPath
));
367 while (lpszPath
&& *lpszPath
)
369 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
370 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
371 lastSlash
= lpszPath
+ 1;
372 lpszPath
= CharNextA(lpszPath
);
374 return (LPSTR
)lastSlash
;
377 /*************************************************************************
378 * PathFindFileNameW [SHLWAPI.@]
380 * See PathFindFileNameA.
382 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
384 LPCWSTR lastSlash
= lpszPath
;
386 TRACE("(%s)\n",debugstr_w(lpszPath
));
388 while (lpszPath
&& *lpszPath
)
390 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
391 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
392 lastSlash
= lpszPath
+ 1;
395 return (LPWSTR
)lastSlash
;
398 /*************************************************************************
399 * PathFindExtensionA [SHLWAPI.@]
401 * Locate the start of the file extension in a path
404 * lpszPath [I] The path to search
407 * A pointer to the first character of the extension, the end of
408 * the string if the path has no extension, or NULL If lpszPath is NULL
410 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
412 LPCSTR lastpoint
= NULL
;
414 TRACE("(%s)\n", debugstr_a(lpszPath
));
420 if (*lpszPath
== '\\' || *lpszPath
==' ')
422 else if (*lpszPath
== '.')
423 lastpoint
= lpszPath
;
424 lpszPath
= CharNextA(lpszPath
);
427 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
430 /*************************************************************************
431 * PathFindExtensionW [SHLWAPI.@]
433 * See PathFindExtensionA.
435 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
437 LPCWSTR lastpoint
= NULL
;
439 TRACE("(%s)\n", debugstr_w(lpszPath
));
445 if (*lpszPath
== '\\' || *lpszPath
==' ')
447 else if (*lpszPath
== '.')
448 lastpoint
= lpszPath
;
452 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
455 /*************************************************************************
456 * PathGetArgsA [SHLWAPI.@]
458 * Find the next argument in a string delimited by spaces.
461 * lpszPath [I] The string to search for arguments in
464 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
467 * Spaces in quoted strings are ignored as delimiters.
469 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
471 BOOL bSeenQuote
= FALSE
;
473 TRACE("(%s)\n",debugstr_a(lpszPath
));
479 if ((*lpszPath
==' ') && !bSeenQuote
)
480 return (LPSTR
)lpszPath
+ 1;
481 if (*lpszPath
== '"')
482 bSeenQuote
= !bSeenQuote
;
483 lpszPath
= CharNextA(lpszPath
);
486 return (LPSTR
)lpszPath
;
489 /*************************************************************************
490 * PathGetArgsW [SHLWAPI.@]
494 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
496 BOOL bSeenQuote
= FALSE
;
498 TRACE("(%s)\n",debugstr_w(lpszPath
));
504 if ((*lpszPath
==' ') && !bSeenQuote
)
505 return (LPWSTR
)lpszPath
+ 1;
506 if (*lpszPath
== '"')
507 bSeenQuote
= !bSeenQuote
;
511 return (LPWSTR
)lpszPath
;
514 /*************************************************************************
515 * PathGetDriveNumberA [SHLWAPI.@]
517 * Return the drive number from a path
520 * lpszPath [I] Path to get the drive number from
523 * Success: The drive number corresponding to the drive in the path
524 * Failure: -1, if lpszPath contains no valid drive
526 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
528 TRACE ("(%s)\n",debugstr_a(lpszPath
));
530 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
531 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
532 return tolower(*lpszPath
) - 'a';
536 /*************************************************************************
537 * PathGetDriveNumberW [SHLWAPI.@]
539 * See PathGetDriveNumberA.
541 int WINAPI
PathGetDriveNumberW(const WCHAR
*path
)
545 static const WCHAR nt_prefixW
[] = {'\\','\\','?','\\'};
547 TRACE("(%s)\n", debugstr_w(path
));
552 if (!strncmpW(path
, nt_prefixW
, 4))
555 drive
= tolowerW(path
[0]);
556 if (drive
< 'a' || drive
> 'z' || path
[1] != ':')
562 /*************************************************************************
563 * PathRemoveFileSpecA [SHLWAPI.@]
565 * Remove the file specification from a path.
568 * lpszPath [I/O] Path to remove the file spec from
571 * TRUE If the path was valid and modified
574 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
576 LPSTR lpszFileSpec
= lpszPath
;
577 BOOL bModified
= FALSE
;
579 TRACE("(%s)\n",debugstr_a(lpszPath
));
583 /* Skip directory or UNC path */
584 if (*lpszPath
== '\\')
585 lpszFileSpec
= ++lpszPath
;
586 if (*lpszPath
== '\\')
587 lpszFileSpec
= ++lpszPath
;
591 if(*lpszPath
== '\\')
592 lpszFileSpec
= lpszPath
; /* Skip dir */
593 else if(*lpszPath
== ':')
595 lpszFileSpec
= ++lpszPath
; /* Skip drive */
596 if (*lpszPath
== '\\')
599 if (!(lpszPath
= CharNextA(lpszPath
)))
605 *lpszFileSpec
= '\0';
612 /*************************************************************************
613 * PathRemoveFileSpecW [SHLWAPI.@]
615 * See PathRemoveFileSpecA.
617 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
619 LPWSTR lpszFileSpec
= lpszPath
;
620 BOOL bModified
= FALSE
;
622 TRACE("(%s)\n",debugstr_w(lpszPath
));
626 /* Skip directory or UNC path */
627 if (*lpszPath
== '\\')
628 lpszFileSpec
= ++lpszPath
;
629 if (*lpszPath
== '\\')
630 lpszFileSpec
= ++lpszPath
;
634 if(*lpszPath
== '\\')
635 lpszFileSpec
= lpszPath
; /* Skip dir */
636 else if(*lpszPath
== ':')
638 lpszFileSpec
= ++lpszPath
; /* Skip drive */
639 if (*lpszPath
== '\\')
647 *lpszFileSpec
= '\0';
654 /*************************************************************************
655 * PathStripPathA [SHLWAPI.@]
657 * Remove the initial path from the beginning of a filename
660 * lpszPath [I/O] Path to remove the initial path from
665 void WINAPI
PathStripPathA(LPSTR lpszPath
)
667 TRACE("(%s)\n", debugstr_a(lpszPath
));
671 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
672 if(lpszFileName
!= lpszPath
)
673 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
677 /*************************************************************************
678 * PathStripPathW [SHLWAPI.@]
680 * See PathStripPathA.
682 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
686 TRACE("(%s)\n", debugstr_w(lpszPath
));
687 lpszFileName
= PathFindFileNameW(lpszPath
);
688 if(lpszFileName
!= lpszPath
)
689 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
692 /*************************************************************************
693 * PathStripToRootA [SHLWAPI.@]
695 * Reduce a path to its root.
698 * lpszPath [I/O] the path to reduce
701 * Success: TRUE if the stripped path is a root path
702 * Failure: FALSE if the path cannot be stripped or is NULL
704 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
706 TRACE("(%s)\n", debugstr_a(lpszPath
));
710 while(!PathIsRootA(lpszPath
))
711 if (!PathRemoveFileSpecA(lpszPath
))
716 /*************************************************************************
717 * PathStripToRootW [SHLWAPI.@]
719 * See PathStripToRootA.
721 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
723 TRACE("(%s)\n", debugstr_w(lpszPath
));
727 while(!PathIsRootW(lpszPath
))
728 if (!PathRemoveFileSpecW(lpszPath
))
733 /*************************************************************************
734 * PathRemoveArgsA [SHLWAPI.@]
736 * Strip space separated arguments from a path.
739 * lpszPath [I/O] Path to remove arguments from
744 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
746 TRACE("(%s)\n",debugstr_a(lpszPath
));
750 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
755 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
756 if(*lpszLastChar
== ' ')
757 *lpszLastChar
= '\0';
762 /*************************************************************************
763 * PathRemoveArgsW [SHLWAPI.@]
765 * See PathRemoveArgsA.
767 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
769 TRACE("(%s)\n",debugstr_w(lpszPath
));
773 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
774 if (*lpszArgs
|| (lpszArgs
> lpszPath
&& lpszArgs
[-1] == ' '))
779 /*************************************************************************
780 * PathRemoveExtensionA [SHLWAPI.@]
782 * Remove the file extension from a path
785 * lpszPath [I/O] Path to remove the extension from
788 * The NUL terminator must be written only if extension exists
789 * and if the pointed character is not already NUL.
794 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
796 TRACE("(%s)\n", debugstr_a(lpszPath
));
800 lpszPath
= PathFindExtensionA(lpszPath
);
801 if (lpszPath
&& *lpszPath
!= '\0')
806 /*************************************************************************
807 * PathRemoveExtensionW [SHLWAPI.@]
809 * See PathRemoveExtensionA.
811 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
813 TRACE("(%s)\n", debugstr_w(lpszPath
));
817 lpszPath
= PathFindExtensionW(lpszPath
);
818 if (lpszPath
&& *lpszPath
!= '\0')
823 /*************************************************************************
824 * PathRemoveBackslashA [SHLWAPI.@]
826 * Remove a trailing backslash from a path.
829 * lpszPath [I/O] Path to remove backslash from
832 * Success: A pointer to the end of the path
833 * Failure: NULL, if lpszPath is NULL
835 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
839 TRACE("(%s)\n", debugstr_a(lpszPath
));
843 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
844 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
850 /*************************************************************************
851 * PathRemoveBackslashW [SHLWAPI.@]
853 * See PathRemoveBackslashA.
855 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
857 LPWSTR szTemp
= NULL
;
859 TRACE("(%s)\n", debugstr_w(lpszPath
));
863 szTemp
= lpszPath
+ strlenW(lpszPath
);
864 if (szTemp
> lpszPath
) szTemp
--;
865 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
871 /*************************************************************************
872 * PathRemoveBlanksA [SHLWAPI.@]
874 * Remove Spaces from the start and end of a path.
877 * lpszPath [I/O] Path to strip blanks from
882 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
884 TRACE("(%s)\n", debugstr_a(lpszPath
));
886 if(lpszPath
&& *lpszPath
)
888 LPSTR start
= lpszPath
;
890 while (*lpszPath
== ' ')
891 lpszPath
= CharNextA(lpszPath
);
894 *start
++ = *lpszPath
++;
896 if (start
!= lpszPath
)
897 while (start
[-1] == ' ')
903 /*************************************************************************
904 * PathRemoveBlanksW [SHLWAPI.@]
906 * See PathRemoveBlanksA.
908 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
910 TRACE("(%s)\n", debugstr_w(lpszPath
));
912 if(lpszPath
&& *lpszPath
)
914 LPWSTR start
= lpszPath
;
916 while (*lpszPath
== ' ')
920 *start
++ = *lpszPath
++;
922 if (start
!= lpszPath
)
923 while (start
[-1] == ' ')
929 /*************************************************************************
930 * PathQuoteSpacesA [SHLWAPI.@]
932 * Surround a path containing spaces in quotes.
935 * lpszPath [I/O] Path to quote
941 * The path is not changed if it is invalid or has no spaces.
943 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
945 TRACE("(%s)\n", debugstr_a(lpszPath
));
947 if(lpszPath
&& StrChrA(lpszPath
,' '))
949 size_t iLen
= strlen(lpszPath
) + 1;
951 if (iLen
+ 2 < MAX_PATH
)
953 memmove(lpszPath
+ 1, lpszPath
, iLen
);
955 lpszPath
[iLen
] = '"';
956 lpszPath
[iLen
+ 1] = '\0';
961 /*************************************************************************
962 * PathQuoteSpacesW [SHLWAPI.@]
964 * See PathQuoteSpacesA.
966 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
968 TRACE("(%s)\n", debugstr_w(lpszPath
));
970 if(lpszPath
&& StrChrW(lpszPath
,' '))
972 int iLen
= strlenW(lpszPath
) + 1;
974 if (iLen
+ 2 < MAX_PATH
)
976 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
978 lpszPath
[iLen
] = '"';
979 lpszPath
[iLen
+ 1] = '\0';
984 /*************************************************************************
985 * PathUnquoteSpacesA [SHLWAPI.@]
987 * Remove quotes ("") from around a path, if present.
990 * lpszPath [I/O] Path to strip quotes from
996 * If the path contains a single quote only, an empty string will result.
997 * Otherwise quotes are only removed if they appear at the start and end
1000 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
1002 TRACE("(%s)\n", debugstr_a(lpszPath
));
1004 if (lpszPath
&& *lpszPath
== '"')
1006 DWORD dwLen
= strlen(lpszPath
) - 1;
1008 if (lpszPath
[dwLen
] == '"')
1010 lpszPath
[dwLen
] = '\0';
1011 for (; *lpszPath
; lpszPath
++)
1012 *lpszPath
= lpszPath
[1];
1017 /*************************************************************************
1018 * PathUnquoteSpacesW [SHLWAPI.@]
1020 * See PathUnquoteSpacesA.
1022 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
1024 TRACE("(%s)\n", debugstr_w(lpszPath
));
1026 if (lpszPath
&& *lpszPath
== '"')
1028 DWORD dwLen
= strlenW(lpszPath
) - 1;
1030 if (lpszPath
[dwLen
] == '"')
1032 lpszPath
[dwLen
] = '\0';
1033 for (; *lpszPath
; lpszPath
++)
1034 *lpszPath
= lpszPath
[1];
1039 /*************************************************************************
1040 * PathParseIconLocationA [SHLWAPI.@]
1042 * Parse the location of an icon from a path.
1045 * lpszPath [I/O] The path to parse the icon location from.
1048 * Success: The number of the icon
1049 * Failure: 0 if the path does not contain an icon location or is NULL
1052 * The path has surrounding quotes and spaces removed regardless
1053 * of whether the call succeeds or not.
1055 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1060 TRACE("(%s)\n", debugstr_a(lpszPath
));
1064 if ((lpszComma
= strchr(lpszPath
, ',')))
1066 *lpszComma
++ = '\0';
1067 iRet
= StrToIntA(lpszComma
);
1069 PathUnquoteSpacesA(lpszPath
);
1070 PathRemoveBlanksA(lpszPath
);
1075 /*************************************************************************
1076 * PathParseIconLocationW [SHLWAPI.@]
1078 * See PathParseIconLocationA.
1080 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1085 TRACE("(%s)\n", debugstr_w(lpszPath
));
1089 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1091 *lpszComma
++ = '\0';
1092 iRet
= StrToIntW(lpszComma
);
1094 PathUnquoteSpacesW(lpszPath
);
1095 PathRemoveBlanksW(lpszPath
);
1100 /*************************************************************************
1103 * Unicode version of PathFileExistsDefExtA.
1105 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1107 static const WCHAR pszExts
[][5] = { { '.', 'p', 'i', 'f', 0},
1108 { '.', 'c', 'o', 'm', 0},
1109 { '.', 'e', 'x', 'e', 0},
1110 { '.', 'b', 'a', 't', 0},
1111 { '.', 'l', 'n', 'k', 0},
1112 { '.', 'c', 'm', 'd', 0},
1115 TRACE("(%s,%d)\n", debugstr_w(lpszPath
), dwWhich
);
1117 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1122 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1123 if (!*szExt
|| dwWhich
& 0x40)
1126 int iLen
= lstrlenW(lpszPath
);
1127 if (iLen
> (MAX_PATH
- 5))
1129 while ( (dwWhich
& 0x1) && pszExts
[iChoose
][0] )
1131 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1132 if (PathFileExistsW(lpszPath
))
1137 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1141 return PathFileExistsW(lpszPath
);
1144 /*************************************************************************
1147 * Determine if a file exists locally and is of an executable type.
1150 * lpszPath [I/O] File to search for
1151 * dwWhich [I] Type of executable to search for
1154 * TRUE If the file was found. lpszPath contains the file name.
1158 * lpszPath is modified in place and must be at least MAX_PATH in length.
1159 * If the function returns FALSE, the path is modified to its original state.
1160 * If the given path contains an extension or dwWhich is 0, executable
1161 * extensions are not checked.
1163 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1164 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1165 * their own developers exclusive use. Monopoly, anyone?
1167 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1171 TRACE("(%s,%d)\n", debugstr_a(lpszPath
), dwWhich
);
1175 WCHAR szPath
[MAX_PATH
];
1176 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1177 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1179 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1184 /*************************************************************************
1185 * SHLWAPI_PathFindInOtherDirs
1187 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1189 static BOOL
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1191 static const WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1192 static const WCHAR szPath
[] = { 'P','A','T','H','\0'};
1196 WCHAR buff
[MAX_PATH
];
1198 TRACE("(%s,%08x)\n", debugstr_w(lpszFile
), dwWhich
);
1200 /* Try system directories */
1201 GetSystemDirectoryW(buff
, MAX_PATH
);
1202 if (!PathAppendW(buff
, lpszFile
))
1204 if (PathFileExistsDefExtW(buff
, dwWhich
))
1206 strcpyW(lpszFile
, buff
);
1209 GetWindowsDirectoryW(buff
, MAX_PATH
);
1210 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1212 if (PathFileExistsDefExtW(buff
, dwWhich
))
1214 strcpyW(lpszFile
, buff
);
1217 GetWindowsDirectoryW(buff
, MAX_PATH
);
1218 if (!PathAppendW(buff
, lpszFile
))
1220 if (PathFileExistsDefExtW(buff
, dwWhich
))
1222 strcpyW(lpszFile
, buff
);
1225 /* Try dirs listed in %PATH% */
1226 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1228 if (!dwLenPATH
|| !(lpszPATH
= HeapAlloc(GetProcessHeap(), 0, (dwLenPATH
+ 1) * sizeof (WCHAR
))))
1231 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1232 lpszCurr
= lpszPATH
;
1235 LPCWSTR lpszEnd
= lpszCurr
;
1236 LPWSTR pBuff
= buff
;
1238 while (*lpszEnd
== ' ')
1240 while (*lpszEnd
&& *lpszEnd
!= ';')
1241 *pBuff
++ = *lpszEnd
++;
1245 lpszCurr
= lpszEnd
+ 1;
1247 lpszCurr
= NULL
; /* Last Path, terminate after this */
1249 if (!PathAppendW(buff
, lpszFile
))
1251 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1254 if (PathFileExistsDefExtW(buff
, dwWhich
))
1256 strcpyW(lpszFile
, buff
);
1257 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1261 HeapFree(GetProcessHeap(), 0, lpszPATH
);
1265 /*************************************************************************
1268 * Search a range of paths for a specific type of executable.
1271 * lpszFile [I/O] File to search for
1272 * lppszOtherDirs [I] Other directories to look in
1273 * dwWhich [I] Type of executable to search for
1276 * Success: TRUE. The path to the executable is stored in lpszFile.
1277 * Failure: FALSE. The path to the executable is unchanged.
1279 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1281 WCHAR szFile
[MAX_PATH
];
1282 WCHAR buff
[MAX_PATH
];
1284 TRACE("(%s,%p,%08x)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1286 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1289 MultiByteToWideChar(CP_ACP
,0,lpszFile
,-1,szFile
,MAX_PATH
);
1291 /* Search provided directories first */
1292 if (lppszOtherDirs
&& *lppszOtherDirs
)
1294 WCHAR szOther
[MAX_PATH
];
1295 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1297 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1299 MultiByteToWideChar(CP_ACP
,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1300 PathCombineW(buff
, szOther
, szFile
);
1301 if (PathFileExistsDefExtW(buff
, dwWhich
))
1303 WideCharToMultiByte(CP_ACP
,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1309 /* Not found, try system and path dirs */
1310 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1312 WideCharToMultiByte(CP_ACP
,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1318 /*************************************************************************
1321 * Unicode version of PathFindOnPathExA.
1323 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1325 WCHAR buff
[MAX_PATH
];
1327 TRACE("(%s,%p,%08x)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1329 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1332 /* Search provided directories first */
1333 if (lppszOtherDirs
&& *lppszOtherDirs
)
1335 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1336 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1338 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1339 if (PathFileExistsDefExtW(buff
, dwWhich
))
1341 strcpyW(lpszFile
, buff
);
1347 /* Not found, try system and path dirs */
1348 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1351 /*************************************************************************
1352 * PathFindOnPathA [SHLWAPI.@]
1354 * Search a range of paths for an executable.
1357 * lpszFile [I/O] File to search for
1358 * lppszOtherDirs [I] Other directories to look in
1361 * Success: TRUE. The path to the executable is stored in lpszFile.
1362 * Failure: FALSE. The path to the executable is unchanged.
1364 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1366 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1367 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1370 /*************************************************************************
1371 * PathFindOnPathW [SHLWAPI.@]
1373 * See PathFindOnPathA.
1375 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1377 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1378 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1381 /*************************************************************************
1382 * PathCompactPathExA [SHLWAPI.@]
1384 * Compact a path into a given number of characters.
1387 * lpszDest [O] Destination for compacted path
1388 * lpszPath [I] Source path
1389 * cchMax [I] Maximum size of compacted path
1390 * dwFlags [I] Reserved
1393 * Success: TRUE. The compacted path is written to lpszDest.
1394 * Failure: FALSE. lpszPath is undefined.
1397 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1399 * The Win32 version of this function contains a bug: When cchMax == 7,
1400 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1403 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1404 * because Win32 will insert a "\" in lpszDest, even if one is
1405 * not present in the original path.
1407 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1408 UINT cchMax
, DWORD dwFlags
)
1412 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1414 if (lpszPath
&& lpszDest
)
1416 WCHAR szPath
[MAX_PATH
];
1417 WCHAR szDest
[MAX_PATH
];
1419 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
1421 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1422 WideCharToMultiByte(CP_ACP
,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1427 /*************************************************************************
1428 * PathCompactPathExW [SHLWAPI.@]
1430 * See PathCompactPathExA.
1432 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1433 UINT cchMax
, DWORD dwFlags
)
1435 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1437 DWORD dwLen
, dwFileLen
= 0;
1439 TRACE("(%p,%s,%d,0x%08x)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1446 WARN("Invalid lpszDest would crash under Win32!\n");
1455 dwLen
= strlenW(lpszPath
) + 1;
1459 /* Don't need to compact */
1460 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1464 /* Path must be compacted to fit into lpszDest */
1465 lpszFile
= PathFindFileNameW(lpszPath
);
1466 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1468 if (dwFileLen
== dwLen
)
1470 /* No root in psth */
1473 while (--cchMax
> 0) /* No room left for anything but ellipses */
1478 /* Compact the file name with ellipses at the end */
1480 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1481 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1484 /* We have a root in the path */
1485 lpszFile
--; /* Start compacted filename with the path separator */
1488 if (dwFileLen
+ 3 > cchMax
)
1490 /* Compact the file name */
1493 while (--cchMax
> 0) /* No room left for anything but ellipses */
1498 strcpyW(lpszDest
, szEllipses
);
1501 *lpszDest
++ = *lpszFile
++;
1504 while (--cchMax
> 0) /* No room left for anything but ellipses */
1510 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1511 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1515 /* Only the root needs to be Compacted */
1516 dwLen
= cchMax
- dwFileLen
- 3;
1517 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1518 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1519 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1523 /*************************************************************************
1524 * PathIsRelativeA [SHLWAPI.@]
1526 * Determine if a path is a relative path.
1529 * lpszPath [I] Path to check
1532 * TRUE: The path is relative, or is invalid.
1533 * FALSE: The path is not relative.
1535 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1537 TRACE("(%s)\n",debugstr_a(lpszPath
));
1539 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1541 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1546 /*************************************************************************
1547 * PathIsRelativeW [SHLWAPI.@]
1549 * See PathIsRelativeA.
1551 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1553 TRACE("(%s)\n",debugstr_w(lpszPath
));
1555 if (!lpszPath
|| !*lpszPath
)
1557 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1562 /*************************************************************************
1563 * PathIsRootA [SHLWAPI.@]
1565 * Determine if a path is a root path.
1568 * lpszPath [I] Path to check
1571 * TRUE If lpszPath is valid and a root path,
1574 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1576 TRACE("(%s)\n", debugstr_a(lpszPath
));
1578 if (lpszPath
&& *lpszPath
)
1580 if (*lpszPath
== '\\')
1583 return TRUE
; /* \ */
1584 else if (lpszPath
[1]=='\\')
1586 BOOL bSeenSlash
= FALSE
;
1589 /* Check for UNC root path */
1592 if (*lpszPath
== '\\')
1598 lpszPath
= CharNextA(lpszPath
);
1603 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1604 return TRUE
; /* X:\ */
1609 /*************************************************************************
1610 * PathIsRootW [SHLWAPI.@]
1614 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1616 TRACE("(%s)\n", debugstr_w(lpszPath
));
1618 if (lpszPath
&& *lpszPath
)
1620 if (*lpszPath
== '\\')
1623 return TRUE
; /* \ */
1624 else if (lpszPath
[1]=='\\')
1626 BOOL bSeenSlash
= FALSE
;
1629 /* Check for UNC root path */
1632 if (*lpszPath
== '\\')
1643 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1644 return TRUE
; /* X:\ */
1649 /*************************************************************************
1650 * PathIsDirectoryA [SHLWAPI.@]
1652 * Determine if a path is a valid directory
1655 * lpszPath [I] Path to check.
1658 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1659 * FALSE if lpszPath is invalid or not a directory.
1662 * Although this function is prototyped as returning a BOOL, it returns
1663 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1665 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1670 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1674 TRACE("(%s)\n", debugstr_a(lpszPath
));
1676 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1679 if (PathIsUNCServerShareA(lpszPath
))
1681 FIXME("UNC Server Share not yet supported - FAILING\n");
1685 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1687 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1690 /*************************************************************************
1691 * PathIsDirectoryW [SHLWAPI.@]
1693 * See PathIsDirectoryA.
1695 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1699 TRACE("(%s)\n", debugstr_w(lpszPath
));
1701 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1704 if (PathIsUNCServerShareW(lpszPath
))
1706 FIXME("UNC Server Share not yet supported - FAILING\n");
1710 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1712 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1715 /*************************************************************************
1716 * PathFileExistsA [SHLWAPI.@]
1718 * Determine if a file exists.
1721 * lpszPath [I] Path to check
1724 * TRUE If the file exists and is readable
1727 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1732 TRACE("(%s)\n",debugstr_a(lpszPath
));
1737 /* Prevent a dialog box if path is on a disk that has been ejected. */
1738 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1739 dwAttr
= GetFileAttributesA(lpszPath
);
1740 SetErrorMode(iPrevErrMode
);
1741 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1744 /*************************************************************************
1745 * PathFileExistsW [SHLWAPI.@]
1747 * See PathFileExistsA.
1749 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1754 TRACE("(%s)\n",debugstr_w(lpszPath
));
1759 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1760 dwAttr
= GetFileAttributesW(lpszPath
);
1761 SetErrorMode(iPrevErrMode
);
1762 return dwAttr
!= INVALID_FILE_ATTRIBUTES
;
1765 /*************************************************************************
1766 * PathFileExistsAndAttributesA [SHLWAPI.445]
1768 * Determine if a file exists.
1771 * lpszPath [I] Path to check
1772 * dwAttr [O] attributes of file
1775 * TRUE If the file exists and is readable
1778 BOOL WINAPI
PathFileExistsAndAttributesA(LPCSTR lpszPath
, DWORD
*dwAttr
)
1783 TRACE("(%s %p)\n", debugstr_a(lpszPath
), dwAttr
);
1786 *dwAttr
= INVALID_FILE_ATTRIBUTES
;
1791 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1792 dwVal
= GetFileAttributesA(lpszPath
);
1793 SetErrorMode(iPrevErrMode
);
1796 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1799 /*************************************************************************
1800 * PathFileExistsAndAttributesW [SHLWAPI.446]
1802 * See PathFileExistsA.
1804 BOOL WINAPI
PathFileExistsAndAttributesW(LPCWSTR lpszPath
, DWORD
*dwAttr
)
1809 TRACE("(%s %p)\n", debugstr_w(lpszPath
), dwAttr
);
1814 iPrevErrMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
1815 dwVal
= GetFileAttributesW(lpszPath
);
1816 SetErrorMode(iPrevErrMode
);
1819 return (dwVal
!= INVALID_FILE_ATTRIBUTES
);
1822 /*************************************************************************
1823 * PathMatchSingleMaskA [internal]
1825 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1827 while (*name
&& *mask
&& *mask
!=';')
1833 if (PathMatchSingleMaskA(name
,mask
+1))
1834 return TRUE
; /* try substrings */
1839 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1842 name
= CharNextA(name
);
1843 mask
= CharNextA(mask
);
1848 while (*mask
== '*')
1850 if (!*mask
|| *mask
== ';')
1856 /*************************************************************************
1857 * PathMatchSingleMaskW [internal]
1859 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1861 while (*name
&& *mask
&& *mask
!= ';')
1867 if (PathMatchSingleMaskW(name
,mask
+1))
1868 return TRUE
; /* try substrings */
1873 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1881 while (*mask
== '*')
1883 if (!*mask
|| *mask
== ';')
1889 /*************************************************************************
1890 * PathMatchSpecA [SHLWAPI.@]
1892 * Determine if a path matches one or more search masks.
1895 * lpszPath [I] Path to check
1896 * lpszMask [I] Search mask(s)
1899 * TRUE If lpszPath is valid and is matched
1903 * Multiple search masks may be given if they are separated by ";". The
1904 * pattern "*.*" is treated specially in that it matches all paths (for
1905 * backwards compatibility with DOS).
1907 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1909 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1911 if (!lstrcmpA(lpszMask
, "*.*"))
1912 return TRUE
; /* Matches every path */
1916 while (*lpszMask
== ' ')
1917 lpszMask
++; /* Eat leading spaces */
1919 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1920 return TRUE
; /* Matches the current mask */
1922 while (*lpszMask
&& *lpszMask
!= ';')
1923 lpszMask
= CharNextA(lpszMask
); /* masks separated by ';' */
1925 if (*lpszMask
== ';')
1931 /*************************************************************************
1932 * PathMatchSpecW [SHLWAPI.@]
1934 * See PathMatchSpecA.
1936 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1938 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1940 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1942 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1943 return TRUE
; /* Matches every path */
1947 while (*lpszMask
== ' ')
1948 lpszMask
++; /* Eat leading spaces */
1950 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1951 return TRUE
; /* Matches the current path */
1953 while (*lpszMask
&& *lpszMask
!= ';')
1954 lpszMask
++; /* masks separated by ';' */
1956 if (*lpszMask
== ';')
1962 /*************************************************************************
1963 * PathIsSameRootA [SHLWAPI.@]
1965 * Determine if two paths share the same root.
1968 * lpszPath1 [I] Source path
1969 * lpszPath2 [I] Path to compare with
1972 * TRUE If both paths are valid and share the same root.
1973 * FALSE If either path is invalid or the paths do not share the same root.
1975 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1980 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1982 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1985 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1986 if (lpszStart
- lpszPath1
> dwLen
)
1987 return FALSE
; /* Paths not common up to length of the root */
1991 /*************************************************************************
1992 * PathIsSameRootW [SHLWAPI.@]
1994 * See PathIsSameRootA.
1996 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
2001 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
2003 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
2006 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
2007 if (lpszStart
- lpszPath1
> dwLen
)
2008 return FALSE
; /* Paths not common up to length of the root */
2012 /*************************************************************************
2013 * PathIsContentTypeA [SHLWAPI.@]
2015 * Determine if a file is of a given registered content type.
2018 * lpszPath [I] File to check
2019 * lpszContentType [I] Content type to check for
2022 * TRUE If lpszPath is a given registered content type,
2026 * This function looks up the registered content type for lpszPath. If
2027 * a content type is registered, it is compared (case insensitively) to
2028 * lpszContentType. Only if this matches does the function succeed.
2030 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
2034 char szBuff
[MAX_PATH
];
2036 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
2038 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
2039 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
2040 REG_NONE
, szBuff
, &dwDummy
) &&
2041 !strcasecmp(lpszContentType
, szBuff
))
2048 /*************************************************************************
2049 * PathIsContentTypeW [SHLWAPI.@]
2051 * See PathIsContentTypeA.
2053 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
2055 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
2058 WCHAR szBuff
[MAX_PATH
];
2060 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
2062 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
2063 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
2064 REG_NONE
, szBuff
, &dwDummy
) &&
2065 !strcmpiW(lpszContentType
, szBuff
))
2072 /*************************************************************************
2073 * PathIsFileSpecA [SHLWAPI.@]
2075 * Determine if a path is a file specification.
2078 * lpszPath [I] Path to check
2081 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
2084 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
2086 TRACE("(%s)\n", debugstr_a(lpszPath
));
2093 if (*lpszPath
== '\\' || *lpszPath
== ':')
2095 lpszPath
= CharNextA(lpszPath
);
2100 /*************************************************************************
2101 * PathIsFileSpecW [SHLWAPI.@]
2103 * See PathIsFileSpecA.
2105 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2107 TRACE("(%s)\n", debugstr_w(lpszPath
));
2114 if (*lpszPath
== '\\' || *lpszPath
== ':')
2121 /*************************************************************************
2122 * PathIsPrefixA [SHLWAPI.@]
2124 * Determine if a path is a prefix of another.
2127 * lpszPrefix [I] Prefix
2128 * lpszPath [I] Path to check
2131 * TRUE If lpszPath has lpszPrefix as its prefix,
2132 * FALSE If either path is NULL or lpszPrefix is not a prefix
2134 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2136 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2138 if (lpszPrefix
&& lpszPath
&&
2139 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2144 /*************************************************************************
2145 * PathIsPrefixW [SHLWAPI.@]
2147 * See PathIsPrefixA.
2149 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2151 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2153 if (lpszPrefix
&& lpszPath
&&
2154 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2159 /*************************************************************************
2160 * PathIsSystemFolderA [SHLWAPI.@]
2162 * Determine if a path or file attributes are a system folder.
2165 * lpszPath [I] Path to check.
2166 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2169 * TRUE If lpszPath or dwAttrib are a system folder.
2170 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2172 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2174 TRACE("(%s,0x%08x)\n", debugstr_a(lpszPath
), dwAttrib
);
2176 if (lpszPath
&& *lpszPath
)
2177 dwAttrib
= GetFileAttributesA(lpszPath
);
2179 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2180 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2185 /*************************************************************************
2186 * PathIsSystemFolderW [SHLWAPI.@]
2188 * See PathIsSystemFolderA.
2190 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2192 TRACE("(%s,0x%08x)\n", debugstr_w(lpszPath
), dwAttrib
);
2194 if (lpszPath
&& *lpszPath
)
2195 dwAttrib
= GetFileAttributesW(lpszPath
);
2197 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2198 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2203 /*************************************************************************
2204 * PathIsUNCA [SHLWAPI.@]
2206 * Determine if a path is in UNC format.
2209 * lpszPath [I] Path to check
2212 * TRUE: The path is UNC.
2213 * FALSE: The path is not UNC or is NULL.
2215 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2217 TRACE("(%s)\n",debugstr_a(lpszPath
));
2219 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2224 /*************************************************************************
2225 * PathIsUNCW [SHLWAPI.@]
2229 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2231 TRACE("(%s)\n",debugstr_w(lpszPath
));
2233 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2238 /*************************************************************************
2239 * PathIsUNCServerA [SHLWAPI.@]
2241 * Determine if a path is a UNC server name ("\\SHARENAME").
2244 * lpszPath [I] Path to check.
2247 * TRUE If lpszPath is a valid UNC server name.
2251 * This routine is bug compatible with Win32: Server names with a
2252 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2253 * Fixing this bug may break other shlwapi functions!
2255 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2257 TRACE("(%s)\n", debugstr_a(lpszPath
));
2259 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2263 if (*lpszPath
== '\\')
2265 lpszPath
= CharNextA(lpszPath
);
2272 /*************************************************************************
2273 * PathIsUNCServerW [SHLWAPI.@]
2275 * See PathIsUNCServerA.
2277 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2279 TRACE("(%s)\n", debugstr_w(lpszPath
));
2281 if (lpszPath
&& lpszPath
[0] == '\\' && lpszPath
[1] == '\\')
2283 return !strchrW( lpszPath
+ 2, '\\' );
2288 /*************************************************************************
2289 * PathIsUNCServerShareA [SHLWAPI.@]
2291 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2294 * lpszPath [I] Path to check.
2297 * TRUE If lpszPath is a valid UNC server share.
2301 * This routine is bug compatible with Win32: Server shares with a
2302 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2303 * Fixing this bug may break other shlwapi functions!
2305 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2307 TRACE("(%s)\n", debugstr_a(lpszPath
));
2309 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2311 BOOL bSeenSlash
= FALSE
;
2314 if (*lpszPath
== '\\')
2320 lpszPath
= CharNextA(lpszPath
);
2327 /*************************************************************************
2328 * PathIsUNCServerShareW [SHLWAPI.@]
2330 * See PathIsUNCServerShareA.
2332 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2334 TRACE("(%s)\n", debugstr_w(lpszPath
));
2336 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2338 BOOL bSeenSlash
= FALSE
;
2341 if (*lpszPath
== '\\')
2354 /*************************************************************************
2355 * PathCanonicalizeA [SHLWAPI.@]
2357 * Convert a path to its canonical form.
2360 * lpszBuf [O] Output path
2361 * lpszPath [I] Path to canonicalize
2364 * Success: TRUE. lpszBuf contains the output path,
2365 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2367 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2371 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2376 if (!lpszBuf
|| !lpszPath
)
2377 SetLastError(ERROR_INVALID_PARAMETER
);
2380 WCHAR szPath
[MAX_PATH
];
2381 WCHAR szBuff
[MAX_PATH
];
2382 int ret
= MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2385 WARN("Failed to convert string to widechar (too long?), LE %d.\n", GetLastError());
2388 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2389 WideCharToMultiByte(CP_ACP
,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2395 /*************************************************************************
2396 * PathCanonicalizeW [SHLWAPI.@]
2398 * See PathCanonicalizeA.
2400 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2402 LPWSTR lpszDst
= lpszBuf
;
2403 LPCWSTR lpszSrc
= lpszPath
;
2405 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2410 if (!lpszBuf
|| !lpszPath
)
2412 SetLastError(ERROR_INVALID_PARAMETER
);
2423 /* Copy path root */
2424 if (*lpszSrc
== '\\')
2426 *lpszDst
++ = *lpszSrc
++;
2428 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2431 *lpszDst
++ = *lpszSrc
++;
2432 *lpszDst
++ = *lpszSrc
++;
2433 if (*lpszSrc
== '\\')
2434 *lpszDst
++ = *lpszSrc
++;
2437 /* Canonicalize the rest of the path */
2440 if (*lpszSrc
== '.')
2442 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2444 lpszSrc
+= 2; /* Skip .\ */
2446 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2448 /* \.. backs up a directory, over the root if it has no \ following X:.
2449 * .. is ignored if it would remove a UNC server name or initial \\
2451 if (lpszDst
!= lpszBuf
)
2453 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2454 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2455 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2457 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2460 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2462 if (*lpszDst
== '\\')
2463 lpszDst
++; /* Reset to last '\' */
2465 lpszDst
= lpszBuf
; /* Start path again from new root */
2467 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2470 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2472 if (lpszDst
== lpszBuf
)
2478 lpszSrc
+= 2; /* Skip .. in src path */
2481 *lpszDst
++ = *lpszSrc
++;
2484 *lpszDst
++ = *lpszSrc
++;
2486 /* Append \ to naked drive specs */
2487 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2493 /*************************************************************************
2494 * PathFindNextComponentA [SHLWAPI.@]
2496 * Find the next component in a path.
2499 * lpszPath [I] Path to find next component in
2502 * Success: A pointer to the next component, or the end of the string.
2503 * Failure: NULL, If lpszPath is invalid
2506 * A 'component' is either a backslash character (\) or UNC marker (\\).
2507 * Because of this, relative paths (e.g "c:foo") are regarded as having
2508 * only one component.
2510 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2514 TRACE("(%s)\n", debugstr_a(lpszPath
));
2516 if(!lpszPath
|| !*lpszPath
)
2519 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2521 if (lpszSlash
[1] == '\\')
2523 return lpszSlash
+ 1;
2525 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2528 /*************************************************************************
2529 * PathFindNextComponentW [SHLWAPI.@]
2531 * See PathFindNextComponentA.
2533 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2537 TRACE("(%s)\n", debugstr_w(lpszPath
));
2539 if(!lpszPath
|| !*lpszPath
)
2542 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2544 if (lpszSlash
[1] == '\\')
2546 return lpszSlash
+ 1;
2548 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2551 /*************************************************************************
2552 * PathAddExtensionA [SHLWAPI.@]
2554 * Add a file extension to a path
2557 * lpszPath [I/O] Path to add extension to
2558 * lpszExtension [I] Extension to add to lpszPath
2561 * TRUE If the path was modified,
2562 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2563 * extension already, or the new path length is too big.
2566 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2567 * does not do this, so the behaviour was removed.
2569 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2573 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2575 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2578 dwLen
= strlen(lpszPath
);
2580 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2583 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2587 /*************************************************************************
2588 * PathAddExtensionW [SHLWAPI.@]
2590 * See PathAddExtensionA.
2592 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2596 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2598 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2601 dwLen
= strlenW(lpszPath
);
2603 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2606 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2610 /*************************************************************************
2611 * PathMakePrettyA [SHLWAPI.@]
2613 * Convert an uppercase DOS filename into lowercase.
2616 * lpszPath [I/O] Path to convert.
2619 * TRUE If the path was an uppercase DOS path and was converted,
2622 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2624 LPSTR pszIter
= lpszPath
;
2626 TRACE("(%s)\n", debugstr_a(lpszPath
));
2635 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2636 return FALSE
; /* Not DOS path */
2639 pszIter
= lpszPath
+ 1;
2642 *pszIter
= tolower(*pszIter
);
2649 /*************************************************************************
2650 * PathMakePrettyW [SHLWAPI.@]
2652 * See PathMakePrettyA.
2654 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2656 LPWSTR pszIter
= lpszPath
;
2658 TRACE("(%s)\n", debugstr_w(lpszPath
));
2667 if (islowerW(*pszIter
))
2668 return FALSE
; /* Not DOS path */
2671 pszIter
= lpszPath
+ 1;
2674 *pszIter
= tolowerW(*pszIter
);
2681 /*************************************************************************
2682 * PathCommonPrefixA [SHLWAPI.@]
2684 * Determine the length of the common prefix between two paths.
2687 * lpszFile1 [I] First path for comparison
2688 * lpszFile2 [I] Second path for comparison
2689 * achPath [O] Destination for common prefix string
2692 * The length of the common prefix. This is 0 if there is no common
2693 * prefix between the paths or if any parameters are invalid. If the prefix
2694 * is non-zero and achPath is not NULL, achPath is filled with the common
2695 * part of the prefix and NUL terminated.
2698 * A common prefix of 2 is always returned as 3. It is thus possible for
2699 * the length returned to be invalid (i.e. Longer than one or both of the
2700 * strings given as parameters). This Win32 behaviour has been implemented
2701 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2702 * To work around this when using this function, always check that the byte
2703 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2705 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2708 LPCSTR lpszIter1
= lpszFile1
;
2709 LPCSTR lpszIter2
= lpszFile2
;
2711 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2716 if (!lpszFile1
|| !lpszFile2
)
2719 /* Handle roots first */
2720 if (PathIsUNCA(lpszFile1
))
2722 if (!PathIsUNCA(lpszFile2
))
2727 else if (PathIsUNCA(lpszFile2
))
2728 return 0; /* Know already lpszFile1 is not UNC */
2733 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2734 (!*lpszIter2
|| *lpszIter2
== '\\'))
2735 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2737 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2738 break; /* Strings differ at this point */
2745 iLen
++; /* Feature/Bug compatible with Win32 */
2747 if (iLen
&& achPath
)
2749 memcpy(achPath
,lpszFile1
,iLen
);
2750 achPath
[iLen
] = '\0';
2755 /*************************************************************************
2756 * PathCommonPrefixW [SHLWAPI.@]
2758 * See PathCommonPrefixA.
2760 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2763 LPCWSTR lpszIter1
= lpszFile1
;
2764 LPCWSTR lpszIter2
= lpszFile2
;
2766 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2771 if (!lpszFile1
|| !lpszFile2
)
2774 /* Handle roots first */
2775 if (PathIsUNCW(lpszFile1
))
2777 if (!PathIsUNCW(lpszFile2
))
2782 else if (PathIsUNCW(lpszFile2
))
2783 return 0; /* Know already lpszFile1 is not UNC */
2788 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2789 (!*lpszIter2
|| *lpszIter2
== '\\'))
2790 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2792 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2793 break; /* Strings differ at this point */
2800 iLen
++; /* Feature/Bug compatible with Win32 */
2802 if (iLen
&& achPath
)
2804 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2805 achPath
[iLen
] = '\0';
2810 /*************************************************************************
2811 * PathCompactPathA [SHLWAPI.@]
2813 * Make a path fit into a given width when printed to a DC.
2816 * hDc [I] Destination DC
2817 * lpszPath [I/O] Path to be printed to hDc
2818 * dx [I] Desired width
2821 * TRUE If the path was modified/went well.
2824 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2828 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2832 WCHAR szPath
[MAX_PATH
];
2833 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
2834 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2835 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2840 /*************************************************************************
2841 * PathCompactPathW [SHLWAPI.@]
2843 * See PathCompactPathA.
2845 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2847 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2850 WCHAR buff
[MAX_PATH
];
2854 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2860 hdc
= hDC
= GetDC(0);
2862 /* Get the length of the whole path */
2863 dwLen
= strlenW(lpszPath
);
2864 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2866 if ((UINT
)size
.cx
> dx
)
2868 /* Path too big, must reduce it */
2870 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2872 sFile
= PathFindFileNameW(lpszPath
);
2873 if (sFile
!= lpszPath
) sFile
--;
2875 /* Get the size of ellipses */
2876 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2877 dwEllipsesLen
= size
.cx
;
2878 /* Get the size of the file name */
2879 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2880 dwPathLen
= size
.cx
;
2882 if (sFile
!= lpszPath
)
2884 LPWSTR sPath
= sFile
;
2885 BOOL bEllipses
= FALSE
;
2887 /* The path includes a file name. Include as much of the path prior to
2888 * the file name as possible, allowing for the ellipses, e.g:
2889 * c:\some very long path\filename ==> c:\some v...\filename
2891 lstrcpynW(buff
, sFile
, MAX_PATH
);
2895 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2897 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2898 dwTotalLen
+= size
.cx
;
2899 if (dwTotalLen
<= dx
)
2907 } while (sPath
> lpszPath
);
2909 if (sPath
> lpszPath
)
2913 strcpyW(sPath
, szEllipses
);
2914 strcpyW(sPath
+3, buff
);
2919 strcpyW(lpszPath
, szEllipses
);
2920 strcpyW(lpszPath
+3, buff
);
2925 /* Trim the path by adding ellipses to the end, e.g:
2926 * A very long file name.txt ==> A very...
2928 dwLen
= strlenW(lpszPath
);
2930 if (dwLen
> MAX_PATH
- 3)
2931 dwLen
= MAX_PATH
- 3;
2932 lstrcpynW(buff
, sFile
, dwLen
);
2936 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2937 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2941 DWORD dwWritten
= 0;
2943 dwEllipsesLen
/= 3; /* Size of a single '.' */
2945 /* Write as much of the Ellipses string as possible */
2946 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2949 dwWritten
+= dwEllipsesLen
;
2957 strcpyW(buff
+ dwLen
, szEllipses
);
2958 strcpyW(lpszPath
, buff
);
2969 /*************************************************************************
2970 * PathGetCharTypeA [SHLWAPI.@]
2972 * Categorise a character from a file path.
2975 * ch [I] Character to get the type of
2978 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2980 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2982 return PathGetCharTypeW(ch
);
2985 /*************************************************************************
2986 * PathGetCharTypeW [SHLWAPI.@]
2988 * See PathGetCharTypeA.
2990 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2994 TRACE("(%d)\n", ch
);
2996 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2997 ch
== '"' || ch
== '|' || ch
== '/')
2998 flags
= GCT_INVALID
; /* Invalid */
2999 else if (ch
== '*' || ch
=='?')
3000 flags
= GCT_WILD
; /* Wildchars */
3001 else if ((ch
== '\\') || (ch
== ':'))
3002 return GCT_SEPARATOR
; /* Path separators */
3007 if (((ch
& 0x1) && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
3008 ch
== '.' || ch
== '@' || ch
== '^' ||
3009 ch
== '\'' || ch
== 130 || ch
== '`')
3010 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
3013 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
3014 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
3019 /*************************************************************************
3020 * SHLWAPI_UseSystemForSystemFolders
3022 * Internal helper for PathMakeSystemFolderW.
3024 static BOOL
SHLWAPI_UseSystemForSystemFolders(void)
3026 static BOOL bCheckedReg
= FALSE
;
3027 static BOOL bUseSystemForSystemFolders
= FALSE
;
3033 /* Key tells Win what file attributes to use on system folders */
3034 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
3035 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
3036 "UseSystemForSystemFolders", 0, 0, 0))
3037 bUseSystemForSystemFolders
= TRUE
;
3039 return bUseSystemForSystemFolders
;
3042 /*************************************************************************
3043 * PathMakeSystemFolderA [SHLWAPI.@]
3045 * Set system folder attribute for a path.
3048 * lpszPath [I] The path to turn into a system folder
3051 * TRUE If the path was changed to/already was a system folder
3052 * FALSE If the path is invalid or SetFileAttributesA() fails
3054 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
3058 TRACE("(%s)\n", debugstr_a(lpszPath
));
3060 if (lpszPath
&& *lpszPath
)
3062 WCHAR szPath
[MAX_PATH
];
3063 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3064 bRet
= PathMakeSystemFolderW(szPath
);
3069 /*************************************************************************
3070 * PathMakeSystemFolderW [SHLWAPI.@]
3072 * See PathMakeSystemFolderA.
3074 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
3076 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
3077 WCHAR buff
[MAX_PATH
];
3079 TRACE("(%s)\n", debugstr_w(lpszPath
));
3081 if (!lpszPath
|| !*lpszPath
)
3084 /* If the directory is already a system directory, don't do anything */
3085 GetSystemDirectoryW(buff
, MAX_PATH
);
3086 if (!strcmpW(buff
, lpszPath
))
3089 GetWindowsDirectoryW(buff
, MAX_PATH
);
3090 if (!strcmpW(buff
, lpszPath
))
3093 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
3094 if (SHLWAPI_UseSystemForSystemFolders())
3095 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
3097 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
3100 /* Change file attributes to system attributes */
3101 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
3102 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
3105 /*************************************************************************
3106 * PathRenameExtensionA [SHLWAPI.@]
3108 * Swap the file extension in a path with another extension.
3111 * lpszPath [I/O] Path to swap the extension in
3112 * lpszExt [I] The new extension
3115 * TRUE if lpszPath was modified,
3116 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3118 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3120 LPSTR lpszExtension
;
3122 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3124 lpszExtension
= PathFindExtensionA(lpszPath
);
3126 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3129 strcpy(lpszExtension
, lpszExt
);
3133 /*************************************************************************
3134 * PathRenameExtensionW [SHLWAPI.@]
3136 * See PathRenameExtensionA.
3138 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3140 LPWSTR lpszExtension
;
3142 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3144 lpszExtension
= PathFindExtensionW(lpszPath
);
3146 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3149 strcpyW(lpszExtension
, lpszExt
);
3153 /*************************************************************************
3154 * PathSearchAndQualifyA [SHLWAPI.@]
3156 * Determine if a given path is correct and fully qualified.
3159 * lpszPath [I] Path to check
3160 * lpszBuf [O] Output for correct path
3161 * cchBuf [I] Size of lpszBuf
3166 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3168 TRACE("(%s,%p,0x%08x)\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3170 if(SearchPathA(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3172 return !!GetFullPathNameA(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3175 /*************************************************************************
3176 * PathSearchAndQualifyW [SHLWAPI.@]
3178 * See PathSearchAndQualifyA.
3180 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3182 TRACE("(%s,%p,0x%08x)\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3184 if(SearchPathW(NULL
, lpszPath
, NULL
, cchBuf
, lpszBuf
, NULL
))
3186 return !!GetFullPathNameW(lpszPath
, cchBuf
, lpszBuf
, NULL
);
3189 /*************************************************************************
3190 * PathSkipRootA [SHLWAPI.@]
3192 * Return the portion of a path following the drive letter or mount point.
3195 * lpszPath [I] The path to skip on
3198 * Success: A pointer to the next character after the root.
3199 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3201 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3203 TRACE("(%s)\n", debugstr_a(lpszPath
));
3205 if (!lpszPath
|| !*lpszPath
)
3208 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3210 /* Network share: skip share server and mount point */
3212 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3213 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3215 return (LPSTR
)lpszPath
;
3218 if (IsDBCSLeadByte(*lpszPath
))
3222 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3223 return (LPSTR
)lpszPath
+ 3;
3227 /*************************************************************************
3228 * PathSkipRootW [SHLWAPI.@]
3230 * See PathSkipRootA.
3232 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3234 TRACE("(%s)\n", debugstr_w(lpszPath
));
3236 if (!lpszPath
|| !*lpszPath
)
3239 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3241 /* Network share: skip share server and mount point */
3243 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3244 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3246 return (LPWSTR
)lpszPath
;
3250 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3251 return (LPWSTR
)lpszPath
+ 3;
3255 /*************************************************************************
3256 * PathCreateFromUrlA [SHLWAPI.@]
3258 * See PathCreateFromUrlW
3260 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR pszUrl
, LPSTR pszPath
,
3261 LPDWORD pcchPath
, DWORD dwReserved
)
3263 WCHAR bufW
[MAX_PATH
];
3264 WCHAR
*pathW
= bufW
;
3265 UNICODE_STRING urlW
;
3267 DWORD lenW
= sizeof(bufW
)/sizeof(WCHAR
), lenA
;
3269 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3270 return E_INVALIDARG
;
3272 if(!RtlCreateUnicodeStringFromAsciiz(&urlW
, pszUrl
))
3273 return E_INVALIDARG
;
3274 if((ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
)) == E_POINTER
) {
3275 pathW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
3276 ret
= PathCreateFromUrlW(urlW
.Buffer
, pathW
, &lenW
, dwReserved
);
3279 RtlUnicodeToMultiByteSize(&lenA
, pathW
, lenW
* sizeof(WCHAR
));
3280 if(*pcchPath
> lenA
) {
3281 RtlUnicodeToMultiByteN(pszPath
, *pcchPath
- 1, &lenA
, pathW
, lenW
* sizeof(WCHAR
));
3285 *pcchPath
= lenA
+ 1;
3289 if(pathW
!= bufW
) HeapFree(GetProcessHeap(), 0, pathW
);
3290 RtlFreeUnicodeString(&urlW
);
3294 /*************************************************************************
3295 * PathCreateFromUrlW [SHLWAPI.@]
3297 * Create a path from a URL
3300 * lpszUrl [I] URL to convert into a path
3301 * lpszPath [O] Output buffer for the resulting Path
3302 * pcchPath [I] Length of lpszPath
3303 * dwFlags [I] Flags controlling the conversion
3306 * Success: S_OK. lpszPath contains the URL in path format,
3307 * Failure: An HRESULT error code such as E_INVALIDARG.
3309 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR pszUrl
, LPWSTR pszPath
,
3310 LPDWORD pcchPath
, DWORD dwReserved
)
3312 static const WCHAR file_colon
[] = { 'f','i','l','e',':',0 };
3313 static const WCHAR localhost
[] = { 'l','o','c','a','l','h','o','s','t',0 };
3314 DWORD nslashes
, unescape
, len
;
3319 TRACE("(%s,%p,%p,0x%08x)\n", debugstr_w(pszUrl
), pszPath
, pcchPath
, dwReserved
);
3321 if (!pszUrl
|| !pszPath
|| !pcchPath
|| !*pcchPath
)
3322 return E_INVALIDARG
;
3324 if (lstrlenW(pszUrl
) < 5)
3325 return E_INVALIDARG
;
3327 if (CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
, pszUrl
, 5,
3328 file_colon
, 5) != CSTR_EQUAL
)
3329 return E_INVALIDARG
;
3335 while (*src
== '/' || *src
== '\\') {
3340 /* We need a temporary buffer so we can compute what size to ask for.
3341 * We know that the final string won't be longer than the current pszUrl
3342 * plus at most two backslashes. All the other transformations make it
3345 len
= 2 + lstrlenW(pszUrl
) + 1;
3346 if (*pcchPath
< len
)
3347 tpath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3357 /* 'file:' + escaped DOS path */
3360 /* 'file:/' + escaped DOS path */
3363 /* 'file:///' (implied localhost) + escaped DOS path */
3364 if (!isalphaW(*src
) || (src
[1] != ':' && src
[1] != '|'))
3368 if (lstrlenW(src
) >= 10 && CompareStringW(LOCALE_INVARIANT
, NORM_IGNORECASE
,
3369 src
, 9, localhost
, 9) == CSTR_EQUAL
&& (src
[9] == '/' || src
[9] == '\\'))
3371 /* 'file://localhost/' + escaped DOS path */
3374 else if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3376 /* 'file://' + unescaped DOS path */
3381 /* 'file://hostname:port/path' (where path is escaped)
3382 * or 'file:' + escaped UNC path (\\server\share\path)
3383 * The second form is clearly specific to Windows and it might
3384 * even be doing a network lookup to try to figure it out.
3386 while (*src
&& *src
!= '/' && *src
!= '\\')
3389 StrCpyNW(dst
, pszUrl
, len
+ 1);
3391 if (*src
&& isalphaW(src
[1]) && (src
[2] == ':' || src
[2] == '|'))
3393 /* 'Forget' to add a trailing '/', just like Windows */
3399 /* 'file://' + unescaped UNC path (\\server\share\path) */
3401 if (isalphaW(*src
) && (src
[1] == ':' || src
[1] == '|'))
3405 /* 'file:/...' + escaped UNC path (\\server\share\path) */
3409 /* Copy the remainder of the path */
3410 len
+= lstrlenW(src
);
3413 /* First do the Windows-specific path conversions */
3414 for (dst
= tpath
; *dst
; dst
++)
3415 if (*dst
== '/') *dst
= '\\';
3416 if (isalphaW(*tpath
) && tpath
[1] == '|')
3417 tpath
[1] = ':'; /* c| -> c: */
3419 /* And only then unescape the path (i.e. escaped slashes are left as is) */
3422 ret
= UrlUnescapeW(tpath
, NULL
, &len
, URL_UNESCAPE_INPLACE
);
3425 /* When working in-place UrlUnescapeW() does not set len */
3426 len
= lstrlenW(tpath
);
3430 if (*pcchPath
< len
+ 1)
3433 *pcchPath
= len
+ 1;
3438 if (tpath
!= pszPath
)
3439 StrCpyW(pszPath
, tpath
);
3441 if (tpath
!= pszPath
)
3442 HeapFree(GetProcessHeap(), 0, tpath
);
3444 TRACE("Returning (%u) %s\n", *pcchPath
, debugstr_w(pszPath
));
3448 /*************************************************************************
3449 * PathCreateFromUrlAlloc [SHLWAPI.@]
3451 HRESULT WINAPI
PathCreateFromUrlAlloc(LPCWSTR pszUrl
, LPWSTR
*pszPath
,
3454 WCHAR pathW
[MAX_PATH
];
3459 hr
= PathCreateFromUrlW(pszUrl
, pathW
, &size
, dwReserved
);
3462 /* Yes, this is supposed to crash if pszPath is NULL */
3463 *pszPath
= StrDupW(pathW
);
3468 /*************************************************************************
3469 * PathRelativePathToA [SHLWAPI.@]
3471 * Create a relative path from one path to another.
3474 * lpszPath [O] Destination for relative path
3475 * lpszFrom [I] Source path
3476 * dwAttrFrom [I] File attribute of source path
3477 * lpszTo [I] Destination path
3478 * dwAttrTo [I] File attributes of destination path
3481 * TRUE If a relative path can be formed. lpszPath contains the new path
3482 * FALSE If the paths are not relative or any parameters are invalid
3485 * lpszTo should be at least MAX_PATH in length.
3487 * Calling this function with relative paths for lpszFrom or lpszTo may
3488 * give erroneous results.
3490 * The Win32 version of this function contains a bug where the lpszTo string
3491 * may be referenced 1 byte beyond the end of the string. As a result random
3492 * garbage may be written to the output path, depending on what lies beyond
3493 * the last byte of the string. This bug occurs because of the behaviour of
3494 * PathCommonPrefix() (see notes for that function), and no workaround seems
3495 * possible with Win32.
3497 * This bug has been fixed here, so for example the relative path from "\\"
3498 * to "\\" is correctly determined as "." in this implementation.
3500 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3501 LPCSTR lpszTo
, DWORD dwAttrTo
)
3505 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_a(lpszFrom
),
3506 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3508 if(lpszPath
&& lpszFrom
&& lpszTo
)
3510 WCHAR szPath
[MAX_PATH
];
3511 WCHAR szFrom
[MAX_PATH
];
3512 WCHAR szTo
[MAX_PATH
];
3513 MultiByteToWideChar(CP_ACP
,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3514 MultiByteToWideChar(CP_ACP
,0,lpszTo
,-1,szTo
,MAX_PATH
);
3515 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3516 WideCharToMultiByte(CP_ACP
,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3521 /*************************************************************************
3522 * PathRelativePathToW [SHLWAPI.@]
3524 * See PathRelativePathToA.
3526 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3527 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3529 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3530 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3531 WCHAR szFrom
[MAX_PATH
];
3532 WCHAR szTo
[MAX_PATH
];
3535 TRACE("(%p,%s,0x%08x,%s,0x%08x)\n", lpszPath
, debugstr_w(lpszFrom
),
3536 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3538 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3542 lstrcpynW(szFrom
, lpszFrom
, MAX_PATH
);
3543 lstrcpynW(szTo
, lpszTo
, MAX_PATH
);
3545 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3546 PathRemoveFileSpecW(szFrom
);
3547 if(!(dwAttrTo
& FILE_ATTRIBUTE_DIRECTORY
))
3548 PathRemoveFileSpecW(szTo
);
3550 /* Paths can only be relative if they have a common root */
3551 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3554 /* Strip off lpszFrom components to the root, by adding "..\" */
3555 lpszFrom
= szFrom
+ dwLen
;
3561 if (*lpszFrom
== '\\')
3566 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3567 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3570 /* From the root add the components of lpszTo */
3572 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3575 if (*lpszTo
&& lpszTo
[-1])
3577 if (*lpszTo
!= '\\')
3579 dwLen
= strlenW(lpszPath
);
3580 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3585 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3590 /*************************************************************************
3591 * PathUnmakeSystemFolderA [SHLWAPI.@]
3593 * Remove the system folder attributes from a path.
3596 * lpszPath [I] The path to remove attributes from
3600 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3601 * SetFileAttributesA() fails.
3603 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3607 TRACE("(%s)\n", debugstr_a(lpszPath
));
3609 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3610 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3613 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3614 return SetFileAttributesA(lpszPath
, dwAttr
);
3617 /*************************************************************************
3618 * PathUnmakeSystemFolderW [SHLWAPI.@]
3620 * See PathUnmakeSystemFolderA.
3622 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3626 TRACE("(%s)\n", debugstr_w(lpszPath
));
3628 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3629 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3632 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3633 return SetFileAttributesW(lpszPath
, dwAttr
);
3637 /*************************************************************************
3638 * PathSetDlgItemPathA [SHLWAPI.@]
3640 * Set the text of a dialog item to a path, shrinking the path to fit
3641 * if it is too big for the item.
3644 * hDlg [I] Dialog handle
3645 * id [I] ID of item in the dialog
3646 * lpszPath [I] Path to set as the items text
3652 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3653 * window text is erased).
3655 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3657 WCHAR szPath
[MAX_PATH
];
3659 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3662 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3665 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3668 /*************************************************************************
3669 * PathSetDlgItemPathW [SHLWAPI.@]
3671 * See PathSetDlgItemPathA.
3673 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3675 WCHAR path
[MAX_PATH
+ 1];
3681 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3683 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3687 lstrcpynW(path
, lpszPath
, sizeof(path
) / sizeof(WCHAR
));
3691 GetClientRect(hwItem
, &rect
);
3693 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3697 PathCompactPathW(hdc
, path
, rect
.right
);
3698 SelectObject(hdc
, hPrevObj
);
3701 ReleaseDC(hDlg
, hdc
);
3702 SetWindowTextW(hwItem
, path
);
3705 /*************************************************************************
3706 * PathIsNetworkPathA [SHLWAPI.@]
3708 * Determine if the given path is a network path.
3711 * lpszPath [I] Path to check
3714 * TRUE If lpszPath is a UNC share or mapped network drive, or
3715 * FALSE If lpszPath is a local drive or cannot be determined
3717 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3721 TRACE("(%s)\n",debugstr_a(lpszPath
));
3725 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3727 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3728 if (dwDriveNum
== -1)
3730 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3731 return pIsNetDrive(dwDriveNum
);
3734 /*************************************************************************
3735 * PathIsNetworkPathW [SHLWAPI.@]
3737 * See PathIsNetworkPathA.
3739 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3743 TRACE("(%s)\n", debugstr_w(lpszPath
));
3747 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3749 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3750 if (dwDriveNum
== -1)
3752 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3753 return pIsNetDrive(dwDriveNum
);
3756 /*************************************************************************
3757 * PathIsLFNFileSpecA [SHLWAPI.@]
3759 * Determine if the given path is a long file name
3762 * lpszPath [I] Path to check
3765 * TRUE If path is a long file name,
3766 * FALSE If path is a valid DOS short file name
3768 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3770 DWORD dwNameLen
= 0, dwExtLen
= 0;
3772 TRACE("(%s)\n",debugstr_a(lpszPath
));
3779 if (*lpszPath
== ' ')
3780 return TRUE
; /* DOS names cannot have spaces */
3781 if (*lpszPath
== '.')
3784 return TRUE
; /* DOS names have only one dot */
3791 return TRUE
; /* DOS extensions are <= 3 chars*/
3797 return TRUE
; /* DOS names are <= 8 chars */
3799 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3801 return FALSE
; /* Valid DOS path */
3804 /*************************************************************************
3805 * PathIsLFNFileSpecW [SHLWAPI.@]
3807 * See PathIsLFNFileSpecA.
3809 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3811 DWORD dwNameLen
= 0, dwExtLen
= 0;
3813 TRACE("(%s)\n",debugstr_w(lpszPath
));
3820 if (*lpszPath
== ' ')
3821 return TRUE
; /* DOS names cannot have spaces */
3822 if (*lpszPath
== '.')
3825 return TRUE
; /* DOS names have only one dot */
3832 return TRUE
; /* DOS extensions are <= 3 chars*/
3838 return TRUE
; /* DOS names are <= 8 chars */
3842 return FALSE
; /* Valid DOS path */
3845 /*************************************************************************
3846 * PathIsDirectoryEmptyA [SHLWAPI.@]
3848 * Determine if a given directory is empty.
3851 * lpszPath [I] Directory to check
3854 * TRUE If the directory exists and contains no files,
3857 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3861 TRACE("(%s)\n",debugstr_a(lpszPath
));
3865 WCHAR szPath
[MAX_PATH
];
3866 MultiByteToWideChar(CP_ACP
,0,lpszPath
,-1,szPath
,MAX_PATH
);
3867 bRet
= PathIsDirectoryEmptyW(szPath
);
3872 /*************************************************************************
3873 * PathIsDirectoryEmptyW [SHLWAPI.@]
3875 * See PathIsDirectoryEmptyA.
3877 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3879 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3880 WCHAR szSearch
[MAX_PATH
];
3884 WIN32_FIND_DATAW find_data
;
3886 TRACE("(%s)\n",debugstr_w(lpszPath
));
3888 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3891 lstrcpynW(szSearch
, lpszPath
, MAX_PATH
);
3892 PathAddBackslashW(szSearch
);
3893 dwLen
= strlenW(szSearch
);
3894 if (dwLen
> MAX_PATH
- 4)
3897 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3898 hfind
= FindFirstFileW(szSearch
, &find_data
);
3899 if (hfind
== INVALID_HANDLE_VALUE
)
3904 if (find_data
.cFileName
[0] == '.')
3906 if (find_data
.cFileName
[1] == '\0') continue;
3907 if (find_data
.cFileName
[1] == '.' && find_data
.cFileName
[2] == '\0') continue;
3913 while (FindNextFileW(hfind
, &find_data
));
3920 /*************************************************************************
3921 * PathFindSuffixArrayA [SHLWAPI.@]
3923 * Find a suffix string in an array of suffix strings
3926 * lpszSuffix [I] Suffix string to search for
3927 * lppszArray [I] Array of suffix strings to search
3928 * dwCount [I] Number of elements in lppszArray
3931 * Success: The index of the position of lpszSuffix in lppszArray
3932 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3935 * The search is case sensitive.
3936 * The match is made against the end of the suffix string, so for example:
3937 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3939 LPCSTR WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3944 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3946 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3948 dwLen
= strlen(lpszSuffix
);
3950 while (dwRet
< dwCount
)
3952 size_t dwCompareLen
= strlen(*lppszArray
);
3953 if (dwCompareLen
< dwLen
)
3955 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3956 return *lppszArray
; /* Found */
3965 /*************************************************************************
3966 * PathFindSuffixArrayW [SHLWAPI.@]
3968 * See PathFindSuffixArrayA.
3970 LPCWSTR WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3975 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3977 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3979 dwLen
= strlenW(lpszSuffix
);
3981 while (dwRet
< dwCount
)
3983 size_t dwCompareLen
= strlenW(*lppszArray
);
3984 if (dwCompareLen
< dwLen
)
3986 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3987 return *lppszArray
; /* Found */
3996 /*************************************************************************
3997 * PathUndecorateA [SHLWAPI.@]
3999 * Undecorate a file path
4002 * lpszPath [I/O] Path to remove any decoration from
4008 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
4010 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
4012 TRACE("(%s)\n",debugstr_a(lpszPath
));
4016 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
4017 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4019 LPSTR lpszSkip
= lpszExt
- 2;
4020 if (*lpszSkip
== '[')
4021 lpszSkip
++; /* [] (no number) */
4023 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
4025 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4027 /* remove the [n] */
4030 *lpszSkip
++ = *lpszExt
++;
4037 /*************************************************************************
4038 * PathUndecorateW [SHLWAPI.@]
4040 * See PathUndecorateA.
4042 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
4044 TRACE("(%s)\n",debugstr_w(lpszPath
));
4048 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
4049 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
4051 LPWSTR lpszSkip
= lpszExt
- 2;
4052 if (*lpszSkip
== '[')
4053 lpszSkip
++; /* [] (no number) */
4055 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
4057 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
4059 /* remove the [n] */
4062 *lpszSkip
++ = *lpszExt
++;
4069 /*************************************************************************
4070 * PathUnExpandEnvStringsA [SHLWAPI.@]
4072 * Substitute folder names in a path with their corresponding environment
4076 * path [I] Buffer containing the path to unexpand.
4077 * buffer [O] Buffer to receive the unexpanded path.
4078 * buf_len [I] Size of pszBuf in characters.
4084 BOOL WINAPI
PathUnExpandEnvStringsA(LPCSTR path
, LPSTR buffer
, UINT buf_len
)
4086 WCHAR bufferW
[MAX_PATH
], *pathW
;
4090 TRACE("(%s, %p, %d)\n", debugstr_a(path
), buffer
, buf_len
);
4092 pathW
= heap_strdupAtoW(path
);
4093 if (!pathW
) return FALSE
;
4095 ret
= PathUnExpandEnvStringsW(pathW
, bufferW
, MAX_PATH
);
4096 HeapFree(GetProcessHeap(), 0, pathW
);
4097 if (!ret
) return FALSE
;
4099 len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
4100 if (buf_len
< len
+ 1) return FALSE
;
4102 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, buffer
, buf_len
, NULL
, NULL
);
4106 static const WCHAR allusersprofileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%',0};
4107 static const WCHAR appdataW
[] = {'%','A','P','P','D','A','T','A','%',0};
4108 static const WCHAR programfilesW
[] = {'%','P','r','o','g','r','a','m','F','i','l','e','s','%',0};
4109 static const WCHAR systemrootW
[] = {'%','S','y','s','t','e','m','R','o','o','t','%',0};
4110 static const WCHAR systemdriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%',0};
4111 static const WCHAR userprofileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%',0};
4117 WCHAR path
[MAX_PATH
];
4121 static void init_envvars_map(struct envvars_map
*map
)
4125 map
->len
= ExpandEnvironmentStringsW(map
->var
, map
->path
, sizeof(map
->path
)/sizeof(WCHAR
));
4126 /* exclude null from length */
4127 if (map
->len
) map
->len
--;
4132 /*************************************************************************
4133 * PathUnExpandEnvStringsW [SHLWAPI.@]
4135 * Unicode version of PathUnExpandEnvStringsA.
4137 BOOL WINAPI
PathUnExpandEnvStringsW(LPCWSTR path
, LPWSTR buffer
, UINT buf_len
)
4139 static struct envvars_map null_var
= {NULL
, 0, {0}, 0};
4140 struct envvars_map
*match
= &null_var
, *cur
;
4141 struct envvars_map envvars
[] = {
4142 { allusersprofileW
, sizeof(allusersprofileW
)/sizeof(WCHAR
) },
4143 { appdataW
, sizeof(appdataW
)/sizeof(WCHAR
) },
4144 { programfilesW
, sizeof(programfilesW
)/sizeof(WCHAR
) },
4145 { systemrootW
, sizeof(systemrootW
)/sizeof(WCHAR
) },
4146 { systemdriveW
, sizeof(systemdriveW
)/sizeof(WCHAR
) },
4147 { userprofileW
, sizeof(userprofileW
)/sizeof(WCHAR
) },
4153 TRACE("(%s, %p, %d)\n", debugstr_w(path
), buffer
, buf_len
);
4155 pathlen
= strlenW(path
);
4156 init_envvars_map(envvars
);
4160 /* path can't contain expanded value or value wasn't retrieved */
4161 if (cur
->len
== 0 || cur
->len
> pathlen
|| strncmpiW(cur
->path
, path
, cur
->len
))
4167 if (cur
->len
> match
->len
)
4172 /* 'varlen' includes NULL termination char */
4173 needed
= match
->varlen
+ pathlen
- match
->len
;
4174 if (match
->len
== 0 || needed
> buf_len
) return FALSE
;
4176 strcpyW(buffer
, match
->var
);
4177 strcatW(buffer
, &path
[match
->len
]);
4178 TRACE("ret %s\n", debugstr_w(buffer
));
4183 /*************************************************************************
4186 * Find localised or default web content in "%WINDOWS%\web\".
4189 * lpszFile [I] File name containing content to look for
4190 * lpszPath [O] Buffer to contain the full path to the file
4191 * dwPathLen [I] Length of lpszPath
4194 * Success: S_OK. lpszPath contains the full path to the content.
4195 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
4197 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
4199 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
4202 TRACE("(%s,%p,%d)\n", lpszFile
, lpszPath
, dwPathLen
);
4204 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, szFile
, MAX_PATH
);
4206 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
4207 WideCharToMultiByte(CP_ACP
, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
4211 /*************************************************************************
4214 * Unicode version of SHGetWebFolderFilePathA.
4216 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
4218 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
4219 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
4220 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
4221 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
4222 DWORD dwLen
, dwFileLen
;
4223 LANGID lidSystem
, lidUser
;
4225 TRACE("(%s,%p,%d)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
4227 /* Get base directory for web content */
4228 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
4229 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
4232 dwFileLen
= strlenW(lpszFile
);
4234 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
4235 return E_FAIL
; /* lpszPath too short */
4237 strcpyW(lpszPath
+dwLen
, szWeb
);
4239 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
4241 lidSystem
= GetSystemDefaultUILanguage();
4242 lidUser
= GetUserDefaultUILanguage();
4244 if (lidSystem
!= lidUser
)
4246 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
4248 /* Use localised content in the users UI language if present */
4249 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
4250 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
4251 if (PathFileExistsW(lpszPath
))
4256 /* Fall back to OS default installed content */
4257 strcpyW(lpszPath
+ dwLen
, lpszFile
);
4258 if (PathFileExistsW(lpszPath
))
4263 #define PATH_CHAR_CLASS_LETTER 0x00000001
4264 #define PATH_CHAR_CLASS_ASTERIX 0x00000002
4265 #define PATH_CHAR_CLASS_DOT 0x00000004
4266 #define PATH_CHAR_CLASS_BACKSLASH 0x00000008
4267 #define PATH_CHAR_CLASS_COLON 0x00000010
4268 #define PATH_CHAR_CLASS_SEMICOLON 0x00000020
4269 #define PATH_CHAR_CLASS_COMMA 0x00000040
4270 #define PATH_CHAR_CLASS_SPACE 0x00000080
4271 #define PATH_CHAR_CLASS_OTHER_VALID 0x00000100
4272 #define PATH_CHAR_CLASS_DOUBLEQUOTE 0x00000200
4274 #define PATH_CHAR_CLASS_INVALID 0x00000000
4275 #define PATH_CHAR_CLASS_ANY 0xffffffff
4277 static const DWORD SHELL_charclass
[] =
4279 /* 0x00 */ PATH_CHAR_CLASS_INVALID
, /* 0x01 */ PATH_CHAR_CLASS_INVALID
,
4280 /* 0x02 */ PATH_CHAR_CLASS_INVALID
, /* 0x03 */ PATH_CHAR_CLASS_INVALID
,
4281 /* 0x04 */ PATH_CHAR_CLASS_INVALID
, /* 0x05 */ PATH_CHAR_CLASS_INVALID
,
4282 /* 0x06 */ PATH_CHAR_CLASS_INVALID
, /* 0x07 */ PATH_CHAR_CLASS_INVALID
,
4283 /* 0x08 */ PATH_CHAR_CLASS_INVALID
, /* 0x09 */ PATH_CHAR_CLASS_INVALID
,
4284 /* 0x0a */ PATH_CHAR_CLASS_INVALID
, /* 0x0b */ PATH_CHAR_CLASS_INVALID
,
4285 /* 0x0c */ PATH_CHAR_CLASS_INVALID
, /* 0x0d */ PATH_CHAR_CLASS_INVALID
,
4286 /* 0x0e */ PATH_CHAR_CLASS_INVALID
, /* 0x0f */ PATH_CHAR_CLASS_INVALID
,
4287 /* 0x10 */ PATH_CHAR_CLASS_INVALID
, /* 0x11 */ PATH_CHAR_CLASS_INVALID
,
4288 /* 0x12 */ PATH_CHAR_CLASS_INVALID
, /* 0x13 */ PATH_CHAR_CLASS_INVALID
,
4289 /* 0x14 */ PATH_CHAR_CLASS_INVALID
, /* 0x15 */ PATH_CHAR_CLASS_INVALID
,
4290 /* 0x16 */ PATH_CHAR_CLASS_INVALID
, /* 0x17 */ PATH_CHAR_CLASS_INVALID
,
4291 /* 0x18 */ PATH_CHAR_CLASS_INVALID
, /* 0x19 */ PATH_CHAR_CLASS_INVALID
,
4292 /* 0x1a */ PATH_CHAR_CLASS_INVALID
, /* 0x1b */ PATH_CHAR_CLASS_INVALID
,
4293 /* 0x1c */ PATH_CHAR_CLASS_INVALID
, /* 0x1d */ PATH_CHAR_CLASS_INVALID
,
4294 /* 0x1e */ PATH_CHAR_CLASS_INVALID
, /* 0x1f */ PATH_CHAR_CLASS_INVALID
,
4295 /* ' ' */ PATH_CHAR_CLASS_SPACE
, /* '!' */ PATH_CHAR_CLASS_OTHER_VALID
,
4296 /* '"' */ PATH_CHAR_CLASS_DOUBLEQUOTE
, /* '#' */ PATH_CHAR_CLASS_OTHER_VALID
,
4297 /* '$' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '%' */ PATH_CHAR_CLASS_OTHER_VALID
,
4298 /* '&' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '\'' */ PATH_CHAR_CLASS_OTHER_VALID
,
4299 /* '(' */ PATH_CHAR_CLASS_OTHER_VALID
, /* ')' */ PATH_CHAR_CLASS_OTHER_VALID
,
4300 /* '*' */ PATH_CHAR_CLASS_ASTERIX
, /* '+' */ PATH_CHAR_CLASS_OTHER_VALID
,
4301 /* ',' */ PATH_CHAR_CLASS_COMMA
, /* '-' */ PATH_CHAR_CLASS_OTHER_VALID
,
4302 /* '.' */ PATH_CHAR_CLASS_DOT
, /* '/' */ PATH_CHAR_CLASS_INVALID
,
4303 /* '0' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '1' */ PATH_CHAR_CLASS_OTHER_VALID
,
4304 /* '2' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '3' */ PATH_CHAR_CLASS_OTHER_VALID
,
4305 /* '4' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '5' */ PATH_CHAR_CLASS_OTHER_VALID
,
4306 /* '6' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '7' */ PATH_CHAR_CLASS_OTHER_VALID
,
4307 /* '8' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '9' */ PATH_CHAR_CLASS_OTHER_VALID
,
4308 /* ':' */ PATH_CHAR_CLASS_COLON
, /* ';' */ PATH_CHAR_CLASS_SEMICOLON
,
4309 /* '<' */ PATH_CHAR_CLASS_INVALID
, /* '=' */ PATH_CHAR_CLASS_OTHER_VALID
,
4310 /* '>' */ PATH_CHAR_CLASS_INVALID
, /* '?' */ PATH_CHAR_CLASS_LETTER
,
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_BACKSLASH
, /* ']' */ PATH_CHAR_CLASS_OTHER_VALID
,
4326 /* '^' */ PATH_CHAR_CLASS_OTHER_VALID
, /* '_' */ PATH_CHAR_CLASS_OTHER_VALID
,
4327 /* '`' */ PATH_CHAR_CLASS_OTHER_VALID
, /* 'a' */ PATH_CHAR_CLASS_ANY
,
4328 /* 'b' */ PATH_CHAR_CLASS_ANY
, /* 'c' */ PATH_CHAR_CLASS_ANY
,
4329 /* 'd' */ PATH_CHAR_CLASS_ANY
, /* 'e' */ PATH_CHAR_CLASS_ANY
,
4330 /* 'f' */ PATH_CHAR_CLASS_ANY
, /* 'g' */ PATH_CHAR_CLASS_ANY
,
4331 /* 'h' */ PATH_CHAR_CLASS_ANY
, /* 'i' */ PATH_CHAR_CLASS_ANY
,
4332 /* 'j' */ PATH_CHAR_CLASS_ANY
, /* 'k' */ PATH_CHAR_CLASS_ANY
,
4333 /* 'l' */ PATH_CHAR_CLASS_ANY
, /* 'm' */ PATH_CHAR_CLASS_ANY
,
4334 /* 'n' */ PATH_CHAR_CLASS_ANY
, /* 'o' */ PATH_CHAR_CLASS_ANY
,
4335 /* 'p' */ PATH_CHAR_CLASS_ANY
, /* 'q' */ PATH_CHAR_CLASS_ANY
,
4336 /* 'r' */ PATH_CHAR_CLASS_ANY
, /* 's' */ PATH_CHAR_CLASS_ANY
,
4337 /* 't' */ PATH_CHAR_CLASS_ANY
, /* 'u' */ PATH_CHAR_CLASS_ANY
,
4338 /* 'v' */ PATH_CHAR_CLASS_ANY
, /* 'w' */ PATH_CHAR_CLASS_ANY
,
4339 /* 'x' */ PATH_CHAR_CLASS_ANY
, /* 'y' */ PATH_CHAR_CLASS_ANY
,
4340 /* 'z' */ PATH_CHAR_CLASS_ANY
, /* '{' */ PATH_CHAR_CLASS_OTHER_VALID
,
4341 /* '|' */ PATH_CHAR_CLASS_INVALID
, /* '}' */ PATH_CHAR_CLASS_OTHER_VALID
,
4342 /* '~' */ PATH_CHAR_CLASS_OTHER_VALID
4345 /*************************************************************************
4348 * Check if an ASCII char is of a certain class
4350 BOOL WINAPI
PathIsValidCharA( char c
, DWORD
class )
4352 if ((unsigned)c
> 0x7e)
4353 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4355 return class & SHELL_charclass
[(unsigned)c
];
4358 /*************************************************************************
4361 * Check if a Unicode char is of a certain class
4363 BOOL WINAPI
PathIsValidCharW( WCHAR c
, DWORD
class )
4366 return class & PATH_CHAR_CLASS_OTHER_VALID
;
4368 return class & SHELL_charclass
[c
];