WindowsAppHost.cs 4.7 KB

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