mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-22 14:55:11 +00:00
Move major version helper out of deserializer
This commit is contained in:
@@ -36,7 +36,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#endregion
|
||||
|
||||
// Get the major version
|
||||
int majorVersion = GetMajorVersion(commonHeader);
|
||||
int majorVersion = commonHeader.GetMajorVersion();
|
||||
|
||||
#region Volume Header
|
||||
|
||||
@@ -725,30 +725,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Get the major version of the cabinet
|
||||
/// </summary>
|
||||
/// <remarks>This should live in the wrapper but is needed during parsing</remarks>
|
||||
public static int GetMajorVersion(CommonHeader commonHeader)
|
||||
{
|
||||
uint majorVersion = commonHeader.Version;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
47
SabreTools.Serialization/Extensions.InstallShieldCabinet.cs
Normal file
47
SabreTools.Serialization/Extensions.InstallShieldCabinet.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using SabreTools.Models.InstallShieldCabinet;
|
||||
|
||||
namespace SabreTools.Serialization
|
||||
{
|
||||
public static partial class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the major version of an InstallShield Cabinet
|
||||
/// </summary>
|
||||
/// <param name="cabinet">Cabinet to derive the version from</param>
|
||||
/// <returns>Major version of the cabinet, -1 on error</returns>
|
||||
public static int GetMajorVersion(this Cabinet? cabinet)
|
||||
{
|
||||
// Ignore invalid cabinets
|
||||
if (cabinet == null)
|
||||
return -1;
|
||||
|
||||
return cabinet.CommonHeader.GetMajorVersion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the major version of an InstallShield Cabinet
|
||||
/// </summary>
|
||||
/// <param name="commonHeader">CommonHeader to derive the version from</param>
|
||||
/// <returns>Major version of the cabinet, -1 on error</returns>
|
||||
public static int GetMajorVersion(this CommonHeader? commonHeader)
|
||||
{
|
||||
// Ignore invalid headers
|
||||
if (commonHeader == null)
|
||||
return -1;
|
||||
|
||||
uint majorVersion = commonHeader.Version;
|
||||
if (majorVersion >> 24 == 1)
|
||||
{
|
||||
majorVersion = (majorVersion >> 12) & 0x0F;
|
||||
}
|
||||
else if (majorVersion >> 24 == 2 || majorVersion >> 24 == 4)
|
||||
{
|
||||
majorVersion &= 0xFFFF;
|
||||
if (majorVersion != 0)
|
||||
majorVersion /= 100;
|
||||
}
|
||||
|
||||
return (int)majorVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,25 +64,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// <summary>
|
||||
/// The major version of the cabinet
|
||||
/// </summary>
|
||||
public int MajorVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
uint majorVersion = 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;
|
||||
}
|
||||
}
|
||||
public int MajorVersion => Model.CommonHeader.GetMajorVersion();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user