diff options
Diffstat (limited to 'MediaBrowser.Server.Mac/Main.cs')
| -rw-r--r-- | MediaBrowser.Server.Mac/Main.cs | 189 |
1 files changed, 146 insertions, 43 deletions
diff --git a/MediaBrowser.Server.Mac/Main.cs b/MediaBrowser.Server.Mac/Main.cs index b48f44707..cda6f459a 100644 --- a/MediaBrowser.Server.Mac/Main.cs +++ b/MediaBrowser.Server.Mac/Main.cs @@ -1,47 +1,57 @@ -using System; +using MediaBrowser.Model.Logging; +using MediaBrowser.Server.Startup.Common; +using MediaBrowser.Server.Startup.Common.IO; +using MediaBrowser.Server.Implementations; +using System; using System.Diagnostics; -using System.Drawing; +using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Net.Security; using System.Reflection; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Drawing; using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Implementations.IO; -using MediaBrowser.Common.Implementations.Logging; -using MediaBrowser.Model.Logging; -using MediaBrowser.Server.Implementations; -using MediaBrowser.Server.Startup.Common; -using MediaBrowser.Server.Startup.Common.Browser; -using Microsoft.Win32; using MonoMac.AppKit; using MonoMac.Foundation; using MonoMac.ObjCRuntime; -using CommonIO; -using MediaBrowser.Server.Implementations.Logging; +using Emby.Server.Core; +using Emby.Server.Implementations; +using Emby.Common.Implementations.Logging; +using Emby.Common.Implementations.EnvironmentInfo; +using Emby.Server.Mac.Native; +using Emby.Server.Implementations.IO; +using Emby.Common.Implementations.Networking; +using Emby.Common.Implementations.Security; +using Mono.Unix.Native; +using MediaBrowser.Model.System; namespace MediaBrowser.Server.Mac { class MainClass { - internal static ApplicationHost AppHost; + internal static MacAppHost AppHost; private static ILogger _logger; static void Main (string[] args) { - var applicationPath = Assembly.GetEntryAssembly().Location; + SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); - var options = new StartupOptions(); + var applicationPath = Assembly.GetEntryAssembly().Location; + + var options = new StartupOptions(Environment.GetCommandLineArgs()); // Allow this to be specified on the command line. var customProgramDataPath = options.GetOption("-programdata"); - var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath); + var appFolderPath = Path.GetDirectoryName(applicationPath); + + var appPaths = CreateApplicationPaths(appFolderPath, customProgramDataPath); var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Info); @@ -58,7 +68,7 @@ namespace MediaBrowser.Server.Mac NSApplication.Main (args); } - private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, string programDataPath) + private static ServerApplicationPaths CreateApplicationPaths(string appFolderPath, string programDataPath) { if (string.IsNullOrEmpty(programDataPath)) { @@ -71,9 +81,9 @@ namespace MediaBrowser.Server.Mac } // Within the mac bundle, go uo two levels then down into Resources folder - var resourcesPath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName (applicationPath)), "Resources"); + var resourcesPath = Path.Combine(Path.GetDirectoryName(appFolderPath), "Resources"); - return new ServerApplicationPaths(programDataPath, applicationPath, resourcesPath); + return new ServerApplicationPaths(programDataPath, appFolderPath, resourcesPath); } /// <summary> @@ -86,17 +96,34 @@ namespace MediaBrowser.Server.Mac ILogManager logManager, StartupOptions options) { - SystemEvents.SessionEnding += SystemEvents_SessionEnding; - // Allow all https requests ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; }); - var fileSystem = new ManagedFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")), false, true); + var fileSystem = new MonoFileSystem(logManager.GetLogger("FileSystem"), false, false); fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem)); - var nativeApp = new NativeApp(logManager.GetLogger("App")); - - AppHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "Emby.Server.Mac.pkg", nativeApp); + var environmentInfo = GetEnvironmentInfo(); + + var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, + logManager, + fileSystem, + options, + () => AppHost.HttpClient, + appPaths); + + AppHost = new MacAppHost(appPaths, + logManager, + options, + fileSystem, + new PowerManagement(), + "Emby.Server.Mac.pkg", + environmentInfo, + imageEncoder, + new Startup.Common.SystemEvents(logManager.GetLogger("SystemEvents")), + new MemoryStreamProvider(), + new NetworkManager(logManager.GetLogger("NetworkManager")), + GenerateCertificate, + () => Environment.UserName); if (options.ContainsOption("-v")) { Console.WriteLine (AppHost.ApplicationVersion.ToString()); @@ -106,9 +133,95 @@ namespace MediaBrowser.Server.Mac Console.WriteLine ("appHost.Init"); Task.Run (() => StartServer(CancellationToken.None)); - } + } + + private static void GenerateCertificate(string certPath, string certHost) + { + CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, _logger); + } + + private static EnvironmentInfo GetEnvironmentInfo() + { + var info = new EnvironmentInfo(); + + 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; + } - private static async void StartServer(CancellationToken cancellationToken) + private static async void StartServer(CancellationToken cancellationToken) { var initProgress = new Progress<double>(); @@ -122,19 +235,6 @@ namespace MediaBrowser.Server.Mac } } - /// <summary> - /// Handles the SessionEnding event of the SystemEvents control. - /// </summary> - /// <param name="sender">The source of the event.</param> - /// <param name="e">The <see cref="SessionEndingEventArgs"/> instance containing the event data.</param> - static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e) - { - if (e.Reason == SessionEndReasons.SystemShutdown) - { - Shutdown(); - } - } - public static void Shutdown() { ShutdownApp(); @@ -202,10 +302,13 @@ namespace MediaBrowser.Server.Mac class NoCheckCertificatePolicy : ICertificatePolicy { - public bool CheckValidationResult (ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) + public bool CheckValidationResult (ServicePoint srvPoint, + System.Security.Cryptography.X509Certificates.X509Certificate certificate, + WebRequest request, + int certificateProblem) { return true; } - } + } } |
