mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-29 01:50:13 +00:00
106 lines
3.2 KiB
C#
106 lines
3.2 KiB
C#
using System.IO;
|
|
|
|
namespace SabreTools.Serialization.Wrappers
|
|
{
|
|
public partial class InstallShieldCabinet : WrapperBase<Models.InstallShieldCabinet.Cabinet>
|
|
{
|
|
#region Descriptive Properties
|
|
|
|
/// <inheritdoc/>
|
|
public override string DescriptionString => "InstallShield Cabinet";
|
|
|
|
#endregion
|
|
|
|
#region Extension Properties
|
|
|
|
/// <summary>
|
|
/// The major version of the cabinet
|
|
/// </summary>
|
|
public int MajorVersion
|
|
{
|
|
get
|
|
{
|
|
uint majorVersion = this.Model.CommonHeader?.Version ?? 0;
|
|
if (majorVersion >> 24 == 1)
|
|
{
|
|
majorVersion = (majorVersion >> 12) & 0x0F;
|
|
}
|
|
else if (majorVersion >> 24 == 2 || majorVersion >> 24 == 4)
|
|
{
|
|
majorVersion = majorVersion & 0xFFFF;
|
|
if (majorVersion != 0)
|
|
majorVersion /= 100;
|
|
}
|
|
|
|
return (int)majorVersion;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
/// <inheritdoc/>
|
|
public InstallShieldCabinet(Models.InstallShieldCabinet.Cabinet? model, byte[]? data, int offset)
|
|
: base(model, data, offset)
|
|
{
|
|
// All logic is handled by the base class
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public InstallShieldCabinet(Models.InstallShieldCabinet.Cabinet? model, Stream? data)
|
|
: base(model, data)
|
|
{
|
|
// All logic is handled by the base class
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create an InstallShield 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 InstallShieldCabinet? 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a InstallShield 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 InstallShieldCabinet? Create(Stream? data)
|
|
{
|
|
// If the data is invalid
|
|
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
|
return null;
|
|
|
|
var cabinet = new Streams.InstallShieldCabinet().Deserialize(data);
|
|
if (cabinet == null)
|
|
return null;
|
|
|
|
try
|
|
{
|
|
return new InstallShieldCabinet(cabinet, data);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|