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 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'};
772 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'};
773 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
774 static const WCHAR AppData_LocalLowW
[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','L','o','w','\0'};
775 static const WCHAR Application_DataW
[] = {'A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
776 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
777 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
778 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'};
779 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
780 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
781 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
782 static const WCHAR Common_FavoritesW
[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
783 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
784 static const WCHAR CommonFilesDirX86W
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
785 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
786 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
787 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
788 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
789 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
790 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
791 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
792 static const WCHAR ContactsW
[] = {'C','o','n','t','a','c','t','s','\0'};
793 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
794 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
795 static const WCHAR DocumentsW
[] = {'D','o','c','u','m','e','n','t','s','\0'};
796 static const WCHAR DownloadsW
[] = {'D','o','w','n','l','o','a','d','s','\0'};
797 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
798 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
799 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
800 static const WCHAR LinksW
[] = {'L','i','n','k','s','\0'};
801 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
802 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'};
803 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'};
804 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'};
805 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'};
806 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'};
807 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'};
808 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'};
809 static const WCHAR MusicW
[] = {'M','u','s','i','c','\0'};
810 static const WCHAR Music_PlaylistsW
[] = {'M','u','s','i','c','\\','P','l','a','y','l','i','s','t','s','\0'};
811 static const WCHAR Music_Sample_MusicW
[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','M','u','s','i','c','\0'};
812 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'};
813 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
814 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
815 static const WCHAR My_VideosW
[] = {'M','y',' ','V','i','d','e','o','s','\0'};
816 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
817 static const WCHAR OEM_LinksW
[] = {'O','E','M',' ','L','i','n','k','s','\0'};
818 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
819 static const WCHAR PicturesW
[] = {'P','i','c','t','u','r','e','s','\0'};
820 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'};
821 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'};
822 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
823 static const WCHAR Program_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\0'};
824 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'};
825 static const WCHAR Program_Files_x86W
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\0'};
826 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'};
827 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
828 static const WCHAR ProgramFilesDirX86W
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
829 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
830 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
831 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
832 static const WCHAR Saved_GamesW
[] = {'S','a','v','e','d',' ','G','a','m','e','s','\0'};
833 static const WCHAR SearchesW
[] = {'S','e','a','r','c','h','e','s','\0'};
834 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
835 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
836 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
837 static const WCHAR Start_Menu_ProgramsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\0'};
838 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'};
839 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'};
840 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
841 static const WCHAR UsersW
[] = {'U','s','e','r','s','\0'};
842 static const WCHAR UsersPublicW
[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
843 static const WCHAR VideosW
[] = {'V','i','d','e','o','s','\0'};
844 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'};
845 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
846 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
847 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
848 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
849 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};
850 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
851 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
852 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'};
853 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'};
854 static const WCHAR szDefaultProfileDirW
[] = {'u','s','e','r','s',0};
855 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'};
856 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};
857 static const WCHAR AllUsersW
[] = {'P','u','b','l','i','c',0};
859 typedef enum _CSIDL_Type
{
863 CSIDL_Type_Disallowed
,
864 CSIDL_Type_NonExistent
,
865 CSIDL_Type_WindowsPath
,
866 CSIDL_Type_SystemPath
,
867 CSIDL_Type_SystemX86Path
,
870 #define CSIDL_CONTACTS 0x0043
871 #define CSIDL_DOWNLOADS 0x0047
872 #define CSIDL_LINKS 0x004d
873 #define CSIDL_APPDATA_LOCALLOW 0x004e
874 #define CSIDL_SAVED_GAMES 0x0062
875 #define CSIDL_SEARCHES 0x0063
879 const KNOWNFOLDERID
*id
;
882 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
885 static const CSIDL_DATA CSIDL_Data
[] =
887 { /* 0x00 - CSIDL_DESKTOP */
891 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
893 { /* 0x01 - CSIDL_INTERNET */
894 &FOLDERID_InternetFolder
,
895 CSIDL_Type_Disallowed
,
899 { /* 0x02 - CSIDL_PROGRAMS */
905 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
906 &FOLDERID_ControlPanelFolder
,
907 CSIDL_Type_SystemPath
,
911 { /* 0x04 - CSIDL_PRINTERS */
912 &FOLDERID_PrintersFolder
,
913 CSIDL_Type_SystemPath
,
917 { /* 0x05 - CSIDL_PERSONAL */
921 MAKEINTRESOURCEW(IDS_PERSONAL
)
923 { /* 0x06 - CSIDL_FAVORITES */
929 { /* 0x07 - CSIDL_STARTUP */
935 { /* 0x08 - CSIDL_RECENT */
941 { /* 0x09 - CSIDL_SENDTO */
947 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
948 &FOLDERID_RecycleBinFolder
,
949 CSIDL_Type_Disallowed
,
953 { /* 0x0b - CSIDL_STARTMENU */
959 { /* 0x0c - CSIDL_MYDOCUMENTS */
961 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
965 { /* 0x0d - CSIDL_MYMUSIC */
969 MAKEINTRESOURCEW(IDS_MYMUSIC
)
971 { /* 0x0e - CSIDL_MYVIDEO */
975 MAKEINTRESOURCEW(IDS_MYVIDEOS
)
977 { /* 0x0f - unassigned */
979 CSIDL_Type_Disallowed
,
983 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
987 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
989 { /* 0x11 - CSIDL_DRIVES */
990 &FOLDERID_ComputerFolder
,
991 CSIDL_Type_Disallowed
,
995 { /* 0x12 - CSIDL_NETWORK */
996 &FOLDERID_NetworkFolder
,
997 CSIDL_Type_Disallowed
,
1001 { /* 0x13 - CSIDL_NETHOOD */
1007 { /* 0x14 - CSIDL_FONTS */
1009 CSIDL_Type_WindowsPath
,
1013 { /* 0x15 - CSIDL_TEMPLATES */
1014 &FOLDERID_Templates
,
1019 { /* 0x16 - CSIDL_COMMON_STARTMENU */
1020 &FOLDERID_CommonStartMenu
,
1021 CSIDL_Type_AllUsers
,
1025 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
1026 &FOLDERID_CommonPrograms
,
1027 CSIDL_Type_AllUsers
,
1029 Start_Menu_ProgramsW
1031 { /* 0x18 - CSIDL_COMMON_STARTUP */
1032 &FOLDERID_CommonStartup
,
1033 CSIDL_Type_AllUsers
,
1037 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
1038 &FOLDERID_PublicDesktop
,
1039 CSIDL_Type_AllUsers
,
1041 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
1043 { /* 0x1a - CSIDL_APPDATA */
1044 &FOLDERID_RoamingAppData
,
1049 { /* 0x1b - CSIDL_PRINTHOOD */
1050 &FOLDERID_PrintHood
,
1055 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1056 &FOLDERID_LocalAppData
,
1059 Local_Settings_Application_DataW
1061 { /* 0x1d - CSIDL_ALTSTARTUP */
1063 CSIDL_Type_NonExistent
,
1067 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1069 CSIDL_Type_NonExistent
,
1073 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1074 &FOLDERID_Favorites
,
1075 CSIDL_Type_AllUsers
,
1079 { /* 0x20 - CSIDL_INTERNET_CACHE */
1080 &FOLDERID_InternetCache
,
1083 Local_Settings_Temporary_Internet_FilesW
1085 { /* 0x21 - CSIDL_COOKIES */
1091 { /* 0x22 - CSIDL_HISTORY */
1095 Local_Settings_HistoryW
1097 { /* 0x23 - CSIDL_COMMON_APPDATA */
1098 &FOLDERID_ProgramData
,
1099 CSIDL_Type_AllUsers
,
1103 { /* 0x24 - CSIDL_WINDOWS */
1105 CSIDL_Type_WindowsPath
,
1109 { /* 0x25 - CSIDL_SYSTEM */
1111 CSIDL_Type_SystemPath
,
1115 { /* 0x26 - CSIDL_PROGRAM_FILES */
1116 &FOLDERID_ProgramFiles
,
1121 { /* 0x27 - CSIDL_MYPICTURES */
1125 MAKEINTRESOURCEW(IDS_MYPICTURES
)
1127 { /* 0x28 - CSIDL_PROFILE */
1133 { /* 0x29 - CSIDL_SYSTEMX86 */
1134 &FOLDERID_SystemX86
,
1135 CSIDL_Type_SystemX86Path
,
1139 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1140 &FOLDERID_ProgramFilesX86
,
1142 ProgramFilesDirX86W
,
1145 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1146 &FOLDERID_ProgramFilesCommon
,
1149 Program_Files_Common_FilesW
1151 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1152 &FOLDERID_ProgramFilesCommonX86
,
1155 Program_Files_x86_Common_FilesW
1157 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1158 &FOLDERID_CommonTemplates
,
1159 CSIDL_Type_AllUsers
,
1163 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1164 &FOLDERID_PublicDocuments
,
1165 CSIDL_Type_AllUsers
,
1169 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1170 &FOLDERID_CommonAdminTools
,
1171 CSIDL_Type_AllUsers
,
1172 Common_Administrative_ToolsW
,
1173 Start_Menu_Admin_ToolsW
1175 { /* 0x30 - CSIDL_ADMINTOOLS */
1176 &FOLDERID_AdminTools
,
1178 Administrative_ToolsW
,
1179 Start_Menu_Admin_ToolsW
1181 { /* 0x31 - CSIDL_CONNECTIONS */
1182 &FOLDERID_ConnectionsFolder
,
1183 CSIDL_Type_Disallowed
,
1187 { /* 0x32 - unassigned */
1189 CSIDL_Type_Disallowed
,
1193 { /* 0x33 - unassigned */
1195 CSIDL_Type_Disallowed
,
1199 { /* 0x34 - unassigned */
1201 CSIDL_Type_Disallowed
,
1205 { /* 0x35 - CSIDL_COMMON_MUSIC */
1206 &FOLDERID_PublicMusic
,
1207 CSIDL_Type_AllUsers
,
1211 { /* 0x36 - CSIDL_COMMON_PICTURES */
1212 &FOLDERID_PublicPictures
,
1213 CSIDL_Type_AllUsers
,
1217 { /* 0x37 - CSIDL_COMMON_VIDEO */
1218 &FOLDERID_PublicVideos
,
1219 CSIDL_Type_AllUsers
,
1223 { /* 0x38 - CSIDL_RESOURCES */
1224 &FOLDERID_ResourceDir
,
1225 CSIDL_Type_WindowsPath
,
1229 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1230 &FOLDERID_LocalizedResourcesDir
,
1231 CSIDL_Type_NonExistent
,
1235 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1236 &FOLDERID_CommonOEMLinks
,
1237 CSIDL_Type_AllUsers
,
1241 { /* 0x3b - CSIDL_CDBURN_AREA */
1242 &FOLDERID_CDBurning
,
1245 Local_Settings_CD_BurningW
1247 { /* 0x3c unassigned */
1249 CSIDL_Type_Disallowed
,
1253 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1255 CSIDL_Type_Disallowed
, /* FIXME */
1259 { /* 0x3e - CSIDL_PROFILES */
1261 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1266 &FOLDERID_AddNewPrograms
,
1267 CSIDL_Type_Disallowed
,
1272 &FOLDERID_AppUpdates
,
1273 CSIDL_Type_Disallowed
,
1278 &FOLDERID_ChangeRemovePrograms
,
1279 CSIDL_Type_Disallowed
,
1284 &FOLDERID_ConflictFolder
,
1285 CSIDL_Type_Disallowed
,
1289 { /* 0x43 - CSIDL_CONTACTS */
1296 &FOLDERID_DeviceMetadataStore
,
1297 CSIDL_Type_Disallowed
, /* FIXME */
1308 &FOLDERID_DocumentsLibrary
,
1309 CSIDL_Type_Disallowed
, /* FIXME */
1313 { /* 0x47 - CSIDL_DOWNLOADS */
1314 &FOLDERID_Downloads
,
1321 CSIDL_Type_Disallowed
,
1326 &FOLDERID_GameTasks
,
1327 CSIDL_Type_Disallowed
, /* FIXME */
1332 &FOLDERID_HomeGroup
,
1333 CSIDL_Type_Disallowed
,
1338 &FOLDERID_ImplicitAppShortcuts
,
1339 CSIDL_Type_Disallowed
, /* FIXME */
1344 &FOLDERID_Libraries
,
1345 CSIDL_Type_Disallowed
, /* FIXME */
1349 { /* 0x4d - CSIDL_LINKS */
1355 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
1356 &FOLDERID_LocalAppDataLow
,
1362 &FOLDERID_MusicLibrary
,
1363 CSIDL_Type_Disallowed
, /* FIXME */
1368 &FOLDERID_OriginalImages
,
1369 CSIDL_Type_Disallowed
, /* FIXME */
1374 &FOLDERID_PhotoAlbums
,
1377 Pictures_Slide_ShowsW
1380 &FOLDERID_PicturesLibrary
,
1381 CSIDL_Type_Disallowed
, /* FIXME */
1386 &FOLDERID_Playlists
,
1392 &FOLDERID_ProgramFilesX64
,
1393 CSIDL_Type_NonExistent
,
1398 &FOLDERID_ProgramFilesCommonX64
,
1399 CSIDL_Type_NonExistent
,
1405 CSIDL_Type_CurrVer
, /* FIXME */
1410 &FOLDERID_PublicDownloads
,
1411 CSIDL_Type_AllUsers
,
1416 &FOLDERID_PublicGameTasks
,
1417 CSIDL_Type_AllUsers
,
1419 Microsoft_Windows_GameExplorerW
1422 &FOLDERID_PublicLibraries
,
1423 CSIDL_Type_AllUsers
,
1425 Microsoft_Windows_LibrariesW
1428 &FOLDERID_PublicRingtones
,
1429 CSIDL_Type_AllUsers
,
1431 Microsoft_Windows_RingtonesW
1434 &FOLDERID_QuickLaunch
,
1435 CSIDL_Type_Disallowed
, /* FIXME */
1440 &FOLDERID_RecordedTVLibrary
,
1441 CSIDL_Type_Disallowed
, /* FIXME */
1446 &FOLDERID_Ringtones
,
1447 CSIDL_Type_Disallowed
, /* FIXME */
1452 &FOLDERID_SampleMusic
,
1453 CSIDL_Type_AllUsers
,
1458 &FOLDERID_SamplePictures
,
1459 CSIDL_Type_AllUsers
,
1461 Pictures_Sample_PicturesW
1464 &FOLDERID_SamplePlaylists
,
1465 CSIDL_Type_AllUsers
,
1467 Music_Sample_PlaylistsW
1470 &FOLDERID_SampleVideos
,
1471 CSIDL_Type_AllUsers
,
1473 Videos_Sample_VideosW
1475 { /* 0x62 - CSIDL_SAVED_GAMES */
1476 &FOLDERID_SavedGames
,
1481 { /* 0x63 - CSIDL_SEARCHES */
1482 &FOLDERID_SavedSearches
,
1488 &FOLDERID_SEARCH_CSC
,
1489 CSIDL_Type_Disallowed
,
1494 &FOLDERID_SEARCH_MAPI
,
1495 CSIDL_Type_Disallowed
,
1500 &FOLDERID_SearchHome
,
1501 CSIDL_Type_Disallowed
,
1506 &FOLDERID_SidebarDefaultParts
,
1507 CSIDL_Type_Disallowed
, /* FIXME */
1512 &FOLDERID_SidebarParts
,
1513 CSIDL_Type_Disallowed
, /* FIXME */
1518 &FOLDERID_SyncManagerFolder
,
1519 CSIDL_Type_Disallowed
,
1524 &FOLDERID_SyncResultsFolder
,
1525 CSIDL_Type_Disallowed
,
1530 &FOLDERID_SyncSetupFolder
,
1531 CSIDL_Type_Disallowed
,
1536 &FOLDERID_UserPinned
,
1537 CSIDL_Type_Disallowed
, /* FIXME */
1542 &FOLDERID_UserProfiles
,
1548 &FOLDERID_UserProgramFiles
,
1549 CSIDL_Type_Disallowed
, /* FIXME */
1554 &FOLDERID_UserProgramFilesCommon
,
1555 CSIDL_Type_Disallowed
, /* FIXME */
1560 &FOLDERID_UsersFiles
,
1561 CSIDL_Type_Disallowed
,
1566 &FOLDERID_UsersLibraries
,
1567 CSIDL_Type_Disallowed
,
1572 &FOLDERID_VideosLibrary
,
1573 CSIDL_Type_Disallowed
, /* FIXME */
1579 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1581 /* Gets the value named value from the registry key
1582 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1583 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1584 * is assumed to be MAX_PATH WCHARs in length.
1585 * If it exists, expands the value and writes the expanded value to
1586 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1587 * Returns successful error code if the value was retrieved from the registry,
1588 * and a failure otherwise.
1590 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1591 LPCWSTR value
, LPWSTR path
)
1594 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1595 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1596 DWORD dwType
, dwPathLen
= MAX_PATH
;
1597 HKEY userShellFolderKey
, shellFolderKey
;
1599 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1604 strcpyW(shellFolderPath
, userPrefix
);
1605 PathAddBackslashW(shellFolderPath
);
1606 strcatW(shellFolderPath
, szSHFolders
);
1607 pShellFolderPath
= shellFolderPath
;
1608 strcpyW(userShellFolderPath
, userPrefix
);
1609 PathAddBackslashW(userShellFolderPath
);
1610 strcatW(userShellFolderPath
, szSHUserFolders
);
1611 pUserShellFolderPath
= userShellFolderPath
;
1615 pUserShellFolderPath
= szSHUserFolders
;
1616 pShellFolderPath
= szSHFolders
;
1619 if (RegCreateKeyW(rootKey
, pShellFolderPath
, &shellFolderKey
))
1621 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1624 if (RegCreateKeyW(rootKey
, pUserShellFolderPath
, &userShellFolderKey
))
1626 TRACE("Failed to create %s\n",
1627 debugstr_w(pUserShellFolderPath
));
1628 RegCloseKey(shellFolderKey
);
1632 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1633 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1637 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1638 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1640 WCHAR szTemp
[MAX_PATH
];
1642 _SHExpandEnvironmentStrings(path
, szTemp
);
1643 lstrcpynW(path
, szTemp
, MAX_PATH
);
1645 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1646 (strlenW(path
) + 1) * sizeof(WCHAR
));
1647 if (ret
!= ERROR_SUCCESS
)
1648 hr
= HRESULT_FROM_WIN32(ret
);
1654 RegCloseKey(shellFolderKey
);
1655 RegCloseKey(userShellFolderKey
);
1656 TRACE("returning 0x%08x\n", hr
);
1660 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1661 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1662 * - The entry's szDefaultPath may be either a string value or an integer
1663 * resource identifier. In the latter case, the string value of the resource
1665 * - Depending on the entry's type, the path may begin with an (unexpanded)
1666 * environment variable name. The caller is responsible for expanding
1667 * environment strings if so desired.
1668 * The types that are prepended with environment variables are:
1669 * CSIDL_Type_User: %USERPROFILE%
1670 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1671 * CSIDL_Type_CurrVer: %SystemDrive%
1672 * (Others might make sense too, but as yet are unneeded.)
1674 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1677 WCHAR resourcePath
[MAX_PATH
];
1678 LPCWSTR pDefaultPath
= NULL
;
1680 TRACE("0x%02x,%p\n", folder
, pszPath
);
1682 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1683 return E_INVALIDARG
;
1685 return E_INVALIDARG
;
1693 case CSIDL_PROGRAM_FILES
:
1694 case CSIDL_PROGRAM_FILESX86
:
1695 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1696 folder
= is_wow64
? CSIDL_PROGRAM_FILESX86
: CSIDL_PROGRAM_FILES
;
1698 case CSIDL_PROGRAM_FILES_COMMON
:
1699 case CSIDL_PROGRAM_FILES_COMMONX86
:
1700 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1701 folder
= is_wow64
? CSIDL_PROGRAM_FILES_COMMONX86
: CSIDL_PROGRAM_FILES_COMMON
;
1706 if (CSIDL_Data
[folder
].szDefaultPath
&&
1707 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1709 if (LoadStringW(shell32_hInstance
,
1710 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1713 pDefaultPath
= resourcePath
;
1717 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1718 debugstr_w(pszPath
));
1725 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1729 switch (CSIDL_Data
[folder
].type
)
1731 case CSIDL_Type_User
:
1732 strcpyW(pszPath
, UserProfileW
);
1734 case CSIDL_Type_AllUsers
:
1735 strcpyW(pszPath
, AllUsersProfileW
);
1737 case CSIDL_Type_CurrVer
:
1738 strcpyW(pszPath
, SystemDriveW
);
1741 ; /* no corresponding env. var, do nothing */
1745 PathAddBackslashW(pszPath
);
1746 strcatW(pszPath
, pDefaultPath
);
1749 TRACE("returning 0x%08x\n", hr
);
1753 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1754 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1755 * can be overridden in the HKLM\\szCurrentVersion key.
1756 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1757 * the registry, uses _SHGetDefaultValue to get the value.
1759 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1764 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1766 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1767 return E_INVALIDARG
;
1768 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1769 return E_INVALIDARG
;
1771 return E_INVALIDARG
;
1773 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1774 hr
= _SHGetDefaultValue(folder
, pszPath
);
1779 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hKey
))
1783 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1785 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1786 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1787 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1789 hr
= _SHGetDefaultValue(folder
, pszPath
);
1790 dwType
= REG_EXPAND_SZ
;
1793 case CSIDL_PROGRAM_FILESX86
:
1794 case CSIDL_PROGRAM_FILES_COMMONX86
:
1795 /* these two should never be set on 32-bit setups */
1799 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1800 if (!is_wow64
) break;
1804 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1805 (LPBYTE
)pszPath
, (strlenW(pszPath
)+1)*sizeof(WCHAR
));
1810 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1816 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1820 static LPWSTR
_GetUserSidStringFromToken(HANDLE Token
)
1822 char InfoBuffer
[64];
1823 PTOKEN_USER UserInfo
;
1827 UserInfo
= (PTOKEN_USER
) InfoBuffer
;
1828 if (! GetTokenInformation(Token
, TokenUser
, InfoBuffer
, sizeof(InfoBuffer
),
1831 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1833 UserInfo
= HeapAlloc(GetProcessHeap(), 0, InfoSize
);
1834 if (UserInfo
== NULL
)
1836 if (! GetTokenInformation(Token
, TokenUser
, UserInfo
, InfoSize
,
1839 HeapFree(GetProcessHeap(), 0, UserInfo
);
1844 if (! ConvertSidToStringSidW(UserInfo
->User
.Sid
, &SidStr
))
1847 if (UserInfo
!= (PTOKEN_USER
) InfoBuffer
)
1848 HeapFree(GetProcessHeap(), 0, UserInfo
);
1853 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1854 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1855 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1856 * - if hToken is -1, looks in HKEY_USERS\.Default
1857 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1858 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1859 * calls _SHGetDefaultValue for it.
1861 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1864 const WCHAR
*szValueName
;
1868 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1870 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1871 return E_INVALIDARG
;
1872 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1873 return E_INVALIDARG
;
1875 return E_INVALIDARG
;
1877 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1879 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
1881 FIXME("unsupported for user other than current or default\n");
1884 hr
= _SHGetDefaultValue(folder
, pszPath
);
1888 LPCWSTR userPrefix
= NULL
;
1891 if (hToken
== (HANDLE
)-1)
1893 hRootKey
= HKEY_USERS
;
1894 userPrefix
= DefaultW
;
1896 else if (hToken
== NULL
)
1897 hRootKey
= HKEY_CURRENT_USER
;
1900 hRootKey
= HKEY_USERS
;
1901 userPrefix
= _GetUserSidStringFromToken(hToken
);
1902 if (userPrefix
== NULL
)
1909 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
1910 szValueName
= CSIDL_Data
[folder
].szValueName
;
1913 StringFromGUID2( CSIDL_Data
[folder
].id
, buffer
, 39 );
1914 szValueName
= &buffer
[0];
1917 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, szValueName
, pszPath
);
1918 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1919 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, szValueName
, pszPath
);
1921 hr
= _SHGetDefaultValue(folder
, pszPath
);
1922 if (userPrefix
!= NULL
&& userPrefix
!= DefaultW
)
1923 LocalFree((HLOCAL
) userPrefix
);
1926 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1930 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1931 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1932 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1933 * If this fails, falls back to _SHGetDefaultValue.
1935 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1940 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1942 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1943 return E_INVALIDARG
;
1944 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1945 return E_INVALIDARG
;
1947 return E_INVALIDARG
;
1949 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1950 hr
= _SHGetDefaultValue(folder
, pszPath
);
1953 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1954 CSIDL_Data
[folder
].szValueName
, pszPath
);
1956 hr
= _SHGetDefaultValue(folder
, pszPath
);
1958 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1962 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
1967 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, NULL
, 0,
1968 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
1969 return HRESULT_FROM_WIN32(lRet
);
1972 /* Reads the value named szValueName from the key profilesKey (assumed to be
1973 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1974 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1975 * szDefault to the registry).
1977 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
1978 LPWSTR szValue
, LPCWSTR szDefault
)
1981 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1984 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
1985 debugstr_w(szDefault
));
1986 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
1987 (LPBYTE
)szValue
, &dwPathLen
);
1988 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
1991 dwPathLen
/= sizeof(WCHAR
);
1992 szValue
[dwPathLen
] = '\0';
1997 /* Missing or invalid value, set a default */
1998 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
1999 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
2000 debugstr_w(szValue
));
2001 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
2003 (strlenW(szValue
) + 1) * sizeof(WCHAR
));
2005 hr
= HRESULT_FROM_WIN32(lRet
);
2009 TRACE("returning 0x%08x (output value is %s)\n", hr
, debugstr_w(szValue
));
2013 /* Attempts to expand environment variables from szSrc into szDest, which is
2014 * assumed to be MAX_PATH characters in length. Before referring to the
2015 * environment, handles a few variables directly, because the environment
2016 * variables may not be set when this is called (as during Wine's installation
2017 * when default values are being written to the registry).
2018 * The directly handled environment variables, and their source, are:
2019 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
2020 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
2022 * If one of the directly handled environment variables is expanded, only
2023 * expands a single variable, and only in the beginning of szSrc.
2025 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
2028 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
2031 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
2033 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
2035 /* short-circuit if there's nothing to expand */
2036 if (szSrc
[0] != '%')
2038 strcpyW(szDest
, szSrc
);
2042 /* Get the profile prefix, we'll probably be needing it */
2043 hr
= _SHOpenProfilesKey(&key
);
2046 WCHAR def_val
[MAX_PATH
];
2048 /* get the system drive */
2049 GetSystemDirectoryW(def_val
, MAX_PATH
);
2050 if (def_val
[1] == ':') strcpyW( def_val
+ 3, szDefaultProfileDirW
);
2051 else FIXME("non-drive system paths unsupported\n");
2053 hr
= _SHGetProfilesValue(key
, ProfilesDirectoryW
, szProfilesPrefix
, def_val
);
2057 strcpyW(szTemp
, szSrc
);
2058 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
2060 if (!strncmpiW(szTemp
, AllUsersProfileW
, strlenW(AllUsersProfileW
)))
2062 WCHAR szAllUsers
[MAX_PATH
];
2064 strcpyW(szDest
, szProfilesPrefix
);
2065 hr
= _SHGetProfilesValue(key
, AllUsersProfileValueW
,
2066 szAllUsers
, AllUsersW
);
2067 PathAppendW(szDest
, szAllUsers
);
2068 PathAppendW(szDest
, szTemp
+ strlenW(AllUsersProfileW
));
2070 else if (!strncmpiW(szTemp
, UserProfileW
, strlenW(UserProfileW
)))
2072 WCHAR userName
[MAX_PATH
];
2073 DWORD userLen
= MAX_PATH
;
2075 strcpyW(szDest
, szProfilesPrefix
);
2076 GetUserNameW(userName
, &userLen
);
2077 PathAppendW(szDest
, userName
);
2078 PathAppendW(szDest
, szTemp
+ strlenW(UserProfileW
));
2080 else if (!strncmpiW(szTemp
, SystemDriveW
, strlenW(SystemDriveW
)))
2082 GetSystemDirectoryW(szDest
, MAX_PATH
);
2083 if (szDest
[1] != ':')
2085 FIXME("non-drive system paths unsupported\n");
2090 strcpyW(szDest
+ 3, szTemp
+ strlenW(SystemDriveW
) + 1);
2096 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
2099 hr
= E_NOT_SUFFICIENT_BUFFER
;
2101 hr
= HRESULT_FROM_WIN32(GetLastError());
2105 if (SUCCEEDED(hr
) && szDest
[0] == '%')
2106 strcpyW(szTemp
, szDest
);
2109 /* terminate loop */
2116 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr
,
2117 debugstr_w(szSrc
), debugstr_w(szDest
));
2121 /*************************************************************************
2122 * SHGetFolderPathW [SHELL32.@]
2124 * Convert nFolder to path.
2128 * Failure: standard HRESULT error codes.
2131 * Most values can be overridden in either
2132 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
2133 * or in the same location in HKLM.
2134 * The "Shell Folders" registry key was used in NT4 and earlier systems.
2135 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
2136 * changes made to it are made to the former key too. This synchronization is
2137 * done on-demand: not until someone requests the value of one of these paths
2138 * (by calling one of the SHGet functions) is the value synchronized.
2139 * Furthermore, the HKCU paths take precedence over the HKLM paths.
2141 HRESULT WINAPI
SHGetFolderPathW(
2142 HWND hwndOwner
, /* [I] owner window */
2143 int nFolder
, /* [I] CSIDL identifying the folder */
2144 HANDLE hToken
, /* [I] access token */
2145 DWORD dwFlags
, /* [I] which path to return */
2146 LPWSTR pszPath
) /* [O] converted path */
2148 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
2149 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
2150 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
2154 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
2155 HWND hwndOwner
, /* [I] owner window */
2156 int nFolder
, /* [I] CSIDL identifying the folder */
2157 HANDLE hToken
, /* [I] access token */
2158 DWORD dwFlags
, /* [I] which path to return */
2159 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
2160 LPSTR pszPath
) /* [O] converted path */
2164 LPWSTR pszSubPathW
= NULL
;
2165 LPWSTR pszPathW
= NULL
;
2166 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2169 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
2171 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2175 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2177 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
2178 * set (null), or an empty string.therefore call it without the parameter set
2179 * if pszSubPath is an empty string
2181 if (pszSubPath
&& pszSubPath
[0]) {
2182 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
2183 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
2185 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2188 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
2191 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
2193 if (SUCCEEDED(hr
) && pszPath
)
2194 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
2197 HeapFree(GetProcessHeap(), 0, pszPathW
);
2198 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
2202 /*************************************************************************
2203 * SHGetFolderPathAndSubDirW [SHELL32.@]
2205 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
2206 HWND hwndOwner
, /* [I] owner window */
2207 int nFolder
, /* [I] CSIDL identifying the folder */
2208 HANDLE hToken
, /* [I] access token */
2209 DWORD dwFlags
, /* [I] which path to return */
2210 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
2211 LPWSTR pszPath
) /* [O] converted path */
2214 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
2215 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2219 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
2221 /* Windows always NULL-terminates the resulting path regardless of success
2222 * or failure, so do so first
2227 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2228 return E_INVALIDARG
;
2229 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
2230 return E_INVALIDARG
;
2232 type
= CSIDL_Data
[folder
].type
;
2235 case CSIDL_Type_Disallowed
:
2238 case CSIDL_Type_NonExistent
:
2241 case CSIDL_Type_WindowsPath
:
2242 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
2243 if (CSIDL_Data
[folder
].szDefaultPath
&&
2244 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2245 *CSIDL_Data
[folder
].szDefaultPath
)
2247 PathAddBackslashW(szTemp
);
2248 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2252 case CSIDL_Type_SystemPath
:
2253 GetSystemDirectoryW(szTemp
, MAX_PATH
);
2254 if (CSIDL_Data
[folder
].szDefaultPath
&&
2255 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2256 *CSIDL_Data
[folder
].szDefaultPath
)
2258 PathAddBackslashW(szTemp
);
2259 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2263 case CSIDL_Type_SystemX86Path
:
2264 if (!GetSystemWow64DirectoryW(szTemp
, MAX_PATH
)) GetSystemDirectoryW(szTemp
, MAX_PATH
);
2265 if (CSIDL_Data
[folder
].szDefaultPath
&&
2266 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2267 *CSIDL_Data
[folder
].szDefaultPath
)
2269 PathAddBackslashW(szTemp
);
2270 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2274 case CSIDL_Type_CurrVer
:
2275 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
2277 case CSIDL_Type_User
:
2278 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
2280 case CSIDL_Type_AllUsers
:
2281 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
2284 FIXME("bogus type %d, please fix\n", type
);
2289 /* Expand environment strings if necessary */
2291 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
2293 strcpyW(szBuildPath
, szTemp
);
2295 if (FAILED(hr
)) goto end
;
2298 /* make sure the new path does not exceed the buffer length
2299 * and remember to backslash and terminate it */
2300 if(MAX_PATH
< (lstrlenW(szBuildPath
) + lstrlenW(pszSubPath
) + 2)) {
2301 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
2304 PathAppendW(szBuildPath
, pszSubPath
);
2305 PathRemoveBackslashW(szBuildPath
);
2307 /* Copy the path if it's available before we might return */
2308 if (SUCCEEDED(hr
) && pszPath
)
2309 strcpyW(pszPath
, szBuildPath
);
2311 /* if we don't care about existing directories we are ready */
2312 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
2314 if (PathFileExistsW(szBuildPath
)) goto end
;
2316 /* not existing but we are not allowed to create it. The return value
2317 * is verified against shell32 version 6.0.
2319 if (!(nFolder
& CSIDL_FLAG_CREATE
))
2321 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2325 /* create directory/directories */
2326 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
2327 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
2329 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
2334 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
2336 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
2340 /*************************************************************************
2341 * SHGetFolderPathA [SHELL32.@]
2343 * See SHGetFolderPathW.
2345 HRESULT WINAPI
SHGetFolderPathA(
2352 WCHAR szTemp
[MAX_PATH
];
2355 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
2359 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
2360 if (SUCCEEDED(hr
) && pszPath
)
2361 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
2367 /* For each folder in folders, if its value has not been set in the registry,
2368 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
2369 * folder's type) to get the unexpanded value first.
2370 * Writes the unexpanded value to User Shell Folders, and queries it with
2371 * SHGetFolderPathW to force the creation of the directory if it doesn't
2372 * already exist. SHGetFolderPathW also returns the expanded value, which
2373 * this then writes to Shell Folders.
2375 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
2376 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
2379 const WCHAR
*szValueName
;
2382 WCHAR path
[MAX_PATH
];
2384 HKEY hUserKey
= NULL
, hKey
= NULL
;
2385 DWORD dwType
, dwPathLen
;
2388 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
2389 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
2391 ret
= RegCreateKeyW(hRootKey
, szUserShellFolderPath
, &hUserKey
);
2393 hr
= HRESULT_FROM_WIN32(ret
);
2396 ret
= RegCreateKeyW(hRootKey
, szShellFolderPath
, &hKey
);
2398 hr
= HRESULT_FROM_WIN32(ret
);
2400 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
2402 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2404 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
2405 szValueName
= CSIDL_Data
[folders
[i
]].szValueName
;
2406 if (!szValueName
&& CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2408 StringFromGUID2( CSIDL_Data
[folders
[i
]].id
, buffer
, 39 );
2409 szValueName
= &buffer
[0];
2412 if (RegQueryValueExW(hUserKey
, szValueName
, NULL
,
2413 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
2414 dwType
!= REG_EXPAND_SZ
))
2417 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2418 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
2420 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
2421 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
2422 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
2424 GetWindowsDirectoryW(path
, MAX_PATH
);
2425 if (CSIDL_Data
[folders
[i
]].szDefaultPath
&&
2426 !IS_INTRESOURCE(CSIDL_Data
[folders
[i
]].szDefaultPath
))
2428 PathAddBackslashW(path
);
2429 strcatW(path
, CSIDL_Data
[folders
[i
]].szDefaultPath
);
2436 ret
= RegSetValueExW(hUserKey
, szValueName
, 0, REG_EXPAND_SZ
,
2437 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2439 hr
= HRESULT_FROM_WIN32(ret
);
2442 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
2443 hToken
, SHGFP_TYPE_DEFAULT
, path
);
2444 ret
= RegSetValueExW(hKey
, szValueName
, 0, REG_SZ
,
2445 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2447 hr
= HRESULT_FROM_WIN32(ret
);
2453 RegCloseKey(hUserKey
);
2457 TRACE("returning 0x%08x\n", hr
);
2461 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
2463 static const UINT folders
[] = {
2474 CSIDL_DESKTOPDIRECTORY
,
2478 CSIDL_LOCAL_APPDATA
,
2479 CSIDL_INTERNET_CACHE
,
2488 CSIDL_APPDATA_LOCALLOW
,
2492 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
2493 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
2498 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
2501 hToken
= (HANDLE
)-1;
2502 hRootKey
= HKEY_USERS
;
2503 strcpyW(userShellFolderPath
, DefaultW
);
2504 PathAddBackslashW(userShellFolderPath
);
2505 strcatW(userShellFolderPath
, szSHUserFolders
);
2506 pUserShellFolderPath
= userShellFolderPath
;
2507 strcpyW(shellFolderPath
, DefaultW
);
2508 PathAddBackslashW(shellFolderPath
);
2509 strcatW(shellFolderPath
, szSHFolders
);
2510 pShellFolderPath
= shellFolderPath
;
2515 hRootKey
= HKEY_CURRENT_USER
;
2516 pUserShellFolderPath
= szSHUserFolders
;
2517 pShellFolderPath
= szSHFolders
;
2520 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
2521 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2522 TRACE("returning 0x%08x\n", hr
);
2526 static HRESULT
_SHRegisterCommonShellFolders(void)
2528 static const UINT folders
[] = {
2529 CSIDL_COMMON_STARTMENU
,
2530 CSIDL_COMMON_PROGRAMS
,
2531 CSIDL_COMMON_STARTUP
,
2532 CSIDL_COMMON_DESKTOPDIRECTORY
,
2533 CSIDL_COMMON_FAVORITES
,
2534 CSIDL_COMMON_APPDATA
,
2535 CSIDL_COMMON_TEMPLATES
,
2536 CSIDL_COMMON_DOCUMENTS
,
2537 CSIDL_COMMON_ADMINTOOLS
,
2539 CSIDL_COMMON_PICTURES
,
2545 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
2546 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2547 TRACE("returning 0x%08x\n", hr
);
2551 /******************************************************************************
2552 * _SHAppendToUnixPath [Internal]
2554 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
2555 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
2556 * and replaces backslashes with slashes.
2559 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
2560 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
2566 static inline BOOL
_SHAppendToUnixPath(char *szBasePath
, LPCWSTR pwszSubPath
) {
2567 WCHAR wszSubPath
[MAX_PATH
];
2568 int cLen
= strlen(szBasePath
);
2571 if (IS_INTRESOURCE(pwszSubPath
)) {
2572 if (!LoadStringW(shell32_hInstance
, LOWORD(pwszSubPath
), wszSubPath
, MAX_PATH
)) {
2573 /* Fall back to hard coded defaults. */
2574 switch (LOWORD(pwszSubPath
)) {
2576 lstrcpyW(wszSubPath
, DocumentsW
);
2579 lstrcpyW(wszSubPath
, My_MusicW
);
2581 case IDS_MYPICTURES
:
2582 lstrcpyW(wszSubPath
, My_PicturesW
);
2585 lstrcpyW(wszSubPath
, My_VideosW
);
2588 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath
));
2593 lstrcpyW(wszSubPath
, pwszSubPath
);
2596 if (szBasePath
[cLen
-1] != '/') szBasePath
[cLen
++] = '/';
2598 if (!WideCharToMultiByte(CP_UNIXCP
, 0, wszSubPath
, -1, szBasePath
+ cLen
,
2599 FILENAME_MAX
- cLen
, NULL
, NULL
))
2604 pBackslash
= szBasePath
+ cLen
;
2605 while ((pBackslash
= strchr(pBackslash
, '\\'))) *pBackslash
= '/';
2610 /******************************************************************************
2611 * _SHCreateSymbolicLinks [Internal]
2613 * Sets up symbol links for various shell folders to point into the users home
2614 * directory. We do an educated guess about what the user would probably want:
2615 * - If there is a 'My Documents' directory in $HOME, the user probably wants
2616 * wine's 'My Documents' to point there. Furthermore, we imply that the user
2617 * is a Windows lover and has no problem with wine creating 'My Pictures',
2618 * 'My Music' and 'My Videos' subfolders under '$HOME/My Documents', if those
2619 * do not already exits. We put appropriate symbolic links in place for those,
2621 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2622 * point directly to $HOME. We assume the user to be a unix hacker who does not
2623 * want wine to create anything anywhere besides the .wine directory. So, if
2624 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2625 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
2626 * directory, and try to link to that. If that fails, then we symlink to
2627 * $HOME directly. The same holds fo 'My Pictures' and 'My Videos'.
2628 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
2629 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
2631 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2633 static void _SHCreateSymbolicLinks(void)
2635 UINT aidsMyStuff
[] = { IDS_MYPICTURES
, IDS_MYVIDEOS
, IDS_MYMUSIC
}, i
;
2636 int acsidlMyStuff
[] = { CSIDL_MYPICTURES
, CSIDL_MYVIDEO
, CSIDL_MYMUSIC
};
2637 static const char * const xdg_dirs
[] = { "PICTURES", "VIDEOS", "MUSIC", "DESKTOP" };
2638 static const unsigned int num
= sizeof(xdg_dirs
) / sizeof(xdg_dirs
[0]);
2639 WCHAR wszTempPath
[MAX_PATH
];
2640 char szPersonalTarget
[FILENAME_MAX
], *pszPersonal
;
2641 char szMyStuffTarget
[FILENAME_MAX
], *pszMyStuff
;
2642 char szDesktopTarget
[FILENAME_MAX
], *pszDesktop
;
2643 struct stat statFolder
;
2644 const char *pszHome
;
2646 char ** xdg_results
;
2647 char * xdg_desktop_dir
;
2649 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2650 hr
= SHGetFolderPathW(NULL
, CSIDL_PERSONAL
|CSIDL_FLAG_CREATE
, NULL
,
2651 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2652 if (FAILED(hr
)) return;
2653 pszPersonal
= wine_get_unix_file_name(wszTempPath
);
2654 if (!pszPersonal
) return;
2656 hr
= XDG_UserDirLookup(xdg_dirs
, num
, &xdg_results
);
2657 if (FAILED(hr
)) xdg_results
= NULL
;
2659 pszHome
= getenv("HOME");
2660 if (pszHome
&& !stat(pszHome
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)) {
2661 strcpy(szPersonalTarget
, pszHome
);
2662 if (_SHAppendToUnixPath(szPersonalTarget
, MAKEINTRESOURCEW(IDS_PERSONAL
)) &&
2663 !stat(szPersonalTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2665 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2666 * 'My Music' subfolders or fail silently if they already exist. */
2667 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2668 strcpy(szMyStuffTarget
, szPersonalTarget
);
2669 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2670 mkdir(szMyStuffTarget
, 0777);
2675 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2676 strcpy(szPersonalTarget
, pszHome
);
2679 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2681 symlink(szPersonalTarget
, pszPersonal
);
2685 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2686 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2687 strcpy(szPersonalTarget
, pszPersonal
);
2688 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2689 strcpy(szMyStuffTarget
, szPersonalTarget
);
2690 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2691 mkdir(szMyStuffTarget
, 0777);
2695 /* Create symbolic links for 'My Pictures', 'My Videos' and 'My Music'. */
2696 for (i
=0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2697 /* Create the current 'My Whatever' folder and get its unix path. */
2698 hr
= SHGetFolderPathW(NULL
, acsidlMyStuff
[i
]|CSIDL_FLAG_CREATE
, NULL
,
2699 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2700 if (FAILED(hr
)) continue;
2701 pszMyStuff
= wine_get_unix_file_name(wszTempPath
);
2702 if (!pszMyStuff
) continue;
2704 strcpy(szMyStuffTarget
, szPersonalTarget
);
2705 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])) &&
2706 !stat(szMyStuffTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2708 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2710 symlink(szMyStuffTarget
, pszMyStuff
);
2715 if (xdg_results
&& xdg_results
[i
])
2717 /* the folder specified by XDG_XXX_DIR exists, link to it. */
2718 symlink(xdg_results
[i
], pszMyStuff
);
2722 /* Else link to where 'My Documents' itself links to. */
2723 symlink(szPersonalTarget
, pszMyStuff
);
2726 HeapFree(GetProcessHeap(), 0, pszMyStuff
);
2729 /* Last but not least, the Desktop folder */
2731 strcpy(szDesktopTarget
, pszHome
);
2733 strcpy(szDesktopTarget
, pszPersonal
);
2734 HeapFree(GetProcessHeap(), 0, pszPersonal
);
2736 xdg_desktop_dir
= xdg_results
? xdg_results
[num
- 1] : NULL
;
2737 if (xdg_desktop_dir
||
2738 (_SHAppendToUnixPath(szDesktopTarget
, DesktopW
) &&
2739 !stat(szDesktopTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)))
2741 hr
= SHGetFolderPathW(NULL
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, NULL
,
2742 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2743 if (SUCCEEDED(hr
) && (pszDesktop
= wine_get_unix_file_name(wszTempPath
)))
2746 if (xdg_desktop_dir
)
2747 symlink(xdg_desktop_dir
, pszDesktop
);
2749 symlink(szDesktopTarget
, pszDesktop
);
2750 HeapFree(GetProcessHeap(), 0, pszDesktop
);
2754 /* Free resources allocated by XDG_UserDirLookup() */
2757 for (i
= 0; i
< num
; i
++)
2758 HeapFree(GetProcessHeap(), 0, xdg_results
[i
]);
2759 HeapFree(GetProcessHeap(), 0, xdg_results
);
2763 /******************************************************************************
2764 * create_extra_folders [Internal]
2766 * Create some extra folders that don't have a standard CSIDL definition.
2768 static HRESULT
create_extra_folders(void)
2770 static const WCHAR environW
[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
2771 static const WCHAR microsoftW
[] = {'M','i','c','r','o','s','o','f','t',0};
2772 static const WCHAR TempW
[] = {'T','e','m','p',0};
2773 static const WCHAR TEMPW
[] = {'T','E','M','P',0};
2774 static const WCHAR TMPW
[] = {'T','M','P',0};
2775 WCHAR path
[MAX_PATH
+5];
2778 DWORD type
, size
, ret
;
2780 ret
= RegCreateKeyW( HKEY_CURRENT_USER
, environW
, &hkey
);
2781 if (ret
) return HRESULT_FROM_WIN32( ret
);
2783 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
2784 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
,
2785 SHGFP_TYPE_DEFAULT
, TempW
, path
);
2788 size
= sizeof(path
);
2789 if (RegQueryValueExW( hkey
, TEMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2790 RegSetValueExW( hkey
, TEMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2791 size
= sizeof(path
);
2792 if (RegQueryValueExW( hkey
, TMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2793 RegSetValueExW( hkey
, TMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2795 RegCloseKey( hkey
);
2799 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA
| CSIDL_FLAG_CREATE
, NULL
,
2800 SHGFP_TYPE_DEFAULT
, microsoftW
, path
);
2806 /******************************************************************************
2807 * set_folder_attributes
2809 * Set the various folder attributes registry keys.
2811 static HRESULT
set_folder_attributes(void)
2813 static const WCHAR clsidW
[] = {'C','L','S','I','D','\\',0 };
2814 static const WCHAR shellfolderW
[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
2815 static const WCHAR wfparsingW
[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
2816 static const WCHAR wfdisplayW
[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
2817 static const WCHAR hideasdeleteW
[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
2818 static const WCHAR attributesW
[] = {'A','t','t','r','i','b','u','t','e','s',0};
2819 static const WCHAR cfattributesW
[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
2820 static const WCHAR emptyW
[] = {0};
2829 DWORD call_for_attr
;
2832 { &CLSID_UnixFolder
, TRUE
, FALSE
, FALSE
},
2833 { &CLSID_UnixDosFolder
, TRUE
, FALSE
, FALSE
,
2834 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2835 { &CLSID_FolderShortcut
, FALSE
, FALSE
, FALSE
,
2836 SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_LINK
,
2837 SFGAO_HASSUBFOLDER
|SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_FILESYSANCESTOR
},
2838 { &CLSID_MyDocuments
, TRUE
, FALSE
, FALSE
,
2839 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2840 { &CLSID_RecycleBin
, FALSE
, FALSE
, FALSE
,
2841 SFGAO_FOLDER
|SFGAO_DROPTARGET
|SFGAO_HASPROPSHEET
},
2842 { &CLSID_ControlPanel
, FALSE
, TRUE
, TRUE
,
2843 SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
}
2847 WCHAR buffer
[39 + (sizeof(clsidW
) + sizeof(shellfolderW
)) / sizeof(WCHAR
)];
2851 for (i
= 0; i
< sizeof(folders
)/sizeof(folders
[0]); i
++)
2853 strcpyW( buffer
, clsidW
);
2854 StringFromGUID2( folders
[i
].clsid
, buffer
+ strlenW(buffer
), 39 );
2855 strcatW( buffer
, shellfolderW
);
2856 res
= RegCreateKeyExW( HKEY_CLASSES_ROOT
, buffer
, 0, NULL
, 0,
2857 KEY_READ
| KEY_WRITE
, NULL
, &hkey
, NULL
);
2858 if (res
) return HRESULT_FROM_WIN32( res
);
2859 if (folders
[i
].wfparsing
)
2860 res
= RegSetValueExW( hkey
, wfparsingW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2861 if (folders
[i
].wfdisplay
)
2862 res
= RegSetValueExW( hkey
, wfdisplayW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2863 if (folders
[i
].hideasdel
)
2864 res
= RegSetValueExW( hkey
, hideasdeleteW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2865 if (folders
[i
].attr
)
2866 res
= RegSetValueExW( hkey
, attributesW
, 0, REG_DWORD
,
2867 (const BYTE
*)&folders
[i
].attr
, sizeof(DWORD
));
2868 if (folders
[i
].call_for_attr
)
2869 res
= RegSetValueExW( hkey
, cfattributesW
, 0, REG_DWORD
,
2870 (const BYTE
*)&folders
[i
].call_for_attr
, sizeof(DWORD
));
2871 RegCloseKey( hkey
);
2877 /* Register the default values in the registry, as some apps seem to depend
2878 * on their presence. The set registered was taken from Windows XP.
2880 HRESULT
SHELL_RegisterShellFolders(void)
2884 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2885 * 'My Videos', 'My Music' and 'Desktop' in advance, so that the
2886 * _SHRegister*ShellFolders() functions will find everything nice and clean
2887 * and thus will not attempt to create them in the profile directory. */
2888 _SHCreateSymbolicLinks();
2890 hr
= _SHRegisterUserShellFolders(TRUE
);
2892 hr
= _SHRegisterUserShellFolders(FALSE
);
2894 hr
= _SHRegisterCommonShellFolders();
2896 hr
= create_extra_folders();
2898 hr
= set_folder_attributes();
2902 /*************************************************************************
2903 * SHGetSpecialFolderPathA [SHELL32.@]
2905 BOOL WINAPI
SHGetSpecialFolderPathA (
2911 return SHGetFolderPathA(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2915 /*************************************************************************
2916 * SHGetSpecialFolderPathW
2918 BOOL WINAPI
SHGetSpecialFolderPathW (
2924 return SHGetFolderPathW(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2928 /*************************************************************************
2929 * SHGetSpecialFolderPath (SHELL32.175)
2931 BOOL WINAPI
SHGetSpecialFolderPathAW (
2938 if (SHELL_OsIsUnicode())
2939 return SHGetSpecialFolderPathW (hwndOwner
, szPath
, nFolder
, bCreate
);
2940 return SHGetSpecialFolderPathA (hwndOwner
, szPath
, nFolder
, bCreate
);
2943 /*************************************************************************
2944 * SHGetFolderLocation [SHELL32.@]
2946 * Gets the folder locations from the registry and creates a pidl.
2950 * nFolder [I] CSIDL_xxxxx
2951 * hToken [I] token representing user, or NULL for current user, or -1 for
2953 * dwReserved [I] must be zero
2954 * ppidl [O] PIDL of a special folder
2958 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2961 * Creates missing reg keys and directories.
2962 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2963 * virtual folders that are handled here.
2965 HRESULT WINAPI
SHGetFolderLocation(
2970 LPITEMIDLIST
*ppidl
)
2972 HRESULT hr
= E_INVALIDARG
;
2974 TRACE("%p 0x%08x %p 0x%08x %p\n",
2975 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
2978 return E_INVALIDARG
;
2980 return E_INVALIDARG
;
2982 /* The virtual folders' locations are not user-dependent */
2984 switch (nFolder
& CSIDL_FOLDER_MASK
)
2987 *ppidl
= _ILCreateDesktop();
2990 case CSIDL_PERSONAL
:
2991 *ppidl
= _ILCreateMyDocuments();
2994 case CSIDL_INTERNET
:
2995 *ppidl
= _ILCreateIExplore();
2998 case CSIDL_CONTROLS
:
2999 *ppidl
= _ILCreateControlPanel();
3002 case CSIDL_PRINTERS
:
3003 *ppidl
= _ILCreatePrinters();
3006 case CSIDL_BITBUCKET
:
3007 *ppidl
= _ILCreateBitBucket();
3011 *ppidl
= _ILCreateMyComputer();
3015 *ppidl
= _ILCreateNetwork();
3020 WCHAR szPath
[MAX_PATH
];
3022 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
3023 SHGFP_TYPE_CURRENT
, szPath
);
3028 TRACE("Value=%s\n", debugstr_w(szPath
));
3029 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
3031 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
3033 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
3034 * version 6.0 returns E_FAIL for nonexistent paths
3043 TRACE("-- (new pidl %p)\n",*ppidl
);
3047 /*************************************************************************
3048 * SHGetSpecialFolderLocation [SHELL32.@]
3051 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
3054 HRESULT WINAPI
SHGetSpecialFolderLocation(
3057 LPITEMIDLIST
* ppidl
)
3059 HRESULT hr
= E_INVALIDARG
;
3061 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
3064 return E_INVALIDARG
;
3066 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);
3070 static int csidl_from_id( const KNOWNFOLDERID
*id
)
3073 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
3074 if (IsEqualGUID( CSIDL_Data
[i
].id
, id
)) return i
;
3078 /*************************************************************************
3079 * SHGetKnownFolderPath [SHELL32.@]
3081 HRESULT WINAPI
SHGetKnownFolderPath(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PWSTR
*path
)
3084 WCHAR folder
[MAX_PATH
];
3085 int index
= csidl_from_id( rfid
);
3087 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid
), flags
, token
, path
);
3092 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND
);
3094 if (flags
& KF_FLAG_CREATE
)
3095 index
|= CSIDL_FLAG_CREATE
;
3097 if (flags
& KF_FLAG_DONT_VERIFY
)
3098 index
|= CSIDL_FLAG_DONT_VERIFY
;
3100 if (flags
& KF_FLAG_NO_ALIAS
)
3101 index
|= CSIDL_FLAG_NO_ALIAS
;
3103 if (flags
& KF_FLAG_INIT
)
3104 index
|= CSIDL_FLAG_PER_USER_INIT
;
3106 if (flags
& ~(KF_FLAG_CREATE
|KF_FLAG_DONT_VERIFY
|KF_FLAG_NO_ALIAS
|KF_FLAG_INIT
))
3108 FIXME("flags 0x%08x not supported\n", flags
);
3109 return E_INVALIDARG
;
3112 hr
= SHGetFolderPathW( NULL
, index
, token
, 0, folder
);
3115 *path
= CoTaskMemAlloc( (strlenW( folder
) + 1) * sizeof(WCHAR
) );
3117 return E_OUTOFMEMORY
;
3118 strcpyW( *path
, folder
);
3123 /*************************************************************************
3124 * SHGetFolderPathEx [SHELL32.@]
3126 HRESULT WINAPI
SHGetFolderPathEx(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, LPWSTR path
, DWORD len
)
3131 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid
), flags
, token
, path
, len
);
3133 if (!path
|| !len
) return E_INVALIDARG
;
3135 hr
= SHGetKnownFolderPath( rfid
, flags
, token
, &buffer
);
3136 if (SUCCEEDED( hr
))
3138 if (strlenW( buffer
) + 1 > len
)
3140 CoTaskMemFree( buffer
);
3141 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER
);
3143 strcpyW( path
, buffer
);
3144 CoTaskMemFree( buffer
);
3149 /* constant values used by known folder functions */
3150 static const WCHAR szCategory
[] = {'C','a','t','e','g','o','r','y',0};
3151 static const WCHAR szName
[] = {'N','a','m','e',0};
3152 static const WCHAR szRelativePath
[] = {'R','e','l','a','t','i','v','e','P','a','t','h',0};
3153 static const WCHAR szParentFolder
[] = {'P','a','r','e','n','t','F','o','l','d','e','r',0};
3156 * Internal function to convert known folder identifier to path of registry key
3157 * associated with known folder.
3160 * rfid [I] pointer to known folder identifier (may be NULL)
3161 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
3162 * lpPath [O] place to store string address. String should be
3163 * later freed using HeapFree(GetProcessHeap(),0, ... )
3165 static HRESULT
get_known_folder_registry_path(
3166 REFKNOWNFOLDERID rfid
,
3167 LPWSTR lpStringGuid
,
3170 static const WCHAR sBackslash
[] = {'\\',0};
3175 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid
), debugstr_w(lpStringGuid
), lpPath
);
3178 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3180 lstrcpyW(sGuid
, lpStringGuid
);
3182 length
= lstrlenW(szKnownFolderDescriptions
)+51;
3183 *lpPath
= HeapAlloc(GetProcessHeap(), 0, length
*sizeof(WCHAR
));
3189 lstrcpyW(*lpPath
, szKnownFolderDescriptions
);
3190 lstrcatW(*lpPath
, sBackslash
);
3191 lstrcatW(*lpPath
, sGuid
);
3198 * Internal function to get place where folder redirection information are stored.
3201 * rfid [I] pointer to known folder identifier (may be NULL)
3202 * rootKey [O] root key where the redirection information are stored
3203 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
3204 * However, besides root key, path is always that same, and is stored
3205 * as "szKnownFolderRedirections" constant
3207 static HRESULT
get_known_folder_redirection_place(
3208 REFKNOWNFOLDERID rfid
,
3212 LPWSTR lpRegistryPath
= NULL
;
3213 KF_CATEGORY category
;
3216 /* first, get known folder's category */
3217 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3221 dwSize
= sizeof(category
);
3222 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, lpRegistryPath
, szCategory
, RRF_RT_DWORD
, NULL
, &category
, &dwSize
));
3227 if(category
== KF_CATEGORY_COMMON
)
3229 *rootKey
= HKEY_LOCAL_MACHINE
;
3232 else if(category
== KF_CATEGORY_PERUSER
)
3234 *rootKey
= HKEY_CURRENT_USER
;
3241 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3245 static HRESULT
get_known_folder_path_by_id(REFKNOWNFOLDERID folderId
, LPWSTR lpRegistryPath
, DWORD dwFlags
, LPWSTR
*ppszPath
);
3247 static HRESULT
get_known_folder_category(
3248 LPWSTR registryPath
,
3249 KF_CATEGORY
* pCategory
)
3251 DWORD dwSize
= sizeof(DWORD
);
3253 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szCategory
, RRF_RT_DWORD
, &dwType
, pCategory
, &dwSize
));
3256 static HRESULT
redirect_known_folder(
3257 REFKNOWNFOLDERID rfid
,
3259 KF_REDIRECT_FLAGS flags
,
3260 LPCWSTR pszTargetPath
,
3262 KNOWNFOLDERID
const *pExclusion
,
3266 HKEY rootKey
= HKEY_LOCAL_MACHINE
, hKey
;
3268 LPWSTR lpRegistryPath
= NULL
, lpSrcPath
= NULL
;
3269 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid
), hwnd
, flags
, debugstr_w(pszTargetPath
), cFolders
, pExclusion
, ppszError
);
3271 if (ppszError
) *ppszError
= NULL
;
3273 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3276 hr
= get_known_folder_path_by_id(rfid
, lpRegistryPath
, 0, &lpSrcPath
);
3278 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3280 /* get path to redirection storage */
3282 hr
= get_known_folder_redirection_place(rfid
, &rootKey
);
3284 /* write redirection information */
3286 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey
, szKnownFolderRedirections
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hKey
, NULL
));
3290 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3292 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, sGuid
, 0, REG_SZ
, (LPBYTE
)pszTargetPath
, (lstrlenW(pszTargetPath
)+1)*sizeof(WCHAR
)));
3297 /* make sure destination path exists */
3298 SHCreateDirectory(NULL
, pszTargetPath
);
3300 /* copy content if required */
3301 if(SUCCEEDED(hr
) && (flags
& KF_REDIRECT_COPY_CONTENTS
) )
3303 static const WCHAR sWildcard
[] = {'\\','*',0};
3304 WCHAR srcPath
[MAX_PATH
+1], dstPath
[MAX_PATH
+1];
3305 SHFILEOPSTRUCTW fileOp
;
3307 ZeroMemory(srcPath
, sizeof(srcPath
));
3308 lstrcpyW(srcPath
, lpSrcPath
);
3309 lstrcatW(srcPath
, sWildcard
);
3311 ZeroMemory(dstPath
, sizeof(dstPath
));
3312 lstrcpyW(dstPath
, pszTargetPath
);
3314 ZeroMemory(&fileOp
, sizeof(fileOp
));
3316 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3317 fileOp
.wFunc
= FO_MOVE
;
3319 fileOp
.wFunc
= FO_COPY
;
3321 fileOp
.pFrom
= srcPath
;
3322 fileOp
.pTo
= dstPath
;
3323 fileOp
.fFlags
= FOF_NO_UI
;
3325 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3327 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3329 ZeroMemory(srcPath
, sizeof(srcPath
));
3330 lstrcpyW(srcPath
, lpSrcPath
);
3332 ZeroMemory(&fileOp
, sizeof(fileOp
));
3333 fileOp
.wFunc
= FO_DELETE
;
3334 fileOp
.pFrom
= srcPath
;
3335 fileOp
.fFlags
= FOF_NO_UI
;
3337 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3341 CoTaskMemFree(lpSrcPath
);
3349 IKnownFolder IKnownFolder_iface
;
3352 LPWSTR registryPath
;
3355 static inline struct knownfolder
*impl_from_IKnownFolder( IKnownFolder
*iface
)
3357 return CONTAINING_RECORD( iface
, struct knownfolder
, IKnownFolder_iface
);
3360 static ULONG WINAPI
knownfolder_AddRef(
3361 IKnownFolder
*iface
)
3363 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3364 return InterlockedIncrement( &knownfolder
->refs
);
3367 static ULONG WINAPI
knownfolder_Release(
3368 IKnownFolder
*iface
)
3370 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3371 LONG refs
= InterlockedDecrement( &knownfolder
->refs
);
3374 TRACE("destroying %p\n", knownfolder
);
3375 HeapFree( GetProcessHeap(), 0, knownfolder
->registryPath
);
3376 HeapFree( GetProcessHeap(), 0, knownfolder
);
3381 static HRESULT WINAPI
knownfolder_QueryInterface(
3382 IKnownFolder
*iface
,
3386 struct knownfolder
*This
= impl_from_IKnownFolder( iface
);
3388 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3390 if ( IsEqualGUID( riid
, &IID_IKnownFolder
) ||
3391 IsEqualGUID( riid
, &IID_IUnknown
) )
3397 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3398 return E_NOINTERFACE
;
3400 IKnownFolder_AddRef( iface
);
3404 static HRESULT
knownfolder_set_id(
3405 struct knownfolder
*knownfolder
,
3406 const KNOWNFOLDERID
*kfid
)
3411 TRACE("%s\n", debugstr_guid(kfid
));
3413 knownfolder
->id
= *kfid
;
3415 /* check is it registry-registered folder */
3416 hr
= get_known_folder_registry_path(kfid
, NULL
, &knownfolder
->registryPath
);
3418 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, 0, 0, &hKey
));
3427 /* This known folder is not registered. To mark it, we set registryPath to NULL */
3428 HeapFree(GetProcessHeap(), 0, knownfolder
->registryPath
);
3429 knownfolder
->registryPath
= NULL
;
3436 static HRESULT WINAPI
knownfolder_GetId(
3437 IKnownFolder
*iface
,
3438 KNOWNFOLDERID
*pkfid
)
3440 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3442 TRACE("%p\n", pkfid
);
3444 *pkfid
= knownfolder
->id
;
3448 static HRESULT WINAPI
knownfolder_GetCategory(
3449 IKnownFolder
*iface
,
3450 KF_CATEGORY
*pCategory
)
3452 struct knownfolder
*knownfolder
= impl_from_IKnownFolder(iface
);
3455 TRACE("%p, %p\n", knownfolder
, pCategory
);
3457 /* we cannot get a category for a folder which is not registered */
3458 if(!knownfolder
->registryPath
)
3462 hr
= get_known_folder_category(knownfolder
->registryPath
, pCategory
);
3467 static HRESULT WINAPI
knownfolder_GetShellItem(
3468 IKnownFolder
*iface
,
3473 FIXME("0x%08x, %s, %p\n", dwFlags
, debugstr_guid(riid
), ppv
);
3477 static HRESULT
get_known_folder_path(
3479 LPWSTR registryPath
,
3482 static const WCHAR sBackslash
[] = {'\\',0};
3484 DWORD dwSize
, dwType
;
3485 WCHAR path
[MAX_PATH
] = {0};
3486 WCHAR parentGuid
[39];
3487 KF_CATEGORY category
;
3488 LPWSTR parentRegistryPath
, parentPath
;
3489 HKEY hRedirectionRootKey
= NULL
;
3491 TRACE("(%s, %p)\n", debugstr_w(registryPath
), ppszPath
);
3494 /* check if folder has parent */
3495 dwSize
= sizeof(parentGuid
);
3496 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szParentFolder
, RRF_RT_REG_SZ
, &dwType
, parentGuid
, &dwSize
));
3497 if(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) hr
= S_FALSE
;
3501 /* get parent's known folder path (recursive) */
3502 hr
= get_known_folder_registry_path(NULL
, parentGuid
, &parentRegistryPath
);
3503 if(FAILED(hr
)) return hr
;
3505 hr
= get_known_folder_path(parentGuid
, parentRegistryPath
, &parentPath
);
3507 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3511 lstrcatW(path
, parentPath
);
3512 lstrcatW(path
, sBackslash
);
3514 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3515 HeapFree(GetProcessHeap(), 0, parentPath
);
3518 /* check, if folder was redirected */
3520 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szCategory
, RRF_RT_REG_DWORD
, NULL
, &category
, &dwSize
));
3524 if(category
== KF_CATEGORY_COMMON
)
3525 hRedirectionRootKey
= HKEY_LOCAL_MACHINE
;
3526 else if(category
== KF_CATEGORY_PERUSER
)
3527 hRedirectionRootKey
= HKEY_CURRENT_USER
;
3529 if(hRedirectionRootKey
)
3531 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3535 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3536 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3541 lstrcpyW(*ppszPath
, path
);
3542 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3548 /* no redirection, use previous way - read the relative path from folder definition */
3549 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, NULL
, &dwSize
));
3553 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3554 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3559 lstrcpyW(*ppszPath
, path
);
3560 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3565 TRACE("returning path: %s\n", debugstr_w(*ppszPath
));
3569 static HRESULT
get_known_folder_path_by_id(
3570 REFKNOWNFOLDERID folderId
,
3571 LPWSTR lpRegistryPath
,
3579 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId
), debugstr_w(lpRegistryPath
), dwFlags
, ppszPath
);
3581 /* if this is registry-registered known folder, get path from registry */
3584 StringFromGUID2(folderId
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3586 hr
= get_known_folder_path(sGuid
, lpRegistryPath
, ppszPath
);
3588 /* in other case, use older way */
3590 hr
= SHGetKnownFolderPath( folderId
, dwFlags
, NULL
, ppszPath
);
3592 if (FAILED(hr
)) return hr
;
3594 /* check if known folder really exists */
3595 dwAttributes
= GetFileAttributesW(*ppszPath
);
3596 if(dwAttributes
== INVALID_FILE_ATTRIBUTES
|| !(dwAttributes
& FILE_ATTRIBUTE_DIRECTORY
) )
3598 TRACE("directory %s not found\n", debugstr_w(*ppszPath
));
3599 CoTaskMemFree(*ppszPath
);
3601 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
3607 static HRESULT WINAPI
knownfolder_GetPath(
3608 IKnownFolder
*iface
,
3612 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3613 TRACE("(%p, 0x%08x, %p)\n", knownfolder
, dwFlags
, ppszPath
);
3615 return get_known_folder_path_by_id(&knownfolder
->id
, knownfolder
->registryPath
, dwFlags
, ppszPath
);
3618 static HRESULT WINAPI
knownfolder_SetPath(
3619 IKnownFolder
*iface
,
3623 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3626 TRACE("(%p, 0x%08x, %s)\n", knownfolder
, dwFlags
, debugstr_w(pszPath
));
3628 /* check if the known folder is registered */
3629 if(!knownfolder
->registryPath
)
3633 hr
= redirect_known_folder(&knownfolder
->id
, NULL
, 0, pszPath
, 0, NULL
, NULL
);
3638 static HRESULT WINAPI
knownfolder_GetIDList(
3639 IKnownFolder
*iface
,
3641 PIDLIST_ABSOLUTE
*ppidl
)
3643 FIXME("0x%08x, %p\n", dwFlags
, ppidl
);
3647 static HRESULT WINAPI
knownfolder_GetFolderType(
3648 IKnownFolder
*iface
,
3649 FOLDERTYPEID
*pftid
)
3651 FIXME("%p\n", pftid
);
3655 static HRESULT WINAPI
knownfolder_GetRedirectionCapabilities(
3656 IKnownFolder
*iface
,
3657 KF_REDIRECTION_CAPABILITIES
*pCapabilities
)
3659 FIXME("%p\n", pCapabilities
);
3663 static HRESULT WINAPI
knownfolder_GetFolderDefinition(
3664 IKnownFolder
*iface
,
3665 KNOWNFOLDER_DEFINITION
*pKFD
)
3667 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3670 TRACE("(%p, %p)\n", knownfolder
, pKFD
);
3672 if(!pKFD
) return E_INVALIDARG
;
3674 ZeroMemory(pKFD
, sizeof(*pKFD
));
3676 hr
= get_known_folder_category(knownfolder
->registryPath
, &pKFD
->category
);
3679 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, szName
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3683 pKFD
->pszName
= CoTaskMemAlloc(dwSize
);
3684 if(!pKFD
->pszName
) hr
= E_OUTOFMEMORY
;
3688 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, szName
, RRF_RT_REG_SZ
, NULL
, pKFD
->pszName
, &dwSize
));
3693 static const struct IKnownFolderVtbl knownfolder_vtbl
=
3695 knownfolder_QueryInterface
,
3697 knownfolder_Release
,
3699 knownfolder_GetCategory
,
3700 knownfolder_GetShellItem
,
3701 knownfolder_GetPath
,
3702 knownfolder_SetPath
,
3703 knownfolder_GetIDList
,
3704 knownfolder_GetFolderType
,
3705 knownfolder_GetRedirectionCapabilities
,
3706 knownfolder_GetFolderDefinition
3709 static HRESULT
knownfolder_create( struct knownfolder
**knownfolder
)
3711 struct knownfolder
*kf
;
3713 kf
= HeapAlloc( GetProcessHeap(), 0, sizeof(*kf
) );
3714 if (!kf
) return E_OUTOFMEMORY
;
3716 kf
->IKnownFolder_iface
.lpVtbl
= &knownfolder_vtbl
;
3718 memset( &kf
->id
, 0, sizeof(kf
->id
) );
3719 kf
->registryPath
= NULL
;
3723 TRACE("returning iface %p\n", &kf
->IKnownFolder_iface
);
3727 struct foldermanager
3729 IKnownFolderManager IKnownFolderManager_iface
;
3735 static inline struct foldermanager
*impl_from_IKnownFolderManager( IKnownFolderManager
*iface
)
3737 return CONTAINING_RECORD( iface
, struct foldermanager
, IKnownFolderManager_iface
);
3740 static ULONG WINAPI
foldermanager_AddRef(
3741 IKnownFolderManager
*iface
)
3743 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3744 return InterlockedIncrement( &foldermanager
->refs
);
3747 static ULONG WINAPI
foldermanager_Release(
3748 IKnownFolderManager
*iface
)
3750 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3751 LONG refs
= InterlockedDecrement( &foldermanager
->refs
);
3754 TRACE("destroying %p\n", foldermanager
);
3755 HeapFree( GetProcessHeap(), 0, foldermanager
->ids
);
3756 HeapFree( GetProcessHeap(), 0, foldermanager
);
3761 static HRESULT WINAPI
foldermanager_QueryInterface(
3762 IKnownFolderManager
*iface
,
3766 struct foldermanager
*This
= impl_from_IKnownFolderManager( iface
);
3768 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3770 if ( IsEqualGUID( riid
, &IID_IKnownFolderManager
) ||
3771 IsEqualGUID( riid
, &IID_IUnknown
) )
3777 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3778 return E_NOINTERFACE
;
3780 IKnownFolderManager_AddRef( iface
);
3784 static HRESULT WINAPI
foldermanager_FolderIdFromCsidl(
3785 IKnownFolderManager
*iface
,
3787 KNOWNFOLDERID
*pfid
)
3789 TRACE("%d, %p\n", nCsidl
, pfid
);
3791 if (nCsidl
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
3792 return E_INVALIDARG
;
3793 *pfid
= *CSIDL_Data
[nCsidl
].id
;
3797 static HRESULT WINAPI
foldermanager_FolderIdToCsidl(
3798 IKnownFolderManager
*iface
,
3799 REFKNOWNFOLDERID rfid
,
3804 TRACE("%s, %p\n", debugstr_guid(rfid
), pnCsidl
);
3806 csidl
= csidl_from_id( rfid
);
3807 if (csidl
== -1) return E_INVALIDARG
;
3812 static HRESULT WINAPI
foldermanager_GetFolderIds(
3813 IKnownFolderManager
*iface
,
3814 KNOWNFOLDERID
**ppKFId
,
3817 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
3819 TRACE("%p, %p\n", ppKFId
, pCount
);
3822 *pCount
= fm
->num_ids
;
3826 static BOOL
is_knownfolder( struct foldermanager
*fm
, const KNOWNFOLDERID
*id
)
3830 LPWSTR registryPath
= NULL
;
3833 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
3834 for (i
= 0; i
< fm
->num_ids
; i
++)
3835 if (IsEqualGUID( &fm
->ids
[i
], id
)) return TRUE
;
3837 hr
= get_known_folder_registry_path(id
, NULL
, ®istryPath
);
3840 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, 0, &hKey
));
3841 HeapFree(GetProcessHeap(), 0, registryPath
);
3853 static HRESULT WINAPI
foldermanager_GetFolder(
3854 IKnownFolderManager
*iface
,
3855 REFKNOWNFOLDERID rfid
,
3856 IKnownFolder
**ppkf
)
3858 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
3859 struct knownfolder
*kf
;
3862 TRACE("%s, %p\n", debugstr_guid(rfid
), ppkf
);
3864 if (!is_knownfolder( fm
, rfid
))
3866 WARN("unknown folder\n");
3867 return E_INVALIDARG
;
3869 hr
= knownfolder_create( &kf
);
3870 if (SUCCEEDED( hr
))
3872 hr
= knownfolder_set_id( kf
, rfid
);
3873 *ppkf
= &kf
->IKnownFolder_iface
;
3881 static HRESULT WINAPI
foldermanager_GetFolderByName(
3882 IKnownFolderManager
*iface
,
3883 LPCWSTR pszCanonicalName
,
3884 IKnownFolder
**ppkf
)
3886 FIXME("%s, %p\n", debugstr_w(pszCanonicalName
), ppkf
);
3890 static HRESULT WINAPI
foldermanager_RegisterFolder(
3891 IKnownFolderManager
*iface
,
3892 REFKNOWNFOLDERID rfid
,
3893 KNOWNFOLDER_DEFINITION
const *pKFD
)
3898 LPWSTR registryPath
= NULL
;
3899 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(rfid
), pKFD
);
3901 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
3902 TRACE("registry path: %s\n", debugstr_w(registryPath
));
3905 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, NULL
, 0, KEY_WRITE
, 0, &hKey
, &dwDisp
));
3909 if(dwDisp
== REG_OPENED_EXISTING_KEY
)
3913 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szCategory
, 0, REG_DWORD
, (LPBYTE
)&pKFD
->category
, sizeof(pKFD
->category
)));
3916 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szName
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszName
, (lstrlenW(pKFD
->pszName
)+1)*sizeof(WCHAR
) ));
3918 if(SUCCEEDED(hr
) && !IsEqualGUID(&pKFD
->fidParent
, &GUID_NULL
))
3920 WCHAR sParentGuid
[39];
3921 StringFromGUID2(&pKFD
->fidParent
, sParentGuid
, sizeof(sParentGuid
)/sizeof(sParentGuid
[0]));
3923 /* this known folder has parent folder */
3924 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szParentFolder
, 0, REG_SZ
, (LPBYTE
)sParentGuid
, sizeof(sParentGuid
)));
3927 if(SUCCEEDED(hr
) && pKFD
->category
!= KF_CATEGORY_VIRTUAL
)
3929 if(!pKFD
->pszRelativePath
)
3933 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szRelativePath
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszRelativePath
, (lstrlenW(pKFD
->pszRelativePath
)+1)*sizeof(WCHAR
) ));
3939 SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
);
3942 HeapFree(GetProcessHeap(), 0, registryPath
);
3946 static HRESULT WINAPI
foldermanager_UnregisterFolder(
3947 IKnownFolderManager
*iface
,
3948 REFKNOWNFOLDERID rfid
)
3951 LPWSTR registryPath
= NULL
;
3952 TRACE("(%p, %s)\n", iface
, debugstr_guid(rfid
));
3954 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
3957 hr
= HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
));
3959 HeapFree(GetProcessHeap(), 0, registryPath
);
3963 static HRESULT WINAPI
foldermanager_FindFolderFromPath(
3964 IKnownFolderManager
*iface
,
3967 IKnownFolder
**ppkf
)
3969 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath
), mode
, ppkf
);
3973 static HRESULT WINAPI
foldermanager_FindFolderFromIDList(
3974 IKnownFolderManager
*iface
,
3975 PCIDLIST_ABSOLUTE pidl
,
3976 IKnownFolder
**ppkf
)
3978 FIXME("%p, %p\n", pidl
, ppkf
);
3982 static HRESULT WINAPI
foldermanager_Redirect(
3983 IKnownFolderManager
*iface
,
3984 REFKNOWNFOLDERID rfid
,
3986 KF_REDIRECT_FLAGS flags
,
3987 LPCWSTR pszTargetPath
,
3989 KNOWNFOLDERID
const *pExclusion
,
3992 return redirect_known_folder(rfid
, hwnd
, flags
, pszTargetPath
, cFolders
, pExclusion
, ppszError
);
3995 static const struct IKnownFolderManagerVtbl foldermanager_vtbl
=
3997 foldermanager_QueryInterface
,
3998 foldermanager_AddRef
,
3999 foldermanager_Release
,
4000 foldermanager_FolderIdFromCsidl
,
4001 foldermanager_FolderIdToCsidl
,
4002 foldermanager_GetFolderIds
,
4003 foldermanager_GetFolder
,
4004 foldermanager_GetFolderByName
,
4005 foldermanager_RegisterFolder
,
4006 foldermanager_UnregisterFolder
,
4007 foldermanager_FindFolderFromPath
,
4008 foldermanager_FindFolderFromIDList
,
4009 foldermanager_Redirect
4012 static HRESULT
foldermanager_create( void **ppv
)
4015 struct foldermanager
*fm
;
4017 fm
= HeapAlloc( GetProcessHeap(), 0, sizeof(*fm
) );
4018 if (!fm
) return E_OUTOFMEMORY
;
4020 fm
->IKnownFolderManager_iface
.lpVtbl
= &foldermanager_vtbl
;
4024 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
4026 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
)) fm
->num_ids
++;
4028 fm
->ids
= HeapAlloc( GetProcessHeap(), 0, fm
->num_ids
* sizeof(KNOWNFOLDERID
) );
4031 HeapFree( GetProcessHeap(), 0, fm
);
4032 return E_OUTOFMEMORY
;
4034 for (i
= j
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
4036 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
))
4038 fm
->ids
[j
] = *CSIDL_Data
[i
].id
;
4042 TRACE("found %u known folders\n", fm
->num_ids
);
4043 *ppv
= &fm
->IKnownFolderManager_iface
;
4045 TRACE("returning iface %p\n", *ppv
);
4049 HRESULT WINAPI
KnownFolderManager_Constructor( IUnknown
*punk
, REFIID riid
, void **ppv
)
4051 TRACE("%p, %s, %p\n", punk
, debugstr_guid(riid
), ppv
);
4056 return CLASS_E_NOAGGREGATION
;
4058 return foldermanager_create( ppv
);
4061 HRESULT WINAPI
SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PIDLIST_ABSOLUTE
*pidl
)
4063 FIXME("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid
), flags
, token
, pidl
);