Skip to content

Commit

Permalink
Merge pull request #3229 from corbob/3224-fix-license-check
Browse files Browse the repository at this point in the history
(#3224) Do not try to use the Licensed Assembly when it is not loaded for compatibility reasons.
  • Loading branch information
AdmiringWorm committed Jun 27, 2023
2 parents d871a22 + 293e480 commit a6bbcbd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 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
@@ -1,4 +1,4 @@
// Copyright © 2017 - 2021 Chocolatey Software, Inc
// Copyright © 2017 - 2021 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -134,10 +134,13 @@ 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
2 changes: 1 addition & 1 deletion tests/helpers/common/Chocolatey/Get-ChocolateyVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[CmdletBinding()]
param()
if (-not $script:runningVersion) {
[NuGet.Versioning.NuGetVersion]$script:runningVersion = ((Invoke-Choco --version).Lines | Where-Object { $_ -NotMatch "please upgrade" }) -join '`r`n'
[NuGet.Versioning.NuGetVersion]$script:runningVersion = (Invoke-Choco --version).Lines | Where-Object { $_ -Match "^\d+\.[\d\.]+" } | Select-Object -First 1
}

$script:runningVersion
Expand Down

0 comments on commit a6bbcbd

Please sign in to comment.