using System.Collections.Generic; using System.IO; using SabreTools.Data.Models.XDVDFS; namespace SabreTools.Wrappers { public partial class XDVDFS : WrapperBase { #region Descriptive Properties /// public override string DescriptionString => "Xbox DVD Filesystem"; #endregion #region Extension Properties /// public byte[] ReservedArea => Model.ReservedArea; /// public VolumeDescriptor VolumeDescriptor => Model.VolumeDescriptor; /// public LayoutDescriptor? LayoutDescriptor => Model.LayoutDescriptor; /// public Dictionary DirectoryDescriptors => Model.DirectoryDescriptors; #endregion #region Constructors /// public XDVDFS(Volume model, byte[] data) : base(model, data) { } /// public XDVDFS(Volume model, byte[] data, int offset) : base(model, data, offset) { } /// public XDVDFS(Volume model, byte[] data, int offset, int length) : base(model, data, offset, length) { } /// public XDVDFS(Volume model, Stream data) : base(model, data) { } /// public XDVDFS(Volume model, Stream data, long offset) : base(model, data, offset) { } /// public XDVDFS(Volume model, Stream data, long offset, long length) : base(model, data, offset, length) { } #endregion #region Static Constructors /// /// Create an XDVDFS Volume from a byte array and offset /// /// Byte array representing the XDVDFS Volume /// Offset within the array to parse /// An XDVDFS Volume wrapper on success, null on failure public static XDVDFS? Create(byte[]? data, int offset) { // If the data is invalid if (data is null || data.Length == 0) 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); } /// /// Create an XDVDFS Volume from a Stream /// /// Stream representing the XDVDFS Volume /// An XDVDFS Volume wrapper on success, null on failure public static XDVDFS? Create(Stream? data) { // If the data is invalid if (data is null || !data.CanRead) return null; try { // Cache the current offset long currentOffset = data.Position; var model = new Serialization.Readers.XDVDFS().Deserialize(data); if (model is null) return null; return new XDVDFS(model, data, currentOffset); } catch { return null; } } #endregion } }