;=============================================================================;
;
; $VER: DT_Install 2.32 (30.06.2000)
;
; Installation script for DeliTracker II
; (c) Copyright 1994-2000 by Frank Riffel and Peter Kunath
;
; French installation by Acechan of THE END  (10.05.95)
;
;=============================================================================;
;=============================================================================;
;=============================================================================;
;
; This is a quick description of how this script works:
;
; 1. INIT_STUFF
;
; 2. CHECK_INSTALLED_VERSION:
;    NO_VERSION  => CHOOSE_DESTINATION
;            (suggestion Work: or SYS:)
;    OLD_VERSION => UNINSTALL_OLD
;    NEW_VERSION => EXIT
;
; 3. MAIN                                                      ~  80 KB
;
; 4. PLAYERS (default players, ask further players to install) ~ 500 KB
; 
; 5. ASK PLAYSID                                               ~  20 KB
;
; 6. ASK PLAYAY                                                ~ 100 KB
;
; 7. GENIES (default genies, ask further genies to install)    ~ 300 KB
;
; 8. AREXX (ask user)                                          ~  15 KB
;
; 9. LIBS (ask user, suggested)                                ~  40 KB
;
; 10.DOCS (depending on language)                              ~ 110 KB
;                                                              
; 11.DEVELOPER_DOCS (ask only ADVANCED)                        ~ 160 KB
;                                                                ======
;                                                      TOTAL   ~ 1.3 MB
;
;=============================================================================;
;=============================================================================;
;=============================================================================;
;
; Some initial stuff like kick version check, language selection, ...

(if (= @LANGUAGE "english")
 (
  (set def_pat "#?.eng#?")

  (set #bad-kick
  (cat "DeliTracker 2.0 will only run under Kickstart 2.04 or above!"
  ))

  (set #abort-t
  (cat "Make sure that T: is large enough to hold 500KB."
  ))

  (set #invalid-env
  (cat "\nENV:DeliConfig doesn't point to a valid directory. It has been deleted.\n\n To install DeliTracker, run this script again."
  ))
 
  (set #abort-no-space
  (cat "You need at least 850.000 Bytes of free store to install DeliTracker II"
  ))

  (set #choose-text
  (cat "Please choose a directory where DeliTracker should be installed. A drawer will be created there."
  ))

  (set #choose-help
  (cat "In this location a drawer will be created. All files, except the libraries, will be installed inside this drawer. The complete installation will require about 1MB of free harddisk space."
  ))

  (set #create-maindir
  (cat "Creating DeliTracker directory"
  ))

  (set #create-configdir
  (cat "Creating Config directory"
  ))

  (set #set-path
  (cat "Setting up configuration path"
  ))

  (set #inst-main
  (cat "Installing main program."
  ))

  (set #create-docsdir
  (cat "Creating Docs dir"
  ))

  (set #inst-docs
  (cat "Installing program documentation"
  ))

  (set #ask-xpk
  (cat "Do you wish to install the decompression libraries?"
  ))

  (set #xpk-help
  (cat "It's suggested that you install the decompression libraries, even if you currently don't have packed modules!"
  ))

  (set #create-comressorsdir
  (cat "Creating Libs:Compressors dir"
  ))

  (set #create-playerdir
  (cat "Creating Player dir"
  ))

  (set #create-playerstore
  (cat "Creating PlayerStore"
  ))

  (set #ask-players
  (cat "Which Players should be activated?"
  ))

  (set #ask-additional-players
  (cat "Activate further players ? These players are not widespread. The average user won't need them to be activated. We suggest that you select 'NO'!"
  ))

  (set #ask-players-2
  (cat "Which additional Players should be activated? Think twice before selecting!"
  ))

  (set #ask-playsid
  (cat "Would you like to install the PlaySID deliplayer?\nNote: This deliplayer uses the playsid.library, which is SHAREWARE!. Please read the supplied documentation for further information."
  ))

  (set #ask-playay
  (cat "Would you like to install the PlayAY deliplayer?\n(This player emulates the AY soundchip of the ZX Spectrum)"
  ))

  (set #player-help
  (cat "Select the players you want to be loaded at startup. Please choose only the ones you REALLY need and you have modules for. All other ones will be installed in the PlayerStore directory, so you may load them later."
  ))

  (set #create-geniedir
  (cat "Creating Genie dir"
  ))

  (set #create-geniestore
  (cat "Creating GenieStore"
  ))

  (set #ask-genies
  (cat "Which genies should be activated?"
  ))

  (set #genie-help
  (cat "All genies that are not activated will be installed in the GenieStore directory. For further informations about particular genies, please refer to Genies.eng."
  ))

  (set #ask-arexx
  (cat "Do you wish to install ARexx scripts?"
  ))

  (set #help-arexx
  (cat "Only choose this if you really use ARexx!"
  ))

  (set #create-arexx
  (cat "Creating ARexx dir"
  ))

  (set #ask-pdocs
  (cat "Do you wish to install Programming documentation?"
  ))

  (set #help-pdocs
  (cat "Only choose this if you plan to write your own players or genies."
  ))

  (set #create-pdocs
  (cat "Creating Developer dir"
  ))

  (set #extract-players
  (cat "Extracting Players"
  ))

  (set #extract-genies
  (cat "Extracting Genies"
  ))

  (set #extract-arexx
  (cat "Extracting and installing ARexx Scripts"
  ))

  (set #extract-docs
  (cat "Extracting and installing Docs"
  ))

  (set #extract-libs
  (cat "Extracting and installing Libs"
  ))

  (set #extract-pdocs
  (cat "Extracting and installing development stuff"
  ))
   
  (set #final-msg
  (cat "To configure the genies, repeat the following steps for each genie:\n\n1. Open the genie GUI with the 'Show' function.\n\n2. Activate the window and move it to the position where it should pop up.\n\n3. Set your defaults. You will find various op\
tions in the 'Settings' Menu. In particular: If you want the window to be opened every time DeliTracker is started, turn 'Popup' on.\n\n4. Select 'Save Prefs' from the 'Project' Menu."
  ))

  ; Update Strings

  (set #remove-old
  (cat "All old files will be removed."
  ))

  (set #proceed
  (cat "Proceed"
  ))

  (set #abort
  (cat "Abort"
  ))

  (set #remove-old-help
  (cat "If you'd like to keep your current installation, you'll have to delete ENV:DELICONFIG and run this script again. Make sure that you select a different location for the new installation."
  ))

  (set #removing-dt
  (cat "Removing old files"
  ))

  (set #already-newer-installed
  (cat "The installation was aborted because this version or a newer one is already installed."
  ))

  (set #update-msg
  (cat "\n\nDeliTracker is SHAREWARE.\n\nIt seems that you use DeliTracker frequently. If you have not registered yet, please register now."
  ))
 )
)

; French string

(if (= @LANGUAGE "français")
 (
  (set def_pat "#?.fra#?")

  (set #bad-kick
  (cat "DeliTracker 2.0 nécessite le système 2.04 au minimum !"
  ))

  (set #abort-t
  (cat "Assurez-vous que le répertoire T: peut contenir au moins 500 KB."
  ))

  (set #invalid-env
  (cat "\nLa variable contenue dans 'ENV:DeliConfig' est erronée. Le fichier a été effacé.\n\n Si vous voulez installer DeliTracker, relancez le script d'installation."
  ))
 
  (set #abort-no-space
  (cat "Vous avez besoin d'au-moins 850 KB de libre sur votre disque pour installer DeliTracker II"
  ))

  (set #choose-text
  (cat "Veuillez choisir le répertoire dans lequel DeliTracker doit être installé. Un répertoire y sera alors créé."
  ))

  (set #choose-help
  (cat "Un répertoire sera créé ici. Tous les fichiers, à l'exception des bibliothèques, seront installés dans ce répertoire. L'installation complète nécessite environ 1 MB d'espace libre sur votre disque dur."
  ))

  (set #create-maindir
  (cat "Création du répertoire 'DeliTracker'"
  ))

  (set #create-configdir
  (cat "Création du réertoire 'Config'"
  ))

  (set #set-path
  (cat "Choix du chemin pour la configuration"
  ))

  (set #inst-main
  (cat "Installation du programme principal"
  ))

  (set #create-docsdir
  (cat "Création du répertoire 'Docs'"
  ))

  (set #inst-docs
  (cat "Installation de la documentation"
  ))

  (set #ask-xpk
  (cat "Voulez-vous installer les bibliothèques de décompression XPK ?"
  ))

  (set #xpk-help
  (cat "Il est indiqué d'installer ces bibliothèques, même si vous n'en éprouvez pas le besoin pour l'instant et que vous n'avez pas compressé de modules !"
  ))

  (set #create-comressorsdir
  (cat "Création du répertoire 'Compressors' dans Libs:"
  ))

  (set #create-playerdir
  (cat "Création du répertoire 'DeliPlayers'"
  ))

  (set #create-playerstore
  (cat "Création du répertoire 'DeliPlayers/PlayerStore'"
  ))

  (set #ask-players
  (cat "Quels sont les players que vous désirez charger au démarrage ?"
  ))

  (set #ask-additional-players
  (cat "Désirez-vous en installer d'autres ? Ces players ne sont que très peu utilisés, nous vous suggérons donc de ne pas les sélectionner !"
  ))

  (set #ask-players-2
  (cat "Quels sont les players que vous désirez ajouter encore ? Réfléchissez-y à deux fois avant d'en sélectionner !"
  ))

  (set #ask-playsid
  (cat "Désirez-vous installer le player PlaySID ?\nRemarque: Ce player a besoin de la 'playsid.library', qui est considérée comme SHAREWARE ! Veuillez vous référer à la documentation pour plus de détails."
  ))

  (set #ask-playay
  (cat "Voulez-vous installer le player PlayAY ?\n(Ce player sert à émuler les sons AY du ZX Spectrum)"
  ))

  (set #player-help
  (cat "Cochez les cases correspondant aux players que vous désirez charger au démarrage de DeliTracker. Ne choisissez que des players dont vous avez besoin ! Tous les autres seront installés dans le répertoire PlayerStore et pourront par conséquent être\
 chargés plus tard. N'oubliez pas que chaque player a besoin de mémoire supplémentaire ! Référez-vous à la documentation pour plus de renseignements au sujet des players (Players.fra)..."
  ))

  (set #create-geniedir
  (cat "Création du répertoire 'DeliGenies'"
  ))

  (set #create-geniestore
  (cat "Création du répertoire 'DeliGenies/GenieStore'"
  ))

  (set #ask-genies
  (cat "Quels sont les génies que vous voulez activer lors du démarrage de DeliTracker II ?"
  ))

  (set #genie-help
  (cat "Tous les génies que vous n'avez pas cochés seront copiés dans le répertoire 'GenieStore' et pourront donc être appelés plus tard. Pour plus d'informations, référez-vous à la documentation correspondante (Genies.fra)..."
  ))

  (set #ask-arexx
  (cat "Désirez-vous installer les scripts ARexx ?"
  ))

  (set #help-arexx
  (cat "N'installez ces scripts que si vous en avez vraiment besoin et si vous utilisez régulièrement ARexx."
  ))

  (set #create-arexx
  (cat "Création du répertoire 'ARexx'"
  ))

  (set #ask-pdocs
  (cat "Désirez-vous installer la documentation pour programmeurs (en anglais) ?"
  ))

  (set #help-pdocs
  (cat "N'installez ces fichiers que si vous prévoyez d'écrire vos propres routines pour vos propres players !  (Connaissances sérieuses en anglais requises)"
  ))

  (set #create-pdocs
  (cat "Création du répertoire 'Developer'"
  ))

  (set #extract-players
  (cat "Décompression de l'archive contenant les players\n\nVeuillez patienter quelques instants..."
  ))

  (set #extract-genies
  (cat "Décompression de l'archive contenant les génies\n\nVeuillez patienter quelques instants..."
  ))

  (set #extract-arexx
  (cat "Décompression et installation de l'archive contenant les scripts ARexx\n\nVeuillez patienter..."
  ))

  (set #extract-docs
  (cat "Décompression et installation de l'archive contenant la documentation\n\nVeuillez patienter..."
  ))

  (set #extract-libs
  (cat "Décompression et installation de l'archive contenant les bibliothèques\n\nVeuillez patienter..."
  ))

  (set #extract-pdocs
  (cat "Décompression et installation de l'archive contenant les informations pour programmeurs\n\nVeuillez patienter..."
  ))
   
  (set #final-msg
  (cat "\nPour configurer les génies, veuillez procéder comme suit pour chacun d'eux :\n\n1. Ouvrez la fenêtre de configuration à l'aide de l'option 'Show'.\n2. Activez la fenêtre et déplacez-la ensuite où vous voulez qu'elle apparaisse.\n3. Choisissez\
 vos options par défaut (généralement dans le menu 'Settings', en particulier 'Popup', qui vous permet de choisir si vous désirez que DeliTracker ouvre la fenêtre lors du démarrage).\n4. Concluez par 'Save Prefs' dans le menu 'Project'."
  ))

  ; Update Strings

  (set #remove-old
  (cat "Tous les anciens fichiers seront détruits."
  ))

  (set #proceed
  (cat "Continuer"
  ))

  (set #abort
  (cat "Arrêter"
  ))

  (set #remove-old-help
  (cat "Si vous désirez garder votre installation de DeliTracker intacte, sans effacer les anciens fichiers, vous devez effacer 'ENV:DELICONFIG' et redémarrer le script d'installation. Assurez-vous que vous avez bien choisi un autre chemin pour effectuer\
 l'installation."
  ))

  (set #removing-dt
  (cat "Efface les anciens fichiers."
  ))

  (set #already-newer-installed
  (cat "L'installation est impossible, car cette version (ou une version plus récente) est déjà installée sur votre disque dur."
  ))

  (set #update-msg
  (cat "\n\nDeliTracker est un produit considéré comme SHAREWARE.\n\nApparemment, vous utilisez DeliTracker fréquemment. Si vous n'êtes pas encore un utilisateur référencié, nous vous prions de le devenir aussi tôt que possible !"
  ))
 )
)

; German strings

(if (= @LANGUAGE "deutsch")
 (
  (set def_pat "#?.deu#?")

  (set #bad-kick
  (cat "DeliTracker 2.0 benötigt mindenstens Kickstart 2.04!"
  ))

  (set #abort-t
  (cat "Das T: Verzeichnis muß mindestens 500KB Platz zum Entpacken verschiedener Dateien bieten."
  ))

  (set #invalid-env
  (cat "\nENV:DeliConfig enthält eine ungültige Pfadangabe und wurde gelöscht.\n\n Starten Sie dieses Skript nochmal, um DeliTracker neu zu installieren."
  ))

  (set #abort-no-space
  (cat "Sie benötigen mindestens 850.000 Bytes freien Plattenplatz um DeliTracker zu installieren."
  ))

  (set #choose-text
  (cat "Bitte wählen Sie das Verzeichnis wohin DeliTracker installiert werden soll. Dieses Installationsscript legt dort selbst eine Schublade an."
  ))

  (set #choose-help
  (cat "Bei der Installation werden alle Dateien, bis auf die Libraries, in dieses Verzeichnis installiert. Die vollständige Installation von DeliTracker belegt auf der Festplatte etwa 1MB."
  ))

  (set #create-maindir
  (cat "Erstelle DeliTracker-Verzeichnis"
  ))

  (set #create-configdir
  (cat "Erstelle Konfigurations-Verzeichnis"
  ))

  (set #set-path
  (cat "Erstelle Pfad-Variable"
  ))

  (set #inst-main
  (cat "Installiere Hauptprogramm."
  ))

  (set #create-docsdir
  (cat "Erstelle Docs-Verzeichnis"
  ))

  (set #inst-docs
  (cat "Installiere Programm Dokumentation"
  ))

  (set #ask-xpk
  (cat "Wollen Sie die XPK Packer-Libraries installieren?"
  ))

  (set #xpk-help
  (cat "Sie sollenten die Packer-Libraries auch dann installieren, wenn Sie (noch) keine gepackten Module besitzen!"
  ))

  (set #create-comressorsdir
  (cat "Erstelle Libs:Compressors Unterverzeichnis"
  ))

  (set #create-playerdir
  (cat "Erstelle Player-Verzeichnis"
  ))

  (set #create-playerstore
  (cat "Erstelle PlayerStore"
  ))

  (set #ask-players
  (cat "Welche Player sollen aktiviert werden werden?"
  ))

  (set #ask-additional-players
  (cat "Sollen zusätzliche Player aktiviert werden? Hierbei handelt es sich um Player die nicht sehr verbreitet sind. Der normale Benutzer wird diese Player nicht benötigen. Wir schlagen deshalb vor, das Sie mit 'NEIN' fortfahren."
  ))   

  (set #ask-players-2
  (cat "Welche zusätzlichen Player sollen bei Programmstart geladen werden?"
  ))

  (set #ask-playsid
  (cat "Wollen sie den PlaySID Player für DeliTracker installieren ?\nHinweis: Dieser DeliPlayer benutzt die playsid.library. Diese Library ist SHAREWARE! Für weitere Informationen lesen sie bitte die zugehörige Dokumentation."
  ))

  (set #ask-playay
  (cat "Wollen Sie den PlayAY Player installieren?\n(Dieser Player emuliert den AY Soundchip des ZX Spectrum)"
  ))

  (set #player-help
  (cat "Bitte wählen Sie nur Player für die Sie auch Module besitzen. Nicht angewählete Player werden im Playerstore installiert. Sie können diese Player bei Bedarf später immer noch nachladen."
  ))

  (set #create-geniedir
  (cat "Erstelle Genie Verzeichnis"
  ))

  (set #create-geniestore
  (cat "Erstelle GenieStore"
  ))

  (set #ask-genies
  (cat "Welche zusätzlichen Genies sollen bei Programmstart geladen werden?"
  ))

  (set #genie-help
  (cat "Alle Genies, die nicht aktiviert werden, sind im GenieStore zu finden. Weitere Informationen finden Sie in Genies.deu."
  ))

  (set #ask-arexx
  (cat "Wollen Sie die ARexx scripts installieren?"
  ))

  (set #help-arexx
  (cat "Wählen Sie diese Option nur, wenn Sie Arexx auch benutzen."
  ))

  (set #create-arexx
  (cat "Erstelle Arexx-Verzeichnis"
  ))

  (set #ask-pdocs
  (cat "Wollen Sie die Programmierdokumentation installieren?"
  ))

  (set #help-pdocs
  (cat "Wählen Sie diese Option nur, wenn Sie eigene Player oder Genies schreiben wollen. Hinweis: Die Entwicklerdokumentation ist für Assemblerprogramierer gedacht und ist nur in Englisch verfügbar!"
  ))

  (set #create-pdocs
  (cat "Erstelle Developer-Verzeichnis"
  ))

  (set #extract-players
  (cat "Entpacke Player"
  ))

  (set #extract-genies
  (cat "Entpacke Genies"
  ))

  (set #extract-arexx
  (cat "Entpacke Arexx Scripts"
  ))

  (set #extract-docs
  (cat "Entpacke Dokumentation"
  ))

  (set #extract-libs
  (cat "Entpacke Libraries"
  ))

  (set #extract-pdocs
  (cat "Entpacke Entwicklungspaket"
  ))

  (set #final-msg
  (cat "Um die Genies zu konfigurieren, wiederholen Sie folgende Schritte für jedes Genie:\n\n1. Öffnen Sie die zugehörige GUI mit der 'Show' Funktion.\n2. Aktivieren Sie das Fenster und positionieren Sie es an der gewünschten Stelle.\n3. Stellen Sie die\
 Optionen nach Bedarf ein. Sie finden die Einstellungen im 'Settings' Menü. Wenn Sie wünschen, daß dieses Fenster bei jedem Start von DeliTracker geöffnet wird, schalten Sie 'Popup' an.\n\n4. Wählen Sie den Menüpunkt 'Save Prefs' aus dem 'Project' Menü."
  ))

  ; Update Strings

  (set #remove-old
  (cat "Es werden jetzt alle alten Dateien gelöscht."
  ))
  
  (set #proceed
  (cat "Weiter"
  ))

  (set #abort
  (cat "Abbrechen"
  ))

  (set #remove-old-help
  (cat "Wenn Sie Ihre alte Installation behalten wollen, müssen Sie ENV:DELICONFIG löschen und dieses Script erneut starten. Installieren Sie die neue Version unbedingt in einem anderen Directory."
  ))

  (set #removing-dt
  (cat "Entferne alte Dateien."
  ))

  (set #already-newer-installed
  (cat "Die Installation wurde abgebrochen, da bereits eine neuere Version installiert ist!"
  ))

  (set #update-msg
  (cat "\n\nDeliTracker ist SHAREWARE.\n\nDa Sie scheinbar DeliTracker öfter benutzen, sollten Sie sich, falls Sie das noch nicht getan haben, registrieren!"
  ))
 )
)

; check kick version

(if (< (/ (getversion) 65536) 37) (abort #bad-kick))

; say hi 
(welcome)
(complete 0)

;=============================================================================;
; Choose directory where DeliTracker is/will be installed.
; (Check for enough room)
;
(if (exists "ENVARC:DELICONFIG" (noreq))
 (
  ; for compatibility with AmiNET 8 CD
  (copyfiles (source "ENVARC:DELICONFIG") (dest "ENV:"))

  (set @default-dest (getenv "DELICONFIG"))
  (set @default-dest (substr @default-dest 0 (- (strlen @default-dest) 11)))

  ; check ENV Variable
  (if (NOT (exists @default-dest (noreq)))
   (
    (delete "ENVARC:DELICONFIG")
    (abort #invalid-env)
   )
  )

  ; check installed version
  (if (> (BITAND 65535 (getversion ("DeliTracker2"))) (BITAND 65535 (getversion (tackon @default-dest "DeliTracker2"))))
   (    
    (if (= 1 (askbool (prompt #remove-old) (help #remove-old-help) (choices #proceed #abort)))
     (
      (working #removing-dt)
      (if (= 2 (exists @default-dest))
       (; delete all files in the DeliTracker2 drawer
        (foreach (tackon @default-dest "DeliPlayers/PlayerStore") "#?" (delete (tackon (tackon @default-dest "DeliPlayers/PlayerStore") @each-name)))
        (foreach (tackon @default-dest "DeliPlayers") "#?" (delete (tackon (tackon @default-dest "DeliPlayers") @each-name)))
        (if (= 2 (exists (tackon @default-dest "AYPlayers")))
         (
           (foreach (tackon @default-dest "AYPlayers") "#?" (delete (tackon (tackon @default-dest "AYPlayers") @each-name)))
           (delete (tackon @default-dest "AYPlayers.info"))
           (delete (tackon @default-dest "AYPlayers"))
         )
        )
        (foreach (tackon @default-dest "DeliGenies/GenieStore") "#?" (delete (tackon (tackon @default-dest "DeliGenies/GenieStore") @each-name)))
        (foreach (tackon @default-dest "DeliGenies") "#?" (delete (tackon (tackon @default-dest "DeliGenies") @each-name)))
        (if (= 2 (exists (tackon @default-dest "Docs")))
  	  (foreach (tackon @default-dest "Docs") "#?" (delete (tackon (tackon @default-dest "Docs") @each-name)))
          (delete (tackon @default-dest "Docs.info"))
          (delete (tackon @default-dest "Docs"))
        )
        (if (= 2 (exists (tackon @default-dest "Arexx")))
         (
          (foreach (tackon @default-dest "ARexx") "#?" (delete (tackon (tackon @default-dest "ARexx") @each-name)))
          (delete (tackon @default-dest "ARexx.info"))
          (delete (tackon @default-dest "ARexx"))
         )
        )
        (if (= 2 (exists (tackon @default-dest "Developer")))
         (
          (foreach (tackon @default-dest "Developer/Include/Misc") "#?" (delete (tackon (tackon @default-dest "Developer/Include/Misc") @each-name)))
          (foreach (tackon @default-dest "Developer/Include") "#?" (delete (tackon (tackon @default-dest "Developer/Include") @each-name)))
          ; Custom dir has been removed
          (if (= 2 (exists (tackon @default-dest "Developer/Examples/Custom")))
           (
            (foreach (tackon @default-dest "Developer/Examples/Custom") "#?" (delete (tackon (tackon @default-dest "Developer/Examples/Custom") @each-name)))
           )
          )
          (foreach (tackon @default-dest "Developer/Examples") "#?" (delete (tackon (tackon @default-dest "Developer/Examples") @each-name)))
          (foreach (tackon @default-dest "Developer") "#?" (delete (tackon (tackon @default-dest "Developer") @each-name)))
          (delete (tackon @default-dest "Developer.info"))
          (delete (tackon @default-dest "Developer"))
         )
        )
       )
      )

      ; for those who have moved DeliTracker into the WBStartUp drawer
      (delete "SYS:WBStartUp/DeliTracker2")
      (delete "SYS:WBStartUp/DeliTracker2.info")
      ; remind shareware (obsolete)
      ;;(message #update-msg)
     )
     (exit "Bye Bye ...")
    )
   )
   (abort #already-newer-installed)
  )
 )

 ; CHOOSE_DESTINATION

 (
  (if (= "RAM" (getdevice "T:"))
   (set freespace (+ (database "total-mem")))
   (set freespace (getdiskspace ("%s:" (getdevice "T:"))))
  )
  (if (< freespace 500000)
    (abort #abort-t))
  
  (set @default-dest (getassign "Work" "dva"))
  (if (= @default-dest "")
   (set @default-dest "SYS:"))
  
  (set @default-dest (askdir
    (prompt #choose-text)
    (help #choose-help)
    (default @default-dest))
  ) 
  
  (set @default-dest (tackon @default-dest "DeliTracker_II"))
  
  (if (NOT (= "RAM" (getdevice @default-dest)))
   (if (> 850000 (getdiskspace ("%s:" (getdevice @default-dest))))
    (abort #abort-no-space)
   )
  )
 )
)

(complete 5)

;=============================================================================;
; Install procedure for DeliTracker itself

(if (exists "Files/Docs.lzx" (noreq))
 (
  (copyfiles (source "c/UNLZX") (dest "T:") (newname "UnPack"))
 )
 (
  ; for compatibility with AmiNET uploads
  (copyfiles (source "c/LHX") (dest "T:") (newname "UnPack"))
 )
)

(makedir @default-dest (prompt #create-maindir)(infos))
(makedir (tackon @default-dest "DELICONFIG") (prompt #create-configdir))
(copyfiles (prompt #inst-main)
 (source "DeliTracker2")
 (dest @default-dest)
 (optional "fail")
 (infos)
)

(complete 10)

;=============================================================================;
; Installation procedure for players
; 

(makedir (tackon @default-dest "DeliPlayers")
 (prompt #create-playerdir)
 (infos)
)

(makedir (tackon @default-dest "DeliPlayers/PlayerStore")
 (prompt #create-playerstore)
 (infos)
)

(working #extract-players)
(run "T:UnPack -m -x x Files/players T:")

(
 (copyfiles (prompt #ask-players)
  (help #player-help)
  (source "T:DeliPlayers/")
  (dest (tackon @default-dest "DeliPlayers"))
  (optional "nofail")
  (confirm "average")
  (files)
  (all)
 )
)

(if (= 1 (askbool (prompt #ask-additional-players) (help @help-askbool)))
 (
  (
   (copyfiles (prompt #ask-players-2)
   (help #player-help)
   (source "T:DeliPlayers/Playerstore")
   (dest (tackon @default-dest "DeliPlayers"))
   (optional "nofail")
   (confirm "average")
   (files)
   (all)
   )
  )
 )
)

(foreach (tackon @default-dest "DeliPlayers") "#?" (delete (tackon "T:DeliPlayers/" (fileonly @each-name))))
(foreach (tackon @default-dest "DeliPlayers") "#?" (delete (tackon "T:DeliPlayers/PlayerStore/" (fileonly @each-name))))
(copyfiles (source "T:DeliPlayers/Playerstore")
      (dest (tackon @default-dest "DeliPlayers/PlayerStore"))
      (files)
      (all)
)
(foreach "T:DeliPlayers/Playerstore" "#?" (delete (tackon "T:DeliPlayers/PlayerStore/" (fileonly @each-name))))
(delete "T:DeliPlayers/Playerstore")
(copyfiles (source "T:DeliPlayers") 
      (dest (tackon @default-dest "DeliPlayers/PlayerStore"))
      (files)
      (all)
)
(foreach "T:DeliPlayers" "#?" (delete (tackon "T:DeliPlayers/" (fileonly @each-name))))
(delete "T:DeliPlayers")

(complete 60)

;=============================================================================;
; Installation procedure for PlaySID
; 

(if (= 1 (askbool (prompt #ask-playsid) (help @help-askbool)))
 (
  (
   (working #extract-players)
   (run "T:UnPack -m x Bonus/DeliSID DeliSID T:")
   (run "T:UnPack -m x Bonus/playsid3 PlaySID3.0/PlaySID.doc PlaySID3.0/PlaySID.doc.info PlaySID3.0/libs/playsid.library T:")

   (copyfiles (help #player-help)
    (source "T:DeliSID")
    (dest (tackon @default-dest "DeliPlayers"))
   )

   (copyfiles (help #player-help)
    (source "T:PlaySID3.0/PlaySID.doc.info")
    (dest (tackon @default-dest "Docs"))
   )

   (copyfiles (help #player-help)
    (source "T:PlaySID3.0/PlaySID.doc")
    (dest (tackon @default-dest "Docs"))
   )

   (copylib (prompt "The playsid.library is required for DeliSID")
    (source "T:PlaySID3.0/libs/playsid.library")
    (dest "libs:")
    (help @copylib-help)
   )
   (delete "T:DeliSID")
   (delete "T:PlaySID3.0/PlaySID.doc.info")
   (delete "T:PlaySID3.0/PlaySID.doc")
   (delete "T:PlaySID3.0/libs/playsid.library")
   (delete "T:PlaySID3.0/libs")
   (delete "T:PlaySID3.0")
  )
 )
)

(complete 65)

;=============================================================================;
; Installation procedure for PlayAY
; 

(if (= 1 (askbool (prompt #ask-playay) (help @help-askbool)))
 ( 
  (
   (working #extract-players)
   (run "T:UnPack -m x Bonus/playay100 PlayAY/#?readme#? PlayAY/AYPlayers/#? PlayAY/DeliPlayers/#? T:")

   ; copy docs 
   (copyfiles (help #player-help)
    (source "T:PlayAY/PlayAY100.readme.info")
    (dest (tackon @default-dest "Docs"))
   )   
   (copyfiles (help #player-help)
    (source "T:PlayAY/PlayAY100.readme")
    (dest (tackon @default-dest "Docs"))
    (files)
   )

   ; copy PlayAY player
   (copyfiles (help #player-help)
    (source "T:PlayAY/DeliPlayers/PlayAY")
    (dest (tackon @default-dest "DeliPlayers"))
   )

   ; let's make a new sub-player directory
   (makedir (tackon @default-dest "AYPlayers")
   (prompt #create-playerdir)
   )
 
   ; copy sub-players
   (copyfiles (help #player-help)
    (source "T:PlayAY/AYPlayers")
    (dest (tackon @default-dest "AYPlayers"))
    (files)
    (all)
   )

   ; delete temporary files 
   (foreach "T:PlayAY/AYPlayers/" "#?" (delete (tackon "T:PlayAY/AYPlayers/" @each-name) (optional force)))
   (foreach "T:PlayAY/DeliPlayers/" "#?" (delete (tackon "T:PlayAY/DeliPlayers/" @each-name) (optional force)))
   (foreach "T:PlayAY/" "#?" (delete "T:PlayAY/" (tackon "T:PlayAY/" @each-name) (optional force)))
   (delete "T:PlayAY")

  )
 )
)

(complete 66)

;=============================================================================;
; Installation procedure for genies
; Install default genies
; Average, Expert: ask optional genies

(makedir (tackon @default-dest "DeliGenies")
 (prompt #create-geniedir)
 (infos)
)

(makedir (tackon @default-dest "DeliGenies/GenieStore")
 (prompt #create-geniestore)
 (infos)
)

(working #extract-genies)
(run ("T:UnPack -m -x x Files/genies \"%s/\"" @default-dest))

(if (OR (= "68000" (database "cpu") (= "68010" (database "cpu"))))
 ; remove NotePlayers on 68000er Systems that require at least a '020
 (
  (delete (tackon @default-dest "DeliGenies/GenieStore/14Bit-NotePlayer"))
  (delete (tackon @default-dest "DeliGenies/GenieStore/32Voc-NotePlayer"))
  (delete (tackon @default-dest "DeliGenies/GenieStore/32Voc-NotePlayerPlus"))
  (delete (tackon @default-dest "DeliGenies/GenieStore/ModSave-NotePlayer"))
 )
 ; remove obsolete NotePlayers for 68020+ Systems
 (
  (delete (tackon @default-dest "DeliGenies/8Voc-NotePlayer"))
 )
)

(
 (copyfiles (prompt #ask-genies)
  (help #genie-help)
  (source (tackon @default-dest "DeliGenies/Geniestore"))
  (dest (tackon @default-dest "DeliGenies"))
  (optional "nofail")
  (confirm "average")
  (files)
  (all)
 )
)

(foreach (tackon @default-dest "DeliGenies") "#?" (delete (tackon (tackon @default-dest "DeliGenies/GenieStore/") (fileonly @each-name))))

(complete 75)

;=============================================================================
; Installation procedure for Arexx Scripts

(if (< 0 @user-level)
 (if (= 1 (askbool (prompt #ask-arexx) (help #help-arexx)))
  (
   (makedir (tackon @default-dest "Arexx")
    (prompt #create-arexx)
    (infos)
   )
   (working #extract-arexx)
   (run ("T:UnPack -m -x x Files/arexx \"%s/\"" @default-dest))
  )
 )
)

(complete 80)

;=============================================================================;
; Install procedure for the decompression libraries

(if (OR (= 0 @user-level) (if (< 0 @user-level) (askbool (prompt #ask-xpk) (help #xpk-help))))
 (
  (makedir "Libs:Compressors" (prompt #create-comressorsdir))
  (working #extract-libs)
  (run "T:UnPack -m -x x Files/libs >NIL: <NIL: T:")  
  (run "T:UnPack -m x Files/xpkSMPL xpkSMPL.library >NIL: <NIL: T:libs/compressors/")
  (run "T:UnPack -m x Files/xpkSHRI xpkSHRI.library >NIL: <NIL: T:libs/compressors/")
  (run "T:UnPack -m x Files/xpkSQSH >NIL: <NIL: T:libs/")

  (copylib (prompt "Install xpkmaster.library")
  (source "T:libs/xpkmaster.library")
  (dest "libs:")
  (confirm)
  (optional nofail askuser)
  (help @copylib-help)
  )

  (copylib (prompt "Install powerpacker.library")
  (source "T:libs/powerpacker.library")
  (dest "libs:")
  (confirm)
  (optional nofail askuser)
  (help @copylib-help)
  )

  ; xpk sub lib's
  
  (copylib (prompt "Install compressors/xpkNUKE.library")
  (source "T:libs/compressors/xpkNUKE.library")
  (dest "libs:compressors/")
  (confirm)
  (optional nofail askuser)
  (help @copylib-help)
  )

  (copylib (prompt "Install compressors/xpkSMPL.library")
  (source "T:libs/compressors/xpkSMPL.library")
  (dest "libs:compressors/")
  (confirm)
  (optional nofail askuser)
  (help @copylib-help)
  )

  (copylib (prompt "Install compressors/xpkSHRI.library")
  (source "T:libs/compressors/xpkSHRI.library")
  (dest "libs:compressors/")
  (confirm)
  (optional nofail askuser)
  (help @copylib-help)
  )

  ; install right version for 680x0 cpu
  (if (OR (= "68000" (database "cpu") (= "68010" (database "cpu"))))
   (copylib (prompt "Install compressors/xpkSQSH.library")
    (source "T:libs/68000/xpkSQSH.library")
    (dest "libs:compressors/")
    (confirm)
    (optional nofail askuser)
    (help @copylib-help)
   )
   (copylib (prompt "Install compressors/xpkSQSH.library")
    (source "T:libs/68020/xpkSQSH.library")
    (dest "libs:compressors/")
    (confirm)
    (optional nofail askuser)
    (help @copylib-help)
   )
  )

  ; cleanup temp dir

  (foreach "T:libs/compressors" "#?" (delete (tackon "T:libs/compressors/" @each-name) (optional force)))
  (foreach "T:libs/" "#?" (delete (tackon "T:libs/" @each-name) (optional force)))
  (delete "T:libs/68000/xpkSQSH.library")
  (delete "T:libs/68020/xpkSQSH.library")
  (delete "T:libs/68000")
  (delete "T:libs/68020")
  (delete "T:libs")

 )
)

(complete 90)

;=============================================================================;
; Install procedure for the documentation files

(makedir (tackon @default-dest "Docs")
 (prompt #create-docsdir)
 (infos)
)

(working #extract-docs)
(run "T:UnPack -m -x x Files/docs >NIL: <NIL: T:")

(copyfiles (prompt #inst-docs)
 (source "T:Docs/")
 (dest (tackon @default-dest "Docs"))
 (pattern def_pat)
 (optional "nofail")
 (infos)
 (files)
)

; cleanup temp dir

(foreach "T:Docs/" "#?" (delete (tackon "T:Docs/" @each-name) (optional force)))
(delete "T:Docs" (optional force))

(complete 95)

;=============================================================================;
; Installation procedure for Development Documentation

(if (= 2 @user-level)
 (if (= 1 (askbool (prompt #ask-pdocs) (help #help-pdocs)))
  (
   (makedir (tackon @default-dest "Developer")
    (prompt #create-pdocs)
    (infos)
   )
   (makedir (tackon @default-dest "Developer/Examples")
    (prompt #create-pdocs)
    (infos)
   )
   (makedir (tackon @default-dest "Developer/Include")
    (prompt #create-pdocs)
    (infos)
   )

   (working #extract-pdocs)
   (run ("T:UnPack -m -x x Files/developer \"%s/\"" @default-dest))

   (if (= @LANGUAGE "deutsch")
    (
    (delete (tackon @default-dest "Developer/Developer.eng"))
    (delete (tackon @default-dest "Developer/Developer.eng.info"))
    )
    (
    (delete (tackon @default-dest "Developer/Developer.deu"))
    (delete (tackon @default-dest "Developer/Developer.deu.info"))
    )
   )
  )
 )
)

;=============================================================================;
; Set environment variables for configuration path

(complete 98)

(textfile (prompt #set-path) (dest "ENV:DELICONFIG") (append (expandpath (tackon @default-dest "DELICONFIG")))) 

; this makes testing easier...
(if (NOT (= "RAM" (getdevice @default-dest)))
 (textfile (prompt #set-path) (dest "ENVARC:DELICONFIG") (append (expandpath (tackon @default-dest "DELICONFIG")))) 
)

;=============================================================================;
; Cleanup & tell some important things!

(delete "T:UnPack")
(complete 99)
(message #final-msg)
(complete 100)

;=============================================================================;
