diff --git a/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs b/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs
new file mode 100644
index 0000000000..39690eb07e
--- /dev/null
+++ b/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs
@@ -0,0 +1,87 @@
+using MediaBrowser.Model.IO;
+using SharpCompress.Archive.SevenZip;
+using SharpCompress.Common;
+using SharpCompress.Reader;
+using System.IO;
+
+namespace MediaBrowser.Common.Implementations.Archiving
+{
+ ///
+ /// Class DotNetZipClient
+ ///
+ public class ZipClient : IZipClient
+ {
+ ///
+ /// Extracts all.
+ ///
+ /// The source file.
+ /// The target path.
+ /// if set to true [overwrite existing files].
+ public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var fileStream = File.OpenRead(sourceFile))
+ {
+ ExtractAll(fileStream, targetPath, overwriteExistingFiles);
+ }
+ }
+
+ ///
+ /// Extracts all.
+ ///
+ /// The source.
+ /// The target path.
+ /// if set to true [overwrite existing files].
+ public void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var reader = ReaderFactory.Open(source))
+ {
+ var options = ExtractOptions.ExtractFullPath;
+
+ if (overwriteExistingFiles)
+ {
+ options = options | ExtractOptions.Overwrite;
+ }
+
+ reader.WriteAllToDirectory(targetPath, options);
+ }
+ }
+
+ ///
+ /// Extracts all from7z.
+ ///
+ /// The source file.
+ /// The target path.
+ /// if set to true [overwrite existing files].
+ public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var fileStream = File.OpenRead(sourceFile))
+ {
+ ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
+ }
+ }
+
+ ///
+ /// Extracts all from7z.
+ ///
+ /// The source.
+ /// The target path.
+ /// if set to true [overwrite existing files].
+ public void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var archive = SevenZipArchive.Open(source))
+ {
+ using (var reader = archive.ExtractAllEntries())
+ {
+ var options = ExtractOptions.ExtractFullPath;
+
+ if (overwriteExistingFiles)
+ {
+ options = options | ExtractOptions.Overwrite;
+ }
+
+ reader.WriteAllToDirectory(targetPath, options);
+ }
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
index c0ac6a4b3a..0d96df9a23 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
@@ -1,5 +1,6 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
+using MediaBrowser.Common.Implementations.Archiving;
using MediaBrowser.Common.Implementations.NetworkManagement;
using MediaBrowser.Common.Implementations.ScheduledTasks;
using MediaBrowser.Common.Implementations.Security;
@@ -10,6 +11,7 @@ using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Updates;
@@ -149,6 +151,12 @@ namespace MediaBrowser.Common.Implementations
/// The installation manager.
protected IInstallationManager InstallationManager { get; set; }
+ ///
+ /// Gets or sets the zip client.
+ ///
+ /// The zip client.
+ protected IZipClient ZipClient { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -202,12 +210,27 @@ namespace MediaBrowser.Common.Implementations
{
Resolve().AddTasks(GetExports(false));
- Task.Run(() => ConfigureAutoRunAtStartup());
+ Task.Run(() => ConfigureAutorun());
ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
});
}
+ ///
+ /// Configures the autorun.
+ ///
+ private void ConfigureAutorun()
+ {
+ try
+ {
+ ConfigureAutoRunAtStartup(ConfigurationManager.CommonConfiguration.RunAtStartup);
+ }
+ catch (Exception ex)
+ {
+ Logger.ErrorException("Error configuring autorun", ex);
+ }
+ }
+
///
/// Gets the composable part assemblies.
///
@@ -281,6 +304,9 @@ namespace MediaBrowser.Common.Implementations
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager);
RegisterSingleInstance(InstallationManager);
+
+ ZipClient = new ZipClient();
+ RegisterSingleInstance(ZipClient);
});
}
@@ -453,11 +479,6 @@ namespace MediaBrowser.Common.Implementations
}
}
- ///
- /// Defines the full path to our shortcut in the start menu
- ///
- protected abstract string ProductShortcutPath { get; }
-
///
/// Handles the ConfigurationUpdated event of the ConfigurationManager control.
///
@@ -466,32 +487,10 @@ namespace MediaBrowser.Common.Implementations
///
protected virtual void OnConfigurationUpdated(object sender, EventArgs e)
{
- ConfigureAutoRunAtStartup();
+ ConfigureAutorun();
}
- ///
- /// Configures the auto run at startup.
- ///
- private void ConfigureAutoRunAtStartup()
- {
- if (ConfigurationManager.CommonConfiguration.RunAtStartup)
- {
- //Copy our shortut into the startup folder for this user
- File.Copy(ProductShortcutPath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileName(ProductShortcutPath) ?? "MBstartup.lnk"), true);
- }
- else
- {
- //Remove our shortcut from the startup folder for this user
- try
- {
- File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileName(ProductShortcutPath) ?? "MBstartup.lnk"));
- }
- catch (FileNotFoundException)
- {
- //This is okay - trying to remove it anyway
- }
- }
- }
+ protected abstract void ConfigureAutoRunAtStartup(bool autorun);
///
/// Removes the plugin.
diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
index 79514b5cbd..11da950f7c 100644
--- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
+++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
@@ -37,6 +37,9 @@
Always
+
+ ..\packages\sharpcompress.0.10.1.3\lib\net40\SharpCompress.dll
+
@@ -58,6 +61,7 @@
Properties\SharedVersion.cs
+
diff --git a/MediaBrowser.Common.Implementations/packages.config b/MediaBrowser.Common.Implementations/packages.config
index 4be861cceb..d03cb14e07 100644
--- a/MediaBrowser.Common.Implementations/packages.config
+++ b/MediaBrowser.Common.Implementations/packages.config
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/MediaBrowser.Model/IO/IZipClient.cs b/MediaBrowser.Model/IO/IZipClient.cs
index c9e7e0db68..694c393aa0 100644
--- a/MediaBrowser.Model/IO/IZipClient.cs
+++ b/MediaBrowser.Model/IO/IZipClient.cs
@@ -22,5 +22,21 @@ namespace MediaBrowser.Model.IO
/// The target path.
/// if set to true [overwrite existing files].
void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles);
+
+ ///
+ /// Extracts all from7z.
+ ///
+ /// The source file.
+ /// The target path.
+ /// if set to true [overwrite existing files].
+ void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles);
+
+ ///
+ /// Extracts all from7z.
+ ///
+ /// The source.
+ /// The target path.
+ /// if set to true [overwrite existing files].
+ void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles);
}
}
diff --git a/MediaBrowser.Mono.userprefs b/MediaBrowser.Mono.userprefs
index 95fb57a897..80da5915d9 100644
--- a/MediaBrowser.Mono.userprefs
+++ b/MediaBrowser.Mono.userprefs
@@ -1,6 +1,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MediaBrowser.ServerApplication/EntryPoints/UdpServerEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs
similarity index 95%
rename from MediaBrowser.ServerApplication/EntryPoints/UdpServerEntryPoint.cs
rename to MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs
index 595d5c89fc..9c1a953b11 100644
--- a/MediaBrowser.ServerApplication/EntryPoints/UdpServerEntryPoint.cs
+++ b/MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs
@@ -5,7 +5,7 @@ using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations.Udp;
using System.Net.Sockets;
-namespace MediaBrowser.ServerApplication.EntryPoints
+namespace MediaBrowser.Server.Implementations.EntryPoints
{
///
/// Class UdpServerEntryPoint
@@ -35,6 +35,8 @@ namespace MediaBrowser.ServerApplication.EntryPoints
///
private readonly IHttpServer _httpServer;
+ public const int PortNumber = 7359;
+
///
/// Initializes a new instance of the class.
///
@@ -59,7 +61,7 @@ namespace MediaBrowser.ServerApplication.EntryPoints
try
{
- udpServer.Start(ApplicationHost.UdpServerPort);
+ udpServer.Start(PortNumber);
UdpServer = udpServer;
}
diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
index e44089cc16..f409b72059 100644
--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
@@ -113,6 +113,7 @@
+
diff --git a/MediaBrowser.Server.Mono/FFMpeg/FFMpegDownloader.cs b/MediaBrowser.Server.Mono/FFMpeg/FFMpegDownloader.cs
new file mode 100644
index 0000000000..cc268ef072
--- /dev/null
+++ b/MediaBrowser.Server.Mono/FFMpeg/FFMpegDownloader.cs
@@ -0,0 +1,36 @@
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.IO;
+using MediaBrowser.Common.Net;
+using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Logging;
+using MediaBrowser.Model.Net;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.ServerApplication.FFMpeg
+{
+ public class FFMpegDownloader
+ {
+ private readonly IHttpClient _httpClient;
+ private readonly IApplicationPaths _appPaths;
+ private readonly ILogger _logger;
+ private readonly IZipClient _zipClient;
+
+ public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient)
+ {
+ _logger = logger;
+ _appPaths = appPaths;
+ _httpClient = httpClient;
+ _zipClient = zipClient;
+ }
+
+ public Task GetFFMpegInfo()
+ {
+ return Task.FromResult (new FFMpegInfo());
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
index a97ab4facd..1c369daacb 100644
--- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
+++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
@@ -40,6 +40,9 @@
+
+
+
@@ -52,6 +55,25 @@
+
+ EntryPoints\StartupWizard.cs
+
+
+ Native\BrowserLauncher.cs
+
+
+
+
+
+ FFMpeg\FFMpegInfo.cs
+
+
+ ApplicationHost.cs
+
+
+
+
+
@@ -88,4 +110,10 @@
MediaBrowser.Api
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MediaBrowser.Server.Mono/Native/Assemblies.cs b/MediaBrowser.Server.Mono/Native/Assemblies.cs
new file mode 100644
index 0000000000..eae6366e13
--- /dev/null
+++ b/MediaBrowser.Server.Mono/Native/Assemblies.cs
@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Assemblies
+ ///
+ public static class Assemblies
+ {
+ ///
+ /// Gets the assemblies with parts.
+ ///
+ /// List{Assembly}.
+ public static List GetAssembliesWithParts()
+ {
+ var list = new List();
+
+ return list;
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Mono/Native/Autorun.cs b/MediaBrowser.Server.Mono/Native/Autorun.cs
new file mode 100644
index 0000000000..ee33c5967a
--- /dev/null
+++ b/MediaBrowser.Server.Mono/Native/Autorun.cs
@@ -0,0 +1,20 @@
+using System;
+using System.IO;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Autorun
+ ///
+ public static class Autorun
+ {
+ ///
+ /// Configures the specified autorun.
+ ///
+ /// if set to true [autorun].
+ public static void Configure(bool autorun)
+ {
+
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Mono/Native/HttpMessageHandlerFactory.cs b/MediaBrowser.Server.Mono/Native/HttpMessageHandlerFactory.cs
new file mode 100644
index 0000000000..5823a7e51b
--- /dev/null
+++ b/MediaBrowser.Server.Mono/Native/HttpMessageHandlerFactory.cs
@@ -0,0 +1,25 @@
+using System.Net;
+using System.Net.Cache;
+using System.Net.Http;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class HttpMessageHandlerFactory
+ ///
+ public static class HttpMessageHandlerFactory
+ {
+ ///
+ /// Gets the HTTP message handler.
+ ///
+ /// if set to true [enable HTTP compression].
+ /// HttpMessageHandler.
+ public static HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
+ {
+ return new HttpClientHandler
+ {
+ AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
+ };
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Mono/Native/NativeApp.cs b/MediaBrowser.Server.Mono/Native/NativeApp.cs
new file mode 100644
index 0000000000..bb47f6ea43
--- /dev/null
+++ b/MediaBrowser.Server.Mono/Native/NativeApp.cs
@@ -0,0 +1,25 @@
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class NativeApp
+ ///
+ public static class NativeApp
+ {
+ ///
+ /// Shutdowns this instance.
+ ///
+ public static void Shutdown()
+ {
+
+ }
+
+ ///
+ /// Restarts this instance.
+ ///
+ public static void Restart()
+ {
+
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Mono/Native/ServerAuthorization.cs b/MediaBrowser.Server.Mono/Native/ServerAuthorization.cs
new file mode 100644
index 0000000000..6f43a12c09
--- /dev/null
+++ b/MediaBrowser.Server.Mono/Native/ServerAuthorization.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Reflection;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Authorization
+ ///
+ public static class ServerAuthorization
+ {
+ ///
+ /// Authorizes the server.
+ ///
+ /// The HTTP server port.
+ /// The HTTP server URL prefix.
+ /// The web socket port.
+ /// The UDP port.
+ /// The temp directory.
+ public static void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int webSocketPort, int udpPort, string tempDirectory)
+ {
+
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Mono/Native/Sqlite.cs b/MediaBrowser.Server.Mono/Native/Sqlite.cs
new file mode 100644
index 0000000000..cc20952d73
--- /dev/null
+++ b/MediaBrowser.Server.Mono/Native/Sqlite.cs
@@ -0,0 +1,36 @@
+using System.Data;
+using System.Data.SQLite;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Sqlite
+ ///
+ public static class Sqlite
+ {
+ ///
+ /// Connects to db.
+ ///
+ /// The db path.
+ /// Task{IDbConnection}.
+ /// dbPath
+ public static async Task OpenDatabase(string dbPath)
+ {
+ var connectionstr = new SQLiteConnectionStringBuilder
+ {
+ PageSize = 4096,
+ CacheSize = 4096,
+ SyncMode = SynchronizationModes.Normal,
+ DataSource = dbPath,
+ JournalMode = SQLiteJournalModeEnum.Wal
+ };
+
+ var connection = new SQLiteConnection(connectionstr.ConnectionString);
+
+ await connection.OpenAsync().ConfigureAwait(false);
+
+ return connection;
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Mono/gtk-gui/gui.stetic b/MediaBrowser.Server.Mono/gtk-gui/gui.stetic
index d564b44466..81685442c3 100644
--- a/MediaBrowser.Server.Mono/gtk-gui/gui.stetic
+++ b/MediaBrowser.Server.Mono/gtk-gui/gui.stetic
@@ -1,6 +1,7 @@
+ ..
2.12
diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs
index 69de391a4d..706206d3a5 100644
--- a/MediaBrowser.ServerApplication/App.xaml.cs
+++ b/MediaBrowser.ServerApplication/App.xaml.cs
@@ -154,58 +154,5 @@ namespace MediaBrowser.ServerApplication
{
Dispatcher.Invoke(Shutdown);
}
-
- ///
- /// Opens the dashboard page.
- ///
- /// The page.
- /// The logged in user.
- /// The configuration manager.
- /// The app host.
- public static void OpenDashboardPage(string page, User loggedInUser, IServerConfigurationManager configurationManager, IServerApplicationHost appHost)
- {
- var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
- appHost.WebApplicationName + "/dashboard/" + page;
-
- OpenUrl(url);
- }
-
- ///
- /// Opens the URL.
- ///
- /// The URL.
- public static void OpenUrl(string url)
- {
- var process = new Process
- {
- StartInfo = new ProcessStartInfo
- {
- FileName = url
- },
-
- EnableRaisingEvents = true
- };
-
- process.Exited += ProcessExited;
-
- try
- {
- process.Start();
- }
- catch (Exception ex)
- {
- MessageBox.Show("There was an error launching your web browser. Please check your defualt browser settings.");
- }
- }
-
- ///
- /// Processes the exited.
- ///
- /// The sender.
- /// The instance containing the event data.
- static void ProcessExited(object sender, EventArgs e)
- {
- ((Process)sender).Dispose();
- }
}
}
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs
index e965166036..d0f7da73de 100644
--- a/MediaBrowser.ServerApplication/ApplicationHost.cs
+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs
@@ -24,7 +24,6 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.Sorting;
-using MediaBrowser.IsoMounter;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.MediaInfo;
@@ -36,6 +35,7 @@ using MediaBrowser.Server.Implementations.BdInfo;
using MediaBrowser.Server.Implementations.Configuration;
using MediaBrowser.Server.Implementations.Drawing;
using MediaBrowser.Server.Implementations.Dto;
+using MediaBrowser.Server.Implementations.EntryPoints;
using MediaBrowser.Server.Implementations.HttpServer;
using MediaBrowser.Server.Implementations.IO;
using MediaBrowser.Server.Implementations.Library;
@@ -46,16 +46,14 @@ using MediaBrowser.Server.Implementations.Providers;
using MediaBrowser.Server.Implementations.ServerManager;
using MediaBrowser.Server.Implementations.Session;
using MediaBrowser.Server.Implementations.WebSocket;
-using MediaBrowser.ServerApplication.Implementations;
+using MediaBrowser.ServerApplication.FFMpeg;
+using MediaBrowser.ServerApplication.Native;
using MediaBrowser.WebDashboard.Api;
using System;
using System.Collections.Generic;
-using System.Data.SQLite;
-using System.Diagnostics;
+using System.Data;
using System.IO;
using System.Linq;
-using System.Net;
-using System.Net.Cache;
using System.Net.Http;
using System.Reflection;
using System.Threading;
@@ -68,8 +66,6 @@ namespace MediaBrowser.ServerApplication
///
public class ApplicationHost : BaseApplicationHost, IServerApplicationHost
{
- internal const int UdpServerPort = 7359;
-
///
/// Gets the server kernel.
///
@@ -142,11 +138,6 @@ namespace MediaBrowser.ServerApplication
/// The provider manager.
private IProviderManager ProviderManager { get; set; }
///
- /// Gets or sets the zip client.
- ///
- /// The zip client.
- private IZipClient ZipClient { get; set; }
- ///
/// Gets or sets the HTTP server.
///
/// The HTTP server.
@@ -175,14 +166,6 @@ namespace MediaBrowser.ServerApplication
private IItemRepository ItemRepository { get; set; }
private INotificationsRepository NotificationsRepository { get; set; }
- ///
- /// The full path to our startmenu shortcut
- ///
- protected override string ProductShortcutPath
- {
- get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); }
- }
-
private Task _httpServerCreationTask;
///
@@ -256,9 +239,6 @@ namespace MediaBrowser.ServerApplication
RegisterSingleInstance(() => new BdInfoExaminer());
- ZipClient = new ZipClient();
- RegisterSingleInstance(ZipClient);
-
var mediaEncoderTask = RegisterMediaEncoder();
UserDataRepository = new SqliteUserDataRepository(ApplicationPaths, JsonSerializer, LogManager);
@@ -322,7 +302,7 @@ namespace MediaBrowser.ServerApplication
/// Task.
private async Task RegisterMediaEncoder()
{
- var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient).GetFFMpegInfo().ConfigureAwait(false);
+ var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient).GetFFMpegInfo().ConfigureAwait(false);
MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), ApplicationPaths, JsonSerializer, info.Path, info.ProbePath, info.Version);
RegisterSingleInstance(MediaEncoder);
@@ -407,27 +387,14 @@ namespace MediaBrowser.ServerApplication
/// The db path.
/// Task{IDbConnection}.
/// dbPath
- private static async Task ConnectToDb(string dbPath)
+ private static Task ConnectToDb(string dbPath)
{
if (string.IsNullOrEmpty(dbPath))
{
throw new ArgumentNullException("dbPath");
}
- var connectionstr = new SQLiteConnectionStringBuilder
- {
- PageSize = 4096,
- CacheSize = 4096,
- SyncMode = SynchronizationModes.Normal,
- DataSource = dbPath,
- JournalMode = SQLiteJournalModeEnum.Wal
- };
-
- var connection = new SQLiteConnection(connectionstr.ConnectionString);
-
- await connection.OpenAsync().ConfigureAwait(false);
-
- return connection;
+ return Sqlite.OpenDatabase(dbPath);
}
///
@@ -479,7 +446,7 @@ namespace MediaBrowser.ServerApplication
IsoManager.AddParts(GetExports());
SessionManager.AddParts(GetExports());
-
+
ImageProcessor.AddParts(GetExports());
}
@@ -530,7 +497,6 @@ namespace MediaBrowser.ServerApplication
{
NotifyPendingRestart();
}
-
}
///
@@ -547,7 +513,7 @@ namespace MediaBrowser.ServerApplication
Logger.ErrorException("Error sending server restart web socket message", ex);
}
- MainStartup.Restart();
+ NativeApp.Restart();
}
///
@@ -571,44 +537,44 @@ namespace MediaBrowser.ServerApplication
/// IEnumerable{Assembly}.
protected override IEnumerable GetComposablePartAssemblies()
{
+ var list = Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
+ .Select(LoadAssembly)
+ .Where(a => a != null)
+ .ToList();
+
// Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
// This will prevent the .dll file from getting locked, and allow us to replace it when needed
- foreach (var pluginAssembly in Directory
- .EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
- .Select(LoadAssembly).Where(a => a != null))
- {
- yield return pluginAssembly;
- }
// Include composable parts in the Api assembly
- yield return typeof(ApiEntryPoint).Assembly;
+ list.Add(typeof(ApiEntryPoint).Assembly);
// Include composable parts in the Dashboard assembly
- yield return typeof(DashboardInfo).Assembly;
+ list.Add(typeof(DashboardInfo).Assembly);
// Include composable parts in the Model assembly
- yield return typeof(SystemInfo).Assembly;
+ list.Add(typeof(SystemInfo).Assembly);
// Include composable parts in the Common assembly
- yield return typeof(IApplicationHost).Assembly;
+ list.Add(typeof(IApplicationHost).Assembly);
// Include composable parts in the Controller assembly
- yield return typeof(Kernel).Assembly;
+ list.Add(typeof(Kernel).Assembly);
// Include composable parts in the Providers assembly
- yield return typeof(ImagesByNameProvider).Assembly;
+ list.Add(typeof(ImagesByNameProvider).Assembly);
// Common implementations
- yield return typeof(TaskManager).Assembly;
+ list.Add(typeof(TaskManager).Assembly);
// Server implementations
- yield return typeof(ServerApplicationPaths).Assembly;
+ list.Add(typeof(ServerApplicationPaths).Assembly);
- // Pismo
- yield return typeof(PismoIsoManager).Assembly;
+ list.AddRange(Assemblies.GetAssembliesWithParts());
// Include composable parts in the running assembly
- yield return GetType().Assembly;
+ list.Add(GetType().Assembly);
+
+ return list;
}
private readonly string _systemId = Environment.MachineName.GetMD5().ToString();
@@ -667,7 +633,7 @@ namespace MediaBrowser.ServerApplication
Logger.ErrorException("Error sending server shutdown web socket message", ex);
}
- MainStartup.Shutdown();
+ NativeApp.Shutdown();
}
///
@@ -677,36 +643,16 @@ namespace MediaBrowser.ServerApplication
{
Logger.Info("Requesting administrative access to authorize http server");
- // Create a temp file path to extract the bat file to
- var tmpFile = Path.Combine(ConfigurationManager.CommonApplicationPaths.TempDirectory, Guid.NewGuid() + ".bat");
-
- // Extract the bat file
- using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.ServerApplication.RegisterServer.bat"))
+ try
{
- using (var fileStream = File.Create(tmpFile))
- {
- stream.CopyTo(fileStream);
- }
+ ServerAuthorization.AuthorizeServer(ServerConfigurationManager.Configuration.HttpServerPortNumber,
+ HttpServerUrlPrefix, ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber,
+ UdpServerEntryPoint.PortNumber,
+ ConfigurationManager.CommonApplicationPaths.TempDirectory);
}
-
- var startInfo = new ProcessStartInfo
+ catch (Exception ex)
{
- FileName = tmpFile,
-
- Arguments = string.Format("{0} {1} {2} {3}", ServerConfigurationManager.Configuration.HttpServerPortNumber,
- HttpServerUrlPrefix,
- UdpServerPort,
- ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber),
-
- CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Hidden,
- Verb = "runas",
- ErrorDialog = false
- };
-
- using (var process = Process.Start(startInfo))
- {
- process.WaitForExit();
+ Logger.ErrorException("Error authorizing server", ex);
}
}
@@ -716,8 +662,7 @@ namespace MediaBrowser.ServerApplication
/// The cancellation token.
/// The progress.
/// Task{CheckForUpdateResult}.
- public override async Task CheckForApplicationUpdate(CancellationToken cancellationToken,
- IProgress progress)
+ public override async Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress)
{
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
@@ -748,11 +693,12 @@ namespace MediaBrowser.ServerApplication
/// HttpMessageHandler.
protected override HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
{
- return new WebRequestHandler
- {
- CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
- AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
- };
+ return HttpMessageHandlerFactory.GetHttpMessageHandler(enableHttpCompression);
+ }
+
+ protected override void ConfigureAutoRunAtStartup(bool autorun)
+ {
+ Autorun.Configure(autorun);
}
}
}
diff --git a/MediaBrowser.ServerApplication/EntryPoints/StartupWizard.cs b/MediaBrowser.ServerApplication/EntryPoints/StartupWizard.cs
index 87578ef84c..1a5f9e2c35 100644
--- a/MediaBrowser.ServerApplication/EntryPoints/StartupWizard.cs
+++ b/MediaBrowser.ServerApplication/EntryPoints/StartupWizard.cs
@@ -3,9 +3,10 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
-using System.ComponentModel;
+using System;
using System.Linq;
-using System.Windows;
+using System.Windows.Forms;
+using MediaBrowser.ServerApplication.Native;
namespace MediaBrowser.ServerApplication.EntryPoints
{
@@ -31,9 +32,10 @@ namespace MediaBrowser.ServerApplication.EntryPoints
///
/// The app host.
/// The user manager.
- public StartupWizard(IServerApplicationHost appHost, IUserManager userManager, IServerConfigurationManager configurationManager)
+ public StartupWizard(IServerApplicationHost appHost, IUserManager userManager, IServerConfigurationManager configurationManager, ILogger logger)
{
_appHost = appHost;
+ _logger = logger;
_userManager = userManager;
_configurationManager = configurationManager;
}
@@ -58,9 +60,9 @@ namespace MediaBrowser.ServerApplication.EntryPoints
try
{
- App.OpenDashboardPage("wizardstart.html", user, _configurationManager, _appHost);
+ BrowserLauncher.OpenDashboardPage("wizardstart.html", user, _configurationManager, _appHost, _logger);
}
- catch (Win32Exception ex)
+ catch (Exception ex)
{
_logger.ErrorException("Error launching startup wizard", ex);
@@ -75,4 +77,4 @@ namespace MediaBrowser.ServerApplication.EntryPoints
{
}
}
-}
+}
\ No newline at end of file
diff --git a/MediaBrowser.ServerApplication/Implementations/FFMpegDownloader.cs b/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs
similarity index 93%
rename from MediaBrowser.ServerApplication/Implementations/FFMpegDownloader.cs
rename to MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs
index 1bc0b90f07..c43a85c87f 100644
--- a/MediaBrowser.ServerApplication/Implementations/FFMpegDownloader.cs
+++ b/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs
@@ -1,11 +1,9 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
-using SharpCompress.Archive.SevenZip;
-using SharpCompress.Common;
-using SharpCompress.Reader;
using System;
using System.Collections.Generic;
using System.IO;
@@ -14,13 +12,14 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
-namespace MediaBrowser.ServerApplication.Implementations
+namespace MediaBrowser.ServerApplication.FFMpeg
{
public class FFMpegDownloader
{
private readonly IHttpClient _httpClient;
private readonly IApplicationPaths _appPaths;
private readonly ILogger _logger;
+ private readonly IZipClient _zipClient;
private const string Version = "ffmpeg20130904";
@@ -37,11 +36,12 @@ namespace MediaBrowser.ServerApplication.Implementations
"https://www.dropbox.com/s/a81cb2ob23fwcfs/ffmpeg-20130904-git-f974289-win32-static.7z?dl=1"
};
- public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient)
+ public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient)
{
_logger = logger;
_appPaths = appPaths;
_httpClient = httpClient;
+ _zipClient = zipClient;
}
public async Task GetFFMpegInfo()
@@ -138,13 +138,7 @@ namespace MediaBrowser.ServerApplication.Implementations
private void Extract7zArchive(string archivePath, string targetPath)
{
- using (var archive = SevenZipArchive.Open(archivePath))
- {
- using (var reader = archive.ExtractAllEntries())
- {
- reader.WriteAllToDirectory(targetPath, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
- }
- }
+ _zipClient.ExtractAllFrom7z(archivePath, targetPath, true);
}
private void DeleteFile(string path)
@@ -305,11 +299,4 @@ namespace MediaBrowser.ServerApplication.Implementations
return path;
}
}
-
- public class FFMpegInfo
- {
- public string Path { get; set; }
- public string ProbePath { get; set; }
- public string Version { get; set; }
- }
}
diff --git a/MediaBrowser.ServerApplication/FFMpeg/FFMpegInfo.cs b/MediaBrowser.ServerApplication/FFMpeg/FFMpegInfo.cs
new file mode 100644
index 0000000000..147a9f7717
--- /dev/null
+++ b/MediaBrowser.ServerApplication/FFMpeg/FFMpegInfo.cs
@@ -0,0 +1,24 @@
+namespace MediaBrowser.ServerApplication.FFMpeg
+{
+ ///
+ /// Class FFMpegInfo
+ ///
+ public class FFMpegInfo
+ {
+ ///
+ /// Gets or sets the path.
+ ///
+ /// The path.
+ public string Path { get; set; }
+ ///
+ /// Gets or sets the probe path.
+ ///
+ /// The probe path.
+ public string ProbePath { get; set; }
+ ///
+ /// Gets or sets the version.
+ ///
+ /// The version.
+ public string Version { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/MediaBrowser.ServerApplication/Implementations/ffmpeg-20130904-git-f974289-win32-static.7z.REMOVED.git-id b/MediaBrowser.ServerApplication/FFMpeg/ffmpeg-20130904-git-f974289-win32-static.7z.REMOVED.git-id
similarity index 100%
rename from MediaBrowser.ServerApplication/Implementations/ffmpeg-20130904-git-f974289-win32-static.7z.REMOVED.git-id
rename to MediaBrowser.ServerApplication/FFMpeg/ffmpeg-20130904-git-f974289-win32-static.7z.REMOVED.git-id
diff --git a/MediaBrowser.ServerApplication/Implementations/ZipClient.cs b/MediaBrowser.ServerApplication/Implementations/ZipClient.cs
deleted file mode 100644
index e9e8645e9f..0000000000
--- a/MediaBrowser.ServerApplication/Implementations/ZipClient.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using MediaBrowser.Model.IO;
-using SharpCompress.Common;
-using SharpCompress.Reader;
-using System.IO;
-
-namespace MediaBrowser.ServerApplication.Implementations
-{
- ///
- /// Class DotNetZipClient
- ///
- public class ZipClient : IZipClient
- {
- ///
- /// Extracts all.
- ///
- /// The source file.
- /// The target path.
- /// if set to true [overwrite existing files].
- public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
- {
- using (var fileStream = File.OpenRead(sourceFile))
- {
- ExtractAll(fileStream, targetPath, overwriteExistingFiles);
- }
- }
-
- ///
- /// Extracts all.
- ///
- /// The source.
- /// The target path.
- /// if set to true [overwrite existing files].
- public void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles)
- {
- using (var reader = ReaderFactory.Open(source))
- {
- var options = ExtractOptions.ExtractFullPath;
-
- if (overwriteExistingFiles)
- {
- options = options | ExtractOptions.Overwrite;
- }
-
- reader.WriteAllToDirectory(targetPath, options);
- }
- }
- }
-}
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs
index e9c1fdc99b..55fa60ed21 100644
--- a/MediaBrowser.ServerApplication/MainStartup.cs
+++ b/MediaBrowser.ServerApplication/MainStartup.cs
@@ -11,7 +11,6 @@ using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Threading;
-using System.Threading.Tasks;
using System.Windows;
namespace MediaBrowser.ServerApplication
diff --git a/MediaBrowser.ServerApplication/MainWindow.xaml.cs b/MediaBrowser.ServerApplication/MainWindow.xaml.cs
index 4c9c065e67..c22c35be8f 100644
--- a/MediaBrowser.ServerApplication/MainWindow.xaml.cs
+++ b/MediaBrowser.ServerApplication/MainWindow.xaml.cs
@@ -12,6 +12,7 @@ using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
+using MediaBrowser.ServerApplication.Native;
namespace MediaBrowser.ServerApplication
{
@@ -188,19 +189,19 @@ namespace MediaBrowser.ServerApplication
/// The instance containing the event data.
void cmdApiDocs_Click(object sender, EventArgs e)
{
- App.OpenUrl("http://localhost:" + _configurationManager.Configuration.HttpServerPortNumber + "/" +
- _appHost.WebApplicationName + "/metadata");
+ BrowserLauncher.OpenUrl("http://localhost:" + _configurationManager.Configuration.HttpServerPortNumber + "/" +
+ _appHost.WebApplicationName + "/metadata", _logger);
}
void cmdSwaggerApiDocs_Click(object sender, EventArgs e)
{
- App.OpenUrl("http://localhost:" + _configurationManager.Configuration.HttpServerPortNumber + "/" +
- _appHost.WebApplicationName + "/swagger-ui/index.html");
+ BrowserLauncher.OpenUrl("http://localhost:" + _configurationManager.Configuration.HttpServerPortNumber + "/" +
+ _appHost.WebApplicationName + "/swagger-ui/index.html", _logger);
}
void cmdGithubWiki_Click(object sender, EventArgs e)
{
- App.OpenUrl("https://github.com/MediaBrowser/MediaBrowser/wiki");
+ BrowserLauncher.OpenUrl("https://github.com/MediaBrowser/MediaBrowser/wiki", _logger);
}
///
@@ -254,7 +255,7 @@ namespace MediaBrowser.ServerApplication
///
private void OpenDashboard(User loggedInUser)
{
- App.OpenDashboardPage("dashboard.html", loggedInUser, _configurationManager, _appHost);
+ BrowserLauncher.OpenDashboardPage("dashboard.html", loggedInUser, _configurationManager, _appHost, _logger);
}
///
@@ -264,7 +265,7 @@ namespace MediaBrowser.ServerApplication
/// The instance containing the event data.
private void cmVisitCT_click(object sender, RoutedEventArgs e)
{
- App.OpenUrl("http://community.mediabrowser.tv/");
+ BrowserLauncher.OpenUrl("http://community.mediabrowser.tv/", _logger);
}
///
@@ -275,7 +276,7 @@ namespace MediaBrowser.ServerApplication
private void cmdBrowseLibrary_click(object sender, RoutedEventArgs e)
{
var user = _userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
- App.OpenDashboardPage("index.html", user, _configurationManager, _appHost);
+ BrowserLauncher.OpenDashboardPage("index.html", user, _configurationManager, _appHost, _logger);
}
///
diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
index 793489c1fc..61ec19dd57 100644
--- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
+++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
@@ -130,10 +130,6 @@
False
..\packages\MediaBrowser.IsoMounting.3.0.56\lib\net45\MediaBrowser.IsoMounter.dll
-
- False
- ..\packages\morelinq.1.0.16006\lib\net35\MoreLinq.dll
-
False
..\packages\NLog.2.0.1.2\lib\net45\NLog.dll
@@ -168,9 +164,6 @@
False
..\packages\ServiceStack.Text.3.9.62\lib\net35\ServiceStack.Text.dll
-
- ..\packages\sharpcompress.0.10.1.3\lib\net40\SharpCompress.dll
-
False
..\packages\SimpleInjector.2.3.5\lib\net40-client\SimpleInjector.dll
@@ -190,7 +183,6 @@
-
@@ -212,12 +204,19 @@
Component
-
-
+
+
+
+
+
+
+
+
Component
+
SplashWindow.xaml
@@ -245,7 +244,6 @@
Code
-
LibraryExplorer.xaml
@@ -281,15 +279,15 @@
Resources.Designer.cs
-
-
+
+
SettingsSingleFileGenerator
Settings.Designer.cs
-
+
diff --git a/MediaBrowser.ServerApplication/Native/Assemblies.cs b/MediaBrowser.ServerApplication/Native/Assemblies.cs
new file mode 100644
index 0000000000..b43dc1a104
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/Assemblies.cs
@@ -0,0 +1,25 @@
+using MediaBrowser.IsoMounter;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Assemblies
+ ///
+ public static class Assemblies
+ {
+ ///
+ /// Gets the assemblies with parts.
+ ///
+ /// List{Assembly}.
+ public static List GetAssembliesWithParts()
+ {
+ var list = new List();
+
+ list.Add(typeof(PismoIsoManager).Assembly);
+
+ return list;
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/Native/Autorun.cs b/MediaBrowser.ServerApplication/Native/Autorun.cs
new file mode 100644
index 0000000000..d1c02db84f
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/Autorun.cs
@@ -0,0 +1,31 @@
+using System;
+using System.IO;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Autorun
+ ///
+ public static class Autorun
+ {
+ ///
+ /// Configures the specified autorun.
+ ///
+ /// if set to true [autorun].
+ public static void Configure(bool autorun)
+ {
+ var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk");
+
+ if (autorun)
+ {
+ //Copy our shortut into the startup folder for this user
+ File.Copy(shortcutPath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileName(shortcutPath) ?? "MBstartup.lnk"), true);
+ }
+ else
+ {
+ //Remove our shortcut from the startup folder for this user
+ File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileName(shortcutPath) ?? "MBstartup.lnk"));
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/Native/BrowserLauncher.cs b/MediaBrowser.ServerApplication/Native/BrowserLauncher.cs
new file mode 100644
index 0000000000..e7d041d15e
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/BrowserLauncher.cs
@@ -0,0 +1,68 @@
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.Logging;
+using System;
+using System.Diagnostics;
+using System.Windows.Forms;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ public static class BrowserLauncher
+ {
+ ///
+ /// Opens the dashboard page.
+ ///
+ /// The page.
+ /// The logged in user.
+ /// The configuration manager.
+ /// The app host.
+ public static void OpenDashboardPage(string page, User loggedInUser, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
+ {
+ var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
+ appHost.WebApplicationName + "/dashboard/" + page;
+
+ OpenUrl(url, logger);
+ }
+
+ ///
+ /// Opens the URL.
+ ///
+ /// The URL.
+ public static void OpenUrl(string url, ILogger logger)
+ {
+ 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);
+
+ MessageBox.Show("There was an error launching your web browser. Please check your default browser settings.");
+ }
+ }
+
+ ///
+ /// Processes the exited.
+ ///
+ /// The sender.
+ /// The instance containing the event data.
+ private static void ProcessExited(object sender, EventArgs e)
+ {
+ ((Process)sender).Dispose();
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/Native/HttpMessageHandlerFactory.cs b/MediaBrowser.ServerApplication/Native/HttpMessageHandlerFactory.cs
new file mode 100644
index 0000000000..4bbcc9ea09
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/HttpMessageHandlerFactory.cs
@@ -0,0 +1,26 @@
+using System.Net;
+using System.Net.Cache;
+using System.Net.Http;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class HttpMessageHandlerFactory
+ ///
+ public static class HttpMessageHandlerFactory
+ {
+ ///
+ /// Gets the HTTP message handler.
+ ///
+ /// if set to true [enable HTTP compression].
+ /// HttpMessageHandler.
+ public static HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
+ {
+ return new WebRequestHandler
+ {
+ CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
+ AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
+ };
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/Native/NativeApp.cs b/MediaBrowser.ServerApplication/Native/NativeApp.cs
new file mode 100644
index 0000000000..ea4218afc9
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/NativeApp.cs
@@ -0,0 +1,25 @@
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class NativeApp
+ ///
+ public static class NativeApp
+ {
+ ///
+ /// Shutdowns this instance.
+ ///
+ public static void Shutdown()
+ {
+ MainStartup.Shutdown();
+ }
+
+ ///
+ /// Restarts this instance.
+ ///
+ public static void Restart()
+ {
+ MainStartup.Restart();
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/RegisterServer.bat b/MediaBrowser.ServerApplication/Native/RegisterServer.bat
similarity index 100%
rename from MediaBrowser.ServerApplication/RegisterServer.bat
rename to MediaBrowser.ServerApplication/Native/RegisterServer.bat
diff --git a/MediaBrowser.ServerApplication/Native/ServerAuthorization.cs b/MediaBrowser.ServerApplication/Native/ServerAuthorization.cs
new file mode 100644
index 0000000000..91f0974eb9
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/ServerAuthorization.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Reflection;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Authorization
+ ///
+ public static class ServerAuthorization
+ {
+ ///
+ /// Authorizes the server.
+ ///
+ /// The HTTP server port.
+ /// The HTTP server URL prefix.
+ /// The web socket port.
+ /// The UDP port.
+ /// The temp directory.
+ public static void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int webSocketPort, int udpPort, string tempDirectory)
+ {
+ // Create a temp file path to extract the bat file to
+ var tmpFile = Path.Combine(tempDirectory, Guid.NewGuid() + ".bat");
+
+ // Extract the bat file
+ using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(ServerAuthorization).Namespace + ".RegisterServer.bat"))
+ {
+ using (var fileStream = File.Create(tmpFile))
+ {
+ stream.CopyTo(fileStream);
+ }
+ }
+
+ var startInfo = new ProcessStartInfo
+ {
+ FileName = tmpFile,
+
+ Arguments = string.Format("{0} {1} {2} {3}", httpServerPort,
+ httpServerUrlPrefix,
+ udpPort,
+ webSocketPort),
+
+ CreateNoWindow = true,
+ WindowStyle = ProcessWindowStyle.Hidden,
+ Verb = "runas",
+ ErrorDialog = false
+ };
+
+ using (var process = Process.Start(startInfo))
+ {
+ process.WaitForExit();
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/Native/Sqlite.cs b/MediaBrowser.ServerApplication/Native/Sqlite.cs
new file mode 100644
index 0000000000..cc20952d73
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Native/Sqlite.cs
@@ -0,0 +1,36 @@
+using System.Data;
+using System.Data.SQLite;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.ServerApplication.Native
+{
+ ///
+ /// Class Sqlite
+ ///
+ public static class Sqlite
+ {
+ ///
+ /// Connects to db.
+ ///
+ /// The db path.
+ /// Task{IDbConnection}.
+ /// dbPath
+ public static async Task OpenDatabase(string dbPath)
+ {
+ var connectionstr = new SQLiteConnectionStringBuilder
+ {
+ PageSize = 4096,
+ CacheSize = 4096,
+ SyncMode = SynchronizationModes.Normal,
+ DataSource = dbPath,
+ JournalMode = SQLiteJournalModeEnum.Wal
+ };
+
+ var connection = new SQLiteConnection(connectionstr.ConnectionString);
+
+ await connection.OpenAsync().ConfigureAwait(false);
+
+ return connection;
+ }
+ }
+}
diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config
index 137483ef1a..e680b556ff 100644
--- a/MediaBrowser.ServerApplication/packages.config
+++ b/MediaBrowser.ServerApplication/packages.config
@@ -4,14 +4,12 @@
-
-
\ No newline at end of file