The Free Software Media System - Server Backend & API
Fix some warnings
Bond_009474b035d99c3
diff --git a/Emby.Server.Implementations/Data/ManagedConnection.cs b/Emby.Server.Implementations/Data/ManagedConnection.csindex 44dad5b178..11e33278d4 100644--- a/Emby.Server.Implementations/Data/ManagedConnection.cs+++ b/Emby.Server.Implementations/Data/ManagedConnection.cs@@ -7,7 +7,7 @@ using SQLitePCL.pretty;namespace Emby.Server.Implementations.Data{- public class ManagedConnection : IDisposable+ public sealed class ManagedConnection : IDisposable{private readonly SemaphoreSlim _writeLock;diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.csindex 47a83d77ce..e62361c1e1 100644--- a/Emby.Server.Implementations/IO/FileRefresher.cs+++ b/Emby.Server.Implementations/IO/FileRefresher.cs@@ -1,5 +1,3 @@-#nullable disable-#pragma warning disable CS1591using System;@@ -14,7 +12,7 @@ using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.IO{- public class FileRefresher : IDisposable+ public sealed class FileRefresher : IDisposable{private readonly ILogger _logger;private readonly ILibraryManager _libraryManager;@@ -22,7 +20,7 @@ namespace Emby.Server.Implementations.IOprivate readonly List<string> _affectedPaths = new List<string>();private readonly object _timerLock = new object();- private Timer _timer;+ private Timer? _timer;private bool _disposed;public FileRefresher(string path, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogger logger)@@ -36,7 +34,7 @@ namespace Emby.Server.Implementations.IOAddPath(path);}- public event EventHandler<EventArgs> Completed;+ public event EventHandler<EventArgs>? Completed;public string Path { get; private set; }@@ -111,7 +109,7 @@ namespace Emby.Server.Implementations.IORestartTimer();}- private void OnTimerCallback(object state)+ private void OnTimerCallback(object? state){List<string> paths;@@ -127,7 +125,7 @@ namespace Emby.Server.Implementations.IOtry{- ProcessPathChanges(paths.ToList());+ ProcessPathChanges(paths);}catch (Exception ex){@@ -137,12 +135,12 @@ namespace Emby.Server.Implementations.IOprivate void ProcessPathChanges(List<string> paths){- var itemsToRefresh = paths+ IEnumerable<BaseItem> itemsToRefresh = paths.Distinct(StringComparer.OrdinalIgnoreCase).Select(GetAffectedBaseItem).Where(item => item != null)- .GroupBy(x => x.Id)- .Select(x => x.First());+ .GroupBy(x => x!.Id) // Removed null values in the previous .Where()+ .Select(x => x.First())!;foreach (var item in itemsToRefresh){@@ -176,15 +174,15 @@ namespace Emby.Server.Implementations.IO/// </summary>/// <param name="path">The path.</param>/// <returns>BaseItem.</returns>- private BaseItem GetAffectedBaseItem(string path)+ private BaseItem? GetAffectedBaseItem(string path){- BaseItem item = null;+ BaseItem? item = null;while (item == null && !string.IsNullOrEmpty(path)){item = _libraryManager.FindByPath(path, null);- path = System.IO.Path.GetDirectoryName(path);+ path = System.IO.Path.GetDirectoryName(path) ?? string.Empty;}if (item != null)diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.csindex b525f5a2f8..9fcc7fe59c 100644--- a/Emby.Server.Implementations/IO/LibraryMonitor.cs+++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs@@ -449,12 +449,12 @@ namespace Emby.Server.Implementations.IO}var newRefresher = new FileRefresher(path, _configurationManager, _libraryManager, _logger);- newRefresher.Completed += NewRefresher_Completed;+ newRefresher.Completed += OnNewRefresherCompleted;_activeRefreshers.Add(newRefresher);}}- private void NewRefresher_Completed(object sender, EventArgs e)+ private void OnNewRefresherCompleted(object sender, EventArgs e){var refresher = (FileRefresher)sender;DisposeRefresher(refresher);@@ -481,6 +481,7 @@ namespace Emby.Server.Implementations.IO{lock (_activeRefreshers){+ refresher.Completed -= OnNewRefresherCompleted;refresher.Dispose();_activeRefreshers.Remove(refresher);}@@ -492,6 +493,7 @@ namespace Emby.Server.Implementations.IO{foreach (var refresher in _activeRefreshers.ToList()){+ refresher.Completed -= OnNewRefresherCompleted;refresher.Dispose();}diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.csindex 5726d7158f..a88a1fe849 100644--- a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs@@ -187,7 +187,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTVCultureInfo.InvariantCulture,"-i \"{0}\" {2} -map_metadata -1 -threads {6} {3}{4}{5} -y \"{1}\"",inputTempFile,- targetFile.Replace("\"", "\\\""), // Escape quotes in filename+ targetFile.Replace("\"", "\\\"", StringComparison.Ordinal), // Escape quotes in filenamevideoArgs,GetAudioArgs(mediaSource),subtitleArgs,diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.csindex f9d151a81a..9ab4cc628b 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs@@ -51,7 +51,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerunpublic async Task<bool> CheckTunerAvailability(IPAddress remoteIp, int tuner, CancellationToken cancellationToken){using var client = new TcpClient();- client.Connect(remoteIp, HdHomeRunPort);+ await client.ConnectAsync(remoteIp, HdHomeRunPort).ConfigureAwait(false);using var stream = client.GetStream();return await CheckTunerAvailability(stream, tuner, cancellationToken).ConfigureAwait(false);diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.csindex 506ef5548a..708ff52d79 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs@@ -283,7 +283,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts// #EXTINF:0,84.0 - VOX Schweizif (!string.IsNullOrWhiteSpace(nameInExtInf)){- var numberIndex = nameInExtInf.IndexOf(' ');+ var numberIndex = nameInExtInf.IndexOf(' ', StringComparison.Ordinal);if (numberIndex > 0){var numberPart = nameInExtInf.Substring(0, numberIndex).Trim(new[] { ' ', '.' });diff --git a/Emby.Server.Implementations/Playlists/PlaylistManager.cs b/Emby.Server.Implementations/Playlists/PlaylistManager.csindex b07798fa40..9481e26f72 100644--- a/Emby.Server.Implementations/Playlists/PlaylistManager.cs+++ b/Emby.Server.Implementations/Playlists/PlaylistManager.cs@@ -527,7 +527,7 @@ namespace Emby.Server.Implementations.Playlistsvar relativeUri = folderUri.MakeRelativeUri(fileAbsoluteUri);string relativePath = Uri.UnescapeDataString(relativeUri.ToString());- if (fileAbsoluteUri.Scheme.Equals("file", StringComparison.CurrentCultureIgnoreCase))+ if (fileAbsoluteUri.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase)){relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);}diff --git a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.csindex bd19666238..67a9fbd3bc 100644--- a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs+++ b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs@@ -26,7 +26,7 @@ namespace Emby.Server.Implementations.Sorting/// <returns>System.Int32.</returns>public int Compare(BaseItem? x, BaseItem? y){- return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);+ return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);}/// <summary>diff --git a/Emby.Server.Implementations/Sorting/AlbumComparer.cs b/Emby.Server.Implementations/Sorting/AlbumComparer.csindex fe7dc84cbf..4d09dda842 100644--- a/Emby.Server.Implementations/Sorting/AlbumComparer.cs+++ b/Emby.Server.Implementations/Sorting/AlbumComparer.cs@@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Sorting/// <returns>System.Int32.</returns>public int Compare(BaseItem? x, BaseItem? y){- return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);+ return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);}/// <summary>@@ -35,9 +35,7 @@ namespace Emby.Server.Implementations.Sorting/// <returns>System.String.</returns>private static string? GetValue(BaseItem? x){- var audio = x as Audio;-- return audio == null ? string.Empty : audio.Album;+ return x is Audio audio ? audio.Album : string.Empty;}}}diff --git a/Emby.Server.Implementations/Sorting/ArtistComparer.cs b/Emby.Server.Implementations/Sorting/ArtistComparer.csindex 7b7ba57531..a8bb55e2bc 100644--- a/Emby.Server.Implementations/Sorting/ArtistComparer.cs+++ b/Emby.Server.Implementations/Sorting/ArtistComparer.cs@@ -17,7 +17,7 @@ namespace Emby.Server.Implementations.Sorting/// <inheritdoc />public int Compare(BaseItem? x, BaseItem? y){- return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);+ return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);}/// <summary>diff --git a/Emby.Server.Implementations/Sorting/NameComparer.cs b/Emby.Server.Implementations/Sorting/NameComparer.csindex 8f87717f49..c2875eeb97 100644--- a/Emby.Server.Implementations/Sorting/NameComparer.cs+++ b/Emby.Server.Implementations/Sorting/NameComparer.cs@@ -34,7 +34,7 @@ namespace Emby.Server.Implementations.Sortingthrow new ArgumentNullException(nameof(y));}- return string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase);+ return string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase);}}}diff --git a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.csindex 4123a59f8b..0bd9600b98 100644--- a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs+++ b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs@@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Sorting/// <returns>System.Int32.</returns>public int Compare(BaseItem x, BaseItem y){- return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);+ return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);}private static string GetValue(BaseItem item)diff --git a/Emby.Server.Implementations/Sorting/SortNameComparer.cs b/Emby.Server.Implementations/Sorting/SortNameComparer.csindex fb97a0349d..79be9a89a4 100644--- a/Emby.Server.Implementations/Sorting/SortNameComparer.cs+++ b/Emby.Server.Implementations/Sorting/SortNameComparer.cs@@ -36,7 +36,7 @@ namespace Emby.Server.Implementations.Sortingthrow new ArgumentNullException(nameof(y));}- return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);+ return string.Compare(x.SortName, y.SortName, StringComparison.OrdinalIgnoreCase);}}}diff --git a/RSSDP/HttpParserBase.cs b/RSSDP/HttpParserBase.csindex c56249523d..6b6c13d996 100644--- a/RSSDP/HttpParserBase.cs+++ b/RSSDP/HttpParserBase.cs@@ -82,7 +82,7 @@ namespace Rssdp.Infrastructurethrow new ArgumentNullException(nameof(versionData));}- var versionSeparatorIndex = versionData.IndexOf('/');+ var versionSeparatorIndex = versionData.IndexOf('/', StringComparison.Ordinal);if (versionSeparatorIndex <= 0 || versionSeparatorIndex == versionData.Length){throw new ArgumentException("request header line is invalid. Http Version not supplied or incorrect format.", nameof(versionData));@@ -101,7 +101,7 @@ namespace Rssdp.Infrastructure{// Header format is// name: value- var headerKeySeparatorIndex = line.IndexOf(":", StringComparison.OrdinalIgnoreCase);+ var headerKeySeparatorIndex = line.IndexOf(':', StringComparison.Ordinal);var headerName = line.Substring(0, headerKeySeparatorIndex).Trim();var headerValue = line.Substring(headerKeySeparatorIndex + 1).Trim();@@ -172,7 +172,7 @@ namespace Rssdp.Infrastructureelse{var segments = headerValue.Split(SeparatorCharacters);- if (headerValue.Contains('"'))+ if (headerValue.Contains('"', StringComparison.Ordinal)){for (int segmentIndex = 0; segmentIndex < segments.Length; segmentIndex++){diff --git a/jellyfin.ruleset b/jellyfin.rulesetindex e14c1c4270..469f61021a 100644--- a/jellyfin.ruleset+++ b/jellyfin.ruleset@@ -38,8 +38,14 @@</Rules><Rules AnalyzerId="Microsoft.CodeAnalysis.NetAnalyzers" RuleNamespace="Microsoft.Design">+ <!-- error on CA1063: Implement IDisposable correctly -->+ <Rule Id="CA1063" Action="Error" /><!-- error on CA1305: Specify IFormatProvider --><Rule Id="CA1305" Action="Error" />+ <!-- error on CA1307: Specify StringComparison for clarity -->+ <Rule Id="CA1307" Action="Error" />+ <!-- error on CA1309: Use ordinal StringComparison -->+ <Rule Id="CA1309" Action="Error" /><!-- error on CA1725: Parameter names should match base declaration --><Rule Id="CA1725" Action="Error" /><!-- error on CA1725: Call async methods when in an async method -->