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