diff --git a/Wabbajack.CLI/CLIUtils.cs b/Wabbajack.CLI/CLIUtils.cs index 7a3f0316..c9a081e8 100644 --- a/Wabbajack.CLI/CLIUtils.cs +++ b/Wabbajack.CLI/CLIUtils.cs @@ -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}"); diff --git a/Wabbajack.CLI/Verbs/ChangeDownload.cs b/Wabbajack.CLI/Verbs/ChangeDownload.cs index f50cc8a9..966dfad9 100644 --- a/Wabbajack.CLI/Verbs/ChangeDownload.cs +++ b/Wabbajack.CLI/Verbs/ChangeDownload.cs @@ -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"); diff --git a/Wabbajack.CLI/Verbs/DownloadUrl.cs b/Wabbajack.CLI/Verbs/DownloadUrl.cs index 02196579..ead09310 100644 --- a/Wabbajack.CLI/Verbs/DownloadUrl.cs +++ b/Wabbajack.CLI/Verbs/DownloadUrl.cs @@ -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(); diff --git a/Wabbajack.CLI/Verbs/Validate.cs b/Wabbajack.CLI/Verbs/Validate.cs index 6c50c817..5a21e0af 100644 --- a/Wabbajack.CLI/Verbs/Validate.cs +++ b/Wabbajack.CLI/Verbs/Validate.cs @@ -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); } } }