Don't hardcode c:\windows paths in msi.dll.
[wine.git] / dlls / shell32 / shellpath.c
bloba8d6a2bc36dc4fcd0975f44237a04b8841da42fb
1 /*
2 * Path Functions
4 * Copyright 1998, 1999, 2000 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * NOTES:
22 * Many of these functions are in SHLWAPI.DLL also
26 #include "config.h"
27 #include "wine/port.h"
29 #include <stdarg.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include "wine/debug.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winnls.h"
36 #include "winreg.h"
37 #include "wingdi.h"
38 #include "winuser.h"
40 #include "shlobj.h"
41 #include "shell32_main.h"
42 #include "undocshell.h"
43 #include "pidl.h"
44 #include "wine/unicode.h"
45 #include "shlwapi.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 ########## Combining and Constructing paths ##########
53 /*************************************************************************
54 * PathAppend [SHELL32.36]
56 BOOL WINAPI PathAppendAW(
57 LPVOID lpszPath1,
58 LPCVOID lpszPath2)
60 if (SHELL_OsIsUnicode())
61 return PathAppendW(lpszPath1, lpszPath2);
62 return PathAppendA(lpszPath1, lpszPath2);
65 /*************************************************************************
66 * PathCombine [SHELL32.37]
68 LPVOID WINAPI PathCombineAW(
69 LPVOID szDest,
70 LPCVOID lpszDir,
71 LPCVOID lpszFile)
73 if (SHELL_OsIsUnicode())
74 return PathCombineW( szDest, lpszDir, lpszFile );
75 return PathCombineA( szDest, lpszDir, lpszFile );
78 /*************************************************************************
79 * PathAddBackslash [SHELL32.32]
81 LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
83 if(SHELL_OsIsUnicode())
84 return PathAddBackslashW(lpszPath);
85 return PathAddBackslashA(lpszPath);
88 /*************************************************************************
89 * PathBuildRoot [SHELL32.30]
91 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
93 if(SHELL_OsIsUnicode())
94 return PathBuildRootW(lpszPath, drive);
95 return PathBuildRootA(lpszPath, drive);
99 Extracting Component Parts
102 /*************************************************************************
103 * PathFindFileName [SHELL32.34]
105 LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
107 if(SHELL_OsIsUnicode())
108 return PathFindFileNameW(lpszPath);
109 return PathFindFileNameA(lpszPath);
112 /*************************************************************************
113 * PathFindExtension [SHELL32.31]
115 LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
117 if (SHELL_OsIsUnicode())
118 return PathFindExtensionW(lpszPath);
119 return PathFindExtensionA(lpszPath);
123 /*************************************************************************
124 * PathGetExtensionA [internal]
126 * NOTES
127 * exported by ordinal
128 * return value points to the first char after the dot
130 static LPSTR PathGetExtensionA(LPCSTR lpszPath)
132 TRACE("(%s)\n",lpszPath);
134 lpszPath = PathFindExtensionA(lpszPath);
135 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
138 /*************************************************************************
139 * PathGetExtensionW [internal]
141 static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
143 TRACE("(%s)\n",debugstr_w(lpszPath));
145 lpszPath = PathFindExtensionW(lpszPath);
146 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
149 /*************************************************************************
150 * PathGetExtension [SHELL32.158]
152 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath,DWORD void1, DWORD void2)
154 if (SHELL_OsIsUnicode())
155 return PathGetExtensionW(lpszPath);
156 return PathGetExtensionA(lpszPath);
159 /*************************************************************************
160 * PathGetArgs [SHELL32.52]
162 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
164 if (SHELL_OsIsUnicode())
165 return PathGetArgsW(lpszPath);
166 return PathGetArgsA(lpszPath);
169 /*************************************************************************
170 * PathGetDriveNumber [SHELL32.57]
172 int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
174 if (SHELL_OsIsUnicode())
175 return PathGetDriveNumberW(lpszPath);
176 return PathGetDriveNumberA(lpszPath);
179 /*************************************************************************
180 * PathRemoveFileSpec [SHELL32.35]
182 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
184 if (SHELL_OsIsUnicode())
185 return PathRemoveFileSpecW(lpszPath);
186 return PathRemoveFileSpecA(lpszPath);
189 /*************************************************************************
190 * PathStripPath [SHELL32.38]
192 void WINAPI PathStripPathAW(LPVOID lpszPath)
194 if (SHELL_OsIsUnicode())
195 PathStripPathW(lpszPath);
196 else
197 PathStripPathA(lpszPath);
200 /*************************************************************************
201 * PathStripToRoot [SHELL32.50]
203 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
205 if (SHELL_OsIsUnicode())
206 return PathStripToRootW(lpszPath);
207 return PathStripToRootA(lpszPath);
210 /*************************************************************************
211 * PathRemoveArgs [SHELL32.251]
213 void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
215 if (SHELL_OsIsUnicode())
216 PathRemoveArgsW(lpszPath);
217 else
218 PathRemoveArgsA(lpszPath);
221 /*************************************************************************
222 * PathRemoveExtension [SHELL32.250]
224 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
226 if (SHELL_OsIsUnicode())
227 PathRemoveExtensionW(lpszPath);
228 else
229 PathRemoveExtensionA(lpszPath);
234 Path Manipulations
237 /*************************************************************************
238 * PathGetShortPathA [internal]
240 static void PathGetShortPathA(LPSTR pszPath)
242 CHAR path[MAX_PATH];
244 TRACE("%s\n", pszPath);
246 if (GetShortPathNameA(pszPath, path, MAX_PATH))
248 lstrcpyA(pszPath, path);
252 /*************************************************************************
253 * PathGetShortPathW [internal]
255 static void PathGetShortPathW(LPWSTR pszPath)
257 WCHAR path[MAX_PATH];
259 TRACE("%s\n", debugstr_w(pszPath));
261 if (GetShortPathNameW(pszPath, path, MAX_PATH))
263 lstrcpyW(pszPath, path);
267 /*************************************************************************
268 * PathGetShortPath [SHELL32.92]
270 VOID WINAPI PathGetShortPathAW(LPVOID pszPath)
272 if(SHELL_OsIsUnicode())
273 PathGetShortPathW(pszPath);
274 PathGetShortPathA(pszPath);
277 /*************************************************************************
278 * PathRemoveBlanks [SHELL32.33]
280 void WINAPI PathRemoveBlanksAW(LPVOID str)
282 if(SHELL_OsIsUnicode())
283 PathRemoveBlanksW(str);
284 else
285 PathRemoveBlanksA(str);
288 /*************************************************************************
289 * PathQuoteSpaces [SHELL32.55]
291 VOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
293 if(SHELL_OsIsUnicode())
294 PathQuoteSpacesW(lpszPath);
295 else
296 PathQuoteSpacesA(lpszPath);
299 /*************************************************************************
300 * PathUnquoteSpaces [SHELL32.56]
302 VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
304 if(SHELL_OsIsUnicode())
305 PathUnquoteSpacesW(str);
306 else
307 PathUnquoteSpacesA(str);
310 /*************************************************************************
311 * PathParseIconLocation [SHELL32.249]
313 int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
315 if(SHELL_OsIsUnicode())
316 return PathParseIconLocationW(lpszPath);
317 return PathParseIconLocationA(lpszPath);
321 ########## Path Testing ##########
323 /*************************************************************************
324 * PathIsUNC [SHELL32.39]
326 BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
328 if (SHELL_OsIsUnicode())
329 return PathIsUNCW( lpszPath );
330 return PathIsUNCA( lpszPath );
333 /*************************************************************************
334 * PathIsRelative [SHELL32.40]
336 BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
338 if (SHELL_OsIsUnicode())
339 return PathIsRelativeW( lpszPath );
340 return PathIsRelativeA( lpszPath );
343 /*************************************************************************
344 * PathIsRoot [SHELL32.29]
346 BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
348 if (SHELL_OsIsUnicode())
349 return PathIsRootW(lpszPath);
350 return PathIsRootA(lpszPath);
353 /*************************************************************************
354 * PathIsExeA [internal]
356 static BOOL PathIsExeA (LPCSTR lpszPath)
358 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
359 int i;
360 static const char * const lpszExtensions[] =
361 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
363 TRACE("path=%s\n",lpszPath);
365 for(i=0; lpszExtensions[i]; i++)
366 if (!strcasecmp(lpszExtension,lpszExtensions[i])) return TRUE;
368 return FALSE;
371 /*************************************************************************
372 * PathIsExeW [internal]
374 static BOOL PathIsExeW (LPCWSTR lpszPath)
376 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
377 int i;
378 static const WCHAR lpszExtensions[][4] =
379 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
380 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
381 {'s','c','r','\0'}, {'\0'} };
383 TRACE("path=%s\n",debugstr_w(lpszPath));
385 for(i=0; lpszExtensions[i][0]; i++)
386 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
388 return FALSE;
391 /*************************************************************************
392 * PathIsExe [SHELL32.43]
394 BOOL WINAPI PathIsExeAW (LPCVOID path)
396 if (SHELL_OsIsUnicode())
397 return PathIsExeW (path);
398 return PathIsExeA(path);
401 /*************************************************************************
402 * PathIsDirectory [SHELL32.159]
404 BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
406 if (SHELL_OsIsUnicode())
407 return PathIsDirectoryW (lpszPath);
408 return PathIsDirectoryA (lpszPath);
411 /*************************************************************************
412 * PathFileExists [SHELL32.45]
414 BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
416 if (SHELL_OsIsUnicode())
417 return PathFileExistsW (lpszPath);
418 return PathFileExistsA (lpszPath);
421 /*************************************************************************
422 * PathMatchSpec [SHELL32.46]
424 BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
426 if (SHELL_OsIsUnicode())
427 return PathMatchSpecW( name, mask );
428 return PathMatchSpecA( name, mask );
431 /*************************************************************************
432 * PathIsSameRoot [SHELL32.650]
434 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
436 if (SHELL_OsIsUnicode())
437 return PathIsSameRootW(lpszPath1, lpszPath2);
438 return PathIsSameRootA(lpszPath1, lpszPath2);
441 /*************************************************************************
442 * IsLFNDriveA [SHELL32.41]
444 BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
446 DWORD fnlen;
448 if (!GetVolumeInformationA(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
449 return FALSE;
450 return fnlen > 12;
453 /*************************************************************************
454 * IsLFNDriveW [SHELL32.42]
456 BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
458 DWORD fnlen;
460 if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
461 return FALSE;
462 return fnlen > 12;
465 /*************************************************************************
466 * IsLFNDrive [SHELL32.119]
468 BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath)
470 if (SHELL_OsIsUnicode())
471 return IsLFNDriveW(lpszPath);
472 return IsLFNDriveA(lpszPath);
476 ########## Creating Something Unique ##########
478 /*************************************************************************
479 * PathMakeUniqueNameA [internal]
481 BOOL WINAPI PathMakeUniqueNameA(
482 LPSTR lpszBuffer,
483 DWORD dwBuffSize,
484 LPCSTR lpszShortName,
485 LPCSTR lpszLongName,
486 LPCSTR lpszPathName)
488 FIXME("%p %lu %s %s %s stub\n",
489 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
490 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
491 return TRUE;
494 /*************************************************************************
495 * PathMakeUniqueNameW [internal]
497 BOOL WINAPI PathMakeUniqueNameW(
498 LPWSTR lpszBuffer,
499 DWORD dwBuffSize,
500 LPCWSTR lpszShortName,
501 LPCWSTR lpszLongName,
502 LPCWSTR lpszPathName)
504 FIXME("%p %lu %s %s %s stub\n",
505 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
506 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
507 return TRUE;
510 /*************************************************************************
511 * PathMakeUniqueName [SHELL32.47]
513 BOOL WINAPI PathMakeUniqueNameAW(
514 LPVOID lpszBuffer,
515 DWORD dwBuffSize,
516 LPCVOID lpszShortName,
517 LPCVOID lpszLongName,
518 LPCVOID lpszPathName)
520 if (SHELL_OsIsUnicode())
521 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
522 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
525 /*************************************************************************
526 * PathYetAnotherMakeUniqueName [SHELL32.75]
528 * NOTES
529 * exported by ordinal
531 BOOL WINAPI PathYetAnotherMakeUniqueName(
532 LPWSTR lpszBuffer,
533 LPCWSTR lpszPathName,
534 LPCWSTR lpszShortName,
535 LPCWSTR lpszLongName)
537 FIXME("(%p, %s, %s ,%s):stub.\n",
538 lpszBuffer, debugstr_w(lpszPathName), debugstr_w(lpszShortName), debugstr_w(lpszLongName));
539 return TRUE;
544 ########## cleaning and resolving paths ##########
547 /*************************************************************************
548 * PathFindOnPath [SHELL32.145]
550 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID sOtherDirs)
552 if (SHELL_OsIsUnicode())
553 return PathFindOnPathW(sFile, (LPCWSTR *)sOtherDirs);
554 return PathFindOnPathA(sFile, (LPCSTR *)sOtherDirs);
557 /*************************************************************************
558 * PathCleanupSpec [SHELL32.171]
560 DWORD WINAPI PathCleanupSpecAW (LPCVOID x, LPVOID y)
562 FIXME("(%p, %p) stub\n",x,y);
563 return TRUE;
566 /*************************************************************************
567 * PathQualifyA [SHELL32]
569 BOOL WINAPI PathQualifyA(LPCSTR pszPath)
571 FIXME("%s\n",pszPath);
572 return 0;
575 /*************************************************************************
576 * PathQualifyW [SHELL32]
578 BOOL WINAPI PathQualifyW(LPCWSTR pszPath)
580 FIXME("%s\n",debugstr_w(pszPath));
581 return 0;
584 /*************************************************************************
585 * PathQualify [SHELL32.49]
587 BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
589 if (SHELL_OsIsUnicode())
590 return PathQualifyW(pszPath);
591 return PathQualifyA(pszPath);
594 /*************************************************************************
595 * PathResolveA [SHELL32.51]
597 BOOL WINAPI PathResolveA(
598 LPSTR lpszPath,
599 LPCSTR *alpszPaths,
600 DWORD dwFlags)
602 FIXME("(%s,%p,0x%08lx),stub!\n",
603 lpszPath, *alpszPaths, dwFlags);
604 return 0;
607 /*************************************************************************
608 * PathResolveW [SHELL32]
610 BOOL WINAPI PathResolveW(
611 LPWSTR lpszPath,
612 LPCWSTR *alpszPaths,
613 DWORD dwFlags)
615 FIXME("(%s,%p,0x%08lx),stub!\n",
616 debugstr_w(lpszPath), debugstr_w(*alpszPaths), dwFlags);
617 return 0;
620 /*************************************************************************
621 * PathResolve [SHELL32.51]
623 BOOL WINAPI PathResolveAW(
624 LPVOID lpszPath,
625 LPCVOID *alpszPaths,
626 DWORD dwFlags)
628 if (SHELL_OsIsUnicode())
629 return PathResolveW(lpszPath, (LPCWSTR*)alpszPaths, dwFlags);
630 return PathResolveA(lpszPath, (LPCSTR*)alpszPaths, dwFlags);
633 /*************************************************************************
634 * PathProcessCommandA [SHELL32.653]
636 HRESULT WINAPI PathProcessCommandA (
637 LPCSTR lpszPath,
638 LPSTR lpszBuff,
639 DWORD dwBuffSize,
640 DWORD dwFlags)
642 FIXME("%s %p 0x%04lx 0x%04lx stub\n",
643 lpszPath, lpszBuff, dwBuffSize, dwFlags);
644 strcpy(lpszBuff, lpszPath);
645 return 0;
648 /*************************************************************************
649 * PathProcessCommandW
651 HRESULT WINAPI PathProcessCommandW (
652 LPCWSTR lpszPath,
653 LPWSTR lpszBuff,
654 DWORD dwBuffSize,
655 DWORD dwFlags)
657 FIXME("(%s, %p, 0x%04lx, 0x%04lx) stub\n",
658 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
659 strcpyW(lpszBuff, lpszPath);
660 return 0;
663 /*************************************************************************
664 * PathProcessCommand (SHELL32.653)
666 HRESULT WINAPI PathProcessCommandAW (
667 LPCVOID lpszPath,
668 LPVOID lpszBuff,
669 DWORD dwBuffSize,
670 DWORD dwFlags)
672 if (SHELL_OsIsUnicode())
673 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
674 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
678 ########## special ##########
681 /*************************************************************************
682 * PathSetDlgItemPath (SHELL32.48)
684 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
686 if (SHELL_OsIsUnicode())
687 PathSetDlgItemPathW(hDlg, id, pszPath);
688 else
689 PathSetDlgItemPathA(hDlg, id, pszPath);
692 /*************************************************************************
693 * SHGetFolderPathW [SHELL32.@]
695 * converts csidl to path
698 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'};
699 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'};
700 static const WCHAR szSetup[] = {'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','e','t','u','p','\0'};
701 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'};
703 typedef struct
705 DWORD dwFlags;
706 HKEY hRootKey;
707 LPCSTR szValueName;
708 LPCSTR szDefaultPath; /* fallback string; sub dir of windows directory */
709 } CSIDL_DATA;
711 #define CSIDL_MYFLAG_SHFOLDER 1
712 #define CSIDL_MYFLAG_SETUP 2
713 #define CSIDL_MYFLAG_CURRVER 4
714 #define CSIDL_MYFLAG_RELATIVE 8
716 #define HKLM HKEY_LOCAL_MACHINE
717 #define HKCU HKEY_CURRENT_USER
718 #define HKEY_DISALLOWED (HKEY)0
719 #define HKEY_UNIMPLEMENTED (HKEY)1
720 #define HKEY_WINDOWSPATH (HKEY)2
721 #define HKEY_NONEXISTENT (HKEY)3
722 static const CSIDL_DATA CSIDL_Data[] =
724 { /* CSIDL_DESKTOP */
725 9, HKCU,
726 "Desktop",
727 "Desktop"
729 { /* CSIDL_INTERNET */
730 0, HKEY_DISALLOWED,
731 NULL,
732 NULL,
734 { /* CSIDL_PROGRAMS */
735 9, HKCU,
736 "Programs",
737 "Start Menu\\Programs",
739 { /* CSIDL_CONTROLS (.CPL files) */
740 10, HKLM,
741 "SysDir",
742 "SYSTEM"
744 { /* CSIDL_PRINTERS */
745 10, HKLM,
746 "SysDir",
747 "SYSTEM"
749 { /* CSIDL_PERSONAL */
750 1, HKCU,
751 "Personal",
752 "My Documents"
754 { /* CSIDL_FAVORITES */
755 9, HKCU,
756 "Favorites",
757 "Favorites"
759 { /* CSIDL_STARTUP */
760 9, HKCU,
761 "StartUp",
762 "Start Menu\\Programs\\StartUp"
764 { /* CSIDL_RECENT */
765 9, HKCU,
766 "Recent",
767 "Recent"
769 { /* CSIDL_SENDTO */
770 9, HKCU,
771 "SendTo",
772 "SendTo"
774 { /* CSIDL_BITBUCKET - Recycle Bin */
775 0, HKEY_DISALLOWED,
776 NULL,
777 NULL,
779 { /* CSIDL_STARTMENU */
780 9, HKCU,
781 "Start Menu",
782 "Start Menu"
784 { /* CSIDL_MYDOCUMENTS */
785 0, HKEY_UNIMPLEMENTED, /* FIXME */
786 NULL,
787 NULL
789 { /* CSIDL_MYMUSIC */
790 1, HKCU,
791 "My Music",
792 "My Documents\\My Music"
794 { /* CSIDL_MYVIDEO */
795 1, HKCU,
796 "My Video",
797 "My Documents\\My Video"
799 { /* unassigned */
800 0, 0,
801 NULL,
802 NULL,
804 { /* CSIDL_DESKTOPDIRECTORY */
805 9, HKCU,
806 "Desktop",
807 "Desktop"
809 { /* CSIDL_DRIVES */
810 0, HKEY_DISALLOWED,
811 NULL,
812 NULL,
814 { /* CSIDL_NETWORK */
815 0, HKEY_DISALLOWED,
816 NULL,
817 NULL,
819 { /* CSIDL_NETHOOD */
820 9, HKCU,
821 "NetHood",
822 "NetHood"
824 { /* CSIDL_FONTS */
825 9, HKCU,
826 "Fonts",
827 "Fonts"
829 { /* CSIDL_TEMPLATES */
830 9, HKCU,
831 "Templates",
832 "ShellNew"
834 { /* CSIDL_COMMON_STARTMENU */
835 9, HKLM,
836 "Common Start Menu",
837 "Start Menu"
839 { /* CSIDL_COMMON_PROGRAMS */
840 9, HKLM,
841 "Common Programs",
844 { /* CSIDL_COMMON_STARTUP */
845 9, HKLM,
846 "Common StartUp",
847 "All Users\\Start Menu\\Programs\\StartUp"
849 { /* CSIDL_COMMON_DESKTOPDIRECTORY */
850 9, HKLM,
851 "Common Desktop",
852 "Desktop"
854 { /* CSIDL_APPDATA */
855 9, HKCU,
856 "AppData",
857 "Application Data"
859 { /* CSIDL_PRINTHOOD */
860 9, HKCU,
861 "PrintHood",
862 "PrintHood"
864 { /* CSIDL_LOCAL_APPDATA (win2k only/undocumented) */
865 1, HKCU,
866 "Local AppData",
867 "Local Settings\\Application Data",
869 { /* CSIDL_ALTSTARTUP */
870 0, HKEY_NONEXISTENT,
871 NULL,
872 NULL
874 { /* CSIDL_COMMON_ALTSTARTUP */
875 0, HKEY_NONEXISTENT,
876 NULL,
877 NULL
879 { /* CSIDL_COMMON_FAVORITES */
880 9, HKCU,
881 "Favorites",
882 "Favorites"
884 { /* CSIDL_INTERNET_CACHE (32) */
885 9, HKCU,
886 "Cache",
887 "Temporary Internet Files"
889 { /* CSIDL_COOKIES (33) */
890 9, HKCU,
891 "Cookies",
892 "Cookies"
894 { /* CSIDL_HISTORY (34) */
895 9, HKCU,
896 "History",
897 "History"
899 { /* CSIDL_COMMON_APPDATA */
900 9, HKLM,
901 "Common AppData",
902 "All Users\\Application Data"
904 { /* CSIDL_WINDOWS */
905 2, HKLM,
906 "WinDir",
907 "Windows"
909 { /* CSIDL_SYSTEM */
910 10, HKLM,
911 "SysDir",
912 "SYSTEM"
914 { /* CSIDL_PROGRAM_FILES */
915 4, HKLM,
916 "ProgramFilesDir",
917 "Program Files"
919 { /* CSIDL_MYPICTURES */
920 1, HKCU,
921 "My Pictures",
922 "My Documents\\My Pictures"
924 { /* CSIDL_PROFILE */
925 10, HKLM,
926 "WinDir", /* correct ? */
929 { /* CSIDL_SYSTEMX86 */
930 10, HKLM,
931 "SysDir",
932 "SYSTEM"
934 { /* CSIDL_PROGRAM_FILESX86 */
935 4, HKLM,
936 "ProgramFilesDir",
937 "Program Files"
939 { /* CSIDL_PROGRAM_FILES_COMMON */
940 4, HKLM,
941 "CommonFilesDir",
942 "Program Files\\Common Files" /* ? */
944 { /* CSIDL_PROGRAM_FILES_COMMONX86 */
945 4, HKLM,
946 "CommonFilesDir",
947 "Program Files\\Common Files" /* ? */
949 { /* CSIDL_COMMON_TEMPLATES */
950 9, HKLM,
951 "Common Templates",
952 /*"Documents and Settings\\"*/"All Users\\Templates"
954 { /* CSIDL_COMMON_DOCUMENTS */
955 9, HKLM,
956 "Common Documents",
957 /*"Documents and Settings\\"*/"All Users\\Documents"
959 { /* CSIDL_COMMON_ADMINTOOLS */
960 9, HKLM,
961 "Common Administrative Tools",
962 /*"Documents and Settings\\"*/"All Users\\Start Menu\\Programs\\Administrative Tools"
964 { /* CSIDL_ADMINTOOLS */
965 9, HKCU,
966 "Administrative Tools",
967 "Start Menu\\Programs\\Administrative Tools"
969 { /* CSIDL_CONNECTIONS */
970 0, HKEY_DISALLOWED,
971 NULL,
972 NULL
974 { /* unassigned 32 */
975 0, HKEY_DISALLOWED,
976 NULL,
977 NULL
979 { /* unassigned 33 */
980 0, HKEY_DISALLOWED,
981 NULL,
982 NULL
984 { /* unassigned 34 */
985 0, HKEY_DISALLOWED,
986 NULL,
987 NULL
989 { /* CSIDL_COMMON_MUSIC */
990 9, HKLM,
991 "CommonMusic",
992 /*"Documents and Settings\\"*/"All Users\\Documents\\My Music"
994 { /* CSIDL_COMMON_PICTURES */
995 9, HKLM,
996 "CommonPictures",
997 /*"Documents and Settings\\"*/"All Users\\Documents\\My Pictures"
999 { /* CSIDL_COMMON_VIDEO */
1000 9, HKLM,
1001 "CommonVideo",
1002 /*"Documents and Settings\\"*/"All Users\\Documents\\My Video"
1004 { /* CSIDL_RESOURCES */
1005 0, HKEY_WINDOWSPATH,
1006 NULL,
1007 "Resources"
1009 { /* CSIDL_RESOURCES_LOCALIZED */
1010 0, 0, /* FIXME */
1011 NULL,
1012 NULL
1014 { /* CSIDL_COMMON_OEM_LINKS */
1015 0, 0, /* FIXME */
1016 NULL,
1017 NULL
1019 { /* CSIDL_CDBURN_AREA */
1020 1, HKCU,
1021 "CD Burning",
1022 "Local Settings\\Application Data\\Microsoft\\CD Burning"
1024 { /* unassigned 3C */
1025 0, 0,
1026 NULL,
1027 NULL
1029 { /* CSIDL_COMPUTERSNEARME */
1030 0, 0, /* FIXME */
1031 NULL,
1032 NULL
1034 { /* CSIDL_PROFILES */
1035 0, 0, /* FIXME */
1036 NULL,
1037 NULL
1040 #undef HKCU
1041 #undef HKLM
1043 /**********************************************************************/
1045 HRESULT WINAPI SHGetFolderPathW(
1046 HWND hwndOwner,
1047 int csidl,
1048 HANDLE hToken, /* [in] FIXME: get paths for specific user */
1049 DWORD dwFlags, /* [in] FIXME: SHGFP_TYPE_CURRENT|SHGFP_TYPE_DEFAULT */
1050 LPWSTR pszPath)
1052 WCHAR szValueName[MAX_PATH], szDefaultPath[MAX_PATH], szBuildPath[MAX_PATH];
1053 HKEY hRootKey, hKey;
1054 DWORD dwCsidlFlags;
1055 DWORD dwType, dwDisp, dwPathLen = MAX_PATH;
1056 DWORD folder = csidl & CSIDL_FOLDER_MASK;
1057 WCHAR *p;
1059 TRACE("%p,%p,csidl=0x%04x\n", hwndOwner,pszPath,csidl);
1061 if (!pszPath)
1062 return E_INVALIDARG;
1064 *pszPath = '\0';
1065 if ((folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0])) ||
1066 (CSIDL_Data[folder].hRootKey == HKEY_DISALLOWED))
1067 return E_INVALIDARG;
1068 if (CSIDL_Data[folder].hRootKey == HKEY_UNIMPLEMENTED)
1070 FIXME("folder 0x%04lx unknown, please add.\n", folder);
1071 return E_FAIL;
1073 if (CSIDL_Data[folder].hRootKey == HKEY_NONEXISTENT)
1074 return S_FALSE;
1076 /* Special case for some values that don't exist in registry */
1077 if (CSIDL_Data[folder].hRootKey == HKEY_WINDOWSPATH)
1079 GetWindowsDirectoryW(pszPath, MAX_PATH);
1080 PathAddBackslashW(pszPath);
1081 strcatW(pszPath, szDefaultPath);
1082 return S_OK;
1085 dwCsidlFlags = CSIDL_Data[folder].dwFlags;
1086 hRootKey = CSIDL_Data[folder].hRootKey;
1087 MultiByteToWideChar(CP_ACP, 0, CSIDL_Data[folder].szValueName, -1, szValueName, MAX_PATH);
1088 MultiByteToWideChar(CP_ACP, 0, CSIDL_Data[folder].szDefaultPath, -1, szDefaultPath, MAX_PATH);
1090 if (dwCsidlFlags & CSIDL_MYFLAG_SHFOLDER)
1092 /* user shell folders */
1093 if (RegCreateKeyExW(hRootKey,szSHUserFolders,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,&dwDisp)) return E_FAIL;
1095 if (RegQueryValueExW(hKey,szValueName,NULL,&dwType,(LPBYTE)pszPath,&dwPathLen))
1097 RegCloseKey(hKey);
1099 /* shell folders */
1100 if (RegCreateKeyExW(hRootKey,szSHFolders,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,&dwDisp)) return E_FAIL;
1102 if (RegQueryValueExW(hKey,szValueName,NULL,&dwType,(LPBYTE)pszPath,&dwPathLen))
1105 /* value not existing */
1106 if (dwCsidlFlags & CSIDL_MYFLAG_RELATIVE)
1108 GetWindowsDirectoryW(pszPath, MAX_PATH);
1109 PathAddBackslashW(pszPath);
1110 strcatW(pszPath, szDefaultPath);
1112 else
1114 GetSystemDirectoryW(pszPath, MAX_PATH);
1115 strcpyW(pszPath + 3, szDefaultPath);
1117 dwType=REG_SZ;
1118 RegSetValueExW(hKey,szValueName,0,REG_SZ,(LPBYTE)pszPath,
1119 (strlenW(pszPath)+1)*sizeof(WCHAR));
1122 RegCloseKey(hKey);
1124 else
1126 LPCWSTR pRegPath;
1128 if (dwCsidlFlags & CSIDL_MYFLAG_SETUP)
1129 pRegPath = szSetup;
1130 else if (dwCsidlFlags & CSIDL_MYFLAG_CURRVER)
1131 pRegPath = szCurrentVersion;
1132 else
1134 ERR("folder settings broken, please correct !\n");
1135 return E_FAIL;
1138 if (RegCreateKeyExW(hRootKey,pRegPath,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,&dwDisp)) return E_FAIL;
1140 if (RegQueryValueExW(hKey,szValueName,NULL,&dwType,(LPBYTE)pszPath,&dwPathLen))
1142 /* value not existing */
1143 if (dwCsidlFlags & CSIDL_MYFLAG_RELATIVE)
1145 GetWindowsDirectoryW(pszPath, MAX_PATH);
1146 PathAddBackslashW(pszPath);
1147 strcatW(pszPath, szDefaultPath);
1149 else
1151 GetSystemDirectoryW(pszPath, MAX_PATH);
1152 strcpyW(pszPath + 3, szDefaultPath);
1154 dwType=REG_SZ;
1155 RegSetValueExW(hKey,szValueName,0,REG_SZ,(LPBYTE)pszPath,
1156 (strlenW(pszPath)+1)*sizeof(WCHAR));
1158 RegCloseKey(hKey);
1161 /* expand paths like %USERPROFILE% */
1162 if (dwType == REG_EXPAND_SZ)
1164 ExpandEnvironmentStringsW(pszPath, szDefaultPath, MAX_PATH);
1165 strcpyW(pszPath, szDefaultPath);
1168 /* if we don't care about existing directories we are ready */
1169 if(csidl & CSIDL_FLAG_DONT_VERIFY) return S_OK;
1171 if (PathFileExistsW(pszPath)) return S_OK;
1173 /* not existing but we are not allowed to create it */
1174 if (!(csidl & CSIDL_FLAG_CREATE)) return E_FAIL;
1176 /* create directory/directories */
1177 strcpyW(szBuildPath, pszPath);
1178 p = strchrW(szBuildPath, '\\');
1179 while (p)
1181 *p = 0;
1182 if (!PathFileExistsW(szBuildPath))
1184 if (!CreateDirectoryW(szBuildPath,NULL))
1186 ERR("Failed to create directory '%s'.\n", debugstr_w(pszPath));
1187 return E_FAIL;
1190 *p = '\\';
1191 p = strchrW(p+1, '\\');
1193 /* last component must be created too. */
1194 if (!PathFileExistsW(szBuildPath))
1196 if (!CreateDirectoryW(szBuildPath,NULL))
1198 ERR("Failed to create directory '%s'.\n", debugstr_w(pszPath));
1199 return E_FAIL;
1203 TRACE("Created missing system directory '%s'\n", debugstr_w(pszPath));
1204 return S_OK;
1207 /*************************************************************************
1208 * SHGetFolderPathA [SHELL32.@]
1210 HRESULT WINAPI SHGetFolderPathA(
1211 HWND hwndOwner,
1212 int csidl,
1213 HANDLE hToken,
1214 DWORD dwFlags,
1215 LPSTR pszPath)
1217 WCHAR szTemp[MAX_PATH];
1218 HRESULT hr;
1220 if (!pszPath)
1221 return E_INVALIDARG;
1223 *pszPath = '\0';
1224 hr = SHGetFolderPathW(hwndOwner, csidl, hToken, dwFlags, szTemp);
1225 if (SUCCEEDED(hr))
1226 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
1227 NULL);
1229 TRACE("%p,%p,csidl=0x%04x\n",hwndOwner,pszPath,csidl);
1231 return hr;
1234 /*************************************************************************
1235 * SHGetSpecialFolderPathA [SHELL32.@]
1237 BOOL WINAPI SHGetSpecialFolderPathA (
1238 HWND hwndOwner,
1239 LPSTR szPath,
1240 int csidl,
1241 BOOL bCreate)
1243 return (SHGetFolderPathA(
1244 hwndOwner,
1245 csidl + (bCreate ? CSIDL_FLAG_CREATE : 0),
1246 NULL,
1248 szPath)) == S_OK ? TRUE : FALSE;
1251 /*************************************************************************
1252 * SHGetSpecialFolderPathW
1254 BOOL WINAPI SHGetSpecialFolderPathW (
1255 HWND hwndOwner,
1256 LPWSTR szPath,
1257 int csidl,
1258 BOOL bCreate)
1260 return (SHGetFolderPathW(
1261 hwndOwner,
1262 csidl + (bCreate ? CSIDL_FLAG_CREATE : 0),
1263 NULL,
1265 szPath)) == S_OK ? TRUE : FALSE;
1268 /*************************************************************************
1269 * SHGetSpecialFolderPath (SHELL32.175)
1271 BOOL WINAPI SHGetSpecialFolderPathAW (
1272 HWND hwndOwner,
1273 LPVOID szPath,
1274 int csidl,
1275 BOOL bCreate)
1278 if (SHELL_OsIsUnicode())
1279 return SHGetSpecialFolderPathW (hwndOwner, szPath, csidl, bCreate);
1280 return SHGetSpecialFolderPathA (hwndOwner, szPath, csidl, bCreate);
1283 /*************************************************************************
1284 * SHGetSpecialFolderLocation [SHELL32.@]
1286 * gets the folder locations from the registry and creates a pidl
1287 * creates missing reg keys and directories
1289 * PARAMS
1290 * hwndOwner [I]
1291 * nFolder [I] CSIDL_xxxxx
1292 * ppidl [O] PIDL of a special folder
1294 * NOTES
1295 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
1296 * directory. If the directory is missing it returns a x80070002.
1297 * In most cases, this forwards to SHGetSpecialFolderPath, but
1298 * CSIDLs with virtual folders (not real paths) must be handled
1299 * here.
1301 HRESULT WINAPI SHGetSpecialFolderLocation(
1302 HWND hwndOwner,
1303 INT nFolder,
1304 LPITEMIDLIST * ppidl)
1306 HRESULT hr = E_INVALIDARG;
1308 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
1310 if (!ppidl)
1311 return E_INVALIDARG;
1313 *ppidl = NULL;
1314 switch (nFolder)
1316 case CSIDL_DESKTOP:
1317 *ppidl = _ILCreateDesktop();
1318 break;
1320 case CSIDL_INTERNET:
1321 *ppidl = _ILCreateIExplore();
1322 break;
1324 case CSIDL_CONTROLS:
1325 *ppidl = _ILCreateControlPanel();
1326 break;
1328 case CSIDL_PRINTERS:
1329 *ppidl = _ILCreatePrinters();
1330 break;
1332 case CSIDL_BITBUCKET:
1333 *ppidl = _ILCreateBitBucket();
1334 break;
1336 case CSIDL_DRIVES:
1337 *ppidl = _ILCreateMyComputer();
1338 break;
1340 case CSIDL_NETWORK:
1341 *ppidl = _ILCreateNetwork();
1342 break;
1344 case CSIDL_ALTSTARTUP:
1345 case CSIDL_COMMON_ALTSTARTUP:
1346 hr = E_FAIL;
1347 break;
1349 case CSIDL_COMPUTERSNEARME:
1350 hr = E_FAIL;
1351 break;
1353 default:
1355 WCHAR szPath[MAX_PATH];
1357 if (SHGetSpecialFolderPathW(hwndOwner, szPath, nFolder, TRUE))
1359 DWORD attributes=0;
1361 TRACE("Value=%s\n", debugstr_w(szPath));
1362 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
1366 if(*ppidl)
1367 hr = NOERROR;
1369 TRACE("-- (new pidl %p)\n",*ppidl);
1370 return hr;
1373 /*************************************************************************
1374 * SHGetFolderLocation [SHELL32.@]
1376 * NOTES
1377 * the pidl can be a simple one. since we can't get the path out of the pidl
1378 * we have to take all data from the pidl
1379 * Mostly we forward to SHGetSpecialFolderLocation, but a few special cases
1380 * we handle here.
1382 HRESULT WINAPI SHGetFolderLocation(
1383 HWND hwnd,
1384 int csidl,
1385 HANDLE hToken,
1386 DWORD dwFlags,
1387 LPITEMIDLIST *ppidl)
1389 HRESULT hr;
1391 TRACE_(shell)("%p 0x%08x %p 0x%08lx %p\n",
1392 hwnd, csidl, hToken, dwFlags, ppidl);
1394 if (!ppidl)
1395 return E_INVALIDARG;
1397 switch (csidl)
1399 case CSIDL_ALTSTARTUP:
1400 case CSIDL_COMMON_ALTSTARTUP:
1401 *ppidl = NULL;
1402 hr = S_FALSE;
1403 break;
1404 default:
1405 hr = SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
1407 return hr;