[DatFile, Logger] Update stats output, fix parsing with percieved flags; fix log command line

This commit is contained in:
Matt Nadareski
2016-09-23 15:22:58 -07:00
parent 8a39d398a4
commit 95193effbe
4 changed files with 20 additions and 43 deletions

View File

@@ -1379,17 +1379,6 @@ namespace SabreTools.Helper
continue; continue;
} }
// Special cases for item statuses // Special cases for item statuses
else if (gc[i] == "good" && attrib != "status" && attrib != "flags")
{
if (item.Type == ItemType.Rom)
{
((Rom)item).ItemStatus = ItemStatus.Good;
}
else if (item.Type == ItemType.Disk)
{
((Disk)item).ItemStatus = ItemStatus.Good;
}
}
else if (gc[i] == "baddump" && attrib != "status" && attrib != "flags") else if (gc[i] == "baddump" && attrib != "status" && attrib != "flags")
{ {
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
@@ -1412,17 +1401,6 @@ namespace SabreTools.Helper
((Disk)item).ItemStatus = ItemStatus.Nodump; ((Disk)item).ItemStatus = ItemStatus.Nodump;
} }
} }
else if (gc[i] == "verified" && attrib != "status" && attrib != "flags")
{
if (item.Type == ItemType.Rom)
{
((Rom)item).ItemStatus = ItemStatus.Verified;
}
else if (item.Type == ItemType.Disk)
{
((Disk)item).ItemStatus = ItemStatus.Verified;
}
}
// Even number of quotes, not in a quote, not in attribute // Even number of quotes, not in a quote, not in attribute
else if (Regex.Matches(gc[i], "\"").Count % 2 == 0 && !quote && attrib == "") else if (Regex.Matches(gc[i], "\"").Count % 2 == 0 && !quote && attrib == "")
{ {
@@ -3023,7 +3001,7 @@ namespace SabreTools.Helper
// Output initial statistics, for kicks // Output initial statistics, for kicks
if (stats) if (stats)
{ {
OutputStats(logger, (RomCount + DiskCount == 0)); OutputStats(logger, logger, (RomCount + DiskCount == 0));
} }
// Bucket roms by game name and optionally dedupe // Bucket roms by game name and optionally dedupe
@@ -4356,9 +4334,10 @@ namespace SabreTools.Helper
/// Output the stats for the Dat in a human-readable format /// Output the stats for the Dat in a human-readable format
/// </summary> /// </summary>
/// <param name="logger">Logger object for file and console writing</param> /// <param name="logger">Logger object for file and console writing</param>
/// <param name="statLogger">Logger object for file and console output (statistics)</param>
/// <param name="recalculate">True if numbers should be recalculated for the DAT, false otherwise (default)</param> /// <param name="recalculate">True if numbers should be recalculated for the DAT, false otherwise (default)</param>
/// <param name="game">Number of games to use, -1 means recalculate games (default)</param> /// <param name="game">Number of games to use, -1 means recalculate games (default)</param>
public void OutputStats(Logger logger, bool recalculate = false, long game = -1) public void OutputStats(Logger logger, Logger statLogger, bool recalculate = false, long game = -1)
{ {
// If we're supposed to recalculate the statistics, do so // If we're supposed to recalculate the statistics, do so
if (recalculate) if (recalculate)
@@ -4371,7 +4350,7 @@ namespace SabreTools.Helper
{ {
TotalSize = Int64.MaxValue + TotalSize; TotalSize = Int64.MaxValue + TotalSize;
} }
logger.User(" Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @" statLogger.User(" Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @"
Games found: " + (game == -1 ? Files.Count : game) + @" Games found: " + (game == -1 ? Files.Count : game) + @"
Roms found: " + RomCount + @" Roms found: " + RomCount + @"
Disks found: " + DiskCount + @" Disks found: " + DiskCount + @"
@@ -4379,7 +4358,7 @@ namespace SabreTools.Helper
Roms with MD5: " + MD5Count + @" Roms with MD5: " + MD5Count + @"
Roms with SHA-1: " + SHA1Count + @" Roms with SHA-1: " + SHA1Count + @"
Roms with Nodump status: " + NodumpCount + @" Roms with Nodump status: " + NodumpCount + @"
"); ", false);
} }
#endregion #endregion
@@ -5046,7 +5025,8 @@ namespace SabreTools.Helper
/// <param name="inputs">List of input files and folders</param> /// <param name="inputs">List of input files and folders</param>
/// <param name="single">True if single DAT stats are output, false otherwise</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> /// <param name="logger">Logger object for file and console output</param>
public static void OutputStats(List<string> inputs, bool single, Logger logger) /// <param name="statLogger">Logger object for file and console output (statistics)</param>
public static void OutputStats(List<string> inputs, bool single, Logger logger, Logger statLogger)
{ {
// Make sure we have all files // Make sure we have all files
List<string> newinputs = new List<string>(); List<string> newinputs = new List<string>();
@@ -5078,7 +5058,7 @@ namespace SabreTools.Helper
/// Now process each of the input files /// Now process each of the input files
foreach (string filename in newinputs) foreach (string filename in newinputs)
{ {
logger.Verbose("Beginning stat collection for '" + filename + "'"); logger.Verbose("Beginning stat collection for '" + filename + "'", false);
List<string> games = new List<string>(); List<string> games = new List<string>();
DatFile datdata = new DatFile(); DatFile datdata = new DatFile();
datdata.Parse(filename, 0, 0, logger); datdata.Parse(filename, 0, 0, logger);
@@ -5087,13 +5067,13 @@ namespace SabreTools.Helper
// Output single DAT stats (if asked) // Output single DAT stats (if asked)
if (single) if (single)
{ {
logger.User(@"\nFor file '" + filename + @"': statLogger.User(@"\nFor file '" + filename + @"':
--------------------------------------------------"); --------------------------------------------------", false);
datdata.OutputStats(logger); datdata.OutputStats(logger, statLogger);
} }
else else
{ {
logger.User("Adding stats for file '" + filename + "'\n"); logger.User("Adding stats for file '" + filename + "'\n", false);
} }
// Add single DAT stats to totals // Add single DAT stats to totals
@@ -5108,7 +5088,7 @@ namespace SabreTools.Helper
} }
// Output total DAT stats // Output total DAT stats
if (!single) { logger.User(""); } if (!single) { logger.User("", false); }
DatFile totaldata = new DatFile DatFile totaldata = new DatFile
{ {
TotalSize = totalSize, TotalSize = totalSize,
@@ -5119,11 +5099,11 @@ namespace SabreTools.Helper
SHA1Count = totalSHA1, SHA1Count = totalSHA1,
NodumpCount = totalNodump, NodumpCount = totalNodump,
}; };
logger.User(@"For ALL DATs found statLogger.User(@"For ALL DATs found
--------------------------------------------------"); --------------------------------------------------", false);
totaldata.OutputStats(logger, game: totalGame); totaldata.OutputStats(logger, statLogger, game: totalGame);
logger.User(@" logger.User(@"
Please check the log folder if the stats scrolled offscreen"); Please check the log folder if the stats scrolled offscreen", false);
} }
#endregion #endregion

View File

@@ -57,7 +57,7 @@ namespace SabreTools.Helper
{ {
_log = new StreamWriter(File.Open(_basepath + _filename, FileMode.OpenOrCreate | FileMode.Append)); _log = new StreamWriter(File.Open(_basepath + _filename, FileMode.OpenOrCreate | FileMode.Append));
_log.WriteLine("Logging started " + DateTime.Now); _log.WriteLine("Logging started " + DateTime.Now);
_log.WriteLine(GetCommandLine()); _log.WriteLine(Environment.CommandLine);
_log.Flush(); _log.Flush();
} }
catch catch
@@ -245,8 +245,5 @@ namespace SabreTools.Helper
} }
return true; return true;
} }
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern System.IntPtr GetCommandLine();
} }
} }

View File

@@ -262,7 +262,7 @@ namespace SabreTools.Helper
_logger.ClearBeneath(Constants.HeaderHeight); _logger.ClearBeneath(Constants.HeaderHeight);
Console.SetCursorPosition(0, Constants.HeaderHeight + 1); Console.SetCursorPosition(0, Constants.HeaderHeight + 1);
_logger.User("Stats of the matched ROMs:"); _logger.User("Stats of the matched ROMs:");
_matched.OutputStats(_logger, true); _matched.OutputStats(_logger, _logger, true);
// Now output the fixdat based on the original input if asked // Now output the fixdat based on the original input if asked
if (_updateDat) if (_updateDat)

View File

@@ -288,7 +288,7 @@ namespace SabreTools
private static void InitStats(List<string> inputs, bool single) private static void InitStats(List<string> inputs, bool single)
{ {
Logger statlog = new Logger(true, "stats.txt"); Logger statlog = new Logger(true, "stats.txt");
DatFile.OutputStats(inputs, single, statlog); DatFile.OutputStats(inputs, single, _logger, statlog);
statlog.Close(true); statlog.Close(true);
} }