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"
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 if (!(func = (void*)GetProcAddress(SHLWAPI_h##module, name))) return fail; \
50 /* DLL handles for late bound calls */
51 extern HMODULE SHLWAPI_hshell32
;
53 /* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
54 static BOOL (WINAPI
*pIsNetDrive
)(DWORD
);
56 /*************************************************************************
57 * PathAppendA [SHLWAPI.@]
59 * Append one path to another.
62 * lpszPath [O] Initial part of path
63 * lpszAppend [I] Path to append
66 * Success: TRUE. lpszPath contains the newly created path.
67 * Failure: FALSE, if either path is NULL, or PathCombineA fails.
70 * lpszAppend must contain at least one backslash ('\') if not NULL.
71 * Because PathCombineA is used to join the paths, the resulting
72 * path is also canonicalized.
74 BOOL WINAPI
PathAppendA (LPSTR lpszPath
, LPCSTR lpszAppend
)
76 TRACE("(%s,%s)\n",debugstr_a(lpszPath
), debugstr_a(lpszAppend
));
78 if (lpszPath
&& lpszAppend
)
80 if (!PathIsUNCA(lpszAppend
))
81 while (*lpszAppend
== '\\')
83 if (PathCombineA(lpszPath
, lpszPath
, lpszAppend
))
89 /*************************************************************************
90 * PathAppendW [SHLWAPI.@]
94 BOOL WINAPI
PathAppendW(LPWSTR lpszPath
, LPCWSTR lpszAppend
)
96 TRACE("(%s,%s)\n",debugstr_w(lpszPath
), debugstr_w(lpszAppend
));
98 if (lpszPath
&& lpszAppend
)
100 if (!PathIsUNCW(lpszAppend
))
101 while (*lpszAppend
== '\\')
103 if (PathCombineW(lpszPath
, lpszPath
, lpszAppend
))
109 /*************************************************************************
110 * PathCombineA [SHLWAPI.@]
112 * Combine two paths together.
115 * lpszDest [O] Destination for combined path
116 * lpszDir [I] Directory path
117 * liszFile [I] File path
120 * Success: The output path
121 * Failure: NULL, if inputs are invalid.
124 * lpszDest should be at least MAX_PATH in size, and may point to the same
125 * memory location as lpszDir. The combined path is canonicalised.
127 LPSTR WINAPI
PathCombineA(LPSTR lpszDest
, LPCSTR lpszDir
, LPCSTR lpszFile
)
129 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_a(lpszDir
), debugstr_a(lpszFile
));
131 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
132 return NULL
; /* Invalid parameters */
135 WCHAR szDest
[MAX_PATH
];
136 WCHAR szDir
[MAX_PATH
];
137 WCHAR szFile
[MAX_PATH
];
139 MultiByteToWideChar(0,0,lpszDir
,-1,szDir
,MAX_PATH
);
141 MultiByteToWideChar(0,0,lpszFile
,-1,szFile
,MAX_PATH
);
142 PathCombineW(szDest
, lpszDir
? szDir
: NULL
, lpszFile
? szFile
: NULL
);
143 WideCharToMultiByte(0,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
148 /*************************************************************************
149 * PathCombineW [SHLWAPI.@]
153 LPWSTR WINAPI
PathCombineW(LPWSTR lpszDest
, LPCWSTR lpszDir
, LPCWSTR lpszFile
)
155 WCHAR szTemp
[MAX_PATH
];
156 BOOL bUseBoth
= FALSE
, bStrip
= FALSE
;
158 TRACE("(%p,%s,%s)\n", lpszDest
, debugstr_w(lpszDir
), debugstr_w(lpszFile
));
160 if (!lpszDest
|| (!lpszDir
&& !lpszFile
))
161 return lpszDest
; /* Invalid parameters */
163 if (!lpszFile
|| !*lpszFile
)
166 strncpyW(szTemp
, lpszDir
, MAX_PATH
);
168 else if (!lpszDir
|| !*lpszDir
|| !PathIsRelativeW(lpszFile
))
170 if (!lpszDir
|| !*lpszDir
|| *lpszFile
!= '\\' || PathIsUNCW(lpszFile
))
173 strncpyW(szTemp
, lpszFile
, MAX_PATH
);
186 strncpyW(szTemp
, lpszDir
, MAX_PATH
);
189 PathStripToRootW(szTemp
);
190 lpszFile
++; /* Skip '\' */
192 if (!PathAddBackslashW(szTemp
))
194 if (strlenW(szTemp
) + strlenW(lpszFile
) >= MAX_PATH
)
196 strcatW(szTemp
, lpszFile
);
199 PathCanonicalizeW(lpszDest
, szTemp
);
203 /*************************************************************************
204 * PathAddBackslashA [SHLWAPI.@]
206 * Append a backslash ('\') to a path if one doesn't exist.
209 * lpszPath [O] The path to append a backslash to.
212 * Success: The position of the last backslash in the path.
213 * Failure: NULL, if lpszPath is NULL or the path is too large.
215 LPSTR WINAPI
PathAddBackslashA(LPSTR lpszPath
)
219 TRACE("(%s)\n",debugstr_a(lpszPath
));
221 if (!lpszPath
|| (iLen
= strlen(lpszPath
)) >= MAX_PATH
)
227 if (lpszPath
[-1] != '\\')
236 /*************************************************************************
237 * PathAddBackslashW [SHLWAPI.@]
239 * See PathAddBackslashA.
241 LPWSTR WINAPI
PathAddBackslashW( LPWSTR lpszPath
)
245 TRACE("(%s)\n",debugstr_w(lpszPath
));
247 if (!lpszPath
|| (iLen
= strlenW(lpszPath
)) >= MAX_PATH
)
253 if (lpszPath
[-1] != '\\')
262 /*************************************************************************
263 * PathBuildRootA [SHLWAPI.@]
265 * Create a root drive string (e.g. "A:\") from a drive number.
268 * lpszPath [O] Destination for the drive string
274 * If lpszPath is NULL or drive is invalid, nothing is written to lpszPath.
276 LPSTR WINAPI
PathBuildRootA(LPSTR lpszPath
, int drive
)
278 TRACE("(%p,%d)\n", debugstr_a(lpszPath
), drive
);
280 if (lpszPath
&& drive
>= 0 && drive
< 26)
282 lpszPath
[0] = 'A' + drive
;
290 /*************************************************************************
291 * PathBuildRootW [SHLWAPI.@]
293 * See PathBuildRootA.
295 LPWSTR WINAPI
PathBuildRootW(LPWSTR lpszPath
, int drive
)
297 TRACE("(%p,%d)\n",debugstr_w(lpszPath
), drive
);
299 if (lpszPath
&& drive
>= 0 && drive
< 26)
301 lpszPath
[0] = 'A' + drive
;
309 /*************************************************************************
310 * PathFindFileNameA [SHLWAPI.@]
312 * Locate the start of the file name in a path
315 * lpszPath [I] Path to search
318 * A pointer to the first character of the file name
320 LPSTR WINAPI
PathFindFileNameA(LPCSTR lpszPath
)
322 LPCSTR lastSlash
= lpszPath
;
324 TRACE("(%s)\n",debugstr_a(lpszPath
));
326 while (lpszPath
&& *lpszPath
)
328 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
329 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
330 lastSlash
= lpszPath
+ 1;
331 lpszPath
= CharNextA(lpszPath
);
333 return (LPSTR
)lastSlash
;
336 /*************************************************************************
337 * PathFindFileNameW [SHLWAPI.@]
339 * See PathFindFileNameA.
341 LPWSTR WINAPI
PathFindFileNameW(LPCWSTR lpszPath
)
343 LPCWSTR lastSlash
= lpszPath
;
345 TRACE("(%s)\n",debugstr_w(lpszPath
));
347 while (lpszPath
&& *lpszPath
)
349 if ((*lpszPath
== '\\' || *lpszPath
== '/' || *lpszPath
== ':') &&
350 lpszPath
[1] && lpszPath
[1] != '\\' && lpszPath
[1] != '/')
351 lastSlash
= lpszPath
+ 1;
352 lpszPath
= CharNextW(lpszPath
);
354 return (LPWSTR
)lastSlash
;
357 /*************************************************************************
358 * PathFindExtensionA [SHLWAPI.@]
360 * Locate the start of the file extension in a path
363 * lpszPath [I] The path to search
366 * A pointer to the first character of the extension, the end of
367 * the string if the path has no extension, or NULL If lpszPath is NULL
369 LPSTR WINAPI
PathFindExtensionA( LPCSTR lpszPath
)
371 LPCSTR lastpoint
= NULL
;
373 TRACE("(%s)\n", debugstr_a(lpszPath
));
379 if (*lpszPath
== '\\' || *lpszPath
==' ')
381 else if (*lpszPath
== '.')
382 lastpoint
= lpszPath
;
383 lpszPath
= CharNextA(lpszPath
);
386 return (LPSTR
)(lastpoint
? lastpoint
: lpszPath
);
389 /*************************************************************************
390 * PathFindExtensionW [SHLWAPI.@]
392 * See PathFindExtensionA.
394 LPWSTR WINAPI
PathFindExtensionW( LPCWSTR lpszPath
)
396 LPCWSTR lastpoint
= NULL
;
398 TRACE("(%s)\n", debugstr_w(lpszPath
));
404 if (*lpszPath
== '\\' || *lpszPath
==' ')
406 else if (*lpszPath
== '.')
407 lastpoint
= lpszPath
;
408 lpszPath
= CharNextW(lpszPath
);
411 return (LPWSTR
)(lastpoint
? lastpoint
: lpszPath
);
414 /*************************************************************************
415 * PathGetArgsA [SHLWAPI.@]
417 * Find the next argument in a string delimited by spaces.
420 * lpszPath [I] The string to search for arguments in
423 * The start of the next argument in lpszPath, or NULL if lpszPath is NULL
426 * Spaces in quoted strings are ignored as delimiters.
428 LPSTR WINAPI
PathGetArgsA(LPCSTR lpszPath
)
430 BOOL bSeenQuote
= FALSE
;
432 TRACE("(%s)\n",debugstr_a(lpszPath
));
438 if ((*lpszPath
==' ') && !bSeenQuote
)
439 return (LPSTR
)lpszPath
+ 1;
440 if (*lpszPath
== '"')
441 bSeenQuote
= !bSeenQuote
;
442 lpszPath
= CharNextA(lpszPath
);
445 return (LPSTR
)lpszPath
;
448 /*************************************************************************
449 * PathGetArgsW [SHLWAPI.@]
453 LPWSTR WINAPI
PathGetArgsW(LPCWSTR lpszPath
)
455 BOOL bSeenQuote
= FALSE
;
457 TRACE("(%s)\n",debugstr_w(lpszPath
));
463 if ((*lpszPath
==' ') && !bSeenQuote
)
464 return (LPWSTR
)lpszPath
+ 1;
465 if (*lpszPath
== '"')
466 bSeenQuote
= !bSeenQuote
;
467 lpszPath
= CharNextW(lpszPath
);
470 return (LPWSTR
)lpszPath
;
473 /*************************************************************************
474 * PathGetDriveNumberA [SHLWAPI.@]
476 * Return the drive number from a path
479 * lpszPath [I] Path to get the drive number from
482 * Success: The drive number corresponding to the drive in the path
483 * Failure: -1, if lpszPath contains no valid drive
485 int WINAPI
PathGetDriveNumberA(LPCSTR lpszPath
)
487 TRACE ("(%s)\n",debugstr_a(lpszPath
));
489 if (lpszPath
&& !IsDBCSLeadByte(*lpszPath
) && lpszPath
[1] == ':' &&
490 tolower(*lpszPath
) >= 'a' && tolower(*lpszPath
) <= 'z')
491 return tolower(*lpszPath
) - 'a';
495 /*************************************************************************
496 * PathGetDriveNumberW [SHLWAPI.@]
498 * See PathGetDriveNumberA.
500 int WINAPI
PathGetDriveNumberW(LPCWSTR lpszPath
)
502 TRACE ("(%s)\n",debugstr_w(lpszPath
));
504 if (lpszPath
&& lpszPath
[1] == ':' &&
505 tolowerW(*lpszPath
) >= 'a' && tolowerW(*lpszPath
) <= 'z')
506 return tolowerW(*lpszPath
) - 'a';
510 /*************************************************************************
511 * PathRemoveFileSpecA [SHLWAPI.@]
513 * Remove the file specification from a path.
516 * lpszPath [O] Path to remove the file spec from
519 * TRUE If the path was valid and modified
522 BOOL WINAPI
PathRemoveFileSpecA(LPSTR lpszPath
)
524 LPSTR lpszFileSpec
= lpszPath
;
525 BOOL bModified
= FALSE
;
527 TRACE("(%s)\n",debugstr_a(lpszPath
));
531 /* Skip directory or UNC path */
532 if (*lpszPath
== '\\')
533 lpszFileSpec
= ++lpszPath
;
534 if (*lpszPath
== '\\')
535 lpszFileSpec
= ++lpszPath
;
539 if(*lpszPath
== '\\')
540 lpszFileSpec
= lpszPath
; /* Skip dir */
541 else if(*lpszPath
== ':')
543 lpszFileSpec
= ++lpszPath
; /* Skip drive */
544 if (*lpszPath
== '\\')
547 if (!(lpszPath
= CharNextA(lpszPath
)))
553 *lpszFileSpec
= '\0';
560 /*************************************************************************
561 * PathRemoveFileSpecW [SHLWAPI.@]
563 * See PathRemoveFileSpecA.
565 BOOL WINAPI
PathRemoveFileSpecW(LPWSTR lpszPath
)
567 LPWSTR lpszFileSpec
= lpszPath
;
568 BOOL bModified
= FALSE
;
570 TRACE("(%s)\n",debugstr_w(lpszPath
));
574 /* Skip directory or UNC path */
575 if (*lpszPath
== '\\')
576 lpszFileSpec
= ++lpszPath
;
577 if (*lpszPath
== '\\')
578 lpszFileSpec
= ++lpszPath
;
582 if(*lpszPath
== '\\')
583 lpszFileSpec
= lpszPath
; /* Skip dir */
584 else if(*lpszPath
== ':')
586 lpszFileSpec
= ++lpszPath
; /* Skip drive */
587 if (*lpszPath
== '\\')
590 if (!(lpszPath
= CharNextW(lpszPath
)))
596 *lpszFileSpec
= '\0';
603 /*************************************************************************
604 * PathStripPathA [SHLWAPI.@]
606 * Remove the initial path from the beginning of a filename
609 * lpszPath [O] Path to remove the initial path from
614 void WINAPI
PathStripPathA(LPSTR lpszPath
)
616 TRACE("(%s)\n", debugstr_a(lpszPath
));
620 LPSTR lpszFileName
= PathFindFileNameA(lpszPath
);
622 RtlMoveMemory(lpszPath
, lpszFileName
, strlen(lpszFileName
)+1);
626 /*************************************************************************
627 * PathStripPathW [SHLWAPI.@]
629 * See PathStripPathA.
631 void WINAPI
PathStripPathW(LPWSTR lpszPath
)
635 TRACE("(%s)\n", debugstr_w(lpszPath
));
636 lpszFileName
= PathFindFileNameW(lpszPath
);
638 RtlMoveMemory(lpszPath
, lpszFileName
, (strlenW(lpszFileName
)+1)*sizeof(WCHAR
));
641 /*************************************************************************
642 * PathStripToRootA [SHLWAPI.@]
644 * Reduce a path to its root.
647 * lpszPath [O] the path to reduce
650 * Success: TRUE if the stripped path is a root path
651 * Failure: FALSE if the path cannot be stripped or is NULL
653 BOOL WINAPI
PathStripToRootA(LPSTR lpszPath
)
655 TRACE("(%s)\n", debugstr_a(lpszPath
));
659 while(!PathIsRootA(lpszPath
))
660 if (!PathRemoveFileSpecA(lpszPath
))
665 /*************************************************************************
666 * PathStripToRootW [SHLWAPI.@]
668 * See PathStripToRootA.
670 BOOL WINAPI
PathStripToRootW(LPWSTR lpszPath
)
672 TRACE("(%s)\n", debugstr_w(lpszPath
));
676 while(!PathIsRootW(lpszPath
))
677 if (!PathRemoveFileSpecW(lpszPath
))
682 /*************************************************************************
683 * PathRemoveArgsA [SHLWAPI.@]
685 * Strip space seperated arguments from a path.
688 * lpszPath [I] Path to remove arguments from
693 void WINAPI
PathRemoveArgsA(LPSTR lpszPath
)
695 TRACE("(%s)\n",debugstr_a(lpszPath
));
699 LPSTR lpszArgs
= PathGetArgsA(lpszPath
);
704 LPSTR lpszLastChar
= CharPrevA(lpszPath
, lpszArgs
);
705 if(*lpszLastChar
== ' ')
706 *lpszLastChar
= '\0';
711 /*************************************************************************
712 * PathRemoveArgsW [SHLWAPI.@]
714 * See PathRemoveArgsA.
716 void WINAPI
PathRemoveArgsW(LPWSTR lpszPath
)
718 TRACE("(%s)\n",debugstr_w(lpszPath
));
722 LPWSTR lpszArgs
= PathGetArgsW(lpszPath
);
727 LPWSTR lpszLastChar
= CharPrevW(lpszPath
, lpszArgs
);
728 if(*lpszLastChar
== ' ')
729 *lpszLastChar
= '\0';
734 /*************************************************************************
735 * PathRemoveExtensionA [SHLWAPI.@]
737 * Remove the file extension from a path
740 * lpszPath [O] Path to remove the extension from
745 void WINAPI
PathRemoveExtensionA(LPSTR lpszPath
)
747 TRACE("(%s)\n", debugstr_a(lpszPath
));
751 lpszPath
= PathFindExtensionA(lpszPath
);
756 /*************************************************************************
757 * PathRemoveExtensionW [SHLWAPI.@]
759 * See PathRemoveExtensionA.
761 void WINAPI
PathRemoveExtensionW(LPWSTR lpszPath
)
763 TRACE("(%s)\n", debugstr_w(lpszPath
));
767 lpszPath
= PathFindExtensionW(lpszPath
);
772 /*************************************************************************
773 * PathRemoveBackslashA [SHLWAPI.@]
775 * Remove a trailing backslash from a path.
778 * lpszPath [O] Path to remove backslash from
781 * Success: A pointer to the end of the path
782 * Failure: NULL, if lpszPath is NULL
784 LPSTR WINAPI
PathRemoveBackslashA( LPSTR lpszPath
)
788 TRACE("(%s)\n", debugstr_a(lpszPath
));
792 szTemp
= CharPrevA(lpszPath
, lpszPath
+ strlen(lpszPath
));
793 if (!PathIsRootA(lpszPath
) && *szTemp
== '\\')
799 /*************************************************************************
800 * PathRemoveBackslashW [SHLWAPI.@]
802 * See PathRemoveBackslashA.
804 LPWSTR WINAPI
PathRemoveBackslashW( LPWSTR lpszPath
)
806 LPWSTR szTemp
= NULL
;
808 TRACE("(%s)\n", debugstr_w(lpszPath
));
812 szTemp
= CharPrevW(lpszPath
, lpszPath
+ strlenW(lpszPath
));
813 if (!PathIsRootW(lpszPath
) && *szTemp
== '\\')
819 /*************************************************************************
820 * PathRemoveBlanksA [SHLWAPI.@]
822 * Remove Spaces from the start and end of a path.
825 * lpszPath [O] Path to strip blanks from
830 VOID WINAPI
PathRemoveBlanksA(LPSTR lpszPath
)
832 TRACE("(%s)\n", debugstr_a(lpszPath
));
834 if(lpszPath
&& *lpszPath
)
836 LPSTR start
= lpszPath
;
838 while (*lpszPath
== ' ')
839 lpszPath
= CharNextA(lpszPath
);
842 *start
++ = *lpszPath
++;
844 if (start
!= lpszPath
)
845 while (start
[-1] == ' ')
851 /*************************************************************************
852 * PathRemoveBlanksW [SHLWAPI.@]
854 * See PathRemoveBlanksA.
856 VOID WINAPI
PathRemoveBlanksW(LPWSTR lpszPath
)
858 TRACE("(%s)\n", debugstr_w(lpszPath
));
860 if(lpszPath
&& *lpszPath
)
862 LPWSTR start
= lpszPath
;
864 while (*lpszPath
== ' ')
868 *start
++ = *lpszPath
++;
870 if (start
!= lpszPath
)
871 while (start
[-1] == ' ')
877 /*************************************************************************
878 * PathQuoteSpacesA [SHLWAPI.@]
880 * Surround a path containg spaces in quotes.
883 * lpszPath [O] Path to quote
889 * The path is not changed if it is invalid or has no spaces.
891 VOID WINAPI
PathQuoteSpacesA(LPSTR lpszPath
)
893 TRACE("(%s)\n", debugstr_a(lpszPath
));
895 if(lpszPath
&& StrChrA(lpszPath
,' '))
897 int iLen
= strlen(lpszPath
) + 1;
899 if (iLen
+ 2 < MAX_PATH
)
901 memmove(lpszPath
+ 1, lpszPath
, iLen
);
903 lpszPath
[iLen
] = '"';
904 lpszPath
[iLen
+ 1] = '\0';
909 /*************************************************************************
910 * PathQuoteSpacesW [SHLWAPI.@]
912 * See PathQuoteSpacesA.
914 VOID WINAPI
PathQuoteSpacesW(LPWSTR lpszPath
)
916 TRACE("(%s)\n", debugstr_w(lpszPath
));
918 if(lpszPath
&& StrChrW(lpszPath
,' '))
920 int iLen
= strlenW(lpszPath
) + 1;
922 if (iLen
+ 2 < MAX_PATH
)
924 memmove(lpszPath
+ 1, lpszPath
, iLen
* sizeof(WCHAR
));
926 lpszPath
[iLen
] = '"';
927 lpszPath
[iLen
+ 1] = '\0';
932 /*************************************************************************
933 * PathUnquoteSpacesA [SHLWAPI.@]
935 * Remove quotes ("") from around a path, if present.
938 * lpszPath [O] Path to strip quotes from
944 * If the path contains a single quote only, an empty string will result.
945 * Otherwise quotes are only removed if they appear at the start and end
948 VOID WINAPI
PathUnquoteSpacesA(LPSTR lpszPath
)
950 TRACE("(%s)\n", debugstr_a(lpszPath
));
952 if (lpszPath
&& *lpszPath
== '"')
954 DWORD dwLen
= strlen(lpszPath
) - 1;
956 if (lpszPath
[dwLen
] == '"')
958 lpszPath
[dwLen
] = '\0';
959 for (; *lpszPath
; lpszPath
++)
960 *lpszPath
= lpszPath
[1];
965 /*************************************************************************
966 * PathUnquoteSpacesW [SHLWAPI.@]
968 * See PathUnquoteSpacesA.
970 VOID WINAPI
PathUnquoteSpacesW(LPWSTR lpszPath
)
972 TRACE("(%s)\n", debugstr_w(lpszPath
));
974 if (lpszPath
&& *lpszPath
== '"')
976 DWORD dwLen
= strlenW(lpszPath
) - 1;
978 if (lpszPath
[dwLen
] == '"')
980 lpszPath
[dwLen
] = '\0';
981 for (; *lpszPath
; lpszPath
++)
982 *lpszPath
= lpszPath
[1];
987 /*************************************************************************
988 * PathParseIconLocationA [SHLWAPI.@]
990 * Parse the location of an icon from a path.
993 * lpszPath [O] The path to parse the icon location from.
996 * Success: The number of the icon
997 * Failure: 0 if the path does not contain an icon location or is NULL
1000 * The path has surrounding quotes and spaces removed regardless
1001 * of whether the call succeeds or not.
1003 int WINAPI
PathParseIconLocationA(LPSTR lpszPath
)
1008 TRACE("(%s)\n", debugstr_a(lpszPath
));
1012 if ((lpszComma
= strchr(lpszPath
, ',')))
1014 *lpszComma
++ = '\0';
1015 iRet
= StrToIntA(lpszComma
);
1017 PathUnquoteSpacesA(lpszPath
);
1018 PathRemoveBlanksA(lpszPath
);
1023 /*************************************************************************
1024 * PathParseIconLocationW [SHLWAPI.@]
1026 * See PathParseIconLocationA.
1028 int WINAPI
PathParseIconLocationW(LPWSTR lpszPath
)
1033 TRACE("(%s)\n", debugstr_w(lpszPath
));
1037 if ((lpszComma
= StrChrW(lpszPath
, ',')))
1039 *lpszComma
++ = '\0';
1040 iRet
= StrToIntW(lpszComma
);
1042 PathUnquoteSpacesW(lpszPath
);
1043 PathRemoveBlanksW(lpszPath
);
1048 /*************************************************************************
1051 * Unicode version of SHLWAPI_3.
1053 BOOL WINAPI
SHLWAPI_4(LPWSTR lpszPath
,DWORD dwWhich
)
1055 static const WCHAR pszExts
[7][5] = { { '.', 'p', 'i', 'f', '0'},
1056 { '.', 'c', 'o', 'm', '0'},
1057 { '.', 'e', 'x', 'e', '0'},
1058 { '.', 'b', 'a', 't', '0'},
1059 { '.', 'l', 'n', 'k', '0'},
1060 { '.', 'c', 'm', 'd', '0'},
1061 { '0', '0', '0', '0', '0'} };
1063 TRACE("(%s,%ld)\n", debugstr_w(lpszPath
), dwWhich
);
1065 if (!lpszPath
|| PathIsUNCServerW(lpszPath
) || PathIsUNCServerShareW(lpszPath
))
1070 LPCWSTR szExt
= PathFindExtensionW(lpszPath
);
1071 if (!*szExt
|| dwWhich
& 0x40)
1074 int iLen
= lstrlenW(lpszPath
);
1075 if (iLen
> (MAX_PATH
- 5))
1077 while (dwWhich
& 0x1 && iChoose
< sizeof(pszExts
))
1079 lstrcpyW(lpszPath
+ iLen
, pszExts
[iChoose
]);
1080 if (PathFileExistsW(lpszPath
))
1085 *(lpszPath
+ iLen
) = (WCHAR
)'\0';
1089 return PathFileExistsW(lpszPath
);
1092 /*************************************************************************
1095 * Determine if a file exists locally and is of an executable type.
1098 * lpszPath [O] File to search for
1099 * dwWhich [I] Type of executable to search for
1102 * TRUE If the file was found. lpszFile contains the file name.
1106 * lpszPath is modified in place and must be at least MAX_PATH in length.
1107 * If the function returns FALSE, the path is modified to its orginal state.
1108 * If the given path contains an extension or dwWhich is 0, executable
1109 * extensions are not checked.
1111 * Ordinals 3-6 are a classic case of MS exposing limited functionality to
1112 * users (here through PathFindOnPath) and keeping advanced functionality for
1113 * their own developers exclusive use. Monopoly, anyone?
1115 BOOL WINAPI
SHLWAPI_3(LPSTR lpszPath
,DWORD dwWhich
)
1119 TRACE("(%s,%ld)\n", debugstr_a(lpszPath
), dwWhich
);
1123 WCHAR szPath
[MAX_PATH
];
1124 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
1125 bRet
= SHLWAPI_4(szPath
, dwWhich
);
1127 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
1132 /*************************************************************************
1133 * SHLWAPI_PathFindInOtherDirs
1135 * Internal helper for SHLWAPI_PathFindOnPathExA/W.
1137 static BOOL WINAPI
SHLWAPI_PathFindInOtherDirs(LPWSTR lpszFile
, DWORD dwWhich
)
1139 static WCHAR szSystem
[] = { 'S','y','s','t','e','m','\0'};
1140 static WCHAR szPath
[] = { 'P','A','T','H','\0'};
1144 WCHAR buff
[MAX_PATH
];
1146 TRACE("(%s,%08lx)\n", debugstr_w(lpszFile
), dwWhich
);
1148 /* Try system directories */
1149 GetSystemDirectoryW(buff
, MAX_PATH
);
1150 if (!PathAppendW(buff
, lpszFile
))
1152 if (SHLWAPI_4(buff
, dwWhich
))
1154 strcpyW(lpszFile
, buff
);
1157 GetWindowsDirectoryW(buff
, MAX_PATH
);
1158 if (!PathAppendW(buff
, szSystem
) || !PathAppendW(buff
, lpszFile
))
1160 if (SHLWAPI_4(buff
, dwWhich
))
1162 strcpyW(lpszFile
, buff
);
1165 GetWindowsDirectoryW(buff
, MAX_PATH
);
1166 if (!PathAppendW(buff
, lpszFile
))
1168 if (SHLWAPI_4(buff
, dwWhich
))
1170 strcpyW(lpszFile
, buff
);
1173 /* Try dirs listed in %PATH% */
1174 dwLenPATH
= GetEnvironmentVariableW(szPath
, buff
, MAX_PATH
);
1176 if (!dwLenPATH
|| !(lpszPATH
= malloc((dwLenPATH
+ 1) * sizeof (WCHAR
))))
1179 GetEnvironmentVariableW(szPath
, lpszPATH
, dwLenPATH
+ 1);
1180 lpszCurr
= lpszPATH
;
1183 LPCWSTR lpszEnd
= lpszCurr
;
1184 LPWSTR pBuff
= buff
;
1186 while (*lpszEnd
== ' ')
1188 while (*lpszEnd
&& *lpszEnd
!= ';')
1189 *pBuff
++ = *lpszEnd
++;
1193 lpszCurr
= lpszEnd
+ 1;
1195 lpszCurr
= NULL
; /* Last Path, terminate after this */
1197 if (!PathAppendW(buff
, lpszFile
))
1199 if (SHLWAPI_4(buff
, dwWhich
))
1201 strcpyW(lpszFile
, buff
);
1210 /*************************************************************************
1213 * Search a range of paths for a specific type of executable.
1216 * lpszFile [O] File to search for
1217 * lppszOtherDirs [I] Other directories to look in
1218 * dwWhich [I] Type of executable to search for
1221 * Success: TRUE. The path to the executable is stored in sFile.
1222 * Failure: FALSE. The path to the executable is unchanged.
1224 BOOL WINAPI
SHLWAPI_5(LPSTR lpszFile
,LPCSTR
*lppszOtherDirs
,DWORD dwWhich
)
1226 WCHAR szFile
[MAX_PATH
];
1227 WCHAR buff
[MAX_PATH
];
1229 TRACE("(%s,%p,%08lx)\n", debugstr_a(lpszFile
), lppszOtherDirs
, dwWhich
);
1231 if (!lpszFile
|| !PathIsFileSpecA(lpszFile
))
1234 MultiByteToWideChar(0,0,lpszFile
,-1,szFile
,MAX_PATH
);
1236 /* Search provided directories first */
1237 if (lppszOtherDirs
&& *lppszOtherDirs
)
1239 WCHAR szOther
[MAX_PATH
];
1240 LPCSTR
*lpszOtherPath
= lppszOtherDirs
;
1242 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1244 MultiByteToWideChar(0,0,*lpszOtherPath
,-1,szOther
,MAX_PATH
);
1245 PathCombineW(buff
, szOther
, szFile
);
1246 if (SHLWAPI_4(buff
, dwWhich
))
1248 WideCharToMultiByte(0,0,buff
,-1,lpszFile
,MAX_PATH
,0,0);
1254 /* Not found, try system and path dirs */
1255 if (SHLWAPI_PathFindInOtherDirs(szFile
, dwWhich
))
1257 WideCharToMultiByte(0,0,szFile
,-1,lpszFile
,MAX_PATH
,0,0);
1263 /*************************************************************************
1266 * Unicode version of SHLWAPI_5.
1268 BOOL WINAPI
SHLWAPI_6(LPWSTR lpszFile
,LPCWSTR
*lppszOtherDirs
,DWORD dwWhich
)
1270 WCHAR buff
[MAX_PATH
];
1272 TRACE("(%s,%p,%08lx)\n", debugstr_w(lpszFile
), lppszOtherDirs
, dwWhich
);
1274 if (!lpszFile
|| !PathIsFileSpecW(lpszFile
))
1277 /* Search provided directories first */
1278 if (lppszOtherDirs
&& *lppszOtherDirs
)
1280 LPCWSTR
*lpszOtherPath
= lppszOtherDirs
;
1281 while (lpszOtherPath
&& *lpszOtherPath
&& (*lpszOtherPath
)[0])
1283 PathCombineW(buff
, *lpszOtherPath
, lpszFile
);
1284 if (SHLWAPI_4(buff
, dwWhich
))
1286 strcpyW(lpszFile
, buff
);
1292 /* Not found, try system and path dirs */
1293 return SHLWAPI_PathFindInOtherDirs(lpszFile
, dwWhich
);
1296 /*************************************************************************
1297 * PathFindOnPathA [SHLWAPI.@]
1299 * Search a range of paths for an executable.
1302 * lpszFile [O] File to search for
1303 * lppszOtherDirs [I] Other directories to look in
1306 * Success: TRUE. The path to the executable is stored in lpszFile.
1307 * Failure: FALSE. The path to the executable is unchanged.
1309 BOOL WINAPI
PathFindOnPathA(LPSTR lpszFile
, LPCSTR
*lppszOtherDirs
)
1311 TRACE("(%s,%p)\n", debugstr_a(lpszFile
), lppszOtherDirs
);
1312 return SHLWAPI_5(lpszFile
, lppszOtherDirs
, 0);
1315 /*************************************************************************
1316 * PathFindOnPathW [SHLWAPI.@]
1318 * See PathFindOnPathA.
1320 BOOL WINAPI
PathFindOnPathW(LPWSTR lpszFile
, LPCWSTR
*lppszOtherDirs
)
1322 TRACE("(%s,%p)\n", debugstr_w(lpszFile
), lppszOtherDirs
);
1323 return SHLWAPI_6(lpszFile
,lppszOtherDirs
, 0);
1326 /*************************************************************************
1327 * PathCompactPathExA [SHLWAPI.@]
1329 * Compact a path into a given number of characters.
1332 * lpszDest [O] Destination for compacted path
1333 * lpszPath [I] Source path
1334 * cchMax [I[ Maximum size of compacted path
1335 * dwFlags [I] Reserved
1338 * Success: TRUE. The compacted path is written to lpszDest.
1339 * Failure: FALSE. lpszPath is undefined.
1342 * If cchMax is given as 0, lpszDest will still be NUL terminated.
1343 * The Win32 version of this function contains a bug: When cchMax == 7,
1344 * 8 bytes will be written to lpszDest. This bug is fixed in the Wine
1346 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1347 * because Win32 will insert a \ in the compact filename, even if one is
1348 * not present in the original path.
1350 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1351 UINT cchMax
, DWORD dwFlags
)
1355 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1357 if (lpszPath
&& lpszDest
)
1359 WCHAR szPath
[MAX_PATH
];
1360 WCHAR szDest
[MAX_PATH
];
1362 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
1364 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1365 WideCharToMultiByte(0,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1370 /*************************************************************************
1371 * PathCompactPathExW [SHLWAPI.@]
1373 * See PathCompactPathExA.
1375 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1376 UINT cchMax
, DWORD dwFlags
)
1378 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1380 DWORD dwLen
, dwFileLen
= 0;
1382 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1389 WARN("Invalid lpszDest would crash under Win32!\n");
1398 dwLen
= strlenW(lpszPath
) + 1;
1402 /* Don't need to compact */
1403 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1407 /* Path must be compacted to fit into lpszDest */
1408 lpszFile
= PathFindFileNameW(lpszPath
);
1409 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1411 if (dwFileLen
== dwLen
)
1413 /* No root in psth */
1416 while (--cchMax
> 0) /* No room left for anything but ellipses */
1421 /* Compact the file name with ellipses at the end */
1423 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1424 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1427 /* We have a root in the path */
1428 lpszFile
--; /* Start compacted filename with the path seperator */
1431 if (dwFileLen
+ 3 > cchMax
)
1433 /* Compact the file name */
1436 while (--cchMax
> 0) /* No room left for anything but ellipses */
1441 strcpyW(lpszDest
, szEllipses
);
1444 *lpszDest
++ = *lpszFile
++;
1447 while (--cchMax
> 0) /* No room left for anything but ellipses */
1453 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1454 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1458 /* Only the root needs to be Compacted */
1459 dwLen
= cchMax
- dwFileLen
- 3;
1460 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1461 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1462 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1466 /*************************************************************************
1467 * PathIsRelativeA [SHLWAPI.@]
1469 * Determine if a path is a relative path.
1472 * lpszPath [I] Path to check
1475 * TRUE: The path is relative, or is invalid.
1476 * FALSE: The path is not relative.
1478 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1480 TRACE("(%s)\n",debugstr_a(lpszPath
));
1482 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1484 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1489 /*************************************************************************
1490 * PathIsRelativeW [SHLWAPI.@]
1492 * See PathIsRelativeA.
1494 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1496 TRACE("(%s)\n",debugstr_w(lpszPath
));
1498 if (!lpszPath
|| !*lpszPath
)
1500 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1505 /*************************************************************************
1506 * PathIsRootA [SHLWAPI.@]
1508 * Determine if a path is a root path.
1511 * lpszPath [I] Path to check
1514 * TRUE If lpszPath is valid and a root path
1517 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1519 TRACE("(%s)\n", debugstr_a(lpszPath
));
1521 if (lpszPath
&& *lpszPath
)
1523 if (*lpszPath
== '\\')
1526 return TRUE
; /* \ */
1527 else if (lpszPath
[1]=='\\')
1529 BOOL bSeenSlash
= FALSE
;
1532 /* Check for UNC root path */
1535 if (*lpszPath
== '\\')
1541 lpszPath
= CharNextA(lpszPath
);
1546 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1547 return TRUE
; /* X:\ */
1552 /*************************************************************************
1553 * PathIsRootW [SHLWAPI.@]
1557 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1559 TRACE("(%s)\n", debugstr_w(lpszPath
));
1561 if (lpszPath
&& *lpszPath
)
1563 if (*lpszPath
== '\\')
1566 return TRUE
; /* \ */
1567 else if (lpszPath
[1]=='\\')
1569 BOOL bSeenSlash
= FALSE
;
1572 /* Check for UNC root path */
1575 if (*lpszPath
== '\\')
1581 lpszPath
= CharNextW(lpszPath
);
1586 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1587 return TRUE
; /* X:\ */
1592 /*************************************************************************
1593 * PathIsDirectoryA [SHLWAPI.@]
1595 * Determine if a path is a valid directory
1598 * lpszPath [I] Path to check.
1601 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1602 * FALSE if lpszPath is invalid or not a directory.
1605 * Although this function is prototyped as returning a BOOL, it returns
1606 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1608 * if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1613 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1617 TRACE("(%s)\n", debugstr_a(lpszPath
));
1619 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1622 if (PathIsUNCServerShareA(lpszPath
))
1624 FIXME("UNC Server Share not yet supported - FAILING\n");
1628 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == -1u)
1630 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1633 /*************************************************************************
1634 * PathIsDirectoryW [SHLWAPI.@]
1636 * See PathIsDirectoryA.
1638 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1642 TRACE("(%s)\n", debugstr_w(lpszPath
));
1644 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1647 if (PathIsUNCServerShareW(lpszPath
))
1649 FIXME("UNC Server Share not yet supported - FAILING\n");
1653 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == -1u)
1655 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1658 /*************************************************************************
1659 * PathFileExistsA [SHLWAPI.@]
1661 * Determine if a file exists.
1664 * lpszPath [I] Path to check
1667 * TRUE If the file exists and is readable
1670 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1675 TRACE("(%s)\n",debugstr_a(lpszPath
));
1680 iPrevErrMode
= SetErrorMode(1);
1681 dwAttr
= GetFileAttributesA(lpszPath
);
1682 SetErrorMode(iPrevErrMode
);
1683 return dwAttr
== -1u ? FALSE
: TRUE
;
1686 /*************************************************************************
1687 * PathFileExistsW [SHLWAPI.@]
1689 * See PathFileExistsA
1691 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1696 TRACE("(%s)\n",debugstr_w(lpszPath
));
1701 iPrevErrMode
= SetErrorMode(1);
1702 dwAttr
= GetFileAttributesW(lpszPath
);
1703 SetErrorMode(iPrevErrMode
);
1704 return dwAttr
== -1u ? FALSE
: TRUE
;
1707 /*************************************************************************
1708 * PathMatchSingleMaskA [internal]
1711 * internal (used by PathMatchSpec)
1713 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1715 while (*name
&& *mask
&& *mask
!=';')
1721 if (PathMatchSingleMaskA(name
,mask
+1)) return 1; /* try substrings */
1725 if (toupper(*mask
)!=toupper(*name
) && *mask
!='?') return 0;
1726 name
= CharNextA(name
);
1727 mask
= CharNextA(mask
);
1731 while (*mask
=='*') mask
++;
1732 if (!*mask
|| *mask
==';') return 1;
1737 /*************************************************************************
1738 * PathMatchSingleMaskW [internal]
1740 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1742 while (*name
&& *mask
&& *mask
!=';')
1748 if (PathMatchSingleMaskW(name
,mask
+1)) return 1; /* try substrings */
1752 if (toupperW(*mask
)!=toupperW(*name
) && *mask
!='?') return 0;
1753 name
= CharNextW(name
);
1754 mask
= CharNextW(mask
);
1758 while (*mask
=='*') mask
++;
1759 if (!*mask
|| *mask
==';') return 1;
1764 /*************************************************************************
1765 * PathMatchSpecA [SHLWAPI.@]
1767 * Determine if a path matches one or more search masks.
1770 * lpszPath [I] Path to check
1771 * lpszMask [I} Search mask(s)
1774 * TRUE If lpszPath is valid and is matched
1778 * Multiple search masks may be given if they are seperated by ";". The
1779 * pattern "*.*" is treated specially in that it matches all paths (for
1780 * backwards compatability with DOS).
1782 BOOL WINAPI
PathMatchSpecA(LPCSTR name
, LPCSTR mask
)
1784 TRACE("%s %s\n",name
,mask
);
1786 if (!lstrcmpA( mask
, "*.*" )) return 1; /* we don't require a period */
1790 if (PathMatchSingleMaskA(name
,mask
)) return 1; /* helper function */
1791 while (*mask
&& *mask
!=';') mask
= CharNextA(mask
);
1795 while (*mask
==' ') mask
++; /* masks may be separated by "; " */
1801 /*************************************************************************
1802 * PathMatchSpecW [SHLWAPI.@]
1804 * See PathMatchSpecA.
1806 BOOL WINAPI
PathMatchSpecW(LPCWSTR name
, LPCWSTR mask
)
1808 static const WCHAR stemp
[] = { '*','.','*',0 };
1809 TRACE("%s %s\n",debugstr_w(name
),debugstr_w(mask
));
1811 if (!lstrcmpW( mask
, stemp
)) return 1; /* we don't require a period */
1815 if (PathMatchSingleMaskW(name
,mask
)) return 1; /* helper function */
1816 while (*mask
&& *mask
!=';') mask
= CharNextW(mask
);
1820 while (*mask
==' ') mask
++; /* masks may be separated by "; " */
1826 /*************************************************************************
1827 * PathIsSameRootA [SHLWAPI.@]
1829 * Determine if two paths share the same root.
1832 * lpszPath1 [I] Source path
1833 * lpszPath2 [I] Path to compare with
1836 * TRUE If both paths are valid and share the same root.
1837 * FALSE If either path is invalid or the paths do not share the same root.
1839 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1844 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1846 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1849 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1850 if (lpszStart
- lpszPath1
> dwLen
)
1851 return FALSE
; /* Paths not common up to length of the root */
1855 /*************************************************************************
1856 * PathIsSameRootW [SHLWAPI.@]
1858 * See PathIsSameRootA.
1860 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1865 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1867 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1870 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1871 if (lpszStart
- lpszPath1
> dwLen
)
1872 return FALSE
; /* Paths not common up to length of the root */
1876 /*************************************************************************
1877 * PathIsContentTypeA [SHLWAPI.@]
1879 * Determine if a file is of a given registered content type.
1882 * lpszPath [I] file to check
1885 * TRUE If lpszPath is a given registered content type
1889 * This function looks up the registered content type for lpszPath. If
1890 * a content type is registered, it is compared (case insensitively) to
1891 * lpszContentType. Only if this matches does the function succeed.
1893 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
1897 char szBuff
[MAX_PATH
];
1899 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
1901 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
1902 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
1903 REG_NONE
, szBuff
, &dwDummy
) &&
1904 !strcasecmp(lpszContentType
, szBuff
))
1911 /*************************************************************************
1912 * PathIsContentTypeW [SHLWAPI.@]
1914 * See PathIsContentTypeA.
1916 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
1918 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
1921 WCHAR szBuff
[MAX_PATH
];
1923 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
1925 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
1926 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
1927 REG_NONE
, szBuff
, &dwDummy
) &&
1928 !strcmpiW(lpszContentType
, szBuff
))
1935 /*************************************************************************
1936 * PathIsFileSpecA [SHLWAPI.@]
1938 * Determine if a path is a file specification.
1941 * lpszPath [I] Path to chack
1944 * TRUE If lpszPath is a file spec (contains no directories).
1947 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
1949 TRACE("(%s)\n", debugstr_a(lpszPath
));
1956 if (*lpszPath
== '\\' || *lpszPath
== ':')
1958 lpszPath
= CharNextA(lpszPath
);
1963 /*************************************************************************
1964 * PathIsFileSpecW [SHLWAPI.@]
1966 * See PathIsFileSpecA.
1968 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
1970 TRACE("(%s)\n", debugstr_w(lpszPath
));
1977 if (*lpszPath
== '\\' || *lpszPath
== ':')
1979 lpszPath
= CharNextW(lpszPath
);
1984 /*************************************************************************
1985 * PathIsPrefixA [SHLWAPI.@]
1987 * Determine if a path is a prefix of another.
1990 * lpszPrefix [I] Prefix
1991 * lpszPath [i] Path to check
1994 * TRUE If lpszPath has lpszPrefix as its prefix
1995 * FALSE If either path is NULL or lpszPrefix is not a prefix
1997 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
1999 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2001 if (lpszPrefix
&& lpszPath
&&
2002 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2007 /*************************************************************************
2008 * PathIsPrefixW [SHLWAPI.@]
2010 * See PathIsPrefixA.
2012 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2014 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2016 if (lpszPrefix
&& lpszPath
&&
2017 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2022 /*************************************************************************
2023 * PathIsSystemFolderA [SHLWAPI.@]
2025 * Determine if a path or file attributes are a system folder.
2028 * lpszPath [I] Path to check.
2029 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2032 * TRUE If lpszPath or dwAttrib are a system folder.
2033 * FALSE If GetFileAttributesA fails or neither parameter is a system folder.
2035 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2037 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath
), dwAttrib
);
2039 if (lpszPath
&& *lpszPath
)
2040 dwAttrib
= GetFileAttributesA(lpszPath
);
2042 if (dwAttrib
== -1u || !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2043 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2048 /*************************************************************************
2049 * PathIsSystemFolderW [SHLWAPI.@]
2051 * See PathIsSystemFolderA.
2053 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2055 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath
), dwAttrib
);
2057 if (lpszPath
&& *lpszPath
)
2058 dwAttrib
= GetFileAttributesW(lpszPath
);
2060 if (dwAttrib
== -1u || !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2061 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2066 /*************************************************************************
2067 * PathIsUNCA [SHLWAPI.@]
2069 * Determine if a path is in UNC format.
2072 * lpszPath [I] Path to check
2075 * TRUE: The path is UNC.
2076 * FALSE: The path is not UNC or is NULL.
2078 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2080 TRACE("(%s)\n",debugstr_a(lpszPath
));
2082 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2087 /*************************************************************************
2088 * PathIsUNCW [SHLWAPI.@]
2092 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2094 TRACE("(%s)\n",debugstr_w(lpszPath
));
2096 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2101 /*************************************************************************
2102 * PathIsUNCServerA [SHLWAPI.@]
2104 * Determine if a path is a UNC server name ("\\SHARENAME").
2107 * lpszPath [I] Path to check.
2110 * TRUE If lpszPath is a valid UNC server name.
2114 * This routine is bug compatible with Win32: Server names with a
2115 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2116 * Fixing this bug may break other shlwapi functions!
2118 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2120 TRACE("(%s)\n", debugstr_a(lpszPath
));
2122 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2126 if (*lpszPath
== '\\')
2128 lpszPath
= CharNextA(lpszPath
);
2135 /*************************************************************************
2136 * PathIsUNCServerW [SHLWAPI.@]
2138 * See PathIsUNCServerA.
2140 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2142 TRACE("(%s)\n", debugstr_w(lpszPath
));
2144 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2148 if (*lpszPath
== '\\')
2150 lpszPath
= CharNextW(lpszPath
);
2157 /*************************************************************************
2158 * PathIsUNCServerShareA [SHLWAPI.@]
2160 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2163 * lpszPath [I] Path to check.
2166 * TRUE If lpszPath is a valid UNC server share.
2170 * This routine is bug compatible with Win32: Server shares with a
2171 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2172 * Fixing this bug may break other shlwapi functions!
2174 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2176 TRACE("(%s)\n", debugstr_a(lpszPath
));
2178 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2180 BOOL bSeenSlash
= FALSE
;
2183 if (*lpszPath
== '\\')
2189 lpszPath
= CharNextA(lpszPath
);
2196 /*************************************************************************
2197 * PathIsUNCServerShareW [SHLWAPI.@]
2199 * See PathIsUNCServerShareA.
2201 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2203 TRACE("(%s)\n", debugstr_w(lpszPath
));
2205 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2207 BOOL bSeenSlash
= FALSE
;
2210 if (*lpszPath
== '\\')
2216 lpszPath
= CharNextW(lpszPath
);
2223 /*************************************************************************
2224 * PathCanonicalizeA [SHLWAPI.@]
2226 * Convert a path to its canonical form.
2229 * lpszBuf [O] Output path
2230 * lpszPath [I] Path to cnonicalize
2233 * Success: TRUE. lpszBuf contains the output path
2234 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2236 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2240 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2245 if (!lpszBuf
|| !lpszPath
)
2246 SetLastError(ERROR_INVALID_PARAMETER
);
2249 WCHAR szPath
[MAX_PATH
];
2250 WCHAR szBuff
[MAX_PATH
];
2251 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2252 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2253 WideCharToMultiByte(0,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2259 /*************************************************************************
2260 * PathCanonicalizeW [SHLWAPI.@]
2262 * See PathCanonicalizeA.
2264 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2266 LPWSTR lpszDst
= lpszBuf
;
2267 LPCWSTR lpszSrc
= lpszPath
;
2269 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2274 if (!lpszBuf
|| !lpszPath
)
2276 SetLastError(ERROR_INVALID_PARAMETER
);
2287 /* Copy path root */
2288 if (*lpszSrc
== '\\')
2290 *lpszDst
++ = *lpszSrc
++;
2292 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2295 *lpszDst
++ = *lpszSrc
++;
2296 *lpszDst
++ = *lpszSrc
++;
2297 if (*lpszSrc
== '\\')
2298 *lpszDst
++ = *lpszSrc
++;
2301 /* Canonicalize the rest of the path */
2304 if (*lpszSrc
== '.')
2306 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2308 lpszSrc
+= 2; /* Skip .\ */
2310 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2312 /* \.. backs up a directory, over the root if it has no \ following X:.
2313 * .. is ignored if it would remove a UNC server name or inital \\
2315 if (lpszDst
!= lpszBuf
)
2317 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2318 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2319 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2321 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2324 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2326 if (*lpszDst
== '\\')
2327 lpszDst
++; /* Reset to last '\' */
2329 lpszDst
= lpszBuf
; /* Start path again from new root */
2331 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2334 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2336 if (lpszDst
== lpszBuf
)
2342 lpszSrc
+= 2; /* Skip .. in src path */
2345 *lpszDst
++ = *lpszSrc
++;
2348 *lpszDst
++ = *lpszSrc
++;
2350 /* Append \ to naked drive specs */
2351 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2357 /*************************************************************************
2358 * PathFindNextComponentA [SHLWAPI.@]
2360 * Find the next component in a path.
2363 * lpszPath [I] Path to find next component in
2366 * Success: A pointer to the next component, or the end of the string
2367 * Failure: NULL, If lpszPath is invalid
2370 * A 'component' is either a backslash character (\) or UNC marker (\\).
2371 * Because of this, relative paths (e.g "c:foo") are regarded as having
2372 * only one component.
2374 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2378 TRACE("(%s)\n", debugstr_a(lpszPath
));
2380 if(!lpszPath
|| !*lpszPath
)
2383 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2385 if (lpszSlash
[1] == '\\')
2387 return lpszSlash
+ 1;
2389 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2392 /*************************************************************************
2393 * PathFindNextComponentW [SHLWAPI.@]
2395 * See PathFindNextComponentA.
2397 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2401 TRACE("(%s)\n", debugstr_w(lpszPath
));
2403 if(!lpszPath
|| !*lpszPath
)
2406 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2408 if (lpszSlash
[1] == '\\')
2410 return lpszSlash
+ 1;
2412 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2415 /*************************************************************************
2416 * PathAddExtensionA [SHLWAPI.@]
2418 * Add a file extension to a path
2421 * lpszPath [O] Path to add extension to
2422 * lpszExtension [I} Extension to add to lpszPath
2425 * TRUE If the path was modified
2426 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2427 * extension allready, or the new path length is too big.
2430 * What version of shlwapi.dll adds "exe" if pszExtension is NULL? Win2k
2431 * does not do this, so the behaviour was removed.
2433 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2437 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2439 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2442 dwLen
= strlen(lpszPath
);
2444 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2447 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2451 /*************************************************************************
2452 * PathAddExtensionW [SHLWAPI.@]
2454 * See PathAddExtensionA.
2456 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2460 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2462 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2465 dwLen
= strlenW(lpszPath
);
2467 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2470 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2474 /*************************************************************************
2475 * PathMakePrettyA [SHLWAPI.@]
2477 * Convert an uppercase DOS filename into lowercase.
2480 * lpszPath [O] Path to convert.
2483 * TRUE If the path was an uppercase DOS path and was converted
2486 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2488 LPSTR pszIter
= lpszPath
;
2490 TRACE("(%s)\n", debugstr_a(lpszPath
));
2492 if (!pszIter
|| !*pszIter
)
2497 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2498 return FALSE
; /* Not DOS path */
2501 pszIter
= lpszPath
+ 1;
2504 *pszIter
= tolower(*pszIter
);
2510 /*************************************************************************
2511 * PathMakePrettyW [SHLWAPI.@]
2513 * See PathMakePrettyA
2515 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2517 LPWSTR pszIter
= lpszPath
;
2519 TRACE("(%s)\n", debugstr_w(lpszPath
));
2521 if (!pszIter
|| !*pszIter
)
2526 if (islowerW(*pszIter
))
2527 return FALSE
; /* Not DOS path */
2530 pszIter
= lpszPath
+ 1;
2533 *pszIter
= tolowerW(*pszIter
);
2539 /*************************************************************************
2540 * PathCommonPrefixA [SHLWAPI.@]
2542 * Determine the length of the common prefix between two paths.
2545 * lpszFile1 [I] First path for comparason
2546 * lpszFile2 [I] Second path for comparason
2547 * achPath [O] Destination for common prefix string
2550 * The length of the common prefix. This is 0 if there is no common
2551 * prefix between the paths or if any parameters are invalid. If the prefix
2552 * is non-zero and achPath is not NULL, achPath is filled with the common
2553 * part of the prefix and NUL terminated.
2556 * A common prefix of 2 is always returned as 3. It is thus possible for
2557 * the length returned to be invalid (i.e. Longer than one or both of the
2558 * strings given as parameters). This Win32 behaviour has been implimented
2559 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2560 * To work around this when using this function, always check that the byte
2561 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2563 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2566 LPCSTR lpszIter1
= lpszFile1
;
2567 LPCSTR lpszIter2
= lpszFile2
;
2569 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2574 if (!lpszFile1
|| !lpszFile2
)
2577 /* Handle roots first */
2578 if (PathIsUNCA(lpszFile1
))
2580 if (!PathIsUNCA(lpszFile2
))
2585 else if (PathIsUNCA(lpszFile2
))
2586 return 0; /* Know already lpszFile1 is not UNC */
2591 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2592 (!*lpszIter2
|| *lpszIter2
== '\\'))
2593 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2595 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2596 break; /* Strings differ at this point */
2603 iLen
++; /* Feature/Bug compatable with Win32 */
2605 if (iLen
&& achPath
)
2607 memcpy(achPath
,lpszFile1
,iLen
);
2608 achPath
[iLen
] = '\0';
2613 /*************************************************************************
2614 * PathCommonPrefixW [SHLWAPI.@]
2616 * See PathCommonPrefixA.
2618 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2621 LPCWSTR lpszIter1
= lpszFile1
;
2622 LPCWSTR lpszIter2
= lpszFile2
;
2624 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2629 if (!lpszFile1
|| !lpszFile2
)
2632 /* Handle roots first */
2633 if (PathIsUNCW(lpszFile1
))
2635 if (!PathIsUNCW(lpszFile2
))
2640 else if (PathIsUNCW(lpszFile2
))
2641 return 0; /* Know already lpszFile1 is not UNC */
2646 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2647 (!*lpszIter2
|| *lpszIter2
== '\\'))
2648 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2650 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2651 break; /* Strings differ at this point */
2658 iLen
++; /* Feature/Bug compatable with Win32 */
2660 if (iLen
&& achPath
)
2662 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2663 achPath
[iLen
] = '\0';
2668 /*************************************************************************
2669 * PathCompactPathA [SHLWAPI.@]
2671 * Make a path fit into a given width when printed to a DC.
2674 * hDc [I] Destination DC
2675 * lpszPath [O] Path to be printed to hDc
2676 * dx [i] Desired width
2679 * TRUE If the path was modified.
2682 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2686 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2690 WCHAR szPath
[MAX_PATH
];
2691 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2692 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2693 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2698 /*************************************************************************
2699 * PathCompactPathW [SHLWAPI.@]
2701 * See PathCompactPathA.
2703 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2705 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2708 WCHAR buff
[MAX_PATH
];
2712 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2718 hdc
= hDC
= GetDC(0);
2720 /* Get the length of the whole path */
2721 dwLen
= strlenW(lpszPath
);
2722 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2724 if ((UINT
)size
.cx
> dx
)
2726 /* Path too big, must reduce it */
2728 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2730 sFile
= PathFindFileNameW(lpszPath
);
2731 if (sFile
!= lpszPath
)
2732 sFile
= CharPrevW(lpszPath
, sFile
);
2734 /* Get the size of ellipses */
2735 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2736 dwEllipsesLen
= size
.cx
;
2737 /* Get the size of the file name */
2738 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2739 dwPathLen
= size
.cx
;
2741 if (sFile
!= lpszPath
)
2743 LPWSTR sPath
= sFile
;
2744 BOOL bEllipses
= FALSE
;
2746 /* The path includes a file name. Include as much of the path prior to
2747 * the file name as possible, allowing for the ellipses, e.g:
2748 * c:\some very long path\filename ==> c:\some v...\filename
2750 strncpyW(buff
, sFile
, MAX_PATH
);
2754 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2756 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2757 dwTotalLen
+= size
.cx
;
2758 if (dwTotalLen
<= dx
)
2760 sPath
= CharPrevW(lpszPath
, sPath
);
2764 sPath
= CharPrevW(lpszPath
, sPath
);
2765 sPath
= CharPrevW(lpszPath
, sPath
);
2767 } while (sPath
> lpszPath
);
2769 if (sPath
> lpszPath
)
2773 strcpyW(sPath
, szEllipses
);
2774 strcpyW(sPath
+3, buff
);
2779 strcpyW(lpszPath
, szEllipses
);
2780 strcpyW(lpszPath
+3, buff
);
2785 /* Trim the path by adding ellipses to the end, e.g:
2786 * A very long file name.txt ==> A very...
2788 dwLen
= strlenW(lpszPath
);
2790 if (dwLen
> MAX_PATH
- 3)
2791 dwLen
= MAX_PATH
- 3;
2792 strncpyW(buff
, sFile
, dwLen
);
2796 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2797 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2801 DWORD dwWritten
= 0;
2803 dwEllipsesLen
/= 3; /* Size of a single '.' */
2805 /* Write as much of the Ellipses string as possible */
2806 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2809 dwWritten
+= dwEllipsesLen
;
2817 strcpyW(buff
+ dwLen
, szEllipses
);
2818 strcpyW(lpszPath
, buff
);
2829 /*************************************************************************
2830 * PathGetCharTypeA [SHLWAPI.@]
2832 * Categorise a character from a file path.
2835 * ch [I] Character to get the type of
2838 * A set of GCT_ bit flags (from shlwapi.h) indicating the character type.
2840 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2842 return PathGetCharTypeW(ch
);
2845 /*************************************************************************
2846 * PathGetCharTypeW [SHLWAPI.@]
2848 * See PathGetCharTypeA.
2850 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2854 TRACE("(%d)\n", ch
);
2856 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2857 ch
== '"' || ch
== '|' || ch
== '/')
2858 flags
= GCT_INVALID
; /* Invalid */
2859 else if (ch
== '*' || ch
=='?')
2860 flags
= GCT_WILD
; /* Wildchars */
2861 else if ((ch
== '\\') || (ch
== ':'))
2862 return GCT_SEPARATOR
; /* Path separators */
2867 if ((ch
& 0x1 && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2868 ch
== '.' || ch
== '@' || ch
== '^' ||
2869 ch
== '\'' || ch
== 130 || ch
== '`')
2870 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2873 flags
|= GCT_SHORTCHAR
; /* Bug compatable with win32 */
2874 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2879 /*************************************************************************
2880 * SHLWAPI_UseSystemForSystemFolders
2882 * Internal helper for PathMakeSystemFolderW.
2884 static BOOL
SHLWAPI_UseSystemForSystemFolders()
2886 static BOOL bCheckedReg
= FALSE
;
2887 static BOOL bUseSystemForSystemFolders
= FALSE
;
2893 /* Key tells Win what file attributes to use on system folders */
2894 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
2895 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2896 "UseSystemForSystemFolders", 0, 0, 0))
2897 bUseSystemForSystemFolders
= TRUE
;
2899 return bUseSystemForSystemFolders
;
2902 /*************************************************************************
2903 * PathMakeSystemFolderA [SHLWAPI.@]
2905 * Set system folder attribute for a path.
2908 * lpszPath [I] The path to turn into a system folder
2911 * TRUE If the path was changed to/already was a system folder
2912 * FALSE If the path is invalid or SetFileAttributesA fails
2914 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
2918 TRACE("(%s)\n", debugstr_a(lpszPath
));
2920 if (lpszPath
&& *lpszPath
)
2922 WCHAR szPath
[MAX_PATH
];
2923 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2924 bRet
= PathMakeSystemFolderW(szPath
);
2929 /*************************************************************************
2930 * PathMakeSystemFolderW [SHLWAPI.@]
2932 * See PathMakeSystemFolderA.
2934 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
2936 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
2937 WCHAR buff
[MAX_PATH
];
2939 TRACE("(%s)\n", debugstr_w(lpszPath
));
2941 if (!lpszPath
|| !*lpszPath
)
2944 /* If the directory is already a system directory, dont do anything */
2945 GetSystemDirectoryW(buff
, MAX_PATH
);
2946 if (!strcmpW(buff
, lpszPath
))
2949 GetWindowsDirectoryW(buff
, MAX_PATH
);
2950 if (!strcmpW(buff
, lpszPath
))
2953 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
2954 if (SHLWAPI_UseSystemForSystemFolders())
2955 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
2957 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == -1u)
2960 /* Change file attributes to system attributes */
2961 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
2962 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
2965 /*************************************************************************
2966 * PathRenameExtensionA [SHLWAPI.@]
2968 * Swap the file extension in a path with another extension.
2971 * pszPath [O] Path to swap the extension in
2972 * pszExt [I] The new extension
2975 * TRUE if pszPath was modified
2976 * FALSE if pszPath or pszExt is NULL, or the new path is too long
2978 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
2980 LPSTR lpszExtension
;
2982 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
2984 lpszExtension
= PathFindExtensionA(lpszPath
);
2986 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
2989 strcpy(lpszExtension
, lpszExt
);
2993 /*************************************************************************
2994 * PathRenameExtensionW [SHLWAPI.@]
2996 * See PathRenameExtensionA.
2998 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3000 LPWSTR lpszExtension
;
3002 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3004 lpszExtension
= PathFindExtensionW(lpszPath
);
3006 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3009 strcpyW(lpszExtension
, lpszExt
);
3013 /*************************************************************************
3014 * PathSearchAndQualifyA [SHLWAPI.@]
3016 * Determine if a given path is correct and fully qualified.
3019 * lpszPath [I] Path to check
3020 * lpszBuf [O] Output for correct path
3021 * cchBuf [I] Size of lpszBuf
3026 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3028 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3032 /*************************************************************************
3033 * PathSearchAndQualifyW [SHLWAPI.@]
3035 * See PathSearchAndQualifyA
3037 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3039 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3043 /*************************************************************************
3044 * PathSkipRootA [SHLWAPI.@]
3046 * Return the portion of a path following the drive letter or mount point.
3049 * lpszPath [I] The path to skip on
3052 * Success: A pointer to the next character after the root.
3053 * Failure: NULL, if lpszPath is invalid, has no root or is a MB string.
3055 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3057 TRACE("(%s)\n", debugstr_a(lpszPath
));
3059 if (!lpszPath
|| !*lpszPath
)
3062 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3064 /* Network share: skip share server and mount point */
3066 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3067 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3069 return (LPSTR
)lpszPath
;
3072 if (IsDBCSLeadByte(*lpszPath
))
3076 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3077 return (LPSTR
)lpszPath
+ 3;
3081 /*************************************************************************
3082 * PathSkipRootW [SHLWAPI.@]
3084 * See PathSkipRootA.
3086 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3088 TRACE("(%s)\n", debugstr_w(lpszPath
));
3090 if (!lpszPath
|| !*lpszPath
)
3093 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3095 /* Network share: skip share server and mount point */
3097 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3098 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3100 return (LPWSTR
)lpszPath
;
3104 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3105 return (LPWSTR
)lpszPath
+ 3;
3109 /*************************************************************************
3110 * PathCreateFromUrlA [SHLWAPI.@]
3112 * Create a path from a URL
3115 * lpszUrl [I] URL to convert into a path
3116 * lpszPath [O] Output buffer for the resulting Path
3117 * pcchPath [I] Length of lpszPath
3118 * dwFlags [I] Flags controlling the conversion
3121 * Success: S_OK. lpszPath contains the URL in path format
3122 * Failure: An HRESULT error code such as E_INVALIDARG.
3124 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR lpszUrl
, LPSTR lpszPath
,
3125 LPDWORD pcchPath
, DWORD dwFlags
)
3127 FIXME("(%s,%p,%p,0x%08lx)-stub\n", debugstr_a(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3129 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3130 return E_INVALIDARG
;
3132 /* extracts thing prior to : in pszURL and checks against:
3136 * about - if match returns E_INVALIDARG
3142 /*************************************************************************
3143 * PathCreateFromUrlW [SHLWAPI.@]
3145 * See PathCreateFromUrlA.
3147 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR lpszUrl
, LPWSTR lpszPath
,
3148 LPDWORD pcchPath
, DWORD dwFlags
)
3150 FIXME("(%s,%p,%p,0x%08lx)-stub\n", debugstr_w(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3152 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3153 return E_INVALIDARG
;
3158 /*************************************************************************
3159 * PathRelativePathToA [SHLWAPI.@]
3161 * Create a relative path from one path to another.
3164 * lpszPath [O] Destination for relative path
3165 * lpszFrom [I] Source path
3166 * dwAttrFrom [I] File attribute of source path
3167 * lpszTo [I] Destination path
3168 * dwAttrTo [I] File attributes of destination path
3171 * TRUE If a relative path can be formed. lpszPath contains the new path
3172 * FALSE If the paths are not relavtive or any parameters are invalid
3175 * lpszTo should be at least MAX_PATH in length.
3176 * Calling this function with relative paths for lpszFrom or lpszTo may
3177 * give erroneous results.
3179 * The Win32 version of this function contains a bug where the lpszTo string
3180 * may be referenced 1 byte beyond the end of the string. As a result random
3181 * garbage may be written to the output path, depending on what lies beyond
3182 * the last byte of the string. This bug occurs because of the behaviour of
3183 * PathCommonPrefix (see notes for that function), and no workaround seems
3184 * possible with Win32.
3185 * This bug has been fixed here, so for example the relative path from "\\"
3186 * to "\\" is correctly determined as "." in this implementation.
3188 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3189 LPCSTR lpszTo
, DWORD dwAttrTo
)
3193 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_a(lpszFrom
),
3194 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3196 if(lpszPath
&& lpszFrom
&& lpszTo
)
3198 WCHAR szPath
[MAX_PATH
];
3199 WCHAR szFrom
[MAX_PATH
];
3200 WCHAR szTo
[MAX_PATH
];
3201 MultiByteToWideChar(0,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3202 MultiByteToWideChar(0,0,lpszTo
,-1,szTo
,MAX_PATH
);
3203 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3204 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3209 /*************************************************************************
3210 * PathRelativePathToW [SHLWAPI.@]
3212 * See PathRelativePathToA.
3214 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3215 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3217 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3218 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3219 WCHAR szFrom
[MAX_PATH
];
3220 WCHAR szTo
[MAX_PATH
];
3223 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_w(lpszFrom
),
3224 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3226 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3230 strncpyW(szFrom
, lpszFrom
, MAX_PATH
);
3231 strncpyW(szTo
, lpszTo
, MAX_PATH
);
3233 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3234 PathRemoveFileSpecW(szFrom
);
3235 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3236 PathRemoveFileSpecW(szTo
);
3238 /* Paths can only be relative if they have a common root */
3239 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3242 /* Strip off lpszFrom components to the root, by adding "..\" */
3243 lpszFrom
= szFrom
+ dwLen
;
3249 if (*lpszFrom
== '\\')
3254 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3255 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3258 /* From the root add the components of lpszTo */
3260 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3263 if (*lpszTo
&& lpszTo
[-1])
3265 if (*lpszTo
!= '\\')
3267 dwLen
= strlenW(lpszPath
);
3268 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3273 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3278 /*************************************************************************
3279 * PathUnmakeSystemFolderA [SHLWAPI.@]
3281 * Remove the system folder attributes from a path.
3284 * lpszPath [I] The path to remove attributes from
3288 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3289 * SetFileAttributesA fails.
3291 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3295 TRACE("(%s)\n", debugstr_a(lpszPath
));
3297 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == -1u ||
3298 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3301 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3302 return SetFileAttributesA(lpszPath
, dwAttr
);
3305 /*************************************************************************
3306 * PathUnmakeSystemFolderW [SHLWAPI.@]
3308 * See PathUnmakeSystemFolderA.
3310 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3314 TRACE("(%s)\n", debugstr_w(lpszPath
));
3316 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == -1u ||
3317 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3320 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3321 return SetFileAttributesW(lpszPath
, dwAttr
);
3325 /*************************************************************************
3326 * PathSetDlgItemPathA [SHLWAPI.@]
3328 * Set the text of a dialog item to a path, shrinking the path to fit
3329 * if it is too big for the item.
3332 * hDlg [I] Dialog handle
3333 * id [I] ID of item in the dialog
3334 * lpszPath [I] Path to set as the items text
3340 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3341 * window text is erased).
3343 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3345 WCHAR szPath
[MAX_PATH
];
3347 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3350 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3353 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3356 /*************************************************************************
3357 * PathSetDlgItemPathW [SHLWAPI.@]
3359 * See PathSetDlgItemPathA.
3361 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3363 WCHAR path
[MAX_PATH
+ 1];
3369 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3371 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3375 strncpyW(path
, lpszPath
, sizeof(path
));
3379 GetClientRect(hwItem
, &rect
);
3381 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3385 PathCompactPathW(hdc
, path
, rect
.right
);
3386 SelectObject(hdc
, hPrevObj
);
3389 ReleaseDC(hDlg
, hdc
);
3390 SetWindowTextW(hwItem
, path
);
3393 /*************************************************************************
3394 * PathIsNetworkPathA [SHLWAPI.@]
3396 * Determine if the given path is a network path.
3399 * lpszPath [I] Path to check
3402 * TRUE If path is a UNC share or mapped network drive
3403 * FALSE If path is a local drive or cannot be determined
3405 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3409 TRACE("(%s)\n",debugstr_a(lpszPath
));
3413 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3415 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3416 if (dwDriveNum
== -1u)
3418 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3419 return pIsNetDrive(dwDriveNum
);
3422 /*************************************************************************
3423 * PathIsNetworkPathW [SHLWAPI.@]
3425 * See PathIsNetworkPathA.
3427 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3431 TRACE("(%s)\n", debugstr_w(lpszPath
));
3435 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3437 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3438 if (dwDriveNum
== -1u)
3440 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3441 return pIsNetDrive(dwDriveNum
);
3444 /*************************************************************************
3445 * PathIsLFNFileSpecA [SHLWAPI.@]
3447 * Determine if the given path is a long file name
3450 * lpszPath [I] Path to check
3453 * TRUE If path is a long file name
3454 * FALSE If path is a valid DOS 8.3 file name
3456 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3458 DWORD dwNameLen
= 0, dwExtLen
= 0;
3460 TRACE("(%s)\n",debugstr_a(lpszPath
));
3467 if (*lpszPath
== ' ')
3468 return TRUE
; /* DOS names cannot have spaces */
3469 if (*lpszPath
== '.')
3472 return TRUE
; /* DOS names have only one dot */
3479 return TRUE
; /* DOS extensions are <= 3 chars*/
3485 return TRUE
; /* DOS names are <= 8 chars */
3487 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3489 return FALSE
; /* Valid DOS path */
3492 /*************************************************************************
3493 * PathIsLFNFileSpecW [SHLWAPI.@]
3495 * See PathIsLFNFileSpecA.
3497 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3499 DWORD dwNameLen
= 0, dwExtLen
= 0;
3501 TRACE("(%s)\n",debugstr_w(lpszPath
));
3508 if (*lpszPath
== ' ')
3509 return TRUE
; /* DOS names cannot have spaces */
3510 if (*lpszPath
== '.')
3513 return TRUE
; /* DOS names have only one dot */
3520 return TRUE
; /* DOS extensions are <= 3 chars*/
3526 return TRUE
; /* DOS names are <= 8 chars */
3530 return FALSE
; /* Valid DOS path */
3533 /*************************************************************************
3534 * PathIsDirectoryEmptyA [SHLWAPI.@]
3536 * Determine if a given directory is empty.
3539 * lpszPath [I] Directory to check
3542 * TRUE If the directory exists and contains no files
3545 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3549 TRACE("(%s)\n",debugstr_a(lpszPath
));
3553 WCHAR szPath
[MAX_PATH
];
3554 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3555 bRet
= PathIsDirectoryEmptyW(szPath
);
3560 /*************************************************************************
3561 * PathIsDirectoryEmptyW [SHLWAPI.@]
3563 * See PathIsDirectoryEmptyA.
3565 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3567 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3568 WCHAR szSearch
[MAX_PATH
];
3571 BOOL retVal
= FALSE
;
3572 WIN32_FIND_DATAW find_data
;
3574 TRACE("(%s)\n",debugstr_w(lpszPath
));
3576 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3579 strncpyW(szSearch
, lpszPath
, MAX_PATH
);
3580 PathAddBackslashW(szSearch
);
3581 dwLen
= strlenW(szSearch
);
3582 if (dwLen
> MAX_PATH
- 4)
3585 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3586 hfind
= FindFirstFileW(szSearch
, &find_data
);
3588 if (hfind
!= INVALID_HANDLE_VALUE
&&
3589 find_data
.cFileName
[0] == '.' &&
3590 find_data
.cFileName
[1] == '.')
3592 /* The only directory entry should be the parent */
3593 if (!FindNextFileW(hfind
, &find_data
))
3601 /*************************************************************************
3602 * PathFindSuffixArrayA [SHLWAPI.@]
3604 * Find a suffix string in an array of suffix strings
3607 * lpszSuffix [I] Suffix string to search for
3608 * lppszArray [I] Array of suffix strings to search
3609 * dwCount [I] Number of elements in lppszArray
3612 * Success The index of the position of lpszSuffix in lppszArray
3613 * Failure 0, if any parameters are invalid or lpszSuffix is not found
3616 * The search is case sensitive.
3617 * The match is made against the end of the suffix string, so for example:
3618 * lpszSuffix=fooBAR matches BAR, but lpszSuffix=fooBARfoo does not.
3620 int WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3625 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3627 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3629 dwLen
= strlen(lpszSuffix
);
3631 while (dwRet
< dwCount
)
3633 DWORD dwCompareLen
= strlen(*lppszArray
);
3634 if (dwCompareLen
< dwLen
)
3636 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3637 return dwRet
; /* Found */
3646 /*************************************************************************
3647 * PathFindSuffixArrayW [SHLWAPI.@]
3649 * See PathFindSuffixArrayA.
3651 int WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3656 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3658 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3660 dwLen
= strlenW(lpszSuffix
);
3662 while (dwRet
< dwCount
)
3664 DWORD dwCompareLen
= strlenW(*lppszArray
);
3665 if (dwCompareLen
< dwLen
)
3667 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3668 return dwRet
; /* Found */
3677 /*************************************************************************
3678 * PathUndecorateA [SHLWAPI.@]
3680 * Undecorate a file path
3683 * lpszPath [O] Path to undecorate
3689 * A decorations form is "path[n].ext" where n is an optional decimal number.
3691 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3693 TRACE("(%s)\n",debugstr_a(lpszPath
));
3697 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3698 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3700 LPSTR lpszSkip
= lpszExt
- 2;
3701 if (*lpszSkip
== '[')
3702 lpszSkip
++; /* [] (no number) */
3704 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3706 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3708 /* remove the [n] */
3711 *lpszSkip
++ = *lpszExt
++;
3718 /*************************************************************************
3719 * PathUndecorateW [SHLWAPI.@]
3721 * See PathUndecorateA.
3723 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3725 TRACE("(%s)\n",debugstr_w(lpszPath
));
3729 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3730 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3732 LPWSTR lpszSkip
= lpszExt
- 2;
3733 if (*lpszSkip
== '[')
3734 lpszSkip
++; /* [] (no number) */
3736 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3738 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3740 /* remove the [n] */
3743 *lpszSkip
++ = *lpszExt
++;