Skip to content

Commit

Permalink
only force update checks when running without cli arguments. new cli …
Browse files Browse the repository at this point in the history
…command "update-self" to force the app to update itself
  • Loading branch information
mattpannella committed Sep 18, 2023
1 parent 7b17605 commit 45487c6
Showing 1 changed file with 47 additions and 33 deletions.
80 changes: 47 additions & 33 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object?> data = new Dictionary<string, object?>();
Parser.Default.ParseArguments<MenuOptions, FundOptions, UpdateOptions,
AssetsOptions, FirmwareOptions, ImagesOptions, InstancegeneratorOptions>(args)
AssetsOptions, FirmwareOptions, ImagesOptions, InstancegeneratorOptions, UpdateSelfOptions>(args)
.WithParsed<UpdateSelfOptions>(o => {
selfUpdate = true;
})
.WithParsed<FundOptions>(async o =>
{
verb = "fund";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<T>(this IEnumerable<T> self)
Expand Down

0 comments on commit 45487c6

Please sign in to comment.