2017-10-09 18:04:49 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
using System.IO;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
2018-01-15 10:47:19 -08:00
|
|
|
|
using System.Xml;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2017-10-09 18:04:49 -07:00
|
|
|
|
using SabreTools.Library.Data;
|
2017-11-02 15:44:15 -07:00
|
|
|
|
using SabreTools.Library.DatItems;
|
2020-08-01 23:04:11 -07:00
|
|
|
|
using SabreTools.Library.IO;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
using SabreTools.Library.Tools;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Library.DatFiles
|
|
|
|
|
|
{
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents parsing and writing of an SabreDat XML DAT
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class SabreDat : DatFile
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor designed for casting a base DatFile
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
|
|
|
|
|
public SabreDat(DatFile datFile)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
: base(datFile)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse an SabreDat XML DAT and return all found directories and files within
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
/// <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>
|
2020-08-28 15:06:07 -07:00
|
|
|
|
protected override void ParseFile(string filename, int indexId, bool keep)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// Prepare all internal variables
|
|
|
|
|
|
bool empty = true;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
string key;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
List<string> parent = new List<string>();
|
|
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we're ending a folder or game, take care of possibly empty games and removing from the parent
|
|
|
|
|
|
if (xtr.NodeType == XmlNodeType.EndElement && (xtr.Name == "directory" || xtr.Name == "dir"))
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we didn't find any items in the folder, make sure to add the blank rom
|
|
|
|
|
|
if (empty)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string tempgame = string.Join("\\", parent);
|
2020-07-15 09:41:59 -07:00
|
|
|
|
Rom rom = new Rom("null", tempgame);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Now process and add the rom
|
2020-07-15 09:41:59 -07:00
|
|
|
|
key = ParseAddHelper(rom);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Regardless, end the current folder
|
|
|
|
|
|
int parentcount = parent.Count;
|
|
|
|
|
|
if (parentcount == 0)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
Globals.Logger.Verbose($"Empty parent '{string.Join("\\", parent)}' found in '{filename}'");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
empty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have an end folder element, remove one item from the parent, if possible
|
|
|
|
|
|
if (parentcount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
parent.RemoveAt(parent.Count - 1);
|
|
|
|
|
|
if (keep && parentcount > 1)
|
2020-07-27 10:26:08 -07:00
|
|
|
|
Header.Type = (string.IsNullOrWhiteSpace(Header.Type) ? "SuperDAT" : Header.Type);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (xtr.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (xtr.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We want to process the entire subtree of the header
|
|
|
|
|
|
case "header":
|
|
|
|
|
|
ReadHeader(xtr.ReadSubtree(), keep);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the header node now that we've processed it
|
|
|
|
|
|
xtr.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "dir":
|
|
|
|
|
|
case "directory":
|
2020-07-15 09:41:59 -07:00
|
|
|
|
empty = ReadDirectory(xtr.ReadSubtree(), parent, filename, indexId, keep);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the directory node now that we've processed it
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
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 header information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader to use to parse the header</param>
|
|
|
|
|
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
|
|
|
|
|
private void ReadHeader(XmlReader reader, bool keep)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool superdat = false;
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element || reader.Name == "header")
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get all header items (ONLY OVERWRITE IF THERE'S NO DATA)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
string content;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "name":
|
|
|
|
|
|
content = reader.ReadElementContentAsString(); ;
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Name = (Header.Name== null ? content : Header.Name);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
superdat = superdat || content.Contains(" - SuperDAT");
|
|
|
|
|
|
if (keep && superdat)
|
|
|
|
|
|
{
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Type = (Header.Type == null ? "SuperDAT" : Header.Type);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "description":
|
|
|
|
|
|
content = reader.ReadElementContentAsString();
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Description = (Header.Description== null ? content : Header.Description);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "rootdir":
|
|
|
|
|
|
content = reader.ReadElementContentAsString();
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.RootDir = (Header.RootDir== null ? content : Header.RootDir);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "category":
|
|
|
|
|
|
content = reader.ReadElementContentAsString();
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Category = (Header.Category== null ? content : Header.Category);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "version":
|
|
|
|
|
|
content = reader.ReadElementContentAsString();
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Version = (Header.Version== null ? content : Header.Version);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "date":
|
|
|
|
|
|
content = reader.ReadElementContentAsString();
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Date = (Header.Date== null ? content.Replace(".", "/") : Header.Date);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "author":
|
|
|
|
|
|
content = reader.ReadElementContentAsString();
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Author = (Header.Author== null ? content : Header.Author);
|
|
|
|
|
|
Header.Email = (Header.Email == null ? reader.GetAttribute("email") : Header.Email);
|
|
|
|
|
|
Header.Homepage = (Header.Homepage == null ? reader.GetAttribute("homepage") : Header.Homepage);
|
|
|
|
|
|
Header.Url = (Header.Url == null ? reader.GetAttribute("url") : Header.Url);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "comment":
|
|
|
|
|
|
content = reader.ReadElementContentAsString();
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Comment = (Header.Comment== null ? content : Header.Comment);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "flags":
|
|
|
|
|
|
ReadFlags(reader.ReadSubtree(), superdat);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the flags node now that we've processed it
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read directory information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader to use to parse the header</param>
|
|
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
/// <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>
|
2020-09-01 13:36:32 -07:00
|
|
|
|
/// TODO: This is horrendeously out of date. Once all done promoting, try to make this like JSON
|
2020-08-28 15:06:07 -07:00
|
|
|
|
private bool ReadDirectory(
|
|
|
|
|
|
XmlReader reader,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
List<string> parent,
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Miscellaneous
|
2020-07-15 09:41:59 -07:00
|
|
|
|
bool keep)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// Prepare all internal variables
|
|
|
|
|
|
XmlReader flagreader;
|
|
|
|
|
|
bool empty = true;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string key = string.Empty, date = string.Empty;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
long size = -1;
|
|
|
|
|
|
ItemStatus its = ItemStatus.None;
|
|
|
|
|
|
|
|
|
|
|
|
// If there's no subtree to the header, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return empty;
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string foldername = (reader.GetAttribute("name") ?? string.Empty);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(foldername))
|
2019-01-11 13:43:15 -08:00
|
|
|
|
parent.Add(foldername);
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, read what we can from the directory
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we're ending a folder or game, take care of possibly empty games and removing from the parent
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.EndElement && (reader.Name == "directory" || reader.Name == "dir"))
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we didn't find any items in the folder, make sure to add the blank rom
|
|
|
|
|
|
if (empty)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string tempgame = string.Join("\\", parent);
|
2020-07-15 09:41:59 -07:00
|
|
|
|
Rom rom = new Rom("null", tempgame);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Now process and add the rom
|
2020-07-15 09:41:59 -07:00
|
|
|
|
key = ParseAddHelper(rom);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Regardless, end the current folder
|
|
|
|
|
|
int parentcount = parent.Count;
|
|
|
|
|
|
if (parentcount == 0)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
Globals.Logger.Verbose($"Empty parent '{string.Join("\\", parent)}' found in '{filename}'");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
empty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have an end folder element, remove one item from the parent, if possible
|
|
|
|
|
|
if (parentcount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
parent.RemoveAt(parent.Count - 1);
|
|
|
|
|
|
if (keep && parentcount > 1)
|
2020-07-27 10:26:08 -07:00
|
|
|
|
Header.Type = (string.IsNullOrWhiteSpace(Header.Type) ? "SuperDAT" : Header.Type);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get all directory items
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string content = string.Empty;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Directories can contain directories
|
|
|
|
|
|
case "dir":
|
|
|
|
|
|
case "directory":
|
2020-07-15 09:41:59 -07:00
|
|
|
|
ReadDirectory(reader.ReadSubtree(), parent, filename, indexId, keep);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the directory node now that we've processed it
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "file":
|
|
|
|
|
|
empty = false;
|
|
|
|
|
|
|
|
|
|
|
|
// If the rom is itemStatus, flag it
|
|
|
|
|
|
its = ItemStatus.None;
|
|
|
|
|
|
flagreader = reader.ReadSubtree();
|
|
|
|
|
|
|
|
|
|
|
|
// If the subtree is empty, skip it
|
|
|
|
|
|
if (flagreader == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (!flagreader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (flagreader.NodeType != XmlNodeType.Element || flagreader.Name == "flags")
|
|
|
|
|
|
{
|
|
|
|
|
|
flagreader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (flagreader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "flag":
|
|
|
|
|
|
if (flagreader.GetAttribute("name") != null && flagreader.GetAttribute("value") != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
content = flagreader.GetAttribute("value");
|
2020-07-15 09:41:59 -07:00
|
|
|
|
its = flagreader.GetAttribute("name").AsItemStatus();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
flagreader.Read();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the rom has a Date attached, read it in and then sanitize it
|
2020-07-15 09:41:59 -07:00
|
|
|
|
date = Sanitizer.CleanDate(reader.GetAttribute("date"));
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Take care of hex-sized files
|
2020-07-15 09:41:59 -07:00
|
|
|
|
size = Sanitizer.CleanSize(reader.GetAttribute("size"));
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
Machine dir = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
// Get the name of the game from the parent
|
|
|
|
|
|
Name = string.Join("\\", parent),
|
|
|
|
|
|
Description = string.Join("\\", parent),
|
|
|
|
|
|
};
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
DatItem datItem;
|
|
|
|
|
|
switch (reader.GetAttribute("type").ToLowerInvariant())
|
|
|
|
|
|
{
|
2020-09-01 13:36:32 -07:00
|
|
|
|
case "adjuster":
|
|
|
|
|
|
datItem = new Adjuster
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Default = reader.GetAttribute("default").AsYesNo(),
|
2020-09-01 16:21:55 -07:00
|
|
|
|
Conditions = new List<Condition>(),
|
2020-09-01 13:36:32 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Now read the internal tags
|
|
|
|
|
|
ReadAdjuster(reader.ReadSubtree(), datItem);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the adjuster now that we've processed it
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "archive":
|
|
|
|
|
|
datItem = new Archive
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "biosset":
|
|
|
|
|
|
datItem = new BiosSet
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Description = reader.GetAttribute("description"),
|
2020-07-15 09:41:59 -07:00
|
|
|
|
Default = reader.GetAttribute("default").AsYesNo(),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-25 22:48:46 -07:00
|
|
|
|
case "chip":
|
|
|
|
|
|
datItem = new Chip
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Tag = reader.GetAttribute("tag"),
|
2020-09-02 14:32:16 -07:00
|
|
|
|
ChipType = reader.GetAttribute("chiptype").AsChipType(),
|
2020-08-25 22:48:46 -07:00
|
|
|
|
Clock = reader.GetAttribute("clock"),
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
case "configuration":
|
|
|
|
|
|
datItem = new Configuration
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Tag = reader.GetAttribute("tag"),
|
|
|
|
|
|
Mask = reader.GetAttribute("mask"),
|
2020-09-01 16:21:55 -07:00
|
|
|
|
Conditions = new List<Condition>(),
|
|
|
|
|
|
Locations = new List<Location>(),
|
|
|
|
|
|
Settings = new List<Setting>(),
|
2020-09-01 13:36:32 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Now read the internal tags
|
|
|
|
|
|
ReadConfiguration(reader.ReadSubtree(), datItem);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the configuration now that we've processed it
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "device_ref":
|
|
|
|
|
|
datItem = new DeviceReference
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "dipswitch":
|
|
|
|
|
|
datItem = new DipSwitch
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Tag = reader.GetAttribute("tag"),
|
|
|
|
|
|
Mask = reader.GetAttribute("mask"),
|
2020-09-01 16:21:55 -07:00
|
|
|
|
Conditions = new List<Condition>(),
|
|
|
|
|
|
Locations = new List<Location>(),
|
|
|
|
|
|
Values = new List<Setting>(),
|
2020-09-01 13:36:32 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Now read the internal tags
|
|
|
|
|
|
ReadDipSwitch(reader.ReadSubtree(), datItem);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the dipswitch now that we've processed it
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "disk":
|
|
|
|
|
|
datItem = new Disk
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
2020-07-15 09:41:59 -07:00
|
|
|
|
MD5 = reader.GetAttribute("md5"),
|
|
|
|
|
|
SHA1 = reader.GetAttribute("sha1"),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
ItemStatus = its,
|
|
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-27 16:57:22 -07:00
|
|
|
|
case "media":
|
|
|
|
|
|
datItem = new Media
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
MD5 = reader.GetAttribute("md5"),
|
|
|
|
|
|
SHA1 = reader.GetAttribute("sha1"),
|
|
|
|
|
|
SHA256 = reader.GetAttribute("sha256"),
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "release":
|
|
|
|
|
|
datItem = new Release
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Region = reader.GetAttribute("region"),
|
|
|
|
|
|
Language = reader.GetAttribute("language"),
|
|
|
|
|
|
Date = reader.GetAttribute("date"),
|
2020-07-15 09:41:59 -07:00
|
|
|
|
Default = reader.GetAttribute("default").AsYesNo(),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "rom":
|
|
|
|
|
|
datItem = new Rom
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Size = size,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
CRC = reader.GetAttribute("crc"),
|
|
|
|
|
|
MD5 = reader.GetAttribute("md5"),
|
|
|
|
|
|
#if NET_FRAMEWORK
|
|
|
|
|
|
RIPEMD160 = reader.GetAttribute("ripemd160"),
|
|
|
|
|
|
#endif
|
|
|
|
|
|
SHA1 = reader.GetAttribute("sha1"),
|
|
|
|
|
|
SHA256 = reader.GetAttribute("sha256"),
|
|
|
|
|
|
SHA384 = reader.GetAttribute("sha384"),
|
|
|
|
|
|
SHA512 = reader.GetAttribute("sha512"),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
ItemStatus = its,
|
|
|
|
|
|
Date = date,
|
|
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "sample":
|
|
|
|
|
|
datItem = new Sample
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
// By default, create a new Blank, just in case
|
|
|
|
|
|
datItem = new Blank();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
datItem?.CopyMachineInformation(dir);
|
|
|
|
|
|
|
|
|
|
|
|
// Now process and add the rom
|
2020-07-15 09:41:59 -07:00
|
|
|
|
key = ParseAddHelper(datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read flags information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader to use to parse the header</param>
|
|
|
|
|
|
/// <param name="superdat">True if superdat has already been set externally, false otherwise</param>
|
|
|
|
|
|
private void ReadFlags(XmlReader reader, bool superdat)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Prepare all internal variables
|
2020-07-15 09:41:59 -07:00
|
|
|
|
string content;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we somehow have a null flag section, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element || reader.Name == "flags")
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "flag":
|
|
|
|
|
|
if (reader.GetAttribute("name") != null && reader.GetAttribute("value") != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
content = reader.GetAttribute("value");
|
|
|
|
|
|
switch (reader.GetAttribute("name").ToLowerInvariant())
|
|
|
|
|
|
{
|
|
|
|
|
|
case "type":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Type = (Header.Type == null ? content : Header.Type);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
superdat = superdat || content.Contains("SuperDAT");
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "forcemerging":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForceMerging == MergingFlag.None)
|
|
|
|
|
|
Header.ForceMerging = content.AsMergingFlag();
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "forcenodump":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForceNodump == NodumpFlag.None)
|
|
|
|
|
|
Header.ForceNodump = content.AsNodumpFlag();
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "forcepacking":
|
2020-08-20 20:38:29 -07:00
|
|
|
|
if (Header.ForcePacking == PackingFlag.None)
|
|
|
|
|
|
Header.ForcePacking = content.AsPackingFlag();
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read Adjuster information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a diskarea block</param>
|
|
|
|
|
|
/// <param name="adjuster">Adjuster to populate</param>
|
|
|
|
|
|
private void ReadAdjuster(XmlReader reader, DatItem adjuster)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we have an empty port, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// If the DatItem isn't an Adjuster, skip it
|
|
|
|
|
|
if (adjuster.ItemType != ItemType.Adjuster)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Get list ready
|
2020-09-01 16:21:55 -07:00
|
|
|
|
(adjuster as Adjuster).Conditions = new List<Condition>();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the information from the adjuster
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "condition":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var condition = new Condition();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
condition.Tag = reader.GetAttribute("tag");
|
|
|
|
|
|
condition.Mask = reader.GetAttribute("mask");
|
|
|
|
|
|
condition.Relation = reader.GetAttribute("relation");
|
|
|
|
|
|
condition.Value = reader.GetAttribute("value");
|
|
|
|
|
|
|
|
|
|
|
|
(adjuster as Adjuster).Conditions.Add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read Configuration information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a diskarea block</param>
|
|
|
|
|
|
/// <param name="configuration">Configuration to populate</param>
|
|
|
|
|
|
private void ReadConfiguration(XmlReader reader, DatItem configuration)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we have an empty configuration, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// If the DatItem isn't an Configuration, skip it
|
|
|
|
|
|
if (configuration.ItemType != ItemType.Configuration)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Get lists ready
|
2020-09-01 16:21:55 -07:00
|
|
|
|
(configuration as Configuration).Conditions = new List<Condition>();
|
|
|
|
|
|
(configuration as Configuration).Locations = new List<Location>();
|
|
|
|
|
|
(configuration as Configuration).Settings = new List<Setting>();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the information from the dipswitch
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "condition":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var condition = new Condition();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
condition.Tag = reader.GetAttribute("tag");
|
|
|
|
|
|
condition.Mask = reader.GetAttribute("mask");
|
|
|
|
|
|
condition.Relation = reader.GetAttribute("relation");
|
|
|
|
|
|
condition.Value = reader.GetAttribute("value");
|
|
|
|
|
|
|
|
|
|
|
|
(configuration as Configuration).Conditions.Add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "conflocation":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var confLocation = new Location();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
confLocation.Name = reader.GetAttribute("name");
|
|
|
|
|
|
confLocation.Number = reader.GetAttribute("number");
|
|
|
|
|
|
confLocation.Inverted = reader.GetAttribute("inverted").AsYesNo();
|
|
|
|
|
|
|
|
|
|
|
|
(configuration as Configuration).Locations.Add(confLocation);
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "confsetting":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var confSetting = new Setting();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
confSetting.Name = reader.GetAttribute("name");
|
|
|
|
|
|
confSetting.Value = reader.GetAttribute("value");
|
|
|
|
|
|
confSetting.Default = reader.GetAttribute("default").AsYesNo();
|
|
|
|
|
|
|
|
|
|
|
|
// Now read the internal tags
|
|
|
|
|
|
ReadConfSetting(reader, confSetting);
|
|
|
|
|
|
|
|
|
|
|
|
(configuration as Configuration).Settings.Add(confSetting);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the dipvalue now that we've processed it
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read ConfSetting information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a diskarea block</param>
|
|
|
|
|
|
/// <param name="confSetting">ListXmlConfSetting to populate</param>
|
2020-09-01 16:21:55 -07:00
|
|
|
|
private void ReadConfSetting(XmlReader reader, Setting confSetting)
|
2020-09-01 13:36:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
// If we have an empty confsetting, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Get list ready
|
2020-09-01 16:21:55 -07:00
|
|
|
|
confSetting.Conditions = new List<Condition>();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the information from the confsetting
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "condition":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var condition = new Condition();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
condition.Tag = reader.GetAttribute("tag");
|
|
|
|
|
|
condition.Mask = reader.GetAttribute("mask");
|
|
|
|
|
|
condition.Relation = reader.GetAttribute("relation");
|
|
|
|
|
|
condition.Value = reader.GetAttribute("value");
|
|
|
|
|
|
|
|
|
|
|
|
confSetting.Conditions.Add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read DipSwitch information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a diskarea block</param>
|
|
|
|
|
|
/// <param name="dipSwitch">DipSwitch to populate</param>
|
|
|
|
|
|
private void ReadDipSwitch(XmlReader reader, DatItem dipSwitch)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we have an empty dipswitch, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// If the DatItem isn't an DipSwitch, skip it
|
|
|
|
|
|
if (dipSwitch.ItemType != ItemType.DipSwitch)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Get lists ready
|
2020-09-01 16:21:55 -07:00
|
|
|
|
(dipSwitch as DipSwitch).Conditions = new List<Condition>();
|
|
|
|
|
|
(dipSwitch as DipSwitch).Locations = new List<Location>();
|
|
|
|
|
|
(dipSwitch as DipSwitch).Values = new List<Setting>();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the information from the dipswitch
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "condition":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var condition = new Condition();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
condition.Tag = reader.GetAttribute("tag");
|
|
|
|
|
|
condition.Mask = reader.GetAttribute("mask");
|
|
|
|
|
|
condition.Relation = reader.GetAttribute("relation");
|
|
|
|
|
|
condition.Value = reader.GetAttribute("value");
|
|
|
|
|
|
|
|
|
|
|
|
(dipSwitch as DipSwitch).Conditions.Add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "diplocation":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var dipLocation = new Location();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
dipLocation.Name = reader.GetAttribute("name");
|
|
|
|
|
|
dipLocation.Number = reader.GetAttribute("number");
|
|
|
|
|
|
dipLocation.Inverted = reader.GetAttribute("inverted").AsYesNo();
|
|
|
|
|
|
|
|
|
|
|
|
(dipSwitch as DipSwitch).Locations.Add(dipLocation);
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "dipvalue":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var dipValue = new Setting();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
dipValue.Name = reader.GetAttribute("name");
|
|
|
|
|
|
dipValue.Value = reader.GetAttribute("value");
|
|
|
|
|
|
dipValue.Default = reader.GetAttribute("default").AsYesNo();
|
|
|
|
|
|
|
|
|
|
|
|
// Now read the internal tags
|
|
|
|
|
|
ReadDipValue(reader, dipValue);
|
|
|
|
|
|
|
|
|
|
|
|
(dipSwitch as DipSwitch).Values.Add(dipValue);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the dipvalue now that we've processed it
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read DipValue information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a diskarea block</param>
|
2020-09-01 16:21:55 -07:00
|
|
|
|
/// <param name="dipValue">Setting to populate</param>
|
|
|
|
|
|
private void ReadDipValue(XmlReader reader, Setting dipValue)
|
2020-09-01 13:36:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
// If we have an empty dipvalue, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Get list ready
|
2020-09-01 16:21:55 -07:00
|
|
|
|
dipValue.Conditions = new List<Condition>();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the information from the dipvalue
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "condition":
|
2020-09-01 16:21:55 -07:00
|
|
|
|
var condition = new Condition();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
condition.Tag = reader.GetAttribute("tag");
|
|
|
|
|
|
condition.Mask = reader.GetAttribute("mask");
|
|
|
|
|
|
condition.Relation = reader.GetAttribute("relation");
|
|
|
|
|
|
condition.Value = reader.GetAttribute("value");
|
|
|
|
|
|
|
|
|
|
|
|
dipValue.Conditions.Add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
/// TODO: Fix writing out files that have a path in the name
|
|
|
|
|
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
Globals.Logger.User($"Opening file for writing: {outfile}");
|
2020-07-15 09:41:59 -07:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
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
|
2020-06-10 22:37:19 -07:00
|
|
|
|
WriteHeader(xtw);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Write out each of the machines and roms
|
|
|
|
|
|
int depth = 2, last = -1;
|
|
|
|
|
|
string lastgame = null;
|
|
|
|
|
|
List<string> splitpath = new List<string>();
|
|
|
|
|
|
|
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-08-28 15:06:07 -07:00
|
|
|
|
List<DatItem> datItems = Items.FilteredItems(key);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Resolve the names in the block
|
2020-08-28 15:06:07 -07:00
|
|
|
|
datItems = DatItem.ResolveNames(datItems);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
for (int index = 0; index < datItems.Count; index++)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-28 15:06:07 -07:00
|
|
|
|
DatItem datItem = datItems[index];
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
List<string> newsplit = datItem.Machine.Name.Split('\\').ToList();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we have a different game and we're not at the start of the list, output the end of last item
|
2020-08-28 15:06:07 -07:00
|
|
|
|
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
2020-06-10 22:37:19 -07:00
|
|
|
|
depth = WriteEndGame(xtw, splitpath, newsplit, depth, out last);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we have a new game, output the beginning of the new item
|
2020-08-28 15:06:07 -07:00
|
|
|
|
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
|
|
|
|
|
depth = WriteStartGame(xtw, datItem, newsplit, depth, last);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
// Check for a "null" item
|
|
|
|
|
|
datItem = ProcessNullifiedItem(datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
// Write out the item if we're not ignoring
|
|
|
|
|
|
if (!ShouldIgnore(datItem, ignoreblanks))
|
|
|
|
|
|
WriteDatItem(xtw, datItem, depth);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Set the new data to compare against
|
|
|
|
|
|
splitpath = newsplit;
|
2020-08-28 15:06:07 -07:00
|
|
|
|
lastgame = datItem.Machine.Name;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write the file footer out
|
2020-06-10 22:37:19 -07:00
|
|
|
|
WriteFooter(xtw, depth);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
Globals.Logger.Verbose("File written!" + Environment.NewLine);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
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>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <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>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private bool WriteHeader(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteStartDocument();
|
|
|
|
|
|
xtw.WriteDocType("sabredat", null, "newdat.xsd", null);
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("datafile");
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("header");
|
|
|
|
|
|
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredElementString("name", Header.Name);
|
|
|
|
|
|
xtw.WriteRequiredElementString("description", Header.Description);
|
2020-08-24 00:25:23 -07:00
|
|
|
|
xtw.WriteOptionalElementString("rootdir", Header.RootDir);
|
|
|
|
|
|
xtw.WriteOptionalElementString("category", Header.Category);
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredElementString("version", Header.Version);
|
2020-08-24 00:25:23 -07:00
|
|
|
|
xtw.WriteOptionalElementString("date", Header.Date);
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredElementString("author", Header.Author);
|
2020-08-24 00:25:23 -07:00
|
|
|
|
xtw.WriteOptionalElementString("comment", Header.Comment);
|
2020-07-27 10:26:08 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(Header.Type)
|
2020-08-20 20:38:29 -07:00
|
|
|
|
|| Header.ForcePacking != PackingFlag.None
|
|
|
|
|
|
|| Header.ForceMerging != MergingFlag.None
|
|
|
|
|
|
|| Header.ForceNodump != NodumpFlag.None)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("flags");
|
|
|
|
|
|
|
2020-07-27 10:26:08 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(Header.Type))
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("flag");
|
|
|
|
|
|
xtw.WriteAttributeString("name", "type");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("value", Header.Type);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2020-08-24 13:21:59 -07:00
|
|
|
|
if (Header.ForcePacking != PackingFlag.None)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteStartElement("flag");
|
|
|
|
|
|
xtw.WriteAttributeString("name", "forcepacking");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", Header.ForcePacking.FromPackingFlag(false));
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2020-08-24 13:21:59 -07:00
|
|
|
|
if (Header.ForceMerging != MergingFlag.None)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteStartElement("flag");
|
|
|
|
|
|
xtw.WriteAttributeString("name", "forcemerging");
|
|
|
|
|
|
xtw.WriteAttributeString("value", Header.ForceMerging.FromMergingFlag(false));
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2020-08-24 13:21:59 -07:00
|
|
|
|
if (Header.ForceNodump != NodumpFlag.None)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteStartElement("flag");
|
|
|
|
|
|
xtw.WriteAttributeString("name", "forcenodump");
|
|
|
|
|
|
xtw.WriteAttributeString("value", Header.ForceNodump.FromNodumpFlag());
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// End flags
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// End header
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("data");
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <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="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>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
private int WriteStartGame(XmlTextWriter xtw, DatItem datItem, List<string> newsplit, int depth, int last)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// No game should start with a path separator
|
2020-08-23 22:23:55 -07:00
|
|
|
|
datItem.Machine.Name = datItem.Machine.Name?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-23 22:23:55 -07:00
|
|
|
|
// Build the state
|
2019-01-11 13:43:15 -08:00
|
|
|
|
for (int i = (last == -1 ? 0 : last); i < newsplit.Count; i++)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteStartElement("directory");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", newsplit[i]);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("description", newsplit[i]);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
depth = depth - (last == -1 ? 0 : last) + newsplit.Count;
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return depth;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return depth;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out Game start using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <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>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private int WriteEndGame(XmlTextWriter xtw, List<string> splitpath, List<string> newsplit, int depth, out int last)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
last = 0;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (splitpath != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < newsplit.Count && i < splitpath.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Always keep track of the last seen item
|
|
|
|
|
|
last = i;
|
|
|
|
|
|
|
|
|
|
|
|
// 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--)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
// End directory
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reset the current depth
|
|
|
|
|
|
depth = 2 + last;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return depth;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return depth;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DatItem using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <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="depth">Current depth to output file at (SabreDAT only)</param>
|
|
|
|
|
|
/// <returns>True if the data was written, false on error</returns>
|
2020-08-28 15:06:07 -07:00
|
|
|
|
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, int depth)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// Pre-process the item name
|
2020-06-10 22:37:19 -07:00
|
|
|
|
ProcessItemName(datItem, true);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-23 22:23:55 -07:00
|
|
|
|
// Build the state
|
2020-06-10 22:37:19 -07:00
|
|
|
|
switch (datItem.ItemType)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-01 11:34:52 -07:00
|
|
|
|
case ItemType.Adjuster:
|
|
|
|
|
|
var adjuster = datItem as Adjuster;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "adjuster");
|
2020-09-02 12:32:10 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", adjuster.Name);
|
2020-09-01 11:34:52 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("default", adjuster.Default.FromYesNo());
|
|
|
|
|
|
if (adjuster.Conditions != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var condition in adjuster.Conditions)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("condition");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("tag", condition.Tag);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("mask", condition.Mask);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("relation", condition.Relation);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", condition.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case ItemType.Archive:
|
2020-09-02 12:32:10 -07:00
|
|
|
|
var archive = datItem as Archive;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "archive");
|
2020-09-02 12:32:10 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", archive.Name);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case ItemType.BiosSet:
|
2020-06-10 22:37:19 -07:00
|
|
|
|
var biosSet = datItem as BiosSet;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "biosset");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", biosSet.Name);
|
2020-08-23 22:54:09 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("description", biosSet.Description);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("default", biosSet.Default.FromYesNo());
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-25 22:48:46 -07:00
|
|
|
|
case ItemType.Chip:
|
|
|
|
|
|
var chip = datItem as Chip;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "chip");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", chip.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("tag", chip.Tag);
|
2020-09-02 14:32:16 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("chiptype", chip.ChipType.FromChipType());
|
2020-08-25 22:48:46 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("clock", chip.Clock);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-09-01 12:04:35 -07:00
|
|
|
|
case ItemType.Configuration:
|
|
|
|
|
|
var configuration = datItem as Configuration;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "configuration");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", configuration.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("tag", configuration.Tag);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("mask", configuration.Mask);
|
|
|
|
|
|
|
|
|
|
|
|
if (configuration.Conditions != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var condition in configuration.Conditions)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("condition");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("tag", condition.Tag);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("mask", condition.Mask);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("relation", condition.Relation);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", condition.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (configuration.Locations != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var location in configuration.Locations)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("conflocation");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", location.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("number", location.Number);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("inverted", location.Inverted.FromYesNo());
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (configuration.Settings != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var setting in configuration.Settings)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("confsetting");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", setting.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", setting.Value);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("default", setting.Default.FromYesNo());
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-08-31 23:01:51 -07:00
|
|
|
|
case ItemType.DeviceReference:
|
2020-09-02 12:32:10 -07:00
|
|
|
|
var deviceRef = datItem as DeviceReference;
|
2020-08-31 23:01:51 -07:00
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "device_ref");
|
2020-09-02 12:32:10 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", deviceRef.Name);
|
2020-08-31 23:01:51 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
case ItemType.DipSwitch:
|
|
|
|
|
|
var dipSwitch = datItem as DipSwitch;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "dipswitch");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", dipSwitch.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("tag", dipSwitch.Tag);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("mask", dipSwitch.Mask);
|
|
|
|
|
|
if (dipSwitch.Conditions != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var condition in dipSwitch.Conditions)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("condition");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("tag", condition.Tag);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("mask", condition.Mask);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("relation", condition.Relation);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", condition.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (dipSwitch.Locations != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var location in dipSwitch.Locations)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("diplocation");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", location.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("number", location.Number);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("inverted", location.Inverted.FromYesNo());
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (dipSwitch.Values != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var value in dipSwitch.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("dipvalue");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", value.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", value.Value);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("default", value.Default.FromYesNo());
|
|
|
|
|
|
if (value.Conditions != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var condition in value.Conditions)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("condition");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("tag", condition.Tag);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("mask", condition.Mask);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("relation", condition.Relation);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", condition.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case ItemType.Disk:
|
2020-06-10 22:37:19 -07:00
|
|
|
|
var disk = datItem as Disk;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "disk");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", disk.Name);
|
2020-08-24 11:56:49 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant());
|
2020-08-23 22:23:55 -07:00
|
|
|
|
if (disk.ItemStatus != ItemStatus.None)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("flags");
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("flag");
|
|
|
|
|
|
xtw.WriteAttributeString("name", "status");
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteAttributeString("value", disk.ItemStatus.FromItemStatus(false));
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End flags
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-08-27 16:57:22 -07:00
|
|
|
|
|
2020-09-02 13:31:50 -07:00
|
|
|
|
case ItemType.Feature:
|
|
|
|
|
|
var feature = datItem as Feature;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "feature");
|
2020-09-02 14:04:02 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("type", feature.Type.FromFeatureType());
|
2020-09-02 14:32:16 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("status", feature.Status.FromEmulationStatus());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("overall", feature.Overall.FromEmulationStatus());
|
2020-09-02 13:31:50 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-08-27 16:57:22 -07:00
|
|
|
|
case ItemType.Media:
|
|
|
|
|
|
var media = datItem as Media;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "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.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-01 11:34:52 -07:00
|
|
|
|
case ItemType.RamOption:
|
|
|
|
|
|
var ramOption = datItem as RamOption;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "ramoption");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", ramOption.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("default", ramOption.Default.FromYesNo());
|
|
|
|
|
|
xtw.WriteRaw(ramOption.Content ?? string.Empty);
|
|
|
|
|
|
xtw.WriteFullEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case ItemType.Release:
|
2020-06-10 22:37:19 -07:00
|
|
|
|
var release = datItem as Release;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "release");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", release.Name);
|
2020-08-23 22:54:09 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("region", release.Region);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("language", release.Language);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("date", release.Date);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("default", release.Default.FromYesNo());
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case ItemType.Rom:
|
2020-06-10 22:37:19 -07:00
|
|
|
|
var rom = datItem as Rom;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "rom");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", rom.Name);
|
2020-08-23 22:54:09 -07:00
|
|
|
|
if (rom.Size != -1) xtw.WriteAttributeString("size", rom.Size.ToString());
|
2020-08-24 11:56:49 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#if NET_FRAMEWORK
|
2020-08-24 11:56:49 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("ripemd160", rom.RIPEMD160?.ToLowerInvariant());
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#endif
|
2020-08-24 11:56:49 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("sha1", rom.SHA1?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha256", rom.SHA256?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha384", rom.SHA384?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant());
|
2020-08-23 22:54:09 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("date", rom.Date);
|
2020-08-23 22:23:55 -07:00
|
|
|
|
if (rom.ItemStatus != ItemStatus.None)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("flags");
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("flag");
|
|
|
|
|
|
xtw.WriteAttributeString("name", "status");
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteAttributeString("value", rom.ItemStatus.FromItemStatus(false));
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End flags
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case ItemType.Sample:
|
2020-09-02 12:32:10 -07:00
|
|
|
|
var sample = datItem as Sample;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "sample");
|
2020-09-02 12:32:10 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", sample.Name);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-08-31 23:26:07 -07:00
|
|
|
|
|
2020-09-01 16:21:55 -07:00
|
|
|
|
case ItemType.Slot:
|
|
|
|
|
|
var slot = datItem as Slot;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "slot");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", slot.Name);
|
|
|
|
|
|
if (slot.SlotOptions != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var slotOption in slot.SlotOptions)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("slotoption");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("name", slotOption.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("devname", slotOption.DeviceName);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("default", slotOption.Default.FromYesNo());
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2020-08-31 23:26:07 -07:00
|
|
|
|
case ItemType.SoftwareList:
|
|
|
|
|
|
var softwareList = datItem as DatItems.SoftwareList;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "softwarelist");
|
2020-09-02 12:32:10 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("name", softwareList.Name);
|
2020-08-31 23:26:07 -07:00
|
|
|
|
xtw.WriteOptionalAttributeString("status", softwareList.Status.FromSoftwareListStatus());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha512", softwareList.Filter);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-09-02 12:51:21 -07:00
|
|
|
|
|
|
|
|
|
|
case ItemType.Sound:
|
|
|
|
|
|
var sound = datItem as Sound;
|
|
|
|
|
|
xtw.WriteStartElement("file");
|
|
|
|
|
|
xtw.WriteAttributeString("type", "sound");
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("channels", sound.Channels);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07: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 DAT footer using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
|
|
|
|
|
/// <returns>True if the data was written, false on error</returns>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private bool WriteFooter(XmlTextWriter xtw, int depth)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = depth - 1; i >= 2; i--)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
// End directory
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
// End data
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End datafile
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-09 18:04:49 -07:00
|
|
|
|
}
|