45 lines
1.7 KiB
C#
45 lines
1.7 KiB
C#
using TuneBoss.Core.Models;
|
|
|
|
namespace TuneBoss.Core.IO;
|
|
|
|
/// <summary>
|
|
/// Checks whether a loaded map's tag matches the connected ECU. Mirrors the legacy
|
|
/// open-time check, which warns (but doesn't hard-block) on make/model mismatch.
|
|
/// </summary>
|
|
public static class MapCompatibility
|
|
{
|
|
public enum Result
|
|
{
|
|
Match,
|
|
ModelMismatch,
|
|
MakeMismatch,
|
|
CylinderMismatch,
|
|
}
|
|
|
|
public readonly record struct Report(Result Result, string Message)
|
|
{
|
|
public bool IsMatch => Result == Result.Match;
|
|
}
|
|
|
|
public static Report Check(MapTag tag, EcuInfo ecu, int connectedCylinders)
|
|
{
|
|
if (tag.Make != ecu.BikeManufacturer)
|
|
return new Report(Result.MakeMismatch,
|
|
$"This map is for {BikeRegistry.GetMake((byte)tag.Make)} but the connected unit is " +
|
|
$"{BikeRegistry.GetMake(ecu.BikeManufacturer)}. Loading it is not recommended.");
|
|
|
|
if (tag.Model != ecu.BikeModel)
|
|
return new Report(Result.ModelMismatch,
|
|
$"This map is for {BikeRegistry.GetDisplayName((byte)tag.Make, tag.Model)} but the connected unit is " +
|
|
$"{BikeRegistry.GetDisplayName(ecu.BikeManufacturer, ecu.BikeModel)}. Loading it is not recommended.");
|
|
|
|
if (connectedCylinders > 0 && tag.CylinderCount != connectedCylinders)
|
|
return new Report(Result.CylinderMismatch,
|
|
$"This map is for a {tag.CylinderCount}-cylinder layout but the connected unit is " +
|
|
$"{connectedCylinders}-cylinder.");
|
|
|
|
return new Report(Result.Match,
|
|
$"Map matches the connected {BikeRegistry.GetDisplayName(ecu.BikeManufacturer, ecu.BikeModel)}.");
|
|
}
|
|
}
|