Refactor Update-Scripts function to improve error handling and code structure
This commit is contained in:
@@ -57,11 +57,12 @@ function Update-Scripts {
|
|||||||
Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray
|
Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray
|
||||||
return $false # Failed to download
|
return $false # Failed to download
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the download was successful (file exists and is not empty)
|
# Check if the download was successful (file exists and is not empty)
|
||||||
if (Test-Path $zipPath -and (Get-Item $zipPath).Length -gt 0) {
|
if (Test-Path $zipPath -and (Get-Item $zipPath).Length -gt 0) {
|
||||||
Write-Host "Download successful!" -ForegroundColor Green
|
Write-Host "Download successful!" -ForegroundColor Green
|
||||||
|
|
||||||
|
try {
|
||||||
# Extract the zip file
|
# Extract the zip file
|
||||||
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
||||||
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
||||||
@@ -115,6 +116,7 @@ function Update-Scripts {
|
|||||||
return $false # Update failed
|
return $false # Update failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Call the update function at the beginning
|
# Call the update function at the beginning
|
||||||
$scriptUpdated = Update-Scripts
|
$scriptUpdated = Update-Scripts
|
||||||
|
|||||||
@@ -57,11 +57,12 @@ function Update-Scripts {
|
|||||||
Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray
|
Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray
|
||||||
return $false # Failed to download
|
return $false # Failed to download
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the download was successful (file exists and is not empty)
|
# Check if the download was successful (file exists and is not empty)
|
||||||
if (Test-Path $zipPath -and (Get-Item $zipPath).Length -gt 0) {
|
if (Test-Path $zipPath -and (Get-Item $zipPath).Length -gt 0) {
|
||||||
Write-Host "Download successful!" -ForegroundColor Green
|
Write-Host "Download successful!" -ForegroundColor Green
|
||||||
|
|
||||||
|
try {
|
||||||
# Extract the zip file
|
# Extract the zip file
|
||||||
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
||||||
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
||||||
@@ -115,6 +116,7 @@ function Update-Scripts {
|
|||||||
return $false # Update failed
|
return $false # Update failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Call the update function at the beginning
|
# Call the update function at the beginning
|
||||||
$scriptUpdated = Update-Scripts
|
$scriptUpdated = Update-Scripts
|
||||||
|
|||||||
@@ -57,11 +57,12 @@ function Update-Scripts {
|
|||||||
Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray
|
Write-Host "Failed to download from URL: $_" -ForegroundColor DarkGray
|
||||||
return $false # Failed to download
|
return $false # Failed to download
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the download was successful (file exists and is not empty)
|
# Check if the download was successful (file exists and is not empty)
|
||||||
if (Test-Path $zipPath -and (Get-Item $zipPath).Length -gt 0) {
|
if (Test-Path $zipPath -and (Get-Item $zipPath).Length -gt 0) {
|
||||||
Write-Host "Download successful!" -ForegroundColor Green
|
Write-Host "Download successful!" -ForegroundColor Green
|
||||||
|
|
||||||
|
try {
|
||||||
# Extract the zip file
|
# Extract the zip file
|
||||||
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
Write-Host "Extracting update package..." -ForegroundColor Cyan
|
||||||
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
|
||||||
|
|||||||
Reference in New Issue
Block a user