:: _4INST.BTM   Free 4DOS Self-Installer V7.9   Copyright 1999 JP Software Inc.
::
:: Author: Tom Rawson :::::::::::::::::::::::::::::::: Last Revision: 1999-3-24
:: Adaptations for free 4DOS by Klaus Meinhard and Luchezar Georgiev, 2008-11-7
::
:: This batch file installs free 4DOS. It runs once, and then renames itself so
:: it will no longer be run automatically. Its primary functions are:
::
::   * Check the 4DOS verson and that the required files exist, and test the
::     operating system.
::   * Locate the previous copy of 4DOS, if any. If there was one:
::	- Copy over the old .INI and 4START files.
::	- Update the old .INI file for the new path and replace the obsolete
::	  HelpPath directive with InstallPath.
::   * Update CONFIG.SYS so the SHELL= line points to [the new] 4DOS (except in
::     WinME, NT or OS/2).
::   * Update AUTOEXEC.BAT to include KSTACK (except in Win9x/ME, NT or OS/2).
::   * If running OS/2, start a .CMD file to create a desktop folder for 4DOS.
::   * If running Win9x/ME, make a shortcut for 4DOS & add registry extensions.
::
	@*echo off
	*setlocal
	*unalias *
	on errormsg goto ON_ERROR
	on break goto ON_BREAK
	setdos /g.,
	if %_4ver ge 7.90 goto VEROK
	cls
	text
This installer is for use under 4DOS 7.90 or above. It will not work for other
products or earlier versions.

	endtext
	pause
	goto DONE
:VEROK
	setdos /p%=&
	setdos /b1
	cls
	if "%_jprr" eq "Y" goto PATHOK
	text
Welcome to free 4DOS!

This installer is run automatically the first time you start a new copy of free
4DOS. If you are new to 4DOS, it will install 4DOS on your system. No system
files will be modified without your permission.

If you already have a previous version of 4DOS installed, it will copy the
settings (4DOS.INI, 4START and 4EXIT) from the previous version to the new
directory, and (after requesting your permission) will update the appropriate
configuration files.

If you have already installed this new version of 4DOS, or prefer to perform
the installation manually as described in the INTRO.TXT file, you can exit
now, and this installer will not be run again.

	endtext
	inkey /k"yn" Proceed with installation (Y/N)?  %%yn
	if "%yn" ne "Y" goto EXIT_NORETRY
	if %@len["%@full[%0]"] lt 150 goto PATHOK
	echo.
	echo The 4DOS directory name is too long for automated installation.
	goto FATALERR
:PATHOK
	cdd "%@path["%@full[%0]"]" || (echo Cannot switch to the 4DOS directory! %+ goto FATALERR)
	iff not exist 4DOS.COM then
		echo. %+ echo %@repeat[Í,79]
		text

The 4DOS automated installation batch file is not in the directory where the
4DOS files are stored. Please put all the new 4DOS files in the same directory
and try again.
		endtext
		goto DONE
	endiff
	iff (%_env lt 512 .or. %_alias lt 256) then
		iff "%_jprr" eq "Y" then
			exit 16
		else
			echo. %+ echo %@repeat[Í,79]
			text

The free environment or alias space is not adequate for automated installation.
The installer will start a temporary copy of 4DOS with larger environment and
alias space, and try again.

			endtext
			pause
			set _jprr=Y
			.\4dos.com //envfree=768 //alias=%@eval[%_alias + 384] /c "%@full[%0]" %&
			unset /q _jprr
			iff %? eq 16 then
				echo. %+ echo %@repeat[Í,79]
				text

The free environment or alias space is still inadequate for automated
installation.
				endtext
				goto FATALERR
			else
				goto DONE
			endiff
		endiff
	endiff
	alias wait `echo. %+ pause Press any key to continue...`
	alias yesno `echo. %+ inkey /k"yn" %2& (Y/N)?  %%%1`
	alias retry `(beep %+ iff "%2&" ne "" then %+ echo. %+ echo %2& %+ endiff %+ goto %1)`
	alias insthelp `pushd %+ .\insthelp.exe %& %+ set result=%? %+ popd`
	alias instinf `pushd %+ %instinf %& %+ popd`
	alias sep `echo. %+ echo %@repeat[Í,79] %+ echo.`
	set cd=%@upper[%_cwds]
	set instinf=rem
	iff %_win ge 40 then
		set cd=%@sfn["%cd"]
		set instinf=rundll.exe
		if "%windir" ne "" .and. exist "%windir\rundll.exe" set instinf=%windir\rundll.exe
		set instinf=%instinf setupx.dll,InstallHinfSection DefaultInstall 132
	endiff
	set reqfiles=4DOS.COM OPTION.EXE 4HELP.EXE 4DOS.HLP INSTHELP.EXE
	set exefile=4DOS.COM
	set batext=BTM BAT
	set opsys=%_dos
	if %_win eq 40 set opsys=Windows 95
	if %_win eq 41 set opsys=Windows 98
	if %_win eq 42 set opsys=Windows ME
	for %f in (%reqfiles) if not exist %f (set errname=%f %+ goto MISSING_FILE)
	goto FILESOK
:MISSING_FILE
	sep
	echo The %errname file is missing. This file is required to install 4DOS.
	echo Please check that all unarchived files were placed in the same directory.
	goto ON_ERROR
:FILESOK
	sep
	echo This procedure installs 4DOS version %_4ver.
	yesno pver Are you currently using an earlier version of 4DOS on your system
	if "%pver" ne "Y" goto NOPREV
:GETPDIR
	sep
	echo Please enter the name of the directory where your previous
	input version of 4DOS is installed:  %%prevdir
	iff %_dosver eq 5.50 then
		option //Win95LFN=Yes
		option //Win95SFNSearch=No
		text
You seem to be running a Windows NT family operating system: Windows NT,
Windows 2000, Windows XP, Server 2003, Windows Vista, Server 2008, etc.

4DOS is a DOS-based program, not designed for Windows NT. It can be run there
but with limitations. Files and directories with extremely long DOS-compatible
filenames or without DOS-compatible filenames will be inaccessible. Long
filename support is disabled by default and must be explicitly enabled through
an .INI directive. Very large or deeply nested directories may cause "out of
memory" errors. 4DOS does not support Internet files, links, Windows file
associations, graphical controls or true pipes, nor can it access the clipboard
under Windows NT. That is why using 4DOS under Windows NT is not recommended.

4NT and Take Command are the preferred command shells for Windows NT. They were
designed for it and do not suffer from the DOS-imposed limitations of 4DOS.
		endtext
		wait
	endiff
	set prevdir=%@rtrim[/\,%@sfn[%@quote[%prevdir]]]\
	if not isdir %prevdir retry getpdir That is not a valid directory
	iff not exist %[prevdir]%exefile then
		text
This directory does not seem to contain a previous version of 4DOS. Please try
again.
		endtext
		retry getpdir
	endiff
	sep
	text
Your current 4DOS.INI, 4START and 4EXIT files (if any) will now be copied from
the previous 4DOS directory. If these files already exist in the new 4DOS
directory you will be prompted for whether to replace the file in the new
directory with the file from the old directory.
	endtext
	yesno yn Copy the 4DOS.INI, 4START and 4EXIT files
	iff "%yn" eq "Y" then
		if exist %[prevdir]4DOS.INI copy %[prevdir]4DOS.INI .\
		for %f in (4START 4EXIT) for %e in (%batext) if exist %[prevdir]%f.%e copy %[prevdir]%f.%e .\
		iff exist 4DOS.INI then
			sep
			text
Paths in the new copy of 4DOS.INI will now be updated to point to your new 4DOS
directory. The old .INI file will be saved as 4DOS.JPS. If you do not allow
this update, you must perform it manually, or 4DOS may not work properly.

During the update process any old HelpPath directive will be removed from
4DOS.INI (this directive is now obsolete), and an InstallPath directive will be
added.
			endtext
			yesno yn Update 4DOS.INI
			set jptemp=%@filename["%@unique[.]"]
			iff "%yn" eq "Y" then
				insthelp IniFile /d"%cd" /o"4DOS.INI" /t"%jptemp"
				iff %result eq 0 then
					copy 4DOS.INI 4DOS.JPS > nul
					copy %jptemp 4DOS.INI > nul
				else
					sep
					text
Paths in 4DOS.INI could not be updated due to the above error. Be sure to
manually update any settings in 4DOS.INI which point to the 4DOS directory. If
you do not, 4DOS may not work properly.
					endtext
				endiff
				wait
			endiff
			del /q %jptemp > nul
		endiff
	else
		sep
		text
You chose not to copy existing startup files from your previous 4DOS directory.
You may want to copy these files manually at a later time, and update them for
the new version.
		endtext
		wait
	endiff
:NOPREV
	echo [4DOS] >! 4DOS.INI
	echo InstallPath = %cd >>! 4DOS.INI
:DOCONFIG
	if %_win eq 42 .or. %_dosver eq 5.50 .or. %_dosver ge 20.0 goto CONFIGDONE
	set csname=%_boot:\CONFIG.SYS
	set csbak=%_boot:\CONFIG.JPS
	set csmod=N
	sep
	text
The installer can update CONFIG.SYS to load your new copy of 4DOS as the
default command processor. You have three choices:

   - Update the system CONFIG.SYS file. This is the recommended method and will
     fully install 4DOS on your system. Your previous CONFIG.SYS file will be
     saved as CONFIG.JPS.

   - Make a copy of CONFIG.SYS in the 4DOS directory and update that copy,
     instead of the "real" CONFIG.SYS file. This allows you to review the
     changes before implementing them. If there is already a copy of CONFIG.SYS
     in the 4DOS directory it will be renamed CONFIG.JPS.

   - Skip the CONFIG.SYS update. In this case you will have to update
     CONFIG.SYS manually (see the INTRO.TXT file for details).

Enter:	Y to update CONFIG.SYS
	C to update a copy of CONFIG.SYS in the 4DOS directory
	N to skip the CONFIG.SYS changes

	endtext
	inkey /k"YNC" Your choice:  %%csopt
	switch %csopt
		case Y
			set jptemp=%@filename["%@unique[.]"]
			insthelp Config /d"%cd" /o"%csname" /t"%jptemp"
			iff %result eq 0 then
				copy %csname %csbak > nul
				copy %jptemp %csname > nul
				set csmod=Y
				sep
echo CONFIG.SYS has been updated. The next time you reboot your system, your new
echo copy of 4DOS will be used as the %opsys command processor.
			else
				sep
				text
CONFIG.SYS could not be updated due to the above error. You must update it
manually (see the INTRO.TXT file for details).
				endtext
			endiff
			del /q %jptemp > nul
		case C
			echo.
			if exist .\config.sys (move .\CONFIG.SYS .\CONFIG.JPS > nul)
			insthelp Config /d"%cd" /o"%csname" /t"%[cd]CONFIG.SYS"
			sep
			iff %result eq 0 then
echo The copy of CONFIG.SYS has been updated. You can review this file, then
echo make changes to the real CONFIG.SYS file manually when you are ready to
echo start using your new copy of 4DOS as the %opsys command processor.
			else
				text
The copy of CONFIG.SYS could not be updated due to the above error. You must
update CONFIG.SYS manually (see the INTRO.TXT file for details).
				endtext
			endiff
		case N
			sep
echo CONFIG.SYS will not be updated. You can update it manually when you are
echo ready to start using your new copy of 4DOS as the default %opsys
echo command processor (see the INTRO.TXT file for details).
	endswitch
	wait
:CONFIGDONE
	if %_win ge 40 .or. %_dosver eq 5.50 .or. %_dosver ge 20.0 goto AUTOEXECDONE
	set aename=%_boot:\AUTOEXEC.BAT
	set aebak=%_boot:\AUTOEXEC.JPS
	sep
	text
The installer can update AUTOEXEC.BAT to load the KSTACK.COM program, a small
memory-resident program used by the 4DOS KEYSTACK command to pass keystrokes to
DOS applications. You have three choices:

   - Update the system AUTOEXEC.BAT file. This is the recommended method and
     will fully install 4DOS on your system. Your previous AUTOEXEC.BAT file
     will be saved as AUTOEXEC.JPS.

   - Make a copy of AUTOEXEC.BAT in the 4DOS directory and update that copy,
     instead of the "real" AUTOEXEC.BAT file. This allows you to review the
     changes before implementing them. If there is already a copy of
     AUTOEXEC.BAT in the 4DOS directory it will be renamed to AUTOEXEC.JPS.

   - Skip the AUTOEXEC.BAT update. In this case you will have to update
     AUTOEXEC.BAT manually to install KSTACK.COM (see the INTRO.TXT file for
     details).

Enter:	Y to update AUTOEXEC.BAT
	C to update a copy of AUTOEXEC.BAT in the 4DOS directory
	N to skip the AUTOEXEC.BAT changes

	endtext
	inkey /k"YNC" Your choice:  %%aeopt
	switch %aeopt
		case Y
			set jptemp=%@filename["%@unique[.]"]
			insthelp AutoExec /d"%cd" /o"%aename" /t"%jptemp"
			iff %result eq 0 then
				copy %aename %aebak > nul
				copy %jptemp %aename > nul
				set aemod=Y
				echo AUTOEXEC.BAT has been updated.
			else
				sep
				text
AUTOEXEC.BAT could not be updated due to the above error. You must update it
manually (see the INTRO.TXT file for details).
				endtext
			endiff
			del /q %jptemp > nul
		case C
			if exist .\AUTOEXEC.BAT (move .\AUTOEXEC.BAT .\AUTOEXEC.JPS > nul)
			insthelp AutoExec /d"%cd" /o"%aename" /t"%[cd]AUTOEXEC.BAT"
			sep
			iff %result eq 0 then
				text
The copy of AUTOEXEC.BAT has been updated. You can review this file, then make
changes to the real AUTOEXEC.BAT file manually when you are ready.
				endtext
			else
				text
The copy of AUTOEXEC.BAT could not be updated due to the above error. You must
update AUTOEXEC.BAT manually (see the INTRO.TXT file for details).
				endtext
			endiff
		case N
			sep
			text
AUTOEXEC.BAT will not be updated. You can update it manually when you are ready
(see the INTRO.TXT file for details).
			endtext
	endswitch
	wait
:AUTOEXECDONE
	iff %_dosver ge 20.0 .and. exist jpos2ins.cmd then
		sep
		text
You seem to be running OS/2. Note that 4OS2 is the preferred command shell for
OS/2. It was designed for this system, has several OS/2-specific commands that
4DOS lacks, and does not suffer from its DOS-imposed limitations.

If you wish, the installer can create an OS/2 desktop folder for 4DOS,
including objects to start 4DOS itself and the 4DOS help.
		endtext
		yesno yn Create an OS/2 desktop folder for 4DOS
		iff "%yn" == "Y" then
			start /fg /c jpos2ins.cmd "4DOS" "%cd" "CreateFolder"
			sep
			text
You should see the folder creation window open and execute on the screen.
Creating a folder is a separate process, and the installer cannot determine
when the process is finished or whether it worked correctly. When you return to
this screen you can continue and complete the installation.

If there are any errors in creating the folder or it does not appear on your
desktop, you can create 4DOS desktop objects manually as described in the
INTRO.TXT file, in the section on using 4DOS under OS/2.
			endtext
			wait
		endiff
	endiff
	iff %_win ge 40 then
		iff exist jp4dossc.inf then
			sep
			text
The installer can create a JP Software program group for 4DOS, accessible
through the Windows 95/98/ME Start menu. The group will include shortcuts
to start 4DOS itself and the 4DOS help. The same process creates a desktop
shortcut for 4DOS (easily deleted if you prefer to use only the Start menu).

The JP Software group and related desktop shortcuts will also be made removable
using Windows 95/98/ME's Uninstall facility (available from the Control Panel's
Add / Remove Programs item).

If you choose not to create these items now, you can create shortcuts manually
as described in the INTRO.TXT file, in the chapter on installing 4DOS.
			endtext
			yesno yn Create a Win95/98/ME program group and desktop shortcut for 4DOS
			iff "%yn" == "Y" then
				instinf %[cd]jp4dossc.inf
				sep
				text
The process to create the 4DOS group and shortcuts has been started and should
be complete in a few seconds (this is a separate process and the installer
cannot determine when it is finished).

Installation will now continue. If there are any errors in creating the group
or shortcuts, or they do not appear on your Start menu or desktop, you can
create 4DOS shortcuts manually as described in the INTRO.TXT file, in the
section on using 4DOS under Windows 95/98/ME.
				endtext
				wait
			endiff
		endiff
		iff exist jp4dos.inf then
			sep
			text
The installer can install optional registry extensions for 4DOS. The registry
extensions customize a few Windows 95/98/ME functions to best take advantage of
features provided by 4DOS. Specifically, they:

   - Create a new "4DOS Prompt here" entry in the context menu of drives and
     directories, to launch 4DOS in that drive or directory.

   - Extend Windows' definition of a "batch file" to include BTM files.

   - Provide an additional "open" option in the context menu of all batch files
     (.BAT and .BTM), to run the file with 4DOS.

These registry extensions can be removed using Windows 95/98/ME's Uninstall
facility (available from the Control Panel under Add / Remove Programs).

If you choose not to install the registry extensions now, you can do so later
as described in INTRO.TXT, in the 4DOS installation chapter.
			endtext
			yesno yn Install 4DOS registry extensions
			iff "%yn" == "Y" then
				instinf %[cd]jp4dos.inf
				sep
				text
The process to install the 4DOS registry extensions has been started and should
be complete in a few seconds (this is a separate process and the installer
cannot determine when it is finished).

You can continue now and complete the installation.
				endtext
				wait
			endiff
		endiff
	endiff
	sep
	iff %csmod eq Y then
echo 4DOS installation is complete. The next time you reboot your system, 4DOS
echo will be used as the default %opsys command processor.
	else
		text
4DOS installation is complete. The CONFIG.SYS file was not updated. See the
file INTRO.TXT to find out what to do to ensure that 4DOS starts properly.
		endtext
	endiff
	iff %_win eq 40 then
		text

To start 4DOS from the Windows 95/98/ME desktop, use the shortcut or group
created during the installation process. If you did not allow the installer to
create a shortcut you can do so manually; instructions are in the INTRO.TXT
file, in the chapter on 4DOS installation.
		endtext
	endiff
	wait
:OPTION
	sep
	text
You can now start the 4DOS configuration command OPTION. It is used to
fine-tune many property settings of 4DOS, stored in the 4DOS.INI file:

   - memory usage: the size of meory allocated for variables, aliases and
     functions and which parts of 4DOS are loaded into UMBs or XMS

   - your color scheme

   - filename completion and extended directory search

   - the use of filename descriptions, logging, command history

and much more. If you do not want to do this now, you can do this anytime later
when you are ready by just typing "OPTION" at the command line.
	endtext
	yesno yn Run OPTION now?
	iff "%yn" eq "Y" then
		OPTION
		sep
		text
OPTION is now done. You can always make further configuration changes by
running OPTION from the command line.
		endtext
	else
		sep
		text
OPTION not started. You can always change the 4DOS configuration settings by
running OPTION from the command line.
		endtext
	endiff
	echo.
	echo You are now ready to use 4DOS.
	goto EXIT_NORETRY
:ON_ERROR
	on errormsg
	on break
	text

*** The installation stopped due to the above error. The installer will restart
the next time you start 4DOS.
	endtext
	goto DONE
:ON_BREAK
	on errormsg
	on break
	text

*** Installation was interrupted. The installer will restart the next time you
start 4DOS.
	endtext
	goto DONE
:FATALERR
	on errormsg
	on break
	text

*** Installation stopped due to the above error.

You will have to complete the installation manually. For instructions, please
see the chapter on 4DOS installation in the INTRO.TXT file.
	endtext
:EXIT_NORETRY
	on errormsg
	on break
	set bname="%@full[%0]"
	move %bname "%@path[%bname]\%@name[%bname].btx" >& nul
:DONE
	on errormsg
	on break
	if "%_jprr" eq "Y" (endlocal %+ quit)
	echo.
	pause Press any key to exit to the 4DOS prompt...
	endlocal
	quit
