예제 #1
0
        private string SubstituteArguments(string arguments, VisualGitDiffToolArgs diffArgs, DiffToolMode toolMode)
        {
            if (diffArgs == null)
                throw new ArgumentNullException("diffArgs");

            if (_re == null)
            {
                const string ifBody = "\\?(?<tick>['\"])(?<ifbody>([^'\"]|('')|(\"\"))*)\\k<tick>";
                const string elseBody = "(:(?<tick2>['\"])(?<elsebody>([^'\"]|('')|(\"\"))*)\\k<tick2>)?";

                _re = new Regex(@"(\%(?<pc>[a-zA-Z0-9_]+)(\%|\b))|(\$\((?<vs>[a-zA-Z0-9_-]*)(\((?<arg>[a-zA-Z0-9_-]*)\))?\))" +
                "|(\\$\\((?<if>[a-zA-Z0-9_-]+)" + ifBody + elseBody + "\\))");
            }

            return _re.Replace(arguments, new Replacer(this, diffArgs, toolMode).Replace).TrimEnd();
        }
예제 #2
0
            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
        private bool Substitute(string reference, VisualGitDiffToolArgs args, DiffToolMode toolMode, out string program, out string arguments)
        {
            if (string.IsNullOrEmpty(reference))
                throw new ArgumentNullException("reference");
            else if (args == null)
                throw new ArgumentNullException("args");

            // Ok: We received a string with a program and arguments and windows
            // wants a program and arguments separated. Let's find the program before substituting

            reference = reference.TrimStart();

            program = null;
            arguments = null;

            string app;
            if (!string.IsNullOrEmpty(app = VisualGitDiffTool.GetToolNameFromTemplate(reference)))
            {
                // We have a predefined template. Just use it
                VisualGitDiffTool tool = GetAppItem(app, toolMode);

                if (tool == null)
                    return false;
                else if (!tool.IsAvailable)
                    return false;

                program = SubstituteArguments(tool.Program, args, toolMode);
                arguments = SubstituteArguments(tool.Arguments, args, toolMode);

                return !String.IsNullOrEmpty(program) && File.Exists(program);
            }
            else if (!TrySplitPath(reference, out program, out arguments))
                return false;

            program = SubstituteArguments(program, args, toolMode);
            arguments = SubstituteArguments(arguments, args, toolMode);

            return true;
        }