@echo off
rem 30-04-2002 JvW Initial version, derived from DFSUNFD
rem 11-07-2002 JvW Updated to use V5 DFSDOS
rem 20-07-2002 JvW Removed confusing 'spacebar' hint for non-registred users
rem 05-11-2002 JvW Updated for executable naming DFSOS2, DFSWIN and DFSDOS
echo.

if "%0"=="IMGETEST"     echo on
if "%0"=="imgetest"     echo on

if "%OS2_SHELL%"=="" goto notos2
set dfsexe=dfsos2.exe
set cmdext=CMD
goto dfsee
:notos2
if "%OS%"==""        goto notnt
if "%OS%"=="DOS"     goto notnt
if "%OS%"=="MSDOS"   goto notnt
if "%OS%"=="DRDOS"   goto notnt
if "%OS%"=="IBMDOS"  goto notnt
if "%OS%"=="OPENDOS" goto notnt
set dfsexe=dfswin.exe
set cmdext=BAT
goto dfsee
:notnt
set dfsexe=dfsdos.exe
set cmdext=BAT
:dfsee

if "%1" == "?"   goto usage
if "%1" == "/?"  goto usage
if "%1" == "-?"  goto usage

%dfsexe% -b -q query RValid
if not errorlevel 1 goto work
echo.
echo NOTE: Your DFSee version is not properly registred, this will cause
echo       some extra delays and reminder messages to be displayed  ...
echo.

:work
set volume=A:
if "%2" == "*"   goto auto
if "%2" == "."   goto auto
if "%2" == ""    goto auto
set volume=%2
:auto
set imgcmd=wrim
set imfile=%1
if exist %1      goto checkvol
if exist %1.img  goto checkvol
if exist %1.imz  goto checkvol

if "%2" == ""    goto autosim

:trysim
set volume=%1
set imfile=%2
:autosim
set imgcmd=sim

:checkvol
if "%volume%" == "a:" goto validvol
if "%volume%" == "b:" goto validvol
if "%volume%" == "c:" goto validvol
if "%volume%" == "d:" goto validvol
if "%volume%" == "e:" goto validvol
if "%volume%" == "f:" goto validvol
if "%volume%" == "g:" goto validvol
if "%volume%" == "h:" goto validvol
if "%volume%" == "i:" goto validvol
if "%volume%" == "j:" goto validvol
if "%volume%" == "k:" goto validvol
if "%volume%" == "l:" goto validvol
if "%volume%" == "m:" goto validvol
if "%volume%" == "n:" goto validvol
if "%volume%" == "o:" goto validvol
if "%volume%" == "p:" goto validvol
if "%volume%" == "q:" goto validvol
if "%volume%" == "r:" goto validvol
if "%volume%" == "s:" goto validvol
if "%volume%" == "t:" goto validvol
if "%volume%" == "u:" goto validvol
if "%volume%" == "v:" goto validvol
if "%volume%" == "w:" goto validvol
if "%volume%" == "x:" goto validvol
if "%volume%" == "y:" goto validvol
if "%volume%" == "z:" goto validvol
if "%volume%" == "A:" goto validvol
if "%volume%" == "B:" goto validvol
if "%volume%" == "C:" goto validvol
if "%volume%" == "D:" goto validvol
if "%volume%" == "E:" goto validvol
if "%volume%" == "F:" goto validvol
if "%volume%" == "G:" goto validvol
if "%volume%" == "H:" goto validvol
if "%volume%" == "I:" goto validvol
if "%volume%" == "J:" goto validvol
if "%volume%" == "K:" goto validvol
if "%volume%" == "L:" goto validvol
if "%volume%" == "M:" goto validvol
if "%volume%" == "N:" goto validvol
if "%volume%" == "O:" goto validvol
if "%volume%" == "P:" goto validvol
if "%volume%" == "Q:" goto validvol
if "%volume%" == "R:" goto validvol
if "%volume%" == "S:" goto validvol
if "%volume%" == "T:" goto validvol
if "%volume%" == "U:" goto validvol
if "%volume%" == "V:" goto validvol
if "%volume%" == "W:" goto validvol
if "%volume%" == "X:" goto validvol
if "%volume%" == "Y:" goto validvol
if "%volume%" == "Z:" goto validvol
echo.

if %imgcmd% == sim goto badparam
if not "%2" == ""  goto trysim

echo The specified parameter %volume% is not a valid driveletter! Use A: .. Z:
goto end

:badparam
echo The specified parameter %volume% is not a valid driveletter,
echo and it is not an existing imagefile either!
goto usage2

:validvol
echo.
if %imgcmd% == wrim goto wrimcmd

echo Create an image of volume %volume% to compressed imagefile %imfile%
echo.
%dfsexe% %3 %4 %5 %6 %7 %8 %9 vol %volume%#sim -zip %imfile%#q
goto end

:wrimcmd
echo Restore imagefile %imfile% to volume %volume%
echo.
%dfsexe% %3 %4 %5 %6 %7 %8 %9 vol %volume%#wrim %imfile%#q
goto end

:usage
echo Create a compressed imagefile from diskette  (or any other driveletter)
echo or uncompress and write an imagefile back to diskette (or other volume)
:usage2
echo.
echo Usage:  %0  imagefile  X:  /  X:  imagefile  /  imagefile  [ switches ]
echo.
echo         imagefile =  Name of the imagefile, default extention is .IMZ
echo.
echo.                     When only an imagefile is specified (no 2nd param)
echo.                     and the file exists, it will be restored to the
echo                      diskette in the A: drive, otherwise the imagefile
echo                      will be created as an image of the diskette in A:
echo.
echo         X:        =  Drive-letter of the volume to use (often diskette)
echo.
echo         switches  =  Any valid DFSee switch  (as shown by DFSxx.exe -?)
echo.
echo                      Usefull switches for imaging are:
echo                      -l:logfile  = create a logfile
echo                      -b          = batch option, no confirmations
echo                      -w          = use windowed user interface
echo Examples:
echo  %0 A: floppy      Create imagefile 'floppy.imz' from diskette in A:
echo  %0 A: floppy -b   Create 'floppy.imz' from A:, no confirmations
echo  %0 floppy A:      Restore imagefile 'floppy.imz' to diskette in A:
echo  %0 floppy         Restore imagefile 'floppy.imz' to diskette in A:
echo                          file must exist, otherwise it is created from A:
:end
