DiscordMediaLoader/Discord Media Loader/Helper/VersionHelper.cs

43 lines
1.6 KiB
C#
Raw Normal View History

2017-03-09 20:56:48 +01:00
using System;
using System.Collections.Generic;
2017-04-16 17:57:27 +02:00
using System.Diagnostics;
2017-03-09 20:56:48 +01:00
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
2017-10-12 21:28:02 +02:00
using DML.Application.Classes;
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;
2017-10-12 21:28:02 +02:00
internal static Version AppVersion => typeof(Core).Assembly.GetName().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();
return releaseVersion.Assets.FirstOrDefault()?.BrowserDownloadUrl;
}
2017-03-09 20:56:48 +01:00
}
}