diff --git a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs index f712004..3b904af 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs @@ -20,7 +20,9 @@ using PureSharpCompress.Common; using PureSharpCompress.Readers; using QuickLook.Common.Plugin; using System; +using System.Diagnostics; using System.IO; +using System.Linq; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Resources; @@ -73,6 +75,34 @@ internal static class Handler context.PreferredSize = new Size { Width = 1200, Height = 900 }; } } + else if (path.EndsWith(".kra", 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 = 800, Height = 600 }; + } + } + else if (path.EndsWith(".cdr", 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 = 800, Height = 600 }; + } + } } public static Stream ViewImage(string path) @@ -142,6 +172,40 @@ internal static class Handler } } } + else if (path.EndsWith(".kra", StringComparison.OrdinalIgnoreCase)) + { + using ZipArchive archive = ZipArchive.Open(path, new()); + using IReader reader = archive.ExtractAllEntries(); + + while (reader.MoveToNextEntry()) + { + Debug.WriteLine(reader.Entry.Key); + + if (reader.Entry.Key!.Contains("mergedimage")) + { + MemoryStream ms = new(); + using EntryStream stream = reader.OpenEntryStream(); + stream.CopyTo(ms); + return ms; + } + } + } + else if (path.EndsWith(".cdr", StringComparison.OrdinalIgnoreCase)) + { + using ZipArchive archive = ZipArchive.Open(path, new()); + using IReader reader = archive.ExtractAllEntries(); + + while (reader.MoveToNextEntry()) + { + if (reader.Entry.Key!.Equals("previews/thumbnail.png", StringComparison.OrdinalIgnoreCase)) + { + MemoryStream ms = new(); + using EntryStream stream = reader.OpenEntryStream(); + stream.CopyTo(ms); + return ms; + } + } + } return null; } diff --git a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs index 7d2ae58..4599504 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs @@ -30,7 +30,9 @@ public class Plugin : IViewer { private static readonly HashSet WellKnownImageExtensions = new( [ + ".cdr", // CorelDraw ".fig", // Figma + ".kra", // Krita ".xd", // AdobeXD ".xmind", // XMind ]); @@ -65,6 +67,9 @@ public class Plugin : IViewer _ = Task.Run(() => { using Stream imageData = Handler.ViewImage(path); + + if (imageData is null) return; + BitmapImage bitmap = imageData.ReadAsBitmapImage(); if (_ip is null) return;