aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.ServerApplication')
-rw-r--r--MediaBrowser.ServerApplication/MainStartup.cs101
-rw-r--r--MediaBrowser.ServerApplication/Native/Autorun.cs17
-rw-r--r--MediaBrowser.ServerApplication/packages.config2
3 files changed, 99 insertions, 21 deletions
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs
index b8af35fde1..ac6fd1bbea 100644
--- a/MediaBrowser.ServerApplication/MainStartup.cs
+++ b/MediaBrowser.ServerApplication/MainStartup.cs
@@ -18,6 +18,9 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using CommonIO.Windows;
+using Emby.Drawing.ImageMagick;
+using ImageMagickSharp;
+using MediaBrowser.Common.Net;
using MediaBrowser.Server.Implementations.Logging;
namespace MediaBrowser.ServerApplication
@@ -29,6 +32,10 @@ namespace MediaBrowser.ServerApplication
private static ILogger _logger;
private static bool _isRunningAsService = false;
+ private static bool _appHostDisposed;
+
+ [DllImport("kernel32.dll", SetLastError = true)]
+ static extern bool SetDllDirectory(string lpPathName);
/// <summary>
/// Defines the entry point of the application.
@@ -41,6 +48,11 @@ namespace MediaBrowser.ServerApplication
var currentProcess = Process.GetCurrentProcess();
var 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);
@@ -215,7 +227,7 @@ namespace MediaBrowser.ServerApplication
logManager,
options,
fileSystem,
- "MBServer",
+ "emby.windows.zip",
nativeApp);
var initProgress = new Progress<double>();
@@ -241,6 +253,9 @@ namespace MediaBrowser.ServerApplication
{
Task.WaitAll(task);
+ task = InstallVcredistIfNeeded(_appHost, _logger);
+ Task.WaitAll(task);
+
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
@@ -329,7 +344,7 @@ namespace MediaBrowser.ServerApplication
{
_logger.Info("Shutting down");
- _appHost.Dispose();
+ DisposeAppHost();
}
/// <summary>
@@ -500,14 +515,15 @@ namespace MediaBrowser.ServerApplication
}
else
{
+ DisposeAppHost();
+
ShutdownWindowsApplication();
}
}
public static void Restart()
{
- _logger.Info("Disposing app host");
- _appHost.Dispose();
+ DisposeAppHost();
if (!_isRunningAsService)
{
@@ -522,11 +538,24 @@ namespace MediaBrowser.ServerApplication
}
}
+ private static void DisposeAppHost()
+ {
+ if (!_appHostDisposed)
+ {
+ _logger.Info("Disposing app host");
+
+ _appHostDisposed = true;
+ _appHost.Dispose();
+ }
+ }
+
private static void ShutdownWindowsApplication()
{
_logger.Info("Calling Application.Exit");
Application.Exit();
+ Environment.Exit(0);
+
_logger.Info("Calling ApplicationTaskCompletionSource.SetResult");
ApplicationTaskCompletionSource.SetResult(true);
}
@@ -544,6 +573,70 @@ namespace MediaBrowser.ServerApplication
}
}
+ 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 ImageMagick", ex);
+ }
+ }
+
+ private async static Task InstallVcredist()
+ {
+ var httpClient = _appHost.HttpClient;
+
+ var tmp = await httpClient.GetTempFile(new HttpRequestOptions
+ {
+ Url = GetVcredistUrl(),
+ Progress = new Progress<double>()
+
+ }).ConfigureAwait(false);
+
+ var exePath = Path.ChangeExtension(tmp, ".exe");
+ File.Copy(tmp, exePath);
+
+ var startInfo = new ProcessStartInfo
+ {
+ FileName = exePath,
+
+ CreateNoWindow = true,
+ WindowStyle = ProcessWindowStyle.Hidden,
+ Verb = "runas",
+ ErrorDialog = false
+ };
+
+ using (var process = Process.Start(startInfo))
+ {
+ process.WaitForExit();
+ }
+ }
+
+ private static string GetVcredistUrl()
+ {
+ if (Environment.Is64BitProcess)
+ {
+ return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_x64.exe";
+ }
+
+ // TODO: ARM url - https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_arm.exe
+
+ return "https://github.com/MediaBrowser/Emby.Resources/raw/master/vcredist2013/vcredist_x86.exe";
+ }
+
/// <summary>
/// Sets the error mode.
/// </summary>
diff --git a/MediaBrowser.ServerApplication/Native/Autorun.cs b/MediaBrowser.ServerApplication/Native/Autorun.cs
index 2cacaae8ed..c384d04602 100644
--- a/MediaBrowser.ServerApplication/Native/Autorun.cs
+++ b/MediaBrowser.ServerApplication/Native/Autorun.cs
@@ -17,25 +17,10 @@ namespace MediaBrowser.ServerApplication.Native
/// <param name="fileSystem">The file system.</param>
public static void Configure(bool autorun, IFileSystem fileSystem)
{
- var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk");
-
- if (!Directory.Exists(Path.GetDirectoryName(shortcutPath)))
- {
- shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
- }
+ var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
- // Remove lnk from old name
- try
- {
- fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Media Browser Server.lnk"));
- }
- catch
- {
-
- }
-
if (autorun)
{
//Copy our shortut into the startup folder for this user
diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config
index dec8199cc2..3ea97a30e6 100644
--- a/MediaBrowser.ServerApplication/packages.config
+++ b/MediaBrowser.ServerApplication/packages.config
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonIO" version="1.0.0.5" targetFramework="net45" />
- <package id="ImageMagickSharp" version="1.0.0.16" targetFramework="net45" />
+ <package id="ImageMagickSharp" version="1.0.0.17" targetFramework="net45" />
<package id="MediaBrowser.IsoMounting" version="3.0.69" targetFramework="net45" />
<package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.94.0" targetFramework="net45" />