Files
Matt Nadareski 7689c6dd07 Libraries
This change looks dramatic, but it's just separating out the already-split namespaces into separate top-level folders. In theory, every single one could be built into their own Nuget package. `SabreTools.Serialization` still builds the normal Nuget package that is used by all other projects and includes all namespaces.
2026-03-21 16:26:56 -04:00

141 lines
4.6 KiB
C#

using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
using SabreTools.Data.Models.VDF;
namespace SabreTools.Wrappers
{
public partial class SkuSis : WrapperBase<Data.Models.VDF.SkuSis>
{
#region Descriptive Properties
/// <inheritdoc/>
public override string DescriptionString => "Valve Data File";
#endregion
#region Extension Properties
/// <inheritdoc cref="Models.VDF.SkuSis.Sku"/>
public Sku? Sku => Model.Sku;
/// <inheritdoc cref="Models.VDF.Sku.Name"/>
public string? Name => Sku?.Name;
/// <inheritdoc cref="Models.VDF.Sku.ProductName"/>
public string? ProductName => Sku?.ProductName;
/// <inheritdoc cref="Models.VDF.Sku.SubscriptionId"/>
public long? SubscriptionId => Sku?.SubscriptionId;
/// <inheritdoc cref="Models.VDF.Sku.AppId"/>
public long? AppId => Sku?.AppId;
/// <inheritdoc cref="Models.VDF.Sku.Disks"/>
public uint? Disks => Sku?.Disks;
/// <inheritdoc cref="Models.VDF.Sku.Language"/>
public string? Language => Sku?.Language;
/// <inheritdoc cref="Models.VDF.Sku.Disk"/>
public uint? Disk => Sku?.Disk;
/// <inheritdoc cref="Models.VDF.Sku.Backup"/>
public uint? Backup => Sku?.Backup;
/// <inheritdoc cref="Models.VDF.Sku.contenttype"/>
public uint? ContentType => Sku?.ContentType;
/// <inheritdoc cref="Models.VDF.Sku.Apps"/>
public Dictionary<long, long>? Apps => Sku?.Apps;
/// <inheritdoc cref="Models.VDF.Sku.Depots"/>
public Dictionary<long, long>? Depots => Sku?.Depots;
/// <inheritdoc cref="Models.VDF.Sku.Manifests"/>
public Dictionary<long, long>? Manifests => Sku?.Manifests;
/// <inheritdoc cref="Models.VDF.Sku.Chunkstores"/>
public Dictionary<long, Dictionary<long, long>?>? Chunkstores => Sku?.Chunkstores;
/// <inheritdoc cref="Models.VDF.Sku.EverythingElse"/>
public IDictionary<string, JToken>? EverythingElse => Sku?.EverythingElse;
#endregion
#region Constructors
public SkuSis(Data.Models.VDF.SkuSis model, byte[] data) : base(model, data) { }
/// <inheritdoc/>
public SkuSis(Data.Models.VDF.SkuSis model, byte[] data, int offset) : base(model, data, offset) { }
/// <inheritdoc/>
public SkuSis(Data.Models.VDF.SkuSis model, byte[] data, int offset, int length) : base(model, data, offset, length) { }
/// <inheritdoc/>
public SkuSis(Data.Models.VDF.SkuSis model, Stream data) : base(model, data) { }
/// <inheritdoc/>
public SkuSis(Data.Models.VDF.SkuSis model, Stream data, long offset) : base(model, data, offset) { }
/// <inheritdoc/>
public SkuSis(Data.Models.VDF.SkuSis model, Stream data, long offset, long length) : base(model, data, offset, length) { }
#endregion
#region Static Constructors
/// <summary>
/// Create an SKU sis from a byte array and offset
/// </summary>
/// <param name="data">Byte array representing the SKU sis</param>
/// <param name="offset">Offset within the array to parse</param>
/// <returns>An SKU sis wrapper on success, null on failure</returns>
public static SkuSis? 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);
}
/// <summary>
/// Create an SKU sis from a Stream
/// </summary>
/// <param name="data">Stream representing the SKU sis</param>
/// <returns>An SKU sis wrapper on success, null on failure</returns>
public static SkuSis? 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.SkuSis().Deserialize(data);
if (model is null)
return null;
return new SkuSis(model, data, currentOffset);
}
catch
{
return null;
}
}
#endregion
}
}