From be7918e5f68f67ed32a50c2d86ee9cae79cf2b93 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 30 Oct 2013 10:40:14 -0400 Subject: fixes #567 - Deprecate native shortcut code --- MediaBrowser.Api/Library/LibraryHelpers.cs | 35 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.Api/Library/LibraryHelpers.cs') diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs index 008cfb27f..906b47458 100644 --- a/MediaBrowser.Api/Library/LibraryHelpers.cs +++ b/MediaBrowser.Api/Library/LibraryHelpers.cs @@ -12,20 +12,27 @@ namespace MediaBrowser.Api.Library /// public static class LibraryHelpers { + /// + /// The shortcut file extension + /// private const string ShortcutFileExtension = ".mblink"; + /// + /// The shortcut file search + /// private const string ShortcutFileSearch = "*" + ShortcutFileExtension; /// /// Adds the virtual folder. /// + /// The file system. /// The name. /// Type of the collection. /// The user. /// The app paths. /// There is already a media collection with the name + name + . - public static void AddVirtualFolder(string name, string collectionType, User user, IServerApplicationPaths appPaths) + public static void AddVirtualFolder(IFileSystem fileSystem, string name, string collectionType, User user, IServerApplicationPaths appPaths) { - name = FileSystem.GetValidFilename(name); + name = fileSystem.GetValidFilename(name); var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; var virtualFolderPath = Path.Combine(rootFolderPath, name); @@ -106,12 +113,13 @@ namespace MediaBrowser.Api.Library /// /// Deletes a shortcut from within a virtual folder, within either the default view or a user view /// + /// The file system. /// Name of the virtual folder. /// The media path. /// The user. /// The app paths. /// The media folder does not exist - public static void RemoveMediaPath(string virtualFolderName, string mediaPath, User user, IServerApplicationPaths appPaths) + public static void RemoveMediaPath(IFileSystem fileSystem, string virtualFolderName, string mediaPath, User user, IServerApplicationPaths appPaths) { var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; var path = Path.Combine(rootFolderPath, virtualFolderName); @@ -121,7 +129,7 @@ namespace MediaBrowser.Api.Library throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName)); } - var shortcut = Directory.EnumerateFiles(path, ShortcutFileSearch, SearchOption.AllDirectories).FirstOrDefault(f => FileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase)); + var shortcut = Directory.EnumerateFiles(path, ShortcutFileSearch, SearchOption.AllDirectories).FirstOrDefault(f => fileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(shortcut)) { @@ -132,13 +140,14 @@ namespace MediaBrowser.Api.Library /// /// Adds an additional mediaPath to an existing virtual folder, within either the default view or a user view /// + /// The file system. /// Name of the virtual folder. /// The path. /// The user. /// The app paths. /// The path is not valid. /// The path does not exist. - public static void AddMediaPath(string virtualFolderName, string path, User user, IServerApplicationPaths appPaths) + public static void AddMediaPath(IFileSystem fileSystem, string virtualFolderName, string path, User user, IServerApplicationPaths appPaths) { if (!Path.IsPathRooted(path)) { @@ -160,7 +169,7 @@ namespace MediaBrowser.Api.Library var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName); - ValidateNewMediaPath(rootFolderPath, path, appPaths); + ValidateNewMediaPath(fileSystem, rootFolderPath, path, appPaths); var shortcutFilename = Path.GetFileNameWithoutExtension(path); @@ -172,20 +181,22 @@ namespace MediaBrowser.Api.Library lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension); } - FileSystem.CreateShortcut(lnk, path); + fileSystem.CreateShortcut(lnk, path); } /// /// Validates that a new media path can be added /// + /// The file system. /// The current view root folder path. /// The media path. /// The app paths. - /// - private static void ValidateNewMediaPath(string currentViewRootFolderPath, string mediaPath, IServerApplicationPaths appPaths) + /// + /// + private static void ValidateNewMediaPath(IFileSystem fileSystem, string currentViewRootFolderPath, string mediaPath, IServerApplicationPaths appPaths) { var duplicate = Directory.EnumerateFiles(appPaths.RootFolderPath, ShortcutFileSearch, SearchOption.AllDirectories) - .Select(FileSystem.ResolveShortcut) + .Select(fileSystem.ResolveShortcut) .FirstOrDefault(p => !IsNewPathValid(mediaPath, p, false)); if (!string.IsNullOrEmpty(duplicate)) @@ -196,7 +207,7 @@ namespace MediaBrowser.Api.Library // Don't allow duplicate sub-paths within the same user library, or it will result in duplicate items // See comments in IsNewPathValid duplicate = Directory.EnumerateFiles(currentViewRootFolderPath, ShortcutFileSearch, SearchOption.AllDirectories) - .Select(FileSystem.ResolveShortcut) + .Select(fileSystem.ResolveShortcut) .FirstOrDefault(p => !IsNewPathValid(mediaPath, p, true)); if (!string.IsNullOrEmpty(duplicate)) @@ -206,7 +217,7 @@ namespace MediaBrowser.Api.Library // Make sure the current root folder doesn't already have a shortcut to the same path duplicate = Directory.EnumerateFiles(currentViewRootFolderPath, ShortcutFileSearch, SearchOption.AllDirectories) - .Select(FileSystem.ResolveShortcut) + .Select(fileSystem.ResolveShortcut) .FirstOrDefault(p => mediaPath.Equals(p, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(duplicate)) -- cgit v1.2.3