mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Added Extension check for files
This commit is contained in:
parent
0f4c843730
commit
fd66313858
@ -30,7 +30,13 @@ namespace Wabbajack.CLI
|
||||
/// <summary>
|
||||
/// Validating if the file exists
|
||||
/// </summary>
|
||||
internal class IsFileAttribute : AValidateAttribute { }
|
||||
internal class IsFileAttribute : AValidateAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension the file should have
|
||||
/// </summary>
|
||||
public string? Extension { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validating if the directory exists
|
||||
@ -89,8 +95,21 @@ namespace Wabbajack.CLI
|
||||
|
||||
if (p.HasAttribute(typeof(IsFileAttribute)))
|
||||
{
|
||||
var fileAttribute = (IsFileAttribute)attribute;
|
||||
isFile = true;
|
||||
valid = File.Exists(value);
|
||||
|
||||
if (!File.Exists(value))
|
||||
valid = false;
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(fileAttribute.Extension))
|
||||
{
|
||||
valid = value.EndsWith(fileAttribute.Extension);
|
||||
if(!valid)
|
||||
Exit($"The file {value} does not have the extension {fileAttribute.Extension}!",
|
||||
ExitCode.BadArguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (p.HasAttribute(typeof(IsDirectoryAttribute)))
|
||||
|
@ -4,32 +4,22 @@ using CommandLine;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.Validation;
|
||||
using File = Alphaleonis.Win32.Filesystem.File;
|
||||
|
||||
namespace Wabbajack.CLI.Verbs
|
||||
{
|
||||
[Verb("validate", HelpText = @"Validates a Modlist")]
|
||||
public class Validate : AVerb
|
||||
{
|
||||
[IsFile(CustomMessage = "The modlist file %1 does not exist!")]
|
||||
[IsFile(CustomMessage = "The modlist file %1 does not exist!", Extension = Consts.ModListExtension)]
|
||||
[Option('i', "input", Required = true, HelpText = @"Modlist file")]
|
||||
public string? Input { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Runs the Validation of a Modlist
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <para>
|
||||
/// <c>-1</c> bad Input
|
||||
/// <c>0</c> valid modlist
|
||||
/// <c>1</c> broken modlist
|
||||
/// </para>
|
||||
/// </returns>
|
||||
/// <returns></returns>
|
||||
protected override async Task<int> Run()
|
||||
{
|
||||
if (Input != null && !Input.EndsWith(Consts.ModListExtension))
|
||||
return CLIUtils.Exit($"The file {Input} does not end with {Consts.ModListExtension}!", ExitCode.BadArguments);
|
||||
|
||||
ModList modlist;
|
||||
|
||||
try
|
||||
|
@ -90,7 +90,7 @@ namespace Wabbajack.Common
|
||||
|
||||
public static string HashFileExtension => ".xxHash";
|
||||
public static string MetaFileExtension => ".meta";
|
||||
public static string ModListExtension = ".wabbajack";
|
||||
public const string ModListExtension = ".wabbajack";
|
||||
public static string LocalAppDataPath => Path.Combine(KnownFolders.LocalAppData.Path, "Wabbajack");
|
||||
public static string MetricsKeyHeader => "x-metrics-key";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user