From e109f13dba37e733096a522eb855a3fd691f6c7b Mon Sep 17 00:00:00 2001 From: Ahrimdon Date: Tue, 19 Nov 2024 16:59:53 -0500 Subject: [PATCH] maint(one-liner.ps1) improve compatibility with Invoke-WebRequest & better error handling --- installer/one-liner.ps1 | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/installer/one-liner.ps1 b/installer/one-liner.ps1 index 176feccb..4a88d3de 100644 --- a/installer/one-liner.ps1 +++ b/installer/one-liner.ps1 @@ -1,6 +1,27 @@ +# Define URL and dynamically extract filename from URL $url = "https://git.rimmyscorner.com/Rim/iw7-mod/releases/download/latest/iw7Installer.exe" -$file = "iw7Installer.exe" +$file = Split-Path -Path $url -Leaf -(New-Object System.Net.WebClient).DownloadFile($url, $file) -Start-Process -Wait $file -ArgumentList "-s" -Remove-Item $file +# Check if file already exists and delete if necessary +if (Test-Path -Path $file) { + Write-Host "Removing existing file: $file" + Remove-Item -Path $file -Force +} + +# Download the file using Invoke-WebRequest for better cross-platform compatibility +try { + Invoke-WebRequest -Uri $url -OutFile $file -ErrorAction Stop +} catch { + Write-Error "Download failed: $_" + exit 1 +} + +# Start the installer with arguments, wait for it to complete +try { + Start-Process -FilePath $file -ArgumentList "-s" -Wait +} catch { + Write-Error "Installation failed: $_" +} + +# Clean up downloaded file +Remove-Item -Path $file -Force