From 929dccb75a1405737975d76648e015a3e7c00177 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 Oct 2017 23:07:10 -0400 Subject: reorganise repo structure --- src/StardewModdingAPI/Framework/ModRegistry.cs | 113 ------------------------- 1 file changed, 113 deletions(-) delete mode 100644 src/StardewModdingAPI/Framework/ModRegistry.cs (limited to 'src/StardewModdingAPI/Framework/ModRegistry.cs') diff --git a/src/StardewModdingAPI/Framework/ModRegistry.cs b/src/StardewModdingAPI/Framework/ModRegistry.cs deleted file mode 100644 index 9dde7a20..00000000 --- a/src/StardewModdingAPI/Framework/ModRegistry.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; - -namespace StardewModdingAPI.Framework -{ - /// Tracks the installed mods. - internal class ModRegistry - { - /********* - ** Properties - *********/ - /// The registered mod data. - private readonly List Mods = new List(); - - /// The friendly mod names treated as deprecation warning sources (assembly full name => mod name). - private readonly IDictionary ModNamesByAssembly = new Dictionary(); - - - /********* - ** Public methods - *********/ - /**** - ** Basic metadata - ****/ - /// Get metadata for all loaded mods. - public IEnumerable GetAll() - { - return this.Mods.Select(p => p.Manifest); - } - - /// Get metadata for a loaded mod. - /// The mod's unique ID. - /// Returns the matching mod's metadata, or null if not found. - public IManifest Get(string uniqueID) - { - // normalise search ID - if (string.IsNullOrWhiteSpace(uniqueID)) - return null; - uniqueID = uniqueID.Trim(); - - // find match - return this.GetAll().FirstOrDefault(p => p.UniqueID.Trim().Equals(uniqueID, StringComparison.InvariantCultureIgnoreCase)); - } - - /// Get whether a mod has been loaded. - /// The mod's unique ID. - public bool IsLoaded(string uniqueID) - { - return this.Get(uniqueID) != null; - } - - /**** - ** Mod data - ****/ - /// Register a mod as a possible source of deprecation warnings. - /// The mod metadata. - public void Add(IModMetadata metadata) - { - this.Mods.Add(metadata); - this.ModNamesByAssembly[metadata.Mod.GetType().Assembly.FullName] = metadata.DisplayName; - } - - /// Get all enabled mods. - public IEnumerable GetMods() - { - return (from mod in this.Mods select mod); - } - - /// Get the friendly mod name which defines a type. - /// The type to check. - /// Returns the mod name, or null if the type isn't part of a known mod. - public string GetModFrom(Type type) - { - // null - if (type == null) - return null; - - // known type - string assemblyName = type.Assembly.FullName; - if (this.ModNamesByAssembly.ContainsKey(assemblyName)) - return this.ModNamesByAssembly[assemblyName]; - - // not found - return null; - } - - /// Get the friendly name for the closest assembly registered as a source of deprecation warnings. - /// Returns the source name, or null if no registered assemblies were found. - public string GetModFromStack() - { - // get stack frames - StackTrace stack = new StackTrace(); - StackFrame[] frames = stack.GetFrames(); - if (frames == null) - return null; - - // search stack for a source assembly - foreach (StackFrame frame in frames) - { - MethodBase method = frame.GetMethod(); - string name = this.GetModFrom(method.ReflectedType); - if (name != null) - return name; - } - - // no known assembly found - return null; - } - } -} -- cgit