@Rem GodSpeed 16-bit app in 64-bit Windows - DOSBox automation - Mar 2013

@Rem set to BGS.exe, GS.exe, GH.bat, COLORMEN.exe
@Set BGS_CMMD=GH.BAT 

@Rem For hardcoded path Set GPATH=/Users/All Users/GodSpeed
@Rem For current working directory use: Set GPATH=%CD%
@Set GPATH=%CD%
@Set DBOX=c:\Program Files (x86)\DOSBox-0.74\DOSBox.exe
@Set CONF=GSDosBox.conf
@Set PAUSE_CMD=Pause
@Rem Pause allows seeing error if any
@Rem Change to PAUSE_CMD="" if you do not need the pause

@Rem Overview:
@Rem 0. Make sure file exists proving we're in the correct folder
@Rem 1. Touch NOTICE to factory datestamp
@Rem 2. Read OS parameters from environment
@Rem 3. For 32-bit just run GH.bat / BGS.exe etc.
@Rem 4. For 64-bit OS, detect or install DosBox 0.74,
@Rem 5. Then run DOSBox with arguments to mount and run gh

@Rem 0. Make sure file exists proving we're in the correct folder
@If NOT Exist %BGS_CMMD% (
  Echo Usage: This BAT file needs to be in same folder with GodSpeed files
  Pause
  Exit
)
Echo "Test" > TEST.TXT
@If NOT Exist TEST.TXT (
  Echo Usage: This folder won't work directly from the CD.
  Echo    Copy it to a folder on your hard drive or even a thumb drive.
  Pause
  Exit
)
@DEL TEST.TXT

@Rem 1. Touch NOTICE to factory datestamp
Notifix

@Rem 2. Read OS parameters from environment
echo %PROCESSOR_IDENTIFIER% > CheckOS.txt
@Rem for testing or to force DOSBox, remove the "@Rem" from one of these two lines
@Rem echo x86 > CheckOS.txt
@Rem echo Intel64 > CheckOS.txt
@Rem if the PROC ID is not sufficient see http://support.microsoft.com/kb/556009

@Rem 3. For 32-bit just run GH.bat / BGS.exe etc.
@Find /i "x86" < CheckOS.txt > NUL
@If %ERRORLEVEL% == 0 (
  @Rem Echo "Detected 32 Bit Operating system"
  %BGS_CMMD%
  @Del checkOS.txt
  exit
)
@Rem @Find /i "Intel64" < CheckOS.txt > NUL
@Rem If %ERRORLEVEL% == 0 (
  @Rem  @Echo "This is 64 Bit Operating System"
@Rem 4. For 64-bit OS, detect or install DosBox 0.74,
:NEWDBOX
  @If NOT Exist "%DBOX%" goto NODOSBOX
    @If NOT Exist %CONF% (
      @Rem Use a local conf file to set larger resolution, need DirectDraw for that
      @Rem "%DBOX%" -noconsole -c "rem  Initial Load - preparing config" -c Pause -c Exit
      @Rem @Copy C:\Users\%USERNAME%\AppData\Local\DOSBox\*.conf %CONF%
      echo # Supplemental configuration - specifies ddraw and larger window resolution >> %CONF%
      echo [sdl]                           >> %CONF%
      echo windowresolution=1024x768       >> %CONF%
      echo output=ddraw                    >> %CONF%
      echo #                               >> %CONF%
      echo [autoexec]                      >> %CONF%
      echo # Lines in this section will be run at startup.  >> %CONF%
      echo # You can put your MOUNT lines here.             >> %CONF%
      @Rem echo MOUNT c "%GPATH%"          >> %CONF%
      @Rem echo c:                         >> %CONF%
      @Rem echo gh                         >> %CONF%
    )

@Rem 5. Then run DOSBox with arguments to mount and run gh
    @Rem ******************************
    @Rem     Invoke DOSBox Here
    @Rem ******************************
    @Rem minimalist DOSBox command line that still mounts and runs GS
    @Rem "%DBOX%" -c "mount c \"%GPATH%\"" -c C: -c GH

    @Rem use config file to set larger resolution, minimize if started from shortcut, exit after user hits space bar
    @Rem For Hebrew/Greek: -c "bgs m" -c HG
    @Rem For BGS alone:    -c bgs
    @Rem As adopted, now uses %BGS_CMMD% instead of BGS or GH or COLORMEN etc:
    "%DBOX%" -conf %CONF% -noconsole -c "mount c \"%GPATH%\"" -c C: -c "command /c %BGS_CMMD%" -c %PAUSE_CMD% -c Exit

    goto DONEDOSBOX
  @Rem )
:NODOSBOX
  @cls
  @Echo     GodSpeed will use DosBox 0.74 ...
  @Echo     DosBox 0.74 not installed!
  @If Exist %GPATH%\DOSBox0.74-win32-installer.exe (
    @Echo However the installer is present, so this will now install...
    @Echo During install, remember to Uncheck "Desktop Shortcut" box
    @Echo Press Ctrl+C to quit, or to begin installation,
    @Pause
    start /wait %GPATH%\DOSBox0.74-win32-installer.exe
    @Rem check again after installer
    @If Exist "%DBOX%" goto NEWDBOX
  )
  @If Exist \Users\%USERNAME%\Downloads\DOSBox0.74-win32-installer.exe (
    @Echo However it has been downloaded.
    @Echo During install, remember to Uncheck "Desktop Shortcut" box
    @Echo Press Ctrl+C to quit, or to begin installation,
    @Pause
    start /wait \Users\%USERNAME%\Downloads\DOSBox0.74-win32-installer.exe
    @Rem check again after installer
    @If Exist "%DBOX%" goto NEWDBOX
  )
  @Echo Press Ctrl+C to quit,
  @Echo  OR to download from http://www.dosbox.com,
    @Echo This will automatically launch Internet Explorer
    @Echo    to download DosBox
    @Echo click "Windows" in the following screen
    @Echo The download should start in a few seconds
    @Echo Click "Save" at the bottom
    @Echo This script will look in your Downloads folder next time
    @Echo Ready? If not, press Ctrl+C to quit, or else
    @Pause     "    "
    start iexplore http://www.dosbox.com/download.php?main=1
    @Echo Try again after downloading DOSBox
    Pause
:DONEDOSBOX
Del checkOS.txt
