Skip to content

Commit

Permalink
Add No-Intro Support (#8)
Browse files Browse the repository at this point in the history
* Add support for No-Intro's DATs
Fixes #7
  • Loading branch information
michael-j-green authored Feb 11, 2024
1 parent 4ce9f27 commit d3e6afb
Show file tree
Hide file tree
Showing 7 changed files with 643 additions and 72 deletions.
7 changes: 6 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
"stopAtEntry": false,
"projectPath": "${workspaceFolder}/TestApp/TestApp.csproj",
"launchConfigurationId": "TargetFramework=;TestApp",
"args": ["-tosecpath", "/Volumes/Macintosh HD/Users/michaelgreen/Downloads/TOSEC.2016.11.11.Commodore.C64.AlphaBot/"]
"args": [
"-datpath",
"/Users/michaelgreen/Downloads/No-Intro Love Pack (Standard) (2024-02-09)/No-Intro/",
"-dbpath",
"/Users/michaelgreen/Downloads/No-Intro Love Pack (DB Export) (2024-02-08)/No-Intro/"
]
}
]
}
80 changes: 55 additions & 25 deletions TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
string[] commandLineArgs = Environment.GetCommandLineArgs();

string scanPath = "./";
string tosecXML = "";
string datPath = "";
string? dbPath = null;

string inArgument = "";
foreach (string commandLineArg in commandLineArgs)
Expand All @@ -21,10 +22,10 @@
{
switch (commandLineArg.ToLower())
{

case "-scanpath":
inArgument = commandLineArg.ToLower();
break;
case "-tosecpath":
case "-datpath":
case "-dbpath":
inArgument = commandLineArg.ToLower();
break;
default:
Expand All @@ -38,8 +39,11 @@
case "-scanpath":
scanPath = commandLineArg;
break;
case "-tosecpath":
tosecXML = commandLineArg;
case "-datpath":
datPath = commandLineArg;
break;
case "-dbpath":
dbPath = commandLineArg;
break;
default:
break;
Expand All @@ -55,37 +59,63 @@
List<RomSignatureObject> romSignatures = new List<RomSignatureObject>();
System.Collections.ArrayList availablePlatforms = new System.Collections.ArrayList();

// load TOSEC XML files
if (tosecXML != null && tosecXML.Length > 0)
// load DAT XML files
if (datPath != null && datPath.Length > 0)
{
tosecXML = Path.GetFullPath(tosecXML);
Console.WriteLine("TOSEC is enabled");
Console.WriteLine("TOSEC XML search path: " + tosecXML);
datPath = Path.GetFullPath(datPath);
Console.WriteLine("DATs are enabled");
Console.WriteLine("DAT XML search path: " + datPath);
if (dbPath != null)
{
Console.WriteLine("DB XML search path: " + dbPath);
}

string[] tosecPathContents = Directory.GetFiles(tosecXML);
int lastCLILineLength = 0;
for (UInt16 i = 0; i < tosecPathContents.Length; ++i)
string[] datPathContents = Directory.GetFiles(datPath, "*.dat");
string[] dbPathContents = new string[0];
if (dbPath != null)
{
string tosecXMLFile = tosecPathContents[i];
dbPathContents = Directory.GetFiles(dbPath, "*.xml");
}

int lastCLILineLength = 0;
for (UInt16 i = 0; i < datPathContents.Length; ++i)
{
string datPathFile = datPathContents[i];

parser Parser = new parser();
try {
RomSignatureObject tosecObject = Parser.ParseSignatureDAT(tosecXMLFile);
string? dbPathFile = null;
string dbPathName = "";
if (dbPathContents.Length > 0)
{
foreach (string dbFile in dbPathContents)
{
string testFileName = Path.GetFileNameWithoutExtension(dbFile.Replace(" (DB Export)", ""));
if (testFileName == Path.GetFileNameWithoutExtension(datPathFile))
{
// match!
dbPathFile = dbFile;
dbPathName = Path.GetFileName(dbFile);
}
}
}

RomSignatureObject datObject = Parser.ParseSignatureDAT(datPathFile, dbPathFile);

if (tosecObject != null) {
string statusOutput = i + " / " + tosecPathContents.Length + " : " + Path.GetFileName(tosecXMLFile);
if (datObject != null) {
string statusOutput = (i + 1) + " / " + datPathContents.Length + " : " + Path.GetFileName(datPathFile) + " " + dbPathName;
Console.Write("\r " + statusOutput.PadRight(lastCLILineLength, ' ') + "\r");
lastCLILineLength = statusOutput.Length;

foreach (RomSignatureObject.Game gameRom in tosecObject.Games)
foreach (RomSignatureObject.Game gameRom in datObject.Games)
{
if (!availablePlatforms.Contains(gameRom.System))
{
availablePlatforms.Add(gameRom.System);
}
}

romSignatures.Add(tosecObject);
romSignatures.Add(datObject);
}
}
catch {
Expand All @@ -95,9 +125,9 @@
Console.WriteLine("");
} else
{
Console.WriteLine("TOSEC is disabled.");
Console.WriteLine("DATs are disabled.");
}
Console.WriteLine(romSignatures.Count + " TOSEC files loaded");
Console.WriteLine(romSignatures.Count + " DAT files loaded");

// Summarise signatures
if (availablePlatforms.Count > 0)
Expand Down Expand Up @@ -127,9 +157,9 @@
string sha1Hash = BitConverter.ToString(sha1HashByte).Replace("-", "").ToLowerInvariant();

bool gameFound = false;
foreach (RomSignatureObject tosecList in romSignatures)
foreach (RomSignatureObject datList in romSignatures)
{
foreach (RomSignatureObject.Game gameObject in tosecList.Games)
foreach (RomSignatureObject.Game gameObject in datList.Games)
{
foreach (RomSignatureObject.Game.Rom romObject in gameObject.Roms)
{
Expand Down Expand Up @@ -170,7 +200,7 @@
}
if (gameFound == false)
{
Console.WriteLine("File not found in TOSEC library");
Console.WriteLine("File not found in DAT library");
}
}

Expand Down
58 changes: 32 additions & 26 deletions gaseous-signature-parser/classes/parsers/MAMEParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public RomSignatureObject Parse(string XMLFile, parser.SignatureParser DocumentT
RomSignatureObject.Game machineObject = new RomSignatureObject.Game();
machineObject.System = "Arcade";
machineObject.Roms = new List<RomSignatureObject.Game.Rom>();
machineObject.flags = new List<KeyValuePair<string, object>>();
machineObject.flags = new Dictionary<string, object>();

machineObject.Name = xmlMachine.Attributes["name"].Value;

if (xmlMachine.Attributes["sourcefile"] != null) {
machineObject.flags.Add(new KeyValuePair<string, object>(
"sourcefile",
xmlMachine.Attributes["sourcefile"].Value
));
if (!machineObject.flags.ContainsKey("sourcefile"))
{
machineObject.flags.Add("sourcefile", xmlMachine.Attributes["sourcefile"].Value);
}
}

foreach (XmlNode childNode in xmlMachine.ChildNodes)
Expand All @@ -134,7 +134,7 @@ public RomSignatureObject Parse(string XMLFile, parser.SignatureParser DocumentT

case "rom":
RomSignatureObject.Game.Rom rom = new RomSignatureObject.Game.Rom();
rom.Attributes = new List<KeyValuePair<string, object>>();
rom.Attributes = new Dictionary<string, object>();
rom.SignatureSource = signatureSource;
foreach (XmlAttribute romAttribute in childNode.Attributes)
{
Expand All @@ -154,11 +154,10 @@ public RomSignatureObject Parse(string XMLFile, parser.SignatureParser DocumentT
break;

default:
KeyValuePair<string, object> keyValuePair = new KeyValuePair<string, object>(
romAttribute.Name,
childNode.Attributes[romAttribute.Name]?.Value
);
rom.Attributes.Add(keyValuePair);
if (!rom.Attributes.ContainsKey(romAttribute.Name))
{
rom.Attributes.Add(romAttribute.Name, childNode.Attributes[romAttribute.Name]?.Value);

Check warning on line 159 in gaseous-signature-parser/classes/parsers/MAMEParser.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'value' in 'void Dictionary<string, object>.Add(string key, object value)'.
}
break;
}
}
Expand All @@ -167,10 +166,10 @@ public RomSignatureObject Parse(string XMLFile, parser.SignatureParser DocumentT
break;

default:
machineObject.flags.Add(new KeyValuePair<string, object>(
childNode.Name,
parser.ConvertXmlNodeToDictionary(childNode)
));
if (!machineObject.flags.ContainsKey(childNode.Name))
{
machineObject.flags.Add(childNode.Name, parser.ConvertXmlNodeToDictionary(childNode));
}
break;
}
}
Expand All @@ -181,23 +180,30 @@ public RomSignatureObject Parse(string XMLFile, parser.SignatureParser DocumentT
}

public parser.SignatureParser GetXmlType(XmlDocument xml) {
XmlNode xmlHeader = xml.DocumentElement.SelectSingleNode("/datafile/header");
try
{
XmlNode xmlHeader = xml.DocumentElement.SelectSingleNode("/datafile/header");

if (xmlHeader != null) {
if (xmlHeader.SelectSingleNode("name").InnerText.Equals("MAME", StringComparison.OrdinalIgnoreCase)) {
if (xmlHeader.SelectSingleNode("description").InnerText.StartsWith("MAME Arcade")) {
return parser.SignatureParser.MAMEArcade;
if (xmlHeader != null) {
if (xmlHeader.SelectSingleNode("name").InnerText.Equals("MAME", StringComparison.OrdinalIgnoreCase)) {
if (xmlHeader.SelectSingleNode("description").InnerText.StartsWith("MAME Arcade")) {
return parser.SignatureParser.MAMEArcade;
}
}
}

if (xmlHeader.SelectSingleNode("name").InnerText.Equals("MESS", StringComparison.OrdinalIgnoreCase)) {
if (xmlHeader.SelectSingleNode("description").InnerText.StartsWith("MAME Home")) {
return parser.SignatureParser.MAMEMess;
if (xmlHeader.SelectSingleNode("name").InnerText.Equals("MESS", StringComparison.OrdinalIgnoreCase)) {
if (xmlHeader.SelectSingleNode("description").InnerText.StartsWith("MAME Home")) {
return parser.SignatureParser.MAMEMess;
}
}
}
}

return parser.SignatureParser.Unknown;
return parser.SignatureParser.Unknown;
}
catch
{
return parser.SignatureParser.Unknown;
}
}
}
}
Loading

0 comments on commit d3e6afb

Please sign in to comment.