wabbajack/Wabbajack.CLI/Verbs/Validate.cs

65 lines
1.9 KiB
C#
Raw Normal View History

2020-02-08 18:03:49 +00:00
using System;
using System.Threading.Tasks;
2020-02-08 18:03:49 +00:00
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
2020-02-08 18:03:49 +00:00
{
[IsFile(CustomMessage = "The modlist file %1 does not exist!")]
2020-02-08 18:03:49 +00:00
[Option('i', "input", Required = true, HelpText = @"Modlist file")]
2020-04-06 12:04:40 +00:00
public string? Input { get; set; }
2020-02-08 18:03:49 +00:00
/// <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>
protected override async Task<int> Run()
2020-02-08 18:03:49 +00:00
{
2020-04-06 12:04:40 +00:00
if (Input != null && !Input.EndsWith(Consts.ModListExtension))
2020-04-06 13:09:17 +00:00
return CLIUtils.Exit($"The file {Input} does not end with {Consts.ModListExtension}!", ExitCode.BadArguments);
2020-02-24 17:05:42 +00:00
2020-02-08 18:03:49 +00:00
ModList modlist;
try
{
modlist = AInstaller.LoadFromFile(Input);
2020-02-08 18:03:49 +00:00
}
2020-02-08 18:47:32 +00:00
catch (Exception e)
2020-02-08 18:03:49 +00:00
{
2020-04-06 13:09:17 +00:00
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", ExitCode.Error);
2020-02-08 18:03:49 +00:00
}
if (modlist == null)
2020-02-08 18:47:32 +00:00
{
2020-04-06 13:09:17 +00:00
return CLIUtils.Exit($"The Modlist could not be loaded!", ExitCode.Error);
2020-02-08 18:47:32 +00:00
}
2020-02-08 18:03:49 +00:00
var queue = new WorkQueue();
try
{
ValidateModlist.RunValidation(queue, modlist).RunSynchronously();
}
2020-02-08 18:47:32 +00:00
catch (Exception e)
2020-02-08 18:03:49 +00:00
{
2020-04-06 13:09:17 +00:00
return CLIUtils.Exit($"Error during Validation!\n{e}", ExitCode.Error);
2020-02-08 18:03:49 +00:00
}
2020-02-24 17:05:42 +00:00
return CLIUtils.Exit("The Modlist passed the Validation", 0);
2020-02-08 18:03:49 +00:00
}
}
}