mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-04 13:45:40 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6aaf3afa38 | ||
|
|
2a7eb44281 | ||
|
|
08bbc93793 | ||
|
|
789478df13 | ||
|
|
cd4f1c9d97 | ||
|
|
1a2e9fb942 | ||
|
|
d0865739de | ||
|
|
0696bbab72 | ||
|
|
4b4c17ac24 | ||
|
|
d768172da1 | ||
|
|
2a4d24309d | ||
|
|
bc01ce4552 | ||
|
|
ef0efe66bd | ||
|
|
7c21f65723 | ||
|
|
cec53e907f |
@@ -11,6 +11,7 @@ Below is a table representing the various interfaces that are implemented within
|
||||
| Interface Name | Source Type | Destination Type |
|
||||
| --- | --- | --- |
|
||||
| `IByteDeserializer` | `byte[]?` | Model |
|
||||
| `IByteSerializer` | Model | `byte[]?` |
|
||||
| `IFileDeserializer` | `string?` path | Model |
|
||||
| `IFileSerializer` | Model | `string?` path |
|
||||
| `IModelSerializer` | Model | Model |
|
||||
|
||||
@@ -2,73 +2,15 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.AACS;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class AACS :
|
||||
IByteDeserializer<MediaKeyBlock>,
|
||||
IFileDeserializer<MediaKeyBlock>,
|
||||
IStreamDeserializer<MediaKeyBlock>
|
||||
public class AACS : BaseBinaryDeserializer<MediaKeyBlock>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static MediaKeyBlock? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new AACS();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MediaKeyBlock? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static MediaKeyBlock? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new AACS();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MediaKeyBlock? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static MediaKeyBlock? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new AACS();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MediaKeyBlock? Deserialize(Stream? data)
|
||||
public override MediaKeyBlock? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -496,7 +438,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,7 @@
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class ArchiveDotOrg :
|
||||
XmlFile<Models.ArchiveDotOrg.Files>
|
||||
public class ArchiveDotOrg : XmlFile<Models.ArchiveDotOrg.Files>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.ArchiveDotOrg.Files? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new ArchiveDotOrg();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.ArchiveDotOrg.Files? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new ArchiveDotOrg();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.ArchiveDotOrg.Files? DeserializeStream(System.IO.Stream? data)
|
||||
{
|
||||
var deserializer = new ArchiveDotOrg();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.Models.AttractMode;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class AttractMode :
|
||||
IByteDeserializer<MetadataFile>,
|
||||
IFileDeserializer<MetadataFile>,
|
||||
IStreamDeserializer<MetadataFile>
|
||||
public class AttractMode : BaseBinaryDeserializer<MetadataFile>
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -21,62 +17,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
#endregion
|
||||
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static MetadataFile? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new AttractMode();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static MetadataFile? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new AttractMode();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static MetadataFile? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new AttractMode();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(Stream? data)
|
||||
public override MetadataFile? Deserialize(Stream? data)
|
||||
{
|
||||
// If the stream is null
|
||||
if (data == null)
|
||||
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.BDPlus;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.BDPlus.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class BDPlus :
|
||||
IByteDeserializer<SVM>,
|
||||
IFileDeserializer<SVM>,
|
||||
IStreamDeserializer<SVM>
|
||||
public class BDPlus : BaseBinaryDeserializer<SVM>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static SVM? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new BDPlus();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SVM? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static SVM? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new BDPlus();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SVM? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static SVM? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new BDPlus();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SVM? Deserialize(Stream? data)
|
||||
public override SVM? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -119,7 +61,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return svm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.BFPK;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.BFPK.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class BFPK :
|
||||
IByteDeserializer<Archive>,
|
||||
IFileDeserializer<Archive>,
|
||||
IStreamDeserializer<Archive>
|
||||
public class BFPK : BaseBinaryDeserializer<Archive>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Archive? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new BFPK();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Archive? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new BFPK();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Archive? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new BFPK();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(Stream? data)
|
||||
public override Archive? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -175,7 +117,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return fileEntry;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,16 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.BSP;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.BSP.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class BSP :
|
||||
IByteDeserializer<Models.BSP.File>,
|
||||
IFileDeserializer<Models.BSP.File>,
|
||||
IStreamDeserializer<Models.BSP.File>
|
||||
public class BSP : BaseBinaryDeserializer<Models.BSP.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.BSP.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new BSP();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.BSP.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.BSP.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new BSP();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.BSP.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.BSP.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new BSP();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.BSP.File? Deserialize(Stream? data)
|
||||
public override Models.BSP.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -274,7 +216,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
134
SabreTools.Serialization/Deserializers/BaseBinaryDeserializer.cs
Normal file
134
SabreTools.Serialization/Deserializers/BaseBinaryDeserializer.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for all binary deserializers
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">Type of the model to deserialize</typeparam>
|
||||
/// <remarks>These methods assume there is a concrete implementation of the deserialzier for the model available</remarks>
|
||||
public abstract class BaseBinaryDeserializer<TModel> :
|
||||
IByteDeserializer<TModel>,
|
||||
IFileDeserializer<TModel>,
|
||||
IStreamDeserializer<TModel>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual TModel? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return default;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return default;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual TModel? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract TModel? Deserialize(Stream? data);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Implementations
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static TModel? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = GetType<IByteDeserializer<TModel>>();
|
||||
if (deserializer == null)
|
||||
return default;
|
||||
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static TModel? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = GetType<IFileDeserializer<TModel>>();
|
||||
if (deserializer == null)
|
||||
return default;
|
||||
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static TModel? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = GetType<IStreamDeserializer<TModel>>();
|
||||
if (deserializer == null)
|
||||
return default;
|
||||
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Get a constructed instance of a type, if possible
|
||||
/// </summary>
|
||||
/// <typeparam name="TDeserializer">Deserializer type to construct</typeparam>
|
||||
/// <returns>Deserializer of the requested type, null on error</returns>
|
||||
private static TDeserializer? GetType<TDeserializer>()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
if (assembly == null)
|
||||
return default;
|
||||
|
||||
// If not all types can be loaded, use the ones that could be
|
||||
List<Type> assemblyTypes = [];
|
||||
try
|
||||
{
|
||||
assemblyTypes = assembly.GetTypes().ToList<Type>();
|
||||
}
|
||||
catch (ReflectionTypeLoadException rtle)
|
||||
{
|
||||
assemblyTypes = rtle.Types.Where(t => t != null)!.ToList<Type>();
|
||||
}
|
||||
|
||||
// Loop through all types
|
||||
foreach (Type type in assemblyTypes)
|
||||
{
|
||||
// If the type isn't a class or doesn't implement the interface
|
||||
if (!type.IsClass || type.GetInterface(typeof(TDeserializer).Name) == null)
|
||||
continue;
|
||||
|
||||
// Try to create a concrete instance of the type
|
||||
var instance = (TDeserializer?)Activator.CreateInstance(type);
|
||||
if (instance != null)
|
||||
return instance;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,74 +2,16 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.CFB;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.CFB.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class CFB :
|
||||
IByteDeserializer<Binary>,
|
||||
IFileDeserializer<Binary>,
|
||||
IStreamDeserializer<Binary>
|
||||
public class CFB : BaseBinaryDeserializer<Binary>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Binary? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new CFB();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Binary? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Binary? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new CFB();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Binary? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Binary? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new CFB();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Binary? Deserialize(Stream? data)
|
||||
public override Binary? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -418,7 +360,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return directoryEntry;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.N3DS;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class CIA :
|
||||
IByteDeserializer<Models.N3DS.CIA>,
|
||||
IFileDeserializer<Models.N3DS.CIA>,
|
||||
IStreamDeserializer<Models.N3DS.CIA>
|
||||
public class CIA : BaseBinaryDeserializer<Models.N3DS.CIA>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.N3DS.CIA? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new CIA();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.N3DS.CIA? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.N3DS.CIA? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new CIA();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.N3DS.CIA? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.N3DS.CIA? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new CIA();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.N3DS.CIA? Deserialize(Stream? data)
|
||||
public override Models.N3DS.CIA? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -557,7 +499,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return metaData;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,10 @@ using System.Text;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class Catalog :
|
||||
JsonFile<Models.Xbox.Catalog>
|
||||
public class Catalog : JsonFile<Models.Xbox.Catalog>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.Xbox.Catalog? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new Catalog();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <remarks>Catalog.js file is encoded as UTF-16 LE</remarks>
|
||||
public override Models.Xbox.Catalog? Deserialize(byte[]? data, int offset)
|
||||
=> Deserialize(data, offset, new UnicodeEncoding());
|
||||
@@ -23,13 +15,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.Xbox.Catalog? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new Catalog();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <remarks>Catalog.js file is encoded as UTF-16 LE</remarks>
|
||||
public override Models.Xbox.Catalog? Deserialize(string? path)
|
||||
=> Deserialize(path, new UnicodeEncoding());
|
||||
@@ -38,13 +23,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.Xbox.Catalog? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new Catalog();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <remarks>Catalog.js file is encoded as UTF-16 LE</remarks>
|
||||
public override Models.Xbox.Catalog? Deserialize(Stream? data)
|
||||
=> Deserialize(data, new UnicodeEncoding());
|
||||
|
||||
@@ -4,14 +4,10 @@ using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.Models.ClrMamePro;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class ClrMamePro :
|
||||
IByteDeserializer<MetadataFile>,
|
||||
IFileDeserializer<MetadataFile>,
|
||||
IStreamDeserializer<MetadataFile>
|
||||
public class ClrMamePro : BaseBinaryDeserializer<MetadataFile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
@@ -23,7 +19,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
public override MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
=> Deserialize(data, offset, true);
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -31,11 +27,11 @@ namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
return default;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
return default;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
@@ -54,7 +50,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(string? path)
|
||||
public override MetadataFile? Deserialize(string? path)
|
||||
=> Deserialize(path, true);
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -76,7 +72,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(Stream? data)
|
||||
public override MetadataFile? Deserialize(Stream? data)
|
||||
=> Deserialize(data, true);
|
||||
|
||||
/// <inheritdoc cref="Deserialize(Stream)"/>
|
||||
|
||||
@@ -3,73 +3,15 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.CueSheets;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class CueSheet :
|
||||
IByteDeserializer<Models.CueSheets.CueSheet>,
|
||||
IFileDeserializer<Models.CueSheets.CueSheet>,
|
||||
IStreamDeserializer<Models.CueSheets.CueSheet>
|
||||
public class CueSheet : BaseBinaryDeserializer<Models.CueSheets.CueSheet>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.CueSheets.CueSheet? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new CueSheet();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.CueSheets.CueSheet? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.CueSheets.CueSheet? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new CueSheet();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.CueSheets.CueSheet? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.CueSheets.CueSheet? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new CueSheet();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.CueSheets.CueSheet? Deserialize(Stream? data)
|
||||
public override Models.CueSheets.CueSheet? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -647,7 +589,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,71 +3,13 @@ using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.Models.DosCenter;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class DosCenter :
|
||||
IByteDeserializer<MetadataFile>,
|
||||
IFileDeserializer<MetadataFile>,
|
||||
IStreamDeserializer<MetadataFile>
|
||||
public class DosCenter : BaseBinaryDeserializer<MetadataFile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static MetadataFile? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new DosCenter();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static MetadataFile? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new DosCenter();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static MetadataFile? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new DosCenter();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(Stream? data)
|
||||
public override MetadataFile? Deserialize(Stream? data)
|
||||
{
|
||||
// If the stream is null
|
||||
if (data == null)
|
||||
@@ -268,7 +210,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
file.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
return file;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,71 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.Models.EverdriveSMDB;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class EverdriveSMDB :
|
||||
IByteDeserializer<MetadataFile>,
|
||||
IFileDeserializer<MetadataFile>,
|
||||
IStreamDeserializer<MetadataFile>
|
||||
public class EverdriveSMDB : BaseBinaryDeserializer<MetadataFile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static MetadataFile? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new EverdriveSMDB();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static MetadataFile? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new EverdriveSMDB();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static MetadataFile? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new EverdriveSMDB();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(Stream? data)
|
||||
public override MetadataFile? Deserialize(Stream? data)
|
||||
{
|
||||
// If the stream is null
|
||||
if (data == null)
|
||||
@@ -116,7 +58,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
dat.Row = rows.ToArray();
|
||||
return dat;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.GCF;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class GCF :
|
||||
IByteDeserializer<Models.GCF.File>,
|
||||
IFileDeserializer<Models.GCF.File>,
|
||||
IStreamDeserializer<Models.GCF.File>
|
||||
public class GCF : BaseBinaryDeserializer<Models.GCF.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.GCF.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new GCF();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.GCF.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.GCF.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new GCF();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.GCF.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.GCF.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new GCF();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.GCF.File? Deserialize(Stream? data)
|
||||
public override Models.GCF.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -797,7 +739,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return dataBlockHeader;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,11 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.Models.Hashfile;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class Hashfile :
|
||||
IByteDeserializer<Models.Hashfile.Hashfile>,
|
||||
IFileDeserializer<Models.Hashfile.Hashfile>,
|
||||
IStreamDeserializer<Models.Hashfile.Hashfile>
|
||||
// TODO: Create variants for the implemented types
|
||||
public class Hashfile : BaseBinaryDeserializer<Models.Hashfile.Hashfile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
@@ -23,7 +20,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.Hashfile.Hashfile? Deserialize(byte[]? data, int offset)
|
||||
public override Models.Hashfile.Hashfile? Deserialize(byte[]? data, int offset)
|
||||
=> Deserialize(data, offset, HashType.CRC32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -54,7 +51,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.Hashfile.Hashfile? Deserialize(string? path)
|
||||
public override Models.Hashfile.Hashfile? Deserialize(string? path)
|
||||
=> Deserialize(path, HashType.CRC32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -76,7 +73,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.Hashfile.Hashfile? Deserialize(Stream? data)
|
||||
public override Models.Hashfile.Hashfile? Deserialize(Stream? data)
|
||||
=> Deserialize(data, HashType.CRC32);
|
||||
|
||||
/// <inheritdoc cref="Deserialize(Stream)"/>
|
||||
|
||||
@@ -1,71 +1,13 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class IRD :
|
||||
IByteDeserializer<Models.IRD.File>,
|
||||
IFileDeserializer<Models.IRD.File>,
|
||||
IStreamDeserializer<Models.IRD.File>
|
||||
public class IRD : BaseBinaryDeserializer<Models.IRD.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.IRD.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new IRD();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.IRD.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.IRD.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new IRD();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.IRD.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.IRD.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new IRD();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.IRD.File? Deserialize(Stream? data)
|
||||
public override Models.IRD.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -167,7 +109,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return ird;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,75 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.InstallShieldCabinet;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.InstallShieldCabinet.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
// TODO: Add multi-cabinet reading
|
||||
public class InstallShieldCabinet :
|
||||
IByteDeserializer<Cabinet>,
|
||||
IFileDeserializer<Cabinet>,
|
||||
IStreamDeserializer<Cabinet>
|
||||
public class InstallShieldCabinet : BaseBinaryDeserializer<Cabinet>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Cabinet? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new InstallShieldCabinet();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cabinet? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Cabinet? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new InstallShieldCabinet();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cabinet? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Cabinet? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new InstallShieldCabinet();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cabinet? Deserialize(Stream? data)
|
||||
public override Cabinet? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -833,7 +775,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
@@ -9,15 +8,12 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// Base class for other JSON serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class JsonFile<T> :
|
||||
IByteDeserializer<T>,
|
||||
IFileDeserializer<T>,
|
||||
IStreamDeserializer<T>
|
||||
public class JsonFile<T> : BaseBinaryDeserializer<T>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual T? Deserialize(byte[]? data, int offset)
|
||||
public override T? Deserialize(byte[]? data, int offset)
|
||||
=> Deserialize(data, offset, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
@@ -48,7 +44,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual T? Deserialize(string? path)
|
||||
public override T? Deserialize(string? path)
|
||||
=> Deserialize(path, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
@@ -69,7 +65,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual T? Deserialize(Stream? data)
|
||||
public override T? Deserialize(Stream? data)
|
||||
=> Deserialize(data, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,74 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.LinearExecutable;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.LinearExecutable.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class LinearExecutable :
|
||||
IByteDeserializer<Executable>,
|
||||
IFileDeserializer<Executable>,
|
||||
IStreamDeserializer<Executable>
|
||||
public class LinearExecutable : BaseBinaryDeserializer<Executable>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Executable? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new LinearExecutable();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Executable? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new LinearExecutable();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Executable? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new LinearExecutable();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(Stream? data)
|
||||
public override Executable? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -1059,7 +1001,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return debugInformation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,71 +3,13 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Models.Listrom;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class Listrom :
|
||||
IByteDeserializer<MetadataFile>,
|
||||
IFileDeserializer<MetadataFile>,
|
||||
IStreamDeserializer<MetadataFile>
|
||||
public class Listrom : BaseBinaryDeserializer<MetadataFile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static MetadataFile? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new Listrom();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static MetadataFile? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new Listrom();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static MetadataFile? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new Listrom();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(Stream? data)
|
||||
public override MetadataFile? Deserialize(Stream? data)
|
||||
{
|
||||
// If the stream is null
|
||||
if (data == null)
|
||||
@@ -295,7 +237,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
||||
return dat;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,7 @@
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class Listxml :
|
||||
XmlFile<Models.Listxml.Mame>
|
||||
public class Listxml : XmlFile<Models.Listxml.Mame>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.Listxml.Mame? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new Listxml();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.Listxml.Mame? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new Listxml();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.Listxml.Mame? DeserializeStream(System.IO.Stream? data)
|
||||
{
|
||||
var deserializer = new Listxml();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,7 @@
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class Logiqx :
|
||||
XmlFile<Models.Logiqx.Datafile>
|
||||
public class Logiqx : XmlFile<Models.Logiqx.Datafile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.Logiqx.Datafile? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new Logiqx();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.Logiqx.Datafile? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new Logiqx();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.Logiqx.Datafile? DeserializeStream(System.IO.Stream? data)
|
||||
{
|
||||
var deserializer = new Logiqx();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,7 @@
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class M1 :
|
||||
XmlFile<Models.Listxml.M1>
|
||||
public class M1 : XmlFile<Models.Listxml.M1>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.Listxml.M1? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new M1();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.Listxml.M1? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new M1();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.Listxml.M1? DeserializeStream(System.IO.Stream? data)
|
||||
{
|
||||
var deserializer = new M1();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.MSDOS;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.MSDOS.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class MSDOS :
|
||||
IByteDeserializer<Executable>,
|
||||
IFileDeserializer<Executable>,
|
||||
IStreamDeserializer<Executable>
|
||||
public class MSDOS : BaseBinaryDeserializer<Executable>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Executable? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new MSDOS();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Executable? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new MSDOS();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Executable? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new MSDOS();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(Stream? data)
|
||||
public override Executable? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -199,7 +141,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return relocationTable;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,16 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.MicrosoftCabinet;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.MicrosoftCabinet.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
// TODO: Add multi-cabinet reading
|
||||
public class MicrosoftCabinet :
|
||||
IByteDeserializer<Cabinet>,
|
||||
IFileDeserializer<Cabinet>,
|
||||
IStreamDeserializer<Cabinet>
|
||||
public class MicrosoftCabinet : BaseBinaryDeserializer<Cabinet>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Cabinet? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new MicrosoftCabinet();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cabinet? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Cabinet? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new MicrosoftCabinet();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cabinet? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Cabinet? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new MicrosoftCabinet();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cabinet? Deserialize(Stream? data)
|
||||
public override Cabinet? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -298,7 +240,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,74 +2,16 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.MoPaQ;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.MoPaQ.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class MoPaQ :
|
||||
IByteDeserializer<Archive>,
|
||||
IFileDeserializer<Archive>,
|
||||
IStreamDeserializer<Archive>
|
||||
public class MoPaQ : BaseBinaryDeserializer<Archive>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Archive? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new MoPaQ();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Archive? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new MoPaQ();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Archive? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new MoPaQ();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(Stream? data)
|
||||
public override Archive? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -685,7 +627,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,16 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.N3DS;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.N3DS.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class N3DS :
|
||||
IByteDeserializer<Cart>,
|
||||
IFileDeserializer<Cart>,
|
||||
IStreamDeserializer<Cart>
|
||||
public class N3DS : BaseBinaryDeserializer<Cart>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Cart? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new N3DS();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cart? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Cart? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new N3DS();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cart? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Cart? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new N3DS();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cart? Deserialize(Stream? data)
|
||||
public override Cart? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -765,7 +707,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return romFSHeader;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.NCF;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class NCF :
|
||||
IByteDeserializer<Models.NCF.File>,
|
||||
IFileDeserializer<Models.NCF.File>,
|
||||
IStreamDeserializer<Models.NCF.File>
|
||||
public class NCF : BaseBinaryDeserializer<Models.NCF.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.NCF.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new NCF();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.NCF.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.NCF.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new NCF();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.NCF.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.NCF.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new NCF();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.NCF.File? Deserialize(Stream? data)
|
||||
public override Models.NCF.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -566,7 +508,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return checksumEntry;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,74 +2,16 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.NewExecutable;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.NewExecutable.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class NewExecutable :
|
||||
IByteDeserializer<Executable>,
|
||||
IFileDeserializer<Executable>,
|
||||
IStreamDeserializer<Executable>
|
||||
public class NewExecutable : BaseBinaryDeserializer<Executable>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Executable? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new NewExecutable();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Executable? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new NewExecutable();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Executable? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new NewExecutable();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(Stream? data)
|
||||
public override Executable? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -534,7 +476,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return [.. residentNameTable];
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.Nitro;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class Nitro :
|
||||
IByteDeserializer<Cart>,
|
||||
IFileDeserializer<Cart>,
|
||||
IStreamDeserializer<Cart>
|
||||
public class Nitro : BaseBinaryDeserializer<Cart>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Cart? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new Nitro();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cart? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Cart? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new Nitro();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cart? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Cart? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new Nitro();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Cart? Deserialize(Stream? data)
|
||||
public override Cart? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -417,7 +359,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,7 @@
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class OfflineList :
|
||||
XmlFile<Models.OfflineList.Dat>
|
||||
public class OfflineList : XmlFile<Models.OfflineList.Dat>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.OfflineList.Dat? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new OfflineList();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.OfflineList.Dat? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new OfflineList();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.OfflineList.Dat? DeserializeStream(System.IO.Stream? data)
|
||||
{
|
||||
var deserializer = new OfflineList();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,7 @@
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class OpenMSX :
|
||||
XmlFile<Models.OpenMSX.SoftwareDb>
|
||||
public class OpenMSX : XmlFile<Models.OpenMSX.SoftwareDb>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.OpenMSX.SoftwareDb? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new OpenMSX();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.OpenMSX.SoftwareDb? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new OpenMSX();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.OpenMSX.SoftwareDb? DeserializeStream(System.IO.Stream? data)
|
||||
{
|
||||
var deserializer = new OpenMSX();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.PAK;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.PAK.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class PAK :
|
||||
IByteDeserializer<Models.PAK.File>,
|
||||
IFileDeserializer<Models.PAK.File>,
|
||||
IStreamDeserializer<Models.PAK.File>
|
||||
public class PAK : BaseBinaryDeserializer<Models.PAK.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.PAK.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new PAK();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.PAK.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.PAK.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new PAK();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.PAK.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.PAK.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new PAK();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.PAK.File? Deserialize(Stream? data)
|
||||
public override Models.PAK.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -162,7 +104,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return directoryItem;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.PFF;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.PFF.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class PFF :
|
||||
IByteDeserializer<Archive>,
|
||||
IFileDeserializer<Archive>,
|
||||
IStreamDeserializer<Archive>
|
||||
public class PFF : BaseBinaryDeserializer<Archive>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Archive? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new PFF();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Archive? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new PFF();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Archive? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new PFF();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(Stream? data)
|
||||
public override Archive? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -237,7 +179,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return segment;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.PIC;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.PIC.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class PIC :
|
||||
IByteDeserializer<DiscInformation>,
|
||||
IFileDeserializer<DiscInformation>,
|
||||
IStreamDeserializer<DiscInformation>
|
||||
public class PIC : BaseBinaryDeserializer<DiscInformation>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static DiscInformation? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new PIC();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DiscInformation? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static DiscInformation? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new PIC();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DiscInformation? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static DiscInformation? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new PIC();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DiscInformation? Deserialize(Stream? data)
|
||||
public override DiscInformation? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
|
||||
@@ -1,64 +1,13 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.PlayJ;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.PlayJ.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class PlayJAudio :
|
||||
IByteDeserializer<AudioFile>,
|
||||
IFileDeserializer<AudioFile>,
|
||||
IStreamDeserializer<AudioFile>
|
||||
public class PlayJAudio : BaseBinaryDeserializer<AudioFile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static AudioFile? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new PlayJAudio();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public AudioFile? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static AudioFile? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new PlayJAudio();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public AudioFile? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static AudioFile? DeserializeStream(Stream? data, long adjust = 0)
|
||||
{
|
||||
@@ -67,7 +16,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public AudioFile? Deserialize(Stream? data)
|
||||
public override AudioFile? Deserialize(Stream? data)
|
||||
=> Deserialize(data, 0);
|
||||
|
||||
/// <inheritdoc cref="Deserialize(Stream)"/>
|
||||
@@ -397,7 +346,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,71 +1,13 @@
|
||||
using System.IO;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.PlayJ;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class PlayJPlaylist :
|
||||
IByteDeserializer<Playlist>,
|
||||
IFileDeserializer<Playlist>,
|
||||
IStreamDeserializer<Playlist>
|
||||
public class PlayJPlaylist : BaseBinaryDeserializer<Playlist>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Playlist? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new PlayJPlaylist();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Playlist? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Playlist? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new PlayJPlaylist();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Playlist? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Playlist? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new PlayJPlaylist();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Playlist? Deserialize(Stream? data)
|
||||
public override Playlist? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -129,7 +71,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return playlistHeader;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,74 +3,16 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.PortableExecutable;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.PortableExecutable.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class PortableExecutable :
|
||||
IByteDeserializer<Executable>,
|
||||
IFileDeserializer<Executable>,
|
||||
IStreamDeserializer<Executable>
|
||||
public class PortableExecutable : BaseBinaryDeserializer<Executable>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Executable? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new PortableExecutable();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Executable? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new PortableExecutable();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Executable? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new PortableExecutable();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Executable? Deserialize(Stream? data)
|
||||
public override Executable? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -1387,7 +1329,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return resourceDirectoryTable;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.Quantum;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.Quantum.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class Quantum :
|
||||
IByteDeserializer<Archive>,
|
||||
IFileDeserializer<Archive>,
|
||||
IStreamDeserializer<Archive>
|
||||
public class Quantum : BaseBinaryDeserializer<Archive>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Archive? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new Quantum();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Archive? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new Quantum();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Archive? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new Quantum();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Archive? Deserialize(Stream? data)
|
||||
public override Archive? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -210,7 +152,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
byte b1 = data.ReadByteValue();
|
||||
return (b0 << 8) | b1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,71 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.Models.RomCenter;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class RomCenter :
|
||||
IByteDeserializer<MetadataFile>,
|
||||
IFileDeserializer<MetadataFile>,
|
||||
IStreamDeserializer<MetadataFile>
|
||||
public class RomCenter : BaseBinaryDeserializer<MetadataFile>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static MetadataFile? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new RomCenter();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static MetadataFile? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new RomCenter();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static MetadataFile? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new RomCenter();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(Stream? data)
|
||||
public override MetadataFile? Deserialize(Stream? data)
|
||||
{
|
||||
// If the stream is null
|
||||
if (data == null)
|
||||
@@ -267,7 +209,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
return dat;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.SGA;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.SGA.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class SGA :
|
||||
IByteDeserializer<Models.SGA.File>,
|
||||
IFileDeserializer<Models.SGA.File>,
|
||||
IStreamDeserializer<Models.SGA.File>
|
||||
public class SGA : BaseBinaryDeserializer<Models.SGA.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.SGA.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new SGA();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.SGA.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.SGA.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new SGA();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.SGA.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.SGA.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new SGA();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.SGA.File? Deserialize(Stream? data)
|
||||
public override Models.SGA.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -782,7 +724,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return file7;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Readers;
|
||||
using SabreTools.Models.SeparatedValue;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class SeparatedValue :
|
||||
IByteDeserializer<MetadataFile>,
|
||||
IFileDeserializer<MetadataFile>,
|
||||
IStreamDeserializer<MetadataFile>
|
||||
// TODO: Create variants for the 3 common types: CSV, SSV, TSV
|
||||
public class SeparatedValue : BaseBinaryDeserializer<MetadataFile>
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -31,7 +28,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
public override MetadataFile? Deserialize(byte[]? data, int offset)
|
||||
=> Deserialize(data, offset, ',');
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -62,7 +59,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(string? path)
|
||||
public override MetadataFile? Deserialize(string? path)
|
||||
=> Deserialize(path, ',');
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -84,7 +81,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MetadataFile? Deserialize(Stream? data)
|
||||
public override MetadataFile? Deserialize(Stream? data)
|
||||
=> Deserialize(data, ',');
|
||||
|
||||
/// <inheritdoc cref="Deserialize(Stream)"/>
|
||||
|
||||
@@ -1,39 +1,7 @@
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class SoftwareList :
|
||||
XmlFile<Models.SoftwareList.SoftwareList>
|
||||
public class SoftwareList : XmlFile<Models.SoftwareList.SoftwareList>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.SoftwareList.SoftwareList? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new SoftwareList();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.SoftwareList.SoftwareList? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new SoftwareList();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.SoftwareList.SoftwareList? DeserializeStream(System.IO.Stream? data)
|
||||
{
|
||||
var deserializer = new SoftwareList();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.VBSP;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.VBSP.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class VBSP :
|
||||
IByteDeserializer<Models.VBSP.File>,
|
||||
IFileDeserializer<Models.VBSP.File>,
|
||||
IStreamDeserializer<Models.VBSP.File>
|
||||
public class VBSP : BaseBinaryDeserializer<Models.VBSP.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.VBSP.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new VBSP();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.VBSP.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.VBSP.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new VBSP();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.VBSP.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.VBSP.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new VBSP();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.VBSP.File? Deserialize(Stream? data)
|
||||
public override Models.VBSP.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -165,7 +107,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return lump;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.VPK;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.VPK.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class VPK :
|
||||
IByteDeserializer<Models.VPK.File>,
|
||||
IFileDeserializer<Models.VPK.File>,
|
||||
IStreamDeserializer<Models.VPK.File>
|
||||
public class VPK : BaseBinaryDeserializer<Models.VPK.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.VPK.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new VPK();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.VPK.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.VPK.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new VPK();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.VPK.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.VPK.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new VPK();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.VPK.File? Deserialize(Stream? data)
|
||||
public override Models.VPK.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -339,7 +281,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return directoryEntry;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.WAD;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.WAD.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class WAD :
|
||||
IByteDeserializer<Models.WAD.File>,
|
||||
IFileDeserializer<Models.WAD.File>,
|
||||
IStreamDeserializer<Models.WAD.File>
|
||||
public class WAD : BaseBinaryDeserializer<Models.WAD.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.WAD.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new WAD();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.WAD.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.WAD.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new WAD();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.WAD.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.WAD.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new WAD();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.WAD.File? Deserialize(Stream? data)
|
||||
public override Models.WAD.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -298,7 +240,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return lumpInfo;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.XZP;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
using static SabreTools.Models.XZP.Constants;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public class XZP :
|
||||
IByteDeserializer<Models.XZP.File>,
|
||||
IFileDeserializer<Models.XZP.File>,
|
||||
IStreamDeserializer<Models.XZP.File>
|
||||
public class XZP : BaseBinaryDeserializer<Models.XZP.File>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc cref="IByteDeserializer.Deserialize(byte[]?, int)"/>
|
||||
public static Models.XZP.File? DeserializeBytes(byte[]? data, int offset)
|
||||
{
|
||||
var deserializer = new XZP();
|
||||
return deserializer.Deserialize(data, offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.XZP.File? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return DeserializeStream(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc cref="IFileDeserializer.Deserialize(string?)"/>
|
||||
public static Models.XZP.File? DeserializeFile(string? path)
|
||||
{
|
||||
var deserializer = new XZP();
|
||||
return deserializer.Deserialize(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.XZP.File? Deserialize(string? path)
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return DeserializeStream(stream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc cref="IStreamDeserializer.Deserialize(Stream?)"/>
|
||||
public static Models.XZP.File? DeserializeStream(Stream? data)
|
||||
{
|
||||
var deserializer = new XZP();
|
||||
return deserializer.Deserialize(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Models.XZP.File? Deserialize(Stream? data)
|
||||
public override Models.XZP.File? Deserialize(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
@@ -301,7 +243,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return footer;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
@@ -10,46 +9,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// Base class for other XML deserializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class XmlFile<T> :
|
||||
IByteDeserializer<T>,
|
||||
IFileDeserializer<T>,
|
||||
IStreamDeserializer<T>
|
||||
public class XmlFile<T> : BaseBinaryDeserializer<T>
|
||||
{
|
||||
#region IByteDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public T? Deserialize(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return default;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return default;
|
||||
|
||||
// Create a memory stream and parse that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Deserialize(dataStream);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public T? Deserialize(string? path)
|
||||
{
|
||||
using var data = PathProcessor.OpenStream(path);
|
||||
return Deserialize(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamDeserializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public T? Deserialize(Stream? data)
|
||||
public override T? Deserialize(Stream? data)
|
||||
{
|
||||
// If the stream is null
|
||||
if (data == null)
|
||||
@@ -72,7 +35,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Perform the deserialization and return
|
||||
return (T?)serializer.Deserialize(xmlReader);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.PortableExecutable;
|
||||
|
||||
namespace SabreTools.Serialization
|
||||
|
||||
16
SabreTools.Serialization/Interfaces/IByteSerializer.cs
Normal file
16
SabreTools.Serialization/Interfaces/IByteSerializer.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace SabreTools.Serialization.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines how to serialize to byte arrays
|
||||
/// </summary>
|
||||
public interface IByteSerializer<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="T"/> into a byte array
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to serialize from</typeparam>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
byte[]? SerializeArray(T? obj);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,20 @@
|
||||
namespace SabreTools.Serialization.Interfaces
|
||||
{
|
||||
public interface IWrapper
|
||||
/// <summary>
|
||||
/// Represents a wrapper around a top-level model
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">Top-level model for the wrapper</typeparam>
|
||||
public interface IWrapper<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a human-readable description of the wrapper
|
||||
/// </summary>
|
||||
string Description();
|
||||
|
||||
/// <summary>
|
||||
/// Get the backing model
|
||||
/// </summary>
|
||||
TModel GetModel();
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.5.0</Version>
|
||||
<Version>1.5.1</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
@@ -29,7 +29,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.2.0" />
|
||||
<PackageReference Include="SabreTools.IO" Version="1.3.3" />
|
||||
<PackageReference Include="SabreTools.IO" Version="1.3.6" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -2,26 +2,6 @@ namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class ArchiveDotOrg : XmlFile<Models.ArchiveDotOrg.Files>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.ArchiveDotOrg.Files? obj, string? path)
|
||||
{
|
||||
var serializer = new ArchiveDotOrg();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamSerializer.Serialize(T?)"/>
|
||||
public static System.IO.Stream? SerializeStream(Models.ArchiveDotOrg.Files? obj)
|
||||
{
|
||||
var serializer = new ArchiveDotOrg();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Writers;
|
||||
using SabreTools.Models.AttractMode;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class AttractMode :
|
||||
IFileSerializer<MetadataFile>,
|
||||
IStreamSerializer<MetadataFile>
|
||||
public class AttractMode : BaseBinarySerializer<MetadataFile>
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -66,17 +63,44 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(MetadataFile? obj, string? path, bool longHeader = false)
|
||||
/// <inheritdoc cref="Interfaces.IByteSerializer.SerializeArray(T?)"/>
|
||||
public static byte[]? SerializeBytes(MetadataFile? obj, bool longHeader = false)
|
||||
{
|
||||
var serializer = new AttractMode();
|
||||
return serializer.Serialize(obj, path);
|
||||
return serializer.SerializeArray(obj, longHeader);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(MetadataFile? obj, string? path)
|
||||
public override byte[]? SerializeArray(MetadataFile? obj)
|
||||
=> SerializeArray(obj, false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public byte[]? SerializeArray(MetadataFile? obj, bool longHeader)
|
||||
{
|
||||
using var stream = SerializeStream(obj, longHeader);
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(MetadataFile? obj, string? path, bool longHeader = false)
|
||||
{
|
||||
var serializer = new AttractMode();
|
||||
return serializer.Serialize(obj, path, longHeader);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Serialize(MetadataFile? obj, string? path)
|
||||
=> Serialize(obj, path, false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -98,7 +122,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
/// <inheritdoc cref="Interfaces.IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(MetadataFile? obj, bool longHeader = false)
|
||||
{
|
||||
var serializer = new AttractMode();
|
||||
@@ -106,7 +130,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(MetadataFile? obj)
|
||||
public override Stream? Serialize(MetadataFile? obj)
|
||||
=> Serialize(obj, false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
138
SabreTools.Serialization/Serializers/BaseBinarySerializer.cs
Normal file
138
SabreTools.Serialization/Serializers/BaseBinarySerializer.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for all binary serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">Type of the model to serialize</typeparam>
|
||||
/// <remarks>These methods assume there is a concrete implementation of the serializer for the model available</remarks>
|
||||
public abstract class BaseBinarySerializer<TModel> :
|
||||
IByteSerializer<TModel>,
|
||||
IFileSerializer<TModel>,
|
||||
IStreamSerializer<TModel>
|
||||
{
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual byte[]? SerializeArray(TModel? obj)
|
||||
{
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool Serialize(TModel? obj, string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract Stream? Serialize(TModel? obj);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Implementations
|
||||
|
||||
/// <inheritdoc cref="IByteSerializer.Deserialize(T?)"/>
|
||||
public static byte[]? SerializeBytes(TModel? obj)
|
||||
{
|
||||
var serializer = GetType<IByteSerializer<TModel>>();
|
||||
if (serializer == null)
|
||||
return default;
|
||||
|
||||
return serializer.SerializeArray(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(TModel? obj, string? path)
|
||||
{
|
||||
var serializer = GetType<IFileSerializer<TModel>>();
|
||||
if (serializer == null)
|
||||
return default;
|
||||
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(TModel? obj)
|
||||
{
|
||||
var serializer = GetType<IStreamSerializer<TModel>>();
|
||||
if (serializer == null)
|
||||
return default;
|
||||
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Get a constructed instance of a type, if possible
|
||||
/// </summary>
|
||||
/// <typeparam name="TSerializer">Serializer type to construct</typeparam>
|
||||
/// <returns>Serializer of the requested type, null on error</returns>
|
||||
private static TSerializer? GetType<TSerializer>()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
if (assembly == null)
|
||||
return default;
|
||||
|
||||
// If not all types can be loaded, use the ones that could be
|
||||
List<Type> assemblyTypes = [];
|
||||
try
|
||||
{
|
||||
assemblyTypes = assembly.GetTypes().ToList<Type>();
|
||||
}
|
||||
catch (ReflectionTypeLoadException rtle)
|
||||
{
|
||||
assemblyTypes = rtle.Types.Where(t => t != null)!.ToList<Type>();
|
||||
}
|
||||
|
||||
// Loop through all types
|
||||
foreach (Type type in assemblyTypes)
|
||||
{
|
||||
// If the type isn't a class or doesn't implement the interface
|
||||
if (!type.IsClass || type.GetInterface(typeof(TSerializer).Name) == null)
|
||||
continue;
|
||||
|
||||
// Try to create a concrete instance of the type
|
||||
var instance = (TSerializer?)Activator.CreateInstance(type);
|
||||
if (instance != null)
|
||||
return instance;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,37 +3,10 @@ using System.Text;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class Catalog :
|
||||
JsonFile<Models.Xbox.Catalog>
|
||||
public class Catalog : JsonFile<Models.Xbox.Catalog>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.Xbox.Catalog? obj, string? path)
|
||||
{
|
||||
var serializer = new Catalog();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <remarks>Catalog.js file is encoded as UTF-16 LE</remarks>
|
||||
public override bool Serialize(Models.Xbox.Catalog? obj, string? path)
|
||||
=> Serialize(obj, path, new UnicodeEncoding());
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(Models.Xbox.Catalog? obj)
|
||||
{
|
||||
var serializer = new Catalog();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <remarks>Catalog.js file is encoded as UTF-16 LE</remarks>
|
||||
public override Stream? Serialize(Models.Xbox.Catalog? obj)
|
||||
=> Serialize(obj, new UnicodeEncoding());
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,38 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Writers;
|
||||
using SabreTools.Models.ClrMamePro;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class ClrMamePro :
|
||||
IFileSerializer<MetadataFile>,
|
||||
IStreamSerializer<MetadataFile>
|
||||
public class ClrMamePro : BaseBinarySerializer<MetadataFile>
|
||||
{
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteSerializer.SerializeArray(T?)"/>
|
||||
public static byte[]? SerializeBytes(MetadataFile? obj, bool quotes = false)
|
||||
{
|
||||
var serializer = new ClrMamePro();
|
||||
return serializer.SerializeArray(obj, quotes);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override byte[]? SerializeArray(MetadataFile? obj)
|
||||
=> SerializeArray(obj, false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public byte[]? SerializeArray(MetadataFile? obj, bool quotes)
|
||||
{
|
||||
using var stream = SerializeStream(obj, quotes);
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
@@ -21,7 +45,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(MetadataFile? obj, string? path)
|
||||
public override bool Serialize(MetadataFile? obj, string? path)
|
||||
=> Serialize(obj, path, true);
|
||||
|
||||
/// <inheritdoc cref="Serialize(MetadataFile, string)"/>
|
||||
@@ -51,7 +75,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(MetadataFile? obj)
|
||||
public override Stream? Serialize(MetadataFile? obj)
|
||||
=> Serialize(obj, true);
|
||||
|
||||
/// <inheritdoc cref="Serialize(MetadataFile)"/>
|
||||
|
||||
@@ -2,51 +2,13 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Models.CueSheets;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class CueSheet :
|
||||
IFileSerializer<Models.CueSheets.CueSheet>,
|
||||
IStreamSerializer<Models.CueSheets.CueSheet>
|
||||
public class CueSheet : BaseBinarySerializer<Models.CueSheets.CueSheet>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.CueSheets.CueSheet? obj, string? path)
|
||||
{
|
||||
var serializer = new CueSheet();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(Models.CueSheets.CueSheet? obj, string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(Models.CueSheets.CueSheet? obj)
|
||||
{
|
||||
var serializer = new CueSheet();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(Models.CueSheets.CueSheet? obj)
|
||||
public override Stream? Serialize(Models.CueSheets.CueSheet? obj)
|
||||
{
|
||||
// If the cuesheet is null
|
||||
if (obj == null)
|
||||
@@ -293,7 +255,5 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,51 +3,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Writers;
|
||||
using SabreTools.Models.DosCenter;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class DosCenter :
|
||||
IFileSerializer<MetadataFile>,
|
||||
IStreamSerializer<MetadataFile>
|
||||
public class DosCenter : BaseBinarySerializer<MetadataFile>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(MetadataFile? obj, string? path)
|
||||
{
|
||||
var serializer = new DosCenter();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(MetadataFile? obj, string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(MetadataFile? obj)
|
||||
{
|
||||
var serializer = new DosCenter();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(MetadataFile? obj)
|
||||
public override Stream? Serialize(MetadataFile? obj)
|
||||
{
|
||||
// If the metadata file is null
|
||||
if (obj == null)
|
||||
@@ -160,7 +122,5 @@ namespace SabreTools.Serialization.Serializers
|
||||
writer.WriteEndElement(); // file
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,51 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Writers;
|
||||
using SabreTools.Models.EverdriveSMDB;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class EverdriveSMDB :
|
||||
IFileSerializer<MetadataFile>,
|
||||
IStreamSerializer<MetadataFile>
|
||||
public class EverdriveSMDB : BaseBinarySerializer<MetadataFile>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(MetadataFile? obj, string? path)
|
||||
{
|
||||
var serializer = new EverdriveSMDB();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(MetadataFile? obj, string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(MetadataFile? obj)
|
||||
{
|
||||
var serializer = new EverdriveSMDB();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(MetadataFile? obj)
|
||||
public override Stream? Serialize(MetadataFile? obj)
|
||||
{
|
||||
// If the metadata file is null
|
||||
if (obj == null)
|
||||
@@ -99,7 +61,5 @@ namespace SabreTools.Serialization.Serializers
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,39 @@ using System.Text;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.IO.Writers;
|
||||
using SabreTools.Models.Hashfile;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class Hashfile :
|
||||
IFileSerializer<Models.Hashfile.Hashfile>,
|
||||
IStreamSerializer<Models.Hashfile.Hashfile>
|
||||
// TODO: Create variants for the implemented types
|
||||
public class Hashfile : BaseBinarySerializer<Models.Hashfile.Hashfile>
|
||||
{
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteSerializer.SerializeArray(T?)"/>
|
||||
public static byte[]? SerializeBytes(Models.Hashfile.Hashfile? obj, HashType hash = HashType.CRC32)
|
||||
{
|
||||
var serializer = new Hashfile();
|
||||
return serializer.SerializeArray(obj, hash);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override byte[]? SerializeArray(Models.Hashfile.Hashfile? obj)
|
||||
=> SerializeArray(obj, HashType.CRC32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public byte[]? SerializeArray(Models.Hashfile.Hashfile? obj, HashType hash)
|
||||
{
|
||||
using var stream = SerializeStream(obj, hash);
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
@@ -23,7 +48,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(Models.Hashfile.Hashfile? obj, string? path)
|
||||
public override bool Serialize(Models.Hashfile.Hashfile? obj, string? path)
|
||||
=> Serialize(obj, path, HashType.CRC32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -53,7 +78,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(Models.Hashfile.Hashfile? obj)
|
||||
public override Stream? Serialize(Models.Hashfile.Hashfile? obj)
|
||||
=> Serialize(obj, HashType.CRC32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -2,51 +2,13 @@ using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class IRD :
|
||||
IFileSerializer<Models.IRD.File>,
|
||||
IStreamSerializer<Models.IRD.File>
|
||||
public class IRD : BaseBinarySerializer<Models.IRD.File>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.IRD.File? obj, string? path)
|
||||
{
|
||||
var serializer = new IRD();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(Models.IRD.File? obj, string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(Models.IRD.File? obj)
|
||||
{
|
||||
var serializer = new IRD();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(Models.IRD.File? obj)
|
||||
public override Stream? Serialize(Models.IRD.File? obj)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (obj?.Magic == null)
|
||||
@@ -165,7 +127,5 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
@@ -9,14 +8,38 @@ namespace SabreTools.Serialization.Serializers
|
||||
/// Base class for other JSON serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class JsonFile<T> :
|
||||
IFileSerializer<T>,
|
||||
IStreamSerializer<T>
|
||||
public class JsonFile<T> : BaseBinarySerializer<T>
|
||||
{
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override byte[]? SerializeArray(T? obj)
|
||||
=> SerializeArray(obj, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="T"/> into a byte array
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to serialize from</typeparam>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <param name="encoding">Encoding to parse text as</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
public byte[]? SerializeArray(T? obj, Encoding encoding)
|
||||
{
|
||||
using var stream = Serialize(obj, encoding);
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool Serialize(T? obj, string? path)
|
||||
public override bool Serialize(T? obj, string? path)
|
||||
=> Serialize(obj, path, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +70,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual Stream? Serialize(T? obj)
|
||||
public override Stream? Serialize(T? obj)
|
||||
=> Serialize(obj, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,51 +2,13 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.Models.Listrom;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class Listrom :
|
||||
IFileSerializer<MetadataFile>,
|
||||
IStreamSerializer<MetadataFile>
|
||||
public class Listrom : BaseBinarySerializer<MetadataFile>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(MetadataFile? obj, string? path)
|
||||
{
|
||||
var serializer = new Listrom();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(MetadataFile? obj, string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(MetadataFile? obj)
|
||||
{
|
||||
var serializer = new Listrom();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(MetadataFile? obj)
|
||||
public override Stream? Serialize(MetadataFile? obj)
|
||||
{
|
||||
// If the metadata file is null
|
||||
if (obj == null)
|
||||
@@ -192,7 +154,5 @@ namespace SabreTools.Serialization.Serializers
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,7 @@
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class Listxml :
|
||||
XmlFile<Models.Listxml.Mame>
|
||||
public class Listxml : XmlFile<Models.Listxml.Mame>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.Listxml.Mame? obj, string? path)
|
||||
{
|
||||
var serializer = new Listxml();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamSerializer.Serialize(T?)"/>
|
||||
public static System.IO.Stream? SerializeStream(Models.Listxml.Mame? obj)
|
||||
{
|
||||
var serializer = new Listxml();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@ using SabreTools.Models.Logiqx;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class Logiqx :
|
||||
XmlFile<Datafile>
|
||||
public class Logiqx : XmlFile<Datafile>
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -30,15 +29,16 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#endregion
|
||||
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc cref="XmlFile.SerializeArray(T?, string?, string?, string?, string?)" />
|
||||
public override byte[]? SerializeArray(Datafile? obj)
|
||||
=> SerializeArray(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Datafile? obj, string? path)
|
||||
{
|
||||
var serializer = new Logiqx();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="XmlFile.Serialize(T?, string?, string?, string?, string?, string?)" />
|
||||
public override bool Serialize(Datafile? obj, string? path)
|
||||
=> Serialize(obj, path, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
@@ -47,13 +47,6 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(Datafile? obj)
|
||||
{
|
||||
var serializer = new Logiqx();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="XmlFile.Serialize(T?, string?, string?, string?, string?)" />
|
||||
public override Stream? Serialize(Datafile? obj)
|
||||
=> Serialize(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
|
||||
@@ -1,28 +1,7 @@
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class M1 :
|
||||
XmlFile<Models.Listxml.M1>
|
||||
public class M1 : XmlFile<Models.Listxml.M1>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.Listxml.M1? obj, string? path)
|
||||
{
|
||||
var serializer = new M1();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamSerializer.Serialize(T?)"/>
|
||||
public static System.IO.Stream? SerializeStream(Models.Listxml.M1? obj)
|
||||
{
|
||||
var serializer = new M1();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,7 @@
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class OfflineList :
|
||||
XmlFile<Models.OfflineList.Dat>
|
||||
public class OfflineList : XmlFile<Models.OfflineList.Dat>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.OfflineList.Dat? obj, string? path)
|
||||
{
|
||||
var serializer = new OfflineList();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamSerializer.Serialize(T?)"/>
|
||||
public static System.IO.Stream? SerializeStream(Models.OfflineList.Dat? obj)
|
||||
{
|
||||
var serializer = new OfflineList();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// All logic taken care of in the base class
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@ using SabreTools.Models.OpenMSX;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class OpenMSX :
|
||||
XmlFile<SoftwareDb>
|
||||
public class OpenMSX : XmlFile<SoftwareDb>
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -30,15 +29,16 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#endregion
|
||||
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc cref="XmlFile.SerializeArray(T?, string?, string?, string?, string?)" />
|
||||
public override byte[]? SerializeArray(SoftwareDb? obj)
|
||||
=> SerializeArray(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(SoftwareDb? obj, string? path)
|
||||
{
|
||||
var serializer = new OpenMSX();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="XmlFile.Serialize(T?, string?, string?, string?, string?, string?)" />
|
||||
public override bool Serialize(SoftwareDb? obj, string? path)
|
||||
=> Serialize(obj, path, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
@@ -47,13 +47,6 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(SoftwareDb? obj)
|
||||
{
|
||||
var serializer = new OpenMSX();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="XmlFile.Serialize(T?, string?, string?, string?, string?)" />
|
||||
public override Stream? Serialize(SoftwareDb? obj)
|
||||
=> Serialize(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
|
||||
@@ -3,51 +3,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Writers;
|
||||
using SabreTools.Models.RomCenter;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class RomCenter :
|
||||
IFileSerializer<MetadataFile>,
|
||||
IStreamSerializer<MetadataFile>
|
||||
public class RomCenter : BaseBinarySerializer<MetadataFile>
|
||||
{
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(MetadataFile? obj, string? path)
|
||||
{
|
||||
var serializer = new RomCenter();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(MetadataFile? obj, string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = SerializeStream(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(MetadataFile? obj)
|
||||
{
|
||||
var serializer = new RomCenter();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(MetadataFile? obj)
|
||||
public override Stream? Serialize(MetadataFile? obj)
|
||||
{
|
||||
// If the metadata file is null
|
||||
if (obj == null)
|
||||
@@ -199,7 +161,5 @@ namespace SabreTools.Serialization.Serializers
|
||||
writer.WriteLine();
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,39 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Writers;
|
||||
using SabreTools.Models.SeparatedValue;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class SeparatedValue :
|
||||
IFileSerializer<MetadataFile>,
|
||||
IStreamSerializer<MetadataFile>
|
||||
// TODO: Create variants for the 3 common types: CSV, SSV, TSV
|
||||
public class SeparatedValue : BaseBinarySerializer<MetadataFile>
|
||||
{
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IByteSerializer.SerializeArray(T?)"/>
|
||||
public static byte[]? SerializeBytes(MetadataFile? obj, char delim = ',', bool longHeader = false)
|
||||
{
|
||||
var serializer = new SeparatedValue();
|
||||
return serializer.SerializeArray(obj, delim, longHeader);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override byte[]? SerializeArray(MetadataFile? obj)
|
||||
=> SerializeArray(obj, ',', false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public byte[]? SerializeArray(MetadataFile? obj, char delim, bool longHeader)
|
||||
{
|
||||
using var stream = SerializeStream(obj, delim, longHeader);
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="IFileSerializer.Serialize(T?, string?)"/>
|
||||
@@ -21,7 +46,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(MetadataFile? obj, string? path)
|
||||
public override bool Serialize(MetadataFile? obj, string? path)
|
||||
=> Serialize(obj, path, ',', false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -51,7 +76,7 @@ namespace SabreTools.Serialization.Serializers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(MetadataFile? obj)
|
||||
public override Stream? Serialize(MetadataFile? obj)
|
||||
=> Serialize(obj, ',', false);
|
||||
|
||||
/// <inheritdoc cref="Serialize(MetadataFile)"/>
|
||||
|
||||
@@ -2,8 +2,7 @@ using System.IO;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public class SoftwareList :
|
||||
XmlFile<Models.SoftwareList.SoftwareList>
|
||||
public class SoftwareList : XmlFile<Models.SoftwareList.SoftwareList>
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -31,13 +30,6 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IFileSerializer.Serialize(T?, string?)"/>
|
||||
public static bool SerializeFile(Models.SoftwareList.SoftwareList? obj, string? path)
|
||||
{
|
||||
var serializer = new SoftwareList();
|
||||
return serializer.Serialize(obj, path);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="XmlFile.Serialize(T?, string?, string?, string?, string?, string?)" />
|
||||
public override bool Serialize(Models.SoftwareList.SoftwareList? obj, string? path)
|
||||
=> Serialize(obj, path, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
@@ -46,13 +38,6 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <inheritdoc cref="Interfaces.IStreamSerializer.Serialize(T?)"/>
|
||||
public static Stream? SerializeStream(Models.SoftwareList.SoftwareList? obj)
|
||||
{
|
||||
var serializer = new SoftwareList();
|
||||
return serializer.Serialize(obj);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="XmlFile.Serialize(T?, string?, string?, string?, string?)" />
|
||||
public override Stream? Serialize(Models.SoftwareList.SoftwareList? obj)
|
||||
=> Serialize(obj, DocTypeName, DocTypePubId, DocTypeSysId, DocTypeSysId);
|
||||
|
||||
@@ -3,8 +3,7 @@ using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public partial class XMID :
|
||||
IStringSerializer<Models.Xbox.XMID>
|
||||
public partial class XMID : IStringSerializer<Models.Xbox.XMID>
|
||||
{
|
||||
#region IStringSerializer
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
public partial class XeMID :
|
||||
IStringSerializer<Models.Xbox.XeMID>
|
||||
public partial class XeMID : IStringSerializer<Models.Xbox.XeMID>
|
||||
{
|
||||
#region IStringSerializer
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Serializers
|
||||
{
|
||||
@@ -10,14 +9,40 @@ namespace SabreTools.Serialization.Serializers
|
||||
/// Base class for other XML serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class XmlFile<T> :
|
||||
IFileSerializer<T>,
|
||||
IStreamSerializer<T>
|
||||
public class XmlFile<T> : BaseBinarySerializer<T>
|
||||
{
|
||||
#region IByteSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override byte[]? SerializeArray(T? obj)
|
||||
=> SerializeArray(obj, null, null, null, null);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the defined type to a byte array
|
||||
/// </summary>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <param name="name">Optional DOCTYPE name</param>
|
||||
/// <param name="pubid">Optional DOCTYPE pubid</param>
|
||||
/// <param name="sysid">Optional DOCTYPE sysid</param>
|
||||
/// <param name="subset">Optional DOCTYPE name</param>
|
||||
/// <returns>Byte array containing serialized data on success, null otherwise</returns>
|
||||
public byte[]? SerializeArray(T? obj, string? name = null, string? pubid = null, string? sysid = null, string? subset = null)
|
||||
{
|
||||
using var stream = Serialize(obj, name, pubid, sysid, subset);
|
||||
if (stream == null)
|
||||
return null;
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFileSerializer
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool Serialize(T? obj, string? path)
|
||||
public override bool Serialize(T? obj, string? path)
|
||||
=> Serialize(obj, path, null, null, null, null);
|
||||
|
||||
/// <summary>
|
||||
@@ -49,12 +74,8 @@ namespace SabreTools.Serialization.Serializers
|
||||
|
||||
#region IStreamSerializer
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the defined type to a stream
|
||||
/// </summary>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||
public virtual Stream? Serialize(T? obj)
|
||||
/// <inheritdoc/>
|
||||
public override Stream? Serialize(T? obj)
|
||||
=> Serialize(obj, null, null, null, null);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SabreTools.Models.CHD;
|
||||
using SabreTools.Models.CueSheets;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
|
||||
@@ -26,12 +26,14 @@ namespace SabreTools.Serialization.Wrappers
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}/// <summary>
|
||||
/// Create an LE/LX executable from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the executable</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>An LE/LX executable wrapper on success, null on failure</returns>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an LE/LX executable from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the executable</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>An LE/LX executable wrapper on success, null on failure</returns>
|
||||
public static LinearExecutable? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
|
||||
@@ -25,12 +25,14 @@ namespace SabreTools.Serialization.Wrappers
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}/// <summary>
|
||||
/// Create an MS-DOS executable from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the executable</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>An MS-DOS executable wrapper on success, null on failure</returns>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an MS-DOS executable from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the executable</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>An MS-DOS executable wrapper on success, null on failure</returns>
|
||||
public static MSDOS? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
|
||||
@@ -26,12 +26,14 @@ namespace SabreTools.Serialization.Wrappers
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}/// <summary>
|
||||
/// Create a Microsoft Cabinet from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the cabinet</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A cabinet wrapper on success, null on failure</returns>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a Microsoft Cabinet from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the cabinet</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A cabinet wrapper on success, null on failure</returns>
|
||||
public static MicrosoftCabinet? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
|
||||
79
SabreTools.Serialization/Wrappers/MoPaQ.cs
Normal file
79
SabreTools.Serialization/Wrappers/MoPaQ.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.IO;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
// TODO: Figure out extension properties
|
||||
public partial class MoPaQ : WrapperBase<Models.MoPaQ.Archive>
|
||||
{
|
||||
#region Descriptive Properties
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string DescriptionString => "MoPaQ Archive";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MoPaQ(Models.MoPaQ.Archive? model, byte[]? data, int offset)
|
||||
: base(model, data, offset)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MoPaQ(Models.MoPaQ.Archive? model, Stream? data)
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a MoPaQ archive from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the archive</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A MoPaQ archive wrapper on success, null on failure</returns>
|
||||
public static MoPaQ? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a MoPaQ archive from a Stream
|
||||
/// </summary>
|
||||
/// <param name="data">Stream representing the archive</param>
|
||||
/// <returns>A MoPaQ archive wrapper on success, null on failure</returns>
|
||||
public static MoPaQ? Create(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
return null;
|
||||
|
||||
var archive = Deserializers.MoPaQ.DeserializeStream(data);
|
||||
if (archive == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return new MoPaQ(archive, data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
@@ -26,12 +25,14 @@ namespace SabreTools.Serialization.Wrappers
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}/// <summary>
|
||||
/// Create a PFF archive from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the archive</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A PFF archive wrapper on success, null on failure</returns>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PFF archive from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the archive</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A PFF archive wrapper on success, null on failure</returns>
|
||||
public static PFF? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
|
||||
79
SabreTools.Serialization/Wrappers/PIC.cs
Normal file
79
SabreTools.Serialization/Wrappers/PIC.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.IO;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
// TODO: Figure out extension properties
|
||||
public class PIC : WrapperBase<Models.PIC.DiscInformation>
|
||||
{
|
||||
#region Descriptive Properties
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string DescriptionString => "Disc Information";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PIC(Models.PIC.DiscInformation? model, byte[]? data, int offset)
|
||||
: base(model, data, offset)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PIC(Models.PIC.DiscInformation? model, Stream? data)
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PIC disc information object from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the information</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A PIC disc information wrapper on success, null on failure</returns>
|
||||
public static PIC? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PIC disc information object from a Stream
|
||||
/// </summary>
|
||||
/// <param name="data">Stream representing the information</param>
|
||||
/// <returns>A PIC disc information wrapper on success, null on failure</returns>
|
||||
public static PIC? Create(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
return null;
|
||||
|
||||
var info = Deserializers.PIC.DeserializeStream(data);
|
||||
if (info == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return new PIC(info, data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// <summary>
|
||||
/// Create a PlayJ audio file from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the archive</param>
|
||||
/// <param name="data">Byte array representing the audio file</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A PlayJ audio file wrapper on success, null on failure</returns>
|
||||
public static PlayJAudioFile? Create(byte[]? data, int offset)
|
||||
@@ -51,7 +51,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// <summary>
|
||||
/// Create a PlayJ audio file from a Stream
|
||||
/// </summary>
|
||||
/// <param name="data">Stream representing the archive</param>
|
||||
/// <param name="data">Stream representing the audio file</param>
|
||||
/// <returns>A PlayJ audio file wrapper on success, null on failure</returns>
|
||||
public static PlayJAudioFile? Create(Stream? data)
|
||||
{
|
||||
|
||||
78
SabreTools.Serialization/Wrappers/PlayJPlaylist.cs
Normal file
78
SabreTools.Serialization/Wrappers/PlayJPlaylist.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System.IO;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
public class PlayJPlaylist : WrapperBase<Models.PlayJ.Playlist>
|
||||
{
|
||||
#region Descriptive Properties
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string DescriptionString => "PlayJ Playlist";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PlayJPlaylist(Models.PlayJ.Playlist? model, byte[]? data, int offset)
|
||||
: base(model, data, offset)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PlayJPlaylist(Models.PlayJ.Playlist? model, Stream? data)
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PlayJ playlist from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the playlist</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A PlayJ playlist wrapper on success, null on failure</returns>
|
||||
public static PlayJPlaylist? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PlayJ playlist from a Stream
|
||||
/// </summary>
|
||||
/// <param name="data">Stream representing the playlist</param>
|
||||
/// <returns>A PlayJ playlist wrapper on success, null on failure</returns>
|
||||
public static PlayJPlaylist? Create(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
return null;
|
||||
|
||||
var playlist = Deserializers.PlayJPlaylist.DeserializeStream(data);
|
||||
if (playlist == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return new PlayJPlaylist(playlist, data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
|
||||
@@ -3,12 +3,12 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
public abstract class WrapperBase<T> : IWrapper
|
||||
public abstract class WrapperBase<T> : IWrapper<T>
|
||||
{
|
||||
#region Descriptive Properties
|
||||
|
||||
@@ -24,6 +24,9 @@ namespace SabreTools.Serialization.Wrappers
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <inheritdoc/>
|
||||
public T GetModel() => Model;
|
||||
|
||||
/// <summary>
|
||||
/// Internal model
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user