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"
30 #include "wine/unicode.h"
35 #define NO_SHLWAPI_STREAM
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 /* function pointers for GET_FUNC macro; these need to be global because of gcc bug */
43 static BOOL (WINAPI
*pIsNetDrive
)(DWORD
);
45 /*************************************************************************
46 * PathAppendA [SHLWAPI.@]
48 * Append one path to another.
51 * lpszPath [O] Initial part of path
52 * lpszAppend [I] Path to append
55 * Success: TRUE. lpszPath contains the newly created path.
56 * Failure: FALSE, if either path is NULL, or PathCombineA fails.
59 * lpszAppend must contain at least one backslash ('\') if not NULL.
60 * Because PathCombineA is used to join the paths, the resulting
61 * path is also canonicalized.
63 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
65 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
67 if (lpszPath
&& lpszAppend
)
69 if (!PathIsUNCA(lpszAppend
))
70 while (*lpszAppend
== '\\')
72 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
78 /*************************************************************************
79 * PathAppendW [SHLWAPI.@]
83 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
85 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
87 if (lpszPath
&& lpszAppend
)
89 if (!PathIsUNCW(lpszAppend
))
90 while (*lpszAppend
== '\\')
92 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
98 /*************************************************************************
99 * PathCombineA [SHLWAPI.@]
101 * Combine two paths together.
104 * lpszDest [O] Destination for combined path
105 * lpszDir [I] Directory path
106 * liszFile [I] File path
109 * Success: The output path
110 * Failure: NULL, if inputs are invalid.
113 * lpszDest should be at least MAX_PATH in size, and may point to the same
114 * memory location as lpszDir. The combined path is canonicalised.
116 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
118 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
120 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
121 return NULL
; /* Invalid parameters */
124 WCHAR szDest
[MAX_PATH
];
125 WCHAR szDir
[MAX_PATH
];
126 WCHAR szFile
[MAX_PATH
];
128 MultiByteToWideChar(0,0,lpszDir
,-1,szDir
,MAX_PATH
);
130 MultiByteToWideChar(0,0,lpszFile
,-1,szFile
,MAX_PATH
);
131 PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
);
132 WideCharToMultiByte(0,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
137 /*************************************************************************
138 * PathCombineW [SHLWAPI.@]
142 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
144 WCHAR szTemp
[MAX_PATH
];
145 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
147 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
149 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
150 return lpszDest
; /* Invalid parameters */
152 if (!lpszFile
|| !*lpszFile
)
155 strncpyW(szTemp
, lpszDir
, MAX_PATH
);
157 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
159 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
162 strncpyW(szTemp
, lpszFile
, MAX_PATH
);
175 strncpyW(szTemp
, lpszDir
, MAX_PATH
);
178 PathStripToRootW(szTemp
);
179 lpszFile
++; /* Skip '\' */
181 if (!PathAddBackslashW(szTemp
))
183 if (strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
185 strcatW(szTemp
, lpszFile
);
188 PathCanonicalizeW(lpszDest
, szTemp
);
192 /*************************************************************************
193 * PathAddBackslashA [SHLWAPI.@]
195 * Append a backslash ('\') to a path if one doesn't exist.
198 * lpszPath [O] The path to append a backslash to.
201 * Success: The position of the last backslash in the path.
202 * Failure: NULL, if lpszPath is NULL or the path is too large.
204 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
208 TRACE("(%s)\n",debugstr_a(lpszPath
));
210 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
216 if (lpszPath
[-1] != '\\')
225 /*************************************************************************
226 * PathAddBackslashW [SHLWAPI.@]
228 * See PathAddBackslashA.
230 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
234 TRACE("(%s)\n",debugstr_w(lpszPath
));
236 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
242 if (lpszPath
[-1] != '\\')
251 /*************************************************************************
252 * PathBuildRootA [SHLWAPI.@]
254 * Create a root drive string (e.g. "A:\") from a drive number.
257 * lpszPath [O] Destination for the drive string
263 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
265 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
267 TRACE("(%p,%d)\n", debugstr_a(lpszPath
), drive
);
269 if (lpszPath
&& drive
>= 0 && drive
< 26)
271 lpszPath
[0] = 'A' + drive
;
279 /*************************************************************************
280 * PathBuildRootW [SHLWAPI.@]
282 * See PathBuildRootA.
284 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
286 TRACE("(%p,%d)\n",debugstr_w(lpszPath
), drive
);
288 if (lpszPath
&& drive
>= 0 && drive
< 26)
290 lpszPath
[0] = 'A' + drive
;
298 /*************************************************************************
299 * PathFindFileNameA [SHLWAPI.@]
301 * Locate the start of the file name in a path
304 * lpszPath [I] Path to search
307 * A pointer to the first character of the file name
309 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
311 LPCSTR lastSlash
= lpszPath
;
313 TRACE("(%s)\n",debugstr_a(lpszPath
));
315 while (lpszPath
&& *lpszPath
)
317 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
318 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
319 lastSlash
= lpszPath
+ 1;
320 lpszPath
= CharNextA(lpszPath
);
322 return (LPSTR
)lastSlash
;
325 /*************************************************************************
326 * PathFindFileNameW [SHLWAPI.@]
328 * See PathFindFileNameA.
330 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
332 LPCWSTR lastSlash
= lpszPath
;
334 TRACE("(%s)\n",debugstr_w(lpszPath
));
336 while (lpszPath
&& *lpszPath
)
338 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
339 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
340 lastSlash
= lpszPath
+ 1;
341 lpszPath
= CharNextW(lpszPath
);
343 return (LPWSTR
)lastSlash
;
346 /*************************************************************************
347 * PathFindExtensionA [SHLWAPI.@]
349 * Locate the start of the file extension in a path
352 * lpszPath [I] The path to search
355 * A pointer to the first character of the extension, the end of
356 * the string if the path has no extension, or NULL If lpszPath is NULL
358 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
360 LPCSTR lastpoint
= NULL
;
362 TRACE("(%s)\n", debugstr_a(lpszPath
));
368 if (*lpszPath
== '\\' || *lpszPath
==' ')
370 else if (*lpszPath
== '.')
371 lastpoint
= lpszPath
;
372 lpszPath
= CharNextA(lpszPath
);
375 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
378 /*************************************************************************
379 * PathFindExtensionW [SHLWAPI.@]
381 * See PathFindExtensionA.
383 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
385 LPCWSTR lastpoint
= NULL
;
387 TRACE("(%s)\n", debugstr_w(lpszPath
));
393 if (*lpszPath
== '\\' || *lpszPath
==' ')
395 else if (*lpszPath
== '.')
396 lastpoint
= lpszPath
;
397 lpszPath
= CharNextW(lpszPath
);
400 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
403 /*************************************************************************
404 * PathGetArgsA [SHLWAPI.@]
406 * Find the next argument in a string delimited by spaces.
409 * lpszPath [I] The string to search for arguments in
412 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
415 * Spaces in quoted strings are ignored as delimiters.
417 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
419 BOOL bSeenQuote
= FALSE
;
421 TRACE("(%s)\n",debugstr_a(lpszPath
));
427 if ((*lpszPath
==' ') && !bSeenQuote
)
428 return (LPSTR
)lpszPath
+ 1;
429 if (*lpszPath
== '"')
430 bSeenQuote
= !bSeenQuote
;
431 lpszPath
= CharNextA(lpszPath
);
434 return (LPSTR
)lpszPath
;
437 /*************************************************************************
438 * PathGetArgsW [SHLWAPI.@]
442 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
444 BOOL bSeenQuote
= FALSE
;
446 TRACE("(%s)\n",debugstr_w(lpszPath
));
452 if ((*lpszPath
==' ') && !bSeenQuote
)
453 return (LPWSTR
)lpszPath
+ 1;
454 if (*lpszPath
== '"')
455 bSeenQuote
= !bSeenQuote
;
456 lpszPath
= CharNextW(lpszPath
);
459 return (LPWSTR
)lpszPath
;
462 /*************************************************************************
463 * PathGetDriveNumberA [SHLWAPI.@]
465 * Return the drive number from a path
468 * lpszPath [I] Path to get the drive number from
471 * Success: The drive number corresponding to the drive in the path
472 * Failure: -1, if lpszPath contains no valid drive
474 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
476 TRACE ("(%s)\n",debugstr_a(lpszPath
));
478 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
479 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
480 return tolower(*lpszPath
) - 'a';
484 /*************************************************************************
485 * PathGetDriveNumberW [SHLWAPI.@]
487 * See PathGetDriveNumberA.
489 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
491 TRACE ("(%s)\n",debugstr_w(lpszPath
));
493 if (lpszPath
&& lpszPath
[1] == ':' &&
494 tolowerW(*lpszPath
) >= 'a' && tolowerW(*lpszPath
) <= 'z')
495 return tolowerW(*lpszPath
) - 'a';
499 /*************************************************************************
500 * PathRemoveFileSpecA [SHLWAPI.@]
502 * Remove the file specification from a path.
505 * lpszPath [O] Path to remove the file spec from
508 * TRUE If the path was valid and modified
511 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
513 LPSTR lpszFileSpec
= lpszPath
;
514 BOOL bModified
= FALSE
;
516 TRACE("(%s)\n",debugstr_a(lpszPath
));
520 /* Skip directory or UNC path */
521 if (*lpszPath
== '\\')
522 lpszFileSpec
= ++lpszPath
;
523 if (*lpszPath
== '\\')
524 lpszFileSpec
= ++lpszPath
;
528 if(*lpszPath
== '\\')
529 lpszFileSpec
= lpszPath
; /* Skip dir */
530 else if(*lpszPath
== ':')
532 lpszFileSpec
= ++lpszPath
; /* Skip drive */
533 if (*lpszPath
== '\\')
536 if (!(lpszPath
= CharNextA(lpszPath
)))
542 *lpszFileSpec
= '\0';
549 /*************************************************************************
550 * PathRemoveFileSpecW [SHLWAPI.@]
552 * See PathRemoveFileSpecA.
554 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
556 LPWSTR lpszFileSpec
= lpszPath
;
557 BOOL bModified
= FALSE
;
559 TRACE("(%s)\n",debugstr_w(lpszPath
));
563 /* Skip directory or UNC path */
564 if (*lpszPath
== '\\')
565 lpszFileSpec
= ++lpszPath
;
566 if (*lpszPath
== '\\')
567 lpszFileSpec
= ++lpszPath
;
571 if(*lpszPath
== '\\')
572 lpszFileSpec
= lpszPath
; /* Skip dir */
573 else if(*lpszPath
== ':')
575 lpszFileSpec
= ++lpszPath
; /* Skip drive */
576 if (*lpszPath
== '\\')
579 if (!(lpszPath
= CharNextW(lpszPath
)))
585 *lpszFileSpec
= '\0';
592 /*************************************************************************
593 * PathStripPathA [SHLWAPI.@]
595 * Remove the initial path from the beginning of a filename
598 * lpszPath [O] Path to remove the initial path from
603 void WINAPI
PathStripPathA(LPSTR lpszPath
)
605 TRACE("(%s)\n", debugstr_a(lpszPath
));
609 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
611 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
615 /*************************************************************************
616 * PathStripPathW [SHLWAPI.@]
618 * See PathStripPathA.
620 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
624 TRACE("(%s)\n", debugstr_w(lpszPath
));
625 lpszFileName
= PathFindFileNameW(lpszPath
);
627 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
630 /*************************************************************************
631 * PathStripToRootA [SHLWAPI.@]
633 * Reduce a path to its root.
636 * lpszPath [O] the path to reduce
639 * Success: TRUE if the stripped path is a root path
640 * Failure: FALSE if the path cannot be stripped or is NULL
642 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
644 TRACE("(%s)\n", debugstr_a(lpszPath
));
648 while(!PathIsRootA(lpszPath
))
649 if (!PathRemoveFileSpecA(lpszPath
))
654 /*************************************************************************
655 * PathStripToRootW [SHLWAPI.@]
657 * See PathStripToRootA.
659 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
661 TRACE("(%s)\n", debugstr_w(lpszPath
));
665 while(!PathIsRootW(lpszPath
))
666 if (!PathRemoveFileSpecW(lpszPath
))
671 /*************************************************************************
672 * PathRemoveArgsA [SHLWAPI.@]
674 * Strip space seperated arguments from a path.
677 * lpszPath [I] Path to remove arguments from
682 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
684 TRACE("(%s)\n",debugstr_a(lpszPath
));
688 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
693 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
694 if(*lpszLastChar
== ' ')
695 *lpszLastChar
= '\0';
700 /*************************************************************************
701 * PathRemoveArgsW [SHLWAPI.@]
703 * See PathRemoveArgsA.
705 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
707 TRACE("(%s)\n",debugstr_w(lpszPath
));
711 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
716 LPWSTR lpszLastChar
= CharPrevW(lpszPath
, lpszArgs
);
717 if(*lpszLastChar
== ' ')
718 *lpszLastChar
= '\0';
723 /*************************************************************************
724 * PathRemoveExtensionA [SHLWAPI.@]
726 * Remove the file extension from a path
729 * lpszPath [O] Path to remove the extension from
734 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
736 TRACE("(%s)\n", debugstr_a(lpszPath
));
740 lpszPath
= PathFindExtensionA(lpszPath
);
745 /*************************************************************************
746 * PathRemoveExtensionW [SHLWAPI.@]
748 * See PathRemoveExtensionA.
750 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
752 TRACE("(%s)\n", debugstr_w(lpszPath
));
756 lpszPath
= PathFindExtensionW(lpszPath
);
761 /*************************************************************************
762 * PathRemoveBackslashA [SHLWAPI.@]
764 * Remove a trailing backslash from a path.
767 * lpszPath [O] Path to remove backslash from
770 * Success: A pointer to the end of the path
771 * Failure: NULL, if lpszPath is NULL
773 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
777 TRACE("(%s)\n", debugstr_a(lpszPath
));
781 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
782 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
788 /*************************************************************************
789 * PathRemoveBackslashW [SHLWAPI.@]
791 * See PathRemoveBackslashA.
793 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
795 LPWSTR szTemp
= NULL
;
797 TRACE("(%s)\n", debugstr_w(lpszPath
));
801 szTemp
= CharPrevW(lpszPath
, lpszPath
+ strlenW(lpszPath
));
802 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
808 /*************************************************************************
809 * PathRemoveBlanksA [SHLWAPI.@]
811 * Remove Spaces from the start and end of a path.
814 * lpszPath [O] Path to strip blanks from
819 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
821 TRACE("(%s)\n", debugstr_a(lpszPath
));
823 if(lpszPath
&& *lpszPath
)
825 LPSTR start
= lpszPath
;
827 while (*lpszPath
== ' ')
828 lpszPath
= CharNextA(lpszPath
);
831 *start
++ = *lpszPath
++;
833 if (start
!= lpszPath
)
834 while (start
[-1] == ' ')
840 /*************************************************************************
841 * PathRemoveBlanksW [SHLWAPI.@]
843 * See PathRemoveBlanksA.
845 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
847 TRACE("(%s)\n", debugstr_w(lpszPath
));
849 if(lpszPath
&& *lpszPath
)
851 LPWSTR start
= lpszPath
;
853 while (*lpszPath
== ' ')
857 *start
++ = *lpszPath
++;
859 if (start
!= lpszPath
)
860 while (start
[-1] == ' ')
866 /*************************************************************************
867 * PathQuoteSpacesA [SHLWAPI.@]
869 * Surround a path containg spaces in quotes.
872 * lpszPath [O] Path to quote
878 * The path is not changed if it is invalid or has no spaces.
880 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
882 TRACE("(%s)\n", debugstr_a(lpszPath
));
884 if(lpszPath
&& StrChrA(lpszPath
,' '))
886 int iLen
= strlen(lpszPath
) + 1;
888 if (iLen
+ 2 < MAX_PATH
)
890 memmove(lpszPath
+ 1, lpszPath
, iLen
);
892 lpszPath
[iLen
] = '"';
893 lpszPath
[iLen
+ 1] = '\0';
898 /*************************************************************************
899 * PathQuoteSpacesW [SHLWAPI.@]
901 * See PathQuoteSpacesA.
903 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
905 TRACE("(%s)\n", debugstr_w(lpszPath
));
907 if(lpszPath
&& StrChrW(lpszPath
,' '))
909 int iLen
= strlenW(lpszPath
) + 1;
911 if (iLen
+ 2 < MAX_PATH
)
913 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
915 lpszPath
[iLen
] = '"';
916 lpszPath
[iLen
+ 1] = '\0';
921 /*************************************************************************
922 * PathUnquoteSpacesA [SHLWAPI.@]
924 * Remove quotes ("") from around a path, if present.
927 * lpszPath [O] Path to strip quotes from
933 * If the path contains a single quote only, an empty string will result.
934 * Otherwise quotes are only removed if they appear at the start and end
937 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
939 TRACE("(%s)\n", debugstr_a(lpszPath
));
941 if (lpszPath
&& *lpszPath
== '"')
943 DWORD dwLen
= strlen(lpszPath
) - 1;
945 if (lpszPath
[dwLen
] == '"')
947 lpszPath
[dwLen
] = '\0';
948 for (; *lpszPath
; lpszPath
++)
949 *lpszPath
= lpszPath
[1];
954 /*************************************************************************
955 * PathUnquoteSpacesW [SHLWAPI.@]
957 * See PathUnquoteSpacesA.
959 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
961 TRACE("(%s)\n", debugstr_w(lpszPath
));
963 if (lpszPath
&& *lpszPath
== '"')
965 DWORD dwLen
= strlenW(lpszPath
) - 1;
967 if (lpszPath
[dwLen
] == '"')
969 lpszPath
[dwLen
] = '\0';
970 for (; *lpszPath
; lpszPath
++)
971 *lpszPath
= lpszPath
[1];
976 /*************************************************************************
977 * PathParseIconLocationA [SHLWAPI.@]
979 * Parse the location of an icon from a path.
982 * lpszPath [O] The path to parse the icon location from.
985 * Success: The number of the icon
986 * Failure: 0 if the path does not contain an icon location or is NULL
989 * The path has surrounding quotes and spaces removed regardless
990 * of whether the call succeeds or not.
992 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
997 TRACE("(%s)\n", debugstr_a(lpszPath
));
1001 if ((lpszComma
= strchr(lpszPath
, ',')))
1003 *lpszComma
++ = '\0';
1004 iRet
= StrToIntA(lpszComma
);
1006 PathUnquoteSpacesA(lpszPath
);
1007 PathRemoveBlanksA(lpszPath
);
1012 /*************************************************************************
1013 * PathParseIconLocationW [SHLWAPI.@]
1015 * See PathParseIconLocationA.
1017 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1022 TRACE("(%s)\n", debugstr_w(lpszPath
));
1026 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1028 *lpszComma
++ = '\0';
1029 iRet
= StrToIntW(lpszComma
);
1031 PathUnquoteSpacesW(lpszPath
);
1032 PathRemoveBlanksW(lpszPath
);
1037 /*************************************************************************
1038 * SHLWAPI_PathFindLocalExeA
1040 * Internal implementation of SHLWAPI_3.
1042 BOOL WINAPI
SHLWAPI_PathFindLocalExeA (LPSTR lpszPath
, DWORD dwWhich
)
1046 TRACE("(%s,%ld)\n", debugstr_a(lpszPath
), dwWhich
);
1050 WCHAR szPath
[MAX_PATH
];
1051 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
1052 bRet
= SHLWAPI_PathFindLocalExeW(szPath
, dwWhich
);
1054 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1059 /*************************************************************************
1060 * SHLWAPI_PathFindLocalExeW
1062 * Internal implementation of SHLWAPI_4.
1064 BOOL WINAPI
SHLWAPI_PathFindLocalExeW (LPWSTR lpszPath
, DWORD dwWhich
)
1066 static const WCHAR pszExts
[7][5] = { { '.', 'p', 'i', 'f', '0'},
1067 { '.', 'c', 'o', 'm', '0'},
1068 { '.', 'e', 'x', 'e', '0'},
1069 { '.', 'b', 'a', 't', '0'},
1070 { '.', 'l', 'n', 'k', '0'},
1071 { '.', 'c', 'm', 'd', '0'},
1072 { '0', '0', '0', '0', '0'} };
1074 TRACE("(%s,%ld)\n", debugstr_w(lpszPath
), dwWhich
);
1076 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1081 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1082 if (!*szExt
|| dwWhich
& 0x40)
1085 int iLen
= lstrlenW(lpszPath
);
1086 if (iLen
> (MAX_PATH
- 5))
1088 while (dwWhich
& 0x1 && iChoose
< sizeof(pszExts
))
1090 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1091 if (PathFileExistsW(lpszPath
))
1096 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1100 return PathFileExistsW(lpszPath
);
1103 /*************************************************************************
1104 * SHLWAPI_PathFindInOtherDirs
1106 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1108 static BOOL WINAPI
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1110 static WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1111 static WCHAR szPath
[] = { 'P','A','T','H','\0'};
1115 WCHAR buff
[MAX_PATH
];
1117 TRACE("(%s,%08lx)\n", debugstr_w(lpszFile
), dwWhich
);
1119 /* Try system directories */
1120 GetSystemDirectoryW(buff
, MAX_PATH
);
1121 if (!PathAppendW(buff
, lpszFile
))
1123 if (SHLWAPI_PathFindLocalExeW(buff
, dwWhich
))
1125 strcpyW(lpszFile
, buff
);
1128 GetWindowsDirectoryW(buff
, MAX_PATH
);
1129 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1131 if (SHLWAPI_PathFindLocalExeW(buff
, dwWhich
))
1133 strcpyW(lpszFile
, buff
);
1136 GetWindowsDirectoryW(buff
, MAX_PATH
);
1137 if (!PathAppendW(buff
, lpszFile
))
1139 if (SHLWAPI_PathFindLocalExeW(buff
, dwWhich
))
1141 strcpyW(lpszFile
, buff
);
1144 /* Try dirs listed in %PATH% */
1145 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1147 if (!dwLenPATH
|| !(lpszPATH
= malloc((dwLenPATH
+ 1) * sizeof (WCHAR
))))
1150 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1151 lpszCurr
= lpszPATH
;
1154 LPCWSTR lpszEnd
= lpszCurr
;
1155 LPWSTR pBuff
= buff
;
1157 while (*lpszEnd
== ' ')
1159 while (*lpszEnd
&& *lpszEnd
!= ';')
1160 *pBuff
++ = *lpszEnd
++;
1164 lpszCurr
= lpszEnd
+ 1;
1166 lpszCurr
= NULL
; /* Last Path, terminate after this */
1168 if (!PathAppendW(buff
, lpszFile
))
1170 if (SHLWAPI_PathFindLocalExeW(buff
, dwWhich
))
1172 strcpyW(lpszFile
, buff
);
1182 /*************************************************************************
1183 * SHLWAPI_PathFindOnPathExA
1185 * Internal implementation of SHLWAPI_5
1187 BOOL WINAPI
SHLWAPI_PathFindOnPathExA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
, DWORD dwWhich
)
1189 WCHAR szFile
[MAX_PATH
];
1190 WCHAR buff
[MAX_PATH
];
1192 TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1194 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1197 MultiByteToWideChar(0,0,lpszFile
,-1,szFile
,MAX_PATH
);
1199 /* Search provided directories first */
1200 if (lppszOtherDirs
&& *lppszOtherDirs
)
1202 WCHAR szOther
[MAX_PATH
];
1203 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1205 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1207 MultiByteToWideChar(0,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1208 PathCombineW(buff
, szOther
, szFile
);
1209 if (SHLWAPI_PathFindLocalExeW(buff
, dwWhich
))
1211 WideCharToMultiByte(0,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1217 /* Not found, try system and path dirs */
1218 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1220 WideCharToMultiByte(0,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1226 /*************************************************************************
1227 * SHLWAPI_PathFindOnPathExW
1229 * Internal implementation of SHLWAPI_6.
1231 BOOL WINAPI
SHLWAPI_PathFindOnPathExW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
, DWORD dwWhich
)
1233 WCHAR buff
[MAX_PATH
];
1235 TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1237 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1240 /* Search provided directories first */
1241 if (lppszOtherDirs
&& *lppszOtherDirs
)
1243 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1244 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1246 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1247 if (SHLWAPI_PathFindLocalExeW(buff
, dwWhich
))
1249 strcpyW(lpszFile
, buff
);
1255 /* Not found, try system and path dirs */
1256 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1259 /*************************************************************************
1260 * PathFindOnPathA [SHLWAPI.@]
1262 * Search a range of paths for an executable.
1265 * lpszFile [O] File to search for
1266 * lppszOtherDirs [I] Other directories to look in
1269 * Success: TRUE. The path to the executable is stored in lpszFile.
1270 * Failure: FALSE. The path to the executable is unchanged.
1272 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1274 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1275 return SHLWAPI_PathFindOnPathExA(lpszFile
, lppszOtherDirs
, 0);
1278 /*************************************************************************
1279 * PathFindOnPathW [SHLWAPI.@]
1281 * See PathFindOnPathA.
1283 BOOL WINAPI
PathFindOnPathW (LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1285 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1286 return SHLWAPI_PathFindOnPathExW(lpszFile
,lppszOtherDirs
, 0);
1289 /*************************************************************************
1290 * PathCompactPathExA [SHLWAPI.@]
1292 * Compact a path into a given number of characters.
1295 * lpszDest [O] Destination for compacted path
1296 * lpszPath [I] Source path
1297 * cchMax [I[ Maximum size of compacted path
1298 * dwFlags [I] Reserved
1301 * Success: TRUE. The compacted path is written to lpszDest.
1302 * Failure: FALSE. lpszPath is undefined.
1305 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1306 * The Win32 version of this function contains a bug: When cchMax == 7,
1307 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1309 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1310 * because Win32 will insert a \ in the compact filename, even if one is
1311 * not present in the original path.
1313 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1314 UINT cchMax
, DWORD dwFlags
)
1318 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1320 if (lpszPath
&& lpszDest
)
1322 WCHAR szPath
[MAX_PATH
];
1323 WCHAR szDest
[MAX_PATH
];
1325 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
1327 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1328 WideCharToMultiByte(0,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1333 /*************************************************************************
1334 * PathCompactPathExW [SHLWAPI.@]
1336 * See PathCompactPathExA.
1338 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1339 UINT cchMax
, DWORD dwFlags
)
1341 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1343 DWORD dwLen
, dwFileLen
= 0;
1345 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1352 WARN("Invalid lpszDest would crash under Win32!\n");
1361 dwLen
= strlenW(lpszPath
) + 1;
1365 /* Don't need to compact */
1366 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1370 /* Path must be compacted to fit into lpszDest */
1371 lpszFile
= PathFindFileNameW(lpszPath
);
1372 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1374 if (dwFileLen
== dwLen
)
1376 /* No root in psth */
1379 while (--cchMax
> 0) /* No room left for anything but ellipses */
1384 /* Compact the file name with ellipses at the end */
1386 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1387 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1390 /* We have a root in the path */
1391 lpszFile
--; /* Start compacted filename with the path seperator */
1394 if (dwFileLen
+ 3 > cchMax
)
1396 /* Compact the file name */
1399 while (--cchMax
> 0) /* No room left for anything but ellipses */
1404 strcpyW(lpszDest
, szEllipses
);
1407 *lpszDest
++ = *lpszFile
++;
1410 while (--cchMax
> 0) /* No room left for anything but ellipses */
1416 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1417 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1421 /* Only the root needs to be Compacted */
1422 dwLen
= cchMax
- dwFileLen
- 3;
1423 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1424 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1425 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1429 /*************************************************************************
1430 * PathIsRelativeA [SHLWAPI.@]
1432 * Determine if a path is a relative path.
1435 * lpszPath [I] Path to check
1438 * TRUE: The path is relative, or is invalid.
1439 * FALSE: The path is not relative.
1441 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1443 TRACE("(%s)\n",debugstr_a(lpszPath
));
1445 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1447 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1452 /*************************************************************************
1453 * PathIsRelativeW [SHLWAPI.@]
1455 * See PathIsRelativeA.
1457 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1459 TRACE("(%s)\n",debugstr_w(lpszPath
));
1461 if (!lpszPath
|| !*lpszPath
)
1463 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1468 /*************************************************************************
1469 * PathIsRootA [SHLWAPI.@]
1471 * Determine if a path is a root path.
1474 * lpszPath [I] Path to check
1477 * TRUE If lpszPath is valid and a root path
1480 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1482 TRACE("(%s)\n", debugstr_a(lpszPath
));
1484 if (lpszPath
&& *lpszPath
)
1486 if (*lpszPath
== '\\')
1489 return TRUE
; /* \ */
1490 else if (lpszPath
[1]=='\\')
1492 BOOL bSeenSlash
= FALSE
;
1495 /* Check for UNC root path */
1498 if (*lpszPath
== '\\')
1504 lpszPath
= CharNextA(lpszPath
);
1509 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1510 return TRUE
; /* X:\ */
1515 /*************************************************************************
1516 * PathIsRootW [SHLWAPI.@]
1520 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1522 TRACE("(%s)\n", debugstr_w(lpszPath
));
1524 if (lpszPath
&& *lpszPath
)
1526 if (*lpszPath
== '\\')
1529 return TRUE
; /* \ */
1530 else if (lpszPath
[1]=='\\')
1532 BOOL bSeenSlash
= FALSE
;
1535 /* Check for UNC root path */
1538 if (*lpszPath
== '\\')
1544 lpszPath
= CharNextW(lpszPath
);
1549 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1550 return TRUE
; /* X:\ */
1555 /*************************************************************************
1556 * PathIsDirectoryA [SHLWAPI.@]
1558 * Determine if a path is a valid directory
1561 * lpszPath [I] Path to check.
1564 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1565 * FALSE if lpszPath is invalid or not a directory.
1568 * Although this function is prototyped as returning a BOOL, it returns
1569 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1571 * if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1576 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1580 TRACE("(%s)\n", debugstr_a(lpszPath
));
1582 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1585 if (PathIsUNCServerShareA(lpszPath
))
1587 FIXME("UNC Server Share not yet supported - FAILING\n");
1591 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == -1u)
1593 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1596 /*************************************************************************
1597 * PathIsDirectoryW [SHLWAPI.@]
1599 * See PathIsDirectoryA.
1601 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1605 TRACE("(%s)\n", debugstr_w(lpszPath
));
1607 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1610 if (PathIsUNCServerShareW(lpszPath
))
1612 FIXME("UNC Server Share not yet supported - FAILING\n");
1616 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == -1u)
1618 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1621 /*************************************************************************
1622 * PathFileExistsA [SHLWAPI.@]
1624 * Determine if a file exists.
1627 * lpszPath [I] Path to check
1630 * TRUE If the file exists and is readable
1633 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1638 TRACE("(%s)\n",debugstr_a(lpszPath
));
1643 iPrevErrMode
= SetErrorMode(1);
1644 dwAttr
= GetFileAttributesA(lpszPath
);
1645 SetErrorMode(iPrevErrMode
);
1646 return dwAttr
== -1u ? FALSE
: TRUE
;
1649 /*************************************************************************
1650 * PathFileExistsW [SHLWAPI.@]
1652 * See PathFileExistsA
1654 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1659 TRACE("(%s)\n",debugstr_w(lpszPath
));
1664 iPrevErrMode
= SetErrorMode(1);
1665 dwAttr
= GetFileAttributesW(lpszPath
);
1666 SetErrorMode(iPrevErrMode
);
1667 return dwAttr
== -1u ? FALSE
: TRUE
;
1670 /*************************************************************************
1671 * PathMatchSingleMaskA [internal]
1674 * internal (used by PathMatchSpec)
1676 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1678 while (*name
&& *mask
&& *mask
!=';')
1684 if (PathMatchSingleMaskA(name
,mask
+1)) return 1; /* try substrings */
1688 if (toupper(*mask
)!=toupper(*name
) && *mask
!='?') return 0;
1689 name
= CharNextA(name
);
1690 mask
= CharNextA(mask
);
1694 while (*mask
=='*') mask
++;
1695 if (!*mask
|| *mask
==';') return 1;
1700 /*************************************************************************
1701 * PathMatchSingleMaskW [internal]
1703 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1705 while (*name
&& *mask
&& *mask
!=';')
1711 if (PathMatchSingleMaskW(name
,mask
+1)) return 1; /* try substrings */
1715 if (toupperW(*mask
)!=toupperW(*name
) && *mask
!='?') return 0;
1716 name
= CharNextW(name
);
1717 mask
= CharNextW(mask
);
1721 while (*mask
=='*') mask
++;
1722 if (!*mask
|| *mask
==';') return 1;
1727 /*************************************************************************
1728 * PathMatchSpecA [SHLWAPI.@]
1730 * Determine if a path matches one or more search masks.
1733 * lpszPath [I] Path to check
1734 * lpszMask [I} Search mask(s)
1737 * TRUE If lpszPath is valid and is matched
1741 * Multiple search masks may be given if they are seperated by ";". The
1742 * pattern "*.*" is treated specially in that it matches all paths (for
1743 * backwards compatability with DOS).
1745 BOOL WINAPI
PathMatchSpecA(LPCSTR name
, LPCSTR mask
)
1747 TRACE("%s %s\n",name
,mask
);
1749 if (!lstrcmpA( mask
, "*.*" )) return 1; /* we don't require a period */
1753 if (PathMatchSingleMaskA(name
,mask
)) return 1; /* helper function */
1754 while (*mask
&& *mask
!=';') mask
= CharNextA(mask
);
1758 while (*mask
==' ') mask
++; /* masks may be separated by "; " */
1764 /*************************************************************************
1765 * PathMatchSpecW [SHLWAPI.@]
1767 * See PathMatchSpecA.
1769 BOOL WINAPI
PathMatchSpecW(LPCWSTR name
, LPCWSTR mask
)
1771 static const WCHAR stemp
[] = { '*','.','*',0 };
1772 TRACE("%s %s\n",debugstr_w(name
),debugstr_w(mask
));
1774 if (!lstrcmpW( mask
, stemp
)) return 1; /* we don't require a period */
1778 if (PathMatchSingleMaskW(name
,mask
)) return 1; /* helper function */
1779 while (*mask
&& *mask
!=';') mask
= CharNextW(mask
);
1783 while (*mask
==' ') mask
++; /* masks may be separated by "; " */
1789 /*************************************************************************
1790 * PathIsSameRootA [SHLWAPI.@]
1792 * Determine if two paths share the same root.
1795 * lpszPath1 [I] Source path
1796 * lpszPath2 [I] Path to compare with
1799 * TRUE If both paths are valid and share the same root.
1800 * FALSE If either path is invalid or the paths do not share the same root.
1802 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1807 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1809 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1812 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1813 if (lpszStart
- lpszPath1
> dwLen
)
1814 return FALSE
; /* Paths not common up to length of the root */
1818 /*************************************************************************
1819 * PathIsSameRootW [SHLWAPI.@]
1821 * See PathIsSameRootA.
1823 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1828 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1830 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1833 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1834 if (lpszStart
- lpszPath1
> dwLen
)
1835 return FALSE
; /* Paths not common up to length of the root */
1839 /*************************************************************************
1840 * PathIsURLA [SHLWAPI.@]
1842 * Check if the given path is a URL.
1845 * lpszPath [I] Path to check.
1848 * TRUE if lpszPath is a URL.
1849 * FALSE if lpszPath is NULL or not a URL.
1851 BOOL WINAPI
PathIsURLA(LPCSTR lpstrPath
)
1853 UNKNOWN_SHLWAPI_1 base
;
1856 if (!lpstrPath
|| !*lpstrPath
) return FALSE
;
1859 base
.size
= sizeof(base
);
1860 res1
= SHLWAPI_1(lpstrPath
, &base
);
1861 return (base
.fcncde
) ? TRUE
: FALSE
;
1864 /*************************************************************************
1865 * PathIsURLW [SHLWAPI.@]
1867 BOOL WINAPI
PathIsURLW(LPCWSTR lpstrPath
)
1869 UNKNOWN_SHLWAPI_2 base
;
1872 if (!lpstrPath
|| !*lpstrPath
) return FALSE
;
1875 base
.size
= sizeof(base
);
1876 res1
= SHLWAPI_2(lpstrPath
, &base
);
1877 return (base
.fcncde
) ? TRUE
: FALSE
;
1880 /*************************************************************************
1881 * PathIsContentTypeA [SHLWAPI.@]
1883 * Determine if a file is of a given registered content type.
1886 * lpszPath [I] file to check
1889 * TRUE If lpszPath is a given registered content type
1893 * This function looks up the registered content type for lpszPath. If
1894 * a content type is registered, it is compared (case insensitively) to
1895 * lpszContentType. Only if this matches does the function succeed.
1897 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
1901 char szBuff
[MAX_PATH
];
1903 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
1905 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
1906 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
1907 REG_NONE
, szBuff
, &dwDummy
) &&
1908 !strcasecmp(lpszContentType
, szBuff
))
1915 /*************************************************************************
1916 * PathIsContentTypeW [SHLWAPI.@]
1918 * See PathIsContentTypeA.
1920 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
1922 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
1925 WCHAR szBuff
[MAX_PATH
];
1927 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
1929 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
1930 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
1931 REG_NONE
, szBuff
, &dwDummy
) &&
1932 !strcmpiW(lpszContentType
, szBuff
))
1939 /*************************************************************************
1940 * PathIsFileSpecA [SHLWAPI.@]
1942 * Determine if a path is a file specification.
1945 * lpszPath [I] Path to chack
1948 * TRUE If lpszPath is a file spec (contains no directories).
1951 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
1953 TRACE("(%s)\n", debugstr_a(lpszPath
));
1960 if (*lpszPath
== '\\' || *lpszPath
== ':')
1962 lpszPath
= CharNextA(lpszPath
);
1967 /*************************************************************************
1968 * PathIsFileSpecW [SHLWAPI.@]
1970 * See PathIsFileSpecA.
1972 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
1974 TRACE("(%s)\n", debugstr_w(lpszPath
));
1981 if (*lpszPath
== '\\' || *lpszPath
== ':')
1983 lpszPath
= CharNextW(lpszPath
);
1988 /*************************************************************************
1989 * PathIsPrefixA [SHLWAPI.@]
1991 * Determine if a path is a prefix of another.
1994 * lpszPrefix [I] Prefix
1995 * lpszPath [i] Path to check
1998 * TRUE If lpszPath has lpszPrefix as its prefix
1999 * FALSE If either path is NULL or lpszPrefix is not a prefix
2001 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2003 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2005 if (lpszPrefix
&& lpszPath
&&
2006 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2011 /*************************************************************************
2012 * PathIsPrefixW [SHLWAPI.@]
2014 * See PathIsPrefixA.
2016 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2018 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2020 if (lpszPrefix
&& lpszPath
&&
2021 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2026 /*************************************************************************
2027 * PathIsSystemFolderA [SHLWAPI.@]
2029 * Determine if a path or file attributes are a system folder.
2032 * lpszPath [I] Path to check.
2033 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2036 * TRUE If lpszPath or dwAttrib are a system folder.
2037 * FALSE If GetFileAttributesA fails or neither parameter is a system folder.
2039 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2041 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath
), dwAttrib
);
2043 if (lpszPath
&& *lpszPath
)
2044 dwAttrib
= GetFileAttributesA(lpszPath
);
2046 if (dwAttrib
== -1u || !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2047 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2052 /*************************************************************************
2053 * PathIsSystemFolderW [SHLWAPI.@]
2055 * See PathIsSystemFolderA.
2057 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2059 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath
), dwAttrib
);
2061 if (lpszPath
&& *lpszPath
)
2062 dwAttrib
= GetFileAttributesW(lpszPath
);
2064 if (dwAttrib
== -1u || !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2065 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2070 /*************************************************************************
2071 * PathIsUNCA [SHLWAPI.@]
2073 * Determine if a path is in UNC format.
2076 * lpszPath [I] Path to check
2079 * TRUE: The path is UNC.
2080 * FALSE: The path is not UNC or is NULL.
2082 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2084 TRACE("(%s)\n",debugstr_a(lpszPath
));
2086 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2091 /*************************************************************************
2092 * PathIsUNCW [SHLWAPI.@]
2096 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2098 TRACE("(%s)\n",debugstr_w(lpszPath
));
2100 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2105 /*************************************************************************
2106 * PathIsUNCServerA [SHLWAPI.@]
2108 * Determine if a path is a UNC server name ("\\SHARENAME").
2111 * lpszPath [I] Path to check.
2114 * TRUE If lpszPath is a valid UNC server name.
2118 * This routine is bug compatible with Win32: Server names with a
2119 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2120 * Fixing this bug may break other shlwapi functions!
2122 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2124 TRACE("(%s)\n", debugstr_a(lpszPath
));
2126 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2130 if (*lpszPath
== '\\')
2132 lpszPath
= CharNextA(lpszPath
);
2139 /*************************************************************************
2140 * PathIsUNCServerW [SHLWAPI.@]
2142 * See PathIsUNCServerA.
2144 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2146 TRACE("(%s)\n", debugstr_w(lpszPath
));
2148 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2152 if (*lpszPath
== '\\')
2154 lpszPath
= CharNextW(lpszPath
);
2161 /*************************************************************************
2162 * PathIsUNCServerShareA [SHLWAPI.@]
2164 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2167 * lpszPath [I] Path to check.
2170 * TRUE If lpszPath is a valid UNC server share.
2174 * This routine is bug compatible with Win32: Server shares with a
2175 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2176 * Fixing this bug may break other shlwapi functions!
2178 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2180 TRACE("(%s)\n", debugstr_a(lpszPath
));
2182 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2184 BOOL bSeenSlash
= FALSE
;
2187 if (*lpszPath
== '\\')
2193 lpszPath
= CharNextA(lpszPath
);
2200 /*************************************************************************
2201 * PathIsUNCServerShareW [SHLWAPI.@]
2203 * See PathIsUNCServerShareA.
2205 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2207 TRACE("(%s)\n", debugstr_w(lpszPath
));
2209 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2211 BOOL bSeenSlash
= FALSE
;
2214 if (*lpszPath
== '\\')
2220 lpszPath
= CharNextW(lpszPath
);
2227 /*************************************************************************
2228 * PathCanonicalizeA [SHLWAPI.@]
2230 * Convert a path to its canonical form.
2233 * lpszBuf [O] Output path
2234 * lpszPath [I] Path to cnonicalize
2237 * Success: TRUE. lpszBuf contains the output path
2238 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2240 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2244 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2249 if (!lpszBuf
|| !lpszPath
)
2250 SetLastError(ERROR_INVALID_PARAMETER
);
2253 WCHAR szPath
[MAX_PATH
];
2254 WCHAR szBuff
[MAX_PATH
];
2255 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2256 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2257 WideCharToMultiByte(0,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2263 /*************************************************************************
2264 * PathCanonicalizeW [SHLWAPI.@]
2266 * See PathCanonicalizeA.
2268 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2270 LPWSTR lpszDst
= lpszBuf
;
2271 LPCWSTR lpszSrc
= lpszPath
;
2273 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2278 if (!lpszBuf
|| !lpszPath
)
2280 SetLastError(ERROR_INVALID_PARAMETER
);
2291 /* Copy path root */
2292 if (*lpszSrc
== '\\')
2294 *lpszDst
++ = *lpszSrc
++;
2296 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2299 *lpszDst
++ = *lpszSrc
++;
2300 *lpszDst
++ = *lpszSrc
++;
2301 if (*lpszSrc
== '\\')
2302 *lpszDst
++ = *lpszSrc
++;
2305 /* Canonicalize the rest of the path */
2308 if (*lpszSrc
== '.')
2310 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2312 lpszSrc
+= 2; /* Skip .\ */
2314 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2316 /* \.. backs up a directory, over the root if it has no \ following X:.
2317 * .. is ignored if it would remove a UNC server name or inital \\
2319 if (lpszDst
!= lpszBuf
)
2321 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2322 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2323 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2325 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2328 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2330 if (*lpszDst
== '\\')
2331 lpszDst
++; /* Reset to last '\' */
2333 lpszDst
= lpszBuf
; /* Start path again from new root */
2335 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2338 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2340 if (lpszDst
== lpszBuf
)
2346 lpszSrc
+= 2; /* Skip .. in src path */
2349 *lpszDst
++ = *lpszSrc
++;
2352 *lpszDst
++ = *lpszSrc
++;
2354 /* Append \ to naked drive specs */
2355 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2361 /*************************************************************************
2362 * PathFindNextComponentA [SHLWAPI.@]
2364 * Find the next component in a path.
2367 * lpszPath [I] Path to find next component in
2370 * Success: A pointer to the next component, or the end of the string
2371 * Failure: NULL, If lpszPath is invalid
2374 * A 'component' is either a backslash character (\) or UNC marker (\\).
2375 * Because of this, relative paths (e.g "c:foo") are regarded as having
2376 * only one component.
2378 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2382 TRACE("(%s)\n", debugstr_a(lpszPath
));
2384 if(!lpszPath
|| !*lpszPath
)
2387 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2389 if (lpszSlash
[1] == '\\')
2391 return lpszSlash
+ 1;
2393 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2396 /*************************************************************************
2397 * PathFindNextComponentW [SHLWAPI.@]
2399 * See PathFindNextComponentA.
2401 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2405 TRACE("(%s)\n", debugstr_w(lpszPath
));
2407 if(!lpszPath
|| !*lpszPath
)
2410 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2412 if (lpszSlash
[1] == '\\')
2414 return lpszSlash
+ 1;
2416 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2419 /*************************************************************************
2420 * PathAddExtensionA [SHLWAPI.@]
2422 * Add a file extension to a path
2425 * lpszPath [O] Path to add extension to
2426 * lpszExtension [I} Extension to add to lpszPath
2429 * TRUE If the path was modified
2430 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2431 * extension allready, or the new path length is too big.
2434 * What version of shlwapi.dll adds "exe" if pszExtension is NULL? Win2k
2435 * does not do this, so the behaviour was removed.
2437 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2441 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2443 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2446 dwLen
= strlen(lpszPath
);
2448 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2451 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2455 /*************************************************************************
2456 * PathAddExtensionW [SHLWAPI.@]
2458 * See PathAddExtensionA.
2460 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2464 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2466 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2469 dwLen
= strlenW(lpszPath
);
2471 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2474 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2478 /*************************************************************************
2479 * PathMakePrettyA [SHLWAPI.@]
2481 * Convert an uppercase DOS filename into lowercase.
2484 * lpszPath [O] Path to convert.
2487 * TRUE If the path was an uppercase DOS path and was converted
2490 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2492 LPSTR pszIter
= lpszPath
;
2494 TRACE("(%s)\n", debugstr_a(lpszPath
));
2496 if (!pszIter
|| !*pszIter
)
2501 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2502 return FALSE
; /* Not DOS path */
2505 pszIter
= lpszPath
+ 1;
2508 *pszIter
= tolower(*pszIter
);
2514 /*************************************************************************
2515 * PathMakePrettyW [SHLWAPI.@]
2517 * See PathMakePrettyA
2519 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2521 LPWSTR pszIter
= lpszPath
;
2523 TRACE("(%s)\n", debugstr_w(lpszPath
));
2525 if (!pszIter
|| !*pszIter
)
2530 if (islowerW(*pszIter
))
2531 return FALSE
; /* Not DOS path */
2534 pszIter
= lpszPath
+ 1;
2537 *pszIter
= tolowerW(*pszIter
);
2543 /*************************************************************************
2544 * PathCommonPrefixA [SHLWAPI.@]
2546 * Determine the length of the common prefix between two paths.
2549 * lpszFile1 [I] First path for comparason
2550 * lpszFile2 [I] Second path for comparason
2551 * achPath [O] Destination for common prefix string
2554 * The length of the common prefix. This is 0 if there is no common
2555 * prefix between the paths or if any parameters are invalid. If the prefix
2556 * is non-zero and achPath is not NULL, achPath is filled with the common
2557 * part of the prefix and NUL terminated.
2560 * A common prefix of 2 is always returned as 3. It is thus possible for
2561 * the length returned to be invalid (i.e. Longer than one or both of the
2562 * strings given as parameters). This Win32 behaviour has been implimented
2563 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2564 * To work around this when using this function, always check that the byte
2565 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2567 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2570 LPCSTR lpszIter1
= lpszFile1
;
2571 LPCSTR lpszIter2
= lpszFile2
;
2573 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2578 if (!lpszFile1
|| !lpszFile2
)
2581 /* Handle roots first */
2582 if (PathIsUNCA(lpszFile1
))
2584 if (!PathIsUNCA(lpszFile2
))
2589 else if (PathIsUNCA(lpszFile2
))
2590 return 0; /* Know already lpszFile1 is not UNC */
2595 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2596 (!*lpszIter2
|| *lpszIter2
== '\\'))
2597 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2599 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2600 break; /* Strings differ at this point */
2607 iLen
++; /* Feature/Bug compatable with Win32 */
2609 if (iLen
&& achPath
)
2611 memcpy(achPath
,lpszFile1
,iLen
);
2612 achPath
[iLen
] = '\0';
2617 /*************************************************************************
2618 * PathCommonPrefixW [SHLWAPI.@]
2620 * See PathCommonPrefixA.
2622 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2625 LPCWSTR lpszIter1
= lpszFile1
;
2626 LPCWSTR lpszIter2
= lpszFile2
;
2628 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2633 if (!lpszFile1
|| !lpszFile2
)
2636 /* Handle roots first */
2637 if (PathIsUNCW(lpszFile1
))
2639 if (!PathIsUNCW(lpszFile2
))
2644 else if (PathIsUNCW(lpszFile2
))
2645 return 0; /* Know already lpszFile1 is not UNC */
2650 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2651 (!*lpszIter2
|| *lpszIter2
== '\\'))
2652 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2654 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2655 break; /* Strings differ at this point */
2662 iLen
++; /* Feature/Bug compatable with Win32 */
2664 if (iLen
&& achPath
)
2666 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2667 achPath
[iLen
] = '\0';
2672 /*************************************************************************
2673 * PathCompactPathA [SHLWAPI.@]
2675 * Make a path fit into a given width when printed to a DC.
2678 * hDc [I] Destination DC
2679 * lpszPath [O] Path to be printed to hDc
2680 * dx [i] Desired width
2683 * TRUE If the path was modified.
2686 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2690 TRACE("(%08x,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2694 WCHAR szPath
[MAX_PATH
];
2695 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2696 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2697 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2702 /*************************************************************************
2703 * PathCompactPathW [SHLWAPI.@]
2705 * See PathCompactPathA.
2707 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2709 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2712 WCHAR buff
[MAX_PATH
];
2716 TRACE("(%08x,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2722 hdc
= hDC
= GetDC(0);
2724 /* Get the length of the whole path */
2725 dwLen
= strlenW(lpszPath
);
2726 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2728 if ((UINT
)size
.cx
> dx
)
2730 /* Path too big, must reduce it */
2732 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2734 sFile
= PathFindFileNameW(lpszPath
);
2735 if (sFile
!= lpszPath
)
2736 sFile
= CharPrevW(lpszPath
, sFile
);
2738 /* Get the size of ellipses */
2739 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2740 dwEllipsesLen
= size
.cx
;
2741 /* Get the size of the file name */
2742 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2743 dwPathLen
= size
.cx
;
2745 if (sFile
!= lpszPath
)
2747 LPWSTR sPath
= sFile
;
2748 BOOL bEllipses
= FALSE
;
2750 /* The path includes a file name. Include as much of the path prior to
2751 * the file name as possible, allowing for the ellipses, e.g:
2752 * c:\some very long path\filename ==> c:\some v...\filename
2754 strncpyW(buff
, sFile
, MAX_PATH
);
2758 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2760 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2761 dwTotalLen
+= size
.cx
;
2762 if (dwTotalLen
<= dx
)
2764 sPath
= CharPrevW(lpszPath
, sPath
);
2768 sPath
= CharPrevW(lpszPath
, sPath
);
2769 sPath
= CharPrevW(lpszPath
, sPath
);
2771 } while (sPath
> lpszPath
);
2773 if (sPath
> lpszPath
)
2777 strcpyW(sPath
, szEllipses
);
2778 strcpyW(sPath
+3, buff
);
2784 strcpyW(lpszPath
, szEllipses
);
2785 strcpyW(lpszPath
+3, buff
);
2789 /* Trim the path by adding ellipses to the end, e.g:
2790 * A very long file name.txt ==> A very...
2792 dwLen
= strlenW(lpszPath
);
2794 if (dwLen
> MAX_PATH
- 3)
2795 dwLen
= MAX_PATH
- 3;
2796 strncpyW(buff
, sFile
, dwLen
);
2800 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2801 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2805 DWORD dwWritten
= 0;
2807 dwEllipsesLen
/= 3; /* Size of a single '.' */
2809 /* Write as much of the Ellipses string as possible */
2810 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2813 dwWritten
+= dwEllipsesLen
;
2821 strcpyW(buff
+ dwLen
, szEllipses
);
2822 strcpyW(lpszPath
, buff
);
2832 /*************************************************************************
2833 * PathGetCharTypeA [SHLWAPI.@]
2835 * Categorise a character from a file path.
2838 * ch [I] Character to get the type of
2841 * A set of GCT_ bit flags (from shlwapi.h) indicating the character type.
2843 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2845 return PathGetCharTypeW(ch
);
2848 /*************************************************************************
2849 * PathGetCharTypeW [SHLWAPI.@]
2851 * See PathGetCharTypeA.
2853 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2857 TRACE("(%d)\n", ch
);
2859 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2860 ch
== '"' || ch
== '|' || ch
== '/')
2861 flags
= GCT_INVALID
; /* Invalid */
2862 else if (ch
== '*' || ch
=='?')
2863 flags
= GCT_WILD
; /* Wildchars */
2864 else if ((ch
== '\\') || (ch
== ':'))
2865 return GCT_SEPARATOR
; /* Path separators */
2870 if ((ch
& 0x1 && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2871 ch
== '.' || ch
== '@' || ch
== '^' ||
2872 ch
== '\'' || ch
== 130 || ch
== '`')
2873 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2876 flags
|= GCT_SHORTCHAR
; /* Bug compatable with win32 */
2877 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2882 /*************************************************************************
2883 * SHLWAPI_UseSystemForSystemFolders
2885 * Internal helper for PathMakeSystemFolderW.
2887 static BOOL
SHLWAPI_UseSystemForSystemFolders()
2889 static BOOL bCheckedReg
= FALSE
;
2890 static BOOL bUseSystemForSystemFolders
= FALSE
;
2896 /* Key tells Win what file attributes to use on system folders */
2897 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
2898 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2899 "UseSystemForSystemFolders", 0, 0, 0))
2900 bUseSystemForSystemFolders
= TRUE
;
2902 return bUseSystemForSystemFolders
;
2905 /*************************************************************************
2906 * PathMakeSystemFolderA [SHLWAPI.@]
2908 * Set system folder attribute for a path.
2911 * lpszPath [I] The path to turn into a system folder
2914 * TRUE If the path was changed to/already was a system folder
2915 * FALSE If the path is invalid or SetFileAttributesA fails
2917 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
2921 TRACE("(%s)\n", debugstr_a(lpszPath
));
2923 if (lpszPath
&& *lpszPath
)
2925 WCHAR szPath
[MAX_PATH
];
2926 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2927 bRet
= PathMakeSystemFolderW(szPath
);
2932 /*************************************************************************
2933 * PathMakeSystemFolderW [SHLWAPI.@]
2935 * See PathMakeSystemFolderA.
2937 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
2939 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
2940 WCHAR buff
[MAX_PATH
];
2942 TRACE("(%s)\n", debugstr_w(lpszPath
));
2944 if (!lpszPath
|| !*lpszPath
)
2947 /* If the directory is already a system directory, dont do anything */
2948 GetSystemDirectoryW(buff
, MAX_PATH
);
2949 if (!strcmpW(buff
, lpszPath
))
2952 GetWindowsDirectoryW(buff
, MAX_PATH
);
2953 if (!strcmpW(buff
, lpszPath
))
2956 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
2957 if (SHLWAPI_UseSystemForSystemFolders())
2958 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
2960 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == -1u)
2963 /* Change file attributes to system attributes */
2964 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
2965 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
2968 /*************************************************************************
2969 * PathRenameExtensionA [SHLWAPI.@]
2971 * Swap the file extension in a path with another extension.
2974 * pszPath [O] Path to swap the extension in
2975 * pszExt [I] The new extension
2978 * TRUE if pszPath was modified
2979 * FALSE if pszPath or pszExt is NULL, or the new path is too long
2981 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
2983 LPSTR lpszExtension
;
2985 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
2987 lpszExtension
= PathFindExtensionA(lpszPath
);
2989 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
2992 strcpy(lpszExtension
, lpszExt
);
2996 /*************************************************************************
2997 * PathRenameExtensionW [SHLWAPI.@]
2999 * See PathRenameExtensionA.
3001 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3003 LPWSTR lpszExtension
;
3005 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3007 lpszExtension
= PathFindExtensionW(lpszPath
);
3009 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3012 strcpyW(lpszExtension
, lpszExt
);
3016 /*************************************************************************
3017 * PathSearchAndQualifyA [SHLWAPI.@]
3019 * Determine if a given path is correct and fully qualified.
3022 * lpszPath [I] Path to check
3023 * lpszBuf [O] Output for correct path
3024 * cchBuf [I] Size of lpszBuf
3029 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3031 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3035 /*************************************************************************
3036 * PathSearchAndQualifyW [SHLWAPI.@]
3038 * See PathSearchAndQualifyA
3040 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3042 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3046 /*************************************************************************
3047 * PathSkipRootA [SHLWAPI.@]
3049 * Return the portion of a path following the drive letter or mount point.
3052 * lpszPath [I] The path to skip on
3055 * Success: A pointer to the next character after the root.
3056 * Failure: NULL, if lpszPath is invalid, has no root or is a MB string.
3058 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3060 TRACE("(%s)\n", debugstr_a(lpszPath
));
3062 if (!lpszPath
|| !*lpszPath
)
3065 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3067 /* Network share: skip share server and mount point */
3069 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3070 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3072 return (LPSTR
)lpszPath
;
3075 if (IsDBCSLeadByte(*lpszPath
))
3079 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3080 return (LPSTR
)lpszPath
+ 3;
3084 /*************************************************************************
3085 * PathSkipRootW [SHLWAPI.@]
3087 * See PathSkipRootA.
3089 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3091 TRACE("(%s)\n", debugstr_w(lpszPath
));
3093 if (!lpszPath
|| !*lpszPath
)
3096 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3098 /* Network share: skip share server and mount point */
3100 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3101 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3103 return (LPWSTR
)lpszPath
;
3107 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3108 return (LPWSTR
)lpszPath
+ 3;
3112 /*************************************************************************
3113 * PathCreateFromUrlA [SHLWAPI.@]
3115 * Create a path from a URL
3118 * lpszUrl [I] URL to convert into a path
3119 * lpszPath [O] Output buffer for the resulting Path
3120 * pcchPath [I] Length of lpszPath
3121 * dwFlags [I] Flags controlling the conversion
3124 * Success: S_OK. lpszPath contains the URL in path format
3125 * Failure: An HRESULT error code such as E_INVALIDARG.
3127 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR lpszUrl
, LPSTR lpszPath
,
3128 LPDWORD pcchPath
, DWORD dwFlags
)
3130 FIXME("(%s,%p,%p,0x%08lx)-stub\n", debugstr_a(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3132 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3133 return E_INVALIDARG
;
3135 /* extracts thing prior to : in pszURL and checks against:
3139 * about - if match returns E_INVALIDARG
3145 /*************************************************************************
3146 * PathCreateFromUrlW [SHLWAPI.@]
3148 * See PathCreateFromUrlA.
3150 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR lpszUrl
, LPWSTR lpszPath
,
3151 LPDWORD pcchPath
, DWORD dwFlags
)
3153 FIXME("(%s,%p,%p,0x%08lx)-stub\n", debugstr_w(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3155 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3156 return E_INVALIDARG
;
3161 /*************************************************************************
3162 * PathRelativePathToA [SHLWAPI.@]
3164 * Create a relative path from one path to another.
3167 * lpszPath [O] Destination for relative path
3168 * lpszFrom [I] Source path
3169 * dwAttrFrom [I] File attribute of source path
3170 * lpszTo [I] Destination path
3171 * dwAttrTo [I] File attributes of destination path
3174 * TRUE If a relative path can be formed. lpszPath contains the new path
3175 * FALSE If the paths are not relavtive or any parameters are invalid
3178 * lpszTo should be at least MAX_PATH in length.
3179 * Calling this function with relative paths for lpszFrom or lpszTo may
3180 * give erroneous results.
3182 * The Win32 version of this function contains a bug where the lpszTo string
3183 * may be referenced 1 byte beyond the end of the string. As a result random
3184 * garbage may be written to the output path, depending on what lies beyond
3185 * the last byte of the string. This bug occurs because of the behaviour of
3186 * PathCommonPrefix (see notes for that function), and no workaround seems
3187 * possible with Win32.
3188 * This bug has been fixed here, so for example the relative path from "\\"
3189 * to "\\" is correctly determined as "." in this implementation.
3191 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3192 LPCSTR lpszTo
, DWORD dwAttrTo
)
3196 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_a(lpszFrom
),
3197 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3199 if(lpszPath
&& lpszFrom
&& lpszTo
)
3201 WCHAR szPath
[MAX_PATH
];
3202 WCHAR szFrom
[MAX_PATH
];
3203 WCHAR szTo
[MAX_PATH
];
3204 MultiByteToWideChar(0,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3205 MultiByteToWideChar(0,0,lpszTo
,-1,szTo
,MAX_PATH
);
3206 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3207 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3212 /*************************************************************************
3213 * PathRelativePathToW [SHLWAPI.@]
3215 * See PathRelativePathToA.
3217 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3218 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3220 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3221 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3222 WCHAR szFrom
[MAX_PATH
];
3223 WCHAR szTo
[MAX_PATH
];
3226 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_w(lpszFrom
),
3227 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3229 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3233 strncpyW(szFrom
, lpszFrom
, MAX_PATH
);
3234 strncpyW(szTo
, lpszTo
, MAX_PATH
);
3236 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3237 PathRemoveFileSpecW(szFrom
);
3238 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3239 PathRemoveFileSpecW(szTo
);
3241 /* Paths can only be relative if they have a common root */
3242 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3245 /* Strip off lpszFrom components to the root, by adding "..\" */
3246 lpszFrom
= szFrom
+ dwLen
;
3252 if (*lpszFrom
== '\\')
3257 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3258 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3261 /* From the root add the components of lpszTo */
3263 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3266 if (*lpszTo
&& lpszTo
[-1])
3268 if (*lpszTo
!= '\\')
3270 dwLen
= strlenW(lpszPath
);
3271 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3276 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3281 /*************************************************************************
3282 * PathUnmakeSystemFolderA [SHLWAPI.@]
3284 * Remove the system folder attributes from a path.
3287 * lpszPath [I] The path to remove attributes from
3291 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3292 * SetFileAttributesA fails.
3294 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3298 TRACE("(%s)\n", debugstr_a(lpszPath
));
3300 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == -1u ||
3301 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3304 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3305 return SetFileAttributesA(lpszPath
, dwAttr
);
3308 /*************************************************************************
3309 * PathUnmakeSystemFolderW [SHLWAPI.@]
3311 * See PathUnmakeSystemFolderA.
3313 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3317 TRACE("(%s)\n", debugstr_w(lpszPath
));
3319 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == -1u ||
3320 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3323 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3324 return SetFileAttributesW(lpszPath
, dwAttr
);
3328 /*************************************************************************
3329 * PathSetDlgItemPathA [SHLWAPI.@]
3331 * Set the text of a dialog item to a path, shrinking the path to fit
3332 * if it is too big for the item.
3335 * hDlg [I] Dialog handle
3336 * id [I] ID of item in the dialog
3337 * lpszPath [I] Path to set as the items text
3343 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3344 * window text is erased).
3346 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3348 WCHAR szPath
[MAX_PATH
];
3350 TRACE("(%8x,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3353 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3356 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3359 /*************************************************************************
3360 * PathSetDlgItemPathW [SHLWAPI.@]
3362 * See PathSetDlgItemPathA.
3364 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3366 WCHAR path
[MAX_PATH
+ 1];
3372 TRACE("(%8x,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3374 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3378 strncpyW(path
, lpszPath
, sizeof(path
));
3382 GetClientRect(hwItem
, &rect
);
3384 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3388 PathCompactPathW(hdc
, path
, rect
.right
);
3389 SelectObject(hdc
, hPrevObj
);
3392 ReleaseDC(hDlg
, hdc
);
3393 SetWindowTextW(hwItem
, path
);
3396 /*************************************************************************
3397 * PathIsNetworkPathA [SHLWAPI.@]
3399 * Determine if the given path is a network path.
3402 * lpszPath [I] Path to check
3405 * TRUE If path is a UNC share or mapped network drive
3406 * FALSE If path is a local drive or cannot be determined
3408 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3412 TRACE("(%s)\n",debugstr_a(lpszPath
));
3416 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3418 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3419 if (dwDriveNum
== -1u)
3421 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3422 return pIsNetDrive(dwDriveNum
);
3425 /*************************************************************************
3426 * PathIsNetworkPathW [SHLWAPI.@]
3428 * See PathIsNetworkPathA.
3430 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3434 TRACE("(%s)\n", debugstr_w(lpszPath
));
3438 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3440 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3441 if (dwDriveNum
== -1u)
3443 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3444 return pIsNetDrive(dwDriveNum
);
3447 /*************************************************************************
3448 * PathIsLFNFileSpecA [SHLWAPI.@]
3450 * Determine if the given path is a long file name
3453 * lpszPath [I] Path to check
3456 * TRUE If path is a long file name
3457 * FALSE If path is a valid DOS 8.3 file name
3459 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3461 DWORD dwNameLen
= 0, dwExtLen
= 0;
3463 TRACE("(%s)\n",debugstr_a(lpszPath
));
3470 if (*lpszPath
== ' ')
3471 return TRUE
; /* DOS names cannot have spaces */
3472 if (*lpszPath
== '.')
3475 return TRUE
; /* DOS names have only one dot */
3482 return TRUE
; /* DOS extensions are <= 3 chars*/
3488 return TRUE
; /* DOS names are <= 8 chars */
3490 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3492 return FALSE
; /* Valid DOS path */
3495 /*************************************************************************
3496 * PathIsLFNFileSpecW [SHLWAPI.@]
3498 * See PathIsLFNFileSpecA.
3500 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3502 DWORD dwNameLen
= 0, dwExtLen
= 0;
3504 TRACE("(%s)\n",debugstr_w(lpszPath
));
3511 if (*lpszPath
== ' ')
3512 return TRUE
; /* DOS names cannot have spaces */
3513 if (*lpszPath
== '.')
3516 return TRUE
; /* DOS names have only one dot */
3523 return TRUE
; /* DOS extensions are <= 3 chars*/
3529 return TRUE
; /* DOS names are <= 8 chars */
3533 return FALSE
; /* Valid DOS path */
3536 /*************************************************************************
3537 * PathIsDirectoryEmptyA [SHLWAPI.@]
3539 * Determine if a given directory is empty.
3542 * lpszPath [I] Directory to check
3545 * TRUE If the directory exists and contains no files
3548 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3552 TRACE("(%s)\n",debugstr_a(lpszPath
));
3556 WCHAR szPath
[MAX_PATH
];
3557 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3558 bRet
= PathIsDirectoryEmptyW(szPath
);
3563 /*************************************************************************
3564 * PathIsDirectoryEmptyW [SHLWAPI.@]
3566 * See PathIsDirectoryEmptyA.
3568 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3570 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3571 WCHAR szSearch
[MAX_PATH
];
3574 BOOL retVal
= FALSE
;
3575 WIN32_FIND_DATAW find_data
;
3577 TRACE("(%s)\n",debugstr_w(lpszPath
));
3579 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3582 strncpyW(szSearch
, lpszPath
, MAX_PATH
);
3583 PathAddBackslashW(szSearch
);
3584 dwLen
= strlenW(szSearch
);
3585 if (dwLen
> MAX_PATH
- 4)
3588 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3589 hfind
= FindFirstFileW(szSearch
, &find_data
);
3591 if (hfind
!= INVALID_HANDLE_VALUE
&&
3592 find_data
.cFileName
[0] == '.' &&
3593 find_data
.cFileName
[1] == '.')
3595 /* The only directory entry should be the parent */
3596 if (!FindNextFileW(hfind
, &find_data
))
3604 /*************************************************************************
3605 * PathFindSuffixArrayA [SHLWAPI.@]
3607 * Find a suffix string in an array of suffix strings
3610 * lpszSuffix [I] Suffix string to search for
3611 * lppszArray [I] Array of suffix strings to search
3612 * dwCount [I] Number of elements in lppszArray
3615 * Success The index of the position of lpszSuffix in lppszArray
3616 * Failure 0, if any parameters are invalid or lpszSuffix is not found
3619 * The search is case sensitive.
3620 * The match is made against the end of the suffix string, so for example:
3621 * lpszSuffix=fooBAR matches BAR, but lpszSuffix=fooBARfoo does not.
3623 int WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3628 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3630 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3632 dwLen
= strlen(lpszSuffix
);
3634 while (dwRet
< dwCount
)
3636 DWORD dwCompareLen
= strlen(*lppszArray
);
3637 if (dwCompareLen
< dwLen
)
3639 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3640 return dwRet
; /* Found */
3649 /*************************************************************************
3650 * PathFindSuffixArrayW [SHLWAPI.@]
3652 * See PathFindSuffixArrayA.
3654 int WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3659 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3661 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3663 dwLen
= strlenW(lpszSuffix
);
3665 while (dwRet
< dwCount
)
3667 DWORD dwCompareLen
= strlenW(*lppszArray
);
3668 if (dwCompareLen
< dwLen
)
3670 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3671 return dwRet
; /* Found */
3680 /*************************************************************************
3681 * PathUndecorateA [SHLWAPI.@]
3683 * Undecorate a file path
3686 * lpszPath [O] Path to undecorate
3692 * A decorations form is "path[n].ext" where n is an optional decimal number.
3694 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3696 TRACE("(%s)\n",debugstr_a(lpszPath
));
3700 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3701 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3703 LPSTR lpszSkip
= lpszExt
- 2;
3704 if (*lpszSkip
== '[')
3705 lpszSkip
++; /* [] (no number) */
3707 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3709 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3711 /* remove the [n] */
3714 *lpszSkip
++ = *lpszExt
++;
3721 /*************************************************************************
3722 * PathUndecorateW [SHLWAPI.@]
3724 * See PathUndecorateA.
3726 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3728 TRACE("(%s)\n",debugstr_w(lpszPath
));
3732 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3733 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3735 LPWSTR lpszSkip
= lpszExt
- 2;
3736 if (*lpszSkip
== '[')
3737 lpszSkip
++; /* [] (no number) */
3739 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3741 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3743 /* remove the [n] */
3746 *lpszSkip
++ = *lpszExt
++;