Gracefully handle corrupt plugin zips

This commit is contained in:
Brant Martin
2019-08-27 16:43:31 -04:00
parent ed5d0ea474
commit ff0d881273

View File

@@ -206,6 +206,8 @@ namespace Torch.Managers
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly()); 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<PluginItem> GetLocalPlugins(string pluginDir, bool debug = false) private List<PluginItem> GetLocalPlugins(string pluginDir, bool debug = false)
{ {
var firstLoad = Torch.Config.Plugins.Count == 0; var firstLoad = Torch.Config.Plugins.Count == 0;
@@ -505,19 +507,27 @@ namespace Torch.Managers
private PluginManifest GetManifestFromZip(string path) 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)) foreach (var entry in zipFile.Entries)
continue;
using (var stream = new StreamReader(entry.Open()))
{ {
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; return null;
} }