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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Many of these functions are in SHLWAPI.DLL also
28 #include "wine/port.h"
34 #include "wine/debug.h"
44 #include "shell32_main.h"
45 #include "undocshell.h"
47 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(shell);
54 ########## Combining and Constructing paths ##########
57 /*************************************************************************
58 * PathAppend [SHELL32.36]
60 BOOL WINAPI PathAppendAW(
64 if (SHELL_OsIsUnicode())
65 return PathAppendW(lpszPath1, lpszPath2);
66 return PathAppendA(lpszPath1, lpszPath2);
69 /*************************************************************************
70 * PathCombine [SHELL32.37]
72 LPVOID WINAPI PathCombineAW(
77 if (SHELL_OsIsUnicode())
78 return PathCombineW( szDest, lpszDir, lpszFile );
79 return PathCombineA( szDest, lpszDir, lpszFile );
82 /*************************************************************************
83 * PathAddBackslash [SHELL32.32]
85 LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
87 if(SHELL_OsIsUnicode())
88 return PathAddBackslashW(lpszPath);
89 return PathAddBackslashA(lpszPath);
92 /*************************************************************************
93 * PathBuildRoot [SHELL32.30]
95 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
97 if(SHELL_OsIsUnicode())
98 return PathBuildRootW(lpszPath, drive);
99 return PathBuildRootA(lpszPath, drive);
103 Extracting Component Parts
106 /*************************************************************************
107 * PathFindFileName [SHELL32.34]
109 LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
111 if(SHELL_OsIsUnicode())
112 return PathFindFileNameW(lpszPath);
113 return PathFindFileNameA(lpszPath);
116 /*************************************************************************
117 * PathFindExtension [SHELL32.31]
119 LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
121 if (SHELL_OsIsUnicode())
122 return PathFindExtensionW(lpszPath);
123 return PathFindExtensionA(lpszPath);
127 /*************************************************************************
128 * PathGetExtensionA [internal]
131 * exported by ordinal
132 * return value points to the first char after the dot
134 static LPSTR PathGetExtensionA(LPCSTR lpszPath)
136 TRACE("(%s)\n",lpszPath);
138 lpszPath = PathFindExtensionA(lpszPath);
139 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
142 /*************************************************************************
143 * PathGetExtensionW [internal]
145 static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
147 TRACE("(%s)\n",debugstr_w(lpszPath));
149 lpszPath = PathFindExtensionW(lpszPath);
150 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
153 /*************************************************************************
154 * PathGetExtension [SHELL32.158]
156 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath,DWORD void1, DWORD void2)
158 if (SHELL_OsIsUnicode())
159 return PathGetExtensionW(lpszPath);
160 return PathGetExtensionA(lpszPath);
163 /*************************************************************************
164 * PathGetArgs [SHELL32.52]
166 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
168 if (SHELL_OsIsUnicode())
169 return PathGetArgsW(lpszPath);
170 return PathGetArgsA(lpszPath);
173 /*************************************************************************
174 * PathGetDriveNumber [SHELL32.57]
176 int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
178 if (SHELL_OsIsUnicode())
179 return PathGetDriveNumberW(lpszPath);
180 return PathGetDriveNumberA(lpszPath);
183 /*************************************************************************
184 * PathRemoveFileSpec [SHELL32.35]
186 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
188 if (SHELL_OsIsUnicode())
189 return PathRemoveFileSpecW(lpszPath);
190 return PathRemoveFileSpecA(lpszPath);
193 /*************************************************************************
194 * PathStripPath [SHELL32.38]
196 void WINAPI PathStripPathAW(LPVOID lpszPath)
198 if (SHELL_OsIsUnicode())
199 PathStripPathW(lpszPath);
201 PathStripPathA(lpszPath);
204 /*************************************************************************
205 * PathStripToRoot [SHELL32.50]
207 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
209 if (SHELL_OsIsUnicode())
210 return PathStripToRootW(lpszPath);
211 return PathStripToRootA(lpszPath);
214 /*************************************************************************
215 * PathRemoveArgs [SHELL32.251]
217 void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
219 if (SHELL_OsIsUnicode())
220 PathRemoveArgsW(lpszPath);
222 PathRemoveArgsA(lpszPath);
225 /*************************************************************************
226 * PathRemoveExtension [SHELL32.250]
228 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
230 if (SHELL_OsIsUnicode())
231 PathRemoveExtensionW(lpszPath);
233 PathRemoveExtensionA(lpszPath);
241 /*************************************************************************
242 * PathGetShortPathA [internal]
244 static void PathGetShortPathA(LPSTR pszPath)
248 TRACE("%s\n", pszPath);
250 if (GetShortPathNameA(pszPath, path, MAX_PATH))
252 lstrcpyA(pszPath, path);
256 /*************************************************************************
257 * PathGetShortPathW [internal]
259 static void PathGetShortPathW(LPWSTR pszPath)
261 WCHAR path[MAX_PATH];
263 TRACE("%s\n", debugstr_w(pszPath));
265 if (GetShortPathNameW(pszPath, path, MAX_PATH))
267 lstrcpyW(pszPath, path);
271 /*************************************************************************
272 * PathGetShortPath [SHELL32.92]
274 VOID WINAPI PathGetShortPathAW(LPVOID pszPath)
276 if(SHELL_OsIsUnicode())
277 PathGetShortPathW(pszPath);
278 PathGetShortPathA(pszPath);
281 /*************************************************************************
282 * PathRemoveBlanks [SHELL32.33]
284 void WINAPI PathRemoveBlanksAW(LPVOID str)
286 if(SHELL_OsIsUnicode())
287 PathRemoveBlanksW(str);
289 PathRemoveBlanksA(str);
292 /*************************************************************************
293 * PathQuoteSpaces [SHELL32.55]
295 VOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
297 if(SHELL_OsIsUnicode())
298 PathQuoteSpacesW(lpszPath);
300 PathQuoteSpacesA(lpszPath);
303 /*************************************************************************
304 * PathUnquoteSpaces [SHELL32.56]
306 VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
308 if(SHELL_OsIsUnicode())
309 PathUnquoteSpacesW(str);
311 PathUnquoteSpacesA(str);
314 /*************************************************************************
315 * PathParseIconLocation [SHELL32.249]
317 int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
319 if(SHELL_OsIsUnicode())
320 return PathParseIconLocationW(lpszPath);
321 return PathParseIconLocationA(lpszPath);
325 ########## Path Testing ##########
327 /*************************************************************************
328 * PathIsUNC [SHELL32.39]
330 BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
332 if (SHELL_OsIsUnicode())
333 return PathIsUNCW( lpszPath );
334 return PathIsUNCA( lpszPath );
337 /*************************************************************************
338 * PathIsRelative [SHELL32.40]
340 BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
342 if (SHELL_OsIsUnicode())
343 return PathIsRelativeW( lpszPath );
344 return PathIsRelativeA( lpszPath );
347 /*************************************************************************
348 * PathIsRoot [SHELL32.29]
350 BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
352 if (SHELL_OsIsUnicode())
353 return PathIsRootW(lpszPath);
354 return PathIsRootA(lpszPath);
357 /*************************************************************************
358 * PathIsExeA [internal]
360 static BOOL PathIsExeA (LPCSTR lpszPath)
362 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
364 static const char * const lpszExtensions[] =
365 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
367 TRACE("path=%s\n",lpszPath);
369 for(i=0; lpszExtensions[i]; i++)
370 if (!lstrcmpiA(lpszExtension,lpszExtensions[i])) return TRUE;
375 /*************************************************************************
376 * PathIsExeW [internal]
378 static BOOL PathIsExeW (LPCWSTR lpszPath)
380 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
382 static const WCHAR lpszExtensions[][4] =
383 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
384 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
385 {'s','c','r','\0'}, {'\0'} };
387 TRACE("path=%s\n",debugstr_w(lpszPath));
389 for(i=0; lpszExtensions[i][0]; i++)
390 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
395 /*************************************************************************
396 * PathIsExe [SHELL32.43]
398 BOOL WINAPI PathIsExeAW (LPCVOID path)
400 if (SHELL_OsIsUnicode())
401 return PathIsExeW (path);
402 return PathIsExeA(path);
405 /*************************************************************************
406 * PathIsDirectory [SHELL32.159]
408 BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
410 if (SHELL_OsIsUnicode())
411 return PathIsDirectoryW (lpszPath);
412 return PathIsDirectoryA (lpszPath);
415 /*************************************************************************
416 * PathFileExists [SHELL32.45]
418 BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
420 if (SHELL_OsIsUnicode())
421 return PathFileExistsW (lpszPath);
422 return PathFileExistsA (lpszPath);
425 /*************************************************************************
426 * PathMatchSpec [SHELL32.46]
428 BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
430 if (SHELL_OsIsUnicode())
431 return PathMatchSpecW( name, mask );
432 return PathMatchSpecA( name, mask );
435 /*************************************************************************
436 * PathIsSameRoot [SHELL32.650]
438 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
440 if (SHELL_OsIsUnicode())
441 return PathIsSameRootW(lpszPath1, lpszPath2);
442 return PathIsSameRootA(lpszPath1, lpszPath2);
445 /*************************************************************************
446 * IsLFNDriveA [SHELL32.41]
448 BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
452 if (!GetVolumeInformationA(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
457 /*************************************************************************
458 * IsLFNDriveW [SHELL32.42]
460 BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
464 if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
469 /*************************************************************************
470 * IsLFNDrive [SHELL32.119]
472 BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath)
474 if (SHELL_OsIsUnicode())
475 return IsLFNDriveW(lpszPath);
476 return IsLFNDriveA(lpszPath);
480 ########## Creating Something Unique ##########
482 /*************************************************************************
483 * PathMakeUniqueNameA [internal]
485 BOOL WINAPI PathMakeUniqueNameA(
488 LPCSTR lpszShortName,
492 FIXME("%p %u %s %s %s stub\n",
493 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
494 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
498 /*************************************************************************
499 * PathMakeUniqueNameW [internal]
501 BOOL WINAPI PathMakeUniqueNameW(
504 LPCWSTR lpszShortName,
505 LPCWSTR lpszLongName,
506 LPCWSTR lpszPathName)
508 FIXME("%p %u %s %s %s stub\n",
509 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
510 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
514 /*************************************************************************
515 * PathMakeUniqueName [SHELL32.47]
517 BOOL WINAPI PathMakeUniqueNameAW(
520 LPCVOID lpszShortName,
521 LPCVOID lpszLongName,
522 LPCVOID lpszPathName)
524 if (SHELL_OsIsUnicode())
525 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
526 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
529 /*************************************************************************
530 * PathYetAnotherMakeUniqueName [SHELL32.75]
533 * exported by ordinal
535 BOOL WINAPI PathYetAnotherMakeUniqueName(
537 LPCWSTR lpszPathName,
538 LPCWSTR lpszShortName,
539 LPCWSTR lpszLongName)
541 FIXME("(%p, %s, %s ,%s):stub.\n",
542 lpszBuffer, debugstr_w(lpszPathName), debugstr_w(lpszShortName), debugstr_w(lpszLongName));
548 ########## cleaning and resolving paths ##########
551 /*************************************************************************
552 * PathFindOnPath [SHELL32.145]
554 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID *sOtherDirs)
556 if (SHELL_OsIsUnicode())
557 return PathFindOnPathW(sFile, (LPCWSTR *)sOtherDirs);
558 return PathFindOnPathA(sFile, (LPCSTR *)sOtherDirs);
561 /*************************************************************************
562 * PathCleanupSpec [SHELL32.171]
564 * lpszFile is changed in place.
566 int WINAPI PathCleanupSpec( LPCWSTR lpszPathW, LPWSTR lpszFileW )
572 if (SHELL_OsIsUnicode())
574 LPWSTR p = lpszFileW;
576 TRACE("Cleanup %s\n",debugstr_w(lpszFileW));
579 length = strlenW(lpszPathW);
583 int gct = PathGetCharTypeW(*p);
584 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
587 rc |= PCS_REPLACEDCHAR;
593 if (length + i == MAX_PATH)
595 rc |= PCS_FATAL | PCS_PATHTOOLONG;
603 LPSTR lpszFileA = (LPSTR)lpszFileW;
604 LPCSTR lpszPathA = (LPCSTR)lpszPathW;
607 TRACE("Cleanup %s\n",debugstr_a(lpszFileA));
610 length = strlen(lpszPathA);
614 int gct = PathGetCharTypeA(*p);
615 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
618 rc |= PCS_REPLACEDCHAR;
624 if (length + i == MAX_PATH)
626 rc |= PCS_FATAL | PCS_PATHTOOLONG;
635 /*************************************************************************
636 * PathQualifyA [SHELL32]
638 BOOL WINAPI PathQualifyA(LPCSTR pszPath)
640 FIXME("%s\n",pszPath);
644 /*************************************************************************
645 * PathQualifyW [SHELL32]
647 BOOL WINAPI PathQualifyW(LPCWSTR pszPath)
649 FIXME("%s\n",debugstr_w(pszPath));
653 /*************************************************************************
654 * PathQualify [SHELL32.49]
656 BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
658 if (SHELL_OsIsUnicode())
659 return PathQualifyW(pszPath);
660 return PathQualifyA(pszPath);
663 /*************************************************************************
664 * PathResolveA [SHELL32.51]
666 BOOL WINAPI PathResolveA(
671 FIXME("(%s,%p,0x%08x),stub!\n",
672 lpszPath, *alpszPaths, dwFlags);
676 /*************************************************************************
677 * PathResolveW [SHELL32]
679 BOOL WINAPI PathResolveW(
684 FIXME("(%s,%p,0x%08x),stub!\n",
685 debugstr_w(lpszPath), debugstr_w(*alpszPaths), dwFlags);
689 /*************************************************************************
690 * PathResolve [SHELL32.51]
692 BOOL WINAPI PathResolveAW(
697 if (SHELL_OsIsUnicode())
698 return PathResolveW(lpszPath, (LPCWSTR*)alpszPaths, dwFlags);
699 return PathResolveA(lpszPath, (LPCSTR*)alpszPaths, dwFlags);
702 /*************************************************************************
703 * PathProcessCommandA [SHELL32.653]
705 LONG WINAPI PathProcessCommandA (
711 FIXME("%s %p 0x%04x 0x%04x stub\n",
712 lpszPath, lpszBuff, dwBuffSize, dwFlags);
713 if(!lpszPath) return -1;
714 if(lpszBuff) strcpy(lpszBuff, lpszPath);
715 return strlen(lpszPath);
718 /*************************************************************************
719 * PathProcessCommandW
721 LONG WINAPI PathProcessCommandW (
727 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
728 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
729 if(!lpszPath) return -1;
730 if(lpszBuff) strcpyW(lpszBuff, lpszPath);
731 return strlenW(lpszPath);
734 /*************************************************************************
735 * PathProcessCommand (SHELL32.653)
737 LONG WINAPI PathProcessCommandAW (
743 if (SHELL_OsIsUnicode())
744 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
745 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
749 ########## special ##########
752 /*************************************************************************
753 * PathSetDlgItemPath (SHELL32.48)
755 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
757 if (SHELL_OsIsUnicode())
758 PathSetDlgItemPathW(hDlg, id, pszPath);
760 PathSetDlgItemPathA(hDlg, id, pszPath);
763 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'};
764 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'};
765 static const WCHAR AppDataW[] = {'A','p','p','D','a','t','a','\0'};
766 static const WCHAR CacheW[] = {'C','a','c','h','e','\0'};
767 static const WCHAR CD_BurningW[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
768 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'};
769 static const WCHAR Common_AppDataW[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
770 static const WCHAR Common_DesktopW[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
771 static const WCHAR Common_DocumentsW[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
772 static const WCHAR CommonFilesDirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
773 static const WCHAR CommonMusicW[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
774 static const WCHAR CommonPicturesW[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
775 static const WCHAR Common_ProgramsW[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
776 static const WCHAR Common_StartUpW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
777 static const WCHAR Common_Start_MenuW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
778 static const WCHAR Common_TemplatesW[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
779 static const WCHAR CommonVideoW[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
780 static const WCHAR CookiesW[] = {'C','o','o','k','i','e','s','\0'};
781 static const WCHAR DesktopW[] = {'D','e','s','k','t','o','p','\0'};
782 static const WCHAR FavoritesW[] = {'F','a','v','o','r','i','t','e','s','\0'};
783 static const WCHAR FontsW[] = {'F','o','n','t','s','\0'};
784 static const WCHAR HistoryW[] = {'H','i','s','t','o','r','y','\0'};
785 static const WCHAR Local_AppDataW[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
786 static const WCHAR My_MusicW[] = {'M','y',' ','M','u','s','i','c','\0'};
787 static const WCHAR My_PicturesW[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
788 static const WCHAR My_VideoW[] = {'M','y',' ','V','i','d','e','o','s','\0'};
789 static const WCHAR NetHoodW[] = {'N','e','t','H','o','o','d','\0'};
790 static const WCHAR PersonalW[] = {'P','e','r','s','o','n','a','l','\0'};
791 static const WCHAR PrintHoodW[] = {'P','r','i','n','t','H','o','o','d','\0'};
792 static const WCHAR ProgramFilesDirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
793 static const WCHAR ProgramsW[] = {'P','r','o','g','r','a','m','s','\0'};
794 static const WCHAR RecentW[] = {'R','e','c','e','n','t','\0'};
795 static const WCHAR ResourcesW[] = {'R','e','s','o','u','r','c','e','s','\0'};
796 static const WCHAR SendToW[] = {'S','e','n','d','T','o','\0'};
797 static const WCHAR StartUpW[] = {'S','t','a','r','t','U','p','\0'};
798 static const WCHAR Start_MenuW[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
799 static const WCHAR TemplatesW[] = {'T','e','m','p','l','a','t','e','s','\0'};
800 static const WCHAR DefaultW[] = {'.','D','e','f','a','u','l','t','\0'};
801 static const WCHAR AllUsersProfileW[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
802 static const WCHAR UserProfileW[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
803 static const WCHAR SystemDriveW[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
804 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};
805 static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
806 static const WCHAR AllUsersProfileValueW[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
807 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'};
808 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'};
809 /* This defaults to L"Documents and Settings" on Windows 2000/XP, but we're
810 * acting more Windows 9x-like for now.
812 static const WCHAR szDefaultProfileDirW[] = {'p','r','o','f','i','l','e','s','\0'};
813 static const WCHAR AllUsersW[] = {'A','l','l',' ','U','s','e','r','s','\0'};
815 typedef enum _CSIDL_Type {
819 CSIDL_Type_Disallowed,
820 CSIDL_Type_NonExistent,
821 CSIDL_Type_WindowsPath,
822 CSIDL_Type_SystemPath,
829 LPCWSTR szDefaultPath; /* fallback string or resource ID */
832 static const CSIDL_DATA CSIDL_Data[] =
834 { /* 0x00 - CSIDL_DESKTOP */
837 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
839 { /* 0x01 - CSIDL_INTERNET */
840 CSIDL_Type_Disallowed,
844 { /* 0x02 - CSIDL_PROGRAMS */
847 MAKEINTRESOURCEW(IDS_PROGRAMS)
849 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
850 CSIDL_Type_SystemPath,
854 { /* 0x04 - CSIDL_PRINTERS */
855 CSIDL_Type_SystemPath,
859 { /* 0x05 - CSIDL_PERSONAL */
862 MAKEINTRESOURCEW(IDS_PERSONAL)
864 { /* 0x06 - CSIDL_FAVORITES */
867 MAKEINTRESOURCEW(IDS_FAVORITES)
869 { /* 0x07 - CSIDL_STARTUP */
872 MAKEINTRESOURCEW(IDS_STARTUP)
874 { /* 0x08 - CSIDL_RECENT */
877 MAKEINTRESOURCEW(IDS_RECENT)
879 { /* 0x09 - CSIDL_SENDTO */
882 MAKEINTRESOURCEW(IDS_SENDTO)
884 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
885 CSIDL_Type_Disallowed,
889 { /* 0x0b - CSIDL_STARTMENU */
892 MAKEINTRESOURCEW(IDS_STARTMENU)
894 { /* 0x0c - CSIDL_MYDOCUMENTS */
895 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
899 { /* 0x0d - CSIDL_MYMUSIC */
902 MAKEINTRESOURCEW(IDS_MYMUSIC)
904 { /* 0x0e - CSIDL_MYVIDEO */
907 MAKEINTRESOURCEW(IDS_MYVIDEO)
909 { /* 0x0f - unassigned */
910 CSIDL_Type_Disallowed,
914 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
917 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
919 { /* 0x11 - CSIDL_DRIVES */
920 CSIDL_Type_Disallowed,
924 { /* 0x12 - CSIDL_NETWORK */
925 CSIDL_Type_Disallowed,
929 { /* 0x13 - CSIDL_NETHOOD */
932 MAKEINTRESOURCEW(IDS_NETHOOD)
934 { /* 0x14 - CSIDL_FONTS */
935 CSIDL_Type_WindowsPath,
939 { /* 0x15 - CSIDL_TEMPLATES */
942 MAKEINTRESOURCEW(IDS_TEMPLATES)
944 { /* 0x16 - CSIDL_COMMON_STARTMENU */
947 MAKEINTRESOURCEW(IDS_STARTMENU)
949 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
952 MAKEINTRESOURCEW(IDS_PROGRAMS)
954 { /* 0x18 - CSIDL_COMMON_STARTUP */
957 MAKEINTRESOURCEW(IDS_STARTUP)
959 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
962 MAKEINTRESOURCEW(IDS_DESKTOP)
964 { /* 0x1a - CSIDL_APPDATA */
967 MAKEINTRESOURCEW(IDS_APPDATA)
969 { /* 0x1b - CSIDL_PRINTHOOD */
972 MAKEINTRESOURCEW(IDS_PRINTHOOD)
974 { /* 0x1c - CSIDL_LOCAL_APPDATA */
977 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA)
979 { /* 0x1d - CSIDL_ALTSTARTUP */
980 CSIDL_Type_NonExistent,
984 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
985 CSIDL_Type_NonExistent,
989 { /* 0x1f - CSIDL_COMMON_FAVORITES */
992 MAKEINTRESOURCEW(IDS_FAVORITES)
994 { /* 0x20 - CSIDL_INTERNET_CACHE */
997 MAKEINTRESOURCEW(IDS_INTERNET_CACHE)
999 { /* 0x21 - CSIDL_COOKIES */
1002 MAKEINTRESOURCEW(IDS_COOKIES)
1004 { /* 0x22 - CSIDL_HISTORY */
1007 MAKEINTRESOURCEW(IDS_HISTORY)
1009 { /* 0x23 - CSIDL_COMMON_APPDATA */
1010 CSIDL_Type_AllUsers,
1012 MAKEINTRESOURCEW(IDS_APPDATA)
1014 { /* 0x24 - CSIDL_WINDOWS */
1015 CSIDL_Type_WindowsPath,
1019 { /* 0x25 - CSIDL_SYSTEM */
1020 CSIDL_Type_SystemPath,
1024 { /* 0x26 - CSIDL_PROGRAM_FILES */
1027 MAKEINTRESOURCEW(IDS_PROGRAM_FILES)
1029 { /* 0x27 - CSIDL_MYPICTURES */
1032 MAKEINTRESOURCEW(IDS_MYPICTURES)
1034 { /* 0x28 - CSIDL_PROFILE */
1039 { /* 0x29 - CSIDL_SYSTEMX86 */
1040 CSIDL_Type_NonExistent,
1044 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1045 CSIDL_Type_NonExistent,
1049 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1052 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON)
1054 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1055 CSIDL_Type_NonExistent,
1059 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1060 CSIDL_Type_AllUsers,
1062 MAKEINTRESOURCEW(IDS_TEMPLATES)
1064 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1065 CSIDL_Type_AllUsers,
1067 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS)
1069 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1070 CSIDL_Type_AllUsers,
1071 Common_Administrative_ToolsW,
1072 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1074 { /* 0x30 - CSIDL_ADMINTOOLS */
1076 Administrative_ToolsW,
1077 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1079 { /* 0x31 - CSIDL_CONNECTIONS */
1080 CSIDL_Type_Disallowed,
1084 { /* 0x32 - unassigned */
1085 CSIDL_Type_Disallowed,
1089 { /* 0x33 - unassigned */
1090 CSIDL_Type_Disallowed,
1094 { /* 0x34 - unassigned */
1095 CSIDL_Type_Disallowed,
1099 { /* 0x35 - CSIDL_COMMON_MUSIC */
1100 CSIDL_Type_AllUsers,
1102 MAKEINTRESOURCEW(IDS_COMMON_MUSIC)
1104 { /* 0x36 - CSIDL_COMMON_PICTURES */
1105 CSIDL_Type_AllUsers,
1107 MAKEINTRESOURCEW(IDS_COMMON_PICTURES)
1109 { /* 0x37 - CSIDL_COMMON_VIDEO */
1110 CSIDL_Type_AllUsers,
1112 MAKEINTRESOURCEW(IDS_COMMON_VIDEO)
1114 { /* 0x38 - CSIDL_RESOURCES */
1115 CSIDL_Type_WindowsPath,
1119 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1120 CSIDL_Type_NonExistent,
1124 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1125 CSIDL_Type_NonExistent,
1129 { /* 0x3b - CSIDL_CDBURN_AREA */
1132 MAKEINTRESOURCEW(IDS_CDBURN_AREA)
1134 { /* 0x3c unassigned */
1135 CSIDL_Type_Disallowed,
1139 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1140 CSIDL_Type_Disallowed, /* FIXME */
1144 { /* 0x3e - CSIDL_PROFILES */
1145 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
1151 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
1153 /* Gets the value named value from the registry key
1154 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1155 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1156 * is assumed to be MAX_PATH WCHARs in length.
1157 * If it exists, expands the value and writes the expanded value to
1158 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1159 * Returns successful error code if the value was retrieved from the registry,
1160 * and a failure otherwise.
1162 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
1163 LPCWSTR value, LPWSTR path)
1166 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
1167 LPCWSTR pShellFolderPath, pUserShellFolderPath;
1168 DWORD dwType, dwPathLen = MAX_PATH;
1169 HKEY userShellFolderKey, shellFolderKey;
1171 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
1176 strcpyW(shellFolderPath, userPrefix);
1177 PathAddBackslashW(shellFolderPath);
1178 strcatW(shellFolderPath, szSHFolders);
1179 pShellFolderPath = shellFolderPath;
1180 strcpyW(userShellFolderPath, userPrefix);
1181 PathAddBackslashW(userShellFolderPath);
1182 strcatW(userShellFolderPath, szSHUserFolders);
1183 pUserShellFolderPath = userShellFolderPath;
1187 pUserShellFolderPath = szSHUserFolders;
1188 pShellFolderPath = szSHFolders;
1191 if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey))
1193 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
1196 if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey))
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%08x\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 if (CSIDL_Data[folder].szDefaultPath &&
1260 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
1262 if (LoadStringW(shell32_hInstance,
1263 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
1266 pDefaultPath = resourcePath;
1270 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
1271 debugstr_w(pszPath));
1278 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
1282 switch (CSIDL_Data[folder].type)
1284 case CSIDL_Type_User:
1285 strcpyW(pszPath, UserProfileW);
1287 case CSIDL_Type_AllUsers:
1288 strcpyW(pszPath, AllUsersProfileW);
1290 case CSIDL_Type_CurrVer:
1291 strcpyW(pszPath, SystemDriveW);
1294 ; /* no corresponding env. var, do nothing */
1298 PathAddBackslashW(pszPath);
1299 strcatW(pszPath, pDefaultPath);
1302 TRACE("returning 0x%08x\n", hr);
1306 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1307 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1308 * can be overridden in the HKLM\\szCurrentVersion key.
1309 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1310 * the registry, uses _SHGetDefaultValue to get the value.
1312 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
1317 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1319 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1320 return E_INVALIDARG;
1321 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
1322 return E_INVALIDARG;
1324 return E_INVALIDARG;
1326 if (dwFlags & SHGFP_TYPE_DEFAULT)
1327 hr = _SHGetDefaultValue(folder, pszPath);
1332 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
1336 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
1338 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
1339 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
1340 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
1342 hr = _SHGetDefaultValue(folder, pszPath);
1343 dwType = REG_EXPAND_SZ;
1344 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
1345 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
1349 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
1355 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1359 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1360 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1361 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1362 * - if hToken is -1, looks in HKEY_USERS\.Default
1363 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1364 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1365 * calls _SHGetDefaultValue for it.
1367 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
1372 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
1374 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1375 return E_INVALIDARG;
1376 if (CSIDL_Data[folder].type != CSIDL_Type_User)
1377 return E_INVALIDARG;
1379 return E_INVALIDARG;
1381 /* Only the current user and the default user are supported right now
1383 * FIXME: should be able to call GetTokenInformation on the token,
1384 * then call ConvertSidToStringSidW on it to get the user prefix.
1385 * But Wine's registry doesn't store user info by sid, it stores it
1386 * by user name (and I don't know how to convert from a token to a
1389 if (hToken != NULL && hToken != (HANDLE)-1)
1391 FIXME("unsupported for user other than current or default\n");
1395 if (dwFlags & SHGFP_TYPE_DEFAULT)
1396 hr = _SHGetDefaultValue(folder, pszPath);
1399 LPCWSTR userPrefix = NULL;
1402 if (hToken == (HANDLE)-1)
1404 hRootKey = HKEY_USERS;
1405 userPrefix = DefaultW;
1407 else /* hToken == NULL, other values disallowed above */
1408 hRootKey = HKEY_CURRENT_USER;
1409 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix,
1410 CSIDL_Data[folder].szValueName, pszPath);
1411 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
1412 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1413 CSIDL_Data[folder].szValueName, pszPath);
1415 hr = _SHGetDefaultValue(folder, pszPath);
1417 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1421 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1422 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1423 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1424 * If this fails, falls back to _SHGetDefaultValue.
1426 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
1431 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1433 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1434 return E_INVALIDARG;
1435 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
1436 return E_INVALIDARG;
1438 return E_INVALIDARG;
1440 if (dwFlags & SHGFP_TYPE_DEFAULT)
1441 hr = _SHGetDefaultValue(folder, pszPath);
1444 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1445 CSIDL_Data[folder].szValueName, pszPath);
1447 hr = _SHGetDefaultValue(folder, pszPath);
1449 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1453 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
1458 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
1459 KEY_ALL_ACCESS, NULL, pKey, &disp);
1460 return HRESULT_FROM_WIN32(lRet);
1463 /* Reads the value named szValueName from the key profilesKey (assumed to be
1464 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1465 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1466 * szDefault to the registry).
1468 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
1469 LPWSTR szValue, LPCWSTR szDefault)
1472 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
1475 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
1476 debugstr_w(szDefault));
1477 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
1478 (LPBYTE)szValue, &dwPathLen);
1479 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
1482 dwPathLen /= sizeof(WCHAR);
1483 szValue[dwPathLen] = '\0';
1488 /* Missing or invalid value, set a default */
1489 lstrcpynW(szValue, szDefault, MAX_PATH);
1490 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
1491 debugstr_w(szValue));
1492 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
1494 (strlenW(szValue) + 1) * sizeof(WCHAR));
1496 hr = HRESULT_FROM_WIN32(lRet);
1500 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
1504 /* Attempts to expand environment variables from szSrc into szDest, which is
1505 * assumed to be MAX_PATH characters in length. Before referring to the
1506 * environment, handles a few variables directly, because the environment
1507 * variables may not be set when this is called (as during Wine's installation
1508 * when default values are being written to the registry).
1509 * The directly handled environment variables, and their source, are:
1510 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1511 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1513 * If one of the directly handled environment variables is expanded, only
1514 * expands a single variable, and only in the beginning of szSrc.
1516 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
1519 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
1522 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
1524 if (!szSrc || !szDest) return E_INVALIDARG;
1526 /* short-circuit if there's nothing to expand */
1527 if (szSrc[0] != '%')
1529 strcpyW(szDest, szSrc);
1533 /* Get the profile prefix, we'll probably be needing it */
1534 hr = _SHOpenProfilesKey(&key);
1537 WCHAR szDefaultProfilesPrefix[MAX_PATH];
1539 GetWindowsDirectoryW(szDefaultProfilesPrefix, MAX_PATH);
1540 PathAddBackslashW(szDefaultProfilesPrefix);
1541 PathAppendW(szDefaultProfilesPrefix, szDefaultProfileDirW);
1542 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix,
1543 szDefaultProfilesPrefix);
1547 strcpyW(szTemp, szSrc);
1548 while (SUCCEEDED(hr) && szTemp[0] == '%')
1550 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
1552 WCHAR szAllUsers[MAX_PATH];
1554 strcpyW(szDest, szProfilesPrefix);
1555 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
1556 szAllUsers, AllUsersW);
1557 PathAppendW(szDest, szAllUsers);
1558 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
1560 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
1562 WCHAR userName[MAX_PATH];
1563 DWORD userLen = MAX_PATH;
1565 strcpyW(szDest, szProfilesPrefix);
1566 GetUserNameW(userName, &userLen);
1567 PathAppendW(szDest, userName);
1568 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
1570 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
1572 GetSystemDirectoryW(szDest, MAX_PATH);
1573 if (szDest[1] != ':')
1575 FIXME("non-drive system paths unsupported\n");
1580 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
1586 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
1589 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1591 hr = HRESULT_FROM_WIN32(GetLastError());
1595 if (SUCCEEDED(hr) && szDest[0] == '%')
1596 strcpyW(szTemp, szDest);
1599 /* terminate loop */
1606 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
1607 debugstr_w(szSrc), debugstr_w(szDest));
1611 /*************************************************************************
1612 * SHGetFolderPathW [SHELL32.@]
1614 * Convert nFolder to path.
1618 * Failure: standard HRESULT error codes.
1621 * Most values can be overridden in either
1622 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1623 * or in the same location in HKLM.
1624 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1625 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1626 * changes made to it are made to the former key too. This synchronization is
1627 * done on-demand: not until someone requests the value of one of these paths
1628 * (by calling one of the SHGet functions) is the value synchronized.
1629 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1631 HRESULT WINAPI SHGetFolderPathW(
1632 HWND hwndOwner, /* [I] owner window */
1633 int nFolder, /* [I] CSIDL identifying the folder */
1634 HANDLE hToken, /* [I] access token */
1635 DWORD dwFlags, /* [I] which path to return */
1636 LPWSTR pszPath) /* [O] converted path */
1639 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
1640 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
1644 TRACE("%p,%p,nFolder=0x%04x\n", hwndOwner,pszPath,nFolder);
1646 /* Windows always NULL-terminates the resulting path regardless of success
1647 * or failure, so do so first
1651 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1652 return E_INVALIDARG;
1654 type = CSIDL_Data[folder].type;
1657 case CSIDL_Type_Disallowed:
1660 case CSIDL_Type_NonExistent:
1663 case CSIDL_Type_WindowsPath:
1664 GetWindowsDirectoryW(szTemp, MAX_PATH);
1665 if (CSIDL_Data[folder].szDefaultPath &&
1666 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1667 *CSIDL_Data[folder].szDefaultPath)
1669 PathAddBackslashW(szTemp);
1670 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1674 case CSIDL_Type_SystemPath:
1675 GetSystemDirectoryW(szTemp, MAX_PATH);
1676 if (CSIDL_Data[folder].szDefaultPath &&
1677 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1678 *CSIDL_Data[folder].szDefaultPath)
1680 PathAddBackslashW(szTemp);
1681 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1685 case CSIDL_Type_CurrVer:
1686 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
1688 case CSIDL_Type_User:
1689 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
1691 case CSIDL_Type_AllUsers:
1692 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
1695 FIXME("bogus type %d, please fix\n", type);
1700 /* Expand environment strings if necessary */
1702 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
1704 strcpyW(szBuildPath, szTemp);
1705 /* Copy the path if it's available before we might return */
1706 if (SUCCEEDED(hr) && pszPath)
1707 strcpyW(pszPath, szBuildPath);
1709 if (FAILED(hr)) goto end;
1711 /* if we don't care about existing directories we are ready */
1712 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
1714 if (PathFileExistsW(szBuildPath)) goto end;
1716 /* not existing but we are not allowed to create it. The return value
1717 * is verified against shell32 version 6.0.
1719 if (!(nFolder & CSIDL_FLAG_CREATE))
1721 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1725 /* create directory/directories */
1726 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
1727 if (ret && ret != ERROR_ALREADY_EXISTS)
1729 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
1734 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
1736 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
1740 /*************************************************************************
1741 * SHGetFolderPathA [SHELL32.@]
1743 * See SHGetFolderPathW.
1745 HRESULT WINAPI SHGetFolderPathA(
1752 WCHAR szTemp[MAX_PATH];
1755 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
1759 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
1760 if (SUCCEEDED(hr) && pszPath)
1761 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
1767 /* For each folder in folders, if its value has not been set in the registry,
1768 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1769 * folder's type) to get the unexpanded value first.
1770 * Writes the unexpanded value to User Shell Folders, and queries it with
1771 * SHGetFolderPathW to force the creation of the directory if it doesn't
1772 * already exist. SHGetFolderPathW also returns the expanded value, which
1773 * this then writes to Shell Folders.
1775 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
1776 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
1780 WCHAR path[MAX_PATH];
1782 HKEY hUserKey = NULL, hKey = NULL;
1783 DWORD dwType, dwPathLen;
1786 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
1787 debugstr_w(szUserShellFolderPath), folders, foldersLen);
1789 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
1791 hr = HRESULT_FROM_WIN32(ret);
1794 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
1796 hr = HRESULT_FROM_WIN32(ret);
1798 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
1800 dwPathLen = MAX_PATH * sizeof(WCHAR);
1801 if (RegQueryValueExW(hUserKey, CSIDL_Data[folders[i]].szValueName, NULL,
1802 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
1803 dwType != REG_EXPAND_SZ))
1806 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
1807 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
1809 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
1810 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
1811 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
1812 GetWindowsDirectoryW(path, MAX_PATH);
1817 ret = RegSetValueExW(hUserKey,
1818 CSIDL_Data[folders[i]].szValueName, 0, REG_EXPAND_SZ,
1819 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1821 hr = HRESULT_FROM_WIN32(ret);
1824 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
1825 hToken, SHGFP_TYPE_DEFAULT, path);
1826 ret = RegSetValueExW(hKey,
1827 CSIDL_Data[folders[i]].szValueName, 0, REG_SZ,
1828 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1830 hr = HRESULT_FROM_WIN32(ret);
1836 RegCloseKey(hUserKey);
1840 TRACE("returning 0x%08x\n", hr);
1844 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
1846 static const UINT folders[] = {
1857 CSIDL_DESKTOPDIRECTORY,
1861 CSIDL_LOCAL_APPDATA,
1862 CSIDL_INTERNET_CACHE,
1868 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
1869 LPCWSTR pUserShellFolderPath, pShellFolderPath;
1874 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
1877 hToken = (HANDLE)-1;
1878 hRootKey = HKEY_USERS;
1879 strcpyW(userShellFolderPath, DefaultW);
1880 PathAddBackslashW(userShellFolderPath);
1881 strcatW(userShellFolderPath, szSHUserFolders);
1882 pUserShellFolderPath = userShellFolderPath;
1883 strcpyW(shellFolderPath, DefaultW);
1884 PathAddBackslashW(shellFolderPath);
1885 strcatW(shellFolderPath, szSHFolders);
1886 pShellFolderPath = shellFolderPath;
1891 hRootKey = HKEY_CURRENT_USER;
1892 pUserShellFolderPath = szSHUserFolders;
1893 pShellFolderPath = szSHFolders;
1896 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
1897 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
1898 TRACE("returning 0x%08x\n", hr);
1902 static HRESULT _SHRegisterCommonShellFolders(void)
1904 static const UINT folders[] = {
1905 CSIDL_COMMON_STARTMENU,
1906 CSIDL_COMMON_PROGRAMS,
1907 CSIDL_COMMON_STARTUP,
1908 CSIDL_COMMON_DESKTOPDIRECTORY,
1909 CSIDL_COMMON_FAVORITES,
1910 CSIDL_COMMON_APPDATA,
1911 CSIDL_COMMON_TEMPLATES,
1912 CSIDL_COMMON_DOCUMENTS,
1917 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
1918 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
1919 TRACE("returning 0x%08x\n", hr);
1923 /******************************************************************************
1924 * _SHAppendToUnixPath [Internal]
1926 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
1927 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
1928 * and replaces backslashes with slashes.
1931 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
1932 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
1938 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
1939 WCHAR wszSubPath[MAX_PATH];
1940 int cLen = strlen(szBasePath);
1943 if (IS_INTRESOURCE(pwszSubPath)) {
1944 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
1945 /* Fall back to hard coded defaults. */
1946 switch (LOWORD(pwszSubPath)) {
1948 lstrcpyW(wszSubPath, PersonalW);
1951 lstrcpyW(wszSubPath, My_MusicW);
1953 case IDS_MYPICTURES:
1954 lstrcpyW(wszSubPath, My_PicturesW);
1957 lstrcpyW(wszSubPath, My_VideoW);
1960 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
1965 lstrcpyW(wszSubPath, pwszSubPath);
1968 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
1970 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
1971 FILENAME_MAX - cLen, NULL, NULL))
1976 pBackslash = szBasePath + cLen;
1977 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
1982 /******************************************************************************
1983 * _SHCreateSymbolicLinks [Internal]
1985 * Sets up symbol links for various shell folders to point into the users home
1986 * directory. We do an educated guess about what the user would probably want:
1987 * - If there is a 'My Documents' directory in $HOME, the user probably wants
1988 * wine's 'My Documents' to point there. Furthermore, we imply that the user
1989 * is a Windows lover and has no problem with wine creating 'My Pictures',
1990 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
1991 * do not already exits. We put appropriate symbolic links in place for those,
1993 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
1994 * point directly to $HOME. We assume the user to be a unix hacker who does not
1995 * want wine to create anything anywhere besides the .wine directory. So, if
1996 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
1997 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
1998 * directory, and try to link to that. If that fails, then we symlink to
1999 * $HOME directly. The same holds fo 'My Pictures' and 'My Video'.
2000 * - The Desktop shell folder is symlinked to '$HOME/Desktop', if that does
2001 * exists and left alone if not.
2002 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2004 static void _SHCreateSymbolicLinks(void)
2006 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEO, IDS_MYMUSIC }, i;
2007 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
2008 static const char * xdg_dirs[] = { "PICTURES", "VIDEOS", "MUSIC" };
2009 WCHAR wszTempPath[MAX_PATH];
2010 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
2011 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
2012 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
2013 struct stat statFolder;
2014 const char *pszHome;
2016 const unsigned int num = sizeof(xdg_dirs) / sizeof(xdg_dirs[0]);
2017 char ** xdg_results = NULL;
2019 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2020 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
2021 SHGFP_TYPE_DEFAULT, wszTempPath);
2022 if (FAILED(hr)) return;
2023 pszPersonal = wine_get_unix_file_name(wszTempPath);
2024 if (!pszPersonal) return;
2026 XDG_UserDirLookup(xdg_dirs, num, &xdg_results);
2028 pszHome = getenv("HOME");
2029 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode)) {
2030 strcpy(szPersonalTarget, pszHome);
2031 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
2032 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2034 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2035 * 'My Music' subfolders or fail silently if they already exist. */
2036 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2037 strcpy(szMyStuffTarget, szPersonalTarget);
2038 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2039 mkdir(szMyStuffTarget, 0777);
2044 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2045 strcpy(szPersonalTarget, pszHome);
2048 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2050 symlink(szPersonalTarget, pszPersonal);
2054 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2055 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2056 strcpy(szPersonalTarget, pszPersonal);
2057 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2058 strcpy(szMyStuffTarget, szPersonalTarget);
2059 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2060 mkdir(szMyStuffTarget, 0777);
2064 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
2065 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2066 /* Create the current 'My Whatever' folder and get it's unix path. */
2067 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
2068 SHGFP_TYPE_DEFAULT, wszTempPath);
2069 if (FAILED(hr)) continue;
2070 pszMyStuff = wine_get_unix_file_name(wszTempPath);
2071 if (!pszMyStuff) continue;
2073 strcpy(szMyStuffTarget, szPersonalTarget);
2074 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
2075 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2077 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2079 symlink(szMyStuffTarget, pszMyStuff);
2084 if (xdg_results && xdg_results[i])
2086 /* the folder specified by XDG_XXX_DIR exists, link to it. */
2087 symlink(xdg_results[i], pszMyStuff);
2091 /* Else link to where 'My Documents' itself links to. */
2092 symlink(szPersonalTarget, pszMyStuff);
2095 HeapFree(GetProcessHeap(), 0, pszMyStuff);
2098 /* Last but not least, the Desktop folder */
2100 strcpy(szDesktopTarget, pszHome);
2102 strcpy(szDesktopTarget, pszPersonal);
2103 HeapFree(GetProcessHeap(), 0, pszPersonal);
2105 if (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
2106 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2108 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
2109 SHGFP_TYPE_DEFAULT, wszTempPath);
2110 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
2113 symlink(szDesktopTarget, pszDesktop);
2114 HeapFree(GetProcessHeap(), 0, pszDesktop);
2118 /* Free resources allocated by XDG_UserDirLookup() */
2121 for (i = 0; i < num; i++)
2122 HeapFree(GetProcessHeap(), 0, xdg_results[i]);
2123 HeapFree(GetProcessHeap(), 0, xdg_results);
2127 /* Register the default values in the registry, as some apps seem to depend
2128 * on their presence. The set registered was taken from Windows XP.
2130 HRESULT SHELL_RegisterShellFolders(void)
2134 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2135 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
2136 * _SHRegister*ShellFolders() functions will find everything nice and clean
2137 * and thus will not attempt to create them in the profile directory. */
2138 _SHCreateSymbolicLinks();
2140 hr = _SHRegisterUserShellFolders(TRUE);
2142 hr = _SHRegisterUserShellFolders(FALSE);
2144 hr = _SHRegisterCommonShellFolders();
2148 /*************************************************************************
2149 * SHGetSpecialFolderPathA [SHELL32.@]
2151 BOOL WINAPI SHGetSpecialFolderPathA (
2157 return (SHGetFolderPathA(
2159 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2162 szPath)) == S_OK ? TRUE : FALSE;
2165 /*************************************************************************
2166 * SHGetSpecialFolderPathW
2168 BOOL WINAPI SHGetSpecialFolderPathW (
2174 return (SHGetFolderPathW(
2176 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2179 szPath)) == S_OK ? TRUE : FALSE;
2182 /*************************************************************************
2183 * SHGetSpecialFolderPath (SHELL32.175)
2185 BOOL WINAPI SHGetSpecialFolderPathAW (
2192 if (SHELL_OsIsUnicode())
2193 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
2194 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
2197 /*************************************************************************
2198 * SHGetFolderLocation [SHELL32.@]
2200 * Gets the folder locations from the registry and creates a pidl.
2204 * nFolder [I] CSIDL_xxxxx
2205 * hToken [I] token representing user, or NULL for current user, or -1 for
2207 * dwReserved [I] must be zero
2208 * ppidl [O] PIDL of a special folder
2212 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2215 * Creates missing reg keys and directories.
2216 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2217 * virtual folders that are handled here.
2219 HRESULT WINAPI SHGetFolderLocation(
2224 LPITEMIDLIST *ppidl)
2226 HRESULT hr = E_INVALIDARG;
2228 TRACE("%p 0x%08x %p 0x%08x %p\n",
2229 hwndOwner, nFolder, hToken, dwReserved, ppidl);
2232 return E_INVALIDARG;
2234 return E_INVALIDARG;
2236 /* The virtual folders' locations are not user-dependent */
2241 *ppidl = _ILCreateDesktop();
2244 case CSIDL_PERSONAL:
2245 *ppidl = _ILCreateMyDocuments();
2248 case CSIDL_INTERNET:
2249 *ppidl = _ILCreateIExplore();
2252 case CSIDL_CONTROLS:
2253 *ppidl = _ILCreateControlPanel();
2256 case CSIDL_PRINTERS:
2257 *ppidl = _ILCreatePrinters();
2260 case CSIDL_BITBUCKET:
2261 *ppidl = _ILCreateBitBucket();
2265 *ppidl = _ILCreateMyComputer();
2269 *ppidl = _ILCreateNetwork();
2274 WCHAR szPath[MAX_PATH];
2276 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
2277 SHGFP_TYPE_CURRENT, szPath);
2282 TRACE("Value=%s\n", debugstr_w(szPath));
2283 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
2285 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
2287 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2288 * version 6.0 returns E_FAIL for nonexistent paths
2297 TRACE("-- (new pidl %p)\n",*ppidl);
2301 /*************************************************************************
2302 * SHGetSpecialFolderLocation [SHELL32.@]
2305 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2308 HRESULT WINAPI SHGetSpecialFolderLocation(
2311 LPITEMIDLIST * ppidl)
2313 HRESULT hr = E_INVALIDARG;
2315 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
2318 return E_INVALIDARG;
2320 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);