mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Remove Logging dependency from Skippers
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using SabreTools.Logging;
|
|
||||||
using SabreTools.Skippers.Tests;
|
using SabreTools.Skippers.Tests;
|
||||||
|
|
||||||
namespace SabreTools.Skippers
|
namespace SabreTools.Skippers
|
||||||
@@ -85,20 +84,6 @@ namespace SabreTools.Skippers
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Logging
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Logging object
|
|
||||||
/// </summary>
|
|
||||||
private readonly Logger logger;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public Rule()
|
|
||||||
{
|
|
||||||
logger = new Logger(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if a Stream passes all tests in the Rule
|
/// Check if a Stream passes all tests in the Rule
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -131,17 +116,11 @@ namespace SabreTools.Skippers
|
|||||||
{
|
{
|
||||||
// If the input file doesn't exist
|
// If the input file doesn't exist
|
||||||
if (string.IsNullOrEmpty(input) || !File.Exists(input))
|
if (string.IsNullOrEmpty(input) || !File.Exists(input))
|
||||||
{
|
|
||||||
logger.Error($"'{input}' doesn't exist and cannot be transformed!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// If we have an invalid output directory name
|
// If we have an invalid output directory name
|
||||||
if (string.IsNullOrEmpty(output))
|
if (string.IsNullOrEmpty(output))
|
||||||
{
|
|
||||||
logger.Error($"Output path was null or empty, cannot write transformed file!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Create the output directory if it doesn't already
|
// Create the output directory if it doesn't already
|
||||||
string parentDirectory = Path.GetDirectoryName(output) ?? string.Empty;
|
string parentDirectory = Path.GetDirectoryName(output) ?? string.Empty;
|
||||||
@@ -174,10 +153,7 @@ namespace SabreTools.Skippers
|
|||||||
|
|
||||||
// If the input stream isn't valid
|
// If the input stream isn't valid
|
||||||
if (input == null || !input.CanRead)
|
if (input == null || !input.CanRead)
|
||||||
{
|
|
||||||
logger.Error("The stream was invalid!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// If the sizes are wrong for the values, fail
|
// If the sizes are wrong for the values, fail
|
||||||
long extsize = input.Length;
|
long extsize = input.Length;
|
||||||
@@ -185,7 +161,6 @@ namespace SabreTools.Skippers
|
|||||||
|| (Operation > HeaderSkipOperation.Byteswap && (extsize % 4) != 0)
|
|| (Operation > HeaderSkipOperation.Byteswap && (extsize % 4) != 0)
|
||||||
|| (Operation > HeaderSkipOperation.Bitswap && (_startOffset == null || _startOffset % 2 != 0)))
|
|| (Operation > HeaderSkipOperation.Bitswap && (_startOffset == null || _startOffset % 2 != 0)))
|
||||||
{
|
{
|
||||||
logger.Error("The stream did not have the correct size to be transformed!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +169,6 @@ namespace SabreTools.Skippers
|
|||||||
BinaryReader? br = null;
|
BinaryReader? br = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger.User("Applying found rule to input stream");
|
|
||||||
bw = new BinaryWriter(output);
|
bw = new BinaryWriter(output);
|
||||||
br = new BinaryReader(input);
|
br = new BinaryReader(input);
|
||||||
|
|
||||||
@@ -277,30 +251,21 @@ namespace SabreTools.Skippers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch
|
||||||
{
|
{
|
||||||
logger.Error(ex);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
#if NET40_OR_GREATER
|
||||||
// If we're not keeping the read stream open, dispose of the binary reader
|
// If we're not keeping the read stream open, dispose of the binary reader
|
||||||
if (!keepReadOpen)
|
if (!keepReadOpen)
|
||||||
{
|
|
||||||
#if NET40_OR_GREATER
|
|
||||||
br?.Dispose();
|
br?.Dispose();
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// If we're not keeping the write stream open, dispose of the binary reader
|
// If we're not keeping the write stream open, dispose of the binary reader
|
||||||
if (!keepWriteOpen)
|
if (!keepWriteOpen)
|
||||||
{
|
|
||||||
#if NET40_OR_GREATER
|
|
||||||
bw?.Dispose();
|
bw?.Dispose();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
|||||||
@@ -20,10 +20,6 @@
|
|||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\SabreTools.Logging\SabreTools.Logging.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="Skippers\*" />
|
<None Remove="Skippers\*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Xml;
|
|||||||
using System.Xml.Schema;
|
using System.Xml.Schema;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using SabreTools.IO;
|
using SabreTools.IO;
|
||||||
using SabreTools.Logging;
|
|
||||||
|
|
||||||
namespace SabreTools.Skippers
|
namespace SabreTools.Skippers
|
||||||
{
|
{
|
||||||
@@ -35,15 +34,6 @@ namespace SabreTools.Skippers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly string LocalPath = Path.Combine(PathTool.GetRuntimeDirectory(), "Skippers") + Path.DirectorySeparatorChar;
|
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>
|
/// <summary>
|
||||||
/// Initialize static fields
|
/// Initialize static fields
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -162,10 +152,7 @@ namespace SabreTools.Skippers
|
|||||||
{
|
{
|
||||||
// If the file doesn't exist, return a blank skipper rule
|
// If the file doesn't exist, return a blank skipper rule
|
||||||
if (!File.Exists(input))
|
if (!File.Exists(input))
|
||||||
{
|
|
||||||
logger.Error($"The file '{input}' does not exist so it cannot be tested");
|
|
||||||
return new Rule();
|
return new Rule();
|
||||||
}
|
|
||||||
|
|
||||||
return GetMatchingRule(File.OpenRead(input), skipperName);
|
return GetMatchingRule(File.OpenRead(input), skipperName);
|
||||||
}
|
}
|
||||||
@@ -189,9 +176,6 @@ namespace SabreTools.Skippers
|
|||||||
if (Skippers == null || skipperName == null)
|
if (Skippers == null || skipperName == null)
|
||||||
return skipperRule;
|
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
|
// Loop through all known Detectors
|
||||||
foreach (Detector? skipper in Skippers)
|
foreach (Detector? skipper in Skippers)
|
||||||
{
|
{
|
||||||
@@ -210,13 +194,6 @@ namespace SabreTools.Skippers
|
|||||||
|
|
||||||
// If the Rule is null, make it empty
|
// If the Rule is null, make it empty
|
||||||
skipperRule ??= new Rule();
|
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;
|
return skipperRule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user