WindowsAppHost.cs 4.3 KB

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