From 8b1f28ac950603aef5e33dc35ddc15b10c2e4177 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 6 Jun 2024 10:36:17 +0800 Subject: [PATCH] enhance: show file size change in image diff --- src/Models/DiffResult.cs | 7 +++++-- src/ViewModels/DiffContext.cs | 18 ++++++++++++------ src/Views/DiffView.axaml | 14 +++++++++----- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index 3cc33f59..64ec2393 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -570,8 +570,11 @@ namespace SourceGit.Models public Bitmap Old { get; set; } = null; public Bitmap New { get; set; } = null; - public string OldSize => Old != null ? $"{Old.PixelSize.Width} x {Old.PixelSize.Height}" : "0 x 0"; - public string NewSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0"; + public long OldFileSize { get; set; } = 0; + public long NewFileSize { get; set; } = 0; + + public string OldImageSize => Old != null ? $"{Old.PixelSize.Width} x {Old.PixelSize.Height}" : "0 x 0"; + public string NewImageSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0"; } public class NoOrEOLChange diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 8a10feab..4ff80c23 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -157,14 +157,19 @@ namespace SourceGit.ViewModels var imgDiff = new Models.ImageDiff(); if (_option.Revisions.Count == 2) { - imgDiff.Old = BitmapFromRevisionFile(_repo, _option.Revisions[0], oldPath); - imgDiff.New = BitmapFromRevisionFile(_repo, _option.Revisions[1], oldPath); + (imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[0], oldPath); + (imgDiff.New, imgDiff.NewFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[1], oldPath); } else { var fullPath = Path.Combine(_repo, _option.Path); - imgDiff.Old = BitmapFromRevisionFile(_repo, "HEAD", oldPath); - imgDiff.New = File.Exists(fullPath) ? new Bitmap(fullPath) : null; + (imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, "HEAD", oldPath); + + if (File.Exists(fullPath)) + { + imgDiff.New = new Bitmap(fullPath); + imgDiff.NewFileSize = new FileInfo(fullPath).Length; + } } rs = imgDiff; } @@ -207,10 +212,11 @@ namespace SourceGit.ViewModels }); } - private Bitmap BitmapFromRevisionFile(string repo, string revision, string file) + private (Bitmap, long) BitmapFromRevisionFile(string repo, string revision, string file) { var stream = Commands.QueryFileContent.Run(repo, revision, file); - return stream.Length > 0 ? new Bitmap(stream) : null; + var size = stream.Length; + return size > 0 ? (new Bitmap(stream), size) : (null, size); } private static readonly HashSet IMG_EXTS = new HashSet() diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 96af72cb..17bba0f3 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -177,18 +177,22 @@ - - + + - + + + - + - + + +