Browse Source

Applied nullability to PluginMetadata

pull/94/head
Anairkoen Schno 3 years ago
parent
commit
803183c6bc
Signed by: DaNike GPG Key ID: BEFB74D5F3FC4387
2 changed files with 23 additions and 18 deletions
  1. +9
    -5
      IPA.Loader/Loader/PluginLoader.cs
  2. +14
    -13
      IPA.Loader/Loader/PluginMetadata.cs

+ 9
- 5
IPA.Loader/Loader/PluginLoader.cs View File

@ -132,6 +132,7 @@ namespace IPA.Loader
string pluginNs = "";
PluginManifest? pluginManifest = null;
foreach (var resource in pluginModule.Resources)
{
const string manifestSuffix = ".manifest.json";
@ -144,11 +145,11 @@ namespace IPA.Loader
using (var manifestReader = new StreamReader(embedded.GetResourceStream()))
manifest = manifestReader.ReadToEnd();
metadata.Manifest = JsonConvert.DeserializeObject<PluginManifest>(manifest);
pluginManifest = JsonConvert.DeserializeObject<PluginManifest?>(manifest);
break;
}
if (metadata.Manifest == null)
if (pluginManifest == null)
{
#if DIRE_LOADER_WARNINGS
Logger.loader.Error($"Could not find manifest.json for {Path.GetFileName(plugin)}");
@ -158,6 +159,8 @@ namespace IPA.Loader
continue;
}
metadata.Manifest = pluginManifest;
void TryGetNamespacedPluginType(string ns, PluginMetadata meta)
{
foreach (var type in pluginModule.Types)
@ -277,7 +280,8 @@ namespace IPA.Loader
string description;
if (!meta.IsSelf)
{
var resc = meta.PluginType.Module.Resources.Select(r => r as EmbeddedResource)
// plugin type must be non-null for non-self plugins
var resc = meta.PluginType!.Module.Resources.Select(r => r as EmbeddedResource)
.NonNull()
.FirstOrDefault(r => r.Name == name);
if (resc == null)
@ -747,7 +751,7 @@ namespace IPA.Loader
{
if (feature.TryGetDefiningPlugin(out var plugin))
{
if (plugin != meta)
if (plugin != meta && plugin != null)
{ // if the feature is not applied to the defining feature
_ = meta.LoadsAfter.Add(plugin);
}
@ -777,7 +781,7 @@ namespace IPA.Loader
{ // clean them up so we can still use the metadata for updates
m.InternalFeatures.Clear();
m.PluginType = null;
m.Assembly = null;
m.Assembly = null!;
}
}
PluginsMetadata = new List<PluginMetadata>();


+ 14
- 13
IPA.Loader/Loader/PluginMetadata.cs View File

@ -1,4 +1,5 @@
using IPA.Loader.Features;
#nullable enable
using IPA.Loader.Features;
using IPA.Utilities;
using Mono.Cecil;
using System;
@ -23,13 +24,13 @@ namespace IPA.Loader
/// The assembly the plugin was loaded from.
/// </summary>
/// <value>the loaded Assembly that contains the plugin main type</value>
public Assembly Assembly { get; internal set; }
public Assembly Assembly { get; internal set; } = null!;
/// <summary>
/// The TypeDefinition for the main type of the plugin.
/// </summary>
/// <value>the Cecil definition for the plugin main type</value>
public TypeDefinition PluginType { get; internal set; }
public TypeDefinition? PluginType { get; internal set; }
/// <summary>
/// The human readable name of the plugin.
@ -65,7 +66,7 @@ namespace IPA.Loader
/// The file the plugin was loaded from.
/// </summary>
/// <value>the file the plugin was loaded from</value>
public FileInfo File { get; internal set; }
public FileInfo File { get; internal set; } = null!;
// ReSharper disable once UnusedAutoPropertyAccessor.Global
/// <summary>
@ -74,11 +75,11 @@ namespace IPA.Loader
/// <value>the list of features requested by the plugin</value>
public IReadOnlyList<Feature> Features => InternalFeatures;
internal readonly List<Feature> InternalFeatures = new List<Feature>();
internal readonly List<Feature> InternalFeatures = new();
internal readonly HashSet<Feature.Instance> UnloadedFeatures = new HashSet<Feature.Instance>();
internal readonly HashSet<Feature.Instance> UnloadedFeatures = new();
internal readonly List<Feature.Instance> CreateFeaturesWhenLoaded = new List<Feature.Instance>();
internal readonly List<Feature.Instance> CreateFeaturesWhenLoaded = new();
/// <summary>
/// A list of files (that aren't <see cref="File"/>) that are associated with this plugin.
@ -96,18 +97,18 @@ namespace IPA.Loader
/// A link to this plugin's home page, if any.
/// </summary>
/// <value>the <see cref="Uri"/> of the plugin's home page</value>
public Uri PluginHomeLink => manifest.Links?.ProjectHome;
public Uri? PluginHomeLink => manifest.Links?.ProjectHome;
/// <summary>
/// A link to this plugin's source code, if avaliable.
/// </summary>
/// <value>the <see cref="Uri"/> of the plugin's source code</value>
public Uri PluginSourceLink => manifest.Links?.ProjectSource;
public Uri? PluginSourceLink => manifest.Links?.ProjectSource;
/// <summary>
/// A link to a donate page for the author of this plugin, if avaliable.
/// </summary>
/// <value>the <see cref="Uri"/> of the author's donate page</value>
public Uri DonateLink => manifest.Links?.Donate;
public Uri? DonateLink => manifest.Links?.Donate;
internal bool IsSelf;
@ -117,10 +118,10 @@ namespace IPA.Loader
/// <value><see langword="true"/> if it is bare, <see langword="false"/> otherwise</value>
public bool IsBare { get; internal set; }
private PluginManifest manifest;
private PluginManifest manifest = null!;
internal HashSet<PluginMetadata> Dependencies { get; } = new HashSet<PluginMetadata>();
internal HashSet<PluginMetadata> LoadsAfter { get; } = new HashSet<PluginMetadata>();
internal HashSet<PluginMetadata> Dependencies { get; } = new();
internal HashSet<PluginMetadata> LoadsAfter { get; } = new();
internal PluginManifest Manifest
{


Loading…
Cancel
Save