
; Installation script for InterChange Plus v3.0

; Thanks to ASDG and Black Belt Systems for ideas on Installer scripts.


; How to clean-up anything left in RAM:

(procedure cleanup_done
 (

  (if (= 1 (exists "RAM:Lharc"))
    (delete "RAM:Lharc")
  )

 )
)


; This procedure installs a single module.
; It removes it if it already exists.

;    module_dir		dir name to install to
;    module_thisfile	name of file
;    module_srcdir	disk path of LZH for module
;    module_prefix	the LZH the files are in, minus the 's'

(procedure install_module
 (
  ; Delete the file if it already exists
  (protect (tackon module_dir module_thisfile) "+rwed")
  (delete  (tackon module_dir module_thisfile))

  ; Remove the file from the proper archive

  ;Ex. RAM:Lharc -m x DF0:Converters.LZH RAM:InterChange_Plus/ LightWave_Converter
  ; add >CON:0/50/640/100/Extract to RAM:Lharc to see output

  (run ("RAM:Lharc -m x %s%ss.lzh \"%s/\" \"%s\"" 
	module_srcdir module_prefix module_dir module_thisfile ))

  ; Warn if we couldn't get the file
  (if
    (= 0 (exists (tackon module_dir module_thisfile)))
     (
      (cleanup_done)
      (abort ("An error occurred while installing the file %s. The installation cannot continue." module_thisfile))
     )
  )

  ; And get its icon

  (run ("RAM:Lharc -m x InterChange_Plus:Icons.lzh \"%s/\" \"%s.info\"" 
	module_dir module_thisfile))

 )
)


; This procedure copies a single module
;  module_n		preset to 0
;  module_thisfile	module name
;  module_type		string of Converter, Tool, etc.
;  module_todo		a list of things to install

(procedure install_standard_module
 (
  (set pct (/ (* accum 100) totalfiles))
  (set accum (+ accum 1))
  (complete pct)
  (if (IN module_todo module_n)
      (
       ; (working ("Installing %s %s..." module_thisfile module_type))
       (working ("Installing %s..." module_thisfile))
       (install_module)
      )
  )
 )
)


; Find out which version of AmigaDOS they're using
(set osversion (/ (getversion) 65536))


; Put up a list of choices to install

(set todo
  (askoptions
    (prompt
      "Select the parts of InterChange Plus you'd like to install. "
      "If you need help, click Help now."
    )
    (help
	"Select the first choice to install the InterChange Plus "
	"main program.  You must make this choice."
	"\n\n"
	"Select the second choice to install Converters.  You need to "
	"install at least one Converter.  Install the Converter for "
	"each format that you plan to read or write, import or export. "
	"Examples of Converters are the LightWave_Converter and the "
	"Imagine_Converter."
	"\n\n"
	"Tools - Install Tools that work with "
	"InterChange Plus.  Tools require that you've installed at least "
	"one Converter.  Examples of Tools are Scale and GridSnap."
	"\n\n"
	"InterFont - Install the InterFont Converter, 75 InterFonts, "
	"and the InterFont Designer."
	"\n\n"
	"ARexx Scripts - Install ARexx scripts that enhance your use of "
	"InterChange Plus."
	"\n\n"
	"Sample files - Install sample 3D and surface files "
	"that demonstrate InterChange Plus."
	"\n\n"
	"PC_Tools - MS-DOS, AutoCAD and 3D Studio tools.  These require "
        "an MS-DOS computer."
	"\n\n"
	"Full installation requires about 3 megabytes of space."
	"\n\n"
        @askdir-help
    )

    ; Selecting these Boolean gadgets set 'todo' to [0 1 2 3 4 5 6] respectively
    (choices
	"InterChange Plus"	; 0
	"Converters"		; 1
	"Tools"			; 2
	"InterFont"		; 3
	"ARexx Scripts"		; 4
	"Sample files"		; 5
	"PC_Tools"		; 6
    )
  )
)


; Install their selections


; If they chose nothing from the main install list...

(if (= todo 0)
  (abort "You must choose something to install.  Or, click Abort.")
)


; If they choose anything from the main install list, 
; then make the InterChange_Plus drawer...

(if (AND todo 6)
  (

    ; Get the directory to install ICP
    (set @default-dest
      (askdir

	; This message must be a one- or two-liner or you crash
	; Or "Click Proceed to install ICP here or
	; select another location"
        (prompt "Where should InterChange Plus be installed?" )

        (help 

	  "Select the disk volume where the InterChange Plus "
	  "drawer should be installed."
	  "\n\n"

	  "If this is the first time you've installed InterChange "
	  "Plus, select the disk volume where you'd like the "
	  "InterChange Plus drawer to be installed."
	  "\n\n"

	  "If you are installing for a second time, select the "
	  "disk volume where your previously installed "
	  "InterChange Plus drawer resides."
	  "\n\n"

          @askdir-help
        )

;	  "You must select a disk volume where InterChange "
;	  "Plus will be installed, or where you installed it "
;	  "last time."

        (default "SYS:")
      )
    )

    ; Add "InterChange_Plus" to whatever they entered
    (set @default-dest (tackon @default-dest "InterChange_Plus"))

    ; Make this InterChange_Plus drawer if it's not already there
    (if
      (= (exists @default-dest) 0)
      (makedir @default-dest)
    )

    ; And the icon for the drawer
    (copyfiles
      (prompt "" )
      (help "" )
      (source "InterChange_Plus:ICP_Drawer_Icon" )
      (dest @default-dest)
    )

    ; Move it by renaming upwards
    (rename (tackon @default-dest "ICP_Drawer_Icon") 
	    (tackon @default-dest "/InterChange_Plus.info"))


    ; Copy the req.library to LIBS:
    (onerror
      (abort
        "The file req.library could not be copied to your LIBS: directory. "
        "This might be because the disk which contains your LIBS: "
        "directory has no room, or it is write protected.  This "
        "installation cannot continue."
      )
    )
    (copylib
      (prompt "Copying req.library to LIBS:")
      (help
        "The ASDG file requester library must be installed. "
        "It will replace any copy you already have with a "
        "newer version.\n\n"
        @copylib-help
      )
      (source "InterChange_Plus:libs/req.library")
      (dest "LIBS:")
      (confirm)
    )


  )
)


; Always copy lharc to RAM:

(onerror
)

(copyfiles
  (prompt "" )
  (help "")
  (source "InterChange_Plus:C/lharc")
  (dest "RAM:")
)

(if
  (= 0 (exists "RAM:Lharc"))
  (abort
	"The files needed for installation could not be copied "
	"to the RAM disk.  You need at least 350K RAM free."
  )
)


; If anything goes wrong after this, clean up

(onerror cleanup_done)


; Install the main InterChange program

(if
  (IN todo 0)
  (
    (working "Installing InterChange Plus...")

    ; Preset the percent-done stuff
    (set totalfiles 2)
    (set accum 0)
    (set pct (/ (* accum 100) totalfiles))
    (set accum (+ accum 1))
    (complete pct)


    ; If the files already exist, delete them
    (protect (tackon @default-dest "InterChange_Plus") "+rwed")
    (delete (tackon @default-dest "InterChange_Plus"))

    (protect (tackon @default-dest "InterChange_Plus.info") "+rwed")
    (delete (tackon @default-dest "InterChange_Plus.info"))


    ; Retrieve InterChange Plus and Converter_List
    (run ("RAM:Lharc -m x InterChange_Plus:InterChange.LZH \"%s/\" *" 
	@default-dest))


    ; If under AmigaDOS 2.0, ask if they want an automatic ASSIGN
    ;(if (>= osversion 36)

      (startup "InterChange Plus"

        (prompt "Add an IC_PLUS: assignment to \"S:User-Startup\"?" )

        (help
          "Select YES to automatically set a logical 'ASSIGN' "
	  ;"assignment on startup, placing it in AmigaDOS 2.0's "
	  ;"User-Startup script stored in S:."
	  ;"\n"
          @startup-help
        )

	; This is the only command we put in User-Startup
        (command ("ASSIGN IC_PLUS: %s" @default-dest))
      )

    ;)

    ; Retrieve startup icon and script
    (run ("RAM:Lharc -m x InterChange_Plus:Icons.LZH \"%s/\" ICP_Start*" @default-dest ))

    ; And empty stat icon
    (run ("RAM:Lharc -m x InterChange_Plus:Icons.LZH \"%s/\" Empty*" @default-dest ))

    ; Make the assignment IC_PLUS to the destination directory
    (makeassign "IC_PLUS" @default-dest)

    (set module_dir @default-dest)

  )
)


; Install Converters

(if
  (IN todo 1)
  (
    (working "Installing Converters...")

    ; Preset the percent-done stuff
    (set totalfiles 13)
    (set accum 0)
    (set pct (/ (* accum 100) totalfiles))
    (set accum (+ accum 1))
    (complete pct)


    (set mtodo1 65535)
    (set mtodo2 65535)
    (set mtodo3 65535)
    (set mtodo4 65535)
    (set mtodo5 65535)
    (set mtodo6 65535)
    (set mtodo7 65535)

    ; If they want to do an expert install
    (if (= @user-level 2)
      (

        (set mtodo1
          (askoptions
            (prompt "Select Converters to install:" )
            (help "These Converters work with 3D data." )
            (choices
		"Sculpt_Converter"
		"VideoScape3D_Converter"
		"Imagine_Converter"
		"TurboSilver_Converter"
		"LightWave_Converter"
		"PAGErender_Converter"
		"CAD3D_Converter"
		"Statistics_Converter"
		"Surface_Converter"
		"VistaDEM_Converter"
		"InterFont_Converter"
		"3DStudio_Converter"
		"AutoCAD_Converter"
		"Wavefront_Converter"
            )
          )
        )

        (set mtodo2
          (askoptions
            (prompt "Select Converters to install:" )
            (help "These Converters work with structured drawings." )
            (choices
		"AegisDraw_Converter"
		"ProDraw_Converter"
		"ISHape_Converter"
            )
          )
        )
      )
      ; Else if not user-level 2
    )

    (set module_srcdir "InterChange_Plus:")

    ; Copy Converters group 1
    (set module_n 0)
    (set module_type "Converter")
    (set module_prefix "Converter")
    (set module_todo mtodo1)
    (while (set module_thisfile 
	(select module_n 
		"Sculpt_Converter"
		"VideoScape3D_Converter"
		"Imagine_Converter"
		"TurboSilver_Converter"
		"LightWave_Converter"
		"PAGErender_Converter"
		"CAD3D_Converter"
		"Statistics_Converter"
		"Surface_Converter"
		"VistaDEM_Converter"
		"InterFont_Converter"
		"3DStudio_Converter"
		"AutoCAD_Converter"
		"Wavefront_Converter"
		""
	))
      (install_standard_module)
      (set module_n (+ module_n 1))
    )

    ; Copy Converters group 2
    (set module_n 0)
    (set module_type "Converter")
    (set module_prefix "Converter")
    (set module_todo mtodo2)
    (while (set module_thisfile 
	(select module_n 
		"AegisDraw_Converter"
		"ProDraw_Converter"
		"ISHape_Converter"
		""
	))
      (install_standard_module)
      (set module_n (+ module_n 1))
    )

  )
)


; Install Tools

(if
  (IN todo 1)
  (
    (working "Installing Tools...")

    ; Preset the percent-done stuff
    (set totalfiles 3)
    (set accum 0)
    (set pct (/ (* accum 100) totalfiles))
    (set accum (+ accum 1))
    (complete pct)


    (set mtodo1 65535)
    (set mtodo2 65535)
    (set mtodo3 65535)
    (set mtodo4 65535)
    (set mtodo5 65535)
    (set mtodo6 65535)
    (set mtodo7 65535)

    ; If they want to do an expert install
    (if (= @user-level 2)
      (

        (set mtodo1
          (askoptions
            (prompt "Select Tools to install:" )
            (help "These Tools modify 3D data." )
            (choices
		"Scale_Tool"
		"PointReduce_Tool"
		"GridSnap_Tool"
            )
          )
        )

      )
      ; Else if not user-level 2
    )

    (set module_srcdir "InterChange_Plus:" )

    ; Copy Tools group
    (set module_n 0)
    (set module_type "Tool")
    (set module_prefix "Tool")
    (set module_todo mtodo1)
    (while (set module_thisfile 
	(select module_n 
		"Scale_Tool"
		"PointReduce_Tool"
		"GridSnap_Tool"
		""
	))
      (install_standard_module)
      (set module_n (+ module_n 1))
    )

  )
)


; Install InterFonts

(if
 (IN todo 3)
  (

   (working "Installing InterFonts..." )

   ; Set name for subdir for InterFonts
   (set @execute-dir (tackon @default-dest "InterFonts" ))

   ; Make the directory if it's not already there
   (if
     (= (exists @execute-dir) 0)
     (makedir @execute-dir)
   )

   (askdisk
    (prompt ("Please insert the second InterChange Plus disk."))
    (help "This disk is necessary for this installation. ")
    (dest "InterChange_2")
   )

   ; Un-arc all the InterFonts
   (run ("RAM:Lharc -m x InterChange_2:InterFonts.LZH %s *" @execute-dir ))

   (askdisk
    (prompt ("Please insert the first InterChange Plus disk."))
    (help "This disk is necessary for this installation. ")
    (dest "InterChange_Plus")
   )

   ; And the icon for the InterFont drawer
   (run ("RAM:Lharc -m x InterChange_Plus:Icons.LZH \"%s/\" InterFonts.info*" @default-dest ))

  )
)


; Install ARexx scripts

(if
 (IN todo 4)
  (

   (set @execute-dir

    (askdir

     (prompt "Please select a drawer for ARexx script(s)." )

     (help
     "This installs ARexx scripts for program-driven\n"
     "control of InterChange Plus and Converters.\n"
     "\n"
     "If you don't own ARexx or AmigaDOS 2.0, then you\n"
     "can safely abort the installation now.\n"
     @askdir-help
     )

     (default "REXX:" )
    )
   )

   (run ("RAM:Lharc -m x InterChange_Plus:ICP_ARexx.lzh %s" @execute-dir))

  )
)


; Install Sample files

(if
 (IN todo 5)
  (

   (working "Installing Sample files..." )

   ; Set name for subdir for Samples
   (set @execute-dir (tackon @default-dest "SampleFiles" ))

   ; Make the directory if it's not already there
   (if
     (= (exists @execute-dir) 0)
     (makedir @execute-dir)
   )

   ; Un-arc all the sample files
   (run ("RAM:Lharc -m x InterChange_Plus:SampleFiles.LZH %s *" @execute-dir ))

   ; And the icon for the drawer
   (run ("RAM:Lharc -m x InterChange_Plus:Icons.LZH \"%s/\" SampleFiles.info*" @default-dest ))

  )
)


; Install PC_Tools

(if
 (IN todo 6)
  (

   (working "Installing PC_Tools..." )

   ; Set name for subdir for PC_Tools
   (set @execute-dir (tackon @default-dest "PC_Tools" ))

   ; Make the directory if it's not already there
   (if
     (= (exists @execute-dir) 0)
     (makedir @execute-dir)
   )

   (askdisk
    (prompt ("Please insert the second InterChange disk."))
    (help "This disk is necessary for this installation. ")
    (dest "InterChange_2")
   )

   ; Un-arc all the PC_Tools
   (run ("RAM:Lharc -m x InterChange_2:PC_Tools.LZH %s *" @execute-dir ))

   (askdisk
    (prompt ("Please insert the first InterChange disk."))
    (help "This disk is necessary for this installation. ")
    (dest "InterChange_Plus")
   )

   ; And the icon for the PC_Tools drawer
   (run ("RAM:Lharc -m x InterChange_Plus:Icons.LZH \"%s/\" PC_Tools.info*" @default-dest ))

  )
)


; Remove the lharc program from RAM:

(cleanup_done)

(complete 100)

(exit)

