repo creation with initial code after cloning public repo

This commit is contained in:
2026-02-19 07:36:25 -05:00
commit 460884fea3
2860 changed files with 650825 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
#nullable disable
using System;
using System.IO;
using System.Reflection;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Provides a common base class for all plugins.
/// </summary>
public abstract class BasePlugin : IPlugin, IPluginAssembly
{
/// <summary>
/// Gets the name of the plugin.
/// </summary>
/// <value>The name.</value>
public abstract string Name { get; }
/// <summary>
/// Gets the description.
/// </summary>
/// <value>The description.</value>
public virtual string Description => string.Empty;
/// <summary>
/// Gets the unique id.
/// </summary>
/// <value>The unique id.</value>
public virtual Guid Id { get; private set; }
/// <summary>
/// Gets the plugin version.
/// </summary>
/// <value>The version.</value>
public Version Version { get; private set; }
/// <summary>
/// Gets the path to the assembly file.
/// </summary>
/// <value>The assembly file path.</value>
public string AssemblyFilePath { get; private set; }
/// <summary>
/// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed.
/// </summary>
/// <value>The data folder path.</value>
public string DataFolderPath { get; private set; }
/// <summary>
/// Gets a value indicating whether the plugin can be uninstalled.
/// </summary>
public bool CanUninstall => !Path.GetDirectoryName(AssemblyFilePath)
.Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), StringComparison.Ordinal);
/// <summary>
/// Gets the plugin info.
/// </summary>
/// <returns>PluginInfo.</returns>
public virtual PluginInfo GetPluginInfo()
{
var info = new PluginInfo(
Name,
Version,
Description,
Id,
CanUninstall);
return info;
}
/// <summary>
/// Called just before the plugin is uninstalled from the server.
/// </summary>
public virtual void OnUninstalling()
{
}
/// <inheritdoc />
public void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion)
{
AssemblyFilePath = assemblyFilePath;
DataFolderPath = dataFolderPath;
Version = assemblyVersion;
}
/// <inheritdoc />
public void SetId(Guid assemblyId)
{
Id = assemblyId;
}
}
}
@@ -0,0 +1,200 @@
#nullable disable
#pragma warning disable SA1649 // File name should match first type name
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Provides a common base class for all plugins.
/// </summary>
/// <typeparam name="TConfigurationType">The type of the T configuration type.</typeparam>
public abstract class BasePlugin<TConfigurationType> : BasePlugin, IHasPluginConfiguration
where TConfigurationType : BasePluginConfiguration
{
/// <summary>
/// The configuration sync lock.
/// </summary>
private readonly Lock _configurationSyncLock = new();
/// <summary>
/// The configuration save lock.
/// </summary>
private readonly Lock _configurationSaveLock = new();
/// <summary>
/// The configuration.
/// </summary>
private TConfigurationType _configuration;
/// <summary>
/// Initializes a new instance of the <see cref="BasePlugin{TConfigurationType}" /> class.
/// </summary>
/// <param name="applicationPaths">The application paths.</param>
/// <param name="xmlSerializer">The XML serializer.</param>
protected BasePlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
{
ApplicationPaths = applicationPaths;
XmlSerializer = xmlSerializer;
var assembly = GetType().Assembly;
var assemblyName = assembly.GetName();
var assemblyFilePath = assembly.Location;
var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath));
if (Version is not null && !Directory.Exists(dataFolderPath))
{
// Try again with the version number appended to the folder name.
dataFolderPath += "_" + Version;
}
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);
SetId(assemblyId);
}
}
/// <summary>
/// Gets the application paths.
/// </summary>
/// <value>The application paths.</value>
protected IApplicationPaths ApplicationPaths { get; private set; }
/// <summary>
/// Gets the XML serializer.
/// </summary>
/// <value>The XML serializer.</value>
protected IXmlSerializer XmlSerializer { get; private set; }
/// <summary>
/// Gets the type of configuration this plugin uses.
/// </summary>
/// <value>The type of the configuration.</value>
public Type ConfigurationType => typeof(TConfigurationType);
/// <summary>
/// Gets or sets the event handler that is triggered when this configuration changes.
/// </summary>
public EventHandler<BasePluginConfiguration> ConfigurationChanged { get; set; }
/// <summary>
/// Gets the name the assembly file.
/// </summary>
/// <value>The name of the assembly file.</value>
protected string AssemblyFileName => Path.GetFileName(AssemblyFilePath);
/// <summary>
/// Gets or sets the plugin configuration.
/// </summary>
/// <value>The configuration.</value>
public TConfigurationType Configuration
{
get
{
// Lazy load
if (_configuration is null)
{
lock (_configurationSyncLock)
{
_configuration ??= LoadConfiguration();
}
}
return _configuration;
}
protected set => _configuration = value;
}
/// <summary>
/// Gets the name of the configuration file. Subclasses should override.
/// </summary>
/// <value>The name of the configuration file.</value>
public virtual string ConfigurationFileName => Path.ChangeExtension(AssemblyFileName, ".xml");
/// <summary>
/// Gets the full path to the configuration file.
/// </summary>
/// <value>The configuration file path.</value>
public string ConfigurationFilePath => Path.Combine(ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName);
/// <summary>
/// Gets the plugin configuration.
/// </summary>
/// <value>The configuration.</value>
BasePluginConfiguration IHasPluginConfiguration.Configuration => Configuration;
/// <summary>
/// Saves the current configuration to the file system.
/// </summary>
/// <param name="config">Configuration to save.</param>
public virtual void SaveConfiguration(TConfigurationType config)
{
lock (_configurationSaveLock)
{
var folder = Path.GetDirectoryName(ConfigurationFilePath);
Directory.CreateDirectory(folder);
XmlSerializer.SerializeToFile(config, ConfigurationFilePath);
}
}
/// <summary>
/// Saves the current configuration to the file system.
/// </summary>
public virtual void SaveConfiguration()
{
SaveConfiguration(Configuration);
}
/// <inheritdoc />
public virtual void UpdateConfiguration(BasePluginConfiguration configuration)
{
ArgumentNullException.ThrowIfNull(configuration);
Configuration = (TConfigurationType)configuration;
SaveConfiguration(Configuration);
ConfigurationChanged?.Invoke(this, configuration);
}
/// <inheritdoc />
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 = Activator.CreateInstance<TConfigurationType>();
SaveConfiguration(config);
return config;
}
}
}
}
@@ -0,0 +1,27 @@
using System;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Defines the <see cref="IHasPluginConfiguration" />.
/// </summary>
public interface IHasPluginConfiguration
{
/// <summary>
/// Gets the type of configuration this plugin uses.
/// </summary>
Type ConfigurationType { get; }
/// <summary>
/// Gets the plugin's configuration.
/// </summary>
BasePluginConfiguration Configuration { get; }
/// <summary>
/// Completely overwrites the current configuration with a new copy.
/// </summary>
/// <param name="configuration">The configuration.</param>
void UpdateConfiguration(BasePluginConfiguration configuration);
}
}
+59
View File
@@ -0,0 +1,59 @@
#nullable disable
using System;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Defines the <see cref="IPlugin" />.
/// </summary>
public interface IPlugin
{
/// <summary>
/// Gets the name of the plugin.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the Description.
/// </summary>
string Description { get; }
/// <summary>
/// Gets the unique id.
/// </summary>
Guid Id { get; }
/// <summary>
/// Gets the plugin version.
/// </summary>
Version Version { get; }
/// <summary>
/// Gets the path to the assembly file.
/// </summary>
string AssemblyFilePath { get; }
/// <summary>
/// Gets a value indicating whether the plugin can be uninstalled.
/// </summary>
bool CanUninstall { get; }
/// <summary>
/// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed.
/// </summary>
string DataFolderPath { get; }
/// <summary>
/// Gets the <see cref="PluginInfo"/>.
/// </summary>
/// <returns>PluginInfo.</returns>
PluginInfo GetPluginInfo();
/// <summary>
/// Called when just before the plugin is uninstalled from the server.
/// </summary>
void OnUninstalling();
}
}
@@ -0,0 +1,13 @@
#pragma warning disable CS1591
using System;
namespace MediaBrowser.Common.Plugins
{
public interface IPluginAssembly
{
void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion);
void SetId(Guid assemblyId);
}
}
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Updates;
using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Defines the <see cref="IPluginManager" />.
/// </summary>
public interface IPluginManager
{
/// <summary>
/// Gets the Plugins.
/// </summary>
IReadOnlyList<LocalPlugin> Plugins { get; }
/// <summary>
/// Creates the plugins.
/// </summary>
void CreatePlugins();
/// <summary>
/// Returns all the assemblies.
/// </summary>
/// <returns>An IEnumerable{Assembly}.</returns>
IEnumerable<Assembly> LoadAssemblies();
/// <summary>
/// Registers the plugin's services with the DI.
/// Note: DI is not yet instantiated yet.
/// </summary>
/// <param name="serviceCollection">A <see cref="ServiceCollection"/> instance.</param>
void RegisterServices(IServiceCollection serviceCollection);
/// <summary>
/// Saves the manifest back to disk.
/// </summary>
/// <param name="manifest">The <see cref="PluginManifest"/> to save.</param>
/// <param name="path">The path where to save the manifest.</param>
/// <returns>True if successful.</returns>
bool SaveManifest(PluginManifest manifest, string path);
/// <summary>
/// Generates a manifest from repository data.
/// </summary>
/// <param name="packageInfo">The <see cref="PackageInfo"/> used to generate a manifest.</param>
/// <param name="version">Version to be installed.</param>
/// <param name="path">The path where to save the manifest.</param>
/// <param name="status">Initial status of the plugin.</param>
/// <returns>True if successful.</returns>
Task<bool> PopulateManifest(PackageInfo packageInfo, Version version, string path, PluginStatus status);
/// <summary>
/// Imports plugin details from a folder.
/// </summary>
/// <param name="folder">Folder of the plugin.</param>
void ImportPluginFrom(string folder);
/// <summary>
/// Disable the plugin.
/// </summary>
/// <param name="assembly">The <see cref="Assembly"/> of the plug to disable.</param>
void FailPlugin(Assembly assembly);
/// <summary>
/// Disable the plugin.
/// </summary>
/// <param name="plugin">The <see cref="LocalPlugin"/> of the plug to disable.</param>
void DisablePlugin(LocalPlugin plugin);
/// <summary>
/// Enables the plugin, disabling all other versions.
/// </summary>
/// <param name="plugin">The <see cref="LocalPlugin"/> of the plug to disable.</param>
void EnablePlugin(LocalPlugin plugin);
/// <summary>
/// Attempts to find the plugin with and id of <paramref name="id"/>.
/// </summary>
/// <param name="id">Id of plugin.</param>
/// <param name="version">The version of the plugin to locate.</param>
/// <returns>A <see cref="LocalPlugin"/> if located, or null if not.</returns>
LocalPlugin? GetPlugin(Guid id, Version? version = null);
/// <summary>
/// Removes the plugin.
/// </summary>
/// <param name="plugin">The plugin.</param>
/// <returns>Outcome of the operation.</returns>
bool RemovePlugin(LocalPlugin plugin);
}
}
+139
View File
@@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Local plugin class.
/// </summary>
public class LocalPlugin : IEquatable<LocalPlugin>
{
private readonly bool _supported;
private Version? _version;
/// <summary>
/// Initializes a new instance of the <see cref="LocalPlugin"/> class.
/// </summary>
/// <param name="path">The plugin path.</param>
/// <param name="isSupported"><b>True</b> if Jellyfin supports this version of the plugin.</param>
/// <param name="manifest">The manifest record for this plugin, or null if one does not exist.</param>
public LocalPlugin(string path, bool isSupported, PluginManifest manifest)
{
Path = path;
DllFiles = Array.Empty<string>();
_supported = isSupported;
Manifest = manifest;
}
/// <summary>
/// Gets the plugin id.
/// </summary>
public Guid Id => Manifest.Id;
/// <summary>
/// Gets the plugin name.
/// </summary>
public string Name => Manifest.Name;
/// <summary>
/// Gets the plugin version.
/// </summary>
public Version Version
{
get
{
if (_version is null)
{
_version = Version.Parse(Manifest.Version);
}
return _version;
}
}
/// <summary>
/// Gets the plugin path.
/// </summary>
public string Path { get; }
/// <summary>
/// Gets or sets the list of dll files for this plugin.
/// </summary>
public IReadOnlyList<string> DllFiles { get; set; }
/// <summary>
/// Gets or sets the instance of this plugin.
/// </summary>
public IPlugin? Instance { get; set; }
/// <summary>
/// Gets a value indicating whether Jellyfin supports this version of the plugin, and it's enabled.
/// </summary>
public bool IsEnabledAndSupported => _supported && Manifest.Status >= PluginStatus.Active;
/// <summary>
/// Gets a value indicating whether the plugin has a manifest.
/// </summary>
public PluginManifest Manifest { get; }
/// <summary>
/// Compare two <see cref="LocalPlugin"/>.
/// </summary>
/// <param name="a">The first item.</param>
/// <param name="b">The second item.</param>
/// <returns>Comparison result.</returns>
public static int Compare(LocalPlugin a, LocalPlugin b)
{
if (a is null || b is null)
{
throw new ArgumentNullException(a is null ? nameof(a) : nameof(b));
}
var compare = string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);
// Id is not equal but name is.
if (!a.Id.Equals(b.Id) && compare == 0)
{
compare = a.Id.CompareTo(b.Id);
}
return compare == 0 ? a.Version.CompareTo(b.Version) : compare;
}
/// <summary>
/// Returns the plugin information.
/// </summary>
/// <returns>A <see cref="PluginInfo"/> instance containing the information.</returns>
public PluginInfo GetPluginInfo()
{
var inst = Instance?.GetPluginInfo() ?? new PluginInfo(Manifest.Name, Version, Manifest.Description, Manifest.Id, true);
inst.Status = Manifest.Status;
inst.HasImage = !string.IsNullOrEmpty(Manifest.ImagePath);
return inst;
}
/// <inheritdoc />
public override bool Equals(object? obj)
{
return obj is LocalPlugin other && this.Equals(other);
}
/// <inheritdoc />
public override int GetHashCode()
{
return Name.GetHashCode(StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc />
public bool Equals(LocalPlugin? other)
{
if (other is null)
{
return false;
}
return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) && Id.Equals(other.Id) && Version.Equals(other.Version);
}
}
}
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Defines a Plugin manifest file.
/// </summary>
public class PluginManifest
{
/// <summary>
/// Initializes a new instance of the <see cref="PluginManifest"/> class.
/// </summary>
public PluginManifest()
{
Category = string.Empty;
Changelog = string.Empty;
Description = string.Empty;
Id = Guid.Empty;
Name = string.Empty;
Owner = string.Empty;
Overview = string.Empty;
TargetAbi = string.Empty;
Version = string.Empty;
Assemblies = Array.Empty<string>();
}
/// <summary>
/// Gets or sets the category of the plugin.
/// </summary>
[JsonPropertyName("category")]
public string Category { get; set; }
/// <summary>
/// Gets or sets the changelog information.
/// </summary>
[JsonPropertyName("changelog")]
public string Changelog { get; set; }
/// <summary>
/// Gets or sets the description of the plugin.
/// </summary>
[JsonPropertyName("description")]
public string Description { get; set; }
/// <summary>
/// Gets or sets the Global Unique Identifier for the plugin.
/// </summary>
[JsonPropertyName("guid")]
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the Name of the plugin.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets an overview of the plugin.
/// </summary>
[JsonPropertyName("overview")]
public string Overview { get; set; }
/// <summary>
/// Gets or sets the owner of the plugin.
/// </summary>
[JsonPropertyName("owner")]
public string Owner { get; set; }
/// <summary>
/// Gets or sets the compatibility version for the plugin.
/// </summary>
[JsonPropertyName("targetAbi")]
public string TargetAbi { get; set; }
/// <summary>
/// Gets or sets the timestamp of the plugin.
/// </summary>
[JsonPropertyName("timestamp")]
public DateTime Timestamp { get; set; }
/// <summary>
/// Gets or sets the Version number of the plugin.
/// </summary>
[JsonPropertyName("version")]
public string Version { get; set; }
/// <summary>
/// Gets or sets a value indicating the operational status of this plugin.
/// </summary>
[JsonPropertyName("status")]
public PluginStatus Status { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this plugin should automatically update.
/// </summary>
[JsonPropertyName("autoUpdate")]
public bool AutoUpdate { get; set; } = true; // DO NOT MOVE THIS INTO THE CONSTRUCTOR.
/// <summary>
/// Gets or sets the ImagePath
/// Gets or sets a value indicating whether this plugin has an image.
/// Image must be located in the local plugin folder.
/// </summary>
[JsonPropertyName("imagePath")]
public string? ImagePath { get; set; }
/// <summary>
/// Gets or sets the collection of assemblies that should be loaded.
/// Paths are considered relative to the plugin folder.
/// </summary>
[JsonPropertyName("assemblies")]
public IReadOnlyList<string> Assemblies { get; set; }
}
}