Remove .NET Framework 4.6.2/4.7.2 (#24)

* Remove < .NET 4.8, general cleanup

* Abstract

* Tango

* Banner

* Scan no more

* Common

* Application

* Access

* Filter-feeder

* Graffiti

* Paint-over

* Law and Order

* XOR-o

* Unused staircase

* Maybe

* Maybe not

* Delete this

* The word is "no"

* Emit

* Improper

* Aye aye

* Fence

* Barrier

* Monkey

* Pail

* Lines
This commit is contained in:
Matt Nadareski
2020-07-15 09:41:59 -07:00
committed by GitHub
parent 1a718a3915
commit 4e406604c2
82 changed files with 8975 additions and 11172 deletions

View File

@@ -54,10 +54,8 @@ namespace SabreTools.Library.DatItems
Devices = this.Devices,
MachineType = this.MachineType,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
};
}

View File

@@ -71,10 +71,8 @@ namespace SabreTools.Library.DatItems
Devices = this.Devices,
MachineType = this.MachineType,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
Description = this.Description,
Default = this.Default,

View File

@@ -54,10 +54,8 @@ namespace SabreTools.Library.DatItems
Devices = this.Devices,
MachineType = this.MachineType,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
};
}

View File

@@ -2,9 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.FileTypes;
using SabreTools.Library.Tools;
using NaturalSort;
using Newtonsoft.Json;
@@ -558,28 +559,16 @@ namespace SabreTools.Library.DatItems
#region Source metadata information
/// <summary>
/// Internal system ID for organization
/// Internal DatFile index for organization
/// </summary>
[JsonIgnore]
public int SystemID { get; set; }
public int IndexId { get; set; }
/// <summary>
/// Internal system name for organization
/// Internal DatFile name for organization
/// </summary>
[JsonIgnore]
public string System { get; set; }
/// <summary>
/// Internal source ID for organization
/// </summary>
[JsonIgnore]
public int SourceID { get; set; }
/// <summary>
/// Internal source name for organization
/// </summary>
[JsonIgnore]
public string Source { get; set; }
public string IndexSource { get; set; }
/// <summary>
/// Flag if item should be removed
@@ -698,12 +687,14 @@ namespace SabreTools.Library.DatItems
else if (ItemType == ItemType.Rom)
fieldValue = (this as Rom).MD5;
break;
#if NET_FRAMEWORK
case Field.RIPEMD160:
if (ItemType == ItemType.Disk)
fieldValue = (this as Disk).RIPEMD160;
else if (ItemType == ItemType.Rom)
fieldValue = (this as Rom).RIPEMD160;
break;
#endif
case Field.SHA1:
if (ItemType == ItemType.Disk)
fieldValue = (this as Disk).SHA1;
@@ -805,6 +796,90 @@ namespace SabreTools.Library.DatItems
#endregion
#region Constructors
/// <summary>
/// Create a specific type of DatItem to be used based on an ItemType
/// </summary>
/// <param name="itemType">Type of the DatItem to be created</param>
/// <returns>DatItem of the specific internal type that corresponds to the inputs</returns>
public static DatItem Create(ItemType itemType)
{
#if NET_FRAMEWORK
switch (itemType)
{
case ItemType.Archive:
return new Archive();
case ItemType.BiosSet:
return new BiosSet();
case ItemType.Blank:
return new Blank();
case ItemType.Disk:
return new Disk();
case ItemType.Release:
return new Release();
case ItemType.Rom:
return new Rom();
case ItemType.Sample:
return new Sample();
default:
return new Rom();
}
#else
return itemType switch
{
ItemType.Archive => new Archive(),
ItemType.BiosSet => new BiosSet(),
ItemType.Blank => new Blank(),
ItemType.Disk => new Disk(),
ItemType.Release => new Release(),
ItemType.Rom => new Rom(),
ItemType.Sample => new Sample(),
_ => new Rom(),
};
#endif
}
/// <summary>
/// Create a specific type of DatItem to be used based on a BaseFile
/// </summary>
/// <param name="baseFile">BaseFile containing information to be created</param>
/// <returns>DatItem of the specific internal type that corresponds to the inputs</returns>
public static DatItem Create(BaseFile baseFile)
{
switch (baseFile.Type)
{
case FileType.CHD:
return new Disk(baseFile);
case FileType.GZipArchive:
case FileType.LRZipArchive:
case FileType.LZ4Archive:
case FileType.None:
case FileType.RarArchive:
case FileType.SevenZipArchive:
case FileType.TapeArchive:
case FileType.XZArchive:
case FileType.ZipArchive:
case FileType.ZPAQArchive:
case FileType.ZstdArchive:
return new Rom(baseFile);
case FileType.Folder:
default:
return null;
}
}
#endregion
#region Cloning Methods
/// <summary>
@@ -837,21 +912,17 @@ namespace SabreTools.Library.DatItems
public int CompareTo(DatItem other)
{
int ret = 0;
try
{
if (this.Name == other.Name)
ret = (this.Equals(other) ? 0 : 1);
return this.Equals(other) ? 0 : 1;
ret = String.Compare(this.Name, other.Name);
return String.Compare(this.Name, other.Name);
}
catch
{
ret = 1;
return 1;
}
return ret;
}
/// <summary>
@@ -875,7 +946,7 @@ namespace SabreTools.Library.DatItems
return output;
// If the duplicate is external already or should be, set it
if ((lastItem.DupeType & DupeType.External) != 0 || lastItem.SystemID != this.SystemID || lastItem.SourceID != this.SourceID)
if (lastItem.DupeType.HasFlag(DupeType.External) || lastItem.IndexId != this.IndexId)
{
if (lastItem.MachineName == this.MachineName && lastItem.Name == this.Name)
output = DupeType.External | DupeType.All;
@@ -900,94 +971,96 @@ namespace SabreTools.Library.DatItems
#region Sorting and Merging
/// <summary>
/// Check if a DAT contains the given rom
/// Get the dictionary key that should be used for a given item and sorting type
/// </summary>
/// <param name="datdata">Dat to match against</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>True if it contains the rom, false otherwise</returns>
public bool HasDuplicates(DatFile datdata, bool sorted = false)
/// <param name="sortedBy">BucketedBy enum representing what key to get</param>
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
/// <returns>String representing the key to be used for the DatItem</returns>
public string GetKey(BucketedBy sortedBy, bool lower = true, bool norename = true)
{
// Check for an empty rom list first
if (datdata.Count == 0)
return false;
// Set the output key as the default blank string
string key = string.Empty;
// We want to get the proper key for the DatItem
string key = SortAndGetKey(datdata, sorted);
// If the key doesn't exist, return the empty list
if (!datdata.Contains(key))
return false;
// Try to find duplicates
List<DatItem> roms = datdata[key];
return roms.Any(r => this.Equals(r));
}
/// <summary>
/// List all duplicates found in a DAT based on a rom
/// </summary>
/// <param name="datdata">Dat to match against</param>
/// <param name="remove">True to mark matched roms for removal from the input, false otherwise (default)</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>List of matched DatItem objects</returns>
public List<DatItem> GetDuplicates(DatFile datdata, bool remove = false, bool sorted = false)
{
List<DatItem> output = new List<DatItem>();
// Check for an empty rom list first
if (datdata.Count == 0)
return output;
// We want to get the proper key for the DatItem
string key = SortAndGetKey(datdata, sorted);
// If the key doesn't exist, return the empty list
if (!datdata.Contains(key))
return output;
// Try to find duplicates
List<DatItem> roms = datdata[key];
List<DatItem> left = new List<DatItem>();
for (int i = 0; i < roms.Count; i++)
// Now determine what the key should be based on the sortedBy value
switch (sortedBy)
{
DatItem datItem = roms[i];
case BucketedBy.CRC:
key = (this.ItemType == ItemType.Rom ? ((Rom)this).CRC : Constants.CRCZero);
break;
if (this.Equals(datItem))
{
datItem.Remove = true;
output.Add(datItem);
}
else
{
left.Add(datItem);
}
case BucketedBy.Game:
key = (norename ? string.Empty
: this.IndexId.ToString().PadLeft(10, '0')
+ "-")
+ (string.IsNullOrWhiteSpace(this.MachineName)
? "Default"
: this.MachineName);
if (lower)
key = key.ToLowerInvariant();
if (key == null)
key = "null";
key = WebUtility.HtmlEncode(key);
break;
case BucketedBy.MD5:
key = (this.ItemType == ItemType.Rom
? ((Rom)this).MD5
: (this.ItemType == ItemType.Disk
? ((Disk)this).MD5
: Constants.MD5Zero));
break;
#if NET_FRAMEWORK
case BucketedBy.RIPEMD160:
key = (this.ItemType == ItemType.Rom
? ((Rom)this).RIPEMD160
: (this.ItemType == ItemType.Disk
? ((Disk)this).RIPEMD160
: Constants.RIPEMD160Zero));
break;
#endif
case BucketedBy.SHA1:
key = (this.ItemType == ItemType.Rom
? ((Rom)this).SHA1
: (this.ItemType == ItemType.Disk
? ((Disk)this).SHA1
: Constants.SHA1Zero));
break;
case BucketedBy.SHA256:
key = (this.ItemType == ItemType.Rom
? ((Rom)this).SHA256
: (this.ItemType == ItemType.Disk
? ((Disk)this).SHA256
: Constants.SHA256Zero));
break;
case BucketedBy.SHA384:
key = (this.ItemType == ItemType.Rom
? ((Rom)this).SHA384
: (this.ItemType == ItemType.Disk
? ((Disk)this).SHA384
: Constants.SHA384Zero));
break;
case BucketedBy.SHA512:
key = (this.ItemType == ItemType.Rom
? ((Rom)this).SHA512
: (this.ItemType == ItemType.Disk
? ((Disk)this).SHA512
: Constants.SHA512Zero));
break;
}
// If we're in removal mode, add back all roms with the proper flags
if (remove)
{
datdata.Remove(key);
datdata.AddRange(key, output);
datdata.AddRange(key, left);
}
// Double and triple check the key for corner cases
if (key == null)
key = string.Empty;
return output;
}
/// <summary>
/// Sort the input DAT and get the key to be used by the item
/// </summary>
/// <param name="datdata">Dat to match against</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>Key to try to use</returns>
private string SortAndGetKey(DatFile datdata, bool sorted = false)
{
// If we're not already sorted, take care of it
if (!sorted)
datdata.BucketByBestAvailable();
// Now that we have the sorted type, we get the proper key
return Utilities.GetKeyFromDatItem(this, datdata.SortedBy);
return key;
}
#endregion
@@ -1069,9 +1142,11 @@ namespace SabreTools.Library.DatItems
((Rom)saveditem).MD5 = (string.IsNullOrWhiteSpace(((Rom)saveditem).MD5) && !string.IsNullOrWhiteSpace(((Rom)file).MD5)
? ((Rom)file).MD5
: ((Rom)saveditem).MD5);
#if NET_FRAMEWORK
((Rom)saveditem).RIPEMD160 = (string.IsNullOrWhiteSpace(((Rom)saveditem).RIPEMD160) && !string.IsNullOrWhiteSpace(((Rom)file).RIPEMD160)
? ((Rom)file).RIPEMD160
: ((Rom)saveditem).RIPEMD160);
#endif
((Rom)saveditem).SHA1 = (string.IsNullOrWhiteSpace(((Rom)saveditem).SHA1) && !string.IsNullOrWhiteSpace(((Rom)file).SHA1)
? ((Rom)file).SHA1
: ((Rom)saveditem).SHA1);
@@ -1090,9 +1165,11 @@ namespace SabreTools.Library.DatItems
((Disk)saveditem).MD5 = (string.IsNullOrWhiteSpace(((Disk)saveditem).MD5) && !string.IsNullOrWhiteSpace(((Disk)file).MD5)
? ((Disk)file).MD5
: ((Disk)saveditem).MD5);
#if NET_FRAMEWORK
((Disk)saveditem).RIPEMD160 = (string.IsNullOrWhiteSpace(((Disk)saveditem).RIPEMD160) && !string.IsNullOrWhiteSpace(((Disk)file).RIPEMD160)
? ((Disk)file).RIPEMD160
: ((Disk)saveditem).RIPEMD160);
#endif
((Disk)saveditem).SHA1 = (string.IsNullOrWhiteSpace(((Disk)saveditem).SHA1) && !string.IsNullOrWhiteSpace(((Disk)file).SHA1)
? ((Disk)file).SHA1
: ((Disk)saveditem).SHA1);
@@ -1110,19 +1187,10 @@ namespace SabreTools.Library.DatItems
saveditem.DupeType = dupetype;
// If the current system has a lower ID than the previous, set the system accordingly
if (file.SystemID < saveditem.SystemID)
if (file.IndexId < saveditem.IndexId)
{
saveditem.SystemID = file.SystemID;
saveditem.System = file.System;
saveditem.CopyMachineInformation(file);
saveditem.Name = file.Name;
}
// If the current source has a lower ID than the previous, set the source accordingly
if (file.SourceID < saveditem.SourceID)
{
saveditem.SourceID = file.SourceID;
saveditem.Source = file.Source;
saveditem.IndexId = file.IndexId;
saveditem.IndexSource = file.IndexSource;
saveditem.CopyMachineInformation(file);
saveditem.Name = file.Name;
}
@@ -1185,7 +1253,7 @@ namespace SabreTools.Library.DatItems
}
// If the current item exactly matches the last item, then we don't add it
if ((datItem.GetDuplicateStatus(lastItem) & DupeType.All) != 0)
if (datItem.GetDuplicateStatus(lastItem).HasFlag(DupeType.All))
{
Globals.Logger.Verbose($"Exact duplicate found for '{datItem.Name}'");
continue;
@@ -1199,7 +1267,11 @@ namespace SabreTools.Library.DatItems
if (datItem.ItemType == ItemType.Disk || datItem.ItemType == ItemType.Rom)
{
datItem.Name += GetDuplicateSuffix(datItem);
#if NET_FRAMEWORK
lastrenamed = lastrenamed ?? datItem.Name;
#else
lastrenamed ??= datItem.Name;
#endif
}
// If we have a conflict with the last renamed item, do the right thing
@@ -1281,47 +1353,42 @@ namespace SabreTools.Library.DatItems
try
{
NaturalComparer nc = new NaturalComparer();
if (x.SystemID == y.SystemID)
if (x.IndexId == y.IndexId)
{
if (x.SourceID == y.SourceID)
if (x.MachineName == y.MachineName)
{
if (x.MachineName == y.MachineName)
if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk))
{
if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk))
if (Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)))
{
if (Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name)))
{
return nc.Compare(Path.GetFileName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Utilities.RemovePathUnsafeCharacters(y.Name)));
}
return nc.Compare(Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
}
return nc.Compare(Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name)));
}
else if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType != ItemType.Rom && y.ItemType != ItemType.Disk))
{
return -1;
}
else if ((x.ItemType != ItemType.Rom && x.ItemType != ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk))
{
return 1;
}
else
{
if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name))
{
return nc.Compare(Path.GetFileName(x.Name), Path.GetFileName(y.Name));
}
return nc.Compare(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name));
}
return nc.Compare(Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
}
else if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType != ItemType.Rom && y.ItemType != ItemType.Disk))
{
return -1;
}
else if ((x.ItemType != ItemType.Rom && x.ItemType != ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk))
{
return 1;
}
else
{
if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name))
{
return nc.Compare(Path.GetFileName(x.Name), Path.GetFileName(y.Name));
}
return nc.Compare(x.MachineName, y.MachineName);
return nc.Compare(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name));
}
}
return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.SourceID - y.SourceID);
return nc.Compare(x.MachineName, y.MachineName);
}
return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.SystemID - y.SystemID);
return (norename ? nc.Compare(x.MachineName, y.MachineName) : x.IndexId - y.IndexId);
}
catch (Exception)
{

View File

@@ -31,19 +31,21 @@ namespace SabreTools.Library.DatItems
[JsonProperty("md5")]
public string MD5
{
get { return _md5.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_md5); }
set { _md5 = Utilities.StringToByteArray(value); }
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
set { _md5 = Utilities.StringToByteArray(Sanitizer.CleanMD5(value)); }
}
#if NET_FRAMEWORK
/// <summary>
/// Data RIPEMD160 hash
/// </summary>
[JsonProperty("ripemd160")]
public string RIPEMD160
{
get { return _ripemd160.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_ripemd160); }
set { _ripemd160 = Utilities.StringToByteArray(value); }
get { return _ripemd160.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_ripemd160); }
set { _ripemd160 = Utilities.StringToByteArray(Sanitizer.CleanRIPEMD160(value)); }
}
#endif
/// <summary>
/// Data SHA-1 hash
@@ -51,8 +53,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha1")]
public string SHA1
{
get { return _sha1.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha1); }
set { _sha1 = Utilities.StringToByteArray(value); }
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
set { _sha1 = Utilities.StringToByteArray(Sanitizer.CleanSHA1(value)); }
}
/// <summary>
@@ -61,8 +63,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha256")]
public string SHA256
{
get { return _sha256.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha256); }
set { _sha256 = Utilities.StringToByteArray(value); }
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
set { _sha256 = Utilities.StringToByteArray(Sanitizer.CleanSHA256(value)); }
}
/// <summary>
@@ -71,8 +73,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha384")]
public string SHA384
{
get { return _sha384.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha384); }
set { _sha384 = Utilities.StringToByteArray(value); }
get { return _sha384.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha384); }
set { _sha384 = Utilities.StringToByteArray(Sanitizer.CleanSHA384(value)); }
}
/// <summary>
@@ -81,8 +83,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha512")]
public string SHA512
{
get { return _sha512.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha512); }
set { _sha512 = Utilities.StringToByteArray(value); }
get { return _sha512.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha512); }
set { _sha512 = Utilities.StringToByteArray(Sanitizer.CleanSHA512(value)); }
}
/// <summary>
@@ -144,7 +146,9 @@ namespace SabreTools.Library.DatItems
{
this.Name = baseFile.Filename;
_md5 = baseFile.MD5;
#if NET_FRAMEWORK
_ripemd160 = baseFile.RIPEMD160;
#endif
_sha1 = baseFile.SHA1;
_sha256 = baseFile.SHA256;
_sha384 = baseFile.SHA384;
@@ -191,10 +195,8 @@ namespace SabreTools.Library.DatItems
Devices = this.Devices,
MachineType = this.MachineType,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
_md5 = this._md5,
_ripemd160 = this._ripemd160,
@@ -220,7 +222,9 @@ namespace SabreTools.Library.DatItems
CRC = null,
MD5 = this.MD5,
#if NET_FRAMEWORK
RIPEMD160 = this.RIPEMD160,
#endif
SHA1 = this.SHA1,
SHA256 = this.SHA256,
SHA384 = this.SHA384,
@@ -256,10 +260,8 @@ namespace SabreTools.Library.DatItems
AreaName = this.AreaName,
AreaSize = this.AreaSize,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
Remove = this.Remove,
};
@@ -284,34 +286,34 @@ namespace SabreTools.Library.DatItems
// If all hashes are empty but they're both nodump and the names match, then they're dupes
if ((this.ItemStatus == ItemStatus.Nodump && newOther.ItemStatus == ItemStatus.Nodump)
&& (this.Name == newOther.Name)
&& (this._md5.IsNullOrWhiteSpace() && newOther._md5.IsNullOrWhiteSpace())
&& (this._ripemd160.IsNullOrWhiteSpace() && newOther._ripemd160.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() && newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() && newOther._sha256.IsNullOrWhiteSpace())
&& (this._sha384.IsNullOrWhiteSpace() && newOther._sha384.IsNullOrWhiteSpace())
&& (this._sha512.IsNullOrWhiteSpace() && newOther._sha512.IsNullOrWhiteSpace()))
&& (this._md5.IsNullOrEmpty() && newOther._md5.IsNullOrEmpty())
&& (this._ripemd160.IsNullOrEmpty() && newOther._ripemd160.IsNullOrEmpty())
&& (this._sha1.IsNullOrEmpty() && newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() && newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() && newOther._sha384.IsNullOrEmpty())
&& (this._sha512.IsNullOrEmpty() && newOther._sha512.IsNullOrEmpty()))
{
dupefound = true;
}
// If we can determine that the disks have no non-empty hashes in common, we return false
else if ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace())
&& (this._ripemd160.IsNullOrWhiteSpace() || newOther._ripemd160.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace())
&& (this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace())
&& (this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace()))
else if ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty())
&& (this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty())
&& (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty())
&& (this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty()))
{
dupefound = false;
}
// Otherwise if we get a partial match
else if (((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
&& ((this._ripemd160.IsNullOrWhiteSpace() || newOther._ripemd160.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
&& ((this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1))
&& ((this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256))
&& ((this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))
&& ((this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512)))
else if (((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
&& ((this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
&& ((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._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))
&& ((this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512)))
{
dupefound = true;
}

View File

@@ -87,10 +87,8 @@ namespace SabreTools.Library.DatItems
Devices = this.Devices,
MachineType = this.MachineType,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
Region = this.Region,
Language = this.Language,

View File

@@ -44,8 +44,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("crc")]
public string CRC
{
get { return _crc.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_crc); }
set { _crc = (value == "null" ? Constants.CRCZeroBytes : Utilities.StringToByteArray(value)); }
get { return _crc.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_crc); }
set { _crc = (value == "null" ? Constants.CRCZeroBytes : Utilities.StringToByteArray(Sanitizer.CleanCRC32(value))); }
}
/// <summary>
@@ -54,19 +54,21 @@ namespace SabreTools.Library.DatItems
[JsonProperty("md5")]
public string MD5
{
get { return _md5.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_md5); }
set { _md5 = Utilities.StringToByteArray(value); }
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
set { _md5 = Utilities.StringToByteArray(Sanitizer.CleanMD5(value)); }
}
#if NET_FRAMEWORK
/// <summary>
/// File RIPEMD160 hash
/// </summary>
[JsonProperty("ripemd160")]
public string RIPEMD160
{
get { return _ripemd160.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_ripemd160); }
set { _ripemd160 = Utilities.StringToByteArray(value); }
get { return _ripemd160.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_ripemd160); }
set { _ripemd160 = Utilities.StringToByteArray(Sanitizer.CleanRIPEMD160(value)); }
}
#endif
/// <summary>
/// File SHA-1 hash
@@ -74,8 +76,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha1")]
public string SHA1
{
get { return _sha1.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha1); }
set { _sha1 = Utilities.StringToByteArray(value); }
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
set { _sha1 = Utilities.StringToByteArray(Sanitizer.CleanSHA1(value)); }
}
/// <summary>
@@ -84,8 +86,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha256")]
public string SHA256
{
get { return _sha256.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha256); }
set { _sha256 = Utilities.StringToByteArray(value); }
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
set { _sha256 = Utilities.StringToByteArray(Sanitizer.CleanSHA256(value)); }
}
/// <summary>
@@ -94,8 +96,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha384")]
public string SHA384
{
get { return _sha384.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha384); }
set { _sha384 = Utilities.StringToByteArray(value); }
get { return _sha384.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha384); }
set { _sha384 = Utilities.StringToByteArray(Sanitizer.CleanSHA384(value)); }
}
/// <summary>
@@ -104,8 +106,8 @@ namespace SabreTools.Library.DatItems
[JsonProperty("sha512")]
public string SHA512
{
get { return _sha512.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha512); }
set { _sha512 = Utilities.StringToByteArray(value); }
get { return _sha512.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha512); }
set { _sha512 = Utilities.StringToByteArray(Sanitizer.CleanSHA512(value)); }
}
/// <summary>
@@ -166,34 +168,11 @@ namespace SabreTools.Library.DatItems
/// <param name="name"></param>
/// <param name="machineName"></param>
/// <param name="omitFromScan"></param>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public Rom(string name, string machineName, Hash omitFromScan = Hash.DeepHashes)
public Rom(string name, string machineName)
{
this.Name = name;
this.ItemType = ItemType.Rom;
this.Size = -1;
if ((omitFromScan & Hash.CRC) == 0)
_crc = null;
if ((omitFromScan & Hash.MD5) == 0)
_md5 = null;
if ((omitFromScan & Hash.RIPEMD160) == 0)
_ripemd160 = null;
if ((omitFromScan & Hash.SHA1) == 0)
_sha1 = null;
if ((omitFromScan & Hash.SHA256) == 0)
_sha256 = null;
if ((omitFromScan & Hash.SHA384) == 0)
_sha384 = null;
if ((omitFromScan & Hash.SHA512) == 0)
_sha512 = null;
this.ItemStatus = ItemStatus.None;
_machine = new Machine
@@ -213,7 +192,9 @@ namespace SabreTools.Library.DatItems
this.Size = baseFile.Size ?? -1;
_crc = baseFile.CRC;
_md5 = baseFile.MD5;
#if NET_FRAMEWORK
_ripemd160 = baseFile.RIPEMD160;
#endif
_sha1 = baseFile.SHA1;
_sha256 = baseFile.SHA256;
_sha384 = baseFile.SHA384;
@@ -261,10 +242,8 @@ namespace SabreTools.Library.DatItems
Devices = this.Devices,
MachineType = this.MachineType,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
Size = this.Size,
_crc = this._crc,
@@ -297,51 +276,51 @@ namespace SabreTools.Library.DatItems
// If all hashes are empty but they're both nodump and the names match, then they're dupes
if ((this.ItemStatus == ItemStatus.Nodump && newOther.ItemStatus == ItemStatus.Nodump)
&& (this.Name == newOther.Name)
&& (this._crc.IsNullOrWhiteSpace() && newOther._crc.IsNullOrWhiteSpace())
&& (this._md5.IsNullOrWhiteSpace() && newOther._md5.IsNullOrWhiteSpace())
&& (this._ripemd160.IsNullOrWhiteSpace() && newOther._ripemd160.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() && newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() && newOther._sha256.IsNullOrWhiteSpace())
&& (this._sha384.IsNullOrWhiteSpace() && newOther._sha384.IsNullOrWhiteSpace())
&& (this._sha512.IsNullOrWhiteSpace() && newOther._sha512.IsNullOrWhiteSpace()))
&& (this._crc.IsNullOrEmpty() && newOther._crc.IsNullOrEmpty())
&& (this._md5.IsNullOrEmpty() && newOther._md5.IsNullOrEmpty())
&& (this._ripemd160.IsNullOrEmpty() && newOther._ripemd160.IsNullOrEmpty())
&& (this._sha1.IsNullOrEmpty() && newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() && newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() && newOther._sha384.IsNullOrEmpty())
&& (this._sha512.IsNullOrEmpty() && newOther._sha512.IsNullOrEmpty()))
{
dupefound = true;
}
// If we can determine that the roms have no non-empty hashes in common, we return false
else if ((this._crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace())
&& (this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace())
&& (this._ripemd160.IsNullOrWhiteSpace() || newOther._ripemd160.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace())
&& (this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace())
&& (this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace()))
else if ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty())
&& (this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty())
&& (this._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty())
&& (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty())
&& (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty())
&& (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty())
&& (this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty()))
{
dupefound = false;
}
// If we have a file that has no known size, rely on the hashes only
else if ((this.Size == -1)
&& ((this._crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._crc, newOther._crc))
&& ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
&& ((this._ripemd160.IsNullOrWhiteSpace() || newOther._ripemd160.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
&& ((this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1))
&& ((this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256))
&& ((this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))
&& ((this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512)))
&& ((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._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
&& ((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._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))
&& ((this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512)))
{
dupefound = true;
}
// Otherwise if we get a partial match
else if ((this.Size == newOther.Size)
&& ((this._crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._crc, newOther._crc))
&& ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
&& ((this._ripemd160.IsNullOrWhiteSpace() || newOther._ripemd160.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
&& ((this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1))
&& ((this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256))
&& ((this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))
&& ((this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512)))
&& ((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._ripemd160.IsNullOrEmpty() || newOther._ripemd160.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._ripemd160, newOther._ripemd160))
&& ((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._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384))
&& ((this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512)))
{
dupefound = true;
}

View File

@@ -54,10 +54,8 @@ namespace SabreTools.Library.DatItems
Devices = this.Devices,
MachineType = this.MachineType,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
IndexId = this.IndexId,
IndexSource = this.IndexSource,
};
}