Merge pull request #5676 from Bond-009/useless

This commit is contained in:
Bond-009 2021-04-03 02:00:03 +02:00 committed by GitHub
commit 959a09bdb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 112 deletions

View File

@ -31,7 +31,7 @@ namespace Emby.Dlna.ConnectionManager
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void WriteResult(string methodName, IDictionary<string, string> methodParams, XmlWriter xmlWriter) protected override void WriteResult(string methodName, IReadOnlyDictionary<string, string> methodParams, XmlWriter xmlWriter)
{ {
if (string.Equals(methodName, "GetProtocolInfo", StringComparison.OrdinalIgnoreCase)) if (string.Equals(methodName, "GetProtocolInfo", StringComparison.OrdinalIgnoreCase))
{ {

View File

@ -121,7 +121,7 @@ namespace Emby.Dlna.ContentDirectory
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void WriteResult(string methodName, IDictionary<string, string> methodParams, XmlWriter xmlWriter) protected override void WriteResult(string methodName, IReadOnlyDictionary<string, string> methodParams, XmlWriter xmlWriter)
{ {
if (xmlWriter == null) if (xmlWriter == null)
{ {
@ -201,8 +201,8 @@ namespace Emby.Dlna.ContentDirectory
/// <summary> /// <summary>
/// Adds a "XSetBookmark" element to the xml document. /// Adds a "XSetBookmark" element to the xml document.
/// </summary> /// </summary>
/// <param name="sparams">The <see cref="IDictionary"/>.</param> /// <param name="sparams">The method parameters.</param>
private void HandleXSetBookmark(IDictionary<string, string> sparams) private void HandleXSetBookmark(IReadOnlyDictionary<string, string> sparams)
{ {
var id = sparams["ObjectID"]; var id = sparams["ObjectID"];
@ -305,35 +305,18 @@ namespace Emby.Dlna.ContentDirectory
return builder.ToString(); return builder.ToString();
} }
/// <summary>
/// Returns the value in the key of the dictionary, or defaultValue if it doesn't exist.
/// </summary>
/// <param name="sparams">The <see cref="IDictionary"/>.</param>
/// <param name="key">The key.</param>
/// <param name="defaultValue">The defaultValue.</param>
/// <returns>The <see cref="string"/>.</returns>
public static string GetValueOrDefault(IDictionary<string, string> sparams, string key, string defaultValue)
{
if (sparams != null && sparams.TryGetValue(key, out string val))
{
return val;
}
return defaultValue;
}
/// <summary> /// <summary>
/// Builds the "Browse" xml response. /// Builds the "Browse" xml response.
/// </summary> /// </summary>
/// <param name="xmlWriter">The <see cref="XmlWriter"/>.</param> /// <param name="xmlWriter">The <see cref="XmlWriter"/>.</param>
/// <param name="sparams">The <see cref="IDictionary"/>.</param> /// <param name="sparams">The method parameters.</param>
/// <param name="deviceId">The device Id to use.</param> /// <param name="deviceId">The device Id to use.</param>
private void HandleBrowse(XmlWriter xmlWriter, IDictionary<string, string> sparams, string deviceId) private void HandleBrowse(XmlWriter xmlWriter, IReadOnlyDictionary<string, string> sparams, string deviceId)
{ {
var id = sparams["ObjectID"]; var id = sparams["ObjectID"];
var flag = sparams["BrowseFlag"]; var flag = sparams["BrowseFlag"];
var filter = new Filter(GetValueOrDefault(sparams, "Filter", "*")); var filter = new Filter(sparams.GetValueOrDefault("Filter", "*"));
var sortCriteria = new SortCriteria(GetValueOrDefault(sparams, "SortCriteria", string.Empty)); var sortCriteria = new SortCriteria(sparams.GetValueOrDefault("SortCriteria", string.Empty));
var provided = 0; var provided = 0;
@ -435,9 +418,9 @@ namespace Emby.Dlna.ContentDirectory
/// Builds the response to the "X_BrowseByLetter request. /// Builds the response to the "X_BrowseByLetter request.
/// </summary> /// </summary>
/// <param name="xmlWriter">The <see cref="XmlWriter"/>.</param> /// <param name="xmlWriter">The <see cref="XmlWriter"/>.</param>
/// <param name="sparams">The <see cref="IDictionary"/>.</param> /// <param name="sparams">The method parameters.</param>
/// <param name="deviceId">The device id.</param> /// <param name="deviceId">The device id.</param>
private void HandleXBrowseByLetter(XmlWriter xmlWriter, IDictionary<string, string> sparams, string deviceId) private void HandleXBrowseByLetter(XmlWriter xmlWriter, IReadOnlyDictionary<string, string> sparams, string deviceId)
{ {
// TODO: Implement this method // TODO: Implement this method
HandleSearch(xmlWriter, sparams, deviceId); HandleSearch(xmlWriter, sparams, deviceId);
@ -447,13 +430,13 @@ namespace Emby.Dlna.ContentDirectory
/// Builds a response to the "Search" request. /// Builds a response to the "Search" request.
/// </summary> /// </summary>
/// <param name="xmlWriter">The xmlWriter<see cref="XmlWriter"/>.</param> /// <param name="xmlWriter">The xmlWriter<see cref="XmlWriter"/>.</param>
/// <param name="sparams">The sparams<see cref="IDictionary"/>.</param> /// <param name="sparams">The method parameters.</param>
/// <param name="deviceId">The deviceId<see cref="string"/>.</param> /// <param name="deviceId">The deviceId<see cref="string"/>.</param>
private void HandleSearch(XmlWriter xmlWriter, IDictionary<string, string> sparams, string deviceId) private void HandleSearch(XmlWriter xmlWriter, IReadOnlyDictionary<string, string> sparams, string deviceId)
{ {
var searchCriteria = new SearchCriteria(GetValueOrDefault(sparams, "SearchCriteria", string.Empty)); var searchCriteria = new SearchCriteria(sparams.GetValueOrDefault("SearchCriteria", string.Empty));
var sortCriteria = new SortCriteria(GetValueOrDefault(sparams, "SortCriteria", string.Empty)); var sortCriteria = new SortCriteria(sparams.GetValueOrDefault("SortCriteria", string.Empty));
var filter = new Filter(GetValueOrDefault(sparams, "Filter", "*")); var filter = new Filter(sparams.GetValueOrDefault("Filter", "*"));
// sort example: dc:title, dc:date // sort example: dc:title, dc:date

View File

@ -24,7 +24,7 @@ namespace Emby.Dlna.MediaReceiverRegistrar
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void WriteResult(string methodName, IDictionary<string, string> methodParams, XmlWriter xmlWriter) protected override void WriteResult(string methodName, IReadOnlyDictionary<string, string> methodParams, XmlWriter xmlWriter)
{ {
if (string.Equals(methodName, "IsAuthorized", StringComparison.OrdinalIgnoreCase)) if (string.Equals(methodName, "IsAuthorized", StringComparison.OrdinalIgnoreCase))
{ {

View File

@ -210,7 +210,7 @@ namespace Emby.Dlna.Service
} }
} }
protected abstract void WriteResult(string methodName, IDictionary<string, string> methodParams, XmlWriter xmlWriter); protected abstract void WriteResult(string methodName, IReadOnlyDictionary<string, string> methodParams, XmlWriter xmlWriter);
private void LogRequest(ControlRequest request) private void LogRequest(ControlRequest request)
{ {

View File

@ -55,7 +55,7 @@ namespace Emby.Server.Implementations.IO
} }
var extension = Path.GetExtension(filename); var extension = Path.GetExtension(filename);
return _shortcutHandlers.Any(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase)); return _shortcutHandlers.Any(i => string.Equals(extension, i.Extension, _isEnvironmentCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal));
} }
/// <summary> /// <summary>
@ -487,26 +487,9 @@ namespace Emby.Server.Implementations.IO
throw new ArgumentNullException(nameof(path)); throw new ArgumentNullException(nameof(path));
} }
var separatorChar = Path.DirectorySeparatorChar; return path.Contains(
Path.TrimEndingDirectorySeparator(parentPath) + Path.DirectorySeparatorChar,
return path.IndexOf(parentPath.TrimEnd(separatorChar) + separatorChar, StringComparison.OrdinalIgnoreCase) != -1; _isEnvironmentCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
}
public virtual bool IsRootPath(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
var parent = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(parent))
{
return false;
}
return true;
} }
public virtual string NormalizePath(string path) public virtual string NormalizePath(string path)
@ -521,7 +504,7 @@ namespace Emby.Server.Implementations.IO
return path; return path;
} }
return path.TrimEnd(Path.DirectorySeparatorChar); return Path.TrimEndingDirectorySeparator(path);
} }
public virtual bool AreEqual(string path1, string path2) public virtual bool AreEqual(string path1, string path2)
@ -536,7 +519,10 @@ namespace Emby.Server.Implementations.IO
return false; return false;
} }
return string.Equals(NormalizePath(path1), NormalizePath(path2), StringComparison.OrdinalIgnoreCase); return string.Equals(
NormalizePath(path1),
NormalizePath(path2),
_isEnvironmentCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
} }
public virtual string GetFileNameWithoutExtension(FileSystemMetadata info) public virtual string GetFileNameWithoutExtension(FileSystemMetadata info)

View File

@ -127,7 +127,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
{ {
if (child.IsDirectory) if (child.IsDirectory)
{ {
if (IsSeasonFolder(child.FullName, isTvContentType, libraryManager)) if (IsSeasonFolder(child.FullName, isTvContentType))
{ {
logger.LogDebug("{Path} is a series because of season folder {Dir}.", path, child.FullName); logger.LogDebug("{Path} is a series because of season folder {Dir}.", path, child.FullName);
return true; return true;
@ -160,32 +160,13 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
return false; return false;
} }
/// <summary>
/// Determines whether [is place holder] [the specified path].
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is place holder] [the specified path]; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentNullException">path</exception>
private static bool IsVideoPlaceHolder(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
var extension = Path.GetExtension(path);
return string.Equals(extension, ".disc", StringComparison.OrdinalIgnoreCase);
}
/// <summary> /// <summary>
/// Determines whether [is season folder] [the specified path]. /// Determines whether [is season folder] [the specified path].
/// </summary> /// </summary>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="isTvContentType">if set to <c>true</c> [is tv content type].</param> /// <param name="isTvContentType">if set to <c>true</c> [is tv content type].</param>
/// <param name="libraryManager">The library manager.</param>
/// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns>
private static bool IsSeasonFolder(string path, bool isTvContentType, ILibraryManager libraryManager) private static bool IsSeasonFolder(string path, bool isTvContentType)
{ {
var seasonNumber = SeasonPathParser.Parse(path, isTvContentType, isTvContentType).SeasonNumber; var seasonNumber = SeasonPathParser.Parse(path, isTvContentType, isTvContentType).SeasonNumber;

View File

@ -9,55 +9,44 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
internal class EpgChannelData internal class EpgChannelData
{ {
private readonly Dictionary<string, ChannelInfo> _channelsById;
private readonly Dictionary<string, ChannelInfo> _channelsByNumber;
private readonly Dictionary<string, ChannelInfo> _channelsByName;
public EpgChannelData(IEnumerable<ChannelInfo> channels) public EpgChannelData(IEnumerable<ChannelInfo> channels)
{ {
ChannelsById = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase); _channelsById = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
ChannelsByNumber = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase); _channelsByNumber = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
ChannelsByName = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase); _channelsByName = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
foreach (var channel in channels) foreach (var channel in channels)
{ {
ChannelsById[channel.Id] = channel; _channelsById[channel.Id] = channel;
if (!string.IsNullOrEmpty(channel.Number)) if (!string.IsNullOrEmpty(channel.Number))
{ {
ChannelsByNumber[channel.Number] = channel; _channelsByNumber[channel.Number] = channel;
} }
var normalizedName = NormalizeName(channel.Name ?? string.Empty); var normalizedName = NormalizeName(channel.Name ?? string.Empty);
if (!string.IsNullOrWhiteSpace(normalizedName)) if (!string.IsNullOrWhiteSpace(normalizedName))
{ {
ChannelsByName[normalizedName] = channel; _channelsByName[normalizedName] = channel;
} }
} }
} }
private Dictionary<string, ChannelInfo> ChannelsById { get; set; }
private Dictionary<string, ChannelInfo> ChannelsByNumber { get; set; }
private Dictionary<string, ChannelInfo> ChannelsByName { get; set; }
public ChannelInfo GetChannelById(string id) public ChannelInfo GetChannelById(string id)
{ => _channelsById.GetValueOrDefault(id);
ChannelsById.TryGetValue(id, out var result);
return result;
}
public ChannelInfo GetChannelByNumber(string number) public ChannelInfo GetChannelByNumber(string number)
{ => _channelsByNumber.GetValueOrDefault(number);
ChannelsByNumber.TryGetValue(number, out var result);
return result;
}
public ChannelInfo GetChannelByName(string name) public ChannelInfo GetChannelByName(string name)
{ => _channelsByName.GetValueOrDefault(name);
ChannelsByName.TryGetValue(name, out var result);
return result;
}
public static string NormalizeName(string value) public static string NormalizeName(string value)
{ {

View File

@ -117,13 +117,6 @@ namespace MediaBrowser.Model.IO
/// <returns><c>true</c> if [contains sub path] [the specified parent path]; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if [contains sub path] [the specified parent path]; otherwise, <c>false</c>.</returns>
bool ContainsSubPath(string parentPath, string path); bool ContainsSubPath(string parentPath, string path);
/// <summary>
/// Determines whether [is root path] [the specified path].
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is root path] [the specified path]; otherwise, <c>false</c>.</returns>
bool IsRootPath(string path);
/// <summary> /// <summary>
/// Normalizes the path. /// Normalizes the path.
/// </summary> /// </summary>