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