2016-04-24 03:03:49 +00:00
|
|
|
|
using System;
|
2014-11-09 18:24:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-04-24 03:03:49 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-04-03 17:34:52 +00:00
|
|
|
|
using System.IO;
|
2014-11-09 18:24:57 +00:00
|
|
|
|
using System.Reflection;
|
2016-11-11 05:23:15 +00:00
|
|
|
|
using Emby.Server.Core;
|
2016-11-11 06:43:42 +00:00
|
|
|
|
using Emby.Server.Core.Data;
|
|
|
|
|
using Emby.Server.Core.FFMpeg;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-11-13 04:33:51 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.System;
|
|
|
|
|
using MediaBrowser.ServerApplication.Native;
|
2014-11-09 18:24:57 +00:00
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
namespace MediaBrowser.ServerApplication
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
public class WindowsAppHost : ApplicationHost
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
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)
|
2015-01-13 03:46:44 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
public override bool IsRunningAsService
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
get { return MainStartup.IsRunningAsService; }
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override FFMpegInstallInfo GetFfmpegInstallInfo()
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
var info = new FFMpegInstallInfo();
|
2014-11-09 18:24:57 +00:00
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
info.FFMpegFilename = "ffmpeg.exe";
|
|
|
|
|
info.FFProbeFilename = "ffprobe.exe";
|
|
|
|
|
info.Version = "0";
|
2015-10-03 18:13:53 +00:00
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
return info;
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override void RestartInternal()
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
MainStartup.Restart();
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override List<Assembly> GetAssembliesWithPartsInternal()
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
var list = new List<Assembly>();
|
2014-11-09 18:24:57 +00:00
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
if (!Environment.Is64BitProcess)
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
//list.Add(typeof(PismoIsoManager).Assembly);
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
2016-11-13 04:33:51 +00:00
|
|
|
|
|
|
|
|
|
list.Add(GetType().Assembly);
|
|
|
|
|
|
|
|
|
|
return list;
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override void ShutdownInternal()
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
MainStartup.Shutdown();
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override void AuthorizeServer(int udpPort, int httpServerPort, int httpsServerPort, string applicationPath, string tempDirectory)
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsServerPort, applicationPath, tempDirectory);
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override IDbConnector GetDbConnector()
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
return new DbConnector(Logger);
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override void ConfigureAutoRunInternal(bool autorun)
|
2014-11-09 18:24:57 +00:00
|
|
|
|
{
|
2016-04-03 17:34:52 +00:00
|
|
|
|
var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
|
|
|
|
|
|
|
|
|
|
var startupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
|
2016-11-13 04:33:51 +00:00
|
|
|
|
|
2016-04-03 17:34:52 +00:00
|
|
|
|
if (autorun)
|
|
|
|
|
{
|
|
|
|
|
//Copy our shortut into the startup folder for this user
|
|
|
|
|
var targetPath = Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk");
|
2016-11-13 04:33:51 +00:00
|
|
|
|
FileSystemManager.CreateDirectory(Path.GetDirectoryName(targetPath));
|
2016-04-03 17:34:52 +00:00
|
|
|
|
File.Copy(shortcutPath, targetPath, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Remove our shortcut from the startup folder for this user
|
2016-11-13 04:33:51 +00:00
|
|
|
|
FileSystemManager.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
|
2016-04-03 17:34:52 +00:00
|
|
|
|
}
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
public override void LaunchUrl(string url)
|
2016-04-24 03:03:49 +00:00
|
|
|
|
{
|
|
|
|
|
var process = new Process
|
|
|
|
|
{
|
|
|
|
|
StartInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = url
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
EnableRaisingEvents = true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
process.Exited += ProcessExited;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
process.Start();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
Logger.ErrorException("Error launching url: {0}", ex, url);
|
2016-04-24 03:03:49 +00:00
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ProcessExited(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
((Process)sender).Dispose();
|
|
|
|
|
}
|
2016-09-03 17:16:36 +00:00
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
protected override void EnableLoopbackInternal(string appName)
|
2016-09-03 17:16:36 +00:00
|
|
|
|
{
|
|
|
|
|
LoopUtil.Run(appName);
|
|
|
|
|
}
|
2016-09-06 05:02:05 +00:00
|
|
|
|
|
2016-11-13 04:33:51 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-06 05:02:05 +00:00
|
|
|
|
public bool PortsRequireAuthorization(string applicationPath)
|
|
|
|
|
{
|
|
|
|
|
var appNameSrch = Path.GetFileName(applicationPath);
|
|
|
|
|
|
|
|
|
|
var startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "netsh",
|
|
|
|
|
|
|
|
|
|
Arguments = "advfirewall firewall show rule \"" + appNameSrch + "\"",
|
|
|
|
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
|
ErrorDialog = false,
|
|
|
|
|
RedirectStandardOutput = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using (var process = Process.Start(startInfo))
|
|
|
|
|
{
|
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var data = process.StandardOutput.ReadToEnd() ?? string.Empty;
|
|
|
|
|
|
|
|
|
|
if (data.IndexOf("Block", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
Logger.Info("Found potential windows firewall rule blocking Emby Server: " + data);
|
2016-09-06 05:02:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//var parts = data.Split('\n');
|
|
|
|
|
|
|
|
|
|
//return parts.Length > 4;
|
2016-09-06 06:50:07 +00:00
|
|
|
|
//return Confirm();
|
2016-09-06 05:02:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
Logger.ErrorException("Error querying windows firewall", ex);
|
2016-09-06 05:02:05 +00:00
|
|
|
|
|
|
|
|
|
// Hate having to do this
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
process.Kill();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex1)
|
|
|
|
|
{
|
2016-11-13 04:33:51 +00:00
|
|
|
|
Logger.ErrorException("Error killing process", ex1);
|
2016-09-06 05:02:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-13 04:33:51 +00:00
|
|
|
|
|
2014-11-09 18:24:57 +00:00
|
|
|
|
}
|
2016-11-13 04:33:51 +00:00
|
|
|
|
}
|