-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathTrickSaberPlugin.cs
56 lines (51 loc) · 1.72 KB
/
TrickSaberPlugin.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using OVRSimpleJSON;
using SemVer;
using UnityEngine;
using UnityEngine.Networking;
using Version = SemVer.Version;
namespace TrickSaber.UI
{
class TrickSaberPlugin : MonoBehaviour
{
public static TrickSaberPlugin Instance;
public bool IsNewestVersion = true;
public static void Create()
{
Instance = new GameObject("TrickSaberPlugin").AddComponent<TrickSaberPlugin>();
}
void Start()
{
StartCoroutine(CheckVersion());
}
public IEnumerator CheckVersion()
{
UnityWebRequest www = UnityWebRequest.Get("https://api.github.com/repos/ToniMacaroni/TrickSaber/releases");
www.SetRequestHeader("User-Agent", "TrickSaber-" + Plugin.VersionString);
www.timeout = 10;
yield return www.SendWebRequest();
try
{
if (!www.isNetworkError && !www.isHttpError)
{
JSONNode releases = JSON.Parse(www.downloadHandler.text);
JSONNode latestRelease = releases[0];
JSONNode jsonnode = latestRelease["tag_name"];
string githubVerStr = (jsonnode != null) ? jsonnode.Value : null;
Version githubVer = new Version(githubVerStr);
IsNewestVersion = !new Range($">{Plugin.Version}").IsSatisfied(githubVer);
}
}
catch (Exception ex)
{
Plugin.Log.Error("couldn't get version: " + ex.Message);
}
}
}
}