Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-702) Fully qualify shutdown.exe
  (maint) Suggest ignore checksum switch on error
  (GH-435) Get-FileName enhancements
  (maint) ignore .vscode folder
  (GH-535) install template information
  (GH-696) Approved/Failing statuses on install
  (maint) Provide better warning on non-admin prompt
  • Loading branch information
ferventcoder committed Apr 22, 2016
2 parents 8897359 + 39d1723 commit 95fcd53
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ code_drop
[Bb]in
obj
src/packages

/.vscode/

*.suo
*.sln.docstates
*.user
*.user
*.csproj.user
*.[rR]esharper.user
*.DotSettings.user
Expand All @@ -24,7 +24,7 @@ _ReSharper*
*.pidb
*userprefs
*.nupkg

TestResult.xml
submit.xml
SolutionVersion.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ param(
Write-Debug "Command [`'$checksumExe`' $params] exited with `'$exitCode`'."

if ($exitCode -ne 0) {
throw "Checksum for `'$file'` did not meet `'$checksum`' for checksum type `'$checksumType`'."
throw "Checksum for '$file' did not meet '$checksum' for checksum type '$checksumType'. Consider passing --ignore-checksums if necessary."
}

#$fileCheckSumActual = $md5Output.Split(' ')[0]
Expand Down
25 changes: 18 additions & 7 deletions src/chocolatey.resources/helpers/functions/Get-FileName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ param(
$originalFileName = $defaultName
$fileName = $null

if ($url -eq $null -or $url -eq '') {
Write-Debug "Url was null, using default name."
return $originalFileName
}

$request = [System.Net.HttpWebRequest]::Create($url)
if ($request -eq $null) {
$request.Close()
return $originalFileName
Write-Debug "Request was null, using default name."
return $originalFileName
}

$defaultCreds = [System.Net.CredentialCache]::DefaultCredentials
Expand Down Expand Up @@ -86,9 +92,10 @@ param(
try
{
[System.Net.HttpWebResponse]$response = $request.GetResponse()
if ($response -eq $null) {
$response.Close()
return $originalFileName
if ($response -eq $null) {
$response.Close()
Write-Debug "Response was null, using default name."
return $originalFileName
}

[string]$header = $response.Headers['Content-Disposition']
Expand All @@ -99,31 +106,35 @@ param(
$fileHeaderName = 'filename='
$index = $header.LastIndexOf($fileHeaderName, [StringComparison]::OrdinalIgnoreCase)
if ($index -gt -1) {
Write-Debug "Using header 'Content-Disposition' to determine file name."
$fileName = $header.Substring($index + $fileHeaderName.Length).Replace('"', '')
}
}

# If empty, check location header next
if ($fileName -eq $null -or $fileName -eq '') {
if ($headerLocation -ne '') {
Write-Debug "Using header 'Location' to determine file name."
$fileName = [System.IO.Path]::GetFileName($headerLocation)
}
}

# Next comes using the response url value
if ($fileName -eq $null -or $fileName -eq '') {
Write-Debug "Using response url to determine file name."
$containsQuery = [System.IO.Path]::GetFileName($url).Contains('?')
$containsEquals = [System.IO.Path]::GetFileName($url).Contains('=')
$fileName = [System.IO.Path]::GetFileName($response.ResponseUri.ToString())
}

$response.Close()
$response.Dispose()
[System.Text.RegularExpressions.Regex]$containsABadCharacter = New-Object Regex("[" + [System.Text.RegularExpressions.Regex]::Escape([System.IO.Path]::GetInvalidFileNameChars()) + "]");

[System.Text.RegularExpressions.Regex]$containsABadCharacter = New-Object Regex("[" + [System.Text.RegularExpressions.Regex]::Escape([System.IO.Path]::GetInvalidFileNameChars()) + "]", [System.Text.RegularExpressions.RegexOptions]::IgnorePatternWhitespace);

# when all else fails, default the name
if ($fileName -eq $null -or $fileName -eq '' -or $containsABadCharacter.IsMatch($fileName)) {
Write-Debug "File name is null or illegal. Using $originalFileName instead."
$fileName = $originalFileName
}

Expand Down
10 changes: 8 additions & 2 deletions src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,17 @@ public static IPackageManager GetPackageManager(ChocolateyConfiguration configur
}

//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}".format_with(Environment.NewLine, pkg.Id, pkg.Version.to_string(), configuration.Force ? " (forced)" : string.Empty));
"chocolatey".Log().Info(ChocolateyLoggers.Important, "{0}{1} v{2}{3}{4}{5}".format_with(
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
));

if (installSuccessAction != null) installSuccessAction.Invoke(e);
};
Expand Down
5 changes: 3 additions & 2 deletions src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ public void warn_when_admin_needs_elevation(ChocolateyConfiguration config)

if (shouldWarn)
{
var selection = InteractivePrompt.prompt_for_confirmation(@"
this.Log().Warn(ChocolateyLoggers.Important, @"
You may experience errors - many functions/packages
require admin rights. Only advanced users should run choco w/out an
elevated shell. When you open the command shell, you should ensure
that you do so with ""Run as Administrator"" selected.
");
var selection = InteractivePrompt.prompt_for_confirmation(@"
Do you want to continue?", new[] { "yes", "no" },
defaultChoice: null,
requireAnswer: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ChocolateyPackageService : IChocolateyPackageService
private readonly IXmlService _xmlService;
private readonly IConfigTransformService _configTransformService;

private readonly string _shutdownExe = Environment.ExpandEnvironmentVariables("%systemroot%\\System32\\shutdown.exe");

public ChocolateyPackageService(INugetService nugetService, IPowershellService powershellService,
IEnumerable<ISourceRunner> sourceRunners, IShimGenerationService shimgenService,
IFileSystem fileSystem, IRegistryService registryService,
Expand Down Expand Up @@ -259,7 +261,7 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu
if (powerShellRan)
{
// we don't care about the exit code
if (config.Information.PlatformType == PlatformType.Windows) CommandExecutor.execute_static("shutdown", "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false);
if (config.Information.PlatformType == PlatformType.Windows) CommandExecutor.execute_static(_shutdownExe, "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false);
}

var installersDifferences = _registryService.get_installer_key_differences(installersBefore, _registryService.get_installer_keys());
Expand Down Expand Up @@ -689,7 +691,7 @@ public void handle_package_uninstall(PackageResult packageResult, ChocolateyConf
}

// we don't care about the exit code
if (config.Information.PlatformType == PlatformType.Windows) CommandExecutor.execute_static("shutdown", "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false);
if (config.Information.PlatformType == PlatformType.Windows) CommandExecutor.execute_static(_shutdownExe, "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false);

if (packageResult.Success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ChocolateyInstallTemplate
$packageName= '[[PackageName]]' # arbitrary name for the package, used in messages
$toolsDir = ""$(Split-Path -parent $MyInvocation.MyCommand.Definition)""
$url = '[[Url]]' # download url
$url64 = '[[Url64]]' # 64bit URL here or remove - if installer is both, use $url
$url64 = '[[Url64]]' # 64bit URL here or remove - if installer contains both (very rare), use $url
#$fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE'
#$fileLocation = '\\SHARE_LOCATION\to\INSTALLER_FILE'
Expand Down Expand Up @@ -61,7 +61,7 @@ public class ChocolateyInstallTemplate
# optional, highly recommended
softwareName = '[[PackageName]]*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique
checksum = '[[Checksum]]'
checksumType = '[[ChecksumType]]' #default is md5, can also be sha1
checksumType = '[[ChecksumType]]' #default is md5, can also be sha1, sha256 or sha512
checksum64 = '[[Checksum64]]'
checksumType64= '[[ChecksumType64]]' #default is checksumType
}
Expand Down

0 comments on commit 95fcd53

Please sign in to comment.