diff --git a/gaseous-identifier/Classes/TosecParser.cs b/gaseous-identifier/Classes/TosecParser.cs index b4e1a9c..f6ea727 100644 --- a/gaseous-identifier/Classes/TosecParser.cs +++ b/gaseous-identifier/Classes/TosecParser.cs @@ -8,7 +8,7 @@ namespace gaseous_identifier.classes { public class TosecParser { - public objects.RomSignatureObject Parse(string XMLFile) + public Gaseous_ROMSignatureObject.RomSignatureObject Parse(string XMLFile) { // load resources var assembly = Assembly.GetExecutingAssembly(); @@ -92,7 +92,7 @@ namespace gaseous_identifier.classes XmlDocument tosecXmlDoc = new XmlDocument(); tosecXmlDoc.Load(XMLFile); - objects.RomSignatureObject tosecObject = new objects.RomSignatureObject(); + Gaseous_ROMSignatureObject.RomSignatureObject tosecObject = new Gaseous_ROMSignatureObject.RomSignatureObject(); // get header XmlNode xmlHeader = tosecXmlDoc.DocumentElement.SelectSingleNode("/datafile/header"); @@ -145,11 +145,11 @@ namespace gaseous_identifier.classes } // get games - tosecObject.Games = new List(); + tosecObject.Games = new List(); XmlNodeList xmlGames = tosecXmlDoc.DocumentElement.SelectNodes("/datafile/game"); 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 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 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) ", ""); } 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) ", ""); } 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) ", ""); } 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) ", ""); } 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) ", ""); } else { - gameObject.Demo = objects.RomSignatureObject.Game.DemoTypes.NotDemo; + gameObject.Demo = Gaseous_ROMSignatureObject.RomSignatureObject.Game.DemoTypes.NotDemo; } string[] gameNameTokens = gameName.Split("("); @@ -336,7 +336,7 @@ namespace gaseous_identifier.classes StartToken += 1; } - gameObject.Roms = new List(); + gameObject.Roms = new List(); // get the roms string romDescription = ""; @@ -349,7 +349,7 @@ namespace gaseous_identifier.classes break; 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.Size = UInt64.Parse(xmlGameDetail.Attributes["size"]?.Value); romObject.Crc = xmlGameDetail.Attributes["crc"]?.Value; @@ -382,22 +382,22 @@ namespace gaseous_identifier.classes switch (tokens[0]) { case "Disc": - romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Disc; + romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Disc; break; case "Disk": - romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Disk; + romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Disk; break; case "File": - romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.File; + romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.File; break; case "Part": - romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Part; + romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Part; break; case "Side": - romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Side; + romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Side; break; case "Tape": - romObject.RomType = objects.RomSignatureObject.Game.Rom.RomTypes.Tape; + romObject.RomType = Gaseous_ROMSignatureObject.RomSignatureObject.Game.Rom.RomTypes.Tape; break; } romObject.RomTypeMedia = token; @@ -487,7 +487,7 @@ namespace gaseous_identifier.classes // search for existing gameObject to update 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 && existingGame.Year == gameObject.Year && diff --git a/gaseous-identifier/Program.cs b/gaseous-identifier/Program.cs index 0f5b344..4430fdd 100644 --- a/gaseous-identifier/Program.cs +++ b/gaseous-identifier/Program.cs @@ -50,7 +50,7 @@ foreach (string commandLineArg in commandLineArgs) scanPath = Path.GetFullPath(scanPath); Console.WriteLine("ROM search path: " + scanPath); -List romSignatures = new List(); +List romSignatures = new List(); 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) { diff --git a/gaseous-identifier/gaseous-identifier.csproj b/gaseous-identifier/gaseous-identifier.csproj index 4b0419b..dbee03d 100644 --- a/gaseous-identifier/gaseous-identifier.csproj +++ b/gaseous-identifier/gaseous-identifier.csproj @@ -20,12 +20,14 @@ + + @@ -38,4 +40,7 @@ + + +