Version gate remaining Linq statements

This commit is contained in:
Matt Nadareski
2024-11-22 13:00:11 -05:00
parent 575c1a7bd7
commit 62475f725a
6 changed files with 79 additions and 3 deletions

View File

@@ -69,7 +69,6 @@
<!-- Support for old .NET versions -->
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`))">
<PackageReference Include="Net30.LinqBridge" Version="1.3.0" />
<PackageReference Include="Net35.Actions" Version="1.1.0" />
</ItemGroup>
<ItemGroup Condition="!$(TargetFramework.StartsWith(`net2`)) AND !$(TargetFramework.StartsWith(`net3`))">

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
#if NET35_OR_GREATER || NETCOREAPP
using System.Linq;
#endif
using BinaryObjectScanner.Data;
using BinaryObjectScanner.Interfaces;
using SabreTools.IO.Extensions;
@@ -267,9 +269,20 @@ namespace BinaryObjectScanner.FileType
return protections;
// If we have any extractable packers
#if NET20
var extractables = new List<IExtractableExecutable<T>>();
foreach (var check in checks)
{
if (check == null || check is not IExtractableExecutable<T> extractable)
continue;
extractables.Add(extractable);
}
#else
var extractables = checks
.Where(c => c is IExtractableExecutable<T>)
.Select(c => c as IExtractableExecutable<T>);
#endif
extractables.IterateWithAction(extractable =>
{
var subProtections = PerformExtractableCheck(extractable!, file, exe, getProtections, includeDebug);

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
#if NET35_OR_GREATER || NETCOREAPP
using System.Linq;
#endif
using System.Text;
using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
@@ -125,9 +127,28 @@ namespace BinaryObjectScanner.Protection
// Check the imported-name table
// Found in "h3blade.exe" in Redump entry 85077.
#if NET20
bool intMatch = false;
if (nex.Model.ImportedNameTable?.Values != null)
{
foreach (var inte in nex.Model.ImportedNameTable.Values)
{
if (inte?.NameString == null || inte.NameString.Length == 0)
continue;
string ns = Encoding.ASCII.GetString(inte.NameString);
if (ns.Contains("CDCOPS"))
{
intMatch = true;
break;
}
}
}
#else
bool intMatch = nex.Model.ImportedNameTable?.Values?
.Select(inte => inte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(inte.NameString))
.Any(s => s.Contains("CDCOPS")) ?? false;
#endif
if (intMatch)
return "CD-Cops";

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
#if NET35_OR_GREATER || NETCOREAPP
using System.Linq;
#endif
using System.Text;
using SabreTools.Matching;
using SabreTools.Matching.Paths;
@@ -121,10 +123,22 @@ namespace BinaryObjectScanner.Protection
return string.Empty;
// Find the version.txt file first
#if NET20
string? versionPath = null;
foreach (string file in files)
{
if (Path.GetFileName(file).Equals("version.txt", StringComparison.OrdinalIgnoreCase))
{
versionPath = file;
break;
}
}
#else
var versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase));
#endif
if (!string.IsNullOrEmpty(versionPath))
{
var version = GetCactusDataShieldInternalVersion(versionPath);
var version = GetCactusDataShieldInternalVersion(versionPath!);
if (!string.IsNullOrEmpty(version))
return version!;
}

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
#if NET35_OR_GREATER || NETCOREAPP
using System.Linq;
#endif
using BinaryObjectScanner.Interfaces;
using SabreTools.IO.Extensions;
using SabreTools.Matching;
@@ -631,7 +633,19 @@ namespace BinaryObjectScanner.Protection
}
// Get distinct and order
#if NET20
var distinct = new List<string>();
foreach (string result in resultsList)
{
if (!distinct.Contains(result))
distinct.Add(result);
}
distinct.Sort();
return distinct;
#else
return [.. resultsList.Distinct().OrderBy(s => s)];
#endif
}
}
}

View File

@@ -1,6 +1,8 @@
using System;
using System.IO;
#if NET35_OR_GREATER || NETCOREAPP
using System.Linq;
#endif
using BinaryObjectScanner;
namespace ProtectionScan
@@ -85,13 +87,26 @@ namespace ProtectionScan
}
using var sw = new StreamWriter(File.OpenWrite($"protection-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt"));
#if NET20
var keysArr = new string[protections.Keys.Count];
protections.Keys.CopyTo(keysArr, 0);
Array.Sort(keysArr);
foreach (string key in keysArr)
#else
foreach (string key in protections.Keys.OrderBy(k => k))
#endif
{
// Skip over files with no protection
if (protections[key] == null || protections[key].Count == 0)
continue;
string line = $"{key}: {string.Join(", ", [.. protections[key].OrderBy(p => p)])}";
#if NET20
string[] fileProtections = [.. protections[key]];
Array.Sort(fileProtections);
#else
string[] fileProtections = [.. protections[key].OrderBy(p => p)];
#endif
string line = $"{key}: {string.Join(", ", fileProtections)}";
Console.WriteLine(line);
sw.WriteLine(line);
}