2020-06-10 22:37:19 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2024-10-24 00:36:44 -04:00
|
|
|
|
using SabreTools.IO.Logging;
|
2020-12-07 14:29:45 -08:00
|
|
|
|
|
2020-12-07 13:57:26 -08:00
|
|
|
|
namespace SabreTools.Help
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents an actionable top-level feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract class TopLevel : Feature
|
|
|
|
|
|
{
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List of files, directories, and potential wildcard paths
|
|
|
|
|
|
/// </summary>
|
2024-07-18 00:32:41 -04:00
|
|
|
|
public readonly List<string> Inputs = [];
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
#region Logging
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Logging object
|
|
|
|
|
|
/// </summary>
|
2020-12-07 14:29:45 -08:00
|
|
|
|
private readonly Logger logger;
|
2020-10-07 16:37:10 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public TopLevel()
|
|
|
|
|
|
{
|
2020-12-07 14:29:45 -08:00
|
|
|
|
logger = new Logger(this);
|
2020-10-07 16:37:10 -07:00
|
|
|
|
}
|
2020-10-07 15:42:30 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#region Processing
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process args list based on current feature
|
|
|
|
|
|
/// </summary>
|
2020-12-08 17:05:08 -08:00
|
|
|
|
public virtual bool ProcessArgs(string[] args, FeatureSet help)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
for (int i = 1; i < args.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Verify that the current flag is proper for the feature
|
2024-07-18 00:32:41 -04:00
|
|
|
|
if (ValidateInput(args[i]))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Special precautions for files and directories
|
|
|
|
|
|
if (File.Exists(args[i]) || Directory.Exists(args[i]))
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
2024-07-18 00:32:41 -04:00
|
|
|
|
Inputs.Add(item: args[i]);
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2024-07-18 00:32:41 -04:00
|
|
|
|
// Special precautions for wildcarded inputs (potential paths)
|
2024-02-28 23:14:21 -05:00
|
|
|
|
#if NETFRAMEWORK
|
2024-07-18 00:32:41 -04:00
|
|
|
|
else if (args[i].Contains("*") || args[i].Contains("?"))
|
2024-02-28 23:14:21 -05:00
|
|
|
|
#else
|
2024-07-18 00:32:41 -04:00
|
|
|
|
else if (args[i].Contains('*') || args[i].Contains('?'))
|
2024-02-28 23:14:21 -05:00
|
|
|
|
#endif
|
2024-07-18 00:32:41 -04:00
|
|
|
|
{
|
|
|
|
|
|
Inputs.Add(args[i]);
|
|
|
|
|
|
}
|
2020-08-08 21:53:34 -07:00
|
|
|
|
|
2024-07-18 00:32:41 -04:00
|
|
|
|
// Everything else isn't a file
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.Error($"Invalid input detected: {args[i]}");
|
|
|
|
|
|
help.OutputIndividualFeature(Name);
|
|
|
|
|
|
LoggerImpl.Close();
|
|
|
|
|
|
return false;
|
2020-08-17 14:37:37 -07:00
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process and extract variables based on current feature
|
|
|
|
|
|
/// </summary>
|
2021-03-19 20:52:11 -07:00
|
|
|
|
/// <returns>True if execution was successful, false otherwise</returns>
|
2024-03-05 20:26:38 -05:00
|
|
|
|
public virtual bool ProcessFeatures(Dictionary<string, Feature?> features) => true;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
#region Generic Extraction
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get boolean value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2024-03-05 20:26:38 -05:00
|
|
|
|
protected static bool GetBoolean(Dictionary<string, Feature?> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get int value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2024-03-05 20:26:38 -05:00
|
|
|
|
protected static int GetInt32(Dictionary<string, Feature?> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return Int32.MinValue;
|
|
|
|
|
|
|
2024-03-05 20:26:38 -05:00
|
|
|
|
return features[key]!.GetInt32Value();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get long value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2024-03-05 20:26:38 -05:00
|
|
|
|
protected static long GetInt64(Dictionary<string, Feature?> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return Int64.MinValue;
|
|
|
|
|
|
|
2024-03-05 20:26:38 -05:00
|
|
|
|
return features[key]!.GetInt64Value();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get list value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2024-03-05 20:26:38 -05:00
|
|
|
|
protected static List<string> GetList(Dictionary<string, Feature?> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
2024-02-28 19:19:50 -05:00
|
|
|
|
return [];
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2024-03-05 20:26:38 -05:00
|
|
|
|
return features[key]!.GetListValue() ?? [];
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get string value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2024-03-05 20:26:38 -05:00
|
|
|
|
protected static string? GetString(Dictionary<string, Feature?> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
2024-03-11 16:26:28 -04:00
|
|
|
|
return features[key]!.GetStringFieldValue();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|