mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-22 14:55:11 +00:00
Add PIC wrapper
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
// 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>
|
||||
/// 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
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
// 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>
|
||||
/// 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
|
||||
@@ -50,10 +50,10 @@ namespace SabreTools.Serialization.Wrappers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a Microsoft Cabinet from a Stream
|
||||
/// Create a MoPaQ archive from a Stream
|
||||
/// </summary>
|
||||
/// <param name="data">Stream representing the cabinet</param>
|
||||
/// <returns>A cabinet wrapper on success, null on failure</returns>
|
||||
/// <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
|
||||
|
||||
@@ -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 archive = Deserializers.PIC.DeserializeStream(data);
|
||||
if (archive == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return new PIC(archive, data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user