// 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.Data; namespace Spludlow.Mame { public class MameClean { public static string CleanAll() { StringBuilder text = new StringBuilder(); text.AppendLine(CleanMachineRom()); text.AppendLine(CleanMachineDisk()); text.AppendLine(CleanSoftwareRom()); text.AppendLine(CleanSoftwareDisk()); return text.ToString(); } public static string CleanMachineRom() { MameHashStores mameHashStores = new MameHashStores(); HashStore hashStore = mameHashStores.MachineRom; HashSet databaseHashes = MameDatabase.MachineRomHashes(); return Clean("Clean Machine Rom", hashStore, databaseHashes); } public static string CleanMachineDisk() { MameHashStores mameHashStores = new MameHashStores(); HashStore hashStore = mameHashStores.MachineDisk; HashSet databaseHashes = MameDatabase.MachineDiskHashes(); return Clean("Clean Machine Disk", hashStore, databaseHashes); } public static string CleanSoftwareRom() { MameHashStores mameHashStores = new MameHashStores(); HashStore hashStore = mameHashStores.SoftwareRom; HashSet databaseHashes = MameDatabase.SoftwareRomHashes(); return Clean("Clean Software Rom", hashStore, databaseHashes); } public static string CleanSoftwareDisk() { MameHashStores mameHashStores = new MameHashStores(); HashStore hashStore = mameHashStores.SoftwareDisk; HashSet databaseHashes = MameDatabase.SoftwareDiskHashes(); return Clean("Clean Software Disk", hashStore, databaseHashes); } private static string Clean(string title, HashStore hashStore, HashSet databaseHashes) { string[] unusedHashes = MameReports.UnusedHashes(hashStore, databaseHashes); if (unusedHashes.Length > 0) { DataTable table = new DataTable(); table.Columns.Add("SHA1", typeof(string)); foreach (string sha1 in unusedHashes) { hashStore.Delete(sha1); table.Rows.Add(sha1); } MameReport.Report(title, table); } return title + (unusedHashes.Length == 0 ? ", already clean." : ", removed unused from hash store: " + unusedHashes.Length); } } }