12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 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.RemoteConfig.Init(delegate() {
- string currentSdkVersion = GetCurrentVersion();
- string sdkVersion = VRC.Core.RemoteConfig.GetString("devSdkVersion");
- string sdkUrl = VRC.Core.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);
- }
-
- }
|