mirror of
https://github.com/cmderdev/cmder.git
synced 2025-06-14 21:57:52 +08:00
Error checking for 7z extraction
This commit is contained in:
@ -69,6 +69,14 @@ function Flatten-Directory ($name) {
|
||||
Remove-Item -Recurse "$($name)_moving"
|
||||
}
|
||||
|
||||
function Extract-Archive ($source, $target) {
|
||||
Invoke-Expression "7z x -y -o$($target) $source"
|
||||
if ($lastexitcode -ne 0) {
|
||||
Write-Error "Extracting of $source failied"
|
||||
}
|
||||
Remove-Item $source
|
||||
}
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Check for requirements
|
||||
@ -87,8 +95,7 @@ foreach ($s in $sources) {
|
||||
Delete-Existing $s.name
|
||||
|
||||
Invoke-WebRequest -Uri $s.url -OutFile $tempArchive -ErrorAction Stop
|
||||
Invoke-Expression "7z x -y -o$($s.name) $tempArchive"
|
||||
Remove-Item $tempArchive
|
||||
Extract-Archive $tempArchive $s.name
|
||||
|
||||
if ((Get-Childitem $s.name).Count -eq 1) {
|
||||
Flatten-Directory($s.name)
|
||||
|
Reference in New Issue
Block a user