2013-09-25 02:54:51 +02: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="udpPort">The UDP port.</param>
|
2014-12-27 23:52:41 +01:00
|
|
|
|
/// <param name="httpServerPort">The HTTP server port.</param>
|
2015-01-11 03:12:43 +01:00
|
|
|
|
/// <param name="httpsServerPort">The HTTPS server port.</param>
|
2013-09-25 02:54:51 +02:00
|
|
|
|
/// <param name="tempDirectory">The temp directory.</param>
|
2015-01-11 03:12:43 +01:00
|
|
|
|
public static void AuthorizeServer(int udpPort, int httpServerPort, int httpsServerPort, string tempDirectory)
|
2013-09-25 02:54:51 +02:00
|
|
|
|
{
|
2013-12-15 02:17:57 +01:00
|
|
|
|
Directory.CreateDirectory(tempDirectory);
|
|
|
|
|
|
2013-09-25 02:54:51 +02: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,
|
|
|
|
|
|
2015-01-11 03:12:43 +01:00
|
|
|
|
Arguments = string.Format("{0} {1} {2}", udpPort, httpServerPort, httpsServerPort),
|
2013-09-25 02:54:51 +02:00
|
|
|
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
|
Verb = "runas",
|
|
|
|
|
ErrorDialog = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using (var process = Process.Start(startInfo))
|
|
|
|
|
{
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|