mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Convert Rom size field to long?
This commit is contained in:
@@ -286,12 +286,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
case "size":
|
||||
if (item.ItemType == ItemType.Rom)
|
||||
{
|
||||
if (Int64.TryParse(attrVal, out long size))
|
||||
(item as Rom).Size = size;
|
||||
else
|
||||
(item as Rom).Size = -1;
|
||||
}
|
||||
(item as Rom).Size = Sanitizer.CleanLong(attrVal);
|
||||
|
||||
break;
|
||||
case "crc":
|
||||
@@ -660,7 +655,7 @@ namespace SabreTools.Library.DatFiles
|
||||
var rom = datItem as Rom;
|
||||
cmpw.WriteStartElement("rom");
|
||||
cmpw.WriteRequiredAttributeString("name", rom.Name);
|
||||
if (rom.Size != -1) cmpw.WriteAttributeString("size", rom.Size.ToString());
|
||||
cmpw.WriteOptionalAttributeString("size", rom.Size?.ToString());
|
||||
cmpw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
cmpw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
||||
#if NET_FRAMEWORK
|
||||
|
||||
@@ -1876,7 +1876,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Rom rom = item as Rom;
|
||||
|
||||
// If we have the case where there is SHA-1 and nothing else, we don't fill in any other part of the data
|
||||
if (rom.Size == -1
|
||||
if (rom.Size == null
|
||||
&& string.IsNullOrWhiteSpace(rom.CRC)
|
||||
&& string.IsNullOrWhiteSpace(rom.MD5)
|
||||
#if NET_FRAMEWORK
|
||||
@@ -1892,7 +1892,7 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info
|
||||
else if ((rom.Size == 0 || rom.Size == -1)
|
||||
else if ((rom.Size == 0 || rom.Size == null)
|
||||
&& ((rom.CRC == Constants.CRCZero || string.IsNullOrWhiteSpace(rom.CRC))
|
||||
|| rom.MD5 == Constants.MD5Zero
|
||||
#if NET_FRAMEWORK
|
||||
@@ -1917,7 +1917,7 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// If the file has no size and it's not the above case, skip and log
|
||||
else if (rom.ItemStatus != ItemStatus.Nodump && (rom.Size == 0 || rom.Size == -1))
|
||||
else if (rom.ItemStatus != ItemStatus.Nodump && (rom.Size == 0 || rom.Size == null))
|
||||
{
|
||||
Globals.Logger.Verbose($"{Header.FileName}: Incomplete entry for '{rom.Name}' will be output as nodump");
|
||||
rom.ItemStatus = ItemStatus.Nodump;
|
||||
@@ -1925,6 +1925,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// If the file has a size but aboslutely no hashes, skip and log
|
||||
else if (rom.ItemStatus != ItemStatus.Nodump
|
||||
&& rom.Size != null
|
||||
&& rom.Size > 0
|
||||
&& string.IsNullOrWhiteSpace(rom.CRC)
|
||||
&& string.IsNullOrWhiteSpace(rom.MD5)
|
||||
@@ -3360,6 +3361,10 @@ namespace SabreTools.Library.DatFiles
|
||||
if (item.ItemType != ItemType.Rom)
|
||||
lessThan.Items.Add(key, item);
|
||||
|
||||
// If the file is a Rom and has no size, put it in the "lesser" dat
|
||||
else if (item.ItemType == ItemType.Rom && (item as Rom).Size == null)
|
||||
lessThan.Items.Add(key, item);
|
||||
|
||||
// If the file is a Rom and less than the radix, put it in the "lesser" dat
|
||||
else if (item.ItemType == ItemType.Rom && (item as Rom).Size < radix)
|
||||
lessThan.Items.Add(key, item);
|
||||
@@ -3557,7 +3562,7 @@ namespace SabreTools.Library.DatFiles
|
||||
sha256 = (item as Rom).SHA256 ?? string.Empty;
|
||||
sha384 = (item as Rom).SHA384 ?? string.Empty;
|
||||
sha512 = (item as Rom).SHA512 ?? string.Empty;
|
||||
size = (item as Rom).Size.ToString();
|
||||
size = (item as Rom).Size?.ToString() ?? string.Empty;
|
||||
spamsum = (item as Rom).SpamSum ?? string.Empty;
|
||||
}
|
||||
|
||||
@@ -3690,7 +3695,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Rom rom = datItem as Rom;
|
||||
|
||||
// If the Rom has "null" characteristics, ensure all fields
|
||||
if (rom.Size == -1 && rom.CRC == "null")
|
||||
if (rom.Size == null && rom.CRC == "null")
|
||||
{
|
||||
Globals.Logger.Verbose($"Empty folder found: {datItem.Machine.Name}");
|
||||
|
||||
@@ -3732,7 +3737,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Rom rom = datItem as Rom;
|
||||
|
||||
// If we have a 0-size or blank rom, then we ignore
|
||||
if (rom.Size == 0 || rom.Size == -1)
|
||||
if (rom.Size == 0 || rom.Size == null)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -209,11 +210,7 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "size":
|
||||
if (Int64.TryParse(attrVal, out long size))
|
||||
item.Size = size;
|
||||
else
|
||||
item.Size = -1;
|
||||
|
||||
item.Size = Sanitizer.CleanLong(attrVal);
|
||||
break;
|
||||
|
||||
case "crc":
|
||||
@@ -435,7 +432,7 @@ namespace SabreTools.Library.DatFiles
|
||||
var rom = datItem as Rom;
|
||||
cmpw.WriteStartElement("file");
|
||||
cmpw.WriteRequiredAttributeString("name", rom.Name);
|
||||
if (rom.Size != -1) cmpw.WriteAttributeString("size", rom.Size.ToString());
|
||||
cmpw.WriteOptionalAttributeString("size", rom.Size?.ToString());
|
||||
cmpw.WriteOptionalAttributeString("date", rom.Date);
|
||||
cmpw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
cmpw.WriteEndElement();
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Rom rom = new Rom
|
||||
{
|
||||
Name = gameinfo[1].Substring(fullname[0].Length + 1),
|
||||
Size = -1, // No size provided, but we don't want the size being 0
|
||||
Size = null, // No size provided, but we don't want the size being 0
|
||||
CRC = gameinfo[4],
|
||||
MD5 = gameinfo[3],
|
||||
SHA1 = gameinfo[2],
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Rom rom = new Rom
|
||||
{
|
||||
Name = name,
|
||||
Size = -1,
|
||||
Size = null,
|
||||
CRC = (_hash.HasFlag(Hash.CRC) ? hash : null),
|
||||
MD5 = (_hash.HasFlag(Hash.MD5) ? hash : null),
|
||||
#if NET_FRAMEWORK
|
||||
|
||||
@@ -679,7 +679,7 @@ namespace SabreTools.Library.DatFiles
|
||||
RomCount++;
|
||||
if ((item as Rom).ItemStatus != ItemStatus.Nodump)
|
||||
{
|
||||
TotalSize += (item as Rom).Size;
|
||||
TotalSize += (item as Rom).Size ?? 0;
|
||||
CRCCount += (string.IsNullOrWhiteSpace((item as Rom).CRC) ? 0 : 1);
|
||||
MD5Count += (string.IsNullOrWhiteSpace((item as Rom).MD5) ? 0 : 1);
|
||||
#if NET_FRAMEWORK
|
||||
@@ -875,7 +875,7 @@ namespace SabreTools.Library.DatFiles
|
||||
RomCount--;
|
||||
if ((item as Rom).ItemStatus != ItemStatus.Nodump)
|
||||
{
|
||||
TotalSize -= (item as Rom).Size;
|
||||
TotalSize -= (item as Rom).Size ?? 0;
|
||||
CRCCount -= (string.IsNullOrWhiteSpace((item as Rom).CRC) ? 0 : 1);
|
||||
MD5Count -= (string.IsNullOrWhiteSpace((item as Rom).MD5) ? 0 : 1);
|
||||
#if NET_FRAMEWORK
|
||||
|
||||
@@ -146,13 +146,10 @@ namespace SabreTools.Library.DatFiles
|
||||
// Standard ROMs have 4 pieces (name, size, crc, sha1)
|
||||
else if (split.Length == 3)
|
||||
{
|
||||
if (!Int64.TryParse(split[0], out long size))
|
||||
size = 0;
|
||||
|
||||
Rom rom = new Rom()
|
||||
{
|
||||
Name = romname,
|
||||
Size = size,
|
||||
Size = Sanitizer.CleanLong(split[0]),
|
||||
CRC = Sanitizer.CleanListromHashData(split[1]),
|
||||
SHA1 = Sanitizer.CleanListromHashData(split[2]),
|
||||
|
||||
@@ -197,13 +194,10 @@ namespace SabreTools.Library.DatFiles
|
||||
// Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP)
|
||||
else if (split.Length == 5 && line.EndsWith("BAD_DUMP"))
|
||||
{
|
||||
if (!Int64.TryParse(split[0], out long size))
|
||||
size = 0;
|
||||
|
||||
Rom rom = new Rom()
|
||||
{
|
||||
Name = romname,
|
||||
Size = size,
|
||||
Size = Sanitizer.CleanLong(split[0]),
|
||||
CRC = Sanitizer.CleanListromHashData(split[2]),
|
||||
SHA1 = Sanitizer.CleanListromHashData(split[3]),
|
||||
ItemStatus = ItemStatus.BadDump,
|
||||
@@ -226,13 +220,10 @@ namespace SabreTools.Library.DatFiles
|
||||
// Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN)
|
||||
else if (split.Length == 5 && line.EndsWith("NO GOOD DUMP KNOWN"))
|
||||
{
|
||||
if (!Int64.TryParse(split[0], out long size))
|
||||
size = 0;
|
||||
|
||||
Rom rom = new Rom()
|
||||
{
|
||||
Name = romname,
|
||||
Size = size,
|
||||
Size = Sanitizer.CleanLong(split[0]),
|
||||
ItemStatus = ItemStatus.Nodump,
|
||||
|
||||
Machine = new Machine
|
||||
@@ -429,13 +420,13 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// The name is padded out to a particular length
|
||||
if (rom.Name.Length < 43)
|
||||
sw.Write(rom.Name.PadRight(43 - rom.Size.ToString().Length, ' '));
|
||||
sw.Write(rom.Name.PadRight(43 - rom.Size?.ToString().Length ?? 0, ' '));
|
||||
else
|
||||
sw.Write($"{rom.Name} ");
|
||||
|
||||
// If we don't have a nodump, write out the size
|
||||
if (rom.ItemStatus != ItemStatus.Nodump)
|
||||
sw.Write(rom.Size);
|
||||
sw.Write(rom.Size?.ToString() ?? string.Empty);
|
||||
|
||||
// If we have a baddump, put the first indicator
|
||||
if (rom.ItemStatus == ItemStatus.BadDump)
|
||||
|
||||
@@ -212,6 +212,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Name = reader.GetAttribute("name"),
|
||||
Tag = reader.GetAttribute("tag"),
|
||||
ChipType = reader.GetAttribute("type").AsChipType(),
|
||||
Clock = Sanitizer.CleanLong(reader.GetAttribute("clock")),
|
||||
|
||||
Source = new Source
|
||||
{
|
||||
@@ -220,13 +221,6 @@ namespace SabreTools.Library.DatFiles
|
||||
},
|
||||
};
|
||||
|
||||
// Set the clock
|
||||
if (reader.GetAttribute("clock") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("clock"), out long clock))
|
||||
chip.Clock = clock;
|
||||
}
|
||||
|
||||
datItems.Add(chip);
|
||||
|
||||
reader.Read();
|
||||
@@ -369,7 +363,17 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
Tag = reader.GetAttribute("tag"),
|
||||
DisplayType = reader.GetAttribute("type").AsDisplayType(),
|
||||
Rotate = Sanitizer.CleanLong(reader.GetAttribute("rotate")),
|
||||
FlipX = reader.GetAttribute("flipx").AsYesNo(),
|
||||
Width = Sanitizer.CleanLong(reader.GetAttribute("width")),
|
||||
Height = Sanitizer.CleanLong(reader.GetAttribute("height")),
|
||||
PixClock = Sanitizer.CleanLong(reader.GetAttribute("pixclock")),
|
||||
HTotal = Sanitizer.CleanLong(reader.GetAttribute("htotal")),
|
||||
HBEnd = Sanitizer.CleanLong(reader.GetAttribute("hbend")),
|
||||
HBStart = Sanitizer.CleanLong(reader.GetAttribute("hbstart")),
|
||||
VTotal = Sanitizer.CleanLong(reader.GetAttribute("vtotal")),
|
||||
VBEnd = Sanitizer.CleanLong(reader.GetAttribute("vbend")),
|
||||
VBStart = Sanitizer.CleanLong(reader.GetAttribute("vbstart")),
|
||||
|
||||
Source = new Source
|
||||
{
|
||||
@@ -378,27 +382,6 @@ namespace SabreTools.Library.DatFiles
|
||||
},
|
||||
};
|
||||
|
||||
// Set the rotation
|
||||
if (reader.GetAttribute("rotate") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("rotate"), out long rotate))
|
||||
display.Rotate = rotate;
|
||||
}
|
||||
|
||||
// Set the width
|
||||
if (reader.GetAttribute("width") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("width"), out long width))
|
||||
display.Width = width;
|
||||
}
|
||||
|
||||
// Set the height
|
||||
if (reader.GetAttribute("height") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("height"), out long height))
|
||||
display.Height = height;
|
||||
}
|
||||
|
||||
// Set the refresh
|
||||
if (reader.GetAttribute("refresh") != null)
|
||||
{
|
||||
@@ -406,55 +389,6 @@ namespace SabreTools.Library.DatFiles
|
||||
display.Refresh = refresh;
|
||||
}
|
||||
|
||||
// Set the pixclock
|
||||
if (reader.GetAttribute("pixclock") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("pixclock"), out long pixclock))
|
||||
display.PixClock = pixclock;
|
||||
}
|
||||
|
||||
// Set the htotal
|
||||
if (reader.GetAttribute("htotal") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("htotal"), out long htotal))
|
||||
display.HTotal = htotal;
|
||||
}
|
||||
|
||||
// Set the hbend
|
||||
if (reader.GetAttribute("hbend") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("hbend"), out long hbend))
|
||||
display.HBEnd = hbend;
|
||||
}
|
||||
|
||||
// Set the hbstart
|
||||
if (reader.GetAttribute("hbstart") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("hbstart"), out long hbstart))
|
||||
display.HBStart = hbstart;
|
||||
}
|
||||
|
||||
// Set the vtotal
|
||||
if (reader.GetAttribute("vtotal") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("vtotal"), out long vtotal))
|
||||
display.VTotal = vtotal;
|
||||
}
|
||||
|
||||
// Set the vbend
|
||||
if (reader.GetAttribute("vbend") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("vbend"), out long vbend))
|
||||
display.VBEnd = vbend;
|
||||
}
|
||||
|
||||
// Set the vbstart
|
||||
if (reader.GetAttribute("vbstart") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("vbstart"), out long vbstart))
|
||||
display.VBStart = vbstart;
|
||||
}
|
||||
|
||||
datItems.Add(display);
|
||||
|
||||
reader.Read();
|
||||
@@ -500,6 +434,8 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
Service = reader.GetAttribute("service").AsYesNo(),
|
||||
Tilt = reader.GetAttribute("tilt").AsYesNo(),
|
||||
Players = Sanitizer.CleanLong(reader.GetAttribute("players")),
|
||||
Coins = Sanitizer.CleanLong(reader.GetAttribute("coins")),
|
||||
|
||||
Source = new Source
|
||||
{
|
||||
@@ -508,20 +444,6 @@ namespace SabreTools.Library.DatFiles
|
||||
},
|
||||
};
|
||||
|
||||
// Set the players count
|
||||
if (reader.GetAttribute("players") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("players"), out long players))
|
||||
input.Players = players;
|
||||
}
|
||||
|
||||
// Set the coins count
|
||||
if (reader.GetAttribute("coins") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("coins"), out long coins))
|
||||
input.Coins = coins;
|
||||
}
|
||||
|
||||
// Now read the internal tags
|
||||
ReadInput(reader.ReadSubtree(), input);
|
||||
|
||||
@@ -573,7 +495,7 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Bios = reader.GetAttribute("bios"),
|
||||
Size = Sanitizer.CleanSize(reader.GetAttribute("size")),
|
||||
Size = Sanitizer.CleanLong(reader.GetAttribute("size")),
|
||||
CRC = reader.GetAttribute("crc"),
|
||||
SHA1 = reader.GetAttribute("sha1"),
|
||||
MergeTag = reader.GetAttribute("merge"),
|
||||
@@ -649,6 +571,8 @@ namespace SabreTools.Library.DatFiles
|
||||
case "sound":
|
||||
var sound = new Sound
|
||||
{
|
||||
Channels = Sanitizer.CleanLong(reader.GetAttribute("channels")),
|
||||
|
||||
Source = new Source
|
||||
{
|
||||
Index = indexId,
|
||||
@@ -656,13 +580,6 @@ namespace SabreTools.Library.DatFiles
|
||||
},
|
||||
};
|
||||
|
||||
// Set the channels
|
||||
if (reader.GetAttribute("channels") != null)
|
||||
{
|
||||
if (Int64.TryParse(reader.GetAttribute("channels"), out long channels))
|
||||
sound.Channels = channels;
|
||||
}
|
||||
|
||||
datItems.Add(sound);
|
||||
|
||||
reader.Read();
|
||||
@@ -1738,7 +1655,7 @@ namespace SabreTools.Library.DatFiles
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteStartElement("rom");
|
||||
xtw.WriteRequiredAttributeString("name", rom.Name);
|
||||
if (rom.Size != -1) xtw.WriteAttributeString("size", rom.Size.ToString());
|
||||
xtw.WriteOptionalAttributeString("size", rom.Size?.ToString());
|
||||
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha1", rom.SHA1?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("bios", rom.Bios);
|
||||
|
||||
@@ -489,7 +489,7 @@ namespace SabreTools.Library.DatFiles
|
||||
DatItem rom = new Rom
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Size = Sanitizer.CleanSize(reader.GetAttribute("size")),
|
||||
Size = Sanitizer.CleanLong(reader.GetAttribute("size")),
|
||||
CRC = reader.GetAttribute("crc"),
|
||||
MD5 = reader.GetAttribute("md5"),
|
||||
#if NET_FRAMEWORK
|
||||
@@ -991,7 +991,7 @@ namespace SabreTools.Library.DatFiles
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteStartElement("rom");
|
||||
xtw.WriteRequiredAttributeString("name", rom.Name);
|
||||
if (rom.Size != -1) xtw.WriteAttributeString("size", rom.Size.ToString());
|
||||
xtw.WriteAttributeString("size", rom.Size?.ToString());
|
||||
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
||||
#if NET_FRAMEWORK
|
||||
|
||||
@@ -874,7 +874,7 @@ namespace SabreTools.Library.DatFiles
|
||||
if (datItem.ItemType == ItemType.Rom)
|
||||
{
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteRequiredElementString("romSize", rom.Size.ToString());
|
||||
xtw.WriteRequiredElementString("romSize", rom.Size?.ToString());
|
||||
}
|
||||
|
||||
xtw.WriteRequiredElementString("publisher", datItem.Machine.Publisher);
|
||||
|
||||
@@ -329,7 +329,7 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
||||
Offset = offset,
|
||||
Size = -1,
|
||||
Size = null,
|
||||
SHA1 = hash,
|
||||
|
||||
Source = new Source
|
||||
@@ -411,7 +411,7 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
||||
Offset = offset,
|
||||
Size = -1,
|
||||
Size = null,
|
||||
SHA1 = hash,
|
||||
|
||||
Source = new Source
|
||||
@@ -487,7 +487,7 @@ namespace SabreTools.Library.DatFiles
|
||||
return new Rom
|
||||
{
|
||||
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
||||
Size = -1,
|
||||
Size = null,
|
||||
SHA1 = hash,
|
||||
|
||||
Source = new Source
|
||||
|
||||
@@ -508,7 +508,7 @@ namespace SabreTools.Library.DatFiles
|
||||
iw.WriteString($"¬{rom.Machine.Description ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Name ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.CRC ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Size}");
|
||||
iw.WriteString($"¬{rom.Size?.ToString() ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Machine.RomOf ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.MergeTag ?? string.Empty}");
|
||||
iw.WriteString("¬");
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="indexId">Index ID for the DAT</param>
|
||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||
/// TODO: This is horrendeously out of date. Once all done promoting, try to make this like JSON
|
||||
/// TODO: Convert this to a direct serializer like JSON is
|
||||
private bool ReadDirectory(
|
||||
XmlReader reader,
|
||||
List<string> parent,
|
||||
@@ -234,7 +234,7 @@ namespace SabreTools.Library.DatFiles
|
||||
XmlReader flagreader;
|
||||
bool empty = true;
|
||||
string key = string.Empty, date = string.Empty;
|
||||
long size = -1;
|
||||
long? size = null;
|
||||
ItemStatus its = ItemStatus.None;
|
||||
|
||||
// If there's no subtree to the header, skip it
|
||||
@@ -339,7 +339,7 @@ namespace SabreTools.Library.DatFiles
|
||||
date = Sanitizer.CleanDate(reader.GetAttribute("date"));
|
||||
|
||||
// Take care of hex-sized files
|
||||
size = Sanitizer.CleanSize(reader.GetAttribute("size"));
|
||||
size = Sanitizer.CleanLong(reader.GetAttribute("size"));
|
||||
|
||||
Machine dir = new Machine
|
||||
{
|
||||
@@ -1578,7 +1578,7 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "rom");
|
||||
xtw.WriteRequiredAttributeString("name", rom.Name);
|
||||
if (rom.Size != -1) xtw.WriteAttributeString("size", rom.Size.ToString());
|
||||
xtw.WriteOptionalAttributeString("size", rom.Size?.ToString());
|
||||
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
||||
#if NET_FRAMEWORK
|
||||
|
||||
@@ -268,7 +268,7 @@ namespace SabreTools.Library.DatFiles
|
||||
fields[5] = "rom";
|
||||
fields[6] = rom.Name;
|
||||
fields[7] = string.Empty;
|
||||
fields[8] = rom.Size.ToString();
|
||||
fields[8] = rom.Size?.ToString();
|
||||
fields[9] = rom.CRC?.ToLowerInvariant();
|
||||
fields[10] = rom.MD5?.ToLowerInvariant();
|
||||
//fields[11] = rom.RIPEMD160?.ToLowerInvariant();
|
||||
|
||||
@@ -374,7 +374,7 @@ namespace SabreTools.Library.DatFiles
|
||||
var rom = new Rom
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Size = Sanitizer.CleanSize(reader.GetAttribute("size")),
|
||||
Size = Sanitizer.CleanLong(reader.GetAttribute("size")),
|
||||
CRC = reader.GetAttribute("crc"),
|
||||
SHA1 = reader.GetAttribute("sha1"),
|
||||
Offset = reader.GetAttribute("offset"),
|
||||
@@ -788,7 +788,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
xtw.WriteStartElement("rom");
|
||||
xtw.WriteRequiredAttributeString("name", rom.Name);
|
||||
if (rom.Size != -1) xtw.WriteAttributeString("size", rom.Size.ToString());
|
||||
xtw.WriteOptionalAttributeString("size", rom.Size?.ToString());
|
||||
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
||||
#if NET_FRAMEWORK
|
||||
|
||||
@@ -110,7 +110,6 @@ namespace SabreTools.Library.DatItems
|
||||
/// <summary>
|
||||
/// List of valid field types within a DatItem/Machine
|
||||
/// </summary>
|
||||
/// TODO: Move this to a more common location
|
||||
public enum Field : int
|
||||
{
|
||||
NULL = 0,
|
||||
|
||||
@@ -53,9 +53,8 @@ namespace SabreTools.Library.DatItems
|
||||
/// <summary>
|
||||
/// Byte size of the rom
|
||||
/// </summary>
|
||||
/// TODO: Can this be made optional instead of concrete long? Use `null` instead of `-1`?
|
||||
[JsonProperty("size", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public long Size { get; set; }
|
||||
public long? Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// File CRC32 hash
|
||||
@@ -429,7 +428,7 @@ namespace SabreTools.Library.DatItems
|
||||
{
|
||||
Name = name;
|
||||
ItemType = ItemType.Rom;
|
||||
Size = -1;
|
||||
Size = null;
|
||||
ItemStatus = ItemStatus.None;
|
||||
|
||||
Machine = new Machine
|
||||
@@ -446,7 +445,7 @@ namespace SabreTools.Library.DatItems
|
||||
public Rom(BaseFile baseFile)
|
||||
{
|
||||
Name = baseFile.Filename;
|
||||
Size = baseFile.Size ?? -1;
|
||||
Size = baseFile.Size;
|
||||
_crc = baseFile.CRC;
|
||||
_md5 = baseFile.MD5;
|
||||
#if NET_FRAMEWORK
|
||||
@@ -540,7 +539,7 @@ namespace SabreTools.Library.DatItems
|
||||
}
|
||||
|
||||
// If we have a file that has no known size, rely on the hashes only
|
||||
else if (Size == -1 && HashMatch(newOther))
|
||||
else if (Size == null && HashMatch(newOther))
|
||||
{
|
||||
dupefound = true;
|
||||
}
|
||||
@@ -560,7 +559,7 @@ namespace SabreTools.Library.DatItems
|
||||
/// <param name="other">Rom to fill information from</param>
|
||||
public void FillMissingInformation(Rom other)
|
||||
{
|
||||
if (Size == -1 && other.Size != -1)
|
||||
if (Size == null && other.Size != null)
|
||||
Size = other.Size;
|
||||
|
||||
if (_crc.IsNullOrEmpty() && !other._crc.IsNullOrEmpty())
|
||||
@@ -736,11 +735,11 @@ namespace SabreTools.Library.DatItems
|
||||
return false;
|
||||
|
||||
// Filter on rom size
|
||||
if (filter.DatItem_Size.MatchesNeutral(-1, Size) == false)
|
||||
if (filter.DatItem_Size.MatchesNeutral(null, Size) == false)
|
||||
return false;
|
||||
else if (filter.DatItem_Size.MatchesPositive(-1, Size) == false)
|
||||
else if (filter.DatItem_Size.MatchesPositive(null, Size) == false)
|
||||
return false;
|
||||
else if (filter.DatItem_Size.MatchesNegative(-1, Size) == false)
|
||||
else if (filter.DatItem_Size.MatchesNegative(null, Size) == false)
|
||||
return false;
|
||||
|
||||
// Filter on CRC
|
||||
|
||||
@@ -478,7 +478,7 @@ namespace SabreTools.Library.FileTypes
|
||||
.Concat(Utilities.StringToByteArray(rom.CRC)) // CRC
|
||||
.ToArray();
|
||||
sw.Write(data);
|
||||
sw.Write((ulong)rom.Size); // Long size (Unsigned, Mirrored)
|
||||
sw.Write((ulong)(rom.Size ?? 0)); // Long size (Unsigned, Mirrored)
|
||||
|
||||
// Now create a deflatestream from the input file
|
||||
ZlibBaseStream ds = new ZlibBaseStream(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true);
|
||||
@@ -496,7 +496,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Now write the standard footer
|
||||
sw.Write(Utilities.StringToByteArray(rom.CRC).Reverse().ToArray());
|
||||
sw.Write((uint)rom.Size);
|
||||
sw.Write((uint)(rom.Size ?? 0));
|
||||
|
||||
// Dispose of everything
|
||||
sw.Dispose();
|
||||
|
||||
@@ -342,7 +342,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Copy the input stream to the output
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
tarFile.AddEntry(rom.Name, inputStream, size: rom.Size, modified: usableDate);
|
||||
tarFile.AddEntry(rom.Name, inputStream, size: rom.Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, sort the input files and write out in the correct order
|
||||
@@ -394,7 +394,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Copy the input file to the output
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
tarFile.AddEntry(rom.Name, inputStream, size: rom.Size, modified: usableDate);
|
||||
tarFile.AddEntry(rom.Name, inputStream, size: rom.Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
@@ -514,7 +514,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
tarFile.AddEntry(roms[index].Name, FileExtensions.TryOpenRead(inputFiles[index]), size: roms[index].Size, modified: usableDate);
|
||||
tarFile.AddEntry(roms[index].Name, FileExtensions.TryOpenRead(inputFiles[index]), size: roms[index].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Copy the input file to the output
|
||||
tarFile.AddEntry(roms[-index - 1].Name, FileExtensions.TryOpenRead(inputFiles[-index - 1]), size: roms[-index - 1].Size, modified: usableDate);
|
||||
tarFile.AddEntry(roms[-index - 1].Name, FileExtensions.TryOpenRead(inputFiles[-index - 1]), size: roms[-index - 1].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace SabreTools.Library.Filtering
|
||||
// Rom
|
||||
public FilterItem<string> DatItem_Name { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> DatItem_Bios { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<long> DatItem_Size { get; private set; } = new FilterItem<long>() { Positive = -1, Negative = -1, Neutral = -1 };
|
||||
public FilterItem<long?> DatItem_Size { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
|
||||
public FilterItem<string> DatItem_CRC { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> DatItem_MD5 { get; private set; } = new FilterItem<string>();
|
||||
#if NET_FRAMEWORK
|
||||
@@ -706,7 +706,7 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_Clock:
|
||||
SetOptionalLongFilter(DatItem_Clock, value, negate);
|
||||
SetLongFilter(DatItem_Clock, value, negate);
|
||||
break;
|
||||
|
||||
// Condition
|
||||
@@ -746,11 +746,11 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_Player:
|
||||
SetOptionalLongFilter(DatItem_Control_Player, value, negate);
|
||||
SetLongFilter(DatItem_Control_Player, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_Buttons:
|
||||
SetOptionalLongFilter(DatItem_Control_Buttons, value, negate);
|
||||
SetLongFilter(DatItem_Control_Buttons, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_RegButtons:
|
||||
@@ -758,19 +758,19 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_Minimum:
|
||||
SetOptionalLongFilter(DatItem_Control_Minimum, value, negate);
|
||||
SetLongFilter(DatItem_Control_Minimum, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_Maximum:
|
||||
SetOptionalLongFilter(DatItem_Control_Maximum, value, negate);
|
||||
SetLongFilter(DatItem_Control_Maximum, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_Sensitivity:
|
||||
SetOptionalLongFilter(DatItem_Control_Sensitivity, value, negate);
|
||||
SetLongFilter(DatItem_Control_Sensitivity, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_KeyDelta:
|
||||
SetOptionalLongFilter(DatItem_Control_KeyDelta, value, negate);
|
||||
SetLongFilter(DatItem_Control_KeyDelta, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Control_Reverse:
|
||||
@@ -795,11 +795,11 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_AreaSize:
|
||||
SetOptionalLongFilter(DatItem_AreaSize, value, negate);
|
||||
SetLongFilter(DatItem_AreaSize, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_AreaWidth:
|
||||
SetOptionalLongFilter(DatItem_AreaWidth, value, negate);
|
||||
SetLongFilter(DatItem_AreaWidth, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_AreaEndianness:
|
||||
@@ -835,7 +835,7 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_Rotate:
|
||||
SetOptionalLongFilter(DatItem_Rotate, value, negate);
|
||||
SetLongFilter(DatItem_Rotate, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_FlipX:
|
||||
@@ -843,11 +843,11 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_Width:
|
||||
SetOptionalLongFilter(DatItem_Width, value, negate);
|
||||
SetLongFilter(DatItem_Width, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Height:
|
||||
SetOptionalLongFilter(DatItem_Height, value, negate);
|
||||
SetLongFilter(DatItem_Height, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Refresh:
|
||||
@@ -855,31 +855,31 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_PixClock:
|
||||
SetOptionalLongFilter(DatItem_PixClock, value, negate);
|
||||
SetLongFilter(DatItem_PixClock, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_HTotal:
|
||||
SetOptionalLongFilter(DatItem_HTotal, value, negate);
|
||||
SetLongFilter(DatItem_HTotal, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_HBEnd:
|
||||
SetOptionalLongFilter(DatItem_HBEnd, value, negate);
|
||||
SetLongFilter(DatItem_HBEnd, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_HBStart:
|
||||
SetOptionalLongFilter(DatItem_HBStart, value, negate);
|
||||
SetLongFilter(DatItem_HBStart, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_VTotal:
|
||||
SetOptionalLongFilter(DatItem_VTotal, value, negate);
|
||||
SetLongFilter(DatItem_VTotal, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_VBEnd:
|
||||
SetOptionalLongFilter(DatItem_VBEnd, value, negate);
|
||||
SetLongFilter(DatItem_VBEnd, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_VBStart:
|
||||
SetOptionalLongFilter(DatItem_VBStart, value, negate);
|
||||
SetLongFilter(DatItem_VBStart, value, negate);
|
||||
break;
|
||||
|
||||
// Driver
|
||||
@@ -948,11 +948,11 @@ namespace SabreTools.Library.Filtering
|
||||
break;
|
||||
|
||||
case Field.DatItem_Players:
|
||||
SetOptionalLongFilter(DatItem_Players, value, negate);
|
||||
SetLongFilter(DatItem_Players, value, negate);
|
||||
break;
|
||||
|
||||
case Field.DatItem_Coins:
|
||||
SetOptionalLongFilter(DatItem_Coins, value, negate);
|
||||
SetLongFilter(DatItem_Coins, value, negate);
|
||||
break;
|
||||
|
||||
// Instance
|
||||
@@ -1045,7 +1045,7 @@ namespace SabreTools.Library.Filtering
|
||||
|
||||
// Sound
|
||||
case Field.DatItem_Channels:
|
||||
SetOptionalLongFilter(DatItem_Channels, value, negate);
|
||||
SetLongFilter(DatItem_Channels, value, negate);
|
||||
break;
|
||||
|
||||
#endregion
|
||||
@@ -1128,72 +1128,13 @@ namespace SabreTools.Library.Filtering
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a long filter
|
||||
/// </summary>
|
||||
/// <param name="filterItem">FilterItem to populate</param>
|
||||
/// <param name="value">String value to add</param>
|
||||
/// <param name="negate">True to set negative filter, false otherwise</param>
|
||||
/// TODO: Can anything using this go with SetOptionalLongFilter instead?
|
||||
private void SetLongFilter(FilterItem<long> filterItem, string value, bool negate)
|
||||
{
|
||||
bool? operation = null;
|
||||
if (value.StartsWith(">"))
|
||||
operation = true;
|
||||
else if (value.StartsWith("<"))
|
||||
operation = false;
|
||||
else if (value.StartsWith("="))
|
||||
operation = null;
|
||||
|
||||
string valueString = value.TrimStart('>', '<', '=');
|
||||
if (!Int64.TryParse(valueString, out long valueLong))
|
||||
return;
|
||||
|
||||
// Equal
|
||||
if (operation == null && !negate)
|
||||
{
|
||||
filterItem.Neutral = valueLong;
|
||||
}
|
||||
|
||||
// Not Equal
|
||||
else if (operation == null && negate)
|
||||
{
|
||||
filterItem.Negative = valueLong - 1;
|
||||
filterItem.Positive = valueLong + 1;
|
||||
}
|
||||
|
||||
// Greater Than or Equal
|
||||
else if (operation == true && !negate)
|
||||
{
|
||||
filterItem.Positive = valueLong;
|
||||
}
|
||||
|
||||
// Strictly Less Than
|
||||
else if (operation == true && negate)
|
||||
{
|
||||
filterItem.Negative = valueLong - 1;
|
||||
}
|
||||
|
||||
// Less Than or Equal
|
||||
else if (operation == false && !negate)
|
||||
{
|
||||
filterItem.Negative = valueLong;
|
||||
}
|
||||
|
||||
// Strictly Greater Than
|
||||
else if (operation == false && negate)
|
||||
{
|
||||
filterItem.Positive = valueLong + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a long? filter
|
||||
/// </summary>
|
||||
/// <param name="filterItem">FilterItem to populate</param>
|
||||
/// <param name="value">String value to add</param>
|
||||
/// <param name="negate">True to set negative filter, false otherwise</param>
|
||||
private void SetOptionalLongFilter(FilterItem<long?> filterItem, string value, bool negate)
|
||||
private void SetLongFilter(FilterItem<long?> filterItem, string value, bool negate)
|
||||
{
|
||||
bool? operation = null;
|
||||
if (value.StartsWith(">"))
|
||||
|
||||
@@ -158,27 +158,19 @@ namespace SabreTools.Library.Skippers
|
||||
{
|
||||
string offset = xtr.GetAttribute("start_offset");
|
||||
if (offset.ToLowerInvariant() == "eof")
|
||||
{
|
||||
rule.StartOffset = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
rule.StartOffset = Convert.ToInt64(offset, 16);
|
||||
}
|
||||
}
|
||||
|
||||
if (xtr.GetAttribute("end_offset") != null)
|
||||
{
|
||||
string offset = xtr.GetAttribute("end_offset");
|
||||
if (offset.ToLowerInvariant() == "eof")
|
||||
{
|
||||
rule.EndOffset = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
rule.EndOffset = Convert.ToInt64(offset, 16);
|
||||
}
|
||||
}
|
||||
|
||||
if (xtr.GetAttribute("operation") != null)
|
||||
{
|
||||
|
||||
@@ -202,15 +202,18 @@ namespace SabreTools.Library.Tools
|
||||
/// Get a sanitized size from an input string
|
||||
/// </summary>
|
||||
/// <param name="input">String to get value from</param>
|
||||
/// <returns>Size as a long, if possible</returns>
|
||||
public static long CleanSize(string input)
|
||||
/// <returns>Size as a long?, if possible</returns>
|
||||
public static long? CleanLong(string input)
|
||||
{
|
||||
long size = -1;
|
||||
long? size = null;
|
||||
if (input != null && input.Contains("0x"))
|
||||
size = Convert.ToInt64(input, 16);
|
||||
|
||||
else if (input != null)
|
||||
Int64.TryParse(input, out size);
|
||||
{
|
||||
if (Int64.TryParse(input, out long longSize))
|
||||
size = longSize;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user