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

(set #readme-file "README")	;name of the readme file

(procedure P_MakeImages
  (askdisk
    (prompt ("\n\nPlease insert your Captain Planet disk\ninto drive DF%ld:" #CI_drive))
    (dest "CAPTAIN PLANET - BOOTDISK")
    (help @askdisk-help)
  )
  (message "\n\nPress \"Proceed\" to start copying your disk")

  (copyfiles (source "readplanetdisk") (dest #dest) (nogauge))
  (if (<> 0 (run ("cd \"%s\"\nreadplanetdisk %ld >ENV:xfail" #dest #CI_drive)))
    (abort (cat
      "Your Captain Planet disk could not be correctly read!\n"
      (getenv "xfail")
    ))
  )
  (delete "ENV:xfail" ("%s/readplanetdisk" #dest) (safe))
)

;****************************
;----------------------------
; 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."
      )
    )
  )
)

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

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

; in expert mode ask for source drive
(if (= @user-level 2)
  (set #CI_drive (askchoice
    (prompt "Select source drive for diskimages") (default 0)
    (choices "DF0:" "DF1:" "DF2:" "DF3:")
    (help @askchoice-help)
  ))
  (set #CI_drive 0)
)


(set @default-dest
  (askdir
    (prompt 
      (cat
	"Where should \"" @app-name "\" installed ?\n"
	"A drawer \"" @app-name "\" will automatically created."
      )
    )
    (help @askdir-help)
    (default @default-dest)
    (disk)
  )
)
(set #dest (tackon @default-dest @app-name))
(if
  (exists #dest)
  (
    (set #choice
      (askbool
        (prompt
          (cat
            "\nDirectory \"" #dest "\" already exists.\n"
            "Should it be deleted?"
          )
        )
        (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 do you like to install ?\n")
      (default 0)
      (choices "Normal" "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)
  )
)
(if
  (exists ("%s.info" #readme-file))
  (copyfiles
    (help @copyfiles-help)
    (source ("%s.info" #readme-file))
    (dest #dest)
  )
)

(P_MakeImages)

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

(exit)

