diff --git a/CustomizePlus/Api/CustomizePlusIpc.cs b/CustomizePlus/Api/CustomizePlusIpc.cs index c874956..8b609aa 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.cs @@ -14,6 +14,7 @@ using Dalamud.Plugin; using Dalamud.Plugin.Ipc; using Newtonsoft.Json; +using System.Linq; namespace CustomizePlus.Api { @@ -24,6 +25,7 @@ public class CustomizePlusIpc : IDisposable 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; @@ -36,6 +38,7 @@ public class CustomizePlusIpc : IDisposable internal ICallGateProvider? ProviderSetProfileToCharacter; internal ICallGateProvider? ProviderGetProfileFromCharacter; internal ICallGateProvider<(int, int)>? ProviderGetApiVersion; + internal ICallGateProvider? ProviderGetProfiles; public CustomizePlusIpc(IObjectTable objectTable, DalamudPluginInterface pluginInterface) { @@ -57,6 +60,7 @@ private void DisposeProviders() ProviderRevertCharacter?.UnregisterAction(); ProviderGetApiVersion?.UnregisterFunc(); ProviderOnProfileUpdate?.UnregisterFunc(); + ProviderGetProfiles?.UnregisterFunc(); } private void InitializeProviders() @@ -113,6 +117,16 @@ private void InitializeProviders() { PluginLog.Error(ex, $"Error registering IPC provider for {OnProfileUpdateLabel}."); } + + try + { + ProviderGetProfiles = _pluginInterface.GetIpcProvider(GetProfilesLabel); + ProviderGetProfiles.RegisterFunc(GetProfiles); + } + catch (Exception ex) + { + PluginLog.Error(ex, $"Error registering IPC provider for {GetProfiles}."); + } } public void OnProfileUpdate(CharacterProfile? profile) @@ -179,6 +193,11 @@ private void RevertCharacter(Character? character) 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);