From b50fc351a12fa890b2d4ab6e71b7a4b609dd583c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 Jan 2014 16:21:47 -0500 Subject: [PATCH] add null checks to video methods --- MediaBrowser.Controller/Entities/Video.cs | 20 ++++++++++++++++--- .../Resolvers/EntityResolutionHelper.cs | 15 ++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index ba0e71d7d4..19cad79482 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -225,11 +225,25 @@ namespace MediaBrowser.Controller.Entities { IEnumerable files; + var path = Path; + + if (string.IsNullOrEmpty(path)) + { + throw new ApplicationException(string.Format("Item {0} has a null path.", Name ?? Id.ToString())); + } + if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd) { - files = new DirectoryInfo(System.IO.Path.GetDirectoryName(Path)) + var parentPath = System.IO.Path.GetDirectoryName(path); + + if (string.IsNullOrEmpty(parentPath)) + { + throw new ApplicationException("Unable to get parent path info from " + path); + } + + files = new DirectoryInfo(parentPath) .EnumerateDirectories() - .Where(i => !string.Equals(i.FullName, Path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFile(i.Name)); + .Where(i => !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFile(i.Name)); } else { @@ -240,7 +254,7 @@ namespace MediaBrowser.Controller.Entities return false; } - return !string.Equals(i.FullName, Path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name); + return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name); }); } diff --git a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs index 3cd38da45f..079571ee99 100644 --- a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs +++ b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs @@ -66,6 +66,11 @@ namespace MediaBrowser.Controller.Resolvers /// true if [is multi part file] [the specified path]; otherwise, false. public static bool IsMultiPartFile(string path) { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + return MultiFileRegex.Match(path).Success || MultiFolderRegex.Match(path).Success; } @@ -97,6 +102,11 @@ namespace MediaBrowser.Controller.Resolvers /// true if [is audio file] [the specified args]; otherwise, false. public static bool IsAudioFile(string path) { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + var extension = Path.GetExtension(path); if (string.IsNullOrEmpty(extension)) @@ -114,6 +124,11 @@ namespace MediaBrowser.Controller.Resolvers /// true if [is video file] [the specified path]; otherwise, false. public static bool IsVideoFile(string path) { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + var extension = Path.GetExtension(path); if (string.IsNullOrEmpty(extension))