StartupWizard.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Controller.Plugins;
  5. using MediaBrowser.Model.Logging;
  6. using System;
  7. using System.Linq;
  8. using System.Windows.Forms;
  9. using MediaBrowser.ServerApplication.Native;
  10. namespace MediaBrowser.ServerApplication.EntryPoints
  11. {
  12. /// <summary>
  13. /// Class StartupWizard
  14. /// </summary>
  15. public class StartupWizard : IServerEntryPoint
  16. {
  17. /// <summary>
  18. /// The _app host
  19. /// </summary>
  20. private readonly IServerApplicationHost _appHost;
  21. /// <summary>
  22. /// The _user manager
  23. /// </summary>
  24. private readonly IUserManager _userManager;
  25. private readonly ILogger _logger;
  26. private readonly IServerConfigurationManager _configurationManager;
  27. /// <summary>
  28. /// Initializes a new instance of the <see cref="StartupWizard" /> class.
  29. /// </summary>
  30. /// <param name="appHost">The app host.</param>
  31. /// <param name="userManager">The user manager.</param>
  32. public StartupWizard(IServerApplicationHost appHost, IUserManager userManager, IServerConfigurationManager configurationManager, ILogger logger)
  33. {
  34. _appHost = appHost;
  35. _logger = logger;
  36. _userManager = userManager;
  37. _configurationManager = configurationManager;
  38. }
  39. /// <summary>
  40. /// Runs this instance.
  41. /// </summary>
  42. public void Run()
  43. {
  44. if (_appHost.IsFirstRun)
  45. {
  46. LaunchStartupWizard();
  47. }
  48. }
  49. /// <summary>
  50. /// Launches the startup wizard.
  51. /// </summary>
  52. private void LaunchStartupWizard()
  53. {
  54. var user = _userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
  55. try
  56. {
  57. BrowserLauncher.OpenDashboardPage("wizardstart.html", user, _configurationManager, _appHost, _logger);
  58. }
  59. catch (Exception ex)
  60. {
  61. _logger.ErrorException("Error launching startup wizard", ex);
  62. MessageBox.Show("There was an error launching the Media Browser startup wizard. Please ensure a web browser is installed on the machine and is configured as the default browser.", "Media Browser");
  63. }
  64. }
  65. /// <summary>
  66. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  67. /// </summary>
  68. public void Dispose()
  69. {
  70. }
  71. }
  72. }