mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Created CLIUtils.Exit
This commit is contained in:
parent
52784789ab
commit
8caa66b6fa
@ -13,6 +13,12 @@ namespace Wabbajack.CLI
|
||||
Console.Write(msg);
|
||||
}
|
||||
|
||||
internal static int Exit(string msg, int code)
|
||||
{
|
||||
Log(msg);
|
||||
return code;
|
||||
}
|
||||
|
||||
internal static void LogException(Exception e, string msg)
|
||||
{
|
||||
Console.WriteLine($"{msg}\n{e}");
|
||||
|
@ -58,16 +58,10 @@ namespace Wabbajack.CLI.Verbs
|
||||
protected override async Task<int> Run()
|
||||
{
|
||||
if (!File.Exists(Modlist))
|
||||
{
|
||||
CLIUtils.Log($"The file {Modlist} does not exist!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit($"The file {Modlist} does not exist!", -1);
|
||||
|
||||
if (!Directory.Exists(Input))
|
||||
{
|
||||
CLIUtils.Log($"The input directory {Input} does not exist!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit($"The input directory {Input} does not exist!", -1);
|
||||
|
||||
if (!Directory.Exists(Output))
|
||||
{
|
||||
@ -76,16 +70,10 @@ namespace Wabbajack.CLI.Verbs
|
||||
}
|
||||
|
||||
if (!Modlist.EndsWith(Consts.ModListExtension) && !Modlist.EndsWith("modlist.txt"))
|
||||
{
|
||||
CLIUtils.Log($"The file {Modlist} is not a valid modlist file!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit($"The file {Modlist} is not a valid modlist file!", -1);
|
||||
|
||||
if (Copy && Move)
|
||||
{
|
||||
CLIUtils.Log("You can't set both copy and move flags!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit("You can't set both copy and move flags!", -1);
|
||||
|
||||
var isModlist = Modlist.EndsWith(Consts.ModListExtension);
|
||||
|
||||
@ -101,14 +89,12 @@ namespace Wabbajack.CLI.Verbs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CLIUtils.Log($"Error while loading the Modlist!\n{e}");
|
||||
return 1;
|
||||
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", 1);
|
||||
}
|
||||
|
||||
if (modlist == null)
|
||||
{
|
||||
CLIUtils.Log("The Modlist could not be loaded!");
|
||||
return 1;
|
||||
return CLIUtils.Exit("The Modlist could not be loaded!", 1);
|
||||
}
|
||||
|
||||
CLIUtils.Log($"Modlist contains {modlist.Archives.Count} archives.");
|
||||
@ -167,26 +153,18 @@ namespace Wabbajack.CLI.Verbs
|
||||
else
|
||||
{
|
||||
if (!Directory.Exists(Mods))
|
||||
{
|
||||
CLIUtils.Log($"Mods directory {Mods} does not exist!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit($"Mods directory {Mods} does not exist!", -1);
|
||||
|
||||
CLIUtils.Log($"Reading modlist.txt from {Modlist}");
|
||||
string[] modlist = File.ReadAllLines(Modlist);
|
||||
|
||||
if (modlist == null || modlist.Length == 0)
|
||||
{
|
||||
CLIUtils.Log($"Provided modlist.txt file at {Modlist} is empty or could not be read!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit($"Provided modlist.txt file at {Modlist} is empty or could not be read!", -1);
|
||||
|
||||
var mods = modlist.Where(s => s.StartsWith("+")).Select(s => s.Substring(1)).ToHashSet();
|
||||
|
||||
if (mods.Count == 0)
|
||||
{
|
||||
CLIUtils.Log("Counted mods from modlist.txt are 0!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit("Counted mods from modlist.txt are 0!", -1);
|
||||
|
||||
CLIUtils.Log($"Found {mods.Count} mods in modlist.txt");
|
||||
|
||||
|
@ -23,11 +23,8 @@ namespace Wabbajack.CLI.Verbs
|
||||
{
|
||||
var state = DownloadDispatcher.Infer(Url);
|
||||
if (state == null)
|
||||
{
|
||||
CLIUtils.Log($"Could not find download source for URL {Url}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return CLIUtils.Exit($"Could not find download source for URL {Url}", 1);
|
||||
|
||||
DownloadDispatcher.PrepareAll(new []{state});
|
||||
|
||||
using var queue = new WorkQueue();
|
||||
|
@ -30,18 +30,12 @@ namespace Wabbajack.CLI.Verbs
|
||||
protected override async Task<int> Run()
|
||||
{
|
||||
if (!File.Exists(Input))
|
||||
{
|
||||
CLIUtils.Log($"The file {Input} does not exist!");
|
||||
return -1;
|
||||
}
|
||||
return CLIUtils.Exit($"The file {Input} does not exist!", -1);
|
||||
|
||||
|
||||
if (!Input.EndsWith(Consts.ModListExtension))
|
||||
{
|
||||
CLIUtils.Log($"The file {Input} does not end with {Consts.ModListExtension}!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return CLIUtils.Exit($"The file {Input} does not end with {Consts.ModListExtension}!", -1);
|
||||
|
||||
ModList modlist;
|
||||
|
||||
try
|
||||
@ -50,14 +44,12 @@ namespace Wabbajack.CLI.Verbs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CLIUtils.Log($"Error while loading the Modlist!\n{e}");
|
||||
return 1;
|
||||
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", 1);
|
||||
}
|
||||
|
||||
if (modlist == null)
|
||||
{
|
||||
CLIUtils.Log($"The Modlist could not be loaded!");
|
||||
return 1;
|
||||
return CLIUtils.Exit($"The Modlist could not be loaded!", 1);
|
||||
}
|
||||
|
||||
|
||||
@ -69,12 +61,10 @@ namespace Wabbajack.CLI.Verbs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CLIUtils.Log($"Error during Validation!\n{e}");
|
||||
return 1;
|
||||
return CLIUtils.Exit($"Error during Validation!\n{e}", 1);
|
||||
}
|
||||
|
||||
CLIUtils.Log("The Modlist passed the Validation");
|
||||
return 0;
|
||||
return CLIUtils.Exit("The Modlist passed the Validation", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user