From 32621084d43e826784f67c1d75567f0200ca017a Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 5 Jun 2016 16:32:30 -0500 Subject: [PATCH] (GH-620) Set pro/business environment Provide a way to update pro/business environment values that are set. Pro/business was already doing this out of bound, but this allows for more consistency in controlling when those values are set. --- .../ApplicationParameters.cs | 1 + .../configuration/EnvironmentSettings.cs | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 761ba5fe4e..f8d5e81918 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -49,6 +49,7 @@ public static class ApplicationParameters public static readonly string LicensedAssemblyLocation = _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll"); public static readonly string LicensedComponentRegistry = @"chocolatey.licensed.infrastructure.app.registration.ContainerBinding"; public static readonly string LicensedConfigurationBuilder = @"chocolatey.licensed.infrastructure.app.builders.ConfigurationBuilder"; + public static readonly string LicensedEnvironmentSettings = @"chocolatey.licensed.infrastructure.app.configuration.EnvironmentSettings"; public static readonly string PackageNamesSeparator = ";"; public static readonly string OfficialChocolateyPublicKey = "79d02ea9cad655eb"; diff --git a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs index fdb81aa6a8..9106e9995c 100644 --- a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs +++ b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs @@ -91,6 +91,50 @@ public static void set_environment_variables(ChocolateyConfiguration config) if (config.Features.UsePowerShellHost) Environment.SetEnvironmentVariable("ChocolateyPowerShellHost", "true"); if (config.Force) Environment.SetEnvironmentVariable("ChocolateyForce", "true"); + set_licensed_environment(config); + } + + private static void set_licensed_environment(ChocolateyConfiguration config) + { + if (!config.Information.IsLicensedVersion) return; + + var licenseAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name.is_equal_to("chocolatey.licensed")); + + if (licenseAssembly != null) + { + Type licensedEnvironmentSettings = licenseAssembly.GetType(ApplicationParameters.LicensedEnvironmentSettings, throwOnError: false, ignoreCase: true); + + if (licensedEnvironmentSettings == null) + { + "chocolatey".Log().Warn( + ChocolateyLoggers.Important, + @"Unable to set licensed environment. This is likely related to a + missing or outdated licensed DLL."); + return; + } + try + { + object componentClass = Activator.CreateInstance(licensedEnvironmentSettings); + + licensedEnvironmentSettings.InvokeMember( + SET_ENVIRONMENT_METHOD, + BindingFlags.InvokeMethod, + null, + componentClass, + new Object[] { config } + ); + } + catch (Exception ex) + { + "chocolatey".Log().Error( + ChocolateyLoggers.Important, + @"Error when setting configuration for '{0}':{1} {2}".format_with( + licensedEnvironmentSettings.FullName, + Environment.NewLine, + ex.Message + )); + } + } } } }