Skip to content

Commit

Permalink
Merge pull request jellyfin#10366 from goremykin/fix-resharper-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 authored Oct 17, 2023
2 parents 59ac548 + 38d9622 commit 84bbf75
Show file tree
Hide file tree
Showing 89 changed files with 449 additions and 507 deletions.
12 changes: 4 additions & 8 deletions Emby.Dlna/PlayTo/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -927,14 +927,11 @@ private static string[] GetProtocolInfo(XElement container)

var resElement = container.Element(UPnpNamespaces.Res);

if (resElement is not null)
{
var info = resElement.Attribute(UPnpNamespaces.ProtocolInfo);
var info = resElement?.Attribute(UPnpNamespaces.ProtocolInfo);

if (info is not null && !string.IsNullOrWhiteSpace(info.Value))
{
return info.Value.Split(':');
}
if (info is not null && !string.IsNullOrWhiteSpace(info.Value))
{
return info.Value.Split(':');
}

return new string[4];
Expand Down Expand Up @@ -1139,7 +1136,6 @@ private string NormalizeUrl(string baseUrl, string url)
return new Device(deviceProperties, httpClientFactory, logger);
}

#nullable enable
private static DeviceIcon CreateIcon(XElement element)
{
ArgumentNullException.ThrowIfNull(element);
Expand Down
4 changes: 2 additions & 2 deletions Emby.Dlna/PlayTo/PlayToManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public sealed class PlayToManager : IDisposable
private readonly IMediaSourceManager _mediaSourceManager;
private readonly IMediaEncoder _mediaEncoder;

private readonly SemaphoreSlim _sessionLock = new SemaphoreSlim(1, 1);
private readonly CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource();
private bool _disposed;
private SemaphoreSlim _sessionLock = new SemaphoreSlim(1, 1);
private CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource();

public PlayToManager(ILogger logger, ISessionManager sessionManager, ILibraryManager libraryManager, IUserManager userManager, IDlnaManager dlnaManager, IServerApplicationHost appHost, IImageProcessor imageProcessor, IDeviceDiscovery deviceDiscovery, IHttpClientFactory httpClientFactory, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder)
{
Expand Down
10 changes: 5 additions & 5 deletions Emby.Naming/Common/NamingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public NamingOptions()
new EpisodeExpression(@"[\._ -]()[Ee][Pp]_?([0-9]+)([^\\/]*)$"),
// <!-- foo.E01., foo.e01. -->
new EpisodeExpression(@"[^\\/]*?()\.?[Ee]([0-9]+)\.([^\\/]*)$"),
new EpisodeExpression(@"(?<year>[0-9]{4})[._ -](?<month>[0-9]{2})[._ -](?<day>[0-9]{2})", true)
new EpisodeExpression("(?<year>[0-9]{4})[._ -](?<month>[0-9]{2})[._ -](?<day>[0-9]{2})", true)
{
DateTimeFormats = new[]
{
Expand All @@ -328,7 +328,7 @@ public NamingOptions()
"yyyy MM dd"
}
},
new EpisodeExpression(@"(?<day>[0-9]{2})[._ -](?<month>[0-9]{2})[._ -](?<year>[0-9]{4})", true)
new EpisodeExpression("(?<day>[0-9]{2})[._ -](?<month>[0-9]{2})[._ -](?<year>[0-9]{4})", true)
{
DateTimeFormats = new[]
{
Expand Down Expand Up @@ -376,7 +376,7 @@ public NamingOptions()
IsNamed = true,
SupportsAbsoluteEpisodeNumbers = false
},
new EpisodeExpression("[\\/._ -]p(?:ar)?t[_. -]()([ivx]+|[0-9]+)([._ -][^\\/]*)$")
new EpisodeExpression(@"[\/._ -]p(?:ar)?t[_. -]()([ivx]+|[0-9]+)([._ -][^\/]*)$")
{
SupportsAbsoluteEpisodeNumbers = true
},
Expand Down Expand Up @@ -417,7 +417,7 @@ public NamingOptions()
},

// "1-12 episode title"
new EpisodeExpression(@"([0-9]+)-([0-9]+)"),
new EpisodeExpression("([0-9]+)-([0-9]+)"),

// "01 - blah.avi", "01-blah.avi"
new EpisodeExpression(@".*(\\|\/)(?<epnumber>[0-9]{1,3})(-(?<endingepnumber>[0-9]{2,3}))*\s?-\s?[^\\\/]*$")
Expand Down Expand Up @@ -712,7 +712,7 @@ public NamingOptions()
// Chapter is often beginning of filename
"^(?<chapter>[0-9]+)",
// Part if often ending of filename
@"(?<!ch(?:apter) )(?<part>[0-9]+)$",
"(?<!ch(?:apter) )(?<part>[0-9]+)$",
// Sometimes named as 0001_005 (chapter_part)
"(?<chapter>[0-9]+)_(?<part>[0-9]+)",
// Some audiobooks are ripped from cd's, and will be named by disk number.
Expand Down
6 changes: 2 additions & 4 deletions Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Emby.Server.Implementations.AppBase
/// </summary>
public abstract class BaseApplicationPaths : IApplicationPaths
{
private string _dataPath;

/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
/// </summary>
Expand All @@ -33,7 +31,7 @@ protected BaseApplicationPaths(
CachePath = cacheDirectoryPath;
WebPath = webDirectoryPath;

_dataPath = Directory.CreateDirectory(Path.Combine(ProgramDataPath, "data")).FullName;
DataPath = Directory.CreateDirectory(Path.Combine(ProgramDataPath, "data")).FullName;
}

/// <summary>
Expand All @@ -55,7 +53,7 @@ protected BaseApplicationPaths(
/// Gets the folder path to the data directory.
/// </summary>
/// <value>The data directory.</value>
public string DataPath => _dataPath;
public string DataPath { get; }

/// <inheritdoc />
public string VirtualDataPath => "%AppDataPath%";
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ private async Task<BaseItem> GetChannelItemEntityAsync(ChannelItemInfo info, ICh

if (info.People is not null && info.People.Count > 0)
{
_libraryManager.UpdatePeople(item, info.People);
await _libraryManager.UpdatePeopleAsync(item, info.People, cancellationToken).ConfigureAwait(false);
}
}
else if (forceUpdate)
Expand Down
7 changes: 2 additions & 5 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3540,10 +3540,7 @@ private List<string> GetWhereClauses(InternalItemsQuery query, SqliteCommand? st
.Append(paramName)
.Append("))) OR ");

if (statement is not null)
{
statement.TryBind(paramName, query.PersonIds[i]);
}
statement?.TryBind(paramName, query.PersonIds[i]);
}

clauseBuilder.Length -= Or.Length;
Expand Down Expand Up @@ -4382,7 +4379,7 @@ private List<string> GetWhereClauses(InternalItemsQuery query, SqliteCommand? st

foreach (var videoType in query.VideoTypes)
{
videoTypes.Add("data like '%\"VideoType\":\"" + videoType.ToString() + "\"%'");
videoTypes.Add("data like '%\"VideoType\":\"" + videoType + "\"%'");
}

whereClauses.Add("(" + string.Join(" OR ", videoTypes) + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public sealed class UdpServerEntryPoint : IServerEntryPoint
/// <summary>
/// The UDP server.
/// </summary>
private List<UdpServer> _udpServers;
private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private bool _disposed = false;
private readonly List<UdpServer> _udpServers;
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private bool _disposed;

/// <summary>
/// Initializes a new instance of the <see cref="UdpServerEntryPoint" /> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using MediaBrowser.Controller.Net.WebSocketMessages;
using MediaBrowser.Controller.Net.WebSocketMessages.Outbound;
using MediaBrowser.Model.Session;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

namespace Emby.Server.Implementations.HttpServer
Expand Down
1 change: 0 additions & 1 deletion Emby.Server.Implementations/IO/FileRefresher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ public void Dispose()

DisposeTimer();
_disposed = true;
GC.SuppressFinalize(this);
}
}
}
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/IO/ManagedFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public virtual string MakeAbsolutePath(string folderPath, string filePath)
}

// unc path
if (filePath.StartsWith("\\\\", StringComparison.Ordinal))
if (filePath.StartsWith(@"\\", StringComparison.Ordinal))
{
return filePath;
}
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,7 @@ public async Task AddVirtualFolder(string name, CollectionTypeOptions? collectio
{
var path = Path.Combine(virtualFolderPath, collectionType.ToString().ToLowerInvariant() + ".collection");

File.WriteAllBytes(path, Array.Empty<byte>());
await File.WriteAllBytesAsync(path, Array.Empty<byte>()).ConfigureAwait(false);
}

CollectionFolder.SaveLibraryOptions(virtualFolderPath, options);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Emby.Naming.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override Season Resolve(ItemResolveArgs args)
var resolver = new Naming.TV.EpisodeResolver(namingOptions);

var folderName = System.IO.Path.GetFileName(path);
var testPath = "\\\\test\\" + folderName;
var testPath = @"\\test\" + folderName;

var episodeInfo = resolver.Resolve(testPath, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;

namespace Emby.Server.Implementations.LiveTv.TunerHosts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Net;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;

namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public void Dispose()
StopStreaming(socket).GetAwaiter().GetResult();
}
}

GC.SuppressFinalize(this);
}

public async Task<bool> CheckTunerAvailability(IPAddress remoteIP, int tuner, CancellationToken cancellationToken)
Expand Down
2 changes: 0 additions & 2 deletions Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
Expand All @@ -22,7 +21,6 @@
using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.MediaInfo;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;

Expand Down
6 changes: 3 additions & 3 deletions Emby.Server.Implementations/Net/SocketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Socket CreateUdpBroadcastSocket(int localPort)
}
catch
{
socket?.Dispose();
socket.Dispose();

throw;
}
Expand All @@ -59,7 +59,7 @@ public Socket CreateSsdpUdpSocket(IPData bindInterface, int localPort)
}
catch
{
socket?.Dispose();
socket.Dispose();

throw;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public Socket CreateUdpMulticastSocket(IPAddress multicastAddress, IPData bindIn
}
catch
{
socket?.Dispose();
socket.Dispose();

throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken can
{
try
{
previouslyFailedImages = File.ReadAllText(failHistoryPath)
previouslyFailedImages = (await File.ReadAllTextAsync(failHistoryPath, cancellationToken).ConfigureAwait(false))
.Split('|', StringSplitOptions.RemoveEmptyEntries)
.ToList();
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken can
}

string text = string.Join('|', previouslyFailedImages);
File.WriteAllText(failHistoryPath, text);
await File.WriteAllTextAsync(failHistoryPath, text, cancellationToken).ConfigureAwait(false);
}

numComplete++;
Expand Down
11 changes: 5 additions & 6 deletions Emby.Server.Implementations/Udp/UdpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public sealed class UdpServer : IDisposable

private readonly byte[] _receiveBuffer = new byte[8192];

private Socket _udpSocket;
private IPEndPoint _endpoint;
private bool _disposed = false;
private readonly Socket _udpSocket;
private readonly IPEndPoint _endpoint;
private bool _disposed;

/// <summary>
/// Initializes a new instance of the <see cref="UdpServer" /> class.
Expand Down Expand Up @@ -130,9 +130,8 @@ public void Dispose()
return;
}

_udpSocket?.Dispose();

GC.SuppressFinalize(this);
_udpSocket.Dispose();
_disposed = true;
}
}
}
6 changes: 3 additions & 3 deletions Jellyfin.Api/Controllers/LibraryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ public ActionResult<AllThemeMediaResult> GetThemeMedia(

return new AllThemeMediaResult
{
ThemeSongsResult = themeSongs?.Value,
ThemeVideosResult = themeVideos?.Value,
ThemeSongsResult = themeSongs.Value,
ThemeVideosResult = themeVideos.Value,
SoundtrackSongsResult = new ThemeMediaResult()
};
}
Expand Down Expand Up @@ -490,7 +490,7 @@ public ActionResult<IEnumerable<BaseItemDto>> GetAncestors([FromRoute, Required]

baseItemDtos.Add(_dtoService.GetBaseItemDto(parent, dtoOptions, user));

parent = parent?.GetParent();
parent = parent.GetParent();
}

return baseItemDtos;
Expand Down
20 changes: 10 additions & 10 deletions Jellyfin.Api/Middleware/ExceptionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ private static Exception GetActualException(Exception ex)

private static int GetStatusCode(Exception ex)
{
switch (ex)
return ex switch
{
case ArgumentException _: return StatusCodes.Status400BadRequest;
case AuthenticationException _: return StatusCodes.Status401Unauthorized;
case SecurityException _: return StatusCodes.Status403Forbidden;
case DirectoryNotFoundException _:
case FileNotFoundException _:
case ResourceNotFoundException _: return StatusCodes.Status404NotFound;
case MethodNotAllowedException _: return StatusCodes.Status405MethodNotAllowed;
default: return StatusCodes.Status500InternalServerError;
}
ArgumentException => StatusCodes.Status400BadRequest,
AuthenticationException => StatusCodes.Status401Unauthorized,
SecurityException => StatusCodes.Status403Forbidden,
DirectoryNotFoundException => StatusCodes.Status404NotFound,
FileNotFoundException => StatusCodes.Status404NotFound,
ResourceNotFoundException => StatusCodes.Status404NotFound,
MethodNotAllowedException => StatusCodes.Status405MethodNotAllowed,
_ => StatusCodes.Status500InternalServerError
};
}

private string NormalizeExceptionMessage(string msg)
Expand Down
3 changes: 1 addition & 2 deletions Jellyfin.Networking/Extensions/NetworkExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -204,7 +203,7 @@ public static bool TryParseToSubnet(ReadOnlySpan<char> value, [NotNullWhen(true)
{
var ipBlock = splitString.Current;
var address = IPAddress.None;
if (negated && ipBlock.StartsWith<char>("!") && IPAddress.TryParse(ipBlock[1..], out var tmpAddress))
if (negated && ipBlock.StartsWith("!") && IPAddress.TryParse(ipBlock[1..], out var tmpAddress))
{
address = tmpAddress;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Globalization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Events;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Events.Authentication;
using MediaBrowser.Model.Activity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Jellyfin.Data.Events;
using Jellyfin.Data.Events.System;
using Jellyfin.Data.Events.System;
using Jellyfin.Data.Events.Users;
using Jellyfin.Server.Implementations.Events.Consumers.Library;
using Jellyfin.Server.Implementations.Events.Consumers.Security;
Expand Down
Loading

0 comments on commit 84bbf75

Please sign in to comment.