Convert a few more path checks

This commit is contained in:
Matt Nadareski
2021-03-22 22:23:55 -07:00
parent 532e912a2d
commit 76d76b2bf2
5 changed files with 69 additions and 61 deletions

View File

@@ -18,7 +18,7 @@ namespace BurnOutSharp.ProtectionType
new PathMatchSet(Path.Combine("AACS", "MKBROM.AACS"), GetVersion, "AACS"),
};
var matches = MatchUtil.GetFirstMatch(files, matchers, any: true);
var matches = MatchUtil.GetAllMatches(files, matchers, any: true);
return string.Join(", ", matches);
}
@@ -28,10 +28,10 @@ namespace BurnOutSharp.ProtectionType
var matchers = new List<PathMatchSet>
{
// BD-ROM
new PathMatchSet("MKB_RO.inf", GetVersion, "AACS"),
new PathMatchSet(new PathMatch("MKB_RO.inf", useEndsWith: true), GetVersion, "AACS"),
// HD-DVD
new PathMatchSet("MKBROM.AACS", GetVersion, "AACS"),
new PathMatchSet(new PathMatch("MKBROM.AACS", useEndsWith: true), GetVersion, "AACS"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
@@ -10,19 +8,24 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckDirectoryPath(string path, IEnumerable<string> files)
{
if (files.Any(f => Path.GetFileName(f).Equals("PlayDVD.exe", StringComparison.OrdinalIgnoreCase)))
return "Alpha-DVD";
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("PlayDVD.exe", useEndsWith: true), "Alpha-DVD"),
};
return null;
var matches = MatchUtil.GetAllMatches(files, matchers, any: true);
return string.Join(", ", matches);
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
if (Path.GetFileName(path).Equals("PlayDVD.exe", StringComparison.OrdinalIgnoreCase))
return "Alpha-DVD";
return null;
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("PlayDVD.exe", useEndsWith: true), "Alpha-DVD"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
}
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
@@ -10,39 +11,41 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckDirectoryPath(string path, IEnumerable<string> files)
{
if (files.Any(f => f.Contains(Path.Combine("BDSVM", "00000.svm")))
&& files.Any(f => f.Contains(Path.Combine("BDSVM", "BACKUP", "00000.svm"))))
var matchers = new List<PathMatchSet>
{
string file = files.FirstOrDefault(f => Path.GetFileName(f).Equals("00000.svm", StringComparison.OrdinalIgnoreCase));
string version = GetVersion(file);
return version == null ? "BD+ (Unknown Version)" : $"BD+ {version}";
}
new PathMatchSet(new List<string>
{
Path.Combine("BDSVM", "00000.svm"),
Path.Combine("BDSVM", "BACKUP", "00000.svm"),
}, GetVersion, "BD+"),
};
return null;
var matches = MatchUtil.GetAllMatches(files, matchers, any: true);
return string.Join(", ", matches);
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
string filename = Path.GetFileName(path);
if (filename.Equals("00000.svm", StringComparison.OrdinalIgnoreCase))
var matchers = new List<PathMatchSet>
{
string version = GetVersion(path);
return version == null ? "BD+ (Unknown Version)" : $"BD+ {version}";
}
return null;
new PathMatchSet(new PathMatch("00000.svm", useEndsWith: true), GetVersion, "BD+"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
/// <remarks>Version detection logic from libbdplus was used to implement this</remarks>
private static string GetVersion(string path)
/// <remarks>
/// Version detection logic from libbdplus was used to implement this
/// </remarks>
public static string GetVersion(string firstMatchedString, IEnumerable<string> files)
{
if (!File.Exists(path))
return null;
if (!File.Exists(firstMatchedString))
return "(Unknown Version)";
try
{
using (var fs = File.OpenRead(path))
using (var fs = File.OpenRead(firstMatchedString))
{
fs.Seek(0x0D, SeekOrigin.Begin);
byte[] date = new byte[4];
@@ -51,14 +54,14 @@ namespace BurnOutSharp.ProtectionType
// Do some rudimentary date checking
if (year < 2006 || year > 2100 || date[2] < 1 || date[2] > 12 || date[3] < 1 || date[3] > 31)
return null;
return "(Invalid Version)";
return $"{year:0000}/{date[2]:00}/{date[3]:00}";
}
}
catch
{
return null;
return "(Unknown Version)";
}
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
@@ -10,19 +8,24 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckDirectoryPath(string path, IEnumerable<string> files)
{
if (files.Any(f => Path.GetFileName(f).Equals("bitpool.rsc", StringComparison.OrdinalIgnoreCase)))
return "Bitpool";
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("bitpool.rsc", useEndsWith: true), "Bitpool"),
};
return null;
var matches = MatchUtil.GetAllMatches(files, matchers, any: true);
return string.Join(", ", matches);
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
if (Path.GetFileName(path).Equals("bitpool.rsc", StringComparison.OrdinalIgnoreCase))
return "Bitpool";
return null;
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("bitpool.rsc", useEndsWith: true), "Bitpool"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
@@ -10,25 +8,26 @@ namespace BurnOutSharp.ProtectionType
/// <inheritdoc/>
public string CheckDirectoryPath(string path, IEnumerable<string> files)
{
if (files.Any(f => Path.GetFileName(f).Equals("Byteshield.dll", StringComparison.OrdinalIgnoreCase))
|| files.Any(f => Path.GetExtension(f).Trim('.').Equals("bbz", StringComparison.OrdinalIgnoreCase)))
var matchers = new List<PathMatchSet>
{
return "ByteShield";
}
new PathMatchSet(new PathMatch("Byteshield.dll", useEndsWith: true), "ByteShield"),
new PathMatchSet(new PathMatch(".bbz", useEndsWith: true), "ByteShield"),
};
return null;
var matches = MatchUtil.GetAllMatches(files, matchers, any: true);
return string.Join(", ", matches);
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
if (Path.GetFileName(path).Equals("Byteshield.dll", StringComparison.OrdinalIgnoreCase)
|| Path.GetExtension(path).Trim('.').Equals("bbz", StringComparison.OrdinalIgnoreCase))
var matchers = new List<PathMatchSet>
{
return "ByteShield";
}
return null;
new PathMatchSet(new PathMatch("Byteshield.dll", useEndsWith: true), "ByteShield"),
new PathMatchSet(new PathMatch(".bbz", useEndsWith: true), "ByteShield"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
}
}