@chcp 866

:CHECK1
@IF EXIST "game.aqsp" GOTO CHECK2
@ECHO.
@ECHO    Game file does not exist!
@ECHO    You need to place a file "game.aqsp" in this folder.
@ECHO.
@pause
@GOTO END

:CHECK2
@IF EXIST "background.png" GOTO CHECK3
@ECHO.
@ECHO    Background picture does not exist!
@ECHO    You need to place a file "background.png" in this folder.
@ECHO.
@pause
@GOTO END

:CHECK3
@7z\7za e game.aqsp config.xml
@IF EXIST "config.xml" GOTO CHECK4
@ECHO.
@ECHO    Game configuration file does not exist!
@ECHO    There must be an "config.xml" configuration file in game archive.
@ECHO.
@pause
@GOTO END

:CHECK4
::Get width and height from config.xml configuration file, 
::which is contained in .aqsp archive
@xmlstarlet\xml sel -t -m "game" -v "@width" config.xml > tmpextracted.txt
@SET /P width=<tmpextracted.txt
@xmlstarlet\xml sel -t -m "game" -v "@height" config.xml > tmpextracted.txt
@SET /P height=<tmpextracted.txt
@del /Q tmpextracted.txt
@del /Q config.xml

::Copy game file to be embedded
@copy /Y game.aqsp aero_src\standalone\game.aqsp

::Copy background picture to be embedded
@copy /Y background.png aero_src\standalone\background.png

::Ensure that AeroQSPConfig.xml is identical to AeroQSPConfig_smart.xml,
::if somebody changed it, we just ovewrite
@copy /Y aero_src\obj\AeroQSPConfig_smart.xml aero_src\obj\AeroQSPConfig.xml


::Compile final swf
flexsdk\bin\mxmlc +aero_width=%width% +aero_height=%height% +aero_source_dir="%cd%\aero_src" -load-config+=aero_src\obj\AeroQSPConfig.xml -incremental=true -benchmark=false -optimize=true -define+=CONFIG::standalone,true -define+=CONFIG::no_standalone,false -o AeroQSP_standalone.swf

::Clean garbage
@del /Q AeroQSP_standalone.swf.cache

:END