MbLinkShortcutHandler.cs 1.4 KB

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