mirror of
https://github.com/ckaczor/Common.git
synced 2026-02-08 17:24:31 -05:00
Add support for updates from GitHub
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user