Skip to content

Commit

Permalink
Merge pull request #2669 from corbob/another_fix
Browse files Browse the repository at this point in the history
(#2660) Check for valid license before checking for compatibility
gep13 authored Mar 29, 2022
2 parents a418b8f + cf28622 commit 1df3031
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ private static void Main(string[] args)
warning => { warnings.Add(warning); }
);

if (!license.IsCompatible && !config.DisableCompatibilityChecks)
if (license.is_licensed_version() && !license.IsCompatible && !config.DisableCompatibilityChecks)
{
write_warning_for_incompatible_versions();
}
@@ -171,7 +171,7 @@ private static void Main(string[] args)
}
finally
{
if (license != null && !license.IsCompatible && config != null && !config.DisableCompatibilityChecks)
if (license != null && license.is_licensed_version() && !license.IsCompatible && config != null && !config.DisableCompatibilityChecks)
{
write_warning_for_incompatible_versions();
}
17 changes: 9 additions & 8 deletions src/chocolatey/infrastructure/licensing/LicenseValidation.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © 2017 - 2021 Chocolatey Software, Inc
// Copyright © 2011 - 2017 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.
@@ -31,7 +31,8 @@ public static ChocolateyLicense validate()
{
var chocolateyLicense = new ChocolateyLicense
{
LicenseType = ChocolateyLicenseType.Unknown
LicenseType = ChocolateyLicenseType.Unknown,
IsCompatible = true
};

var regularLogOutput = determine_if_regular_output_for_logging();
@@ -52,7 +53,7 @@ public static ChocolateyLicense validate()
{
if (Directory.GetFiles(licenseDirectory).Length != 0)
{
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Files found in directory '{0}' but not a
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Files found in directory '{0}' but not a
valid license file. License should be named '{1}'.".format_with(licenseDirectory, licenseFileName));
"chocolatey".Log().Warn(ChocolateyLoggers.Important,@" Rename license file to '{0}' to allow commercial features.".format_with(licenseFileName));
}
@@ -62,12 +63,12 @@ public static ChocolateyLicense validate()
// - user put the license file in the top level location and/or forgot to rename it
if (File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName)) || File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName + ".txt")))
{
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Chocolatey license found in the wrong location. File must be located at
"chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Chocolatey license found in the wrong location. File must be located at
'{0}'.".format_with(ApplicationParameters.LicenseFileLocation));
"chocolatey".Log().Warn(regularLogOutput ? ChocolateyLoggers.Important : ChocolateyLoggers.LogFileOnly, @" Move license file to '{0}' to allow commercial features.".format_with(ApplicationParameters.LicenseFileLocation));
}
}

// no IFileSystem at this point
if (File.Exists(licenseFile))
{

0 comments on commit 1df3031

Please sign in to comment.