using System.IO; namespace SabreTools.Serialization.Wrappers { public class XZP : WrapperBase { #region Descriptive Properties /// public override string DescriptionString => "Xbox Package File (XZP)"; #endregion #region Constructors /// public XZP(Models.XZP.File? model, byte[]? data, int offset) : base(model, data, offset) { // All logic is handled by the base class } /// public XZP(Models.XZP.File? model, Stream? data) : base(model, data) { // All logic is handled by the base class } /// /// Create a XZP from a byte array and offset /// /// Byte array representing the XZP /// Offset within the array to parse /// A XZP wrapper on success, null on failure public static XZP? 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 MemoryStream dataStream = new MemoryStream(data, offset, data.Length - offset); return Create(dataStream); } /// /// Create a XZP from a Stream /// /// Stream representing the XZP /// A XZP wrapper on success, null on failure public static XZP? Create(Stream? data) { // If the data is invalid if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead) return null; var file = new Streams.XZP().Deserialize(data); if (file == null) return null; try { return new XZP(file, data); } catch { return null; } } #endregion } }