diff --git a/tldr-sharp/Program.cs b/tldr-sharp/Program.cs index 2d1671c..7eb2d78 100644 --- a/tldr-sharp/Program.cs +++ b/tldr-sharp/Program.cs @@ -96,6 +96,14 @@ public static int Main(string[] args) "u|update", "Update the local cache.", u => update = true }, + { + "self-update", "Check for tldr-sharp updates.", + u => + { + SelfUpdate(); + Environment.Exit(0); + } + }, { "v|version", "Show version information.", v => @@ -543,5 +551,26 @@ private static void ClearCache() } Console.WriteLine("Cache cleared."); } + + private static void SelfUpdate() + { + + using (var webclient = new WebClient()) + { + webclient.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; " + "Windows NT 5.2; .NET CLR 1.0.3705;)"); + var json = webclient.DownloadString( + "https://api.github.com/repos/principis/tldr-sharp/releases/latest"); + var remoteVersion = new Version(json.Substring(json.IndexOf("tag_name") + 12, 5)); + + if (remoteVersion.CompareTo(Assembly.GetExecutingAssembly().GetName().Version) > 0) + { + Console.WriteLine("Version {0} is available. Download it from {1}", remoteVersion, "https://github.com/principis/tldr-sharp/releases/latest"); + } + else + { + Console.WriteLine("tldr-sharp is up to date!"); + } + } + } } -} \ No newline at end of file +} diff --git a/tldr-sharp/Properties/AssemblyInfo.cs b/tldr-sharp/Properties/AssemblyInfo.cs index b23670f..e86b621 100644 --- a/tldr-sharp/Properties/AssemblyInfo.cs +++ b/tldr-sharp/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0")] -[assembly: AssemblyFileVersion("2.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.1.0")] +[assembly: AssemblyFileVersion("2.1.0")] \ No newline at end of file