public ToolOptionsForm(ToolParameters toolParameters)
        {
            InitializeComponent();

            if (toolParameters != null)
            {
                ToolParameters = toolParameters.Clone();
            }
            else
            {
                ToolParameters = new ToolParameters();
            }

            edName.Text = ToolParameters.Name;
            edPath.Text = ToolParameters.Path;
            edCommandLine.Text = ToolParameters.CommandLine;
            edIcon.Text = ToolParameters.CustomImagePath;
            switch (ToolParameters.ToolCategory)
            {
                case ToolCategory.Diff:
                    rbDiff.Checked = true;
                    break;
                case ToolCategory.Merge:
                    rbMerge.Checked = true;
                    break;
            }

            imgIcon.Image = ToolParameters.GetAssociatedIcon();
        }
        public void ExecuteTool(ToolParameters tp, string[] parameters, Action<ToolExecutionResult> callback)
        {
            _parameters = parameters;
            var commandLine = tp.CommandLine;

            if (string.IsNullOrWhiteSpace(commandLine))
            {
                commandLine = "%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16 %17 %18 %19 %20";
            }

            commandLine = commandLine
                .Replace("%20", GetParam(19))
                .Replace("%19", GetParam(18))
                .Replace("%18", GetParam(17))
                .Replace("%17", GetParam(16))
                .Replace("%16", GetParam(15))
                .Replace("%15", GetParam(14))
                .Replace("%14", GetParam(13))
                .Replace("%13", GetParam(12))
                .Replace("%12", GetParam(11))
                .Replace("%11", GetParam(10))
                .Replace("%10", GetParam(9))
                .Replace("%1", GetParam(0))
                .Replace("%2", GetParam(1))
                .Replace("%3", GetParam(2))
                .Replace("%4", GetParam(3))
                .Replace("%5", GetParam(4))
                .Replace("%6", GetParam(5))
                .Replace("%7", GetParam(6))
                .Replace("%8", GetParam(7))
                .Replace("%9", GetParam(8))
                ;

            new Thread(() =>
            {
                try
                {
                    var process = System.Diagnostics.Process.Start(tp.Path, commandLine);

                    callback(new ToolExecutionResult(this, tp, ToolExecutionStatus.Started));

                    process.WaitForExit();

                    callback(new ToolExecutionResult(this, tp, ToolExecutionStatus.FinishedSuccess));
                }
                catch (Exception ex)
                {
                    callback(new ToolExecutionResult(this, tp, ToolExecutionStatus.Error)
                    {
                        Exception = ex,
                    });
                }
            }).Start();
        }
        private void Execute(ToolParameters tp)
        {
            if (chRememberChoice.Checked)
            {
                var config = Config.Instance;
                config.LastChoiceToolIndex = lvTools.SelectedIndices[0];
                config.LastChoiceDuration = 100;
                config.LastChoiceValid = DateTime.Now.AddMinutes(config.LastChoiceDuration);
                config.Save();
            }

            ToolExecutionManager.ExecuteTool(tp, _parameters);

            Close();
        }
        public ToolNotificationForm(ToolParameters toolParameters, int seconds)
        {
            InitializeComponent();

            lbText.Text = lbText.Text.Replace("%ToolName%", toolParameters.Name);

            picIcon.Image = toolParameters.GetAssociatedIcon();

            //TODO: somehow identify screen on which diff merge tool opens
            var screen = Screen.PrimaryScreen;
            Top = screen.WorkingArea.Bottom - Height;
            Left = screen.WorkingArea.Right - Width;

            timer1.Enabled = true;
            timer1.Interval = 100;
            timer1.Tag = "wait for close";
            _timeWhenStartClose = DateTime.Now.AddSeconds(seconds);

            TopMost = true;
        }
 private void FillListItem(ListViewItem item, ToolParameters tp)
 {
     item.Tag = tp;
     item.Group = listView1.Groups[(int)tp.ToolCategory];
     item.Text = "  " + tp.Name;
     item.Name = tp.Name;
     item.SubItems.Clear();
     item.SubItems.Add(tp.Path);
     item.SubItems.Add(tp.CommandLine);
 }
 private Config()
 {
     Instance       = this;
     ToolParameters = new ToolParameters[] { };
 }
 public ToolExecutionResult(ToolExecution te, ToolParameters tp, ToolExecutionStatus status)
 {
     ToolExecution = te;
     ToolParameters = tp;
     Status = status;
 }
 public static void ExecuteTool(ToolParameters tp, string[] parameters)
 {
     var toolEx = new ToolExecution();
     _executionTools.Add(toolEx);
     toolEx.ExecuteTool(tp, parameters, (result) =>
     {
         lock (_tasksResultsQueue)
         {
             _tasksResultsQueue.Enqueue(result);
         }
     });
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            edName.BackColor = SystemColors.Window;
            if (string.IsNullOrWhiteSpace(edName.Text))
            {
                edName.BackColor = Color.LightPink;
                return;
            }

            edPath.BackColor = SystemColors.Window;
            if (string.IsNullOrWhiteSpace(edPath.Text))
            {
                edPath.BackColor = Color.LightPink;
                return;
            }

            ToolParameters = new ToolParameters
            {
                Name = edName.Text,
                Path = edPath.Text,
                CustomImagePath = edIcon.Text,
                CommandLine = edCommandLine.Text,
                ToolCategory = rbDiff.Checked ? ToolCategory.Diff : ToolCategory.Merge,
            };

            DialogResult = System.Windows.Forms.DialogResult.OK;

            Close();
        }
 private Config()
 {
     Instance = this;
     ToolParameters = new ToolParameters[] { };
 }