Files
QuickLook/QuickLook.Plugin/QuickLook.Plugin.CertViewer/Plugin.cs
ema 06694e0b16
Some checks failed
build / build (push) Has been cancelled
build / publish (push) Has been cancelled
Add password support for protected certificates
Introduces UI and logic to handle password-protected certificate files. The CertViewerControl now prompts for a password if needed, and attempts to reload the certificate with the provided password. Refactored certificate loading flow to support this feature.
2025-12-23 14:41:59 +08:00

73 lines
1.5 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;
_control = new CertViewerControl();
_control.LoadFromPath(path);
context.ViewerContent = _control;
context.Title = Path.GetFileName(path);
context.IsBusy = false;
}
public void Cleanup()
{
_control?.Dispose();
_control = null;
}
}