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
28 #include "wine/port.h"
34 #include "wine/debug.h"
44 #include "shell32_main.h"
45 #include "undocshell.h"
47 #include "wine/unicode.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 ########## Combining and Constructing paths ##########
58 /*************************************************************************
59 * PathAppend [SHELL32.36]
61 BOOL WINAPI PathAppendAW(
65 if (SHELL_OsIsUnicode())
66 return PathAppendW(lpszPath1, lpszPath2);
67 return PathAppendA(lpszPath1, lpszPath2);
70 /*************************************************************************
71 * PathCombine [SHELL32.37]
73 LPVOID WINAPI PathCombineAW(
78 if (SHELL_OsIsUnicode())
79 return PathCombineW( szDest, lpszDir, lpszFile );
80 return PathCombineA( szDest, lpszDir, lpszFile );
83 /*************************************************************************
84 * PathAddBackslash [SHELL32.32]
86 LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
88 if(SHELL_OsIsUnicode())
89 return PathAddBackslashW(lpszPath);
90 return PathAddBackslashA(lpszPath);
93 /*************************************************************************
94 * PathBuildRoot [SHELL32.30]
96 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
98 if(SHELL_OsIsUnicode())
99 return PathBuildRootW(lpszPath, drive);
100 return PathBuildRootA(lpszPath, drive);
104 Extracting Component Parts
107 /*************************************************************************
108 * PathFindFileName [SHELL32.34]
110 LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
112 if(SHELL_OsIsUnicode())
113 return PathFindFileNameW(lpszPath);
114 return PathFindFileNameA(lpszPath);
117 /*************************************************************************
118 * PathFindExtension [SHELL32.31]
120 LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
122 if (SHELL_OsIsUnicode())
123 return PathFindExtensionW(lpszPath);
124 return PathFindExtensionA(lpszPath);
128 /*************************************************************************
129 * PathGetExtensionA [internal]
132 * exported by ordinal
133 * return value points to the first char after the dot
135 static LPSTR PathGetExtensionA(LPCSTR lpszPath)
137 TRACE("(%s)\n",lpszPath);
139 lpszPath = PathFindExtensionA(lpszPath);
140 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
143 /*************************************************************************
144 * PathGetExtensionW [internal]
146 static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
148 TRACE("(%s)\n",debugstr_w(lpszPath));
150 lpszPath = PathFindExtensionW(lpszPath);
151 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
154 /*************************************************************************
155 * PathGetExtension [SHELL32.158]
157 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath,DWORD void1, DWORD void2)
159 if (SHELL_OsIsUnicode())
160 return PathGetExtensionW(lpszPath);
161 return PathGetExtensionA(lpszPath);
164 /*************************************************************************
165 * PathGetArgs [SHELL32.52]
167 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
169 if (SHELL_OsIsUnicode())
170 return PathGetArgsW(lpszPath);
171 return PathGetArgsA(lpszPath);
174 /*************************************************************************
175 * PathGetDriveNumber [SHELL32.57]
177 int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
179 if (SHELL_OsIsUnicode())
180 return PathGetDriveNumberW(lpszPath);
181 return PathGetDriveNumberA(lpszPath);
184 /*************************************************************************
185 * PathRemoveFileSpec [SHELL32.35]
187 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
189 if (SHELL_OsIsUnicode())
190 return PathRemoveFileSpecW(lpszPath);
191 return PathRemoveFileSpecA(lpszPath);
194 /*************************************************************************
195 * PathStripPath [SHELL32.38]
197 void WINAPI PathStripPathAW(LPVOID lpszPath)
199 if (SHELL_OsIsUnicode())
200 PathStripPathW(lpszPath);
202 PathStripPathA(lpszPath);
205 /*************************************************************************
206 * PathStripToRoot [SHELL32.50]
208 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
210 if (SHELL_OsIsUnicode())
211 return PathStripToRootW(lpszPath);
212 return PathStripToRootA(lpszPath);
215 /*************************************************************************
216 * PathRemoveArgs [SHELL32.251]
218 void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
220 if (SHELL_OsIsUnicode())
221 PathRemoveArgsW(lpszPath);
223 PathRemoveArgsA(lpszPath);
226 /*************************************************************************
227 * PathRemoveExtension [SHELL32.250]
229 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
231 if (SHELL_OsIsUnicode())
232 PathRemoveExtensionW(lpszPath);
234 PathRemoveExtensionA(lpszPath);
242 /*************************************************************************
243 * PathGetShortPathA [internal]
245 static void PathGetShortPathA(LPSTR pszPath)
249 TRACE("%s\n", pszPath);
251 if (GetShortPathNameA(pszPath, path, MAX_PATH))
253 lstrcpyA(pszPath, path);
257 /*************************************************************************
258 * PathGetShortPathW [internal]
260 static void PathGetShortPathW(LPWSTR pszPath)
262 WCHAR path[MAX_PATH];
264 TRACE("%s\n", debugstr_w(pszPath));
266 if (GetShortPathNameW(pszPath, path, MAX_PATH))
268 lstrcpyW(pszPath, path);
272 /*************************************************************************
273 * PathGetShortPath [SHELL32.92]
275 VOID WINAPI PathGetShortPathAW(LPVOID pszPath)
277 if(SHELL_OsIsUnicode())
278 PathGetShortPathW(pszPath);
279 PathGetShortPathA(pszPath);
282 /*************************************************************************
283 * PathRemoveBlanks [SHELL32.33]
285 void WINAPI PathRemoveBlanksAW(LPVOID str)
287 if(SHELL_OsIsUnicode())
288 PathRemoveBlanksW(str);
290 PathRemoveBlanksA(str);
293 /*************************************************************************
294 * PathQuoteSpaces [SHELL32.55]
296 VOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
298 if(SHELL_OsIsUnicode())
299 PathQuoteSpacesW(lpszPath);
301 PathQuoteSpacesA(lpszPath);
304 /*************************************************************************
305 * PathUnquoteSpaces [SHELL32.56]
307 VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
309 if(SHELL_OsIsUnicode())
310 PathUnquoteSpacesW(str);
312 PathUnquoteSpacesA(str);
315 /*************************************************************************
316 * PathParseIconLocation [SHELL32.249]
318 int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
320 if(SHELL_OsIsUnicode())
321 return PathParseIconLocationW(lpszPath);
322 return PathParseIconLocationA(lpszPath);
326 ########## Path Testing ##########
328 /*************************************************************************
329 * PathIsUNC [SHELL32.39]
331 BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
333 if (SHELL_OsIsUnicode())
334 return PathIsUNCW( lpszPath );
335 return PathIsUNCA( lpszPath );
338 /*************************************************************************
339 * PathIsRelative [SHELL32.40]
341 BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
343 if (SHELL_OsIsUnicode())
344 return PathIsRelativeW( lpszPath );
345 return PathIsRelativeA( lpszPath );
348 /*************************************************************************
349 * PathIsRoot [SHELL32.29]
351 BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
353 if (SHELL_OsIsUnicode())
354 return PathIsRootW(lpszPath);
355 return PathIsRootA(lpszPath);
358 /*************************************************************************
359 * PathIsExeA [internal]
361 static BOOL PathIsExeA (LPCSTR lpszPath)
363 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
365 static const char * const lpszExtensions[] =
366 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
368 TRACE("path=%s\n",lpszPath);
370 for(i=0; lpszExtensions[i]; i++)
371 if (!lstrcmpiA(lpszExtension,lpszExtensions[i])) return TRUE;
376 /*************************************************************************
377 * PathIsExeW [internal]
379 static BOOL PathIsExeW (LPCWSTR lpszPath)
381 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
383 static const WCHAR lpszExtensions[][4] =
384 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
385 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
386 {'s','c','r','\0'}, {'\0'} };
388 TRACE("path=%s\n",debugstr_w(lpszPath));
390 for(i=0; lpszExtensions[i][0]; i++)
391 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
396 /*************************************************************************
397 * PathIsExe [SHELL32.43]
399 BOOL WINAPI PathIsExeAW (LPCVOID path)
401 if (SHELL_OsIsUnicode())
402 return PathIsExeW (path);
403 return PathIsExeA(path);
406 /*************************************************************************
407 * PathIsDirectory [SHELL32.159]
409 BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
411 if (SHELL_OsIsUnicode())
412 return PathIsDirectoryW (lpszPath);
413 return PathIsDirectoryA (lpszPath);
416 /*************************************************************************
417 * PathFileExists [SHELL32.45]
419 BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
421 if (SHELL_OsIsUnicode())
422 return PathFileExistsW (lpszPath);
423 return PathFileExistsA (lpszPath);
426 /*************************************************************************
427 * PathMatchSpec [SHELL32.46]
429 BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
431 if (SHELL_OsIsUnicode())
432 return PathMatchSpecW( name, mask );
433 return PathMatchSpecA( name, mask );
436 /*************************************************************************
437 * PathIsSameRoot [SHELL32.650]
439 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
441 if (SHELL_OsIsUnicode())
442 return PathIsSameRootW(lpszPath1, lpszPath2);
443 return PathIsSameRootA(lpszPath1, lpszPath2);
446 /*************************************************************************
447 * IsLFNDriveA [SHELL32.41]
449 BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
453 if (!GetVolumeInformationA(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
458 /*************************************************************************
459 * IsLFNDriveW [SHELL32.42]
461 BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
465 if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
470 /*************************************************************************
471 * IsLFNDrive [SHELL32.119]
473 BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath)
475 if (SHELL_OsIsUnicode())
476 return IsLFNDriveW(lpszPath);
477 return IsLFNDriveA(lpszPath);
481 ########## Creating Something Unique ##########
483 /*************************************************************************
484 * PathMakeUniqueNameA [internal]
486 static BOOL PathMakeUniqueNameA(
489 LPCSTR lpszShortName,
493 FIXME("%p %u %s %s %s stub\n",
494 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
495 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
499 /*************************************************************************
500 * PathMakeUniqueNameW [internal]
502 static BOOL PathMakeUniqueNameW(
505 LPCWSTR lpszShortName,
506 LPCWSTR lpszLongName,
507 LPCWSTR lpszPathName)
509 FIXME("%p %u %s %s %s stub\n",
510 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
511 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
515 /*************************************************************************
516 * PathMakeUniqueName [SHELL32.47]
518 BOOL WINAPI PathMakeUniqueNameAW(
521 LPCVOID lpszShortName,
522 LPCVOID lpszLongName,
523 LPCVOID lpszPathName)
525 if (SHELL_OsIsUnicode())
526 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
527 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
530 /*************************************************************************
531 * PathYetAnotherMakeUniqueName [SHELL32.75]
534 * exported by ordinal
536 BOOL WINAPI PathYetAnotherMakeUniqueName(
538 LPCWSTR lpszPathName,
539 LPCWSTR lpszShortName,
540 LPCWSTR lpszLongName)
542 FIXME("(%p, %s, %s ,%s):stub.\n",
543 lpszBuffer, debugstr_w(lpszPathName), debugstr_w(lpszShortName), debugstr_w(lpszLongName));
549 ########## cleaning and resolving paths ##########
552 /*************************************************************************
553 * PathFindOnPath [SHELL32.145]
555 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID *sOtherDirs)
557 if (SHELL_OsIsUnicode())
558 return PathFindOnPathW(sFile, (LPCWSTR *)sOtherDirs);
559 return PathFindOnPathA(sFile, (LPCSTR *)sOtherDirs);
562 /*************************************************************************
563 * PathCleanupSpec [SHELL32.171]
565 * lpszFile is changed in place.
567 int WINAPI PathCleanupSpec( LPCWSTR lpszPathW, LPWSTR lpszFileW )
573 if (SHELL_OsIsUnicode())
575 LPWSTR p = lpszFileW;
577 TRACE("Cleanup %s\n",debugstr_w(lpszFileW));
580 length = strlenW(lpszPathW);
584 int gct = PathGetCharTypeW(*p);
585 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
588 rc |= PCS_REPLACEDCHAR;
594 if (length + i == MAX_PATH)
596 rc |= PCS_FATAL | PCS_PATHTOOLONG;
604 LPSTR lpszFileA = (LPSTR)lpszFileW;
605 LPCSTR lpszPathA = (LPCSTR)lpszPathW;
608 TRACE("Cleanup %s\n",debugstr_a(lpszFileA));
611 length = strlen(lpszPathA);
615 int gct = PathGetCharTypeA(*p);
616 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
619 rc |= PCS_REPLACEDCHAR;
625 if (length + i == MAX_PATH)
627 rc |= PCS_FATAL | PCS_PATHTOOLONG;
636 /*************************************************************************
637 * PathQualifyA [SHELL32]
639 static BOOL PathQualifyA(LPCSTR pszPath)
641 FIXME("%s\n",pszPath);
645 /*************************************************************************
646 * PathQualifyW [SHELL32]
648 static BOOL PathQualifyW(LPCWSTR pszPath)
650 FIXME("%s\n",debugstr_w(pszPath));
654 /*************************************************************************
655 * PathQualify [SHELL32.49]
657 BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
659 if (SHELL_OsIsUnicode())
660 return PathQualifyW(pszPath);
661 return PathQualifyA(pszPath);
664 static BOOL PathResolveA(
669 FIXME("(%s,%p,0x%08x),stub!\n",
670 lpszPath, *alpszPaths, dwFlags);
674 static BOOL PathResolveW(
679 FIXME("(%s,%p,0x%08x),stub!\n",
680 debugstr_w(lpszPath), debugstr_w(*alpszPaths), dwFlags);
684 /*************************************************************************
685 * PathResolve [SHELL32.51]
687 BOOL WINAPI PathResolveAW(
692 if (SHELL_OsIsUnicode())
693 return PathResolveW(lpszPath, (LPCWSTR*)alpszPaths, dwFlags);
694 return PathResolveA(lpszPath, (LPCSTR*)alpszPaths, dwFlags);
697 /*************************************************************************
698 * PathProcessCommandA
700 static LONG PathProcessCommandA (
706 FIXME("%s %p 0x%04x 0x%04x stub\n",
707 lpszPath, lpszBuff, dwBuffSize, dwFlags);
708 if(!lpszPath) return -1;
709 if(lpszBuff) strcpy(lpszBuff, lpszPath);
710 return strlen(lpszPath);
713 /*************************************************************************
714 * PathProcessCommandW
716 static LONG PathProcessCommandW (
722 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
723 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
724 if(!lpszPath) return -1;
725 if(lpszBuff) strcpyW(lpszBuff, lpszPath);
726 return strlenW(lpszPath);
729 /*************************************************************************
730 * PathProcessCommand (SHELL32.653)
732 LONG WINAPI PathProcessCommandAW (
738 if (SHELL_OsIsUnicode())
739 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
740 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
744 ########## special ##########
747 /*************************************************************************
748 * PathSetDlgItemPath (SHELL32.48)
750 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
752 if (SHELL_OsIsUnicode())
753 PathSetDlgItemPathW(hDlg, id, pszPath);
755 PathSetDlgItemPathA(hDlg, id, pszPath);
758 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'};
759 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'};
760 static const WCHAR AppDataW[] = {'A','p','p','D','a','t','a','\0'};
761 static const WCHAR CacheW[] = {'C','a','c','h','e','\0'};
762 static const WCHAR CD_BurningW[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
763 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'};
764 static const WCHAR Common_AppDataW[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
765 static const WCHAR Common_DesktopW[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
766 static const WCHAR Common_DocumentsW[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
767 static const WCHAR CommonFilesDirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\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 CookiesW[] = {'C','o','o','k','i','e','s','\0'};
776 static const WCHAR DesktopW[] = {'D','e','s','k','t','o','p','\0'};
777 static const WCHAR FavoritesW[] = {'F','a','v','o','r','i','t','e','s','\0'};
778 static const WCHAR FontsW[] = {'F','o','n','t','s','\0'};
779 static const WCHAR HistoryW[] = {'H','i','s','t','o','r','y','\0'};
780 static const WCHAR Local_AppDataW[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
781 static const WCHAR My_MusicW[] = {'M','y',' ','M','u','s','i','c','\0'};
782 static const WCHAR My_PicturesW[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
783 static const WCHAR My_VideoW[] = {'M','y',' ','V','i','d','e','o','s','\0'};
784 static const WCHAR NetHoodW[] = {'N','e','t','H','o','o','d','\0'};
785 static const WCHAR PersonalW[] = {'P','e','r','s','o','n','a','l','\0'};
786 static const WCHAR PrintHoodW[] = {'P','r','i','n','t','H','o','o','d','\0'};
787 static const WCHAR ProgramFilesDirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
788 static const WCHAR ProgramsW[] = {'P','r','o','g','r','a','m','s','\0'};
789 static const WCHAR RecentW[] = {'R','e','c','e','n','t','\0'};
790 static const WCHAR ResourcesW[] = {'R','e','s','o','u','r','c','e','s','\0'};
791 static const WCHAR SendToW[] = {'S','e','n','d','T','o','\0'};
792 static const WCHAR StartUpW[] = {'S','t','a','r','t','U','p','\0'};
793 static const WCHAR Start_MenuW[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
794 static const WCHAR TemplatesW[] = {'T','e','m','p','l','a','t','e','s','\0'};
795 static const WCHAR DefaultW[] = {'.','D','e','f','a','u','l','t','\0'};
796 static const WCHAR AllUsersProfileW[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
797 static const WCHAR UserProfileW[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
798 static const WCHAR SystemDriveW[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
799 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};
800 static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
801 static const WCHAR AllUsersProfileValueW[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
802 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'};
803 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'};
804 static const WCHAR szDefaultProfileDirW[] = {'u','s','e','r','s',0};
805 static const WCHAR AllUsersW[] = {'P','u','b','l','i','c',0};
807 typedef enum _CSIDL_Type {
811 CSIDL_Type_Disallowed,
812 CSIDL_Type_NonExistent,
813 CSIDL_Type_WindowsPath,
814 CSIDL_Type_SystemPath,
815 CSIDL_Type_SystemX86Path,
822 LPCWSTR szDefaultPath; /* fallback string or resource ID */
825 static const CSIDL_DATA CSIDL_Data[] =
827 { /* 0x00 - CSIDL_DESKTOP */
830 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
832 { /* 0x01 - CSIDL_INTERNET */
833 CSIDL_Type_Disallowed,
837 { /* 0x02 - CSIDL_PROGRAMS */
840 MAKEINTRESOURCEW(IDS_PROGRAMS)
842 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
843 CSIDL_Type_SystemPath,
847 { /* 0x04 - CSIDL_PRINTERS */
848 CSIDL_Type_SystemPath,
852 { /* 0x05 - CSIDL_PERSONAL */
855 MAKEINTRESOURCEW(IDS_PERSONAL)
857 { /* 0x06 - CSIDL_FAVORITES */
860 MAKEINTRESOURCEW(IDS_FAVORITES)
862 { /* 0x07 - CSIDL_STARTUP */
865 MAKEINTRESOURCEW(IDS_STARTUP)
867 { /* 0x08 - CSIDL_RECENT */
870 MAKEINTRESOURCEW(IDS_RECENT)
872 { /* 0x09 - CSIDL_SENDTO */
875 MAKEINTRESOURCEW(IDS_SENDTO)
877 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
878 CSIDL_Type_Disallowed,
882 { /* 0x0b - CSIDL_STARTMENU */
885 MAKEINTRESOURCEW(IDS_STARTMENU)
887 { /* 0x0c - CSIDL_MYDOCUMENTS */
888 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
892 { /* 0x0d - CSIDL_MYMUSIC */
895 MAKEINTRESOURCEW(IDS_MYMUSIC)
897 { /* 0x0e - CSIDL_MYVIDEO */
900 MAKEINTRESOURCEW(IDS_MYVIDEO)
902 { /* 0x0f - unassigned */
903 CSIDL_Type_Disallowed,
907 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
910 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
912 { /* 0x11 - CSIDL_DRIVES */
913 CSIDL_Type_Disallowed,
917 { /* 0x12 - CSIDL_NETWORK */
918 CSIDL_Type_Disallowed,
922 { /* 0x13 - CSIDL_NETHOOD */
925 MAKEINTRESOURCEW(IDS_NETHOOD)
927 { /* 0x14 - CSIDL_FONTS */
928 CSIDL_Type_WindowsPath,
932 { /* 0x15 - CSIDL_TEMPLATES */
935 MAKEINTRESOURCEW(IDS_TEMPLATES)
937 { /* 0x16 - CSIDL_COMMON_STARTMENU */
940 MAKEINTRESOURCEW(IDS_STARTMENU)
942 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
945 MAKEINTRESOURCEW(IDS_PROGRAMS)
947 { /* 0x18 - CSIDL_COMMON_STARTUP */
950 MAKEINTRESOURCEW(IDS_STARTUP)
952 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
955 MAKEINTRESOURCEW(IDS_DESKTOP)
957 { /* 0x1a - CSIDL_APPDATA */
960 MAKEINTRESOURCEW(IDS_APPDATA)
962 { /* 0x1b - CSIDL_PRINTHOOD */
965 MAKEINTRESOURCEW(IDS_PRINTHOOD)
967 { /* 0x1c - CSIDL_LOCAL_APPDATA */
970 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA)
972 { /* 0x1d - CSIDL_ALTSTARTUP */
973 CSIDL_Type_NonExistent,
977 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
978 CSIDL_Type_NonExistent,
982 { /* 0x1f - CSIDL_COMMON_FAVORITES */
985 MAKEINTRESOURCEW(IDS_FAVORITES)
987 { /* 0x20 - CSIDL_INTERNET_CACHE */
990 MAKEINTRESOURCEW(IDS_INTERNET_CACHE)
992 { /* 0x21 - CSIDL_COOKIES */
995 MAKEINTRESOURCEW(IDS_COOKIES)
997 { /* 0x22 - CSIDL_HISTORY */
1000 MAKEINTRESOURCEW(IDS_HISTORY)
1002 { /* 0x23 - CSIDL_COMMON_APPDATA */
1003 CSIDL_Type_AllUsers,
1005 MAKEINTRESOURCEW(IDS_APPDATA)
1007 { /* 0x24 - CSIDL_WINDOWS */
1008 CSIDL_Type_WindowsPath,
1012 { /* 0x25 - CSIDL_SYSTEM */
1013 CSIDL_Type_SystemPath,
1017 { /* 0x26 - CSIDL_PROGRAM_FILES */
1020 MAKEINTRESOURCEW(IDS_PROGRAM_FILES)
1022 { /* 0x27 - CSIDL_MYPICTURES */
1025 MAKEINTRESOURCEW(IDS_MYPICTURES)
1027 { /* 0x28 - CSIDL_PROFILE */
1032 { /* 0x29 - CSIDL_SYSTEMX86 */
1033 CSIDL_Type_SystemX86Path,
1037 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1038 CSIDL_Type_NonExistent,
1042 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1045 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON)
1047 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1048 CSIDL_Type_NonExistent,
1052 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1053 CSIDL_Type_AllUsers,
1055 MAKEINTRESOURCEW(IDS_TEMPLATES)
1057 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1058 CSIDL_Type_AllUsers,
1060 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS)
1062 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1063 CSIDL_Type_AllUsers,
1064 Common_Administrative_ToolsW,
1065 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1067 { /* 0x30 - CSIDL_ADMINTOOLS */
1069 Administrative_ToolsW,
1070 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1072 { /* 0x31 - CSIDL_CONNECTIONS */
1073 CSIDL_Type_Disallowed,
1077 { /* 0x32 - unassigned */
1078 CSIDL_Type_Disallowed,
1082 { /* 0x33 - unassigned */
1083 CSIDL_Type_Disallowed,
1087 { /* 0x34 - unassigned */
1088 CSIDL_Type_Disallowed,
1092 { /* 0x35 - CSIDL_COMMON_MUSIC */
1093 CSIDL_Type_AllUsers,
1095 MAKEINTRESOURCEW(IDS_COMMON_MUSIC)
1097 { /* 0x36 - CSIDL_COMMON_PICTURES */
1098 CSIDL_Type_AllUsers,
1100 MAKEINTRESOURCEW(IDS_COMMON_PICTURES)
1102 { /* 0x37 - CSIDL_COMMON_VIDEO */
1103 CSIDL_Type_AllUsers,
1105 MAKEINTRESOURCEW(IDS_COMMON_VIDEO)
1107 { /* 0x38 - CSIDL_RESOURCES */
1108 CSIDL_Type_WindowsPath,
1112 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1113 CSIDL_Type_NonExistent,
1117 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1118 CSIDL_Type_NonExistent,
1122 { /* 0x3b - CSIDL_CDBURN_AREA */
1125 MAKEINTRESOURCEW(IDS_CDBURN_AREA)
1127 { /* 0x3c unassigned */
1128 CSIDL_Type_Disallowed,
1132 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1133 CSIDL_Type_Disallowed, /* FIXME */
1137 { /* 0x3e - CSIDL_PROFILES */
1138 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
1144 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
1146 /* Gets the value named value from the registry key
1147 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1148 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1149 * is assumed to be MAX_PATH WCHARs in length.
1150 * If it exists, expands the value and writes the expanded value to
1151 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1152 * Returns successful error code if the value was retrieved from the registry,
1153 * and a failure otherwise.
1155 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
1156 LPCWSTR value, LPWSTR path)
1159 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
1160 LPCWSTR pShellFolderPath, pUserShellFolderPath;
1161 DWORD dwType, dwPathLen = MAX_PATH;
1162 HKEY userShellFolderKey, shellFolderKey;
1164 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
1169 strcpyW(shellFolderPath, userPrefix);
1170 PathAddBackslashW(shellFolderPath);
1171 strcatW(shellFolderPath, szSHFolders);
1172 pShellFolderPath = shellFolderPath;
1173 strcpyW(userShellFolderPath, userPrefix);
1174 PathAddBackslashW(userShellFolderPath);
1175 strcatW(userShellFolderPath, szSHUserFolders);
1176 pUserShellFolderPath = userShellFolderPath;
1180 pUserShellFolderPath = szSHUserFolders;
1181 pShellFolderPath = szSHFolders;
1184 if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey))
1186 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
1189 if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey))
1191 TRACE("Failed to create %s\n",
1192 debugstr_w(pUserShellFolderPath));
1193 RegCloseKey(shellFolderKey);
1197 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
1198 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
1202 path[dwPathLen / sizeof(WCHAR)] = '\0';
1203 if (dwType == REG_EXPAND_SZ && path[0] == '%')
1205 WCHAR szTemp[MAX_PATH];
1207 _SHExpandEnvironmentStrings(path, szTemp);
1208 lstrcpynW(path, szTemp, MAX_PATH);
1210 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
1211 (strlenW(path) + 1) * sizeof(WCHAR));
1212 if (ret != ERROR_SUCCESS)
1213 hr = HRESULT_FROM_WIN32(ret);
1219 RegCloseKey(shellFolderKey);
1220 RegCloseKey(userShellFolderKey);
1221 TRACE("returning 0x%08x\n", hr);
1225 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1226 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1227 * - The entry's szDefaultPath may be either a string value or an integer
1228 * resource identifier. In the latter case, the string value of the resource
1230 * - Depending on the entry's type, the path may begin with an (unexpanded)
1231 * environment variable name. The caller is responsible for expanding
1232 * environment strings if so desired.
1233 * The types that are prepended with environment variables are:
1234 * CSIDL_Type_User: %USERPROFILE%
1235 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1236 * CSIDL_Type_CurrVer: %SystemDrive%
1237 * (Others might make sense too, but as yet are unneeded.)
1239 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
1242 WCHAR resourcePath[MAX_PATH];
1243 LPCWSTR pDefaultPath = NULL;
1245 TRACE("0x%02x,%p\n", folder, pszPath);
1247 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1248 return E_INVALIDARG;
1250 return E_INVALIDARG;
1252 if (CSIDL_Data[folder].szDefaultPath &&
1253 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
1255 if (LoadStringW(shell32_hInstance,
1256 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
1259 pDefaultPath = resourcePath;
1263 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
1264 debugstr_w(pszPath));
1271 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
1275 switch (CSIDL_Data[folder].type)
1277 case CSIDL_Type_User:
1278 strcpyW(pszPath, UserProfileW);
1280 case CSIDL_Type_AllUsers:
1281 strcpyW(pszPath, AllUsersProfileW);
1283 case CSIDL_Type_CurrVer:
1284 strcpyW(pszPath, SystemDriveW);
1287 ; /* no corresponding env. var, do nothing */
1291 PathAddBackslashW(pszPath);
1292 strcatW(pszPath, pDefaultPath);
1295 TRACE("returning 0x%08x\n", hr);
1299 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1300 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1301 * can be overridden in the HKLM\\szCurrentVersion key.
1302 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1303 * the registry, uses _SHGetDefaultValue to get the value.
1305 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
1310 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1312 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1313 return E_INVALIDARG;
1314 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
1315 return E_INVALIDARG;
1317 return E_INVALIDARG;
1319 if (dwFlags & SHGFP_TYPE_DEFAULT)
1320 hr = _SHGetDefaultValue(folder, pszPath);
1325 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
1329 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
1331 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
1332 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
1333 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
1335 hr = _SHGetDefaultValue(folder, pszPath);
1336 dwType = REG_EXPAND_SZ;
1337 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
1338 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
1342 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
1348 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1352 static LPWSTR _GetUserSidStringFromToken(HANDLE Token)
1354 char InfoBuffer[64];
1355 PTOKEN_USER UserInfo;
1359 UserInfo = (PTOKEN_USER) InfoBuffer;
1360 if (! GetTokenInformation(Token, TokenUser, InfoBuffer, sizeof(InfoBuffer),
1363 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1365 UserInfo = HeapAlloc(GetProcessHeap(), 0, InfoSize);
1366 if (UserInfo == NULL)
1368 if (! GetTokenInformation(Token, TokenUser, UserInfo, InfoSize,
1371 HeapFree(GetProcessHeap(), 0, UserInfo);
1376 if (! ConvertSidToStringSidW(UserInfo->User.Sid, &SidStr))
1379 if (UserInfo != (PTOKEN_USER) InfoBuffer)
1380 HeapFree(GetProcessHeap(), 0, UserInfo);
1385 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1386 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1387 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1388 * - if hToken is -1, looks in HKEY_USERS\.Default
1389 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1390 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1391 * calls _SHGetDefaultValue for it.
1393 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
1398 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
1400 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1401 return E_INVALIDARG;
1402 if (CSIDL_Data[folder].type != CSIDL_Type_User)
1403 return E_INVALIDARG;
1405 return E_INVALIDARG;
1407 if (dwFlags & SHGFP_TYPE_DEFAULT)
1409 if (hToken != NULL && hToken != (HANDLE)-1)
1411 FIXME("unsupported for user other than current or default\n");
1414 hr = _SHGetDefaultValue(folder, pszPath);
1418 LPCWSTR userPrefix = NULL;
1421 if (hToken == (HANDLE)-1)
1423 hRootKey = HKEY_USERS;
1424 userPrefix = DefaultW;
1426 else if (hToken == NULL)
1427 hRootKey = HKEY_CURRENT_USER;
1430 hRootKey = HKEY_USERS;
1431 userPrefix = _GetUserSidStringFromToken(hToken);
1432 if (userPrefix == NULL)
1438 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix,
1439 CSIDL_Data[folder].szValueName, pszPath);
1440 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
1441 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1442 CSIDL_Data[folder].szValueName, pszPath);
1444 hr = _SHGetDefaultValue(folder, pszPath);
1445 if (userPrefix != NULL && userPrefix != DefaultW)
1446 LocalFree((HLOCAL) userPrefix);
1449 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1453 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1454 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1455 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1456 * If this fails, falls back to _SHGetDefaultValue.
1458 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
1463 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1465 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1466 return E_INVALIDARG;
1467 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
1468 return E_INVALIDARG;
1470 return E_INVALIDARG;
1472 if (dwFlags & SHGFP_TYPE_DEFAULT)
1473 hr = _SHGetDefaultValue(folder, pszPath);
1476 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1477 CSIDL_Data[folder].szValueName, pszPath);
1479 hr = _SHGetDefaultValue(folder, pszPath);
1481 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1485 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
1490 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
1491 KEY_ALL_ACCESS, NULL, pKey, &disp);
1492 return HRESULT_FROM_WIN32(lRet);
1495 /* Reads the value named szValueName from the key profilesKey (assumed to be
1496 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1497 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1498 * szDefault to the registry).
1500 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
1501 LPWSTR szValue, LPCWSTR szDefault)
1504 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
1507 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
1508 debugstr_w(szDefault));
1509 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
1510 (LPBYTE)szValue, &dwPathLen);
1511 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
1514 dwPathLen /= sizeof(WCHAR);
1515 szValue[dwPathLen] = '\0';
1520 /* Missing or invalid value, set a default */
1521 lstrcpynW(szValue, szDefault, MAX_PATH);
1522 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
1523 debugstr_w(szValue));
1524 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
1526 (strlenW(szValue) + 1) * sizeof(WCHAR));
1528 hr = HRESULT_FROM_WIN32(lRet);
1532 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
1536 /* Attempts to expand environment variables from szSrc into szDest, which is
1537 * assumed to be MAX_PATH characters in length. Before referring to the
1538 * environment, handles a few variables directly, because the environment
1539 * variables may not be set when this is called (as during Wine's installation
1540 * when default values are being written to the registry).
1541 * The directly handled environment variables, and their source, are:
1542 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1543 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1545 * If one of the directly handled environment variables is expanded, only
1546 * expands a single variable, and only in the beginning of szSrc.
1548 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
1551 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
1554 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
1556 if (!szSrc || !szDest) return E_INVALIDARG;
1558 /* short-circuit if there's nothing to expand */
1559 if (szSrc[0] != '%')
1561 strcpyW(szDest, szSrc);
1565 /* Get the profile prefix, we'll probably be needing it */
1566 hr = _SHOpenProfilesKey(&key);
1569 WCHAR def_val[MAX_PATH];
1571 /* get the system drive */
1572 GetSystemDirectoryW(def_val, MAX_PATH);
1573 if (def_val[1] == ':') strcpyW( def_val + 3, szDefaultProfileDirW );
1574 else FIXME("non-drive system paths unsupported\n");
1576 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix, def_val );
1580 strcpyW(szTemp, szSrc);
1581 while (SUCCEEDED(hr) && szTemp[0] == '%')
1583 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
1585 WCHAR szAllUsers[MAX_PATH];
1587 strcpyW(szDest, szProfilesPrefix);
1588 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
1589 szAllUsers, AllUsersW);
1590 PathAppendW(szDest, szAllUsers);
1591 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
1593 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
1595 WCHAR userName[MAX_PATH];
1596 DWORD userLen = MAX_PATH;
1598 strcpyW(szDest, szProfilesPrefix);
1599 GetUserNameW(userName, &userLen);
1600 PathAppendW(szDest, userName);
1601 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
1603 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
1605 GetSystemDirectoryW(szDest, MAX_PATH);
1606 if (szDest[1] != ':')
1608 FIXME("non-drive system paths unsupported\n");
1613 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
1619 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
1622 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1624 hr = HRESULT_FROM_WIN32(GetLastError());
1628 if (SUCCEEDED(hr) && szDest[0] == '%')
1629 strcpyW(szTemp, szDest);
1632 /* terminate loop */
1639 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
1640 debugstr_w(szSrc), debugstr_w(szDest));
1644 /*************************************************************************
1645 * SHGetFolderPathW [SHELL32.@]
1647 * Convert nFolder to path.
1651 * Failure: standard HRESULT error codes.
1654 * Most values can be overridden in either
1655 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1656 * or in the same location in HKLM.
1657 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1658 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1659 * changes made to it are made to the former key too. This synchronization is
1660 * done on-demand: not until someone requests the value of one of these paths
1661 * (by calling one of the SHGet functions) is the value synchronized.
1662 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1664 HRESULT WINAPI SHGetFolderPathW(
1665 HWND hwndOwner, /* [I] owner window */
1666 int nFolder, /* [I] CSIDL identifying the folder */
1667 HANDLE hToken, /* [I] access token */
1668 DWORD dwFlags, /* [I] which path to return */
1669 LPWSTR pszPath) /* [O] converted path */
1671 HRESULT hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, NULL, pszPath);
1672 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr)
1673 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1677 HRESULT WINAPI SHGetFolderPathAndSubDirA(
1678 HWND hwndOwner, /* [I] owner window */
1679 int nFolder, /* [I] CSIDL identifying the folder */
1680 HANDLE hToken, /* [I] access token */
1681 DWORD dwFlags, /* [I] which path to return */
1682 LPCSTR pszSubPath, /* [I] sub directory of the specified folder */
1683 LPSTR pszPath) /* [O] converted path */
1687 LPWSTR pszSubPathW = NULL;
1688 LPWSTR pszPathW = NULL;
1689 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
1692 pszPathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
1694 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
1698 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
1700 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
1701 * set (null), or an empty string.therefore call it without the parameter set
1702 * if pszSubPath is an empty string
1704 if (pszSubPath && pszSubPath[0]) {
1705 length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0);
1706 pszSubPathW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR));
1708 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
1711 MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length);
1714 hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
1716 if (SUCCEEDED(hr) && pszPath)
1717 WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
1720 HeapFree(GetProcessHeap(), 0, pszPathW);
1721 HeapFree(GetProcessHeap(), 0, pszSubPathW);
1725 /*************************************************************************
1726 * SHGetFolderPathAndSubDirW [SHELL32.@]
1728 HRESULT WINAPI SHGetFolderPathAndSubDirW(
1729 HWND hwndOwner, /* [I] owner window */
1730 int nFolder, /* [I] CSIDL identifying the folder */
1731 HANDLE hToken, /* [I] access token */
1732 DWORD dwFlags, /* [I] which path to return */
1733 LPCWSTR pszSubPath,/* [I] sub directory of the specified folder */
1734 LPWSTR pszPath) /* [O] converted path */
1737 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
1738 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
1742 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner,pszPath,nFolder,debugstr_w(pszSubPath));
1744 /* Windows always NULL-terminates the resulting path regardless of success
1745 * or failure, so do so first
1750 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1751 return E_INVALIDARG;
1752 if ((SHGFP_TYPE_CURRENT != dwFlags) && (SHGFP_TYPE_DEFAULT != dwFlags))
1753 return E_INVALIDARG;
1755 type = CSIDL_Data[folder].type;
1758 case CSIDL_Type_Disallowed:
1761 case CSIDL_Type_NonExistent:
1764 case CSIDL_Type_WindowsPath:
1765 GetWindowsDirectoryW(szTemp, MAX_PATH);
1766 if (CSIDL_Data[folder].szDefaultPath &&
1767 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1768 *CSIDL_Data[folder].szDefaultPath)
1770 PathAddBackslashW(szTemp);
1771 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1775 case CSIDL_Type_SystemPath:
1776 GetSystemDirectoryW(szTemp, MAX_PATH);
1777 if (CSIDL_Data[folder].szDefaultPath &&
1778 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1779 *CSIDL_Data[folder].szDefaultPath)
1781 PathAddBackslashW(szTemp);
1782 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1786 case CSIDL_Type_SystemX86Path:
1787 if (!GetSystemWow64DirectoryW(szTemp, MAX_PATH)) GetSystemDirectoryW(szTemp, MAX_PATH);
1788 if (CSIDL_Data[folder].szDefaultPath &&
1789 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
1790 *CSIDL_Data[folder].szDefaultPath)
1792 PathAddBackslashW(szTemp);
1793 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
1797 case CSIDL_Type_CurrVer:
1798 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
1800 case CSIDL_Type_User:
1801 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
1803 case CSIDL_Type_AllUsers:
1804 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
1807 FIXME("bogus type %d, please fix\n", type);
1812 /* Expand environment strings if necessary */
1814 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
1816 strcpyW(szBuildPath, szTemp);
1818 if (FAILED(hr)) goto end;
1821 /* make sure the new path does not exceed th bufferlength
1822 * rememebr to backslash and the termination */
1823 if(MAX_PATH < (lstrlenW(szBuildPath) + lstrlenW(pszSubPath) + 2)) {
1824 hr = HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
1827 PathAppendW(szBuildPath, pszSubPath);
1828 PathRemoveBackslashW(szBuildPath);
1830 /* Copy the path if it's available before we might return */
1831 if (SUCCEEDED(hr) && pszPath)
1832 strcpyW(pszPath, szBuildPath);
1834 /* if we don't care about existing directories we are ready */
1835 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
1837 if (PathFileExistsW(szBuildPath)) goto end;
1839 /* not existing but we are not allowed to create it. The return value
1840 * is verified against shell32 version 6.0.
1842 if (!(nFolder & CSIDL_FLAG_CREATE))
1844 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
1848 /* create directory/directories */
1849 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
1850 if (ret && ret != ERROR_ALREADY_EXISTS)
1852 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
1857 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
1859 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
1863 /*************************************************************************
1864 * SHGetFolderPathA [SHELL32.@]
1866 * See SHGetFolderPathW.
1868 HRESULT WINAPI SHGetFolderPathA(
1875 WCHAR szTemp[MAX_PATH];
1878 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
1882 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
1883 if (SUCCEEDED(hr) && pszPath)
1884 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
1890 /* For each folder in folders, if its value has not been set in the registry,
1891 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1892 * folder's type) to get the unexpanded value first.
1893 * Writes the unexpanded value to User Shell Folders, and queries it with
1894 * SHGetFolderPathW to force the creation of the directory if it doesn't
1895 * already exist. SHGetFolderPathW also returns the expanded value, which
1896 * this then writes to Shell Folders.
1898 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
1899 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
1903 WCHAR path[MAX_PATH];
1905 HKEY hUserKey = NULL, hKey = NULL;
1906 DWORD dwType, dwPathLen;
1909 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
1910 debugstr_w(szUserShellFolderPath), folders, foldersLen);
1912 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
1914 hr = HRESULT_FROM_WIN32(ret);
1917 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
1919 hr = HRESULT_FROM_WIN32(ret);
1921 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
1923 dwPathLen = MAX_PATH * sizeof(WCHAR);
1924 if (RegQueryValueExW(hUserKey, CSIDL_Data[folders[i]].szValueName, NULL,
1925 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
1926 dwType != REG_EXPAND_SZ))
1929 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
1930 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
1932 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
1933 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
1934 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
1936 GetWindowsDirectoryW(path, MAX_PATH);
1937 if (CSIDL_Data[folders[i]].szDefaultPath &&
1938 !IS_INTRESOURCE(CSIDL_Data[folders[i]].szDefaultPath))
1940 PathAddBackslashW(path);
1941 strcatW(path, CSIDL_Data[folders[i]].szDefaultPath);
1948 ret = RegSetValueExW(hUserKey,
1949 CSIDL_Data[folders[i]].szValueName, 0, REG_EXPAND_SZ,
1950 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1952 hr = HRESULT_FROM_WIN32(ret);
1955 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
1956 hToken, SHGFP_TYPE_DEFAULT, path);
1957 ret = RegSetValueExW(hKey,
1958 CSIDL_Data[folders[i]].szValueName, 0, REG_SZ,
1959 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
1961 hr = HRESULT_FROM_WIN32(ret);
1967 RegCloseKey(hUserKey);
1971 TRACE("returning 0x%08x\n", hr);
1975 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
1977 static const UINT folders[] = {
1988 CSIDL_DESKTOPDIRECTORY,
1992 CSIDL_LOCAL_APPDATA,
1993 CSIDL_INTERNET_CACHE,
1999 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
2000 LPCWSTR pUserShellFolderPath, pShellFolderPath;
2005 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
2008 hToken = (HANDLE)-1;
2009 hRootKey = HKEY_USERS;
2010 strcpyW(userShellFolderPath, DefaultW);
2011 PathAddBackslashW(userShellFolderPath);
2012 strcatW(userShellFolderPath, szSHUserFolders);
2013 pUserShellFolderPath = userShellFolderPath;
2014 strcpyW(shellFolderPath, DefaultW);
2015 PathAddBackslashW(shellFolderPath);
2016 strcatW(shellFolderPath, szSHFolders);
2017 pShellFolderPath = shellFolderPath;
2022 hRootKey = HKEY_CURRENT_USER;
2023 pUserShellFolderPath = szSHUserFolders;
2024 pShellFolderPath = szSHFolders;
2027 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
2028 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
2029 TRACE("returning 0x%08x\n", hr);
2033 static HRESULT _SHRegisterCommonShellFolders(void)
2035 static const UINT folders[] = {
2036 CSIDL_COMMON_STARTMENU,
2037 CSIDL_COMMON_PROGRAMS,
2038 CSIDL_COMMON_STARTUP,
2039 CSIDL_COMMON_DESKTOPDIRECTORY,
2040 CSIDL_COMMON_FAVORITES,
2041 CSIDL_COMMON_APPDATA,
2042 CSIDL_COMMON_TEMPLATES,
2043 CSIDL_COMMON_DOCUMENTS,
2048 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
2049 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
2050 TRACE("returning 0x%08x\n", hr);
2054 /******************************************************************************
2055 * _SHAppendToUnixPath [Internal]
2057 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
2058 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
2059 * and replaces backslashes with slashes.
2062 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
2063 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
2069 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
2070 WCHAR wszSubPath[MAX_PATH];
2071 int cLen = strlen(szBasePath);
2074 if (IS_INTRESOURCE(pwszSubPath)) {
2075 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
2076 /* Fall back to hard coded defaults. */
2077 switch (LOWORD(pwszSubPath)) {
2079 lstrcpyW(wszSubPath, PersonalW);
2082 lstrcpyW(wszSubPath, My_MusicW);
2084 case IDS_MYPICTURES:
2085 lstrcpyW(wszSubPath, My_PicturesW);
2088 lstrcpyW(wszSubPath, My_VideoW);
2091 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
2096 lstrcpyW(wszSubPath, pwszSubPath);
2099 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
2101 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
2102 FILENAME_MAX - cLen, NULL, NULL))
2107 pBackslash = szBasePath + cLen;
2108 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
2113 /******************************************************************************
2114 * _SHCreateSymbolicLinks [Internal]
2116 * Sets up symbol links for various shell folders to point into the users home
2117 * directory. We do an educated guess about what the user would probably want:
2118 * - If there is a 'My Documents' directory in $HOME, the user probably wants
2119 * wine's 'My Documents' to point there. Furthermore, we imply that the user
2120 * is a Windows lover and has no problem with wine creating 'My Pictures',
2121 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
2122 * do not already exits. We put appropriate symbolic links in place for those,
2124 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2125 * point directly to $HOME. We assume the user to be a unix hacker who does not
2126 * want wine to create anything anywhere besides the .wine directory. So, if
2127 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2128 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
2129 * directory, and try to link to that. If that fails, then we symlink to
2130 * $HOME directly. The same holds fo 'My Pictures' and 'My Video'.
2131 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
2132 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
2134 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2136 static void _SHCreateSymbolicLinks(void)
2138 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEO, IDS_MYMUSIC }, i;
2139 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
2140 static const char * const xdg_dirs[] = { "PICTURES", "VIDEOS", "MUSIC", "DESKTOP" };
2141 static const unsigned int num = sizeof(xdg_dirs) / sizeof(xdg_dirs[0]);
2142 WCHAR wszTempPath[MAX_PATH];
2143 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
2144 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
2145 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
2146 struct stat statFolder;
2147 const char *pszHome;
2149 char ** xdg_results;
2150 char * xdg_desktop_dir;
2152 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2153 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
2154 SHGFP_TYPE_DEFAULT, wszTempPath);
2155 if (FAILED(hr)) return;
2156 pszPersonal = wine_get_unix_file_name(wszTempPath);
2157 if (!pszPersonal) return;
2159 hr = XDG_UserDirLookup(xdg_dirs, num, &xdg_results);
2160 if (FAILED(hr)) xdg_results = NULL;
2162 pszHome = getenv("HOME");
2163 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode)) {
2164 strcpy(szPersonalTarget, pszHome);
2165 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
2166 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2168 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2169 * 'My Music' subfolders or fail silently if they already exist. */
2170 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2171 strcpy(szMyStuffTarget, szPersonalTarget);
2172 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2173 mkdir(szMyStuffTarget, 0777);
2178 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2179 strcpy(szPersonalTarget, pszHome);
2182 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2184 symlink(szPersonalTarget, pszPersonal);
2188 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2189 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2190 strcpy(szPersonalTarget, pszPersonal);
2191 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2192 strcpy(szMyStuffTarget, szPersonalTarget);
2193 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
2194 mkdir(szMyStuffTarget, 0777);
2198 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
2199 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
2200 /* Create the current 'My Whatever' folder and get it's unix path. */
2201 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
2202 SHGFP_TYPE_DEFAULT, wszTempPath);
2203 if (FAILED(hr)) continue;
2204 pszMyStuff = wine_get_unix_file_name(wszTempPath);
2205 if (!pszMyStuff) continue;
2207 strcpy(szMyStuffTarget, szPersonalTarget);
2208 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
2209 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2211 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2213 symlink(szMyStuffTarget, pszMyStuff);
2218 if (xdg_results && xdg_results[i])
2220 /* the folder specified by XDG_XXX_DIR exists, link to it. */
2221 symlink(xdg_results[i], pszMyStuff);
2225 /* Else link to where 'My Documents' itself links to. */
2226 symlink(szPersonalTarget, pszMyStuff);
2229 HeapFree(GetProcessHeap(), 0, pszMyStuff);
2232 /* Last but not least, the Desktop folder */
2234 strcpy(szDesktopTarget, pszHome);
2236 strcpy(szDesktopTarget, pszPersonal);
2237 HeapFree(GetProcessHeap(), 0, pszPersonal);
2239 xdg_desktop_dir = xdg_results ? xdg_results[num - 1] : NULL;
2240 if (xdg_desktop_dir ||
2241 (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
2242 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode)))
2244 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
2245 SHGFP_TYPE_DEFAULT, wszTempPath);
2246 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
2249 if (xdg_desktop_dir)
2250 symlink(xdg_desktop_dir, pszDesktop);
2252 symlink(szDesktopTarget, pszDesktop);
2253 HeapFree(GetProcessHeap(), 0, pszDesktop);
2257 /* Free resources allocated by XDG_UserDirLookup() */
2260 for (i = 0; i < num; i++)
2261 HeapFree(GetProcessHeap(), 0, xdg_results[i]);
2262 HeapFree(GetProcessHeap(), 0, xdg_results);
2266 /* Register the default values in the registry, as some apps seem to depend
2267 * on their presence. The set registered was taken from Windows XP.
2269 HRESULT SHELL_RegisterShellFolders(void)
2273 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2274 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
2275 * _SHRegister*ShellFolders() functions will find everything nice and clean
2276 * and thus will not attempt to create them in the profile directory. */
2277 _SHCreateSymbolicLinks();
2279 hr = _SHRegisterUserShellFolders(TRUE);
2281 hr = _SHRegisterUserShellFolders(FALSE);
2283 hr = _SHRegisterCommonShellFolders();
2287 /*************************************************************************
2288 * SHGetSpecialFolderPathA [SHELL32.@]
2290 BOOL WINAPI SHGetSpecialFolderPathA (
2296 return (SHGetFolderPathA(
2298 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2301 szPath)) == S_OK ? TRUE : FALSE;
2304 /*************************************************************************
2305 * SHGetSpecialFolderPathW
2307 BOOL WINAPI SHGetSpecialFolderPathW (
2313 return (SHGetFolderPathW(
2315 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2318 szPath)) == S_OK ? TRUE : FALSE;
2321 /*************************************************************************
2322 * SHGetSpecialFolderPath (SHELL32.175)
2324 BOOL WINAPI SHGetSpecialFolderPathAW (
2331 if (SHELL_OsIsUnicode())
2332 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
2333 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
2336 /*************************************************************************
2337 * SHGetFolderLocation [SHELL32.@]
2339 * Gets the folder locations from the registry and creates a pidl.
2343 * nFolder [I] CSIDL_xxxxx
2344 * hToken [I] token representing user, or NULL for current user, or -1 for
2346 * dwReserved [I] must be zero
2347 * ppidl [O] PIDL of a special folder
2351 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2354 * Creates missing reg keys and directories.
2355 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2356 * virtual folders that are handled here.
2358 HRESULT WINAPI SHGetFolderLocation(
2363 LPITEMIDLIST *ppidl)
2365 HRESULT hr = E_INVALIDARG;
2367 TRACE("%p 0x%08x %p 0x%08x %p\n",
2368 hwndOwner, nFolder, hToken, dwReserved, ppidl);
2371 return E_INVALIDARG;
2373 return E_INVALIDARG;
2375 /* The virtual folders' locations are not user-dependent */
2380 *ppidl = _ILCreateDesktop();
2383 case CSIDL_PERSONAL:
2384 *ppidl = _ILCreateMyDocuments();
2387 case CSIDL_INTERNET:
2388 *ppidl = _ILCreateIExplore();
2391 case CSIDL_CONTROLS:
2392 *ppidl = _ILCreateControlPanel();
2395 case CSIDL_PRINTERS:
2396 *ppidl = _ILCreatePrinters();
2399 case CSIDL_BITBUCKET:
2400 *ppidl = _ILCreateBitBucket();
2404 *ppidl = _ILCreateMyComputer();
2408 *ppidl = _ILCreateNetwork();
2413 WCHAR szPath[MAX_PATH];
2415 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
2416 SHGFP_TYPE_CURRENT, szPath);
2421 TRACE("Value=%s\n", debugstr_w(szPath));
2422 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
2424 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
2426 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2427 * version 6.0 returns E_FAIL for nonexistent paths
2436 TRACE("-- (new pidl %p)\n",*ppidl);
2440 /*************************************************************************
2441 * SHGetSpecialFolderLocation [SHELL32.@]
2444 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2447 HRESULT WINAPI SHGetSpecialFolderLocation(
2450 LPITEMIDLIST * ppidl)
2452 HRESULT hr = E_INVALIDARG;
2454 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
2457 return E_INVALIDARG;
2459 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);