mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-01-13 07:05:24 +08:00
Introduces QuickLook.Plugin.CertViewer for viewing certificate files (.pfx, .cer, .pem, etc.) in QuickLook. The plugin loads and displays certificate details or raw content, and is integrated into the solution and project files.
83 lines
1.8 KiB
C#
83 lines
1.8 KiB
C#
using QuickLook.Common.Plugin;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Windows;
|
|
|
|
namespace QuickLook.Plugin.CertViewer;
|
|
|
|
public class Plugin : IViewer
|
|
{
|
|
private static readonly HashSet<string> WellKnownExtensions = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
".p12",
|
|
".pfx",
|
|
".cer",
|
|
".crt",
|
|
".pem",
|
|
".snk",
|
|
".pvk",
|
|
".spc",
|
|
".mobileprovision",
|
|
".certSigningRequest",
|
|
".csr",
|
|
".keystore",
|
|
};
|
|
|
|
private CertViewerControl _control;
|
|
private string _currentPath;
|
|
|
|
public int Priority => 0;
|
|
|
|
public void Init()
|
|
{
|
|
}
|
|
|
|
public bool CanHandle(string path)
|
|
{
|
|
if (Directory.Exists(path))
|
|
return false;
|
|
|
|
var ext = Path.GetExtension(path);
|
|
if (!string.IsNullOrEmpty(ext) && WellKnownExtensions.Contains(ext))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
public void Prepare(string path, ContextObject context)
|
|
{
|
|
context.PreferredSize = new Size { Width = 800, Height = 600 };
|
|
}
|
|
|
|
public void View(string path, ContextObject context)
|
|
{
|
|
_currentPath = path;
|
|
|
|
context.IsBusy = true;
|
|
|
|
var result = CertUtils.TryLoadCertificate(path);
|
|
|
|
_control = new CertViewerControl();
|
|
|
|
if (result.Success && result.Certificate != null)
|
|
{
|
|
_control.LoadCertificate(result.Certificate);
|
|
}
|
|
else
|
|
{
|
|
_control.LoadRaw(path, result.Message, result.RawContent);
|
|
}
|
|
|
|
context.ViewerContent = _control;
|
|
context.Title = Path.GetFileName(path);
|
|
context.IsBusy = false;
|
|
}
|
|
|
|
public void Cleanup()
|
|
{
|
|
_control?.Dispose();
|
|
_control = null;
|
|
}
|
|
}
|