Skip to content

Commit

Permalink
Remove duplicate exception log
Browse files Browse the repository at this point in the history
  • Loading branch information
KamilDev committed Dec 7, 2024
1 parent c3e78f6 commit 34e4a9a
Showing 1 changed file with 48 additions and 56 deletions.
104 changes: 48 additions & 56 deletions QuickLook/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,64 +85,56 @@ private void LoadPlugins(string folder)

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

try
{
Directory.GetFiles(folder, "QuickLook.Plugin.*.dll",
SearchOption.AllDirectories)
.ToList()
.ForEach(
lib =>
Directory.GetFiles(folder, "QuickLook.Plugin.*.dll",
SearchOption.AllDirectories)
.ToList()
.ForEach(
lib =>
{
try
{
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>()));
}
catch (FileLoadException ex) when (ex.Message.Contains("0x80131515") && SettingHelper.IsPortableVersion())
{
MessageBox.Show(
"Windows has blocked the plugins.\n\n" +
"To fix this, please follow these steps:\n" +
"1. Right-click the downloaded QuickLook zip file and select 'Properties'\n" +
"2. At the bottom of the Properties window, check 'Unblock'\n" +
"3. Click 'Apply' and 'OK'\n" +
"4. Extract the zip file again\n\n" +
"QuickLook will now close. Please launch it from the unblocked folder.",
"Security Block Detected",
MessageBoxButton.OK,
MessageBoxImage.Error);
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();

// If any plugins failed to load, show a message box with the details
if (failedPlugins.Any())
{
var message = "The following plugins failed to load:\n\n" +
string.Join("\n", failedPlugins.Select(f => $"• {f.Plugin}"));

MessageBox.Show(
message,
"Some Plugins Failed to Load",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
}
catch (Exception ex)
(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>()));
}
catch (FileLoadException ex) when (ex.Message.Contains("0x80131515") && SettingHelper.IsPortableVersion())
{
MessageBox.Show(
"Windows has blocked the plugins.\n\n" +
"To fix this, please follow these steps:\n" +
"1. Right-click the downloaded QuickLook zip file and select 'Properties'\n" +
"2. At the bottom of the Properties window, check 'Unblock'\n" +
"3. Click 'Apply' and 'OK'\n" +
"4. Extract the zip file again\n\n" +
"QuickLook will now close. Please launch it from the unblocked folder.",
"Security Block Detected",
MessageBoxButton.OK,
MessageBoxImage.Error);
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();

// If any plugins failed to load, show a message box with the details
if (failedPlugins.Any())
{
ProcessHelper.WriteLog(ex.ToString());
throw;
var message = "The following plugins failed to load:\n\n" +
string.Join("\n", failedPlugins.Select(f => $"• {f.Plugin}"));

MessageBox.Show(
message,
"Some Plugins Failed to Load",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
}

Expand Down

0 comments on commit 34e4a9a

Please sign in to comment.