public UpdateResult CheckUpdate() { lock (this) { var result = new UpdateResult( EssCore.PLUGIN_VERSION, ToDecimalVersion(EssCore.PLUGIN_VERSION), string.Empty ); try { var httpRequest = (HttpWebRequest)WebRequest.Create(ReleasesUrl); httpRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"; var respStream = httpRequest.GetResponse().GetResponseStream(); if (respStream == null) { throw new Exception("request returned null response"); } using (var reader = new StreamReader(respStream)) { var jsonData = reader.ReadToEnd(); var jsonObj = JObject.Parse(jsonData); var latestVersion = jsonObj.GetValue("tag_name"); if (latestVersion == null) { throw new Exception("latest version not found."); } var latestVersionDecimal = ToDecimalVersion(latestVersion.ToString()); var currentVersionDecimal = ToDecimalVersion(EssCore.PLUGIN_VERSION); if (currentVersionDecimal < latestVersionDecimal) { var additionalData = new JObject(); var body = jsonObj.GetValue("body")?.ToString() ?? ""; var assets = jsonObj.GetValue("assets").Children <JObject>(); additionalData.Add("changes", body); additionalData.Add("download_url", assets.First().GetValue("browser_download_url")?.ToString() ?? "null"); result = new UpdateResult( latestVersion.ToString(), latestVersionDecimal, additionalData.ToString() ); } } } catch (Exception ex) { Logger.LogWarning("Could not check update!"); Logger.LogWarning(ex.Message); Logger.LogWarning(string.Empty); Logger.LogWarning( "Try downloading manually here https://github.com/uEssentials/uEssentials/releases"); } return(LastResult = result); } }
public UpdateResult CheckUpdate() { lock ( this ) { var result = new UpdateResult ( EssCore.PLUGIN_VERSION, ToDecimalVersion( EssCore.PLUGIN_VERSION ), string.Empty ); try { var httpRequest = (HttpWebRequest) WebRequest.Create( ReleasesUrl ); httpRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"; var respStream = httpRequest.GetResponse().GetResponseStream(); if ( respStream == null ) { throw new Exception( "request returned null response" ); } using (var reader = new StreamReader( respStream )) { var jsonData = reader.ReadToEnd(); var jsonObj = JObject.Parse( jsonData ); var latestVersion = jsonObj.GetValue( "tag_name" ); if ( latestVersion == null ) { throw new Exception( "latest version not found." ); } var latestVersionDecimal = ToDecimalVersion( latestVersion.ToString() ); var currentVersionDecimal = ToDecimalVersion( EssCore.PLUGIN_VERSION ); if ( currentVersionDecimal < latestVersionDecimal ) { var additionalData = new JObject(); var body = jsonObj.GetValue( "body" )?.ToString() ?? ""; var assets = jsonObj.GetValue( "assets" ).Children<JObject>(); additionalData.Add( "changes", body ); additionalData.Add( "download_url", assets.First().GetValue( "browser_download_url" )?.ToString() ?? "null" ); result = new UpdateResult ( latestVersion.ToString(), latestVersionDecimal, additionalData.ToString() ); } } } catch (Exception ex) { Logger.LogWarning( "Could not check update!" ); Logger.LogWarning( ex.Message ); } return LastResult = result; } }