1 /******************************************************************************* 2 3 copyright: Copyright (c) 2007 the Tango team. All rights reserved 4 5 license: BSD style: $(LICENSE) 6 7 version: Initial release: July 2007 8 9 author: Cyborg16, Sean Kelly 10 11 *******************************************************************************/ 12 13 module tango.sys.win32.SpecialPath; 14 15 private import tango.text.convert.Utf; 16 private import tango.sys.Common; 17 private import tango.sys.win32.CodePage; 18 private import tango.stdc.stringz; 19 20 pragma(lib, "shell32.lib"); 21 22 version(Win32SansUnicode) 23 extern(Windows) int SHGetSpecialFolderPathA(HWND, LPCSTR, int, BOOL); 24 else 25 extern(Windows) int SHGetSpecialFolderPathW(HWND, LPCWSTR, int, BOOL); 26 27 enum 28 { 29 CSIDL_DESKTOP = 0, 30 CSIDL_INTERNET, 31 CSIDL_PROGRAMS, 32 CSIDL_CONTROLS, 33 CSIDL_PRINTERS, 34 CSIDL_PERSONAL, 35 CSIDL_FAVORITES, 36 CSIDL_STARTUP, 37 CSIDL_RECENT, 38 CSIDL_SENDTO, 39 CSIDL_BITBUCKET, 40 CSIDL_STARTMENU, // = 11 41 CSIDL_DESKTOPDIRECTORY = 16, 42 CSIDL_DRIVES, 43 CSIDL_NETWORK, 44 CSIDL_NETHOOD, 45 CSIDL_FONTS, 46 CSIDL_TEMPLATES, 47 CSIDL_COMMON_STARTMENU, 48 CSIDL_COMMON_PROGRAMS, 49 CSIDL_COMMON_STARTUP, 50 CSIDL_COMMON_DESKTOPDIRECTORY, 51 CSIDL_APPDATA, 52 CSIDL_PRINTHOOD, 53 CSIDL_LOCAL_APPDATA, 54 CSIDL_ALTSTARTUP, 55 CSIDL_COMMON_ALTSTARTUP, 56 CSIDL_COMMON_FAVORITES, 57 CSIDL_INTERNET_CACHE, 58 CSIDL_COOKIES, 59 CSIDL_HISTORY, 60 CSIDL_COMMON_APPDATA, 61 CSIDL_WINDOWS, 62 CSIDL_SYSTEM, 63 CSIDL_PROGRAM_FILES, 64 CSIDL_MYPICTURES, 65 CSIDL_PROFILE, 66 CSIDL_SYSTEMX86, 67 CSIDL_PROGRAM_FILESX86, 68 CSIDL_PROGRAM_FILES_COMMON, 69 CSIDL_PROGRAM_FILES_COMMONX86, 70 CSIDL_COMMON_TEMPLATES, 71 CSIDL_COMMON_DOCUMENTS, 72 CSIDL_COMMON_ADMINTOOLS, 73 CSIDL_ADMINTOOLS, 74 CSIDL_CONNECTIONS, // =49 75 CSIDL_COMMON_MUSIC = 53, 76 CSIDL_COMMON_PICTURES, 77 CSIDL_COMMON_VIDEO, 78 CSIDL_RESOURCES, 79 CSIDL_RESOURCES_LOCALIZED, 80 CSIDL_COMMON_OEM_LINKS, 81 CSIDL_CDBURN_AREA, // = 59 82 CSIDL_COMPUTERSNEARME = 61, 83 CSIDL_FLAG_DONT_VERIFY = 0x4000, 84 CSIDL_FLAG_CREATE = 0x8000, 85 CSIDL_FLAG_MASK = 0xFF00 86 } 87 88 /** 89 * Get a special path (on Windows). 90 * 91 * Params: 92 * csidl = Enum of path to get 93 * 94 * Throws: 95 * 96 * 97 * Returns: 98 * A string containing the path 99 */ 100 char[] getSpecialPath( int csidl ) 101 { 102 version( Win32SansUnicode ) 103 { 104 char* spath = (new char[MAX_PATH]).ptr; 105 scope(exit) delete spath; 106 107 if( !SHGetSpecialFolderPathA( null, spath, csidl, true ) ) 108 throw new Exception( "getSpecialPath :: " ~ SysError.lastMsg.idup ); 109 char[] dpath = new char[MAX_PATH]; 110 return CodePage.from(fromStringz(spath), dpath); 111 } 112 else 113 { 114 wchar* spath = (new wchar[MAX_PATH]).ptr; 115 scope(exit) spath.destroy; 116 117 if( !SHGetSpecialFolderPathW( null, spath, csidl, true ) ) 118 throw new Exception( "getSpecialPath :: " ~ SysError.lastMsg.idup ); 119 return toString(fromString16z(spath)); 120 } 121 }