; Version history
; 0.4beta
;   Was copying TMiga instead of TMigaPre
;   Updated for TMiga's new command line
;   Now backs up existing Ed_Tag file
; 0.6
;   Substantial changes to Tag-o-Miga.  Therefore substantial changes
;   here!
; 0.62
;   Installs bgui.library
;   Replaced %s with @F
;   Copies icons (whoops!)
; 0.63
;   Makes directories in ENV[ARC]:
; 1.0alpha1
;   Copies documentation to chosen destination.  Filenames changed.
; 1.1.334
;   Fixed CygnusEd command line
;   Updated for new make_config that detects/updates old
;   installations
;   Removed BGUI

(set dirname
    (askdir
	(prompt "Select the directory where you want Tag-o-Miga to be "
		"placed.  A directory called TMiga will be created "
		"there.")
	(help @askdir-help)
	(default "MAIL:")
    )
)
(set @default-dest (tackon dirname "Tag-o-Miga"))

(makedir @default-dest
    (prompt "Making Tag-o-Miga directory...")
    (help @makedir-help)
    (infos)
)

(set prefstool
    (askchoice
	(prompt "Where do you want the preferences tool installed?")
	(help @askchoice-help)
	(choices "Tag-o-Miga's directory" "SYS:Prefs directory" "Somewhere else")
    )
)

(select prefstool
    ( ;0 = Tag-o-Miga's directory
	(set prefsdir @default-dest)
    )
    ( ;1 = SYS:Prefs
	(set prefsdir "SYS:Prefs")
    )
    ( ;2 = somewhere else
	(set prefsdir
	    (askdir
		(prompt "Select the directory where you want Tag-o-Miga's "
			"preferences tool to be placed.  A directory will "
			"NOT be created.")
		(help @askdir-help)
		(default @default-dest)
	    )
	)
    )
)

(set docs
    (askchoice
	(prompt "Where do you want the documentation installed?")
	(help @askchoice-help)
	(choices "Tag-o-Miga's directory" "HELP: directory" "Somewhere else" "Don't install documentation")
    )
)

(select docs
    ( ;0 = Tag-o-Miga's directory
	(set docsdir @default-dest)
    )
    ( ;1 = HELP:
	(set docsdir "HELP:")
    )
    ( ;2 = somewhere else
	(set docsdir
	    (askdir
		(prompt "Select the directory where you want "
			"Tag-o-Miga's documentation to be placed.  A "
			"directory will NOT be created.")
		(help @askdir-help)
		(default @default-dest)
	    )
	)
    )
    ( ;3 = don't install
       (set docsdir "")
    )
)

(copyfiles
    (prompt "Copying Tag-o-Miga...")
    (help @copyfiles-help)
    (source "Tag-o-Miga")
    (dest @default-dest)
    (infos)
)

(copyfiles
    (prompt "Copying Tag-o-Miga Preferences...")
    (help @copyfiles-help)
    (source "Tag-o-Miga-Prefs")
    (dest prefsdir)
    (infos)
)

(if (< docs 2)
    (copyfiles
	(prompt "Copying documentation...")
	(help @copyfiles-help)
	(source "Tag-o-Miga.guide")
	(dest docsdir)
	(infos)
    )
)

(copyfiles
    (prompt "Copying sample tagline file...")
    (help @copyfiles-help)
    (source "Taglines.txt")
    (dest @default-dest)
    (infos)
)

;(copylib
;    (prompt "Copying BGUI library...")
;    (help @copylib-help)
;    (source "bgui.library")
;    (dest "LIBS:")
;)

(working "Searching for old versions...")
(set configtest
    (run
	("make_config test")
	(safe)
    )
)
(select configtest
    ( ;0 = no config file
	(message "No configuration file found.  Creating new "
		 "configuration file.")
    )
    ( ;1 = invalid config file
	(message "Invalid configuration file found.  Creating "
		 "new configuration file.")
    )
    ( ;2 = 1.0 config file
	(message "Found configuration file for Tag-o-Miga 1.0.  "
		 "Converting to new file format.")
    )
    ( ;3 = 1.1 config file
	(message "Found configuration file for Tag-o-Miga 1.1.  "
		 "Preserving original file format.")
    )
)

(if (< (exists "ENV:Tag-o-Miga") 2)
    (makedir "ENV:Tag-o-Miga"
	(prompt "Creating configuration drawer...")
	(help @makedir-help)
    )
)

(if (< (exists "ENVARC:Tag-o-Miga") 2)
    (makedir "ENVARC:Tag-o-Miga"
	(prompt "Creating configuration drawer...")
	(help @makedir-help)
    )
)

(if (< configtest 2) (
    (set editor
	(askchoice
	    (prompt "Which text editor do you use?")
	    (help @askchoice-help)
	    (choices "Commodore ED" "Commodore MEmacs" "GoldED" "CygnusEd" "other")
	)
    )
    (select editor
	( ;0 = Commodore ED
	    (set editstring "C:Ed @F")
	)
	( ;1 = Commodore MEmacs
	    (set editstring "SYS:Tools/MEmacs @F")
	)
	( ;2 = GoldED
	    (set editstring "GoldED:ED @F STICKY")
	)
	( ;3 = CygnusEd
	    (set editstring "C:Ed @F -keepio")
	)
	( ;4 = other
	    (set editstring
		(askstring
		    (prompt "Enter the command to start your editor")
		    (help @askstring-help)
		    (default "C:Ed %s")
		)
	    )
	)
    )
    (if (AND (>= @user-level 2) (<> editor 4)) (
	(set newstring
	    (askstring
		(prompt "The editor command is believed to be as shown below.  "
			"If this is incorrect please correct it.")
		(help @askstring-help)
		(default editstring)
	    )
	)
	(set editstring newstring)
    ))

    (working "Generating configuration file...")
    (run ("make_config \"%s\" \"%s\"" @default-dest editstring))
))

(if (= configtest 2) (
    (working "Converting old configuration file...")
    (run ("make_config update"))
))

(exit
    "Installation has been completed.  You must now modify your message "
    "editor's configuration as described in the user guide."
)
