mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Instance logging with backing static class instead of Global
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Logging;
|
||||
|
||||
namespace SabreTools.Library.Skippers
|
||||
{
|
||||
@@ -38,6 +38,15 @@ namespace SabreTools.Library.Skippers
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logging
|
||||
|
||||
/// <summary>
|
||||
/// Logging object
|
||||
/// </summary>
|
||||
private Logger logger = new Logger();
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Check if a Stream passes all tests in the SkipperRule
|
||||
/// </summary>
|
||||
@@ -66,14 +75,14 @@ namespace SabreTools.Library.Skippers
|
||||
// If the input file doesn't exist, fail
|
||||
if (!File.Exists(input))
|
||||
{
|
||||
Globals.Logger.Error($"I'm sorry but '{input}' doesn't exist!");
|
||||
logger.Error($"I'm sorry but '{input}' doesn't exist!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the output directory if it doesn't already
|
||||
DirectoryExtensions.Ensure(Path.GetDirectoryName(output));
|
||||
|
||||
Globals.Logger.User($"Attempting to apply rule to '{input}'");
|
||||
logger.User($"Attempting to apply rule to '{input}'");
|
||||
bool success = TransformStream(FileExtensions.TryOpenRead(input), FileExtensions.TryCreate(output));
|
||||
|
||||
// If the output file has size 0, delete it
|
||||
@@ -104,7 +113,7 @@ namespace SabreTools.Library.Skippers
|
||||
|| (Operation > HeaderSkipOperation.Byteswap && (extsize % 4) != 0)
|
||||
|| (Operation > HeaderSkipOperation.Bitswap && (StartOffset == null || StartOffset % 2 == 0)))
|
||||
{
|
||||
Globals.Logger.Error("The stream did not have the correct size to be transformed!");
|
||||
logger.Error("The stream did not have the correct size to be transformed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -113,7 +122,7 @@ namespace SabreTools.Library.Skippers
|
||||
BinaryReader br = null;
|
||||
try
|
||||
{
|
||||
Globals.Logger.User("Applying found rule to input stream");
|
||||
logger.User("Applying found rule to input stream");
|
||||
bw = new BinaryWriter(output);
|
||||
br = new BinaryReader(input);
|
||||
|
||||
@@ -201,7 +210,7 @@ namespace SabreTools.Library.Skippers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex);
|
||||
logger.Error(ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -5,6 +5,7 @@ using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.FileTypes;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Logging;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Library.Skippers
|
||||
@@ -31,6 +32,15 @@ namespace SabreTools.Library.Skippers
|
||||
/// </summary>
|
||||
private static List<SkipperFile> List;
|
||||
|
||||
#region Logging
|
||||
|
||||
/// <summary>
|
||||
/// Logging object
|
||||
/// </summary>
|
||||
private static Logger logger = new Logger();
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Local paths
|
||||
/// </summary>
|
||||
@@ -74,7 +84,7 @@ namespace SabreTools.Library.Skippers
|
||||
// Create the output directory if it doesn't exist
|
||||
DirectoryExtensions.Ensure(outDir, create: true);
|
||||
|
||||
Globals.Logger.User($"\nGetting skipper information for '{file}'");
|
||||
logger.User($"\nGetting skipper information for '{file}'");
|
||||
|
||||
// Get the skipper rule that matches the file, if any
|
||||
SkipperRule rule = GetMatchingRule(file, string.Empty);
|
||||
@@ -83,7 +93,7 @@ namespace SabreTools.Library.Skippers
|
||||
if (rule.Tests == null || rule.Tests.Count == 0 || rule.Operation != HeaderSkipOperation.None)
|
||||
return false;
|
||||
|
||||
Globals.Logger.User("File has a valid copier header");
|
||||
logger.User("File has a valid copier header");
|
||||
|
||||
// Get the header bytes from the file first
|
||||
string hstr;
|
||||
@@ -152,9 +162,9 @@ namespace SabreTools.Library.Skippers
|
||||
for (int i = 0; i < headers.Count; i++)
|
||||
{
|
||||
string outputFile = (string.IsNullOrWhiteSpace(outDir) ? $"{Path.GetFullPath(file)}.new" : Path.Combine(outDir, Path.GetFileName(file))) + i;
|
||||
Globals.Logger.User($"Creating reheadered file: {outputFile}");
|
||||
logger.User($"Creating reheadered file: {outputFile}");
|
||||
FileExtensions.AppendBytes(file, outputFile, Utilities.StringToByteArray(headers[i]), null);
|
||||
Globals.Logger.User("Reheadered file created!");
|
||||
logger.User("Reheadered file created!");
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -172,7 +182,7 @@ namespace SabreTools.Library.Skippers
|
||||
// If the file doesn't exist, return a blank skipper rule
|
||||
if (!File.Exists(input))
|
||||
{
|
||||
Globals.Logger.Error($"The file '{input}' does not exist so it cannot be tested");
|
||||
logger.Error($"The file '{input}' does not exist so it cannot be tested");
|
||||
return new SkipperRule();
|
||||
}
|
||||
|
||||
@@ -195,7 +205,7 @@ namespace SabreTools.Library.Skippers
|
||||
return skipperRule;
|
||||
|
||||
// Loop through and find a Skipper that has the right name
|
||||
Globals.Logger.Verbose("Beginning search for matching header skip rules");
|
||||
logger.Verbose("Beginning search for matching header skip rules");
|
||||
List<SkipperFile> tempList = new List<SkipperFile>();
|
||||
tempList.AddRange(List);
|
||||
|
||||
@@ -217,9 +227,9 @@ namespace SabreTools.Library.Skippers
|
||||
|
||||
// If we have a blank rule, inform the user
|
||||
if (skipperRule.Tests == null)
|
||||
Globals.Logger.Verbose("No matching rule found!");
|
||||
logger.Verbose("No matching rule found!");
|
||||
else
|
||||
Globals.Logger.User("Matching rule found!");
|
||||
logger.User("Matching rule found!");
|
||||
|
||||
return skipperRule;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user