PhotoThumbnail/ApkPreviewHandler/ApkPreviewHandler.cs

58 lines
1.4 KiB
C#

using ShellExtensions;
using ShellExtensions.PreviewHandlers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ApkPreviewHandler
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Tsanie.ApkPreviewHandler")]
[Guid("2b09062a-b853-4e5c-b349-b1f3aa8e063b")]
[PreviewHandler("ApkPreviewHandler", ".xapk", "{74428040-0d3b-4789-a70f-91582d9a643e}")]
public class ApkPreviewHandler : WpfPreviewHandler, IPreviewFromFile, IPreviewFromStream
{
public ApkPreviewHandler()
{
Control = new ApkPreviewPanel();
}
private void Populate(Stream stream)
{
if (Control is ApkPreviewPanel panel)
{
panel.SetLabel($"length: {stream.Length}");
}
}
#region IPreviewFromFile Members
public void Load(FileInfo info)
{
using (var stream = File.OpenRead(info.FullName))
{
Populate(stream);
}
}
#endregion
#region IPreviewFromStream Members
public void Load(Stream stream)
{
using (stream)
{
Populate(stream);
}
}
#endregion
}
}