MonoAppHost.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Emby.Server.Core;
  5. using Emby.Server.Implementations;
  6. using Emby.Server.Implementations.FFMpeg;
  7. using MediaBrowser.IsoMounter;
  8. using MediaBrowser.Model.IO;
  9. using MediaBrowser.Model.Logging;
  10. using MediaBrowser.Model.System;
  11. namespace MediaBrowser.Server.Mono
  12. {
  13. public class MonoAppHost : ApplicationHost
  14. {
  15. public MonoAppHost(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) : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory)
  16. {
  17. }
  18. public override bool CanSelfRestart
  19. {
  20. get
  21. {
  22. // A restart script must be provided
  23. return StartupOptions.ContainsOption("-restartpath");
  24. }
  25. }
  26. public override bool CanSelfUpdate
  27. {
  28. get
  29. {
  30. return false;
  31. }
  32. }
  33. protected override FFMpegInstallInfo GetFfmpegInstallInfo()
  34. {
  35. var info = new FFMpegInstallInfo();
  36. // Windows builds: http://ffmpeg.zeranoe.com/builds/
  37. // Linux builds: http://johnvansickle.com/ffmpeg/
  38. // OS X builds: http://ffmpegmac.net/
  39. // OS X x64: http://www.evermeet.cx/ffmpeg/
  40. var environment = (MonoEnvironmentInfo) EnvironmentInfo;
  41. if (environment.IsBsd)
  42. {
  43. }
  44. else if (environment.OperatingSystem == Model.System.OperatingSystem.Linux)
  45. {
  46. info.FFMpegFilename = "ffmpeg";
  47. info.FFProbeFilename = "ffprobe";
  48. info.ArchiveType = "7z";
  49. info.Version = "20160215";
  50. info.DownloadUrls = GetDownloadUrls();
  51. }
  52. // No version available - user requirement
  53. info.DownloadUrls = new string[] { };
  54. return info;
  55. }
  56. private string[] GetDownloadUrls()
  57. {
  58. switch (EnvironmentInfo.SystemArchitecture)
  59. {
  60. case Architecture.X64:
  61. return new[]
  62. {
  63. "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-git-20160215-64bit-static.7z"
  64. };
  65. case Architecture.X86:
  66. return new[]
  67. {
  68. "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-git-20160215-32bit-static.7z"
  69. };
  70. }
  71. return new string[] { };
  72. }
  73. protected override void RestartInternal()
  74. {
  75. MainClass.Restart(StartupOptions);
  76. }
  77. protected override List<Assembly> GetAssembliesWithPartsInternal()
  78. {
  79. var list = new List<Assembly>();
  80. list.Add(GetType().Assembly);
  81. list.AddRange(GetLinuxAssemblies());
  82. return list;
  83. }
  84. private IEnumerable<Assembly> GetLinuxAssemblies()
  85. {
  86. var list = new List<Assembly>();
  87. list.Add(typeof(LinuxIsoManager).Assembly);
  88. return list;
  89. }
  90. protected override void ShutdownInternal()
  91. {
  92. MainClass.Shutdown();
  93. }
  94. protected override bool SupportsDualModeSockets
  95. {
  96. get
  97. {
  98. return GetMonoVersion() >= new Version(4, 6);
  99. }
  100. }
  101. private static Version GetMonoVersion()
  102. {
  103. Type type = Type.GetType("Mono.Runtime");
  104. if (type != null)
  105. {
  106. MethodInfo displayName = type.GetTypeInfo().GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
  107. var displayNameValue = displayName.Invoke(null, null).ToString().Trim().Split(' ')[0];
  108. Version version;
  109. if (Version.TryParse(displayNameValue, out version))
  110. {
  111. return version;
  112. }
  113. }
  114. return new Version(1, 0);
  115. }
  116. protected override void AuthorizeServer()
  117. {
  118. throw new NotImplementedException();
  119. }
  120. protected override void ConfigureAutoRunInternal(bool autorun)
  121. {
  122. throw new NotImplementedException();
  123. }
  124. protected override void EnableLoopbackInternal(string appName)
  125. {
  126. }
  127. public override bool SupportsRunningAsService
  128. {
  129. get
  130. {
  131. return false;
  132. }
  133. }
  134. public override bool SupportsAutoRunAtStartup
  135. {
  136. get { return false; }
  137. }
  138. public override bool IsRunningAsService
  139. {
  140. get
  141. {
  142. return false;
  143. }
  144. }
  145. }
  146. }