mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Promote DipSwitch
This commit is contained in:
@@ -113,6 +113,12 @@ namespace SabreTools.Library.DatFiles
|
||||
[JsonIgnore]
|
||||
public long DeviceReferenceCount { get; private set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Number of DIP Switch items
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public long DipSwitchCount { get; private set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Number of Disk items
|
||||
/// </summary>
|
||||
@@ -500,6 +506,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.DeviceReference:
|
||||
DeviceReferenceCount++;
|
||||
break;
|
||||
case ItemType.DipSwitch:
|
||||
DipSwitchCount++;
|
||||
break;
|
||||
case ItemType.Disk:
|
||||
DiskCount++;
|
||||
if ((item as Disk).ItemStatus != ItemStatus.Nodump)
|
||||
@@ -644,6 +653,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.DeviceReference:
|
||||
DeviceReferenceCount--;
|
||||
break;
|
||||
case ItemType.DipSwitch:
|
||||
DipSwitchCount--;
|
||||
break;
|
||||
case ItemType.Disk:
|
||||
DiskCount--;
|
||||
if ((item as Disk).ItemStatus != ItemStatus.Nodump)
|
||||
|
||||
@@ -229,6 +229,9 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.DeviceReference:
|
||||
datItem = datItemObj.ToObject<DeviceReference>();
|
||||
break;
|
||||
case ItemType.DipSwitch:
|
||||
datItem = datItemObj.ToObject<DipSwitch>();
|
||||
break;
|
||||
case ItemType.Disk:
|
||||
datItem = datItemObj.ToObject<Disk>();
|
||||
break;
|
||||
|
||||
@@ -247,6 +247,24 @@ namespace SabreTools.Library.DatFiles
|
||||
reader.Read();
|
||||
break;
|
||||
|
||||
case "dipswitch":
|
||||
var dipSwitch = new DipSwitch
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Tag = reader.GetAttribute("tag"),
|
||||
Mask = reader.GetAttribute("mask"),
|
||||
Conditions = new List<ListXmlCondition>(),
|
||||
Locations = new List<ListXmlDipLocation>(),
|
||||
Values = new List<ListXmlDipValue>(),
|
||||
};
|
||||
|
||||
// Now read the internal tags
|
||||
ReadDipSwitch(reader.ReadSubtree(), dipSwitch);
|
||||
|
||||
// Skip the dipswitch now that we've processed it
|
||||
reader.Skip();
|
||||
break;
|
||||
|
||||
case "disk":
|
||||
datItems.Add(new Disk
|
||||
{
|
||||
@@ -411,25 +429,6 @@ namespace SabreTools.Library.DatFiles
|
||||
reader.Skip();
|
||||
break;
|
||||
|
||||
case "dipswitch":
|
||||
var dipSwitch = new ListXmlDipSwitch();
|
||||
dipSwitch.Name = reader.GetAttribute("name");
|
||||
dipSwitch.Tag = reader.GetAttribute("tag");
|
||||
dipSwitch.Mask = reader.GetAttribute("mask");
|
||||
|
||||
// Now read the internal tags
|
||||
ReadDipSwitch(reader.ReadSubtree(), dipSwitch);
|
||||
|
||||
// Ensure the list exists
|
||||
if (machine.DipSwitches == null)
|
||||
machine.DipSwitches = new List<ListXmlDipSwitch>();
|
||||
|
||||
machine.DipSwitches.Add(dipSwitch);
|
||||
|
||||
// Skip the dipswitch now that we've processed it
|
||||
reader.Skip();
|
||||
break;
|
||||
|
||||
case "port":
|
||||
var port = new ListXmlPort();
|
||||
port.Tag = reader.GetAttribute("tag");
|
||||
@@ -658,8 +657,8 @@ namespace SabreTools.Library.DatFiles
|
||||
/// Read DipSwitch information
|
||||
/// </summary>
|
||||
/// <param name="reader">XmlReader representing a diskarea block</param>
|
||||
/// <param name="dipSwitch">ListXmlDipSwitch to populate</param>
|
||||
private void ReadDipSwitch(XmlReader reader, ListXmlDipSwitch dipSwitch)
|
||||
/// <param name="dipSwitch">DipSwitch to populate</param>
|
||||
private void ReadDipSwitch(XmlReader reader, DipSwitch dipSwitch)
|
||||
{
|
||||
// If we have an empty dipswitch, skip it
|
||||
if (reader == null)
|
||||
@@ -1289,80 +1288,6 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
if (datItem.Machine.DipSwitches != null)
|
||||
{
|
||||
foreach (var dipSwitch in datItem.Machine.DipSwitches)
|
||||
{
|
||||
xtw.WriteStartElement("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);
|
||||
|
||||
// End condition
|
||||
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());
|
||||
|
||||
// End diplocation
|
||||
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);
|
||||
|
||||
// End condition
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
// End dipvalue
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
// End dipswitch
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
if (datItem.Machine.Ports != null)
|
||||
{
|
||||
foreach (var port in datItem.Machine.Ports)
|
||||
@@ -1626,6 +1551,61 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.DipSwitch:
|
||||
var dipSwitch = datItem as DipSwitch;
|
||||
xtw.WriteStartElement("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;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("disk");
|
||||
|
||||
@@ -218,6 +218,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="indexId">Index ID for the DAT</param>
|
||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||
/// TODO: This is horrendeously out of date. Once all done promoting, try to make this like JSON
|
||||
private bool ReadDirectory(
|
||||
XmlReader reader,
|
||||
List<string> parent,
|
||||
@@ -350,6 +351,21 @@ namespace SabreTools.Library.DatFiles
|
||||
DatItem datItem;
|
||||
switch (reader.GetAttribute("type").ToLowerInvariant())
|
||||
{
|
||||
case "adjuster":
|
||||
datItem = new Adjuster
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Default = reader.GetAttribute("default").AsYesNo(),
|
||||
Conditions = new List<ListXmlCondition>(),
|
||||
};
|
||||
|
||||
// Now read the internal tags
|
||||
ReadAdjuster(reader.ReadSubtree(), datItem);
|
||||
|
||||
// Skip the adjuster now that we've processed it
|
||||
reader.Skip();
|
||||
break;
|
||||
|
||||
case "archive":
|
||||
datItem = new Archive
|
||||
{
|
||||
@@ -394,6 +410,51 @@ namespace SabreTools.Library.DatFiles
|
||||
};
|
||||
break;
|
||||
|
||||
case "configuration":
|
||||
datItem = new Configuration
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Tag = reader.GetAttribute("tag"),
|
||||
Mask = reader.GetAttribute("mask"),
|
||||
Conditions = new List<ListXmlCondition>(),
|
||||
Locations = new List<ListXmlConfLocation>(),
|
||||
Settings = new List<ListXmlConfSetting>(),
|
||||
};
|
||||
|
||||
// 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"),
|
||||
Conditions = new List<ListXmlCondition>(),
|
||||
Locations = new List<ListXmlDipLocation>(),
|
||||
Values = new List<ListXmlDipValue>(),
|
||||
};
|
||||
|
||||
// Now read the internal tags
|
||||
ReadDipSwitch(reader.ReadSubtree(), datItem);
|
||||
|
||||
// Skip the dipswitch now that we've processed it
|
||||
reader.Skip();
|
||||
break;
|
||||
|
||||
case "disk":
|
||||
datItem = new Disk
|
||||
{
|
||||
@@ -566,6 +627,314 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <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
|
||||
(adjuster as Adjuster).Conditions = new List<ListXmlCondition>();
|
||||
|
||||
// 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":
|
||||
var condition = new ListXmlCondition();
|
||||
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
|
||||
(configuration as Configuration).Conditions = new List<ListXmlCondition>();
|
||||
(configuration as Configuration).Locations = new List<ListXmlConfLocation>();
|
||||
(configuration as Configuration).Settings = new List<ListXmlConfSetting>();
|
||||
|
||||
// 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":
|
||||
var condition = new ListXmlCondition();
|
||||
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":
|
||||
var confLocation = new ListXmlConfLocation();
|
||||
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":
|
||||
var confSetting = new ListXmlConfSetting();
|
||||
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>
|
||||
private void ReadConfSetting(XmlReader reader, ListXmlConfSetting confSetting)
|
||||
{
|
||||
// If we have an empty confsetting, skip it
|
||||
if (reader == null)
|
||||
return;
|
||||
|
||||
// Get list ready
|
||||
confSetting.Conditions = new List<ListXmlCondition>();
|
||||
|
||||
// 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":
|
||||
var condition = new ListXmlCondition();
|
||||
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
|
||||
(dipSwitch as DipSwitch).Conditions = new List<ListXmlCondition>();
|
||||
(dipSwitch as DipSwitch).Locations = new List<ListXmlDipLocation>();
|
||||
(dipSwitch as DipSwitch).Values = new List<ListXmlDipValue>();
|
||||
|
||||
// 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":
|
||||
var condition = new ListXmlCondition();
|
||||
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":
|
||||
var dipLocation = new ListXmlDipLocation();
|
||||
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":
|
||||
var dipValue = new ListXmlDipValue();
|
||||
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>
|
||||
/// <param name="dipValue">ListXmlDipValue to populate</param>
|
||||
private void ReadDipValue(XmlReader reader, ListXmlDipValue dipValue)
|
||||
{
|
||||
// If we have an empty dipvalue, skip it
|
||||
if (reader == null)
|
||||
return;
|
||||
|
||||
// Get list ready
|
||||
dipValue.Conditions = new List<ListXmlCondition>();
|
||||
|
||||
// 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":
|
||||
var condition = new ListXmlCondition();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create and open an output file for writing direct from a dictionary
|
||||
/// </summary>
|
||||
@@ -940,6 +1309,62 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
xtw.WriteStartElement("file");
|
||||
|
||||
@@ -336,19 +336,20 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "dipswitch":
|
||||
var dipSwitch = new ListXmlDipSwitch();
|
||||
dipSwitch.Name = reader.GetAttribute("name");
|
||||
dipSwitch.Tag = reader.GetAttribute("tag");
|
||||
dipSwitch.Mask = reader.GetAttribute("mask");
|
||||
var dipSwitch = new DipSwitch
|
||||
{
|
||||
Name = reader.GetAttribute("name"),
|
||||
Tag = reader.GetAttribute("tag"),
|
||||
Mask = reader.GetAttribute("mask"),
|
||||
Conditions = new List<ListXmlCondition>(),
|
||||
Locations = new List<ListXmlDipLocation>(),
|
||||
Values = new List<ListXmlDipValue>(),
|
||||
};
|
||||
|
||||
// Now read the internal tags
|
||||
ReadDipSwitch(reader.ReadSubtree(), dipSwitch);
|
||||
|
||||
// Ensure the list exists
|
||||
if (machine.DipSwitches == null)
|
||||
machine.DipSwitches = new List<ListXmlDipSwitch>();
|
||||
|
||||
machine.DipSwitches.Add(dipSwitch);
|
||||
items.Add(dipSwitch);
|
||||
|
||||
// Skip the dipswitch now that we've processed it
|
||||
reader.Skip();
|
||||
@@ -517,8 +518,8 @@ namespace SabreTools.Library.DatFiles
|
||||
/// Read DipSwitch DipValues information
|
||||
/// </summary>
|
||||
/// <param name="reader">XmlReader representing a diskarea block</param>
|
||||
/// <param name="dipSwitch">ListXMLDipSwitch to populate</param>
|
||||
private void ReadDipSwitch(XmlReader reader, ListXmlDipSwitch dipSwitch)
|
||||
/// <param name="dipSwitch">DipSwitch to populate</param>
|
||||
private void ReadDipSwitch(XmlReader reader, DipSwitch dipSwitch)
|
||||
{
|
||||
// If we have an empty dipswitch, skip it
|
||||
if (reader == null)
|
||||
@@ -720,29 +721,6 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
if (datItem.Machine.DipSwitches != null && datItem.Machine.DipSwitches.Count > 0)
|
||||
{
|
||||
foreach (ListXmlDipSwitch dip in datItem.Machine.DipSwitches)
|
||||
{
|
||||
xtw.WriteStartElement("dipswitch");
|
||||
xtw.WriteRequiredAttributeString("name", dip.Name);
|
||||
xtw.WriteRequiredAttributeString("tag", dip.Tag);
|
||||
xtw.WriteRequiredAttributeString("mask", dip.Mask);
|
||||
|
||||
foreach (ListXmlDipValue dipval in dip.Values)
|
||||
{
|
||||
xtw.WriteStartElement("dipvalue");
|
||||
xtw.WriteRequiredAttributeString("name", dipval.Name);
|
||||
xtw.WriteRequiredAttributeString("value", dipval.Value);
|
||||
xtw.WriteRequiredAttributeString("default", dipval.Default == true ? "yes" : "no");
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
// End dipswitch
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -809,6 +787,26 @@ namespace SabreTools.Library.DatFiles
|
||||
string areaName = datItem.AreaName;
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
case ItemType.DipSwitch:
|
||||
var dipSwitch = datItem as DipSwitch;
|
||||
xtw.WriteStartElement("dipswitch");
|
||||
xtw.WriteRequiredAttributeString("name", dipSwitch.Name);
|
||||
xtw.WriteRequiredAttributeString("tag", dipSwitch.Tag);
|
||||
xtw.WriteRequiredAttributeString("mask", dipSwitch.Mask);
|
||||
if (dipSwitch.Values != null)
|
||||
{
|
||||
foreach (ListXmlDipValue dipValue in dipSwitch.Values)
|
||||
{
|
||||
xtw.WriteStartElement("dipvalue");
|
||||
xtw.WriteRequiredAttributeString("name", dipValue.Name);
|
||||
xtw.WriteOptionalAttributeString("value", dipValue.Value);
|
||||
xtw.WriteOptionalAttributeString("default", dipValue.Default.FromYesNo());
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
}
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
|
||||
case ItemType.Disk:
|
||||
var disk = datItem as Disk;
|
||||
if (string.IsNullOrWhiteSpace(areaName))
|
||||
|
||||
Reference in New Issue
Block a user