Move former Sanitizer methods to better places

This commit is contained in:
Matt Nadareski
2020-12-09 22:27:41 -08:00
parent caf5fae5ad
commit 7e86b6914d
32 changed files with 367 additions and 382 deletions

View File

@@ -312,5 +312,48 @@ namespace SabreTools.DatFiles
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected abstract void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false);
#region Input Sanitization
/// <summary>
/// Get a sanitized Date from an input string
/// </summary>
/// <param name="input">String to get value from</param>
/// <returns>Date as a string, if possible</returns>
protected string CleanDate(string input)
{
// Null in, null out
if (input == null)
return null;
string date = string.Empty;
if (input != null)
{
if (DateTime.TryParse(input, out DateTime dateTime))
date = dateTime.ToString();
else
date = input;
}
return date;
}
/// <summary>
/// Clean a hash string from a Listrom DAT
/// </summary>
/// <param name="hash">Hash string to sanitize</param>
/// <returns>Cleaned string</returns>
protected string CleanListromHashData(string hash)
{
if (hash.StartsWith("CRC"))
return hash.Substring(4, 8).ToLowerInvariant();
else if (hash.StartsWith("SHA1"))
return hash.Substring(5, 40).ToLowerInvariant();
return hash;
}
#endregion
}
}

View File

@@ -104,7 +104,7 @@ namespace SabreTools.DatFiles.Formats
Disk disk = new Disk()
{
Name = romname,
SHA1 = Sanitizer.CleanListromHashData(split[0]),
SHA1 = CleanListromHashData(split[0]),
Machine = new Machine
{
@@ -127,7 +127,7 @@ namespace SabreTools.DatFiles.Formats
Disk disk = new Disk()
{
Name = romname,
SHA1 = Sanitizer.CleanListromHashData(split[1]),
SHA1 = CleanListromHashData(split[1]),
ItemStatus = ItemStatus.BadDump,
Machine = new Machine
@@ -152,8 +152,8 @@ namespace SabreTools.DatFiles.Formats
{
Name = romname,
Size = Sanitizer.CleanLong(split[0]),
CRC = Sanitizer.CleanListromHashData(split[1]),
SHA1 = Sanitizer.CleanListromHashData(split[2]),
CRC = CleanListromHashData(split[1]),
SHA1 = CleanListromHashData(split[2]),
Machine = new Machine
{
@@ -200,8 +200,8 @@ namespace SabreTools.DatFiles.Formats
{
Name = romname,
Size = Sanitizer.CleanLong(split[0]),
CRC = Sanitizer.CleanListromHashData(split[2]),
SHA1 = Sanitizer.CleanListromHashData(split[3]),
CRC = CleanListromHashData(split[2]),
SHA1 = CleanListromHashData(split[3]),
ItemStatus = ItemStatus.BadDump,
Machine = new Machine

View File

@@ -622,7 +622,7 @@ namespace SabreTools.DatFiles.Formats
SpamSum = reader.GetAttribute("spamsum"),
MergeTag = reader.GetAttribute("merge"),
ItemStatus = reader.GetAttribute("status").AsItemStatus(),
Date = Sanitizer.CleanDate(reader.GetAttribute("date")),
Date = CleanDate(reader.GetAttribute("date")),
Inverted = reader.GetAttribute("inverted").AsYesNo(),
Source = new Source