diff options
| author | crobibero <cody@robibe.ro> | 2020-09-30 17:37:30 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-09-30 17:37:30 -0600 |
| commit | 53d8023defe19ef943f72964d93dbed40b6f1180 (patch) | |
| tree | 37b5398d2eb6db4a29bd946ac38ba148364b413d /MediaBrowser.Common/Plugins/LocalPlugin.cs | |
| parent | c7b3d4a90c946f9a2438622cc0ca43d19b84bef8 (diff) | |
Update all on-disk plugins
Diffstat (limited to 'MediaBrowser.Common/Plugins/LocalPlugin.cs')
| -rw-r--r-- | MediaBrowser.Common/Plugins/LocalPlugin.cs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Plugins/LocalPlugin.cs b/MediaBrowser.Common/Plugins/LocalPlugin.cs new file mode 100644 index 000000000..e26631615 --- /dev/null +++ b/MediaBrowser.Common/Plugins/LocalPlugin.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Globalization; + +namespace MediaBrowser.Common.Plugins +{ + /// <summary> + /// Local plugin struct. + /// </summary> + public readonly struct LocalPlugin : IEquatable<LocalPlugin> + { + /// <summary> + /// Initializes a new instance of the <see cref="LocalPlugin"/> struct. + /// </summary> + /// <param name="id">The plugin id.</param> + /// <param name="name">The plugin name.</param> + /// <param name="version">The plugin version.</param> + /// <param name="path">The plugin path.</param> + public LocalPlugin(Guid id, string name, Version version, string path) + { + Id = id; + Name = name; + Version = version; + Path = path; + DllFiles = new List<string>(); + } + + /// <summary> + /// Gets the plugin id. + /// </summary> + public Guid Id { get; } + + /// <summary> + /// Gets the plugin name. + /// </summary> + public string Name { get; } + + /// <summary> + /// Gets the plugin version. + /// </summary> + public Version Version { get; } + + /// <summary> + /// Gets the plugin path. + /// </summary> + public string Path { get; } + + /// <summary> + /// Gets the list of dll files for this plugin. + /// </summary> + public List<string> DllFiles { get; } + + /// <summary> + /// == operator. + /// </summary> + /// <param name="left">Left item.</param> + /// <param name="right">Right item.</param> + /// <returns>Comparison result.</returns> + public static bool operator ==(LocalPlugin left, LocalPlugin right) + { + return left.Equals(right); + } + + /// <summary> + /// != operator. + /// </summary> + /// <param name="left">Left item.</param> + /// <param name="right">Right item.</param> + /// <returns>Comparison result.</returns> + public static bool operator !=(LocalPlugin left, LocalPlugin right) + { + return !(left == right); + } + + /// <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) + { + var compare = string.Compare(a.Name, b.Name, true, CultureInfo.InvariantCulture); + + // Id is not equal but name is. + if (a.Id != b.Id && compare == 0) + { + compare = a.Id.CompareTo(b.Id); + } + + return compare == 0 ? a.Version.CompareTo(b.Version) : compare; + } + + /// <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) + { + return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) + && Id.Equals(other.Id); + } + } +} |
