MbLinkShortcutHandler.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. ArgumentException.ThrowIfNullOrEmpty(shortcutPath);
  18. if (string.Equals(Path.GetExtension(shortcutPath), ".mblink", StringComparison.OrdinalIgnoreCase))
  19. {
  20. var path = File.ReadAllText(shortcutPath);
  21. return _fileSystem.NormalizePath(path);
  22. }
  23. return null;
  24. }
  25. public void Create(string shortcutPath, string targetPath)
  26. {
  27. ArgumentException.ThrowIfNullOrEmpty(shortcutPath);
  28. ArgumentException.ThrowIfNullOrEmpty(targetPath);
  29. File.WriteAllText(shortcutPath, targetPath);
  30. }
  31. }
  32. }