2025-04-18 11:54:59 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Help
|
|
|
|
|
{
|
|
|
|
|
public class Int64Feature : Feature<long>
|
|
|
|
|
{
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
public Int64Feature(string name, string flag, string description, string? longDescription = null)
|
|
|
|
|
: base(name, flag, description, longDescription)
|
|
|
|
|
{
|
2025-04-18 12:34:53 -04:00
|
|
|
Value = long.MinValue;
|
2025-04-18 11:54:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Int64Feature(string name, string[] flags, string description, string? longDescription = null)
|
|
|
|
|
: base(name, flags, description, longDescription)
|
|
|
|
|
{
|
2025-04-18 12:34:53 -04:00
|
|
|
Value = long.MinValue;
|
2025-04-18 11:54:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Instance Methods
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override bool ValidateInput(string input, bool exact = false, bool ignore = false)
|
|
|
|
|
{
|
|
|
|
|
// Pre-split the input for efficiency
|
|
|
|
|
string[] splitInput = input.Split('=');
|
|
|
|
|
|
|
|
|
|
bool valid = input.Contains("=") && Flags.Contains(splitInput[0]);
|
|
|
|
|
if (valid)
|
|
|
|
|
{
|
|
|
|
|
if (!long.TryParse(splitInput[1], out long value))
|
|
|
|
|
value = long.MinValue;
|
|
|
|
|
|
|
|
|
|
Value = value;
|
|
|
|
|
|
|
|
|
|
// If we've already found this feature before
|
|
|
|
|
if (_foundOnce && !ignore)
|
|
|
|
|
valid = false;
|
|
|
|
|
|
|
|
|
|
_foundOnce = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we haven't found a valid flag and we're not looking for just this feature, check to see if any of the subfeatures are valid
|
|
|
|
|
if (!valid && !exact)
|
|
|
|
|
{
|
|
|
|
|
string[] featureKeys = [.. Features.Keys];
|
|
|
|
|
valid = Array.Exists(featureKeys, k => Features[k]!.ValidateInput(input));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override bool IsEnabled() => Value != long.MinValue;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
protected override string FormatFlags()
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
Flags.ForEach(flag => sb.Append($"{flag}=, "));
|
|
|
|
|
return sb.ToString().TrimEnd(' ', ',');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|