using System;
using System.Collections.Generic;
namespace TownOfUsStatsExporter.Reflection;
///
/// Manages version compatibility checks for TOU Mira.
///
public static class VersionCompatibility
{
private static readonly HashSet TestedVersions = new()
{
"1.2.1",
"1.2.0",
};
private static readonly HashSet IncompatibleVersions = new()
{
// Add any known incompatible versions here
};
///
/// Checks if a version is compatible.
///
/// The version to check.
/// A string describing the compatibility status.
public static string CheckVersion(string? version)
{
if (string.IsNullOrEmpty(version))
{
return "Unsupported: Version unknown";
}
// Parse version
if (!Version.TryParse(version, out var parsedVersion))
{
return $"Unsupported: Cannot parse version '{version}'";
}
// Check if explicitly incompatible
if (IncompatibleVersions.Contains(version))
{
return $"Unsupported: Version {version} is known to be incompatible";
}
// Check if tested
if (TestedVersions.Contains(version))
{
return $"Supported: Version {version} is tested and compatible";
}
// Check if it's a newer minor/patch version
foreach (var testedVersion in TestedVersions)
{
if (Version.TryParse(testedVersion, out var tested))
{
// Same major version = probably compatible
if (parsedVersion.Major == tested.Major)
{
return $"Probably Compatible: Version {version} (tested with {testedVersion})";
}
}
}
return $"Unsupported: Version {version} has not been tested";
}
///
/// Adds a version to the tested versions list.
///
/// The version to add.
public static void AddTestedVersion(string version)
{
TestedVersions.Add(version);
}
///
/// Adds a version to the incompatible versions list.
///
/// The version to add.
public static void AddIncompatibleVersion(string version)
{
IncompatibleVersions.Add(version);
}
}