; $VER: Install-Plotter3D 1.85 (27.10.96)

;##############################################################################
; global variables

(set ul_novice  0)
(set ul_average 1)
(set ul_expert  2)

; last_choice contains the result of the last askoptions-call
(set last_choice       0)
; need_conformation is used by CHECK_USERLEVEL
(set need_confirmation 1)

;##############################################################################
; Localize
;

(if (= @language "deutsch")
  (
    (set #update "Update")
    (set #abort  "Abbrechen")

    (set #intro_1 "Willkommen zum Plotter3D Installation programm.")

    (set #cp_main   "Installiere Hauptprogramm 'Plotter3D'.")
    (set #cp_docs   "Installiere Documentation.")
    (set #cp_locale "Installiere Sprachen.")
    (set #cp_funcs  "Kopiere Beispiel-Funktionen.")
    (set #cp_mats   "Kopiere Beispiel-Materialen.")
    (set #cp_lights "Kopiere Beispiel-Lightquellen.")
    (set #cp_pals   "Kopiere Standard-Farbpaletten.")

    (set #ask_update  "Plotter3D ist schon auf ihrem System installiert.\nSie können diese Installation updaten oder abbrechen.")
    (set #ask_docs    "Bitte wählen Sie die Sprache(n) für die AmigaGuide Dokumentation aus.")
    (set #ask_locale  "Bitte wählen Sie die Sprache(n) aus, die Sie installieren wollen.")
    (set #ask_funcs   "Bitte wählen Sie die zu installierenden Beispiele aus.\n(Empfohlen: Alle)")
    (set #ask_drawers "Bitte wählen Sie die Verzeichnisse aus, die kopiert werden sollen.\n(Empfohlen: Alle)")
    (set #ask_others  "Bitte wählen Sie die Dateien aus, die kopiert werden sollen.")

    (set #destdir "Bitte wählen Sie einen Platz für Plotter3D. Ein Verzeichnis namens 'Plotter3D' wird dort automatisch erzeugt.")
    (set #startup "Einige Kommandos werden zu ihrer \"s:user-startup\" Datei gefügt.")

    (set #user_abort "Fehler: Abbruch durch den Benutzer.")
  )
  (
    (set #update "Update")
    (set #abort  "Abort")

    (set #intro_1 "Welcome to the Plotter3D installation program.")

    (set #cp_main   "Installing main program 'Plotter3D'.")
    (set #cp_docs   "Installing documentation.")
    (set #cp_locale "Installing languages.")
    (set #cp_funcs  "Copying example functions.")
    (set #cp_mats   "Copying example materials.")
    (set #cp_lights "Copying example lightsources.")
    (set #cp_pals   "Copying standard colorpalettes.")

    (set #ask_update  "Plotter3D is already installed on your system.\nYou can make an update or abort.")
    (set #ask_docs    "Select the language(s) of AmigaGuide documentations you wish to install.")
    (set #ask_locale  "Select the language(s) you wish to install.")
    (set #ask_funcs   "Select the examples you wish to install.\n(Recommended: All)")
    (set #ask_drawers "Select the drawers you wish to copy.\n(Recommended: All)")
    (set #ask_others  "Select the files you wish to copy.")

    (set #destdir "Please select a place for the Plotter3D package. A drawer called 'Plotter3D' will be created here.")
    (set #startup "Some commands will be added to your \"s:user-startup\" file.")

    (set #user_abort "Error: User abort.")
  )
)

;#############################################################################
; procedure N_MAKEDIR
; creates a new drawer and copies the icon.
;
; #spath - source path
; #dpath - destination path
; #name  - name of drawer

(procedure N_MAKEDIR #spath #dpath #name
  (
    (if (= (exists (tackon #dpath #name) (noreq)) 0)
      (
        (makedir
          (help @makedir-help)
          (tackon #dpath #name)
        )
        (set #spath (expandpath #spath))
        (copyfiles
          (help @copyfiles-help)
          (source (tackon #spath (cat #name ".info")))
          (dest #dpath)
          (infos)
        )
      )
    )
  )
)

;##############################################################################
; procedure COPYDIR
; copies a whole directory including all subdirectories. If an file exists
; it is not overwritten if it has an higher version.
;
; #name - name of directory
; #help - text shown during copy

(procedure COPYDIR #name #help
  (
    (foreach #name "#?"
      (
        (if (> @each-type 0)
          (
            (COPYDIR (tackon #name @each-name) #help)
          )
          (
            (set cd_source (tackon #name @each-name))
            (set cd_dest   (tackon (tackon @default-dest #name) @each-name))
            (if (= (exists cd_dest) 0)
              (set cd_doit TRUE)
              (
                (set cd_doit FALSE)
                (set cd_version (GETVERSION cd_dest))
                (if (<> cd_version 0)
                  (if (> (GETVERSION cd_source) cd_version)
                    (set cd_doit TRUE)
                  )
                )
              )
            )
            (if cd_doit
              (copyfiles
                (prompt #help)
                (help @copyfiles-help)
                (source cd_source)
                (dest (tackon @default-dest #name))
              )
            )
          )
        )
      )
    )
  )
)

;##############################################################################
; procedure COPYFILE
; copies a file (with icon)
;
; #path   - path of file
; #name   - name of file
; #prompt - text for prompt
;
(procedure COPYFILE #path #name #prompt
  (
    (copyfiles
      (prompt #prompt)
      (help @copyfiles-help)
      (source (tackon #path #name))
      (dest (tackon @default-dest #path))
      (infos))
  )
)

;##############################################################################
; procedure CHECK_USERLEVEL
; set variable need_confirmation to TRUE if current user level is higher or
; equal to #minlevel.
;
; #minlevel    - minimal user level (ul_XXX)
; #last_choice - default value for last_choice variable
;
(procedure CHECK_USERLEVEL #minlevel #last_choice
  (
    (if (>= @user-level #minlevel)
      (
        (set need_confirmation TRUE)
      )
      (
        (set last_choice #last_choice)
        (set need_confirmation FALSE)
      )
    )
  )
)

;(procedure USER_ABORT
;  (
;    (ABORT #user_abort)
;  )
;)

;##############################################################################
; start

(complete 0)

(if (<> (exists "plotter3d:" (noreq)) 0)
  (
    (if (askbool (prompt #ask_update) (choices #update #abort) (help @askbool-help))
      (
        (set @default-dest (expandpath "plotter3d:/"))
      )
      (
        (exit (quiet))
      )
    )
  )
  (
    (set @default-dest
      (askdir
        (prompt #destdir)
        (help @askdir-help)
        (default @default-dest)
      )
    )
    (set @default-dest (expandpath @default-dest))
    (N_MAKEDIR "/" @default-dest "Plotter3D")
    (tooltype (dest (tackon @default-dest "Plotter3D")) (noposition))
  )
)

(complete 10)
(set @default-dest (tackon @default-dest "Plotter3D"))

;##############################################################################
; copy Main Program

(copylib
  (prompt #cp_main)
  (help @copylib-help)
  (source "Plotter3D")
  (dest @default-dest)
  (infos)
)

;##############################################################################
; copy documentation

(complete 20)
(N_MAKEDIR "" @default-dest "Docs")
(COPYFILE "Docs" "History" #cp_docs)
(COPYFILE "Docs" "Bugs"    #cp_docs)

(CHECK_USERLEVEL ul_average -1)
(if need_confirmation
  (set last_choice
    (askoptions
       (prompt #ask_docs)
       (choices "English" "Deutsch")
       (help @askoptions-help)
    )
  )
)
(if (<> last_choice 0)
  (
    (if (BITAND last_choice 1) ( (N_MAKEDIR "Docs" (tackon @default-dest "Docs") "English") (COPYDIR "Docs/English" #cp_docs)))
    (if (BITAND last_choice 2) ( (N_MAKEDIR "Docs" (tackon @default-dest "Docs") "Deutsch") (COPYDIR "Docs/Deutsch" #cp_docs)))
  )
)

;##############################################################################
; copy Locale

(complete 30)
(CHECK_USERLEVEL ul_average -1)
(if need_confirmation
  (set last_choice
    (askoptions
      (prompt #ask_locale)
      (choices "English" "Deutsch" "Français")
      (help @askoptions-help)
    )
  )
)
(if (> last_choice 1)
  (
    (makedir (tackon @default-dest "Catalogs"))
    (if (BITAND last_choice 2) ( (COPYDIR "Catalogs/Deutsch" #cp_locale) ))
    (if (BITAND last_choice 4) ( (COPYDIR "Catalogs/Français" #cp_locale) ))
  )
)

;##############################################################################
; install functions etc.

(complete 40)
(CHECK_USERLEVEL ul_expert -1)
(if need_confirmation
  (set last_choice
    (askoptions
      (prompt #ask_funcs)
      (choices "Functions" "Materials" "Lightsources" "Palettes")
      (help @askoptions-help)
    )
  )
)
(if (BITAND last_choice 1) ( (N_MAKEDIR "" @default-dest "Functions") (COPYDIR "Functions" #cp_funcs )))
(if (BITAND last_choice 2) ( (N_MAKEDIR "" @default-dest "Materials") (COPYDIR "Materials" #cp_mats  )))
(if (BITAND last_choice 4) ( (N_MAKEDIR "" @default-dest "Lights"   ) (COPYDIR "Lights"    #cp_lights)))
(if (BITAND last_choice 8) ( (N_MAKEDIR "" @default-dest "Palettes" ) (COPYDIR "Palettes"  #cp_pals)))

;##############################################################################
; copy other drawers

(complete 60)
(CHECK_USERLEVEL ul_expert -1)
(if need_confirmation
  (set last_choice
    (askoptions
      (prompt #ask_drawers)
      (choices "Imagebuttons" "Preferences" "Tools")
      (help @askoptions-help)
    )
  )
)
(if (BITAND last_choice 1) ( (N_MAKEDIR "" @default-dest "Images") (COPYDIR "Images" "")))
(if (BITAND last_choice 2) ( (N_MAKEDIR "" @default-dest "Prefs" ) (COPYDIR "Prefs"  "")))
(if (BITAND last_choice 4) ( (N_MAKEDIR "" @default-dest "Tools" ) (COPYDIR "Tools"  "")))

;##############################################################################
; install functions etc.

(complete 80)
(CHECK_USERLEVEL ul_average -1)
(if need_confirmation
  (set last_choice
    (askoptions
      (prompt #ask_others)
      (choices "Preview picture")
      (help @askoptions-help)
    )
  )
)
(if (BITAND last_choice 1) (copyfiles (source "PreviewPic") (dest @default-dest) (infos) (help @copyfiles-help)))

;##############################################################################
; startup-sequence

(complete 90)
(startup "Plotter3D"
  (prompt #startup)
  (help @startup-help)
  (command "assign Plotter3D: \"" @default-dest "\"")
  (confirm "expert")
)

(makeassign "Plotter3D" @default-dest)

(complete 100)
