Add support for .kra and .cdr previews #1662

This commit is contained in:
ema
2025-07-05 04:58:24 +08:00
parent 63f516b504
commit 22e8838ce3
2 changed files with 69 additions and 0 deletions

View File

@@ -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;
}