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 %lu %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 %lu %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%08lx),stub!\n",
671 lpszPath, *alpszPaths, dwFlags);
675 /*************************************************************************
676 * PathResolveW [SHELL32]
678 BOOL WINAPI PathResolveW(
683 FIXME("(%s,%p,0x%08lx),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%04lx 0x%04lx 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%04lx, 0x%04lx) 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','\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 dwDisp, 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 (RegCreateKeyExW(rootKey, pShellFolderPath, 0, NULL, 0, KEY_ALL_ACCESS,
1191 NULL, &shellFolderKey, &dwDisp))
1193 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
1196 if (RegCreateKeyExW(rootKey, pUserShellFolderPath, 0, NULL, 0,
1197 KEY_ALL_ACCESS, NULL, &userShellFolderKey, &dwDisp))
1199 TRACE("Failed to create %s\n",
1200 debugstr_w(pUserShellFolderPath));
1201 RegCloseKey(shellFolderKey);
1205 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
1206 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
1210 path[dwPathLen / sizeof(WCHAR)] = '\0';
1211 if (dwType == REG_EXPAND_SZ && path[0] == '%')
1213 WCHAR szTemp[MAX_PATH];
1215 _SHExpandEnvironmentStrings(path, szTemp);
1216 lstrcpynW(path, szTemp, MAX_PATH);
1218 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
1219 (strlenW(path) + 1) * sizeof(WCHAR));
1220 if (ret != ERROR_SUCCESS)
1221 hr = HRESULT_FROM_WIN32(ret);
1227 RegCloseKey(shellFolderKey);
1228 RegCloseKey(userShellFolderKey);
1229 TRACE("returning 0x%08lx\n", hr);
1233 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1234 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1235 * - The entry's szDefaultPath may be either a string value or an integer
1236 * resource identifier. In the latter case, the string value of the resource
1238 * - Depending on the entry's type, the path may begin with an (unexpanded)
1239 * environment variable name. The caller is responsible for expanding
1240 * environment strings if so desired.
1241 * The types that are prepended with environment variables are:
1242 * CSIDL_Type_User: %USERPROFILE%
1243 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1244 * CSIDL_Type_CurrVer: %SystemDrive%
1245 * (Others might make sense too, but as yet are unneeded.)
1247 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
1250 WCHAR resourcePath[MAX_PATH];
1251 LPCWSTR pDefaultPath = NULL;
1253 TRACE("0x%02x,%p\n", folder, pszPath);
1255 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1256 return E_INVALIDARG;
1258 return E_INVALIDARG;
1260 if (CSIDL_Data[folder].szDefaultPath &&
1261 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
1263 if (LoadStringW(shell32_hInstance,
1264 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
1267 pDefaultPath = resourcePath;
1271 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
1272 debugstr_w(pszPath));
1279 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
1283 switch (CSIDL_Data[folder].type)
1285 case CSIDL_Type_User:
1286 strcpyW(pszPath, UserProfileW);
1288 case CSIDL_Type_AllUsers:
1289 strcpyW(pszPath, AllUsersProfileW);
1291 case CSIDL_Type_CurrVer:
1292 strcpyW(pszPath, SystemDriveW);
1295 ; /* no corresponding env. var, do nothing */
1299 PathAddBackslashW(pszPath);
1300 strcatW(pszPath, pDefaultPath);
1303 TRACE("returning 0x%08lx\n", hr);
1307 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1308 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1309 * can be overridden in the HKLM\\szCurrentVersion key.
1310 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1311 * the registry, uses _SHGetDefaultValue to get the value.
1313 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
1318 TRACE("0x%08lx,0x%02x,%p\n", dwFlags, folder, pszPath);
1320 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1321 return E_INVALIDARG;
1322 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
1323 return E_INVALIDARG;
1325 return E_INVALIDARG;
1327 if (dwFlags & SHGFP_TYPE_DEFAULT)
1328 hr = _SHGetDefaultValue(folder, pszPath);
1334 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szCurrentVersion, 0,
1335 NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp))
1339 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
1341 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
1342 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
1343 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
1345 hr = _SHGetDefaultValue(folder, pszPath);
1346 dwType = REG_EXPAND_SZ;
1347 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
1348 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
1352 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
1358 TRACE("returning 0x%08lx (output path is %s)\n", hr, debugstr_w(pszPath));
1362 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1363 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1364 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1365 * - if hToken is -1, looks in HKEY_USERS\.Default
1366 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1367 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1368 * calls _SHGetDefaultValue for it.
1370 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
1375 TRACE("%p,0x%08lx,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
1377 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1378 return E_INVALIDARG;
1379 if (CSIDL_Data[folder].type != CSIDL_Type_User)
1380 return E_INVALIDARG;
1382 return E_INVALIDARG;
1384 /* Only the current user and the default user are supported right now
1386 * FIXME: should be able to call GetTokenInformation on the token,
1387 * then call ConvertSidToStringSidW on it to get the user prefix.
1388 * But Wine's registry doesn't store user info by sid, it stores it
1389 * by user name (and I don't know how to convert from a token to a
1392 if (hToken != NULL && hToken != (HANDLE)-1)
1394 FIXME("unsupported for user other than current or default\n");
1398 if (dwFlags & SHGFP_TYPE_DEFAULT)
1399 hr = _SHGetDefaultValue(folder, pszPath);
1402 LPCWSTR userPrefix = NULL;
1405 if (hToken == (HANDLE)-1)
1407 hRootKey = HKEY_USERS;
1408 userPrefix = DefaultW;
1410 else /* hToken == NULL, other values disallowed above */
1411 hRootKey = HKEY_CURRENT_USER;
1412 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix,
1413 CSIDL_Data[folder].szValueName, pszPath);
1414 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
1415 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1416 CSIDL_Data[folder].szValueName, pszPath);
1418 hr = _SHGetDefaultValue(folder, pszPath);
1420 TRACE("returning 0x%08lx (output path is %s)\n", hr, debugstr_w(pszPath));
1424 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1425 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1426 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1427 * If this fails, falls back to _SHGetDefaultValue.
1429 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
1434 TRACE("0x%08lx,0x%02x,%p\n", dwFlags, folder, pszPath);
1436 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1437 return E_INVALIDARG;
1438 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
1439 return E_INVALIDARG;
1441 return E_INVALIDARG;
1443 if (dwFlags & SHGFP_TYPE_DEFAULT)
1444 hr = _SHGetDefaultValue(folder, pszPath);
1447 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1448 CSIDL_Data[folder].szValueName, pszPath);
1450 hr = _SHGetDefaultValue(folder, pszPath);
1452 TRACE("returning 0x%08lx (output path is %s)\n", hr, debugstr_w(pszPath));
1456 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
1461 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
1462 KEY_ALL_ACCESS, NULL, pKey, &disp);
1463 return HRESULT_FROM_WIN32(lRet);
1466 /* Reads the value named szValueName from the key profilesKey (assumed to be
1467 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1468 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1469 * szDefault to the registry).
1471 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
1472 LPWSTR szValue, LPCWSTR szDefault)
1475 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
1478 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
1479 debugstr_w(szDefault));
1480 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
1481 (LPBYTE)szValue, &dwPathLen);
1482 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
1485 dwPathLen /= sizeof(WCHAR);
1486 szValue[dwPathLen] = '\0';
1491 /* Missing or invalid value, set a default */
1492 lstrcpynW(szValue, szDefault, MAX_PATH);
1493 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
1494 debugstr_w(szValue));
1495 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
1497 (strlenW(szValue) + 1) * sizeof(WCHAR));
1499 hr = HRESULT_FROM_WIN32(lRet);
1503 TRACE("returning 0x%08lx (output value is %s)\n", hr, debugstr_w(szValue));
1507 /* Attempts to expand environment variables from szSrc into szDest, which is
1508 * assumed to be MAX_PATH characters in length. Before referring to the
1509 * environment, handles a few variables directly, because the environment
1510 * variables may not be set when this is called (as during Wine's installation
1511 * when default values are being written to the registry).
1512 * The directly handled environment variables, and their source, are:
1513 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1514 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1516 * If one of the directly handled environment variables is expanded, only
1517 * expands a single variable, and only in the beginning of szSrc.
1519 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
1522 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
1525 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
1527 if (!szSrc || !szDest) return E_INVALIDARG;
1529 /* short-circuit if there's nothing to expand */
1530 if (szSrc[0] != '%')
1532 strcpyW(szDest, szSrc);
1536 /* Get the profile prefix, we'll probably be needing it */
1537 hr = _SHOpenProfilesKey(&key);
1540 WCHAR szDefaultProfilesPrefix[MAX_PATH];
1542 GetWindowsDirectoryW(szDefaultProfilesPrefix, MAX_PATH);
1543 PathAddBackslashW(szDefaultProfilesPrefix);
1544 PathAppendW(szDefaultProfilesPrefix, szDefaultProfileDirW);
1545 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix,
1546 szDefaultProfilesPrefix);
1550 strcpyW(szTemp, szSrc);
1551 while (SUCCEEDED(hr) && szTemp[0] == '%')
1553 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
1555 WCHAR szAllUsers[MAX_PATH];
1557 strcpyW(szDest, szProfilesPrefix);
1558 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
1559 szAllUsers, AllUsersW);
1560 PathAppendW(szDest, szAllUsers);
1561 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
1563 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
1565 WCHAR userName[MAX_PATH];
1566 DWORD userLen = MAX_PATH;
1568 strcpyW(szDest, szProfilesPrefix);
1569 GetUserNameW(userName, &userLen);
1570 PathAppendW(szDest, userName);
1571 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
1573 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
1575 GetSystemDirectoryW(szDest, MAX_PATH);
1576 if (szDest[1] != ':')
1578 FIXME("non-drive system paths unsupported\n");
1583 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
1589 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
1592 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1594 hr = HRESULT_FROM_WIN32(GetLastError());
1598 if (SUCCEEDED(hr) && szDest[0] == '%')
1599 strcpyW(szTemp, szDest);
1602 /* terminate loop */
1609 TRACE("returning 0x%08lx (input was %s, output is %s)\n", hr,
1610 debugstr_w(szSrc), debugstr_w(szDest));
1614 /*************************************************************************
1615 * SHGetFolderPathW [SHELL32.@]
1617 * Convert nFolder to path.
1621 * Failure: standard HRESULT error codes.
1624 * Most values can be overridden in either
1625 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1626 * or in the same location in HKLM.
1627 * The registry usage is explained by the following tech note:
1628 * http://www.microsoft.com/windows2000/techinfo/reskit/en-us/default.asp?url=/windows2000/techinfo/reskit/en-us/regentry/36173.asp
1629 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1630 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1631 * changes made to it are made to the former key too. This synchronization is
1632 * done on-demand: not until someone requests the value of one of these paths
1633 * (by calling one of the SHGet functions) is the value synchronized.
1634 * Furthermore, as explained here:
1635 * http://www.microsoft.com/windows2000/techinfo/reskit/en-us/default.asp?url=/windows2000/techinfo/reskit/en-us/regentry/36276.asp
1636 * the HKCU paths take precedence over the HKLM paths.
1639 HRESULT WINAPI SHGetFolderPathW(
1640 HWND hwndOwner, /* [I] owner window */
1641 int nFolder, /* [I] CSIDL identifying the folder */
1642 HANDLE hToken, /* [I] access token */
1643 DWORD dwFlags, /* [I] which path to return */
1644 LPWSTR pszPath) /* [O] converted path */
1647 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
1648 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
1652 TRACE("%p,%p,nFolder=0x%04x\n", hwndOwner,pszPath,nFolder);
1654 /* Windows always NULL-terminates the resulting path regardless of success
1655 * or failure, so do so first
1659 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1660 return E_INVALIDARG;
1662 type = CSIDL_Data[folder].type;
1665 case CSIDL_Type_Disallowed:
1668 case CSIDL_Type_NonExistent:
1671 case CSIDL_Type_WindowsPath:
1672 GetWindowsDirectoryW(szTemp, MAX_PATH);
1673 if (CSIDL_Data[folder].szDefaultPath &&
1674 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1675 *CSIDL_Data[folder].szDefaultPath)
1677 PathAddBackslashW(szTemp);
1678 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1682 case CSIDL_Type_SystemPath:
1683 GetSystemDirectoryW(szTemp, MAX_PATH);
1684 if (CSIDL_Data[folder].szDefaultPath &&
1685 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1686 *CSIDL_Data[folder].szDefaultPath)
1688 PathAddBackslashW(szTemp);
1689 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1693 case CSIDL_Type_CurrVer:
1694 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
1696 case CSIDL_Type_User:
1697 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
1699 case CSIDL_Type_AllUsers:
1700 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
1703 FIXME("bogus type %d, please fix\n", type);
1708 /* Expand environment strings if necessary */
1710 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
1712 strcpyW(szBuildPath, szTemp);
1713 /* Copy the path if it's available before we might return */
1714 if (SUCCEEDED(hr) && pszPath)
1715 strcpyW(pszPath, szBuildPath);
1717 if (FAILED(hr)) goto end;
1719 /* if we don't care about existing directories we are ready */
1720 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
1722 if (PathFileExistsW(szBuildPath)) goto end;
1724 /* not existing but we are not allowed to create it. The return value
1725 * is verified against shell32 version 6.0.
1727 if (!(nFolder & CSIDL_FLAG_CREATE))
1729 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1733 /* create directory/directories */
1734 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
1735 if (ret && ret != ERROR_ALREADY_EXISTS)
1737 ERR("Failed to create directory '%s'.\n", debugstr_w(szBuildPath));
1742 TRACE("Created missing system directory '%s'\n", debugstr_w(szBuildPath));
1744 TRACE("returning 0x%08lx (final path is %s)\n", hr, debugstr_w(szBuildPath));
1748 /*************************************************************************
1749 * SHGetFolderPathA [SHELL32.@]
1751 * See SHGetFolderPathW.
1753 HRESULT WINAPI SHGetFolderPathA(
1760 WCHAR szTemp[MAX_PATH];
1763 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
1767 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
1768 if (SUCCEEDED(hr) && pszPath)
1769 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
1775 /* For each folder in folders, if its value has not been set in the registry,
1776 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1777 * folder's type) to get the unexpanded value first.
1778 * Writes the unexpanded value to User Shell Folders, and queries it with
1779 * SHGetFolderPathW to force the creation of the directory if it doesn't
1780 * already exist. SHGetFolderPathW also returns the expanded value, which
1781 * this then writes to Shell Folders.
1783 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
1784 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
1788 WCHAR path[MAX_PATH];
1790 HKEY hUserKey = NULL, hKey = NULL;
1791 DWORD dwDisp, dwType, dwPathLen;
1794 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
1795 debugstr_w(szUserShellFolderPath), folders, foldersLen);
1797 ret = RegCreateKeyExW(hRootKey, szUserShellFolderPath, 0, NULL, 0,
1798 KEY_ALL_ACCESS, NULL, &hUserKey, &dwDisp);
1800 hr = HRESULT_FROM_WIN32(ret);
1803 ret = RegCreateKeyExW(hRootKey, szShellFolderPath, 0, NULL, 0,
1804 KEY_ALL_ACCESS, NULL, &hKey, &dwDisp);
1806 hr = HRESULT_FROM_WIN32(ret);
1808 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
1810 dwPathLen = MAX_PATH * sizeof(WCHAR);
1811 if (RegQueryValueExW(hUserKey, CSIDL_Data[folders[i]].szValueName, NULL,
1812 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
1813 dwType != REG_EXPAND_SZ))
1816 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
1817 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
1819 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
1820 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
1821 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
1822 GetWindowsDirectoryW(path, MAX_PATH);
1827 ret = RegSetValueExW(hUserKey,
1828 CSIDL_Data[folders[i]].szValueName, 0, REG_EXPAND_SZ,
1829 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1831 hr = HRESULT_FROM_WIN32(ret);
1834 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
1835 hToken, SHGFP_TYPE_DEFAULT, path);
1836 ret = RegSetValueExW(hKey,
1837 CSIDL_Data[folders[i]].szValueName, 0, REG_SZ,
1838 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1840 hr = HRESULT_FROM_WIN32(ret);
1846 RegCloseKey(hUserKey);
1850 TRACE("returning 0x%08lx\n", hr);
1854 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
1856 static const UINT folders[] = {
1867 CSIDL_DESKTOPDIRECTORY,
1871 CSIDL_LOCAL_APPDATA,
1872 CSIDL_INTERNET_CACHE,
1878 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
1879 LPCWSTR pUserShellFolderPath, pShellFolderPath;
1884 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
1887 hToken = (HANDLE)-1;
1888 hRootKey = HKEY_USERS;
1889 strcpyW(userShellFolderPath, DefaultW);
1890 PathAddBackslashW(userShellFolderPath);
1891 strcatW(userShellFolderPath, szSHUserFolders);
1892 pUserShellFolderPath = userShellFolderPath;
1893 strcpyW(shellFolderPath, DefaultW);
1894 PathAddBackslashW(shellFolderPath);
1895 strcatW(shellFolderPath, szSHFolders);
1896 pShellFolderPath = shellFolderPath;
1901 hRootKey = HKEY_CURRENT_USER;
1902 pUserShellFolderPath = szSHUserFolders;
1903 pShellFolderPath = szSHFolders;
1906 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
1907 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
1908 TRACE("returning 0x%08lx\n", hr);
1912 static HRESULT _SHRegisterCommonShellFolders(void)
1914 static const UINT folders[] = {
1915 CSIDL_COMMON_STARTMENU,
1916 CSIDL_COMMON_PROGRAMS,
1917 CSIDL_COMMON_STARTUP,
1918 CSIDL_COMMON_DESKTOPDIRECTORY,
1919 CSIDL_COMMON_FAVORITES,
1920 CSIDL_COMMON_APPDATA,
1921 CSIDL_COMMON_TEMPLATES,
1922 CSIDL_COMMON_DOCUMENTS,
1927 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
1928 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
1929 TRACE("returning 0x%08lx\n", hr);
1933 /******************************************************************************
1934 * _SHAppendToUnixPath [Internal]
1936 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
1937 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
1938 * and replaces backslashes with slashes.
1941 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
1942 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
1948 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
1949 WCHAR wszSubPath[MAX_PATH];
1950 int cLen = strlen(szBasePath);
1953 if (IS_INTRESOURCE(pwszSubPath)) {
1954 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
1955 /* Fall back to hard coded defaults. */
1956 switch (LOWORD(pwszSubPath)) {
1958 lstrcpyW(wszSubPath, PersonalW);
1961 lstrcpyW(wszSubPath, My_MusicW);
1963 case IDS_MYPICTURES:
1964 lstrcpyW(wszSubPath, My_PicturesW);
1967 lstrcpyW(wszSubPath, My_VideoW);
1970 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
1975 lstrcpyW(wszSubPath, pwszSubPath);
1978 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
1980 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
1981 FILENAME_MAX - cLen, NULL, NULL))
1986 pBackslash = szBasePath + cLen;
1987 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
1992 /******************************************************************************
1993 * _SHCreateSymbolicLinks [Internal]
1995 * Sets up symbol links for various shell folders to point into the users home
1996 * directory. We do an educated guess about what the user would probably want:
1997 * - If there is a 'My Documents' directory in $HOME, the user probably wants
1998 * wine's 'My Documents' to point there. Furthermore, we imply that the user
1999 * is a Windows lover and has no problem with wine creating 'My Pictures',
2000 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
2001 * do not already exits. We put appropriate symbolic links in place for those,
2003 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2004 * point directly to $HOME. We assume the user to be a unix hacker who does not
2005 * want wine to create anything anywhere besides the .wine directory. So, if
2006 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2007 * shell folder to it. But if not, we symlink it to $HOME directly. The same
2008 * holds fo 'My Pictures' and 'My Video'.
2009 * - The Desktop shell folder is symlinked to '$HOME/Desktop', if that does
2010 * exists and left alone if not.
2011 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2013 static void _SHCreateSymbolicLinks(void)
2015 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEO, IDS_MYMUSIC }, i;
2016 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
2017 WCHAR wszTempPath[MAX_PATH];
2018 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
2019 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
2020 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
2021 struct stat statFolder;
2022 const char *pszHome;
2025 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2026 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
2027 SHGFP_TYPE_DEFAULT, wszTempPath);
2028 if (FAILED(hr)) return;
2029 pszPersonal = wine_get_unix_file_name(wszTempPath);
2030 if (!pszPersonal) return;
2032 pszHome = getenv("HOME");
2033 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode)) {
2034 strcpy(szPersonalTarget, pszHome);
2035 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
2036 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2038 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2039 * 'My Music' subfolders or fail silently if they already exist. */
2040 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2041 strcpy(szMyStuffTarget, szPersonalTarget);
2042 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2043 mkdir(szMyStuffTarget, S_IRWXU|S_IRWXG|S_IRWXO);
2048 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2049 strcpy(szPersonalTarget, pszHome);
2052 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2054 symlink(szPersonalTarget, pszPersonal);
2058 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2059 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2060 strcpy(szPersonalTarget, pszPersonal);
2061 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2062 strcpy(szMyStuffTarget, szPersonalTarget);
2063 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2064 mkdir(szMyStuffTarget, S_IRWXU|S_IRWXG|S_IRWXO);
2068 HeapFree(GetProcessHeap(), 0, pszPersonal);
2070 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
2071 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2072 /* Create the current 'My Whatever' folder and get it's unix path. */
2073 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
2074 SHGFP_TYPE_DEFAULT, wszTempPath);
2075 if (FAILED(hr)) continue;
2076 pszMyStuff = wine_get_unix_file_name(wszTempPath);
2077 if (!pszMyStuff) continue;
2079 strcpy(szMyStuffTarget, szPersonalTarget);
2080 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
2081 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2083 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2085 symlink(szMyStuffTarget, pszMyStuff);
2089 /* Else link to where 'My Documents' itself links to. */
2091 symlink(szPersonalTarget, pszMyStuff);
2093 HeapFree(GetProcessHeap(), 0, pszMyStuff);
2096 /* Last but not least, the Desktop folder */
2097 strcpy(szDesktopTarget, pszHome);
2098 if (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
2099 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2101 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
2102 SHGFP_TYPE_DEFAULT, wszTempPath);
2103 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
2106 symlink(szDesktopTarget, pszDesktop);
2107 HeapFree(GetProcessHeap(), 0, pszDesktop);
2112 /* Register the default values in the registry, as some apps seem to depend
2113 * on their presence. The set registered was taken from Windows XP.
2115 HRESULT SHELL_RegisterShellFolders(void)
2119 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2120 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
2121 * _SHRegister*ShellFolders() functions will find everything nice and clean
2122 * and thus will not attempt to create them in the profile directory. */
2123 _SHCreateSymbolicLinks();
2125 hr = _SHRegisterUserShellFolders(TRUE);
2127 hr = _SHRegisterUserShellFolders(FALSE);
2129 hr = _SHRegisterCommonShellFolders();
2133 /*************************************************************************
2134 * SHGetSpecialFolderPathA [SHELL32.@]
2136 BOOL WINAPI SHGetSpecialFolderPathA (
2142 return (SHGetFolderPathA(
2144 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2147 szPath)) == S_OK ? TRUE : FALSE;
2150 /*************************************************************************
2151 * SHGetSpecialFolderPathW
2153 BOOL WINAPI SHGetSpecialFolderPathW (
2159 return (SHGetFolderPathW(
2161 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2164 szPath)) == S_OK ? TRUE : FALSE;
2167 /*************************************************************************
2168 * SHGetSpecialFolderPath (SHELL32.175)
2170 BOOL WINAPI SHGetSpecialFolderPathAW (
2177 if (SHELL_OsIsUnicode())
2178 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
2179 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
2182 /*************************************************************************
2183 * SHGetFolderLocation [SHELL32.@]
2185 * Gets the folder locations from the registry and creates a pidl.
2189 * nFolder [I] CSIDL_xxxxx
2190 * hToken [I] token representing user, or NULL for current user, or -1 for
2192 * dwReserved [I] must be zero
2193 * ppidl [O] PIDL of a special folder
2197 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2200 * Creates missing reg keys and directories.
2201 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2202 * virtual folders that are handled here.
2204 HRESULT WINAPI SHGetFolderLocation(
2209 LPITEMIDLIST *ppidl)
2211 HRESULT hr = E_INVALIDARG;
2213 TRACE("%p 0x%08x %p 0x%08lx %p\n",
2214 hwndOwner, nFolder, hToken, dwReserved, ppidl);
2217 return E_INVALIDARG;
2219 return E_INVALIDARG;
2221 /* The virtual folders' locations are not user-dependent */
2226 *ppidl = _ILCreateDesktop();
2229 case CSIDL_PERSONAL:
2230 *ppidl = _ILCreateMyDocuments();
2233 case CSIDL_INTERNET:
2234 *ppidl = _ILCreateIExplore();
2237 case CSIDL_CONTROLS:
2238 *ppidl = _ILCreateControlPanel();
2241 case CSIDL_PRINTERS:
2242 *ppidl = _ILCreatePrinters();
2245 case CSIDL_BITBUCKET:
2246 *ppidl = _ILCreateBitBucket();
2250 *ppidl = _ILCreateMyComputer();
2254 *ppidl = _ILCreateNetwork();
2259 WCHAR szPath[MAX_PATH];
2261 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
2262 SHGFP_TYPE_CURRENT, szPath);
2267 TRACE("Value=%s\n", debugstr_w(szPath));
2268 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
2270 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
2272 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2273 * version 6.0 returns E_FAIL for nonexistent paths
2282 TRACE("-- (new pidl %p)\n",*ppidl);
2286 /*************************************************************************
2287 * SHGetSpecialFolderLocation [SHELL32.@]
2290 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2293 HRESULT WINAPI SHGetSpecialFolderLocation(
2296 LPITEMIDLIST * ppidl)
2298 HRESULT hr = E_INVALIDARG;
2300 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
2303 return E_INVALIDARG;
2305 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);