MbLinkShortcutHandler.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Common.IO;
  4. using MediaBrowser.Controller.IO;
  5. using MediaBrowser.Model.IO;
  6. namespace Emby.Server.Implementations.IO
  7. {
  8. public class MbLinkShortcutHandler : IShortcutHandler
  9. {
  10. private readonly IFileSystem _fileSystem;
  11. public MbLinkShortcutHandler(IFileSystem fileSystem)
  12. {
  13. _fileSystem = fileSystem;
  14. }
  15. public string Extension
  16. {
  17. get { return ".mblink"; }
  18. }
  19. public string Resolve(string shortcutPath)
  20. {
  21. if (string.IsNullOrEmpty(shortcutPath))
  22. {
  23. throw new ArgumentNullException("filenshortcutPathame");
  24. }
  25. if (string.Equals(Path.GetExtension(shortcutPath), ".mblink", StringComparison.OrdinalIgnoreCase))
  26. {
  27. var path = _fileSystem.ReadAllText(shortcutPath);
  28. return _fileSystem.NormalizePath(path);
  29. }
  30. return null;
  31. }
  32. public void Create(string shortcutPath, string targetPath)
  33. {
  34. if (string.IsNullOrEmpty(shortcutPath))
  35. {
  36. throw new ArgumentNullException("shortcutPath");
  37. }
  38. if (string.IsNullOrEmpty(targetPath))
  39. {
  40. throw new ArgumentNullException("targetPath");
  41. }
  42. _fileSystem.WriteAllText(shortcutPath, targetPath);
  43. }
  44. }
  45. }