diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/PdnProvider.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/PdnProvider.cs deleted file mode 100644 index d4f78ef..0000000 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/PdnProvider.cs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright © 2017-2025 QL-Win Contributors -// -// This file is part of QuickLook program. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using QuickLook.Common.Helpers; -using QuickLook.Common.Plugin; -using System; -using System.IO; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media.Animation; -using System.Windows.Media.Imaging; -using System.Xml.Linq; - -namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers; - -internal class PdnProvider : AnimationProvider -{ - public PdnProvider(Uri path, MetaProvider meta, ContextObject contextObject) : base(path, meta, contextObject) - { - Animator = new Int32AnimationUsingKeyFrames(); - Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0, - KeyTime.FromTimeSpan(TimeSpan.Zero))); - } - - public override Task GetThumbnail(Size renderSize) - { - // Skip thumbnail - return new Task(() => null); - } - - public override Task GetRenderedFrame(int index) - { - return new Task(() => - { - try - { - using TextReader reader = new StreamReader(Path.LocalPath, Encoding.UTF8); - string line = reader.ReadLine(); - - if (!line.StartsWith("PDN")) - return null; - - int indexOfStart = line.IndexOf("<"); - int indexOfEnd = line.LastIndexOf(">"); - - if (indexOfStart < 0 || indexOfEnd < 0) - return null; - - string xml = line.Substring(indexOfStart, indexOfEnd - indexOfStart + 1); - - // - // - // - // - // - XDocument doc = XDocument.Parse(xml); - var pngBase64 = doc.Root - ?.Element("custom") - ?.Element("thumb") - ?.Attribute("png") - ?.Value; - - if (pngBase64 != null) - { - byte[] imageBytes = Convert.FromBase64String(pngBase64); - MemoryStream ms = new(imageBytes); - BitmapImage bitmap = new(); - bitmap.BeginInit(); - bitmap.CacheOption = BitmapCacheOption.OnLoad; - bitmap.StreamSource = ms; - bitmap.EndInit(); - bitmap.Freeze(); - return bitmap; - } - - return null; - } - catch (Exception e) - { - ProcessHelper.WriteLog(e.ToString()); - return null; - } - }); - } - - public override void Dispose() - { - } -} diff --git a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs index 259a8d1..a5c77bf 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Handler.cs @@ -21,6 +21,7 @@ using PureSharpCompress.Readers; using QuickLook.Common.Helpers; using QuickLook.Common.Plugin; using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Windows; @@ -30,8 +31,18 @@ namespace QuickLook.Plugin.ThumbnailViewer; internal static class Handler { + // List> + public static List> Providers = []; + public static void Prepare(string path, ContextObject context) { + // Temporary codes + if (path.EndsWith(".pdn", StringComparison.OrdinalIgnoreCase)) + { + new PdnProvider().Prepare(path, context); + return; + } + try { using Stream imageData = ViewImage(path); @@ -47,6 +58,12 @@ internal static class Handler public static Stream ViewImage(string path) { + // Temporary codes + if (path.EndsWith(".pdn", StringComparison.OrdinalIgnoreCase)) + { + return new PdnProvider().ViewImage(path); + } + try { using ZipArchive archive = ZipArchive.Open(path, new()); diff --git a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs index 4016078..47a9c1f 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Plugin.cs @@ -34,6 +34,7 @@ public class Plugin : IViewer ".cdr", // CorelDraw ".fig", // Figma ".kra", // Krita + ".pdn", // Paint.NET ".pip", ".pix", // Pixso ".sketch", // Sketch ".xd", // AdobeXD @@ -46,6 +47,8 @@ public class Plugin : IViewer public void Init() { + Handler.Providers.Add(new KeyValuePair( + [".pdn"], typeof(PdnProvider))); } public bool CanHandle(string path) diff --git a/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Providors/PdnProvider.cs b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Providors/PdnProvider.cs new file mode 100644 index 0000000..a86d1e4 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.ThumbnailViewer/Providors/PdnProvider.cs @@ -0,0 +1,93 @@ +// Copyright © 2017-2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using QuickLook.Common.Helpers; +using QuickLook.Common.Plugin; +using QuickLook.Plugin.ImageViewer; +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Windows; +using System.Windows.Media.Imaging; +using System.Xml.Linq; + +namespace QuickLook.Plugin.ThumbnailViewer; + +internal class PdnProvider +{ + public void Prepare(string path, ContextObject context) + { + try + { + using Stream imageData = ViewImage(path); + BitmapImage bitmap = imageData.ReadAsBitmapImage(); + context.SetPreferredSizeFit(new Size(bitmap.PixelWidth, bitmap.PixelHeight), 0.8d); + } + catch (Exception ex) + { + Debug.WriteLine($"Error reading thumbnail from {path}: {ex.Message}"); + context.PreferredSize = new Size { Width = 800, Height = 600 }; + } + } + + public Stream ViewImage(string path) + { + try + { + using TextReader reader = new StreamReader(path, Encoding.UTF8); + string line = reader.ReadLine(); + + if (!line.StartsWith("PDN")) + return null; + + int indexOfStart = line.IndexOf("<"); + int indexOfEnd = line.LastIndexOf(">"); + + if (indexOfStart < 0 || indexOfEnd < 0) + return null; + + string xml = line.Substring(indexOfStart, indexOfEnd - indexOfStart + 1); + + // + // + // + // + // + XDocument doc = XDocument.Parse(xml); + var pngBase64 = doc.Root + ?.Element("custom") + ?.Element("thumb") + ?.Attribute("png") + ?.Value; + + if (pngBase64 != null) + { + byte[] imageBytes = Convert.FromBase64String(pngBase64); + MemoryStream ms = new(imageBytes); + return ms; + } + + return null; + } + catch (Exception e) + { + ProcessHelper.WriteLog(e.ToString()); + return null; + } + } +}