Skip to content

Commit

Permalink
chore: add some debugger displays
Browse files Browse the repository at this point in the history
  • Loading branch information
Js41637 committed Nov 28, 2024
1 parent 1d1da15 commit d232391
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 52 deletions.
13 changes: 7 additions & 6 deletions TACTLib/Core/Key/FullKey.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +13,7 @@ namespace TACTLib.Core.Key {
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[InlineArray(CASC_FULL_KEY_SIZE)]
[DebuggerDisplay("{ToHexString()}")]
[SuppressMessage("ReSharper", "UseSymbolAlias")]
public struct FullKey : IComparable<FullKey> {
// ReSharper disable once InconsistentNaming
Expand All @@ -23,15 +25,15 @@ public struct FullKey : IComparable<FullKey> {
/// <summary>
/// Convert to a hex string
/// </summary>
/// <returns>Hex stirng</returns>
/// <returns>Hex string</returns>
public readonly string ToHexString() {
return Extensions.ToHexString(this);
}

/// <summary>
/// Create from a hex string
/// </summary>
/// <param name="string">Source stirng</param>
/// <param name="string">Source string</param>
/// <returns>Created FullKey</returns>
public static FullKey FromString(ReadOnlySpan<char> @string) {
return FromByteArray(StringToByteArray(@string));
Expand All @@ -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<byte>)left;
var rightSpan = (ReadOnlySpan<byte>)right;
public static int FullKeyCompare(FullKey left, FullKey right) {
var leftSpan = (ReadOnlySpan<byte>) left;
var rightSpan = (ReadOnlySpan<byte>) right;

var leftU0 = BinaryPrimitives.ReadUInt64BigEndian(leftSpan);
var rightU0 = BinaryPrimitives.ReadUInt64BigEndian(rightSpan);
Expand Down
17 changes: 9 additions & 8 deletions TACTLib/Core/Key/TruncatedKey.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,8 +13,9 @@ namespace TACTLib.Core.Key {
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[InlineArray(CASC_TRUNCATED_KEY_SIZE)]
[DebuggerDisplay("{ToHexString()}")]
[SuppressMessage("ReSharper", "UseSymbolAlias")]
public struct TruncatedKey : IComparable<TruncatedKey> {
public struct TruncatedKey : IComparable<TruncatedKey> {
// ReSharper disable once InconsistentNaming
/// <summary>Encoding Key size, in bytes</summary>
public const int CASC_TRUNCATED_KEY_SIZE = 9;
Expand All @@ -23,15 +25,15 @@ public struct TruncatedKey : IComparable<TruncatedKey> {
/// <summary>
/// Convert to a hex string
/// </summary>
/// <returns>Hex stirng</returns>
/// <returns>Hex string</returns>
public readonly string ToHexString() {
return Extensions.ToHexString(this);
}

/// <summary>
/// Create from a hex string
/// </summary>
/// <param name="string">Source stirng</param>
/// <param name="string">Source string</param>
/// <returns>Created EKey</returns>
public static TruncatedKey FromString(ReadOnlySpan<char> @string) {
return FromByteArray(StringToByteArray(@string));
Expand All @@ -49,15 +51,14 @@ public static TruncatedKey FromByteArray(ReadOnlySpan<byte> array) {

return MemoryMarshal.Read<TruncatedKey>(array);
}

public readonly int CompareTo(TruncatedKey other) {
return TruncatedKeyCompare(this, other);
}

public static int TruncatedKeyCompare(TruncatedKey left, TruncatedKey right)
{
var leftSpan = (ReadOnlySpan<byte>)left;
var rightSpan = (ReadOnlySpan<byte>)right;
public static int TruncatedKeyCompare(TruncatedKey left, TruncatedKey right) {
var leftSpan = (ReadOnlySpan<byte>) left;
var rightSpan = (ReadOnlySpan<byte>) right;

var leftU0 = BinaryPrimitives.ReadUInt64BigEndian(leftSpan);
var rightU0 = BinaryPrimitives.ReadUInt64BigEndian(rightSpan);
Expand Down
63 changes: 25 additions & 38 deletions TACTLib/Core/Product/CommonV2/RootFile.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,81 +14,66 @@ public class RootFile {
public byte MPriority;
public string? FileName;
public string? InstallPath;

public RootFile()
{
}

private RootFile(ReadOnlySpan<string> columns, string row)
{

public RootFile() { }

private RootFile(ReadOnlySpan<string> columns, string row) {
Span<Range> 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<RootFile> ParseList(StreamReader reader)
{

public static List<RootFile> ParseList(StreamReader reader) {
var header = reader.ReadLine()!;
if (header[0] != '#') throw new InvalidDataException($"bad header: \"{header}\"");

var files = new List<RootFile>();

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;
}
}
}
}

0 comments on commit d232391

Please sign in to comment.