2021-06-10 16:31:15 +02:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
namespace DutyContent
|
|
|
|
{
|
2021-06-18 14:08:43 +02:00
|
|
|
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()
|
2021-06-14 18:16:06 +02:00
|
|
|
{
|
2021-06-18 14:08:43 +02:00
|
|
|
Task.Factory.StartNew(() =>
|
2021-06-14 18:16:06 +02:00
|
|
|
{
|
2021-06-18 14:08:43 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
var url = $"{UrlContent}/{PathData}/{PfxDuty}-{DcContent.Language}.json";
|
|
|
|
var json = WebApi.Request(url);
|
|
|
|
DcContent.Fill(json);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2021-08-14 16:35:53 +02:00
|
|
|
Logger.Ex(ex, 31);
|
2021-06-18 14:08:43 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-06-14 18:16:06 +02:00
|
|
|
|
2021-06-18 14:08:43 +02:00
|
|
|
public static string CheckNewPacket(string name)
|
|
|
|
{
|
|
|
|
try
|
2021-06-14 18:16:06 +02:00
|
|
|
{
|
2021-06-18 14:08:43 +02:00
|
|
|
var url = $"{UrlContent}/{PathData}/{PfxPacket}-{name}.config";
|
|
|
|
var ret = WebApi.Request(url);
|
2021-06-14 18:16:06 +02:00
|
|
|
|
2021-06-18 14:08:43 +02:00
|
|
|
return ret;
|
2021-06-14 18:16:06 +02:00
|
|
|
}
|
2021-06-18 14:08:43 +02:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2021-08-14 16:35:53 +02:00
|
|
|
Logger.Ex(ex, 32);
|
2021-06-18 14:08:43 +02:00
|
|
|
|
|
|
|
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;
|
2021-06-14 18:16:06 +02:00
|
|
|
}
|
2021-06-18 14:08:43 +02:00
|
|
|
}
|
2021-06-10 16:31:15 +02:00
|
|
|
}
|