(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 #sub-dir "ccdat")		;sub directory containing data files
(set #readme-file "Readme")	;name of readme file
(set #cleanup "")		;files to delete after install

;---
; 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))
))

(procedure P_disk
 ((askdisk
	(prompt ("\n\n\nPlease insert %s disk %ld in any drive." @app-name #num))
	(help @askdisk-help)
	(dest #AD_disk)
	(assigns)
  )
  (copyfiles
	(help @copyfiles-help)
	(source ("%s:" #AD_disk))
	(dest #dest)
	(pattern "~(c|s|system-configuration|.info|disk.info|#?int#?|anim)")
)))


(set #program "WHDLoad")
(P_chkrun)

(set #program "Patcher")
(P_chkrun)

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

;---

(set #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 @default-dest (tackon #dest @app-name))

(set #dest @default-dest)
(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)
)

;---

(copyfiles
	(help @copyfiles-help)
	(source ("%s.slave" @app-name))
	(dest #dest)
)
(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 (= #sub-dir "")
    ("")
    ((set #dest (tackon #dest #sub-dir))
     (makedir #dest
	(help @makedir-help)
    ))
)
(copyfiles
	(help @copyfiles-help)
	(source ("OSEMUMODULE400.BIN"))
	(dest #dest)
)

;---
(set #game_ver
 (askchoice
	(prompt ("\nWould you like to install the\nIntro Animation of %s ?\n" @app-name))
	(help @askoptions-help)
	(choices "Yes" "No")
))

(set #AD_disk "CCIII")	(set #num 1)	(P_disk)

(if (= #game_ver 0)
    (copyfiles
	(help @copyfiles-help)
	(source "CCIII:")
	(dest #dest)
	(pattern "(intr#?|anim)")
    )
    (copyfiles
	(help @copyfiles-help)
	(source "anim")
	(dest #dest)
    )
)
(set #AD_disk "CCDAT")	(set #num 2)	(P_disk)

(run ("Assign \"ToPatch:\" \"%s\"" #dest))
(run ("Patcher -p%s.param" @app-name))
(run ("Assign \"ToPatch:\" Remove"))

;---

(run ("Delete %s ALL QUIET FORCE" #cleanup))

(exit)
