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:
65
MareSynchronos/Export/MareCharaFileData.cs
Normal file
65
MareSynchronos/Export/MareCharaFileData.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.FileCache;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronos.Export;
|
||||
|
||||
public record MareCharaFileData
|
||||
{
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string GlamourerData { get; set; } = string.Empty;
|
||||
public string CustomizePlusData { get; set; } = string.Empty;
|
||||
public string ManipulationData { get; set; } = string.Empty;
|
||||
public List<FileData> Files { get; set; } = new();
|
||||
public List<FileSwap> FileSwaps { get; set; } = new();
|
||||
|
||||
public MareCharaFileData() { }
|
||||
public MareCharaFileData(FileCacheManager manager, string description, CharacterCacheDto dto)
|
||||
{
|
||||
Description = description;
|
||||
|
||||
if (dto.GlamourerData.TryGetValue(ObjectKind.Player, out var glamourerData))
|
||||
{
|
||||
GlamourerData = glamourerData;
|
||||
}
|
||||
|
||||
CustomizePlusData = dto.CustomizePlusData;
|
||||
ManipulationData = dto.ManipulationData;
|
||||
|
||||
if (dto.FileReplacements.TryGetValue(ObjectKind.Player, out var fileReplacements))
|
||||
{
|
||||
foreach (var file in fileReplacements)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(file.FileSwapPath))
|
||||
{
|
||||
FileSwaps.Add(new FileSwap(file.GamePaths, file.FileSwapPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
var filePath = manager.GetFileCacheByHash(file.Hash)?.ResolvedFilepath;
|
||||
if (filePath != null)
|
||||
{
|
||||
Files.Add(new FileData(file.GamePaths, new FileInfo(filePath).Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ToByteArray()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(this));
|
||||
}
|
||||
|
||||
public static MareCharaFileData FromByteArray(byte[] data)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<MareCharaFileData>(Encoding.UTF8.GetString(data))!;
|
||||
}
|
||||
|
||||
public record FileSwap(IEnumerable<string> GamePaths, string FileSwapPath);
|
||||
|
||||
public record FileData(IEnumerable<string> GamePaths, long Length);
|
||||
}
|
||||
Reference in New Issue
Block a user