diff --git a/src/chocolatey/infrastructure/licensing/LicenseValidation.cs b/src/chocolatey/infrastructure/licensing/LicenseValidation.cs index b866369864..826a13d4ac 100644 --- a/src/chocolatey/infrastructure/licensing/LicenseValidation.cs +++ b/src/chocolatey/infrastructure/licensing/LicenseValidation.cs @@ -34,6 +34,8 @@ public static ChocolateyLicense validate() LicenseType = ChocolateyLicenseType.Unknown }; + var regularLogOutput = determine_if_regular_output_for_logging(); + string licenseFile = ApplicationParameters.LicenseFileLocation; var userLicenseFile = ApplicationParameters.UserLicenseFileLocation; if (File.Exists(userLicenseFile)) licenseFile = userLicenseFile; @@ -50,7 +52,7 @@ public static ChocolateyLicense validate() { if (Directory.GetFiles(licenseDirectory).Length != 0) { - "chocolatey".Log().Error(@"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)); } @@ -60,9 +62,9 @@ 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(@"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(ChocolateyLoggers.Important, @" Move license file to '{0}' to allow commercial features.".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)); } } @@ -88,7 +90,7 @@ public static ChocolateyLicense validate() { chocolateyLicense.IsValid = false; chocolateyLicense.InvalidReason = e.Message; - "chocolatey".Log().Error("A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message, + "chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, "A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message, "A license was also not found in the user profile: '{0}'.".format_with(ApplicationParameters.UserLicenseFileLocation))); } catch (Exception e) @@ -96,7 +98,7 @@ public static ChocolateyLicense validate() //license may be invalid chocolateyLicense.IsValid = false; chocolateyLicense.InvalidReason = e.Message; - "chocolatey".Log().Error("A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message)); + "chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, "A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message)); } var chocolateyLicenseType = ChocolateyLicenseType.Unknown; @@ -134,5 +136,16 @@ public static ChocolateyLicense validate() return chocolateyLicense; } + + private static bool determine_if_regular_output_for_logging() + { + var args = Environment.GetCommandLineArgs(); + if (args == null || args.Length < 2) return true; + + var firstArg = args[1].to_string(); + if (firstArg.is_equal_to("-v") || firstArg.is_equal_to("--version")) return false; + + return true; + } } }