9 Commits
1.3.5 ... 1.3.6

Author SHA1 Message Date
Matt Nadareski
f450da1621 Bump version 2024-04-17 13:31:02 -04:00
Matt Nadareski
d2c68eef4b Rename region to be more accurate 2024-04-17 13:30:29 -04:00
Matt Nadareski
65facd03d1 Add PrintToConsole helper 2024-04-17 13:28:38 -04:00
Matt Nadareski
606d2268e7 Move individual implementations to separate namespace 2024-04-17 13:14:52 -04:00
Matt Nadareski
c65bbe9fd6 Rename StringBuilderExtensions 2024-04-17 13:12:39 -04:00
Matt Nadareski
e4a98f1e73 Add PrintExtensions to simplify printing from IWrapper 2024-04-17 13:11:26 -04:00
Matt Nadareski
0cf4d46de0 Move IPrinter to separate namespace 2024-04-17 13:08:35 -04:00
Matt Nadareski
913caddb10 Update packages 2024-04-17 13:05:51 -04:00
Matt Nadareski
df6b77812a Rename PlayJAudioPlaylist to be consistent 2024-04-17 12:52:55 -04:00
35 changed files with 499 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
using System.Text;
namespace SabreTools.Printing
namespace SabreTools.Printing.Interfaces
{
/// <summary>
/// Marks a class as a printer associated with a model

View File

@@ -0,0 +1,430 @@
using System;
using System.Text;
using SabreTools.Printing.Printers;
using SabreTools.Serialization.Interfaces;
using Wrapper = SabreTools.Serialization.Wrappers;
namespace SabreTools.Printing
{
/// <summary>
/// Generic wrapper around printing methods
/// </summary>
public static class PrintExtensions
{
/// <summary>
/// Print the item information from a wrapper to console as
/// pretty-printed text
/// </summary>
public static void PrintToConsole(this IWrapper wrapper)
{
var sb = wrapper.ExportStringBuilder();
if (sb == null)
{
Console.WriteLine("No item information could be generated");
return;
}
Console.WriteLine(sb.ToString());
}
/// <summary>
/// Export the item information as a StringBuilder
/// </summary>
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.CIA item => item.PrettyPrint(),
Wrapper.GCF item => item.PrettyPrint(),
Wrapper.InstallShieldCabinet item => item.PrettyPrint(),
Wrapper.IRD item => item.PrettyPrint(),
Wrapper.LinearExecutable 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.PlayJAudioFile item => item.PrettyPrint(),
Wrapper.PlayJPlaylist item => item.PrettyPrint(),
Wrapper.PortableExecutable item => item.PrettyPrint(),
Wrapper.Quantum item => item.PrettyPrint(),
Wrapper.SGA item => item.PrettyPrint(),
Wrapper.VBSP item => item.PrettyPrint(),
Wrapper.VPK item => item.PrettyPrint(),
Wrapper.WAD item => item.PrettyPrint(),
Wrapper.XeMID item => item.PrettyPrint(),
Wrapper.XMID item => item.PrettyPrint(),
Wrapper.XZP item => item.PrettyPrint(),
_ => null,
};
}
#if NET6_0_OR_GREATER
/// <summary>
/// Export the item information as JSON
/// </summary>
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.CIA item => item.ExportJSON(),
Wrapper.GCF item => item.ExportJSON(),
Wrapper.InstallShieldCabinet item => item.ExportJSON(),
Wrapper.IRD item => item.ExportJSON(),
Wrapper.LinearExecutable 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.PlayJAudioFile item => item.ExportJSON(),
Wrapper.PlayJPlaylist item => item.ExportJSON(),
Wrapper.PortableExecutable item => item.ExportJSON(),
Wrapper.Quantum item => item.ExportJSON(),
Wrapper.SGA item => item.ExportJSON(),
Wrapper.VBSP item => item.ExportJSON(),
Wrapper.VPK item => item.ExportJSON(),
Wrapper.WAD item => item.ExportJSON(),
Wrapper.XeMID item => item.ExportJSON(),
Wrapper.XMID item => item.ExportJSON(),
Wrapper.XZP item => item.ExportJSON(),
_ => string.Empty,
};
}
#endif
#region Static Printing Implementations
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.AACSMediaKeyBlock item)
{
var builder = new StringBuilder();
AACSMediaKeyBlock.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.BDPlusSVM item)
{
var builder = new StringBuilder();
BDPlusSVM.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.BFPK item)
{
var builder = new StringBuilder();
BFPK.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.BSP item)
{
var builder = new StringBuilder();
BSP.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.CFB item)
{
var builder = new StringBuilder();
CFB.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.CIA item)
{
var builder = new StringBuilder();
CIA.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.GCF item)
{
var builder = new StringBuilder();
GCF.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.InstallShieldCabinet item)
{
var builder = new StringBuilder();
InstallShieldCabinet.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.IRD item)
{
var builder = new StringBuilder();
IRD.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.LinearExecutable item)
{
var builder = new StringBuilder();
LinearExecutable.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.MicrosoftCabinet item)
{
var builder = new StringBuilder();
MicrosoftCabinet.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.MoPaQ item)
{
var builder = new StringBuilder();
MoPaQ.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.MSDOS item)
{
var builder = new StringBuilder();
MSDOS.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.N3DS item)
{
var builder = new StringBuilder();
N3DS.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.NCF item)
{
var builder = new StringBuilder();
NCF.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.NewExecutable item)
{
var builder = new StringBuilder();
NewExecutable.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.Nitro item)
{
var builder = new StringBuilder();
Nitro.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.PAK item)
{
var builder = new StringBuilder();
PAK.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.PFF item)
{
var builder = new StringBuilder();
PFF.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.PIC item)
{
var builder = new StringBuilder();
PIC.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.PlayJAudioFile item)
{
var builder = new StringBuilder();
PlayJAudioFile.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.PlayJPlaylist item)
{
var builder = new StringBuilder();
PlayJPlaylist.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.PortableExecutable item)
{
var builder = new StringBuilder();
PortableExecutable.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.Quantum item)
{
var builder = new StringBuilder();
Quantum.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.SGA item)
{
var builder = new StringBuilder();
SGA.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.VBSP item)
{
var builder = new StringBuilder();
VBSP.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.VPK item)
{
var builder = new StringBuilder();
VPK.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.WAD item)
{
var builder = new StringBuilder();
WAD.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.XeMID item)
{
var builder = new StringBuilder();
XeMID.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.XMID item)
{
var builder = new StringBuilder();
XMID.Print(builder, item.Model);
return builder;
}
/// <summary>
/// Export the item information as pretty-printed text
/// </summary>
private static StringBuilder PrettyPrint(this Wrapper.XZP item)
{
var builder = new StringBuilder();
XZP.Print(builder, item.Model);
return builder;
}
#endregion
}
}

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.AACS;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class AACSMediaKeyBlock : IPrinter<MediaKeyBlock>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.BDPlus;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class BDPlusSVM : IPrinter<SVM>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.BFPK;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class BFPK : IPrinter<Archive>
{

View File

@@ -1,8 +1,9 @@
using System.Text;
using SabreTools.Models.BSP;
using SabreTools.Printing.Interfaces;
using static SabreTools.Models.BSP.Constants;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class BSP : IPrinter<File>
{

View File

@@ -1,8 +1,9 @@
using System;
using System.Text;
using SabreTools.Models.CFB;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class CFB : IPrinter<Binary>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.N3DS;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class CIA : IPrinter<Models.N3DS.CIA>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.GCF;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class GCF : IPrinter<File>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.IRD;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class IRD : IPrinter<File>
{

View File

@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Text;
using SabreTools.Models.InstallShieldCabinet;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class InstallShieldCabinet : IPrinter<Cabinet>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.LinearExecutable;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class LinearExecutable : IPrinter<Executable>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.MSDOS;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class MSDOS : IPrinter<Executable>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.MicrosoftCabinet;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class MicrosoftCabinet : IPrinter<Cabinet>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.MoPaQ;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class MoPaQ : IPrinter<Archive>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.N3DS;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class N3DS : IPrinter<Cart>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.NCF;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class NCF : IPrinter<File>
{

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.Text;
using SabreTools.Models.NewExecutable;
using SabreTools.Printing.Interfaces;
using static SabreTools.Serialization.Extensions;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class NewExecutable : IPrinter<Executable>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.Nitro;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class Nitro : IPrinter<Cart>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.PAK;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class PAK : IPrinter<File>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.PFF;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class PFF : IPrinter<Archive>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.PIC;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class PIC : IPrinter<DiscInformation>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.PlayJ;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class PlayJAudioFile : IPrinter<AudioFile>
{

View File

@@ -1,9 +1,10 @@
using System.Text;
using SabreTools.Models.PlayJ;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class PlayJAudioPlaylist : IPrinter<Playlist>
public class PlayJPlaylist : IPrinter<Playlist>
{
/// <inheritdoc/>
public void PrintInformation(StringBuilder builder, Playlist model)

View File

@@ -4,11 +4,12 @@ using System.Linq;
using System.Text;
using System.Xml;
using SabreTools.ASN1;
using SabreTools.IO;
using SabreTools.IO.Extensions;
using SabreTools.Models.PortableExecutable;
using SabreTools.Printing.Interfaces;
using static SabreTools.Serialization.Extensions;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class PortableExecutable : IPrinter<Executable>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.Quantum;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class Quantum : IPrinter<Archive>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.SGA;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class SGA : IPrinter<File>
{

View File

@@ -1,8 +1,9 @@
using System.Text;
using SabreTools.Models.VBSP;
using SabreTools.Printing.Interfaces;
using static SabreTools.Models.VBSP.Constants;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class VBSP : IPrinter<File>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.VPK;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class VPK : IPrinter<File>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.WAD;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class WAD : IPrinter<File>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Printing.Interfaces;
using static SabreTools.Models.Xbox.Constants;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class XMID : IPrinter<Models.Xbox.XMID>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Models.XZP;
using SabreTools.Printing.Interfaces;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class XZP : IPrinter<File>
{

View File

@@ -1,7 +1,8 @@
using System.Text;
using SabreTools.Printing.Interfaces;
using static SabreTools.Models.Xbox.Constants;
namespace SabreTools.Printing
namespace SabreTools.Printing.Printers
{
public class XeMID : IPrinter<Models.Xbox.XeMID>
{

View File

@@ -7,7 +7,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.3.5</Version>
<Version>1.3.6</Version>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -27,9 +27,9 @@
<ItemGroup>
<PackageReference Include="SabreTools.ASN1" Version="1.3.1" />
<PackageReference Include="SabreTools.IO" Version="1.3.3" />
<PackageReference Include="SabreTools.IO" Version="1.3.6" />
<PackageReference Include="SabreTools.Models" Version="1.4.2" />
<PackageReference Include="SabreTools.Serialization" Version="1.5.0" />
<PackageReference Include="SabreTools.Serialization" Version="1.5.2" />
</ItemGroup>
</Project>

View File

@@ -5,7 +5,7 @@ using System.Text;
namespace SabreTools.Printing
{
// TODO: Add extension for printing enums, if possible
internal static class Extensions
internal static class StringBuilderExtensions
{
/// <summary>
/// Append a line containing a boolean to a StringBuilder