From b1ef4f75c24ad37ac8eedd3669e8a6fc3b975d60 Mon Sep 17 00:00:00 2001 From: ema Date: Fri, 24 Apr 2026 03:03:05 +0800 Subject: [PATCH] Use XML config for extension allow/block lists --- QuickLook/Helpers/ExtensionFilterHelper.cs | 37 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/QuickLook/Helpers/ExtensionFilterHelper.cs b/QuickLook/Helpers/ExtensionFilterHelper.cs index c703333..5b4c4a9 100644 --- a/QuickLook/Helpers/ExtensionFilterHelper.cs +++ b/QuickLook/Helpers/ExtensionFilterHelper.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml; namespace QuickLook.Helpers; @@ -42,6 +43,8 @@ public static class ExtensionFilterHelper private const string AllowlistKey = "ExtensionAllowlist"; private const string BlocklistKey = "ExtensionBlocklist"; private const string UseAllowlistModeKey = "UseExtensionAllowlist"; + private const string AllowlistPlaceholder = "$(ExtensionAllowlist)"; + private const string BlocklistPlaceholder = "$(ExtensionBlocklist)"; private static readonly char[] ExtensionSeparators = [';', ',']; private static readonly HashSet DefaultBlocklist = new(StringComparer.OrdinalIgnoreCase) @@ -84,9 +87,10 @@ public static class ExtensionFilterHelper { if (_allowlistCache == null) { - var list = SettingHelper.Get(AllowlistKey, string.Empty); - _allowlistCache = ParseExtensionList(list); - _allowlistCache.UnionWith(DefaultAllowlist); + var list = GetSettingNodeValue(AllowlistKey); + _allowlistCache = ParseExtensionList(list ?? string.Empty); + if (list == null || list.Contains(AllowlistPlaceholder, StringComparison.Ordinal)) + _allowlistCache.UnionWith(DefaultAllowlist); } return _allowlistCache; } @@ -102,9 +106,10 @@ public static class ExtensionFilterHelper { if (_blocklistCache == null) { - var list = SettingHelper.Get(BlocklistKey, string.Empty); - _blocklistCache = ParseExtensionList(list); - _blocklistCache.UnionWith(DefaultBlocklist); + var list = GetSettingNodeValue(BlocklistKey); + _blocklistCache = ParseExtensionList(list ?? string.Empty); + if (list == null || list.Contains(BlocklistPlaceholder, StringComparison.Ordinal)) + _blocklistCache.UnionWith(DefaultBlocklist); } return _blocklistCache; } @@ -239,4 +244,24 @@ public static class ExtensionFilterHelper return true; } + + private static string GetSettingNodeValue(string key) + { + var file = Path.Combine(SettingHelper.LocalDataPath, "QuickLook.config"); + if (!File.Exists(file)) + return null; + + var doc = new XmlDocument(); + try + { + doc.Load(file); + } + catch (XmlException) + { + return null; + } + + var node = doc.SelectSingleNode($"/Settings/{key}"); + return node?.InnerText; + } }