Skip to content

Commit bc7ae46

Browse files
committed
Code Cleanup
1 parent 612fb36 commit bc7ae46

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

QuickLook/PluginManager.cs

+27-29
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ private PluginManager()
4242

4343
internal IViewer DefaultPlugin { get; } = new Plugin.InfoPanel.Plugin();
4444

45-
internal List<IViewer> LoadedPlugins { get; private set; } = new List<IViewer>();
45+
internal List<IViewer> LoadedPlugins { get; private set; } = [];
4646

4747
internal static PluginManager GetInstance()
4848
{
49-
return _instance ?? (_instance = new PluginManager());
49+
return _instance ??= new PluginManager();
5050
}
5151

5252
internal IViewer FindMatch(string path)
@@ -86,34 +86,32 @@ private void LoadPlugins(string folder)
8686

8787
var failedPlugins = new List<(string Plugin, Exception Error)>();
8888

89-
Directory.GetFiles(folder, "QuickLook.Plugin.*.dll",
90-
SearchOption.AllDirectories)
89+
Directory.GetFiles(folder, "QuickLook.Plugin.*.dll", SearchOption.AllDirectories)
9190
.ToList()
92-
.ForEach(
93-
lib =>
94-
{
95-
try
96-
{
97-
(from t in Assembly.LoadFrom(lib).GetExportedTypes()
98-
where !t.IsInterface && !t.IsAbstract
99-
where typeof(IViewer).IsAssignableFrom(t)
100-
select t).ToList()
101-
.ForEach(type => LoadedPlugins.Add(type.CreateInstance<IViewer>()));
102-
}
103-
// 0x80131515: ERROR_ASSEMBLY_FILE_BLOCKED - Windows blocked the assembly due to security policy
104-
catch (FileLoadException ex) when (ex.HResult == unchecked((int)0x80131515) && SettingHelper.IsPortableVersion())
105-
{
106-
if (!HandleSecurityBlockedException()) throw;
107-
}
108-
catch (Exception ex)
109-
{
110-
// Log the error
111-
ProcessHelper.WriteLog($"Failed to load plugin {Path.GetFileName(lib)}: {ex}");
112-
failedPlugins.Add((Path.GetFileName(lib), ex));
113-
}
114-
});
115-
116-
LoadedPlugins = LoadedPlugins.OrderByDescending(i => i.Priority).ToList();
91+
.ForEach(lib =>
92+
{
93+
try
94+
{
95+
(from t in Assembly.LoadFrom(lib).GetExportedTypes()
96+
where !t.IsInterface && !t.IsAbstract
97+
where typeof(IViewer).IsAssignableFrom(t)
98+
select t).ToList()
99+
.ForEach(type => LoadedPlugins.Add(type.CreateInstance<IViewer>()));
100+
}
101+
// 0x80131515: ERROR_ASSEMBLY_FILE_BLOCKED - Windows blocked the assembly due to security policy
102+
catch (FileLoadException ex) when (ex.HResult == unchecked((int)0x80131515) && SettingHelper.IsPortableVersion())
103+
{
104+
if (!HandleSecurityBlockedException()) throw;
105+
}
106+
catch (Exception ex)
107+
{
108+
// Log the error
109+
ProcessHelper.WriteLog($"Failed to load plugin {Path.GetFileName(lib)}: {ex}");
110+
failedPlugins.Add((Path.GetFileName(lib), ex));
111+
}
112+
});
113+
114+
LoadedPlugins = [.. LoadedPlugins.OrderByDescending(i => i.Priority)];
117115

118116
// If any plugins failed to load, show a message box with the details
119117
if (failedPlugins.Any())

0 commit comments

Comments
 (0)