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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #include "wine/unicode.h"
35 #define NO_SHLWAPI_STREAM
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
41 /* Get a function pointer from a DLL handle */
42 #define GET_FUNC(func, module, name, fail) \
45 if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
46 func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
47 if (!func) return fail; \
51 /* DLL handles for late bound calls */
52 extern HMODULE SHLWAPI_hshell32
;
54 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
55 typedef BOOL (WINAPI
*fnpIsNetDrive
)(int);
56 static fnpIsNetDrive pIsNetDrive
;
58 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR
,LPWSTR
,DWORD
);
60 /*************************************************************************
61 * PathAppendA [SHLWAPI.@]
63 * Append one path to another.
66 * lpszPath [I/O] Initial part of path, and destination for output
67 * lpszAppend [I] Path to append
70 * Success: TRUE. lpszPath contains the newly created path.
71 * Failure: FALSE, if either path is NULL, or PathCombineA() fails.
74 * lpszAppend must contain at least one backslash ('\') if not NULL.
75 * Because PathCombineA() is used to join the paths, the resulting
76 * path is also canonicalized.
78 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
80 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
82 if (lpszPath
&& lpszAppend
)
84 if (!PathIsUNCA(lpszAppend
))
85 while (*lpszAppend
== '\\')
87 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
93 /*************************************************************************
94 * PathAppendW [SHLWAPI.@]
98 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
100 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
102 if (lpszPath
&& lpszAppend
)
104 if (!PathIsUNCW(lpszAppend
))
105 while (*lpszAppend
== '\\')
107 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
113 /*************************************************************************
114 * PathCombineA [SHLWAPI.@]
116 * Combine two paths together.
119 * lpszDest [O] Destination for combined path
120 * lpszDir [I] Directory path
121 * lpszFile [I] File path
124 * Success: The output path
125 * Failure: NULL, if inputs are invalid.
128 * lpszDest should be at least MAX_PATH in size, and may point to the same
129 * memory location as lpszDir. The combined path is canonicalised.
131 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
133 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
135 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
136 return NULL
; /* Invalid parameters */
139 WCHAR szDest
[MAX_PATH
];
140 WCHAR szDir
[MAX_PATH
];
141 WCHAR szFile
[MAX_PATH
];
143 MultiByteToWideChar(0,0,lpszDir
,-1,szDir
,MAX_PATH
);
145 MultiByteToWideChar(0,0,lpszFile
,-1,szFile
,MAX_PATH
);
146 PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
);
147 WideCharToMultiByte(0,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
152 /*************************************************************************
153 * PathCombineW [SHLWAPI.@]
157 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
159 WCHAR szTemp
[MAX_PATH
];
160 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
162 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
164 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
165 return lpszDest
; /* Invalid parameters */
167 if (!lpszFile
|| !*lpszFile
)
170 strncpyW(szTemp
, lpszDir
, MAX_PATH
);
172 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
174 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
177 strncpyW(szTemp
, lpszFile
, MAX_PATH
);
190 strncpyW(szTemp
, lpszDir
, MAX_PATH
);
193 PathStripToRootW(szTemp
);
194 lpszFile
++; /* Skip '\' */
196 if (!PathAddBackslashW(szTemp
))
198 if (strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
200 strcatW(szTemp
, lpszFile
);
203 PathCanonicalizeW(lpszDest
, szTemp
);
207 /*************************************************************************
208 * PathAddBackslashA [SHLWAPI.@]
210 * Append a backslash ('\') to a path if one doesn't exist.
213 * lpszPath [I/O] The path to append a backslash to.
216 * Success: The position of the last backslash in the path.
217 * Failure: NULL, if lpszPath is NULL or the path is too large.
219 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
223 TRACE("(%s)\n",debugstr_a(lpszPath
));
225 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
231 if (lpszPath
[-1] != '\\')
240 /*************************************************************************
241 * PathAddBackslashW [SHLWAPI.@]
243 * See PathAddBackslashA.
245 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
249 TRACE("(%s)\n",debugstr_w(lpszPath
));
251 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
257 if (lpszPath
[-1] != '\\')
266 /*************************************************************************
267 * PathBuildRootA [SHLWAPI.@]
269 * Create a root drive string (e.g. "A:\") from a drive number.
272 * lpszPath [O] Destination for the drive string
278 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
280 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
282 TRACE("(%p,%d)\n", lpszPath
, drive
);
284 if (lpszPath
&& drive
>= 0 && drive
< 26)
286 lpszPath
[0] = 'A' + drive
;
294 /*************************************************************************
295 * PathBuildRootW [SHLWAPI.@]
297 * See PathBuildRootA.
299 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
301 TRACE("(%p,%d)\n", lpszPath
, drive
);
303 if (lpszPath
&& drive
>= 0 && drive
< 26)
305 lpszPath
[0] = 'A' + drive
;
313 /*************************************************************************
314 * PathFindFileNameA [SHLWAPI.@]
316 * Locate the start of the file name in a path
319 * lpszPath [I] Path to search
322 * A pointer to the first character of the file name
324 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
326 LPCSTR lastSlash
= lpszPath
;
328 TRACE("(%s)\n",debugstr_a(lpszPath
));
330 while (lpszPath
&& *lpszPath
)
332 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
333 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
334 lastSlash
= lpszPath
+ 1;
335 lpszPath
= CharNextA(lpszPath
);
337 return (LPSTR
)lastSlash
;
340 /*************************************************************************
341 * PathFindFileNameW [SHLWAPI.@]
343 * See PathFindFileNameA.
345 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
347 LPCWSTR lastSlash
= lpszPath
;
349 TRACE("(%s)\n",debugstr_w(lpszPath
));
351 while (lpszPath
&& *lpszPath
)
353 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
354 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
355 lastSlash
= lpszPath
+ 1;
356 lpszPath
= CharNextW(lpszPath
);
358 return (LPWSTR
)lastSlash
;
361 /*************************************************************************
362 * PathFindExtensionA [SHLWAPI.@]
364 * Locate the start of the file extension in a path
367 * lpszPath [I] The path to search
370 * A pointer to the first character of the extension, the end of
371 * the string if the path has no extension, or NULL If lpszPath is NULL
373 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
375 LPCSTR lastpoint
= NULL
;
377 TRACE("(%s)\n", debugstr_a(lpszPath
));
383 if (*lpszPath
== '\\' || *lpszPath
==' ')
385 else if (*lpszPath
== '.')
386 lastpoint
= lpszPath
;
387 lpszPath
= CharNextA(lpszPath
);
390 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
393 /*************************************************************************
394 * PathFindExtensionW [SHLWAPI.@]
396 * See PathFindExtensionA.
398 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
400 LPCWSTR lastpoint
= NULL
;
402 TRACE("(%s)\n", debugstr_w(lpszPath
));
408 if (*lpszPath
== '\\' || *lpszPath
==' ')
410 else if (*lpszPath
== '.')
411 lastpoint
= lpszPath
;
412 lpszPath
= CharNextW(lpszPath
);
415 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
418 /*************************************************************************
419 * PathGetArgsA [SHLWAPI.@]
421 * Find the next argument in a string delimited by spaces.
424 * lpszPath [I] The string to search for arguments in
427 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
430 * Spaces in quoted strings are ignored as delimiters.
432 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
434 BOOL bSeenQuote
= FALSE
;
436 TRACE("(%s)\n",debugstr_a(lpszPath
));
442 if ((*lpszPath
==' ') && !bSeenQuote
)
443 return (LPSTR
)lpszPath
+ 1;
444 if (*lpszPath
== '"')
445 bSeenQuote
= !bSeenQuote
;
446 lpszPath
= CharNextA(lpszPath
);
449 return (LPSTR
)lpszPath
;
452 /*************************************************************************
453 * PathGetArgsW [SHLWAPI.@]
457 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
459 BOOL bSeenQuote
= FALSE
;
461 TRACE("(%s)\n",debugstr_w(lpszPath
));
467 if ((*lpszPath
==' ') && !bSeenQuote
)
468 return (LPWSTR
)lpszPath
+ 1;
469 if (*lpszPath
== '"')
470 bSeenQuote
= !bSeenQuote
;
471 lpszPath
= CharNextW(lpszPath
);
474 return (LPWSTR
)lpszPath
;
477 /*************************************************************************
478 * PathGetDriveNumberA [SHLWAPI.@]
480 * Return the drive number from a path
483 * lpszPath [I] Path to get the drive number from
486 * Success: The drive number corresponding to the drive in the path
487 * Failure: -1, if lpszPath contains no valid drive
489 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
491 TRACE ("(%s)\n",debugstr_a(lpszPath
));
493 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
494 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
495 return tolower(*lpszPath
) - 'a';
499 /*************************************************************************
500 * PathGetDriveNumberW [SHLWAPI.@]
502 * See PathGetDriveNumberA.
504 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
506 TRACE ("(%s)\n",debugstr_w(lpszPath
));
508 if (lpszPath
&& lpszPath
[1] == ':' &&
509 tolowerW(*lpszPath
) >= 'a' && tolowerW(*lpszPath
) <= 'z')
510 return tolowerW(*lpszPath
) - 'a';
514 /*************************************************************************
515 * PathRemoveFileSpecA [SHLWAPI.@]
517 * Remove the file specification from a path.
520 * lpszPath [I/O] Path to remove the file spec from
523 * TRUE If the path was valid and modified
526 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
528 LPSTR lpszFileSpec
= lpszPath
;
529 BOOL bModified
= FALSE
;
531 TRACE("(%s)\n",debugstr_a(lpszPath
));
535 /* Skip directory or UNC path */
536 if (*lpszPath
== '\\')
537 lpszFileSpec
= ++lpszPath
;
538 if (*lpszPath
== '\\')
539 lpszFileSpec
= ++lpszPath
;
543 if(*lpszPath
== '\\')
544 lpszFileSpec
= lpszPath
; /* Skip dir */
545 else if(*lpszPath
== ':')
547 lpszFileSpec
= ++lpszPath
; /* Skip drive */
548 if (*lpszPath
== '\\')
551 if (!(lpszPath
= CharNextA(lpszPath
)))
557 *lpszFileSpec
= '\0';
564 /*************************************************************************
565 * PathRemoveFileSpecW [SHLWAPI.@]
567 * See PathRemoveFileSpecA.
569 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
571 LPWSTR lpszFileSpec
= lpszPath
;
572 BOOL bModified
= FALSE
;
574 TRACE("(%s)\n",debugstr_w(lpszPath
));
578 /* Skip directory or UNC path */
579 if (*lpszPath
== '\\')
580 lpszFileSpec
= ++lpszPath
;
581 if (*lpszPath
== '\\')
582 lpszFileSpec
= ++lpszPath
;
586 if(*lpszPath
== '\\')
587 lpszFileSpec
= lpszPath
; /* Skip dir */
588 else if(*lpszPath
== ':')
590 lpszFileSpec
= ++lpszPath
; /* Skip drive */
591 if (*lpszPath
== '\\')
594 if (!(lpszPath
= CharNextW(lpszPath
)))
600 *lpszFileSpec
= '\0';
607 /*************************************************************************
608 * PathStripPathA [SHLWAPI.@]
610 * Remove the initial path from the beginning of a filename
613 * lpszPath [I/O] Path to remove the initial path from
618 void WINAPI
PathStripPathA(LPSTR lpszPath
)
620 TRACE("(%s)\n", debugstr_a(lpszPath
));
624 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
626 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
630 /*************************************************************************
631 * PathStripPathW [SHLWAPI.@]
633 * See PathStripPathA.
635 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
639 TRACE("(%s)\n", debugstr_w(lpszPath
));
640 lpszFileName
= PathFindFileNameW(lpszPath
);
642 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
645 /*************************************************************************
646 * PathStripToRootA [SHLWAPI.@]
648 * Reduce a path to its root.
651 * lpszPath [I/O] the path to reduce
654 * Success: TRUE if the stripped path is a root path
655 * Failure: FALSE if the path cannot be stripped or is NULL
657 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
659 TRACE("(%s)\n", debugstr_a(lpszPath
));
663 while(!PathIsRootA(lpszPath
))
664 if (!PathRemoveFileSpecA(lpszPath
))
669 /*************************************************************************
670 * PathStripToRootW [SHLWAPI.@]
672 * See PathStripToRootA.
674 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
676 TRACE("(%s)\n", debugstr_w(lpszPath
));
680 while(!PathIsRootW(lpszPath
))
681 if (!PathRemoveFileSpecW(lpszPath
))
686 /*************************************************************************
687 * PathRemoveArgsA [SHLWAPI.@]
689 * Strip space separated arguments from a path.
692 * lpszPath [I/O] Path to remove arguments from
697 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
699 TRACE("(%s)\n",debugstr_a(lpszPath
));
703 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
708 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
709 if(*lpszLastChar
== ' ')
710 *lpszLastChar
= '\0';
715 /*************************************************************************
716 * PathRemoveArgsW [SHLWAPI.@]
718 * See PathRemoveArgsA.
720 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
722 TRACE("(%s)\n",debugstr_w(lpszPath
));
726 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
731 LPWSTR lpszLastChar
= CharPrevW(lpszPath
, lpszArgs
);
732 if(*lpszLastChar
== ' ')
733 *lpszLastChar
= '\0';
738 /*************************************************************************
739 * PathRemoveExtensionA [SHLWAPI.@]
741 * Remove the file extension from a path
744 * lpszPath [I/O] Path to remove the extension from
749 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
751 TRACE("(%s)\n", debugstr_a(lpszPath
));
755 lpszPath
= PathFindExtensionA(lpszPath
);
760 /*************************************************************************
761 * PathRemoveExtensionW [SHLWAPI.@]
763 * See PathRemoveExtensionA.
765 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
767 TRACE("(%s)\n", debugstr_w(lpszPath
));
771 lpszPath
= PathFindExtensionW(lpszPath
);
776 /*************************************************************************
777 * PathRemoveBackslashA [SHLWAPI.@]
779 * Remove a trailing backslash from a path.
782 * lpszPath [I/O] Path to remove backslash from
785 * Success: A pointer to the end of the path
786 * Failure: NULL, if lpszPath is NULL
788 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
792 TRACE("(%s)\n", debugstr_a(lpszPath
));
796 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
797 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
803 /*************************************************************************
804 * PathRemoveBackslashW [SHLWAPI.@]
806 * See PathRemoveBackslashA.
808 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
810 LPWSTR szTemp
= NULL
;
812 TRACE("(%s)\n", debugstr_w(lpszPath
));
816 szTemp
= CharPrevW(lpszPath
, lpszPath
+ strlenW(lpszPath
));
817 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
823 /*************************************************************************
824 * PathRemoveBlanksA [SHLWAPI.@]
826 * Remove Spaces from the start and end of a path.
829 * lpszPath [I/O] Path to strip blanks from
834 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
836 TRACE("(%s)\n", debugstr_a(lpszPath
));
838 if(lpszPath
&& *lpszPath
)
840 LPSTR start
= lpszPath
;
842 while (*lpszPath
== ' ')
843 lpszPath
= CharNextA(lpszPath
);
846 *start
++ = *lpszPath
++;
848 if (start
!= lpszPath
)
849 while (start
[-1] == ' ')
855 /*************************************************************************
856 * PathRemoveBlanksW [SHLWAPI.@]
858 * See PathRemoveBlanksA.
860 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
862 TRACE("(%s)\n", debugstr_w(lpszPath
));
864 if(lpszPath
&& *lpszPath
)
866 LPWSTR start
= lpszPath
;
868 while (*lpszPath
== ' ')
872 *start
++ = *lpszPath
++;
874 if (start
!= lpszPath
)
875 while (start
[-1] == ' ')
881 /*************************************************************************
882 * PathQuoteSpacesA [SHLWAPI.@]
884 * Surround a path containg spaces in quotes.
887 * lpszPath [I/O] Path to quote
893 * The path is not changed if it is invalid or has no spaces.
895 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
897 TRACE("(%s)\n", debugstr_a(lpszPath
));
899 if(lpszPath
&& StrChrA(lpszPath
,' '))
901 size_t iLen
= strlen(lpszPath
) + 1;
903 if (iLen
+ 2 < MAX_PATH
)
905 memmove(lpszPath
+ 1, lpszPath
, iLen
);
907 lpszPath
[iLen
] = '"';
908 lpszPath
[iLen
+ 1] = '\0';
913 /*************************************************************************
914 * PathQuoteSpacesW [SHLWAPI.@]
916 * See PathQuoteSpacesA.
918 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
920 TRACE("(%s)\n", debugstr_w(lpszPath
));
922 if(lpszPath
&& StrChrW(lpszPath
,' '))
924 int iLen
= strlenW(lpszPath
) + 1;
926 if (iLen
+ 2 < MAX_PATH
)
928 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
930 lpszPath
[iLen
] = '"';
931 lpszPath
[iLen
+ 1] = '\0';
936 /*************************************************************************
937 * PathUnquoteSpacesA [SHLWAPI.@]
939 * Remove quotes ("") from around a path, if present.
942 * lpszPath [I/O] Path to strip quotes from
948 * If the path contains a single quote only, an empty string will result.
949 * Otherwise quotes are only removed if they appear at the start and end
952 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
954 TRACE("(%s)\n", debugstr_a(lpszPath
));
956 if (lpszPath
&& *lpszPath
== '"')
958 DWORD dwLen
= strlen(lpszPath
) - 1;
960 if (lpszPath
[dwLen
] == '"')
962 lpszPath
[dwLen
] = '\0';
963 for (; *lpszPath
; lpszPath
++)
964 *lpszPath
= lpszPath
[1];
969 /*************************************************************************
970 * PathUnquoteSpacesW [SHLWAPI.@]
972 * See PathUnquoteSpacesA.
974 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
976 TRACE("(%s)\n", debugstr_w(lpszPath
));
978 if (lpszPath
&& *lpszPath
== '"')
980 DWORD dwLen
= strlenW(lpszPath
) - 1;
982 if (lpszPath
[dwLen
] == '"')
984 lpszPath
[dwLen
] = '\0';
985 for (; *lpszPath
; lpszPath
++)
986 *lpszPath
= lpszPath
[1];
991 /*************************************************************************
992 * PathParseIconLocationA [SHLWAPI.@]
994 * Parse the location of an icon from a path.
997 * lpszPath [I/O] The path to parse the icon location from.
1000 * Success: The number of the icon
1001 * Failure: 0 if the path does not contain an icon location or is NULL
1004 * The path has surrounding quotes and spaces removed regardless
1005 * of whether the call succeeds or not.
1007 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1012 TRACE("(%s)\n", debugstr_a(lpszPath
));
1016 if ((lpszComma
= strchr(lpszPath
, ',')))
1018 *lpszComma
++ = '\0';
1019 iRet
= StrToIntA(lpszComma
);
1021 PathUnquoteSpacesA(lpszPath
);
1022 PathRemoveBlanksA(lpszPath
);
1027 /*************************************************************************
1028 * PathParseIconLocationW [SHLWAPI.@]
1030 * See PathParseIconLocationA.
1032 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1037 TRACE("(%s)\n", debugstr_w(lpszPath
));
1041 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1043 *lpszComma
++ = '\0';
1044 iRet
= StrToIntW(lpszComma
);
1046 PathUnquoteSpacesW(lpszPath
);
1047 PathRemoveBlanksW(lpszPath
);
1052 /*************************************************************************
1055 * Unicode version of PathFileExistsDefExtA.
1057 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR lpszPath
,DWORD dwWhich
)
1059 static const WCHAR pszExts
[7][5] = { { '.', 'p', 'i', 'f', 0},
1060 { '.', 'c', 'o', 'm', 0},
1061 { '.', 'e', 'x', 'e', 0},
1062 { '.', 'b', 'a', 't', 0},
1063 { '.', 'l', 'n', 'k', 0},
1064 { '.', 'c', 'm', 'd', 0},
1067 TRACE("(%s,%ld)\n", debugstr_w(lpszPath
), dwWhich
);
1069 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1074 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1075 if (!*szExt
|| dwWhich
& 0x40)
1078 int iLen
= lstrlenW(lpszPath
);
1079 if (iLen
> (MAX_PATH
- 5))
1081 while (dwWhich
& 0x1 && iChoose
< sizeof(pszExts
))
1083 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1084 if (PathFileExistsW(lpszPath
))
1089 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1093 return PathFileExistsW(lpszPath
);
1096 /*************************************************************************
1099 * Determine if a file exists locally and is of an executable type.
1102 * lpszPath [I/O] File to search for
1103 * dwWhich [I] Type of executable to search for
1106 * TRUE If the file was found. lpszPath contains the file name.
1110 * lpszPath is modified in place and must be at least MAX_PATH in length.
1111 * If the function returns FALSE, the path is modified to its orginal state.
1112 * If the given path contains an extension or dwWhich is 0, executable
1113 * extensions are not checked.
1115 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1116 * users (here through PathFindOnPathA()) and keeping advanced functionality for
1117 * their own developers exclusive use. Monopoly, anyone?
1119 BOOL WINAPI
PathFileExistsDefExtA(LPSTR lpszPath
,DWORD dwWhich
)
1123 TRACE("(%s,%ld)\n", debugstr_a(lpszPath
), dwWhich
);
1127 WCHAR szPath
[MAX_PATH
];
1128 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
1129 bRet
= PathFileExistsDefExtW(szPath
, dwWhich
);
1131 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1136 /*************************************************************************
1137 * SHLWAPI_PathFindInOtherDirs
1139 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1141 static BOOL WINAPI
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1143 static WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1144 static WCHAR szPath
[] = { 'P','A','T','H','\0'};
1148 WCHAR buff
[MAX_PATH
];
1150 TRACE("(%s,%08lx)\n", debugstr_w(lpszFile
), dwWhich
);
1152 /* Try system directories */
1153 GetSystemDirectoryW(buff
, MAX_PATH
);
1154 if (!PathAppendW(buff
, lpszFile
))
1156 if (PathFileExistsDefExtW(buff
, dwWhich
))
1158 strcpyW(lpszFile
, buff
);
1161 GetWindowsDirectoryW(buff
, MAX_PATH
);
1162 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1164 if (PathFileExistsDefExtW(buff
, dwWhich
))
1166 strcpyW(lpszFile
, buff
);
1169 GetWindowsDirectoryW(buff
, MAX_PATH
);
1170 if (!PathAppendW(buff
, lpszFile
))
1172 if (PathFileExistsDefExtW(buff
, dwWhich
))
1174 strcpyW(lpszFile
, buff
);
1177 /* Try dirs listed in %PATH% */
1178 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1180 if (!dwLenPATH
|| !(lpszPATH
= malloc((dwLenPATH
+ 1) * sizeof (WCHAR
))))
1183 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1184 lpszCurr
= lpszPATH
;
1187 LPCWSTR lpszEnd
= lpszCurr
;
1188 LPWSTR pBuff
= buff
;
1190 while (*lpszEnd
== ' ')
1192 while (*lpszEnd
&& *lpszEnd
!= ';')
1193 *pBuff
++ = *lpszEnd
++;
1197 lpszCurr
= lpszEnd
+ 1;
1199 lpszCurr
= NULL
; /* Last Path, terminate after this */
1201 if (!PathAppendW(buff
, lpszFile
))
1206 if (PathFileExistsDefExtW(buff
, dwWhich
))
1208 strcpyW(lpszFile
, buff
);
1217 /*************************************************************************
1220 * Search a range of paths for a specific type of executable.
1223 * lpszFile [I/O] File to search for
1224 * lppszOtherDirs [I] Other directories to look in
1225 * dwWhich [I] Type of executable to search for
1228 * Success: TRUE. The path to the executable is stored in lpszFile.
1229 * Failure: FALSE. The path to the executable is unchanged.
1231 BOOL WINAPI
PathFindOnPathExA(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1233 WCHAR szFile
[MAX_PATH
];
1234 WCHAR buff
[MAX_PATH
];
1236 TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1238 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1241 MultiByteToWideChar(0,0,lpszFile
,-1,szFile
,MAX_PATH
);
1243 /* Search provided directories first */
1244 if (lppszOtherDirs
&& *lppszOtherDirs
)
1246 WCHAR szOther
[MAX_PATH
];
1247 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1249 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1251 MultiByteToWideChar(0,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1252 PathCombineW(buff
, szOther
, szFile
);
1253 if (PathFileExistsDefExtW(buff
, dwWhich
))
1255 WideCharToMultiByte(0,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1261 /* Not found, try system and path dirs */
1262 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1264 WideCharToMultiByte(0,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1270 /*************************************************************************
1273 * Unicode version of PathFindOnPathExA.
1275 BOOL WINAPI
PathFindOnPathExW(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1277 WCHAR buff
[MAX_PATH
];
1279 TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1281 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1284 /* Search provided directories first */
1285 if (lppszOtherDirs
&& *lppszOtherDirs
)
1287 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1288 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1290 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1291 if (PathFileExistsDefExtW(buff
, dwWhich
))
1293 strcpyW(lpszFile
, buff
);
1299 /* Not found, try system and path dirs */
1300 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1303 /*************************************************************************
1304 * PathFindOnPathA [SHLWAPI.@]
1306 * Search a range of paths for an executable.
1309 * lpszFile [I/O] File to search for
1310 * lppszOtherDirs [I] Other directories to look in
1313 * Success: TRUE. The path to the executable is stored in lpszFile.
1314 * Failure: FALSE. The path to the executable is unchanged.
1316 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1318 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1319 return PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1322 /*************************************************************************
1323 * PathFindOnPathW [SHLWAPI.@]
1325 * See PathFindOnPathA.
1327 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1329 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1330 return PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1333 /*************************************************************************
1334 * PathCompactPathExA [SHLWAPI.@]
1336 * Compact a path into a given number of characters.
1339 * lpszDest [O] Destination for compacted path
1340 * lpszPath [I] Source path
1341 * cchMax [I] Maximum size of compacted path
1342 * dwFlags [I] Reserved
1345 * Success: TRUE. The compacted path is written to lpszDest.
1346 * Failure: FALSE. lpszPath is undefined.
1349 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1351 * The Win32 version of this function contains a bug: When cchMax == 7,
1352 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1355 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1356 * because Win32 will insert a "\" in lpszDest, even if one is
1357 * not present in the original path.
1359 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1360 UINT cchMax
, DWORD dwFlags
)
1364 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1366 if (lpszPath
&& lpszDest
)
1368 WCHAR szPath
[MAX_PATH
];
1369 WCHAR szDest
[MAX_PATH
];
1371 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
1373 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1374 WideCharToMultiByte(0,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1379 /*************************************************************************
1380 * PathCompactPathExW [SHLWAPI.@]
1382 * See PathCompactPathExA.
1384 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1385 UINT cchMax
, DWORD dwFlags
)
1387 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1389 DWORD dwLen
, dwFileLen
= 0;
1391 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1398 WARN("Invalid lpszDest would crash under Win32!\n");
1407 dwLen
= strlenW(lpszPath
) + 1;
1411 /* Don't need to compact */
1412 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1416 /* Path must be compacted to fit into lpszDest */
1417 lpszFile
= PathFindFileNameW(lpszPath
);
1418 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1420 if (dwFileLen
== dwLen
)
1422 /* No root in psth */
1425 while (--cchMax
> 0) /* No room left for anything but ellipses */
1430 /* Compact the file name with ellipses at the end */
1432 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1433 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1436 /* We have a root in the path */
1437 lpszFile
--; /* Start compacted filename with the path separator */
1440 if (dwFileLen
+ 3 > cchMax
)
1442 /* Compact the file name */
1445 while (--cchMax
> 0) /* No room left for anything but ellipses */
1450 strcpyW(lpszDest
, szEllipses
);
1453 *lpszDest
++ = *lpszFile
++;
1456 while (--cchMax
> 0) /* No room left for anything but ellipses */
1462 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1463 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1467 /* Only the root needs to be Compacted */
1468 dwLen
= cchMax
- dwFileLen
- 3;
1469 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1470 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1471 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1475 /*************************************************************************
1476 * PathIsRelativeA [SHLWAPI.@]
1478 * Determine if a path is a relative path.
1481 * lpszPath [I] Path to check
1484 * TRUE: The path is relative, or is invalid.
1485 * FALSE: The path is not relative.
1487 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1489 TRACE("(%s)\n",debugstr_a(lpszPath
));
1491 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1493 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1498 /*************************************************************************
1499 * PathIsRelativeW [SHLWAPI.@]
1501 * See PathIsRelativeA.
1503 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1505 TRACE("(%s)\n",debugstr_w(lpszPath
));
1507 if (!lpszPath
|| !*lpszPath
)
1509 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1514 /*************************************************************************
1515 * PathIsRootA [SHLWAPI.@]
1517 * Determine if a path is a root path.
1520 * lpszPath [I] Path to check
1523 * TRUE If lpszPath is valid and a root path,
1526 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1528 TRACE("(%s)\n", debugstr_a(lpszPath
));
1530 if (lpszPath
&& *lpszPath
)
1532 if (*lpszPath
== '\\')
1535 return TRUE
; /* \ */
1536 else if (lpszPath
[1]=='\\')
1538 BOOL bSeenSlash
= FALSE
;
1541 /* Check for UNC root path */
1544 if (*lpszPath
== '\\')
1550 lpszPath
= CharNextA(lpszPath
);
1555 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1556 return TRUE
; /* X:\ */
1561 /*************************************************************************
1562 * PathIsRootW [SHLWAPI.@]
1566 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1568 TRACE("(%s)\n", debugstr_w(lpszPath
));
1570 if (lpszPath
&& *lpszPath
)
1572 if (*lpszPath
== '\\')
1575 return TRUE
; /* \ */
1576 else if (lpszPath
[1]=='\\')
1578 BOOL bSeenSlash
= FALSE
;
1581 /* Check for UNC root path */
1584 if (*lpszPath
== '\\')
1590 lpszPath
= CharNextW(lpszPath
);
1595 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1596 return TRUE
; /* X:\ */
1601 /*************************************************************************
1602 * PathIsDirectoryA [SHLWAPI.@]
1604 * Determine if a path is a valid directory
1607 * lpszPath [I] Path to check.
1610 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1611 * FALSE if lpszPath is invalid or not a directory.
1614 * Although this function is prototyped as returning a BOOL, it returns
1615 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1617 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1622 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1626 TRACE("(%s)\n", debugstr_a(lpszPath
));
1628 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1631 if (PathIsUNCServerShareA(lpszPath
))
1633 FIXME("UNC Server Share not yet supported - FAILING\n");
1637 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1639 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1642 /*************************************************************************
1643 * PathIsDirectoryW [SHLWAPI.@]
1645 * See PathIsDirectoryA.
1647 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1651 TRACE("(%s)\n", debugstr_w(lpszPath
));
1653 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1656 if (PathIsUNCServerShareW(lpszPath
))
1658 FIXME("UNC Server Share not yet supported - FAILING\n");
1662 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
1664 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1667 /*************************************************************************
1668 * PathFileExistsA [SHLWAPI.@]
1670 * Determine if a file exists.
1673 * lpszPath [I] Path to check
1676 * TRUE If the file exists and is readable
1679 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1684 TRACE("(%s)\n",debugstr_a(lpszPath
));
1689 iPrevErrMode
= SetErrorMode(1);
1690 dwAttr
= GetFileAttributesA(lpszPath
);
1691 SetErrorMode(iPrevErrMode
);
1692 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1695 /*************************************************************************
1696 * PathFileExistsW [SHLWAPI.@]
1698 * See PathFileExistsA.
1700 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1705 TRACE("(%s)\n",debugstr_w(lpszPath
));
1710 iPrevErrMode
= SetErrorMode(1);
1711 dwAttr
= GetFileAttributesW(lpszPath
);
1712 SetErrorMode(iPrevErrMode
);
1713 return dwAttr
== INVALID_FILE_ATTRIBUTES
? FALSE
: TRUE
;
1716 /*************************************************************************
1717 * PathMatchSingleMaskA [internal]
1719 static BOOL WINAPI
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1721 while (*name
&& *mask
&& *mask
!=';')
1727 if (PathMatchSingleMaskA(name
,mask
+1))
1728 return TRUE
; /* try substrings */
1733 if (toupper(*mask
) != toupper(*name
) && *mask
!= '?')
1736 name
= CharNextA(name
);
1737 mask
= CharNextA(mask
);
1742 while (*mask
== '*')
1744 if (!*mask
|| *mask
== ';')
1750 /*************************************************************************
1751 * PathMatchSingleMaskW [internal]
1753 static BOOL WINAPI
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1755 while (*name
&& *mask
&& *mask
!= ';')
1761 if (PathMatchSingleMaskW(name
,mask
+1))
1762 return TRUE
; /* try substrings */
1767 if (toupperW(*mask
) != toupperW(*name
) && *mask
!= '?')
1770 name
= CharNextW(name
);
1771 mask
= CharNextW(mask
);
1775 while (*mask
== '*')
1777 if (!*mask
|| *mask
== ';')
1783 /*************************************************************************
1784 * PathMatchSpecA [SHLWAPI.@]
1786 * Determine if a path matches one or more search masks.
1789 * lpszPath [I] Path to check
1790 * lpszMask [I] Search mask(s)
1793 * TRUE If lpszPath is valid and is matched
1797 * Multiple search masks may be given if they are separated by ";". The
1798 * pattern "*.*" is treated specially in that it matches all paths (for
1799 * backwards compatibility with DOS).
1801 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1803 TRACE("(%s,%s)\n", lpszPath
, lpszMask
);
1805 if (!lstrcmpA(lpszMask
, "*.*"))
1806 return TRUE
; /* Matches every path */
1810 if (PathMatchSingleMaskA(lpszPath
, lpszMask
))
1811 return TRUE
; /* Matches the current mask */
1813 while (*lpszMask
&& *lpszMask
!= ';')
1814 lpszMask
= CharNextA(lpszMask
);
1816 if (*lpszMask
== ';')
1819 while (*lpszMask
== ' ')
1820 lpszMask
++; /* masks may be separated by "; " */
1826 /*************************************************************************
1827 * PathMatchSpecW [SHLWAPI.@]
1829 * See PathMatchSpecA.
1831 BOOL WINAPI
PathMatchSpecW(LPCWSTR lpszPath
, LPCWSTR lpszMask
)
1833 static const WCHAR szStarDotStar
[] = { '*', '.', '*', '\0' };
1835 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszMask
));
1837 if (!lstrcmpW(lpszMask
, szStarDotStar
))
1838 return TRUE
; /* Matches every path */
1842 if (PathMatchSingleMaskW(lpszPath
, lpszMask
))
1843 return TRUE
; /* Matches the current path */
1845 while (*lpszMask
&& *lpszMask
!= ';')
1848 if (*lpszMask
== ';')
1851 while (*lpszMask
== ' ')
1852 lpszMask
++; /* Masks may be separated by "; " */
1858 /*************************************************************************
1859 * PathIsSameRootA [SHLWAPI.@]
1861 * Determine if two paths share the same root.
1864 * lpszPath1 [I] Source path
1865 * lpszPath2 [I] Path to compare with
1868 * TRUE If both paths are valid and share the same root.
1869 * FALSE If either path is invalid or the paths do not share the same root.
1871 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1876 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1878 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1881 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1882 if (lpszStart
- lpszPath1
> dwLen
)
1883 return FALSE
; /* Paths not common up to length of the root */
1887 /*************************************************************************
1888 * PathIsSameRootW [SHLWAPI.@]
1890 * See PathIsSameRootA.
1892 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1897 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1899 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1902 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1903 if (lpszStart
- lpszPath1
> dwLen
)
1904 return FALSE
; /* Paths not common up to length of the root */
1908 /*************************************************************************
1909 * PathIsContentTypeA [SHLWAPI.@]
1911 * Determine if a file is of a given registered content type.
1914 * lpszPath [I] File to check
1915 * lpszContentType [I] Content type to check for
1918 * TRUE If lpszPath is a given registered content type,
1922 * This function looks up the registered content type for lpszPath. If
1923 * a content type is registered, it is compared (case insensitively) to
1924 * lpszContentType. Only if this matches does the function succeed.
1926 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
1930 char szBuff
[MAX_PATH
];
1932 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
1934 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
1935 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
1936 REG_NONE
, szBuff
, &dwDummy
) &&
1937 !strcasecmp(lpszContentType
, szBuff
))
1944 /*************************************************************************
1945 * PathIsContentTypeW [SHLWAPI.@]
1947 * See PathIsContentTypeA.
1949 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
1951 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
1954 WCHAR szBuff
[MAX_PATH
];
1956 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
1958 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
1959 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
1960 REG_NONE
, szBuff
, &dwDummy
) &&
1961 !strcmpiW(lpszContentType
, szBuff
))
1968 /*************************************************************************
1969 * PathIsFileSpecA [SHLWAPI.@]
1971 * Determine if a path is a file specification.
1974 * lpszPath [I] Path to chack
1977 * TRUE If lpszPath is a file specification (i.e. Contains no directories).
1980 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
1982 TRACE("(%s)\n", debugstr_a(lpszPath
));
1989 if (*lpszPath
== '\\' || *lpszPath
== ':')
1991 lpszPath
= CharNextA(lpszPath
);
1996 /*************************************************************************
1997 * PathIsFileSpecW [SHLWAPI.@]
1999 * See PathIsFileSpecA.
2001 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
2003 TRACE("(%s)\n", debugstr_w(lpszPath
));
2010 if (*lpszPath
== '\\' || *lpszPath
== ':')
2012 lpszPath
= CharNextW(lpszPath
);
2017 /*************************************************************************
2018 * PathIsPrefixA [SHLWAPI.@]
2020 * Determine if a path is a prefix of another.
2023 * lpszPrefix [I] Prefix
2024 * lpszPath [I] Path to check
2027 * TRUE If lpszPath has lpszPrefix as its prefix,
2028 * FALSE If either path is NULL or lpszPrefix is not a prefix
2030 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2032 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2034 if (lpszPrefix
&& lpszPath
&&
2035 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2040 /*************************************************************************
2041 * PathIsPrefixW [SHLWAPI.@]
2043 * See PathIsPrefixA.
2045 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2047 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2049 if (lpszPrefix
&& lpszPath
&&
2050 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2055 /*************************************************************************
2056 * PathIsSystemFolderA [SHLWAPI.@]
2058 * Determine if a path or file attributes are a system folder.
2061 * lpszPath [I] Path to check.
2062 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2065 * TRUE If lpszPath or dwAttrib are a system folder.
2066 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2068 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2070 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath
), dwAttrib
);
2072 if (lpszPath
&& *lpszPath
)
2073 dwAttrib
= GetFileAttributesA(lpszPath
);
2075 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2076 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2081 /*************************************************************************
2082 * PathIsSystemFolderW [SHLWAPI.@]
2084 * See PathIsSystemFolderA.
2086 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2088 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath
), dwAttrib
);
2090 if (lpszPath
&& *lpszPath
)
2091 dwAttrib
= GetFileAttributesW(lpszPath
);
2093 if (dwAttrib
== INVALID_FILE_ATTRIBUTES
|| !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2094 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2099 /*************************************************************************
2100 * PathIsUNCA [SHLWAPI.@]
2102 * Determine if a path is in UNC format.
2105 * lpszPath [I] Path to check
2108 * TRUE: The path is UNC.
2109 * FALSE: The path is not UNC or is NULL.
2111 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2113 TRACE("(%s)\n",debugstr_a(lpszPath
));
2115 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2120 /*************************************************************************
2121 * PathIsUNCW [SHLWAPI.@]
2125 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2127 TRACE("(%s)\n",debugstr_w(lpszPath
));
2129 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2134 /*************************************************************************
2135 * PathIsUNCServerA [SHLWAPI.@]
2137 * Determine if a path is a UNC server name ("\\SHARENAME").
2140 * lpszPath [I] Path to check.
2143 * TRUE If lpszPath is a valid UNC server name.
2147 * This routine is bug compatible with Win32: Server names with a
2148 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2149 * Fixing this bug may break other shlwapi functions!
2151 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2153 TRACE("(%s)\n", debugstr_a(lpszPath
));
2155 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2159 if (*lpszPath
== '\\')
2161 lpszPath
= CharNextA(lpszPath
);
2168 /*************************************************************************
2169 * PathIsUNCServerW [SHLWAPI.@]
2171 * See PathIsUNCServerA.
2173 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2175 TRACE("(%s)\n", debugstr_w(lpszPath
));
2177 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2181 if (*lpszPath
== '\\')
2183 lpszPath
= CharNextW(lpszPath
);
2190 /*************************************************************************
2191 * PathIsUNCServerShareA [SHLWAPI.@]
2193 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2196 * lpszPath [I] Path to check.
2199 * TRUE If lpszPath is a valid UNC server share.
2203 * This routine is bug compatible with Win32: Server shares with a
2204 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2205 * Fixing this bug may break other shlwapi functions!
2207 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2209 TRACE("(%s)\n", debugstr_a(lpszPath
));
2211 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2213 BOOL bSeenSlash
= FALSE
;
2216 if (*lpszPath
== '\\')
2222 lpszPath
= CharNextA(lpszPath
);
2229 /*************************************************************************
2230 * PathIsUNCServerShareW [SHLWAPI.@]
2232 * See PathIsUNCServerShareA.
2234 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2236 TRACE("(%s)\n", debugstr_w(lpszPath
));
2238 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2240 BOOL bSeenSlash
= FALSE
;
2243 if (*lpszPath
== '\\')
2249 lpszPath
= CharNextW(lpszPath
);
2256 /*************************************************************************
2257 * PathCanonicalizeA [SHLWAPI.@]
2259 * Convert a path to its canonical form.
2262 * lpszBuf [O] Output path
2263 * lpszPath [I] Path to cnonicalize
2266 * Success: TRUE. lpszBuf contains the output path,
2267 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2269 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2273 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2278 if (!lpszBuf
|| !lpszPath
)
2279 SetLastError(ERROR_INVALID_PARAMETER
);
2282 WCHAR szPath
[MAX_PATH
];
2283 WCHAR szBuff
[MAX_PATH
];
2284 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2285 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2286 WideCharToMultiByte(0,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2292 /*************************************************************************
2293 * PathCanonicalizeW [SHLWAPI.@]
2295 * See PathCanonicalizeA.
2297 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2299 LPWSTR lpszDst
= lpszBuf
;
2300 LPCWSTR lpszSrc
= lpszPath
;
2302 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2307 if (!lpszBuf
|| !lpszPath
)
2309 SetLastError(ERROR_INVALID_PARAMETER
);
2320 /* Copy path root */
2321 if (*lpszSrc
== '\\')
2323 *lpszDst
++ = *lpszSrc
++;
2325 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2328 *lpszDst
++ = *lpszSrc
++;
2329 *lpszDst
++ = *lpszSrc
++;
2330 if (*lpszSrc
== '\\')
2331 *lpszDst
++ = *lpszSrc
++;
2334 /* Canonicalize the rest of the path */
2337 if (*lpszSrc
== '.')
2339 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2341 lpszSrc
+= 2; /* Skip .\ */
2343 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2345 /* \.. backs up a directory, over the root if it has no \ following X:.
2346 * .. is ignored if it would remove a UNC server name or inital \\
2348 if (lpszDst
!= lpszBuf
)
2350 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2351 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2352 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2354 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2357 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2359 if (*lpszDst
== '\\')
2360 lpszDst
++; /* Reset to last '\' */
2362 lpszDst
= lpszBuf
; /* Start path again from new root */
2364 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2367 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2369 if (lpszDst
== lpszBuf
)
2375 lpszSrc
+= 2; /* Skip .. in src path */
2378 *lpszDst
++ = *lpszSrc
++;
2381 *lpszDst
++ = *lpszSrc
++;
2383 /* Append \ to naked drive specs */
2384 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2390 /*************************************************************************
2391 * PathFindNextComponentA [SHLWAPI.@]
2393 * Find the next component in a path.
2396 * lpszPath [I] Path to find next component in
2399 * Success: A pointer to the next component, or the end of the string.
2400 * Failure: NULL, If lpszPath is invalid
2403 * A 'component' is either a backslash character (\) or UNC marker (\\).
2404 * Because of this, relative paths (e.g "c:foo") are regarded as having
2405 * only one component.
2407 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2411 TRACE("(%s)\n", debugstr_a(lpszPath
));
2413 if(!lpszPath
|| !*lpszPath
)
2416 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2418 if (lpszSlash
[1] == '\\')
2420 return lpszSlash
+ 1;
2422 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2425 /*************************************************************************
2426 * PathFindNextComponentW [SHLWAPI.@]
2428 * See PathFindNextComponentA.
2430 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2434 TRACE("(%s)\n", debugstr_w(lpszPath
));
2436 if(!lpszPath
|| !*lpszPath
)
2439 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2441 if (lpszSlash
[1] == '\\')
2443 return lpszSlash
+ 1;
2445 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2448 /*************************************************************************
2449 * PathAddExtensionA [SHLWAPI.@]
2451 * Add a file extension to a path
2454 * lpszPath [I/O] Path to add extension to
2455 * lpszExtension [I] Extension to add to lpszPath
2458 * TRUE If the path was modified,
2459 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2460 * extension allready, or the new path length is too big.
2463 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2464 * does not do this, so the behaviour was removed.
2466 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2470 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2472 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2475 dwLen
= strlen(lpszPath
);
2477 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2480 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2484 /*************************************************************************
2485 * PathAddExtensionW [SHLWAPI.@]
2487 * See PathAddExtensionA.
2489 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2493 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2495 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2498 dwLen
= strlenW(lpszPath
);
2500 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2503 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2507 /*************************************************************************
2508 * PathMakePrettyA [SHLWAPI.@]
2510 * Convert an uppercase DOS filename into lowercase.
2513 * lpszPath [I/O] Path to convert.
2516 * TRUE If the path was an uppercase DOS path and was converted,
2519 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2521 LPSTR pszIter
= lpszPath
;
2523 TRACE("(%s)\n", debugstr_a(lpszPath
));
2525 if (!pszIter
|| !*pszIter
)
2530 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2531 return FALSE
; /* Not DOS path */
2534 pszIter
= lpszPath
+ 1;
2537 *pszIter
= tolower(*pszIter
);
2543 /*************************************************************************
2544 * PathMakePrettyW [SHLWAPI.@]
2546 * See PathMakePrettyA.
2548 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2550 LPWSTR pszIter
= lpszPath
;
2552 TRACE("(%s)\n", debugstr_w(lpszPath
));
2554 if (!pszIter
|| !*pszIter
)
2559 if (islowerW(*pszIter
))
2560 return FALSE
; /* Not DOS path */
2563 pszIter
= lpszPath
+ 1;
2566 *pszIter
= tolowerW(*pszIter
);
2572 /*************************************************************************
2573 * PathCommonPrefixA [SHLWAPI.@]
2575 * Determine the length of the common prefix between two paths.
2578 * lpszFile1 [I] First path for comparison
2579 * lpszFile2 [I] Second path for comparison
2580 * achPath [O] Destination for common prefix string
2583 * The length of the common prefix. This is 0 if there is no common
2584 * prefix between the paths or if any parameters are invalid. If the prefix
2585 * is non-zero and achPath is not NULL, achPath is filled with the common
2586 * part of the prefix and NUL terminated.
2589 * A common prefix of 2 is always returned as 3. It is thus possible for
2590 * the length returned to be invalid (i.e. Longer than one or both of the
2591 * strings given as parameters). This Win32 behaviour has been implemented
2592 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2593 * To work around this when using this function, always check that the byte
2594 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2596 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2599 LPCSTR lpszIter1
= lpszFile1
;
2600 LPCSTR lpszIter2
= lpszFile2
;
2602 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2607 if (!lpszFile1
|| !lpszFile2
)
2610 /* Handle roots first */
2611 if (PathIsUNCA(lpszFile1
))
2613 if (!PathIsUNCA(lpszFile2
))
2618 else if (PathIsUNCA(lpszFile2
))
2619 return 0; /* Know already lpszFile1 is not UNC */
2624 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2625 (!*lpszIter2
|| *lpszIter2
== '\\'))
2626 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2628 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2629 break; /* Strings differ at this point */
2636 iLen
++; /* Feature/Bug compatible with Win32 */
2638 if (iLen
&& achPath
)
2640 memcpy(achPath
,lpszFile1
,iLen
);
2641 achPath
[iLen
] = '\0';
2646 /*************************************************************************
2647 * PathCommonPrefixW [SHLWAPI.@]
2649 * See PathCommonPrefixA.
2651 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2654 LPCWSTR lpszIter1
= lpszFile1
;
2655 LPCWSTR lpszIter2
= lpszFile2
;
2657 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2662 if (!lpszFile1
|| !lpszFile2
)
2665 /* Handle roots first */
2666 if (PathIsUNCW(lpszFile1
))
2668 if (!PathIsUNCW(lpszFile2
))
2673 else if (PathIsUNCW(lpszFile2
))
2674 return 0; /* Know already lpszFile1 is not UNC */
2679 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2680 (!*lpszIter2
|| *lpszIter2
== '\\'))
2681 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2683 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2684 break; /* Strings differ at this point */
2691 iLen
++; /* Feature/Bug compatible with Win32 */
2693 if (iLen
&& achPath
)
2695 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2696 achPath
[iLen
] = '\0';
2701 /*************************************************************************
2702 * PathCompactPathA [SHLWAPI.@]
2704 * Make a path fit into a given width when printed to a DC.
2707 * hDc [I] Destination DC
2708 * lpszPath [I/O] Path to be printed to hDc
2709 * dx [I] Desired width
2712 * TRUE If the path was modified.
2715 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2719 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2723 WCHAR szPath
[MAX_PATH
];
2724 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2725 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2726 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2731 /*************************************************************************
2732 * PathCompactPathW [SHLWAPI.@]
2734 * See PathCompactPathA.
2736 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2738 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2741 WCHAR buff
[MAX_PATH
];
2745 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2751 hdc
= hDC
= GetDC(0);
2753 /* Get the length of the whole path */
2754 dwLen
= strlenW(lpszPath
);
2755 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2757 if ((UINT
)size
.cx
> dx
)
2759 /* Path too big, must reduce it */
2761 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2763 sFile
= PathFindFileNameW(lpszPath
);
2764 if (sFile
!= lpszPath
)
2765 sFile
= CharPrevW(lpszPath
, sFile
);
2767 /* Get the size of ellipses */
2768 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2769 dwEllipsesLen
= size
.cx
;
2770 /* Get the size of the file name */
2771 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2772 dwPathLen
= size
.cx
;
2774 if (sFile
!= lpszPath
)
2776 LPWSTR sPath
= sFile
;
2777 BOOL bEllipses
= FALSE
;
2779 /* The path includes a file name. Include as much of the path prior to
2780 * the file name as possible, allowing for the ellipses, e.g:
2781 * c:\some very long path\filename ==> c:\some v...\filename
2783 strncpyW(buff
, sFile
, MAX_PATH
);
2787 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2789 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2790 dwTotalLen
+= size
.cx
;
2791 if (dwTotalLen
<= dx
)
2793 sPath
= CharPrevW(lpszPath
, sPath
);
2797 sPath
= CharPrevW(lpszPath
, sPath
);
2798 sPath
= CharPrevW(lpszPath
, sPath
);
2800 } while (sPath
> lpszPath
);
2802 if (sPath
> lpszPath
)
2806 strcpyW(sPath
, szEllipses
);
2807 strcpyW(sPath
+3, buff
);
2812 strcpyW(lpszPath
, szEllipses
);
2813 strcpyW(lpszPath
+3, buff
);
2818 /* Trim the path by adding ellipses to the end, e.g:
2819 * A very long file name.txt ==> A very...
2821 dwLen
= strlenW(lpszPath
);
2823 if (dwLen
> MAX_PATH
- 3)
2824 dwLen
= MAX_PATH
- 3;
2825 strncpyW(buff
, sFile
, dwLen
);
2829 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2830 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2834 DWORD dwWritten
= 0;
2836 dwEllipsesLen
/= 3; /* Size of a single '.' */
2838 /* Write as much of the Ellipses string as possible */
2839 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2842 dwWritten
+= dwEllipsesLen
;
2850 strcpyW(buff
+ dwLen
, szEllipses
);
2851 strcpyW(lpszPath
, buff
);
2862 /*************************************************************************
2863 * PathGetCharTypeA [SHLWAPI.@]
2865 * Categorise a character from a file path.
2868 * ch [I] Character to get the type of
2871 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2873 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2875 return PathGetCharTypeW(ch
);
2878 /*************************************************************************
2879 * PathGetCharTypeW [SHLWAPI.@]
2881 * See PathGetCharTypeA.
2883 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2887 TRACE("(%d)\n", ch
);
2889 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2890 ch
== '"' || ch
== '|' || ch
== '/')
2891 flags
= GCT_INVALID
; /* Invalid */
2892 else if (ch
== '*' || ch
=='?')
2893 flags
= GCT_WILD
; /* Wildchars */
2894 else if ((ch
== '\\') || (ch
== ':'))
2895 return GCT_SEPARATOR
; /* Path separators */
2900 if ((ch
& 0x1 && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2901 ch
== '.' || ch
== '@' || ch
== '^' ||
2902 ch
== '\'' || ch
== 130 || ch
== '`')
2903 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2906 flags
|= GCT_SHORTCHAR
; /* Bug compatible with win32 */
2907 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2912 /*************************************************************************
2913 * SHLWAPI_UseSystemForSystemFolders
2915 * Internal helper for PathMakeSystemFolderW.
2917 static BOOL WINAPI
SHLWAPI_UseSystemForSystemFolders()
2919 static BOOL bCheckedReg
= FALSE
;
2920 static BOOL bUseSystemForSystemFolders
= FALSE
;
2926 /* Key tells Win what file attributes to use on system folders */
2927 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
2928 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2929 "UseSystemForSystemFolders", 0, 0, 0))
2930 bUseSystemForSystemFolders
= TRUE
;
2932 return bUseSystemForSystemFolders
;
2935 /*************************************************************************
2936 * PathMakeSystemFolderA [SHLWAPI.@]
2938 * Set system folder attribute for a path.
2941 * lpszPath [I] The path to turn into a system folder
2944 * TRUE If the path was changed to/already was a system folder
2945 * FALSE If the path is invalid or SetFileAttributesA() fails
2947 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
2951 TRACE("(%s)\n", debugstr_a(lpszPath
));
2953 if (lpszPath
&& *lpszPath
)
2955 WCHAR szPath
[MAX_PATH
];
2956 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2957 bRet
= PathMakeSystemFolderW(szPath
);
2962 /*************************************************************************
2963 * PathMakeSystemFolderW [SHLWAPI.@]
2965 * See PathMakeSystemFolderA.
2967 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
2969 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
2970 WCHAR buff
[MAX_PATH
];
2972 TRACE("(%s)\n", debugstr_w(lpszPath
));
2974 if (!lpszPath
|| !*lpszPath
)
2977 /* If the directory is already a system directory, dont do anything */
2978 GetSystemDirectoryW(buff
, MAX_PATH
);
2979 if (!strcmpW(buff
, lpszPath
))
2982 GetWindowsDirectoryW(buff
, MAX_PATH
);
2983 if (!strcmpW(buff
, lpszPath
))
2986 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
2987 if (SHLWAPI_UseSystemForSystemFolders())
2988 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
2990 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
)
2993 /* Change file attributes to system attributes */
2994 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
2995 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
2998 /*************************************************************************
2999 * PathRenameExtensionA [SHLWAPI.@]
3001 * Swap the file extension in a path with another extension.
3004 * lpszPath [I/O] Path to swap the extension in
3005 * lpszExt [I] The new extension
3008 * TRUE if lpszPath was modified,
3009 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
3011 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
3013 LPSTR lpszExtension
;
3015 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
3017 lpszExtension
= PathFindExtensionA(lpszPath
);
3019 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
3022 strcpy(lpszExtension
, lpszExt
);
3026 /*************************************************************************
3027 * PathRenameExtensionW [SHLWAPI.@]
3029 * See PathRenameExtensionA.
3031 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3033 LPWSTR lpszExtension
;
3035 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3037 lpszExtension
= PathFindExtensionW(lpszPath
);
3039 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3042 strcpyW(lpszExtension
, lpszExt
);
3046 /*************************************************************************
3047 * PathSearchAndQualifyA [SHLWAPI.@]
3049 * Determine if a given path is correct and fully qualified.
3052 * lpszPath [I] Path to check
3053 * lpszBuf [O] Output for correct path
3054 * cchBuf [I] Size of lpszBuf
3059 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3061 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3065 /*************************************************************************
3066 * PathSearchAndQualifyW [SHLWAPI.@]
3068 * See PathSearchAndQualifyA.
3070 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3072 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3076 /*************************************************************************
3077 * PathSkipRootA [SHLWAPI.@]
3079 * Return the portion of a path following the drive letter or mount point.
3082 * lpszPath [I] The path to skip on
3085 * Success: A pointer to the next character after the root.
3086 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3088 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3090 TRACE("(%s)\n", debugstr_a(lpszPath
));
3092 if (!lpszPath
|| !*lpszPath
)
3095 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3097 /* Network share: skip share server and mount point */
3099 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3100 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3102 return (LPSTR
)lpszPath
;
3105 if (IsDBCSLeadByte(*lpszPath
))
3109 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3110 return (LPSTR
)lpszPath
+ 3;
3114 /*************************************************************************
3115 * PathSkipRootW [SHLWAPI.@]
3117 * See PathSkipRootA.
3119 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3121 TRACE("(%s)\n", debugstr_w(lpszPath
));
3123 if (!lpszPath
|| !*lpszPath
)
3126 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3128 /* Network share: skip share server and mount point */
3130 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3131 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3133 return (LPWSTR
)lpszPath
;
3137 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3138 return (LPWSTR
)lpszPath
+ 3;
3142 /*************************************************************************
3143 * PathCreateFromUrlA [SHLWAPI.@]
3145 * Create a path from a URL
3148 * lpszUrl [I] URL to convert into a path
3149 * lpszPath [O] Output buffer for the resulting Path
3150 * pcchPath [I] Length of lpszPath
3151 * dwFlags [I] Flags controlling the conversion
3154 * Success: S_OK. lpszPath contains the URL in path format,
3155 * Failure: An HRESULT error code such as E_INVALIDARG.
3157 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR lpszUrl
, LPSTR lpszPath
,
3158 LPDWORD pcchPath
, DWORD dwFlags
)
3161 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_a(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3163 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3164 return E_INVALIDARG
;
3166 pszPathPart
= StrChrA(lpszUrl
, ':');
3167 if ((((pszPathPart
- lpszUrl
) == 1) && isalpha(*lpszUrl
)) ||
3168 !lstrcmpA(lpszUrl
, "file:"))
3170 return UrlUnescapeA(pszPathPart
, lpszPath
, pcchPath
, dwFlags
);
3172 /* extracts thing prior to : in pszURL and checks against:
3176 * about - if match returns E_INVALIDARG
3179 return E_INVALIDARG
;
3182 /*************************************************************************
3183 * PathCreateFromUrlW [SHLWAPI.@]
3185 * See PathCreateFromUrlA.
3187 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR lpszUrl
, LPWSTR lpszPath
,
3188 LPDWORD pcchPath
, DWORD dwFlags
)
3190 static const WCHAR stemp
[] = { 'f','i','l','e',':','/','/',0 };
3191 LPWSTR pwszPathPart
;
3194 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_w(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3196 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3197 return E_INVALIDARG
;
3199 /* Path of the form file://... */
3200 if (!strncmpW(lpszUrl
, stemp
, 7))
3204 /* Path of the form file:... */
3205 else if (!strncmpW(lpszUrl
, stemp
, 5))
3210 /* Ensure that path is of the form c:... or c|... */
3211 if (lpszUrl
[1] != ':' && lpszUrl
[1] != '|' && isalphaW(*lpszUrl
))
3212 return E_INVALIDARG
;
3214 hr
= UrlUnescapeW(lpszUrl
, lpszPath
, pcchPath
, dwFlags
);
3215 if (lpszPath
[1] == '|')
3218 for (pwszPathPart
= lpszPath
; *pwszPathPart
; pwszPathPart
++)
3219 if (*pwszPathPart
== '/')
3220 *pwszPathPart
= '\\';
3222 TRACE("Returning %s\n",debugstr_w(lpszPath
));
3227 /*************************************************************************
3228 * PathRelativePathToA [SHLWAPI.@]
3230 * Create a relative path from one path to another.
3233 * lpszPath [O] Destination for relative path
3234 * lpszFrom [I] Source path
3235 * dwAttrFrom [I] File attribute of source path
3236 * lpszTo [I] Destination path
3237 * dwAttrTo [I] File attributes of destination path
3240 * TRUE If a relative path can be formed. lpszPath contains the new path
3241 * FALSE If the paths are not relavtive or any parameters are invalid
3244 * lpszTo should be at least MAX_PATH in length.
3246 * Calling this function with relative paths for lpszFrom or lpszTo may
3247 * give erroneous results.
3249 * The Win32 version of this function contains a bug where the lpszTo string
3250 * may be referenced 1 byte beyond the end of the string. As a result random
3251 * garbage may be written to the output path, depending on what lies beyond
3252 * the last byte of the string. This bug occurs because of the behaviour of
3253 * PathCommonPrefix() (see notes for that function), and no workaround seems
3254 * possible with Win32.
3256 * This bug has been fixed here, so for example the relative path from "\\"
3257 * to "\\" is correctly determined as "." in this implementation.
3259 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3260 LPCSTR lpszTo
, DWORD dwAttrTo
)
3264 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_a(lpszFrom
),
3265 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3267 if(lpszPath
&& lpszFrom
&& lpszTo
)
3269 WCHAR szPath
[MAX_PATH
];
3270 WCHAR szFrom
[MAX_PATH
];
3271 WCHAR szTo
[MAX_PATH
];
3272 MultiByteToWideChar(0,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3273 MultiByteToWideChar(0,0,lpszTo
,-1,szTo
,MAX_PATH
);
3274 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3275 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3280 /*************************************************************************
3281 * PathRelativePathToW [SHLWAPI.@]
3283 * See PathRelativePathToA.
3285 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3286 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3288 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3289 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3290 WCHAR szFrom
[MAX_PATH
];
3291 WCHAR szTo
[MAX_PATH
];
3294 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_w(lpszFrom
),
3295 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3297 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3301 strncpyW(szFrom
, lpszFrom
, MAX_PATH
);
3302 strncpyW(szTo
, lpszTo
, MAX_PATH
);
3304 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3305 PathRemoveFileSpecW(szFrom
);
3306 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3307 PathRemoveFileSpecW(szTo
);
3309 /* Paths can only be relative if they have a common root */
3310 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3313 /* Strip off lpszFrom components to the root, by adding "..\" */
3314 lpszFrom
= szFrom
+ dwLen
;
3320 if (*lpszFrom
== '\\')
3325 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3326 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3329 /* From the root add the components of lpszTo */
3331 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3334 if (*lpszTo
&& lpszTo
[-1])
3336 if (*lpszTo
!= '\\')
3338 dwLen
= strlenW(lpszPath
);
3339 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3344 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3349 /*************************************************************************
3350 * PathUnmakeSystemFolderA [SHLWAPI.@]
3352 * Remove the system folder attributes from a path.
3355 * lpszPath [I] The path to remove attributes from
3359 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3360 * SetFileAttributesA() fails.
3362 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3366 TRACE("(%s)\n", debugstr_a(lpszPath
));
3368 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3369 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3372 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3373 return SetFileAttributesA(lpszPath
, dwAttr
);
3376 /*************************************************************************
3377 * PathUnmakeSystemFolderW [SHLWAPI.@]
3379 * See PathUnmakeSystemFolderA.
3381 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3385 TRACE("(%s)\n", debugstr_w(lpszPath
));
3387 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == INVALID_FILE_ATTRIBUTES
||
3388 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3391 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3392 return SetFileAttributesW(lpszPath
, dwAttr
);
3396 /*************************************************************************
3397 * PathSetDlgItemPathA [SHLWAPI.@]
3399 * Set the text of a dialog item to a path, shrinking the path to fit
3400 * if it is too big for the item.
3403 * hDlg [I] Dialog handle
3404 * id [I] ID of item in the dialog
3405 * lpszPath [I] Path to set as the items text
3411 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3412 * window text is erased).
3414 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3416 WCHAR szPath
[MAX_PATH
];
3418 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3421 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3424 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3427 /*************************************************************************
3428 * PathSetDlgItemPathW [SHLWAPI.@]
3430 * See PathSetDlgItemPathA.
3432 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3434 WCHAR path
[MAX_PATH
+ 1];
3440 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3442 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3446 strncpyW(path
, lpszPath
, sizeof(path
));
3450 GetClientRect(hwItem
, &rect
);
3452 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3456 PathCompactPathW(hdc
, path
, rect
.right
);
3457 SelectObject(hdc
, hPrevObj
);
3460 ReleaseDC(hDlg
, hdc
);
3461 SetWindowTextW(hwItem
, path
);
3464 /*************************************************************************
3465 * PathIsNetworkPathA [SHLWAPI.@]
3467 * Determine if the given path is a network path.
3470 * lpszPath [I] Path to check
3473 * TRUE If lpszPath is a UNC share or mapped network drive, or
3474 * FALSE If lpszPath is a local drive or cannot be determined
3476 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3480 TRACE("(%s)\n",debugstr_a(lpszPath
));
3484 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3486 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3487 if (dwDriveNum
== -1)
3489 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3490 return pIsNetDrive(dwDriveNum
);
3493 /*************************************************************************
3494 * PathIsNetworkPathW [SHLWAPI.@]
3496 * See PathIsNetworkPathA.
3498 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3502 TRACE("(%s)\n", debugstr_w(lpszPath
));
3506 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3508 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3509 if (dwDriveNum
== -1)
3511 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3512 return pIsNetDrive(dwDriveNum
);
3515 /*************************************************************************
3516 * PathIsLFNFileSpecA [SHLWAPI.@]
3518 * Determine if the given path is a long file name
3521 * lpszPath [I] Path to check
3524 * TRUE If path is a long file name,
3525 * FALSE If path is a valid DOS short file name
3527 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3529 DWORD dwNameLen
= 0, dwExtLen
= 0;
3531 TRACE("(%s)\n",debugstr_a(lpszPath
));
3538 if (*lpszPath
== ' ')
3539 return TRUE
; /* DOS names cannot have spaces */
3540 if (*lpszPath
== '.')
3543 return TRUE
; /* DOS names have only one dot */
3550 return TRUE
; /* DOS extensions are <= 3 chars*/
3556 return TRUE
; /* DOS names are <= 8 chars */
3558 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3560 return FALSE
; /* Valid DOS path */
3563 /*************************************************************************
3564 * PathIsLFNFileSpecW [SHLWAPI.@]
3566 * See PathIsLFNFileSpecA.
3568 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3570 DWORD dwNameLen
= 0, dwExtLen
= 0;
3572 TRACE("(%s)\n",debugstr_w(lpszPath
));
3579 if (*lpszPath
== ' ')
3580 return TRUE
; /* DOS names cannot have spaces */
3581 if (*lpszPath
== '.')
3584 return TRUE
; /* DOS names have only one dot */
3591 return TRUE
; /* DOS extensions are <= 3 chars*/
3597 return TRUE
; /* DOS names are <= 8 chars */
3601 return FALSE
; /* Valid DOS path */
3604 /*************************************************************************
3605 * PathIsDirectoryEmptyA [SHLWAPI.@]
3607 * Determine if a given directory is empty.
3610 * lpszPath [I] Directory to check
3613 * TRUE If the directory exists and contains no files,
3616 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3620 TRACE("(%s)\n",debugstr_a(lpszPath
));
3624 WCHAR szPath
[MAX_PATH
];
3625 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3626 bRet
= PathIsDirectoryEmptyW(szPath
);
3631 /*************************************************************************
3632 * PathIsDirectoryEmptyW [SHLWAPI.@]
3634 * See PathIsDirectoryEmptyA.
3636 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3638 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3639 WCHAR szSearch
[MAX_PATH
];
3642 BOOL retVal
= FALSE
;
3643 WIN32_FIND_DATAW find_data
;
3645 TRACE("(%s)\n",debugstr_w(lpszPath
));
3647 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3650 strncpyW(szSearch
, lpszPath
, MAX_PATH
);
3651 PathAddBackslashW(szSearch
);
3652 dwLen
= strlenW(szSearch
);
3653 if (dwLen
> MAX_PATH
- 4)
3656 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3657 hfind
= FindFirstFileW(szSearch
, &find_data
);
3659 if (hfind
!= INVALID_HANDLE_VALUE
&&
3660 find_data
.cFileName
[0] == '.' &&
3661 find_data
.cFileName
[1] == '.')
3663 /* The only directory entry should be the parent */
3664 if (!FindNextFileW(hfind
, &find_data
))
3672 /*************************************************************************
3673 * PathFindSuffixArrayA [SHLWAPI.@]
3675 * Find a suffix string in an array of suffix strings
3678 * lpszSuffix [I] Suffix string to search for
3679 * lppszArray [I] Array of suffix strings to search
3680 * dwCount [I] Number of elements in lppszArray
3683 * Success: The index of the position of lpszSuffix in lppszArray
3684 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3687 * The search is case sensitive.
3688 * The match is made against the end of the suffix string, so for example:
3689 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3691 int WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3696 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3698 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3700 dwLen
= strlen(lpszSuffix
);
3702 while (dwRet
< dwCount
)
3704 size_t dwCompareLen
= strlen(*lppszArray
);
3705 if (dwCompareLen
< dwLen
)
3707 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3708 return dwRet
; /* Found */
3717 /*************************************************************************
3718 * PathFindSuffixArrayW [SHLWAPI.@]
3720 * See PathFindSuffixArrayA.
3722 int WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3727 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3729 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3731 dwLen
= strlenW(lpszSuffix
);
3733 while (dwRet
< dwCount
)
3735 size_t dwCompareLen
= strlenW(*lppszArray
);
3736 if (dwCompareLen
< dwLen
)
3738 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3739 return dwRet
; /* Found */
3748 /*************************************************************************
3749 * PathUndecorateA [SHLWAPI.@]
3751 * Undecorate a file path
3754 * lpszPath [I/O] Path to remove any decoration from
3760 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3762 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3764 TRACE("(%s)\n",debugstr_a(lpszPath
));
3768 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3769 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3771 LPSTR lpszSkip
= lpszExt
- 2;
3772 if (*lpszSkip
== '[')
3773 lpszSkip
++; /* [] (no number) */
3775 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3777 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3779 /* remove the [n] */
3782 *lpszSkip
++ = *lpszExt
++;
3789 /*************************************************************************
3790 * PathUndecorateW [SHLWAPI.@]
3792 * See PathUndecorateA.
3794 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3796 TRACE("(%s)\n",debugstr_w(lpszPath
));
3800 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3801 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3803 LPWSTR lpszSkip
= lpszExt
- 2;
3804 if (*lpszSkip
== '[')
3805 lpszSkip
++; /* [] (no number) */
3807 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3809 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3811 /* remove the [n] */
3814 *lpszSkip
++ = *lpszExt
++;
3821 /*************************************************************************
3824 * Find localised or default web content in "%WINDOWS%\web\".
3827 * lpszFile [I] File name containing content to look for
3828 * lpszPath [O] Buffer to contain the full path to the file
3829 * dwPathLen [I] Length of lpszPath
3832 * Success: S_OK. lpszPath contains the full path to the content.
3833 * Failure: E_FAIL. The content does not exist or lpszPath is too short.
3835 HRESULT WINAPI
SHGetWebFolderFilePathA(LPCSTR lpszFile
, LPSTR lpszPath
, DWORD dwPathLen
)
3837 WCHAR szFile
[MAX_PATH
], szPath
[MAX_PATH
];
3840 TRACE("(%s,%p,%ld)\n", lpszFile
, lpszPath
, dwPathLen
);
3842 MultiByteToWideChar(0, 0, lpszFile
, -1, szFile
, MAX_PATH
);
3844 hRet
= SHGetWebFolderFilePathW(szFile
, szPath
, dwPathLen
);
3845 WideCharToMultiByte(0, 0, szPath
, -1, lpszPath
, dwPathLen
, 0, 0);
3849 /*************************************************************************
3852 * Unicode version of SHGetWebFolderFilePathA.
3854 HRESULT WINAPI
SHGetWebFolderFilePathW(LPCWSTR lpszFile
, LPWSTR lpszPath
, DWORD dwPathLen
)
3856 static const WCHAR szWeb
[] = {'\\','W','e','b','\\','\0'};
3857 static const WCHAR szWebMui
[] = {'m','u','i','\\','%','0','4','x','\\','\0'};
3858 #define szWebLen (sizeof(szWeb)/sizeof(WCHAR))
3859 #define szWebMuiLen ((sizeof(szWebMui)+1)/sizeof(WCHAR))
3860 DWORD dwLen
, dwFileLen
;
3861 LANGID lidSystem
, lidUser
;
3863 TRACE("(%s,%p,%ld)\n", debugstr_w(lpszFile
), lpszPath
, dwPathLen
);
3865 /* Get base directory for web content */
3866 dwLen
= GetSystemWindowsDirectoryW(lpszPath
, dwPathLen
);
3867 if (dwLen
> 0 && lpszPath
[dwLen
-1] == '\\')
3870 dwFileLen
= strlenW(lpszFile
);
3872 if (dwLen
+ dwFileLen
+ szWebLen
>= dwPathLen
)
3873 return E_FAIL
; /* lpszPath too short */
3875 strcpyW(lpszPath
+dwLen
, szWeb
);
3877 dwPathLen
= dwPathLen
- dwLen
; /* Remaining space */
3879 lidSystem
= GetSystemDefaultUILanguage();
3880 lidUser
= GetUserDefaultUILanguage();
3882 if (lidSystem
!= lidUser
)
3884 if (dwFileLen
+ szWebMuiLen
< dwPathLen
)
3886 /* Use localised content in the users UI language if present */
3887 wsprintfW(lpszPath
+ dwLen
, szWebMui
, lidUser
);
3888 strcpyW(lpszPath
+ dwLen
+ szWebMuiLen
, lpszFile
);
3889 if (PathFileExistsW(lpszPath
))
3894 /* Fall back to OS default installed content */
3895 strcpyW(lpszPath
+ dwLen
, lpszFile
);
3896 if (PathFileExistsW(lpszPath
))