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); } }
private static void GetFileLines(FileCompInfo fileA, FileCompInfo fileB, 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; // Nothing to compare if both files do not exist if (fileA.FileExists == false && fileB.FileExists == false) { a = new List <string>(); b = new List <string>(); return; } if (compareType == CompareType.Binary || (args.IsAuto && fileA.Is == FileType.Binary || fileB.Is == FileType.Binary)) { GetBinaryFileLines(fileA, fileB, args, progress, out a, out b, out leadingCharactersToIgnore); return; } if (compareType == CompareType.Xml || (args.IsAuto && (a == null || b == null))) { a = fileA.TryGetXmlLines(DiffUtility.GetXmlTextLines, !args.IsAuto, args, progress); // If A failed to parse with Auto, then there's no reason to try B. if (fileA.Is == FileType.Xml) { b = fileB.TryGetXmlLines(DiffUtility.GetXmlTextLines, !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 (fileA.Is != FileType.Xml || fileB.Is != FileType.Xml) { if (fileA.FileExists) { a = DiffUtility.GetFileTextLines(fileA.FileNamePath, progress); } else { a = new List <string>(); } if (fileB.FileExists) { b = DiffUtility.GetFileTextLines(fileB.FileNamePath, progress); } else { b = new List <string>(); } } }