From ebcdc08a7731feb4216ebe70957d272def8a3b6a Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 15 Sep 2023 12:01:56 -0400 Subject: [PATCH] Port WAD to new printing --- BinaryObjectScanner.Printing/Extensions.cs | 2 +- BinaryObjectScanner.Printing/SGA.cs | 14 --- BinaryObjectScanner.Printing/WAD.cs | 114 +++++++++++++++++++++ BinaryObjectScanner.Wrappers/WAD.cs | 99 +----------------- 4 files changed, 116 insertions(+), 113 deletions(-) create mode 100644 BinaryObjectScanner.Printing/WAD.cs diff --git a/BinaryObjectScanner.Printing/Extensions.cs b/BinaryObjectScanner.Printing/Extensions.cs index 2aa6e5a1..0b2bad69 100644 --- a/BinaryObjectScanner.Printing/Extensions.cs +++ b/BinaryObjectScanner.Printing/Extensions.cs @@ -34,7 +34,7 @@ namespace BinaryObjectScanner.Printing #if NET48 string valueString = value.ToString(); #else - string valueString = value == null ? "[NULL]" : value.ToString(); + string valueString = (value == null ? "[NULL]" : value.ToString()); #endif return sb.AppendLine($"{prefixString}: {valueString}"); diff --git a/BinaryObjectScanner.Printing/SGA.cs b/BinaryObjectScanner.Printing/SGA.cs index 2ad578ae..fac7de60 100644 --- a/BinaryObjectScanner.Printing/SGA.cs +++ b/BinaryObjectScanner.Printing/SGA.cs @@ -100,21 +100,7 @@ namespace BinaryObjectScanner.Printing Print(builder, directory7.DirectoryHeader); Print(builder, directory7.Sections); Print(builder, directory7.Folders); - -/* Unmerged change from project 'b:\Programs\GitHub\BurnOutSharp\BinaryObjectScanner.Printing\BinaryObjectScanner.Printing.csproj ($net6.0)' -Before: Print(builder, directory7.Files); -After: - Print(builder, (File6?[]?)directory7.Files); -*/ - -/* Unmerged change from project 'b:\Programs\GitHub\BurnOutSharp\BinaryObjectScanner.Printing\BinaryObjectScanner.Printing.csproj ($net7.0)' -Before: - Print(builder, directory7.Files); -After: - Print(builder, (File6?[]?)directory7.Files); -*/ - Print(builder, (File6[])directory7.Files); break; default: diff --git a/BinaryObjectScanner.Printing/WAD.cs b/BinaryObjectScanner.Printing/WAD.cs new file mode 100644 index 00000000..cac94813 --- /dev/null +++ b/BinaryObjectScanner.Printing/WAD.cs @@ -0,0 +1,114 @@ +using System.Text; +using SabreTools.Models.WAD; + +namespace BinaryObjectScanner.Printing +{ + public static class WAD + { + public static void Print(StringBuilder builder, File file) + { + builder.AppendLine("WAD Information:"); + builder.AppendLine("-------------------------"); + builder.AppendLine(); + + Print(builder, file.Header); + Print(builder, file.Lumps); + Print(builder, file.LumpInfos); + } + +#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"); + builder.AppendLine(); + return; + } + + builder.AppendLine(header.Signature, " Signature"); + builder.AppendLine(header.LumpCount, " Lump count"); + builder.AppendLine(header.LumpOffset, " Lump offset"); + builder.AppendLine(); + } + +#if NET48 + private static void Print(StringBuilder builder, Lump[] entries) +#else + private static void Print(StringBuilder builder, Lump?[]? entries) +#endif + { + builder.AppendLine(" Lumps Information:"); + builder.AppendLine(" -------------------------"); + if (entries == null || entries.Length == 0) + { + builder.AppendLine(" No lumps"); + builder.AppendLine(); + return; + } + + for (int i = 0; i < entries.Length; i++) + { + var entry = entries[i]; + builder.AppendLine($" Lump {i}"); + if (entry == null) + { + builder.AppendLine(" [NULL]"); + continue; + } + + builder.AppendLine(entry.Offset, " Offset"); + builder.AppendLine(entry.DiskLength, " Disk length"); + builder.AppendLine(entry.Length, " Length"); + builder.AppendLine(entry.Type, " Type"); + builder.AppendLine(entry.Compression, " Compression"); + builder.AppendLine(entry.Padding0, " Padding 0"); + builder.AppendLine(entry.Padding1, " Padding 1"); + builder.AppendLine(entry.Name, " Name"); + } + builder.AppendLine(); + } + +#if NET48 + private static void Print(StringBuilder builder, LumpInfo[] entries) +#else + private static void Print(StringBuilder builder, LumpInfo?[]? entries) +#endif + { + builder.AppendLine(" Lump Infos Information:"); + builder.AppendLine(" -------------------------"); + if (entries == null || entries.Length == 0) + { + builder.AppendLine(" No lump infos"); + builder.AppendLine(); + return; + } + + for (int i = 0; i < entries.Length; i++) + { + var entry = entries[i]; + builder.AppendLine($" Lump Info {i}"); + if (entry == null) + { + builder.AppendLine(" Lump is compressed"); + continue; + } + + builder.AppendLine(entry.Name, " Name"); + builder.AppendLine(entry.Width, " Width"); + builder.AppendLine(entry.Height, " Height"); + builder.AppendLine(entry.PixelOffset, " Pixel offset"); + // TODO: Print unknown data? + // TODO: Print pixel data? + builder.AppendLine(entry.PaletteSize, " Palette size"); + // TODO: Print palette data? + } + builder.AppendLine(); + } + } +} \ No newline at end of file diff --git a/BinaryObjectScanner.Wrappers/WAD.cs b/BinaryObjectScanner.Wrappers/WAD.cs index 328637d1..75182b4a 100644 --- a/BinaryObjectScanner.Wrappers/WAD.cs +++ b/BinaryObjectScanner.Wrappers/WAD.cs @@ -155,107 +155,10 @@ namespace BinaryObjectScanner.Wrappers public override StringBuilder PrettyPrint() { StringBuilder builder = new StringBuilder(); - - builder.AppendLine("WAD Information:"); - builder.AppendLine("-------------------------"); - builder.AppendLine(); - - PrintHeader(builder); - PrintLumps(builder); - PrintLumpInfos(builder); - + Printing.WAD.Print(builder, _model); return builder; } - /// - /// Print header information - /// - /// StringBuilder to append information to - private void PrintHeader(StringBuilder builder) - { - builder.AppendLine(" Header Information:"); - builder.AppendLine(" -------------------------"); - builder.AppendLine($" Signature: {Signature}"); - builder.AppendLine($" Lump count: {LumpCount} (0x{LumpCount:X})"); - builder.AppendLine($" Lump offset: {LumpOffset} (0x{LumpOffset:X})"); - builder.AppendLine(); - } - - /// - /// Print lumps information - /// - /// StringBuilder to append information to - private void PrintLumps(StringBuilder builder) - { - builder.AppendLine(" Lumps Information:"); - builder.AppendLine(" -------------------------"); - if (Lumps == null || Lumps.Length == 0) - { - builder.AppendLine(" No lumps"); - } - else - { - for (int i = 0; i < Lumps.Length; i++) - { - var lump = Lumps[i]; - builder.AppendLine($" Lump {i}"); - if (lump == null) - { - builder.AppendLine(" [NULL]"); - continue; - } - - builder.AppendLine($" Offset: {lump.Offset} (0x{lump.Offset:X})"); - builder.AppendLine($" Disk length: {lump.DiskLength} (0x{lump.DiskLength:X})"); - builder.AppendLine($" Length: {lump.Length} (0x{lump.Length:X})"); - builder.AppendLine($" Type: {lump.Type} (0x{lump.Type:X})"); - builder.AppendLine($" Compression: {lump.Compression} (0x{lump.Compression:X})"); - builder.AppendLine($" Padding 0: {lump.Padding0} (0x{lump.Padding0:X})"); - builder.AppendLine($" Padding 1: {lump.Padding1} (0x{lump.Padding1:X})"); - builder.AppendLine($" Name: {lump.Name ?? "[NULL]"}"); - } - } - builder.AppendLine(); - } - - /// - /// Print lump infos information - /// - /// StringBuilder to append information to - private void PrintLumpInfos(StringBuilder builder) - { - builder.AppendLine(" Lump Infos Information:"); - builder.AppendLine(" -------------------------"); - if (LumpInfos == null || LumpInfos.Length == 0) - { - builder.AppendLine(" No lump infos"); - } - else - { - for (int i = 0; i < LumpInfos.Length; i++) - { - var lumpInfo = LumpInfos[i]; - builder.AppendLine($" Lump Info {i}"); - if (lumpInfo == null) - { - builder.AppendLine(" Lump is compressed"); - } - else - { - builder.AppendLine($" Name: {lumpInfo.Name ?? "[NULL]"}"); - builder.AppendLine($" Width: {lumpInfo.Width} (0x{lumpInfo.Width:X})"); - builder.AppendLine($" Height: {lumpInfo.Height} (0x{lumpInfo.Height:X})"); - builder.AppendLine($" Pixel offset: {lumpInfo.PixelOffset} (0x{lumpInfo.PixelOffset:X})"); - // TODO: Print unknown data? - // TODO: Print pixel data? - builder.AppendLine($" Palette size: {lumpInfo.PaletteSize} (0x{lumpInfo.PaletteSize:X})"); - // TODO: Print palette data? - } - } - } - builder.AppendLine(); - } - #if NET6_0_OR_GREATER ///