示例#1
0
        /// <summary>
        /// Compares two file with a byte-by-byte sequence strategy.
        /// Either based on a:
        /// 1) byte size comparison and byte-by-byte comparison or
        /// 2) byte-by-byte comparison ignoring different line feed styles on text files.
        /// </summary>
        /// <param name="ifo1"></param>
        /// <param name="ifo2"></param>
        /// <param name="diffMode"></param>
        /// <returns>false if both files are equal and true if they differ</returns>
        public bool AreBinaryFilesDifferent(IFileInfo ifo1, IFileInfo ifo2, DiffDirFileMode diffMode)
        {
            // Should we ignore different linefeeds on text files and is this type of matching applicable here?
            if (diffMode == DiffDirFileMode.ByteLength_AllBytes_IgnoreLf)
            {
                bool IsIfo1Text = ifo1.Is == FileType.Text | ifo1.Is == FileType.Xml;
                bool IsIfo2Text = ifo2.Is == FileType.Text | ifo2.Is == FileType.Xml;

                if (IsIfo1Text && IsIfo2Text)
                {
                    return(AreTextFiles_IgnoringLF_Different(ifo1, ifo2));
                }
            }
            else if (diffMode == DiffDirFileMode.ByteLength_AllBytes_IgnoreLf_WSP)
            {
                bool IsIfo1Text = ifo1.Is == FileType.Text | ifo1.Is == FileType.Xml;
                bool IsIfo2Text = ifo2.Is == FileType.Text | ifo2.Is == FileType.Xml;

                if (IsIfo1Text && IsIfo2Text)
                {
                    return(AreTextFiles_IgnoringLF_WSP_Different(ifo1, ifo2));
                }
            }

            // Before we open the files, compare the sizes.  If they are different,
            // then the files are certainly different.
            if (ifo1.Length != ifo2.Length)
            {
                return(true);
            }

            var info1 = new FileInfo(ifo1.FullName);
            var info2 = new FileInfo(ifo2.FullName);

            using (FileStream stream1 = info1.OpenRead())
                using (FileStream stream2 = info2.OpenRead())
                {
                    // The previous length check should ensure these are equal.
                    Debug.Assert(stream1.Length == stream2.Length, "The streams' lengths must be the same.");

                    // They have the same lengths, so we have to check byte-by-byte.  As soon as we find a difference, we can quit.
                    int byte1, byte2;
                    do
                    {
                        byte1 = stream1.ReadByte();
                        byte2 = stream2.ReadByte();

                        Debug.Assert(byte1 <= 255, "Byte1 size is larger than 8 bit.");
                        Debug.Assert(byte2 <= 255, "Byte2 size is larger than 8 bit.");

                        if (byte1 != byte2)
                        {
                            return(true);                     // The files are different
                        }
                    }while (byte1 >= 0 && byte2 >= 0);

                    return(false);            // The files are byte-by-byte equal.
                }
        }
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="name"></param>
 /// <param name="description"></param>
 /// <param name="modeKey"></param>
 public DiffFileModeItemViewModel(string name,
                                  string description,
                                  DiffDirFileMode modeKey)
     : this()
 {
     this.Name        = name;
     this.Description = description;
     this.ModeKey     = modeKey;
 }
示例#3
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="args">Determines the options that control the way in which
 /// the diff is computed (eg.: whether sub-directories should be considered or not).</param>
 public DirectoryDiff(DirDiffArgs args)
 {
     _ShowOnlyInA               = args.ShowOnlyInA;
     _ShowOnlyInB               = args.ShowOnlyInB;
     _ShowDifferent             = args.ShowDifferent;
     _ShowSame                  = args.ShowSame;
     _Recursive                 = args.Recursive;
     _IgnoreDirectoryComparison = args.IgnoreDirectoryComparison;
     _Filter              = args.FileFilter;
     _DiffMode            = args.CompareDirFileMode;
     _LastUpDatePrecision = args.LastUpDateFilePrecision;
 }
示例#4
0
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="recursive"></param>
        /// <param name="rootPathA"></param>
        /// <param name="rootPathB"></param>
        /// <param name="diffMode">
        /// Determines the modus operandi per <see cref="DiffDirFileMode"/> that is used to
        /// compare two files and pronounce them as different or equal.
        /// </param>
        public DirectoryDiffRoot(string rootPathA, string rootPathB,
                                 bool recursive,
                                 DirectoryDiffFileFilter filter,
                                 DiffDirFileMode diffMode)
            : this()
        {
            this.RootPathA = rootPathA;
            this.RootPathB = rootPathB;

            _Recursive = recursive;
            _Filter    = filter;
            _DiffMode  = diffMode;
        }
示例#5
0
 /// <summary>
 /// Compares two file on a byte-by-byte sequence strategy.
 /// Either based on a:
 /// 1) byte size comparison and byte-by-byte comparison or
 /// 2) byte-by-byte comparison ignoring different line feed styles on text files.
 /// </summary>
 /// <param name="info1"></param>
 /// <param name="info2"></param>
 /// <param name="diffMode"></param>
 /// <returns>false if both files are equal and true if they differ</returns>
 public bool AreBinaryFilesDifferent(string fileName1, string fileName2, DiffDirFileMode diffMode)
 {
     return(AreBinaryFilesDifferent(new FileInfoImpl(fileName1), new FileInfoImpl(fileName2), diffMode));
 }
示例#6
0
        private void CompareFilesCommand_Executed(string leftDir,
                                                  string rightDir,
                                                  DiffDirFileMode dirFileMode)
        {
            if (_cancelTokenSource.IsCancellationRequested == true)
            {
                return;
            }

            DirDiffArgs args = _Args;

            _Args.CompareDirFileMode = dirFileMode;

            // Construct deffault options if there are no others
            if (_Args == null)
            {
                args = new DirDiffArgs(leftDir, rightDir);
            }
            else
            {
                _Args.LeftDir  = leftDir;
                _Args.RightDir = rightDir;
            }

            var diff = new DirectoryDiff(args);

            try
            {
                _DiffProgress.ResetProgressValues(_cancelTokenSource.Token);

                Task.Factory.StartNew <IDiffProgress>(
                    (p) => diff.Execute(args.LeftDir, args.RightDir, _DiffProgress, _DataSource)
                    , TaskCreationOptions.LongRunning, _cancelTokenSource.Token)
                .ContinueWith((r) =>
                {
                    bool onError       = false;
                    bool taskCancelled = false;

                    if (_cancelTokenSource != null)
                    {
                        // Re-create cancellation token if this task was cancelled
                        // to support cancelable tasks in the future
                        if (_cancelTokenSource.IsCancellationRequested)
                        {
                            taskCancelled = true;
                            _cancelTokenSource.Dispose();
                            _cancelTokenSource = new CancellationTokenSource();
                        }
                    }

                    if (taskCancelled == false)
                    {
                        if (r.Result == null)
                        {
                            onError = true;
                        }
                        else
                        {
                            if (r.Result.ResultData == null)
                            {
                                onError = true;
                            }
                        }
                    }

                    if (onError == false && taskCancelled == false)
                    {
                        var diffResults = r.Result.ResultData as IDirectoryDiffRoot;
                        _DirDiffDoc.ShowDifferences(args, diffResults);
                    }
                    else
                    {
                        // Display Error
                    }
                });
            }
            catch
            {
                // Handle task based error and display error
            }
        }