;******************************************************************************
; Installation script for Gadget & Image Collection #1 (GI1)
; Written by David N. Junod
;******************************************************************************

; Initialize a few things
(set docbits 0)
(set ename "GI1_Examples")

;******************************************************************************
; Ask the user if we are installing or removing

(set mode
	(askchoice
		(prompt "Gadget & Image Collection #1")
		(help @askchoice-help)
		(choices "Install" "Remove")
	)
)

; Set the prompt string
(if mode
	(set pmode "Remove")
	(set pmode "Install")
)

;******************************************************************************
; Prompt for components and their directories

(set cbits
	(askoptions
		(prompt "Components to " pmode)
		(help @askoptions-help)
		(choices "Classes" "Examples" "Example source" "Include files" "Autodocs")
		(default 1)
	)
)

; Classes
(if (bitand cbits 1)
	(set classdir
		(askdir
			(prompt "Where do the Classes belong")
			(help @askdir-help)
			(default "SYS:Classes")
		)
	)
)

; Developer files
(if (bitand cbits 6)
	(set edir
		(askdir
			(prompt "Where does the " ename " directory belong")
			(help @askdir-help)
			(default "WORK:")
		)
	)
)

; Include files
(if (bitand cbits 8)
	(set incdir
		(askdir
			(prompt "Where do the Include files belong")
			(help @askdir-help)
			(default "INCLUDE:")
		)
	)
)

; Autodocs files
(if (bitand cbits 16)
	(
		(set docbits
			(askoptions
				(prompt "Autodocs formats to " pmode)
				(help @askoptions-help)
				(choices "Text" "AmigaGuide")
				(default 3)
			)
		)
		(if (bitand docbits 1)
			(set tdocdir
				(askdir
					(prompt "Where do the text-format Autodoc files belong")
					(help @askdir-help)
					(default "DOC:")
				)
			)
		)
		(if (bitand docbits 2)
			(set adocdir
				(askdir
					(prompt "Where do the AmigaGuide-format Autodoc files belong")
					(help @askdir-help)
					(default (getenv "amigaguide/path"))
				)
			)
		)
	)
)

;******************************************************************************
;******************************************************************************
;******************************************************************************

(if mode
        ;**********************************************************************
	; Remove
        ;**********************************************************************
	(
		; Are we supposed to remove classes
		(if (bitand cbits 1)
			(
				(working "Removing Classes")
				(delete (tackon classdir "gadgets/button.gadget"))
				(delete (tackon classdir "gadgets/calendar.gadget"))
				(delete (tackon classdir "gadgets/tabs.gadget"))
				(delete (tackon classdir "images/led.image"))
			)
		)

		; Are we supposed to remove examples
		(if (bitand cbits 2)
			(
				(working "Removing Examples")
				(delete (tackon edir "GI1_Examples/Button_Test") (infos))
				(delete (tackon edir "GI1_Examples/Calendar_Test") (infos))
				(delete (tackon edir "GI1_Examples/Tabs_Test") (infos))
				(delete (tackon edir "GI1_Examples/LED_Test") (infos))
			)
		)

		; Are we supposed to remove example source files
		(if (bitand cbits 4)
			(
				(working "Removing Example Source")
				(delete (tackon edir "GI1_Examples/Button_Test.c") (infos))
				(delete (tackon edir "GI1_Examples/Calendar_Test.c") (infos))
				(delete (tackon edir "GI1_Examples/Tabs_Test.c") (infos))
				(delete (tackon edir "GI1_Examples/LED_Test.c") (infos))
			)
		)

		(if (bitand cbits 6)
			(
				(delete (tackon edir ename) (infos))
			)
		)

		; Are we supposed to remove include files
		(if (bitand cbits 8)
			(
				(working "Removing Include files")
				(delete (tackon incdir "gadgets/button.h"))
				(delete (tackon incdir "gadgets/calendar.h"))
				(delete (tackon incdir "gadgets/tabs.h"))
				(delete (tackon incdir "images/led.h"))
				(delete (tackon incdir "gadgets/button.i"))
				(delete (tackon incdir "gadgets/calendar.i"))
				(delete (tackon incdir "gadgets/tabs.i"))
				(delete (tackon incdir "images/led.i"))
			)
		)

		; Are we supposed to remove text autodoc files
		(if (bitand docbits 1)
			(
				(working "Removing text-format Autodocs")
				(delete (tackon tdocdir "button_gc.doc") (infos))
				(delete (tackon tdocdir "calendar_gc.doc") (infos))
				(delete (tackon tdocdir "tabs_gc.doc") (infos))
				(delete (tackon tdocdir "led_ic.doc") (infos))
			)
		)

		; Are we supposed to remove AmigaGuide autodoc files
		(if (bitand docbits 2)
			(
				(working "Removing AmigaGuide-format Autodocs")
				(delete (tackon adocdir "button_gc") (infos))
				(delete (tackon adocdir "calendar_gc") (infos))
				(delete (tackon adocdir "tabs_gc") (infos))
				(delete (tackon adocdir "led_ic") (infos))
			)
		)

		; Don't want to use the confusing "Installation Complete" message
		; when what we really did was remove things...
		(message "The \"Gadget & Image Collection #1\" components "
			 "that you specified have been successfully removed")
		(exit (quiet))
	)

        ;**********************************************************************
	; Install
        ;**********************************************************************
	(
		; Are we supposed to install classes
		(if (bitand cbits 1)
			(
				; Make sure the class sub-directories exist */
				(makedir (tackon classdir "Gadgets"))
				(makedir (tackon classdir "Images"))

				; Install the classes
				(copylib
					(prompt "Copying button gadget")
					(help @copylib-help)
					(source "classes/gadgets/button.gadget")
					(dest (tackon classdir "Gadgets"))
					(confirm)
				)
				(copylib
					(prompt "Copying calendar gadget")
					(help @copylib-help)
					(source "classes/gadgets/calendar.gadget")
					(dest (tackon classdir "Gadgets"))
					(confirm)
				)
				(copylib
					(prompt "Copying tabs gadget")
					(help @copylib-help)
					(source "classes/gadgets/tabs.gadget")
					(dest (tackon classdir "Gadgets"))
					(confirm)
				)
				(copylib
					(prompt "Copying LED image")
					(help @copylib-help)
					(source "classes/images/led.image")
					(dest (tackon classdir "Images"))
					(confirm)
				)
			)
		)

		; Are we supposed to install Example files
		(if (bitand cbits 2)
			(
				(makedir (tackon edir ename) (infos))
				(copyfiles
					(prompt "Copying Examples")
					(help @copyfiles-help)
					(source "Examples")
					(dest (tackon edir ename))
					(pattern "~(#?.(c|c.info))")
					(confirm)
				)
			)
		)

		; Are we supposed to install Example source files
		(if (bitand cbits 4)
			(
				(makedir (tackon edir ename) (infos))
				(copyfiles
					(prompt "Copying Example source")
					(help @copyfiles-help)
					(source "Examples")
					(dest (tackon edir ename))
					(pattern "#?.(c|c.info)")
					(confirm)
				)
			)
		)

		; Are we supposed to install Include files
		(if (bitand cbits 8)
			(
				(copyfiles
					(prompt "Copying gadget headers")
					(help @copyfiles-help)
					(source "include/gadgets")
					(dest (tackon incdir "gadgets"))
					(pattern "~(#?.info)")
					(confirm)
				)
				(copyfiles
					(prompt "Copying image headers")
					(help @copyfiles-help)
					(source "include/images")
					(dest (tackon incdir "images"))
					(pattern "~(#?.info)")
					(confirm)
				)
				(copyfiles
					(prompt "Copying Intuition headers")
					(help @copyfiles-help)
					(source "include/intuition")
					(dest (tackon incdir "intuition"))
					(pattern "~(#?.info)")
					(confirm)
				)
			)
		)

		; Are we supposed to install text autodoc files
		(if (bitand docbits 1)
			(
				(copyfiles
					(prompt "Copying text-format Autodocs")
					(help @copyfiles-help)
					(source "Doc")
					(dest tdocdir)
					(all)
					(confirm)
				)
			)
		)

		; Are we supposed to install AmigaGuide autodoc files
		(if (bitand docbits 2)
			(
				(copyfiles
					(prompt "Copying AmigaGuide-format Autodocs")
					(help @copyfiles-help)
					(source "AGDoc")
					(dest adocdir)
					(all)
					(confirm)
				)
			)
		)
	)
)
