fix: guard against CommandInfo, Manifest ever becoming null

This commit is contained in:
goat 2023-06-20 19:35:59 +02:00
parent 28e9d5f156
commit d1c22f7dd6
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 6 additions and 3 deletions

View file

@ -2174,7 +2174,10 @@ internal class PluginInstallerWindow : Window, IDisposable
if (plugin.IsLoaded)
{
var commands = commandManager.Commands
.Where(cInfo => cInfo.Value.ShowInHelp && cInfo.Value.LoaderAssemblyName == plugin.Manifest.InternalName)
.Where(cInfo =>
cInfo.Value != null &&
cInfo.Value.ShowInHelp &&
cInfo.Value.LoaderAssemblyName == plugin.Manifest.InternalName)
.ToArray();
if (commands.Any())

View file

@ -630,7 +630,7 @@ internal class LocalPlugin : IDisposable
if (manifest.Exists)
{
// var isDisabled = this.IsDisabled; // saving the internal state because it could have been deleted
this.Manifest = LocalPluginManifest.Load(manifest);
this.Manifest = LocalPluginManifest.Load(manifest) ?? throw new Exception("Could not reload manifest.");
// this.Manifest.Disabled = isDisabled;
this.SaveManifest();

View file

@ -76,7 +76,7 @@ internal record LocalPluginManifest : PluginManifest
/// </summary>
/// <param name="manifestFile">Path to the manifest.</param>
/// <returns>A <see cref="PluginManifest"/> object.</returns>
public static LocalPluginManifest Load(FileInfo manifestFile) => JsonConvert.DeserializeObject<LocalPluginManifest>(File.ReadAllText(manifestFile.FullName))!;
public static LocalPluginManifest? Load(FileInfo manifestFile) => JsonConvert.DeserializeObject<LocalPluginManifest>(File.ReadAllText(manifestFile.FullName));
/// <summary>
/// A standardized way to get the plugin DLL name that should accompany a manifest file. May not exist.