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);
            }
        }
Exemple #2
0
        public void AddChange(String verFileName)
        {
            WriteLine("Adding changes from {0}", verFileName);
            Stream      baseStream = new MemoryStream(_baseData);
            Stream      stream     = File.OpenRead(verFileName);
            BinaryDiff  diff       = new BinaryDiff();
            AddCopyList change     = diff.Execute(baseStream, stream);

            _changes.Add(change);
            stream.Close();
            baseStream.Close();
            WriteLine("Changes added successfully.  AddCopy byte length: {0}", change.TotalByteLength);
        }
Exemple #3
0
        private void GetFileLines(string strA, string strB, out Collection <string> A, out Collection <string> B)
        {
            if (this.isBinary)
            {
                using (FileStream AF = File.OpenRead(strA))
                    using (FileStream BF = File.OpenRead(strB))
                    {
                        BinaryDiff BDiff = new BinaryDiff();
                        BDiff.FootprintLength = 8;
                        AddCopyList List = BDiff.Execute(AF, BF);

                        BinaryDiffLines Lines = new BinaryDiffLines(AF, List, 8);
                        A = Lines.BaseLines;
                        B = Lines.VerLines;
                    }
            }
            else
            {
                A = Functions.GetFileTextLines(strA);
                B = Functions.GetFileTextLines(strB);
            }
        }
Exemple #4
0
        private static void GetBinaryFileLines(FileCompInfo fileA, FileCompInfo fileB,
                                               TextBinaryDiffArgs args,
                                               IDiffProgress progress,
                                               out IList <string> a, out IList <string> b,
                                               out int leadingCharactersToIgnore)
        {
            a = new List <string>();
            b = new List <string>();
            leadingCharactersToIgnore = BinaryDiffLines.PrefixLength;

            // Neither left nor right file exist or cannot be accessed
            if (fileA.FileExists == false && fileB.FileExists == false)
            {
                return;
            }

            Stream fileStreamA = null, fileStreamB = null;

            try
            {
                // Open the file or an internal empty stream to compare against
                if (fileA.FileExists)
                {
                    fileStreamA = File.OpenRead(fileA.FileNamePath);
                }
                else
                {
                    fileStreamA = Assembly.GetExecutingAssembly().GetManifestResourceStream("AehnlichLib.Binaries.Resources.NonExistingFile.bin");
                }

                // Open the file or an internal empty stream to compare against
                if (fileB.FileExists)
                {
                    fileStreamB = File.OpenRead(fileB.FileNamePath);
                }
                else
                {
                    fileStreamB = Assembly.GetExecutingAssembly().GetManifestResourceStream("AehnlichLib.Binaries.Resources.NonExistingFile.bin");
                }

                BinaryDiff diff = new BinaryDiff
                {
                    FootprintLength = args.BinaryFootprintLength
                };

                AddCopyCollection addCopy = diff.Execute(fileStreamA, fileStreamB, progress);

                BinaryDiffLines lines = new BinaryDiffLines(fileStreamA, addCopy, args.BinaryFootprintLength);
                a = lines.BaseLines;
                b = lines.VersionLines;
                leadingCharactersToIgnore = BinaryDiffLines.PrefixLength;
            }
            finally
            {
                if (fileStreamA != null)
                {
                    fileStreamA.Dispose();
                }

                if (fileStreamB != null)
                {
                    fileStreamB.Dispose();
                }
            }

            return;
        }
Exemple #5
0
        /// <summary>
        /// Get Binary file contents rendered as text lines with line number marker at beginning of each line.
        /// </summary>
        /// <param name="fileA"></param>
        /// <param name="fileB"></param>
        /// <param name="args"></param>
        /// <param name="progress"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="leadingCharactersToIgnore">Leading number of characters to ignore for diff in each line.
        /// This space is used in binary diff to display 8 digit line number and 4 digit space.</param>
        private DiffBinaryTextResults GetBinaryFileLines(IFileInfo fileA, IFileInfo fileB
                                                         , TextBinaryDiffArgs args
                                                         , IDiffProgress progress)
        {
            // Neither left nor right file exist or cannot be accessed
            if (fileA.FileExists == false && fileB.FileExists == false)
            {
                return(new DiffBinaryTextResults(CompareType.Binary, new FileContentInfo(), new FileContentInfo()));
            }

            Stream         fileStreamA = null, fileStreamB = null;
            IList <string> a = null, b = null;

            try
            {
                // Open the file or an internal empty stream to compare against
                if (fileA.FileExists)
                {
                    fileStreamA = File.OpenRead(fileA.FullName);
                }
                else
                {
                    fileStreamA = Assembly.GetExecutingAssembly().GetManifestResourceStream("AehnlichLib.Binaries.Resources.NonExistingFile.bin");
                }

                // Open the file or an internal empty stream to compare against
                if (fileB.FileExists)
                {
                    fileStreamB = File.OpenRead(fileB.FullName);
                }
                else
                {
                    fileStreamB = Assembly.GetExecutingAssembly().GetManifestResourceStream("AehnlichLib.Binaries.Resources.NonExistingFile.bin");
                }

                BinaryDiff diff = new BinaryDiff
                {
                    FootprintLength = args.BinaryFootprintLength
                };

                AddCopyCollection addCopy = diff.Execute(fileStreamA, fileStreamB, progress);

                BinaryDiffLines lines = new BinaryDiffLines(fileStreamA, addCopy, args.BinaryFootprintLength);
                a = lines.BaseLines;
                b = lines.VersionLines;
            }
            finally
            {
                if (fileStreamA != null)
                {
                    fileStreamA.Dispose();
                }

                if (fileStreamB != null)
                {
                    fileStreamB.Dispose();
                }
            }

            FileContentInfo af = new FileContentInfo(true, a);
            FileContentInfo bf = new FileContentInfo(true, b);

            return(new DiffBinaryTextResults(CompareType.Binary, af, bf, BinaryDiffLines.PrefixLength));
        }