diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-11 03:13:11 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-11 03:13:11 -0500 |
| commit | 918b9ca86d1bdb9758430e9164f5fba72de1d9a7 (patch) | |
| tree | 1f9ec909d18593a8f69a6dbbf7af580ad25005a5 /MediaBrowser.Server.Mono/Program.cs | |
| parent | f8dd02bb66d2f243515d295b4d256a4c74f433ca (diff) | |
update core projects
Diffstat (limited to 'MediaBrowser.Server.Mono/Program.cs')
| -rw-r--r-- | MediaBrowser.Server.Mono/Program.cs | 98 |
1 files changed, 96 insertions, 2 deletions
diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs index 7d687bb54..7c77f67ed 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; + } + /// <summary> /// Handles the SessionEnding event of the SystemEvents control. /// </summary> @@ -192,4 +281,9 @@ namespace MediaBrowser.Server.Mono return true; } } + + public class MonoEnvironmentInfo : EnvironmentInfo + { + public bool IsBsd { get; set; } + } } |
