// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Data; namespace Spludlow.Mame { public class MameVerify { public static string VerifyMachineRom() { MameHashStores mameHashStores = new MameHashStores(); return ReportValidateHashStore(mameHashStores.MachineRom, "Verify Machine Rom", 1000); } public static string VerifyMachineDisk() { MameHashStores mameHashStores = new MameHashStores(); return ReportValidateHashStoreDiskVerify(mameHashStores.MachineDisk, "Verify Machine Disk", 10); } public static string CheckMachineDisk() { MameHashStores mameHashStores = new MameHashStores(); return ReportValidateHashStore(mameHashStores.MachineDisk, "Check Machine Disk", 10); } public static string VerifySoftwareRom() { MameHashStores mameHashStores = new MameHashStores(); return ReportValidateHashStore(mameHashStores.SoftwareRom, "Verify Software Rom", 1000); } public static string VerifySoftwareDisk() { MameHashStores mameHashStores = new MameHashStores(); return ReportValidateHashStoreDiskVerify(mameHashStores.SoftwareDisk, "Verify Software Disk", 10); } public static string CheckSoftwareDisk() { MameHashStores mameHashStores = new MameHashStores(); return ReportValidateHashStore(mameHashStores.SoftwareDisk, "Check Software Disk", 10); } public static string ReportValidateHashStore(HashStore hashStore, string subject, int progressSize) { DataTable table = ValidateHashStore(hashStore, progressSize); MameReport.Report(subject, table); DataView view = new DataView(table); view.RowFilter = "Problems <> ''"; return subject + ", total " + hashStore.Length + ", " + (view.Count == 0 ? "All good" : "bad count: " + view.Count); } private static DataTable ValidateHashStore(HashStore hashStore, int progressSize) { DataTable table = Spludlow.Data.TextTable.ReadText(new string[] { "Filename Problems", "String String", }); int count = 0; foreach (string filename in hashStore.FileNames()) { if (count % progressSize == 0) Console.WriteLine(count + " / " + hashStore.Length); ++count; DataRow row = table.Rows.Add(filename, ""); try { string storeHash = Path.GetFileNameWithoutExtension(filename); string actualHash = hashStore.Hash(filename); if (storeHash != actualHash) throw new ApplicationException(actualHash); } catch (Exception ee) { row["Problems"] = ee.Message; } } return table; } public static string ReportValidateHashStoreDiskVerify(HashStore hashStore, string subject, int progressSize) { DataTable table = ValidateHashStoreDiskVerify(hashStore, progressSize); MameReport.Report(subject, table); DataView view = new DataView(table); view.RowFilter = "Problems <> ''"; return subject + ", total " + hashStore.Length + ", " + (view.Count == 0 ? "All good" : "bad count: " + view.Count); } private static DataTable ValidateHashStoreDiskVerify(HashStore hashStore, int progressSize) { MameChdMan chdMan = new MameChdMan(); DataTable table = Spludlow.Data.TextTable.ReadText(new string[] { "Filename Problems", "String String", }); int count = 0; foreach (string filename in hashStore.FileNames()) { if (count % progressSize == 0) Console.WriteLine(count + " / " + hashStore.Length); ++count; DataRow row = table.Rows.Add(filename, ""); try { string storeHash = Path.GetFileNameWithoutExtension(filename); string actualHash = hashStore.Hash(filename); if (storeHash != actualHash) throw new ApplicationException(actualHash); if (chdMan.Verify(filename) == false) throw new ApplicationException("CHD Failed Verify"); } catch (Exception ee) { row["Problems"] = ee.Message; } } return table; } } }