Browse Source

Use github.io for updates.xml instead of ilspy.net custom domain (#3706)

master v10.0
Christoph Wille 3 days ago committed by GitHub
parent
commit
5deb6fb425
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 32
      ILSpy/Updates/UpdateService.cs

32
ILSpy/Updates/UpdateService.cs

@ -19,6 +19,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
@ -27,7 +28,7 @@ namespace ICSharpCode.ILSpy.Updates
{ {
internal static class UpdateService internal static class UpdateService
{ {
static readonly Uri UpdateUrl = new Uri("https://ilspy.net/updates.xml"); static readonly Uri UpdateUrl = new Uri("https://icsharpcode.github.io/ILSpy/updates.xml");
const string band = "stable"; const string band = "stable";
public static AvailableVersionInfo LatestAvailableVersion { get; private set; } public static AvailableVersionInfo LatestAvailableVersion { get; private set; }
@ -36,12 +37,12 @@ namespace ICSharpCode.ILSpy.Updates
{ {
var client = new HttpClient(new HttpClientHandler() { var client = new HttpClient(new HttpClientHandler() {
UseProxy = true, UseProxy = true,
UseDefaultCredentials = true, UseDefaultCredentials = true
}); });
string data = await client.GetStringAsync(UpdateUrl).ConfigureAwait(false); string data = await GetWithRedirectsAsync(client, UpdateUrl).ConfigureAwait(false);
XDocument doc = XDocument.Load(new StringReader(data)); XDocument doc = XDocument.Load(new StringReader(data));
var bands = doc.Root.Elements("band"); var bands = doc.Root.Elements("band").ToList();
var currentBand = bands.FirstOrDefault(b => (string)b.Attribute("id") == band) ?? bands.First(); var currentBand = bands.FirstOrDefault(b => (string)b.Attribute("id") == band) ?? bands.First();
Version version = new Version((string)currentBand.Element("latestVersion")); Version version = new Version((string)currentBand.Element("latestVersion"));
string url = (string)currentBand.Element("downloadUrl"); string url = (string)currentBand.Element("downloadUrl");
@ -52,6 +53,29 @@ namespace ICSharpCode.ILSpy.Updates
return LatestAvailableVersion; return LatestAvailableVersion;
} }
static async Task<string> GetWithRedirectsAsync(HttpClient client, Uri uri, int maxRedirects = 5)
{
for (int i = 0; i <= maxRedirects; i++)
{
using var response = await client.GetAsync(uri).ConfigureAwait(false);
if (response.StatusCode is HttpStatusCode.MovedPermanently
or HttpStatusCode.Found
or HttpStatusCode.TemporaryRedirect
or HttpStatusCode.PermanentRedirect)
{
var location = response.Headers.Location;
uri = location?.IsAbsoluteUri == true ? location : new Uri(uri, location);
continue;
}
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
throw new HttpRequestException($"Exceeded maximum redirect limit ({maxRedirects}).");
}
/// <summary> /// <summary>
/// If automatic update checking is enabled, checks if there are any updates available. /// If automatic update checking is enabled, checks if there are any updates available.
/// Returns the download URL if an update is available. /// Returns the download URL if an update is available.

Loading…
Cancel
Save