; Internet Amiga F1GP Championship datafile installer
; $VER: Make_IAF1GPC_Datafile 1.4 (4.10.98)
;
; Copyright © 1997-1998 Oliver Roberts

(if (= (exists "Env:Language") 1)
	(set @language (getenv "Language"))
)

;*****************
; English strings
;
(set #str-welcome (cat
	"1998/99 IAF1GPC F1GP-Ed Datafile Creator - Release 1.2 (10-Oct-98)\n\n"
	"This is more than just an initial installation utility.  You can "
	"(and should) use it at any time to make sure your datafile complies to the rules. "
	"This utility creates a new datafile by merging the datafile "
	"you usually use, with the offical championship datafile. Only the "
	"required settings to make your datafile comply with the IAF1GPC "
	"rules will be changed (all other settings will remain intact).")
)
(set #str-keeppalette (cat
	"Would you like to use the supplied in-game palette or keep your "
        "own custom palette? (the cars might look a bit strange when "
	"using your own custon palette)")
)
(set #str-series "Which championship series are you competing in?")
(set #str-getsrcfile (cat
	"Select the location and filename of your usual F1GP-Ed datafile:\n"
	"(if this is left blank, you'll just get a copy of the championship "
	"datafile)")
)
(set #str-notdata "That doesn't appear to be a F1GP-Ed datafile!\n\nInstallation failed.")
(set #str-getdestfile (cat
	"Select the location and filename of the datafile to be created. "
	"If the file already exists, it will be replaced!  If it does not "
	"exist, the prefix \".f1gp\" will be added to the filename, if "
	"necessary.")
)
(set #str-makedata "Making new datafile \"%s\" using your settings from \"%s\"")
(set #str-copydata "Making new datafile \"%s\" using default settings")
(set #str-nofile "You didn't specify a file!  Please try again.")
(set #str-notexist "The file you specified does not exist!  Please try again.")
(set #str-makefailed "Failed to make datafile - returncode: %ld")
(set #str-exit1 (cat
	"Installation complete.  New IAF1GPC complient datafile created in "
	"your \"%s\" drawer (filename \"%s\").\n\nYou should not make any "
	"changes to this datafile.  If you do need to change it, you must "
	"run it through this installer script to make sure it complies to "
	"the IAF1GPC rules.  Therefore, it's probably a good idea to install ")
)
(set #str-exit2 (cat
	"this installer script on your harddrive - just drag the drawer to the "
	"desired location using Workbench.\n\nSend general IAF1GPC queries to "
	"Markus.Kruggel@uni-duisburg.de.  If you have problems with the "
	"datafile or with this installer contact Oliver Roberts (oliver.roberts@iname.com)")
)

;*******
; BEGIN
;

(message #str-welcome)

(welcome)

(set #done 0)
(set #srcfile @default-dest)
(until #done
	(
		(set #srcfile
			(askfile
				(prompt #str-getsrcfile)
				(help @askfile-help)
				(default (pathonly #srcfile))
			)
		)
		(if (OR (= "" (fileonly #srcfile)) (exists #srcfile))
			(set #done 1)
			(message #str-notexist)
		)
	)
)
(if (<> "" (fileonly #srcfile))
	(if (NOT (= 6275 (getsize #srcfile)))
		(abort #str-notdata)
	)
)

(set #done 0)
(set #destfile #srcfile)
(until #done
	(
		(set #destfile
			(askfile
				(prompt #str-getdestfile)
				(help @askfile-help)
				(default (pathonly #destfile))
			)
		)
		(if (= "" (fileonly #destfile))
			(message #str-nofile)
			(set #done 1)
		)
	)
)
(if (NOT (exists #destfile))
	(if (OR (< (strlen (fileonly #destfile)) 5) (<> ".f1gp" (substr #destfile (- (strlen #destfile) 5))))
		(set #destfile (cat #destfile ".f1gp"))
	)
)
(set @default-dest (pathonly #destfile))
(if (= "" (fileonly #srcfile))
	(set #srcfile "")
)

(set #series
	(askchoice
		(prompt #str-series)
		(help @askchoice-help)
		(choices (if (< @installer-version 42) "Ace" "\x1b[2pAce") "Pro" "Beginner")
	)
)

(set #palette
	(askchoice
		(prompt #str-keeppalette)
		(help @askchoice-help)
		(choices (if (< @installer-version 42) "Keep" "\x1b[2pKeep") "Overwrite")
		(default 1)
	)
)

(set #rc
	(run ("makeicdata data/makeicdata.in \"%s\" \"%s\" %ld %ld" #srcfile #destfile #series #palette)
		(prompt (if (= "" #srcfile) (#str-copydata #destfile) (#str-makedata #destfile #srcfile)))
		(confirm)
		(help "")
	)
)
(if (<> 0 #rc)
	(abort (#str-makefailed #rc))
)

(set #icon (tackon @default-dest #destfile))
(if (NOT (exists (cat #icon ".info")))
	(
		(copyfiles
			(prompt #str-copydata)
			(source "data/datafile.info")
			(dest @default-dest)
			(newname (fileonly (cat #icon ".info")))
			(help @copyfiles-help)
		)
		(tooltype
			(prompt "")
			(help "")
			(dest #icon)
			(noposition)
		)
	)
)

(set #mcmd "")
(if (> (exists ("sys:Utilities/more")) 0) (set #mcmd  "sys:Utilities/more") )
(if (> (exists ("c:more")) 0) (set #mcmd  "c:more") )
(if (> (exists ("c:amigaguide")) 0) (set #mcmd  "c:amigaguide") )
(if (> (exists ("sys:Utilities/amigaguide")) 0) (set #mcmd  "sys:Utilities/amigaguide") )
(if (> (exists ("c:multiview")) 0) (set #mcmd "c:multiview") )
(if (> (exists ("sys:Utilities/multiview")) 0) (set #mcmd  "sys:Utilities/multiview") )

(if (<> "" #mcmd)
	(run (cat "run " #mcmd " ReadMe.txt"))
)

(if (< @installer-version 42)
	(
		(message (#str-exit1 (pathonly #destfile) (fileonly #destfile)) #str-exit2)
		(exit (quiet))
	)
	(exit (#str-exit1 (pathonly #destfile) (fileonly #destfile)) #str-exit2)
)
