jellyfin-server/MediaBrowser.ServerApplication/Native/ServerAuthorization.cs

57 lines
1.8 KiB
C#
Raw Normal View History

2013-09-25 00:54:51 +00:00
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="udpPort">The UDP port.</param>
/// <param name="tempDirectory">The temp directory.</param>
2014-07-20 04:46:29 +00:00
public static void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int udpPort, string tempDirectory)
2013-09-25 00:54:51 +00:00
{
2013-12-15 01:17:57 +00:00
Directory.CreateDirectory(tempDirectory);
2013-09-25 00:54:51 +00:00
// 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,
2014-07-20 04:46:29 +00:00
Arguments = string.Format("{0} {1} {2}", httpServerPort,
2013-09-25 00:54:51 +00:00
httpServerUrlPrefix,
2014-07-20 04:46:29 +00:00
udpPort),
2013-09-25 00:54:51 +00:00
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
Verb = "runas",
ErrorDialog = false
};
using (var process = Process.Start(startInfo))
{
process.WaitForExit();
}
}
}
}