From 75c0185f387c46ff5f35f6e46e42ec5e0c100a8e Mon Sep 17 00:00:00 2001 From: Konrad Krawiec Date: Thu, 19 Apr 2018 17:45:47 +0200 Subject: [PATCH] Update InstaShitCore, add checking for updates --- InstaShit/InstaShit.csproj | 6 ++---- InstaShit/Program.cs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/InstaShit/InstaShit.csproj b/InstaShit/InstaShit.csproj index 3d1d69d..5550f56 100644 --- a/InstaShit/InstaShit.csproj +++ b/InstaShit/InstaShit.csproj @@ -5,9 +5,7 @@ netcoreapp2.0 Konrad Krawiec - win-x86;win-x64;linux-x64;osx-x64 - false - 2.1.1 + 2.2 @@ -20,7 +18,7 @@ - + diff --git a/InstaShit/Program.cs b/InstaShit/Program.cs index 87a36a0..63efe39 100644 --- a/InstaShit/Program.cs +++ b/InstaShit/Program.cs @@ -2,8 +2,10 @@ // Created by Konrad Krawiec using System; using System.Net.Http; +using System.Reflection; using System.Threading.Tasks; using InstaShitCore; +using static InstaShit.UserInput; namespace InstaShit { @@ -33,6 +35,34 @@ private static async Task Main(string[] args) break; } } + HttpClient client = new HttpClient + { + BaseAddress = new Uri("https://instashit.pl") + }; + try + { + string latestVersionString = await client.GetStringAsync("/cli.version"); + Version latestVersion = new Version(latestVersionString); + var localVersion = Assembly.GetEntryAssembly().GetName().Version; + if (latestVersion > localVersion) + { + Console.WriteLine("A new version of InstaShit.CLI is available. It is very important " + + "to keep all InstaShit products updated, since Insta.Ling creators sometimes make " + + "changes that require updating InstaShit."); + Console.WriteLine($"Your current version is {localVersion}, while the newest version is {latestVersion}."); + Console.WriteLine("Visit https://instashit.pl to download newest InstaShit.CLI."); + if (!noUserInteraction) + { + Console.Write("Continue without updating? (y/n) "); + if (!CanContinue()) + return; + } + } + } + catch (Exception ex) + { + Console.WriteLine("An error occured while trying to check for updates: " + ex); + } try { var instaShit = new InstaShit(ignoreSettings); @@ -52,7 +82,8 @@ private static async Task Main(string[] args) if (!noUserInteraction) { Console.Write("Continue (y/n)? "); - if (!UserInput.CanContinue()) return; + if (!CanContinue()) + return; } } while (true)