update the updater

pull/702/head
Luke Pulverenti 9 years ago
parent 614edab79f
commit e0e4ebb0bb

@ -25,7 +25,7 @@ namespace MediaBrowser.Common.Implementations.Updates
_cacheLength = cacheLength; _cacheLength = cacheLength;
} }
public async Task<CheckForUpdateResult> CheckForUpdateResult(string organzation, string repository, Version minVersion, bool includePrerelease, string[] excludeSuffixes, string assetFilename, string packageName, string targetFilename, CancellationToken cancellationToken) public async Task<CheckForUpdateResult> CheckForUpdateResult(string organzation, string repository, Version minVersion, PackageVersionClass updateLevel, string assetFilename, string packageName, string targetFilename, CancellationToken cancellationToken)
{ {
var url = string.Format("https://api.github.com/repos/{0}/{1}/releases", organzation, repository); var url = string.Format("https://api.github.com/repos/{0}/{1}/releases", organzation, repository);
@ -44,42 +44,31 @@ namespace MediaBrowser.Common.Implementations.Updates
options.CacheLength = _cacheLength; options.CacheLength = _cacheLength;
} }
using (var stream = await _httpClient.Get(new HttpRequestOptions using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
{
Url = url,
EnableKeepAlive = false,
CancellationToken = cancellationToken,
UserAgent = "Emby/3.0"
}).ConfigureAwait(false))
{ {
var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream); var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream);
var availableUpdate = CheckForUpdateResult(obj, minVersion, includePrerelease, excludeSuffixes, assetFilename, packageName, targetFilename); return CheckForUpdateResult(obj, minVersion, updateLevel, assetFilename, packageName, targetFilename);
return availableUpdate ?? new CheckForUpdateResult
{
IsUpdateAvailable = false
};
} }
} }
private CheckForUpdateResult CheckForUpdateResult(RootObject[] obj, Version minVersion, bool includePrerelease, string[] excludeSuffixes, string assetFilename, string packageName, string targetFilename) private CheckForUpdateResult CheckForUpdateResult(RootObject[] obj, Version minVersion, PackageVersionClass updateLevel, string assetFilename, string packageName, string targetFilename)
{ {
if (!includePrerelease) if (updateLevel == PackageVersionClass.Release)
{ {
obj = obj.Where(i => !i.prerelease).ToArray(); obj = obj.Where(i => !i.prerelease).ToArray();
} }
else if (updateLevel == PackageVersionClass.Beta)
if (excludeSuffixes.Length > 0)
{ {
obj = obj.Where(i => !excludeSuffixes.Any(e => i.name.EndsWith(e, StringComparison.OrdinalIgnoreCase))).ToArray(); obj = obj.Where(i => !i.prerelease || !i.name.EndsWith("-dev", StringComparison.OrdinalIgnoreCase)).ToArray();
} }
// TODO: var availableUpdate = obj.Select(i => CheckForUpdateResult(i, minVersion, assetFilename, packageName, targetFilename)).FirstOrDefault(i => i != null);
// Filter using name and check for suffixes such as -beta, -dev?
return obj.Select(i => CheckForUpdateResult(i, minVersion, assetFilename, packageName, targetFilename)).FirstOrDefault(i => i != null); return availableUpdate ?? new CheckForUpdateResult
{
IsUpdateAvailable = false
};
} }
private CheckForUpdateResult CheckForUpdateResult(RootObject obj, Version minVersion, string assetFilename, string packageName, string targetFilename) private CheckForUpdateResult CheckForUpdateResult(RootObject obj, Version minVersion, string assetFilename, string packageName, string targetFilename)
@ -108,7 +97,9 @@ namespace MediaBrowser.Common.Implementations.Updates
IsUpdateAvailable = version > minVersion, IsUpdateAvailable = version > minVersion,
Package = new PackageVersionInfo Package = new PackageVersionInfo
{ {
classification = obj.prerelease ? PackageVersionClass.Beta : PackageVersionClass.Release, classification = obj.prerelease ?
(obj.name.EndsWith("-dev", StringComparison.OrdinalIgnoreCase) ? PackageVersionClass.Dev : PackageVersionClass.Beta) :
PackageVersionClass.Release,
name = packageName, name = packageName,
sourceUrl = asset.browser_download_url, sourceUrl = asset.browser_download_url,
targetFilename = targetFilename, targetFilename = targetFilename,

@ -1301,30 +1301,20 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>Task{CheckForUpdateResult}.</returns> /// <returns>Task{CheckForUpdateResult}.</returns>
public override Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress) public override Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
{ {
var includePreRelease = false;
var cacheLength = TimeSpan.FromHours(12); var cacheLength = TimeSpan.FromHours(12);
var excludeSuffixes = new List<string>(); var updateLevel = ConfigurationManager.CommonConfiguration.SystemUpdateLevel;
if (ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Release) if (updateLevel == PackageVersionClass.Beta)
{ {
// Shouldn't actually be needed due to the prerelease filter
excludeSuffixes.Add("-beta");
excludeSuffixes.Add("-dev");
}
else if (ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Beta)
{
excludeSuffixes.Add("-dev");
cacheLength = TimeSpan.FromHours(1); cacheLength = TimeSpan.FromHours(1);
includePreRelease = true;
} }
else if (ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev) else if (updateLevel == PackageVersionClass.Dev)
{ {
cacheLength = TimeSpan.FromMinutes(5); cacheLength = TimeSpan.FromMinutes(5);
includePreRelease = true;
} }
return new GithubUpdater(HttpClient, JsonSerializer, cacheLength) return new GithubUpdater(HttpClient, JsonSerializer, cacheLength).CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, updateLevel, _releaseAssetFilename,
.CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, includePreRelease, excludeSuffixes.ToArray(), _releaseAssetFilename, "MBServer", "Mbserver.zip", cancellationToken); "MBServer", "Mbserver.zip", cancellationToken);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save