diff --git a/README.MD b/README.MD index 69b5e1b9..f0180318 100644 --- a/README.MD +++ b/README.MD @@ -99,8 +99,8 @@ Below is a table representing the various non-conversion interfaces that are imp | Interface Name | Purpose | | --- | --- | -| `SabreTools.Data.Printers.IPrinter` | Provides a formatted output for a `TModel` | | `SabreTools.Serialization.Wrappers.IExtractable` | Marks a wrapper as able to be extracted | +| `SabreTools.Serialization.Wrappers.IPrintable` | Marks a wrapper as able to print model information | | `SabreTools.Serialization.Wrappers.IWrapper` | Represents an item with a description and JSON serializable state, allowing for extensions | | `SabreTools.Serialization.Wrappers.IWrapper` | Wraps a model with source data, allowing for extensions | @@ -114,7 +114,6 @@ Below is a table of all namespaces within the library and what they represent | `SabreTools.Data.Extensions` | Extension methods related to models | | `SabreTools.Data.Models` | Models representing different file and structure types | | `SabreTools.Data.ObjectIdentifier` | Object Identifier (OID) parsing | -| `SabreTools.Data.Printers` | Export model information in a formatted manner | | `SabreTools.Serialization.CrossModel` | Convert between models; mainly used for metadata files converting to and from a common, `Dictionary`-based model | | `SabreTools.Serialization.Interfaces` | Interfaces used commonly throughout the library | | `SabreTools.Serialization.Readers` | Convert from external sources to models | diff --git a/SabreTools.Serialization/Extensions/ISO9660.cs b/SabreTools.Serialization/Extensions/ISO9660.cs index 0db4e8f0..0dba7065 100644 --- a/SabreTools.Serialization/Extensions/ISO9660.cs +++ b/SabreTools.Serialization/Extensions/ISO9660.cs @@ -4,6 +4,12 @@ namespace SabreTools.Data.Extensions { public static class ISO9660 { + /// + /// Get the logical block size from a sector length + /// + /// Volume descriptor containing block information + /// Defined sector length + /// Size of a logical block public static short GetLogicalBlockSize(this BaseVolumeDescriptor bvd, short sectorLength) { short blockLength = sectorLength; diff --git a/SabreTools.Serialization/Printers/StringBuilderExtensions.cs b/SabreTools.Serialization/Extensions/StringBuilderExtensions.cs similarity index 99% rename from SabreTools.Serialization/Printers/StringBuilderExtensions.cs rename to SabreTools.Serialization/Extensions/StringBuilderExtensions.cs index 12c55832..a44da52c 100644 --- a/SabreTools.Serialization/Printers/StringBuilderExtensions.cs +++ b/SabreTools.Serialization/Extensions/StringBuilderExtensions.cs @@ -2,7 +2,7 @@ using System; using System.Text; using SabreTools.Numerics; -namespace SabreTools.Data.Printers +namespace SabreTools.Data.Extensions { // TODO: Add extension for printing enums, if possible internal static class StringBuilderExtensions diff --git a/SabreTools.Serialization/Models/ISO9660/ExtendedAttributeRecord.cs b/SabreTools.Serialization/Models/ISO9660/ExtendedAttributeRecord.cs index 04cf0fb5..cee40853 100644 --- a/SabreTools.Serialization/Models/ISO9660/ExtendedAttributeRecord.cs +++ b/SabreTools.Serialization/Models/ISO9660/ExtendedAttributeRecord.cs @@ -53,7 +53,7 @@ namespace SabreTools.Data.Models.ISO9660 /// /// Record attributes - /// Note: If RecordType is zero, this field is ignored by readers + /// Note: If RecordType is zero, this field is ignored by readers /// public RecordAttributes RecordAttributes { get; set; } diff --git a/SabreTools.Serialization/Printer.cs b/SabreTools.Serialization/Printer.cs index ed98aab3..c664b2be 100644 --- a/SabreTools.Serialization/Printer.cs +++ b/SabreTools.Serialization/Printer.cs @@ -1,7 +1,6 @@ using System; using System.Text; -using SabreTools.Data.Printers; -using Wrapper = SabreTools.Serialization.Wrappers; +using SabreTools.Serialization.Wrappers; namespace SabreTools.Serialization { @@ -14,9 +13,9 @@ namespace SabreTools.Serialization /// Print the item information from a wrapper to console as /// pretty-printed text /// - public static void PrintToConsole(this Wrapper.IWrapper wrapper) + public static void PrintToConsole(this IWrapper wrapper) { - var sb = wrapper.ExportStringBuilder(); + var sb = ExportStringBuilder(wrapper); if (sb == null) { Console.WriteLine("No item information could be generated"); @@ -29,569 +28,29 @@ namespace SabreTools.Serialization /// /// Export the item information as a StringBuilder /// - public static StringBuilder? ExportStringBuilder(this Wrapper.IWrapper wrapper) + public static StringBuilder? ExportStringBuilder(this IWrapper wrapper) { - return wrapper switch - { - Wrapper.AACSMediaKeyBlock item => item.PrettyPrint(), - Wrapper.BDPlusSVM item => item.PrettyPrint(), - Wrapper.BFPK item => item.PrettyPrint(), - Wrapper.BSP item => item.PrettyPrint(), - Wrapper.CFB item => item.PrettyPrint(), - Wrapper.CHD item => item.PrettyPrint(), - Wrapper.CIA item => item.PrettyPrint(), - Wrapper.GCF item => item.PrettyPrint(), - Wrapper.GZip item => item.PrettyPrint(), - Wrapper.InstallShieldArchiveV3 item => item.PrettyPrint(), - Wrapper.InstallShieldCabinet item => item.PrettyPrint(), - Wrapper.IRD item => item.PrettyPrint(), - Wrapper.ISO9660 item => item.PrettyPrint(), - Wrapper.LinearExecutable item => item.PrettyPrint(), - Wrapper.LZKWAJ item => item.PrettyPrint(), - Wrapper.LZQBasic item => item.PrettyPrint(), - Wrapper.LZSZDD item => item.PrettyPrint(), - Wrapper.MicrosoftCabinet item => item.PrettyPrint(), - Wrapper.MoPaQ item => item.PrettyPrint(), - Wrapper.MSDOS item => item.PrettyPrint(), - Wrapper.N3DS item => item.PrettyPrint(), - Wrapper.NCF item => item.PrettyPrint(), - Wrapper.NewExecutable item => item.PrettyPrint(), - Wrapper.Nitro item => item.PrettyPrint(), - Wrapper.PAK item => item.PrettyPrint(), - Wrapper.PFF item => item.PrettyPrint(), - Wrapper.PIC item => item.PrettyPrint(), - Wrapper.PKZIP item => item.PrettyPrint(), - Wrapper.PlayJAudioFile item => item.PrettyPrint(), - Wrapper.PlayJPlaylist item => item.PrettyPrint(), - Wrapper.PortableExecutable item => item.PrettyPrint(), - Wrapper.Quantum item => item.PrettyPrint(), - Wrapper.SecuROMDFA item => item.PrettyPrint(), - Wrapper.SGA item => item.PrettyPrint(), - Wrapper.TapeArchive item => item.PrettyPrint(), - Wrapper.VBSP item => item.PrettyPrint(), - Wrapper.VPK item => item.PrettyPrint(), - Wrapper.WAD3 item => item.PrettyPrint(), - Wrapper.WiseOverlayHeader item => item.PrettyPrint(), - Wrapper.WiseScript item => item.PrettyPrint(), - Wrapper.WiseSectionHeader item => item.PrettyPrint(), - Wrapper.XeMID item => item.PrettyPrint(), - Wrapper.XMID item => item.PrettyPrint(), - Wrapper.XZ item => item.PrettyPrint(), - Wrapper.XZP item => item.PrettyPrint(), - _ => null, - }; + // Ignore unprintable types + if (wrapper is not IPrintable printable) + return null; + + var builder = new StringBuilder(); + printable.PrintInformation(builder); + return builder; } #if NETCOREAPP /// /// Export the item information as JSON /// - public static string ExportJSON(this Wrapper.IWrapper wrapper) + public static string ExportJSON(this IWrapper wrapper) { - return wrapper switch - { - Wrapper.AACSMediaKeyBlock item => item.ExportJSON(), - Wrapper.BDPlusSVM item => item.ExportJSON(), - Wrapper.BFPK item => item.ExportJSON(), - Wrapper.BSP item => item.ExportJSON(), - Wrapper.CFB item => item.ExportJSON(), - Wrapper.CHD item => item.ExportJSON(), - Wrapper.CIA item => item.ExportJSON(), - Wrapper.GCF item => item.ExportJSON(), - Wrapper.GZip item => item.ExportJSON(), - Wrapper.InstallShieldArchiveV3 item => item.ExportJSON(), - Wrapper.InstallShieldCabinet item => item.ExportJSON(), - Wrapper.IRD item => item.ExportJSON(), - Wrapper.ISO9660 item => item.ExportJSON(), - Wrapper.LinearExecutable item => item.ExportJSON(), - Wrapper.LZKWAJ item => item.ExportJSON(), - Wrapper.LZQBasic item => item.ExportJSON(), - Wrapper.LZSZDD item => item.ExportJSON(), - Wrapper.MicrosoftCabinet item => item.ExportJSON(), - Wrapper.MoPaQ item => item.ExportJSON(), - Wrapper.MSDOS item => item.ExportJSON(), - Wrapper.N3DS item => item.ExportJSON(), - Wrapper.NCF item => item.ExportJSON(), - Wrapper.NewExecutable item => item.ExportJSON(), - Wrapper.Nitro item => item.ExportJSON(), - Wrapper.PAK item => item.ExportJSON(), - Wrapper.PFF item => item.ExportJSON(), - Wrapper.PIC item => item.ExportJSON(), - Wrapper.PKZIP item => item.ExportJSON(), - Wrapper.PlayJAudioFile item => item.ExportJSON(), - Wrapper.PlayJPlaylist item => item.ExportJSON(), - Wrapper.PortableExecutable item => item.ExportJSON(), - Wrapper.Quantum item => item.ExportJSON(), - Wrapper.SecuROMDFA item => item.ExportJSON(), - Wrapper.SGA item => item.ExportJSON(), - Wrapper.TapeArchive item => item.ExportJSON(), - Wrapper.VBSP item => item.ExportJSON(), - Wrapper.VPK item => item.ExportJSON(), - Wrapper.WAD3 item => item.ExportJSON(), - Wrapper.WiseOverlayHeader item => item.ExportJSON(), - Wrapper.WiseScript item => item.ExportJSON(), - Wrapper.WiseSectionHeader item => item.ExportJSON(), - Wrapper.XeMID item => item.ExportJSON(), - Wrapper.XMID item => item.ExportJSON(), - Wrapper.XZ item => item.ExportJSON(), - Wrapper.XZP item => item.ExportJSON(), - _ => string.Empty, - }; + // Ignore unprintable types + if (wrapper is not IPrintable printable) + return string.Empty; + + return printable.ExportJSON(); } #endif - - #region Static Printing Implementations - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.AACSMediaKeyBlock item) - { - var builder = new StringBuilder(); - AACSMediaKeyBlock.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.BDPlusSVM item) - { - var builder = new StringBuilder(); - BDPlusSVM.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.BFPK item) - { - var builder = new StringBuilder(); - BFPK.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.BSP item) - { - var builder = new StringBuilder(); - BSP.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.CFB item) - { - var builder = new StringBuilder(); - CFB.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.CHD item) - { - var builder = new StringBuilder(); - CHD.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.CIA item) - { - var builder = new StringBuilder(); - CIA.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.GCF item) - { - var builder = new StringBuilder(); - GCF.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.GZip item) - { - var builder = new StringBuilder(); - GZip.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.InstallShieldArchiveV3 item) - { - var builder = new StringBuilder(); - InstallShieldArchiveV3.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.InstallShieldCabinet item) - { - var builder = new StringBuilder(); - InstallShieldCabinet.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.IRD item) - { - var builder = new StringBuilder(); - IRD.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.ISO9660 item) - { - var builder = new StringBuilder(); - ISO9660.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.LinearExecutable item) - { - var builder = new StringBuilder(); - LinearExecutable.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.LZKWAJ item) - { - var builder = new StringBuilder(); - LZKWAJ.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.LZQBasic item) - { - var builder = new StringBuilder(); - LZQBasic.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.LZSZDD item) - { - var builder = new StringBuilder(); - LZSZDD.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.MicrosoftCabinet item) - { - var builder = new StringBuilder(); - MicrosoftCabinet.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.MoPaQ item) - { - var builder = new StringBuilder(); - MoPaQ.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.MSDOS item) - { - var builder = new StringBuilder(); - MSDOS.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.N3DS item) - { - var builder = new StringBuilder(); - N3DS.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.NCF item) - { - var builder = new StringBuilder(); - NCF.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.NewExecutable item) - { - var builder = new StringBuilder(); - NewExecutable.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.Nitro item) - { - var builder = new StringBuilder(); - Nitro.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.PAK item) - { - var builder = new StringBuilder(); - PAK.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.PFF item) - { - var builder = new StringBuilder(); - PFF.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.PIC item) - { - var builder = new StringBuilder(); - PIC.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.PKZIP item) - { - var builder = new StringBuilder(); - PKZIP.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.PlayJAudioFile item) - { - var builder = new StringBuilder(); - PlayJAudioFile.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.PlayJPlaylist item) - { - var builder = new StringBuilder(); - PlayJPlaylist.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.PortableExecutable item) - { - var builder = new StringBuilder(); - PortableExecutable.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.Quantum item) - { - var builder = new StringBuilder(); - Quantum.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.SecuROMDFA item) - { - var builder = new StringBuilder(); - SecuROMDFA.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.SGA item) - { - var builder = new StringBuilder(); - SGA.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.TapeArchive item) - { - var builder = new StringBuilder(); - TapeArchive.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.VBSP item) - { - var builder = new StringBuilder(); - VBSP.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.VPK item) - { - var builder = new StringBuilder(); - VPK.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.WAD3 item) - { - var builder = new StringBuilder(); - WAD3.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.WiseOverlayHeader item) - { - var builder = new StringBuilder(); - WiseOverlayHeader.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.WiseScript item) - { - var builder = new StringBuilder(); - WiseScript.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.WiseSectionHeader item) - { - var builder = new StringBuilder(); - WiseSectionHeader.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.XeMID item) - { - var builder = new StringBuilder(); - XeMID.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.XMID item) - { - var builder = new StringBuilder(); - XMID.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.XZ item) - { - var builder = new StringBuilder(); - XZ.Print(builder, item.Model); - return builder; - } - - /// - /// Export the item information as pretty-printed text - /// - private static StringBuilder PrettyPrint(this Wrapper.XZP item) - { - var builder = new StringBuilder(); - XZP.Print(builder, item.Model); - return builder; - } - - #endregion } } diff --git a/SabreTools.Serialization/Printers/IPrinter.cs b/SabreTools.Serialization/Printers/IPrinter.cs deleted file mode 100644 index 631d7e04..00000000 --- a/SabreTools.Serialization/Printers/IPrinter.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Text; - -namespace SabreTools.Data.Printers -{ - /// - /// Marks a class as a printer associated with a model - /// - /// Type of the top-level model - public interface IPrinter - { - /// - /// Print information associated with a model - /// - /// StringBuilder to append information to - /// Model to print - void PrintInformation(StringBuilder builder, TModel model); - } -} diff --git a/SabreTools.Serialization/Readers/ISO9660.cs b/SabreTools.Serialization/Readers/ISO9660.cs index 6951a341..20c7e553 100644 --- a/SabreTools.Serialization/Readers/ISO9660.cs +++ b/SabreTools.Serialization/Readers/ISO9660.cs @@ -1,17 +1,16 @@ -using System; using System.Collections.Generic; using System.IO; using SabreTools.Data.Extensions; using SabreTools.Data.Models.ISO9660; using SabreTools.IO.Extensions; -using SabreTools.Numerics; namespace SabreTools.Serialization.Readers { public class ISO9660 : BaseBinaryReader { /// - public override Volume? Deserialize(Stream? data) => Deserialize(data, Constants.MinimumSectorSize); + public override Volume? Deserialize(Stream? data) + => Deserialize(data, Constants.MinimumSectorSize); /// /// Size of the logical sector used in the volume @@ -84,7 +83,7 @@ namespace SabreTools.Serialization.Readers // If no valid volume descriptor could be read, return the current set if (volumeDescriptor == null) return [.. obj]; - + // If the set has already been terminated and the returned volume descriptor is not another terminator, // assume the read volume descriptor is not a valid volume descriptor and return the current set if (setTerminated && volumeDescriptor.Type != VolumeDescriptorType.VOLUME_DESCRIPTOR_SET_TERMINATOR) @@ -93,7 +92,7 @@ namespace SabreTools.Serialization.Readers data.Seek(-sectorLength, SeekOrigin.Current); return [.. obj]; } - + // Add the valid read volume descriptor to the set obj.Add(volumeDescriptor); @@ -397,7 +396,7 @@ namespace SabreTools.Serialization.Readers } } - // Return error (null) if no valid path table groups were found + // Return error (null) if no valid path table groups were found if (groups.Count == 0) return null; @@ -421,7 +420,7 @@ namespace SabreTools.Serialization.Readers int locationL2 = vd.OptionalPathTableLocationL; int locationM = vd.PathTableLocationM; int locationM2 = vd.OptionalPathTableLocationM; - + short blockLength = vd.GetLogicalBlockSize(sectorLength); var groupL = new PathTableGroup(); @@ -453,7 +452,7 @@ namespace SabreTools.Serialization.Readers // If the both-endian path table size value is consistent, return the single path table group if (sizeL == sizeB) return groups; - + // Get the other-sized path table group var groupB = new PathTableGroup(); if (locationL != 0 && ((locationL * blockLength) + sizeB) < data.Length) @@ -582,7 +581,7 @@ namespace SabreTools.Serialization.Readers } } - // Return error (null) if no valid directory descriptors were found + // Return error (null) if no valid directory descriptors were found if (directories.Count == 0) return null; diff --git a/SabreTools.Serialization/Printers/AACSMediaKeyBlock.cs b/SabreTools.Serialization/Wrappers/AACSMediaKeyBlock.Printing.cs similarity index 94% rename from SabreTools.Serialization/Printers/AACSMediaKeyBlock.cs rename to SabreTools.Serialization/Wrappers/AACSMediaKeyBlock.Printing.cs index 689023a2..bfab60ca 100644 --- a/SabreTools.Serialization/Printers/AACSMediaKeyBlock.cs +++ b/SabreTools.Serialization/Wrappers/AACSMediaKeyBlock.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.AACS; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class AACSMediaKeyBlock : IPrinter + public partial class AACSMediaKeyBlock : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, MediaKeyBlock model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, MediaKeyBlock mediaKeyBlock) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, MediaKeyBlock mediaKeyBlock) { builder.AppendLine("AACS Media Key Block Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/AACSMediaKeyBlock.cs b/SabreTools.Serialization/Wrappers/AACSMediaKeyBlock.cs index 9f678d69..38cc765e 100644 --- a/SabreTools.Serialization/Wrappers/AACSMediaKeyBlock.cs +++ b/SabreTools.Serialization/Wrappers/AACSMediaKeyBlock.cs @@ -4,7 +4,7 @@ using SabreTools.Data.Models.AACS; namespace SabreTools.Serialization.Wrappers { - public class AACSMediaKeyBlock : WrapperBase + public partial class AACSMediaKeyBlock : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/BDPlusSVM.cs b/SabreTools.Serialization/Wrappers/BDPlusSVM.Printing.cs similarity index 61% rename from SabreTools.Serialization/Printers/BDPlusSVM.cs rename to SabreTools.Serialization/Wrappers/BDPlusSVM.Printing.cs index bc41d332..1d6ad8c1 100644 --- a/SabreTools.Serialization/Printers/BDPlusSVM.cs +++ b/SabreTools.Serialization/Wrappers/BDPlusSVM.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.BDPlus; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class BDPlusSVM : IPrinter + public partial class BDPlusSVM : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, SVM model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, SVM svm) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, SVM svm) { builder.AppendLine("BD+ SVM Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/BDPlusSVM.cs b/SabreTools.Serialization/Wrappers/BDPlusSVM.cs index 9c36acfa..29215926 100644 --- a/SabreTools.Serialization/Wrappers/BDPlusSVM.cs +++ b/SabreTools.Serialization/Wrappers/BDPlusSVM.cs @@ -3,7 +3,7 @@ using SabreTools.Data.Models.BDPlus; namespace SabreTools.Serialization.Wrappers { - public class BDPlusSVM : WrapperBase + public partial class BDPlusSVM : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/BFPK.cs b/SabreTools.Serialization/Wrappers/BFPK.Printing.cs similarity index 80% rename from SabreTools.Serialization/Printers/BFPK.cs rename to SabreTools.Serialization/Wrappers/BFPK.Printing.cs index 5880e877..fb808a4c 100644 --- a/SabreTools.Serialization/Printers/BFPK.cs +++ b/SabreTools.Serialization/Wrappers/BFPK.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.BFPK; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class BFPK : IPrinter + public partial class BFPK : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive archive) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive archive) { builder.AppendLine("BFPK Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/BSP.cs b/SabreTools.Serialization/Wrappers/BSP.Printing.cs similarity index 97% rename from SabreTools.Serialization/Printers/BSP.cs rename to SabreTools.Serialization/Wrappers/BSP.Printing.cs index 52997990..c7be9e62 100644 --- a/SabreTools.Serialization/Printers/BSP.cs +++ b/SabreTools.Serialization/Wrappers/BSP.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.BSP; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class BSP : IPrinter + public partial class BSP : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, BspFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, BspFile file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, BspFile file) { builder.AppendLine("BSP Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/BZip2.cs b/SabreTools.Serialization/Wrappers/BZip2.cs index 8822ec01..a004c791 100644 --- a/SabreTools.Serialization/Wrappers/BZip2.cs +++ b/SabreTools.Serialization/Wrappers/BZip2.cs @@ -77,15 +77,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); - -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Printers/CFB.cs b/SabreTools.Serialization/Wrappers/CFB.Printing.cs similarity index 92% rename from SabreTools.Serialization/Printers/CFB.cs rename to SabreTools.Serialization/Wrappers/CFB.Printing.cs index 23714e9f..9db7012e 100644 --- a/SabreTools.Serialization/Printers/CFB.cs +++ b/SabreTools.Serialization/Wrappers/CFB.Printing.cs @@ -1,16 +1,22 @@ using System; using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.CFB; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class CFB : IPrinter + public partial class CFB : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Binary model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Binary binary) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Binary binary) { builder.AppendLine("Compound File Binary Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/CHD.cs b/SabreTools.Serialization/Wrappers/CHD.Printing.cs similarity index 93% rename from SabreTools.Serialization/Printers/CHD.cs rename to SabreTools.Serialization/Wrappers/CHD.Printing.cs index 49b4b1b3..c32ab8a4 100644 --- a/SabreTools.Serialization/Printers/CHD.cs +++ b/SabreTools.Serialization/Wrappers/CHD.Printing.cs @@ -1,17 +1,23 @@ using System; using System.Collections.Generic; using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.CHD; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class CHD : IPrinter
+ public partial class CHD : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Header model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Header header) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Header header) { builder.AppendLine("CHD Header Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/CHD.cs b/SabreTools.Serialization/Wrappers/CHD.cs index 7c5afd17..854ad394 100644 --- a/SabreTools.Serialization/Wrappers/CHD.cs +++ b/SabreTools.Serialization/Wrappers/CHD.cs @@ -3,7 +3,7 @@ using SabreTools.Data.Models.CHD; namespace SabreTools.Serialization.Wrappers { - public class CHD : WrapperBase
+ public partial class CHD : WrapperBase
{ #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/CIA.cs b/SabreTools.Serialization/Wrappers/CIA.Printing.cs similarity index 97% rename from SabreTools.Serialization/Printers/CIA.cs rename to SabreTools.Serialization/Wrappers/CIA.Printing.cs index 76020192..a1351d15 100644 --- a/SabreTools.Serialization/Printers/CIA.cs +++ b/SabreTools.Serialization/Wrappers/CIA.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.N3DS; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class CIA : IPrinter + public partial class CIA : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Models.N3DS.CIA model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Models.N3DS.CIA cia) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Data.Models.N3DS.CIA cia) { builder.AppendLine("CIA Archive Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/CIA.cs b/SabreTools.Serialization/Wrappers/CIA.cs index 0c82e90b..395b35d1 100644 --- a/SabreTools.Serialization/Wrappers/CIA.cs +++ b/SabreTools.Serialization/Wrappers/CIA.cs @@ -3,7 +3,7 @@ using SabreTools.Data.Models.N3DS; namespace SabreTools.Serialization.Wrappers { - public class CIA : WrapperBase + public partial class CIA : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/GCF.cs b/SabreTools.Serialization/Wrappers/GCF.Printing.cs similarity index 97% rename from SabreTools.Serialization/Printers/GCF.cs rename to SabreTools.Serialization/Wrappers/GCF.Printing.cs index dff703c9..e00372fc 100644 --- a/SabreTools.Serialization/Printers/GCF.cs +++ b/SabreTools.Serialization/Wrappers/GCF.Printing.cs @@ -1,16 +1,22 @@ using System.Collections.Generic; using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.GCF; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class GCF : IPrinter + public partial class GCF : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, File model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, File file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, File file) { builder.AppendLine("GCF Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/GZip.cs b/SabreTools.Serialization/Wrappers/GZip.Printing.cs similarity index 87% rename from SabreTools.Serialization/Printers/GZip.cs rename to SabreTools.Serialization/Wrappers/GZip.Printing.cs index dc88d071..722b222f 100644 --- a/SabreTools.Serialization/Printers/GZip.cs +++ b/SabreTools.Serialization/Wrappers/GZip.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.GZIP; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class GZip : IPrinter + public partial class GZip : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive file) { builder.AppendLine("gzip Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/IPrintable.cs b/SabreTools.Serialization/Wrappers/IPrintable.cs new file mode 100644 index 00000000..97c4ec27 --- /dev/null +++ b/SabreTools.Serialization/Wrappers/IPrintable.cs @@ -0,0 +1,23 @@ +using System.Text; + +namespace SabreTools.Serialization.Wrappers +{ + /// + /// Marks a wrapper as being able to print model information + /// + public interface IPrintable + { +#if NETCOREAPP + /// + /// Export the item information as JSON + /// + string ExportJSON(); +#endif + + /// + /// Print information associated with a model + /// + /// StringBuilder to append information to + void PrintInformation(StringBuilder builder); + } +} diff --git a/SabreTools.Serialization/Printers/IRD.cs b/SabreTools.Serialization/Wrappers/IRD.Printing.cs similarity index 82% rename from SabreTools.Serialization/Printers/IRD.cs rename to SabreTools.Serialization/Wrappers/IRD.Printing.cs index cffb4b61..e03fe7d3 100644 --- a/SabreTools.Serialization/Printers/IRD.cs +++ b/SabreTools.Serialization/Wrappers/IRD.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.IRD; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class IRD : IPrinter + public partial class IRD : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, File model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, File ird) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, File ird) { builder.AppendLine("IRD Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/IRD.cs b/SabreTools.Serialization/Wrappers/IRD.cs index 0168059b..84ac88b3 100644 --- a/SabreTools.Serialization/Wrappers/IRD.cs +++ b/SabreTools.Serialization/Wrappers/IRD.cs @@ -2,7 +2,7 @@ using System.IO; namespace SabreTools.Serialization.Wrappers { - public class IRD : WrapperBase + public partial class IRD : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/ISO9660.cs b/SabreTools.Serialization/Wrappers/ISO9660.Printing.cs similarity index 94% rename from SabreTools.Serialization/Printers/ISO9660.cs rename to SabreTools.Serialization/Wrappers/ISO9660.Printing.cs index f327a7d8..6371d002 100644 --- a/SabreTools.Serialization/Printers/ISO9660.cs +++ b/SabreTools.Serialization/Wrappers/ISO9660.Printing.cs @@ -1,18 +1,23 @@ using System; using System.Collections.Generic; using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.ISO9660; -using SabreTools.Numerics; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class ISO9660 : IPrinter + public partial class ISO9660 : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Volume model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Volume volume) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Volume volume) { builder.AppendLine("ISO 9660 Information:"); builder.AppendLine("-------------------------"); @@ -83,7 +88,7 @@ namespace SabreTools.Data.Printers } private static void Print(StringBuilder builder, BaseVolumeDescriptor vd) - { + { // TOOD: Determine encoding based on vd.Type, svd.EscapeSequence (and manual detection?) if (vd.Type == VolumeDescriptorType.PRIMARY_VOLUME_DESCRIPTOR) @@ -117,7 +122,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(vd.SystemIdentifier, " System Identifier"); builder.AppendLine(vd.VolumeIdentifier, " Volume Identifier"); - + if (vd.Unused8Bytes != null && Array.TrueForAll(vd.Unused8Bytes, b => b == 0)) builder.AppendLine("Zeroed", " Unused 8 Bytes"); else @@ -146,7 +151,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(vd.OptionalPathTableLocationL, " Optional Type-L Path Table Location"); builder.AppendLine(vd.PathTableLocationM, " Type-M Path Table Location"); builder.AppendLine(vd.OptionalPathTableLocationM, " Optional Type-M Path Table Location"); - + builder.AppendLine(" Root Directory Record:"); Print(builder, vd.RootDirectoryRecord); @@ -342,7 +347,7 @@ namespace SabreTools.Data.Printers return; } - foreach(var kvp in dirs) + foreach (var kvp in dirs) { builder.AppendLine($" Directory at Sector {kvp.Key}"); builder.AppendLine(" -------------------------"); @@ -394,7 +399,7 @@ namespace SabreTools.Data.Printers builder.AppendLineBothEndian(dr.ExtentLength, " Extent Length"); Print(builder, dr.RecordingDateTime); - + builder.AppendLine(" File Flags:"); builder.AppendLine((dr.FileFlags & FileFlags.EXISTENCE) == FileFlags.EXISTENCE, " Existence"); builder.AppendLine((dr.FileFlags & FileFlags.DIRECTORY) == FileFlags.DIRECTORY, " Directory"); @@ -413,7 +418,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(dr.FileIdentifierLength, " File Identifier Length"); builder.AppendLine(dr.FileIdentifier, " File Identifier"); builder.AppendLine(dr.PaddingField, " Padding Field"); - + if (dr.SystemUse == null || dr.SystemUse.Length == 0) builder.AppendLine(dr.SystemUse, " System Use"); else if (Array.TrueForAll(dr.SystemUse, b => b == 0)) @@ -437,7 +442,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(drdt.Hour, " Hour"); builder.AppendLine(drdt.Minute, " Minute"); builder.AppendLine(drdt.Second, " Second"); - string tz = $"{((drdt.TimezoneOffset-48)*15/60):+0;-0}:{((drdt.TimezoneOffset-48)*15%60+60)%60:00} (0x{drdt.TimezoneOffset.ToString("X2")})"; + string tz = $"{((drdt.TimezoneOffset - 48) * 15 / 60):+0;-0}:{((drdt.TimezoneOffset - 48) * 15 % 60 + 60) % 60:00} (0x{drdt.TimezoneOffset.ToString("X2")})"; builder.AppendLine(tz, " Timezone Offset"); } @@ -450,7 +455,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(" [NULL]"); return; } - + if (IsDigits(dt.Year)) builder.AppendLine(Encoding.ASCII.GetString(dt.Year), " Year"); else @@ -479,7 +484,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(Encoding.ASCII.GetString(dt.Centisecond), " Centisecond"); else builder.AppendLine(dt.Centisecond, " Centisecond"); - string tz = $"{((dt.TimezoneOffset-48)*15/60):+0;-0}:{((dt.TimezoneOffset-48)*15%60+60)%60:00} (0x{dt.TimezoneOffset.ToString("X2")})"; + string tz = $"{((dt.TimezoneOffset - 48) * 15 / 60):+0;-0}:{((dt.TimezoneOffset - 48) * 15 % 60 + 60) % 60:00} (0x{dt.TimezoneOffset.ToString("X2")})"; builder.AppendLine(tz, " Timezone Offset"); } diff --git a/SabreTools.Serialization/Wrappers/ISO9660.cs b/SabreTools.Serialization/Wrappers/ISO9660.cs index cc9a6c3c..169324e3 100644 --- a/SabreTools.Serialization/Wrappers/ISO9660.cs +++ b/SabreTools.Serialization/Wrappers/ISO9660.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using SabreTools.Data.Models.ISO9660; @@ -16,19 +15,13 @@ namespace SabreTools.Serialization.Wrappers #region Extension Properties - /// - /// Volume Descriptors - /// + /// public VolumeDescriptor[] VolumeDescriptorSet => Model.VolumeDescriptorSet ?? []; - /// - /// Path Tables - /// + /// public PathTableGroup[] PathTableGroups => Model.PathTableGroups ?? []; - /// - /// Directory Descriptors - /// + /// public Dictionary DirectoryDescriptors => Model.DirectoryDescriptors ?? []; #endregion diff --git a/SabreTools.Serialization/Wrappers/IWrapper.cs b/SabreTools.Serialization/Wrappers/IWrapper.cs index 35f9a61d..719e01e0 100644 --- a/SabreTools.Serialization/Wrappers/IWrapper.cs +++ b/SabreTools.Serialization/Wrappers/IWrapper.cs @@ -9,12 +9,5 @@ namespace SabreTools.Serialization.Wrappers /// Get a human-readable description of the wrapper /// string Description(); - -#if NETCOREAPP - /// - /// Export the item information as JSON - /// - string ExportJSON(); -#endif } } diff --git a/SabreTools.Serialization/Printers/InstallShieldArchiveV3.cs b/SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.Printing.cs similarity index 90% rename from SabreTools.Serialization/Printers/InstallShieldArchiveV3.cs rename to SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.Printing.cs index e0222049..0b1919c8 100644 --- a/SabreTools.Serialization/Printers/InstallShieldArchiveV3.cs +++ b/SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.InstallShieldArchiveV3; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class InstallShieldArchiveV3 : IPrinter + public partial class InstallShieldArchiveV3 : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive archive) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive archive) { builder.AppendLine("InstallShield Archive V3 Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/InstallShieldCabinet.cs b/SabreTools.Serialization/Wrappers/InstallShieldCabinet.Printing.cs similarity index 97% rename from SabreTools.Serialization/Printers/InstallShieldCabinet.cs rename to SabreTools.Serialization/Wrappers/InstallShieldCabinet.Printing.cs index 221c8510..182e1da2 100644 --- a/SabreTools.Serialization/Printers/InstallShieldCabinet.cs +++ b/SabreTools.Serialization/Wrappers/InstallShieldCabinet.Printing.cs @@ -1,16 +1,22 @@ using System.Collections.Generic; using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.InstallShieldCabinet; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class InstallShieldCabinet : IPrinter + public partial class InstallShieldCabinet : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Cabinet model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Cabinet cabinet) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Cabinet cabinet) { builder.AppendLine("InstallShield Cabinet Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/LDSCRYPT.cs b/SabreTools.Serialization/Wrappers/LDSCRYPT.cs index ca62f6d6..59e6533a 100644 --- a/SabreTools.Serialization/Wrappers/LDSCRYPT.cs +++ b/SabreTools.Serialization/Wrappers/LDSCRYPT.cs @@ -77,15 +77,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); - -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Printers/LZKWAJ.cs b/SabreTools.Serialization/Wrappers/LZKWAJ.Printing.cs similarity index 83% rename from SabreTools.Serialization/Printers/LZKWAJ.cs rename to SabreTools.Serialization/Wrappers/LZKWAJ.Printing.cs index eed019f4..1e46574e 100644 --- a/SabreTools.Serialization/Printers/LZKWAJ.cs +++ b/SabreTools.Serialization/Wrappers/LZKWAJ.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.LZ; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class LZKWAJ : IPrinter + public partial class LZKWAJ : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, KWAJFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, KWAJFile file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, KWAJFile file) { builder.AppendLine("LZ-compressed File, KWAJ Variant Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/LZQBasic.cs b/SabreTools.Serialization/Wrappers/LZQBasic.Printing.cs similarity index 66% rename from SabreTools.Serialization/Printers/LZQBasic.cs rename to SabreTools.Serialization/Wrappers/LZQBasic.Printing.cs index dc7df664..431af9c6 100644 --- a/SabreTools.Serialization/Printers/LZQBasic.cs +++ b/SabreTools.Serialization/Wrappers/LZQBasic.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.LZ; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class LZQBasic : IPrinter + public partial class LZQBasic : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, QBasicFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, QBasicFile file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, QBasicFile file) { builder.AppendLine("LZ-compressed File, QBasic Variant Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/LZSZDD.cs b/SabreTools.Serialization/Wrappers/LZSZDD.Printing.cs similarity index 70% rename from SabreTools.Serialization/Printers/LZSZDD.cs rename to SabreTools.Serialization/Wrappers/LZSZDD.Printing.cs index 298bc2a4..9e6419e0 100644 --- a/SabreTools.Serialization/Printers/LZSZDD.cs +++ b/SabreTools.Serialization/Wrappers/LZSZDD.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.LZ; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class LZSZDD : IPrinter + public partial class LZSZDD : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, SZDDFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, SZDDFile file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, SZDDFile file) { builder.AppendLine("LZ-compressed File, SZDD Variant Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/LinearExecutable.cs b/SabreTools.Serialization/Wrappers/LinearExecutable.Printing.cs similarity index 98% rename from SabreTools.Serialization/Printers/LinearExecutable.cs rename to SabreTools.Serialization/Wrappers/LinearExecutable.Printing.cs index 309b87b7..2b5bf506 100644 --- a/SabreTools.Serialization/Printers/LinearExecutable.cs +++ b/SabreTools.Serialization/Wrappers/LinearExecutable.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.LinearExecutable; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class LinearExecutable : IPrinter + public partial class LinearExecutable : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Executable model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Executable executable) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Executable executable) { builder.AppendLine("New Executable Information:"); builder.AppendLine("-------------------------"); @@ -40,7 +46,7 @@ namespace SabreTools.Data.Printers Print(builder, executable.DebugInformation); } - private static void Print(StringBuilder builder, Models.MSDOS.ExecutableHeader? header) + private static void Print(StringBuilder builder, Data.Models.MSDOS.ExecutableHeader? header) { builder.AppendLine(" MS-DOS Stub Header Information:"); builder.AppendLine(" -------------------------"); diff --git a/SabreTools.Serialization/Wrappers/LinearExecutable.cs b/SabreTools.Serialization/Wrappers/LinearExecutable.cs index 81ddb060..c8fff0f8 100644 --- a/SabreTools.Serialization/Wrappers/LinearExecutable.cs +++ b/SabreTools.Serialization/Wrappers/LinearExecutable.cs @@ -5,7 +5,7 @@ using SabreTools.IO.Extensions; namespace SabreTools.Serialization.Wrappers { - public class LinearExecutable : WrapperBase + public partial class LinearExecutable : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/MSDOS.cs b/SabreTools.Serialization/Wrappers/MSDOS.Printing.cs similarity index 85% rename from SabreTools.Serialization/Printers/MSDOS.cs rename to SabreTools.Serialization/Wrappers/MSDOS.Printing.cs index c04747b0..ec02cad5 100644 --- a/SabreTools.Serialization/Printers/MSDOS.cs +++ b/SabreTools.Serialization/Wrappers/MSDOS.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.MSDOS; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class MSDOS : IPrinter + public partial class MSDOS : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Executable model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Executable executable) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Executable executable) { builder.AppendLine("MS-DOS Executable Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/MSDOS.cs b/SabreTools.Serialization/Wrappers/MSDOS.cs index d4acaf71..f8606cad 100644 --- a/SabreTools.Serialization/Wrappers/MSDOS.cs +++ b/SabreTools.Serialization/Wrappers/MSDOS.cs @@ -3,7 +3,7 @@ using SabreTools.Data.Models.MSDOS; namespace SabreTools.Serialization.Wrappers { - public class MSDOS : WrapperBase + public partial class MSDOS : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/MicrosoftCabinet.cs b/SabreTools.Serialization/Wrappers/MicrosoftCabinet.Printing.cs similarity index 93% rename from SabreTools.Serialization/Printers/MicrosoftCabinet.cs rename to SabreTools.Serialization/Wrappers/MicrosoftCabinet.Printing.cs index d3ea45d8..3b5fae77 100644 --- a/SabreTools.Serialization/Printers/MicrosoftCabinet.cs +++ b/SabreTools.Serialization/Wrappers/MicrosoftCabinet.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.MicrosoftCabinet; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class MicrosoftCabinet : IPrinter + public partial class MicrosoftCabinet : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Cabinet model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Cabinet cabinet) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Cabinet cabinet) { builder.AppendLine("Microsoft Cabinet Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/MoPaQ.cs b/SabreTools.Serialization/Wrappers/MoPaQ.Printing.cs similarity index 95% rename from SabreTools.Serialization/Printers/MoPaQ.cs rename to SabreTools.Serialization/Wrappers/MoPaQ.Printing.cs index 6e78296d..f10aaea9 100644 --- a/SabreTools.Serialization/Printers/MoPaQ.cs +++ b/SabreTools.Serialization/Wrappers/MoPaQ.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.MoPaQ; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class MoPaQ : IPrinter + public partial class MoPaQ : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive archive) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive archive) { builder.AppendLine("MoPaQ Archive Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/N3DS.cs b/SabreTools.Serialization/Wrappers/N3DS.Printing.cs similarity index 98% rename from SabreTools.Serialization/Printers/N3DS.cs rename to SabreTools.Serialization/Wrappers/N3DS.Printing.cs index 18463152..9a2c8d29 100644 --- a/SabreTools.Serialization/Printers/N3DS.cs +++ b/SabreTools.Serialization/Wrappers/N3DS.Printing.cs @@ -1,16 +1,22 @@ using System; using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.N3DS; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class N3DS : IPrinter + public partial class N3DS : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Cart model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Cart cart) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Cart cart) { builder.AppendLine("3DS Cart Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/NCF.cs b/SabreTools.Serialization/Wrappers/NCF.Printing.cs similarity index 96% rename from SabreTools.Serialization/Printers/NCF.cs rename to SabreTools.Serialization/Wrappers/NCF.Printing.cs index b664dbdb..f4fa454e 100644 --- a/SabreTools.Serialization/Printers/NCF.cs +++ b/SabreTools.Serialization/Wrappers/NCF.Printing.cs @@ -1,16 +1,22 @@ using System.Collections.Generic; using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.NCF; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class NCF : IPrinter + public partial class NCF : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, File model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, File file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, File file) { builder.AppendLine("NCF Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/NCF.cs b/SabreTools.Serialization/Wrappers/NCF.cs index 6e18b965..e0ba1e7a 100644 --- a/SabreTools.Serialization/Wrappers/NCF.cs +++ b/SabreTools.Serialization/Wrappers/NCF.cs @@ -2,7 +2,7 @@ using System.IO; namespace SabreTools.Serialization.Wrappers { - public class NCF : WrapperBase + public partial class NCF : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/NewExecutable.cs b/SabreTools.Serialization/Wrappers/NewExecutable.Printing.cs similarity index 96% rename from SabreTools.Serialization/Printers/NewExecutable.cs rename to SabreTools.Serialization/Wrappers/NewExecutable.Printing.cs index 943646dd..30480a16 100644 --- a/SabreTools.Serialization/Printers/NewExecutable.cs +++ b/SabreTools.Serialization/Wrappers/NewExecutable.Printing.cs @@ -3,15 +3,20 @@ using System.Text; using SabreTools.Data.Extensions; using SabreTools.Data.Models.NewExecutable; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class NewExecutable : IPrinter + public partial class NewExecutable : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Executable model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Executable executable) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Executable executable) { builder.AppendLine("New Executable Information:"); builder.AppendLine("-------------------------"); @@ -33,7 +38,7 @@ namespace SabreTools.Data.Printers Print(builder, executable.NonResidentNameTable); } - private static void Print(StringBuilder builder, Models.MSDOS.ExecutableHeader? header) + private static void Print(StringBuilder builder, Data.Models.MSDOS.ExecutableHeader? header) { builder.AppendLine(" MS-DOS Stub Header Information:"); builder.AppendLine(" -------------------------"); @@ -242,7 +247,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, ModuleReferenceTableEntry[]? entries, Models.MSDOS.ExecutableHeader? stub, ExecutableHeader? header) + private static void Print(StringBuilder builder, ModuleReferenceTableEntry[]? entries, Data.Models.MSDOS.ExecutableHeader? stub, ExecutableHeader? header) { builder.AppendLine(" Module-Reference Table Information:"); builder.AppendLine(" -------------------------"); diff --git a/SabreTools.Serialization/Printers/Nitro.cs b/SabreTools.Serialization/Wrappers/Nitro.Printing.cs similarity index 96% rename from SabreTools.Serialization/Printers/Nitro.cs rename to SabreTools.Serialization/Wrappers/Nitro.Printing.cs index fbf37801..ef6a6e08 100644 --- a/SabreTools.Serialization/Printers/Nitro.cs +++ b/SabreTools.Serialization/Wrappers/Nitro.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.Nitro; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class Nitro : IPrinter + public partial class Nitro : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Cart model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Cart cart) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Cart cart) { builder.AppendLine("NDS Cart Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/PAK.cs b/SabreTools.Serialization/Wrappers/PAK.Printing.cs similarity index 80% rename from SabreTools.Serialization/Printers/PAK.cs rename to SabreTools.Serialization/Wrappers/PAK.Printing.cs index 7e3e5538..da42002e 100644 --- a/SabreTools.Serialization/Printers/PAK.cs +++ b/SabreTools.Serialization/Wrappers/PAK.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.PAK; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class PAK : IPrinter + public partial class PAK : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, File model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, File file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, File file) { builder.AppendLine("PAK Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/PFF.cs b/SabreTools.Serialization/Wrappers/PFF.Printing.cs similarity index 86% rename from SabreTools.Serialization/Printers/PFF.cs rename to SabreTools.Serialization/Wrappers/PFF.Printing.cs index 4fc83d8d..f9483f68 100644 --- a/SabreTools.Serialization/Printers/PFF.cs +++ b/SabreTools.Serialization/Wrappers/PFF.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.PFF; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class PFF : IPrinter + public partial class PFF : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive archive) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive archive) { builder.AppendLine("PFF Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/PIC.cs b/SabreTools.Serialization/Wrappers/PIC.Printing.cs similarity index 87% rename from SabreTools.Serialization/Printers/PIC.cs rename to SabreTools.Serialization/Wrappers/PIC.Printing.cs index 8c3e5584..69ddc919 100644 --- a/SabreTools.Serialization/Printers/PIC.cs +++ b/SabreTools.Serialization/Wrappers/PIC.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.PIC; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class PIC : IPrinter + public partial class PIC : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, DiscInformation model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, DiscInformation di) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, DiscInformation di) { builder.AppendLine("PIC Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/PIC.cs b/SabreTools.Serialization/Wrappers/PIC.cs index d9c85dbc..7b6fcb2c 100644 --- a/SabreTools.Serialization/Wrappers/PIC.cs +++ b/SabreTools.Serialization/Wrappers/PIC.cs @@ -3,7 +3,7 @@ using SabreTools.Data.Models.PIC; namespace SabreTools.Serialization.Wrappers { - public class PIC : WrapperBase + public partial class PIC : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/PKZIP.cs b/SabreTools.Serialization/Wrappers/PKZIP.Printing.cs similarity index 97% rename from SabreTools.Serialization/Printers/PKZIP.cs rename to SabreTools.Serialization/Wrappers/PKZIP.Printing.cs index 091444eb..21ac6073 100644 --- a/SabreTools.Serialization/Printers/PKZIP.cs +++ b/SabreTools.Serialization/Wrappers/PKZIP.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.PKZIP; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class PKZIP : IPrinter + public partial class PKZIP : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive archive) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive archive) { builder.AppendLine("PKZIP Archive (or Derived Format) Information:"); builder.AppendLine("-------------------------"); @@ -279,7 +285,7 @@ namespace SabreTools.Data.Printers var entry = entries[i]; builder.AppendLine($" Extra Field {i}:"); - builder.AppendLine($" Header ID: {entry.HeaderID} (0x{(byte)entry.HeaderID:X4})"); + builder.AppendLine($" Header ID: {entry.HeaderID} (0x{(ushort)entry.HeaderID:X4})"); builder.AppendLine(entry.DataSize, " Data size"); switch (entry) { diff --git a/SabreTools.Serialization/Printers/PlayJAudioFile.cs b/SabreTools.Serialization/Wrappers/PlayJAudioFile.Printing.cs similarity index 94% rename from SabreTools.Serialization/Printers/PlayJAudioFile.cs rename to SabreTools.Serialization/Wrappers/PlayJAudioFile.Printing.cs index ebc8b8de..05c935cf 100644 --- a/SabreTools.Serialization/Printers/PlayJAudioFile.cs +++ b/SabreTools.Serialization/Wrappers/PlayJAudioFile.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.PlayJ; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class PlayJAudioFile : IPrinter + public partial class PlayJAudioFile : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, AudioFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, AudioFile audio) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, AudioFile audio) { builder.AppendLine("PlayJ Audio File Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/PlayJAudioFile.cs b/SabreTools.Serialization/Wrappers/PlayJAudioFile.cs index d1dc9dfc..3eed12ac 100644 --- a/SabreTools.Serialization/Wrappers/PlayJAudioFile.cs +++ b/SabreTools.Serialization/Wrappers/PlayJAudioFile.cs @@ -2,7 +2,7 @@ using System.IO; namespace SabreTools.Serialization.Wrappers { - public class PlayJAudioFile : WrapperBase + public partial class PlayJAudioFile : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/PlayJPlaylist.cs b/SabreTools.Serialization/Wrappers/PlayJPlaylist.Printing.cs similarity index 95% rename from SabreTools.Serialization/Printers/PlayJPlaylist.cs rename to SabreTools.Serialization/Wrappers/PlayJPlaylist.Printing.cs index d086ec0d..86976b0b 100644 --- a/SabreTools.Serialization/Printers/PlayJPlaylist.cs +++ b/SabreTools.Serialization/Wrappers/PlayJPlaylist.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.PlayJ; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class PlayJPlaylist : IPrinter + public partial class PlayJPlaylist : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Playlist model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Playlist playlist) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Playlist playlist) { builder.AppendLine("PlayJ Playlist Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/PlayJPlaylist.cs b/SabreTools.Serialization/Wrappers/PlayJPlaylist.cs index e4453e4c..beacc6e6 100644 --- a/SabreTools.Serialization/Wrappers/PlayJPlaylist.cs +++ b/SabreTools.Serialization/Wrappers/PlayJPlaylist.cs @@ -2,7 +2,7 @@ using System.IO; namespace SabreTools.Serialization.Wrappers { - public class PlayJPlaylist : WrapperBase + public partial class PlayJPlaylist : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/PortableExecutable.cs b/SabreTools.Serialization/Wrappers/PortableExecutable.Printing.cs similarity index 93% rename from SabreTools.Serialization/Printers/PortableExecutable.cs rename to SabreTools.Serialization/Wrappers/PortableExecutable.Printing.cs index 474f1307..41ee57ee 100644 --- a/SabreTools.Serialization/Printers/PortableExecutable.cs +++ b/SabreTools.Serialization/Wrappers/PortableExecutable.Printing.cs @@ -9,15 +9,20 @@ using SabreTools.Data.Models.PortableExecutable; using SabreTools.Data.Models.PortableExecutable.Resource.Entries; using SabreTools.IO.Extensions; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class PortableExecutable : IPrinter + public partial class PortableExecutable : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Executable model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Executable executable) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Executable executable) { builder.AppendLine("Portable Executable Information:"); builder.AppendLine("-------------------------"); @@ -59,7 +64,7 @@ namespace SabreTools.Data.Printers Print(builder, executable.DebugTable); } - private static void Print(StringBuilder builder, Models.MSDOS.ExecutableHeader? header) + private static void Print(StringBuilder builder, Data.Models.MSDOS.ExecutableHeader? header) { builder.AppendLine(" MS-DOS Stub Header Information:"); builder.AppendLine(" -------------------------"); @@ -118,7 +123,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.OptionalHeader? header, SectionHeader[]? table) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.OptionalHeader? header, SectionHeader[]? table) { builder.AppendLine(" Optional Header Information:"); builder.AppendLine(" -------------------------"); @@ -416,7 +421,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(entry.Reserved2, " Reserved"); } - private static void Print(StringBuilder builder, Models.COFF.StringTable? stringTable) + private static void Print(StringBuilder builder, Data.Models.COFF.StringTable? stringTable) { builder.AppendLine(" String Table Information:"); builder.AppendLine(" -------------------------"); @@ -438,7 +443,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.AttributeCertificate.Entry[]? entries) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.AttributeCertificate.Entry[]? entries) { builder.AppendLine(" Attribute Certificate Table Information:"); builder.AppendLine(" -------------------------"); @@ -479,7 +484,7 @@ namespace SabreTools.Data.Printers } else { - foreach (Models.ASN1.TypeLengthValue tlv in topLevelValues) + foreach (Data.Models.ASN1.TypeLengthValue tlv in topLevelValues) { string tlvString = tlv.Format(paddingLevel: 4); builder.AppendLine(tlvString); @@ -505,7 +510,7 @@ namespace SabreTools.Data.Printers } } - private static void Print(StringBuilder builder, Models.PortableExecutable.DelayLoad.DirectoryTable? table, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.DelayLoad.DirectoryTable? table, SectionHeader[]? sections) { builder.AppendLine(" Delay-Load Directory Table Information:"); builder.AppendLine(" -------------------------"); @@ -532,7 +537,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.BaseRelocation.Block[]? entries, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.BaseRelocation.Block[]? entries, SectionHeader[]? sections) { builder.AppendLine(" Base Relocation Table Information:"); builder.AppendLine(" -------------------------"); @@ -575,7 +580,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.DebugData.Table? table) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.DebugData.Table? table) { builder.AppendLine(" Debug Table Information:"); builder.AppendLine(" -------------------------"); @@ -604,7 +609,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Export.DirectoryTable? table, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.DirectoryTable? table, SectionHeader[]? sections) { builder.AppendLine(value: " Export Directory Table Information:"); builder.AppendLine(" -------------------------"); @@ -634,7 +639,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Export.AddressTableEntry[]? table, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.AddressTableEntry[]? table, SectionHeader[]? sections) { builder.AppendLine(" Export Address Table Information:"); builder.AppendLine(" -------------------------"); @@ -657,7 +662,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Export.NamePointerTable? table) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.NamePointerTable? table) { builder.AppendLine(" Export Name Pointer Table Information:"); builder.AppendLine(" -------------------------"); @@ -679,7 +684,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Export.OrdinalTable? table) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.OrdinalTable? table) { builder.AppendLine(" Export Ordinal Table Information:"); builder.AppendLine(" -------------------------"); @@ -701,7 +706,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Export.NameTable? table) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Export.NameTable? table) { builder.AppendLine(" Export Name Table Information:"); builder.AppendLine(" -------------------------"); @@ -723,7 +728,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Import.DirectoryTableEntry[]? table, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Import.DirectoryTableEntry[]? table, SectionHeader[]? sections) { builder.AppendLine(" Import Directory Table Information:"); builder.AppendLine(" -------------------------"); @@ -753,7 +758,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[]? sections) { builder.AppendLine(" Import Lookup Tables Information:"); builder.AppendLine(" -------------------------"); @@ -799,7 +804,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Dictionary? tables, SectionHeader[]? sections) { builder.AppendLine(" Import Address Tables Information:"); builder.AppendLine(" -------------------------"); @@ -845,7 +850,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Import.HintNameTableEntry[]? table) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Import.HintNameTableEntry[]? table) { builder.AppendLine(" Import Hint/Name Table Information:"); builder.AppendLine(" -------------------------"); @@ -868,7 +873,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Resource.DirectoryTable? table, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Resource.DirectoryTable? table, SectionHeader[]? sections) { builder.AppendLine(" Resource Directory Table Information:"); builder.AppendLine(" -------------------------"); @@ -883,7 +888,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Resource.DirectoryTable table, int level, List types, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Resource.DirectoryTable table, int level, List types, SectionHeader[]? sections) { string padding = new(' ', (level + 1) * 2); @@ -923,7 +928,7 @@ namespace SabreTools.Data.Printers } } - private static void Print(StringBuilder builder, Models.PortableExecutable.Resource.DirectoryEntry entry, int level, List types, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Resource.DirectoryEntry entry, int level, List types, SectionHeader[]? sections) { string padding = new(' ', (level + 1) * 2); @@ -944,7 +949,7 @@ namespace SabreTools.Data.Printers Print(builder, entry.Subdirectory, level: level + 1, types, sections); } - private static void Print(StringBuilder builder, Models.PortableExecutable.Resource.DataEntry entry, int level, List types, SectionHeader[]? sections) + private static void Print(StringBuilder builder, Data.Models.PortableExecutable.Resource.DataEntry entry, int level, List types, SectionHeader[]? sections) { string padding = new(' ', (level + 1) * 2); @@ -1040,25 +1045,25 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } - private static void PrintResourceRT_CURSOR(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_CURSOR(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Hardware-dependent cursor resource found, not parsed yet"); } - private static void PrintResourceRT_BITMAP(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_BITMAP(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Bitmap resource found, not parsed yet"); } - private static void PrintResourceRT_ICON(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_ICON(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Hardware-dependent icon resource found, not parsed yet"); } - private static void PrintResourceRT_MENU(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_MENU(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1136,7 +1141,7 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceRT_DIALOG(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_DIALOG(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1271,7 +1276,7 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceRT_STRING(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_STRING(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1291,19 +1296,19 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceRT_FONTDIR(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_FONTDIR(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Font directory resource found, not parsed yet"); } - private static void PrintResourceRT_FONT(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_FONT(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Font resource found, not parsed yet"); } - private static void PrintResourceRT_ACCELERATOR(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_ACCELERATOR(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1326,7 +1331,7 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceRT_RCDATA(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_RCDATA(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Application-defined resource found, not parsed yet"); @@ -1361,11 +1366,11 @@ namespace SabreTools.Data.Printers { builder.AppendLine($"{padding}Data: [Embedded spanned PKZIP file]"); // TODO: Parse this out and print separately } - else if (magic.StartsWith(Models.RAR.Constants.OldSignatureBytes)) + else if (magic.StartsWith(Data.Models.RAR.Constants.OldSignatureBytes)) { builder.AppendLine($"{padding}Data: [Embedded RAR file]"); // TODO: Parse this out and print separately } - else if (magic.StartsWith(Models.RAR.Constants.NewSignatureBytes)) + else if (magic.StartsWith(Data.Models.RAR.Constants.NewSignatureBytes)) { builder.AppendLine($"{padding}Data: [Embedded RAR5 file]"); // TODO: Parse this out and print separately } @@ -1385,7 +1390,7 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceRT_MESSAGETABLE(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_MESSAGETABLE(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1452,19 +1457,19 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceRT_GROUP_CURSOR(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_GROUP_CURSOR(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Hardware-independent cursor resource found, not parsed yet"); } - private static void PrintResourceRT_GROUP_ICON(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_GROUP_ICON(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Hardware-independent icon resource found, not parsed yet"); } - private static void PrintResourceRT_VERSION(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_VERSION(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1585,37 +1590,37 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceRT_DLGINCLUDE(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_DLGINCLUDE(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}External header resource found, not parsed yet"); } - private static void PrintResourceRT_PLUGPLAY(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_PLUGPLAY(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Plug and Play resource found, not parsed yet"); } - private static void PrintResourceRT_VXD(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_VXD(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}VXD found, not parsed yet"); } - private static void PrintResourceRT_ANICURSOR(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_ANICURSOR(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Animated cursor found, not parsed yet"); } - private static void PrintResourceRT_ANIICON(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_ANIICON(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}Animated icon found, not parsed yet"); } - private static void PrintResourceRT_HTML(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_HTML(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); builder.AppendLine($"{padding}HTML resource found, not parsed yet"); @@ -1628,7 +1633,7 @@ namespace SabreTools.Data.Printers // builder.AppendLine(Encoding.Unicode.GetString(entry.Data), $"{padding}Value (Unicode)"); } - private static void PrintResourceRT_MANIFEST(Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) + private static void PrintResourceRT_MANIFEST(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1805,7 +1810,7 @@ namespace SabreTools.Data.Printers } } - private static void PrintResourceUNKNOWN(Models.PortableExecutable.Resource.DataEntry entry, int level, object resourceType, StringBuilder builder) + private static void PrintResourceUNKNOWN(Data.Models.PortableExecutable.Resource.DataEntry entry, int level, object resourceType, StringBuilder builder) { string padding = new(' ', (level + 1) * 2); @@ -1847,11 +1852,11 @@ namespace SabreTools.Data.Printers { builder.AppendLine($"{padding}Data: [Embedded spanned PKZIP file]"); // TODO: Parse this out and print separately } - else if (magic.StartsWith(Models.RAR.Constants.OldSignatureBytes)) + else if (magic.StartsWith(Data.Models.RAR.Constants.OldSignatureBytes)) { builder.AppendLine($"{padding}Data: [Embedded RAR file]"); // TODO: Parse this out and print separately } - else if (magic.StartsWith(Models.RAR.Constants.NewSignatureBytes)) + else if (magic.StartsWith(Data.Models.RAR.Constants.NewSignatureBytes)) { builder.AppendLine($"{padding}Data: [Embedded RAR5 file]"); // TODO: Parse this out and print separately } diff --git a/SabreTools.Serialization/Printers/Quantum.cs b/SabreTools.Serialization/Wrappers/Quantum.Printing.cs similarity index 85% rename from SabreTools.Serialization/Printers/Quantum.cs rename to SabreTools.Serialization/Wrappers/Quantum.Printing.cs index b041a42c..9995ee77 100644 --- a/SabreTools.Serialization/Printers/Quantum.cs +++ b/SabreTools.Serialization/Wrappers/Quantum.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.Quantum; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class Quantum : IPrinter + public partial class Quantum : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive archive) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive archive) { builder.AppendLine("Quantum Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/RAR.cs b/SabreTools.Serialization/Wrappers/RAR.cs index 68cc822b..e083c6cf 100644 --- a/SabreTools.Serialization/Wrappers/RAR.cs +++ b/SabreTools.Serialization/Wrappers/RAR.cs @@ -77,14 +77,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Wrappers/RealArcadeInstaller.cs b/SabreTools.Serialization/Wrappers/RealArcadeInstaller.cs index fc4ce219..d2346e9f 100644 --- a/SabreTools.Serialization/Wrappers/RealArcadeInstaller.cs +++ b/SabreTools.Serialization/Wrappers/RealArcadeInstaller.cs @@ -77,14 +77,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Wrappers/RealArcadeMezzanine.cs b/SabreTools.Serialization/Wrappers/RealArcadeMezzanine.cs index 59bbfd39..bc916228 100644 --- a/SabreTools.Serialization/Wrappers/RealArcadeMezzanine.cs +++ b/SabreTools.Serialization/Wrappers/RealArcadeMezzanine.cs @@ -77,14 +77,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Wrappers/SFFS.Printing.cs b/SabreTools.Serialization/Wrappers/SFFS.Printing.cs new file mode 100644 index 00000000..7d8cd7a9 --- /dev/null +++ b/SabreTools.Serialization/Wrappers/SFFS.Printing.cs @@ -0,0 +1,92 @@ +using System.Text; +using SabreTools.Data.Extensions; +using SabreTools.Data.Models.StarForce; + +namespace SabreTools.Serialization.Wrappers +{ + public partial class SFFS : IPrintable + { +#if NETCOREAPP + /// + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif + + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, FileSystem fs) + { + builder.AppendLine("StarForce File System Information:"); + builder.AppendLine("-------------------------"); + builder.AppendLine(); + + Print(builder, fs.Header); + Print(builder, fs.Files); + Print(builder, fs.FileHeaders); + } + + private static void Print(StringBuilder builder, Header? header) + { + builder.AppendLine(" Header Information:"); + builder.AppendLine(" -------------------------"); + if (header == null) + { + builder.AppendLine(" No header"); + builder.AppendLine(); + return; + } + + builder.AppendLine(header.Magic, " Magic"); + builder.AppendLine(header.Version, " Version"); + builder.AppendLine(header.FileCount, " FileCount"); + builder.AppendLine(); + } + + private static void Print(StringBuilder builder, FileEntry[]? entries) + { + builder.AppendLine(" File Entries Information:"); + builder.AppendLine(" -------------------------"); + if (entries == null || entries.Length == 0) + { + builder.AppendLine(" No file entries"); + builder.AppendLine(); + return; + } + + for (int i = 0; i < entries.Length; i++) + { + var file = entries[i]; + + builder.AppendLine($" File {i}"); + builder.AppendLine(file.FilenameMD5Hash, " Filename MD5 hash"); + builder.AppendLine(file.FileHeaderIndex, " File header index"); + } + + builder.AppendLine(); + } + + private static void Print(StringBuilder builder, FileHeader[]? entries) + { + builder.AppendLine(" File Headers Information:"); + builder.AppendLine(" -------------------------"); + if (entries == null || entries.Length == 0) + { + builder.AppendLine(" No file headers"); + builder.AppendLine(); + return; + } + + for (int i = 0; i < entries.Length; i++) + { + var file = entries[i]; + + builder.AppendLine($" File {i}"); + builder.AppendLine(file.FileContentStart, " File content start"); + builder.AppendLine(file.FileInfo, " File info"); + } + + builder.AppendLine(); + } + } +} diff --git a/SabreTools.Serialization/Wrappers/SFFS.cs b/SabreTools.Serialization/Wrappers/SFFS.cs index 8062e57f..c02e9385 100644 --- a/SabreTools.Serialization/Wrappers/SFFS.cs +++ b/SabreTools.Serialization/Wrappers/SFFS.cs @@ -9,7 +9,7 @@ namespace SabreTools.Serialization.Wrappers /// types that typically do not have models. /// /// TODO: Hook up the models to a proper deserializer - public class SFFS : WrapperBase + public partial class SFFS : WrapperBase { #region Descriptive Properties @@ -78,14 +78,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Printers/SGA.cs b/SabreTools.Serialization/Wrappers/SGA.Printing.cs similarity index 97% rename from SabreTools.Serialization/Printers/SGA.cs rename to SabreTools.Serialization/Wrappers/SGA.Printing.cs index d8d05e32..b7393b3f 100644 --- a/SabreTools.Serialization/Printers/SGA.cs +++ b/SabreTools.Serialization/Wrappers/SGA.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.SGA; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class SGA : IPrinter + public partial class SGA : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive file) { builder.AppendLine("SGA Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/SecuROMDFA.cs b/SabreTools.Serialization/Wrappers/SecuROMDFA.Printing.cs similarity index 77% rename from SabreTools.Serialization/Printers/SecuROMDFA.cs rename to SabreTools.Serialization/Wrappers/SecuROMDFA.Printing.cs index ce1e74c9..cede27db 100644 --- a/SabreTools.Serialization/Printers/SecuROMDFA.cs +++ b/SabreTools.Serialization/Wrappers/SecuROMDFA.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.SecuROM; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class SecuROMDFA : IPrinter + public partial class SecuROMDFA : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, DFAFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, DFAFile dfaFile) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, DFAFile dfaFile) { builder.AppendLine("SecuROM DFA File Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/SecuROMDFA.cs b/SabreTools.Serialization/Wrappers/SecuROMDFA.cs index bee1aef8..2f4b415c 100644 --- a/SabreTools.Serialization/Wrappers/SecuROMDFA.cs +++ b/SabreTools.Serialization/Wrappers/SecuROMDFA.cs @@ -3,7 +3,7 @@ using SabreTools.Data.Models.SecuROM; namespace SabreTools.Serialization.Wrappers { - public class SecuROMDFA : WrapperBase + public partial class SecuROMDFA : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Wrappers/SecuROMMatroschkaPackage.Printing.cs b/SabreTools.Serialization/Wrappers/SecuROMMatroschkaPackage.Printing.cs new file mode 100644 index 00000000..78659dd8 --- /dev/null +++ b/SabreTools.Serialization/Wrappers/SecuROMMatroschkaPackage.Printing.cs @@ -0,0 +1,66 @@ +using System.Text; +using SabreTools.Data.Extensions; +using SabreTools.Data.Models.SecuROM; + +namespace SabreTools.Serialization.Wrappers +{ + public partial class SecuROMMatroschkaPackage : IPrintable + { +#if NETCOREAPP + /// + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif + + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, MatroshkaPackage package) + { + builder.AppendLine("SecuROM Matroschka Package Information:"); + builder.AppendLine("-------------------------"); + builder.AppendLine(); + builder.AppendLine(package.Signature, "Signature"); + builder.AppendLine(package.EntryCount, "Entry count"); + builder.AppendLine(package.UnknownRCValue1, "Unknown RC value 1"); + builder.AppendLine(package.UnknownRCValue2, "Unknown RC value 2"); + builder.AppendLine(package.UnknownRCValue3, "Unknown RC value 3"); + builder.AppendLine(package.KeyHexString, "Key hex string"); + builder.AppendLine(package.Padding, "Padding"); + builder.AppendLine(); + + Print(builder, package.Entries); + } + + private static void Print(StringBuilder builder, MatroshkaEntry[]? entries) + { + builder.AppendLine(" Entries Information:"); + builder.AppendLine(" -------------------------"); + if (entries == null || entries.Length == 0) + { + builder.AppendLine(" No entries"); + builder.AppendLine(); + return; + } + + for (int i = 0; i < entries.Length; i++) + { + var file = entries[i]; + + builder.AppendLine($" File {i}"); + builder.AppendLine(file.Path, " Path"); + builder.AppendLine($"Entry type: {file.EntryType} (0x{(uint)file.EntryType:X8})"); + builder.AppendLine(file.Size, " Size"); + builder.AppendLine(file.Offset, " Offset"); + builder.AppendLine(file.Unknown, " Unknown"); + builder.AppendLine(file.ModifiedTime, " Modified time"); + builder.AppendLine(file.CreatedTime, " Created time"); + builder.AppendLine(file.AccessedTime, " Accessed time"); + builder.AppendLine(file.MD5, " MD5"); + // builder.AppendLine(file.FileData, " File data"); + } + + builder.AppendLine(); + } + } +} diff --git a/SabreTools.Serialization/Wrappers/SevenZip.cs b/SabreTools.Serialization/Wrappers/SevenZip.cs index 44949302..1284a801 100644 --- a/SabreTools.Serialization/Wrappers/SevenZip.cs +++ b/SabreTools.Serialization/Wrappers/SevenZip.cs @@ -77,14 +77,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Printers/TapeArchive.cs b/SabreTools.Serialization/Wrappers/TapeArchive.Printing.cs similarity index 88% rename from SabreTools.Serialization/Printers/TapeArchive.cs rename to SabreTools.Serialization/Wrappers/TapeArchive.Printing.cs index a9692e8f..a6c9523b 100644 --- a/SabreTools.Serialization/Printers/TapeArchive.cs +++ b/SabreTools.Serialization/Wrappers/TapeArchive.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.TAR; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class TapeArchive : IPrinter + public partial class TapeArchive : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive file) { builder.AppendLine("Tape Archive Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/VBSP.cs b/SabreTools.Serialization/Wrappers/VBSP.Printing.cs similarity index 99% rename from SabreTools.Serialization/Printers/VBSP.cs rename to SabreTools.Serialization/Wrappers/VBSP.Printing.cs index ee24b4a9..4ad5179b 100644 --- a/SabreTools.Serialization/Printers/VBSP.cs +++ b/SabreTools.Serialization/Wrappers/VBSP.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.BSP; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class VBSP : IPrinter + public partial class VBSP : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, VbspFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, VbspFile file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, VbspFile file) { builder.AppendLine("BSP Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/VPK.cs b/SabreTools.Serialization/Wrappers/VPK.Printing.cs similarity index 91% rename from SabreTools.Serialization/Printers/VPK.cs rename to SabreTools.Serialization/Wrappers/VPK.Printing.cs index 464f0045..a88913c7 100644 --- a/SabreTools.Serialization/Printers/VPK.cs +++ b/SabreTools.Serialization/Wrappers/VPK.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.VPK; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class VPK : IPrinter + public partial class VPK : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, File model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, File file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, File file) { builder.AppendLine("VPK Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/WAD3.cs b/SabreTools.Serialization/Wrappers/WAD3.Printing.cs similarity index 91% rename from SabreTools.Serialization/Printers/WAD3.cs rename to SabreTools.Serialization/Wrappers/WAD3.Printing.cs index 81c84e73..8b03619c 100644 --- a/SabreTools.Serialization/Printers/WAD3.cs +++ b/SabreTools.Serialization/Wrappers/WAD3.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.WAD3; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class WAD3 : IPrinter + public partial class WAD3 : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, File model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, File file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, File file) { builder.AppendLine("WAD Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/WiseOverlayHeader.cs b/SabreTools.Serialization/Wrappers/WiseOverlayHeader.Printing.cs similarity index 83% rename from SabreTools.Serialization/Printers/WiseOverlayHeader.cs rename to SabreTools.Serialization/Wrappers/WiseOverlayHeader.Printing.cs index a6d1008e..914808ec 100644 --- a/SabreTools.Serialization/Printers/WiseOverlayHeader.cs +++ b/SabreTools.Serialization/Wrappers/WiseOverlayHeader.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.WiseInstaller; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class WiseOverlayHeader : IPrinter + public partial class WiseOverlayHeader : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, OverlayHeader model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, OverlayHeader overlayHeader) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, OverlayHeader overlayHeader) { #if NET20 || NET35 bool pkzip = (overlayHeader.Flags & OverlayHeaderFlags.WISE_FLAG_PK_ZIP) != 0; @@ -22,7 +28,7 @@ namespace SabreTools.Data.Printers builder.AppendLine(overlayHeader.DllNameLen, "DLL name length"); builder.AppendLine(overlayHeader.DllName, "DLL name"); builder.AppendLine(overlayHeader.DllSize, "DLL size"); - builder.AppendLine($"Flags: {overlayHeader.Flags} (0x{(uint)overlayHeader.Flags:X4})"); + builder.AppendLine($"Flags: {overlayHeader.Flags} (0x{(uint)overlayHeader.Flags:X8})"); builder.AppendLine(pkzip, " Uses PKZIP containers"); builder.AppendLine(overlayHeader.GraphicsData, "Graphics data"); builder.AppendLine(overlayHeader.WiseScriptExitEventOffset, "Wise script exit event offset"); @@ -45,13 +51,13 @@ namespace SabreTools.Data.Printers builder.AppendLine(overlayHeader.DibInflatedSize, "DIB inflated size"); builder.AppendLine(overlayHeader.InstallScriptDeflatedSize, "Install script deflated size"); if (overlayHeader.CharacterSet != null) - builder.AppendLine($"Character set: {overlayHeader.CharacterSet} (0x{(uint)overlayHeader.CharacterSet:X4})"); + builder.AppendLine($"Character set: {overlayHeader.CharacterSet} (0x{(uint)overlayHeader.CharacterSet:X8})"); else builder.AppendLine((uint?)null, $"Character set"); - builder.AppendLine($"Endianness: {overlayHeader.Endianness} (0x{(uint)overlayHeader.Endianness:X4})"); + builder.AppendLine($"Endianness: {overlayHeader.Endianness} (0x{(ushort)overlayHeader.Endianness:X4})"); builder.AppendLine(overlayHeader.InitTextLen, "Init text length"); builder.AppendLine(overlayHeader.InitText, "Init text"); builder.AppendLine(); } } -} \ No newline at end of file +} diff --git a/SabreTools.Serialization/Printers/WiseScript.cs b/SabreTools.Serialization/Wrappers/WiseScript.Printing.cs similarity index 98% rename from SabreTools.Serialization/Printers/WiseScript.cs rename to SabreTools.Serialization/Wrappers/WiseScript.Printing.cs index 10322542..3c47396f 100644 --- a/SabreTools.Serialization/Printers/WiseScript.cs +++ b/SabreTools.Serialization/Wrappers/WiseScript.Printing.cs @@ -3,15 +3,20 @@ using SabreTools.Data.Extensions; using SabreTools.Data.Models.WiseInstaller; using SabreTools.Data.Models.WiseInstaller.Actions; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class WiseScript : IPrinter + public partial class WiseScript : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, ScriptFile model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, ScriptFile scriptFile) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, ScriptFile scriptFile) { builder.AppendLine("Wise Installer Script File Information:"); builder.AppendLine("-------------------------"); @@ -836,4 +841,4 @@ namespace SabreTools.Data.Printers #endregion } -} \ No newline at end of file +} diff --git a/SabreTools.Serialization/Wrappers/WiseScript.cs b/SabreTools.Serialization/Wrappers/WiseScript.cs index 5a68f2a3..c2fdb034 100644 --- a/SabreTools.Serialization/Wrappers/WiseScript.cs +++ b/SabreTools.Serialization/Wrappers/WiseScript.cs @@ -10,7 +10,7 @@ using SabreTools.IO.Extensions; namespace SabreTools.Serialization.Wrappers { - public class WiseScript : WrapperBase + public partial class WiseScript : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/WiseSectionHeader.cs b/SabreTools.Serialization/Wrappers/WiseSectionHeader.Printing.cs similarity index 85% rename from SabreTools.Serialization/Printers/WiseSectionHeader.cs rename to SabreTools.Serialization/Wrappers/WiseSectionHeader.Printing.cs index eac0d58b..2e9a24e2 100644 --- a/SabreTools.Serialization/Printers/WiseSectionHeader.cs +++ b/SabreTools.Serialization/Wrappers/WiseSectionHeader.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.WiseInstaller; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class WiseSectionHeader : IPrinter + public partial class WiseSectionHeader : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, SectionHeader model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, SectionHeader header) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, SectionHeader header) { builder.AppendLine("Wise Section Header Information:"); builder.AppendLine("-------------------------"); @@ -56,4 +62,4 @@ namespace SabreTools.Data.Printers builder.AppendLine(); } } -} \ No newline at end of file +} diff --git a/SabreTools.Serialization/Wrappers/WrapperBase.cs b/SabreTools.Serialization/Wrappers/WrapperBase.cs index 25d0649f..1f94753d 100644 --- a/SabreTools.Serialization/Wrappers/WrapperBase.cs +++ b/SabreTools.Serialization/Wrappers/WrapperBase.cs @@ -58,7 +58,7 @@ namespace SabreTools.Serialization.Wrappers #endif /// - /// Lock for accessing + /// Lock for accessing /// protected readonly object _dataSourceLock = new(); @@ -157,7 +157,7 @@ namespace SabreTools.Serialization.Wrappers /// This method locks the data source to avoid potential conflicts in reading /// from the data source. This should be the preferred way of reading in cases /// where there may be multiple threads accessing the wrapper. - /// + /// /// This method will return an empty array if the length is greater than what is left /// in the stream. This is different behavior than a normal stream read that would /// attempt to read as much as possible, returning the amount of bytes read. @@ -171,16 +171,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - /// Export the item information as JSON - /// - public abstract string ExportJSON(); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Wrappers/WrapperBaseT.cs b/SabreTools.Serialization/Wrappers/WrapperBaseT.cs index 46f7363f..0e6c281e 100644 --- a/SabreTools.Serialization/Wrappers/WrapperBaseT.cs +++ b/SabreTools.Serialization/Wrappers/WrapperBaseT.cs @@ -92,14 +92,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Printers/XMID.cs b/SabreTools.Serialization/Wrappers/XMID.Printing.cs similarity index 67% rename from SabreTools.Serialization/Printers/XMID.cs rename to SabreTools.Serialization/Wrappers/XMID.Printing.cs index cdc6e7a2..c55f4f44 100644 --- a/SabreTools.Serialization/Printers/XMID.cs +++ b/SabreTools.Serialization/Wrappers/XMID.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using static SabreTools.Data.Models.Xbox.Constants; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class XMID : IPrinter + public partial class XMID : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Models.Xbox.XMID model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Models.Xbox.XMID xmid) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Data.Models.Xbox.XMID xmid) { builder.AppendLine("Xbox Media Identifier Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/XMID.cs b/SabreTools.Serialization/Wrappers/XMID.cs index 4de0b91d..3611f93d 100644 --- a/SabreTools.Serialization/Wrappers/XMID.cs +++ b/SabreTools.Serialization/Wrappers/XMID.cs @@ -4,7 +4,7 @@ using static SabreTools.Data.Models.Xbox.Constants; namespace SabreTools.Serialization.Wrappers { - public class XMID : WrapperBase + public partial class XMID : WrapperBase { #region Descriptive Properties diff --git a/SabreTools.Serialization/Printers/XZ.cs b/SabreTools.Serialization/Wrappers/XZ.Printing.cs similarity index 91% rename from SabreTools.Serialization/Printers/XZ.cs rename to SabreTools.Serialization/Wrappers/XZ.Printing.cs index 856f61bd..157a675d 100644 --- a/SabreTools.Serialization/Printers/XZ.cs +++ b/SabreTools.Serialization/Wrappers/XZ.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.XZ; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class XZ : IPrinter + public partial class XZ : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Archive model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Archive archive) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Archive archive) { builder.AppendLine("xz Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/XZ.cs b/SabreTools.Serialization/Wrappers/XZ.cs index 755b25f8..69ebe0c7 100644 --- a/SabreTools.Serialization/Wrappers/XZ.cs +++ b/SabreTools.Serialization/Wrappers/XZ.cs @@ -91,14 +91,5 @@ namespace SabreTools.Serialization.Wrappers } #endregion - - #region JSON Export - -#if NETCOREAPP - /// - public override string ExportJSON() => throw new System.NotImplementedException(); -#endif - - #endregion } } diff --git a/SabreTools.Serialization/Printers/XZP.cs b/SabreTools.Serialization/Wrappers/XZP.Printing.cs similarity index 91% rename from SabreTools.Serialization/Printers/XZP.cs rename to SabreTools.Serialization/Wrappers/XZP.Printing.cs index cc89e615..65df02e5 100644 --- a/SabreTools.Serialization/Printers/XZP.cs +++ b/SabreTools.Serialization/Wrappers/XZP.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using SabreTools.Data.Models.XZP; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class XZP : IPrinter + public partial class XZP : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, File model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, File file) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, File file) { builder.AppendLine("XZP Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Printers/XeMID.cs b/SabreTools.Serialization/Wrappers/XeMID.Printing.cs similarity index 76% rename from SabreTools.Serialization/Printers/XeMID.cs rename to SabreTools.Serialization/Wrappers/XeMID.Printing.cs index 1603527a..de4bbf17 100644 --- a/SabreTools.Serialization/Printers/XeMID.cs +++ b/SabreTools.Serialization/Wrappers/XeMID.Printing.cs @@ -1,15 +1,21 @@ using System.Text; +using SabreTools.Data.Extensions; using static SabreTools.Data.Models.Xbox.Constants; -namespace SabreTools.Data.Printers +namespace SabreTools.Serialization.Wrappers { - public class XeMID : IPrinter + public partial class XeMID : IPrintable { +#if NETCOREAPP /// - public void PrintInformation(StringBuilder builder, Models.Xbox.XeMID model) - => Print(builder, model); + public string ExportJSON() => System.Text.Json.JsonSerializer.Serialize(Model, _jsonSerializerOptions); +#endif - public static void Print(StringBuilder builder, Models.Xbox.XeMID xemid) + /// + public void PrintInformation(StringBuilder builder) + => Print(builder, Model); + + private static void Print(StringBuilder builder, Data.Models.Xbox.XeMID xemid) { builder.AppendLine("Xbox Media Identifier Information:"); builder.AppendLine("-------------------------"); diff --git a/SabreTools.Serialization/Wrappers/XeMID.cs b/SabreTools.Serialization/Wrappers/XeMID.cs index 28ac7369..aca17233 100644 --- a/SabreTools.Serialization/Wrappers/XeMID.cs +++ b/SabreTools.Serialization/Wrappers/XeMID.cs @@ -4,7 +4,7 @@ using static SabreTools.Data.Models.Xbox.Constants; namespace SabreTools.Serialization.Wrappers { - public class XeMID : WrapperBase + public partial class XeMID : WrapperBase { #region Descriptive Properties