Extra merge tag code

This commit is contained in:
Matt Nadareski
2020-07-23 15:45:14 -07:00
parent ef71eea353
commit 151b0b4a79
3 changed files with 47 additions and 6 deletions

View File

@@ -1574,7 +1574,7 @@ namespace SabreTools.Library.DatFiles
continue; continue;
// If the game (is/is not) a bios, we want to continue // If the game (is/is not) a bios, we want to continue
if (dev ^ (datFile[game][0].MachineType.HasFlag(Data.MachineType.Device))) if (dev ^ (datFile[game][0].MachineType.HasFlag(MachineType.Device)))
continue; continue;
// If the game has no devices, we continue // If the game has no devices, we continue
@@ -1736,14 +1736,33 @@ namespace SabreTools.Library.DatFiles
foreach (DatItem item in items) foreach (DatItem item in items)
{ {
// If the disk doesn't have a valid merge tag OR the merged file doesn't exist in the parent, then add it // If the disk doesn't have a valid merge tag OR the merged file doesn't exist in the parent, then add it
if (item.ItemType == Data.ItemType.Disk && (((Disk)item).MergeTag == null || !datFile[parent].Select(i => i.Name).Contains(((Disk)item).MergeTag))) if (item.ItemType == ItemType.Disk && (((Disk)item).MergeTag == null || !datFile[parent].Select(i => i.Name).Contains(((Disk)item).MergeTag)))
{ {
// Rename the child so it's in a subfolder
item.Name = $"{item.MachineName}\\{item.Name}";
// Update the machine to be the new parent
item.CopyMachineInformation(copyFrom); item.CopyMachineInformation(copyFrom);
// Add the rom to the parent set
datFile.Add(parent, item);
}
// If the rom doesn't have a valid merge tag OR the merged file doesn't exist in the parent, then add it
else if (item.ItemType == ItemType.Rom && (((Rom)item).MergeTag == null || !datFile[parent].Select(i => i.Name).Contains(((Rom)item).MergeTag)))
{
// Rename the child so it's in a subfolder
item.Name = $"{item.MachineName}\\{item.Name}";
// Update the machine to be the new parent
item.CopyMachineInformation(copyFrom);
// Add the rom to the parent set
datFile.Add(parent, item); datFile.Add(parent, item);
} }
// Otherwise, if the parent doesn't already contain the non-disk (or a merge-equivalent), add it // Otherwise, if the parent doesn't already contain the non-disk (or a merge-equivalent), add it
else if (item.ItemType != Data.ItemType.Disk && !datFile[parent].Contains(item)) else if (item.ItemType != ItemType.Disk && !datFile[parent].Contains(item))
{ {
// Rename the child so it's in a subfolder // Rename the child so it's in a subfolder
item.Name = $"{item.MachineName}\\{item.Name}"; item.Name = $"{item.MachineName}\\{item.Name}";
@@ -1771,8 +1790,8 @@ namespace SabreTools.Library.DatFiles
foreach (string game in games) foreach (string game in games)
{ {
if (datFile[game].Count > 0 if (datFile[game].Count > 0
&& (datFile[game][0].MachineType.HasFlag(Data.MachineType.Bios) && (datFile[game][0].MachineType.HasFlag(MachineType.Bios)
|| datFile[game][0].MachineType.HasFlag(Data.MachineType.Device))) || datFile[game][0].MachineType.HasFlag(MachineType.Device)))
{ {
datFile.Remove(game); datFile.Remove(game);
} }
@@ -1795,7 +1814,7 @@ namespace SabreTools.Library.DatFiles
continue; continue;
// If the game (is/is not) a bios, we want to continue // If the game (is/is not) a bios, we want to continue
if (bios ^ datFile[game][0].MachineType.HasFlag(Data.MachineType.Bios)) if (bios ^ datFile[game][0].MachineType.HasFlag(MachineType.Bios))
continue; continue;
// Determine if the game has a parent or not // Determine if the game has a parent or not

View File

@@ -15,7 +15,9 @@ namespace SabreTools.Library.DatItems
#region Private instance variables #region Private instance variables
private byte[] _md5; // 16 bytes private byte[] _md5; // 16 bytes
#if NET_FRAMEWORK
private byte[] _ripemd160; // 20 bytes private byte[] _ripemd160; // 20 bytes
#endif
private byte[] _sha1; // 20 bytes private byte[] _sha1; // 20 bytes
private byte[] _sha256; // 32 bytes private byte[] _sha256; // 32 bytes
private byte[] _sha384; // 48 bytes private byte[] _sha384; // 48 bytes
@@ -200,7 +202,9 @@ namespace SabreTools.Library.DatItems
IndexSource = this.IndexSource, IndexSource = this.IndexSource,
_md5 = this._md5, _md5 = this._md5,
#if NET_FRAMEWORK
_ripemd160 = this._ripemd160, _ripemd160 = this._ripemd160,
#endif
_sha1 = this._sha1, _sha1 = this._sha1,
_sha256 = this._sha256, _sha256 = this._sha256,
_sha384 = this._sha384, _sha384 = this._sha384,
@@ -289,7 +293,9 @@ namespace SabreTools.Library.DatItems
if ((this.ItemStatus == ItemStatus.Nodump && newOther.ItemStatus == ItemStatus.Nodump) if ((this.ItemStatus == ItemStatus.Nodump && newOther.ItemStatus == ItemStatus.Nodump)
&& (this.Name == newOther.Name) && (this.Name == newOther.Name)
&& (this._md5.IsNullOrEmpty() && newOther._md5.IsNullOrEmpty()) && (this._md5.IsNullOrEmpty() && newOther._md5.IsNullOrEmpty())
#if NET_FRAMEWORK
&& (this._ripemd160.IsNullOrEmpty() && newOther._ripemd160.IsNullOrEmpty()) && (this._ripemd160.IsNullOrEmpty() && newOther._ripemd160.IsNullOrEmpty())
#endif
&& (this._sha1.IsNullOrEmpty() && newOther._sha1.IsNullOrEmpty()) && (this._sha1.IsNullOrEmpty() && newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() && newOther._sha256.IsNullOrEmpty()) && (this._sha256.IsNullOrEmpty() && newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() && newOther._sha384.IsNullOrEmpty()) && (this._sha384.IsNullOrEmpty() && newOther._sha384.IsNullOrEmpty())
@@ -300,7 +306,9 @@ namespace SabreTools.Library.DatItems
// If we can determine that the disks have no non-empty hashes in common, we return false // If we can determine that the disks have no non-empty hashes in common, we return false
else if ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) else if ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty())
#if NET_FRAMEWORK
&& (this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) && (this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty())
#endif
&& (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) && (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) && (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) && (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty())
@@ -311,7 +319,9 @@ namespace SabreTools.Library.DatItems
// Otherwise if we get a partial match // Otherwise if we get a partial match
else if (((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5)) else if (((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
#if NET_FRAMEWORK
&& ((this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160)) && ((this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
#endif
&& ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1)) && ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1))
&& ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256)) && ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256))
&& ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384)) && ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))

View File

@@ -16,7 +16,9 @@ namespace SabreTools.Library.DatItems
private byte[] _crc; // 8 bytes private byte[] _crc; // 8 bytes
private byte[] _md5; // 16 bytes private byte[] _md5; // 16 bytes
#if NET_FRAMEWORK
private byte[] _ripemd160; // 20 bytes private byte[] _ripemd160; // 20 bytes
#endif
private byte[] _sha1; // 20 bytes private byte[] _sha1; // 20 bytes
private byte[] _sha256; // 32 bytes private byte[] _sha256; // 32 bytes
private byte[] _sha384; // 48 bytes private byte[] _sha384; // 48 bytes
@@ -249,7 +251,9 @@ namespace SabreTools.Library.DatItems
Size = this.Size, Size = this.Size,
_crc = this._crc, _crc = this._crc,
_md5 = this._md5, _md5 = this._md5,
#if NET_FRAMEWORK
_ripemd160 = this._ripemd160, _ripemd160 = this._ripemd160,
#endif
_sha1 = this._sha1, _sha1 = this._sha1,
_sha256 = this._sha256, _sha256 = this._sha256,
_sha384 = this._sha384, _sha384 = this._sha384,
@@ -279,7 +283,9 @@ namespace SabreTools.Library.DatItems
&& (this.Name == newOther.Name) && (this.Name == newOther.Name)
&& (this._crc.IsNullOrEmpty() && newOther._crc.IsNullOrEmpty()) && (this._crc.IsNullOrEmpty() && newOther._crc.IsNullOrEmpty())
&& (this._md5.IsNullOrEmpty() && newOther._md5.IsNullOrEmpty()) && (this._md5.IsNullOrEmpty() && newOther._md5.IsNullOrEmpty())
#if NET_FRAMEWORK
&& (this._ripemd160.IsNullOrEmpty() && newOther._ripemd160.IsNullOrEmpty()) && (this._ripemd160.IsNullOrEmpty() && newOther._ripemd160.IsNullOrEmpty())
#endif
&& (this._sha1.IsNullOrEmpty() && newOther._sha1.IsNullOrEmpty()) && (this._sha1.IsNullOrEmpty() && newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() && newOther._sha256.IsNullOrEmpty()) && (this._sha256.IsNullOrEmpty() && newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() && newOther._sha384.IsNullOrEmpty()) && (this._sha384.IsNullOrEmpty() && newOther._sha384.IsNullOrEmpty())
@@ -291,7 +297,9 @@ namespace SabreTools.Library.DatItems
// If we can determine that the roms have no non-empty hashes in common, we return false // If we can determine that the roms have no non-empty hashes in common, we return false
else if ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty()) else if ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty())
&& (this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) && (this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty())
#if NET_FRAMEWORK
&& (this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) && (this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty())
#endif
&& (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) && (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) && (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) && (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty())
@@ -304,7 +312,9 @@ namespace SabreTools.Library.DatItems
else if ((this.Size == -1) else if ((this.Size == -1)
&& ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._crc, newOther._crc)) && ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._crc, newOther._crc))
&& ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5)) && ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
#if NET_FRAMEWORK
&& ((this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160)) && ((this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
#endif
&& ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1)) && ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1))
&& ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256)) && ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256))
&& ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384)) && ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))
@@ -317,7 +327,9 @@ namespace SabreTools.Library.DatItems
else if ((this.Size == newOther.Size) else if ((this.Size == newOther.Size)
&& ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._crc, newOther._crc)) && ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._crc, newOther._crc))
&& ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5)) && ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
#if NET_FRAMEWORK
&& ((this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160)) && ((this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
#endif
&& ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1)) && ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1))
&& ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256)) && ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256))
&& ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384)) && ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))