diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index c5257db6..64f6872c 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -27,17 +27,23 @@ namespace IPA.Loader { #pragma warning disable CS0618 // Type or member is obsolete (IPlugin) - internal class BSPluginMeta + /// + /// A container object for all the data relating to a plugin. + /// + public class PluginInfo { - public IBeatSaberPlugin Plugin { get; internal set; } - public string Filename { get; internal set; } + internal IBeatSaberPlugin Plugin { get; set; } + internal string Filename { get; set; } + /// + /// The Modsaber updating info for the mod, or null. + /// public ModsaberModInfo ModsaberInfo { get; internal set; } } /// /// An of new Beat Saber plugins /// - public static IEnumerable BSPlugins + internal static IEnumerable BSPlugins { get { @@ -48,8 +54,8 @@ namespace IPA.Loader return _bsPlugins.Select(p => p.Plugin); } } - private static List _bsPlugins = null; - internal static IEnumerable BSMetas + private static List _bsPlugins = null; + internal static IEnumerable BSMetas { get { @@ -60,10 +66,31 @@ namespace IPA.Loader return _bsPlugins; } } + + /// + /// Gets info about the plugin with the specified name. + /// + /// the name of the plugin to get (must be an exact match) + /// the plugin info for the requested plugin or null + public static PluginInfo GetPlugin(string name) + { + return BSMetas.Where(p => p.Plugin.Name == name).FirstOrDefault(); + } + + /// + /// Gets info about the plugin with the specified modsaber name. + /// + /// the modsaber name of the plugin to get (must be an exact match) + /// the plugin info for the requested plugin or null + public static PluginInfo GetPluginFromModsaberName(string name) + { + return BSMetas.Where(p => p.ModsaberInfo.InternalName == name).FirstOrDefault(); + } /// /// An of old IPA plugins /// + [Obsolete("I mean, IPlugin shouldn't be used, so why should this? Not renaming to extend support for old plugins.")] public static IEnumerable Plugins { get @@ -88,7 +115,7 @@ namespace IPA.Loader // Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL, // so we need to resort to P/Invoke string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath); - _bsPlugins = new List(); + _bsPlugins = new List(); _ipaPlugins = new List(); if (!Directory.Exists(pluginDirectory)) return; @@ -155,7 +182,7 @@ namespace IPA.Loader #endregion } - var selfPlugin = new BSPluginMeta + var selfPlugin = new PluginInfo { Filename = Path.Combine(Environment.CurrentDirectory, "IPA.exe"), Plugin = SelfPlugin.Instance @@ -194,13 +221,13 @@ namespace IPA.Loader Logger.log.Info("-----------------------------"); } - private static Tuple, IEnumerable> LoadPluginsFromFile(string file, string exeName) + private static Tuple, IEnumerable> LoadPluginsFromFile(string file, string exeName) { - List bsPlugins = new List(); + List bsPlugins = new List(); List ipaPlugins = new List(); if (!File.Exists(file) || !file.EndsWith(".dll", true, null)) - return new Tuple, IEnumerable>(bsPlugins, ipaPlugins); + return new Tuple, IEnumerable>(bsPlugins, ipaPlugins); T OptionalGetPlugin(Type t) where T : class { @@ -280,7 +307,7 @@ namespace IPA.Loader init.Invoke(bsPlugin, initArgs.ToArray()); } - bsPlugins.Add(new BSPluginMeta + bsPlugins.Add(new PluginInfo { Plugin = bsPlugin, Filename = file.Replace("\\.cache", ""), // quick and dirty fix @@ -308,7 +335,7 @@ namespace IPA.Loader Logger.loader.Error($"Could not load {Path.GetFileName(file)}! {e}"); } - return new Tuple, IEnumerable>(bsPlugins, ipaPlugins); + return new Tuple, IEnumerable>(bsPlugins, ipaPlugins); } internal class AppInfo diff --git a/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs b/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs index 33671149..a1c19fe5 100644 --- a/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs +++ b/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs @@ -14,11 +14,41 @@ namespace IPA /// /// The name the mod uses on ModSaber as an identifier. /// - public string InternalName { get; set; } - + public string InternalName + { + get => _InternalName; + set + { + if (_InternalName == null) + { + _InternalName = value; + } + else + { + throw new Exception("Cannot change name one it has been set!"); + } + } + } + private string _InternalName = null; + /// /// The version of the currently installed mod. Used to compare to the version on ModSaber. Should be a valid SemVer version. /// - public string CurrentVersion { get; set; } + public string CurrentVersion + { + get => _CurrentVersion; + set + { + if (_CurrentVersion == null) + { + _CurrentVersion = value; + } + else + { + throw new Exception("Cannot change version one it has been set!"); + } + } + } + private string _CurrentVersion = null; } } diff --git a/IPA.Loader/Updating/ModsaberML/Updater.cs b/IPA.Loader/Updating/ModsaberML/Updater.cs index 53a2760b..a1ae5500 100644 --- a/IPA.Loader/Updating/ModsaberML/Updater.cs +++ b/IPA.Loader/Updating/ModsaberML/Updater.cs @@ -65,7 +65,7 @@ namespace IPA.Updating.ModsaberML public bool MetaRequestFailed { get; set; } = false; - public BSPluginMeta LocalPluginMeta { get; set; } = null; + public PluginInfo LocalPluginMeta { get; set; } = null; public override string ToString() {