Пример #1
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        /// <param name="options">The options.</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
        {
            var fileSystem = new WindowsFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")));

            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            var nativeApp = new WindowsApp(fileSystem)
            {
                IsRunningAsService = runService
            };

            _appHost = new ApplicationHost(appPaths,
                                           logManager,
                                           options,
                                           fileSystem,
                                           "emby.windows.zip",
                                           nativeApp);

            var initProgress = new Progress <double>();

            if (!runService)
            {
                if (!options.ContainsOption("-nosplash"))
                {
                    ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));
                }

                // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                             ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
            }


            var task = _appHost.Init(initProgress);

            task = task.ContinueWith(new Action <Task>(a => _appHost.RunStartupTasks()));

            if (runService)
            {
                StartService(logManager);
            }
            else
            {
                Task.WaitAll(task);

                task = InstallVcredistIfNeeded(_appHost, _logger);
                Task.WaitAll(task);

                SystemEvents.SessionEnding += SystemEvents_SessionEnding;
                SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

                HideSplashScreen();

                ShowTrayIcon();

                task = ApplicationTaskCompletionSource.Task;
                Task.WaitAll(task);
            }
        }
Пример #2
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        /// <param name="options">The options.</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
        {
            var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), true, true, true, appPaths.TempDirectory);
            fileSystem.AddShortcutHandler(new LnkShortcutHandler());
            fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));

            var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths);

            _appHost = new WindowsAppHost(appPaths,
                logManager,
                options,
                fileSystem,
                new PowerManagement(),
                "emby.windows.zip",
                new EnvironmentInfo(),
                imageEncoder,
                new Server.Startup.Common.SystemEvents(logManager.GetLogger("SystemEvents")),
                new RecyclableMemoryStreamProvider(),
                new Networking.NetworkManager(logManager.GetLogger("NetworkManager")),
                GenerateCertificate,
                () => Environment.UserDomainName);

            var initProgress = new Progress<double>();

            if (!runService)
            {
                if (!options.ContainsOption("-nosplash")) ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));

                // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                             ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
            }

            var task = _appHost.Init(initProgress);
            Task.WaitAll(task);

            task = task.ContinueWith(new Action<Task>(a => _appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);

            if (runService)
            {
                StartService(logManager);
            }
            else
            {
                Task.WaitAll(task);

                task = InstallVcredist2013IfNeeded(_appHost, _logger);
                Task.WaitAll(task);

                Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

                HideSplashScreen();

                ShowTrayIcon();

                task = ApplicationTaskCompletionSource.Task;
                Task.WaitAll(task);
            }
        }
Пример #3
0
 private static void ShowTrayIcon(ApplicationHost appHost)
 {
     //Application.EnableVisualStyles();
     //Application.SetCompatibleTextRenderingDefault(false);
     _serverNotifyIcon  = new ServerNotifyIcon(appHost.LogManager, appHost, appHost.ServerConfigurationManager, appHost.LocalizationManager);
     _mainTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
     Application.Run();
 }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="App" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        public App(ApplicationHost appHost, ILogger logger, bool isRunningAsService)
        {
            _appHost           = appHost;
            _logger            = logger;
            IsRunningAsService = isRunningAsService;

            InitializeComponent();
        }
Пример #5
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        /// <param name="options">The options.</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
        {
            var fileSystem = new NativeFileSystem(logManager.GetLogger("FileSystem"), false);

            _appHost = new ApplicationHost(appPaths,
                logManager,
                true,
                runService,
                options,
                fileSystem,
                "MBServer",
                true);

            var initProgress = new Progress<double>();

            if (!runService)
            {
                ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));

                // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                             ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
            }

            var task = _appHost.Init(initProgress);
            task = task.ContinueWith(new Action<Task>(a => _appHost.RunStartupTasks()));

            if (runService)
            {
                StartService(logManager);
            }
            else
            {
                Task.WaitAll(task);

                SystemEvents.SessionEnding += SystemEvents_SessionEnding;
                SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

                HideSplashScreen();

                ShowTrayIcon();

                task = ApplicationTaskCompletionSource.Task;
                Task.WaitAll(task);
            }
        }
Пример #6
0
        private static async Task InstallVcredistIfNeeded(ApplicationHost appHost, ILogger logger)
        {
            try
            {
                var version = ImageMagickEncoder.GetVersion();
                return;
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error loading ImageMagick", ex);
            }

            try
            {
                await InstallVcredist().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error installing Visual Studio C++ runtime", ex);
            }
        }
Пример #7
0
        private static async Task InstallVcredist2015IfNeeded(ApplicationHost appHost, ILogger logger)
        {
            // Reference
            // http://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed

            try
            {
                var subkey = Environment.Is64BitProcess
                    ? "SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64"
                    : "SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x86";

                using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)
                                            .OpenSubKey(subkey))
                {
                    if (ndpKey != null && ndpKey.GetValue("Version") != null)
                    {
                        var installedVersion = ((string)ndpKey.GetValue("Version")).TrimStart('v');
                        if (installedVersion.StartsWith("14", StringComparison.OrdinalIgnoreCase))
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error getting .NET Framework version", ex);
                return;
            }

            try
            {
                await InstallVcredist(GetVcredist2015Url()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error installing Visual Studio C++ runtime", ex);
            }
        }
Пример #8
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService)
        {
            SystemEvents.SessionEnding += SystemEvents_SessionEnding;
            SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

            _appHost = new ApplicationHost(appPaths, logManager);

            _app = new App(_appHost, _appHost.LogManager.GetLogger("App"), runService);

            if (runService)
            {
                _app.AppStarted += (sender, args) => StartService(logManager);
            }
            else
            {
                // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                             ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
            }

            _app.Run();
        }
Пример #9
0
        /// <summary>
        /// Loads the kernel.
        /// </summary>
        protected async void LoadKernel()
        {
            try
            {
                CompositionRoot = new ApplicationHost();

                Logger = CompositionRoot.LogManager.GetLogger("App");

                await CompositionRoot.Init();

                var win = new MainWindow(CompositionRoot.LogManager, CompositionRoot, CompositionRoot.ServerConfigurationManager, CompositionRoot.UserManager, CompositionRoot.LibraryManager, CompositionRoot.JsonSerializer);

                win.Show();
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Error launching application", ex);

                MessageBox.Show("There was an error launching Media Browser: " + ex.Message);

                // Shutdown the app with an error code
                Shutdown(1);
            }
        }
Пример #10
0
        public static void Main()
        {
            var options = new StartupOptions(Environment.GetCommandLineArgs());

            IsRunningAsService = options.ContainsOption("-service");

            if (IsRunningAsService)
            {
                //_canRestartService = CanRestartWindowsService();
            }

            var currentProcess = Process.GetCurrentProcess();

            ApplicationPath = currentProcess.MainModule.FileName;
            var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86");

            var success = SetDllDirectory(architecturePath);

            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());

            var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);

            var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");

            logManager.ReloadLogger(LogSeverity.Debug);
            logManager.AddConsoleOutput();

            var logger = _logger = logManager.GetLogger("Main");

            ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

            // Install directly
            if (options.ContainsOption("-installservice"))
            {
                logger.Info("Performing service installation");
                InstallService(ApplicationPath, logger);
                return;
            }

            // Restart with admin rights, then install
            if (options.ContainsOption("-installserviceasadmin"))
            {
                logger.Info("Performing service installation");
                RunServiceInstallation(ApplicationPath);
                return;
            }

            // Uninstall directly
            if (options.ContainsOption("-uninstallservice"))
            {
                logger.Info("Performing service uninstallation");
                UninstallService(ApplicationPath, logger);
                return;
            }

            // Restart with admin rights, then uninstall
            if (options.ContainsOption("-uninstallserviceasadmin"))
            {
                logger.Info("Performing service uninstallation");
                RunServiceUninstallation(ApplicationPath);
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            RunServiceInstallationIfNeeded(ApplicationPath);

            if (IsAlreadyRunning(ApplicationPath, currentProcess))
            {
                logger.Info("Shutting down because another instance of Emby Server is already running.");
                return;
            }

            if (PerformUpdateIfNeeded(appPaths, logger))
            {
                logger.Info("Exiting to perform application update.");
                return;
            }

            try
            {
                RunApplication(appPaths, logManager, IsRunningAsService, options);
            }
            finally
            {
                OnServiceShutdown();
            }
        }
Пример #11
0
 /// <summary>
 /// Begins the log.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="appPaths">The app paths.</param>
 private static void BeginLog(ILogger logger, IApplicationPaths appPaths)
 {
     logger.Info("Media Browser Server started");
     ApplicationHost.LogEnvironmentInfo(logger, appPaths);
 }
Пример #12
0
        private static async Task InstallVcredist2015IfNeeded(ApplicationHost appHost, ILogger logger)
        {
            // Reference
            // http://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed

            try
            {
                RegistryKey key;

                if (Environment.Is64BitProcess)
                {
                    key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)
                          .OpenSubKey("SOFTWARE\\Classes\\Installer\\Dependencies\\{d992c12e-cab2-426f-bde3-fb8c53950b0d}");

                    if (key == null)
                    {
                        key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)
                              .OpenSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64");
                    }
                }
                else
                {
                    key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)
                          .OpenSubKey("SOFTWARE\\Classes\\Installer\\Dependencies\\{e2803110-78b3-4664-a479-3611a381656a}");

                    if (key == null)
                    {
                        key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)
                              .OpenSubKey("SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x86");
                    }
                }

                if (key != null)
                {
                    using (key)
                    {
                        var version = key.GetValue("Version");
                        if (version != null)
                        {
                            var installedVersion = ((string)version).TrimStart('v');
                            if (installedVersion.StartsWith("14", StringComparison.OrdinalIgnoreCase))
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error getting .NET Framework version", ex);
                return;
            }

            try
            {
                await InstallVcredist(GetVcredist2015Url()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error installing Visual Studio C++ runtime", ex);
            }
        }
Пример #13
0
        public static void Main()
        {
            var options = new StartupOptions(Environment.GetCommandLineArgs());

            IsRunningAsService = options.ContainsOption("-service");

            var currentProcess = Process.GetCurrentProcess();

            ApplicationPath = currentProcess.MainModule.FileName;
            var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86");

            var success = SetDllDirectory(architecturePath);

            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());

            var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);

            _appPaths = appPaths;

            using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"))
            {
                _logManager = logManager;

                var task = logManager.ReloadLogger(LogSeverity.Debug, CancellationToken.None);
                Task.WaitAll(task);

                logManager.AddConsoleOutput();

                var logger = _logger = logManager.GetLogger("Main");

                ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

                // Uninstall directly
                if (options.ContainsOption("-uninstallservice"))
                {
                    logger.Info("Performing service uninstallation");
                    UninstallService(ApplicationPath, logger);
                    return;
                }

                // Restart with admin rights, then uninstall
                if (options.ContainsOption("-uninstallserviceasadmin"))
                {
                    logger.Info("Performing service uninstallation");
                    RunServiceUninstallation(ApplicationPath);
                    return;
                }

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                if (IsAlreadyRunning(ApplicationPath, currentProcess))
                {
                    logger.Info("Shutting down because another instance of Emby Server is already running.");
                    return;
                }

                if (PerformUpdateIfNeeded(appPaths, logger))
                {
                    logger.Info("Exiting to perform application update.");
                    return;
                }

                RunApplication(appPaths, logManager, IsRunningAsService, options);

                logger.Info("Shutdown complete");

                if (_restartOnShutdown)
                {
                    logger.Info("Starting new server process");
                    var restartCommandLine = GetRestartCommandLine();

                    Process.Start(restartCommandLine.Item1, restartCommandLine.Item2);
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        public static void Main()
        {
            var options = new StartupOptions();

            _isRunningAsService = options.ContainsOption("-service");

            var currentProcess = Process.GetCurrentProcess();

            var applicationPath = currentProcess.MainModule.FileName;

            //Wand.SetMagickCoderModulePath(Path.Combine(Path.GetDirectoryName(applicationPath), "ImageMagickCoders", "x86"));
            var appPaths = CreateApplicationPaths(applicationPath, _isRunningAsService);

            var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");

            logManager.ReloadLogger(LogSeverity.Debug);
            logManager.AddConsoleOutput();

            var logger = _logger = logManager.GetLogger("Main");

            ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

            // Install directly
            if (options.ContainsOption("-installservice"))
            {
                logger.Info("Performing service installation");
                InstallService(applicationPath, logger);
                return;
            }

            // Restart with admin rights, then install
            if (options.ContainsOption("-installserviceasadmin"))
            {
                logger.Info("Performing service installation");
                RunServiceInstallation(applicationPath);
                return;
            }

            // Uninstall directly
            if (options.ContainsOption("-uninstallservice"))
            {
                logger.Info("Performing service uninstallation");
                UninstallService(applicationPath, logger);
                return;
            }

            // Restart with admin rights, then uninstall
            if (options.ContainsOption("-uninstallserviceasadmin"))
            {
                logger.Info("Performing service uninstallation");
                RunServiceUninstallation(applicationPath);
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            RunServiceInstallationIfNeeded(applicationPath);

            if (IsAlreadyRunning(applicationPath, currentProcess))
            {
                logger.Info("Shutting down because another instance of Media Browser Server is already running.");
                return;
            }

            if (PerformUpdateIfNeeded(appPaths, logger))
            {
                logger.Info("Exiting to perform application update.");
                return;
            }

            try
            {
                RunApplication(appPaths, logManager, _isRunningAsService, options);
            }
            finally
            {
                OnServiceShutdown();
            }
        }
Пример #15
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <param name="appPaths">The app paths.</param>
        /// <param name="logManager">The log manager.</param>
        /// <param name="runService">if set to <c>true</c> [run service].</param>
        /// <param name="options">The options.</param>
        private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
        {
            var environmentInfo = new EnvironmentInfo();

            var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), environmentInfo, appPaths.TempDirectory);

            FileSystem = fileSystem;

            _appHost = new WindowsAppHost(appPaths,
                                          logManager,
                                          options,
                                          fileSystem,
                                          new PowerManagement(),
                                          "emby.windows.zip",
                                          environmentInfo,
                                          new NullImageEncoder(),
                                          new SystemEvents(logManager.GetLogger("SystemEvents")),
                                          new Networking.NetworkManager(logManager.GetLogger("NetworkManager")));

            var initProgress = new Progress <double>();

            if (!runService)
            {
                if (!options.ContainsOption("-nosplash"))
                {
                    ShowSplashScreen(_appHost.ApplicationVersion, initProgress, logManager.GetLogger("Splash"));
                }

                // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
                SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
                             ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
            }

            var task = _appHost.Init(initProgress);

            Task.WaitAll(task);

            if (!runService)
            {
                task = InstallVcredist2013IfNeeded(_appHost, _logger);
                Task.WaitAll(task);

                // needed by skia
                task = InstallVcredist2015IfNeeded(_appHost, _logger);
                Task.WaitAll(task);
            }

            // set image encoder here
            _appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths);

            task = task.ContinueWith(new Action <Task>(a => _appHost.RunStartupTasks()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent);

            if (runService)
            {
                StartService(logManager);
            }
            else
            {
                Task.WaitAll(task);

                Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

                HideSplashScreen();

                ShowTrayIcon();
            }
        }