From 93a3b8e469a908f3d60bcc7da92ccb39e6c7a697 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Thu, 16 Jan 2020 22:12:26 -0600 Subject: [PATCH] PluginManager cleanup --- IPA.Loader/Loader/PluginManager.cs | 143 ------------------ .../Loader/StateTransitionTransaction.cs | 1 + 2 files changed, 1 insertion(+), 143 deletions(-) diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index ae5f8fd3..f13105b3 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -203,149 +203,6 @@ namespace IPA.Loader public IEnumerable Dependents; } - // TODO: rewrite below - /* - /// - /// Disables a plugin, and all dependents. - /// - /// the plugin to disable - /// whether or not it needs a restart to enable - public static bool DisablePlugin(PluginInfo plugin) - { - if (plugin == null) return false; - - if (plugin.Metadata.IsBare) - { - Logger.loader.Warn($"Trying to disable bare manifest"); - return false; - } - - if (IsDisabled(plugin.Metadata)) return false; - - var needsRestart = false; - - Logger.loader.Info($"Disabling {plugin.Metadata.Name}"); - - var dependents = BSMetas.Where(m => m.Metadata.Dependencies.Contains(plugin.Metadata)).ToList(); - needsRestart = dependents.Aggregate(needsRestart, (b, p) => DisablePlugin(p) || b); - - DisabledConfig.Instance.DisabledModIds.Add(plugin.Metadata.Id ?? plugin.Metadata.Name); - - if (!needsRestart && plugin.Plugin is IDisablablePlugin disable) - { - try - { - disable.OnDisable(); - } - catch (Exception e) - { - Logger.loader.Error($"Error occurred trying to disable {plugin.Metadata.Name}"); - Logger.loader.Error(e); - } - - if (needsRestart) - Logger.loader.Warn($"Disablable plugin has non-disablable dependents; some things may not work properly"); - } - else needsRestart = true; - - runtimeDisabled.Add(plugin); - _bsPlugins.Remove(plugin); - - try - { - PluginDisabled?.Invoke(plugin.Metadata, needsRestart); - } - catch (Exception e) - { - Logger.loader.Error($"Error occurred invoking disable event for {plugin.Metadata.Name}"); - Logger.loader.Error(e); - } - - return needsRestart; - } - - /// - /// Disables a plugin, and all dependents. - /// - /// the ID, or name if the ID is null, of the plugin to disable - /// whether a restart is needed to activate - public static bool DisablePlugin(string pluginId) => DisablePlugin(GetPluginFromId(pluginId) ?? GetPlugin(pluginId)); - - /// - /// Enables a plugin that had been previously disabled. - /// - /// the plugin to enable - /// whether a restart is needed to activate - public static bool EnablePlugin(PluginMetadata plugin) - { // TODO: fix some of this behaviour, by adding better support for runtime enable/disable of mods - if (plugin == null) return false; - - if (plugin.IsBare) - { - Logger.loader.Warn($"Trying to enable bare manifest"); - return false; - } - - if (!IsDisabled(plugin)) return false; - - Logger.loader.Info($"Enabling {plugin.Name}"); - - DisabledConfig.Instance.DisabledModIds.Remove(plugin.Id ?? plugin.Name); - - var needsRestart = true; - - var depsNeedRestart = plugin.Dependencies.Aggregate(false, (b, p) => EnablePlugin(p) || b); - - var runtimeInfo = runtimeDisabled.FirstOrDefault(p => p.Metadata == plugin); - if (runtimeInfo != null && runtimeInfo.Plugin is IPlugin newPlugin) - { - try - { - newPlugin.OnEnable(); - } - catch (Exception e) - { - Logger.loader.Error($"Error occurred trying to enable {plugin.Name}"); - Logger.loader.Error(e); - } - needsRestart = false; - } - else - { - PluginLoader.DisabledPlugins.Remove(plugin); - if (runtimeInfo == null) - { - runtimeInfo = InitPlugin(plugin, AllPlugins.Select(i => i.Metadata)); - needsRestart = false; - } - } - - if (runtimeInfo != null) - runtimeDisabled.Remove(runtimeInfo); - - _bsPlugins.Add(runtimeInfo); - - try - { - PluginEnabled?.Invoke(runtimeInfo, needsRestart || depsNeedRestart); - } - catch (Exception e) - { - Logger.loader.Error($"Error occurred invoking enable event for {plugin.Name}"); - Logger.loader.Error(e); - } - - return needsRestart || depsNeedRestart; - } - - /// - /// Enables a plugin that had been previously disabled. - /// - /// the ID, or name if the ID is null, of the plugin to enable - /// whether a restart is needed to activate - public static bool EnablePlugin(string pluginId) => - EnablePlugin(GetDisabledPluginFromId(pluginId) ?? GetDisabledPlugin(pluginId));*/ - /// /// Checks if a given plugin is disabled. /// diff --git a/IPA.Loader/Loader/StateTransitionTransaction.cs b/IPA.Loader/Loader/StateTransitionTransaction.cs index 1bfa94bc..5452cfcd 100644 --- a/IPA.Loader/Loader/StateTransitionTransaction.cs +++ b/IPA.Loader/Loader/StateTransitionTransaction.cs @@ -203,6 +203,7 @@ namespace IPA.Loader /// /// /// After this completes, this transaction will be disposed. + /// It is illegal to call this anywhere but the main Unity thread. /// /// The that is returned will error if any of the mods being disabled /// error. It is up to the caller to handle these in a sane way, like logging them. If nothing else, do something like this: