aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.ServerApplication')
-rw-r--r--MediaBrowser.ServerApplication/App.config64
-rw-r--r--MediaBrowser.ServerApplication/MainForm.Designer.cs58
-rw-r--r--MediaBrowser.ServerApplication/MainStartup.cs121
-rw-r--r--MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj117
-rw-r--r--MediaBrowser.ServerApplication/Native/DbConnector.cs22
-rw-r--r--MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs4
-rw-r--r--MediaBrowser.ServerApplication/Native/PowerManagement.cs17
-rw-r--r--MediaBrowser.ServerApplication/Native/RegisterServer.bat3
-rw-r--r--MediaBrowser.ServerApplication/Native/WindowsApp.cs262
-rw-r--r--MediaBrowser.ServerApplication/Networking/CertificateGenerator.cs244
-rw-r--r--MediaBrowser.ServerApplication/Networking/NetworkManager.cs20
-rw-r--r--MediaBrowser.ServerApplication/ServerNotifyIcon.cs4
-rw-r--r--MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs19
-rw-r--r--MediaBrowser.ServerApplication/WindowsAppHost.cs215
-rw-r--r--MediaBrowser.ServerApplication/packages.config9
15 files changed, 445 insertions, 734 deletions
diff --git a/MediaBrowser.ServerApplication/App.config b/MediaBrowser.ServerApplication/App.config
index fa7bc9f89..4bac6bb70 100644
--- a/MediaBrowser.ServerApplication/App.config
+++ b/MediaBrowser.ServerApplication/App.config
@@ -1,80 +1,84 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
- <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
+ <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
- <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
+ <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.diagnostics>
- <assert assertuienabled="false"/>
+ <assert assertuienabled="false" />
</system.diagnostics>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true"></targets>
</nlog>
<appSettings>
- <add key="DebugProgramDataPath" value="..\..\..\ProgramData-Server"/>
- <add key="ReleaseProgramDataPath" value=".."/>
- <add key="ClientSettingsProvider.ServiceUri" value=""/>
+ <add key="DebugProgramDataPath" value="..\..\..\ProgramData-Server" />
+ <add key="ReleaseProgramDataPath" value=".." />
+ <add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<startup useLegacyV2RuntimeActivationPolicy="true">
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<runtime>
- <gcAllowVeryLargeObjects enabled="true"/>
- <gcServer enabled="true"/>
+ <gcAllowVeryLargeObjects enabled="true" />
+ <gcServer enabled="true" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
- <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
- <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
+ <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
- <assemblyIdentity name="System.Reactive.Core" publicKeyToken="f300afd708cefcd3" culture="neutral"/>
- <bindingRedirect oldVersion="0.0.0.0-2.0.20823.0" newVersion="2.0.20823.0"/>
+ <assemblyIdentity name="System.Reactive.Core" publicKeyToken="f300afd708cefcd3" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-2.0.20823.0" newVersion="2.0.20823.0" />
</dependentAssembly>
<dependentAssembly>
- <assemblyIdentity name="System.Reactive.Interfaces" publicKeyToken="f300afd708cefcd3" culture="neutral"/>
- <bindingRedirect oldVersion="0.0.0.0-2.0.20823.0" newVersion="2.0.20823.0"/>
+ <assemblyIdentity name="System.Reactive.Interfaces" publicKeyToken="f300afd708cefcd3" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-2.0.20823.0" newVersion="2.0.20823.0" />
</dependentAssembly>
<dependentAssembly>
- <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
- <bindingRedirect oldVersion="0.0.0.0-1.5.11.0" newVersion="1.5.11.0"/>
+ <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-1.5.11.0" newVersion="1.5.11.0" />
</dependentAssembly>
<dependentAssembly>
- <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
- <bindingRedirect oldVersion="0.0.0.0-1.5.11.0" newVersion="1.5.11.0"/>
+ <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-1.5.11.0" newVersion="1.5.11.0" />
</dependentAssembly>
<dependentAssembly>
- <assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral"/>
- <bindingRedirect oldVersion="0.0.0.0-1.0.94.0" newVersion="1.0.94.0"/>
+ <assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-1.0.94.0" newVersion="1.0.94.0" />
</dependentAssembly>
<dependentAssembly>
- <assemblyIdentity name="SimpleInjector" publicKeyToken="984cb50dea722e99" culture="neutral"/>
- <bindingRedirect oldVersion="0.0.0.0-2.3.6.0" newVersion="2.3.6.0"/>
+ <assemblyIdentity name="SimpleInjector" publicKeyToken="984cb50dea722e99" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-2.3.6.0" newVersion="2.3.6.0" />
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
- <enforceFIPSPolicy enabled="false"/>
+ <enforceFIPSPolicy enabled="false" />
</runtime>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
- <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/>
+ <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
- <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>
+ <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
- <parameter value="v11.0"/>
+ <parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
- <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
- <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
+ <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
+ <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
diff --git a/MediaBrowser.ServerApplication/MainForm.Designer.cs b/MediaBrowser.ServerApplication/MainForm.Designer.cs
index 480e10a46..855a64899 100644
--- a/MediaBrowser.ServerApplication/MainForm.Designer.cs
+++ b/MediaBrowser.ServerApplication/MainForm.Designer.cs
@@ -35,14 +35,8 @@
this.cmdBrowse = new System.Windows.Forms.ToolStripMenuItem();
this.cmdConfigure = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
- this.cmdLibraryExplorer = new System.Windows.Forms.ToolStripMenuItem();
this.cmdRestart = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
- this.cmdApiDocs = new System.Windows.Forms.ToolStripMenuItem();
- this.cmdStandardDocs = new System.Windows.Forms.ToolStripMenuItem();
- this.cmdSwagger = new System.Windows.Forms.ToolStripMenuItem();
- this.cmdGtihub = new System.Windows.Forms.ToolStripMenuItem();
- this.cmdLogWindow = new System.Windows.Forms.ToolStripMenuItem();
this.cmdCommunity = new System.Windows.Forms.ToolStripMenuItem();
this.cmdExit = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
@@ -52,7 +46,7 @@
//
this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
- this.notifyIcon1.Text = "Media Browser";
+ this.notifyIcon1.Text = "Emby";
this.notifyIcon1.Visible = true;
//
// contextMenuStrip1
@@ -61,11 +55,8 @@
this.cmdBrowse,
this.cmdConfigure,
this.toolStripSeparator2,
- this.cmdLibraryExplorer,
this.cmdRestart,
this.toolStripSeparator1,
- this.cmdApiDocs,
- this.cmdLogWindow,
this.cmdCommunity,
this.cmdExit});
this.contextMenuStrip1.Name = "contextMenuStrip1";
@@ -90,12 +81,6 @@
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(205, 6);
//
- // cmdLibraryExplorer
- //
- this.cmdLibraryExplorer.Name = "cmdLibraryExplorer";
- this.cmdLibraryExplorer.Size = new System.Drawing.Size(208, 22);
- this.cmdLibraryExplorer.Text = "Open Library Explorer";
- //
// cmdRestart
//
this.cmdRestart.Name = "cmdRestart";
@@ -107,41 +92,6 @@
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(205, 6);
//
- // cmdApiDocs
- //
- this.cmdApiDocs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.cmdStandardDocs,
- this.cmdSwagger,
- this.cmdGtihub});
- this.cmdApiDocs.Name = "cmdApiDocs";
- this.cmdApiDocs.Size = new System.Drawing.Size(208, 22);
- this.cmdApiDocs.Text = "View Api Documentation";
- //
- // cmdStandardDocs
- //
- this.cmdStandardDocs.Name = "cmdStandardDocs";
- this.cmdStandardDocs.Size = new System.Drawing.Size(136, 22);
- this.cmdStandardDocs.Text = "Standard";
- //
- // cmdSwagger
- //
- this.cmdSwagger.Name = "cmdSwagger";
- this.cmdSwagger.Size = new System.Drawing.Size(136, 22);
- this.cmdSwagger.Text = "Swagger";
- //
- // cmdGtihub
- //
- this.cmdGtihub.Name = "cmdGtihub";
- this.cmdGtihub.Size = new System.Drawing.Size(136, 22);
- this.cmdGtihub.Text = "Github Wiki";
- //
- // cmdLogWindow
- //
- this.cmdLogWindow.CheckOnClick = true;
- this.cmdLogWindow.Name = "cmdLogWindow";
- this.cmdLogWindow.Size = new System.Drawing.Size(208, 22);
- this.cmdLogWindow.Text = "Show Log Window";
- //
// cmdCommunity
//
this.cmdCommunity.Name = "cmdCommunity";
@@ -179,14 +129,8 @@
private System.Windows.Forms.ToolStripMenuItem cmdBrowse;
private System.Windows.Forms.ToolStripMenuItem cmdConfigure;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
- private System.Windows.Forms.ToolStripMenuItem cmdLibraryExplorer;
private System.Windows.Forms.ToolStripMenuItem cmdRestart;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
- private System.Windows.Forms.ToolStripMenuItem cmdLogWindow;
private System.Windows.Forms.ToolStripMenuItem cmdCommunity;
- private System.Windows.Forms.ToolStripMenuItem cmdApiDocs;
- private System.Windows.Forms.ToolStripMenuItem cmdStandardDocs;
- private System.Windows.Forms.ToolStripMenuItem cmdSwagger;
- private System.Windows.Forms.ToolStripMenuItem cmdGtihub;
}
} \ No newline at end of file
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs
index 92ff78152..c34940141 100644
--- a/MediaBrowser.ServerApplication/MainStartup.cs
+++ b/MediaBrowser.ServerApplication/MainStartup.cs
@@ -1,8 +1,6 @@
-using MediaBrowser.Common.Implementations.Logging;
-using MediaBrowser.Model.Logging;
+using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations;
using MediaBrowser.Server.Startup.Common;
-using MediaBrowser.Server.Startup.Common.Browser;
using MediaBrowser.ServerApplication.Native;
using MediaBrowser.ServerApplication.Splash;
using MediaBrowser.ServerApplication.Updates;
@@ -19,10 +17,18 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
-using CommonIO.Windows;
+using Emby.Common.Implementations.EnvironmentInfo;
+using Emby.Common.Implementations.IO;
+using Emby.Common.Implementations.Logging;
+using Emby.Common.Implementations.Networking;
+using Emby.Common.Implementations.Security;
+using Emby.Server.Core;
+using Emby.Server.Implementations;
+using Emby.Server.Implementations.Browser;
+using Emby.Server.Implementations.IO;
using ImageMagickSharp;
using MediaBrowser.Common.Net;
-using MediaBrowser.Server.Implementations.Logging;
+using MediaBrowser.Server.Startup.Common.IO;
namespace MediaBrowser.ServerApplication
{
@@ -32,13 +38,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 == ""))
@@ -62,28 +70,30 @@ namespace MediaBrowser.ServerApplication
return false;
}
/// <summary>
- /// Defines the entry point of the application.
- /// </summary>
+ /// Defines the entry point of the application.
+ /// </summary>
public static void Main()
{
- var options = new StartupOptions();
- _isRunningAsService = options.ContainsOption("-service");
+ var options = new StartupOptions(Environment.GetCommandLineArgs());
+ 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);
+ SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
+
+ var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Debug);
@@ -97,7 +107,7 @@ namespace MediaBrowser.ServerApplication
if (options.ContainsOption("-installservice"))
{
logger.Info("Performing service installation");
- InstallService(applicationPath, logger);
+ InstallService(ApplicationPath, logger);
return;
}
@@ -105,7 +115,7 @@ namespace MediaBrowser.ServerApplication
if (options.ContainsOption("-installserviceasadmin"))
{
logger.Info("Performing service installation");
- RunServiceInstallation(applicationPath);
+ RunServiceInstallation(ApplicationPath);
return;
}
@@ -113,7 +123,7 @@ namespace MediaBrowser.ServerApplication
if (options.ContainsOption("-uninstallservice"))
{
logger.Info("Performing service uninstallation");
- UninstallService(applicationPath, logger);
+ UninstallService(ApplicationPath, logger);
return;
}
@@ -121,15 +131,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;
@@ -143,7 +153,7 @@ namespace MediaBrowser.ServerApplication
try
{
- RunApplication(appPaths, logManager, _isRunningAsService, options);
+ RunApplication(appPaths, logManager, IsRunningAsService, options);
}
finally
{
@@ -199,7 +209,7 @@ namespace MediaBrowser.ServerApplication
}
}
- if (!_isRunningAsService)
+ if (!IsRunningAsService)
{
return IsAlreadyRunningAsService(applicationPath);
}
@@ -245,6 +255,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)
@@ -253,10 +265,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>
@@ -267,7 +279,7 @@ namespace MediaBrowser.ServerApplication
{
get
{
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
return _canRestartService;
}
@@ -286,7 +298,11 @@ namespace MediaBrowser.ServerApplication
{
get
{
- if (_isRunningAsService)
+#if DEBUG
+ return false;
+#endif
+
+ if (IsRunningAsService)
{
return _canRestartService;
}
@@ -308,21 +324,25 @@ 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(new PatternsLogger(logManager.GetLogger("FileSystem")));
+ var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), true, true, true);
+ fileSystem.AddShortcutHandler(new LnkShortcutHandler());
fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));
- //fileSystem.AddShortcutHandler(new LnkShortcutHandler(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,
+ new PowerManagement(),
"emby.windows.zip",
- nativeApp);
+ new EnvironmentInfo(),
+ imageEncoder,
+ new Server.Startup.Common.SystemEvents(logManager.GetLogger("SystemEvents")),
+ new RecyclableMemoryStreamProvider(),
+ new Networking.NetworkManager(logManager.GetLogger("NetworkManager")),
+ GenerateCertificate,
+ () => Environment.UserDomainName);
var initProgress = new Progress<double>();
@@ -351,8 +371,7 @@ namespace MediaBrowser.ServerApplication
task = InstallVcredist2013IfNeeded(_appHost, _logger);
Task.WaitAll(task);
- SystemEvents.SessionEnding += SystemEvents_SessionEnding;
- SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
+ Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
HideSplashScreen();
@@ -363,6 +382,11 @@ namespace MediaBrowser.ServerApplication
}
}
+ private static void GenerateCertificate(string certPath, string certHost)
+ {
+ CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, _logger);
+ }
+
private static ServerNotifyIcon _serverNotifyIcon;
private static TaskScheduler _mainTaskScheduler;
private static void ShowTrayIcon()
@@ -416,7 +440,7 @@ namespace MediaBrowser.ServerApplication
public static void Invoke(Action action)
{
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
action();
}
@@ -548,19 +572,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>
@@ -571,7 +582,7 @@ namespace MediaBrowser.ServerApplication
new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);
- if (!_isRunningAsService)
+ if (!IsRunningAsService)
{
MessageBox.Show("Unhandled exception: " + exception.Message);
}
@@ -599,7 +610,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
@@ -618,7 +629,7 @@ namespace MediaBrowser.ServerApplication
public static void Shutdown()
{
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
ShutdownWindowsService();
}
@@ -634,7 +645,7 @@ namespace MediaBrowser.ServerApplication
{
DisposeAppHost();
- if (_isRunningAsService)
+ if (IsRunningAsService)
{
RestartWindowsService();
}
@@ -645,7 +656,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 0a7a3a6a5..7badccef3 100644
--- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
+++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
@@ -64,32 +64,51 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
- <Reference Include="CommonIO, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\CommonIO.1.0.0.9\lib\net45\CommonIO.dll</HintPath>
+ <Reference Include="Emby.Common.Implementations">
+ <HintPath>..\ThirdParty\emby\Emby.Common.Implementations.dll</HintPath>
+ </Reference>
+ <Reference Include="Emby.Server.Core">
+ <HintPath>..\ThirdParty\emby\Emby.Server.Core.dll</HintPath>
</Reference>
<Reference Include="ImageMagickSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ImageMagickSharp.1.0.0.18\lib\net45\ImageMagickSharp.dll</HintPath>
</Reference>
- <Reference Include="Patterns.Logging, Version=1.0.5494.41209, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Patterns.Logging.1.0.0.2\lib\portable-net45+sl4+wp71+win8+wpa81\Patterns.Logging.dll</HintPath>
+ <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
+ <HintPath>..\packages\NLog.4.4.0-betaV15\lib\net45\NLog.dll</HintPath>
+ <Private>True</Private>
</Reference>
- <Reference Include="ServiceStack.Interfaces">
- <HintPath>..\ThirdParty\ServiceStack\ServiceStack.Interfaces.dll</HintPath>
+ <Reference Include="ServiceStack.Text, Version=4.5.4.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\ServiceStack.Text.4.5.4\lib\net45\ServiceStack.Text.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="SharpCompress, Version=0.14.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\SharpCompress.0.14.0\lib\net45\SharpCompress.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="SimpleInjector, Version=3.2.4.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
+ <HintPath>..\packages\SimpleInjector.3.2.4\lib\net45\SimpleInjector.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
+ <HintPath>..\packages\SQLitePCLRaw.core.1.1.1\lib\net45\SQLitePCLRaw.core.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="SQLitePCLRaw.provider.sqlite3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=62684c7b4f184e3f, processorArchitecture=MSIL">
+ <HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
+ <Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
- <Reference Include="System.Data.SQLite, Version=1.0.103.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
- <HintPath>..\packages\System.Data.SQLite.Core.1.0.103\lib\net46\System.Data.SQLite.dll</HintPath>
- <Private>True</Private>
- </Reference>
<Reference Include="System.Drawing" />
+ <Reference Include="System.IO.Compression" />
<Reference Include="System.Management" />
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceProcess" />
+ <Reference Include="System.Transactions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -98,9 +117,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="..\MediaBrowser.Server.Implementations\Persistence\SqliteExtensions.cs">
- <Link>Native\SqliteExtensions.cs</Link>
- </Compile>
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
@@ -118,12 +134,10 @@
</Compile>
<Compile Include="MainStartup.cs" />
<Compile Include="Native\LnkShortcutHandler.cs" />
- <Compile Include="Native\DbConnector.cs" />
<Compile Include="Native\LoopbackUtil.cs" />
+ <Compile Include="Native\PowerManagement.cs" />
<Compile Include="Native\Standby.cs" />
<Compile Include="Native\ServerAuthorization.cs" />
- <Compile Include="Native\WindowsApp.cs" />
- <Compile Include="Networking\CertificateGenerator.cs" />
<Compile Include="Networking\NativeMethods.cs" />
<Compile Include="Networking\NetworkManager.cs" />
<Compile Include="Networking\NetworkShares.cs" />
@@ -141,6 +155,7 @@
<DependentUpon>SplashForm.cs</DependentUpon>
</Compile>
<Compile Include="Updates\ApplicationUpdater.cs" />
+ <Compile Include="WindowsAppHost.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@@ -608,6 +623,9 @@
<Content Include="x64\IM_MOD_RL_yuv_.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="x64\sqlite3.dll">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="x86\CORE_RL_bzlib_.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -1048,20 +1066,47 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\Images\mb3logo800.png" />
+ <Content Include="x86\sqlite3.dll">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\BDInfo\BDInfo.csproj">
+ <Project>{88ae38df-19d7-406f-a6a9-09527719a21e}</Project>
+ <Name>BDInfo</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\DvdLib\DvdLib.csproj">
+ <Project>{713f42b5-878e-499d-a878-e4c652b1d5e8}</Project>
+ <Name>DvdLib</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Emby.Dlna\Emby.Dlna.csproj">
+ <Project>{805844ab-e92f-45e6-9d99-4f6d48d129a5}</Project>
+ <Name>Emby.Dlna</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Emby.Drawing.ImageMagick\Emby.Drawing.ImageMagick.csproj">
+ <Project>{6cfee013-6e7c-432b-ac37-cabf0880c69a}</Project>
+ <Name>Emby.Drawing.ImageMagick</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Emby.Drawing.Net\Emby.Drawing.Net.csproj">
+ <Project>{c97a239e-a96c-4d64-a844-ccf8cc30aecb}</Project>
+ <Name>Emby.Drawing.Net</Name>
+ </ProjectReference>
<ProjectReference Include="..\Emby.Drawing\Emby.Drawing.csproj">
<Project>{08fff49b-f175-4807-a2b5-73b0ebd9f716}</Project>
<Name>Emby.Drawing</Name>
</ProjectReference>
+ <ProjectReference Include="..\Emby.Photos\Emby.Photos.csproj">
+ <Project>{89ab4548-770d-41fd-a891-8daff44f452c}</Project>
+ <Name>Emby.Photos</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Emby.Server.Implementations\Emby.Server.Implementations.csproj">
+ <Project>{e383961b-9356-4d5d-8233-9a1079d03055}</Project>
+ <Name>Emby.Server.Implementations</Name>
+ </ProjectReference>
<ProjectReference Include="..\MediaBrowser.Api\MediaBrowser.Api.csproj">
<Project>{4fd51ac5-2c16-4308-a993-c3a84f3b4582}</Project>
<Name>MediaBrowser.Api</Name>
</ProjectReference>
- <ProjectReference Include="..\MediaBrowser.Common.Implementations\MediaBrowser.Common.Implementations.csproj">
- <Project>{c4d2573a-3fd3-441f-81af-174ac4cd4e1d}</Project>
- <Name>MediaBrowser.Common.Implementations</Name>
- </ProjectReference>
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj">
<Project>{9142eefa-7570-41e1-bfcc-468bb571af2f}</Project>
<Name>MediaBrowser.Common</Name>
@@ -1070,10 +1115,6 @@
<Project>{17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2}</Project>
<Name>MediaBrowser.Controller</Name>
</ProjectReference>
- <ProjectReference Include="..\MediaBrowser.Dlna\MediaBrowser.Dlna.csproj">
- <Project>{734098eb-6dc1-4dd0-a1ca-3140dcd2737c}</Project>
- <Name>MediaBrowser.Dlna</Name>
- </ProjectReference>
<ProjectReference Include="..\MediaBrowser.LocalMetadata\MediaBrowser.LocalMetadata.csproj">
<Project>{7ef9f3e0-697d-42f3-a08f-19deb5f84392}</Project>
<Name>MediaBrowser.LocalMetadata</Name>
@@ -1106,20 +1147,28 @@
<Project>{23499896-b135-4527-8574-c26e926ea99e}</Project>
<Name>MediaBrowser.XbmcMetadata</Name>
</ProjectReference>
+ <ProjectReference Include="..\OpenSubtitlesHandler\OpenSubtitlesHandler.csproj">
+ <Project>{4a4402d4-e910-443b-b8fc-2c18286a2ca0}</Project>
+ <Name>OpenSubtitlesHandler</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\RSSDP\RSSDP.csproj">
+ <Project>{21002819-c39a-4d3e-be83-2a276a77fb1f}</Project>
+ <Name>RSSDP</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ServiceStack\ServiceStack.csproj">
+ <Project>{680a1709-25eb-4d52-a87f-ee03ffd94baa}</Project>
+ <Name>ServiceStack</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\SocketHttpListener.Portable\SocketHttpListener.Portable.csproj">
+ <Project>{4f26d5d8-a7b0-42b3-ba42-7cb7d245934e}</Project>
+ <Name>SocketHttpListener.Portable</Name>
+ </ProjectReference>
</ItemGroup>
- <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
- <Import Project="..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets')" />
- <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
- <PropertyGroup>
- <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
- </PropertyGroup>
- <Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.103\build\net46\System.Data.SQLite.Core.targets'))" />
- </Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
diff --git a/MediaBrowser.ServerApplication/Native/DbConnector.cs b/MediaBrowser.ServerApplication/Native/DbConnector.cs
deleted file mode 100644
index f403ce2ce..000000000
--- a/MediaBrowser.ServerApplication/Native/DbConnector.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System.Data;
-using System.Threading.Tasks;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.Server.Implementations.Persistence;
-
-namespace MediaBrowser.ServerApplication.Native
-{
- public class DbConnector : IDbConnector
- {
- private readonly ILogger _logger;
-
- public DbConnector(ILogger logger)
- {
- _logger = logger;
- }
-
- public Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null)
- {
- return SqliteExtensions.ConnectToDb(dbPath, isReadOnly, enablePooling, cacheSize, _logger);
- }
- }
-} \ No newline at end of file
diff --git a/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs b/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs
index dc1e3c79b..91ff7033e 100644
--- a/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs
+++ b/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs
@@ -3,11 +3,11 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
-using CommonIO;
+using MediaBrowser.Model.IO;
namespace MediaBrowser.ServerApplication.Native
{
- public class LnkShortcutHandler : IShortcutHandler
+ public class LnkShortcutHandler :IShortcutHandler
{
public string Extension
{
diff --git a/MediaBrowser.ServerApplication/Native/PowerManagement.cs b/MediaBrowser.ServerApplication/Native/PowerManagement.cs
new file mode 100644
index 000000000..0bd3db1da
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/PowerManagement.cs
@@ -0,0 +1,17 @@
+using MediaBrowser.Model.System;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ public class PowerManagement : IPowerManagement
+ {
+ public void PreventSystemStandby()
+ {
+ MainStartup.Invoke(Standby.PreventSleep);
+ }
+
+ public void AllowSystemStandby()
+ {
+ MainStartup.Invoke(Standby.AllowSleep);
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/Native/RegisterServer.bat b/MediaBrowser.ServerApplication/Native/RegisterServer.bat
index 85baa0d03..504df2199 100644
--- a/MediaBrowser.ServerApplication/Native/RegisterServer.bat
+++ b/MediaBrowser.ServerApplication/Native/RegisterServer.bat
@@ -26,6 +26,9 @@ netsh advfirewall firewall delete rule name="Emby Server"
netsh advfirewall firewall add rule name="Emby Server" dir=in action=allow protocol=TCP program=%4 enable=yes
netsh advfirewall firewall add rule name="Emby Server" dir=in action=allow protocol=UDP program=%4 enable=yes
+netsh advfirewall firewall add rule name="mediabrowser.serverapplication.exe" dir=in action=allow protocol=TCP program=%4 enable=yes
+netsh advfirewall firewall add rule name="mediabrowser.serverapplication.exe" dir=in action=allow protocol=UDP program=%4 enable=yes
+
:DONE
Exit \ No newline at end of file
diff --git a/MediaBrowser.ServerApplication/Native/WindowsApp.cs b/MediaBrowser.ServerApplication/Native/WindowsApp.cs
deleted file mode 100644
index 7ebede40c..000000000
--- a/MediaBrowser.ServerApplication/Native/WindowsApp.cs
+++ /dev/null
@@ -1,262 +0,0 @@
-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 CommonIO;
-using MediaBrowser.Model.System;
-using MediaBrowser.Server.Implementations.Persistence;
-using MediaBrowser.Server.Startup.Common.FFMpeg;
-using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem;
-
-namespace MediaBrowser.ServerApplication.Native
-{
- public class WindowsApp : INativeApp
- {
- private readonly IFileSystem _fileSystem;
- private readonly ILogger _logger;
-
- public WindowsApp(IFileSystem fileSystem, ILogger logger)
- {
- _fileSystem = fileSystem;
- _logger = logger;
- }
-
- public List<Assembly> GetAssembliesWithParts()
- {
- var list = new List<Assembly>();
-
- if (!System.Environment.Is64BitProcess)
- {
- //list.Add(typeof(PismoIsoManager).Assembly);
- }
-
- list.Add(GetType().Assembly);
-
- return list;
- }
-
- public void AuthorizeServer(int udpPort, int httpServerPort, int httpsPort, string applicationPath, string tempDirectory)
- {
- ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsPort, applicationPath, tempDirectory);
- }
-
- public NativeEnvironment Environment
- {
- get
- {
- return new NativeEnvironment
- {
- OperatingSystem = OperatingSystem.Windows,
- SystemArchitecture = System.Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86,
- OperatingSystemVersionString = System.Environment.OSVersion.VersionString
- };
- }
- }
-
- public bool SupportsLibraryMonitor
- {
- get { return true; }
- }
-
- public bool SupportsRunningAsService
- {
- get
- {
- return true;
- }
- }
-
- public bool IsRunningAsService
- {
- get;
- set;
- }
-
- public bool CanSelfRestart
- {
- get
- {
- return MainStartup.CanSelfRestart;
- }
- }
-
- public bool SupportsAutoRunAtStartup
- {
- get
- {
- return true;
- }
- }
-
- public bool CanSelfUpdate
- {
- get
- {
- return MainStartup.CanSelfUpdate;
- }
- }
-
- public void Shutdown()
- {
- MainStartup.Shutdown();
- }
-
- public void Restart(StartupOptions startupOptions)
- {
- MainStartup.Restart();
- }
-
- public void ConfigureAutoRun(bool autorun)
- {
- var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
-
- var startupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
-
- if (autorun)
- {
- //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));
- 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"));
- }
- }
-
- public INetworkManager CreateNetworkManager(ILogger logger)
- {
- return new NetworkManager(logger);
- }
-
- public void PreventSystemStandby()
- {
- MainStartup.Invoke(Standby.PreventSleep);
- }
-
- public void AllowSystemStandby()
- {
- MainStartup.Invoke(Standby.AllowSleep);
- }
-
- 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)
- {
- var process = new Process
- {
- StartInfo = new ProcessStartInfo
- {
- FileName = url
- },
-
- EnableRaisingEvents = true,
- };
-
- process.Exited += ProcessExited;
-
- try
- {
- process.Start();
- }
- catch (Exception ex)
- {
- _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)
- {
- LoopUtil.Run(appName);
- }
-
- 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)
- {
- _logger.Info("Found potential windows firewall rule blocking Emby Server: " + data);
- }
-
- //var parts = data.Split('\n');
-
- //return parts.Length > 4;
- //return Confirm();
- return false;
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error querying windows firewall", ex);
-
- // Hate having to do this
- try
- {
- process.Kill();
- }
- catch (Exception ex1)
- {
- _logger.ErrorException("Error killing process", ex1);
- }
-
- throw;
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/MediaBrowser.ServerApplication/Networking/CertificateGenerator.cs b/MediaBrowser.ServerApplication/Networking/CertificateGenerator.cs
deleted file mode 100644
index a7b0d6c32..000000000
--- a/MediaBrowser.ServerApplication/Networking/CertificateGenerator.cs
+++ /dev/null
@@ -1,244 +0,0 @@
-using MediaBrowser.Model.Logging;
-using System;
-using System.IO;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace MediaBrowser.ServerApplication.Networking
-{
- // Copied from: http://blogs.msdn.com/b/dcook/archive/2014/05/16/9143036.aspx
- // In case anybody is interested, source code is attached and is free for use by anybody as long as you don't hold me or Microsoft liable for it --
- // I have no idea whether this is actually the right or best way to do this. Give it the X500 distinguished name, validity start and end dates,
- // and an optional password for encrypting the key data, and it will give you the PFX file data. Let me know if you find any bugs or have any suggestions.
- internal class CertificateGenerator
- {
- internal static void CreateSelfSignCertificatePfx(
- string fileName,
- string hostname,
- ILogger logger)
- {
- if (string.IsNullOrWhiteSpace(fileName))
- {
- throw new ArgumentNullException("fileName");
- }
-
- string x500 = string.Format("CN={0}", hostname);
-
- DateTime startTime = DateTime.Now.AddDays(-2);
- DateTime endTime = DateTime.Now.AddYears(10);
-
- byte[] pfxData = CreateSelfSignCertificatePfx(
- x500,
- startTime,
- endTime);
-
- File.WriteAllBytes(fileName, pfxData);
- }
-
- private static byte[] CreateSelfSignCertificatePfx(
- string x500,
- DateTime startTime,
- DateTime endTime)
- {
- byte[] pfxData;
-
- if (x500 == null)
- {
- x500 = "";
- }
-
- SystemTime startSystemTime = ToSystemTime(startTime);
- SystemTime endSystemTime = ToSystemTime(endTime);
- string containerName = Guid.NewGuid().ToString();
-
- GCHandle dataHandle = new GCHandle();
- IntPtr providerContext = IntPtr.Zero;
- IntPtr cryptKey = IntPtr.Zero;
- IntPtr certContext = IntPtr.Zero;
- IntPtr certStore = IntPtr.Zero;
- IntPtr storeCertContext = IntPtr.Zero;
- IntPtr passwordPtr = IntPtr.Zero;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- Check(NativeMethods.CryptAcquireContextW(
- out providerContext,
- containerName,
- null,
- 1, // PROV_RSA_FULL
- 8)); // CRYPT_NEWKEYSET
-
- Check(NativeMethods.CryptGenKey(
- providerContext,
- 1, // AT_KEYEXCHANGE
- 1 | 2048 << 16, // CRYPT_EXPORTABLE 2048 bit key
- out cryptKey));
-
- IntPtr errorStringPtr;
- int nameDataLength = 0;
- byte[] nameData;
-
- // errorStringPtr gets a pointer into the middle of the x500 string,
- // so x500 needs to be pinned until after we've copied the value
- // of errorStringPtr.
- dataHandle = GCHandle.Alloc(x500, GCHandleType.Pinned);
-
- if (!NativeMethods.CertStrToNameW(
- 0x00010001, // X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
- dataHandle.AddrOfPinnedObject(),
- 3, // CERT_X500_NAME_STR = 3
- IntPtr.Zero,
- null,
- ref nameDataLength,
- out errorStringPtr))
- {
- string error = Marshal.PtrToStringUni(errorStringPtr);
- throw new ArgumentException(error);
- }
-
- nameData = new byte[nameDataLength];
-
- if (!NativeMethods.CertStrToNameW(
- 0x00010001, // X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
- dataHandle.AddrOfPinnedObject(),
- 3, // CERT_X500_NAME_STR = 3
- IntPtr.Zero,
- nameData,
- ref nameDataLength,
- out errorStringPtr))
- {
- string error = Marshal.PtrToStringUni(errorStringPtr);
- throw new ArgumentException(error);
- }
-
- dataHandle.Free();
-
- dataHandle = GCHandle.Alloc(nameData, GCHandleType.Pinned);
- CryptoApiBlob nameBlob = new CryptoApiBlob(
- nameData.Length,
- dataHandle.AddrOfPinnedObject());
-
- CryptKeyProviderInformation kpi = new CryptKeyProviderInformation();
- kpi.ContainerName = containerName;
- kpi.ProviderType = 1; // PROV_RSA_FULL
- kpi.KeySpec = 1; // AT_KEYEXCHANGE
-
- CryptAlgorithmIdentifier sha256Identifier = new CryptAlgorithmIdentifier();
- sha256Identifier.pszObjId = "1.2.840.113549.1.1.11";
-
- certContext = NativeMethods.CertCreateSelfSignCertificate(
- providerContext,
- ref nameBlob,
- 0,
- ref kpi,
- ref sha256Identifier,
- ref startSystemTime,
- ref endSystemTime,
- IntPtr.Zero);
- Check(certContext != IntPtr.Zero);
- dataHandle.Free();
-
- certStore = NativeMethods.CertOpenStore(
- "Memory", // sz_CERT_STORE_PROV_MEMORY
- 0,
- IntPtr.Zero,
- 0x2000, // CERT_STORE_CREATE_NEW_FLAG
- IntPtr.Zero);
- Check(certStore != IntPtr.Zero);
-
- Check(NativeMethods.CertAddCertificateContextToStore(
- certStore,
- certContext,
- 1, // CERT_STORE_ADD_NEW
- out storeCertContext));
-
- NativeMethods.CertSetCertificateContextProperty(
- storeCertContext,
- 2, // CERT_KEY_PROV_INFO_PROP_ID
- 0,
- ref kpi);
-
- CryptoApiBlob pfxBlob = new CryptoApiBlob();
- Check(NativeMethods.PFXExportCertStoreEx(
- certStore,
- ref pfxBlob,
- passwordPtr,
- IntPtr.Zero,
- 7)); // EXPORT_PRIVATE_KEYS | REPORT_NO_PRIVATE_KEY | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
-
- pfxData = new byte[pfxBlob.DataLength];
- dataHandle = GCHandle.Alloc(pfxData, GCHandleType.Pinned);
- pfxBlob.Data = dataHandle.AddrOfPinnedObject();
- Check(NativeMethods.PFXExportCertStoreEx(
- certStore,
- ref pfxBlob,
- passwordPtr,
- IntPtr.Zero,
- 7)); // EXPORT_PRIVATE_KEYS | REPORT_NO_PRIVATE_KEY | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
- dataHandle.Free();
- }
- finally
- {
- if (passwordPtr != IntPtr.Zero)
- {
- Marshal.ZeroFreeCoTaskMemUnicode(passwordPtr);
- }
-
- if (dataHandle.IsAllocated)
- {
- dataHandle.Free();
- }
-
- if (certContext != IntPtr.Zero)
- {
- NativeMethods.CertFreeCertificateContext(certContext);
- }
-
- if (storeCertContext != IntPtr.Zero)
- {
- NativeMethods.CertFreeCertificateContext(storeCertContext);
- }
-
- if (certStore != IntPtr.Zero)
- {
- NativeMethods.CertCloseStore(certStore, 0);
- }
-
- if (cryptKey != IntPtr.Zero)
- {
- NativeMethods.CryptDestroyKey(cryptKey);
- }
-
- if (providerContext != IntPtr.Zero)
- {
- NativeMethods.CryptReleaseContext(providerContext, 0);
- NativeMethods.CryptAcquireContextW(
- out providerContext,
- containerName,
- null,
- 1, // PROV_RSA_FULL
- 0x10); // CRYPT_DELETEKEYSET
- }
- }
-
- return pfxData;
- }
-
- private static SystemTime ToSystemTime(DateTime dateTime)
- {
- long fileTime = dateTime.ToFileTime();
- SystemTime systemTime;
- Check(NativeMethods.FileTimeToSystemTime(ref fileTime, out systemTime));
- return systemTime;
- }
-
- private static void Check(bool nativeCallSucceeded)
- {
- if (!nativeCallSucceeded)
- {
- int error = Marshal.GetHRForLastWin32Error();
- Marshal.ThrowExceptionForHR(error);
- }
- }
- }
-}
diff --git a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs
index ed60de9d2..6d3d96e19 100644
--- a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs
+++ b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs
@@ -1,6 +1,4 @@
-using MediaBrowser.Common.Implementations.Networking;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Model.IO;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
@@ -15,7 +13,7 @@ namespace MediaBrowser.ServerApplication.Networking
/// <summary>
/// Class NetUtils
/// </summary>
- public class NetworkManager : BaseNetworkManager, INetworkManager
+ public class NetworkManager : Emby.Common.Implementations.Networking.NetworkManager
{
public NetworkManager(ILogger logger)
: base(logger)
@@ -27,7 +25,7 @@ namespace MediaBrowser.ServerApplication.Networking
/// </summary>
/// <param name="path">The path.</param>
/// <returns>IEnumerable{NetworkShare}.</returns>
- public IEnumerable<NetworkShare> GetNetworkShares(string path)
+ public override IEnumerable<NetworkShare> GetNetworkShares(string path)
{
Logger.Info("Getting network shares from {0}", path);
return new ShareCollection(path).OfType<Share>().Select(ToNetworkShare);
@@ -150,7 +148,7 @@ namespace MediaBrowser.ServerApplication.Networking
/// Gets available devices within the domain
/// </summary>
/// <returns>PC's in the Domain</returns>
- public IEnumerable<FileSystemEntryInfo> GetNetworkDevices()
+ public override IEnumerable<FileSystemEntryInfo> GetNetworkDevices()
{
return GetNetworkDevicesInternal().Select(c => new FileSystemEntryInfo
{
@@ -161,16 +159,6 @@ namespace MediaBrowser.ServerApplication.Networking
}
/// <summary>
- /// Generates a self signed certificate at the locatation specified by <paramref name="certificatePath"/>.
- /// </summary>
- /// <param name="certificatePath">The path to generate the certificate.</param>
- /// <param name="hostname">The common name for the certificate.</param>
- public void GenerateSelfSignedSslCertificate(string certificatePath, string hostname)
- {
- CertificateGenerator.CreateSelfSignCertificatePfx(certificatePath, hostname, Logger);
- }
-
- /// <summary>
/// Gets the network prefix.
/// </summary>
/// <value>The network prefix.</value>
diff --git a/MediaBrowser.ServerApplication/ServerNotifyIcon.cs b/MediaBrowser.ServerApplication/ServerNotifyIcon.cs
index 7805c0d68..c421dd9eb 100644
--- a/MediaBrowser.ServerApplication/ServerNotifyIcon.cs
+++ b/MediaBrowser.ServerApplication/ServerNotifyIcon.cs
@@ -1,11 +1,11 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Localization;
using MediaBrowser.Model.Logging;
-using MediaBrowser.Server.Startup.Common.Browser;
using System;
using System.ComponentModel;
using System.Windows.Forms;
+using Emby.Server.Implementations.Browser;
+using MediaBrowser.Model.Globalization;
namespace MediaBrowser.ServerApplication
{
diff --git a/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs b/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs
index 08c8a4dea..aa8679bd5 100644
--- a/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs
+++ b/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs
@@ -37,11 +37,6 @@ namespace MediaBrowser.ServerApplication.Updates
logger.Info("Copying updater dependencies to temporary location");
File.Copy(source, tempUpdaterDll, true);
var product = "server";
- // Our updater needs SS and ionic
- source = Path.Combine(systemPath, "ServiceStack.Text.dll");
- File.Copy(source, Path.Combine(tempPath, "ServiceStack.Text.dll"), true);
- source = Path.Combine(systemPath, "SharpCompress.dll");
- File.Copy(source, Path.Combine(tempPath, "SharpCompress.dll"), true);
logger.Info("Starting updater process.");
@@ -49,10 +44,20 @@ 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);
+
+ Process.Start(new ProcessStartInfo
+ {
+ FileName = tempUpdater,
+ Arguments = args,
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ ErrorDialog = false,
+ WindowStyle = ProcessWindowStyle.Hidden,
+ WorkingDirectory = Path.GetDirectoryName(tempUpdater)
+ });
// That's it. The installer will do the work once we exit
}
diff --git a/MediaBrowser.ServerApplication/WindowsAppHost.cs b/MediaBrowser.ServerApplication/WindowsAppHost.cs
new file mode 100644
index 000000000..c2cdb9ab0
--- /dev/null
+++ b/MediaBrowser.ServerApplication/WindowsAppHost.cs
@@ -0,0 +1,215 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Reflection;
+using Emby.Server.Core;
+using Emby.Server.Implementations;
+using Emby.Server.Implementations.EntryPoints;
+using Emby.Server.Implementations.FFMpeg;
+using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Logging;
+using MediaBrowser.Model.System;
+using MediaBrowser.ServerApplication.Native;
+
+namespace MediaBrowser.ServerApplication
+{
+ public class WindowsAppHost : ApplicationHost
+ {
+ 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)
+ {
+ }
+
+ public override bool IsRunningAsService
+ {
+ get { return MainStartup.IsRunningAsService; }
+ }
+
+ protected override FFMpegInstallInfo GetFfmpegInstallInfo()
+ {
+ var info = new FFMpegInstallInfo();
+
+ info.FFMpegFilename = "ffmpeg.exe";
+ info.FFProbeFilename = "ffprobe.exe";
+ info.Version = "20160410";
+ info.ArchiveType = "7z";
+ info.DownloadUrls = GetDownloadUrls();
+
+ return info;
+ }
+
+ private string[] GetDownloadUrls()
+ {
+ switch (EnvironmentInfo.SystemArchitecture)
+ {
+ 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"
+ };
+ }
+
+ return new string[] { };
+ }
+
+ protected override void RestartInternal()
+ {
+ MainStartup.Restart();
+ }
+
+ protected override List<Assembly> GetAssembliesWithPartsInternal()
+ {
+ var list = new List<Assembly>();
+
+ if (!Environment.Is64BitProcess)
+ {
+ //list.Add(typeof(PismoIsoManager).Assembly);
+ }
+
+ list.Add(GetType().Assembly);
+
+ return list;
+ }
+
+ protected override void ShutdownInternal()
+ {
+ MainStartup.Shutdown();
+ }
+
+ protected override void AuthorizeServer()
+ {
+ ServerAuthorization.AuthorizeServer(UdpServerEntryPoint.PortNumber,
+ ServerConfigurationManager.Configuration.HttpServerPortNumber,
+ ServerConfigurationManager.Configuration.HttpsPortNumber,
+ MainStartup.ApplicationPath,
+ ConfigurationManager.CommonApplicationPaths.TempDirectory);
+ }
+
+ protected override void ConfigureAutoRunInternal(bool autorun)
+ {
+ var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
+
+ var startupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
+
+ if (autorun)
+ {
+ //Copy our shortut into the startup folder for this user
+ var targetPath = Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk");
+ FileSystemManager.CreateDirectory(Path.GetDirectoryName(targetPath));
+ File.Copy(shortcutPath, targetPath, true);
+ }
+ else
+ {
+ //Remove our shortcut from the startup folder for this user
+ FileSystemManager.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
+ }
+ }
+
+ protected override bool SupportsDualModeSockets
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ 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);
+
+ 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)
+ {
+ Logger.Info("Found potential windows firewall rule blocking Emby Server: " + data);
+ }
+
+ //var parts = data.Split('\n');
+
+ //return parts.Length > 4;
+ //return Confirm();
+ return false;
+ }
+ catch (Exception ex)
+ {
+ Logger.ErrorException("Error querying windows firewall", ex);
+
+ // Hate having to do this
+ try
+ {
+ process.Kill();
+ }
+ catch (Exception ex1)
+ {
+ Logger.ErrorException("Error killing process", ex1);
+ }
+
+ throw;
+ }
+ }
+ }
+
+ }
+}
diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config
index 63d3bab8a..2cebb9aea 100644
--- a/MediaBrowser.ServerApplication/packages.config
+++ b/MediaBrowser.ServerApplication/packages.config
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="CommonIO" version="1.0.0.9" targetFramework="net45" />
<package id="ImageMagickSharp" version="1.0.0.18" targetFramework="net45" />
- <package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
- <package id="System.Data.SQLite.Core" version="1.0.103" targetFramework="net462" />
+ <package id="NLog" version="4.4.0-betaV15" targetFramework="net462" />
+ <package id="ServiceStack.Text" version="4.5.4" targetFramework="net462" />
+ <package id="SharpCompress" version="0.14.0" targetFramework="net462" />
+ <package id="SimpleInjector" version="3.2.4" targetFramework="net462" />
+ <package id="SQLitePCLRaw.core" version="1.1.1" targetFramework="net462" />
+ <package id="SQLitePCLRaw.provider.sqlite3.net45" version="1.1.1" targetFramework="net462" />
</packages> \ No newline at end of file