diff --git a/SabreTools.Library/Help/Help.cs b/SabreTools.Library/Help/Help.cs index 365fdcda..7f22bd35 100644 --- a/SabreTools.Library/Help/Help.cs +++ b/SabreTools.Library/Help/Help.cs @@ -3,385 +3,356 @@ using System.Collections.Generic; namespace SabreTools.Library.Help { - public class Help - { - #region Private variables + public class Help + { + #region Private variables - private List _header; - private Dictionary _features; - private static string _barrier = "-----------------------------------------"; + private List _header; + private Dictionary _features; + private static string _barrier = "-----------------------------------------"; - #endregion + #endregion - #region Constructors + #region Constructors - public Help() - { - _header = new List(); - _features = new Dictionary(); - } + public Help() + { + _header = new List(); + _features = new Dictionary(); + } - public Help(List header) - { - _header = header; - _features = new Dictionary(); - } + public Help(List header) + { + _header = header; + _features = new Dictionary(); + } - #endregion + #endregion - #region Accessors + #region Accessors - public Feature this[string name] - { - get - { - if (_features == null) - { - _features = new Dictionary(); - } + public Feature this[string name] + { + get + { + if (_features == null) + _features = new Dictionary(); - if (!_features.ContainsKey(name)) - { - return null; - } + if (!_features.ContainsKey(name)) + return null; - return _features[name]; - } - set - { - if (_features == null) - { - _features = new Dictionary(); - } + return _features[name]; + } + set + { + if (_features == null) + _features = new Dictionary(); - if (_features.ContainsKey(name)) - { - _features[name] = value; - } - else - { - _features.Add(name, value); - } - } - } + _features[name] = value; + } + } - public Feature this[Feature subfeature] - { - get - { - if (_features == null) - { - _features = new Dictionary(); - } + public Feature this[Feature subfeature] + { + get + { + if (_features == null) + _features = new Dictionary(); - if (!_features.ContainsKey(subfeature.Name)) - { - return null; - } + if (!_features.ContainsKey(subfeature.Name)) + return null; - return _features[subfeature.Name]; - } - set - { - if (_features == null) - { - _features = new Dictionary(); - } + return _features[subfeature.Name]; + } + set + { + if (_features == null) + _features = new Dictionary(); - if (_features.ContainsKey(subfeature.Name)) - { - _features[subfeature.Name] = value; - } - else - { - _features.Add(subfeature.Name, value); - } - } - } + _features[subfeature.Name] = value; + } + } - /// - /// Add a new feature to the help - /// - /// Feature object to map to - public void Add(Feature feature) - { - if (_features == null) - { - _features = new Dictionary(); - } + /// + /// Add a new feature to the help + /// + /// Feature object to map to + public void Add(Feature feature) + { + if (_features == null) + _features = new Dictionary(); - lock (_features) - { - _features.Add(feature.Name, feature); - } - } + lock (_features) + { + _features.Add(feature.Name, feature); + } + } - #endregion + #endregion - #region Instance Methods + #region Instance Methods - /// - /// Get the feature name for a given flag or short name - /// - /// Feature name - public string GetFeatureName(string name) - { - string feature = ""; + /// + /// Get the feature name for a given flag or short name + /// + /// Feature name + public string GetFeatureName(string name) + { + string feature = ""; - // Loop through the features - foreach (string featureName in _features.Keys) - { - if (_features[featureName].ValidateInput(name, exact: true, ignore: true)) - { - feature = featureName; - break; - } - } + // Loop through the features + foreach (string featureName in _features.Keys) + { + if (_features[featureName].ValidateInput(name, exact: true, ignore: true)) + { + feature = featureName; + break; + } + } - return feature; - } + return feature; + } - /// - /// Output top-level features only - /// - public void OutputGenericHelp() - { - // Start building the output list - List output = new List(); + /// + /// Output top-level features only + /// + public void OutputGenericHelp() + { + // Start building the output list + List output = new List(); - // Append the header first - output.AddRange(_header); + // Append the header first + output.AddRange(_header); - // Now append all available top-level flags - output.Add("Available options:"); - foreach (string feature in _features.Keys) - { - output.AddRange(_features[feature].Output(pre: 2, midpoint: 30)); - } + // Now append all available top-level flags + output.Add("Available options:"); + foreach (string feature in _features.Keys) + { + output.AddRange(_features[feature].Output(pre: 2, midpoint: 30)); + } - // And append the generic ending - output.Add(""); - output.Add("For information on available flags, put the option name after help"); + // And append the generic ending + output.Add(""); + output.Add("For information on available flags, put the option name after help"); - // Now write out everything in a staged manner - WriteOutWithPauses(output); - } + // Now write out everything in a staged manner + WriteOutWithPauses(output); + } - /// - /// Output all features recursively - /// - public void OutputAllHelp() - { - // Start building the output list - List output = new List(); + /// + /// Output all features recursively + /// + public void OutputAllHelp() + { + // Start building the output list + List output = new List(); - // Append the header first - output.AddRange(_header); + // Append the header first + output.AddRange(_header); - // Now append all available flags recursively - output.Add("Available options:"); - foreach (string feature in _features.Keys) - { - output.AddRange(_features[feature].OutputRecursive(0, pre: 2, midpoint: 30, includeLongDescription: true)); - } + // Now append all available flags recursively + output.Add("Available options:"); + foreach (string feature in _features.Keys) + { + output.AddRange(_features[feature].OutputRecursive(0, pre: 2, midpoint: 30, includeLongDescription: true)); + } - // Now write out everything in a staged manner - WriteOutWithPauses(output); - } + // Now write out everything in a staged manner + WriteOutWithPauses(output); + } - /// - /// Output the SabreTools suite credits - /// - public void OutputCredits() - { - List credits = new List(); - credits.Add(_barrier); - credits.Add("Credits"); - credits.Add(_barrier); - credits.Add(""); - credits.Add("Programmer / Lead: Matt Nadareski (darksabre76)"); - credits.Add("Additional code: emuLOAD, @tractivo, motoschifo"); - credits.Add("Testing: emuLOAD, @tractivo, Kludge, Obiwantje, edc"); - credits.Add("Suggestions: edc, AcidX, Amiga12, EliUmniCk"); - credits.Add("Based on work by: The Wizard of DATz"); - WriteOutWithPauses(credits); - } + /// + /// Output the SabreTools suite credits + /// + public void OutputCredits() + { + List credits = new List(); + credits.Add(_barrier); + credits.Add("Credits"); + credits.Add(_barrier); + credits.Add(""); + credits.Add("Programmer / Lead: Matt Nadareski (darksabre76)"); + credits.Add("Additional code: emuLOAD, @tractivo, motoschifo"); + credits.Add("Testing: emuLOAD, @tractivo, Kludge, Obiwantje, edc"); + credits.Add("Suggestions: edc, AcidX, Amiga12, EliUmniCk"); + credits.Add("Based on work by: The Wizard of DATz"); + WriteOutWithPauses(credits); + } - /// - /// Output a single feature recursively - /// - /// Name of the feature to output information for, if possible - /// True if the long description should be formatted and output, false otherwise - public void OutputIndividualFeature(string featurename, bool includeLongDescription = false) - { - // Start building the output list - List output = new List(); + /// + /// Output a single feature recursively + /// + /// Name of the feature to output information for, if possible + /// True if the long description should be formatted and output, false otherwise + public void OutputIndividualFeature(string featurename, bool includeLongDescription = false) + { + // Start building the output list + List output = new List(); - // Now try to find the feature that has the name included - string realname = null; - List startsWith = new List(); - foreach (string feature in _features.Keys) - { - // If we have a match to the feature name somehow - if (feature == featurename) - { - realname = feature; - break; - } + // Now try to find the feature that has the name included + string realname = null; + List startsWith = new List(); + foreach (string feature in _features.Keys) + { + // If we have a match to the feature name somehow + if (feature == featurename) + { + realname = feature; + break; + } - // If we have a match within the flags - else if (_features[feature].ContainsFlag(featurename)) - { - realname = feature; - break; - } + // If we have a match within the flags + else if (_features[feature].ContainsFlag(featurename)) + { + realname = feature; + break; + } - // Otherwise, we want to get features with the same start - else if (_features[feature].StartsWith(featurename.TrimStart('-')[0])) - { - startsWith.Add(feature); - } - } + // Otherwise, we want to get features with the same start + else if (_features[feature].StartsWith(featurename.TrimStart('-')[0])) + { + startsWith.Add(feature); + } + } - // If we have a real name found, append all available subflags recursively - if (realname != null) - { - output.Add("Available options for " + realname + ":"); - output.AddRange(_features[realname].OutputRecursive(0, pre: 2, midpoint: 30, includeLongDescription: includeLongDescription)); - } + // If we have a real name found, append all available subflags recursively + if (realname != null) + { + output.Add("Available options for " + realname + ":"); + output.AddRange(_features[realname].OutputRecursive(0, pre: 2, midpoint: 30, includeLongDescription: includeLongDescription)); + } - // If no name was found but we have possible matches, show them - else if (startsWith.Count > 0) - { - output.Add("\"" + featurename + "\" not found. Did you mean:"); - foreach (string possible in startsWith) - { - output.AddRange(_features[possible].Output(pre: 2, midpoint: 30, includeLongDescription: includeLongDescription)); - } - } + // If no name was found but we have possible matches, show them + else if (startsWith.Count > 0) + { + output.Add("\"" + featurename + "\" not found. Did you mean:"); + foreach (string possible in startsWith) + { + output.AddRange(_features[possible].Output(pre: 2, midpoint: 30, includeLongDescription: includeLongDescription)); + } + } - // Now write out everything in a staged manner - WriteOutWithPauses(output); - } + // Now write out everything in a staged manner + WriteOutWithPauses(output); + } - /// - /// Check if a flag is a top-level (main application) flag - /// - /// Name of the flag to check - /// True if the feature was found, false otherwise - public bool TopLevelFlag(string flag) - { - bool success = false; + /// + /// Check if a flag is a top-level (main application) flag + /// + /// Name of the flag to check + /// True if the feature was found, false otherwise + public bool TopLevelFlag(string flag) + { + bool success = false; - // Loop through the features and check - foreach (string feature in _features.Keys) - { - if (_features[feature].ValidateInput(flag, exact: true)) - { - success = true; - break; - } - } + // Loop through the features and check + foreach (string feature in _features.Keys) + { + if (_features[feature].ValidateInput(flag, exact: true)) + { + success = true; + break; + } + } - return success; - } + return success; + } - /// - /// Retrieve a list of enabled features - /// - /// List of Features representing what is enabled - public Dictionary GetEnabledFeatures() - { - Dictionary enabled = new Dictionary(); + /// + /// Retrieve a list of enabled features + /// + /// List of Features representing what is enabled + public Dictionary GetEnabledFeatures() + { + Dictionary enabled = new Dictionary(); - // Loop through the features - foreach(KeyValuePair feature in _features) - { - Dictionary temp = GetEnabledSubfeatures(feature.Key, feature.Value); - foreach (KeyValuePair tempfeat in temp) - { - if (!enabled.ContainsKey(tempfeat.Key)) - { - enabled.Add(tempfeat.Key, null); - } - enabled[tempfeat.Key] = tempfeat.Value; - } - } + // Loop through the features + foreach(KeyValuePair feature in _features) + { + Dictionary temp = GetEnabledSubfeatures(feature.Key, feature.Value); + foreach (KeyValuePair tempfeat in temp) + { + if (!enabled.ContainsKey(tempfeat.Key)) + enabled.Add(tempfeat.Key, null); - return enabled; - } + enabled[tempfeat.Key] = tempfeat.Value; + } + } - /// - /// Retrieve a nested list of subfeatures from the current feature - /// - /// Name that should be assigned to the feature - /// Feature with possible subfeatures to test - /// List of Features representing what is enabled - private Dictionary GetEnabledSubfeatures(string key, Feature feature) - { - Dictionary enabled = new Dictionary(); + return enabled; + } - // First determine if the current feature is enabled - if (feature.IsEnabled()) - { - enabled.Add(key, feature); - } + /// + /// Retrieve a nested list of subfeatures from the current feature + /// + /// Name that should be assigned to the feature + /// Feature with possible subfeatures to test + /// List of Features representing what is enabled + private Dictionary GetEnabledSubfeatures(string key, Feature feature) + { + Dictionary enabled = new Dictionary(); - // Now loop through the subfeatures recursively - foreach (KeyValuePair sub in feature.Features) - { - Dictionary temp = GetEnabledSubfeatures(sub.Key, sub.Value); - foreach (KeyValuePair tempfeat in temp) - { - if (!enabled.ContainsKey(tempfeat.Key)) - { - enabled.Add(tempfeat.Key, null); - } - enabled[tempfeat.Key] = tempfeat.Value; - } - } + // First determine if the current feature is enabled + if (feature.IsEnabled()) + { + enabled.Add(key, feature); + } - return enabled; - } + // Now loop through the subfeatures recursively + foreach (KeyValuePair sub in feature.Features) + { + Dictionary temp = GetEnabledSubfeatures(sub.Key, sub.Value); + foreach (KeyValuePair tempfeat in temp) + { + if (!enabled.ContainsKey(tempfeat.Key)) + { + enabled.Add(tempfeat.Key, null); + } + enabled[tempfeat.Key] = tempfeat.Value; + } + } - /// - /// Write out the help text with pauses, if needed - /// - /// - private void WriteOutWithPauses(List helptext) - { - // Now output based on the size of the screen - int i = 0; - for (int line = 0; line < helptext.Count; line++) - { - string help = helptext[line]; + return enabled; + } - Console.WriteLine(help); - i++; + /// + /// Write out the help text with pauses, if needed + /// + /// + private void WriteOutWithPauses(List helptext) + { + // Now output based on the size of the screen + int i = 0; + for (int line = 0; line < helptext.Count; line++) + { + string help = helptext[line]; - // If we're not being redirected and we reached the size of the screen, pause - if (i == Console.WindowHeight - 3 && line != helptext.Count - 1) - { - i = 0; - Pause(); - } - } - Pause(); - } + Console.WriteLine(help); + i++; - /// - /// Pause on console output - /// - private static void Pause() - { - if (!Console.IsOutputRedirected) - { - Console.WriteLine(); - Console.WriteLine("Press enter to continue..."); - Console.ReadLine(); - } - } + // If we're not being redirected and we reached the size of the screen, pause + if (i == Console.WindowHeight - 3 && line != helptext.Count - 1) + { + i = 0; + Pause(); + } + } + Pause(); + } - #endregion - } + /// + /// Pause on console output + /// + private static void Pause() + { + if (!Console.IsOutputRedirected) + { + Console.WriteLine(); + Console.WriteLine("Press enter to continue..."); + Console.ReadLine(); + } + } + + #endregion + } }