; This is the Installer-script for AmigaBase.

(set OS_version (/ (getversion) 65536))
(set IsKick20 (>= OS_Version 36))

(transcript "Installing AmigaBase V2.00.")
(complete 0)

(set HD_Installation
   (=
      (askchoice
         (prompt "Choose installation:")
         (help "The harddisk installation installs all files"
               "in a seperate directory, while the floppy"
               "installation creates a working disk.")
         (choices "Harddisk installation" "Floppy installation")
         (default 1)
      )
      0
   )
)

(if HD_Installation
   (set AB_dest_parent
      (askdir
         (prompt "Select disk/directory where AmigaBase should be installed. "
                 "The installation program automatically creates the directory "
                 "\"AmigaBase\" in this directory.")
         (help @askdir-help)
         (default @default-dest)
      )
   )
   (
      (set AB_dest_parent "RAM:")
      (message
         "The installation script assumes that you have already "
         "created a copy of your Workbench disk which has at "
         "least 100 kBytes free, rebooted your computer from "
         "that disk and formatted a new disk with name \"AmigaBase\".\n\n"
         "If not then please abort the installation now, "
         "do the steps above and restart the installation.\n\n"
         "The floppy installation will first copy all needed files "
         "to RAM:AmigaBase and then copy them to the disk."
      )
   )
)

(set AB_dest (tackon AB_dest_parent "AmigaBase"))

(if HD_Installation
   (
      (set @default-dest AB_dest)

         (if (exists AB_dest)
            (message
               "You have already installed AmigaBase in this directory. "
               "If you continue the old installation will be overwritten!"
            )
         )
      )
)

(complete 5)

; Make dest directory and create icon
(makedir AB_dest)
(copyfiles
   (source "AB_dir.icon")
   (dest AB_dest_parent)
   (newname "AmigaBase.info")
)

(complete 10)

;copy AmigaBase
(set packed (exists "AmigaBase.lha"))
(if packed
   (set lha (expandpath "lha"))
)

(copyfiles
   (prompt "Copying AmigaBase.")
   (help @copyfiles-help)
   (source (if packed "AmigaBase.lha" "AmigaBase"))
   (dest AB_dest)
   (infos)
   (confirm)
)

(if packed
   (
      (working "Extracting AmigaBase...")
      (run ("cd \"%s\"\n\"%s\" x AmigaBase.lha\n delete AmigaBase.lha" AB_dest lha))
   )
)

(complete 15)

;copy some text files
(copyfiles
   (prompt "Copying the text files.")
      (help @copyfiles-help)
      (source "")
      (dest AB_dest)
      (choices "ReadMe" "LiesMich" "BUGS" "HISTORY" "TODO")
      (infos)
      (confirm)
)

(complete 20)

;copy reqtools.library
(copylib
   (prompt "Installing 'reqtools.library'.")
	(help @copylib-help)
	(source
      (if IsKick20
         "libs20/reqtools.library"
         "libs13/reqtools.library"
      )
   )
	(dest "libs:")
	(confirm)
)

(complete 30)

;copy gadget.library
(copylib
   (prompt "Installing 'gadget.library'.")
	(help @copylib-help)
	(source "libs13/gadget.library")
	(dest "libs:")
	(confirm)
)

(complete 40)

(if HD_Installation
   (
      ;make AmigaBase assign in startup-sequence

      (startup "AmigaBase"
      	(prompt
	      	"An assign instruction need to be added to the \"S:user-startup\" "
            "so that AmigaBase can be started by double clicking an "
            "AmigaBase project."
         )
      	(help @startup-help)
	      (command (cat "assign AmigaBase: " AB_dest "\n"))
      )
      (makeassign "AmigaBase" AB_dest)
   )
)

(complete 50)

;copy catalog files
(if IsKick20
   (copyfiles
      (prompt "Which additional languages should AmigaBase support?")
      (help "The builtin language of AmigaBase is 'english'. ")
      (source "Catalogs")
      (dest "LOCALE:Catalogs")
      (pattern "#?")
      (confirm)
   )
)

(complete 60)

;create "Data" directory
(makedir (tackon AB_dest "Data"))
(copyfiles
   (source "Data.info")
   (dest AB_dest)
   (newname "Data.info")
)

(complete 70)

;copy optional examples
(set choice
   (askoptions
      (prompt "Copying optional examples.")
      (help @askoptions-help)
      (choices "Deutsch" "English")
   )
)

(if choice
   (
      (set Data_dest (tackon AB_dest "Data"))

      (copyfiles
         (prompt "Copying Mandel picture.")
         (help @copyfiles-help)
         (source "Data")
         (dest Data_dest)
         (choices "Graphics")
         (infos)
      )

      (set packed (exists "Data/Deutsch.lha"))
      (if packed
         (set lha (expandpath "lha"))
      )

      (if (BITAND choice 1)
         (
            (copyfiles
               (prompt "Copying German example projects.")
               (help @copyfiles-help)
               (source "Data")
               (dest Data_dest)
               (choices (if packed "Deutsch.lha" "Deutsch"))
               (infos)
            )
            (if packed
               (
                  (working "Extracting archive...")
                  (run ("cd \"%s\"\n\"%s\" x Deutsch.lha\n delete Deutsch.lha" Data_dest lha))
               )
            )
         )
      )
      (if (BITAND choice 2)
         (
            (copyfiles
               (prompt "Copying English example projects.")
               (help @copyfiles-help)
               (source "Data")
               (dest Data_dest)
               (choices (if packed "English.lha" "English"))
               (infos)
            )
            (if packed
               (
                  (working "Extracting archive...")
                  (run ("cd \"%s\"\n\"%s\" x English.lha\n delete English.lha" Data_dest lha))
               )
            )
         )
      )
   )
)

(complete 80)

(if (NOT HD_Installation)
   (
      (askdisk
         (prompt
            "All necessary files have been copied to RAM:AmigaBase. "
            "Please insert now the disk \"AmigaBase\"."
         )
         (help @askdisk-help)
         (dest "AmigaBase")
      )
      (copyfiles
         (source AB_dest)
         (dest "AmigaBase:")
         (all)
      )
      (run "delete ram:AmigaBase ram:AmigaBase.info ALL QUIET FORCE")

      (set @default-dest "AmigaBase:")
   )
)

(complete 100)

(exit)

