Exemplo n.º 1
0
        /// <summary>
        /// Gets the environment variable value for the given XDG environment variable.
        /// </summary>
        /// <param name="xdgEnvironmentVariable">The XDG environment variable whose value is desired.</param>
        /// <returns>The environment variable value.</returns>
        public static string GetEnvironmentVariableValue(this XdgEnvironmentVariable xdgEnvironmentVariable)
        {
            var    xdgEnvironmentVariableValue = string.Empty;
            string xdgEnvironmentVariableName;

            if (XdgEnvironmentVariableNames.TryGetValue(xdgEnvironmentVariable, out xdgEnvironmentVariableName))
            {
                xdgEnvironmentVariableValue = System.Environment.GetEnvironmentVariable(xdgEnvironmentVariableName);
                if (string.IsNullOrEmpty(xdgEnvironmentVariableValue))
                {
                    xdgEnvironmentVariableValue = xdgEnvironmentVariable.GetDefaultXdgEnvironmentVariableValue();
                }
            }
            return(xdgEnvironmentVariableValue);
        }
Exemplo n.º 2
0
        private static string GetDefaultXdgEnvironmentVariableValue(this XdgEnvironmentVariable xdgEnvironmentVariable)
        {
            var value   = string.Empty;
            var homeDir = PathUtils.UserHomeDirectory;

            switch (xdgEnvironmentVariable)
            {
            case XdgEnvironmentVariable.Data:
                value = System.IO.Path.Combine(homeDir, ".local", "share");
                break;

            case XdgEnvironmentVariable.Config:
                value = System.IO.Path.Combine(homeDir, ".config");
                break;

            case XdgEnvironmentVariable.DataDirectories:
                value = "/usr/local/share/:/usr/share/";
                break;

            case XdgEnvironmentVariable.ConfigDirectories:
                value = "/etc/xdg";
                break;

            case XdgEnvironmentVariable.Cache:
                value = System.IO.Path.Combine(homeDir, ".cache");
                break;

            case XdgEnvironmentVariable.Runtime:
                ////value = System.IO.Path.Combine (homeDir, );
                break;

            case XdgEnvironmentVariable.Desktop:
                value = System.IO.Path.Combine(homeDir, "Desktop");
                break;

            case XdgEnvironmentVariable.Documents:
                value = System.IO.Path.Combine(homeDir, "Documents");
                break;

            case XdgEnvironmentVariable.Downloads:
                value = System.IO.Path.Combine(homeDir, "Downloads");
                break;

            case XdgEnvironmentVariable.Music:
                value = System.IO.Path.Combine(homeDir, "Music");
                break;

            case XdgEnvironmentVariable.Pictures:
                value = System.IO.Path.Combine(homeDir, "Pictures");
                break;

            case XdgEnvironmentVariable.Public:
                value = System.IO.Path.Combine(homeDir, "Public");
                break;

            case XdgEnvironmentVariable.Templates:
                value = System.IO.Path.Combine(homeDir, "Templates");
                break;

            case XdgEnvironmentVariable.Videos:
                value = System.IO.Path.Combine(homeDir, "Videos");
                break;

            default:
                break;
            }
            return(value);
        }