77 lines
1.8 KiB
PowerShell
Raw Normal View History

2023-07-30 16:15:52 -04:00
param(
[string]$source,
[string]$destination
)
Clear-Host
2023-07-30 16:15:52 -04:00
Write-Host "Stopping installer ... " -ForegroundColor cyan -NoNewLine
2023-07-30 16:15:52 -04:00
$installer = Stop-Process -Name "SPTInstaller" -ErrorAction SilentlyContinue
2024-05-01 10:31:55 -04:00
if ($installer -ne $null)
{
Write-Warning "Something went wrong, couldn't stop installer process'"
2023-07-30 16:15:52 -04:00
return;
}
Write-Host "OK" -ForegroundColor green
2024-05-04 17:57:59 -04:00
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 ... " -ForegroundColor cyan
2023-07-30 16:15:52 -04:00
2024-05-04 17:57:59 -04:00
$maxAttempts = 10
$copied = $false
2024-05-04 17:57:59 -04:00
while (-not $copied) {
2024-05-04 17:57:59 -04:00
$maxAttempts--
Write-Host " > Please wait ... " -NoNewLine
2024-05-04 17:57:59 -04:00
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
}
try {
Remove-Item $destination -ErrorAction SilentlyContinue
Copy-Item $source $destination -ErrorAction SilentlyContinue
}
catch {
Write-Host "file locked, retrying ..." -ForegroundColor yellow
sleep(2)
continue
}
2024-05-04 17:57:59 -04:00
if (Test-Path $destination) {
$sLength = (Get-Item $source).Length
$dLength = (Get-Item $destination).Length
if ($sLength -eq $dLength) {
$copied = $true
Write-Host "OK" -ForegroundColor green
2024-05-04 17:57:59 -04:00
break
}
Write-Host "sizes differ, retrying ..." -ForegroundColor yellow
2024-05-04 17:57:59 -04:00
sleep(2)
}
}
2023-07-30 16:15:52 -04:00
# remove the new installer from the cache folder after it is copied
Remove-Item -Path $source
2023-07-30 16:15:52 -04:00
Start-Process $destination
Write-Host "Done"