Browse Source

PluginManager cleanup

4.0.0-beta
Anairkoen Schno 4 years ago
parent
commit
93a3b8e469
2 changed files with 1 additions and 143 deletions
  1. +0
    -143
      IPA.Loader/Loader/PluginManager.cs
  2. +1
    -0
      IPA.Loader/Loader/StateTransitionTransaction.cs

+ 0
- 143
IPA.Loader/Loader/PluginManager.cs View File

@ -203,149 +203,6 @@ namespace IPA.Loader
public IEnumerable<DisableExecutor> Dependents; public IEnumerable<DisableExecutor> Dependents;
} }
// TODO: rewrite below
/*
/// <summary>
/// Disables a plugin, and all dependents.
/// </summary>
/// <param name="plugin">the plugin to disable</param>
/// <returns>whether or not it needs a restart to enable</returns>
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;
}
/// <summary>
/// Disables a plugin, and all dependents.
/// </summary>
/// <param name="pluginId">the ID, or name if the ID is null, of the plugin to disable</param>
/// <returns>whether a restart is needed to activate</returns>
public static bool DisablePlugin(string pluginId) => DisablePlugin(GetPluginFromId(pluginId) ?? GetPlugin(pluginId));
/// <summary>
/// Enables a plugin that had been previously disabled.
/// </summary>
/// <param name="plugin">the plugin to enable</param>
/// <returns>whether a restart is needed to activate</returns>
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;
}
/// <summary>
/// Enables a plugin that had been previously disabled.
/// </summary>
/// <param name="pluginId">the ID, or name if the ID is null, of the plugin to enable</param>
/// <returns>whether a restart is needed to activate</returns>
public static bool EnablePlugin(string pluginId) =>
EnablePlugin(GetDisabledPluginFromId(pluginId) ?? GetDisabledPlugin(pluginId));*/
/// <summary> /// <summary>
/// Checks if a given plugin is disabled. /// Checks if a given plugin is disabled.
/// </summary> /// </summary>


+ 1
- 0
IPA.Loader/Loader/StateTransitionTransaction.cs View File

@ -203,6 +203,7 @@ namespace IPA.Loader
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para>After this completes, this transaction will be disposed.</para> /// <para>After this completes, this transaction will be disposed.</para>
/// <para>It is illegal to call this anywhere but the main Unity thread.</para>
/// <para> /// <para>
/// The <see cref="Task"/> that is returned will error if <b>any</b> of the mods being <b>disabled</b> /// The <see cref="Task"/> that is returned will error if <b>any</b> of the mods being <b>disabled</b>
/// error. It is up to the caller to handle these in a sane way, like logging them. If nothing else, do something like this: /// error. It is up to the caller to handle these in a sane way, like logging them. If nothing else, do something like this:


Loading…
Cancel
Save