;Installer script for PCBDesigner 0.34.
;by Grzegorz Kraszewski 1997
;$VER: PCBDesigner install 0.34 (28.10.97)

(complete 0)

;*********** Installer version checking

(if (< @installer-version 2818051)
    (abort "This script requires Installer v43.3 or newer. Please update.")
)

;*********** Check if MUI is installed.

(set #muiversion (getversion "LIBS:muimaster.library"))

(if (= #muiversion 0)
    (abort "You haven't installed Magic User Interface (MUI), which is required by PCBDesigner (read the manual).")
)

;*********** Check MUI version. Expert gets additional informations.

(if (< #muiversion 720896)
    (
      (if (= @user-level 2)
          (
            (set #version (/ #muiversion 65536))
            (set #revision (- #muiversion (* #version 65536)))
             (message ("You have \"muimaster.library\" %ld.%ld installed, while PCBDesigner requires 11.0 or higher." #version #revision))
          )
      )
      (abort "Your Magic User Interface (MUI) is too old. Please upgrade. PCBDesigner requires version 3.0 or higher (read the manual).")
    )
)

;*********** Get destination directory from user.

(set #instdir
  (askdir 
    (prompt "Where to make \"PCBDesigner\" drawer?")
    (help "You have to choose place on the harddisk, where PCBDesigner will be installed. \"PCBDesigner\" drawer will be created, all neccesary files will be placed in.")
    (default @default-dest)
  )
)

;*********** Get full destination path.

(set #destdir
  (tackon #instdir "PCBDesigner")
)

;*********** Ask for installing additional files (not in NOVICE mode).

;*********** NOVICE:

(if (= @user-level 0)
    (
      (set #instaldoc 1)
      (set #installocpl 0)
      (set #instalcdct 0)
      (set #instaldocpl 0)
      (set #instalconfig 1)
    )
)

;*********** ADVANCED:

(if (= @user-level 1)
    (
      (set #bitmask
        (askoptions
          (prompt "Which additional files do You want to install?")
          (help "Select additional elements of PCBDesigner, they are not neccesary to run the program, but makes work easier and nicer.")
          (choices "documentation")
        )
      )
      (if (BITAND #bitmask $00000001)
          (set #instaldoc 1)
          (set #instaldoc 0)
      )
      (set #installocpl 0)
      (set #instalcdct 0)
      (set #instaldocpl 0)
      (set #instalconfig 1)
    )
)

;*********** EXPERT:

(if (= @user-level 2)
    (
      (set #bitmask
        (askoptions
          (prompt "Which additional files do You want to install?")
          (help "Select additional elements of PCBDesigner, they are not neccesary to run the program, but makes work easier and nicer.")
          (choices "documentation" "default configuration" ".cd file" "Polish documentation" "Polish locale")
        )
      )
      (if (BITAND #bitmask $00000001)
          (set #instaldoc 1)
          (set #instaldoc 0)
      )
      (if (BITAND #bitmask $00000002)
          (set #instalconfig 1)
          (set #instalconfig 0)
      )
      (if (BITAND #bitmask $00000004)
          (set #instalcdct 1)
          (set #instalcdct 0)
      )
      (if (BITAND #bitmask $00000008)
          (set #instaldocpl 1)
          (set #instaldocpl 0)
      )
      (if (BITAND #bitmask $00000010)
          (set #installocpl 1)
          (set #installocpl 0)
      )
    )
)

;*********** Ask for overwrite old version.


(if (> @user-level 0)
    (if (exists #destdir)
        (if (NOT (askbool
                   (prompt "ATTENTION! Directory " #destdir " already exists. Overwrite old files? (icons won't be overwritten)")
                   (help "Directory \"PCBDesigner\" already exist in \"" #instdir "\". If You continue installation all old PCBDesigner files (except icons) will be replaced by new ones. Icons will stay intact, so You neend't rearrange them.")
                 )
            )
            (abort "Installation aborted.")
        )
    )
)

;*********** Creating dest drawer.
         
(makedir #destdir)

(complete 10)

;*********** Copying main file.

(copyfiles
  (source "PCBDesigner")
  (dest #destdir)
)

(complete 30)

;*********** Copying images.

(copyfiles
  (source "Images")
  (dest (tackon #destdir "Images"))
  (all)
)

(complete 50)

;*********** Copying English docs.

(if (= #instaldoc 1)
    (
      (copyfiles
        (source "Docs/PCBDesigner.guide")
        (dest (tackon #destdir "Docs"))
      )
      (if (NOT (exists (tackon #destdir "Docs/PCBDesigner.guide.info")))
          (copyfiles
            (source "Docs/PCBDesigner.guide.info")
            (dest (tackon #destdir "Docs"))
          )
      )
      (copyfiles
        (source "Docs/AFD-COPYRIGHT")
        (dest (tackon #destdir "Docs"))
      )
    )
)

;*********** Copying Polish docs.

(if (= #instaldocpl 1)
    (
      (copyfiles
        (source "Docs/PCBDesignerPL.guide")
        (dest (tackon #destdir "Docs"))
      )
      (if (NOT (exists (tackon #destdir "Docs/PCBDesignerPL.guide.info")))
          (copyfiles
            (source "Docs/PCBDesignerPL.guide.info")
            (dest (tackon #destdir "Docs"))
          )
      )
      (copyfiles
        (source "Docs/AFD-COPYRIGHT.pl")
        (dest (tackon #destdir "Docs"))
      )
    )
)

(complete 70)

;*********** Copying Polish locale.

(if (= #installocpl 1)
    (
      (makedir (tackon #destdir "Catalogs"))
      (copyfiles
        (source "Catalogs/polski/pcbdesigner.catalog")
        (dest (tackon #destdir "Catalogs/polski"))
      )
    )
)

(complete 85)

;*********** Copying .cd file.

(if (= #instalcdct 1)
    (copyfiles
      (source "Catalogs/pcbdesigner.cd")
      (dest (tackon #destdir "Catalogs"))
    )
)

(complete 90)

;*********** Copying default configuration file to ENVARC:

(if (= #instalconfig 1)
    (
      (if (exists "ENVARC:mui/PCBDESIGNER.1.cfg")
          (if (= @user-level 2)
              (set #instalconfig
                (askbool
                  (prompt "PCBDesigner configuration file in ENVARC:mui drawer already exists. Overwrite it with defaults?")
                  (help "If You overwrite Your configuration file all program settings changes to defaults.")
                )
              )
              (set #instalconfig 0)
          )
      )
      (if (= #instalconfig 1)
          (copyfiles
            (source "PCBDESIGNER.1.cfg")
            (dest "ENVARC:mui")
          )
      )
    )
)

(complete 95)

;*********** Copying icons.

;*********** Copying main drawer icon.

(if (NOT (exists (tackon #instdir "PCBDesigner.info")))
    (copyfiles
      (source "PCBdrawer.icon")
      (newname "PCBDesigner.info")
      (dest #instdir)
    )
)

;*********** Copying program icon.

(if (NOT (exists (tackon #destdir "PCBDesigner.info")))
    (copyfiles
      (source "PCBDesigner.info")
      (dest #destdir)
    )
)

;*********** Copying Docs drawer icon.

(if (AND (= #instaldoc 1) (NOT (exists (tackon #destdir "Docs.info"))))
    (copyfiles
      (source "Docs.info")
      (dest #destdir)
    )
)

(complete 100)

(set @default-dest #instdir)

(exit)
