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