mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Create hashfile and separated value subclasses
This commit is contained in:
@@ -81,7 +81,7 @@ namespace SabreTools.DatFiles
|
|||||||
DatFormat.ArchiveDotOrg => new ArchiveDotOrg(baseDat),
|
DatFormat.ArchiveDotOrg => new ArchiveDotOrg(baseDat),
|
||||||
DatFormat.AttractMode => new AttractMode(baseDat),
|
DatFormat.AttractMode => new AttractMode(baseDat),
|
||||||
DatFormat.ClrMamePro => new ClrMamePro(baseDat, quotes),
|
DatFormat.ClrMamePro => new ClrMamePro(baseDat, quotes),
|
||||||
DatFormat.CSV => new SeparatedValue(baseDat, ','),
|
DatFormat.CSV => new CommaSeparatedValue(baseDat),
|
||||||
DatFormat.DOSCenter => new DosCenter(baseDat),
|
DatFormat.DOSCenter => new DosCenter(baseDat),
|
||||||
DatFormat.EverdriveSMDB => new EverdriveSMDB(baseDat),
|
DatFormat.EverdriveSMDB => new EverdriveSMDB(baseDat),
|
||||||
DatFormat.Listrom => new Listrom(baseDat),
|
DatFormat.Listrom => new Listrom(baseDat),
|
||||||
@@ -91,19 +91,19 @@ namespace SabreTools.DatFiles
|
|||||||
DatFormat.MissFile => new Missfile(baseDat),
|
DatFormat.MissFile => new Missfile(baseDat),
|
||||||
DatFormat.OfflineList => new OfflineList(baseDat),
|
DatFormat.OfflineList => new OfflineList(baseDat),
|
||||||
DatFormat.OpenMSX => new OpenMSX(baseDat),
|
DatFormat.OpenMSX => new OpenMSX(baseDat),
|
||||||
DatFormat.RedumpMD5 => new Hashfile(baseDat, HashType.MD5),
|
DatFormat.RedumpMD5 => new Md5File(baseDat),
|
||||||
DatFormat.RedumpSFV => new Hashfile(baseDat, HashType.CRC32),
|
DatFormat.RedumpSFV => new SfvFile(baseDat),
|
||||||
DatFormat.RedumpSHA1 => new Hashfile(baseDat, HashType.SHA1),
|
DatFormat.RedumpSHA1 => new Sha1File(baseDat),
|
||||||
DatFormat.RedumpSHA256 => new Hashfile(baseDat, HashType.SHA256),
|
DatFormat.RedumpSHA256 => new Sha256File(baseDat),
|
||||||
DatFormat.RedumpSHA384 => new Hashfile(baseDat, HashType.SHA384),
|
DatFormat.RedumpSHA384 => new Sha384File(baseDat),
|
||||||
DatFormat.RedumpSHA512 => new Hashfile(baseDat, HashType.SHA512),
|
DatFormat.RedumpSHA512 => new Sha512File(baseDat),
|
||||||
DatFormat.RedumpSpamSum => new Hashfile(baseDat, HashType.SpamSum),
|
DatFormat.RedumpSpamSum => new SpamSumFile(baseDat),
|
||||||
DatFormat.RomCenter => new RomCenter(baseDat),
|
DatFormat.RomCenter => new RomCenter(baseDat),
|
||||||
DatFormat.SabreJSON => new SabreJSON(baseDat),
|
DatFormat.SabreJSON => new SabreJSON(baseDat),
|
||||||
DatFormat.SabreXML => new SabreXML(baseDat),
|
DatFormat.SabreXML => new SabreXML(baseDat),
|
||||||
DatFormat.SoftwareList => new Formats.SoftwareList(baseDat),
|
DatFormat.SoftwareList => new Formats.SoftwareList(baseDat),
|
||||||
DatFormat.SSV => new SeparatedValue(baseDat, ';'),
|
DatFormat.SSV => new SemicolonSeparatedValue(baseDat),
|
||||||
DatFormat.TSV => new SeparatedValue(baseDat, '\t'),
|
DatFormat.TSV => new TabSeparatedValue(baseDat),
|
||||||
|
|
||||||
// We use new-style Logiqx as a backup for generic DatFile
|
// We use new-style Logiqx as a backup for generic DatFile
|
||||||
_ => new Logiqx(baseDat, false),
|
_ => new Logiqx(baseDat, false),
|
||||||
|
|||||||
@@ -3,45 +3,24 @@ using System.Collections.Generic;
|
|||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
using SabreTools.Hashing;
|
|
||||||
|
|
||||||
namespace SabreTools.DatFiles.Formats
|
namespace SabreTools.DatFiles.Formats
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a hashfile such as an SFV, MD5, or SHA-1 file
|
/// Represents a hashfile such as an SFV, MD5, or SHA-1 file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class Hashfile : SerializableDatFile<Models.Hashfile.Hashfile, Serialization.Files.Hashfile, Serialization.CrossModel.Hashfile>
|
internal abstract class Hashfile : SerializableDatFile<Models.Hashfile.Hashfile, Serialization.Files.Hashfile, Serialization.CrossModel.Hashfile>
|
||||||
{
|
{
|
||||||
// Private instance variables specific to Hashfile DATs
|
// Private instance variables specific to Hashfile DATs
|
||||||
private readonly Serialization.Hash _hash;
|
protected Serialization.Hash _hash;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor designed for casting a base DatFile
|
/// Constructor designed for casting a base DatFile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">Parent DatFile to copy from</param>
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
/// <param name="hash">Type of hash that is associated with this DAT</param>
|
public Hashfile(DatFile? datFile)
|
||||||
public Hashfile(DatFile? datFile, HashType hash)
|
|
||||||
: base(datFile)
|
: base(datFile)
|
||||||
{
|
{
|
||||||
_hash = ConvertHash(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert hash types between internal and Serialization
|
|
||||||
/// </summary>
|
|
||||||
private static Serialization.Hash ConvertHash(HashType hash)
|
|
||||||
{
|
|
||||||
return hash switch
|
|
||||||
{
|
|
||||||
HashType.CRC32 => Serialization.Hash.CRC,
|
|
||||||
HashType.MD5 => Serialization.Hash.MD5,
|
|
||||||
HashType.SHA1 => Serialization.Hash.SHA1,
|
|
||||||
HashType.SHA256 => Serialization.Hash.SHA256,
|
|
||||||
HashType.SHA384 => Serialization.Hash.SHA384,
|
|
||||||
HashType.SHA512 => Serialization.Hash.SHA512,
|
|
||||||
HashType.SpamSum => Serialization.Hash.SpamSum,
|
|
||||||
_ => throw new System.ArgumentOutOfRangeException(nameof(hash)),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -225,4 +204,116 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an SFV (CRC-32) hashfile
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class SfvFile : Hashfile
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public SfvFile(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_hash = Serialization.Hash.CRC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an MD5 hashfile
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class Md5File : Hashfile
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public Md5File(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_hash = Serialization.Hash.MD5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an SHA-1 hashfile
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class Sha1File : Hashfile
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public Sha1File(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_hash = Serialization.Hash.SHA1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an SHA-256 hashfile
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class Sha256File : Hashfile
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public Sha256File(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_hash = Serialization.Hash.SHA256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an SHA-384 hashfile
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class Sha384File : Hashfile
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public Sha384File(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_hash = Serialization.Hash.SHA384;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an SHA-512 hashfile
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class Sha512File : Hashfile
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public Sha512File(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_hash = Serialization.Hash.SHA512;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an SpamSum hashfile
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class SpamSumFile : Hashfile
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public SpamSumFile(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_hash = Serialization.Hash.SpamSum;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,18 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a value-separated DAT
|
/// Represents a value-separated DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class SeparatedValue : SerializableDatFile<Models.SeparatedValue.MetadataFile, Serialization.Files.SeparatedValue, Serialization.CrossModel.SeparatedValue>
|
internal abstract class SeparatedValue : SerializableDatFile<Models.SeparatedValue.MetadataFile, Serialization.Files.SeparatedValue, Serialization.CrossModel.SeparatedValue>
|
||||||
{
|
{
|
||||||
// Private instance variables specific to Separated Value DATs
|
// Private instance variables specific to Hashfile DATs
|
||||||
private readonly char _delim;
|
protected char _delim;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor designed for casting a base DatFile
|
/// Constructor designed for casting a base DatFile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">Parent DatFile to copy from</param>
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
/// <param name="delim">Delimiter for parsing individual lines</param>
|
public SeparatedValue(DatFile? datFile)
|
||||||
public SeparatedValue(DatFile? datFile, char delim)
|
|
||||||
: base(datFile)
|
: base(datFile)
|
||||||
{
|
{
|
||||||
_delim = delim;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -119,4 +117,52 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a comma-separated value file
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class CommaSeparatedValue : SeparatedValue
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public CommaSeparatedValue(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_delim = ',';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a semicolon-separated value file
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class SemicolonSeparatedValue : SeparatedValue
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public SemicolonSeparatedValue(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_delim = ';';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a tab-separated value file
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class TabSeparatedValue : SeparatedValue
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor designed for casting a base DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
||||||
|
public TabSeparatedValue(DatFile? datFile)
|
||||||
|
: base(datFile)
|
||||||
|
{
|
||||||
|
_delim = '\t';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user