summaryrefslogtreecommitdiffhomepage
path: root/dist/update.bat
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2023-07-29 14:26:05 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2023-08-02 01:10:12 +0100
commitd337b09936ecd90bad07b28b48b7103395d97ce5 (patch)
tree12af039f74f5fdabef7971b6df7159934fdc11df /dist/update.bat
parenta64e4316a6d5b603df25a105468a94c951eaf27d (diff)
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.
Diffstat (limited to 'dist/update.bat')
-rw-r--r--dist/update.bat53
1 files changed, 53 insertions, 0 deletions
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