Added BD+ version detection (#26)

* Added BD+ version detection

* Address Comments

* Address comment

* Remove unnecessary assignment
This commit is contained in:
SilasLaspada
2021-03-18 11:50:45 -06:00
committed by GitHub
parent 854a257fd6
commit 30d3312d87
2 changed files with 44 additions and 6 deletions

View File

@@ -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}");
}
}

View File

@@ -7,7 +7,6 @@ namespace BurnOutSharp.ProtectionType
{
public class BDPlus : IPathCheck
{
// TODO: Figure out how to detect version
/// <inheritdoc/>
public string CheckPath(string path, bool isDirectory, IEnumerable<string> 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;
}
}
}
}