4 * Copyright 1998, 1999, 2000 Juergen Schmied
5 * Copyright 2004 Juan Lang
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 * Many of these functions are in SHLWAPI.DLL also
28 #include "wine/port.h"
33 #include "wine/debug.h"
43 #include "shell32_main.h"
44 #include "undocshell.h"
46 #include "wine/unicode.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
52 ########## Combining and Constructing paths ##########
55 /*************************************************************************
56 * PathAppend [SHELL32.36]
58 BOOL WINAPI
PathAppendAW(
62 if (SHELL_OsIsUnicode())
63 return PathAppendW(lpszPath1
, lpszPath2
);
64 return PathAppendA(lpszPath1
, lpszPath2
);
67 /*************************************************************************
68 * PathCombine [SHELL32.37]
70 LPVOID WINAPI
PathCombineAW(
75 if (SHELL_OsIsUnicode())
76 return PathCombineW( szDest
, lpszDir
, lpszFile
);
77 return PathCombineA( szDest
, lpszDir
, lpszFile
);
80 /*************************************************************************
81 * PathAddBackslash [SHELL32.32]
83 LPVOID WINAPI
PathAddBackslashAW(LPVOID lpszPath
)
85 if(SHELL_OsIsUnicode())
86 return PathAddBackslashW(lpszPath
);
87 return PathAddBackslashA(lpszPath
);
90 /*************************************************************************
91 * PathBuildRoot [SHELL32.30]
93 LPVOID WINAPI
PathBuildRootAW(LPVOID lpszPath
, int drive
)
95 if(SHELL_OsIsUnicode())
96 return PathBuildRootW(lpszPath
, drive
);
97 return PathBuildRootA(lpszPath
, drive
);
101 Extracting Component Parts
104 /*************************************************************************
105 * PathFindFileName [SHELL32.34]
107 LPVOID WINAPI
PathFindFileNameAW(LPCVOID lpszPath
)
109 if(SHELL_OsIsUnicode())
110 return PathFindFileNameW(lpszPath
);
111 return PathFindFileNameA(lpszPath
);
114 /*************************************************************************
115 * PathFindExtension [SHELL32.31]
117 LPVOID WINAPI
PathFindExtensionAW(LPCVOID lpszPath
)
119 if (SHELL_OsIsUnicode())
120 return PathFindExtensionW(lpszPath
);
121 return PathFindExtensionA(lpszPath
);
125 /*************************************************************************
126 * PathGetExtensionA [internal]
129 * exported by ordinal
130 * return value points to the first char after the dot
132 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
134 TRACE("(%s)\n",lpszPath
);
136 lpszPath
= PathFindExtensionA(lpszPath
);
137 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
140 /*************************************************************************
141 * PathGetExtensionW [internal]
143 static LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
145 TRACE("(%s)\n",debugstr_w(lpszPath
));
147 lpszPath
= PathFindExtensionW(lpszPath
);
148 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
151 /*************************************************************************
152 * PathGetExtension [SHELL32.158]
154 LPVOID WINAPI
PathGetExtensionAW(LPCVOID lpszPath
,DWORD void1
, DWORD void2
)
156 if (SHELL_OsIsUnicode())
157 return PathGetExtensionW(lpszPath
);
158 return PathGetExtensionA(lpszPath
);
161 /*************************************************************************
162 * PathGetArgs [SHELL32.52]
164 LPVOID WINAPI
PathGetArgsAW(LPVOID lpszPath
)
166 if (SHELL_OsIsUnicode())
167 return PathGetArgsW(lpszPath
);
168 return PathGetArgsA(lpszPath
);
171 /*************************************************************************
172 * PathGetDriveNumber [SHELL32.57]
174 int WINAPI
PathGetDriveNumberAW(LPVOID lpszPath
)
176 if (SHELL_OsIsUnicode())
177 return PathGetDriveNumberW(lpszPath
);
178 return PathGetDriveNumberA(lpszPath
);
181 /*************************************************************************
182 * PathRemoveFileSpec [SHELL32.35]
184 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
186 if (SHELL_OsIsUnicode())
187 return PathRemoveFileSpecW(lpszPath
);
188 return PathRemoveFileSpecA(lpszPath
);
191 /*************************************************************************
192 * PathStripPath [SHELL32.38]
194 void WINAPI
PathStripPathAW(LPVOID lpszPath
)
196 if (SHELL_OsIsUnicode())
197 PathStripPathW(lpszPath
);
199 PathStripPathA(lpszPath
);
202 /*************************************************************************
203 * PathStripToRoot [SHELL32.50]
205 BOOL WINAPI
PathStripToRootAW(LPVOID lpszPath
)
207 if (SHELL_OsIsUnicode())
208 return PathStripToRootW(lpszPath
);
209 return PathStripToRootA(lpszPath
);
212 /*************************************************************************
213 * PathRemoveArgs [SHELL32.251]
215 void WINAPI
PathRemoveArgsAW(LPVOID lpszPath
)
217 if (SHELL_OsIsUnicode())
218 PathRemoveArgsW(lpszPath
);
220 PathRemoveArgsA(lpszPath
);
223 /*************************************************************************
224 * PathRemoveExtension [SHELL32.250]
226 void WINAPI
PathRemoveExtensionAW(LPVOID lpszPath
)
228 if (SHELL_OsIsUnicode())
229 PathRemoveExtensionW(lpszPath
);
231 PathRemoveExtensionA(lpszPath
);
239 /*************************************************************************
240 * PathGetShortPathA [internal]
242 static void PathGetShortPathA(LPSTR pszPath
)
246 TRACE("%s\n", pszPath
);
248 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
250 lstrcpyA(pszPath
, path
);
254 /*************************************************************************
255 * PathGetShortPathW [internal]
257 static void PathGetShortPathW(LPWSTR pszPath
)
259 WCHAR path
[MAX_PATH
];
261 TRACE("%s\n", debugstr_w(pszPath
));
263 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
265 lstrcpyW(pszPath
, path
);
269 /*************************************************************************
270 * PathGetShortPath [SHELL32.92]
272 VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
274 if(SHELL_OsIsUnicode())
275 PathGetShortPathW(pszPath
);
276 PathGetShortPathA(pszPath
);
279 /*************************************************************************
280 * PathRemoveBlanks [SHELL32.33]
282 void WINAPI
PathRemoveBlanksAW(LPVOID str
)
284 if(SHELL_OsIsUnicode())
285 PathRemoveBlanksW(str
);
287 PathRemoveBlanksA(str
);
290 /*************************************************************************
291 * PathQuoteSpaces [SHELL32.55]
293 VOID WINAPI
PathQuoteSpacesAW (LPVOID lpszPath
)
295 if(SHELL_OsIsUnicode())
296 PathQuoteSpacesW(lpszPath
);
298 PathQuoteSpacesA(lpszPath
);
301 /*************************************************************************
302 * PathUnquoteSpaces [SHELL32.56]
304 VOID WINAPI
PathUnquoteSpacesAW(LPVOID str
)
306 if(SHELL_OsIsUnicode())
307 PathUnquoteSpacesW(str
);
309 PathUnquoteSpacesA(str
);
312 /*************************************************************************
313 * PathParseIconLocation [SHELL32.249]
315 int WINAPI
PathParseIconLocationAW (LPVOID lpszPath
)
317 if(SHELL_OsIsUnicode())
318 return PathParseIconLocationW(lpszPath
);
319 return PathParseIconLocationA(lpszPath
);
323 ########## Path Testing ##########
325 /*************************************************************************
326 * PathIsUNC [SHELL32.39]
328 BOOL WINAPI
PathIsUNCAW (LPCVOID lpszPath
)
330 if (SHELL_OsIsUnicode())
331 return PathIsUNCW( lpszPath
);
332 return PathIsUNCA( lpszPath
);
335 /*************************************************************************
336 * PathIsRelative [SHELL32.40]
338 BOOL WINAPI
PathIsRelativeAW (LPCVOID lpszPath
)
340 if (SHELL_OsIsUnicode())
341 return PathIsRelativeW( lpszPath
);
342 return PathIsRelativeA( lpszPath
);
345 /*************************************************************************
346 * PathIsRoot [SHELL32.29]
348 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
350 if (SHELL_OsIsUnicode())
351 return PathIsRootW(lpszPath
);
352 return PathIsRootA(lpszPath
);
355 /*************************************************************************
356 * PathIsExeA [internal]
358 static BOOL
PathIsExeA (LPCSTR lpszPath
)
360 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
362 static const char * const lpszExtensions
[] =
363 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
365 TRACE("path=%s\n",lpszPath
);
367 for(i
=0; lpszExtensions
[i
]; i
++)
368 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
373 /*************************************************************************
374 * PathIsExeW [internal]
376 static BOOL
PathIsExeW (LPCWSTR lpszPath
)
378 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
380 static const WCHAR lpszExtensions
[][4] =
381 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
382 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
383 {'s','c','r','\0'}, {'\0'} };
385 TRACE("path=%s\n",debugstr_w(lpszPath
));
387 for(i
=0; lpszExtensions
[i
][0]; i
++)
388 if (!strcmpiW(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
393 /*************************************************************************
394 * PathIsExe [SHELL32.43]
396 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
398 if (SHELL_OsIsUnicode())
399 return PathIsExeW (path
);
400 return PathIsExeA(path
);
403 /*************************************************************************
404 * PathIsDirectory [SHELL32.159]
406 BOOL WINAPI
PathIsDirectoryAW (LPCVOID lpszPath
)
408 if (SHELL_OsIsUnicode())
409 return PathIsDirectoryW (lpszPath
);
410 return PathIsDirectoryA (lpszPath
);
413 /*************************************************************************
414 * PathFileExists [SHELL32.45]
416 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
418 if (SHELL_OsIsUnicode())
419 return PathFileExistsW (lpszPath
);
420 return PathFileExistsA (lpszPath
);
423 /*************************************************************************
424 * PathMatchSpec [SHELL32.46]
426 BOOL WINAPI
PathMatchSpecAW(LPVOID name
, LPVOID mask
)
428 if (SHELL_OsIsUnicode())
429 return PathMatchSpecW( name
, mask
);
430 return PathMatchSpecA( name
, mask
);
433 /*************************************************************************
434 * PathIsSameRoot [SHELL32.650]
436 BOOL WINAPI
PathIsSameRootAW(LPCVOID lpszPath1
, LPCVOID lpszPath2
)
438 if (SHELL_OsIsUnicode())
439 return PathIsSameRootW(lpszPath1
, lpszPath2
);
440 return PathIsSameRootA(lpszPath1
, lpszPath2
);
443 /*************************************************************************
444 * IsLFNDriveA [SHELL32.41]
446 BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
450 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
455 /*************************************************************************
456 * IsLFNDriveW [SHELL32.42]
458 BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
462 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
467 /*************************************************************************
468 * IsLFNDrive [SHELL32.119]
470 BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
472 if (SHELL_OsIsUnicode())
473 return IsLFNDriveW(lpszPath
);
474 return IsLFNDriveA(lpszPath
);
478 ########## Creating Something Unique ##########
480 /*************************************************************************
481 * PathMakeUniqueNameA [internal]
483 BOOL WINAPI
PathMakeUniqueNameA(
486 LPCSTR lpszShortName
,
490 FIXME("%p %lu %s %s %s stub\n",
491 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
492 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
496 /*************************************************************************
497 * PathMakeUniqueNameW [internal]
499 BOOL WINAPI
PathMakeUniqueNameW(
502 LPCWSTR lpszShortName
,
503 LPCWSTR lpszLongName
,
504 LPCWSTR lpszPathName
)
506 FIXME("%p %lu %s %s %s stub\n",
507 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
508 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
512 /*************************************************************************
513 * PathMakeUniqueName [SHELL32.47]
515 BOOL WINAPI
PathMakeUniqueNameAW(
518 LPCVOID lpszShortName
,
519 LPCVOID lpszLongName
,
520 LPCVOID lpszPathName
)
522 if (SHELL_OsIsUnicode())
523 return PathMakeUniqueNameW(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
524 return PathMakeUniqueNameA(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
527 /*************************************************************************
528 * PathYetAnotherMakeUniqueName [SHELL32.75]
531 * exported by ordinal
533 BOOL WINAPI
PathYetAnotherMakeUniqueName(
535 LPCWSTR lpszPathName
,
536 LPCWSTR lpszShortName
,
537 LPCWSTR lpszLongName
)
539 FIXME("(%p, %s, %s ,%s):stub.\n",
540 lpszBuffer
, debugstr_w(lpszPathName
), debugstr_w(lpszShortName
), debugstr_w(lpszLongName
));
546 ########## cleaning and resolving paths ##########
549 /*************************************************************************
550 * PathFindOnPath [SHELL32.145]
552 BOOL WINAPI
PathFindOnPathAW(LPVOID sFile
, LPCVOID sOtherDirs
)
554 if (SHELL_OsIsUnicode())
555 return PathFindOnPathW(sFile
, (LPCWSTR
*)sOtherDirs
);
556 return PathFindOnPathA(sFile
, (LPCSTR
*)sOtherDirs
);
559 /*************************************************************************
560 * PathCleanupSpec [SHELL32.171]
562 * lpszFile is changed in place.
564 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
570 if (SHELL_OsIsUnicode())
572 LPWSTR p
= lpszFileW
;
574 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
577 length
= strlenW(lpszPathW
);
581 int gct
= PathGetCharTypeW(*p
);
582 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
585 rc
|= PCS_REPLACEDCHAR
;
591 if (length
+ i
== MAX_PATH
)
593 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
601 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
602 LPCSTR lpszPathA
= (LPSTR
)lpszPathW
;
605 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
608 length
= strlen(lpszPathA
);
612 int gct
= PathGetCharTypeA(*p
);
613 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
616 rc
|= PCS_REPLACEDCHAR
;
622 if (length
+ i
== MAX_PATH
)
624 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
633 /*************************************************************************
634 * PathQualifyA [SHELL32]
636 BOOL WINAPI
PathQualifyA(LPCSTR pszPath
)
638 FIXME("%s\n",pszPath
);
642 /*************************************************************************
643 * PathQualifyW [SHELL32]
645 BOOL WINAPI
PathQualifyW(LPCWSTR pszPath
)
647 FIXME("%s\n",debugstr_w(pszPath
));
651 /*************************************************************************
652 * PathQualify [SHELL32.49]
654 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
656 if (SHELL_OsIsUnicode())
657 return PathQualifyW(pszPath
);
658 return PathQualifyA(pszPath
);
661 /*************************************************************************
662 * PathResolveA [SHELL32.51]
664 BOOL WINAPI
PathResolveA(
669 FIXME("(%s,%p,0x%08lx),stub!\n",
670 lpszPath
, *alpszPaths
, dwFlags
);
674 /*************************************************************************
675 * PathResolveW [SHELL32]
677 BOOL WINAPI
PathResolveW(
682 FIXME("(%s,%p,0x%08lx),stub!\n",
683 debugstr_w(lpszPath
), debugstr_w(*alpszPaths
), dwFlags
);
687 /*************************************************************************
688 * PathResolve [SHELL32.51]
690 BOOL WINAPI
PathResolveAW(
695 if (SHELL_OsIsUnicode())
696 return PathResolveW(lpszPath
, (LPCWSTR
*)alpszPaths
, dwFlags
);
697 return PathResolveA(lpszPath
, (LPCSTR
*)alpszPaths
, dwFlags
);
700 /*************************************************************************
701 * PathProcessCommandA [SHELL32.653]
703 LONG WINAPI
PathProcessCommandA (
709 FIXME("%s %p 0x%04lx 0x%04lx stub\n",
710 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
711 if(!lpszPath
) return -1;
712 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
713 return strlen(lpszPath
);
716 /*************************************************************************
717 * PathProcessCommandW
719 LONG WINAPI
PathProcessCommandW (
725 FIXME("(%s, %p, 0x%04lx, 0x%04lx) stub\n",
726 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
727 if(!lpszPath
) return -1;
728 if(lpszBuff
) strcpyW(lpszBuff
, lpszPath
);
729 return strlenW(lpszPath
);
732 /*************************************************************************
733 * PathProcessCommand (SHELL32.653)
735 LONG WINAPI
PathProcessCommandAW (
741 if (SHELL_OsIsUnicode())
742 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
743 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
747 ########## special ##########
750 /*************************************************************************
751 * PathSetDlgItemPath (SHELL32.48)
753 VOID WINAPI
PathSetDlgItemPathAW(HWND hDlg
, int id
, LPCVOID pszPath
)
755 if (SHELL_OsIsUnicode())
756 PathSetDlgItemPathW(hDlg
, id
, pszPath
);
758 PathSetDlgItemPathA(hDlg
, id
, pszPath
);
761 static const WCHAR szCurrentVersion
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0'};
762 static const WCHAR Administrative_ToolsW
[] = {'A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
763 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
764 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
765 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
766 static const WCHAR Common_Administrative_ToolsW
[] = {'C','o','m','m','o','n',' ','A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
767 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
768 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
769 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
770 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
771 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
772 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
773 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
774 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
775 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
776 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
777 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
778 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
779 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
780 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
781 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
782 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
783 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
784 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
785 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
786 static const WCHAR My_VideoW
[] = {'M','y',' ','V','i','d','e','o','\0'};
787 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
788 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
789 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
790 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
791 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
792 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
793 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
794 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
795 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
796 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
797 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
798 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
799 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
800 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
801 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
802 static const WCHAR ProfileListW
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','P','r','o','f','i','l','e','L','i','s','t',0};
803 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
804 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
805 static const WCHAR szSHFolders
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
806 static const WCHAR szSHUserFolders
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','U','s','e','r',' ','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
807 /* This defaults to L"Documents and Settings" on Windows 2000/XP, but we're
808 * acting more Windows 9x-like for now.
810 static const WCHAR szDefaultProfileDirW
[] = {'p','r','o','f','i','l','e','s','\0'};
811 static const WCHAR AllUsersW
[] = {'A','l','l',' ','U','s','e','r','s','\0'};
813 typedef enum _CSIDL_Type
{
817 CSIDL_Type_Disallowed
,
818 CSIDL_Type_NonExistent
,
819 CSIDL_Type_WindowsPath
,
820 CSIDL_Type_SystemPath
,
827 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
830 static const CSIDL_DATA CSIDL_Data
[] =
832 { /* 0x00 - CSIDL_DESKTOP */
835 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
837 { /* 0x01 - CSIDL_INTERNET */
838 CSIDL_Type_Disallowed
,
842 { /* 0x02 - CSIDL_PROGRAMS */
845 MAKEINTRESOURCEW(IDS_PROGRAMS
)
847 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
848 CSIDL_Type_SystemPath
,
852 { /* 0x04 - CSIDL_PRINTERS */
853 CSIDL_Type_SystemPath
,
857 { /* 0x05 - CSIDL_PERSONAL */
860 MAKEINTRESOURCEW(IDS_PERSONAL
)
862 { /* 0x06 - CSIDL_FAVORITES */
865 MAKEINTRESOURCEW(IDS_FAVORITES
)
867 { /* 0x07 - CSIDL_STARTUP */
870 MAKEINTRESOURCEW(IDS_STARTUP
)
872 { /* 0x08 - CSIDL_RECENT */
875 MAKEINTRESOURCEW(IDS_RECENT
)
877 { /* 0x09 - CSIDL_SENDTO */
880 MAKEINTRESOURCEW(IDS_SENDTO
)
882 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
883 CSIDL_Type_Disallowed
,
887 { /* 0x0b - CSIDL_STARTMENU */
890 MAKEINTRESOURCEW(IDS_STARTMENU
)
892 { /* 0x0c - CSIDL_MYDOCUMENTS */
893 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
897 { /* 0x0d - CSIDL_MYMUSIC */
900 MAKEINTRESOURCEW(IDS_MYMUSIC
)
902 { /* 0x0e - CSIDL_MYVIDEO */
905 MAKEINTRESOURCEW(IDS_MYVIDEO
)
907 { /* 0x0f - unassigned */
908 CSIDL_Type_Disallowed
,
912 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
915 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
917 { /* 0x11 - CSIDL_DRIVES */
918 CSIDL_Type_Disallowed
,
922 { /* 0x12 - CSIDL_NETWORK */
923 CSIDL_Type_Disallowed
,
927 { /* 0x13 - CSIDL_NETHOOD */
930 MAKEINTRESOURCEW(IDS_NETHOOD
)
932 { /* 0x14 - CSIDL_FONTS */
933 CSIDL_Type_WindowsPath
,
937 { /* 0x15 - CSIDL_TEMPLATES */
940 MAKEINTRESOURCEW(IDS_TEMPLATES
)
942 { /* 0x16 - CSIDL_COMMON_STARTMENU */
945 MAKEINTRESOURCEW(IDS_STARTMENU
)
947 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
950 MAKEINTRESOURCEW(IDS_PROGRAMS
)
952 { /* 0x18 - CSIDL_COMMON_STARTUP */
955 MAKEINTRESOURCEW(IDS_STARTUP
)
957 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
960 MAKEINTRESOURCEW(IDS_DESKTOP
)
962 { /* 0x1a - CSIDL_APPDATA */
965 MAKEINTRESOURCEW(IDS_APPDATA
)
967 { /* 0x1b - CSIDL_PRINTHOOD */
970 MAKEINTRESOURCEW(IDS_PRINTHOOD
)
972 { /* 0x1c - CSIDL_LOCAL_APPDATA */
975 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA
)
977 { /* 0x1d - CSIDL_ALTSTARTUP */
978 CSIDL_Type_NonExistent
,
982 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
983 CSIDL_Type_NonExistent
,
987 { /* 0x1f - CSIDL_COMMON_FAVORITES */
990 MAKEINTRESOURCEW(IDS_FAVORITES
)
992 { /* 0x20 - CSIDL_INTERNET_CACHE */
995 MAKEINTRESOURCEW(IDS_INTERNET_CACHE
)
997 { /* 0x21 - CSIDL_COOKIES */
1000 MAKEINTRESOURCEW(IDS_COOKIES
)
1002 { /* 0x22 - CSIDL_HISTORY */
1005 MAKEINTRESOURCEW(IDS_HISTORY
)
1007 { /* 0x23 - CSIDL_COMMON_APPDATA */
1008 CSIDL_Type_AllUsers
,
1010 MAKEINTRESOURCEW(IDS_APPDATA
)
1012 { /* 0x24 - CSIDL_WINDOWS */
1013 CSIDL_Type_WindowsPath
,
1017 { /* 0x25 - CSIDL_SYSTEM */
1018 CSIDL_Type_SystemPath
,
1022 { /* 0x26 - CSIDL_PROGRAM_FILES */
1025 MAKEINTRESOURCEW(IDS_PROGRAM_FILES
)
1027 { /* 0x27 - CSIDL_MYPICTURES */
1030 MAKEINTRESOURCEW(IDS_MYPICTURES
)
1032 { /* 0x28 - CSIDL_PROFILE */
1037 { /* 0x29 - CSIDL_SYSTEMX86 */
1038 CSIDL_Type_NonExistent
,
1042 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1043 CSIDL_Type_NonExistent
,
1047 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1050 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON
)
1052 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1053 CSIDL_Type_NonExistent
,
1057 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1058 CSIDL_Type_AllUsers
,
1060 MAKEINTRESOURCEW(IDS_TEMPLATES
)
1062 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1063 CSIDL_Type_AllUsers
,
1065 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS
)
1067 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1068 CSIDL_Type_AllUsers
,
1069 Common_Administrative_ToolsW
,
1070 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
1072 { /* 0x30 - CSIDL_ADMINTOOLS */
1074 Administrative_ToolsW
,
1075 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
1077 { /* 0x31 - CSIDL_CONNECTIONS */
1078 CSIDL_Type_Disallowed
,
1082 { /* 0x32 - unassigned */
1083 CSIDL_Type_Disallowed
,
1087 { /* 0x33 - unassigned */
1088 CSIDL_Type_Disallowed
,
1092 { /* 0x34 - unassigned */
1093 CSIDL_Type_Disallowed
,
1097 { /* 0x35 - CSIDL_COMMON_MUSIC */
1098 CSIDL_Type_AllUsers
,
1100 MAKEINTRESOURCEW(IDS_COMMON_MUSIC
)
1102 { /* 0x36 - CSIDL_COMMON_PICTURES */
1103 CSIDL_Type_AllUsers
,
1105 MAKEINTRESOURCEW(IDS_COMMON_PICTURES
)
1107 { /* 0x37 - CSIDL_COMMON_VIDEO */
1108 CSIDL_Type_AllUsers
,
1110 MAKEINTRESOURCEW(IDS_COMMON_VIDEO
)
1112 { /* 0x38 - CSIDL_RESOURCES */
1113 CSIDL_Type_WindowsPath
,
1117 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1118 CSIDL_Type_NonExistent
,
1122 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1123 CSIDL_Type_NonExistent
,
1127 { /* 0x3b - CSIDL_CDBURN_AREA */
1130 MAKEINTRESOURCEW(IDS_CDBURN_AREA
)
1132 { /* 0x3c unassigned */
1133 CSIDL_Type_Disallowed
,
1137 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1138 CSIDL_Type_Disallowed
, /* FIXME */
1142 { /* 0x3e - CSIDL_PROFILES */
1143 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1149 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1151 /* Gets the value named value from the registry key
1152 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1153 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1154 * is assumed to be MAX_PATH WCHARs in length.
1155 * If it exists, expands the value and writes the expanded value to
1156 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1157 * Returns successful error code if the value was retrieved from the registry,
1158 * and a failure otherwise.
1160 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1161 LPCWSTR value
, LPWSTR path
)
1164 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1165 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1166 DWORD dwDisp
, dwType
, dwPathLen
= MAX_PATH
;
1167 HKEY userShellFolderKey
, shellFolderKey
;
1169 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1174 strcpyW(shellFolderPath
, userPrefix
);
1175 PathAddBackslashW(shellFolderPath
);
1176 strcatW(shellFolderPath
, szSHFolders
);
1177 pShellFolderPath
= shellFolderPath
;
1178 strcpyW(userShellFolderPath
, userPrefix
);
1179 PathAddBackslashW(userShellFolderPath
);
1180 strcatW(userShellFolderPath
, szSHUserFolders
);
1181 pUserShellFolderPath
= userShellFolderPath
;
1185 pUserShellFolderPath
= szSHUserFolders
;
1186 pShellFolderPath
= szSHFolders
;
1189 if (RegCreateKeyExW(rootKey
, pShellFolderPath
, 0, NULL
, 0, KEY_ALL_ACCESS
,
1190 NULL
, &shellFolderKey
, &dwDisp
))
1192 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1195 if (RegCreateKeyExW(rootKey
, pUserShellFolderPath
, 0, NULL
, 0,
1196 KEY_ALL_ACCESS
, NULL
, &userShellFolderKey
, &dwDisp
))
1198 TRACE("Failed to create %s\n",
1199 debugstr_w(pUserShellFolderPath
));
1200 RegCloseKey(shellFolderKey
);
1204 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1205 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1209 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1210 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1212 WCHAR szTemp
[MAX_PATH
];
1214 _SHExpandEnvironmentStrings(path
, szTemp
);
1215 lstrcpynW(path
, szTemp
, MAX_PATH
);
1217 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1218 (strlenW(path
) + 1) * sizeof(WCHAR
));
1219 if (ret
!= ERROR_SUCCESS
)
1220 hr
= HRESULT_FROM_WIN32(ret
);
1226 RegCloseKey(shellFolderKey
);
1227 RegCloseKey(userShellFolderKey
);
1228 TRACE("returning 0x%08lx\n", hr
);
1232 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1233 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1234 * - The entry's szDefaultPath may be either a string value or an integer
1235 * resource identifier. In the latter case, the string value of the resource
1237 * - Depending on the entry's type, the path may begin with an (unexpanded)
1238 * environment variable name. The caller is responsible for expanding
1239 * environment strings if so desired.
1240 * The types that are prepended with environment variables are:
1241 * CSIDL_Type_User: %USERPROFILE%
1242 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1243 * CSIDL_Type_CurrVer: %SystemDrive%
1244 * (Others might make sense too, but as yet are unneeded.)
1246 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1249 WCHAR resourcePath
[MAX_PATH
];
1250 LPCWSTR pDefaultPath
= NULL
;
1252 TRACE("0x%02x,%p\n", folder
, pszPath
);
1254 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1255 return E_INVALIDARG
;
1257 return E_INVALIDARG
;
1259 /* Try special cases first */
1263 case CSIDL_PERSONAL
:
1265 case CSIDL_MYPICTURES
:
1268 const char *home
= getenv("HOME");
1270 /* special case for "My Documents", map to $HOME */
1273 WCHAR homeW
[MAX_PATH
];
1275 MultiByteToWideChar(CP_ACP
, 0, home
, -1, homeW
, MAX_PATH
);
1276 if (GetFullPathNameW(homeW
, MAX_PATH
, pszPath
, NULL
) != 0 &&
1277 PathIsDirectoryW(pszPath
))
1283 case CSIDL_DESKTOPDIRECTORY
:
1285 const char *home
= getenv("HOME");
1287 /* special case for Desktop, map to $HOME/Desktop if it exists */
1290 WCHAR desktopW
[MAX_PATH
];
1292 MultiByteToWideChar(CP_ACP
, 0, home
, -1, desktopW
, MAX_PATH
);
1293 PathAppendW(desktopW
, DesktopW
);
1294 if (GetFullPathNameW(desktopW
, MAX_PATH
, pszPath
, NULL
) != 0 &&
1295 PathIsDirectoryW(pszPath
))
1304 /* Either the folder was unhandled, or a suitable default wasn't found,
1305 * so use one of the resource-based defaults
1307 if (CSIDL_Data
[folder
].szDefaultPath
&&
1308 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1310 if (LoadStringW(shell32_hInstance
,
1311 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1314 pDefaultPath
= resourcePath
;
1318 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1319 debugstr_w(pszPath
));
1326 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1330 switch (CSIDL_Data
[folder
].type
)
1332 case CSIDL_Type_User
:
1333 strcpyW(pszPath
, UserProfileW
);
1335 case CSIDL_Type_AllUsers
:
1336 strcpyW(pszPath
, AllUsersProfileW
);
1338 case CSIDL_Type_CurrVer
:
1339 strcpyW(pszPath
, SystemDriveW
);
1342 ; /* no corresponding env. var, do nothing */
1346 PathAddBackslashW(pszPath
);
1347 strcatW(pszPath
, pDefaultPath
);
1350 TRACE("returning 0x%08lx\n", hr
);
1354 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1355 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1356 * can be overridden in the HKLM\\szCurrentVersion key.
1357 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1358 * the registry, uses _SHGetDefaultValue to get the value.
1360 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1365 TRACE("0x%08lx,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1367 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1368 return E_INVALIDARG
;
1369 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1370 return E_INVALIDARG
;
1372 return E_INVALIDARG
;
1374 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1375 hr
= _SHGetDefaultValue(folder
, pszPath
);
1381 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, 0,
1382 NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
))
1386 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1388 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1389 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1390 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1392 hr
= _SHGetDefaultValue(folder
, pszPath
);
1393 dwType
= REG_EXPAND_SZ
;
1394 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1395 (LPBYTE
)pszPath
, (strlenW(pszPath
)+1)*sizeof(WCHAR
));
1399 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1405 TRACE("returning 0x%08lx (output path is %s)\n", hr
, debugstr_w(pszPath
));
1409 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1410 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1411 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1412 * - if hToken is -1, looks in HKEY_USERS\.Default
1413 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1414 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1415 * calls _SHGetDefaultValue for it.
1417 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1422 TRACE("%p,0x%08lx,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1424 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1425 return E_INVALIDARG
;
1426 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1427 return E_INVALIDARG
;
1429 return E_INVALIDARG
;
1431 /* Only the current user and the default user are supported right now
1433 * FIXME: should be able to call GetTokenInformation on the token,
1434 * then call ConvertSidToStringSidW on it to get the user prefix.
1435 * But Wine's registry doesn't store user info by sid, it stores it
1436 * by user name (and I don't know how to convert from a token to a
1439 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
1441 FIXME("unsupported for user other than current or default\n");
1445 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1446 hr
= _SHGetDefaultValue(folder
, pszPath
);
1449 LPCWSTR userPrefix
= NULL
;
1452 if (hToken
== (HANDLE
)-1)
1454 hRootKey
= HKEY_USERS
;
1455 userPrefix
= DefaultW
;
1457 else /* hToken == NULL, other values disallowed above */
1458 hRootKey
= HKEY_CURRENT_USER
;
1459 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
,
1460 CSIDL_Data
[folder
].szValueName
, pszPath
);
1461 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1462 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1463 CSIDL_Data
[folder
].szValueName
, pszPath
);
1465 hr
= _SHGetDefaultValue(folder
, pszPath
);
1467 TRACE("returning 0x%08lx (output path is %s)\n", hr
, debugstr_w(pszPath
));
1471 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1472 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1473 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1474 * If this fails, falls back to _SHGetDefaultValue.
1476 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1481 TRACE("0x%08lx,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1483 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1484 return E_INVALIDARG
;
1485 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1486 return E_INVALIDARG
;
1488 return E_INVALIDARG
;
1490 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1491 hr
= _SHGetDefaultValue(folder
, pszPath
);
1494 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1495 CSIDL_Data
[folder
].szValueName
, pszPath
);
1497 hr
= _SHGetDefaultValue(folder
, pszPath
);
1499 TRACE("returning 0x%08lx (output path is %s)\n", hr
, debugstr_w(pszPath
));
1503 /* From the original Wine source:
1505 * Attempts to expand environment variables from szSrc into szDest, which is
1506 * assumed to be MAX_PATH characters in length. Before referring to the
1507 * environment, handles a few variables directly, because the environment
1508 * variables may not be set when this is called (as during Wine's installation
1509 * when default values are being written to the registry).
1510 * The directly handled environment variables, and their source, are:
1511 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1512 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1514 * If one of the directly handled environment variables is expanded, only
1515 * expands a single variable, and only in the beginning of szSrc.
1517 * That's fine for Wine, but it breaks in ReactOS where we have profile paths
1518 * like "c:\documents and settings\Administrator.REACTOS". Anyway, we have the
1519 * environment variables handy so we'll just use them instead of hacking around
1521 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
1524 WCHAR szTemp
[MAX_PATH
];
1526 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
1528 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
1530 /* short-circuit if there's nothing to expand */
1531 if (szSrc
[0] != '%')
1533 strcpyW(szDest
, szSrc
);
1539 strcpyW(szTemp
, szSrc
);
1540 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
1542 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
1545 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
1547 hr
= HRESULT_FROM_WIN32(GetLastError());
1550 if (SUCCEEDED(hr
) && szDest
[0] == '%')
1551 strcpyW(szTemp
, szDest
);
1554 /* terminate loop */
1559 TRACE("returning 0x%08lx (input was %s, output is %s)\n", hr
,
1560 debugstr_w(szSrc
), debugstr_w(szDest
));
1564 /*************************************************************************
1565 * SHGetFolderPathW [SHELL32.@]
1567 * Convert nFolder to path.
1571 * Failure: standard HRESULT error codes.
1574 * Most values can be overridden in either
1575 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1576 * or in the same location in HKLM.
1577 * The registry usage is explained by the following tech note:
1578 * http://www.microsoft.com/windows2000/techinfo/reskit/en-us/default.asp?url=/windows2000/techinfo/reskit/en-us/regentry/36173.asp
1579 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1580 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1581 * changes made to it are made to the former key too. This synchronization is
1582 * done on-demand: not until someone requests the value of one of these paths
1583 * (by calling one of the SHGet functions) is the value synchronized.
1584 * Furthermore, as explained here:
1585 * http://www.microsoft.com/windows2000/techinfo/reskit/en-us/default.asp?url=/windows2000/techinfo/reskit/en-us/regentry/36276.asp
1586 * the HKCU paths take precedence over the HKLM paths.
1589 HRESULT WINAPI
SHGetFolderPathW(
1590 HWND hwndOwner
, /* [I] owner window */
1591 int nFolder
, /* [I] CSIDL identifying the folder */
1592 HANDLE hToken
, /* [I] access token */
1593 DWORD dwFlags
, /* [I] which path to return */
1594 LPWSTR pszPath
) /* [O] converted path */
1597 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
1598 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
1602 TRACE("%p,%p,nFolder=0x%04x\n", hwndOwner
,pszPath
,nFolder
);
1604 /* Windows always NULL-terminates the resulting path regardless of success
1605 * or failure, so do so first
1609 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1610 return E_INVALIDARG
;
1612 type
= CSIDL_Data
[folder
].type
;
1615 case CSIDL_Type_Disallowed
:
1618 case CSIDL_Type_NonExistent
:
1621 case CSIDL_Type_WindowsPath
:
1622 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
1623 if (CSIDL_Data
[folder
].szDefaultPath
&&
1624 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1625 *CSIDL_Data
[folder
].szDefaultPath
)
1627 PathAddBackslashW(szTemp
);
1628 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1632 case CSIDL_Type_SystemPath
:
1633 GetSystemDirectoryW(szTemp
, MAX_PATH
);
1634 if (CSIDL_Data
[folder
].szDefaultPath
&&
1635 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1636 *CSIDL_Data
[folder
].szDefaultPath
)
1638 PathAddBackslashW(szTemp
);
1639 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1643 case CSIDL_Type_CurrVer
:
1644 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
1646 case CSIDL_Type_User
:
1647 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
1649 case CSIDL_Type_AllUsers
:
1650 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
1653 FIXME("bogus type %d, please fix\n", type
);
1658 /* Expand environment strings if necessary */
1660 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
1662 strcpyW(szBuildPath
, szTemp
);
1663 /* Copy the path if it's available before we might return */
1664 if (SUCCEEDED(hr
) && pszPath
)
1665 strcpyW(pszPath
, szBuildPath
);
1667 if (FAILED(hr
)) goto end
;
1669 /* if we don't care about existing directories we are ready */
1670 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
1672 if (PathFileExistsW(szBuildPath
)) goto end
;
1674 /* not existing but we are not allowed to create it. The return value
1675 * is verified against shell32 version 6.0.
1677 if (!(nFolder
& CSIDL_FLAG_CREATE
))
1679 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1683 /* create directory/directories */
1684 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
1685 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
1687 ERR("Failed to create directory '%s'.\n", debugstr_w(szBuildPath
));
1692 TRACE("Created missing system directory '%s'\n", debugstr_w(szBuildPath
));
1694 TRACE("returning 0x%08lx (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
1698 /*************************************************************************
1699 * SHGetFolderPathA [SHELL32.@]
1701 * See SHGetFolderPathW.
1703 HRESULT WINAPI
SHGetFolderPathA(
1710 WCHAR szTemp
[MAX_PATH
];
1713 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
1717 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
1718 if (SUCCEEDED(hr
) && pszPath
)
1719 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
1725 /* For each folder in folders, if its value has not been set in the registry,
1726 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1727 * folder's type) to get the unexpanded value first.
1728 * Writes the unexpanded value to User Shell Folders, and queries it with
1729 * SHGetFolderPathW to force the creation of the directory if it doesn't
1730 * already exist. SHGetFolderPathW also returns the expanded value, which
1731 * this then writes to Shell Folders.
1733 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
1734 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
1738 WCHAR path
[MAX_PATH
];
1740 HKEY hUserKey
= NULL
, hKey
= NULL
;
1741 DWORD dwDisp
, dwType
, dwPathLen
;
1744 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
1745 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
1747 ret
= RegCreateKeyExW(hRootKey
, szUserShellFolderPath
, 0, NULL
, 0,
1748 KEY_ALL_ACCESS
, NULL
, &hUserKey
, &dwDisp
);
1750 hr
= HRESULT_FROM_WIN32(ret
);
1753 ret
= RegCreateKeyExW(hRootKey
, szShellFolderPath
, 0, NULL
, 0,
1754 KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
);
1756 hr
= HRESULT_FROM_WIN32(ret
);
1758 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
1760 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1761 if (RegQueryValueExW(hUserKey
, CSIDL_Data
[folders
[i
]].szValueName
, NULL
,
1762 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
1763 dwType
!= REG_EXPAND_SZ
))
1766 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
1767 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
1769 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
1770 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
1775 ret
= RegSetValueExW(hUserKey
,
1776 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_EXPAND_SZ
,
1777 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
1779 hr
= HRESULT_FROM_WIN32(ret
);
1782 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
1783 hToken
, SHGFP_TYPE_DEFAULT
, path
);
1784 ret
= RegSetValueExW(hKey
,
1785 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_SZ
,
1786 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
1788 hr
= HRESULT_FROM_WIN32(ret
);
1794 RegCloseKey(hUserKey
);
1798 TRACE("returning 0x%08lx\n", hr
);
1802 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
1804 static const UINT folders
[] = {
1815 CSIDL_DESKTOPDIRECTORY
,
1819 CSIDL_LOCAL_APPDATA
,
1820 CSIDL_INTERNET_CACHE
,
1825 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
1826 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
1831 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
1834 hToken
= (HANDLE
)-1;
1835 hRootKey
= HKEY_USERS
;
1836 strcpyW(userShellFolderPath
, DefaultW
);
1837 PathAddBackslashW(userShellFolderPath
);
1838 strcatW(userShellFolderPath
, szSHUserFolders
);
1839 pUserShellFolderPath
= userShellFolderPath
;
1840 strcpyW(shellFolderPath
, DefaultW
);
1841 PathAddBackslashW(shellFolderPath
);
1842 strcatW(shellFolderPath
, szSHFolders
);
1843 pShellFolderPath
= shellFolderPath
;
1848 hRootKey
= HKEY_CURRENT_USER
;
1849 pUserShellFolderPath
= szSHUserFolders
;
1850 pShellFolderPath
= szSHFolders
;
1853 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
1854 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1855 TRACE("returning 0x%08lx\n", hr
);
1859 static HRESULT
_SHRegisterCommonShellFolders(void)
1861 static const UINT folders
[] = {
1862 CSIDL_COMMON_STARTMENU
,
1863 CSIDL_COMMON_PROGRAMS
,
1864 CSIDL_COMMON_STARTUP
,
1865 CSIDL_COMMON_DESKTOPDIRECTORY
,
1866 CSIDL_COMMON_FAVORITES
,
1867 CSIDL_COMMON_APPDATA
,
1868 CSIDL_COMMON_TEMPLATES
,
1869 CSIDL_COMMON_DOCUMENTS
,
1874 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
1875 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1876 TRACE("returning 0x%08lx\n", hr
);
1880 /* Register the default values in the registry, as some apps seem to depend
1881 * on their presence. The set registered was taken from Windows XP.
1883 HRESULT
SHELL_RegisterShellFolders(void)
1885 HRESULT hr
= _SHRegisterUserShellFolders(TRUE
);
1888 hr
= _SHRegisterUserShellFolders(FALSE
);
1890 hr
= _SHRegisterCommonShellFolders();
1894 /*************************************************************************
1895 * SHGetSpecialFolderPathA [SHELL32.@]
1897 BOOL WINAPI
SHGetSpecialFolderPathA (
1903 return (SHGetFolderPathA(
1905 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
1908 szPath
)) == S_OK
? TRUE
: FALSE
;
1911 /*************************************************************************
1912 * SHGetSpecialFolderPathW
1914 BOOL WINAPI
SHGetSpecialFolderPathW (
1920 return (SHGetFolderPathW(
1922 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
1925 szPath
)) == S_OK
? TRUE
: FALSE
;
1928 /*************************************************************************
1929 * SHGetSpecialFolderPath (SHELL32.175)
1931 BOOL WINAPI
SHGetSpecialFolderPathAW (
1938 if (SHELL_OsIsUnicode())
1939 return SHGetSpecialFolderPathW (hwndOwner
, szPath
, nFolder
, bCreate
);
1940 return SHGetSpecialFolderPathA (hwndOwner
, szPath
, nFolder
, bCreate
);
1943 /*************************************************************************
1944 * SHGetFolderLocation [SHELL32.@]
1946 * Gets the folder locations from the registry and creates a pidl.
1950 * nFolder [I] CSIDL_xxxxx
1951 * hToken [I] token representing user, or NULL for current user, or -1 for
1953 * dwReserved [I] must be zero
1954 * ppidl [O] PIDL of a special folder
1958 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
1961 * Creates missing reg keys and directories.
1962 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
1963 * virtual folders that are handled here.
1965 HRESULT WINAPI
SHGetFolderLocation(
1970 LPITEMIDLIST
*ppidl
)
1972 HRESULT hr
= E_INVALIDARG
;
1974 TRACE("%p 0x%08x %p 0x%08lx %p\n",
1975 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
1978 return E_INVALIDARG
;
1980 return E_INVALIDARG
;
1982 /* The virtual folders' locations are not user-dependent */
1987 *ppidl
= _ILCreateDesktop();
1990 case CSIDL_INTERNET
:
1991 *ppidl
= _ILCreateIExplore();
1994 case CSIDL_CONTROLS
:
1995 *ppidl
= _ILCreateControlPanel();
1998 case CSIDL_PRINTERS
:
1999 *ppidl
= _ILCreatePrinters();
2003 FIXME("virtual font folder");
2006 case CSIDL_BITBUCKET
:
2007 *ppidl
= _ILCreateBitBucket();
2011 *ppidl
= _ILCreateMyComputer();
2015 *ppidl
= _ILCreateNetwork();
2020 WCHAR szPath
[MAX_PATH
];
2022 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
2023 SHGFP_TYPE_CURRENT
, szPath
);
2028 TRACE("Value=%s\n", debugstr_w(szPath
));
2029 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
2031 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
2033 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2034 * version 6.0 returns E_FAIL for nonexistent paths
2043 TRACE("-- (new pidl %p)\n",*ppidl
);
2047 /*************************************************************************
2048 * SHGetSpecialFolderLocation [SHELL32.@]
2051 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2054 HRESULT WINAPI
SHGetSpecialFolderLocation(
2057 LPITEMIDLIST
* ppidl
)
2059 HRESULT hr
= E_INVALIDARG
;
2061 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
2064 return E_INVALIDARG
;
2066 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);