Skip to content

Commit

Permalink
Fix failing shutdown with already shutdown monkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Nov 22, 2024
1 parent 4ab3717 commit 76bb700
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion MonkeyLoader/Meta/IShutdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ public static class ShutdownEnumerableExtensions
/// Calls the <see cref="IShutdown.Shutdown"/> method on all elements of the collection,
/// aggregating their success state as an 'all'.
/// </summary>
/// <remarks>
/// Already <see cref="IShutdown.ShutdownRan">shut down</see> elements are ignored.
/// </remarks>
/// <param name="shutdowns">The <see cref="IShutdown"/> instances to process.</param>
/// <param name="applicationExiting">Whether the shutdown was caused by the application exiting.</param>
/// <returns><c>true</c> if all instances successfully shut down, <c>false</c> otherwise.</returns>
public static bool ShutdownAll(this IEnumerable<IShutdown> shutdowns, bool applicationExiting)
{
var success = true;

foreach (var shutdown in shutdowns)
foreach (var shutdown in shutdowns.Where(shutdown => !shutdown.ShutdownRan))
success &= shutdown.Shutdown(applicationExiting);

return success;
Expand Down
5 changes: 3 additions & 2 deletions MonkeyLoader/Patching/MonkeyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ public bool Shutdown(bool applicationExiting)

/// <inheritdoc/>
/// <remarks>
/// <i>Format:</i> <c>{<see cref="Mod">Mod</see>.<see cref="Mod.Title">Title</see>}/{<see cref="Name">Name</see>}</c>
/// <i>Format:</i> <c>{<see cref="Mod">Mod</see>.<see cref="Mod.Title">Title</see>}/{<see cref="Name">Name</see>}
/// ({(<see cref="Ran">Ran</see> ? (<see cref="ShutdownRan">ShutdownRan</see> ? "Ended" : (<see cref="Enabled">Enabled</see> ? "Active" : "Inactive")) : "Pending")})</c>
/// </remarks>
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<TMonkey>(Type type, Mod mod) where TMonkey : IMonkey
{
Expand Down

0 comments on commit 76bb700

Please sign in to comment.