@echo off
rem *** Author: T. Wittrock, RZ Uni Kiel ***

verify other 2>nul
setlocal enableextensions
if errorlevel 1 goto NoExtensions

%~d0
cd "%~p0"

if /i "%3"=="/outputpath" (
  if %4~==~ (goto NoOutPath) else (set OUTPUT_PATH=%~fs4)
)
for %%i in (enu deu nld esn fra ptg ptb ita rus plk ell csy dan nor sve fin) do (if /i "%2"=="%%i" goto Valid2)
if /i "%2"=="/outputpath" (
  if %3~==~ (goto NoOutPath) else (set OUTPUT_PATH=%~fs3)
  set CREATE_DVD=1
  goto Empty2
) else (
  if %2~==~ (
    set CREATE_DVD=1
    goto Empty2
  ) else (
    goto InValid2
  )
)
:Empty2
for %%i in (all enu deu nld esn fra ptg ptb ita rus plk ell csy dan nor sve fin) do (if /i "%1"=="%%i" goto Valid1)
:Valid2
for %%i in (w2k w2k3 wxp) do (if /i "%1"=="%%i" goto Valid1)
goto InValid1

:Valid1
if not exist ..\bin\mkisofs.exe goto NoMkIsoFs
if %OUTPUT_PATH%~==~ set OUTPUT_PATH=..\iso

rem *** Create ISO image ***
if "%CREATE_DVD%"=="1" goto DVD
title Creating ISO image for %1 %2...
echo Creating ISO image for %1 %2...
if exist %OUTPUT_PATH%\wsusoffline-%1-%2.iso del %OUTPUT_PATH%\wsusoffline-%1-%2.iso
..\bin\mkisofs.exe -iso-level 4 -joliet -joliet-long -rational-rock -exclude-list ..\exclude\exclude-list-iso-%1-%2.txt -output %OUTPUT_PATH%\wsusoffline-%1-%2.iso -volid ctou_%1_%2 ..\client
if errorlevel 1 goto MkIsoError
goto EoF

:DVD
title Creating ISO image for %1...
echo Creating ISO image for %1...
if exist %OUTPUT_PATH%\wsusoffline-%1.iso del %OUTPUT_PATH%\wsusoffline-%1.iso
..\bin\mkisofs.exe -iso-level 4 -joliet -joliet-long -rational-rock -exclude-list ..\exclude\exclude-list-iso-%1.txt -output %OUTPUT_PATH%\wsusoffline-%1.iso -volid ctou_%1 ..\client
if errorlevel 1 goto MkIsoError
goto EoF

:NoExtensions
echo.
echo ERROR: No command extensions available.
echo.
goto Error

:NoOutPath
echo.
echo ERROR: Missing parameter outputpath
goto Usage

:InValid1
echo.
echo ERROR: Invalid parameter #1: %1
goto Usage

:InValid2
echo.
echo ERROR: Invalid parameter #2: %2
goto Usage

:Usage
echo Usage1: %~n0 {w2k ^| w2k3 ^| wxp} {enu ^| deu ^| nld ^| esn ^| fra ^| ptg ^| ptb ^| ita ^| rus ^| plk ^| ell ^| csy ^| dan ^| nor ^| sve ^| fin} [/outputpath ^<outputpath^>] 
echo Usage2: %~n0 {w2k ^| w2k3 ^| wxp ^| enu ^| deu ^| nld ^| esn ^| fra ^| ptg ^| ptb ^| ita ^| rus ^| plk ^| ell ^| csy ^| dan ^| nor ^| sve ^| fin ^| all} [/outputpath ^<outputpath^>] 
echo.
goto EoF

:NoMkIsoFs
echo.
echo ERROR: Utility ..\bin\mkisofs.exe not found.
echo.
goto Error

:MkIsoError
echo.
echo ERROR: Creation of ISO image failed.
echo.
goto Error

:Error
endlocal
pause
SignalError.exe
exit

:EoF
title %ComSpec%
endlocal
