From 342f78ffd075eaac88c2223091dd1095056b7272 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 9 Jan 2023 22:23:12 -0800 Subject: [PATCH] Add extension properties for sector sizes --- BurnOutSharp.Wrappers/CFB.cs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/BurnOutSharp.Wrappers/CFB.cs b/BurnOutSharp.Wrappers/CFB.cs index fd61e632..15a483f1 100644 --- a/BurnOutSharp.Wrappers/CFB.cs +++ b/BurnOutSharp.Wrappers/CFB.cs @@ -96,6 +96,20 @@ namespace BurnOutSharp.Wrappers #endregion + #region Extension Properties + + /// + /// Normal sector size in bytes + /// + public long SectorSize => (long)Math.Pow(2, SectorShift); + + /// + /// Mini sector size in bytes + /// + public long MiniSectorSize => (long)Math.Pow(2, MiniSectorShift); + + #endregion + #region Instance Variables /// @@ -215,8 +229,7 @@ namespace BurnOutSharp.Wrappers return null; // Try to read the sector data - int sectorDataLength = (int)Math.Pow(2, SectorShift); - var sectorData = ReadFromDataSource(sectorDataOffset, sectorDataLength); + var sectorData = ReadFromDataSource(sectorDataOffset, (int)SectorSize); if (sectorData == null) return null; @@ -239,7 +252,7 @@ namespace BurnOutSharp.Wrappers return -1; // Convert based on the sector shift value - return (long)((long)(sector + 1) * Math.Pow(2, SectorShift)); + return (long)(sector + 1) * SectorSize; } #endregion @@ -300,8 +313,7 @@ namespace BurnOutSharp.Wrappers return null; // Try to read the sector data - int sectorDataLength = (int)Math.Pow(2, MiniSectorShift); - var sectorData = ReadFromDataSource(sectorDataOffset, sectorDataLength); + var sectorData = ReadFromDataSource(sectorDataOffset, (int)MiniSectorSize); if (sectorData == null) return null; @@ -324,7 +336,7 @@ namespace BurnOutSharp.Wrappers return -1; // Convert based on the sector shift value - return (long)((long)(sector + 1) * Math.Pow(2, MiniSectorShift)); + return (long)(sector + 1) * MiniSectorSize; } #endregion