From 7986465cf785ca385fd1765326887e550bced033 Mon Sep 17 00:00:00 2001 From: Greenback Date: Sun, 6 Dec 2020 23:48:54 +0000 Subject: Initial upload --- MediaBrowser.Model/Updates/VersionInfo.cs | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'MediaBrowser.Model/Updates/VersionInfo.cs') diff --git a/MediaBrowser.Model/Updates/VersionInfo.cs b/MediaBrowser.Model/Updates/VersionInfo.cs index 844170999..1e07c9f26 100644 --- a/MediaBrowser.Model/Updates/VersionInfo.cs +++ b/MediaBrowser.Model/Updates/VersionInfo.cs @@ -1,6 +1,6 @@ -#nullable disable +#nullable enable -using System; +using SysVersion = System.Version; namespace MediaBrowser.Model.Updates { @@ -9,68 +9,68 @@ namespace MediaBrowser.Model.Updates /// public class VersionInfo { - private Version _version; + private SysVersion? _version; /// /// Gets or sets the version. /// /// The version. - public string version + public string Version { - get - { - return _version == null ? string.Empty : _version.ToString(); - } + get => _version == null ? string.Empty : _version.ToString(); - set - { - _version = Version.Parse(value); - } + set => _version = SysVersion.Parse(value); } /// - /// Gets the version as a . + /// Gets the version as a . /// - public Version VersionNumber => _version; + public SysVersion VersionNumber => _version ?? new SysVersion(0, 0, 0); /// /// Gets or sets the changelog for this version. /// /// The changelog. - public string changelog { get; set; } + public string? Changelog { get; set; } /// /// Gets or sets the ABI that this version was built against. /// /// The target ABI version. - public string targetAbi { get; set; } + public string? TargetAbi { get; set; } + + /// + /// Gets or sets the maximum ABI that this version will work with. + /// + /// The target ABI version. + public string? MaxAbi { get; set; } /// /// Gets or sets the source URL. /// /// The source URL. - public string sourceUrl { get; set; } + public string? SourceUrl { get; set; } /// /// Gets or sets a checksum for the binary. /// /// The checksum. - public string checksum { get; set; } + public string? Checksum { get; set; } /// /// Gets or sets a timestamp of when the binary was built. /// /// The timestamp. - public string timestamp { get; set; } + public string? Timestamp { get; set; } /// /// Gets or sets the repository name. /// - public string repositoryName { get; set; } + public string RepositoryName { get; set; } = string.Empty; /// /// Gets or sets the repository url. /// - public string repositoryUrl { get; set; } + public string RepositoryUrl { get; set; } = string.Empty; } } -- cgit v1.2.3 From c197dca759ee7353d7e9f477b3cc189eac0c14e0 Mon Sep 17 00:00:00 2001 From: Greenback Date: Tue, 15 Dec 2020 18:27:31 +0000 Subject: Changed PluginId to guid so its the same type as plugin.id --- Jellyfin.Api/Models/ConfigurationPageInfo.cs | 9 ++++----- MediaBrowser.Model/Updates/VersionInfo.cs | 12 +++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'MediaBrowser.Model/Updates/VersionInfo.cs') diff --git a/Jellyfin.Api/Models/ConfigurationPageInfo.cs b/Jellyfin.Api/Models/ConfigurationPageInfo.cs index 3c553a1b5..c15ed05d3 100644 --- a/Jellyfin.Api/Models/ConfigurationPageInfo.cs +++ b/Jellyfin.Api/Models/ConfigurationPageInfo.cs @@ -1,3 +1,4 @@ +using System; using MediaBrowser.Common.Plugins; using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Plugins; @@ -23,7 +24,7 @@ namespace Jellyfin.Api.Models { DisplayName = page.Plugin.Name; // Don't use "N" because it needs to match Plugin.Id - PluginId = page.Plugin.Id.ToString(); + PluginId = page.Plugin.Id; } } @@ -39,9 +40,7 @@ namespace Jellyfin.Api.Models MenuSection = page.MenuSection; MenuIcon = page.MenuIcon; DisplayName = string.IsNullOrWhiteSpace(page.DisplayName) ? plugin?.Name : page.DisplayName; - - // Don't use "N" because it needs to match Plugin.Id - PluginId = plugin?.Id.ToString(); + PluginId = plugin?.Id; } /// @@ -80,6 +79,6 @@ namespace Jellyfin.Api.Models /// Gets or sets the plugin id. /// /// The plugin id. - public string? PluginId { get; set; } + public Guid? PluginId { get; set; } } } diff --git a/MediaBrowser.Model/Updates/VersionInfo.cs b/MediaBrowser.Model/Updates/VersionInfo.cs index 1e07c9f26..503dba0a1 100644 --- a/MediaBrowser.Model/Updates/VersionInfo.cs +++ b/MediaBrowser.Model/Updates/VersionInfo.cs @@ -1,11 +1,12 @@ #nullable enable +using System.Text.Json.Serialization; using SysVersion = System.Version; namespace MediaBrowser.Model.Updates { /// - /// Class PackageVersionInfo. + /// Defines the class. /// public class VersionInfo { @@ -15,6 +16,7 @@ namespace MediaBrowser.Model.Updates /// Gets or sets the version. /// /// The version. + [JsonPropertyName("version")] public string Version { get => _version == null ? string.Empty : _version.ToString(); @@ -31,46 +33,54 @@ namespace MediaBrowser.Model.Updates /// Gets or sets the changelog for this version. /// /// The changelog. + [JsonPropertyName("changelog")] public string? Changelog { get; set; } /// /// Gets or sets the ABI that this version was built against. /// /// The target ABI version. + [JsonPropertyName("targetAbi")] public string? TargetAbi { get; set; } /// /// Gets or sets the maximum ABI that this version will work with. /// /// The target ABI version. + [JsonPropertyName("maxAbi")] public string? MaxAbi { get; set; } /// /// Gets or sets the source URL. /// /// The source URL. + [JsonPropertyName("sourceUrl")] public string? SourceUrl { get; set; } /// /// Gets or sets a checksum for the binary. /// /// The checksum. + [JsonPropertyName("checksum")] public string? Checksum { get; set; } /// /// Gets or sets a timestamp of when the binary was built. /// /// The timestamp. + [JsonPropertyName("timestamp")] public string? Timestamp { get; set; } /// /// Gets or sets the repository name. /// + [JsonPropertyName("repositoryName")] public string RepositoryName { get; set; } = string.Empty; /// /// Gets or sets the repository url. /// + [JsonPropertyName("repositoryUrl")] public string RepositoryUrl { get; set; } = string.Empty; } } -- cgit v1.2.3 From 486148dd6b18ec336ca076b8ec0a23d257789683 Mon Sep 17 00:00:00 2001 From: Greenback Date: Fri, 18 Dec 2020 09:44:57 +0000 Subject: Removed maxAbi --- Emby.Server.Implementations/ApplicationHost.cs | 1 - .../Plugins/PluginManager.cs | 11 +- .../Updates/InstallationManager.cs | 18 +- MediaBrowser.Common/Plugins/BasePlugin.cs | 210 -------------------- MediaBrowser.Common/Plugins/BasePluginOfT.cs | 218 +++++++++++++++++++++ MediaBrowser.Model/Updates/VersionInfo.cs | 7 - 6 files changed, 224 insertions(+), 241 deletions(-) create mode 100644 MediaBrowser.Common/Plugins/BasePluginOfT.cs (limited to 'MediaBrowser.Model/Updates/VersionInfo.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index d7bc83f3a..b91ba6b6c 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -286,7 +286,6 @@ namespace Emby.Server.Implementations this, ServerConfigurationManager.Configuration, ApplicationPaths.PluginsPath, - ApplicationPaths.CachePath, ApplicationVersion); } diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 151e2c203..4c508279c 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -39,17 +39,15 @@ namespace Emby.Server.Implementations.Plugins /// The . /// The . /// The plugin path. - /// The image cache path. /// The application version. public PluginManager( ILogger logger, IApplicationHost appHost, ServerConfiguration config, string pluginsPath, - string imagesPath, Version appVersion) { - _logger = _logger ?? throw new ArgumentNullException(nameof(logger)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _pluginsPath = pluginsPath; _appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion)); _jsonOptions = JsonDefaults.GetOptions(); @@ -509,17 +507,12 @@ namespace Emby.Server.Implementations.Plugins targetAbi = _minimumVersion; } - if (!Version.TryParse(manifest.MaxAbi, out var maxAbi)) - { - maxAbi = _appVersion; - } - if (!Version.TryParse(manifest.Version, out version)) { manifest.Version = _minimumVersion.ToString(); } - return new LocalPlugin(dir, _appVersion >= targetAbi && _appVersion <= maxAbi, manifest); + return new LocalPlugin(dir, _appVersion >= targetAbi, manifest); } // No metafile, so lets see if the folder is versioned. diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 70424369b..cf059fb97 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -132,13 +132,8 @@ namespace Emby.Server.Implementations.Updates targetAbi = minimumVersion; } - if (!Version.TryParse(ver.MaxAbi, out var maxAbi)) - { - maxAbi = _applicationHost.ApplicationVersion; - } - // Only show plugins that fall between targetAbi and maxAbi - if (_applicationHost.ApplicationVersion >= targetAbi && _applicationHost.ApplicationVersion <= maxAbi) + if (_applicationHost.ApplicationVersion >= targetAbi) { continue; } @@ -200,19 +195,15 @@ namespace Emby.Server.Implementations.Updates // Update the manifests, if anything changes. if (plugin != null) { - bool noChange = string.Equals(plugin.Manifest.MaxAbi, version.MaxAbi, StringComparison.Ordinal) - || string.Equals(plugin.Manifest.TargetAbi, version.TargetAbi, StringComparison.Ordinal); - if (!noChange) + if (!string.Equals(plugin.Manifest.TargetAbi, version.TargetAbi, StringComparison.Ordinal)) { - plugin.Manifest.MaxAbi = version.MaxAbi ?? string.Empty; plugin.Manifest.TargetAbi = version.TargetAbi ?? string.Empty; _pluginManager.SaveManifest(plugin.Manifest, plugin.Path); } } // Remove versions with a target abi that is greater then the current application version. - if ((Version.TryParse(version.TargetAbi, out var targetAbi) && _applicationHost.ApplicationVersion < targetAbi) - || (Version.TryParse(version.MaxAbi, out var maxAbi) && _applicationHost.ApplicationVersion > maxAbi)) + if (Version.TryParse(version.TargetAbi, out var targetAbi) && _applicationHost.ApplicationVersion < targetAbi) { package.Versions.RemoveAt(i); } @@ -283,8 +274,7 @@ namespace Emby.Server.Implementations.Updates var appVer = _applicationHost.ApplicationVersion; var availableVersions = package.Versions - .Where(x => (string.IsNullOrEmpty(x.TargetAbi) || Version.Parse(x.TargetAbi) <= appVer) - && (string.IsNullOrEmpty(x.MaxAbi) || Version.Parse(x.MaxAbi) >= appVer)); + .Where(x => string.IsNullOrEmpty(x.TargetAbi) || Version.Parse(x.TargetAbi) <= appVer); if (specificVersion != null) { diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 5750c59c4..e228ae7ec 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -1,5 +1,3 @@ -#pragma warning disable SA1402 - using System; using System.IO; using System.Reflection; @@ -94,212 +92,4 @@ namespace MediaBrowser.Common.Plugins Id = assemblyId; } } - - /// - /// Provides a common base class for all plugins. - /// - /// The type of the T configuration type. - public abstract class BasePlugin : BasePlugin, IHasPluginConfiguration - where TConfigurationType : BasePluginConfiguration - { - /// - /// The configuration sync lock. - /// - private readonly object _configurationSyncLock = new object(); - - /// - /// The configuration save lock. - /// - private readonly object _configurationSaveLock = new object(); - - private Action _directoryCreateFn; - - /// - /// The configuration. - /// - private TConfigurationType _configuration; - - /// - /// Initializes a new instance of the class. - /// - /// The application paths. - /// The XML serializer. - protected BasePlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) - { - ApplicationPaths = applicationPaths; - XmlSerializer = xmlSerializer; - if (this is IPluginAssembly assemblyPlugin) - { - var assembly = GetType().Assembly; - var assemblyName = assembly.GetName(); - var assemblyFilePath = assembly.Location; - - var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath)); - if (!Directory.Exists(dataFolderPath)) - { - // Try again with the version number appended to the folder name. - dataFolderPath = dataFolderPath + "_" + Version.ToString(); - } - - assemblyPlugin.SetAttributes(assemblyFilePath, dataFolderPath, assemblyName.Version); - - var idAttributes = assembly.GetCustomAttributes(typeof(GuidAttribute), true); - if (idAttributes.Length > 0) - { - var attribute = (GuidAttribute)idAttributes[0]; - var assemblyId = new Guid(attribute.Value); - - assemblyPlugin.SetId(assemblyId); - } - } - - if (this is IHasPluginConfiguration hasPluginConfiguration) - { - hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s)); - } - } - - /// - /// Gets the application paths. - /// - /// The application paths. - protected IApplicationPaths ApplicationPaths { get; private set; } - - /// - /// Gets the XML serializer. - /// - /// The XML serializer. - protected IXmlSerializer XmlSerializer { get; private set; } - - /// - /// Gets the type of configuration this plugin uses. - /// - /// The type of the configuration. - public Type ConfigurationType => typeof(TConfigurationType); - - /// - /// Gets or sets the event handler that is triggered when this configuration changes. - /// - public EventHandler ConfigurationChanged { get; set; } - - /// - /// Gets the name the assembly file. - /// - /// The name of the assembly file. - protected string AssemblyFileName => Path.GetFileName(AssemblyFilePath); - - /// - /// Gets or sets the plugin configuration. - /// - /// The configuration. - public TConfigurationType Configuration - { - get - { - // Lazy load - if (_configuration == null) - { - lock (_configurationSyncLock) - { - if (_configuration == null) - { - _configuration = LoadConfiguration(); - } - } - } - - return _configuration; - } - - protected set => _configuration = value; - } - - /// - /// Gets the name of the configuration file. Subclasses should override. - /// - /// The name of the configuration file. - public virtual string ConfigurationFileName => Path.ChangeExtension(AssemblyFileName, ".xml"); - - /// - /// Gets the full path to the configuration file. - /// - /// The configuration file path. - public string ConfigurationFilePath { get; } - - /// - /// Gets the plugin configuration. - /// - /// The configuration. - BasePluginConfiguration IHasPluginConfiguration.Configuration => Configuration; - - /// - public void SetStartupInfo(Action directoryCreateFn) - { - // hack alert, until the .net core transition is complete - _directoryCreateFn = directoryCreateFn; - } - - private TConfigurationType LoadConfiguration() - { - var path = ConfigurationFilePath; - - try - { - return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path); - } - catch - { - var config = (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); - SaveConfiguration(config); - return config; - } - } - - /// - /// Saves the current configuration to the file system. - /// - /// Configuration to save. - public virtual void SaveConfiguration(TConfigurationType config) - { - lock (_configurationSaveLock) - { - _directoryCreateFn(Path.GetDirectoryName(ConfigurationFilePath)); - - XmlSerializer.SerializeToFile(config, ConfigurationFilePath); - } - } - - /// - /// Saves the current configuration to the file system. - /// - public virtual void SaveConfiguration() - { - SaveConfiguration(Configuration); - } - - /// - public virtual void UpdateConfiguration(BasePluginConfiguration configuration) - { - if (configuration == null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - Configuration = (TConfigurationType)configuration; - - SaveConfiguration(Configuration); - - ConfigurationChanged?.Invoke(this, configuration); - } - - /// - public override PluginInfo GetPluginInfo() - { - var info = base.GetPluginInfo(); - - info.ConfigurationFileName = ConfigurationFileName; - - return info; - } - } } diff --git a/MediaBrowser.Common/Plugins/BasePluginOfT.cs b/MediaBrowser.Common/Plugins/BasePluginOfT.cs new file mode 100644 index 000000000..66aec92ab --- /dev/null +++ b/MediaBrowser.Common/Plugins/BasePluginOfT.cs @@ -0,0 +1,218 @@ +#pragma warning disable SA1649 // File name should match first type name +using System; +using System.IO; +using System.Runtime.InteropServices; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Plugins; +using MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Common.Plugins +{ + /// + /// Provides a common base class for all plugins. + /// + /// The type of the T configuration type. + public abstract class BasePlugin : BasePlugin, IHasPluginConfiguration + where TConfigurationType : BasePluginConfiguration + { + /// + /// The configuration sync lock. + /// + private readonly object _configurationSyncLock = new object(); + + /// + /// The configuration save lock. + /// + private readonly object _configurationSaveLock = new object(); + + private Action _directoryCreateFn; + + /// + /// The configuration. + /// + private TConfigurationType _configuration; + + /// + /// Initializes a new instance of the class. + /// + /// The application paths. + /// The XML serializer. + protected BasePlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) + { + ApplicationPaths = applicationPaths; + XmlSerializer = xmlSerializer; + if (this is IPluginAssembly assemblyPlugin) + { + var assembly = GetType().Assembly; + var assemblyName = assembly.GetName(); + var assemblyFilePath = assembly.Location; + + var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath)); + if (!Directory.Exists(dataFolderPath)) + { + // Try again with the version number appended to the folder name. + dataFolderPath = dataFolderPath + "_" + Version.ToString(); + } + + assemblyPlugin.SetAttributes(assemblyFilePath, dataFolderPath, assemblyName.Version); + + var idAttributes = assembly.GetCustomAttributes(typeof(GuidAttribute), true); + if (idAttributes.Length > 0) + { + var attribute = (GuidAttribute)idAttributes[0]; + var assemblyId = new Guid(attribute.Value); + + assemblyPlugin.SetId(assemblyId); + } + } + + if (this is IHasPluginConfiguration hasPluginConfiguration) + { + hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s)); + } + } + + /// + /// Gets the application paths. + /// + /// The application paths. + protected IApplicationPaths ApplicationPaths { get; private set; } + + /// + /// Gets the XML serializer. + /// + /// The XML serializer. + protected IXmlSerializer XmlSerializer { get; private set; } + + /// + /// Gets the type of configuration this plugin uses. + /// + /// The type of the configuration. + public Type ConfigurationType => typeof(TConfigurationType); + + /// + /// Gets or sets the event handler that is triggered when this configuration changes. + /// + public EventHandler ConfigurationChanged { get; set; } + + /// + /// Gets the name the assembly file. + /// + /// The name of the assembly file. + protected string AssemblyFileName => Path.GetFileName(AssemblyFilePath); + + /// + /// Gets or sets the plugin configuration. + /// + /// The configuration. + public TConfigurationType Configuration + { + get + { + // Lazy load + if (_configuration == null) + { + lock (_configurationSyncLock) + { + if (_configuration == null) + { + _configuration = LoadConfiguration(); + } + } + } + + return _configuration; + } + + protected set => _configuration = value; + } + + /// + /// Gets the name of the configuration file. Subclasses should override. + /// + /// The name of the configuration file. + public virtual string ConfigurationFileName => Path.ChangeExtension(AssemblyFileName, ".xml"); + + /// + /// Gets the full path to the configuration file. + /// + /// The configuration file path. + public string ConfigurationFilePath { get; } + + /// + /// Gets the plugin configuration. + /// + /// The configuration. + BasePluginConfiguration IHasPluginConfiguration.Configuration => Configuration; + + /// + public void SetStartupInfo(Action directoryCreateFn) + { + // hack alert, until the .net core transition is complete + _directoryCreateFn = directoryCreateFn; + } + + /// + /// Saves the current configuration to the file system. + /// + /// Configuration to save. + public virtual void SaveConfiguration(TConfigurationType config) + { + lock (_configurationSaveLock) + { + _directoryCreateFn(Path.GetDirectoryName(ConfigurationFilePath)); + + XmlSerializer.SerializeToFile(config, ConfigurationFilePath); + } + } + + /// + /// Saves the current configuration to the file system. + /// + public virtual void SaveConfiguration() + { + SaveConfiguration(Configuration); + } + + /// + public virtual void UpdateConfiguration(BasePluginConfiguration configuration) + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + Configuration = (TConfigurationType)configuration; + + SaveConfiguration(Configuration); + + ConfigurationChanged?.Invoke(this, configuration); + } + + /// + public override PluginInfo GetPluginInfo() + { + var info = base.GetPluginInfo(); + + info.ConfigurationFileName = ConfigurationFileName; + + return info; + } + + private TConfigurationType LoadConfiguration() + { + var path = ConfigurationFilePath; + + try + { + return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path); + } + catch + { + var config = (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); + SaveConfiguration(config); + return config; + } + } + } +} diff --git a/MediaBrowser.Model/Updates/VersionInfo.cs b/MediaBrowser.Model/Updates/VersionInfo.cs index 503dba0a1..209092265 100644 --- a/MediaBrowser.Model/Updates/VersionInfo.cs +++ b/MediaBrowser.Model/Updates/VersionInfo.cs @@ -43,13 +43,6 @@ namespace MediaBrowser.Model.Updates [JsonPropertyName("targetAbi")] public string? TargetAbi { get; set; } - /// - /// Gets or sets the maximum ABI that this version will work with. - /// - /// The target ABI version. - [JsonPropertyName("maxAbi")] - public string? MaxAbi { get; set; } - /// /// Gets or sets the source URL. /// -- cgit v1.2.3