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
30 #include "wine/port.h"
36 #include "wine/debug.h"
47 #include "shell32_main.h"
48 #include "undocshell.h"
50 #include "wine/unicode.h"
55 #include "knownfolders.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(shell);
60 static const BOOL is_win64 = sizeof(void *) > sizeof(int);
63 ########## Combining and Constructing paths ##########
66 /*************************************************************************
67 * PathAppend [SHELL32.36]
69 BOOL WINAPI PathAppendAW(
73 if (SHELL_OsIsUnicode())
74 return PathAppendW(lpszPath1, lpszPath2);
75 return PathAppendA(lpszPath1, lpszPath2);
78 /*************************************************************************
79 * PathCombine [SHELL32.37]
81 LPVOID WINAPI PathCombineAW(
86 if (SHELL_OsIsUnicode())
87 return PathCombineW( szDest, lpszDir, lpszFile );
88 return PathCombineA( szDest, lpszDir, lpszFile );
91 /*************************************************************************
92 * PathAddBackslash [SHELL32.32]
94 LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
96 if(SHELL_OsIsUnicode())
97 return PathAddBackslashW(lpszPath);
98 return PathAddBackslashA(lpszPath);
101 /*************************************************************************
102 * PathBuildRoot [SHELL32.30]
104 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
106 if(SHELL_OsIsUnicode())
107 return PathBuildRootW(lpszPath, drive);
108 return PathBuildRootA(lpszPath, drive);
112 Extracting Component Parts
115 /*************************************************************************
116 * PathFindFileName [SHELL32.34]
118 LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
120 if(SHELL_OsIsUnicode())
121 return PathFindFileNameW(lpszPath);
122 return PathFindFileNameA(lpszPath);
125 /*************************************************************************
126 * PathFindExtension [SHELL32.31]
128 LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
130 if (SHELL_OsIsUnicode())
131 return PathFindExtensionW(lpszPath);
132 return PathFindExtensionA(lpszPath);
136 /*************************************************************************
137 * PathGetExtensionA [internal]
140 * exported by ordinal
141 * return value points to the first char after the dot
143 static LPSTR PathGetExtensionA(LPCSTR lpszPath)
145 TRACE("(%s)\n",lpszPath);
147 lpszPath = PathFindExtensionA(lpszPath);
148 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
151 /*************************************************************************
152 * PathGetExtensionW [internal]
154 static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
156 TRACE("(%s)\n",debugstr_w(lpszPath));
158 lpszPath = PathFindExtensionW(lpszPath);
159 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
162 /*************************************************************************
163 * PathGetExtension [SHELL32.158]
165 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath,DWORD void1, DWORD void2)
167 if (SHELL_OsIsUnicode())
168 return PathGetExtensionW(lpszPath);
169 return PathGetExtensionA(lpszPath);
172 /*************************************************************************
173 * PathGetArgs [SHELL32.52]
175 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
177 if (SHELL_OsIsUnicode())
178 return PathGetArgsW(lpszPath);
179 return PathGetArgsA(lpszPath);
182 /*************************************************************************
183 * PathGetDriveNumber [SHELL32.57]
185 int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
187 if (SHELL_OsIsUnicode())
188 return PathGetDriveNumberW(lpszPath);
189 return PathGetDriveNumberA(lpszPath);
192 /*************************************************************************
193 * PathRemoveFileSpec [SHELL32.35]
195 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
197 if (SHELL_OsIsUnicode())
198 return PathRemoveFileSpecW(lpszPath);
199 return PathRemoveFileSpecA(lpszPath);
202 /*************************************************************************
203 * PathStripPath [SHELL32.38]
205 void WINAPI PathStripPathAW(LPVOID lpszPath)
207 if (SHELL_OsIsUnicode())
208 PathStripPathW(lpszPath);
210 PathStripPathA(lpszPath);
213 /*************************************************************************
214 * PathStripToRoot [SHELL32.50]
216 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
218 if (SHELL_OsIsUnicode())
219 return PathStripToRootW(lpszPath);
220 return PathStripToRootA(lpszPath);
223 /*************************************************************************
224 * PathRemoveArgs [SHELL32.251]
226 void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
228 if (SHELL_OsIsUnicode())
229 PathRemoveArgsW(lpszPath);
231 PathRemoveArgsA(lpszPath);
234 /*************************************************************************
235 * PathRemoveExtension [SHELL32.250]
237 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
239 if (SHELL_OsIsUnicode())
240 PathRemoveExtensionW(lpszPath);
242 PathRemoveExtensionA(lpszPath);
250 /*************************************************************************
251 * PathGetShortPathA [internal]
253 static void PathGetShortPathA(LPSTR pszPath)
257 TRACE("%s\n", pszPath);
259 if (GetShortPathNameA(pszPath, path, MAX_PATH))
261 lstrcpyA(pszPath, path);
265 /*************************************************************************
266 * PathGetShortPathW [internal]
268 static void PathGetShortPathW(LPWSTR pszPath)
270 WCHAR path[MAX_PATH];
272 TRACE("%s\n", debugstr_w(pszPath));
274 if (GetShortPathNameW(pszPath, path, MAX_PATH))
276 lstrcpyW(pszPath, path);
280 /*************************************************************************
281 * PathGetShortPath [SHELL32.92]
283 VOID WINAPI PathGetShortPathAW(LPVOID pszPath)
285 if(SHELL_OsIsUnicode())
286 PathGetShortPathW(pszPath);
287 PathGetShortPathA(pszPath);
290 /*************************************************************************
291 * PathRemoveBlanks [SHELL32.33]
293 void WINAPI PathRemoveBlanksAW(LPVOID str)
295 if(SHELL_OsIsUnicode())
296 PathRemoveBlanksW(str);
298 PathRemoveBlanksA(str);
301 /*************************************************************************
302 * PathQuoteSpaces [SHELL32.55]
304 VOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
306 if(SHELL_OsIsUnicode())
307 PathQuoteSpacesW(lpszPath);
309 PathQuoteSpacesA(lpszPath);
312 /*************************************************************************
313 * PathUnquoteSpaces [SHELL32.56]
315 VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
317 if(SHELL_OsIsUnicode())
318 PathUnquoteSpacesW(str);
320 PathUnquoteSpacesA(str);
323 /*************************************************************************
324 * PathParseIconLocation [SHELL32.249]
326 int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
328 if(SHELL_OsIsUnicode())
329 return PathParseIconLocationW(lpszPath);
330 return PathParseIconLocationA(lpszPath);
334 ########## Path Testing ##########
336 /*************************************************************************
337 * PathIsUNC [SHELL32.39]
339 BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
341 if (SHELL_OsIsUnicode())
342 return PathIsUNCW( lpszPath );
343 return PathIsUNCA( lpszPath );
346 /*************************************************************************
347 * PathIsRelative [SHELL32.40]
349 BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
351 if (SHELL_OsIsUnicode())
352 return PathIsRelativeW( lpszPath );
353 return PathIsRelativeA( lpszPath );
356 /*************************************************************************
357 * PathIsRoot [SHELL32.29]
359 BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
361 if (SHELL_OsIsUnicode())
362 return PathIsRootW(lpszPath);
363 return PathIsRootA(lpszPath);
366 /*************************************************************************
367 * PathIsExeA [internal]
369 static BOOL PathIsExeA (LPCSTR lpszPath)
371 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
373 static const char * const lpszExtensions[] =
374 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
376 TRACE("path=%s\n",lpszPath);
378 for(i=0; lpszExtensions[i]; i++)
379 if (!lstrcmpiA(lpszExtension,lpszExtensions[i])) return TRUE;
384 /*************************************************************************
385 * PathIsExeW [internal]
387 static BOOL PathIsExeW (LPCWSTR lpszPath)
389 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
391 static const WCHAR lpszExtensions[][4] =
392 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
393 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
394 {'s','c','r','\0'}, {'\0'} };
396 TRACE("path=%s\n",debugstr_w(lpszPath));
398 for(i=0; lpszExtensions[i][0]; i++)
399 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
404 /*************************************************************************
405 * PathIsExe [SHELL32.43]
407 BOOL WINAPI PathIsExeAW (LPCVOID path)
409 if (SHELL_OsIsUnicode())
410 return PathIsExeW (path);
411 return PathIsExeA(path);
414 /*************************************************************************
415 * PathIsDirectory [SHELL32.159]
417 BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
419 if (SHELL_OsIsUnicode())
420 return PathIsDirectoryW (lpszPath);
421 return PathIsDirectoryA (lpszPath);
424 /*************************************************************************
425 * PathFileExists [SHELL32.45]
427 BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
429 if (SHELL_OsIsUnicode())
430 return PathFileExistsW (lpszPath);
431 return PathFileExistsA (lpszPath);
434 /*************************************************************************
435 * PathMatchSpec [SHELL32.46]
437 BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
439 if (SHELL_OsIsUnicode())
440 return PathMatchSpecW( name, mask );
441 return PathMatchSpecA( name, mask );
444 /*************************************************************************
445 * PathIsSameRoot [SHELL32.650]
447 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
449 if (SHELL_OsIsUnicode())
450 return PathIsSameRootW(lpszPath1, lpszPath2);
451 return PathIsSameRootA(lpszPath1, lpszPath2);
454 /*************************************************************************
455 * IsLFNDriveA [SHELL32.41]
457 BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
461 if (!GetVolumeInformationA(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
466 /*************************************************************************
467 * IsLFNDriveW [SHELL32.42]
469 BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
473 if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
478 /*************************************************************************
479 * IsLFNDrive [SHELL32.119]
481 BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath)
483 if (SHELL_OsIsUnicode())
484 return IsLFNDriveW(lpszPath);
485 return IsLFNDriveA(lpszPath);
489 ########## Creating Something Unique ##########
491 /*************************************************************************
492 * PathMakeUniqueNameA [internal]
494 static BOOL PathMakeUniqueNameA(
497 LPCSTR lpszShortName,
501 FIXME("%p %u %s %s %s stub\n",
502 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
503 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
507 /*************************************************************************
508 * PathMakeUniqueNameW [internal]
510 static BOOL PathMakeUniqueNameW(
513 LPCWSTR lpszShortName,
514 LPCWSTR lpszLongName,
515 LPCWSTR lpszPathName)
517 FIXME("%p %u %s %s %s stub\n",
518 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
519 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
523 /*************************************************************************
524 * PathMakeUniqueName [SHELL32.47]
526 BOOL WINAPI PathMakeUniqueNameAW(
529 LPCVOID lpszShortName,
530 LPCVOID lpszLongName,
531 LPCVOID lpszPathName)
533 if (SHELL_OsIsUnicode())
534 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
535 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
538 /*************************************************************************
539 * PathYetAnotherMakeUniqueName [SHELL32.75]
542 * exported by ordinal
544 BOOL WINAPI PathYetAnotherMakeUniqueName(
546 LPCWSTR lpszPathName,
547 LPCWSTR lpszShortName,
548 LPCWSTR lpszLongName)
550 FIXME("(%p, %s, %s ,%s):stub.\n",
551 lpszBuffer, debugstr_w(lpszPathName), debugstr_w(lpszShortName), debugstr_w(lpszLongName));
557 ########## cleaning and resolving paths ##########
560 /*************************************************************************
561 * PathFindOnPath [SHELL32.145]
563 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID *sOtherDirs)
565 if (SHELL_OsIsUnicode())
566 return PathFindOnPathW(sFile, (LPCWSTR *)sOtherDirs);
567 return PathFindOnPathA(sFile, (LPCSTR *)sOtherDirs);
570 /*************************************************************************
571 * PathCleanupSpec [SHELL32.171]
573 * lpszFile is changed in place.
575 int WINAPI PathCleanupSpec( LPCWSTR lpszPathW, LPWSTR lpszFileW )
581 if (SHELL_OsIsUnicode())
583 LPWSTR p = lpszFileW;
585 TRACE("Cleanup %s\n",debugstr_w(lpszFileW));
588 length = strlenW(lpszPathW);
592 int gct = PathGetCharTypeW(*p);
593 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
596 rc |= PCS_REPLACEDCHAR;
602 if (length + i == MAX_PATH)
604 rc |= PCS_FATAL | PCS_PATHTOOLONG;
612 LPSTR lpszFileA = (LPSTR)lpszFileW;
613 LPCSTR lpszPathA = (LPCSTR)lpszPathW;
616 TRACE("Cleanup %s\n",debugstr_a(lpszFileA));
619 length = strlen(lpszPathA);
623 int gct = PathGetCharTypeA(*p);
624 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
627 rc |= PCS_REPLACEDCHAR;
633 if (length + i == MAX_PATH)
635 rc |= PCS_FATAL | PCS_PATHTOOLONG;
644 /*************************************************************************
645 * PathQualifyA [SHELL32]
647 static BOOL PathQualifyA(LPCSTR pszPath)
649 FIXME("%s\n",pszPath);
653 /*************************************************************************
654 * PathQualifyW [SHELL32]
656 static BOOL PathQualifyW(LPCWSTR pszPath)
658 FIXME("%s\n",debugstr_w(pszPath));
662 /*************************************************************************
663 * PathQualify [SHELL32.49]
665 BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
667 if (SHELL_OsIsUnicode())
668 return PathQualifyW(pszPath);
669 return PathQualifyA(pszPath);
672 static BOOL PathResolveA(
677 FIXME("(%s,%p,0x%08x),stub!\n",
678 lpszPath, *alpszPaths, dwFlags);
682 static BOOL PathResolveW(
687 FIXME("(%s,%p,0x%08x),stub!\n",
688 debugstr_w(lpszPath), debugstr_w(*alpszPaths), dwFlags);
692 /*************************************************************************
693 * PathResolve [SHELL32.51]
695 BOOL WINAPI PathResolveAW(
700 if (SHELL_OsIsUnicode())
701 return PathResolveW(lpszPath, (LPCWSTR*)alpszPaths, dwFlags);
702 return PathResolveA(lpszPath, (LPCSTR*)alpszPaths, dwFlags);
705 /*************************************************************************
706 * PathProcessCommandA
708 static LONG PathProcessCommandA (
714 FIXME("%s %p 0x%04x 0x%04x stub\n",
715 lpszPath, lpszBuff, dwBuffSize, dwFlags);
716 if(!lpszPath) return -1;
717 if(lpszBuff) strcpy(lpszBuff, lpszPath);
718 return strlen(lpszPath);
721 /*************************************************************************
722 * PathProcessCommandW
724 static LONG PathProcessCommandW (
730 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
731 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
732 if(!lpszPath) return -1;
733 if(lpszBuff) strcpyW(lpszBuff, lpszPath);
734 return strlenW(lpszPath);
737 /*************************************************************************
738 * PathProcessCommand (SHELL32.653)
740 LONG WINAPI PathProcessCommandAW (
746 if (SHELL_OsIsUnicode())
747 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
748 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
752 ########## special ##########
755 /*************************************************************************
756 * PathSetDlgItemPath (SHELL32.48)
758 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
760 if (SHELL_OsIsUnicode())
761 PathSetDlgItemPathW(hDlg, id, pszPath);
763 PathSetDlgItemPathA(hDlg, id, pszPath);
766 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'};
767 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'};
768 static const WCHAR AppDataW[] = {'A','p','p','D','a','t','a','\0'};
769 static const WCHAR CacheW[] = {'C','a','c','h','e','\0'};
770 static const WCHAR CD_BurningW[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
771 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'};
772 static const WCHAR Common_AppDataW[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
773 static const WCHAR Common_DesktopW[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
774 static const WCHAR Common_DocumentsW[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
775 static const WCHAR Common_FavoritesW[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
776 static const WCHAR CommonFilesDirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
777 static const WCHAR CommonFilesDirX86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
778 static const WCHAR CommonMusicW[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
779 static const WCHAR CommonPicturesW[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
780 static const WCHAR Common_ProgramsW[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
781 static const WCHAR Common_StartUpW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
782 static const WCHAR Common_Start_MenuW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
783 static const WCHAR Common_TemplatesW[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
784 static const WCHAR CommonVideoW[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
785 static const WCHAR ContactsW[] = {'C','o','n','t','a','c','t','s','\0'};
786 static const WCHAR CookiesW[] = {'C','o','o','k','i','e','s','\0'};
787 static const WCHAR DesktopW[] = {'D','e','s','k','t','o','p','\0'};
788 static const WCHAR FavoritesW[] = {'F','a','v','o','r','i','t','e','s','\0'};
789 static const WCHAR FontsW[] = {'F','o','n','t','s','\0'};
790 static const WCHAR HistoryW[] = {'H','i','s','t','o','r','y','\0'};
791 static const WCHAR Local_AppDataW[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
792 static const WCHAR My_MusicW[] = {'M','y',' ','M','u','s','i','c','\0'};
793 static const WCHAR My_PicturesW[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
794 static const WCHAR My_VideoW[] = {'M','y',' ','V','i','d','e','o','s','\0'};
795 static const WCHAR NetHoodW[] = {'N','e','t','H','o','o','d','\0'};
796 static const WCHAR PersonalW[] = {'P','e','r','s','o','n','a','l','\0'};
797 static const WCHAR PrintHoodW[] = {'P','r','i','n','t','H','o','o','d','\0'};
798 static const WCHAR ProgramFilesDirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
799 static const WCHAR ProgramFilesDirX86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
800 static const WCHAR ProgramsW[] = {'P','r','o','g','r','a','m','s','\0'};
801 static const WCHAR RecentW[] = {'R','e','c','e','n','t','\0'};
802 static const WCHAR ResourcesW[] = {'R','e','s','o','u','r','c','e','s','\0'};
803 static const WCHAR SendToW[] = {'S','e','n','d','T','o','\0'};
804 static const WCHAR StartUpW[] = {'S','t','a','r','t','U','p','\0'};
805 static const WCHAR Start_MenuW[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
806 static const WCHAR TemplatesW[] = {'T','e','m','p','l','a','t','e','s','\0'};
807 static const WCHAR UsersW[] = {'U','s','e','r','s','\0'};
808 static const WCHAR UsersPublicW[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
809 static const WCHAR DefaultW[] = {'.','D','e','f','a','u','l','t','\0'};
810 static const WCHAR AllUsersProfileW[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
811 static const WCHAR UserProfileW[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
812 static const WCHAR SystemDriveW[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
813 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};
814 static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
815 static const WCHAR AllUsersProfileValueW[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
816 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'};
817 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'};
818 static const WCHAR szDefaultProfileDirW[] = {'u','s','e','r','s',0};
819 static const WCHAR szKnownFolderDescriptions[] = {'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','\\','F','o','l','d','e','r','D','e','s','c','r','i','p','t','i','o','n','s','\0'};
820 static const WCHAR szKnownFolderRedirections[] = {'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};
821 static const WCHAR AllUsersW[] = {'P','u','b','l','i','c',0};
823 typedef enum _CSIDL_Type {
827 CSIDL_Type_Disallowed,
828 CSIDL_Type_NonExistent,
829 CSIDL_Type_WindowsPath,
830 CSIDL_Type_SystemPath,
831 CSIDL_Type_SystemX86Path,
836 const KNOWNFOLDERID *id;
839 LPCWSTR szDefaultPath; /* fallback string or resource ID */
842 static const CSIDL_DATA CSIDL_Data[] =
844 { /* 0x00 - CSIDL_DESKTOP */
848 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
850 { /* 0x01 - CSIDL_INTERNET */
851 &FOLDERID_InternetFolder,
852 CSIDL_Type_Disallowed,
856 { /* 0x02 - CSIDL_PROGRAMS */
860 MAKEINTRESOURCEW(IDS_PROGRAMS)
862 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
863 &FOLDERID_ControlPanelFolder,
864 CSIDL_Type_SystemPath,
868 { /* 0x04 - CSIDL_PRINTERS */
869 &FOLDERID_PrintersFolder,
870 CSIDL_Type_SystemPath,
874 { /* 0x05 - CSIDL_PERSONAL */
878 MAKEINTRESOURCEW(IDS_PERSONAL)
880 { /* 0x06 - CSIDL_FAVORITES */
884 MAKEINTRESOURCEW(IDS_FAVORITES)
886 { /* 0x07 - CSIDL_STARTUP */
890 MAKEINTRESOURCEW(IDS_STARTUP)
892 { /* 0x08 - CSIDL_RECENT */
896 MAKEINTRESOURCEW(IDS_RECENT)
898 { /* 0x09 - CSIDL_SENDTO */
902 MAKEINTRESOURCEW(IDS_SENDTO)
904 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
905 &FOLDERID_RecycleBinFolder,
906 CSIDL_Type_Disallowed,
910 { /* 0x0b - CSIDL_STARTMENU */
914 MAKEINTRESOURCEW(IDS_STARTMENU)
916 { /* 0x0c - CSIDL_MYDOCUMENTS */
918 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
922 { /* 0x0d - CSIDL_MYMUSIC */
926 MAKEINTRESOURCEW(IDS_MYMUSIC)
928 { /* 0x0e - CSIDL_MYVIDEO */
932 MAKEINTRESOURCEW(IDS_MYVIDEO)
934 { /* 0x0f - unassigned */
936 CSIDL_Type_Disallowed,
940 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
944 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
946 { /* 0x11 - CSIDL_DRIVES */
947 &FOLDERID_ComputerFolder,
948 CSIDL_Type_Disallowed,
952 { /* 0x12 - CSIDL_NETWORK */
953 &FOLDERID_NetworkFolder,
954 CSIDL_Type_Disallowed,
958 { /* 0x13 - CSIDL_NETHOOD */
962 MAKEINTRESOURCEW(IDS_NETHOOD)
964 { /* 0x14 - CSIDL_FONTS */
966 CSIDL_Type_WindowsPath,
970 { /* 0x15 - CSIDL_TEMPLATES */
974 MAKEINTRESOURCEW(IDS_TEMPLATES)
976 { /* 0x16 - CSIDL_COMMON_STARTMENU */
977 &FOLDERID_CommonStartMenu,
980 MAKEINTRESOURCEW(IDS_STARTMENU)
982 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
983 &FOLDERID_CommonPrograms,
986 MAKEINTRESOURCEW(IDS_PROGRAMS)
988 { /* 0x18 - CSIDL_COMMON_STARTUP */
989 &FOLDERID_CommonStartup,
992 MAKEINTRESOURCEW(IDS_STARTUP)
994 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
995 &FOLDERID_PublicDesktop,
998 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
1000 { /* 0x1a - CSIDL_APPDATA */
1001 &FOLDERID_RoamingAppData,
1004 MAKEINTRESOURCEW(IDS_APPDATA)
1006 { /* 0x1b - CSIDL_PRINTHOOD */
1007 &FOLDERID_PrintHood,
1010 MAKEINTRESOURCEW(IDS_PRINTHOOD)
1012 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1013 &FOLDERID_LocalAppData,
1016 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA)
1018 { /* 0x1d - CSIDL_ALTSTARTUP */
1020 CSIDL_Type_NonExistent,
1024 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1026 CSIDL_Type_NonExistent,
1030 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1031 &FOLDERID_Favorites,
1032 CSIDL_Type_AllUsers,
1034 MAKEINTRESOURCEW(IDS_FAVORITES)
1036 { /* 0x20 - CSIDL_INTERNET_CACHE */
1037 &FOLDERID_InternetCache,
1040 MAKEINTRESOURCEW(IDS_INTERNET_CACHE)
1042 { /* 0x21 - CSIDL_COOKIES */
1046 MAKEINTRESOURCEW(IDS_COOKIES)
1048 { /* 0x22 - CSIDL_HISTORY */
1052 MAKEINTRESOURCEW(IDS_HISTORY)
1054 { /* 0x23 - CSIDL_COMMON_APPDATA */
1055 &FOLDERID_ProgramData,
1056 CSIDL_Type_AllUsers,
1058 MAKEINTRESOURCEW(IDS_APPDATA)
1060 { /* 0x24 - CSIDL_WINDOWS */
1062 CSIDL_Type_WindowsPath,
1066 { /* 0x25 - CSIDL_SYSTEM */
1068 CSIDL_Type_SystemPath,
1072 { /* 0x26 - CSIDL_PROGRAM_FILES */
1073 &FOLDERID_ProgramFiles,
1076 MAKEINTRESOURCEW(IDS_PROGRAM_FILES)
1078 { /* 0x27 - CSIDL_MYPICTURES */
1082 MAKEINTRESOURCEW(IDS_MYPICTURES)
1084 { /* 0x28 - CSIDL_PROFILE */
1090 { /* 0x29 - CSIDL_SYSTEMX86 */
1091 &FOLDERID_SystemX86,
1092 CSIDL_Type_SystemX86Path,
1096 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1097 &FOLDERID_ProgramFilesX86,
1099 ProgramFilesDirX86W,
1100 MAKEINTRESOURCEW(IDS_PROGRAM_FILESX86)
1102 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1103 &FOLDERID_ProgramFilesCommon,
1106 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON)
1108 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1109 &FOLDERID_ProgramFilesCommonX86,
1112 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMONX86)
1114 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1115 &FOLDERID_CommonTemplates,
1116 CSIDL_Type_AllUsers,
1118 MAKEINTRESOURCEW(IDS_TEMPLATES)
1120 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1121 &FOLDERID_PublicDocuments,
1122 CSIDL_Type_AllUsers,
1124 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS)
1126 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1127 &FOLDERID_CommonAdminTools,
1128 CSIDL_Type_AllUsers,
1129 Common_Administrative_ToolsW,
1130 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1132 { /* 0x30 - CSIDL_ADMINTOOLS */
1133 &FOLDERID_AdminTools,
1135 Administrative_ToolsW,
1136 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1138 { /* 0x31 - CSIDL_CONNECTIONS */
1139 &FOLDERID_ConnectionsFolder,
1140 CSIDL_Type_Disallowed,
1144 { /* 0x32 - unassigned */
1146 CSIDL_Type_Disallowed,
1150 { /* 0x33 - unassigned */
1152 CSIDL_Type_Disallowed,
1156 { /* 0x34 - unassigned */
1158 CSIDL_Type_Disallowed,
1162 { /* 0x35 - CSIDL_COMMON_MUSIC */
1163 &FOLDERID_PublicMusic,
1164 CSIDL_Type_AllUsers,
1166 MAKEINTRESOURCEW(IDS_COMMON_MUSIC)
1168 { /* 0x36 - CSIDL_COMMON_PICTURES */
1169 &FOLDERID_PublicPictures,
1170 CSIDL_Type_AllUsers,
1172 MAKEINTRESOURCEW(IDS_COMMON_PICTURES)
1174 { /* 0x37 - CSIDL_COMMON_VIDEO */
1175 &FOLDERID_PublicVideos,
1176 CSIDL_Type_AllUsers,
1178 MAKEINTRESOURCEW(IDS_COMMON_VIDEO)
1180 { /* 0x38 - CSIDL_RESOURCES */
1181 &FOLDERID_ResourceDir,
1182 CSIDL_Type_WindowsPath,
1186 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1187 &FOLDERID_LocalizedResourcesDir,
1188 CSIDL_Type_NonExistent,
1192 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1193 &FOLDERID_CommonOEMLinks,
1194 CSIDL_Type_AllUsers,
1196 MAKEINTRESOURCEW(IDS_COMMON_OEM_LINKS)
1198 { /* 0x3b - CSIDL_CDBURN_AREA */
1199 &FOLDERID_CDBurning,
1202 MAKEINTRESOURCEW(IDS_CDBURN_AREA)
1204 { /* 0x3c unassigned */
1206 CSIDL_Type_Disallowed,
1210 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1212 CSIDL_Type_Disallowed, /* FIXME */
1216 { /* 0x3e - CSIDL_PROFILES */
1218 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
1223 &FOLDERID_AddNewPrograms,
1224 CSIDL_Type_Disallowed,
1229 &FOLDERID_AppUpdates,
1230 CSIDL_Type_Disallowed,
1235 &FOLDERID_ChangeRemovePrograms,
1236 CSIDL_Type_Disallowed,
1241 &FOLDERID_ConflictFolder,
1242 CSIDL_Type_Disallowed,
1250 MAKEINTRESOURCEW(IDS_CONTACTS)
1253 &FOLDERID_DeviceMetadataStore,
1254 CSIDL_Type_Disallowed, /* FIXME */
1259 &FOLDERID_Documents,
1262 MAKEINTRESOURCEW(IDS_DOCUMENTS)
1265 &FOLDERID_DocumentsLibrary,
1266 CSIDL_Type_Disallowed, /* FIXME */
1271 &FOLDERID_Downloads,
1274 MAKEINTRESOURCEW(IDS_DOWNLOADS)
1278 CSIDL_Type_Disallowed,
1283 &FOLDERID_GameTasks,
1284 CSIDL_Type_Disallowed, /* FIXME */
1289 &FOLDERID_HomeGroup,
1290 CSIDL_Type_Disallowed,
1295 &FOLDERID_ImplicitAppShortcuts,
1296 CSIDL_Type_Disallowed, /* FIXME */
1301 &FOLDERID_Libraries,
1302 CSIDL_Type_Disallowed, /* FIXME */
1310 MAKEINTRESOURCEW(IDS_LINKS)
1313 &FOLDERID_LocalAppDataLow,
1316 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA_LOW)
1319 &FOLDERID_MusicLibrary,
1320 CSIDL_Type_Disallowed, /* FIXME */
1325 &FOLDERID_OriginalImages,
1326 CSIDL_Type_Disallowed, /* FIXME */
1331 &FOLDERID_PhotoAlbums,
1334 MAKEINTRESOURCEW(IDS_PHOTO_ALBUMS)
1337 &FOLDERID_PicturesLibrary,
1338 CSIDL_Type_Disallowed, /* FIXME */
1343 &FOLDERID_Playlists,
1346 MAKEINTRESOURCEW(IDS_PLAYLISTS)
1349 &FOLDERID_ProgramFilesX64,
1350 CSIDL_Type_NonExistent,
1355 &FOLDERID_ProgramFilesCommonX64,
1356 CSIDL_Type_NonExistent,
1362 CSIDL_Type_CurrVer, /* FIXME */
1367 &FOLDERID_PublicDownloads,
1368 CSIDL_Type_AllUsers,
1370 MAKEINTRESOURCEW(IDS_PUBLIC_DOWNLOADS)
1373 &FOLDERID_PublicGameTasks,
1374 CSIDL_Type_AllUsers,
1376 MAKEINTRESOURCEW(IDS_PUBLIC_GAME_TASKS)
1379 &FOLDERID_PublicLibraries,
1380 CSIDL_Type_AllUsers,
1382 MAKEINTRESOURCEW(IDS_PUBLIC_LIBRARIES)
1385 &FOLDERID_PublicRingtones,
1386 CSIDL_Type_AllUsers,
1388 MAKEINTRESOURCEW(IDS_PUBLIC_RINGTONES)
1391 &FOLDERID_QuickLaunch,
1392 CSIDL_Type_Disallowed, /* FIXME */
1397 &FOLDERID_RecordedTVLibrary,
1398 CSIDL_Type_Disallowed, /* FIXME */
1403 &FOLDERID_Ringtones,
1404 CSIDL_Type_Disallowed, /* FIXME */
1409 &FOLDERID_SampleMusic,
1410 CSIDL_Type_AllUsers,
1412 MAKEINTRESOURCEW(IDS_SAMPLE_MUSIC)
1415 &FOLDERID_SamplePictures,
1416 CSIDL_Type_AllUsers,
1418 MAKEINTRESOURCEW(IDS_SAMPLE_PICTURES)
1421 &FOLDERID_SamplePlaylists,
1422 CSIDL_Type_AllUsers,
1424 MAKEINTRESOURCEW(IDS_SAMPLE_PLAYLISTS)
1427 &FOLDERID_SampleVideos,
1428 CSIDL_Type_AllUsers,
1430 MAKEINTRESOURCEW(IDS_SAMPLE_VIDEOS)
1433 &FOLDERID_SavedGames,
1436 MAKEINTRESOURCEW(IDS_SAVED_GAMES)
1439 &FOLDERID_SavedSearches,
1442 MAKEINTRESOURCEW(IDS_SAVED_SEARCHES)
1445 &FOLDERID_SEARCH_CSC,
1446 CSIDL_Type_Disallowed,
1451 &FOLDERID_SEARCH_MAPI,
1452 CSIDL_Type_Disallowed,
1457 &FOLDERID_SearchHome,
1458 CSIDL_Type_Disallowed,
1463 &FOLDERID_SidebarDefaultParts,
1464 CSIDL_Type_Disallowed, /* FIXME */
1469 &FOLDERID_SidebarParts,
1470 CSIDL_Type_Disallowed, /* FIXME */
1475 &FOLDERID_SyncManagerFolder,
1476 CSIDL_Type_Disallowed,
1481 &FOLDERID_SyncResultsFolder,
1482 CSIDL_Type_Disallowed,
1487 &FOLDERID_SyncSetupFolder,
1488 CSIDL_Type_Disallowed,
1493 &FOLDERID_UserPinned,
1494 CSIDL_Type_Disallowed, /* FIXME */
1499 &FOLDERID_UserProfiles,
1502 MAKEINTRESOURCEW(IDS_USER_PROFILES)
1505 &FOLDERID_UserProgramFiles,
1506 CSIDL_Type_Disallowed, /* FIXME */
1511 &FOLDERID_UserProgramFilesCommon,
1512 CSIDL_Type_Disallowed, /* FIXME */
1517 &FOLDERID_UsersFiles,
1518 CSIDL_Type_Disallowed,
1523 &FOLDERID_UsersLibraries,
1524 CSIDL_Type_Disallowed,
1529 &FOLDERID_VideosLibrary,
1530 CSIDL_Type_Disallowed, /* FIXME */
1536 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
1538 /* Gets the value named value from the registry key
1539 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1540 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1541 * is assumed to be MAX_PATH WCHARs in length.
1542 * If it exists, expands the value and writes the expanded value to
1543 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1544 * Returns successful error code if the value was retrieved from the registry,
1545 * and a failure otherwise.
1547 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
1548 LPCWSTR value, LPWSTR path)
1551 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
1552 LPCWSTR pShellFolderPath, pUserShellFolderPath;
1553 DWORD dwType, dwPathLen = MAX_PATH;
1554 HKEY userShellFolderKey, shellFolderKey;
1556 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
1561 strcpyW(shellFolderPath, userPrefix);
1562 PathAddBackslashW(shellFolderPath);
1563 strcatW(shellFolderPath, szSHFolders);
1564 pShellFolderPath = shellFolderPath;
1565 strcpyW(userShellFolderPath, userPrefix);
1566 PathAddBackslashW(userShellFolderPath);
1567 strcatW(userShellFolderPath, szSHUserFolders);
1568 pUserShellFolderPath = userShellFolderPath;
1572 pUserShellFolderPath = szSHUserFolders;
1573 pShellFolderPath = szSHFolders;
1576 if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey))
1578 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
1581 if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey))
1583 TRACE("Failed to create %s\n",
1584 debugstr_w(pUserShellFolderPath));
1585 RegCloseKey(shellFolderKey);
1589 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
1590 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
1594 path[dwPathLen / sizeof(WCHAR)] = '\0';
1595 if (dwType == REG_EXPAND_SZ && path[0] == '%')
1597 WCHAR szTemp[MAX_PATH];
1599 _SHExpandEnvironmentStrings(path, szTemp);
1600 lstrcpynW(path, szTemp, MAX_PATH);
1602 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
1603 (strlenW(path) + 1) * sizeof(WCHAR));
1604 if (ret != ERROR_SUCCESS)
1605 hr = HRESULT_FROM_WIN32(ret);
1611 RegCloseKey(shellFolderKey);
1612 RegCloseKey(userShellFolderKey);
1613 TRACE("returning 0x%08x\n", hr);
1617 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1618 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1619 * - The entry's szDefaultPath may be either a string value or an integer
1620 * resource identifier. In the latter case, the string value of the resource
1622 * - Depending on the entry's type, the path may begin with an (unexpanded)
1623 * environment variable name. The caller is responsible for expanding
1624 * environment strings if so desired.
1625 * The types that are prepended with environment variables are:
1626 * CSIDL_Type_User: %USERPROFILE%
1627 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1628 * CSIDL_Type_CurrVer: %SystemDrive%
1629 * (Others might make sense too, but as yet are unneeded.)
1631 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
1634 WCHAR resourcePath[MAX_PATH];
1635 LPCWSTR pDefaultPath = NULL;
1637 TRACE("0x%02x,%p\n", folder, pszPath);
1639 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1640 return E_INVALIDARG;
1642 return E_INVALIDARG;
1650 case CSIDL_PROGRAM_FILES:
1651 case CSIDL_PROGRAM_FILESX86:
1652 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1653 folder = is_wow64 ? CSIDL_PROGRAM_FILESX86 : CSIDL_PROGRAM_FILES;
1655 case CSIDL_PROGRAM_FILES_COMMON:
1656 case CSIDL_PROGRAM_FILES_COMMONX86:
1657 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1658 folder = is_wow64 ? CSIDL_PROGRAM_FILES_COMMONX86 : CSIDL_PROGRAM_FILES_COMMON;
1663 if (CSIDL_Data[folder].szDefaultPath &&
1664 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
1666 if (LoadStringW(shell32_hInstance,
1667 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
1670 pDefaultPath = resourcePath;
1674 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
1675 debugstr_w(pszPath));
1682 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
1686 switch (CSIDL_Data[folder].type)
1688 case CSIDL_Type_User:
1689 strcpyW(pszPath, UserProfileW);
1691 case CSIDL_Type_AllUsers:
1692 strcpyW(pszPath, AllUsersProfileW);
1694 case CSIDL_Type_CurrVer:
1695 strcpyW(pszPath, SystemDriveW);
1698 ; /* no corresponding env. var, do nothing */
1702 PathAddBackslashW(pszPath);
1703 strcatW(pszPath, pDefaultPath);
1706 TRACE("returning 0x%08x\n", hr);
1710 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1711 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1712 * can be overridden in the HKLM\\szCurrentVersion key.
1713 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1714 * the registry, uses _SHGetDefaultValue to get the value.
1716 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
1721 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1723 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1724 return E_INVALIDARG;
1725 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
1726 return E_INVALIDARG;
1728 return E_INVALIDARG;
1730 if (dwFlags & SHGFP_TYPE_DEFAULT)
1731 hr = _SHGetDefaultValue(folder, pszPath);
1736 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
1740 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
1742 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
1743 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
1744 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
1746 hr = _SHGetDefaultValue(folder, pszPath);
1747 dwType = REG_EXPAND_SZ;
1750 case CSIDL_PROGRAM_FILESX86:
1751 case CSIDL_PROGRAM_FILES_COMMONX86:
1752 /* these two should never be set on 32-bit setups */
1756 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1757 if (!is_wow64) break;
1761 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
1762 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
1767 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
1773 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1777 static LPWSTR _GetUserSidStringFromToken(HANDLE Token)
1779 char InfoBuffer[64];
1780 PTOKEN_USER UserInfo;
1784 UserInfo = (PTOKEN_USER) InfoBuffer;
1785 if (! GetTokenInformation(Token, TokenUser, InfoBuffer, sizeof(InfoBuffer),
1788 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1790 UserInfo = HeapAlloc(GetProcessHeap(), 0, InfoSize);
1791 if (UserInfo == NULL)
1793 if (! GetTokenInformation(Token, TokenUser, UserInfo, InfoSize,
1796 HeapFree(GetProcessHeap(), 0, UserInfo);
1801 if (! ConvertSidToStringSidW(UserInfo->User.Sid, &SidStr))
1804 if (UserInfo != (PTOKEN_USER) InfoBuffer)
1805 HeapFree(GetProcessHeap(), 0, UserInfo);
1810 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1811 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1812 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1813 * - if hToken is -1, looks in HKEY_USERS\.Default
1814 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1815 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1816 * calls _SHGetDefaultValue for it.
1818 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
1823 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
1825 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1826 return E_INVALIDARG;
1827 if (CSIDL_Data[folder].type != CSIDL_Type_User)
1828 return E_INVALIDARG;
1830 return E_INVALIDARG;
1832 if (dwFlags & SHGFP_TYPE_DEFAULT)
1834 if (hToken != NULL && hToken != (HANDLE)-1)
1836 FIXME("unsupported for user other than current or default\n");
1839 hr = _SHGetDefaultValue(folder, pszPath);
1843 LPCWSTR userPrefix = NULL;
1846 if (hToken == (HANDLE)-1)
1848 hRootKey = HKEY_USERS;
1849 userPrefix = DefaultW;
1851 else if (hToken == NULL)
1852 hRootKey = HKEY_CURRENT_USER;
1855 hRootKey = HKEY_USERS;
1856 userPrefix = _GetUserSidStringFromToken(hToken);
1857 if (userPrefix == NULL)
1863 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix,
1864 CSIDL_Data[folder].szValueName, pszPath);
1865 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
1866 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1867 CSIDL_Data[folder].szValueName, pszPath);
1869 hr = _SHGetDefaultValue(folder, pszPath);
1870 if (userPrefix != NULL && userPrefix != DefaultW)
1871 LocalFree((HLOCAL) userPrefix);
1874 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1878 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1879 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1880 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1881 * If this fails, falls back to _SHGetDefaultValue.
1883 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
1888 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1890 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1891 return E_INVALIDARG;
1892 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
1893 return E_INVALIDARG;
1895 return E_INVALIDARG;
1897 if (dwFlags & SHGFP_TYPE_DEFAULT)
1898 hr = _SHGetDefaultValue(folder, pszPath);
1901 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1902 CSIDL_Data[folder].szValueName, pszPath);
1904 hr = _SHGetDefaultValue(folder, pszPath);
1906 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1910 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
1915 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
1916 KEY_ALL_ACCESS, NULL, pKey, &disp);
1917 return HRESULT_FROM_WIN32(lRet);
1920 /* Reads the value named szValueName from the key profilesKey (assumed to be
1921 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1922 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1923 * szDefault to the registry).
1925 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
1926 LPWSTR szValue, LPCWSTR szDefault)
1929 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
1932 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
1933 debugstr_w(szDefault));
1934 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
1935 (LPBYTE)szValue, &dwPathLen);
1936 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
1939 dwPathLen /= sizeof(WCHAR);
1940 szValue[dwPathLen] = '\0';
1945 /* Missing or invalid value, set a default */
1946 lstrcpynW(szValue, szDefault, MAX_PATH);
1947 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
1948 debugstr_w(szValue));
1949 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
1951 (strlenW(szValue) + 1) * sizeof(WCHAR));
1953 hr = HRESULT_FROM_WIN32(lRet);
1957 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
1961 /* Attempts to expand environment variables from szSrc into szDest, which is
1962 * assumed to be MAX_PATH characters in length. Before referring to the
1963 * environment, handles a few variables directly, because the environment
1964 * variables may not be set when this is called (as during Wine's installation
1965 * when default values are being written to the registry).
1966 * The directly handled environment variables, and their source, are:
1967 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1968 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1970 * If one of the directly handled environment variables is expanded, only
1971 * expands a single variable, and only in the beginning of szSrc.
1973 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
1976 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
1979 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
1981 if (!szSrc || !szDest) return E_INVALIDARG;
1983 /* short-circuit if there's nothing to expand */
1984 if (szSrc[0] != '%')
1986 strcpyW(szDest, szSrc);
1990 /* Get the profile prefix, we'll probably be needing it */
1991 hr = _SHOpenProfilesKey(&key);
1994 WCHAR def_val[MAX_PATH];
1996 /* get the system drive */
1997 GetSystemDirectoryW(def_val, MAX_PATH);
1998 if (def_val[1] == ':') strcpyW( def_val + 3, szDefaultProfileDirW );
1999 else FIXME("non-drive system paths unsupported\n");
2001 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix, def_val );
2005 strcpyW(szTemp, szSrc);
2006 while (SUCCEEDED(hr) && szTemp[0] == '%')
2008 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
2010 WCHAR szAllUsers[MAX_PATH];
2012 strcpyW(szDest, szProfilesPrefix);
2013 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
2014 szAllUsers, AllUsersW);
2015 PathAppendW(szDest, szAllUsers);
2016 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
2018 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
2020 WCHAR userName[MAX_PATH];
2021 DWORD userLen = MAX_PATH;
2023 strcpyW(szDest, szProfilesPrefix);
2024 GetUserNameW(userName, &userLen);
2025 PathAppendW(szDest, userName);
2026 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
2028 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
2030 GetSystemDirectoryW(szDest, MAX_PATH);
2031 if (szDest[1] != ':')
2033 FIXME("non-drive system paths unsupported\n");
2038 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
2044 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
2047 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
2049 hr = HRESULT_FROM_WIN32(GetLastError());
2053 if (SUCCEEDED(hr) && szDest[0] == '%')
2054 strcpyW(szTemp, szDest);
2057 /* terminate loop */
2064 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
2065 debugstr_w(szSrc), debugstr_w(szDest));
2069 /*************************************************************************
2070 * SHGetFolderPathW [SHELL32.@]
2072 * Convert nFolder to path.
2076 * Failure: standard HRESULT error codes.
2079 * Most values can be overridden in either
2080 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
2081 * or in the same location in HKLM.
2082 * The "Shell Folders" registry key was used in NT4 and earlier systems.
2083 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
2084 * changes made to it are made to the former key too. This synchronization is
2085 * done on-demand: not until someone requests the value of one of these paths
2086 * (by calling one of the SHGet functions) is the value synchronized.
2087 * Furthermore, the HKCU paths take precedence over the HKLM paths.
2089 HRESULT WINAPI SHGetFolderPathW(
2090 HWND hwndOwner, /* [I] owner window */
2091 int nFolder, /* [I] CSIDL identifying the folder */
2092 HANDLE hToken, /* [I] access token */
2093 DWORD dwFlags, /* [I] which path to return */
2094 LPWSTR pszPath) /* [O] converted path */
2096 HRESULT hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, NULL, pszPath);
2097 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr)
2098 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
2102 HRESULT WINAPI SHGetFolderPathAndSubDirA(
2103 HWND hwndOwner, /* [I] owner window */
2104 int nFolder, /* [I] CSIDL identifying the folder */
2105 HANDLE hToken, /* [I] access token */
2106 DWORD dwFlags, /* [I] which path to return */
2107 LPCSTR pszSubPath, /* [I] sub directory of the specified folder */
2108 LPSTR pszPath) /* [O] converted path */
2112 LPWSTR pszSubPathW = NULL;
2113 LPWSTR pszPathW = NULL;
2114 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
2117 pszPathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
2119 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
2123 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
2125 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
2126 * set (null), or an empty string.therefore call it without the parameter set
2127 * if pszSubPath is an empty string
2129 if (pszSubPath && pszSubPath[0]) {
2130 length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0);
2131 pszSubPathW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR));
2133 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
2136 MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length);
2139 hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
2141 if (SUCCEEDED(hr) && pszPath)
2142 WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
2145 HeapFree(GetProcessHeap(), 0, pszPathW);
2146 HeapFree(GetProcessHeap(), 0, pszSubPathW);
2150 /*************************************************************************
2151 * SHGetFolderPathAndSubDirW [SHELL32.@]
2153 HRESULT WINAPI SHGetFolderPathAndSubDirW(
2154 HWND hwndOwner, /* [I] owner window */
2155 int nFolder, /* [I] CSIDL identifying the folder */
2156 HANDLE hToken, /* [I] access token */
2157 DWORD dwFlags, /* [I] which path to return */
2158 LPCWSTR pszSubPath,/* [I] sub directory of the specified folder */
2159 LPWSTR pszPath) /* [O] converted path */
2162 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
2163 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
2167 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner,pszPath,nFolder,debugstr_w(pszSubPath));
2169 /* Windows always NULL-terminates the resulting path regardless of success
2170 * or failure, so do so first
2175 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
2176 return E_INVALIDARG;
2177 if ((SHGFP_TYPE_CURRENT != dwFlags) && (SHGFP_TYPE_DEFAULT != dwFlags))
2178 return E_INVALIDARG;
2180 type = CSIDL_Data[folder].type;
2183 case CSIDL_Type_Disallowed:
2186 case CSIDL_Type_NonExistent:
2189 case CSIDL_Type_WindowsPath:
2190 GetWindowsDirectoryW(szTemp, MAX_PATH);
2191 if (CSIDL_Data[folder].szDefaultPath &&
2192 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
2193 *CSIDL_Data[folder].szDefaultPath)
2195 PathAddBackslashW(szTemp);
2196 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
2200 case CSIDL_Type_SystemPath:
2201 GetSystemDirectoryW(szTemp, MAX_PATH);
2202 if (CSIDL_Data[folder].szDefaultPath &&
2203 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
2204 *CSIDL_Data[folder].szDefaultPath)
2206 PathAddBackslashW(szTemp);
2207 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
2211 case CSIDL_Type_SystemX86Path:
2212 if (!GetSystemWow64DirectoryW(szTemp, MAX_PATH)) GetSystemDirectoryW(szTemp, MAX_PATH);
2213 if (CSIDL_Data[folder].szDefaultPath &&
2214 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
2215 *CSIDL_Data[folder].szDefaultPath)
2217 PathAddBackslashW(szTemp);
2218 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
2222 case CSIDL_Type_CurrVer:
2223 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
2225 case CSIDL_Type_User:
2226 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
2228 case CSIDL_Type_AllUsers:
2229 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
2232 FIXME("bogus type %d, please fix\n", type);
2237 /* Expand environment strings if necessary */
2239 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
2241 strcpyW(szBuildPath, szTemp);
2243 if (FAILED(hr)) goto end;
2246 /* make sure the new path does not exceed th bufferlength
2247 * rememebr to backslash and the termination */
2248 if(MAX_PATH < (lstrlenW(szBuildPath) + lstrlenW(pszSubPath) + 2)) {
2249 hr = HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
2252 PathAppendW(szBuildPath, pszSubPath);
2253 PathRemoveBackslashW(szBuildPath);
2255 /* Copy the path if it's available before we might return */
2256 if (SUCCEEDED(hr) && pszPath)
2257 strcpyW(pszPath, szBuildPath);
2259 /* if we don't care about existing directories we are ready */
2260 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
2262 if (PathFileExistsW(szBuildPath)) goto end;
2264 /* not existing but we are not allowed to create it. The return value
2265 * is verified against shell32 version 6.0.
2267 if (!(nFolder & CSIDL_FLAG_CREATE))
2269 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
2273 /* create directory/directories */
2274 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
2275 if (ret && ret != ERROR_ALREADY_EXISTS)
2277 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
2282 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
2284 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
2288 /*************************************************************************
2289 * SHGetFolderPathA [SHELL32.@]
2291 * See SHGetFolderPathW.
2293 HRESULT WINAPI SHGetFolderPathA(
2300 WCHAR szTemp[MAX_PATH];
2303 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
2307 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
2308 if (SUCCEEDED(hr) && pszPath)
2309 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
2315 /* For each folder in folders, if its value has not been set in the registry,
2316 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
2317 * folder's type) to get the unexpanded value first.
2318 * Writes the unexpanded value to User Shell Folders, and queries it with
2319 * SHGetFolderPathW to force the creation of the directory if it doesn't
2320 * already exist. SHGetFolderPathW also returns the expanded value, which
2321 * this then writes to Shell Folders.
2323 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
2324 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
2328 WCHAR path[MAX_PATH];
2330 HKEY hUserKey = NULL, hKey = NULL;
2331 DWORD dwType, dwPathLen;
2334 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
2335 debugstr_w(szUserShellFolderPath), folders, foldersLen);
2337 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
2339 hr = HRESULT_FROM_WIN32(ret);
2342 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
2344 hr = HRESULT_FROM_WIN32(ret);
2346 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
2348 dwPathLen = MAX_PATH * sizeof(WCHAR);
2349 if (RegQueryValueExW(hUserKey, CSIDL_Data[folders[i]].szValueName, NULL,
2350 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
2351 dwType != REG_EXPAND_SZ))
2354 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
2355 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
2357 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
2358 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
2359 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
2361 GetWindowsDirectoryW(path, MAX_PATH);
2362 if (CSIDL_Data[folders[i]].szDefaultPath &&
2363 !IS_INTRESOURCE(CSIDL_Data[folders[i]].szDefaultPath))
2365 PathAddBackslashW(path);
2366 strcatW(path, CSIDL_Data[folders[i]].szDefaultPath);
2373 ret = RegSetValueExW(hUserKey,
2374 CSIDL_Data[folders[i]].szValueName, 0, REG_EXPAND_SZ,
2375 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
2377 hr = HRESULT_FROM_WIN32(ret);
2380 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
2381 hToken, SHGFP_TYPE_DEFAULT, path);
2382 ret = RegSetValueExW(hKey,
2383 CSIDL_Data[folders[i]].szValueName, 0, REG_SZ,
2384 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
2386 hr = HRESULT_FROM_WIN32(ret);
2392 RegCloseKey(hUserKey);
2396 TRACE("returning 0x%08x\n", hr);
2400 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
2402 static const UINT folders[] = {
2413 CSIDL_DESKTOPDIRECTORY,
2417 CSIDL_LOCAL_APPDATA,
2418 CSIDL_INTERNET_CACHE,
2424 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
2425 LPCWSTR pUserShellFolderPath, pShellFolderPath;
2430 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
2433 hToken = (HANDLE)-1;
2434 hRootKey = HKEY_USERS;
2435 strcpyW(userShellFolderPath, DefaultW);
2436 PathAddBackslashW(userShellFolderPath);
2437 strcatW(userShellFolderPath, szSHUserFolders);
2438 pUserShellFolderPath = userShellFolderPath;
2439 strcpyW(shellFolderPath, DefaultW);
2440 PathAddBackslashW(shellFolderPath);
2441 strcatW(shellFolderPath, szSHFolders);
2442 pShellFolderPath = shellFolderPath;
2447 hRootKey = HKEY_CURRENT_USER;
2448 pUserShellFolderPath = szSHUserFolders;
2449 pShellFolderPath = szSHFolders;
2452 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
2453 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
2454 TRACE("returning 0x%08x\n", hr);
2458 static HRESULT _SHRegisterCommonShellFolders(void)
2460 static const UINT folders[] = {
2461 CSIDL_COMMON_STARTMENU,
2462 CSIDL_COMMON_PROGRAMS,
2463 CSIDL_COMMON_STARTUP,
2464 CSIDL_COMMON_DESKTOPDIRECTORY,
2465 CSIDL_COMMON_FAVORITES,
2466 CSIDL_COMMON_APPDATA,
2467 CSIDL_COMMON_TEMPLATES,
2468 CSIDL_COMMON_DOCUMENTS,
2469 CSIDL_COMMON_ADMINTOOLS,
2471 CSIDL_COMMON_PICTURES,
2477 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
2478 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
2479 TRACE("returning 0x%08x\n", hr);
2483 /******************************************************************************
2484 * _SHAppendToUnixPath [Internal]
2486 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
2487 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
2488 * and replaces backslashes with slashes.
2491 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
2492 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
2498 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
2499 WCHAR wszSubPath[MAX_PATH];
2500 int cLen = strlen(szBasePath);
2503 if (IS_INTRESOURCE(pwszSubPath)) {
2504 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
2505 /* Fall back to hard coded defaults. */
2506 switch (LOWORD(pwszSubPath)) {
2508 lstrcpyW(wszSubPath, PersonalW);
2511 lstrcpyW(wszSubPath, My_MusicW);
2513 case IDS_MYPICTURES:
2514 lstrcpyW(wszSubPath, My_PicturesW);
2517 lstrcpyW(wszSubPath, My_VideoW);
2520 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
2525 lstrcpyW(wszSubPath, pwszSubPath);
2528 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
2530 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
2531 FILENAME_MAX - cLen, NULL, NULL))
2536 pBackslash = szBasePath + cLen;
2537 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
2542 /******************************************************************************
2543 * _SHCreateSymbolicLinks [Internal]
2545 * Sets up symbol links for various shell folders to point into the users home
2546 * directory. We do an educated guess about what the user would probably want:
2547 * - If there is a 'My Documents' directory in $HOME, the user probably wants
2548 * wine's 'My Documents' to point there. Furthermore, we imply that the user
2549 * is a Windows lover and has no problem with wine creating 'My Pictures',
2550 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
2551 * do not already exits. We put appropriate symbolic links in place for those,
2553 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2554 * point directly to $HOME. We assume the user to be a unix hacker who does not
2555 * want wine to create anything anywhere besides the .wine directory. So, if
2556 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2557 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
2558 * directory, and try to link to that. If that fails, then we symlink to
2559 * $HOME directly. The same holds fo 'My Pictures' and 'My Video'.
2560 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
2561 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
2563 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2565 static void _SHCreateSymbolicLinks(void)
2567 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEO, IDS_MYMUSIC }, i;
2568 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
2569 static const char * const xdg_dirs[] = { "PICTURES", "VIDEOS", "MUSIC", "DESKTOP" };
2570 static const unsigned int num = sizeof(xdg_dirs) / sizeof(xdg_dirs[0]);
2571 WCHAR wszTempPath[MAX_PATH];
2572 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
2573 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
2574 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
2575 struct stat statFolder;
2576 const char *pszHome;
2578 char ** xdg_results;
2579 char * xdg_desktop_dir;
2581 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2582 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
2583 SHGFP_TYPE_DEFAULT, wszTempPath);
2584 if (FAILED(hr)) return;
2585 pszPersonal = wine_get_unix_file_name(wszTempPath);
2586 if (!pszPersonal) return;
2588 hr = XDG_UserDirLookup(xdg_dirs, num, &xdg_results);
2589 if (FAILED(hr)) xdg_results = NULL;
2591 pszHome = getenv("HOME");
2592 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode)) {
2593 strcpy(szPersonalTarget, pszHome);
2594 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
2595 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2597 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2598 * 'My Music' subfolders or fail silently if they already exist. */
2599 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2600 strcpy(szMyStuffTarget, szPersonalTarget);
2601 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2602 mkdir(szMyStuffTarget, 0777);
2607 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2608 strcpy(szPersonalTarget, pszHome);
2611 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2613 symlink(szPersonalTarget, pszPersonal);
2617 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2618 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2619 strcpy(szPersonalTarget, pszPersonal);
2620 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2621 strcpy(szMyStuffTarget, szPersonalTarget);
2622 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2623 mkdir(szMyStuffTarget, 0777);
2627 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
2628 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2629 /* Create the current 'My Whatever' folder and get it's unix path. */
2630 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
2631 SHGFP_TYPE_DEFAULT, wszTempPath);
2632 if (FAILED(hr)) continue;
2633 pszMyStuff = wine_get_unix_file_name(wszTempPath);
2634 if (!pszMyStuff) continue;
2636 strcpy(szMyStuffTarget, szPersonalTarget);
2637 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
2638 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2640 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2642 symlink(szMyStuffTarget, pszMyStuff);
2647 if (xdg_results && xdg_results[i])
2649 /* the folder specified by XDG_XXX_DIR exists, link to it. */
2650 symlink(xdg_results[i], pszMyStuff);
2654 /* Else link to where 'My Documents' itself links to. */
2655 symlink(szPersonalTarget, pszMyStuff);
2658 HeapFree(GetProcessHeap(), 0, pszMyStuff);
2661 /* Last but not least, the Desktop folder */
2663 strcpy(szDesktopTarget, pszHome);
2665 strcpy(szDesktopTarget, pszPersonal);
2666 HeapFree(GetProcessHeap(), 0, pszPersonal);
2668 xdg_desktop_dir = xdg_results ? xdg_results[num - 1] : NULL;
2669 if (xdg_desktop_dir ||
2670 (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
2671 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode)))
2673 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
2674 SHGFP_TYPE_DEFAULT, wszTempPath);
2675 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
2678 if (xdg_desktop_dir)
2679 symlink(xdg_desktop_dir, pszDesktop);
2681 symlink(szDesktopTarget, pszDesktop);
2682 HeapFree(GetProcessHeap(), 0, pszDesktop);
2686 /* Free resources allocated by XDG_UserDirLookup() */
2689 for (i = 0; i < num; i++)
2690 HeapFree(GetProcessHeap(), 0, xdg_results[i]);
2691 HeapFree(GetProcessHeap(), 0, xdg_results);
2695 /******************************************************************************
2696 * create_extra_folders [Internal]
2698 * Create some extra folders that don't have a standard CSIDL definition.
2700 static HRESULT create_extra_folders(void)
2702 static const WCHAR environW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
2703 static const WCHAR TempW[] = {'T','e','m','p',0};
2704 static const WCHAR TEMPW[] = {'T','E','M','P',0};
2705 static const WCHAR TMPW[] = {'T','M','P',0};
2706 WCHAR path[MAX_PATH+5];
2709 DWORD type, size, ret;
2711 ret = RegCreateKeyW( HKEY_CURRENT_USER, environW, &hkey );
2712 if (ret) return HRESULT_FROM_WIN32( ret );
2714 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
2715 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL,
2716 SHGFP_TYPE_DEFAULT, TempW, path );
2719 size = sizeof(path);
2720 if (RegQueryValueExW( hkey, TEMPW, NULL, &type, (LPBYTE)path, &size ))
2721 RegSetValueExW( hkey, TEMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
2722 size = sizeof(path);
2723 if (RegQueryValueExW( hkey, TMPW, NULL, &type, (LPBYTE)path, &size ))
2724 RegSetValueExW( hkey, TMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
2726 RegCloseKey( hkey );
2731 /******************************************************************************
2732 * set_folder_attributes
2734 * Set the various folder attributes registry keys.
2736 static HRESULT set_folder_attributes(void)
2738 static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0 };
2739 static const WCHAR shellfolderW[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
2740 static const WCHAR wfparsingW[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
2741 static const WCHAR wfdisplayW[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
2742 static const WCHAR hideasdeleteW[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
2743 static const WCHAR attributesW[] = {'A','t','t','r','i','b','u','t','e','s',0};
2744 static const WCHAR cfattributesW[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
2745 static const WCHAR emptyW[] = {0};
2754 DWORD call_for_attr;
2757 { &CLSID_UnixFolder, TRUE, FALSE, FALSE },
2758 { &CLSID_UnixDosFolder, TRUE, FALSE, FALSE,
2759 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
2760 { &CLSID_FolderShortcut, FALSE, FALSE, FALSE,
2761 SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_LINK,
2762 SFGAO_HASSUBFOLDER|SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR },
2763 { &CLSID_MyDocuments, TRUE, FALSE, FALSE,
2764 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
2765 { &CLSID_RecycleBin, FALSE, FALSE, FALSE,
2766 SFGAO_FOLDER|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET },
2767 { &CLSID_ControlPanel, FALSE, TRUE, TRUE,
2768 SFGAO_FOLDER|SFGAO_HASSUBFOLDER }
2772 WCHAR buffer[39 + (sizeof(clsidW) + sizeof(shellfolderW)) / sizeof(WCHAR)];
2776 for (i = 0; i < sizeof(folders)/sizeof(folders[0]); i++)
2778 strcpyW( buffer, clsidW );
2779 StringFromGUID2( folders[i].clsid, buffer + strlenW(buffer), 39 );
2780 strcatW( buffer, shellfolderW );
2781 res = RegCreateKeyExW( HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
2782 KEY_READ | KEY_WRITE, NULL, &hkey, NULL);
2783 if (res) return HRESULT_FROM_WIN32( res );
2784 if (folders[i].wfparsing)
2785 res = RegSetValueExW( hkey, wfparsingW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
2786 if (folders[i].wfdisplay)
2787 res = RegSetValueExW( hkey, wfdisplayW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
2788 if (folders[i].hideasdel)
2789 res = RegSetValueExW( hkey, hideasdeleteW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
2790 if (folders[i].attr)
2791 res = RegSetValueExW( hkey, attributesW, 0, REG_DWORD,
2792 (const BYTE *)&folders[i].attr, sizeof(DWORD));
2793 if (folders[i].call_for_attr)
2794 res = RegSetValueExW( hkey, cfattributesW, 0, REG_DWORD,
2795 (const BYTE *)&folders[i].call_for_attr, sizeof(DWORD));
2796 RegCloseKey( hkey );
2802 /* Register the default values in the registry, as some apps seem to depend
2803 * on their presence. The set registered was taken from Windows XP.
2805 HRESULT SHELL_RegisterShellFolders(void)
2809 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2810 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
2811 * _SHRegister*ShellFolders() functions will find everything nice and clean
2812 * and thus will not attempt to create them in the profile directory. */
2813 _SHCreateSymbolicLinks();
2815 hr = _SHRegisterUserShellFolders(TRUE);
2817 hr = _SHRegisterUserShellFolders(FALSE);
2819 hr = _SHRegisterCommonShellFolders();
2821 hr = create_extra_folders();
2823 hr = set_folder_attributes();
2827 /*************************************************************************
2828 * SHGetSpecialFolderPathA [SHELL32.@]
2830 BOOL WINAPI SHGetSpecialFolderPathA (
2836 return (SHGetFolderPathA(
2838 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2841 szPath)) == S_OK ? TRUE : FALSE;
2844 /*************************************************************************
2845 * SHGetSpecialFolderPathW
2847 BOOL WINAPI SHGetSpecialFolderPathW (
2853 return (SHGetFolderPathW(
2855 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2858 szPath)) == S_OK ? TRUE : FALSE;
2861 /*************************************************************************
2862 * SHGetSpecialFolderPath (SHELL32.175)
2864 BOOL WINAPI SHGetSpecialFolderPathAW (
2871 if (SHELL_OsIsUnicode())
2872 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
2873 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
2876 /*************************************************************************
2877 * SHGetFolderLocation [SHELL32.@]
2879 * Gets the folder locations from the registry and creates a pidl.
2883 * nFolder [I] CSIDL_xxxxx
2884 * hToken [I] token representing user, or NULL for current user, or -1 for
2886 * dwReserved [I] must be zero
2887 * ppidl [O] PIDL of a special folder
2891 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2894 * Creates missing reg keys and directories.
2895 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2896 * virtual folders that are handled here.
2898 HRESULT WINAPI SHGetFolderLocation(
2903 LPITEMIDLIST *ppidl)
2905 HRESULT hr = E_INVALIDARG;
2907 TRACE("%p 0x%08x %p 0x%08x %p\n",
2908 hwndOwner, nFolder, hToken, dwReserved, ppidl);
2911 return E_INVALIDARG;
2913 return E_INVALIDARG;
2915 /* The virtual folders' locations are not user-dependent */
2917 switch (nFolder & CSIDL_FOLDER_MASK)
2920 *ppidl = _ILCreateDesktop();
2923 case CSIDL_PERSONAL:
2924 *ppidl = _ILCreateMyDocuments();
2927 case CSIDL_INTERNET:
2928 *ppidl = _ILCreateIExplore();
2931 case CSIDL_CONTROLS:
2932 *ppidl = _ILCreateControlPanel();
2935 case CSIDL_PRINTERS:
2936 *ppidl = _ILCreatePrinters();
2939 case CSIDL_BITBUCKET:
2940 *ppidl = _ILCreateBitBucket();
2944 *ppidl = _ILCreateMyComputer();
2948 *ppidl = _ILCreateNetwork();
2953 WCHAR szPath[MAX_PATH];
2955 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
2956 SHGFP_TYPE_CURRENT, szPath);
2961 TRACE("Value=%s\n", debugstr_w(szPath));
2962 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
2964 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
2966 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2967 * version 6.0 returns E_FAIL for nonexistent paths
2976 TRACE("-- (new pidl %p)\n",*ppidl);
2980 /*************************************************************************
2981 * SHGetSpecialFolderLocation [SHELL32.@]
2984 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2987 HRESULT WINAPI SHGetSpecialFolderLocation(
2990 LPITEMIDLIST * ppidl)
2992 HRESULT hr = E_INVALIDARG;
2994 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
2997 return E_INVALIDARG;
2999 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);
3003 static int csidl_from_id( const KNOWNFOLDERID *id )
3006 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
3007 if (IsEqualGUID( CSIDL_Data[i].id, id )) return i;
3011 /*************************************************************************
3012 * SHGetKnownFolderPath [SHELL32.@]
3014 HRESULT WINAPI SHGetKnownFolderPath(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, PWSTR *path)
3017 WCHAR folder[MAX_PATH];
3018 int index = csidl_from_id( rfid );
3020 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, path);
3023 return E_INVALIDARG;
3025 if (flags & KF_FLAG_CREATE)
3026 index |= CSIDL_FLAG_CREATE;
3028 if (flags & KF_FLAG_DONT_VERIFY)
3029 index |= CSIDL_FLAG_DONT_VERIFY;
3031 if (flags & KF_FLAG_NO_ALIAS)
3032 index |= CSIDL_FLAG_NO_ALIAS;
3034 if (flags & KF_FLAG_INIT)
3035 index |= CSIDL_FLAG_PER_USER_INIT;
3037 if (flags & ~(KF_FLAG_CREATE|KF_FLAG_DONT_VERIFY|KF_FLAG_NO_ALIAS|KF_FLAG_INIT))
3039 FIXME("flags 0x%08x not supported\n", flags);
3040 return E_INVALIDARG;
3043 hr = SHGetFolderPathW( NULL, index, token, 0, folder );
3046 *path = CoTaskMemAlloc( (strlenW( folder ) + 1) * sizeof(WCHAR) );
3048 return E_OUTOFMEMORY;
3049 strcpyW( *path, folder );
3054 /*************************************************************************
3055 * SHGetFolderPathEx [SHELL32.@]
3057 HRESULT WINAPI SHGetFolderPathEx(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, LPWSTR path, DWORD len)
3062 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid), flags, token, path, len);
3064 if (!path || !len) return E_INVALIDARG;
3066 hr = SHGetKnownFolderPath( rfid, flags, token, &buffer );
3067 if (SUCCEEDED( hr ))
3069 if (strlenW( buffer ) + 1 > len)
3071 CoTaskMemFree( buffer );
3072 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER );
3074 strcpyW( path, buffer );
3075 CoTaskMemFree( buffer );
3080 /* constant values used by known folder functions */
3081 static const WCHAR szCategory[] = {'C','a','t','e','g','o','r','y',0};
3082 static const WCHAR szName[] = {'N','a','m','e',0};
3083 static const WCHAR szRelativePath[] = {'R','e','l','a','t','i','v','e','P','a','t','h',0};
3084 static const WCHAR szParentFolder[] = {'P','a','r','e','n','t','F','o','l','d','e','r',0};
3087 * Internal function to convert known folder identifier to path of registry key
3088 * associated with known folder.
3091 * rfid [I] pointer to known folder identifier (may be NULL)
3092 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
3093 * lpPath [O] place to store string address. String should be
3094 * later freed using HeapFree(GetProcessHeap(),0, ... )
3096 static HRESULT get_known_folder_registry_path(
3097 REFKNOWNFOLDERID rfid,
3098 LPWSTR lpStringGuid,
3101 static const WCHAR sBackslash[] = {'\\',0};
3106 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid), debugstr_w(lpStringGuid), lpPath);
3109 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
3111 lstrcpyW(sGuid, lpStringGuid);
3113 length = lstrlenW(szKnownFolderDescriptions)+51;
3114 *lpPath = HeapAlloc(GetProcessHeap(), 0, length*sizeof(WCHAR));
3120 lstrcpyW(*lpPath, szKnownFolderDescriptions);
3121 lstrcatW(*lpPath, sBackslash);
3122 lstrcatW(*lpPath, sGuid);
3129 * Internal function to get place where folder redirection information are stored.
3132 * rfid [I] pointer to known folder identifier (may be NULL)
3133 * rootKey [O] root key where the redirection information are stored
3134 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
3135 * However, besides root key, path is always that same, and is stored
3136 * as "szKnownFolderRedirections" constant
3138 static HRESULT get_known_folder_redirection_place(
3139 REFKNOWNFOLDERID rfid,
3143 LPWSTR lpRegistryPath = NULL;
3144 KF_CATEGORY category;
3147 /* first, get known folder's category */
3148 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
3152 dwSize = sizeof(category);
3153 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, lpRegistryPath, szCategory, RRF_RT_DWORD, NULL, &category, &dwSize));
3158 if(category == KF_CATEGORY_COMMON)
3160 *rootKey = HKEY_LOCAL_MACHINE;
3163 else if(category == KF_CATEGORY_PERUSER)
3165 *rootKey = HKEY_CURRENT_USER;
3172 HeapFree(GetProcessHeap(), 0, lpRegistryPath);
3176 static HRESULT redirect_known_folder(
3177 REFKNOWNFOLDERID rfid,
3179 KF_REDIRECT_FLAGS flags,
3180 LPCWSTR pszTargetPath,
3182 KNOWNFOLDERID const *pExclusion,
3186 HKEY rootKey = HKEY_LOCAL_MACHINE, hKey;
3188 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid), hwnd, flags, debugstr_w(pszTargetPath), cFolders, pExclusion, ppszError);
3190 /* get path to redirection storage */
3191 hr = get_known_folder_redirection_place(rfid, &rootKey);
3193 /* write redirection information */
3195 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey, szKnownFolderRedirections, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL));
3199 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
3201 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, sGuid, 0, REG_SZ, (LPBYTE)pszTargetPath, (lstrlenW(pszTargetPath)+1)*sizeof(WCHAR)));
3212 const struct IKnownFolderVtbl *vtbl;
3215 LPWSTR registryPath;
3218 static inline struct knownfolder *impl_from_IKnownFolder( IKnownFolder *iface )
3220 return (struct knownfolder *)((char *)iface - FIELD_OFFSET( struct knownfolder, vtbl ));
3223 static ULONG WINAPI knownfolder_AddRef(
3224 IKnownFolder *iface )
3226 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
3227 return InterlockedIncrement( &knownfolder->refs );
3230 static ULONG WINAPI knownfolder_Release(
3231 IKnownFolder *iface )
3233 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
3234 LONG refs = InterlockedDecrement( &knownfolder->refs );
3237 TRACE("destroying %p\n", knownfolder);
3238 HeapFree( GetProcessHeap(), 0, knownfolder->registryPath);
3239 HeapFree( GetProcessHeap(), 0, knownfolder );
3244 static HRESULT WINAPI knownfolder_QueryInterface(
3245 IKnownFolder *iface,
3249 struct knownfolder *This = impl_from_IKnownFolder( iface );
3251 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
3253 if ( IsEqualGUID( riid, &IID_IKnownFolder ) ||
3254 IsEqualGUID( riid, &IID_IUnknown ) )
3260 FIXME("interface %s not implemented\n", debugstr_guid(riid));
3261 return E_NOINTERFACE;
3263 IKnownFolder_AddRef( iface );
3267 static HRESULT knownfolder_set_id(
3268 IKnownFolder *iface,
3269 const KNOWNFOLDERID *kfid)
3271 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
3275 TRACE("%s\n", debugstr_guid(kfid));
3277 knownfolder->id = *kfid;
3279 /* check is it registry-registered folder */
3280 hr = get_known_folder_registry_path(kfid, NULL, &knownfolder->registryPath);
3282 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, 0, 0, &hKey));
3291 /* This known folder is not registered. To mark it, we set registryPath to NULL */
3292 HeapFree(GetProcessHeap(), 0, knownfolder->registryPath);
3293 knownfolder->registryPath = NULL;
3300 static HRESULT WINAPI knownfolder_GetId(
3301 IKnownFolder *iface,
3302 KNOWNFOLDERID *pkfid)
3304 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
3306 TRACE("%p\n", pkfid);
3308 *pkfid = knownfolder->id;
3312 static HRESULT WINAPI knownfolder_GetCategory(
3313 IKnownFolder *iface,
3314 KF_CATEGORY *pCategory)
3316 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
3318 DWORD dwSize = sizeof(DWORD);
3321 TRACE("%p, %p\n", knownfolder, pCategory);
3323 /* we cannot get a category for a folder which is not registered */
3324 if(!knownfolder->registryPath)
3328 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, szCategory, RRF_RT_DWORD, &dwType, pCategory, &dwSize));
3333 static HRESULT WINAPI knownfolder_GetShellItem(
3334 IKnownFolder *iface,
3339 FIXME("0x%08x, %s, %p\n", dwFlags, debugstr_guid(riid), ppv);
3343 static HRESULT get_known_folder_path(
3345 LPWSTR registryPath,
3348 static const WCHAR sBackslash[] = {'\\',0};
3350 DWORD dwSize, dwType;
3351 WCHAR path[MAX_PATH] = {0};
3352 WCHAR parentGuid[39];
3353 KF_CATEGORY category;
3354 LPWSTR parentRegistryPath, parentPath;
3355 HKEY hRedirectionRootKey = NULL;
3357 TRACE("(%s, %p)\n", debugstr_w(registryPath), ppszPath);
3360 /* check if folder has parent */
3361 dwSize = sizeof(parentGuid);
3362 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szParentFolder, RRF_RT_REG_SZ, &dwType, parentGuid, &dwSize));
3363 if(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) hr = S_FALSE;
3367 /* get parent's known folder path (recursive) */
3368 get_known_folder_registry_path(NULL, parentGuid, &parentRegistryPath);
3370 hr = get_known_folder_path(parentGuid, parentRegistryPath, &parentPath);
3372 lstrcatW(path, parentPath);
3373 lstrcatW(path, sBackslash);
3375 HeapFree(GetProcessHeap(), 0, parentRegistryPath);
3376 HeapFree(GetProcessHeap(), 0, parentPath);
3379 /* check, if folder was redirected */
3381 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szCategory, RRF_RT_REG_DWORD, NULL, &category, &dwSize));
3385 if(category == KF_CATEGORY_COMMON)
3386 hRedirectionRootKey = HKEY_LOCAL_MACHINE;
3387 else if(category == KF_CATEGORY_PERUSER)
3388 hRedirectionRootKey = HKEY_CURRENT_USER;
3390 if(hRedirectionRootKey)
3392 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, NULL, &dwSize));
3396 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
3397 if(!*ppszPath) hr = E_OUTOFMEMORY;
3402 lstrcpyW(*ppszPath, path);
3403 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, *ppszPath + lstrlenW(path), &dwSize));
3409 /* no redirection, use previous way - read the relative path from folder definition */
3410 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, NULL, &dwSize));
3414 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
3415 if(!*ppszPath) hr = E_OUTOFMEMORY;
3420 lstrcpyW(*ppszPath, path);
3421 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, *ppszPath + lstrlenW(path), &dwSize));
3426 TRACE("returning path: %s\n", debugstr_w(*ppszPath));
3430 static HRESULT WINAPI knownfolder_GetPath(
3431 IKnownFolder *iface,
3435 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
3440 TRACE("(%p, 0x%08x, %p)\n", knownfolder, dwFlags, ppszPath);
3442 /* if this is registry-registered known folder, get path from registry */
3443 if(knownfolder->registryPath)
3445 StringFromGUID2(&knownfolder->id, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
3447 hr = get_known_folder_path(sGuid, knownfolder->registryPath, ppszPath);
3449 /* in other case, use older way */
3451 hr = SHGetKnownFolderPath( &knownfolder->id, dwFlags, NULL, ppszPath );
3453 /* check if known folder really exists */
3454 dwAttributes = GetFileAttributesW(*ppszPath);
3455 if(dwAttributes == INVALID_FILE_ATTRIBUTES || !(dwAttributes & FILE_ATTRIBUTE_DIRECTORY) )
3457 TRACE("directory %s not found\n", debugstr_w(*ppszPath));
3458 CoTaskMemFree(*ppszPath);
3460 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3466 static HRESULT WINAPI knownfolder_SetPath(
3467 IKnownFolder *iface,
3471 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
3474 TRACE("(%p, 0x%08x, %p)\n", knownfolder, dwFlags, debugstr_w(pszPath));
3476 /* check if the known folder is registered */
3477 if(!knownfolder->registryPath)
3481 hr = redirect_known_folder(&knownfolder->id, NULL, 0, pszPath, 0, NULL, NULL);
3486 static HRESULT WINAPI knownfolder_GetIDList(
3487 IKnownFolder *iface,
3489 PIDLIST_ABSOLUTE *ppidl)
3491 FIXME("0x%08x, %p\n", dwFlags, ppidl);
3495 static HRESULT WINAPI knownfolder_GetFolderType(
3496 IKnownFolder *iface,
3497 FOLDERTYPEID *pftid)
3499 FIXME("%p\n", pftid);
3503 static HRESULT WINAPI knownfolder_GetRedirectionCapabilities(
3504 IKnownFolder *iface,
3505 KF_REDIRECTION_CAPABILITIES *pCapabilities)
3507 FIXME("%p\n", pCapabilities);
3511 static HRESULT WINAPI knownfolder_GetFolderDefinition(
3512 IKnownFolder *iface,
3513 KNOWNFOLDER_DEFINITION *pKFD)
3515 FIXME("%p\n", pKFD);
3519 static const struct IKnownFolderVtbl knownfolder_vtbl =
3521 knownfolder_QueryInterface,
3523 knownfolder_Release,
3525 knownfolder_GetCategory,
3526 knownfolder_GetShellItem,
3527 knownfolder_GetPath,
3528 knownfolder_SetPath,
3529 knownfolder_GetIDList,
3530 knownfolder_GetFolderType,
3531 knownfolder_GetRedirectionCapabilities,
3532 knownfolder_GetFolderDefinition
3535 static HRESULT knownfolder_create( void **ppv )
3537 struct knownfolder *kf;
3539 kf = HeapAlloc( GetProcessHeap(), 0, sizeof(*kf) );
3540 if (!kf) return E_OUTOFMEMORY;
3542 kf->vtbl = &knownfolder_vtbl;
3544 memset( &kf->id, 0, sizeof(kf->id) );
3545 kf->registryPath = NULL;
3549 TRACE("returning iface %p\n", *ppv);
3553 struct foldermanager
3555 const struct IKnownFolderManagerVtbl *vtbl;
3561 static inline struct foldermanager *impl_from_IKnownFolderManager( IKnownFolderManager *iface )
3563 return (struct foldermanager *)((char *)iface - FIELD_OFFSET( struct foldermanager, vtbl ));
3566 static ULONG WINAPI foldermanager_AddRef(
3567 IKnownFolderManager *iface )
3569 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
3570 return InterlockedIncrement( &foldermanager->refs );
3573 static ULONG WINAPI foldermanager_Release(
3574 IKnownFolderManager *iface )
3576 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
3577 LONG refs = InterlockedDecrement( &foldermanager->refs );
3580 TRACE("destroying %p\n", foldermanager);
3581 HeapFree( GetProcessHeap(), 0, foldermanager->ids );
3582 HeapFree( GetProcessHeap(), 0, foldermanager );
3587 static HRESULT WINAPI foldermanager_QueryInterface(
3588 IKnownFolderManager *iface,
3592 struct foldermanager *This = impl_from_IKnownFolderManager( iface );
3594 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
3596 if ( IsEqualGUID( riid, &IID_IKnownFolderManager ) ||
3597 IsEqualGUID( riid, &IID_IUnknown ) )
3603 FIXME("interface %s not implemented\n", debugstr_guid(riid));
3604 return E_NOINTERFACE;
3606 IKnownFolderManager_AddRef( iface );
3610 static HRESULT WINAPI foldermanager_FolderIdFromCsidl(
3611 IKnownFolderManager *iface,
3613 KNOWNFOLDERID *pfid)
3615 TRACE("%d, %p\n", nCsidl, pfid);
3617 if (nCsidl >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3618 return E_INVALIDARG;
3619 *pfid = *CSIDL_Data[nCsidl].id;
3623 static HRESULT WINAPI foldermanager_FolderIdToCsidl(
3624 IKnownFolderManager *iface,
3625 REFKNOWNFOLDERID rfid,
3630 TRACE("%s, %p\n", debugstr_guid(rfid), pnCsidl);
3632 csidl = csidl_from_id( rfid );
3633 if (csidl == -1) return E_INVALIDARG;
3638 static HRESULT WINAPI foldermanager_GetFolderIds(
3639 IKnownFolderManager *iface,
3640 KNOWNFOLDERID **ppKFId,
3643 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
3645 TRACE("%p, %p\n", ppKFId, pCount);
3648 *pCount = fm->num_ids;
3652 static BOOL is_knownfolder( struct foldermanager *fm, const KNOWNFOLDERID *id )
3656 LPWSTR registryPath = NULL;
3659 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
3660 for (i = 0; i < fm->num_ids; i++)
3661 if (IsEqualGUID( &fm->ids[i], id )) return TRUE;
3663 hr = get_known_folder_registry_path(id, NULL, ®istryPath);
3665 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, 0, &hKey));
3676 static HRESULT WINAPI foldermanager_GetFolder(
3677 IKnownFolderManager *iface,
3678 REFKNOWNFOLDERID rfid,
3679 IKnownFolder **ppkf)
3681 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
3684 TRACE("%s, %p\n", debugstr_guid(rfid), ppkf);
3686 if (!is_knownfolder( fm, rfid ))
3688 WARN("unknown folder\n");
3689 return E_INVALIDARG;
3691 hr = knownfolder_create( (void **)ppkf );
3692 if (SUCCEEDED( hr ))
3693 hr = knownfolder_set_id( *ppkf, rfid );
3698 static HRESULT WINAPI foldermanager_GetFolderByName(
3699 IKnownFolderManager *iface,
3700 LPCWSTR pszCanonicalName,
3701 IKnownFolder **ppkf)
3703 FIXME("%s, %p\n", debugstr_w(pszCanonicalName), ppkf);
3707 static HRESULT WINAPI foldermanager_RegisterFolder(
3708 IKnownFolderManager *iface,
3709 REFKNOWNFOLDERID rfid,
3710 KNOWNFOLDER_DEFINITION const *pKFD)
3715 LPWSTR registryPath = NULL;
3716 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(rfid), pKFD);
3718 hr = get_known_folder_registry_path(rfid, NULL, ®istryPath);
3719 TRACE("registry path: %s\n", debugstr_w(registryPath));
3722 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, NULL, 0, KEY_WRITE, 0, &hKey, &dwDisp));
3726 if(dwDisp == REG_OPENED_EXISTING_KEY)
3730 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szCategory, 0, REG_DWORD, (LPBYTE)&pKFD->category, sizeof(pKFD->category)));
3733 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szName, 0, REG_SZ, (LPBYTE)pKFD->pszName, (lstrlenW(pKFD->pszName)+1)*sizeof(WCHAR) ));
3735 if(SUCCEEDED(hr) && !IsEqualGUID(&pKFD->fidParent, &GUID_NULL))
3737 WCHAR sParentGuid[39];
3738 StringFromGUID2(&pKFD->fidParent, sParentGuid, sizeof(sParentGuid)/sizeof(sParentGuid[0]));
3740 /* this known folder has parent folder */
3741 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParentFolder, 0, REG_SZ, (LPBYTE)sParentGuid, sizeof(sParentGuid)));
3744 if(SUCCEEDED(hr) && pKFD->category != KF_CATEGORY_VIRTUAL)
3745 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szRelativePath, 0, REG_SZ, (LPBYTE)pKFD->pszRelativePath, (lstrlenW(pKFD->pszRelativePath)+1)*sizeof(WCHAR) ));
3750 HeapFree(GetProcessHeap(), 0, registryPath);
3754 static HRESULT WINAPI foldermanager_UnregisterFolder(
3755 IKnownFolderManager *iface,
3756 REFKNOWNFOLDERID rfid)
3759 LPWSTR registryPath = NULL;
3760 TRACE("(%p, %s)\n", iface, debugstr_guid(rfid));
3762 hr = get_known_folder_registry_path(rfid, NULL, ®istryPath);
3765 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath));
3767 HeapFree(GetProcessHeap(), 0, registryPath);
3771 static HRESULT WINAPI foldermanager_FindFolderFromPath(
3772 IKnownFolderManager *iface,
3775 IKnownFolder **ppkf)
3777 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath), mode, ppkf);
3781 static HRESULT WINAPI foldermanager_FindFolderFromIDList(
3782 IKnownFolderManager *iface,
3783 PCIDLIST_ABSOLUTE pidl,
3784 IKnownFolder **ppkf)
3786 FIXME("%p, %p\n", pidl, ppkf);
3790 static HRESULT WINAPI foldermanager_Redirect(
3791 IKnownFolderManager *iface,
3792 REFKNOWNFOLDERID rfid,
3794 KF_REDIRECT_FLAGS flags,
3795 LPCWSTR pszTargetPath,
3797 KNOWNFOLDERID const *pExclusion,
3800 return redirect_known_folder(rfid, hwnd, flags, pszTargetPath, cFolders, pExclusion, ppszError);
3803 static const struct IKnownFolderManagerVtbl foldermanager_vtbl =
3805 foldermanager_QueryInterface,
3806 foldermanager_AddRef,
3807 foldermanager_Release,
3808 foldermanager_FolderIdFromCsidl,
3809 foldermanager_FolderIdToCsidl,
3810 foldermanager_GetFolderIds,
3811 foldermanager_GetFolder,
3812 foldermanager_GetFolderByName,
3813 foldermanager_RegisterFolder,
3814 foldermanager_UnregisterFolder,
3815 foldermanager_FindFolderFromPath,
3816 foldermanager_FindFolderFromIDList,
3817 foldermanager_Redirect
3820 static HRESULT foldermanager_create( void **ppv )
3823 struct foldermanager *fm;
3825 fm = HeapAlloc( GetProcessHeap(), 0, sizeof(*fm) );
3826 if (!fm) return E_OUTOFMEMORY;
3828 fm->vtbl = &foldermanager_vtbl;
3832 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
3834 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL )) fm->num_ids++;
3836 fm->ids = HeapAlloc( GetProcessHeap(), 0, fm->num_ids * sizeof(KNOWNFOLDERID) );
3839 HeapFree( GetProcessHeap(), 0, fm );
3840 return E_OUTOFMEMORY;
3842 for (i = j = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
3844 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL ))
3846 fm->ids[j] = *CSIDL_Data[i].id;
3850 TRACE("found %u known folders\n", fm->num_ids);
3853 TRACE("returning iface %p\n", *ppv);
3857 HRESULT WINAPI KnownFolderManager_Constructor( IUnknown *punk, REFIID riid, void **ppv )
3859 TRACE("%p, %s, %p\n", punk, debugstr_guid(riid), ppv);
3864 return CLASS_E_NOAGGREGATION;
3866 return foldermanager_create( ppv );