Add ControlType, fix a bunch of numerics

This commit is contained in:
Matt Nadareski
2020-09-06 23:00:13 -07:00
parent aa414bc3cd
commit 5d5520dbdd
16 changed files with 323 additions and 248 deletions

View File

@@ -699,56 +699,20 @@ namespace SabreTools.Library.DatFiles
case "control":
var control = new Control
{
ControlType = reader.GetAttribute("type"),
RegButtons = reader.GetAttribute("regbuttons"),
ControlType = reader.GetAttribute("type").AsControlType(),
Player = Sanitizer.CleanLong(reader.GetAttribute("player")),
Buttons = Sanitizer.CleanLong(reader.GetAttribute("buttons")),
RequiredButtons = Sanitizer.CleanLong(reader.GetAttribute("reqbuttons")),
Minimum = Sanitizer.CleanLong(reader.GetAttribute("minimum")),
Maximum = Sanitizer.CleanLong(reader.GetAttribute("maximum")),
Sensitivity = Sanitizer.CleanLong(reader.GetAttribute("sensitivity")),
KeyDelta = Sanitizer.CleanLong(reader.GetAttribute("keydelta")),
Reverse = reader.GetAttribute("reverse").AsYesNo(),
Ways = reader.GetAttribute("ways"),
Ways2 = reader.GetAttribute("ways2"),
Ways3 = reader.GetAttribute("ways3"),
};
// Set the player
if (reader.GetAttribute("player") != null)
{
if (Int64.TryParse(reader.GetAttribute("player"), out long player))
control.Player = player;
}
// Set the buttons
if (reader.GetAttribute("buttons") != null)
{
if (Int64.TryParse(reader.GetAttribute("buttons"), out long buttons))
control.Buttons = buttons;
}
// Set the minimum
if (reader.GetAttribute("minimum") != null)
{
if (Int64.TryParse(reader.GetAttribute("minimum"), out long minimum))
control.Minimum = minimum;
}
// Set the maximum
if (reader.GetAttribute("maximum") != null)
{
if (Int64.TryParse(reader.GetAttribute("maximum"), out long maximum))
control.Maximum = maximum;
}
// Set the sensitivity
if (reader.GetAttribute("sensitivity") != null)
{
if (Int64.TryParse(reader.GetAttribute("sensitivity"), out long sensitivity))
control.Sensitivity = sensitivity;
}
// Set the keydelta
if (reader.GetAttribute("keydelta") != null)
{
if (Int64.TryParse(reader.GetAttribute("keydelta"), out long keyDelta))
control.KeyDelta = keyDelta;
}
input.Controls.Add(control);
reader.Read();
@@ -1608,10 +1572,10 @@ namespace SabreTools.Library.DatFiles
foreach (var control in input.Controls)
{
xtw.WriteStartElement("control");
xtw.WriteOptionalAttributeString("type", control.ControlType);
xtw.WriteOptionalAttributeString("type", control.ControlType.FromControlType());
xtw.WriteOptionalAttributeString("player", control.Player?.ToString());
xtw.WriteOptionalAttributeString("buttons", control.Buttons?.ToString());
xtw.WriteOptionalAttributeString("regbuttons", control.RegButtons);
xtw.WriteOptionalAttributeString("reqbuttons", control.RequiredButtons?.ToString());
xtw.WriteOptionalAttributeString("minimum", control.Minimum?.ToString());
xtw.WriteOptionalAttributeString("maximum", control.Maximum?.ToString());
xtw.WriteOptionalAttributeString("sensitivity", control.Sensitivity?.ToString());

View File

@@ -466,7 +466,7 @@ namespace SabreTools.Library.DatFiles
{
// Prepare all internal variables
string releaseNumber = string.Empty, duplicateid;
long size = -1;
long? size = null;
List<Rom> datItems = new List<Rom>();
Machine machine = new Machine();
@@ -510,9 +510,7 @@ namespace SabreTools.Library.DatFiles
break;
case "romsize":
if (!Int64.TryParse(reader.ReadElementContentAsString(), out size))
size = -1;
size = Sanitizer.CleanLong(reader.ReadElementContentAsString());
break;
case "publisher":

View File

@@ -7,6 +7,7 @@ using System.Text;
using SabreTools.Library.Data;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
{
@@ -328,15 +329,10 @@ namespace SabreTools.Library.DatFiles
9 - merge name
*/
string[] rominfo = line.Split('¬');
// Try getting the size separately
if (!Int64.TryParse(rominfo[7], out long size))
size = 0;
Rom rom = new Rom
{
Name = rominfo[5],
Size = size,
Size = Sanitizer.CleanLong(rominfo[7]),
CRC = rominfo[6],
ItemStatus = ItemStatus.None,

View File

@@ -400,6 +400,7 @@ namespace SabreTools.Library.DatFiles
Name = reader.GetAttribute("name"),
Tag = reader.GetAttribute("tag"),
ChipType = reader.GetAttribute("chiptype").AsChipType(),
Clock = Sanitizer.CleanLong(reader.GetAttribute("clock")),
Source = new Source
{
@@ -408,13 +409,6 @@ namespace SabreTools.Library.DatFiles
},
};
// Set the clock
if (reader.GetAttribute("clock") != null)
{
if (Int64.TryParse(reader.GetAttribute("clock"), out long clock))
(datItem as Chip).Clock = clock;
}
break;
case "configuration":
@@ -1504,10 +1498,10 @@ namespace SabreTools.Library.DatFiles
foreach (var control in input.Controls)
{
xtw.WriteStartElement("control");
xtw.WriteOptionalAttributeString("type", control.ControlType);
xtw.WriteOptionalAttributeString("type", control.ControlType.FromControlType());
xtw.WriteOptionalAttributeString("player", control.Player?.ToString());
xtw.WriteOptionalAttributeString("buttons", control.Buttons?.ToString());
xtw.WriteOptionalAttributeString("regbuttons", control.RegButtons);
xtw.WriteOptionalAttributeString("reqbuttons", control.RequiredButtons?.ToString());
xtw.WriteOptionalAttributeString("minimum", control.Minimum?.ToString());
xtw.WriteOptionalAttributeString("maximum", control.Maximum?.ToString());
xtw.WriteOptionalAttributeString("sensitivity", control.Sensitivity?.ToString());

View File

@@ -255,23 +255,11 @@ namespace SabreTools.Library.DatFiles
var dataArea = new DataArea
{
Name = reader.GetAttribute("name"),
Size = Sanitizer.CleanLong(reader.GetAttribute("size")),
Width = Sanitizer.CleanLong(reader.GetAttribute("width")),
Endianness = reader.GetAttribute("endianness").AsEndianness(),
};
// Set the size
if (reader.GetAttribute("size") != null)
{
if (Int64.TryParse(reader.GetAttribute("width"), out long size))
dataArea.Size = size;
}
// Set the width
if (reader.GetAttribute("width") != null)
{
if (Int64.TryParse(reader.GetAttribute("width"), out long width))
dataArea.Width = width;
}
List<DatItem> roms = ReadDataArea(reader.ReadSubtree(), dataArea);
// If we got valid roms, add them to the list