Skip to content
Open
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions CustomizePlus/Core/Helpers/Base64Helper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using CustomizePlus.Core.Data;
using CustomizePlus.Templates.Data;
using CustomizePlus.Api.Data;
using CustomizePlus.Profiles;
using CustomizePlus.Profiles.Data;
using CustomizePlus.Templates;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -50,6 +54,33 @@ public static string ExportTemplateToBase64(Template template)
}
}

public static string ExportProfileToBase64(Profile profile)
{
// Does the same thing as before above method but turns the profile into a template first via IPCCharacterProfile
// same as is done over in the PCP Service functionality
try
{
var ipcProfile = IPCCharacterProfile.FromFullProfile(profile);
var template = new Template(ipcProfile);

var json = template.JsonSerialize();
var bytes = Encoding.UTF8.GetBytes(json.ToString(Formatting.None));
using var compressedStream = new MemoryStream();
using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
{
zipStream.WriteByte(Template.Version);
zipStream.Write(bytes, 0, bytes.Length);
}

return Convert.ToBase64String(compressedStream.ToArray());
}

catch
{
return string.Empty;
}
}

// Decompress a base64 encoded string to the given type and a prepended version byte if possible.
// On failure, data will be String error and version will be byte.MaxValue.
// Original by Ottermandias: OtterGui <3
Expand Down
39 changes: 37 additions & 2 deletions CustomizePlus/UI/Windows/MainWindow/Tabs/Profiles/ProfilePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OtterGui;
using OtterGui.Raii;
using OtterGui.Extensions;
using OtterGui.Log;
using System;
using System.Linq;
using System.Numerics;
Expand All @@ -13,6 +14,7 @@
using CustomizePlus.UI.Windows.Controls;
using CustomizePlus.Templates;
using CustomizePlus.Core.Data;
using CustomizePlus.Core.Helpers;
using CustomizePlus.Templates.Events;
using Penumbra.GameData.Actors;
using Penumbra.String;
Expand All @@ -21,6 +23,7 @@
using CustomizePlus.Core.Extensions;
using Dalamud.Interface.Components;
using OtterGui.Extensions;
using System.Windows.Forms;

namespace CustomizePlus.UI.Windows.MainWindow.Tabs.Profiles;

Expand All @@ -34,6 +37,8 @@ public class ProfilePanel
private readonly ActorAssignmentUi _actorAssignmentUi;
private readonly ActorManager _actorManager;
private readonly TemplateEditorEvent _templateEditorEvent;
private readonly PopupSystem _popupSystem;
private readonly Logger _logger;

private string? _newName;
private int? _newPriority;
Expand All @@ -54,7 +59,9 @@ public ProfilePanel(
TemplateEditorManager templateEditorManager,
ActorAssignmentUi actorAssignmentUi,
ActorManager actorManager,
TemplateEditorEvent templateEditorEvent)
TemplateEditorEvent templateEditorEvent,
PopupSystem popupSystem,
Logger logger)
{
_selector = selector;
_manager = manager;
Expand All @@ -64,6 +71,8 @@ public ProfilePanel(
_actorAssignmentUi = actorAssignmentUi;
_actorManager = actorManager;
_templateEditorEvent = templateEditorEvent;
_popupSystem = popupSystem;
_logger = logger;
}

public void Draw()
Expand Down Expand Up @@ -97,9 +106,20 @@ private HeaderDrawer.Button LockButton()
OnClick = () => _manager.SetWriteProtection(_selector.Selected!, true)
};

private HeaderDrawer.Button ExportToClipboardButton()
=> _selector.Selected == null
? HeaderDrawer.Button.Invisible
:new HeaderDrawer.Button {
Description = "Copy the current profile to your clipboard.",
Icon = FontAwesomeIcon.Copy,
OnClick = ExportToClipboard,
Visible = _selector.Selected != null,
Disabled = false
};

private void DrawHeader()
=> HeaderDrawer.Draw(SelectionName, 0, ImGui.GetColorU32(ImGuiCol.FrameBg),
0, LockButton(),
1, ExportToClipboardButton(), LockButton(),
HeaderDrawer.Button.IncognitoButton(_selector.IncognitoMode, v => _selector.IncognitoMode = v));

private void DrawMultiSelection()
Expand Down Expand Up @@ -248,6 +268,21 @@ private void DrawBasicSettings()
}
}

private void ExportToClipboard()
{
try
{
var data = Base64Helper.ExportProfileToBase64(_selector.Selected!);
Clipboard.SetText(data);
_popupSystem.ShowPopup(PopupSystem.Messages.ClipboardDataNotLongTerm);
}
catch (Exception ex)
{
_logger.Error($"Could not copy data from profile {_selector.Selected!.UniqueId} to clipboard: {ex}");
_popupSystem.ShowPopup(PopupSystem.Messages.ActionError);
}
}

private void DrawAddCharactersArea()
{
using (var style = ImRaii.PushStyle(ImGuiStyleVar.ButtonTextAlign, new Vector2(0, 0.5f)))
Expand Down