Files

116 lines
4.4 KiB
C#
Raw Permalink Normal View History

2025-09-30 14:05:34 -04:00
using System.Text;
using SabreTools.Data.Models.XZ;
2026-03-24 19:42:36 -04:00
using SabreTools.Text.Extensions;
2025-09-30 14:05:34 -04:00
2026-03-18 16:37:59 -04:00
namespace SabreTools.Wrappers
2025-09-30 14:05:34 -04:00
{
2025-10-29 08:53:14 -04:00
public partial class XZ : IPrintable
2025-09-30 14:05:34 -04:00
{
2025-10-29 08:53:14 -04:00
#if NETCOREAPP
2025-09-30 14:05:34 -04:00
/// <inheritdoc/>
2025-10-29 08:53:14 -04:00
public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions);
#endif
2025-09-30 14:05:34 -04:00
2025-10-29 08:53:14 -04:00
/// <inheritdoc/>
public void PrintInformation(StringBuilder builder)
2025-09-30 14:05:34 -04:00
{
builder.AppendLine("xz Information:");
builder.AppendLine("-------------------------");
builder.AppendLine();
2025-10-29 09:23:45 -04:00
Print(builder, Model.Header);
Print(builder, Model.Blocks);
Print(builder, Model.Index);
Print(builder, Model.Footer);
2025-09-30 14:05:34 -04:00
}
2025-10-30 23:57:15 -04:00
private static void Print(StringBuilder builder, Header header)
2025-09-30 14:05:34 -04:00
{
builder.AppendLine(" Header Information:");
builder.AppendLine(" -------------------------");
builder.AppendLine(header.Signature, " Signature");
builder.AppendLine($" Flags: {header.Flags} (0x{(ushort)header.Flags:X4})");
builder.AppendLine(header.Crc32, " CRC-32");
builder.AppendLine();
}
2025-10-30 23:57:15 -04:00
private static void Print(StringBuilder builder, Block[] blocks)
2025-09-30 14:05:34 -04:00
{
builder.AppendLine(" Blocks Information:");
builder.AppendLine(" -------------------------");
2025-10-30 23:57:15 -04:00
if (blocks.Length == 0)
2025-09-30 14:05:34 -04:00
{
builder.AppendLine(" No blocks");
builder.AppendLine();
return;
}
for (int i = 0; i < blocks.Length; i++)
{
var block = blocks[i];
builder.AppendLine($" Block {i}:");
builder.AppendLine(block.HeaderSize, " Header size");
builder.AppendLine($" Flags: {block.Flags} (0x{(byte)block.Flags:X2})");
builder.AppendLine(block.CompressedSize, " Compressed size");
builder.AppendLine(block.UncompressedSize, " Uncompressed size");
// TODO: Print filter flags
builder.AppendLine(block.HeaderPadding, " Header padding");
builder.AppendLine(block.Crc32, " CRC-32");
2026-01-25 14:30:18 -05:00
if (block.CompressedData is null)
2025-09-30 14:09:40 -04:00
builder.AppendLine(" Compressed data length: [NULL]");
else
builder.AppendLine(block.CompressedData.Length, " Compressed data length");
2025-09-30 14:05:34 -04:00
builder.AppendLine(block.BlockPadding, " Block padding");
builder.AppendLine(block.Check, " Check");
}
builder.AppendLine();
}
2025-10-30 23:57:15 -04:00
private static void Print(StringBuilder builder, Index index)
2025-09-30 14:05:34 -04:00
{
builder.AppendLine(" Index Information:");
builder.AppendLine(" -------------------------");
builder.AppendLine(index.IndexIndicator, " Index indicator");
builder.AppendLine(index.NumberOfRecords, " Number of records");
2025-09-30 14:09:40 -04:00
Print(builder, index.Records);
2025-09-30 14:05:34 -04:00
builder.AppendLine(index.Padding, " Padding");
builder.AppendLine(index.Crc32, " CRC-32");
builder.AppendLine();
}
2025-10-30 23:57:15 -04:00
private static void Print(StringBuilder builder, Record[] records)
2025-09-30 14:09:40 -04:00
{
builder.AppendLine(" Records Information:");
builder.AppendLine(" -------------------------");
2025-10-30 23:57:15 -04:00
if (records.Length == 0)
2025-09-30 14:09:40 -04:00
{
builder.AppendLine(" No records");
builder.AppendLine();
return;
}
for (int i = 0; i < records.Length; i++)
{
var record = records[i];
builder.AppendLine($" Block {i}:");
builder.AppendLine(record.UnpaddedSize, " Unpadded size");
builder.AppendLine(record.UncompressedSize, " Uncompressed size");
}
}
2025-10-30 23:57:15 -04:00
private static void Print(StringBuilder builder, Footer footer)
2025-09-30 14:05:34 -04:00
{
builder.AppendLine(" Footer Information:");
builder.AppendLine(" -------------------------");
builder.AppendLine(footer.Crc32, " CRC-32");
builder.AppendLine(footer.BackwardSize, " Backward size");
builder.AppendLine($" Flags: {footer.Flags} (0x{(ushort)footer.Flags:X4})");
builder.AppendLine(footer.Signature, " Signature");
builder.AppendLine();
}
}
}