Skip to content

Commit

Permalink
(GH-775) Use 7z instead of 7za
Browse files Browse the repository at this point in the history
Use the full blown 7z.exe to unzip, so there are no
limitations with unzipping archives.
  • Loading branch information
ferventcoder committed Jun 22, 2016
1 parent c3b427c commit 1ae9c38
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/chocolatey.resources/chocolatey.resources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
<ItemGroup>
<EmbeddedResource Include="helpers\functions\Get-UninstallRegistryKey.ps1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="tools\7z.dll" />
<EmbeddedResource Include="tools\7z.exe" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="tools\7z.exe.ignore" />
<EmbeddedResource Include="tools\7z.exe.manifest" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $extensionsPath = Join-Path $nugetPath 'extensions'
$chocInstallVariableName = "ChocolateyInstall"
$chocoTools = Join-Path $nuGetPath 'tools'
$nugetExe = Join-Path $chocoTools 'nuget.exe'
$7zip = Join-Path $chocoTools '7za.exe'
$7zip = Join-Path $chocoTools '7z.exe'
$ShimGen = Join-Path $chocoTools 'shimgen.exe'
$checksumExe = Join-Path $chocoTools 'checksum.exe'

Expand Down
25 changes: 14 additions & 11 deletions src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ function Get-ChocolateyUnzip {
Unzips an archive file and returns the location for further processing.
.DESCRIPTION
This unzips files using the 7-zip standalone command line tool 7za.exe.
Supported archive formats are: 7z, lzma, cab, zip, gzip, bzip2, and tar.
This unzips files using the 7-zip command line tool 7z.exe.
Supported archive formats are listed at:
https://sevenzip.osdn.jp/chm/general/formats.htm
Prior to 0.9.10.1, 7za.exe was used. Supported archive formats for
7za.exe are: 7z, lzma, cab, zip, gzip, bzip2, and tar.
.INPUTS
None
Expand Down Expand Up @@ -98,15 +101,15 @@ param(
Write-Host "Extracting $fileFullPath to $destination..."
if (![System.IO.Directory]::Exists($destination)) {[System.IO.Directory]::CreateDirectory($destination)}

$7zip = Join-Path "$helpersPath" '..\tools\7za.exe'
$7zip = Join-Path "$helpersPath" '..\tools\7z.exe'
if (!([System.IO.File]::Exists($7zip))) {
Update-SessionEnvironment
$7zip = Join-Path "$env:ChocolateyInstall" 'tools\7za.exe'
$7zip = Join-Path "$env:ChocolateyInstall" 'tools\7z.exe'
}
$7zip = [System.IO.Path]::GetFullPath($7zip)
Write-Debug "7zip found at `'$7zip`'"

# 32-bit 7za.exe would not find C:\Windows\System32\config\systemprofile\AppData\Local\Temp,
# 32-bit 7z.exe would not find C:\Windows\System32\config\systemprofile\AppData\Local\Temp,
# because it gets translated to C:\Windows\SysWOW64\... by the WOW redirection layer.
# Replace System32 with sysnative, which does not get redirected.
if ([IntPtr]::Size -ne 4) {
Expand All @@ -117,7 +120,7 @@ param(
$destination32 = $destination
}

$params = "x -aoa -o`"$destination`" -y `"$fileFullPath`""
$params = "x -aoa -bd -bb1 -o`"$destination`" -y `"$fileFullPath`""
Write-Debug "Executing command ['$7zip' $params]"

# Capture 7z's output into a StringBuilder and write it out in blocks, to improve I/O performance.
Expand All @@ -129,8 +132,8 @@ param(
if ($EventArgs.Data -ne $null) {
$line = $EventArgs.Data
Write-Verbose "$line"
if ($line.StartsWith("Extracting")) {
$global:zipFileList.AppendLine($global:zipDestinationFolder + "\" + $line.Substring(12))
if ($line.StartsWith("- ")) {
$global:zipFileList.AppendLine($global:zipDestinationFolder + "\" + $line.Substring(2))
}
}
}
Expand All @@ -143,7 +146,7 @@ param(

$process = New-Object System.Diagnostics.Process
$process.EnableRaisingEvents = $true
Register-ObjectEvent -InputObject $process -SourceIdentifier "LogOutput_ChocolateyZipProc" -EventName OutputDataReceived -Action $writeOutput | Out-Null
Register-ObjectEvent -InputObject $process -SourceIdentifier "LogOutput_ChocolateyZipProc" -EventName OutputDataReceived -Action $writeOutput | Out-Null
Register-ObjectEvent -InputObject $process -SourceIdentifier "LogErrors_ChocolateyZipProc" -EventName ErrorDataReceived -Action $writeError | Out-Null

$process.StartInfo = new-object System.Diagnostics.ProcessStartInfo($7zip, $params)
Expand All @@ -153,7 +156,7 @@ param(
$process.StartInfo.WorkingDirectory = Get-Location
$process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden

[void] $process.Start()
$process.Start() | Out-Null
if ($process.StartInfo.RedirectStandardOutput) { $process.BeginOutputReadLine() }
if ($process.StartInfo.RedirectStandardError) { $process.BeginErrorReadLine() }
$process.WaitForExit()
Expand All @@ -172,7 +175,7 @@ param(
Set-Content $zipExtractLogFullPath $global:zipFileList.ToString() -Encoding UTF8 -Force
}

Write-Debug "7za exit code: $exitCode"
Write-Debug "7z exit code: $exitCode"
switch ($exitCode) {
0 { break }
1 { throw 'Some files could not be extracted' } # this one is returned e.g. for access denied errors
Expand Down
Binary file added src/chocolatey.resources/tools/7z.dll
Binary file not shown.
Binary file added src/chocolatey.resources/tools/7z.exe
Binary file not shown.
Empty file.
11 changes: 11 additions & 0 deletions src/chocolatey.resources/tools/7z.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="7z" processorArchitecture="*" type="win32" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public string scan_file(string filePath)
private void unzip_die_files(string zipPath, string extractDirectory)
{
//todo: replace with https://github.com/adamhathcock/sharpcompress
var sevenZip = _fileSystem.combine_paths(ApplicationParameters.InstallLocation, "tools", "7za.exe");
var sevenZip = _fileSystem.combine_paths(ApplicationParameters.InstallLocation, "tools", "7z.exe");
CommandExecutor.execute_static(sevenZip, "x -aoa -o\"{0}\" -y \"{1}\"".format_with(extractDirectory, zipPath), 30, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false, false);
}
}
Expand Down

0 comments on commit 1ae9c38

Please sign in to comment.