diff --git a/BurnOutSharp/ProtectionType/AACS.cs b/BurnOutSharp/ProtectionType/AACS.cs index e6e5c5b1..11ef64a1 100644 --- a/BurnOutSharp/ProtectionType/AACS.cs +++ b/BurnOutSharp/ProtectionType/AACS.cs @@ -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 { // 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); diff --git a/BurnOutSharp/ProtectionType/AlphaDVD.cs b/BurnOutSharp/ProtectionType/AlphaDVD.cs index 13d19478..42dfd9b5 100644 --- a/BurnOutSharp/ProtectionType/AlphaDVD.cs +++ b/BurnOutSharp/ProtectionType/AlphaDVD.cs @@ -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 /// public string CheckDirectoryPath(string path, IEnumerable files) { - if (files.Any(f => Path.GetFileName(f).Equals("PlayDVD.exe", StringComparison.OrdinalIgnoreCase))) - return "Alpha-DVD"; + var matchers = new List + { + new PathMatchSet(new PathMatch("PlayDVD.exe", useEndsWith: true), "Alpha-DVD"), + }; - return null; + var matches = MatchUtil.GetAllMatches(files, matchers, any: true); + return string.Join(", ", matches); } /// public string CheckFilePath(string path) { - if (Path.GetFileName(path).Equals("PlayDVD.exe", StringComparison.OrdinalIgnoreCase)) - return "Alpha-DVD"; - - return null; + var matchers = new List + { + new PathMatchSet(new PathMatch("PlayDVD.exe", useEndsWith: true), "Alpha-DVD"), + }; + + return MatchUtil.GetFirstMatch(path, matchers, any: true); } } } diff --git a/BurnOutSharp/ProtectionType/BDPlus.cs b/BurnOutSharp/ProtectionType/BDPlus.cs index ab572c22..9940a88e 100644 --- a/BurnOutSharp/ProtectionType/BDPlus.cs +++ b/BurnOutSharp/ProtectionType/BDPlus.cs @@ -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 /// public string CheckDirectoryPath(string path, IEnumerable 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 { - 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 + { + 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); } /// public string CheckFilePath(string path) { - string filename = Path.GetFileName(path); - if (filename.Equals("00000.svm", StringComparison.OrdinalIgnoreCase)) + var matchers = new List { - 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); } - /// Version detection logic from libbdplus was used to implement this - private static string GetVersion(string path) + /// + /// Version detection logic from libbdplus was used to implement this + /// + public static string GetVersion(string firstMatchedString, IEnumerable 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)"; } } } diff --git a/BurnOutSharp/ProtectionType/Bitpool.cs b/BurnOutSharp/ProtectionType/Bitpool.cs index b3daaca4..60f0b94f 100644 --- a/BurnOutSharp/ProtectionType/Bitpool.cs +++ b/BurnOutSharp/ProtectionType/Bitpool.cs @@ -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 /// public string CheckDirectoryPath(string path, IEnumerable files) { - if (files.Any(f => Path.GetFileName(f).Equals("bitpool.rsc", StringComparison.OrdinalIgnoreCase))) - return "Bitpool"; + var matchers = new List + { + new PathMatchSet(new PathMatch("bitpool.rsc", useEndsWith: true), "Bitpool"), + }; - return null; + var matches = MatchUtil.GetAllMatches(files, matchers, any: true); + return string.Join(", ", matches); } /// public string CheckFilePath(string path) { - if (Path.GetFileName(path).Equals("bitpool.rsc", StringComparison.OrdinalIgnoreCase)) - return "Bitpool"; - - return null; + var matchers = new List + { + new PathMatchSet(new PathMatch("bitpool.rsc", useEndsWith: true), "Bitpool"), + }; + + return MatchUtil.GetFirstMatch(path, matchers, any: true); } } } diff --git a/BurnOutSharp/ProtectionType/ByteShield.cs b/BurnOutSharp/ProtectionType/ByteShield.cs index 7814822f..f834969b 100644 --- a/BurnOutSharp/ProtectionType/ByteShield.cs +++ b/BurnOutSharp/ProtectionType/ByteShield.cs @@ -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 /// public string CheckDirectoryPath(string path, IEnumerable 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 { - 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); } /// 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 { - 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); } } }