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 * lpszFile [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},
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. lpszPath 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 PathFindOnPathA()) 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 lpszFile.
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
1347 * Some relative paths will be different when cchMax == 5 or 6. This occurs
1348 * because Win32 will insert a "\" in lpszDest, even if one is
1349 * not present in the original path.
1351 BOOL WINAPI
PathCompactPathExA(LPSTR lpszDest
, LPCSTR lpszPath
,
1352 UINT cchMax
, DWORD dwFlags
)
1356 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_a(lpszPath
), cchMax
, dwFlags
);
1358 if (lpszPath
&& lpszDest
)
1360 WCHAR szPath
[MAX_PATH
];
1361 WCHAR szDest
[MAX_PATH
];
1363 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
1365 bRet
= PathCompactPathExW(szDest
, szPath
, cchMax
, dwFlags
);
1366 WideCharToMultiByte(0,0,szDest
,-1,lpszDest
,MAX_PATH
,0,0);
1371 /*************************************************************************
1372 * PathCompactPathExW [SHLWAPI.@]
1374 * See PathCompactPathExA.
1376 BOOL WINAPI
PathCompactPathExW(LPWSTR lpszDest
, LPCWSTR lpszPath
,
1377 UINT cchMax
, DWORD dwFlags
)
1379 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
1381 DWORD dwLen
, dwFileLen
= 0;
1383 TRACE("(%p,%s,%d,0x%08lx)\n", lpszDest
, debugstr_w(lpszPath
), cchMax
, dwFlags
);
1390 WARN("Invalid lpszDest would crash under Win32!\n");
1399 dwLen
= strlenW(lpszPath
) + 1;
1403 /* Don't need to compact */
1404 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1408 /* Path must be compacted to fit into lpszDest */
1409 lpszFile
= PathFindFileNameW(lpszPath
);
1410 dwFileLen
= lpszPath
+ dwLen
- lpszFile
;
1412 if (dwFileLen
== dwLen
)
1414 /* No root in psth */
1417 while (--cchMax
> 0) /* No room left for anything but ellipses */
1422 /* Compact the file name with ellipses at the end */
1424 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1425 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1428 /* We have a root in the path */
1429 lpszFile
--; /* Start compacted filename with the path seperator */
1432 if (dwFileLen
+ 3 > cchMax
)
1434 /* Compact the file name */
1437 while (--cchMax
> 0) /* No room left for anything but ellipses */
1442 strcpyW(lpszDest
, szEllipses
);
1445 *lpszDest
++ = *lpszFile
++;
1448 while (--cchMax
> 0) /* No room left for anything but ellipses */
1454 memcpy(lpszDest
, lpszFile
, cchMax
* sizeof(WCHAR
));
1455 strcpyW(lpszDest
+ cchMax
, szEllipses
);
1459 /* Only the root needs to be Compacted */
1460 dwLen
= cchMax
- dwFileLen
- 3;
1461 memcpy(lpszDest
, lpszPath
, dwLen
* sizeof(WCHAR
));
1462 strcpyW(lpszDest
+ dwLen
, szEllipses
);
1463 strcpyW(lpszDest
+ dwLen
+ 3, lpszFile
);
1467 /*************************************************************************
1468 * PathIsRelativeA [SHLWAPI.@]
1470 * Determine if a path is a relative path.
1473 * lpszPath [I] Path to check
1476 * TRUE: The path is relative, or is invalid.
1477 * FALSE: The path is not relative.
1479 BOOL WINAPI
PathIsRelativeA (LPCSTR lpszPath
)
1481 TRACE("(%s)\n",debugstr_a(lpszPath
));
1483 if (!lpszPath
|| !*lpszPath
|| IsDBCSLeadByte(*lpszPath
))
1485 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1490 /*************************************************************************
1491 * PathIsRelativeW [SHLWAPI.@]
1493 * See PathIsRelativeA.
1495 BOOL WINAPI
PathIsRelativeW (LPCWSTR lpszPath
)
1497 TRACE("(%s)\n",debugstr_w(lpszPath
));
1499 if (!lpszPath
|| !*lpszPath
)
1501 if (*lpszPath
== '\\' || (*lpszPath
&& lpszPath
[1] == ':'))
1506 /*************************************************************************
1507 * PathIsRootA [SHLWAPI.@]
1509 * Determine if a path is a root path.
1512 * lpszPath [I] Path to check
1515 * TRUE If lpszPath is valid and a root path,
1518 BOOL WINAPI
PathIsRootA(LPCSTR lpszPath
)
1520 TRACE("(%s)\n", debugstr_a(lpszPath
));
1522 if (lpszPath
&& *lpszPath
)
1524 if (*lpszPath
== '\\')
1527 return TRUE
; /* \ */
1528 else if (lpszPath
[1]=='\\')
1530 BOOL bSeenSlash
= FALSE
;
1533 /* Check for UNC root path */
1536 if (*lpszPath
== '\\')
1542 lpszPath
= CharNextA(lpszPath
);
1547 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1548 return TRUE
; /* X:\ */
1553 /*************************************************************************
1554 * PathIsRootW [SHLWAPI.@]
1558 BOOL WINAPI
PathIsRootW(LPCWSTR lpszPath
)
1560 TRACE("(%s)\n", debugstr_w(lpszPath
));
1562 if (lpszPath
&& *lpszPath
)
1564 if (*lpszPath
== '\\')
1567 return TRUE
; /* \ */
1568 else if (lpszPath
[1]=='\\')
1570 BOOL bSeenSlash
= FALSE
;
1573 /* Check for UNC root path */
1576 if (*lpszPath
== '\\')
1582 lpszPath
= CharNextW(lpszPath
);
1587 else if (lpszPath
[1] == ':' && lpszPath
[2] == '\\' && lpszPath
[3] == '\0')
1588 return TRUE
; /* X:\ */
1593 /*************************************************************************
1594 * PathIsDirectoryA [SHLWAPI.@]
1596 * Determine if a path is a valid directory
1599 * lpszPath [I] Path to check.
1602 * FILE_ATTRIBUTE_DIRECTORY if lpszPath exists and can be read (See Notes)
1603 * FALSE if lpszPath is invalid or not a directory.
1606 * Although this function is prototyped as returning a BOOL, it returns
1607 * FILE_ATTRIBUTE_DIRECTORY for success. This means that code such as:
1609 *| if (PathIsDirectoryA("c:\\windows\\") == TRUE)
1614 BOOL WINAPI
PathIsDirectoryA(LPCSTR lpszPath
)
1618 TRACE("(%s)\n", debugstr_a(lpszPath
));
1620 if (!lpszPath
|| PathIsUNCServerA(lpszPath
))
1623 if (PathIsUNCServerShareA(lpszPath
))
1625 FIXME("UNC Server Share not yet supported - FAILING\n");
1629 if ((dwAttr
= GetFileAttributesA(lpszPath
)) == -1u)
1631 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1634 /*************************************************************************
1635 * PathIsDirectoryW [SHLWAPI.@]
1637 * See PathIsDirectoryA.
1639 BOOL WINAPI
PathIsDirectoryW(LPCWSTR lpszPath
)
1643 TRACE("(%s)\n", debugstr_w(lpszPath
));
1645 if (!lpszPath
|| PathIsUNCServerW(lpszPath
))
1648 if (PathIsUNCServerShareW(lpszPath
))
1650 FIXME("UNC Server Share not yet supported - FAILING\n");
1654 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == -1u)
1656 return dwAttr
& FILE_ATTRIBUTE_DIRECTORY
;
1659 /*************************************************************************
1660 * PathFileExistsA [SHLWAPI.@]
1662 * Determine if a file exists.
1665 * lpszPath [I] Path to check
1668 * TRUE If the file exists and is readable
1671 BOOL WINAPI
PathFileExistsA(LPCSTR lpszPath
)
1676 TRACE("(%s)\n",debugstr_a(lpszPath
));
1681 iPrevErrMode
= SetErrorMode(1);
1682 dwAttr
= GetFileAttributesA(lpszPath
);
1683 SetErrorMode(iPrevErrMode
);
1684 return dwAttr
== -1u ? FALSE
: TRUE
;
1687 /*************************************************************************
1688 * PathFileExistsW [SHLWAPI.@]
1690 * See PathFileExistsA
1692 BOOL WINAPI
PathFileExistsW(LPCWSTR lpszPath
)
1697 TRACE("(%s)\n",debugstr_w(lpszPath
));
1702 iPrevErrMode
= SetErrorMode(1);
1703 dwAttr
= GetFileAttributesW(lpszPath
);
1704 SetErrorMode(iPrevErrMode
);
1705 return dwAttr
== -1u ? FALSE
: TRUE
;
1708 /*************************************************************************
1709 * PathMatchSingleMaskA [internal]
1712 * internal (used by PathMatchSpec)
1714 static BOOL
PathMatchSingleMaskA(LPCSTR name
, LPCSTR mask
)
1716 while (*name
&& *mask
&& *mask
!=';')
1722 if (PathMatchSingleMaskA(name
,mask
+1)) return 1; /* try substrings */
1726 if (toupper(*mask
)!=toupper(*name
) && *mask
!='?') return 0;
1727 name
= CharNextA(name
);
1728 mask
= CharNextA(mask
);
1732 while (*mask
=='*') mask
++;
1733 if (!*mask
|| *mask
==';') return 1;
1738 /*************************************************************************
1739 * PathMatchSingleMaskW [internal]
1741 static BOOL
PathMatchSingleMaskW(LPCWSTR name
, LPCWSTR mask
)
1743 while (*name
&& *mask
&& *mask
!=';')
1749 if (PathMatchSingleMaskW(name
,mask
+1)) return 1; /* try substrings */
1753 if (toupperW(*mask
)!=toupperW(*name
) && *mask
!='?') return 0;
1754 name
= CharNextW(name
);
1755 mask
= CharNextW(mask
);
1759 while (*mask
=='*') mask
++;
1760 if (!*mask
|| *mask
==';') return 1;
1765 /*************************************************************************
1766 * PathMatchSpecA [SHLWAPI.@]
1768 * Determine if a path matches one or more search masks.
1771 * lpszPath [I] Path to check
1772 * lpszMask [I] Search mask(s)
1775 * TRUE If lpszPath is valid and is matched
1779 * Multiple search masks may be given if they are seperated by ";". The
1780 * pattern "*.*" is treated specially in that it matches all paths (for
1781 * backwards compatability with DOS).
1783 BOOL WINAPI
PathMatchSpecA(LPCSTR lpszPath
, LPCSTR lpszMask
)
1785 TRACE("%s %s\n", lpszPath
, lpszMask
);
1787 if (!lstrcmpA( lpszMask
, "*.*" )) return 1; /* we don't require a period */
1791 if (PathMatchSingleMaskA(lpszPath
,lpszMask
)) return 1; /* helper function */
1792 while (*lpszMask
&& *lpszMask
!=';') lpszMask
= CharNextA(lpszMask
);
1796 while (*lpszMask
==' ') lpszMask
++; /* masks may be separated by "; " */
1802 /*************************************************************************
1803 * PathMatchSpecW [SHLWAPI.@]
1805 * See PathMatchSpecA.
1807 BOOL WINAPI
PathMatchSpecW(LPCWSTR name
, LPCWSTR mask
)
1809 static const WCHAR stemp
[] = { '*','.','*',0 };
1810 TRACE("%s %s\n",debugstr_w(name
),debugstr_w(mask
));
1812 if (!lstrcmpW( mask
, stemp
)) return 1; /* we don't require a period */
1816 if (PathMatchSingleMaskW(name
,mask
)) return 1; /* helper function */
1817 while (*mask
&& *mask
!=';') mask
= CharNextW(mask
);
1821 while (*mask
==' ') mask
++; /* masks may be separated by "; " */
1827 /*************************************************************************
1828 * PathIsSameRootA [SHLWAPI.@]
1830 * Determine if two paths share the same root.
1833 * lpszPath1 [I] Source path
1834 * lpszPath2 [I] Path to compare with
1837 * TRUE If both paths are valid and share the same root.
1838 * FALSE If either path is invalid or the paths do not share the same root.
1840 BOOL WINAPI
PathIsSameRootA(LPCSTR lpszPath1
, LPCSTR lpszPath2
)
1845 TRACE("(%s,%s)\n", debugstr_a(lpszPath1
), debugstr_a(lpszPath2
));
1847 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootA(lpszPath1
)))
1850 dwLen
= PathCommonPrefixA(lpszPath1
, lpszPath2
, NULL
) + 1;
1851 if (lpszStart
- lpszPath1
> dwLen
)
1852 return FALSE
; /* Paths not common up to length of the root */
1856 /*************************************************************************
1857 * PathIsSameRootW [SHLWAPI.@]
1859 * See PathIsSameRootA.
1861 BOOL WINAPI
PathIsSameRootW(LPCWSTR lpszPath1
, LPCWSTR lpszPath2
)
1866 TRACE("(%s,%s)\n", debugstr_w(lpszPath1
), debugstr_w(lpszPath2
));
1868 if (!lpszPath1
|| !lpszPath2
|| !(lpszStart
= PathSkipRootW(lpszPath1
)))
1871 dwLen
= PathCommonPrefixW(lpszPath1
, lpszPath2
, NULL
) + 1;
1872 if (lpszStart
- lpszPath1
> dwLen
)
1873 return FALSE
; /* Paths not common up to length of the root */
1877 /*************************************************************************
1878 * PathIsContentTypeA [SHLWAPI.@]
1880 * Determine if a file is of a given registered content type.
1883 * lpszPath [I] file to check
1886 * TRUE If lpszPath is a given registered content type,
1890 * This function looks up the registered content type for lpszPath. If
1891 * a content type is registered, it is compared (case insensitively) to
1892 * lpszContentType. Only if this matches does the function succeed.
1894 BOOL WINAPI
PathIsContentTypeA(LPCSTR lpszPath
, LPCSTR lpszContentType
)
1898 char szBuff
[MAX_PATH
];
1900 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszContentType
));
1902 if (lpszPath
&& (szExt
= PathFindExtensionA(lpszPath
)) && *szExt
&&
1903 !SHGetValueA(HKEY_CLASSES_ROOT
, szExt
, "Content Type",
1904 REG_NONE
, szBuff
, &dwDummy
) &&
1905 !strcasecmp(lpszContentType
, szBuff
))
1912 /*************************************************************************
1913 * PathIsContentTypeW [SHLWAPI.@]
1915 * See PathIsContentTypeA.
1917 BOOL WINAPI
PathIsContentTypeW(LPCWSTR lpszPath
, LPCWSTR lpszContentType
)
1919 static const WCHAR szContentType
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0' };
1922 WCHAR szBuff
[MAX_PATH
];
1924 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszContentType
));
1926 if (lpszPath
&& (szExt
= PathFindExtensionW(lpszPath
)) && *szExt
&&
1927 !SHGetValueW(HKEY_CLASSES_ROOT
, szExt
, szContentType
,
1928 REG_NONE
, szBuff
, &dwDummy
) &&
1929 !strcmpiW(lpszContentType
, szBuff
))
1936 /*************************************************************************
1937 * PathIsFileSpecA [SHLWAPI.@]
1939 * Determine if a path is a file specification.
1942 * lpszPath [I] Path to chack
1945 * TRUE If lpszPath is a file spec (contains no directories).
1948 BOOL WINAPI
PathIsFileSpecA(LPCSTR lpszPath
)
1950 TRACE("(%s)\n", debugstr_a(lpszPath
));
1957 if (*lpszPath
== '\\' || *lpszPath
== ':')
1959 lpszPath
= CharNextA(lpszPath
);
1964 /*************************************************************************
1965 * PathIsFileSpecW [SHLWAPI.@]
1967 * See PathIsFileSpecA.
1969 BOOL WINAPI
PathIsFileSpecW(LPCWSTR lpszPath
)
1971 TRACE("(%s)\n", debugstr_w(lpszPath
));
1978 if (*lpszPath
== '\\' || *lpszPath
== ':')
1980 lpszPath
= CharNextW(lpszPath
);
1985 /*************************************************************************
1986 * PathIsPrefixA [SHLWAPI.@]
1988 * Determine if a path is a prefix of another.
1991 * lpszPrefix [I] Prefix
1992 * lpszPath [i] Path to check
1995 * TRUE If lpszPath has lpszPrefix as its prefix,
1996 * FALSE If either path is NULL or lpszPrefix is not a prefix
1998 BOOL WINAPI
PathIsPrefixA (LPCSTR lpszPrefix
, LPCSTR lpszPath
)
2000 TRACE("(%s,%s)\n", debugstr_a(lpszPrefix
), debugstr_a(lpszPath
));
2002 if (lpszPrefix
&& lpszPath
&&
2003 PathCommonPrefixA(lpszPath
, lpszPrefix
, NULL
) == (int)strlen(lpszPrefix
))
2008 /*************************************************************************
2009 * PathIsPrefixW [SHLWAPI.@]
2011 * See PathIsPrefixA.
2013 BOOL WINAPI
PathIsPrefixW(LPCWSTR lpszPrefix
, LPCWSTR lpszPath
)
2015 TRACE("(%s,%s)\n", debugstr_w(lpszPrefix
), debugstr_w(lpszPath
));
2017 if (lpszPrefix
&& lpszPath
&&
2018 PathCommonPrefixW(lpszPath
, lpszPrefix
, NULL
) == (int)strlenW(lpszPrefix
))
2023 /*************************************************************************
2024 * PathIsSystemFolderA [SHLWAPI.@]
2026 * Determine if a path or file attributes are a system folder.
2029 * lpszPath [I] Path to check.
2030 * dwAttrib [I] Attributes to check, if lpszPath is NULL.
2033 * TRUE If lpszPath or dwAttrib are a system folder.
2034 * FALSE If GetFileAttributesA() fails or neither parameter is a system folder.
2036 BOOL WINAPI
PathIsSystemFolderA(LPCSTR lpszPath
, DWORD dwAttrib
)
2038 TRACE("(%s,0x%08lx)\n", debugstr_a(lpszPath
), dwAttrib
);
2040 if (lpszPath
&& *lpszPath
)
2041 dwAttrib
= GetFileAttributesA(lpszPath
);
2043 if (dwAttrib
== -1u || !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2044 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2049 /*************************************************************************
2050 * PathIsSystemFolderW [SHLWAPI.@]
2052 * See PathIsSystemFolderA.
2054 BOOL WINAPI
PathIsSystemFolderW(LPCWSTR lpszPath
, DWORD dwAttrib
)
2056 TRACE("(%s,0x%08lx)\n", debugstr_w(lpszPath
), dwAttrib
);
2058 if (lpszPath
&& *lpszPath
)
2059 dwAttrib
= GetFileAttributesW(lpszPath
);
2061 if (dwAttrib
== -1u || !(dwAttrib
& FILE_ATTRIBUTE_DIRECTORY
) ||
2062 !(dwAttrib
& (FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_READONLY
)))
2067 /*************************************************************************
2068 * PathIsUNCA [SHLWAPI.@]
2070 * Determine if a path is in UNC format.
2073 * lpszPath [I] Path to check
2076 * TRUE: The path is UNC.
2077 * FALSE: The path is not UNC or is NULL.
2079 BOOL WINAPI
PathIsUNCA(LPCSTR lpszPath
)
2081 TRACE("(%s)\n",debugstr_a(lpszPath
));
2083 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2088 /*************************************************************************
2089 * PathIsUNCW [SHLWAPI.@]
2093 BOOL WINAPI
PathIsUNCW(LPCWSTR lpszPath
)
2095 TRACE("(%s)\n",debugstr_w(lpszPath
));
2097 if (lpszPath
&& (lpszPath
[0]=='\\') && (lpszPath
[1]=='\\'))
2102 /*************************************************************************
2103 * PathIsUNCServerA [SHLWAPI.@]
2105 * Determine if a path is a UNC server name ("\\SHARENAME").
2108 * lpszPath [I] Path to check.
2111 * TRUE If lpszPath is a valid UNC server name.
2115 * This routine is bug compatible with Win32: Server names with a
2116 * trailing backslash (e.g. "\\FOO\"), return FALSE incorrectly.
2117 * Fixing this bug may break other shlwapi functions!
2119 BOOL WINAPI
PathIsUNCServerA(LPCSTR lpszPath
)
2121 TRACE("(%s)\n", debugstr_a(lpszPath
));
2123 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2127 if (*lpszPath
== '\\')
2129 lpszPath
= CharNextA(lpszPath
);
2136 /*************************************************************************
2137 * PathIsUNCServerW [SHLWAPI.@]
2139 * See PathIsUNCServerA.
2141 BOOL WINAPI
PathIsUNCServerW(LPCWSTR lpszPath
)
2143 TRACE("(%s)\n", debugstr_w(lpszPath
));
2145 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2149 if (*lpszPath
== '\\')
2151 lpszPath
= CharNextW(lpszPath
);
2158 /*************************************************************************
2159 * PathIsUNCServerShareA [SHLWAPI.@]
2161 * Determine if a path is a UNC server share ("\\SHARENAME\SHARE").
2164 * lpszPath [I] Path to check.
2167 * TRUE If lpszPath is a valid UNC server share.
2171 * This routine is bug compatible with Win32: Server shares with a
2172 * trailing backslash (e.g. "\\FOO\BAR\"), return FALSE incorrectly.
2173 * Fixing this bug may break other shlwapi functions!
2175 BOOL WINAPI
PathIsUNCServerShareA(LPCSTR lpszPath
)
2177 TRACE("(%s)\n", debugstr_a(lpszPath
));
2179 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2181 BOOL bSeenSlash
= FALSE
;
2184 if (*lpszPath
== '\\')
2190 lpszPath
= CharNextA(lpszPath
);
2197 /*************************************************************************
2198 * PathIsUNCServerShareW [SHLWAPI.@]
2200 * See PathIsUNCServerShareA.
2202 BOOL WINAPI
PathIsUNCServerShareW(LPCWSTR lpszPath
)
2204 TRACE("(%s)\n", debugstr_w(lpszPath
));
2206 if (lpszPath
&& *lpszPath
++ == '\\' && *lpszPath
++ == '\\')
2208 BOOL bSeenSlash
= FALSE
;
2211 if (*lpszPath
== '\\')
2217 lpszPath
= CharNextW(lpszPath
);
2224 /*************************************************************************
2225 * PathCanonicalizeA [SHLWAPI.@]
2227 * Convert a path to its canonical form.
2230 * lpszBuf [O] Output path
2231 * lpszPath [I] Path to cnonicalize
2234 * Success: TRUE. lpszBuf contains the output path,
2235 * Failure: FALSE, If input path is invalid. lpszBuf is undefined
2237 BOOL WINAPI
PathCanonicalizeA(LPSTR lpszBuf
, LPCSTR lpszPath
)
2241 TRACE("(%p,%s)\n", lpszBuf
, debugstr_a(lpszPath
));
2246 if (!lpszBuf
|| !lpszPath
)
2247 SetLastError(ERROR_INVALID_PARAMETER
);
2250 WCHAR szPath
[MAX_PATH
];
2251 WCHAR szBuff
[MAX_PATH
];
2252 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2253 bRet
= PathCanonicalizeW(szBuff
, szPath
);
2254 WideCharToMultiByte(0,0,szBuff
,-1,lpszBuf
,MAX_PATH
,0,0);
2260 /*************************************************************************
2261 * PathCanonicalizeW [SHLWAPI.@]
2263 * See PathCanonicalizeA.
2265 BOOL WINAPI
PathCanonicalizeW(LPWSTR lpszBuf
, LPCWSTR lpszPath
)
2267 LPWSTR lpszDst
= lpszBuf
;
2268 LPCWSTR lpszSrc
= lpszPath
;
2270 TRACE("(%p,%s)\n", lpszBuf
, debugstr_w(lpszPath
));
2275 if (!lpszBuf
|| !lpszPath
)
2277 SetLastError(ERROR_INVALID_PARAMETER
);
2288 /* Copy path root */
2289 if (*lpszSrc
== '\\')
2291 *lpszDst
++ = *lpszSrc
++;
2293 else if (*lpszSrc
&& lpszSrc
[1] == ':')
2296 *lpszDst
++ = *lpszSrc
++;
2297 *lpszDst
++ = *lpszSrc
++;
2298 if (*lpszSrc
== '\\')
2299 *lpszDst
++ = *lpszSrc
++;
2302 /* Canonicalize the rest of the path */
2305 if (*lpszSrc
== '.')
2307 if (lpszSrc
[1] == '\\' && (lpszSrc
== lpszPath
|| lpszSrc
[-1] == '\\' || lpszSrc
[-1] == ':'))
2309 lpszSrc
+= 2; /* Skip .\ */
2311 else if (lpszSrc
[1] == '.' && (lpszDst
== lpszBuf
|| lpszDst
[-1] == '\\'))
2313 /* \.. backs up a directory, over the root if it has no \ following X:.
2314 * .. is ignored if it would remove a UNC server name or inital \\
2316 if (lpszDst
!= lpszBuf
)
2318 *lpszDst
= '\0'; /* Allow PathIsUNCServerShareA test on lpszBuf */
2319 if (lpszDst
> lpszBuf
+1 && lpszDst
[-1] == '\\' &&
2320 (lpszDst
[-2] != '\\' || lpszDst
> lpszBuf
+2))
2322 if (lpszDst
[-2] == ':' && (lpszDst
> lpszBuf
+3 || lpszDst
[-3] == ':'))
2325 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2327 if (*lpszDst
== '\\')
2328 lpszDst
++; /* Reset to last '\' */
2330 lpszDst
= lpszBuf
; /* Start path again from new root */
2332 else if (lpszDst
[-2] != ':' && !PathIsUNCServerShareW(lpszBuf
))
2335 while (lpszDst
> lpszBuf
&& *lpszDst
!= '\\')
2337 if (lpszDst
== lpszBuf
)
2343 lpszSrc
+= 2; /* Skip .. in src path */
2346 *lpszDst
++ = *lpszSrc
++;
2349 *lpszDst
++ = *lpszSrc
++;
2351 /* Append \ to naked drive specs */
2352 if (lpszDst
- lpszBuf
== 2 && lpszDst
[-1] == ':')
2358 /*************************************************************************
2359 * PathFindNextComponentA [SHLWAPI.@]
2361 * Find the next component in a path.
2364 * lpszPath [I] Path to find next component in
2367 * Success: A pointer to the next component, or the end of the string,
2368 * Failure: NULL, If lpszPath is invalid
2371 * A 'component' is either a backslash character (\) or UNC marker (\\).
2372 * Because of this, relative paths (e.g "c:foo") are regarded as having
2373 * only one component.
2375 LPSTR WINAPI
PathFindNextComponentA(LPCSTR lpszPath
)
2379 TRACE("(%s)\n", debugstr_a(lpszPath
));
2381 if(!lpszPath
|| !*lpszPath
)
2384 if ((lpszSlash
= StrChrA(lpszPath
, '\\')))
2386 if (lpszSlash
[1] == '\\')
2388 return lpszSlash
+ 1;
2390 return (LPSTR
)lpszPath
+ strlen(lpszPath
);
2393 /*************************************************************************
2394 * PathFindNextComponentW [SHLWAPI.@]
2396 * See PathFindNextComponentA.
2398 LPWSTR WINAPI
PathFindNextComponentW(LPCWSTR lpszPath
)
2402 TRACE("(%s)\n", debugstr_w(lpszPath
));
2404 if(!lpszPath
|| !*lpszPath
)
2407 if ((lpszSlash
= StrChrW(lpszPath
, '\\')))
2409 if (lpszSlash
[1] == '\\')
2411 return lpszSlash
+ 1;
2413 return (LPWSTR
)lpszPath
+ strlenW(lpszPath
);
2416 /*************************************************************************
2417 * PathAddExtensionA [SHLWAPI.@]
2419 * Add a file extension to a path
2422 * lpszPath [O] Path to add extension to
2423 * lpszExtension [I] Extension to add to lpszPath
2426 * TRUE If the path was modified,
2427 * FALSE If lpszPath or lpszExtension are invalid, lpszPath has an
2428 * extension allready, or the new path length is too big.
2431 * What version of shlwapi.dll adds "exe" if lpszExtension is NULL? Win2k
2432 * does not do this, so the behaviour was removed.
2434 BOOL WINAPI
PathAddExtensionA(LPSTR lpszPath
, LPCSTR lpszExtension
)
2438 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExtension
));
2440 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionA(lpszPath
)))
2443 dwLen
= strlen(lpszPath
);
2445 if (dwLen
+ strlen(lpszExtension
) >= MAX_PATH
)
2448 strcpy(lpszPath
+ dwLen
, lpszExtension
);
2452 /*************************************************************************
2453 * PathAddExtensionW [SHLWAPI.@]
2455 * See PathAddExtensionA.
2457 BOOL WINAPI
PathAddExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExtension
)
2461 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExtension
));
2463 if (!lpszPath
|| !lpszExtension
|| *(PathFindExtensionW(lpszPath
)))
2466 dwLen
= strlenW(lpszPath
);
2468 if (dwLen
+ strlenW(lpszExtension
) >= MAX_PATH
)
2471 strcpyW(lpszPath
+ dwLen
, lpszExtension
);
2475 /*************************************************************************
2476 * PathMakePrettyA [SHLWAPI.@]
2478 * Convert an uppercase DOS filename into lowercase.
2481 * lpszPath [O] Path to convert.
2484 * TRUE If the path was an uppercase DOS path and was converted,
2487 BOOL WINAPI
PathMakePrettyA(LPSTR lpszPath
)
2489 LPSTR pszIter
= lpszPath
;
2491 TRACE("(%s)\n", debugstr_a(lpszPath
));
2493 if (!pszIter
|| !*pszIter
)
2498 if (islower(*pszIter
) || IsDBCSLeadByte(*pszIter
))
2499 return FALSE
; /* Not DOS path */
2502 pszIter
= lpszPath
+ 1;
2505 *pszIter
= tolower(*pszIter
);
2511 /*************************************************************************
2512 * PathMakePrettyW [SHLWAPI.@]
2514 * See PathMakePrettyA
2516 BOOL WINAPI
PathMakePrettyW(LPWSTR lpszPath
)
2518 LPWSTR pszIter
= lpszPath
;
2520 TRACE("(%s)\n", debugstr_w(lpszPath
));
2522 if (!pszIter
|| !*pszIter
)
2527 if (islowerW(*pszIter
))
2528 return FALSE
; /* Not DOS path */
2531 pszIter
= lpszPath
+ 1;
2534 *pszIter
= tolowerW(*pszIter
);
2540 /*************************************************************************
2541 * PathCommonPrefixA [SHLWAPI.@]
2543 * Determine the length of the common prefix between two paths.
2546 * lpszFile1 [I] First path for comparison
2547 * lpszFile2 [I] Second path for comparison
2548 * achPath [O] Destination for common prefix string
2551 * The length of the common prefix. This is 0 if there is no common
2552 * prefix between the paths or if any parameters are invalid. If the prefix
2553 * is non-zero and achPath is not NULL, achPath is filled with the common
2554 * part of the prefix and NUL terminated.
2557 * A common prefix of 2 is always returned as 3. It is thus possible for
2558 * the length returned to be invalid (i.e. Longer than one or both of the
2559 * strings given as parameters). This Win32 behaviour has been implimented
2560 * here, and cannot be changed (fixed?) without breaking other SHLWAPI calls.
2561 * To work around this when using this function, always check that the byte
2562 * at [common_prefix_len-1] is not a NUL. If it is, deduct 1 from the prefix.
2564 int WINAPI
PathCommonPrefixA(LPCSTR lpszFile1
, LPCSTR lpszFile2
, LPSTR achPath
)
2567 LPCSTR lpszIter1
= lpszFile1
;
2568 LPCSTR lpszIter2
= lpszFile2
;
2570 TRACE("(%s,%s,%p)\n", debugstr_a(lpszFile1
), debugstr_a(lpszFile2
), achPath
);
2575 if (!lpszFile1
|| !lpszFile2
)
2578 /* Handle roots first */
2579 if (PathIsUNCA(lpszFile1
))
2581 if (!PathIsUNCA(lpszFile2
))
2586 else if (PathIsUNCA(lpszFile2
))
2587 return 0; /* Know already lpszFile1 is not UNC */
2592 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2593 (!*lpszIter2
|| *lpszIter2
== '\\'))
2594 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2596 if (!*lpszIter1
|| (tolower(*lpszIter1
) != tolower(*lpszIter2
)))
2597 break; /* Strings differ at this point */
2604 iLen
++; /* Feature/Bug compatable with Win32 */
2606 if (iLen
&& achPath
)
2608 memcpy(achPath
,lpszFile1
,iLen
);
2609 achPath
[iLen
] = '\0';
2614 /*************************************************************************
2615 * PathCommonPrefixW [SHLWAPI.@]
2617 * See PathCommonPrefixA.
2619 int WINAPI
PathCommonPrefixW(LPCWSTR lpszFile1
, LPCWSTR lpszFile2
, LPWSTR achPath
)
2622 LPCWSTR lpszIter1
= lpszFile1
;
2623 LPCWSTR lpszIter2
= lpszFile2
;
2625 TRACE("(%s,%s,%p)\n", debugstr_w(lpszFile1
), debugstr_w(lpszFile2
), achPath
);
2630 if (!lpszFile1
|| !lpszFile2
)
2633 /* Handle roots first */
2634 if (PathIsUNCW(lpszFile1
))
2636 if (!PathIsUNCW(lpszFile2
))
2641 else if (PathIsUNCW(lpszFile2
))
2642 return 0; /* Know already lpszFile1 is not UNC */
2647 if ((!*lpszIter1
|| *lpszIter1
== '\\') &&
2648 (!*lpszIter2
|| *lpszIter2
== '\\'))
2649 iLen
= lpszIter1
- lpszFile1
; /* Common to this point */
2651 if (!*lpszIter1
|| (tolowerW(*lpszIter1
) != tolowerW(*lpszIter2
)))
2652 break; /* Strings differ at this point */
2659 iLen
++; /* Feature/Bug compatable with Win32 */
2661 if (iLen
&& achPath
)
2663 memcpy(achPath
,lpszFile1
,iLen
* sizeof(WCHAR
));
2664 achPath
[iLen
] = '\0';
2669 /*************************************************************************
2670 * PathCompactPathA [SHLWAPI.@]
2672 * Make a path fit into a given width when printed to a DC.
2675 * hDc [I] Destination DC
2676 * lpszPath [O] Path to be printed to hDc
2677 * dx [i] Desired width
2680 * TRUE If the path was modified.
2683 BOOL WINAPI
PathCompactPathA(HDC hDC
, LPSTR lpszPath
, UINT dx
)
2687 TRACE("(%p,%s,%d)\n", hDC
, debugstr_a(lpszPath
), dx
);
2691 WCHAR szPath
[MAX_PATH
];
2692 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2693 bRet
= PathCompactPathW(hDC
, szPath
, dx
);
2694 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
2699 /*************************************************************************
2700 * PathCompactPathW [SHLWAPI.@]
2702 * See PathCompactPathA.
2704 BOOL WINAPI
PathCompactPathW(HDC hDC
, LPWSTR lpszPath
, UINT dx
)
2706 static const WCHAR szEllipses
[] = { '.', '.', '.', '\0' };
2709 WCHAR buff
[MAX_PATH
];
2713 TRACE("(%p,%s,%d)\n", hDC
, debugstr_w(lpszPath
), dx
);
2719 hdc
= hDC
= GetDC(0);
2721 /* Get the length of the whole path */
2722 dwLen
= strlenW(lpszPath
);
2723 GetTextExtentPointW(hDC
, lpszPath
, dwLen
, &size
);
2725 if ((UINT
)size
.cx
> dx
)
2727 /* Path too big, must reduce it */
2729 DWORD dwEllipsesLen
= 0, dwPathLen
= 0;
2731 sFile
= PathFindFileNameW(lpszPath
);
2732 if (sFile
!= lpszPath
)
2733 sFile
= CharPrevW(lpszPath
, sFile
);
2735 /* Get the size of ellipses */
2736 GetTextExtentPointW(hDC
, szEllipses
, 3, &size
);
2737 dwEllipsesLen
= size
.cx
;
2738 /* Get the size of the file name */
2739 GetTextExtentPointW(hDC
, sFile
, strlenW(sFile
), &size
);
2740 dwPathLen
= size
.cx
;
2742 if (sFile
!= lpszPath
)
2744 LPWSTR sPath
= sFile
;
2745 BOOL bEllipses
= FALSE
;
2747 /* The path includes a file name. Include as much of the path prior to
2748 * the file name as possible, allowing for the ellipses, e.g:
2749 * c:\some very long path\filename ==> c:\some v...\filename
2751 strncpyW(buff
, sFile
, MAX_PATH
);
2755 DWORD dwTotalLen
= bEllipses
? dwPathLen
+ dwEllipsesLen
: dwPathLen
;
2757 GetTextExtentPointW(hDC
, lpszPath
, sPath
- lpszPath
, &size
);
2758 dwTotalLen
+= size
.cx
;
2759 if (dwTotalLen
<= dx
)
2761 sPath
= CharPrevW(lpszPath
, sPath
);
2765 sPath
= CharPrevW(lpszPath
, sPath
);
2766 sPath
= CharPrevW(lpszPath
, sPath
);
2768 } while (sPath
> lpszPath
);
2770 if (sPath
> lpszPath
)
2774 strcpyW(sPath
, szEllipses
);
2775 strcpyW(sPath
+3, buff
);
2780 strcpyW(lpszPath
, szEllipses
);
2781 strcpyW(lpszPath
+3, buff
);
2786 /* Trim the path by adding ellipses to the end, e.g:
2787 * A very long file name.txt ==> A very...
2789 dwLen
= strlenW(lpszPath
);
2791 if (dwLen
> MAX_PATH
- 3)
2792 dwLen
= MAX_PATH
- 3;
2793 strncpyW(buff
, sFile
, dwLen
);
2797 GetTextExtentPointW(hDC
, buff
, dwLen
, &size
);
2798 } while (dwLen
&& size
.cx
+ dwEllipsesLen
> dx
);
2802 DWORD dwWritten
= 0;
2804 dwEllipsesLen
/= 3; /* Size of a single '.' */
2806 /* Write as much of the Ellipses string as possible */
2807 while (dwWritten
+ dwEllipsesLen
< dx
&& dwLen
< 3)
2810 dwWritten
+= dwEllipsesLen
;
2818 strcpyW(buff
+ dwLen
, szEllipses
);
2819 strcpyW(lpszPath
, buff
);
2830 /*************************************************************************
2831 * PathGetCharTypeA [SHLWAPI.@]
2833 * Categorise a character from a file path.
2836 * ch [I] Character to get the type of
2839 * A set of GCT_ bit flags (from "shlwapi.h") indicating the character type.
2841 UINT WINAPI
PathGetCharTypeA(UCHAR ch
)
2843 return PathGetCharTypeW(ch
);
2846 /*************************************************************************
2847 * PathGetCharTypeW [SHLWAPI.@]
2849 * See PathGetCharTypeA.
2851 UINT WINAPI
PathGetCharTypeW(WCHAR ch
)
2855 TRACE("(%d)\n", ch
);
2857 if (!ch
|| ch
< ' ' || ch
== '<' || ch
== '>' ||
2858 ch
== '"' || ch
== '|' || ch
== '/')
2859 flags
= GCT_INVALID
; /* Invalid */
2860 else if (ch
== '*' || ch
=='?')
2861 flags
= GCT_WILD
; /* Wildchars */
2862 else if ((ch
== '\\') || (ch
== ':'))
2863 return GCT_SEPARATOR
; /* Path separators */
2868 if ((ch
& 0x1 && ch
!= ';') || !ch
|| isalnum(ch
) || ch
== '$' || ch
== '&' || ch
== '(' ||
2869 ch
== '.' || ch
== '@' || ch
== '^' ||
2870 ch
== '\'' || ch
== 130 || ch
== '`')
2871 flags
|= GCT_SHORTCHAR
; /* All these are valid for DOS */
2874 flags
|= GCT_SHORTCHAR
; /* Bug compatable with win32 */
2875 flags
|= GCT_LFNCHAR
; /* Valid for long file names */
2880 /*************************************************************************
2881 * SHLWAPI_UseSystemForSystemFolders
2883 * Internal helper for PathMakeSystemFolderW.
2885 static BOOL
SHLWAPI_UseSystemForSystemFolders()
2887 static BOOL bCheckedReg
= FALSE
;
2888 static BOOL bUseSystemForSystemFolders
= FALSE
;
2894 /* Key tells Win what file attributes to use on system folders */
2895 if (SHGetValueA(HKEY_LOCAL_MACHINE
,
2896 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
2897 "UseSystemForSystemFolders", 0, 0, 0))
2898 bUseSystemForSystemFolders
= TRUE
;
2900 return bUseSystemForSystemFolders
;
2903 /*************************************************************************
2904 * PathMakeSystemFolderA [SHLWAPI.@]
2906 * Set system folder attribute for a path.
2909 * lpszPath [I] The path to turn into a system folder
2912 * TRUE If the path was changed to/already was a system folder
2913 * FALSE If the path is invalid or SetFileAttributesA() fails
2915 BOOL WINAPI
PathMakeSystemFolderA(LPCSTR lpszPath
)
2919 TRACE("(%s)\n", debugstr_a(lpszPath
));
2921 if (lpszPath
&& *lpszPath
)
2923 WCHAR szPath
[MAX_PATH
];
2924 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
2925 bRet
= PathMakeSystemFolderW(szPath
);
2930 /*************************************************************************
2931 * PathMakeSystemFolderW [SHLWAPI.@]
2933 * See PathMakeSystemFolderA.
2935 BOOL WINAPI
PathMakeSystemFolderW(LPCWSTR lpszPath
)
2937 DWORD dwDefaultAttr
= FILE_ATTRIBUTE_READONLY
, dwAttr
;
2938 WCHAR buff
[MAX_PATH
];
2940 TRACE("(%s)\n", debugstr_w(lpszPath
));
2942 if (!lpszPath
|| !*lpszPath
)
2945 /* If the directory is already a system directory, dont do anything */
2946 GetSystemDirectoryW(buff
, MAX_PATH
);
2947 if (!strcmpW(buff
, lpszPath
))
2950 GetWindowsDirectoryW(buff
, MAX_PATH
);
2951 if (!strcmpW(buff
, lpszPath
))
2954 /* "UseSystemForSystemFolders" Tells Win what attributes to use */
2955 if (SHLWAPI_UseSystemForSystemFolders())
2956 dwDefaultAttr
= FILE_ATTRIBUTE_SYSTEM
;
2958 if ((dwAttr
= GetFileAttributesW(lpszPath
)) == -1u)
2961 /* Change file attributes to system attributes */
2962 dwAttr
&= ~(FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_READONLY
);
2963 return SetFileAttributesW(lpszPath
, dwAttr
| dwDefaultAttr
);
2966 /*************************************************************************
2967 * PathRenameExtensionA [SHLWAPI.@]
2969 * Swap the file extension in a path with another extension.
2972 * lpszPath [O] Path to swap the extension in
2973 * lpszExt [I] The new extension
2976 * TRUE if lpszPath was modified,
2977 * FALSE if lpszPath or lpszExt is NULL, or the new path is too long
2979 BOOL WINAPI
PathRenameExtensionA(LPSTR lpszPath
, LPCSTR lpszExt
)
2981 LPSTR lpszExtension
;
2983 TRACE("(%s,%s)\n", debugstr_a(lpszPath
), debugstr_a(lpszExt
));
2985 lpszExtension
= PathFindExtensionA(lpszPath
);
2987 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlen(lpszExt
) >= MAX_PATH
))
2990 strcpy(lpszExtension
, lpszExt
);
2994 /*************************************************************************
2995 * PathRenameExtensionW [SHLWAPI.@]
2997 * See PathRenameExtensionA.
2999 BOOL WINAPI
PathRenameExtensionW(LPWSTR lpszPath
, LPCWSTR lpszExt
)
3001 LPWSTR lpszExtension
;
3003 TRACE("(%s,%s)\n", debugstr_w(lpszPath
), debugstr_w(lpszExt
));
3005 lpszExtension
= PathFindExtensionW(lpszPath
);
3007 if (!lpszExtension
|| (lpszExtension
- lpszPath
+ strlenW(lpszExt
) >= MAX_PATH
))
3010 strcpyW(lpszExtension
, lpszExt
);
3014 /*************************************************************************
3015 * PathSearchAndQualifyA [SHLWAPI.@]
3017 * Determine if a given path is correct and fully qualified.
3020 * lpszPath [I] Path to check
3021 * lpszBuf [O] Output for correct path
3022 * cchBuf [I] Size of lpszBuf
3027 BOOL WINAPI
PathSearchAndQualifyA(LPCSTR lpszPath
, LPSTR lpszBuf
, UINT cchBuf
)
3029 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_a(lpszPath
), lpszBuf
, cchBuf
);
3033 /*************************************************************************
3034 * PathSearchAndQualifyW [SHLWAPI.@]
3036 * See PathSearchAndQualifyA
3038 BOOL WINAPI
PathSearchAndQualifyW(LPCWSTR lpszPath
, LPWSTR lpszBuf
, UINT cchBuf
)
3040 FIXME("(%s,%p,0x%08x)-stub\n", debugstr_w(lpszPath
), lpszBuf
, cchBuf
);
3044 /*************************************************************************
3045 * PathSkipRootA [SHLWAPI.@]
3047 * Return the portion of a path following the drive letter or mount point.
3050 * lpszPath [I] The path to skip on
3053 * Success: A pointer to the next character after the root.
3054 * Failure: NULL, if lpszPath is invalid, has no root or is a multibyte string.
3056 LPSTR WINAPI
PathSkipRootA(LPCSTR lpszPath
)
3058 TRACE("(%s)\n", debugstr_a(lpszPath
));
3060 if (!lpszPath
|| !*lpszPath
)
3063 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3065 /* Network share: skip share server and mount point */
3067 if ((lpszPath
= StrChrA(lpszPath
, '\\')) &&
3068 (lpszPath
= StrChrA(lpszPath
+ 1, '\\')))
3070 return (LPSTR
)lpszPath
;
3073 if (IsDBCSLeadByte(*lpszPath
))
3077 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3078 return (LPSTR
)lpszPath
+ 3;
3082 /*************************************************************************
3083 * PathSkipRootW [SHLWAPI.@]
3085 * See PathSkipRootA.
3087 LPWSTR WINAPI
PathSkipRootW(LPCWSTR lpszPath
)
3089 TRACE("(%s)\n", debugstr_w(lpszPath
));
3091 if (!lpszPath
|| !*lpszPath
)
3094 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3096 /* Network share: skip share server and mount point */
3098 if ((lpszPath
= StrChrW(lpszPath
, '\\')) &&
3099 (lpszPath
= StrChrW(lpszPath
+ 1, '\\')))
3101 return (LPWSTR
)lpszPath
;
3105 if (lpszPath
[0] && lpszPath
[1] == ':' && lpszPath
[2] == '\\')
3106 return (LPWSTR
)lpszPath
+ 3;
3110 /*************************************************************************
3111 * PathCreateFromUrlA [SHLWAPI.@]
3113 * Create a path from a URL
3116 * lpszUrl [I] URL to convert into a path
3117 * lpszPath [O] Output buffer for the resulting Path
3118 * pcchPath [I] Length of lpszPath
3119 * dwFlags [I] Flags controlling the conversion
3122 * Success: S_OK. lpszPath contains the URL in path format,
3123 * Failure: An HRESULT error code such as E_INVALIDARG.
3125 HRESULT WINAPI
PathCreateFromUrlA(LPCSTR lpszUrl
, LPSTR lpszPath
,
3126 LPDWORD pcchPath
, DWORD dwFlags
)
3129 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_a(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3131 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3132 return E_INVALIDARG
;
3134 pszPathPart
= StrChrA(lpszUrl
, ':');
3135 if ((((pszPathPart
- lpszUrl
) == 1) && isalpha(*lpszUrl
)) ||
3136 !lstrcmpA(lpszUrl
, "file:"))
3138 return UrlUnescapeA(pszPathPart
, lpszPath
, pcchPath
, dwFlags
);
3140 /* extracts thing prior to : in pszURL and checks against:
3144 * about - if match returns E_INVALIDARG
3147 return E_INVALIDARG
;
3150 /*************************************************************************
3151 * PathCreateFromUrlW [SHLWAPI.@]
3153 * See PathCreateFromUrlA.
3155 HRESULT WINAPI
PathCreateFromUrlW(LPCWSTR lpszUrl
, LPWSTR lpszPath
,
3156 LPDWORD pcchPath
, DWORD dwFlags
)
3158 static const WCHAR stemp
[] = { 'f','i','l','e',':','/','/',0 };
3159 LPWSTR pwszPathPart
;
3162 TRACE("(%s,%p,%p,0x%08lx)\n", debugstr_w(lpszUrl
), lpszPath
, pcchPath
, dwFlags
);
3164 if (!lpszUrl
|| !lpszPath
|| !pcchPath
|| !*pcchPath
)
3165 return E_INVALIDARG
;
3167 /* Path of the form file://... */
3168 if (!strncmpW(lpszUrl
, stemp
, 7))
3172 /* Path of the form file:... */
3173 else if (!strncmpW(lpszUrl
, stemp
, 5))
3178 /* Ensure that path is of the form c:... or c|... */
3179 if (lpszUrl
[1] != ':' && lpszUrl
[1] != '|' && isalphaW(*lpszUrl
))
3180 return E_INVALIDARG
;
3182 hr
= UrlUnescapeW(lpszUrl
, lpszPath
, pcchPath
, dwFlags
);
3183 if (lpszPath
[1] == '|')
3186 for (pwszPathPart
= lpszPath
; *pwszPathPart
; pwszPathPart
++)
3187 if (*pwszPathPart
== '/')
3188 *pwszPathPart
= '\\';
3190 TRACE("Returning %s\n",debugstr_w(lpszPath
));
3195 /*************************************************************************
3196 * PathRelativePathToA [SHLWAPI.@]
3198 * Create a relative path from one path to another.
3201 * lpszPath [O] Destination for relative path
3202 * lpszFrom [I] Source path
3203 * dwAttrFrom [I] File attribute of source path
3204 * lpszTo [I] Destination path
3205 * dwAttrTo [I] File attributes of destination path
3208 * TRUE If a relative path can be formed. lpszPath contains the new path
3209 * FALSE If the paths are not relavtive or any parameters are invalid
3212 * lpszTo should be at least MAX_PATH in length.
3214 * Calling this function with relative paths for lpszFrom or lpszTo may
3215 * give erroneous results.
3217 * The Win32 version of this function contains a bug where the lpszTo string
3218 * may be referenced 1 byte beyond the end of the string. As a result random
3219 * garbage may be written to the output path, depending on what lies beyond
3220 * the last byte of the string. This bug occurs because of the behaviour of
3221 * PathCommonPrefix() (see notes for that function), and no workaround seems
3222 * possible with Win32.
3224 * This bug has been fixed here, so for example the relative path from "\\"
3225 * to "\\" is correctly determined as "." in this implementation.
3227 BOOL WINAPI
PathRelativePathToA(LPSTR lpszPath
, LPCSTR lpszFrom
, DWORD dwAttrFrom
,
3228 LPCSTR lpszTo
, DWORD dwAttrTo
)
3232 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_a(lpszFrom
),
3233 dwAttrFrom
, debugstr_a(lpszTo
), dwAttrTo
);
3235 if(lpszPath
&& lpszFrom
&& lpszTo
)
3237 WCHAR szPath
[MAX_PATH
];
3238 WCHAR szFrom
[MAX_PATH
];
3239 WCHAR szTo
[MAX_PATH
];
3240 MultiByteToWideChar(0,0,lpszFrom
,-1,szFrom
,MAX_PATH
);
3241 MultiByteToWideChar(0,0,lpszTo
,-1,szTo
,MAX_PATH
);
3242 bRet
= PathRelativePathToW(szPath
,szFrom
,dwAttrFrom
,szTo
,dwAttrTo
);
3243 WideCharToMultiByte(0,0,szPath
,-1,lpszPath
,MAX_PATH
,0,0);
3248 /*************************************************************************
3249 * PathRelativePathToW [SHLWAPI.@]
3251 * See PathRelativePathToA.
3253 BOOL WINAPI
PathRelativePathToW(LPWSTR lpszPath
, LPCWSTR lpszFrom
, DWORD dwAttrFrom
,
3254 LPCWSTR lpszTo
, DWORD dwAttrTo
)
3256 static const WCHAR szPrevDirSlash
[] = { '.', '.', '\\', '\0' };
3257 static const WCHAR szPrevDir
[] = { '.', '.', '\0' };
3258 WCHAR szFrom
[MAX_PATH
];
3259 WCHAR szTo
[MAX_PATH
];
3262 TRACE("(%p,%s,0x%08lx,%s,0x%08lx)\n", lpszPath
, debugstr_w(lpszFrom
),
3263 dwAttrFrom
, debugstr_w(lpszTo
), dwAttrTo
);
3265 if(!lpszPath
|| !lpszFrom
|| !lpszTo
)
3269 strncpyW(szFrom
, lpszFrom
, MAX_PATH
);
3270 strncpyW(szTo
, lpszTo
, MAX_PATH
);
3272 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3273 PathRemoveFileSpecW(szFrom
);
3274 if(!(dwAttrFrom
& FILE_ATTRIBUTE_DIRECTORY
))
3275 PathRemoveFileSpecW(szTo
);
3277 /* Paths can only be relative if they have a common root */
3278 if(!(dwLen
= PathCommonPrefixW(szFrom
, szTo
, 0)))
3281 /* Strip off lpszFrom components to the root, by adding "..\" */
3282 lpszFrom
= szFrom
+ dwLen
;
3288 if (*lpszFrom
== '\\')
3293 lpszFrom
= PathFindNextComponentW(lpszFrom
);
3294 strcatW(lpszPath
, *lpszFrom
? szPrevDirSlash
: szPrevDir
);
3297 /* From the root add the components of lpszTo */
3299 /* We check lpszTo[-1] to avoid skipping end of string. See the notes for
3302 if (*lpszTo
&& lpszTo
[-1])
3304 if (*lpszTo
!= '\\')
3306 dwLen
= strlenW(lpszPath
);
3307 if (dwLen
+ strlenW(lpszTo
) >= MAX_PATH
)
3312 strcpyW(lpszPath
+ dwLen
, lpszTo
);
3317 /*************************************************************************
3318 * PathUnmakeSystemFolderA [SHLWAPI.@]
3320 * Remove the system folder attributes from a path.
3323 * lpszPath [I] The path to remove attributes from
3327 * Failure: FALSE, if lpszPath is NULL, empty, not a directory, or calling
3328 * SetFileAttributesA() fails.
3330 BOOL WINAPI
PathUnmakeSystemFolderA(LPCSTR lpszPath
)
3334 TRACE("(%s)\n", debugstr_a(lpszPath
));
3336 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesA(lpszPath
)) == -1u ||
3337 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3340 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3341 return SetFileAttributesA(lpszPath
, dwAttr
);
3344 /*************************************************************************
3345 * PathUnmakeSystemFolderW [SHLWAPI.@]
3347 * See PathUnmakeSystemFolderA.
3349 BOOL WINAPI
PathUnmakeSystemFolderW(LPCWSTR lpszPath
)
3353 TRACE("(%s)\n", debugstr_w(lpszPath
));
3355 if (!lpszPath
|| !*lpszPath
|| (dwAttr
= GetFileAttributesW(lpszPath
)) == -1u ||
3356 !(dwAttr
& FILE_ATTRIBUTE_DIRECTORY
))
3359 dwAttr
&= ~(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
3360 return SetFileAttributesW(lpszPath
, dwAttr
);
3364 /*************************************************************************
3365 * PathSetDlgItemPathA [SHLWAPI.@]
3367 * Set the text of a dialog item to a path, shrinking the path to fit
3368 * if it is too big for the item.
3371 * hDlg [I] Dialog handle
3372 * id [I] ID of item in the dialog
3373 * lpszPath [I] Path to set as the items text
3379 * If lpszPath is NULL, a blank string ("") is set (i.e. The previous
3380 * window text is erased).
3382 VOID WINAPI
PathSetDlgItemPathA(HWND hDlg
, int id
, LPCSTR lpszPath
)
3384 WCHAR szPath
[MAX_PATH
];
3386 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_a(lpszPath
));
3389 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3392 PathSetDlgItemPathW(hDlg
, id
, szPath
);
3395 /*************************************************************************
3396 * PathSetDlgItemPathW [SHLWAPI.@]
3398 * See PathSetDlgItemPathA.
3400 VOID WINAPI
PathSetDlgItemPathW(HWND hDlg
, int id
, LPCWSTR lpszPath
)
3402 WCHAR path
[MAX_PATH
+ 1];
3408 TRACE("(%p,%8x,%s)\n",hDlg
, id
, debugstr_w(lpszPath
));
3410 if (!(hwItem
= GetDlgItem(hDlg
, id
)))
3414 strncpyW(path
, lpszPath
, sizeof(path
));
3418 GetClientRect(hwItem
, &rect
);
3420 hPrevObj
= SelectObject(hdc
, (HGDIOBJ
)SendMessageW(hwItem
,WM_GETFONT
,0,0));
3424 PathCompactPathW(hdc
, path
, rect
.right
);
3425 SelectObject(hdc
, hPrevObj
);
3428 ReleaseDC(hDlg
, hdc
);
3429 SetWindowTextW(hwItem
, path
);
3432 /*************************************************************************
3433 * PathIsNetworkPathA [SHLWAPI.@]
3435 * Determine if the given path is a network path.
3438 * lpszPath [I] Path to check
3441 * TRUE If lpszPath is a UNC share or mapped network drive, or
3442 * FALSE If lpszPath is a local drive or cannot be determined
3444 BOOL WINAPI
PathIsNetworkPathA(LPCSTR lpszPath
)
3448 TRACE("(%s)\n",debugstr_a(lpszPath
));
3452 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3454 dwDriveNum
= PathGetDriveNumberA(lpszPath
);
3455 if (dwDriveNum
== -1u)
3457 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3458 return pIsNetDrive(dwDriveNum
);
3461 /*************************************************************************
3462 * PathIsNetworkPathW [SHLWAPI.@]
3464 * See PathIsNetworkPathA.
3466 BOOL WINAPI
PathIsNetworkPathW(LPCWSTR lpszPath
)
3470 TRACE("(%s)\n", debugstr_w(lpszPath
));
3474 if (*lpszPath
== '\\' && lpszPath
[1] == '\\')
3476 dwDriveNum
= PathGetDriveNumberW(lpszPath
);
3477 if (dwDriveNum
== -1u)
3479 GET_FUNC(pIsNetDrive
, shell32
, (LPCSTR
)66, FALSE
); /* ord 66 = shell32.IsNetDrive */
3480 return pIsNetDrive(dwDriveNum
);
3483 /*************************************************************************
3484 * PathIsLFNFileSpecA [SHLWAPI.@]
3486 * Determine if the given path is a long file name
3489 * lpszPath [I] Path to check
3492 * TRUE If path is a long file name,
3493 * FALSE If path is a valid DOS 8.3 file name
3495 BOOL WINAPI
PathIsLFNFileSpecA(LPCSTR lpszPath
)
3497 DWORD dwNameLen
= 0, dwExtLen
= 0;
3499 TRACE("(%s)\n",debugstr_a(lpszPath
));
3506 if (*lpszPath
== ' ')
3507 return TRUE
; /* DOS names cannot have spaces */
3508 if (*lpszPath
== '.')
3511 return TRUE
; /* DOS names have only one dot */
3518 return TRUE
; /* DOS extensions are <= 3 chars*/
3524 return TRUE
; /* DOS names are <= 8 chars */
3526 lpszPath
+= IsDBCSLeadByte(*lpszPath
) ? 2 : 1;
3528 return FALSE
; /* Valid DOS path */
3531 /*************************************************************************
3532 * PathIsLFNFileSpecW [SHLWAPI.@]
3534 * See PathIsLFNFileSpecA.
3536 BOOL WINAPI
PathIsLFNFileSpecW(LPCWSTR lpszPath
)
3538 DWORD dwNameLen
= 0, dwExtLen
= 0;
3540 TRACE("(%s)\n",debugstr_w(lpszPath
));
3547 if (*lpszPath
== ' ')
3548 return TRUE
; /* DOS names cannot have spaces */
3549 if (*lpszPath
== '.')
3552 return TRUE
; /* DOS names have only one dot */
3559 return TRUE
; /* DOS extensions are <= 3 chars*/
3565 return TRUE
; /* DOS names are <= 8 chars */
3569 return FALSE
; /* Valid DOS path */
3572 /*************************************************************************
3573 * PathIsDirectoryEmptyA [SHLWAPI.@]
3575 * Determine if a given directory is empty.
3578 * lpszPath [I] Directory to check
3581 * TRUE If the directory exists and contains no files,
3584 BOOL WINAPI
PathIsDirectoryEmptyA(LPCSTR lpszPath
)
3588 TRACE("(%s)\n",debugstr_a(lpszPath
));
3592 WCHAR szPath
[MAX_PATH
];
3593 MultiByteToWideChar(0,0,lpszPath
,-1,szPath
,MAX_PATH
);
3594 bRet
= PathIsDirectoryEmptyW(szPath
);
3599 /*************************************************************************
3600 * PathIsDirectoryEmptyW [SHLWAPI.@]
3602 * See PathIsDirectoryEmptyA.
3604 BOOL WINAPI
PathIsDirectoryEmptyW(LPCWSTR lpszPath
)
3606 static const WCHAR szAllFiles
[] = { '*', '.', '*', '\0' };
3607 WCHAR szSearch
[MAX_PATH
];
3610 BOOL retVal
= FALSE
;
3611 WIN32_FIND_DATAW find_data
;
3613 TRACE("(%s)\n",debugstr_w(lpszPath
));
3615 if (!lpszPath
|| !PathIsDirectoryW(lpszPath
))
3618 strncpyW(szSearch
, lpszPath
, MAX_PATH
);
3619 PathAddBackslashW(szSearch
);
3620 dwLen
= strlenW(szSearch
);
3621 if (dwLen
> MAX_PATH
- 4)
3624 strcpyW(szSearch
+ dwLen
, szAllFiles
);
3625 hfind
= FindFirstFileW(szSearch
, &find_data
);
3627 if (hfind
!= INVALID_HANDLE_VALUE
&&
3628 find_data
.cFileName
[0] == '.' &&
3629 find_data
.cFileName
[1] == '.')
3631 /* The only directory entry should be the parent */
3632 if (!FindNextFileW(hfind
, &find_data
))
3640 /*************************************************************************
3641 * PathFindSuffixArrayA [SHLWAPI.@]
3643 * Find a suffix string in an array of suffix strings
3646 * lpszSuffix [I] Suffix string to search for
3647 * lppszArray [I] Array of suffix strings to search
3648 * dwCount [I] Number of elements in lppszArray
3651 * Success: The index of the position of lpszSuffix in lppszArray
3652 * Failure: 0, if any parameters are invalid or lpszSuffix is not found
3655 * The search is case sensitive.
3656 * The match is made against the end of the suffix string, so for example:
3657 * lpszSuffix="fooBAR" matches "BAR", but lpszSuffix="fooBARfoo" does not.
3659 int WINAPI
PathFindSuffixArrayA(LPCSTR lpszSuffix
, LPCSTR
*lppszArray
, int dwCount
)
3664 TRACE("(%s,%p,%d)\n",debugstr_a(lpszSuffix
), lppszArray
, dwCount
);
3666 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3668 dwLen
= strlen(lpszSuffix
);
3670 while (dwRet
< dwCount
)
3672 DWORD dwCompareLen
= strlen(*lppszArray
);
3673 if (dwCompareLen
< dwLen
)
3675 if (!strcmp(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3676 return dwRet
; /* Found */
3685 /*************************************************************************
3686 * PathFindSuffixArrayW [SHLWAPI.@]
3688 * See PathFindSuffixArrayA.
3690 int WINAPI
PathFindSuffixArrayW(LPCWSTR lpszSuffix
, LPCWSTR
*lppszArray
, int dwCount
)
3695 TRACE("(%s,%p,%d)\n",debugstr_w(lpszSuffix
), lppszArray
, dwCount
);
3697 if (lpszSuffix
&& lppszArray
&& dwCount
> 0)
3699 dwLen
= strlenW(lpszSuffix
);
3701 while (dwRet
< dwCount
)
3703 DWORD dwCompareLen
= strlenW(*lppszArray
);
3704 if (dwCompareLen
< dwLen
)
3706 if (!strcmpW(lpszSuffix
+ dwLen
- dwCompareLen
, *lppszArray
))
3707 return dwRet
; /* Found */
3716 /*************************************************************************
3717 * PathUndecorateA [SHLWAPI.@]
3719 * Undecorate a file path
3722 * lpszPath [O] Path to undecorate
3728 * A decorations form is "path[n].ext" where "n" is an optional decimal number.
3730 VOID WINAPI
PathUndecorateA(LPSTR lpszPath
)
3732 TRACE("(%s)\n",debugstr_a(lpszPath
));
3736 LPSTR lpszExt
= PathFindExtensionA(lpszPath
);
3737 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3739 LPSTR lpszSkip
= lpszExt
- 2;
3740 if (*lpszSkip
== '[')
3741 lpszSkip
++; /* [] (no number) */
3743 while (lpszSkip
> lpszPath
&& isdigit(lpszSkip
[-1]))
3745 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3747 /* remove the [n] */
3750 *lpszSkip
++ = *lpszExt
++;
3757 /*************************************************************************
3758 * PathUndecorateW [SHLWAPI.@]
3760 * See PathUndecorateA.
3762 VOID WINAPI
PathUndecorateW(LPWSTR lpszPath
)
3764 TRACE("(%s)\n",debugstr_w(lpszPath
));
3768 LPWSTR lpszExt
= PathFindExtensionW(lpszPath
);
3769 if (lpszExt
> lpszPath
&& lpszExt
[-1] == ']')
3771 LPWSTR lpszSkip
= lpszExt
- 2;
3772 if (*lpszSkip
== '[')
3773 lpszSkip
++; /* [] (no number) */
3775 while (lpszSkip
> lpszPath
&& isdigitW(lpszSkip
[-1]))
3777 if (lpszSkip
> lpszPath
&& lpszSkip
[-1] == '[' && lpszSkip
[-2] != '\\')
3779 /* remove the [n] */
3782 *lpszSkip
++ = *lpszExt
++;