예제 #1
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;
		}
예제 #2
0
		static FolderAttributes GetSpecialFolderAttribute (SpecialFolder special)
		{
			switch (special) {
			case SpecialFolder.All:     return FolderAttributes.All;
			case SpecialFolder.Archive: return FolderAttributes.Archive;
			case SpecialFolder.Drafts:  return FolderAttributes.Drafts;
			case SpecialFolder.Flagged: return FolderAttributes.Flagged;
			case SpecialFolder.Junk:    return FolderAttributes.Junk;
			case SpecialFolder.Sent:    return FolderAttributes.Sent;
			case SpecialFolder.Trash:   return FolderAttributes.Trash;
			default: throw new ArgumentOutOfRangeException ();
			}
		}
예제 #3
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;
            }
        }
        private void AddAndCreateSpecialFolder(SpecialFolder folder, string path)
        {
            var combinedPath = Path.Combine(path, folder == SpecialFolder.Root ? string.Empty : folder.ToString());

            Directory.CreateDirectory(combinedPath);

            AddSpecialFolder(folder, combinedPath);
        }
예제 #5
0
		/// <summary>
		/// Create a new subfolder with the given name.
		/// </summary>
		/// <remarks>
		/// Creates a new subfolder with the given name.
		/// </remarks>
		/// <returns>The created folder.</returns>
		/// <param name="name">The name of the folder to create.</param>
		/// <param name="specialUse">The special use for the folder being created.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="name"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="name"/> is empty.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The <see cref="DirectorySeparator"/> is nil, and thus child folders cannot be created.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The <see cref="MailService"/> does not support the creation of special folders.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public virtual IMailFolder Create (string name, SpecialFolder specialUse, CancellationToken cancellationToken = default (CancellationToken))
		{
			return Create (name, new [] { specialUse }, cancellationToken);
		}
예제 #6
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;
		}
예제 #7
0
 private static string GetFolderPathCoreCurrent(SpecialFolder folder) =>
 // While all of these give back real paths, most of them are not accessible
 // from an appcontainer currently (they will give access denied)
 folder switch
 {
예제 #8
0
 public override string GetFolderPath(SpecialFolder folder, bool create)
 {
     var dir = Far.Api.GetFolderPath(folder) + @"\FarNet\" + ModuleName;
     if (create && !Directory.Exists(dir))
         Directory.CreateDirectory(dir);
     return dir;
 }
	public static string GetFolderPath(SpecialFolder folder) {}
예제 #10
0
 public string GetEnsuredPath(string path, SpecialFolder folder)
 {
     return(GetEnsuredPath(folder + "\\" + path, false));
 }
		// the security runtime (and maybe other parts of corlib) needs the
		// information to initialize themselves before permissions can be checked
		internal static string InternalGetFolderPath (SpecialFolder folder)
		{
			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:
				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:
				return ReadXdgUserDir (config, home, "XDG_MUSIC_DIR", "Music");

			case SpecialFolder.MyPictures:
				return ReadXdgUserDir (config, home, "XDG_PICTURES_DIR", "Pictures");
				
			// these simply dont exist on Linux
			// The spec says if a folder doesnt exist, we
			// should return ""
			case SpecialFolder.Favorites:
			case SpecialFolder.Programs:
			case SpecialFolder.SendTo:
			case SpecialFolder.StartMenu:
			case SpecialFolder.Startup:
			case SpecialFolder.Templates:
			case SpecialFolder.Cookies:
			case SpecialFolder.History:
			case SpecialFolder.InternetCache:
			case SpecialFolder.Recent:
			case SpecialFolder.CommonProgramFiles:
			case SpecialFolder.ProgramFiles:
			case SpecialFolder.System:
				return String.Empty;
			// This is where data common to all users goes
			case SpecialFolder.CommonApplicationData:
				return "/usr/share";
			default:
				throw new ArgumentException ("Invalid SpecialFolder");
                        }
                }
예제 #12
0
 /// <summary>
 /// Gets the path to the system special folder that is identified by the specified enumeration.
 /// </summary>
 /// <param name="folder">Special folder enumeration.</param>
 /// <param name="create">Tells to create the directory if it does not exist.</param>
 /// <remarks>
 /// Local and roaming data directories are designed for module data and settings files.
 /// NOTE: Names like <b>FarNet.*</b> are reserved for the internal use.
 /// </remarks>
 public abstract string GetFolderPath(SpecialFolder folder, bool create);
예제 #13
0
 public string GetRelativePath(string relativePath, SpecialFolder folder)
 {
     return(GetRelativePath(folder + "\\" + relativePath));
 }
예제 #14
0
        public static string GetSpecialFolder(SpecialFolder folder)
        {
            switch (folder)
            {
            case SpecialFolder.AddNewPrograms:        return(NativeMethods.GetKnownFolderPath(new Guid("de61d971-5ebc-4f02-a3a9-6c82895e5c04")));

            case SpecialFolder.AdminTools:            return(NativeMethods.GetKnownFolderPath(new Guid("724EF170-A42D-4FEF-9F26-B60E846FBA4F")));

            case SpecialFolder.AppUpdates:            return(NativeMethods.GetKnownFolderPath(new Guid("a305ce99-f527-492b-8b1a-7e76fa98d6e4")));

            case SpecialFolder.CDBurning:             return(NativeMethods.GetKnownFolderPath(new Guid("9E52AB10-F80D-49DF-ACB8-4330F5687855")));

            case SpecialFolder.ChangeRemovePrograms:  return(NativeMethods.GetKnownFolderPath(new Guid("df7266ac-9274-4867-8d55-3bd661de872d")));

            case SpecialFolder.CommonAdminTools:      return(NativeMethods.GetKnownFolderPath(new Guid("D0384E7D-BAC3-4797-8F14-CBA229B392B5")));

            case SpecialFolder.CommonOEMLinks:        return(NativeMethods.GetKnownFolderPath(new Guid("C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D")));

            case SpecialFolder.CommonPrograms:        return(NativeMethods.GetKnownFolderPath(new Guid("0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8")));

            case SpecialFolder.CommonStartMenu:       return(NativeMethods.GetKnownFolderPath(new Guid("A4115719-D62E-491D-AA7C-E74B8BE3B067")));

            case SpecialFolder.CommonStartup:         return(NativeMethods.GetKnownFolderPath(new Guid("82A5EA35-D9CD-47C5-9629-E15D2F714E6E")));

            case SpecialFolder.CommonTemplates:       return(NativeMethods.GetKnownFolderPath(new Guid("B94237E7-57AC-4347-9151-B08C6C32D1F7")));

            case SpecialFolder.ComputerFolder:        return(NativeMethods.GetKnownFolderPath(new Guid("0AC0837C-BBF8-452A-850D-79D08E667CA7")));

            case SpecialFolder.ConflictFolder:        return(NativeMethods.GetKnownFolderPath(new Guid("4bfefb45-347d-4006-a5be-ac0cb0567192")));

            case SpecialFolder.ConnectionsFolder:     return(NativeMethods.GetKnownFolderPath(new Guid("6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD")));

            case SpecialFolder.Contacts:              return(NativeMethods.GetKnownFolderPath(new Guid("56784854-C6CB-462b-8169-88E350ACB882")));

            case SpecialFolder.ControlPanelFolder:    return(NativeMethods.GetKnownFolderPath(new Guid("82A74AEB-AEB4-465C-A014-D097EE346D63")));

            case SpecialFolder.Cookies:               return(NativeMethods.GetKnownFolderPath(new Guid("2B0F765D-C0E9-4171-908E-08A611B84FF6")));

            case SpecialFolder.Desktop:               return(NativeMethods.GetKnownFolderPath(new Guid("B4BFCC3A-DB2C-424C-B029-7FE99A87C641")));

            case SpecialFolder.Documents:             return(NativeMethods.GetKnownFolderPath(new Guid("FDD39AD0-238F-46AF-ADB4-6C85480369C7")));

            case SpecialFolder.Downloads:             return(NativeMethods.GetKnownFolderPath(new Guid("374DE290-123F-4565-9164-39C4925E467B")));

            case SpecialFolder.Favorites:             return(NativeMethods.GetKnownFolderPath(new Guid("1777F761-68AD-4D8A-87BD-30B759FA33DD")));

            case SpecialFolder.Fonts:                 return(NativeMethods.GetKnownFolderPath(new Guid("FD228CB7-AE11-4AE3-864C-16F3910AB8FE")));

            case SpecialFolder.Games:                 return(NativeMethods.GetKnownFolderPath(new Guid("CAC52C1A-B53D-4edc-92D7-6B2E8AC19434")));

            case SpecialFolder.GameTasks:             return(NativeMethods.GetKnownFolderPath(new Guid("054FAE61-4DD8-4787-80B6-090220C4B700")));

            case SpecialFolder.History:               return(NativeMethods.GetKnownFolderPath(new Guid("D9DC8A3B-B784-432E-A781-5A1130A75963")));

            case SpecialFolder.InternetCache:         return(NativeMethods.GetKnownFolderPath(new Guid("352481E8-33BE-4251-BA85-6007CAEDCF9D")));

            case SpecialFolder.InternetFolder:        return(NativeMethods.GetKnownFolderPath(new Guid("4D9F7874-4E0C-4904-967B-40B0D20C3E4B")));

            case SpecialFolder.Links:                 return(NativeMethods.GetKnownFolderPath(new Guid("bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968")));

            case SpecialFolder.LocalAppData:          return(NativeMethods.GetKnownFolderPath(new Guid("F1B32785-6FBA-4FCF-9D55-7B8E7F157091")));

            case SpecialFolder.LocalAppDataLow:       return(NativeMethods.GetKnownFolderPath(new Guid("A520A1A4-1780-4FF6-BD18-167343C5AF16")));

            case SpecialFolder.LocalizedResourcesDir: return(NativeMethods.GetKnownFolderPath(new Guid("2A00375E-224C-49DE-B8D1-440DF7EF3DDC")));

            case SpecialFolder.Music:                 return(NativeMethods.GetKnownFolderPath(new Guid("4BD8D571-6D19-48D3-BE97-422220080E43")));

            case SpecialFolder.NetHood:               return(NativeMethods.GetKnownFolderPath(new Guid("C5ABBF53-E17F-4121-8900-86626FC2C973")));

            case SpecialFolder.NetworkFolder:         return(NativeMethods.GetKnownFolderPath(new Guid("D20BEEC4-5CA8-4905-AE3B-BF251EA09B53")));

            case SpecialFolder.OriginalImages:        return(NativeMethods.GetKnownFolderPath(new Guid("2C36C0AA-5812-4b87-BFD0-4CD0DFB19B39")));

            case SpecialFolder.PhotoAlbums:           return(NativeMethods.GetKnownFolderPath(new Guid("69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C")));

            case SpecialFolder.Pictures:              return(NativeMethods.GetKnownFolderPath(new Guid("33E28130-4E1E-4676-835A-98395C3BC3BB")));

            case SpecialFolder.Playlists:             return(NativeMethods.GetKnownFolderPath(new Guid("DE92C1C7-837F-4F69-A3BB-86E631204A23")));

            case SpecialFolder.PrintersFolder:        return(NativeMethods.GetKnownFolderPath(new Guid("76FC4E2D-D6AD-4519-A663-37BD56068185")));

            case SpecialFolder.PrintHood:             return(NativeMethods.GetKnownFolderPath(new Guid("9274BD8D-CFD1-41C3-B35E-B13F55A758F4")));

            case SpecialFolder.Profile:               return(NativeMethods.GetKnownFolderPath(new Guid("5E6C858F-0E22-4760-9AFE-EA3317B67173")));

            case SpecialFolder.ProgramData:           return(NativeMethods.GetKnownFolderPath(new Guid("62AB5D82-FDC1-4DC3-A9DD-070D1D495D97")));

            case SpecialFolder.ProgramFiles:          return(NativeMethods.GetKnownFolderPath(new Guid("905e63b6-c1bf-494e-b29c-65b732d3d21a")));

            case SpecialFolder.ProgramFilesX64:       return(NativeMethods.GetKnownFolderPath(new Guid("6D809377-6AF0-444b-8957-A3773F02200E")));

            case SpecialFolder.ProgramFilesX86:       return(NativeMethods.GetKnownFolderPath(new Guid("7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E")));

            case SpecialFolder.ProgramFilesCommon:    return(NativeMethods.GetKnownFolderPath(new Guid("F7F1ED05-9F6D-47A2-AAAE-29D317C6F066")));

            case SpecialFolder.ProgramFilesCommonX64: return(NativeMethods.GetKnownFolderPath(new Guid("6365D5A7-0F0D-45E5-87F6-0DA56B6A4F7D")));

            case SpecialFolder.ProgramFilesCommonX86: return(NativeMethods.GetKnownFolderPath(new Guid("DE974D24-D9C6-4D3E-BF91-F4455120B917")));

            case SpecialFolder.Programs:              return(NativeMethods.GetKnownFolderPath(new Guid("A77F5D77-2E2B-44C3-A6A2-ABA601054A51")));

            case SpecialFolder.Public:                return(NativeMethods.GetKnownFolderPath(new Guid("DFDF76A2-C82A-4D63-906A-5644AC457385")));

            case SpecialFolder.PublicDesktop:         return(NativeMethods.GetKnownFolderPath(new Guid("C4AA340D-F20F-4863-AFEF-F87EF2E6BA25")));

            case SpecialFolder.PublicDocuments:       return(NativeMethods.GetKnownFolderPath(new Guid("ED4824AF-DCE4-45A8-81E2-FC7965083634")));

            case SpecialFolder.PublicDownloads:       return(NativeMethods.GetKnownFolderPath(new Guid("3D644C9B-1FB8-4f30-9B45-F670235F79C0")));

            case SpecialFolder.PublicGameTasks:       return(NativeMethods.GetKnownFolderPath(new Guid("DEBF2536-E1A8-4c59-B6A2-414586476AEA")));

            case SpecialFolder.PublicMusic:           return(NativeMethods.GetKnownFolderPath(new Guid("3214FAB5-9757-4298-BB61-92A9DEAA44FF")));

            case SpecialFolder.PublicPictures:        return(NativeMethods.GetKnownFolderPath(new Guid("B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5")));

            case SpecialFolder.PublicVideos:          return(NativeMethods.GetKnownFolderPath(new Guid("2400183A-6185-49FB-A2D8-4A392A602BA3")));

            case SpecialFolder.QuickLaunch:           return(NativeMethods.GetKnownFolderPath(new Guid("52a4f021-7b75-48a9-9f6b-4b87a210bc8f")));

            case SpecialFolder.Recent:                return(NativeMethods.GetKnownFolderPath(new Guid("AE50C081-EBD2-438A-8655-8A092E34987A")));

            case SpecialFolder.RecycleBinFolder:      return(NativeMethods.GetKnownFolderPath(new Guid("B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC")));

            case SpecialFolder.ResourceDir:           return(NativeMethods.GetKnownFolderPath(new Guid("8AD10C31-2ADB-4296-A8F7-E4701232C972")));

            case SpecialFolder.RoamingAppData:        return(NativeMethods.GetKnownFolderPath(new Guid("3EB685DB-65F9-4CF6-A03A-E3EF65729F3D")));

            case SpecialFolder.SampleMusic:           return(NativeMethods.GetKnownFolderPath(new Guid("B250C668-F57D-4EE1-A63C-290EE7D1AA1F")));

            case SpecialFolder.SamplePictures:        return(NativeMethods.GetKnownFolderPath(new Guid("C4900540-2379-4C75-844B-64E6FAF8716B")));

            case SpecialFolder.SamplePlaylists:       return(NativeMethods.GetKnownFolderPath(new Guid("15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5")));

            case SpecialFolder.SampleVideos:          return(NativeMethods.GetKnownFolderPath(new Guid("859EAD94-2E85-48AD-A71A-0969CB56A6CD")));

            case SpecialFolder.SavedGames:            return(NativeMethods.GetKnownFolderPath(new Guid("4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4")));

            case SpecialFolder.SavedSearches:         return(NativeMethods.GetKnownFolderPath(new Guid("7d1d3a04-debb-4115-95cf-2f29da2920da")));

            case SpecialFolder.SearchCSC:             return(NativeMethods.GetKnownFolderPath(new Guid("ee32e446-31ca-4aba-814f-a5ebd2fd6d5e")));

            case SpecialFolder.SearchMapi:            return(NativeMethods.GetKnownFolderPath(new Guid("98ec0e18-2098-4d44-8644-66979315a281")));

            case SpecialFolder.SearchHome:            return(NativeMethods.GetKnownFolderPath(new Guid("190337d1-b8ca-4121-a639-6d472d16972a")));

            case SpecialFolder.SendTo:                return(NativeMethods.GetKnownFolderPath(new Guid("8983036C-27C0-404B-8F08-102D10DCFD74")));

            case SpecialFolder.SidebarDefaultParts:   return(NativeMethods.GetKnownFolderPath(new Guid("7B396E54-9EC5-4300-BE0A-2482EBAE1A26")));

            case SpecialFolder.SidebarParts:          return(NativeMethods.GetKnownFolderPath(new Guid("A75D362E-50FC-4fb7-AC2C-A8BEAA314493")));

            case SpecialFolder.StartMenu:             return(NativeMethods.GetKnownFolderPath(new Guid("625B53C3-AB48-4EC1-BA1F-A1EF4146FC19")));

            case SpecialFolder.Startup:               return(NativeMethods.GetKnownFolderPath(new Guid("B97D20BB-F46A-4C97-BA10-5E3608430854")));

            case SpecialFolder.SyncManagerFolder:     return(NativeMethods.GetKnownFolderPath(new Guid("43668BF8-C14E-49B2-97C9-747784D784B7")));

            case SpecialFolder.SyncResultsFolder:     return(NativeMethods.GetKnownFolderPath(new Guid("289a9a43-be44-4057-a41b-587a76d7e7f9")));

            case SpecialFolder.SyncSetupFolder:       return(NativeMethods.GetKnownFolderPath(new Guid("0F214138-B1D3-4a90-BBA9-27CBC0C5389A")));

            case SpecialFolder.System:                return(NativeMethods.GetKnownFolderPath(new Guid("1AC14E77-02E7-4E5D-B744-2EB1AE5198B7")));

            case SpecialFolder.SystemX86:             return(NativeMethods.GetKnownFolderPath(new Guid("D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27")));

            case SpecialFolder.Templates:             return(NativeMethods.GetKnownFolderPath(new Guid("A63293E8-664E-48DB-A079-DF759E0509F7")));

            case SpecialFolder.TreeProperties:        return(NativeMethods.GetKnownFolderPath(new Guid("5b3749ad-b49f-49c1-83eb-15370fbd4882")));

            case SpecialFolder.UserProfiles:          return(NativeMethods.GetKnownFolderPath(new Guid("0762D272-C50A-4BB0-A382-697DCD729B80")));

            case SpecialFolder.UsersFiles:            return(NativeMethods.GetKnownFolderPath(new Guid("f3ce0f7c-4901-4acc-8648-d5d44b04ef8f")));

            case SpecialFolder.Videos:                return(NativeMethods.GetKnownFolderPath(new Guid("18989B1D-99B5-455B-841C-AB7C74E4DDFC")));

            case SpecialFolder.Windows:               return(NativeMethods.GetKnownFolderPath(new Guid("F38BF404-1D43-42F2-9305-67DE0B28FC23")));

            default:
                throw new ArgumentException(RS.InvalidSpecialFolderEnum, nameof(folder));
            }
        }
예제 #15
0
        public string GetFullPath(string directory, string filenameWithExtention, bool ensureDirectoryExists = false, SpecialFolder specialFolder = SpecialFolder.None)
        {
            var directoryPath = specialFolder == SpecialFolder.None ? directory : Combine(GetSpecialFolder(specialFolder), directory);
            var fullPath      = Combine(directoryPath, filenameWithExtention);

            if (ensureDirectoryExists)
            {
                CreateDirectory(directoryPath);
            }

            return(fullPath);
        }
예제 #16
0
 private static string GetFolderPathCoreFallBack(SpecialFolder folder) =>
 // For testing without the new WinRT APIs. We cannot use Win32 APIs for
 // special folders as they are not in the WACK.
 folder switch
 {
예제 #17
0
 public string GetFolderPath(SpecialFolder folder)
 {
     // In virtual file system, all special folders are associated with the root
     return(Root.FullPath);
 }
예제 #18
0
        private static string GetFolderPathCoreCurrent(SpecialFolder folder)
        {
            // While all of these give back real paths, most of them are not accessible
            // from an appcontainer currently (they will give access denied)
            switch (folder)
            {
            case SpecialFolder.ApplicationData:
                return(UserDataPaths.GetDefault().RoamingAppData);

            case SpecialFolder.CommonApplicationData:
                return(AppDataPaths.GetDefault().ProgramData);

            case SpecialFolder.LocalApplicationData:
                return(AppDataPaths.GetDefault().LocalAppData);

            case SpecialFolder.Cookies:
                return(AppDataPaths.GetDefault().Cookies);

            case SpecialFolder.Desktop:
                return(AppDataPaths.GetDefault().Desktop);

            case SpecialFolder.Favorites:
                return(AppDataPaths.GetDefault().Favorites);

            case SpecialFolder.History:
                return(AppDataPaths.GetDefault().History);

            case SpecialFolder.InternetCache:
                return(AppDataPaths.GetDefault().InternetCache);

            case SpecialFolder.MyMusic:
                return(UserDataPaths.GetDefault().Music);

            case SpecialFolder.MyPictures:
                return(UserDataPaths.GetDefault().Pictures);

            case SpecialFolder.MyVideos:
                return(UserDataPaths.GetDefault().Videos);

            case SpecialFolder.Recent:
                return(UserDataPaths.GetDefault().Recent);

            case SpecialFolder.System:
                return(SystemDataPaths.GetDefault().System);

            case SpecialFolder.Templates:
                return(UserDataPaths.GetDefault().Templates);

            case SpecialFolder.DesktopDirectory:
                return(UserDataPaths.GetDefault().Desktop);

            case SpecialFolder.Personal:
                return(UserDataPaths.GetDefault().Documents);

            case SpecialFolder.CommonDocuments:
                return(SystemDataPaths.GetDefault().PublicDocuments);

            case SpecialFolder.CommonMusic:
                return(SystemDataPaths.GetDefault().PublicMusic);

            case SpecialFolder.CommonPictures:
                return(SystemDataPaths.GetDefault().PublicPictures);

            case SpecialFolder.CommonDesktopDirectory:
                return(SystemDataPaths.GetDefault().PublicDesktop);

            case SpecialFolder.CommonVideos:
                return(SystemDataPaths.GetDefault().PublicVideos);

            case SpecialFolder.UserProfile:
                return(UserDataPaths.GetDefault().Profile);

            case SpecialFolder.SystemX86:
                return(SystemDataPaths.GetDefault().SystemX86);

            case SpecialFolder.Windows:
                return(SystemDataPaths.GetDefault().Windows);

            // The following aren't available on WinRT. Our default behavior
            // is string.Empty for paths that aren't available.
            //
            // case SpecialFolder.Programs:
            // case SpecialFolder.MyComputer:
            // case SpecialFolder.SendTo:
            // case SpecialFolder.StartMenu:
            // case SpecialFolder.Startup:
            // case SpecialFolder.ProgramFiles:
            // case SpecialFolder.CommonProgramFiles:
            // case SpecialFolder.AdminTools:
            // case SpecialFolder.CDBurning:
            // case SpecialFolder.CommonAdminTools:
            // case SpecialFolder.CommonOemLinks:
            // case SpecialFolder.CommonStartMenu:
            // case SpecialFolder.CommonPrograms:
            // case SpecialFolder.CommonStartup:
            // case SpecialFolder.CommonTemplates:
            // case SpecialFolder.Fonts:
            // case SpecialFolder.NetworkShortcuts:
            // case SpecialFolder.PrinterShortcuts:
            // case SpecialFolder.CommonProgramFilesX86:
            // case SpecialFolder.ProgramFilesX86:
            // case SpecialFolder.Resources:
            // case SpecialFolder.LocalizedResources:

            default:
                return(string.Empty);
            }
        }
예제 #19
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
 {
     return string.Empty;
 }
예제 #20
0
 public string GetFolderPath(SpecialFolder folder, SpecialFolderOption option = SpecialFolderOption.None) => Environment.GetFolderPath((Environment.SpecialFolder)folder, (Environment.SpecialFolderOption)option);
예제 #21
0
		/// <summary>
		/// Get the specified special folder.
		/// </summary>
		/// <remarks>
		/// Not all IMAP servers support special folders. Only IMAP servers
		/// supporting the <see cref="ImapCapabilities.SpecialUse"/> or
		/// <see cref="ImapCapabilities.XList"/> extensions may have
		/// special folders.
		/// </remarks>
		/// <returns>The folder if available; otherwise <c>null</c>.</returns>
		/// <param name="folder">The type of special folder.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="folder"/> is out of range.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="ImapClient"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="ImapClient"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="ImapClient"/> is not authenticated.
		/// </exception>
		public override IMailFolder GetFolder (SpecialFolder folder)
		{
			CheckDisposed ();
			CheckConnected ();
			CheckAuthenticated ();

			switch (folder) {
			case SpecialFolder.All:     return engine.All;
			case SpecialFolder.Archive: return engine.Archive;
			case SpecialFolder.Drafts:  return engine.Drafts;
			case SpecialFolder.Flagged: return engine.Flagged;
			case SpecialFolder.Junk:    return engine.Junk;
			case SpecialFolder.Sent:    return engine.Sent;
			case SpecialFolder.Trash:   return engine.Trash;
			default: throw new ArgumentOutOfRangeException ("folder");
			}
		}
예제 #22
0
 /// <summary>
 /// INTERNAL Gets the local or roamimg data directory path of the application.
 /// </summary>
 /// <param name="folder">The special folder.</param>
 /// <remarks>
 /// This method and directories are used by the core and not designed for modules.
 /// Modules should use <see cref="IModuleManager.GetFolderPath"/> in order to get their data directories.
 /// </remarks>
 public abstract string GetFolderPath(SpecialFolder folder);
 internal static string UnsafeGetFolderPath(SpecialFolder folder)
 {
     return InternalGetFolderPath(folder, SpecialFolderOption.None, suppressSecurityChecks: true);
 }
예제 #24
0
	// Get a path to a specific system folder.
	public static String GetFolderPath(SpecialFolder folder)
			{
				// We can use the operating system under Win32.
				if(InfoMethods.GetPlatformID() != PlatformID.Unix)
				{
					// Allocate a buffer to hold the result path.
					IntPtr buffer = Marshal.AllocHGlobal(260 /*MAX_PATH*/ + 1);

					// Call "SHGetFolderPath" to retrieve the path.
					try
					{
						SHGetFolderPathA(IntPtr.Zero, (int)folder,
									     IntPtr.Zero, 0, buffer);
						String value = Marshal.PtrToStringAnsi(buffer);
						if(value != null && value.Length != 0)
						{
							Marshal.FreeHGlobal(buffer);
							return value;
						}
					}
					catch(Exception)
					{
						// We weren't able to find the function in the DLL.
					}
					Marshal.FreeHGlobal(buffer);
				}

				// Special handling for some of the cases.
				String dir = null;
				switch(folder)
				{
					case SpecialFolder.System:
					{
						dir = DirMethods.GetSystemDirectory();
					}
					break;

					case SpecialFolder.ApplicationData:
					{
						dir = InfoMethods.GetUserStorageDir() +
							  Path.DirectorySeparatorChar +
							  "ApplicationData";
					}
					break;

					case SpecialFolder.LocalApplicationData:
					{
						dir = InfoMethods.GetUserStorageDir() +
							  Path.DirectorySeparatorChar +
							  "LocalApplicationData";
					}
					break;

					case SpecialFolder.CommonApplicationData:
					{
						dir = InfoMethods.GetUserStorageDir() +
							  Path.DirectorySeparatorChar +
							  "CommonApplicationData";
					}
					break;
				}
				if(dir != null && dir.Length > 0)
				{
					return dir;
				}

				// The empty string indicates that the value is not present.
				return String.Empty;
			}
예제 #25
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);
        }
 public string GetEnsuredPath(string path, SpecialFolder folder)
 {
     return GetEnsuredPath(folder + "\\" + path, false);
 }
예제 #27
0
        // the security runtime (and maybe other parts of corlib) needs the
        // information to initialize themselves before permissions can be checked
        internal static string InternalGetFolderPath(SpecialFolder folder)
        {
            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)
            {
#if NET_1_1
            // MyComputer is a virtual directory
            case SpecialFolder.MyComputer:
                return(String.Empty);
#endif
            // personal == ~
            case SpecialFolder.Personal:
#if MONOTOUCH && !UNITY
                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:
                return(config);

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

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

            case SpecialFolder.MyMusic:
                return(ReadXdgUserDir(config, home, "XDG_MUSIC_DIR", "Music"));

            case SpecialFolder.MyPictures:
                return(ReadXdgUserDir(config, home, "XDG_PICTURES_DIR", "Pictures"));

            // these simply dont exist on Linux
            // The spec says if a folder doesnt exist, we
            // should return ""
            case SpecialFolder.Favorites:
            case SpecialFolder.Programs:
            case SpecialFolder.SendTo:
            case SpecialFolder.StartMenu:
            case SpecialFolder.Startup:
            case SpecialFolder.Templates:
            case SpecialFolder.Cookies:
            case SpecialFolder.History:
            case SpecialFolder.InternetCache:
            case SpecialFolder.Recent:
            case SpecialFolder.CommonProgramFiles:
            case SpecialFolder.ProgramFiles:
            case SpecialFolder.System:
                return(String.Empty);

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

            default:
                throw new ArgumentException("Invalid SpecialFolder");
            }
        }
예제 #28
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option) =>
 WinRTFolderPaths.GetFolderPath(folder, option);
 public string GetRelativePath(string relativePath, SpecialFolder folder)
 {
     return GetRelativePath(folder + "\\" + relativePath);
 }
예제 #30
0
        private static string GetFolderPath(SpecialFolder folder)
        {
            switch (folder)
            {
            case SpecialFolder.ProgramFilesX86:
                return(Environment.GetEnvironmentVariable("PROGRAMFILES(X86)"));

            case SpecialFolder.ProgramFiles:
                return(Environment.GetEnvironmentVariable("PROGRAMFILES"));

            case SpecialFolder.UserProfile:
                return(_getHome.Value);

            case SpecialFolder.CommonApplicationData:
                if (RuntimeEnvironmentHelper.IsWindows)
                {
                    var programData = Environment.GetEnvironmentVariable("PROGRAMDATA");

                    if (!string.IsNullOrEmpty(programData))
                    {
                        return(programData);
                    }

                    return(Environment.GetEnvironmentVariable("ALLUSERSPROFILE"));
                }
                else if (RuntimeEnvironmentHelper.IsMacOSX)
                {
                    return(@"/Library/Application Support");
                }
                else
                {
                    var commonApplicationDataOverride = Environment.GetEnvironmentVariable("NUGET_COMMON_APPLICATION_DATA");

                    if (!string.IsNullOrEmpty(commonApplicationDataOverride))
                    {
                        return(commonApplicationDataOverride);
                    }

                    return(@"/etc/opt");
                }

            case SpecialFolder.ApplicationData:
                if (RuntimeEnvironmentHelper.IsWindows)
                {
                    return(Environment.GetEnvironmentVariable("APPDATA"));
                }
                else
                {
                    return(Path.Combine(_getHome.Value, ".nuget"));
                }

            case SpecialFolder.LocalApplicationData:
                if (RuntimeEnvironmentHelper.IsWindows)
                {
                    return(Environment.GetEnvironmentVariable("LOCALAPPDATA"));
                }
                else
                {
                    var xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
                    if (!string.IsNullOrEmpty(xdgDataHome))
                    {
                        return(xdgDataHome);
                    }

                    return(Path.Combine(_getHome.Value, ".local", "share"));
                }

            default:
                return(null);
            }
        }
 protected string GetSpecialFolder(SpecialFolder folder) => _folders[folder];
예제 #32
0
 /// <summary>
 /// Get the specified special folder.
 /// </summary>
 /// <remarks>
 /// Not all mail stores support special folders. Each implementation
 /// should provide a way to determine if special folders are supported.
 /// </remarks>
 /// <returns>The folder if available; otherwise <c>null</c>.</returns>
 /// <param name="folder">The type of special folder.</param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// <paramref name="folder"/> is out of range.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 /// The <see cref="MailStore"/> has been disposed.
 /// </exception>
 /// <exception cref="ServiceNotConnectedException">
 /// The <see cref="MailStore"/> is not connected.
 /// </exception>
 /// <exception cref="ServiceNotAuthenticatedException">
 /// The <see cref="MailStore"/> is not authenticated.
 /// </exception>
 public abstract IMailFolder GetFolder(SpecialFolder folder);
 private void AddSpecialFolder(SpecialFolder folder, string path) => _folders.Add(folder, path);
예제 #34
0
 private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
 {
     return(string.Empty);
 }
예제 #35
0
		/// <summary>
		/// Asynchronously create a new subfolder with the given name.
		/// </summary>
		/// <remarks>
		/// Asynchronously creates a new subfolder with the given name.
		/// </remarks>
		/// <returns>The created folder.</returns>
		/// <param name="name">The name of the folder to create.</param>
		/// <param name="specialUse">The special use for the folder being created.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="name"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="name"/> is empty.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The <see cref="DirectorySeparator"/> is nil, and thus child folders cannot be created.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The <see cref="MailService"/> does not support the creation of special folders.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public virtual Task<IMailFolder> CreateAsync (string name, SpecialFolder specialUse, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (name == null)
				throw new ArgumentNullException (nameof (name));

			if (name.Length == 0 || name.IndexOf (DirectorySeparator) != -1)
				throw new ArgumentException ("The name is not a legal folder name.", nameof (name));

			return Task.Factory.StartNew (() => {
				lock (SyncRoot) {
					return Create (name, specialUse, cancellationToken);
				}
			}, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
		}
예제 #36
0
 /// <param name="folder">
 ///   A <see cref="T:System.Environment+SpecialFolder" /> instance.
 /// </param>
 /// <remarks>
 ///   <c>M:System.Environment.GetFolderPath(System.Environment+SpecialFolder)</c>
 /// </remarks>
 public static string GetFolderPath(SpecialFolder folder)
 {
     throw new NotSupportedException();
 }
예제 #37
0
		/// <summary>
		/// Get the specified special folder.
		/// </summary>
		/// <remarks>
		/// Not all IMAP servers support special folders. Only IMAP servers
		/// supporting the <see cref="ImapCapabilities.SpecialUse"/> or
		/// <see cref="ImapCapabilities.XList"/> extensions may have
		/// special folders.
		/// </remarks>
		/// <returns>The folder if available; otherwise <c>null</c>.</returns>
		/// <param name="folder">The type of special folder.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="folder"/> is out of range.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="ImapClient"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="ImapClient"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="ImapClient"/> is not authenticated.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The IMAP server does not support the SPECIAL-USE nor XLIST extensions.
		/// </exception>
		public override IMailFolder GetFolder (SpecialFolder folder)
		{
			CheckDisposed ();
			CheckConnected ();
			CheckAuthenticated ();

			if ((Capabilities & (ImapCapabilities.SpecialUse | ImapCapabilities.XList)) == 0)
				throw new NotSupportedException ("The IMAP server does not support the SPECIAL-USE nor XLIST extensions.");

			switch (folder) {
			case SpecialFolder.All:     return engine.All;
			case SpecialFolder.Archive: return engine.Archive;
			case SpecialFolder.Drafts:  return engine.Drafts;
			case SpecialFolder.Flagged: return engine.Flagged;
			case SpecialFolder.Junk:    return engine.Junk;
			case SpecialFolder.Sent:    return engine.Sent;
			case SpecialFolder.Trash:   return engine.Trash;
			default: throw new ArgumentOutOfRangeException ("folder");
			}
		}
예제 #38
0
 /// <summary>
 /// Returns the fully qualified path of the
 /// folder specified by the "folder" parameter
 /// </summary>
 public static string GetFolderPath(SpecialFolder folder)
 {
     return(GetFolderPath(folder, SpecialFolderOption.None));
 }
		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;
		}
예제 #40
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");
            }
        }
예제 #41
0
        /// <summary>
        /// Gets the specified special folder.
        /// </summary>
        /// <remarks>
        /// Not all IMAP servers support special folders. Only IMAP servers
        /// supporting the <see cref="ImapCapabilities.SpecialUse"/> or
        /// <see cref="ImapCapabilities.XList"/> extensions may have
        /// special folders.
        /// </remarks>
        /// <returns>The folder if available; otherwise <c>null</c>.</returns>
        /// <param name="folder">The type of special folder.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="folder"/> is out of range.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="ImapClient"/> has been disposed.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// <para>The <see cref="ImapClient"/> is not connected.</para>
        /// <para>-or-</para>
        /// <para>The <see cref="ImapClient"/> is not authenticated.</para>
        /// </exception>
        public IFolder GetFolder(SpecialFolder folder)
        {
            CheckDisposed ();

            if (!IsConnected)
                throw new InvalidOperationException ("The ImapClient is not connected.");

            if (engine.State != ImapEngineState.Authenticated && engine.State != ImapEngineState.Selected)
                throw new InvalidOperationException ("The ImapClient is not authenticated.");

            switch (folder) {
            case SpecialFolder.All:     return engine.All;
            case SpecialFolder.Archive: return engine.Archive;
            case SpecialFolder.Drafts:  return engine.Drafts;
            case SpecialFolder.Flagged: return engine.Flagged;
            case SpecialFolder.Junk:    return engine.Junk;
            case SpecialFolder.Sent:    return engine.Sent;
            case SpecialFolder.Trash:   return engine.Trash;
            default: throw new ArgumentOutOfRangeException ("folder");
            }
        }
예제 #42
0
        private static string GetFolderPathCoreWithoutValidation(SpecialFolder folder)
        {
            // First handle any paths that involve only static paths, avoiding the overheads of getting user-local paths.
            // https://www.freedesktop.org/software/systemd/man/file-hierarchy.html
            switch (folder)
            {
            case SpecialFolder.CommonApplicationData: return("/usr/share");

            case SpecialFolder.CommonTemplates: return("/usr/share/templates");
            }
            if (IsMac)
            {
                switch (folder)
                {
                case SpecialFolder.ProgramFiles: return("/Applications");

                case SpecialFolder.System: return("/System");
                }
            }

            // All other paths are based on the XDG Base Directory Specification:
            // https://specifications.freedesktop.org/basedir-spec/latest/
            string home;

            try
            {
                home = PersistedFiles.GetHomeDirectory();
            }
            catch (Exception exc)
            {
                Debug.Fail($"Unable to get home directory: {exc}");
                home = Path.GetTempPath();
            }
            Debug.Assert(!string.IsNullOrEmpty(home), "Expected non-null or empty HOME");

            // TODO: Consider caching (or precomputing and caching) all subsequent results.
            // This would significantly improve performance for repeated access, at the expense
            // of not being responsive to changes in the underlying environment variables,
            // configuration files, etc.

            switch (folder)
            {
            case SpecialFolder.UserProfile:
            case SpecialFolder.MyDocuments:     // same value as Personal
                return(home);

            case SpecialFolder.ApplicationData:
                return(GetXdgConfig(home));

            case SpecialFolder.LocalApplicationData:
                // "$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored."
                // "If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used."
                string data = GetEnvironmentVariable("XDG_DATA_HOME");
                if (string.IsNullOrEmpty(data) || data[0] != '/')
                {
                    data = Path.Combine(home, ".local", "share");
                }
                return(data);

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

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

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

            case SpecialFolder.MyMusic:
                return(IsMac ? Path.Combine(home, "Music") : ReadXdgDirectory(home, "XDG_MUSIC_DIR", "Music"));

            case SpecialFolder.MyPictures:
                return(IsMac ? Path.Combine(home, "Pictures") : ReadXdgDirectory(home, "XDG_PICTURES_DIR", "Pictures"));

            case SpecialFolder.Fonts:
                return(IsMac ? Path.Combine(home, "Library", "Fonts") : Path.Combine(home, ".fonts"));

            case SpecialFolder.Favorites:
                if (IsMac)
                {
                    return(Path.Combine(home, "Library", "Favorites"));
                }
                break;

            case SpecialFolder.InternetCache:
                if (IsMac)
                {
                    return(Path.Combine(home, "Library", "Caches"));
                }
                break;
            }

            // No known path for the SpecialFolder
            return(string.Empty);
        }
예제 #43
0
파일: MailStore.cs 프로젝트: dcga/MailKit
		/// <summary>
		/// Get the specified special folder.
		/// </summary>
		/// <remarks>
		/// Not all mail stores support special folders. Each implementation
		/// should provide a way to determine if special folders are supported.
		/// </remarks>
		/// <returns>The folder if available; otherwise <c>null</c>.</returns>
		/// <param name="folder">The type of special folder.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="folder"/> is out of range.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="MailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="MailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="MailStore"/> is not authenticated.
		/// </exception>
		public abstract IMailFolder GetFolder (SpecialFolder folder);
예제 #44
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(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);
        }
예제 #46
0
 public static string GetFolderPath(SpecialFolder folder) => GetFolderPath(folder, SpecialFolderOption.None);
        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
        }
예제 #48
0
        private static string?GetSpecialFolder(SpecialFolder folder)
        {
            string?home = null;

            try
            {
                home = PersistedFiles.GetHomeDirectory();
            }
            catch (Exception exc)
            {
                Debug.Fail($"Unable to get home directory: {exc}");
            }

            // Fall back to '/' when we can't determine the home directory.
            // This location isn't writable by non-root users which provides some safeguard
            // that the application doesn't write data which is meant to be private.
            if (string.IsNullOrEmpty(home))
            {
                home = "/";
            }

            switch (folder)
            {
            case SpecialFolder.Personal:
            case SpecialFolder.LocalApplicationData:
                return(home);

            case SpecialFolder.ApplicationData:
                return(Path.Combine(home, ".config"));

            case SpecialFolder.Desktop:
            case SpecialFolder.DesktopDirectory:
                return(Path.Combine(home, "Desktop"));

            case SpecialFolder.MyMusic:
                return(Path.Combine(home, "Music"));

            case SpecialFolder.MyPictures:
                return(Path.Combine(home, "Pictures"));

            case SpecialFolder.Templates:
                return(Path.Combine(home, "Templates"));

            case SpecialFolder.MyVideos:
                return(Path.Combine(home, "Videos"));

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

            case SpecialFolder.Fonts:
                return(Path.Combine(home, ".fonts"));

            case SpecialFolder.UserProfile:
                return(GetEnvironmentVariable("HOME"));

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

            default:
                return(string.Empty);
            }
        }
예제 #49
0
        public static Image GetImage(SpecialFolder specialFolder)
        {
            uint dwflag = NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_PIDL | NativeMethods.SHGFI_ICON;
            int dwAttr = 0;

            IntPtr pidl;
            NativeMethods.Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, (int)specialFolder, out pidl);

            NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO();
            NativeMethods.Shell32.SHGetFileInfo(pidl, dwAttr, ref shfi, Marshal.SizeOf(shfi), dwflag);

            IntPtr iconPtr = NativeMethods.ComCtl32.ImageList_GetIcon(m_largeImageListHandle, shfi.iIcon, NativeMethods.ILD_NORMAL);

            return Icon.FromHandle(iconPtr).ToBitmap();
        }
예제 #50
0
 public IMailFolder GetFolder(SpecialFolder folder)
 {
     return _imapClient.GetFolder(folder);
 }
예제 #51
0
		/// <summary>
		/// Returns the fully qualified path of the
		/// folder specified by the "folder" parameter
		/// </summary>
		public static string GetFolderPath (SpecialFolder folder)
		{
			return GetFolderPath (folder, SpecialFolderOption.None);
		}
예제 #52
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);
        }
예제 #53
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");
                        }
                }
예제 #54
0
        /// <summary>
        /// Creates a path for the given special folder. When the
        /// </summary>
        /// <param name="folder"></param>
        public SmartFolder(SpecialFolder folder)
        {
            var path = GetFolderPath(folder, SpecialFolderOption.None);

            _value = path;
        }