private static bool integrateInDiffTool(string applicationFullPath) { IIntegratedDiffTool diffTool = createDiffTool(); DiffToolIntegration integration = new DiffToolIntegration(); try { integration.Integrate(diffTool, applicationFullPath); } catch (DiffToolNotInstalledException) { string message = String.Format( "{0} is not installed. It must be installed at least for the current user. Application cannot start", diffTool.GetToolName()); MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (DiffToolIntegrationException ex) { string message = String.Format("{0} integration failed. Application cannot start. See logs for details", diffTool.GetToolName()); MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ExceptionHandlers.Handle(String.Format("Cannot integrate \"{0}\"", diffTool.GetToolName()), ex); return(false); } finally { GitTools.TraceGitConfiguration(); } return(true); }
private string getGitCommand(IIntegratedDiffTool diffTool, string toolPath) { var path = System.IO.Path.Combine(toolPath, diffTool.GetToolCommand()); path = path.Replace(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar); return("\"\\\"" + path + "\\\"" + diffTool.GetToolCommandArguments() + "\""); }
/// <summary> /// Throws GitOperationException if integration failed /// Throws DiffToolIntegrationException if diff tool is not installed /// </summary> private void registerInGit(IIntegratedDiffTool diffTool, string name) { if (!isInstalled(diffTool)) { throw new DiffToolIntegrationException("Diff tool not installed", null); } _globalGitConfiguration.SetGlobalDiffTool(name, getGitCommand(diffTool)); }
private string getGitCommand(IIntegratedDiffTool diffTool) { string toolPath = getToolPath(diffTool); if (toolPath == null) { throw new DiffToolIntegrationException(String.Format("Cannot find installation location in registry")); } var path = System.IO.Path.Combine(toolPath, diffTool.GetToolCommand()); path = path.Replace(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar); return("\"\\\"" + path + "\\\"" + diffTool.GetToolCommandArguments() + "\""); }
/// <summary> /// Throws DiffToolIntegrationException if integration failed /// </summary> private void registerInTool(IIntegratedDiffTool diffTool, string self) { try { diffTool.PatchToolConfig(self + " diff"); } catch (DiffToolIntegrationException) { throw; } catch (Exception ex) // whatever XML exception { throw new DiffToolIntegrationException("Unknown error", ex); } }
/// <summary> /// Throws DiffToolIntegrationException if integration failed /// </summary> private void registerInTool(IIntegratedDiffTool diffTool) { if (!isInstalled(diffTool)) { throw new DiffToolIntegrationException("Diff tool not installed", null); } try { diffTool.PatchToolConfig(Process.GetCurrentProcess().MainModule.FileName + " diff"); } catch (DiffToolIntegrationException) { throw; } catch (Exception ex) // whatever XML exception { throw new DiffToolIntegrationException("Unknown error", ex); } }
/// <summary> /// Throws DiffToolNotInstalledException if diff tool is not installed /// Throws DiffToolIntegrationException if integration failed /// </summary> public void Integrate(IIntegratedDiffTool diffTool, string self) { AppFinder.AppInfo appInfo = AppFinder.GetApplicationInfo(diffTool.GetToolRegistryNames()); if (appInfo == null || !isInstalled(appInfo.InstallPath)) { throw new DiffToolNotInstalledException("Diff tool not installed"); } string toolpath = appInfo.InstallPath; Trace.TraceInformation(String.Format("Diff Tool installed at: {0}", toolpath)); registerInGit(diffTool, toolpath); try { registerInTool(diffTool, self); } catch (DiffToolIntegrationException) { Trace.TraceError(String.Format("Cannot register the application in \"{0}\"", Constants.GitDiffToolName)); try { string key = String.Format("difftool.{0}.cmd", Constants.GitDiffToolName); GitTools.SetConfigKeyValue(GitTools.ConfigScope.Global, key, null, String.Empty); } catch (ExternalProcessSystemException) { Trace.TraceError(String.Format("Cannot remove \"{0}\" from git config", Constants.GitDiffToolName)); } catch (ExternalProcessFailureException) { Trace.TraceError(String.Format("Cannot remove \"{0}\" from git config", Constants.GitDiffToolName)); } throw; } }
/// <summary> /// Throws GitOperationException if integration failed /// Throws DiffToolIntegrationException if diff tool is not installed /// </summary> public void Integrate(IIntegratedDiffTool diffTool) { registerInGit(diffTool, GitDiffToolName); try { registerInTool(diffTool); } catch (DiffToolIntegrationException) { Trace.TraceError(String.Format("Cannot register the application in \"{0}\"", GitDiffToolName)); try { _globalGitConfiguration.RemoveGlobalDiffTool(GitDiffToolName); } catch (GitOperationException) { Trace.TraceError(String.Format("Cannot remove \"{0}\" from git config", GitDiffToolName)); } throw; } }
/// <summary> /// Throws ExternalProcessFailureException/ExternalProcessSystemException if registration failed /// </summary> private void registerInGit(IIntegratedDiffTool diffTool, string toolpath) { string value = getGitCommand(diffTool, toolpath); GitTools.SetConfigKeyValue(GitTools.ConfigScope.Global, Constants.GitDiffToolConfigKey, value, String.Empty); }
public bool isInstalled(IIntegratedDiffTool diffTool) { return(getToolPath(diffTool) != null); }
private string getToolPath(IIntegratedDiffTool diffTool) { return(getInstallPath(diffTool.GetToolRegistryNames())); }