Chara file data export (#38)

* add rudimentary saving of chara file data

* fix building

* working prototype for MCDF import and application

* adjust code to use streams

* rename cache -> storage
add ui for import/export mcdf

* minor wording adjustments, version bump

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
Co-authored-by: Stanley Dimant <stanley.dimant@varian.com>
This commit is contained in:
rootdarkarchon
2023-01-23 12:56:43 +01:00
committed by GitHub
parent 1c95a6d40e
commit 7a8655f6b1
15 changed files with 664 additions and 51 deletions

View File

@@ -13,6 +13,7 @@ using MareSynchronos.Utils;
using MareSynchronos.WebAPI.Utils;
using Dalamud.Utility;
using Newtonsoft.Json;
using MareSynchronos.Export;
namespace MareSynchronos.UI;
@@ -22,6 +23,7 @@ public class SettingsUi : Window, IDisposable
private readonly Configuration _configuration;
private readonly WindowSystem _windowSystem;
private readonly ApiController _apiController;
private readonly MareCharaFileManager _mareCharaFileManager;
private readonly UiShared _uiShared;
public CharacterCacheDto LastCreatedCharacterData { private get; set; }
@@ -32,9 +34,11 @@ public class SettingsUi : Window, IDisposable
private bool _openPopupOnAddition;
private bool _hideInfoMessages;
private bool _disableOptionalPluginsWarnings;
private bool _wasOpen = false;
public SettingsUi(WindowSystem windowSystem,
UiShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos Settings")
UiShared uiShared, Configuration configuration, ApiController apiController,
MareCharaFileManager mareCharaFileManager) : base("Mare Synchronos Settings")
{
Logger.Verbose("Creating " + nameof(SettingsUi));
@@ -47,17 +51,36 @@ public class SettingsUi : Window, IDisposable
_configuration = configuration;
_windowSystem = windowSystem;
_apiController = apiController;
_mareCharaFileManager = mareCharaFileManager;
_uiShared = uiShared;
_openPopupOnAddition = _configuration.OpenPopupOnAdd;
_hideInfoMessages = _configuration.HideInfoMessages;
_disableOptionalPluginsWarnings = _configuration.DisableOptionalPluginWarnings;
_uiShared.GposeStart += _uiShared_GposeStart;
_uiShared.GposeEnd += _uiShared_GposeEnd;
windowSystem.AddWindow(this);
}
private void _uiShared_GposeEnd()
{
IsOpen = _wasOpen;
}
private void _uiShared_GposeStart()
{
_wasOpen = IsOpen;
IsOpen = false;
}
public void Dispose()
{
Logger.Verbose("Disposing " + nameof(SettingsUi));
_uiShared.GposeStart -= _uiShared_GposeStart;
_uiShared.GposeEnd -= _uiShared_GposeEnd;
_windowSystem.RemoveWindow(this);
}
@@ -87,9 +110,9 @@ public class SettingsUi : Window, IDisposable
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("Cache Settings"))
if (ImGui.BeginTabItem("Export & Storage"))
{
DrawFileCacheSettings();
DrawFileStorageSettings();
ImGui.EndTabItem();
}
@@ -140,6 +163,7 @@ public class SettingsUi : Window, IDisposable
}
_lastTab = "General";
UiShared.FontText("Notes", _uiShared.UidFont);
if (UiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard"))
{
ImGui.SetClipboardText(_uiShared.GetNotes());
@@ -162,7 +186,6 @@ public class SettingsUi : Window, IDisposable
{
UiShared.ColorTextWrapped("Attempt to import notes from clipboard failed. Check formatting and try again", ImGuiColors.DalamudRed);
}
ImGui.Separator();
if (ImGui.Checkbox("Open Notes Popup on user addition", ref _openPopupOnAddition))
{
_apiController.LastAddedUser = null;
@@ -170,6 +193,9 @@ public class SettingsUi : Window, IDisposable
_configuration.Save();
}
UiShared.DrawHelpText("This will open a popup that allows you to set the notes for a user after successfully adding them to your individual pairs.");
ImGui.Separator();
UiShared.FontText("Server Messages", _uiShared.UidFont);
if (ImGui.Checkbox("Hide Server Info Messages", ref _hideInfoMessages))
{
_configuration.HideInfoMessages = _hideInfoMessages;
@@ -520,7 +546,7 @@ public class SettingsUi : Window, IDisposable
if (!_configuration.FullPause)
{
UiShared.ColorTextWrapped("Note: to change servers you need to disconnect from your current Mare Synchronos server.", ImGuiColors.DalamudYellow);
UiShared.ColorTextWrapped("Note: to change servers or your secret key you need to disconnect from your current Mare Synchronos server.", ImGuiColors.DalamudYellow);
}
var marePaused = _configuration.FullPause;
@@ -546,6 +572,10 @@ public class SettingsUi : Window, IDisposable
_uiShared.DrawServiceSelection(() => { });
}
ImGui.Separator();
UiShared.FontText("Debug", _uiShared.UidFont);
if (UiShared.IconTextButton(FontAwesomeIcon.Copy, "[DEBUG] Copy Last created Character Data to clipboard"))
{
if (LastCreatedCharacterData != null)
@@ -560,6 +590,9 @@ public class SettingsUi : Window, IDisposable
UiShared.AttachToolTip("Use this when reporting mods being rejected from the server.");
}
private string _charaFileSavePath = string.Empty;
private string _charaFileLoadPath = string.Empty;
private void DrawBlockedTransfers()
{
_lastTab = "BlockedTransfers";
@@ -675,15 +708,77 @@ public class SettingsUi : Window, IDisposable
}
}
private void DrawFileCacheSettings()
private bool _readExport = false;
private string _exportDescription = string.Empty;
private void DrawFileStorageSettings()
{
_lastTab = "FileCache";
UiShared.FontText("Export MCDF", _uiShared.UidFont);
UiShared.TextWrapped("This feature allows you to pack your character into a MCDF file and manually send it to other people. MCDF files can officially only be imported during GPose through Mare. " +
"Be aware that the possibility exists that people write unoffocial custom exporters to extract the containing data.");
ImGui.Checkbox("##readExport", ref _readExport);
ImGui.SameLine();
UiShared.TextWrapped("I understand that by exporting my character data and sending it to other people I am giving away my current character appearance irrevocably. People I am sharing my data with have the ability to share it with other people without limitations.");
if (_readExport)
{
if (!_mareCharaFileManager.CurrentlyWorking)
{
ImGui.Indent();
ImGui.InputTextWithHint("Export Descriptor", "This description will be shown on loading the data", ref _exportDescription, 255);
if (UiShared.IconTextButton(FontAwesomeIcon.Save, "Export Character as MCDF"))
{
_uiShared.FileDialogManager.SaveFileDialog("Export Character to file", ".mcdf", "export.mcdf", ".mcdf", (success, path) =>
{
if (!success) return;
Task.Run(() =>
{
try
{
_mareCharaFileManager.SaveMareCharaFile(LastCreatedCharacterData, _exportDescription, path);
_exportDescription = string.Empty;
}
catch (Exception ex)
{
Logger.Error("Error saving data", ex);
}
});
});
}
ImGui.Unindent();
}
else
{
UiShared.ColorTextWrapped("Export in progress", ImGuiColors.DalamudYellow);
}
}
bool openInGpose = _configuration.OpenGposeImportOnGposeStart;
if (ImGui.Checkbox("Open MCDF import window when GPose loads", ref openInGpose))
{
_configuration.OpenGposeImportOnGposeStart = openInGpose;
_configuration.Save();
}
UiShared.DrawHelpText("This will automatically open the import menu when loading into Gpose. If unchecked you can open the menu manually with /mare gpose");
ImGui.Separator();
UiShared.FontText("Storage", _uiShared.UidFont);
UiShared.TextWrapped("Mare stores downloaded files from paired people permanently. This is to improve loading performance and requiring less downloads. " +
"The storage governs itself by clearing data beyond the set storage size. Please set the storage size accordingly. It is not necessary to manually clear the storage.");
_uiShared.DrawFileScanState();
_uiShared.DrawTimeSpanBetweenScansSetting();
_uiShared.DrawCacheDirectorySetting();
ImGui.Text($"Local cache size: {UiShared.ByteToString(_uiShared.FileCacheSize)}");
ImGui.Text($"Local storage size: {UiShared.ByteToString(_uiShared.FileCacheSize)}");
ImGui.SameLine();
if (ImGui.Button("Clear local cache"))
if (ImGui.Button("Clear local storage"))
{
if (UiShared.CtrlPressed())
{
@@ -699,7 +794,7 @@ public class SettingsUi : Window, IDisposable
}
}
UiShared.AttachToolTip("You normally do not need to do this. This will solely remove all downloaded data from all players and will require you to re-download everything again." + Environment.NewLine
+ "Mares Cache is self-clearing and will not surpass the limit you have set it to." + Environment.NewLine
+ "Mares storage is self-clearing and will not surpass the limit you have set it to." + Environment.NewLine
+ "If you still think you need to do this hold CTRL while pressing the button.");
}