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
27 #define WIN32_NO_STATUS
31 #include <wine/config.h>
36 #include <undocshell.h>
39 #include <wine/debug.h>
40 #include <wine/unicode.h>
45 #include "shell32_main.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
50 static const BOOL is_win64
= sizeof(void *) > sizeof(int);
52 typedef BOOL(WINAPI
*LPFN_ISWOW64PROCESS
) (HANDLE
, PBOOL
);
54 static LPFN_ISWOW64PROCESS fnIsWow64Process
= NULL
;
58 BOOL bIsWow64
= FALSE
;
60 if (!fnIsWow64Process
)
62 fnIsWow64Process
= (LPFN_ISWOW64PROCESS
) GetProcAddress(
63 GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
66 if (!fnIsWow64Process
)
69 if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64
))
77 ########## Combining and Constructing paths ##########
80 /*************************************************************************
81 * PathAppend [SHELL32.36]
83 BOOL WINAPI
PathAppendAW(
87 if (SHELL_OsIsUnicode())
88 return PathAppendW(lpszPath1
, lpszPath2
);
89 return PathAppendA(lpszPath1
, lpszPath2
);
92 /*************************************************************************
93 * PathGetExtensionA [internal]
97 * return value points to the first char after the dot
99 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
101 TRACE("(%s)\n",lpszPath
);
103 lpszPath
= PathFindExtensionA(lpszPath
);
104 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
107 /*************************************************************************
108 * PathGetExtensionW [internal]
110 static LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
112 TRACE("(%s)\n",debugstr_w(lpszPath
));
114 lpszPath
= PathFindExtensionW(lpszPath
);
115 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
118 /*************************************************************************
119 * SHPathGetExtension [SHELL32.158]
121 LPVOID WINAPI
SHPathGetExtensionW(LPCWSTR lpszPath
, DWORD void1
, DWORD void2
)
123 return PathGetExtensionW(lpszPath
);
126 /*************************************************************************
127 * PathRemoveFileSpec [SHELL32.35]
129 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
131 if (SHELL_OsIsUnicode())
132 return PathRemoveFileSpecW(lpszPath
);
133 return PathRemoveFileSpecA(lpszPath
);
140 /*************************************************************************
141 * PathGetShortPathA [internal]
143 static void PathGetShortPathA(LPSTR pszPath
)
147 TRACE("%s\n", pszPath
);
149 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
151 lstrcpyA(pszPath
, path
);
155 /*************************************************************************
156 * PathGetShortPathW [internal]
158 static void PathGetShortPathW(LPWSTR pszPath
)
160 WCHAR path
[MAX_PATH
];
162 TRACE("%s\n", debugstr_w(pszPath
));
164 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
166 lstrcpyW(pszPath
, path
);
170 /*************************************************************************
171 * PathGetShortPath [SHELL32.92]
173 VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
175 if(SHELL_OsIsUnicode())
176 PathGetShortPathW(pszPath
);
177 PathGetShortPathA(pszPath
);
181 ########## Path Testing ##########
184 /*************************************************************************
185 * PathIsRoot [SHELL32.29]
187 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
189 if (SHELL_OsIsUnicode())
190 return PathIsRootW(lpszPath
);
191 return PathIsRootA(lpszPath
);
194 /*************************************************************************
195 * PathIsExeA [internal]
197 static BOOL
PathIsExeA (LPCSTR lpszPath
)
199 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
201 static const char * const lpszExtensions
[] =
202 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
204 TRACE("path=%s\n",lpszPath
);
206 for(i
=0; lpszExtensions
[i
]; i
++)
207 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
212 /*************************************************************************
213 * PathIsExeW [internal]
215 BOOL
PathIsExeW (LPCWSTR lpszPath
)
217 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
219 static const WCHAR lpszExtensions
[][4] =
220 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
221 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
222 {'s','c','r','\0'}, {'\0'} };
224 TRACE("path=%s\n",debugstr_w(lpszPath
));
226 for(i
=0; lpszExtensions
[i
][0]; i
++)
227 if (!strcmpiW(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
232 /*************************************************************************
233 * PathIsExe [SHELL32.43]
235 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
237 if (SHELL_OsIsUnicode())
238 return PathIsExeW (path
);
239 return PathIsExeA(path
);
242 /*************************************************************************
243 * PathFileExists [SHELL32.45]
245 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
247 if (SHELL_OsIsUnicode())
248 return PathFileExistsW (lpszPath
);
249 return PathFileExistsA (lpszPath
);
252 /*************************************************************************
253 * IsLFNDriveA [SHELL32.41]
255 BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
259 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
264 /*************************************************************************
265 * IsLFNDriveW [SHELL32.42]
267 BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
271 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
276 /*************************************************************************
277 * IsLFNDrive [SHELL32.119]
279 BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
281 if (SHELL_OsIsUnicode())
282 return IsLFNDriveW(lpszPath
);
283 return IsLFNDriveA(lpszPath
);
287 ########## Creating Something Unique ##########
289 /*************************************************************************
290 * PathMakeUniqueNameA [internal]
292 static BOOL
PathMakeUniqueNameA(
295 LPCSTR lpszShortName
,
299 FIXME("%p %u %s %s %s stub\n",
300 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
301 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
305 /*************************************************************************
306 * PathMakeUniqueNameW [internal]
308 static BOOL
PathMakeUniqueNameW(
311 LPCWSTR lpszShortName
,
312 LPCWSTR lpszLongName
,
313 LPCWSTR lpszPathName
)
315 FIXME("%p %u %s %s %s stub\n",
316 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
317 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
321 /*************************************************************************
322 * PathMakeUniqueName [SHELL32.47]
324 BOOL WINAPI
PathMakeUniqueNameAW(
327 LPCVOID lpszShortName
,
328 LPCVOID lpszLongName
,
329 LPCVOID lpszPathName
)
331 if (SHELL_OsIsUnicode())
332 return PathMakeUniqueNameW(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
333 return PathMakeUniqueNameA(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
336 /*************************************************************************
337 * PathYetAnotherMakeUniqueName [SHELL32.75]
339 BOOL WINAPI
PathYetAnotherMakeUniqueName(LPWSTR buffer
, LPCWSTR path
, LPCWSTR shortname
, LPCWSTR longname
)
341 WCHAR pathW
[MAX_PATH
], retW
[MAX_PATH
];
342 const WCHAR
*file
, *ext
;
345 TRACE("(%p, %s, %s, %s)\n", buffer
, debugstr_w(path
), debugstr_w(shortname
), debugstr_w(longname
));
347 file
= longname
? longname
: shortname
;
348 PathCombineW(pathW
, path
, file
);
349 strcpyW(retW
, pathW
);
350 PathRemoveExtensionW(pathW
);
352 ext
= PathFindExtensionW(file
);
354 /* now try to make it unique */
355 while (PathFileExistsW(retW
))
357 static const WCHAR fmtW
[] = {'%','s',' ','(','%','d',')','%','s',0};
359 sprintfW(retW
, fmtW
, pathW
, i
, ext
);
363 strcpyW(buffer
, retW
);
364 TRACE("ret - %s\n", debugstr_w(buffer
));
370 ########## cleaning and resolving paths ##########
373 /*************************************************************************
374 * PathCleanupSpec [SHELL32.171]
376 * lpszFile is changed in place.
378 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
384 if (SHELL_OsIsUnicode())
386 LPWSTR p
= lpszFileW
;
388 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
391 length
= strlenW(lpszPathW
);
395 int gct
= PathGetCharTypeW(*p
);
396 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
399 rc
|= PCS_REPLACEDCHAR
;
405 if (length
+ i
== MAX_PATH
)
407 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
415 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
416 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
419 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
422 length
= strlen(lpszPathA
);
426 int gct
= PathGetCharTypeA(*p
);
427 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
430 rc
|= PCS_REPLACEDCHAR
;
436 if (length
+ i
== MAX_PATH
)
438 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
447 /*************************************************************************
448 * PathQualifyA [SHELL32]
450 static BOOL
PathQualifyA(LPCSTR pszPath
)
452 FIXME("%s\n",pszPath
);
456 /*************************************************************************
457 * PathQualifyW [SHELL32]
459 static BOOL
PathQualifyW(LPCWSTR pszPath
)
461 FIXME("%s\n",debugstr_w(pszPath
));
465 /*************************************************************************
466 * PathQualify [SHELL32.49]
468 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
470 if (SHELL_OsIsUnicode())
471 return PathQualifyW(pszPath
);
472 return PathQualifyA(pszPath
);
475 static BOOL
PathResolveA(LPSTR path
, LPCSTR
*paths
, DWORD flags
)
477 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_a(path
), paths
, flags
);
481 static BOOL
PathResolveW(LPWSTR path
, LPCWSTR
*paths
, DWORD flags
)
483 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_w(path
), paths
, flags
);
487 /*************************************************************************
488 * PathResolve [SHELL32.51]
490 BOOL WINAPI
PathResolveAW(LPVOID path
, LPCVOID
*paths
, DWORD flags
)
492 if (SHELL_OsIsUnicode())
493 return PathResolveW(path
, (LPCWSTR
*)paths
, flags
);
495 return PathResolveA(path
, (LPCSTR
*)paths
, flags
);
498 /*************************************************************************
499 * PathProcessCommandA
501 static LONG
PathProcessCommandA (
507 FIXME("%s %p 0x%04x 0x%04x stub\n",
508 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
509 if(!lpszPath
) return -1;
510 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
511 return strlen(lpszPath
);
514 /*************************************************************************
515 * PathProcessCommandW
517 static LONG
PathProcessCommandW (
523 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
524 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
525 if(!lpszPath
) return -1;
526 if(lpszBuff
) strcpyW(lpszBuff
, lpszPath
);
527 return strlenW(lpszPath
);
530 /*************************************************************************
531 * PathProcessCommand (SHELL32.653)
533 LONG WINAPI
PathProcessCommandAW (
539 if (SHELL_OsIsUnicode())
540 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
541 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
545 ########## special ##########
548 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'};
549 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'};
550 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
551 static const WCHAR AppData_LocalLowW
[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','L','o','w','\0'};
552 static const WCHAR Application_DataW
[] = {'A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
553 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
554 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
555 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'};
556 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
557 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
558 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
559 static const WCHAR Common_FavoritesW
[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
560 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
561 static const WCHAR CommonFilesDirX86W
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
562 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
563 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
564 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
565 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
566 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
567 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
568 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
569 static const WCHAR ContactsW
[] = {'C','o','n','t','a','c','t','s','\0'};
570 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
571 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
572 static const WCHAR DocumentsW
[] = {'D','o','c','u','m','e','n','t','s','\0'};
573 static const WCHAR DownloadsW
[] = {'D','o','w','n','l','o','a','d','s','\0'};
574 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
575 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
576 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
577 static const WCHAR LinksW
[] = {'L','i','n','k','s','\0'};
578 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
579 static const WCHAR Local_Settings_Application_DataW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
580 static const WCHAR Local_Settings_CD_BurningW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\\','M','i','c','r','o','s','o','f','t','\\','C','D',' ','B','u','r','n','i','n','g','\0'};
581 static const WCHAR Local_Settings_HistoryW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','H','i','s','t','o','r','y','\0'};
582 static const WCHAR Local_Settings_Temporary_Internet_FilesW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','T','e','m','p','o','r','a','r','y',' ','I','n','t','e','r','n','e','t',' ','F','i','l','e','s','\0'};
583 static const WCHAR Microsoft_Windows_GameExplorerW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','G','a','m','e','E','x','p','l','o','r','e','r','\0'};
584 static const WCHAR Microsoft_Windows_LibrariesW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','L','i','b','r','a','r','i','e','s','\0'};
585 static const WCHAR Microsoft_Windows_RingtonesW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','R','i','n','g','t','o','n','e','s','\0'};
586 static const WCHAR MusicW
[] = {'M','u','s','i','c','\0'};
587 static const WCHAR Music_PlaylistsW
[] = {'M','u','s','i','c','\\','P','l','a','y','l','i','s','t','s','\0'};
588 static const WCHAR Music_Sample_MusicW
[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','M','u','s','i','c','\0'};
589 static const WCHAR Music_Sample_PlaylistsW
[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','P','l','a','y','l','i','s','t','s','\0'};
590 static const WCHAR My_DocumentsW
[] = {'M','y',' ','D','o','c','u','m','e','n','t','s','\0'};
591 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
592 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
593 static const WCHAR My_VideoW
[] = {'M','y',' ','V','i','d','e','o','\0'};
594 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
595 static const WCHAR OEM_LinksW
[] = {'O','E','M',' ','L','i','n','k','s','\0'};
596 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
597 static const WCHAR PicturesW
[] = {'P','i','c','t','u','r','e','s','\0'};
598 static const WCHAR Pictures_Sample_PicturesW
[] = {'P','i','c','t','u','r','e','s','\\','S','a','m','p','l','e',' ','P','i','c','t','u','r','e','s','\0'};
599 static const WCHAR Pictures_Slide_ShowsW
[] = {'P','i','c','t','u','r','e','s','\\','S','l','i','d','e',' ','S','h','o','w','s','\0'};
600 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
601 static const WCHAR Program_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\0'};
602 static const WCHAR Program_Files_Common_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
603 static const WCHAR Program_Files_x86W
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\0'};
604 static const WCHAR Program_Files_x86_Common_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
605 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
606 static const WCHAR ProgramFilesDirX86W
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
607 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
608 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
609 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
610 static const WCHAR Saved_GamesW
[] = {'S','a','v','e','d',' ','G','a','m','e','s','\0'};
611 static const WCHAR SearchesW
[] = {'S','e','a','r','c','h','e','s','\0'};
612 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
613 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
614 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
615 static const WCHAR Start_Menu_ProgramsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\0'};
616 static const WCHAR Start_Menu_Admin_ToolsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
617 static const WCHAR Start_Menu_StartupW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','S','t','a','r','t','U','p','\0'};
618 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
619 static const WCHAR UsersW
[] = {'U','s','e','r','s','\0'};
620 static const WCHAR UsersPublicW
[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
621 static const WCHAR VideosW
[] = {'V','i','d','e','o','s','\0'};
622 static const WCHAR Videos_Sample_VideosW
[] = {'V','i','d','e','o','s','\\','S','a','m','p','l','e',' ','V','i','d','e','o','s','\0'};
623 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
624 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
625 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
626 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
627 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};
628 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
629 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
630 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'};
631 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'};
632 static const WCHAR szDefaultProfileDirW
[] = {'u','s','e','r','s',0};
633 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'};
634 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};
635 static const WCHAR AllUsersW
[] = {'P','u','b','l','i','c',0};
637 typedef enum _CSIDL_Type
{
641 CSIDL_Type_Disallowed
,
642 CSIDL_Type_NonExistent
,
643 CSIDL_Type_WindowsPath
,
644 CSIDL_Type_SystemPath
,
645 CSIDL_Type_SystemX86Path
,
648 /* Cannot use #if _WIN32_WINNT >= 0x0600 because _WIN32_WINNT == 0x0600 here. */
650 #define CSIDL_CONTACTS 0x0043
651 #define CSIDL_DOWNLOADS 0x0047
652 #define CSIDL_LINKS 0x004d
653 #define CSIDL_APPDATA_LOCALLOW 0x004e
654 #define CSIDL_SAVED_GAMES 0x0062
655 #define CSIDL_SEARCHES 0x0063
660 const KNOWNFOLDERID
*id
;
663 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
666 static const CSIDL_DATA CSIDL_Data
[] =
668 { /* 0x00 - CSIDL_DESKTOP */
672 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
674 { /* 0x01 - CSIDL_INTERNET */
675 &FOLDERID_InternetFolder
,
676 CSIDL_Type_Disallowed
,
680 { /* 0x02 - CSIDL_PROGRAMS */
684 MAKEINTRESOURCEW(IDS_PROGRAMS
)
686 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
687 &FOLDERID_ControlPanelFolder
,
688 CSIDL_Type_SystemPath
,
692 { /* 0x04 - CSIDL_PRINTERS */
693 &FOLDERID_PrintersFolder
,
694 CSIDL_Type_SystemPath
,
698 { /* 0x05 - CSIDL_PERSONAL */
702 MAKEINTRESOURCEW(IDS_PERSONAL
)
704 { /* 0x06 - CSIDL_FAVORITES */
708 MAKEINTRESOURCEW(IDS_FAVORITES
)
710 { /* 0x07 - CSIDL_STARTUP */
714 MAKEINTRESOURCEW(IDS_STARTUP
)
716 { /* 0x08 - CSIDL_RECENT */
720 MAKEINTRESOURCEW(IDS_RECENT
)
722 { /* 0x09 - CSIDL_SENDTO */
726 MAKEINTRESOURCEW(IDS_SENDTO
)
728 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
729 &FOLDERID_RecycleBinFolder
,
730 CSIDL_Type_Disallowed
,
734 { /* 0x0b - CSIDL_STARTMENU */
738 MAKEINTRESOURCEW(IDS_STARTMENU
)
740 { /* 0x0c - CSIDL_MYDOCUMENTS */
742 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
746 { /* 0x0d - CSIDL_MYMUSIC */
750 MAKEINTRESOURCEW(IDS_MYMUSIC
)
752 { /* 0x0e - CSIDL_MYVIDEO */
756 MAKEINTRESOURCEW(IDS_MYVIDEO
)
758 { /* 0x0f - unassigned */
760 CSIDL_Type_Disallowed
,
764 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
768 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
770 { /* 0x11 - CSIDL_DRIVES */
771 &FOLDERID_ComputerFolder
,
772 CSIDL_Type_Disallowed
,
776 { /* 0x12 - CSIDL_NETWORK */
777 &FOLDERID_NetworkFolder
,
778 CSIDL_Type_Disallowed
,
782 { /* 0x13 - CSIDL_NETHOOD */
786 MAKEINTRESOURCEW(IDS_NETHOOD
)
788 { /* 0x14 - CSIDL_FONTS */
790 CSIDL_Type_WindowsPath
,
794 { /* 0x15 - CSIDL_TEMPLATES */
798 MAKEINTRESOURCEW(IDS_TEMPLATES
)
800 { /* 0x16 - CSIDL_COMMON_STARTMENU */
801 &FOLDERID_CommonStartMenu
,
804 MAKEINTRESOURCEW(IDS_STARTMENU
)
806 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
807 &FOLDERID_CommonPrograms
,
810 MAKEINTRESOURCEW(IDS_PROGRAMS
)
812 { /* 0x18 - CSIDL_COMMON_STARTUP */
813 &FOLDERID_CommonStartup
,
816 MAKEINTRESOURCEW(IDS_STARTUP
)
818 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
819 &FOLDERID_PublicDesktop
,
822 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
824 { /* 0x1a - CSIDL_APPDATA */
825 &FOLDERID_RoamingAppData
,
828 MAKEINTRESOURCEW(IDS_APPDATA
)
830 { /* 0x1b - CSIDL_PRINTHOOD */
834 MAKEINTRESOURCEW(IDS_PRINTHOOD
)
836 { /* 0x1c - CSIDL_LOCAL_APPDATA */
837 &FOLDERID_LocalAppData
,
840 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA
)
842 { /* 0x1d - CSIDL_ALTSTARTUP */
844 CSIDL_Type_NonExistent
,
848 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
850 CSIDL_Type_NonExistent
,
854 { /* 0x1f - CSIDL_COMMON_FAVORITES */
858 MAKEINTRESOURCEW(IDS_FAVORITES
)
860 { /* 0x20 - CSIDL_INTERNET_CACHE */
861 &FOLDERID_InternetCache
,
864 MAKEINTRESOURCEW(IDS_INTERNET_CACHE
)
866 { /* 0x21 - CSIDL_COOKIES */
870 MAKEINTRESOURCEW(IDS_COOKIES
)
872 { /* 0x22 - CSIDL_HISTORY */
876 MAKEINTRESOURCEW(IDS_HISTORY
)
878 { /* 0x23 - CSIDL_COMMON_APPDATA */
879 &FOLDERID_ProgramData
,
882 MAKEINTRESOURCEW(IDS_APPDATA
)
884 { /* 0x24 - CSIDL_WINDOWS */
886 CSIDL_Type_WindowsPath
,
890 { /* 0x25 - CSIDL_SYSTEM */
892 CSIDL_Type_SystemPath
,
896 { /* 0x26 - CSIDL_PROGRAM_FILES */
897 &FOLDERID_ProgramFiles
,
900 MAKEINTRESOURCEW(IDS_PROGRAM_FILES
)
902 { /* 0x27 - CSIDL_MYPICTURES */
906 MAKEINTRESOURCEW(IDS_MYPICTURES
)
908 { /* 0x28 - CSIDL_PROFILE */
914 { /* 0x29 - CSIDL_SYSTEMX86 */
916 CSIDL_Type_SystemX86Path
,
920 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
921 &FOLDERID_ProgramFilesX86
,
926 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
927 &FOLDERID_ProgramFilesCommon
,
930 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON
)
932 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
933 &FOLDERID_ProgramFilesCommonX86
,
936 Program_Files_x86_Common_FilesW
938 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
939 &FOLDERID_CommonTemplates
,
942 MAKEINTRESOURCEW(IDS_TEMPLATES
)
944 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
945 &FOLDERID_PublicDocuments
,
948 MAKEINTRESOURCEW(IDS_PERSONAL
)
950 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
951 &FOLDERID_CommonAdminTools
,
953 Common_Administrative_ToolsW
,
954 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
956 { /* 0x30 - CSIDL_ADMINTOOLS */
957 &FOLDERID_AdminTools
,
959 Administrative_ToolsW
,
960 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
962 { /* 0x31 - CSIDL_CONNECTIONS */
963 &FOLDERID_ConnectionsFolder
,
964 CSIDL_Type_Disallowed
,
968 { /* 0x32 - unassigned */
970 CSIDL_Type_Disallowed
,
974 { /* 0x33 - unassigned */
976 CSIDL_Type_Disallowed
,
980 { /* 0x34 - unassigned */
982 CSIDL_Type_Disallowed
,
986 { /* 0x35 - CSIDL_COMMON_MUSIC */
987 &FOLDERID_PublicMusic
,
990 MAKEINTRESOURCEW(IDS_COMMON_MUSIC
)
992 { /* 0x36 - CSIDL_COMMON_PICTURES */
993 &FOLDERID_PublicPictures
,
996 MAKEINTRESOURCEW(IDS_COMMON_PICTURES
)
998 { /* 0x37 - CSIDL_COMMON_VIDEO */
999 &FOLDERID_PublicVideos
,
1000 CSIDL_Type_AllUsers
,
1002 MAKEINTRESOURCEW(IDS_COMMON_VIDEO
)
1004 { /* 0x38 - CSIDL_RESOURCES */
1005 &FOLDERID_ResourceDir
,
1006 CSIDL_Type_WindowsPath
,
1010 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1011 &FOLDERID_LocalizedResourcesDir
,
1012 CSIDL_Type_NonExistent
,
1016 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1017 &FOLDERID_CommonOEMLinks
,
1018 CSIDL_Type_AllUsers
,
1022 { /* 0x3b - CSIDL_CDBURN_AREA */
1023 &FOLDERID_CDBurning
,
1026 Local_Settings_CD_BurningW
1028 { /* 0x3c unassigned */
1030 CSIDL_Type_Disallowed
,
1034 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1036 CSIDL_Type_Disallowed
, /* FIXME */
1040 { /* 0x3e - CSIDL_PROFILES */
1042 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1046 /* Cannot use #if _WIN32_WINNT >= 0x0600 because _WIN32_WINNT == 0x0600 here. */
1049 &FOLDERID_AddNewPrograms
,
1050 CSIDL_Type_Disallowed
,
1055 &FOLDERID_AppUpdates
,
1056 CSIDL_Type_Disallowed
,
1061 &FOLDERID_ChangeRemovePrograms
,
1062 CSIDL_Type_Disallowed
,
1067 &FOLDERID_ConflictFolder
,
1068 CSIDL_Type_Disallowed
,
1072 { /* 0x43 - CSIDL_CONTACTS */
1079 &FOLDERID_DeviceMetadataStore
,
1080 CSIDL_Type_Disallowed
, /* FIXME */
1091 &FOLDERID_DocumentsLibrary
,
1092 CSIDL_Type_Disallowed
, /* FIXME */
1096 { /* 0x47 - CSIDL_DOWNLOADS */
1097 &FOLDERID_Downloads
,
1104 CSIDL_Type_Disallowed
,
1109 &FOLDERID_GameTasks
,
1110 CSIDL_Type_Disallowed
, /* FIXME */
1115 &FOLDERID_HomeGroup
,
1116 CSIDL_Type_Disallowed
,
1121 &FOLDERID_ImplicitAppShortcuts
,
1122 CSIDL_Type_Disallowed
, /* FIXME */
1127 &FOLDERID_Libraries
,
1128 CSIDL_Type_Disallowed
, /* FIXME */
1132 { /* 0x4d - CSIDL_LINKS */
1138 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
1139 &FOLDERID_LocalAppDataLow
,
1145 &FOLDERID_MusicLibrary
,
1146 CSIDL_Type_Disallowed
, /* FIXME */
1151 &FOLDERID_OriginalImages
,
1152 CSIDL_Type_Disallowed
, /* FIXME */
1157 &FOLDERID_PhotoAlbums
,
1160 Pictures_Slide_ShowsW
1163 &FOLDERID_PicturesLibrary
,
1164 CSIDL_Type_Disallowed
, /* FIXME */
1169 &FOLDERID_Playlists
,
1175 &FOLDERID_ProgramFilesX64
,
1176 CSIDL_Type_NonExistent
,
1181 &FOLDERID_ProgramFilesCommonX64
,
1182 CSIDL_Type_NonExistent
,
1188 CSIDL_Type_CurrVer
, /* FIXME */
1193 &FOLDERID_PublicDownloads
,
1194 CSIDL_Type_AllUsers
,
1199 &FOLDERID_PublicGameTasks
,
1200 CSIDL_Type_AllUsers
,
1202 Microsoft_Windows_GameExplorerW
1205 &FOLDERID_PublicLibraries
,
1206 CSIDL_Type_AllUsers
,
1208 Microsoft_Windows_LibrariesW
1211 &FOLDERID_PublicRingtones
,
1212 CSIDL_Type_AllUsers
,
1214 Microsoft_Windows_RingtonesW
1217 &FOLDERID_QuickLaunch
,
1218 CSIDL_Type_Disallowed
, /* FIXME */
1223 &FOLDERID_RecordedTVLibrary
,
1224 CSIDL_Type_Disallowed
, /* FIXME */
1229 &FOLDERID_Ringtones
,
1230 CSIDL_Type_Disallowed
, /* FIXME */
1235 &FOLDERID_SampleMusic
,
1236 CSIDL_Type_AllUsers
,
1241 &FOLDERID_SamplePictures
,
1242 CSIDL_Type_AllUsers
,
1244 Pictures_Sample_PicturesW
1247 &FOLDERID_SamplePlaylists
,
1248 CSIDL_Type_AllUsers
,
1250 Music_Sample_PlaylistsW
1253 &FOLDERID_SampleVideos
,
1254 CSIDL_Type_AllUsers
,
1256 Videos_Sample_VideosW
1258 { /* 0x62 - CSIDL_SAVED_GAMES */
1259 &FOLDERID_SavedGames
,
1264 { /* 0x63 - CSIDL_SEARCHES */
1265 &FOLDERID_SavedSearches
,
1271 &FOLDERID_SEARCH_CSC
,
1272 CSIDL_Type_Disallowed
,
1277 &FOLDERID_SEARCH_MAPI
,
1278 CSIDL_Type_Disallowed
,
1283 &FOLDERID_SearchHome
,
1284 CSIDL_Type_Disallowed
,
1289 &FOLDERID_SidebarDefaultParts
,
1290 CSIDL_Type_Disallowed
, /* FIXME */
1295 &FOLDERID_SidebarParts
,
1296 CSIDL_Type_Disallowed
, /* FIXME */
1301 &FOLDERID_SyncManagerFolder
,
1302 CSIDL_Type_Disallowed
,
1307 &FOLDERID_SyncResultsFolder
,
1308 CSIDL_Type_Disallowed
,
1313 &FOLDERID_SyncSetupFolder
,
1314 CSIDL_Type_Disallowed
,
1319 &FOLDERID_UserPinned
,
1320 CSIDL_Type_Disallowed
, /* FIXME */
1325 &FOLDERID_UserProfiles
,
1331 &FOLDERID_UserProgramFiles
,
1332 CSIDL_Type_Disallowed
, /* FIXME */
1337 &FOLDERID_UserProgramFilesCommon
,
1338 CSIDL_Type_Disallowed
, /* FIXME */
1343 &FOLDERID_UsersFiles
,
1344 CSIDL_Type_Disallowed
,
1349 &FOLDERID_UsersLibraries
,
1350 CSIDL_Type_Disallowed
,
1355 &FOLDERID_VideosLibrary
,
1356 CSIDL_Type_Disallowed
, /* FIXME */
1363 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1365 /* Gets the value named value from the registry key
1366 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1367 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1368 * is assumed to be MAX_PATH WCHARs in length.
1369 * If it exists, expands the value and writes the expanded value to
1370 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1371 * Returns successful error code if the value was retrieved from the registry,
1372 * and a failure otherwise.
1374 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1375 LPCWSTR value
, LPWSTR path
)
1378 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1379 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1380 DWORD dwType
, dwPathLen
= MAX_PATH
;
1381 HKEY userShellFolderKey
, shellFolderKey
;
1383 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1388 strcpyW(shellFolderPath
, userPrefix
);
1389 PathAddBackslashW(shellFolderPath
);
1390 strcatW(shellFolderPath
, szSHFolders
);
1391 pShellFolderPath
= shellFolderPath
;
1392 strcpyW(userShellFolderPath
, userPrefix
);
1393 PathAddBackslashW(userShellFolderPath
);
1394 strcatW(userShellFolderPath
, szSHUserFolders
);
1395 pUserShellFolderPath
= userShellFolderPath
;
1399 pUserShellFolderPath
= szSHUserFolders
;
1400 pShellFolderPath
= szSHFolders
;
1403 if (RegCreateKeyW(rootKey
, pShellFolderPath
, &shellFolderKey
))
1405 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1408 if (RegCreateKeyW(rootKey
, pUserShellFolderPath
, &userShellFolderKey
))
1410 TRACE("Failed to create %s\n",
1411 debugstr_w(pUserShellFolderPath
));
1412 RegCloseKey(shellFolderKey
);
1416 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1417 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1421 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1422 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1424 WCHAR szTemp
[MAX_PATH
];
1426 _SHExpandEnvironmentStrings(path
, szTemp
);
1427 lstrcpynW(path
, szTemp
, MAX_PATH
);
1429 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1430 (strlenW(path
) + 1) * sizeof(WCHAR
));
1431 if (ret
!= ERROR_SUCCESS
)
1432 hr
= HRESULT_FROM_WIN32(ret
);
1438 RegCloseKey(shellFolderKey
);
1439 RegCloseKey(userShellFolderKey
);
1440 TRACE("returning 0x%08x\n", hr
);
1444 BOOL
_SHGetUserProfileDirectoryW(HANDLE hToken
, LPWSTR szPath
, LPDWORD lpcchPath
)
1449 OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
);
1450 result
= GetUserProfileDirectoryW(hToken
, szPath
, lpcchPath
);
1451 CloseHandle(hToken
);
1453 else if ((INT
) hToken
== -1)
1455 result
= GetDefaultUserProfileDirectoryW(szPath
, lpcchPath
);
1459 result
= GetUserProfileDirectoryW(hToken
, szPath
, lpcchPath
);
1461 DbgPrint("_SHGetUserProfileDirectoryW returning %S\n", szPath
);
1465 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1466 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1467 * - The entry's szDefaultPath may be either a string value or an integer
1468 * resource identifier. In the latter case, the string value of the resource
1470 * - Depending on the entry's type, the path may begin with an (unexpanded)
1471 * environment variable name. The caller is responsible for expanding
1472 * environment strings if so desired.
1473 * The types that are prepended with environment variables are:
1474 * CSIDL_Type_User: %USERPROFILE%
1475 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1476 * CSIDL_Type_CurrVer: %SystemDrive%
1477 * (Others might make sense too, but as yet are unneeded.)
1479 static HRESULT
_SHGetDefaultValue(HANDLE hToken
, BYTE folder
, LPWSTR pszPath
)
1483 WCHAR resourcePath
[MAX_PATH
];
1485 TRACE("0x%02x,%p\n", folder
, pszPath
);
1487 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1488 return E_INVALIDARG
;
1490 return E_INVALIDARG
;
1494 case CSIDL_PROGRAM_FILES
:
1496 folder
= CSIDL_PROGRAM_FILESX86
;
1498 case CSIDL_PROGRAM_FILES_COMMON
:
1500 folder
= CSIDL_PROGRAM_FILESX86
;
1504 switch (CSIDL_Data
[folder
].type
)
1506 case CSIDL_Type_User
:
1508 if (!_SHGetUserProfileDirectoryW(hToken
, pszPath
, &cchSize
))
1509 return HRESULT_FROM_WIN32(GetLastError());
1511 case CSIDL_Type_AllUsers
:
1513 if (!GetAllUsersProfileDirectoryW(pszPath
, &cchSize
))
1514 return HRESULT_FROM_WIN32(GetLastError());
1516 case CSIDL_Type_CurrVer
:
1517 strcpyW(pszPath
, SystemDriveW
);
1520 ; /* no corresponding env. var, do nothing */
1524 if (CSIDL_Data
[folder
].szDefaultPath
)
1526 if (IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1528 if (LoadStringW(shell32_hInstance
,
1529 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1531 PathAppendW(pszPath
, resourcePath
);
1535 ERR("(%d,%s), LoadString failed, missing translation?\n", folder
,
1536 debugstr_w(pszPath
));
1542 PathAppendW(pszPath
, CSIDL_Data
[folder
].szDefaultPath
);
1545 TRACE("returning 0x%08x\n", hr
);
1549 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1550 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1551 * can be overridden in the HKLM\\szCurrentVersion key.
1552 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1553 * the registry, uses _SHGetDefaultValue to get the value.
1555 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1560 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1562 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1563 return E_INVALIDARG
;
1564 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1565 return E_INVALIDARG
;
1567 return E_INVALIDARG
;
1569 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1570 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1575 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hKey
))
1579 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1581 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1582 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1583 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1585 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1586 dwType
= REG_EXPAND_SZ
;
1589 case CSIDL_PROGRAM_FILESX86
:
1590 case CSIDL_PROGRAM_FILES_COMMONX86
:
1591 /* these two should never be set on 32-bit setups */
1595 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1596 if (!is_wow64
) break;
1600 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1601 (LPBYTE
)pszPath
, (strlenW(pszPath
)+1)*sizeof(WCHAR
));
1606 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1612 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1616 static LPWSTR
_GetUserSidStringFromToken(HANDLE Token
)
1618 char InfoBuffer
[64];
1619 PTOKEN_USER UserInfo
;
1623 UserInfo
= (PTOKEN_USER
) InfoBuffer
;
1624 if (! GetTokenInformation(Token
, TokenUser
, InfoBuffer
, sizeof(InfoBuffer
),
1627 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1629 UserInfo
= HeapAlloc(GetProcessHeap(), 0, InfoSize
);
1630 if (UserInfo
== NULL
)
1632 if (! GetTokenInformation(Token
, TokenUser
, UserInfo
, InfoSize
,
1635 HeapFree(GetProcessHeap(), 0, UserInfo
);
1640 if (! ConvertSidToStringSidW(UserInfo
->User
.Sid
, &SidStr
))
1643 if (UserInfo
!= (PTOKEN_USER
) InfoBuffer
)
1644 HeapFree(GetProcessHeap(), 0, UserInfo
);
1649 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1650 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1651 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1652 * - if hToken is -1, looks in HKEY_USERS\.Default
1653 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1654 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1655 * calls _SHGetDefaultValue for it.
1657 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1660 const WCHAR
*szValueName
;
1664 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1666 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1667 return E_INVALIDARG
;
1668 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1669 return E_INVALIDARG
;
1671 return E_INVALIDARG
;
1673 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1675 hr
= _SHGetDefaultValue(hToken
, folder
, pszPath
);
1679 LPCWSTR userPrefix
= NULL
;
1682 if (hToken
== (HANDLE
)-1)
1684 hRootKey
= HKEY_USERS
;
1685 userPrefix
= DefaultW
;
1687 else if (hToken
== NULL
)
1688 hRootKey
= HKEY_CURRENT_USER
;
1691 hRootKey
= HKEY_USERS
;
1692 userPrefix
= _GetUserSidStringFromToken(hToken
);
1693 if (userPrefix
== NULL
)
1700 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
1701 szValueName
= CSIDL_Data
[folder
].szValueName
;
1704 StringFromGUID2( CSIDL_Data
[folder
].id
, buffer
, 39 );
1705 szValueName
= &buffer
[0];
1708 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, szValueName
, pszPath
);
1709 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1710 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, szValueName
, pszPath
);
1712 hr
= _SHGetDefaultValue(hToken
, folder
, pszPath
);
1713 if (userPrefix
!= NULL
&& userPrefix
!= DefaultW
)
1714 LocalFree((HLOCAL
) userPrefix
);
1717 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1721 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1722 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1723 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1724 * If this fails, falls back to _SHGetDefaultValue.
1726 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1731 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1733 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1734 return E_INVALIDARG
;
1735 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1736 return E_INVALIDARG
;
1738 return E_INVALIDARG
;
1740 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1741 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1744 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1745 CSIDL_Data
[folder
].szValueName
, pszPath
);
1747 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1749 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1753 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
1758 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, NULL
, 0,
1759 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
1760 return HRESULT_FROM_WIN32(lRet
);
1763 /* Reads the value named szValueName from the key profilesKey (assumed to be
1764 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1765 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1766 * szDefault to the registry).
1768 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
1769 LPWSTR szValue
, LPCWSTR szDefault
)
1772 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1775 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
1776 debugstr_w(szDefault
));
1777 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
1778 (LPBYTE
)szValue
, &dwPathLen
);
1779 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
1782 dwPathLen
/= sizeof(WCHAR
);
1783 szValue
[dwPathLen
] = '\0';
1788 /* Missing or invalid value, set a default */
1789 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
1790 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
1791 debugstr_w(szValue
));
1792 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
1794 (strlenW(szValue
) + 1) * sizeof(WCHAR
));
1796 hr
= HRESULT_FROM_WIN32(lRet
);
1800 TRACE("returning 0x%08x (output value is %s)\n", hr
, debugstr_w(szValue
));
1804 /* Attempts to expand environment variables from szSrc into szDest, which is
1805 * assumed to be MAX_PATH characters in length. Before referring to the
1806 * environment, handles a few variables directly, because the environment
1807 * variables may not be set when this is called (as during Wine's installation
1808 * when default values are being written to the registry).
1809 * The directly handled environment variables, and their source, are:
1810 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1811 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1813 * If one of the directly handled environment variables is expanded, only
1814 * expands a single variable, and only in the beginning of szSrc.
1816 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
1819 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
1822 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
1824 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
1826 /* short-circuit if there's nothing to expand */
1827 if (szSrc
[0] != '%')
1829 strcpyW(szDest
, szSrc
);
1833 /* Get the profile prefix, we'll probably be needing it */
1834 hr
= _SHOpenProfilesKey(&key
);
1837 WCHAR def_val
[MAX_PATH
];
1839 /* get the system drive */
1840 GetSystemDirectoryW(def_val
, MAX_PATH
);
1841 if (def_val
[1] == ':') strcpyW( def_val
+ 3, szDefaultProfileDirW
);
1842 else FIXME("non-drive system paths unsupported\n");
1844 hr
= _SHGetProfilesValue(key
, ProfilesDirectoryW
, szProfilesPrefix
, def_val
);
1848 strcpyW(szTemp
, szSrc
);
1849 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
1851 if (!strncmpiW(szTemp
, AllUsersProfileW
, strlenW(AllUsersProfileW
)))
1853 WCHAR szAllUsers
[MAX_PATH
];
1855 strcpyW(szDest
, szProfilesPrefix
);
1856 hr
= _SHGetProfilesValue(key
, AllUsersProfileValueW
,
1857 szAllUsers
, AllUsersW
);
1858 PathAppendW(szDest
, szAllUsers
);
1859 PathAppendW(szDest
, szTemp
+ strlenW(AllUsersProfileW
));
1861 else if (!strncmpiW(szTemp
, UserProfileW
, strlenW(UserProfileW
)))
1863 WCHAR userName
[MAX_PATH
];
1864 DWORD userLen
= MAX_PATH
;
1866 strcpyW(szDest
, szProfilesPrefix
);
1867 GetUserNameW(userName
, &userLen
);
1868 PathAppendW(szDest
, userName
);
1869 PathAppendW(szDest
, szTemp
+ strlenW(UserProfileW
));
1871 else if (!strncmpiW(szTemp
, SystemDriveW
, strlenW(SystemDriveW
)))
1873 GetSystemDirectoryW(szDest
, MAX_PATH
);
1874 if (szDest
[1] != ':')
1876 FIXME("non-drive system paths unsupported\n");
1881 strcpyW(szDest
+ 3, szTemp
+ strlenW(SystemDriveW
) + 1);
1887 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
1890 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
1892 hr
= HRESULT_FROM_WIN32(GetLastError());
1896 if (SUCCEEDED(hr
) && szDest
[0] == '%')
1897 strcpyW(szTemp
, szDest
);
1900 /* terminate loop */
1907 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr
,
1908 debugstr_w(szSrc
), debugstr_w(szDest
));
1912 /*************************************************************************
1913 * SHGetFolderPathW [SHELL32.@]
1915 * Convert nFolder to path.
1919 * Failure: standard HRESULT error codes.
1922 * Most values can be overridden in either
1923 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1924 * or in the same location in HKLM.
1925 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1926 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1927 * changes made to it are made to the former key too. This synchronization is
1928 * done on-demand: not until someone requests the value of one of these paths
1929 * (by calling one of the SHGet functions) is the value synchronized.
1930 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1932 HRESULT WINAPI
SHGetFolderPathW(
1933 HWND hwndOwner
, /* [I] owner window */
1934 int nFolder
, /* [I] CSIDL identifying the folder */
1935 HANDLE hToken
, /* [I] access token */
1936 DWORD dwFlags
, /* [I] which path to return */
1937 LPWSTR pszPath
) /* [O] converted path */
1939 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
1940 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
1941 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1945 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
1946 HWND hwndOwner
, /* [I] owner window */
1947 int nFolder
, /* [I] CSIDL identifying the folder */
1948 HANDLE hToken
, /* [I] access token */
1949 DWORD dwFlags
, /* [I] which path to return */
1950 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
1951 LPSTR pszPath
) /* [O] converted path */
1955 LPWSTR pszSubPathW
= NULL
;
1956 LPWSTR pszPathW
= NULL
;
1957 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1960 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
1962 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1966 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1968 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
1969 * set (null), or an empty string.therefore call it without the parameter set
1970 * if pszSubPath is an empty string
1972 if (pszSubPath
&& pszSubPath
[0]) {
1973 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
1974 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
1976 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1979 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
1982 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
1984 if (SUCCEEDED(hr
) && pszPath
)
1985 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1988 HeapFree(GetProcessHeap(), 0, pszPathW
);
1989 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
1993 /*************************************************************************
1994 * SHGetFolderPathAndSubDirW [SHELL32.@]
1996 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
1997 HWND hwndOwner
, /* [I] owner window */
1998 int nFolder
, /* [I] CSIDL identifying the folder */
1999 HANDLE hToken
, /* [I] access token */
2000 DWORD dwFlags
, /* [I] which path to return */
2001 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
2002 LPWSTR pszPath
) /* [O] converted path */
2005 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
2006 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2010 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
2012 /* Windows always NULL-terminates the resulting path regardless of success
2013 * or failure, so do so first
2018 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2019 return E_INVALIDARG
;
2020 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
2021 return E_INVALIDARG
;
2023 type
= CSIDL_Data
[folder
].type
;
2026 case CSIDL_Type_Disallowed
:
2029 case CSIDL_Type_NonExistent
:
2032 case CSIDL_Type_WindowsPath
:
2033 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
2034 if (CSIDL_Data
[folder
].szDefaultPath
&&
2035 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2036 *CSIDL_Data
[folder
].szDefaultPath
)
2038 PathAddBackslashW(szTemp
);
2039 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2043 case CSIDL_Type_SystemPath
:
2044 GetSystemDirectoryW(szTemp
, MAX_PATH
);
2045 if (CSIDL_Data
[folder
].szDefaultPath
&&
2046 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2047 *CSIDL_Data
[folder
].szDefaultPath
)
2049 PathAddBackslashW(szTemp
);
2050 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2054 case CSIDL_Type_SystemX86Path
:
2055 if (!GetSystemWow64DirectoryW(szTemp
, MAX_PATH
)) GetSystemDirectoryW(szTemp
, MAX_PATH
);
2056 if (CSIDL_Data
[folder
].szDefaultPath
&&
2057 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2058 *CSIDL_Data
[folder
].szDefaultPath
)
2060 PathAddBackslashW(szTemp
);
2061 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2065 case CSIDL_Type_CurrVer
:
2066 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
2068 case CSIDL_Type_User
:
2069 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
2071 case CSIDL_Type_AllUsers
:
2072 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
2075 FIXME("bogus type %d, please fix\n", type
);
2080 /* Expand environment strings if necessary */
2082 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
2084 strcpyW(szBuildPath
, szTemp
);
2086 if (FAILED(hr
)) goto end
;
2089 /* make sure the new path does not exceed the buffer length
2090 * and remember to backslash and terminate it */
2091 if(MAX_PATH
< (lstrlenW(szBuildPath
) + lstrlenW(pszSubPath
) + 2)) {
2092 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
2095 PathAppendW(szBuildPath
, pszSubPath
);
2096 PathRemoveBackslashW(szBuildPath
);
2098 /* Copy the path if it's available before we might return */
2099 if (SUCCEEDED(hr
) && pszPath
)
2100 strcpyW(pszPath
, szBuildPath
);
2102 /* if we don't care about existing directories we are ready */
2103 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
2105 if (PathFileExistsW(szBuildPath
)) goto end
;
2107 /* not existing but we are not allowed to create it. The return value
2108 * is verified against shell32 version 6.0.
2110 if (!(nFolder
& CSIDL_FLAG_CREATE
))
2112 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2116 /* create directory/directories */
2117 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
2118 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
2120 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
2125 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
2127 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
2131 /*************************************************************************
2132 * SHGetFolderPathA [SHELL32.@]
2134 * See SHGetFolderPathW.
2136 HRESULT WINAPI
SHGetFolderPathA(
2143 WCHAR szTemp
[MAX_PATH
];
2146 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
2150 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
2151 if (SUCCEEDED(hr
) && pszPath
)
2152 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
2158 /* For each folder in folders, if its value has not been set in the registry,
2159 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
2160 * folder's type) to get the unexpanded value first.
2161 * Writes the unexpanded value to User Shell Folders, and queries it with
2162 * SHGetFolderPathW to force the creation of the directory if it doesn't
2163 * already exist. SHGetFolderPathW also returns the expanded value, which
2164 * this then writes to Shell Folders.
2166 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
2167 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
2170 const WCHAR
*szValueName
;
2173 WCHAR path
[MAX_PATH
];
2175 HKEY hUserKey
= NULL
, hKey
= NULL
;
2176 DWORD dwType
, dwPathLen
;
2179 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
2180 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
2182 ret
= RegCreateKeyW(hRootKey
, szUserShellFolderPath
, &hUserKey
);
2184 hr
= HRESULT_FROM_WIN32(ret
);
2187 ret
= RegCreateKeyW(hRootKey
, szShellFolderPath
, &hKey
);
2189 hr
= HRESULT_FROM_WIN32(ret
);
2191 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
2193 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2195 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
2196 szValueName
= CSIDL_Data
[folders
[i
]].szValueName
;
2197 if (!szValueName
&& CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2199 StringFromGUID2( CSIDL_Data
[folders
[i
]].id
, buffer
, 39 );
2200 szValueName
= &buffer
[0];
2203 if (RegQueryValueExW(hUserKey
, szValueName
, NULL
,
2204 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
2205 dwType
!= REG_EXPAND_SZ
))
2208 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2209 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
2211 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
2212 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
2213 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
2215 GetWindowsDirectoryW(path
, MAX_PATH
);
2216 if (CSIDL_Data
[folders
[i
]].szDefaultPath
&&
2217 !IS_INTRESOURCE(CSIDL_Data
[folders
[i
]].szDefaultPath
))
2219 PathAddBackslashW(path
);
2220 strcatW(path
, CSIDL_Data
[folders
[i
]].szDefaultPath
);
2227 ret
= RegSetValueExW(hUserKey
, szValueName
, 0, REG_EXPAND_SZ
,
2228 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2230 hr
= HRESULT_FROM_WIN32(ret
);
2233 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
2234 hToken
, SHGFP_TYPE_DEFAULT
, path
);
2235 ret
= RegSetValueExW(hKey
, szValueName
, 0, REG_SZ
,
2236 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2238 hr
= HRESULT_FROM_WIN32(ret
);
2244 RegCloseKey(hUserKey
);
2248 TRACE("returning 0x%08x\n", hr
);
2252 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
2254 static const UINT folders
[] = {
2265 CSIDL_DESKTOPDIRECTORY
,
2269 CSIDL_LOCAL_APPDATA
,
2270 CSIDL_INTERNET_CACHE
,
2276 /* Cannot use #if _WIN32_WINNT >= 0x0600 because _WIN32_WINNT == 0x0600 here. */
2281 CSIDL_APPDATA_LOCALLOW
,
2286 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
2287 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
2292 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
2295 hToken
= (HANDLE
)-1;
2296 hRootKey
= HKEY_USERS
;
2297 strcpyW(userShellFolderPath
, DefaultW
);
2298 PathAddBackslashW(userShellFolderPath
);
2299 strcatW(userShellFolderPath
, szSHUserFolders
);
2300 pUserShellFolderPath
= userShellFolderPath
;
2301 strcpyW(shellFolderPath
, DefaultW
);
2302 PathAddBackslashW(shellFolderPath
);
2303 strcatW(shellFolderPath
, szSHFolders
);
2304 pShellFolderPath
= shellFolderPath
;
2309 hRootKey
= HKEY_CURRENT_USER
;
2310 pUserShellFolderPath
= szSHUserFolders
;
2311 pShellFolderPath
= szSHFolders
;
2314 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
2315 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2316 TRACE("returning 0x%08x\n", hr
);
2320 static HRESULT
_SHRegisterCommonShellFolders(void)
2322 static const UINT folders
[] = {
2323 CSIDL_COMMON_STARTMENU
,
2324 CSIDL_COMMON_PROGRAMS
,
2325 CSIDL_COMMON_STARTUP
,
2326 CSIDL_COMMON_DESKTOPDIRECTORY
,
2327 CSIDL_COMMON_FAVORITES
,
2328 CSIDL_COMMON_APPDATA
,
2329 CSIDL_COMMON_TEMPLATES
,
2330 CSIDL_COMMON_DOCUMENTS
,
2331 CSIDL_COMMON_ADMINTOOLS
,
2333 CSIDL_COMMON_PICTURES
,
2339 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
2340 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2341 TRACE("returning 0x%08x\n", hr
);
2345 /* Register the default values in the registry, as some apps seem to depend
2346 * on their presence. The set registered was taken from Windows XP.
2348 HRESULT
SHELL_RegisterShellFolders(void)
2352 hr
= _SHRegisterUserShellFolders(TRUE
);
2354 hr
= _SHRegisterUserShellFolders(FALSE
);
2356 hr
= _SHRegisterCommonShellFolders();
2360 /*************************************************************************
2361 * SHGetSpecialFolderPathA [SHELL32.@]
2363 BOOL WINAPI
SHGetSpecialFolderPathA (
2369 return SHGetFolderPathA(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2373 /*************************************************************************
2374 * SHGetSpecialFolderPathW
2376 BOOL WINAPI
SHGetSpecialFolderPathW (
2382 return SHGetFolderPathW(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2386 /*************************************************************************
2387 * SHGetFolderLocation [SHELL32.@]
2389 * Gets the folder locations from the registry and creates a pidl.
2393 * nFolder [I] CSIDL_xxxxx
2394 * hToken [I] token representing user, or NULL for current user, or -1 for
2396 * dwReserved [I] must be zero
2397 * ppidl [O] PIDL of a special folder
2401 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2404 * Creates missing reg keys and directories.
2405 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2406 * virtual folders that are handled here.
2408 HRESULT WINAPI
SHGetFolderLocation(
2413 LPITEMIDLIST
*ppidl
)
2415 HRESULT hr
= E_INVALIDARG
;
2417 TRACE("%p 0x%08x %p 0x%08x %p\n",
2418 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
2421 return E_INVALIDARG
;
2423 return E_INVALIDARG
;
2425 /* The virtual folders' locations are not user-dependent */
2427 switch (nFolder
& CSIDL_FOLDER_MASK
)
2430 *ppidl
= _ILCreateDesktop();
2433 case CSIDL_PERSONAL
:
2434 *ppidl
= _ILCreateMyDocuments();
2437 case CSIDL_INTERNET
:
2438 *ppidl
= _ILCreateIExplore();
2441 case CSIDL_CONTROLS
:
2442 *ppidl
= _ILCreateControlPanel();
2445 case CSIDL_PRINTERS
:
2446 *ppidl
= _ILCreatePrinters();
2449 case CSIDL_BITBUCKET
:
2450 *ppidl
= _ILCreateBitBucket();
2454 *ppidl
= _ILCreateMyComputer();
2458 *ppidl
= _ILCreateNetwork();
2463 WCHAR szPath
[MAX_PATH
];
2465 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
2466 SHGFP_TYPE_CURRENT
, szPath
);
2471 TRACE("Value=%s\n", debugstr_w(szPath
));
2472 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
2474 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
2476 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2477 * version 6.0 returns E_FAIL for nonexistent paths
2486 TRACE("-- (new pidl %p)\n",*ppidl
);
2490 /*************************************************************************
2491 * SHGetSpecialFolderLocation [SHELL32.@]
2494 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2497 HRESULT WINAPI
SHGetSpecialFolderLocation(
2500 LPITEMIDLIST
* ppidl
)
2502 HRESULT hr
= E_INVALIDARG
;
2504 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
2507 return E_INVALIDARG
;
2509 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);