Last active
May 25, 2016 15:28
-
-
Save TarasOsiris/b0621e319e2a9b636ad0afc0386b3da1 to your computer and use it in GitHub Desktop.
Check for upates on GitHub form Unity Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const string LatestReleaseApiURL = "https://api.github.com/repos/getsocial-im/getsocial-unity-sdk/releases/latest"; | |
private const string LatestReleaseURL = "https://github.com/getsocial-im/getsocial-unity-sdk/releases/latest"; | |
[MenuItem(GetSocialMenuParent + "GetSocial/Check for Updates...", false, priority: 2000)] | |
public static void CheckForUpdates() | |
{ | |
CheckForUpdatesOnReleaseRepo(); | |
} | |
private static void CheckForUpdatesOnReleaseRepo() | |
{ | |
HttpWebRequest request = WebRequest.Create(LatestReleaseApiURL) as HttpWebRequest; | |
request.Method = "GET"; | |
request.UserAgent = "Unity Editor"; | |
request.Proxy = null; | |
request.KeepAlive = false; | |
request.Accept = "application/vnd.github.v3+json"; | |
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) | |
{ | |
using (StreamReader reader = new StreamReader(response.GetResponseStream())) | |
{ | |
string jsonResponse = reader.ReadToEnd().ToString(); | |
var lastVersionTag = new JSONObject(jsonResponse).GetField("tag_name").str; | |
ShowUpdateDialog(lastVersionTag); | |
} | |
} | |
} | |
private static void ShowUpdateDialog(string lastVersionTag) | |
{ | |
var dialogTitle = "Update GetSocial SDK"; | |
if(IsInstalledVersionLatest(lastVersionTag)) | |
{ | |
EditorUtility.DisplayDialog(dialogTitle, "You already have the latest version installed (" + lastVersionTag + ")", "OK"); | |
} | |
else | |
{ | |
var downloadUpdate = EditorUtility.DisplayDialog(dialogTitle, | |
string.Format("[GetSocial] plugin {0} is now available!", lastVersionTag), "Download Update", "Cancel"); | |
if(downloadUpdate) | |
{ | |
Application.OpenURL(LatestReleaseURL); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment