* 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>
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using Lumina.Extensions;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace MareSynchronos.Export;
|
|
|
|
public record MareCharaFileHeader(byte Version, MareCharaFileData CharaFileData)
|
|
{
|
|
public static readonly byte CurrentVersion = 1;
|
|
|
|
public byte Version { get; set; } = Version;
|
|
public MareCharaFileData CharaFileData { get; set; } = CharaFileData;
|
|
public string FilePath { get; private set; }
|
|
|
|
public void WriteToStream(BinaryWriter writer)
|
|
{
|
|
writer.Write('M');
|
|
writer.Write('C');
|
|
writer.Write('D');
|
|
writer.Write('F');
|
|
writer.Write(Version);
|
|
var charaFileDataArray = CharaFileData.ToByteArray();
|
|
writer.Write(charaFileDataArray.Length);
|
|
writer.Write(charaFileDataArray);
|
|
}
|
|
|
|
public static MareCharaFileHeader? FromBinaryReader(string path, BinaryReader reader)
|
|
{
|
|
var chars = new string(reader.ReadChars(4));
|
|
if (!string.Equals(chars, "MCDF", System.StringComparison.Ordinal)) throw new System.Exception("Not a Mare Chara File");
|
|
|
|
MareCharaFileHeader? decoded = null;
|
|
|
|
var version = reader.ReadByte();
|
|
if (version == 1)
|
|
{
|
|
var dataLength = reader.ReadInt32();
|
|
|
|
decoded = new(version, MareCharaFileData.FromByteArray(reader.ReadBytes(dataLength)));
|
|
decoded.FilePath = path;
|
|
}
|
|
|
|
return decoded;
|
|
}
|
|
|
|
public void AdvanceReaderToData(BinaryReader reader)
|
|
{
|
|
reader.ReadChars(4);
|
|
var version = reader.ReadByte();
|
|
if (version == 1)
|
|
{
|
|
var length = reader.ReadInt32();
|
|
_ = reader.ReadBytes(length);
|
|
}
|
|
}
|
|
}
|