MbLinkShortcutHandler.cs 1.4 KB

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