Skip to content

Commit

Permalink
Merge pull request 'fix and improve the update script' (#98) from waf…
Browse files Browse the repository at this point in the history
…fle.lord/Installer:fix/update-script into master

Reviewed-on: https://dev.sp-tarkov.com/SPT/Installer/pulls/98
  • Loading branch information
IsWaffle committed Jul 5, 2024
2 parents 6502dde + e751f93 commit 498eeaa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 17 additions & 6 deletions SPTInstaller/Resources/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

Clear-Host

Write-Host "Stopping installer ..."
Write-Host "Stopping installer ... " -ForegroundColor cyan -NoNewLine

$installer = Stop-Process -Name "SPTInstaller" -ErrorAction SilentlyContinue

if ($installer -ne $null)
{
Write-Host "Something went wrong, couldn't stop installer process'"
Write-Warning "Something went wrong, couldn't stop installer process'"
return;
}

Write-Host "OK" -ForegroundColor green

if (-not(Test-Path $source) -and -not(Test-Path $destination)) {
Write-Warning "Can't find a required file"
Write-host ""
Expand All @@ -23,7 +25,7 @@ if (-not(Test-Path $source) -and -not(Test-Path $destination)) {
exit
}

Write-Host "Copying new installer ..."
Write-Host "Copying new installer ... " -ForegroundColor cyan

$maxAttempts = 10
$copied = $false
Expand All @@ -32,7 +34,7 @@ while (-not $copied) {

$maxAttempts--

Write-Host "Please wait ..."
Write-Host " > Please wait ... " -NoNewLine

if ($maxAttempts -le 0) {
Write-Host "Couldn't copy new installer :( Please re-download the installer"
Expand All @@ -42,18 +44,27 @@ while (-not $copied) {
exit
}

Remove-Item $destination -ErrorAction SilentlyContinue
Copy-Item $source $destination -ErrorAction SilentlyContinue
try {
Remove-Item $destination -ErrorAction SilentlyContinue
Copy-Item $source $destination -ErrorAction SilentlyContinue
}
catch {
Write-Host "file locked, retrying ..." -ForegroundColor yellow
sleep(2)
continue
}

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
break
}

Write-Host "sizes differ, retrying ..." -ForegroundColor yellow
sleep(2)
}
}
Expand Down
4 changes: 2 additions & 2 deletions SPTInstaller/SPTInstaller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<PackageIcon>icon.ico</PackageIcon>
<ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon>
<Configurations>Debug;Release;TEST</Configurations>
<AssemblyVersion>2.84</AssemblyVersion>
<FileVersion>2.84</FileVersion>
<AssemblyVersion>2.85</AssemblyVersion>
<FileVersion>2.85</FileVersion>
<Company>SPT</Company>
</PropertyGroup>

Expand Down

0 comments on commit 498eeaa

Please sign in to comment.