Support ancient .NET in Skippers

This commit is contained in:
Matt Nadareski
2024-02-28 20:31:22 -05:00
parent c6df7980a8
commit 080c8a749b
5 changed files with 27 additions and 6 deletions

View File

@@ -53,7 +53,7 @@ namespace SabreTools.Skippers
public Rule? GetMatchingRule(Stream input, string skipperName)
{
// If we have no name supplied, try to blindly match
if (string.IsNullOrWhiteSpace(skipperName))
if (string.IsNullOrEmpty(skipperName))
return GetMatchingRule(input);
// If the name matches the internal name of the skipper

View File

@@ -130,14 +130,14 @@ namespace SabreTools.Skippers
public bool TransformFile(string input, string output)
{
// If the input file doesn't exist
if (string.IsNullOrWhiteSpace(input) || !File.Exists(input))
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.IsNullOrWhiteSpace(output))
if (string.IsNullOrEmpty(output))
{
logger.Error($"Output path was null or empty, cannot write transformed file!");
return false;
@@ -284,6 +284,7 @@ namespace SabreTools.Skippers
}
finally
{
#if NET40_OR_GREATER
// If we're not keeping the read stream open, dispose of the binary reader
if (!keepReadOpen)
br?.Dispose();
@@ -291,6 +292,7 @@ namespace SabreTools.Skippers
// If we're not keeping the write stream open, dispose of the binary reader
if (!keepWriteOpen)
bw?.Dispose();
#endif
}
return success;

View File

@@ -1,10 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
<Copyright>Copyright (c)2016-2024 Matt Nadareski</Copyright>
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
<RepositoryUrl>https://github.com/SabreTools/SabreTools</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>

View File

@@ -79,7 +79,11 @@ namespace SabreTools.Skippers
var xts = new XmlSerializer(typeof(Detector));
// Get skippers for each known header type
#if NET20 || NET35
foreach (string skipperPath in Directory.GetFiles(LocalPath, "*"))
#else
foreach (string skipperPath in Directory.EnumerateFiles(LocalPath, "*", SearchOption.AllDirectories))
#endif
{
try
{
@@ -87,7 +91,9 @@ namespace SabreTools.Skippers
var xtr = XmlReader.Create(skipperPath, new XmlReaderSettings
{
CheckCharacters = false,
#if NET40_OR_GREATER
DtdProcessing = DtdProcessing.Ignore,
#endif
IgnoreComments = true,
IgnoreWhitespace = true,
ValidationFlags = XmlSchemaValidationFlags.None,

View File

@@ -25,10 +25,10 @@ namespace SabreTools.Skippers
protected static byte[]? ParseByteArrayFromHex(string? hex)
{
// If we have an invalid string
if (string.IsNullOrWhiteSpace(hex))
if (string.IsNullOrEmpty(hex))
return null;
var ret = new byte[hex.Length / 2];
var ret = new byte[hex!.Length / 2];
for (int index = 0; index < ret.Length; index++)
{
string byteValue = hex.Substring(index * 2, 2);