Files
SabreTools/SabreTools.Library/DatFiles/OpenMSX.cs

819 lines
30 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using SabreTools.Library.Data;
using SabreTools.Library.DatItems;
2020-08-01 23:04:11 -07:00
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles
{
2019-01-11 13:43:15 -08:00
/// <summary>
/// Represents parsing and writing of a openMSX softawre list XML DAT
/// </summary>
internal class OpenMSX : DatFile
{
/// <summary>
/// Constructor designed for casting a base DatFile
/// </summary>
/// <param name="datFile">Parent DatFile to copy from</param>
public OpenMSX(DatFile datFile)
: base(datFile)
2019-01-11 13:43:15 -08:00
{
}
/// <summary>
/// Parse a openMSX softawre list XML DAT and return all found games and roms within
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
2019-01-11 13:43:15 -08:00
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
protected override void ParseFile(
2019-01-11 13:43:15 -08:00
// Standard Dat parsing
string filename,
int indexId,
2019-01-11 13:43:15 -08:00
// Miscellaneous
bool keep)
2019-01-11 13:43:15 -08:00
{
// Prepare all internal variables
XmlReader xtr = filename.GetXmlTextReader();
2019-01-11 13:43:15 -08:00
// If we got a null reader, just return
if (xtr == null)
return;
// Otherwise, read the file to the end
try
{
xtr.MoveToContent();
while (!xtr.EOF)
{
// We only want elements
if (xtr.NodeType != XmlNodeType.Element)
{
xtr.Read();
continue;
}
switch (xtr.Name)
{
case "softwaredb":
Header.Name = (Header.Name == null ? "openMSX Software List" : Header.Name);
Header.Description = (Header.Description == null ? Header.Name : Header.Description);
2020-08-20 15:53:56 -07:00
Header.Date = (Header.Date == null ? xtr.GetAttribute("timestamp") : Header.Date);
2019-01-11 13:43:15 -08:00
xtr.Read();
break;
2019-01-11 13:43:15 -08:00
// We want to process the entire subtree of the software
case "software":
ReadSoftware(xtr.ReadSubtree(), filename, indexId);
2019-01-11 13:43:15 -08:00
// Skip the software now that we've processed it
xtr.Skip();
break;
2019-01-11 13:43:15 -08:00
default:
xtr.Read();
break;
}
}
}
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
2019-01-11 13:43:15 -08:00
// For XML errors, just skip the affected node
xtr?.Read();
}
xtr.Dispose();
}
/// <summary>
/// Read software information
/// </summary>
/// <param name="reader">XmlReader representing a machine block</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
2019-01-11 13:43:15 -08:00
private void ReadSoftware(
XmlReader reader,
// Standard Dat parsing
string filename,
int indexId)
2019-01-11 13:43:15 -08:00
{
// If we have an empty machine, skip it
if (reader == null)
return;
// Otherwise, add what is possible
reader.MoveToContent();
int diskno = 0;
bool containsItems = false;
// Create a new machine
Machine machine = new Machine();
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the roms from the machine
switch (reader.Name)
{
case "title":
machine.Name = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "genmsxid":
machine.GenMSXID = reader.ReadElementContentAsString();
2019-01-11 13:43:15 -08:00
break;
2019-01-11 13:43:15 -08:00
case "system":
machine.System = reader.ReadElementContentAsString();
2019-01-11 13:43:15 -08:00
break;
2019-01-11 13:43:15 -08:00
case "company":
machine.Manufacturer = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "year":
machine.Year = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "country":
machine.Country = reader.ReadElementContentAsString();
2019-01-11 13:43:15 -08:00
break;
2019-01-11 13:43:15 -08:00
case "dump":
containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, filename, indexId);
2019-01-11 13:43:15 -08:00
diskno++;
// Skip the dump now that we've processed it
reader.Skip();
break;
2019-01-11 13:43:15 -08:00
default:
reader.Read();
break;
}
}
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
{
2020-08-20 13:17:14 -07:00
Source = new Source
{
Index = indexId,
Name = filename,
},
2019-01-11 13:43:15 -08:00
};
2020-08-20 13:17:14 -07:00
2019-01-11 13:43:15 -08:00
blank.CopyMachineInformation(machine);
// Now process and add the rom
ParseAddHelper(blank);
2019-01-11 13:43:15 -08:00
}
}
/// <summary>
/// Read dump information
/// </summary>
/// <param name="reader">XmlReader representing a part block</param>
/// <param name="machine">Machine information to pass to contained items</param>
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
2019-01-11 13:43:15 -08:00
private bool ReadDump(
XmlReader reader,
Machine machine,
int diskno,
// Standard Dat parsing
string filename,
int indexId)
2019-01-11 13:43:15 -08:00
{
List<DatItem> items = new List<DatItem>();
OpenMSXOriginal original = null;
2019-01-11 13:43:15 -08:00
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the elements from the dump
switch (reader.Name)
{
case "rom":
DatItem rom = ReadRom(reader.ReadSubtree(), machine, diskno, filename, indexId);
if (rom != null)
items.Add(rom);
2019-01-11 13:43:15 -08:00
// Skip the rom now that we've processed it
reader.Skip();
break;
2019-01-11 13:43:15 -08:00
case "megarom":
DatItem megarom = ReadMegaRom(reader.ReadSubtree(), machine, diskno, filename, indexId);
if (megarom != null)
items.Add(megarom);
2019-01-11 13:43:15 -08:00
// Skip the megarom now that we've processed it
reader.Skip();
break;
2019-01-11 13:43:15 -08:00
case "sccpluscart":
DatItem sccpluscart = ReadSccPlusCart(reader.ReadSubtree(), machine, diskno, filename, indexId);
if (sccpluscart != null)
items.Add(sccpluscart);
2019-01-11 13:43:15 -08:00
// Skip the sccpluscart now that we've processed it
reader.Skip();
break;
2019-01-11 13:43:15 -08:00
case "original":
bool? value = reader.GetAttribute("value").AsYesNo();
string orig = reader.ReadElementContentAsString();
original = new OpenMSXOriginal(orig, value);
2019-01-11 13:43:15 -08:00
break;
2019-01-11 13:43:15 -08:00
default:
reader.Read();
break;
}
}
// If we have any items, loop through and add them
foreach (DatItem item in items)
{
item.CopyMachineInformation(machine);
item.Original = original;
ParseAddHelper(item);
}
return items.Count > 0;
2019-01-11 13:43:15 -08:00
}
/// <summary>
/// Read rom information
/// </summary>
/// <param name="reader">XmlReader representing a rom block</param>
/// <param name="machine">Machine information to pass to contained items</param>
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
private DatItem ReadRom(
2019-01-11 13:43:15 -08:00
XmlReader reader,
Machine machine,
int diskno,
// Standard Dat parsing
string filename,
int indexId)
2019-01-11 13:43:15 -08:00
{
string hash = string.Empty,
offset = string.Empty,
type = string.Empty,
remark = string.Empty;
2019-01-11 13:43:15 -08:00
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the elements from the rom
switch (reader.Name)
{
case "hash":
hash = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "start":
offset = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "type":
type = reader.ReadElementContentAsString();
2019-01-11 13:43:15 -08:00
break;
2019-01-11 13:43:15 -08:00
case "remark":
remark = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
default:
reader.Read();
break;
}
}
// If we got a hash, then create and return the item
if (!string.IsNullOrWhiteSpace(hash))
2019-01-11 13:43:15 -08:00
{
return new Rom
2020-08-20 13:17:14 -07:00
{
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
Offset = offset,
Size = -1,
SHA1 = hash,
Source = new Source
{
Index = indexId,
Name = filename,
},
2019-01-11 13:43:15 -08:00
OpenMSXSubType = OpenMSXSubType.Rom,
OpenMSXType = type,
Remark = remark,
};
}
2019-01-11 13:43:15 -08:00
// No valid item means returning null
return null;
2019-01-11 13:43:15 -08:00
}
/// <summary>
/// Read megarom information
/// </summary>
/// <param name="reader">XmlReader representing a megarom block</param>
/// <param name="machine">Machine information to pass to contained items</param>
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
private DatItem ReadMegaRom(
2019-01-11 13:43:15 -08:00
XmlReader reader,
Machine machine,
int diskno,
// Standard Dat parsing
string filename,
int indexId)
2019-01-11 13:43:15 -08:00
{
string hash = string.Empty,
offset = string.Empty,
type = string.Empty,
remark = string.Empty;
2019-01-11 13:43:15 -08:00
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the elements from the dump
switch (reader.Name)
{
case "hash":
hash = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "start":
offset = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "type":
reader.ReadElementContentAsString();
2019-01-11 13:43:15 -08:00
break;
2019-01-11 13:43:15 -08:00
case "remark":
remark = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
default:
reader.Read();
break;
}
}
// If we got a hash, then create and return the item
if (!string.IsNullOrWhiteSpace(hash))
2019-01-11 13:43:15 -08:00
{
return new Rom
2020-08-20 13:17:14 -07:00
{
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
Offset = offset,
Size = -1,
SHA1 = hash,
2019-01-11 13:43:15 -08:00
Source = new Source
{
Index = indexId,
Name = filename,
},
OpenMSXSubType = OpenMSXSubType.MegaRom,
OpenMSXType = type,
Remark = remark,
};
}
2019-01-11 13:43:15 -08:00
// No valid item means returning null
return null;
2019-01-11 13:43:15 -08:00
}
/// <summary>
/// Read sccpluscart information
/// </summary>
/// <param name="reader">XmlReader representing a sccpluscart block</param>
/// <param name="machine">Machine information to pass to contained items</param>
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
private DatItem ReadSccPlusCart(
2019-01-11 13:43:15 -08:00
XmlReader reader,
Machine machine,
int diskno,
// Standard Dat parsing
string filename,
int indexId)
2019-01-11 13:43:15 -08:00
{
string boot = string.Empty,
hash = string.Empty,
remark = string.Empty;
2019-01-11 13:43:15 -08:00
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get the elements from the dump
switch (reader.Name)
{
case "boot":
boot = reader.ReadElementContentAsString();
2019-01-11 13:43:15 -08:00
break;
2019-01-11 13:43:15 -08:00
case "hash":
hash = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
case "remark":
remark = reader.ReadElementContentAsString();
break;
2019-01-11 13:43:15 -08:00
default:
reader.Read();
break;
}
}
// If we got a hash, then create and return the item
if (!string.IsNullOrWhiteSpace(hash))
2019-01-11 13:43:15 -08:00
{
return new Rom
2020-08-20 13:17:14 -07:00
{
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
Size = -1,
SHA1 = hash,
2019-01-11 13:43:15 -08:00
Source = new Source
{
Index = indexId,
Name = filename,
},
2019-01-11 13:43:15 -08:00
OpenMSXSubType = OpenMSXSubType.SCCPlusCart,
Boot = boot,
Remark = remark,
};
}
// No valid item means returning null
return null;
2019-01-11 13:43:15 -08:00
}
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
{
try
{
Globals.Logger.User($"Opening file for writing: {outfile}");
FileStream fs = FileExtensions.TryCreate(outfile);
2019-01-11 13:43:15 -08:00
// If we get back null for some reason, just log and return
if (fs == null)
{
Globals.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;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = '\t',
Indentation = 1
};
2019-01-11 13:43:15 -08:00
// Write out the header
WriteHeader(xtw);
2019-01-11 13:43:15 -08:00
// Write out each of the machines and roms
string lastgame = null;
2020-07-26 21:00:30 -07:00
// Use a sorted list of games to output
2020-07-26 22:34:45 -07:00
foreach (string key in Items.SortedKeys)
2019-01-11 13:43:15 -08:00
{
2020-07-26 22:34:45 -07:00
List<DatItem> roms = Items[key];
2019-01-11 13:43:15 -08:00
// Resolve the names in the block
roms = DatItem.ResolveNames(roms);
for (int index = 0; index < roms.Count; index++)
{
DatItem rom = roms[index];
// There are apparently times when a null rom can skip by, skip them
2020-08-20 13:17:14 -07:00
if (rom.Name == null || rom.Machine.Name == null)
2019-01-11 13:43:15 -08:00
{
Globals.Logger.Warning("Null rom found!");
continue;
}
// If we have a different game and we're not at the start of the list, output the end of last item
2020-08-20 13:17:14 -07:00
if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
WriteEndGame(xtw);
2019-01-11 13:43:15 -08:00
// If we have a new game, output the beginning of the new item
2020-08-20 13:17:14 -07:00
if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
WriteStartGame(xtw, rom);
2019-01-11 13:43:15 -08:00
// If we have a "null" game (created by DATFromDir or something similar), log it to file
if (rom.ItemType == ItemType.Rom
&& ((Rom)rom).Size == -1
&& ((Rom)rom).CRC == "null")
{
2020-08-20 13:17:14 -07:00
Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
2019-01-11 13:43:15 -08:00
2020-08-20 13:17:14 -07:00
lastgame = rom.Machine.Name;
2019-01-11 13:43:15 -08:00
continue;
}
// Now, output the rom data
WriteDatItem(xtw, rom, ignoreblanks);
2019-01-11 13:43:15 -08:00
// Set the new data to compare against
2020-08-20 13:17:14 -07:00
lastgame = rom.Machine.Name;
2019-01-11 13:43:15 -08:00
}
}
// Write the file footer out
WriteFooter(xtw);
2019-01-11 13:43:15 -08:00
Globals.Logger.Verbose("File written!" + Environment.NewLine);
xtw.Dispose();
2019-01-11 13:43:15 -08:00
fs.Dispose();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
2019-01-11 13:43:15 -08:00
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(XmlTextWriter xtw)
2019-01-11 13:43:15 -08:00
{
try
{
xtw.WriteStartDocument();
xtw.WriteDocType("softwaredb", null, "softwaredb1.dtd", null);
xtw.WriteStartElement("softwaredb");
2020-08-20 15:53:56 -07:00
xtw.WriteAttributeString("timestamp", Header.Date);
2020-06-11 11:44:46 -07:00
//TODO: Figure out how to fix the issue with removed formatting after this point
// xtw.WriteComment("Credits");
// xtw.WriteCData(@"The softwaredb.xml file contains information about rom mapper types
//-Copyright 2003 Nicolas Beyaert(Initial Database)
//-Copyright 2004 - 2013 BlueMSX Team
//-Copyright 2005 - 2020 openMSX Team
//-Generation MSXIDs by www.generation - msx.nl
//- Thanks go out to:
//-Generation MSX / Sylvester for the incredible source of information
//- p_gimeno and diedel for their help adding and valdiating ROM additions
//- GDX for additional ROM info and validations and corrections");
xtw.Flush();
2019-01-11 13:43:15 -08:00
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
2019-01-11 13:43:15 -08:00
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
2019-01-11 13:43:15 -08:00
{
try
{
// No game should start with a path separator
2020-08-20 13:17:14 -07:00
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
// Build the state based on excluded fields
xtw.WriteStartElement("software");
xtw.WriteElementString("title", datItem.GetField(Field.MachineName, Header.ExcludeFields));
xtw.WriteElementString("genmsxid", datItem.GetField(Field.GenMSXID, Header.ExcludeFields));
xtw.WriteElementString("system", datItem.GetField(Field.System, Header.ExcludeFields));
xtw.WriteElementString("company", datItem.GetField(Field.Manufacturer, Header.ExcludeFields));
xtw.WriteElementString("year", datItem.GetField(Field.Year, Header.ExcludeFields));
xtw.WriteElementString("country", datItem.GetField(Field.Country, Header.ExcludeFields));
xtw.Flush();
2019-01-11 13:43:15 -08:00
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
2019-01-11 13:43:15 -08:00
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(XmlTextWriter xtw)
2019-01-11 13:43:15 -08:00
{
try
{
// End software
xtw.WriteEndElement();
2019-01-11 13:43:15 -08:00
xtw.Flush();
2019-01-11 13:43:15 -08:00
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
2019-01-11 13:43:15 -08:00
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, bool ignoreblanks = false)
2019-01-11 13:43:15 -08:00
{
// If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
2019-01-11 13:43:15 -08:00
return true;
try
{
// Pre-process the item name
ProcessItemName(datItem, true);
2019-01-11 13:43:15 -08:00
// Build the state based on excluded fields
switch (datItem.ItemType)
2019-01-11 13:43:15 -08:00
{
case ItemType.Rom:
var rom = datItem as Rom;
xtw.WriteStartElement("dump");
if (!Header.ExcludeFields.Contains(Field.Original) && rom.Original != null)
{
xtw.WriteStartElement("original");
xtw.WriteAttributeString("value", rom.Original.Value == true ? "true" : "false");
xtw.WriteString(rom.Original.Original);
xtw.WriteEndElement();
}
switch (datItem.OpenMSXSubType)
{
// Default to Rom for converting from other formats
case OpenMSXSubType.Rom:
case OpenMSXSubType.NULL:
xtw.WriteStartElement("rom");
xtw.WriteElementString("hash", rom.GetField(Field.SHA1, Header.ExcludeFields).ToLowerInvariant());
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Offset, Header.ExcludeFields)))
xtw.WriteElementString("start", rom.Offset);
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.OpenMSXType, Header.ExcludeFields)))
xtw.WriteElementString("type", rom.OpenMSXType);
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Remark, Header.ExcludeFields)))
xtw.WriteElementString("remark", rom.Remark);
xtw.WriteEndElement();
break;
case OpenMSXSubType.MegaRom:
xtw.WriteStartElement("megarom");
xtw.WriteElementString("hash", rom.GetField(Field.SHA1, Header.ExcludeFields).ToLowerInvariant());
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Offset, Header.ExcludeFields)))
xtw.WriteElementString("start", rom.Offset);
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.OpenMSXType, Header.ExcludeFields)))
xtw.WriteElementString("type", rom.OpenMSXType);
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Remark, Header.ExcludeFields)))
xtw.WriteElementString("remark", rom.Remark);
xtw.WriteEndElement();
break;
case OpenMSXSubType.SCCPlusCart:
xtw.WriteStartElement("sccpluscart");
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Boot, Header.ExcludeFields)))
xtw.WriteElementString("boot", rom.Boot);
xtw.WriteElementString("hash", rom.GetField(Field.SHA1, Header.ExcludeFields).ToLowerInvariant());
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Remark, Header.ExcludeFields)))
xtw.WriteElementString("remark", rom.Remark);
xtw.WriteEndElement();
break;
}
// End dump
xtw.WriteEndElement();
2019-01-11 13:43:15 -08:00
break;
}
xtw.Flush();
2019-01-11 13:43:15 -08:00
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
2019-01-11 13:43:15 -08:00
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(XmlTextWriter xtw)
2019-01-11 13:43:15 -08:00
{
try
{
// End software
xtw.WriteEndElement();
// End softwaredb
xtw.WriteEndElement();
2019-01-11 13:43:15 -08:00
xtw.Flush();
2019-01-11 13:43:15 -08:00
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
}
}