mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Created HasValidArguments function for checking paths
This commit is contained in:
parent
9a3a3448d0
commit
b8be153c99
@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using CommandLine;
|
||||
using Wabbajack.CLI.Verbs;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.CLI
|
||||
{
|
||||
@ -11,9 +16,58 @@ namespace Wabbajack.CLI
|
||||
|
||||
internal static class CLIUtils
|
||||
{
|
||||
internal static bool VerifyArguments(AVerb verb)
|
||||
internal static bool HasValidArguments(AVerb verb)
|
||||
{
|
||||
return true;
|
||||
var props = verb.GetType().GetProperties().Where(p =>
|
||||
{
|
||||
var hasAttr = p.HasAttribute(typeof(OptionAttribute));
|
||||
if (!hasAttr)
|
||||
return false;
|
||||
|
||||
if (p.PropertyType != typeof(string))
|
||||
return false;
|
||||
|
||||
var value = p.GetValue(verb);
|
||||
if (value == null)
|
||||
return false;
|
||||
|
||||
var stringValue = (string)value;
|
||||
return string.IsNullOrWhiteSpace(stringValue);
|
||||
});
|
||||
|
||||
var valid = true;
|
||||
|
||||
props.Do(p =>
|
||||
{
|
||||
if (!valid)
|
||||
return;
|
||||
|
||||
var valueObject = p.GetValue(verb);
|
||||
|
||||
// not really possible since we filtered them out but whatever
|
||||
if (valueObject == null)
|
||||
return;
|
||||
|
||||
var value = (string)valueObject;
|
||||
|
||||
if (p.HasAttribute(typeof(FileAttribute)))
|
||||
{
|
||||
valid = File.Exists(value);
|
||||
}
|
||||
|
||||
if (p.HasAttribute(typeof(DirectoryAttribute)))
|
||||
{
|
||||
valid = Directory.Exists(value);
|
||||
}
|
||||
});
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
internal static bool HasAttribute(this MemberInfo member, Type attribute)
|
||||
{
|
||||
var attributes = member.GetCustomAttributes(attribute);
|
||||
return attributes.Count() == 1;
|
||||
}
|
||||
|
||||
internal static void Log(string msg, bool newLine = true)
|
||||
|
Loading…
Reference in New Issue
Block a user