mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Fix more things that were broken
This commit is contained in:
@@ -265,7 +265,8 @@ namespace SabreTools.Helper.Data
|
|||||||
|
|
||||||
// Special combinations
|
// Special combinations
|
||||||
Standard = CRC | MD5 | SHA1,
|
Standard = CRC | MD5 | SHA1,
|
||||||
DeepHashes = MD5 | SHA1 | SHA256 | SHA384 | SHA512,
|
DeepHashes = SHA256 | SHA384 | SHA512,
|
||||||
|
SecureHashes = MD5 | SHA1 | SHA256 | SHA384 | SHA512,
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
using SabreTools.Helper.Tools;
|
using SabreTools.Helper.Tools;
|
||||||
@@ -252,38 +253,28 @@ namespace SabreTools.Helper.Dats
|
|||||||
return false;
|
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 = "";
|
string key = "";
|
||||||
if (_itemType == ItemType.Rom && ((Rom)this).SHA1 != null)
|
|
||||||
{
|
// For Roms, we get the CRC
|
||||||
key = ((Rom)this).SHA1;
|
if (_itemType == ItemType.Rom)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
key = ((Rom)this).CRC;
|
key = ((Rom)this).CRC;
|
||||||
datdata.BucketByCRC(false, logger, false);
|
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();
|
key = ((Disk)this).MD5;
|
||||||
datdata.BucketBySize(false, logger, false);
|
datdata.BucketByMD5(false, logger, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, we use -1 as the key
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key = "-1";
|
key = "-1";
|
||||||
@@ -327,38 +318,24 @@ namespace SabreTools.Helper.Dats
|
|||||||
return output;
|
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 = "";
|
string key = "";
|
||||||
if (_itemType == ItemType.Rom && ((Rom)this).SHA1 != null)
|
|
||||||
{
|
// For Roms, we get the CRC
|
||||||
key = ((Rom)this).SHA1;
|
if (_itemType == ItemType.Rom)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
key = ((Rom)this).CRC;
|
key = ((Rom)this).CRC;
|
||||||
datdata.BucketByCRC(false, logger, false);
|
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();
|
key = ((Disk)this).MD5;
|
||||||
datdata.BucketBySize(false, logger, false);
|
datdata.BucketByMD5(false, logger, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, we use -1 as the key
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key = "-1";
|
key = "-1";
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If all deep hash skip flags are set, do a quickscan
|
// 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);
|
ArchiveType? type = ArchiveTools.GetCurrentArchiveType(newItem, logger);
|
||||||
|
|
||||||
|
|||||||
@@ -439,80 +439,69 @@ namespace SabreTools.Helper.Dats
|
|||||||
// Names are not quoted, for some stupid reason
|
// Names are not quoted, for some stupid reason
|
||||||
if (gc[i] == "name")
|
if (gc[i] == "name")
|
||||||
{
|
{
|
||||||
// Advance to the first part of the name
|
// Get the name in order until we find the next flag
|
||||||
i++;
|
while (++i < gc.Length && gc[i] != "size" && gc[i] != "date" && gc[i] != "crc" && gc[i] != "md5"
|
||||||
item.Name = gc[i];
|
&& gc[i] != "sha1" && gc[i] != "sha256" && gc[i] != "sha384" && gc[i] != "sha512")
|
||||||
|
|
||||||
// Advance to the next item, adding until we find "size"
|
|
||||||
i++;
|
|
||||||
while (i < gc.Length && gc[i] != "size" && gc[i] != "date" && gc[i] != "crc")
|
|
||||||
{
|
{
|
||||||
item.Name += " " + gc[i];
|
item.Name += " " + gc[i];
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Perform correction
|
||||||
|
item.Name = item.Name.TrimStart();
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the size from the next part
|
// Get the size from the next part
|
||||||
else if (gc[i] == "size")
|
else if (gc[i] == "size")
|
||||||
{
|
{
|
||||||
i++;
|
|
||||||
long tempsize = -1;
|
long tempsize = -1;
|
||||||
if (!Int64.TryParse(gc[i], out tempsize))
|
if (!Int64.TryParse(gc[++i], out tempsize))
|
||||||
{
|
{
|
||||||
tempsize = 0;
|
tempsize = 0;
|
||||||
}
|
}
|
||||||
((Rom)item).Size = tempsize;
|
((Rom)item).Size = tempsize;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the date from the next part
|
// Get the date from the next part
|
||||||
else if (gc[i] == "date")
|
else if (gc[i] == "date")
|
||||||
{
|
{
|
||||||
i++;
|
((Rom)item).Date = gc[++i].Replace("\"", "") + " " + gc[++i].Replace("\"", "");
|
||||||
((Rom)item).Date = gc[i].Replace("\"", "") + " " + gc[i + 1].Replace("\"", "");
|
|
||||||
i += 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the CRC from the next part
|
// Get the CRC from the next part
|
||||||
else if (gc[i] == "crc")
|
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
|
// Get the MD5 from the next part
|
||||||
else if (gc[i] == "md5")
|
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
|
// Get the SHA1 from the next part
|
||||||
else if (gc[i] == "sha1")
|
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
|
// Get the SHA256 from the next part
|
||||||
else if (gc[i] == "sha256")
|
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
|
// Get the SHA384 from the next part
|
||||||
else if (gc[i] == "sha384")
|
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
|
// Get the SHA512 from the next part
|
||||||
else if (gc[i] == "sha512")
|
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;
|
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
|
// If we're in cleaning mode, sanitize the game name
|
||||||
item.Machine.Name = (clean ? Style.CleanGameName(item.Machine.Name) : item.Machine.Name);
|
item.Machine.Name = (clean ? Style.CleanGameName(item.Machine.Name) : item.Machine.Name);
|
||||||
|
|
||||||
@@ -3124,12 +3120,15 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Add statistical data
|
// Add statistical data
|
||||||
DiskCount += 1;
|
DiskCount += 1;
|
||||||
TotalSize += 0;
|
if (((Disk)item).ItemStatus != ItemStatus.Nodump)
|
||||||
MD5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1);
|
{
|
||||||
SHA1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1);
|
TotalSize += 0;
|
||||||
SHA256Count += (String.IsNullOrEmpty(((Disk)item).SHA256) ? 0 : 1);
|
MD5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1);
|
||||||
SHA384Count += (String.IsNullOrEmpty(((Disk)item).SHA384) ? 0 : 1);
|
SHA1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1);
|
||||||
SHA512Count += (String.IsNullOrEmpty(((Disk)item).SHA512) ? 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);
|
BaddumpCount += (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
NodumpCount += (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
NodumpCount += (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
@@ -3138,13 +3137,16 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Add statistical data
|
// Add statistical data
|
||||||
RomCount += 1;
|
RomCount += 1;
|
||||||
TotalSize += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 0 : ((Rom)item).Size);
|
if (((Rom)item).ItemStatus != ItemStatus.Nodump)
|
||||||
CRCCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1);
|
{
|
||||||
MD5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1);
|
TotalSize += ((Rom)item).Size;
|
||||||
SHA1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1);
|
CRCCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1);
|
||||||
SHA256Count += (String.IsNullOrEmpty(((Rom)item).SHA256) ? 0 : 1);
|
MD5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1);
|
||||||
SHA384Count += (String.IsNullOrEmpty(((Rom)item).SHA384) ? 0 : 1);
|
SHA1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1);
|
||||||
SHA512Count += (String.IsNullOrEmpty(((Rom)item).SHA512) ? 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);
|
BaddumpCount += (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
NodumpCount += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
NodumpCount += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using SearchOption = System.IO.SearchOption;
|
|||||||
|
|
||||||
namespace SabreTools.Helper.Dats
|
namespace SabreTools.Helper.Dats
|
||||||
{
|
{
|
||||||
|
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||||
public partial class DatFile
|
public partial class DatFile
|
||||||
{
|
{
|
||||||
#region Rebuilding and Verifying [MODULAR DONE, FOR NOW]
|
#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 we're supposed to scan the file externally
|
||||||
if (shouldExternalProcess)
|
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,
|
usedExternally = RebuildIndividualFile(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
|
||||||
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
||||||
}
|
}
|
||||||
@@ -423,7 +424,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
|
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
|
||||||
foreach (string entry in extracted)
|
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,
|
usedInternally &= RebuildIndividualFile(rom, entry, outDir, tempSubDir, date, inverse, outputFormat,
|
||||||
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
||||||
}
|
}
|
||||||
@@ -431,7 +432,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
// Otherwise, just get the info on the file itself
|
// Otherwise, just get the info on the file itself
|
||||||
else if (File.Exists(file))
|
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,
|
usedExternally = RebuildIndividualFile(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
|
||||||
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
||||||
}
|
}
|
||||||
@@ -914,7 +915,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
// TODO: Eventually migrate noSHA256 to quickScan instead of true
|
// 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 */,
|
true /* enableGzip */, false /* addBlanks */, false /* addDate */, tempDir /* tempDir */, false /* copyFiles */,
|
||||||
headerToCheckAgainst, 4 /* maxDegreeOfParallelism */, logger);
|
headerToCheckAgainst, 4 /* maxDegreeOfParallelism */, logger);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user