/// <summary> /// Output the stats for a list of input dats as files in a human-readable format /// </summary> /// <param name="stats">List of pre-calculated statistics objects</param> /// <param name="reportName">Name of the output file</param> /// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param> /// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param> /// <param name="statDatFormat"> Set the statistics output format to use</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> /// <returns>True if the report was written correctly, false otherwise</returns> public static bool Write( List <DatStatistics> stats, string reportName, string outDir, bool baddumpCol, bool nodumpCol, StatReportFormat statDatFormat, bool throwOnError = false) { // If there's no output format, set the default if (statDatFormat == StatReportFormat.None) { logger.Verbose("No report format defined, defaulting to textfile"); statDatFormat = StatReportFormat.Textfile; } // Get the proper output file name if (string.IsNullOrWhiteSpace(reportName)) { reportName = "report"; } // Get the proper output directory name outDir = outDir.Ensure(); InternalStopwatch watch = new InternalStopwatch($"Writing out report data to '{outDir}'"); // Get the dictionary of desired output report names Dictionary <StatReportFormat, string> outfiles = CreateOutStatsNames(outDir, statDatFormat, reportName); try { // Write out all required formats Parallel.ForEach(outfiles.Keys, Globals.ParallelOptions, reportFormat => { string outfile = outfiles[reportFormat]; try { BaseReport.Create(reportFormat, stats)?.WriteToFile(outfile, baddumpCol, nodumpCol, throwOnError); } catch (Exception ex) when(!throwOnError) { logger.Error(ex, $"Report '{outfile}' could not be written out"); } }); } catch (Exception ex) when(!throwOnError) { logger.Error(ex); return(false); } finally { watch.Stop(); } return(true); }
/// <summary> /// Write the stats out to console for the current DatFile /// </summary> /// <param name="datFile">Current DatFile object to write from</param> public static void WriteStatsToConsole(DatFile datFile) { if (datFile.Items.RomCount + datFile.Items.DiskCount == 0) { datFile.Items.RecalculateStats(); } datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); var statsList = new List <DatStatistics> { new DatStatistics { Statistics = datFile.Items, DisplayName = datFile.Header.FileName, MachineCount = datFile.Items.Keys.Count(), IsDirectory = false, }, }; var consoleOutput = BaseReport.Create(StatReportFormat.None, statsList); consoleOutput.WriteToFile(null, true, true); }