Add support for updates from GitHub

This commit is contained in:
2018-04-06 09:51:09 -04:00
parent ecd3717eab
commit 88149c43c3
4 changed files with 240 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using Common.Debug;
using System;
using System.Net;
using System.Xml.Linq;
namespace Common.Update
@@ -10,7 +11,20 @@ namespace Common.Update
public string InstallFile { get; set; }
public DateTime InstallCreated { get; set; }
public static VersionInfo Load(string server, string file)
public static VersionInfo Load(ServerType updateServerType, string server, string file)
{
switch (updateServerType)
{
case ServerType.Generic:
return LoadFile(server, file);
case ServerType.GitHub:
return LoadGitHub(server);
}
return null;
}
private static VersionInfo LoadFile(string server, string file)
{
try
{
@@ -44,5 +58,38 @@ namespace Common.Update
return null;
}
}
private static VersionInfo LoadGitHub(string server)
{
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
using (var webClient = new WebClient())
{
webClient.Headers.Add("User-Agent", UpdateCheck.ApplicationName);
var json = webClient.DownloadString(server);
var release = GitHubRelease.FromJson(json);
var versionInfo = new VersionInfo
{
Version = Version.Parse(release.TagName),
InstallFile = release.Assets[0].BrowserDownloadUrl,
InstallCreated = release.Assets[0].CreatedAt.LocalDateTime
};
return versionInfo;
}
}
catch (Exception exception)
{
Tracer.WriteException(exception);
return null;
}
}
}
}