(set #readme-file "README")	;name of readme file
(set #cleanup "")		;files to delete after install
(set #last-file "Disk.1")	;last file the imager should create
(set #diskname "Coverdisk 18")	;name of requested dos disk

;---
; Checks if given program is reachable via the path
; if not abort install
; IN:  #program - to check
; OUT: -

(procedure P_chkrun
 (if (= 0 (run ("cd SYS:\nWhich %s" #program)))
     ("")
     (abort ("You must install \"%s\" first !\nIt must be accessible via the path.\nYou can find it in the whdload package." #program))
))

;---

(if (exists #readme-file)
    (if	(= 0 (run ("SYS:Utilities/Multiview %s" #readme-file)))
	("")
	(run ("SYS:Utilities/More %s" #readme-file))
    )
)
(set #program "WHDLoad")
(P_chkrun)

;---

(if	(exists "Games:" (noreq))
	(set @default-dest "Games:")
	(if	(exists "SYS:Games" (noreq))
		(set @default-dest "SYS:Games")
		(if	(exists "Work:Games" (noreq))
			(set @default-dest "Work:Games")
			(if	(exists "JEUX:" (noreq) )
				(set @default-dest "JEUX:")
				(set @default-dest "SYS:")
			)
		)
	)
)
(set #game_ver
 (askchoice
	(prompt ("\nWhich version of \"%s\"\nwould you like to install ?\n" @app-name))
	(help @askoptions-help)
	(choices "Original Release" "Amiga Format Release")
 )
)
(if (= #game_ver 0)
 ((set #program "Patcher")
  (P_chkrun)

  (if (= @user-level 2)
    ((set #CI_drive
      (askchoice
	(prompt "\nSelect source drive for diskimages\n")
	(default 0)
	(choices "DF0:" "DF1:" "DF2:" "DF3:")
	(help @askchoice-help)
     ))
     (select #CI_drive
	(set #CI_drive "DF0:")
	(set #CI_drive "DF1:")
	(set #CI_drive "DF2:")
	(set #CI_drive "DF3:")
    ))
    (set #CI_drive "DF0:")
)))

(set @default-dest
 (askdir
	(prompt ("Where should \"%s\" installed ?\nA drawer \"%s\" will automatically created." @app-name @app-name))
	(help @askdir-help)
	(default @default-dest)
	(disk)
  )
)
(set #dest (tackon @default-dest @app-name))

(if (exists #dest)
    ((set #choice
      (askbool
	(prompt ("\nDirectory \"%s\" already exists.\n Should it be deleted ?" #dest))
	(default 1)
	(choices "Delete" "Skip")
	(help @askbool-help)
     ))
     (if (= #choice 1)
	 (run ("Delete \"%s\" \"%s.info\" All" #dest #dest))
    ))
)
(makedir #dest
	(help @makedir-help)
	(infos)
)

;---

(if (exists ("%s.newicon" @app-name))
    (set #icon
	(askchoice
		(prompt "\nWhich icon would you like to install ?\n")
		(default 0)
		(choices "RomIcon" "NewIcon")
		(help @askchoice-help)
	)
    )
    (set #icon 0)
)
(select #icon
	(set #icon ("%s.inf" @app-name))
	(set #icon ("%s.newicon" @app-name))
)
(copyfiles
	(help @copyfiles-help)
	(source #icon)
	(newname ("%s.info" @app-name))
	(dest #dest)
)
(if (exists #readme-file)
    (copyfiles
	(help @copyfiles-help)
	(source #readme-file)
	(dest #dest)
	(infos)
    )
)

;---

(if (= #game_ver 0)
   ((copyfiles
	(help @copyfiles-help)
	(source  ("%s.slave" @app-name))
	(dest #dest)
    )
    (run ("Assign \"%s:\" \"%s\"" @app-name #dest))
    (run ("Patcher -p%s.imager -s%s" @app-name #CI_drive))
    (run ("Assign \"%s:\" Remove" @app-name))

    (if	(exists (tackon #dest #last-file))
	("")
	(abort "Diskimaging not successful !\nThe Patcher could'nt create all needed files !")
   ))
)

;---

(if (= #game_ver 1)
   ((copyfiles
	(help @copyfiles-help)
	(source ("%sAF.slave" @app-name))
	(dest #dest)
	(newname ("%s.slave" @app-name))
    )
    (copyfiles
	(help @copyfiles-help)
	(source "OSEMUMODULE400.BIN")
	(dest #dest)
    )
    (askdisk
	(prompt	("\n\n\nPlease insert Amiga Format %s in any drive" #diskname))
	(dest #diskname)
	(help ("Insert %s in any floppy drive or you'll wait for a while !!!" #diskname))
	(assigns)
    )
    (copyfiles
	(source ("%s:" #diskname))
	(dest #dest)
	(pattern "(Int|IntLoad)")
   ))
)

;---

(run ("Delete %s ALL QUIET FORCE" #cleanup))    ;delete temporary files

(exit)
