mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-16 16:05:00 +00:00
refactor: rewrite lfs pointer detection and image loading
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
eebadd67a1
commit
a023a9259b
14 changed files with 286 additions and 199 deletions
8
src/Models/ImageDecoder.cs
Normal file
8
src/Models/ImageDecoder.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace SourceGit.Models
|
||||
{
|
||||
public enum ImageDecoder
|
||||
{
|
||||
None = 0,
|
||||
Builtin,
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue