; $VER: New Homer Installer 1.3 (4.08.01)

;
; Notice: this installer was derived from the original Homer installer...
; I did this since I had NEVER used the commodore installer before, so I
; wanted to lose as less time as possible.
;

; =======================================================================
;   Set up some variables
; =======================================================================

(set OSVersion       (/ (getversion) 65536))
(set WBVersion       (/ (getversion "libs:version.library") 65536))
(set AGVersion       (/ (getversion "libs:amigaguide.library") 65536))
(set cpu             (database "cpu"))
(set #welcome        "\nNewHomer 1.5 @2001 Emiliano Esposito\nWelcome to New Homer installation program.\n\nNew Homer is a (bit better) replacement for old Homer 1.6 found on Aminet.\nNB be sure to read the install part of documentation before installing.\n")

(message #welcome)
(welcome)

;
; ===== English
;
(set #kickstart "\nERROR : BAD VERSION OF KICKSTART\n\nHomer requires KickStart %s (V%ld) or higher. It will not work on earlier versions.\nYou currently are running KickStart V%ld.\n\n%s")
(set #goodbye "\nHave fun with Homer!\nIf you want, send any bug-reports, comments, or suggestions to:\n\nEmiliano Esposito - emiespo@tiscalinet.it\n")
(set #continue "Continue with installation?")
(set #aborted "Installation aborted!")
(set #askfile "Please choose the NewHomerDATA.lha file\n")
(set #askfile-help "You need some data files (samples+appropriate config) in order to use Homer. If you didn't have old Homer 1.x installed (and this seems to be the case), you need an extra file called "NewHomerDATA.lha". If you downloaded it, please choose it now.\n")
(set #yes "Yes")
(set #no "No")
(set #which-disk "Choose the directory where your Homer 1.x DIR was installed,\nor where you want to create a new Homer directory.\n(ie if your old Homer was installed in Work:Homer, you must choose Work:, NOT Work:homer)")
(set #newhomerdest "Choose the dir. where you have old NewHomer installed.\n")
(set #which-disk-help "If you are reading this, you probably didn't read the guide file... or you are new to Amiga and the latter sounds too strange nowadays! ;))\n\n")
(set #doc-which-disk "Select directory to install documentation to")

;*** starting actions
(set #acpr "Please choose what sort of installation do you want to perform for Homer")
(set #ch1 "Upgrade from previous NewHomer release")
(set #ch2 "Install over Homer1.5/1.6 and keep old executable")
(set #ch3 "Install over Homer1.5/1.6 and replace old executable")
(set #ch4 "New installation (needs the NewHomer_DATA file)")
(set #askchoice-h "Choose the most appropriate installation method for New Homer.\n\n")
(set #acpr2 "\nPlease choose the language of the documentation that you'd like to have installed.")
(set #language-1 "English")
(set #language-2 "Italiano")
(set #askchoice-h2 "Choose your favourite language\n")

;*** Messages
(set #msg_tooltypes "\nSetting tool types for current setup...")
(set #exec-msg "\nAbout to execute the following command:\n\n")

;*** Errors
(set #err_CantMakeDirectory "An error has occured creating the Homer directory. Please check that the path you specified for installation to is valid!")
(set #err_CantFindDirectory "The path you specified to install to was not located. Please check that the path you specified for installation to is valid!")

; =======================================================================
;   Initialization
; =======================================================================

; ===== Make sure that we are running under the correct version of kickstart
(complete 0)(working #working_kickstart)
(set #minver-text (cat "2.1") )
(set minver 38)

(if (< OSVersion minver)
   (
   (set warning (#kickstart #minver-text minver OSVersion #aborted) )
   (abort warning)
   )
)


(if ( exists "Work:" (noreq) )
   (set @default-dest "Work:")
   (if ( exists "Sys:" (noreq) )
      (set @default-dest "Sys:")
   )
)

(set assigned 0)
(if (= (exists "T:" (noreq) ) 0 )
   (makedir "RAM:T")
   (makeassign "T:" "RAM:T")
   (set assigned 1)
)

(complete 0)

;
; select what type of action to perform
;

(set insttype  (askchoice (prompt #acpr)
                  (choices #ch1 #ch2 #ch3 #ch4)
                  (help #askchoice-h @askchoice-help)
                  (default 0)
               )
)

; =======================================================================
;   Select target directory
; =======================================================================
(set target
    (if (= insttype 0)
       (
         (askdir (prompt #newhomerdest)
            (help #which-disk-help @askdir-help)
            (default @default-dest)
         )
       )
       (
         (askdir (prompt #which-disk)
            (help #which-disk-help @askdir-help)
            (default @default-dest)
         )
       )
    )
)

(set #dest-dir "T:Homer")

(copyfiles (source "NewHomer") (dest #dest-dir))
(copyfiles (source "NewHomer.info") (dest #dest-dir))

(set geppetto  (askchoice (prompt #acpr2)
                  (choices #language1 #language2)
                  (help #askchoice-h2 @askchoice-help)
                  (default 0)
               )
)

(if (= geppetto 0)
   (
      (copyfiles (source "NewHomer.guide") (dest #dest-dir))
      (copyfiles (source "NewHomer.guide.info") (dest #dest-dir))
   )
   (
      (copyfiles (source "NewHomer_italiano.guide") (dest #dest-dir))
      (copyfiles (source "NewHomer_italiano.guide.info") (dest #dest-dir))
   )
)

(complete 30)

(if (<> insttype 0)
   (
      (set target (tackon target "Homer" ) )
      (makedir target (infos) )
   )
)

(makeassign "Homer" target (safe))

(if (= insttype 2)
   (
      (rename "T:Homer/NewHomer" "T:Homer/Homer")
      (rename "T:Homer/NewHomer.info" "T:Homer/Homer.info")
      (rename "T:Homer/NewHomer.conf" "T:Homer/Homer.conf")
   )
)

(if (= insttype 3)
   (
      (set datafile
         (askfile (prompt #askfile)
                  (help #askfile-help @askfile-help)
                  (default "NewHomer_DATA.lha")
         )
      )
      (set #cmd ('c:lha x "%s" "%s/"' datafile target) )
      (message #exec-msg '"' #cmd '"' "\n(Please wait, this may take a while on slower machines)" )
      (if (<> (run #cmd ) 0)
         (
            (abort "Error from archive extraction command!")
         )
      )
   )
)

(complete 60)

(message "\nAbout to copy Homer files to chosen destination. Click proceed to confirm action.")
(if (= insttype 0)
   (delete "T:Homer/#?.info")
)
(copyfiles (source "T:Homer") (dest target) (all))

(complete 95)

(working #msg_tooltypes)     ; ===== Change icon tool types

(set #homer_conf "Homer.conf")

(if (<> insttype 0)
   (if (= insttype 2)
      (tooltype   (dest "Homer:Homer")
         (settooltype "PROGDIR" target )
         (settooltype "CONFIG" #homer_conf)
      )
      (
         (tooltype   (dest "Homer:NewHomer")
            (settooltype "PROGDIR" target )
            (if (= insttype 3)
               (settooltype "CONFIG" "NewHomer.conf")
               (settooltype "CONFIG" #homer_conf)
            )
         )
      )
   )
)

(complete 100)

(makeassign "Homer" (safe))
(delete "T:Homer/#?" (safe))
(if (= assigned 1)
  (makeassign "T:")
)

(exit #goodbye)
