mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-04-23 22:55:05 +00:00
Port BFPK to new printing
This commit is contained in:
70
BinaryObjectScanner.Printing/BFPK.cs
Normal file
70
BinaryObjectScanner.Printing/BFPK.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Text;
|
||||
using SabreTools.Models.BFPK;
|
||||
|
||||
namespace BinaryObjectScanner.Printing
|
||||
{
|
||||
public static class BFPK
|
||||
{
|
||||
public static void Print(StringBuilder builder, Archive archive)
|
||||
{
|
||||
builder.AppendLine("BFPK Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
builder.AppendLine();
|
||||
|
||||
Print(builder, archive.Header);
|
||||
Print(builder, archive.Files);
|
||||
}
|
||||
|
||||
#if NET48
|
||||
private static void Print(StringBuilder builder, Header header)
|
||||
#else
|
||||
private static void Print(StringBuilder builder, Header? header)
|
||||
#endif
|
||||
{
|
||||
builder.AppendLine(" Header Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (header == null)
|
||||
{
|
||||
builder.AppendLine(" No header");
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Magic: {header.Magic}");
|
||||
builder.AppendLine($" Version: {header.Version} (0x{header.Version:X})");
|
||||
builder.AppendLine($" Files: {header.Files} (0x{header.Files:X})");
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
#if NET48
|
||||
private static void Print(StringBuilder builder, FileEntry[] files)
|
||||
#else
|
||||
private static void Print(StringBuilder builder, FileEntry[]? files)
|
||||
#endif
|
||||
{
|
||||
builder.AppendLine(" File Table Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (files == null || files.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No file table items");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
var entry = files[i];
|
||||
builder.AppendLine($" File Table Entry {i}");
|
||||
if (entry == null)
|
||||
{
|
||||
builder.AppendLine(" [NULL]");
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.AppendLine($" Name size: {entry.NameSize} (0x{entry.NameSize:X})");
|
||||
builder.AppendLine($" Name: {entry.Name}");
|
||||
builder.AppendLine($" Uncompressed size: {entry.UncompressedSize} (0x{entry.UncompressedSize:X})");
|
||||
builder.AppendLine($" Offset: {entry.Offset} (0x{entry.Offset:X})");
|
||||
builder.AppendLine($" Compressed Size: {entry.CompressedSize} (0x{entry.CompressedSize:X})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,67 +236,10 @@ namespace BinaryObjectScanner.Wrappers
|
||||
public override StringBuilder PrettyPrint()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("BFPK Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
builder.AppendLine();
|
||||
|
||||
PrintHeader(builder);
|
||||
PrintFileTable(builder);
|
||||
|
||||
Printing.BFPK.Print(builder, _model);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print header information
|
||||
/// </summary>
|
||||
/// <param name="builder">StringBuilder to append information to</param>
|
||||
private void PrintHeader(StringBuilder builder)
|
||||
{
|
||||
builder.AppendLine(" Header Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
builder.AppendLine($" Magic: {Magic}");
|
||||
builder.AppendLine($" Version: {Version} (0x{Version:X})");
|
||||
builder.AppendLine($" Files: {Files} (0x{Files:X})");
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print file table information
|
||||
/// </summary>
|
||||
/// <param name="builder">StringBuilder to append information to</param>
|
||||
private void PrintFileTable(StringBuilder builder)
|
||||
{
|
||||
builder.AppendLine(" File Table Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (Files == 0 || FileTable == null || FileTable.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No file table items");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < FileTable.Length; i++)
|
||||
{
|
||||
var entry = FileTable[i];
|
||||
builder.AppendLine($" File Table Entry {i}");
|
||||
if (entry == null)
|
||||
{
|
||||
builder.AppendLine(" [NULL]");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AppendLine($" Name size: {entry.NameSize} (0x{entry.NameSize:X})");
|
||||
builder.AppendLine($" Name: {entry.Name}");
|
||||
builder.AppendLine($" Uncompressed size: {entry.UncompressedSize} (0x{entry.UncompressedSize:X})");
|
||||
builder.AppendLine($" Offset: {entry.Offset} (0x{entry.Offset:X})");
|
||||
builder.AppendLine($" Compressed Size: {entry.CompressedSize} (0x{entry.CompressedSize:X})");
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
Reference in New Issue
Block a user