From 651681c27630af0fd0852980ac473ce570805dc3 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 13 Mar 2024 14:56:51 +0100 Subject: [PATCH] Enable nullable for more files --- .../ApplicationHost.cs | 2 +- .../Devices/DeviceId.cs | 14 +++---- .../Library/LiveStreamHelper.cs | 10 ++--- .../Library/MusicManager.cs | 39 ++++++++----------- .../Library/SearchEngine.cs | 10 ++--- .../Channels/IHasCacheKey.cs | 4 +- .../Channels/ISearchableChannel.cs | 21 ---------- .../Channels/ISupportsLatestMedia.cs | 4 +- .../Library/IMusicManager.cs | 8 ++-- MediaBrowser.Model/Search/SearchQuery.cs | 3 +- MediaBrowser.Model/System/LogFile.cs | 3 +- .../Channels/ChannelManager.cs | 1 - 12 files changed, 39 insertions(+), 80 deletions(-) delete mode 100644 MediaBrowser.Controller/Channels/ISearchableChannel.cs diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 745753440d..acabbb059b 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -146,7 +146,7 @@ namespace Emby.Server.Implementations _startupConfig = startupConfig; Logger = LoggerFactory.CreateLogger(); - _deviceId = new DeviceId(ApplicationPaths, LoggerFactory); + _deviceId = new DeviceId(ApplicationPaths, LoggerFactory.CreateLogger()); ApplicationVersion = typeof(ApplicationHost).Assembly.GetName().Version; ApplicationVersionString = ApplicationVersion.ToString(3); diff --git a/Emby.Server.Implementations/Devices/DeviceId.cs b/Emby.Server.Implementations/Devices/DeviceId.cs index b3f5549bcd..2459178d81 100644 --- a/Emby.Server.Implementations/Devices/DeviceId.cs +++ b/Emby.Server.Implementations/Devices/DeviceId.cs @@ -1,5 +1,3 @@ -#nullable disable - #pragma warning disable CS1591 using System; @@ -17,19 +15,19 @@ namespace Emby.Server.Implementations.Devices private readonly ILogger _logger; private readonly object _syncLock = new object(); - private string _id; + private string? _id; - public DeviceId(IApplicationPaths appPaths, ILoggerFactory loggerFactory) + public DeviceId(IApplicationPaths appPaths, ILogger logger) { _appPaths = appPaths; - _logger = loggerFactory.CreateLogger(); + _logger = logger; } - public string Value => _id ?? (_id = GetDeviceId()); + public string Value => _id ??= GetDeviceId(); private string CachePath => Path.Combine(_appPaths.DataPath, "device.txt"); - private string GetCachedId() + private string? GetCachedId() { try { @@ -65,7 +63,7 @@ namespace Emby.Server.Implementations.Devices { var path = CachePath; - Directory.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path) ?? throw new InvalidOperationException("Path can't be a root directory.")); lock (_syncLock) { diff --git a/Emby.Server.Implementations/Library/LiveStreamHelper.cs b/Emby.Server.Implementations/Library/LiveStreamHelper.cs index d4aeae41a5..0ebfe3ae71 100644 --- a/Emby.Server.Implementations/Library/LiveStreamHelper.cs +++ b/Emby.Server.Implementations/Library/LiveStreamHelper.cs @@ -1,5 +1,3 @@ -#nullable disable - #pragma warning disable CS1591 using System; @@ -37,16 +35,16 @@ namespace Emby.Server.Implementations.Library _appPaths = appPaths; } - public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProbeDelay, CancellationToken cancellationToken) + public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string? cacheKey, bool addProbeDelay, CancellationToken cancellationToken) { var originalRuntime = mediaSource.RunTimeTicks; var now = DateTime.UtcNow; - MediaInfo mediaInfo = null; + MediaInfo? mediaInfo = null; var cacheFilePath = string.IsNullOrEmpty(cacheKey) ? null : Path.Combine(_appPaths.CachePath, "mediainfo", cacheKey.GetMD5().ToString("N", CultureInfo.InvariantCulture) + ".json"); - if (!string.IsNullOrEmpty(cacheKey)) + if (cacheFilePath is not null) { try { @@ -91,7 +89,7 @@ namespace Emby.Server.Implementations.Library if (cacheFilePath is not null) { - Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath)); + Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath) ?? throw new InvalidOperationException("Path can't be a root directory.")); FileStream createStream = AsyncFile.OpenWrite(cacheFilePath); await using (createStream.ConfigureAwait(false)) { diff --git a/Emby.Server.Implementations/Library/MusicManager.cs b/Emby.Server.Implementations/Library/MusicManager.cs index 078f4ad219..a69a0f33f3 100644 --- a/Emby.Server.Implementations/Library/MusicManager.cs +++ b/Emby.Server.Implementations/Library/MusicManager.cs @@ -1,5 +1,3 @@ -#nullable disable - #pragma warning disable CS1591 using System; @@ -13,7 +11,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Playlists; -using MediaBrowser.Model.Querying; using MusicAlbum = MediaBrowser.Controller.Entities.Audio.MusicAlbum; namespace Emby.Server.Implementations.Library @@ -27,33 +24,35 @@ namespace Emby.Server.Implementations.Library _libraryManager = libraryManager; } - public List GetInstantMixFromSong(Audio item, User user, DtoOptions dtoOptions) + public List GetInstantMixFromSong(Audio item, User? user, DtoOptions dtoOptions) { - var list = new List