mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Logger, SimpleSort, Stats] Make everything prettier
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear lines beneath the given line in the console
|
||||
/// </summary>
|
||||
/// <param name="line">Line number to clear beneath</param>
|
||||
/// <returns>True</returns>
|
||||
public bool ClearBeneath(int line)
|
||||
{
|
||||
if (!Console.IsOutputRedirected)
|
||||
{
|
||||
for (int i = line; i < Console.WindowHeight; i++)
|
||||
{
|
||||
Log(" ", i, 0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -133,21 +133,21 @@ Please check the log folder if the stats scrolled offscreen");
|
||||
|
||||
SortedDictionary<string, List<Rom>> 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("");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace SabreTools
|
||||
// Other private variables
|
||||
private int _cursorTop;
|
||||
private int _cursorLeft;
|
||||
private Dat _matched;
|
||||
|
||||
/// <summary>
|
||||
/// 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<string, List<Rom>>(),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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<Rom> temp = new List<Rom>();
|
||||
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<Rom> temp = new List<Rom>();
|
||||
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<Rom> temp = new List<Rom>();
|
||||
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<Rom> temp = new List<Rom>();
|
||||
temp.Add(found);
|
||||
_matched.Roms.Add(key, temp);
|
||||
}
|
||||
|
||||
if (_toFolder)
|
||||
{
|
||||
// Copy file to output directory
|
||||
|
||||
Reference in New Issue
Block a user