aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
authorDominik <git@secnd.me>2023-06-15 19:38:42 +0200
committerGitHub <noreply@github.com>2023-06-15 19:38:42 +0200
commit17f1e8d19b1fd693893d66d2275ed8ae2476344e (patch)
tree7f48be975faa92042769870957587b3c7864f631 /MediaBrowser.Common
parente8ae7e5c38e28f13fa8de295e26c930cb46d9b79 (diff)
parent6771b5cabe96b4b3cbd1cd0c998d564f3dd17ed4 (diff)
Merge branch 'master' into segment-deletion
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Events/EventHelper.cs4
-rw-r--r--MediaBrowser.Common/Extensions/HttpContextExtensions.cs4
-rw-r--r--MediaBrowser.Common/IApplicationHost.cs6
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj18
-rw-r--r--MediaBrowser.Common/Net/CustomHeaderNames.cs13
-rw-r--r--MediaBrowser.Common/Net/IPHost.cs6
-rw-r--r--MediaBrowser.Common/Net/IPNetAddress.cs7
-rw-r--r--MediaBrowser.Common/Net/IPObject.cs4
-rw-r--r--MediaBrowser.Common/Net/NamedClient.cs9
-rw-r--r--MediaBrowser.Common/Net/NetworkExtensions.cs4
-rw-r--r--MediaBrowser.Common/Plugins/BasePluginOfT.cs6
-rw-r--r--MediaBrowser.Common/Plugins/IPluginManager.cs7
-rw-r--r--MediaBrowser.Common/Plugins/LocalPlugin.cs8
-rw-r--r--MediaBrowser.Common/Plugins/PluginManifest.cs9
-rw-r--r--MediaBrowser.Common/Providers/ProviderIdParsers.cs4
-rw-r--r--MediaBrowser.Common/System/OperatingSystem.cs74
16 files changed, 57 insertions, 126 deletions
diff --git a/MediaBrowser.Common/Events/EventHelper.cs b/MediaBrowser.Common/Events/EventHelper.cs
index a9cf86fbc3..0e495f4fa3 100644
--- a/MediaBrowser.Common/Events/EventHelper.cs
+++ b/MediaBrowser.Common/Events/EventHelper.cs
@@ -19,7 +19,7 @@ namespace MediaBrowser.Common.Events
/// <param name="logger">The logger.</param>
public static void QueueEventIfNotNull(EventHandler? handler, object sender, EventArgs args, ILogger logger)
{
- if (handler != null)
+ if (handler is not null)
{
Task.Run(() =>
{
@@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Events
/// <param name="logger">The logger.</param>
public static void QueueEventIfNotNull<T>(EventHandler<T>? handler, object sender, T args, ILogger logger)
{
- if (handler != null)
+ if (handler is not null)
{
Task.Run(() =>
{
diff --git a/MediaBrowser.Common/Extensions/HttpContextExtensions.cs b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs
index 1e5877c84c..6608704c0a 100644
--- a/MediaBrowser.Common/Extensions/HttpContextExtensions.cs
+++ b/MediaBrowser.Common/Extensions/HttpContextExtensions.cs
@@ -15,8 +15,8 @@ namespace MediaBrowser.Common.Extensions
/// <returns><c>true</c> if the request is coming from LAN, <c>false</c> otherwise.</returns>
public static bool IsLocal(this HttpContext context)
{
- return (context.Connection.LocalIpAddress == null
- && context.Connection.RemoteIpAddress == null)
+ return (context.Connection.LocalIpAddress is null
+ && context.Connection.RemoteIpAddress is null)
|| Equals(context.Connection.LocalIpAddress, context.Connection.RemoteIpAddress);
}
diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs
index 53683cdbdf..96ee701b38 100644
--- a/MediaBrowser.Common/IApplicationHost.cs
+++ b/MediaBrowser.Common/IApplicationHost.cs
@@ -48,12 +48,6 @@ namespace MediaBrowser.Common
bool IsShuttingDown { get; }
/// <summary>
- /// Gets a value indicating whether this instance can self restart.
- /// </summary>
- /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
- bool CanSelfRestart { get; }
-
- /// <summary>
/// Gets the application version.
/// </summary>
/// <value>The application version.</value>
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index 7a55f398a1..3f1a098e45 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -19,9 +19,9 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
- <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
- <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
+ <PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
@@ -29,7 +29,7 @@
</ItemGroup>
<PropertyGroup>
- <TargetFramework>net6.0</TargetFramework>
+ <TargetFramework>net7.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
@@ -39,7 +39,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
- <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
+ <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Stability)'=='Unstable'">
@@ -49,13 +49,13 @@
<!-- Code analyzers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
- <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.3">
+ <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
- <PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
- <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
- <PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
+ <PackageReference Include="SerilogAnalyzer" PrivateAssets="All" />
+ <PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
+ <PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.Common/Net/CustomHeaderNames.cs b/MediaBrowser.Common/Net/CustomHeaderNames.cs
deleted file mode 100644
index 5ca9897eb4..0000000000
--- a/MediaBrowser.Common/Net/CustomHeaderNames.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma warning disable CS1591
-
-namespace MediaBrowser.Common.Net
-{
- public static class CustomHeaderNames
- {
- // Other Headers
- public const string XForwardedFor = "X-Forwarded-For";
- public const string XForwardedPort = "X-Forwarded-Port";
- public const string XForwardedProto = "X-Forwarded-Proto";
- public const string XRealIP = "X-Real-IP";
- }
-}
diff --git a/MediaBrowser.Common/Net/IPHost.cs b/MediaBrowser.Common/Net/IPHost.cs
index 1f125f2b1d..ec76a43b6f 100644
--- a/MediaBrowser.Common/Net/IPHost.cs
+++ b/MediaBrowser.Common/Net/IPHost.cs
@@ -190,7 +190,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Object representing the string, if it has successfully been parsed.</returns>
public static IPHost Parse(string host)
{
- if (!string.IsNullOrEmpty(host) && IPHost.TryParse(host, out IPHost res))
+ if (IPHost.TryParse(host, out IPHost res))
{
return res;
}
@@ -206,7 +206,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Object representing the string, if it has successfully been parsed.</returns>
public static IPHost Parse(string host, AddressFamily family)
{
- if (!string.IsNullOrEmpty(host) && IPHost.TryParse(host, out IPHost res))
+ if (IPHost.TryParse(host, out IPHost res))
{
if (family == AddressFamily.InterNetwork)
{
@@ -236,7 +236,7 @@ namespace MediaBrowser.Common.Net
/// <inheritdoc/>
public override bool Contains(IPAddress address)
{
- if (address != null && !Address.Equals(IPAddress.None))
+ if (address is not null && !Address.Equals(IPAddress.None))
{
if (address.IsIPv4MappedToIPv6)
{
diff --git a/MediaBrowser.Common/Net/IPNetAddress.cs b/MediaBrowser.Common/Net/IPNetAddress.cs
index 98d1c2d97b..de72d978ec 100644
--- a/MediaBrowser.Common/Net/IPNetAddress.cs
+++ b/MediaBrowser.Common/Net/IPNetAddress.cs
@@ -167,6 +167,11 @@ namespace MediaBrowser.Common.Net
address = address.MapToIPv4();
}
+ if (address.AddressFamily != AddressFamily)
+ {
+ return false;
+ }
+
var (altAddress, altPrefix) = NetworkAddressOf(address, PrefixLength);
return NetworkAddress.Address.Equals(altAddress) && NetworkAddress.PrefixLength >= altPrefix;
}
@@ -214,7 +219,7 @@ namespace MediaBrowser.Common.Net
/// <inheritdoc/>
public override bool Equals(IPAddress ip)
{
- if (ip != null && !ip.Equals(IPAddress.None) && !Address.Equals(IPAddress.None))
+ if (ip is not null && !ip.Equals(IPAddress.None) && !Address.Equals(IPAddress.None))
{
return ip.Equals(Address);
}
diff --git a/MediaBrowser.Common/Net/IPObject.cs b/MediaBrowser.Common/Net/IPObject.cs
index 37385972f7..93655234b0 100644
--- a/MediaBrowser.Common/Net/IPObject.cs
+++ b/MediaBrowser.Common/Net/IPObject.cs
@@ -292,7 +292,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Equality result.</returns>
public virtual bool Equals(IPAddress ip)
{
- if (ip != null)
+ if (ip is not null)
{
if (ip.IsIPv4MappedToIPv6)
{
@@ -312,7 +312,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Equality result.</returns>
public virtual bool Equals(IPObject? other)
{
- if (other != null)
+ if (other is not null)
{
return !Address.Equals(IPAddress.None) && Address.Equals(other.Address);
}
diff --git a/MediaBrowser.Common/Net/NamedClient.cs b/MediaBrowser.Common/Net/NamedClient.cs
index a6cacd4f17..9c5544b0ff 100644
--- a/MediaBrowser.Common/Net/NamedClient.cs
+++ b/MediaBrowser.Common/Net/NamedClient.cs
@@ -1,4 +1,4 @@
-namespace MediaBrowser.Common.Net
+namespace MediaBrowser.Common.Net
{
/// <summary>
/// Registered http client names.
@@ -6,7 +6,7 @@
public static class NamedClient
{
/// <summary>
- /// Gets the value for the default named http client.
+ /// Gets the value for the default named http client which implements happy eyeballs.
/// </summary>
public const string Default = nameof(Default);
@@ -19,5 +19,10 @@
/// Gets the value for the DLNA named http client.
/// </summary>
public const string Dlna = nameof(Dlna);
+
+ /// <summary>
+ /// Non happy eyeballs implementation.
+ /// </summary>
+ public const string DirectIp = nameof(DirectIp);
}
}
diff --git a/MediaBrowser.Common/Net/NetworkExtensions.cs b/MediaBrowser.Common/Net/NetworkExtensions.cs
index 7ad0058540..5e5e5b81b7 100644
--- a/MediaBrowser.Common/Net/NetworkExtensions.cs
+++ b/MediaBrowser.Common/Net/NetworkExtensions.cs
@@ -114,7 +114,7 @@ namespace MediaBrowser.Common.Net
/// <returns>True if both are equal.</returns>
public static bool Compare(this Collection<IPObject> source, Collection<IPObject> dest)
{
- if (dest == null || source.Count != dest.Count)
+ if (dest is null || source.Count != dest.Count)
{
return false;
}
@@ -187,7 +187,7 @@ namespace MediaBrowser.Common.Net
/// <returns>A new collection, with the items excluded.</returns>
public static Collection<IPObject> Exclude(this Collection<IPObject> source, Collection<IPObject> excludeList, bool isNetwork)
{
- if (source.Count == 0 || excludeList == null)
+ if (source.Count == 0 || excludeList is null)
{
return new Collection<IPObject>(source);
}
diff --git a/MediaBrowser.Common/Plugins/BasePluginOfT.cs b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
index 0da5592d38..116e9cef80 100644
--- a/MediaBrowser.Common/Plugins/BasePluginOfT.cs
+++ b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
@@ -47,10 +47,10 @@ namespace MediaBrowser.Common.Plugins
var assemblyFilePath = assembly.Location;
var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath));
- if (Version != null && !Directory.Exists(dataFolderPath))
+ if (Version is not null && !Directory.Exists(dataFolderPath))
{
// Try again with the version number appended to the folder name.
- dataFolderPath += "_" + Version.ToString();
+ dataFolderPath += "_" + Version;
}
SetAttributes(assemblyFilePath, dataFolderPath, assemblyName.Version);
@@ -103,7 +103,7 @@ namespace MediaBrowser.Common.Plugins
get
{
// Lazy load
- if (_configuration == null)
+ if (_configuration is null)
{
lock (_configurationSyncLock)
{
diff --git a/MediaBrowser.Common/Plugins/IPluginManager.cs b/MediaBrowser.Common/Plugins/IPluginManager.cs
index 176bcbbd54..1d73de3c95 100644
--- a/MediaBrowser.Common/Plugins/IPluginManager.cs
+++ b/MediaBrowser.Common/Plugins/IPluginManager.cs
@@ -30,6 +30,11 @@ namespace MediaBrowser.Common.Plugins
IEnumerable<Assembly> LoadAssemblies();
/// <summary>
+ /// Unloads all of the assemblies.
+ /// </summary>
+ void UnloadAssemblies();
+
+ /// <summary>
/// Registers the plugin's services with the DI.
/// Note: DI is not yet instantiated yet.
/// </summary>
@@ -52,7 +57,7 @@ namespace MediaBrowser.Common.Plugins
/// <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> GenerateManifest(PackageInfo packageInfo, Version version, string path, PluginStatus status);
+ Task<bool> PopulateManifest(PackageInfo packageInfo, Version version, string path, PluginStatus status);
/// <summary>
/// Imports plugin details from a folder.
diff --git a/MediaBrowser.Common/Plugins/LocalPlugin.cs b/MediaBrowser.Common/Plugins/LocalPlugin.cs
index 4c8e2d5044..96af423cc3 100644
--- a/MediaBrowser.Common/Plugins/LocalPlugin.cs
+++ b/MediaBrowser.Common/Plugins/LocalPlugin.cs
@@ -43,7 +43,7 @@ namespace MediaBrowser.Common.Plugins
{
get
{
- if (_version == null)
+ if (_version is null)
{
_version = Version.Parse(Manifest.Version);
}
@@ -85,9 +85,9 @@ namespace MediaBrowser.Common.Plugins
/// <returns>Comparison result.</returns>
public static int Compare(LocalPlugin a, LocalPlugin b)
{
- if (a == null || b == null)
+ if (a is null || b is null)
{
- throw new ArgumentNullException(a == null ? nameof(a) : nameof(b));
+ throw new ArgumentNullException(a is null ? nameof(a) : nameof(b));
}
var compare = string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);
@@ -128,7 +128,7 @@ namespace MediaBrowser.Common.Plugins
/// <inheritdoc />
public bool Equals(LocalPlugin? other)
{
- if (other == null)
+ if (other is null)
{
return false;
}
diff --git a/MediaBrowser.Common/Plugins/PluginManifest.cs b/MediaBrowser.Common/Plugins/PluginManifest.cs
index 2910dbe144..e0847ccea4 100644
--- a/MediaBrowser.Common/Plugins/PluginManifest.cs
+++ b/MediaBrowser.Common/Plugins/PluginManifest.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Text.Json.Serialization;
using MediaBrowser.Model.Plugins;
@@ -23,6 +24,7 @@ namespace MediaBrowser.Common.Plugins
Overview = string.Empty;
TargetAbi = string.Empty;
Version = string.Empty;
+ Assemblies = Array.Empty<string>();
}
/// <summary>
@@ -104,5 +106,12 @@ namespace MediaBrowser.Common.Plugins
/// </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; }
}
}
diff --git a/MediaBrowser.Common/Providers/ProviderIdParsers.cs b/MediaBrowser.Common/Providers/ProviderIdParsers.cs
index 487b5a6d29..d569167b1d 100644
--- a/MediaBrowser.Common/Providers/ProviderIdParsers.cs
+++ b/MediaBrowser.Common/Providers/ProviderIdParsers.cs
@@ -20,7 +20,7 @@ namespace MediaBrowser.Common.Providers
/// <returns>True if parsing was successful, false otherwise.</returns>
public static bool TryFindImdbId(ReadOnlySpan<char> text, out ReadOnlySpan<char> imdbId)
{
- // imdb id is at least 9 chars (tt + 7 numbers)
+ // IMDb id is at least 9 chars (tt + 7 numbers)
while (text.Length >= 2 + ImdbMinNumbers)
{
var ttPos = text.IndexOf(ImdbPrefix);
@@ -42,7 +42,7 @@ namespace MediaBrowser.Common.Providers
}
}
- // skip if more than 8 digits + 2 chars for tt
+ // Skip if more than 8 digits + 2 chars for tt
if (i <= ImdbMaxNumbers + 2 && i >= ImdbMinNumbers + 2)
{
imdbId = text.Slice(0, i);
diff --git a/MediaBrowser.Common/System/OperatingSystem.cs b/MediaBrowser.Common/System/OperatingSystem.cs
deleted file mode 100644
index 5f673d3208..0000000000
--- a/MediaBrowser.Common/System/OperatingSystem.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-#pragma warning disable CS1591
-
-using System;
-using System.Runtime.InteropServices;
-using System.Threading;
-using MediaBrowser.Model.System;
-
-namespace MediaBrowser.Common.System
-{
- public static class OperatingSystem
- {
- // We can't use Interlocked.CompareExchange for enums
- private static int _id = int.MaxValue;
-
- public static OperatingSystemId Id
- {
- get
- {
- if (_id == int.MaxValue)
- {
- Interlocked.CompareExchange(ref _id, (int)GetId(), int.MaxValue);
- }
-
- return (OperatingSystemId)_id;
- }
- }
-
- public static string Name
- {
- get
- {
- switch (Id)
- {
- case OperatingSystemId.BSD: return "BSD";
- case OperatingSystemId.Linux: return "Linux";
- case OperatingSystemId.Darwin: return "macOS";
- case OperatingSystemId.Windows: return "Windows";
- default: throw new PlatformNotSupportedException($"Unknown OS {Id}");
- }
- }
- }
-
- private static OperatingSystemId GetId()
- {
- switch (Environment.OSVersion.Platform)
- {
- // On .NET Core `MacOSX` got replaced by `Unix`, this case should never be hit.
- case PlatformID.MacOSX:
- return OperatingSystemId.Darwin;
- case PlatformID.Win32NT:
- return OperatingSystemId.Windows;
- case PlatformID.Unix:
- default:
- {
- string osDescription = RuntimeInformation.OSDescription;
- if (osDescription.Contains("linux", StringComparison.OrdinalIgnoreCase))
- {
- return OperatingSystemId.Linux;
- }
- else if (osDescription.Contains("darwin", StringComparison.OrdinalIgnoreCase))
- {
- return OperatingSystemId.Darwin;
- }
- else if (osDescription.Contains("bsd", StringComparison.OrdinalIgnoreCase))
- {
- return OperatingSystemId.BSD;
- }
-
- throw new PlatformNotSupportedException($"Can't resolve OS with description: '{osDescription}'");
- }
- }
- }
- }
-}