@echo off
rem 08-05-2002 JvW Initial version, derived from DFSIMAGE
rem 29-05-2002 JvW Updated basename to fixed 'dfstart'
echo.

if "%0"=="STARTEST"     echo on
if "%0"=="startest"     echo on

if "%OS%"==""        goto notnt
if "%OS%"=="DOS"     goto notnt
if "%OS%"=="MSDOS"   goto notnt
if "%OS%"=="DRDOS"   goto notnt
if "%OS%"=="IBMDOS"  goto notnt
:dfsnt
set dfsexe=dfsnt
goto dfsee
:notnt
if "%OS2_SHELL%"=="" goto notos2
:dfsnt
set dfsexe=dfs
goto dfsee
:notos2
set dfsexe=dfsmdos
:dfsee

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

%dfsexe% -R -b -q query RValid
if not errorlevel 1 goto work
echo.
echo NOTE: Your DFSee version is not properly registred, this will
echo       require you to press [Space-bar] a few times  ...
echo.

:work
set dfswitch=
set basename=dfstart
if "%1" == ""    goto step1
if "%1" == "-R-" goto setswitch
if "%1" == "-7"  goto setswitch
if "%1" == "-a"  goto setswitch
if "%1" == "-b"  goto setswitch
if "%1" == "-q"  goto setswitch
if "%1" == "-Q"  goto setswitch
if "%1" == "-w"  goto setswitch
if "%1" == "-w-" goto setswitch
set basename=%1
goto step1

:setswitch
set dfswitch=%1

:step1
echo.
echo This script will start a DFSee recovery session but will create
echo some very usefull backup files the first time it is used.
echo These might come in very handy if anything unexpected happens ...
echo To refresh the files, delete %basename%1.log and %basename%.pd1
echo and new ones will be generated. All logging will be appended
echo to %basename%.log, each time you run %0
echo.
echo For safety, DFSee will be started in READONLY mode, if you need
echo to fix something, and have found out how to do that, you can start
echo this script with the "-R-" option to allow writing to the disks
echo.
echo For some help in using this script, use the command '%0  ?'
echo.
echo If you do not need the backups, or know exactly what you are
echo doing, you can start the DFSee program %dfsexe%.exe directly
echo.
echo In any case, YOU are responsible for any damage you cause :-)
echo.
echo Press any key to start with the %basename% session now,
echo or use Ctrl+C to abort the script ...
echo.
pause > NUL

if exist %basename%1.log goto step2
echo.
echo Create backup log-files with important information ...
echo.
call DFSUNFD
echo.
echo Rename DFSUNFD files to %basename% name ...
echo.
if exist dfsunfd1.log copy dfsunfd1.log %basename%1.log
if exist dfsunfd1.log del  dfsunfd1.log
if exist dfsunfd2.log copy dfsunfd2.log %basename%2.log
if exist dfsunfd2.log del  dfsunfd2.log
if exist dfsunfd3.log copy dfsunfd3.log %basename%3.log
if exist dfsunfd3.log del  dfsunfd3.log
if exist dfsunfd4.log copy dfsunfd4.log %basename%4.log
if exist dfsunfd4.log del  dfsunfd4.log
if exist dfsunfd5.log copy dfsunfd5.log %basename%5.log
if exist dfsunfd5.log del  dfsunfd5.log
if exist dfsunfd6.log copy dfsunfd6.log %basename%6.log
if exist dfsunfd6.log del  dfsunfd6.log
if exist dfsunfd7.log copy dfsunfd7.log %basename%7.log
if exist dfsunfd7.log del  dfsunfd7.log
if exist dfsunfd8.log copy dfsunfd8.log %basename%8.log
if exist dfsunfd8.log del  dfsunfd8.log
if exist dfsunfd9.log copy dfsunfd9.log %basename%9.log
if exist dfsunfd9.log del  dfsunfd9.log

:step2
echo.
echo Create backup files with important partition/boot sectors ...
echo.
if exist %basename%.pd1 goto step3
%dfsexe% -R -b -Q -l:%basename% fdisk psave * %basename% Backup important sectors by %0

:step3
echo.
echo Start DFSee executable %dfsexe% for interactive recovery ...
echo.
%dfsexe% -R -l:%basename% %2 %3 %4 %5 %6 %7 %8 %9
echo.
echo Log and backup files collect for the %basename% session sofar:
echo.
dir %basename%*.*
echo.
echo For support, ZIP these files, add as much problem description as
echo you can, and send it to: support@dfsee.com
goto end

:usage
echo Start a DFSee recovery session, creating logs/backups on first time
echo.
echo Usage:  %0  [somename] [switches ]
echo.
echo         somename  =  Basename to be used for log and backupfiles, the
echo                      name should not be longer than 7 characters!
echo                      Part of your (computer) name would be usefull.
echo.                     When no name is specified, '%0' will be used
echo.
echo         switches  =  Any valid DFSee switch  (as shown by DFSxx.exe -?)
echo                      -w          = use windowed user interface
echo                      -R-         = turn off READONLY mode
echo Examples:
echo  %0             Start a DFSee recovery, create the following files:
echo                      - dfstart?.LOG
echo                      - dfstart.PD?          Where '?' is a disk number
echo                      - dfstart.LOG
echo.
echo  %0 recover     Start a DFSee recovery, create the following files:
echo                      - RECOVER?.LOG
echo                      - RECOVER.PD?          Where '?' is a disk number
echo                      - RECOVER.LOG
echo.
:end
