2017-10-09 18:04:49 -07:00
|
|
|
|
using System;
|
2022-11-03 17:02:38 -07:00
|
|
|
|
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;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
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-08 00:13:22 -08:00
|
|
|
|
using SabreTools.IO;
|
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 MAME Listrom DAT
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class Listrom : DatFile
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor designed for casting a base DatFile
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
|
|
|
|
|
public Listrom(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/>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// In a new style MAME listrom DAT, each game has the following format:
|
|
|
|
|
|
///
|
2023-07-12 10:57:46 -04:00
|
|
|
|
/// ROMs required for driver "testdriver".
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// Name Size Checksum
|
2023-07-12 10:57:46 -04:00
|
|
|
|
/// abcd.bin 1024 CRC(00000000) SHA1(da39a3ee5e6b4b0d3255bfef95601890afd80709)
|
|
|
|
|
|
/// efgh.bin 1024 BAD CRC(00000000) SHA1(da39a3ee5e6b4b0d3255bfef95601890afd80709) BAD_DUMP
|
|
|
|
|
|
/// ijkl.bin 1024 NO GOOD DUMP KNOWN
|
2023-07-13 17:52:25 -04:00
|
|
|
|
/// abcd SHA1(da39a3ee5e6b4b0d3255bfef95601890afd80709)
|
|
|
|
|
|
/// efgh BAD (da39a3ee5e6b4b0d3255bfef95601890afd80709) BAD_DUMP
|
|
|
|
|
|
/// ijkl NO GOOD DUMP KNOWN
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// </remarks>
|
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
|
|
|
|
{
|
|
|
|
|
|
// Open a file reader
|
2020-12-10 22:16:53 -08:00
|
|
|
|
Encoding enc = filename.GetEncoding();
|
2023-04-19 16:39:58 -04:00
|
|
|
|
StreamReader sr = new(System.IO.File.OpenRead(filename), enc);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string gamename = string.Empty;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
while (!sr.EndOfStream)
|
|
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
try
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
string line = sr.ReadLine().Trim();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// If we have a blank line, we just skip it
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(line))
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
continue;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// If we have the descriptor line, ignore it
|
|
|
|
|
|
else if (line == "Name Size Checksum")
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// If we have the beginning of a game, set the name of the game
|
|
|
|
|
|
else if (line.StartsWith("ROMs required for"))
|
|
|
|
|
|
{
|
2020-12-20 15:09:36 -08:00
|
|
|
|
gamename = Regex.Match(line, @"^ROMs required for \S*? ""(.*?)""\.").Groups[1].Value;
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// If we have a machine with no required roms (usually internal devices), skip it
|
|
|
|
|
|
else if (line.StartsWith("No ROMs required for"))
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// Otherwise, we assume we have a rom that we need to add
|
|
|
|
|
|
else
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// First, we preprocess the line so that the rom name is consistently correct
|
|
|
|
|
|
string[] split = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// If the line doesn't have the 4 spaces of padding, check for 3
|
|
|
|
|
|
if (split.Length == 1)
|
|
|
|
|
|
split = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// If the split is still unsuccessful, log it and skip
|
|
|
|
|
|
if (split.Length == 1)
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Warning($"Possibly malformed line: '{line}'");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
string romname = split[0];
|
2020-12-14 16:01:28 -08:00
|
|
|
|
line = line[romname.Length..];
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// Next we separate the ROM into pieces
|
2023-04-19 16:39:58 -04:00
|
|
|
|
split = line.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-21 13:04:11 -07:00
|
|
|
|
// Standard Disks have 2 pieces (name, sha1)
|
|
|
|
|
|
if (split.Length == 1)
|
|
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
Disk disk = new()
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
Name = romname,
|
2020-12-09 22:27:41 -08:00
|
|
|
|
SHA1 = CleanListromHashData(split[0]),
|
2020-09-21 13:04:11 -07:00
|
|
|
|
|
|
|
|
|
|
Machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = gamename,
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(disk, statsOnly);
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Baddump Disks have 4 pieces (name, BAD, sha1, BAD_DUMP)
|
|
|
|
|
|
else if (split.Length == 3 && line.EndsWith("BAD_DUMP"))
|
|
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
Disk disk = new()
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
Name = romname,
|
2020-12-09 22:27:41 -08:00
|
|
|
|
SHA1 = CleanListromHashData(split[1]),
|
2020-09-21 13:04:11 -07:00
|
|
|
|
ItemStatus = ItemStatus.BadDump,
|
|
|
|
|
|
|
|
|
|
|
|
Machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = gamename,
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(disk, statsOnly);
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Standard ROMs have 4 pieces (name, size, crc, sha1)
|
|
|
|
|
|
else if (split.Length == 3)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
Rom rom = new()
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
Name = romname,
|
2020-12-09 22:33:49 -08:00
|
|
|
|
Size = Utilities.CleanLong(split[0]),
|
2020-12-09 22:27:41 -08:00
|
|
|
|
CRC = CleanListromHashData(split[1]),
|
|
|
|
|
|
SHA1 = CleanListromHashData(split[2]),
|
2020-09-21 13:04:11 -07:00
|
|
|
|
|
|
|
|
|
|
Machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = gamename,
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(rom, statsOnly);
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Nodump Disks have 5 pieces (name, NO, GOOD, DUMP, KNOWN)
|
|
|
|
|
|
else if (split.Length == 4 && line.EndsWith("NO GOOD DUMP KNOWN"))
|
|
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
Disk disk = new()
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
Name = romname,
|
|
|
|
|
|
ItemStatus = ItemStatus.Nodump,
|
|
|
|
|
|
|
|
|
|
|
|
Machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = gamename,
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(disk, statsOnly);
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP)
|
|
|
|
|
|
else if (split.Length == 5 && line.EndsWith("BAD_DUMP"))
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
Rom rom = new()
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
Name = romname,
|
2020-12-09 22:33:49 -08:00
|
|
|
|
Size = Utilities.CleanLong(split[0]),
|
2020-12-09 22:27:41 -08:00
|
|
|
|
CRC = CleanListromHashData(split[2]),
|
|
|
|
|
|
SHA1 = CleanListromHashData(split[3]),
|
2020-09-21 13:04:11 -07:00
|
|
|
|
ItemStatus = ItemStatus.BadDump,
|
|
|
|
|
|
|
|
|
|
|
|
Machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = gamename,
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(rom, statsOnly);
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN)
|
|
|
|
|
|
else if (split.Length == 5 && line.EndsWith("NO GOOD DUMP KNOWN"))
|
|
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
Rom rom = new()
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-09-21 13:04:11 -07:00
|
|
|
|
Name = romname,
|
2020-12-09 22:33:49 -08:00
|
|
|
|
Size = Utilities.CleanLong(split[0]),
|
2020-09-21 13:04:11 -07:00
|
|
|
|
ItemStatus = ItemStatus.Nodump,
|
|
|
|
|
|
|
|
|
|
|
|
Machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = gamename,
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(rom, statsOnly);
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have something else, it's invalid
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Warning($"Invalid line detected: '{romname} {line}'");
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
2020-09-21 13:04:11 -07:00
|
|
|
|
}
|
2021-01-12 15:54:14 -08:00
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
2020-09-21 13:04:11 -07:00
|
|
|
|
{
|
|
|
|
|
|
string message = $"'{filename}' - There was an error parsing at position {sr.BaseStream.Position}";
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error(ex, message);
|
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.Disk, ItemType.Rom };
|
2022-11-03 17:02:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
protected override List<DatItemField> GetMissingRequiredFields(DatItem datItem)
|
|
|
|
|
|
{
|
2023-04-19 16:39:58 -04:00
|
|
|
|
List<DatItemField> missingFields = new();
|
2022-11-03 21:20:18 -07:00
|
|
|
|
|
|
|
|
|
|
// Check item name
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(datItem.GetName()))
|
|
|
|
|
|
missingFields.Add(DatItemField.Name);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Should CRC/SHA1 be included here? Unclear right now if fully required. Probably is, though
|
|
|
|
|
|
|
2022-11-03 17:02:38 -07:00
|
|
|
|
return null;
|
2020-09-18 17:12:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
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}'...");
|
2023-04-17 13:22:35 -04:00
|
|
|
|
FileStream fs = System.IO.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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-19 16:39:58 -04:00
|
|
|
|
StreamWriter sw = new(fs, new UTF8Encoding(false));
|
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
|
|
|
|
{
|
2021-07-18 21:00:01 -07:00
|
|
|
|
ConcurrentList<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())
|
2019-01-11 13:43:15 -08:00
|
|
|
|
WriteEndGame(sw);
|
|
|
|
|
|
|
|
|
|
|
|
// 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(sw, 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(sw, 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}");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
sw.Dispose();
|
|
|
|
|
|
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 Game start using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sw">StreamWriter to output to</param>
|
|
|
|
|
|
/// <param name="rom">DatItem object to be output</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteStartGame(StreamWriter sw, DatItem rom)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// No game should start with a path separator
|
|
|
|
|
|
rom.Machine.Name = rom.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Build the state
|
|
|
|
|
|
sw.Write($"ROMs required for driver \"{rom.Machine.Name}\".\n");
|
|
|
|
|
|
sw.Write("Name Size Checksum\n");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
sw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out Game end using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sw">StreamWriter to output to</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteEndGame(StreamWriter sw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End driver
|
|
|
|
|
|
sw.Write("\n");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
sw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DatItem using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sw">StreamWriter 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(StreamWriter sw, 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.Disk:
|
|
|
|
|
|
var disk = datItem as Disk;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// The name is padded out to a particular length
|
|
|
|
|
|
if (disk.Name.Length < 43)
|
|
|
|
|
|
sw.Write(disk.Name.PadRight(43, ' '));
|
|
|
|
|
|
else
|
|
|
|
|
|
sw.Write($"{disk.Name} ");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// If we have a baddump, put the first indicator
|
|
|
|
|
|
if (disk.ItemStatus == ItemStatus.BadDump)
|
|
|
|
|
|
sw.Write(" BAD");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// If we have a nodump, write out the indicator
|
|
|
|
|
|
if (disk.ItemStatus == ItemStatus.Nodump)
|
|
|
|
|
|
sw.Write(" NO GOOD DUMP KNOWN");
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Otherwise, write out the SHA-1 hash
|
|
|
|
|
|
else if (!string.IsNullOrWhiteSpace(disk.SHA1))
|
|
|
|
|
|
sw.Write($" SHA1({disk.SHA1 ?? string.Empty})");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// If we have a baddump, put the second indicator
|
|
|
|
|
|
if (disk.ItemStatus == ItemStatus.BadDump)
|
|
|
|
|
|
sw.Write(" BAD_DUMP");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
sw.Write("\n");
|
|
|
|
|
|
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;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// The name is padded out to a particular length
|
|
|
|
|
|
if (rom.Name.Length < 43)
|
|
|
|
|
|
sw.Write(rom.Name.PadRight(43 - rom.Size?.ToString().Length ?? 0, ' '));
|
|
|
|
|
|
else
|
|
|
|
|
|
sw.Write($"{rom.Name} ");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// If we don't have a nodump, write out the size
|
|
|
|
|
|
if (rom.ItemStatus != ItemStatus.Nodump)
|
|
|
|
|
|
sw.Write(rom.Size?.ToString() ?? string.Empty);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// If we have a baddump, put the first indicator
|
|
|
|
|
|
if (rom.ItemStatus == ItemStatus.BadDump)
|
|
|
|
|
|
sw.Write(" BAD");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// If we have a nodump, write out the indicator
|
|
|
|
|
|
if (rom.ItemStatus == ItemStatus.Nodump)
|
|
|
|
|
|
{
|
|
|
|
|
|
sw.Write(" NO GOOD DUMP KNOWN");
|
|
|
|
|
|
}
|
|
|
|
|
|
// Otherwise, write out the CRC and SHA-1 hashes
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rom.CRC))
|
|
|
|
|
|
sw.Write($" CRC({rom.CRC ?? string.Empty})");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rom.SHA1))
|
|
|
|
|
|
sw.Write($" SHA1({rom.SHA1 ?? string.Empty})");
|
|
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// If we have a baddump, put the second indicator
|
|
|
|
|
|
if (rom.ItemStatus == ItemStatus.BadDump)
|
|
|
|
|
|
sw.Write(" BAD_DUMP");
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
sw.Write("\n");
|
|
|
|
|
|
break;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
sw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-09 18:04:49 -07:00
|
|
|
|
}
|