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"
54 #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]
541 BOOL WINAPI
PathYetAnotherMakeUniqueName(LPWSTR buffer
, LPCWSTR path
, LPCWSTR shortname
, LPCWSTR longname
)
543 WCHAR pathW
[MAX_PATH
], retW
[MAX_PATH
];
544 const WCHAR
*file
, *ext
;
547 TRACE("(%p, %s, %s, %s)\n", buffer
, debugstr_w(path
), debugstr_w(shortname
), debugstr_w(longname
));
549 file
= longname
? longname
: shortname
;
550 PathCombineW(pathW
, path
, file
);
551 strcpyW(retW
, pathW
);
552 PathRemoveExtensionW(pathW
);
554 ext
= PathFindExtensionW(file
);
556 /* now try to make it unique */
557 while (PathFileExistsW(retW
))
559 static const WCHAR fmtW
[] = {'%','s',' ','(','%','d',')','%','s',0};
561 sprintfW(retW
, fmtW
, pathW
, i
, ext
);
565 strcpyW(buffer
, retW
);
566 TRACE("ret - %s\n", debugstr_w(buffer
));
572 ########## cleaning and resolving paths ##########
575 /*************************************************************************
576 * PathFindOnPath [SHELL32.145]
578 BOOL WINAPI
PathFindOnPathAW(LPVOID sFile
, LPCVOID
*sOtherDirs
)
580 if (SHELL_OsIsUnicode())
581 return PathFindOnPathW(sFile
, (LPCWSTR
*)sOtherDirs
);
582 return PathFindOnPathA(sFile
, (LPCSTR
*)sOtherDirs
);
585 /*************************************************************************
586 * PathCleanupSpec [SHELL32.171]
588 * lpszFile is changed in place.
590 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
596 if (SHELL_OsIsUnicode())
598 LPWSTR p
= lpszFileW
;
600 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
603 length
= strlenW(lpszPathW
);
607 int gct
= PathGetCharTypeW(*p
);
608 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
611 rc
|= PCS_REPLACEDCHAR
;
617 if (length
+ i
== MAX_PATH
)
619 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
627 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
628 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
631 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
634 length
= strlen(lpszPathA
);
638 int gct
= PathGetCharTypeA(*p
);
639 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
642 rc
|= PCS_REPLACEDCHAR
;
648 if (length
+ i
== MAX_PATH
)
650 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
659 /*************************************************************************
660 * PathQualifyA [SHELL32]
662 static BOOL
PathQualifyA(LPCSTR pszPath
)
664 FIXME("%s\n",pszPath
);
668 /*************************************************************************
669 * PathQualifyW [SHELL32]
671 static BOOL
PathQualifyW(LPCWSTR pszPath
)
673 FIXME("%s\n",debugstr_w(pszPath
));
677 /*************************************************************************
678 * PathQualify [SHELL32.49]
680 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
682 if (SHELL_OsIsUnicode())
683 return PathQualifyW(pszPath
);
684 return PathQualifyA(pszPath
);
687 static BOOL
PathResolveA(LPSTR path
, LPCSTR
*paths
, DWORD flags
)
689 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_a(path
), paths
, flags
);
693 static BOOL
PathResolveW(LPWSTR path
, LPCWSTR
*paths
, DWORD flags
)
695 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_w(path
), paths
, flags
);
699 /*************************************************************************
700 * PathResolve [SHELL32.51]
702 BOOL WINAPI
PathResolveAW(LPVOID path
, LPCVOID
*paths
, DWORD flags
)
704 if (SHELL_OsIsUnicode())
705 return PathResolveW(path
, (LPCWSTR
*)paths
, flags
);
707 return PathResolveA(path
, (LPCSTR
*)paths
, flags
);
710 /*************************************************************************
711 * PathProcessCommandA
713 static LONG
PathProcessCommandA (
719 FIXME("%s %p 0x%04x 0x%04x stub\n",
720 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
721 if(!lpszPath
) return -1;
722 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
723 return strlen(lpszPath
);
726 /*************************************************************************
727 * PathProcessCommandW
729 static LONG
PathProcessCommandW (
735 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
736 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
737 if(!lpszPath
) return -1;
738 if(lpszBuff
) strcpyW(lpszBuff
, lpszPath
);
739 return strlenW(lpszPath
);
742 /*************************************************************************
743 * PathProcessCommand (SHELL32.653)
745 LONG WINAPI
PathProcessCommandAW (
751 if (SHELL_OsIsUnicode())
752 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
753 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
757 ########## special ##########
760 /*************************************************************************
761 * PathSetDlgItemPath (SHELL32.48)
763 VOID WINAPI
PathSetDlgItemPathAW(HWND hDlg
, int id
, LPCVOID pszPath
)
765 if (SHELL_OsIsUnicode())
766 PathSetDlgItemPathW(hDlg
, id
, pszPath
);
768 PathSetDlgItemPathA(hDlg
, id
, pszPath
);
771 static const WCHAR szCategory
[] = {'C','a','t','e','g','o','r','y',0};
772 static const WCHAR szAttributes
[] = {'A','t','t','r','i','b','u','t','e','s',0};
773 static const WCHAR szName
[] = {'N','a','m','e',0};
774 static const WCHAR szRelativePath
[] = {'R','e','l','a','t','i','v','e','P','a','t','h',0};
775 static const WCHAR szParentFolder
[] = {'P','a','r','e','n','t','F','o','l','d','e','r',0};
777 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'};
778 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'};
779 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
780 static const WCHAR AppData_LocalLowW
[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','L','o','w','\0'};
781 static const WCHAR Application_DataW
[] = {'A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
782 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
783 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
784 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'};
785 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
786 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
787 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
788 static const WCHAR Common_FavoritesW
[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
789 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
790 static const WCHAR CommonFilesDirX86W
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
791 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
792 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
793 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
794 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
795 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
796 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
797 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
798 static const WCHAR ContactsW
[] = {'C','o','n','t','a','c','t','s','\0'};
799 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
800 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
801 static const WCHAR DocumentsW
[] = {'D','o','c','u','m','e','n','t','s','\0'};
802 static const WCHAR DownloadsW
[] = {'D','o','w','n','l','o','a','d','s','\0'};
803 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
804 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
805 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
806 static const WCHAR LinksW
[] = {'L','i','n','k','s','\0'};
807 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
808 static const WCHAR Local_Settings_Application_DataW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
809 static const WCHAR Local_Settings_CD_BurningW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\\','M','i','c','r','o','s','o','f','t','\\','C','D',' ','B','u','r','n','i','n','g','\0'};
810 static const WCHAR Local_Settings_HistoryW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','H','i','s','t','o','r','y','\0'};
811 static const WCHAR Local_Settings_Temporary_Internet_FilesW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','T','e','m','p','o','r','a','r','y',' ','I','n','t','e','r','n','e','t',' ','F','i','l','e','s','\0'};
812 static const WCHAR Microsoft_Windows_GameExplorerW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','G','a','m','e','E','x','p','l','o','r','e','r','\0'};
813 static const WCHAR Microsoft_Windows_LibrariesW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','L','i','b','r','a','r','i','e','s','\0'};
814 static const WCHAR Microsoft_Windows_RingtonesW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','R','i','n','g','t','o','n','e','s','\0'};
815 static const WCHAR Microsoft_Windows_Start_MenuW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','S','t','a','r','t',' ','M','e','n','u',0};
816 static const WCHAR MusicW
[] = {'M','u','s','i','c','\0'};
817 static const WCHAR Music_PlaylistsW
[] = {'M','u','s','i','c','\\','P','l','a','y','l','i','s','t','s','\0'};
818 static const WCHAR Music_Sample_MusicW
[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','M','u','s','i','c','\0'};
819 static const WCHAR Music_Sample_PlaylistsW
[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','P','l','a','y','l','i','s','t','s','\0'};
820 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
821 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
822 static const WCHAR My_VideosW
[] = {'M','y',' ','V','i','d','e','o','s','\0'};
823 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
824 static const WCHAR OEM_LinksW
[] = {'O','E','M',' ','L','i','n','k','s','\0'};
825 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
826 static const WCHAR PicturesW
[] = {'P','i','c','t','u','r','e','s','\0'};
827 static const WCHAR Pictures_Sample_PicturesW
[] = {'P','i','c','t','u','r','e','s','\\','S','a','m','p','l','e',' ','P','i','c','t','u','r','e','s','\0'};
828 static const WCHAR Pictures_Slide_ShowsW
[] = {'P','i','c','t','u','r','e','s','\\','S','l','i','d','e',' ','S','h','o','w','s','\0'};
829 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
830 static const WCHAR Program_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\0'};
831 static const WCHAR ProgramFilesW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','\0'};
832 static const WCHAR Program_Files_Common_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
833 static const WCHAR Program_Files_x86W
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\0'};
834 static const WCHAR Program_Files_x86_Common_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
835 static const WCHAR ProgramFilesCommonW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','C','o','m','m','o','n',0};
836 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
837 static const WCHAR ProgramFilesDirX86W
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
838 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
839 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
840 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
841 static const WCHAR Saved_GamesW
[] = {'S','a','v','e','d',' ','G','a','m','e','s','\0'};
842 static const WCHAR SearchesW
[] = {'S','e','a','r','c','h','e','s','\0'};
843 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
844 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
845 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
846 static const WCHAR Start_Menu_ProgramsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\0'};
847 static const WCHAR Start_Menu_Admin_ToolsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
848 static const WCHAR Start_Menu_StartupW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','S','t','a','r','t','U','p','\0'};
849 static const WCHAR SystemW
[] = {'S','y','s','t','e','m',0};
850 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
851 static const WCHAR UsersW
[] = {'U','s','e','r','s','\0'};
852 static const WCHAR UsersPublicW
[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
853 static const WCHAR VideosW
[] = {'V','i','d','e','o','s','\0'};
854 static const WCHAR Videos_Sample_VideosW
[] = {'V','i','d','e','o','s','\\','S','a','m','p','l','e',' ','V','i','d','e','o','s','\0'};
855 static const WCHAR WindowsW
[] = {'W','i','n','d','o','w','s',0};
856 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
857 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
858 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
859 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
860 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};
861 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
862 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
863 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'};
864 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'};
865 static const WCHAR szDefaultProfileDirW
[] = {'u','s','e','r','s',0};
866 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'};
867 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};
868 static const WCHAR AllUsersW
[] = {'P','u','b','l','i','c',0};
870 typedef enum _CSIDL_Type
{
874 CSIDL_Type_Disallowed
,
875 CSIDL_Type_NonExistent
,
876 CSIDL_Type_WindowsPath
,
877 CSIDL_Type_SystemPath
,
878 CSIDL_Type_SystemX86Path
,
881 #define CSIDL_CONTACTS 0x0043
882 #define CSIDL_DOWNLOADS 0x0047
883 #define CSIDL_LINKS 0x004d
884 #define CSIDL_APPDATA_LOCALLOW 0x004e
885 #define CSIDL_SAVED_GAMES 0x0062
886 #define CSIDL_SEARCHES 0x0063
890 const KNOWNFOLDERID
*id
;
893 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
895 /* KNOWNFOLDER_DEFINITION fields */
896 KF_CATEGORY category
;
897 const WCHAR
*pszName
;
898 const WCHAR
*pszDescription
;
899 const KNOWNFOLDERID
*fidParent
;
900 const WCHAR
*pszRelativePath
;
901 const WCHAR
*pszParsingName
;
902 const WCHAR
*pszTooltip
;
903 const WCHAR
*pszLocalizedName
;
904 const WCHAR
*pszIcon
;
905 const WCHAR
*pszSecurity
;
907 KF_DEFINITION_FLAGS kfdFlags
;
908 const FOLDERTYPEID
*ftidType
;
911 static const CSIDL_DATA CSIDL_Data
[] =
913 { /* 0x00 - CSIDL_DESKTOP */
917 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
),
919 KF_CATEGORY_PERUSER
, /* category */
921 NULL
, /* description */
922 &GUID_NULL
, /* parent */
923 DesktopW
, /* relative path */
926 NULL
, /* localized */
929 FILE_ATTRIBUTE_READONLY
, /* attributes */
931 &GUID_NULL
/* typeid */
933 { /* 0x01 - CSIDL_INTERNET */
934 &FOLDERID_InternetFolder
,
935 CSIDL_Type_Disallowed
,
939 { /* 0x02 - CSIDL_PROGRAMS */
945 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
946 &FOLDERID_ControlPanelFolder
,
947 CSIDL_Type_SystemPath
,
951 { /* 0x04 - CSIDL_PRINTERS */
952 &FOLDERID_PrintersFolder
,
953 CSIDL_Type_SystemPath
,
957 { /* 0x05 - CSIDL_PERSONAL */
961 MAKEINTRESOURCEW(IDS_PERSONAL
)
963 { /* 0x06 - CSIDL_FAVORITES */
969 { /* 0x07 - CSIDL_STARTUP */
975 { /* 0x08 - CSIDL_RECENT */
981 { /* 0x09 - CSIDL_SENDTO */
987 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
988 &FOLDERID_RecycleBinFolder
,
989 CSIDL_Type_Disallowed
,
993 { /* 0x0b - CSIDL_STARTMENU */
999 { /* 0x0c - CSIDL_MYDOCUMENTS */
1001 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
1005 { /* 0x0d - CSIDL_MYMUSIC */
1009 MAKEINTRESOURCEW(IDS_MYMUSIC
)
1011 { /* 0x0e - CSIDL_MYVIDEO */
1015 MAKEINTRESOURCEW(IDS_MYVIDEOS
)
1017 { /* 0x0f - unassigned */
1019 CSIDL_Type_Disallowed
,
1023 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
1027 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
1029 { /* 0x11 - CSIDL_DRIVES */
1030 &FOLDERID_ComputerFolder
,
1031 CSIDL_Type_Disallowed
,
1035 { /* 0x12 - CSIDL_NETWORK */
1036 &FOLDERID_NetworkFolder
,
1037 CSIDL_Type_Disallowed
,
1041 { /* 0x13 - CSIDL_NETHOOD */
1047 { /* 0x14 - CSIDL_FONTS */
1049 CSIDL_Type_WindowsPath
,
1053 KF_CATEGORY_FIXED
, /* category */
1055 NULL
, /* description */
1056 &GUID_NULL
, /* parent */
1057 NULL
, /* relative path */
1060 NULL
, /* localized */
1062 NULL
, /* security */
1065 &FOLDERID_Windows
/* typeid */
1067 { /* 0x15 - CSIDL_TEMPLATES */
1068 &FOLDERID_Templates
,
1073 { /* 0x16 - CSIDL_COMMON_STARTMENU */
1074 &FOLDERID_CommonStartMenu
,
1075 CSIDL_Type_AllUsers
,
1079 KF_CATEGORY_COMMON
, /* category */
1080 Common_Start_MenuW
, /* name */
1081 NULL
, /* description */
1082 &FOLDERID_ProgramData
, /* parent */
1083 Microsoft_Windows_Start_MenuW
, /* relative path */
1086 NULL
, /* localized */
1088 NULL
, /* security */
1089 FILE_ATTRIBUTE_READONLY
, /* attributes */
1091 &GUID_NULL
/* typeid */
1093 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
1094 &FOLDERID_CommonPrograms
,
1095 CSIDL_Type_AllUsers
,
1097 Start_Menu_ProgramsW
,
1099 KF_CATEGORY_COMMON
, /* category */
1100 Common_ProgramsW
, /* name */
1101 NULL
, /* description */
1102 &FOLDERID_CommonStartMenu
, /* parent */
1103 ProgramsW
, /* relative path */
1106 NULL
, /* localized */
1108 NULL
, /* security */
1109 FILE_ATTRIBUTE_READONLY
, /* attributes */
1111 &GUID_NULL
/* typeid */
1113 { /* 0x18 - CSIDL_COMMON_STARTUP */
1114 &FOLDERID_CommonStartup
,
1115 CSIDL_Type_AllUsers
,
1119 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
1120 &FOLDERID_PublicDesktop
,
1121 CSIDL_Type_AllUsers
,
1123 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
1125 { /* 0x1a - CSIDL_APPDATA */
1126 &FOLDERID_RoamingAppData
,
1131 { /* 0x1b - CSIDL_PRINTHOOD */
1132 &FOLDERID_PrintHood
,
1137 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1138 &FOLDERID_LocalAppData
,
1141 Local_Settings_Application_DataW
1143 { /* 0x1d - CSIDL_ALTSTARTUP */
1145 CSIDL_Type_NonExistent
,
1149 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1151 CSIDL_Type_NonExistent
,
1155 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1156 &FOLDERID_Favorites
,
1157 CSIDL_Type_AllUsers
,
1161 { /* 0x20 - CSIDL_INTERNET_CACHE */
1162 &FOLDERID_InternetCache
,
1165 Local_Settings_Temporary_Internet_FilesW
1167 { /* 0x21 - CSIDL_COOKIES */
1173 { /* 0x22 - CSIDL_HISTORY */
1177 Local_Settings_HistoryW
1179 { /* 0x23 - CSIDL_COMMON_APPDATA */
1180 &FOLDERID_ProgramData
,
1181 CSIDL_Type_AllUsers
,
1185 KF_CATEGORY_FIXED
, /* category */
1186 Common_AppDataW
, /* name */
1187 NULL
, /* description */
1188 &GUID_NULL
, /* parent */
1189 NULL
, /* relative path */
1192 NULL
, /* localized */
1194 NULL
, /* security */
1197 &GUID_NULL
/* typeid */
1199 { /* 0x24 - CSIDL_WINDOWS */
1201 CSIDL_Type_WindowsPath
,
1205 KF_CATEGORY_FIXED
, /* category */
1206 WindowsW
, /* name */
1207 NULL
, /* description */
1208 &GUID_NULL
, /* parent */
1209 NULL
, /* relative path */
1212 NULL
, /* localized */
1214 NULL
, /* security */
1217 &GUID_NULL
/* typeid */
1219 { /* 0x25 - CSIDL_SYSTEM */
1221 CSIDL_Type_SystemPath
,
1225 KF_CATEGORY_FIXED
, /* category */
1227 NULL
, /* description */
1228 &GUID_NULL
, /* parent */
1229 NULL
, /* relative path */
1232 NULL
, /* localized */
1234 NULL
, /* security */
1237 &GUID_NULL
/* typeid */
1239 { /* 0x26 - CSIDL_PROGRAM_FILES */
1240 &FOLDERID_ProgramFiles
,
1245 KF_CATEGORY_FIXED
, /* category */
1246 ProgramFilesW
, /* name */
1247 NULL
, /* description */
1248 &GUID_NULL
, /* parent */
1249 NULL
, /* relative path */
1252 NULL
, /* localized */
1254 NULL
, /* security */
1255 FILE_ATTRIBUTE_READONLY
, /* attributes */
1257 &GUID_NULL
/* typeid */
1259 { /* 0x27 - CSIDL_MYPICTURES */
1263 MAKEINTRESOURCEW(IDS_MYPICTURES
)
1265 { /* 0x28 - CSIDL_PROFILE */
1271 { /* 0x29 - CSIDL_SYSTEMX86 */
1272 &FOLDERID_SystemX86
,
1273 CSIDL_Type_SystemX86Path
,
1277 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1278 &FOLDERID_ProgramFilesX86
,
1280 ProgramFilesDirX86W
,
1283 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1284 &FOLDERID_ProgramFilesCommon
,
1287 Program_Files_Common_FilesW
,
1289 KF_CATEGORY_FIXED
, /* category */
1290 ProgramFilesCommonW
, /* name */
1291 NULL
, /* description */
1292 &GUID_NULL
, /* parent */
1293 NULL
, /* relative path */
1296 NULL
, /* localized */
1298 NULL
, /* security */
1301 &GUID_NULL
/* typeid */
1303 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1304 &FOLDERID_ProgramFilesCommonX86
,
1307 Program_Files_x86_Common_FilesW
1309 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1310 &FOLDERID_CommonTemplates
,
1311 CSIDL_Type_AllUsers
,
1315 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1316 &FOLDERID_PublicDocuments
,
1317 CSIDL_Type_AllUsers
,
1321 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1322 &FOLDERID_CommonAdminTools
,
1323 CSIDL_Type_AllUsers
,
1324 Common_Administrative_ToolsW
,
1325 Start_Menu_Admin_ToolsW
1327 { /* 0x30 - CSIDL_ADMINTOOLS */
1328 &FOLDERID_AdminTools
,
1330 Administrative_ToolsW
,
1331 Start_Menu_Admin_ToolsW
1333 { /* 0x31 - CSIDL_CONNECTIONS */
1334 &FOLDERID_ConnectionsFolder
,
1335 CSIDL_Type_Disallowed
,
1339 { /* 0x32 - unassigned */
1341 CSIDL_Type_Disallowed
,
1345 { /* 0x33 - unassigned */
1347 CSIDL_Type_Disallowed
,
1351 { /* 0x34 - unassigned */
1353 CSIDL_Type_Disallowed
,
1357 { /* 0x35 - CSIDL_COMMON_MUSIC */
1358 &FOLDERID_PublicMusic
,
1359 CSIDL_Type_AllUsers
,
1363 { /* 0x36 - CSIDL_COMMON_PICTURES */
1364 &FOLDERID_PublicPictures
,
1365 CSIDL_Type_AllUsers
,
1369 { /* 0x37 - CSIDL_COMMON_VIDEO */
1370 &FOLDERID_PublicVideos
,
1371 CSIDL_Type_AllUsers
,
1375 { /* 0x38 - CSIDL_RESOURCES */
1376 &FOLDERID_ResourceDir
,
1377 CSIDL_Type_WindowsPath
,
1381 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1382 &FOLDERID_LocalizedResourcesDir
,
1383 CSIDL_Type_NonExistent
,
1387 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1388 &FOLDERID_CommonOEMLinks
,
1389 CSIDL_Type_AllUsers
,
1393 { /* 0x3b - CSIDL_CDBURN_AREA */
1394 &FOLDERID_CDBurning
,
1397 Local_Settings_CD_BurningW
1399 { /* 0x3c unassigned */
1401 CSIDL_Type_Disallowed
,
1405 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1407 CSIDL_Type_Disallowed
, /* FIXME */
1411 { /* 0x3e - CSIDL_PROFILES */
1413 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1418 &FOLDERID_AddNewPrograms
,
1419 CSIDL_Type_Disallowed
,
1424 &FOLDERID_AppUpdates
,
1425 CSIDL_Type_Disallowed
,
1430 &FOLDERID_ChangeRemovePrograms
,
1431 CSIDL_Type_Disallowed
,
1436 &FOLDERID_ConflictFolder
,
1437 CSIDL_Type_Disallowed
,
1441 { /* 0x43 - CSIDL_CONTACTS */
1448 &FOLDERID_DeviceMetadataStore
,
1449 CSIDL_Type_Disallowed
, /* FIXME */
1460 &FOLDERID_DocumentsLibrary
,
1461 CSIDL_Type_Disallowed
, /* FIXME */
1465 { /* 0x47 - CSIDL_DOWNLOADS */
1466 &FOLDERID_Downloads
,
1473 CSIDL_Type_Disallowed
,
1478 &FOLDERID_GameTasks
,
1479 CSIDL_Type_Disallowed
, /* FIXME */
1484 &FOLDERID_HomeGroup
,
1485 CSIDL_Type_Disallowed
,
1490 &FOLDERID_ImplicitAppShortcuts
,
1491 CSIDL_Type_Disallowed
, /* FIXME */
1496 &FOLDERID_Libraries
,
1497 CSIDL_Type_Disallowed
, /* FIXME */
1501 { /* 0x4d - CSIDL_LINKS */
1507 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
1508 &FOLDERID_LocalAppDataLow
,
1514 &FOLDERID_MusicLibrary
,
1515 CSIDL_Type_Disallowed
, /* FIXME */
1520 &FOLDERID_OriginalImages
,
1521 CSIDL_Type_Disallowed
, /* FIXME */
1526 &FOLDERID_PhotoAlbums
,
1529 Pictures_Slide_ShowsW
1532 &FOLDERID_PicturesLibrary
,
1533 CSIDL_Type_Disallowed
, /* FIXME */
1538 &FOLDERID_Playlists
,
1544 &FOLDERID_ProgramFilesX64
,
1545 CSIDL_Type_NonExistent
,
1550 &FOLDERID_ProgramFilesCommonX64
,
1551 CSIDL_Type_NonExistent
,
1557 CSIDL_Type_CurrVer
, /* FIXME */
1562 &FOLDERID_PublicDownloads
,
1563 CSIDL_Type_AllUsers
,
1568 &FOLDERID_PublicGameTasks
,
1569 CSIDL_Type_AllUsers
,
1571 Microsoft_Windows_GameExplorerW
1574 &FOLDERID_PublicLibraries
,
1575 CSIDL_Type_AllUsers
,
1577 Microsoft_Windows_LibrariesW
1580 &FOLDERID_PublicRingtones
,
1581 CSIDL_Type_AllUsers
,
1583 Microsoft_Windows_RingtonesW
1586 &FOLDERID_QuickLaunch
,
1587 CSIDL_Type_Disallowed
, /* FIXME */
1592 &FOLDERID_RecordedTVLibrary
,
1593 CSIDL_Type_Disallowed
, /* FIXME */
1598 &FOLDERID_Ringtones
,
1599 CSIDL_Type_Disallowed
, /* FIXME */
1604 &FOLDERID_SampleMusic
,
1605 CSIDL_Type_AllUsers
,
1610 &FOLDERID_SamplePictures
,
1611 CSIDL_Type_AllUsers
,
1613 Pictures_Sample_PicturesW
1616 &FOLDERID_SamplePlaylists
,
1617 CSIDL_Type_AllUsers
,
1619 Music_Sample_PlaylistsW
1622 &FOLDERID_SampleVideos
,
1623 CSIDL_Type_AllUsers
,
1625 Videos_Sample_VideosW
1627 { /* 0x62 - CSIDL_SAVED_GAMES */
1628 &FOLDERID_SavedGames
,
1633 { /* 0x63 - CSIDL_SEARCHES */
1634 &FOLDERID_SavedSearches
,
1640 &FOLDERID_SEARCH_CSC
,
1641 CSIDL_Type_Disallowed
,
1646 &FOLDERID_SEARCH_MAPI
,
1647 CSIDL_Type_Disallowed
,
1652 &FOLDERID_SearchHome
,
1653 CSIDL_Type_Disallowed
,
1658 &FOLDERID_SidebarDefaultParts
,
1659 CSIDL_Type_Disallowed
, /* FIXME */
1664 &FOLDERID_SidebarParts
,
1665 CSIDL_Type_Disallowed
, /* FIXME */
1670 &FOLDERID_SyncManagerFolder
,
1671 CSIDL_Type_Disallowed
,
1676 &FOLDERID_SyncResultsFolder
,
1677 CSIDL_Type_Disallowed
,
1682 &FOLDERID_SyncSetupFolder
,
1683 CSIDL_Type_Disallowed
,
1688 &FOLDERID_UserPinned
,
1689 CSIDL_Type_Disallowed
, /* FIXME */
1694 &FOLDERID_UserProfiles
,
1700 &FOLDERID_UserProgramFiles
,
1701 CSIDL_Type_Disallowed
, /* FIXME */
1706 &FOLDERID_UserProgramFilesCommon
,
1707 CSIDL_Type_Disallowed
, /* FIXME */
1712 &FOLDERID_UsersFiles
,
1713 CSIDL_Type_Disallowed
,
1718 &FOLDERID_UsersLibraries
,
1719 CSIDL_Type_Disallowed
,
1724 &FOLDERID_VideosLibrary
,
1725 CSIDL_Type_Disallowed
, /* FIXME */
1731 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1733 /* Gets the value named value from the registry key
1734 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1735 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1736 * is assumed to be MAX_PATH WCHARs in length.
1737 * If it exists, expands the value and writes the expanded value to
1738 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1739 * Returns successful error code if the value was retrieved from the registry,
1740 * and a failure otherwise.
1742 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1743 LPCWSTR value
, LPWSTR path
)
1746 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1747 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1748 DWORD dwType
, dwPathLen
= MAX_PATH
;
1749 HKEY userShellFolderKey
, shellFolderKey
;
1751 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1756 strcpyW(shellFolderPath
, userPrefix
);
1757 PathAddBackslashW(shellFolderPath
);
1758 strcatW(shellFolderPath
, szSHFolders
);
1759 pShellFolderPath
= shellFolderPath
;
1760 strcpyW(userShellFolderPath
, userPrefix
);
1761 PathAddBackslashW(userShellFolderPath
);
1762 strcatW(userShellFolderPath
, szSHUserFolders
);
1763 pUserShellFolderPath
= userShellFolderPath
;
1767 pUserShellFolderPath
= szSHUserFolders
;
1768 pShellFolderPath
= szSHFolders
;
1771 if (RegCreateKeyW(rootKey
, pShellFolderPath
, &shellFolderKey
))
1773 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1776 if (RegCreateKeyW(rootKey
, pUserShellFolderPath
, &userShellFolderKey
))
1778 TRACE("Failed to create %s\n",
1779 debugstr_w(pUserShellFolderPath
));
1780 RegCloseKey(shellFolderKey
);
1784 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1785 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1789 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1790 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1792 WCHAR szTemp
[MAX_PATH
];
1794 _SHExpandEnvironmentStrings(path
, szTemp
);
1795 lstrcpynW(path
, szTemp
, MAX_PATH
);
1797 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1798 (strlenW(path
) + 1) * sizeof(WCHAR
));
1799 if (ret
!= ERROR_SUCCESS
)
1800 hr
= HRESULT_FROM_WIN32(ret
);
1806 RegCloseKey(shellFolderKey
);
1807 RegCloseKey(userShellFolderKey
);
1808 TRACE("returning 0x%08x\n", hr
);
1812 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1813 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1814 * - The entry's szDefaultPath may be either a string value or an integer
1815 * resource identifier. In the latter case, the string value of the resource
1817 * - Depending on the entry's type, the path may begin with an (unexpanded)
1818 * environment variable name. The caller is responsible for expanding
1819 * environment strings if so desired.
1820 * The types that are prepended with environment variables are:
1821 * CSIDL_Type_User: %USERPROFILE%
1822 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1823 * CSIDL_Type_CurrVer: %SystemDrive%
1824 * (Others might make sense too, but as yet are unneeded.)
1826 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1829 WCHAR resourcePath
[MAX_PATH
];
1830 LPCWSTR pDefaultPath
= NULL
;
1832 TRACE("0x%02x,%p\n", folder
, pszPath
);
1834 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1835 return E_INVALIDARG
;
1837 return E_INVALIDARG
;
1845 case CSIDL_PROGRAM_FILES
:
1846 case CSIDL_PROGRAM_FILESX86
:
1847 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1848 folder
= is_wow64
? CSIDL_PROGRAM_FILESX86
: CSIDL_PROGRAM_FILES
;
1850 case CSIDL_PROGRAM_FILES_COMMON
:
1851 case CSIDL_PROGRAM_FILES_COMMONX86
:
1852 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1853 folder
= is_wow64
? CSIDL_PROGRAM_FILES_COMMONX86
: CSIDL_PROGRAM_FILES_COMMON
;
1858 if (CSIDL_Data
[folder
].szDefaultPath
&&
1859 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1861 if (LoadStringW(shell32_hInstance
,
1862 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1865 pDefaultPath
= resourcePath
;
1869 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1870 debugstr_w(pszPath
));
1877 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1881 switch (CSIDL_Data
[folder
].type
)
1883 case CSIDL_Type_User
:
1884 strcpyW(pszPath
, UserProfileW
);
1886 case CSIDL_Type_AllUsers
:
1887 strcpyW(pszPath
, AllUsersProfileW
);
1889 case CSIDL_Type_CurrVer
:
1890 strcpyW(pszPath
, SystemDriveW
);
1893 ; /* no corresponding env. var, do nothing */
1897 PathAddBackslashW(pszPath
);
1898 strcatW(pszPath
, pDefaultPath
);
1901 TRACE("returning 0x%08x\n", hr
);
1905 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1906 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1907 * can be overridden in the HKLM\\szCurrentVersion key.
1908 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1909 * the registry, uses _SHGetDefaultValue to get the value.
1911 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1916 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1918 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1919 return E_INVALIDARG
;
1920 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1921 return E_INVALIDARG
;
1923 return E_INVALIDARG
;
1925 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1926 hr
= _SHGetDefaultValue(folder
, pszPath
);
1931 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hKey
))
1935 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1937 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1938 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1939 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1941 hr
= _SHGetDefaultValue(folder
, pszPath
);
1942 dwType
= REG_EXPAND_SZ
;
1945 case CSIDL_PROGRAM_FILESX86
:
1946 case CSIDL_PROGRAM_FILES_COMMONX86
:
1947 /* these two should never be set on 32-bit setups */
1951 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1952 if (!is_wow64
) break;
1956 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1957 (LPBYTE
)pszPath
, (strlenW(pszPath
)+1)*sizeof(WCHAR
));
1962 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1968 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1972 static LPWSTR
_GetUserSidStringFromToken(HANDLE Token
)
1974 char InfoBuffer
[64];
1975 PTOKEN_USER UserInfo
;
1979 UserInfo
= (PTOKEN_USER
) InfoBuffer
;
1980 if (! GetTokenInformation(Token
, TokenUser
, InfoBuffer
, sizeof(InfoBuffer
),
1983 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1985 UserInfo
= HeapAlloc(GetProcessHeap(), 0, InfoSize
);
1986 if (UserInfo
== NULL
)
1988 if (! GetTokenInformation(Token
, TokenUser
, UserInfo
, InfoSize
,
1991 HeapFree(GetProcessHeap(), 0, UserInfo
);
1996 if (! ConvertSidToStringSidW(UserInfo
->User
.Sid
, &SidStr
))
1999 if (UserInfo
!= (PTOKEN_USER
) InfoBuffer
)
2000 HeapFree(GetProcessHeap(), 0, UserInfo
);
2005 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
2006 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
2007 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
2008 * - if hToken is -1, looks in HKEY_USERS\.Default
2009 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
2010 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
2011 * calls _SHGetDefaultValue for it.
2013 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
2016 const WCHAR
*szValueName
;
2020 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
2022 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2023 return E_INVALIDARG
;
2024 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
2025 return E_INVALIDARG
;
2027 return E_INVALIDARG
;
2029 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
2031 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
2033 FIXME("unsupported for user other than current or default\n");
2036 hr
= _SHGetDefaultValue(folder
, pszPath
);
2040 LPCWSTR userPrefix
= NULL
;
2043 if (hToken
== (HANDLE
)-1)
2045 hRootKey
= HKEY_USERS
;
2046 userPrefix
= DefaultW
;
2048 else if (hToken
== NULL
)
2049 hRootKey
= HKEY_CURRENT_USER
;
2052 hRootKey
= HKEY_USERS
;
2053 userPrefix
= _GetUserSidStringFromToken(hToken
);
2054 if (userPrefix
== NULL
)
2061 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
2062 szValueName
= CSIDL_Data
[folder
].szValueName
;
2065 StringFromGUID2( CSIDL_Data
[folder
].id
, buffer
, 39 );
2066 szValueName
= &buffer
[0];
2069 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, szValueName
, pszPath
);
2070 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
2071 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, szValueName
, pszPath
);
2073 hr
= _SHGetDefaultValue(folder
, pszPath
);
2074 if (userPrefix
!= NULL
&& userPrefix
!= DefaultW
)
2075 LocalFree((HLOCAL
) userPrefix
);
2078 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
2082 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
2083 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
2084 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
2085 * If this fails, falls back to _SHGetDefaultValue.
2087 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
2092 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
2094 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2095 return E_INVALIDARG
;
2096 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
2097 return E_INVALIDARG
;
2099 return E_INVALIDARG
;
2101 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
2102 hr
= _SHGetDefaultValue(folder
, pszPath
);
2105 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
2106 CSIDL_Data
[folder
].szValueName
, pszPath
);
2108 hr
= _SHGetDefaultValue(folder
, pszPath
);
2110 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
2114 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
2119 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, NULL
, 0,
2120 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
2121 return HRESULT_FROM_WIN32(lRet
);
2124 /* Reads the value named szValueName from the key profilesKey (assumed to be
2125 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
2126 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
2127 * szDefault to the registry).
2129 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
2130 LPWSTR szValue
, LPCWSTR szDefault
)
2133 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2136 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
2137 debugstr_w(szDefault
));
2138 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
2139 (LPBYTE
)szValue
, &dwPathLen
);
2140 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
2143 dwPathLen
/= sizeof(WCHAR
);
2144 szValue
[dwPathLen
] = '\0';
2149 /* Missing or invalid value, set a default */
2150 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
2151 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
2152 debugstr_w(szValue
));
2153 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
2155 (strlenW(szValue
) + 1) * sizeof(WCHAR
));
2157 hr
= HRESULT_FROM_WIN32(lRet
);
2161 TRACE("returning 0x%08x (output value is %s)\n", hr
, debugstr_w(szValue
));
2165 /* Attempts to expand environment variables from szSrc into szDest, which is
2166 * assumed to be MAX_PATH characters in length. Before referring to the
2167 * environment, handles a few variables directly, because the environment
2168 * variables may not be set when this is called (as during Wine's installation
2169 * when default values are being written to the registry).
2170 * The directly handled environment variables, and their source, are:
2171 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
2172 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
2174 * If one of the directly handled environment variables is expanded, only
2175 * expands a single variable, and only in the beginning of szSrc.
2177 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
2180 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
2183 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
2185 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
2187 /* short-circuit if there's nothing to expand */
2188 if (szSrc
[0] != '%')
2190 strcpyW(szDest
, szSrc
);
2194 /* Get the profile prefix, we'll probably be needing it */
2195 hr
= _SHOpenProfilesKey(&key
);
2198 WCHAR def_val
[MAX_PATH
];
2200 /* get the system drive */
2201 GetSystemDirectoryW(def_val
, MAX_PATH
);
2202 if (def_val
[1] == ':') strcpyW( def_val
+ 3, szDefaultProfileDirW
);
2203 else FIXME("non-drive system paths unsupported\n");
2205 hr
= _SHGetProfilesValue(key
, ProfilesDirectoryW
, szProfilesPrefix
, def_val
);
2209 strcpyW(szTemp
, szSrc
);
2210 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
2212 if (!strncmpiW(szTemp
, AllUsersProfileW
, strlenW(AllUsersProfileW
)))
2214 WCHAR szAllUsers
[MAX_PATH
];
2216 strcpyW(szDest
, szProfilesPrefix
);
2217 hr
= _SHGetProfilesValue(key
, AllUsersProfileValueW
,
2218 szAllUsers
, AllUsersW
);
2219 PathAppendW(szDest
, szAllUsers
);
2220 PathAppendW(szDest
, szTemp
+ strlenW(AllUsersProfileW
));
2222 else if (!strncmpiW(szTemp
, UserProfileW
, strlenW(UserProfileW
)))
2224 WCHAR userName
[MAX_PATH
];
2225 DWORD userLen
= MAX_PATH
;
2227 strcpyW(szDest
, szProfilesPrefix
);
2228 GetUserNameW(userName
, &userLen
);
2229 PathAppendW(szDest
, userName
);
2230 PathAppendW(szDest
, szTemp
+ strlenW(UserProfileW
));
2232 else if (!strncmpiW(szTemp
, SystemDriveW
, strlenW(SystemDriveW
)))
2234 GetSystemDirectoryW(szDest
, MAX_PATH
);
2235 if (szDest
[1] != ':')
2237 FIXME("non-drive system paths unsupported\n");
2242 strcpyW(szDest
+ 3, szTemp
+ strlenW(SystemDriveW
) + 1);
2248 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
2251 hr
= E_NOT_SUFFICIENT_BUFFER
;
2253 hr
= HRESULT_FROM_WIN32(GetLastError());
2257 if (SUCCEEDED(hr
) && szDest
[0] == '%')
2258 strcpyW(szTemp
, szDest
);
2261 /* terminate loop */
2268 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr
,
2269 debugstr_w(szSrc
), debugstr_w(szDest
));
2273 /*************************************************************************
2274 * SHGetFolderPathW [SHELL32.@]
2276 * Convert nFolder to path.
2280 * Failure: standard HRESULT error codes.
2283 * Most values can be overridden in either
2284 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
2285 * or in the same location in HKLM.
2286 * The "Shell Folders" registry key was used in NT4 and earlier systems.
2287 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
2288 * changes made to it are made to the former key too. This synchronization is
2289 * done on-demand: not until someone requests the value of one of these paths
2290 * (by calling one of the SHGet functions) is the value synchronized.
2291 * Furthermore, the HKCU paths take precedence over the HKLM paths.
2293 HRESULT WINAPI
SHGetFolderPathW(
2294 HWND hwndOwner
, /* [I] owner window */
2295 int nFolder
, /* [I] CSIDL identifying the folder */
2296 HANDLE hToken
, /* [I] access token */
2297 DWORD dwFlags
, /* [I] which path to return */
2298 LPWSTR pszPath
) /* [O] converted path */
2300 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
2301 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
2302 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
2306 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
2307 HWND hwndOwner
, /* [I] owner window */
2308 int nFolder
, /* [I] CSIDL identifying the folder */
2309 HANDLE hToken
, /* [I] access token */
2310 DWORD dwFlags
, /* [I] which path to return */
2311 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
2312 LPSTR pszPath
) /* [O] converted path */
2316 LPWSTR pszSubPathW
= NULL
;
2317 LPWSTR pszPathW
= NULL
;
2318 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2321 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
2323 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2327 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2329 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
2330 * set (null), or an empty string.therefore call it without the parameter set
2331 * if pszSubPath is an empty string
2333 if (pszSubPath
&& pszSubPath
[0]) {
2334 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
2335 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
2337 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2340 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
2343 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
2345 if (SUCCEEDED(hr
) && pszPath
)
2346 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
2349 HeapFree(GetProcessHeap(), 0, pszPathW
);
2350 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
2354 /*************************************************************************
2355 * SHGetFolderPathAndSubDirW [SHELL32.@]
2357 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
2358 HWND hwndOwner
, /* [I] owner window */
2359 int nFolder
, /* [I] CSIDL identifying the folder */
2360 HANDLE hToken
, /* [I] access token */
2361 DWORD dwFlags
, /* [I] which path to return */
2362 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
2363 LPWSTR pszPath
) /* [O] converted path */
2366 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
2367 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2371 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
2373 /* Windows always NULL-terminates the resulting path regardless of success
2374 * or failure, so do so first
2379 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2380 return E_INVALIDARG
;
2381 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
2382 return E_INVALIDARG
;
2384 type
= CSIDL_Data
[folder
].type
;
2387 case CSIDL_Type_Disallowed
:
2390 case CSIDL_Type_NonExistent
:
2393 case CSIDL_Type_WindowsPath
:
2394 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
2395 if (CSIDL_Data
[folder
].szDefaultPath
&&
2396 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2397 *CSIDL_Data
[folder
].szDefaultPath
)
2399 PathAddBackslashW(szTemp
);
2400 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2404 case CSIDL_Type_SystemPath
:
2405 GetSystemDirectoryW(szTemp
, MAX_PATH
);
2406 if (CSIDL_Data
[folder
].szDefaultPath
&&
2407 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2408 *CSIDL_Data
[folder
].szDefaultPath
)
2410 PathAddBackslashW(szTemp
);
2411 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2415 case CSIDL_Type_SystemX86Path
:
2416 if (!GetSystemWow64DirectoryW(szTemp
, MAX_PATH
)) GetSystemDirectoryW(szTemp
, MAX_PATH
);
2417 if (CSIDL_Data
[folder
].szDefaultPath
&&
2418 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2419 *CSIDL_Data
[folder
].szDefaultPath
)
2421 PathAddBackslashW(szTemp
);
2422 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2426 case CSIDL_Type_CurrVer
:
2427 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
2429 case CSIDL_Type_User
:
2430 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
2432 case CSIDL_Type_AllUsers
:
2433 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
2436 FIXME("bogus type %d, please fix\n", type
);
2441 /* Expand environment strings if necessary */
2443 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
2445 strcpyW(szBuildPath
, szTemp
);
2447 if (FAILED(hr
)) goto end
;
2450 /* make sure the new path does not exceed the buffer length
2451 * and remember to backslash and terminate it */
2452 if(MAX_PATH
< (lstrlenW(szBuildPath
) + lstrlenW(pszSubPath
) + 2)) {
2453 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
2456 PathAppendW(szBuildPath
, pszSubPath
);
2457 PathRemoveBackslashW(szBuildPath
);
2459 /* Copy the path if it's available before we might return */
2460 if (SUCCEEDED(hr
) && pszPath
)
2461 strcpyW(pszPath
, szBuildPath
);
2463 /* if we don't care about existing directories we are ready */
2464 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
2466 if (PathFileExistsW(szBuildPath
)) goto end
;
2468 /* not existing but we are not allowed to create it. The return value
2469 * is verified against shell32 version 6.0.
2471 if (!(nFolder
& CSIDL_FLAG_CREATE
))
2473 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2477 /* create directory/directories */
2478 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
2479 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
2481 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
2486 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
2488 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
2492 /*************************************************************************
2493 * SHGetFolderPathA [SHELL32.@]
2495 * See SHGetFolderPathW.
2497 HRESULT WINAPI
SHGetFolderPathA(
2504 WCHAR szTemp
[MAX_PATH
];
2507 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
2511 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
2512 if (SUCCEEDED(hr
) && pszPath
)
2513 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
2519 /* For each folder in folders, if its value has not been set in the registry,
2520 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
2521 * folder's type) to get the unexpanded value first.
2522 * Writes the unexpanded value to User Shell Folders, and queries it with
2523 * SHGetFolderPathW to force the creation of the directory if it doesn't
2524 * already exist. SHGetFolderPathW also returns the expanded value, which
2525 * this then writes to Shell Folders.
2527 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
2528 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
2531 const WCHAR
*szValueName
;
2534 WCHAR path
[MAX_PATH
];
2536 HKEY hUserKey
= NULL
, hKey
= NULL
;
2537 DWORD dwType
, dwPathLen
;
2540 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
2541 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
2543 ret
= RegCreateKeyW(hRootKey
, szUserShellFolderPath
, &hUserKey
);
2545 hr
= HRESULT_FROM_WIN32(ret
);
2548 ret
= RegCreateKeyW(hRootKey
, szShellFolderPath
, &hKey
);
2550 hr
= HRESULT_FROM_WIN32(ret
);
2552 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
2554 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2556 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
2557 szValueName
= CSIDL_Data
[folders
[i
]].szValueName
;
2558 if (!szValueName
&& CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2560 StringFromGUID2( CSIDL_Data
[folders
[i
]].id
, buffer
, 39 );
2561 szValueName
= &buffer
[0];
2564 if (RegQueryValueExW(hUserKey
, szValueName
, NULL
,
2565 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
2566 dwType
!= REG_EXPAND_SZ
))
2569 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2570 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
2572 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
2573 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
2574 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
2576 GetWindowsDirectoryW(path
, MAX_PATH
);
2577 if (CSIDL_Data
[folders
[i
]].szDefaultPath
&&
2578 !IS_INTRESOURCE(CSIDL_Data
[folders
[i
]].szDefaultPath
))
2580 PathAddBackslashW(path
);
2581 strcatW(path
, CSIDL_Data
[folders
[i
]].szDefaultPath
);
2588 ret
= RegSetValueExW(hUserKey
, szValueName
, 0, REG_EXPAND_SZ
,
2589 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2591 hr
= HRESULT_FROM_WIN32(ret
);
2594 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
2595 hToken
, SHGFP_TYPE_DEFAULT
, path
);
2596 ret
= RegSetValueExW(hKey
, szValueName
, 0, REG_SZ
,
2597 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2599 hr
= HRESULT_FROM_WIN32(ret
);
2605 RegCloseKey(hUserKey
);
2609 TRACE("returning 0x%08x\n", hr
);
2613 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
2615 static const UINT folders
[] = {
2626 CSIDL_DESKTOPDIRECTORY
,
2630 CSIDL_LOCAL_APPDATA
,
2631 CSIDL_INTERNET_CACHE
,
2640 CSIDL_APPDATA_LOCALLOW
,
2644 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
2645 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
2650 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
2653 hToken
= (HANDLE
)-1;
2654 hRootKey
= HKEY_USERS
;
2655 strcpyW(userShellFolderPath
, DefaultW
);
2656 PathAddBackslashW(userShellFolderPath
);
2657 strcatW(userShellFolderPath
, szSHUserFolders
);
2658 pUserShellFolderPath
= userShellFolderPath
;
2659 strcpyW(shellFolderPath
, DefaultW
);
2660 PathAddBackslashW(shellFolderPath
);
2661 strcatW(shellFolderPath
, szSHFolders
);
2662 pShellFolderPath
= shellFolderPath
;
2667 hRootKey
= HKEY_CURRENT_USER
;
2668 pUserShellFolderPath
= szSHUserFolders
;
2669 pShellFolderPath
= szSHFolders
;
2672 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
2673 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2674 TRACE("returning 0x%08x\n", hr
);
2678 static HRESULT
_SHRegisterCommonShellFolders(void)
2680 static const UINT folders
[] = {
2681 CSIDL_COMMON_STARTMENU
,
2682 CSIDL_COMMON_PROGRAMS
,
2683 CSIDL_COMMON_STARTUP
,
2684 CSIDL_COMMON_DESKTOPDIRECTORY
,
2685 CSIDL_COMMON_FAVORITES
,
2686 CSIDL_COMMON_APPDATA
,
2687 CSIDL_COMMON_TEMPLATES
,
2688 CSIDL_COMMON_DOCUMENTS
,
2689 CSIDL_COMMON_ADMINTOOLS
,
2691 CSIDL_COMMON_PICTURES
,
2697 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
2698 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2699 TRACE("returning 0x%08x\n", hr
);
2703 /******************************************************************************
2704 * _SHAppendToUnixPath [Internal]
2706 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
2707 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
2708 * and replaces backslashes with slashes.
2711 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
2712 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
2718 static inline BOOL
_SHAppendToUnixPath(char *szBasePath
, LPCWSTR pwszSubPath
) {
2719 WCHAR wszSubPath
[MAX_PATH
];
2720 int cLen
= strlen(szBasePath
);
2723 if (IS_INTRESOURCE(pwszSubPath
)) {
2724 if (!LoadStringW(shell32_hInstance
, LOWORD(pwszSubPath
), wszSubPath
, MAX_PATH
)) {
2725 /* Fall back to hard coded defaults. */
2726 switch (LOWORD(pwszSubPath
)) {
2728 lstrcpyW(wszSubPath
, DocumentsW
);
2731 lstrcpyW(wszSubPath
, My_MusicW
);
2733 case IDS_MYPICTURES
:
2734 lstrcpyW(wszSubPath
, My_PicturesW
);
2737 lstrcpyW(wszSubPath
, My_VideosW
);
2740 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath
));
2745 lstrcpyW(wszSubPath
, pwszSubPath
);
2748 if (szBasePath
[cLen
-1] != '/') szBasePath
[cLen
++] = '/';
2750 if (!WideCharToMultiByte(CP_UNIXCP
, 0, wszSubPath
, -1, szBasePath
+ cLen
,
2751 FILENAME_MAX
- cLen
, NULL
, NULL
))
2756 pBackslash
= szBasePath
+ cLen
;
2757 while ((pBackslash
= strchr(pBackslash
, '\\'))) *pBackslash
= '/';
2762 /******************************************************************************
2763 * _SHCreateSymbolicLinks [Internal]
2765 * Sets up symbol links for various shell folders to point into the users home
2766 * directory. We do an educated guess about what the user would probably want:
2767 * - If there is a 'My Documents' directory in $HOME, the user probably wants
2768 * wine's 'My Documents' to point there. Furthermore, we imply that the user
2769 * is a Windows lover and has no problem with wine creating 'My Pictures',
2770 * 'My Music' and 'My Videos' subfolders under '$HOME/My Documents', if those
2771 * do not already exits. We put appropriate symbolic links in place for those,
2773 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2774 * point directly to $HOME. We assume the user to be a unix hacker who does not
2775 * want wine to create anything anywhere besides the .wine directory. So, if
2776 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2777 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
2778 * directory, and try to link to that. If that fails, then we symlink to
2779 * $HOME directly. The same holds fo 'My Pictures' and 'My Videos'.
2780 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
2781 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
2783 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2785 static void _SHCreateSymbolicLinks(void)
2787 UINT aidsMyStuff
[] = { IDS_MYPICTURES
, IDS_MYVIDEOS
, IDS_MYMUSIC
}, i
;
2788 int acsidlMyStuff
[] = { CSIDL_MYPICTURES
, CSIDL_MYVIDEO
, CSIDL_MYMUSIC
};
2789 static const char * const xdg_dirs
[] = { "PICTURES", "VIDEOS", "MUSIC", "DESKTOP" };
2790 static const unsigned int num
= sizeof(xdg_dirs
) / sizeof(xdg_dirs
[0]);
2791 WCHAR wszTempPath
[MAX_PATH
];
2792 char szPersonalTarget
[FILENAME_MAX
], *pszPersonal
;
2793 char szMyStuffTarget
[FILENAME_MAX
], *pszMyStuff
;
2794 char szDesktopTarget
[FILENAME_MAX
], *pszDesktop
;
2795 struct stat statFolder
;
2796 const char *pszHome
;
2798 char ** xdg_results
;
2799 char * xdg_desktop_dir
;
2801 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2802 hr
= SHGetFolderPathW(NULL
, CSIDL_PERSONAL
|CSIDL_FLAG_CREATE
, NULL
,
2803 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2804 if (FAILED(hr
)) return;
2805 pszPersonal
= wine_get_unix_file_name(wszTempPath
);
2806 if (!pszPersonal
) return;
2808 hr
= XDG_UserDirLookup(xdg_dirs
, num
, &xdg_results
);
2809 if (FAILED(hr
)) xdg_results
= NULL
;
2811 pszHome
= getenv("HOME");
2812 if (pszHome
&& !stat(pszHome
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)) {
2813 strcpy(szPersonalTarget
, pszHome
);
2814 if (_SHAppendToUnixPath(szPersonalTarget
, MAKEINTRESOURCEW(IDS_PERSONAL
)) &&
2815 !stat(szPersonalTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2817 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2818 * 'My Music' subfolders or fail silently if they already exist. */
2819 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2820 strcpy(szMyStuffTarget
, szPersonalTarget
);
2821 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2822 mkdir(szMyStuffTarget
, 0777);
2827 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2828 strcpy(szPersonalTarget
, pszHome
);
2831 /* Replace 'My Documents' directory with a symlink or fail silently if not empty. */
2833 symlink(szPersonalTarget
, pszPersonal
);
2837 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2838 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2840 strcpy(szPersonalTarget
, pszPersonal
);
2841 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2842 strcpy(szMyStuffTarget
, szPersonalTarget
);
2843 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2844 mkdir(szMyStuffTarget
, 0777);
2848 /* Create symbolic links for 'My Pictures', 'My Videos' and 'My Music'. */
2849 for (i
=0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2850 /* Create the current 'My Whatever' folder and get its unix path. */
2851 hr
= SHGetFolderPathW(NULL
, acsidlMyStuff
[i
]|CSIDL_FLAG_CREATE
, NULL
,
2852 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2853 if (FAILED(hr
)) continue;
2854 pszMyStuff
= wine_get_unix_file_name(wszTempPath
);
2855 if (!pszMyStuff
) continue;
2857 strcpy(szMyStuffTarget
, szPersonalTarget
);
2858 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])) &&
2859 !stat(szMyStuffTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2861 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2863 symlink(szMyStuffTarget
, pszMyStuff
);
2868 if (xdg_results
&& xdg_results
[i
])
2870 /* the folder specified by XDG_XXX_DIR exists, link to it. */
2871 symlink(xdg_results
[i
], pszMyStuff
);
2875 /* Else link to where 'My Documents' itself links to. */
2876 symlink(szPersonalTarget
, pszMyStuff
);
2879 HeapFree(GetProcessHeap(), 0, pszMyStuff
);
2882 /* Last but not least, the Desktop folder */
2884 strcpy(szDesktopTarget
, pszHome
);
2886 strcpy(szDesktopTarget
, pszPersonal
);
2887 HeapFree(GetProcessHeap(), 0, pszPersonal
);
2889 xdg_desktop_dir
= xdg_results
? xdg_results
[num
- 1] : NULL
;
2890 if (xdg_desktop_dir
||
2891 (_SHAppendToUnixPath(szDesktopTarget
, DesktopW
) &&
2892 !stat(szDesktopTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)))
2894 hr
= SHGetFolderPathW(NULL
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, NULL
,
2895 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2896 if (SUCCEEDED(hr
) && (pszDesktop
= wine_get_unix_file_name(wszTempPath
)))
2899 if (xdg_desktop_dir
)
2900 symlink(xdg_desktop_dir
, pszDesktop
);
2902 symlink(szDesktopTarget
, pszDesktop
);
2903 HeapFree(GetProcessHeap(), 0, pszDesktop
);
2907 /* Free resources allocated by XDG_UserDirLookup() */
2910 for (i
= 0; i
< num
; i
++)
2911 HeapFree(GetProcessHeap(), 0, xdg_results
[i
]);
2912 HeapFree(GetProcessHeap(), 0, xdg_results
);
2916 /******************************************************************************
2917 * create_extra_folders [Internal]
2919 * Create some extra folders that don't have a standard CSIDL definition.
2921 static HRESULT
create_extra_folders(void)
2923 static const WCHAR environW
[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
2924 static const WCHAR microsoftW
[] = {'M','i','c','r','o','s','o','f','t',0};
2925 static const WCHAR TempW
[] = {'T','e','m','p',0};
2926 static const WCHAR TEMPW
[] = {'T','E','M','P',0};
2927 static const WCHAR TMPW
[] = {'T','M','P',0};
2928 WCHAR path
[MAX_PATH
+5];
2931 DWORD type
, size
, ret
;
2933 ret
= RegCreateKeyW( HKEY_CURRENT_USER
, environW
, &hkey
);
2934 if (ret
) return HRESULT_FROM_WIN32( ret
);
2936 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
2937 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
,
2938 SHGFP_TYPE_DEFAULT
, TempW
, path
);
2941 size
= sizeof(path
);
2942 if (RegQueryValueExW( hkey
, TEMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2943 RegSetValueExW( hkey
, TEMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2944 size
= sizeof(path
);
2945 if (RegQueryValueExW( hkey
, TMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2946 RegSetValueExW( hkey
, TMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2948 RegCloseKey( hkey
);
2952 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA
| CSIDL_FLAG_CREATE
, NULL
,
2953 SHGFP_TYPE_DEFAULT
, microsoftW
, path
);
2959 /******************************************************************************
2960 * set_folder_attributes
2962 * Set the various folder attributes registry keys.
2964 static HRESULT
set_folder_attributes(void)
2966 static const WCHAR clsidW
[] = {'C','L','S','I','D','\\',0 };
2967 static const WCHAR shellfolderW
[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
2968 static const WCHAR wfparsingW
[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
2969 static const WCHAR wfdisplayW
[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
2970 static const WCHAR hideasdeleteW
[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
2971 static const WCHAR cfattributesW
[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
2972 static const WCHAR emptyW
[] = {0};
2981 DWORD call_for_attr
;
2984 { &CLSID_UnixFolder
, TRUE
, FALSE
, FALSE
},
2985 { &CLSID_UnixDosFolder
, TRUE
, FALSE
, FALSE
,
2986 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2987 { &CLSID_FolderShortcut
, FALSE
, FALSE
, FALSE
,
2988 SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_LINK
,
2989 SFGAO_HASSUBFOLDER
|SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_FILESYSANCESTOR
},
2990 { &CLSID_MyDocuments
, TRUE
, FALSE
, FALSE
,
2991 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2992 { &CLSID_RecycleBin
, FALSE
, FALSE
, FALSE
,
2993 SFGAO_FOLDER
|SFGAO_DROPTARGET
|SFGAO_HASPROPSHEET
},
2994 { &CLSID_ControlPanel
, FALSE
, TRUE
, TRUE
,
2995 SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
}
2999 WCHAR buffer
[39 + (sizeof(clsidW
) + sizeof(shellfolderW
)) / sizeof(WCHAR
)];
3003 for (i
= 0; i
< sizeof(folders
)/sizeof(folders
[0]); i
++)
3005 strcpyW( buffer
, clsidW
);
3006 StringFromGUID2( folders
[i
].clsid
, buffer
+ strlenW(buffer
), 39 );
3007 strcatW( buffer
, shellfolderW
);
3008 res
= RegCreateKeyExW( HKEY_CLASSES_ROOT
, buffer
, 0, NULL
, 0,
3009 KEY_READ
| KEY_WRITE
, NULL
, &hkey
, NULL
);
3010 if (res
) return HRESULT_FROM_WIN32( res
);
3011 if (folders
[i
].wfparsing
)
3012 res
= RegSetValueExW( hkey
, wfparsingW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
3013 if (folders
[i
].wfdisplay
)
3014 res
= RegSetValueExW( hkey
, wfdisplayW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
3015 if (folders
[i
].hideasdel
)
3016 res
= RegSetValueExW( hkey
, hideasdeleteW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
3017 if (folders
[i
].attr
)
3018 res
= RegSetValueExW( hkey
, szAttributes
, 0, REG_DWORD
,
3019 (const BYTE
*)&folders
[i
].attr
, sizeof(DWORD
));
3020 if (folders
[i
].call_for_attr
)
3021 res
= RegSetValueExW( hkey
, cfattributesW
, 0, REG_DWORD
,
3022 (const BYTE
*)&folders
[i
].call_for_attr
, sizeof(DWORD
));
3023 RegCloseKey( hkey
);
3028 /*************************************************************************
3029 * SHGetSpecialFolderPathA [SHELL32.@]
3031 BOOL WINAPI
SHGetSpecialFolderPathA (
3037 return SHGetFolderPathA(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
3041 /*************************************************************************
3042 * SHGetSpecialFolderPathW
3044 BOOL WINAPI
SHGetSpecialFolderPathW (
3050 return SHGetFolderPathW(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
3054 /*************************************************************************
3055 * SHGetSpecialFolderPath (SHELL32.175)
3057 BOOL WINAPI
SHGetSpecialFolderPathAW (
3064 if (SHELL_OsIsUnicode())
3065 return SHGetSpecialFolderPathW (hwndOwner
, szPath
, nFolder
, bCreate
);
3066 return SHGetSpecialFolderPathA (hwndOwner
, szPath
, nFolder
, bCreate
);
3069 /*************************************************************************
3070 * SHGetFolderLocation [SHELL32.@]
3072 * Gets the folder locations from the registry and creates a pidl.
3076 * nFolder [I] CSIDL_xxxxx
3077 * hToken [I] token representing user, or NULL for current user, or -1 for
3079 * dwReserved [I] must be zero
3080 * ppidl [O] PIDL of a special folder
3084 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
3087 * Creates missing reg keys and directories.
3088 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
3089 * virtual folders that are handled here.
3091 HRESULT WINAPI
SHGetFolderLocation(
3096 LPITEMIDLIST
*ppidl
)
3098 HRESULT hr
= E_INVALIDARG
;
3100 TRACE("%p 0x%08x %p 0x%08x %p\n",
3101 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
3104 return E_INVALIDARG
;
3106 return E_INVALIDARG
;
3108 /* The virtual folders' locations are not user-dependent */
3110 switch (nFolder
& CSIDL_FOLDER_MASK
)
3113 *ppidl
= _ILCreateDesktop();
3116 case CSIDL_PERSONAL
:
3117 *ppidl
= _ILCreateMyDocuments();
3120 case CSIDL_INTERNET
:
3121 *ppidl
= _ILCreateIExplore();
3124 case CSIDL_CONTROLS
:
3125 *ppidl
= _ILCreateControlPanel();
3128 case CSIDL_PRINTERS
:
3129 *ppidl
= _ILCreatePrinters();
3132 case CSIDL_BITBUCKET
:
3133 *ppidl
= _ILCreateBitBucket();
3137 *ppidl
= _ILCreateMyComputer();
3141 *ppidl
= _ILCreateNetwork();
3146 WCHAR szPath
[MAX_PATH
];
3148 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
3149 SHGFP_TYPE_CURRENT
, szPath
);
3154 TRACE("Value=%s\n", debugstr_w(szPath
));
3155 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
3157 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
3159 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
3160 * version 6.0 returns E_FAIL for nonexistent paths
3169 TRACE("-- (new pidl %p)\n",*ppidl
);
3173 /*************************************************************************
3174 * SHGetSpecialFolderLocation [SHELL32.@]
3177 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
3180 HRESULT WINAPI
SHGetSpecialFolderLocation(
3183 LPITEMIDLIST
* ppidl
)
3185 HRESULT hr
= E_INVALIDARG
;
3187 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
3190 return E_INVALIDARG
;
3192 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);
3196 static int csidl_from_id( const KNOWNFOLDERID
*id
)
3199 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
3200 if (IsEqualGUID( CSIDL_Data
[i
].id
, id
)) return i
;
3204 /*************************************************************************
3205 * SHGetKnownFolderPath [SHELL32.@]
3207 HRESULT WINAPI
SHGetKnownFolderPath(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PWSTR
*path
)
3210 WCHAR folder
[MAX_PATH
];
3211 int index
= csidl_from_id( rfid
);
3213 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid
), flags
, token
, path
);
3218 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND
);
3220 if (flags
& KF_FLAG_CREATE
)
3221 index
|= CSIDL_FLAG_CREATE
;
3223 if (flags
& KF_FLAG_DONT_VERIFY
)
3224 index
|= CSIDL_FLAG_DONT_VERIFY
;
3226 if (flags
& KF_FLAG_NO_ALIAS
)
3227 index
|= CSIDL_FLAG_NO_ALIAS
;
3229 if (flags
& KF_FLAG_INIT
)
3230 index
|= CSIDL_FLAG_PER_USER_INIT
;
3232 if (flags
& ~(KF_FLAG_CREATE
|KF_FLAG_DONT_VERIFY
|KF_FLAG_NO_ALIAS
|KF_FLAG_INIT
))
3234 FIXME("flags 0x%08x not supported\n", flags
);
3235 return E_INVALIDARG
;
3238 hr
= SHGetFolderPathW( NULL
, index
, token
, 0, folder
);
3241 *path
= CoTaskMemAlloc( (strlenW( folder
) + 1) * sizeof(WCHAR
) );
3243 return E_OUTOFMEMORY
;
3244 strcpyW( *path
, folder
);
3249 /*************************************************************************
3250 * SHGetFolderPathEx [SHELL32.@]
3252 HRESULT WINAPI
SHGetFolderPathEx(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, LPWSTR path
, DWORD len
)
3257 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid
), flags
, token
, path
, len
);
3259 if (!path
|| !len
) return E_INVALIDARG
;
3261 hr
= SHGetKnownFolderPath( rfid
, flags
, token
, &buffer
);
3262 if (SUCCEEDED( hr
))
3264 if (strlenW( buffer
) + 1 > len
)
3266 CoTaskMemFree( buffer
);
3267 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER
);
3269 strcpyW( path
, buffer
);
3270 CoTaskMemFree( buffer
);
3276 * Internal function to convert known folder identifier to path of registry key
3277 * associated with known folder.
3280 * rfid [I] pointer to known folder identifier (may be NULL)
3281 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
3282 * lpPath [O] place to store string address. String should be
3283 * later freed using HeapFree(GetProcessHeap(),0, ... )
3285 static HRESULT
get_known_folder_registry_path(
3286 REFKNOWNFOLDERID rfid
,
3287 LPWSTR lpStringGuid
,
3290 static const WCHAR sBackslash
[] = {'\\',0};
3295 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid
), debugstr_w(lpStringGuid
), lpPath
);
3298 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3300 lstrcpyW(sGuid
, lpStringGuid
);
3302 length
= lstrlenW(szKnownFolderDescriptions
)+51;
3303 *lpPath
= HeapAlloc(GetProcessHeap(), 0, length
*sizeof(WCHAR
));
3309 lstrcpyW(*lpPath
, szKnownFolderDescriptions
);
3310 lstrcatW(*lpPath
, sBackslash
);
3311 lstrcatW(*lpPath
, sGuid
);
3317 static HRESULT
get_known_folder_wstr(const WCHAR
*regpath
, const WCHAR
*value
, WCHAR
**out
)
3323 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, regpath
, value
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
));
3327 *out
= CoTaskMemAlloc(size
);
3329 return E_OUTOFMEMORY
;
3331 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, regpath
, value
, RRF_RT_REG_SZ
, NULL
, *out
, &size
));
3333 CoTaskMemFree(*out
);
3340 static HRESULT
get_known_folder_dword(const WCHAR
*registryPath
, const WCHAR
*value
, DWORD
*out
)
3342 DWORD dwSize
= sizeof(DWORD
);
3344 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, value
, RRF_RT_DWORD
, &dwType
, out
, &dwSize
));
3348 * Internal function to get place where folder redirection information are stored.
3351 * rfid [I] pointer to known folder identifier (may be NULL)
3352 * rootKey [O] root key where the redirection information are stored
3353 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
3354 * However, besides root key, path is always that same, and is stored
3355 * as "szKnownFolderRedirections" constant
3357 static HRESULT
get_known_folder_redirection_place(
3358 REFKNOWNFOLDERID rfid
,
3362 LPWSTR lpRegistryPath
= NULL
;
3363 KF_CATEGORY category
;
3365 /* first, get known folder's category */
3366 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3369 hr
= get_known_folder_dword(lpRegistryPath
, szCategory
, &category
);
3373 if(category
== KF_CATEGORY_COMMON
)
3375 *rootKey
= HKEY_LOCAL_MACHINE
;
3378 else if(category
== KF_CATEGORY_PERUSER
)
3380 *rootKey
= HKEY_CURRENT_USER
;
3387 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3391 static HRESULT
get_known_folder_path_by_id(REFKNOWNFOLDERID folderId
, LPWSTR lpRegistryPath
, DWORD dwFlags
, LPWSTR
*ppszPath
);
3393 static HRESULT
redirect_known_folder(
3394 REFKNOWNFOLDERID rfid
,
3396 KF_REDIRECT_FLAGS flags
,
3397 LPCWSTR pszTargetPath
,
3399 KNOWNFOLDERID
const *pExclusion
,
3403 HKEY rootKey
= HKEY_LOCAL_MACHINE
, hKey
;
3405 LPWSTR lpRegistryPath
= NULL
, lpSrcPath
= NULL
;
3406 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid
), hwnd
, flags
, debugstr_w(pszTargetPath
), cFolders
, pExclusion
, ppszError
);
3408 if (ppszError
) *ppszError
= NULL
;
3410 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3413 hr
= get_known_folder_path_by_id(rfid
, lpRegistryPath
, 0, &lpSrcPath
);
3415 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3417 /* get path to redirection storage */
3419 hr
= get_known_folder_redirection_place(rfid
, &rootKey
);
3421 /* write redirection information */
3423 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey
, szKnownFolderRedirections
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hKey
, NULL
));
3427 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3429 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, sGuid
, 0, REG_SZ
, (LPBYTE
)pszTargetPath
, (lstrlenW(pszTargetPath
)+1)*sizeof(WCHAR
)));
3434 /* make sure destination path exists */
3435 SHCreateDirectory(NULL
, pszTargetPath
);
3437 /* copy content if required */
3438 if(SUCCEEDED(hr
) && (flags
& KF_REDIRECT_COPY_CONTENTS
) )
3440 static const WCHAR sWildcard
[] = {'\\','*',0};
3441 WCHAR srcPath
[MAX_PATH
+1], dstPath
[MAX_PATH
+1];
3442 SHFILEOPSTRUCTW fileOp
;
3444 ZeroMemory(srcPath
, sizeof(srcPath
));
3445 lstrcpyW(srcPath
, lpSrcPath
);
3446 lstrcatW(srcPath
, sWildcard
);
3448 ZeroMemory(dstPath
, sizeof(dstPath
));
3449 lstrcpyW(dstPath
, pszTargetPath
);
3451 ZeroMemory(&fileOp
, sizeof(fileOp
));
3453 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3454 fileOp
.wFunc
= FO_MOVE
;
3456 fileOp
.wFunc
= FO_COPY
;
3458 fileOp
.pFrom
= srcPath
;
3459 fileOp
.pTo
= dstPath
;
3460 fileOp
.fFlags
= FOF_NO_UI
;
3462 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3464 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3466 ZeroMemory(srcPath
, sizeof(srcPath
));
3467 lstrcpyW(srcPath
, lpSrcPath
);
3469 ZeroMemory(&fileOp
, sizeof(fileOp
));
3470 fileOp
.wFunc
= FO_DELETE
;
3471 fileOp
.pFrom
= srcPath
;
3472 fileOp
.fFlags
= FOF_NO_UI
;
3474 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3478 CoTaskMemFree(lpSrcPath
);
3486 IKnownFolder IKnownFolder_iface
;
3489 LPWSTR registryPath
;
3492 static inline struct knownfolder
*impl_from_IKnownFolder( IKnownFolder
*iface
)
3494 return CONTAINING_RECORD( iface
, struct knownfolder
, IKnownFolder_iface
);
3497 static ULONG WINAPI
knownfolder_AddRef(
3498 IKnownFolder
*iface
)
3500 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3501 return InterlockedIncrement( &knownfolder
->refs
);
3504 static ULONG WINAPI
knownfolder_Release(
3505 IKnownFolder
*iface
)
3507 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3508 LONG refs
= InterlockedDecrement( &knownfolder
->refs
);
3511 TRACE("destroying %p\n", knownfolder
);
3512 HeapFree( GetProcessHeap(), 0, knownfolder
->registryPath
);
3513 HeapFree( GetProcessHeap(), 0, knownfolder
);
3518 static HRESULT WINAPI
knownfolder_QueryInterface(
3519 IKnownFolder
*iface
,
3523 struct knownfolder
*This
= impl_from_IKnownFolder( iface
);
3525 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3527 if ( IsEqualGUID( riid
, &IID_IKnownFolder
) ||
3528 IsEqualGUID( riid
, &IID_IUnknown
) )
3534 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3535 return E_NOINTERFACE
;
3537 IKnownFolder_AddRef( iface
);
3541 static HRESULT
knownfolder_set_id(
3542 struct knownfolder
*knownfolder
,
3543 const KNOWNFOLDERID
*kfid
)
3548 TRACE("%s\n", debugstr_guid(kfid
));
3550 knownfolder
->id
= *kfid
;
3552 /* check is it registry-registered folder */
3553 hr
= get_known_folder_registry_path(kfid
, NULL
, &knownfolder
->registryPath
);
3555 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, 0, 0, &hKey
));
3564 /* This known folder is not registered. To mark it, we set registryPath to NULL */
3565 HeapFree(GetProcessHeap(), 0, knownfolder
->registryPath
);
3566 knownfolder
->registryPath
= NULL
;
3573 static HRESULT WINAPI
knownfolder_GetId(
3574 IKnownFolder
*iface
,
3575 KNOWNFOLDERID
*pkfid
)
3577 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3579 TRACE("%p\n", pkfid
);
3581 *pkfid
= knownfolder
->id
;
3585 static HRESULT WINAPI
knownfolder_GetCategory(
3586 IKnownFolder
*iface
,
3587 KF_CATEGORY
*pCategory
)
3589 struct knownfolder
*knownfolder
= impl_from_IKnownFolder(iface
);
3592 TRACE("%p, %p\n", knownfolder
, pCategory
);
3594 /* we cannot get a category for a folder which is not registered */
3595 if(!knownfolder
->registryPath
)
3599 hr
= get_known_folder_dword(knownfolder
->registryPath
, szCategory
, pCategory
);
3604 static HRESULT WINAPI
knownfolder_GetShellItem(
3605 IKnownFolder
*iface
,
3610 FIXME("0x%08x, %s, %p\n", dwFlags
, debugstr_guid(riid
), ppv
);
3614 static HRESULT
get_known_folder_path(
3616 LPWSTR registryPath
,
3619 static const WCHAR sBackslash
[] = {'\\',0};
3621 DWORD dwSize
, dwType
;
3622 WCHAR path
[MAX_PATH
] = {0};
3623 WCHAR parentGuid
[39];
3624 KF_CATEGORY category
;
3625 LPWSTR parentRegistryPath
, parentPath
;
3626 HKEY hRedirectionRootKey
= NULL
;
3628 TRACE("(%s, %p)\n", debugstr_w(registryPath
), ppszPath
);
3631 /* check if folder has parent */
3632 dwSize
= sizeof(parentGuid
);
3633 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szParentFolder
, RRF_RT_REG_SZ
, &dwType
, parentGuid
, &dwSize
));
3634 if(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) hr
= S_FALSE
;
3638 /* get parent's known folder path (recursive) */
3639 hr
= get_known_folder_registry_path(NULL
, parentGuid
, &parentRegistryPath
);
3640 if(FAILED(hr
)) return hr
;
3642 hr
= get_known_folder_path(parentGuid
, parentRegistryPath
, &parentPath
);
3644 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3648 lstrcatW(path
, parentPath
);
3649 lstrcatW(path
, sBackslash
);
3651 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3652 HeapFree(GetProcessHeap(), 0, parentPath
);
3655 /* check, if folder was redirected */
3657 hr
= get_known_folder_dword(registryPath
, szCategory
, &category
);
3661 if(category
== KF_CATEGORY_COMMON
)
3662 hRedirectionRootKey
= HKEY_LOCAL_MACHINE
;
3663 else if(category
== KF_CATEGORY_PERUSER
)
3664 hRedirectionRootKey
= HKEY_CURRENT_USER
;
3666 if(hRedirectionRootKey
)
3668 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3672 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3673 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3678 lstrcpyW(*ppszPath
, path
);
3679 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3685 /* no redirection, use previous way - read the relative path from folder definition */
3686 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, NULL
, &dwSize
));
3690 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3691 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3696 lstrcpyW(*ppszPath
, path
);
3697 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3702 TRACE("returning path: %s\n", debugstr_w(*ppszPath
));
3706 static HRESULT
get_known_folder_path_by_id(
3707 REFKNOWNFOLDERID folderId
,
3708 LPWSTR lpRegistryPath
,
3712 HRESULT hr
= E_FAIL
;
3716 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId
), debugstr_w(lpRegistryPath
), dwFlags
, ppszPath
);
3718 /* if this is registry-registered known folder, get path from registry */
3721 StringFromGUID2(folderId
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3723 hr
= get_known_folder_path(sGuid
, lpRegistryPath
, ppszPath
);
3725 /* in other case, use older way */
3728 hr
= SHGetKnownFolderPath( folderId
, dwFlags
, NULL
, ppszPath
);
3730 if (FAILED(hr
)) return hr
;
3732 /* check if known folder really exists */
3733 dwAttributes
= GetFileAttributesW(*ppszPath
);
3734 if(dwAttributes
== INVALID_FILE_ATTRIBUTES
|| !(dwAttributes
& FILE_ATTRIBUTE_DIRECTORY
) )
3736 TRACE("directory %s not found\n", debugstr_w(*ppszPath
));
3737 CoTaskMemFree(*ppszPath
);
3739 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
3745 static HRESULT WINAPI
knownfolder_GetPath(
3746 IKnownFolder
*iface
,
3750 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3751 TRACE("(%p, 0x%08x, %p)\n", knownfolder
, dwFlags
, ppszPath
);
3753 return get_known_folder_path_by_id(&knownfolder
->id
, knownfolder
->registryPath
, dwFlags
, ppszPath
);
3756 static HRESULT WINAPI
knownfolder_SetPath(
3757 IKnownFolder
*iface
,
3761 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3764 TRACE("(%p, 0x%08x, %s)\n", knownfolder
, dwFlags
, debugstr_w(pszPath
));
3766 /* check if the known folder is registered */
3767 if(!knownfolder
->registryPath
)
3771 hr
= redirect_known_folder(&knownfolder
->id
, NULL
, 0, pszPath
, 0, NULL
, NULL
);
3776 static HRESULT WINAPI
knownfolder_GetIDList(
3777 IKnownFolder
*iface
,
3779 PIDLIST_ABSOLUTE
*ppidl
)
3781 FIXME("0x%08x, %p\n", dwFlags
, ppidl
);
3785 static HRESULT WINAPI
knownfolder_GetFolderType(
3786 IKnownFolder
*iface
,
3787 FOLDERTYPEID
*pftid
)
3789 FIXME("%p\n", pftid
);
3793 static HRESULT WINAPI
knownfolder_GetRedirectionCapabilities(
3794 IKnownFolder
*iface
,
3795 KF_REDIRECTION_CAPABILITIES
*pCapabilities
)
3797 FIXME("%p\n", pCapabilities
);
3801 static HRESULT WINAPI
knownfolder_GetFolderDefinition(
3802 IKnownFolder
*iface
,
3803 KNOWNFOLDER_DEFINITION
*pKFD
)
3805 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3808 WCHAR parentGuid
[39];
3809 TRACE("(%p, %p)\n", knownfolder
, pKFD
);
3811 if(!pKFD
) return E_INVALIDARG
;
3813 ZeroMemory(pKFD
, sizeof(*pKFD
));
3815 /* required fields */
3816 hr
= get_known_folder_dword(knownfolder
->registryPath
, szCategory
, &pKFD
->category
);
3820 hr
= get_known_folder_wstr(knownfolder
->registryPath
, szName
, &pKFD
->pszName
);
3824 /* optional fields */
3825 dwSize
= sizeof(parentGuid
);
3826 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, szParentFolder
,
3827 RRF_RT_REG_SZ
, NULL
, parentGuid
, &dwSize
));
3829 IIDFromString(parentGuid
, &pKFD
->fidParent
);
3831 get_known_folder_dword(knownfolder
->registryPath
, szAttributes
, &pKFD
->dwAttributes
);
3833 get_known_folder_wstr(knownfolder
->registryPath
, szRelativePath
, &pKFD
->pszRelativePath
);
3838 static const struct IKnownFolderVtbl knownfolder_vtbl
=
3840 knownfolder_QueryInterface
,
3842 knownfolder_Release
,
3844 knownfolder_GetCategory
,
3845 knownfolder_GetShellItem
,
3846 knownfolder_GetPath
,
3847 knownfolder_SetPath
,
3848 knownfolder_GetIDList
,
3849 knownfolder_GetFolderType
,
3850 knownfolder_GetRedirectionCapabilities
,
3851 knownfolder_GetFolderDefinition
3854 static HRESULT
knownfolder_create( struct knownfolder
**knownfolder
)
3856 struct knownfolder
*kf
;
3858 kf
= HeapAlloc( GetProcessHeap(), 0, sizeof(*kf
) );
3859 if (!kf
) return E_OUTOFMEMORY
;
3861 kf
->IKnownFolder_iface
.lpVtbl
= &knownfolder_vtbl
;
3863 memset( &kf
->id
, 0, sizeof(kf
->id
) );
3864 kf
->registryPath
= NULL
;
3868 TRACE("returning iface %p\n", &kf
->IKnownFolder_iface
);
3872 struct foldermanager
3874 IKnownFolderManager IKnownFolderManager_iface
;
3880 static inline struct foldermanager
*impl_from_IKnownFolderManager( IKnownFolderManager
*iface
)
3882 return CONTAINING_RECORD( iface
, struct foldermanager
, IKnownFolderManager_iface
);
3885 static ULONG WINAPI
foldermanager_AddRef(
3886 IKnownFolderManager
*iface
)
3888 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3889 return InterlockedIncrement( &foldermanager
->refs
);
3892 static ULONG WINAPI
foldermanager_Release(
3893 IKnownFolderManager
*iface
)
3895 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3896 LONG refs
= InterlockedDecrement( &foldermanager
->refs
);
3899 TRACE("destroying %p\n", foldermanager
);
3900 HeapFree( GetProcessHeap(), 0, foldermanager
->ids
);
3901 HeapFree( GetProcessHeap(), 0, foldermanager
);
3906 static HRESULT WINAPI
foldermanager_QueryInterface(
3907 IKnownFolderManager
*iface
,
3911 struct foldermanager
*This
= impl_from_IKnownFolderManager( iface
);
3913 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3915 if ( IsEqualGUID( riid
, &IID_IKnownFolderManager
) ||
3916 IsEqualGUID( riid
, &IID_IUnknown
) )
3922 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3923 return E_NOINTERFACE
;
3925 IKnownFolderManager_AddRef( iface
);
3929 static HRESULT WINAPI
foldermanager_FolderIdFromCsidl(
3930 IKnownFolderManager
*iface
,
3932 KNOWNFOLDERID
*pfid
)
3934 TRACE("%d, %p\n", nCsidl
, pfid
);
3936 if (nCsidl
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
3937 return E_INVALIDARG
;
3938 *pfid
= *CSIDL_Data
[nCsidl
].id
;
3942 static HRESULT WINAPI
foldermanager_FolderIdToCsidl(
3943 IKnownFolderManager
*iface
,
3944 REFKNOWNFOLDERID rfid
,
3949 TRACE("%s, %p\n", debugstr_guid(rfid
), pnCsidl
);
3951 csidl
= csidl_from_id( rfid
);
3952 if (csidl
== -1) return E_INVALIDARG
;
3957 static HRESULT WINAPI
foldermanager_GetFolderIds(
3958 IKnownFolderManager
*iface
,
3959 KNOWNFOLDERID
**ppKFId
,
3962 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
3964 TRACE("%p, %p\n", ppKFId
, pCount
);
3967 *pCount
= fm
->num_ids
;
3971 static BOOL
is_knownfolder( struct foldermanager
*fm
, const KNOWNFOLDERID
*id
)
3975 LPWSTR registryPath
= NULL
;
3978 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
3979 for (i
= 0; i
< fm
->num_ids
; i
++)
3980 if (IsEqualGUID( &fm
->ids
[i
], id
)) return TRUE
;
3982 hr
= get_known_folder_registry_path(id
, NULL
, ®istryPath
);
3985 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, 0, &hKey
));
3986 HeapFree(GetProcessHeap(), 0, registryPath
);
3998 static HRESULT WINAPI
foldermanager_GetFolder(
3999 IKnownFolderManager
*iface
,
4000 REFKNOWNFOLDERID rfid
,
4001 IKnownFolder
**ppkf
)
4003 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
4004 struct knownfolder
*kf
;
4007 TRACE("%s, %p\n", debugstr_guid(rfid
), ppkf
);
4009 if (!is_knownfolder( fm
, rfid
))
4011 WARN("unknown folder\n");
4012 return E_INVALIDARG
;
4014 hr
= knownfolder_create( &kf
);
4015 if (SUCCEEDED( hr
))
4017 hr
= knownfolder_set_id( kf
, rfid
);
4018 *ppkf
= &kf
->IKnownFolder_iface
;
4026 static HRESULT WINAPI
foldermanager_GetFolderByName(
4027 IKnownFolderManager
*iface
,
4028 LPCWSTR pszCanonicalName
,
4029 IKnownFolder
**ppkf
)
4031 FIXME("%s, %p\n", debugstr_w(pszCanonicalName
), ppkf
);
4035 static HRESULT
register_folder(const KNOWNFOLDERID
*rfid
, const KNOWNFOLDER_DEFINITION
*pKFD
)
4040 LPWSTR registryPath
= NULL
;
4042 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
4043 TRACE("registry path: %s\n", debugstr_w(registryPath
));
4046 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, NULL
, 0, KEY_WRITE
, 0, &hKey
, &dwDisp
));
4051 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szCategory
, 0, REG_DWORD
, (LPBYTE
)&pKFD
->category
, sizeof(pKFD
->category
)));
4053 if(SUCCEEDED(hr
) && pKFD
->dwAttributes
!= 0)
4054 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szAttributes
, 0, REG_DWORD
, (LPBYTE
)&pKFD
->dwAttributes
, sizeof(pKFD
->dwAttributes
)));
4057 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szName
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszName
, (lstrlenW(pKFD
->pszName
)+1)*sizeof(WCHAR
) ));
4059 if(SUCCEEDED(hr
) && !IsEqualGUID(&pKFD
->fidParent
, &GUID_NULL
))
4061 WCHAR sParentGuid
[39];
4062 StringFromGUID2(&pKFD
->fidParent
, sParentGuid
, sizeof(sParentGuid
)/sizeof(sParentGuid
[0]));
4064 /* this known folder has parent folder */
4065 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szParentFolder
, 0, REG_SZ
, (LPBYTE
)sParentGuid
, sizeof(sParentGuid
)));
4068 if(SUCCEEDED(hr
) && pKFD
->category
!= KF_CATEGORY_VIRTUAL
&& pKFD
->pszRelativePath
)
4071 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szRelativePath
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszRelativePath
, (lstrlenW(pKFD
->pszRelativePath
)+1)*sizeof(WCHAR
) ));
4077 SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
);
4080 HeapFree(GetProcessHeap(), 0, registryPath
);
4084 static HRESULT WINAPI
foldermanager_RegisterFolder(
4085 IKnownFolderManager
*iface
,
4086 REFKNOWNFOLDERID rfid
,
4087 KNOWNFOLDER_DEFINITION
const *pKFD
)
4089 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(rfid
), pKFD
);
4090 return register_folder(rfid
, pKFD
);
4093 static HRESULT WINAPI
foldermanager_UnregisterFolder(
4094 IKnownFolderManager
*iface
,
4095 REFKNOWNFOLDERID rfid
)
4098 LPWSTR registryPath
= NULL
;
4099 TRACE("(%p, %s)\n", iface
, debugstr_guid(rfid
));
4101 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
4104 hr
= HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
));
4106 HeapFree(GetProcessHeap(), 0, registryPath
);
4110 static HRESULT WINAPI
foldermanager_FindFolderFromPath(
4111 IKnownFolderManager
*iface
,
4114 IKnownFolder
**ppkf
)
4116 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath
), mode
, ppkf
);
4120 static HRESULT WINAPI
foldermanager_FindFolderFromIDList(
4121 IKnownFolderManager
*iface
,
4122 PCIDLIST_ABSOLUTE pidl
,
4123 IKnownFolder
**ppkf
)
4125 FIXME("%p, %p\n", pidl
, ppkf
);
4129 static HRESULT WINAPI
foldermanager_Redirect(
4130 IKnownFolderManager
*iface
,
4131 REFKNOWNFOLDERID rfid
,
4133 KF_REDIRECT_FLAGS flags
,
4134 LPCWSTR pszTargetPath
,
4136 KNOWNFOLDERID
const *pExclusion
,
4139 return redirect_known_folder(rfid
, hwnd
, flags
, pszTargetPath
, cFolders
, pExclusion
, ppszError
);
4142 static const struct IKnownFolderManagerVtbl foldermanager_vtbl
=
4144 foldermanager_QueryInterface
,
4145 foldermanager_AddRef
,
4146 foldermanager_Release
,
4147 foldermanager_FolderIdFromCsidl
,
4148 foldermanager_FolderIdToCsidl
,
4149 foldermanager_GetFolderIds
,
4150 foldermanager_GetFolder
,
4151 foldermanager_GetFolderByName
,
4152 foldermanager_RegisterFolder
,
4153 foldermanager_UnregisterFolder
,
4154 foldermanager_FindFolderFromPath
,
4155 foldermanager_FindFolderFromIDList
,
4156 foldermanager_Redirect
4159 static HRESULT
foldermanager_create( void **ppv
)
4162 struct foldermanager
*fm
;
4164 fm
= HeapAlloc( GetProcessHeap(), 0, sizeof(*fm
) );
4165 if (!fm
) return E_OUTOFMEMORY
;
4167 fm
->IKnownFolderManager_iface
.lpVtbl
= &foldermanager_vtbl
;
4171 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
4173 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
)) fm
->num_ids
++;
4175 fm
->ids
= HeapAlloc( GetProcessHeap(), 0, fm
->num_ids
* sizeof(KNOWNFOLDERID
) );
4178 HeapFree( GetProcessHeap(), 0, fm
);
4179 return E_OUTOFMEMORY
;
4181 for (i
= j
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
4183 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
))
4185 fm
->ids
[j
] = *CSIDL_Data
[i
].id
;
4189 TRACE("found %u known folders\n", fm
->num_ids
);
4190 *ppv
= &fm
->IKnownFolderManager_iface
;
4192 TRACE("returning iface %p\n", *ppv
);
4196 HRESULT WINAPI
KnownFolderManager_Constructor( IUnknown
*punk
, REFIID riid
, void **ppv
)
4198 TRACE("%p, %s, %p\n", punk
, debugstr_guid(riid
), ppv
);
4203 return CLASS_E_NOAGGREGATION
;
4205 return foldermanager_create( ppv
);
4208 HRESULT WINAPI
SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PIDLIST_ABSOLUTE
*pidl
)
4210 FIXME("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid
), flags
, token
, pidl
);
4214 static void register_system_knownfolders(void)
4217 for(i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); ++i
){
4218 const CSIDL_DATA
*folder
= &CSIDL_Data
[i
];
4219 if(folder
->pszName
){
4220 KNOWNFOLDER_DEFINITION kfd
;
4222 /* register_folder won't modify kfd, so cast away const instead of
4224 kfd
.category
= folder
->category
;
4225 kfd
.pszName
= (WCHAR
*)folder
->pszName
;
4226 kfd
.pszDescription
= (WCHAR
*)folder
->pszDescription
;
4227 memcpy(&kfd
.fidParent
, folder
->fidParent
, sizeof(KNOWNFOLDERID
));
4228 kfd
.pszRelativePath
= (WCHAR
*)folder
->pszRelativePath
;
4229 kfd
.pszParsingName
= (WCHAR
*)folder
->pszParsingName
;
4230 kfd
.pszTooltip
= (WCHAR
*)folder
->pszTooltip
;
4231 kfd
.pszLocalizedName
= (WCHAR
*)folder
->pszLocalizedName
;
4232 kfd
.pszIcon
= (WCHAR
*)folder
->pszIcon
;
4233 kfd
.pszSecurity
= (WCHAR
*)folder
->pszSecurity
;
4234 kfd
.dwAttributes
= folder
->dwAttributes
;
4235 kfd
.kfdFlags
= folder
->kfdFlags
;
4236 memcpy(&kfd
.ftidType
, folder
->ftidType
, sizeof(FOLDERTYPEID
));
4238 register_folder(folder
->id
, &kfd
);
4243 HRESULT
SHELL_RegisterShellFolders(void)
4247 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
4248 * 'My Videos', 'My Music' and 'Desktop' in advance, so that the
4249 * _SHRegister*ShellFolders() functions will find everything nice and clean
4250 * and thus will not attempt to create them in the profile directory. */
4251 _SHCreateSymbolicLinks();
4253 hr
= _SHRegisterUserShellFolders(TRUE
);
4255 hr
= _SHRegisterUserShellFolders(FALSE
);
4257 hr
= _SHRegisterCommonShellFolders();
4259 hr
= create_extra_folders();
4261 hr
= set_folder_attributes();
4263 register_system_knownfolders();