diff --git a/src/chocolatey.console/Program.cs b/src/chocolatey.console/Program.cs index 03b44a7eff..30554ce404 100644 --- a/src/chocolatey.console/Program.cs +++ b/src/chocolatey.console/Program.cs @@ -27,15 +27,13 @@ namespace chocolatey.console using infrastructure.commandline; using infrastructure.configuration; using infrastructure.extractors; - using infrastructure.filesystem; - using infrastructure.information; using infrastructure.licensing; using infrastructure.logging; using infrastructure.registration; using resources; - using SimpleInjector; using Console = System.Console; using Environment = System.Environment; + using IFileSystem = infrastructure.filesystem.IFileSystem; public sealed class Program { @@ -52,33 +50,7 @@ private static void Main(string[] args) Log4NetAppenderConfiguration.configure(loggingLocation); Bootstrap.initialize(); Bootstrap.startup(); - - var license = LicenseValidation.validate(); - if (license.is_licensed_version()) - { - try - { - var licensedAssembly = Assembly.LoadFile(ApplicationParameters.LicensedAssemblyLocation); - license.AssemblyLoaded = true; - license.Assembly = licensedAssembly; - license.Version = VersionInformation.get_current_informational_version(licensedAssembly); - Type licensedComponent = licensedAssembly.GetType(ApplicationParameters.LicensedComponentRegistry, throwOnError: false, ignoreCase: true); - SimpleInjectorContainer.add_component_registry_class(licensedComponent); - } - catch (Exception ex) - { - "chocolatey".Log().Error( -@"Error when attempting to load chocolatey licensed assembly. Ensure - that chocolatey.licensed.dll exists at - '{0}'. - Install with `choco install chocolatey.extension`. - The error message itself may be helpful as well:{1} {2}".format_with( - ApplicationParameters.LicensedAssemblyLocation, - Environment.NewLine, - ex.Message - )); - } - } + var license = License.validate_license(); var container = SimpleInjectorContainer.Container; var config = container.GetInstance(); @@ -185,7 +157,6 @@ Install with `choco install chocolatey.extension`. #endif pause_execution_if_debug(); Bootstrap.shutdown(); - Environment.Exit(Environment.ExitCode); } } diff --git a/src/chocolatey/GetChocolatey.cs b/src/chocolatey/GetChocolatey.cs index de3e8f11a9..5110c34487 100644 --- a/src/chocolatey/GetChocolatey.cs +++ b/src/chocolatey/GetChocolatey.cs @@ -18,6 +18,7 @@ namespace chocolatey using System; using System.Collections.Generic; using infrastructure.licensing; + using NuGet; using SimpleInjector; using infrastructure.adapters; using infrastructure.app; @@ -26,11 +27,10 @@ namespace chocolatey using infrastructure.app.runners; using infrastructure.configuration; using infrastructure.extractors; - using infrastructure.filesystem; using infrastructure.logging; using infrastructure.registration; - using infrastructure.services; using resources; + using IFileSystem = infrastructure.filesystem.IFileSystem; // ReSharper disable InconsistentNaming @@ -61,7 +61,7 @@ public GetChocolatey() { Log4NetAppenderConfiguration.configure(); Bootstrap.initialize(); - _license = LicenseValidation.validate(); + _license = License.validate_license(); _container = SimpleInjectorContainer.Container; } @@ -221,7 +221,13 @@ public int ListCount() private ChocolateyConfiguration create_configuration(IList args) { var configuration = new ChocolateyConfiguration(); - ConfigurationBuilder.set_up_configuration(args, configuration, _container, _license, null); + ConfigurationBuilder.set_up_configuration( + args, + configuration, + _container, + _license, + null); + Config.initialize_with(configuration); configuration.PromptForConfirmation = false; diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index 2c4a7e3f45..576d0fdc5f 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -144,6 +144,7 @@ + diff --git a/src/chocolatey/infrastructure/licensing/License.cs b/src/chocolatey/infrastructure/licensing/License.cs new file mode 100644 index 0000000000..783942b2b4 --- /dev/null +++ b/src/chocolatey/infrastructure/licensing/License.cs @@ -0,0 +1,59 @@ +// Copyright © 2011 - Present RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.infrastructure.licensing +{ + using System; + using adapters; + using app; + using information; + using registration; + using Environment = System.Environment; + + public static class License + { + public static ChocolateyLicense validate_license() + { + var license = LicenseValidation.validate(); + if (license.is_licensed_version()) + { + try + { + var licensedAssembly = Assembly.LoadFile(ApplicationParameters.LicensedAssemblyLocation); + license.AssemblyLoaded = true; + license.Assembly = licensedAssembly; + license.Version = VersionInformation.get_current_informational_version(licensedAssembly); + Type licensedComponent = licensedAssembly.GetType(ApplicationParameters.LicensedComponentRegistry, throwOnError: false, ignoreCase: true); + SimpleInjectorContainer.add_component_registry_class(licensedComponent); + } + catch (Exception ex) + { + "chocolatey".Log().Error( +@"Error when attempting to load chocolatey licensed assembly. Ensure + that chocolatey.licensed.dll exists at + '{0}'. + Install with `choco install chocolatey.extension`. + The error message itself may be helpful as well:{1} {2}".format_with( + ApplicationParameters.LicensedAssemblyLocation, + Environment.NewLine, + ex.Message + )); + } + } + + return license; + } + } +}