diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 5d0b52a763..87ed233422 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -159,6 +159,7 @@ public static class Features public static readonly string UseFipsCompliantChecksums = "useFipsCompliantChecksums"; public static readonly string ScriptsCheckLastExitCode = "scriptsCheckLastExitCode"; public static readonly string ShowNonElevatedWarnings = "showNonElevatedWarnings"; + public static readonly string ShowDownloadProgress = "showDownloadProgress"; } public static class Messages diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 36df59286c..346a1797b1 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -280,6 +280,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile config.Features.UsePackageExitCodes = set_feature_flag(ApplicationParameters.Features.UsePackageExitCodes, configFileSettings, defaultEnabled: true, description: "Use Package Exit Codes - Package scripts can provide exit codes. With this on, package exit codes will be what choco uses for exit when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. With this feature off, choco will exit with a 0 or a 1 (matching previous behavior). Available in 0.9.10+."); config.Features.UseFipsCompliantChecksums = set_feature_flag(ApplicationParameters.Features.UseFipsCompliantChecksums, configFileSettings, defaultEnabled: false, description: "Use FIPS Compliant Checksums - Ensure checksumming done by choco uses FIPS compliant algorithms. Not recommended unless required by FIPS Mode. Enabling on an existing installation could have unintended consequences related to upgrades/uninstalls. Available in 0.9.10+."); config.Features.ShowNonElevatedWarnings = set_feature_flag(ApplicationParameters.Features.ShowNonElevatedWarnings, configFileSettings, defaultEnabled: true, description: "Show Non-Elevated Warnings - Display non-elevated warnings. Available in 0.10.4+."); + config.Features.ShowDownloadProgress = set_feature_flag(ApplicationParameters.Features.ShowDownloadProgress, configFileSettings, defaultEnabled: true, description: "Show Download Progress - Show download progress percentages in the CLI. Available in 0.10.4+."); config.Features.ScriptsCheckLastExitCode = set_feature_flag(ApplicationParameters.Features.ScriptsCheckLastExitCode, configFileSettings, defaultEnabled: false, description: "Scripts Check $LastExitCode (external commands) - Leave this off unless you absolutely need it while you fix your package scripts to use `throw 'error message'` or `Set-PowerShellExitCode #` instead of `exit #`. This behavior started in 0.9.10 and produced hard to find bugs. If the last external process exits successfully but with an exit code of not zero, this could cause hard to detect package failures. Available in 0.10.3+. Will be removed in 0.11.0."); config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass."); } @@ -368,6 +369,9 @@ private static void set_global_options(IList args, ChocolateyConfigurati .Add("use-system-powershell", "UseSystemPowerShell - Execute PowerShell using an external process instead of the built-in PowerShell host. Should only be used when internal host is failing. Available in 0.9.10+.", option => config.Features.UsePowerShellHost = option == null) + .Add("no-progress", + "Do Not Show Progress - Do not show download progress percentages. Available in 0.10.4+.", + option => config.Features.ShowDownloadProgress = option == null) ; }, (unparsedArgs) => diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index c546e4649f..8771dfcd9e 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -353,6 +353,7 @@ public sealed class FeaturesConfiguration public bool UsePackageExitCodes { get; set; } public bool UseFipsCompliantChecksums { get; set; } public bool ShowNonElevatedWarnings { get; set; } + public bool ShowDownloadProgress { get; set; } //todo remove in 0.11.0 public bool ScriptsCheckLastExitCode { get; set; } } diff --git a/src/chocolatey/infrastructure.app/nuget/ChocolateyNugetLogger.cs b/src/chocolatey/infrastructure.app/nuget/ChocolateyNugetLogger.cs index 66318573c5..a0232f4e82 100644 --- a/src/chocolatey/infrastructure.app/nuget/ChocolateyNugetLogger.cs +++ b/src/chocolatey/infrastructure.app/nuget/ChocolateyNugetLogger.cs @@ -15,6 +15,7 @@ namespace chocolatey.infrastructure.app.nuget { + using logging; using NuGet; // ReSharper disable InconsistentNaming @@ -41,7 +42,13 @@ public void Log(MessageLevel level, string message, params object[] args) break; case MessageLevel.Error: this.Log().Error("[NuGet] " + message, args); - break; + break; + //todo: case MessageLevel.Fatal: + // this.Log().Fatal("[NuGet] " + message, args); + // break; + //case MessageLevel.Verbose: + // this.Log().Info(ChocolateyLoggers.Verbose,"[NuGet] " + message, args); + // break; } } } diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 595ffdad37..1ff94b6310 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -31,13 +31,7 @@ public sealed class NugetCommon { public static IFileSystem GetNuGetFileSystem(ChocolateyConfiguration configuration, ILogger nugetLogger) { - var fileSystem = new ChocolateyPhysicalFileSystem(ApplicationParameters.PackagesLocation); - if (configuration.Debug) - { - fileSystem.Logger = nugetLogger; - } - - return fileSystem; + return new ChocolateyPhysicalFileSystem(ApplicationParameters.PackagesLocation) { Logger = nugetLogger }; } public static IPackagePathResolver GetPathResolver(ChocolateyConfiguration configuration, IFileSystem nugetPackagesFileSystem) @@ -45,27 +39,27 @@ public static IPackagePathResolver GetPathResolver(ChocolateyConfiguration confi return new ChocolateyPackagePathResolver(nugetPackagesFileSystem, configuration.AllowMultipleVersions); } - public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem) + public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem, ILogger nugetLogger) { - IPackageRepository localRepository = new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem); - localRepository.PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec; - - return localRepository; + return new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem) { Logger = nugetLogger, PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec }; } public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader) { - packageDownloader.ProgressAvailable += (sender, e) => + if (configuration.Features.ShowDownloadProgress) { - // http://stackoverflow.com/a/888569/18475 - Console.Write("\rProgress: {0} {1}%".format_with(e.Operation, e.PercentComplete.to_string()).PadRight(Console.WindowWidth)); - if (e.PercentComplete == 100) + packageDownloader.ProgressAvailable += (sender, e) => { - Console.WriteLine(""); - } - }; - - IEnumerable sources = configuration.Sources.Split(new[] {";", ","}, StringSplitOptions.RemoveEmptyEntries); + // http://stackoverflow.com/a/888569/18475 + Console.Write("\rProgress: {0} {1}%".format_with(e.Operation, e.PercentComplete.to_string()).PadRight(Console.WindowWidth)); + if (e.PercentComplete == 100) + { + Console.WriteLine(""); + } + }; + } + + IEnumerable sources = configuration.Sources.Split(new[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries); IList repositories = new List(); @@ -126,16 +120,16 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con var uri = new Uri(source); if (uri.IsFile || uri.IsUnc) { - repositories.Add(new ChocolateyLocalPackageRepository(uri.LocalPath)); + repositories.Add(new ChocolateyLocalPackageRepository(uri.LocalPath) { Logger = nugetLogger }); } else { - repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri, bypassProxy), packageDownloader)); + repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri, bypassProxy) { UserAgent = "Chocolatey Core" }, packageDownloader) { Logger = nugetLogger }); } } catch (Exception) { - repositories.Add(new ChocolateyLocalPackageRepository(source)); + repositories.Add(new ChocolateyLocalPackageRepository(source) { Logger = nugetLogger }); } } @@ -145,12 +139,12 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con } //todo well that didn't work on failing repos... grrr - var repository = new AggregateRepository(repositories) {IgnoreFailingRepositories = true}; - repository.ResolveDependenciesVertically = true; - if (configuration.Debug) + var repository = new AggregateRepository(repositories) { - repository.Logger = nugetLogger; - } + IgnoreFailingRepositories = true, + Logger = nugetLogger, + ResolveDependenciesVertically = true + }; return repository; } @@ -159,24 +153,20 @@ public static IPackageManager GetPackageManager(ChocolateyConfiguration configur { IFileSystem nugetPackagesFileSystem = GetNuGetFileSystem(configuration, nugetLogger); IPackagePathResolver pathResolver = GetPathResolver(configuration, nugetPackagesFileSystem); - var packageManager = new PackageManager(GetRemoteRepository(configuration, nugetLogger, packageDownloader), pathResolver, nugetPackagesFileSystem, GetLocalRepository(pathResolver, nugetPackagesFileSystem)) + var packageManager = new PackageManager(GetRemoteRepository(configuration, nugetLogger, packageDownloader), pathResolver, nugetPackagesFileSystem, GetLocalRepository(pathResolver, nugetPackagesFileSystem, nugetLogger)) { DependencyVersion = DependencyVersion.Highest, + Logger = nugetLogger, }; - if (configuration.Debug) - { - packageManager.Logger = nugetLogger; - } - //NOTE DO NOT EVER use this method - packageManager.PackageInstalling += (s, e) => packageManager.PackageInstalled += (s, e) => { var pkg = e.Package; "chocolatey".Log().Info(ChocolateyLoggers.Important, "{0}{1} v{2}{3}{4}{5}".format_with( - Environment.NewLine, - pkg.Id, - pkg.Version.to_string(), + Environment.NewLine, + pkg.Id, + pkg.Version.to_string(), configuration.Force ? " (forced)" : string.Empty, pkg.IsApproved ? " [Approved]" : string.Empty, pkg.PackageTestResultStatus == "Failing" && pkg.IsDownloadCacheAvailable ? " - Likely broken for FOSS users (due to download location changes)" : pkg.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 3ce6ee2337..ec208679f5 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -20,6 +20,7 @@ namespace chocolatey.infrastructure.app.services using System.Collections.Generic; using System.IO; using System.Linq; + using System.Net; using NuGet; using adapters; using commandline; @@ -468,7 +469,15 @@ public ConcurrentDictionary install_run(ChocolateyConfigu } catch (Exception ex) { - var logMessage = "{0} not installed. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, ex.Message); + var message = ex.Message; + var webException = ex as System.Net.WebException; + if (webException != null) + { + var response = webException.Response as HttpWebResponse; + if (response != null && !string.IsNullOrWhiteSpace(response.StatusDescription)) message += " {0}".format_with(response.StatusDescription); + } + + var logMessage = "{0} not installed. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, message); this.Log().Error(ChocolateyLoggers.Important, logMessage); var errorResult = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, version.to_string(), null)); errorResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage)); @@ -748,7 +757,15 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu } catch (Exception ex) { - var logMessage = "{0} not upgraded. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, ex.Message); + var message = ex.Message; + var webException = ex as System.Net.WebException; + if (webException != null) + { + var response = webException.Response as HttpWebResponse; + if (response != null && !string.IsNullOrWhiteSpace(response.StatusDescription)) message += " {0}".format_with(response.StatusDescription); + } + + var logMessage = "{0} not upgraded. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, message); this.Log().Error(ChocolateyLoggers.Important, logMessage); packageResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage)); if (packageResult.ExitCode == 0) packageResult.ExitCode = 1; diff --git a/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs b/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs index 2f3f8241a8..ef8bcefebb 100644 --- a/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs +++ b/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs @@ -128,8 +128,11 @@ public override void WriteProgress(long sourceId, ProgressRecord record) this.Log().Debug(record.Activity.escape_curly_braces()); } - // http://stackoverflow.com/a/888569/18475 - Console.Write("\rProgress: {0}% - {1}".format_with(record.PercentComplete.to_string(), record.StatusDescription).PadRight(Console.WindowWidth)); + if (_configuration.Features.ShowDownloadProgress) + { + // http://stackoverflow.com/a/888569/18475 + Console.Write("\rProgress: {0}% - {1}".format_with(record.PercentComplete.to_string(), record.StatusDescription).PadRight(Console.WindowWidth)); + } } public override void WriteVerboseLine(string message)