; $VER: Installer 1.0 (24.1.99)
;
; An Amiga Installer for the Installer mode for GoldEd
;
; Copyright © 1999 Thomas Aglassinger.
; Freeware. Use at your own risk.

;----------------------------------------------------------------------------
; Specify minimum installer version
;----------------------------------------------------------------------------
(debug "set version")
(set #minimum-installer-version 43)
(set #minimum-installer-revision 3)
(set #minimum-installer-id
   (+ #minimum-installer-revision
       (* #minimum-installer-version 65536)
   )
)
(debug "  minimum-installer-id = " #minimum-installer-id)
(debug "  current-installer-id = " @installer-version)

;----------------------------------------------------------------------------
; Setup messages, prompts and help text
;----------------------------------------------------------------------------

(set #message-wrong-installer
(cat "You have an old version of the program 'Installer' on your Amiga!\n\n"
     "The installation procedure needs at least Installer "
     #minimum-installer-version "." #minimum-installer-revision ".\n\n"
     "Please obtain a newer version!\n\n"
     "(Check Aminet or "
     "the WWW site of the current owner of the rights for Amiga.)"
))

(set #message-welcome
(cat "Welcome to the Amiga Installer for GedInstaller\n\n"
     "This will install an Installer mode for GoldEd. It features a "
     "syntax parser and a procedure scanner."
))

(set #update-registry-manually
(cat "There has been a minor problem:\n\n"
     "Because the registry editor has not been installed, the Installer "
     "filetype could not have been created automatically. Thus, you "
     "have to do it manually.\n\n"
     "Simply create a new filetype for \"Install*\" and assign all the "
     "installer.* presets to it."
))

(set #message-exit
(cat "\nThe Installer mode has been installed.\n\n"
     "Please restart GoldEd."
))

(set #message-wrong-golded
(cat "This script requires GoldED 4.7.\n\n"
     "If you are using GoldEd 5, install the contents manually"
))


;----------------------------------------------------------------------------
; Check requirements
;----------------------------------------------------------------------------

; Check installer version to piss people off and make them
; download a new one or forget about the whole thing - He he he.
; (The script should work with older versions, but how am I
; supposed to test this?)
;
; After that, check for GoldEd 4.7 to piss off users of GoldEd 5.

(procedure P-check-requirements
(
   (debug "check installer version")
   (if (< @installer-version #minimum-installer-id)
     (
       (debug "installer too old")
       (abort #message-wrong-installer)
     )
   )

   (debug "check golded version")
   (set #golded-installed 0)
   (if (exists "GOLDED:" (NOREQ))
      (
         (set #golded-version (getversion "golded:golded"))

         (set #version-high (/ #golded-version 65536))
         (set #version-low (- #golded-version (* #version-high 65536)))

         (set #version-by-ten (+ (* 10 #version-high) #version-low))

         (if (= #version-by-ten 47) (set #golded-installed 1))
      )
   )

   (if (= 0 #golded-installed) (abort #message-wrong-golded))
))


;----------------------------------------------------------------------------
; Welcome user
;----------------------------------------------------------------------------
(procedure P-welcome
(
   (debug "welcome")
   (welcome #message-welcome)
))

;----------------------------------------------------------------------------
; Copy files
;----------------------------------------------------------------------------
(procedure P-copy-files
(
   (debug "copy-files")
   (copylib
      (prompt "Copy syntax parser")
      (source "syntax/installer.parser")
      (dest "golded:syntax")
      (confirm)
      (help @copylib-help)
   )

   (copylib
      (prompt "Copy routine scanner")
      (source "scanner/installer")
      (dest "golded:parser")
      (confirm)
      (help @copylib-help)
   )
))

;----------------------------------------------------------------------------
; Copy presets
;----------------------------------------------------------------------------
(procedure P-copy-presets
(
   (debug "copy-presets")
   (if (exists("golded:tools/regedit/regedit"))
      (
         (working "Updating registry...")
         (run "golded:tools/regedit/regedit script=install.bat")
      )
      (
         (copyfiles
            (prompt "Copy installer.* presets")
            (source "presets")
            (dest "golded:presets")
            (confirm)
            (all)
            (help @copyfiles-help)
         )
         (message #update-registry-manually)
      )
   )
))

;----------------------------------------------------------------------------
; Exit
;----------------------------------------------------------------------------
(procedure P-exit
(
   (debug "exit")

   (message (#message-exit) (all))
   (exit (quiet))
))

;----------------------------------------------------------------------------
; "Wollt ihr das totale Programm?"
;----------------------------------------------------------------------------

(complete   0) (P-check-requirements)

(complete   0) (P-welcome)

(complete  30) (P-copy-files)

(complete  60) (P-copy-presets)

(complete 100) (P-exit)

