update github updater

This commit is contained in:
Luke Pulverenti 2016-01-03 14:01:05 -05:00
parent 3560e61596
commit 316b7da1a3
4 changed files with 36 additions and 36 deletions

View file

@ -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 assetFilename, string packageName, string targetFilename, CancellationToken cancellationToken) public async Task<CheckForUpdateResult> CheckForUpdateResult(string organzation, string repository, Version minVersion, bool includePrerelease, string[] excludeSuffixes, 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);
@ -55,7 +55,7 @@ namespace MediaBrowser.Common.Implementations.Updates
{ {
var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream); var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream);
var availableUpdate = CheckForUpdateResult(obj, minVersion, includePrerelease, assetFilename, packageName, targetFilename); var availableUpdate = CheckForUpdateResult(obj, minVersion, includePrerelease, excludeSuffixes, assetFilename, packageName, targetFilename);
return availableUpdate ?? new CheckForUpdateResult return availableUpdate ?? new CheckForUpdateResult
{ {
@ -64,13 +64,18 @@ namespace MediaBrowser.Common.Implementations.Updates
} }
} }
private CheckForUpdateResult CheckForUpdateResult(RootObject[] obj, Version minVersion, bool includePrerelease, string assetFilename, string packageName, string targetFilename) private CheckForUpdateResult CheckForUpdateResult(RootObject[] obj, Version minVersion, bool includePrerelease, string[] excludeSuffixes, string assetFilename, string packageName, string targetFilename)
{ {
if (!includePrerelease) if (!includePrerelease)
{ {
obj = obj.Where(i => !i.prerelease).ToArray(); obj = obj.Where(i => !i.prerelease).ToArray();
} }
if (excludeSuffixes.Length > 0)
{
obj = obj.Where(i => !excludeSuffixes.Any(e => i.name.EndsWith(e, StringComparison.OrdinalIgnoreCase))).ToArray();
}
// TODO: // TODO:
// Filter using name and check for suffixes such as -beta, -dev? // Filter using name and check for suffixes such as -beta, -dev?

View file

@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Mono
var nativeApp = new NativeApp(options); var nativeApp = new NativeApp(options);
_appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "MBServer.Mono", nativeApp); _appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "emby.mono.zip", nativeApp);
if (options.ContainsOption("-v")) if (options.ContainsOption("-v"))
{ {

View file

@ -207,7 +207,7 @@ namespace MediaBrowser.Server.Startup.Common
private IPlaylistManager PlaylistManager { get; set; } private IPlaylistManager PlaylistManager { get; set; }
private readonly StartupOptions _startupOptions; private readonly StartupOptions _startupOptions;
private readonly string _remotePackageName; private readonly string _releaseAssetFilename;
internal INativeApp NativeApp { get; set; } internal INativeApp NativeApp { get; set; }
private Timer _ipAddressCacheTimer; private Timer _ipAddressCacheTimer;
@ -219,18 +219,18 @@ namespace MediaBrowser.Server.Startup.Common
/// <param name="logManager">The log manager.</param> /// <param name="logManager">The log manager.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="fileSystem">The file system.</param> /// <param name="fileSystem">The file system.</param>
/// <param name="remotePackageName">Name of the remote package.</param> /// <param name="releaseAssetFilename">The release asset filename.</param>
/// <param name="nativeApp">The native application.</param> /// <param name="nativeApp">The native application.</param>
public ApplicationHost(ServerApplicationPaths applicationPaths, public ApplicationHost(ServerApplicationPaths applicationPaths,
ILogManager logManager, ILogManager logManager,
StartupOptions options, StartupOptions options,
IFileSystem fileSystem, IFileSystem fileSystem,
string remotePackageName, string releaseAssetFilename,
INativeApp nativeApp) INativeApp nativeApp)
: base(applicationPaths, logManager, fileSystem) : base(applicationPaths, logManager, fileSystem)
{ {
_startupOptions = options; _startupOptions = options;
_remotePackageName = remotePackageName; _releaseAssetFilename = releaseAssetFilename;
NativeApp = nativeApp; NativeApp = nativeApp;
SetBaseExceptionMessage(); SetBaseExceptionMessage();
@ -1309,36 +1309,31 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>Task{CheckForUpdateResult}.</returns> /// <returns>Task{CheckForUpdateResult}.</returns>
public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress) public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
{ {
if (ConfigurationManager.CommonConfiguration.SystemUpdateLevel != PackageVersionClass.Dev) var includePreRelease = false;
{ var cacheLength = TimeSpan.FromHours(12);
var includePreRelease = ConfigurationManager.CommonConfiguration.SystemUpdateLevel != PackageVersionClass.Release; var excludeSuffixes = new List<string>();
var cacheLength = TimeSpan.FromHours(1); if (ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Release)
{
// 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);
includePreRelease = true;
}
else if (ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev)
{
excludeSuffixes.Add("-dev");
cacheLength = TimeSpan.FromMinutes(5);
includePreRelease = true;
}
return await new GithubUpdater(HttpClient, JsonSerializer, cacheLength) return await new GithubUpdater(HttpClient, JsonSerializer, cacheLength)
.CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, includePreRelease, "emby.windows.zip", "MBServer", "Mbserver.zip", cancellationToken).ConfigureAwait(false); .CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, includePreRelease, excludeSuffixes.ToArray(), _releaseAssetFilename, "MBServer", "Mbserver.zip", cancellationToken).ConfigureAwait(false);
}
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, _remotePackageName, null, ApplicationVersion, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
var versionObject = version == null || string.IsNullOrWhiteSpace(version.versionStr) ? null : new Version(version.versionStr);
var isUpdateAvailable = versionObject != null && versionObject > ApplicationVersion;
var result = versionObject != null ?
new CheckForUpdateResult { AvailableVersion = versionObject.ToString(), IsUpdateAvailable = isUpdateAvailable, Package = version } :
new CheckForUpdateResult { AvailableVersion = ApplicationVersion.ToString(), IsUpdateAvailable = false };
HasUpdateAvailable = result.IsUpdateAvailable;
if (result.IsUpdateAvailable)
{
Logger.Info("New application version is available: {0}", result.AvailableVersion);
}
return result;
} }
/// <summary> /// <summary>

View file

@ -225,7 +225,7 @@ namespace MediaBrowser.ServerApplication
logManager, logManager,
options, options,
fileSystem, fileSystem,
"MBServer", "emby.windows.zip",
nativeApp); nativeApp);
var initProgress = new Progress<double>(); var initProgress = new Progress<double>();