mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools] First attempt to handle postfixed sizes
This commit is contained in:
@@ -120,6 +120,77 @@ ORDER BY system.manufacturer, system.name";
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the multiplier to be used with the size given
|
||||
/// </summary>
|
||||
/// <param name="sizestring">String with possible size with extension</param>
|
||||
/// <returns>Tuple of multiplier to use on final size and fixed size string</returns>
|
||||
private static long GetSizeFromString(string sizestring)
|
||||
{
|
||||
long size = 0;
|
||||
|
||||
// Make sure the string is in lower case
|
||||
sizestring = sizestring.ToLowerInvariant();
|
||||
|
||||
// Get any trailing size identifiers
|
||||
long multiplier = 1;
|
||||
if (sizestring.EndsWith("kb"))
|
||||
{
|
||||
multiplier = Constants.KiloByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("kib"))
|
||||
{
|
||||
multiplier = Constants.KibiByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("mb"))
|
||||
{
|
||||
multiplier = Constants.MegaByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("mib"))
|
||||
{
|
||||
multiplier = Constants.MibiByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("gb"))
|
||||
{
|
||||
multiplier = Constants.GigaByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("gib"))
|
||||
{
|
||||
multiplier = Constants.GibiByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("tb"))
|
||||
{
|
||||
multiplier = Constants.TeraByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("tib"))
|
||||
{
|
||||
multiplier = Constants.TibiByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("pb"))
|
||||
{
|
||||
multiplier = Constants.PetaByte;
|
||||
}
|
||||
else if (sizestring.EndsWith("pib"))
|
||||
{
|
||||
multiplier = Constants.PibiByte;
|
||||
}
|
||||
|
||||
// Remove any trailing identifiers
|
||||
sizestring = sizestring.TrimEnd(new char[] { 'k', 'm', 'g', 't', 'p', 'i', 'b' });
|
||||
|
||||
// Now try to get the size from the string
|
||||
if (!Int64.TryParse(sizestring, out size))
|
||||
{
|
||||
size = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
size *= multiplier;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,17 +519,11 @@ namespace SabreTools
|
||||
}
|
||||
else if (temparg.StartsWith("-seq=") || temparg.StartsWith("--equal="))
|
||||
{
|
||||
if (!Int64.TryParse(temparg.Split('=')[1], out seq))
|
||||
{
|
||||
seq = -1;
|
||||
}
|
||||
seq = GetSizeFromString(temparg.Split('=')[1]);
|
||||
}
|
||||
else if (temparg.StartsWith("-sgt=") || temparg.StartsWith("--greater="))
|
||||
{
|
||||
if (!Int64.TryParse(temparg.Split('=')[1], out sgt))
|
||||
{
|
||||
sgt = -1;
|
||||
}
|
||||
sgt = GetSizeFromString(temparg.Split('=')[1]);
|
||||
}
|
||||
else if (temparg.StartsWith("-sha1=") || temparg.StartsWith("--sha1="))
|
||||
{
|
||||
@@ -537,10 +531,7 @@ namespace SabreTools
|
||||
}
|
||||
else if (temparg.StartsWith("-slt=") || temparg.StartsWith("--less="))
|
||||
{
|
||||
if (!Int64.TryParse(temparg.Split('=')[1], out slt))
|
||||
{
|
||||
slt = -1;
|
||||
}
|
||||
slt = GetSizeFromString(temparg.Split('=')[1]);
|
||||
}
|
||||
else if (temparg.StartsWith("-source=") && sources == "")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user