aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2016-11-14 02:29:42 -0500
committerGitHub <noreply@github.com>2016-11-14 02:29:42 -0500
commit54d3c2eed767b6d030961f9a75216c447f94abef (patch)
tree1855731242b35ffbed16beb1c96de1e6442a797e /MediaBrowser.ServerApplication
parente8379b865c301cb8ab65eb5b883c44abdbedcf79 (diff)
parent43c69713835afee3d27ced041e5f96ec36fa0ce3 (diff)
Merge pull request #2288 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.ServerApplication')
-rw-r--r--MediaBrowser.ServerApplication/MainStartup.cs76
-rw-r--r--MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj2
-rw-r--r--MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs2
-rw-r--r--MediaBrowser.ServerApplication/WindowsAppHost.cs (renamed from MediaBrowser.ServerApplication/Native/WindowsApp.cs)189
4 files changed, 128 insertions, 141 deletions
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs
index fa8cccf342..f5e7681333 100644
--- a/MediaBrowser.ServerApplication/MainStartup.cs
+++ b/MediaBrowser.ServerApplication/MainStartup.cs
@@ -37,13 +37,15 @@ namespace MediaBrowser.ServerApplication
private static ILogger _logger;
- private static bool _isRunningAsService = false;
+ public static bool IsRunningAsService = false;
private static bool _canRestartService = false;
private static bool _appHostDisposed;
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
+ public static string ApplicationPath;
+
public static bool TryGetLocalFromUncDirectory(string local, out string unc)
{
if ((local == null) || (local == ""))
@@ -72,23 +74,23 @@ namespace MediaBrowser.ServerApplication
public static void Main()
{
var options = new StartupOptions();
- _isRunningAsService = options.ContainsOption("-service");
+ IsRunningAsService = options.ContainsOption("-service");
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
//_canRestartService = CanRestartWindowsService();
}
var currentProcess = Process.GetCurrentProcess();
- var applicationPath = currentProcess.MainModule.FileName;
- var architecturePath = Path.Combine(Path.GetDirectoryName(applicationPath), Environment.Is64BitProcess ? "x64" : "x86");
+ ApplicationPath = currentProcess.MainModule.FileName;
+ var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86");
Wand.SetMagickCoderModulePath(architecturePath);
var success = SetDllDirectory(architecturePath);
- var appPaths = CreateApplicationPaths(applicationPath, _isRunningAsService);
+ var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Debug);
@@ -102,7 +104,7 @@ namespace MediaBrowser.ServerApplication
if (options.ContainsOption("-installservice"))
{
logger.Info("Performing service installation");
- InstallService(applicationPath, logger);
+ InstallService(ApplicationPath, logger);
return;
}
@@ -110,7 +112,7 @@ namespace MediaBrowser.ServerApplication
if (options.ContainsOption("-installserviceasadmin"))
{
logger.Info("Performing service installation");
- RunServiceInstallation(applicationPath);
+ RunServiceInstallation(ApplicationPath);
return;
}
@@ -118,7 +120,7 @@ namespace MediaBrowser.ServerApplication
if (options.ContainsOption("-uninstallservice"))
{
logger.Info("Performing service uninstallation");
- UninstallService(applicationPath, logger);
+ UninstallService(ApplicationPath, logger);
return;
}
@@ -126,15 +128,15 @@ namespace MediaBrowser.ServerApplication
if (options.ContainsOption("-uninstallserviceasadmin"))
{
logger.Info("Performing service uninstallation");
- RunServiceUninstallation(applicationPath);
+ RunServiceUninstallation(ApplicationPath);
return;
}
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
- RunServiceInstallationIfNeeded(applicationPath);
+ RunServiceInstallationIfNeeded(ApplicationPath);
- if (IsAlreadyRunning(applicationPath, currentProcess))
+ if (IsAlreadyRunning(ApplicationPath, currentProcess))
{
logger.Info("Shutting down because another instance of Emby Server is already running.");
return;
@@ -148,7 +150,7 @@ namespace MediaBrowser.ServerApplication
try
{
- RunApplication(appPaths, logManager, _isRunningAsService, options);
+ RunApplication(appPaths, logManager, IsRunningAsService, options);
}
finally
{
@@ -204,7 +206,7 @@ namespace MediaBrowser.ServerApplication
}
}
- if (!_isRunningAsService)
+ if (!IsRunningAsService)
{
return IsAlreadyRunningAsService(applicationPath);
}
@@ -250,6 +252,8 @@ namespace MediaBrowser.ServerApplication
/// <returns>ServerApplicationPaths.</returns>
private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, bool runAsService)
{
+ var appFolderPath = Path.GetDirectoryName(applicationPath);
+
var resourcesPath = Path.GetDirectoryName(applicationPath);
if (runAsService)
@@ -258,10 +262,10 @@ namespace MediaBrowser.ServerApplication
var programDataPath = Path.GetDirectoryName(systemPath);
- return new ServerApplicationPaths(programDataPath, applicationPath, resourcesPath);
+ return new ServerApplicationPaths(programDataPath, appFolderPath, resourcesPath);
}
- return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(applicationPath), applicationPath, resourcesPath);
+ return new ServerApplicationPaths(ApplicationPathHelper.GetProgramDataPath(applicationPath), appFolderPath, resourcesPath);
}
/// <summary>
@@ -272,7 +276,7 @@ namespace MediaBrowser.ServerApplication
{
get
{
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
return _canRestartService;
}
@@ -295,7 +299,7 @@ namespace MediaBrowser.ServerApplication
return false;
#endif
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
return _canRestartService;
}
@@ -317,22 +321,16 @@ namespace MediaBrowser.ServerApplication
/// <param name="options">The options.</param>
private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options)
{
- var fileSystem = new WindowsFileSystem(logManager.GetLogger("FileSystem"));
+ var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), true, true, true);
fileSystem.AddShortcutHandler(new LnkShortcutHandler());
fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));
- var nativeApp = new WindowsApp(fileSystem, _logger)
- {
- IsRunningAsService = runService
- };
-
var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths);
- _appHost = new ApplicationHost(appPaths,
+ _appHost = new WindowsAppHost(appPaths,
logManager,
options,
fileSystem,
- nativeApp,
new PowerManagement(),
"emby.windows.zip",
new EnvironmentInfo(),
@@ -370,7 +368,6 @@ namespace MediaBrowser.ServerApplication
task = InstallVcredist2013IfNeeded(_appHost, _logger);
Task.WaitAll(task);
- Microsoft.Win32.SystemEvents.SessionEnding += SystemEvents_SessionEnding;
Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
HideSplashScreen();
@@ -440,7 +437,7 @@ namespace MediaBrowser.ServerApplication
public static void Invoke(Action action)
{
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
action();
}
@@ -572,19 +569,6 @@ namespace MediaBrowser.ServerApplication
}
/// <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 || !_isRunningAsService)
- {
- Shutdown();
- }
- }
-
- /// <summary>
/// Handles the UnhandledException event of the CurrentDomain control.
/// </summary>
/// <param name="sender">The source of the event.</param>
@@ -595,7 +579,7 @@ namespace MediaBrowser.ServerApplication
new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);
- if (!_isRunningAsService)
+ if (!IsRunningAsService)
{
MessageBox.Show("Unhandled exception: " + exception.Message);
}
@@ -623,7 +607,7 @@ namespace MediaBrowser.ServerApplication
// Update is there - execute update
try
{
- var serviceName = _isRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty;
+ var serviceName = IsRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty;
new ApplicationUpdater().UpdateApplication(appPaths, updateArchive, logger, serviceName);
// And just let the app exit so it can update
@@ -642,7 +626,7 @@ namespace MediaBrowser.ServerApplication
public static void Shutdown()
{
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
ShutdownWindowsService();
}
@@ -658,7 +642,7 @@ namespace MediaBrowser.ServerApplication
{
DisposeAppHost();
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
RestartWindowsService();
}
@@ -669,7 +653,7 @@ namespace MediaBrowser.ServerApplication
_logger.Info("Starting new instance");
//Application.Restart();
- Process.Start(_appHost.ServerConfigurationManager.ApplicationPaths.ApplicationPath);
+ Process.Start(ApplicationPath);
ShutdownWindowsApplication();
}
diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
index f6aef57443..6984ff2bed 100644
--- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
+++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
@@ -138,7 +138,6 @@
<Compile Include="Native\PowerManagement.cs" />
<Compile Include="Native\Standby.cs" />
<Compile Include="Native\ServerAuthorization.cs" />
- <Compile Include="Native\WindowsApp.cs" />
<Compile Include="Networking\NativeMethods.cs" />
<Compile Include="Networking\NetworkManager.cs" />
<Compile Include="Networking\NetworkShares.cs" />
@@ -156,6 +155,7 @@
<DependentUpon>SplashForm.cs</DependentUpon>
</Compile>
<Compile Include="Updates\ApplicationUpdater.cs" />
+ <Compile Include="WindowsAppHost.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
diff --git a/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs b/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs
index c426395b76..97537b27d0 100644
--- a/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs
+++ b/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs
@@ -44,7 +44,7 @@ namespace MediaBrowser.ServerApplication.Updates
// startpath = executable to launch
// systempath = folder containing installation
var args = string.Format("product={0} archive=\"{1}\" caller={2} pismo=false version={3} service={4} installpath=\"{5}\" startpath=\"{6}\" systempath=\"{7}\"",
- product, archive, Process.GetCurrentProcess().Id, version, restartServiceName ?? string.Empty, appPaths.ProgramDataPath, appPaths.ApplicationPath, systemPath);
+ product, archive, Process.GetCurrentProcess().Id, version, restartServiceName ?? string.Empty, appPaths.ProgramDataPath, MainStartup.ApplicationPath, systemPath);
logger.Info("Args: {0}", args);
Process.Start(tempUpdater, args);
diff --git a/MediaBrowser.ServerApplication/Native/WindowsApp.cs b/MediaBrowser.ServerApplication/WindowsAppHost.cs
index babe952d6d..fa18b52295 100644
--- a/MediaBrowser.ServerApplication/Native/WindowsApp.cs
+++ b/MediaBrowser.ServerApplication/WindowsAppHost.cs
@@ -1,106 +1,102 @@
using System;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.Server.Startup.Common;
-using MediaBrowser.ServerApplication.Networking;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
-using System.Windows.Forms;
using Emby.Server.Core;
using Emby.Server.Core.Data;
using Emby.Server.Core.FFMpeg;
-using MediaBrowser.Common.IO;
-using MediaBrowser.Controller.IO;
+using Emby.Server.Implementations.EntryPoints;
using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Logging;
+using MediaBrowser.Model.System;
+using MediaBrowser.ServerApplication.Native;
-namespace MediaBrowser.ServerApplication.Native
+namespace MediaBrowser.ServerApplication
{
- public class WindowsApp : INativeApp
+ public class WindowsAppHost : ApplicationHost
{
- private readonly IFileSystem _fileSystem;
- private readonly ILogger _logger;
-
- public WindowsApp(IFileSystem fileSystem, ILogger logger)
+ public WindowsAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, IMemoryStreamFactory memoryStreamFactory, MediaBrowser.Common.Net.INetworkManager networkManager, Action<string, string> certificateGenerator, Func<string> defaultUsernameFactory)
+ : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory)
{
- _fileSystem = fileSystem;
- _logger = logger;
}
- public List<Assembly> GetAssembliesWithParts()
+ public override bool IsRunningAsService
{
- var list = new List<Assembly>();
-
- if (!System.Environment.Is64BitProcess)
- {
- //list.Add(typeof(PismoIsoManager).Assembly);
- }
-
- list.Add(GetType().Assembly);
-
- return list;
+ get { return MainStartup.IsRunningAsService; }
}
- public void AuthorizeServer(int udpPort, int httpServerPort, int httpsPort, string applicationPath, string tempDirectory)
+ protected override FFMpegInstallInfo GetFfmpegInstallInfo()
{
- ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsPort, applicationPath, tempDirectory);
- }
+ var info = new FFMpegInstallInfo();
- public bool SupportsLibraryMonitor
- {
- get { return true; }
+ info.FFMpegFilename = "ffmpeg.exe";
+ info.FFProbeFilename = "ffprobe.exe";
+ info.Version = "20160410";
+ info.ArchiveType = "7z";
+ info.DownloadUrls = GetDownloadUrls();
+
+ return info;
}
- public bool SupportsRunningAsService
+ private string[] GetDownloadUrls()
{
- get
+ switch (EnvironmentInfo.SystemArchitecture)
{
- return true;
+ case Architecture.X64:
+ return new[]
+ {
+ "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160410-win64.7z"
+ };
+ case Architecture.X86:
+ return new[]
+ {
+ "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160410-win32.7z"
+ };
}
- }
- public bool IsRunningAsService
- {
- get;
- set;
+ return new string[] { };
}
- public bool CanSelfRestart
+ protected override void RestartInternal()
{
- get
- {
- return MainStartup.CanSelfRestart;
- }
+ MainStartup.Restart();
}
- public bool SupportsAutoRunAtStartup
+ protected override List<Assembly> GetAssembliesWithPartsInternal()
{
- get
+ var list = new List<Assembly>();
+
+ if (!Environment.Is64BitProcess)
{
- return true;
+ //list.Add(typeof(PismoIsoManager).Assembly);
}
+
+ list.Add(GetType().Assembly);
+
+ return list;
}
- public bool CanSelfUpdate
+ protected override void ShutdownInternal()
{
- get
- {
- return MainStartup.CanSelfUpdate;
- }
+ MainStartup.Shutdown();
}
- public void Shutdown()
+ protected override void AuthorizeServer()
{
- MainStartup.Shutdown();
+ ServerAuthorization.AuthorizeServer(UdpServerEntryPoint.PortNumber,
+ ServerConfigurationManager.Configuration.HttpServerPortNumber,
+ ServerConfigurationManager.Configuration.HttpsPortNumber,
+ MainStartup.ApplicationPath,
+ ConfigurationManager.CommonApplicationPaths.TempDirectory);
}
- public void Restart(StartupOptions startupOptions)
+ protected override IDbConnector GetDbConnector()
{
- MainStartup.Restart();
+ return new DbConnector(Logger);
}
- public void ConfigureAutoRun(bool autorun)
+ protected override void ConfigureAutoRunInternal(bool autorun)
{
var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
@@ -110,33 +106,17 @@ namespace MediaBrowser.ServerApplication.Native
{
//Copy our shortut into the startup folder for this user
var targetPath = Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk");
- _fileSystem.CreateDirectory(Path.GetDirectoryName(targetPath));
+ FileSystemManager.CreateDirectory(Path.GetDirectoryName(targetPath));
File.Copy(shortcutPath, targetPath, true);
}
else
{
//Remove our shortcut from the startup folder for this user
- _fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
+ FileSystemManager.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
}
}
- public INetworkManager CreateNetworkManager(ILogger logger)
- {
- return new NetworkManager(logger);
- }
-
- public FFMpegInstallInfo GetFfmpegInstallInfo()
- {
- var info = new FFMpegInstallInfo();
-
- info.FFMpegFilename = "ffmpeg.exe";
- info.FFProbeFilename = "ffprobe.exe";
- info.Version = "0";
-
- return info;
- }
-
- public void LaunchUrl(string url)
+ public override void LaunchUrl(string url)
{
var process = new Process
{
@@ -156,32 +136,54 @@ namespace MediaBrowser.ServerApplication.Native
}
catch (Exception ex)
{
- _logger.ErrorException("Error launching url: {0}", ex, url);
+ Logger.ErrorException("Error launching url: {0}", ex, url);
throw;
}
}
- public IDbConnector GetDbConnector()
- {
- return new DbConnector(_logger);
- }
-
- /// <summary>
- /// Processes the exited.
- /// </summary>
- /// <param name="sender">The sender.</param>
- /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void ProcessExited(object sender, EventArgs e)
{
((Process)sender).Dispose();
}
- public void EnableLoopback(string appName)
+ protected override void EnableLoopbackInternal(string appName)
{
LoopUtil.Run(appName);
}
+ public override bool SupportsRunningAsService
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public override bool CanSelfRestart
+ {
+ get
+ {
+ return MainStartup.CanSelfRestart;
+ }
+ }
+
+ public override bool SupportsAutoRunAtStartup
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public override bool CanSelfUpdate
+ {
+ get
+ {
+ return MainStartup.CanSelfUpdate;
+ }
+ }
+
public bool PortsRequireAuthorization(string applicationPath)
{
var appNameSrch = Path.GetFileName(applicationPath);
@@ -209,7 +211,7 @@ namespace MediaBrowser.ServerApplication.Native
if (data.IndexOf("Block", StringComparison.OrdinalIgnoreCase) != -1)
{
- _logger.Info("Found potential windows firewall rule blocking Emby Server: " + data);
+ Logger.Info("Found potential windows firewall rule blocking Emby Server: " + data);
}
//var parts = data.Split('\n');
@@ -220,7 +222,7 @@ namespace MediaBrowser.ServerApplication.Native
}
catch (Exception ex)
{
- _logger.ErrorException("Error querying windows firewall", ex);
+ Logger.ErrorException("Error querying windows firewall", ex);
// Hate having to do this
try
@@ -229,12 +231,13 @@ namespace MediaBrowser.ServerApplication.Native
}
catch (Exception ex1)
{
- _logger.ErrorException("Error killing process", ex1);
+ Logger.ErrorException("Error killing process", ex1);
}
throw;
}
}
}
+
}
-} \ No newline at end of file
+}