@ECHO OFF
SET INPUTFILE=?INPUTFILE?
SET TECHFILE=?TECHFILE?
SET TARGETDIR=?TARGETDIR?
SET XZEXEC=xzdec.exe
SET XZOPT=-d
SET BINDIR=win32
SET GDS3DEXEC=GDS3D.exe
SET BINDIR=%TARGETDIR%%BINDIR%
SET TECHFILE=%TARGETDIR%%TECHFILE%
SET XZDIR=
SET GDSFILE=%INPUTFILE%

REM Check file extension if we need to uncompress first
FOR %%i IN ("%INPUTFILE%") DO SET FILENAME="%%~ni" & SET FILEEXT="%%~xi"
SET FILENAME=%FILENAME: =%
IF NOT %FILEEXT% == ".xz" GOTO LAUNCH

REM Uncompress first
SET GDSFILE="%TEMP%/%FILENAME%.gds"
IF EXIST %BINDIR%\%XZEXEC% SET XZDIR=%BINDIR%\
ECHO Uncompressing %INPUTFILE% to %GDSFILE% using %XZDIR%%XZEXEC%
%XZDIR%%XZEXEC% %XZOPT% %INPUTFILE% > %GDSFILE%

:LAUNCH
%BINDIR%\%GDS3DEXEC% -p %TECHFILE% -i %GDSFILE%
