private string FindSvnBinary()
        {
            string svn = null;

            // Try the PATH environment variable
            if (svn == null)
            {
                string pathEnv = Environment.GetEnvironmentVariable("PATH");
                foreach (string dir_ in pathEnv.Split(Path.PathSeparator))
                {
                    string dir = dir_;
                    if (dir.StartsWith("\"") && dir.EndsWith("\""))
                    {
                        // Strip quotes (no Path.PathSeparator supported in quoted directories though)
                        dir = dir.Substring(1, dir.Length - 2);
                    }
                    svn = Path.Combine(dir, svnExeName);
                    if (File.Exists(svn))
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{dir}"" via %PATH%");
                        break;
                    }
                }
                if (!File.Exists(svn))
                {
                    svn = null;
                }
            }

            var registry = new WindowsRegistry();

            // If TortoiseSVN has been installed with command-line binaries
            if (svn == null && isWindows)
            {
                string keyPath = @"Software\TortoiseSVN";
                string loc     = registry.GetStringValue("HKLM", keyPath, "Directory");
                if (loc != null)
                {
                    svn = Path.Combine(loc, Path.Combine(@"bin", svnExeName));
                    if (!File.Exists(svn))
                    {
                        svn = null;
                    }
                    else
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{loc}"" via HKLM\\{keyPath}\\Directory");
                    }
                }
            }

            // Read registry uninstaller key
            if (svn == null && isWindows)
            {
                string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CollabNet Subversion Client";
                string loc     = registry.GetStringValue("HKLM", keyPath, "UninstallString");
                if (loc != null)
                {
                    svn = Path.Combine(Path.GetDirectoryName(loc), svnExeName);
                    if (!File.Exists(svn))
                    {
                        svn = null;
                    }
                    else
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{loc}"" via HKLM\\{keyPath}\\UninstallString");
                    }
                }
            }
            if (svn == null && isWindows)
            {
                string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F5980BF8-ED95-4742-A89F-CDAC202D53CF}_is1";
                string loc     = registry.GetStringValue("HKLM", keyPath, "InstallLocation");
                if (loc != null)
                {
                    svn = Path.Combine(loc, svnExeName);
                    if (!File.Exists(svn))
                    {
                        svn = null;
                    }
                    else
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{loc}"" via HKLM\\{keyPath}\\InstallLocation");
                    }
                }
            }

            // Try 64-bit registry keys
            if (svn == null && Is64Bit && isWindows)
            {
                string keyPath = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\CollabNet Subversion Client";
                string loc     = registry.GetStringValue("HKLM", keyPath, "UninstallString");
                if (loc != null)
                {
                    svn = Path.Combine(Path.GetDirectoryName(loc), svnExeName);
                    if (!File.Exists(svn))
                    {
                        svn = null;
                    }
                    else
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{loc}"" via HKLM\\{keyPath}\\UninstallString");
                    }
                }
            }
            if (svn == null && Is64Bit && isWindows)
            {
                string keyPath = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{F5980BF8-ED95-4742-A89F-CDAC202D53CF}_is1";
                string loc     = registry.GetStringValue("HKLM", keyPath, "InstallLocation");
                if (loc != null)
                {
                    svn = Path.Combine(loc, svnExeName);
                    if (!File.Exists(svn))
                    {
                        svn = null;
                    }
                    else
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{loc}"" via HKLM\\{keyPath}\\InstallLocation");
                    }
                }
            }

            // Search program files directory
            if (svn == null && isWindows)
            {
                foreach (string dir in Directory.GetDirectories(ProgramFiles(), "*subversion*"))
                {
                    svn = Path.Combine(dir, svnExeName);
                    if (File.Exists(svn))
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{dir}"" via %ProgramFiles%\\*subversion*");
                        break;
                    }
                    svn = Path.Combine(dir, "bin", svnExeName);
                    if (File.Exists(svn))
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{dir}"" via %ProgramFiles%\\*subversion*\\bin");
                        break;
                    }
                }
                if (!File.Exists(svn))
                {
                    svn = null;
                }
            }

            // Try 32-bit program files directory
            if (svn == null && Is64Bit && isWindows)
            {
                foreach (string dir in Directory.GetDirectories(ProgramFilesX86(), "*subversion*"))
                {
                    svn = Path.Combine(dir, svnExeName);
                    if (File.Exists(svn))
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{dir}"" via %ProgramFiles(x86)%\\*subversion*");
                        break;
                    }
                    svn = Path.Combine(dir, "bin", svnExeName);
                    if (File.Exists(svn))
                    {
                        Logger?.Success($@"Found {svnExeName} in ""{dir}"" via %ProgramFiles(x86)%\\*subversion*\\bin");
                        break;
                    }
                }
                if (!File.Exists(svn))
                {
                    svn = null;
                }
            }
            return(svn);
        }
示例#2
0
        private string FindGitBinary()
        {
            string git = null;

            // Try the PATH environment variable
            if (git == null)
            {
                string pathEnv = Environment.GetEnvironmentVariable("PATH");
                foreach (string _dir in pathEnv.Split(Path.PathSeparator))
                {
                    string dir = _dir;
                    if (dir.StartsWith("\"") && dir.EndsWith("\""))
                    {
                        // Strip quotes (no Path.PathSeparator supported in quoted directories though)
                        dir = dir.Substring(1, dir.Length - 2);
                    }
                    string testPath = Path.Combine(dir, gitExeName);
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{dir}"" via %PATH%");
                        break;
                    }
                }
            }

            var registry = new WindowsRegistry();

            // Read registry uninstaller key
            if (git == null && isWindows)
            {
                string keyPath = @"Software\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1";
                string loc     = registry.GetStringValue("HKLM", keyPath, "InstallLocation");
                if (loc != null)
                {
                    string testPath = Path.Combine(loc, Path.Combine("bin", gitExeName));
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{loc}"" via HKLM\\{keyPath}\\InstallLocation");
                    }
                }
            }

            // Try 64-bit registry key
            if (git == null && Is64Bit && isWindows)
            {
                string keyPath = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1";
                string loc     = registry.GetStringValue("HKLM", keyPath, "InstallLocation");
                if (loc != null)
                {
                    string testPath = Path.Combine(loc, Path.Combine("bin", gitExeName));
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{loc}"" via HKLM\\{keyPath}\\InstallLocation");
                    }
                }
            }

            // Try user profile key (since Git for Windows 2.x)
            if (git == null && isWindows)
            {
                string keyPath = @"Software\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1";
                string loc     = registry.GetStringValue("HKCU", keyPath, "InstallLocation");
                if (loc != null)
                {
                    string testPath = Path.Combine(loc, Path.Combine("bin", gitExeName));
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{loc}"" via HKCU\\{keyPath}\\InstallLocation");
                    }
                }
            }

            // Search program files directory
            if (git == null && isWindows)
            {
                foreach (string dir in Directory.GetDirectories(ProgramFiles(), "git*"))
                {
                    string testPath = Path.Combine(dir, gitExeName);
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{dir}"" via %ProgramFiles%\\git*");
                        break;
                    }
                    testPath = Path.Combine(dir, "bin", gitExeName);
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{dir}"" via %ProgramFiles%\\git*\\bin");
                        break;
                    }
                }
            }

            // Try 32-bit program files directory
            if (git == null && Is64Bit && isWindows)
            {
                foreach (string dir in Directory.GetDirectories(ProgramFilesX86(), "git*"))
                {
                    string testPath = Path.Combine(dir, gitExeName);
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{dir}"" via %ProgramFiles(x86)%\\git*");
                        break;
                    }
                    testPath = Path.Combine(dir, "bin", gitExeName);
                    if (File.Exists(testPath))
                    {
                        git = testPath;
                        Logger?.Success($@"Found {gitExeName} in ""{dir}"" via %ProgramFiles(x86)%\\git*\\bin");
                        break;
                    }
                }
            }

            // Try Atlassian SourceTree local directory
            if (git == null && isWindows)
            {
                string dir      = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\AppData\Local\Atlassian\SourceTree\git_local\bin");
                string testPath = Path.Combine(dir, gitExeName);
                if (File.Exists(testPath))
                {
                    git = testPath;
                    Logger?.Success($@"Found {gitExeName} in ""{dir}""");
                }
            }

            // Try Tower local directory
            if (git == null && isWindows)
            {
                string dir      = Environment.ExpandEnvironmentVariables(ProgramFilesX86() + @"\fournova\Tower\vendor\Git\bin");
                string testPath = Path.Combine(dir, gitExeName);
                if (File.Exists(testPath))
                {
                    git = testPath;
                    Logger?.Success($@"Found {gitExeName} in ""{dir}""");
                }
            }

            // Try SmartGit local directory
            if (git == null && isWindows)
            {
                string dir      = Environment.ExpandEnvironmentVariables(ProgramFilesX86() + @"\SmartGit\git\bin");
                string testPath = Path.Combine(dir, gitExeName);
                if (File.Exists(testPath))
                {
                    git = testPath;
                    Logger?.Success($@"Found {gitExeName} in ""{dir}""");
                }
            }
            return(git);
        }