Enable nullable reference types for Emby.Server.Implementations

This commit is contained in:
Bond_009 2021-05-20 21:28:18 +02:00
parent e8790bfa96
commit 7e8428e588
151 changed files with 300 additions and 99 deletions

View File

@ -33,7 +33,7 @@ namespace Emby.Server.Implementations.AppBase
CachePath = cacheDirectoryPath;
WebPath = webDirectoryPath;
DataPath = Path.Combine(ProgramDataPath, "data");
_dataPath = Directory.CreateDirectory(Path.Combine(ProgramDataPath, "data")).FullName;
}
/// <summary>
@ -55,11 +55,7 @@ namespace Emby.Server.Implementations.AppBase
/// Gets the folder path to the data directory.
/// </summary>
/// <value>The data directory.</value>
public string DataPath
{
get => _dataPath;
private set => _dataPath = Directory.CreateDirectory(value).FullName;
}
public string DataPath => _dataPath;
/// <inheritdoc />
public string VirtualDataPath => "%AppDataPath%";

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.IO;
using System.Linq;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Globalization;

View File

@ -82,9 +82,9 @@ namespace Emby.Server.Implementations.Collections
return null;
})
.Where(i => i != null)
.GroupBy(x => x.Id)
.GroupBy(x => x!.Id) // We removed the null values
.Select(x => x.First())
.ToList();
.ToList()!; // Again... the list doesn't contain any null values
}
/// <inheritdoc />

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.IO;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Globalization;
using System.IO;

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Security.Cryptography;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -9,7 +9,7 @@ namespace Emby.Server.Implementations.Data
{
public class ManagedConnection : IDisposable
{
private SQLiteDatabaseConnection _db;
private SQLiteDatabaseConnection? _db;
private readonly SemaphoreSlim _writeLock;
private bool _disposed = false;

View File

@ -1,3 +1,4 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -13,7 +13,7 @@ namespace Emby.Server.Implementations.Data
/// This holds all the types in the running assemblies
/// so that we can de-serialize properly when we don't have strong types.
/// </summary>
private readonly ConcurrentDictionary<string, Type> _typeMap = new ConcurrentDictionary<string, Type>();
private readonly ConcurrentDictionary<string, Type?> _typeMap = new ConcurrentDictionary<string, Type?>();
/// <summary>
/// Gets the type.
@ -21,7 +21,7 @@ namespace Emby.Server.Implementations.Data
/// <param name="typeName">Name of the type.</param>
/// <returns>Type.</returns>
/// <exception cref="ArgumentNullException"><c>typeName</c> is null.</exception>
public Type GetType(string typeName)
public Type? GetType(string typeName)
{
if (string.IsNullOrEmpty(typeName))
{
@ -36,7 +36,7 @@ namespace Emby.Server.Implementations.Data
/// </summary>
/// <param name="typeName">Name of the type.</param>
/// <returns>Type.</returns>
private Type LookupType(string typeName)
private Type? LookupType(string typeName)
{
return AppDomain.CurrentDomain.GetAssemblies()
.Select(a => a.GetType(typeName))

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -44,6 +44,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors Condition=" '$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<!-- https://github.com/microsoft/ApplicationInsights-dotnet/issues/2047 -->
<NoWarn>AD0001</NoWarn>
<AnalysisMode Condition=" '$(Configuration)' == 'Debug' ">AllEnabledByDefault</AnalysisMode>

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.Net.Sockets;
using System.Threading;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -27,7 +27,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
{
if (requestContext.Request.HttpContext.Items.TryGetValue("AuthorizationInfo", out var cached))
{
return (AuthorizationInfo)cached;
return (AuthorizationInfo)cached!; // Cache should never contain null
}
return GetAuthorization(requestContext);
@ -55,15 +55,15 @@ namespace Emby.Server.Implementations.HttpServer.Security
}
private AuthorizationInfo GetAuthorizationInfoFromDictionary(
in Dictionary<string, string> auth,
in Dictionary<string, string>? auth,
in IHeaderDictionary headers,
in IQueryCollection queryString)
{
string deviceId = null;
string device = null;
string client = null;
string version = null;
string token = null;
string? deviceId = null;
string? device = null;
string? client = null;
string? version = null;
string? token = null;
if (auth != null)
{
@ -206,7 +206,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
/// </summary>
/// <param name="httpReq">The HTTP req.</param>
/// <returns>Dictionary{System.StringSystem.String}.</returns>
private Dictionary<string, string> GetAuthorizationDictionary(HttpContext httpReq)
private Dictionary<string, string>? GetAuthorizationDictionary(HttpContext httpReq)
{
var auth = httpReq.Request.Headers["X-Emby-Authorization"];
@ -223,7 +223,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
/// </summary>
/// <param name="httpReq">The HTTP req.</param>
/// <returns>Dictionary{System.StringSystem.String}.</returns>
private Dictionary<string, string> GetAuthorizationDictionary(HttpRequest httpReq)
private Dictionary<string, string>? GetAuthorizationDictionary(HttpRequest httpReq)
{
var auth = httpReq.Headers["X-Emby-Authorization"];
@ -240,7 +240,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
/// </summary>
/// <param name="authorizationHeader">The authorization header.</param>
/// <returns>Dictionary{System.StringSystem.String}.</returns>
private Dictionary<string, string> GetAuthorization(ReadOnlySpan<char> authorizationHeader)
private Dictionary<string, string>? GetAuthorization(ReadOnlySpan<char> authorizationHeader)
{
if (authorizationHeader == null)
{

View File

@ -36,14 +36,14 @@ namespace Emby.Server.Implementations.HttpServer.Security
return GetSession((HttpContext)requestContext);
}
public User GetUser(HttpContext requestContext)
public User? GetUser(HttpContext requestContext)
{
var session = GetSession(requestContext);
return session == null || session.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(session.UserId);
}
public User GetUser(object requestContext)
public User? GetUser(object requestContext)
{
return GetUser(((HttpRequest)requestContext).HttpContext);
}

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.Buffers;
using System.IO.Pipelines;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -61,7 +61,7 @@ namespace Emby.Server.Implementations.IO
/// <param name="filename">The filename.</param>
/// <returns>System.String.</returns>
/// <exception cref="ArgumentNullException">filename</exception>
public virtual string ResolveShortcut(string filename)
public virtual string? ResolveShortcut(string filename)
{
if (string.IsNullOrEmpty(filename))
{
@ -601,7 +601,7 @@ namespace Emby.Server.Implementations.IO
return GetFiles(path, null, false, recursive);
}
public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string> extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
{
var enumerationOptions = GetEnumerationOptions(recursive);
@ -655,7 +655,7 @@ namespace Emby.Server.Implementations.IO
return GetFilePaths(path, null, false, recursive);
}
public virtual IEnumerable<string> GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
public virtual IEnumerable<string> GetFilePaths(string path, string[]? extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
{
var enumerationOptions = GetEnumerationOptions(recursive);

View File

@ -17,7 +17,7 @@ namespace Emby.Server.Implementations.IO
public string Extension => ".mblink";
public string Resolve(string shortcutPath)
public string? Resolve(string shortcutPath)
{
if (string.IsNullOrEmpty(shortcutPath))
{

View File

@ -11,7 +11,7 @@ namespace Emby.Server.Implementations.IO
{
public class StreamHelper : IStreamHelper
{
public async Task CopyToAsync(Stream source, Stream destination, int bufferSize, Action onStarted, CancellationToken cancellationToken)
public async Task CopyToAsync(Stream source, Stream destination, int bufferSize, Action? onStarted, CancellationToken cancellationToken)
{
byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
try

View File

@ -1,5 +1,4 @@
#pragma warning disable CS1591
#nullable enable
namespace Emby.Server.Implementations
{

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System.Collections.Generic;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System.Collections.Generic;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System.Collections.Generic;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.Linq;
using DotNet.Globbing;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using MediaBrowser.Common.Providers;

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.IO;
using System.Linq;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Linq;
using System.Threading.Tasks;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;

View File

@ -1,3 +1,5 @@
#nullable disable
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.IO;
using MediaBrowser.Controller.Entities;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.IO;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Linq;
using MediaBrowser.Controller.Entities;

View File

@ -1,3 +1,5 @@
#nullable disable
using System.Globalization;
using Emby.Naming.TV;
using MediaBrowser.Controller.Entities.TV;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using MediaBrowser.Controller.Entities;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -6,7 +6,6 @@ using MediaBrowser.Controller.LiveTv;
namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
internal class EpgChannelData
{
@ -39,13 +38,13 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
public ChannelInfo GetChannelById(string id)
public ChannelInfo? GetChannelById(string id)
=> _channelsById.GetValueOrDefault(id);
public ChannelInfo GetChannelByNumber(string number)
public ChannelInfo? GetChannelByNumber(string number)
=> _channelsByNumber.GetValueOrDefault(number);
public ChannelInfo GetChannelByName(string name)
public ChannelInfo? GetChannelByName(string name)
=> _channelsByName.GetValueOrDefault(name);
public static string NormalizeName(string value)

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
{
internal class Channels

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Globalization;

View File

@ -1,3 +1,5 @@
#nullable disable
using System;
using System.Collections.Concurrent;
using System.Globalization;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

View File

@ -1,3 +1,5 @@
#nullable disable
#pragma warning disable CS1591
using System;

Some files were not shown because too many files have changed in this diff Show More