2013-06-14 17:21:12 +02:00
|
|
|
using System;
|
2013-07-09 02:47:09 +02:00
|
|
|
using System.Diagnostics;
|
2013-05-21 06:03:05 +02:00
|
|
|
using System.IO;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common;
|
2013-07-09 02:47:09 +02:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-06-14 17:21:12 +02:00
|
|
|
using IServiceProvider = NzbDrone.Common.IServiceProvider;
|
2013-05-21 06:03:05 +02:00
|
|
|
|
|
|
|
namespace NzbDrone.Update.UpdateEngine
|
|
|
|
{
|
|
|
|
public interface IStartNzbDrone
|
|
|
|
{
|
|
|
|
void Start(AppType appType, string installationFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class StartNzbDrone : IStartNzbDrone
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IProcessProvider _processProvider;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public StartNzbDrone(IServiceProvider serviceProvider, IProcessProvider processProvider, Logger logger)
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_processProvider = processProvider;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Start(AppType appType, string installationFolder)
|
|
|
|
{
|
|
|
|
_logger.Info("Starting NzbDrone");
|
|
|
|
if (appType == AppType.Service)
|
|
|
|
{
|
2013-06-14 17:21:12 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
StartService();
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (InvalidOperationException e)
|
|
|
|
{
|
|
|
|
_logger.Warn("Couldn't start NzbDrone Service (Most likely due to permission issues). falling back to console.", e);
|
|
|
|
StartConsole(installationFolder);
|
|
|
|
}
|
2013-05-21 06:03:05 +02:00
|
|
|
}
|
|
|
|
else if (appType == AppType.Console)
|
|
|
|
{
|
2013-06-14 17:21:12 +02:00
|
|
|
StartConsole(installationFolder);
|
2013-05-21 06:03:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-14 17:21:12 +02:00
|
|
|
StartWinform(installationFolder);
|
2013-05-21 06:03:05 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-14 17:21:12 +02:00
|
|
|
|
|
|
|
private void StartService()
|
|
|
|
{
|
|
|
|
_logger.Info("Starting NzbDrone service");
|
|
|
|
_serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StartWinform(string installationFolder)
|
|
|
|
{
|
2013-07-09 02:47:09 +02:00
|
|
|
Start(installationFolder, "NzbDrone.exe");
|
2013-06-14 17:21:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void StartConsole(string installationFolder)
|
|
|
|
{
|
2013-07-09 02:47:09 +02:00
|
|
|
Start(installationFolder, "NzbDrone.Console.exe");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start(string installationFolder, string fileName)
|
|
|
|
{
|
|
|
|
_logger.Info("Starting {0}", fileName);
|
|
|
|
var path = Path.Combine(installationFolder, fileName);
|
|
|
|
|
|
|
|
_processProvider.Start(new ProcessStartInfo(path, StartupArguments.NO_BROWSER));
|
2013-06-14 17:21:12 +02:00
|
|
|
}
|
2013-05-21 06:03:05 +02:00
|
|
|
}
|
|
|
|
}
|