NzbDrone Update no longer opens console/browser.

pull/3113/head
Keivan Beigi 12 years ago
parent 46c093559e
commit 34f3ee6b4b

@ -16,22 +16,25 @@ namespace NzbDrone.App.Test
[TestFixture] [TestFixture]
public class ContainerFixture : TestBase public class ContainerFixture : TestBase
{ {
string[] args = new[]{"first","second"};
[Test] [Test]
public void should_be_able_to_resolve_indexers() public void should_be_able_to_resolve_indexers()
{ {
MainAppContainerBuilder.BuildContainer().Resolve<IEnumerable<IIndexer>>().Should().NotBeEmpty(); MainAppContainerBuilder.BuildContainer(args).Resolve<IEnumerable<IIndexer>>().Should().NotBeEmpty();
} }
[Test] [Test]
public void should_be_able_to_resolve_downlodclients() public void should_be_able_to_resolve_downlodclients()
{ {
MainAppContainerBuilder.BuildContainer().Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty(); MainAppContainerBuilder.BuildContainer(args).Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty();
} }
[Test] [Test]
public void container_should_inject_itself() public void container_should_inject_itself()
{ {
var factory = MainAppContainerBuilder.BuildContainer().Resolve<IServiceFactory>(); var factory = MainAppContainerBuilder.BuildContainer(args).Resolve<IServiceFactory>();
factory.Build<IIndexerService>().Should().NotBeNull(); factory.Build<IIndexerService>().Should().NotBeNull();
} }
@ -40,7 +43,7 @@ namespace NzbDrone.App.Test
public void should_resolve_command_executor_by_name() public void should_resolve_command_executor_by_name()
{ {
var genericExecutor = typeof(IExecute<>).MakeGenericType(typeof(RssSyncCommand)); var genericExecutor = typeof(IExecute<>).MakeGenericType(typeof(RssSyncCommand));
var container = MainAppContainerBuilder.BuildContainer(); var container = MainAppContainerBuilder.BuildContainer(args);
DbFactory.RegisterDatabase(container); DbFactory.RegisterDatabase(container);
var executor = container.Resolve(genericExecutor); var executor = container.Resolve(genericExecutor);
@ -53,7 +56,7 @@ namespace NzbDrone.App.Test
[Ignore("need to fix this at some point")] [Ignore("need to fix this at some point")]
public void should_return_same_instance_of_singletons() public void should_return_same_instance_of_singletons()
{ {
var container = MainAppContainerBuilder.BuildContainer(); var container = MainAppContainerBuilder.BuildContainer(args);
var first = container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single(); var first = container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single();
var second = container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single(); var second = container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single();

@ -1,5 +1,4 @@
using System.ServiceProcess; using System.ServiceProcess;
using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
@ -11,37 +10,6 @@ namespace NzbDrone.App.Test
[TestFixture] [TestFixture]
public class RouterTest : TestBase<Router> public class RouterTest : TestBase<Router>
{ {
[TestCase(null, ApplicationModes.Console)]
[TestCase("", ApplicationModes.Console)]
[TestCase("1", ApplicationModes.Help)]
[TestCase("ii", ApplicationModes.Help)]
[TestCase("uu", ApplicationModes.Help)]
[TestCase("i", ApplicationModes.InstallService)]
[TestCase("I", ApplicationModes.InstallService)]
[TestCase("/I", ApplicationModes.InstallService)]
[TestCase("/i", ApplicationModes.InstallService)]
[TestCase("-I", ApplicationModes.InstallService)]
[TestCase("-i", ApplicationModes.InstallService)]
[TestCase("u", ApplicationModes.UninstallService)]
[TestCase("U", ApplicationModes.UninstallService)]
[TestCase("/U", ApplicationModes.UninstallService)]
[TestCase("/u", ApplicationModes.UninstallService)]
[TestCase("-U", ApplicationModes.UninstallService)]
[TestCase("-u", ApplicationModes.UninstallService)]
public void GetApplicationMode_single_arg(string arg, ApplicationModes modes)
{
Router.GetApplicationMode(new[] { arg }).Should().Be(modes);
}
[TestCase("", "", ApplicationModes.Console)]
[TestCase("", null, ApplicationModes.Console)]
[TestCase("i", "n", ApplicationModes.Help)]
public void GetApplicationMode_two_args(string a, string b, ApplicationModes modes)
{
Router.GetApplicationMode(new[] { a, b }).Should().Be(modes);
}
[Test] [Test]
public void Route_should_call_install_service_when_application_mode_is_install() public void Route_should_call_install_service_when_application_mode_is_install()
{ {
@ -123,7 +91,7 @@ namespace NzbDrone.App.Test
var serviceMock = Mocker.GetMock<IServiceProvider>(); var serviceMock = Mocker.GetMock<IServiceProvider>();
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true); Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceDoestExist()); consoleMock.Setup(c => c.PrintServiceDoesNotExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false); serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
Subject.Route(ApplicationModes.UninstallService); Subject.Route(ApplicationModes.UninstallService);

@ -0,0 +1,30 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Test.Common;
namespace NzbDrone.Common.Test.EnvironmentTests
{
[TestFixture]
public class StartupArgumentsFixture : TestBase
{
[Test]
public void empty_array_should_return_empty_flags()
{
var args = new StartupArguments(new string[0]);
args.Flags.Should().BeEmpty();
}
[TestCase("/t")]
[TestCase(" /t")]
[TestCase(" /T")]
[TestCase(" /t ")]
public void should_parse_single_flag(string arg)
{
var args = new StartupArguments(new[] { arg });
args.Flags.Should().HaveCount(1);
args.Flags.Contains("t").Should().BeTrue();
}
}
}

@ -82,6 +82,7 @@
<Compile Include="CacheTests\CachedFixture.cs" /> <Compile Include="CacheTests\CachedFixture.cs" />
<Compile Include="ConfigFileProviderTest.cs" /> <Compile Include="ConfigFileProviderTest.cs" />
<Compile Include="EnsureTest\PathExtensionFixture.cs" /> <Compile Include="EnsureTest\PathExtensionFixture.cs" />
<Compile Include="EnvironmentTests\StartupArgumentsFixture.cs" />
<Compile Include="EnvironmentTests\EnviromentProviderTest.cs" /> <Compile Include="EnvironmentTests\EnviromentProviderTest.cs" />
<Compile Include="EventingTests\MessageAggregatorCommandTests.cs" /> <Compile Include="EventingTests\MessageAggregatorCommandTests.cs" />
<Compile Include="EventingTests\MessageAggregatorEventTests.cs" /> <Compile Include="EventingTests\MessageAggregatorEventTests.cs" />
@ -124,7 +125,6 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="EnviromentTests\" />
<Folder Include="Properties\" /> <Folder Include="Properties\" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

@ -13,10 +13,9 @@ namespace NzbDrone.Common.Test
[SetUp] [SetUp]
public void setup() public void setup()
{ {
Mocker.SetConstant(MainAppContainerBuilder.BuildContainer()); Mocker.SetConstant(MainAppContainerBuilder.BuildContainer(new string[0]));
} }
[Test] [Test]
public void event_handlers_should_be_unique() public void event_handlers_should_be_unique()
{ {

@ -1,6 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Common namespace NzbDrone.Common
{ {
@ -10,7 +11,7 @@ namespace NzbDrone.Common
void WaitForClose(); void WaitForClose();
void PrintHelp(); void PrintHelp();
void PrintServiceAlreadyExist(); void PrintServiceAlreadyExist();
void PrintServiceDoestExist(); void PrintServiceDoesNotExist();
} }
public class ConsoleService : IConsoleService public class ConsoleService : IConsoleService
@ -33,8 +34,9 @@ namespace NzbDrone.Common
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(" Usage: {0} <command> ", Process.GetCurrentProcess().MainModule.ModuleName); Console.WriteLine(" Usage: {0} <command> ", Process.GetCurrentProcess().MainModule.ModuleName);
Console.WriteLine(" Commands:"); Console.WriteLine(" Commands:");
Console.WriteLine(" /i Install the application as a Windows Service ({0}).", ServiceProvider.NZBDRONE_SERVICE_NAME); Console.WriteLine(" /{0} Install the application as a Windows Service ({1}).",StartupArguments.INSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" /u Uninstall already installed Windows Service ({0}).", ServiceProvider.NZBDRONE_SERVICE_NAME); Console.WriteLine(" /{0} Uninstall already installed Windows Service ({1}).",StartupArguments.UNINSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" /{0} Don't open NzbDrone in a browser", StartupArguments.NO_BROWSER);
Console.WriteLine(" <No Arguments> Run application in console mode."); Console.WriteLine(" <No Arguments> Run application in console mode.");
} }
@ -43,7 +45,7 @@ namespace NzbDrone.Common
Console.WriteLine("A service with the same name ({0}) already exists. Aborting installation", ServiceProvider.NZBDRONE_SERVICE_NAME); Console.WriteLine("A service with the same name ({0}) already exists. Aborting installation", ServiceProvider.NZBDRONE_SERVICE_NAME);
} }
public void PrintServiceDoestExist() public void PrintServiceDoesNotExist()
{ {
Console.WriteLine("Can't find service ({0})", ServiceProvider.NZBDRONE_SERVICE_NAME); Console.WriteLine("Can't find service ({0})", ServiceProvider.NZBDRONE_SERVICE_NAME);
} }

@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace NzbDrone.Common.EnvironmentInfo
{
public class StartupArguments
{
public const string NO_BROWSER = "no-browser";
public const string INSTALL_SERVICE = "i";
public const string UNINSTALL_SERVICE = "u";
public const string HELP = "?";
public StartupArguments(string[] args)
{
Flags = new HashSet<string>();
foreach (var s in args)
{
var flag = s.Trim(' ', '/', '-').ToLower();
Flags.Add(flag);
}
}
public HashSet<string> Flags { get; private set; }
}
}

@ -104,6 +104,7 @@
<Compile Include="EnsureThat\Param.cs" /> <Compile Include="EnsureThat\Param.cs" />
<Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" /> <Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" />
<Compile Include="EnvironmentInfo\BuildInfo.cs" /> <Compile Include="EnvironmentInfo\BuildInfo.cs" />
<Compile Include="EnvironmentInfo\StartupArguments.cs" />
<Compile Include="EnvironmentInfo\RuntimeInfo.cs" /> <Compile Include="EnvironmentInfo\RuntimeInfo.cs" />
<Compile Include="EnvironmentInfo\OsInfo.cs" /> <Compile Include="EnvironmentInfo\OsInfo.cs" />
<Compile Include="Exceptions\NzbDroneException.cs" /> <Compile Include="Exceptions\NzbDroneException.cs" />

@ -57,7 +57,7 @@ namespace NzbDrone.Integration.Test
[SetUp] [SetUp]
public void SmokeTestSetup() public void SmokeTestSetup()
{ {
Container = MainAppContainerBuilder.BuildContainer(); Container = MainAppContainerBuilder.BuildContainer(new string[0]);
Container.Register(typeof(IAppFolderInfo), new IntegrationTestFolderInfo()); Container.Register(typeof(IAppFolderInfo), new IntegrationTestFolderInfo());
DbFactory.RegisterDatabase(Container); DbFactory.RegisterDatabase(Container);

@ -81,6 +81,8 @@ namespace NzbDrone.Test.Common
Mocker.SetConstant(LogManager.GetLogger("TestLogger")); Mocker.SetConstant(LogManager.GetLogger("TestLogger"));
Mocker.SetConstant(new StartupArguments(new string[0]));
LogManager.ReconfigExistingLoggers(); LogManager.ReconfigExistingLoggers();
TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "_temp_" + DateTime.Now.Ticks); TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "_temp_" + DateTime.Now.Ticks);

@ -1,9 +1,11 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using NzbDrone.Update.UpdateEngine; using NzbDrone.Update.UpdateEngine;
@ -26,13 +28,16 @@ namespace NzbDrone.Update.Test
[Test] [Test]
public void should_start_console_if_app_type_was_serivce_but_start_failed_because_of_permissions() public void should_start_console_if_app_type_was_serivce_but_start_failed_because_of_permissions()
{ {
string targetFolder = "c:\\NzbDrone\\"; const string targetFolder = "c:\\NzbDrone\\";
Mocker.GetMock<Common.IServiceProvider>().Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME)).Throws(new InvalidOperationException()); Mocker.GetMock<Common.IServiceProvider>().Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME)).Throws(new InvalidOperationException());
Subject.Start(AppType.Service, targetFolder); Subject.Start(AppType.Service, targetFolder);
Mocker.GetMock<IProcessProvider>().Verify(c => c.Start("c:\\NzbDrone\\NzbDrone.Console.exe"), Times.Once()); Mocker.GetMock<IProcessProvider>().Verify(c => c.Start(It.Is<ProcessStartInfo>(s =>
s.FileName == "c:\\NzbDrone\\NzbDrone.Console.exe" &&
s.Arguments == StartupArguments.NO_BROWSER
)), Times.Once());
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }

@ -6,7 +6,7 @@
<ProductVersion>8.0.30703</ProductVersion> <ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}</ProjectGuid> <ProjectGuid>{4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone.Update</RootNamespace> <RootNamespace>NzbDrone.Update</RootNamespace>
<AssemblyName>NzbDrone.Update</AssemblyName> <AssemblyName>NzbDrone.Update</AssemblyName>
@ -54,6 +54,9 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>

@ -1,7 +1,9 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using IServiceProvider = NzbDrone.Common.IServiceProvider; using IServiceProvider = NzbDrone.Common.IServiceProvider;
namespace NzbDrone.Update.UpdateEngine namespace NzbDrone.Update.UpdateEngine
@ -58,14 +60,20 @@ namespace NzbDrone.Update.UpdateEngine
private void StartWinform(string installationFolder) private void StartWinform(string installationFolder)
{ {
_logger.Info("Starting NzbDrone without Console"); Start(installationFolder, "NzbDrone.exe");
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.exe"));
} }
private void StartConsole(string installationFolder) private void StartConsole(string installationFolder)
{ {
_logger.Info("Starting NzbDrone with Console"); Start(installationFolder, "NzbDrone.Console.exe");
_processProvider.Start(Path.Combine(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));
} }
} }
} }

@ -8,6 +8,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=NUnit_002ENonPublicMethodWithTestAttribute/@EntryIndexedValue">ERROR</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=NUnit_002ENonPublicMethodWithTestAttribute/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReturnTypeCanBeEnumerable_002EGlobal/@EntryIndexedValue">HINT</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ReturnTypeCanBeEnumerable_002EGlobal/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">HINT</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseObjectOrCollectionInitializer/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Position/@EntryValue">BOTH_SIDES</s:String> <s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Position/@EntryValue">BOTH_SIDES</s:String>

@ -49,10 +49,10 @@ namespace NzbDrone
return; return;
} }
var container = MainAppContainerBuilder.BuildContainer(); var container = MainAppContainerBuilder.BuildContainer(args);
DbFactory.RegisterDatabase(container); DbFactory.RegisterDatabase(container);
container.Resolve<Router>().Route(args); container.Resolve<Router>().Route();
} }
catch (Exception e) catch (Exception e)
{ {

@ -22,12 +22,13 @@ namespace NzbDrone
private readonly IHostController _hostController; private readonly IHostController _hostController;
private readonly IProcessProvider _processProvider; private readonly IProcessProvider _processProvider;
private readonly PriorityMonitor _priorityMonitor; private readonly PriorityMonitor _priorityMonitor;
private readonly StartupArguments _startupArguments;
private readonly IFirewallAdapter _firewallAdapter; private readonly IFirewallAdapter _firewallAdapter;
private readonly IUrlAclAdapter _urlAclAdapter; private readonly IUrlAclAdapter _urlAclAdapter;
private readonly Logger _logger; private readonly Logger _logger;
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController, IRuntimeInfo runtimeInfo, public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController, IRuntimeInfo runtimeInfo,
IProcessProvider processProvider, PriorityMonitor priorityMonitor, IProcessProvider processProvider, PriorityMonitor priorityMonitor, StartupArguments startupArguments,
IFirewallAdapter firewallAdapter, IUrlAclAdapter urlAclAdapter, Logger logger) IFirewallAdapter firewallAdapter, IUrlAclAdapter urlAclAdapter, Logger logger)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
@ -35,6 +36,7 @@ namespace NzbDrone
_runtimeInfo = runtimeInfo; _runtimeInfo = runtimeInfo;
_processProvider = processProvider; _processProvider = processProvider;
_priorityMonitor = priorityMonitor; _priorityMonitor = priorityMonitor;
_startupArguments = startupArguments;
_firewallAdapter = firewallAdapter; _firewallAdapter = firewallAdapter;
_urlAclAdapter = urlAclAdapter; _urlAclAdapter = urlAclAdapter;
_logger = logger; _logger = logger;
@ -55,7 +57,9 @@ namespace NzbDrone
} }
_hostController.StartServer(); _hostController.StartServer();
if (_runtimeInfo.IsUserInteractive && _configFileProvider.LaunchBrowser) if (!_startupArguments.Flags.Contains(StartupArguments.NO_BROWSER) &&
_runtimeInfo.IsUserInteractive &&
_configFileProvider.LaunchBrowser)
{ {
try try
{ {

@ -1,11 +1,9 @@
using NLog; using Nancy.Bootstrapper;
using Nancy.Bootstrapper;
using NzbDrone.Api; using NzbDrone.Api;
using NzbDrone.Api.SignalR; using NzbDrone.Api.SignalR;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
using NzbDrone.Common.Messaging; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
@ -13,15 +11,12 @@ namespace NzbDrone
{ {
public class MainAppContainerBuilder : ContainerBuilderBase public class MainAppContainerBuilder : ContainerBuilderBase
{ {
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilderBase"); public static IContainer BuildContainer(string[] args)
public static IContainer BuildContainer()
{ {
return new MainAppContainerBuilder().Container; return new MainAppContainerBuilder(args).Container;
} }
private MainAppContainerBuilder(string[] args)
private MainAppContainerBuilder()
: base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api") : base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api")
{ {
AutoRegisterImplementations<NzbDronePersistentConnection>(); AutoRegisterImplementations<NzbDronePersistentConnection>();
@ -31,8 +26,7 @@ namespace NzbDrone
Container.Register<INancyBootstrapper, NancyBootstrapper>(); Container.Register<INancyBootstrapper, NancyBootstrapper>();
Container.Register(new StartupArguments(args));
} }
} }
} }

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Composition;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.SysTray; using NzbDrone.SysTray;
using IServiceProvider = NzbDrone.Common.IServiceProvider; using IServiceProvider = NzbDrone.Common.IServiceProvider;
@ -14,25 +13,28 @@ namespace NzbDrone
{ {
private readonly INzbDroneServiceFactory _nzbDroneServiceFactory; private readonly INzbDroneServiceFactory _nzbDroneServiceFactory;
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private readonly StartupArguments _startupArguments;
private readonly IConsoleService _consoleService; private readonly IConsoleService _consoleService;
private readonly IRuntimeInfo _runtimeInfo; private readonly IRuntimeInfo _runtimeInfo;
private readonly ISystemTrayApp _systemTrayProvider; private readonly ISystemTrayApp _systemTrayProvider;
private readonly Logger _logger; private readonly Logger _logger;
public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider, public Router(INzbDroneServiceFactory nzbDroneServiceFactory, IServiceProvider serviceProvider, StartupArguments startupArguments,
IConsoleService consoleService, IRuntimeInfo runtimeInfo, ISystemTrayApp systemTrayProvider, Logger logger) IConsoleService consoleService, IRuntimeInfo runtimeInfo, ISystemTrayApp systemTrayProvider, Logger logger)
{ {
_nzbDroneServiceFactory = nzbDroneServiceFactory; _nzbDroneServiceFactory = nzbDroneServiceFactory;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_startupArguments = startupArguments;
_consoleService = consoleService; _consoleService = consoleService;
_runtimeInfo = runtimeInfo; _runtimeInfo = runtimeInfo;
_systemTrayProvider = systemTrayProvider; _systemTrayProvider = systemTrayProvider;
_logger = logger; _logger = logger;
} }
public void Route(IEnumerable<string> args) public void Route()
{ {
Route(GetApplicationMode(args)); var appMode = GetApplicationMode();
Route(appMode);
} }
public void Route(ApplicationModes applicationModes) public void Route(ApplicationModes applicationModes)
@ -87,7 +89,7 @@ namespace NzbDrone
_logger.Trace("Uninstall Service selected"); _logger.Trace("Uninstall Service selected");
if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)) if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
{ {
_consoleService.PrintServiceDoestExist(); _consoleService.PrintServiceDoesNotExist();
} }
else else
{ {
@ -104,20 +106,24 @@ namespace NzbDrone
} }
} }
public static ApplicationModes GetApplicationMode(IEnumerable<string> args) private ApplicationModes GetApplicationMode()
{ {
if (args == null) return ApplicationModes.Console; if (_startupArguments.Flags.Contains(StartupArguments.HELP))
{
var cleanArgs = args.Where(c => c != null && !String.IsNullOrWhiteSpace(c)).ToList(); return ApplicationModes.Help;
if (cleanArgs.Count == 0) return ApplicationModes.Console; }
if (cleanArgs.Count != 1) return ApplicationModes.Help;
var arg = cleanArgs.First().Trim('/', '\\', '-').ToLower(); if (_startupArguments.Flags.Contains(StartupArguments.INSTALL_SERVICE))
{
return ApplicationModes.InstallService;
}
if (arg == "i") return ApplicationModes.InstallService; if (_startupArguments.Flags.Contains(StartupArguments.UNINSTALL_SERVICE))
if (arg == "u") return ApplicationModes.UninstallService; {
return ApplicationModes.UninstallService;
}
return ApplicationModes.Help; return ApplicationModes.Console;
} }
} }
} }

Loading…
Cancel
Save