From d23239133c39169c729e2d60fb10764185a90822 Mon Sep 17 00:00:00 2001 From: Js41637 Date: Fri, 29 Nov 2024 08:19:13 +1100 Subject: [PATCH] chore: add some debugger displays --- TACTLib/Core/Key/FullKey.cs | 13 ++--- TACTLib/Core/Key/TruncatedKey.cs | 17 +++--- TACTLib/Core/Product/CommonV2/RootFile.cs | 63 +++++++++-------------- 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/TACTLib/Core/Key/FullKey.cs b/TACTLib/Core/Key/FullKey.cs index 87fa919..5c40d05 100644 --- a/TACTLib/Core/Key/FullKey.cs +++ b/TACTLib/Core/Key/FullKey.cs @@ -1,5 +1,6 @@ using System; using System.Buffers.Binary; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,6 +13,7 @@ namespace TACTLib.Core.Key { /// [StructLayout(LayoutKind.Sequential, Pack = 1)] [InlineArray(CASC_FULL_KEY_SIZE)] + [DebuggerDisplay("{ToHexString()}")] [SuppressMessage("ReSharper", "UseSymbolAlias")] public struct FullKey : IComparable { // ReSharper disable once InconsistentNaming @@ -23,7 +25,7 @@ public struct FullKey : IComparable { /// /// Convert to a hex string /// - /// Hex stirng + /// Hex string public readonly string ToHexString() { return Extensions.ToHexString(this); } @@ -31,7 +33,7 @@ public readonly string ToHexString() { /// /// Create from a hex string /// - /// Source stirng + /// Source string /// Created FullKey public static FullKey FromString(ReadOnlySpan @string) { return FromByteArray(StringToByteArray(@string)); @@ -58,10 +60,9 @@ public readonly int CompareTo(FullKey other) { return FullKeyCompare(this, other); } - public static int FullKeyCompare(FullKey left, FullKey right) - { - var leftSpan = (ReadOnlySpan)left; - var rightSpan = (ReadOnlySpan)right; + public static int FullKeyCompare(FullKey left, FullKey right) { + var leftSpan = (ReadOnlySpan) left; + var rightSpan = (ReadOnlySpan) right; var leftU0 = BinaryPrimitives.ReadUInt64BigEndian(leftSpan); var rightU0 = BinaryPrimitives.ReadUInt64BigEndian(rightSpan); diff --git a/TACTLib/Core/Key/TruncatedKey.cs b/TACTLib/Core/Key/TruncatedKey.cs index 9027567..127c2fd 100644 --- a/TACTLib/Core/Key/TruncatedKey.cs +++ b/TACTLib/Core/Key/TruncatedKey.cs @@ -1,5 +1,6 @@ using System; using System.Buffers.Binary; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -12,8 +13,9 @@ namespace TACTLib.Core.Key { /// [StructLayout(LayoutKind.Sequential, Pack = 1)] [InlineArray(CASC_TRUNCATED_KEY_SIZE)] + [DebuggerDisplay("{ToHexString()}")] [SuppressMessage("ReSharper", "UseSymbolAlias")] - public struct TruncatedKey : IComparable { + public struct TruncatedKey : IComparable { // ReSharper disable once InconsistentNaming /// Encoding Key size, in bytes public const int CASC_TRUNCATED_KEY_SIZE = 9; @@ -23,7 +25,7 @@ public struct TruncatedKey : IComparable { /// /// Convert to a hex string /// - /// Hex stirng + /// Hex string public readonly string ToHexString() { return Extensions.ToHexString(this); } @@ -31,7 +33,7 @@ public readonly string ToHexString() { /// /// Create from a hex string /// - /// Source stirng + /// Source string /// Created EKey public static TruncatedKey FromString(ReadOnlySpan @string) { return FromByteArray(StringToByteArray(@string)); @@ -49,15 +51,14 @@ public static TruncatedKey FromByteArray(ReadOnlySpan array) { return MemoryMarshal.Read(array); } - + public readonly int CompareTo(TruncatedKey other) { return TruncatedKeyCompare(this, other); } - public static int TruncatedKeyCompare(TruncatedKey left, TruncatedKey right) - { - var leftSpan = (ReadOnlySpan)left; - var rightSpan = (ReadOnlySpan)right; + public static int TruncatedKeyCompare(TruncatedKey left, TruncatedKey right) { + var leftSpan = (ReadOnlySpan) left; + var rightSpan = (ReadOnlySpan) right; var leftU0 = BinaryPrimitives.ReadUInt64BigEndian(leftSpan); var rightU0 = BinaryPrimitives.ReadUInt64BigEndian(rightSpan); diff --git a/TACTLib/Core/Product/CommonV2/RootFile.cs b/TACTLib/Core/Product/CommonV2/RootFile.cs index 0039bd0..a623aee 100644 --- a/TACTLib/Core/Product/CommonV2/RootFile.cs +++ b/TACTLib/Core/Product/CommonV2/RootFile.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; // ReSharper disable file NotAccessedField.Global namespace TACTLib.Core.Product.CommonV2 { + [DebuggerDisplay("{FileName}")] public class RootFile { public string? FileID; public CKey MD5; @@ -12,81 +14,66 @@ public class RootFile { public byte MPriority; public string? FileName; public string? InstallPath; - - public RootFile() - { - } - - private RootFile(ReadOnlySpan columns, string row) - { + + public RootFile() { } + + private RootFile(ReadOnlySpan columns, string row) { Span ranges = stackalloc Range[columns.Length]; MemoryExtensions.Split(row, ranges, '|'); - - for (var i = 0; i < columns.Length; i++) - { + + for (var i = 0; i < columns.Length; i++) { var valueSpan = row.AsSpan(ranges[i]); - - switch (columns[i]) - { - case "FILEID": - { + + switch (columns[i]) { + case "FILEID": { FileID = row[ranges[i]]; break; } - case "MD5": - { + case "MD5": { MD5 = CKey.FromString(valueSpan); break; } - case "CHUNK_ID": - { + case "CHUNK_ID": { ChunkID = byte.Parse(valueSpan); break; } - case "PRIORITY": - { + case "PRIORITY": { Priority = byte.Parse(valueSpan); break; } - case "MPRIORITY": - { + case "MPRIORITY": { MPriority = byte.Parse(valueSpan); break; } - case "FILENAME": - { + case "FILENAME": { FileName = row[ranges[i]]; break; } - case "INSTALLPATH": - { + case "INSTALLPATH": { InstallPath = row[ranges[i]]; break; } - default: - { + default: { Logger.Debug("RootFile", $"Unknown column {columns[i]}"); break; } } } } - - public static List ParseList(StreamReader reader) - { + + public static List ParseList(StreamReader reader) { var header = reader.ReadLine()!; if (header[0] != '#') throw new InvalidDataException($"bad header: \"{header}\""); - + var files = new List(); - + var columns = header.Substring(1).Split('|'); - while (reader.ReadLine() is { } row) - { + while (reader.ReadLine() is { } row) { var rootFile = new RootFile(columns, row); files.Add(rootFile); } - + return files; } } -} +} \ No newline at end of file