From 5573edeb9edb5df74964ae80c4e06ae42f96c2be Mon Sep 17 00:00:00 2001 From: Jasmine Wells Date: Tue, 3 Sep 2024 03:26:45 -0700 Subject: [PATCH 1/2] Add support to notify users when they are using an outdated version. --- OF DL/OF DL.csproj | 1 + OF DL/Program.cs | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) mode change 100644 => 100755 OF DL/OF DL.csproj diff --git a/OF DL/OF DL.csproj b/OF DL/OF DL.csproj old mode 100644 new mode 100755 index 9e31828..f5b0c14 --- a/OF DL/OF DL.csproj +++ b/OF DL/OF DL.csproj @@ -18,6 +18,7 @@ + diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 90a8ad9..73bd73b 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -9,6 +9,7 @@ using OF_DL.Enumerations; using OF_DL.Enumurations; using OF_DL.Helpers; +using Octokit; using Serilog; using Serilog.Core; using Serilog.Events; @@ -49,11 +50,39 @@ public async static Task Main(string[] args) AnsiConsole.Write(new FigletText("Welcome to OF-DL").Color(Color.Red)); - var version = Assembly.GetEntryAssembly()?.GetName().Version; - if (version != null) + try { - AnsiConsole.Markup("[green]Version: " + $"{version.Major}.{version.Minor}.{version.Build}\n[/]"); + Version localVersion = Assembly.GetEntryAssembly()?.GetName().Version; //Only tested with numeric values. + //Get all releases from GitHub + //Source: https://octokitnet.readthedocs.io/en/latest/getting-started/ + GitHubClient client = new GitHubClient(new ProductHeaderValue("SomeName")); + IReadOnlyList releases = await client.Repository.Release.GetAll("sim0n00ps", "OF-DL"); + + //Setup the versions + Version latestGitHubVersion = new Version(releases[0].TagName.Replace("OFDLV", "")); + + //Compare the Versions + //Source: https://stackoverflow.com/questions/7568147/compare-version-numbers-without-using-split-function + int versionComparison = localVersion.CompareTo(latestGitHubVersion); + if (versionComparison < 0) + { + //The version on GitHub is more up to date than this local release. + AnsiConsole.Markup("[red]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]"); + AnsiConsole.Markup("[red]Please update to the current release on GitHub, " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}: {releases[0].HtmlUrl}\n[/]"); + } + else + { + //This local version is greater than the release version on GitHub. + AnsiConsole.Markup("[green]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]"); + AnsiConsole.Markup("[green]Latest GitHub Release version: " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}\n[/]"); + } } + catch (Exception e) + { + AnsiConsole.Markup("[red]Error checking latest release on GitHub:\n[/]"); + Console.WriteLine(e); + } + //I dont like it... but I needed to move config here, otherwise the logging level gets changed too late after we missed a whole bunch of important info if (File.Exists("config.json")) { From 08b97e1304a5eb573409e888d61b0090a0a184e4 Mon Sep 17 00:00:00 2001 From: Jasmine Wells Date: Tue, 3 Sep 2024 09:43:59 -0700 Subject: [PATCH 2/2] Added logging support for version checking. --- OF DL/Program.cs | 71 ++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 73bd73b..afdda76 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -50,39 +50,6 @@ public async static Task Main(string[] args) AnsiConsole.Write(new FigletText("Welcome to OF-DL").Color(Color.Red)); - try - { - Version localVersion = Assembly.GetEntryAssembly()?.GetName().Version; //Only tested with numeric values. - //Get all releases from GitHub - //Source: https://octokitnet.readthedocs.io/en/latest/getting-started/ - GitHubClient client = new GitHubClient(new ProductHeaderValue("SomeName")); - IReadOnlyList releases = await client.Repository.Release.GetAll("sim0n00ps", "OF-DL"); - - //Setup the versions - Version latestGitHubVersion = new Version(releases[0].TagName.Replace("OFDLV", "")); - - //Compare the Versions - //Source: https://stackoverflow.com/questions/7568147/compare-version-numbers-without-using-split-function - int versionComparison = localVersion.CompareTo(latestGitHubVersion); - if (versionComparison < 0) - { - //The version on GitHub is more up to date than this local release. - AnsiConsole.Markup("[red]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]"); - AnsiConsole.Markup("[red]Please update to the current release on GitHub, " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}: {releases[0].HtmlUrl}\n[/]"); - } - else - { - //This local version is greater than the release version on GitHub. - AnsiConsole.Markup("[green]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]"); - AnsiConsole.Markup("[green]Latest GitHub Release version: " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}\n[/]"); - } - } - catch (Exception e) - { - AnsiConsole.Markup("[red]Error checking latest release on GitHub:\n[/]"); - Console.WriteLine(e); - } - //I dont like it... but I needed to move config here, otherwise the logging level gets changed too late after we missed a whole bunch of important info if (File.Exists("config.json")) { @@ -168,6 +135,44 @@ public async static Task Main(string[] args) } } + try + { + Version localVersion = Assembly.GetEntryAssembly()?.GetName().Version; //Only tested with numeric values. + //Get all releases from GitHub + //Source: https://octokitnet.readthedocs.io/en/latest/getting-started/ + GitHubClient client = new GitHubClient(new ProductHeaderValue("SomeName")); + IReadOnlyList releases = await client.Repository.Release.GetAll("sim0n00ps", "OF-DL"); + + //Setup the versions + Version latestGitHubVersion = new Version(releases[0].TagName.Replace("OFDLV", "")); + + //Compare the Versions + //Source: https://stackoverflow.com/questions/7568147/compare-version-numbers-without-using-split-function + int versionComparison = localVersion.CompareTo(latestGitHubVersion); + if (versionComparison < 0) + { + //The version on GitHub is more up to date than this local release. + AnsiConsole.Markup("[red]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]"); + AnsiConsole.Markup("[red]Please update to the current release on GitHub, " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}: {releases[0].HtmlUrl}\n[/]"); + Log.Debug("Detected outdated client running version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}"); + Log.Debug("Latest GitHub release version " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}"); + } + else + { + //This local version is greater than the release version on GitHub. + AnsiConsole.Markup("[green]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]"); + AnsiConsole.Markup("[green]Latest GitHub Release version: " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}\n[/]"); + Log.Debug("Detected client running version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}"); + Log.Debug("Latest GitHub release version " + $"{latestGitHubVersion.Major}.{latestGitHubVersion.Minor}.{latestGitHubVersion.Build}"); + } + } + catch (Exception e) + { + AnsiConsole.Markup("[red]Error checking latest release on GitHub:\n[/]"); + Console.WriteLine(e); + Log.Error("Error checking latest release on GitHub.", e.Message); + } + if (File.Exists("auth.json")) { AnsiConsole.Markup("[green]auth.json located successfully!\n[/]");