echo off

REM Set ECHO_LABLES to "YES" for to display each lable traversed.
set ECHO_LABLES="NO"
if     %ECHO_LABLES%=="YES" set !=echo
if NOT %ECHO_LABLES%=="YES" set !=REM

REM Default system to use when no parameters specified
set DEFLTSYS=SVMi16E

if "%1%"=="/?"        goto Usage
if "%1%"=="/h"        goto Usage
if "%1%"=="/H"        goto Usage
if "%1%"=="/help"     goto Usage
goto SetSystem

REM Usage message
:Usage
%!% :Usage
echo :
echo Usage: DEFAULT [System]
echo :
echo This will default the system to the "out of box" configuration.
echo Different configurations are possible. They go by a name like Basic.
echo If no name is specified as a command line parameter, a '%DEFLTSYS%'
echo will be assumed. 
goto End


:SetSystem
%!% :SetSystem

set SYSVER=%1

REM Set to the directory where SVM.EXE is located. Normally, C:\DTA
set DTA_DIR=C:\DTA 

if "%SYSVER%"==""         set SYSVER=%DEFLTSYS%
if "%SYSVER%"=="ALL"      goto ALL
if "%SYSVER%"=="Basic"    goto Basic
if "%SYSVER%"=="SVMi8"    goto SVMi8
if "%SYSVER%"=="SVMi16E"  goto SVMi16E
echo "%SYSVER%" is not a recognized version.
echo Try "%0 Basic", "%0 SVMi8",
echo "%0 SVMi16E", or "%0 ALL".
goto End

:ALL
%!% :ALL
  REM SVMi16E default system files extension
  set EXT=SVF        
  goto OkToProceedALL

:Basic 
%!% :Basic
  echo This operation will configure the SVM/SVMi System to avail simpler more
  echo Basic TUI, like the original SVMi4 System.
  REM Basic default system files extension
  set EXT=SV4        
  goto OkToProceed

:SVMi8
%!% :SVMi8
  REM SVMi8 default system files extension
  set EXT=SRD        
  goto OkToProceed

:SVMi16E
%!% :SVMi16E
  REM SVMi16E default system files extension
  set EXT=SVF        
  goto OkToProceed

:OkToProceed
%!% :OkToProceed
  set ORG_DIR=%DTA_DIR%\ORIGINAL
  echo This operation will set up the system to original configuration.
  echo This means that all the costumization that was done will be REMOVED.
  echo In particular, all the mailboxes and all messages in them will be DELETED.
  echo .
  echo .
  echo Press any key to continue or Ctrl+C to stop this batch process.
  pause

  goto RestoreOriginal

:OkToProceedALL
%!% :OkToProceedALL
  set ORG_DIR=%DTA_DIR%\ORIGINAL
  set SOC_DIR=C:\SOCKETS
  set PMT_DIR=C:\PMT\EN_US
  echo This operation will set up the system to original configuration.
  echo This means that all the costumization that was done will be REMOVED.
  echo In particular, all the mailboxes and all messages in them will be DELETED.
  echo .
  echo Socket.CFG and custom EN_US prompts 1001, 1002, 1003, and 1004 will also 
  echo be returned to their original "out of box" settings.
  echo .
  echo .
  echo Press any key to continue or Ctrl+C to stop this batch process.
  pause

  goto RestoreALL
   
 :RestoreALL
  %!% :RestoreALL
  
  :DoSocketConfig
   %!% :DoSocketConfig
    if EXIST %SOC_DIR%\ORIGINAL\Socket.CFG goto RestSocketConfig
    echo Cannot find original Socket Config file %SOC_DIR%\Original\Socket.cfg
    goto DoSocketUPW
    :RestSocketConfig
     %!% :RestSocketConfig
       copy   %SOC_DIR%\ORIGINAL\Socket.cfg    %SOC_DIR%\Socket.cfg
       if not ERRORLEVEL 1 echo Copied %SOC_DIR%\ORIGINAL\Socket.cfg    to %SOC_DIR%\Socket.cfg

  :DoSocketUPW
   %!% :DoSocketUPW
    if EXIST %SOC_DIR%\ORIGINAL\Socket.UPW goto RestSocketUPW
    echo Cannot find original Socket User file %SOC_DIR%\Original\Socket.UPW
    goto DoPMT
    :RestSocketUPW
     %!% :RestSocketUPW
       copy   %SOC_DIR%\ORIGINAL\Socket.upw    %SOC_DIR%\Socket.upw
       if not ERRORLEVEL 1 echo Copied %SOC_DIR%\ORIGINAL\Socket.upw    to %SOC_DIR%\Socket.upw


  :DoPMT
   %!% :DoPMT
    if EXIST %PMT_DIR%\Original\1*.PMT goto RestPMT
    echo Cannot find original "out of box" prompt File %PMT_DIR%\Original\100x.PMT
    goto RestoreOriginal
    :RestPMT
     %!% :RestPMT
       copy   %PMT_DIR%\Original\1001.PMT %PMT_DIR%\1001.PMT
       if not ERRORLEVEL 1 echo Copied %PMT_DIR%\Original\1001.PMT to %PMT_DIR%\1001.PMT
       copy   %PMT_DIR%\Original\1002.PMT %PMT_DIR%\1002.PMT
       if not ERRORLEVEL 1 echo Copied %PMT_DIR%\Original\1002.PMT to %PMT_DIR%\1002.PMT
       copy   %PMT_DIR%\Original\1003.PMT %PMT_DIR%\1003.PMT
       if not ERRORLEVEL 1 echo Copied %PMT_DIR%\Original\1003.PMT to %PMT_DIR%\1003.PMT
       copy   %PMT_DIR%\Original\1004.PMT %PMT_DIR%\1004.PMT
       if not ERRORLEVEL 1 echo Copied %PMT_DIR%\Original\1004.PMT to %PMT_DIR%\1004.PMT
       copy   %PMT_DIR%\Original\5*.PMT %PMT_DIR%\5*.PMT
       if not ERRORLEVEL 1 echo Copied %PMT_DIR%\Original\5*.PMT to %PMT_DIR%\5*.PMT

  goto RestoreOriginal

 :RestoreOriginal
  %!% :RestoreOriginal
  
  :DoBlockTable
   %!% :DoBlockTable
    if EXIST %ORG_DIR%\BLOCK.%EXT% goto RestBlockTable
    echo Cannot find original Block table file %ORG_DIR%\BLOCK.%EXT%
    goto DoSiteInfoTable
    :RestBlockTable
     %!% :RestBlockTable
       copy   %ORG_DIR%\BLOCK.%EXT%    %DTA_DIR%\BLOCK.TBL
       if not ERRORLEVEL 1 echo Copied %ORG_DIR%\BLOCK.%EXT%    to %DTA_DIR%\BLOCK.TBL

  :DoSiteInfoTable
   %!% :DoSiteInfoTable
    if EXIST %ORG_DIR%\SITEINFO.%EXT% goto RestSiteInfoTable
    echo Cannot find original Site Info table file %ORG_DIR%\SITEINFO.%EXT%
    goto DoScheduleTable
    :RestSiteInfoTable
     %!% :RestSiteInfoTable
       copy   %ORG_DIR%\SITEINFO.%EXT% %DTA_DIR%\SITEINFO.TBL
       if not ERRORLEVEL 1 echo Copied %ORG_DIR%\SITEINFO.%EXT% to %DTA_DIR%\SITEINFO.TBL

  :DoScheduleTable
   %!% :DoScheduleTable
    if EXIST %ORG_DIR%\SCHEDULE.%EXT% goto RestScheduleTable
    echo Cannot find original Schedule table file %ORG_DIR%\SCHEDULE.%EXT%
    goto DoMessageTable
    :RestScheduleTable
     %!% :RestScheduleTable
       copy   %ORG_DIR%\SCHEDULE.%EXT% %DTA_DIR%\SCHEDULE.TBL
       if not ERRORLEVEL 1 echo Copied %ORG_DIR%\SCHEDULE.%EXT% to %DTA_DIR%\SCHEDULE.TBL

  :DoMessageTable
   %!% :DoMessageTable
    if EXIST %ORG_DIR%\MESSAGE.%EXT%  goto RestMessageTable     
    echo Cannot find original Message table file %ORG_DIR%\MESSAGE.%EXT%
    goto DoTrunksTable
    :RestMessageTable
     %!% :RestMessageTable
       copy   %ORG_DIR%\MESSAGE.%EXT%  %DTA_DIR%\MESSAGE.TBL
       if not ERRORLEVEL 1 echo Copied %ORG_DIR%\MESSAGE.%EXT%  to %DTA_DIR%\MESSAGE.TBL
    
  :DoTrunksTable
   %!% :DoTrunksTable
    if EXIST %ORG_DIR%\TRUNKS.%EXT%  goto RestTrunksTable    
    echo Cannot find original Trunks table file %ORG_DIR%\TRUNKS.%EXT%
    goto DoSystemCfgFile
    :RestTrunksTable
     %!% :RestTrunksTable
       copy   %ORG_DIR%\TRUNKS.%EXT%   %DTA_DIR%\TRUNKS.TBL
       if not ERRORLEVEL 1 echo Copied %ORG_DIR%\TRUNKS.%EXT%   to %DTA_DIR%\TRUNKS.TBL

  :DoSystemCfgFile
   %!% :DoSystemCfgFile
    if EXIST %ORG_DIR%\SYSTEM.CFG  goto RestSystemCfgFile    
    echo Cannot find original SYSTEM.CFG file %ORG_DIR%\SYSTEM.CFG
    goto DoIniFile
    :RestSystemCfgFile
     %!% :RestSystemCfgFile
       copy   %ORG_DIR%\SYSTEM.CFG   %DTA_DIR%\SYSTEM.CFG
       if not ERRORLEVEL 1 echo Copied %ORG_DIR%\SYSTEM.CFG   to %DTA_DIR%\SYSTEM.CFG

  :DoIniFile
   %!% :DoIniFile
    if EXIST %ORG_DIR%\INIFILE.%EXT%  goto RestIniFile    
    echo Cannot find original SVMi INI file %ORG_DIR%\INIFILE.%EXT%
    goto DoneRestoreOriginal
    :RestIniFile
     %!% :RestIniFile
       copy   %ORG_DIR%\INIFILE.%EXT% %DTA_DIR%\SYSTEM.INI
       if not ERRORLEVEL 1 echo Copied %ORG_DIR%\INIFILE.%EXT%  to %DTA_DIR%\SYSTEM.INI

 :DoneRestoreOriginal
  %!% :DoneRestoreOriginal


  :DelMbx
  %!% :DelMbx
  echo Deleting Mailboxes!
  del C:\MBX\*.*

  :DelMsg
  %!% :DelMsg
  echo Deleting Messages!
  del C:\MSG\*.*

:End
%!% :End
  set DEBUG=
  set DTA_DIR=
  set DEFLTSYS=
  set SYSVER=
  set ECHO_LABLES=
  set ORG_DIR=
  set SOC_DIR=
  set PMT_DIR=
  set !=
  set EXT=