Browse Source

Changed disable logic to only disable if all dependents could be disabled

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
fd45def7f1
2 changed files with 12 additions and 2 deletions
  1. +7
    -0
      IPA.Loader/Loader/CannotRuntimeDisableException.cs
  2. +5
    -2
      IPA.Loader/Loader/PluginManager.cs

+ 7
- 0
IPA.Loader/Loader/CannotRuntimeDisableException.cs View File

@ -22,6 +22,13 @@ namespace IPA.Loader
/// <param name="plugin">the plugin that cannot be disabled</param> /// <param name="plugin">the plugin that cannot be disabled</param>
public CannotRuntimeDisableException(PluginMetadata plugin) : base($"Cannot runtime disable plugin \"{plugin.Name}\" ({plugin.Id})") public CannotRuntimeDisableException(PluginMetadata plugin) : base($"Cannot runtime disable plugin \"{plugin.Name}\" ({plugin.Id})")
=> Plugin = plugin; => Plugin = plugin;
/// <summary>
/// Creats an exception with the given plugin metadata and message information.
/// </summary>
/// <param name="plugin">the plugin that cannot be disabled</param>
/// <param name="message">the message to associate with it</param>
public CannotRuntimeDisableException(PluginMetadata plugin, string message) : base($"{message} \"{plugin.Name}\" ({plugin.Id})")
=> Plugin = plugin;
/// <summary> /// <summary>
/// Creates an exception from a serialization context. Not currently implemented. /// Creates an exception from a serialization context. Not currently implemented.


+ 5
- 2
IPA.Loader/Loader/PluginManager.cs View File

@ -190,8 +190,11 @@ namespace IPA.Loader
return TaskEx6.FromException(new CannotRuntimeDisableException(exec.Executor.Metadata)); return TaskEx6.FromException(new CannotRuntimeDisableException(exec.Executor.Metadata));
var res = TaskEx.WhenAll(exec.Dependents.Select(d => Disable(d, alreadyDisabled))) var res = TaskEx.WhenAll(exec.Dependents.Select(d => Disable(d, alreadyDisabled)))
.ContinueWith(t => TaskEx.WhenAll(t, exec.Executor.Disable()), UnityMainThreadTaskScheduler.Default).Unwrap();
// The WhenAll above allows us to wait for the executor to disable, but still propagate errors
.ContinueWith(t => t.IsFaulted
? TaskEx.WhenAll(t, TaskEx6.FromException(
new CannotRuntimeDisableException(exec.Executor.Metadata, "Dependents cannot be disabled for plugin")))
: exec.Executor.Disable(), UnityMainThreadTaskScheduler.Default).Unwrap();
// We do not want to call the disable method if a dependent couldn't be disabled
// By scheduling on a UnityMainThreadScheduler, we ensure that Disable() is always called on the Unity main thread // By scheduling on a UnityMainThreadScheduler, we ensure that Disable() is always called on the Unity main thread
alreadyDisabled.Add(exec.Executor, res); alreadyDisabled.Add(exec.Executor, res);
return res; return res;


Loading…
Cancel
Save