From 76bb700e1e3bab582ff79c1fec03ba657a179a8d Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Fri, 22 Nov 2024 22:17:34 +0100 Subject: [PATCH] Fix failing shutdown with already shutdown monkeys --- MonkeyLoader/Meta/IShutdown.cs | 5 ++++- MonkeyLoader/Patching/MonkeyBase.cs | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/MonkeyLoader/Meta/IShutdown.cs b/MonkeyLoader/Meta/IShutdown.cs index 849f13d..bfddde8 100644 --- a/MonkeyLoader/Meta/IShutdown.cs +++ b/MonkeyLoader/Meta/IShutdown.cs @@ -23,6 +23,9 @@ public static class ShutdownEnumerableExtensions /// Calls the method on all elements of the collection, /// aggregating their success state as an 'all'. /// + /// + /// Already shut down elements are ignored. + /// /// The instances to process. /// Whether the shutdown was caused by the application exiting. /// true if all instances successfully shut down, false otherwise. @@ -30,7 +33,7 @@ public static bool ShutdownAll(this IEnumerable shutdowns, bool appli { var success = true; - foreach (var shutdown in shutdowns) + foreach (var shutdown in shutdowns.Where(shutdown => !shutdown.ShutdownRan)) success &= shutdown.Shutdown(applicationExiting); return success; diff --git a/MonkeyLoader/Patching/MonkeyBase.cs b/MonkeyLoader/Patching/MonkeyBase.cs index 8078666..5783049 100644 --- a/MonkeyLoader/Patching/MonkeyBase.cs +++ b/MonkeyLoader/Patching/MonkeyBase.cs @@ -209,9 +209,10 @@ public bool Shutdown(bool applicationExiting) /// /// - /// Format: {Mod.Title}/{Name} + /// Format: {Mod.Title}/{Name} + /// ({(Ran ? (ShutdownRan ? "Ended" : (Enabled ? "Active" : "Inactive")) : "Pending")}) /// - public override string ToString() => $"{Mod.Title}/{Name}"; + public override string ToString() => $"{Mod.Title}/{Name} ({(Ran ? (ShutdownRan ? "Ended" : (Enabled ? "Active" : "Inactive")) : "Pending")})"; internal static TMonkey GetInstance(Type type, Mod mod) where TMonkey : IMonkey {