; $VER: World Construction Set Install Version 1.1 (10-Feb-95)
; Script to Install the World Construction Set System Software.
; By Gary R. Huber.
; Portions involving installation of MagicUserInterface are by
; Stefan Stuntz and used by permission.
; Questar Productions
;
;=============================================================================
;Constants


;(set DATA_SIZE   4000000)

(set INST_WCS  1)
(set INST_MUI  2)
(set INST_DATA  4)
(set INST_IMAGES  8)

;=============================================================================
;**** Setup


(Procedure Config_Options
  (set osversion (/ (getversion) 65536))
  (if (=(database "cpu") "68000")
    ( (SET @InstallOpts %1011101)
      (SET Accelerator 0)
    )
    ( (SET @InstallOpts %1011110)
      (SET Accelerator 1)
    )
  )
)


(Procedure Get_Selections
  (set Selection
    (askoptions
      (prompt "Please select which parts of the World Construction Set Version 2 system you would like to install.\n\n"
		"WCS employs MagicUserInterface to create its GUI."
      )
      (help   "     The WCS system software includes:\n\n"
		"World Construction Set V2\n"
		"  A 3D Geographic Information System.\n"
		"  Requires version 2.04 of the Amiga Operating System\n"
		"      or higher.\n"
		"  The 68030/40 version is optimized for the 68030/40\n"
		"      processors and also requires a 68881/2\n"
		"      coprocessor.\n\n"
		"MagicUserInterface Version 2.3\n"
		"  The Graphical User Interface for WCS and many other\n"
		"      programs. Version 2.3 is supplied. If you do\n"
		"      not have MUI on your system or wish to upgrade\n"
		"      to version 2.3 you should select this option.\n\n"
		"Sample Data\n"
		"  Enough data to get you started.\n"
		"  The sample data will require about 6 megabytes of\n"
		"      disk storage space.\n\n"
;		"Sample Images\n"
;		"  JPEG format images referred to in the Instant\n"
;		"      Gratification chapter of the WCS Operator's\n"
;		"      Manual. These are for your enjoyment only.\n"
;		"      Installation is optional.\n"  
;		"  The sample images will require only about half a\n"
;		"      megabyte of storage."
      )
      (choices
        "World Construction Set"
        "MagicUserInterface"
        "Sample Data"
;	"Sample Images"
      )
      (default %00000111)
    )
  )

  ( while (= Selection 0)
    ((message "You did not select anything, so there is nothing to do.")
     (Get_Selections)
    )
  )
)

;=========================================================================
;**** Install MUI

(Procedure Install_MUI

;***** Old File Deletion

  (if (<> (exists "sys:classes/mui") 0)
    (
	(if (askbool (help @askbool-help) (prompt "Some old MUI stuff is in your libs: drawer. Do you want to delete it now?"))
	  (
		(if (<> (exists "sys:libs/muimaster.library") 0)
		  (
			(delete
				("sys:libs/muimaster.library")
				(prompt "Deleting old muimaster.library...")
				(help @deletefile-help)
			)
		  )
		)

		(foreach "sys:Classes/MUI" "#?.mui"
			(delete
				(tackon "sys:Classes/MUI" @each-name)
				(help @deletefile-help)
			)
		)

		(if (<> (exists "sys:Classes/Images") 0)
		  (
			(foreach "sys:Classes/Images" "mui#?.image"
				(delete
					(tackon "sys:Classes/Images" @each-name)
					(help @deletefile-help)
				)
			)
		  )
		)

		(delete
			("sys:Classes/MUI")
			(help @deletefile-help)
		)
	  )
	)
    )
    (
	(if (<> (exists "sys:libs/muimaster.library") 0)
	  (
		(delete
			("sys:libs/muimaster.library")
			(prompt "Deleting old muimaster.library...")
			(help @deletefile-help)
		)
	  )
	)
    )
  )

  (if (<> (exists "sys:prefs/mui") 0)
    (
	(if (askbool (help @askbool-help) (prompt "The old preferences program is obsolete. Do you want to delete it now?"))
	  (
		(delete
			("sys:Prefs/MUI")
			(help @deletefile-help)
		)
		(delete
			("sys:Prefs/MUI.info")
			(help @deletefile-help)
		)
	  )
	)
    )
  )

  (if (<> (exists "sys:prefs/MUI-Images") 0)
    (
	(if (askbool (help @askbool-help) (prompt "The images in sys:prefs/MUI-Images have moved. Do you want to delete it now? CAUTION: If you have added some extra images here, be sure to copy them somewhere else before proceeding!"))
	  (
		(run "delete sys:Prefs/MUI-images#? all >nil:")
	  )
	)
	(if (askbool (help @askbool-help) (prompt "Due to the new directory"
		" structure, your old preferences settings are no longer valid and must be"
		" deleted. This will not affect window positions and application private"
		" settings. Please don't worry, instead take"
		" a look at the prefs program's preset menu when"
		" reconfiguring MUI. Do you want to delete the old settings now?"))
	  (
		(run "delete envarc:mui/#?.prefs >nil:")
		(run "delete envarc:mui/MUIPREFS.cfg >nil:")
	  )
	)
    )
  )

;***** We won't delete the catalogs since we aren't replacing them

;  (if (<> (exists "sys:locale/catalogs/Deutsch/MUI.catalog" (noreq)) 0)
;    (
;	(delete
;		("sys:locale/catalogs/Deutsch/MUI.catalog")
;		(help @deletefile-help)
;	)
;    )
;  )



;***** Destination Directory Selection & Creation

  (if (<> (exists "MUI:" (noreq)) 0)
    (
	(if (<> (exists "MUI:MUI-Install" (noreq)) 0)
	  (
	    (set muimsg "Please select a place for \"MagicUserInterface\". A drawer called \"MUI\" will be created here. The minimum space required is about 500 kB.")
	  )
	  (
	    (set @default-dest "MUI:/")
	    (set muimsg "MUI is already installed on your system. Press \"Proceed\" to update your installation or select a different path for the \"MUI\" drawer.")
	  )
	)
    )
    (
	(set muimsg "Please select a place for \"MagicUserInterface\". A drawer called \"MUI\" will be created here. The minimum space required is about 500 kB.")
    )
  )

  (set @default-dest (expandpath @default-dest))

  (set MUI-dest
	(askdir
		(prompt muimsg)
		(help @askdir-help)
		(default @default-dest)
	)
  )

  (set MUI-drawer (tackon MUI-dest "MUI"))

  (if (= (exists MUI-drawer) 2)
    (message
	"A MUI drawer does already exist in the selected directory. By selecting \"Proceed\", "
	"you indicate that you want to update the MUI installation with the "
	"included version (v2.3). Several MUI specific files will be overwritten!"
    )
  )

  (makeassign "MUI" MUI-dest)

;***** Copy the MUI archive to ram and unarc it to the selected directory

  (askdisk
    (dest "WCS1")
    (prompt "Please Insert WCS Disk 1")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS1:MUI.Lha")
    (dest "RAM:")
  )
  ( (working "Installing MagicUserInterface")
    (run "RAM:lha -E -N e RAM:MUI.Lha MUI:")
  )
  (delete "RAM:MUI.Lha")

  (makeassign "MUI" MUI-drawer)

  (set MUI_Installed 1)

)


;=========================================================================
;**** Create directories, make assignments...

(Procedure Make_WCSProgDir
  ( set prog-dest
    (askdir
      (prompt "Please select a directory to install WCS into. Approximately one megabyte of storage space is required.")
      (Help @askdir-help)
      (newpath)
      (default (tackon @default-dest "WCS"))
    )
  )
  ( if (= (exists prog-dest) 0)
    (makedir prog-dest (infos))
  )
  (makeassign "WCSProg" prog-dest)
)

(Procedure Make_WCSProjDir
  ( set proj-dest
    (askdir
      (prompt "Please select a directory to install WCS Projects into. Approximately 6 megabytes of storage space is required.")
      (Help @askdir-help)
      (newpath)
      (default (tackon prog-dest "WCSProjects"))
    )
  )
  ( if (= (exists proj-dest) 0)
    (makedir proj-dest (infos))
  )
  (makeassign "WCSProjects" proj-dest)
)

(Procedure Make_WCSFrameDir
  ( set frame-dest
    (askdir
      (prompt "Please select a directory for WCS Rendered Image output. Animation frames will also be saved here so leave plenty of room.")
      (Help @askdir-help)
      (newpath)
      (default (tackon prog-dest "WCSFrames"))
    )
  )
  ( if (= (exists frame-dest) 0)
    (makedir frame-dest (infos))
  )
  (makeassign "WCSFrames" frame-dest)
)

(Procedure Make_WCSImageDir
  ( set image-dest
    (askdir
      (prompt "Please select directory for WCS Sample Images. A new sub-directory will be created here to hold the images. Approximately 500 kilobytes of storage space are required.")
      (Help @askdir-help)
      (newpath)
      (default image-dest)
    )
  )
  ( if (= (exists image-dest) 0)
    (makedir image-dest (infos))
  )
  (set image-dest (tackon image-dest "InstantGratification"))
  ( if (= (exists image-dest) 0)
    (makedir image-dest (infos))
  )
  (makeassign "WCSImages" image-dest)
)

;=========================================================================
;**** Install WCS

(Procedure Install_WCS
  (if (= Accelerator 1)
    (set WCSVersion
      (askchoice
        (prompt "Please select which version of WCS you wish to Install:")
        (help   "     Two versions of WCS are available:\n\n"
	  "68030 No Math\n"
          "  The 68030 No Math version does not require a\n"
	  "      math coprocessor but will run appreciably\n"
	  "      slower as a result. It is optimized for\n"
	  "      use with a 68030 CPU.\n\n"
	  "68030/40\n"
          "  The 68030/40 version is optimized for\n"
          "      the 68030/40 processors and also requires\n"
          "      a 68881/2 math coprocessor. If you have\n"
          "      an Amiga 3000 or 4000 use this version."
        )
        (choices
          "68030 No Math Processor"
          "68030/68040 With 68881/68882"
        )
        (default Accelerator)
      )
    )
  )


  (Make_WCSProgDir)

  (run ("copy WCS1:ReadMe WCSProg:"))

  (if (= WCSVersion 1)
    (
      (copyfiles
        (prompt "")
        (help "")
        (source "WCS1:WCS.lha")
        (dest "RAM:")
      )

      ( (working "Installing WCS")
        (delete "WCSProg:WCS")
        (run "RAM:lha -E -N e RAM:WCS.lha WCS.MATH WCSProg:")

        (rename "WCSProg:WCS.MATH" "WCSProg:WCS")
      )
      (run ("RAM:lha -E -N e RAM:WCS.lha WCS.info WCSProg:"))
      (run ("RAM:lha -E -N e RAM:WCS.lha WCS.Prefs WCSProg:"))
      (run ("RAM:lha -E -N e RAM:WCS.lha Tools/#? WCSProg:"))

    )
    (
      (copyfiles
        (prompt "")
        (help "")
        (source "WCS1:WCS.lha")
        (dest "RAM:")
      )

      (run ("RAM:lha -E -N e RAM:WCS.lha Tools/#? WCSProg:"))

      (askdisk
        (dest "WCS7")
        (prompt "Please Insert WCS Disk 7")
        (help @askdisk-help)
      )

      (copyfiles
        (prompt "")
        (help "")
        (source "WCS7:WCS.lha")
        (dest "RAM:")
      )

      ( (working "Installing WCS")
        (delete "WCSProg:WCS")
        (run "RAM:lha -E -N e RAM:WCS.lha WCS.NOMATH WCSProg:")

        (rename "WCSProg:WCS.NOMATH" "WCSProg:WCS")
      )
      (run ("RAM:lha -E -N e RAM:WCS.lha WCS.info WCSProg:"))
      (run ("RAM:lha -E -N e RAM:WCS.lha WCS.Prefs WCSProg:"))

      (askdisk
        (dest "WCS1")
        (prompt "Please Reinsert WCS Disk 1")
        (help @askdisk-help)
      )
    )
  )


  (Make_WCSFrameDir)
  (set WCS_Installed 1)

)

;=========================================================================
;**** Install Data

(Procedure Install_Data
  (Make_WCSProjDir)
 
  (Copy_Data)
  (set Data_Installed 1)
)


(Procedure Copy_Data

  (askdisk
    (dest "WCS2")
    (prompt "Please Insert WCS Disk 2")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS2:Data.Lha")
    (dest "RAM:")
  )
  ( (working "Installing Data")
    (run "RAM:lha -E -N e RAM:Data.Lha WCSProjects:")
  )
  (delete "RAM:Data.Lha")

  (askdisk
    (dest "WCS3")
    (prompt "Please Insert WCS Disk 3")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS3:Data.Lha")
    (dest "RAM:")
  )
  ( (working "Installing Data")
    (run "RAM:lha -E -N e RAM:Data.Lha WCSProjects:")
  )
  (delete "RAM:Data.Lha")

  (askdisk
    (dest "WCS4")
    (prompt "Please Insert WCS Disk 4")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS4:Data.Lha")
    (dest "RAM:")
  )
  ( (working "Installing Data")
    (run "RAM:lha -E -N e RAM:Data.Lha WCSProjects:")
  )
  (delete "RAM:Data.Lha")

  (askdisk
    (dest "WCS5")
    (prompt "Please Insert WCS Disk 5")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS5:Data.Lha")
    (dest "RAM:")
  )
  ( (working "Installing Data")
    (run "RAM:lha -E -N e RAM:Data.Lha WCSProjects:")
  )
  (delete "RAM:Data.Lha")

  (askdisk
    (dest "WCS6")
    (prompt "Please Insert WCS Disk 6")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS6:Data.Lha")
    (dest "RAM:")
  )
  ( (working "Installing Data")
    (run "RAM:lha -E -N e RAM:Data.Lha WCSProjects:")
  )
  (delete "RAM:Data.Lha")

  (askdisk
    (dest "WCS7")
    (prompt "Please Insert WCS Disk 7")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS7:Data.Lha")
    (dest "RAM:")
  )
  ( (working "Installing Data")
    (run "RAM:lha -E -N e RAM:Data.Lha WCSProjects:")
  )
  (delete "RAM:Data.Lha")

  (copyfiles
    (prompt "")
    (help "")
    (source "WCS7:DEMData.Lha")
    (dest "RAM:")
  )
  ( (working "Installing Data")
    (run "RAM:lha -E -N e RAM:DEMData.Lha WCSProjects:")
  )
  (delete "RAM:DEMData.Lha")
)

;==========================================================================
;**** Install Images

(Procedure Install_Images

  (if (<> (exists "WCSFrames:" (noreq)) 0)
    ((set image-dest ("WCSFrames:"))
    )
  )

  (Make_WCSImageDir) 

  (Copy_Images)
  (set Images_Installed 1)
)


(Procedure Copy_Images
  (askdisk
    (dest "WCS7")
    (prompt "Please Insert WCS Disk 7")
    (help @askdisk-help)
  )
  (copyfiles
    (prompt "")
    (help "")
    (source "WCS7:InstantGratification")
    (pattern "#?")
    (dest image-dest)
  )
)

;===========================================================================
;**** Modify Startup Sequence

(Procedure Modify_StartUp
  (set NeedMod 0)
  (set ProjAssign ("Assign WCSProjects: %s\n" proj-dest))
  (set FramesAssign ("Assign WCSFrames: %s\n" frame-dest))
  (set NeedMod 1)

  (if (= NeedMod 1)
    (startup "WCS"
      (prompt
        "Some instructions need to be added to the \"S:user-startup\" file "
        "so that your system will be properly configured to use " 
        "the World Construction Set."
      )
      (help "Do this or WCS won't be able to find its data!!")

      (if (= WCS_Installed 1)
        (command
          FramesAssign
        )
      )
      (if (= Data_Installed 1)
        (command
          ProjAssign
        )
      )
    )
  )
)

;=========================================================================
;**** MUI Startup Modifications

(Procedure Modify_MUIStartup
  (set MUIPath   ("Assign MUI: %s\n" MUI-drawer))
  (set LIBSPath  ("Assign add LIBS: MUI:Libs"))

  (startup "MUI"
	(prompt "Some required MUI commands must be added to your \"S:user-startup\" file.")
	(help @startup-help)
	(command
	  MUIPath
	)
	(command
	  LIBSPath
	)
  )
)

;=========================================================================
;**** Show ReadMe file

(Procedure Read_Me
  (set ReadIt
    (askbool
      (prompt "Do you wish to read the 'ReadMe' file which\n"
        "contains last minute notes and updates since\n"
        "the last printing of the manual?\n"
      )
      (help "You'll never know if you don't look.")
      (default 1)
    )
  )

  (if (= ReadIt 1)
    ( (if (= (exists "SYS:c/More" (noreq)) 0)
        (askdisk
          (dest "WCS1")
          (prompt "Please Insert WCS Disk ")
          (help @askdisk-help)
        )
      )
      
      (if (<> (exists "WCSProg:ReadMe" (noreq)) 0)
        (if (<> (exists "SYS:c/More" (noreq)) 0)
          ( (run ("run SYS:c/More WCSProg:ReadMe"))
          )
          ( (run ("run WCS1:c/More WCSProg:ReadMe"))
          )
        )
        ( (askdisk
            (dest "WCS1")
            (prompt "Please Insert WCS Disk 1")
            (help @askdisk-help)
          )
          (if (<> (exists "SYS:c/More" (noreq)) 0)
            ( (run ("run SYS:c/More WCS1:ReadMe"))
            )
            ( (run ("run WCS1:c/More WCS1:ReadMe"))
            )
          )
        )
      )
    )
  )
)

;=============================================================================
;**** Take it away, Johnny...

(set WCS_Installed 0)
(set MUI_Installed 0)
(set Data_Installed 0)
(set Images_Installed 0)
(Config_Options)
(Get_Selections)

(askdisk
  (dest "WCS7")
  (prompt "Please Insert WCS Disk 7")
        (help @askdisk-help)
)

(copyfiles
  (prompt "")
  (help "")
  (source "WCS7:c/Lha")
  (dest "RAM:")
)

(askdisk
  (dest "WCS1")
  (prompt "Please Insert WCS Disk 1")
        (help @askdisk-help)
)

(set prog-dest ("SYS:WCS"))
(set proj-dest ("SYS:WCSProjects"))
(set frame-dest ("SYS:WCSFrames"))
(set image-dest ("SYS:WCSFrames"))
(set MUI-dest ("SYS:MUI"))

(if (BITAND Selection INST_WCS) (Install_WCS))
(if (BITAND Selection INST_MUI) (Install_MUI))
(if (BITAND Selection INST_DATA) (Install_Data))
;(if (BITAND Selection INST_IMAGES) (Install_Images))

(delete "RAM:Lha" "RAM:WCS.lha")
(if (<> (exists "RAM:More" (noreq)) 0)
  (delete "RAM:More")
)
(if (BITAND Selection INST_WCS) (Modify_Startup))
(if (= MUI_Installed 1) (Modify_MUIStartup))
(Read_Me)

(set @default-dest prog-dest)

(exit)
