Autorun.cs 1.8 KB

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