mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, Feature, Help] Use Help more...
This commit is contained in:
@@ -358,6 +358,8 @@
|
||||
{
|
||||
Flag = 0,
|
||||
String,
|
||||
Int32,
|
||||
Int64,
|
||||
List,
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,26 @@ namespace SabreTools.Library.Help
|
||||
|
||||
// Specific value types
|
||||
private bool _valueBool = false;
|
||||
private int _valueInt32 = Int32.MinValue;
|
||||
private long _valueInt64 = Int64.MinValue;
|
||||
private string _valueString = null;
|
||||
private List<string> _valueList = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Publicly facing variables
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return _description; }
|
||||
}
|
||||
public Dictionary<string, Feature> Features
|
||||
{
|
||||
get { return _features; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public Feature()
|
||||
@@ -336,8 +351,9 @@ namespace SabreTools.Library.Help
|
||||
/// </summary>
|
||||
/// <param name="input">Input to check against</param>
|
||||
/// <param name="exact">True if just this feature should be checked, false if all subfeatures are checked as well</param>
|
||||
/// <param name="ignore">True if the existing flag should be ignored, false otherwise</param>
|
||||
/// <returns>True if the flag was valid, false otherwise</returns>
|
||||
public bool ValidateInput(string input, bool exact = false)
|
||||
public bool ValidateInput(string input, bool exact = false, bool ignore = false)
|
||||
{
|
||||
bool valid = false;
|
||||
|
||||
@@ -350,10 +366,56 @@ namespace SabreTools.Library.Help
|
||||
if (valid)
|
||||
{
|
||||
_valueBool = true;
|
||||
|
||||
// If we've already found this feature before
|
||||
if (_foundOnce && !ignore)
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
_foundOnce = true;
|
||||
}
|
||||
break;
|
||||
// If we have an Int32, try to parse it if at all possible
|
||||
case FeatureType.Int32:
|
||||
valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]);
|
||||
if (valid)
|
||||
{
|
||||
if (!Int32.TryParse(input.Split('=')[1], out int value))
|
||||
{
|
||||
value = Int32.MinValue;
|
||||
}
|
||||
_valueInt32 = value;
|
||||
|
||||
// If we've already found this feature before
|
||||
if (_foundOnce && !ignore)
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
_foundOnce = true;
|
||||
}
|
||||
break;
|
||||
// If we have an Int32, try to parse it if at all possible
|
||||
case FeatureType.Int64:
|
||||
valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]);
|
||||
if (valid)
|
||||
{
|
||||
if (!Int64.TryParse(input.Split('=')[1], out long value))
|
||||
{
|
||||
value = Int64.MinValue;
|
||||
}
|
||||
_valueInt64 = value;
|
||||
|
||||
// If we've already found this feature before
|
||||
if (_foundOnce && !ignore)
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
_foundOnce = true;
|
||||
}
|
||||
break;
|
||||
// If we have an input, make sure it has an equals sign in it
|
||||
case FeatureType.List:
|
||||
valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]);
|
||||
@@ -372,6 +434,13 @@ namespace SabreTools.Library.Help
|
||||
if (valid)
|
||||
{
|
||||
_valueString = input.Split('=')[1];
|
||||
|
||||
// If we've already found this feature before
|
||||
if (_foundOnce && !ignore)
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
_foundOnce = true;
|
||||
}
|
||||
break;
|
||||
@@ -392,12 +461,6 @@ namespace SabreTools.Library.Help
|
||||
}
|
||||
}
|
||||
|
||||
// If we've already found this flag before and we don't allow duplicates, set valid to false
|
||||
if (valid && _foundOnce && _featureType != FeatureType.List)
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// If we're not valid at this point, we want to check if this flag is a file or a folder
|
||||
if (!valid)
|
||||
{
|
||||
@@ -417,6 +480,10 @@ namespace SabreTools.Library.Help
|
||||
{
|
||||
case FeatureType.Flag:
|
||||
return _valueBool;
|
||||
case FeatureType.Int32:
|
||||
return _valueInt32;
|
||||
case FeatureType.Int64:
|
||||
return _valueInt64;
|
||||
case FeatureType.List:
|
||||
return _valueList;
|
||||
case FeatureType.String:
|
||||
@@ -438,6 +505,10 @@ namespace SabreTools.Library.Help
|
||||
{
|
||||
case FeatureType.Flag:
|
||||
return (bool)obj;
|
||||
case FeatureType.Int32:
|
||||
return (int)obj != Int32.MinValue;
|
||||
case FeatureType.Int64:
|
||||
return (long)obj != Int64.MinValue;
|
||||
case FeatureType.List:
|
||||
return obj != null;
|
||||
case FeatureType.String:
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace SabreTools.Library.Help
|
||||
// Loop through the features
|
||||
foreach (string featureName in _features.Keys)
|
||||
{
|
||||
if (_features[featureName].ValidateInput(name, exact: true))
|
||||
if (_features[featureName].ValidateInput(name, exact: true, ignore: true))
|
||||
{
|
||||
feature = featureName;
|
||||
break;
|
||||
@@ -259,14 +259,22 @@ namespace SabreTools.Library.Help
|
||||
/// Retrieve a list of enabled features
|
||||
/// </summary>
|
||||
/// <returns>List of Features representing what is enabled</returns>
|
||||
public List<Feature> GetEnabledFeatures()
|
||||
public Dictionary<string, Feature> GetEnabledFeatures()
|
||||
{
|
||||
List<Feature> enabled = new List<Feature>();
|
||||
Dictionary<string, Feature> enabled = new Dictionary<string, Feature>();
|
||||
|
||||
// Loop through the features
|
||||
foreach(KeyValuePair<string, Feature> feature in _features)
|
||||
{
|
||||
enabled.AddRange(GetEnabledSubfeatures(feature.Value));
|
||||
Dictionary<string, Feature> temp = GetEnabledSubfeatures(feature.Key, feature.Value);
|
||||
foreach (KeyValuePair<string, Feature> tempfeat in temp)
|
||||
{
|
||||
if (!enabled.ContainsKey(tempfeat.Key))
|
||||
{
|
||||
enabled.Add(tempfeat.Key, null);
|
||||
}
|
||||
enabled[tempfeat.Key] = tempfeat.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return enabled;
|
||||
@@ -275,22 +283,31 @@ namespace SabreTools.Library.Help
|
||||
/// <summary>
|
||||
/// Retrieve a nested list of subfeatures from the current feature
|
||||
/// </summary>
|
||||
/// <param name="key">Name that should be assigned to the feature</param>
|
||||
/// <param name="feature">Feature with possible subfeatures to test</param>
|
||||
/// <returns>List of Features representing what is enabled</returns>
|
||||
private List<Feature> GetEnabledSubfeatures(Feature feature)
|
||||
private Dictionary<string, Feature> GetEnabledSubfeatures(string key, Feature feature)
|
||||
{
|
||||
List<Feature> enabled = new List<Feature>();
|
||||
Dictionary<string, Feature> enabled = new Dictionary<string, Feature>();
|
||||
|
||||
// First determine if the current feature is enabled
|
||||
if (feature.IsEnabled())
|
||||
{
|
||||
enabled.Add(feature);
|
||||
enabled.Add(key, feature);
|
||||
}
|
||||
|
||||
// Now loop through the subfeatures recursively
|
||||
foreach (KeyValuePair<string, Feature> sub in _features)
|
||||
foreach (KeyValuePair<string, Feature> sub in feature.Features)
|
||||
{
|
||||
enabled.AddRange(GetEnabledSubfeatures(sub.Value));
|
||||
Dictionary<string, Feature> temp = GetEnabledSubfeatures(sub.Key, sub.Value);
|
||||
foreach (KeyValuePair<string, Feature> tempfeat in temp)
|
||||
{
|
||||
if (!enabled.ContainsKey(tempfeat.Key))
|
||||
{
|
||||
enabled.Add(tempfeat.Key, null);
|
||||
}
|
||||
enabled[tempfeat.Key] = tempfeat.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return enabled;
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace SabreTools
|
||||
datFromDir.AddFeature("mt", new Feature(
|
||||
new List<string>() { "-mt", "--mt" },
|
||||
"Amount of threads to use (default 4, -1 unlimted)",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
|
||||
#endregion
|
||||
@@ -473,22 +473,22 @@ namespace SabreTools
|
||||
sort.AddFeature("7z", new Feature(
|
||||
new List<string>() { "-7z", "--7z" },
|
||||
"Set scanning level for 7z archives (default 1)",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
sort.AddFeature("gz", new Feature(
|
||||
new List<string>() { "-gz", "--gz" },
|
||||
"Set scanning level for GZip archives (default 1)",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
sort.AddFeature("rar", new Feature(
|
||||
new List<string>() { "-rar", "--rar" },
|
||||
"Set scanning level for RAR archives (default 1)",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
sort.AddFeature("zip", new Feature(
|
||||
new List<string>() { "-zip", "--zip" },
|
||||
"Set scanning level for ZIP archives (default 1)",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
sort.AddFeature("scan-all", new Feature(
|
||||
new List<string>() { "-sa", "--scan-all" },
|
||||
@@ -523,7 +523,7 @@ namespace SabreTools
|
||||
sort.AddFeature("mt", new Feature(
|
||||
new List<string>() { "-mt", "--mt" },
|
||||
"Amount of threads to use (default 4, -1 unlimted)",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
|
||||
#endregion
|
||||
@@ -1318,17 +1318,17 @@ namespace SabreTools
|
||||
update.AddFeature("greater", new Feature(
|
||||
new List<string>() { "-sgt", "--greater" },
|
||||
"Filter by size >=",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
update.AddFeature("less", new Feature(
|
||||
new List<string>() { "-slt", "--less" },
|
||||
"Filter by size =<",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
update.AddFeature("equal", new Feature(
|
||||
new List<string>() { "-seq", "--equal" },
|
||||
"Filter by size ==",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
update.AddFeature("crc", new Feature(
|
||||
new List<string>() { "-crc", "--crc" },
|
||||
@@ -1449,7 +1449,7 @@ namespace SabreTools
|
||||
update.AddFeature("mt", new Feature(
|
||||
new List<string>() { "-mt", "--mt" },
|
||||
"Amount of threads to use (default 4, -1 unlimited)",
|
||||
FeatureType.String,
|
||||
FeatureType.Int32,
|
||||
null));
|
||||
|
||||
#endregion
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user