Use PluginWatchService for Glamournumbra too
This commit is contained in:
		| @@ -27,6 +27,9 @@ public sealed class IpcCallerGlamourer : DisposableMediatorSubscriberBase, IIpcC | |||||||
|     private readonly UnlockStateName _glamourerUnlockByName; |     private readonly UnlockStateName _glamourerUnlockByName; | ||||||
|     private readonly EventSubscriber<nint>? _glamourerStateChanged; |     private readonly EventSubscriber<nint>? _glamourerStateChanged; | ||||||
|  |  | ||||||
|  |     private bool _pluginLoaded; | ||||||
|  |     private Version _pluginVersion; | ||||||
|  |  | ||||||
|     private bool _shownGlamourerUnavailable = false; |     private bool _shownGlamourerUnavailable = false; | ||||||
|     private readonly uint LockCode = 0x626E7579; |     private readonly uint LockCode = 0x626E7579; | ||||||
|  |  | ||||||
| @@ -52,6 +55,18 @@ public sealed class IpcCallerGlamourer : DisposableMediatorSubscriberBase, IIpcC | |||||||
|         _glamourerStateChanged.Enable(); |         _glamourerStateChanged.Enable(); | ||||||
|  |  | ||||||
|         Mediator.Subscribe<DalamudLoginMessage>(this, s => _shownGlamourerUnavailable = false); |         Mediator.Subscribe<DalamudLoginMessage>(this, s => _shownGlamourerUnavailable = false); | ||||||
|  |  | ||||||
|  |         var plugin = _pi.InstalledPlugins.FirstOrDefault(p => p.InternalName.Equals("Glamourer", StringComparison.Ordinal)); | ||||||
|  |  | ||||||
|  |         _pluginLoaded = plugin?.IsLoaded ?? false; | ||||||
|  |         _pluginVersion = plugin?.Version ?? new(0, 0, 0, 0); | ||||||
|  |  | ||||||
|  |         Mediator.SubscribeKeyed<PluginChangeMessage>(this, "Glamourer", (msg) => | ||||||
|  |         { | ||||||
|  |              _pluginLoaded = msg.IsLoaded; | ||||||
|  |              _pluginVersion = msg.Version; | ||||||
|  |              CheckAPI(); | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected override void Dispose(bool disposing) |     protected override void Dispose(bool disposing) | ||||||
| @@ -69,9 +84,7 @@ public sealed class IpcCallerGlamourer : DisposableMediatorSubscriberBase, IIpcC | |||||||
|         bool apiAvailable = false; |         bool apiAvailable = false; | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
|             bool versionValid = (_pi.InstalledPlugins |             bool versionValid = _pluginLoaded && _pluginVersion >= new Version(1, 0, 6, 1); | ||||||
|                 .FirstOrDefault(p => string.Equals(p.InternalName, "Glamourer", StringComparison.OrdinalIgnoreCase)) |  | ||||||
|                 ?.Version ?? new Version(0, 0, 0, 0)) >= new Version(1, 0, 6, 1); |  | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 var version = _glamourerApiVersions.Invoke(); |                 var version = _glamourerApiVersions.Invoke(); | ||||||
|   | |||||||
| @@ -53,6 +53,9 @@ public sealed class IpcCallerPenumbra : DisposableMediatorSubscriberBase, IIpcCa | |||||||
|     private readonly ResolvePlayerPathsAsync _penumbraResolvePaths; |     private readonly ResolvePlayerPathsAsync _penumbraResolvePaths; | ||||||
|     private readonly GetGameObjectResourcePaths _penumbraResourcePaths; |     private readonly GetGameObjectResourcePaths _penumbraResourcePaths; | ||||||
|  |  | ||||||
|  |     private bool _pluginLoaded; | ||||||
|  |     private Version _pluginVersion; | ||||||
|  |  | ||||||
|     public IpcCallerPenumbra(ILogger<IpcCallerPenumbra> logger, IDalamudPluginInterface pi, DalamudUtilService dalamudUtil, |     public IpcCallerPenumbra(ILogger<IpcCallerPenumbra> logger, IDalamudPluginInterface pi, DalamudUtilService dalamudUtil, | ||||||
|         MareMediator mareMediator, RedrawManager redrawManager) : base(logger, mareMediator) |         MareMediator mareMediator, RedrawManager redrawManager) : base(logger, mareMediator) | ||||||
|     { |     { | ||||||
| @@ -92,6 +95,18 @@ public sealed class IpcCallerPenumbra : DisposableMediatorSubscriberBase, IIpcCa | |||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         Mediator.Subscribe<DalamudLoginMessage>(this, (msg) => _shownPenumbraUnavailable = false); |         Mediator.Subscribe<DalamudLoginMessage>(this, (msg) => _shownPenumbraUnavailable = false); | ||||||
|  |  | ||||||
|  |         var plugin = _pi.InstalledPlugins.FirstOrDefault(p => p.InternalName.Equals("Penumbra", StringComparison.Ordinal)); | ||||||
|  |  | ||||||
|  |         _pluginLoaded = plugin?.IsLoaded ?? false; | ||||||
|  |         _pluginVersion = plugin?.Version ?? new(0, 0, 0, 0); | ||||||
|  |  | ||||||
|  |         Mediator.SubscribeKeyed<PluginChangeMessage>(this, "Penumbra", (msg) => | ||||||
|  |         { | ||||||
|  |              _pluginLoaded = msg.IsLoaded; | ||||||
|  |              _pluginVersion = msg.Version; | ||||||
|  |              CheckAPI(); | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public bool APIAvailable { get; private set; } = false; |     public bool APIAvailable { get; private set; } = false; | ||||||
| @@ -101,10 +116,7 @@ public sealed class IpcCallerPenumbra : DisposableMediatorSubscriberBase, IIpcCa | |||||||
|         bool penumbraAvailable = false; |         bool penumbraAvailable = false; | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
|             var penumbraVersion = (_pi.InstalledPlugins |             penumbraAvailable = _pluginLoaded && _pluginVersion >= new Version(1, 0, 1, 0); | ||||||
|                 .FirstOrDefault(p => string.Equals(p.InternalName, "Penumbra", StringComparison.OrdinalIgnoreCase)) |  | ||||||
|                 ?.Version ?? new Version(0, 0, 0, 0)); |  | ||||||
|             penumbraAvailable = penumbraVersion >= new Version(1, 0, 1, 0); |  | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 penumbraAvailable &= _penumbraEnabled.Invoke(); |                 penumbraAvailable &= _penumbraEnabled.Invoke(); | ||||||
|   | |||||||
| @@ -58,8 +58,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber | |||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         _marePluginEnabled = pi.InstalledPlugins.Any(p => p.InternalName == "MareSynchronos" && p.IsLoaded); |         _marePluginEnabled = pi.InstalledPlugins.Any(p => p.InternalName == "MareSynchronos" && p.IsLoaded); | ||||||
|         Mediator.Subscribe<PluginChangeMessage>(this, p => { |         Mediator.SubscribeKeyed<PluginChangeMessage>(this, "MareSynchronos", p => { | ||||||
|             if (p.InternalName == "MareSynchronos") |  | ||||||
|             _marePluginEnabled = p.IsLoaded; |             _marePluginEnabled = p.IsLoaded; | ||||||
|             HandleMareImpersonation(); |             HandleMareImpersonation(); | ||||||
|         }); |         }); | ||||||
|   | |||||||
| @@ -100,6 +100,6 @@ public record PairDataAnalyzedMessage(string UID) : KeyedMessage(UID); | |||||||
| public record GameObjectHandlerCreatedMessage(GameObjectHandler GameObjectHandler, bool OwnedObject) : MessageBase; | public record GameObjectHandlerCreatedMessage(GameObjectHandler GameObjectHandler, bool OwnedObject) : MessageBase; | ||||||
| public record GameObjectHandlerDestroyedMessage(GameObjectHandler GameObjectHandler, bool OwnedObject) : MessageBase; | public record GameObjectHandlerDestroyedMessage(GameObjectHandler GameObjectHandler, bool OwnedObject) : MessageBase; | ||||||
|  |  | ||||||
| public record PluginChangeMessage(string InternalName, Version Version, bool IsLoaded) : MessageBase; | public record PluginChangeMessage(string InternalName, Version Version, bool IsLoaded) : KeyedMessage(InternalName); | ||||||
| #pragma warning restore S2094 | #pragma warning restore S2094 | ||||||
| #pragma warning restore MA0048 // File name must match type name | #pragma warning restore MA0048 // File name must match type name | ||||||
| @@ -1,13 +1,13 @@ | |||||||
| using Dalamud.Plugin; | using Dalamud.Plugin; | ||||||
| using MareSynchronos.API.Data; | using MareSynchronos.API.Data; | ||||||
| using MareSynchronos.API.Data.Comparer; | using MareSynchronos.API.Data.Comparer; | ||||||
| using MareSynchronos.MareConfiguration; | using MareSynchronos.PlayerData.Pairs; | ||||||
| using MareSynchronos.Services.Mediator; | using MareSynchronos.Services.Mediator; | ||||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||||
| using System.Collections.Concurrent; | using System.Collections.Concurrent; | ||||||
| using CapturedPluginState = (string InternalName, System.Version Version, bool IsLoaded); | using CapturedPluginState = (string InternalName, System.Version Version, bool IsLoaded); | ||||||
|  |  | ||||||
| namespace MareSynchronos.PlayerData.Pairs; | namespace MareSynchronos.Services; | ||||||
|  |  | ||||||
| /* Parts of this code from ECommons DalamudReflector | /* Parts of this code from ECommons DalamudReflector | ||||||
|  |  | ||||||
| @@ -42,22 +42,20 @@ public class PluginWatcherService : MediatorSubscriberBase | |||||||
|  |  | ||||||
|     private CapturedPluginState[] _prevInstalledPluginState = []; |     private CapturedPluginState[] _prevInstalledPluginState = []; | ||||||
|  |  | ||||||
|     private readonly static System.Version VersionZero = new(0, 0, 0, 0); |     private static bool ExposedPluginsEqual(IEnumerable<IExposedPlugin> plugins, IEnumerable<CapturedPluginState> other) | ||||||
|  |  | ||||||
|     private bool ExposedPluginsEqual(IEnumerable<IExposedPlugin> plugins, IEnumerable<CapturedPluginState> other) |  | ||||||
|     { |     { | ||||||
|         if(plugins.Count() != other.Count()) return false; |         if (plugins.Count() != other.Count()) return false; | ||||||
|         var enumeratorOriginal = plugins.GetEnumerator(); |         var enumeratorOriginal = plugins.GetEnumerator(); | ||||||
|         var enumeratorOther = other.GetEnumerator(); |         var enumeratorOther = other.GetEnumerator(); | ||||||
|         while(true) |         while (true) | ||||||
|         { |         { | ||||||
|             var move1 = enumeratorOriginal.MoveNext(); |             var move1 = enumeratorOriginal.MoveNext(); | ||||||
|             var move2 = enumeratorOther.MoveNext(); |             var move2 = enumeratorOther.MoveNext(); | ||||||
|             if(move1 != move2) return false; |             if (move1 != move2) return false; | ||||||
|             if(move1 == false) return true; |             if (move1 == false) return true; | ||||||
|             if(enumeratorOriginal.Current.IsLoaded != enumeratorOther.Current.IsLoaded) return false; |             if (enumeratorOriginal.Current.IsLoaded != enumeratorOther.Current.IsLoaded) return false; | ||||||
|             if(enumeratorOriginal.Current.Version != enumeratorOther.Current.Version) return false; |             if (enumeratorOriginal.Current.Version != enumeratorOther.Current.Version) return false; | ||||||
|             if(enumeratorOriginal.Current.InternalName != enumeratorOther.Current.InternalName) return false; |             if (enumeratorOriginal.Current.InternalName != enumeratorOther.Current.InternalName) return false; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -65,7 +63,8 @@ public class PluginWatcherService : MediatorSubscriberBase | |||||||
|     { |     { | ||||||
|         _pluginInterface = pluginInterface; |         _pluginInterface = pluginInterface; | ||||||
|  |  | ||||||
|         Mediator.Subscribe<PriorityFrameworkUpdateMessage>(this, (_) => { |         Mediator.Subscribe<PriorityFrameworkUpdateMessage>(this, (_) => | ||||||
|  |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 Update(); |                 Update(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Loporrit
					Loporrit