[DatFile] Fix more things that were broken

This commit is contained in:
Matt Nadareski
2017-02-27 20:09:47 -08:00
parent f17a0bc2d4
commit 60ad9f3a61
5 changed files with 76 additions and 95 deletions

View File

@@ -265,7 +265,8 @@ namespace SabreTools.Helper.Data
// Special combinations
Standard = CRC | MD5 | SHA1,
DeepHashes = MD5 | SHA1 | SHA256 | SHA384 | SHA512,
DeepHashes = SHA256 | SHA384 | SHA512,
SecureHashes = MD5 | SHA1 | SHA256 | SHA384 | SHA512,
}
#endregion

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SabreTools.Helper.Data;
using SabreTools.Helper.Tools;
@@ -252,38 +253,28 @@ namespace SabreTools.Helper.Dats
return false;
}
// Get the correct dictionary based on what is available
// How about this: If RomCount + DiskCount = SHA1Count, sort by SHA1
// then if RomCount + DiskCount == MD5Count, sort by MD5 (or make this default for Disk)
// then if RomCount == CRCCount, sort by CRC (or make this default for Rom)
// We assume that we check by CRC for Rom and MD5 for Disk
string key = "";
if (_itemType == ItemType.Rom && ((Rom)this).SHA1 != null)
{
key = ((Rom)this).SHA1;
datdata.BucketBySHA1(false, logger, false);
}
else if (_itemType == ItemType.Disk && ((Disk)this).SHA1 != null)
{
key = ((Disk)this).SHA1;
datdata.BucketBySHA1(false, logger, false);
}
else if (_itemType == ItemType.Rom && ((Rom)this).MD5 != null)
{
key = ((Rom)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
else if (_itemType == ItemType.Disk && ((Disk)this).MD5 != null)
{
key = ((Disk)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
else if (_itemType == ItemType.Rom && ((Rom)this).CRC != null)
// For Roms, we get the CRC
if (_itemType == ItemType.Rom)
{
key = ((Rom)this).CRC;
datdata.BucketByCRC(false, logger, false);
}
else if (_itemType == ItemType.Rom)
// For Disks, we get the MD5
else if (_itemType == ItemType.Disk)
{
key = ((Rom)this).Size.ToString();
datdata.BucketBySize(false, logger, false);
key = ((Disk)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
// Otherwise, we use -1 as the key
else
{
key = "-1";
@@ -327,38 +318,24 @@ namespace SabreTools.Helper.Dats
return output;
}
// Get the correct dictionary based on what is available
// We assume that we check by CRC for Rom and MD5 for Disk
string key = "";
if (_itemType == ItemType.Rom && ((Rom)this).SHA1 != null)
{
key = ((Rom)this).SHA1;
datdata.BucketBySHA1(false, logger, false);
}
else if (_itemType == ItemType.Disk && ((Disk)this).SHA1 != null)
{
key = ((Disk)this).SHA1;
datdata.BucketBySHA1(false, logger, false);
}
else if (_itemType == ItemType.Rom && ((Rom)this).MD5 != null)
{
key = ((Rom)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
else if (_itemType == ItemType.Disk && ((Disk)this).MD5 != null)
{
key = ((Disk)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
else if (_itemType == ItemType.Rom && ((Rom)this).CRC != null)
// For Roms, we get the CRC
if (_itemType == ItemType.Rom)
{
key = ((Rom)this).CRC;
datdata.BucketByCRC(false, logger, false);
}
else if (_itemType == ItemType.Rom)
// For Disks, we get the MD5
else if (_itemType == ItemType.Disk)
{
key = ((Rom)this).Size.ToString();
datdata.BucketBySize(false, logger, false);
key = ((Disk)this).MD5;
datdata.BucketByMD5(false, logger, false);
}
// Otherwise, we use -1 as the key
else
{
key = "-1";

View File

@@ -226,7 +226,7 @@ namespace SabreTools.Helper.Dats
}
// If all deep hash skip flags are set, do a quickscan
if (omitFromScan == Hash.DeepHashes)
if (omitFromScan == Hash.SecureHashes)
{
ArchiveType? type = ArchiveTools.GetCurrentArchiveType(newItem, logger);

View File

@@ -439,80 +439,69 @@ namespace SabreTools.Helper.Dats
// Names are not quoted, for some stupid reason
if (gc[i] == "name")
{
// Advance to the first part of the name
i++;
item.Name = gc[i];
// Advance to the next item, adding until we find "size"
i++;
while (i < gc.Length && gc[i] != "size" && gc[i] != "date" && gc[i] != "crc")
// Get the name in order until we find the next flag
while (++i < gc.Length && gc[i] != "size" && gc[i] != "date" && gc[i] != "crc" && gc[i] != "md5"
&& gc[i] != "sha1" && gc[i] != "sha256" && gc[i] != "sha384" && gc[i] != "sha512")
{
item.Name += " " + gc[i];
i++;
}
// Perform correction
item.Name = item.Name.TrimStart();
i--;
}
// Get the size from the next part
else if (gc[i] == "size")
{
i++;
long tempsize = -1;
if (!Int64.TryParse(gc[i], out tempsize))
if (!Int64.TryParse(gc[++i], out tempsize))
{
tempsize = 0;
}
((Rom)item).Size = tempsize;
i++;
}
// Get the date from the next part
else if (gc[i] == "date")
{
i++;
((Rom)item).Date = gc[i].Replace("\"", "") + " " + gc[i + 1].Replace("\"", "");
i += 3;
((Rom)item).Date = gc[++i].Replace("\"", "") + " " + gc[++i].Replace("\"", "");
}
// Get the CRC from the next part
else if (gc[i] == "crc")
{
i++;
((Rom)item).CRC = gc[i].Replace("\"", "").ToLowerInvariant();
((Rom)item).CRC = gc[++i].Replace("\"", "").ToLowerInvariant();
}
// Get the MD5 from the next part
else if (gc[i] == "md5")
{
i++;
((Rom)item).MD5 = gc[i].Replace("\"", "").ToLowerInvariant();
((Rom)item).MD5 = gc[++i].Replace("\"", "").ToLowerInvariant();
}
// Get the SHA1 from the next part
else if (gc[i] == "sha1")
{
i++;
((Rom)item).SHA1 = gc[i].Replace("\"", "").ToLowerInvariant();
((Rom)item).SHA1 = gc[++i].Replace("\"", "").ToLowerInvariant();
}
// Get the SHA256 from the next part
else if (gc[i] == "sha256")
{
i++;
((Rom)item).SHA256 = gc[i].Replace("\"", "").ToLowerInvariant();
((Rom)item).SHA256 = gc[++i].Replace("\"", "").ToLowerInvariant();
}
// Get the SHA384 from the next part
else if (gc[i] == "sha384")
{
i++;
((Rom)item).SHA384 = gc[i].Replace("\"", "").ToLowerInvariant();
((Rom)item).SHA384 = gc[++i].Replace("\"", "").ToLowerInvariant();
}
// Get the SHA512 from the next part
else if (gc[i] == "sha512")
{
i++;
((Rom)item).SHA512 = gc[i].Replace("\"", "").ToLowerInvariant();
((Rom)item).SHA512 = gc[++i].Replace("\"", "").ToLowerInvariant();
}
}
@@ -3007,6 +2996,13 @@ namespace SabreTools.Helper.Dats
return;
}
// If the name ends with a directory separator, we log and skip it (DOSCenter only?)
if (item.Name.EndsWith("/") || item.Name.EndsWith("\\"))
{
logger.Warning("Rom with directory separator found: '" + item.Name + "'. Skipping...");
return;
}
// If we're in cleaning mode, sanitize the game name
item.Machine.Name = (clean ? Style.CleanGameName(item.Machine.Name) : item.Machine.Name);
@@ -3124,12 +3120,15 @@ namespace SabreTools.Helper.Dats
// Add statistical data
DiskCount += 1;
TotalSize += 0;
MD5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1);
SHA1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1);
SHA256Count += (String.IsNullOrEmpty(((Disk)item).SHA256) ? 0 : 1);
SHA384Count += (String.IsNullOrEmpty(((Disk)item).SHA384) ? 0 : 1);
SHA512Count += (String.IsNullOrEmpty(((Disk)item).SHA512) ? 0 : 1);
if (((Disk)item).ItemStatus != ItemStatus.Nodump)
{
TotalSize += 0;
MD5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1);
SHA1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1);
SHA256Count += (String.IsNullOrEmpty(((Disk)item).SHA256) ? 0 : 1);
SHA384Count += (String.IsNullOrEmpty(((Disk)item).SHA384) ? 0 : 1);
SHA512Count += (String.IsNullOrEmpty(((Disk)item).SHA512) ? 0 : 1);
}
BaddumpCount += (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
NodumpCount += (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
break;
@@ -3138,13 +3137,16 @@ namespace SabreTools.Helper.Dats
// Add statistical data
RomCount += 1;
TotalSize += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 0 : ((Rom)item).Size);
CRCCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1);
MD5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1);
SHA1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1);
SHA256Count += (String.IsNullOrEmpty(((Rom)item).SHA256) ? 0 : 1);
SHA384Count += (String.IsNullOrEmpty(((Rom)item).SHA384) ? 0 : 1);
SHA512Count += (String.IsNullOrEmpty(((Rom)item).SHA512) ? 0 : 1);
if (((Rom)item).ItemStatus != ItemStatus.Nodump)
{
TotalSize += ((Rom)item).Size;
CRCCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1);
MD5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1);
SHA1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1);
SHA256Count += (String.IsNullOrEmpty(((Rom)item).SHA256) ? 0 : 1);
SHA384Count += (String.IsNullOrEmpty(((Rom)item).SHA384) ? 0 : 1);
SHA512Count += (String.IsNullOrEmpty(((Rom)item).SHA512) ? 0 : 1);
}
BaddumpCount += (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
NodumpCount += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
break;

View File

@@ -16,6 +16,7 @@ using SearchOption = System.IO.SearchOption;
namespace SabreTools.Helper.Dats
{
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
public partial class DatFile
{
#region Rebuilding and Verifying [MODULAR DONE, FOR NOW]
@@ -389,7 +390,7 @@ namespace SabreTools.Helper.Dats
// If we're supposed to scan the file externally
if (shouldExternalProcess)
{
Rom rom = FileTools.GetFileInfo(file, logger, omitFromScan: (quickScan ? Hash.DeepHashes : 0x0), header: headerToCheckAgainst);
Rom rom = FileTools.GetFileInfo(file, logger, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), header: headerToCheckAgainst);
usedExternally = RebuildIndividualFile(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
}
@@ -423,7 +424,7 @@ namespace SabreTools.Helper.Dats
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
foreach (string entry in extracted)
{
Rom rom = FileTools.GetFileInfo(entry, logger, omitFromScan: (quickScan ? Hash.DeepHashes : 0x0));
Rom rom = FileTools.GetFileInfo(entry, logger, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes));
usedInternally &= RebuildIndividualFile(rom, entry, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
}
@@ -431,7 +432,7 @@ namespace SabreTools.Helper.Dats
// Otherwise, just get the info on the file itself
else if (File.Exists(file))
{
Rom rom = FileTools.GetFileInfo(file, logger, omitFromScan: (quickScan ? Hash.DeepHashes : 0x0));
Rom rom = FileTools.GetFileInfo(file, logger, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes));
usedExternally = RebuildIndividualFile(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
}
@@ -914,7 +915,7 @@ namespace SabreTools.Helper.Dats
foreach (string input in inputs)
{
// TODO: Eventually migrate noSHA256 to quickScan instead of true
PopulateFromDir(input, (quickScan ? Hash.DeepHashes : 0x0) /* omitFromScan */, true /* bare */, false /* archivesAsFiles */,
PopulateFromDir(input, (quickScan ? Hash.SecureHashes : Hash.DeepHashes) /* omitFromScan */, true /* bare */, false /* archivesAsFiles */,
true /* enableGzip */, false /* addBlanks */, false /* addDate */, tempDir /* tempDir */, false /* copyFiles */,
headerToCheckAgainst, 4 /* maxDegreeOfParallelism */, logger);
}