;******************************************************************************
;     __  __ __            __     ______ __  __
;    / / / // /           / /    /_  __// / / /
;   / / / // /    ______ / /___   / /  / / / /
;  / / / // /    / __  // __  /  / /  / / / /
; / /_/ // /___ / __  // /_/ /  / /  / /_/ /
; \____//_____//_/ /_//_____/  /_/   \____/
;
; $VER: .13a_VLabTV_Installer (Jan-15-1996) 
; Changes, suggestions or problems: rcr@netcom.com
; If you wish to use any part of this installer you must ask.
;
; Installer by Robert C. Reiswig ©1995, 1996 
; VLabTV    by Frank Mariak      ©1995, 1996 
;******************************************************************************

;*** 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) )

(if (> cpu 68010)  (set #fpuGuess 0)  (set #fpuGuess 1) )
   
(set vernum1 (getversion "VLabTV")) (set ver1 (/ vernum1 65536)) 
(set rev1 (- vernum1 (* ver1 65536) ) ) (set VLabTVver (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))
(if (= "italiano"   lanfound) (set lan 2)) 

(set #English    "English")
(set #Deutsch    "Deutsch")
(set #Italiano  "Italiano")

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

;********************************************************************
; English Strings
;********************************************************************
(set #about (cat "\n\n\n\nWelcome to VLabTV " VLabTVver "\n\n\nCopyright © 1995,1996 by\n\nFrank Mariak\n") )
(set #whereVLabTV "Where do you wish to install VLabTV. A directory called 'VLabTV' will be created if one is not there. If a copy of VLabTV is found it will be backed up.")
(set #filethere1 "\n\nThe installer has found VLabTV 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 'VLabTV.")
(set #copyover "Copy Over Old Version")
(set #oktodelete1 "\nIs it ok to delete the older VLabTV binary so that the VLabTV Directory can be made?\n")
(set #oktodelete2 "\nIs it ok to delete the older _renamed_ VLabTV binary so that the VLabTV Directory can be made?\n")
(set #VLabTVfound "\nThe Installer has found a copy of VLabTV already installed. What do you want to do?\n")
(set #newicon "\nDo you wish to copy over The VLabTV 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 #whatcat "\nSelect the VLabTV Language catalog you wish to install.\n")
(set #wherecat "\nWhere do you wish to install the VLabTV Language Catalog? Default is ")
(set #catnofind "Can not find this catalog in this VLabTV archive. You may need to get a newer archive.")
(set #whatdocs "\nWhat VLabTV documentation would you like to install?\n")
(set #wheredocs "Where would you like the VLabTV documentation you selected to be installed?")
(set #byebye (cat "\nVLabTV Install Complete!\n\n" ))



;********************************************************************
; German Strings
;********************************************************************

(if (= lan 1)
(
 (set po 1)

(set #about (cat "\n\n\n\nWillkommen zu VLabTV " VLabTVver "\n\n\nCopyright © 1995,1996 by\n\nFrank Mariak\n") )
(set #whereVLabTV "Wohin wollen Sie VlabTV installieren ? Ein Verzeichnis 'VLabTV' wird erzeugt, wenn es nicht existiert. Wenn bereits eine VLabTV Version vorhanden ist, wird diese gesichert.")
(set #filethere1 "\n\nDas Installationsprogramm fand VLabTV Version ")
(set #filethere2 " at ")
(set #filethere3 "\n\nDie Datei wird umbenannt in ")
(set #filethere4 " und wird dann verschoben nach ")
(set #backuptoXXX "sichern als Datei 'VLabTV.")
(set #copyover "alte Version überschreiben")
(set #oktodelete1 "\nSind Sie damit einverstanden, daß das alte VLabTV Hauptprogramm gelöscht, so daß das VLabTV Verzeichnis erstellt werden kann?\n")
(set #oktodelete2 "\nSind Sie damit einverstanden, daß das alte _umbenannte_ VLabTV Hauptprogramm gelöscht wird, so daß das VLabTV Verzeichnis erstellt werden kann?\n")
(set #VLabTVfound "\nDas Installationsprogramm hat bereits eine installierte VLabTV Version gefunden. Was wollen Sie tun?\n")
(set #newicon "\nWollen Sie das VlabTV Piktogramm aus dem Archiv übernehmen? Wenn Sie bereits die Programmmerkmale verändert haben, wählen Sie bitte Nein.\n")
(set #nonewicon  "Nein  - Programmmerkmale verändert.")
(set #yesnewicon "Ja - Überschreibe Icon.")
(set #whatcat "\nWählen Sie die Sprache, die installiert werden soll.\n")
(set #wherecat "\nWohin wollen Sie die VLabTV Sprachdatei installieren? Eingestellt ist ")
(set #catnofind "Ich kann die passende Sprachdatei im Archiv nicht finden. Sie benötigen ggfls. ein neueres Archiv.")
(set #whatdocs "\nWelche Anleitung wollen Sie installieren ?\n")
(set #wheredocs "Wohin wollen Sie die gewählte Anleitung kopieren?")
(set #byebye (cat "\nVLabTV Installation abgeschlossen!\n\n" ))

)
)

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

;********************************************************************
; Ask where to put VLabTV & Make dir if needed
;********************************************************************
(set VLabTVdir  (askdir (prompt #whereVLabTV)
		        (help   #whereVLabTV)
     		        (default "Work:")
               )  
)

(set where VLabTVdir)

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

    (message (cat #filethere1 ver1 "." rev1 #filethere2 where #filethere3 
                  (cat "VLabTV" VLabTV_old) #filethere4 (tackon VLabTVdir "VLabTV") )
    )
    

    (copyfiles (source (tackon where "VLabTV"))
               (dest where) 
               (infos)
               (newname (cat "VLabTV." VLabTV_old))
    )
    
    (delete (tackon VLabTVdir "VLabTV") (prompt #oktodelete1) (help #oktodelete1) (confirm) (infos)) 

    (if (< (exists (tackon VLabTVdir "VLabTV")) 2) (makedir (tackon VLabTVdir "VLabTV") (infos)) )    

    (copyfiles (source (tackon where (cat "VLabTV." VLabTV_old) ))
                       (dest (tackon VLabTVdir "VLabTV")) 
                       (infos)
               
    )

    (delete (tackon where (cat "VLabTV" VLabTV_old)) (prompt #oktodelete2) (help #oktodelete2) (confirm) (infos) ) 

    ;(set firsttime 1)

  )
)

(if (< (exists (tackon VLabTVdir "VLabTV")) 2) (makedir (tackon VLabTVdir "VLabTV") (infos)) )
(set where (tackon VLabTVdir "VLabTV"))
(set @default-dest where)

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

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


      (if (= keeper 0)
         (copyfiles (source (tackon where "VLabTV"))
                     (dest where) 
                     (infos)
                     (newname (cat "VLabTV" VLabTV_old))
         )
      )          

      (set firsttime 1)
    
  )
)

;********************************************************************
; Copy over correct VLabTV and Icon if wanted
;********************************************************************
(copyfiles (source "VLabTV") (dest where) (optional "nofail") )


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


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

  )

)

;********************************************************************
; Select and copy over Catalog
;********************************************************************
(set catalog (askchoice (choices #English #Deutsch #Italiano) ;#Svenska #Suomi #Français #Norsk #Español #Greek #Nederlands #Bosanski #Dansk #Polski
                           (prompt #whatcat)
	                   (help   #whatcat)
                           (default lan)
             )
)



(if (= catalog 0)  (set #lcat #English ))   (if (= catalog 1)  (set #lcat #Deutsch))
(if (= catalog 2)  (set #lcat #Italiano))

(if (<> catalog 0)
 (
  (if (> (exists (cat "Catalogs/" #lcat "/vlabtv.catalog")) 0)
    (
        (set wherecat  (askchoice (choices (tackon where (cat "Catalogs/" #lcat)) (cat "Locale:Catalogs/" #lcat) )
                                  (prompt (cat #wherecat (tackon where (cat "Catalogs/" #lcat)) "\n"))
	  	                  (help   #wherecat)
     		                  (default 0)
                       )  
        )

      (if (= wherecat 1)
        (
         (if (< (exists "Locale:") 2) ( (makedir "sys:Locale") (makeassign "Locale" "sys:Locale") ) )
         (if (< (exists "Locale:Catalogs") 2) (makedir "sys:Locale/Catalogs") )
         (if (< (exists (cat "Locale:Catalogs/" #lcat)) 2) (makedir (cat "sys:Locale/Catalogs/" #lcat)) )
         (copylib (source (cat "Catalogs/" #lcat "/vlabtv.catalog")) (dest (cat "sys:Locale/Catalogs/" #lcat)) )
        )
  
        (
         (if (< (exists (tackon where "Catalogs")) 2) (makedir (tackon where "Catalogs")) )
         (if (< (exists (tackon where (cat "Catalogs/" #lcat)) ) 2) (makedir (tackon where (cat "Catalogs/" #lcat)) ) )
         (copylib (source (cat "Catalogs/" #lcat "/vlabtv.catalog")) (dest (tackon where (cat "Catalogs/" #lcat)) ) (optional "nofail") )
        )
      )

    )

    (message (cat "\nCatalogs/" #lcat "/vlabtv.catalog\n\n" #catnofind))
  )


 )
)
;********************************************************************
; Ask and copy docs if wanted!
;********************************************************************
(set docs (askoptions (choices " VLabTV.guide")
		      (prompt #whatdocs)
                      (help #whatdocs)
	              (default 1)
	  )
)

(if (<> docs 0)
 (
   (set docsdir (askdir (prompt #wheredocs)
		       (help   #wheredocs)
     		       (default where)
                )  
   )

   (if (IN docs 0) (copyfiles (source "VLabTV.guide") (dest docsdir) (infos) (optional "nofail") ) )
   
 )
)

;********************************************************************
; Copy or Update gtlayout.library & vlab.library
;********************************************************************
(copylib  (source "libs/gtlayout.library") (dest "libs:") )
(copylib  (source "libs/vlab.library") (dest "libs:") )

;********************************************************************
; End Bye 
;********************************************************************
(exit #byebye)
