Skip to content

Commit

Permalink
(GH-620) Set pro/business environment
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Jun 5, 2016
1 parent e627a01 commit 3262108
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}
}
}
}
}

0 comments on commit 3262108

Please sign in to comment.