Autorun.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using MediaBrowser.Common.IO;
  2. using System;
  3. using System.IO;
  4. using CommonIO;
  5. namespace MediaBrowser.ServerApplication.Native
  6. {
  7. /// <summary>
  8. /// Class Autorun
  9. /// </summary>
  10. public static class Autorun
  11. {
  12. /// <summary>
  13. /// Configures the specified autorun.
  14. /// </summary>
  15. /// <param name="autorun">if set to <c>true</c> [autorun].</param>
  16. /// <param name="fileSystem">The file system.</param>
  17. public static void Configure(bool autorun, IFileSystem fileSystem)
  18. {
  19. var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk");
  20. if (!Directory.Exists(Path.GetDirectoryName(shortcutPath)))
  21. {
  22. shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
  23. }
  24. var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
  25. // Remove lnk from old name
  26. try
  27. {
  28. fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Media Browser Server.lnk"));
  29. }
  30. catch
  31. {
  32. }
  33. if (autorun)
  34. {
  35. //Copy our shortut into the startup folder for this user
  36. File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"), true);
  37. }
  38. else
  39. {
  40. //Remove our shortcut from the startup folder for this user
  41. fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
  42. }
  43. }
  44. }
  45. }