;$VER: Twist_2 2.08 (13.12.94)
;Twist  Installation script - Richard, Munged by Alex
;*catch any errors and pass dos errors to a message screen
;*if a dos problem occured
(onerror
(USER 2)
(IF (> @ioerr 0)
(Message ("\n\nA Dos Error %ld has occured" @ioerr)
"\n\n\n\nPlease consult your Workbench manual"
(" for further details, or type Fault %ld from a shell." @ioerr))
)
)
(SET DEFAULT-USER @user-level)
;*set version - true if greater than version 37
(SET WBVer (< 2424832 (getversion "exec.library" (resident))))

;*0 floppy 1 hard disk 2 if hard disk and floppy
(PROCEDURE MEDIA
(USER 2)
(SET MEDIA
	(Askchoice
	(Help @askchoice-help)
	(Prompt "Select installation you require?")
	(Choices "Floppy disk" "Hard disk")
	(Default 1))
)
(user DEFAULT-USER)
)
(PROCEDURE DELETEFILES
(SET x 0)
(while (SET DELETEFILE (select x "Devs/narrator.Device"
"Devs/ramdrive.Device" "L/Speak-Handler" "L/CrossDOSFileSystem"
"L/FastFileSystem" "Libs/mathtrans.Library" "Libs/Translator.Library"
"Libs/mathieeesingtrans.Library" "C/DiskDoctor" "C/Ed" "C/Search"
"C/Avail" "C/Status" "C/Sort" "C/Join" "C/Lock" "C/Edit"
"C/Which" "C/Protect" "C/Relabel" "C/RemRAD" "System/InitPrinter"
"System/FixFonts" "System/MergeMem" "System/NoFastMem"
""))
	(
	(SET x (+ x 1))
	(IF (= (exists ("DF0:%s" DELETEFILE)) 1)
		(delete ("DF0:%s" DELETEFILE) (optional "force") (safe))
  	)
	(IF (= (exists ("DF0:%s.info" DELETEFILE)) 1)
		(delete ("DF0:%s.info" DELETEFILE) (optional "force") (safe))
  	)
	)
)
)

(procedure fixmistake
(User 2)
(if (AND (= media 1) (> (getversion "exec.library" (resident)) 2555904) 
	(< (getversion "exec.library" (resident)) 2614886)
	(> (getversion "Libs:DataTypes.Library") 2621440))
(
(set fixdatatypes
(askchoice 
(prompt
"A previous installation has incorrectly updated the datatype files"
" should the installer replace the files with the correct versions on your"
" Workbench disks?") 
(help @askoptions-help)
(choices "Fix DataTypes" "Do not fix DataTypes")
(default 0))
)

(if (= fixdatatypes 0)
(

(Message "Insert your Workbench 3.0 disk in DF0: and select proceed")

(copyfiles
(source "DF0:Libs/datatypes.library")
(dest "Libs:")
(optional "force")
)

(set path "SYS:Classes/DataTypes")
(foreach "DF0:Classes/DataTypes" "#?.datatype"
	(
	(IF (= (exists ("%s/%s" path @each-name)) 1)
		(

		(copyfiles
		(source ("DF0:Classes/DataTypes/%s" @each-name))
		(dest path)
		(optional "nofail")

		)
		)
	)
	)
)

)
)

)
)

(user default-user)

)


(PROCEDURE MAIN
(USER 2)
(if (= media 0)
(
(Message "\nInsert the Workbench disk you want to use as a Twist boot"
" disk in DF0:(internal) and the backup copy of your Twist"
" master disk in any other drive"
)

(if (= WBVer 0)
(
(PROCEDURE PATCHER
(textfile
(DEST ("%s" PATCHFILE))
(Append "M1; F/LoadWB/; I\n")
(Append "IF EXISTS S:User-Startup\n")
(Append "   Execute S:User-Startup\n")
(Append "EndIF\n\n")
(Append "Z\n")
)
(rename FILETOBEPATCHED (cat FILETOBEPATCHED ".bak"))
(Run ("Edit from %s.bak with %s to %s" FILETOBEPATCHED PATCHFILE FILETOBEPATCHED))
(delete PATCHFILE)
)
(SET PATCHFILE "RAM:Patchfile")
(SET FILETOBEPATCHED "DF0:S/Startup-Sequence")
(PATCHER)
)
)

(DELETEFILES)

(copylib
(source "Twist2:Libs/rct.library")
(dest "DF0:Libs")
(optional "askuser")
)

(copylib
(source "Twist2:Libs/iffparse.library")
(dest "DF0:Libs")
(optional "askuser")
)


(copyfiles
(source "Twist2:S/User-Startup")
(dest "DF0:S")
(optional "askuser")
)

(if (= WBVer 1)
(

(copylib
(source "Twist2:Libs/asl.library")
(dest "DF0:Libs")
(optional "askuser")
)

(if (< (getversion "exec.library" (resident)) 2490368)
	(set file "Twist2:SetPatch37/SetPatch")
	(set file "Twist2:SetPatch40/SetPatch")
)

	(copylib
	(source file)
	(dest "DF0:C")
	(optional "askuser")
	)
)
)

(makeassign "Twist" "Twist2:Twist")
(makeassign "TwistIcon" "Twist:Icons")
(set APP_DEST "Floppy")
)
)


(if (= media 1)
(

(SET APP_DEST
(tackon
(askdir
(prompt "Select the location for the Twist Drawer")
(help @askdir-help)
(default @default-dest))
"Twist")
)

(IF (<> (exists APP_DEST) 2)
(Makedir APP_DEST (infos))
)
(MAKEASSIGN "Twist" APP_DEST)

(copyfiles
(source "Twist2:Twist/")
(dest APP_DEST)
(all)
)

(MAKEASSIGN "TwistIcon" "Twist:Icons")

(copyfiles
(source "Twist2:ReadMe")
(dest APP_DEST)
(infos)
)

(if (= WBVer 1)
(

(copylib
(source "Twist2:Libs/asl.library")
(dest "Libs:")
(optional "askuser")
)

(if (< (getversion "exec.library" (resident)) 2490368)
	(set file "Twist2:SetPatch37/SetPatch")
	(set file "Twist2:SetPatch40/SetPatch")
)

	(copylib
	(source file)
	(dest "C:")
	(optional "askuser")
	)


)
)


(copylib
(source "Twist2:Libs/iffparse.library")
(dest "Libs:")
(optional "askuser")
)


(copylib
(source "Twist2:Libs/rct.library")
(dest "Libs:")
(optional "askuser")
)

(askdisk
(Prompt "\n\nPlease insert Twist installation disk 2 (examples) in any drive")
(help @askdisk-help)
(DEST "Twist2_Disk2")
)

(copyfiles
(source "Twist2_Disk2:Examples/")
(dest APP_DEST)
(all)
)

(askdisk
(Prompt "\n\nPlease insert the Twist installation disk 1 in any drive")
(help @askdisk-help)
(DEST "Twist2")
)

(startup "Twist 2"
(Prompt "Place Twist paths/assigns in the user-startup?")
(help @startup-help)
(Command
("Assign Twist: \"%s\"\n" APP_DEST)
"Assign TwistIcon: Twist:Icons\n"
)
)

)
)

(procedure GETNAME
(set NAME
(askstring
(prompt "Enter the name you want to place"
" in the the Twist registration box (Max 39 characters)")
(help "")
)
)
)

(GETNAME)

(while (>= (strlen NAME) 40)
(
(Message "The name entered is too long please re-enter it")
(GETNAME)
)
)


(procedure serial
(set SERIALNUMBER
(askstring
(prompt "Please enter the serial number on your Twist master disk")
(help "")
)
)
)

(SERIAL)

(while (AND (<> (substr SERIALNUMBER 9 0) "-") (<> (strlen SERIALNUMBER) 14))
(
(Message "The serial number entered is incorect please re-enter it")
(SERIAL)
)
)

(set processor
(database "cpu")
)
(set chipmem
(database "graphics-mem")
)
(set totalmem
(database "total-mem")
)
(set hertz
(database "vblank")
)
(set fastmem
(- (totalmem) (chipmem))
)
(set file "Twist2:Install-Twist")
(set Version
(getversion file)
)
(Set Ver
(/ Version 65536)
)
(set Rev
(- version (* ver 65536))
)
(set exec
(getversion "exec.library" (resident))
)

(textfile
(dest "Twist:TechSupportDetails")
(Append ("Media is %ld\n" MEDIA))
(Append ("APP DEST is %s\n" APP_DEST))
(Append ("WBVer is %ld\n" WBVER))
(Append ("%ld %ld %ld\n" Version Ver Rev))
(Append ("Processor is a %s\n" processor))
(Append ("Chip Memory available is %s\n" chipmem))
(Append ("Fast Memory available is %ld\n" fastmem))
(Append ("Total Memory available is %s\n" totalmem))
(Append ("Exec version is %ld\n" exec))
(Append ("%s\n" NAME))
(Append ("%s" SERIALNUMBER))
)

(run ("run Twist:Twist2 \"-serialvs:%s|%s\"" NAME SERIALNUMBER))

)

;***********************Introduction**************************
(PROCEDURE INTRODUCTION
(USER 2)
(message "\n Welcome to the installation utility for \nTwist 2 \n"
"\n\nTo ensure proper installation on a hard disk, it is important that"
" you boot from your hard drive before using the installation utility!"
)
(user DEFAULT-USER)
)
;****************************bye bye************************
(PROCEDURE BYE
(USER 2)
(Message "Twist 2 Installation is complete."
"\nTo obtain your 30 days free technical support and notification of"
" Twist 2 updates, please complete your registration card and return"
" it to:-\n\n"
;* text starts at * and ends at *                   *
"            North America          Rest of world    \n"
"           Oregon Research            HiSoft        \n"
"           9880 SW Pembrook       The Old School    \n"
"               Tigard               Greenfield      \n"
"               Oregon               Bedford, UK     \n"
"               97224                 MK45 5DE       \n"
"Phone:    +1 503 620 4919         +44 525 718181    \n"
" FAX:     +1 503 624 2940         +44 525 713716    \n")
(Message "Please remember, UK technical support is\n between 2-3p.m."
" Mon-Fri\nIf you need technical support, please remember to have when you"
" phone, your:-\nSerial Number\nSoftware version number\nMachine"
" configuration (RAM,Processor,Hard disk etc.)\n\n Please also have a"
" clear and concise description of the problem you are having to ensure"
" that we can deal with your problem as quickly as possible.\n\n"
" Select Proceed to quit to Workbench")
(IF (AND (= WBVer 1) (= media 1) (= (exists "SYS:Utilities/Multiview") 1))
	(Run "Run SYS:Utilities/Multiview Twist2:ReadMe" (safe))
	(Run "Run SYS:Utilities/More Twist2:ReadMe" (safe))
)
(Exit (quiet))
)
;**************************do ya stuff*********************************
(INTRODUCTION)
(MEDIA)
(fixmistake)
(MAIN)
(BYE)
