diff --git a/SPTInstaller/Resources/update.ps1 b/SPTInstaller/Resources/update.ps1 index 77fd0cb..a93e30d 100644 --- a/SPTInstaller/Resources/update.ps1 +++ b/SPTInstaller/Resources/update.ps1 @@ -15,13 +15,48 @@ if ($installer -ne $null) return; } +if (-not(Test-Path $source) -and -not(Test-Path $destination)) { + Write-Warning "Can't find a required file" + Write-host "" + Write-Host "Press [enter] to close ..." + Read-Host + exit +} + Write-Host "Copying new installer ..." -Import-Module BitsTransfer +$maxAttempts = 10 +$copied = $false -Start-BitsTransfer -Source $source -Destination $destination +while (-not $copied) { -Remove-Module BitsTransfer + $maxAttempts-- + + Write-Host "Please wait ..." + + if ($maxAttempts -le 0) { + Write-Host "Couldn't copy new installer :( Please re-download the installer" + Write-Host "" + Write-Host "Press [enter] to close ..." + Read-Host + exit + } + + Remove-Item $destination -ErrorAction SilentlyContinue + Copy-Item $source $destination + + if (Test-Path $destination) { + $sLength = (Get-Item $source).Length + $dLength = (Get-Item $destination).Length + + if ($sLength -eq $dLength) { + $copied = $true + break + } + + sleep(2) + } +} # remove the new installer from the cache folder after it is copied Remove-Item -Path $source