예제 #1
0
            public static DiffRange Parse(IStringReader reader)
            {
                var range = new DiffRange();

                reader.Skip("@@");
                reader.SkipWhitespace();
                reader.Skip('-');
                range.LeftFrom = reader.ReadInt();
                if (reader.Skip(','))
                {
                    range.LeftTo = range.LeftFrom + reader.ReadInt();
                }
                else
                {
                    range.LeftTo = range.LeftFrom;
                }
                reader.SkipWhitespace();
                reader.Skip('+');
                range.RightFrom = reader.ReadInt();
                if (reader.Skip(','))
                {
                    range.RightTo = range.RightFrom + reader.ReadInt();
                }
                else
                {
                    range.RightTo = range.RightFrom;
                }
                reader.SkipWhitespace();
                reader.Skip("@@");
                return(range);
            }
예제 #2
0
            private void SetupNode()
            {
                if (Left == null)
                {
                    Text = String.Format(Properties.Resources.DiffPacketsControl_NodeAdded, FormatNode(Right));

                    Mode = DiffRange.DiffType.Added;
                }
                else if (Right == null)
                {
                    Text = String.Format(Properties.Resources.DiffPacketsControl_NodeDeleted, FormatNode(Left));
                    Mode = DiffRange.DiffType.Deleted;
                }
                else
                {
                    Text = String.Format(Properties.Resources.DiffPacketsControl_NodeModified, FormatNode(Left), FormatNode(Right));
                    Mode = DiffRange.DiffType.Modified;

                    if (!IsBasic)
                    {
                        // This is just so we can handle expanding nodes on demand
                        Nodes.Add(new TreeNode("dummy"));
                    }
                }

                BackColor = DiffRange.GetColor(Mode);
            }
예제 #3
0
 private void DoWork()
 {
     try
     {
         _bytediffs = DiffRange.BuildDifferences(_left, _right, EqualityComparer <byte> .Default).ToArray();
         _linediffs = DiffRange.BuildDifferences(_leftlines, _rightlines, EqualityComparer <string> .Default).ToArray();
         Invoke(new Action(CompleteDifferences));
     }
     catch (ThreadAbortException)
     {
         throw;
     }
     catch
     {
     }
 }
예제 #4
0
        private void CompleteDifferences()
        {
            // This is probably redundant but might as well be sure
            if ((_bytediffs.Length == 0) && (_linediffs.Length == 0))
            {
                MessageBox.Show(this, Properties.Resources.BinaryFrameDiffControl_NoDifferenceFound,
                                Properties.Resources.BinaryFrameDiffControl_NoDifferenceFoundCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                toolStripLabelInfo.Text = String.Format(Properties.Resources.BinaryFrameDiffControl_LabelFormat, 0, 0);
            }
            else
            {
                foreach (DiffRange range in _bytediffs)
                {
                    if (range.LeftLength > 0)
                    {
                        hexEditorControlLeft.AddAnnotation(range.LeftStartPos, range.LeftStartPos + range.LeftLength - 1, Color.Black, DiffRange.GetColor(range.LeftType));
                    }

                    if (range.RightLength > 0)
                    {
                        hexEditorControlRight.AddAnnotation(range.RightStartPos, range.RightStartPos + range.RightLength - 1, Color.Black, DiffRange.GetColor(range.RightType));
                    }
                }

                foreach (DiffRange range in _linediffs)
                {
                    if (range.LeftLength > 0)
                    {
                        for (int i = 0; i < range.LeftLength; ++i)
                        {
                            ColorLine(richTextBoxLeft, (int)range.LeftStartPos + i, DiffRange.GetColor(range.LeftType));
                        }
                    }

                    if (range.RightLength > 0)
                    {
                        for (int i = 0; i < range.RightLength; ++i)
                        {
                            ColorLine(richTextBoxRight, (int)range.RightStartPos + i, DiffRange.GetColor(range.RightType));
                        }
                    }
                }

                SetDifference(0);
            }
        }
예제 #5
0
 public static DiffRange Parse(IStringReader reader)
 {
     var range = new DiffRange();
     reader.Skip("@@");
     reader.SkipWhitespace();
     reader.Skip('-');
     range.LeftFrom = reader.ReadInt();
     if (reader.Skip(','))
     {
         range.LeftTo = range.LeftFrom + reader.ReadInt();
     }
     else
     {
         range.LeftTo = range.LeftFrom;
     }
     reader.SkipWhitespace();
     reader.Skip('+');
     range.RightFrom = reader.ReadInt();
     if (reader.Skip(','))
     {
         range.RightTo = range.RightFrom + reader.ReadInt();
     }
     else
     {
         range.RightTo = range.RightFrom;
     }
     reader.SkipWhitespace();
     reader.Skip("@@");
     return range;
 }
예제 #6
0
        internal static FileDiff ParseDiffChunk(IStringReader reader, ref ChangeSetDetail merge)
        {
            var diff = ParseDiffHeader(reader, merge);

            if (diff == null)
            {
                return(null);
            }

            // Current diff range
            DiffRange currentRange = null;
            int?      leftCounter  = null;
            int?      rightCounter = null;

            // Parse the file diff
            while (!reader.Done)
            {
                int?   currentLeft  = null;
                int?   currentRight = null;
                string line         = reader.ReadLine();

                if (line.Equals(@"\ No newline at end of file", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                bool       isDiffRange = line.StartsWith("@@", StringComparison.Ordinal);
                ChangeType?changeType  = null;

                if (line.StartsWith("+", StringComparison.Ordinal))
                {
                    changeType   = ChangeType.Added;
                    currentRight = ++rightCounter;
                    currentLeft  = null;
                }
                else if (line.StartsWith("-", StringComparison.Ordinal))
                {
                    changeType   = ChangeType.Deleted;
                    currentLeft  = ++leftCounter;
                    currentRight = null;
                }
                else if (IsCommitHeader(line))
                {
                    reader.PutBack(line.Length);
                    merge = ParseCommitAndSummary(reader);
                }
                else
                {
                    if (!isDiffRange)
                    {
                        currentLeft  = ++leftCounter;
                        currentRight = ++rightCounter;
                    }
                    changeType = ChangeType.None;
                }

                if (changeType != null)
                {
                    var lineDiff = new LineDiff(changeType.Value, line);
                    if (!isDiffRange)
                    {
                        lineDiff.LeftLine  = currentLeft;
                        lineDiff.RightLine = currentRight;
                    }

                    diff.Lines.Add(lineDiff);
                }

                if (isDiffRange)
                {
                    // Parse the new diff range
                    currentRange = DiffRange.Parse(line.AsReader());
                    leftCounter  = currentRange.LeftFrom - 1;
                    rightCounter = currentRange.RightFrom - 1;
                }
            }

            return(diff);
        }
예제 #7
0
 private double DifficultyRange(double difficulty, DiffRange range) =>
 DifficultyRange(difficulty, range.lower, range.middle, range.upper);
예제 #8
0
        private void DiffNodesAndAdd(TreeNodeCollection col, DataNode[] left, DataNode[] right)
        {
            treeViewOutput.SuspendLayout();
            col.Clear();

            if ((left.Length == 0) && (right.Length == 0))
            {
                MessageBox.Show(this, Properties.Resources.DiffPacketsControl_NoDifferencesFound, Properties.Resources.DiffPacketsControl_NoDifferencesFoundCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (left.Length == 0)
            {
                foreach (DataNode packet in right)
                {
                    AddNodes(col, null, packet);
                }
            }
            else if (right.Length == 0)
            {
                foreach (DataNode packet in left)
                {
                    AddNodes(col, packet, null);
                }
            }
            else
            {
                DiffRange[] ranges = DiffRange.BuildDifferences(left, right, new DataNodeEqualityComparer()).ToArray();

                if (ranges.Length > 0)
                {
                    foreach (DiffRange range in ranges)
                    {
                        if (range.LeftLength == range.RightLength)
                        {
                            for (int i = 0; i < range.LeftLength; ++i)
                            {
                                AddNodes(col, left[i + range.LeftStartPos], right[i + range.RightStartPos]);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < range.LeftLength; ++i)
                            {
                                AddNodes(col, left[i + range.LeftStartPos], null);
                            }

                            for (int i = 0; i < range.RightLength; ++i)
                            {
                                AddNodes(col, null, right[i + range.RightStartPos]);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show(this, Properties.Resources.DiffPacketsControl_NoDifferencesFound, Properties.Resources.DiffPacketsControl_NoDifferencesFoundCaption,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            treeViewOutput.ResumeLayout();
        }