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
|
// USER and ERROR writes to console
|
||||||
if (loglevel == LogLevel.USER || loglevel == LogLevel.ERROR)
|
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, ' ');
|
string tempoutput = output.PadRight(padlength, ' ');
|
||||||
Console.WriteLine((loglevel == LogLevel.ERROR ? loglevel.ToString() + " " : "") + tempoutput);
|
Console.WriteLine((loglevel == LogLevel.ERROR ? loglevel.ToString() + " " : "") + tempoutput);
|
||||||
}
|
}
|
||||||
@@ -178,6 +179,7 @@ namespace SabreTools.Helper
|
|||||||
|
|
||||||
// Write out to the console
|
// Write out to the console
|
||||||
int padlength = (int)(Math.Ceiling((double)output.Length / 80) * 80) - 1;
|
int padlength = (int)(Math.Ceiling((double)output.Length / 80) * 80) - 1;
|
||||||
|
padlength = (padlength > 0 ? padlength : 0);
|
||||||
string tempoutput = output.PadRight(padlength, ' ');
|
string tempoutput = output.PadRight(padlength, ' ');
|
||||||
Console.Write(tempoutput);
|
Console.Write(tempoutput);
|
||||||
|
|
||||||
@@ -228,5 +230,22 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
return Log(output, LogLevel.ERROR);
|
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)
|
foreach (Rom rom in newroms)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
string key = rom.Size + "-" + rom.CRC; ;
|
string key = rom.Size + "-" + rom.CRC;
|
||||||
if (sortable.ContainsKey(key))
|
if (sortable.ContainsKey(key))
|
||||||
{
|
{
|
||||||
sortable[key].Add(rom);
|
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);
|
SortedDictionary<string, List<Rom>> newroms = DatTools.BucketByGame(datdata.Roms, false, true, logger, false);
|
||||||
string line = " Uncompressed size: " + Style.GetBytesReadable(datdata.TotalSize);
|
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);
|
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;
|
line = " Roms found: " + datdata.RomCount;
|
||||||
logger.User(line.PadRight(79, ' '));
|
logger.Log(line, Console.CursorTop + 1, 0);
|
||||||
line = " Disks found: " + datdata.DiskCount;
|
line = " Disks found: " + datdata.DiskCount;
|
||||||
logger.User(line.PadRight(79, ' '));
|
logger.Log(line, Console.CursorTop + 1, 0);
|
||||||
line = " Roms with CRC: " + datdata.CRCCount;
|
line = " Roms with CRC: " + datdata.CRCCount;
|
||||||
logger.User(line.PadRight(79, ' '));
|
logger.Log(line, Console.CursorTop + 1, 0);
|
||||||
line = " Roms with MD5: " + datdata.MD5Count;
|
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;
|
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;
|
line = " Roms with Nodump status: " + datdata.NodumpCount;
|
||||||
logger.User(line.PadRight(79, ' '));
|
logger.Log(line, Console.CursorTop + 1, 0);
|
||||||
logger.User("");
|
logger.User("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace SabreTools
|
|||||||
// Other private variables
|
// Other private variables
|
||||||
private int _cursorTop;
|
private int _cursorTop;
|
||||||
private int _cursorLeft;
|
private int _cursorLeft;
|
||||||
|
private Dat _matched;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new SimpleSort object
|
/// Create a new SimpleSort object
|
||||||
@@ -53,6 +54,13 @@ namespace SabreTools
|
|||||||
_rar = (ArchiveScanLevel)(rar < 0 || rar > 2 ? 0 : rar);
|
_rar = (ArchiveScanLevel)(rar < 0 || rar > 2 ? 0 : rar);
|
||||||
_zip = (ArchiveScanLevel)(zip < 0 || zip > 2 ? 0 : zip);
|
_zip = (ArchiveScanLevel)(zip < 0 || zip > 2 ? 0 : zip);
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
|
_cursorTop = Console.CursorTop;
|
||||||
|
_cursorLeft = Console.CursorLeft;
|
||||||
|
_matched = new Dat
|
||||||
|
{
|
||||||
|
Roms = new Dictionary<string, List<Rom>>(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -333,8 +341,8 @@ namespace SabreTools
|
|||||||
|
|
||||||
// Now output the stats for the DAT (remaining)
|
// Now output the stats for the DAT (remaining)
|
||||||
Console.SetCursorPosition(0, Console.CursorTop - 2);
|
Console.SetCursorPosition(0, Console.CursorTop - 2);
|
||||||
_logger.User("Stats of the unmatched ROMs:".PadRight(79, ' '));
|
_logger.User("Stats of the matched ROMs:".PadRight(79, ' '));
|
||||||
Stats.OutputStats(_datdata, _logger, true);
|
Stats.OutputStats(_matched, _logger, true);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -354,6 +362,7 @@ namespace SabreTools
|
|||||||
// Get the full path of the input for movement purposes
|
// Get the full path of the input for movement purposes
|
||||||
string percentage = Math.Round((100 * ((double)index / total)), 2, MidpointRounding.AwayFromZero).ToString();
|
string percentage = Math.Round((100 * ((double)index / total)), 2, MidpointRounding.AwayFromZero).ToString();
|
||||||
string statement = percentage + "% - " + input;
|
string statement = percentage + "% - " + input;
|
||||||
|
_logger.ClearBeneath(_cursorTop + 1);
|
||||||
_logger.Log(statement, _cursorTop, 0);
|
_logger.Log(statement, _cursorTop, 0);
|
||||||
|
|
||||||
// Get if the file should be scanned internally and externally
|
// Get if the file should be scanned internally and externally
|
||||||
@@ -403,6 +412,19 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
_logger.Log("Matched name: " + found.Name);
|
_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)
|
if (_toFolder)
|
||||||
{
|
{
|
||||||
// Copy file to output directory
|
// Copy file to output directory
|
||||||
@@ -447,6 +469,19 @@ namespace SabreTools
|
|||||||
_logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!");
|
_logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!");
|
||||||
foreach (Rom found in founddroms)
|
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
|
// First output the headerless rom
|
||||||
_logger.Log("Matched name: " + found.Name);
|
_logger.Log("Matched name: " + found.Name);
|
||||||
|
|
||||||
@@ -475,6 +510,19 @@ namespace SabreTools
|
|||||||
Rom newfound = found;
|
Rom newfound = found;
|
||||||
newfound.Name = Path.GetFileNameWithoutExtension(newfound.Name) + " (" + rom.CRC + ")" + Path.GetExtension(newfound.Name);
|
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)
|
if (_toFolder)
|
||||||
{
|
{
|
||||||
// Copy file to output directory
|
// Copy file to output directory
|
||||||
@@ -530,6 +578,19 @@ namespace SabreTools
|
|||||||
_logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!");
|
_logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!");
|
||||||
foreach (Rom found in foundroms)
|
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)
|
if (_toFolder)
|
||||||
{
|
{
|
||||||
// Copy file to output directory
|
// Copy file to output directory
|
||||||
|
|||||||
Reference in New Issue
Block a user