moved a few things for mono

This commit is contained in:
Luke Pulverenti 2013-09-24 20:54:51 -04:00
parent 0ab379e271
commit fe5a9232c8
36 changed files with 740 additions and 279 deletions

View File

@ -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
{
/// <summary>
/// Class DotNetZipClient
/// </summary>
public class ZipClient : IZipClient
{
/// <summary>
/// Extracts all.
/// </summary>
/// <param name="sourceFile">The source file.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
{
using (var fileStream = File.OpenRead(sourceFile))
{
ExtractAll(fileStream, targetPath, overwriteExistingFiles);
}
}
/// <summary>
/// Extracts all.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
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);
}
}
/// <summary>
/// Extracts all from7z.
/// </summary>
/// <param name="sourceFile">The source file.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles)
{
using (var fileStream = File.OpenRead(sourceFile))
{
ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
}
}
/// <summary>
/// Extracts all from7z.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
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);
}
}
}
}
}

View File

@ -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
/// <value>The installation manager.</value>
protected IInstallationManager InstallationManager { get; set; }
/// <summary>
/// Gets or sets the zip client.
/// </summary>
/// <value>The zip client.</value>
protected IZipClient ZipClient { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
/// </summary>
@ -202,12 +210,27 @@ namespace MediaBrowser.Common.Implementations
{
Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false));
Task.Run(() => ConfigureAutoRunAtStartup());
Task.Run(() => ConfigureAutorun());
ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
});
}
/// <summary>
/// Configures the autorun.
/// </summary>
private void ConfigureAutorun()
{
try
{
ConfigureAutoRunAtStartup(ConfigurationManager.CommonConfiguration.RunAtStartup);
}
catch (Exception ex)
{
Logger.ErrorException("Error configuring autorun", ex);
}
}
/// <summary>
/// Gets the composable part assemblies.
/// </summary>
@ -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
}
}
/// <summary>
/// Defines the full path to our shortcut in the start menu
/// </summary>
protected abstract string ProductShortcutPath { get; }
/// <summary>
/// Handles the ConfigurationUpdated event of the ConfigurationManager control.
/// </summary>
@ -466,32 +487,10 @@ namespace MediaBrowser.Common.Implementations
/// <exception cref="System.NotImplementedException"></exception>
protected virtual void OnConfigurationUpdated(object sender, EventArgs e)
{
ConfigureAutoRunAtStartup();
ConfigureAutorun();
}
/// <summary>
/// Configures the auto run at startup.
/// </summary>
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);
/// <summary>
/// Removes the plugin.

View File

@ -37,6 +37,9 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpCompress">
<HintPath>..\packages\sharpcompress.0.10.1.3\lib\net40\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
@ -58,6 +61,7 @@
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="Archiving\ZipClient.cs" />
<Compile Include="BaseApplicationHost.cs" />
<Compile Include="BaseApplicationPaths.cs" />
<Compile Include="Configuration\BaseConfigurationManager.cs" />

View File

@ -2,5 +2,6 @@
<packages>
<package id="NLog" version="2.0.1.2" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
<package id="sharpcompress" version="0.10.1.3" targetFramework="net45" />
<package id="SimpleInjector" version="2.3.5" targetFramework="net45" />
</packages>

View File

@ -22,5 +22,21 @@ namespace MediaBrowser.Model.IO
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles);
/// <summary>
/// Extracts all from7z.
/// </summary>
/// <param name="sourceFile">The source file.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles);
/// <summary>
/// Extracts all from7z.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles);
}
}

View File

@ -1,6 +1,17 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench />
<MonoDevelop.Ide.Workbench ActiveDocument="d:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\Sqlite.cs">
<Files>
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\MainWindow.cs" Line="8" Column="12" />
<File FileName="MediaBrowser.Server.Mono\Native\Autorun.cs" Line="17" Column="4" />
<File FileName="MediaBrowser.Server.Mono\Native\ServerAuthorization.cs" Line="23" Column="1" />
<File FileName="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloader.cs" Line="7" Column="14" />
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="548" Column="61" />
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="22" Column="13" />
<File FileName="d:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\Sqlite.cs" Line="21" Column="14" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>

View File

@ -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
{
/// <summary>
/// Class UdpServerEntryPoint
@ -35,6 +35,8 @@ namespace MediaBrowser.ServerApplication.EntryPoints
/// </summary>
private readonly IHttpServer _httpServer;
public const int PortNumber = 7359;
/// <summary>
/// Initializes a new instance of the <see cref="UdpServerEntryPoint"/> class.
/// </summary>
@ -59,7 +61,7 @@ namespace MediaBrowser.ServerApplication.EntryPoints
try
{
udpServer.Start(ApplicationHost.UdpServerPort);
udpServer.Start(PortNumber);
UdpServer = udpServer;
}

View File

@ -113,6 +113,7 @@
<Compile Include="EntryPoints\Notifications\RemoteNotifications.cs" />
<Compile Include="EntryPoints\Notifications\WebSocketNotifier.cs" />
<Compile Include="EntryPoints\RefreshUsersMetadata.cs" />
<Compile Include="EntryPoints\UdpServerEntryPoint.cs" />
<Compile Include="EntryPoints\WebSocketEvents.cs" />
<Compile Include="HttpServer\HttpResultFactory.cs" />
<Compile Include="HttpServer\HttpServer.cs" />

View File

@ -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<FFMpegInfo> GetFFMpegInfo()
{
return Task.FromResult (new FFMpegInfo());
}
}
}

View File

@ -40,6 +40,9 @@
<Reference Include="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Data" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic">
@ -52,6 +55,25 @@
<Compile Include="gtk-gui\MainWindow.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\MediaBrowser.ServerApplication\EntryPoints\StartupWizard.cs">
<Link>EntryPoints\StartupWizard.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.ServerApplication\Native\BrowserLauncher.cs">
<Link>Native\BrowserLauncher.cs</Link>
</Compile>
<Compile Include="Native\Autorun.cs" />
<Compile Include="Native\ServerAuthorization.cs" />
<Compile Include="FFMpeg\FFMpegDownloader.cs" />
<Compile Include="..\MediaBrowser.ServerApplication\FFMpeg\FFMpegInfo.cs">
<Link>FFMpeg\FFMpegInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.ServerApplication\ApplicationHost.cs">
<Link>ApplicationHost.cs</Link>
</Compile>
<Compile Include="Native\HttpMessageHandlerFactory.cs" />
<Compile Include="Native\Assemblies.cs" />
<Compile Include="Native\Sqlite.cs" />
<Compile Include="Native\NativeApp.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@ -88,4 +110,10 @@
<Name>MediaBrowser.Api</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="EntryPoints\" />
<Folder Include="Implementations\" />
<Folder Include="Native\" />
<Folder Include="FFMpeg\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Reflection;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Assemblies
/// </summary>
public static class Assemblies
{
/// <summary>
/// Gets the assemblies with parts.
/// </summary>
/// <returns>List{Assembly}.</returns>
public static List<Assembly> GetAssembliesWithParts()
{
var list = new List<Assembly>();
return list;
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.IO;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Autorun
/// </summary>
public static class Autorun
{
/// <summary>
/// Configures the specified autorun.
/// </summary>
/// <param name="autorun">if set to <c>true</c> [autorun].</param>
public static void Configure(bool autorun)
{
}
}
}

View File

@ -0,0 +1,25 @@
using System.Net;
using System.Net.Cache;
using System.Net.Http;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class HttpMessageHandlerFactory
/// </summary>
public static class HttpMessageHandlerFactory
{
/// <summary>
/// Gets the HTTP message handler.
/// </summary>
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
/// <returns>HttpMessageHandler.</returns>
public static HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
{
return new HttpClientHandler
{
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
};
}
}
}

View File

@ -0,0 +1,25 @@

namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class NativeApp
/// </summary>
public static class NativeApp
{
/// <summary>
/// Shutdowns this instance.
/// </summary>
public static void Shutdown()
{
}
/// <summary>
/// Restarts this instance.
/// </summary>
public static void Restart()
{
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Authorization
/// </summary>
public static class ServerAuthorization
{
/// <summary>
/// Authorizes the server.
/// </summary>
/// <param name="httpServerPort">The HTTP server port.</param>
/// <param name="httpServerUrlPrefix">The HTTP server URL prefix.</param>
/// <param name="webSocketPort">The web socket port.</param>
/// <param name="udpPort">The UDP port.</param>
/// <param name="tempDirectory">The temp directory.</param>
public static void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int webSocketPort, int udpPort, string tempDirectory)
{
}
}
}

View File

@ -0,0 +1,36 @@
using System.Data;
using System.Data.SQLite;
using System.Threading.Tasks;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Sqlite
/// </summary>
public static class Sqlite
{
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> 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;
}
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<stetic-interface>
<configuration>
<images-root-path>..</images-root-path>
<target-gtk-version>2.12</target-gtk-version>
</configuration>
<import>

View File

@ -154,58 +154,5 @@ namespace MediaBrowser.ServerApplication
{
Dispatcher.Invoke(Shutdown);
}
/// <summary>
/// Opens the dashboard page.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="loggedInUser">The logged in user.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="appHost">The app host.</param>
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);
}
/// <summary>
/// Opens the URL.
/// </summary>
/// <param name="url">The URL.</param>
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.");
}
}
/// <summary>
/// Processes the exited.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
static void ProcessExited(object sender, EventArgs e)
{
((Process)sender).Dispose();
}
}
}

View File

@ -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
/// </summary>
public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost
{
internal const int UdpServerPort = 7359;
/// <summary>
/// Gets the server kernel.
/// </summary>
@ -142,11 +138,6 @@ namespace MediaBrowser.ServerApplication
/// <value>The provider manager.</value>
private IProviderManager ProviderManager { get; set; }
/// <summary>
/// Gets or sets the zip client.
/// </summary>
/// <value>The zip client.</value>
private IZipClient ZipClient { get; set; }
/// <summary>
/// Gets or sets the HTTP server.
/// </summary>
/// <value>The HTTP server.</value>
@ -175,14 +166,6 @@ namespace MediaBrowser.ServerApplication
private IItemRepository ItemRepository { get; set; }
private INotificationsRepository NotificationsRepository { get; set; }
/// <summary>
/// The full path to our startmenu shortcut
/// </summary>
protected override string ProductShortcutPath
{
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); }
}
private Task<IHttpServer> _httpServerCreationTask;
/// <summary>
@ -256,9 +239,6 @@ namespace MediaBrowser.ServerApplication
RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
ZipClient = new ZipClient();
RegisterSingleInstance(ZipClient);
var mediaEncoderTask = RegisterMediaEncoder();
UserDataRepository = new SqliteUserDataRepository(ApplicationPaths, JsonSerializer, LogManager);
@ -322,7 +302,7 @@ namespace MediaBrowser.ServerApplication
/// <returns>Task.</returns>
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
/// <param name="dbPath">The db path.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
private static async Task<SQLiteConnection> ConnectToDb(string dbPath)
private static Task<IDbConnection> 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);
}
/// <summary>
@ -479,7 +446,7 @@ namespace MediaBrowser.ServerApplication
IsoManager.AddParts(GetExports<IIsoMounter>());
SessionManager.AddParts(GetExports<ISessionRemoteController>());
ImageProcessor.AddParts(GetExports<IImageEnhancer>());
}
@ -530,7 +497,6 @@ namespace MediaBrowser.ServerApplication
{
NotifyPendingRestart();
}
}
/// <summary>
@ -547,7 +513,7 @@ namespace MediaBrowser.ServerApplication
Logger.ErrorException("Error sending server restart web socket message", ex);
}
MainStartup.Restart();
NativeApp.Restart();
}
/// <summary>
@ -571,44 +537,44 @@ namespace MediaBrowser.ServerApplication
/// <returns>IEnumerable{Assembly}.</returns>
protected override IEnumerable<Assembly> 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();
}
/// <summary>
@ -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
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task{CheckForUpdateResult}.</returns>
public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken,
IProgress<double> progress)
public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
{
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
@ -748,11 +693,12 @@ namespace MediaBrowser.ServerApplication
/// <returns>HttpMessageHandler.</returns>
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);
}
}
}

View File

@ -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
/// </summary>
/// <param name="appHost">The app host.</param>
/// <param name="userManager">The user manager.</param>
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
{
}
}
}
}

View File

@ -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<FFMpegInfo> 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; }
}
}

View File

@ -0,0 +1,24 @@
namespace MediaBrowser.ServerApplication.FFMpeg
{
/// <summary>
/// Class FFMpegInfo
/// </summary>
public class FFMpegInfo
{
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
public string Path { get; set; }
/// <summary>
/// Gets or sets the probe path.
/// </summary>
/// <value>The probe path.</value>
public string ProbePath { get; set; }
/// <summary>
/// Gets or sets the version.
/// </summary>
/// <value>The version.</value>
public string Version { get; set; }
}
}

View File

@ -1,48 +0,0 @@
using MediaBrowser.Model.IO;
using SharpCompress.Common;
using SharpCompress.Reader;
using System.IO;
namespace MediaBrowser.ServerApplication.Implementations
{
/// <summary>
/// Class DotNetZipClient
/// </summary>
public class ZipClient : IZipClient
{
/// <summary>
/// Extracts all.
/// </summary>
/// <param name="sourceFile">The source file.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
{
using (var fileStream = File.OpenRead(sourceFile))
{
ExtractAll(fileStream, targetPath, overwriteExistingFiles);
}
}
/// <summary>
/// Extracts all.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
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);
}
}
}
}

View File

@ -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

View File

@ -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
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
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);
}
/// <summary>
@ -254,7 +255,7 @@ namespace MediaBrowser.ServerApplication
/// </summary>
private void OpenDashboard(User loggedInUser)
{
App.OpenDashboardPage("dashboard.html", loggedInUser, _configurationManager, _appHost);
BrowserLauncher.OpenDashboardPage("dashboard.html", loggedInUser, _configurationManager, _appHost, _logger);
}
/// <summary>
@ -264,7 +265,7 @@ namespace MediaBrowser.ServerApplication
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
private void cmVisitCT_click(object sender, RoutedEventArgs e)
{
App.OpenUrl("http://community.mediabrowser.tv/");
BrowserLauncher.OpenUrl("http://community.mediabrowser.tv/", _logger);
}
/// <summary>
@ -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);
}
/// <summary>

View File

@ -130,10 +130,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MediaBrowser.IsoMounting.3.0.56\lib\net45\MediaBrowser.IsoMounter.dll</HintPath>
</Reference>
<Reference Include="MoreLinq, Version=1.0.16006.0, Culture=neutral, PublicKeyToken=384d532d7e88985d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\morelinq.1.0.16006\lib\net35\MoreLinq.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.2.0.1.2\lib\net45\NLog.dll</HintPath>
@ -168,9 +164,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ServiceStack.Text.3.9.62\lib\net35\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="SharpCompress">
<HintPath>..\packages\sharpcompress.0.10.1.3\lib\net40\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector, Version=2.3.5.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SimpleInjector.2.3.5\lib\net40-client\SimpleInjector.dll</HintPath>
@ -190,7 +183,6 @@
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@ -212,12 +204,19 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="EntryPoints\StartupWizard.cs" />
<Compile Include="EntryPoints\UdpServerEntryPoint.cs" />
<Compile Include="Implementations\FFMpegDownloader.cs" />
<Compile Include="FFMpeg\FFMpegInfo.cs" />
<Compile Include="Native\Assemblies.cs" />
<Compile Include="Native\HttpMessageHandlerFactory.cs" />
<Compile Include="Native\NativeApp.cs" />
<Compile Include="Native\ServerAuthorization.cs" />
<Compile Include="Native\Autorun.cs" />
<Compile Include="Native\BrowserLauncher.cs" />
<Compile Include="FFMpeg\FFMpegDownloader.cs" />
<Compile Include="MainStartup.cs" />
<Compile Include="BackgroundServiceInstaller.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Native\Sqlite.cs" />
<Compile Include="Splash\SplashWindow.xaml.cs">
<DependentUpon>SplashWindow.xaml</DependentUpon>
</Compile>
@ -245,7 +244,6 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ApplicationHost.cs" />
<Compile Include="Implementations\ZipClient.cs" />
<Compile Include="LibraryExplorer.xaml.cs">
<DependentUpon>LibraryExplorer.xaml</DependentUpon>
</Compile>
@ -281,15 +279,15 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.manifest" />
<None Include="Implementations\ARIALUNI.7z" />
<None Include="Implementations\ffmpeg-20130904-git-f974289-win32-static.7z" />
<None Include="FFMpeg\ARIALUNI.7z" />
<None Include="FFMpeg\ffmpeg-20130904-git-f974289-win32-static.7z" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
<EmbeddedResource Include="RegisterServer.bat" />
<EmbeddedResource Include="Native\RegisterServer.bat" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">

View File

@ -0,0 +1,25 @@
using MediaBrowser.IsoMounter;
using System.Collections.Generic;
using System.Reflection;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Assemblies
/// </summary>
public static class Assemblies
{
/// <summary>
/// Gets the assemblies with parts.
/// </summary>
/// <returns>List{Assembly}.</returns>
public static List<Assembly> GetAssembliesWithParts()
{
var list = new List<Assembly>();
list.Add(typeof(PismoIsoManager).Assembly);
return list;
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.IO;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Autorun
/// </summary>
public static class Autorun
{
/// <summary>
/// Configures the specified autorun.
/// </summary>
/// <param name="autorun">if set to <c>true</c> [autorun].</param>
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"));
}
}
}
}

View File

@ -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
{
/// <summary>
/// Opens the dashboard page.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="loggedInUser">The logged in user.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="appHost">The app host.</param>
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);
}
/// <summary>
/// Opens the URL.
/// </summary>
/// <param name="url">The URL.</param>
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.");
}
}
/// <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();
}
}
}

View File

@ -0,0 +1,26 @@
using System.Net;
using System.Net.Cache;
using System.Net.Http;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class HttpMessageHandlerFactory
/// </summary>
public static class HttpMessageHandlerFactory
{
/// <summary>
/// Gets the HTTP message handler.
/// </summary>
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
/// <returns>HttpMessageHandler.</returns>
public static HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
{
return new WebRequestHandler
{
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
};
}
}
}

View File

@ -0,0 +1,25 @@

namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class NativeApp
/// </summary>
public static class NativeApp
{
/// <summary>
/// Shutdowns this instance.
/// </summary>
public static void Shutdown()
{
MainStartup.Shutdown();
}
/// <summary>
/// Restarts this instance.
/// </summary>
public static void Restart()
{
MainStartup.Restart();
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Authorization
/// </summary>
public static class ServerAuthorization
{
/// <summary>
/// Authorizes the server.
/// </summary>
/// <param name="httpServerPort">The HTTP server port.</param>
/// <param name="httpServerUrlPrefix">The HTTP server URL prefix.</param>
/// <param name="webSocketPort">The web socket port.</param>
/// <param name="udpPort">The UDP port.</param>
/// <param name="tempDirectory">The temp directory.</param>
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();
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Data;
using System.Data.SQLite;
using System.Threading.Tasks;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Sqlite
/// </summary>
public static class Sqlite
{
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> 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;
}
}
}

View File

@ -4,14 +4,12 @@
<package id="Hardcodet.Wpf.TaskbarNotification" version="1.0.4.0" targetFramework="net45" />
<package id="MahApps.Metro" version="0.11.0.17-ALPHA" targetFramework="net45" />
<package id="MediaBrowser.IsoMounting" version="3.0.56" targetFramework="net45" />
<package id="morelinq" version="1.0.16006" targetFramework="net45" />
<package id="NLog" version="2.0.1.2" targetFramework="net45" />
<package id="ServiceStack" version="3.9.62" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.62" targetFramework="net45" />
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.44" targetFramework="net45" />
<package id="ServiceStack.Redis" version="3.9.44" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
<package id="sharpcompress" version="0.10.1.3" targetFramework="net45" />
<package id="SimpleInjector" version="2.3.5" targetFramework="net45" />
<package id="System.Data.SQLite.x86" version="1.0.88.0" targetFramework="net45" />
</packages>