summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Editor/SDKUpdater.cs
blob: 0be3003a4dc147dba4b15925a7126ee6804bc7e5 (plain)
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
using UnityEngine;
using System.Collections;
using UnityEditor;

public class SDKUpdater : MonoBehaviour
{
	static string GetCurrentVersion()
	{
		string currentVersion = "";
		string versionTextPath = Application.dataPath + "/VRCSDK/version.txt";
		if(System.IO.File.Exists(versionTextPath))
		{
			string[] versionFileLines = System.IO.File.ReadAllLines(versionTextPath);
			if(versionFileLines.Length > 0)
				currentVersion = versionFileLines[0];	
		}
		return currentVersion;
	}

	[MenuItem("VRChat SDK/Utilities/Check For Updates")]
	static void CheckForUpdatesWithProgressBar()
	{
		CheckForUpdates(false);
	}

	public static void CheckForUpdates(bool isSilent = true)
	{
		Debug.Log("Checking for VRChat SDK updates...");
		if(!isSilent)
			EditorUtility.DisplayProgressBar("SDK Updater", "Checking for updates...", 1f);
		
		VRC.Core.ConfigManager.RemoteConfig.Init(delegate() {
			string currentSdkVersion = GetCurrentVersion();
			string sdkVersion = VRC.Core.ConfigManager.RemoteConfig.GetString("devSdkVersion");
			string sdkUrl = VRC.Core.ConfigManager.RemoteConfig.GetString("devSdkUrl");
			EditorUtility.ClearProgressBar();

			if(sdkVersion == currentSdkVersion)
			{
				ShowDownloadUpdatePopup(false, currentSdkVersion, sdkUrl, isSilent);
			}
			else
			{
				ShowDownloadUpdatePopup(true, sdkVersion, sdkUrl, isSilent);
			}
		});
	}

	static void ShowDownloadUpdatePopup(bool updateAvailable, string latestVersion, string sdkUrl, bool isSilent)
	{
		if(!updateAvailable)
		{
			if(!isSilent)
				EditorUtility.DisplayDialog("VRChat SDK Updater", "SDK is up to date (version " + latestVersion + ")", "Okay");
		}
		else
		{
			if(EditorUtility.DisplayDialog("VRChat SDK Updater", "An update is available (version " + latestVersion + ")", "Download", "Cancel"))
			{
				DownloadUpdate(sdkUrl);
			}
		}
	}

	static void DownloadUpdate(string sdkUrl)
	{
		Application.OpenURL(sdkUrl);
	}

}