diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index 0c6ee20f79..b152f02020 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -15,7 +15,7 @@ namespace MediaBrowser.Api /// Class GetPackage /// [Route("/Packages/{Name}", "GET")] - [Api(("Gets a package, by name"))] + [Api(("Gets a package, by name or assembly guid"))] public class GetPackage : IReturn { /// @@ -24,6 +24,13 @@ namespace MediaBrowser.Api /// The name. [ApiMember(Name = "Name", Description = "The name of the package", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Name { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "AssemblyGuid", Description = "The guid of the associated assembly", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string AssemblyGuid { get; set; } } /// @@ -76,6 +83,13 @@ namespace MediaBrowser.Api [ApiMember(Name = "Name", Description = "Package name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] public string Name { get; set; } + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "AssemblyGuid", Description = "Guid of the associated assembly", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] + public string AssemblyGuid { get; set; } + /// /// Gets or sets the version. /// @@ -157,7 +171,8 @@ namespace MediaBrowser.Api { var packages = _installationManager.GetAvailablePackages(CancellationToken.None, applicationVersion: _appHost.ApplicationVersion).Result; - var result = packages.FirstOrDefault(p => p.name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); + var result = packages.FirstOrDefault(p => string.Equals(p.guid, request.AssemblyGuid ?? "none", StringComparison.OrdinalIgnoreCase)) + ?? packages.FirstOrDefault(p => p.name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); return ToOptimizedResult(result); } @@ -194,8 +209,8 @@ namespace MediaBrowser.Api public void Post(InstallPackage request) { var package = string.IsNullOrEmpty(request.Version) ? - _installationManager.GetLatestCompatibleVersion(request.Name, _appHost.ApplicationVersion, request.UpdateClass).Result : - _installationManager.GetPackage(request.Name, request.UpdateClass, Version.Parse(request.Version)).Result; + _installationManager.GetLatestCompatibleVersion(request.Name, request.AssemblyGuid, _appHost.ApplicationVersion, request.UpdateClass).Result : + _installationManager.GetPackage(request.Name, request.AssemblyGuid, request.UpdateClass, Version.Parse(request.Version)).Result; if (package == null) { diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index 72e739bccb..56641296f6 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -255,14 +255,16 @@ namespace MediaBrowser.Common.Implementations.Updates /// Gets the package. /// /// The name. + /// The assembly guid /// The classification. /// The version. /// Task{PackageVersionInfo}. - public async Task GetPackage(string name, PackageVersionClass classification, Version version) + public async Task GetPackage(string name, string guid, PackageVersionClass classification, Version version) { var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false); - var package = packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); + var package = packages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase)) + ?? packages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (package == null) { @@ -276,14 +278,15 @@ namespace MediaBrowser.Common.Implementations.Updates /// Gets the latest compatible version. /// /// The name. + /// The assembly guid if this is a plug-in /// The current server version. /// The classification. /// Task{PackageVersionInfo}. - public async Task GetLatestCompatibleVersion(string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release) + public async Task GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release) { var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false); - return GetLatestCompatibleVersion(packages, name, currentServerVersion, classification); + return GetLatestCompatibleVersion(packages, name, guid, currentServerVersion, classification); } /// @@ -294,9 +297,10 @@ namespace MediaBrowser.Common.Implementations.Updates /// The current server version. /// The classification. /// PackageVersionInfo. - public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable availablePackages, string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release) + public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release) { - var package = availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); + var package = availablePackages.FirstOrDefault(p => string.Equals(p.guid, guid ?? "none", StringComparison.OrdinalIgnoreCase)) + ?? availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (package == null) { @@ -331,14 +335,14 @@ namespace MediaBrowser.Common.Implementations.Updates // Figure out what needs to be installed var packages = plugins.Select(p => { - var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, applicationVersion, p.Configuration.UpdateClass); + var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Id.ToString(), applicationVersion, p.Configuration.UpdateClass); return latestPluginInfo != null && latestPluginInfo.version != null && latestPluginInfo.version > p.Version ? latestPluginInfo : null; }).Where(i => i != null).ToList(); return packages - .Where(p => !string.IsNullOrWhiteSpace(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.Name, p.name, StringComparison.OrdinalIgnoreCase))); + .Where(p => !string.IsNullOrWhiteSpace(p.sourceUrl) && !CompletedInstallations.Any(i => string.Equals(i.AssemblyGuid, p.guid, StringComparison.OrdinalIgnoreCase))); } /// @@ -365,6 +369,7 @@ namespace MediaBrowser.Common.Implementations.Updates { Id = Guid.NewGuid(), Name = package.name, + AssemblyGuid = package.guid, UpdateClass = package.classification, Version = package.versionStr }; @@ -471,7 +476,8 @@ namespace MediaBrowser.Common.Implementations.Updates if (!string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".rar", StringComparison.OrdinalIgnoreCase) && !string.Equals(extension, ".7z", StringComparison.OrdinalIgnoreCase)) { // Set last update time if we were installed before - var plugin = _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase)); + var plugin = _applicationHost.Plugins.FirstOrDefault(p => string.Equals(p.Id.ToString(), package.guid, StringComparison.OrdinalIgnoreCase)) + ?? _applicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase)); if (plugin != null) { diff --git a/MediaBrowser.Common/Updates/IInstallationManager.cs b/MediaBrowser.Common/Updates/IInstallationManager.cs index b64506c973..f162f8dc8c 100644 --- a/MediaBrowser.Common/Updates/IInstallationManager.cs +++ b/MediaBrowser.Common/Updates/IInstallationManager.cs @@ -58,34 +58,37 @@ namespace MediaBrowser.Common.Updates /// The cancellation token. /// Task{List{PackageInfo}}. Task> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken); - + /// /// Gets the package. /// /// The name. + /// The assembly guid /// The classification. /// The version. /// Task{PackageVersionInfo}. - Task GetPackage(string name, PackageVersionClass classification, Version version); + Task GetPackage(string name, string guid, PackageVersionClass classification, Version version); /// /// Gets the latest compatible version. /// /// The name. + /// The assembly guid /// The current server version. /// The classification. /// Task{PackageVersionInfo}. - Task GetLatestCompatibleVersion(string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release); + Task GetLatestCompatibleVersion(string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release); /// /// Gets the latest compatible version. /// /// The available packages. /// The name. + /// The assembly guid /// The current server version. /// The classification. /// PackageVersionInfo. - PackageVersionInfo GetLatestCompatibleVersion(IEnumerable availablePackages, string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release); + PackageVersionInfo GetLatestCompatibleVersion(IEnumerable availablePackages, string name, string guid, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release); /// /// Gets the available plugin updates. diff --git a/MediaBrowser.Model/Updates/InstallationInfo.cs b/MediaBrowser.Model/Updates/InstallationInfo.cs index 55848b8e54..09b4975a86 100644 --- a/MediaBrowser.Model/Updates/InstallationInfo.cs +++ b/MediaBrowser.Model/Updates/InstallationInfo.cs @@ -19,6 +19,12 @@ namespace MediaBrowser.Model.Updates /// The name. public string Name { get; set; } + /// + /// Gets or sets the assembly guid. + /// + /// The guid of the assembly. + public string AssemblyGuid { get; set; } + /// /// Gets or sets the version. /// diff --git a/MediaBrowser.Model/Updates/PackageInfo.cs b/MediaBrowser.Model/Updates/PackageInfo.cs index c13d59adb4..9f8f90f2bd 100644 --- a/MediaBrowser.Model/Updates/PackageInfo.cs +++ b/MediaBrowser.Model/Updates/PackageInfo.cs @@ -104,6 +104,13 @@ namespace MediaBrowser.Model.Updates /// The target system. public PackageTargetSystem targetSystem { get; set; } + /// + /// The guid of the assembly associated with this package (if a plug-in). + /// This is used to identify the proper item for automatic updates. + /// + /// The name. + public string guid { get; set; } + /// /// Gets or sets whether or not this package is registered. /// diff --git a/MediaBrowser.Model/Updates/PackageVersionInfo.cs b/MediaBrowser.Model/Updates/PackageVersionInfo.cs index eb447795e4..8b7b65f0cc 100644 --- a/MediaBrowser.Model/Updates/PackageVersionInfo.cs +++ b/MediaBrowser.Model/Updates/PackageVersionInfo.cs @@ -15,6 +15,12 @@ namespace MediaBrowser.Model.Updates /// The name. public string name { get; set; } + /// + /// Gets or sets the guid. + /// + /// The guid. + public string guid { get; set; } + /// /// Gets or sets the version STR. /// diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 0ec1d68135..c5c5bc7e53 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -683,7 +683,7 @@ namespace MediaBrowser.ServerApplication { var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false); - var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ApplicationVersion, + var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, null, ApplicationVersion, ConfigurationManager.CommonConfiguration.SystemUpdateLevel); return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } : diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index 25cbc98779..58f4421ca3 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -730,7 +730,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi /** * Installs or updates a new plugin */ - self.installPlugin = function (name, updateClass, version) { + self.installPlugin = function (name, guid, updateClass, version) { if (!name) { throw new Error("null name"); @@ -741,7 +741,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi } var options = { - updateClass: updateClass + updateClass: updateClass, + AssemblyGuid: guid }; if (version) { @@ -785,13 +786,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi /** * Gets information about an installable package */ - self.getPackageInfo = function (name) { + self.getPackageInfo = function (name, guid) { if (!name) { throw new Error("null name"); } - var url = self.getUrl("Packages/" + name); + var options = { + AssemblyGuid: guid + }; + + var url = self.getUrl("Packages/" + name, options); return self.ajax({ type: "GET",