Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ function Expand-MsiArchive {
$Removal
)
$DestinationPath = $DestinationPath.TrimEnd("\")
if ($ExtractDir) {
$OriDestinationPath = $DestinationPath
$DestinationPath = "$DestinationPath\_tmp"
}
if ((get_config MSIEXTRACT_USE_LESSMSI)) {
$MsiPath = Get-HelperPath -Helper Lessmsi
$ArgList = @('x', "`"$Path`"", "`"$DestinationPath\\`"")
Expand All @@ -138,11 +142,11 @@ function Expand-MsiArchive {
abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogPath)`n$(new_issue_msg $app $bucket 'decompress error')"
}
if ($ExtractDir -and (Test-Path "$DestinationPath\SourceDir")) {
movedir "$DestinationPath\SourceDir\$ExtractDir" $DestinationPath | Out-Null
Remove-Item "$DestinationPath\SourceDir" -Recurse -Force
movedir "$DestinationPath\SourceDir\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
} elseif ($ExtractDir) {
Get-ChildItem $DestinationPath -Exclude $ExtractDir, $Path | Remove-Item -Recurse -Force
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
movedir "$DestinationPath\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
} elseif (Test-Path "$DestinationPath\SourceDir") {
movedir "$DestinationPath\SourceDir" $DestinationPath | Out-Null
}
Expand Down Expand Up @@ -207,6 +211,10 @@ function Expand-ZipArchive {
[Switch]
$Removal
)
if ($ExtractDir) {
$OriDestinationPath = $DestinationPath
$DestinationPath = "$DestinationPath\_tmp"
}
# All methods to unzip the file require .NET4.5+
if ($PSVersionTable.PSVersion.Major -lt 5) {
Add-Type -AssemblyName System.IO.Compression.FileSystem
Expand Down Expand Up @@ -236,8 +244,8 @@ function Expand-ZipArchive {
Microsoft.PowerShell.Archive\Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
}
if ($ExtractDir) {
Get-ChildItem $DestinationPath -Exclude $ExtractDir, $Path | Remove-Item -Recurse -Force
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
movedir "$DestinationPath\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
}
if ($Removal) {
# Remove original archive file
Expand All @@ -254,15 +262,12 @@ function Expand-DarkArchive {
[Parameter(Position = 1)]
[String]
$DestinationPath = (Split-Path $Path),
[String]
$ExtractDir,
[Parameter(ValueFromRemainingArguments = $true)]
[String]
$Switches,
[Switch]
$Removal
)
$DestinationPath = $DestinationPath.TrimEnd("\")
$LogPath = "$(Split-Path $Path)\dark.log"
$ArgList = @('-nologo', "-x `"$DestinationPath`"", "`"$Path`"")
if ($Switches) {
Expand All @@ -275,10 +280,6 @@ function Expand-DarkArchive {
if (Test-Path $LogPath) {
Remove-Item $LogPath -Force
}
if ($ExtractDir) {
Get-ChildItem $DestinationPath -Exclude $ExtractDir, $Path | Remove-Item -Recurse -Force
movedir "$DestinationPath\$ExtractDir" $DestinationPath | Out-Null
}
if ($Removal) {
# Remove original archive file
Remove-Item $Path -Force
Expand Down