(procedure check-system-version
 (set exec-version (/ (getversion) 65536))
 (if (< exec-version 37)
  (abort "Rtgmaster needs at least Exec version 37.\n")
 )
)

(set #NoUp    "No, Don't update")
(set #OnlyNew "Yes, Only if newer")
(set #YesAll  "Yes, No matter what")
(set #wishtoinstall "Do you wish to install any of the following?")
(set #guide "AmigaGuide File")
(set #devdocs  "Developer Documentation")
(set #incl "Includes")
(set #demos "Demos")
(set #goodies "Goodies")
(set #WhereStuffDir "Please select where you wish to put them.\n(A directory called \"RTGMaster\" will be created there!)")
(set #wishtoinstall2 "Do you wish to install the latest version of the rtgmaster c2p package ? (It c2p algorithms with the same filenames are existing, they will be overwritten)")
(set #installit "RtgMaster c2p Package")

(procedure copy-files-to-destination
 (set vernum1 (getversion "libs:rtgmaster.library"))
(set ver1 (/ vernum1 65536))
(set rev1 (- vernum1 (* ver1 65536) ) )


(set vernum2 (getversion "libs/rtgmaster.library"))
(set ver2 (/ vernum2 65536))
(set rev2 (- vernum2 (* ver2 65536) ) )

 (set pick 0)

(set pick (askchoice
                (choices #NoUp #OnlyNew #YesAll)
                (prompt ("'rtgmaster.library' :\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nVersion Currently Installed   : %ld.%ld\n\nVersion From Update : %ld.%ld\n\nDo you wish to install Version %ld.%ld of the 'rtgmaster.library' \n" ver1 rev1 ver2 rev2 ver2 rev2))
                (help "rtgmaster.library is the main-library of rtgmaster. You HAVE TO install it. ")
              (default 1)
          )
)



(if (= pick 1)

        (copylib (source "libs/rtgmaster.library") (dest "libs:"))

)


(if (= pick 2)

        (copyfiles
                (prompt "Copying 'rtgmaster.library' to Libs:")
                (source "libs/rtgmaster.library")
                (dest "libs:")
                (confirm)
                (infos) (help " ")
        )

)

(complete 10)

 (set vernum1 (getversion "libs:rtg/rtgCGX.library"))
(set ver1 (/ vernum1 65536))
(set rev1 (- vernum1 (* ver1 65536) ) )


(set vernum2 (getversion "libs/rtg/rtgCGX.library"))
(set ver2 (/ vernum2 65536))
(set rev2 (- vernum2 (* ver2 65536) ) )

 (set pick 0)

(set pick (askchoice
                (choices #NoUp #OnlyNew #YesAll)
                (prompt ("'rtg/rtgCGX.library' :\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nVersion Currently Installed   : %ld.%ld\n\nVersion From Update : %ld.%ld\n\nDo you wish to install Version %ld.%ld of the 'rtg/rtgCGX.library' \n" ver1 rev1 ver2 rev2 ver2 rev2))
                (help "rtg/rtgCGX.library is the CyberGraphX Support-Library of Rtgmaster ")
              (default 1)
          )
)



(if (= pick 1)

        (copylib (source "libs/rtg/rtgCGX.library") (dest "libs:rtg"))

)


(if (= pick 2)

        (copyfiles
                (prompt "Copying 'rtg/rtgCGX.library' to Libs:Rtg")
                (source "libs/rtg/rtgCGX.library")
                (dest "libs:rtg")
                (confirm)
                (infos) (help " ")
        )

)

(complete 15)

(set vernum1 (getversion "libs:rtg/rtgAMI.library"))
(set ver1 (/ vernum1 65536))
(set rev1 (- vernum1 (* ver1 65536) ) )


(set vernum2 (getversion "libs/rtg/rtgAMI.library"))
(set ver2 (/ vernum2 65536))
(set rev2 (- vernum2 (* ver2 65536) ) )

 (set pick 0)

(set pick (askchoice
                (choices #NoUp #OnlyNew #YesAll)
                (prompt ("'rtg/rtgAMI.library' :\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nVersion Currently Installed   : %ld.%ld\n\nVersion From Update : %ld.%ld\n\nDo you wish to install Version %ld.%ld of the 'rtg/rtgAMI.library' \n" ver1 rev1 ver2 rev2 ver2 rev2))
                (help "rtg/rtgAMI.library is needed for ECS/AGA support of rtgmaster ")
              (default 1)
          )
)



(if (= pick 1)

        (copylib (source "libs/rtg/rtgAMI.library") (dest "libs:rtg"))

)


(if (= pick 2)

        (copyfiles
                (prompt "Copying 'rtg/rtgAMI.library' to Libs:Rtg")
                (source "libs/rtg/rtgAMI.library")
                (dest "libs:rtg")
                (confirm)
                (infos) (help " ")
        )

)

(complete 20)

 (set pick 0)

(set pick (askchoice
                (choices #NoUp #OnlyNew #YesAll)
                (prompt ("'rtg/rtgEGS.library' :\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nVersion Currently Installed   : %ld.%ld\n\nVersion From Update : %ld.%ld\n\nDo you wish to install Version %ld.%ld of the 'rtg/rtgEGS.library' \n" ver1 rev1 ver2 rev2 ver2 rev2))
                (help "rtg/rtgEGS.library is for support of EGS Boards with EGS WB-Emulation running ")
              (default 1)
          )
)



(if (= pick 1)

        (copylib (source "libs/rtg/rtgEGS.library") (dest "libs:rtg"))

)


(if (= pick 2)

        (copyfiles
                (prompt "Copying 'rtg/rtgEGS.library' to Libs:Rtg")
                (source "libs/rtg/rtgEGS.library")
                (dest "libs:rtg")
                (confirm)
                (infos) (help " ")
        )

)

(complete 25)

 (set pick 0)

(set pick (askchoice
                (choices #NoUp #OnlyNew #YesAll)
                (prompt ("'rtg/rtgPICA.library' :\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nVersion Currently Installed   : %ld.%ld\nVersion From Update : %ld.%ld\n\nDo you wish to install Version %ld.%ld of the 'rtg/rtgPICA.library' \nNOTE: Might crash your system in this version, \n if you do not have a Picasso II installed" ver1 rev1 ver2 rev2 ver2 rev2))
                (help "rtg/rtgPICA.library is needed for Picasso II Boards running with Villagetronic WB-Emulation software ")
              (default 1)
          )
)



(if (= pick 1)

        (copylib (source "libs/rtg/rtgPICA.library") (dest "libs:rtg"))

)


(if (= pick 2)

        (copyfiles
                (prompt "Copying 'rtg/rtgPICA.library' to Libs:Rtg")
                (source "libs/rtg/rtgPICA.library")
                (dest "libs:rtg")
                (confirm)
                (infos) (help "")
        )

)

(complete 30)

 (set pick 0)

(set pick (askchoice
                (choices #NoUp #OnlyNew #YesAll)
                (prompt ("'rtg/rtgTIGA.library' :\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nVersion Currently Installed   : %ld.%ld\n\nVersion From Update : %ld.%ld\n\nDo you wish to install Version %ld.%ld of the 'rtg/rtgTIGA.library' \nNOTE: Won't do much up to now, as not finished." ver1 rev1 ver2 rev2 ver2 rev2))
                (help "rtg/rtgTIGA.library is needed, if you own a A2410 Board. Is not 100% compatible to rtgmaster, due to hardware problems of the A2410. Not finished up to now, so it does not do much.")
              (default 1)
          )
)



(if (= pick 1)

        (copylib (source "libs/rtg/rtgTIGA.library") (dest "libs:rtg"))

)


(if (= pick 2)

        (copyfiles
                (prompt "Copying 'rtg/rtgTIGA.library' to Libs:Rtg")
                (source "libs/rtg/rtgTIGA.library")
                (dest "libs:rtg")
                (confirm)
                (infos) (help " ")
        )

)

(complete 35)

(set ToDo       (askoptions (choices #guide #devdocs #incl #demos #goodies)
                            (prompt #wishtoinstall)
                            (help #wishtoinstall)
                            (default 63)
                )
)

;********************************************************************************
; Ask WHERE to install DEVDOCS, Versions, Order, guide
;********************************************************************************
(if (<> ToDo 0)
 (

  (set RtgMaster (askdir (prompt #WhereStuffDir)
                           (help   #WhereStuffDir)
                           (default "Work:")
                   )
  )


  (if (< (exists (tackon RtgMaster "RtgMaster")) 2)
      (makedir (tackon RtgMaster "RtgMaster") (infos))

  )


  (set where (tackon RtgMaster "RtgMaster"))
  (set @default-dest RtgMaster)

;********************************************************************************
; COPY selected stuff!
;********************************************************************************

  (if (IN ToDo 0)
   (

     (copyfiles (source "rtgmaster.guide")  (dest where) (infos) (newname "rtgmaster.guide"))

   )
  )

(complete 40)

  (if (IN ToDo 1)
   (
     (if (< (exists (tackon where "DevDocs")) 2)
          (makedir (tackon where "DevDocs") (infos))
     )
     (copyfiles (source "devdocs") (dest (tackon where "DevDocs")) (all) )
   )
  )

(complete 50)

  (if (IN ToDo 2)
   (
     (if (< (exists (tackon where "Includes")) 2)
          (makedir (tackon where "Includes") (infos))
     )
     (copyfiles (source "Includes") (dest (tackon where "Includes")) (all) )
   )
  )

(complete 60)

  (if (IN ToDo 3)
   (
     (if (< (exists (tackon where "Demos")) 2)
          (makedir (tackon where "Demos") (infos))
     )
          (copyfiles (source "demos") (dest (tackon where "Demos")) (all) )
   )
  )

(complete 70)

  (if (IN ToDo 4)
   (
     (if (< (exists (tackon where "Goodies")) 2)
          (makedir (tackon where "Goodies") (infos))
     )
          (copyfiles (source "goodies") (dest (tackon where "Goodies")) (all) )
   )
  )

(complete 80)

  (set RtgMaster where)

  (set c2p       (askoptions (choices #installit)
                            (prompt #wishtoinstall2)
                            (help #wishtoinstall2)
                            (default 63)
                )
)

(if (IN c2p 0)
 (
  (copyfiles (source "rtgc2p") (dest ("libs:rtgc2p")) (all))
 )
)

 )
)

)

 

;;;; Start

;(welcome "Welcome to the Rtgmaster installation.\n")

(set app-name "Rtgmaster")

(check-system-version)

(complete 0)

(set source-dir (if (= 1 (exists @icon)) (pathonly (expandpath @icon))
 (expandpath @icon))
)

(if (not (exists ("libs:rtg")))
 (makedir ("libs:rtg") (infos))
)

(if (not (exists ("libs:rtgc2p")))
 (makedir ("libs:rtgc2p") (infos))
)

(complete 0)

(copy-files-to-destination)

(complete 100)

(exit "You should reboot your machine now. Note for "
       "users : You don't have to bother much about rtgmaster.library from now on, "
       "simply start the programs it uses :) To change an already saved Screenmode "
       "press SHIFT while running the program. For more information : Read the "
       "User information in the Docs.")
