From ff0d881273b8ca3b4c20eb865fa4dc97d9323205 Mon Sep 17 00:00:00 2001 From: Brant Martin Date: Tue, 27 Aug 2019 16:43:31 -0400 Subject: [PATCH] Gracefully handle corrupt plugin zips --- Torch/Plugins/PluginManager.cs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Torch/Plugins/PluginManager.cs b/Torch/Plugins/PluginManager.cs index 86c68c2..f1097e0 100644 --- a/Torch/Plugins/PluginManager.cs +++ b/Torch/Plugins/PluginManager.cs @@ -206,6 +206,8 @@ namespace Torch.Managers PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly()); } + //debug flag is set when the user asks us to run with a specific plugin for plugin development debug + //please do not change references to this arg unless you are very sure you know what you're doing private List GetLocalPlugins(string pluginDir, bool debug = false) { var firstLoad = Torch.Config.Plugins.Count == 0; @@ -505,19 +507,27 @@ namespace Torch.Managers private PluginManifest GetManifestFromZip(string path) { - using (var zipFile = ZipFile.OpenRead(path)) + try { - foreach (var entry in zipFile.Entries) + using (var zipFile = ZipFile.OpenRead(path)) { - if (!entry.Name.Equals(MANIFEST_NAME, StringComparison.CurrentCultureIgnoreCase)) - continue; - - using (var stream = new StreamReader(entry.Open())) + foreach (var entry in zipFile.Entries) { - return PluginManifest.Load(stream); + if (!entry.Name.Equals(MANIFEST_NAME, StringComparison.CurrentCultureIgnoreCase)) + continue; + + using (var stream = new StreamReader(entry.Open())) + { + return PluginManifest.Load(stream); + } } } } + catch (Exception ex) + { + _log.Error(ex, $"Error opening zip! File is likely corrupt. File at {path} will be deleted and re-acquired on the next restart!"); + File.Delete(path); + } return null; }