mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, OpenMSX] Make sure data is clean for writing
This commit is contained in:
@@ -3265,8 +3265,21 @@ namespace SabreTools.Library.DatFiles
|
|||||||
itemRom.SHA384 = Utilities.CleanHashData(itemRom.SHA384, Constants.SHA384Length);
|
itemRom.SHA384 = Utilities.CleanHashData(itemRom.SHA384, Constants.SHA384Length);
|
||||||
itemRom.SHA512 = Utilities.CleanHashData(itemRom.SHA512, Constants.SHA512Length);
|
itemRom.SHA512 = Utilities.CleanHashData(itemRom.SHA512, Constants.SHA512Length);
|
||||||
|
|
||||||
|
// If we have the case where there is SHA-1 and nothing else, we don't fill in any other part of the data
|
||||||
|
if (itemRom.Size == -1
|
||||||
|
&& String.IsNullOrWhiteSpace(itemRom.CRC)
|
||||||
|
&& String.IsNullOrWhiteSpace(itemRom.MD5)
|
||||||
|
&& !String.IsNullOrWhiteSpace(itemRom.SHA1)
|
||||||
|
&& String.IsNullOrWhiteSpace(itemRom.SHA256)
|
||||||
|
&& String.IsNullOrWhiteSpace(itemRom.SHA384)
|
||||||
|
&& String.IsNullOrWhiteSpace(itemRom.SHA512))
|
||||||
|
{
|
||||||
|
// No-op, just catch it so it doesn't go further
|
||||||
|
Globals.Logger.Verbose("{0}: Entry with only SHA-1 found - '{1}'", FileName, itemRom.Name);
|
||||||
|
}
|
||||||
|
|
||||||
// If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info
|
// If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info
|
||||||
if ((itemRom.Size == 0 || itemRom.Size == -1)
|
else if ((itemRom.Size == 0 || itemRom.Size == -1)
|
||||||
&& ((itemRom.CRC == Constants.CRCZero || String.IsNullOrWhiteSpace(itemRom.CRC))
|
&& ((itemRom.CRC == Constants.CRCZero || String.IsNullOrWhiteSpace(itemRom.CRC))
|
||||||
|| itemRom.MD5 == Constants.MD5Zero
|
|| itemRom.MD5 == Constants.MD5Zero
|
||||||
|| itemRom.SHA1 == Constants.SHA1Zero
|
|| itemRom.SHA1 == Constants.SHA1Zero
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// Otherwise, add what is possible
|
// Otherwise, add what is possible
|
||||||
reader.MoveToContent();
|
reader.MoveToContent();
|
||||||
|
|
||||||
|
int diskno = 0;
|
||||||
bool containsItems = false;
|
bool containsItems = false;
|
||||||
|
|
||||||
// Create a new machine
|
// Create a new machine
|
||||||
@@ -183,7 +184,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
reader.Read();
|
reader.Read();
|
||||||
break;
|
break;
|
||||||
case "dump":
|
case "dump":
|
||||||
containsItems = ReadDump(reader.ReadSubtree(), machine, filename, sysid, srcid, keep, clean, remUnicode);
|
containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
|
diskno++;
|
||||||
|
|
||||||
// Skip the dump now that we've processed it
|
// Skip the dump now that we've processed it
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
@@ -218,6 +220,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a part block</param>
|
/// <param name="reader">XmlReader representing a part block</param>
|
||||||
/// <param name="machine">Machine information to pass to contained items</param>
|
/// <param name="machine">Machine information to pass to contained items</param>
|
||||||
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source ID for the DAT</param>
|
/// <param name="srcid">Source ID for the DAT</param>
|
||||||
@@ -227,6 +230,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
private bool ReadDump(
|
private bool ReadDump(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Machine machine,
|
Machine machine,
|
||||||
|
int diskno,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -238,7 +242,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool clean,
|
bool clean,
|
||||||
bool remUnicode)
|
bool remUnicode)
|
||||||
{
|
{
|
||||||
string temptype = reader.Name;
|
|
||||||
bool containsItems = false;
|
bool containsItems = false;
|
||||||
|
|
||||||
while (!reader.EOF)
|
while (!reader.EOF)
|
||||||
@@ -254,19 +257,19 @@ namespace SabreTools.Library.DatFiles
|
|||||||
switch (reader.Name)
|
switch (reader.Name)
|
||||||
{
|
{
|
||||||
case "rom":
|
case "rom":
|
||||||
containsItems = ReadRom(reader.ReadSubtree(), machine, filename, sysid, srcid, keep, clean, remUnicode);
|
containsItems = ReadRom(reader.ReadSubtree(), machine, diskno, filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
|
|
||||||
// Skip the rom now that we've processed it
|
// Skip the rom now that we've processed it
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
break;
|
break;
|
||||||
case "megarom":
|
case "megarom":
|
||||||
containsItems = ReadMegaRom(reader.ReadSubtree(), machine, filename, sysid, srcid, keep, clean, remUnicode);
|
containsItems = ReadMegaRom(reader.ReadSubtree(), machine, diskno, filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
|
|
||||||
// Skip the megarom now that we've processed it
|
// Skip the megarom now that we've processed it
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
break;
|
break;
|
||||||
case "sccpluscart":
|
case "sccpluscart":
|
||||||
containsItems = ReadSccPlusCart(reader.ReadSubtree(), machine, filename, sysid, srcid, keep, clean, remUnicode);
|
containsItems = ReadSccPlusCart(reader.ReadSubtree(), machine, diskno, filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
|
|
||||||
// Skip the sccpluscart now that we've processed it
|
// Skip the sccpluscart now that we've processed it
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
@@ -288,18 +291,19 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read rom information
|
/// Read rom information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a part block</param>
|
/// <param name="reader">XmlReader representing a rom block</param>
|
||||||
/// <param name="machine">Machine information to pass to contained items</param>
|
/// <param name="machine">Machine information to pass to contained items</param>
|
||||||
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source ID for the DAT</param>
|
/// <param name="srcid">Source ID for the DAT</param>
|
||||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||||
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
||||||
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// TODO: Make sure that this outputs proper values since only SHA-1 is included
|
|
||||||
private bool ReadRom(
|
private bool ReadRom(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Machine machine,
|
Machine machine,
|
||||||
|
int diskno,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -348,8 +352,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// Create and add the new rom
|
// Create and add the new rom
|
||||||
Rom rom = new Rom
|
Rom rom = new Rom
|
||||||
{
|
{
|
||||||
Name = machine.Name + (!String.IsNullOrWhiteSpace(remark) ? " " + remark : ""),
|
Name = machine.Name + "_" + diskno + (!String.IsNullOrWhiteSpace(remark) ? " " + remark : ""),
|
||||||
Offset = offset,
|
Offset = offset,
|
||||||
|
Size = -1,
|
||||||
SHA1 = Utilities.CleanHashData(hash, Constants.SHA1Length),
|
SHA1 = Utilities.CleanHashData(hash, Constants.SHA1Length),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -362,18 +367,19 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read megarom information
|
/// Read megarom information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a part block</param>
|
/// <param name="reader">XmlReader representing a megarom block</param>
|
||||||
/// <param name="machine">Machine information to pass to contained items</param>
|
/// <param name="machine">Machine information to pass to contained items</param>
|
||||||
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source ID for the DAT</param>
|
/// <param name="srcid">Source ID for the DAT</param>
|
||||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||||
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
||||||
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// TODO: Make sure that this outputs proper values since only SHA-1 is included
|
|
||||||
private bool ReadMegaRom(
|
private bool ReadMegaRom(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Machine machine,
|
Machine machine,
|
||||||
|
int diskno,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -422,8 +428,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// Create and add the new rom
|
// Create and add the new rom
|
||||||
Rom rom = new Rom
|
Rom rom = new Rom
|
||||||
{
|
{
|
||||||
Name = machine.Name + (!String.IsNullOrWhiteSpace(remark) ? " " + remark : ""),
|
Name = machine.Name + "_" + diskno + (!String.IsNullOrWhiteSpace(remark) ? " " + remark : ""),
|
||||||
Offset = offset,
|
Offset = offset,
|
||||||
|
Size = -1,
|
||||||
SHA1 = Utilities.CleanHashData(hash, Constants.SHA1Length),
|
SHA1 = Utilities.CleanHashData(hash, Constants.SHA1Length),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -436,18 +443,19 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read sccpluscart information
|
/// Read sccpluscart information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a part block</param>
|
/// <param name="reader">XmlReader representing a sccpluscart block</param>
|
||||||
/// <param name="machine">Machine information to pass to contained items</param>
|
/// <param name="machine">Machine information to pass to contained items</param>
|
||||||
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source ID for the DAT</param>
|
/// <param name="srcid">Source ID for the DAT</param>
|
||||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||||
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
||||||
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// TODO: Make sure that this outputs proper values since only SHA-1 is included
|
|
||||||
private bool ReadSccPlusCart(
|
private bool ReadSccPlusCart(
|
||||||
XmlReader reader,
|
XmlReader reader,
|
||||||
Machine machine,
|
Machine machine,
|
||||||
|
int diskno,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
@@ -493,7 +501,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// Create and add the new rom
|
// Create and add the new rom
|
||||||
Rom rom = new Rom
|
Rom rom = new Rom
|
||||||
{
|
{
|
||||||
Name = machine.Name + (!String.IsNullOrWhiteSpace(remark) ? " " + remark : ""),
|
Name = machine.Name + "_" + diskno + (!String.IsNullOrWhiteSpace(remark) ? " " + remark : ""),
|
||||||
|
Size = -1,
|
||||||
SHA1 = Utilities.CleanHashData(hash, Constants.SHA1Length),
|
SHA1 = Utilities.CleanHashData(hash, Constants.SHA1Length),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user