WindowsAppHost.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Runtime.InteropServices.ComTypes;
  7. using Emby.Server.CinemaMode;
  8. using Emby.Server.Connect;
  9. using Emby.Server.Core;
  10. using Emby.Server.Implementations;
  11. using Emby.Server.Implementations.EntryPoints;
  12. using Emby.Server.Implementations.FFMpeg;
  13. using Emby.Server.Implementations.Windows;
  14. using Emby.Server.Sync;
  15. using MediaBrowser.Controller.Connect;
  16. using MediaBrowser.Controller.Sync;
  17. using MediaBrowser.Model.IO;
  18. using MediaBrowser.Model.Logging;
  19. using MediaBrowser.Model.System;
  20. using MediaBrowser.ServerApplication.Native;
  21. namespace MediaBrowser.ServerApplication
  22. {
  23. public class WindowsAppHost : ApplicationHost
  24. {
  25. public WindowsAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, IMemoryStreamFactory memoryStreamFactory, MediaBrowser.Common.Net.INetworkManager networkManager, Action<string, string> certificateGenerator, Func<string> defaultUsernameFactory)
  26. : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory)
  27. {
  28. }
  29. public override bool IsRunningAsService
  30. {
  31. get { return MainStartup.IsRunningAsService; }
  32. }
  33. protected override IConnectManager CreateConnectManager()
  34. {
  35. return new ConnectManager();
  36. }
  37. protected override ISyncManager CreateSyncManager()
  38. {
  39. return new SyncManager();
  40. }
  41. protected override void RestartInternal()
  42. {
  43. MainStartup.Restart();
  44. }
  45. protected override List<Assembly> GetAssembliesWithPartsInternal()
  46. {
  47. var list = new List<Assembly>();
  48. if (!Environment.Is64BitProcess)
  49. {
  50. //list.Add(typeof(PismoIsoManager).Assembly);
  51. }
  52. list.Add(typeof(DefaultIntroProvider).Assembly);
  53. list.Add(typeof(ConnectManager).Assembly);
  54. list.Add(typeof(SyncManager).Assembly);
  55. list.Add(GetType().Assembly);
  56. return list;
  57. }
  58. protected override void ShutdownInternal()
  59. {
  60. MainStartup.Shutdown();
  61. }
  62. protected override void AuthorizeServer()
  63. {
  64. ServerAuthorization.AuthorizeServer(UdpServerEntryPoint.PortNumber,
  65. ServerConfigurationManager.Configuration.HttpServerPortNumber,
  66. ServerConfigurationManager.Configuration.HttpsPortNumber,
  67. MainStartup.ApplicationPath,
  68. ConfigurationManager.CommonApplicationPaths.TempDirectory);
  69. }
  70. protected override void ConfigureAutoRunInternal(bool autorun)
  71. {
  72. var startupPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
  73. if (autorun && !MainStartup.IsRunningAsService)
  74. {
  75. //Copy our shortut into the startup folder for this user
  76. var targetPath = Path.Combine(startupPath, "Emby Server.lnk");
  77. IShellLinkW link = (IShellLinkW)new ShellLink();
  78. var appPath = Process.GetCurrentProcess().MainModule.FileName;
  79. // setup shortcut information
  80. link.SetDescription(Name);
  81. link.SetPath(appPath);
  82. link.SetWorkingDirectory(Path.GetDirectoryName(appPath));
  83. // save it
  84. IPersistFile file = (IPersistFile)link;
  85. file.Save(targetPath, true);
  86. }
  87. else
  88. {
  89. //Remove our shortcut from the startup folder for this user
  90. FileSystemManager.DeleteFile(Path.Combine(startupPath, "Emby Server.lnk"));
  91. }
  92. }
  93. public override bool SupportsRunningAsService
  94. {
  95. get
  96. {
  97. return true;
  98. }
  99. }
  100. public override bool CanSelfRestart
  101. {
  102. get
  103. {
  104. return MainStartup.CanSelfRestart;
  105. }
  106. }
  107. public override bool CanSelfUpdate
  108. {
  109. get
  110. {
  111. return MainStartup.CanSelfUpdate;
  112. }
  113. }
  114. }
  115. }