diff --git a/BurnOutSharp/ProtectionType/AACS.cs b/BurnOutSharp/ProtectionType/AACS.cs
index 845e3c8a..717879f1 100644
--- a/BurnOutSharp/ProtectionType/AACS.cs
+++ b/BurnOutSharp/ProtectionType/AACS.cs
@@ -30,14 +30,12 @@ namespace BurnOutSharp.ProtectionType
string filename = Path.GetFileName(path);
if (filename.Equals("MKBROM.AACS", StringComparison.OrdinalIgnoreCase))
{
- string file = path;
- int? version = GetVersion(file);
+ int? version = GetVersion(path);
return (version == null ? "AACS (Unknown Version)" : $"AACS Version {version}");
}
if (filename.Equals("MKB_RO.inf", StringComparison.OrdinalIgnoreCase))
{
- string file = path;
- int? version = GetVersion(file);
+ int? version = GetVersion(path);
return (version == null ? "AACS (Unknown Version)" : $"AACS Version {version}");
}
}
diff --git a/BurnOutSharp/ProtectionType/BD+.cs b/BurnOutSharp/ProtectionType/BD+.cs
index 1cfed3d2..0c5c81e5 100644
--- a/BurnOutSharp/ProtectionType/BD+.cs
+++ b/BurnOutSharp/ProtectionType/BD+.cs
@@ -7,7 +7,6 @@ namespace BurnOutSharp.ProtectionType
{
public class BDPlus : IPathCheck
{
- // TODO: Figure out how to detect version
///
public string CheckPath(string path, bool isDirectory, IEnumerable files)
{
@@ -17,11 +16,52 @@ namespace BurnOutSharp.ProtectionType
if (files.Any(f => f.Contains(Path.Combine("BDSVM", "00000.svm")))
&& files.Any(f => f.Contains(Path.Combine("BDSVM", "BACKUP", "00000.svm"))))
{
- return "BD+";
+ 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 {version}");
+ }
+ }
+ else
+ {
+ string filename = Path.GetFileName(path);
+ if (filename.Equals("00000.svm", StringComparison.OrdinalIgnoreCase))
+ {
+ string version = GetVersion(path);
+ return (version == null ? "BD+ (Unknown Version)" : $"BD+ Version {version}");
}
}
return null;
}
+
+ // Version detection logic from libbdplus was used to implement this
+ private static string GetVersion(string path)
+ {
+ try
+ {
+ using (var fs = File.OpenRead(path))
+ {
+ fs.Seek(0x0d, SeekOrigin.Begin);
+ int year1 = fs.ReadByte();
+ int year2 = fs.ReadByte();
+ int month = fs.ReadByte();
+ int day = fs.ReadByte();
+
+ int year = (year1 << 8) | year2;
+
+ // If the result isn't a valid date, report it as an unknown version
+ if (year < 2006 || year > 2100 || month < 1 || month > 12 || day < 1 || day > 31)
+ {
+ return null;
+ }
+
+ return $"{year}/{month}/{day}";
+ }
+ }
+ catch
+ {
+ return null;
+ }
+ }
}
}