4 * Copyright 1998, 1999, 2000 Juergen Schmied
5 * Copyright 2004 Juan Lang
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Many of these functions are in SHLWAPI.DLL also
30 #include "wine/port.h"
36 #include "wine/debug.h"
47 #include "shell32_main.h"
48 #include "undocshell.h"
50 #include "wine/unicode.h"
55 #include "knownfolders.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
60 static const BOOL is_win64
= sizeof(void *) > sizeof(int);
63 ########## Combining and Constructing paths ##########
66 /*************************************************************************
67 * PathAppend [SHELL32.36]
69 BOOL WINAPI
PathAppendAW(
73 if (SHELL_OsIsUnicode())
74 return PathAppendW(lpszPath1
, lpszPath2
);
75 return PathAppendA(lpszPath1
, lpszPath2
);
78 /*************************************************************************
79 * PathCombine [SHELL32.37]
81 LPVOID WINAPI
PathCombineAW(
86 if (SHELL_OsIsUnicode())
87 return PathCombineW( szDest
, lpszDir
, lpszFile
);
88 return PathCombineA( szDest
, lpszDir
, lpszFile
);
91 /*************************************************************************
92 * PathAddBackslash [SHELL32.32]
94 LPVOID WINAPI
PathAddBackslashAW(LPVOID lpszPath
)
96 if(SHELL_OsIsUnicode())
97 return PathAddBackslashW(lpszPath
);
98 return PathAddBackslashA(lpszPath
);
101 /*************************************************************************
102 * PathBuildRoot [SHELL32.30]
104 LPVOID WINAPI
PathBuildRootAW(LPVOID lpszPath
, int drive
)
106 if(SHELL_OsIsUnicode())
107 return PathBuildRootW(lpszPath
, drive
);
108 return PathBuildRootA(lpszPath
, drive
);
112 Extracting Component Parts
115 /*************************************************************************
116 * PathFindFileName [SHELL32.34]
118 LPVOID WINAPI
PathFindFileNameAW(LPCVOID lpszPath
)
120 if(SHELL_OsIsUnicode())
121 return PathFindFileNameW(lpszPath
);
122 return PathFindFileNameA(lpszPath
);
125 /*************************************************************************
126 * PathFindExtension [SHELL32.31]
128 LPVOID WINAPI
PathFindExtensionAW(LPCVOID lpszPath
)
130 if (SHELL_OsIsUnicode())
131 return PathFindExtensionW(lpszPath
);
132 return PathFindExtensionA(lpszPath
);
136 /*************************************************************************
137 * PathGetExtensionA [internal]
140 * exported by ordinal
141 * return value points to the first char after the dot
143 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
145 TRACE("(%s)\n",lpszPath
);
147 lpszPath
= PathFindExtensionA(lpszPath
);
148 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
151 /*************************************************************************
152 * PathGetExtensionW [internal]
154 static LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
156 TRACE("(%s)\n",debugstr_w(lpszPath
));
158 lpszPath
= PathFindExtensionW(lpszPath
);
159 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
162 /*************************************************************************
163 * PathGetExtension [SHELL32.158]
165 LPVOID WINAPI
PathGetExtensionAW(LPCVOID lpszPath
,DWORD void1
, DWORD void2
)
167 if (SHELL_OsIsUnicode())
168 return PathGetExtensionW(lpszPath
);
169 return PathGetExtensionA(lpszPath
);
172 /*************************************************************************
173 * PathGetArgs [SHELL32.52]
175 LPVOID WINAPI
PathGetArgsAW(LPVOID lpszPath
)
177 if (SHELL_OsIsUnicode())
178 return PathGetArgsW(lpszPath
);
179 return PathGetArgsA(lpszPath
);
182 /*************************************************************************
183 * PathGetDriveNumber [SHELL32.57]
185 int WINAPI
PathGetDriveNumberAW(LPVOID lpszPath
)
187 if (SHELL_OsIsUnicode())
188 return PathGetDriveNumberW(lpszPath
);
189 return PathGetDriveNumberA(lpszPath
);
192 /*************************************************************************
193 * PathRemoveFileSpec [SHELL32.35]
195 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
197 if (SHELL_OsIsUnicode())
198 return PathRemoveFileSpecW(lpszPath
);
199 return PathRemoveFileSpecA(lpszPath
);
202 /*************************************************************************
203 * PathStripPath [SHELL32.38]
205 void WINAPI
PathStripPathAW(LPVOID lpszPath
)
207 if (SHELL_OsIsUnicode())
208 PathStripPathW(lpszPath
);
210 PathStripPathA(lpszPath
);
213 /*************************************************************************
214 * PathStripToRoot [SHELL32.50]
216 BOOL WINAPI
PathStripToRootAW(LPVOID lpszPath
)
218 if (SHELL_OsIsUnicode())
219 return PathStripToRootW(lpszPath
);
220 return PathStripToRootA(lpszPath
);
223 /*************************************************************************
224 * PathRemoveArgs [SHELL32.251]
226 void WINAPI
PathRemoveArgsAW(LPVOID lpszPath
)
228 if (SHELL_OsIsUnicode())
229 PathRemoveArgsW(lpszPath
);
231 PathRemoveArgsA(lpszPath
);
234 /*************************************************************************
235 * PathRemoveExtension [SHELL32.250]
237 void WINAPI
PathRemoveExtensionAW(LPVOID lpszPath
)
239 if (SHELL_OsIsUnicode())
240 PathRemoveExtensionW(lpszPath
);
242 PathRemoveExtensionA(lpszPath
);
250 /*************************************************************************
251 * PathGetShortPathA [internal]
253 static void PathGetShortPathA(LPSTR pszPath
)
257 TRACE("%s\n", pszPath
);
259 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
261 lstrcpyA(pszPath
, path
);
265 /*************************************************************************
266 * PathGetShortPathW [internal]
268 static void PathGetShortPathW(LPWSTR pszPath
)
270 WCHAR path
[MAX_PATH
];
272 TRACE("%s\n", debugstr_w(pszPath
));
274 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
276 lstrcpyW(pszPath
, path
);
280 /*************************************************************************
281 * PathGetShortPath [SHELL32.92]
283 VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
285 if(SHELL_OsIsUnicode())
286 PathGetShortPathW(pszPath
);
287 PathGetShortPathA(pszPath
);
290 /*************************************************************************
291 * PathRemoveBlanks [SHELL32.33]
293 void WINAPI
PathRemoveBlanksAW(LPVOID str
)
295 if(SHELL_OsIsUnicode())
296 PathRemoveBlanksW(str
);
298 PathRemoveBlanksA(str
);
301 /*************************************************************************
302 * PathQuoteSpaces [SHELL32.55]
304 VOID WINAPI
PathQuoteSpacesAW (LPVOID lpszPath
)
306 if(SHELL_OsIsUnicode())
307 PathQuoteSpacesW(lpszPath
);
309 PathQuoteSpacesA(lpszPath
);
312 /*************************************************************************
313 * PathUnquoteSpaces [SHELL32.56]
315 VOID WINAPI
PathUnquoteSpacesAW(LPVOID str
)
317 if(SHELL_OsIsUnicode())
318 PathUnquoteSpacesW(str
);
320 PathUnquoteSpacesA(str
);
323 /*************************************************************************
324 * PathParseIconLocation [SHELL32.249]
326 int WINAPI
PathParseIconLocationAW (LPVOID lpszPath
)
328 if(SHELL_OsIsUnicode())
329 return PathParseIconLocationW(lpszPath
);
330 return PathParseIconLocationA(lpszPath
);
334 ########## Path Testing ##########
336 /*************************************************************************
337 * PathIsUNC [SHELL32.39]
339 BOOL WINAPI
PathIsUNCAW (LPCVOID lpszPath
)
341 if (SHELL_OsIsUnicode())
342 return PathIsUNCW( lpszPath
);
343 return PathIsUNCA( lpszPath
);
346 /*************************************************************************
347 * PathIsRelative [SHELL32.40]
349 BOOL WINAPI
PathIsRelativeAW (LPCVOID lpszPath
)
351 if (SHELL_OsIsUnicode())
352 return PathIsRelativeW( lpszPath
);
353 return PathIsRelativeA( lpszPath
);
356 /*************************************************************************
357 * PathIsRoot [SHELL32.29]
359 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
361 if (SHELL_OsIsUnicode())
362 return PathIsRootW(lpszPath
);
363 return PathIsRootA(lpszPath
);
366 /*************************************************************************
367 * PathIsExeA [internal]
369 static BOOL
PathIsExeA (LPCSTR lpszPath
)
371 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
373 static const char * const lpszExtensions
[] =
374 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
376 TRACE("path=%s\n",lpszPath
);
378 for(i
=0; lpszExtensions
[i
]; i
++)
379 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
384 /*************************************************************************
385 * PathIsExeW [internal]
387 static BOOL
PathIsExeW (LPCWSTR lpszPath
)
389 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
391 static const WCHAR lpszExtensions
[][4] =
392 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
393 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
394 {'s','c','r','\0'}, {'\0'} };
396 TRACE("path=%s\n",debugstr_w(lpszPath
));
398 for(i
=0; lpszExtensions
[i
][0]; i
++)
399 if (!strcmpiW(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
404 /*************************************************************************
405 * PathIsExe [SHELL32.43]
407 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
409 if (SHELL_OsIsUnicode())
410 return PathIsExeW (path
);
411 return PathIsExeA(path
);
414 /*************************************************************************
415 * PathIsDirectory [SHELL32.159]
417 BOOL WINAPI
PathIsDirectoryAW (LPCVOID lpszPath
)
419 if (SHELL_OsIsUnicode())
420 return PathIsDirectoryW (lpszPath
);
421 return PathIsDirectoryA (lpszPath
);
424 /*************************************************************************
425 * PathFileExists [SHELL32.45]
427 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
429 if (SHELL_OsIsUnicode())
430 return PathFileExistsW (lpszPath
);
431 return PathFileExistsA (lpszPath
);
434 /*************************************************************************
435 * PathMatchSpec [SHELL32.46]
437 BOOL WINAPI
PathMatchSpecAW(LPVOID name
, LPVOID mask
)
439 if (SHELL_OsIsUnicode())
440 return PathMatchSpecW( name
, mask
);
441 return PathMatchSpecA( name
, mask
);
444 /*************************************************************************
445 * PathIsSameRoot [SHELL32.650]
447 BOOL WINAPI
PathIsSameRootAW(LPCVOID lpszPath1
, LPCVOID lpszPath2
)
449 if (SHELL_OsIsUnicode())
450 return PathIsSameRootW(lpszPath1
, lpszPath2
);
451 return PathIsSameRootA(lpszPath1
, lpszPath2
);
454 /*************************************************************************
455 * IsLFNDriveA [SHELL32.41]
457 BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
461 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
466 /*************************************************************************
467 * IsLFNDriveW [SHELL32.42]
469 BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
473 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
478 /*************************************************************************
479 * IsLFNDrive [SHELL32.119]
481 BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
483 if (SHELL_OsIsUnicode())
484 return IsLFNDriveW(lpszPath
);
485 return IsLFNDriveA(lpszPath
);
489 ########## Creating Something Unique ##########
491 /*************************************************************************
492 * PathMakeUniqueNameA [internal]
494 static BOOL
PathMakeUniqueNameA(
497 LPCSTR lpszShortName
,
501 FIXME("%p %u %s %s %s stub\n",
502 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
503 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
507 /*************************************************************************
508 * PathMakeUniqueNameW [internal]
510 static BOOL
PathMakeUniqueNameW(
513 LPCWSTR lpszShortName
,
514 LPCWSTR lpszLongName
,
515 LPCWSTR lpszPathName
)
517 FIXME("%p %u %s %s %s stub\n",
518 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
519 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
523 /*************************************************************************
524 * PathMakeUniqueName [SHELL32.47]
526 BOOL WINAPI
PathMakeUniqueNameAW(
529 LPCVOID lpszShortName
,
530 LPCVOID lpszLongName
,
531 LPCVOID lpszPathName
)
533 if (SHELL_OsIsUnicode())
534 return PathMakeUniqueNameW(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
535 return PathMakeUniqueNameA(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
538 /*************************************************************************
539 * PathYetAnotherMakeUniqueName [SHELL32.75]
542 * exported by ordinal
544 BOOL WINAPI
PathYetAnotherMakeUniqueName(
546 LPCWSTR lpszPathName
,
547 LPCWSTR lpszShortName
,
548 LPCWSTR lpszLongName
)
550 FIXME("(%p, %s, %s ,%s):stub.\n",
551 lpszBuffer
, debugstr_w(lpszPathName
), debugstr_w(lpszShortName
), debugstr_w(lpszLongName
));
557 ########## cleaning and resolving paths ##########
560 /*************************************************************************
561 * PathFindOnPath [SHELL32.145]
563 BOOL WINAPI
PathFindOnPathAW(LPVOID sFile
, LPCVOID
*sOtherDirs
)
565 if (SHELL_OsIsUnicode())
566 return PathFindOnPathW(sFile
, (LPCWSTR
*)sOtherDirs
);
567 return PathFindOnPathA(sFile
, (LPCSTR
*)sOtherDirs
);
570 /*************************************************************************
571 * PathCleanupSpec [SHELL32.171]
573 * lpszFile is changed in place.
575 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
581 if (SHELL_OsIsUnicode())
583 LPWSTR p
= lpszFileW
;
585 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
588 length
= strlenW(lpszPathW
);
592 int gct
= PathGetCharTypeW(*p
);
593 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
596 rc
|= PCS_REPLACEDCHAR
;
602 if (length
+ i
== MAX_PATH
)
604 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
612 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
613 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
616 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
619 length
= strlen(lpszPathA
);
623 int gct
= PathGetCharTypeA(*p
);
624 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
627 rc
|= PCS_REPLACEDCHAR
;
633 if (length
+ i
== MAX_PATH
)
635 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
644 /*************************************************************************
645 * PathQualifyA [SHELL32]
647 static BOOL
PathQualifyA(LPCSTR pszPath
)
649 FIXME("%s\n",pszPath
);
653 /*************************************************************************
654 * PathQualifyW [SHELL32]
656 static BOOL
PathQualifyW(LPCWSTR pszPath
)
658 FIXME("%s\n",debugstr_w(pszPath
));
662 /*************************************************************************
663 * PathQualify [SHELL32.49]
665 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
667 if (SHELL_OsIsUnicode())
668 return PathQualifyW(pszPath
);
669 return PathQualifyA(pszPath
);
672 static BOOL
PathResolveA(LPSTR path
, LPCSTR
*paths
, DWORD flags
)
674 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_a(path
), paths
, flags
);
678 static BOOL
PathResolveW(LPWSTR path
, LPCWSTR
*paths
, DWORD flags
)
680 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_w(path
), paths
, flags
);
684 /*************************************************************************
685 * PathResolve [SHELL32.51]
687 BOOL WINAPI
PathResolveAW(LPVOID path
, LPCVOID
*paths
, DWORD flags
)
689 if (SHELL_OsIsUnicode())
690 return PathResolveW(path
, (LPCWSTR
*)paths
, flags
);
692 return PathResolveA(path
, (LPCSTR
*)paths
, flags
);
695 /*************************************************************************
696 * PathProcessCommandA
698 static LONG
PathProcessCommandA (
704 FIXME("%s %p 0x%04x 0x%04x stub\n",
705 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
706 if(!lpszPath
) return -1;
707 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
708 return strlen(lpszPath
);
711 /*************************************************************************
712 * PathProcessCommandW
714 static LONG
PathProcessCommandW (
720 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
721 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
722 if(!lpszPath
) return -1;
723 if(lpszBuff
) strcpyW(lpszBuff
, lpszPath
);
724 return strlenW(lpszPath
);
727 /*************************************************************************
728 * PathProcessCommand (SHELL32.653)
730 LONG WINAPI
PathProcessCommandAW (
736 if (SHELL_OsIsUnicode())
737 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
738 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
742 ########## special ##########
745 /*************************************************************************
746 * PathSetDlgItemPath (SHELL32.48)
748 VOID WINAPI
PathSetDlgItemPathAW(HWND hDlg
, int id
, LPCVOID pszPath
)
750 if (SHELL_OsIsUnicode())
751 PathSetDlgItemPathW(hDlg
, id
, pszPath
);
753 PathSetDlgItemPathA(hDlg
, id
, pszPath
);
756 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'};
757 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'};
758 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
759 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
760 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
761 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'};
762 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
763 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
764 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
765 static const WCHAR Common_FavoritesW
[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
766 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
767 static const WCHAR CommonFilesDirX86W
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
768 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
769 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
770 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
771 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
772 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
773 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
774 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
775 static const WCHAR ContactsW
[] = {'C','o','n','t','a','c','t','s','\0'};
776 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
777 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
778 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
779 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
780 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
781 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
782 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
783 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
784 static const WCHAR My_VideoW
[] = {'M','y',' ','V','i','d','e','o','s','\0'};
785 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
786 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
787 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
788 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
789 static const WCHAR ProgramFilesDirX86W
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
790 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
791 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
792 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
793 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
794 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
795 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
796 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
797 static const WCHAR UsersW
[] = {'U','s','e','r','s','\0'};
798 static const WCHAR UsersPublicW
[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
799 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
800 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
801 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
802 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
803 static const WCHAR ProfileListW
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','P','r','o','f','i','l','e','L','i','s','t',0};
804 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
805 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
806 static const WCHAR szSHFolders
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
807 static const WCHAR szSHUserFolders
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','U','s','e','r',' ','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
808 static const WCHAR szDefaultProfileDirW
[] = {'u','s','e','r','s',0};
809 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'};
810 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};
811 static const WCHAR AllUsersW
[] = {'P','u','b','l','i','c',0};
813 typedef enum _CSIDL_Type
{
817 CSIDL_Type_Disallowed
,
818 CSIDL_Type_NonExistent
,
819 CSIDL_Type_WindowsPath
,
820 CSIDL_Type_SystemPath
,
821 CSIDL_Type_SystemX86Path
,
826 const KNOWNFOLDERID
*id
;
829 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
832 static const CSIDL_DATA CSIDL_Data
[] =
834 { /* 0x00 - CSIDL_DESKTOP */
838 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
840 { /* 0x01 - CSIDL_INTERNET */
841 &FOLDERID_InternetFolder
,
842 CSIDL_Type_Disallowed
,
846 { /* 0x02 - CSIDL_PROGRAMS */
850 MAKEINTRESOURCEW(IDS_PROGRAMS
)
852 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
853 &FOLDERID_ControlPanelFolder
,
854 CSIDL_Type_SystemPath
,
858 { /* 0x04 - CSIDL_PRINTERS */
859 &FOLDERID_PrintersFolder
,
860 CSIDL_Type_SystemPath
,
864 { /* 0x05 - CSIDL_PERSONAL */
868 MAKEINTRESOURCEW(IDS_PERSONAL
)
870 { /* 0x06 - CSIDL_FAVORITES */
874 MAKEINTRESOURCEW(IDS_FAVORITES
)
876 { /* 0x07 - CSIDL_STARTUP */
880 MAKEINTRESOURCEW(IDS_STARTUP
)
882 { /* 0x08 - CSIDL_RECENT */
886 MAKEINTRESOURCEW(IDS_RECENT
)
888 { /* 0x09 - CSIDL_SENDTO */
892 MAKEINTRESOURCEW(IDS_SENDTO
)
894 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
895 &FOLDERID_RecycleBinFolder
,
896 CSIDL_Type_Disallowed
,
900 { /* 0x0b - CSIDL_STARTMENU */
904 MAKEINTRESOURCEW(IDS_STARTMENU
)
906 { /* 0x0c - CSIDL_MYDOCUMENTS */
908 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
912 { /* 0x0d - CSIDL_MYMUSIC */
916 MAKEINTRESOURCEW(IDS_MYMUSIC
)
918 { /* 0x0e - CSIDL_MYVIDEO */
922 MAKEINTRESOURCEW(IDS_MYVIDEO
)
924 { /* 0x0f - unassigned */
926 CSIDL_Type_Disallowed
,
930 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
934 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
936 { /* 0x11 - CSIDL_DRIVES */
937 &FOLDERID_ComputerFolder
,
938 CSIDL_Type_Disallowed
,
942 { /* 0x12 - CSIDL_NETWORK */
943 &FOLDERID_NetworkFolder
,
944 CSIDL_Type_Disallowed
,
948 { /* 0x13 - CSIDL_NETHOOD */
952 MAKEINTRESOURCEW(IDS_NETHOOD
)
954 { /* 0x14 - CSIDL_FONTS */
956 CSIDL_Type_WindowsPath
,
960 { /* 0x15 - CSIDL_TEMPLATES */
964 MAKEINTRESOURCEW(IDS_TEMPLATES
)
966 { /* 0x16 - CSIDL_COMMON_STARTMENU */
967 &FOLDERID_CommonStartMenu
,
970 MAKEINTRESOURCEW(IDS_STARTMENU
)
972 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
973 &FOLDERID_CommonPrograms
,
976 MAKEINTRESOURCEW(IDS_PROGRAMS
)
978 { /* 0x18 - CSIDL_COMMON_STARTUP */
979 &FOLDERID_CommonStartup
,
982 MAKEINTRESOURCEW(IDS_STARTUP
)
984 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
985 &FOLDERID_PublicDesktop
,
988 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
990 { /* 0x1a - CSIDL_APPDATA */
991 &FOLDERID_RoamingAppData
,
994 MAKEINTRESOURCEW(IDS_APPDATA
)
996 { /* 0x1b - CSIDL_PRINTHOOD */
1000 MAKEINTRESOURCEW(IDS_PRINTHOOD
)
1002 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1003 &FOLDERID_LocalAppData
,
1006 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA
)
1008 { /* 0x1d - CSIDL_ALTSTARTUP */
1010 CSIDL_Type_NonExistent
,
1014 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1016 CSIDL_Type_NonExistent
,
1020 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1021 &FOLDERID_Favorites
,
1022 CSIDL_Type_AllUsers
,
1024 MAKEINTRESOURCEW(IDS_FAVORITES
)
1026 { /* 0x20 - CSIDL_INTERNET_CACHE */
1027 &FOLDERID_InternetCache
,
1030 MAKEINTRESOURCEW(IDS_INTERNET_CACHE
)
1032 { /* 0x21 - CSIDL_COOKIES */
1036 MAKEINTRESOURCEW(IDS_COOKIES
)
1038 { /* 0x22 - CSIDL_HISTORY */
1042 MAKEINTRESOURCEW(IDS_HISTORY
)
1044 { /* 0x23 - CSIDL_COMMON_APPDATA */
1045 &FOLDERID_ProgramData
,
1046 CSIDL_Type_AllUsers
,
1048 MAKEINTRESOURCEW(IDS_APPDATA
)
1050 { /* 0x24 - CSIDL_WINDOWS */
1052 CSIDL_Type_WindowsPath
,
1056 { /* 0x25 - CSIDL_SYSTEM */
1058 CSIDL_Type_SystemPath
,
1062 { /* 0x26 - CSIDL_PROGRAM_FILES */
1063 &FOLDERID_ProgramFiles
,
1066 MAKEINTRESOURCEW(IDS_PROGRAM_FILES
)
1068 { /* 0x27 - CSIDL_MYPICTURES */
1072 MAKEINTRESOURCEW(IDS_MYPICTURES
)
1074 { /* 0x28 - CSIDL_PROFILE */
1080 { /* 0x29 - CSIDL_SYSTEMX86 */
1081 &FOLDERID_SystemX86
,
1082 CSIDL_Type_SystemX86Path
,
1086 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1087 &FOLDERID_ProgramFilesX86
,
1089 ProgramFilesDirX86W
,
1090 MAKEINTRESOURCEW(IDS_PROGRAM_FILESX86
)
1092 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1093 &FOLDERID_ProgramFilesCommon
,
1096 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON
)
1098 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1099 &FOLDERID_ProgramFilesCommonX86
,
1102 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMONX86
)
1104 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1105 &FOLDERID_CommonTemplates
,
1106 CSIDL_Type_AllUsers
,
1108 MAKEINTRESOURCEW(IDS_TEMPLATES
)
1110 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1111 &FOLDERID_PublicDocuments
,
1112 CSIDL_Type_AllUsers
,
1114 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS
)
1116 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1117 &FOLDERID_CommonAdminTools
,
1118 CSIDL_Type_AllUsers
,
1119 Common_Administrative_ToolsW
,
1120 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
1122 { /* 0x30 - CSIDL_ADMINTOOLS */
1123 &FOLDERID_AdminTools
,
1125 Administrative_ToolsW
,
1126 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
1128 { /* 0x31 - CSIDL_CONNECTIONS */
1129 &FOLDERID_ConnectionsFolder
,
1130 CSIDL_Type_Disallowed
,
1134 { /* 0x32 - unassigned */
1136 CSIDL_Type_Disallowed
,
1140 { /* 0x33 - unassigned */
1142 CSIDL_Type_Disallowed
,
1146 { /* 0x34 - unassigned */
1148 CSIDL_Type_Disallowed
,
1152 { /* 0x35 - CSIDL_COMMON_MUSIC */
1153 &FOLDERID_PublicMusic
,
1154 CSIDL_Type_AllUsers
,
1156 MAKEINTRESOURCEW(IDS_COMMON_MUSIC
)
1158 { /* 0x36 - CSIDL_COMMON_PICTURES */
1159 &FOLDERID_PublicPictures
,
1160 CSIDL_Type_AllUsers
,
1162 MAKEINTRESOURCEW(IDS_COMMON_PICTURES
)
1164 { /* 0x37 - CSIDL_COMMON_VIDEO */
1165 &FOLDERID_PublicVideos
,
1166 CSIDL_Type_AllUsers
,
1168 MAKEINTRESOURCEW(IDS_COMMON_VIDEO
)
1170 { /* 0x38 - CSIDL_RESOURCES */
1171 &FOLDERID_ResourceDir
,
1172 CSIDL_Type_WindowsPath
,
1176 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1177 &FOLDERID_LocalizedResourcesDir
,
1178 CSIDL_Type_NonExistent
,
1182 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1183 &FOLDERID_CommonOEMLinks
,
1184 CSIDL_Type_AllUsers
,
1186 MAKEINTRESOURCEW(IDS_COMMON_OEM_LINKS
)
1188 { /* 0x3b - CSIDL_CDBURN_AREA */
1189 &FOLDERID_CDBurning
,
1192 MAKEINTRESOURCEW(IDS_CDBURN_AREA
)
1194 { /* 0x3c unassigned */
1196 CSIDL_Type_Disallowed
,
1200 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1202 CSIDL_Type_Disallowed
, /* FIXME */
1206 { /* 0x3e - CSIDL_PROFILES */
1208 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1213 &FOLDERID_AddNewPrograms
,
1214 CSIDL_Type_Disallowed
,
1219 &FOLDERID_AppUpdates
,
1220 CSIDL_Type_Disallowed
,
1225 &FOLDERID_ChangeRemovePrograms
,
1226 CSIDL_Type_Disallowed
,
1231 &FOLDERID_ConflictFolder
,
1232 CSIDL_Type_Disallowed
,
1240 MAKEINTRESOURCEW(IDS_CONTACTS
)
1243 &FOLDERID_DeviceMetadataStore
,
1244 CSIDL_Type_Disallowed
, /* FIXME */
1252 MAKEINTRESOURCEW(IDS_DOCUMENTS
)
1255 &FOLDERID_DocumentsLibrary
,
1256 CSIDL_Type_Disallowed
, /* FIXME */
1261 &FOLDERID_Downloads
,
1264 MAKEINTRESOURCEW(IDS_DOWNLOADS
)
1268 CSIDL_Type_Disallowed
,
1273 &FOLDERID_GameTasks
,
1274 CSIDL_Type_Disallowed
, /* FIXME */
1279 &FOLDERID_HomeGroup
,
1280 CSIDL_Type_Disallowed
,
1285 &FOLDERID_ImplicitAppShortcuts
,
1286 CSIDL_Type_Disallowed
, /* FIXME */
1291 &FOLDERID_Libraries
,
1292 CSIDL_Type_Disallowed
, /* FIXME */
1300 MAKEINTRESOURCEW(IDS_LINKS
)
1303 &FOLDERID_LocalAppDataLow
,
1306 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA_LOW
)
1309 &FOLDERID_MusicLibrary
,
1310 CSIDL_Type_Disallowed
, /* FIXME */
1315 &FOLDERID_OriginalImages
,
1316 CSIDL_Type_Disallowed
, /* FIXME */
1321 &FOLDERID_PhotoAlbums
,
1324 MAKEINTRESOURCEW(IDS_PHOTO_ALBUMS
)
1327 &FOLDERID_PicturesLibrary
,
1328 CSIDL_Type_Disallowed
, /* FIXME */
1333 &FOLDERID_Playlists
,
1336 MAKEINTRESOURCEW(IDS_PLAYLISTS
)
1339 &FOLDERID_ProgramFilesX64
,
1340 CSIDL_Type_NonExistent
,
1345 &FOLDERID_ProgramFilesCommonX64
,
1346 CSIDL_Type_NonExistent
,
1352 CSIDL_Type_CurrVer
, /* FIXME */
1357 &FOLDERID_PublicDownloads
,
1358 CSIDL_Type_AllUsers
,
1360 MAKEINTRESOURCEW(IDS_PUBLIC_DOWNLOADS
)
1363 &FOLDERID_PublicGameTasks
,
1364 CSIDL_Type_AllUsers
,
1366 MAKEINTRESOURCEW(IDS_PUBLIC_GAME_TASKS
)
1369 &FOLDERID_PublicLibraries
,
1370 CSIDL_Type_AllUsers
,
1372 MAKEINTRESOURCEW(IDS_PUBLIC_LIBRARIES
)
1375 &FOLDERID_PublicRingtones
,
1376 CSIDL_Type_AllUsers
,
1378 MAKEINTRESOURCEW(IDS_PUBLIC_RINGTONES
)
1381 &FOLDERID_QuickLaunch
,
1382 CSIDL_Type_Disallowed
, /* FIXME */
1387 &FOLDERID_RecordedTVLibrary
,
1388 CSIDL_Type_Disallowed
, /* FIXME */
1393 &FOLDERID_Ringtones
,
1394 CSIDL_Type_Disallowed
, /* FIXME */
1399 &FOLDERID_SampleMusic
,
1400 CSIDL_Type_AllUsers
,
1402 MAKEINTRESOURCEW(IDS_SAMPLE_MUSIC
)
1405 &FOLDERID_SamplePictures
,
1406 CSIDL_Type_AllUsers
,
1408 MAKEINTRESOURCEW(IDS_SAMPLE_PICTURES
)
1411 &FOLDERID_SamplePlaylists
,
1412 CSIDL_Type_AllUsers
,
1414 MAKEINTRESOURCEW(IDS_SAMPLE_PLAYLISTS
)
1417 &FOLDERID_SampleVideos
,
1418 CSIDL_Type_AllUsers
,
1420 MAKEINTRESOURCEW(IDS_SAMPLE_VIDEOS
)
1423 &FOLDERID_SavedGames
,
1426 MAKEINTRESOURCEW(IDS_SAVED_GAMES
)
1429 &FOLDERID_SavedSearches
,
1432 MAKEINTRESOURCEW(IDS_SAVED_SEARCHES
)
1435 &FOLDERID_SEARCH_CSC
,
1436 CSIDL_Type_Disallowed
,
1441 &FOLDERID_SEARCH_MAPI
,
1442 CSIDL_Type_Disallowed
,
1447 &FOLDERID_SearchHome
,
1448 CSIDL_Type_Disallowed
,
1453 &FOLDERID_SidebarDefaultParts
,
1454 CSIDL_Type_Disallowed
, /* FIXME */
1459 &FOLDERID_SidebarParts
,
1460 CSIDL_Type_Disallowed
, /* FIXME */
1465 &FOLDERID_SyncManagerFolder
,
1466 CSIDL_Type_Disallowed
,
1471 &FOLDERID_SyncResultsFolder
,
1472 CSIDL_Type_Disallowed
,
1477 &FOLDERID_SyncSetupFolder
,
1478 CSIDL_Type_Disallowed
,
1483 &FOLDERID_UserPinned
,
1484 CSIDL_Type_Disallowed
, /* FIXME */
1489 &FOLDERID_UserProfiles
,
1492 MAKEINTRESOURCEW(IDS_USER_PROFILES
)
1495 &FOLDERID_UserProgramFiles
,
1496 CSIDL_Type_Disallowed
, /* FIXME */
1501 &FOLDERID_UserProgramFilesCommon
,
1502 CSIDL_Type_Disallowed
, /* FIXME */
1507 &FOLDERID_UsersFiles
,
1508 CSIDL_Type_Disallowed
,
1513 &FOLDERID_UsersLibraries
,
1514 CSIDL_Type_Disallowed
,
1519 &FOLDERID_VideosLibrary
,
1520 CSIDL_Type_Disallowed
, /* FIXME */
1526 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1528 /* Gets the value named value from the registry key
1529 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1530 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1531 * is assumed to be MAX_PATH WCHARs in length.
1532 * If it exists, expands the value and writes the expanded value to
1533 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1534 * Returns successful error code if the value was retrieved from the registry,
1535 * and a failure otherwise.
1537 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1538 LPCWSTR value
, LPWSTR path
)
1541 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1542 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1543 DWORD dwType
, dwPathLen
= MAX_PATH
;
1544 HKEY userShellFolderKey
, shellFolderKey
;
1546 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1551 strcpyW(shellFolderPath
, userPrefix
);
1552 PathAddBackslashW(shellFolderPath
);
1553 strcatW(shellFolderPath
, szSHFolders
);
1554 pShellFolderPath
= shellFolderPath
;
1555 strcpyW(userShellFolderPath
, userPrefix
);
1556 PathAddBackslashW(userShellFolderPath
);
1557 strcatW(userShellFolderPath
, szSHUserFolders
);
1558 pUserShellFolderPath
= userShellFolderPath
;
1562 pUserShellFolderPath
= szSHUserFolders
;
1563 pShellFolderPath
= szSHFolders
;
1566 if (RegCreateKeyW(rootKey
, pShellFolderPath
, &shellFolderKey
))
1568 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1571 if (RegCreateKeyW(rootKey
, pUserShellFolderPath
, &userShellFolderKey
))
1573 TRACE("Failed to create %s\n",
1574 debugstr_w(pUserShellFolderPath
));
1575 RegCloseKey(shellFolderKey
);
1579 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1580 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1584 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1585 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1587 WCHAR szTemp
[MAX_PATH
];
1589 _SHExpandEnvironmentStrings(path
, szTemp
);
1590 lstrcpynW(path
, szTemp
, MAX_PATH
);
1592 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1593 (strlenW(path
) + 1) * sizeof(WCHAR
));
1594 if (ret
!= ERROR_SUCCESS
)
1595 hr
= HRESULT_FROM_WIN32(ret
);
1601 RegCloseKey(shellFolderKey
);
1602 RegCloseKey(userShellFolderKey
);
1603 TRACE("returning 0x%08x\n", hr
);
1607 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1608 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1609 * - The entry's szDefaultPath may be either a string value or an integer
1610 * resource identifier. In the latter case, the string value of the resource
1612 * - Depending on the entry's type, the path may begin with an (unexpanded)
1613 * environment variable name. The caller is responsible for expanding
1614 * environment strings if so desired.
1615 * The types that are prepended with environment variables are:
1616 * CSIDL_Type_User: %USERPROFILE%
1617 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1618 * CSIDL_Type_CurrVer: %SystemDrive%
1619 * (Others might make sense too, but as yet are unneeded.)
1621 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1624 WCHAR resourcePath
[MAX_PATH
];
1625 LPCWSTR pDefaultPath
= NULL
;
1627 TRACE("0x%02x,%p\n", folder
, pszPath
);
1629 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1630 return E_INVALIDARG
;
1632 return E_INVALIDARG
;
1640 case CSIDL_PROGRAM_FILES
:
1641 case CSIDL_PROGRAM_FILESX86
:
1642 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1643 folder
= is_wow64
? CSIDL_PROGRAM_FILESX86
: CSIDL_PROGRAM_FILES
;
1645 case CSIDL_PROGRAM_FILES_COMMON
:
1646 case CSIDL_PROGRAM_FILES_COMMONX86
:
1647 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1648 folder
= is_wow64
? CSIDL_PROGRAM_FILES_COMMONX86
: CSIDL_PROGRAM_FILES_COMMON
;
1653 if (CSIDL_Data
[folder
].szDefaultPath
&&
1654 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1656 if (LoadStringW(shell32_hInstance
,
1657 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1660 pDefaultPath
= resourcePath
;
1664 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1665 debugstr_w(pszPath
));
1672 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1676 switch (CSIDL_Data
[folder
].type
)
1678 case CSIDL_Type_User
:
1679 strcpyW(pszPath
, UserProfileW
);
1681 case CSIDL_Type_AllUsers
:
1682 strcpyW(pszPath
, AllUsersProfileW
);
1684 case CSIDL_Type_CurrVer
:
1685 strcpyW(pszPath
, SystemDriveW
);
1688 ; /* no corresponding env. var, do nothing */
1692 PathAddBackslashW(pszPath
);
1693 strcatW(pszPath
, pDefaultPath
);
1696 TRACE("returning 0x%08x\n", hr
);
1700 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1701 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1702 * can be overridden in the HKLM\\szCurrentVersion key.
1703 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1704 * the registry, uses _SHGetDefaultValue to get the value.
1706 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1711 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1713 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1714 return E_INVALIDARG
;
1715 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1716 return E_INVALIDARG
;
1718 return E_INVALIDARG
;
1720 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1721 hr
= _SHGetDefaultValue(folder
, pszPath
);
1726 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hKey
))
1730 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1732 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1733 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1734 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1736 hr
= _SHGetDefaultValue(folder
, pszPath
);
1737 dwType
= REG_EXPAND_SZ
;
1740 case CSIDL_PROGRAM_FILESX86
:
1741 case CSIDL_PROGRAM_FILES_COMMONX86
:
1742 /* these two should never be set on 32-bit setups */
1746 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1747 if (!is_wow64
) break;
1751 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1752 (LPBYTE
)pszPath
, (strlenW(pszPath
)+1)*sizeof(WCHAR
));
1757 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1763 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1767 static LPWSTR
_GetUserSidStringFromToken(HANDLE Token
)
1769 char InfoBuffer
[64];
1770 PTOKEN_USER UserInfo
;
1774 UserInfo
= (PTOKEN_USER
) InfoBuffer
;
1775 if (! GetTokenInformation(Token
, TokenUser
, InfoBuffer
, sizeof(InfoBuffer
),
1778 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1780 UserInfo
= HeapAlloc(GetProcessHeap(), 0, InfoSize
);
1781 if (UserInfo
== NULL
)
1783 if (! GetTokenInformation(Token
, TokenUser
, UserInfo
, InfoSize
,
1786 HeapFree(GetProcessHeap(), 0, UserInfo
);
1791 if (! ConvertSidToStringSidW(UserInfo
->User
.Sid
, &SidStr
))
1794 if (UserInfo
!= (PTOKEN_USER
) InfoBuffer
)
1795 HeapFree(GetProcessHeap(), 0, UserInfo
);
1800 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1801 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1802 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1803 * - if hToken is -1, looks in HKEY_USERS\.Default
1804 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1805 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1806 * calls _SHGetDefaultValue for it.
1808 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1813 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1815 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1816 return E_INVALIDARG
;
1817 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1818 return E_INVALIDARG
;
1820 return E_INVALIDARG
;
1822 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1824 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
1826 FIXME("unsupported for user other than current or default\n");
1829 hr
= _SHGetDefaultValue(folder
, pszPath
);
1833 LPCWSTR userPrefix
= NULL
;
1836 if (hToken
== (HANDLE
)-1)
1838 hRootKey
= HKEY_USERS
;
1839 userPrefix
= DefaultW
;
1841 else if (hToken
== NULL
)
1842 hRootKey
= HKEY_CURRENT_USER
;
1845 hRootKey
= HKEY_USERS
;
1846 userPrefix
= _GetUserSidStringFromToken(hToken
);
1847 if (userPrefix
== NULL
)
1853 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
,
1854 CSIDL_Data
[folder
].szValueName
, pszPath
);
1855 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1856 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1857 CSIDL_Data
[folder
].szValueName
, pszPath
);
1859 hr
= _SHGetDefaultValue(folder
, pszPath
);
1860 if (userPrefix
!= NULL
&& userPrefix
!= DefaultW
)
1861 LocalFree((HLOCAL
) userPrefix
);
1864 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1868 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1869 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1870 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1871 * If this fails, falls back to _SHGetDefaultValue.
1873 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1878 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1880 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1881 return E_INVALIDARG
;
1882 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1883 return E_INVALIDARG
;
1885 return E_INVALIDARG
;
1887 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1888 hr
= _SHGetDefaultValue(folder
, pszPath
);
1891 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1892 CSIDL_Data
[folder
].szValueName
, pszPath
);
1894 hr
= _SHGetDefaultValue(folder
, pszPath
);
1896 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1900 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
1905 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, NULL
, 0,
1906 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
1907 return HRESULT_FROM_WIN32(lRet
);
1910 /* Reads the value named szValueName from the key profilesKey (assumed to be
1911 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1912 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1913 * szDefault to the registry).
1915 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
1916 LPWSTR szValue
, LPCWSTR szDefault
)
1919 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1922 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
1923 debugstr_w(szDefault
));
1924 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
1925 (LPBYTE
)szValue
, &dwPathLen
);
1926 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
1929 dwPathLen
/= sizeof(WCHAR
);
1930 szValue
[dwPathLen
] = '\0';
1935 /* Missing or invalid value, set a default */
1936 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
1937 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
1938 debugstr_w(szValue
));
1939 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
1941 (strlenW(szValue
) + 1) * sizeof(WCHAR
));
1943 hr
= HRESULT_FROM_WIN32(lRet
);
1947 TRACE("returning 0x%08x (output value is %s)\n", hr
, debugstr_w(szValue
));
1951 /* Attempts to expand environment variables from szSrc into szDest, which is
1952 * assumed to be MAX_PATH characters in length. Before referring to the
1953 * environment, handles a few variables directly, because the environment
1954 * variables may not be set when this is called (as during Wine's installation
1955 * when default values are being written to the registry).
1956 * The directly handled environment variables, and their source, are:
1957 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1958 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1960 * If one of the directly handled environment variables is expanded, only
1961 * expands a single variable, and only in the beginning of szSrc.
1963 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
1966 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
1969 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
1971 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
1973 /* short-circuit if there's nothing to expand */
1974 if (szSrc
[0] != '%')
1976 strcpyW(szDest
, szSrc
);
1980 /* Get the profile prefix, we'll probably be needing it */
1981 hr
= _SHOpenProfilesKey(&key
);
1984 WCHAR def_val
[MAX_PATH
];
1986 /* get the system drive */
1987 GetSystemDirectoryW(def_val
, MAX_PATH
);
1988 if (def_val
[1] == ':') strcpyW( def_val
+ 3, szDefaultProfileDirW
);
1989 else FIXME("non-drive system paths unsupported\n");
1991 hr
= _SHGetProfilesValue(key
, ProfilesDirectoryW
, szProfilesPrefix
, def_val
);
1995 strcpyW(szTemp
, szSrc
);
1996 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
1998 if (!strncmpiW(szTemp
, AllUsersProfileW
, strlenW(AllUsersProfileW
)))
2000 WCHAR szAllUsers
[MAX_PATH
];
2002 strcpyW(szDest
, szProfilesPrefix
);
2003 hr
= _SHGetProfilesValue(key
, AllUsersProfileValueW
,
2004 szAllUsers
, AllUsersW
);
2005 PathAppendW(szDest
, szAllUsers
);
2006 PathAppendW(szDest
, szTemp
+ strlenW(AllUsersProfileW
));
2008 else if (!strncmpiW(szTemp
, UserProfileW
, strlenW(UserProfileW
)))
2010 WCHAR userName
[MAX_PATH
];
2011 DWORD userLen
= MAX_PATH
;
2013 strcpyW(szDest
, szProfilesPrefix
);
2014 GetUserNameW(userName
, &userLen
);
2015 PathAppendW(szDest
, userName
);
2016 PathAppendW(szDest
, szTemp
+ strlenW(UserProfileW
));
2018 else if (!strncmpiW(szTemp
, SystemDriveW
, strlenW(SystemDriveW
)))
2020 GetSystemDirectoryW(szDest
, MAX_PATH
);
2021 if (szDest
[1] != ':')
2023 FIXME("non-drive system paths unsupported\n");
2028 strcpyW(szDest
+ 3, szTemp
+ strlenW(SystemDriveW
) + 1);
2034 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
2037 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
2039 hr
= HRESULT_FROM_WIN32(GetLastError());
2043 if (SUCCEEDED(hr
) && szDest
[0] == '%')
2044 strcpyW(szTemp
, szDest
);
2047 /* terminate loop */
2054 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr
,
2055 debugstr_w(szSrc
), debugstr_w(szDest
));
2059 /*************************************************************************
2060 * SHGetFolderPathW [SHELL32.@]
2062 * Convert nFolder to path.
2066 * Failure: standard HRESULT error codes.
2069 * Most values can be overridden in either
2070 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
2071 * or in the same location in HKLM.
2072 * The "Shell Folders" registry key was used in NT4 and earlier systems.
2073 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
2074 * changes made to it are made to the former key too. This synchronization is
2075 * done on-demand: not until someone requests the value of one of these paths
2076 * (by calling one of the SHGet functions) is the value synchronized.
2077 * Furthermore, the HKCU paths take precedence over the HKLM paths.
2079 HRESULT WINAPI
SHGetFolderPathW(
2080 HWND hwndOwner
, /* [I] owner window */
2081 int nFolder
, /* [I] CSIDL identifying the folder */
2082 HANDLE hToken
, /* [I] access token */
2083 DWORD dwFlags
, /* [I] which path to return */
2084 LPWSTR pszPath
) /* [O] converted path */
2086 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
2087 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
2088 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
2092 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
2093 HWND hwndOwner
, /* [I] owner window */
2094 int nFolder
, /* [I] CSIDL identifying the folder */
2095 HANDLE hToken
, /* [I] access token */
2096 DWORD dwFlags
, /* [I] which path to return */
2097 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
2098 LPSTR pszPath
) /* [O] converted path */
2102 LPWSTR pszSubPathW
= NULL
;
2103 LPWSTR pszPathW
= NULL
;
2104 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2107 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
2109 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2113 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2115 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
2116 * set (null), or an empty string.therefore call it without the parameter set
2117 * if pszSubPath is an empty string
2119 if (pszSubPath
&& pszSubPath
[0]) {
2120 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
2121 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
2123 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2126 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
2129 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
2131 if (SUCCEEDED(hr
) && pszPath
)
2132 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
2135 HeapFree(GetProcessHeap(), 0, pszPathW
);
2136 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
2140 /*************************************************************************
2141 * SHGetFolderPathAndSubDirW [SHELL32.@]
2143 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
2144 HWND hwndOwner
, /* [I] owner window */
2145 int nFolder
, /* [I] CSIDL identifying the folder */
2146 HANDLE hToken
, /* [I] access token */
2147 DWORD dwFlags
, /* [I] which path to return */
2148 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
2149 LPWSTR pszPath
) /* [O] converted path */
2152 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
2153 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2157 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
2159 /* Windows always NULL-terminates the resulting path regardless of success
2160 * or failure, so do so first
2165 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2166 return E_INVALIDARG
;
2167 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
2168 return E_INVALIDARG
;
2170 type
= CSIDL_Data
[folder
].type
;
2173 case CSIDL_Type_Disallowed
:
2176 case CSIDL_Type_NonExistent
:
2179 case CSIDL_Type_WindowsPath
:
2180 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
2181 if (CSIDL_Data
[folder
].szDefaultPath
&&
2182 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2183 *CSIDL_Data
[folder
].szDefaultPath
)
2185 PathAddBackslashW(szTemp
);
2186 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2190 case CSIDL_Type_SystemPath
:
2191 GetSystemDirectoryW(szTemp
, MAX_PATH
);
2192 if (CSIDL_Data
[folder
].szDefaultPath
&&
2193 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2194 *CSIDL_Data
[folder
].szDefaultPath
)
2196 PathAddBackslashW(szTemp
);
2197 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2201 case CSIDL_Type_SystemX86Path
:
2202 if (!GetSystemWow64DirectoryW(szTemp
, MAX_PATH
)) GetSystemDirectoryW(szTemp
, MAX_PATH
);
2203 if (CSIDL_Data
[folder
].szDefaultPath
&&
2204 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2205 *CSIDL_Data
[folder
].szDefaultPath
)
2207 PathAddBackslashW(szTemp
);
2208 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2212 case CSIDL_Type_CurrVer
:
2213 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
2215 case CSIDL_Type_User
:
2216 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
2218 case CSIDL_Type_AllUsers
:
2219 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
2222 FIXME("bogus type %d, please fix\n", type
);
2227 /* Expand environment strings if necessary */
2229 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
2231 strcpyW(szBuildPath
, szTemp
);
2233 if (FAILED(hr
)) goto end
;
2236 /* make sure the new path does not exceed th bufferlength
2237 * rememebr to backslash and the termination */
2238 if(MAX_PATH
< (lstrlenW(szBuildPath
) + lstrlenW(pszSubPath
) + 2)) {
2239 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
2242 PathAppendW(szBuildPath
, pszSubPath
);
2243 PathRemoveBackslashW(szBuildPath
);
2245 /* Copy the path if it's available before we might return */
2246 if (SUCCEEDED(hr
) && pszPath
)
2247 strcpyW(pszPath
, szBuildPath
);
2249 /* if we don't care about existing directories we are ready */
2250 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
2252 if (PathFileExistsW(szBuildPath
)) goto end
;
2254 /* not existing but we are not allowed to create it. The return value
2255 * is verified against shell32 version 6.0.
2257 if (!(nFolder
& CSIDL_FLAG_CREATE
))
2259 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2263 /* create directory/directories */
2264 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
2265 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
2267 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
2272 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
2274 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
2278 /*************************************************************************
2279 * SHGetFolderPathA [SHELL32.@]
2281 * See SHGetFolderPathW.
2283 HRESULT WINAPI
SHGetFolderPathA(
2290 WCHAR szTemp
[MAX_PATH
];
2293 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
2297 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
2298 if (SUCCEEDED(hr
) && pszPath
)
2299 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
2305 /* For each folder in folders, if its value has not been set in the registry,
2306 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
2307 * folder's type) to get the unexpanded value first.
2308 * Writes the unexpanded value to User Shell Folders, and queries it with
2309 * SHGetFolderPathW to force the creation of the directory if it doesn't
2310 * already exist. SHGetFolderPathW also returns the expanded value, which
2311 * this then writes to Shell Folders.
2313 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
2314 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
2318 WCHAR path
[MAX_PATH
];
2320 HKEY hUserKey
= NULL
, hKey
= NULL
;
2321 DWORD dwType
, dwPathLen
;
2324 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
2325 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
2327 ret
= RegCreateKeyW(hRootKey
, szUserShellFolderPath
, &hUserKey
);
2329 hr
= HRESULT_FROM_WIN32(ret
);
2332 ret
= RegCreateKeyW(hRootKey
, szShellFolderPath
, &hKey
);
2334 hr
= HRESULT_FROM_WIN32(ret
);
2336 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
2338 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2339 if (RegQueryValueExW(hUserKey
, CSIDL_Data
[folders
[i
]].szValueName
, NULL
,
2340 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
2341 dwType
!= REG_EXPAND_SZ
))
2344 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2345 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
2347 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
2348 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
2349 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
2351 GetWindowsDirectoryW(path
, MAX_PATH
);
2352 if (CSIDL_Data
[folders
[i
]].szDefaultPath
&&
2353 !IS_INTRESOURCE(CSIDL_Data
[folders
[i
]].szDefaultPath
))
2355 PathAddBackslashW(path
);
2356 strcatW(path
, CSIDL_Data
[folders
[i
]].szDefaultPath
);
2363 ret
= RegSetValueExW(hUserKey
,
2364 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_EXPAND_SZ
,
2365 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2367 hr
= HRESULT_FROM_WIN32(ret
);
2370 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
2371 hToken
, SHGFP_TYPE_DEFAULT
, path
);
2372 ret
= RegSetValueExW(hKey
,
2373 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_SZ
,
2374 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2376 hr
= HRESULT_FROM_WIN32(ret
);
2382 RegCloseKey(hUserKey
);
2386 TRACE("returning 0x%08x\n", hr
);
2390 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
2392 static const UINT folders
[] = {
2403 CSIDL_DESKTOPDIRECTORY
,
2407 CSIDL_LOCAL_APPDATA
,
2408 CSIDL_INTERNET_CACHE
,
2414 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
2415 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
2420 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
2423 hToken
= (HANDLE
)-1;
2424 hRootKey
= HKEY_USERS
;
2425 strcpyW(userShellFolderPath
, DefaultW
);
2426 PathAddBackslashW(userShellFolderPath
);
2427 strcatW(userShellFolderPath
, szSHUserFolders
);
2428 pUserShellFolderPath
= userShellFolderPath
;
2429 strcpyW(shellFolderPath
, DefaultW
);
2430 PathAddBackslashW(shellFolderPath
);
2431 strcatW(shellFolderPath
, szSHFolders
);
2432 pShellFolderPath
= shellFolderPath
;
2437 hRootKey
= HKEY_CURRENT_USER
;
2438 pUserShellFolderPath
= szSHUserFolders
;
2439 pShellFolderPath
= szSHFolders
;
2442 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
2443 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2444 TRACE("returning 0x%08x\n", hr
);
2448 static HRESULT
_SHRegisterCommonShellFolders(void)
2450 static const UINT folders
[] = {
2451 CSIDL_COMMON_STARTMENU
,
2452 CSIDL_COMMON_PROGRAMS
,
2453 CSIDL_COMMON_STARTUP
,
2454 CSIDL_COMMON_DESKTOPDIRECTORY
,
2455 CSIDL_COMMON_FAVORITES
,
2456 CSIDL_COMMON_APPDATA
,
2457 CSIDL_COMMON_TEMPLATES
,
2458 CSIDL_COMMON_DOCUMENTS
,
2459 CSIDL_COMMON_ADMINTOOLS
,
2461 CSIDL_COMMON_PICTURES
,
2467 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
2468 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2469 TRACE("returning 0x%08x\n", hr
);
2473 /******************************************************************************
2474 * _SHAppendToUnixPath [Internal]
2476 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
2477 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
2478 * and replaces backslashes with slashes.
2481 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
2482 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
2488 static inline BOOL
_SHAppendToUnixPath(char *szBasePath
, LPCWSTR pwszSubPath
) {
2489 WCHAR wszSubPath
[MAX_PATH
];
2490 int cLen
= strlen(szBasePath
);
2493 if (IS_INTRESOURCE(pwszSubPath
)) {
2494 if (!LoadStringW(shell32_hInstance
, LOWORD(pwszSubPath
), wszSubPath
, MAX_PATH
)) {
2495 /* Fall back to hard coded defaults. */
2496 switch (LOWORD(pwszSubPath
)) {
2498 lstrcpyW(wszSubPath
, PersonalW
);
2501 lstrcpyW(wszSubPath
, My_MusicW
);
2503 case IDS_MYPICTURES
:
2504 lstrcpyW(wszSubPath
, My_PicturesW
);
2507 lstrcpyW(wszSubPath
, My_VideoW
);
2510 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath
));
2515 lstrcpyW(wszSubPath
, pwszSubPath
);
2518 if (szBasePath
[cLen
-1] != '/') szBasePath
[cLen
++] = '/';
2520 if (!WideCharToMultiByte(CP_UNIXCP
, 0, wszSubPath
, -1, szBasePath
+ cLen
,
2521 FILENAME_MAX
- cLen
, NULL
, NULL
))
2526 pBackslash
= szBasePath
+ cLen
;
2527 while ((pBackslash
= strchr(pBackslash
, '\\'))) *pBackslash
= '/';
2532 /******************************************************************************
2533 * _SHCreateSymbolicLinks [Internal]
2535 * Sets up symbol links for various shell folders to point into the users home
2536 * directory. We do an educated guess about what the user would probably want:
2537 * - If there is a 'My Documents' directory in $HOME, the user probably wants
2538 * wine's 'My Documents' to point there. Furthermore, we imply that the user
2539 * is a Windows lover and has no problem with wine creating 'My Pictures',
2540 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
2541 * do not already exits. We put appropriate symbolic links in place for those,
2543 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2544 * point directly to $HOME. We assume the user to be a unix hacker who does not
2545 * want wine to create anything anywhere besides the .wine directory. So, if
2546 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2547 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
2548 * directory, and try to link to that. If that fails, then we symlink to
2549 * $HOME directly. The same holds fo 'My Pictures' and 'My Video'.
2550 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
2551 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
2553 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2555 static void _SHCreateSymbolicLinks(void)
2557 UINT aidsMyStuff
[] = { IDS_MYPICTURES
, IDS_MYVIDEO
, IDS_MYMUSIC
}, i
;
2558 int acsidlMyStuff
[] = { CSIDL_MYPICTURES
, CSIDL_MYVIDEO
, CSIDL_MYMUSIC
};
2559 static const char * const xdg_dirs
[] = { "PICTURES", "VIDEOS", "MUSIC", "DESKTOP" };
2560 static const unsigned int num
= sizeof(xdg_dirs
) / sizeof(xdg_dirs
[0]);
2561 WCHAR wszTempPath
[MAX_PATH
];
2562 char szPersonalTarget
[FILENAME_MAX
], *pszPersonal
;
2563 char szMyStuffTarget
[FILENAME_MAX
], *pszMyStuff
;
2564 char szDesktopTarget
[FILENAME_MAX
], *pszDesktop
;
2565 struct stat statFolder
;
2566 const char *pszHome
;
2568 char ** xdg_results
;
2569 char * xdg_desktop_dir
;
2571 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2572 hr
= SHGetFolderPathW(NULL
, CSIDL_PERSONAL
|CSIDL_FLAG_CREATE
, NULL
,
2573 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2574 if (FAILED(hr
)) return;
2575 pszPersonal
= wine_get_unix_file_name(wszTempPath
);
2576 if (!pszPersonal
) return;
2578 hr
= XDG_UserDirLookup(xdg_dirs
, num
, &xdg_results
);
2579 if (FAILED(hr
)) xdg_results
= NULL
;
2581 pszHome
= getenv("HOME");
2582 if (pszHome
&& !stat(pszHome
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)) {
2583 strcpy(szPersonalTarget
, pszHome
);
2584 if (_SHAppendToUnixPath(szPersonalTarget
, MAKEINTRESOURCEW(IDS_PERSONAL
)) &&
2585 !stat(szPersonalTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2587 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2588 * 'My Music' subfolders or fail silently if they already exist. */
2589 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2590 strcpy(szMyStuffTarget
, szPersonalTarget
);
2591 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2592 mkdir(szMyStuffTarget
, 0777);
2597 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2598 strcpy(szPersonalTarget
, pszHome
);
2601 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2603 symlink(szPersonalTarget
, pszPersonal
);
2607 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2608 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2609 strcpy(szPersonalTarget
, pszPersonal
);
2610 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2611 strcpy(szMyStuffTarget
, szPersonalTarget
);
2612 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2613 mkdir(szMyStuffTarget
, 0777);
2617 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
2618 for (i
=0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2619 /* Create the current 'My Whatever' folder and get it's unix path. */
2620 hr
= SHGetFolderPathW(NULL
, acsidlMyStuff
[i
]|CSIDL_FLAG_CREATE
, NULL
,
2621 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2622 if (FAILED(hr
)) continue;
2623 pszMyStuff
= wine_get_unix_file_name(wszTempPath
);
2624 if (!pszMyStuff
) continue;
2626 strcpy(szMyStuffTarget
, szPersonalTarget
);
2627 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])) &&
2628 !stat(szMyStuffTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2630 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2632 symlink(szMyStuffTarget
, pszMyStuff
);
2637 if (xdg_results
&& xdg_results
[i
])
2639 /* the folder specified by XDG_XXX_DIR exists, link to it. */
2640 symlink(xdg_results
[i
], pszMyStuff
);
2644 /* Else link to where 'My Documents' itself links to. */
2645 symlink(szPersonalTarget
, pszMyStuff
);
2648 HeapFree(GetProcessHeap(), 0, pszMyStuff
);
2651 /* Last but not least, the Desktop folder */
2653 strcpy(szDesktopTarget
, pszHome
);
2655 strcpy(szDesktopTarget
, pszPersonal
);
2656 HeapFree(GetProcessHeap(), 0, pszPersonal
);
2658 xdg_desktop_dir
= xdg_results
? xdg_results
[num
- 1] : NULL
;
2659 if (xdg_desktop_dir
||
2660 (_SHAppendToUnixPath(szDesktopTarget
, DesktopW
) &&
2661 !stat(szDesktopTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)))
2663 hr
= SHGetFolderPathW(NULL
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, NULL
,
2664 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2665 if (SUCCEEDED(hr
) && (pszDesktop
= wine_get_unix_file_name(wszTempPath
)))
2668 if (xdg_desktop_dir
)
2669 symlink(xdg_desktop_dir
, pszDesktop
);
2671 symlink(szDesktopTarget
, pszDesktop
);
2672 HeapFree(GetProcessHeap(), 0, pszDesktop
);
2676 /* Free resources allocated by XDG_UserDirLookup() */
2679 for (i
= 0; i
< num
; i
++)
2680 HeapFree(GetProcessHeap(), 0, xdg_results
[i
]);
2681 HeapFree(GetProcessHeap(), 0, xdg_results
);
2685 /******************************************************************************
2686 * create_extra_folders [Internal]
2688 * Create some extra folders that don't have a standard CSIDL definition.
2690 static HRESULT
create_extra_folders(void)
2692 static const WCHAR environW
[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
2693 static const WCHAR TempW
[] = {'T','e','m','p',0};
2694 static const WCHAR TEMPW
[] = {'T','E','M','P',0};
2695 static const WCHAR TMPW
[] = {'T','M','P',0};
2696 WCHAR path
[MAX_PATH
+5];
2699 DWORD type
, size
, ret
;
2701 ret
= RegCreateKeyW( HKEY_CURRENT_USER
, environW
, &hkey
);
2702 if (ret
) return HRESULT_FROM_WIN32( ret
);
2704 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
2705 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
,
2706 SHGFP_TYPE_DEFAULT
, TempW
, path
);
2709 size
= sizeof(path
);
2710 if (RegQueryValueExW( hkey
, TEMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2711 RegSetValueExW( hkey
, TEMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2712 size
= sizeof(path
);
2713 if (RegQueryValueExW( hkey
, TMPW
, NULL
, &type
, (LPBYTE
)path
, &size
))
2714 RegSetValueExW( hkey
, TMPW
, 0, REG_SZ
, (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
) );
2716 RegCloseKey( hkey
);
2721 /******************************************************************************
2722 * set_folder_attributes
2724 * Set the various folder attributes registry keys.
2726 static HRESULT
set_folder_attributes(void)
2728 static const WCHAR clsidW
[] = {'C','L','S','I','D','\\',0 };
2729 static const WCHAR shellfolderW
[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
2730 static const WCHAR wfparsingW
[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
2731 static const WCHAR wfdisplayW
[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
2732 static const WCHAR hideasdeleteW
[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
2733 static const WCHAR attributesW
[] = {'A','t','t','r','i','b','u','t','e','s',0};
2734 static const WCHAR cfattributesW
[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
2735 static const WCHAR emptyW
[] = {0};
2744 DWORD call_for_attr
;
2747 { &CLSID_UnixFolder
, TRUE
, FALSE
, FALSE
},
2748 { &CLSID_UnixDosFolder
, TRUE
, FALSE
, FALSE
,
2749 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2750 { &CLSID_FolderShortcut
, FALSE
, FALSE
, FALSE
,
2751 SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_LINK
,
2752 SFGAO_HASSUBFOLDER
|SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_FILESYSANCESTOR
},
2753 { &CLSID_MyDocuments
, TRUE
, FALSE
, FALSE
,
2754 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
2755 { &CLSID_RecycleBin
, FALSE
, FALSE
, FALSE
,
2756 SFGAO_FOLDER
|SFGAO_DROPTARGET
|SFGAO_HASPROPSHEET
},
2757 { &CLSID_ControlPanel
, FALSE
, TRUE
, TRUE
,
2758 SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
}
2762 WCHAR buffer
[39 + (sizeof(clsidW
) + sizeof(shellfolderW
)) / sizeof(WCHAR
)];
2766 for (i
= 0; i
< sizeof(folders
)/sizeof(folders
[0]); i
++)
2768 strcpyW( buffer
, clsidW
);
2769 StringFromGUID2( folders
[i
].clsid
, buffer
+ strlenW(buffer
), 39 );
2770 strcatW( buffer
, shellfolderW
);
2771 res
= RegCreateKeyExW( HKEY_CLASSES_ROOT
, buffer
, 0, NULL
, 0,
2772 KEY_READ
| KEY_WRITE
, NULL
, &hkey
, NULL
);
2773 if (res
) return HRESULT_FROM_WIN32( res
);
2774 if (folders
[i
].wfparsing
)
2775 res
= RegSetValueExW( hkey
, wfparsingW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2776 if (folders
[i
].wfdisplay
)
2777 res
= RegSetValueExW( hkey
, wfdisplayW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2778 if (folders
[i
].hideasdel
)
2779 res
= RegSetValueExW( hkey
, hideasdeleteW
, 0, REG_SZ
, (const BYTE
*)emptyW
, sizeof(emptyW
) );
2780 if (folders
[i
].attr
)
2781 res
= RegSetValueExW( hkey
, attributesW
, 0, REG_DWORD
,
2782 (const BYTE
*)&folders
[i
].attr
, sizeof(DWORD
));
2783 if (folders
[i
].call_for_attr
)
2784 res
= RegSetValueExW( hkey
, cfattributesW
, 0, REG_DWORD
,
2785 (const BYTE
*)&folders
[i
].call_for_attr
, sizeof(DWORD
));
2786 RegCloseKey( hkey
);
2792 /* Register the default values in the registry, as some apps seem to depend
2793 * on their presence. The set registered was taken from Windows XP.
2795 HRESULT
SHELL_RegisterShellFolders(void)
2799 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2800 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
2801 * _SHRegister*ShellFolders() functions will find everything nice and clean
2802 * and thus will not attempt to create them in the profile directory. */
2803 _SHCreateSymbolicLinks();
2805 hr
= _SHRegisterUserShellFolders(TRUE
);
2807 hr
= _SHRegisterUserShellFolders(FALSE
);
2809 hr
= _SHRegisterCommonShellFolders();
2811 hr
= create_extra_folders();
2813 hr
= set_folder_attributes();
2817 /*************************************************************************
2818 * SHGetSpecialFolderPathA [SHELL32.@]
2820 BOOL WINAPI
SHGetSpecialFolderPathA (
2826 return (SHGetFolderPathA(
2828 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
2831 szPath
)) == S_OK
? TRUE
: FALSE
;
2834 /*************************************************************************
2835 * SHGetSpecialFolderPathW
2837 BOOL WINAPI
SHGetSpecialFolderPathW (
2843 return (SHGetFolderPathW(
2845 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
2848 szPath
)) == S_OK
? TRUE
: FALSE
;
2851 /*************************************************************************
2852 * SHGetSpecialFolderPath (SHELL32.175)
2854 BOOL WINAPI
SHGetSpecialFolderPathAW (
2861 if (SHELL_OsIsUnicode())
2862 return SHGetSpecialFolderPathW (hwndOwner
, szPath
, nFolder
, bCreate
);
2863 return SHGetSpecialFolderPathA (hwndOwner
, szPath
, nFolder
, bCreate
);
2866 /*************************************************************************
2867 * SHGetFolderLocation [SHELL32.@]
2869 * Gets the folder locations from the registry and creates a pidl.
2873 * nFolder [I] CSIDL_xxxxx
2874 * hToken [I] token representing user, or NULL for current user, or -1 for
2876 * dwReserved [I] must be zero
2877 * ppidl [O] PIDL of a special folder
2881 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2884 * Creates missing reg keys and directories.
2885 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2886 * virtual folders that are handled here.
2888 HRESULT WINAPI
SHGetFolderLocation(
2893 LPITEMIDLIST
*ppidl
)
2895 HRESULT hr
= E_INVALIDARG
;
2897 TRACE("%p 0x%08x %p 0x%08x %p\n",
2898 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
2901 return E_INVALIDARG
;
2903 return E_INVALIDARG
;
2905 /* The virtual folders' locations are not user-dependent */
2907 switch (nFolder
& CSIDL_FOLDER_MASK
)
2910 *ppidl
= _ILCreateDesktop();
2913 case CSIDL_PERSONAL
:
2914 *ppidl
= _ILCreateMyDocuments();
2917 case CSIDL_INTERNET
:
2918 *ppidl
= _ILCreateIExplore();
2921 case CSIDL_CONTROLS
:
2922 *ppidl
= _ILCreateControlPanel();
2925 case CSIDL_PRINTERS
:
2926 *ppidl
= _ILCreatePrinters();
2929 case CSIDL_BITBUCKET
:
2930 *ppidl
= _ILCreateBitBucket();
2934 *ppidl
= _ILCreateMyComputer();
2938 *ppidl
= _ILCreateNetwork();
2943 WCHAR szPath
[MAX_PATH
];
2945 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
2946 SHGFP_TYPE_CURRENT
, szPath
);
2951 TRACE("Value=%s\n", debugstr_w(szPath
));
2952 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
2954 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
2956 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2957 * version 6.0 returns E_FAIL for nonexistent paths
2966 TRACE("-- (new pidl %p)\n",*ppidl
);
2970 /*************************************************************************
2971 * SHGetSpecialFolderLocation [SHELL32.@]
2974 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2977 HRESULT WINAPI
SHGetSpecialFolderLocation(
2980 LPITEMIDLIST
* ppidl
)
2982 HRESULT hr
= E_INVALIDARG
;
2984 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
2987 return E_INVALIDARG
;
2989 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);
2993 static int csidl_from_id( const KNOWNFOLDERID
*id
)
2996 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
2997 if (IsEqualGUID( CSIDL_Data
[i
].id
, id
)) return i
;
3001 /*************************************************************************
3002 * SHGetKnownFolderPath [SHELL32.@]
3004 HRESULT WINAPI
SHGetKnownFolderPath(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PWSTR
*path
)
3007 WCHAR folder
[MAX_PATH
];
3008 int index
= csidl_from_id( rfid
);
3010 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid
), flags
, token
, path
);
3013 return E_INVALIDARG
;
3015 if (flags
& KF_FLAG_CREATE
)
3016 index
|= CSIDL_FLAG_CREATE
;
3018 if (flags
& KF_FLAG_DONT_VERIFY
)
3019 index
|= CSIDL_FLAG_DONT_VERIFY
;
3021 if (flags
& KF_FLAG_NO_ALIAS
)
3022 index
|= CSIDL_FLAG_NO_ALIAS
;
3024 if (flags
& KF_FLAG_INIT
)
3025 index
|= CSIDL_FLAG_PER_USER_INIT
;
3027 if (flags
& ~(KF_FLAG_CREATE
|KF_FLAG_DONT_VERIFY
|KF_FLAG_NO_ALIAS
|KF_FLAG_INIT
))
3029 FIXME("flags 0x%08x not supported\n", flags
);
3030 return E_INVALIDARG
;
3033 hr
= SHGetFolderPathW( NULL
, index
, token
, 0, folder
);
3036 *path
= CoTaskMemAlloc( (strlenW( folder
) + 1) * sizeof(WCHAR
) );
3038 return E_OUTOFMEMORY
;
3039 strcpyW( *path
, folder
);
3044 /*************************************************************************
3045 * SHGetFolderPathEx [SHELL32.@]
3047 HRESULT WINAPI
SHGetFolderPathEx(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, LPWSTR path
, DWORD len
)
3052 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid
), flags
, token
, path
, len
);
3054 if (!path
|| !len
) return E_INVALIDARG
;
3056 hr
= SHGetKnownFolderPath( rfid
, flags
, token
, &buffer
);
3057 if (SUCCEEDED( hr
))
3059 if (strlenW( buffer
) + 1 > len
)
3061 CoTaskMemFree( buffer
);
3062 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER
);
3064 strcpyW( path
, buffer
);
3065 CoTaskMemFree( buffer
);
3070 /* constant values used by known folder functions */
3071 static const WCHAR szCategory
[] = {'C','a','t','e','g','o','r','y',0};
3072 static const WCHAR szName
[] = {'N','a','m','e',0};
3073 static const WCHAR szRelativePath
[] = {'R','e','l','a','t','i','v','e','P','a','t','h',0};
3074 static const WCHAR szParentFolder
[] = {'P','a','r','e','n','t','F','o','l','d','e','r',0};
3077 * Internal function to convert known folder identifier to path of registry key
3078 * associated with known folder.
3081 * rfid [I] pointer to known folder identifier (may be NULL)
3082 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
3083 * lpPath [O] place to store string address. String should be
3084 * later freed using HeapFree(GetProcessHeap(),0, ... )
3086 static HRESULT
get_known_folder_registry_path(
3087 REFKNOWNFOLDERID rfid
,
3088 LPWSTR lpStringGuid
,
3091 static const WCHAR sBackslash
[] = {'\\',0};
3096 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid
), debugstr_w(lpStringGuid
), lpPath
);
3099 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3101 lstrcpyW(sGuid
, lpStringGuid
);
3103 length
= lstrlenW(szKnownFolderDescriptions
)+51;
3104 *lpPath
= HeapAlloc(GetProcessHeap(), 0, length
*sizeof(WCHAR
));
3110 lstrcpyW(*lpPath
, szKnownFolderDescriptions
);
3111 lstrcatW(*lpPath
, sBackslash
);
3112 lstrcatW(*lpPath
, sGuid
);
3119 * Internal function to get place where folder redirection information are stored.
3122 * rfid [I] pointer to known folder identifier (may be NULL)
3123 * rootKey [O] root key where the redirection information are stored
3124 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
3125 * However, besides root key, path is always that same, and is stored
3126 * as "szKnownFolderRedirections" constant
3128 static HRESULT
get_known_folder_redirection_place(
3129 REFKNOWNFOLDERID rfid
,
3133 LPWSTR lpRegistryPath
= NULL
;
3134 KF_CATEGORY category
;
3137 /* first, get known folder's category */
3138 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3142 dwSize
= sizeof(category
);
3143 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, lpRegistryPath
, szCategory
, RRF_RT_DWORD
, NULL
, &category
, &dwSize
));
3148 if(category
== KF_CATEGORY_COMMON
)
3150 *rootKey
= HKEY_LOCAL_MACHINE
;
3153 else if(category
== KF_CATEGORY_PERUSER
)
3155 *rootKey
= HKEY_CURRENT_USER
;
3162 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3166 static HRESULT
get_known_folder_path_by_id(REFKNOWNFOLDERID folderId
, LPWSTR lpRegistryPath
, DWORD dwFlags
, LPWSTR
*ppszPath
);
3168 static HRESULT
get_known_folder_category(
3169 LPWSTR registryPath
,
3170 KF_CATEGORY
* pCategory
)
3172 DWORD dwSize
= sizeof(DWORD
);
3174 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szCategory
, RRF_RT_DWORD
, &dwType
, pCategory
, &dwSize
));
3177 static HRESULT
redirect_known_folder(
3178 REFKNOWNFOLDERID rfid
,
3180 KF_REDIRECT_FLAGS flags
,
3181 LPCWSTR pszTargetPath
,
3183 KNOWNFOLDERID
const *pExclusion
,
3187 HKEY rootKey
= HKEY_LOCAL_MACHINE
, hKey
;
3189 LPWSTR lpRegistryPath
= NULL
, lpSrcPath
= NULL
;
3190 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid
), hwnd
, flags
, debugstr_w(pszTargetPath
), cFolders
, pExclusion
, ppszError
);
3192 if (ppszError
) *ppszError
= NULL
;
3194 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3197 hr
= get_known_folder_path_by_id(rfid
, lpRegistryPath
, 0, &lpSrcPath
);
3199 HeapFree(GetProcessHeap(), 0, lpRegistryPath
);
3201 /* get path to redirection storage */
3203 hr
= get_known_folder_redirection_place(rfid
, &rootKey
);
3205 /* write redirection information */
3207 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey
, szKnownFolderRedirections
, 0, NULL
, 0, KEY_WRITE
, NULL
, &hKey
, NULL
));
3211 StringFromGUID2(rfid
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3213 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, sGuid
, 0, REG_SZ
, (LPBYTE
)pszTargetPath
, (lstrlenW(pszTargetPath
)+1)*sizeof(WCHAR
)));
3218 /* make sure destination path exists */
3219 SHCreateDirectory(NULL
, pszTargetPath
);
3221 /* copy content if required */
3222 if(SUCCEEDED(hr
) && (flags
& KF_REDIRECT_COPY_CONTENTS
) )
3224 static const WCHAR sWildcard
[] = {'\\','*',0};
3225 WCHAR srcPath
[MAX_PATH
+1], dstPath
[MAX_PATH
+1];
3226 SHFILEOPSTRUCTW fileOp
;
3228 ZeroMemory(srcPath
, sizeof(srcPath
));
3229 lstrcpyW(srcPath
, lpSrcPath
);
3230 lstrcatW(srcPath
, sWildcard
);
3232 ZeroMemory(dstPath
, sizeof(dstPath
));
3233 lstrcpyW(dstPath
, pszTargetPath
);
3235 ZeroMemory(&fileOp
, sizeof(fileOp
));
3237 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3238 fileOp
.wFunc
= FO_MOVE
;
3240 fileOp
.wFunc
= FO_COPY
;
3242 fileOp
.pFrom
= srcPath
;
3243 fileOp
.pTo
= dstPath
;
3244 fileOp
.fFlags
= FOF_NO_UI
;
3246 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3248 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3250 ZeroMemory(srcPath
, sizeof(srcPath
));
3251 lstrcpyW(srcPath
, lpSrcPath
);
3253 ZeroMemory(&fileOp
, sizeof(fileOp
));
3254 fileOp
.wFunc
= FO_DELETE
;
3255 fileOp
.pFrom
= srcPath
;
3256 fileOp
.fFlags
= FOF_NO_UI
;
3258 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3262 CoTaskMemFree(lpSrcPath
);
3270 IKnownFolder IKnownFolder_iface
;
3273 LPWSTR registryPath
;
3276 static inline struct knownfolder
*impl_from_IKnownFolder( IKnownFolder
*iface
)
3278 return CONTAINING_RECORD( iface
, struct knownfolder
, IKnownFolder_iface
);
3281 static ULONG WINAPI
knownfolder_AddRef(
3282 IKnownFolder
*iface
)
3284 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3285 return InterlockedIncrement( &knownfolder
->refs
);
3288 static ULONG WINAPI
knownfolder_Release(
3289 IKnownFolder
*iface
)
3291 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3292 LONG refs
= InterlockedDecrement( &knownfolder
->refs
);
3295 TRACE("destroying %p\n", knownfolder
);
3296 HeapFree( GetProcessHeap(), 0, knownfolder
->registryPath
);
3297 HeapFree( GetProcessHeap(), 0, knownfolder
);
3302 static HRESULT WINAPI
knownfolder_QueryInterface(
3303 IKnownFolder
*iface
,
3307 struct knownfolder
*This
= impl_from_IKnownFolder( iface
);
3309 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3311 if ( IsEqualGUID( riid
, &IID_IKnownFolder
) ||
3312 IsEqualGUID( riid
, &IID_IUnknown
) )
3318 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3319 return E_NOINTERFACE
;
3321 IKnownFolder_AddRef( iface
);
3325 static HRESULT
knownfolder_set_id(
3326 struct knownfolder
*knownfolder
,
3327 const KNOWNFOLDERID
*kfid
)
3332 TRACE("%s\n", debugstr_guid(kfid
));
3334 knownfolder
->id
= *kfid
;
3336 /* check is it registry-registered folder */
3337 hr
= get_known_folder_registry_path(kfid
, NULL
, &knownfolder
->registryPath
);
3339 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, 0, 0, &hKey
));
3348 /* This known folder is not registered. To mark it, we set registryPath to NULL */
3349 HeapFree(GetProcessHeap(), 0, knownfolder
->registryPath
);
3350 knownfolder
->registryPath
= NULL
;
3357 static HRESULT WINAPI
knownfolder_GetId(
3358 IKnownFolder
*iface
,
3359 KNOWNFOLDERID
*pkfid
)
3361 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3363 TRACE("%p\n", pkfid
);
3365 *pkfid
= knownfolder
->id
;
3369 static HRESULT WINAPI
knownfolder_GetCategory(
3370 IKnownFolder
*iface
,
3371 KF_CATEGORY
*pCategory
)
3373 struct knownfolder
*knownfolder
= impl_from_IKnownFolder(iface
);
3376 TRACE("%p, %p\n", knownfolder
, pCategory
);
3378 /* we cannot get a category for a folder which is not registered */
3379 if(!knownfolder
->registryPath
)
3383 hr
= get_known_folder_category(knownfolder
->registryPath
, pCategory
);
3388 static HRESULT WINAPI
knownfolder_GetShellItem(
3389 IKnownFolder
*iface
,
3394 FIXME("0x%08x, %s, %p\n", dwFlags
, debugstr_guid(riid
), ppv
);
3398 static HRESULT
get_known_folder_path(
3400 LPWSTR registryPath
,
3403 static const WCHAR sBackslash
[] = {'\\',0};
3405 DWORD dwSize
, dwType
;
3406 WCHAR path
[MAX_PATH
] = {0};
3407 WCHAR parentGuid
[39];
3408 KF_CATEGORY category
;
3409 LPWSTR parentRegistryPath
, parentPath
;
3410 HKEY hRedirectionRootKey
= NULL
;
3412 TRACE("(%s, %p)\n", debugstr_w(registryPath
), ppszPath
);
3415 /* check if folder has parent */
3416 dwSize
= sizeof(parentGuid
);
3417 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szParentFolder
, RRF_RT_REG_SZ
, &dwType
, parentGuid
, &dwSize
));
3418 if(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) hr
= S_FALSE
;
3422 /* get parent's known folder path (recursive) */
3423 hr
= get_known_folder_registry_path(NULL
, parentGuid
, &parentRegistryPath
);
3424 if(FAILED(hr
)) return hr
;
3426 hr
= get_known_folder_path(parentGuid
, parentRegistryPath
, &parentPath
);
3428 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3432 lstrcatW(path
, parentPath
);
3433 lstrcatW(path
, sBackslash
);
3435 HeapFree(GetProcessHeap(), 0, parentRegistryPath
);
3436 HeapFree(GetProcessHeap(), 0, parentPath
);
3439 /* check, if folder was redirected */
3441 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szCategory
, RRF_RT_REG_DWORD
, NULL
, &category
, &dwSize
));
3445 if(category
== KF_CATEGORY_COMMON
)
3446 hRedirectionRootKey
= HKEY_LOCAL_MACHINE
;
3447 else if(category
== KF_CATEGORY_PERUSER
)
3448 hRedirectionRootKey
= HKEY_CURRENT_USER
;
3450 if(hRedirectionRootKey
)
3452 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3456 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3457 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3462 lstrcpyW(*ppszPath
, path
);
3463 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, szKnownFolderRedirections
, sFolderId
, RRF_RT_REG_SZ
, NULL
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3469 /* no redirection, use previous way - read the relative path from folder definition */
3470 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, NULL
, &dwSize
));
3474 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3475 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3480 lstrcpyW(*ppszPath
, path
);
3481 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, szRelativePath
, RRF_RT_REG_SZ
, &dwType
, *ppszPath
+ lstrlenW(path
), &dwSize
));
3486 TRACE("returning path: %s\n", debugstr_w(*ppszPath
));
3490 static HRESULT
get_known_folder_path_by_id(
3491 REFKNOWNFOLDERID folderId
,
3492 LPWSTR lpRegistryPath
,
3500 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId
), debugstr_w(lpRegistryPath
), dwFlags
, ppszPath
);
3502 /* if this is registry-registered known folder, get path from registry */
3505 StringFromGUID2(folderId
, sGuid
, sizeof(sGuid
)/sizeof(sGuid
[0]));
3507 hr
= get_known_folder_path(sGuid
, lpRegistryPath
, ppszPath
);
3509 /* in other case, use older way */
3511 hr
= SHGetKnownFolderPath( folderId
, dwFlags
, NULL
, ppszPath
);
3513 /* check if known folder really exists */
3514 dwAttributes
= GetFileAttributesW(*ppszPath
);
3515 if(dwAttributes
== INVALID_FILE_ATTRIBUTES
|| !(dwAttributes
& FILE_ATTRIBUTE_DIRECTORY
) )
3517 TRACE("directory %s not found\n", debugstr_w(*ppszPath
));
3518 CoTaskMemFree(*ppszPath
);
3520 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
3526 static HRESULT WINAPI
knownfolder_GetPath(
3527 IKnownFolder
*iface
,
3531 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3532 TRACE("(%p, 0x%08x, %p)\n", knownfolder
, dwFlags
, ppszPath
);
3534 return get_known_folder_path_by_id(&knownfolder
->id
, knownfolder
->registryPath
, dwFlags
, ppszPath
);
3537 static HRESULT WINAPI
knownfolder_SetPath(
3538 IKnownFolder
*iface
,
3542 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3545 TRACE("(%p, 0x%08x, %p)\n", knownfolder
, dwFlags
, debugstr_w(pszPath
));
3547 /* check if the known folder is registered */
3548 if(!knownfolder
->registryPath
)
3552 hr
= redirect_known_folder(&knownfolder
->id
, NULL
, 0, pszPath
, 0, NULL
, NULL
);
3557 static HRESULT WINAPI
knownfolder_GetIDList(
3558 IKnownFolder
*iface
,
3560 PIDLIST_ABSOLUTE
*ppidl
)
3562 FIXME("0x%08x, %p\n", dwFlags
, ppidl
);
3566 static HRESULT WINAPI
knownfolder_GetFolderType(
3567 IKnownFolder
*iface
,
3568 FOLDERTYPEID
*pftid
)
3570 FIXME("%p\n", pftid
);
3574 static HRESULT WINAPI
knownfolder_GetRedirectionCapabilities(
3575 IKnownFolder
*iface
,
3576 KF_REDIRECTION_CAPABILITIES
*pCapabilities
)
3578 FIXME("%p\n", pCapabilities
);
3582 static HRESULT WINAPI
knownfolder_GetFolderDefinition(
3583 IKnownFolder
*iface
,
3584 KNOWNFOLDER_DEFINITION
*pKFD
)
3586 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3589 TRACE("(%p, %p)\n", knownfolder
, pKFD
);
3591 if(!pKFD
) return E_INVALIDARG
;
3593 ZeroMemory(pKFD
, sizeof(*pKFD
));
3595 hr
= get_known_folder_category(knownfolder
->registryPath
, &pKFD
->category
);
3598 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, szName
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3602 pKFD
->pszName
= CoTaskMemAlloc(dwSize
);
3603 if(!pKFD
->pszName
) hr
= E_OUTOFMEMORY
;
3607 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, szName
, RRF_RT_REG_SZ
, NULL
, pKFD
->pszName
, &dwSize
));
3612 static const struct IKnownFolderVtbl knownfolder_vtbl
=
3614 knownfolder_QueryInterface
,
3616 knownfolder_Release
,
3618 knownfolder_GetCategory
,
3619 knownfolder_GetShellItem
,
3620 knownfolder_GetPath
,
3621 knownfolder_SetPath
,
3622 knownfolder_GetIDList
,
3623 knownfolder_GetFolderType
,
3624 knownfolder_GetRedirectionCapabilities
,
3625 knownfolder_GetFolderDefinition
3628 static HRESULT
knownfolder_create( struct knownfolder
**knownfolder
)
3630 struct knownfolder
*kf
;
3632 kf
= HeapAlloc( GetProcessHeap(), 0, sizeof(*kf
) );
3633 if (!kf
) return E_OUTOFMEMORY
;
3635 kf
->IKnownFolder_iface
.lpVtbl
= &knownfolder_vtbl
;
3637 memset( &kf
->id
, 0, sizeof(kf
->id
) );
3638 kf
->registryPath
= NULL
;
3642 TRACE("returning iface %p\n", &kf
->IKnownFolder_iface
);
3646 struct foldermanager
3648 IKnownFolderManager IKnownFolderManager_iface
;
3654 static inline struct foldermanager
*impl_from_IKnownFolderManager( IKnownFolderManager
*iface
)
3656 return CONTAINING_RECORD( iface
, struct foldermanager
, IKnownFolderManager_iface
);
3659 static ULONG WINAPI
foldermanager_AddRef(
3660 IKnownFolderManager
*iface
)
3662 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3663 return InterlockedIncrement( &foldermanager
->refs
);
3666 static ULONG WINAPI
foldermanager_Release(
3667 IKnownFolderManager
*iface
)
3669 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
3670 LONG refs
= InterlockedDecrement( &foldermanager
->refs
);
3673 TRACE("destroying %p\n", foldermanager
);
3674 HeapFree( GetProcessHeap(), 0, foldermanager
->ids
);
3675 HeapFree( GetProcessHeap(), 0, foldermanager
);
3680 static HRESULT WINAPI
foldermanager_QueryInterface(
3681 IKnownFolderManager
*iface
,
3685 struct foldermanager
*This
= impl_from_IKnownFolderManager( iface
);
3687 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3689 if ( IsEqualGUID( riid
, &IID_IKnownFolderManager
) ||
3690 IsEqualGUID( riid
, &IID_IUnknown
) )
3696 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3697 return E_NOINTERFACE
;
3699 IKnownFolderManager_AddRef( iface
);
3703 static HRESULT WINAPI
foldermanager_FolderIdFromCsidl(
3704 IKnownFolderManager
*iface
,
3706 KNOWNFOLDERID
*pfid
)
3708 TRACE("%d, %p\n", nCsidl
, pfid
);
3710 if (nCsidl
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
3711 return E_INVALIDARG
;
3712 *pfid
= *CSIDL_Data
[nCsidl
].id
;
3716 static HRESULT WINAPI
foldermanager_FolderIdToCsidl(
3717 IKnownFolderManager
*iface
,
3718 REFKNOWNFOLDERID rfid
,
3723 TRACE("%s, %p\n", debugstr_guid(rfid
), pnCsidl
);
3725 csidl
= csidl_from_id( rfid
);
3726 if (csidl
== -1) return E_INVALIDARG
;
3731 static HRESULT WINAPI
foldermanager_GetFolderIds(
3732 IKnownFolderManager
*iface
,
3733 KNOWNFOLDERID
**ppKFId
,
3736 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
3738 TRACE("%p, %p\n", ppKFId
, pCount
);
3741 *pCount
= fm
->num_ids
;
3745 static BOOL
is_knownfolder( struct foldermanager
*fm
, const KNOWNFOLDERID
*id
)
3749 LPWSTR registryPath
= NULL
;
3752 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
3753 for (i
= 0; i
< fm
->num_ids
; i
++)
3754 if (IsEqualGUID( &fm
->ids
[i
], id
)) return TRUE
;
3756 hr
= get_known_folder_registry_path(id
, NULL
, ®istryPath
);
3758 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, 0, &hKey
));
3769 static HRESULT WINAPI
foldermanager_GetFolder(
3770 IKnownFolderManager
*iface
,
3771 REFKNOWNFOLDERID rfid
,
3772 IKnownFolder
**ppkf
)
3774 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
3775 struct knownfolder
*kf
;
3778 TRACE("%s, %p\n", debugstr_guid(rfid
), ppkf
);
3780 if (!is_knownfolder( fm
, rfid
))
3782 WARN("unknown folder\n");
3783 return E_INVALIDARG
;
3785 hr
= knownfolder_create( &kf
);
3786 if (SUCCEEDED( hr
))
3788 hr
= knownfolder_set_id( kf
, rfid
);
3789 *ppkf
= &kf
->IKnownFolder_iface
;
3797 static HRESULT WINAPI
foldermanager_GetFolderByName(
3798 IKnownFolderManager
*iface
,
3799 LPCWSTR pszCanonicalName
,
3800 IKnownFolder
**ppkf
)
3802 FIXME("%s, %p\n", debugstr_w(pszCanonicalName
), ppkf
);
3806 static HRESULT WINAPI
foldermanager_RegisterFolder(
3807 IKnownFolderManager
*iface
,
3808 REFKNOWNFOLDERID rfid
,
3809 KNOWNFOLDER_DEFINITION
const *pKFD
)
3814 LPWSTR registryPath
= NULL
;
3815 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(rfid
), pKFD
);
3817 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
3818 TRACE("registry path: %s\n", debugstr_w(registryPath
));
3821 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, NULL
, 0, KEY_WRITE
, 0, &hKey
, &dwDisp
));
3825 if(dwDisp
== REG_OPENED_EXISTING_KEY
)
3829 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szCategory
, 0, REG_DWORD
, (LPBYTE
)&pKFD
->category
, sizeof(pKFD
->category
)));
3832 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szName
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszName
, (lstrlenW(pKFD
->pszName
)+1)*sizeof(WCHAR
) ));
3834 if(SUCCEEDED(hr
) && !IsEqualGUID(&pKFD
->fidParent
, &GUID_NULL
))
3836 WCHAR sParentGuid
[39];
3837 StringFromGUID2(&pKFD
->fidParent
, sParentGuid
, sizeof(sParentGuid
)/sizeof(sParentGuid
[0]));
3839 /* this known folder has parent folder */
3840 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szParentFolder
, 0, REG_SZ
, (LPBYTE
)sParentGuid
, sizeof(sParentGuid
)));
3843 if(SUCCEEDED(hr
) && pKFD
->category
!= KF_CATEGORY_VIRTUAL
)
3845 if(!pKFD
->pszRelativePath
)
3849 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, szRelativePath
, 0, REG_SZ
, (LPBYTE
)pKFD
->pszRelativePath
, (lstrlenW(pKFD
->pszRelativePath
)+1)*sizeof(WCHAR
) ));
3855 SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
);
3858 HeapFree(GetProcessHeap(), 0, registryPath
);
3862 static HRESULT WINAPI
foldermanager_UnregisterFolder(
3863 IKnownFolderManager
*iface
,
3864 REFKNOWNFOLDERID rfid
)
3867 LPWSTR registryPath
= NULL
;
3868 TRACE("(%p, %s)\n", iface
, debugstr_guid(rfid
));
3870 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
3873 hr
= HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
));
3875 HeapFree(GetProcessHeap(), 0, registryPath
);
3879 static HRESULT WINAPI
foldermanager_FindFolderFromPath(
3880 IKnownFolderManager
*iface
,
3883 IKnownFolder
**ppkf
)
3885 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath
), mode
, ppkf
);
3889 static HRESULT WINAPI
foldermanager_FindFolderFromIDList(
3890 IKnownFolderManager
*iface
,
3891 PCIDLIST_ABSOLUTE pidl
,
3892 IKnownFolder
**ppkf
)
3894 FIXME("%p, %p\n", pidl
, ppkf
);
3898 static HRESULT WINAPI
foldermanager_Redirect(
3899 IKnownFolderManager
*iface
,
3900 REFKNOWNFOLDERID rfid
,
3902 KF_REDIRECT_FLAGS flags
,
3903 LPCWSTR pszTargetPath
,
3905 KNOWNFOLDERID
const *pExclusion
,
3908 return redirect_known_folder(rfid
, hwnd
, flags
, pszTargetPath
, cFolders
, pExclusion
, ppszError
);
3911 static const struct IKnownFolderManagerVtbl foldermanager_vtbl
=
3913 foldermanager_QueryInterface
,
3914 foldermanager_AddRef
,
3915 foldermanager_Release
,
3916 foldermanager_FolderIdFromCsidl
,
3917 foldermanager_FolderIdToCsidl
,
3918 foldermanager_GetFolderIds
,
3919 foldermanager_GetFolder
,
3920 foldermanager_GetFolderByName
,
3921 foldermanager_RegisterFolder
,
3922 foldermanager_UnregisterFolder
,
3923 foldermanager_FindFolderFromPath
,
3924 foldermanager_FindFolderFromIDList
,
3925 foldermanager_Redirect
3928 static HRESULT
foldermanager_create( void **ppv
)
3931 struct foldermanager
*fm
;
3933 fm
= HeapAlloc( GetProcessHeap(), 0, sizeof(*fm
) );
3934 if (!fm
) return E_OUTOFMEMORY
;
3936 fm
->IKnownFolderManager_iface
.lpVtbl
= &foldermanager_vtbl
;
3940 for (i
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
3942 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
)) fm
->num_ids
++;
3944 fm
->ids
= HeapAlloc( GetProcessHeap(), 0, fm
->num_ids
* sizeof(KNOWNFOLDERID
) );
3947 HeapFree( GetProcessHeap(), 0, fm
);
3948 return E_OUTOFMEMORY
;
3950 for (i
= j
= 0; i
< sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]); i
++)
3952 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
))
3954 fm
->ids
[j
] = *CSIDL_Data
[i
].id
;
3958 TRACE("found %u known folders\n", fm
->num_ids
);
3959 *ppv
= &fm
->IKnownFolderManager_iface
;
3961 TRACE("returning iface %p\n", *ppv
);
3965 HRESULT WINAPI
KnownFolderManager_Constructor( IUnknown
*punk
, REFIID riid
, void **ppv
)
3967 TRACE("%p, %s, %p\n", punk
, debugstr_guid(riid
), ppv
);
3972 return CLASS_E_NOAGGREGATION
;
3974 return foldermanager_create( ppv
);