Skip to content

Commit

Permalink
(chocolatey#3224) Add Assembly Loaded configuration option
Browse files Browse the repository at this point in the history
In order to determine if the Licensed Assembly has been loaded, we
either need to validate the license every time, or add it somewhere that
we can access more easily. This commit adds a `IsLicensedAssemblyLoaded`
boolean to the `InformationCommand` property of
`ChocolateyConfiguration` beside `IsLicensedVersion` so that we can
reference this property instead of validating the license every time.

Additionally when we're checking for license features, we should be also checking if
the licensed assembly is loaded. When the licensed assembly is not fully
loaded, many features may not work, or are not expected to be used. As
such, this commit updates the logic to check for a valid license as well
as the Assembly to be loaded so that we don't accidentally cause issues
when the assembly is not being used.
  • Loading branch information
corbob committed Jun 27, 2023
1 parent 3208ec4 commit 275ed04
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ private static void SetEnvironmentOptions(ChocolateyConfiguration config)
private static void SetLicensedOptions(ChocolateyConfiguration config, ChocolateyLicense license, ConfigFileSettings configFileSettings)
{
config.Information.IsLicensedVersion = license.IsLicensedVersion();
config.Information.IsLicensedAssemblyLoaded = license.AssemblyLoaded;
config.Information.LicenseType = license.LicenseType.DescriptionOrValue();

if (license.AssemblyLoaded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ public sealed class InformationCommandConfiguration
public bool IsUserRemote { get; set; }
public bool IsProcessElevated { get; set; }
public bool IsLicensedVersion { get; set; }
public bool IsLicensedAssemblyLoaded { get; set; }
public string LicenseType { get; set; }
public string CurrentDirectory { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ public static void SetEnvironmentVariables(ChocolateyConfiguration config)

private static void SetLicensedEnvironment(ChocolateyConfiguration config)
{
if (!config.Information.IsLicensedVersion) return;

Environment.SetEnvironmentVariable("ChocolateyLicenseType", config.Information.LicenseType);

if (!(config.Information.IsLicensedVersion && config.Information.IsLicensedAssemblyLoaded)) return;

var licenseAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name.IsEqualTo("chocolatey.licensed"));

if (licenseAssembly != null)
Expand Down

0 comments on commit 275ed04

Please sign in to comment.