2017-10-09 18:04:49 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
using System.IO;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
using System.Text;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2017-11-02 15:44:15 -07:00
|
|
|
|
using SabreTools.Library.DatItems;
|
2020-08-01 22:46:28 -07:00
|
|
|
|
using SabreTools.Library.IO;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
using SabreTools.Library.Tools;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Library.DatFiles
|
|
|
|
|
|
{
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents parsing and writing of a ClrMamePro DAT
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class ClrMamePro : DatFile
|
|
|
|
|
|
{
|
2020-09-20 21:12:57 -07:00
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get whether to assume quote usage on read and write or not
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool Quotes { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor designed for casting a base DatFile
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
2020-09-20 21:12:57 -07:00
|
|
|
|
/// <param name="quotes">Enable quotes on read and write, false otherwise</param>
|
|
|
|
|
|
public ClrMamePro(DatFile datFile, bool quotes)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
: base(datFile)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-20 21:12:57 -07:00
|
|
|
|
Quotes = quotes;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse a ClrMamePro DAT and return all found games and roms within
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
|
|
|
|
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// Open a file reader
|
2020-07-15 09:41:59 -07:00
|
|
|
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
|
|
|
|
|
ClrMameProReader cmpr = new ClrMameProReader(FileExtensions.TryOpenRead(filename), enc)
|
|
|
|
|
|
{
|
2020-09-20 21:12:57 -07:00
|
|
|
|
DosCenter = false,
|
|
|
|
|
|
Quotes = Quotes,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
};
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
while (!cmpr.EndOfStream)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
cmpr.ReadNextLine();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// Ignore everything not top-level
|
|
|
|
|
|
if (cmpr.RowType != CmpRowType.TopLevel)
|
|
|
|
|
|
continue;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// Switch on the top-level name
|
|
|
|
|
|
switch (cmpr.TopLevel.ToLowerInvariant())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Header values
|
|
|
|
|
|
case "clrmamepro":
|
|
|
|
|
|
case "romvault":
|
|
|
|
|
|
ReadHeader(cmpr, keep);
|
|
|
|
|
|
break;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// Sets
|
|
|
|
|
|
case "set": // Used by the most ancient DATs
|
|
|
|
|
|
case "game": // Used by most CMP DATs
|
|
|
|
|
|
case "machine": // Possibly used by MAME CMP DATs
|
|
|
|
|
|
ReadSet(cmpr, false, filename, indexId);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "resource": // Used by some other DATs to denote a BIOS set
|
|
|
|
|
|
ReadSet(cmpr, true, filename, indexId);
|
|
|
|
|
|
break;
|
2020-06-15 12:41:39 -07:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
string message = $"'{filename}' - There was an error parsing line {cmpr.LineNumber} '{cmpr.CurrentLine}'";
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error(ex, message);
|
2020-09-21 13:04:11 -07:00
|
|
|
|
if (throwOnError)
|
|
|
|
|
|
{
|
|
|
|
|
|
cmpr.Dispose();
|
|
|
|
|
|
throw new Exception(message, ex);
|
|
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
cmpr.Dispose();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read header information
|
|
|
|
|
|
/// </summary>
|
2020-06-15 12:41:39 -07:00
|
|
|
|
/// <param name="cmpr">ClrMameProReader to use to parse the header</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
2020-06-15 12:41:39 -07:00
|
|
|
|
private void ReadHeader(ClrMameProReader cmpr, bool keep)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
bool superdat = false;
|
|
|
|
|
|
|
|
|
|
|
|
// If there's no subtree to the header, skip it
|
2020-06-15 12:41:39 -07:00
|
|
|
|
if (cmpr == null || cmpr.EndOfStream)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
// While we don't hit an end element or end of stream
|
|
|
|
|
|
while (!cmpr.EndOfStream)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-06-15 12:41:39 -07:00
|
|
|
|
cmpr.ReadNextLine();
|
|
|
|
|
|
|
|
|
|
|
|
// Ignore comments, internal items, and nothingness
|
|
|
|
|
|
if (cmpr.RowType == CmpRowType.None || cmpr.RowType == CmpRowType.Comment || cmpr.RowType == CmpRowType.Internal)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// If we reached the end of a section, break
|
|
|
|
|
|
if (cmpr.RowType == CmpRowType.EndTopLevel)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// If the standalone value is null, we skip
|
|
|
|
|
|
if (cmpr.Standalone == null)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
string itemKey = cmpr.Standalone?.Key.ToLowerInvariant();
|
|
|
|
|
|
string itemVal = cmpr.Standalone?.Value;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
// For all other cases
|
|
|
|
|
|
switch (itemKey)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
case "name":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Name = (Header.Name == null ? itemVal : Header.Name);
|
2020-06-15 12:41:39 -07:00
|
|
|
|
superdat = superdat || itemVal.Contains(" - SuperDAT");
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
if (keep && superdat)
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Type = (Header.Type == null ? "SuperDAT" : Header.Type);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "description":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Description = (Header.Description == null ? itemVal : Header.Description);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "rootdir":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.RootDir = (Header.RootDir == null ? itemVal : Header.RootDir);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "category":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Category = (Header.Category == null ? itemVal : Header.Category);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "version":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Version = (Header.Version == null ? itemVal : Header.Version);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "date":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Date = (Header.Date == null ? itemVal : Header.Date);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "author":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Author = (Header.Author == null ? itemVal : Header.Author);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "email":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Email = (Header.Email == null ? itemVal : Header.Email);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "homepage":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Homepage = (Header.Homepage == null ? itemVal : Header.Homepage);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "url":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Url = (Header.Url == null ? itemVal : Header.Url);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "comment":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Comment = (Header.Comment == null ? itemVal : Header.Comment);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "header":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.HeaderSkipper = (Header.HeaderSkipper == null ? itemVal : Header.HeaderSkipper);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "type":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Type = (Header.Type == null ? itemVal : Header.Type);
|
2020-06-15 12:41:39 -07:00
|
|
|
|
superdat = superdat || itemVal.Contains("SuperDAT");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "forcemerging":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForceMerging == MergingFlag.None)
|
|
|
|
|
|
Header.ForceMerging = itemVal.AsMergingFlag();
|
2020-06-15 12:41:39 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "forcezipping":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForcePacking == PackingFlag.None)
|
|
|
|
|
|
Header.ForcePacking = itemVal.AsPackingFlag();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "forcepacking":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForcePacking == PackingFlag.None)
|
|
|
|
|
|
Header.ForcePacking = itemVal.AsPackingFlag();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read set information
|
|
|
|
|
|
/// </summary>
|
2020-06-15 12:41:39 -07:00
|
|
|
|
/// <param name="cmpr">ClrMameProReader to use to parse the header</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <param name="resource">True if the item is a resource (bios), false otherwise</param>
|
|
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
private void ReadSet(
|
2020-06-15 12:41:39 -07:00
|
|
|
|
ClrMameProReader cmpr,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
bool resource,
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// Prepare all internal variables
|
|
|
|
|
|
bool containsItems = false;
|
|
|
|
|
|
Machine machine = new Machine()
|
|
|
|
|
|
{
|
2020-08-24 13:53:53 -07:00
|
|
|
|
MachineType = (resource ? MachineType.Bios : MachineType.NULL),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If there's no subtree to the header, skip it
|
2020-06-15 12:41:39 -07:00
|
|
|
|
if (cmpr == null || cmpr.EndOfStream)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
// While we don't hit an end element or end of stream
|
|
|
|
|
|
while (!cmpr.EndOfStream)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-06-15 12:41:39 -07:00
|
|
|
|
cmpr.ReadNextLine();
|
|
|
|
|
|
|
|
|
|
|
|
// Ignore comments and nothingness
|
|
|
|
|
|
if (cmpr.RowType == CmpRowType.None || cmpr.RowType == CmpRowType.Comment)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
continue;
|
2020-06-15 12:41:39 -07:00
|
|
|
|
|
|
|
|
|
|
// If we reached the end of a section, break
|
|
|
|
|
|
if (cmpr.RowType == CmpRowType.EndTopLevel)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// Handle any standalone items
|
|
|
|
|
|
if (cmpr.RowType == CmpRowType.Standalone && cmpr.Standalone != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string itemKey = cmpr.Standalone?.Key.ToLowerInvariant();
|
|
|
|
|
|
string itemVal = cmpr.Standalone?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
switch (itemKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "name":
|
|
|
|
|
|
machine.Name = itemVal;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "description":
|
|
|
|
|
|
machine.Description = itemVal;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "year":
|
|
|
|
|
|
machine.Year = itemVal;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "manufacturer":
|
|
|
|
|
|
machine.Manufacturer = itemVal;
|
|
|
|
|
|
break;
|
2020-07-18 21:35:17 -07:00
|
|
|
|
case "category":
|
|
|
|
|
|
machine.Category = itemVal;
|
|
|
|
|
|
break;
|
2020-06-15 12:41:39 -07:00
|
|
|
|
case "cloneof":
|
|
|
|
|
|
machine.CloneOf = itemVal;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "romof":
|
|
|
|
|
|
machine.RomOf = itemVal;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sampleof":
|
|
|
|
|
|
machine.SampleOf = itemVal;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
// Handle any internal items
|
|
|
|
|
|
else if (cmpr.RowType == CmpRowType.Internal
|
|
|
|
|
|
&& !string.IsNullOrWhiteSpace(cmpr.InternalName)
|
|
|
|
|
|
&& cmpr.Internal != null)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
containsItems = true;
|
2020-06-15 12:41:39 -07:00
|
|
|
|
string itemKey = cmpr.InternalName;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// Create the proper DatItem based on the type
|
2020-08-27 16:57:22 -07:00
|
|
|
|
ItemType itemType = itemKey.AsItemType() ?? ItemType.Rom;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
DatItem item = DatItem.Create(itemType);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Then populate it with information
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
item.Source.Index = indexId;
|
|
|
|
|
|
item.Source.Name = filename;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
// Loop through all of the attributes
|
|
|
|
|
|
foreach (var kvp in cmpr.Internal)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-06-15 12:41:39 -07:00
|
|
|
|
string attrKey = kvp.Key;
|
|
|
|
|
|
string attrVal = kvp.Value;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-06-15 12:41:39 -07:00
|
|
|
|
switch (attrKey)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
//If the item is empty, we automatically skip it because it's a fluke
|
|
|
|
|
|
case "":
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Regular attributes
|
|
|
|
|
|
case "name":
|
2020-09-02 12:32:10 -07:00
|
|
|
|
item.SetFields(new Dictionary<Field, string> { [Field.DatItem_Name] = attrVal } );
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-15 12:41:39 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "size":
|
|
|
|
|
|
if (item.ItemType == ItemType.Rom)
|
2020-09-04 23:03:27 -07:00
|
|
|
|
(item as Rom).Size = Sanitizer.CleanLong(attrVal);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "crc":
|
|
|
|
|
|
if (item.ItemType == ItemType.Rom)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
(item as Rom).CRC = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "md5":
|
2020-08-27 16:57:22 -07:00
|
|
|
|
if (item.ItemType == ItemType.Disk)
|
|
|
|
|
|
(item as Disk).MD5 = attrVal;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Media)
|
|
|
|
|
|
(item as Media).MD5 = attrVal;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Rom)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
(item as Rom).MD5 = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#if NET_FRAMEWORK
|
2020-06-05 22:26:44 -07:00
|
|
|
|
case "ripemd160":
|
|
|
|
|
|
if (item.ItemType == ItemType.Rom)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
(item as Rom).RIPEMD160 = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-06-05 22:26:44 -07:00
|
|
|
|
break;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#endif
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "sha1":
|
2020-08-27 16:57:22 -07:00
|
|
|
|
if (item.ItemType == ItemType.Disk)
|
|
|
|
|
|
(item as Disk).SHA1 = attrVal;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Media)
|
|
|
|
|
|
(item as Media).SHA1 = attrVal;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Rom)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
(item as Rom).SHA1 = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "sha256":
|
2020-08-27 16:57:22 -07:00
|
|
|
|
if (item.ItemType == ItemType.Media)
|
|
|
|
|
|
(item as Media).SHA256 = attrVal;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Rom)
|
|
|
|
|
|
(item as Rom).SHA256 = attrVal;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "sha384":
|
|
|
|
|
|
if (item.ItemType == ItemType.Rom)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
(item as Rom).SHA384 = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "sha512":
|
|
|
|
|
|
if (item.ItemType == ItemType.Rom)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
(item as Rom).SHA512 = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-04 15:02:15 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "spamsum":
|
|
|
|
|
|
if (item.ItemType == ItemType.Media)
|
|
|
|
|
|
(item as Media).SpamSum = attrVal;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Rom)
|
|
|
|
|
|
(item as Rom).SpamSum = attrVal;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "status":
|
2020-07-15 09:41:59 -07:00
|
|
|
|
ItemStatus tempFlagStatus = attrVal.AsItemStatus();
|
2020-08-27 16:57:22 -07:00
|
|
|
|
if (item.ItemType == ItemType.Disk)
|
|
|
|
|
|
(item as Disk).ItemStatus = tempFlagStatus;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Rom)
|
|
|
|
|
|
(item as Rom).ItemStatus = tempFlagStatus;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "date":
|
2020-08-27 16:57:22 -07:00
|
|
|
|
if (item.ItemType == ItemType.Release)
|
|
|
|
|
|
(item as Release).Date = attrVal;
|
|
|
|
|
|
else if (item.ItemType == ItemType.Rom)
|
|
|
|
|
|
(item as Rom).Date = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "default":
|
|
|
|
|
|
if (item.ItemType == ItemType.BiosSet)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
(item as BiosSet).Default = attrVal.AsYesNo();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
else if (item.ItemType == ItemType.Release)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
(item as Release).Default = attrVal.AsYesNo();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "description":
|
|
|
|
|
|
if (item.ItemType == ItemType.BiosSet)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
(item as BiosSet).Description = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "region":
|
|
|
|
|
|
if (item.ItemType == ItemType.Release)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
(item as Release).Region = attrVal;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
case "language":
|
|
|
|
|
|
if (item.ItemType == ItemType.Release)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
(item as Release).Language = attrVal;
|
2020-08-25 22:48:46 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now process and add the rom
|
2020-07-15 09:41:59 -07:00
|
|
|
|
ParseAddHelper(item);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If no items were found for this machine, add a Blank placeholder
|
|
|
|
|
|
if (!containsItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
Blank blank = new Blank()
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
blank.CopyMachineInformation(machine);
|
|
|
|
|
|
|
|
|
|
|
|
// Now process and add the rom
|
2020-07-15 09:41:59 -07:00
|
|
|
|
ParseAddHelper(blank);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-18 17:12:31 -07:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
protected override ItemType[] GetSupportedTypes()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ItemType[]
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemType.Archive,
|
|
|
|
|
|
ItemType.BiosSet,
|
|
|
|
|
|
ItemType.Disk,
|
|
|
|
|
|
ItemType.Media,
|
|
|
|
|
|
ItemType.Release,
|
|
|
|
|
|
ItemType.Rom,
|
|
|
|
|
|
ItemType.Sample,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create and open an output file for writing direct from a dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="outfile">Name of the file to write to</param>
|
|
|
|
|
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.User($"Opening file for writing: {outfile}");
|
2020-07-15 09:41:59 -07:00
|
|
|
|
FileStream fs = FileExtensions.TryCreate(outfile);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we get back null for some reason, just log and return
|
|
|
|
|
|
if (fs == null)
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Warning($"File '{outfile}' could not be created for writing! Please check to see if the file is writable");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
ClrMameProWriter cmpw = new ClrMameProWriter(fs, new UTF8Encoding(false))
|
|
|
|
|
|
{
|
2020-09-20 21:12:57 -07:00
|
|
|
|
Quotes = Quotes
|
2020-07-15 09:41:59 -07:00
|
|
|
|
};
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Write out the header
|
2020-06-13 13:54:04 -07:00
|
|
|
|
WriteHeader(cmpw);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Write out each of the machines and roms
|
|
|
|
|
|
string lastgame = null;
|
|
|
|
|
|
|
2020-07-26 21:00:30 -07:00
|
|
|
|
// Use a sorted list of games to output
|
2020-07-26 22:34:45 -07:00
|
|
|
|
foreach (string key in Items.SortedKeys)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-28 15:06:07 -07:00
|
|
|
|
List<DatItem> datItems = Items.FilteredItems(key);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-25 20:25:29 -07:00
|
|
|
|
// If this machine doesn't contain any writable items, skip
|
|
|
|
|
|
if (!ContainsWritable(datItems))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// Resolve the names in the block
|
2020-08-28 15:06:07 -07:00
|
|
|
|
datItems = DatItem.ResolveNames(datItems);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
for (int index = 0; index < datItems.Count; index++)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-28 15:06:07 -07:00
|
|
|
|
DatItem datItem = datItems[index];
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we have a different game and we're not at the start of the list, output the end of last item
|
2020-08-28 15:06:07 -07:00
|
|
|
|
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
|
|
|
|
|
WriteEndGame(cmpw, datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we have a new game, output the beginning of the new item
|
2020-08-28 15:06:07 -07:00
|
|
|
|
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
|
|
|
|
|
WriteStartGame(cmpw, datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
// Check for a "null" item
|
|
|
|
|
|
datItem = ProcessNullifiedItem(datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
// Write out the item if we're not ignoring
|
|
|
|
|
|
if (!ShouldIgnore(datItem, ignoreblanks))
|
|
|
|
|
|
WriteDatItem(cmpw, datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Set the new data to compare against
|
2020-08-28 15:06:07 -07:00
|
|
|
|
lastgame = datItem.Machine.Name;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write the file footer out
|
2020-06-13 13:54:04 -07:00
|
|
|
|
WriteFooter(cmpw);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Verbose($"File written!{Environment.NewLine}");
|
2020-06-14 14:16:03 -07:00
|
|
|
|
cmpw.Dispose();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
fs.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error(ex);
|
2020-09-15 14:23:40 -07:00
|
|
|
|
if (throwOnError) throw ex;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DAT header using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-13 13:54:04 -07:00
|
|
|
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteHeader(ClrMameProWriter cmpw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.WriteStartElement("clrmamepro");
|
|
|
|
|
|
|
|
|
|
|
|
cmpw.WriteRequiredStandalone("name", Header.Name);
|
|
|
|
|
|
cmpw.WriteRequiredStandalone("description", Header.Description);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("category", Header.Category);
|
|
|
|
|
|
cmpw.WriteRequiredStandalone("version", Header.Version);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("date", Header.Date);
|
|
|
|
|
|
cmpw.WriteRequiredStandalone("author", Header.Author);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("email", Header.Email);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("homepage", Header.Homepage);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("url", Header.Url);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("comment", Header.Comment);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("forcezipping", Header.ForcePacking.FromPackingFlag(true), false);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("forcemerging", Header.ForceMerging.FromMergingFlag(false), false);
|
|
|
|
|
|
|
|
|
|
|
|
// End clrmamepro
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
cmpw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out Game start using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-13 13:54:04 -07:00
|
|
|
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="datItem">DatItem object to be output</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// No game should start with a path separator
|
|
|
|
|
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Build the state
|
|
|
|
|
|
cmpw.WriteStartElement(datItem.Machine.MachineType == MachineType.Bios ? "resource" : "game");
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.WriteRequiredStandalone("name", datItem.Machine.Name);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("romof", datItem.Machine.RomOf);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("cloneof", datItem.Machine.CloneOf);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("description", datItem.Machine.Description ?? datItem.Machine.Name);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("year", datItem.Machine.Year);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("manufacturer", datItem.Machine.Manufacturer);
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("category", datItem.Machine.Category);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out Game end using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-13 13:54:04 -07:00
|
|
|
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="datItem">DatItem object to be output</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteEndGame(ClrMameProWriter cmpw, DatItem datItem)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Build the state
|
|
|
|
|
|
cmpw.WriteOptionalStandalone("sampleof", datItem.Machine.SampleOf);
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End game
|
|
|
|
|
|
cmpw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DatItem using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datFile">DatFile to write out from</param>
|
2020-06-13 13:54:04 -07:00
|
|
|
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="datItem">DatItem object to be output</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Pre-process the item name
|
|
|
|
|
|
ProcessItemName(datItem, true);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Build the state
|
|
|
|
|
|
switch (datItem.ItemType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ItemType.Archive:
|
|
|
|
|
|
var archive = datItem as Archive;
|
|
|
|
|
|
cmpw.WriteStartElement("archive");
|
|
|
|
|
|
cmpw.WriteRequiredAttributeString("name", archive.Name);
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.BiosSet:
|
|
|
|
|
|
var biosSet = datItem as BiosSet;
|
|
|
|
|
|
cmpw.WriteStartElement("biosset");
|
|
|
|
|
|
cmpw.WriteRequiredAttributeString("name", biosSet.Name);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("description", biosSet.Description);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("default", biosSet.Default?.ToString().ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.Disk:
|
|
|
|
|
|
var disk = datItem as Disk;
|
|
|
|
|
|
cmpw.WriteStartElement("disk");
|
|
|
|
|
|
cmpw.WriteRequiredAttributeString("name", disk.Name);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("flags", disk.ItemStatus.FromItemStatus(false));
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.Media:
|
|
|
|
|
|
var media = datItem as Media;
|
|
|
|
|
|
cmpw.WriteStartElement("media");
|
|
|
|
|
|
cmpw.WriteRequiredAttributeString("name", media.Name);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("md5", media.MD5?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("sha1", media.SHA1?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("sha256", media.SHA256?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("spamsum", media.SpamSum?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-08-27 16:57:22 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.Release:
|
|
|
|
|
|
var release = datItem as Release;
|
|
|
|
|
|
cmpw.WriteStartElement("release");
|
|
|
|
|
|
cmpw.WriteRequiredAttributeString("name", release.Name);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("region", release.Region);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("language", release.Language);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("date", release.Date);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("default", release.Default?.ToString().ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.Rom:
|
|
|
|
|
|
var rom = datItem as Rom;
|
|
|
|
|
|
cmpw.WriteStartElement("rom");
|
|
|
|
|
|
cmpw.WriteRequiredAttributeString("name", rom.Name);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("size", rom.Size?.ToString());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#if NET_FRAMEWORK
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.WriteOptionalAttributeString("ripemd160", rom.RIPEMD160?.ToLowerInvariant());
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#endif
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.WriteOptionalAttributeString("sha1", rom.SHA1?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("sha256", rom.SHA256?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("sha384", rom.SHA384?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("spamsum", rom.SpamSum?.ToLowerInvariant());
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("date", rom.Date);
|
|
|
|
|
|
cmpw.WriteOptionalAttributeString("flags", rom.ItemStatus.FromItemStatus(false));
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.Sample:
|
|
|
|
|
|
var sample = datItem as Sample;
|
|
|
|
|
|
cmpw.WriteStartElement("sample");
|
|
|
|
|
|
cmpw.WriteRequiredAttributeString("name", sample.Name);
|
|
|
|
|
|
cmpw.WriteEndElement();
|
|
|
|
|
|
break;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DAT footer using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-13 13:54:04 -07:00
|
|
|
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteFooter(ClrMameProWriter cmpw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End game
|
|
|
|
|
|
cmpw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
cmpw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-09 18:04:49 -07:00
|
|
|
|
}
|