コード例 #1
0
ファイル: ApplyPatch.cs プロジェクト: pvginkel/VisualGit
        public override void OnExecute(CommandEventArgs e)
        {
            IVisualGitSolutionSettings ss = e.GetService<IVisualGitSolutionSettings>();
            IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>();

            VisualGitPatchArgs args = new VisualGitPatchArgs();
            args.ApplyTo = ss.ProjectRoot;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "Patch files( *.patch)|*.patch|Diff files (*.diff)|*.diff|" +
                    "Text files (*.txt)|*.txt|All files (*.*)|*";

                if (ofd.ShowDialog(e.Context.DialogOwner) != DialogResult.OK)
                    return;

                args.PatchFile = ofd.FileName;
            }

            diff.RunPatch(args);
        }
コード例 #2
0
ファイル: VisualGitDiff.cs プロジェクト: pvginkel/VisualGit
            public Replacer(VisualGitDiff context, VisualGitDiffToolArgs args, DiffToolMode toolMode)
            {
                if (context == null)
                    throw new ArgumentNullException("context");
                else if (args == null)
                    throw new ArgumentNullException("args");

                _context = context;
                _toolArgs = args;
                _diffArgs = args as VisualGitDiffArgs;
                _mergeArgs = args as VisualGitMergeArgs;
                _patchArgs = args as VisualGitPatchArgs;
                _toolMode = toolMode;
            }
コード例 #3
0
ファイル: VisualGitDiff.cs プロジェクト: pvginkel/VisualGit
        public bool RunPatch(VisualGitPatchArgs args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            else if (!args.Validate())
                throw new ArgumentException("Arguments not filled correctly", "args");

            string diffApp = GetPatchPath(args.Mode);

            if (string.IsNullOrEmpty(diffApp))
            {
                new VisualGitMessageBox(Context).Show("Please specify a merge tool in Tools->Options->SourceControl->Git", "VisualGit - No visual merge tool is available");

                return false;
            }

            string program;
            string arguments;
            if (!Substitute(diffApp, args, DiffToolMode.Patch, out program, out arguments))
            {
                new VisualGitMessageBox(Context).Show(string.Format("Can't find patch program '{0}'", program));
                return false;
            }

            Process p = new Process();
            p.StartInfo = new ProcessStartInfo(program, arguments);

            string applyTo = args.ApplyTo;

            DiffToolMonitor monitor = null;
            if (applyTo != null)
            {
                monitor = new DiffToolMonitor(Context, applyTo, true);

                p.EnableRaisingEvents = true;
                monitor.Register(p);
            }

            bool started = false;
            try
            {
                return started = p.Start();
            }
            finally
            {
                if (!started)
                {
                    if (monitor != null)
                        monitor.Dispose();
                }
            }
        }