Fix templates serializing incorrectly for clipboard copies
This commit is contained in:
@@ -2,25 +2,27 @@
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using CustomizePlus.Templates.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CustomizePlus.Core.Helpers;
|
||||
|
||||
//this is jank but I don't have time to rewrite it
|
||||
public static class Base64Helper
|
||||
{
|
||||
// Compress any type to a base64 encoding of its compressed json representation, prepended with a version byte.
|
||||
// Returns an empty string on failure.
|
||||
// Original by Ottermandias: OtterGui <3
|
||||
public static unsafe string ExportToBase64<T>(T obj, byte version)
|
||||
public static string ExportTemplateToBase64(Template template)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(obj, Formatting.None);
|
||||
var bytes = Encoding.UTF8.GetBytes(json);
|
||||
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.Write(new ReadOnlySpan<byte>(&version, 1));
|
||||
zipStream.WriteByte(Template.Version);
|
||||
zipStream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ public class TemplatePanel : IDisposable
|
||||
{
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(Base64Helper.ExportToBase64(_selector.Selected!, Constants.ConfigurationVersion));
|
||||
Clipboard.SetText(Base64Helper.ExportTemplateToBase64(_selector.Selected!));
|
||||
_popupSystem.ShowPopup(PopupSystem.Messages.ClipboardDataNotLongTerm);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user