Esempio n. 1
0
        public static bool TryFindShellPath([NotNull] string shell, out string shellPath)
        {
            try
            {
                shellPath = Path.Combine(EnvironmentAbstraction.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Git", shell);
                if (File.Exists(shellPath))
                {
                    return(true);
                }

                shellPath = Path.Combine(AppSettings.GitBinDir, shell);
                if (File.Exists(shellPath))
                {
                    return(true);
                }

                if (TryFindFullPath(shell, out shellPath))
                {
                    return(true);
                }
            }
            catch
            {
                // do nothing
            }

            shellPath = null;
            return(false);
        }
Esempio n. 2
0
        public static bool TryFindShellPath(string shell, [NotNullWhen(returnValue: true)] out string?shellPath)
        {
            try
            {
                shellPath = Path.Combine(EnvironmentAbstraction.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Git", shell);
                if (File.Exists(shellPath))
                {
                    return(true);
                }

                shellPath = Combine(AppSettings.GitBinDir, shell);
                if (File.Exists(shellPath))
                {
                    // TODO remove suppression when targeting .NET 5
#pragma warning disable CS8762 // Parameter must have a non-null value when exiting in some condition.
                    return(true);

#pragma warning restore CS8762 // Parameter must have a non-null value when exiting in some condition.
                }

                if (TryFindFullPath(shell, out shellPath))
                {
                    return(true);
                }
            }
            catch
            {
                // do nothing
            }

            shellPath = null;
            return(false);
        }
Esempio n. 3
0
        public static bool TryFindShellPath(string shell, [NotNullWhen(returnValue: true)] out string?shellPath)
        {
            try
            {
                shellPath = Path.Combine(EnvironmentAbstraction.GetEnvironmentVariable("ProgramW6432"), "Git", shell);
                if (File.Exists(shellPath))
                {
                    return(true);
                }

                shellPath = Path.Combine(EnvironmentAbstraction.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Git", shell);
                if (File.Exists(shellPath))
                {
                    return(true);
                }

                shellPath = Path.Combine(AppSettings.GitBinDir, shell);
                if (File.Exists(shellPath))
                {
                    return(true);
                }

                if (TryFindFullPath(shell, out shellPath))
                {
                    return(true);
                }
            }
            catch
            {
                // do nothing
            }

            shellPath = null;
            return(false);
        }
        public static string GetDefaultHomeDir()
        {
            // Use the HOME property from the user or machine, as captured at startup
            if (!string.IsNullOrEmpty(UserHomeDir))
            {
                return(UserHomeDir);
            }

            if (EnvUtils.RunningOnWindows())
            {
                // Use the Windows default home directory
                var homeDrive = Env.GetEnvironmentVariable("HOMEDRIVE");

                if (!string.IsNullOrEmpty(homeDrive))
                {
                    return(homeDrive + Env.GetEnvironmentVariable("HOMEPATH"));
                }

                return(Env.GetEnvironmentVariable("USERPROFILE"));
            }

            return(Env.GetFolderPath(Environment.SpecialFolder.Personal));
        }