;******************************************************************************
;         __  __                                     
;        / / / /                                    
;       / / / /______ __  __ ______  ______ ______ _____
;      / / / // __  / \ \/ // __  / / __  // ____// .__/
;     /  \/ // /_/ /   \  // __  / / /_/ // __/_ / /
;     \____//_____/    / //_/ /_/ _\__  //_____//_/
;                     /_/        /_____/   
;
; $VER: Voyager_Installer 1.1y (January-26-1997) 
; Installer by Robert C. Reiswig 1995,1996,1997
; Voyager by Oliver Wagner 1995,1996,1997
;
; If you wish to use any part of this installer you must ask. May not be 
; integrated/placed into any other package. Changes, suggestions or problems:
; voyager@vgr.com or vgr@best.com
;******************************************************************************
(set Vkey 1) ; 0=NoKey, 1=LookForKey

;*** System Stuff ***
(set cpu (database "cpu"))  (set vblank (database "vblank"))
(set graphmem (database "graphics-mem")) (set totmem (database "total-mem"))
(set osver (/ (getversion "LIBS:version.library") 65536))
(if (= vblank "60") ((set blank "NTSC")) ((set blank "PAL")))
(set fastmem (- totmem graphmem))

(if (= osver 37) (set workbench "2.0")) (if (= osver 38) (set workbench "2.1"))
(if (= osver 39) (set workbench "3.0")) (if (= osver 40) (set workbench "3.1"))
(if (= osver 41) (set workbench "3.2"))

(set cpu (database "cpu"))
(if (= cpu 68000) (set #cpu 0)) (if (= cpu 68010) (set #cpu 1))
(if (= cpu 68020) (set #cpu 2)) (if (= cpu 68030) (set #cpu 3))
(if (= cpu 68040) (set #cpu 4)) 
(if (> (exists ("sys:libs/68060.library")) 0) (set #cpu 5) )

(set vernum1 (getversion "V")) (set ver1 (/ vernum1 65536))
;(set vernum1 (getversion "mui/StringNumeric.mcc")) (set ver1 (/ vernum1 65536)) 

(set rev1 (- vernum1 (* ver1 65536) ) ) (set Voyagerver (cat ver1 "." rev1))

(if (> (exists ("env:Language")) 0) (set lanfound (getenv "Language")) )
(set lan 0)

(if (= "english"    lanfound) (set lan 0))  (if (= "deutsch"    lanfound) (set lan 1))
(set #English    "English")  (set #Deutsch    "Deutsch")

(set mfound 0) (set newicon1 1) 
(set keeper 1) (set firsttime 0)

;********************************************************************
; English Strings
;********************************************************************
(set #about (cat "\n\n\n\nWelcome to Voyager-NG " Voyagerver "\n\n\nCopyright  1995-1997 by\n\nOliver Wagner\n") )
(set #installup " Install or Update Voyager-NG")
(set #clearcache " Clear Cache Directory")
(set #task "\nWhat would you like to do?\n")
(set #whereVoyager "Where do you wish to install Voyager-NG. The directory 'Voyager' will be created if it is not there. If a copy of Voyager-NG is found it will be backed up.")
(set muiver "No Version Installed")
(set #newermui "\nVoyager-NG needs version 3.6 or higher of MUI installed to work correctly.\n\nNow would be a good time to Upgrade!\n\nYou can find mui33usr.lha on Aminet in dev/gui\n\nIt looks like you have: \n\n")
(set #need-os "\n\nVoyager-NG needs version 3.0 or higher of the Amiga OS installed to work correctly.\n\n It looks like you have: \n\n")
(set #000used "\n\nThe 68000 version will be installed.") 
(set #nompc "\nThe .MPC files for Voyager-NG can not be installed to 'mui:libs/mui'")
(set #noreg1 "\nThe installer could not find 'S:Voyager.Key' or '")
(set #noreg2 "' on your system. It also does not seem to be in the archive you are installing Voyager-NG from. You may need to get the archive again.\n\nThe installer will now run the Registration Utility, 'Register-Voyager'.")   
(set #filethere1 "\n\nThe installer has found Voyager-NG version ")
(set #filethere2 " at ")
(set #filethere3 "\n\nThe file will be renamed to ")
(set #filethere4 " and it will then be moved to ")
(set #backuptoXXX "Back-UP to file named 'Voyager-NG.")
(set #copyover "Copy Over Old Version")
(set #oktodelete1 "\nIs it ok to delete the older Voyager-NG binary so that the Voyager-NG Directory can be made?\n")
(set #oktodelete2 "\nIs it ok to delete the older _renamed_ Voyager-NG binary so that the Voyager-NG Directory can be made?\n")
(set #Voyagerfound "\nThe Installer has found a copy of Voyager-NG already installed. What do you want to do?\n")
(set #no030found "\n\nThe 68030+FPU Version of Voyager-NG, V030, was not found in this archive this is why the 68000 version was installed.")
(set #newicon "\nDo you wish to copy over The Voyager-NG Icon from the archive? If you have any ToolTypes already set you should select no.\n")
(set #nonewicon  "No  - ToolTypes already set.")
(set #yesnewicon "Yes - Copy over Icon.")
(set #yesnewicon "Yes - Copy over Icon.")
(set #whatcat "\nSelect the Voyager-NG Language catalog you wish to install.\n")
(set #wherecat "\nWhere do you wish to install the Voyager-NG Language Catalog? Default is ")
(set #catnofind "Can not find this catalog in this Voyager-NG archive. You may need to get a newer archive.")
(set #whattools "\nWhat Tools would you like to install? They will be placed in: ")
(set #updatingmuic "\nUpdating the MUI Classes if needed.\n\n(#?.mcc & #?.mcp)")
(set #nomuiarc "\nThe installer could not find the MUI dir in the archive. Because of this the MUI Classes used by Voyager-NG were not installed.\n\n If you are Updating Voyager-NG then this is not a problem. If it is your first time installing Voyager-NG you will need to get an archive with these files.")
(set #whatdocs "\nWhat Voyager-NG documentation would you like to install?\n")
(set #wheredocs "Where would you like the Voyager-NG documentation you selected to be installed?")
(set #byebye (cat "\nVoyager-NG Install Complete!\n\n" ))

(set #askcpu "\nWhat version of Voyager-NG would you like to install?\n")
(set #noregdir "\nThe Register-Voyager directory was not found. This means that the archive has been altered or is bad. Please get another copy of the Voyager-NG Archive.\n\nOR\n\nThe Keyfile is missing. Please contact your REG site.")
(set #updatesetpatch "\nThe installer looked for 'c:setpatch' and did not find it or you have a version lower then 40.16. Voyager-NG needs version 40.16 to work correctly. You wany want to upgrade soon. (NOTE: if you keep 'setpatch' in a different place than 'c:' and its 40.16 or higher then this message is void.)")
(set #updateinstaller "\nJust to let you know ESCOM AG has released a new version of the installer program.\n\n\nVersion 43.3 can be found on Aminet in:\n\n/util/misc/Installer-43_3.lha\n\n\nYou might want to upgrade soon, if you can.")


;********************************************************************
; German Strings
;********************************************************************
(if (= lan 1) (set OlliShareSomePizza TRUE) )

;********************************************************************
; Hello
;********************************************************************
(message #about)
(welcome) 

;********************************************************************
; Checks for MUI & OS versions
;********************************************************************
(set ver 0)
(if (<> (getassign "mui") "")
(
  (if (exists "mui:mui") 
   (
    (set vernum (getversion "mui:mui") )
    (set ver (/ vernum 65536)) (set rev (- vernum (* ver 65536) ) )

    (if (= ver 7) (set muiver "2.0") )   (if (= ver 8) (set muiver "2.1") )
    (if (= ver 9) (set muiver "2.2") )   (if (= ver 10) (set muiver "2.3") )
    (if (= ver 11) (set muiver "3.0") )  (if (= ver 12) (set muiver "3.1") )
    (if (= ver 13) (set muiver "3.2") )  (if (= ver 14) (set muiver "3.3") )
    (if (= ver 15) (set muiver "3.4") )  (if (= ver 16) (set muiver "3.5") )
    (if (= ver 17) (set muiver "3.6") )  (if (= ver 18) (set muiver "3.7") )
   )
  )
)
)

(if (< ver 17)   ( (message (cat #newermui muiver))   (set cpuPick 0) ))
(if (< osver 39) ( (message (cat #need-os workbench)) (set cpuPick 0) ))

;********************************************************************
; check for Register-Voyager-NG
;********************************************************************
(if (OR (exists "Register-Voyager") (exists "Voyager.KEY"))
 (set tempz 0) (abort #noregdir)
)
;********************************************************************
; Ask where to put Voyager-NG & Make dir if needed
;********************************************************************
(set Package (getassign "AmiTCP"))
(if (= Package "") (set Package (getassign "Inet")) )

(set Voyagerdir  (askdir (prompt #whereVoyager)
		        (help   #whereVoyager)
     		        (default Package)
               )  
)

(set where Voyagerdir)

;********************************************************************
; Check for Key file
;********************************************************************
;(if (AND (= Vkey 1) (OR (= (exists "Voyager.Key") 0) (OR (= (exists "S:Voyager.Key") 0)  (= (exists (tackon where "Voyager.Key")) 0) ) ) )
; (
;  (message (cat #noreg1 (tackon where "Voyager/Voyager.Key") #noreg2))
;  (run (cat "run Register-Voyager") )
;  ;;** (exit (quiet))
; )
;) 

;********************************************************************
; Check to see if Voyager-NG is already there, if so ask to backup
;********************************************************************
(if (= 1 (exists (tackon where "V") ) ) 
  (
    (set vernum1 (getversion (tackon where "V") ))
    (set ver1 (/ vernum1 65536)) (set rev1 (- vernum1 (* ver1 65536) ) )
    (set Voyager_old (cat ver1 "." rev1))

    (message (cat #filethere1 ver1 "." rev1 #filethere2 where #filethere3 
                  (cat "V" Voyager_old) #filethere4 (tackon Voyagerdir "V") )
    )

    (copyfiles (source (tackon where "V"))
               (dest where) 
               (infos)
               (newname (cat "V." Voyager_old))
    )
    
    (delete (tackon Voyagerdir "V") (prompt #oktodelete1) (help #oktodelete1) (confirm) (infos)) 

    (if (< (exists (tackon Voyagerdir "V")) 2) (makedir (tackon Voyagerdir "V") (infos)) )    

    (copyfiles (source (tackon where (cat "V." Voyager_old) ))
                       (dest (tackon Voyagerdir "V")) 
                       (infos)
               
    )

    (delete (tackon where (cat "V" Voyager_old)) (prompt #oktodelete2) (help #oktodelete2) (confirm) (infos) ) 

    ;(set firsttime 1)

  )
)

(if (< (exists (tackon Voyagerdir "Voyager")) 2) (makedir (tackon Voyagerdir "Voyager") (infos)) )

(if (exists "/V-NG-Prerelease1.info")
 (copyfiles (source "/V-NG-Prerelease1.info") (dest (tackon "/" where)) (newname "Voyager.info") (optional "nofail") ) 
)


(set where (tackon Voyagerdir "Voyager"))
(set @default-dest where)

;********************************************************************
; Check for old & backup
;********************************************************************
(if (exists (tackon where "V")) 
  (
      (set vernum1 (getversion (tackon where "V") ))
      (set ver1 (/ vernum1 65536)) (set rev1 (- vernum1 (* ver1 65536) ) )
      (set Voyager_old (cat ver1 "." rev1))

      (set keeper  (askchoice (choices  (cat #backuptoXXX Voyager_old "'")  #copyover)
                     (prompt #Voyagerfound)
	             (help   #Voyagerfound)
                     (default 0)
	           )
      )    

      (if (= keeper 0)
         (copyfiles (source (tackon where "V"))
                     (dest where) 
                     (infos)
                     (newname (cat "V" Voyager_old))
         )
      )          

      (set firsttime 1)
  )
)

;********************************************************************
; Copy over correct Voyager and Icon if wanted
;********************************************************************
(set gcpu 0)
(if (AND (> #cpu 1) (exists ("V030")) ) (set gcpu 1) ) 



(set cpuPick (askchoice (choices "68000" "68030+FPU")
			 (prompt #askcpu)
	                 (help   #askcpu)
          		 (default gcpu)
	  )
)

(if (AND (= cpuPick 1) (exists ("V030")) )
 (copyfiles (source "V030") (dest where) (newname "V") (optional "nofail") )
 (copyfiles (source "V") (dest where) (optional "nofail") )
)

(if (AND (> #cpu 1) (= (exists ("V030")) 0) )
 (message #no030found)
)

(if (= firsttime 0)  (copyfiles (source "V.info") (dest where) (optional "nofail") ) )

(if (OR (= keeper 0) (= (exists (tackon where "V.info")) 0))
  (
   (set newicon (askchoice (choices #yesnewicon #nonewicon)
                           (prompt #newicon)
	                   (help   #newicon)
                           (default 0)
	        )
   )
  
   (if (= newicon 0) 
     (copyfiles (source "V.info") (dest where)  (optional "nofail") )
   )
  )
)


;********************************************************************
; Copy over Other stuff
;********************************************************************
(if (exists ("RegisterVoyager"))
 (copyfiles (source "RegisterVoyager") (dest where)  (infos) (optional "nofail") )
)

;*** Copy Key 
(if (> (exists "Voyager.KEY") 0)
 (copyfiles (source "Voyager.KEY") (dest where) (infos) (optional "nofail") ) 
)

(if (> (exists "TransferAnim") 0)
 (copyfiles (source "TransferAnim") (dest where) (infos) (optional "nofail") ) 
)

(makedir (tackon where "Cache"))
(if (> (exists "CacheBrowser") 0)
 (copyfiles (source "CacheBrowser") (dest where) (infos) (optional "nofail") ) 
)
;******************************************************************************** 
; Copy over Plugins stuff
;********************************************************************************
(if (< (exists (tackon where "Plugins")) 2) (makedir (tackon where "Plugins") (infos)) )    
(if (exists "Plugins.info")
 (copyfiles (source "Plugins.info") (dest where) (optional "nofail") ) 
)

(if (> (exists "Plugins") 0)
  (foreach "Plugins" "#?"
     (copylib (source (tackon "Plugins" @each-name)) (dest (tackon where "Plugins")) (optional "nofail") ) 
  )
)
;******************************************************************************** 
; Copy over rexx stuff
;********************************************************************************
(if (< (exists (tackon where "rexx")) 2) (makedir (tackon where "rexx") (infos)) )    
(if (exists "Rexx.info")
 (copyfiles (source "Rexx.info") (dest where) (optional "nofail") ) 
)

(if (> (exists "rexx") 0)
  (foreach "rexx" "#?"
     (copylib (source (tackon "rexx" @each-name)) (dest (tackon where "rexx")) (optional "nofail") ) 
  )
)

;******************************************************************************** 
; Copy over Submissions stuff
;********************************************************************************
(if (< (exists (tackon where "Submissions")) 2) (makedir (tackon where "Submissions") (infos)) )    
(if (exists "Submissions.info")
 (copyfiles (source "Submissions.info") (dest where) (optional "nofail") ) 
)

(if (> (exists "Submissions") 0)
  (foreach "Submissions" "#?"
     (copylib (source (tackon "Submissions" @each-name)) (dest (tackon where "Submissions")) (optional "nofail") ) 
  )
)

;********************************************************************
; Copy over DOCS (home.html and Vpics dir) & Other Docs
;********************************************************************
(set docs (askoptions (choices " Docs In HTML format" " V.readme") ;" V.history"
		      (prompt #whatdocs) 
                      (help #whatdocs)
	              (default 3)
	  )
)

(if (<> docs 0)
 (
   ;(set docsdir (askdir (prompt (cat #wheredocs " (V.readme)" )) ; & V.history
   ;		        (help   (cat #wheredocs " (V.readme)" )) ; & V.history
   ;   		        (default where)
   ;             )  
   ;)

   (set docsdir where)  

   (if (IN docs 0)
    (
      (if (< (exists (tackon where "Voyager_home")) 2) (makedir (tackon where "Voyager_home") (infos)) )    
      (if (< (exists (tackon where "Voyager_home/images")) 2) (makedir (tackon where "Voyager_home/images") (infos)) )    
      (if (exists "Voyager_home.info")
        (copyfiles (source "Voyager_home.info") (dest where) (optional "nofail") ) 
      )

      (if (exists "Voyager_home")
        (foreach "Voyager_home" "#?.html"
           (copyfiles (source (tackon "Voyager_home" @each-name)) (dest (tackon where "Voyager_home")) (optional "nofail") ) 
        )
      )

      (if (exists "Voyager_home/images")
        (foreach "Voyager_home/images" "#?.gif"
          (copyfiles (source (tackon "Voyager_home/images" @each-name)) (dest (tackon where "Voyager_home/images")) (optional "nofail") ) 
        )
      )
    )
   )

   (if (IN docs 1) (copyfiles (source "V.readme") (dest docsdir) (infos) (optional "nofail") ) )
   (if (IN docs 2) (copyfiles (source "V.history") (dest docsdir) (infos) (optional "nofail") ) )
 )
)

;********************************************************************
; Copy over TOOLS if wanted
;********************************************************************
(if (> (exists "Tools") 0)
 (
  (set tools (askoptions (choices " ClearCacheDir" " Uninstall")
	  	         (prompt (cat #whattools (tackon where "Tools\n"))) 
                         (help   (cat #whattools (tackon where "Tools\n")))
	                 (default 1)
             )
  )

  (if (<> tools 0)
   (
     (if (< (exists (tackon where "Tools")) 2) (makedir (tackon where "Tools") (infos)) )    
     (set toolsdir (tackon where "Tools"))   

     (if (IN tools 0) (copyfiles (source "Tools/ClearCacheDir") (dest toolsdir) (infos) (optional "nofail") ) )
     (if (IN tools 1) (copyfiles (source "Tools/Uninstall") (dest toolsdir) (infos) (optional "nofail") ) )
   
   )
  )
 
 )
)

;********************************************************************
; Copy over #?.mpc|#?.mcc (Need to be in mui:libs/mui)
;********************************************************************
(if (<> (getassign "mui") "")
(
  (if (> (exists "mui:libs/mui") 0) 
   (
    (if (= (exists "mui") 2)
     (
        (working #updatingmuic)
  
        (foreach "mui" "#?.mcp"
           (copylib (source (tackon "mui" @each-name)) (dest "mui:libs/mui") (optional "nofail") ) 
        )
    
        (foreach "mui" "#?.mcc"
           (copylib (source (tackon "mui" @each-name)) (dest "mui:libs/mui") (optional "nofail") ) 
        )
     )

     (message #nomuiarc)

    )
   
   )

   (message (cat #newermui muiver #nompc)) 
  )
)
)


;********************************************************************
; Reg stuff 
;********************************************************************
(if (exists"Register-Voyager") 
 (
  (if (< (exists (tackon where "Register-Voyager")) 2) (makedir (tackon where "Register-Voyager") (infos)) )    
  (if (exists "Register-Voyager.info")
    (copyfiles (source "Register-Voyager.info") (dest where) (optional "nofail") ) 
  )
  (set whereR (tackon where "Register-Voyager"))


  (set whatreg  (askchoice (choices "English"  "Deutsch" "Francais" "Svenska" )
                           (prompt "What Registration Files (Language) would you like to install?")
	                   (help   "What Registration Files (Language) would you like to install?")
     		           (default 0)
                )  
  )

  (if (= whatreg 0) ((set basereg "English")  (set baseregTT "English") ) )
  (if (= whatreg 1) ((set basereg "Deutsch")  (set baseregTT "Deutsch") ) )
  (if (= whatreg 2) ((set basereg "Francais") (set baseregTT "French")  ) )
  (if (= whatreg 3) ((set basereg "Svenska")  (set baseregTT "Svenska")  ) )

  (if (exists "Register-Voyager/RegistrationUtility") 
    (copyfiles (source "Register-Voyager/RegistrationUtility")
               (dest whereR) 
    )
  )
 
  (if (exists (tackon "Register-Voyager" (cat "Regtool-" basereg ".info")) )
    (copyfiles (source (tackon "Register-Voyager" (cat "Regtool-" basereg ".info")) )
               (dest whereR) 
               (newname "RegistrationUtility.info")
    )
  )

  (if (exists (tackon "Register-Voyager" (cat "Reg_" basereg ".guide")) ) 
    (copyfiles (source (tackon "Register-Voyager" (cat "Reg_" basereg ".guide")))
               (dest whereR) 
               (infos)
    )
  )

  (if (exists (tackon "Register-Voyager" (cat "Reg_" basereg ".doc")) )
    (copyfiles (source (tackon "Register-Voyager" (cat "Reg_" basereg ".doc")))
               (dest whereR) 
               (infos)
    )
  )


 )
)
;********************************************************************
; Check on Setpatch 
;********************************************************************
(set vernum1 (getversion "c:setpatch")) (set ver1 (/ vernum1 65536)) 
(set rev1 (- vernum1 (* ver1 65536) ) ) (set setpatchver (cat ver1 "." rev1))
(set current_setpatch "40.16")
(if (< setpatchVer current_setpatch) (message #updatesetpatch) )
 
;********************************************************************
; Check on New installer 
;********************************************************************
(set InstallerVer 0)
(set vernum1 @installer-version) (set ver1 (/ vernum1 65536)) 
(set rev1 (- vernum1 (* ver1 65536) ) ) (set InstallerVer (cat ver1 "." rev1))
(set current_installer "43.3")
(if (< InstallerVer current_installer) (message #updateinstaller) )

;********************************************************************
; End Bye 
;********************************************************************
(if (> (exists ("c:multiview")) 0) (set #mpath "c:") )
(if (> (exists ("sys:Utilities/multiview")) 0) (set #mpath "sys:Utilities") )
(run (cat "run " #mpath "/multiview V.readme") )

(exit #byebye)
