SDL_image: Add powershell script to fetch SDL2 VC SDK

From 5c5994f181ec08057e5ed3b3916af432f0ccba99 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 25 May 2022 18:02:56 +0200
Subject: [PATCH] Add powershell script to fetch SDL2 VC SDK

---
 .github/fetch_sdl_vc.ps1 | 40 ++++++++++++++++++++++++++++++++++++++++
 test-versioning.sh       |  8 ++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 .github/fetch_sdl_vc.ps1

diff --git a/.github/fetch_sdl_vc.ps1 b/.github/fetch_sdl_vc.ps1
new file mode 100644
index 00000000..2e3cc7c6
--- /dev/null
+++ b/.github/fetch_sdl_vc.ps1
@@ -0,0 +1,40 @@
+$ErrorActionPreference = "Stop"
+
+$project_root = "$psScriptRoot\.."
+Write-Output "project_root: $project_root"
+
+$sdl2_version = "2.0.9"
+$sdl2_zip = "SDL2-devel-$($sdl2_version)-VC.zip"
+
+$sdl2_url = "https://github.com/libsdl-org/SDL/releases/download/release-$($sdl2_version)/SDL2-devel-$($sdl2_version)-VC.zip"
+$sdl2_dlpath = "$($Env:TEMP)\$sdl2_zip"
+
+$sdl2_bindir = "$($project_root)"
+$sdl2_extractdir = "$($sdl2_bindir)\SDL2-$($sdl2_version)"
+$sdl2_root_name = "SDL2-devel-VC"
+
+echo "sdl2_bindir:     $sdl2_bindir"
+echo "sdl2_extractdir: $sdl2_extractdir"
+echo "sdl2_root_name:  $sdl2_root_name"
+
+echo "Cleaning previous artifacts"
+if (Test-Path $sdl2_extractdir) {
+    Remove-Item $sdl2_extractdir -Recurse -Force
+}
+if (Test-Path "$($sdl2_bindir)/$sdl2_root_name") {
+    Remove-Item "$($sdl2_bindir)/$sdl2_root_name" -Recurse -Force
+}
+if (Test-Path $sdl2_dlpath) {
+    Remove-Item $sdl2_dlpath -Force
+}
+
+Write-Output "Downloading $sdl2_url"
+Invoke-WebRequest -Uri $sdl2_url -OutFile $sdl2_dlpath
+
+Write-Output "Extracting archive"
+Expand-Archive $sdl2_dlpath -DestinationPath $sdl2_bindir
+
+Write-Output "Setting up SDL2 folder"
+Rename-Item $sdl2_extractdir $sdl2_root_name
+
+Write-Output "Done"
diff --git a/test-versioning.sh b/test-versioning.sh
index 50df720a..d3f2f9d6 100755
--- a/test-versioning.sh
+++ b/test-versioning.sh
@@ -157,5 +157,13 @@ else
     not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent"
 fi
 
+sdl_req=$(sed -ne 's/\$sdl2_version = "\([0-9.]\+\)"$/\1/p' .github/fetch_sdl_vc.ps1)
+
+if [ "$ref_sdl_req" = "$sdl_req" ]; then
+    ok ".github/fetch_sdl_vc.ps1 $sdl_req"
+else
+    not_ok ".github/fetch_sdl_vc.ps1 sdl2_version=$sdl_req disagrees with configure.ac SDL_VERSION=$ref_sdl_req"
+fi
+
 echo "1..$tests"
 exit "$failed"