Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Added new IPC method: get list of profiles #219

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CustomizePlus/Api/CustomizePlusIpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Dalamud.Plugin;
using Dalamud.Plugin.Ipc;
using Newtonsoft.Json;
using System.Linq;

namespace CustomizePlus.Api
{
Expand All @@ -24,6 +25,7 @@
public const string SetProfileToCharacterLabel = $"CustomizePlus.{nameof(SetProfileToCharacter)}";
public const string RevertCharacterLabel = $"CustomizePlus.{nameof(RevertCharacter)}";
public const string OnProfileUpdateLabel = $"CustomizePlus.{nameof(OnProfileUpdate)}";
public const string GetProfilesLabel = $"CustomizePlus.{nameof(GetProfiles)}";
public static readonly (int, int) ApiVersion = (3, 0);
private readonly IObjectTable _objectTable;
private readonly DalamudPluginInterface _pluginInterface;
Expand All @@ -36,6 +38,7 @@
internal ICallGateProvider<string, Character?, object>? ProviderSetProfileToCharacter;
internal ICallGateProvider<Character?, string?>? ProviderGetProfileFromCharacter;
internal ICallGateProvider<(int, int)>? ProviderGetApiVersion;
internal ICallGateProvider<string[]>? ProviderGetProfiles;

public CustomizePlusIpc(IObjectTable objectTable, DalamudPluginInterface pluginInterface)
{
Expand All @@ -57,11 +60,12 @@
ProviderRevertCharacter?.UnregisterAction();
ProviderGetApiVersion?.UnregisterFunc();
ProviderOnProfileUpdate?.UnregisterFunc();
ProviderGetProfiles?.UnregisterFunc();
}

private void InitializeProviders()
{
PluginLog.Debug("Initializing c+ ipc providers.");

Check warning on line 68 in CustomizePlus/Api/CustomizePlusIpc.cs

View workflow job for this annotation

GitHub Actions / build

'PluginLog' is obsolete: 'Static PluginLog will be removed in API 10. Developers should use IPluginLog.'
try
{
ProviderGetApiVersion = _pluginInterface.GetIpcProvider<(int, int)>(ProviderApiVersionLabel);
Expand All @@ -69,7 +73,7 @@
}
catch (Exception ex)
{
PluginLog.Error(ex, $"Error registering IPC provider for {ProviderApiVersionLabel}.");

Check warning on line 76 in CustomizePlus/Api/CustomizePlusIpc.cs

View workflow job for this annotation

GitHub Actions / build

'PluginLog' is obsolete: 'Static PluginLog will be removed in API 10. Developers should use IPluginLog.'
}

try
Expand All @@ -80,7 +84,7 @@
}
catch (Exception ex)
{
PluginLog.Error(ex, $"Error registering IPC provider for {GetProfileFromCharacterLabel}.");

Check warning on line 87 in CustomizePlus/Api/CustomizePlusIpc.cs

View workflow job for this annotation

GitHub Actions / build

'PluginLog' is obsolete: 'Static PluginLog will be removed in API 10. Developers should use IPluginLog.'
}

try
Expand Down Expand Up @@ -113,6 +117,16 @@
{
PluginLog.Error(ex, $"Error registering IPC provider for {OnProfileUpdateLabel}.");
}

try
{
ProviderGetProfiles = _pluginInterface.GetIpcProvider<string[]>(GetProfilesLabel);
ProviderGetProfiles.RegisterFunc(GetProfiles);
}
catch (Exception ex)
{
PluginLog.Error(ex, $"Error registering IPC provider for {GetProfiles}.");
}
}

public void OnProfileUpdate(CharacterProfile? profile)
Expand Down Expand Up @@ -179,6 +193,11 @@
Plugin.ProfileManager.RemoveTemporaryProfile(character.Address);
}

private string[] GetProfiles()
{
return Plugin.ProfileManager.Profiles.Select(JsonConvert.SerializeObject).ToArray();
}

private string GetBase64String(string data)
{
var json = JsonConvert.SerializeObject(data, Formatting.None);
Expand Down
Loading