2016-04-23 20:03:49 -07:00
|
|
|
|
using System;
|
2014-11-09 11:24:57 -07:00
|
|
|
|
using System.Collections.Generic;
|
2016-04-23 20:03:49 -07:00
|
|
|
|
using System.Diagnostics;
|
2016-04-03 10:34:52 -07:00
|
|
|
|
using System.IO;
|
2014-11-09 11:24:57 -07:00
|
|
|
|
using System.Reflection;
|
2016-12-22 16:53:57 -07:00
|
|
|
|
using System.Runtime.InteropServices.ComTypes;
|
2017-02-26 14:47:52 -07:00
|
|
|
|
using Emby.Server.CinemaMode;
|
2017-02-20 13:50:58 -07:00
|
|
|
|
using Emby.Server.Connect;
|
2016-11-10 22:23:15 -07:00
|
|
|
|
using Emby.Server.Core;
|
2016-11-18 14:06:00 -07:00
|
|
|
|
using Emby.Server.Implementations;
|
2016-11-13 14:04:21 -07:00
|
|
|
|
using Emby.Server.Implementations.EntryPoints;
|
2016-11-18 14:06:00 -07:00
|
|
|
|
using Emby.Server.Implementations.FFMpeg;
|
2017-08-15 23:43:41 -07:00
|
|
|
|
using Emby.Server.Implementations.IO;
|
2017-02-23 12:13:07 -07:00
|
|
|
|
using Emby.Server.Sync;
|
2017-02-20 13:50:58 -07:00
|
|
|
|
using MediaBrowser.Controller.Connect;
|
2017-02-23 12:13:07 -07:00
|
|
|
|
using MediaBrowser.Controller.Sync;
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-11-12 21:33:51 -07:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.System;
|
2017-04-09 18:51:36 -07:00
|
|
|
|
using MediaBrowser.Model.Updates;
|
|
|
|
|
using MediaBrowser.Server.Startup.Common;
|
2016-11-12 21:33:51 -07:00
|
|
|
|
using MediaBrowser.ServerApplication.Native;
|
2014-11-09 11:24:57 -07:00
|
|
|
|
|
2016-11-12 21:33:51 -07:00
|
|
|
|
namespace MediaBrowser.ServerApplication
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2016-11-12 21:33:51 -07:00
|
|
|
|
public class WindowsAppHost : ApplicationHost
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2017-08-17 13:19:02 -07:00
|
|
|
|
public WindowsAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager)
|
|
|
|
|
: base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, networkManager)
|
2015-01-12 20:46:44 -07:00
|
|
|
|
{
|
2017-08-18 12:34:41 -07:00
|
|
|
|
fileSystem.AddShortcutHandler(new LnkShortcutHandler());
|
2015-01-12 20:46:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 21:33:51 -07:00
|
|
|
|
public override bool IsRunningAsService
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2016-11-12 21:33:51 -07:00
|
|
|
|
get { return MainStartup.IsRunningAsService; }
|
2014-11-09 11:24:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 13:50:58 -07:00
|
|
|
|
protected override IConnectManager CreateConnectManager()
|
|
|
|
|
{
|
|
|
|
|
return new ConnectManager();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 12:13:07 -07:00
|
|
|
|
protected override ISyncManager CreateSyncManager()
|
|
|
|
|
{
|
|
|
|
|
return new SyncManager();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 21:33:51 -07:00
|
|
|
|
protected override void RestartInternal()
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2016-11-12 21:33:51 -07:00
|
|
|
|
MainStartup.Restart();
|
2014-11-09 11:24:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 11:37:04 -07:00
|
|
|
|
public override void EnableLoopback(string appName)
|
|
|
|
|
{
|
|
|
|
|
LoopUtil.Run(appName);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 21:33:51 -07:00
|
|
|
|
protected override List<Assembly> GetAssembliesWithPartsInternal()
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2016-11-12 21:33:51 -07:00
|
|
|
|
var list = new List<Assembly>();
|
2014-11-09 11:24:57 -07:00
|
|
|
|
|
2017-02-26 14:47:52 -07:00
|
|
|
|
list.Add(typeof(DefaultIntroProvider).Assembly);
|
2017-02-20 13:50:58 -07:00
|
|
|
|
list.Add(typeof(ConnectManager).Assembly);
|
2017-02-23 12:13:07 -07:00
|
|
|
|
list.Add(typeof(SyncManager).Assembly);
|
2016-11-12 21:33:51 -07:00
|
|
|
|
list.Add(GetType().Assembly);
|
|
|
|
|
|
|
|
|
|
return list;
|
2014-11-09 11:24:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 21:33:51 -07:00
|
|
|
|
protected override void ShutdownInternal()
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2016-11-12 21:33:51 -07:00
|
|
|
|
MainStartup.Shutdown();
|
2014-11-09 11:24:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 14:04:21 -07:00
|
|
|
|
protected override void AuthorizeServer()
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2016-11-13 14:04:21 -07:00
|
|
|
|
ServerAuthorization.AuthorizeServer(UdpServerEntryPoint.PortNumber,
|
|
|
|
|
ServerConfigurationManager.Configuration.HttpServerPortNumber,
|
|
|
|
|
ServerConfigurationManager.Configuration.HttpsPortNumber,
|
|
|
|
|
MainStartup.ApplicationPath,
|
|
|
|
|
ConfigurationManager.CommonApplicationPaths.TempDirectory);
|
2014-11-09 11:24:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 21:33:51 -07:00
|
|
|
|
protected override void ConfigureAutoRunInternal(bool autorun)
|
2014-11-09 11:24:57 -07:00
|
|
|
|
{
|
2017-02-18 20:46:09 -07:00
|
|
|
|
var startupPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
|
2016-11-13 20:44:54 -07:00
|
|
|
|
|
2016-12-22 16:53:57 -07:00
|
|
|
|
if (autorun && !MainStartup.IsRunningAsService)
|
2016-04-03 10:34:52 -07:00
|
|
|
|
{
|
|
|
|
|
//Copy our shortut into the startup folder for this user
|
2016-12-22 16:53:57 -07:00
|
|
|
|
var targetPath = Path.Combine(startupPath, "Emby Server.lnk");
|
|
|
|
|
|
|
|
|
|
IShellLinkW link = (IShellLinkW)new ShellLink();
|
|
|
|
|
|
|
|
|
|
var appPath = Process.GetCurrentProcess().MainModule.FileName;
|
|
|
|
|
|
|
|
|
|
// setup shortcut information
|
|
|
|
|
link.SetDescription(Name);
|
|
|
|
|
link.SetPath(appPath);
|
|
|
|
|
link.SetWorkingDirectory(Path.GetDirectoryName(appPath));
|
|
|
|
|
|
|
|
|
|
// save it
|
|
|
|
|
IPersistFile file = (IPersistFile)link;
|
2016-12-23 01:50:32 -07:00
|
|
|
|
file.Save(targetPath, true);
|
2016-04-03 10:34:52 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Remove our shortcut from the startup folder for this user
|
2016-12-22 16:53:57 -07:00
|
|
|
|
FileSystemManager.DeleteFile(Path.Combine(startupPath, "Emby Server.lnk"));
|
2016-04-03 10:34:52 -07:00
|
|
|
|
}
|
2014-11-09 11:24:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 21:33:51 -07:00
|
|
|
|
public override bool SupportsRunningAsService
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool CanSelfRestart
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return MainStartup.CanSelfRestart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool CanSelfUpdate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return MainStartup.CanSelfUpdate;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-09 11:24:57 -07:00
|
|
|
|
}
|
2016-11-12 21:33:51 -07:00
|
|
|
|
}
|