Validate installed fpcalc version

This commit is contained in:
ConfusedPolarBear 2022-05-13 16:03:39 -05:00
parent 56fdbef0ec
commit 08c6c48934

View File

@ -14,6 +14,11 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// </summary>
public static class FPCalc
{
/// <summary>
/// Minimum fpcalc version that can be used.
/// </summary>
private static Version minimumFPCalcVersion = new Version(1, 4, 3);
/// <summary>
/// Gets or sets the logger.
/// </summary>
@ -27,9 +32,29 @@ public static class FPCalc
{
try
{
var version = GetOutput("-version", 2000);
Logger?.LogDebug("fpcalc version: {Version}", version);
return version.StartsWith("fpcalc version", StringComparison.OrdinalIgnoreCase);
var rawVersion = GetOutput("-version", 2000).TrimEnd();
if (!rawVersion.StartsWith("fpcalc version", StringComparison.OrdinalIgnoreCase))
{
return false;
}
Logger?.LogDebug("raw fpcalc version: {Version}", rawVersion);
var version = Version.Parse(rawVersion.AsSpan(15));
Logger?.LogDebug("Found fpcalc version {Version}", version);
var okay = version >= minimumFPCalcVersion;
if (!okay)
{
Logger?.LogError(
"installed fpcalc version of {Version} is too old (minimum is {Minimum})",
version,
minimumFPCalcVersion);
}
return okay;
}
catch
{