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

(set #sub-dir "")		;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 installed, if not abort install
; #program - to check

(procedure P_ChkRun
  (if
    (= 0 (run ("cd SYS:\nWhich %s" #program)))
    ("")
    (abort
      (cat
	"You must install \"" #program "\" first!\n"
	"It must be accessible via the path.\n"
	"You can find it in the WHDLoad package."
      )
    )
  )
)

;----------------------------
; Wait for inserting disk
; IN:  #AD_disk - name of disk
; OUT: -

(procedure P_disk
  (askdisk
    (dest #AD_disk)
    (prompt ("\nInsert Disk \"%s\" in any drive !" #AD_disk))
    (help @askdisk-help)
  )
)

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

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

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

;----------------------------

(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 "Normal" "RomIcon" "NewIcon" "GlowIcon")
      (help @askchoice-help)
    )
  )
  (set #icon 0)
)
(select #icon
  (set #icon ("%s.inf" @app-name))
  (set #icon ("%s.romicon" @app-name))
  (set #icon ("%s.newicon" @app-name))
  (set #icon ("%s.glowicon" @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)
  )
)
(if
  (exists ("%s.info" #readme-file))
  (copyfiles
    (help @copyfiles-help)
    (source ("%s.info" #readme-file))
    (dest #dest)
  )
)
(if
  (= #sub-dir "")
  ("")
  (
    (set #dest (tackon #dest #sub-dir))
    (makedir #dest
      (help @makedir-help)
    )
  )
)

(set #vers
  (askchoice
    (prompt "\nWhich version of the game do you want\nto install?\n")
    (default 1)
    (choices "Amiga 500" "Amiga 1200")
    (help @askchoice-help)
  )
)

(select #vers
  (set #game "Gala500")
  (set #game "Gala1200")
)

;----------------------------

(set #AD_disk "The One (A)")
(P_disk)

(copyfiles
  (help @copyfiles-help)
  (source ("%s:" #AD_disk))
  (dest #dest)
  (pattern ("%s" #game))
)

;----------------------------

(if
  (= 1 #vers)
  (if
    (= 0 (run "xfddecrunch" (tackon #dest #game) ">con://///WAIT/CLOSE/AUTO"))
    ("")
    (abort "\"XFDDecrunch\" has failed")
  )
)

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

(exit)
