jellyfin-server/MediaBrowser.Api/Library/LibraryHelpers.cs

55 lines
2.1 KiB
C#
Raw Normal View History

2016-03-27 21:11:27 +00:00
using MediaBrowser.Controller;
2013-02-21 01:33:05 +00:00
using System;
using System.IO;
using System.Linq;
2015-10-04 04:23:11 +00:00
using CommonIO;
2013-02-21 01:33:05 +00:00
2013-02-25 03:56:00 +00:00
namespace MediaBrowser.Api.Library
2013-02-21 01:33:05 +00:00
{
/// <summary>
2013-02-25 03:56:00 +00:00
/// Class LibraryHelpers
2013-02-21 01:33:05 +00:00
/// </summary>
2013-02-25 03:56:00 +00:00
public static class LibraryHelpers
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// The shortcut file extension
/// </summary>
2013-10-01 20:20:48 +00:00
private const string ShortcutFileExtension = ".mblink";
/// <summary>
/// The shortcut file search
/// </summary>
2013-10-01 20:20:48 +00:00
private const string ShortcutFileSearch = "*" + ShortcutFileExtension;
2013-10-01 19:25:12 +00:00
2013-02-25 03:56:00 +00:00
/// <summary>
/// Deletes a shortcut from within a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="fileSystem">The file system.</param>
2013-02-25 03:56:00 +00:00
/// <param name="virtualFolderName">Name of the virtual folder.</param>
/// <param name="mediaPath">The media path.</param>
/// <param name="appPaths">The app paths.</param>
/// <exception cref="System.IO.DirectoryNotFoundException">The media folder does not exist</exception>
2014-02-21 05:04:11 +00:00
public static void RemoveMediaPath(IFileSystem fileSystem, string virtualFolderName, string mediaPath, IServerApplicationPaths appPaths)
2013-02-25 03:56:00 +00:00
{
2015-12-06 01:40:49 +00:00
if (string.IsNullOrWhiteSpace(mediaPath))
{
throw new ArgumentNullException("mediaPath");
}
2014-02-21 05:04:11 +00:00
var rootFolderPath = appPaths.DefaultUserViewsPath;
2013-02-25 03:56:00 +00:00
var path = Path.Combine(rootFolderPath, virtualFolderName);
2015-12-06 01:40:49 +00:00
if (!fileSystem.DirectoryExists(path))
2013-02-25 03:56:00 +00:00
{
2013-03-04 16:42:19 +00:00
throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
2013-02-25 03:56:00 +00:00
}
2015-09-24 17:50:49 +00:00
var shortcut = Directory.EnumerateFiles(path, ShortcutFileSearch, SearchOption.AllDirectories).FirstOrDefault(f => fileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase));
2013-02-25 03:56:00 +00:00
2013-03-04 16:42:19 +00:00
if (!string.IsNullOrEmpty(shortcut))
2013-02-25 03:56:00 +00:00
{
fileSystem.DeleteFile(shortcut);
2013-02-25 03:56:00 +00:00
}
2013-02-21 01:33:05 +00:00
}
}
}