mirror of
https://github.com/SabreTools/SabreTools.Printing.git
synced 2026-04-22 14:13:05 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd87d89cfe | ||
|
|
045ed4d0c0 | ||
|
|
e69ee2ec58 | ||
|
|
2f11ecdfde | ||
|
|
f6b1a19aa2 | ||
|
|
ede807fc76 | ||
|
|
f2d43b2f18 | ||
|
|
047bbeedbc | ||
|
|
bac35b1ba6 | ||
|
|
77fefef1cb | ||
|
|
b7a8cac71e | ||
|
|
6b69a7bd27 | ||
|
|
f450da1621 | ||
|
|
d2c68eef4b | ||
|
|
65facd03d1 | ||
|
|
606d2268e7 | ||
|
|
c65bbe9fd6 | ||
|
|
e4a98f1e73 | ||
|
|
0cf4d46de0 | ||
|
|
913caddb10 | ||
|
|
df6b77812a |
@@ -2,4 +2,6 @@
|
||||
|
||||
This library comprises of code to output human-readable representations of various (usually binary) models. All of the classes here implement the `IPrinter` interface to associate them with a top-level model and utilize `StringBuilder` within `static` implementations.
|
||||
|
||||
Find the link to the Nuget package [here](https://www.nuget.org/packages/SabreTools.Printing).
|
||||
~~Find the link to the Nuget package [here](https://www.nuget.org/packages/SabreTools.Printing).~~
|
||||
|
||||
All functionality from this library has been integrated into [SabreTools.Serialization](https://github.com/SabreTools/SabreTools.Serialization). This repo is now redundant.
|
||||
|
||||
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreTools.Printing", "SabreTools.Printing\SabreTools.Printing.csproj", "{4274AA02-00A0-48F1-98C4-B3286E547246}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{F7DE19C8-9E62-443D-BBD0-A846405E3903}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -18,5 +20,9 @@ Global
|
||||
{4274AA02-00A0-48F1-98C4-B3286E547246}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4274AA02-00A0-48F1-98C4-B3286E547246}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4274AA02-00A0-48F1-98C4-B3286E547246}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F7DE19C8-9E62-443D-BBD0-A846405E3903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F7DE19C8-9E62-443D-BBD0-A846405E3903}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F7DE19C8-9E62-443D-BBD0-A846405E3903}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F7DE19C8-9E62-443D-BBD0-A846405E3903}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -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
|
||||
430
SabreTools.Printing/PrintExtensions.cs
Normal file
430
SabreTools.Printing/PrintExtensions.cs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -65,7 +66,7 @@ namespace SabreTools.Printing
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, SectorNumber?[]? sectorNumbers, string name)
|
||||
private static void Print(StringBuilder builder, SectorNumber[]? sectorNumbers, string name)
|
||||
{
|
||||
builder.AppendLine($" {name} Sectors Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
@@ -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>
|
||||
{
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SabreTools.Models.GCF;
|
||||
using SabreTools.Printing.Interfaces;
|
||||
|
||||
namespace SabreTools.Printing
|
||||
namespace SabreTools.Printing.Printers
|
||||
{
|
||||
public class GCF : IPrinter<File>
|
||||
{
|
||||
@@ -32,7 +34,7 @@ namespace SabreTools.Printing
|
||||
|
||||
// Directory and Directory Maps
|
||||
Print(builder, file.DirectoryHeader);
|
||||
Print(builder, file.DirectoryEntries);
|
||||
Print(builder, file.DirectoryEntries, file.DirectoryNames);
|
||||
// TODO: Should we print out the entire string table?
|
||||
Print(builder, file.DirectoryInfo1Entries);
|
||||
Print(builder, file.DirectoryInfo2Entries);
|
||||
@@ -248,7 +250,7 @@ namespace SabreTools.Printing
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, DirectoryEntry?[]? entries)
|
||||
private static void Print(StringBuilder builder, DirectoryEntry?[]? entries, Dictionary<long, string?>? entryNames)
|
||||
{
|
||||
builder.AppendLine(" Directory Entries Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
@@ -270,7 +272,7 @@ namespace SabreTools.Printing
|
||||
}
|
||||
|
||||
builder.AppendLine(entry.NameOffset, " Name offset");
|
||||
builder.AppendLine(entry.Name, " Name");
|
||||
builder.AppendLine(entryNames![entry.NameOffset], " Name");
|
||||
builder.AppendLine(entry.ItemSize, " Item size");
|
||||
builder.AppendLine(entry.ChecksumIndex, " Checksum index");
|
||||
builder.AppendLine($" Directory flags: {entry.DirectoryFlags} (0x{entry.DirectoryFlags:X})");
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SabreTools.Models.NCF;
|
||||
using SabreTools.Printing.Interfaces;
|
||||
|
||||
namespace SabreTools.Printing
|
||||
namespace SabreTools.Printing.Printers
|
||||
{
|
||||
public class NCF : IPrinter<File>
|
||||
{
|
||||
@@ -20,7 +22,7 @@ namespace SabreTools.Printing
|
||||
|
||||
// Directory and Directory Maps
|
||||
Print(builder, file.DirectoryHeader);
|
||||
Print(builder, file.DirectoryEntries);
|
||||
Print(builder, file.DirectoryEntries, file.DirectoryNames);
|
||||
// TODO: Should we print out the entire string table?
|
||||
Print(builder, file.DirectoryInfo1Entries);
|
||||
Print(builder, file.DirectoryInfo2Entries);
|
||||
@@ -89,7 +91,7 @@ namespace SabreTools.Printing
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, DirectoryEntry?[]? entries)
|
||||
private static void Print(StringBuilder builder, DirectoryEntry?[]? entries, Dictionary<long, string?>? entryNames)
|
||||
{
|
||||
builder.AppendLine(" Directory Entries Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
@@ -111,7 +113,7 @@ namespace SabreTools.Printing
|
||||
}
|
||||
|
||||
builder.AppendLine(entry.NameOffset, " Name offset");
|
||||
builder.AppendLine(entry.Name, " Name");
|
||||
builder.AppendLine(entryNames![entry.NameOffset], " Name");
|
||||
builder.AppendLine(entry.ItemSize, " Item size");
|
||||
builder.AppendLine(entry.ChecksumIndex, " Checksum index");
|
||||
builder.AppendLine($" Directory flags: {entry.DirectoryFlags} (0x{entry.DirectoryFlags:X})");
|
||||
@@ -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>
|
||||
{
|
||||
@@ -281,7 +282,7 @@ namespace SabreTools.Printing
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, Dictionary<ushort, ImportedNameTableEntry?>? entries)
|
||||
private static void Print(StringBuilder builder, Dictionary<ushort, ImportedNameTableEntry>? entries)
|
||||
{
|
||||
builder.AppendLine(" Imported-Name Table Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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)
|
||||
@@ -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>
|
||||
{
|
||||
@@ -1140,18 +1141,18 @@ namespace SabreTools.Printing
|
||||
continue;
|
||||
}
|
||||
|
||||
if (menuItem.NormalMenuText != null)
|
||||
if (menuItem is NormalMenuItem normalMenuItem)
|
||||
{
|
||||
builder.AppendLine($"{padding} Resource info: {menuItem.NormalResInfo} (0x{menuItem.NormalResInfo:X})");
|
||||
builder.AppendLine(menuItem.NormalMenuText, $"{padding} Menu text");
|
||||
builder.AppendLine($"{padding} Resource info: {normalMenuItem.NormalResInfo} (0x{normalMenuItem.NormalResInfo:X})");
|
||||
builder.AppendLine(normalMenuItem.NormalMenuText, $"{padding} Menu text");
|
||||
}
|
||||
else
|
||||
else if (menuItem is PopupMenuItem popupMenuItem)
|
||||
{
|
||||
builder.AppendLine($"{padding} Item type: {menuItem.PopupItemType} (0x{menuItem.PopupItemType:X})");
|
||||
builder.AppendLine($"{padding} State: {menuItem.PopupState} (0x{menuItem.PopupState:X})");
|
||||
builder.AppendLine(menuItem.PopupID, $"{padding} ID");
|
||||
builder.AppendLine($"{padding} Resource info: {menuItem.PopupResInfo} (0x{menuItem.PopupResInfo:X})");
|
||||
builder.AppendLine(menuItem.PopupMenuText, $"{padding} Menu text");
|
||||
builder.AppendLine($"{padding} Item type: {popupMenuItem.PopupItemType} (0x{popupMenuItem.PopupItemType:X})");
|
||||
builder.AppendLine($"{padding} State: {popupMenuItem.PopupState} (0x{popupMenuItem.PopupState:X})");
|
||||
builder.AppendLine(popupMenuItem.PopupID, $"{padding} ID");
|
||||
builder.AppendLine($"{padding} Resource info: {popupMenuItem.PopupResInfo} (0x{popupMenuItem.PopupResInfo:X})");
|
||||
builder.AppendLine(popupMenuItem.PopupMenuText, $"{padding} Menu text");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -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>
|
||||
{
|
||||
@@ -7,7 +7,7 @@
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.3.5</Version>
|
||||
<Version>1.3.9</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.Models" Version="1.4.2" />
|
||||
<PackageReference Include="SabreTools.Serialization" Version="1.5.0" />
|
||||
<PackageReference Include="SabreTools.IO" Version="1.4.0" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.4.5" />
|
||||
<PackageReference Include="SabreTools.Serialization" Version="1.5.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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
|
||||
119
Test/Options.cs
Normal file
119
Test/Options.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
/// <summary>
|
||||
/// Set of options for the test executable
|
||||
/// </summary>
|
||||
internal sealed class Options
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Enable debug output for relevant operations
|
||||
/// </summary>
|
||||
public bool Debug { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Set of input paths to use for operations
|
||||
/// </summary>
|
||||
public List<string> InputPaths { get; private set; } = [];
|
||||
|
||||
#if NETCOREAPP3_1_OR_GREATER
|
||||
/// <summary>
|
||||
/// Enable JSON output
|
||||
/// </summary>
|
||||
public bool Json { get; private set; } = false;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Parse commandline arguments into an Options object
|
||||
/// </summary>
|
||||
public static Options? ParseOptions(string[] args)
|
||||
{
|
||||
// If we have invalid arguments
|
||||
if (args == null || args.Length == 0)
|
||||
return null;
|
||||
|
||||
// Create an Options object
|
||||
var options = new Options();
|
||||
|
||||
// Parse the features
|
||||
int index = 0;
|
||||
for (; index < args.Length; index++)
|
||||
{
|
||||
string arg = args[index];
|
||||
bool featureFound = false;
|
||||
switch (arg)
|
||||
{
|
||||
case "-?":
|
||||
case "-h":
|
||||
case "--help":
|
||||
return null;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// If the flag wasn't a feature
|
||||
if (!featureFound)
|
||||
break;
|
||||
}
|
||||
|
||||
// Parse the options and paths
|
||||
for (; index < args.Length; index++)
|
||||
{
|
||||
string arg = args[index];
|
||||
switch (arg)
|
||||
{
|
||||
case "-d":
|
||||
case "--debug":
|
||||
options.Debug = true;
|
||||
break;
|
||||
|
||||
case "-j":
|
||||
case "--json":
|
||||
#if NET6_0_OR_GREATER
|
||||
options.Json = true;
|
||||
#else
|
||||
Console.WriteLine("JSON output not available in .NET Framework");
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
options.InputPaths.Add(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate we have any input paths to work on
|
||||
if (options.InputPaths.Count == 0)
|
||||
{
|
||||
Console.WriteLine("At least one path is required!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display help text
|
||||
/// </summary>
|
||||
public static void DisplayHelp()
|
||||
{
|
||||
Console.WriteLine("SabreTools.Printing Test Program");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("test.exe <options> file|directory ...");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Options:");
|
||||
Console.WriteLine("-?, -h, --help Display this help text and quit");
|
||||
Console.WriteLine("-d, --debug Enable debug mode");
|
||||
#if NET6_0_OR_GREATER
|
||||
Console.WriteLine("-j, --json Print executable info as JSON");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
141
Test/Program.cs
Normal file
141
Test/Program.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Printing;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Get the options from the arguments
|
||||
var options = Options.ParseOptions(args);
|
||||
|
||||
// If we have an invalid state
|
||||
if (options == null)
|
||||
{
|
||||
Options.DisplayHelp();
|
||||
Console.WriteLine("Press enter to close the program...");
|
||||
Console.ReadLine();
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through the input paths
|
||||
foreach (string inputPath in args)
|
||||
{
|
||||
#if NETFRAMEWORK
|
||||
PrintPathInfo(inputPath, false, options.Debug);
|
||||
#else
|
||||
PrintPathInfo(inputPath, options.Json, options.Debug);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper to print information for a single path
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path</param>
|
||||
/// <param name="json">Enable JSON output, if supported</param>
|
||||
/// <param name="debug">Enable debug output</param>
|
||||
private static void PrintPathInfo(string path, bool json, bool debug)
|
||||
{
|
||||
Console.WriteLine($"Checking possible path: {path}");
|
||||
|
||||
// Check if the file or directory exists
|
||||
if (File.Exists(path))
|
||||
{
|
||||
PrintFileInfo(path, json, debug);
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
#if NET20 || NET35
|
||||
foreach (string file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
|
||||
#else
|
||||
foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories))
|
||||
#endif
|
||||
{
|
||||
PrintFileInfo(file, json, debug);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{path} does not exist, skipping...");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print information for a single file, if possible
|
||||
/// </summary>
|
||||
private static void PrintFileInfo(string file, bool json, bool debug)
|
||||
{
|
||||
Console.WriteLine($"Attempting to print info for {file}");
|
||||
|
||||
try
|
||||
{
|
||||
using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Read the first 8 bytes
|
||||
byte[]? magic = stream.ReadBytes(8);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the file type
|
||||
WrapperType ft = WrapperFactory.GetFileType(magic ?? []);
|
||||
if (ft == WrapperType.UNKNOWN)
|
||||
{
|
||||
string extension = Path.GetExtension(file).TrimStart('.');
|
||||
ft = WrapperFactory.GetFileType(extension);
|
||||
}
|
||||
|
||||
// Print out the file format
|
||||
Console.WriteLine($"File format found: {ft}");
|
||||
|
||||
// Setup the wrapper to print
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, stream);
|
||||
|
||||
// If we don't have a wrapper
|
||||
if (wrapper == null)
|
||||
{
|
||||
Console.WriteLine($"Either {ft} is not supported or something went wrong during parsing!");
|
||||
Console.WriteLine();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the base info output name
|
||||
string filenameBase = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}";
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
// If we have the JSON flag
|
||||
if (json)
|
||||
{
|
||||
// Create the output data
|
||||
string serializedData = wrapper.ExportJSON();
|
||||
Console.WriteLine(serializedData);
|
||||
|
||||
// Write the output data
|
||||
using var jsw = new StreamWriter(File.OpenWrite($"{filenameBase}.json"));
|
||||
jsw.WriteLine(serializedData);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create the output data
|
||||
var builder = wrapper.ExportStringBuilder();
|
||||
if (builder == null)
|
||||
{
|
||||
Console.WriteLine("No item information could be generated");
|
||||
return;
|
||||
}
|
||||
|
||||
// Write the output data
|
||||
Console.WriteLine(builder);
|
||||
using var sw = new StreamWriter(File.OpenWrite($"{filenameBase}.txt"));
|
||||
sw.WriteLine(builder.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(debug ? ex : "[Exception opening file, please try again]");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Test/Test.csproj
Normal file
24
Test/Test.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
|
||||
<OutputType>Exe</OutputType>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SabreTools.Printing\SabreTools.Printing.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SabreTools.IO" Version="1.4.0" />
|
||||
<PackageReference Include="SabreTools.Matching" Version="1.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
923
Test/WrapperFactory.cs
Normal file
923
Test/WrapperFactory.cs
Normal file
@@ -0,0 +1,923 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Matching;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public static class WrapperFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Create an instance of a wrapper based on file type
|
||||
/// </summary>
|
||||
public static IWrapper? CreateWrapper(WrapperType fileType, Stream? data)
|
||||
{
|
||||
switch (fileType)
|
||||
{
|
||||
case WrapperType.AACSMediaKeyBlock: return AACSMediaKeyBlock.Create(data);
|
||||
case WrapperType.BDPlusSVM: return BDPlusSVM.Create(data);
|
||||
case WrapperType.BFPK: return BFPK.Create(data);
|
||||
case WrapperType.BSP: return BSP.Create(data);
|
||||
case WrapperType.BZip2: return null; // TODO: Implement wrapper
|
||||
case WrapperType.CFB: return CFB.Create(data);
|
||||
case WrapperType.CIA: return CIA.Create(data);
|
||||
case WrapperType.Executable: return CreateExecutableWrapper(data);
|
||||
case WrapperType.GCF: return GCF.Create(data);
|
||||
case WrapperType.GZIP: return null; // TODO: Implement wrapper
|
||||
case WrapperType.IniFile: return null; // TODO: Implement wrapper
|
||||
case WrapperType.InstallShieldArchiveV3: return null; // TODO: Implement wrapper
|
||||
case WrapperType.InstallShieldCAB: return InstallShieldCabinet.Create(data);
|
||||
case WrapperType.LDSCRYPT: return null; // TODO: Implement wrapper
|
||||
case WrapperType.MicrosoftCAB: return MicrosoftCabinet.Create(data);
|
||||
case WrapperType.MicrosoftLZ: return null; // TODO: Implement wrapper
|
||||
case WrapperType.MoPaQ: return MoPaQ.Create(data);
|
||||
case WrapperType.N3DS: return N3DS.Create(data);
|
||||
case WrapperType.NCF: return NCF.Create(data);
|
||||
case WrapperType.Nitro: return Nitro.Create(data);
|
||||
case WrapperType.PAK: return PAK.Create(data);
|
||||
case WrapperType.PFF: return PFF.Create(data);
|
||||
case WrapperType.PIC: return PIC.Create(data);
|
||||
case WrapperType.PKZIP: return null; // TODO: Implement wrapper
|
||||
case WrapperType.PlayJAudioFile: return PlayJAudioFile.Create(data);
|
||||
case WrapperType.PlayJPlaylist: return PlayJPlaylist.Create(data);
|
||||
case WrapperType.Quantum: return Quantum.Create(data);
|
||||
case WrapperType.RAR: return null; // TODO: Implement wrapper
|
||||
case WrapperType.RealArcadeInstaller: return null; // TODO: Implement wrapper
|
||||
case WrapperType.RealArcadeMezzanine: return null; // TODO: Implement wrapper
|
||||
case WrapperType.SevenZip: return null; // TODO: Implement wrapper
|
||||
case WrapperType.SFFS: return null; // TODO: Implement wrapper
|
||||
case WrapperType.SGA: return SGA.Create(data);
|
||||
case WrapperType.TapeArchive: return null; // TODO: Implement wrapper
|
||||
case WrapperType.Textfile: return null; // TODO: Implement wrapper
|
||||
case WrapperType.VBSP: return VBSP.Create(data);
|
||||
case WrapperType.VPK: return VPK.Create(data);
|
||||
case WrapperType.WAD: return WAD.Create(data);
|
||||
case WrapperType.XZ: return null; // TODO: Implement wrapper
|
||||
case WrapperType.XZP: return XZP.Create(data);
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an instance of a wrapper based on the executable type
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream data to parse</param>
|
||||
/// <returns>IWrapper representing the executable, null on error</returns>
|
||||
public static IWrapper? CreateExecutableWrapper(Stream? stream)
|
||||
{
|
||||
// If we have no stream
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
// Try to get an MS-DOS wrapper first
|
||||
var wrapper = MSDOS.Create(stream);
|
||||
if (wrapper == null || wrapper is not MSDOS msdos)
|
||||
return null;
|
||||
|
||||
// Check for a valid new executable address
|
||||
if (msdos.Model.Header?.NewExeHeaderAddr == null || msdos.Model.Header.NewExeHeaderAddr >= stream.Length)
|
||||
return wrapper;
|
||||
|
||||
// Try to read the executable info
|
||||
stream.Seek(msdos.Model.Header.NewExeHeaderAddr, SeekOrigin.Begin);
|
||||
var magic = stream.ReadBytes(4);
|
||||
|
||||
// If we didn't get valid data at the offset
|
||||
if (magic == null)
|
||||
{
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
// New Executable
|
||||
else if (magic.StartsWith(SabreTools.Models.NewExecutable.Constants.SignatureBytes))
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return NewExecutable.Create(stream);
|
||||
}
|
||||
|
||||
// Linear Executable
|
||||
else if (magic.StartsWith(SabreTools.Models.LinearExecutable.Constants.LESignatureBytes)
|
||||
|| magic.StartsWith(SabreTools.Models.LinearExecutable.Constants.LXSignatureBytes))
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return LinearExecutable.Create(stream);
|
||||
}
|
||||
|
||||
// Portable Executable
|
||||
else if (magic.StartsWith(SabreTools.Models.PortableExecutable.Constants.SignatureBytes))
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return PortableExecutable.Create(stream);
|
||||
}
|
||||
|
||||
// Everything else fails
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the supported file type for a magic string
|
||||
/// </summary>
|
||||
/// <remarks>Recommend sending in 16 bytes to check</remarks>
|
||||
public static WrapperType GetFileType(byte[] magic)
|
||||
{
|
||||
// If we have an invalid magic byte array
|
||||
if (magic == null || magic.Length == 0)
|
||||
return WrapperType.UNKNOWN;
|
||||
|
||||
// TODO: For all modelled types, use the constants instead of hardcoded values here
|
||||
#region AACSMediaKeyBlock
|
||||
|
||||
// Block starting with verify media key record
|
||||
if (magic.StartsWith(new byte?[] { 0x81, 0x00, 0x00, 0x14 }))
|
||||
return WrapperType.AACSMediaKeyBlock;
|
||||
|
||||
// Block starting with type and version record
|
||||
if (magic.StartsWith(new byte?[] { 0x10, 0x00, 0x00, 0x0C }))
|
||||
return WrapperType.AACSMediaKeyBlock;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BDPlusSVM
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x42, 0x44, 0x53, 0x56, 0x4D, 0x5F, 0x43, 0x43 }))
|
||||
return WrapperType.BDPlusSVM;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BFPK
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x42, 0x46, 0x50, 0x4b }))
|
||||
return WrapperType.BFPK;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BSP
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x1e, 0x00, 0x00, 0x00 }))
|
||||
return WrapperType.BSP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BZip2
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x42, 0x52, 0x68 }))
|
||||
return WrapperType.BZip2;
|
||||
|
||||
#endregion
|
||||
|
||||
#region CFB
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 }))
|
||||
return WrapperType.CFB;
|
||||
|
||||
#endregion
|
||||
|
||||
#region CIA
|
||||
|
||||
// No magic checks for CIA
|
||||
|
||||
#endregion
|
||||
|
||||
#region Executable
|
||||
|
||||
// DOS MZ executable file format (and descendants)
|
||||
if (magic.StartsWith(new byte?[] { 0x4d, 0x5a }))
|
||||
return WrapperType.Executable;
|
||||
|
||||
/*
|
||||
// None of the following are supported yet
|
||||
|
||||
// Executable and Linkable Format
|
||||
if (magic.StartsWith(new byte?[] { 0x7f, 0x45, 0x4c, 0x46 }))
|
||||
return FileTypes.Executable;
|
||||
|
||||
// Mach-O binary (32-bit)
|
||||
if (magic.StartsWith(new byte?[] { 0xfe, 0xed, 0xfa, 0xce }))
|
||||
return FileTypes.Executable;
|
||||
|
||||
// Mach-O binary (32-bit, reverse byte ordering scheme)
|
||||
if (magic.StartsWith(new byte?[] { 0xce, 0xfa, 0xed, 0xfe }))
|
||||
return FileTypes.Executable;
|
||||
|
||||
// Mach-O binary (64-bit)
|
||||
if (magic.StartsWith(new byte?[] { 0xfe, 0xed, 0xfa, 0xcf }))
|
||||
return FileTypes.Executable;
|
||||
|
||||
// Mach-O binary (64-bit, reverse byte ordering scheme)
|
||||
if (magic.StartsWith(new byte?[] { 0xcf, 0xfa, 0xed, 0xfe }))
|
||||
return FileTypes.Executable;
|
||||
|
||||
// Prefrred Executable File Format
|
||||
if (magic.StartsWith(new byte?[] { 0x4a, 0x6f, 0x79, 0x21, 0x70, 0x65, 0x66, 0x66 }))
|
||||
return FileTypes.Executable;
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region GCF
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }))
|
||||
return WrapperType.GCF;
|
||||
|
||||
#endregion
|
||||
|
||||
#region GZIP
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x1f, 0x8b }))
|
||||
return WrapperType.GZIP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region IniFile
|
||||
|
||||
// No magic checks for IniFile
|
||||
|
||||
#endregion
|
||||
|
||||
#region InstallShieldArchiveV3
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x13, 0x5D, 0x65, 0x8C }))
|
||||
return WrapperType.InstallShieldArchiveV3;
|
||||
|
||||
#endregion
|
||||
|
||||
#region InstallShieldCAB
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x49, 0x53, 0x63 }))
|
||||
return WrapperType.InstallShieldCAB;
|
||||
|
||||
#endregion
|
||||
|
||||
#region LDSCRYPT
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x4C, 0x44, 0x53, 0x43, 0x52, 0x59, 0x50, 0x54 }))
|
||||
return WrapperType.LDSCRYPT;
|
||||
|
||||
#endregion
|
||||
|
||||
#region MicrosoftCAB
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x4d, 0x53, 0x43, 0x46 }))
|
||||
return WrapperType.MicrosoftCAB;
|
||||
|
||||
#endregion
|
||||
|
||||
#region MicrosoftLZ
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33 }))
|
||||
return WrapperType.MicrosoftLZ;
|
||||
|
||||
#endregion
|
||||
|
||||
#region MPQ
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x4d, 0x50, 0x51, 0x1a }))
|
||||
return WrapperType.MoPaQ;
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x4d, 0x50, 0x51, 0x1b }))
|
||||
return WrapperType.MoPaQ;
|
||||
|
||||
#endregion
|
||||
|
||||
#region N3DS
|
||||
|
||||
// No magic checks for N3DS
|
||||
|
||||
#endregion
|
||||
|
||||
#region NCF
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 }))
|
||||
return WrapperType.NCF;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nitro
|
||||
|
||||
// No magic checks for Nitro
|
||||
|
||||
#endregion
|
||||
|
||||
#region PAK
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x50, 0x41, 0x43, 0x4B }))
|
||||
return WrapperType.PAK;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PFF
|
||||
|
||||
// Version 2
|
||||
if (magic.StartsWith(new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x32 }))
|
||||
return WrapperType.PFF;
|
||||
|
||||
// Version 3
|
||||
if (magic.StartsWith(new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x33 }))
|
||||
return WrapperType.PFF;
|
||||
|
||||
// Version 4
|
||||
if (magic.StartsWith(new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x34 }))
|
||||
return WrapperType.PFF;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PKZIP
|
||||
|
||||
// PKZIP (Unknown)
|
||||
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x00, 0x00 }))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// PKZIP
|
||||
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x03, 0x04 }))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// PKZIP (Empty Archive)
|
||||
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x05, 0x06 }))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// PKZIP (Spanned Archive)
|
||||
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x07, 0x08 }))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PLJ
|
||||
|
||||
// https://www.iana.org/assignments/media-types/audio/vnd.everad.plj
|
||||
if (magic.StartsWith(new byte?[] { 0xFF, 0x9D, 0x53, 0x4B }))
|
||||
return WrapperType.PlayJAudioFile;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quantum
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x44, 0x53 }))
|
||||
return WrapperType.Quantum;
|
||||
|
||||
#endregion
|
||||
|
||||
#region RAR
|
||||
|
||||
// RAR archive version 1.50 onwards
|
||||
if (magic.StartsWith(new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 }))
|
||||
return WrapperType.RAR;
|
||||
|
||||
// RAR archive version 5.0 onwards
|
||||
if (magic.StartsWith(new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00 }))
|
||||
return WrapperType.RAR;
|
||||
|
||||
#endregion
|
||||
|
||||
#region RealArcade
|
||||
|
||||
// RASGI2.0
|
||||
// Found in the ".rgs files in IA item "Nova_RealArcadeCD_USA".
|
||||
if (magic.StartsWith(new byte?[] { 0x52, 0x41, 0x53, 0x47, 0x49, 0x32, 0x2E, 0x30 }))
|
||||
return WrapperType.RealArcadeInstaller;
|
||||
|
||||
// XZip2.0
|
||||
// Found in the ".mez" files in IA item "Nova_RealArcadeCD_USA".
|
||||
if (magic.StartsWith(new byte?[] { 0x58, 0x5A, 0x69, 0x70, 0x32, 0x2E, 0x30 }))
|
||||
return WrapperType.RealArcadeMezzanine;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SevenZip
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c }))
|
||||
return WrapperType.SevenZip;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SFFS
|
||||
|
||||
// Found in Redump entry 81756, confirmed to be "StarForce Filesystem" by PiD.
|
||||
if (magic.StartsWith(new byte?[] { 0x53, 0x46, 0x46, 0x53 }))
|
||||
return WrapperType.SFFS;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SGA
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x5F, 0x41, 0x52, 0x43, 0x48, 0x49, 0x56, 0x45 }))
|
||||
return WrapperType.SGA;
|
||||
|
||||
#endregion
|
||||
|
||||
#region TapeArchive
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30 }))
|
||||
return WrapperType.TapeArchive;
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00 }))
|
||||
return WrapperType.TapeArchive;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Textfile
|
||||
|
||||
// Not all textfiles can be determined through magic number
|
||||
|
||||
// HTML
|
||||
if (magic.StartsWith(new byte?[] { 0x3c, 0x68, 0x74, 0x6d, 0x6c }))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// HTML and XML
|
||||
if (magic.StartsWith(new byte?[] { 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45 }))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// InstallShield Compiled Rules
|
||||
if (magic.StartsWith(new byte?[] { 0x61, 0x4C, 0x75, 0x5A }))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Microsoft Office File (old)
|
||||
if (magic.StartsWith(new byte?[] { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 }))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Rich Text File
|
||||
if (magic.StartsWith(new byte?[] { 0x7b, 0x5c, 0x72, 0x74, 0x66, 0x31 }))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Windows Help File
|
||||
if (magic.StartsWith(new byte?[] { 0x3F, 0x5F, 0x03, 0x00 }))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// XML
|
||||
// "<?xml"
|
||||
if (magic.StartsWith(new byte?[] { 0x3C, 0x3F, 0x78, 0x6D, 0x6C }))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
#endregion
|
||||
|
||||
#region VBSP
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x56, 0x42, 0x53, 0x50 }))
|
||||
return WrapperType.VBSP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region VPK
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x34, 0x12, 0xaa, 0x55 }))
|
||||
return WrapperType.VPK;
|
||||
|
||||
#endregion
|
||||
|
||||
#region WAD
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x57, 0x41, 0x44, 0x33 }))
|
||||
return WrapperType.WAD;
|
||||
|
||||
#endregion
|
||||
|
||||
#region XZ
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00 }))
|
||||
return WrapperType.XZ;
|
||||
|
||||
#endregion
|
||||
|
||||
#region XZP
|
||||
|
||||
if (magic.StartsWith(new byte?[] { 0x70, 0x69, 0x5A, 0x78 }))
|
||||
return WrapperType.XZP;
|
||||
|
||||
#endregion
|
||||
|
||||
// We couldn't find a supported match
|
||||
return WrapperType.UNKNOWN;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the supported file type for an extension
|
||||
/// </summary>
|
||||
/// <remarks>This is less accurate than a magic string match</remarks>
|
||||
public static WrapperType GetFileType(string extension)
|
||||
{
|
||||
// If we have an invalid extension
|
||||
if (string.IsNullOrEmpty(extension))
|
||||
return WrapperType.UNKNOWN;
|
||||
|
||||
// Normalize the extension
|
||||
extension = extension.TrimStart('.').Trim();
|
||||
|
||||
#region AACSMediaKeyBlock
|
||||
|
||||
// Shares an extension with INF setup information so it can't be used accurately
|
||||
// Blu-ray
|
||||
// if (extension.Equals("inf", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.AACSMediaKeyBlock;
|
||||
|
||||
// HD-DVD
|
||||
if (extension.Equals("aacs", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.AACSMediaKeyBlock;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BDPlusSVM
|
||||
|
||||
if (extension.Equals("svm", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.BDPlusSVM;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BFPK
|
||||
|
||||
// No extensions registered for BFPK
|
||||
|
||||
#endregion
|
||||
|
||||
#region BSP
|
||||
|
||||
// Shares an extension with VBSP so it can't be used accurately
|
||||
// if (extension.Equals("bsp", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.BSP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region BZip2
|
||||
|
||||
if (extension.Equals("bz2", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.BZip2;
|
||||
|
||||
#endregion
|
||||
|
||||
#region CFB
|
||||
|
||||
// Installer package
|
||||
if (extension.Equals("msi", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.CFB;
|
||||
|
||||
// Merge module
|
||||
else if (extension.Equals("msm", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.CFB;
|
||||
|
||||
// Patch Package
|
||||
else if (extension.Equals("msp", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.CFB;
|
||||
|
||||
// Transform
|
||||
else if (extension.Equals("mst", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.CFB;
|
||||
|
||||
// Patch Creation Properties
|
||||
else if (extension.Equals("pcp", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.CFB;
|
||||
|
||||
#endregion
|
||||
|
||||
#region CIA
|
||||
|
||||
if (extension.Equals("cia", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.CIA;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Executable
|
||||
|
||||
// DOS MZ executable file format (and descendants)
|
||||
if (extension.Equals("exe", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Executable;
|
||||
|
||||
// DOS MZ library file format (and descendants)
|
||||
if (extension.Equals("dll", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Executable;
|
||||
|
||||
#endregion
|
||||
|
||||
#region GCF
|
||||
|
||||
if (extension.Equals("gcf", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.GCF;
|
||||
|
||||
#endregion
|
||||
|
||||
#region GZIP
|
||||
|
||||
if (extension.Equals("gz", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.GZIP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region IniFile
|
||||
|
||||
if (extension.Equals("ini", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.IniFile;
|
||||
|
||||
#endregion
|
||||
|
||||
#region InstallShieldArchiveV3
|
||||
|
||||
if (extension.Equals("z", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.InstallShieldArchiveV3;
|
||||
|
||||
#endregion
|
||||
|
||||
#region InstallShieldCAB
|
||||
|
||||
// No extensions registered for InstallShieldCAB
|
||||
// Both InstallShieldCAB and MicrosoftCAB share the same extension
|
||||
|
||||
#endregion
|
||||
|
||||
#region MicrosoftCAB
|
||||
|
||||
// No extensions registered for InstallShieldCAB
|
||||
// Both InstallShieldCAB and MicrosoftCAB share the same extension
|
||||
|
||||
#endregion
|
||||
|
||||
#region MPQ
|
||||
|
||||
if (extension.Equals("mpq", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.MoPaQ;
|
||||
|
||||
#endregion
|
||||
|
||||
#region N3DS
|
||||
|
||||
// 3DS cart image
|
||||
if (extension.Equals("3ds", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.N3DS;
|
||||
|
||||
// CIA package -- Not currently supported
|
||||
// else if (extension.Equals("cia", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.N3DS;
|
||||
|
||||
#endregion
|
||||
|
||||
#region NCF
|
||||
|
||||
if (extension.Equals("ncf", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.NCF;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nitro
|
||||
|
||||
// DS cart image
|
||||
if (extension.Equals("nds", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Nitro;
|
||||
|
||||
// DS development cart image
|
||||
else if (extension.Equals("srl", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Nitro;
|
||||
|
||||
// DSi cart image
|
||||
else if (extension.Equals("dsi", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Nitro;
|
||||
|
||||
// iQue DS cart image
|
||||
else if (extension.Equals("ids", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Nitro;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PAK
|
||||
|
||||
// No extensions registered for PAK
|
||||
// Both PAK and Quantum share one extension
|
||||
// if (extension.Equals("pak", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.PAK;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PFF
|
||||
|
||||
if (extension.Equals("pff", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PFF;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PKZIP
|
||||
|
||||
// PKZIP
|
||||
if (extension.Equals("zip", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Android package
|
||||
if (extension.Equals("apk", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Java archive
|
||||
if (extension.Equals("jar", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Google Earth saved working session file
|
||||
if (extension.Equals("kmz", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// KWord document
|
||||
if (extension.Equals("kwd", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Microsoft Office Open XML Format (OOXML) Document
|
||||
if (extension.Equals("docx", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Microsoft Office Open XML Format (OOXML) Presentation
|
||||
if (extension.Equals("pptx", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Microsoft Office Open XML Format (OOXML) Spreadsheet
|
||||
if (extension.Equals("xlsx", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// OpenDocument text document
|
||||
if (extension.Equals("odt", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// OpenDocument presentation
|
||||
if (extension.Equals("odp", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// OpenDocument text document template
|
||||
if (extension.Equals("ott", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Microsoft Open XML paper specification file
|
||||
if (extension.Equals("oxps", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// OpenOffice spreadsheet
|
||||
if (extension.Equals("sxc", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// OpenOffice drawing
|
||||
if (extension.Equals("sxd", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// OpenOffice presentation
|
||||
if (extension.Equals("sxi", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// OpenOffice word processing
|
||||
if (extension.Equals("sxw", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// StarOffice spreadsheet
|
||||
if (extension.Equals("sxc", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Windows Media compressed skin file
|
||||
if (extension.Equals("wmz", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// Mozilla Browser Archive
|
||||
if (extension.Equals("xpi", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// XML paper specification file
|
||||
if (extension.Equals("xps", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
// eXact Packager Models
|
||||
if (extension.Equals("xpt", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PKZIP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PLJ
|
||||
|
||||
// https://www.iana.org/assignments/media-types/audio/vnd.everad.plj
|
||||
if (extension.Equals("plj", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.PlayJAudioFile;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quantum
|
||||
|
||||
if (extension.Equals("q", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Quantum;
|
||||
|
||||
// Both PAK and Quantum share one extension
|
||||
// if (extension.Equals("pak", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.Quantum;
|
||||
|
||||
#endregion
|
||||
|
||||
#region RAR
|
||||
|
||||
if (extension.Equals("rar", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.RAR;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SevenZip
|
||||
|
||||
if (extension.Equals("7z", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.SevenZip;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SGA
|
||||
|
||||
if (extension.Equals("sga", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.SGA;
|
||||
|
||||
#endregion
|
||||
|
||||
#region TapeArchive
|
||||
|
||||
if (extension.Equals("tar", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.SevenZip;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Textfile
|
||||
|
||||
// "Description in Zip"
|
||||
if (extension.Equals("diz", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Generic textfile (no header)
|
||||
if (extension.Equals("txt", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// HTML
|
||||
if (extension.Equals("htm", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
if (extension.Equals("html", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// InstallShield Script
|
||||
if (extension.Equals("ins", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Microsoft Office File (old)
|
||||
if (extension.Equals("doc", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Property list
|
||||
if (extension.Equals("plist", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Rich Text File
|
||||
if (extension.Equals("rtf", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Setup information
|
||||
if (extension.Equals("inf", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// Windows Help File
|
||||
if (extension.Equals("hlp", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// WZC
|
||||
if (extension.Equals("wzc", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
// XML
|
||||
if (extension.Equals("xml", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.Textfile;
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region VBSP
|
||||
|
||||
// Shares an extension with BSP so it can't be used accurately
|
||||
// if (extension.Equals("bsp", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.VBSP;
|
||||
|
||||
#endregion
|
||||
|
||||
#region VPK
|
||||
|
||||
// Common extension so this cannot be used accurately
|
||||
// if (extension.Equals("vpk", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.VPK;
|
||||
|
||||
#endregion
|
||||
|
||||
#region WAD
|
||||
|
||||
// Common extension so this cannot be used accurately
|
||||
// if (extension.Equals("wad", StringComparison.OrdinalIgnoreCase))
|
||||
// return WrapperType.WAD;
|
||||
|
||||
#endregion
|
||||
|
||||
#region XZ
|
||||
|
||||
if (extension.Equals("xz", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.XZ;
|
||||
|
||||
#endregion
|
||||
|
||||
#region XZP
|
||||
|
||||
if (extension.Equals("xzp", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.XZP;
|
||||
|
||||
#endregion
|
||||
|
||||
// We couldn't find a supported match
|
||||
return WrapperType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
231
Test/WrapperType.cs
Normal file
231
Test/WrapperType.cs
Normal file
@@ -0,0 +1,231 @@
|
||||
namespace Test
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents each of the IWrapper implementations
|
||||
/// </summary>
|
||||
public enum WrapperType
|
||||
{
|
||||
/// <summary>
|
||||
/// Unknown or unsupported
|
||||
/// </summary>
|
||||
UNKNOWN,
|
||||
|
||||
/// <summary>
|
||||
/// AACS media key block
|
||||
/// </summary>
|
||||
AACSMediaKeyBlock,
|
||||
|
||||
/// <summary>
|
||||
/// BD+ SVM
|
||||
/// </summary>
|
||||
BDPlusSVM,
|
||||
|
||||
/// <summary>
|
||||
/// BFPK custom archive
|
||||
/// </summary>
|
||||
BFPK,
|
||||
|
||||
/// <summary>
|
||||
/// Half-Life Level
|
||||
/// </summary>
|
||||
BSP,
|
||||
|
||||
/// <summary>
|
||||
/// bzip2 archive
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
BZip2,
|
||||
|
||||
/// <summary>
|
||||
/// Compound File Binary
|
||||
/// </summary>
|
||||
CFB,
|
||||
|
||||
/// <summary>
|
||||
/// CTR Importable Archive
|
||||
/// </summary>
|
||||
CIA,
|
||||
|
||||
/// <summary>
|
||||
/// Executable or library
|
||||
/// </summary>
|
||||
/// <remarks>Includes MZ, NE, LE/LX, and PE</remarks>
|
||||
Executable,
|
||||
|
||||
/// <summary>
|
||||
/// Half-Life Game Cache File
|
||||
/// </summary>
|
||||
GCF,
|
||||
|
||||
/// <summary>
|
||||
/// gzip archive
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
GZIP,
|
||||
|
||||
/// <summary>
|
||||
/// Key-value pair INI file
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
IniFile,
|
||||
|
||||
/// <summary>
|
||||
/// InstallShield archive v3
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
InstallShieldArchiveV3,
|
||||
|
||||
/// <summary>
|
||||
/// InstallShield cabinet file
|
||||
/// </summary>
|
||||
InstallShieldCAB,
|
||||
|
||||
/// <summary>
|
||||
/// Link Data Security encrypted file
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
LDSCRYPT,
|
||||
|
||||
/// <summary>
|
||||
/// Microsoft cabinet file
|
||||
/// </summary>
|
||||
MicrosoftCAB,
|
||||
|
||||
/// <summary>
|
||||
/// Microsoft LZ-compressed file
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
MicrosoftLZ,
|
||||
|
||||
/// <summary>
|
||||
/// MPQ game data archive
|
||||
/// </summary>
|
||||
MoPaQ,
|
||||
|
||||
/// <summary>
|
||||
/// Nintendo 3DS cart image
|
||||
/// </summary>
|
||||
N3DS,
|
||||
|
||||
/// <summary>
|
||||
/// Half-Life No Cache File
|
||||
/// </summary>
|
||||
NCF,
|
||||
|
||||
/// <summary>
|
||||
/// Nintendo DS/DSi cart image
|
||||
/// </summary>
|
||||
Nitro,
|
||||
|
||||
/// <summary>
|
||||
/// Half-Life Package File
|
||||
/// </summary>
|
||||
PAK,
|
||||
|
||||
/// <summary>
|
||||
/// NovaLogic Game Archive Format
|
||||
/// </summary>
|
||||
PFF,
|
||||
|
||||
/// <summary>
|
||||
/// PIC data object
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no detection method</remarks>
|
||||
PIC,
|
||||
|
||||
/// <summary>
|
||||
/// PKWARE ZIP archive and derivatives
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
PKZIP,
|
||||
|
||||
/// <summary>
|
||||
/// PlayJ audio file
|
||||
/// </summary>
|
||||
PlayJAudioFile,
|
||||
|
||||
/// <summary>
|
||||
/// PlayJ playlist file
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no detection method/remarks>
|
||||
PlayJPlaylist,
|
||||
|
||||
/// <summary>
|
||||
/// Quantum archive
|
||||
/// </summary>
|
||||
Quantum,
|
||||
|
||||
/// <summary>
|
||||
/// RAR archive
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
RAR,
|
||||
|
||||
/// <summary>
|
||||
/// RealArcade Installer
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
RealArcadeInstaller,
|
||||
|
||||
/// <summary>
|
||||
/// RealArcade Mezzanine
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
RealArcadeMezzanine,
|
||||
|
||||
/// <summary>
|
||||
/// 7-zip archive
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
SevenZip,
|
||||
|
||||
/// <summary>
|
||||
/// StarForce FileSystem file
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
SFFS,
|
||||
|
||||
/// <summary>
|
||||
/// SGA
|
||||
/// </summary>
|
||||
SGA,
|
||||
|
||||
/// <summary>
|
||||
/// Tape archive
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
TapeArchive,
|
||||
|
||||
/// <summary>
|
||||
/// Various generic textfile formats
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
Textfile,
|
||||
|
||||
/// <summary>
|
||||
/// Half-Life 2 Level
|
||||
/// </summary>
|
||||
VBSP,
|
||||
|
||||
/// <summary>
|
||||
/// Valve Package File
|
||||
/// </summary>
|
||||
VPK,
|
||||
|
||||
/// <summary>
|
||||
/// Half-Life Texture Package File
|
||||
/// </summary>
|
||||
WAD,
|
||||
|
||||
/// <summary>
|
||||
/// xz archive
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
XZ,
|
||||
|
||||
/// <summary>
|
||||
/// Xbox Package File
|
||||
/// </summary>
|
||||
XZP,
|
||||
}
|
||||
}
|
||||
113
publish-nix.sh
Executable file
113
publish-nix.sh
Executable file
@@ -0,0 +1,113 @@
|
||||
#! /bin/bash
|
||||
|
||||
# This batch file assumes the following:
|
||||
# - .NET 8.0 (or newer) SDK is installed and in PATH
|
||||
# - zip is installed and in PATH
|
||||
# - Git is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
# Optional parameters
|
||||
USE_ALL=false
|
||||
NO_BUILD=false
|
||||
NO_ARCHIVE=false
|
||||
while getopts "uba" OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
u)
|
||||
USE_ALL=true
|
||||
;;
|
||||
b)
|
||||
NO_BUILD=true
|
||||
;;
|
||||
a)
|
||||
NO_ARCHIVE=true
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option provided"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Set the current directory as a variable
|
||||
BUILD_FOLDER=$PWD
|
||||
|
||||
# Set the current commit hash
|
||||
COMMIT=`git log --pretty=%H -1`
|
||||
|
||||
# Create the build matrix arrays
|
||||
FRAMEWORKS=("net8.0")
|
||||
RUNTIMES=("win-x86" "win-x64" "linux-x64" "osx-x64")
|
||||
|
||||
# Use expanded lists, if requested
|
||||
if [ $USE_ALL = true ]
|
||||
then
|
||||
FRAMEWORKS=("net20" "net35" "net40" "net452" "net462" "net472" "net48" "netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0")
|
||||
RUNTIMES=("win-x86" "win-x64" "win-arm64" "linux-x64" "linux-arm64" "osx-x64")
|
||||
fi
|
||||
|
||||
# Create the filter arrays
|
||||
SINGLE_FILE_CAPABLE=("net5.0" "net6.0" "net7.0" "net8.0")
|
||||
VALID_CROSS_PLATFORM_FRAMEWORKS=("netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0")
|
||||
VALID_CROSS_PLATFORM_RUNTIMES=("win-arm64" "linux-x64" "linux-arm64" "osx-x64")
|
||||
|
||||
# Only build if requested
|
||||
if [ $NO_BUILD = false ]
|
||||
then
|
||||
# Restore Nuget packages for all builds
|
||||
echo "Restoring Nuget packages"
|
||||
dotnet restore
|
||||
|
||||
# Create Nuget Package
|
||||
dotnet pack SabreTools.Printing/SabreTools.Printing.csproj --output $BUILD_FOLDER
|
||||
|
||||
# Build Test
|
||||
for FRAMEWORK in "${FRAMEWORKS[@]}"
|
||||
do
|
||||
for RUNTIME in "${RUNTIMES[@]}"
|
||||
do
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if [ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ] && [ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Only .NET 5 and above can publish to a single file
|
||||
if [[ $(echo ${SINGLE_FILE_CAPABLE[@]} | fgrep -w $FRAMEWORK) ]]
|
||||
then
|
||||
dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true
|
||||
dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false
|
||||
else
|
||||
dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT
|
||||
dotnet publish Test/Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
||||
# Only create archives if requested
|
||||
if [ $NO_ARCHIVE = false ]
|
||||
then
|
||||
# Create Test archives
|
||||
for FRAMEWORK in "${FRAMEWORKS[@]}"
|
||||
do
|
||||
for RUNTIME in "${RUNTIMES[@]}"
|
||||
do
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if [ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ] && [ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
cd $BUILD_FOLDER/Test/bin/Debug/${FRAMEWORK}/${RUNTIME}/publish/
|
||||
zip -r $BUILD_FOLDER/SabreTools.Printing_${FRAMEWORK}_${RUNTIME}_debug.zip .
|
||||
cd $BUILD_FOLDER/Test/bin/Release/${FRAMEWORK}/${RUNTIME}/publish/
|
||||
zip -r $BUILD_FOLDER/SabreTools.Printing_${FRAMEWORK}_${RUNTIME}_release.zip .
|
||||
done
|
||||
done
|
||||
|
||||
# Reset the directory
|
||||
cd $BUILD_FOLDER
|
||||
fi
|
||||
105
publish-win.ps1
Normal file
105
publish-win.ps1
Normal file
@@ -0,0 +1,105 @@
|
||||
# This batch file assumes the following:
|
||||
# - .NET 8.0 (or newer) SDK is installed and in PATH
|
||||
# - 7-zip commandline (7z.exe) is installed and in PATH
|
||||
# - Git for Windows is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
# Optional parameters
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("UseAll")]
|
||||
[switch]$USE_ALL,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("NoBuild")]
|
||||
[switch]$NO_BUILD,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("NoArchive")]
|
||||
[switch]$NO_ARCHIVE
|
||||
)
|
||||
|
||||
# Set the current directory as a variable
|
||||
$BUILD_FOLDER = $PSScriptRoot
|
||||
|
||||
# Set the current commit hash
|
||||
$COMMIT = git log --pretty=format:"%H" -1
|
||||
|
||||
# Create the build matrix arrays
|
||||
$FRAMEWORKS = @('net8.0')
|
||||
$RUNTIMES = @('win-x86', 'win-x64', 'linux-x64', 'osx-x64')
|
||||
|
||||
# Use expanded lists, if requested
|
||||
if ($USE_ALL.IsPresent)
|
||||
{
|
||||
$FRAMEWORKS = @('net20', 'net35', 'net40', 'net452', 'net462', 'net472', 'net48', 'netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0')
|
||||
$RUNTIMES = @('win-x86', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64')
|
||||
}
|
||||
|
||||
# Create the filter arrays
|
||||
$SINGLE_FILE_CAPABLE = @('net5.0', 'net6.0', 'net7.0', 'net8.0')
|
||||
$VALID_CROSS_PLATFORM_FRAMEWORKS = @('netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0')
|
||||
$VALID_CROSS_PLATFORM_RUNTIMES = @('win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64')
|
||||
|
||||
# Only build if requested
|
||||
if (!$NO_BUILD.IsPresent)
|
||||
{
|
||||
# Restore Nuget packages for all builds
|
||||
Write-Host "Restoring Nuget packages"
|
||||
dotnet restore
|
||||
|
||||
# Create Nuget Package
|
||||
dotnet pack SabreTools.Printing\SabreTools.Printing.csproj --output $BUILD_FOLDER
|
||||
|
||||
# Build Test
|
||||
foreach ($FRAMEWORK in $FRAMEWORKS)
|
||||
{
|
||||
foreach ($RUNTIME in $RUNTIMES)
|
||||
{
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME)
|
||||
{
|
||||
continue
|
||||
}
|
||||
|
||||
# Only .NET 5 and above can publish to a single file
|
||||
if ($SINGLE_FILE_CAPABLE -contains $FRAMEWORK)
|
||||
{
|
||||
dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true
|
||||
dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false
|
||||
}
|
||||
else
|
||||
{
|
||||
dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT
|
||||
dotnet publish Test\Test.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Only create archives if requested
|
||||
if (!$NO_ARCHIVE.IsPresent)
|
||||
{
|
||||
# Create Test archives
|
||||
foreach ($FRAMEWORK in $FRAMEWORKS)
|
||||
{
|
||||
foreach ($RUNTIME in $RUNTIMES)
|
||||
{
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME)
|
||||
{
|
||||
continue
|
||||
}
|
||||
|
||||
Set-Location -Path $BUILD_FOLDER\Test\bin\Debug\${FRAMEWORK}\${RUNTIME}\publish\
|
||||
7z a -tzip $BUILD_FOLDER\SabreTools.Printing_${FRAMEWORK}_${RUNTIME}_debug.zip *
|
||||
Set-Location -Path $BUILD_FOLDER\Test\bin\Release\${FRAMEWORK}\${RUNTIME}\publish\
|
||||
7z a -tzip $BUILD_FOLDER\SabreTools.Printing_${FRAMEWORK}_${RUNTIME}_release.zip *
|
||||
}
|
||||
}
|
||||
|
||||
# Reset the directory
|
||||
Set-Location -Path $PSScriptRoot
|
||||
}
|
||||
Reference in New Issue
Block a user