Skip to content

Commit 1f37743

Browse files
committed
Added copy, cleaned up some things, matched up binary counts vs ascii lines after compare.
1 parent 0aef5cb commit 1f37743

7 files changed

Lines changed: 119 additions & 41 deletions

File tree

Chizl.FileCompare.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<Company>Chizl.com</Company>
1515
<Copyright>© 2025 chizl.com</Copyright>
1616
<PackageTags>file-compare;library;in-console;on-desktop;netstandard;core;framework</PackageTags>
17-
<FileVersion>5.09.21.1261</FileVersion>
18-
<Version>5.09.21.0</Version>
17+
<FileVersion>5.09.22.943</FileVersion>
18+
<Version>5.09.22.0</Version>
1919
<AssemblyVersion>5.09.0.0</AssemblyVersion>
2020
</PropertyGroup>
2121

Chizl.FileComparer/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// Revision
3131
//
3232
[assembly: AssemblyVersion("5.9.0.0")]
33-
[assembly: AssemblyFileVersion("5.9.21.1261")]
34-
[assembly: AssemblyInformationalVersion("5.9.21.0")]
33+
[assembly: AssemblyFileVersion("5.9.22.943")]
34+
[assembly: AssemblyInformationalVersion("5.9.22.0")]
3535
[assembly: AssemblyKeyFileAttribute("")]
3636
[assembly: AssemblyDelaySignAttribute(false)]

Chizl.FileComparer/StartForm.Designer.cs

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Chizl.FileComparer/StartForm.cs

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Concurrent;
1313
using System.Text.RegularExpressions;
1414
using System.Runtime.InteropServices;
15+
using System.Runtime.CompilerServices;
1516

1617
namespace Chizl.FileComparer
1718
{
@@ -46,8 +47,11 @@ public partial class StartForm : Form
4647
private static RichTextBox _srcRtb;
4748
private static RichTextBox _trgRtb;
4849

49-
private string _oldFile = ".\\testfiles\\test_old.txt";
50-
private string _newFile = ".\\testfiles\\test_new.txt";
50+
//private string _oldFile = ".\\testfiles\\test_old.txt";
51+
//private string _newFile = ".\\testfiles\\test_new.txt";
52+
private string _oldFile = ".\\testfiles\\binary.old";
53+
private string _newFile = ".\\testfiles\\binary.new";
54+
//.\testfiles\binary.old
5155
//private string _oldFile = ".\\testfiles\\large_org.log";
5256
//private string _newFile = ".\\testfiles\\large_new.log";
5357

@@ -425,7 +429,7 @@ private void LoadBinaryHexView(string filePath, RichTextBox rtb)
425429

426430
private void SetStatus(string msg, Color bgColor)
427431
{
428-
StatusText.Text = $"HexView auto zooms text based on window. Use Control-MouseWheel to Zoom In/Out. Click HexView again to exit HexView.";
432+
StatusText.Text = msg;
429433
if (!bgColor.IsEmpty)
430434
{
431435
// off
@@ -584,39 +588,38 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
584588
{
585589
ClearRichText();
586590

591+
var scrollLineMarker = 0;
587592
var prevLineSize = 30;
588593
var useBinary = forceBinary || _lastFileComparison.IsBinary;
589-
590594
if (_lastFileComparison.HasException)
591595
{
592-
SetStatus($"Error: {_lastFileComparison.Exception.Message}", Color.FromArgb(255, 192, 192));
596+
SetStatus($"Exception: {_lastFileComparison.Exception.Message}", Color.FromArgb(255, 192, 192));
593597
return;
594598
}
595599
else
596600
{
597-
SetStatus($"Line by Line Status: Added( {_lastFileComparison.Diffs.Added} ), Deleted( {_lastFileComparison.Diffs.Deleted} ), Modified( {_lastFileComparison.Diffs.Modified} ), No Change({_lastFileComparison.Diffs.Identical} )", Color.Yellow);
601+
var groups = _lastFileComparison.IsBinary ? "Bytes" : "Lines";
602+
var statusType = _lastFileComparison.IsBinary ? "Binary by Byte" : $"ASCII Line by Line{(forceBinary? " in Hex": "")}";
603+
SetStatus($"{statusType}: Added( {_lastFileComparison.Diffs.Added} ), Deleted( {_lastFileComparison.Diffs.Deleted} ), Modified( {_lastFileComparison.Diffs.Modified} ), No Change( {_lastFileComparison.Diffs.Identical} ), Total {groups}( {_lastFileComparison.LineComparison.Length} )", Color.FromArgb(192, 192, 0));
598604
}
599605

600-
ResetTimer.Enabled = true;
601-
var lines = _lastFileComparison.LineComparison.OrderBy(o => o.LineNumber).ToArray();
602-
// For Ascii, maxPerc isn't always 100% if form is zoomed. This is not taken in account and will stay the same.
603-
var maxPerc = lines.Length;
604-
var scrollLineMarker = 0;
605-
StatusText.Tag = $"Lines: {lines.Length} / {lines.Count()}";
606-
607-
var oldRtfBuilder = new RtfBuilder(new Color[4] { LINE_COLOR, ADD_COLOR, DELETE_COLOR, MODIFIED_COLOR });
606+
var oldRtfBuilder = new RtfBuilder(new Color[4] { LINE_COLOR, ADD_COLOR, DELETE_COLOR, MODIFIED_COLOR }, true);
608607
var oldTextBuilder = new RtfBuilder(new Color[4] { LINE_COLOR, ADD_COLOR, DELETE_COLOR, MODIFIED_COLOR }, false);
609-
var newRtfBuilder = new RtfBuilder(new Color[4] { LINE_COLOR, ADD_COLOR, DELETE_COLOR, MODIFIED_COLOR });
608+
var newRtfBuilder = new RtfBuilder(new Color[4] { LINE_COLOR, ADD_COLOR, DELETE_COLOR, MODIFIED_COLOR }, true);
610609
var newTextBuilder = new RtfBuilder(new Color[4] { LINE_COLOR, ADD_COLOR, DELETE_COLOR, MODIFIED_COLOR }, false);
611610

611+
//ResetTimer.Enabled = true;
612+
var lines = _lastFileComparison.LineComparison.OrderBy(o => o.LineNumber).ToArray();
613+
var maxPerc = lines.Length;
614+
612615
if (!useBinary)
613616
{
614617
var stringFiller = $"{new string(' ', prevLineSize)}\n";
615618
foreach (var cmpr in lines)
616619
{
617620
scrollLineMarker++;
618-
619-
var lineNumber = $"{cmpr.LineNumber:0000}: ";
621+
// using (000000000:) to match up with (X8h:) - 10 bytes wide.
622+
var lineNumber = $"{cmpr.LineNumber:000000000}:";
620623
var lineString = $"{cmpr.LineDiffStr}";
621624

622625
// removing any extra that might be residing..
@@ -634,11 +637,11 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
634637
lineString += "\n";
635638
}
636639

637-
oldRtfBuilder.Append($"{lineNumber}", LINE_COLOR);
640+
oldRtfBuilder.Append(lineNumber, LINE_COLOR);
638641
oldRtfBuilder.Append($" ");
639642
if (sideBySide)
640643
{
641-
newRtfBuilder.Append($"{lineNumber}", LINE_COLOR);
644+
newRtfBuilder.Append(lineNumber, LINE_COLOR);
642645
newRtfBuilder.Append($" ");
643646
}
644647

@@ -726,14 +729,14 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
726729
{
727730
if (hexSize.Equals(0))
728731
{
729-
var lineNumber = $"{hexCountLineMarker:X8}";
732+
var lineNumber = $"{hexCountLineMarker:X8}h:\n";
730733
hexCountLineMarker += 16;
731734

732-
oldRtfBuilder.Append($" {lineNumber}h ", LINE_COLOR);
735+
oldRtfBuilder.Append(lineNumber, LINE_COLOR);
733736
oldRtfBuilder.Append(" ");
734737
if (sideBySide)
735738
{
736-
newRtfBuilder.Append($" {lineNumber}h ", LINE_COLOR);
739+
newRtfBuilder.Append(lineNumber, LINE_COLOR);
737740
newRtfBuilder.Append(" ");
738741
}
739742
}
@@ -816,8 +819,8 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
816819

817820
if (hexSize >= 16)
818821
{
819-
oldRtfBuilder.Append(" "); //clears any color that might exist.
820-
newRtfBuilder.Append(" "); //clears any color that might exist.
822+
oldRtfBuilder.Append(" ; "); //clears any color that might exist.
823+
newRtfBuilder.Append(" ; "); //clears any color that might exist.
821824
oldRtfBuilder.AppendLineRtf(oldTextBuilder.GetDocument(true)); //oldPlainText
822825
newRtfBuilder.AppendLineRtf(newTextBuilder.GetDocument(true)); //newPlainText
823826

@@ -836,8 +839,8 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
836839
oldRtfBuilder.Append(padString);
837840
newRtfBuilder.Append(padString);
838841

839-
oldRtfBuilder.Append(" "); //clears any color that might exist.
840-
newRtfBuilder.Append(" "); //clears any color that might exist.
842+
oldRtfBuilder.Append(" ; "); //clears any color that might exist.
843+
newRtfBuilder.Append(" ; "); //clears any color that might exist.
841844
oldRtfBuilder.AppendLineRtf(oldTextBuilder.GetDocument(true)); //oldPlainText
842845
newRtfBuilder.AppendLineRtf(newTextBuilder.GetDocument(true)); //newPlainText
843846
}
@@ -939,5 +942,41 @@ private void ZoomCheck_KeyUp(object sender, KeyEventArgs e)
939942
_trgRtb.ZoomFactor = _srcRtb.ZoomFactor;
940943
}
941944
private void Content_Leave(object sender, EventArgs e) => ZoomCheck_KeyUp(sender, new KeyEventArgs(Keys.ControlKey));
945+
946+
private string _selectedText = string.Empty;
947+
//private string _selectedTextRTF = string.Empty;
948+
private void Content_MouseUp(object sender, MouseEventArgs e)
949+
{
950+
if (e.Button == MouseButtons.Right)
951+
{
952+
var rtb = (RichTextBox)sender;
953+
if (rtb.SelectedText.Length > 0)
954+
{
955+
_selectedText = rtb.SelectedText;
956+
//_selectedTextRTF = rtb.SelectedRtf;
957+
RichTextContextMenus.Show(GetMenuLocation(rtb, e));
958+
}
959+
}
960+
}
961+
962+
private Point GetMenuLocation(RichTextBox rtb, MouseEventArgs e)
963+
{
964+
var titleHeight = SplitContainer1.Top;
965+
var curWidth = (int)Cursor.Size.Width / 4;
966+
var addLeft = SplitContainer1.Margin.Left + curWidth;
967+
var spltPanLeft = SplitContainer1.Panel1.Left + SplitContainer1.Panel1.Padding.Left + addLeft;
968+
969+
if (rtb.Name.StartsWith("New"))
970+
spltPanLeft = SplitContainer1.Panel2.Left + addLeft;
971+
972+
var l = this.Left + spltPanLeft + rtb.Left;
973+
var t = this.Top + rtb.Top + SplitContainer1.Top;
974+
return new Point(l + e.X, t + e.Y + RichTextContextMenus.Height);
975+
}
976+
private void RichTextBoxCopy_Click(object sender, EventArgs e)
977+
{
978+
Clipboard.Clear();
979+
Clipboard.SetText(_selectedText);
980+
}
942981
}
943982
}

Chizl.FileComparer/StartForm.resx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema id="root" xmlns="" xmlns:xsd="http:// www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63-
<xsd:import namespace="http:// www.w3.org/XML/1998/namespace" />
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
6666
<xsd:choice maxOccurs="unbounded">
@@ -222,6 +222,9 @@
222222
<metadata name="NewAsciiButton.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
223223
<value>True</value>
224224
</metadata>
225+
<metadata name="RichTextContextMenus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
226+
<value>453, 17</value>
227+
</metadata>
225228
<metadata name="StartFormMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
226229
<value>179, 17</value>
227230
</metadata>

models/ComparisonResults.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,26 @@ internal ComparisonResults(List<CompareDiff> compareDiffs, FileLevel sourceFile,
4444
this.TargetFile = targetFile;
4545
this.IsBinary = sourceFile.IsBinary || targetFile.IsBinary;
4646
this.LineComparison = compareDiffs.ToArray();
47-
this.Diffs = new DiffCounts(
48-
compareDiffs.Count(w => w.DiffType == DiffType.Added),
49-
compareDiffs.Count(w => w.DiffType == DiffType.Deleted),
50-
compareDiffs.Count(w => w.DiffType == DiffType.Modified),
51-
compareDiffs.Count(w => w.DiffType == DiffType.None)
52-
);
47+
48+
//binary needs to be done by byte, not line
49+
if (this.IsBinary)
50+
{
51+
this.Diffs = new DiffCounts(
52+
compareDiffs.Where(w => w.DiffType == DiffType.Added).Select(s => s.ByteByByteDiff.Length).Sum(),
53+
compareDiffs.Where(w => w.DiffType == DiffType.Deleted).Select(s => s.ByteByByteDiff.Length).Sum(),
54+
compareDiffs.Where(w => w.DiffType == DiffType.Modified).Select(s => s.ByteByByteDiff.Length).Sum(),
55+
compareDiffs.Where(w => w.DiffType == DiffType.None).Select(s => s.ByteByByteDiff.Length).Sum()
56+
);
57+
}
58+
else
59+
{
60+
this.Diffs = new DiffCounts(
61+
compareDiffs.Count(w => w.DiffType == DiffType.Added),
62+
compareDiffs.Count(w => w.DiffType == DiffType.Deleted),
63+
compareDiffs.Count(w => w.DiffType == DiffType.Modified),
64+
compareDiffs.Count(w => w.DiffType == DiffType.None)
65+
);
66+
}
5367
}
5468

5569
/// <summary>

rtf/RtfBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private void RtfSetupPage()
273273
_contentTextRtf.Append($"\\red{colorIndex.R}\\green{colorIndex.G}\\blue{colorIndex.B};");
274274
}
275275

276-
_contentTextRtf.Append($"}} {Environment.NewLine}");
276+
_contentTextRtf.Append($"}}{Environment.NewLine}");
277277
}
278278
}
279279
private bool ValidFontSize(double fontPtSize, out string msg)

0 commit comments

Comments
 (0)