2020-02-08 18:03:49 +00:00
|
|
|
|
using System;
|
2020-02-11 05:04:56 +00:00
|
|
|
|
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")]
|
2020-02-11 05:04:56 +00:00
|
|
|
|
public class Validate : AVerb
|
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>
|
2020-02-11 05:04:56 +00:00
|
|
|
|
protected override async Task<int> Run()
|
2020-02-08 18:03:49 +00:00
|
|
|
|
{
|
2020-02-11 05:04:56 +00:00
|
|
|
|
if (!File.Exists(Input))
|
2020-02-24 17:05:42 +00:00
|
|
|
|
return CLIUtils.Exit($"The file {Input} does not exist!", -1);
|
2020-02-08 18:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
2020-04-06 12:04:40 +00:00
|
|
|
|
if (Input != null && !Input.EndsWith(Consts.ModListExtension))
|
2020-02-24 17:05:42 +00:00
|
|
|
|
return CLIUtils.Exit($"The file {Input} does not end with {Consts.ModListExtension}!", -1);
|
|
|
|
|
|
2020-02-08 18:03:49 +00:00
|
|
|
|
ModList modlist;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-02-11 05:04:56 +00:00
|
|
|
|
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-02-24 17:05:42 +00:00
|
|
|
|
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", 1);
|
2020-02-08 18:03:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (modlist == null)
|
2020-02-08 18:47:32 +00:00
|
|
|
|
{
|
2020-02-24 17:05:42 +00:00
|
|
|
|
return CLIUtils.Exit($"The Modlist could not be loaded!", 1);
|
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-02-24 17:05:42 +00:00
|
|
|
|
return CLIUtils.Exit($"Error during Validation!\n{e}", 1);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|