Add Sketch file support to ThumbnailViewer plugin

This commit is contained in:
ema
2025-07-08 22:57:02 +08:00
parent a6c077fbbb
commit f9586be3ec
2 changed files with 31 additions and 0 deletions

View File

@@ -74,6 +74,20 @@ internal static class Handler
context.PreferredSize = new Size { Width = 100, Height = 100 };
}
}
else if (path.EndsWith(".sketch", StringComparison.OrdinalIgnoreCase))
{
try
{
using Stream imageData = ViewImage(path);
BitmapImage bitmap = imageData.ReadAsBitmapImage();
context.SetPreferredSizeFit(new Size(bitmap.PixelWidth, bitmap.PixelHeight), 0.8d);
}
catch (Exception e)
{
_ = e;
context.PreferredSize = new Size { Width = 100, Height = 100 };
}
}
else if (path.EndsWith(".xmind", StringComparison.OrdinalIgnoreCase))
{
try
@@ -195,6 +209,22 @@ internal static class Handler
StreamResourceInfo info = Application.GetResourceStream(new Uri("pack://application:,,,/QuickLook.Plugin.ThumbnailViewer;component/Resources/broken.png"));
return info?.Stream;
}
else if (path.EndsWith(".sketch", StringComparison.OrdinalIgnoreCase))
{
using ZipArchive archive = ZipArchive.Open(path, new());
using IReader reader = archive.ExtractAllEntries();
while (reader.MoveToNextEntry())
{
if (reader.Entry.Key!.EndsWith("previews/preview.png", StringComparison.OrdinalIgnoreCase))
{
MemoryStream ms = new();
using EntryStream stream = reader.OpenEntryStream();
stream.CopyTo(ms);
return ms;
}
}
}
else if (path.EndsWith(".xmind", StringComparison.OrdinalIgnoreCase))
{
using ZipArchive archive = ZipArchive.Open(path, new());

View File

@@ -34,6 +34,7 @@ public class Plugin : IViewer
".fig", // Figma
".kra", // Krita
".pip", ".pix", // Pixso
".sketch", // Sketch
".xd", // AdobeXD
".xmind", // XMind
]);