From d337b09936ecd90bad07b28b48b7103395d97ce5 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 29 Jul 2023 14:26:05 +0100 Subject: Add the auto-update script from the website Basically for documentation purposes and to ensure it exists outside of my own server; this was a VERY write-only script and is already in fairly wide use so I don't expect to edit it very much. --- dist/update.bat | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 dist/update.bat diff --git a/dist/update.bat b/dist/update.bat new file mode 100644 index 0000000..5deb269 --- /dev/null +++ b/dist/update.bat @@ -0,0 +1,53 @@ +<# : This script file is dedicated to the public domain. SST itself is not. +:: Note: the control flow in this file is pretty wacky, and for that, I apologise. +@echo off +pushd "%~dp0" +powershell -WindowStyle hidden -NoProfile -NoLogo -ExecutionPolicy bypass "iex (${%~f0} | out-string)" +if exist .sst-update.zip ( + del .sst-update.zip + if exist sst-postupdate.bat ( + call sst-postupdate.bat + del sst-postupdate.bat + ) + :: if updated from game launch script, plugin can find out and display a message + set SST_UPDATED=1 +) +popd +goto :eof +#> +$ProgressPreference = "SilentlyContinue" +[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') >$null +$url = [IO.File]::ReadAllText("update-url").Trim() +$realurl = $url +$origurl = $url +$h = @{} +try { + $etag = [IO.File]::ReadAllText("update-version") + $h["If-None-Match"] = $etag +} +catch {} +function errorbox { + [System.Windows.Forms.MessageBox]::Show('Failed to check for SST updates. You may or may not be up to date!', 'Update error') >$null +} +for ($i = 0; $i -lt 10; $i++) { + $r = Invoke-WebRequest -UseBasicParsing -UserAgent "sstupdate v2" -Uri $url -OutFile ".sst-update.zip" -PassThru -Headers $h -MaximumRedirection 0 -ErrorAction SilentlyContinue + if ($r.StatusCode -eq 301) { + $url = $r.Headers.Location + $realurl = $url + continue + } + if ($r.StatusCode -eq 302) { # don't immediately save a Found. + $url = $r.Headers.Location + continue + } + if ($r.StatusCode -eq 200 -or $r.StatusCode -eq 304) { + if ($r.Headers.ETag) { [IO.File]::WriteAllText("update-version", $r.Headers.ETag) } + if ($realurl -ne $origurl) { [IO.File]::WriteAllText("update-url", $realurl) } + if ($r.StatusCode -eq 200) { Expand-Archive -Force -DestinationPath . .sst-update.zip } + else { del .sst-update.zip } # stupid but oh well + exit + } + errorbox + exit +} +errorbox # too many redirects -- cgit v1.2.3