[Constants] Add constants for byte-sizes

This commit is contained in:
Matt Nadareski
2016-06-01 11:33:08 -07:00
parent 12584e5cc3
commit c640e03109
2 changed files with 20 additions and 4 deletions

View File

@@ -492,9 +492,9 @@ namespace SabreTools
long extractedsize = Convert.ToInt64(gzsize, 16);
// Only try to add if the file size is greater than 2.5 GiB
if (filesize >= (2.5 * 1024 * 1024 * 1024))
if (filesize >= (2.5 * Constants.GibiByte))
{
// ISIZE is mod 2^32, so we add that if the ISIZE is smaller than the filesize and header
// ISIZE is mod 4GiB, so we add that if the ISIZE is smaller than the filesize and header
if (extractedsize < (filesize - neededHeaderSize))
{
_logger.Log("Filename: '" + Path.GetFullPath(item) + "'\nExtracted file size: " +
@@ -502,7 +502,7 @@ namespace SabreTools
}
while (extractedsize < (filesize - neededHeaderSize))
{
extractedsize += (long)Math.Pow(2, 32);
extractedsize += (4 * Constants.GibiByte);
}
_logger.Log("Final file size: " + extractedsize + "\nExtracted CRC: " + gzcrc +
"\nExtracted MD5: " + gzmd5 + "\nSHA-1: " + Path.GetFileNameWithoutExtension(item));

View File

@@ -1,4 +1,6 @@
namespace SabreTools.Helper
using System;
namespace SabreTools.Helper
{
public class Constants
{
@@ -47,5 +49,19 @@
public static string HeaderPatternCMP = @"(^.*?) \($";
public static string ItemPatternCMP = @"^\s*(\S*?) (.*)";
public static string EndPatternCMP = @"^\s*\)\s*$";
// Byte (1024-based) size comparisons
public static long KibiByte = 1024;
public static long MibiByte = (long)Math.Pow(KibiByte, 2);
public static long GibiByte = (long)Math.Pow(KibiByte, 3);
public static long TibiByte = (long)Math.Pow(KibiByte, 4);
public static long PibiByte = (long)Math.Pow(KibiByte, 5);
// Byte (1000-based) size comparisons
public static long KiloByte = 1000;
public static long MegaByte = (long)Math.Pow(KiloByte, 2);
public static long GigaByte = (long)Math.Pow(KiloByte, 2);
public static long TeraByte = (long)Math.Pow(KiloByte, 2);
public static long PetaByte = (long)Math.Pow(KiloByte, 2);
}
}