// 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; using System.IO; namespace Spludlow.Mame { public class MameReport { private static readonly string Style = "body {" + " font-family: sans-serif;" + " font-size: small;" + " background-color: #c6eafb;" + "}" + "hr {" + " color: #00ADEF;" + " background-color: #00ADEF;" + " height: 6px;" + " border: none;" + " padding-left: 0px;" + "}" + "table {" + " border-collapse: collapse;" + "}" + "th, td {" + " padding: 2px;" + " text-align: left;" + "}" + "table, th, td {" + " border: 1px solid black;" + "}" + "th {" + " background-color: #00ADEF;" + " color: white;" + "}" + "tr:nth-child(even) {" + " background-color: #b6daeb;" + "}" + ""; public static void Report(string title, DataTable table) { if (table.DataSet == null) { DataSet dataSet = new DataSet(); dataSet.Tables.Add(table); } Report(title, table.DataSet); } public static void Report(string title, DataSet dataSet) { // If running Spludlow Spludlow.Log.Report(title, dataSet); MameConfiguration config = new MameConfiguration(); string name = Spludlow.Text.TimeStamp() + "_" + title; StringBuilder html = new StringBuilder(); html.AppendLine(""); html.AppendLine(""); html.AppendLine(""); html.AppendLine(""); html.AppendLine("MHS • " + title + ""); html.AppendLine(""); html.AppendLine(""); html.AppendLine("

MHS • " + title + "

"); for (int index = 0; index < dataSet.Tables.Count; ++index) { DataTable table = dataSet.Tables[index]; html.AppendLine("
"); if (table.TableName.StartsWith("Table") == false) html.AppendLine("

" + table.TableName + "

"); html.AppendLine(Spludlow.HTML.MakeTable(table, "width:100%;")); string textTableFilename = config.ReportDirectory + @"\" + name + "_" + index.ToString("00") + "_" + table.TableName + ".txt"; Spludlow.Data.TextTable.Write(textTableFilename, table, Encoding.UTF8); } html.AppendLine("
"); html.AppendLine("

" + name + "Spludlow MAME Hash Store

"); html.AppendLine(""); string filename = config.ReportDirectory + @"\" + name + ".htm"; File.WriteAllText(filename, html.ToString(), Encoding.UTF8); } /// /// Recursively traverse ancestors to add sha1s to the HashSet /// Compare to merge being set !!! /// private static int CheckParents(int count, DataRow machineRow, HashSet parentHashes, DataTable romTable) { if (machineRow.IsNull("romof") == true) return count; string name = (string)machineRow["name"]; string parent = (string)machineRow["romof"]; DataTable table = machineRow.Table; DataRow[] rows = table.Select("name = '" + parent + "'"); if (rows.Length != 1) throw new ApplicationException("CheckParentrs: " + name + ", parent:" + parent); DataRow[] romRows = romTable.Select("machine_id = " + rows[0]["machine_id"]); foreach (DataRow romRow in romRows) { if (romRow.IsNull("sha1") == true) continue; string sha1 = ((string)romRow["sha1"]).ToUpper(); if (parentHashes.Contains(sha1) == false) parentHashes.Add(sha1); } return CheckParents(++count, rows[0], parentHashes, romTable); } } }