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_DocumentsW
[] = {'M','y',' ','D','o','c','u','m','e','n','t','s','\0'};
814 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
815 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
816 static const WCHAR My_VideosW
[] = {'M','y',' ','V','i','d','e','o','s','\0'};
817 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
818 static const WCHAR OEM_LinksW
[] = {'O','E','M',' ','L','i','n','k','s','\0'};
819 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
820 static const WCHAR PicturesW
[] = {'P','i','c','t','u','r','e','s','\0'};
821 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'};
822 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'};
823 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
824 static const WCHAR Program_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\0'};
825 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'};
826 static const WCHAR Program_Files_x86W
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\0'};
827 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'};
828 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
829 static const WCHAR ProgramFilesDirX86W
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
830 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
831 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
832 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
833 static const WCHAR Saved_GamesW
[] = {'S','a','v','e','d',' ','G','a','m','e','s','\0'};
834 static const WCHAR SearchesW
[] = {'S','e','a','r','c','h','e','s','\0'};
835 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
836 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
837 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
838 static const WCHAR Start_Menu_ProgramsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\0'};
839 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'};
840 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'};
841 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
842 static const WCHAR UsersW
[] = {'U','s','e','r','s','\0'};
843 static const WCHAR UsersPublicW
[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
844 static const WCHAR VideosW
[] = {'V','i','d','e','o','s','\0'};
845 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'};
846 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
847 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
848 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
849 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
850 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};
851 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
852 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
853 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'};
854 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'};
855 static const WCHAR szDefaultProfileDirW
[] = {'u','s','e','r','s',0};
856 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'};
857 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};
858 static const WCHAR AllUsersW
[] = {'P','u','b','l','i','c',0};
860 typedef enum _CSIDL_Type
{
864 CSIDL_Type_Disallowed
,
865 CSIDL_Type_NonExistent
,
866 CSIDL_Type_WindowsPath
,
867 CSIDL_Type_SystemPath
,
868 CSIDL_Type_SystemX86Path
,
871 #define CSIDL_CONTACTS 0x0043
872 #define CSIDL_DOWNLOADS 0x0047
873 #define CSIDL_LINKS 0x004d
874 #define CSIDL_APPDATA_LOCALLOW 0x004e
875 #define CSIDL_SAVED_GAMES 0x0062
876 #define CSIDL_SEARCHES 0x0063
880 const KNOWNFOLDERID
*id
;
883 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
886 static const CSIDL_DATA CSIDL_Data
[] =
888 { /* 0x00 - CSIDL_DESKTOP */
892 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
894 { /* 0x01 - CSIDL_INTERNET */
895 &FOLDERID_InternetFolder
,
896 CSIDL_Type_Disallowed
,
900 { /* 0x02 - CSIDL_PROGRAMS */
906 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
907 &FOLDERID_ControlPanelFolder
,
908 CSIDL_Type_SystemPath
,
912 { /* 0x04 - CSIDL_PRINTERS */
913 &FOLDERID_PrintersFolder
,
914 CSIDL_Type_SystemPath
,
918 { /* 0x05 - CSIDL_PERSONAL */
922 MAKEINTRESOURCEW(IDS_PERSONAL
)
924 { /* 0x06 - CSIDL_FAVORITES */
930 { /* 0x07 - CSIDL_STARTUP */
936 { /* 0x08 - CSIDL_RECENT */
942 { /* 0x09 - CSIDL_SENDTO */
948 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
949 &FOLDERID_RecycleBinFolder
,
950 CSIDL_Type_Disallowed
,
954 { /* 0x0b - CSIDL_STARTMENU */
960 { /* 0x0c - CSIDL_MYDOCUMENTS */
962 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
966 { /* 0x0d - CSIDL_MYMUSIC */
970 MAKEINTRESOURCEW(IDS_MYMUSIC
)
972 { /* 0x0e - CSIDL_MYVIDEO */
976 MAKEINTRESOURCEW(IDS_MYVIDEOS
)
978 { /* 0x0f - unassigned */
980 CSIDL_Type_Disallowed
,
984 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
988 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
990 { /* 0x11 - CSIDL_DRIVES */
991 &FOLDERID_ComputerFolder
,
992 CSIDL_Type_Disallowed
,
996 { /* 0x12 - CSIDL_NETWORK */
997 &FOLDERID_NetworkFolder
,
998 CSIDL_Type_Disallowed
,
1002 { /* 0x13 - CSIDL_NETHOOD */
1008 { /* 0x14 - CSIDL_FONTS */
1010 CSIDL_Type_WindowsPath
,
1014 { /* 0x15 - CSIDL_TEMPLATES */
1015 &FOLDERID_Templates
,
1020 { /* 0x16 - CSIDL_COMMON_STARTMENU */
1021 &FOLDERID_CommonStartMenu
,
1022 CSIDL_Type_AllUsers
,
1026 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
1027 &FOLDERID_CommonPrograms
,
1028 CSIDL_Type_AllUsers
,
1030 Start_Menu_ProgramsW
1032 { /* 0x18 - CSIDL_COMMON_STARTUP */
1033 &FOLDERID_CommonStartup
,
1034 CSIDL_Type_AllUsers
,
1038 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
1039 &FOLDERID_PublicDesktop
,
1040 CSIDL_Type_AllUsers
,
1042 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
1044 { /* 0x1a - CSIDL_APPDATA */
1045 &FOLDERID_RoamingAppData
,
1050 { /* 0x1b - CSIDL_PRINTHOOD */
1051 &FOLDERID_PrintHood
,
1056 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1057 &FOLDERID_LocalAppData
,
1060 Local_Settings_Application_DataW
1062 { /* 0x1d - CSIDL_ALTSTARTUP */
1064 CSIDL_Type_NonExistent
,
1068 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1070 CSIDL_Type_NonExistent
,
1074 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1075 &FOLDERID_Favorites
,
1076 CSIDL_Type_AllUsers
,
1080 { /* 0x20 - CSIDL_INTERNET_CACHE */
1081 &FOLDERID_InternetCache
,
1084 Local_Settings_Temporary_Internet_FilesW
1086 { /* 0x21 - CSIDL_COOKIES */
1092 { /* 0x22 - CSIDL_HISTORY */
1096 Local_Settings_HistoryW
1098 { /* 0x23 - CSIDL_COMMON_APPDATA */
1099 &FOLDERID_ProgramData
,
1100 CSIDL_Type_AllUsers
,
1104 { /* 0x24 - CSIDL_WINDOWS */
1106 CSIDL_Type_WindowsPath
,
1110 { /* 0x25 - CSIDL_SYSTEM */
1112 CSIDL_Type_SystemPath
,
1116 { /* 0x26 - CSIDL_PROGRAM_FILES */
1117 &FOLDERID_ProgramFiles
,
1122 { /* 0x27 - CSIDL_MYPICTURES */
1126 MAKEINTRESOURCEW(IDS_MYPICTURES
)
1128 { /* 0x28 - CSIDL_PROFILE */
1134 { /* 0x29 - CSIDL_SYSTEMX86 */
1135 &FOLDERID_SystemX86
,
1136 CSIDL_Type_SystemX86Path
,
1140 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1141 &FOLDERID_ProgramFilesX86
,
1143 ProgramFilesDirX86W
,
1146 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1147 &FOLDERID_ProgramFilesCommon
,
1150 Program_Files_Common_FilesW
1152 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1153 &FOLDERID_ProgramFilesCommonX86
,
1156 Program_Files_x86_Common_FilesW
1158 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1159 &FOLDERID_CommonTemplates
,
1160 CSIDL_Type_AllUsers
,
1164 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1165 &FOLDERID_PublicDocuments
,
1166 CSIDL_Type_AllUsers
,
1170 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1171 &FOLDERID_CommonAdminTools
,
1172 CSIDL_Type_AllUsers
,
1173 Common_Administrative_ToolsW
,
1174 Start_Menu_Admin_ToolsW
1176 { /* 0x30 - CSIDL_ADMINTOOLS */
1177 &FOLDERID_AdminTools
,
1179 Administrative_ToolsW
,
1180 Start_Menu_Admin_ToolsW
1182 { /* 0x31 - CSIDL_CONNECTIONS */
1183 &FOLDERID_ConnectionsFolder
,
1184 CSIDL_Type_Disallowed
,
1188 { /* 0x32 - unassigned */
1190 CSIDL_Type_Disallowed
,
1194 { /* 0x33 - unassigned */
1196 CSIDL_Type_Disallowed
,
1200 { /* 0x34 - unassigned */
1202 CSIDL_Type_Disallowed
,
1206 { /* 0x35 - CSIDL_COMMON_MUSIC */
1207 &FOLDERID_PublicMusic
,
1208 CSIDL_Type_AllUsers
,
1212 { /* 0x36 - CSIDL_COMMON_PICTURES */
1213 &FOLDERID_PublicPictures
,
1214 CSIDL_Type_AllUsers
,
1218 { /* 0x37 - CSIDL_COMMON_VIDEO */
1219 &FOLDERID_PublicVideos
,
1220 CSIDL_Type_AllUsers
,
1224 { /* 0x38 - CSIDL_RESOURCES */
1225 &FOLDERID_ResourceDir
,
1226 CSIDL_Type_WindowsPath
,
1230 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1231 &FOLDERID_LocalizedResourcesDir
,
1232 CSIDL_Type_NonExistent
,
1236 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1237 &FOLDERID_CommonOEMLinks
,
1238 CSIDL_Type_AllUsers
,
1242 { /* 0x3b - CSIDL_CDBURN_AREA */
1243 &FOLDERID_CDBurning
,
1246 Local_Settings_CD_BurningW
1248 { /* 0x3c unassigned */
1250 CSIDL_Type_Disallowed
,
1254 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1256 CSIDL_Type_Disallowed
, /* FIXME */
1260 { /* 0x3e - CSIDL_PROFILES */
1262 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1267 &FOLDERID_AddNewPrograms
,
1268 CSIDL_Type_Disallowed
,
1273 &FOLDERID_AppUpdates
,
1274 CSIDL_Type_Disallowed
,
1279 &FOLDERID_ChangeRemovePrograms
,
1280 CSIDL_Type_Disallowed
,
1285 &FOLDERID_ConflictFolder
,
1286 CSIDL_Type_Disallowed
,
1290 { /* 0x43 - CSIDL_CONTACTS */
1297 &FOLDERID_DeviceMetadataStore
,
1298 CSIDL_Type_Disallowed
, /* FIXME */
1309 &FOLDERID_DocumentsLibrary
,
1310 CSIDL_Type_Disallowed
, /* FIXME */
1314 { /* 0x47 - CSIDL_DOWNLOADS */
1315 &FOLDERID_Downloads
,
1322 CSIDL_Type_Disallowed
,
1327 &FOLDERID_GameTasks
,
1328 CSIDL_Type_Disallowed
, /* FIXME */
1333 &FOLDERID_HomeGroup
,
1334 CSIDL_Type_Disallowed
,
1339 &FOLDERID_ImplicitAppShortcuts
,
1340 CSIDL_Type_Disallowed
, /* FIXME */
1345 &FOLDERID_Libraries
,
1346 CSIDL_Type_Disallowed
, /* FIXME */
1350 { /* 0x4d - CSIDL_LINKS */
1356 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
1357 &FOLDERID_LocalAppDataLow
,
1363 &FOLDERID_MusicLibrary
,
1364 CSIDL_Type_Disallowed
, /* FIXME */
1369 &FOLDERID_OriginalImages
,
1370 CSIDL_Type_Disallowed
, /* FIXME */
1375 &FOLDERID_PhotoAlbums
,
1378 Pictures_Slide_ShowsW
1381 &FOLDERID_PicturesLibrary
,
1382 CSIDL_Type_Disallowed
, /* FIXME */
1387 &FOLDERID_Playlists
,
1393 &FOLDERID_ProgramFilesX64
,
1394 CSIDL_Type_NonExistent
,
1399 &FOLDERID_ProgramFilesCommonX64
,
1400 CSIDL_Type_NonExistent
,
1406 CSIDL_Type_CurrVer
, /* FIXME */
1411 &FOLDERID_PublicDownloads
,
1412 CSIDL_Type_AllUsers
,
1417 &FOLDERID_PublicGameTasks
,
1418 CSIDL_Type_AllUsers
,
1420 Microsoft_Windows_GameExplorerW
1423 &FOLDERID_PublicLibraries
,
1424 CSIDL_Type_AllUsers
,
1426 Microsoft_Windows_LibrariesW
1429 &FOLDERID_PublicRingtones
,
1430 CSIDL_Type_AllUsers
,
1432 Microsoft_Windows_RingtonesW
1435 &FOLDERID_QuickLaunch
,
1436 CSIDL_Type_Disallowed
, /* FIXME */
1441 &FOLDERID_RecordedTVLibrary
,
1442 CSIDL_Type_Disallowed
, /* FIXME */
1447 &FOLDERID_Ringtones
,
1448 CSIDL_Type_Disallowed
, /* FIXME */
1453 &FOLDERID_SampleMusic
,
1454 CSIDL_Type_AllUsers
,
1459 &FOLDERID_SamplePictures
,
1460 CSIDL_Type_AllUsers
,
1462 Pictures_Sample_PicturesW
1465 &FOLDERID_SamplePlaylists
,
1466 CSIDL_Type_AllUsers
,
1468 Music_Sample_PlaylistsW
1471 &FOLDERID_SampleVideos
,
1472 CSIDL_Type_AllUsers
,
1474 Videos_Sample_VideosW
1476 { /* 0x62 - CSIDL_SAVED_GAMES */
1477 &FOLDERID_SavedGames
,
1482 { /* 0x63 - CSIDL_SEARCHES */
1483 &FOLDERID_SavedSearches
,
1489 &FOLDERID_SEARCH_CSC
,
1490 CSIDL_Type_Disallowed
,
1495 &FOLDERID_SEARCH_MAPI
,
1496 CSIDL_Type_Disallowed
,
1501 &FOLDERID_SearchHome
,
1502 CSIDL_Type_Disallowed
,
1507 &FOLDERID_SidebarDefaultParts
,
1508 CSIDL_Type_Disallowed
, /* FIXME */
1513 &FOLDERID_SidebarParts
,
1514 CSIDL_Type_Disallowed
, /* FIXME */
1519 &FOLDERID_SyncManagerFolder
,
1520 CSIDL_Type_Disallowed
,
1525 &FOLDERID_SyncResultsFolder
,
1526 CSIDL_Type_Disallowed
,
1531 &FOLDERID_SyncSetupFolder
,
1532 CSIDL_Type_Disallowed
,
1537 &FOLDERID_UserPinned
,
1538 CSIDL_Type_Disallowed
, /* FIXME */
1543 &FOLDERID_UserProfiles
,
1549 &FOLDERID_UserProgramFiles
,
1550 CSIDL_Type_Disallowed
, /* FIXME */
1555 &FOLDERID_UserProgramFilesCommon
,
1556 CSIDL_Type_Disallowed
, /* FIXME */
1561 &FOLDERID_UsersFiles
,
1562 CSIDL_Type_Disallowed
,
1567 &FOLDERID_UsersLibraries
,
1568 CSIDL_Type_Disallowed
,
1573 &FOLDERID_VideosLibrary
,
1574 CSIDL_Type_Disallowed
, /* FIXME */
1580 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1582 /* Gets the value named value from the registry key
1583 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1584 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1585 * is assumed to be MAX_PATH WCHARs in length.
1586 * If it exists, expands the value and writes the expanded value to
1587 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1588 * Returns successful error code if the value was retrieved from the registry,
1589 * and a failure otherwise.
1591 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1592 LPCWSTR value
, LPWSTR path
)
1595 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1596 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1597 DWORD dwType
, dwPathLen
= MAX_PATH
;
1598 HKEY userShellFolderKey
, shellFolderKey
;
1600 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1605 strcpyW(shellFolderPath
, userPrefix
);
1606 PathAddBackslashW(shellFolderPath
);
1607 strcatW(shellFolderPath
, szSHFolders
);
1608 pShellFolderPath
= shellFolderPath
;
1609 strcpyW(userShellFolderPath
, userPrefix
);
1610 PathAddBackslashW(userShellFolderPath
);
1611 strcatW(userShellFolderPath
, szSHUserFolders
);
1612 pUserShellFolderPath
= userShellFolderPath
;
1616 pUserShellFolderPath
= szSHUserFolders
;
1617 pShellFolderPath
= szSHFolders
;
1620 if (RegCreateKeyW(rootKey
, pShellFolderPath
, &shellFolderKey
))
1622 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1625 if (RegCreateKeyW(rootKey
, pUserShellFolderPath
, &userShellFolderKey
))
1627 TRACE("Failed to create %s\n",
1628 debugstr_w(pUserShellFolderPath
));
1629 RegCloseKey(shellFolderKey
);
1633 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1634 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1638 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1639 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1641 WCHAR szTemp
[MAX_PATH
];
1643 _SHExpandEnvironmentStrings(path
, szTemp
);
1644 lstrcpynW(path
, szTemp
, MAX_PATH
);
1646 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1647 (strlenW(path
) + 1) * sizeof(WCHAR
));
1648 if (ret
!= ERROR_SUCCESS
)
1649 hr
= HRESULT_FROM_WIN32(ret
);
1655 RegCloseKey(shellFolderKey
);
1656 RegCloseKey(userShellFolderKey
);
1657 TRACE("returning 0x%08x\n", hr
);
1661 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1662 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1663 * - The entry's szDefaultPath may be either a string value or an integer
1664 * resource identifier. In the latter case, the string value of the resource
1666 * - Depending on the entry's type, the path may begin with an (unexpanded)
1667 * environment variable name. The caller is responsible for expanding
1668 * environment strings if so desired.
1669 * The types that are prepended with environment variables are:
1670 * CSIDL_Type_User: %USERPROFILE%
1671 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1672 * CSIDL_Type_CurrVer: %SystemDrive%
1673 * (Others might make sense too, but as yet are unneeded.)
1675 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1678 WCHAR resourcePath
[MAX_PATH
];
1679 LPCWSTR pDefaultPath
= NULL
;
1681 TRACE("0x%02x,%p\n", folder
, pszPath
);
1683 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1684 return E_INVALIDARG
;
1686 return E_INVALIDARG
;
1694 case CSIDL_PROGRAM_FILES
:
1695 case CSIDL_PROGRAM_FILESX86
:
1696 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1697 folder
= is_wow64
? CSIDL_PROGRAM_FILESX86
: CSIDL_PROGRAM_FILES
;
1699 case CSIDL_PROGRAM_FILES_COMMON
:
1700 case CSIDL_PROGRAM_FILES_COMMONX86
:
1701 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1702 folder
= is_wow64
? CSIDL_PROGRAM_FILES_COMMONX86
: CSIDL_PROGRAM_FILES_COMMON
;
1707 if (CSIDL_Data
[folder
].szDefaultPath
&&
1708 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1710 if (LoadStringW(shell32_hInstance
,
1711 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1714 pDefaultPath
= resourcePath
;
1718 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1719 debugstr_w(pszPath
));
1726 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1730 switch (CSIDL_Data
[folder
].type
)
1732 case CSIDL_Type_User
:
1733 strcpyW(pszPath
, UserProfileW
);
1735 case CSIDL_Type_AllUsers
:
1736 strcpyW(pszPath
, AllUsersProfileW
);
1738 case CSIDL_Type_CurrVer
:
1739 strcpyW(pszPath
, SystemDriveW
);
1742 ; /* no corresponding env. var, do nothing */
1746 PathAddBackslashW(pszPath
);
1747 strcatW(pszPath
, pDefaultPath
);
1750 TRACE("returning 0x%08x\n", hr
);
1754 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1755 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1756 * can be overridden in the HKLM\\szCurrentVersion key.
1757 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1758 * the registry, uses _SHGetDefaultValue to get the value.
1760 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1765 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1767 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1768 return E_INVALIDARG
;
1769 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1770 return E_INVALIDARG
;
1772 return E_INVALIDARG
;
1774 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1775 hr
= _SHGetDefaultValue(folder
, pszPath
);
1780 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hKey
))
1784 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1786 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1787 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1788 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1790 hr
= _SHGetDefaultValue(folder
, pszPath
);
1791 dwType
= REG_EXPAND_SZ
;
1794 case CSIDL_PROGRAM_FILESX86
:
1795 case CSIDL_PROGRAM_FILES_COMMONX86
:
1796 /* these two should never be set on 32-bit setups */
1800 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1801 if (!is_wow64
) break;
1805 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1806 (LPBYTE
)pszPath
, (strlenW(pszPath
)+1)*sizeof(WCHAR
));
1811 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1817 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1821 static LPWSTR
_GetUserSidStringFromToken(HANDLE Token
)
1823 char InfoBuffer
[64];
1824 PTOKEN_USER UserInfo
;
1828 UserInfo
= (PTOKEN_USER
) InfoBuffer
;
1829 if (! GetTokenInformation(Token
, TokenUser
, InfoBuffer
, sizeof(InfoBuffer
),
1832 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1834 UserInfo
= HeapAlloc(GetProcessHeap(), 0, InfoSize
);
1835 if (UserInfo
== NULL
)
1837 if (! GetTokenInformation(Token
, TokenUser
, UserInfo
, InfoSize
,
1840 HeapFree(GetProcessHeap(), 0, UserInfo
);
1845 if (! ConvertSidToStringSidW(UserInfo
->User
.Sid
, &SidStr
))
1848 if (UserInfo
!= (PTOKEN_USER
) InfoBuffer
)
1849 HeapFree(GetProcessHeap(), 0, UserInfo
);
1854 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1855 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1856 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1857 * - if hToken is -1, looks in HKEY_USERS\.Default
1858 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1859 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1860 * calls _SHGetDefaultValue for it.
1862 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1865 const WCHAR
*szValueName
;
1869 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1871 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1872 return E_INVALIDARG
;
1873 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1874 return E_INVALIDARG
;
1876 return E_INVALIDARG
;
1878 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1880 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
1882 FIXME("unsupported for user other than current or default\n");
1885 hr
= _SHGetDefaultValue(folder
, pszPath
);
1889 LPCWSTR userPrefix
= NULL
;
1892 if (hToken
== (HANDLE
)-1)
1894 hRootKey
= HKEY_USERS
;
1895 userPrefix
= DefaultW
;
1897 else if (hToken
== NULL
)
1898 hRootKey
= HKEY_CURRENT_USER
;
1901 hRootKey
= HKEY_USERS
;
1902 userPrefix
= _GetUserSidStringFromToken(hToken
);
1903 if (userPrefix
== NULL
)
1910 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
1911 szValueName
= CSIDL_Data
[folder
].szValueName
;
1914 StringFromGUID2( CSIDL_Data
[folder
].id
, buffer
, 39 );
1915 szValueName
= &buffer
[0];
1918 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, szValueName
, pszPath
);
1919 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1920 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, szValueName
, pszPath
);
1922 hr
= _SHGetDefaultValue(folder
, pszPath
);
1923 if (userPrefix
!= NULL
&& userPrefix
!= DefaultW
)
1924 LocalFree((HLOCAL
) userPrefix
);
1927 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1931 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1932 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1933 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1934 * If this fails, falls back to _SHGetDefaultValue.
1936 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1941 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1943 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1944 return E_INVALIDARG
;
1945 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1946 return E_INVALIDARG
;
1948 return E_INVALIDARG
;
1950 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1951 hr
= _SHGetDefaultValue(folder
, pszPath
);
1954 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1955 CSIDL_Data
[folder
].szValueName
, pszPath
);
1957 hr
= _SHGetDefaultValue(folder
, pszPath
);
1959 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1963 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
1968 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, NULL
, 0,
1969 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
1970 return HRESULT_FROM_WIN32(lRet
);
1973 /* Reads the value named szValueName from the key profilesKey (assumed to be
1974 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1975 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1976 * szDefault to the registry).
1978 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
1979 LPWSTR szValue
, LPCWSTR szDefault
)
1982 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1985 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
1986 debugstr_w(szDefault
));
1987 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
1988 (LPBYTE
)szValue
, &dwPathLen
);
1989 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
1992 dwPathLen
/= sizeof(WCHAR
);
1993 szValue
[dwPathLen
] = '\0';
1998 /* Missing or invalid value, set a default */
1999 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
2000 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
2001 debugstr_w(szValue
));
2002 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
2004 (strlenW(szValue
) + 1) * sizeof(WCHAR
));
2006 hr
= HRESULT_FROM_WIN32(lRet
);
2010 TRACE("returning 0x%08x (output value is %s)\n", hr
, debugstr_w(szValue
));
2014 /* Attempts to expand environment variables from szSrc into szDest, which is
2015 * assumed to be MAX_PATH characters in length. Before referring to the
2016 * environment, handles a few variables directly, because the environment
2017 * variables may not be set when this is called (as during Wine's installation
2018 * when default values are being written to the registry).
2019 * The directly handled environment variables, and their source, are:
2020 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
2021 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
2023 * If one of the directly handled environment variables is expanded, only
2024 * expands a single variable, and only in the beginning of szSrc.
2026 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
2029 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
2032 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
2034 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
2036 /* short-circuit if there's nothing to expand */
2037 if (szSrc
[0] != '%')
2039 strcpyW(szDest
, szSrc
);
2043 /* Get the profile prefix, we'll probably be needing it */
2044 hr
= _SHOpenProfilesKey(&key
);
2047 WCHAR def_val
[MAX_PATH
];
2049 /* get the system drive */
2050 GetSystemDirectoryW(def_val
, MAX_PATH
);
2051 if (def_val
[1] == ':') strcpyW( def_val
+ 3, szDefaultProfileDirW
);
2052 else FIXME("non-drive system paths unsupported\n");
2054 hr
= _SHGetProfilesValue(key
, ProfilesDirectoryW
, szProfilesPrefix
, def_val
);
2058 strcpyW(szTemp
, szSrc
);
2059 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
2061 if (!strncmpiW(szTemp
, AllUsersProfileW
, strlenW(AllUsersProfileW
)))
2063 WCHAR szAllUsers
[MAX_PATH
];
2065 strcpyW(szDest
, szProfilesPrefix
);
2066 hr
= _SHGetProfilesValue(key
, AllUsersProfileValueW
,
2067 szAllUsers
, AllUsersW
);
2068 PathAppendW(szDest
, szAllUsers
);
2069 PathAppendW(szDest
, szTemp
+ strlenW(AllUsersProfileW
));
2071 else if (!strncmpiW(szTemp
, UserProfileW
, strlenW(UserProfileW
)))
2073 WCHAR userName
[MAX_PATH
];
2074 DWORD userLen
= MAX_PATH
;
2076 strcpyW(szDest
, szProfilesPrefix
);
2077 GetUserNameW(userName
, &userLen
);
2078 PathAppendW(szDest
, userName
);
2079 PathAppendW(szDest
, szTemp
+ strlenW(UserProfileW
));
2081 else if (!strncmpiW(szTemp
, SystemDriveW
, strlenW(SystemDriveW
)))
2083 GetSystemDirectoryW(szDest
, MAX_PATH
);
2084 if (szDest
[1] != ':')
2086 FIXME("non-drive system paths unsupported\n");
2091 strcpyW(szDest
+ 3, szTemp
+ strlenW(SystemDriveW
) + 1);
2097 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
2100 hr
= E_NOT_SUFFICIENT_BUFFER
;
2102 hr
= HRESULT_FROM_WIN32(GetLastError());
2106 if (SUCCEEDED(hr
) && szDest
[0] == '%')
2107 strcpyW(szTemp
, szDest
);
2110 /* terminate loop */
2117 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr
,
2118 debugstr_w(szSrc
), debugstr_w(szDest
));
2122 /*************************************************************************
2123 * SHGetFolderPathW [SHELL32.@]
2125 * Convert nFolder to path.
2129 * Failure: standard HRESULT error codes.
2132 * Most values can be overridden in either
2133 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
2134 * or in the same location in HKLM.
2135 * The "Shell Folders" registry key was used in NT4 and earlier systems.
2136 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
2137 * changes made to it are made to the former key too. This synchronization is
2138 * done on-demand: not until someone requests the value of one of these paths
2139 * (by calling one of the SHGet functions) is the value synchronized.
2140 * Furthermore, the HKCU paths take precedence over the HKLM paths.
2142 HRESULT WINAPI
SHGetFolderPathW(
2143 HWND hwndOwner
, /* [I] owner window */
2144 int nFolder
, /* [I] CSIDL identifying the folder */
2145 HANDLE hToken
, /* [I] access token */
2146 DWORD dwFlags
, /* [I] which path to return */
2147 LPWSTR pszPath
) /* [O] converted path */
2149 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
2150 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
2151 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
2155 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
2156 HWND hwndOwner
, /* [I] owner window */
2157 int nFolder
, /* [I] CSIDL identifying the folder */
2158 HANDLE hToken
, /* [I] access token */
2159 DWORD dwFlags
, /* [I] which path to return */
2160 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
2161 LPSTR pszPath
) /* [O] converted path */
2165 LPWSTR pszSubPathW
= NULL
;
2166 LPWSTR pszPathW
= NULL
;
2167 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2170 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
2172 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2176 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2178 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
2179 * set (null), or an empty string.therefore call it without the parameter set
2180 * if pszSubPath is an empty string
2182 if (pszSubPath
&& pszSubPath
[0]) {
2183 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
2184 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
2186 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2189 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
2192 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
2194 if (SUCCEEDED(hr
) && pszPath
)
2195 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
2198 HeapFree(GetProcessHeap(), 0, pszPathW
);
2199 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
2203 /*************************************************************************
2204 * SHGetFolderPathAndSubDirW [SHELL32.@]
2206 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
2207 HWND hwndOwner
, /* [I] owner window */
2208 int nFolder
, /* [I] CSIDL identifying the folder */
2209 HANDLE hToken
, /* [I] access token */
2210 DWORD dwFlags
, /* [I] which path to return */
2211 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
2212 LPWSTR pszPath
) /* [O] converted path */
2215 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
2216 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2220 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
2222 /* Windows always NULL-terminates the resulting path regardless of success
2223 * or failure, so do so first
2228 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2229 return E_INVALIDARG
;
2230 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
2231 return E_INVALIDARG
;
2233 type
= CSIDL_Data
[folder
].type
;
2236 case CSIDL_Type_Disallowed
:
2239 case CSIDL_Type_NonExistent
:
2242 case CSIDL_Type_WindowsPath
:
2243 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
2244 if (CSIDL_Data
[folder
].szDefaultPath
&&
2245 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2246 *CSIDL_Data
[folder
].szDefaultPath
)
2248 PathAddBackslashW(szTemp
);
2249 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2253 case CSIDL_Type_SystemPath
:
2254 GetSystemDirectoryW(szTemp
, MAX_PATH
);
2255 if (CSIDL_Data
[folder
].szDefaultPath
&&
2256 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2257 *CSIDL_Data
[folder
].szDefaultPath
)
2259 PathAddBackslashW(szTemp
);
2260 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2264 case CSIDL_Type_SystemX86Path
:
2265 if (!GetSystemWow64DirectoryW(szTemp
, MAX_PATH
)) GetSystemDirectoryW(szTemp
, MAX_PATH
);
2266 if (CSIDL_Data
[folder
].szDefaultPath
&&
2267 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2268 *CSIDL_Data
[folder
].szDefaultPath
)
2270 PathAddBackslashW(szTemp
);
2271 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2275 case CSIDL_Type_CurrVer
:
2276 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
2278 case CSIDL_Type_User
:
2279 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
2281 case CSIDL_Type_AllUsers
:
2282 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
2285 FIXME("bogus type %d, please fix\n", type
);
2290 /* Expand environment strings if necessary */
2292 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
2294 strcpyW(szBuildPath
, szTemp
);
2296 if (FAILED(hr
)) goto end
;
2299 /* make sure the new path does not exceed the buffer length
2300 * and remember to backslash and terminate it */
2301 if(MAX_PATH
< (lstrlenW(szBuildPath
) + lstrlenW(pszSubPath
) + 2)) {
2302 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
2305 PathAppendW(szBuildPath
, pszSubPath
);
2306 PathRemoveBackslashW(szBuildPath
);
2308 /* Copy the path if it's available before we might return */
2309 if (SUCCEEDED(hr
) && pszPath
)
2310 strcpyW(pszPath
, szBuildPath
);
2312 /* if we don't care about existing directories we are ready */
2313 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
2315 if (PathFileExistsW(szBuildPath
)) goto end
;
2317 /* not existing but we are not allowed to create it. The return value
2318 * is verified against shell32 version 6.0.
2320 if (!(nFolder
& CSIDL_FLAG_CREATE
))
2322 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2326 /* create directory/directories */
2327 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
2328 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
2330 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
2335 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
2337 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
2341 /*************************************************************************
2342 * SHGetFolderPathA [SHELL32.@]
2344 * See SHGetFolderPathW.
2346 HRESULT WINAPI
SHGetFolderPathA(
2353 WCHAR szTemp
[MAX_PATH
];
2356 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
2360 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
2361 if (SUCCEEDED(hr
) && pszPath
)
2362 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
2368 /* For each folder in folders, if its value has not been set in the registry,
2369 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
2370 * folder's type) to get the unexpanded value first.
2371 * Writes the unexpanded value to User Shell Folders, and queries it with
2372 * SHGetFolderPathW to force the creation of the directory if it doesn't
2373 * already exist. SHGetFolderPathW also returns the expanded value, which
2374 * this then writes to Shell Folders.
2376 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
2377 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
2380 const WCHAR
*szValueName
;
2383 WCHAR path
[MAX_PATH
];
2385 HKEY hUserKey
= NULL
, hKey
= NULL
;
2386 DWORD dwType
, dwPathLen
;
2389 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
2390 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
2392 ret
= RegCreateKeyW(hRootKey
, szUserShellFolderPath
, &hUserKey
);
2394 hr
= HRESULT_FROM_WIN32(ret
);
2397 ret
= RegCreateKeyW(hRootKey
, szShellFolderPath
, &hKey
);
2399 hr
= HRESULT_FROM_WIN32(ret
);
2401 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
2403 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2405 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
2406 szValueName
= CSIDL_Data
[folders
[i
]].szValueName
;
2407 if (!szValueName
&& CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2409 StringFromGUID2( CSIDL_Data
[folders
[i
]].id
, buffer
, 39 );
2410 szValueName
= &buffer
[0];
2413 if (RegQueryValueExW(hUserKey
, szValueName
, NULL
,
2414 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
2415 dwType
!= REG_EXPAND_SZ
))
2418 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2419 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
2421 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
2422 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
2423 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
2425 GetWindowsDirectoryW(path
, MAX_PATH
);
2426 if (CSIDL_Data
[folders
[i
]].szDefaultPath
&&
2427 !IS_INTRESOURCE(CSIDL_Data
[folders
[i
]].szDefaultPath
))
2429 PathAddBackslashW(path
);
2430 strcatW(path
, CSIDL_Data
[folders
[i
]].szDefaultPath
);
2437 ret
= RegSetValueExW(hUserKey
, szValueName
, 0, REG_EXPAND_SZ
,
2438 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2440 hr
= HRESULT_FROM_WIN32(ret
);
2443 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
2444 hToken
, SHGFP_TYPE_DEFAULT
, path
);
2445 ret
= RegSetValueExW(hKey
, szValueName
, 0, REG_SZ
,
2446 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2448 hr
= HRESULT_FROM_WIN32(ret
);
2454 RegCloseKey(hUserKey
);
2458 TRACE("returning 0x%08x\n", hr
);
2462 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
2464 static const UINT folders
[] = {
2475 CSIDL_DESKTOPDIRECTORY
,
2479 CSIDL_LOCAL_APPDATA
,
2480 CSIDL_INTERNET_CACHE
,
2489 CSIDL_APPDATA_LOCALLOW
,
2493 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
2494 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
2499 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
2502 hToken
= (HANDLE
)-1;
2503 hRootKey
= HKEY_USERS
;
2504 strcpyW(userShellFolderPath
, DefaultW
);
2505 PathAddBackslashW(userShellFolderPath
);
2506 strcatW(userShellFolderPath
, szSHUserFolders
);
2507 pUserShellFolderPath
= userShellFolderPath
;
2508 strcpyW(shellFolderPath
, DefaultW
);
2509 PathAddBackslashW(shellFolderPath
);
2510 strcatW(shellFolderPath
, szSHFolders
);
2511 pShellFolderPath
= shellFolderPath
;
2516 hRootKey
= HKEY_CURRENT_USER
;
2517 pUserShellFolderPath
= szSHUserFolders
;
2518 pShellFolderPath
= szSHFolders
;
2521 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
2522 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2523 TRACE("returning 0x%08x\n", hr
);
2527 static HRESULT
_SHRegisterCommonShellFolders(void)
2529 static const UINT folders
[] = {
2530 CSIDL_COMMON_STARTMENU
,
2531 CSIDL_COMMON_PROGRAMS
,
2532 CSIDL_COMMON_STARTUP
,
2533 CSIDL_COMMON_DESKTOPDIRECTORY
,
2534 CSIDL_COMMON_FAVORITES
,
2535 CSIDL_COMMON_APPDATA
,
2536 CSIDL_COMMON_TEMPLATES
,
2537 CSIDL_COMMON_DOCUMENTS
,
2538 CSIDL_COMMON_ADMINTOOLS
,
2540 CSIDL_COMMON_PICTURES
,
2546 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
2547 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2548 TRACE("returning 0x%08x\n", hr
);
2552 /******************************************************************************
2553 * _SHAppendToUnixPath [Internal]
2555 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
2556 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
2557 * and replaces backslashes with slashes.
2560 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
2561 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
2567 static inline BOOL
_SHAppendToUnixPath(char *szBasePath
, LPCWSTR pwszSubPath
) {
2568 WCHAR wszSubPath
[MAX_PATH
];
2569 int cLen
= strlen(szBasePath
);
2572 if (IS_INTRESOURCE(pwszSubPath
)) {
2573 if (!LoadStringW(shell32_hInstance
, LOWORD(pwszSubPath
), wszSubPath
, MAX_PATH
)) {
2574 /* Fall back to hard coded defaults. */
2575 switch (LOWORD(pwszSubPath
)) {
2577 lstrcpyW(wszSubPath
, PersonalW
);
2580 lstrcpyW(wszSubPath
, My_MusicW
);
2582 case IDS_MYPICTURES
:
2583 lstrcpyW(wszSubPath
, My_PicturesW
);
2586 lstrcpyW(wszSubPath
, My_VideosW
);
2589 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath
));
2594 lstrcpyW(wszSubPath
, pwszSubPath
);
2597 if (szBasePath
[cLen
-1] != '/') szBasePath
[cLen
++] = '/';
2599 if (!WideCharToMultiByte(CP_UNIXCP
, 0, wszSubPath
, -1, szBasePath
+ cLen
,
2600 FILENAME_MAX
- cLen
, NULL
, NULL
))
2605 pBackslash
= szBasePath
+ cLen
;
2606 while ((pBackslash
= strchr(pBackslash
, '\\'))) *pBackslash
= '/';
2611 /******************************************************************************
2612 * _SHCreateSymbolicLinks [Internal]
2614 * Sets up symbol links for various shell folders to point into the users home
2615 * directory. We do an educated guess about what the user would probably want:
2616 * - If there is a 'My Documents' directory in $HOME, the user probably wants
2617 * wine's 'My Documents' to point there. Furthermore, we imply that the user
2618 * is a Windows lover and has no problem with wine creating 'My Pictures',
2619 * 'My Music' and 'My Videos' subfolders under '$HOME/My Documents', if those
2620 * do not already exits. We put appropriate symbolic links in place for those,
2622 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2623 * point directly to $HOME. We assume the user to be a unix hacker who does not
2624 * want wine to create anything anywhere besides the .wine directory. So, if
2625 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2626 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
2627 * directory, and try to link to that. If that fails, then we symlink to
2628 * $HOME directly. The same holds fo 'My Pictures' and 'My Videos'.
2629 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
2630 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
2632 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2634 static void _SHCreateSymbolicLinks(void)
2636 UINT aidsMyStuff
[] = { IDS_MYPICTURES
, IDS_MYVIDEOS
, IDS_MYMUSIC
}, i
;
2637 int acsidlMyStuff
[] = { CSIDL_MYPICTURES
, CSIDL_MYVIDEO
, CSIDL_MYMUSIC
};
2638 static const char * const xdg_dirs
[] = { "PICTURES", "VIDEOS", "MUSIC", "DESKTOP" };
2639 static const unsigned int num
= sizeof(xdg_dirs
) / sizeof(xdg_dirs
[0]);
2640 WCHAR wszTempPath
[MAX_PATH
];
2641 char szPersonalTarget
[FILENAME_MAX
], *pszPersonal
;
2642 char szMyStuffTarget
[FILENAME_MAX
], *pszMyStuff
;
2643 char szDesktopTarget
[FILENAME_MAX
], *pszDesktop
;
2644 struct stat statFolder
;
2645 const char *pszHome
;
2647 char ** xdg_results
;
2648 char * xdg_desktop_dir
;
2650 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2651 hr
= SHGetFolderPathW(NULL
, CSIDL_PERSONAL
|CSIDL_FLAG_CREATE
, NULL
,
2652 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2653 if (FAILED(hr
)) return;
2654 pszPersonal
= wine_get_unix_file_name(wszTempPath
);
2655 if (!pszPersonal
) return;
2657 hr
= XDG_UserDirLookup(xdg_dirs
, num
, &xdg_results
);
2658 if (FAILED(hr
)) xdg_results
= NULL
;
2660 pszHome
= getenv("HOME");
2661 if (pszHome
&& !stat(pszHome
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)) {
2662 strcpy(szPersonalTarget
, pszHome
);
2663 if (_SHAppendToUnixPath(szPersonalTarget
, MAKEINTRESOURCEW(IDS_PERSONAL
)) &&
2664 !stat(szPersonalTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2666 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2667 * 'My Music' subfolders or fail silently if they already exist. */
2668 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2669 strcpy(szMyStuffTarget
, szPersonalTarget
);
2670 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2671 mkdir(szMyStuffTarget
, 0777);
2676 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2677 strcpy(szPersonalTarget
, pszHome
);
2680 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2682 symlink(szPersonalTarget
, pszPersonal
);
2686 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2687 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2688 strcpy(szPersonalTarget
, pszPersonal
);
2689 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2690 strcpy(szMyStuffTarget
, szPersonalTarget
);
2691 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2692 mkdir(szMyStuffTarget
, 0777);
2696 /* Create symbolic links for 'My Pictures', 'My Videos' and 'My Music'. */
2697 for (i
=0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2698 /* Create the current 'My Whatever' folder and get its unix path. */
2699 hr
= SHGetFolderPathW(NULL
, acsidlMyStuff
[i
]|CSIDL_FLAG_CREATE
, NULL
,
2700 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2701 if (FAILED(hr
)) continue;
2702 pszMyStuff
= wine_get_unix_file_name(wszTempPath
);
2703 if (!pszMyStuff
) continue;
2705 strcpy(szMyStuffTarget
, szPersonalTarget
);
2706 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])) &&
2707 !stat(szMyStuffTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2709 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2711 symlink(szMyStuffTarget
, pszMyStuff
);
2716 if (xdg_results
&& xdg_results
[i
])
2718 /* the folder specified by XDG_XXX_DIR exists, link to it. */
2719 symlink(xdg_results
[i
], pszMyStuff
);
2723 /* Else link to where 'My Documents' itself links to. */
2724 symlink(szPersonalTarget
, pszMyStuff
);
2727 HeapFree(GetProcessHeap(), 0, pszMyStuff
);
2730 /* Last but not least, the Desktop folder */
2732 strcpy(szDesktopTarget
, pszHome
);
2734 strcpy(szDesktopTarget
, pszPersonal
);
2735 HeapFree(GetProcessHeap(), 0, pszPersonal
);
2737 xdg_desktop_dir
= xdg_results
? xdg_results
[num
- 1] : NULL
;
2738 if (xdg_desktop_dir
||
2739 (_SHAppendToUnixPath(szDesktopTarget
, DesktopW
) &&
2740 !stat(szDesktopTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)))
2742 hr
= SHGetFolderPathW(NULL
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, NULL
,
2743 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2744 if (SUCCEEDED(hr
) && (pszDesktop
= wine_get_unix_file_name(wszTempPath
)))
2747 if (xdg_desktop_dir
)
2748 symlink(xdg_desktop_dir
, pszDesktop
);
2750 symlink(szDesktopTarget
, pszDesktop
);
2751 HeapFree(GetProcessHeap(), 0, pszDesktop
);
2755 /* Free resources allocated by XDG_UserDirLookup() */
2758 for (i
= 0; i
< num
; i
++)
2759 HeapFree(GetProcessHeap(), 0, xdg_results
[i
]);
2760 HeapFree(GetProcessHeap(), 0, xdg_results
);
2764 /******************************************************************************
2765 * create_extra_folders [Internal]
2767 * Create some extra folders that don't have a standard CSIDL definition.
2769 static HRESULT
create_extra_folders(void)
2771 static const WCHAR environW
[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
2772 static const WCHAR microsoftW
[] = {'M','i','c','r','o','s','o','f','t',0};
2773 static const WCHAR TempW
[] = {'T','e','m','p',0};
2774 static const WCHAR TEMPW
[] = {'T','E','M','P',0};
2775 static const WCHAR TMPW
[] = {'T','M','P',0};
2776 WCHAR path
[MAX_PATH
+5];
2779 DWORD type
, size
, ret
;
2781 ret
= RegCreateKeyW( HKEY_CURRENT_USER
, environW
, &hkey
);
2782 if (ret
) return HRESULT_FROM_WIN32( ret
);
2784 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
2785 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
,
2786 SHGFP_TYPE_DEFAULT
, TempW
, path
);
2789 size
= sizeof(path
);
2790 if (RegQueryValueExW( hkey
, TEMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2791 RegSetValueExW( hkey
, TEMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2792 size
= sizeof(path
);
2793 if (RegQueryValueExW( hkey
, TMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2794 RegSetValueExW( hkey
, TMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2796 RegCloseKey( hkey
);
2800 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA
| CSIDL_FLAG_CREATE
, NULL
,
2801 SHGFP_TYPE_DEFAULT
, microsoftW
, path
);
2807 /******************************************************************************
2808 * set_folder_attributes
2810 * Set the various folder attributes registry keys.
2812 static HRESULT
set_folder_attributes(void)
2814 static const WCHAR clsidW
[] = {'C','L','S','I','D','\\',0 };
2815 static const WCHAR shellfolderW
[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
2816 static const WCHAR wfparsingW
[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
2817 static const WCHAR wfdisplayW
[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
2818 static const WCHAR hideasdeleteW
[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
2819 static const WCHAR attributesW
[] = {'A','t','t','r','i','b','u','t','e','s',0};
2820 static const WCHAR cfattributesW
[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
2821 static const WCHAR emptyW
[] = {0};
2830 DWORD call_for_attr
;
2833 { &CLSID_UnixFolder
, TRUE
, FALSE
, FALSE
},
2834 { &CLSID_UnixDosFolder
, TRUE
, FALSE
, FALSE
,
2835 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2836 { &CLSID_FolderShortcut
, FALSE
, FALSE
, FALSE
,
2837 SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_LINK
,
2838 SFGAO_HASSUBFOLDER
|SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_FILESYSANCESTOR
},
2839 { &CLSID_MyDocuments
, TRUE
, FALSE
, FALSE
,
2840 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2841 { &CLSID_RecycleBin
, FALSE
, FALSE
, FALSE
,
2842 SFGAO_FOLDER
|SFGAO_DROPTARGET
|SFGAO_HASPROPSHEET
},
2843 { &CLSID_ControlPanel
, FALSE
, TRUE
, TRUE
,
2844 SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
}
2848 WCHAR buffer
[39 + (sizeof(clsidW
) + sizeof(shellfolderW
)) / sizeof(WCHAR
)];
2852 for (i
= 0; i
< sizeof(folders
)/sizeof(folders
[0]); i
++)
2854 strcpyW( buffer
, clsidW
);
2855 StringFromGUID2( folders
[i
].clsid
, buffer
+ strlenW(buffer
), 39 );
2856 strcatW( buffer
, shellfolderW
);
2857 res
= RegCreateKeyExW( HKEY_CLASSES_ROOT
, buffer
, 0, NULL
, 0,
2858 KEY_READ
| KEY_WRITE
, NULL
, &hkey
, NULL
);
2859 if (res
) return HRESULT_FROM_WIN32( res
);
2860 if (folders
[i
].wfparsing
)
2861 res
= RegSetValueExW( hkey
, wfparsingW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2862 if (folders
[i
].wfdisplay
)
2863 res
= RegSetValueExW( hkey
, wfdisplayW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2864 if (folders
[i
].hideasdel
)
2865 res
= RegSetValueExW( hkey
, hideasdeleteW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2866 if (folders
[i
].attr
)
2867 res
= RegSetValueExW( hkey
, attributesW
, 0, REG_DWORD
,
2868 (const BYTE
*)&folders
[i
].attr
, sizeof(DWORD
));
2869 if (folders
[i
].call_for_attr
)
2870 res
= RegSetValueExW( hkey
, cfattributesW
, 0, REG_DWORD
,
2871 (const BYTE
*)&folders
[i
].call_for_attr
, sizeof(DWORD
));
2872 RegCloseKey( hkey
);
2878 /* Register the default values in the registry, as some apps seem to depend
2879 * on their presence. The set registered was taken from Windows XP.
2881 HRESULT
SHELL_RegisterShellFolders(void)
2885 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2886 * 'My Videos', 'My Music' and 'Desktop' in advance, so that the
2887 * _SHRegister*ShellFolders() functions will find everything nice and clean
2888 * and thus will not attempt to create them in the profile directory. */
2889 _SHCreateSymbolicLinks();
2891 hr
= _SHRegisterUserShellFolders(TRUE
);
2893 hr
= _SHRegisterUserShellFolders(FALSE
);
2895 hr
= _SHRegisterCommonShellFolders();
2897 hr
= create_extra_folders();
2899 hr
= set_folder_attributes();
2903 /*************************************************************************
2904 * SHGetSpecialFolderPathA [SHELL32.@]
2906 BOOL WINAPI
SHGetSpecialFolderPathA (
2912 return SHGetFolderPathA(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2916 /*************************************************************************
2917 * SHGetSpecialFolderPathW
2919 BOOL WINAPI
SHGetSpecialFolderPathW (
2925 return SHGetFolderPathW(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2929 /*************************************************************************
2930 * SHGetSpecialFolderPath (SHELL32.175)
2932 BOOL WINAPI
SHGetSpecialFolderPathAW (
2939 if (SHELL_OsIsUnicode())
2940 return SHGetSpecialFolderPathW (hwndOwner
, szPath
, nFolder
, bCreate
);
2941 return SHGetSpecialFolderPathA (hwndOwner
, szPath
, nFolder
, bCreate
);
2944 /*************************************************************************
2945 * SHGetFolderLocation [SHELL32.@]
2947 * Gets the folder locations from the registry and creates a pidl.
2951 * nFolder [I] CSIDL_xxxxx
2952 * hToken [I] token representing user, or NULL for current user, or -1 for
2954 * dwReserved [I] must be zero
2955 * ppidl [O] PIDL of a special folder
2959 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2962 * Creates missing reg keys and directories.
2963 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2964 * virtual folders that are handled here.
2966 HRESULT WINAPI
SHGetFolderLocation(
2971 LPITEMIDLIST
*ppidl
)
2973 HRESULT hr
= E_INVALIDARG
;
2975 TRACE("%p 0x%08x %p 0x%08x %p\n",
2976 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
2979 return E_INVALIDARG
;
2981 return E_INVALIDARG
;
2983 /* The virtual folders' locations are not user-dependent */
2985 switch (nFolder
& CSIDL_FOLDER_MASK
)
2988 *ppidl
= _ILCreateDesktop();
2991 case CSIDL_PERSONAL
:
2992 *ppidl
= _ILCreateMyDocuments();
2995 case CSIDL_INTERNET
:
2996 *ppidl
= _ILCreateIExplore();
2999 case CSIDL_CONTROLS
:
3000 *ppidl
= _ILCreateControlPanel();
3003 case CSIDL_PRINTERS
:
3004 *ppidl
= _ILCreatePrinters();
3007 case CSIDL_BITBUCKET
:
3008 *ppidl
= _ILCreateBitBucket();
3012 *ppidl
= _ILCreateMyComputer();
3016 *ppidl
= _ILCreateNetwork();
3021 WCHAR szPath
[MAX_PATH
];
3023 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
3024 SHGFP_TYPE_CURRENT
, szPath
);
3029 TRACE("Value=%s\n", debugstr_w(szPath
));
3030 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
3032 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
3034 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
3035 * version 6.0 returns E_FAIL for nonexistent paths
3044 TRACE("-- (new pidl %p)\n",*ppidl
);
3048 /*************************************************************************
3049 * SHGetSpecialFolderLocation [SHELL32.@]
3052 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
3055 HRESULT WINAPI
SHGetSpecialFolderLocation(
3058 LPITEMIDLIST
* ppidl
)
3060 HRESULT hr
= E_INVALIDARG
;
3062 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
3065 return E_INVALIDARG
;
3067 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);
3071 static int csidl_from_id( const KNOWNFOLDERID
*id
)
3074 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
3075 if (IsEqualGUID( CSIDL_Data
[i
].id
, id
)) return i
;
3079 /*************************************************************************
3080 * SHGetKnownFolderPath [SHELL32.@]
3082 HRESULT WINAPI
SHGetKnownFolderPath(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PWSTR
*path
)
3085 WCHAR folder
[MAX_PATH
];
3086 int index
= csidl_from_id( rfid
);
3088 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid
), flags
, token
, path
);
3093 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND
);
3095 if (flags
& KF_FLAG_CREATE
)
3096 index
|= CSIDL_FLAG_CREATE
;
3098 if (flags
& KF_FLAG_DONT_VERIFY
)
3099 index
|= CSIDL_FLAG_DONT_VERIFY
;
3101 if (flags
& KF_FLAG_NO_ALIAS
)
3102 index
|= CSIDL_FLAG_NO_ALIAS
;
3104 if (flags
& KF_FLAG_INIT
)
3105 index
|= CSIDL_FLAG_PER_USER_INIT
;
3107 if (flags
& ~(KF_FLAG_CREATE
|KF_FLAG_DONT_VERIFY
|KF_FLAG_NO_ALIAS
|KF_FLAG_INIT
))
3109 FIXME("flags 0x%08x not supported\n", flags
);
3110 return E_INVALIDARG
;
3113 hr
= SHGetFolderPathW( NULL
, index
, token
, 0, folder
);
3116 *path
= CoTaskMemAlloc( (strlenW( folder
) + 1) * sizeof(WCHAR
) );
3118 return E_OUTOFMEMORY
;
3119 strcpyW( *path
, folder
);
3124 /*************************************************************************
3125 * SHGetFolderPathEx [SHELL32.@]
3127 HRESULT WINAPI
SHGetFolderPathEx(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, LPWSTR path
, DWORD len
)
3132 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid
), flags
, token
, path
, len
);
3134 if (!path
|| !len
) return E_INVALIDARG
;
3136 hr
= SHGetKnownFolderPath( rfid
, flags
, token
, &buffer
);
3137 if (SUCCEEDED( hr
))
3139 if (strlenW( buffer
) + 1 > len
)
3141 CoTaskMemFree( buffer
);
3142 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER
);
3144 strcpyW( path
, buffer
);
3145 CoTaskMemFree( buffer
);
3150 /* constant values used by known folder functions */
3151 static const WCHAR szCategory
[] = {'C','a','t','e','g','o','r','y',0};
3152 static const WCHAR szName
[] = {'N','a','m','e',0};
3153 static const WCHAR szRelativePath
[] = {'R','e','l','a','t','i','v','e','P','a','t','h',0};
3154 static const WCHAR szParentFolder
[] = {'P','a','r','e','n','t','F','o','l','d','e','r',0};
3157 * Internal function to convert known folder identifier to path of registry key
3158 * associated with known folder.
3161 * rfid [I] pointer to known folder identifier (may be NULL)
3162 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
3163 * lpPath [O] place to store string address. String should be
3164 * later freed using HeapFree(GetProcessHeap(),0, ... )
3166 static HRESULT
get_known_folder_registry_path(
3167 REFKNOWNFOLDERID rfid
,
3168 LPWSTR lpStringGuid
,
3171 static const WCHAR sBackslash
[] = {'\\',0};
3176 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid
), debugstr_w(lpStringGuid
), lpPath
);
3179 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3181 lstrcpyW(sGuid
, lpStringGuid
);
3183 length
= lstrlenW(szKnownFolderDescriptions
)+51;
3184 *lpPath
= HeapAlloc(GetProcessHeap(), 0, length
*sizeof(WCHAR
));
3190 lstrcpyW(*lpPath
, szKnownFolderDescriptions
);
3191 lstrcatW(*lpPath
, sBackslash
);
3192 lstrcatW(*lpPath
, sGuid
);
3199 * Internal function to get place where folder redirection information are stored.
3202 * rfid [I] pointer to known folder identifier (may be NULL)
3203 * rootKey [O] root key where the redirection information are stored
3204 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
3205 * However, besides root key, path is always that same, and is stored
3206 * as "szKnownFolderRedirections" constant
3208 static HRESULT
get_known_folder_redirection_place(
3209 REFKNOWNFOLDERID rfid
,
3213 LPWSTR lpRegistryPath
= NULL
;
3214 KF_CATEGORY category
;
3217 /* first, get known folder's category */
3218 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3222 dwSize
= sizeof(category
);
3223 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, lpRegistryPath
, szCategory
, RRF_RT_DWORD
, NULL
, &category
, &dwSize
));
3228 if(category
== KF_CATEGORY_COMMON
)
3230 *rootKey
= HKEY_LOCAL_MACHINE
;
3233 else if(category
== KF_CATEGORY_PERUSER
)
3235 *rootKey
= HKEY_CURRENT_USER
;
3242 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3246 static HRESULT
get_known_folder_path_by_id(REFKNOWNFOLDERID folderId
, LPWSTR lpRegistryPath
, DWORD dwFlags
, LPWSTR
*ppszPath
);
3248 static HRESULT
get_known_folder_category(
3249 LPWSTR registryPath
,
3250 KF_CATEGORY
* pCategory
)
3252 DWORD dwSize
= sizeof(DWORD
);
3254 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szCategory
, RRF_RT_DWORD
, &dwType
, pCategory
, &dwSize
));
3257 static HRESULT
redirect_known_folder(
3258 REFKNOWNFOLDERID rfid
,
3260 KF_REDIRECT_FLAGS flags
,
3261 LPCWSTR pszTargetPath
,
3263 KNOWNFOLDERID
const *pExclusion
,
3267 HKEY rootKey
= HKEY_LOCAL_MACHINE
, hKey
;
3269 LPWSTR lpRegistryPath
= NULL
, lpSrcPath
= NULL
;
3270 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid
), hwnd
, flags
, debugstr_w(pszTargetPath
), cFolders
, pExclusion
, ppszError
);
3272 if (ppszError
) *ppszError
= NULL
;
3274 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3277 hr
= get_known_folder_path_by_id(rfid
, lpRegistryPath
, 0, &lpSrcPath
);
3279 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3281 /* get path to redirection storage */
3283 hr
= get_known_folder_redirection_place(rfid
, &rootKey
);
3285 /* write redirection information */
3287 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey
, szKnownFolderRedirections
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hKey
, NULL
));
3291 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3293 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, sGuid
, 0, REG_SZ
, (LPBYTE
)pszTargetPath
, (lstrlenW(pszTargetPath
)+1)*sizeof(WCHAR
)));
3298 /* make sure destination path exists */
3299 SHCreateDirectory(NULL
, pszTargetPath
);
3301 /* copy content if required */
3302 if(SUCCEEDED(hr
) && (flags
& KF_REDIRECT_COPY_CONTENTS
) )
3304 static const WCHAR sWildcard
[] = {'\\','*',0};
3305 WCHAR srcPath
[MAX_PATH
+1], dstPath
[MAX_PATH
+1];
3306 SHFILEOPSTRUCTW fileOp
;
3308 ZeroMemory(srcPath
, sizeof(srcPath
));
3309 lstrcpyW(srcPath
, lpSrcPath
);
3310 lstrcatW(srcPath
, sWildcard
);
3312 ZeroMemory(dstPath
, sizeof(dstPath
));
3313 lstrcpyW(dstPath
, pszTargetPath
);
3315 ZeroMemory(&fileOp
, sizeof(fileOp
));
3317 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3318 fileOp
.wFunc
= FO_MOVE
;
3320 fileOp
.wFunc
= FO_COPY
;
3322 fileOp
.pFrom
= srcPath
;
3323 fileOp
.pTo
= dstPath
;
3324 fileOp
.fFlags
= FOF_NO_UI
;
3326 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3328 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3330 ZeroMemory(srcPath
, sizeof(srcPath
));
3331 lstrcpyW(srcPath
, lpSrcPath
);
3333 ZeroMemory(&fileOp
, sizeof(fileOp
));
3334 fileOp
.wFunc
= FO_DELETE
;
3335 fileOp
.pFrom
= srcPath
;
3336 fileOp
.fFlags
= FOF_NO_UI
;
3338 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3342 CoTaskMemFree(lpSrcPath
);
3350 IKnownFolder IKnownFolder_iface
;
3353 LPWSTR registryPath
;
3356 static inline struct knownfolder
*impl_from_IKnownFolder( IKnownFolder
*iface
)
3358 return CONTAINING_RECORD( iface
, struct knownfolder
, IKnownFolder_iface
);
3361 static ULONG WINAPI
knownfolder_AddRef(
3362 IKnownFolder
*iface
)
3364 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3365 return InterlockedIncrement( &knownfolder
->refs
);
3368 static ULONG WINAPI
knownfolder_Release(
3369 IKnownFolder
*iface
)
3371 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3372 LONG refs
= InterlockedDecrement( &knownfolder
->refs
);
3375 TRACE("destroying %p\n", knownfolder
);
3376 HeapFree( GetProcessHeap(), 0, knownfolder
->registryPath
);
3377 HeapFree( GetProcessHeap(), 0, knownfolder
);
3382 static HRESULT WINAPI
knownfolder_QueryInterface(
3383 IKnownFolder
*iface
,
3387 struct knownfolder
*This
= impl_from_IKnownFolder( iface
);
3389 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3391 if ( IsEqualGUID( riid
, &IID_IKnownFolder
) ||
3392 IsEqualGUID( riid
, &IID_IUnknown
) )
3398 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3399 return E_NOINTERFACE
;
3401 IKnownFolder_AddRef( iface
);
3405 static HRESULT
knownfolder_set_id(
3406 struct knownfolder
*knownfolder
,
3407 const KNOWNFOLDERID
*kfid
)
3412 TRACE("%s\n", debugstr_guid(kfid
));
3414 knownfolder
->id
= *kfid
;
3416 /* check is it registry-registered folder */
3417 hr
= get_known_folder_registry_path(kfid
, NULL
, &knownfolder
->registryPath
);
3419 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, 0, 0, &hKey
));
3428 /* This known folder is not registered. To mark it, we set registryPath to NULL */
3429 HeapFree(GetProcessHeap(), 0, knownfolder
->registryPath
);
3430 knownfolder
->registryPath
= NULL
;
3437 static HRESULT WINAPI
knownfolder_GetId(
3438 IKnownFolder
*iface
,
3439 KNOWNFOLDERID
*pkfid
)
3441 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3443 TRACE("%p\n", pkfid
);
3445 *pkfid
= knownfolder
->id
;
3449 static HRESULT WINAPI
knownfolder_GetCategory(
3450 IKnownFolder
*iface
,
3451 KF_CATEGORY
*pCategory
)
3453 struct knownfolder
*knownfolder
= impl_from_IKnownFolder(iface
);
3456 TRACE("%p, %p\n", knownfolder
, pCategory
);
3458 /* we cannot get a category for a folder which is not registered */
3459 if(!knownfolder
->registryPath
)
3463 hr
= get_known_folder_category(knownfolder
->registryPath
, pCategory
);
3468 static HRESULT WINAPI
knownfolder_GetShellItem(
3469 IKnownFolder
*iface
,
3474 FIXME("0x%08x, %s, %p\n", dwFlags
, debugstr_guid(riid
), ppv
);
3478 static HRESULT
get_known_folder_path(
3480 LPWSTR registryPath
,
3483 static const WCHAR sBackslash
[] = {'\\',0};
3485 DWORD dwSize
, dwType
;
3486 WCHAR path
[MAX_PATH
] = {0};
3487 WCHAR parentGuid
[39];
3488 KF_CATEGORY category
;
3489 LPWSTR parentRegistryPath
, parentPath
;
3490 HKEY hRedirectionRootKey
= NULL
;
3492 TRACE("(%s, %p)\n", debugstr_w(registryPath
), ppszPath
);
3495 /* check if folder has parent */
3496 dwSize
= sizeof(parentGuid
);
3497 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szParentFolder
, RRF_RT_REG_SZ
, &dwType
, parentGuid
, &dwSize
));
3498 if(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) hr
= S_FALSE
;
3502 /* get parent's known folder path (recursive) */
3503 hr
= get_known_folder_registry_path(NULL
, parentGuid
, &parentRegistryPath
);
3504 if(FAILED(hr
)) return hr
;
3506 hr
= get_known_folder_path(parentGuid
, parentRegistryPath
, &parentPath
);
3508 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3512 lstrcatW(path
, parentPath
);
3513 lstrcatW(path
, sBackslash
);
3515 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3516 HeapFree(GetProcessHeap(), 0, parentPath
);
3519 /* check, if folder was redirected */
3521 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szCategory
, RRF_RT_REG_DWORD
, NULL
, &category
, &dwSize
));
3525 if(category
== KF_CATEGORY_COMMON
)
3526 hRedirectionRootKey
= HKEY_LOCAL_MACHINE
;
3527 else if(category
== KF_CATEGORY_PERUSER
)
3528 hRedirectionRootKey
= HKEY_CURRENT_USER
;
3530 if(hRedirectionRootKey
)
3532 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3536 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3537 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3542 lstrcpyW(*ppszPath
, path
);
3543 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3549 /* no redirection, use previous way - read the relative path from folder definition */
3550 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, NULL
, &dwSize
));
3554 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3555 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3560 lstrcpyW(*ppszPath
, path
);
3561 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3566 TRACE("returning path: %s\n", debugstr_w(*ppszPath
));
3570 static HRESULT
get_known_folder_path_by_id(
3571 REFKNOWNFOLDERID folderId
,
3572 LPWSTR lpRegistryPath
,
3580 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId
), debugstr_w(lpRegistryPath
), dwFlags
, ppszPath
);
3582 /* if this is registry-registered known folder, get path from registry */
3585 StringFromGUID2(folderId
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3587 hr
= get_known_folder_path(sGuid
, lpRegistryPath
, ppszPath
);
3589 /* in other case, use older way */
3591 hr
= SHGetKnownFolderPath( folderId
, dwFlags
, NULL
, ppszPath
);
3593 if (FAILED(hr
)) return hr
;
3595 /* check if known folder really exists */
3596 dwAttributes
= GetFileAttributesW(*ppszPath
);
3597 if(dwAttributes
== INVALID_FILE_ATTRIBUTES
|| !(dwAttributes
& FILE_ATTRIBUTE_DIRECTORY
) )
3599 TRACE("directory %s not found\n", debugstr_w(*ppszPath
));
3600 CoTaskMemFree(*ppszPath
);
3602 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
3608 static HRESULT WINAPI
knownfolder_GetPath(
3609 IKnownFolder
*iface
,
3613 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3614 TRACE("(%p, 0x%08x, %p)\n", knownfolder
, dwFlags
, ppszPath
);
3616 return get_known_folder_path_by_id(&knownfolder
->id
, knownfolder
->registryPath
, dwFlags
, ppszPath
);
3619 static HRESULT WINAPI
knownfolder_SetPath(
3620 IKnownFolder
*iface
,
3624 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3627 TRACE("(%p, 0x%08x, %s)\n", knownfolder
, dwFlags
, debugstr_w(pszPath
));
3629 /* check if the known folder is registered */
3630 if(!knownfolder
->registryPath
)
3634 hr
= redirect_known_folder(&knownfolder
->id
, NULL
, 0, pszPath
, 0, NULL
, NULL
);
3639 static HRESULT WINAPI
knownfolder_GetIDList(
3640 IKnownFolder
*iface
,
3642 PIDLIST_ABSOLUTE
*ppidl
)
3644 FIXME("0x%08x, %p\n", dwFlags
, ppidl
);
3648 static HRESULT WINAPI
knownfolder_GetFolderType(
3649 IKnownFolder
*iface
,
3650 FOLDERTYPEID
*pftid
)
3652 FIXME("%p\n", pftid
);
3656 static HRESULT WINAPI
knownfolder_GetRedirectionCapabilities(
3657 IKnownFolder
*iface
,
3658 KF_REDIRECTION_CAPABILITIES
*pCapabilities
)
3660 FIXME("%p\n", pCapabilities
);
3664 static HRESULT WINAPI
knownfolder_GetFolderDefinition(
3665 IKnownFolder
*iface
,
3666 KNOWNFOLDER_DEFINITION
*pKFD
)
3668 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3671 TRACE("(%p, %p)\n", knownfolder
, pKFD
);
3673 if(!pKFD
) return E_INVALIDARG
;
3675 ZeroMemory(pKFD
, sizeof(*pKFD
));
3677 hr
= get_known_folder_category(knownfolder
->registryPath
, &pKFD
->category
);
3680 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, szName
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3684 pKFD
->pszName
= CoTaskMemAlloc(dwSize
);
3685 if(!pKFD
->pszName
) hr
= E_OUTOFMEMORY
;
3689 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, szName
, RRF_RT_REG_SZ
, NULL
, pKFD
->pszName
, &dwSize
));
3694 static const struct IKnownFolderVtbl knownfolder_vtbl
=
3696 knownfolder_QueryInterface
,
3698 knownfolder_Release
,
3700 knownfolder_GetCategory
,
3701 knownfolder_GetShellItem
,
3702 knownfolder_GetPath
,
3703 knownfolder_SetPath
,
3704 knownfolder_GetIDList
,
3705 knownfolder_GetFolderType
,
3706 knownfolder_GetRedirectionCapabilities
,
3707 knownfolder_GetFolderDefinition
3710 static HRESULT
knownfolder_create( struct knownfolder
**knownfolder
)
3712 struct knownfolder
*kf
;
3714 kf
= HeapAlloc( GetProcessHeap(), 0, sizeof(*kf
) );
3715 if (!kf
) return E_OUTOFMEMORY
;
3717 kf
->IKnownFolder_iface
.lpVtbl
= &knownfolder_vtbl
;
3719 memset( &kf
->id
, 0, sizeof(kf
->id
) );
3720 kf
->registryPath
= NULL
;
3724 TRACE("returning iface %p\n", &kf
->IKnownFolder_iface
);
3728 struct foldermanager
3730 IKnownFolderManager IKnownFolderManager_iface
;
3736 static inline struct foldermanager
*impl_from_IKnownFolderManager( IKnownFolderManager
*iface
)
3738 return CONTAINING_RECORD( iface
, struct foldermanager
, IKnownFolderManager_iface
);
3741 static ULONG WINAPI
foldermanager_AddRef(
3742 IKnownFolderManager
*iface
)
3744 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3745 return InterlockedIncrement( &foldermanager
->refs
);
3748 static ULONG WINAPI
foldermanager_Release(
3749 IKnownFolderManager
*iface
)
3751 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3752 LONG refs
= InterlockedDecrement( &foldermanager
->refs
);
3755 TRACE("destroying %p\n", foldermanager
);
3756 HeapFree( GetProcessHeap(), 0, foldermanager
->ids
);
3757 HeapFree( GetProcessHeap(), 0, foldermanager
);
3762 static HRESULT WINAPI
foldermanager_QueryInterface(
3763 IKnownFolderManager
*iface
,
3767 struct foldermanager
*This
= impl_from_IKnownFolderManager( iface
);
3769 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3771 if ( IsEqualGUID( riid
, &IID_IKnownFolderManager
) ||
3772 IsEqualGUID( riid
, &IID_IUnknown
) )
3778 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3779 return E_NOINTERFACE
;
3781 IKnownFolderManager_AddRef( iface
);
3785 static HRESULT WINAPI
foldermanager_FolderIdFromCsidl(
3786 IKnownFolderManager
*iface
,
3788 KNOWNFOLDERID
*pfid
)
3790 TRACE("%d, %p\n", nCsidl
, pfid
);
3792 if (nCsidl
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
3793 return E_INVALIDARG
;
3794 *pfid
= *CSIDL_Data
[nCsidl
].id
;
3798 static HRESULT WINAPI
foldermanager_FolderIdToCsidl(
3799 IKnownFolderManager
*iface
,
3800 REFKNOWNFOLDERID rfid
,
3805 TRACE("%s, %p\n", debugstr_guid(rfid
), pnCsidl
);
3807 csidl
= csidl_from_id( rfid
);
3808 if (csidl
== -1) return E_INVALIDARG
;
3813 static HRESULT WINAPI
foldermanager_GetFolderIds(
3814 IKnownFolderManager
*iface
,
3815 KNOWNFOLDERID
**ppKFId
,
3818 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
3820 TRACE("%p, %p\n", ppKFId
, pCount
);
3823 *pCount
= fm
->num_ids
;
3827 static BOOL
is_knownfolder( struct foldermanager
*fm
, const KNOWNFOLDERID
*id
)
3831 LPWSTR registryPath
= NULL
;
3834 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
3835 for (i
= 0; i
< fm
->num_ids
; i
++)
3836 if (IsEqualGUID( &fm
->ids
[i
], id
)) return TRUE
;
3838 hr
= get_known_folder_registry_path(id
, NULL
, ®istryPath
);
3841 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, 0, &hKey
));
3842 HeapFree(GetProcessHeap(), 0, registryPath
);
3854 static HRESULT WINAPI
foldermanager_GetFolder(
3855 IKnownFolderManager
*iface
,
3856 REFKNOWNFOLDERID rfid
,
3857 IKnownFolder
**ppkf
)
3859 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
3860 struct knownfolder
*kf
;
3863 TRACE("%s, %p\n", debugstr_guid(rfid
), ppkf
);
3865 if (!is_knownfolder( fm
, rfid
))
3867 WARN("unknown folder\n");
3868 return E_INVALIDARG
;
3870 hr
= knownfolder_create( &kf
);
3871 if (SUCCEEDED( hr
))
3873 hr
= knownfolder_set_id( kf
, rfid
);
3874 *ppkf
= &kf
->IKnownFolder_iface
;
3882 static HRESULT WINAPI
foldermanager_GetFolderByName(
3883 IKnownFolderManager
*iface
,
3884 LPCWSTR pszCanonicalName
,
3885 IKnownFolder
**ppkf
)
3887 FIXME("%s, %p\n", debugstr_w(pszCanonicalName
), ppkf
);
3891 static HRESULT WINAPI
foldermanager_RegisterFolder(
3892 IKnownFolderManager
*iface
,
3893 REFKNOWNFOLDERID rfid
,
3894 KNOWNFOLDER_DEFINITION
const *pKFD
)
3899 LPWSTR registryPath
= NULL
;
3900 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(rfid
), pKFD
);
3902 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
3903 TRACE("registry path: %s\n", debugstr_w(registryPath
));
3906 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, NULL
, 0, KEY_WRITE
, 0, &hKey
, &dwDisp
));
3910 if(dwDisp
== REG_OPENED_EXISTING_KEY
)
3914 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szCategory
, 0, REG_DWORD
, (LPBYTE
)&pKFD
->category
, sizeof(pKFD
->category
)));
3917 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szName
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszName
, (lstrlenW(pKFD
->pszName
)+1)*sizeof(WCHAR
) ));
3919 if(SUCCEEDED(hr
) && !IsEqualGUID(&pKFD
->fidParent
, &GUID_NULL
))
3921 WCHAR sParentGuid
[39];
3922 StringFromGUID2(&pKFD
->fidParent
, sParentGuid
, sizeof(sParentGuid
)/sizeof(sParentGuid
[0]));
3924 /* this known folder has parent folder */
3925 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szParentFolder
, 0, REG_SZ
, (LPBYTE
)sParentGuid
, sizeof(sParentGuid
)));
3928 if(SUCCEEDED(hr
) && pKFD
->category
!= KF_CATEGORY_VIRTUAL
)
3930 if(!pKFD
->pszRelativePath
)
3934 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szRelativePath
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszRelativePath
, (lstrlenW(pKFD
->pszRelativePath
)+1)*sizeof(WCHAR
) ));
3940 SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
);
3943 HeapFree(GetProcessHeap(), 0, registryPath
);
3947 static HRESULT WINAPI
foldermanager_UnregisterFolder(
3948 IKnownFolderManager
*iface
,
3949 REFKNOWNFOLDERID rfid
)
3952 LPWSTR registryPath
= NULL
;
3953 TRACE("(%p, %s)\n", iface
, debugstr_guid(rfid
));
3955 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
3958 hr
= HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
));
3960 HeapFree(GetProcessHeap(), 0, registryPath
);
3964 static HRESULT WINAPI
foldermanager_FindFolderFromPath(
3965 IKnownFolderManager
*iface
,
3968 IKnownFolder
**ppkf
)
3970 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath
), mode
, ppkf
);
3974 static HRESULT WINAPI
foldermanager_FindFolderFromIDList(
3975 IKnownFolderManager
*iface
,
3976 PCIDLIST_ABSOLUTE pidl
,
3977 IKnownFolder
**ppkf
)
3979 FIXME("%p, %p\n", pidl
, ppkf
);
3983 static HRESULT WINAPI
foldermanager_Redirect(
3984 IKnownFolderManager
*iface
,
3985 REFKNOWNFOLDERID rfid
,
3987 KF_REDIRECT_FLAGS flags
,
3988 LPCWSTR pszTargetPath
,
3990 KNOWNFOLDERID
const *pExclusion
,
3993 return redirect_known_folder(rfid
, hwnd
, flags
, pszTargetPath
, cFolders
, pExclusion
, ppszError
);
3996 static const struct IKnownFolderManagerVtbl foldermanager_vtbl
=
3998 foldermanager_QueryInterface
,
3999 foldermanager_AddRef
,
4000 foldermanager_Release
,
4001 foldermanager_FolderIdFromCsidl
,
4002 foldermanager_FolderIdToCsidl
,
4003 foldermanager_GetFolderIds
,
4004 foldermanager_GetFolder
,
4005 foldermanager_GetFolderByName
,
4006 foldermanager_RegisterFolder
,
4007 foldermanager_UnregisterFolder
,
4008 foldermanager_FindFolderFromPath
,
4009 foldermanager_FindFolderFromIDList
,
4010 foldermanager_Redirect
4013 static HRESULT
foldermanager_create( void **ppv
)
4016 struct foldermanager
*fm
;
4018 fm
= HeapAlloc( GetProcessHeap(), 0, sizeof(*fm
) );
4019 if (!fm
) return E_OUTOFMEMORY
;
4021 fm
->IKnownFolderManager_iface
.lpVtbl
= &foldermanager_vtbl
;
4025 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
4027 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
)) fm
->num_ids
++;
4029 fm
->ids
= HeapAlloc( GetProcessHeap(), 0, fm
->num_ids
* sizeof(KNOWNFOLDERID
) );
4032 HeapFree( GetProcessHeap(), 0, fm
);
4033 return E_OUTOFMEMORY
;
4035 for (i
= j
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
4037 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
))
4039 fm
->ids
[j
] = *CSIDL_Data
[i
].id
;
4043 TRACE("found %u known folders\n", fm
->num_ids
);
4044 *ppv
= &fm
->IKnownFolderManager_iface
;
4046 TRACE("returning iface %p\n", *ppv
);
4050 HRESULT WINAPI
KnownFolderManager_Constructor( IUnknown
*punk
, REFIID riid
, void **ppv
)
4052 TRACE("%p, %s, %p\n", punk
, debugstr_guid(riid
), ppv
);
4057 return CLASS_E_NOAGGREGATION
;
4059 return foldermanager_create( ppv
);
4062 HRESULT WINAPI
SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PIDLIST_ABSOLUTE
*pidl
)
4064 FIXME("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid
), flags
, token
, pidl
);