refactor: rewrite lfs pointer detection and image loading

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-06-05 21:06:31 +08:00
parent eebadd67a1
commit a023a9259b
No known key found for this signature in database
14 changed files with 286 additions and 199 deletions

View file

@ -0,0 +1,8 @@
namespace SourceGit.Models
{
public enum ImageDecoder
{
None = 0,
Builtin,
}
}

View file

@ -1,8 +1,22 @@
namespace SourceGit.Models
using System.Text.RegularExpressions;
namespace SourceGit.Models
{
public class LFSObject
public partial class LFSObject
{
[GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]
private static partial Regex REG_FORMAT();
public string Oid { get; set; } = string.Empty;
public long Size { get; set; } = 0;
public static LFSObject Parse(string content)
{
var match = REG_FORMAT().Match(content);
if (match.Success)
return new() { Oid = match.Groups[1].Value, Size = long.Parse(match.Groups[2].Value) };
return null;
}
}
}

View file

@ -1,4 +1,6 @@
using Avalonia.Media.Imaging;
using System.Globalization;
using System.IO;
using Avalonia.Media.Imaging;
namespace SourceGit.Models
{
@ -9,10 +11,17 @@ namespace SourceGit.Models
public class RevisionImageFile
{
public Bitmap Image { get; set; } = null;
public long FileSize { get; set; } = 0;
public string ImageType { get; set; } = string.Empty;
public Bitmap Image { get; }
public long FileSize { get; }
public string ImageType { get; }
public string ImageSize => Image != null ? $"{Image.PixelSize.Width} x {Image.PixelSize.Height}" : "0 x 0";
public RevisionImageFile(string file, Bitmap img, long size)
{
Image = img;
FileSize = size;
ImageType = Path.GetExtension(file)!.Substring(1).ToUpper(CultureInfo.CurrentCulture);
}
}
public class RevisionTextFile