You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
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>
|
|
/// <param name="httpServerPort">The HTTP server port.</param>
|
|
/// <param name="tempDirectory">The temp directory.</param>
|
|
public static void AuthorizeServer(int udpPort, int httpServerPort, string tempDirectory)
|
|
{
|
|
Directory.CreateDirectory(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}", udpPort, httpServerPort),
|
|
|
|
CreateNoWindow = true,
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
Verb = "runas",
|
|
ErrorDialog = false
|
|
};
|
|
|
|
using (var process = Process.Start(startInfo))
|
|
{
|
|
process.WaitForExit();
|
|
}
|
|
}
|
|
}
|
|
}
|