Split content and path version checks

This commit is contained in:
Matt Nadareski
2021-03-22 10:04:33 -07:00
parent 95a61c3b28
commit a4aeebee68
2 changed files with 28 additions and 12 deletions

View File

@@ -83,7 +83,7 @@ namespace BurnOutSharp.Matching
string positionsString = string.Join(", ", positions);
// If we there is no version method, just return the protection name
if (matcher.GetVersion == null)
if (matcher.GetContentVersion == null)
{
matchedProtections.Add((matcher.ProtectionName ?? "Unknown Protection") + (includePosition ? $" (Index {positionsString})" : string.Empty));
}
@@ -92,7 +92,7 @@ namespace BurnOutSharp.Matching
// TODO: Pass all positions to the version finding method
else
{
string version = matcher.GetVersion(file, fileContent, positions[0]) ?? "Unknown Version";
string version = matcher.GetContentVersion(file, fileContent, positions[0]) ?? "Unknown Version";
matchedProtections.Add($"{matcher.ProtectionName ?? "Unknown Protection"} {version}" + (includePosition ? $" (Index {positionsString})" : string.Empty));
}
@@ -195,8 +195,18 @@ namespace BurnOutSharp.Matching
if (!passes)
continue;
//Add the matched protection
matchedProtections.Add(matcher.ProtectionName ?? "Unknown Protection");
// If we there is no version method, just return the protection name
if (matcher.GetPathVersion == null)
{
matchedProtections.Add(matcher.ProtectionName ?? "Unknown Protection");
}
// Otherwise, invoke the version method
else
{
string version = matcher.GetPathVersion(files) ?? "Unknown Version";
matchedProtections.Add($"{matcher.ProtectionName ?? "Unknown Protection"} {version}");
}
// If we're stopping after the first protection, bail out here
if (stopAfterFirst)

View File

@@ -14,16 +14,22 @@ namespace BurnOutSharp.Matching
/// </summary>
public IEnumerable<ContentMatch> ContentMatches { get; set; }
/// <summary>
/// Function to get a content version for this Matcher
/// </summary>
/// TODO: Can this be made more generic?
public Func<string, byte[], int, string> GetContentVersion { get; set; }
/// <summary>
/// Set of all path matches
/// </summary>
public IEnumerable<PathMatch> PathMatches { get; set; }
/// <summary>
/// Function to get a version for this Matcher
/// Function to get a path version for this Matcher
/// </summary>
/// TODO: Can this be made more generic?
public Func<string, byte[], int, string> GetVersion { get; set; }
public Func<List<string>, string> GetPathVersion { get; set; }
/// <summary>
/// Name of the protection to show
@@ -56,7 +62,7 @@ namespace BurnOutSharp.Matching
public Matcher(List<ContentMatch> needles, Func<string, byte[], int, string> getVersion, string protectionName)
{
ContentMatches = needles;
GetVersion = getVersion;
GetContentVersion = getVersion;
ProtectionName = protectionName;
}
@@ -70,10 +76,10 @@ namespace BurnOutSharp.Matching
public Matcher(List<string> needles, string protectionName)
: this(needles, null, protectionName) { }
public Matcher(string needle, Func<string, byte[], int, string> getVersion, string protectionName)
public Matcher(string needle, Func<List<string>, string> getVersion, string protectionName)
: this(new List<string> { needle }, getVersion, protectionName) { }
public Matcher(List<string> needles, Func<string, byte[], int, string> getVersion, string protectionName)
public Matcher(List<string> needles, Func<List<string>, string> getVersion, string protectionName)
: this(needles.Select(n => new PathMatch(n)).ToList(), getVersion, protectionName) { }
public Matcher(PathMatch needle, string protectionName)
@@ -82,13 +88,13 @@ namespace BurnOutSharp.Matching
public Matcher(List<PathMatch> needles, string protectionName)
: this(needles, null, protectionName) { }
public Matcher(PathMatch needle, Func<string, byte[], int, string> getVersion, string protectionName)
public Matcher(PathMatch needle, Func<List<string>, string> getVersion, string protectionName)
: this(new List<PathMatch>() { needle }, getVersion, protectionName) { }
public Matcher(List<PathMatch> needles, Func<string, byte[], int, string> getVersion, string protectionName)
public Matcher(List<PathMatch> needles, Func<List<string>, string> getVersion, string protectionName)
{
PathMatches = needles;
GetVersion = getVersion;
GetPathVersion = getVersion;
ProtectionName = protectionName;
}