예제 #1
0
        internal static string InternalGetFolderPath(Environment.SpecialFolder folder)
        {
            string text  = Environment.internalGetHome();
            string text2 = Environment.internalGetEnvironmentVariable("XDG_DATA_HOME");

            if (text2 == null || text2 == string.Empty)
            {
                text2 = Path.Combine(text, ".local");
                text2 = Path.Combine(text2, "share");
            }
            string text3 = Environment.internalGetEnvironmentVariable("XDG_CONFIG_HOME");

            if (text3 == null || text3 == string.Empty)
            {
                text3 = Path.Combine(text, ".config");
            }
            switch (folder)
            {
            case Environment.SpecialFolder.Desktop:
            case Environment.SpecialFolder.DesktopDirectory:
                return(Environment.ReadXdgUserDir(text3, text, "XDG_DESKTOP_DIR", "Desktop"));

            case Environment.SpecialFolder.Programs:
            case Environment.SpecialFolder.Favorites:
            case Environment.SpecialFolder.Startup:
            case Environment.SpecialFolder.Recent:
            case Environment.SpecialFolder.SendTo:
            case Environment.SpecialFolder.StartMenu:
            case Environment.SpecialFolder.Templates:
            case Environment.SpecialFolder.InternetCache:
            case Environment.SpecialFolder.Cookies:
            case Environment.SpecialFolder.History:
            case Environment.SpecialFolder.System:
            case Environment.SpecialFolder.ProgramFiles:
            case Environment.SpecialFolder.CommonProgramFiles:
                return(string.Empty);

            case Environment.SpecialFolder.MyDocuments:
                return(text);

            case Environment.SpecialFolder.MyMusic:
                return(Environment.ReadXdgUserDir(text3, text, "XDG_MUSIC_DIR", "Music"));

            case Environment.SpecialFolder.MyComputer:
                return(string.Empty);

            case Environment.SpecialFolder.ApplicationData:
                return(text3);

            case Environment.SpecialFolder.LocalApplicationData:
                return(text2);

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

            case Environment.SpecialFolder.MyPictures:
                return(Environment.ReadXdgUserDir(text3, text, "XDG_PICTURES_DIR", "Pictures"));
            }
            throw new ArgumentException("Invalid SpecialFolder");
        }
예제 #2
0
        private static Hashtable GetEnvironmentVariablesNoCase()
        {
            Hashtable hashtable = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);

            foreach (string text in Environment.GetEnvironmentVariableNames())
            {
                hashtable[text] = Environment.internalGetEnvironmentVariable(text);
            }
            return(hashtable);
        }
예제 #3
0
        /// <summary>Retrieves all environment variable names and their values from the current process.</summary>
        /// <returns>An <see cref="T:System.Collections.IDictionary" /> that contains all environment variable names and their values; otherwise, an empty dictionary if no environment variables are found.</returns>
        /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation.</exception>
        /// <exception cref="T:System.OutOfMemoryException">The buffer is out of memory.</exception>
        /// <filterpriority>1</filterpriority>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public static IDictionary GetEnvironmentVariables()
        {
            Hashtable hashtable = new Hashtable();

            foreach (string text in Environment.GetEnvironmentVariableNames())
            {
                hashtable[text] = Environment.internalGetEnvironmentVariable(text);
            }
            return(hashtable);
        }
예제 #4
0
        private static string ReadXdgUserDir(string config_dir, string home_dir, string key, string fallback)
        {
            string text = Environment.internalGetEnvironmentVariable(key);

            if (text != null && text != string.Empty)
            {
                return(text);
            }
            string path = Path.Combine(config_dir, "user-dirs.dirs");

            if (!File.Exists(path))
            {
                return(Path.Combine(home_dir, fallback));
            }
            try
            {
                using (StreamReader streamReader = new StreamReader(path))
                {
                    string text2;
                    while ((text2 = streamReader.ReadLine()) != null)
                    {
                        text2 = text2.Trim();
                        int num = text2.IndexOf('=');
                        if (num > 8 && text2.Substring(0, num) == key)
                        {
                            string text3 = text2.Substring(num + 1).Trim(new char[]
                            {
                                '"'
                            });
                            bool flag = false;
                            if (text3.StartsWith("$HOME/"))
                            {
                                flag  = true;
                                text3 = text3.Substring(6);
                            }
                            else if (!text3.StartsWith("/"))
                            {
                                flag = true;
                            }
                            return((!flag) ? text3 : Path.Combine(home_dir, text3));
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
            }
            return(Path.Combine(home_dir, fallback));
        }
예제 #5
0
 /// <summary>Retrieves the value of an environment variable from the current process.</summary>
 /// <returns>The value of the environment variable specified by <paramref name="variable" />, or null if the environment variable is not found.</returns>
 /// <param name="variable">The name of the environment variable. </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="variable" /> is null. </exception>
 /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation.</exception>
 /// <filterpriority>1</filterpriority>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 /// </PermissionSet>
 public static string GetEnvironmentVariable(string variable)
 {
     return(Environment.internalGetEnvironmentVariable(variable));
 }