Instance logging with backing static class instead of Global

This commit is contained in:
Matt Nadareski
2020-10-07 15:42:30 -07:00
parent 348a2a2bcb
commit b7db9f7f14
69 changed files with 1034 additions and 834 deletions

View File

@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.Library.Data;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Logging;
namespace SabreTools.Library.FileTypes
{
@@ -63,7 +63,7 @@ namespace SabreTools.Library.FileTypes
return archive;
// Create the archive based on the type
Globals.Logger.Verbose($"Found archive of type: {at}");
logger.Verbose($"Found archive of type: {at}");
switch (at)
{
case FileType.GZipArchive:

View File

@@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Logging;
using SabreTools.Library.Tools;
namespace SabreTools.Library.FileTypes
@@ -18,7 +18,12 @@ namespace SabreTools.Library.FileTypes
#region Protected instance variables
protected List<BaseFile> _children;
/// <summary>
/// Logging object
/// </summary>
protected static Logger logger = new Logger();
/// <summary>
/// Flag specific to Folder to omit Machine name from output path
/// </summary>
@@ -125,7 +130,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return false;
}
@@ -203,7 +208,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return realentry;
}
@@ -242,7 +247,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return (ms, realentry);
}
@@ -372,7 +377,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
success = false;
}
finally

View File

@@ -87,16 +87,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex)
{
// Catch this but don't count it as an error because SharpCompress is unsafe
Globals.Logger.Verbose(ex);
logger.Verbose(ex);
}
catch (InvalidOperationException ex)
{
Globals.Logger.Warning(ex);
logger.Warning(ex);
encounteredErrors = true;
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
encounteredErrors = true;
}
@@ -183,7 +183,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
ms = null;
realEntry = null;
}
@@ -251,7 +251,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return null;
}
}
@@ -286,21 +286,21 @@ namespace SabreTools.Library.FileTypes
// If we have the romba depot files, just skip them gracefully
if (datum == ".romba_size" || datum == ".romba_size.backup")
{
Globals.Logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
return false;
}
// Check if the name is the right length
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz"))
{
Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
return false;
}
// Check if the file is at least the minimum length
if (filesize < 40 /* bytes */)
{
Globals.Logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
return false;
}
@@ -347,21 +347,21 @@ namespace SabreTools.Library.FileTypes
// If we have the romba depot files, just skip them gracefully
if (datum == ".romba_size" || datum == ".romba_size.backup")
{
Globals.Logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
return null;
}
// Check if the name is the right length
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz"))
{
Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
return null;
}
// Check if the file is at least the minimum length
if (filesize < 40 /* bytes */)
{
Globals.Logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
return null;
}
@@ -427,7 +427,7 @@ namespace SabreTools.Library.FileTypes
// Check that the input file exists
if (!File.Exists(inputFile))
{
Globals.Logger.Warning($"File '{inputFile}' does not exist!");
logger.Warning($"File '{inputFile}' does not exist!");
return false;
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
@@ -71,16 +70,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex)
{
// Catch this but don't count it as an error because SharpCompress is unsafe
Globals.Logger.Verbose(ex);
logger.Verbose(ex);
}
catch (InvalidOperationException ex)
{
Globals.Logger.Warning(ex);
logger.Warning(ex);
encounteredErrors = true;
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
encounteredErrors = true;
}
@@ -160,7 +159,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
ms = null;
realEntry = null;
}
@@ -216,7 +215,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return null;
}
@@ -257,7 +256,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
}
return empties;

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
@@ -120,16 +119,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex)
{
// Catch this but don't count it as an error because SharpCompress is unsafe
Globals.Logger.Verbose(ex);
logger.Verbose(ex);
}
catch (InvalidOperationException ex)
{
Globals.Logger.Warning(ex);
logger.Warning(ex);
encounteredErrors = true;
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
encounteredErrors = true;
}
@@ -244,7 +243,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
ms = null;
realEntry = null;
}
@@ -291,7 +290,7 @@ namespace SabreTools.Library.FileTypes
// If we get a read error, log it and continue
if (zr != ZipReturn.ZipGood)
{
Globals.Logger.Warning($"An error occurred while reading archive {this.Filename}: Zip Error - {zr}");
logger.Warning($"An error occurred while reading archive {this.Filename}: Zip Error - {zr}");
zr = zf.ZipFileCloseReadStream();
continue;
}
@@ -323,7 +322,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return null;
}
@@ -376,7 +375,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
}
return empties;
@@ -589,7 +588,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
success = false;
}
finally
@@ -816,7 +815,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
success = false;
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
@@ -76,16 +75,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex)
{
// Catch this but don't count it as an error because SharpCompress is unsafe
Globals.Logger.Verbose(ex);
logger.Verbose(ex);
}
catch (InvalidOperationException ex)
{
Globals.Logger.Warning(ex);
logger.Warning(ex);
encounteredErrors = true;
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
encounteredErrors = true;
}
@@ -165,7 +164,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
ms = null;
realEntry = null;
}
@@ -221,7 +220,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return null;
}
@@ -262,7 +261,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
}
return empties;
@@ -412,7 +411,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
success = false;
}
finally
@@ -586,7 +585,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
success = false;
}
finally

View File

@@ -81,16 +81,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex)
{
// Catch this but don't count it as an error because SharpCompress is unsafe
Globals.Logger.Verbose(ex);
logger.Verbose(ex);
}
catch (InvalidOperationException ex)
{
Globals.Logger.Warning(ex);
logger.Warning(ex);
encounteredErrors = true;
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
encounteredErrors = true;
}
@@ -175,7 +175,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
ms = null;
realEntry = null;
}
@@ -239,7 +239,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return null;
}
}
@@ -273,7 +273,7 @@ namespace SabreTools.Library.FileTypes
// Check if the name is the right length
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz"))
{
Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
return false;
}
@@ -295,7 +295,7 @@ namespace SabreTools.Library.FileTypes
// Check if the name is the right length
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz"))
{
Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
return null;
}
@@ -327,7 +327,7 @@ namespace SabreTools.Library.FileTypes
// Check that the input file exists
if (!File.Exists(inputFile))
{
Globals.Logger.Warning($"File '{inputFile}' does not exist!");
logger.Warning($"File '{inputFile}' does not exist!");
return false;
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
@@ -121,16 +120,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex)
{
// Catch this but don't count it as an error because SharpCompress is unsafe
Globals.Logger.Verbose(ex);
logger.Verbose(ex);
}
catch (InvalidOperationException ex)
{
Globals.Logger.Warning(ex);
logger.Warning(ex);
encounteredErrors = true;
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
encounteredErrors = true;
}
@@ -245,7 +244,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
ms = null;
realEntry = null;
}
@@ -292,7 +291,7 @@ namespace SabreTools.Library.FileTypes
// If we get a read error, log it and continue
if (zr != ZipReturn.ZipGood)
{
Globals.Logger.Warning($"An error occurred while reading archive {this.Filename}: Zip Error - {zr}");
logger.Warning($"An error occurred while reading archive {this.Filename}: Zip Error - {zr}");
zr = zf.ZipFileCloseReadStream();
continue;
}
@@ -325,7 +324,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
return null;
}
@@ -378,7 +377,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
}
return empties;
@@ -590,7 +589,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
success = false;
}
finally
@@ -818,7 +817,7 @@ namespace SabreTools.Library.FileTypes
}
catch (Exception ex)
{
Globals.Logger.Error(ex);
logger.Error(ex);
success = false;
}