Пример #1
0
        public static string FindRealPath(string source, string path,
                                          SpecialFolderOption opt)
        {
            var specialFld = source.TryEnum <SpecialFolder>();

            if (!specialFld.HasValue)
            {
                return(null);
            }
            string root;
            var    relative = path.TrimStart('/');

            if (specialFld == SpecialFolder.MyComputer)
            {
                var part      = relative.Split(new[] { '/' }, 2);
                var driveName = part.First();
                var drive     = DriveInfo.GetDrives().First(
                    d => PatchLabel(d.VolumeLabel) == driveName);
                relative = part.Length < 2 ? "" : part.Last();
                root     = drive.RootDirectory.FullName;
            }
            else
            {
                root = GetFolderPath(specialFld.Value, opt);
            }
            return(Path.Combine(root, relative));
        }
Пример #2
0
		// needed by our BCL, e.g. IsolatedStorageFile.cs
		internal static string UnixGetFolderPath (SpecialFolder folder, SpecialFolderOption option)
		{
			var dir = iOSGetFolderPath (folder);
			if ((option == SpecialFolderOption.Create) && !Directory.Exists (dir))
				Directory.CreateDirectory (dir);
			return dir;
		}
        public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            if (!Enum.IsDefined(typeof(SpecialFolder), folder))
            {
                throw new ArgumentException(GetResourceString("Arg_EnumIllegalVal", new object[] { (int)folder }));
            }
            if (!Enum.IsDefined(typeof(SpecialFolderOption), option))
            {
                throw new ArgumentException(GetResourceString("Arg_EnumIllegalVal", new object[] { (int)option }));
            }
            if (option == SpecialFolderOption.Create)
            {
                new FileIOPermission(PermissionState.None)
                {
                    AllFiles = FileIOPermissionAccess.Write
                }.Demand();
            }
            StringBuilder lpszPath = new StringBuilder(260);
            int           num      = Win32Native.SHGetFolderPath(IntPtr.Zero, (int)(folder | ((SpecialFolder)((int)option))), IntPtr.Zero, 0, lpszPath);

            if (num < 0)
            {
                switch (num)
                {
                case -2146233031:
                    throw new PlatformNotSupportedException();
                }
            }
            string path = lpszPath.ToString();

            new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
            return(path);
        }
Пример #4
0
        private static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            string dir = null;

            switch (folder)
            {
            case SpecialFolder.ApplicationData:
                dir = String.Format("\\Nvram\\App{0:D2}\\", InitialParametersClass.ApplicationNumber);
                if (option == SpecialFolderOption.Create)
                {
                    Directory.Create(dir);
                }
                break;

            case SpecialFolder.Programs:
                dir = InitialParametersClass.ProgramDirectory.ToString();
                break;

            case SpecialFolder.CommonApplicationData:
                dir = "\\Nvram\\";
                break;
            }

            return(dir);
        }
Пример #5
0
        static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            SecurityManager.EnsureElevatedPermissions();              // this is a no-op outside moonlight

            string dir = null;

#pragma warning disable 162
            if (Environment.IsRunningOnWindows)
            {
                dir = GetWindowsFolderPath((int)folder);
            }
            else
            {
                dir = UnixGetFolderPath(folder, option);
            }
#pragma warning restore 162

#if MONO_FEATURE_CAS
            if ((dir != null) && (dir.Length > 0) && SecurityManager.SecurityEnabled)
            {
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, dir).Demand();
            }
#endif
            return(dir);
        }
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            // Get the path for the SpecialFolder
            string path = GetFolderPathCoreWithoutValidation(folder);

            Debug.Assert(path != null);

            // If we didn't get one, or if we got one but we're not supposed to verify it,
            // or if we're supposed to verify it and it passes verification, return the path.
            if (path.Length == 0 ||
                option == SpecialFolderOption.DoNotVerify ||
                Interop.Sys.Access(path, Interop.Sys.AccessMode.R_OK) == 0)
            {
                return(path);
            }

            // Failed verification.  If None, then we're supposed to return an empty string.
            // If Create, we're supposed to create it and then return the path.
            if (option == SpecialFolderOption.None)
            {
                return(string.Empty);
            }
            else
            {
                Debug.Assert(option == SpecialFolderOption.Create);

                Func <string, object> createDirectory = LazyInitializer.EnsureInitialized(ref s_directoryCreateDirectory, static () =>
Пример #7
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            WinRTInteropCallbacks callbacks = WinRTInterop.UnsafeCallbacks;

            return(callbacks != null && callbacks.IsAppxModel() ?
                   callbacks.GetFolderPath(folder, option) :
                   null);
        }
Пример #8
0
        internal static string GetKnownFolderPath(string folderGuid, SpecialFolderOption option)
        {
            // System.Private.CoreLib/src/System/Environment.Win32.cs
            var folderId = new Guid(folderGuid);
            int hr       = SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out string path);

            return(hr != 0 ? string.Empty : path);
        }
Пример #9
0
        // needed by our BCL, e.g. IsolatedStorageFile.cs
        internal static string UnixGetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            var dir = iOSGetFolderPath(folder);

            if ((option == SpecialFolderOption.Create) && !Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            return(dir);
        }
Пример #10
0
            public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
            {
                if (s_winRTFolderPathsGetFolderPath == null)
                {
                    Type       winRtFolderPathsType = Type.GetType("System.WinRTFolderPaths, System.Runtime.WindowsRuntime, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", throwOnError: false);
                    MethodInfo?getFolderPathsMethod = winRtFolderPathsType?.GetMethod("GetFolderPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(SpecialFolder), typeof(SpecialFolderOption) }, null);
                    var        d = (Func <SpecialFolder, SpecialFolderOption, string>?)getFolderPathsMethod?.CreateDelegate(typeof(Func <SpecialFolder, SpecialFolderOption, string>));
                    s_winRTFolderPathsGetFolderPath = d ?? delegate { return(string.Empty); };
                }

                return(s_winRTFolderPathsGetFolderPath(folder, option));
            }
Пример #11
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            switch (folder)
            {
            case SpecialFolder.System:
                return(SystemDirectory);

            default:
                // TODO: SHGetFolderPath is not available in the approved API list
                return(string.Empty);
            }
        }
Пример #12
0
        private static string GetKnownFolderPath(string folderGuid, SpecialFolderOption option)
        {
            Guid folderId = new Guid(folderGuid);

            int hr = Interop.Shell32.SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out string path);

            if (hr != 0) // Not S_OK
            {
                return(string.Empty);
            }

            return(path);
        }
Пример #13
0
        //  .NET Core doesn't currently have APIs to get the "special" folders (ie the ones defined in the Environment.SpecialFolder enum)
        //  The code here is mostly copied out of the .NET reference source for this functionality

        public static string GetFolderPath(SpecialFolder folder)
        {
            if (NativeMethodsShared.IsUnixLike)
            {
                return(UnixNative.GetFolder(folder));
            }

            if (!NativeMethodsShared.IsWindows)
            {
                throw new PlatformNotSupportedException();
            }

            SpecialFolderOption option = SpecialFolderOption.None;

            StringBuilder sb      = new StringBuilder(NativeMethodsShared.MAX_PATH);
            int           hresult = Win32Native.SHGetFolderPath(IntPtr.Zero,                    /* hwndOwner: [in] Reserved */
                                                                ((int)folder | (int)option),    /* nFolder:   [in] CSIDL    */
                                                                IntPtr.Zero,                    /* hToken:    [in] access token */
                                                                Win32Native.SHGFP_TYPE_CURRENT, /* dwFlags:   [in] retrieve current path */
                                                                sb);                            /* pszPath:   [out]resultant path */

            String s;

            if (hresult < 0)
            {
                switch (hresult)
                {
                default:
                    // The previous incarnation threw away all errors. In order to limit
                    // breaking changes, we will be permissive about these errors
                    // instead of calling ThowExceptionForHR.
                    //Runtime.InteropServices.Marshal.ThrowExceptionForHR(hresult);
                    break;

                case __HResults.COR_E_PLATFORMNOTSUPPORTED:
                    // This one error is the one we do want to throw.
                    // <STRIP>

                    throw new PlatformNotSupportedException();
                }

                // SHGetFolderPath does not initialize the output buffer on error
                s = String.Empty;
            }
            else
            {
                s = sb.ToString();
            }

            return(s);
        }
Пример #14
0
        public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            if (!Enum.IsDefined(typeof(SpecialFolder), folder))
            {
                throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
            }

            if (option != SpecialFolderOption.None && !Enum.IsDefined(typeof(SpecialFolderOption), option))
            {
                throw new ArgumentOutOfRangeException(nameof(option), option, SR.Format(SR.Arg_EnumIllegalVal, option));
            }

            return(GetFolderPathCore(folder, option));
        }
Пример #15
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            if (s_specialFolders == null)
            {
                Interlocked.CompareExchange(ref s_specialFolders, new Dictionary <SpecialFolder, string>(), null);
            }

            string path;

            lock (s_specialFolders)
            {
                if (!s_specialFolders.TryGetValue(folder, out path))
                {
                    path = GetSpecialFolder(folder) ?? string.Empty;
                    s_specialFolders[folder] = path;
                }
            }
            return(path);
        }
Пример #16
0
 public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
 {
     // For testing we'll fall back if the needed APIs aren't present.
     //
     // We're not honoring the special folder options (noverify/create) for a few reasons. One, most of the
     // folders always exist (e.g. it is moot). Two, most locations are inaccessible from an appcontainer
     // currently - making it impossible to answer the question of existence or create if necessary. Thirdly,
     // the Win32 API would create these folders with very specific ACLs, which even in the cases we can create
     // are a significant compat risk (trying to replicate internal Windows behavior- it is documented that they
     // set specific ACLs, but not which ones).
     if (ApiInformation.IsTypePresent("Windows.Storage.UserDataPaths"))
     {
         return(GetFolderPathCoreCurrent(folder));
     }
     else
     {
         return(GetFolderPathCoreFallBack(folder));
     }
 }
Пример #17
0
        private static string GetKnownFolderPath(string folderGuid, SpecialFolderOption option)
        {
            Guid folderId = new Guid(folderGuid);

            string path;
            int    hr = Interop.Shell32.SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out path);

            if (hr != 0) // Not S_OK
            {
                if (hr == Interop.Shell32.COR_E_PLATFORMNOTSUPPORTED)
                {
                    throw new PlatformNotSupportedException();
                }
                else
                {
                    return(string.Empty);
                }
            }

            return(path);
        }
Пример #18
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            // Get the path for the SpecialFolder
            string path = GetFolderPathCoreWithoutValidation(folder);

            Debug.Assert(path != null);

            // If we didn't get one, or if we got one but we're not supposed to verify it,
            // or if we're supposed to verify it and it passes verification, return the path.
            if (path.Length == 0 ||
                option == SpecialFolderOption.DoNotVerify ||
                Interop.Sys.Access(path, Interop.Sys.AccessMode.R_OK) == 0)
            {
                return(path);
            }

            // Failed verification.  If None, then we're supposed to return an empty string.
            // If Create, we're supposed to create it and then return the path.
            if (option == SpecialFolderOption.None)
            {
                return(string.Empty);
            }

            Debug.Assert(option == SpecialFolderOption.Create);

            Func <string, object>?createDirectory = Volatile.Read(ref s_directoryCreateDirectory);

            if (createDirectory is null)
            {
                Type       dirType = Type.GetType("System.IO.Directory, System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true) !;
                MethodInfo mi      = dirType.GetMethod("CreateDirectory", BindingFlags.Public | BindingFlags.Static) !;
                createDirectory = mi.CreateDelegate <Func <string, object> >();
                Volatile.Write(ref s_directoryCreateDirectory, createDirectory);
            }

            createDirectory(path);

            return(path);
        }
Пример #19
0
        static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            SecurityManager.EnsureElevatedPermissions();              // this is a no-op outside moonlight

            string dir = null;

            if (Environment.IsRunningOnWindows)
            {
                dir = GetWindowsFolderPath((int)folder);
            }
            else
            {
                dir = InternalGetFolderPath(folder);
            }
#if !NET_2_1
            if ((dir != null) && (dir.Length > 0) && SecurityManager.SecurityEnabled)
            {
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, dir).Demand();
            }
#endif
            return(dir);
        }
Пример #20
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            // Get the path for the SpecialFolder
            string path = GetFolderPathCoreWithoutValidation(folder);

            Debug.Assert(path != null);

            // If we didn't get one, or if we got one but we're not supposed to verify it,
            // or if we're supposed to verify it and it passes verification, return the path.
            if (path.Length == 0 ||
                option == SpecialFolderOption.DoNotVerify ||
                Interop.Sys.Access(path, Interop.Sys.AccessMode.R_OK) == 0)
            {
                return(path);
            }

            // Failed verification.  If None, then we're supposed to return an empty string.
            // If Create, we're supposed to create it and then return the path.
            if (option == SpecialFolderOption.None)
            {
                return(string.Empty);
            }
            else
            {
                Debug.Assert(option == SpecialFolderOption.Create);

                // TODO #11151: Replace with Directory.CreateDirectory once we have access to System.IO.FileSystem here.
                Func <string, object> createDirectory = LazyInitializer.EnsureInitialized(ref s_directoryCreateDirectory, () =>
                {
                    Type dirType  = Type.GetType("System.IO.Directory, System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true);
                    MethodInfo mi = dirType.GetTypeInfo().GetDeclaredMethod("CreateDirectory");
                    return((Func <string, object>)mi.CreateDelegate(typeof(Func <string, object>)));
                });
                createDirectory(path);

                return(path);
            }
        }
Пример #21
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            // Get the path for the SpecialFolder
            string path = GetFolderPathCoreWithoutValidation(folder);
            Debug.Assert(path != null);

            // If we didn't get one, or if we got one but we're not supposed to verify it,
            // or if we're supposed to verify it and it passes verification, return the path.
            if (path.Length == 0 ||
                option == SpecialFolderOption.DoNotVerify ||
                Interop.Sys.Access(path, Interop.Sys.AccessMode.R_OK) == 0)
            {
                return path;
            }

            // Failed verification.  If None, then we're supposed to return an empty string.
            // If Create, we're supposed to create it and then return the path.
            if (option == SpecialFolderOption.None)
            {
                return string.Empty;
            }
            else
            {
                Debug.Assert(option == SpecialFolderOption.Create);

                // TODO #11151: Replace with Directory.CreateDirectory once we have access to System.IO.FileSystem here.
                Action<string> createDirectory = LazyInitializer.EnsureInitialized(ref s_directoryCreateDirectory, () =>
                {
                    Type dirType = Type.GetType("System.IO.Directory, System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true);
                    MethodInfo mi = dirType.GetTypeInfo().GetDeclaredMethod("CreateDirectory");
                    return (Action<string>)mi.CreateDelegate(typeof(Action<string>));
                });
                createDirectory(path);

                return path;
            }
        }
Пример #22
0
        public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option) { 
            if (!Enum.IsDefined(typeof(SpecialFolder),folder))
                throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)folder)); 
            if (!Enum.IsDefined(typeof(SpecialFolderOption),option)) 
                throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)option));
            Contract.EndContractBlock(); 

            if (option == SpecialFolderOption.Create) {
                FileIOPermission createPermission = new FileIOPermission(PermissionState.None);
                createPermission.AllFiles = FileIOPermissionAccess.Write; 
                createPermission.Demand();
            } 
 
            StringBuilder sb = new StringBuilder(Path.MAX_PATH);
            int hresult = Win32Native.SHGetFolderPath(IntPtr.Zero,                    /* hwndOwner: [in] Reserved */ 
                                                      ((int)folder | (int)option),    /* nFolder:   [in] CSIDL    */
                                                      IntPtr.Zero,                    /* hToken:    [in] access token */
                                                      Win32Native.SHGFP_TYPE_CURRENT, /* dwFlags:   [in] retrieve current path */
                                                      sb);                            /* pszPath:   [out]resultant path */ 
            if (hresult < 0)
            { 
                switch (hresult) 
                {
                default: 
                    // The previous incarnation threw away all errors. In order to limit
                    // breaking changes, we will be permissive about these errors
                    // instead of calling ThowExceptionForHR.
                    //Runtime.InteropServices.Marshal.ThrowExceptionForHR(hresult); 
                    break;
                case __HResults.COR_E_PLATFORMNOTSUPPORTED: 
                    // This one error is the one we do want to throw. 
                    // <STRIP>
 
                    throw new PlatformNotSupportedException();
                }
            }
            String s =  sb.ToString(); 
            new FileIOPermission( FileIOPermissionAccess.PathDiscovery, s ).Demand();
            return s; 
        } 
Пример #23
0
		public static string GetFolderPath (SpecialFolder folder, SpecialFolderOption option)
		{
			return UnixGetFolderPath (folder, option);
		}
Пример #24
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
 {
     return(string.Empty);
 }
Пример #25
0
        public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption options)
        {
            Contract.Ensures(Contract.Result <string>() != null);

            return(default(string));
        }
Пример #26
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
 {
     switch (folder)
     {
         case SpecialFolder.System:
             return SystemDirectory;
         default:
             // TODO: SHGetFolderPath is not available in the approved API list
             return string.Empty;
     }
 }
Пример #27
0
		static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
		{
			SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight

			string dir = null;

			if (Environment.IsRunningOnWindows)
				dir = GetWindowsFolderPath ((int) folder);
			else
				dir = UnixGetFolderPath (folder, option);

#if !NET_2_1
			if ((dir != null) && (dir.Length > 0) && SecurityManager.SecurityEnabled) {
				new FileIOPermission (FileIOPermissionAccess.PathDiscovery, dir).Demand ();
			}
#endif
			return dir;
		}
Пример #28
0
 public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
 {
     return(UnixGetFolderPath(folder, option));
 }
Пример #29
0
 public string GetFolderPath(SpecialFolder folder, SpecialFolderOption option = SpecialFolderOption.None) => Environment.GetFolderPath((Environment.SpecialFolder)folder, (Environment.SpecialFolderOption)option);
Пример #30
0
 internal static string UnixGetFolderPath(SpecialFolder folder, SpecialFolderOption option)
 {
     throw new NotSupportedException();
 }
Пример #31
0
        public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            if (!Enum.IsDefined(typeof(SpecialFolder), folder))
            {
                throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
            }

            if (option != SpecialFolderOption.None && !Enum.IsDefined(typeof(SpecialFolderOption), option))
            {
                throw new ArgumentOutOfRangeException(nameof(option), option, SR.Format(SR.Arg_EnumIllegalVal, option));
            }

            return GetFolderPathCore(folder, option);
        }
Пример #32
0
 public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
 {
     throw new NotImplementedException();
 }
Пример #33
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option) =>
 WinRTFolderPaths.GetFolderPath(folder, option);
Пример #34
0
 private static string GetWindowsFolderPath(int folder) => default;                                                // 0x0000000180318B10-0x0000000180318B20
 public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option) => default;                  // 0x0000000180318880-0x00000001803188D0
Пример #35
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
#if FEATURE_APPX
            if (ApplicationModel.IsUap)
            {
                return(WinRTFolderPaths.GetFolderPath(folder, option));
            }
#endif

            // We're using SHGetKnownFolderPath instead of SHGetFolderPath as SHGetFolderPath is
            // capped at MAX_PATH.
            //
            // Because we validate both of the input enums we shouldn't have to care about CSIDL and flag
            // definitions we haven't mapped. If we remove or loosen the checks we'd have to account
            // for mapping here (this includes tweaking as SHGetFolderPath would do).
            //
            // The only SpecialFolderOption defines we have are equivalent to KnownFolderFlags.

            string folderGuid;

            switch (folder)
            {
            case SpecialFolder.ApplicationData:
                folderGuid = Interop.Shell32.KnownFolders.RoamingAppData;
                break;

            case SpecialFolder.CommonApplicationData:
                folderGuid = Interop.Shell32.KnownFolders.ProgramData;
                break;

            case SpecialFolder.LocalApplicationData:
                folderGuid = Interop.Shell32.KnownFolders.LocalAppData;
                break;

            case SpecialFolder.Cookies:
                folderGuid = Interop.Shell32.KnownFolders.Cookies;
                break;

            case SpecialFolder.Desktop:
                folderGuid = Interop.Shell32.KnownFolders.Desktop;
                break;

            case SpecialFolder.Favorites:
                folderGuid = Interop.Shell32.KnownFolders.Favorites;
                break;

            case SpecialFolder.History:
                folderGuid = Interop.Shell32.KnownFolders.History;
                break;

            case SpecialFolder.InternetCache:
                folderGuid = Interop.Shell32.KnownFolders.InternetCache;
                break;

            case SpecialFolder.Programs:
                folderGuid = Interop.Shell32.KnownFolders.Programs;
                break;

            case SpecialFolder.MyComputer:
                folderGuid = Interop.Shell32.KnownFolders.ComputerFolder;
                break;

            case SpecialFolder.MyMusic:
                folderGuid = Interop.Shell32.KnownFolders.Music;
                break;

            case SpecialFolder.MyPictures:
                folderGuid = Interop.Shell32.KnownFolders.Pictures;
                break;

            case SpecialFolder.MyVideos:
                folderGuid = Interop.Shell32.KnownFolders.Videos;
                break;

            case SpecialFolder.Recent:
                folderGuid = Interop.Shell32.KnownFolders.Recent;
                break;

            case SpecialFolder.SendTo:
                folderGuid = Interop.Shell32.KnownFolders.SendTo;
                break;

            case SpecialFolder.StartMenu:
                folderGuid = Interop.Shell32.KnownFolders.StartMenu;
                break;

            case SpecialFolder.Startup:
                folderGuid = Interop.Shell32.KnownFolders.Startup;
                break;

            case SpecialFolder.System:
                folderGuid = Interop.Shell32.KnownFolders.System;
                break;

            case SpecialFolder.Templates:
                folderGuid = Interop.Shell32.KnownFolders.Templates;
                break;

            case SpecialFolder.DesktopDirectory:
                folderGuid = Interop.Shell32.KnownFolders.Desktop;
                break;

            case SpecialFolder.Personal:
                // Same as Personal
                // case SpecialFolder.MyDocuments:
                folderGuid = Interop.Shell32.KnownFolders.Documents;
                break;

            case SpecialFolder.ProgramFiles:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFiles;
                break;

            case SpecialFolder.CommonProgramFiles:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommon;
                break;

            case SpecialFolder.AdminTools:
                folderGuid = Interop.Shell32.KnownFolders.AdminTools;
                break;

            case SpecialFolder.CDBurning:
                folderGuid = Interop.Shell32.KnownFolders.CDBurning;
                break;

            case SpecialFolder.CommonAdminTools:
                folderGuid = Interop.Shell32.KnownFolders.CommonAdminTools;
                break;

            case SpecialFolder.CommonDocuments:
                folderGuid = Interop.Shell32.KnownFolders.PublicDocuments;
                break;

            case SpecialFolder.CommonMusic:
                folderGuid = Interop.Shell32.KnownFolders.PublicMusic;
                break;

            case SpecialFolder.CommonOemLinks:
                folderGuid = Interop.Shell32.KnownFolders.CommonOEMLinks;
                break;

            case SpecialFolder.CommonPictures:
                folderGuid = Interop.Shell32.KnownFolders.PublicPictures;
                break;

            case SpecialFolder.CommonStartMenu:
                folderGuid = Interop.Shell32.KnownFolders.CommonStartMenu;
                break;

            case SpecialFolder.CommonPrograms:
                folderGuid = Interop.Shell32.KnownFolders.CommonPrograms;
                break;

            case SpecialFolder.CommonStartup:
                folderGuid = Interop.Shell32.KnownFolders.CommonStartup;
                break;

            case SpecialFolder.CommonDesktopDirectory:
                folderGuid = Interop.Shell32.KnownFolders.PublicDesktop;
                break;

            case SpecialFolder.CommonTemplates:
                folderGuid = Interop.Shell32.KnownFolders.CommonTemplates;
                break;

            case SpecialFolder.CommonVideos:
                folderGuid = Interop.Shell32.KnownFolders.PublicVideos;
                break;

            case SpecialFolder.Fonts:
                folderGuid = Interop.Shell32.KnownFolders.Fonts;
                break;

            case SpecialFolder.NetworkShortcuts:
                folderGuid = Interop.Shell32.KnownFolders.NetHood;
                break;

            case SpecialFolder.PrinterShortcuts:
                folderGuid = Interop.Shell32.KnownFolders.PrintersFolder;
                break;

            case SpecialFolder.UserProfile:
                folderGuid = Interop.Shell32.KnownFolders.Profile;
                break;

            case SpecialFolder.CommonProgramFilesX86:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommonX86;
                break;

            case SpecialFolder.ProgramFilesX86:
                folderGuid = Interop.Shell32.KnownFolders.ProgramFilesX86;
                break;

            case SpecialFolder.Resources:
                folderGuid = Interop.Shell32.KnownFolders.ResourceDir;
                break;

            case SpecialFolder.LocalizedResources:
                folderGuid = Interop.Shell32.KnownFolders.LocalizedResourcesDir;
                break;

            case SpecialFolder.SystemX86:
                folderGuid = Interop.Shell32.KnownFolders.SystemX86;
                break;

            case SpecialFolder.Windows:
                folderGuid = Interop.Shell32.KnownFolders.Windows;
                break;

            default:
                return(string.Empty);
            }

            return(GetKnownFolderPath(folderGuid, option));
        }
 public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
 {
     if (!Enum.IsDefined(typeof(SpecialFolder), folder))
     {
         throw new ArgumentException(GetResourceString("Arg_EnumIllegalVal", new object[] { (int) folder }));
     }
     if (!Enum.IsDefined(typeof(SpecialFolderOption), option))
     {
         throw new ArgumentException(GetResourceString("Arg_EnumIllegalVal", new object[] { (int) option }));
     }
     if (option == SpecialFolderOption.Create)
     {
         new FileIOPermission(PermissionState.None) { AllFiles = FileIOPermissionAccess.Write }.Demand();
     }
     StringBuilder lpszPath = new StringBuilder(260);
     int num = Win32Native.SHGetFolderPath(IntPtr.Zero, (int) (folder | ((SpecialFolder) ((int) option))), IntPtr.Zero, 0, lpszPath);
     if (num < 0)
     {
         switch (num)
         {
             case -2146233031:
                 throw new PlatformNotSupportedException();
         }
     }
     string path = lpszPath.ToString();
     new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
     return path;
 }
    public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption options) {
        Contract.Ensures(Contract.Result<string>() != null);

        return default(string);
    }
        public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option) {
            if (!Enum.IsDefined(typeof(SpecialFolder),folder))
                throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)folder));
            if (!Enum.IsDefined(typeof(SpecialFolderOption),option))
                throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)option));
            Contract.EndContractBlock();

            return InternalGetFolderPath(folder, option);
        }
Пример #39
0
        // the security runtime (and maybe other parts of corlib) needs the
        // information to initialize themselves before permissions can be checked
        internal static string UnixGetFolderPath(SpecialFolder folder, SpecialFolderOption option)
        {
            string home = internalGetHome();

            // http://freedesktop.org/Standards/basedir-spec/basedir-spec-0.6.html

            // note: skip security check for environment variables
            string data = internalGetEnvironmentVariable("XDG_DATA_HOME");

            if ((data == null) || (data == String.Empty))
            {
                data = Path.Combine(home, ".local");
                data = Path.Combine(data, "share");
            }

            // note: skip security check for environment variables
            string config = internalGetEnvironmentVariable("XDG_CONFIG_HOME");

            if ((config == null) || (config == String.Empty))
            {
                config = Path.Combine(home, ".config");
            }

            switch (folder)
            {
            // MyComputer is a virtual directory
            case SpecialFolder.MyComputer:
                return(String.Empty);

            // personal == ~
            case SpecialFolder.Personal:
                return(home);

            // use FDO's CONFIG_HOME. This data will be synced across a network like the windows counterpart.
            case SpecialFolder.ApplicationData:
                return(config);

            //use FDO's DATA_HOME. This is *NOT* synced
            case SpecialFolder.LocalApplicationData:
                return(data);

            case SpecialFolder.Desktop:
            case SpecialFolder.DesktopDirectory:
                return(ReadXdgUserDir(config, home, "XDG_DESKTOP_DIR", "Desktop"));

            case SpecialFolder.MyMusic:
                if (Platform == PlatformID.MacOSX)
                {
                    return(Path.Combine(home, "Music"));
                }
                else
                {
                    return(ReadXdgUserDir(config, home, "XDG_MUSIC_DIR", "Music"));
                }

            case SpecialFolder.MyPictures:
                if (Platform == PlatformID.MacOSX)
                {
                    return(Path.Combine(home, "Pictures"));
                }
                else
                {
                    return(ReadXdgUserDir(config, home, "XDG_PICTURES_DIR", "Pictures"));
                }

            case SpecialFolder.Templates:
                return(ReadXdgUserDir(config, home, "XDG_TEMPLATES_DIR", "Templates"));

            case SpecialFolder.MyVideos:
                return(ReadXdgUserDir(config, home, "XDG_VIDEOS_DIR", "Videos"));

            case SpecialFolder.CommonTemplates:
                return("/usr/share/templates");

            case SpecialFolder.Fonts:
                if (Platform == PlatformID.MacOSX)
                {
                    return(Path.Combine(home, "Library", "Fonts"));
                }

                return(Path.Combine(home, ".fonts"));

            // these simply dont exist on Linux
            // The spec says if a folder doesnt exist, we
            // should return ""
            case SpecialFolder.Favorites:
                if (Platform == PlatformID.MacOSX)
                {
                    return(Path.Combine(home, "Library", "Favorites"));
                }
                else
                {
                    return(String.Empty);
                }

            case SpecialFolder.ProgramFiles:
                if (Platform == PlatformID.MacOSX)
                {
                    return("/Applications");
                }
                else
                {
                    return(String.Empty);
                }

            case SpecialFolder.InternetCache:
                if (Platform == PlatformID.MacOSX)
                {
                    return(Path.Combine(home, "Library", "Caches"));
                }
                else
                {
                    return(String.Empty);
                }

            // #2873
            case SpecialFolder.UserProfile:
                return(home);

            case SpecialFolder.Programs:
            case SpecialFolder.SendTo:
            case SpecialFolder.StartMenu:
            case SpecialFolder.Startup:
            case SpecialFolder.Cookies:
            case SpecialFolder.History:
            case SpecialFolder.Recent:
            case SpecialFolder.CommonProgramFiles:
            case SpecialFolder.System:
            case SpecialFolder.NetworkShortcuts:
            case SpecialFolder.CommonStartMenu:
            case SpecialFolder.CommonPrograms:
            case SpecialFolder.CommonStartup:
            case SpecialFolder.CommonDesktopDirectory:
            case SpecialFolder.PrinterShortcuts:
            case SpecialFolder.Windows:
            case SpecialFolder.SystemX86:
            case SpecialFolder.ProgramFilesX86:
            case SpecialFolder.CommonProgramFilesX86:
            case SpecialFolder.CommonDocuments:
            case SpecialFolder.CommonAdminTools:
            case SpecialFolder.AdminTools:
            case SpecialFolder.CommonMusic:
            case SpecialFolder.CommonPictures:
            case SpecialFolder.CommonVideos:
            case SpecialFolder.Resources:
            case SpecialFolder.LocalizedResources:
            case SpecialFolder.CommonOemLinks:
            case SpecialFolder.CDBurning:
                return(String.Empty);

            // This is where data common to all users goes
            case SpecialFolder.CommonApplicationData:
                return("/usr/share");

            default:
                throw new ArgumentException("Invalid SpecialFolder");
            }
        }
        private static string InternalGetFolderPath(SpecialFolder folder, SpecialFolderOption option, bool suppressSecurityChecks = false)
        {
#if FEATURE_CORESYSTEM
            // This is currently customized for Windows Phone since CoreSystem doesn't support
            // SHGetFolderPath. The allowed folder values are based on the version of .NET CF WP7 was using.
            switch (folder)
            {
                case SpecialFolder.System:
                    return SystemDirectory;
                case SpecialFolder.ApplicationData:
                case SpecialFolder.Favorites:
                case SpecialFolder.Programs:
                case SpecialFolder.StartMenu:
                case SpecialFolder.Startup:
                case SpecialFolder.Personal:
                    throw new PlatformNotSupportedException();
                default:
                    throw new PlatformNotSupportedException();
            }
#else // FEATURE_CORESYSTEM
#if !FEATURE_CORECLR
            if (option == SpecialFolderOption.Create && !suppressSecurityChecks) {
                FileIOPermission createPermission = new FileIOPermission(PermissionState.None);
                createPermission.AllFiles = FileIOPermissionAccess.Write;
                createPermission.Demand();
            }
#endif

            StringBuilder sb = new StringBuilder(Path.MAX_PATH);
            int hresult = Win32Native.SHGetFolderPath(IntPtr.Zero,                    /* hwndOwner: [in] Reserved */
                                                      ((int)folder | (int)option),    /* nFolder:   [in] CSIDL    */
                                                      IntPtr.Zero,                    /* hToken:    [in] access token */
                                                      Win32Native.SHGFP_TYPE_CURRENT, /* dwFlags:   [in] retrieve current path */
                                                      sb);                            /* pszPath:   [out]resultant path */
            String s;
            if (hresult < 0)
            {
                switch (hresult)
                {
                default:
                    // The previous incarnation threw away all errors. In order to limit
                    // breaking changes, we will be permissive about these errors
                    // instead of calling ThowExceptionForHR.
                    //Runtime.InteropServices.Marshal.ThrowExceptionForHR(hresult);
                    break;
                case __HResults.COR_E_PLATFORMNOTSUPPORTED:
                    // This one error is the one we do want to throw.
                    // <STRIP>

                    throw new PlatformNotSupportedException();
                }

                // SHGetFolderPath does not initialize the output buffer on error
                s = String.Empty;
            }
            else
            {
                s = sb.ToString();
            }

            if (!suppressSecurityChecks)
            {
                // On CoreCLR we can check with the host if we're not trying to use any special options.
                // Otherwise, we need to do a full demand since hosts aren't expecting to handle requests to
                // create special folders.
#if FEATURE_CORECLR
                if (option == SpecialFolderOption.None)
                {
                    FileSecurityState state = new FileSecurityState(FileSecurityStateAccess.PathDiscovery, String.Empty, s);
                    state.EnsureState();
                }
                else
#endif // FEATURE_CORECLR
                {
                    new FileIOPermission(FileIOPermissionAccess.PathDiscovery, s).Demand();
                }
            }
            return s;
#endif // FEATURE_CORESYSTEM
        }
Пример #41
0
 private static string ReadXdgUserDir(string config_dir, string home_dir, string key, string fallback) => default; // 0x0000000180318B20-0x0000000180318EB0
 internal static string UnixGetFolderPath(SpecialFolder folder, SpecialFolderOption option) => default;            // 0x0000000180318EB0-0x0000000180319330
Пример #42
0
        private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
        {
            // We're using SHGetKnownFolderPath instead of SHGetFolderPath as SHGetFolderPath is
            // capped at MAX_PATH.
            //
            // Because we validate both of the input enums we shouldn't have to care about CSIDL and flag
            // definitions we haven't mapped. If we remove or loosen the checks we'd have to account
            // for mapping here (this includes tweaking as SHGetFolderPath would do).
            //
            // The only SpecialFolderOption defines we have are equivalent to KnownFolderFlags.

            string folderGuid;

            switch (folder)
            {
                case SpecialFolder.ApplicationData:
                    folderGuid = Interop.mincore.KnownFolders.RoamingAppData;
                    break;
                case SpecialFolder.CommonApplicationData:
                    folderGuid = Interop.mincore.KnownFolders.ProgramData;
                    break;
                case SpecialFolder.LocalApplicationData:
                    folderGuid = Interop.mincore.KnownFolders.LocalAppData;
                    break;
                case SpecialFolder.Cookies:
                    folderGuid = Interop.mincore.KnownFolders.Cookies;
                    break;
                case SpecialFolder.Desktop:
                    folderGuid = Interop.mincore.KnownFolders.Desktop;
                    break;
                case SpecialFolder.Favorites:
                    folderGuid = Interop.mincore.KnownFolders.Favorites;
                    break;
                case SpecialFolder.History:
                    folderGuid = Interop.mincore.KnownFolders.History;
                    break;
                case SpecialFolder.InternetCache:
                    folderGuid = Interop.mincore.KnownFolders.InternetCache;
                    break;
                case SpecialFolder.Programs:
                    folderGuid = Interop.mincore.KnownFolders.Programs;
                    break;
                case SpecialFolder.MyComputer:
                    folderGuid = Interop.mincore.KnownFolders.ComputerFolder;
                    break;
                case SpecialFolder.MyMusic:
                    folderGuid = Interop.mincore.KnownFolders.Music;
                    break;
                case SpecialFolder.MyPictures:
                    folderGuid = Interop.mincore.KnownFolders.Pictures;
                    break;
                case SpecialFolder.MyVideos:
                    folderGuid = Interop.mincore.KnownFolders.Videos;
                    break;
                case SpecialFolder.Recent:
                    folderGuid = Interop.mincore.KnownFolders.Recent;
                    break;
                case SpecialFolder.SendTo:
                    folderGuid = Interop.mincore.KnownFolders.SendTo;
                    break;
                case SpecialFolder.StartMenu:
                    folderGuid = Interop.mincore.KnownFolders.StartMenu;
                    break;
                case SpecialFolder.Startup:
                    folderGuid = Interop.mincore.KnownFolders.Startup;
                    break;
                case SpecialFolder.System:
                    folderGuid = Interop.mincore.KnownFolders.System;
                    break;
                case SpecialFolder.Templates:
                    folderGuid = Interop.mincore.KnownFolders.Templates;
                    break;
                case SpecialFolder.DesktopDirectory:
                    folderGuid = Interop.mincore.KnownFolders.Desktop;
                    break;
                case SpecialFolder.Personal:
                    // Same as Personal
                    // case SpecialFolder.MyDocuments:
                    folderGuid = Interop.mincore.KnownFolders.Documents;
                    break;
                case SpecialFolder.ProgramFiles:
                    folderGuid = Interop.mincore.KnownFolders.ProgramFiles;
                    break;
                case SpecialFolder.CommonProgramFiles:
                    folderGuid = Interop.mincore.KnownFolders.ProgramFilesCommon;
                    break;
                case SpecialFolder.AdminTools:
                    folderGuid = Interop.mincore.KnownFolders.AdminTools;
                    break;
                case SpecialFolder.CDBurning:
                    folderGuid = Interop.mincore.KnownFolders.CDBurning;
                    break;
                case SpecialFolder.CommonAdminTools:
                    folderGuid = Interop.mincore.KnownFolders.CommonAdminTools;
                    break;
                case SpecialFolder.CommonDocuments:
                    folderGuid = Interop.mincore.KnownFolders.PublicDocuments;
                    break;
                case SpecialFolder.CommonMusic:
                    folderGuid = Interop.mincore.KnownFolders.PublicMusic;
                    break;
                case SpecialFolder.CommonOemLinks:
                    folderGuid = Interop.mincore.KnownFolders.CommonOEMLinks;
                    break;
                case SpecialFolder.CommonPictures:
                    folderGuid = Interop.mincore.KnownFolders.PublicPictures;
                    break;
                case SpecialFolder.CommonStartMenu:
                    folderGuid = Interop.mincore.KnownFolders.CommonStartMenu;
                    break;
                case SpecialFolder.CommonPrograms:
                    folderGuid = Interop.mincore.KnownFolders.CommonPrograms;
                    break;
                case SpecialFolder.CommonStartup:
                    folderGuid = Interop.mincore.KnownFolders.CommonStartup;
                    break;
                case SpecialFolder.CommonDesktopDirectory:
                    folderGuid = Interop.mincore.KnownFolders.PublicDesktop;
                    break;
                case SpecialFolder.CommonTemplates:
                    folderGuid = Interop.mincore.KnownFolders.CommonTemplates;
                    break;
                case SpecialFolder.CommonVideos:
                    folderGuid = Interop.mincore.KnownFolders.PublicVideos;
                    break;
                case SpecialFolder.Fonts:
                    folderGuid = Interop.mincore.KnownFolders.Fonts;
                    break;
                case SpecialFolder.NetworkShortcuts:
                    folderGuid = Interop.mincore.KnownFolders.NetHood;
                    break;
                case SpecialFolder.PrinterShortcuts:
                    folderGuid = Interop.mincore.KnownFolders.PrintersFolder;
                    break;
                case SpecialFolder.UserProfile:
                    folderGuid = Interop.mincore.KnownFolders.Profile;
                    break;
                case SpecialFolder.CommonProgramFilesX86:
                    folderGuid = Interop.mincore.KnownFolders.ProgramFilesCommonX86;
                    break;
                case SpecialFolder.ProgramFilesX86:
                    folderGuid = Interop.mincore.KnownFolders.ProgramFilesX86;
                    break;
                case SpecialFolder.Resources:
                    folderGuid = Interop.mincore.KnownFolders.ResourceDir;
                    break;
                case SpecialFolder.LocalizedResources:
                    folderGuid = Interop.mincore.KnownFolders.LocalizedResourcesDir;
                    break;
                case SpecialFolder.SystemX86:
                    folderGuid = Interop.mincore.KnownFolders.SystemX86;
                    break;
                case SpecialFolder.Windows:
                    folderGuid = Interop.mincore.KnownFolders.Windows;
                    break;
                default:
                    return string.Empty;
            }

            return GetKnownFolderPath(folderGuid, option);
        }
Пример #43
0
        private static string GetKnownFolderPath(string folderGuid, SpecialFolderOption option)
        {
            Guid folderId = new Guid(folderGuid);

            string path;
            int hr = Interop.mincore.SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out path);
            if (hr != 0) // Not S_OK
            {
                if (hr == Interop.mincore.COR_E_PLATFORMNOTSUPPORTED)
                {
                    throw new PlatformNotSupportedException();
                }
                else
                {
                    return string.Empty;
                }
            }

            return path;
        }
Пример #44
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
 {
     return string.Empty;
 }
Пример #45
0
		// the security runtime (and maybe other parts of corlib) needs the
		// information to initialize themselves before permissions can be checked
		internal static string UnixGetFolderPath (SpecialFolder folder, SpecialFolderOption option)
		{
			string home = internalGetHome ();

			// http://freedesktop.org/Standards/basedir-spec/basedir-spec-0.6.html

			// note: skip security check for environment variables
			string data = internalGetEnvironmentVariable ("XDG_DATA_HOME");
			if ((data == null) || (data == String.Empty)) {
				data = Path.Combine (home, ".local");
				data = Path.Combine (data, "share");
			}

			// note: skip security check for environment variables
			string config = internalGetEnvironmentVariable ("XDG_CONFIG_HOME");
			if ((config == null) || (config == String.Empty)) {
				config = Path.Combine (home, ".config");
			}

			switch (folder) {
			// MyComputer is a virtual directory
			case SpecialFolder.MyComputer:
				return String.Empty;

			// personal == ~
			case SpecialFolder.Personal:
#if MONOTOUCH
				return Path.Combine (home, "Documents");
#else
				return home;
#endif
			// use FDO's CONFIG_HOME. This data will be synced across a network like the windows counterpart.
			case SpecialFolder.ApplicationData:
#if MONOTOUCH
			{
				string dir = Path.Combine (Path.Combine (home, "Documents"), ".config");
				if (option == SpecialFolderOption.Create){
					if (!Directory.Exists (dir))
						Directory.CreateDirectory (dir);
				}
				return dir;
			}
#else
				return config;
#endif
			//use FDO's DATA_HOME. This is *NOT* synced
			case SpecialFolder.LocalApplicationData:
#if MONOTOUCH
			{
				string dir = Path.Combine (home, "Documents");
				if (!Directory.Exists (dir))
					Directory.CreateDirectory (dir);

				return dir;
			}
#else
				return data;
#endif

			case SpecialFolder.Desktop:
			case SpecialFolder.DesktopDirectory:
				return ReadXdgUserDir (config, home, "XDG_DESKTOP_DIR", "Desktop");

			case SpecialFolder.MyMusic:
				if (Platform == PlatformID.MacOSX)
					return Path.Combine (home, "Music");
				else
					return ReadXdgUserDir (config, home, "XDG_MUSIC_DIR", "Music");

			case SpecialFolder.MyPictures:
				if (Platform == PlatformID.MacOSX)
					return Path.Combine (home, "Pictures");
				else
					return ReadXdgUserDir (config, home, "XDG_PICTURES_DIR", "Pictures");
			
			case SpecialFolder.Templates:
				return ReadXdgUserDir (config, home, "XDG_TEMPLATES_DIR", "Templates");
#if NET_4_0 || MOONLIGHT || MOBILE
			case SpecialFolder.MyVideos:
				return ReadXdgUserDir (config, home, "XDG_VIDEOS_DIR", "Videos");
#endif
#if NET_4_0
			case SpecialFolder.CommonTemplates:
				return "/usr/share/templates";
			case SpecialFolder.Fonts:
				if (Platform == PlatformID.MacOSX)
					return Path.Combine (home, "Library", "Fonts");
				
				return Path.Combine (home, ".fonts");
#endif
			// these simply dont exist on Linux
			// The spec says if a folder doesnt exist, we
			// should return ""
			case SpecialFolder.Favorites:
				if (Platform == PlatformID.MacOSX)
					return Path.Combine (home, "Library", "Favorites");
				else
					return String.Empty;
				
			case SpecialFolder.ProgramFiles:
				if (Platform == PlatformID.MacOSX)
					return "/Applications";
				else
					return String.Empty;

			case SpecialFolder.InternetCache:
				if (Platform == PlatformID.MacOSX)
					return Path.Combine (home, "Library", "Caches");
				else
					return String.Empty;

#if NET_4_0
				// #2873
			case SpecialFolder.UserProfile:
				return home;
#endif

			case SpecialFolder.Programs:
			case SpecialFolder.SendTo:
			case SpecialFolder.StartMenu:
			case SpecialFolder.Startup:
			case SpecialFolder.Cookies:
			case SpecialFolder.History:
			case SpecialFolder.Recent:
			case SpecialFolder.CommonProgramFiles:
			case SpecialFolder.System:
#if NET_4_0
			case SpecialFolder.NetworkShortcuts:
			case SpecialFolder.CommonStartMenu:
			case SpecialFolder.CommonPrograms:
			case SpecialFolder.CommonStartup:
			case SpecialFolder.CommonDesktopDirectory:
			case SpecialFolder.PrinterShortcuts:
			case SpecialFolder.Windows:
			case SpecialFolder.SystemX86:
			case SpecialFolder.ProgramFilesX86:
			case SpecialFolder.CommonProgramFilesX86:
			case SpecialFolder.CommonDocuments:
			case SpecialFolder.CommonAdminTools:
			case SpecialFolder.AdminTools:
			case SpecialFolder.CommonMusic:
			case SpecialFolder.CommonPictures:
			case SpecialFolder.CommonVideos:
			case SpecialFolder.Resources:
			case SpecialFolder.LocalizedResources:
			case SpecialFolder.CommonOemLinks:
			case SpecialFolder.CDBurning:
#endif
				return String.Empty;
			// This is where data common to all users goes
			case SpecialFolder.CommonApplicationData:
				return "/usr/share";
			default:
				throw new ArgumentException ("Invalid SpecialFolder");
                        }
                }
		static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
		{
			string dir = null;

			if (Environment.IsRunningOnWindows) {
				dir = GetWindowsFolderPath ((int) folder);
			} else {
				dir = InternalGetFolderPath (folder);
			}
#if !NET_2_1
			if ((dir != null) && (dir.Length > 0) && SecurityManager.SecurityEnabled) {
				new FileIOPermission (FileIOPermissionAccess.PathDiscovery, dir).Demand ();
			}
#endif
			return dir;
		}