MbLinkShortcutHandler.cs 1.3 KB

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