mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make less things use global throw state
This commit is contained in:
@@ -38,7 +38,8 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="indexId">Index ID for the DAT</param>
|
||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
||||
/// <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)
|
||||
{
|
||||
// Prepare all internal variables
|
||||
XmlReader xtr = filename.GetXmlTextReader();
|
||||
@@ -107,8 +108,7 @@ namespace SabreTools.Library.DatFiles
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
if (throwOnError) throw ex;
|
||||
|
||||
// For XML errors, just skip the affected node
|
||||
xtr?.Read();
|
||||
@@ -663,8 +663,9 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </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>
|
||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -733,9 +734,7 @@ namespace SabreTools.Library.DatFiles
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
if (throwOnError) throw ex;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -746,83 +745,69 @@ namespace SabreTools.Library.DatFiles
|
||||
/// Write out DAT header using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private bool WriteHeader(XmlTextWriter xtw)
|
||||
private void WriteHeader(XmlTextWriter xtw)
|
||||
{
|
||||
try
|
||||
xtw.WriteStartDocument();
|
||||
xtw.WriteDocType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null);
|
||||
|
||||
xtw.WriteStartElement("datafile");
|
||||
xtw.WriteOptionalAttributeString("build", Header.Build);
|
||||
xtw.WriteOptionalAttributeString("debug", Header.Debug.FromYesNo());
|
||||
|
||||
xtw.WriteStartElement("header");
|
||||
|
||||
xtw.WriteRequiredElementString("name", Header.Name);
|
||||
xtw.WriteRequiredElementString("description", Header.Description);
|
||||
xtw.WriteOptionalElementString("rootdir", Header.RootDir);
|
||||
xtw.WriteOptionalElementString("category", Header.Category);
|
||||
xtw.WriteRequiredElementString("version", Header.Version);
|
||||
xtw.WriteOptionalElementString("date", Header.Date);
|
||||
xtw.WriteRequiredElementString("author", Header.Author);
|
||||
xtw.WriteOptionalElementString("email", Header.Email);
|
||||
xtw.WriteOptionalElementString("homepage", Header.Homepage);
|
||||
xtw.WriteOptionalElementString("url", Header.Url);
|
||||
xtw.WriteOptionalElementString("comment", Header.Comment);
|
||||
xtw.WriteOptionalElementString("type", Header.Type);
|
||||
|
||||
if (Header.ForcePacking != PackingFlag.None
|
||||
|| Header.ForceMerging != MergingFlag.None
|
||||
|| Header.ForceNodump != NodumpFlag.None
|
||||
|| !string.IsNullOrWhiteSpace(Header.HeaderSkipper))
|
||||
{
|
||||
xtw.WriteStartDocument();
|
||||
xtw.WriteDocType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null);
|
||||
xtw.WriteStartElement("clrmamepro");
|
||||
|
||||
xtw.WriteStartElement("datafile");
|
||||
xtw.WriteOptionalAttributeString("build", Header.Build);
|
||||
xtw.WriteOptionalAttributeString("debug", Header.Debug.FromYesNo());
|
||||
xtw.WriteOptionalAttributeString("forcepacking", Header.ForcePacking.FromPackingFlag(false));
|
||||
xtw.WriteOptionalAttributeString("forcemerging", Header.ForceMerging.FromMergingFlag(false));
|
||||
xtw.WriteOptionalAttributeString("forcenodump", Header.ForceNodump.FromNodumpFlag());
|
||||
xtw.WriteOptionalAttributeString("header", Header.HeaderSkipper);
|
||||
|
||||
xtw.WriteStartElement("header");
|
||||
|
||||
xtw.WriteRequiredElementString("name", Header.Name);
|
||||
xtw.WriteRequiredElementString("description", Header.Description);
|
||||
xtw.WriteOptionalElementString("rootdir", Header.RootDir);
|
||||
xtw.WriteOptionalElementString("category", Header.Category);
|
||||
xtw.WriteRequiredElementString("version", Header.Version);
|
||||
xtw.WriteOptionalElementString("date", Header.Date);
|
||||
xtw.WriteRequiredElementString("author", Header.Author);
|
||||
xtw.WriteOptionalElementString("email", Header.Email);
|
||||
xtw.WriteOptionalElementString("homepage", Header.Homepage);
|
||||
xtw.WriteOptionalElementString("url", Header.Url);
|
||||
xtw.WriteOptionalElementString("comment", Header.Comment);
|
||||
xtw.WriteOptionalElementString("type", Header.Type);
|
||||
|
||||
if (Header.ForcePacking != PackingFlag.None
|
||||
|| Header.ForceMerging != MergingFlag.None
|
||||
|| Header.ForceNodump != NodumpFlag.None
|
||||
|| !string.IsNullOrWhiteSpace(Header.HeaderSkipper))
|
||||
{
|
||||
xtw.WriteStartElement("clrmamepro");
|
||||
|
||||
xtw.WriteOptionalAttributeString("forcepacking", Header.ForcePacking.FromPackingFlag(false));
|
||||
xtw.WriteOptionalAttributeString("forcemerging", Header.ForceMerging.FromMergingFlag(false));
|
||||
xtw.WriteOptionalAttributeString("forcenodump", Header.ForceNodump.FromNodumpFlag());
|
||||
xtw.WriteOptionalAttributeString("header", Header.HeaderSkipper);
|
||||
|
||||
// End clrmamepro
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
if (Header.System != null
|
||||
|| Header.RomMode != MergingFlag.None || Header.LockRomMode != null
|
||||
|| Header.BiosMode != MergingFlag.None || Header.LockBiosMode != null
|
||||
|| Header.SampleMode != MergingFlag.None || Header.LockSampleMode != null)
|
||||
{
|
||||
xtw.WriteStartElement("romcenter");
|
||||
|
||||
xtw.WriteOptionalAttributeString("plugin", Header.System);
|
||||
xtw.WriteOptionalAttributeString("rommode", Header.RomMode.FromMergingFlag(true));
|
||||
xtw.WriteOptionalAttributeString("biosmode", Header.BiosMode.FromMergingFlag(true));
|
||||
xtw.WriteOptionalAttributeString("samplemode", Header.SampleMode.FromMergingFlag(true));
|
||||
xtw.WriteOptionalAttributeString("lockrommode", Header.LockRomMode.FromYesNo());
|
||||
xtw.WriteOptionalAttributeString("lockbiosmode", Header.LockBiosMode.FromYesNo());
|
||||
xtw.WriteOptionalAttributeString("locksamplemode", Header.LockSampleMode.FromYesNo());
|
||||
|
||||
// End romcenter
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
// End header
|
||||
// End clrmamepro
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
if (Header.System != null
|
||||
|| Header.RomMode != MergingFlag.None || Header.LockRomMode != null
|
||||
|| Header.BiosMode != MergingFlag.None || Header.LockBiosMode != null
|
||||
|| Header.SampleMode != MergingFlag.None || Header.LockSampleMode != null)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
xtw.WriteStartElement("romcenter");
|
||||
|
||||
return false;
|
||||
xtw.WriteOptionalAttributeString("plugin", Header.System);
|
||||
xtw.WriteOptionalAttributeString("rommode", Header.RomMode.FromMergingFlag(true));
|
||||
xtw.WriteOptionalAttributeString("biosmode", Header.BiosMode.FromMergingFlag(true));
|
||||
xtw.WriteOptionalAttributeString("samplemode", Header.SampleMode.FromMergingFlag(true));
|
||||
xtw.WriteOptionalAttributeString("lockrommode", Header.LockRomMode.FromYesNo());
|
||||
xtw.WriteOptionalAttributeString("lockbiosmode", Header.LockBiosMode.FromYesNo());
|
||||
xtw.WriteOptionalAttributeString("locksamplemode", Header.LockSampleMode.FromYesNo());
|
||||
|
||||
// End romcenter
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
return true;
|
||||
// End header
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -830,111 +815,83 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||
{
|
||||
try
|
||||
// No game should start with a path separator
|
||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||
|
||||
// Build the state
|
||||
xtw.WriteStartElement(_deprecated ? "game" : "machine");
|
||||
xtw.WriteRequiredAttributeString("name", datItem.Machine.Name);
|
||||
|
||||
if (datItem.Machine.MachineType.HasFlag(MachineType.Bios))
|
||||
xtw.WriteAttributeString("isbios", "yes");
|
||||
if (datItem.Machine.MachineType.HasFlag(MachineType.Device))
|
||||
xtw.WriteAttributeString("isdevice", "yes");
|
||||
if (datItem.Machine.MachineType.HasFlag(MachineType.Mechanical))
|
||||
xtw.WriteAttributeString("ismechanical", "yes");
|
||||
|
||||
xtw.WriteOptionalAttributeString("runnable", datItem.Machine.Runnable.FromRunnable());
|
||||
|
||||
if (!string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase))
|
||||
xtw.WriteOptionalAttributeString("cloneof", datItem.Machine.CloneOf);
|
||||
if (!string.Equals(datItem.Machine.Name, datItem.Machine.RomOf, StringComparison.OrdinalIgnoreCase))
|
||||
xtw.WriteOptionalAttributeString("romof", datItem.Machine.RomOf);
|
||||
if (!string.Equals(datItem.Machine.Name, datItem.Machine.SampleOf, StringComparison.OrdinalIgnoreCase))
|
||||
xtw.WriteOptionalAttributeString("sampleof", datItem.Machine.SampleOf);
|
||||
|
||||
xtw.WriteOptionalElementString("comment", datItem.Machine.Comment);
|
||||
xtw.WriteOptionalElementString("description", datItem.Machine.Description);
|
||||
xtw.WriteOptionalElementString("year", datItem.Machine.Year);
|
||||
xtw.WriteOptionalElementString("publisher", datItem.Machine.Publisher);
|
||||
xtw.WriteOptionalElementString("manufacturer", datItem.Machine.Manufacturer);
|
||||
xtw.WriteOptionalElementString("category", datItem.Machine.Category);
|
||||
|
||||
if (datItem.Machine.TitleID != null
|
||||
|| datItem.Machine.Developer != null
|
||||
|| datItem.Machine.Genre != null
|
||||
|| datItem.Machine.Subgenre != null
|
||||
|| datItem.Machine.Ratings != null
|
||||
|| datItem.Machine.Score != null
|
||||
|| datItem.Machine.Enabled != null
|
||||
|| datItem.Machine.Crc != null
|
||||
|| datItem.Machine.RelatedTo != null)
|
||||
{
|
||||
// No game should start with a path separator
|
||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||
xtw.WriteStartElement("trurip");
|
||||
|
||||
// Build the state
|
||||
xtw.WriteStartElement(_deprecated ? "game" : "machine");
|
||||
xtw.WriteRequiredAttributeString("name", datItem.Machine.Name);
|
||||
|
||||
if (datItem.Machine.MachineType.HasFlag(MachineType.Bios))
|
||||
xtw.WriteAttributeString("isbios", "yes");
|
||||
if (datItem.Machine.MachineType.HasFlag(MachineType.Device))
|
||||
xtw.WriteAttributeString("isdevice", "yes");
|
||||
if (datItem.Machine.MachineType.HasFlag(MachineType.Mechanical))
|
||||
xtw.WriteAttributeString("ismechanical", "yes");
|
||||
|
||||
xtw.WriteOptionalAttributeString("runnable", datItem.Machine.Runnable.FromRunnable());
|
||||
|
||||
if (!string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase))
|
||||
xtw.WriteOptionalAttributeString("cloneof", datItem.Machine.CloneOf);
|
||||
if (!string.Equals(datItem.Machine.Name, datItem.Machine.RomOf, StringComparison.OrdinalIgnoreCase))
|
||||
xtw.WriteOptionalAttributeString("romof", datItem.Machine.RomOf);
|
||||
if (!string.Equals(datItem.Machine.Name, datItem.Machine.SampleOf, StringComparison.OrdinalIgnoreCase))
|
||||
xtw.WriteOptionalAttributeString("sampleof", datItem.Machine.SampleOf);
|
||||
|
||||
xtw.WriteOptionalElementString("comment", datItem.Machine.Comment);
|
||||
xtw.WriteOptionalElementString("description", datItem.Machine.Description);
|
||||
xtw.WriteOptionalElementString("year", datItem.Machine.Year);
|
||||
xtw.WriteOptionalElementString("titleid", datItem.Machine.TitleID);
|
||||
xtw.WriteOptionalElementString("publisher", datItem.Machine.Publisher);
|
||||
xtw.WriteOptionalElementString("manufacturer", datItem.Machine.Manufacturer);
|
||||
xtw.WriteOptionalElementString("category", datItem.Machine.Category);
|
||||
xtw.WriteOptionalElementString("developer", datItem.Machine.Developer);
|
||||
xtw.WriteOptionalElementString("year", datItem.Machine.Year);
|
||||
xtw.WriteOptionalElementString("genre", datItem.Machine.Genre);
|
||||
xtw.WriteOptionalElementString("subgenre", datItem.Machine.Subgenre);
|
||||
xtw.WriteOptionalElementString("ratings", datItem.Machine.Ratings);
|
||||
xtw.WriteOptionalElementString("score", datItem.Machine.Score);
|
||||
xtw.WriteOptionalElementString("players", datItem.Machine.Players);
|
||||
xtw.WriteOptionalElementString("enabled", datItem.Machine.Enabled);
|
||||
xtw.WriteOptionalElementString("titleid", datItem.Machine.TitleID);
|
||||
xtw.WriteOptionalElementString("crc", datItem.Machine.Crc.FromYesNo());
|
||||
xtw.WriteOptionalElementString("source", datItem.Machine.SourceFile);
|
||||
xtw.WriteOptionalElementString("cloneof", datItem.Machine.CloneOf);
|
||||
xtw.WriteOptionalElementString("relatedto", datItem.Machine.RelatedTo);
|
||||
|
||||
if (datItem.Machine.TitleID != null
|
||||
|| datItem.Machine.Developer != null
|
||||
|| datItem.Machine.Genre != null
|
||||
|| datItem.Machine.Subgenre != null
|
||||
|| datItem.Machine.Ratings != null
|
||||
|| datItem.Machine.Score != null
|
||||
|| datItem.Machine.Enabled != null
|
||||
|| datItem.Machine.Crc != null
|
||||
|| datItem.Machine.RelatedTo != null)
|
||||
{
|
||||
xtw.WriteStartElement("trurip");
|
||||
|
||||
xtw.WriteOptionalElementString("titleid", datItem.Machine.TitleID);
|
||||
xtw.WriteOptionalElementString("publisher", datItem.Machine.Publisher);
|
||||
xtw.WriteOptionalElementString("developer", datItem.Machine.Developer);
|
||||
xtw.WriteOptionalElementString("year", datItem.Machine.Year);
|
||||
xtw.WriteOptionalElementString("genre", datItem.Machine.Genre);
|
||||
xtw.WriteOptionalElementString("subgenre", datItem.Machine.Subgenre);
|
||||
xtw.WriteOptionalElementString("ratings", datItem.Machine.Ratings);
|
||||
xtw.WriteOptionalElementString("score", datItem.Machine.Score);
|
||||
xtw.WriteOptionalElementString("players", datItem.Machine.Players);
|
||||
xtw.WriteOptionalElementString("enabled", datItem.Machine.Enabled);
|
||||
xtw.WriteOptionalElementString("titleid", datItem.Machine.TitleID);
|
||||
xtw.WriteOptionalElementString("crc", datItem.Machine.Crc.FromYesNo());
|
||||
xtw.WriteOptionalElementString("source", datItem.Machine.SourceFile);
|
||||
xtw.WriteOptionalElementString("cloneof", datItem.Machine.CloneOf);
|
||||
xtw.WriteOptionalElementString("relatedto", datItem.Machine.RelatedTo);
|
||||
|
||||
// End trurip
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
// End trurip
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
return true;
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out Game end using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private bool WriteEndGame(XmlTextWriter xtw)
|
||||
private void WriteEndGame(XmlTextWriter xtw)
|
||||
{
|
||||
try
|
||||
{
|
||||
// End machine
|
||||
xtw.WriteEndElement();
|
||||
// End machine
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -942,135 +899,107 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||
{
|
||||
try
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
|
||||
// Build the state
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
case ItemType.Archive:
|
||||
var archive = datItem as Archive;
|
||||
xtw.WriteStartElement("archive");
|
||||
xtw.WriteRequiredAttributeString("name", archive.Name);
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
// Build the state
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
case ItemType.Archive:
|
||||
var archive = datItem as Archive;
|
||||
xtw.WriteStartElement("archive");
|
||||
xtw.WriteRequiredAttributeString("name", archive.Name);
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ItemType.BiosSet:
|
||||
var biosSet = datItem as BiosSet;
|
||||
xtw.WriteStartElement("biosset");
|
||||
xtw.WriteRequiredAttributeString("name", biosSet.Name);
|
||||
xtw.WriteOptionalAttributeString("description", biosSet.Description);
|
||||
xtw.WriteOptionalAttributeString("default", biosSet.Default.FromYesNo());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.BiosSet:
|
||||
var biosSet = datItem as BiosSet;
|
||||
xtw.WriteStartElement("biosset");
|
||||
xtw.WriteRequiredAttributeString("name", biosSet.Name);
|
||||
xtw.WriteOptionalAttributeString("description", biosSet.Description);
|
||||
xtw.WriteOptionalAttributeString("default", biosSet.Default.FromYesNo());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("disk");
|
||||
xtw.WriteRequiredAttributeString("name", disk.Name);
|
||||
xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false));
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("disk");
|
||||
xtw.WriteRequiredAttributeString("name", disk.Name);
|
||||
xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false));
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ItemType.Media:
|
||||
var media = datItem as Media;
|
||||
xtw.WriteStartElement("media");
|
||||
xtw.WriteRequiredAttributeString("name", media.Name);
|
||||
xtw.WriteOptionalAttributeString("md5", media.MD5?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha1", media.SHA1?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha256", media.SHA256?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("spamsum", media.SpamSum?.ToLowerInvariant());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Media:
|
||||
var media = datItem as Media;
|
||||
xtw.WriteStartElement("media");
|
||||
xtw.WriteRequiredAttributeString("name", media.Name);
|
||||
xtw.WriteOptionalAttributeString("md5", media.MD5?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha1", media.SHA1?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha256", media.SHA256?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("spamsum", media.SpamSum?.ToLowerInvariant());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ItemType.Release:
|
||||
var release = datItem as Release;
|
||||
xtw.WriteStartElement("release");
|
||||
xtw.WriteRequiredAttributeString("name", release.Name);
|
||||
xtw.WriteOptionalAttributeString("region", release.Region);
|
||||
xtw.WriteOptionalAttributeString("language", release.Language);
|
||||
xtw.WriteOptionalAttributeString("date", release.Date);
|
||||
xtw.WriteOptionalAttributeString("default", release.Default.FromYesNo());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Release:
|
||||
var release = datItem as Release;
|
||||
xtw.WriteStartElement("release");
|
||||
xtw.WriteRequiredAttributeString("name", release.Name);
|
||||
xtw.WriteOptionalAttributeString("region", release.Region);
|
||||
xtw.WriteOptionalAttributeString("language", release.Language);
|
||||
xtw.WriteOptionalAttributeString("date", release.Date);
|
||||
xtw.WriteOptionalAttributeString("default", release.Default.FromYesNo());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Rom:
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteStartElement("rom");
|
||||
xtw.WriteRequiredAttributeString("name", rom.Name);
|
||||
xtw.WriteAttributeString("size", rom.Size?.ToString());
|
||||
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
||||
case ItemType.Rom:
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteStartElement("rom");
|
||||
xtw.WriteRequiredAttributeString("name", rom.Name);
|
||||
xtw.WriteAttributeString("size", rom.Size?.ToString());
|
||||
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
||||
#if NET_FRAMEWORK
|
||||
xtw.WriteOptionalAttributeString("ripemd160", rom.RIPEMD160?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("ripemd160", rom.RIPEMD160?.ToLowerInvariant());
|
||||
#endif
|
||||
xtw.WriteOptionalAttributeString("sha1", rom.SHA1?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha256", rom.SHA256?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha384", rom.SHA384?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("spamsum", rom.SpamSum?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("date", rom.Date);
|
||||
xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false));
|
||||
xtw.WriteOptionalAttributeString("inverted", rom.Inverted.FromYesNo());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
xtw.WriteOptionalAttributeString("sha1", rom.SHA1?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha256", rom.SHA256?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha384", rom.SHA384?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("spamsum", rom.SpamSum?.ToLowerInvariant());
|
||||
xtw.WriteOptionalAttributeString("date", rom.Date);
|
||||
xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false));
|
||||
xtw.WriteOptionalAttributeString("inverted", rom.Inverted.FromYesNo());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Sample:
|
||||
var sample = datItem as Sample;
|
||||
xtw.WriteStartElement("sample");
|
||||
xtw.WriteRequiredAttributeString("name", sample.Name);
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
case ItemType.Sample:
|
||||
var sample = datItem as Sample;
|
||||
xtw.WriteStartElement("sample");
|
||||
xtw.WriteRequiredAttributeString("name", sample.Name);
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out DAT footer using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private bool WriteFooter(XmlTextWriter xtw)
|
||||
private void WriteFooter(XmlTextWriter xtw)
|
||||
{
|
||||
try
|
||||
{
|
||||
// End machine
|
||||
xtw.WriteEndElement();
|
||||
// End machine
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End datafile
|
||||
xtw.WriteEndElement();
|
||||
// End datafile
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
xtw.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user