From fc582aa4135cdf89f9eb4cb235068cb403b4b242 Mon Sep 17 00:00:00 2001 From: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com> Date: Sun, 14 Apr 2024 00:08:33 +0200 Subject: [PATCH] Add "Extended Data Size" field to card properties --- src/KKManager.Core/Data/Cards/AI/AiCard.cs | 6 ++++-- src/KKManager.Core/Data/Cards/AI/AiCoordCard.cs | 11 +++++++---- src/KKManager.Core/Data/Cards/Card.cs | 6 ++++-- src/KKManager.Core/Data/Cards/EC/EmoCard.cs | 6 ++++-- src/KKManager.Core/Data/Cards/HC/HoneyCoomCard.cs | 14 ++++++++++++-- src/KKManager.Core/Data/Cards/KK/KoiCard.cs | 6 ++++-- src/KKManager.Core/Data/Cards/KK/KoiCoordCard.cs | 11 +++++++---- src/KKManager.Core/Data/Cards/KKS/KoiSunCard.cs | 8 +++++--- src/KKManager.Core/Data/Cards/RG/RoomGirlCard.cs | 6 ++++-- 9 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/KKManager.Core/Data/Cards/AI/AiCard.cs b/src/KKManager.Core/Data/Cards/AI/AiCard.cs index 9554e76..91d5e58 100644 --- a/src/KKManager.Core/Data/Cards/AI/AiCard.cs +++ b/src/KKManager.Core/Data/Cards/AI/AiCard.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Drawing; using System.IO; +using KKManager.Util; using MessagePack; namespace KKManager.Data.Cards.AI @@ -49,8 +50,9 @@ public static AiCard ParseAiChara(FileInfo file, BinaryReader reader, CardType g var parameterBytes = reader.ReadBytes((int)info.size); extData = MessagePackSerializer.Deserialize>(parameterBytes); } + var extendedSize = info != null ? Util.FileSize.FromBytes((int)info.size) : Util.FileSize.Empty; - var card = new AiCard(file, gameType, extData, loadVersion) + var card = new AiCard(file, gameType, extData, extendedSize, loadVersion) { Language = language, UserID = userID, @@ -105,7 +107,7 @@ public string GetPersonalityName(int personality) return KKManager.Properties.Resources.Unknown; } - public AiCard(FileInfo cardFile, CardType type, Dictionary extended, Version loadVersion) : base(cardFile, type, extended, loadVersion) + public AiCard(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, Version loadVersion) : base(cardFile, type, extended, extendedSize, loadVersion) { } } diff --git a/src/KKManager.Core/Data/Cards/AI/AiCoordCard.cs b/src/KKManager.Core/Data/Cards/AI/AiCoordCard.cs index b12f1c7..8e2dd75 100644 --- a/src/KKManager.Core/Data/Cards/AI/AiCoordCard.cs +++ b/src/KKManager.Core/Data/Cards/AI/AiCoordCard.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Drawing; using System.IO; +using KKManager.Util; using MessagePack; namespace KKManager.Data.Cards.KK @@ -21,12 +22,13 @@ public static Card ParseAiClothes(FileInfo file, BinaryReader reader, CardType g //load clothes and accs from the bytes array var _ = reader.ReadBytes(num); - var extended = TryReadExtData(reader); + var extended = TryReadExtData(reader, out var extendedSize); - return new AiCoordCard(file, gameType, extended, loadVersion, coordinateName, language); + return new AiCoordCard(file, gameType, extended, Util.FileSize.FromBytes(extendedSize), loadVersion, coordinateName, language); } - private static Dictionary TryReadExtData(BinaryReader br) + private static Dictionary TryReadExtData(BinaryReader br, out int size) { + size = 0; try { var marker = br.ReadString(); @@ -36,6 +38,7 @@ private static Dictionary TryReadExtData(BinaryReader br) if (marker == "KKEx" /*&& version == DataVersion*/ && length > 0) { + size = length; var bytes = br.ReadBytes(length); return MessagePackSerializer.Deserialize>(bytes); } @@ -48,7 +51,7 @@ private static Dictionary TryReadExtData(BinaryReader br) return null; } - public AiCoordCard(FileInfo cardFile, CardType type, Dictionary extended, Version version, string coordinateName, int language) : base(cardFile, type, extended, version) + public AiCoordCard(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, Version version, string coordinateName, int language) : base(cardFile, type, extended, extendedSize, version) { Name = coordinateName; Language = language; diff --git a/src/KKManager.Core/Data/Cards/Card.cs b/src/KKManager.Core/Data/Cards/Card.cs index 516a85a..bacefb8 100644 --- a/src/KKManager.Core/Data/Cards/Card.cs +++ b/src/KKManager.Core/Data/Cards/Card.cs @@ -21,10 +21,11 @@ public abstract class Card : IFileInfoBase [ReadOnly(true)] public virtual string DataID { get; protected set; } public Version Version { get; } - //[Browsable(false)] [DisplayName("Extended Data (plugins)")] [TypeConverter(typeof(DictionaryTypeConverter))] public Dictionary Extended { get; } + [DisplayName("Extended Data Size")] + public FileSize ExtendedSize { get; } [ReadOnly(true)] public string[] MissingZipmods { get; set; } [ReadOnly(true)] public string[] MissingPlugins { get; set; } @@ -57,12 +58,13 @@ public virtual Image GetCardFaceImage() } } - internal Card(FileInfo cardFile, CardType type, Dictionary extended, Version version) + internal Card(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, Version version) { Location = cardFile ?? throw new ArgumentNullException(nameof(cardFile)); Version = version ?? throw new ArgumentNullException(nameof(version)); Type = type; Extended = extended ?? new Dictionary(); + ExtendedSize = extendedSize; FileSize = Util.FileSize.FromBytes(cardFile.Length).ToString(); } diff --git a/src/KKManager.Core/Data/Cards/EC/EmoCard.cs b/src/KKManager.Core/Data/Cards/EC/EmoCard.cs index 00fd2c5..7f0f2b0 100644 --- a/src/KKManager.Core/Data/Cards/EC/EmoCard.cs +++ b/src/KKManager.Core/Data/Cards/EC/EmoCard.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Drawing; using System.IO; +using KKManager.Util; using MessagePack; namespace KKManager.Data.Cards.EC @@ -16,7 +17,7 @@ public class EmoCard : Card public ChaFileParameter Parameter { get; } - private EmoCard(FileInfo cardFile, CardType type, Dictionary extended, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, loadVersion) + private EmoCard(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, extendedSize, loadVersion) { Parameter = parameter; } @@ -71,8 +72,9 @@ public static EmoCard ParseEmoChara(FileInfo file, BinaryReader reader, CardType extData = MessagePackSerializer.Deserialize>(parameterBytes); } + var extendedSize = info != null ? Util.FileSize.FromBytes((int)info.size) : Util.FileSize.Empty; - var card = new EmoCard(file, gameType, extData, parameter, loadVersion) + var card = new EmoCard(file, gameType, extData, extendedSize, parameter, loadVersion) { Language = language, DataID = dataID, diff --git a/src/KKManager.Core/Data/Cards/HC/HoneyCoomCard.cs b/src/KKManager.Core/Data/Cards/HC/HoneyCoomCard.cs index c975385..38960bd 100644 --- a/src/KKManager.Core/Data/Cards/HC/HoneyCoomCard.cs +++ b/src/KKManager.Core/Data/Cards/HC/HoneyCoomCard.cs @@ -4,6 +4,7 @@ using System.IO; using MessagePack; using System.Linq; +using KKManager.Util; namespace KKManager.Data.Cards.HC { @@ -19,7 +20,15 @@ public class HoneyCoomCard : Card [ReadOnly(true)] public HumanDataGameInfo_HC GameInfo { get; } [ReadOnly(true)] public HumanDataGameParameter_HC GameParameter { get; } - private HoneyCoomCard(FileInfo cardFile, CardType type, Dictionary extended, HumanDataParameter parameter, Version version, HumanDataGameInfo_HC gameInfo, HumanDataGameParameter_HC gameParameter) : base(cardFile, type, extended, version) + private HoneyCoomCard( + FileInfo cardFile, + CardType type, + Dictionary extended, + FileSize extendedSize, + HumanDataParameter parameter, + Version version, + HumanDataGameInfo_HC gameInfo, + HumanDataGameParameter_HC gameParameter) : base(cardFile, type, extended, extendedSize, version) { Parameter = parameter; GameInfo = gameInfo; @@ -85,6 +94,7 @@ public static HoneyCoomCard ParseHCPChara(FileInfo file, BinaryReader reader, Ca extData = MessagePackSerializer.Deserialize>(parameterBytes); } + var extendedSize = info != null ? Util.FileSize.FromBytes((int)info.size) : Util.FileSize.Empty; HumanDataAbout about = new HumanDataAbout(); info = blockHeader.SearchInfo(HumanDataAbout.BlockName); @@ -128,7 +138,7 @@ public static HoneyCoomCard ParseHCPChara(FileInfo file, BinaryReader reader, Ca } } - var card = new HoneyCoomCard(file, gameType, extData, parameter, loadVersion, gameInfo, gameParameter) + var card = new HoneyCoomCard(file, gameType, extData, extendedSize, parameter, loadVersion, gameInfo, gameParameter) { Language = about.language, UserID = about.userID, diff --git a/src/KKManager.Core/Data/Cards/KK/KoiCard.cs b/src/KKManager.Core/Data/Cards/KK/KoiCard.cs index 57ce2b4..bebc598 100644 --- a/src/KKManager.Core/Data/Cards/KK/KoiCard.cs +++ b/src/KKManager.Core/Data/Cards/KK/KoiCard.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; +using KKManager.Util; using MessagePack; namespace KKManager.Data.Cards.KK @@ -18,7 +19,7 @@ public class KoiCard : Card [Browsable(false)] public override string UserID => null; [Browsable(false)] public override string DataID => null; - private KoiCard(FileInfo cardFile, CardType type, Dictionary extended, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, loadVersion) + private KoiCard(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, extendedSize, loadVersion) { Parameter = parameter; } @@ -68,8 +69,9 @@ public static KoiCard ParseKoiChara(FileInfo file, BinaryReader reader, CardType extData = MessagePackSerializer.Deserialize>(parameterBytes); } + var extendedSize = info != null ? Util.FileSize.FromBytes((int)info.size) : Util.FileSize.Empty; - var card = new KoiCard(file, gameType, extData, parameter, loadVersion); + var card = new KoiCard(file, gameType, extData, extendedSize, parameter, loadVersion); return card; } diff --git a/src/KKManager.Core/Data/Cards/KK/KoiCoordCard.cs b/src/KKManager.Core/Data/Cards/KK/KoiCoordCard.cs index cb94bc9..f974450 100644 --- a/src/KKManager.Core/Data/Cards/KK/KoiCoordCard.cs +++ b/src/KKManager.Core/Data/Cards/KK/KoiCoordCard.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Drawing; using System.IO; +using KKManager.Util; using MessagePack; namespace KKManager.Data.Cards.KK @@ -20,12 +21,13 @@ public static Card ParseKoiClothes(FileInfo file, BinaryReader reader, CardType //load clothes and accs from the bytes array var _ = reader.ReadBytes(num); - var extended = TryReadExtData(reader); + var extended = TryReadExtData(reader, out var size); - return new KoiCoordCard(file, gameType, extended, loadVersion, coordinateName); + return new KoiCoordCard(file, gameType, extended, Util.FileSize.FromBytes(size), loadVersion, coordinateName); } - private static Dictionary TryReadExtData(BinaryReader br) + private static Dictionary TryReadExtData(BinaryReader br, out int size) { + size = 0; try { var marker = br.ReadString(); @@ -35,6 +37,7 @@ private static Dictionary TryReadExtData(BinaryReader br) if (marker == "KKEx" /*&& version == DataVersion*/ && length > 0) { + size = length; var bytes = br.ReadBytes(length); return MessagePackSerializer.Deserialize>(bytes); } @@ -47,7 +50,7 @@ private static Dictionary TryReadExtData(BinaryReader br) return null; } - public KoiCoordCard(FileInfo cardFile, CardType type, Dictionary extended, Version version, string coordinateName) : base(cardFile, type, extended, version) + public KoiCoordCard(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, Version version, string coordinateName) : base(cardFile, type, extended, extendedSize, version) { Name = coordinateName; } diff --git a/src/KKManager.Core/Data/Cards/KKS/KoiSunCard.cs b/src/KKManager.Core/Data/Cards/KKS/KoiSunCard.cs index ac6c7d6..6cced58 100644 --- a/src/KKManager.Core/Data/Cards/KKS/KoiSunCard.cs +++ b/src/KKManager.Core/Data/Cards/KKS/KoiSunCard.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; +using KKManager.Util; using MessagePack; namespace KKManager.Data.Cards.KKS @@ -19,8 +20,8 @@ public class KoiSunCard : Card public override string UserID => About.userID; public override string DataID => About.dataID; - private KoiSunCard(FileInfo cardFile, CardType type, Dictionary extended, ChaFileParameter parameter, ChaFileAbout about, Version version) : - base(cardFile, type, extended, about?.version ?? version) + private KoiSunCard(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, ChaFileParameter parameter, ChaFileAbout about, Version version) : + base(cardFile, type, extended, extendedSize, about?.version ?? version) { Parameter = parameter; About = about ?? new ChaFileAbout(); @@ -86,8 +87,9 @@ public static KoiSunCard ParseKoiChara(FileInfo file, BinaryReader reader, CardT extData = MessagePackSerializer.Deserialize>(parameterBytes); } + var extendedSize = info != null ? Util.FileSize.FromBytes((int)info.size) : Util.FileSize.Empty; - var card = new KoiSunCard(file, gameType, extData, parameter, about, loadVersion); + var card = new KoiSunCard(file, gameType, extData, extendedSize, parameter, about, loadVersion); return card; } diff --git a/src/KKManager.Core/Data/Cards/RG/RoomGirlCard.cs b/src/KKManager.Core/Data/Cards/RG/RoomGirlCard.cs index b26b73d..0619523 100644 --- a/src/KKManager.Core/Data/Cards/RG/RoomGirlCard.cs +++ b/src/KKManager.Core/Data/Cards/RG/RoomGirlCard.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; +using KKManager.Util; using MessagePack; namespace KKManager.Data.Cards.RG @@ -16,7 +17,7 @@ public class RoomGirlCard : Card public string Traits => String.Join(", ", GetTraits(Parameter.features)); [ReadOnly(true)] public ChaFileParameter Parameter { get; } - private RoomGirlCard(FileInfo cardFile, CardType type, Dictionary extended, ChaFileParameter parameter, Version version) : base(cardFile, type, extended, version) + private RoomGirlCard(FileInfo cardFile, CardType type, Dictionary extended, FileSize extendedSize, ChaFileParameter parameter, Version version) : base(cardFile, type, extended, extendedSize, version) { Parameter = parameter; } @@ -80,8 +81,9 @@ public static RoomGirlCard ParseRGChara(FileInfo file, BinaryReader reader, Card extData = MessagePackSerializer.Deserialize>(parameterBytes); } + var extendedSize = info != null ? Util.FileSize.FromBytes((int)info.size) : Util.FileSize.Empty; - var card = new RoomGirlCard(file, gameType, extData, parameter, loadVersion) + var card = new RoomGirlCard(file, gameType, extData, extendedSize, parameter, loadVersion) { Language = language, UserID = userID,