2012-01-17 07:12:22 +00:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
2012-02-13 06:38:57 +00:00
|
|
|
namespace ServiceInstall
|
2012-01-17 07:12:22 +00:00
|
|
|
{
|
2013-04-07 22:40:13 +00:00
|
|
|
public static class ServiceHelper
|
2012-01-17 07:12:22 +00:00
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
private static string RadarrExe => Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "Radarr.Console.exe");
|
2012-01-17 07:12:22 +00:00
|
|
|
|
|
|
|
private static bool IsAnAdministrator()
|
|
|
|
{
|
|
|
|
WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
|
|
|
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
|
|
|
}
|
|
|
|
|
2013-04-07 22:40:13 +00:00
|
|
|
public static void Run(string arg)
|
2012-01-17 07:12:22 +00:00
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
if (!File.Exists(RadarrExe))
|
2012-01-17 07:12:22 +00:00
|
|
|
{
|
2017-01-05 19:42:02 +00:00
|
|
|
Console.WriteLine("Unable to find Radarr.Console.exe in the current directory.");
|
2012-01-17 07:12:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsAnAdministrator())
|
|
|
|
{
|
|
|
|
Console.WriteLine("Access denied. Please run as administrator.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var startInfo = new ProcessStartInfo
|
2019-12-22 22:08:53 +00:00
|
|
|
{
|
|
|
|
FileName = RadarrExe,
|
|
|
|
Arguments = arg,
|
|
|
|
UseShellExecute = false,
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
RedirectStandardError = true,
|
|
|
|
CreateNoWindow = true
|
|
|
|
};
|
2012-01-17 07:12:22 +00:00
|
|
|
|
|
|
|
var process = new Process { StartInfo = startInfo };
|
2019-12-22 22:08:53 +00:00
|
|
|
process.OutputDataReceived += OnDataReceived;
|
|
|
|
process.ErrorDataReceived += OnDataReceived;
|
2012-01-17 07:12:22 +00:00
|
|
|
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
process.BeginErrorReadLine();
|
|
|
|
process.BeginOutputReadLine();
|
|
|
|
|
|
|
|
process.WaitForExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void OnDataReceived(object sender, DataReceivedEventArgs e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e.Data);
|
|
|
|
}
|
|
|
|
}
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|