WindowsAppHost.cs 4.1 KB

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