diff --git a/SabreTools.Core/Tools/NumberHelper.cs b/SabreTools.Core/Tools/NumberHelper.cs
new file mode 100644
index 00000000..55e1a543
--- /dev/null
+++ b/SabreTools.Core/Tools/NumberHelper.cs
@@ -0,0 +1,123 @@
+using System;
+
+namespace SabreTools.Core.Tools
+{
+ public static class NumberHelper
+ {
+ #region Constants
+
+ #region Byte (1000-based) size comparisons
+
+ private const long KiloByte = 1000;
+ private readonly static long MegaByte = (long)Math.Pow(KiloByte, 2);
+ private readonly static long GigaByte = (long)Math.Pow(KiloByte, 3);
+ private readonly static long TeraByte = (long)Math.Pow(KiloByte, 4);
+ private readonly static long PetaByte = (long)Math.Pow(KiloByte, 5);
+ private readonly static long ExaByte = (long)Math.Pow(KiloByte, 6);
+ private readonly static long ZettaByte = (long)Math.Pow(KiloByte, 7);
+ private readonly static long YottaByte = (long)Math.Pow(KiloByte, 8);
+
+ #endregion
+
+ #region Byte (1024-based) size comparisons
+
+ private const long KibiByte = 1024;
+ private readonly static long MibiByte = (long)Math.Pow(KibiByte, 2);
+ private readonly static long GibiByte = (long)Math.Pow(KibiByte, 3);
+ private readonly static long TibiByte = (long)Math.Pow(KibiByte, 4);
+ private readonly static long PibiByte = (long)Math.Pow(KibiByte, 5);
+ private readonly static long ExiByte = (long)Math.Pow(KibiByte, 6);
+ private readonly static long ZittiByte = (long)Math.Pow(KibiByte, 7);
+ private readonly static long YittiByte = (long)Math.Pow(KibiByte, 8);
+
+ #endregion
+
+ #endregion
+
+ ///
+ /// Convert a string to an Int64
+ ///
+ public static double? ConvertToDouble(string? numeric)
+ {
+ // If we don't have a valid string, we can't do anything
+ if (string.IsNullOrWhiteSpace(numeric))
+ return null;
+
+ if (!double.TryParse(numeric, out double doubleValue))
+ return null;
+
+ return doubleValue;
+ }
+
+ ///
+ /// Convert a string to an Int64
+ ///
+ public static long? ConvertToInt64(string? numeric)
+ {
+ // If we don't have a valid string, we can't do anything
+ if (string.IsNullOrWhiteSpace(numeric))
+ return null;
+
+ // Normalize the string for easier comparison
+ numeric = numeric.ToLowerInvariant();
+
+ // Get the multiplication modifier and trim characters
+ long multiplier = DetermineMultiplier(numeric);
+ numeric = numeric.TrimEnd(new char[] { 'k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ' });
+
+ // Parse the numeric string, if possible
+ long value;
+ if (numeric.StartsWith("0x"))
+ value = Convert.ToInt64(numeric, 16);
+ else if (long.TryParse(numeric, out long longValue))
+ value = longValue;
+ else
+ return null;
+
+ // Apply the multiplier and return
+ return value * multiplier;
+ }
+
+ ///
+ /// Determine the multiplier from a numeric string
+ ///
+ private static long DetermineMultiplier(string numeric)
+ {
+ long multiplier = 1;
+ if (numeric.EndsWith("k") || numeric.EndsWith("kb"))
+ multiplier = KiloByte;
+ else if (numeric.EndsWith("ki") || numeric.EndsWith("kib"))
+ multiplier = KibiByte;
+ else if (numeric.EndsWith("m") || numeric.EndsWith("mb"))
+ multiplier = MegaByte;
+ else if (numeric.EndsWith("mi") || numeric.EndsWith("mib"))
+ multiplier = MibiByte;
+ else if (numeric.EndsWith("g") || numeric.EndsWith("gb"))
+ multiplier = GigaByte;
+ else if (numeric.EndsWith("gi") || numeric.EndsWith("gib"))
+ multiplier = GibiByte;
+ else if (numeric.EndsWith("t") || numeric.EndsWith("tb"))
+ multiplier = TeraByte;
+ else if (numeric.EndsWith("ti") || numeric.EndsWith("tib"))
+ multiplier = TibiByte;
+ else if (numeric.EndsWith("p") || numeric.EndsWith("pb"))
+ multiplier = PetaByte;
+ else if (numeric.EndsWith("pi") || numeric.EndsWith("pib"))
+ multiplier = PibiByte;
+ else if (numeric.EndsWith("e") || numeric.EndsWith("eb"))
+ multiplier = ExaByte;
+ else if (numeric.EndsWith("ei") || numeric.EndsWith("eib"))
+ multiplier = ExiByte;
+ else if (numeric.EndsWith("z") || numeric.EndsWith("zb"))
+ multiplier = ZettaByte;
+ else if (numeric.EndsWith("zi") || numeric.EndsWith("zib"))
+ multiplier = ZittiByte;
+ else if (numeric.EndsWith("y") || numeric.EndsWith("yb"))
+ multiplier = YottaByte;
+ else if (numeric.EndsWith("yi") || numeric.EndsWith("yib"))
+ multiplier = YittiByte;
+
+ return multiplier;
+ }
+ }
+}
\ No newline at end of file
diff --git a/SabreTools.Core/Tools/Utilities.cs b/SabreTools.Core/Tools/Utilities.cs
index 5bb90f87..95d30c10 100644
--- a/SabreTools.Core/Tools/Utilities.cs
+++ b/SabreTools.Core/Tools/Utilities.cs
@@ -62,43 +62,6 @@ namespace SabreTools.Core.Tools
}
}
- ///
- /// Get a sanitized double from an input string
- ///
- /// String to get value from
- /// Value as a double?, if possible
- public static double? CleanDouble(string input)
- {
- double? value = null;
- if (input != null)
- {
- if (Double.TryParse(input, out double doubleValue))
- value = doubleValue;
- }
-
- return value;
- }
-
- ///
- /// Get a sanitized size from an input string
- ///
- /// String to get value from
- /// Size as a long?, if possible
- public static long? CleanLong(string input)
- {
- long? size = null;
- if (input != null && input.Contains("0x"))
- size = Convert.ToInt64(input, 16);
-
- else if (input != null)
- {
- if (Int64.TryParse(input, out long longSize))
- size = longSize;
- }
-
- return size;
- }
-
///
/// Convert .NET DateTime to MS-DOS date format
///
diff --git a/SabreTools.DatFiles/Formats/ArchiveDotOrg.Reader.cs b/SabreTools.DatFiles/Formats/ArchiveDotOrg.Reader.cs
index fb8d6e98..68e3038e 100644
--- a/SabreTools.DatFiles/Formats/ArchiveDotOrg.Reader.cs
+++ b/SabreTools.DatFiles/Formats/ArchiveDotOrg.Reader.cs
@@ -107,7 +107,7 @@ namespace SabreTools.DatFiles.Formats
ArchiveDotOrgSource = file.Source,
//BitTorrentMagnetHash = file.BitTorrentMagnetHash, // TODO: Add to internal model
Date = file.LastModifiedTime?.ToString(),
- Size = Utilities.CleanLong(file.Size),
+ Size = NumberHelper.ConvertToInt64(file.Size),
MD5 = file.MD5,
CRC = file.CRC32,
SHA1 = file.SHA1,
diff --git a/SabreTools.DatFiles/Formats/ClrMamePro.Reader.cs b/SabreTools.DatFiles/Formats/ClrMamePro.Reader.cs
index e370595d..ae24b3d0 100644
--- a/SabreTools.DatFiles/Formats/ClrMamePro.Reader.cs
+++ b/SabreTools.DatFiles/Formats/ClrMamePro.Reader.cs
@@ -247,7 +247,7 @@ namespace SabreTools.DatFiles.Formats
var item = new Rom
{
Name = rom.Name,
- Size = Utilities.CleanLong(rom.Size),
+ Size = NumberHelper.ConvertToInt64(rom.Size),
CRC = rom.CRC,
MD5 = rom.MD5,
SHA1 = rom.SHA1,
@@ -414,7 +414,7 @@ namespace SabreTools.DatFiles.Formats
ChipType = chip.Type?.AsChipType() ?? ChipType.NULL,
Name = chip.Name,
//Flags = chip.Flags, // TODO: Add to internal model
- Clock = Utilities.CleanLong(chip.Clock),
+ Clock = NumberHelper.ConvertToInt64(chip.Clock),
Source = new Source
{
@@ -449,11 +449,11 @@ namespace SabreTools.DatFiles.Formats
var item = new Display
{
DisplayType = video.Screen?.AsDisplayType() ?? DisplayType.NULL,
- Width = Utilities.CleanLong(video.X),
- Height = Utilities.CleanLong(video.Y),
+ Width = NumberHelper.ConvertToInt64(video.X),
+ Height = NumberHelper.ConvertToInt64(video.Y),
//AspectX = video.AspectX, // TODO: Add to internal model or find mapping
//AspectY = video.AspectY, // TODO: Add to internal model or find mapping
- Refresh = Utilities.CleanDouble(video.Freq),
+ Refresh = NumberHelper.ConvertToDouble(video.Freq),
Source = new Source
{
@@ -495,7 +495,7 @@ namespace SabreTools.DatFiles.Formats
containsItems = true;
var item = new Sound
{
- Channels = Utilities.CleanLong(sound.Channels),
+ Channels = NumberHelper.ConvertToInt64(sound.Channels),
Source = new Source
{
@@ -526,16 +526,16 @@ namespace SabreTools.DatFiles.Formats
containsItems = true;
var item = new Input
{
- Players = Utilities.CleanLong(input.Players),
+ Players = NumberHelper.ConvertToInt64(input.Players),
//Control = input.Control, // TODO: Add to internal model or find mapping
Controls = new List
{
new Control
{
- Buttons = Utilities.CleanLong(input.Buttons),
+ Buttons = NumberHelper.ConvertToInt64(input.Buttons),
},
},
- Coins = Utilities.CleanLong(input.Coins),
+ Coins = NumberHelper.ConvertToInt64(input.Coins),
Tilt = input.Tilt?.AsYesNo(),
Service = input.Service?.AsYesNo(),
diff --git a/SabreTools.DatFiles/Formats/DosCenter.Reader.cs b/SabreTools.DatFiles/Formats/DosCenter.Reader.cs
index 041c2e6e..6b8e5071 100644
--- a/SabreTools.DatFiles/Formats/DosCenter.Reader.cs
+++ b/SabreTools.DatFiles/Formats/DosCenter.Reader.cs
@@ -142,7 +142,7 @@ namespace SabreTools.DatFiles.Formats
var item = new Rom
{
Name = rom.Name,
- Size = Utilities.CleanLong(rom.Size),
+ Size = NumberHelper.ConvertToInt64(rom.Size),
CRC = rom.CRC,
Date = rom.Date,
diff --git a/SabreTools.DatFiles/Formats/EverdriveSMDB.Reader.cs b/SabreTools.DatFiles/Formats/EverdriveSMDB.Reader.cs
index 3b702002..9176c057 100644
--- a/SabreTools.DatFiles/Formats/EverdriveSMDB.Reader.cs
+++ b/SabreTools.DatFiles/Formats/EverdriveSMDB.Reader.cs
@@ -101,7 +101,7 @@ namespace SabreTools.DatFiles.Formats
var rom = new Rom()
{
Name = name,
- Size = Utilities.CleanLong(row.Size),
+ Size = NumberHelper.ConvertToInt64(row.Size),
CRC = row.CRC32,
MD5 = row.MD5,
SHA1 = row.SHA1,
diff --git a/SabreTools.DatFiles/Formats/Listrom.Reader.cs b/SabreTools.DatFiles/Formats/Listrom.Reader.cs
index a442285f..328b3ada 100644
--- a/SabreTools.DatFiles/Formats/Listrom.Reader.cs
+++ b/SabreTools.DatFiles/Formats/Listrom.Reader.cs
@@ -144,7 +144,7 @@ namespace SabreTools.DatFiles.Formats
var rom = new Rom
{
Name = row.Name,
- Size = Utilities.CleanLong(row.Size),
+ Size = NumberHelper.ConvertToInt64(row.Size),
CRC = row.CRC,
SHA1 = row.SHA1,
ItemStatus = ItemStatus.None,
@@ -221,7 +221,7 @@ namespace SabreTools.DatFiles.Formats
var rom = new Rom
{
Name = row.Name,
- Size = Utilities.CleanLong(row.Size),
+ Size = NumberHelper.ConvertToInt64(row.Size),
CRC = row.CRC,
SHA1 = row.SHA1,
ItemStatus = ItemStatus.BadDump,
@@ -245,7 +245,7 @@ namespace SabreTools.DatFiles.Formats
var rom = new Rom
{
Name = row.Name,
- Size = Utilities.CleanLong(row.Size),
+ Size = NumberHelper.ConvertToInt64(row.Size),
CRC = null,
SHA1 = null,
ItemStatus = ItemStatus.Nodump,
diff --git a/SabreTools.DatFiles/Formats/Listxml.Reader.cs b/SabreTools.DatFiles/Formats/Listxml.Reader.cs
index d9885ecb..d86eac52 100644
--- a/SabreTools.DatFiles/Formats/Listxml.Reader.cs
+++ b/SabreTools.DatFiles/Formats/Listxml.Reader.cs
@@ -214,7 +214,7 @@ namespace SabreTools.DatFiles.Formats
{
Name = rom.Name,
Bios = rom.Bios,
- Size = Utilities.CleanLong(rom.Size),
+ Size = NumberHelper.ConvertToInt64(rom.Size),
CRC = rom.CRC,
SHA1 = rom.SHA1,
MergeTag = rom.Merge,
@@ -371,7 +371,7 @@ namespace SabreTools.DatFiles.Formats
Tag = chip.Tag,
ChipType = chip.Type.AsChipType(),
//SoundOnly = chip.SoundOnly, // TODO: Add to internal model
- Clock = Utilities.CleanLong(chip.Clock),
+ Clock = NumberHelper.ConvertToInt64(chip.Clock),
Source = new Source
{
@@ -407,18 +407,18 @@ namespace SabreTools.DatFiles.Formats
{
Tag = display.Tag,
DisplayType = display.Type.AsDisplayType(),
- Rotate = Utilities.CleanLong(display.Rotate),
+ Rotate = NumberHelper.ConvertToInt64(display.Rotate),
FlipX = display.FlipX.AsYesNo(),
- Width = Utilities.CleanLong(display.Width),
- Height = Utilities.CleanLong(display.Height),
- Refresh = Utilities.CleanDouble(display.Refresh),
- PixClock = Utilities.CleanLong(display.PixClock),
- HTotal = Utilities.CleanLong(display.HTotal),
- HBEnd = Utilities.CleanLong(display.HBEnd),
- HBStart = Utilities.CleanLong(display.HBStart),
- VTotal = Utilities.CleanLong(display.VTotal),
- VBEnd = Utilities.CleanLong(display.VBEnd),
- VBStart = Utilities.CleanLong(display.VBStart),
+ Width = NumberHelper.ConvertToInt64(display.Width),
+ Height = NumberHelper.ConvertToInt64(display.Height),
+ Refresh = NumberHelper.ConvertToDouble(display.Refresh),
+ PixClock = NumberHelper.ConvertToInt64(display.PixClock),
+ HTotal = NumberHelper.ConvertToInt64(display.HTotal),
+ HBEnd = NumberHelper.ConvertToInt64(display.HBEnd),
+ HBStart = NumberHelper.ConvertToInt64(display.HBStart),
+ VTotal = NumberHelper.ConvertToInt64(display.VTotal),
+ VBEnd = NumberHelper.ConvertToInt64(display.VBEnd),
+ VBStart = NumberHelper.ConvertToInt64(display.VBStart),
Source = new Source
{
@@ -453,11 +453,11 @@ namespace SabreTools.DatFiles.Formats
var item = new Display
{
DisplayType = video.Screen?.AsDisplayType() ?? DisplayType.NULL,
- Width = Utilities.CleanLong(video.Width),
- Height = Utilities.CleanLong(video.Height),
+ Width = NumberHelper.ConvertToInt64(video.Width),
+ Height = NumberHelper.ConvertToInt64(video.Height),
//AspectX = video.AspectX, // TODO: Add to internal model or find mapping
//AspectY = video.AspectY, // TODO: Add to internal model or find mapping
- Refresh = Utilities.CleanDouble(video.Refresh),
+ Refresh = NumberHelper.ConvertToDouble(video.Refresh),
Source = new Source
{
@@ -499,7 +499,7 @@ namespace SabreTools.DatFiles.Formats
containsItems = true;
var item = new Sound
{
- Channels = Utilities.CleanLong(sound.Channels),
+ Channels = NumberHelper.ConvertToInt64(sound.Channels),
Source = new Source
{
@@ -532,10 +532,10 @@ namespace SabreTools.DatFiles.Formats
{
Service = input.Service.AsYesNo(),
Tilt = input.Tilt.AsYesNo(),
- Players = Utilities.CleanLong(input.Players),
+ Players = NumberHelper.ConvertToInt64(input.Players),
//ControlAttr = input.ControlAttr, // TODO: Add to internal model
//Buttons = input.Buttons, // TODO: Add to internal model
- Coins = Utilities.CleanLong(input.Coins),
+ Coins = NumberHelper.ConvertToInt64(input.Coins),
Source = new Source
{
@@ -550,13 +550,13 @@ namespace SabreTools.DatFiles.Formats
var controlItem = new Control
{
ControlType = control.Type.AsControlType(),
- Player = Utilities.CleanLong(control.Player),
- Buttons = Utilities.CleanLong(control.Buttons),
- RequiredButtons = Utilities.CleanLong(control.ReqButtons),
- Minimum = Utilities.CleanLong(control.Minimum),
- Maximum = Utilities.CleanLong(control.Maximum),
- Sensitivity = Utilities.CleanLong(control.Sensitivity),
- KeyDelta = Utilities.CleanLong(control.KeyDelta),
+ Player = NumberHelper.ConvertToInt64(control.Player),
+ Buttons = NumberHelper.ConvertToInt64(control.Buttons),
+ RequiredButtons = NumberHelper.ConvertToInt64(control.ReqButtons),
+ Minimum = NumberHelper.ConvertToInt64(control.Minimum),
+ Maximum = NumberHelper.ConvertToInt64(control.Maximum),
+ Sensitivity = NumberHelper.ConvertToInt64(control.Sensitivity),
+ KeyDelta = NumberHelper.ConvertToInt64(control.KeyDelta),
Reverse = control.Reverse.AsYesNo(),
Ways = control.Ways,
Ways2 = control.Ways2,
@@ -621,7 +621,7 @@ namespace SabreTools.DatFiles.Formats
var locationItem = new Location
{
Name = diplocation.Name,
- Number = Utilities.CleanLong(diplocation.Number),
+ Number = NumberHelper.ConvertToInt64(diplocation.Number),
Inverted = diplocation.Inverted.AsYesNo(),
};
locations.Add(locationItem);
@@ -712,7 +712,7 @@ namespace SabreTools.DatFiles.Formats
var locationItem = new Location
{
Name = confLocation.Name,
- Number = Utilities.CleanLong(confLocation.Number),
+ Number = NumberHelper.ConvertToInt64(confLocation.Number),
Inverted = confLocation.Inverted.AsYesNo(),
};
locations.Add(locationItem);
@@ -869,7 +869,7 @@ namespace SabreTools.DatFiles.Formats
Status = driver.Status.AsSupportStatus(),
//Color = driver.Color.AsSupportStatus(), // TODO: Add to internal model
//Sound = driver.Sound.AsSupportStatus(), // TODO: Add to internal model
- //PaletteSize = Utilities.CleanLong(driver.PaletteSize), // TODO: Add to internal model
+ //PaletteSize = NumberHelper.ConvertToInt64(driver.PaletteSize), // TODO: Add to internal model
Emulation = driver.Emulation.AsSupportStatus(),
Cocktail = driver.Cocktail.AsSupportStatus(),
SaveState = driver.SaveState.AsSupported(),
@@ -948,7 +948,7 @@ namespace SabreTools.DatFiles.Formats
DeviceType = device.Type.AsDeviceType(),
Tag = device.Tag,
FixedImage = device.FixedImage,
- Mandatory = Utilities.CleanLong(device.Mandatory),
+ Mandatory = NumberHelper.ConvertToInt64(device.Mandatory),
Interface = device.Interface,
Source = new Source
diff --git a/SabreTools.DatFiles/Formats/Logiqx.Reader.cs b/SabreTools.DatFiles/Formats/Logiqx.Reader.cs
index 15782587..645ba6b6 100644
--- a/SabreTools.DatFiles/Formats/Logiqx.Reader.cs
+++ b/SabreTools.DatFiles/Formats/Logiqx.Reader.cs
@@ -388,7 +388,7 @@ namespace SabreTools.DatFiles.Formats
var item = new Rom
{
Name = rom.Name,
- Size = Utilities.CleanLong(rom.Size),
+ Size = NumberHelper.ConvertToInt64(rom.Size),
CRC = rom.CRC,
MD5 = rom.MD5,
SHA1 = rom.SHA1,
diff --git a/SabreTools.DatFiles/Formats/OfflineList.Reader.cs b/SabreTools.DatFiles/Formats/OfflineList.Reader.cs
index c793c8e9..efa34cdc 100644
--- a/SabreTools.DatFiles/Formats/OfflineList.Reader.cs
+++ b/SabreTools.DatFiles/Formats/OfflineList.Reader.cs
@@ -316,7 +316,7 @@ namespace SabreTools.DatFiles.Formats
Comment = game.Comment,
};
- long? size = Utilities.CleanLong(game.RomSize);
+ long? size = NumberHelper.ConvertToInt64(game.RomSize);
if (game.DuplicateID != "0")
machine.CloneOf = game.DuplicateID;
diff --git a/SabreTools.DatFiles/Formats/RomCenter.Reader.cs b/SabreTools.DatFiles/Formats/RomCenter.Reader.cs
index 0e566a00..0ba07aa9 100644
--- a/SabreTools.DatFiles/Formats/RomCenter.Reader.cs
+++ b/SabreTools.DatFiles/Formats/RomCenter.Reader.cs
@@ -110,7 +110,7 @@ namespace SabreTools.DatFiles.Formats
var item = new Rom
{
Name = rom.RomName,
- Size = Utilities.CleanLong(rom.RomSize),
+ Size = NumberHelper.ConvertToInt64(rom.RomSize),
CRC = rom.RomCRC,
MergeTag = rom.MergeName,
ItemStatus = ItemStatus.None,
diff --git a/SabreTools.DatFiles/Formats/SoftwareList.Reader.cs b/SabreTools.DatFiles/Formats/SoftwareList.Reader.cs
index 70351a5c..047184c9 100644
--- a/SabreTools.DatFiles/Formats/SoftwareList.Reader.cs
+++ b/SabreTools.DatFiles/Formats/SoftwareList.Reader.cs
@@ -256,8 +256,8 @@ namespace SabreTools.DatFiles.Formats
var item = new DataArea
{
Name = dataarea.Name,
- Size = Utilities.CleanLong(dataarea.Size),
- Width = Utilities.CleanLong(dataarea.Width),
+ Size = NumberHelper.ConvertToInt64(dataarea.Size),
+ Width = NumberHelper.ConvertToInt64(dataarea.Width),
Endianness = dataarea.Endianness.AsEndianness(),
Source = new Source
@@ -295,7 +295,7 @@ namespace SabreTools.DatFiles.Formats
var item = new Rom
{
Name = rom.Name,
- Size = Utilities.CleanLong(rom.Size ?? rom.Length),
+ Size = NumberHelper.ConvertToInt64(rom.Size ?? rom.Length),
CRC = rom.CRC,
SHA1 = rom.SHA1,
Offset = rom.Offset,
diff --git a/SabreTools.DatFiles/Setter.cs b/SabreTools.DatFiles/Setter.cs
index fe018f50..8d95ce90 100644
--- a/SabreTools.DatFiles/Setter.cs
+++ b/SabreTools.DatFiles/Setter.cs
@@ -472,7 +472,7 @@ namespace SabreTools.DatFiles
chip.ChipType = DatItemMappings[DatItemField.ChipType].AsChipType();
if (DatItemMappings!.ContainsKey(DatItemField.Clock))
- chip.Clock = Utilities.CleanLong(DatItemMappings[DatItemField.Clock]);
+ chip.Clock = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Clock]);
if (DatItemMappings!.ContainsKey(DatItemField.Tag))
chip.Tag = DatItemMappings[DatItemField.Tag];
@@ -559,31 +559,31 @@ namespace SabreTools.DatFiles
private void SetFields(Control control)
{
if (DatItemMappings!.ContainsKey(DatItemField.Control_Buttons))
- control.Buttons = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Buttons]);
+ control.Buttons = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Control_Buttons]);
if (DatItemMappings!.ContainsKey(DatItemField.Control_Type))
control.ControlType = DatItemMappings[DatItemField.Control_Type].AsControlType();
if (DatItemMappings!.ContainsKey(DatItemField.Control_KeyDelta))
- control.KeyDelta = Utilities.CleanLong(DatItemMappings[DatItemField.Control_KeyDelta]);
+ control.KeyDelta = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Control_KeyDelta]);
if (DatItemMappings!.ContainsKey(DatItemField.Control_Maximum))
- control.Maximum = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Maximum]);
+ control.Maximum = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Control_Maximum]);
if (DatItemMappings!.ContainsKey(DatItemField.Control_Minimum))
- control.Minimum = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Minimum]);
+ control.Minimum = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Control_Minimum]);
if (DatItemMappings!.ContainsKey(DatItemField.Control_Player))
- control.Player = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Player]);
+ control.Player = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Control_Player]);
if (DatItemMappings!.ContainsKey(DatItemField.Control_RequiredButtons))
- control.RequiredButtons = Utilities.CleanLong(DatItemMappings[DatItemField.Control_RequiredButtons]);
+ control.RequiredButtons = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Control_RequiredButtons]);
if (DatItemMappings!.ContainsKey(DatItemField.Control_Reverse))
control.Reverse = DatItemMappings[DatItemField.Control_Reverse].AsYesNo();
if (DatItemMappings!.ContainsKey(DatItemField.Control_Sensitivity))
- control.Sensitivity = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Sensitivity]);
+ control.Sensitivity = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Control_Sensitivity]);
if (DatItemMappings!.ContainsKey(DatItemField.Control_Ways))
control.Ways = DatItemMappings[DatItemField.Control_Ways];
@@ -608,10 +608,10 @@ namespace SabreTools.DatFiles
dataArea.Name = DatItemMappings[DatItemField.AreaName];
if (DatItemMappings!.ContainsKey(DatItemField.AreaSize))
- dataArea.Size = Utilities.CleanLong(DatItemMappings[DatItemField.AreaSize]);
+ dataArea.Size = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.AreaSize]);
if (DatItemMappings!.ContainsKey(DatItemField.AreaWidth))
- dataArea.Width = Utilities.CleanLong(DatItemMappings[DatItemField.AreaWidth]);
+ dataArea.Width = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.AreaWidth]);
}
///
@@ -630,7 +630,7 @@ namespace SabreTools.DatFiles
device.Interface = DatItemMappings[DatItemField.Interface];
if (DatItemMappings!.ContainsKey(DatItemField.Mandatory))
- device.Mandatory = Utilities.CleanLong(DatItemMappings[DatItemField.Mandatory]);
+ device.Mandatory = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Mandatory]);
if (DatItemMappings!.ContainsKey(DatItemField.Tag))
device.Tag = DatItemMappings[DatItemField.Tag];
@@ -752,40 +752,40 @@ namespace SabreTools.DatFiles
display.FlipX = DatItemMappings[DatItemField.FlipX].AsYesNo();
if (DatItemMappings!.ContainsKey(DatItemField.Height))
- display.Height = Utilities.CleanLong(DatItemMappings[DatItemField.Height]);
+ display.Height = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Height]);
if (DatItemMappings!.ContainsKey(DatItemField.HBEnd))
- display.HBEnd = Utilities.CleanLong(DatItemMappings[DatItemField.HBEnd]);
+ display.HBEnd = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.HBEnd]);
if (DatItemMappings!.ContainsKey(DatItemField.HBStart))
- display.HBStart = Utilities.CleanLong(DatItemMappings[DatItemField.HBStart]);
+ display.HBStart = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.HBStart]);
if (DatItemMappings!.ContainsKey(DatItemField.HTotal))
- display.HTotal = Utilities.CleanLong(DatItemMappings[DatItemField.HTotal]);
+ display.HTotal = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.HTotal]);
if (DatItemMappings!.ContainsKey(DatItemField.PixClock))
- display.PixClock = Utilities.CleanLong(DatItemMappings[DatItemField.PixClock]);
+ display.PixClock = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.PixClock]);
if (DatItemMappings!.ContainsKey(DatItemField.Refresh))
- display.Refresh = Utilities.CleanDouble(DatItemMappings[DatItemField.Refresh]);
+ display.Refresh = NumberHelper.ConvertToDouble(DatItemMappings[DatItemField.Refresh]);
if (DatItemMappings!.ContainsKey(DatItemField.Rotate))
- display.Rotate = Utilities.CleanLong(DatItemMappings[DatItemField.Rotate]);
+ display.Rotate = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Rotate]);
if (DatItemMappings!.ContainsKey(DatItemField.Tag))
display.Tag = DatItemMappings[DatItemField.Tag];
if (DatItemMappings!.ContainsKey(DatItemField.VBEnd))
- display.VBEnd = Utilities.CleanLong(DatItemMappings[DatItemField.VBEnd]);
+ display.VBEnd = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.VBEnd]);
if (DatItemMappings!.ContainsKey(DatItemField.VBStart))
- display.VBStart = Utilities.CleanLong(DatItemMappings[DatItemField.VBStart]);
+ display.VBStart = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.VBStart]);
if (DatItemMappings!.ContainsKey(DatItemField.VTotal))
- display.VTotal = Utilities.CleanLong(DatItemMappings[DatItemField.VTotal]);
+ display.VTotal = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.VTotal]);
if (DatItemMappings!.ContainsKey(DatItemField.Width))
- display.Width = Utilities.CleanLong(DatItemMappings[DatItemField.Width]);
+ display.Width = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Width]);
}
///
@@ -862,10 +862,10 @@ namespace SabreTools.DatFiles
private void SetFields(Input input)
{
if (DatItemMappings!.ContainsKey(DatItemField.Coins))
- input.Coins = Utilities.CleanLong(DatItemMappings[DatItemField.Coins]);
+ input.Coins = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Coins]);
if (DatItemMappings!.ContainsKey(DatItemField.Players))
- input.Players = Utilities.CleanLong(DatItemMappings[DatItemField.Players]);
+ input.Players = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Players]);
if (DatItemMappings!.ContainsKey(DatItemField.Service))
input.Service = DatItemMappings[DatItemField.Service].AsYesNo();
@@ -908,7 +908,7 @@ namespace SabreTools.DatFiles
location.Name = DatItemMappings[DatItemField.Location_Name];
if (DatItemMappings!.ContainsKey(DatItemField.Location_Number))
- location.Number = Utilities.CleanLong(DatItemMappings[DatItemField.Location_Number]);
+ location.Number = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Location_Number]);
}
///
@@ -1099,7 +1099,7 @@ namespace SabreTools.DatFiles
rom.SHA512 = DatItemMappings[DatItemField.SHA512];
if (DatItemMappings!.ContainsKey(DatItemField.Size))
- rom.Size = Utilities.CleanLong(DatItemMappings[DatItemField.Size]);
+ rom.Size = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Size]);
if (DatItemMappings!.ContainsKey(DatItemField.SpamSum))
rom.SpamSum = DatItemMappings[DatItemField.SpamSum];
@@ -1208,7 +1208,7 @@ namespace SabreTools.DatFiles
private void SetFields(Sound sound)
{
if (DatItemMappings!.ContainsKey(DatItemField.Channels))
- sound.Channels = Utilities.CleanLong(DatItemMappings[DatItemField.Channels]);
+ sound.Channels = NumberHelper.ConvertToInt64(DatItemMappings[DatItemField.Channels]);
}
}
}
\ No newline at end of file
diff --git a/SabreTools.Filter/FilterObject.cs b/SabreTools.Filter/FilterObject.cs
index fa57542e..0fc8b62b 100644
--- a/SabreTools.Filter/FilterObject.cs
+++ b/SabreTools.Filter/FilterObject.cs
@@ -84,7 +84,10 @@ namespace SabreTools.Filter
///
/// Determines if a value matches exactly
///
- /// TODO: Add regex matching to this method
+ ///
+ /// TODO: Add regex matching to this method
+ /// TODO: Add logic to convert SI suffixes and hex
+ ///
private bool MatchesEqual(DictionaryBase dictionaryBase)
{
if (!dictionaryBase.ContainsKey(this.Key[1]))
@@ -97,7 +100,10 @@ namespace SabreTools.Filter
///
/// Determines if a value does not match exactly
///
- /// TODO: Add regex matching to this method
+ ///
+ /// TODO: Add regex matching to this method
+ /// TODO: Add logic to convert SI suffixes and hex
+ ///
private bool MatchesNotEqual(DictionaryBase dictionaryBase)
{
if (!dictionaryBase.ContainsKey(this.Key[1]))
@@ -110,6 +116,7 @@ namespace SabreTools.Filter
///
/// Determines if a value is strictly greater than
///
+ /// TODO: Add logic to convert SI suffixes and hex
private bool MatchesGreaterThan(DictionaryBase dictionaryBase)
{
if (!dictionaryBase.ContainsKey(this.Key[1]))
@@ -139,6 +146,7 @@ namespace SabreTools.Filter
///
/// Determines if a value is greater than or equal
///
+ /// TODO: Add logic to convert SI suffixes and hex
private bool MatchesGreaterThanOrEqual(DictionaryBase dictionaryBase)
{
if (!dictionaryBase.ContainsKey(this.Key[1]))
@@ -168,6 +176,7 @@ namespace SabreTools.Filter
///
/// Determines if a value is strictly less than
///
+ /// TODO: Add logic to convert SI suffixes and hex
private bool MatchesLessThan(DictionaryBase dictionaryBase)
{
if (!dictionaryBase.ContainsKey(this.Key[1]))
@@ -197,6 +206,7 @@ namespace SabreTools.Filter
///
/// Determines if a value is less than or equal
///
+ /// TODO: Add logic to convert SI suffixes and hex
private bool MatchesLessThanOrEqual(DictionaryBase dictionaryBase)
{
if (!dictionaryBase.ContainsKey(this.Key[1]))
diff --git a/SabreTools.Models/Internal/DictionaryBase.cs b/SabreTools.Models/Internal/DictionaryBase.cs
index 44f677b6..c0909aac 100644
--- a/SabreTools.Models/Internal/DictionaryBase.cs
+++ b/SabreTools.Models/Internal/DictionaryBase.cs
@@ -62,6 +62,7 @@ namespace SabreTools.Models.Internal
///
/// Read a key as a long, returning null on error
///
+ /// TODO: Add logic to convert SI suffixes and hex
public long? ReadLong(string key)
{
if (!ValidateKey(key))
diff --git a/SabreTools.Test/Core/UtilitiesTests.cs b/SabreTools.Test/Core/UtilitiesTests.cs
index 6c1b4377..c50f5b37 100644
--- a/SabreTools.Test/Core/UtilitiesTests.cs
+++ b/SabreTools.Test/Core/UtilitiesTests.cs
@@ -16,7 +16,7 @@ namespace SabreTools.Test.Core
[InlineData(" 12345 ", 12345L)]
public void CleanLongTest(string input, long? expected)
{
- long? actual = Utilities.CleanLong(input);
+ long? actual = NumberHelper.ConvertToInt64(input);
Assert.Equal(expected, actual);
}