Get framework for Stats into DATabase

This commit is contained in:
Matt Nadareski
2016-05-27 09:28:33 -07:00
parent 2c004de29e
commit b38efc3546
4 changed files with 117 additions and 32 deletions

View File

@@ -693,6 +693,7 @@ Make a selection:
4) Merge, diff, and/or dedup 2 or more DAT files 4) Merge, diff, and/or dedup 2 or more DAT files
5) Split DAT using 2 extensions 5) Split DAT using 2 extensions
6) Split DATs by best available hash values 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 B) Go back to the previous menu
"); ");
Console.Write("Enter selection: "); Console.Write("Enter selection: ");
@@ -717,6 +718,9 @@ Make a selection:
case "6": case "6":
HashSplitMenu(); HashSplitMenu();
break; break;
case "7":
StatsMenu();
break;
} }
} }
} }
@@ -1144,6 +1148,52 @@ Make a selection:
} }
} }
/// <summary>
/// Show the text-based Stats menu
/// </summary>
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<string> inputs = new List<string>();
inputs.Add(input);
InitStats(inputs, single);
Console.Write("\nPress any key to continue...");
Console.ReadKey();
input = "";
single = false;
break;
}
}
}
/// <summary> /// <summary>
/// Show the text-based add and remove menu /// Show the text-based add and remove menu
/// </summary> /// </summary>
@@ -1655,6 +1705,34 @@ Make a selection:
hs.Split(); hs.Split();
} }
/// <summary>
/// Wrap getting statistics on a DAT or folder of DATs
/// </summary>
/// <param name="inputs">List of inputs to be used</param>
/// <param name="single">True to show individual DAT statistics, false otherwise</param>
private static void InitStats(List<string> inputs, bool single)
{
List<string> newinputs = new List<string>();
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();
}
/// <summary> /// <summary>
/// Wrap adding a new source to the database /// Wrap adding a new source to the database
/// </summary> /// </summary>

View File

@@ -112,6 +112,7 @@
<Compile Include="MergeDiff.cs" /> <Compile Include="MergeDiff.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TrimMerge.cs" /> <Compile Include="TrimMerge.cs" />
<Compile Include="UncompressedSize.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />

View File

@@ -6,33 +6,36 @@ using SabreTools.Helper;
namespace SabreTools namespace SabreTools
{ {
/// <summary>
/// Get statistics on one or more DAT files
/// </summary>
/// <remarks>Finish making this a proper object then port to DATabase (-st, --stats)</remarks>
public class UncompressedSize public class UncompressedSize
{ {
public static void Main(string[] args) // Private instance variables
private List<String> _inputs;
private bool _single;
private Logger _logger;
/// <summary>
/// Create a new UncompressedSize object
/// </summary>
/// <param name="inputs">List of files and folders to parse</param>
/// <param name="single">True if single DAT stats are output, false otherwise</param>
/// <param name="logger">Logger object for file and console output</param>
public UncompressedSize(List<String> inputs, bool single, Logger logger)
{ {
Console.Clear(); _inputs = inputs;
Build.Start("UncompressedSize"); _single = single;
_logger = logger;
List<string> inputs = new List<string>(); }
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();
/// <summary>
/// Output all requested statistics
/// </summary>
/// <returns>True if output succeeded, false otherwise</returns>
public bool Process()
{
// Init all single-dat variables // Init all single-dat variables
long singleSize = 0; long singleSize = 0;
long singleGame = 0; long singleGame = 0;
@@ -53,13 +56,13 @@ namespace SabreTools
long totalSHA1 = 0; long totalSHA1 = 0;
long totalNodump = 0; long totalNodump = 0;
/// Now process each of the input files
foreach (string filename in inputs) foreach (string filename in _inputs)
{ {
List<String> games = new List<String>(); List<String> games = new List<String>();
DatData datdata = new DatData(); DatData datdata = new DatData();
datdata = RomManipulation.Parse(filename, 0, 0, datdata, logger); datdata = RomManipulation.Parse(filename, 0, 0, datdata, _logger);
foreach (List<RomData> romlist in datdata.Roms.Values) foreach (List<RomData> romlist in datdata.Roms.Values)
{ {
foreach (RomData rom in romlist) foreach (RomData rom in romlist)
@@ -97,8 +100,10 @@ namespace SabreTools
} }
} }
// Output single DAT stats // Output single DAT stats (if asked)
logger.User(@"For file '" + filename + @"': if (_single)
{
_logger.User(@"For file '" + filename + @"':
-------------------------------------------------- --------------------------------------------------
Uncompressed size: " + Style.GetBytesReadable(singleSize) + @" Uncompressed size: " + Style.GetBytesReadable(singleSize) + @"
Games found: " + singleGame + @" Games found: " + singleGame + @"
@@ -109,6 +114,7 @@ namespace SabreTools
Roms with SHA-1: " + singleSHA1 + @" Roms with SHA-1: " + singleSHA1 + @"
Roms with Nodump status: " + singleNodump + @" Roms with Nodump status: " + singleNodump + @"
"); ");
}
// Add single DAT stats to totals // Add single DAT stats to totals
totalSize += singleSize; totalSize += singleSize;
@@ -132,7 +138,7 @@ namespace SabreTools
} }
// Output total DAT stats // Output total DAT stats
logger.User(@"For ALL DATs found _logger.User(@"For ALL DATs found
-------------------------------------------------- --------------------------------------------------
Uncompressed size: " + Style.GetBytesReadable(totalSize) + @" Uncompressed size: " + Style.GetBytesReadable(totalSize) + @"
Games found: " + totalGame + @" Games found: " + totalGame + @"
@@ -143,8 +149,9 @@ namespace SabreTools
Roms with SHA-1: " + totalSHA1 + @" Roms with SHA-1: " + totalSHA1 + @"
Roms with Nodump status: " + totalNodump + @" Roms with Nodump status: " + totalNodump + @"
For all individual stats, check the log folder for a complete list"); Please check the log folder if the stats scrolled offscreen");
logger.Close();
return true;
} }
} }
} }

View File

@@ -63,7 +63,6 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="UncompressedSize.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>