Add certificate viewer plugin

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.
This commit is contained in:
ema
2025-12-23 14:15:52 +08:00
parent 154ec05528
commit dba41ac890
8 changed files with 390 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
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;
}
}