using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Xml; using SabreTools.Library.Data; using SabreTools.Library.DatItems; using SabreTools.Library.Tools; #if MONO using System.IO; #else using Alphaleonis.Win32.Filesystem; using FileStream = System.IO.FileStream; using StreamWriter = System.IO.StreamWriter; #endif using NaturalSort; namespace SabreTools.Library.DatFiles { /// /// Represents parsing and writing of an OfflineList XML DAT /// /// TODO: Verify that all write for this DatFile type is correct internal class OfflineList : DatFile { /// /// Constructor designed for casting a base DatFile /// /// Parent DatFile to copy from public OfflineList(DatFile datFile) : base(datFile, cloneHeader: false) { } /// /// Parse an OfflineList XML DAT and return all found games and roms within /// /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) /// /// public override void ParseFile( // Standard Dat parsing string filename, int sysid, int srcid, // Miscellaneous bool keep, bool clean, bool remUnicode) { Encoding enc = Utilities.GetEncoding(filename); XmlReader xtr = Utilities.GetXmlTextReader(filename); // 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 "configuration": ReadConfiguration(xtr.ReadSubtree(), keep); // Skip the configuration node now that we've processed it xtr.Skip(); break; case "games": ReadGames(xtr.ReadSubtree(), keep, clean, remUnicode); // Skip the games node now that we've processed it xtr.Skip(); break; default: xtr.Read(); break; } } } catch (Exception ex) { Globals.Logger.Warning("Exception found while parsing '{0}': {1}", filename, ex); // For XML errors, just skip the affected node xtr?.Read(); } xtr.Dispose(); } /// /// Read configuration information /// /// XmlReader to use to parse the header /// True if full pathnames are to be kept, false otherwise (default) private void ReadConfiguration(XmlReader reader, bool keep) { bool superdat = false; // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all configuration items (ONLY OVERWRITE IF THERE'S NO DATA) string content = ""; switch (reader.Name.ToLowerInvariant()) { case "datname": content = reader.ReadElementContentAsString(); Name = (String.IsNullOrWhiteSpace(Name) ? content : Name); superdat = superdat || content.Contains(" - SuperDAT"); if (keep && superdat) { Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type); } break; case "datversion": content = reader.ReadElementContentAsString(); Version = (String.IsNullOrWhiteSpace(Version) ? content : Version); break; case "system": content = reader.ReadElementContentAsString(); // string system = content; break; case "screenshotswidth": content = reader.ReadElementContentAsString(); // string screenshotsWidth = content; // Int32? break; case "screenshotsheight": content = reader.ReadElementContentAsString(); // string screenshotsHeight = content; // Int32? break; case "infos": ReadInfos(reader.ReadSubtree()); // Skip the infos node now that we've processed it reader.Skip(); break; case "canopen": ReadCanOpen(reader.ReadSubtree()); // Skip the canopen node now that we've processed it reader.Skip(); break; case "newdat": ReadNewDat(reader.ReadSubtree()); // Skip the newdat node now that we've processed it reader.Skip(); break; case "search": ReadSearch(reader.ReadSubtree()); // Skip the search node now that we've processed it reader.Skip(); break; case "romtitle": content = reader.ReadElementContentAsString(); // string romtitle = content; break; default: reader.Read(); break; } } } /// /// Read infos information /// /// XmlReader to use to parse the header private void ReadInfos(XmlReader reader) { // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all infos items switch (reader.Name.ToLowerInvariant()) { case "title": // string title_visible = reader.GetAttribute("visible"); // (true|false) // string title_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string title_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "location": // string location_visible = reader.GetAttribute("visible"); // (true|false) // string location_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string location_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "publisher": // string publisher_visible = reader.GetAttribute("visible"); // (true|false) // string publisher_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string publisher_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "sourcerom": // string sourceRom_visible = reader.GetAttribute("visible"); // (true|false) // string sourceRom_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string sourceRom_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "savetype": // string saveType_visible = reader.GetAttribute("visible"); // (true|false) // string saveType_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string saveType_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "romsize": // string romSize_visible = reader.GetAttribute("visible"); // (true|false) // string romSize_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string romSize_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "releasenumber": // string releaseNumber_visible = reader.GetAttribute("visible"); // (true|false) // string releaseNumber_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string releaseNumber_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "languagenumber": // string languageNumber_visible = reader.GetAttribute("visible"); // (true|false) // string languageNumber_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string languageNumber_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "comment": // string comment_visible = reader.GetAttribute("visible"); // (true|false) // string comment_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string comment_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "romcrc": // string romCRC_visible = reader.GetAttribute("visible"); // (true|false) // string romCRC_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string romCRC_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "im1crc": // string im1CRC_visible = reader.GetAttribute("visible"); // (true|false) // string im1CRC_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string im1CRC_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "im2crc": // string im2CRC_visible = reader.GetAttribute("visible"); // (true|false) // string im2CRC_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string im2CRC_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; case "languages": // string languages_visible = reader.GetAttribute("visible"); // (true|false) // string languages_inNamingOption = reader.GetAttribute("inNamingOption"); // (true|false) // string languages_default = reader.GetAttribute("default"); // (true|false) reader.Read(); break; default: reader.Read(); break; } } } /// /// Read canopen information /// /// XmlReader to use to parse the header private void ReadCanOpen(XmlReader reader) { // Prepare all internal variables List extensions = new List(); // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all canopen items switch (reader.Name.ToLowerInvariant()) { case "extension": extensions.Add(reader.ReadElementContentAsString()); break; default: reader.Read(); break; } } } /// /// Read newdat information /// /// XmlReader to use to parse the header private void ReadNewDat(XmlReader reader) { // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all newdat items string content = ""; switch (reader.Name.ToLowerInvariant()) { case "datversionurl": content = reader.ReadElementContentAsString(); Url = (String.IsNullOrWhiteSpace(Name) ? content : Url); break; case "daturl": // string fileName = reader.GetAttribute("fileName"); content = reader.ReadElementContentAsString(); // string url = content; break; case "imurl": content = reader.ReadElementContentAsString(); // string url = content; break; default: reader.Read(); break; } } } /// /// Read search information /// /// XmlReader to use to parse the header private void ReadSearch(XmlReader reader) { // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all search items string content = ""; switch (reader.Name.ToLowerInvariant()) { case "to": // string value = reader.GetAttribute("value"); // string default = reader.GetAttribute("default"); (true|false) // string auto = reader.GetAttribute("auto"); (true|false) ReadTo(reader.ReadSubtree()); // Skip the to node now that we've processed it reader.Skip(); break; default: reader.Read(); break; } } } /// /// Read to information /// /// XmlReader to use to parse the header private void ReadTo(XmlReader reader) { // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all search items string content = ""; switch (reader.Name.ToLowerInvariant()) { case "find": // string operation = reader.GetAttribute("operation"); // string value = reader.GetAttribute("value"); // Int32? content = reader.ReadElementContentAsString(); // string findValue = content; break; default: reader.Read(); break; } } } /// /// Read games information /// /// XmlReader to use to parse the header /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) private void ReadGames(XmlReader reader, // Miscellaneous bool keep, bool clean, bool remUnicode) { // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all games items (ONLY OVERWRITE IF THERE'S NO DATA) switch (reader.Name.ToLowerInvariant()) { case "game": ReadGame(reader.ReadSubtree(), keep, clean, remUnicode); // Skip the game node now that we've processed it reader.Skip(); break; default: reader.Read(); break; } } } /// /// Read game information /// /// XmlReader to use to parse the header /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) private void ReadGame(XmlReader reader, // Miscellaneous bool keep, bool clean, bool remUnicode) { // Prepare all internal variables string releaseNumber = "", key = "", publisher = "", duplicateid = ""; long size = -1; List roms = new List(); Machine machine = new Machine(); // If there's no subtree to the configuration, skip it if (reader == null) { return; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all games items string content = ""; switch (reader.Name.ToLowerInvariant()) { case "imagenumber": content = reader.ReadElementContentAsString(); // string imageNumber = content; break; case "releasenumber": releaseNumber = reader.ReadElementContentAsString(); break; case "title": content = reader.ReadElementContentAsString(); machine.Name = content; break; case "savetype": content = reader.ReadElementContentAsString(); // string saveType = content; break; case "romsize": if (!Int64.TryParse(reader.ReadElementContentAsString(), out size)) { size = -1; } break; case "publisher": publisher = reader.ReadElementContentAsString(); break; case "location": content = reader.ReadElementContentAsString(); // string location = content; break; case "sourcerom": content = reader.ReadElementContentAsString(); // string sourceRom = content; break; case "language": content = reader.ReadElementContentAsString(); // string language = content; break; case "files": roms = ReadFiles(reader.ReadSubtree(), releaseNumber, machine.Name, keep, clean, remUnicode); // Skip the files node now that we've processed it reader.Skip(); break; case "im1crc": content = reader.ReadElementContentAsString(); // string im1crc = content; break; case "im2crc": content = reader.ReadElementContentAsString(); // string im2crc = content; break; case "comment": machine.Comment = reader.ReadElementContentAsString(); break; case "duplicateid": duplicateid = reader.ReadElementContentAsString(); if (duplicateid != "0") { machine.CloneOf = duplicateid; } break; default: reader.Read(); break; } } // Add information accordingly for each rom for (int i = 0; i < roms.Count; i++) { roms[i].Size = size; roms[i].Publisher = publisher; roms[i].CopyMachineInformation(machine); // Now process and add the rom key = ParseAddHelper(roms[i], clean, remUnicode); } } /// /// Read files information /// /// XmlReader to use to parse the header /// Release number from the parent game /// Name of the parent game to use /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) private List ReadFiles(XmlReader reader, string releaseNumber, string machineName, // Miscellaneous bool keep, bool clean, bool remUnicode) { // Prepare all internal variables List> extensionToCrc = new List>(); List roms = new List(); // If there's no subtree to the configuration, skip it if (reader == null) { return roms; } // Otherwise, add what is possible reader.MoveToContent(); // Otherwise, read what we can from the header while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get all romCRC items switch (reader.Name.ToLowerInvariant()) { case "romcrc": extensionToCrc.Add( new Tuple( reader.GetAttribute("extension") ?? "", reader.ReadElementContentAsString().ToLowerInvariant())); break; default: reader.Read(); break; } } // Now process the roms with the proper information foreach (Tuple pair in extensionToCrc) { roms.Add(new Rom() { Name = (releaseNumber != "0" ? releaseNumber + " - " : "") + machineName + pair.Item1, CRC = Utilities.CleanHashData(pair.Item2, Constants.CRCLength), ItemStatus = ItemStatus.None, }); } return roms; } /// /// Create and open an output file for writing direct from a dictionary /// /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise public override bool WriteToFile(string outfile, bool ignoreblanks = false) { try { Globals.Logger.User("Opening file for writing: {0}", outfile); FileStream fs = Utilities.TryCreate(outfile); // If we get back null for some reason, just log and return if (fs == null) { Globals.Logger.Warning("File '{0}' could not be created for writing! Please check to see if the file is writable", outfile); return false; } StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false)); // Write out the header WriteHeader(sw); // Write out each of the machines and roms string lastgame = null; // Get a properly sorted set of keys List keys = Keys; keys.Sort(new NaturalComparer()); foreach (string key in keys) { List roms = this[key]; // 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 if (rom.Name == null || rom.MachineName == null) { 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 if (lastgame != null && lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) { WriteEndGame(sw); } // 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") { Globals.Logger.Verbose("Empty folder found: {0}", rom.MachineName); rom.Name = (rom.Name == "null" ? "-" : rom.Name); ((Rom)rom).Size = Constants.SizeZero; ((Rom)rom).CRC = ((Rom)rom).CRC == "null" ? Constants.CRCZero : null; ((Rom)rom).MD5 = ((Rom)rom).MD5 == "null" ? Constants.MD5Zero : null; ((Rom)rom).SHA1 = ((Rom)rom).SHA1 == "null" ? Constants.SHA1Zero : null; ((Rom)rom).SHA256 = ((Rom)rom).SHA256 == "null" ? Constants.SHA256Zero : null; ((Rom)rom).SHA384 = ((Rom)rom).SHA384 == "null" ? Constants.SHA384Zero : null; ((Rom)rom).SHA512 = ((Rom)rom).SHA512 == "null" ? Constants.SHA512Zero : null; } // Now, output the rom data WriteDatItem(sw, rom, ignoreblanks); // Set the new data to compare against lastgame = rom.MachineName; } } // Write the file footer out WriteFooter(sw); Globals.Logger.Verbose("File written!" + Environment.NewLine); sw.Dispose(); fs.Dispose(); } catch (Exception ex) { Globals.Logger.Error(ex.ToString()); return false; } return true; } /// /// Write out DAT header using the supplied StreamWriter /// /// StreamWriter to output to /// True if the data was written, false on error private bool WriteHeader(StreamWriter sw) { try { string header = "\n" + "\n" + "\t\n" + "\t\t" + HttpUtility.HtmlEncode(Name) + "\n" + "\t\t" + Count + "\n" + "\t\tnone\n" + "\t\t240\n" + "\t\t160\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t<location visible=\"true\" inNamingOption=\"true\" default=\"true\"/>\n" + "\t\t\t<publisher visible=\"true\" inNamingOption=\"true\" default=\"true\"/>\n" + "\t\t\t<sourceRom visible=\"true\" inNamingOption=\"true\" default=\"true\"/>\n" + "\t\t\t<saveType visible=\"true\" inNamingOption=\"true\" default=\"true\"/>\n" + "\t\t\t<romSize visible=\"true\" inNamingOption=\"true\" default=\"true\"/>\n" + "\t\t\t<releaseNumber visible=\"true\" inNamingOption=\"true\" default=\"false\"/>\n" + "\t\t\t<languageNumber visible=\"true\" inNamingOption=\"true\" default=\"false\"/>\n" + "\t\t\t<comment visible=\"true\" inNamingOption=\"true\" default=\"false\"/>\n" + "\t\t\t<romCRC visible=\"true\" inNamingOption=\"true\" default=\"false\"/>\n" + "\t\t\t<im1CRC visible=\"false\" inNamingOption=\"false\" default=\"false\"/>\n" + "\t\t\t<im2CRC visible=\"false\" inNamingOption=\"false\" default=\"false\"/>\n" + "\t\t\t<languages visible=\"true\" inNamingOption=\"true\" default=\"true\"/>\n" + "\t\t</infos>\n" + "\t\t<canOpen>\n" + "\t\t\t<extension>.bin</extension>\n" + "\t\t</canOpen>\n" + "\t\t<newDat>\n" + "\t\t\t<datVersionURL>" + HttpUtility.HtmlEncode(Url) + "</datVersionURL>\n" + "\t\t\t<datURL fileName=\"" + HttpUtility.HtmlEncode(FileName) + ".zip\">" + HttpUtility.HtmlEncode(Url) + "</datURL>\n" + "\t\t\t<imURL>" + HttpUtility.HtmlEncode(Url) + "</imURL>\n" + "\t\t</newDat>\n" + "\t\t<search>\n" + "\t\t\t<to value=\"location\" default=\"true\" auto=\"true\"/>\n" + "\t\t\t<to value=\"romSize\" default=\"true\" auto=\"false\"/>\n" + "\t\t\t<to value=\"languages\" default=\"true\" auto=\"true\"/>\n" + "\t\t\t<to value=\"saveType\" default=\"false\" auto=\"false\"/>\n" + "\t\t\t<to value=\"publisher\" default=\"false\" auto=\"true\"/>\n" + "\t\t\t<to value=\"sourceRom\" default=\"false\" auto=\"true\"/>\n" + "\t\t</search>\n" + "\t\t<romTitle >%u - %n</romTitle>\n" + "\t</configuration>\n" + "\t<games>\n"; // Write the header out sw.Write(header); sw.Flush(); } catch (Exception ex) { Globals.Logger.Error(ex.ToString()); return false; } return true; } /// <summary> /// Write out Game start using the supplied StreamWriter /// </summary> /// <param name="sw">StreamWriter to output to</param> /// <returns>True if the data was written, false on error</returns> private bool WriteEndGame(StreamWriter sw) { try { string state = "\t\t</game>\n"; sw.Write(state); sw.Flush(); } catch (Exception ex) { Globals.Logger.Error(ex.ToString()); return false; } return true; } /// <summary> /// Write out DatItem using the supplied StreamWriter /// </summary> /// <param name="sw">StreamWriter to output to</param> /// <param name="rom">DatItem object to be output</param> /// <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(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks && (rom.ItemType == ItemType.Rom && (((Rom)rom).Size == 0 || ((Rom)rom).Size == -1))) { return true; } try { string state = ""; // Pre-process the item name ProcessItemName(rom, true); state += "\t\t<game>\n" + "\t\t\t<imageNumber>1</imageNumber>\n" + "\t\t\t<releaseNumber>1</releaseNumber>\n" + "\t\t\t<title>" + (!ExcludeFields[(int)Field.Name] ? HttpUtility.HtmlEncode(rom.Name) : "") + "\n" + "\t\t\tNone\n"; if (rom.ItemType == ItemType.Rom) { state += "\t\t\t" + (!ExcludeFields[(int)Field.Size] ? ((Rom)rom).Size.ToString() : "") + "\n"; } state += "\t\t\tNone\n" + "\t\t\t0\n" + "\t\t\tNone\n" + "\t\t\t0\n"; if (rom.ItemType == ItemType.Disk) { state += "\t\t\t\n" + (((Disk)rom).MD5 != null ? "\t\t\t\t" + (!ExcludeFields[(int)Field.MD5] ? ((Disk)rom).MD5.ToUpperInvariant() : "") + "\n" : "\t\t\t\t" + (!ExcludeFields[(int)Field.SHA1] ? ((Disk)rom).SHA1.ToUpperInvariant() : "") + "\n") + "\t\t\t\n"; } else if (rom.ItemType == ItemType.Rom) { string tempext = "." + Utilities.GetExtension(((Rom)rom).Name); state += "\t\t\t\n" + (((Rom)rom).CRC != null ? "\t\t\t\t" + (!ExcludeFields[(int)Field.CRC] ? ((Rom)rom).CRC.ToUpperInvariant() : "") + "\n" : ((Rom)rom).MD5 != null ? "\t\t\t\t" + (!ExcludeFields[(int)Field.MD5] ? ((Rom)rom).MD5.ToUpperInvariant() : "") + "\n" : "\t\t\t\t" + (!ExcludeFields[(int)Field.SHA1] ? ((Rom)rom).SHA1.ToUpperInvariant() : "") + "\n") + "\t\t\t\n"; } state += "\t\t\t00000000\n" + "\t\t\t00000000\n" + "\t\t\t\n" + "\t\t\t0\n" + "\t\t\n"; sw.Write(state); sw.Flush(); } catch (Exception ex) { Globals.Logger.Error(ex.ToString()); return false; } return true; } /// /// Write out DAT footer using the supplied StreamWriter /// /// StreamWriter to output to /// True if the data was written, false on error private bool WriteFooter(StreamWriter sw) { try { string footer = "\t\t" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\n" + ""; // Write the footer out sw.Write(footer); sw.Flush(); } catch (Exception ex) { Globals.Logger.Error(ex.ToString()); return false; } return true; } } }