From 07e8fef9e054764a74f56faa5911c2d963dc62b6 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sat, 4 Apr 2020 17:17:32 -0500 Subject: [PATCH] Pulled out IgnoreReason and stuff and documented --- IPA.Loader/Loader/PluginLoader.cs | 165 ++++++++++++++++++++++++++---- 1 file changed, 144 insertions(+), 21 deletions(-) diff --git a/IPA.Loader/Loader/PluginLoader.cs b/IPA.Loader/Loader/PluginLoader.cs index 3c9bff2a..1155efaa 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -29,7 +29,8 @@ namespace IPA.Loader /// /// A type to manage the loading of plugins. /// - internal class PluginLoader + + internal partial class PluginLoader { internal static Task LoadTask() => TaskEx.Run(() => @@ -112,9 +113,9 @@ namespace IPA.Loader { var pluginModule = AssemblyDefinition.ReadAssembly(plugin, new ReaderParameters { - ReadingMode = ReadingMode.Immediate, - ReadWrite = false, - AssemblyResolver = new CecilLibLoader() + ReadingMode = ReadingMode.Immediate, + ReadWrite = false, + AssemblyResolver = new CecilLibLoader() }).MainModule; string pluginNs = ""; @@ -287,29 +288,151 @@ namespace IPA.Loader } } } + } - internal enum Reason + /// + /// An enum that represents several categories of ignore reasons that the loader may encounter. + /// + /// + public enum Reason + { + /// + /// An error was thrown either loading plugin information fomr disk, or when initializing the plugin. + /// + /// + /// When this is the set in an structure, the member + /// will contain the thrown exception. + /// + Error, + /// + /// The plugin this reason is associated with has the same ID as another plugin whose information was + /// already loaded. + /// + /// + /// When this is the set in an structure, the member + /// will contain the metadata of the already loaded plugin. + /// + Duplicate, + /// + /// The plugin this reason is associated with conflicts with another already loaded plugin. + /// + /// + /// When this is the set in an structure, the member + /// will contain the metadata of the plugin it conflicts with. + /// + Conflict, + /// + /// The plugin this reason is assiciated with is missing a dependency. + /// + /// + /// Since this is only given when a dependency is missing, will + /// not be set. + /// + Dependency, + /// + /// The plugin this reason is associated with was released for a game update, but is still considered + /// present for the purposes of updating. + /// + Released, + /// + /// The plugin this reason is associated with was denied from loading by a + /// that it marks. + /// + Feature, + /// + /// The plugin this reason is assoicated with is unsupported. + /// + /// + /// Currently, there is no path in the loader that emits this , however there may + /// be in the future. + /// + Unsupported, + /// + /// One of the files that a plugin declared in its manifest is missing. + /// + MissingFiles + } + /// + /// A structure describing the reason that a plugin was ignored. + /// + public struct IgnoreReason + { + /// + /// Gets the ignore reason, as represented by the enum. + /// + public Reason Reason { get; } + /// + /// Gets the textual description of the particular ignore reason. This will typically + /// include details about why the plugin was ignored, if it is present. + /// + public string ReasonText { get; internal set; } + /// + /// Gets the that caused this plugin to be ignored, if any. + /// + public Exception Error { get; internal set; } + /// + /// Gets the metadata of the plugin that this ignore was related to, if any. + /// + public PluginMetadata RelatedTo { get; internal set; } + /// + /// Initializes an with the provided data. + /// + /// the enum value that describes this reason + /// the textual description of this ignore reason, if any + /// the that caused this , if any + /// the this reason is related to, if any + public IgnoreReason(Reason reason, string reasonText = null, Exception error = null, PluginMetadata relatedTo = null) { - Error, Duplicate, Conflict, Dependency, - Released, Feature, Unsupported, - MissingFiles + Reason = reason; + ReasonText = reasonText; + Error = error; + RelatedTo = relatedTo; } - internal struct IgnoreReason - { - public Reason Reason { get; } - public string ReasonText { get; set; } - public Exception Error { get; set; } - public PluginMetadata RelatedTo { get; set; } - public IgnoreReason(Reason reason) - { - Reason = reason; - ReasonText = null; - Error = null; - RelatedTo = null; - } + /// + public override bool Equals(object obj) + => obj is IgnoreReason ir && Equals(ir); + /// + /// Compares this with for equality. + /// + /// the reason to compare to + /// if the two reasons compare equal, otherwise + public bool Equals(IgnoreReason other) + => Reason == other.Reason && ReasonText == other.ReasonText + && Error == other.Error && RelatedTo == other.RelatedTo; + + /// + public override int GetHashCode() + { + int hashCode = 778404373; + hashCode = hashCode * -1521134295 + Reason.GetHashCode(); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ReasonText); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Error); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(RelatedTo); + return hashCode; } + /// + /// Checks if two s are equal. + /// + /// the first to compare + /// the second to compare + /// if the two reasons compare equal, otherwise + public static bool operator ==(IgnoreReason left, IgnoreReason right) + => left.Equals(right); + + /// + /// Checks if two s are not equal. + /// + /// the first to compare + /// the second to compare + /// if the two reasons are not equal, otherwise + public static bool operator !=(IgnoreReason left, IgnoreReason right) + => !(left == right); + } + + internal partial class PluginLoader + { // keep track of these for the updater; it should still be able to update mods not loaded // the thing -> the reason internal static Dictionary ignoredPlugins = new Dictionary();