Пример #1
0
        private static void GetFileLines(string fileNameA, string fileNameB,
                                         out IList <string> a, out IList <string> b,
                                         out int leadingCharactersToIgnore,
                                         TextBinaryDiffArgs args,
                                         IDiffProgress progress)
        {
            a = null;
            b = null;
            leadingCharactersToIgnore = 0;
            CompareType compareType = args.CompareType;

            if (compareType == CompareType.Binary ||
                (args.IsAuto && (DiffUtility.IsBinaryFile(fileNameA) || DiffUtility.IsBinaryFile(fileNameB))))
            {
                using (FileStream fileA = File.OpenRead(fileNameA))
                    using (FileStream fileB = File.OpenRead(fileNameB))
                    {
                        BinaryDiff diff = new BinaryDiff
                        {
                            FootprintLength = args.BinaryFootprintLength
                        };

                        AddCopyCollection addCopy = diff.Execute(fileA, fileB);

                        BinaryDiffLines lines = new BinaryDiffLines(fileA, addCopy, args.BinaryFootprintLength);
                        a = lines.BaseLines;
                        b = lines.VersionLines;
                        leadingCharactersToIgnore = BinaryDiffLines.PrefixLength;
                    }
            }

            if (compareType == CompareType.Xml || (args.IsAuto && (a == null || b == null)))
            {
                a = TryGetXmlLines(DiffUtility.GetXmlTextLines, fileNameA, fileNameA, !args.IsAuto, args, progress);

                // If A failed to parse with Auto, then there's no reason to try B.
                if (a != null)
                {
                    b = TryGetXmlLines(DiffUtility.GetXmlTextLines, fileNameB, fileNameB, !args.IsAuto, args, progress);
                }

                // If we get here and the compare type was XML, then both
                // inputs parsed correctly, and both lists should be non-null.
                // If we get here and the compare type was Auto, then one
                // or both lists may be null, so we'll fallthrough to the text
                // handling logic.
            }

            if (a == null || b == null)
            {
                a = DiffUtility.GetFileTextLines(fileNameA, progress);
                b = DiffUtility.GetFileTextLines(fileNameB, progress);
            }
        }