forked from kshman/DutyContent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdater.cs
78 lines (66 loc) · 1.63 KB
/
Updater.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
}
}
}