@echo off
rem detect build OS
if "%OS%".=="Windows_NT". goto Win
if "%VIO_SVGA%".=="". goto UnkOS
set suffix=o
goto cont
:UnkOS
echo Unknown OS!
goto end
:Win
set suffix=w
:cont
if %1.==. goto about
if not exist %suffix%\vpcfcopy.exe goto bserr
if not exist QSINIT.LDI goto dotdot
if not exist OS2LDR goto dotdot
set bsrc=
goto runit
:dotdot
set bsrc=..\
if not exist ..\QSINIT.LDI goto berr
if not exist ..\OS2LDR goto berr
:runit
if not exist %1 goto noimg

%suffix%\vpcfcopy.exe %1 OS2LDR %bsrc%OS2LDR
if errorlevel 1 goto wrerror
%suffix%\vpcfcopy.exe %1 QSINIT.LDI %bsrc%QSINIT.LDI
if errorlevel 1 goto wrerror
%suffix%\vpcfcopy.exe /boot %1 OS2LDR
if errorlevel 1 goto wrerror
goto end

:noimg
if "%2".=="". goto noimgsize
%suffix%\vpcfcopy.exe /create %1 %2
if exist %1 goto runit
echo Unable to create image file %1!
goto end

:wrerror
echo Write failure...
goto end

:noimgsize
echo Image file %1 not found!
goto end

:berr
echo Unable to locate QSINIT files: OS2LDR and QSINIT.LDI.
goto end

:serr
echo Error writing boot sector, cancelled.
goto end

:bserr
echo Unable to locate QSINIT "VPCFCOPY" executable.
goto end

:about
echo.
echo Install QSINIT into a FAT disk image.
echo.
echo Usage: instimg.cmd imgfile [1.44/2.88/size]
echo.
echo        if no "imgfile" found - raw image can be created: 1.44Mb, 2.88Mb
echo        floppy or "size" megabytes HDD (up to 2048).
echo.
echo        HDD image created in RAW format by default, but fixed size VHD
echo        can be forced by ".vhd" extension of the image file.
echo.
:end
