diff --git a/SabreTools.Helper/Logger.cs b/SabreTools.Helper/Logger.cs index fb96589e..4d1e702a 100644 --- a/SabreTools.Helper/Logger.cs +++ b/SabreTools.Helper/Logger.cs @@ -137,7 +137,8 @@ namespace SabreTools.Helper // USER and ERROR writes to console if (loglevel == LogLevel.USER || loglevel == LogLevel.ERROR) { - int padlength = (int)(Math.Ceiling((double)output.Length / 80) * 80) - 1; + int padlength = (int)(Math.Ceiling((double)output.Length / 80) * 80); + padlength = (padlength > 0 ? padlength: 0); string tempoutput = output.PadRight(padlength, ' '); Console.WriteLine((loglevel == LogLevel.ERROR ? loglevel.ToString() + " " : "") + tempoutput); } @@ -178,6 +179,7 @@ namespace SabreTools.Helper // Write out to the console int padlength = (int)(Math.Ceiling((double)output.Length / 80) * 80) - 1; + padlength = (padlength > 0 ? padlength : 0); string tempoutput = output.PadRight(padlength, ' '); Console.Write(tempoutput); @@ -228,5 +230,22 @@ namespace SabreTools.Helper { return Log(output, LogLevel.ERROR); } + + /// + /// Clear lines beneath the given line in the console + /// + /// Line number to clear beneath + /// True + public bool ClearBeneath(int line) + { + if (!Console.IsOutputRedirected) + { + for (int i = line; i < Console.WindowHeight; i++) + { + Log(" ", i, 0); + } + } + return true; + } } } diff --git a/SabreTools.Helper/Skippers.cs b/SabreTools.Helper/Skippers.cs index 98f7d58b..523c830b 100644 --- a/SabreTools.Helper/Skippers.cs +++ b/SabreTools.Helper/Skippers.cs @@ -464,7 +464,7 @@ namespace SabreTools.Helper // If we still have a success, then return this rule if (success) { - logger.User("Matching rule found!"); + logger.User(" Matching rule found!"); skipperRule = rule; break; } diff --git a/SabreTools.Helper/Tools/DatTools.cs b/SabreTools.Helper/Tools/DatTools.cs index 859de421..bf22367f 100644 --- a/SabreTools.Helper/Tools/DatTools.cs +++ b/SabreTools.Helper/Tools/DatTools.cs @@ -1476,7 +1476,7 @@ namespace SabreTools.Helper foreach (Rom rom in newroms) { count++; - string key = rom.Size + "-" + rom.CRC; ; + string key = rom.Size + "-" + rom.CRC; if (sortable.ContainsKey(key)) { sortable[key].Add(rom); diff --git a/SabreTools.Helper/Tools/Stats.cs b/SabreTools.Helper/Tools/Stats.cs index 53ec38c8..6194e353 100644 --- a/SabreTools.Helper/Tools/Stats.cs +++ b/SabreTools.Helper/Tools/Stats.cs @@ -133,21 +133,21 @@ Please check the log folder if the stats scrolled offscreen"); SortedDictionary> newroms = DatTools.BucketByGame(datdata.Roms, false, true, logger, false); string line = " Uncompressed size: " + Style.GetBytesReadable(datdata.TotalSize); - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop, 0); line = " Games found: " + (game == -1 ? newroms.Count : game); - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop + 1, 0); line = " Roms found: " + datdata.RomCount; - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop + 1, 0); line = " Disks found: " + datdata.DiskCount; - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop + 1, 0); line = " Roms with CRC: " + datdata.CRCCount; - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop + 1, 0); line = " Roms with MD5: " + datdata.MD5Count; - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop + 1, 0); line = " Roms with SHA-1: " + datdata.SHA1Count; - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop + 1, 0); line = " Roms with Nodump status: " + datdata.NodumpCount; - logger.User(line.PadRight(79, ' ')); + logger.Log(line, Console.CursorTop + 1, 0); logger.User(""); } } diff --git a/SimpleSort/SimpleSort.cs b/SimpleSort/SimpleSort.cs index c1735b2a..a1319c03 100644 --- a/SimpleSort/SimpleSort.cs +++ b/SimpleSort/SimpleSort.cs @@ -24,6 +24,7 @@ namespace SabreTools // Other private variables private int _cursorTop; private int _cursorLeft; + private Dat _matched; /// /// Create a new SimpleSort object @@ -53,6 +54,13 @@ namespace SabreTools _rar = (ArchiveScanLevel)(rar < 0 || rar > 2 ? 0 : rar); _zip = (ArchiveScanLevel)(zip < 0 || zip > 2 ? 0 : zip); _logger = logger; + + _cursorTop = Console.CursorTop; + _cursorLeft = Console.CursorLeft; + _matched = new Dat + { + Roms = new Dictionary>(), + }; } /// @@ -333,8 +341,8 @@ namespace SabreTools // Now output the stats for the DAT (remaining) Console.SetCursorPosition(0, Console.CursorTop - 2); - _logger.User("Stats of the unmatched ROMs:".PadRight(79, ' ')); - Stats.OutputStats(_datdata, _logger, true); + _logger.User("Stats of the matched ROMs:".PadRight(79, ' ')); + Stats.OutputStats(_matched, _logger, true); return success; } @@ -354,6 +362,7 @@ namespace SabreTools // Get the full path of the input for movement purposes string percentage = Math.Round((100 * ((double)index / total)), 2, MidpointRounding.AwayFromZero).ToString(); string statement = percentage + "% - " + input; + _logger.ClearBeneath(_cursorTop + 1); _logger.Log(statement, _cursorTop, 0); // Get if the file should be scanned internally and externally @@ -403,6 +412,19 @@ namespace SabreTools { _logger.Log("Matched name: " + found.Name); + // Add rom to the matched list + string key = found.Size + "-" + found.CRC; + if(_matched.Roms.ContainsKey(key)) + { + _matched.Roms[key].Add(found); + } + else + { + List temp = new List(); + temp.Add(found); + _matched.Roms.Add(key, temp); + } + if (_toFolder) { // Copy file to output directory @@ -447,6 +469,19 @@ namespace SabreTools _logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!"); foreach (Rom found in founddroms) { + // Add rom to the matched list + string key = found.Size + "-" + found.CRC; + if (_matched.Roms.ContainsKey(key)) + { + _matched.Roms[key].Add(found); + } + else + { + List temp = new List(); + temp.Add(found); + _matched.Roms.Add(key, temp); + } + // First output the headerless rom _logger.Log("Matched name: " + found.Name); @@ -475,6 +510,19 @@ namespace SabreTools Rom newfound = found; newfound.Name = Path.GetFileNameWithoutExtension(newfound.Name) + " (" + rom.CRC + ")" + Path.GetExtension(newfound.Name); + // Add rom to the matched list + key = newfound.Size + "-" + newfound.CRC; + if (_matched.Roms.ContainsKey(key)) + { + _matched.Roms[key].Add(newfound); + } + else + { + List temp = new List(); + temp.Add(newfound); + _matched.Roms.Add(key, temp); + } + if (_toFolder) { // Copy file to output directory @@ -530,6 +578,19 @@ namespace SabreTools _logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!"); foreach (Rom found in foundroms) { + // Add rom to the matched list + string key = found.Size + "-" + found.CRC; + if (_matched.Roms.ContainsKey(key)) + { + _matched.Roms[key].Add(found); + } + else + { + List temp = new List(); + temp.Add(found); + _matched.Roms.Add(key, temp); + } + if (_toFolder) { // Copy file to output directory