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 = ""; string pluginNs = "";
PluginManifest? pluginManifest = null;
foreach (var resource in pluginModule.Resources) foreach (var resource in pluginModule.Resources)
{ {
const string manifestSuffix = ".manifest.json"; const string manifestSuffix = ".manifest.json";
@ -144,11 +145,11 @@ namespace IPA.Loader
using (var manifestReader = new StreamReader(embedded.GetResourceStream())) using (var manifestReader = new StreamReader(embedded.GetResourceStream()))
manifest = manifestReader.ReadToEnd(); manifest = manifestReader.ReadToEnd();
metadata.Manifest = JsonConvert.DeserializeObject<PluginManifest>(manifest);
pluginManifest = JsonConvert.DeserializeObject<PluginManifest?>(manifest);
break; break;
} }
if (metadata.Manifest == null)
if (pluginManifest == null)
{ {
#if DIRE_LOADER_WARNINGS #if DIRE_LOADER_WARNINGS
Logger.loader.Error($"Could not find manifest.json for {Path.GetFileName(plugin)}"); Logger.loader.Error($"Could not find manifest.json for {Path.GetFileName(plugin)}");
@ -158,6 +159,8 @@ namespace IPA.Loader
continue; continue;
} }
metadata.Manifest = pluginManifest;
void TryGetNamespacedPluginType(string ns, PluginMetadata meta) void TryGetNamespacedPluginType(string ns, PluginMetadata meta)
{ {
foreach (var type in pluginModule.Types) foreach (var type in pluginModule.Types)
@ -277,7 +280,8 @@ namespace IPA.Loader
string description; string description;
if (!meta.IsSelf) 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() .NonNull()
.FirstOrDefault(r => r.Name == name); .FirstOrDefault(r => r.Name == name);
if (resc == null) if (resc == null)
@ -747,7 +751,7 @@ namespace IPA.Loader
{ {
if (feature.TryGetDefiningPlugin(out var plugin)) if (feature.TryGetDefiningPlugin(out var plugin))
{ {
if (plugin != meta)
if (plugin != meta && plugin != null)
{ // if the feature is not applied to the defining feature { // if the feature is not applied to the defining feature
_ = meta.LoadsAfter.Add(plugin); _ = meta.LoadsAfter.Add(plugin);
} }
@ -777,7 +781,7 @@ namespace IPA.Loader
{ // clean them up so we can still use the metadata for updates { // clean them up so we can still use the metadata for updates
m.InternalFeatures.Clear(); m.InternalFeatures.Clear();
m.PluginType = null; m.PluginType = null;
m.Assembly = null;
m.Assembly = null!;
} }
} }
PluginsMetadata = new List<PluginMetadata>(); 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 IPA.Utilities;
using Mono.Cecil; using Mono.Cecil;
using System; using System;
@ -23,13 +24,13 @@ namespace IPA.Loader
/// The assembly the plugin was loaded from. /// The assembly the plugin was loaded from.
/// </summary> /// </summary>
/// <value>the loaded Assembly that contains the plugin main type</value> /// <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> /// <summary>
/// The TypeDefinition for the main type of the plugin. /// The TypeDefinition for the main type of the plugin.
/// </summary> /// </summary>
/// <value>the Cecil definition for the plugin main type</value> /// <value>the Cecil definition for the plugin main type</value>
public TypeDefinition PluginType { get; internal set; }
public TypeDefinition? PluginType { get; internal set; }
/// <summary> /// <summary>
/// The human readable name of the plugin. /// The human readable name of the plugin.
@ -65,7 +66,7 @@ namespace IPA.Loader
/// The file the plugin was loaded from. /// The file the plugin was loaded from.
/// </summary> /// </summary>
/// <value>the file the plugin was loaded from</value> /// <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 // ReSharper disable once UnusedAutoPropertyAccessor.Global
/// <summary> /// <summary>
@ -74,11 +75,11 @@ namespace IPA.Loader
/// <value>the list of features requested by the plugin</value> /// <value>the list of features requested by the plugin</value>
public IReadOnlyList<Feature> Features => InternalFeatures; 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> /// <summary>
/// A list of files (that aren't <see cref="File"/>) that are associated with this plugin. /// 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. /// A link to this plugin's home page, if any.
/// </summary> /// </summary>
/// <value>the <see cref="Uri"/> of the plugin's home page</value> /// <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> /// <summary>
/// A link to this plugin's source code, if avaliable. /// A link to this plugin's source code, if avaliable.
/// </summary> /// </summary>
/// <value>the <see cref="Uri"/> of the plugin's source code</value> /// <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> /// <summary>
/// A link to a donate page for the author of this plugin, if avaliable. /// A link to a donate page for the author of this plugin, if avaliable.
/// </summary> /// </summary>
/// <value>the <see cref="Uri"/> of the author's donate page</value> /// <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; internal bool IsSelf;
@ -117,10 +118,10 @@ namespace IPA.Loader
/// <value><see langword="true"/> if it is bare, <see langword="false"/> otherwise</value> /// <value><see langword="true"/> if it is bare, <see langword="false"/> otherwise</value>
public bool IsBare { get; internal set; } 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 internal PluginManifest Manifest
{ {


Loading…
Cancel
Save