static LaunchResult InnerLaunch(TryResolveTool tryResolveTool, string tempFile, string targetFile) { if (ShouldExitLaunch(tryResolveTool, targetFile, out var tool, out var result)) { DiffEngineTray.AddMove(tempFile, targetFile, null, null, false, null); return(result.Value); } tool.CommandAndArguments(tempFile, targetFile, out var arguments, out var command); if (ProcessCleanup.TryGetProcessInfo(command, out var processCommand)) { if (tool.AutoRefresh) { DiffEngineTray.AddMove(tempFile, targetFile, tool.ExePath, arguments, tool.IsMdi !, processCommand.Process); return(LaunchResult.AlreadyRunningAndSupportsRefresh); } KillIfMdi(tool, command); } if (MaxInstance.Reached()) { DiffEngineTray.AddMove(tempFile, targetFile, tool.ExePath, arguments, tool.IsMdi !, null); return(LaunchResult.TooManyRunningDiffTools); } var processId = LaunchProcess(tool, arguments); DiffEngineTray.AddMove(tempFile, targetFile, tool.ExePath, arguments, !tool.IsMdi, processId); return(LaunchResult.StartedNewInstance); }
static async Task <LaunchResult> InnerLaunch(ResolvedTool tool, string tempFile, string targetFile) { var arguments = tool.Arguments(tempFile, targetFile); var command = tool.BuildCommand(tempFile, targetFile); if (ProcessCleanup.TryGetProcessInfo(command, out var processCommand)) { if (tool.AutoRefresh) { await DiffEngineTray.AddMove(tempFile, targetFile, tool.ExePath, arguments, tool.IsMdi !, processCommand.Process); return(LaunchResult.AlreadyRunningAndSupportsRefresh); } if (!tool.IsMdi) { ProcessCleanup.Kill(command); } } var instanceCount = Interlocked.Increment(ref launchedInstances); if (instanceCount > maxInstancesToLaunch) { await DiffEngineTray.AddMove(tempFile, targetFile, tool.ExePath, arguments, tool.IsMdi !, null); return(LaunchResult.TooManyRunningDiffTools); } try { var startInfo = new ProcessStartInfo(tool.ExePath, arguments) { UseShellExecute = true }; using var process = Process.Start(startInfo); if (process == null) { var message = $@"Failed to launch diff tool. {tool.ExePath} {arguments}"; throw new Exception(message); } await DiffEngineTray.AddMove(tempFile, targetFile, tool.ExePath, arguments, !tool.IsMdi, process.Id); return(LaunchResult.StartedNewInstance); } catch (Exception exception) { var message = $@"Failed to launch diff tool. {tool.ExePath} {arguments}"; throw new Exception(message, exception); } }