Remove Logging dependency from Skippers

This commit is contained in:
Matt Nadareski
2024-02-29 00:39:29 -05:00
parent 878b9d5894
commit e973d7cb7b
3 changed files with 2 additions and 64 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Xml.Serialization;
using SabreTools.Logging;
using SabreTools.Skippers.Tests;
namespace SabreTools.Skippers
@@ -85,20 +84,6 @@ namespace SabreTools.Skippers
#endregion
#region Logging
/// <summary>
/// Logging object
/// </summary>
private readonly Logger logger;
#endregion
public Rule()
{
logger = new Logger(this);
}
/// <summary>
/// Check if a Stream passes all tests in the Rule
/// </summary>
@@ -131,17 +116,11 @@ namespace SabreTools.Skippers
{
// If the input file doesn't exist
if (string.IsNullOrEmpty(input) || !File.Exists(input))
{
logger.Error($"'{input}' doesn't exist and cannot be transformed!");
return false;
}
// If we have an invalid output directory name
if (string.IsNullOrEmpty(output))
{
logger.Error($"Output path was null or empty, cannot write transformed file!");
return false;
}
// Create the output directory if it doesn't already
string parentDirectory = Path.GetDirectoryName(output) ?? string.Empty;
@@ -174,10 +153,7 @@ namespace SabreTools.Skippers
// If the input stream isn't valid
if (input == null || !input.CanRead)
{
logger.Error("The stream was invalid!");
return false;
}
// If the sizes are wrong for the values, fail
long extsize = input.Length;
@@ -185,7 +161,6 @@ namespace SabreTools.Skippers
|| (Operation > HeaderSkipOperation.Byteswap && (extsize % 4) != 0)
|| (Operation > HeaderSkipOperation.Bitswap && (_startOffset == null || _startOffset % 2 != 0)))
{
logger.Error("The stream did not have the correct size to be transformed!");
return false;
}
@@ -194,7 +169,6 @@ namespace SabreTools.Skippers
BinaryReader? br = null;
try
{
logger.User("Applying found rule to input stream");
bw = new BinaryWriter(output);
br = new BinaryReader(input);
@@ -277,30 +251,21 @@ namespace SabreTools.Skippers
}
}
}
catch (Exception ex)
catch
{
logger.Error(ex);
return false;
}
finally
{
#if NET40_OR_GREATER
// If we're not keeping the read stream open, dispose of the binary reader
if (!keepReadOpen)
{
#if NET40_OR_GREATER
br?.Dispose();
#endif
}
// If we're not keeping the write stream open, dispose of the binary reader
if (!keepWriteOpen)
{
#if NET40_OR_GREATER
bw?.Dispose();
#endif
}
}
return success;

View File

@@ -20,10 +20,6 @@
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SabreTools.Logging\SabreTools.Logging.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Skippers\*" />
</ItemGroup>

View File

@@ -4,7 +4,6 @@ using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using SabreTools.IO;
using SabreTools.Logging;
namespace SabreTools.Skippers
{
@@ -35,15 +34,6 @@ namespace SabreTools.Skippers
/// </summary>
private static readonly string LocalPath = Path.Combine(PathTool.GetRuntimeDirectory(), "Skippers") + Path.DirectorySeparatorChar;
#region Logging
/// <summary>
/// Logging object
/// </summary>
private static readonly Logger logger = new();
#endregion
/// <summary>
/// Initialize static fields
/// </summary>
@@ -162,10 +152,7 @@ namespace SabreTools.Skippers
{
// If the file doesn't exist, return a blank skipper rule
if (!File.Exists(input))
{
logger.Error($"The file '{input}' does not exist so it cannot be tested");
return new Rule();
}
return GetMatchingRule(File.OpenRead(input), skipperName);
}
@@ -189,9 +176,6 @@ namespace SabreTools.Skippers
if (Skippers == null || skipperName == null)
return skipperRule;
// Loop through and find a Skipper that has the right name
logger.Verbose("Beginning search for matching header skip rules");
// Loop through all known Detectors
foreach (Detector? skipper in Skippers)
{
@@ -210,13 +194,6 @@ namespace SabreTools.Skippers
// If the Rule is null, make it empty
skipperRule ??= new Rule();
// If we have a blank rule, inform the user
if (skipperRule.Tests == null)
logger.Verbose("No matching rule found!");
else
logger.User("Matching rule found!");
return skipperRule;
}
}