WindowsAppHost.cs 4.2 KB

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