refactor: moved over to submodule based linking for RomSignatureObject

This commit is contained in:
Michael Green
2023-02-21 23:48:57 +11:00
parent 0747f3a028
commit d6763623f4
3 changed files with 86 additions and 81 deletions

View File

@@ -8,7 +8,7 @@ namespace gaseous_identifier.classes
{ {
public class TosecParser public class TosecParser
{ {
public objects.RomSignatureObject Parse(string XMLFile) public Gaseous_ROMSignatureObject.RomSignatureObject Parse(string XMLFile)
{ {
// load resources // load resources
var assembly = Assembly.GetExecutingAssembly(); var assembly = Assembly.GetExecutingAssembly();
@@ -92,7 +92,7 @@ namespace gaseous_identifier.classes
XmlDocument tosecXmlDoc = new XmlDocument(); XmlDocument tosecXmlDoc = new XmlDocument();
tosecXmlDoc.Load(XMLFile); tosecXmlDoc.Load(XMLFile);
objects.RomSignatureObject tosecObject = new objects.RomSignatureObject(); Gaseous_ROMSignatureObject.RomSignatureObject tosecObject = new Gaseous_ROMSignatureObject.RomSignatureObject();
// get header // get header
XmlNode xmlHeader = tosecXmlDoc.DocumentElement.SelectSingleNode("/datafile/header"); XmlNode xmlHeader = tosecXmlDoc.DocumentElement.SelectSingleNode("/datafile/header");
@@ -145,11 +145,11 @@ namespace gaseous_identifier.classes
} }
// get games // get games
tosecObject.Games = new List<gaseous_identifier.objects.RomSignatureObject.Game>(); tosecObject.Games = new List<Gaseous_ROMSignatureObject.RomSignatureObject.Game>();
XmlNodeList xmlGames = tosecXmlDoc.DocumentElement.SelectNodes("/datafile/game"); XmlNodeList xmlGames = tosecXmlDoc.DocumentElement.SelectNodes("/datafile/game");
foreach (XmlNode xmlGame in xmlGames) foreach (XmlNode xmlGame in xmlGames)
{ {
objects.RomSignatureObject.Game gameObject = new objects.RomSignatureObject.Game(); Gaseous_ROMSignatureObject.RomSignatureObject.Game gameObject = new Gaseous_ROMSignatureObject.RomSignatureObject.Game();
// parse game name // parse game name
string[] gameNameTitleParts = xmlGame.Attributes["name"].Value.Split("["); string[] gameNameTitleParts = xmlGame.Attributes["name"].Value.Split("[");
@@ -158,32 +158,32 @@ namespace gaseous_identifier.classes
// before split, save and remove the demo tag if present // before split, save and remove the demo tag if present
if (gameName.Contains("(demo) ", StringComparison.CurrentCulture)) if (gameName.Contains("(demo) ", StringComparison.CurrentCulture))
{ {
gameObject.Demo = objects.RomSignatureObject.Game.DemoTypes.demo; gameObject.Demo = Gaseous_ROMSignatureObject.RomSignatureObject.Game.DemoTypes.demo;
gameName = gameName.Replace("(demo) ", ""); gameName = gameName.Replace("(demo) ", "");
} }
else if (gameName.Contains("(demo-kiosk) ", StringComparison.CurrentCulture)) else if (gameName.Contains("(demo-kiosk) ", StringComparison.CurrentCulture))
{ {
gameObject.Demo = objects.RomSignatureObject.Game.DemoTypes.demo_kiosk; gameObject.Demo = Gaseous_ROMSignatureObject.RomSignatureObject.Game.DemoTypes.demo_kiosk;
gameName = gameName.Replace("(demo-kiosk) ", ""); gameName = gameName.Replace("(demo-kiosk) ", "");
} }
else if (gameName.Contains("(demo-playable) ", StringComparison.CurrentCulture)) else if (gameName.Contains("(demo-playable) ", StringComparison.CurrentCulture))
{ {
gameObject.Demo = objects.RomSignatureObject.Game.DemoTypes.demo_playable; gameObject.Demo = Gaseous_ROMSignatureObject.RomSignatureObject.Game.DemoTypes.demo_playable;
gameName = gameName.Replace("(demo-playable) ", ""); gameName = gameName.Replace("(demo-playable) ", "");
} }
else if (gameName.Contains("(demo-rolling) ", StringComparison.CurrentCulture)) else if (gameName.Contains("(demo-rolling) ", StringComparison.CurrentCulture))
{ {
gameObject.Demo = objects.RomSignatureObject.Game.DemoTypes.demo_rolling; gameObject.Demo = Gaseous_ROMSignatureObject.RomSignatureObject.Game.DemoTypes.demo_rolling;
gameName = gameName.Replace("(demo-rolling) ", ""); gameName = gameName.Replace("(demo-rolling) ", "");
} }
else if (gameName.Contains("(demo-slideshow) ", StringComparison.CurrentCulture)) else if (gameName.Contains("(demo-slideshow) ", StringComparison.CurrentCulture))
{ {
gameObject.Demo = objects.RomSignatureObject.Game.DemoTypes.demo_slideshow; gameObject.Demo = Gaseous_ROMSignatureObject.RomSignatureObject.Game.DemoTypes.demo_slideshow;
gameName = gameName.Replace("(demo-slideshow) ", ""); gameName = gameName.Replace("(demo-slideshow) ", "");
} }
else else
{ {
gameObject.Demo = objects.RomSignatureObject.Game.DemoTypes.NotDemo; gameObject.Demo = Gaseous_ROMSignatureObject.RomSignatureObject.Game.DemoTypes.NotDemo;
} }
string[] gameNameTokens = gameName.Split("("); string[] gameNameTokens = gameName.Split("(");
@@ -336,7 +336,7 @@ namespace gaseous_identifier.classes
StartToken += 1; StartToken += 1;
} }
gameObject.Roms = new List<objects.RomSignatureObject.Game.Rom>(); gameObject.Roms = new List<Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom>();
// get the roms // get the roms
string romDescription = ""; string romDescription = "";
@@ -349,7 +349,7 @@ namespace gaseous_identifier.classes
break; break;
case "rom": case "rom":
objects.RomSignatureObject.Game.Rom romObject = new objects.RomSignatureObject.Game.Rom(); Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom romObject = new Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom();
romObject.Name = xmlGameDetail.Attributes["name"]?.Value; romObject.Name = xmlGameDetail.Attributes["name"]?.Value;
romObject.Size = UInt64.Parse(xmlGameDetail.Attributes["size"]?.Value); romObject.Size = UInt64.Parse(xmlGameDetail.Attributes["size"]?.Value);
romObject.Crc = xmlGameDetail.Attributes["crc"]?.Value; romObject.Crc = xmlGameDetail.Attributes["crc"]?.Value;
@@ -382,22 +382,22 @@ namespace gaseous_identifier.classes
switch (tokens[0]) switch (tokens[0])
{ {
case "Disc": case "Disc":
romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Disc; romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Disc;
break; break;
case "Disk": case "Disk":
romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Disk; romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Disk;
break; break;
case "File": case "File":
romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.File; romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.File;
break; break;
case "Part": case "Part":
romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Part; romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Part;
break; break;
case "Side": case "Side":
romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Side; romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Side;
break; break;
case "Tape": case "Tape":
romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Tape; romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Tape;
break; break;
} }
romObject.RomTypeMedia = token; romObject.RomTypeMedia = token;
@@ -487,7 +487,7 @@ namespace gaseous_identifier.classes
// search for existing gameObject to update // search for existing gameObject to update
bool existingGameFound = false; bool existingGameFound = false;
foreach (gaseous_identifier.objects.RomSignatureObject.Game existingGame in tosecObject.Games) foreach (Gaseous_ROMSignatureObject.RomSignatureObject.Game existingGame in tosecObject.Games)
{ {
if (existingGame.Name == gameObject.Name && if (existingGame.Name == gameObject.Name &&
existingGame.Year == gameObject.Year && existingGame.Year == gameObject.Year &&

View File

@@ -50,7 +50,7 @@ foreach (string commandLineArg in commandLineArgs)
scanPath = Path.GetFullPath(scanPath); scanPath = Path.GetFullPath(scanPath);
Console.WriteLine("ROM search path: " + scanPath); Console.WriteLine("ROM search path: " + scanPath);
List<gaseous_identifier.objects.RomSignatureObject> romSignatures = new List<gaseous_identifier.objects.RomSignatureObject>(); List<Gaseous_ROMSignatureObject.RomSignatureObject> romSignatures = new List<Gaseous_ROMSignatureObject.RomSignatureObject>();
System.Collections.ArrayList availablePlatforms = new System.Collections.ArrayList(); System.Collections.ArrayList availablePlatforms = new System.Collections.ArrayList();
// load TOSEC XML files // load TOSEC XML files
@@ -67,13 +67,13 @@ if (tosecXML != null && tosecXML.Length > 0)
string tosecXMLFile = tosecPathContents[i]; string tosecXMLFile = tosecPathContents[i];
gaseous_identifier.classes.TosecParser tosecParser = new gaseous_identifier.classes.TosecParser(); gaseous_identifier.classes.TosecParser tosecParser = new gaseous_identifier.classes.TosecParser();
gaseous_identifier.objects.RomSignatureObject tosecObject = tosecParser.Parse(tosecXMLFile); Gaseous_ROMSignatureObject.RomSignatureObject tosecObject = tosecParser.Parse(tosecXMLFile);
string statusOutput = i + " / " + tosecPathContents.Length + " : " + Path.GetFileName(tosecXMLFile); string statusOutput = i + " / " + tosecPathContents.Length + " : " + Path.GetFileName(tosecXMLFile);
Console.Write("\r " + statusOutput.PadRight(lastCLILineLength, ' ') + "\r"); Console.Write("\r " + statusOutput.PadRight(lastCLILineLength, ' ') + "\r");
lastCLILineLength = statusOutput.Length; lastCLILineLength = statusOutput.Length;
foreach (gaseous_identifier.objects.RomSignatureObject.Game gameRom in tosecObject.Games) foreach (Gaseous_ROMSignatureObject.RomSignatureObject.Game gameRom in tosecObject.Games)
{ {
if (!availablePlatforms.Contains(gameRom.System)) if (!availablePlatforms.Contains(gameRom.System))
{ {
@@ -101,74 +101,74 @@ if (availablePlatforms.Count > 0)
} }
} }
//Console.WriteLine("Examining files"); Console.WriteLine("Examining files");
//string[] romPathContents = Directory.GetFiles(scanPath); string[] romPathContents = Directory.GetFiles(scanPath);
//foreach (string romFile in romPathContents) foreach (string romFile in romPathContents)
//{ {
// Console.WriteLine("Checking " + romFile); Console.WriteLine("Checking " + romFile);
// var stream = File.OpenRead(romFile); var stream = File.OpenRead(romFile);
// var md5 = MD5.Create(); var md5 = MD5.Create();
// byte[] md5HashByte = md5.ComputeHash(stream); byte[] md5HashByte = md5.ComputeHash(stream);
// string md5Hash = BitConverter.ToString(md5HashByte).Replace("-", "").ToLowerInvariant(); string md5Hash = BitConverter.ToString(md5HashByte).Replace("-", "").ToLowerInvariant();
// var sha1 = SHA1.Create(); var sha1 = SHA1.Create();
// byte[] sha1HashByte = sha1.ComputeHash(stream); byte[] sha1HashByte = sha1.ComputeHash(stream);
// string sha1Hash = BitConverter.ToString(sha1HashByte).Replace("-", "").ToLowerInvariant(); string sha1Hash = BitConverter.ToString(sha1HashByte).Replace("-", "").ToLowerInvariant();
// bool gameFound = false; bool gameFound = false;
// foreach (gaseous_identifier.objects.RomSignatureObject tosecList in romSignatures) foreach (Gaseous_ROMSignatureObject.RomSignatureObject tosecList in romSignatures)
// { {
// foreach (gaseous_identifier.objects.RomSignatureObject.Game gameObject in tosecList.Games) foreach (Gaseous_ROMSignatureObject.RomSignatureObject.Game gameObject in tosecList.Games)
// { {
// foreach (gaseous_identifier.objects.RomSignatureObject.Game.Rom romObject in gameObject.Roms) foreach (Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom romObject in gameObject.Roms)
// { {
// if (romObject.Md5 != null) if (romObject.Md5 != null)
// { {
// if (md5Hash == romObject.Md5.ToLowerInvariant()) if (md5Hash == romObject.Md5.ToLowerInvariant())
// { {
// // match // match
// gameFound = true; gameFound = true;
// } }
// } }
// if (romObject.Sha1 != null) if (romObject.Sha1 != null)
// { {
// if (md5Hash == romObject.Sha1.ToLowerInvariant()) if (md5Hash == romObject.Sha1.ToLowerInvariant())
// { {
// // match // match
// gameFound = true; gameFound = true;
// } }
// } }
// if (gameFound == true) if (gameFound == true)
// { {
// Console.WriteLine(romObject.Name); Console.WriteLine(romObject.Name);
// gaseous_identifier.objects.RomSignatureObject.Game gameSignature = gameObject; Gaseous_ROMSignatureObject.RomSignatureObject.Game gameSignature = gameObject;
// gameSignature.Roms.Clear(); gameSignature.Roms.Clear();
// gameSignature.Roms.Add(romObject); gameSignature.Roms.Add(romObject);
// var jsonSerializerSettings = new JsonSerializerSettings(); var jsonSerializerSettings = new JsonSerializerSettings();
// jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
// jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore; jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore;
// Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(gameSignature, Newtonsoft.Json.Formatting.Indented, jsonSerializerSettings)); Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(gameSignature, Newtonsoft.Json.Formatting.Indented, jsonSerializerSettings));
// break; break;
// } }
// } }
// if (gameFound == true) { break; } if (gameFound == true) { break; }
// } }
// if (gameFound == true) { break; } if (gameFound == true) { break; }
// } }
// if (gameFound == false) if (gameFound == false)
// { {
// Console.WriteLine("File not found in TOSEC library"); Console.WriteLine("File not found in TOSEC library");
// } }
//} }
string SearchTitle = "California Games"; string SearchTitle = "California Games";
foreach (gaseous_identifier.objects.RomSignatureObject romSignatureObject in romSignatures) foreach (Gaseous_ROMSignatureObject.RomSignatureObject romSignatureObject in romSignatures)
{ {
foreach (gaseous_identifier.objects.RomSignatureObject.Game gameObject in romSignatureObject.Games) foreach (Gaseous_ROMSignatureObject.RomSignatureObject.Game gameObject in romSignatureObject.Games)
{ {
if (gameObject.Name == SearchTitle) if (gameObject.Name == SearchTitle)
{ {

View File

@@ -20,12 +20,14 @@
<None Remove="Support\Parsers\TOSEC\Copyright.txt" /> <None Remove="Support\Parsers\TOSEC\Copyright.txt" />
<None Remove="Support\Parsers\TOSEC\DevelopmentStatus.txt" /> <None Remove="Support\Parsers\TOSEC\DevelopmentStatus.txt" />
<None Remove="Newtonsoft.Json" /> <None Remove="Newtonsoft.Json" />
<None Remove="Objects\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Classes\" /> <Folder Include="Classes\" />
<Folder Include="Support\" /> <Folder Include="Support\" />
<Folder Include="Support\Parsers\" /> <Folder Include="Support\Parsers\" />
<Folder Include="Support\Parsers\TOSEC\" /> <Folder Include="Support\Parsers\TOSEC\" />
<Folder Include="Objects\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Support\Parsers\TOSEC\Systems.txt" /> <EmbeddedResource Include="Support\Parsers\TOSEC\Systems.txt" />
@@ -38,4 +40,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RomSignatureObject\Gaseous-ROMSignatureObject\Gaseous-ROMSignatureObject.csproj" />
</ItemGroup>
</Project> </Project>