async static Task CheckForUpdateAsync(string authtoken, string contentid) { Uri GetSystemUpdatePackageUri = new Uri($"https://update.xboxlive.com/GetSystemUpdatePackage/{contentid}"); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authtoken); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); StringContent content = new StringContent("{\"UpdateMode\":3,\"LicenseProtocol\":4,\"FileIncludeFilter\":[\"updater.xvd\"],\"IgnoreRootLicense\":0}"); HttpResponseMessage httpResponse = await client.PostAsync(GetSystemUpdatePackageUri, content); if (httpResponse.IsSuccessStatusCode) { string update = httpResponse.Content.ReadAsStringAsync().Result; var updatejson = UpdateXboxLive.FromJson(update); if (updatejson.UpdateType != "None") { Console.WriteLine("***Update Found***"); UpdateInfo(updatejson); await DownloadUpdateAsync(updatejson); } else { Console.WriteLine("No Update Found."); } } else { Console.WriteLine($"update.xboxlive.com error - status code {httpResponse.StatusCode.ToString()}"); } }
static async Task DownloadUpdateAsync(UpdateXboxLive update) { WebClient downloader = new WebClient(); Console.WriteLine($"Downloading Update: {update.TargetVersionId} - Size: {update.Files.EstimatedTotalDownloadSize} KB"); foreach (var file in update.Files.PurpleFiles) { Console.WriteLine($"Downloading {file.Name} - {file.Size} kb"); Uri updatepath = new Uri($"http://assets1.xboxlive.com/{file.RelativeUrl}"); await downloader.DownloadFileTaskAsync(updatepath, file.Name + "_" + update.ContentId); Console.WriteLine($"Downloaded {file.Name} as {file.Name}_{update.ContentId}"); } }
static void UpdateInfo(UpdateXboxLive update) { Console.WriteLine($"Update Version: {update.TargetVersionId}\nUpdate Type: {update.UpdateType}"); }