WindowsAppHost.cs 4.2 KB

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