; ************************************************
; *
; * $VER: Install-HP v1.0.0 (26.03.93)
; *
; * This is the installation script for ASDG's ADPro/MorphPlus
; * HP_SCAN loader module and HP_SCAN_ToDisk program.
; *
; * Copyright © 1993 ASDG Incorporated  All Rights Reserved
; *
; * v1.0.0 -	Initial version of installation script.
; *
; ************************************************
;


; ****************************
; * Set up some global variables.
; ****************************
;
(set ProductName	"HP ScanJet IIc Color Scanner Driver")	; product name
(set ModuleName		"HP_SCAN")			; module name
(set ToDiskName		"HP_SCAN_ToDisk")		; direct-to-disk name
(set VersionNum		"1.0.0")			; version number

(set OSVersion		(/ (getversion) 65536))
(set TotalFiles		0)
(set AccumFiles		0)
(set PctDone		0)
(set DisplayReadMe	0)

(set Disk1Name		"HP_ScanJet")			; actual name of disk 1
(set DiskInstall	Disk1Name)			; installation (main) disk




(procedure setPkgOpts
;
; ****************************
; * Ask the user which parts of the package should be installed.
; ****************************
;
	(
	(set PkgOpts
		(askoptions
			(prompt	("Select the parts of the %s package you want to install at this time." ProductName))
			(help	("This part of the installation procedure lets you select the parts of the %s package you want to install at this time.\n\n" ProductName)

				("*** %s Loader module\n" ModuleName)
				"This option lets you install the ADPro/MorphPlus loader module, which lets you scan directly from the ADPro or MorphPlus program.\n\n"

				"NOTE: You must own ADPro 2.0.4 or later to use this module.  Please call us for upgrade information if you have a version earlier than this.\n\n"

				("*** %s program\n" ToDiskName)
				"This option lets you install the stand-alone (does not require ADPro nor MorphPlus) version of the scanner controller software.  Select "
				"this option if you do not own either product.\n\n"

				@askoptions-help
			)
			(choices
				; bit position 0 -- todo & 1
				;
				("%s Loader module" ModuleName)

				; bit position 1 -- todo & 2
				;
				("%s program" ToDiskName)
			)
		)
	)
	)
)




;+++(procedure setCPUOpts
;; ****************************
;; * Ask the user which version of the package should be installed.
;; ****************************
;	(
;	(set CPUStr (database "cpu"))
;	(if (OR (= CPUStr "68020") (= CPUStr "68030") (= CPUStr "68040"))
;		(set CPUOpts	1)
;		(set CPUOpts	0)
;	)
;
;	(set CPUOpts
;		(askchoice
;			(prompt	"Select the version of the programs you wish to install, based upon the type of CPU installed in your Amiga.")
;			(help	("If you are installing the %s package onto an accelerated Amiga, then there are special versions " ProductName)
;				"many of the files which you should install.\n"
;				"\n"
;				"If you are unsure about which choice to select, use the following as a guide:\n"
;				"\n"
;				"A500/A600/A1000/A1200/A2000:\n"
;				"   Stock                  68000/68010 CPU\n"
;				"   Accelerated (68020+)   68020/68030/68040 CPU\n"
;				"\n"
;				"A2500/A3000/A4000:\n"
;				"   Stock or Accelerated   68020/68030/68040 CPU\n"
;				"\n"
;				"NOTE: If you are installing the 68020/030/040 version, then you MUST have a math coprocessor "
;				"properly activated.  Otherwise, the FPU-specific modules will likely not work at all.\n"
;				"\n"
;				@askoptions-help)
;			(choices
;				; bit position 0 -- todo & 1
;				"68000/68010 CPU"
;
;				; bit position 1 -- todo & 2
;				"68020/68030/68040 CPU"
;			)
;			(default CPUOpts)
;		)
;	)
;	)
;)




(procedure setDirPath
;
; ****************************
; * Ask the user for a directory name.
; ****************************
;
; these variables must be defined before calling this procedure:
;    setDirPathWhy
;    setDirPathHelp
;    DirPath
;
; this procedure returns the selected directory in DirPath
;
	(
	(set moveon FALSE)
	(while (NOT moveon)
		(
		(set DirPath
			(askdir
				(prompt	("Please select the directory %s" setDirPathWhy)
				)
				(help	setDirPathHelp 
					"\n"
					@askdir-help
				)
				(default DirPath)
			)
		)

		(if (= (exists DirPath) 0)
			(makedir DirPath)
			(set moveon TRUE)
		)
		)
	)
	)
)




(procedure copyLibFile
;
; ****************************
; * Copy the specific library file to the LIBS: directory.
; ****************************
;
; these variables must be defined before calling this procedure:
;    copyLibFileName
;    copyLibFileHelp
;    DirPath
;
	(
	(copylib
		(prompt	("Copying %s to %s" copyLibFileName copyLibFileSize DirPath))
		(help	copyLibFileHelp
			"\n"
			"If you already have a copy of this library in the selected destination directory, the library "
			"included on the distribution disk will be compared to the one you "
			"already have.  If your current library is an old version, the newer "
			"version will be installed.\n"
			"\n"
			@copylib-help
		)
		(source copyLibFileName)
		(dest DirPath)
		(confirm)
	)
	)
)




(procedure incrementMeter
;
; ****************************
; * Increment the progress meter indicator.
; ****************************
;
;    addToMeter
;
	(
	(set PctDone (/ (* AccumFiles 100) TotalFiles))
	(set AccumFiles (+ AccumFiles addToMeter))
	(complete PctDone)
	)
)




; ****************************
; * Loader Module Installation routine
; ****************************
;
(procedure HPModuleInstall
	(
	(makeassign "HPINSTALL" ADProDir)

	; ****************************
	; * Install the Loader
	; ****************************
	;
	(set addToMeter 1)
	(incrementMeter)

	(set srcModuleName ("%s:Loaders2/%s" DiskInstall ModuleName))
;+++	(if (= CPUOpts 1)
;		(
;		(set srcModuleName (cat srcModuleName ".020"))
;		)
;	)

	(copyfiles
		(prompt		("Installing %s Loader..." ModuleName))
		(help		"")
		(source		srcModuleName)
		(dest		"HPINSTALL:Loaders2")
		(newname 	ModuleName)
	)

	; ****************************
	; * copy adpro.library to the ADPRO: directory.
	; ****************************
	;
	(set addToMeter 1)
	(incrementMeter)

	(set copyLibFileName	("%s:Libs/adpro.library" DiskInstall))
	(set copyLibFileHelp	("This library is required to run the %s modules.\n" ModuleName))
	(set DirPath		ADProDir)
	(copyLibFile)

	; ****************************
	; * copy req.library to the LIBS: directory.
	; ****************************
	;
	(set addToMeter 1)
	(incrementMeter)

	(set copyLibFileName	("%s:Libs/req.library" DiskInstall))
	(set copyLibFileHelp	("This library is required to run the %s modules.\n" ToDiskName))
	(set DirPath		"LIBS:")
	(copyLibFile)
	)
)




; ****************************
; * DirectToDisk Program Installation routine
; ****************************
;
(procedure HPToDiskInstall
	(
	(makeassign "HPINSTALL" ToDiskDir)

	; ****************************
	; * Install the ToDisk Program
	; ****************************
	;
	(set addToMeter 2)
	(incrementMeter)

	(set srcToDiskName ("%s:ToDisk/%s" DiskInstall ToDiskName))
;+++	(if (= CPUOpts 1)
;		(
;		(set srcToDiskName (cat srcToDiskName ".020"))
;		)
;	)

	(copyfiles
		(prompt		("Installing %s program..." ToDiskName))
		(help		"")
		(source		srcToDiskName)
		(dest		"HPINSTALL:")
		(newname	ToDiskName)
		(infos)
	)

	; ****************************
	; * copy req.library to the LIBS: directory.
	; ****************************
	;
	(set addToMeter 1)
	(incrementMeter)

	(set copyLibFileName	("%s:Libs/req.library" DiskInstall))
	(set copyLibFileHelp	("This library is required to run the %s modules.\n" ToDiskName))
	(set DirPath		"LIBS:")
	(copyLibFile)
	)
)




; ****************************
; * General CleanUp routine
; ****************************
;
(procedure cleanUp
	(
	; ****************************
	; * remove temporary assignment
	; ****************************
	;
	(makeassign "HPINSTALL")

	; ****************************
	; * exit the program.
	; ****************************
	;
	(complete 100)

	(if (= DisplayReadMe 1)
		(
		(if (< OSVersion 37)
			(run ("c:run %s:C/More %s:ReadMe" DiskInstall DiskInstall))
			(run ("run %s:C/More %s:ReadMe" DiskInstall DiskInstall))
		)
		)
	)

	(exit)
	)
)




; *************************************************************************
; *                         ACTUAL START OF SCRIPT
; *
; * Ask all questions for the user now, do all of the work later.
; *************************************************************************
;

(onerror
	(cleanUp)
)

; ****************************
; * set the default destination to ADPRO: (if exists) or SYS:ADPro (if it doesn't).
; ****************************
;
(if (= (getassign "ADPRO" "a") "")
	(set @default-dest "SYS:ADPro")
	(set @default-dest (getassign "ADPRO" "a"))
)
;(set @default-dest "SYS:ADPro")

(setPkgOpts)
;+++(setCPUOpts)


; ****************************
; * if (PkgOpts & 0), ask the user where to install the modules,
; * but don't actually do it yet.
; ****************************
;
(if (IN PkgOpts 0)	; if bit position 0 is on
	(
	(set TotalFiles (+ TotalFiles 2))		; adpro.library, req.library

	(set setDirPathWhy	"where the ADPro or MorphPlus program is located.")
	(set setDirPathHelp 	"This part of the installation is asking in which directory the ADPro or MorphPlus program is located.\n")
	(set DirPath		@default-dest)
	(setDirPath)
	(set ADProDir		DirPath)

	(set @default-dest	ADProDir)

	(set TotalFiles (+ TotalFiles 1))		; 1 loader

	(onerror)
	)
)


; ****************************
; * if (PkgOpts & 1), ask the user where to install the
; * ToDisk program, but don't actually do it yet.
; ****************************
;
(if (IN PkgOpts 1)	; if bit position 1 is on
	(
	(set setDirPathWhy	("where you want to install the %s program." ToDiskName))
	(set setDirPathHelp	("You must select a directory into which the %s program will be installed.\n" ToDiskName))
	(set DirPath		@default-dest)
	(setDirPath)

	(set ToDiskDir		DirPath)

	(set TotalFiles (+ TotalFiles 3))		; 1 program + 1 icon + req.library
	)
)


(complete 0)

(message "\nShall I proceed with the installation?"
	(help	"Once you press the Proceed button, the selected items will be installed.  This is your last chance "
		"to abort this procedure without partially installing the selected files.\n"
		"\n"
		"After you press Proceed, you can use the Esc key to abort the installation procedure.\n")
)


(onerror
	(cleanUp)
)


(if (IN PkgOpts 0)
	(HPModuleInstall)
)
(if (IN PkgOpts 1)
	(HPToDiskInstall)
)

(set DisplayReadMe	1)
(cleanUp)
