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"
50 WINE_DEFAULT_DEBUG_CHANNEL(shell);
53 ########## Combining and Constructing paths ##########
56 /*************************************************************************
57 * PathAppend [SHELL32.36]
59 BOOL WINAPI PathAppendAW(
63 if (SHELL_OsIsUnicode())
64 return PathAppendW(lpszPath1, lpszPath2);
65 return PathAppendA(lpszPath1, lpszPath2);
68 /*************************************************************************
69 * PathCombine [SHELL32.37]
71 LPVOID WINAPI PathCombineAW(
76 if (SHELL_OsIsUnicode())
77 return PathCombineW( szDest, lpszDir, lpszFile );
78 return PathCombineA( szDest, lpszDir, lpszFile );
81 /*************************************************************************
82 * PathAddBackslash [SHELL32.32]
84 LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
86 if(SHELL_OsIsUnicode())
87 return PathAddBackslashW(lpszPath);
88 return PathAddBackslashA(lpszPath);
91 /*************************************************************************
92 * PathBuildRoot [SHELL32.30]
94 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
96 if(SHELL_OsIsUnicode())
97 return PathBuildRootW(lpszPath, drive);
98 return PathBuildRootA(lpszPath, drive);
102 Extracting Component Parts
105 /*************************************************************************
106 * PathFindFileName [SHELL32.34]
108 LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
110 if(SHELL_OsIsUnicode())
111 return PathFindFileNameW(lpszPath);
112 return PathFindFileNameA(lpszPath);
115 /*************************************************************************
116 * PathFindExtension [SHELL32.31]
118 LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
120 if (SHELL_OsIsUnicode())
121 return PathFindExtensionW(lpszPath);
122 return PathFindExtensionA(lpszPath);
126 /*************************************************************************
127 * PathGetExtensionA [internal]
130 * exported by ordinal
131 * return value points to the first char after the dot
133 static LPSTR PathGetExtensionA(LPCSTR lpszPath)
135 TRACE("(%s)\n",lpszPath);
137 lpszPath = PathFindExtensionA(lpszPath);
138 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
141 /*************************************************************************
142 * PathGetExtensionW [internal]
144 static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
146 TRACE("(%s)\n",debugstr_w(lpszPath));
148 lpszPath = PathFindExtensionW(lpszPath);
149 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
152 /*************************************************************************
153 * PathGetExtension [SHELL32.158]
155 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath,DWORD void1, DWORD void2)
157 if (SHELL_OsIsUnicode())
158 return PathGetExtensionW(lpszPath);
159 return PathGetExtensionA(lpszPath);
162 /*************************************************************************
163 * PathGetArgs [SHELL32.52]
165 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
167 if (SHELL_OsIsUnicode())
168 return PathGetArgsW(lpszPath);
169 return PathGetArgsA(lpszPath);
172 /*************************************************************************
173 * PathGetDriveNumber [SHELL32.57]
175 int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
177 if (SHELL_OsIsUnicode())
178 return PathGetDriveNumberW(lpszPath);
179 return PathGetDriveNumberA(lpszPath);
182 /*************************************************************************
183 * PathRemoveFileSpec [SHELL32.35]
185 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
187 if (SHELL_OsIsUnicode())
188 return PathRemoveFileSpecW(lpszPath);
189 return PathRemoveFileSpecA(lpszPath);
192 /*************************************************************************
193 * PathStripPath [SHELL32.38]
195 void WINAPI PathStripPathAW(LPVOID lpszPath)
197 if (SHELL_OsIsUnicode())
198 PathStripPathW(lpszPath);
200 PathStripPathA(lpszPath);
203 /*************************************************************************
204 * PathStripToRoot [SHELL32.50]
206 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
208 if (SHELL_OsIsUnicode())
209 return PathStripToRootW(lpszPath);
210 return PathStripToRootA(lpszPath);
213 /*************************************************************************
214 * PathRemoveArgs [SHELL32.251]
216 void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
218 if (SHELL_OsIsUnicode())
219 PathRemoveArgsW(lpszPath);
221 PathRemoveArgsA(lpszPath);
224 /*************************************************************************
225 * PathRemoveExtension [SHELL32.250]
227 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
229 if (SHELL_OsIsUnicode())
230 PathRemoveExtensionW(lpszPath);
232 PathRemoveExtensionA(lpszPath);
240 /*************************************************************************
241 * PathGetShortPathA [internal]
243 static void PathGetShortPathA(LPSTR pszPath)
247 TRACE("%s\n", pszPath);
249 if (GetShortPathNameA(pszPath, path, MAX_PATH))
251 lstrcpyA(pszPath, path);
255 /*************************************************************************
256 * PathGetShortPathW [internal]
258 static void PathGetShortPathW(LPWSTR pszPath)
260 WCHAR path[MAX_PATH];
262 TRACE("%s\n", debugstr_w(pszPath));
264 if (GetShortPathNameW(pszPath, path, MAX_PATH))
266 lstrcpyW(pszPath, path);
270 /*************************************************************************
271 * PathGetShortPath [SHELL32.92]
273 VOID WINAPI PathGetShortPathAW(LPVOID pszPath)
275 if(SHELL_OsIsUnicode())
276 PathGetShortPathW(pszPath);
277 PathGetShortPathA(pszPath);
280 /*************************************************************************
281 * PathRemoveBlanks [SHELL32.33]
283 void WINAPI PathRemoveBlanksAW(LPVOID str)
285 if(SHELL_OsIsUnicode())
286 PathRemoveBlanksW(str);
288 PathRemoveBlanksA(str);
291 /*************************************************************************
292 * PathQuoteSpaces [SHELL32.55]
294 VOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
296 if(SHELL_OsIsUnicode())
297 PathQuoteSpacesW(lpszPath);
299 PathQuoteSpacesA(lpszPath);
302 /*************************************************************************
303 * PathUnquoteSpaces [SHELL32.56]
305 VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
307 if(SHELL_OsIsUnicode())
308 PathUnquoteSpacesW(str);
310 PathUnquoteSpacesA(str);
313 /*************************************************************************
314 * PathParseIconLocation [SHELL32.249]
316 int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
318 if(SHELL_OsIsUnicode())
319 return PathParseIconLocationW(lpszPath);
320 return PathParseIconLocationA(lpszPath);
324 ########## Path Testing ##########
326 /*************************************************************************
327 * PathIsUNC [SHELL32.39]
329 BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
331 if (SHELL_OsIsUnicode())
332 return PathIsUNCW( lpszPath );
333 return PathIsUNCA( lpszPath );
336 /*************************************************************************
337 * PathIsRelative [SHELL32.40]
339 BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
341 if (SHELL_OsIsUnicode())
342 return PathIsRelativeW( lpszPath );
343 return PathIsRelativeA( lpszPath );
346 /*************************************************************************
347 * PathIsRoot [SHELL32.29]
349 BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
351 if (SHELL_OsIsUnicode())
352 return PathIsRootW(lpszPath);
353 return PathIsRootA(lpszPath);
356 /*************************************************************************
357 * PathIsExeA [internal]
359 static BOOL PathIsExeA (LPCSTR lpszPath)
361 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
363 static const char * const lpszExtensions[] =
364 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
366 TRACE("path=%s\n",lpszPath);
368 for(i=0; lpszExtensions[i]; i++)
369 if (!lstrcmpiA(lpszExtension,lpszExtensions[i])) return TRUE;
374 /*************************************************************************
375 * PathIsExeW [internal]
377 static BOOL PathIsExeW (LPCWSTR lpszPath)
379 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
381 static const WCHAR lpszExtensions[][4] =
382 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
383 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
384 {'s','c','r','\0'}, {'\0'} };
386 TRACE("path=%s\n",debugstr_w(lpszPath));
388 for(i=0; lpszExtensions[i][0]; i++)
389 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
394 /*************************************************************************
395 * PathIsExe [SHELL32.43]
397 BOOL WINAPI PathIsExeAW (LPCVOID path)
399 if (SHELL_OsIsUnicode())
400 return PathIsExeW (path);
401 return PathIsExeA(path);
404 /*************************************************************************
405 * PathIsDirectory [SHELL32.159]
407 BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
409 if (SHELL_OsIsUnicode())
410 return PathIsDirectoryW (lpszPath);
411 return PathIsDirectoryA (lpszPath);
414 /*************************************************************************
415 * PathFileExists [SHELL32.45]
417 BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
419 if (SHELL_OsIsUnicode())
420 return PathFileExistsW (lpszPath);
421 return PathFileExistsA (lpszPath);
424 /*************************************************************************
425 * PathMatchSpec [SHELL32.46]
427 BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
429 if (SHELL_OsIsUnicode())
430 return PathMatchSpecW( name, mask );
431 return PathMatchSpecA( name, mask );
434 /*************************************************************************
435 * PathIsSameRoot [SHELL32.650]
437 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
439 if (SHELL_OsIsUnicode())
440 return PathIsSameRootW(lpszPath1, lpszPath2);
441 return PathIsSameRootA(lpszPath1, lpszPath2);
444 /*************************************************************************
445 * IsLFNDriveA [SHELL32.41]
447 BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
451 if (!GetVolumeInformationA(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
456 /*************************************************************************
457 * IsLFNDriveW [SHELL32.42]
459 BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
463 if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
468 /*************************************************************************
469 * IsLFNDrive [SHELL32.119]
471 BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath)
473 if (SHELL_OsIsUnicode())
474 return IsLFNDriveW(lpszPath);
475 return IsLFNDriveA(lpszPath);
479 ########## Creating Something Unique ##########
481 /*************************************************************************
482 * PathMakeUniqueNameA [internal]
484 BOOL WINAPI PathMakeUniqueNameA(
487 LPCSTR lpszShortName,
491 FIXME("%p %u %s %s %s stub\n",
492 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
493 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
497 /*************************************************************************
498 * PathMakeUniqueNameW [internal]
500 BOOL WINAPI PathMakeUniqueNameW(
503 LPCWSTR lpszShortName,
504 LPCWSTR lpszLongName,
505 LPCWSTR lpszPathName)
507 FIXME("%p %u %s %s %s stub\n",
508 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
509 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
513 /*************************************************************************
514 * PathMakeUniqueName [SHELL32.47]
516 BOOL WINAPI PathMakeUniqueNameAW(
519 LPCVOID lpszShortName,
520 LPCVOID lpszLongName,
521 LPCVOID lpszPathName)
523 if (SHELL_OsIsUnicode())
524 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
525 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
528 /*************************************************************************
529 * PathYetAnotherMakeUniqueName [SHELL32.75]
532 * exported by ordinal
534 BOOL WINAPI PathYetAnotherMakeUniqueName(
536 LPCWSTR lpszPathName,
537 LPCWSTR lpszShortName,
538 LPCWSTR lpszLongName)
540 FIXME("(%p, %s, %s ,%s):stub.\n",
541 lpszBuffer, debugstr_w(lpszPathName), debugstr_w(lpszShortName), debugstr_w(lpszLongName));
547 ########## cleaning and resolving paths ##########
550 /*************************************************************************
551 * PathFindOnPath [SHELL32.145]
553 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID *sOtherDirs)
555 if (SHELL_OsIsUnicode())
556 return PathFindOnPathW(sFile, (LPCWSTR *)sOtherDirs);
557 return PathFindOnPathA(sFile, (LPCSTR *)sOtherDirs);
560 /*************************************************************************
561 * PathCleanupSpec [SHELL32.171]
563 * lpszFile is changed in place.
565 int WINAPI PathCleanupSpec( LPCWSTR lpszPathW, LPWSTR lpszFileW )
571 if (SHELL_OsIsUnicode())
573 LPWSTR p = lpszFileW;
575 TRACE("Cleanup %s\n",debugstr_w(lpszFileW));
578 length = strlenW(lpszPathW);
582 int gct = PathGetCharTypeW(*p);
583 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
586 rc |= PCS_REPLACEDCHAR;
592 if (length + i == MAX_PATH)
594 rc |= PCS_FATAL | PCS_PATHTOOLONG;
602 LPSTR lpszFileA = (LPSTR)lpszFileW;
603 LPCSTR lpszPathA = (LPCSTR)lpszPathW;
606 TRACE("Cleanup %s\n",debugstr_a(lpszFileA));
609 length = strlen(lpszPathA);
613 int gct = PathGetCharTypeA(*p);
614 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
617 rc |= PCS_REPLACEDCHAR;
623 if (length + i == MAX_PATH)
625 rc |= PCS_FATAL | PCS_PATHTOOLONG;
634 /*************************************************************************
635 * PathQualifyA [SHELL32]
637 BOOL WINAPI PathQualifyA(LPCSTR pszPath)
639 FIXME("%s\n",pszPath);
643 /*************************************************************************
644 * PathQualifyW [SHELL32]
646 BOOL WINAPI PathQualifyW(LPCWSTR pszPath)
648 FIXME("%s\n",debugstr_w(pszPath));
652 /*************************************************************************
653 * PathQualify [SHELL32.49]
655 BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
657 if (SHELL_OsIsUnicode())
658 return PathQualifyW(pszPath);
659 return PathQualifyA(pszPath);
662 /*************************************************************************
663 * PathResolveA [SHELL32.51]
665 BOOL WINAPI PathResolveA(
670 FIXME("(%s,%p,0x%08x),stub!\n",
671 lpszPath, *alpszPaths, dwFlags);
675 /*************************************************************************
676 * PathResolveW [SHELL32]
678 BOOL WINAPI PathResolveW(
683 FIXME("(%s,%p,0x%08x),stub!\n",
684 debugstr_w(lpszPath), debugstr_w(*alpszPaths), dwFlags);
688 /*************************************************************************
689 * PathResolve [SHELL32.51]
691 BOOL WINAPI PathResolveAW(
696 if (SHELL_OsIsUnicode())
697 return PathResolveW(lpszPath, (LPCWSTR*)alpszPaths, dwFlags);
698 return PathResolveA(lpszPath, (LPCSTR*)alpszPaths, dwFlags);
701 /*************************************************************************
702 * PathProcessCommandA [SHELL32.653]
704 LONG WINAPI PathProcessCommandA (
710 FIXME("%s %p 0x%04x 0x%04x stub\n",
711 lpszPath, lpszBuff, dwBuffSize, dwFlags);
712 if(!lpszPath) return -1;
713 if(lpszBuff) strcpy(lpszBuff, lpszPath);
714 return strlen(lpszPath);
717 /*************************************************************************
718 * PathProcessCommandW
720 LONG WINAPI PathProcessCommandW (
726 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
727 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
728 if(!lpszPath) return -1;
729 if(lpszBuff) strcpyW(lpszBuff, lpszPath);
730 return strlenW(lpszPath);
733 /*************************************************************************
734 * PathProcessCommand (SHELL32.653)
736 LONG WINAPI PathProcessCommandAW (
742 if (SHELL_OsIsUnicode())
743 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
744 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
748 ########## special ##########
751 /*************************************************************************
752 * PathSetDlgItemPath (SHELL32.48)
754 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
756 if (SHELL_OsIsUnicode())
757 PathSetDlgItemPathW(hDlg, id, pszPath);
759 PathSetDlgItemPathA(hDlg, id, pszPath);
762 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'};
763 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'};
764 static const WCHAR AppDataW[] = {'A','p','p','D','a','t','a','\0'};
765 static const WCHAR CacheW[] = {'C','a','c','h','e','\0'};
766 static const WCHAR CD_BurningW[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
767 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'};
768 static const WCHAR Common_AppDataW[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
769 static const WCHAR Common_DesktopW[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
770 static const WCHAR Common_DocumentsW[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
771 static const WCHAR CommonFilesDirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
772 static const WCHAR CommonMusicW[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
773 static const WCHAR CommonPicturesW[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
774 static const WCHAR Common_ProgramsW[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
775 static const WCHAR Common_StartUpW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
776 static const WCHAR Common_Start_MenuW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
777 static const WCHAR Common_TemplatesW[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
778 static const WCHAR CommonVideoW[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
779 static const WCHAR CookiesW[] = {'C','o','o','k','i','e','s','\0'};
780 static const WCHAR DesktopW[] = {'D','e','s','k','t','o','p','\0'};
781 static const WCHAR FavoritesW[] = {'F','a','v','o','r','i','t','e','s','\0'};
782 static const WCHAR FontsW[] = {'F','o','n','t','s','\0'};
783 static const WCHAR HistoryW[] = {'H','i','s','t','o','r','y','\0'};
784 static const WCHAR Local_AppDataW[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
785 static const WCHAR My_MusicW[] = {'M','y',' ','M','u','s','i','c','\0'};
786 static const WCHAR My_PicturesW[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
787 static const WCHAR My_VideoW[] = {'M','y',' ','V','i','d','e','o','s','\0'};
788 static const WCHAR NetHoodW[] = {'N','e','t','H','o','o','d','\0'};
789 static const WCHAR PersonalW[] = {'P','e','r','s','o','n','a','l','\0'};
790 static const WCHAR PrintHoodW[] = {'P','r','i','n','t','H','o','o','d','\0'};
791 static const WCHAR ProgramFilesDirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
792 static const WCHAR ProgramsW[] = {'P','r','o','g','r','a','m','s','\0'};
793 static const WCHAR RecentW[] = {'R','e','c','e','n','t','\0'};
794 static const WCHAR ResourcesW[] = {'R','e','s','o','u','r','c','e','s','\0'};
795 static const WCHAR SendToW[] = {'S','e','n','d','T','o','\0'};
796 static const WCHAR StartUpW[] = {'S','t','a','r','t','U','p','\0'};
797 static const WCHAR Start_MenuW[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
798 static const WCHAR TemplatesW[] = {'T','e','m','p','l','a','t','e','s','\0'};
799 static const WCHAR DefaultW[] = {'.','D','e','f','a','u','l','t','\0'};
800 static const WCHAR AllUsersProfileW[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
801 static const WCHAR UserProfileW[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
802 static const WCHAR SystemDriveW[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
803 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};
804 static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
805 static const WCHAR AllUsersProfileValueW[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
806 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'};
807 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'};
808 /* This defaults to L"Documents and Settings" on Windows 2000/XP, but we're
809 * acting more Windows 9x-like for now.
811 static const WCHAR szDefaultProfileDirW[] = {'p','r','o','f','i','l','e','s','\0'};
812 static const WCHAR AllUsersW[] = {'A','l','l',' ','U','s','e','r','s','\0'};
814 typedef enum _CSIDL_Type {
818 CSIDL_Type_Disallowed,
819 CSIDL_Type_NonExistent,
820 CSIDL_Type_WindowsPath,
821 CSIDL_Type_SystemPath,
828 LPCWSTR szDefaultPath; /* fallback string or resource ID */
831 static const CSIDL_DATA CSIDL_Data[] =
833 { /* 0x00 - CSIDL_DESKTOP */
836 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
838 { /* 0x01 - CSIDL_INTERNET */
839 CSIDL_Type_Disallowed,
843 { /* 0x02 - CSIDL_PROGRAMS */
846 MAKEINTRESOURCEW(IDS_PROGRAMS)
848 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
849 CSIDL_Type_SystemPath,
853 { /* 0x04 - CSIDL_PRINTERS */
854 CSIDL_Type_SystemPath,
858 { /* 0x05 - CSIDL_PERSONAL */
861 MAKEINTRESOURCEW(IDS_PERSONAL)
863 { /* 0x06 - CSIDL_FAVORITES */
866 MAKEINTRESOURCEW(IDS_FAVORITES)
868 { /* 0x07 - CSIDL_STARTUP */
871 MAKEINTRESOURCEW(IDS_STARTUP)
873 { /* 0x08 - CSIDL_RECENT */
876 MAKEINTRESOURCEW(IDS_RECENT)
878 { /* 0x09 - CSIDL_SENDTO */
881 MAKEINTRESOURCEW(IDS_SENDTO)
883 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
884 CSIDL_Type_Disallowed,
888 { /* 0x0b - CSIDL_STARTMENU */
891 MAKEINTRESOURCEW(IDS_STARTMENU)
893 { /* 0x0c - CSIDL_MYDOCUMENTS */
894 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
898 { /* 0x0d - CSIDL_MYMUSIC */
901 MAKEINTRESOURCEW(IDS_MYMUSIC)
903 { /* 0x0e - CSIDL_MYVIDEO */
906 MAKEINTRESOURCEW(IDS_MYVIDEO)
908 { /* 0x0f - unassigned */
909 CSIDL_Type_Disallowed,
913 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
916 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
918 { /* 0x11 - CSIDL_DRIVES */
919 CSIDL_Type_Disallowed,
923 { /* 0x12 - CSIDL_NETWORK */
924 CSIDL_Type_Disallowed,
928 { /* 0x13 - CSIDL_NETHOOD */
931 MAKEINTRESOURCEW(IDS_NETHOOD)
933 { /* 0x14 - CSIDL_FONTS */
934 CSIDL_Type_WindowsPath,
938 { /* 0x15 - CSIDL_TEMPLATES */
941 MAKEINTRESOURCEW(IDS_TEMPLATES)
943 { /* 0x16 - CSIDL_COMMON_STARTMENU */
946 MAKEINTRESOURCEW(IDS_STARTMENU)
948 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
951 MAKEINTRESOURCEW(IDS_PROGRAMS)
953 { /* 0x18 - CSIDL_COMMON_STARTUP */
956 MAKEINTRESOURCEW(IDS_STARTUP)
958 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
961 MAKEINTRESOURCEW(IDS_DESKTOP)
963 { /* 0x1a - CSIDL_APPDATA */
966 MAKEINTRESOURCEW(IDS_APPDATA)
968 { /* 0x1b - CSIDL_PRINTHOOD */
971 MAKEINTRESOURCEW(IDS_PRINTHOOD)
973 { /* 0x1c - CSIDL_LOCAL_APPDATA */
976 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA)
978 { /* 0x1d - CSIDL_ALTSTARTUP */
979 CSIDL_Type_NonExistent,
983 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
984 CSIDL_Type_NonExistent,
988 { /* 0x1f - CSIDL_COMMON_FAVORITES */
991 MAKEINTRESOURCEW(IDS_FAVORITES)
993 { /* 0x20 - CSIDL_INTERNET_CACHE */
996 MAKEINTRESOURCEW(IDS_INTERNET_CACHE)
998 { /* 0x21 - CSIDL_COOKIES */
1001 MAKEINTRESOURCEW(IDS_COOKIES)
1003 { /* 0x22 - CSIDL_HISTORY */
1006 MAKEINTRESOURCEW(IDS_HISTORY)
1008 { /* 0x23 - CSIDL_COMMON_APPDATA */
1009 CSIDL_Type_AllUsers,
1011 MAKEINTRESOURCEW(IDS_APPDATA)
1013 { /* 0x24 - CSIDL_WINDOWS */
1014 CSIDL_Type_WindowsPath,
1018 { /* 0x25 - CSIDL_SYSTEM */
1019 CSIDL_Type_SystemPath,
1023 { /* 0x26 - CSIDL_PROGRAM_FILES */
1026 MAKEINTRESOURCEW(IDS_PROGRAM_FILES)
1028 { /* 0x27 - CSIDL_MYPICTURES */
1031 MAKEINTRESOURCEW(IDS_MYPICTURES)
1033 { /* 0x28 - CSIDL_PROFILE */
1038 { /* 0x29 - CSIDL_SYSTEMX86 */
1039 CSIDL_Type_NonExistent,
1043 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1044 CSIDL_Type_NonExistent,
1048 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1051 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON)
1053 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1054 CSIDL_Type_NonExistent,
1058 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1059 CSIDL_Type_AllUsers,
1061 MAKEINTRESOURCEW(IDS_TEMPLATES)
1063 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1064 CSIDL_Type_AllUsers,
1066 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS)
1068 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1069 CSIDL_Type_AllUsers,
1070 Common_Administrative_ToolsW,
1071 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1073 { /* 0x30 - CSIDL_ADMINTOOLS */
1075 Administrative_ToolsW,
1076 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1078 { /* 0x31 - CSIDL_CONNECTIONS */
1079 CSIDL_Type_Disallowed,
1083 { /* 0x32 - unassigned */
1084 CSIDL_Type_Disallowed,
1088 { /* 0x33 - unassigned */
1089 CSIDL_Type_Disallowed,
1093 { /* 0x34 - unassigned */
1094 CSIDL_Type_Disallowed,
1098 { /* 0x35 - CSIDL_COMMON_MUSIC */
1099 CSIDL_Type_AllUsers,
1101 MAKEINTRESOURCEW(IDS_COMMON_MUSIC)
1103 { /* 0x36 - CSIDL_COMMON_PICTURES */
1104 CSIDL_Type_AllUsers,
1106 MAKEINTRESOURCEW(IDS_COMMON_PICTURES)
1108 { /* 0x37 - CSIDL_COMMON_VIDEO */
1109 CSIDL_Type_AllUsers,
1111 MAKEINTRESOURCEW(IDS_COMMON_VIDEO)
1113 { /* 0x38 - CSIDL_RESOURCES */
1114 CSIDL_Type_WindowsPath,
1118 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1119 CSIDL_Type_NonExistent,
1123 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1124 CSIDL_Type_NonExistent,
1128 { /* 0x3b - CSIDL_CDBURN_AREA */
1131 MAKEINTRESOURCEW(IDS_CDBURN_AREA)
1133 { /* 0x3c unassigned */
1134 CSIDL_Type_Disallowed,
1138 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1139 CSIDL_Type_Disallowed, /* FIXME */
1143 { /* 0x3e - CSIDL_PROFILES */
1144 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
1150 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
1152 /* Gets the value named value from the registry key
1153 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1154 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1155 * is assumed to be MAX_PATH WCHARs in length.
1156 * If it exists, expands the value and writes the expanded value to
1157 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1158 * Returns successful error code if the value was retrieved from the registry,
1159 * and a failure otherwise.
1161 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
1162 LPCWSTR value, LPWSTR path)
1165 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
1166 LPCWSTR pShellFolderPath, pUserShellFolderPath;
1167 DWORD dwType, dwPathLen = MAX_PATH;
1168 HKEY userShellFolderKey, shellFolderKey;
1170 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
1175 strcpyW(shellFolderPath, userPrefix);
1176 PathAddBackslashW(shellFolderPath);
1177 strcatW(shellFolderPath, szSHFolders);
1178 pShellFolderPath = shellFolderPath;
1179 strcpyW(userShellFolderPath, userPrefix);
1180 PathAddBackslashW(userShellFolderPath);
1181 strcatW(userShellFolderPath, szSHUserFolders);
1182 pUserShellFolderPath = userShellFolderPath;
1186 pUserShellFolderPath = szSHUserFolders;
1187 pShellFolderPath = szSHFolders;
1190 if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey))
1192 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
1195 if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey))
1197 TRACE("Failed to create %s\n",
1198 debugstr_w(pUserShellFolderPath));
1199 RegCloseKey(shellFolderKey);
1203 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
1204 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
1208 path[dwPathLen / sizeof(WCHAR)] = '\0';
1209 if (dwType == REG_EXPAND_SZ && path[0] == '%')
1211 WCHAR szTemp[MAX_PATH];
1213 _SHExpandEnvironmentStrings(path, szTemp);
1214 lstrcpynW(path, szTemp, MAX_PATH);
1216 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
1217 (strlenW(path) + 1) * sizeof(WCHAR));
1218 if (ret != ERROR_SUCCESS)
1219 hr = HRESULT_FROM_WIN32(ret);
1225 RegCloseKey(shellFolderKey);
1226 RegCloseKey(userShellFolderKey);
1227 TRACE("returning 0x%08x\n", hr);
1231 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1232 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1233 * - The entry's szDefaultPath may be either a string value or an integer
1234 * resource identifier. In the latter case, the string value of the resource
1236 * - Depending on the entry's type, the path may begin with an (unexpanded)
1237 * environment variable name. The caller is responsible for expanding
1238 * environment strings if so desired.
1239 * The types that are prepended with environment variables are:
1240 * CSIDL_Type_User: %USERPROFILE%
1241 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1242 * CSIDL_Type_CurrVer: %SystemDrive%
1243 * (Others might make sense too, but as yet are unneeded.)
1245 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
1248 WCHAR resourcePath[MAX_PATH];
1249 LPCWSTR pDefaultPath = NULL;
1251 TRACE("0x%02x,%p\n", folder, pszPath);
1253 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1254 return E_INVALIDARG;
1256 return E_INVALIDARG;
1258 if (CSIDL_Data[folder].szDefaultPath &&
1259 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
1261 if (LoadStringW(shell32_hInstance,
1262 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
1265 pDefaultPath = resourcePath;
1269 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
1270 debugstr_w(pszPath));
1277 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
1281 switch (CSIDL_Data[folder].type)
1283 case CSIDL_Type_User:
1284 strcpyW(pszPath, UserProfileW);
1286 case CSIDL_Type_AllUsers:
1287 strcpyW(pszPath, AllUsersProfileW);
1289 case CSIDL_Type_CurrVer:
1290 strcpyW(pszPath, SystemDriveW);
1293 ; /* no corresponding env. var, do nothing */
1297 PathAddBackslashW(pszPath);
1298 strcatW(pszPath, pDefaultPath);
1301 TRACE("returning 0x%08x\n", hr);
1305 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1306 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1307 * can be overridden in the HKLM\\szCurrentVersion key.
1308 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1309 * the registry, uses _SHGetDefaultValue to get the value.
1311 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
1316 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1318 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1319 return E_INVALIDARG;
1320 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
1321 return E_INVALIDARG;
1323 return E_INVALIDARG;
1325 if (dwFlags & SHGFP_TYPE_DEFAULT)
1326 hr = _SHGetDefaultValue(folder, pszPath);
1331 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
1335 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
1337 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
1338 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
1339 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
1341 hr = _SHGetDefaultValue(folder, pszPath);
1342 dwType = REG_EXPAND_SZ;
1343 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
1344 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
1348 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
1354 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1358 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1359 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1360 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1361 * - if hToken is -1, looks in HKEY_USERS\.Default
1362 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1363 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1364 * calls _SHGetDefaultValue for it.
1366 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
1371 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
1373 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1374 return E_INVALIDARG;
1375 if (CSIDL_Data[folder].type != CSIDL_Type_User)
1376 return E_INVALIDARG;
1378 return E_INVALIDARG;
1380 /* Only the current user and the default user are supported right now
1382 * FIXME: should be able to call GetTokenInformation on the token,
1383 * then call ConvertSidToStringSidW on it to get the user prefix.
1384 * But Wine's registry doesn't store user info by sid, it stores it
1385 * by user name (and I don't know how to convert from a token to a
1388 if (hToken != NULL && hToken != (HANDLE)-1)
1390 FIXME("unsupported for user other than current or default\n");
1394 if (dwFlags & SHGFP_TYPE_DEFAULT)
1395 hr = _SHGetDefaultValue(folder, pszPath);
1398 LPCWSTR userPrefix = NULL;
1401 if (hToken == (HANDLE)-1)
1403 hRootKey = HKEY_USERS;
1404 userPrefix = DefaultW;
1406 else /* hToken == NULL, other values disallowed above */
1407 hRootKey = HKEY_CURRENT_USER;
1408 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix,
1409 CSIDL_Data[folder].szValueName, pszPath);
1410 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
1411 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1412 CSIDL_Data[folder].szValueName, pszPath);
1414 hr = _SHGetDefaultValue(folder, pszPath);
1416 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1420 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1421 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1422 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1423 * If this fails, falls back to _SHGetDefaultValue.
1425 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
1430 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1432 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1433 return E_INVALIDARG;
1434 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
1435 return E_INVALIDARG;
1437 return E_INVALIDARG;
1439 if (dwFlags & SHGFP_TYPE_DEFAULT)
1440 hr = _SHGetDefaultValue(folder, pszPath);
1443 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1444 CSIDL_Data[folder].szValueName, pszPath);
1446 hr = _SHGetDefaultValue(folder, pszPath);
1448 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1452 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
1457 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
1458 KEY_ALL_ACCESS, NULL, pKey, &disp);
1459 return HRESULT_FROM_WIN32(lRet);
1462 /* Reads the value named szValueName from the key profilesKey (assumed to be
1463 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1464 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1465 * szDefault to the registry).
1467 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
1468 LPWSTR szValue, LPCWSTR szDefault)
1471 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
1474 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
1475 debugstr_w(szDefault));
1476 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
1477 (LPBYTE)szValue, &dwPathLen);
1478 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
1481 dwPathLen /= sizeof(WCHAR);
1482 szValue[dwPathLen] = '\0';
1487 /* Missing or invalid value, set a default */
1488 lstrcpynW(szValue, szDefault, MAX_PATH);
1489 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
1490 debugstr_w(szValue));
1491 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
1493 (strlenW(szValue) + 1) * sizeof(WCHAR));
1495 hr = HRESULT_FROM_WIN32(lRet);
1499 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
1503 /* Attempts to expand environment variables from szSrc into szDest, which is
1504 * assumed to be MAX_PATH characters in length. Before referring to the
1505 * environment, handles a few variables directly, because the environment
1506 * variables may not be set when this is called (as during Wine's installation
1507 * when default values are being written to the registry).
1508 * The directly handled environment variables, and their source, are:
1509 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1510 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1512 * If one of the directly handled environment variables is expanded, only
1513 * expands a single variable, and only in the beginning of szSrc.
1515 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
1518 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
1521 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
1523 if (!szSrc || !szDest) return E_INVALIDARG;
1525 /* short-circuit if there's nothing to expand */
1526 if (szSrc[0] != '%')
1528 strcpyW(szDest, szSrc);
1532 /* Get the profile prefix, we'll probably be needing it */
1533 hr = _SHOpenProfilesKey(&key);
1536 WCHAR szDefaultProfilesPrefix[MAX_PATH];
1538 GetWindowsDirectoryW(szDefaultProfilesPrefix, MAX_PATH);
1539 PathAddBackslashW(szDefaultProfilesPrefix);
1540 PathAppendW(szDefaultProfilesPrefix, szDefaultProfileDirW);
1541 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix,
1542 szDefaultProfilesPrefix);
1546 strcpyW(szTemp, szSrc);
1547 while (SUCCEEDED(hr) && szTemp[0] == '%')
1549 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
1551 WCHAR szAllUsers[MAX_PATH];
1553 strcpyW(szDest, szProfilesPrefix);
1554 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
1555 szAllUsers, AllUsersW);
1556 PathAppendW(szDest, szAllUsers);
1557 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
1559 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
1561 WCHAR userName[MAX_PATH];
1562 DWORD userLen = MAX_PATH;
1564 strcpyW(szDest, szProfilesPrefix);
1565 GetUserNameW(userName, &userLen);
1566 PathAppendW(szDest, userName);
1567 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
1569 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
1571 GetSystemDirectoryW(szDest, MAX_PATH);
1572 if (szDest[1] != ':')
1574 FIXME("non-drive system paths unsupported\n");
1579 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
1585 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
1588 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1590 hr = HRESULT_FROM_WIN32(GetLastError());
1594 if (SUCCEEDED(hr) && szDest[0] == '%')
1595 strcpyW(szTemp, szDest);
1598 /* terminate loop */
1605 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
1606 debugstr_w(szSrc), debugstr_w(szDest));
1610 /*************************************************************************
1611 * SHGetFolderPathW [SHELL32.@]
1613 * Convert nFolder to path.
1617 * Failure: standard HRESULT error codes.
1620 * Most values can be overridden in either
1621 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1622 * or in the same location in HKLM.
1623 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1624 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1625 * changes made to it are made to the former key too. This synchronization is
1626 * done on-demand: not until someone requests the value of one of these paths
1627 * (by calling one of the SHGet functions) is the value synchronized.
1628 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1630 HRESULT WINAPI SHGetFolderPathW(
1631 HWND hwndOwner, /* [I] owner window */
1632 int nFolder, /* [I] CSIDL identifying the folder */
1633 HANDLE hToken, /* [I] access token */
1634 DWORD dwFlags, /* [I] which path to return */
1635 LPWSTR pszPath) /* [O] converted path */
1638 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
1639 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
1643 TRACE("%p,%p,nFolder=0x%04x\n", hwndOwner,pszPath,nFolder);
1645 /* Windows always NULL-terminates the resulting path regardless of success
1646 * or failure, so do so first
1650 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1651 return E_INVALIDARG;
1653 type = CSIDL_Data[folder].type;
1656 case CSIDL_Type_Disallowed:
1659 case CSIDL_Type_NonExistent:
1662 case CSIDL_Type_WindowsPath:
1663 GetWindowsDirectoryW(szTemp, MAX_PATH);
1664 if (CSIDL_Data[folder].szDefaultPath &&
1665 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1666 *CSIDL_Data[folder].szDefaultPath)
1668 PathAddBackslashW(szTemp);
1669 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1673 case CSIDL_Type_SystemPath:
1674 GetSystemDirectoryW(szTemp, MAX_PATH);
1675 if (CSIDL_Data[folder].szDefaultPath &&
1676 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1677 *CSIDL_Data[folder].szDefaultPath)
1679 PathAddBackslashW(szTemp);
1680 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1684 case CSIDL_Type_CurrVer:
1685 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
1687 case CSIDL_Type_User:
1688 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
1690 case CSIDL_Type_AllUsers:
1691 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
1694 FIXME("bogus type %d, please fix\n", type);
1699 /* Expand environment strings if necessary */
1701 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
1703 strcpyW(szBuildPath, szTemp);
1704 /* Copy the path if it's available before we might return */
1705 if (SUCCEEDED(hr) && pszPath)
1706 strcpyW(pszPath, szBuildPath);
1708 if (FAILED(hr)) goto end;
1710 /* if we don't care about existing directories we are ready */
1711 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
1713 if (PathFileExistsW(szBuildPath)) goto end;
1715 /* not existing but we are not allowed to create it. The return value
1716 * is verified against shell32 version 6.0.
1718 if (!(nFolder & CSIDL_FLAG_CREATE))
1720 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1724 /* create directory/directories */
1725 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
1726 if (ret && ret != ERROR_ALREADY_EXISTS)
1728 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
1733 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
1735 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
1739 /*************************************************************************
1740 * SHGetFolderPathA [SHELL32.@]
1742 * See SHGetFolderPathW.
1744 HRESULT WINAPI SHGetFolderPathA(
1751 WCHAR szTemp[MAX_PATH];
1754 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
1758 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
1759 if (SUCCEEDED(hr) && pszPath)
1760 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
1766 /* For each folder in folders, if its value has not been set in the registry,
1767 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1768 * folder's type) to get the unexpanded value first.
1769 * Writes the unexpanded value to User Shell Folders, and queries it with
1770 * SHGetFolderPathW to force the creation of the directory if it doesn't
1771 * already exist. SHGetFolderPathW also returns the expanded value, which
1772 * this then writes to Shell Folders.
1774 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
1775 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
1779 WCHAR path[MAX_PATH];
1781 HKEY hUserKey = NULL, hKey = NULL;
1782 DWORD dwType, dwPathLen;
1785 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
1786 debugstr_w(szUserShellFolderPath), folders, foldersLen);
1788 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
1790 hr = HRESULT_FROM_WIN32(ret);
1793 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
1795 hr = HRESULT_FROM_WIN32(ret);
1797 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
1799 dwPathLen = MAX_PATH * sizeof(WCHAR);
1800 if (RegQueryValueExW(hUserKey, CSIDL_Data[folders[i]].szValueName, NULL,
1801 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
1802 dwType != REG_EXPAND_SZ))
1805 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
1806 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
1808 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
1809 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
1810 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
1811 GetWindowsDirectoryW(path, MAX_PATH);
1816 ret = RegSetValueExW(hUserKey,
1817 CSIDL_Data[folders[i]].szValueName, 0, REG_EXPAND_SZ,
1818 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1820 hr = HRESULT_FROM_WIN32(ret);
1823 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
1824 hToken, SHGFP_TYPE_DEFAULT, path);
1825 ret = RegSetValueExW(hKey,
1826 CSIDL_Data[folders[i]].szValueName, 0, REG_SZ,
1827 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1829 hr = HRESULT_FROM_WIN32(ret);
1835 RegCloseKey(hUserKey);
1839 TRACE("returning 0x%08x\n", hr);
1843 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
1845 static const UINT folders[] = {
1856 CSIDL_DESKTOPDIRECTORY,
1860 CSIDL_LOCAL_APPDATA,
1861 CSIDL_INTERNET_CACHE,
1867 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
1868 LPCWSTR pUserShellFolderPath, pShellFolderPath;
1873 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
1876 hToken = (HANDLE)-1;
1877 hRootKey = HKEY_USERS;
1878 strcpyW(userShellFolderPath, DefaultW);
1879 PathAddBackslashW(userShellFolderPath);
1880 strcatW(userShellFolderPath, szSHUserFolders);
1881 pUserShellFolderPath = userShellFolderPath;
1882 strcpyW(shellFolderPath, DefaultW);
1883 PathAddBackslashW(shellFolderPath);
1884 strcatW(shellFolderPath, szSHFolders);
1885 pShellFolderPath = shellFolderPath;
1890 hRootKey = HKEY_CURRENT_USER;
1891 pUserShellFolderPath = szSHUserFolders;
1892 pShellFolderPath = szSHFolders;
1895 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
1896 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
1897 TRACE("returning 0x%08x\n", hr);
1901 static HRESULT _SHRegisterCommonShellFolders(void)
1903 static const UINT folders[] = {
1904 CSIDL_COMMON_STARTMENU,
1905 CSIDL_COMMON_PROGRAMS,
1906 CSIDL_COMMON_STARTUP,
1907 CSIDL_COMMON_DESKTOPDIRECTORY,
1908 CSIDL_COMMON_FAVORITES,
1909 CSIDL_COMMON_APPDATA,
1910 CSIDL_COMMON_TEMPLATES,
1911 CSIDL_COMMON_DOCUMENTS,
1916 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
1917 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
1918 TRACE("returning 0x%08x\n", hr);
1922 /******************************************************************************
1923 * _SHAppendToUnixPath [Internal]
1925 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
1926 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
1927 * and replaces backslashes with slashes.
1930 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
1931 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
1937 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
1938 WCHAR wszSubPath[MAX_PATH];
1939 int cLen = strlen(szBasePath);
1942 if (IS_INTRESOURCE(pwszSubPath)) {
1943 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
1944 /* Fall back to hard coded defaults. */
1945 switch (LOWORD(pwszSubPath)) {
1947 lstrcpyW(wszSubPath, PersonalW);
1950 lstrcpyW(wszSubPath, My_MusicW);
1952 case IDS_MYPICTURES:
1953 lstrcpyW(wszSubPath, My_PicturesW);
1956 lstrcpyW(wszSubPath, My_VideoW);
1959 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
1964 lstrcpyW(wszSubPath, pwszSubPath);
1967 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
1969 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
1970 FILENAME_MAX - cLen, NULL, NULL))
1975 pBackslash = szBasePath + cLen;
1976 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
1981 /******************************************************************************
1982 * _SHCreateSymbolicLinks [Internal]
1984 * Sets up symbol links for various shell folders to point into the users home
1985 * directory. We do an educated guess about what the user would probably want:
1986 * - If there is a 'My Documents' directory in $HOME, the user probably wants
1987 * wine's 'My Documents' to point there. Furthermore, we imply that the user
1988 * is a Windows lover and has no problem with wine creating 'My Pictures',
1989 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
1990 * do not already exits. We put appropriate symbolic links in place for those,
1992 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
1993 * point directly to $HOME. We assume the user to be a unix hacker who does not
1994 * want wine to create anything anywhere besides the .wine directory. So, if
1995 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
1996 * shell folder to it. But if not, we symlink it to $HOME directly. The same
1997 * holds fo 'My Pictures' and 'My Video'.
1998 * - The Desktop shell folder is symlinked to '$HOME/Desktop', if that does
1999 * exists and left alone if not.
2000 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2002 static void _SHCreateSymbolicLinks(void)
2004 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEO, IDS_MYMUSIC }, i;
2005 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
2006 WCHAR wszTempPath[MAX_PATH];
2007 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
2008 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
2009 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
2010 struct stat statFolder;
2011 const char *pszHome;
2014 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2015 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
2016 SHGFP_TYPE_DEFAULT, wszTempPath);
2017 if (FAILED(hr)) return;
2018 pszPersonal = wine_get_unix_file_name(wszTempPath);
2019 if (!pszPersonal) return;
2021 pszHome = getenv("HOME");
2022 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode)) {
2023 strcpy(szPersonalTarget, pszHome);
2024 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
2025 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2027 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2028 * 'My Music' subfolders or fail silently if they already exist. */
2029 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2030 strcpy(szMyStuffTarget, szPersonalTarget);
2031 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2032 mkdir(szMyStuffTarget, 0777);
2037 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2038 strcpy(szPersonalTarget, pszHome);
2041 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2043 symlink(szPersonalTarget, pszPersonal);
2047 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2048 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2049 strcpy(szPersonalTarget, pszPersonal);
2050 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2051 strcpy(szMyStuffTarget, szPersonalTarget);
2052 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2053 mkdir(szMyStuffTarget, 0777);
2057 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
2058 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2059 /* Create the current 'My Whatever' folder and get it's unix path. */
2060 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
2061 SHGFP_TYPE_DEFAULT, wszTempPath);
2062 if (FAILED(hr)) continue;
2063 pszMyStuff = wine_get_unix_file_name(wszTempPath);
2064 if (!pszMyStuff) continue;
2066 strcpy(szMyStuffTarget, szPersonalTarget);
2067 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
2068 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2070 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2072 symlink(szMyStuffTarget, pszMyStuff);
2076 /* Else link to where 'My Documents' itself links to. */
2078 symlink(szPersonalTarget, pszMyStuff);
2080 HeapFree(GetProcessHeap(), 0, pszMyStuff);
2083 /* Last but not least, the Desktop folder */
2085 strcpy(szDesktopTarget, pszHome);
2087 strcpy(szDesktopTarget, pszPersonal);
2088 HeapFree(GetProcessHeap(), 0, pszPersonal);
2090 if (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
2091 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2093 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
2094 SHGFP_TYPE_DEFAULT, wszTempPath);
2095 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
2098 symlink(szDesktopTarget, pszDesktop);
2099 HeapFree(GetProcessHeap(), 0, pszDesktop);
2104 /* Register the default values in the registry, as some apps seem to depend
2105 * on their presence. The set registered was taken from Windows XP.
2107 HRESULT SHELL_RegisterShellFolders(void)
2111 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2112 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
2113 * _SHRegister*ShellFolders() functions will find everything nice and clean
2114 * and thus will not attempt to create them in the profile directory. */
2115 _SHCreateSymbolicLinks();
2117 hr = _SHRegisterUserShellFolders(TRUE);
2119 hr = _SHRegisterUserShellFolders(FALSE);
2121 hr = _SHRegisterCommonShellFolders();
2125 /*************************************************************************
2126 * SHGetSpecialFolderPathA [SHELL32.@]
2128 BOOL WINAPI SHGetSpecialFolderPathA (
2134 return (SHGetFolderPathA(
2136 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2139 szPath)) == S_OK ? TRUE : FALSE;
2142 /*************************************************************************
2143 * SHGetSpecialFolderPathW
2145 BOOL WINAPI SHGetSpecialFolderPathW (
2151 return (SHGetFolderPathW(
2153 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2156 szPath)) == S_OK ? TRUE : FALSE;
2159 /*************************************************************************
2160 * SHGetSpecialFolderPath (SHELL32.175)
2162 BOOL WINAPI SHGetSpecialFolderPathAW (
2169 if (SHELL_OsIsUnicode())
2170 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
2171 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
2174 /*************************************************************************
2175 * SHGetFolderLocation [SHELL32.@]
2177 * Gets the folder locations from the registry and creates a pidl.
2181 * nFolder [I] CSIDL_xxxxx
2182 * hToken [I] token representing user, or NULL for current user, or -1 for
2184 * dwReserved [I] must be zero
2185 * ppidl [O] PIDL of a special folder
2189 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2192 * Creates missing reg keys and directories.
2193 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2194 * virtual folders that are handled here.
2196 HRESULT WINAPI SHGetFolderLocation(
2201 LPITEMIDLIST *ppidl)
2203 HRESULT hr = E_INVALIDARG;
2205 TRACE("%p 0x%08x %p 0x%08x %p\n",
2206 hwndOwner, nFolder, hToken, dwReserved, ppidl);
2209 return E_INVALIDARG;
2211 return E_INVALIDARG;
2213 /* The virtual folders' locations are not user-dependent */
2218 *ppidl = _ILCreateDesktop();
2221 case CSIDL_PERSONAL:
2222 *ppidl = _ILCreateMyDocuments();
2225 case CSIDL_INTERNET:
2226 *ppidl = _ILCreateIExplore();
2229 case CSIDL_CONTROLS:
2230 *ppidl = _ILCreateControlPanel();
2233 case CSIDL_PRINTERS:
2234 *ppidl = _ILCreatePrinters();
2237 case CSIDL_BITBUCKET:
2238 *ppidl = _ILCreateBitBucket();
2242 *ppidl = _ILCreateMyComputer();
2246 *ppidl = _ILCreateNetwork();
2251 WCHAR szPath[MAX_PATH];
2253 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
2254 SHGFP_TYPE_CURRENT, szPath);
2259 TRACE("Value=%s\n", debugstr_w(szPath));
2260 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
2262 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
2264 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2265 * version 6.0 returns E_FAIL for nonexistent paths
2274 TRACE("-- (new pidl %p)\n",*ppidl);
2278 /*************************************************************************
2279 * SHGetSpecialFolderLocation [SHELL32.@]
2282 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2285 HRESULT WINAPI SHGetSpecialFolderLocation(
2288 LPITEMIDLIST * ppidl)
2290 HRESULT hr = E_INVALIDARG;
2292 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
2295 return E_INVALIDARG;
2297 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);