WindowsAppHost.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. list.Add(typeof(DefaultIntroProvider).Assembly);
  59. list.Add(typeof(ConnectManager).Assembly);
  60. list.Add(typeof(SyncManager).Assembly);
  61. list.Add(GetType().Assembly);
  62. return list;
  63. }
  64. protected override void ShutdownInternal()
  65. {
  66. MainStartup.Shutdown();
  67. }
  68. protected override void AuthorizeServer()
  69. {
  70. ServerAuthorization.AuthorizeServer(UdpServerEntryPoint.PortNumber,
  71. ServerConfigurationManager.Configuration.HttpServerPortNumber,
  72. ServerConfigurationManager.Configuration.HttpsPortNumber,
  73. MainStartup.ApplicationPath,
  74. ConfigurationManager.CommonApplicationPaths.TempDirectory);
  75. }
  76. protected override void ConfigureAutoRunInternal(bool autorun)
  77. {
  78. var startupPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
  79. if (autorun && !MainStartup.IsRunningAsService)
  80. {
  81. //Copy our shortut into the startup folder for this user
  82. var targetPath = Path.Combine(startupPath, "Emby Server.lnk");
  83. IShellLinkW link = (IShellLinkW)new ShellLink();
  84. var appPath = Process.GetCurrentProcess().MainModule.FileName;
  85. // setup shortcut information
  86. link.SetDescription(Name);
  87. link.SetPath(appPath);
  88. link.SetWorkingDirectory(Path.GetDirectoryName(appPath));
  89. // save it
  90. IPersistFile file = (IPersistFile)link;
  91. file.Save(targetPath, true);
  92. }
  93. else
  94. {
  95. //Remove our shortcut from the startup folder for this user
  96. FileSystemManager.DeleteFile(Path.Combine(startupPath, "Emby Server.lnk"));
  97. }
  98. }
  99. public override bool SupportsRunningAsService
  100. {
  101. get
  102. {
  103. return true;
  104. }
  105. }
  106. public override bool CanSelfRestart
  107. {
  108. get
  109. {
  110. return MainStartup.CanSelfRestart;
  111. }
  112. }
  113. public override bool CanSelfUpdate
  114. {
  115. get
  116. {
  117. return MainStartup.CanSelfUpdate;
  118. }
  119. }
  120. }
  121. }