public void CheckForUpdatesAsync() { Working = true; Done = false; Exception = null; LatestDev = null; LatestStable = null; Thread thread = new Thread( UpdateWorker, 256 * 1024 ); thread.Name = "Launcher.UpdateCheck"; thread.Start(); }
void CheckUpdates() { string response = GetHtmlAll( BuildsUri, UpdatesUri ); int index = 0; bool success = true; JsonObject data = (JsonObject)Json.ParseValue( response, ref index, ref success ); JsonObject devBuild = (JsonObject)data["latest"]; JsonObject releaseBuilds = (JsonObject)data["releases"]; LatestDev = MakeBuild( devBuild, false ); Build[] stableBuilds = new Build[releaseBuilds.Count]; int i = 0; foreach( KeyValuePair<string, object> pair in releaseBuilds ) stableBuilds[i++] = MakeBuild( (JsonObject)pair.Value, true ); Array.Sort<Build>( stableBuilds, (a, b) => b.TimeBuilt.CompareTo( a.TimeBuilt ) ); LatestStable = stableBuilds[0]; }
void SuccessfulUpdateCheck( UpdateCheckTask task ) { if( task.LatestDev == null || task.LatestStable == null ) return; dev = task.LatestDev; view.LastDev = dev.TimeBuilt; stable = task.LatestStable; view.LastStable = stable.TimeBuilt; Resize(); }
Build MakeBuild( JsonObject obj, bool release ) { Build build = new Build(); string timeKey = release ? "release_ts" : "ts"; double rawTime = Double.Parse( (string)obj[timeKey], CultureInfo.InvariantCulture ); build.TimeBuilt = epoch.AddSeconds( rawTime ).ToLocalTime(); build.DirectXSize = Int32.Parse( (string)obj["dx_size"] ); build.DirectXPath = (string)obj["dx_file"]; build.OpenGLSize = Int32.Parse( (string)obj["ogl_size"] ); build.OpenGLPath = (string)obj["ogl_file"]; if( obj.ContainsKey( "version" ) ) build.Version = (string)obj["version"]; return build; }