diff --git a/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 b/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 index 142edd6009..e3c64e025b 100644 --- a/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 +++ b/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 @@ -162,10 +162,12 @@ param( } if ($total -eq $goal) { - Write-Progress "Completed download of $url." "Completed a total of $total bytes of $fileName" -id 0 -Completed + Write-Progress "Completed download of $url." "Completed download of $fileName ($goalFormatted)." -id 0 -Completed } } } while ($count -gt 0) + Write-Host "" + Write-Host "Download of $([System.IO.Path]::GetFileName($fileName)) ($goalFormatted) completed." } catch { throw $_.Exception } finally { diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 3a5b5b60d5..1b0f30b10f 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -128,6 +128,9 @@ private static ChocolateyConfiguration baseline_configuration() config.Verbose = false; config.Input = config.PackageNames = string.Empty; config.ListCommand.LocalOnly = false; + //config.Features.UsePowerShellHost = true; + //config.Features.AutoUninstaller = true; + //config.Features.CheckSumFiles = true; return config; } diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index 140756815d..ab652db687 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -450,10 +450,27 @@ private PowerShellExecutionResults run_host(ChocolateyConfiguration config, stri { pipeline.Invoke(); } + catch (RuntimeException ex) + { + var errorStackTrace = ex.StackTrace; + var record = ex.ErrorRecord; + if (record != null) + { + // not available in v1 + //errorStackTrace = record.ScriptStackTrace; + var scriptStackTrace = record.GetType().GetProperty("ScriptStackTrace"); + if (scriptStackTrace != null) + { + var scriptError = scriptStackTrace.GetValue(record, null).to_string(); + if (!string.IsNullOrWhiteSpace(scriptError)) errorStackTrace = scriptError; + } + } + this.Log().Error("ERROR: {0}{1}".format_with(ex.Message, !config.Debug ? string.Empty : "{0} {1}".format_with(Environment.NewLine,errorStackTrace))); + } catch (Exception ex) { // Unfortunately this doesn't print line number and character. It might be nice to get back to those items unless it involves tons of work. - this.Log().Error("ERROR: {0}".format_with(ex.Message)); //, !config.Debug ? string.Empty : "{0} {1}".format_with(Environment.NewLine,ex.StackTrace))); + this.Log().Error("ERROR: {0}{1}".format_with(ex.Message, !config.Debug ? string.Empty : "{0} {1}".format_with(Environment.NewLine,ex.StackTrace))); } if (pipeline.PipelineStateInfo != null) diff --git a/src/chocolatey/infrastructure/commands/Execute.cs b/src/chocolatey/infrastructure/commands/Execute.cs index a64640d15e..0e0455ee6a 100644 --- a/src/chocolatey/infrastructure/commands/Execute.cs +++ b/src/chocolatey/infrastructure/commands/Execute.cs @@ -16,6 +16,7 @@ namespace chocolatey.infrastructure.commands { using System; + using System.Threading; using System.Threading.Tasks; /// @@ -61,10 +62,15 @@ public T command(Func function, T timeoutDefaultValue) { if (function == null) return timeoutDefaultValue; - var task = Task.Factory.StartNew(function); + var cancelToken = new CancellationTokenSource(); + cancelToken.Token.ThrowIfCancellationRequested(); + var task = Task.Factory.StartNew(function, cancelToken.Token); //,TaskCreationOptions.LongRunning| TaskCreationOptions.AttachedToParent); + task.Wait(_timespan); - if (task.IsCompleted) return task.Result; + + cancelToken.Cancel(); + return timeoutDefaultValue; //T result = timeoutDefaultValue; diff --git a/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs b/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs index 38ce8c2d6e..6e6ee21814 100644 --- a/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs +++ b/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs @@ -84,7 +84,7 @@ public override void Write(ConsoleColor foregroundColor, ConsoleColor background public override void WriteLine() { - base.WriteLine(); + this.Log().Info(""); } public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value) @@ -118,14 +118,27 @@ public override void WriteDebugLine(string message) this.Log().Debug(message); } + private bool hasLoggedStartProgress = false; + private bool hasLoggedFinalProgress = false; public override void WriteProgress(long sourceId, ProgressRecord record) - { + { if (record.PercentComplete == -1) return; - - if (record.PercentComplete == 100) this.Log().Debug(() => "Progress: 100%{0}".format_with(" ".PadRight(20))); + if (hasLoggedFinalProgress) return; + if (!hasLoggedStartProgress) + { + hasLoggedStartProgress = true; + this.Log().Debug(record.Activity); + } // http://stackoverflow.com/a/888569/18475 - Console.Write("\rProgress: {0}%{1}".format_with(record.PercentComplete, " ".PadRight(20))); + Console.Write("\rProgress: {0}% - {1}".format_with(record.PercentComplete.to_string(), record.StatusDescription.PadRight(50, ' '))); + + if (record.PercentComplete == 100 && !hasLoggedFinalProgress) + { + hasLoggedFinalProgress = true; + //this.Log().Info(""); + //this.Log().Info(record.StatusDescription.Replace("Saving","Finished downloading. Saved")); + } } public override void WriteVerboseLine(string message)