Ejemplo n.º 1
0
 static void KillIfMdi(ResolvedTool tool, string command)
 {
     if (!tool.IsMdi)
     {
         ProcessCleanup.Kill(command);
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Find and kill a diff tool process.
        /// </summary>
        public static void Kill(string tempFile, string targetFile)
        {
            if (Disabled)
            {
                return;
            }

            var extension = Extensions.GetExtension(tempFile);

            if (!DiffTools.TryFind(extension, out var diffTool))
            {
                Logging.Write($"Extension not found. {extension}");
                return;
            }

            var command = diffTool.BuildCommand(tempFile, targetFile);

            if (diffTool.IsMdi)
            {
                Logging.Write($"DiffTool is Mdi so not killing. diffTool: {diffTool.ExePath}");
                return;
            }

            ProcessCleanup.Kill(command);
        }
Ejemplo n.º 4
0
        static void Launch(ResolvedDiffTool tool, string path1, string path2)
        {
            Guard.AgainstNull(tool, nameof(tool));
            var command           = tool.BuildCommand(path1, path2);
            var isDiffToolRunning = ProcessCleanup.IsRunning(command);

            if (isDiffToolRunning)
            {
                if (tool.SupportsAutoRefresh)
                {
                    return;
                }

                if (!tool.IsMdi)
                {
                    ProcessCleanup.Kill(command);
                }
            }

            var arguments = tool.BuildArguments(path1, path2);

            try
            {
                Process.Start(tool.ExePath, arguments);
            }
            catch (Exception exception)
            {
                var message = $@"Failed to launch diff tool.
{tool.ExePath} {arguments}";
                throw new Exception(message, exception);
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Find and kill a diff tool process.
        /// </summary>
        public static void Kill(string path1, string path2)
        {
            Guard.AgainstNullOrEmpty(path1, nameof(path1));
            Guard.AgainstNullOrEmpty(path2, nameof(path2));
            var extension = Extensions.GetExtension(path1);

            if (!DiffTools.TryFind(extension, out var diffTool))
            {
                return;
            }

            var command = diffTool.BuildCommand(path1, path2);

            if (diffTool.IsMdi)
            {
                return;
            }

            ProcessCleanup.Kill(command);
        }