From b38efc3546306eaf83f56b25112916a84df32806 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 27 May 2016 09:28:33 -0700 Subject: [PATCH] Get framework for Stats into DATabase --- DATabase/DATabase.cs | 78 +++++++++++++++++++ DATabase/DATabase.csproj | 1 + .../UncompressedSize.cs | 69 ++++++++-------- UncompressedSize/UncompressedSize.csproj | 1 - 4 files changed, 117 insertions(+), 32 deletions(-) rename {UncompressedSize => DATabase}/UncompressedSize.cs (68%) diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index dc005e58..06e29434 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -693,6 +693,7 @@ Make a selection: 4) Merge, diff, and/or dedup 2 or more DAT files 5) Split DAT using 2 extensions 6) Split DATs by best available hash values + 7) Get statistics on a DAT or folder of DATs B) Go back to the previous menu "); Console.Write("Enter selection: "); @@ -717,6 +718,9 @@ Make a selection: case "6": HashSplitMenu(); break; + case "7": + StatsMenu(); + break; } } } @@ -1144,6 +1148,52 @@ Make a selection: } } + /// + /// Show the text-based Stats menu + /// + private static void StatsMenu() + { + string selection = "", input = ""; + bool single = false; + while (selection.ToLowerInvariant() != "b") + { + Console.Clear(); + Build.Start("DATabase"); + Console.WriteLine(@"STATISTICS MENU +=========================== +Make a selection: + + 1) File or folder to get stats on" + (input != "" ? ":\n\t" + input : "") + @" + 2) " + (single ? "Don't show individual DAT statistics" : "Show individual DAT statistics") + @" + 3) Get stats on the file(s) + B) Go back to the previous menu +"); + Console.Write("Enter selection: "); + selection = Console.ReadLine(); + switch (selection) + { + case "1": + Console.Clear(); + Console.Write("Please enter the file or folder name: "); + input = Console.ReadLine(); + break; + case "2": + single = !single; + break; + case "3": + Console.Clear(); + List inputs = new List(); + inputs.Add(input); + InitStats(inputs, single); + Console.Write("\nPress any key to continue..."); + Console.ReadKey(); + input = ""; + single = false; + break; + } + } + } + /// /// Show the text-based add and remove menu /// @@ -1655,6 +1705,34 @@ Make a selection: hs.Split(); } + /// + /// Wrap getting statistics on a DAT or folder of DATs + /// + /// List of inputs to be used + /// True to show individual DAT statistics, false otherwise + private static void InitStats(List inputs, bool single) + { + List newinputs = new List(); + + foreach (string input in inputs) + { + if (File.Exists(input.Replace("\"", ""))) + { + newinputs.Add(input.Replace("\"", "")); + } + if (Directory.Exists(input.Replace("\"", ""))) + { + foreach (string file in Directory.GetFiles(input.Replace("\"", ""), "*", SearchOption.AllDirectories)) + { + newinputs.Add(file.Replace("\"", "")); + } + } + } + + Stats stats = new Stats(inputs, single, logger); + stats.Process(); + } + /// /// Wrap adding a new source to the database /// diff --git a/DATabase/DATabase.csproj b/DATabase/DATabase.csproj index 6ea0bcf9..9c10a32e 100644 --- a/DATabase/DATabase.csproj +++ b/DATabase/DATabase.csproj @@ -112,6 +112,7 @@ + diff --git a/UncompressedSize/UncompressedSize.cs b/DATabase/UncompressedSize.cs similarity index 68% rename from UncompressedSize/UncompressedSize.cs rename to DATabase/UncompressedSize.cs index 3e6ec9a0..e55f1c46 100644 --- a/UncompressedSize/UncompressedSize.cs +++ b/DATabase/UncompressedSize.cs @@ -6,33 +6,36 @@ using SabreTools.Helper; namespace SabreTools { + /// + /// Get statistics on one or more DAT files + /// + /// Finish making this a proper object then port to DATabase (-st, --stats) public class UncompressedSize { - public static void Main(string[] args) + // Private instance variables + private List _inputs; + private bool _single; + private Logger _logger; + + /// + /// Create a new UncompressedSize object + /// + /// List of files and folders to parse + /// True if single DAT stats are output, false otherwise + /// Logger object for file and console output + public UncompressedSize(List inputs, bool single, Logger logger) { - Console.Clear(); - Build.Start("UncompressedSize"); - - List inputs = new List(); - - foreach (string arg in args) - { - if (File.Exists(arg.Replace("\"", ""))) - { - inputs.Add(arg.Replace("\"", "")); - } - if (Directory.Exists(arg.Replace("\"", ""))) - { - foreach (string file in Directory.GetFiles(arg.Replace("\"", ""), "*", SearchOption.AllDirectories)) - { - inputs.Add(file.Replace("\"", "")); - } - } - } - - Logger logger = new Logger(true, "uncompressedsize.log"); - logger.Start(); + _inputs = inputs; + _single = single; + _logger = logger; + } + /// + /// Output all requested statistics + /// + /// True if output succeeded, false otherwise + public bool Process() + { // Init all single-dat variables long singleSize = 0; long singleGame = 0; @@ -53,13 +56,13 @@ namespace SabreTools long totalSHA1 = 0; long totalNodump = 0; - - foreach (string filename in inputs) + /// Now process each of the input files + foreach (string filename in _inputs) { List games = new List(); DatData datdata = new DatData(); - datdata = RomManipulation.Parse(filename, 0, 0, datdata, logger); + datdata = RomManipulation.Parse(filename, 0, 0, datdata, _logger); foreach (List romlist in datdata.Roms.Values) { foreach (RomData rom in romlist) @@ -97,8 +100,10 @@ namespace SabreTools } } - // Output single DAT stats - logger.User(@"For file '" + filename + @"': + // Output single DAT stats (if asked) + if (_single) + { + _logger.User(@"For file '" + filename + @"': -------------------------------------------------- Uncompressed size: " + Style.GetBytesReadable(singleSize) + @" Games found: " + singleGame + @" @@ -109,6 +114,7 @@ namespace SabreTools Roms with SHA-1: " + singleSHA1 + @" Roms with Nodump status: " + singleNodump + @" "); + } // Add single DAT stats to totals totalSize += singleSize; @@ -132,7 +138,7 @@ namespace SabreTools } // Output total DAT stats - logger.User(@"For ALL DATs found + _logger.User(@"For ALL DATs found -------------------------------------------------- Uncompressed size: " + Style.GetBytesReadable(totalSize) + @" Games found: " + totalGame + @" @@ -143,8 +149,9 @@ namespace SabreTools Roms with SHA-1: " + totalSHA1 + @" Roms with Nodump status: " + totalNodump + @" -For all individual stats, check the log folder for a complete list"); - logger.Close(); +Please check the log folder if the stats scrolled offscreen"); + + return true; } } } diff --git a/UncompressedSize/UncompressedSize.csproj b/UncompressedSize/UncompressedSize.csproj index 2b9c673a..777a5196 100644 --- a/UncompressedSize/UncompressedSize.csproj +++ b/UncompressedSize/UncompressedSize.csproj @@ -63,7 +63,6 @@ -