From 918b9ca86d1bdb9758430e9164f5fba72de1d9a7 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 11 Nov 2016 03:13:11 -0500 Subject: [PATCH] update core projects --- .../BaseApplicationHost.cs | 7 +- .../EnvironmentInfo/EnvironmentInfo.cs | 29 ++++ .../INativeApp.cs | 18 +- .../IServerApplicationHost.cs | 6 - MediaBrowser.Model/System/Architecture.cs | 3 +- MediaBrowser.Model/System/IEnvironmentInfo.cs | 1 + MediaBrowser.Server.Mono/Native/MonoApp.cs | 162 +++--------------- MediaBrowser.Server.Mono/Program.cs | 98 ++++++++++- .../ApplicationHost.cs | 21 +-- .../MediaBrowser.Server.Startup.Common.csproj | 2 - .../NativeEnvironment.cs | 19 -- MediaBrowser.ServerApplication/MainStartup.cs | 4 +- .../Native/WindowsApp.cs | 15 -- 13 files changed, 168 insertions(+), 217 deletions(-) rename {MediaBrowser.Server.Startup.Common => Emby.Server.Core}/INativeApp.cs (78%) delete mode 100644 MediaBrowser.Server.Startup.Common/NativeEnvironment.cs diff --git a/Emby.Common.Implementations/BaseApplicationHost.cs b/Emby.Common.Implementations/BaseApplicationHost.cs index 0cf11e8255..9571ea3889 100644 --- a/Emby.Common.Implementations/BaseApplicationHost.cs +++ b/Emby.Common.Implementations/BaseApplicationHost.cs @@ -172,7 +172,7 @@ namespace Emby.Common.Implementations protected ICryptoProvider CryptographyProvider = new CryptographyProvider(); - protected IEnvironmentInfo EnvironmentInfo = new Emby.Common.Implementations.EnvironmentInfo.EnvironmentInfo(); + protected IEnvironmentInfo EnvironmentInfo { get; private set; } private DeviceId _deviceId; public string SystemId @@ -205,8 +205,11 @@ namespace Emby.Common.Implementations /// protected BaseApplicationHost(TApplicationPathsType applicationPaths, ILogManager logManager, - IFileSystem fileSystem) + IFileSystem fileSystem, + IEnvironmentInfo environmentInfo) { + EnvironmentInfo = environmentInfo; + // hack alert, until common can target .net core BaseExtensions.CryptographyProvider = CryptographyProvider; diff --git a/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs index 8cea617eae..6a1b3ef74c 100644 --- a/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs +++ b/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs @@ -9,6 +9,8 @@ namespace Emby.Common.Implementations.EnvironmentInfo { public class EnvironmentInfo : IEnvironmentInfo { + public MediaBrowser.Model.System.Architecture? CustomArchitecture { get; set; } + public MediaBrowser.Model.System.OperatingSystem OperatingSystem { get @@ -66,5 +68,32 @@ namespace Emby.Common.Implementations.EnvironmentInfo return "1.0"; } } + + public MediaBrowser.Model.System.Architecture SystemArchitecture + { + get + { + if (CustomArchitecture.HasValue) + { + return CustomArchitecture.Value; + } +#if NET46 + return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86; +#elif NETSTANDARD1_6 + switch(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture) + { + case System.Runtime.InteropServices.Architecture.Arm: + return MediaBrowser.Model.System.Architecture.Arm; + case System.Runtime.InteropServices.Architecture.Arm64: + return MediaBrowser.Model.System.Architecture.Arm64; + case System.Runtime.InteropServices.Architecture.X64: + return MediaBrowser.Model.System.Architecture.X64; + case System.Runtime.InteropServices.Architecture.X86: + return MediaBrowser.Model.System.Architecture.X86; + } +#endif + return MediaBrowser.Model.System.Architecture.X64; + } + } } } diff --git a/MediaBrowser.Server.Startup.Common/INativeApp.cs b/Emby.Server.Core/INativeApp.cs similarity index 78% rename from MediaBrowser.Server.Startup.Common/INativeApp.cs rename to Emby.Server.Core/INativeApp.cs index 182afbf003..a79d1f02b8 100644 --- a/MediaBrowser.Server.Startup.Common/INativeApp.cs +++ b/Emby.Server.Core/INativeApp.cs @@ -6,7 +6,7 @@ using Emby.Server.Core; using Emby.Server.Core.Data; using Emby.Server.Core.FFMpeg; -namespace MediaBrowser.Server.Startup.Common +namespace Emby.Server.Core { public interface INativeApp { @@ -19,18 +19,8 @@ namespace MediaBrowser.Server.Startup.Common /// /// Authorizes the server. /// - /// The UDP port. - /// The HTTP server port. - /// The HTTPS server port. - /// The temporary directory. void AuthorizeServer(int udpPort, int httpServerPort, int httpsServerPort, string applicationPath, string tempDirectory); - /// - /// Gets the environment. - /// - /// The environment. - NativeEnvironment Environment { get; } - /// /// Gets a value indicating whether [supports running as service]. /// @@ -54,12 +44,6 @@ namespace MediaBrowser.Server.Startup.Common /// /// true if [supports autorun at startup]; otherwise, false. bool SupportsAutoRunAtStartup { get; } - - /// - /// Gets a value indicating whether [supports library monitor]. - /// - /// true if [supports library monitor]; otherwise, false. - bool SupportsLibraryMonitor { get; } /// /// Gets a value indicating whether this instance can self update. diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs index d2cf23f43f..44c0031974 100644 --- a/MediaBrowser.Controller/IServerApplicationHost.cs +++ b/MediaBrowser.Controller/IServerApplicationHost.cs @@ -26,12 +26,6 @@ namespace MediaBrowser.Controller /// /// true if [supports automatic run at startup]; otherwise, false. bool SupportsAutoRunAtStartup { get; } - - /// - /// Gets a value indicating whether [supports library monitor]. - /// - /// true if [supports library monitor]; otherwise, false. - bool SupportsLibraryMonitor { get; } /// /// Gets the HTTP server port. diff --git a/MediaBrowser.Model/System/Architecture.cs b/MediaBrowser.Model/System/Architecture.cs index 09eedddc13..73f78cd582 100644 --- a/MediaBrowser.Model/System/Architecture.cs +++ b/MediaBrowser.Model/System/Architecture.cs @@ -4,6 +4,7 @@ { X86 = 0, X64 = 1, - Arm = 2 + Arm = 2, + Arm64 = 3 } } diff --git a/MediaBrowser.Model/System/IEnvironmentInfo.cs b/MediaBrowser.Model/System/IEnvironmentInfo.cs index 3fcacb30d4..c5f493e7c9 100644 --- a/MediaBrowser.Model/System/IEnvironmentInfo.cs +++ b/MediaBrowser.Model/System/IEnvironmentInfo.cs @@ -11,6 +11,7 @@ namespace MediaBrowser.Model.System MediaBrowser.Model.System.OperatingSystem OperatingSystem { get; } string OperatingSystemName { get; } string OperatingSystemVersion { get; } + Architecture SystemArchitecture { get; } } public enum OperatingSystem diff --git a/MediaBrowser.Server.Mono/Native/MonoApp.cs b/MediaBrowser.Server.Mono/Native/MonoApp.cs index 6e7a677aee..8257a1b8df 100644 --- a/MediaBrowser.Server.Mono/Native/MonoApp.cs +++ b/MediaBrowser.Server.Mono/Native/MonoApp.cs @@ -12,7 +12,6 @@ using Emby.Server.Core; using Emby.Server.Core.Data; using Emby.Server.Core.FFMpeg; using MediaBrowser.Model.System; -using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem; namespace MediaBrowser.Server.Mono.Native { @@ -20,11 +19,13 @@ namespace MediaBrowser.Server.Mono.Native { protected StartupOptions StartupOptions { get; private set; } protected ILogger Logger { get; private set; } + private readonly MonoEnvironmentInfo _environment; - public MonoApp(StartupOptions startupOptions, ILogger logger) + public MonoApp(StartupOptions startupOptions, ILogger logger, MonoEnvironmentInfo environment) { StartupOptions = startupOptions; Logger = logger; + _environment = environment; } /// @@ -77,11 +78,6 @@ namespace MediaBrowser.Server.Mono.Native { var list = new List(); - if (Environment.OperatingSystem == Startup.Common.OperatingSystem.Linux) - { - list.AddRange(GetLinuxAssemblies()); - } - list.Add(GetType().Assembly); return list; @@ -91,7 +87,7 @@ namespace MediaBrowser.Server.Mono.Native { var list = new List(); - list.Add(typeof(LinuxIsoManager).Assembly); + //list.Add(typeof(LinuxIsoManager).Assembly); return list; } @@ -100,12 +96,6 @@ namespace MediaBrowser.Server.Mono.Native { } - private NativeEnvironment _nativeEnvironment; - public NativeEnvironment Environment - { - get { return _nativeEnvironment ?? (_nativeEnvironment = GetEnvironmentInfo()); } - } - public bool SupportsRunningAsService { get @@ -122,14 +112,6 @@ namespace MediaBrowser.Server.Mono.Native } } - public bool SupportsLibraryMonitor - { - get - { - return Environment.OperatingSystem != Startup.Common.OperatingSystem.Osx; - } - } - public void ConfigureAutoRun(bool autorun) { } @@ -139,96 +121,29 @@ namespace MediaBrowser.Server.Mono.Native return new NetworkManager(logger); } - private NativeEnvironment GetEnvironmentInfo() - { - var info = new NativeEnvironment - { - OperatingSystem = Startup.Common.OperatingSystem.Linux - }; - - var uname = GetUnixName(); - - var sysName = uname.sysname ?? string.Empty; - - if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase)) - { - info.OperatingSystem = Startup.Common.OperatingSystem.Osx; - } - else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase)) - { - info.OperatingSystem = Startup.Common.OperatingSystem.Linux; - } - else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase)) - { - info.OperatingSystem = Startup.Common.OperatingSystem.Bsd; - } - - var archX86 = new Regex("(i|I)[3-6]86"); - - if (archX86.IsMatch(uname.machine)) - { - info.SystemArchitecture = Architecture.X86; - } - else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase)) - { - info.SystemArchitecture = Architecture.X64; - } - else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase)) - { - info.SystemArchitecture = Architecture.Arm; - } - else if (System.Environment.Is64BitOperatingSystem) - { - info.SystemArchitecture = Architecture.X64; - } - else - { - info.SystemArchitecture = Architecture.X86; - } - - info.OperatingSystemVersionString = string.IsNullOrWhiteSpace(sysName) ? - System.Environment.OSVersion.VersionString : - sysName; - - return info; - } - - private Uname _unixName; - - private Uname GetUnixName() - { - if (_unixName == null) - { - var uname = new Uname(); - try - { - Utsname utsname; - var callResult = Syscall.uname(out utsname); - if (callResult == 0) - { - uname.sysname = utsname.sysname ?? string.Empty; - uname.machine = utsname.machine ?? string.Empty; - } - - } - catch (Exception ex) - { - Logger.ErrorException("Error getting unix name", ex); - } - _unixName = uname; - } - return _unixName; - } - - public class Uname - { - public string sysname = string.Empty; - public string machine = string.Empty; - } - public FFMpegInstallInfo GetFfmpegInstallInfo() { - return GetInfo(Environment); + var info = new FFMpegInstallInfo(); + + // Windows builds: http://ffmpeg.zeranoe.com/builds/ + // Linux builds: http://johnvansickle.com/ffmpeg/ + // OS X builds: http://ffmpegmac.net/ + // OS X x64: http://www.evermeet.cx/ffmpeg/ + + if (_environment.IsBsd) + { + + } + else if (_environment.OperatingSystem == Model.System.OperatingSystem.Linux) + { + info.ArchiveType = "7z"; + info.Version = "20160215"; + } + + // No version available - user requirement + info.DownloadUrls = new string[] { }; + + return info; } public void LaunchUrl(string url) @@ -241,33 +156,6 @@ namespace MediaBrowser.Server.Mono.Native return new DbConnector(Logger); } - public static FFMpegInstallInfo GetInfo(NativeEnvironment environment) - { - var info = new FFMpegInstallInfo(); - - // Windows builds: http://ffmpeg.zeranoe.com/builds/ - // Linux builds: http://johnvansickle.com/ffmpeg/ - // OS X builds: http://ffmpegmac.net/ - // OS X x64: http://www.evermeet.cx/ffmpeg/ - - switch (environment.OperatingSystem) - { - case OperatingSystem.Osx: - case OperatingSystem.Bsd: - break; - case OperatingSystem.Linux: - - info.ArchiveType = "7z"; - info.Version = "20160215"; - break; - } - - // No version available - user requirement - info.DownloadUrls = new string[] { }; - - return info; - } - public void EnableLoopback(string appName) { diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index 7d687bb545..7c77f67ed6 100644 --- a/MediaBrowser.Server.Mono/Program.cs +++ b/MediaBrowser.Server.Mono/Program.cs @@ -11,11 +11,17 @@ using System.Net; using System.Net.Security; using System.Reflection; using System.Security.Cryptography.X509Certificates; +using System.Text.RegularExpressions; using System.Threading.Tasks; +using Emby.Common.Implementations.EnvironmentInfo; using Emby.Common.Implementations.IO; using Emby.Common.Implementations.Logging; using Emby.Server.Core; using Emby.Server.Implementations.IO; +using MediaBrowser.Model.System; +using Mono.Unix.Native; +using NLog; +using ILogger = MediaBrowser.Model.Logging.ILogger; namespace MediaBrowser.Server.Mono { @@ -80,9 +86,11 @@ namespace MediaBrowser.Server.Mono var fileSystem = new MonoFileSystem(logManager.GetLogger("FileSystem"), false, false); fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem)); - var nativeApp = new MonoApp(options, logManager.GetLogger("App")); + var environmentInfo = GetEnvironmentInfo(); - _appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, nativeApp, new PowerManagement(), "emby.mono.zip"); + var nativeApp = new MonoApp(options, logManager.GetLogger("App"), environmentInfo); + + _appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, nativeApp, new PowerManagement(), "emby.mono.zip", environmentInfo); if (options.ContainsOption("-v")) { @@ -107,6 +115,87 @@ namespace MediaBrowser.Server.Mono Task.WaitAll(task); } + private static MonoEnvironmentInfo GetEnvironmentInfo() + { + var info = new MonoEnvironmentInfo(); + + var uname = GetUnixName(); + + var sysName = uname.sysname ?? string.Empty; + + if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase)) + { + //info.OperatingSystem = Startup.Common.OperatingSystem.Osx; + } + else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase)) + { + //info.OperatingSystem = Startup.Common.OperatingSystem.Linux; + } + else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase)) + { + //info.OperatingSystem = Startup.Common.OperatingSystem.Bsd; + info.IsBsd = true; + } + + var archX86 = new Regex("(i|I)[3-6]86"); + + if (archX86.IsMatch(uname.machine)) + { + info.CustomArchitecture = Architecture.X86; + } + else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase)) + { + info.CustomArchitecture = Architecture.X64; + } + else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase)) + { + info.CustomArchitecture = Architecture.Arm; + } + else if (System.Environment.Is64BitOperatingSystem) + { + info.CustomArchitecture = Architecture.X64; + } + else + { + info.CustomArchitecture = Architecture.X86; + } + + return info; + } + + private static Uname _unixName; + + private static Uname GetUnixName() + { + if (_unixName == null) + { + var uname = new Uname(); + try + { + Utsname utsname; + var callResult = Syscall.uname(out utsname); + if (callResult == 0) + { + uname.sysname = utsname.sysname ?? string.Empty; + uname.machine = utsname.machine ?? string.Empty; + } + + } + catch (Exception ex) + { + _logger.ErrorException("Error getting unix name", ex); + } + _unixName = uname; + } + return _unixName; + } + + public class Uname + { + public string sysname = string.Empty; + public string machine = string.Empty; + } + /// /// Handles the SessionEnding event of the SystemEvents control. /// @@ -192,4 +281,9 @@ namespace MediaBrowser.Server.Mono return true; } } + + public class MonoEnvironmentInfo : EnvironmentInfo + { + public bool IsBsd { get; set; } + } } diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index f427f9f567..87bbc48dbd 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -277,8 +277,9 @@ namespace MediaBrowser.Server.Startup.Common IFileSystem fileSystem, INativeApp nativeApp, IPowerManagement powerManagement, - string releaseAssetFilename) - : base(applicationPaths, logManager, fileSystem) + string releaseAssetFilename, + IEnvironmentInfo environmentInfo) + : base(applicationPaths, logManager, fileSystem, environmentInfo) { _startupOptions = options; _releaseAssetFilename = releaseAssetFilename; @@ -301,11 +302,6 @@ namespace MediaBrowser.Server.Startup.Common } } - public override string OperatingSystemDisplayName - { - get { return NativeApp.Environment.OperatingSystemVersionString; } - } - public override bool IsRunningAsService { get { return NativeApp.IsRunningAsService; } @@ -316,11 +312,6 @@ namespace MediaBrowser.Server.Startup.Common get { return NativeApp.SupportsRunningAsService; } } - public bool SupportsLibraryMonitor - { - get { return NativeApp.SupportsLibraryMonitor; } - } - /// /// Gets the name. /// @@ -1300,7 +1291,7 @@ namespace MediaBrowser.Server.Startup.Common HttpServerPortNumber = HttpPort, SupportsHttps = SupportsHttps, HttpsPortNumber = HttpsPort, - OperatingSystem = NativeApp.Environment.OperatingSystem.ToString(), + OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(), OperatingSystemDisplayName = OperatingSystemDisplayName, CanSelfRestart = CanSelfRestart, CanSelfUpdate = CanSelfUpdate, @@ -1312,9 +1303,9 @@ namespace MediaBrowser.Server.Startup.Common SupportsRunningAsService = SupportsRunningAsService, ServerName = FriendlyName, LocalAddress = localAddress, - SupportsLibraryMonitor = SupportsLibraryMonitor, + SupportsLibraryMonitor = true, EncoderLocationType = MediaEncoder.EncoderLocationType, - SystemArchitecture = NativeApp.Environment.SystemArchitecture, + SystemArchitecture = EnvironmentInfo.SystemArchitecture, SystemUpdateLevel = ConfigurationManager.CommonConfiguration.SystemUpdateLevel, PackageName = _startupOptions.GetOption("-package") }; diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 3b391b236c..ff7456977b 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -114,7 +114,6 @@ - @@ -138,7 +137,6 @@ - diff --git a/MediaBrowser.Server.Startup.Common/NativeEnvironment.cs b/MediaBrowser.Server.Startup.Common/NativeEnvironment.cs deleted file mode 100644 index b30509982e..0000000000 --- a/MediaBrowser.Server.Startup.Common/NativeEnvironment.cs +++ /dev/null @@ -1,19 +0,0 @@ -using MediaBrowser.Model.System; - -namespace MediaBrowser.Server.Startup.Common -{ - public class NativeEnvironment - { - public OperatingSystem OperatingSystem { get; set; } - public Architecture SystemArchitecture { get; set; } - public string OperatingSystemVersionString { get; set; } - } - - public enum OperatingSystem - { - Windows = 0, - Osx = 1, - Bsd = 2, - Linux = 3 - } -} diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index f2967e14a0..adfc0a5886 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -17,6 +17,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using Emby.Common.Implementations.EnvironmentInfo; using Emby.Common.Implementations.IO; using Emby.Common.Implementations.Logging; using Emby.Server.Core; @@ -324,7 +325,8 @@ namespace MediaBrowser.ServerApplication fileSystem, nativeApp, new PowerManagement(), - "emby.windows.zip"); + "emby.windows.zip", + new EnvironmentInfo()); var initProgress = new Progress(); diff --git a/MediaBrowser.ServerApplication/Native/WindowsApp.cs b/MediaBrowser.ServerApplication/Native/WindowsApp.cs index d0f8239fec..babe952d6d 100644 --- a/MediaBrowser.ServerApplication/Native/WindowsApp.cs +++ b/MediaBrowser.ServerApplication/Native/WindowsApp.cs @@ -14,8 +14,6 @@ using Emby.Server.Core.FFMpeg; using MediaBrowser.Common.IO; using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; -using MediaBrowser.Model.System; -using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem; namespace MediaBrowser.ServerApplication.Native { @@ -49,19 +47,6 @@ namespace MediaBrowser.ServerApplication.Native ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsPort, applicationPath, tempDirectory); } - public NativeEnvironment Environment - { - get - { - return new NativeEnvironment - { - OperatingSystem = OperatingSystem.Windows, - SystemArchitecture = System.Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86, - OperatingSystemVersionString = System.Environment.OSVersion.VersionString - }; - } - } - public bool SupportsLibraryMonitor { get { return true; }