Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Jan 5, 2025
1 parent 612fb36 commit bc7ae46
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions QuickLook/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ private PluginManager()

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

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

internal static PluginManager GetInstance()
{
return _instance ?? (_instance = new PluginManager());
return _instance ??= new PluginManager();
}

internal IViewer FindMatch(string path)
Expand Down Expand Up @@ -86,34 +86,32 @@ private void LoadPlugins(string folder)

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

Directory.GetFiles(folder, "QuickLook.Plugin.*.dll",
SearchOption.AllDirectories)
Directory.GetFiles(folder, "QuickLook.Plugin.*.dll", SearchOption.AllDirectories)
.ToList()
.ForEach(
lib =>
{
try
{
(from t in Assembly.LoadFrom(lib).GetExportedTypes()
where !t.IsInterface && !t.IsAbstract
where typeof(IViewer).IsAssignableFrom(t)
select t).ToList()
.ForEach(type => LoadedPlugins.Add(type.CreateInstance<IViewer>()));
}
// 0x80131515: ERROR_ASSEMBLY_FILE_BLOCKED - Windows blocked the assembly due to security policy
catch (FileLoadException ex) when (ex.HResult == unchecked((int)0x80131515) && SettingHelper.IsPortableVersion())
{
if (!HandleSecurityBlockedException()) throw;
}
catch (Exception ex)
{
// Log the error
ProcessHelper.WriteLog($"Failed to load plugin {Path.GetFileName(lib)}: {ex}");
failedPlugins.Add((Path.GetFileName(lib), ex));
}
});

LoadedPlugins = LoadedPlugins.OrderByDescending(i => i.Priority).ToList();
.ForEach(lib =>
{
try
{
(from t in Assembly.LoadFrom(lib).GetExportedTypes()
where !t.IsInterface && !t.IsAbstract
where typeof(IViewer).IsAssignableFrom(t)
select t).ToList()
.ForEach(type => LoadedPlugins.Add(type.CreateInstance<IViewer>()));
}
// 0x80131515: ERROR_ASSEMBLY_FILE_BLOCKED - Windows blocked the assembly due to security policy
catch (FileLoadException ex) when (ex.HResult == unchecked((int)0x80131515) && SettingHelper.IsPortableVersion())
{
if (!HandleSecurityBlockedException()) throw;
}
catch (Exception ex)
{
// Log the error
ProcessHelper.WriteLog($"Failed to load plugin {Path.GetFileName(lib)}: {ex}");
failedPlugins.Add((Path.GetFileName(lib), ex));
}
});

LoadedPlugins = [.. LoadedPlugins.OrderByDescending(i => i.Priority)];

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

0 comments on commit bc7ae46

Please sign in to comment.