DutyContent/Updater.cs
ksh cbfa535d20
Enhanced after version 14 (#30)
* Add log tab
* Merge control mesg & duty log
* Fix ping (calc loss)
* Add current connection in ping tab. Able to copy by double clicking item
* Log font has moved to config
* Add debug enable on config + save
* Display ping failed reason (debug enable)
* Handled copy exception
* New content list in duty tab
* Show loss rate option in ping tab
* Rename Chinese packet info file (No data)
* Bigger UI font
2021-08-14 23:35:53 +09:00

79 lines
1.6 KiB
C#

using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace DutyContent
{
internal class Updater
{
// https://raw.githubusercontent.com/kshman/DutyContent/main/Data/####-####.####
// https://api.github.com/repos/kshman/DutyContent/releases/latest
private const string UrlContent = "https://raw.githubusercontent.com/kshman/DutyContent";
private const string UrlApiRepo = "https://api.github.com/repos/kshman/DutyContent";
private const string PathData = "main/Data";
private const string PfxDuty = "DcDuty";
private const string PfxPacket = "DcPacket";
internal static void CheckNewVersion()
{
Task.Factory.StartNew(() =>
{
try
{
var url = $"{UrlContent}/{PathData}/{PfxDuty}-{DcContent.Language}.json";
var json = WebApi.Request(url);
DcContent.Fill(json);
}
catch (Exception ex)
{
Logger.Ex(ex, 31);
}
});
}
public static string CheckNewPacket(string name)
{
try
{
var url = $"{UrlContent}/{PathData}/{PfxPacket}-{name}.config";
var ret = WebApi.Request(url);
return ret;
}
catch (Exception ex)
{
Logger.Ex(ex, 32);
return null;
}
}
public static int CheckPluginUpdate(out string body)
{
body = string.Empty;
var url = $"{UrlApiRepo}/releases/latest";
var req = WebApi.Request(url);
if (!string.IsNullOrEmpty(req))
{
try
{
var js = JsonConvert.DeserializeObject<dynamic>(req);
var tag = js.tag_name.ToObject<string>();
body = js.body.ToObject<string>();
return ThirdParty.Converter.ToInt(tag);
}
catch (Exception /*ex*/)
{
}
}
return 0;
}
}
}