mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 00:55:13 +01:00
moved a few things for mono
This commit is contained in:
25
MediaBrowser.ServerApplication/Native/Assemblies.cs
Normal file
25
MediaBrowser.ServerApplication/Native/Assemblies.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
MediaBrowser.ServerApplication/Native/Autorun.cs
Normal file
31
MediaBrowser.ServerApplication/Native/Autorun.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
MediaBrowser.ServerApplication/Native/BrowserLauncher.cs
Normal file
68
MediaBrowser.ServerApplication/Native/BrowserLauncher.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
25
MediaBrowser.ServerApplication/Native/NativeApp.cs
Normal file
25
MediaBrowser.ServerApplication/Native/NativeApp.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
28
MediaBrowser.ServerApplication/Native/RegisterServer.bat
Normal file
28
MediaBrowser.ServerApplication/Native/RegisterServer.bat
Normal file
@@ -0,0 +1,28 @@
|
||||
rem %1 = http server port
|
||||
rem %2 = http server url
|
||||
rem %3 = udp server port
|
||||
rem %4 = tcp server port (web socket)
|
||||
|
||||
if [%1]==[] GOTO DONE
|
||||
|
||||
netsh advfirewall firewall delete rule name="Port %1" protocol=TCP localport=%1
|
||||
netsh advfirewall firewall add rule name="Port %1" dir=in action=allow protocol=TCP localport=%1
|
||||
|
||||
if [%2]==[] GOTO DONE
|
||||
|
||||
netsh http del urlacl url="%2" user="NT AUTHORITY\Authenticated Users"
|
||||
netsh http add urlacl url="%2" user="NT AUTHORITY\Authenticated Users"
|
||||
|
||||
if [%3]==[] GOTO DONE
|
||||
|
||||
netsh advfirewall firewall delete rule name="Port %3" protocol=UDP localport=%3
|
||||
netsh advfirewall firewall add rule name="Port %3" dir=in action=allow protocol=UDP localport=%3
|
||||
|
||||
if [%4]==[] GOTO DONE
|
||||
|
||||
netsh advfirewall firewall delete rule name="Port %4" protocol=TCP localport=%4
|
||||
netsh advfirewall firewall add rule name="Port %4" dir=in action=allow protocol=TCP localport=%4
|
||||
|
||||
|
||||
:DONE
|
||||
Exit
|
||||
56
MediaBrowser.ServerApplication/Native/ServerAuthorization.cs
Normal file
56
MediaBrowser.ServerApplication/Native/ServerAuthorization.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
MediaBrowser.ServerApplication/Native/Sqlite.cs
Normal file
36
MediaBrowser.ServerApplication/Native/Sqlite.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user