From 45487c60086d694b445617a8ee2a0428bfb67964 Mon Sep 17 00:00:00 2001 From: Matt Pannella Date: Sun, 17 Sep 2023 21:51:14 -0400 Subject: [PATCH] only force update checks when running without cli arguments. new cli command "update-self" to force the app to update itself --- src/Program.cs | 80 +++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 66dc44e0..e6fd8e93 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -32,45 +32,17 @@ private static async Task Main(string[] args) string? imagePackRepo = null; string? imagePackVariant = null; bool downloadFirmware = false; + bool selfUpdate = false; ConsoleKey response; - Console.WriteLine("Pocket Updater Utility v" + version); - Console.WriteLine("Checking for updates..."); - - if(await CheckVersion(path)) { - string platform = GetPlatform(); - ConsoleKey[] acceptedInputs = new[] { ConsoleKey.I, ConsoleKey.C, ConsoleKey.Q }; - do { - if (platform == "win") { - Console.Write("Would you like to [i]nstall the update, [c]ontinue with the current version, or [q]uit? [i/c/q]: "); - } else { - Console.Write("Update downloaded. Would you like to [c]ontinue with the current version, or [q]uit? [c/q]: "); - } - response = Console.ReadKey(false).Key; - Console.WriteLine(); - } while(!acceptedInputs.Contains(response)); - - switch(response) { - case ConsoleKey.I: - int result = UpdateSelfAndRun(path, args); - Environment.Exit(result); - break; - - case ConsoleKey.C: - break; - - case ConsoleKey.Q: - Console.WriteLine("Come again soon"); - PauseExit(); - break; - } - } - string verb = "menu"; Dictionary data = new Dictionary(); Parser.Default.ParseArguments(args) + AssetsOptions, FirmwareOptions, ImagesOptions, InstancegeneratorOptions, UpdateSelfOptions>(args) + .WithParsed(o => { + selfUpdate = true; + }) .WithParsed(async o => { verb = "fund"; @@ -161,6 +133,43 @@ private static async Task Main(string[] args) } ); + if (!cliMode) { + Console.WriteLine("Pocket Updater Utility v" + version); + Console.WriteLine("Checking for updates..."); + + if(await CheckVersion(path) && !selfUpdate) { + string platform = GetPlatform(); + ConsoleKey[] acceptedInputs = new[] { ConsoleKey.I, ConsoleKey.C, ConsoleKey.Q }; + do { + if (platform == "win") { + Console.Write("Would you like to [i]nstall the update, [c]ontinue with the current version, or [q]uit? [i/c/q]: "); + } else { + Console.Write("Update downloaded. Would you like to [c]ontinue with the current version, or [q]uit? [c/q]: "); + } + response = Console.ReadKey(false).Key; + Console.WriteLine(); + } while(!acceptedInputs.Contains(response)); + + switch(response) { + case ConsoleKey.I: + int result = UpdateSelfAndRun(path, args); + Environment.Exit(result); + break; + + case ConsoleKey.C: + break; + + case ConsoleKey.Q: + Console.WriteLine("Come again soon"); + PauseExit(); + break; + } + } + if(selfUpdate) { + Environment.Exit(0); + } + } + //path = "/Users/mattpannella/pocket-test"; updater = new PocketCoreUpdater(path); @@ -1153,6 +1162,11 @@ public class FundOptions public string? Core { get; set; } } +[Verb("update-self", HelpText = "Update this utility")] +public class UpdateSelfOptions +{ +} + public static class EnumExtension { public static IEnumerable<(T item, int index)> WithIndex(this IEnumerable self)