|
@ -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>
|
|
|