Skip to content

Commit

Permalink
added update check
Browse files Browse the repository at this point in the history
  • Loading branch information
principis committed Apr 20, 2019
1 parent fdf9343 commit 99d1135
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion tldr-sharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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!");
}
}
}
}
}
}
4 changes: 2 additions & 2 deletions tldr-sharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("2.1.0")]
[assembly: AssemblyFileVersion("2.1.0")]

0 comments on commit 99d1135

Please sign in to comment.