Use ByteArrays for hashes (#2)

* [Disk, Rom] Use byte arrays for hashes to save memory

* [Disk, Rom] Use byte arrays for hashes to save memory

* [Disk, Rom] Use byte arrays for hashes to save memory

* [FileTools] Use ByteArrayToString in CHD info

* [ArchiveTools, FileTools] Use the Style method more

* [Disk, Rom] Use byte arrays for hashes to save memory

* [FileTools] Use ByteArrayToString in CHD info

* [ArchiveTools, FileTools] Use the Style method more

* [Disk, Rom] Use byte arrays for hashes to save memory

* [FileTools] Use ByteArrayToString in CHD info

* [ArchiveTools, FileTools] Use the Style method more

* [Disk, Rom] Use byte arrays for hashes to save memory

* [FileTools] Use ByteArrayToString in CHD info

* [ArchiveTools, FileTools] Use the Style method more

* [Disk, Rom] Use byte arrays for hashes to save memory

* [FileTools] Use ByteArrayToString in CHD info

* [ArchiveTools, FileTools] Use the Style method more

* [SabreTools, GZipArchive] Refix some issues from rebase

* # This is a combination of 2 commits.
# This is the 1st commit message:

# This is a combination of 2 commits.
# This is the 1st commit message:

# This is a combination of 2 commits.
# This is the 1st commit message:

# This is a combination of 2 commits.
# This is the 1st commit message:

# This is a combination of 4 commits.
# This is the 1st commit message:

[Disk, Rom] Use byte arrays for hashes to save memory

# This is the commit message #2:

[FileTools] Use ByteArrayToString in CHD info

# This is the commit message #3:

[ArchiveTools, FileTools] Use the Style method more

# This is the commit message #4:

[SabreTools, GZipArchive] Refix some issues from rebase

# This is the commit message #2:

[FileTools] Use ByteArrayToString in CHD info

# This is the commit message #2:

[FileTools] Use ByteArrayToString in CHD info

# This is the commit message #2:

[FileTools] Use ByteArrayToString in CHD info

# This is the commit message #2:

[FileTools] Use ByteArrayToString in CHD info

* [Disk, Rom, Style] Add null or empty check to fix equality check

* [Disk, Rom] Remove unused references

* [Style] Add and implement BinaryReader extensions
This commit is contained in:
Matt Nadareski
2017-11-02 15:35:15 -07:00
committed by GitHub
parent 639f0491bb
commit 6af1547877
7 changed files with 309 additions and 139 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.Tools;
namespace SabreTools.Library.Items
{
@@ -13,12 +14,12 @@ namespace SabreTools.Library.Items
// Rom information
private long _size;
private string _crc;
private string _md5;
private string _sha1;
private string _sha256;
private string _sha384;
private string _sha512;
private byte[] _crc; // 8 bytes
private byte[] _md5; // 16 bytes
private byte[] _sha1; // 20 bytes
private byte[] _sha256; // 32 bytes
private byte[] _sha384; // 48 bytes
private byte[] _sha512; // 64 bytes
private string _date;
private ItemStatus _itemStatus;
@@ -34,33 +35,33 @@ namespace SabreTools.Library.Items
}
public string CRC
{
get { return _crc; }
set { _crc = value; }
get { return _crc.IsNullOrEmpty() ? null : Style.ByteArrayToString(_crc); }
set { _crc = Style.StringToByteArray(value); }
}
public string MD5
{
get { return _md5; }
set { _md5 = value; }
get { return _md5.IsNullOrEmpty() ? null : Style.ByteArrayToString(_md5); }
set { _md5 = Style.StringToByteArray(value); }
}
public string SHA1
{
get { return _sha1; }
set { _sha1 = value; }
get { return _sha1.IsNullOrEmpty() ? null : Style.ByteArrayToString(_sha1); }
set { _sha1 = Style.StringToByteArray(value); }
}
public string SHA256
{
get { return _sha256; }
set { _sha256 = value; }
get { return _sha256.IsNullOrEmpty() ? null : Style.ByteArrayToString(_sha256); }
set { _sha256 = Style.StringToByteArray(value); }
}
public string SHA384
{
get { return _sha384; }
set { _sha384 = value; }
get { return _sha384.IsNullOrEmpty() ? null : Style.ByteArrayToString(_sha384); }
set { _sha384 = Style.StringToByteArray(value); }
}
public string SHA512
{
get { return _sha512; }
set { _sha512 = value; }
get { return _sha512.IsNullOrEmpty() ? null : Style.ByteArrayToString(_sha512); }
set { _sha512 = Style.StringToByteArray(value); }
}
public string Date
{
@@ -103,27 +104,27 @@ namespace SabreTools.Library.Items
_size = -1;
if ((omitFromScan & Hash.CRC) == 0)
{
_crc = "null";
_crc = null;
}
if ((omitFromScan & Hash.MD5) == 0)
{
_md5 = "null";
_md5 = null;
}
if ((omitFromScan & Hash.SHA1) == 0)
{
_sha1 = "null";
_sha1 = null;
}
if ((omitFromScan & Hash.SHA256) == 0)
{
_sha256 = "null";
_sha256 = null;
}
if ((omitFromScan & Hash.SHA384) == 0)
{
_sha384 = "null";
_sha384 = null;
}
if ((omitFromScan & Hash.SHA512) == 0)
{
_sha512 = "null";
_sha512 = null;
}
_itemStatus = ItemStatus.None;
@@ -176,12 +177,12 @@ namespace SabreTools.Library.Items
Source = this.Source,
Size = this.Size,
CRC = this.CRC,
MD5 = this.MD5,
SHA1 = this.SHA1,
SHA256 = this.SHA256,
SHA384 = this.SHA384,
SHA512 = this.SHA512,
_crc = this._crc,
_md5 = this._md5,
_sha1 = this._sha1,
_sha256 = this._sha256,
_sha384 = this._sha384,
_sha512 = this._sha512,
ItemStatus = this.ItemStatus,
Date = this.Date,
};
@@ -211,22 +212,22 @@ namespace SabreTools.Library.Items
}
// If we can determine that the roms have no non-empty hashes in common, we return false
if ((String.IsNullOrEmpty(_crc) || String.IsNullOrEmpty(newOther.CRC))
&& (String.IsNullOrEmpty(_md5) || String.IsNullOrEmpty(newOther.MD5))
&& (String.IsNullOrEmpty(_sha1) || String.IsNullOrEmpty(newOther.SHA1))
&& (String.IsNullOrEmpty(_sha256) || String.IsNullOrEmpty(newOther.SHA256))
&& (String.IsNullOrEmpty(_sha384) || String.IsNullOrEmpty(newOther.SHA384))
&& (String.IsNullOrEmpty(_sha512) || String.IsNullOrEmpty(newOther.SHA512)))
if ((_crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty())
&& (this._md5.IsNullOrEmpty() || newOther._md5.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;
}
else if ((this.Size == newOther.Size)
&& ((String.IsNullOrEmpty(_crc) || String.IsNullOrEmpty(newOther.CRC)) || _crc == newOther.CRC)
&& ((String.IsNullOrEmpty(_md5) || String.IsNullOrEmpty(newOther.MD5)) || _md5 == newOther.MD5)
&& ((String.IsNullOrEmpty(_sha1) || String.IsNullOrEmpty(newOther.SHA1)) || _sha1 == newOther.SHA1)
&& ((String.IsNullOrEmpty(_sha256) || String.IsNullOrEmpty(newOther.SHA256)) || _sha256 == newOther.SHA256)
&& ((String.IsNullOrEmpty(_sha384) || String.IsNullOrEmpty(newOther.SHA384)) || _sha384 == newOther.SHA384)
&& ((String.IsNullOrEmpty(_sha512) || String.IsNullOrEmpty(newOther.SHA512)) || _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._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;
}