WindowsAppHost.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.Common.Implementations.IO;
  8. using Emby.Server.CinemaMode;
  9. using Emby.Server.Connect;
  10. using Emby.Server.Core;
  11. using Emby.Server.Implementations;
  12. using Emby.Server.Implementations.EntryPoints;
  13. using Emby.Server.Implementations.FFMpeg;
  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.Model.Updates;
  21. using MediaBrowser.Server.Startup.Common;
  22. using MediaBrowser.ServerApplication.Native;
  23. namespace MediaBrowser.ServerApplication
  24. {
  25. public class WindowsAppHost : ApplicationHost
  26. {
  27. 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, string> certificateGenerator, Func<string> defaultUsernameFactory)
  28. : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory)
  29. {
  30. }
  31. public override bool IsRunningAsService
  32. {
  33. get { return MainStartup.IsRunningAsService; }
  34. }
  35. protected override IConnectManager CreateConnectManager()
  36. {
  37. return new ConnectManager();
  38. }
  39. protected override ISyncManager CreateSyncManager()
  40. {
  41. return new SyncManager();
  42. }
  43. protected override void RestartInternal()
  44. {
  45. MainStartup.Restart();
  46. }
  47. public override void EnableLoopback(string appName)
  48. {
  49. LoopUtil.Run(appName);
  50. }
  51. public override PackageVersionClass SystemUpdateLevel
  52. {
  53. get { return UpdateLevelHelper.GetSystemUpdateLevel(ConfigurationManager); }
  54. }
  55. protected override List<Assembly> GetAssembliesWithPartsInternal()
  56. {
  57. var list = new List<Assembly>();
  58. if (!Environment.Is64BitProcess)
  59. {
  60. //list.Add(typeof(PismoIsoManager).Assembly);
  61. }
  62. list.Add(typeof(DefaultIntroProvider).Assembly);
  63. list.Add(typeof(ConnectManager).Assembly);
  64. list.Add(typeof(SyncManager).Assembly);
  65. list.Add(GetType().Assembly);
  66. return list;
  67. }
  68. protected override void ShutdownInternal()
  69. {
  70. MainStartup.Shutdown();
  71. }
  72. protected override void AuthorizeServer()
  73. {
  74. ServerAuthorization.AuthorizeServer(UdpServerEntryPoint.PortNumber,
  75. ServerConfigurationManager.Configuration.HttpServerPortNumber,
  76. ServerConfigurationManager.Configuration.HttpsPortNumber,
  77. MainStartup.ApplicationPath,
  78. ConfigurationManager.CommonApplicationPaths.TempDirectory);
  79. }
  80. protected override void ConfigureAutoRunInternal(bool autorun)
  81. {
  82. var startupPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
  83. if (autorun && !MainStartup.IsRunningAsService)
  84. {
  85. //Copy our shortut into the startup folder for this user
  86. var targetPath = Path.Combine(startupPath, "Emby Server.lnk");
  87. IShellLinkW link = (IShellLinkW)new ShellLink();
  88. var appPath = Process.GetCurrentProcess().MainModule.FileName;
  89. // setup shortcut information
  90. link.SetDescription(Name);
  91. link.SetPath(appPath);
  92. link.SetWorkingDirectory(Path.GetDirectoryName(appPath));
  93. // save it
  94. IPersistFile file = (IPersistFile)link;
  95. file.Save(targetPath, true);
  96. }
  97. else
  98. {
  99. //Remove our shortcut from the startup folder for this user
  100. FileSystemManager.DeleteFile(Path.Combine(startupPath, "Emby Server.lnk"));
  101. }
  102. }
  103. public override bool SupportsRunningAsService
  104. {
  105. get
  106. {
  107. return true;
  108. }
  109. }
  110. public override bool CanSelfRestart
  111. {
  112. get
  113. {
  114. return MainStartup.CanSelfRestart;
  115. }
  116. }
  117. public override bool CanSelfUpdate
  118. {
  119. get
  120. {
  121. return MainStartup.CanSelfUpdate;
  122. }
  123. }
  124. }
  125. }