WindowsAppHost.cs 4.6 KB

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