Autorun.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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. var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
  20. if (autorun)
  21. {
  22. //Copy our shortut into the startup folder for this user
  23. File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk"), true);
  24. }
  25. else
  26. {
  27. //Remove our shortcut from the startup folder for this user
  28. fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk"));
  29. }
  30. }
  31. }
  32. }