[DatFiles/] Clean all hash data

This commit is contained in:
Matt Nadareski
2018-02-21 10:29:57 -08:00
parent 13af2442d3
commit bc059f89fc
9 changed files with 69 additions and 69 deletions

View File

@@ -466,68 +466,68 @@ namespace SabreTools.Library.DatFiles
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Rom)item).CRC = quoteless.ToLowerInvariant(); ((Rom)item).CRC = Utilities.CleanHashData(quoteless, Constants.CRCLength);
} }
break; break;
case "md5": case "md5":
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Rom)item).MD5 = quoteless.ToLowerInvariant(); ((Rom)item).MD5 = Utilities.CleanHashData(quoteless, Constants.MD5Length);
} }
else if (item.Type == ItemType.Disk) else if (item.Type == ItemType.Disk)
{ {
i++; i++;
quoteless = linegc[i].Replace("\"", ""); quoteless = linegc[i].Replace("\"", "");
((Disk)item).MD5 = quoteless.ToLowerInvariant(); ((Disk)item).MD5 = Utilities.CleanHashData(quoteless, Constants.MD5Length);
} }
break; break;
case "sha1": case "sha1":
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Rom)item).SHA1 = quoteless.ToLowerInvariant(); ((Rom)item).SHA1 = Utilities.CleanHashData(quoteless, Constants.SHA1Length);
} }
else if (item.Type == ItemType.Disk) else if (item.Type == ItemType.Disk)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Disk)item).SHA1 = quoteless.ToLowerInvariant(); ((Disk)item).SHA1 = Utilities.CleanHashData(quoteless, Constants.SHA1Length);
} }
break; break;
case "sha256": case "sha256":
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Rom)item).SHA256 = quoteless.ToLowerInvariant(); ((Rom)item).SHA256 = Utilities.CleanHashData(quoteless, Constants.SHA256Length);
} }
else if (item.Type == ItemType.Disk) else if (item.Type == ItemType.Disk)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Disk)item).SHA256 = quoteless.ToLowerInvariant(); ((Disk)item).SHA256 = Utilities.CleanHashData(quoteless, Constants.SHA256Length);
} }
break; break;
case "sha384": case "sha384":
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Rom)item).SHA384 = quoteless.ToLowerInvariant(); ((Rom)item).SHA384 = Utilities.CleanHashData(quoteless, Constants.SHA384Length);
} }
else if (item.Type == ItemType.Disk) else if (item.Type == ItemType.Disk)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Disk)item).SHA384 = quoteless.ToLowerInvariant(); ((Disk)item).SHA384 = Utilities.CleanHashData(quoteless, Constants.SHA384Length);
} }
break; break;
case "sha512": case "sha512":
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Rom)item).SHA512 = quoteless.ToLowerInvariant(); ((Rom)item).SHA512 = Utilities.CleanHashData(quoteless, Constants.SHA512Length);
} }
else if (item.Type == ItemType.Disk) else if (item.Type == ItemType.Disk)
{ {
quoteless = linegc[++i].Replace("\"", ""); quoteless = linegc[++i].Replace("\"", "");
((Disk)item).SHA512 = quoteless.ToLowerInvariant(); ((Disk)item).SHA512 = Utilities.CleanHashData(quoteless, Constants.SHA512Length);
} }
break; break;
case "status": case "status":

View File

@@ -88,12 +88,12 @@ namespace SabreTools.Library.DatFiles
{ {
Name = name, Name = name,
Size = -1, Size = -1,
CRC = ((_hash & Hash.CRC) != 0 ? hash : null), CRC = ((_hash & Hash.CRC) != 0 ? Utilities.CleanHashData(hash, Constants.CRCLength) : null),
MD5 = ((_hash & Hash.MD5) != 0 ? hash : null), MD5 = ((_hash & Hash.MD5) != 0 ? Utilities.CleanHashData(hash, Constants.MD5Length) : null),
SHA1 = ((_hash & Hash.SHA1) != 0 ? hash : null), SHA1 = ((_hash & Hash.SHA1) != 0 ? Utilities.CleanHashData(hash, Constants.SHA1Length) : null),
SHA256 = ((_hash & Hash.SHA256) != 0 ? hash : null), SHA256 = ((_hash & Hash.SHA256) != 0 ? Utilities.CleanHashData(hash, Constants.SHA256Length) : null),
SHA384 = ((_hash & Hash.SHA384) != 0 ? hash : null), SHA384 = ((_hash & Hash.SHA384) != 0 ? Utilities.CleanHashData(hash, Constants.SHA384Length) : null),
SHA512 = ((_hash & Hash.SHA512) != 0 ? hash : null), SHA512 = ((_hash & Hash.SHA512) != 0 ? Utilities.CleanHashData(hash, Constants.SHA512Length) : null),
ItemStatus = ItemStatus.None, ItemStatus = ItemStatus.None,
MachineName = Path.GetFileNameWithoutExtension(filename), MachineName = Path.GetFileNameWithoutExtension(filename),

View File

@@ -239,12 +239,12 @@ namespace SabreTools.Library.DatFiles
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
Bios = reader.GetAttribute("bios"), Bios = reader.GetAttribute("bios"),
Size = Utilities.GetSize(reader.GetAttribute("size")), Size = Utilities.GetSize(reader.GetAttribute("size")),
CRC = reader.GetAttribute("crc")?.ToLowerInvariant(), CRC = Utilities.CleanHashData(reader.GetAttribute("crc"), Constants.CRCLength),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
MergeTag = reader.GetAttribute("merge"), MergeTag = reader.GetAttribute("merge"),
Region = reader.GetAttribute("region"), Region = reader.GetAttribute("region"),
Offset = reader.GetAttribute("offset"), Offset = reader.GetAttribute("offset"),
@@ -269,11 +269,11 @@ namespace SabreTools.Library.DatFiles
DatItem disk = new Disk DatItem disk = new Disk
{ {
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
MergeTag = reader.GetAttribute("merge"), MergeTag = reader.GetAttribute("merge"),
Region = reader.GetAttribute("region"), Region = reader.GetAttribute("region"),
Index = reader.GetAttribute("index"), Index = reader.GetAttribute("index"),

View File

@@ -439,12 +439,12 @@ namespace SabreTools.Library.DatFiles
{ {
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
Size = Utilities.GetSize(reader.GetAttribute("size")), Size = Utilities.GetSize(reader.GetAttribute("size")),
CRC = reader.GetAttribute("crc")?.ToLowerInvariant(), CRC = Utilities.CleanHashData(reader.GetAttribute("crc"), Constants.CRCLength),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
MergeTag = reader.GetAttribute("merge"), MergeTag = reader.GetAttribute("merge"),
ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")), ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")),
Date = Utilities.GetDate(reader.GetAttribute("date")), Date = Utilities.GetDate(reader.GetAttribute("date")),
@@ -467,11 +467,11 @@ namespace SabreTools.Library.DatFiles
DatItem disk = new Disk DatItem disk = new Disk
{ {
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
MergeTag = reader.GetAttribute("merge"), MergeTag = reader.GetAttribute("merge"),
ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")), ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")),

View File

@@ -740,7 +740,7 @@ namespace SabreTools.Library.DatFiles
roms.Add(new Rom() roms.Add(new Rom()
{ {
Name = (releaseNumber != "0" ? releaseNumber + " - " : "") + machineName + pair.Item1, Name = (releaseNumber != "0" ? releaseNumber + " - " : "") + machineName + pair.Item1,
CRC = pair.Item2, CRC = Utilities.CleanHashData(pair.Item2, Constants.CRCLength),
ItemStatus = ItemStatus.None, ItemStatus = ItemStatus.None,
}); });

View File

@@ -174,7 +174,7 @@ namespace SabreTools.Library.DatFiles
{ {
Name = rominfo[5], Name = rominfo[5],
Size = size, Size = size,
CRC = rominfo[6], CRC = Utilities.CleanHashData(rominfo[6], Constants.CRCLength),
ItemStatus = ItemStatus.None, ItemStatus = ItemStatus.None,
MachineName = rominfo[3], MachineName = rominfo[3],

View File

@@ -405,11 +405,11 @@ namespace SabreTools.Library.DatFiles
datItem = new Disk datItem = new Disk
{ {
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
ItemStatus = its, ItemStatus = its,
SystemID = sysid, SystemID = sysid,
@@ -436,12 +436,12 @@ namespace SabreTools.Library.DatFiles
{ {
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
Size = size, Size = size,
CRC = reader.GetAttribute("crc")?.ToLowerInvariant(), CRC = Utilities.CleanHashData(reader.GetAttribute("crc"), Constants.CRCLength),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
ItemStatus = its, ItemStatus = its,
Date = date, Date = date,

View File

@@ -217,22 +217,22 @@ namespace SabreTools.Library.DatFiles
} }
break; break;
case "DatItem.CRC": case "DatItem.CRC":
crc = value; crc = Utilities.CleanHashData(value, Constants.CRCLength);
break; break;
case "DatItem.MD5": case "DatItem.MD5":
md5 = value; md5 = Utilities.CleanHashData(value, Constants.MD5Length);
break; break;
case "DatItem.SHA1": case "DatItem.SHA1":
sha1 = value; sha1 = Utilities.CleanHashData(value, Constants.SHA1Length);
break; break;
case "DatItem.SHA256": case "DatItem.SHA256":
sha256 = value; sha256 = Utilities.CleanHashData(value, Constants.SHA256Length);
break; break;
case "DatItem.SHA384": case "DatItem.SHA384":
sha384 = value; sha384 = Utilities.CleanHashData(value, Constants.SHA384Length);
break; break;
case "DatItem.SHA512": case "DatItem.SHA512":
sha512 = value; sha512 = Utilities.CleanHashData(value, Constants.SHA512Length);
break; break;
case "DatItem.Nodump": case "DatItem.Nodump":
status = Utilities.GetItemStatus(value); status = Utilities.GetItemStatus(value);

View File

@@ -434,12 +434,12 @@ namespace SabreTools.Library.DatFiles
{ {
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
Size = Utilities.GetSize(reader.GetAttribute("size")), Size = Utilities.GetSize(reader.GetAttribute("size")),
CRC = reader.GetAttribute("crc")?.ToLowerInvariant(), CRC = Utilities.CleanHashData(reader.GetAttribute("crc"), Constants.CRCLength),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
Offset = reader.GetAttribute("offset"), Offset = reader.GetAttribute("offset"),
// Value = reader.GetAttribute("value"); // Value = reader.GetAttribute("value");
ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")), ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")),
@@ -529,11 +529,11 @@ namespace SabreTools.Library.DatFiles
DatItem disk = new Disk DatItem disk = new Disk
{ {
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
MD5 = reader.GetAttribute("md5")?.ToLowerInvariant(), MD5 = Utilities.CleanHashData(reader.GetAttribute("md5"), Constants.MD5Length),
SHA1 = reader.GetAttribute("sha1")?.ToLowerInvariant(), SHA1 = Utilities.CleanHashData(reader.GetAttribute("sha1"), Constants.SHA1Length),
SHA256 = reader.GetAttribute("sha256")?.ToLowerInvariant(), SHA256 = Utilities.CleanHashData(reader.GetAttribute("sha256"), Constants.SHA256Length),
SHA384 = reader.GetAttribute("sha384")?.ToLowerInvariant(), SHA384 = Utilities.CleanHashData(reader.GetAttribute("sha384"), Constants.SHA384Length),
SHA512 = reader.GetAttribute("sha512")?.ToLowerInvariant(), SHA512 = Utilities.CleanHashData(reader.GetAttribute("sha512"), Constants.SHA512Length),
ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")), ItemStatus = Utilities.GetItemStatus(reader.GetAttribute("status")),
Writable = Utilities.GetYesNo(reader.GetAttribute("writable")), Writable = Utilities.GetYesNo(reader.GetAttribute("writable")),