setlocal
rem if gradlew.bat does not exist, load the project once in android studio

if not exist "deps\SDL-release-2.28.5\" (
	curl -L -o "SDL-release-2.28.5.zip" "https://github.com/libsdl-org/SDL/archive/refs/tags/release-2.28.5.zip"
	tar -xf "SDL-release-2.28.5.zip" -C "deps/"
	del "SDL-release-2.28.5.zip"
)

rem get the version number from src/version.h
SETLOCAL
SET "filename1=src/version.h"
SET "itemlist=VERSION_MAJOR VERSION_MINOR VERSION_PATCH"
FOR /f "usebackqtokens=1-3*" %%a IN ("%filename1%") DO (
 FOR %%i IN (%itemlist%) DO IF /i "%%b"=="%%i" SET "%%b=%%c"
)
SET "version=%VERSION_MAJOR%.%VERSION_MINOR%.%VERSION_PATCH%"

call android-sdl\gradlew.bat -b android-sdl/build.gradle assembleRelease

for %%f in (android-sdl\build\outputs\apk\release\*.apk) do (
    copy "%%f" shr3d-%version%-sdl.apk
)
