;************************************
;                            
; $VER:		ViewDIZ-Install 1.8
; $TAB:		8
; $AUTHOR:	©1997 By Mikael Lund
;
;************************************
(message
	 "\n!!! READ THIS BEFORE CONTINUING !!!\n\n"
	 "This installation script will check EVERYTHING that is required to use ViewDIZ. "
	 "If something in your system looks suspicious you will get a message. But don't worry - "
	 "it might be nothing - the script can't tell if you have installed enhancements that don't "
	 "look like the original commodore files.\n\n"
	 "REMEMBER: HELP-BUTTONS DON'T BREAK IF USED !"
)

(if (< (/ (getversion) 65536) 37) (abort @app-name" only runs under Kickstart 2.04 or above!"))
(if (< (/ (getversion) 65536) 39) (message "\n"@app-name" should run under Kickstart 2.04 - It have only been tested on Kickstart 3.0, though.\n\nIf you encounter any problems please mail me."))
(if (not (exists "ENV:"		(noreq))) (exit "You MUST have an ENV: directory - Reinstall Workbench!"))
(if (not (exists "ENVARC:"	(noreq))) (exit "You MUST have an ENVARC: directory - Reinstall Workbench!"))
(if (not (exists "FONTS:"	(noreq))) (exit "You MUST have a FONTS: directory - Reinstall Workbench!"))
(if (not (exists "LIBS:"	(noreq))) (exit "You MUST have a LIBS: directory - Reinstall Workbench!"))
(if (not (exists "C:Version"	(noreq))) (exit "You MUST have C:Version - Reinstall Workbench!"))

(if (exists "libs/rexxdossupport.library")
	(copylib
		(source "libs/rexxdossupport.library")
		(dest "libs:")
	)
)
(if (exists "libs/rexxreqtools.library")
	(copylib
		(source "libs/rexxreqtools.library")
		(dest "libs:")
	)
)
;**********************************
;
; Is the Rexx server running ?
;
;**********************************
(working "\nChecking if you have got an ARexx server running\n(This might take some time)\n")
(execute "c/Rexx?")

(if (not (exists "ENV:vd.temp"))
	(
		(run "sys:system/rexxmast")
		(message	"\nHmmm, Your ARexx server doesn't seem to be active.\n\n"
				"If you are sure you have one active, then just ignore this message and continue!\n"
		)
	)
	(delete "ENV:vd.temp")
)
;**********************************
;
; Install the special ANSI font.
;
;**********************************
(if (not (exists "fonts:jetterm/"))
    (copyfiles
	(source "fonts/")
	(dest "fonts:")
	(pattern "#?")
    )
)
;**********************************
;
; Copying ViewDIZ + commands
;
;**********************************
(set @default-dest "C:")
(copylib
	(source "C/ViewDIZ")
	(dest "C:")
)
(set #bin
	(askoptions
		(prompt "\nWhich external programs should be installed ?\n(Versions will be checked if duplicates are found)\n")
		(help	"To use ViewDIZ you will need some additional programs depending on which filetypes you wish to process.\n\n"
			"· Copy2Clip is required for the CLIP-option.\n"
			"· DMSdescript is required for DMS-processing.\n"
			"· MagicDIZ is required for IFF/GIF/JPG-processing.\n"
			"· Textract is required for TXT/NFO-processing.\n\n"
			"Not all required programs is included in this package - below is a list of other program you will need to process other filetypes:\n\n"
			"· LHA,LZX,ZIP,UNZIP Is required for Lha, LZx and ZIP archives.\n"
			"· DMS is required if you want to unpack a DMS-files to a disk.\n"
			"· XFDdecrunch is required for unpacking packed datafiles.\n\n"
			"The files will be copied to C: - You may move them to another destination as long as this is in the command path."
		)
		(choices	"MagicDIZ"
				"DMSdescript"
				"Textract"
				"Copy2Clip"
		)
		(default %1111)
	)
)
(if (IN #bin 0)	(copylib	(dest "c:")	(source "c/MagicDIZ")))
(if (IN #bin 1)	(copyfiles	(dest "c:")	(source "c/DMSdescript")))
(if (IN #bin 2)	(copylib	(dest "c:")	(source "c/Textract")))
(if (IN #bin 3)	(copylib	(dest "c:")	(source "c/Copy2Clip")))

;**********************************
;
; Copy Documentation.
;
;**********************************
(if (exists "HELP:" (noreq))
	(set #docdest "HELP:")
	(set #docdest "C:")
)
(set #bin
	(askoptions
	    (prompt "\nWhich documentation should be installed ?\n(Files will be copied to "#docdest")\n")
	    (help "Only the ViewDIZ documentation is important for using ViewDIZ - the rest is for advanced users who want to know more about the external commands!")
	    (choices	"ViewDIZ"
			"MagicDIZ"
			"Textract"
			"Copy2Clip"
			"Rexxdossupport (library)"
	    )
	    (default %00001)
	)
)
(if (IN #bin 0) (copylib	(dest #docdest) (source "doc/ViewDIZ.Guide")))
(if (IN #bin 1) (copyfiles	(dest #docdest) (source "doc/MagicDIZ.doc")))
(if (IN #bin 2) (copyfiles	(dest #docdest) (source "doc/Textract.doc")))
(if (IN #bin 3) (copylib	(dest #docdest) (source "doc/Copy2Clip.doc")))
(if (IN #bin 4) (copylib	(dest #docdest) (source "doc/RexxDosSupport.doc")))

;************************************
;
; Install Directory Opus 5+ buttons.
;
;************************************

(if (exists "dopus5:buttons" (noreq))
	(copyfiles
		(source "dopus5/buttons/ViewDIZ")
		(dest "dopus5:buttons")
	)
)

;**********************************
;
; Configuration Part.
; Shortcut to executable header &
; the filesubstitution, "{f}"
;
;**********************************

(message "\nThe following section will configure ViewDIZ after your personal needs. From v1.8+ a brand new configuration system is used - if you have got an older version or none at all, you MUST run this section.\n\n"
		 "WARNING: Existing files will be overwritten!\n")

(set	#header	".key f/a\n.bra {\n.ket }\n"
	#f	"\"{f}\""
)

;**********************************
;
; Customize text editor
;
;**********************************
(set #precmd "")
(set #bin
   (askchoice
	(prompt "\nWhat is your favourite texteditor ?\n")
	(help "ViewDIZ lets you chose which texteditor to be used when editing File_ID.DIZ descriptions. If you have installed the CygnusED Prog. package you should use 'CygnusED'. If you are in doubt which editor to use, then just select the Workbench Editor.\n\nNOTE: If you chose 'other' make sure that the texteditor doesn't detatch itself from CLI!")
	(choices "Workbench Editor (C:Ed)"
		 "CygnusED"
		 "Other"
	)
    )
)
(if (= #bin 0)
    (	(set #edfile "C:Ed" #options (cat #f " Window=CON:75/50/376/130/ViewDIZ-Editor/NOSIZE"))
	(if (< (getsize #edfile) 10000)
		(Message "\nYour C:Ed file seems a bit short! Are you sure it is the original Workbench Editor ?\n\nIf you are 110% then just forget this message and go ahead!\n")
	)
    )
)
(if (= #bin 1)
    (	(set #precmd "Stack 8000 >NIL:\n"
	     #cedbin
		(askchoice
			(help "As CygnusED will detatch itself from CLI it must be started with either the 'sticky' or 'keepio' option; which one depends on how you start CygnusED. CygnusED can be started by running the mainprogram or by using an activator which comes with the CygnusED program. The activator can sometimes behave a bit strange, so I recommend using the mainprogram.\n\nNOTE: A new updated activator can be found on Aminet - don't know if it's bugfree (?)")
			(prompt "\nHow should CygnusED be started ?\n")
			(choices "CED (Mainprogram)" "ED (Activator)")
		)
	)
	(if (= #cedbin 0)
		(set	#findprompt "\nPlease find the 'CED' program:\n"
			#options (cat #f " -keepio"))
		(set	#findprompt "Please find the 'ED' activator:"
			#options (cat #f " -sticky -keepio"))
	)
	(set #edfile
		(askfile
			(Prompt #findprompt)
			(help "The mainprogram is named 'CED' while the activator is named 'ED'")
			(default "C:")
		)
	)
    )
)
(if (= #bin 2)
    (
	(set #edfile
		(askfile
			(prompt "\nPlease select your favourite texteditor:\n")
			(help "Here you may select your favourite texteditor. IMPORTANT: The editor must NOT detatch itself from CLI. To check start a CLI-window and start your editor from there. If a new CLI-prompt is returned the editor 'detatches' itself from CLI and cannot be used.")
			(default "SYS:Utilities/")
		)
	)
	(set #options
		(askstring
			(prompt "\nPlease select arguments for "#prg"\n(Use {f} to substitute file send by ViewDIZ.)\n")
			(help "See manual for "#prg" to decide which arguments to use. {f} must ALWAYS be present as this substitutes the filename ViewDIZ will send to the editor. It is recommended to use double quotes around {f} to ensure filenames containing spaces.")
			(default #f)
		)
	)
    )
)
(textfile (dest "env/ViewDIZ/TXTedit.s") (append #header""#precmd"\""#edfile"\" "#options) )

;**********************************
;
; Customize text-reader
;
;**********************************
(set #bin
	(askchoice
		(prompt "\nWhat program do you want to use for reading text files ?\n")
		(help "ViewDIZ offers a \"READ\" button when textfiles are processed - You must chose which reader to be used.\nNOTE: The 'Type' viewer uses c:type and is real cool if you have got KingCON installed.")
		(choices "Multiview" "Amigaguide" "More" "Type :^)" "Other")
	)
)
(if (= #bin 0) (set #prg "SYS:Utilities/Multiview" #args #f))
(if (= #bin 1) (set #prg "SYS:Utilities/Amigaguide" #args #f))
(if (= #bin 2) (set #prg "SYS:Utilities/More" #args #f))
(if (= #bin 3) (set #prg "C:Type" #args (cat #f " >CON:0/0/2000/2000/ViewDIZ-Viewer/CLOSE/WAIT")))
(if (= #bin 4)
	(
		(set #prg
			(askfile (prompt "\nPlease chose textviewer:\n") (help "Chose your favourite textviewer!") (default "SYS:Utilities/"))
			#args
			(askstring
				(prompt "\nPlease select arguments for "#prg"\n(Use {f} to substitute file send by ViewDIZ.)\n")
				(help "See manual for "#prg" to decide which arguments to use. {f} must ALWAYS be present as this substitutes the filename ViewDIZ is processing. It is recommended to use double quotes around {f} to ensure filenames containing spaces.")
				(default #f)
			)
		)
	)
)

(textfile (dest "env/ViewDIZ/txtview.s") (append #header"\""#prg"\" "#args) )

;**********************************
;
; Customize graphic viewer
;
;**********************************
(set #bin
	(askchoice
		(prompt "\nWhat is your favourite Picture viewer ?\n")
		(help "ViewDIZ offers a \"VIEW\" button when pictures are processed - You must chose which viewer to be used.")
		(choices "Multiview" "Other")
	)
)
(if (= #bin 0) (set #prg "SYS:Utilities/Multiview" #args (cat #f " screen")))
(if (= #bin 1)
	(
		(set #prg
			(askfile (prompt "\nPlease chose Picture viewer:\n") (help "Select file with full path.") (default "SYS:Utilities/"))
			#args
			(askstring
				(prompt "\nPlease select arguments for "#prg"\n(Use {f} to substitute file send by ViewDIZ.)\n")
				(help "See manual for "#prg" to decide which arguments to use. {f} must ALWAYS be present as this substitutes the filename ViewDIZ is processing. It is recommended to use double quotes around {f} to ensure filenames containing spaces.")
				(default #f)
			)
		)
	)
)
(textfile (dest "env/ViewDIZ/gfxview.s") (append #header"\""#prg"\" "#args) )
(set #prg "" #args "")

;**********************************
;
; Customize music player
;
;**********************************
(set #bin
	(askchoice
		(prompt "\nWhat is your favourite music player ?\n")
		(help "ViewDIZ offers a \"PLAY\" button when musicfiles are processed - You must chose which player to be used. ViewDIZ recognices a lot of soundformats so you should select a multiplayer.")
		(choices "Delitracker" "Eagleplayer" "Hippoplayer" "Other")
	)
)
(if (= #bin 0) (set #musprompt "\nSelect the Delitracker directory:\n" #prg "delitracker2" #args (cat "module "#f)))
(if (= #bin 1) (set #musprompt "\nSelect the Eagleplayer directory:\n" #prg "eagleplayer" #args ""))
(if (= #bin 2) (set #musprompt "\nSelect the Hippoplayer directory:\n" #prg "hip" #args #f))
(if (<> #bin 3)
	(
		(set #precmd "")
		(set #prgpath
			(askdir
				(help "Select the directory where the player is installed. Etc. \"Work:Music/Delitracker_ii/\"")
				(prompt #musprompt)
				(default "Work:")
			)
		)
		(set	#precmd	(cat "cd \""#prgpath"\"\n")
			#prg	(tackon #prgpath #prg)
		)
	)
)
(if (= #bin 3)
	(
		(set #prg
			(askfile (prompt "\nPlease chose a musicplayer:\n") (help "Select the file with full path.") (default "Work:"))
			#args
			(askstring
				(prompt "\nPlease select arguments for "#prg"\n(Use {f} to substitute file send by ViewDIZ.)\n")
				(help "See manual for "#prg" to decide which arguments to use. {f} must ALWAYS be present as this substitutes the filename ViewDIZ is processing. It is recommended to use double quotes around {f} to ensure filenames containing spaces.")
				(default #f)
			)
		)
	)
)
(textfile (dest "env/ViewDIZ/musplay.s") (append #header""#precmd"\""#prg"\" "#args) )
(set #prg "" #args "")

;***********************************
;                            
; Customize DMS destination
;
;***********************************
(set #prg
	(askstring
		(prompt "\nWhich drives should be presented when unpacking DMS-files ?\n")
		(help "ViewDIZ offers an \"EXTRACT\" button when processing DMS-files (DiskMasher). If you press this button you are asked which drive you want to write to - These drives are chosen here. Each drive you select will appear as a button in ViewDIZ.\n\nNOTE: It is important that you use colon : after the device name, etc. df0:")
		(default "DF0: DF1: RAD: FF0: DM0:")
	)
)
(textfile	(append #prg)	(dest "ENV/ViewDIZ/DMSdest")	)

;**********************************
;
; Install Configuration.
; ...And delete older configs
;
;**********************************
(copyfiles
	(source "ENV/ViewDIZ")
	(dest "ENV:ViewDIZ")
	(pattern "#?")
)
(if (exists "ENV:ViewDIZ/")
    (copyfiles
		(source "ENV:ViewDIZ")
		(dest "ENVARC:ViewDIZ")
		(pattern "#?")
    )
)

(if (exists "ENV:ViewDIZ.config")
	(if	(=	(askbool
				(prompt "\nOlder ViewDIZ configuration file have been found !\n\nIt is no longer needed - would you like to have it deleted ?\n")
				(help "This configuration file is used by ViewDIZ v1.7 and below - as you now have a newer and much better version you might as well delete it!")
				(default 1)
			)
		1)
		((delete "ENV:ViewDIZ.config") (delete "ENVARC:ViewDIZ.config"))
	)
)
;**********************************
;
; Add 'resident' command to
; s:user-startup. Then make ViewDIZ
; resident (replace old)
; (DOS: 5 = err, 0 = ok)
;
;**********************************
(startup "ViewDIZ"
	(Prompt "\nViewDIZ can be made resident - This results in a faster appearance. Do you want to use this feature on bootup ?\n")
	(help "This will add a line to the file s:user-startup, so that ViewDIZ will be pre-loaded into memory at startup. This results in a faster appearance of ViewDIZ but it will cost you approx. 14k of memory.")
	(command "Resident C:ViewDIZ pure")
	(confirm)
)
(if (=	(run "Resident ViewDIZ C:ViewDIZ replace pure") 5)
	(run "Resident C:ViewDIZ pure")
)

(rexx "c/Popbutton!")
(exit	"\n\nEverything should be settled now! To get a quick view of the usage and functions of ViewDIZ start ViewDIZ from CLI with no arguments. For a more detailed explanation see the documentation - And just one more thing: You may run this script again if you wanna change your settings.\n\n"
	"Enjoy the program!\n")
