diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index 2f353b8c08..453144dfc5 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -11,7 +11,6 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -74,10 +73,6 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder Version = version; FFProbePath = ffProbePath; FFMpegPath = ffMpegPath; - - // 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); } /// @@ -994,44 +989,6 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder { _videoImageResourcePool.Dispose(); } - - SetErrorMode(ErrorModes.SYSTEM_DEFAULT); - } - - /// - /// Sets the error mode. - /// - /// The u mode. - /// ErrorModes. - [DllImport("kernel32.dll")] - static extern ErrorModes SetErrorMode(ErrorModes uMode); - - /// - /// Enum ErrorModes - /// - [Flags] - public enum ErrorModes : uint - { - /// - /// The SYSTE m_ DEFAULT - /// - SYSTEM_DEFAULT = 0x0, - /// - /// The SE m_ FAILCRITICALERRORS - /// - SEM_FAILCRITICALERRORS = 0x0001, - /// - /// The SE m_ NOALIGNMENTFAULTEXCEPT - /// - SEM_NOALIGNMENTFAULTEXCEPT = 0x0004, - /// - /// The SE m_ NOGPFAULTERRORBOX - /// - SEM_NOGPFAULTERRORBOX = 0x0002, - /// - /// The SE m_ NOOPENFILEERRORBOX - /// - SEM_NOOPENFILEERRORBOX = 0x8000 } } } diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 75f2a8f286..7780d47452 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -1,8 +1,10 @@ -using MediaBrowser.Common.Constants; +using System.Runtime.InteropServices; +using MediaBrowser.Common.Constants; using MediaBrowser.Common.Implementations.Logging; using MediaBrowser.Common.Implementations.Updates; using MediaBrowser.Model.Logging; using MediaBrowser.Server.Implementations; +using MediaBrowser.ServerApplication.Native; using Microsoft.Win32; using System; using System.ComponentModel; @@ -183,6 +185,7 @@ namespace MediaBrowser.ServerApplication private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService) { SystemEvents.SessionEnding += SystemEvents_SessionEnding; + SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; _appHost = new ApplicationHost(appPaths, logManager); @@ -192,10 +195,24 @@ namespace MediaBrowser.ServerApplication { _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(); } + static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e) + { + if (e.Reason == SessionSwitchReason.SessionLogon) + { + BrowserLauncher.OpenDashboard(_appHost.UserManager, _appHost.ServerConfigurationManager, _appHost, _logger); + } + } + /// /// Starts the service. /// @@ -224,6 +241,11 @@ namespace MediaBrowser.ServerApplication _appHost.Dispose(); + if (!_isRunningAsService) + { + SetErrorMode(ErrorModes.SYSTEM_DEFAULT); + } + if (_isRestarting) { using (var process = Process.Start("cmd", "/c net start " + BackgroundService.Name)) @@ -465,5 +487,41 @@ namespace MediaBrowser.ServerApplication service.Stop(); } } + + /// + /// Sets the error mode. + /// + /// The u mode. + /// ErrorModes. + [DllImport("kernel32.dll")] + static extern ErrorModes SetErrorMode(ErrorModes uMode); + + /// + /// Enum ErrorModes + /// + [Flags] + public enum ErrorModes : uint + { + /// + /// The SYSTE m_ DEFAULT + /// + SYSTEM_DEFAULT = 0x0, + /// + /// The SE m_ FAILCRITICALERRORS + /// + SEM_FAILCRITICALERRORS = 0x0001, + /// + /// The SE m_ NOALIGNMENTFAULTEXCEPT + /// + SEM_NOALIGNMENTFAULTEXCEPT = 0x0004, + /// + /// The SE m_ NOGPFAULTERRORBOX + /// + SEM_NOGPFAULTERRORBOX = 0x0002, + /// + /// The SE m_ NOOPENFILEERRORBOX + /// + SEM_NOOPENFILEERRORBOX = 0x8000 + } } }