[Logger] Logging cleanup across the board

This commit is contained in:
Matt Nadareski
2016-07-12 10:42:29 -07:00
parent 1f7206ad75
commit 4c16ce4a2d
5 changed files with 41 additions and 19 deletions

View File

@@ -22,6 +22,11 @@ namespace SabreTools.Helper
public int CompareTo(object obj)
{
Logger temp = new Logger(false, "");
temp.Start();
int ret = 0;
try
{
Rom comp = (Rom)obj;
@@ -30,23 +35,31 @@ namespace SabreTools.Helper
{
if (this.Name == comp.Name)
{
return (RomTools.IsDuplicate(this, comp) ? 0 : 1);
ret = (RomTools.IsDuplicate(this, comp, temp) ? 0 : 1);
}
return String.Compare(this.Name, comp.Name);
ret = String.Compare(this.Name, comp.Name);
}
return String.Compare(this.Game, comp.Game);
ret = String.Compare(this.Game, comp.Game);
}
catch
{
return 1;
ret = 1;
}
temp.Close();
return ret;
}
public bool Equals(Rom other)
{
Logger temp = new Logger(false, "");
temp.Start();
bool isdupe = RomTools.IsDuplicate(this, other, temp);
temp.Close();
return (this.Game == other.Game &&
this.Name == other.Name &&
RomTools.IsDuplicate(this, other));
isdupe);
}
}

View File

@@ -102,7 +102,7 @@ namespace SabreTools.Helper
archive.SaveTo(archiveFileName + ".tmp", CompressionType.Deflate);
}
catch (Exception ex)
catch (Exception)
{
// Don't log archive write errors
}
@@ -412,7 +412,7 @@ namespace SabreTools.Helper
archive.SaveTo(outputArchive + ".tmp", CompressionType.Deflate);
}
catch (Exception ex)
catch (Exception)
{
// Don't log archive write errors
}
@@ -542,8 +542,8 @@ namespace SabreTools.Helper
string gzsize = BitConverter.ToString(footer.Reverse().ToArray()).Replace("-", string.Empty);
long extractedsize = Convert.ToInt64(gzsize, 16);
// Only try to add if the file size is greater than 750 MiB
if (filesize >= (750 * Constants.MibiByte))
// Only try to add if the file size is greater than 600 MiB
if (filesize >= (600 * Constants.MibiByte))
{
// ISIZE is mod 4GiB, so we add that if the ISIZE is smaller than the filesize and greater than 1% different
bool shouldfollowup = false;

View File

@@ -126,7 +126,7 @@ namespace SabreTools.Helper
Rom lastrom = outroms[i];
// Get the duplicate status
dupetype = GetDuplicateStatus(rom, lastrom);
dupetype = GetDuplicateStatus(rom, lastrom, logger);
// If it's a duplicate, skip adding it to the output but add any missing information
if (dupetype != DupeType.None)
@@ -188,9 +188,10 @@ namespace SabreTools.Helper
/// </summary>
/// <param name="lastrom">Rom to use as a base</param>
/// <param name="datdata">DAT to match against</param>
/// <param name="logger">Logger object for console and/or file output</param>
/// <param name="remove">True to remove matched roms from the input, false otherwise (default)</param>
/// <returns>List of matched RomData objects</returns>
public static List<Rom> GetDuplicates(Rom lastrom, Dat datdata, bool remove = false)
public static List<Rom> GetDuplicates(Rom lastrom, Dat datdata, Logger logger, bool remove = false)
{
List<Rom> output = new List<Rom>();
@@ -208,7 +209,7 @@ namespace SabreTools.Helper
List<Rom> left = new List<Rom>();
foreach (Rom rom in roms)
{
if (IsDuplicate(rom, lastrom))
if (IsDuplicate(rom, lastrom, logger))
{
output.Add(rom);
}
@@ -233,8 +234,9 @@ namespace SabreTools.Helper
/// </summary>
/// <param name="rom">Rom to check for duplicate status</param>
/// <param name="lastrom">Rom to use as a baseline</param>
/// <param name="logger">Logger object for console and/or file output</param>
/// <returns>True if the roms are duplicates, false otherwise</returns>
public static bool IsDuplicate(Rom rom, Rom lastrom)
public static bool IsDuplicate(Rom rom, Rom lastrom, Logger logger)
{
bool dupefound = false;
@@ -259,6 +261,12 @@ namespace SabreTools.Helper
);
}
// More wonderful SHA-1 logging that has to be done
if (rom.SHA1 == lastrom.SHA1 && rom.Size != lastrom.Size)
{
logger.User("SHA-1 mismatch - Hash: " + rom.SHA1);
}
return dupefound;
}
@@ -267,13 +275,14 @@ namespace SabreTools.Helper
/// </summary>
/// <param name="rom">Current rom to check</param>
/// <param name="lastrom">Last rom to check against</param>
/// <param name="logger">Logger object for console and/or file output</param>
/// <returns>The DupeType corresponding to the relationship between the two</returns>
public static DupeType GetDuplicateStatus(Rom rom, Rom lastrom)
public static DupeType GetDuplicateStatus(Rom rom, Rom lastrom, Logger logger)
{
DupeType output = DupeType.None;
// If we don't have a duplicate at all, return none
if (!IsDuplicate(rom, lastrom))
if (!IsDuplicate(rom, lastrom, logger))
{
return output;
}

View File

@@ -45,7 +45,7 @@ namespace SabreTools.Helper
/// Now process each of the input files
foreach (string filename in _inputs)
{
_logger.User("Beginning stat collection for '" + filename + "'");
_logger.Log("Beginning stat collection for '" + filename + "'");
List<String> games = new List<String>();
Dat datdata = new Dat();
datdata = DatTools.Parse(filename, 0, 0, datdata, _logger);

View File

@@ -407,7 +407,7 @@ namespace SabreTools
}
// Try to find the matches to the file that was found
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, true);
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
_logger.Log("File '" + input + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Rom found in foundroms)
{
@@ -466,7 +466,7 @@ namespace SabreTools
}
// Try to find the matches to the file that was found
List<Rom> founddroms = RomTools.GetDuplicates(drom, _datdata, true);
List<Rom> founddroms = RomTools.GetDuplicates(drom, _datdata, _logger, true);
_logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!");
foreach (Rom found in founddroms)
{
@@ -575,7 +575,7 @@ namespace SabreTools
foreach (Rom rom in internalRomData)
{
// Try to find the matches to the file that was found
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, true);
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
_logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Rom found in foundroms)
{