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

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