mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFiles/] Make all DatFile types actually inherit from DatFile
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.Items;
|
||||
@@ -25,12 +23,11 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <summary>
|
||||
/// Represents parsing and writing of an OfflineList XML DAT
|
||||
/// </summary>
|
||||
public class OfflineList
|
||||
public class OfflineList : DatFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Parse an OfflineList XML DAT and return all found games and roms within
|
||||
/// </summary>
|
||||
/// <param name="datFile">DatFile to populate with the read information</param>
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
@@ -39,9 +36,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
public static void Parse(
|
||||
DatFile datFile,
|
||||
|
||||
public void Parse(
|
||||
// Standard Dat parsing
|
||||
string filename,
|
||||
int sysid,
|
||||
@@ -53,17 +48,16 @@ namespace SabreTools.Library.DatFiles
|
||||
bool remUnicode)
|
||||
{
|
||||
// All XML-derived DATs share a lot in common so it just calls one implementation
|
||||
Logiqx.Parse(datFile, filename, sysid, srcid, keep, clean, remUnicode);
|
||||
(this as DatFile as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create and open an output file for writing direct from a dictionary
|
||||
/// </summary>
|
||||
/// <param name="datFile">DatFile to write out from</param>
|
||||
/// <param name="outfile">Name of the file to write to</param>
|
||||
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||
public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false)
|
||||
public bool WriteToFile(string outfile, bool ignoreblanks = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -80,18 +74,18 @@ namespace SabreTools.Library.DatFiles
|
||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||
|
||||
// Write out the header
|
||||
WriteHeader(datFile, sw);
|
||||
WriteHeader(sw);
|
||||
|
||||
// Write out each of the machines and roms
|
||||
string lastgame = null;
|
||||
|
||||
// Get a properly sorted set of keys
|
||||
List<string> keys = datFile.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
keys.Sort(new NaturalComparer());
|
||||
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = datFile[key];
|
||||
List<DatItem> roms = this[key];
|
||||
|
||||
// Resolve the names in the block
|
||||
roms = DatItem.ResolveNames(roms);
|
||||
@@ -157,18 +151,17 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <summary>
|
||||
/// Write out DAT header using the supplied StreamWriter
|
||||
/// </summary>
|
||||
/// <param name="datFile">DatFile to write out from</param>
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private static bool WriteHeader(DatFile datFile, StreamWriter sw)
|
||||
private bool WriteHeader(StreamWriter sw)
|
||||
{
|
||||
try
|
||||
{
|
||||
string header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
|
||||
+ "<dat xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"datas.xsd\">\n"
|
||||
+ "\t<configuration>\n"
|
||||
+ "\t\t<datName>" + HttpUtility.HtmlEncode(datFile.Name) + "</datName>\n"
|
||||
+ "\t\t<datVersion>" + datFile.Count + "</datVersion>\n"
|
||||
+ "\t\t<datName>" + HttpUtility.HtmlEncode(Name) + "</datName>\n"
|
||||
+ "\t\t<datVersion>" + Count + "</datVersion>\n"
|
||||
+ "\t\t<system>none</system>\n"
|
||||
+ "\t\t<screenshotsWidth>240</screenshotsWidth>\n"
|
||||
+ "\t\t<screenshotsHeight>160</screenshotsHeight>\n"
|
||||
@@ -191,9 +184,9 @@ namespace SabreTools.Library.DatFiles
|
||||
+ "\t\t\t<extension>.bin</extension>\n"
|
||||
+ "\t\t</canOpen>\n"
|
||||
+ "\t\t<newDat>\n"
|
||||
+ "\t\t\t<datVersionURL>" + HttpUtility.HtmlEncode(datFile.Url) + "</datVersionURL>\n"
|
||||
+ "\t\t\t<datURL fileName=\"" + HttpUtility.HtmlEncode(datFile.FileName) + ".zip\">" + HttpUtility.HtmlEncode(datFile.Url) + "</datURL>\n"
|
||||
+ "\t\t\t<imURL>" + HttpUtility.HtmlEncode(datFile.Url) + "</imURL>\n"
|
||||
+ "\t\t\t<datVersionURL>" + HttpUtility.HtmlEncode(Url) + "</datVersionURL>\n"
|
||||
+ "\t\t\t<datURL fileName=\"" + HttpUtility.HtmlEncode(FileName) + ".zip\">" + HttpUtility.HtmlEncode(Url) + "</datURL>\n"
|
||||
+ "\t\t\t<imURL>" + HttpUtility.HtmlEncode(Url) + "</imURL>\n"
|
||||
+ "\t\t</newDat>\n"
|
||||
+ "\t\t<search>\n"
|
||||
+ "\t\t\t<to value=\"location\" default=\"true\" auto=\"true\"/>\n"
|
||||
@@ -225,7 +218,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private static bool WriteEndGame(StreamWriter sw)
|
||||
private bool WriteEndGame(StreamWriter sw)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -250,7 +243,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <param name="rom">RomData object to be output</param>
|
||||
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false)
|
||||
private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false)
|
||||
{
|
||||
// If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||
if (ignoreblanks
|
||||
@@ -327,7 +320,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="sw">StreamWriter to output to</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
private static bool WriteFooter(StreamWriter sw)
|
||||
private bool WriteFooter(StreamWriter sw)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user