MbLinkShortcutHandler.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma warning disable CS1591
  2. #pragma warning disable SA1600
  3. using System;
  4. using System.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 => ".mblink";
  16. public string Resolve(string shortcutPath)
  17. {
  18. if (string.IsNullOrEmpty(shortcutPath))
  19. {
  20. throw new ArgumentException("Shortcut path is empty or null.", nameof(shortcutPath));
  21. }
  22. if (string.Equals(Path.GetExtension(shortcutPath), ".mblink", StringComparison.OrdinalIgnoreCase))
  23. {
  24. var path = File.ReadAllText(shortcutPath);
  25. return _fileSystem.NormalizePath(path);
  26. }
  27. return null;
  28. }
  29. public void Create(string shortcutPath, string targetPath)
  30. {
  31. if (string.IsNullOrEmpty(shortcutPath))
  32. {
  33. throw new ArgumentNullException(nameof(shortcutPath));
  34. }
  35. if (string.IsNullOrEmpty(targetPath))
  36. {
  37. throw new ArgumentNullException(nameof(targetPath));
  38. }
  39. File.WriteAllText(shortcutPath, targetPath);
  40. }
  41. }
  42. }