using System; using System.Globalization; using System.IO; using System.Xml; using System.Xml.Linq; using System.Collections.Generic; using System.Linq; using System.Text; using BizHawk.Common; using BizHawk.Emulation.DiscSystem; namespace BizHawk.Client.DBMan { class PsxDBJob { class HashRecord { public string name, bizhash, datahash; public bool matched; } public void Run(string[] args) { string fpHash = null, fpRedump = null, fpOutfile = null; for (int i = 0; ; ) { if (i == args.Length) break; var arg = args[i++]; if (arg == "--hashes") fpHash = args[i++]; if (arg == "--redump") fpRedump = args[i++]; if (arg == "--outfile") fpOutfile = args[i++]; } var hashes = new Dictionary(); Console.WriteLine("Loading redump data"); RedumpPSX rdpsx = new RedumpPSX(); rdpsx.Load(fpRedump); Console.WriteLine("Loading hash data"); var splitSlashes = new string[]{"//"}; foreach (var line in File.ReadAllLines(fpHash)) { var parts = line.Split(splitSlashes, StringSplitOptions.None); var hr = new HashRecord() { name = parts[1], bizhash = parts[0].Substring(8, 8), datahash = parts[0].Substring(26, 8), }; hashes[hr.datahash] = hr; } Console.WriteLine("merging"); foreach (var rr in rdpsx.Records) { HashRecord hr; if (!hashes.TryGetValue(rr.crc, out hr)) continue; hr.matched = true; //correct name to redump current hr.name = rr.name; } Console.WriteLine("writing results"); using (var outf = new StreamWriter(fpOutfile)) { foreach (var hr in hashes.Values) { if (!hr.matched) continue; outf.WriteLine("{0}\tG\t{1}\tPSX\t\tdh={2}", hr.bizhash, hr.name, hr.datahash); } } } } class RedumpPSX { public class RedumpRecord { public string name; public string crc; } public List Records = new List(); public void Load(string datpath) { var xd = XDocument.Load(datpath); Dictionary knownHashes = new Dictionary(); var games = xd.Root.Descendants("game").ToArray(); for(int i=0;i