DiscordMediaLoader/Discord Media Loader/Helper/VersionHelper.cs

40 lines
1.5 KiB
C#
Raw Normal View History

2017-03-09 20:56:48 +01:00
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
2017-04-16 17:57:27 +02:00
using Octokit;
2017-03-09 20:56:48 +01:00
namespace Discord_Media_Loader.Helper
{
internal class VersionHelper
{
internal static Version CurrentVersion => Assembly.GetExecutingAssembly().GetName().Version;
internal static Version AppVersion => AssemblyName.GetAssemblyName("Discord Media Loader.Application.dll").Version;
2017-03-09 20:56:48 +01:00
2017-04-16 17:57:27 +02:00
internal static async Task<Version> GetReleaseVersion()
{
var github = new GitHubClient(new ProductHeaderValue("DiscordMedialLoader"));
2017-03-09 20:56:48 +01:00
2017-04-16 17:57:27 +02:00
var tag =
(await github.Repository.Release.GetAll("Serraniel", "DiscordMediaLoader")).OrderByDescending(x => x.CreatedAt).First().TagName.Replace("v", "") ?? "";
var version = new Version(tag);
return version;
}
internal static async Task<string> DownloadLatestReleaseVersion()
{
return await DownloadVersion(await GetReleaseVersion());
}
internal static async Task<string> DownloadVersion(Version version)
{
var github = new GitHubClient(new ProductHeaderValue("DiscordMediaLoader"));
var releaseVersion = (from release in (await github.Repository.Release.GetAll("Serraniel", "DiscordMediaLoader")) where release.TagName == $"v{version.Major}.{version.Minor}.{version.Build}.{version.Revision}" select release).First();
2017-04-16 17:57:27 +02:00
return releaseVersion.Assets.FirstOrDefault()?.BrowserDownloadUrl;
}
2017-03-09 20:56:48 +01:00
}
}