Add MoPaQ wrapper

This commit is contained in:
Matt Nadareski
2024-04-04 14:06:59 -04:00
parent 4b4c17ac24
commit 0696bbab72
2 changed files with 82 additions and 1 deletions

View File

@@ -26,7 +26,9 @@ namespace SabreTools.Serialization.Wrappers
: base(model, data)
{
// All logic is handled by the base class
}/// <summary>
}
/// <summary>
/// Create a Microsoft Cabinet from a byte array and offset
/// </summary>
/// <param name="data">Byte array representing the cabinet</param>

View 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 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 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 Microsoft Cabinet from a Stream
/// </summary>
/// <param name="data">Stream representing the cabinet</param>
/// <returns>A cabinet 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 cabinet = Deserializers.MoPaQ.DeserializeStream(data);
if (cabinet == null)
return null;
try
{
return new MoPaQ(cabinet, data);
}
catch
{
return null;
}
}
#endregion
}
}