Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Extended Data Size" field to card properties #157

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/KKManager.Core/Data/Cards/AI/AiCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Drawing;
using System.IO;
using KKManager.Util;
using MessagePack;

namespace KKManager.Data.Cards.AI
Expand Down Expand Up @@ -49,8 +50,9 @@ public static AiCard ParseAiChara(FileInfo file, BinaryReader reader, CardType g
var parameterBytes = reader.ReadBytes((int)info.size);
extData = MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(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,
Expand Down Expand Up @@ -105,7 +107,7 @@ public string GetPersonalityName(int personality)
return KKManager.Properties.Resources.Unknown;
}

public AiCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, Version loadVersion) : base(cardFile, type, extended, loadVersion)
public AiCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, FileSize extendedSize, Version loadVersion) : base(cardFile, type, extended, extendedSize, loadVersion)
{
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/KKManager.Core/Data/Cards/AI/AiCoordCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Drawing;
using System.IO;
using KKManager.Util;
using MessagePack;

namespace KKManager.Data.Cards.KK
Expand All @@ -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<string, PluginData> TryReadExtData(BinaryReader br)
private static Dictionary<string, PluginData> TryReadExtData(BinaryReader br, out int size)
{
size = 0;
try
{
var marker = br.ReadString();
Expand All @@ -36,6 +38,7 @@ private static Dictionary<string, PluginData> TryReadExtData(BinaryReader br)

if (marker == "KKEx" /*&& version == DataVersion*/ && length > 0)
{
size = length;
var bytes = br.ReadBytes(length);
return MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(bytes);
}
Expand All @@ -48,7 +51,7 @@ private static Dictionary<string, PluginData> TryReadExtData(BinaryReader br)
return null;
}

public AiCoordCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, Version version, string coordinateName, int language) : base(cardFile, type, extended, version)
public AiCoordCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, FileSize extendedSize, Version version, string coordinateName, int language) : base(cardFile, type, extended, extendedSize, version)
{
Name = coordinateName;
Language = language;
Expand Down
6 changes: 4 additions & 2 deletions src/KKManager.Core/Data/Cards/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, PluginData>))]
public Dictionary<string, PluginData> Extended { get; }
[DisplayName("Extended Data Size")]
public FileSize ExtendedSize { get; }

[ReadOnly(true)] public string[] MissingZipmods { get; set; }
[ReadOnly(true)] public string[] MissingPlugins { get; set; }
Expand Down Expand Up @@ -57,12 +58,13 @@ public virtual Image GetCardFaceImage()
}
}

internal Card(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, Version version)
internal Card(FileInfo cardFile, CardType type, Dictionary<string, PluginData> 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<string, PluginData>();
ExtendedSize = extendedSize;

FileSize = Util.FileSize.FromBytes(cardFile.Length).ToString();
}
Expand Down
6 changes: 4 additions & 2 deletions src/KKManager.Core/Data/Cards/EC/EmoCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Drawing;
using System.IO;
using KKManager.Util;
using MessagePack;

namespace KKManager.Data.Cards.EC
Expand All @@ -16,7 +17,7 @@ public class EmoCard : Card

public ChaFileParameter Parameter { get; }

private EmoCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, loadVersion)
private EmoCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, FileSize extendedSize, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, extendedSize, loadVersion)
{
Parameter = parameter;
}
Expand Down Expand Up @@ -71,8 +72,9 @@ public static EmoCard ParseEmoChara(FileInfo file, BinaryReader reader, CardType

extData = MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(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,
Expand Down
14 changes: 12 additions & 2 deletions src/KKManager.Core/Data/Cards/HC/HoneyCoomCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using MessagePack;
using System.Linq;
using KKManager.Util;

namespace KKManager.Data.Cards.HC
{
Expand All @@ -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<string, PluginData> extended, HumanDataParameter parameter, Version version, HumanDataGameInfo_HC gameInfo, HumanDataGameParameter_HC gameParameter) : base(cardFile, type, extended, version)
private HoneyCoomCard(
FileInfo cardFile,
CardType type,
Dictionary<string, PluginData> extended,
FileSize extendedSize,
HumanDataParameter parameter,
Version version,
HumanDataGameInfo_HC gameInfo,
HumanDataGameParameter_HC gameParameter) : base(cardFile, type, extended, extendedSize, version)
{
Parameter = parameter;
GameInfo = gameInfo;
Expand Down Expand Up @@ -85,6 +94,7 @@ public static HoneyCoomCard ParseHCPChara(FileInfo file, BinaryReader reader, Ca

extData = MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(parameterBytes);
}
var extendedSize = info != null ? Util.FileSize.FromBytes((int)info.size) : Util.FileSize.Empty;

HumanDataAbout about = new HumanDataAbout();
info = blockHeader.SearchInfo(HumanDataAbout.BlockName);
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/KKManager.Core/Data/Cards/KK/KoiCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using KKManager.Util;
using MessagePack;

namespace KKManager.Data.Cards.KK
Expand All @@ -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<string, PluginData> extended, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, loadVersion)
private KoiCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, FileSize extendedSize, ChaFileParameter parameter, Version loadVersion) : base(cardFile, type, extended, extendedSize, loadVersion)
{
Parameter = parameter;
}
Expand Down Expand Up @@ -68,8 +69,9 @@ public static KoiCard ParseKoiChara(FileInfo file, BinaryReader reader, CardType

extData = MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(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;
}
Expand Down
11 changes: 7 additions & 4 deletions src/KKManager.Core/Data/Cards/KK/KoiCoordCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Drawing;
using System.IO;
using KKManager.Util;
using MessagePack;

namespace KKManager.Data.Cards.KK
Expand All @@ -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<string, PluginData> TryReadExtData(BinaryReader br)
private static Dictionary<string, PluginData> TryReadExtData(BinaryReader br, out int size)
{
size = 0;
try
{
var marker = br.ReadString();
Expand All @@ -35,6 +37,7 @@ private static Dictionary<string, PluginData> TryReadExtData(BinaryReader br)

if (marker == "KKEx" /*&& version == DataVersion*/ && length > 0)
{
size = length;
var bytes = br.ReadBytes(length);
return MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(bytes);
}
Expand All @@ -47,7 +50,7 @@ private static Dictionary<string, PluginData> TryReadExtData(BinaryReader br)
return null;
}

public KoiCoordCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, Version version, string coordinateName) : base(cardFile, type, extended, version)
public KoiCoordCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, FileSize extendedSize, Version version, string coordinateName) : base(cardFile, type, extended, extendedSize, version)
{
Name = coordinateName;
}
Expand Down
8 changes: 5 additions & 3 deletions src/KKManager.Core/Data/Cards/KKS/KoiSunCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using KKManager.Util;
using MessagePack;

namespace KKManager.Data.Cards.KKS
Expand All @@ -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<string, PluginData> extended, ChaFileParameter parameter, ChaFileAbout about, Version version) :
base(cardFile, type, extended, about?.version ?? version)
private KoiSunCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, FileSize extendedSize, ChaFileParameter parameter, ChaFileAbout about, Version version) :
base(cardFile, type, extended, extendedSize, about?.version ?? version)
{
Parameter = parameter;
About = about ?? new ChaFileAbout();
Expand Down Expand Up @@ -86,8 +87,9 @@ public static KoiSunCard ParseKoiChara(FileInfo file, BinaryReader reader, CardT

extData = MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/KKManager.Core/Data/Cards/RG/RoomGirlCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using KKManager.Util;
using MessagePack;

namespace KKManager.Data.Cards.RG
Expand All @@ -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<string, PluginData> extended, ChaFileParameter parameter, Version version) : base(cardFile, type, extended, version)
private RoomGirlCard(FileInfo cardFile, CardType type, Dictionary<string, PluginData> extended, FileSize extendedSize, ChaFileParameter parameter, Version version) : base(cardFile, type, extended, extendedSize, version)
{
Parameter = parameter;
}
Expand Down Expand Up @@ -80,8 +81,9 @@ public static RoomGirlCard ParseRGChara(FileInfo file, BinaryReader reader, Card

extData = MessagePackSerializer.Deserialize<Dictionary<string, PluginData>>(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,
Expand Down
Loading