Write-as-you-go for non-XML

This commit is contained in:
Matt Nadareski
2020-06-12 11:02:23 -07:00
parent f00fdfa1ec
commit d27f75b955
9 changed files with 253 additions and 309 deletions

View File

@@ -193,10 +193,8 @@ namespace SabreTools.Library.DatFiles
{
try
{
string header = "#Title;Name;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons\n";
sw.Write("#Title;Name;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons\n");
// Write the header out
sw.Write(header);
sw.Flush();
}
catch (Exception ex)
@@ -229,27 +227,24 @@ namespace SabreTools.Library.DatFiles
// Pre-process the item name
ProcessItemName(datItem, true);
string state = string.Empty;
sw.Write($"{datItem.GetField(Field.MachineName, ExcludeFields)};");
sw.Write($"{datItem.GetField(Field.Description, ExcludeFields)};");
sw.Write($"{FileName};");
sw.Write($"{datItem.GetField(Field.CloneOf, ExcludeFields)};");
sw.Write($"{datItem.GetField(Field.Year, ExcludeFields)};");
sw.Write($"{datItem.GetField(Field.Manufacturer, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.Category, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.Players, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.Rotation, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.Control, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.Status, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.DisplayCount, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.DisplayType, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.AltRomname, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.AltTitle, ExcludeFields)};");
sw.Write($"{datItem.GetField(Field.Comment, ExcludeFields)};");
sw.Write(";"); // $"{datItem.GetField(Field.Buttons, ExcludeFields)};");
state += $"{datItem.GetField(Field.MachineName, ExcludeFields)};";
state += $"{datItem.GetField(Field.Description, ExcludeFields)};";
state += $"{FileName};";
state += $"{datItem.GetField(Field.CloneOf, ExcludeFields)};";
state += $"{datItem.GetField(Field.Year, ExcludeFields)};";
state += $"{datItem.GetField(Field.Manufacturer, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.Category, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.Players, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.Rotation, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.Control, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.Status, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.DisplayCount, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.DisplayType, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.AltRomname, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.AltTitle, ExcludeFields)};";
state += $"{datItem.GetField(Field.Comment, ExcludeFields)};";
state += ";"; // $"{datItem.GetField(Field.Buttons, ExcludeFields)};";
sw.Write(state);
sw.Flush();
}
catch (Exception ex)

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a ClrMamePro DAT
/// </summary>
/// TODO: Verify that all write for this DatFile type is correct
/// TODO: Can there be a writer like XmlTextWriter for this? Or too inconsistent?
internal class ClrMamePro : DatFile
{
/// <summary>
@@ -764,51 +764,53 @@ namespace SabreTools.Library.DatFiles
{
try
{
string header = "clrmamepro (\n";
header += $"\tname \"{Name}\"\n";
header += $"\tdescription \"{Description}\"\n";
sw.Write("clrmamepro (\n");
sw.Write($"\tname \"{Name}\"\n");
sw.Write($"\tdescription \"{Description}\"\n");
if (!string.IsNullOrWhiteSpace(Category))
header += $"\tcategory \"{Category}\"\n";
header += $"\tversion \"{Version}\"\n";
sw.Write($"\tcategory \"{Category}\"\n");
sw.Write($"\tversion \"{Version}\"\n");
if (!string.IsNullOrWhiteSpace(Date))
header += $"\tdate \"{Date}\"\n";
header += $"\tauthor \"{Author}\"\n";
sw.Write($"\tdate \"{Date}\"\n");
sw.Write($"\tauthor \"{Author}\"\n");
if (!string.IsNullOrWhiteSpace(Email))
header += $"\temail \"{Email}\"\n";
sw.Write($"\temail \"{Email}\"\n");
if (!string.IsNullOrWhiteSpace(Homepage))
header += $"\thomepage \"{Homepage}\"\n";
sw.Write($"\thomepage \"{Homepage}\"\n");
if (!string.IsNullOrWhiteSpace(Url))
header += $"\turl \"{Url}\"\n";
sw.Write($"\turl \"{Url}\"\n");
if (!string.IsNullOrWhiteSpace(Comment))
header += $"\tcomment \"{Comment}\"\n";
sw.Write($"\tcomment \"{Comment}\"\n");
switch (ForcePacking)
{
case ForcePacking.Unzip:
header += "\tforcezipping no\n";
sw.Write($"\tforcezipping no\n");
break;
case ForcePacking.Zip:
header += "\tforcezipping yes\n";
sw.Write($"\tforcezipping yes\n");
break;
}
switch (ForceMerging)
{
case ForceMerging.Full:
header += "\tforcemerging full\n";
sw.Write($"\tforcemerging full\n");
break;
case ForceMerging.Split:
header += "\tforcemerging split\n";
sw.Write($"\tforcemerging split\n");
break;
case ForceMerging.Merged:
header += "\tforcemerging merged\n";
sw.Write($"\tforcemerging merged\n");
break;
case ForceMerging.NonMerged:
header += "\tforcemerging nonmerged\n";
sw.Write($"\tforcemerging nonmerged\n");
break;
}
header += ")\n";
// Write the header out
sw.Write(header);
// End clrmamepro
sw.Write(")\n");
sw.Flush();
}
catch (Exception ex)
@@ -834,23 +836,23 @@ namespace SabreTools.Library.DatFiles
datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar);
// Build the state based on excluded fields
string state = (datItem.MachineType == MachineType.Bios ? "resource" : "game");
state += $" (\n\tname \"{datItem.MachineName}\"\n";
state += $"\tromof \"{datItem.RomOf}\"\n";
sw.Write($"{(datItem.MachineType == MachineType.Bios ? "resource" : "game")} (\n");
sw.Write($"\tname \"{datItem.MachineName}\"\n");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RomOf, ExcludeFields)))
sw.Write($"\tromof \"{datItem.RomOf}\"\n");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, ExcludeFields)))
state += $"\tcloneof \"{datItem.CloneOf}\"\n";
sw.Write($"\tcloneof \"{datItem.CloneOf}\"\n");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, ExcludeFields)))
state += $"\tsampleof \"{datItem.SampleOf}\"\n";
sw.Write($"\tsampleof \"{datItem.SampleOf}\"\n");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, ExcludeFields)))
state += $"\tdescription \"{datItem.MachineDescription}\"\n";
sw.Write($"\tdescription \"{datItem.MachineDescription}\"\n");
else if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Description, ExcludeFields)))
state += $"\tdescription \"{datItem.MachineName}\"\n";
sw.Write($"\tdescription \"{datItem.MachineName}\"\n");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Year, ExcludeFields)))
state += $"\tyear \"{datItem.Year}\"\n";
sw.Write($"\tyear \"{datItem.Year}\"\n");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Manufacturer, ExcludeFields)))
state += $"\tmanufacturer \"{datItem.Manufacturer}\"\n";
sw.Write($"\tmanufacturer \"{datItem.Manufacturer}\"\n");
sw.Write(state);
sw.Flush();
}
catch (Exception ex)
@@ -876,11 +878,11 @@ namespace SabreTools.Library.DatFiles
// Build the state based on excluded fields
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, ExcludeFields)))
state += $"\tsampleof \"{datItem.SampleOf}\"\n";
sw.Write($"\tsampleof \"{datItem.SampleOf}\"\n");
state += ")\n";
// End game
sw.Write(")\n");
sw.Write(state);
sw.Flush();
}
catch (Exception ex)
@@ -917,83 +919,89 @@ namespace SabreTools.Library.DatFiles
switch (datItem.ItemType)
{
case ItemType.Archive:
state += $"\tarchive ( name\"{datItem.GetField(Field.Name, ExcludeFields)}\"";
state += " )\n";
sw.Write("\tarchive (");
sw.Write($" name\"{datItem.GetField(Field.Name, ExcludeFields)}\"");
sw.Write(" )\n");
break;
case ItemType.BiosSet:
var biosSet = datItem as BiosSet;
state += $"\tbiosset ( name\"{datItem.GetField(Field.Name, ExcludeFields)}\"";
sw.Write("\tbiosset (");
sw.Write($" name\"{biosSet.GetField(Field.Name, ExcludeFields)}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.BiosDescription, ExcludeFields)))
state += $" description \"{biosSet.Description}\"";
sw.Write($" description \"{biosSet.Description}\"");
if (!ExcludeFields[(int)Field.Default] && biosSet.Default != null)
state += $" default \"{biosSet.Default.ToString().ToLowerInvariant()}\"";
state += " )\n";
sw.Write($" default \"{biosSet.Default.ToString().ToLowerInvariant()}\"");
sw.Write(" )\n");
break;
case ItemType.Disk:
var disk = datItem as Disk;
state += $"\tdisk ( name \"{datItem.GetField(Field.Name, ExcludeFields)}\"";
sw.Write("\tdisk (");
sw.Write($" name\"{disk.GetField(Field.Name, ExcludeFields)}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.MD5, ExcludeFields)))
state += $" md5 \"{disk.MD5.ToLowerInvariant()}\"";
sw.Write($" md5 \"{disk.MD5.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RIPEMD160, ExcludeFields)))
state += $" ripemd160 \"{disk.RIPEMD160.ToLowerInvariant()}\"";
sw.Write($" ripemd160 \"{disk.RIPEMD160.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA1, ExcludeFields)))
state += $" sha1 \"{disk.SHA1.ToLowerInvariant()}\"";
sw.Write($" sha1 \"{disk.SHA1.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA256, ExcludeFields)))
state += $" sha256 \"{disk.SHA256.ToLowerInvariant()}\"";
sw.Write($" sha256 \"{disk.SHA256.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA384, ExcludeFields)))
state += $" sha384 \"{disk.SHA384.ToLowerInvariant()}\"";
sw.Write($" sha384 \"{disk.SHA384.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA512, ExcludeFields)))
state += $" sha512 \"{disk.SHA512.ToLowerInvariant()}\"";
sw.Write($" sha512 \"{disk.SHA512.ToLowerInvariant()}\"");
if (!ExcludeFields[(int)Field.Status] && disk.ItemStatus != ItemStatus.None)
state += $" flags \"{disk.ItemStatus.ToString().ToLowerInvariant()}\"";
state += " )\n";
sw.Write($" flags \"{disk.ItemStatus.ToString().ToLowerInvariant()}\"");
sw.Write(" )\n");
break;
case ItemType.Release:
var release = datItem as Release;
state += $"\trelease ( name\"{datItem.GetField(Field.Name, ExcludeFields)}\"";
sw.Write("\trelease (");
sw.Write($" name\"{release.GetField(Field.Name, ExcludeFields)}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Region, ExcludeFields)))
state += $" region \"{release.Region}\"";
sw.Write($" region \"{release.Region}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Language, ExcludeFields)))
state += $" language \"{release.Language}\"";
sw.Write($" language \"{release.Language}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Date, ExcludeFields)))
state += $" date \"{release.Date}\"";
sw.Write($" date \"{release.Date}\"");
if (!ExcludeFields[(int)Field.Default] && release.Default != null)
state += $" default \"{release.Default.ToString().ToLowerInvariant()}\"";
state += " )\n";
sw.Write($" default \"{release.Default.ToString().ToLowerInvariant()}\"");
sw.Write(" )\n");
break;
case ItemType.Rom:
var rom = datItem as Rom;
state += $"\trom ( name \"{datItem.GetField(Field.Name, ExcludeFields)}\"";
sw.Write("\trom (");
sw.Write($" name\"{rom.GetField(Field.Name, ExcludeFields)}\"");
if (!ExcludeFields[(int)Field.Size] && rom.Size != -1)
state += $" size \"{rom.Size}\"";
sw.Write($" size \"{rom.Size}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CRC, ExcludeFields)))
state += $" crc \"{rom.CRC.ToLowerInvariant()}\"";
sw.Write($" crc \"{rom.CRC.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.MD5, ExcludeFields)))
state += $" md5 \"{rom.MD5.ToLowerInvariant()}\"";
sw.Write($" md5 \"{rom.MD5.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RIPEMD160, ExcludeFields)))
state += $" ripemd160 \"{rom.RIPEMD160.ToLowerInvariant()}\"";
sw.Write($" ripemd160 \"{rom.RIPEMD160.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA1, ExcludeFields)))
state += $" sha1 \"{rom.SHA1.ToLowerInvariant()}\"";
sw.Write($" sha1 \"{rom.SHA1.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA256, ExcludeFields)))
state += $" sha256 \"{rom.SHA256.ToLowerInvariant()}\"";
sw.Write($" sha256 \"{rom.SHA256.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA384, ExcludeFields)))
state += $" sha384 \"{rom.SHA384.ToLowerInvariant()}\"";
sw.Write($" sha384 \"{rom.SHA384.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA512, ExcludeFields)))
state += $" sha512 \"{rom.SHA512.ToLowerInvariant()}\"";
sw.Write($" sha512 \"{rom.SHA512.ToLowerInvariant()}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Date, ExcludeFields)))
state += $" date \"{rom.Date}\"";
sw.Write($" date \"{rom.Date}\"");
if (!ExcludeFields[(int)Field.Status] && rom.ItemStatus != ItemStatus.None)
state += $" flags \"{rom.ItemStatus.ToString().ToLowerInvariant()}\"";
state += " )\n";
sw.Write($" flags \"{rom.ItemStatus.ToString().ToLowerInvariant()}\"");
sw.Write(" )\n");
break;
case ItemType.Sample:
state += $"\tsample ( name\"{datItem.GetField(Field.Name, ExcludeFields)}\"";
state += " )\n";
sw.Write("\tsample (");
sw.Write($" name\"{datItem.GetField(Field.Name, ExcludeFields)}\"");
sw.Write(" )\n");
break;
}
@@ -1018,10 +1026,9 @@ namespace SabreTools.Library.DatFiles
{
try
{
string footer = footer = ")\n";
// End game
sw.Write(")\n");
// Write the footer out
sw.Write(footer);
sw.Flush();
}
catch (Exception ex)

View File

@@ -162,18 +162,16 @@ namespace SabreTools.Library.DatFiles
{
try
{
string header = "DOSCenter (\n";
header += $"\tName: {Name}\n";
header += $"\tDescription: {Description}\n";
header += $"\tVersion: {Version}\n";
header += $"\tDate: {Date}\n";
header += $"\tAuthor: {Author}\n";
header += $"\tHomepage: {Homepage}\n";
header += $"\tComment: {Comment}\n";
header += ")\n";
sw.Write("DOSCenter (\n");
sw.Write($"\tName: {Name}\n");
sw.Write($"\tDescription: {Description}\n");
sw.Write($"\tVersion: {Version}\n");
sw.Write($"\tDate: {Date}\n");
sw.Write($"\tAuthor: {Author}\n");
sw.Write($"\tHomepage: {Homepage}\n");
sw.Write($"\tComment: {Comment}\n");
sw.Write(")\n");
// Write the header out
sw.Write(header);
sw.Flush();
}
catch (Exception ex)
@@ -199,9 +197,9 @@ namespace SabreTools.Library.DatFiles
datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar);
// Build the state based on excluded fields
string state = $"game (\n\tname \"{datItem.GetField(Field.MachineName, ExcludeFields)}.zip\n";
sw.Write("game (\n");
sw.Write($"\tname \"{datItem.GetField(Field.MachineName, ExcludeFields)}.zip\n");
sw.Write(state);
sw.Flush();
}
catch (Exception ex)
@@ -223,15 +221,13 @@ namespace SabreTools.Library.DatFiles
{
try
{
string state = string.Empty;
// Build the state based on excluded fields
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SampleOf, ExcludeFields)))
state += $"\tsampleof \"{datItem.SampleOf}\"\n";
sw.Write($"\tsampleof \"{datItem.SampleOf}\"\n");
state += ")\n";
// End game
sw.Write(")\n");
sw.Write(state);
sw.Flush();
}
catch (Exception ex)
@@ -266,23 +262,17 @@ namespace SabreTools.Library.DatFiles
// Build the state based on excluded fields
switch (datItem.ItemType)
{
case ItemType.Archive:
case ItemType.BiosSet:
case ItemType.Disk:
case ItemType.Release:
case ItemType.Sample:
// We don't output these at all for DosCenter
break;
case ItemType.Rom:
var rom = datItem as Rom;
state += $"\file ( name \"{datItem.GetField(Field.Name, ExcludeFields)}\"";
sw.Write("\tfile (");
sw.Write($" name \"{datItem.GetField(Field.Name, ExcludeFields)}\"");
if (!ExcludeFields[(int)Field.Size] && rom.Size != -1)
state += $" size \"{rom.Size}\"";
sw.Write($" size \"{rom.Size}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Date, ExcludeFields)))
state += $" date \"{rom.Date}\"";
sw.Write($" date \"{rom.Date}\"");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CRC, ExcludeFields)))
state += $" crc \"{rom.CRC.ToLowerInvariant()}\"";
state += " )\n";
sw.Write($" crc \"{rom.CRC.ToLowerInvariant()}\"");
sw.Write(" )\n");
break;
}
@@ -307,10 +297,10 @@ namespace SabreTools.Library.DatFiles
{
try
{
string footer = ")\n";
// End game
sw.Write(")\n");
// Write the footer out
sw.Write(footer);
sw.Flush();
}
catch (Exception ex)

View File

@@ -177,32 +177,21 @@ namespace SabreTools.Library.DatFiles
// Pre-process the item name
ProcessItemName(datItem, true);
string state = string.Empty;
// Build the state based on excluded fields
switch (datItem.ItemType)
{
case ItemType.Archive:
case ItemType.BiosSet:
case ItemType.Disk:
case ItemType.Release:
case ItemType.Sample:
// We don't output these at all for Everdrive SMDB
break;
case ItemType.Rom:
var rom = datItem as Rom;
state += $"{rom.GetField(Field.SHA256, ExcludeFields)}\t";
state += $"{rom.GetField(Field.MachineName, ExcludeFields)}/\t";
state += $"{rom.GetField(Field.Name, ExcludeFields)}\t";
state += $"{rom.GetField(Field.SHA1, ExcludeFields)}\t";
state += $"{rom.GetField(Field.MD5, ExcludeFields)}\t";
state += $"{rom.GetField(Field.CRC, ExcludeFields)}";
state += "\n";
sw.Write($"{rom.GetField(Field.SHA256, ExcludeFields)}\t");
sw.Write($"{rom.GetField(Field.MachineName, ExcludeFields)}/\t");
sw.Write($"{rom.GetField(Field.Name, ExcludeFields)}\t");
sw.Write($"{rom.GetField(Field.SHA1, ExcludeFields)}\t");
sw.Write($"{rom.GetField(Field.MD5, ExcludeFields)}\t");
sw.Write($"{rom.GetField(Field.CRC, ExcludeFields)}");
sw.Write("\n");
break;
}
sw.Write(state);
sw.Flush();
}
catch (Exception ex)

View File

@@ -195,14 +195,16 @@ namespace SabreTools.Library.DatFiles
switch (_hash)
{
case Hash.CRC:
if (datItem.ItemType == ItemType.Rom)
switch (datItem.ItemType)
{
case ItemType.Rom:
var rom = datItem as Rom;
if (GameName)
state += $"{rom.GetField(Field.MachineName, ExcludeFields)}{Path.DirectorySeparatorChar}";
state += $"{rom.GetField(Field.Name, ExcludeFields)}";
state += $"{rom.GetField(Field.CRC, ExcludeFields)}";
state += "\n";
sw.Write($"{rom.GetField(Field.MachineName, ExcludeFields)}{Path.DirectorySeparatorChar}");
sw.Write($"{rom.GetField(Field.Name, ExcludeFields)}");
sw.Write($"{rom.GetField(Field.CRC, ExcludeFields)}");
sw.Write("\n");
break;
}
break;
@@ -213,23 +215,26 @@ namespace SabreTools.Library.DatFiles
case Hash.SHA384:
case Hash.SHA512:
Field hashField = Utilities.GetFieldFromHash(_hash);
if (datItem.ItemType == ItemType.Rom)
{
var rom = datItem as Rom;
state += $"{rom.GetField(hashField, ExcludeFields)}";
if (GameName)
state += $"{rom.GetField(Field.MachineName, ExcludeFields)}{Path.DirectorySeparatorChar}";
state += $"{rom.GetField(Field.Name, ExcludeFields)}";
state += "\n";
}
else if (datItem.ItemType == ItemType.Disk)
switch (datItem.ItemType)
{
case ItemType.Disk:
var disk = datItem as Disk;
state += $"{disk.GetField(hashField, ExcludeFields)}";
sw.Write($"{disk.GetField(hashField, ExcludeFields)}");
if (GameName)
state += $"{disk.GetField(Field.MachineName, ExcludeFields)}{Path.DirectorySeparatorChar}";
state += $"{disk.GetField(Field.Name, ExcludeFields)}";
state += "\n";
sw.Write($"{disk.GetField(Field.MachineName, ExcludeFields)}{Path.DirectorySeparatorChar}");
sw.Write($"{disk.GetField(Field.Name, ExcludeFields)}");
sw.Write("\n");
break;
case ItemType.Rom:
var rom = datItem as Rom;
sw.Write($"{rom.GetField(hashField, ExcludeFields)}");
if (GameName)
sw.Write($"{rom.GetField(Field.MachineName, ExcludeFields)}{Path.DirectorySeparatorChar}");
sw.Write($"{rom.GetField(Field.Name, ExcludeFields)}");
sw.Write("\n");
break;
}
break;
}

View File

@@ -325,10 +325,9 @@ namespace SabreTools.Library.DatFiles
rom.MachineName = rom.MachineName.TrimStart(Path.DirectorySeparatorChar);
// Build the state based on excluded fields
string state = $"ROMs required for driver \"{rom.GetField(Field.MachineName, ExcludeFields)}\".\n";
state += "Name Size Checksum\n";
sw.Write($"ROMs required for driver \"{rom.GetField(Field.MachineName, ExcludeFields)}\".\n");
sw.Write("Name Size Checksum\n");
sw.Write(state);
sw.Flush();
}
catch (Exception ex)
@@ -349,9 +348,9 @@ namespace SabreTools.Library.DatFiles
{
try
{
string state = "\n";
// End driver
sw.Write("\n");
sw.Write(state);
sw.Flush();
}
catch (Exception ex)
@@ -378,89 +377,79 @@ namespace SabreTools.Library.DatFiles
try
{
string state = string.Empty;
// Pre-process the item name
ProcessItemName(datItem, true);
// Build the state based on excluded fields
switch (datItem.ItemType)
{
case ItemType.Archive:
case ItemType.BiosSet:
case ItemType.Release:
case ItemType.Sample:
// We don't output these at all for Listrom
break;
case ItemType.Disk:
var disk = datItem as Disk;
// The name is padded out to a particular length
if (disk.Name.Length < 43)
state += disk.Name.PadRight(43, ' ');
sw.Write(disk.Name.PadRight(43, ' '));
else
state += disk.Name + " ";
sw.Write($"{disk.Name} ");
// If we have a baddump, put the first indicator
if (!ExcludeFields[(int)Field.Status] && disk.ItemStatus == ItemStatus.BadDump)
state += " BAD";
sw.Write(" BAD");
// If we have a nodump, write out the indicator
if (!ExcludeFields[(int)Field.Status] && disk.ItemStatus == ItemStatus.Nodump)
state += " NO GOOD DUMP KNOWN";
sw.Write(" NO GOOD DUMP KNOWN");
// Otherwise, write out the SHA-1 hash
else if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA1, ExcludeFields)))
state += $" SHA1({disk.SHA1})";
sw.Write($" SHA1({disk.SHA1})");
// If we have a baddump, put the second indicator
if (!ExcludeFields[(int)Field.Status] && disk.ItemStatus == ItemStatus.BadDump)
state += " BAD_DUMP";
sw.Write(" BAD_DUMP");
state += "\n";
sw.Write("\n");
break;
case ItemType.Rom:
var rom = datItem as Rom;
// The name is padded out to a particular length
if (rom.Name.Length < 40)
state += rom.Name.PadRight(43 - rom.Size.ToString().Length, ' ');
if (rom.Name.Length < 43)
sw.Write(rom.Name.PadRight(43 - rom.Size.ToString().Length, ' '));
else
state += rom.Name + " ";
sw.Write($"{rom.Name} ");
// If we don't have a nodump, write out the size
if (rom.ItemStatus != ItemStatus.Nodump)
state += rom.Size;
sw.Write(rom.Size);
// If we have a baddump, put the first indicator
if (!ExcludeFields[(int)Field.Status] && rom.ItemStatus == ItemStatus.BadDump)
state += " BAD";
sw.Write(" BAD");
// If we have a nodump, write out the indicator
if (!ExcludeFields[(int)Field.Status] && rom.ItemStatus == ItemStatus.Nodump)
{
state += " NO GOOD DUMP KNOWN";
sw.Write(" NO GOOD DUMP KNOWN");
}
// Otherwise, write out the CRC and SHA-1 hashes
else
{
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CRC, ExcludeFields)))
state += $" CRC({rom.CRC})";
sw.Write($" CRC({rom.CRC})");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA1, ExcludeFields)))
state += $" SHA1({rom.SHA1})";
sw.Write($" SHA1({rom.SHA1})");
}
// If we have a baddump, put the second indicator
if (!ExcludeFields[(int)Field.Status] && rom.ItemStatus == ItemStatus.BadDump)
state += " BAD_DUMP";
sw.Write(" BAD_DUMP");
state += "\n";
sw.Write("\n");
break;
}
sw.Write(state);
sw.Flush();
}
catch (Exception ex)

View File

@@ -150,19 +150,19 @@ namespace SabreTools.Library.DatFiles
// If we're in Romba mode, the state is consistent
if (Romba)
{
state += $"{datItem.GetField(Field.SHA1, ExcludeFields)}\n";
sw.Write($"{datItem.GetField(Field.SHA1, ExcludeFields)}\n");
}
// Otherwise, use any flags
else
{
if (!UseRomName && datItem.MachineName != lastgame)
{
state += $"{datItem.GetField(Field.MachineName, ExcludeFields)}\n";
sw.Write($"{datItem.GetField(Field.MachineName, ExcludeFields)}\n");
lastgame = datItem.MachineName;
}
else if (UseRomName)
{
state += $"{datItem.GetField(Field.Name, ExcludeFields)}\n";
sw.Write($"{datItem.GetField(Field.Name, ExcludeFields)}\n");
}
}

View File

@@ -228,21 +228,19 @@ namespace SabreTools.Library.DatFiles
{
try
{
string header = "[CREDITS]\n";
header += $"author={Author}\n";
header += $"version={Version}\n";
header += $"comment={Comment}\n";
header += "[DAT]\n";
header += "version=2.50\n";
header += $"split={(ForceMerging == ForceMerging.Split ? "1" : "0")}\n";
header += $"merge={(ForceMerging == ForceMerging.Full || ForceMerging == ForceMerging.Merged ? "1" : "0")}\n";
header += "[EMULATOR]\n";
header += $"refname={Name}\n";
header += $"version={Description}\n";
header += "[GAMES]\n";
sw.Write("[CREDITS]\n");
sw.Write($"author={Author}\n");
sw.Write($"version={Version}\n");
sw.Write($"comment={Comment}\n");
sw.Write("[DAT]\n");
sw.Write("version=2.50\n");
sw.Write($"split={(ForceMerging == ForceMerging.Split ? "1" : "0")}\n");
sw.Write($"merge={(ForceMerging == ForceMerging.Full || ForceMerging == ForceMerging.Merged ? "1" : "0")}\n");
sw.Write("[EMULATOR]\n");
sw.Write($"refname={Name}\n");
sw.Write($"version={Description}\n");
sw.Write("[GAMES]\n");
// Write the header out
sw.Write(header);
sw.Flush();
}
catch (Exception ex)
@@ -278,38 +276,38 @@ namespace SabreTools.Library.DatFiles
switch (datItem.ItemType)
{
case ItemType.Disk:
state += "¬";
sw.Write("¬");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, ExcludeFields)))
state += datItem.CloneOf;
state += "¬";
sw.Write(datItem.CloneOf);
sw.Write("¬");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, ExcludeFields)))
state += datItem.CloneOf;
state += $"¬{datItem.GetField(Field.MachineName, ExcludeFields)}";
sw.Write(datItem.CloneOf);
sw.Write($"¬{datItem.GetField(Field.MachineName, ExcludeFields)}");
if (string.IsNullOrWhiteSpace(datItem.MachineDescription))
state += $"¬{datItem.GetField(Field.MachineName, ExcludeFields)}";
sw.Write($"¬{datItem.GetField(Field.MachineName, ExcludeFields)}");
else
state += $"¬{datItem.GetField(Field.Description, ExcludeFields)}";
state += $"¬{datItem.GetField(Field.Name, ExcludeFields)}";
state += "¬¬¬¬¬\n";
sw.Write($"¬{datItem.GetField(Field.Description, ExcludeFields)}");
sw.Write($"¬{datItem.GetField(Field.Name, ExcludeFields)}");
sw.Write("¬¬¬¬¬\n");
break;
case ItemType.Rom:
var rom = datItem as Rom;
state += "¬";
sw.Write("¬");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, ExcludeFields)))
state += datItem.CloneOf;
state += "¬";
sw.Write(datItem.CloneOf);
sw.Write("¬");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CloneOf, ExcludeFields)))
state += datItem.CloneOf;
state += $"¬{datItem.GetField(Field.MachineName, ExcludeFields)}";
sw.Write(datItem.CloneOf);
sw.Write($"¬{datItem.GetField(Field.MachineName, ExcludeFields)}");
if (string.IsNullOrWhiteSpace(datItem.MachineDescription))
state += $"¬{datItem.GetField(Field.MachineName, ExcludeFields)}";
sw.Write($"¬{datItem.GetField(Field.MachineName, ExcludeFields)}");
else
state += $"¬{datItem.GetField(Field.Description, ExcludeFields)}";
state += $"¬{datItem.GetField(Field.Name, ExcludeFields)}";
state += $"¬{datItem.GetField(Field.CRC, ExcludeFields)}";
state += $"¬{datItem.GetField(Field.Size, ExcludeFields)}";
state += "¬¬¬\n";
sw.Write($"¬{datItem.GetField(Field.Description, ExcludeFields)}");
sw.Write($"¬{datItem.GetField(Field.Name, ExcludeFields)}");
sw.Write($"¬{datItem.GetField(Field.CRC, ExcludeFields)}");
sw.Write($"¬{datItem.GetField(Field.Size, ExcludeFields)}");
sw.Write("¬¬¬\n");
break;
}

View File

@@ -456,11 +456,9 @@ namespace SabreTools.Library.DatFiles
{
try
{
string header = string.Format("\"File Name\"{0}\"Internal Name\"{0}\"Description\"{0}\"Game Name\"{0}\"Game Description\"{0}\"Type\"{0}\"" +
"Rom Name\"{0}\"Disk Name\"{0}\"Size\"{0}\"CRC\"{0}\"MD5\"{0}\"SHA1\"{0}\"SHA256\"{0}\"Nodump\"\n", _delim);
sw.Write(string.Format("\"File Name\"{0}\"Internal Name\"{0}\"Description\"{0}\"Game Name\"{0}\"Game Description\"{0}\"Type\"{0}\"" +
"Rom Name\"{0}\"Disk Name\"{0}\"Size\"{0}\"CRC\"{0}\"MD5\"{0}\"SHA1\"{0}\"SHA256\"{0}\"Nodump\"\n", _delim));
// Write the header out
sw.Write(header);
sw.Flush();
}
catch (Exception ex)
@@ -485,84 +483,57 @@ namespace SabreTools.Library.DatFiles
if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
return true;
// TODO: Clean up this mess and make it more like the other DatFile types
// TODO: Specifically, make it so that each ItemType has its own block, if possible
try
{
// Initialize all strings
string state = string.Empty,
pre = string.Empty,
post = string.Empty,
type = string.Empty,
romname = string.Empty,
diskname = string.Empty,
size = string.Empty,
crc = string.Empty,
md5 = string.Empty,
ripemd160 = string.Empty,
sha1 = string.Empty,
sha256 = string.Empty,
sha384 = string.Empty,
sha512 = string.Empty,
status = string.Empty;
// Separated values should only output Rom and Disk
if (datItem.ItemType != ItemType.Disk && datItem.ItemType != ItemType.Rom)
return true;
if (datItem.ItemType == ItemType.Disk)
sw.Write(CreatePrefixPostfix(datItem, true));
sw.Write($"\"{FileName}\"{_delim}");
sw.Write($"\"{Name}\"{_delim}");
sw.Write($"\"{Description}\"{_delim}");
sw.Write($"\"{datItem.GetField(Field.MachineName, ExcludeFields)}\"{_delim}");
sw.Write($"\"{datItem.GetField(Field.Description, ExcludeFields)}\"{_delim}");
switch (datItem.ItemType)
{
case ItemType.Disk:
var disk = datItem as Disk;
type = "disk";
diskname = datItem.Name;
md5 = disk.MD5;
ripemd160 = disk.RIPEMD160;
sha1 = disk.SHA1;
sha256 = disk.SHA256;
sha384 = disk.SHA384;
sha512 = disk.SHA512;
status = (disk.ItemStatus != ItemStatus.None ? $"\"{disk.ItemStatus}\"" : "\"\"");
}
else if (datItem.ItemType == ItemType.Rom)
{
sw.Write($"\"disk\"{_delim}");
sw.Write($"\"\"{_delim}");
sw.Write($"\"{disk.GetField(Field.Name, ExcludeFields)}\"{_delim}");
sw.Write($"\"\"{_delim}");
sw.Write($"\"\"{_delim}");
sw.Write($"\"{disk.GetField(Field.MD5, ExcludeFields).ToLowerInvariant()}\"{_delim}");
//sw.Write($"\"{disk.GetField(Field.RIPEMD160, ExcludeFields).ToLowerInvariant()}\"{_delim}");
sw.Write($"\"{disk.GetField(Field.SHA1, ExcludeFields).ToLowerInvariant()}\"{_delim}");
sw.Write($"\"{disk.GetField(Field.SHA256, ExcludeFields).ToLowerInvariant()}\"{_delim}");
//sw.Write($"\"{disk.GetField(Field.SHA384, ExcludeFields).ToLowerInvariant()}\"{_delim}");
//sw.Write($"\"{disk.GetField(Field.SHA512, ExcludeFields).ToLowerInvariant()}\"{_delim}");
sw.Write($"\"{disk.GetField(Field.Status, ExcludeFields)}\"{_delim}");
break;
case ItemType.Rom:
var rom = datItem as Rom;
type = "rom";
romname = datItem.Name;
size = rom.Size.ToString();
crc = rom.CRC;
md5 = rom.MD5;
ripemd160 = rom.RIPEMD160;
sha1 = rom.SHA1;
sha256 = rom.SHA256;
sha384 = rom.SHA384;
sha512 = rom.SHA512;
status = (rom.ItemStatus != ItemStatus.None ? $"\"{rom.ItemStatus}\"" : "\"\"");
sw.Write($"\"rom\"{_delim}");
sw.Write($"\"{rom.GetField(Field.Name, ExcludeFields)}\"{_delim}");
sw.Write($"\"\"{_delim}");
sw.Write($"\"{rom.GetField(Field.Size, ExcludeFields)}\"{_delim}");
sw.Write($"\"{rom.GetField(Field.CRC, ExcludeFields).ToLowerInvariant()}\"{_delim}");
sw.Write($"\"{rom.GetField(Field.MD5, ExcludeFields).ToLowerInvariant()}\"{_delim}");
//sw.Write($"\"{rom.GetField(Field.RIPEMD160, ExcludeFields).ToLowerInvariant()}\"{_delim}");
sw.Write($"\"{rom.GetField(Field.SHA1, ExcludeFields).ToLowerInvariant()}\"{_delim}");
sw.Write($"\"{rom.GetField(Field.SHA256, ExcludeFields).ToLowerInvariant()}\"{_delim}");
//sw.Write($"\"{rom.GetField(Field.SHA384, ExcludeFields).ToLowerInvariant()}\"{_delim}");
//sw.Write($"\"{rom.GetField(Field.SHA512, ExcludeFields).ToLowerInvariant()}\"{_delim}");
sw.Write($"\"{rom.GetField(Field.Status, ExcludeFields)}\"{_delim}");
break;
}
pre = CreatePrefixPostfix(datItem, true);
post = CreatePrefixPostfix(datItem, false);
string inline = string.Format($"\"{FileName}\""
+ $"{0}\"{Name}\""
+ $"{0}\"{Description}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.MachineName] ? datItem.MachineName : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.Description] ? datItem.MachineDescription : string.Empty)}\""
+ $"{0}\"{type}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.Name] ? romname : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.Name] ? diskname : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.Size] ? size : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.CRC] ? crc : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.MD5] ? md5 : string.Empty)}\""
// + $"{0}\"{(!ExcludeFields[(int)Field.RIPEMD160] ? ripemd160 : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.SHA1] ? sha1 : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.SHA256] ? sha256 : string.Empty)}\""
// + $"{0}\"{(!ExcludeFields[(int)Field.SHA384] ? sha384 : string.Empty)}\""
// + $"{0}\"{(!ExcludeFields[(int)Field.SHA512] ? sha512 : string.Empty)}\""
+ $"{0}\"{(!ExcludeFields[(int)Field.Status] ? status : string.Empty)}\"",
_delim);
sw.Write(CreatePrefixPostfix(datItem, false));
state += $"{pre}{inline}{post}\n";
sw.Write(state);
sw.Flush();
}
catch (Exception ex)