2021-03-19 15:41:49 -07:00
|
|
|
using System;
|
2021-07-18 09:44:23 -07:00
|
|
|
using System.Collections.Concurrent;
|
2021-03-19 15:41:49 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2022-05-01 17:41:50 -07:00
|
|
|
using BurnOutSharp.Interfaces;
|
2021-03-22 22:23:55 -07:00
|
|
|
using BurnOutSharp.Matching;
|
2021-03-19 15:41:49 -07:00
|
|
|
|
|
|
|
|
namespace BurnOutSharp.ProtectionType
|
|
|
|
|
{
|
|
|
|
|
public class BDPlus : IPathCheck
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
|
2021-03-19 15:41:49 -07:00
|
|
|
{
|
2021-03-22 22:23:55 -07:00
|
|
|
var matchers = new List<PathMatchSet>
|
2021-03-19 15:41:49 -07:00
|
|
|
{
|
2021-03-22 22:23:55 -07:00
|
|
|
new PathMatchSet(new List<string>
|
|
|
|
|
{
|
2021-07-17 22:31:29 -07:00
|
|
|
Path.Combine("BDSVM", "00000.svm").Replace("\\", "/"),
|
|
|
|
|
Path.Combine("BDSVM", "BACKUP", "00000.svm").Replace("\\", "/"),
|
2021-03-22 22:23:55 -07:00
|
|
|
}, GetVersion, "BD+"),
|
|
|
|
|
};
|
2021-03-19 15:41:49 -07:00
|
|
|
|
2021-03-23 13:35:12 -07:00
|
|
|
return MatchUtil.GetAllMatches(files, matchers, any: true);
|
2021-03-19 15:41:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public string CheckFilePath(string path)
|
|
|
|
|
{
|
2021-03-22 22:23:55 -07:00
|
|
|
var matchers = new List<PathMatchSet>
|
2021-03-19 15:41:49 -07:00
|
|
|
{
|
2021-03-22 22:23:55 -07:00
|
|
|
new PathMatchSet(new PathMatch("00000.svm", useEndsWith: true), GetVersion, "BD+"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return MatchUtil.GetFirstMatch(path, matchers, any: true);
|
2021-03-19 15:41:49 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 22:23:55 -07:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Version detection logic from libbdplus was used to implement this
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public static string GetVersion(string firstMatchedString, IEnumerable<string> files)
|
2021-03-19 15:41:49 -07:00
|
|
|
{
|
2021-03-22 22:23:55 -07:00
|
|
|
if (!File.Exists(firstMatchedString))
|
|
|
|
|
return "(Unknown Version)";
|
2021-03-20 22:00:38 -07:00
|
|
|
|
2021-03-19 15:41:49 -07:00
|
|
|
try
|
|
|
|
|
{
|
2021-03-22 22:23:55 -07:00
|
|
|
using (var fs = File.OpenRead(firstMatchedString))
|
2021-03-19 15:41:49 -07:00
|
|
|
{
|
2021-03-20 22:00:38 -07:00
|
|
|
fs.Seek(0x0D, SeekOrigin.Begin);
|
|
|
|
|
byte[] date = new byte[4];
|
|
|
|
|
fs.Read(date, 0, 4); //yymd
|
2021-03-20 22:28:57 -07:00
|
|
|
short year = BitConverter.ToInt16(date.Reverse().ToArray(), 2);
|
2021-03-19 15:41:49 -07:00
|
|
|
|
2021-03-20 22:00:38 -07:00
|
|
|
// Do some rudimentary date checking
|
|
|
|
|
if (year < 2006 || year > 2100 || date[2] < 1 || date[2] > 12 || date[3] < 1 || date[3] > 31)
|
2021-03-22 22:23:55 -07:00
|
|
|
return "(Invalid Version)";
|
2021-03-19 15:41:49 -07:00
|
|
|
|
2021-03-20 22:28:57 -07:00
|
|
|
return $"{year:0000}/{date[2]:00}/{date[3]:00}";
|
2021-03-19 15:41:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2021-03-22 22:23:55 -07:00
|
|
|
return "(Unknown Version)";
|
2021-03-19 15:41:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|