mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Cleanup and overhaul (#21)
* Syntax cleanup * More minor cleanup, use Linq * Fix broken features by using correct values * Feature flags the same * Features are modular * No AlphaFS, more .NET versions * Fix appveyor * Put back identifiers, for some reason * String interpolation, modernization * Better use of GetField * XmlTextWriter to remove possible issues * Fix header for OpenMSX
This commit is contained in:
@@ -1,21 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
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
|
||||
@@ -57,7 +49,7 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
// Prepare all internal variables
|
||||
bool empty = true;
|
||||
string key = "";
|
||||
string key = string.Empty;
|
||||
List<string> parent = new List<string>();
|
||||
|
||||
Encoding enc = Utilities.GetEncoding(filename);
|
||||
@@ -65,9 +57,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// If we got a null reader, just return
|
||||
if (xtr == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, read the file to the end
|
||||
try
|
||||
@@ -81,7 +71,7 @@ namespace SabreTools.Library.DatFiles
|
||||
// If we didn't find any items in the folder, make sure to add the blank rom
|
||||
if (empty)
|
||||
{
|
||||
string tempgame = String.Join("\\", parent);
|
||||
string tempgame = string.Join("\\", parent);
|
||||
Rom rom = new Rom("null", tempgame, omitFromScan: Hash.DeepHashes); // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||
|
||||
// Now process and add the rom
|
||||
@@ -92,7 +82,7 @@ namespace SabreTools.Library.DatFiles
|
||||
int parentcount = parent.Count;
|
||||
if (parentcount == 0)
|
||||
{
|
||||
Globals.Logger.Verbose("Empty parent '{0}' found in '{1}'", String.Join("\\", parent), filename);
|
||||
Globals.Logger.Verbose($"Empty parent '{string.Join("\\", parent)}' found in '{filename}'");
|
||||
empty = true;
|
||||
}
|
||||
|
||||
@@ -101,9 +91,7 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
parent.RemoveAt(parent.Count - 1);
|
||||
if (keep && parentcount > 1)
|
||||
{
|
||||
Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
|
||||
}
|
||||
Type = (string.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +111,7 @@ namespace SabreTools.Library.DatFiles
|
||||
// Skip the header node now that we've processed it
|
||||
xtr.Skip();
|
||||
break;
|
||||
|
||||
case "dir":
|
||||
case "directory":
|
||||
empty = ReadDirectory(xtr.ReadSubtree(), parent, filename, sysid, srcid, keep, clean, remUnicode);
|
||||
@@ -138,7 +127,7 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Warning("Exception found while parsing '{0}': {1}", filename, ex);
|
||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||
|
||||
// For XML errors, just skip the affected node
|
||||
xtr?.Read();
|
||||
@@ -158,9 +147,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// If there's no subtree to the header, skip it
|
||||
if (reader == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, read what we can from the header
|
||||
while (!reader.EOF)
|
||||
@@ -173,55 +160,64 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// Get all header items (ONLY OVERWRITE IF THERE'S NO DATA)
|
||||
string content = "";
|
||||
string content = string.Empty;
|
||||
switch (reader.Name)
|
||||
{
|
||||
case "name":
|
||||
content = reader.ReadElementContentAsString(); ;
|
||||
Name = (String.IsNullOrWhiteSpace(Name) ? content : Name);
|
||||
Name = (string.IsNullOrWhiteSpace(Name) ? content : Name);
|
||||
superdat = superdat || content.Contains(" - SuperDAT");
|
||||
if (keep && superdat)
|
||||
{
|
||||
Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
|
||||
Type = (string.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
|
||||
}
|
||||
break;
|
||||
|
||||
case "description":
|
||||
content = reader.ReadElementContentAsString();
|
||||
Description = (String.IsNullOrWhiteSpace(Description) ? content : Description);
|
||||
Description = (string.IsNullOrWhiteSpace(Description) ? content : Description);
|
||||
break;
|
||||
|
||||
case "rootdir":
|
||||
content = reader.ReadElementContentAsString();
|
||||
RootDir = (String.IsNullOrWhiteSpace(RootDir) ? content : RootDir);
|
||||
RootDir = (string.IsNullOrWhiteSpace(RootDir) ? content : RootDir);
|
||||
break;
|
||||
|
||||
case "category":
|
||||
content = reader.ReadElementContentAsString();
|
||||
Category = (String.IsNullOrWhiteSpace(Category) ? content : Category);
|
||||
Category = (string.IsNullOrWhiteSpace(Category) ? content : Category);
|
||||
break;
|
||||
|
||||
case "version":
|
||||
content = reader.ReadElementContentAsString();
|
||||
Version = (String.IsNullOrWhiteSpace(Version) ? content : Version);
|
||||
Version = (string.IsNullOrWhiteSpace(Version) ? content : Version);
|
||||
break;
|
||||
|
||||
case "date":
|
||||
content = reader.ReadElementContentAsString();
|
||||
Date = (String.IsNullOrWhiteSpace(Date) ? content.Replace(".", "/") : Date);
|
||||
Date = (string.IsNullOrWhiteSpace(Date) ? content.Replace(".", "/") : Date);
|
||||
break;
|
||||
|
||||
case "author":
|
||||
content = reader.ReadElementContentAsString();
|
||||
Author = (String.IsNullOrWhiteSpace(Author) ? content : Author);
|
||||
Email = (String.IsNullOrWhiteSpace(Email) ? reader.GetAttribute("email") : Email);
|
||||
Homepage = (String.IsNullOrWhiteSpace(Homepage) ? reader.GetAttribute("homepage") : Homepage);
|
||||
Url = (String.IsNullOrWhiteSpace(Url) ? reader.GetAttribute("url") : Url);
|
||||
Author = (string.IsNullOrWhiteSpace(Author) ? content : Author);
|
||||
Email = (string.IsNullOrWhiteSpace(Email) ? reader.GetAttribute("email") : Email);
|
||||
Homepage = (string.IsNullOrWhiteSpace(Homepage) ? reader.GetAttribute("homepage") : Homepage);
|
||||
Url = (string.IsNullOrWhiteSpace(Url) ? reader.GetAttribute("url") : Url);
|
||||
break;
|
||||
|
||||
case "comment":
|
||||
content = reader.ReadElementContentAsString();
|
||||
Comment = (String.IsNullOrWhiteSpace(Comment) ? content : Comment);
|
||||
Comment = (string.IsNullOrWhiteSpace(Comment) ? content : Comment);
|
||||
break;
|
||||
|
||||
case "flags":
|
||||
ReadFlags(reader.ReadSubtree(), superdat);
|
||||
|
||||
// Skip the flags node now that we've processed it
|
||||
reader.Skip();
|
||||
break;
|
||||
|
||||
default:
|
||||
reader.Read();
|
||||
break;
|
||||
@@ -255,21 +251,17 @@ namespace SabreTools.Library.DatFiles
|
||||
// Prepare all internal variables
|
||||
XmlReader flagreader;
|
||||
bool empty = true;
|
||||
string key = "", date = "";
|
||||
string key = string.Empty, date = string.Empty;
|
||||
long size = -1;
|
||||
ItemStatus its = ItemStatus.None;
|
||||
|
||||
// If there's no subtree to the header, skip it
|
||||
if (reader == null)
|
||||
{
|
||||
return empty;
|
||||
}
|
||||
|
||||
string foldername = (reader.GetAttribute("name") ?? "");
|
||||
if (!String.IsNullOrWhiteSpace(foldername))
|
||||
{
|
||||
string foldername = (reader.GetAttribute("name") ?? string.Empty);
|
||||
if (!string.IsNullOrWhiteSpace(foldername))
|
||||
parent.Add(foldername);
|
||||
}
|
||||
|
||||
// Otherwise, read what we can from the directory
|
||||
while (!reader.EOF)
|
||||
@@ -280,7 +272,7 @@ namespace SabreTools.Library.DatFiles
|
||||
// If we didn't find any items in the folder, make sure to add the blank rom
|
||||
if (empty)
|
||||
{
|
||||
string tempgame = String.Join("\\", parent);
|
||||
string tempgame = string.Join("\\", parent);
|
||||
Rom rom = new Rom("null", tempgame, omitFromScan: Hash.DeepHashes); // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||
|
||||
// Now process and add the rom
|
||||
@@ -291,7 +283,7 @@ namespace SabreTools.Library.DatFiles
|
||||
int parentcount = parent.Count;
|
||||
if (parentcount == 0)
|
||||
{
|
||||
Globals.Logger.Verbose("Empty parent '{0}' found in '{1}'", String.Join("\\", parent), filename);
|
||||
Globals.Logger.Verbose($"Empty parent '{string.Join("\\", parent)}' found in '{filename}'");
|
||||
empty = true;
|
||||
}
|
||||
|
||||
@@ -300,9 +292,7 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
parent.RemoveAt(parent.Count - 1);
|
||||
if (keep && parentcount > 1)
|
||||
{
|
||||
Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
|
||||
}
|
||||
Type = (string.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +304,7 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// Get all directory items
|
||||
string content = "";
|
||||
string content = string.Empty;
|
||||
switch (reader.Name)
|
||||
{
|
||||
// Directories can contain directories
|
||||
@@ -325,6 +315,7 @@ namespace SabreTools.Library.DatFiles
|
||||
// Skip the directory node now that we've processed it
|
||||
reader.Read();
|
||||
break;
|
||||
|
||||
case "file":
|
||||
empty = false;
|
||||
|
||||
@@ -371,7 +362,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Machine dir = new Machine();
|
||||
|
||||
// Get the name of the game from the parent
|
||||
dir.Name = String.Join("\\", parent);
|
||||
dir.Name = string.Join("\\", parent);
|
||||
dir.Description = dir.Name;
|
||||
|
||||
DatItem datItem;
|
||||
@@ -387,6 +378,7 @@ namespace SabreTools.Library.DatFiles
|
||||
SourceID = srcid,
|
||||
};
|
||||
break;
|
||||
|
||||
case "biosset":
|
||||
datItem = new BiosSet
|
||||
{
|
||||
@@ -399,6 +391,7 @@ namespace SabreTools.Library.DatFiles
|
||||
SourceID = srcid,
|
||||
};
|
||||
break;
|
||||
|
||||
case "disk":
|
||||
datItem = new Disk
|
||||
{
|
||||
@@ -416,6 +409,7 @@ namespace SabreTools.Library.DatFiles
|
||||
SourceID = srcid,
|
||||
};
|
||||
break;
|
||||
|
||||
case "release":
|
||||
datItem = new Release
|
||||
{
|
||||
@@ -430,6 +424,7 @@ namespace SabreTools.Library.DatFiles
|
||||
SourceID = srcid,
|
||||
};
|
||||
break;
|
||||
|
||||
case "rom":
|
||||
datItem = new Rom
|
||||
{
|
||||
@@ -450,6 +445,7 @@ namespace SabreTools.Library.DatFiles
|
||||
SourceID = srcid,
|
||||
};
|
||||
break;
|
||||
|
||||
case "sample":
|
||||
datItem = new Sample
|
||||
{
|
||||
@@ -460,6 +456,7 @@ namespace SabreTools.Library.DatFiles
|
||||
SourceID = srcid,
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
// By default, create a new Blank, just in case
|
||||
datItem = new Blank();
|
||||
@@ -487,13 +484,11 @@ namespace SabreTools.Library.DatFiles
|
||||
private void ReadFlags(XmlReader reader, bool superdat)
|
||||
{
|
||||
// Prepare all internal variables
|
||||
string content = "";
|
||||
string content = string.Empty;
|
||||
|
||||
// If we somehow have a null flag section, skip it
|
||||
if (reader == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (!reader.EOF)
|
||||
{
|
||||
@@ -513,21 +508,24 @@ namespace SabreTools.Library.DatFiles
|
||||
switch (reader.GetAttribute("name").ToLowerInvariant())
|
||||
{
|
||||
case "type":
|
||||
Type = (String.IsNullOrWhiteSpace(Type) ? content : Type);
|
||||
Type = (string.IsNullOrWhiteSpace(Type) ? content : Type);
|
||||
superdat = superdat || content.Contains("SuperDAT");
|
||||
break;
|
||||
|
||||
case "forcemerging":
|
||||
if (ForceMerging == ForceMerging.None)
|
||||
{
|
||||
ForceMerging = Utilities.GetForceMerging(content);
|
||||
}
|
||||
break;
|
||||
|
||||
case "forcenodump":
|
||||
if (ForceNodump == ForceNodump.None)
|
||||
{
|
||||
ForceNodump = Utilities.GetForceNodump(content);
|
||||
}
|
||||
break;
|
||||
|
||||
case "forcepacking":
|
||||
if (ForcePacking == ForcePacking.None)
|
||||
{
|
||||
@@ -536,8 +534,10 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
reader.Read();
|
||||
break;
|
||||
|
||||
default:
|
||||
reader.Read();
|
||||
break;
|
||||
@@ -556,20 +556,21 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
try
|
||||
{
|
||||
Globals.Logger.User("Opening file for writing: {0}", outfile);
|
||||
Globals.Logger.User($"Opening file for writing: {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);
|
||||
Globals.Logger.Warning($"File '{outfile}' could not be created for writing! Please check to see if the file is writable");
|
||||
return false;
|
||||
}
|
||||
|
||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
|
||||
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false));
|
||||
xtw.Formatting = Formatting.Indented;
|
||||
|
||||
// Write out the header
|
||||
WriteHeader(sw);
|
||||
WriteHeader(xtw);
|
||||
|
||||
// Write out each of the machines and roms
|
||||
int depth = 2, last = -1;
|
||||
@@ -602,22 +603,18 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// 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())
|
||||
{
|
||||
depth = WriteEndGame(sw, splitpath, newsplit, depth, out last);
|
||||
}
|
||||
depth = WriteEndGame(xtw, splitpath, newsplit, depth, out last);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant())
|
||||
{
|
||||
depth = WriteStartGame(sw, rom, newsplit, lastgame, depth, last);
|
||||
}
|
||||
depth = WriteStartGame(xtw, rom, newsplit, lastgame, depth, last);
|
||||
|
||||
// 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);
|
||||
Globals.Logger.Verbose($"Empty folder found: {rom.MachineName}");
|
||||
|
||||
splitpath = newsplit;
|
||||
lastgame = rom.MachineName;
|
||||
@@ -625,7 +622,7 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// Now, output the rom data
|
||||
WriteDatItem(sw, rom, depth, ignoreblanks);
|
||||
WriteDatItem(xtw, rom, depth, ignoreblanks);
|
||||
|
||||
// Set the new data to compare against
|
||||
splitpath = newsplit;
|
||||
@@ -634,10 +631,10 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
|
||||
// Write the file footer out
|
||||
WriteFooter(sw, depth);
|
||||
WriteFooter(xtw, depth);
|
||||
|
||||
Globals.Logger.Verbose("File written!" + Environment.NewLine);
|
||||
sw.Dispose();
|
||||
xtw.Dispose();
|
||||
fs.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -652,44 +649,119 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <summary>
|
||||
/// Write out DAT header using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private bool WriteHeader(StreamWriter sw)
|
||||
private bool WriteHeader(XmlTextWriter xtw)
|
||||
{
|
||||
try
|
||||
{
|
||||
string header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<!DOCTYPE sabredat SYSTEM \"newdat.xsd\">\n\n" +
|
||||
"<datafile>\n" +
|
||||
"\t<header>\n" +
|
||||
"\t\t<name>" + WebUtility.HtmlEncode(Name) + "</name>\n" +
|
||||
"\t\t<description>" + WebUtility.HtmlEncode(Description) + "</description>\n" +
|
||||
(!String.IsNullOrWhiteSpace(RootDir) ? "\t\t<rootdir>" + WebUtility.HtmlEncode(RootDir) + "</rootdir>\n" : "") +
|
||||
(!String.IsNullOrWhiteSpace(Category) ? "\t\t<category>" + WebUtility.HtmlEncode(Category) + "</category>\n" : "") +
|
||||
"\t\t<version>" + WebUtility.HtmlEncode(Version) + "</version>\n" +
|
||||
(!String.IsNullOrWhiteSpace(Date) ? "\t\t<date>" + WebUtility.HtmlEncode(Date) + "</date>\n" : "") +
|
||||
"\t\t<author>" + WebUtility.HtmlEncode(Author) + "</author>\n" +
|
||||
(!String.IsNullOrWhiteSpace(Comment) ? "\t\t<comment>" + WebUtility.HtmlEncode(Comment) + "</comment>\n" : "") +
|
||||
(!String.IsNullOrWhiteSpace(Type) || ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ?
|
||||
"\t\t<flags>\n" +
|
||||
(!String.IsNullOrWhiteSpace(Type) ? "\t\t\t<flag name=\"type\" value=\"" + WebUtility.HtmlEncode(Type) + "\"/>\n" : "") +
|
||||
(ForcePacking == ForcePacking.Unzip ? "\t\t\t<flag name=\"forcepacking\" value=\"unzip\"/>\n" : "") +
|
||||
(ForcePacking == ForcePacking.Zip ? "\t\t\t<flag name=\"forcepacking\" value=\"zip\"/>\n" : "") +
|
||||
(ForceMerging == ForceMerging.Full ? "\t\t\t<flag name=\"forcemerging\" value=\"full\"/>\n" : "") +
|
||||
(ForceMerging == ForceMerging.Split ? "\t\t\t<flag name=\"forcemerging\" value=\"split\"/>\n" : "") +
|
||||
(ForceMerging == ForceMerging.Merged ? "\t\t\t<flag name=\"forcemerging\" value=\"merged\"/>\n" : "") +
|
||||
(ForceMerging == ForceMerging.NonMerged ? "\t\t\t<flag name=\"forcemerging\" value=\"nonmerged\"/>\n" : "") +
|
||||
(ForceNodump == ForceNodump.Ignore ? "\t\t\t<flag name=\"forcenodump\" value=\"ignore\"/>\n" : "") +
|
||||
(ForceNodump == ForceNodump.Obsolete ? "\t\t\t<flag name=\"forcenodump\" value=\"obsolete\"/>\n" : "") +
|
||||
(ForceNodump == ForceNodump.Required ? "\t\t\t<flag name=\"forcenodump\" value=\"required\"/>\n" : "") +
|
||||
"\t\t</flags>\n"
|
||||
: "") +
|
||||
"\t</header>\n" +
|
||||
"\t<data>\n";
|
||||
xtw.WriteStartDocument();
|
||||
xtw.WriteDocType("sabredat", null, "newdat.xsd", null);
|
||||
|
||||
// Write the header out
|
||||
sw.Write(header);
|
||||
sw.Flush();
|
||||
xtw.WriteStartElement("datafile");
|
||||
|
||||
xtw.WriteStartElement("header");
|
||||
|
||||
xtw.WriteElementString("name", Name);
|
||||
xtw.WriteElementString("description", Description);
|
||||
if (!string.IsNullOrWhiteSpace(RootDir))
|
||||
xtw.WriteElementString("rootdir", RootDir);
|
||||
if (!string.IsNullOrWhiteSpace(Category))
|
||||
xtw.WriteElementString("category", Category);
|
||||
xtw.WriteElementString("version", Version);
|
||||
if (!string.IsNullOrWhiteSpace(Date))
|
||||
xtw.WriteElementString("date", Date);
|
||||
xtw.WriteElementString("author", Author);
|
||||
if (!string.IsNullOrWhiteSpace(Comment))
|
||||
xtw.WriteElementString("comment", Comment);
|
||||
if (!string.IsNullOrWhiteSpace(Type) || ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None)
|
||||
{
|
||||
xtw.WriteStartElement("flags");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Type))
|
||||
{
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "type");
|
||||
xtw.WriteAttributeString("value", Type);
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
switch (ForcePacking)
|
||||
{
|
||||
case ForcePacking.Unzip:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcepacking");
|
||||
xtw.WriteAttributeString("value", "unzip");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ForcePacking.Zip:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcepacking");
|
||||
xtw.WriteAttributeString("value", "zip");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
switch (ForceMerging)
|
||||
{
|
||||
case ForceMerging.Full:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcemerging");
|
||||
xtw.WriteAttributeString("value", "full");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ForceMerging.Split:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcemerging");
|
||||
xtw.WriteAttributeString("value", "split");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ForceMerging.Merged:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcemerging");
|
||||
xtw.WriteAttributeString("value", "merged");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ForceMerging.NonMerged:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcemerging");
|
||||
xtw.WriteAttributeString("value", "nonmerged");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
switch (ForceNodump)
|
||||
{
|
||||
case ForceNodump.Ignore:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcenodump");
|
||||
xtw.WriteAttributeString("value", "ignore");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ForceNodump.Obsolete:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcenodump");
|
||||
xtw.WriteAttributeString("value", "obsolete");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
case ForceNodump.Required:
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "forcenodump");
|
||||
xtw.WriteAttributeString("value", "required");
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
// End flags
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
// End header
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("data");
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -703,37 +775,31 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <summary>
|
||||
/// Write out Game start using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <param name="rom">DatItem object to be output</param>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
/// <param name="newsplit">Split path representing the parent game (SabreDAT only)</param>
|
||||
/// <param name="lastgame">The name of the last game to be output</param>
|
||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
||||
/// <param name="last">Last known depth to cycle back from (SabreDAT only)</param>
|
||||
/// <returns>The new depth of the tag</returns>
|
||||
private int WriteStartGame(StreamWriter sw, DatItem rom, List<string> newsplit, string lastgame, int depth, int last)
|
||||
private int WriteStartGame(XmlTextWriter xtw, DatItem datItem, List<string> newsplit, string lastgame, int depth, int last)
|
||||
{
|
||||
try
|
||||
{
|
||||
// No game should start with a path separator
|
||||
if (rom.MachineName.StartsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
rom.MachineName = rom.MachineName.Substring(1);
|
||||
}
|
||||
datItem.MachineName = datItem.MachineName.TrimStart(Path.DirectorySeparatorChar);
|
||||
|
||||
string state = "";
|
||||
// Build the state based on excluded fields
|
||||
for (int i = (last == -1 ? 0 : last); i < newsplit.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < depth - last + i - (lastgame == null ? 1 : 0); j++)
|
||||
{
|
||||
state += "\t";
|
||||
}
|
||||
state += "<directory name=\"" + (!ExcludeFields[(int)Field.MachineName] ? WebUtility.HtmlEncode(newsplit[i]) : "") + "\" description=\"" +
|
||||
WebUtility.HtmlEncode(newsplit[i]) + "\">\n";
|
||||
xtw.WriteStartElement("directory");
|
||||
xtw.WriteAttributeString("name", !ExcludeFields[(int)Field.MachineName] ? newsplit[i] : string.Empty);
|
||||
xtw.WriteAttributeString("description", !ExcludeFields[(int)Field.MachineName] ? newsplit[i] : string.Empty);
|
||||
}
|
||||
|
||||
depth = depth - (last == -1 ? 0 : last) + newsplit.Count;
|
||||
|
||||
sw.Write(state);
|
||||
sw.Flush();
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -747,19 +813,18 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <summary>
|
||||
/// Write out Game start using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="splitpath">Split path representing last kwown parent game (SabreDAT only)</param>
|
||||
/// <param name="newsplit">Split path representing the parent game (SabreDAT only)</param>
|
||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
||||
/// <param name="last">Last known depth to cycle back from (SabreDAT only)</param>
|
||||
/// <returns>The new depth of the tag</returns>
|
||||
private int WriteEndGame(StreamWriter sw, List<string> splitpath, List<string> newsplit, int depth, out int last)
|
||||
private int WriteEndGame(XmlTextWriter xtw, List<string> splitpath, List<string> newsplit, int depth, out int last)
|
||||
{
|
||||
last = 0;
|
||||
|
||||
try
|
||||
{
|
||||
string state = "";
|
||||
if (splitpath != null)
|
||||
{
|
||||
for (int i = 0; i < newsplit.Count && i < splitpath.Count; i++)
|
||||
@@ -769,28 +834,21 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// If we find a difference, break
|
||||
if (newsplit[i] != splitpath[i])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we have the last known position, take down all open folders
|
||||
for (int i = depth - 1; i > last + 1; i--)
|
||||
{
|
||||
// Print out the number of tabs and the end folder
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
state += "\t";
|
||||
}
|
||||
state += "</directory>\n";
|
||||
// End directory
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
// Reset the current depth
|
||||
depth = 2 + last;
|
||||
}
|
||||
|
||||
sw.Write(state);
|
||||
sw.Flush();
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -804,95 +862,139 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <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="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="datItem">DatItem object to be output</param>
|
||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</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, int depth, bool ignoreblanks = false)
|
||||
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, int depth, 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)))
|
||||
{
|
||||
if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string state = "", prefix = "";
|
||||
|
||||
// Pre-process the item name
|
||||
ProcessItemName(rom, true);
|
||||
ProcessItemName(datItem, true);
|
||||
|
||||
for (int i = 0; i < depth; i++)
|
||||
{
|
||||
prefix += "\t";
|
||||
}
|
||||
state += prefix;
|
||||
|
||||
switch (rom.ItemType)
|
||||
// Build the state based on excluded fields
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
case ItemType.Archive:
|
||||
state += "<file type=\"archive\" name=\"" + (!ExcludeFields[(int)Field.Name] ? WebUtility.HtmlEncode(rom.Name) : "") + "\""
|
||||
+ "/>\n";
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "archive");
|
||||
xtw.WriteAttributeString("name", datItem.GetField(Field.Name, ExcludeFields));
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.BiosSet:
|
||||
state += "<file type=\"biosset\" name\"" + (!ExcludeFields[(int)Field.Name] ? WebUtility.HtmlEncode(rom.Name) : "") + "\""
|
||||
+ (!ExcludeFields[(int)Field.BiosDescription] && !String.IsNullOrWhiteSpace(((BiosSet)rom).Description) ? " description=\"" + WebUtility.HtmlEncode(((BiosSet)rom).Description) + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.Default] && ((BiosSet)rom).Default != null
|
||||
? ((BiosSet)rom).Default.ToString().ToLowerInvariant()
|
||||
: "")
|
||||
+ "/>\n";
|
||||
var biosSet = datItem as BiosSet;
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "biosset");
|
||||
xtw.WriteAttributeString("name", biosSet.GetField(Field.Name, ExcludeFields));
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.BiosDescription, ExcludeFields)))
|
||||
xtw.WriteAttributeString("description", biosSet.Description);
|
||||
if (!ExcludeFields[(int)Field.Default] && biosSet.Default != null)
|
||||
xtw.WriteAttributeString("default", biosSet.Default.ToString().ToLowerInvariant());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Disk:
|
||||
state += "<file type=\"disk\" name=\"" + (!ExcludeFields[(int)Field.Name] ? WebUtility.HtmlEncode(rom.Name) : "") + "\""
|
||||
+ (!ExcludeFields[(int)Field.MD5] && !String.IsNullOrWhiteSpace(((Disk)rom).MD5) ? " md5=\"" + ((Disk)rom).MD5.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.RIPEMD160] && !String.IsNullOrWhiteSpace(((Disk)rom).RIPEMD160) ? " ripemd160=\"" + ((Disk)rom).RIPEMD160.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA1] && !String.IsNullOrWhiteSpace(((Disk)rom).SHA1) ? " sha1=\"" + ((Disk)rom).SHA1.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA256] && !String.IsNullOrWhiteSpace(((Disk)rom).SHA256) ? " sha256=\"" + ((Disk)rom).SHA256.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA384] && !String.IsNullOrWhiteSpace(((Disk)rom).SHA384) ? " sha384=\"" + ((Disk)rom).SHA384.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA512] && !String.IsNullOrWhiteSpace(((Disk)rom).SHA512) ? " sha512=\"" + ((Disk)rom).SHA512.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.Status] && ((Disk)rom).ItemStatus != ItemStatus.None ? prefix + "/>\n" + prefix + "\t<flags>\n" +
|
||||
prefix + "\t\t<flag name=\"status\" value=\"" + ((Disk)rom).ItemStatus.ToString().ToLowerInvariant() + "\"/>\n" +
|
||||
prefix + "\t</flags>\n" +
|
||||
prefix + "</file>\n" : "/>\n");
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "disk");
|
||||
xtw.WriteAttributeString("name", disk.GetField(Field.Name, ExcludeFields));
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.MD5, ExcludeFields)))
|
||||
xtw.WriteAttributeString("md5", disk.MD5.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RIPEMD160, ExcludeFields)))
|
||||
xtw.WriteAttributeString("ripemd160", disk.RIPEMD160.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA1, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha1", disk.SHA1.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA256, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha256", disk.SHA256.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA384, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha384", disk.SHA384.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA512, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha512", disk.SHA512.ToLowerInvariant());
|
||||
if (!ExcludeFields[(int)Field.Status] && disk.ItemStatus != ItemStatus.None)
|
||||
{
|
||||
xtw.WriteStartElement("flags");
|
||||
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "status");
|
||||
xtw.WriteAttributeString("value", disk.ItemStatus.ToString().ToLowerInvariant());
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End flags
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Release:
|
||||
state += "<file type=\"release\" name\"" + (!ExcludeFields[(int)Field.Name] ? WebUtility.HtmlEncode(rom.Name) : "") + "\""
|
||||
+ (!ExcludeFields[(int)Field.Region] && !String.IsNullOrWhiteSpace(((Release)rom).Region) ? " region=\"" + WebUtility.HtmlEncode(((Release)rom).Region) + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.Language] && !String.IsNullOrWhiteSpace(((Release)rom).Language) ? " language=\"" + WebUtility.HtmlEncode(((Release)rom).Language) + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.Date] && !String.IsNullOrWhiteSpace(((Release)rom).Date) ? " date=\"" + WebUtility.HtmlEncode(((Release)rom).Date) + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.Default] && ((Release)rom).Default != null
|
||||
? ((Release)rom).Default.ToString().ToLowerInvariant()
|
||||
: "")
|
||||
+ "/>\n";
|
||||
var release = datItem as Release;
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "release");
|
||||
xtw.WriteAttributeString("name", release.GetField(Field.Name, ExcludeFields));
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Region, ExcludeFields)))
|
||||
xtw.WriteAttributeString("region", release.Region);
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Language, ExcludeFields)))
|
||||
xtw.WriteAttributeString("language", release.Language);
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Date, ExcludeFields)))
|
||||
xtw.WriteAttributeString("date", release.Date);
|
||||
if (!ExcludeFields[(int)Field.Default] && release.Default != null)
|
||||
xtw.WriteAttributeString("default", release.Default.ToString().ToLowerInvariant());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Rom:
|
||||
state += "<file type=\"rom\" name=\"" + (!ExcludeFields[(int)Field.Name] ? WebUtility.HtmlEncode(rom.Name) : "") + "\""
|
||||
+ (!ExcludeFields[(int)Field.Size] && ((Rom)rom).Size != -1 ? " size=\"" + ((Rom)rom).Size + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.CRC] && !String.IsNullOrWhiteSpace(((Rom)rom).CRC) ? " crc=\"" + ((Rom)rom).CRC.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.MD5] && !String.IsNullOrWhiteSpace(((Rom)rom).MD5) ? " md5=\"" + ((Rom)rom).MD5.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.RIPEMD160] && !String.IsNullOrWhiteSpace(((Rom)rom).RIPEMD160) ? " ripemd160=\"" + ((Rom)rom).RIPEMD160.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA1] && !String.IsNullOrWhiteSpace(((Rom)rom).SHA1) ? " sha1=\"" + ((Rom)rom).SHA1.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA256] && !String.IsNullOrWhiteSpace(((Rom)rom).SHA256) ? " sha256=\"" + ((Rom)rom).SHA256.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA384] && !String.IsNullOrWhiteSpace(((Rom)rom).SHA384) ? " sha384=\"" + ((Rom)rom).SHA384.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.SHA512] && !String.IsNullOrWhiteSpace(((Rom)rom).SHA512) ? " sha512=\"" + ((Rom)rom).SHA512.ToLowerInvariant() + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.Date] && !String.IsNullOrWhiteSpace(((Rom)rom).Date) ? " date=\"" + ((Rom)rom).Date + "\"" : "")
|
||||
+ (!ExcludeFields[(int)Field.Status] && ((Rom)rom).ItemStatus != ItemStatus.None ? prefix + "/>\n" + prefix + "\t<flags>\n" +
|
||||
prefix + "\t\t<flag name=\"status\" value=\"" + ((Rom)rom).ItemStatus.ToString().ToLowerInvariant() + "\"/>\n" +
|
||||
prefix + "\t</flags>\n" +
|
||||
prefix + "</file>\n" : "/>\n");
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "rom");
|
||||
xtw.WriteAttributeString("name", rom.GetField(Field.Name, ExcludeFields));
|
||||
if (!ExcludeFields[(int)Field.Size] && rom.Size != -1)
|
||||
xtw.WriteAttributeString("size", rom.Size.ToString());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.CRC, ExcludeFields)))
|
||||
xtw.WriteAttributeString("crc", rom.CRC.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.MD5, ExcludeFields)))
|
||||
xtw.WriteAttributeString("md5", rom.MD5.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.RIPEMD160, ExcludeFields)))
|
||||
xtw.WriteAttributeString("ripemd160", rom.RIPEMD160.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA1, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha1", rom.SHA1.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA256, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha256", rom.SHA256.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA384, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha384", rom.SHA384.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.SHA512, ExcludeFields)))
|
||||
xtw.WriteAttributeString("sha512", rom.SHA512.ToLowerInvariant());
|
||||
if (!string.IsNullOrWhiteSpace(datItem.GetField(Field.Date, ExcludeFields)))
|
||||
xtw.WriteAttributeString("date", rom.Date);
|
||||
if (!ExcludeFields[(int)Field.Status] && rom.ItemStatus != ItemStatus.None)
|
||||
{
|
||||
xtw.WriteStartElement("flags");
|
||||
|
||||
xtw.WriteStartElement("flag");
|
||||
xtw.WriteAttributeString("name", "status");
|
||||
xtw.WriteAttributeString("value", rom.ItemStatus.ToString().ToLowerInvariant());
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End flags
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Sample:
|
||||
state += "<file type=\"sample\" name=\"" + (!ExcludeFields[(int)Field.Name] ? WebUtility.HtmlEncode(rom.Name) : "") + "\""
|
||||
+ "/>\n";
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "sample");
|
||||
xtw.WriteAttributeString("name", datItem.GetField(Field.Name, ExcludeFields));
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
sw.Write(state);
|
||||
sw.Flush();
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -906,28 +1008,26 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <summary>
|
||||
/// Write out DAT footer using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private bool WriteFooter(StreamWriter sw, int depth)
|
||||
private bool WriteFooter(XmlTextWriter xtw, int depth)
|
||||
{
|
||||
try
|
||||
{
|
||||
string footer = "";
|
||||
for (int i = depth - 1; i >= 2; i--)
|
||||
{
|
||||
// Print out the number of tabs and the end folder
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
footer += "\t";
|
||||
}
|
||||
footer += "</directory>\n";
|
||||
// End directory
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
footer += "\t</data>\n</datafile>\n";
|
||||
|
||||
// Write the footer out
|
||||
sw.Write(footer);
|
||||
sw.Flush();
|
||||
// End data
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End datafile
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user