IPC for YesAlready 1.4.x.x

This commit is contained in:
Liza 2023-11-07 20:07:22 +01:00
parent 60e3e4bdbc
commit 1021220064
Signed by: liza
GPG Key ID: 7199F8D727D55F67
4 changed files with 15 additions and 67 deletions

View File

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using LLib;
namespace Workshoppa.External; namespace Workshoppa.External;
@ -9,19 +8,15 @@ internal sealed class ExternalPluginHandler
{ {
private readonly DalamudPluginInterface _pluginInterface; private readonly DalamudPluginInterface _pluginInterface;
private readonly IPluginLog _pluginLog; private readonly IPluginLog _pluginLog;
private readonly YesAlreadyIpc _yesAlreadyIpc;
private readonly PandoraIpc _pandoraIpc; private readonly PandoraIpc _pandoraIpc;
private bool? _yesAlreadyState;
private bool? _pandoraState; private bool? _pandoraState;
public ExternalPluginHandler(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog) public ExternalPluginHandler(DalamudPluginInterface pluginInterface, IPluginLog pluginLog)
{ {
_pluginInterface = pluginInterface; _pluginInterface = pluginInterface;
_pluginLog = pluginLog; _pluginLog = pluginLog;
var dalamudReflector = new DalamudReflector(pluginInterface, framework, pluginLog);
_yesAlreadyIpc = new YesAlreadyIpc(dalamudReflector);
_pandoraIpc = new PandoraIpc(pluginInterface, pluginLog); _pandoraIpc = new PandoraIpc(pluginInterface, pluginLog);
} }
@ -43,8 +38,12 @@ internal sealed class ExternalPluginHandler
private void SaveYesAlreadyState() private void SaveYesAlreadyState()
{ {
_yesAlreadyState = _yesAlreadyIpc.DisableIfNecessary(); if (_pluginInterface.TryGetData<HashSet<string>>("YesAlready.StopRequests", out var data) &&
_pluginLog.Information($"Previous yesalready state: {_yesAlreadyState}"); !data.Contains(nameof(Workshoppa)))
{
_pluginLog.Debug("Disabling YesAlready");
data.Add(nameof(Workshoppa));
}
} }
private void SavePandoraState() private void SavePandoraState()
@ -76,15 +75,17 @@ internal sealed class ExternalPluginHandler
} }
Saved = false; Saved = false;
_yesAlreadyState = null;
_pandoraState = null; _pandoraState = null;
} }
private void RestoreYesAlready() private void RestoreYesAlready()
{ {
_pluginLog.Information($"Restoring previous yesalready state: {_yesAlreadyState}"); if (_pluginInterface.TryGetData<HashSet<string>>("YesAlready.StopRequests", out var data) &&
if (_yesAlreadyState == true) data.Contains(nameof(Workshoppa)))
_yesAlreadyIpc.Enable(); {
_pluginLog.Debug("Restoring YesAlready");
data.Remove(nameof(Workshoppa));
}
} }
private void RestorePandora() private void RestorePandora()

View File

@ -1,53 +0,0 @@
using System.Reflection;
using LLib;
namespace Workshoppa.External;
internal sealed class YesAlreadyIpc
{
private readonly DalamudReflector _dalamudReflector;
public YesAlreadyIpc(DalamudReflector dalamudReflector)
{
_dalamudReflector = dalamudReflector;
}
private object? GetConfiguration()
{
if (_dalamudReflector.TryGetDalamudPlugin("Yes Already", out var plugin))
{
var pluginService = plugin!.GetType().Assembly.GetType("YesAlready.Service");
return pluginService!.GetProperty("Configuration", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null);
}
return null;
}
public bool? DisableIfNecessary()
{
object? configuration = GetConfiguration();
if (configuration == null)
return null;
var property = configuration.GetType().GetProperty("Enabled")!;
bool enabled = (bool)property.GetValue(configuration)!;
if (enabled)
{
property.SetValue(configuration, false);
return true;
}
return false;
}
public void Enable()
{
object? configuration = GetConfiguration();
if (configuration == null)
return;
var property = configuration.GetType().GetProperty("Enabled")!;
property.SetValue(configuration, true);
}
}

View File

@ -65,7 +65,7 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin
_addonLifecycle = addonLifecycle; _addonLifecycle = addonLifecycle;
_chatGui = chatGui; _chatGui = chatGui;
_externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _framework, _pluginLog); _externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _pluginLog);
_configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration();
_workshopCache = new WorkshopCache(dataManager, _pluginLog); _workshopCache = new WorkshopCache(dataManager, _pluginLog);
_gameStrings = new(dataManager, _pluginLog); _gameStrings = new(dataManager, _pluginLog);

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<Version>3.4</Version> <Version>3.5</Version>
<LangVersion>11.0</LangVersion> <LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>