mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Remove most of the outdated references and methods
This commit is contained in:
@@ -56,41 +56,124 @@ namespace SabreTools
|
|||||||
Directory.CreateDirectory(_outdir);
|
Directory.CreateDirectory(_outdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<RomData> romsA = new List<RomData>();
|
// Create the initial DatData object
|
||||||
List<RomData> romsB = new List<RomData>();
|
DatData datdata = new DatData
|
||||||
|
{
|
||||||
|
Name = "",
|
||||||
|
Description = "",
|
||||||
|
Category = "",
|
||||||
|
Version = "",
|
||||||
|
Date = "",
|
||||||
|
Author = "",
|
||||||
|
Email = "",
|
||||||
|
Homepage = "",
|
||||||
|
Url = "",
|
||||||
|
Comment = "",
|
||||||
|
Roms = new Dictionary<string, List<RomData>>(),
|
||||||
|
};
|
||||||
|
|
||||||
// Load the current DAT to be processed
|
// Load the current DAT to be processed
|
||||||
List<RomData> roms = RomManipulation.Parse(_filename, 0, 0, _logger);
|
datdata = RomManipulation.ParseDict(_filename, 0, 0, datdata, _logger);
|
||||||
|
|
||||||
|
// Set all of the appropriate outputs for each of the subsets
|
||||||
|
OutputFormat outputFormat = RomManipulation.GetOutputFormat(_filename);
|
||||||
|
DatData datdataA = new DatData
|
||||||
|
{
|
||||||
|
Name = datdata.Name + "." + _extA,
|
||||||
|
Description = datdata.Description + "." + _extA,
|
||||||
|
Category = datdata.Category,
|
||||||
|
Version = datdata.Version,
|
||||||
|
Date = datdata.Date,
|
||||||
|
Author = datdata.Author,
|
||||||
|
Email = datdata.Email,
|
||||||
|
Homepage = datdata.Homepage,
|
||||||
|
Url = datdata.Url,
|
||||||
|
Comment = datdata.Comment,
|
||||||
|
Roms = new Dictionary<string, List<RomData>>(),
|
||||||
|
OutputFormat = outputFormat,
|
||||||
|
};
|
||||||
|
DatData datdataB = new DatData
|
||||||
|
{
|
||||||
|
Name = datdata.Name + "." + _extB,
|
||||||
|
Description = datdata.Description + "." + _extB,
|
||||||
|
Category = datdata.Category,
|
||||||
|
Version = datdata.Version,
|
||||||
|
Date = datdata.Date,
|
||||||
|
Author = datdata.Author,
|
||||||
|
Email = datdata.Email,
|
||||||
|
Homepage = datdata.Homepage,
|
||||||
|
Url = datdata.Url,
|
||||||
|
Comment = datdata.Comment,
|
||||||
|
Roms = new Dictionary<string, List<RomData>>(),
|
||||||
|
OutputFormat = outputFormat,
|
||||||
|
};
|
||||||
|
|
||||||
// If roms is empty, return false
|
// If roms is empty, return false
|
||||||
if (roms.Count == 0)
|
if (datdata.Roms.Count == 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now separate the roms accordingly
|
// Now separate the roms accordingly
|
||||||
foreach (RomData rom in roms)
|
foreach (string key in datdata.Roms.Keys)
|
||||||
{
|
{
|
||||||
if (rom.Name.ToUpperInvariant().EndsWith(_extA))
|
foreach (RomData rom in datdata.Roms[key])
|
||||||
{
|
{
|
||||||
romsA.Add(rom);
|
if (rom.Name.ToUpperInvariant().EndsWith(_extA))
|
||||||
}
|
{
|
||||||
else if (rom.Name.ToUpperInvariant().EndsWith(_extB))
|
if (datdataA.Roms.ContainsKey(key))
|
||||||
{
|
{
|
||||||
romsB.Add(rom);
|
datdataA.Roms[key].Add(rom);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
romsA.Add(rom);
|
List<RomData> temp = new List<RomData>();
|
||||||
romsB.Add(rom);
|
temp.Add(rom);
|
||||||
|
datdataA.Roms.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (rom.Name.ToUpperInvariant().EndsWith(_extB))
|
||||||
|
{
|
||||||
|
if (datdataB.Roms.ContainsKey(key))
|
||||||
|
{
|
||||||
|
datdataB.Roms[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
datdataB.Roms.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (datdataA.Roms.ContainsKey(key))
|
||||||
|
{
|
||||||
|
datdataA.Roms[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
datdataA.Roms.Add(key, temp);
|
||||||
|
}
|
||||||
|
if (datdataB.Roms.ContainsKey(key))
|
||||||
|
{
|
||||||
|
datdataB.Roms[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
datdataB.Roms.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then write out both files
|
// Then write out both files
|
||||||
bool success = Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename) + "." + _extA, Path.GetFileNameWithoutExtension(_filename) + "." + _extA,
|
bool success = Output.WriteToDatFromDict(datdataA, _outdir, _logger);
|
||||||
"", "", "", "", false, !RomManipulation.IsXmlDat(_filename), _outdir, romsA, _logger);
|
success &= Output.WriteToDatFromDict(datdataB, _outdir, _logger);
|
||||||
success &= Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename) + "." + _extB, Path.GetFileNameWithoutExtension(_filename) + "." + _extB,
|
|
||||||
"", "", "", "", false, !RomManipulation.IsXmlDat(_filename), _outdir, romsB, _logger);
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,40 +82,58 @@ namespace SabreTools
|
|||||||
/// <param name="rename">True if roms are to be renamed</param>
|
/// <param name="rename">True if roms are to be renamed</param>
|
||||||
private void ProcessDAT(string filename, string path, bool rename)
|
private void ProcessDAT(string filename, string path, bool rename)
|
||||||
{
|
{
|
||||||
List<RomData> roms = RomManipulation.Parse(filename, 0, 0, _logger);
|
DatData datdata = new DatData
|
||||||
|
{
|
||||||
|
Name = "",
|
||||||
|
Description = "",
|
||||||
|
Category = "",
|
||||||
|
Version = "",
|
||||||
|
Date = "",
|
||||||
|
Author = "",
|
||||||
|
Email = "",
|
||||||
|
Homepage = "",
|
||||||
|
Url = "",
|
||||||
|
Comment = "",
|
||||||
|
Roms = new Dictionary<string, List<RomData>>(),
|
||||||
|
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
|
||||||
|
OutputFormat = RomManipulation.GetOutputFormat(filename),
|
||||||
|
};
|
||||||
|
datdata = RomManipulation.ParseDict(filename, 0, 0, datdata, _logger);
|
||||||
|
|
||||||
// Trim all file names according to the path that's set
|
// Trim all file names according to the path that's set
|
||||||
List<RomData> outroms = new List<RomData>();
|
foreach (string key in datdata.Roms.Keys)
|
||||||
while (roms.Count != 0)
|
|
||||||
{
|
{
|
||||||
RomData rom = roms[0];
|
List<RomData> outroms = new List<RomData>();
|
||||||
roms.RemoveAt(0);
|
|
||||||
|
|
||||||
// If we are in single game mode, rename all games
|
foreach (RomData actrom in datdata.Roms[key])
|
||||||
if (rename)
|
|
||||||
{
|
{
|
||||||
rom.Game = "!";
|
RomData rom = actrom;
|
||||||
}
|
|
||||||
|
|
||||||
// Windows max name length is 260
|
// If we are in single game mode, rename all games
|
||||||
int usableLength = 260 - rom.Game.Length - _path.Length;
|
if (rename)
|
||||||
if (rom.Name.Length > usableLength)
|
{
|
||||||
{
|
rom.Game = "!";
|
||||||
string ext = Path.GetExtension(rom.Name);
|
}
|
||||||
rom.Name = rom.Name.Substring(0, usableLength - ext.Length);
|
|
||||||
rom.Name += ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
outroms.Add(rom);
|
// Windows max name length is 260
|
||||||
|
int usableLength = 260 - rom.Game.Length - _path.Length;
|
||||||
|
if (rom.Name.Length > usableLength)
|
||||||
|
{
|
||||||
|
string ext = Path.GetExtension(rom.Name);
|
||||||
|
rom.Name = rom.Name.Substring(0, usableLength - ext.Length);
|
||||||
|
rom.Name += ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
outroms.Add(rom);
|
||||||
|
}
|
||||||
|
datdata.Roms[key] = outroms;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now write the file out accordingly
|
// Now write the file out accordingly
|
||||||
string datName = RomManipulation.GetDatName(filename, _logger);
|
Output.WriteToDatFromDict(datdata, Path.GetDirectoryName(filename), _logger);
|
||||||
string datDescription = RomManipulation.GetDatDescription(filename, _logger);
|
|
||||||
Output.WriteToDat(datName, datDescription, "", "", "", "", _forceunpack, !RomManipulation.IsXmlDat(filename), Path.GetDirectoryName(filename), outroms, _logger);
|
|
||||||
|
|
||||||
// Remove the original file if different and inform the user
|
// Remove the original file if different and inform the user
|
||||||
if (filename != datDescription + (RomManipulation.IsXmlDat(filename) ? ".xml" : ".dat"))
|
if (filename != datdata.Description + (RomManipulation.GetOutputFormat(filename) == OutputFormat.Xml ? ".xml" : ".dat"))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,96 +17,36 @@ namespace SabreTools.Helper
|
|||||||
public static string SHA1Zero = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
public static string SHA1Zero = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return if the file is XML or not
|
/// Get what type of DAT the input file is
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <returns>True if the DAT is probably XML, false otherwise</returns>
|
/// <returns>The OutputFormat corresponding to the DAT</returns>
|
||||||
public static bool IsXmlDat(string filename)
|
public static OutputFormat GetOutputFormat(string filename)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StreamReader sr = new StreamReader(File.OpenRead(filename));
|
StreamReader sr = new StreamReader(File.OpenRead(filename));
|
||||||
string first = sr.ReadLine();
|
string first = sr.ReadLine();
|
||||||
sr.Close();
|
sr.Close();
|
||||||
return first.Contains("<") && first.Contains(">");
|
if (first.Contains("<") && first.Contains(">"))
|
||||||
|
{
|
||||||
|
return OutputFormat.Xml;
|
||||||
|
}
|
||||||
|
else if (first.Contains("[") && first.Contains("]"))
|
||||||
|
{
|
||||||
|
return OutputFormat.RomCenter;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return OutputFormat.ClrMamePro;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return false;
|
return OutputFormat.ClrMamePro;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Return if the file is RomCenter or not
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
|
||||||
/// <returns>True if the DAT is probably RomCenter, false otherwise</returns>
|
|
||||||
public static bool IsRCDat(string filename)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StreamReader sr = new StreamReader(File.OpenRead(filename));
|
|
||||||
string first = sr.ReadLine();
|
|
||||||
sr.Close();
|
|
||||||
return first.Contains("[") && first.Contains("]");
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the XmlDocument associated with a file, if possible
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
|
||||||
/// <param name="logger">Logger object for console and file output</param>
|
|
||||||
/// <returns>The XmlDocument representing the (possibly converted) file, null otherwise</returns>
|
|
||||||
public static XmlDocument GetXmlDocument(string filename, Logger logger)
|
|
||||||
{
|
|
||||||
logger.Log("Attempting to read file: " + filename);
|
|
||||||
|
|
||||||
// Check if file exists
|
|
||||||
if (!File.Exists(filename))
|
|
||||||
{
|
|
||||||
logger.Warning("File '" + filename + "' could not read from!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
XmlDocument doc = new XmlDocument();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doc.Load(filename);
|
|
||||||
}
|
|
||||||
catch (XmlException)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doc.LoadXml(Converters.ClrMameProToXML(File.ReadAllLines(filename)).ToString());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.Error(ex.ToString());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException)
|
|
||||||
{
|
|
||||||
logger.Error("File '" + filename + "' could not be open or read");
|
|
||||||
}
|
|
||||||
catch (OutOfMemoryException)
|
|
||||||
{
|
|
||||||
logger.Error("File '" + filename + "' is too large to be processed!");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.Error(ex.ToString());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the XmlTextReader associated with a file, if possible
|
/// Get the XmlTextReader associated with a file, if possible
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -124,128 +64,29 @@ namespace SabreTools.Helper
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsXmlDat(filename))
|
XmlTextReader xtr;
|
||||||
|
StringReader sr;
|
||||||
|
switch (GetOutputFormat(filename))
|
||||||
{
|
{
|
||||||
logger.Log("XML DAT detected");
|
case OutputFormat.Xml:
|
||||||
XmlTextReader xtr = new XmlTextReader(filename);
|
logger.Log("XML DAT detected");
|
||||||
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
xtr = new XmlTextReader(filename);
|
||||||
xtr.DtdProcessing = DtdProcessing.Ignore;
|
break;
|
||||||
return xtr;
|
case OutputFormat.RomCenter:
|
||||||
}
|
logger.Log("RomCenter DAT detected");
|
||||||
else if (IsRCDat(filename))
|
sr = new StringReader(Converters.RomCenterToXML(File.ReadAllLines(filename)).ToString());
|
||||||
{
|
xtr = new XmlTextReader(sr);
|
||||||
logger.Log("RomCenter DAT detected");
|
break;
|
||||||
StringReader sr = new StringReader(Converters.RomCenterToXML(File.ReadAllLines(filename)).ToString());
|
default:
|
||||||
XmlTextReader xtr = new XmlTextReader(sr);
|
logger.Log("ClrMamePro DAT detected");
|
||||||
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
sr = new StringReader(Converters.ClrMameProToXML(File.ReadAllLines(filename)).ToString());
|
||||||
xtr.DtdProcessing = DtdProcessing.Ignore;
|
xtr = new XmlTextReader(sr);
|
||||||
return xtr;
|
break;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Log("ClrMamePro DAT detected");
|
|
||||||
StringReader sr = new StringReader(Converters.ClrMameProToXML(File.ReadAllLines(filename)).ToString());
|
|
||||||
XmlTextReader xtr = new XmlTextReader(sr);
|
|
||||||
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
|
||||||
xtr.DtdProcessing = DtdProcessing.Ignore;
|
|
||||||
return xtr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the name of the DAT for external use
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
|
||||||
/// <param name="logger">Logger object for console and file output</param>
|
|
||||||
/// <returns>The internal name of the DAT on success, empty string otherwise</returns>
|
|
||||||
/// <remarks>Needs to be upgraded to XmlTextReader</remarks>
|
|
||||||
public static string GetDatName(string filename, Logger logger)
|
|
||||||
{
|
|
||||||
string name = "";
|
|
||||||
XmlDocument doc = GetXmlDocument(filename, logger);
|
|
||||||
|
|
||||||
// If the returned document is null, return the blank string
|
|
||||||
if (doc == null)
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Experimental looping using only XML parsing
|
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
||||||
XmlNode node = doc.FirstChild;
|
xtr.DtdProcessing = DtdProcessing.Ignore;
|
||||||
if (node != null && node.Name == "xml")
|
return xtr;
|
||||||
{
|
|
||||||
// Skip over everything that's not an element
|
|
||||||
while (node.NodeType != XmlNodeType.Element)
|
|
||||||
{
|
|
||||||
node = node.NextSibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once we find the main body, enter it
|
|
||||||
if (node != null && (node.Name == "datafile" || node.Name == "softwarelist"))
|
|
||||||
{
|
|
||||||
node = node.FirstChild;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the name from the header
|
|
||||||
if (node != null && node.Name == "header")
|
|
||||||
{
|
|
||||||
XmlNode temp = node.SelectSingleNode("name");
|
|
||||||
if (temp != null)
|
|
||||||
{
|
|
||||||
name = temp.InnerText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the description of the DAT for external use
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
|
||||||
/// <param name="logger">Logger object for console and file output</param>
|
|
||||||
/// <returns>The internal name of the DAT on success, empty string otherwise</returns>
|
|
||||||
/// <remarks>Needs to be upgraded to XmlTextReader</remarks>
|
|
||||||
public static string GetDatDescription(string filename, Logger logger)
|
|
||||||
{
|
|
||||||
string desc = "";
|
|
||||||
XmlDocument doc = GetXmlDocument(filename, logger);
|
|
||||||
|
|
||||||
// If the returned document is null, return the blank string
|
|
||||||
if (doc == null)
|
|
||||||
{
|
|
||||||
return desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Experimental looping using only XML parsing
|
|
||||||
XmlNode node = doc.FirstChild;
|
|
||||||
if (node != null && node.Name == "xml")
|
|
||||||
{
|
|
||||||
// Skip over everything that's not an element
|
|
||||||
while (node.NodeType != XmlNodeType.Element)
|
|
||||||
{
|
|
||||||
node = node.NextSibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once we find the main body, enter it
|
|
||||||
if (node != null && (node.Name == "datafile" || node.Name == "softwarelist"))
|
|
||||||
{
|
|
||||||
node = node.FirstChild;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the name from the header
|
|
||||||
if (node != null && node.Name == "header")
|
|
||||||
{
|
|
||||||
XmlNode temp = node.SelectSingleNode("description");
|
|
||||||
if (temp != null)
|
|
||||||
{
|
|
||||||
desc = temp.InnerText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return desc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user