mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-11-15 17:00:38 +00:00
Port some extensions from BOS
This omits anything that relies on caching, at the moment. There is no easy way of creating a cache for the required pieces in the static context of the extensions.
This commit is contained in:
36
Extensions.CFB.cs
Normal file
36
Extensions.CFB.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using SabreTools.Models.CFB;
|
||||
|
||||
namespace SabreTools.Serialization
|
||||
{
|
||||
public static partial class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sector size in bytes
|
||||
/// </summary>
|
||||
/// <param name="binary">Binary model to derive from</param>
|
||||
/// <returns>Sector size on success, -1 on error</returns>
|
||||
public static long SectorSize(this Binary binary)
|
||||
{
|
||||
// If we have an invalid header
|
||||
if (binary.Header?.SectorShift == null)
|
||||
return -1;
|
||||
|
||||
return (long)Math.Pow(2, binary.Header.SectorShift);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mini sector size in bytes
|
||||
/// </summary>
|
||||
/// <param name="binary">Binary model to derive from</param>
|
||||
/// <returns>Sector size on success, -1 on error</returns>
|
||||
public static long MiniSectorSize(this Binary binary)
|
||||
{
|
||||
// If we have an invalid header
|
||||
if (binary.Header?.SectorShift == null)
|
||||
return -1;
|
||||
|
||||
return (long)Math.Pow(2, binary.Header.MiniSectorShift);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Extensions.InstallShieldCabinet.cs
Normal file
33
Extensions.InstallShieldCabinet.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using SabreTools.Models.InstallShieldCabinet;
|
||||
|
||||
namespace SabreTools.Serialization
|
||||
{
|
||||
public static partial class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The major version of the cabinet
|
||||
/// </summary>
|
||||
/// <param name="cabinet">Cabinet model to derive from</param>
|
||||
/// <returns>Major version on success, -1 on error</returns>
|
||||
public static int MajorVersion(this Cabinet cabinet)
|
||||
{
|
||||
// If we have an invalid header
|
||||
if (cabinet.CommonHeader?.Version == null)
|
||||
return -1;
|
||||
|
||||
uint majorVersion = cabinet.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user