do not exit entire script

This commit is contained in:
Calyx Hikari 2025-06-29 13:27:02 +08:00
parent 4ada8f2fde
commit a238ee84d2
4 changed files with 392 additions and 368 deletions

16
32
View file

@ -3,9 +3,10 @@
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Main {
if ($PSVersionTable.PSEdition -ne 'Desktop' -and $env:OS -ne 'Windows_NT') {
Write-Warning "Please run it on Windows. "
exit 1
return 1
}
$flagPath = "$env:TEMP\elevation_success.flag"
@ -23,11 +24,12 @@ if (-not $IsAdmin) {
Start-Sleep -Seconds 10
if (-Not (Test-Path $flagPath)) {
Write-Warning "User did not confirm UAC prompt or something went wrong."
exit 1
} else {
return 1
}
else {
Remove-Item $flagPath -ErrorAction SilentlyContinue
Write-Host "Setup ran successfully."
exit 0
return 0
}
}
@ -50,7 +52,8 @@ if (-not (Test-Path $aria2Exe)) {
$aria2Zip = Join-Path $tempDir "aria2.zip"
if ($countryCode -eq 'CN') {
$aria2Url = "https://gitee.com/HikariCalyx/OSTRemote/releases/download/v1.0/aria2-1.37.0-win-32bit-build1.zip"
} else {
}
else {
$aria2Url = "https://github.com/aria2/aria2/releases/download/release-1.37.0/aria2-1.37.0-win-32bit-build1.zip"
}
Invoke-WebRequest -Uri $aria2Url -OutFile $aria2Zip
@ -104,3 +107,6 @@ Write-Host "Cleaning up temporary files..."
Start-Sleep -Seconds 2
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path $flagPath -Force -ErrorAction SilentlyContinue
}
Main

16
64
View file

@ -3,9 +3,10 @@
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Main {
if ($PSVersionTable.PSEdition -ne 'Desktop' -and $env:OS -ne 'Windows_NT') {
Write-Warning "Please run it on Windows. "
exit 1
return 1
}
$flagPath = "$env:TEMP\elevation_success.flag"
@ -23,11 +24,12 @@ if (-not $IsAdmin) {
Start-Sleep -Seconds 10
if (-Not (Test-Path $flagPath)) {
Write-Warning "User did not confirm UAC prompt or something went wrong."
exit 1
} else {
return 1
}
else {
Remove-Item $flagPath -ErrorAction SilentlyContinue
Write-Host "Setup ran successfully."
exit 0
return 0
}
}
@ -50,7 +52,8 @@ if (-not (Test-Path $aria2Exe)) {
$aria2Zip = Join-Path $tempDir "aria2.zip"
if ($countryCode -eq 'CN') {
$aria2Url = "https://gitee.com/HikariCalyx/OSTRemote/releases/download/v1.0/aria2-1.37.0-win-64bit-build1.zip"
} else {
}
else {
$aria2Url = "https://github.com/aria2/aria2/releases/download/release-1.37.0/aria2-1.37.0-win-64bit-build1.zip"
}
Invoke-WebRequest -Uri $aria2Url -OutFile $aria2Zip
@ -104,3 +107,6 @@ Write-Host "Cleaning up temporary files..."
Start-Sleep -Seconds 2
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path $flagPath -Force -ErrorAction SilentlyContinue
}
Main

16
dx
View file

@ -3,9 +3,10 @@
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Main {
if ($PSVersionTable.PSEdition -ne 'Desktop' -and $env:OS -ne 'Windows_NT') {
Write-Warning "Please run it on Windows. "
exit 1
return 1
}
$flagPath = "$env:TEMP\elevation_success.flag"
@ -23,11 +24,12 @@ if (-not $IsAdmin) {
Start-Sleep -Seconds 10
if (-Not (Test-Path $flagPath)) {
Write-Warning "User did not confirm UAC prompt or something went wrong."
exit 1
} else {
return 1
}
else {
Remove-Item $flagPath -ErrorAction SilentlyContinue
Write-Host "Setup ran successfully."
exit 0
return 0
}
}
@ -50,7 +52,8 @@ if (-not (Test-Path $aria2Exe)) {
$aria2Zip = Join-Path $tempDir "aria2.zip"
if ($countryCode -eq 'CN') {
$aria2Url = "https://gitee.com/HikariCalyx/OSTRemote/releases/download/v1.0/aria2-1.37.0-win-32bit-build1.zip"
} else {
}
else {
$aria2Url = "https://github.com/aria2/aria2/releases/download/release-1.37.0/aria2-1.37.0-win-32bit-build1.zip"
}
Invoke-WebRequest -Uri $aria2Url -OutFile $aria2Zip
@ -90,3 +93,6 @@ Write-Host "Cleaning up temporary files..."
Start-Sleep -Seconds 2
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path $flagPath -Force -ErrorAction SilentlyContinue
}
Main

View file

@ -3,9 +3,10 @@
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Main {
if ($PSVersionTable.PSEdition -ne 'Desktop' -and $env:OS -ne 'Windows_NT') {
Write-Warning "Please run it on Windows. "
exit 1
return 1
}
$flagPath = "$env:TEMP\elevation_success.flag"
@ -23,11 +24,12 @@ if (-not $IsAdmin) {
Start-Sleep -Seconds 10
if (-Not (Test-Path $flagPath)) {
Write-Warning "User did not confirm UAC prompt or something went wrong."
exit 1
} else {
return 1
}
else {
Remove-Item $flagPath -ErrorAction SilentlyContinue
Write-Host "Setup ran successfully."
exit 0
return 0
}
}
@ -50,7 +52,8 @@ if (-not (Test-Path $aria2Exe)) {
$aria2Zip = Join-Path $tempDir "aria2.zip"
if ($countryCode -eq 'CN') {
$aria2Url = "https://gitee.com/HikariCalyx/OSTRemote/releases/download/v1.0/aria2-1.37.0-win-64bit-build1.zip"
} else {
}
else {
$aria2Url = "https://github.com/aria2/aria2/releases/download/release-1.37.0/aria2-1.37.0-win-64bit-build1.zip"
}
Invoke-WebRequest -Uri $aria2Url -OutFile $aria2Zip
@ -110,3 +113,6 @@ Write-Host "Cleaning up temporary files..."
Start-Sleep -Seconds 2
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path $flagPath -Force -ErrorAction SilentlyContinue
}
Main