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
|
|
|
|
|
2020-12-08 13:23:59 -08:00
|
|
|
|
using SabreTools.Core;
|
2020-12-08 16:37:08 -08:00
|
|
|
|
using SabreTools.Core.Tools;
|
2020-12-08 15:15:41 -08:00
|
|
|
|
using SabreTools.DatItems;
|
2021-02-02 10:23:43 -08:00
|
|
|
|
using SabreTools.DatItems.Formats;
|
2020-12-09 23:11:10 -08:00
|
|
|
|
using SabreTools.IO.Readers;
|
|
|
|
|
|
using SabreTools.IO.Writers;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
|
2020-12-09 22:11:35 -08:00
|
|
|
|
namespace SabreTools.DatFiles.Formats
|
2017-10-09 18:04:49 -07:00
|
|
|
|
{
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents parsing and writing of a RomCenter DAT
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class RomCenter : DatFile
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor designed for casting a base DatFile
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
|
|
|
|
|
public RomCenter(DatFile datFile)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
: base(datFile)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-18 12:09:09 -08:00
|
|
|
|
/// <inheritdoc/>
|
2020-12-23 13:55:09 -08:00
|
|
|
|
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-06-13 23:28:55 -07:00
|
|
|
|
// Prepare all intenral variables
|
2020-12-08 00:13:22 -08:00
|
|
|
|
IniReader ir = new IniReader(filename) { ValidateRows = false };
|
2020-06-13 23:28:55 -07:00
|
|
|
|
|
|
|
|
|
|
// If we got a null reader, just return
|
|
|
|
|
|
if (ir == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-08-21 10:38:42 -07:00
|
|
|
|
// Otherwise, read the file to the end
|
2020-06-13 23:28:55 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ir.ReadNextLine();
|
|
|
|
|
|
while (!ir.EndOfStream)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We don't care about whitespace or comments
|
|
|
|
|
|
if (ir.RowType == IniRowType.None || ir.RowType == IniRowType.Comment)
|
|
|
|
|
|
{
|
|
|
|
|
|
ir.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have a section
|
|
|
|
|
|
if (ir.RowType == IniRowType.SectionHeader)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (ir.Section.ToLowerInvariant())
|
|
|
|
|
|
{
|
|
|
|
|
|
case "credits":
|
|
|
|
|
|
ReadCreditsSection(ir);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "dat":
|
|
|
|
|
|
ReadDatSection(ir);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "emulator":
|
|
|
|
|
|
ReadEmulatorSection(ir);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "games":
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ReadGamesSection(ir, statsOnly, filename, indexId);
|
2020-06-13 23:28:55 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// Unknown section so we ignore it
|
|
|
|
|
|
default:
|
|
|
|
|
|
ir.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-01-12 15:54:14 -08:00
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
string message = $"'{filename}' - There was an error parsing line {ir.LineNumber} '{ir.CurrentLine}'";
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error(ex, message);
|
2020-06-11 21:54:08 -07:00
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-06-13 23:28:55 -07:00
|
|
|
|
ir.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read credits information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">IniReader to use to parse the credits</param>
|
|
|
|
|
|
private void ReadCreditsSection(IniReader reader)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the reader is somehow null, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
2020-12-20 22:01:05 -08:00
|
|
|
|
do
|
2020-06-11 21:54:08 -07:00
|
|
|
|
{
|
2020-06-13 23:28:55 -07:00
|
|
|
|
// We don't care about whitespace, comments, or invalid
|
|
|
|
|
|
if (reader.RowType != IniRowType.KeyValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-06-13 23:28:55 -07:00
|
|
|
|
var kvp = reader.KeyValuePair;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-06-13 23:28:55 -07:00
|
|
|
|
// If the KeyValuePair is invalid, skip it
|
|
|
|
|
|
if (kvp == null)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-20 15:57:52 -07:00
|
|
|
|
// Get all credits items
|
2020-06-13 23:28:55 -07:00
|
|
|
|
switch (kvp?.Key.ToLowerInvariant())
|
|
|
|
|
|
{
|
|
|
|
|
|
case "author":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Author ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "version":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Version ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "email":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Email ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "homepage":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Homepage ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "url":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Url ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "date":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Date ??= kvp?.Value;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "comment":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Comment ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// Unknown value, just skip
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
2020-12-20 22:01:05 -08:00
|
|
|
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "credits");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-13 23:28:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read dat information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">IniReader to use to parse the credits</param>
|
|
|
|
|
|
private void ReadDatSection(IniReader reader)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the reader is somehow null, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
reader.ReadNextLine();
|
2020-12-20 22:01:05 -08:00
|
|
|
|
do
|
2020-06-13 23:28:55 -07:00
|
|
|
|
{
|
|
|
|
|
|
// We don't care about whitespace, comments, or invalid
|
|
|
|
|
|
if (reader.RowType != IniRowType.KeyValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var kvp = reader.KeyValuePair;
|
|
|
|
|
|
|
|
|
|
|
|
// If the KeyValuePair is invalid, skip it
|
|
|
|
|
|
if (kvp == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-20 15:57:52 -07:00
|
|
|
|
// Get all dat items
|
2020-06-13 23:28:55 -07:00
|
|
|
|
switch (kvp?.Key.ToLowerInvariant())
|
|
|
|
|
|
{
|
|
|
|
|
|
case "version":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.RomCenterVersion ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "plugin":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.System ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "split":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForceMerging == MergingFlag.None && kvp?.Value == "1")
|
|
|
|
|
|
Header.ForceMerging = MergingFlag.Split;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "merge":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForceMerging == MergingFlag.None && kvp?.Value == "1")
|
|
|
|
|
|
Header.ForceMerging = MergingFlag.Merged;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// Unknown value, just skip
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-12-20 22:01:05 -08:00
|
|
|
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "dat");
|
2020-06-13 23:28:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read emulator information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">IniReader to use to parse the credits</param>
|
|
|
|
|
|
private void ReadEmulatorSection(IniReader reader)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the reader is somehow null, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
reader.ReadNextLine();
|
2020-12-20 22:01:05 -08:00
|
|
|
|
do
|
2020-06-13 23:28:55 -07:00
|
|
|
|
{
|
|
|
|
|
|
// We don't care about whitespace, comments, or invalid
|
|
|
|
|
|
if (reader.RowType != IniRowType.KeyValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var kvp = reader.KeyValuePair;
|
|
|
|
|
|
|
|
|
|
|
|
// If the KeyValuePair is invalid, skip it
|
|
|
|
|
|
if (kvp == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get all emulator items (ONLY OVERWRITE IF THERE'S NO DATA)
|
|
|
|
|
|
switch (kvp?.Key.ToLowerInvariant())
|
|
|
|
|
|
{
|
|
|
|
|
|
case "refname":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Name ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "version":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Description ??= kvp?.Value;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// Unknown value, just skip
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-12-20 22:01:05 -08:00
|
|
|
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "emulator");
|
2020-06-13 23:28:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read games information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">IniReader to use to parse the credits</param>
|
2020-12-23 13:55:09 -08:00
|
|
|
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
|
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2020-12-23 13:55:09 -08:00
|
|
|
|
private void ReadGamesSection(IniReader reader, bool statsOnly, string filename, int indexId)
|
2020-06-13 23:28:55 -07:00
|
|
|
|
{
|
|
|
|
|
|
// If the reader is somehow null, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
reader.ReadNextLine();
|
2020-12-20 22:01:05 -08:00
|
|
|
|
do
|
2020-06-13 23:28:55 -07:00
|
|
|
|
{
|
|
|
|
|
|
// We don't care about whitespace or comments
|
|
|
|
|
|
// We're keeping keyvalue in case a file has '=' in the row
|
|
|
|
|
|
if (reader.RowType != IniRowType.Invalid && reader.RowType != IniRowType.KeyValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Roms are not valid row formats, usually
|
2020-09-21 13:04:11 -07:00
|
|
|
|
string line = reader.CurrentLine;
|
2020-06-13 23:28:55 -07:00
|
|
|
|
|
|
|
|
|
|
// If we don't have a valid game, keep reading
|
|
|
|
|
|
if (!line.StartsWith("¬"))
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadNextLine();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Some old RC DATs have this behavior
|
|
|
|
|
|
if (line.Contains("¬N¬O"))
|
|
|
|
|
|
line = line.Replace("¬N¬O", string.Empty) + "¬¬";
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
The rominfo order is as follows:
|
|
|
|
|
|
1 - parent name
|
|
|
|
|
|
2 - parent description
|
|
|
|
|
|
3 - game name
|
|
|
|
|
|
4 - game description
|
|
|
|
|
|
5 - rom name
|
|
|
|
|
|
6 - rom crc
|
|
|
|
|
|
7 - rom size
|
|
|
|
|
|
8 - romof name
|
|
|
|
|
|
9 - merge name
|
|
|
|
|
|
*/
|
|
|
|
|
|
string[] rominfo = line.Split('¬');
|
|
|
|
|
|
Rom rom = new Rom
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = rominfo[5],
|
2020-12-09 22:33:49 -08:00
|
|
|
|
Size = Utilities.CleanLong(rominfo[7]),
|
2020-07-15 09:41:59 -07:00
|
|
|
|
CRC = rominfo[6],
|
2020-06-13 23:28:55 -07:00
|
|
|
|
ItemStatus = ItemStatus.None,
|
|
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = rominfo[3],
|
|
|
|
|
|
Description = rominfo[4],
|
|
|
|
|
|
CloneOf = rominfo[1],
|
|
|
|
|
|
RomOf = rominfo[8],
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2020-06-14 13:05:28 -07:00
|
|
|
|
MergeTag = rominfo[9],
|
2020-06-13 23:28:55 -07:00
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2020-06-13 23:28:55 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Now process and add the rom
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(rom, statsOnly);
|
2020-06-13 23:28:55 -07:00
|
|
|
|
|
|
|
|
|
|
reader.ReadNextLine();
|
2020-12-20 22:01:05 -08:00
|
|
|
|
} while (!reader.EndOfStream && reader.Section.ToLowerInvariant() == "games");
|
2020-06-13 23:28:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-18 17:12:31 -07:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
protected override ItemType[] GetSupportedTypes()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ItemType[] { ItemType.Rom };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-18 12:09:09 -08:00
|
|
|
|
/// <inheritdoc/>
|
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
|
|
|
|
|
|
{
|
2021-02-03 11:22:09 -08:00
|
|
|
|
logger.User($"Writing to '{outfile}'...");
|
2020-12-08 00:13:22 -08:00
|
|
|
|
FileStream fs = File.Create(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-06-14 13:05:28 -07:00
|
|
|
|
IniWriter iw = new IniWriter(fs, new UTF8Encoding(false));
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Write out the header
|
2020-06-14 13:05:28 -07:00
|
|
|
|
WriteHeader(iw);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Write out each of the machines and roms
|
|
|
|
|
|
string lastgame = null;
|
|
|
|
|
|
List<string> splitpath = new List<string>();
|
|
|
|
|
|
|
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
|
|
|
|
|
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(iw, 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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-03 11:22:09 -08:00
|
|
|
|
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
2020-06-14 13:05:28 -07:00
|
|
|
|
iw.Dispose();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
fs.Dispose();
|
|
|
|
|
|
}
|
2021-01-12 15:54:14 -08:00
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error(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-14 13:05:28 -07:00
|
|
|
|
/// <param name="iw">IniWriter to output to</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteHeader(IniWriter iw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
iw.WriteSection("CREDITS");
|
|
|
|
|
|
iw.WriteKeyValuePair("author", Header.Author);
|
|
|
|
|
|
iw.WriteKeyValuePair("version", Header.Version);
|
|
|
|
|
|
iw.WriteKeyValuePair("comment", Header.Comment);
|
2020-06-14 13:05:28 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
iw.WriteSection("DAT");
|
|
|
|
|
|
iw.WriteKeyValuePair("version", Header.RomCenterVersion ?? "2.50");
|
|
|
|
|
|
iw.WriteKeyValuePair("plugin", Header.System);
|
|
|
|
|
|
iw.WriteKeyValuePair("split", Header.ForceMerging == MergingFlag.Split ? "1" : "0");
|
|
|
|
|
|
iw.WriteKeyValuePair("merge", Header.ForceMerging == MergingFlag.Full || Header.ForceMerging == MergingFlag.Merged ? "1" : "0");
|
2020-06-14 13:05:28 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
iw.WriteSection("EMULATOR");
|
|
|
|
|
|
iw.WriteKeyValuePair("refname", Header.Name);
|
|
|
|
|
|
iw.WriteKeyValuePair("version", Header.Description);
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
iw.WriteSection("GAMES");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
iw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DatItem using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-14 13:05:28 -07:00
|
|
|
|
/// <param name="iw">IniWriter 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(IniWriter iw, DatItem datItem)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-06-13 23:28:55 -07:00
|
|
|
|
/*
|
|
|
|
|
|
The rominfo order is as follows:
|
|
|
|
|
|
1 - parent name
|
|
|
|
|
|
2 - parent description
|
|
|
|
|
|
3 - game name
|
|
|
|
|
|
4 - game description
|
|
|
|
|
|
5 - rom name
|
|
|
|
|
|
6 - rom crc
|
|
|
|
|
|
7 - rom size
|
|
|
|
|
|
8 - romof name
|
|
|
|
|
|
9 - merge name
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
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)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.Rom:
|
|
|
|
|
|
var rom = datItem as Rom;
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}");
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(rom.Machine.Description ?? string.Empty))
|
|
|
|
|
|
iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}");
|
|
|
|
|
|
else
|
|
|
|
|
|
iw.WriteString($"¬{rom.Machine.Description ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString($"¬{rom.Name ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString($"¬{rom.CRC ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString($"¬{rom.Size?.ToString() ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString($"¬{rom.Machine.RomOf ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString($"¬{rom.MergeTag ?? string.Empty}");
|
|
|
|
|
|
iw.WriteString("¬");
|
|
|
|
|
|
iw.WriteLine();
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
iw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-09 18:04:49 -07:00
|
|
|
|
}
|