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

@@ -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
}
}
}