MbLinkShortcutHandler.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.IO;
  3. using CommonIO;
  4. namespace MediaBrowser.Server.Startup.Common
  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
  14. {
  15. get { return ".mblink"; }
  16. }
  17. public string Resolve(string shortcutPath)
  18. {
  19. if (string.IsNullOrEmpty(shortcutPath))
  20. {
  21. throw new ArgumentNullException("filenshortcutPathame");
  22. }
  23. if (string.Equals(Path.GetExtension(shortcutPath), ".mblink", StringComparison.OrdinalIgnoreCase))
  24. {
  25. var path = _fileSystem.ReadAllText(shortcutPath);
  26. return _fileSystem.NormalizePath(path);
  27. }
  28. return null;
  29. }
  30. public void Create(string shortcutPath, string targetPath)
  31. {
  32. if (string.IsNullOrEmpty(shortcutPath))
  33. {
  34. throw new ArgumentNullException("shortcutPath");
  35. }
  36. if (string.IsNullOrEmpty(targetPath))
  37. {
  38. throw new ArgumentNullException("targetPath");
  39. }
  40. File.WriteAllText(shortcutPath, targetPath);
  41. }
  42. }
  43. }