; #######################################################
; #
; #   DataM_II.install
; #   $VER: 0.02 (24.10.2000)
; #   © 2000 by Christoph Kirsch
; #
; #######################################################

; #######################################################
; # setup language-strings
; #######################################################
; # german
; #######################################################

(procedure p_deutsch
    (set #true  (cat "Ja"))
    (set #false (cat "Nein"))
    (set #work1 (cat "Update"))
    (set #work2 (cat "Neuinstallation"))
    (set #work3 (cat "Umbenennen"))
    (set #work4 (cat "Löschen"))

    (set #falsekick
    (cat "\nDataM II benoetigt "
         "zwingend OS3.0 oder höher."
    ))

    (set #falseinstaller
    (cat "\nDieses Script benötigt einen Installer der "
         "Version V43.2 oder höher. Die Version 43.2 des "
         "Installers ist auf der Aminet-CD 16 zu finden !"
    ))

    (set #info1
    (cat "\nDieses Script installiert \"DataM II\"  und alle "
         "dazugehörigen Dateien auf Ihre Festplatte oder "
         "fertigt ein Update auf eine bereits existierende "
         "DataM II Installation an. Bevor es aber weitergeht, "
         "wird Ihnen eine Textdatei angezeigt, die Sie über "
         "die wichtigsten Veränderungen und Neuerungen von "
         "\"DataM II\"  informiert."
    ))

    (set #info2
    (cat "\nBei der Neuinstallation wird ein Verzeichnis mit "
         "Namen \"DataM_II\"  angelegt in das alle wichtigen "
         "Programmteile kopiert werden. Existiert auf dem "
         "gleichen Pfad bereits eine DataM II Installation, "
         "so wird das alte Verzeichnis nach \"DataM_II_old\" "
         " umbenannt, so dass keinerlei alte Daten verloren gehen."
         "\n\nSoll ein Update vorgenommen werden, so werden "
         "nur alle neuen Programmteile, Dokumentationen "
         "und Katalogfiles installiert. Auch hier ist sichergestellt, "
         "dass nichts verloren gehen und Ihre Einstellungen "
         "und Daten unverändert bleiben. "
    ))

    (set #choice1
    (cat "\nWollen Sie nun ein Update auf eine bereits "
         "vorhandene DataM II Installation oder eine "
         "komplette Neuinstalltion vornehmen ? "
    ))

    (set #updateinfo
    (cat "\nBitte wählen Sie nun den Pfad, bzw. das Verzeichnis "
         "aus, in dem sich das DataM II Hauptverzeichnis befindet\n"
    ))

    (set #installinfo
    (cat "\nBitte wählen Sie nun das Zielverzeichnis für die "
         "Neuinstallation aus. Ein Verzeichnis \"DataM_II\" "
         " wird dort angelegt.\n"
    ))

    (set #createdirs
    (cat "\nEs werden nun alle benötigten Verzeichnisse auf dem "
         "Zielpfad angelegt....."
    ))

    (set #copymain      "\nKopieren von DataM II")
    (set #copylocal     "\nKopiere Locale-Files")
    (set #copyinfos     "\nKopieren der Info-Dateien")
    (set #copyarexx     "\nKopieren der ARexx-Scripte")
    (set #copybuttons   "\nKopieren der Grafiken für Schalter")
    (set #copydata      "\nKopieren der Beispiel-Tabellen")
    (set #copyprefs     "\nKopieren der Voreinstellungen")

    (set #copyoldmainprefs      "\nKopieren der alten Prefs-Dateien von DataM II")
    (set #copyoldmaindata       "\nKopieren der alten Dokumente von DataM II")
    (set #copyoldmainrexx       "\nKopieren der alten ARexx-Scripts von DataM II")
    (set #copykeyfile           "\nKopiere das Keyfile")

    (set #askforlanguages
    (cat "\nMöchten Sie noch weitere der unten aufgeführten "
         "Sprachen für \"DataM II\"  installieren."
    ))

    (set #askforolddata
    (cat "\nSollen die Daten der alten DataM II-Installation "
         "übernommen werden ? Dies betrifft ein evtl. vorhandenes "
         "Keyfile, Ihre Daten von \"DataM II\", die ARexx-Scripts "
         " und die Einstellungen."
    ))

    (set #oldmvexists
    (cat "\nAuf dem Zielpfad befindet sich bereits ein Backup "
         "einer DataM II Installation. Um fortfahren zu können "
         "muss dieses umbenannt oder gelöscht werden !"
         "\n\nWas soll mit dem alten Backup geschehen ?"
    ))

    (set #oldmv
    (cat "\nAuf dem Zielpfad wurde eine DataM II Installation "
         "gefunden. Dieses wird im folgenden nach \"DataM_II_old\" "
         " umbenannt, so dass keine vorhandenen Daten verloren gehen."
    ))

    (set #askfornewname
    (cat "\nBitte einen neuen Namen eingeben oder "
         "den voreingestellten Namen bestätigen."
    ))

    (set #askfordel1 "\nSoll das Verzeichnis\n\n > ")
    (set #askfordel2
    (cat " <\n\njetzt gelöscht werden ?\n"
         "Alle darin enthaltenen Daten gehen unwiderruflich verloren !"
    ))

    (set #error1
    (cat "\n Auf dem von Ihnen angegebenen Pfad konnte kein "
         "Verzeichnis namens \"DataM_II\"  gefunden werden. "
         "Bitte stellen Sie sicher, dass sich das Hauptverzeichnis "
         "von \"DataM II\"  auch wirklich in dem von Ihnen gewählten "
         "Pfad befindet. Wählen Sie nicht dass DataM II Verzeichnis "
         "selbst sondern dass übergeordnete Verzeichnis an !"
    ))

    (set verinfo1 "\n\nBereits installierte Version %ld.%ld\n")
    (set verinfo2 "Zu installierende Version %ld.%ld")
    (set verinfo3 "\n\nBisher nicht installiert\n")

    (set #updatemuimain  "\nUpdate von DataM II\n")

    (set #destination-help
    (cat "\nIn diesem Fenster können Sie das Zielverzeichnis für "
         "die Installation von \"DataM II\"  auswählen. Bei der "
         "Neuinstallation wird ein neues Verzeichnis namens "
         "\"DataM_II\" angelegt. Sollte sich auf dem Pfad bereits "
         "ein Verzeichnis mit diesem Namen befinden, wird es in "
         "\"DataM_II_old\"  umbenannt. Bei einem Update achten Sie "
         "bitte darauf, dass Sie den Pfad angeben, in dem sich das "
         "Hauptverzeichnis von \"DataM II\"  befindet, wählen Sie nicht "
         "das DataM II Verzeichnis selbst an sondern das übergeordnete. "
    ))

    (set #newname-help
    (cat "\nBei einer früheren Neuinstallation von \"DataM II\"  wurde "
         "ein Backup der alten Installation angelegt. Diese Backups "
         "werden vom Installationsprogramm standardmaessig \"DataM_II_old\" "
         " genannt. Auf dem Zielpfad befindet sich noch so ein Backup. "
         "Da auch bei dieser Installation wieder ein Backup angelegt "
         "werden soll, ist es unumgänglich, dass alte Backup umzubenennen "
         "oder zu löschen. Sie können nun in dem Texteingabefeld einen neuen "
         "Namen für das Backup angeben oder den vorgeschlagenen übernehmen. "
    ))

    (set #deloldbackup-help
    (cat "\nWenn Sie die Frage, ob das Backup gelöscht werden soll "
         "mit \"löschen\"  bestätigen, so gehen alle Daten des Backups "
         "unwiderruflich verloren. Wenn Sie sich nicht sicher sind, "
         "ob das Backup nicht doch noch wichtige Daten enthält, wählen "
         "Sie \"Diesen Teil überspringen\", Sie haben dann erneut die "
         "Möglichkeit, dass alte Backup umzubennen oder zu löschen"
    ))

    (set #versions-help
    (cat "\nBei jedem Update von \"DataM II\" werden grundsätzlich "
         "die Versionen der einzelnen Programmteile mit denen der "
         "bereits installierten verglichen. Sie können so leichter "
         "entscheiden, ob Sie ein Programmteil installieren möchten "
         "oder nicht. Bitte beachten Sie aber, dass es auch möglich "
         "ist, neuere Programmteile durch ältere zu ersetzen. "
         "Schauen Sie sich die ausgegebenen Versionsnummern also "
         "genau an, bevor Sie einen Kopiervorgang bestätigen."
    ))

    (set #endmessage
    (cat "\nWir wünschen Ihnen nun viel Spass und Erfolg mit "
         "\"DataM II\". Sollten Sie dieses Programm nutzen und "
         "noch nicht registriert sein, so holen Sie dieses "
         "bitte nach. Sie unterstützen so den Shareware-Gedanken, "
         "und leisten Ihren Beitrag, für gute Amiga-Software"
    ))
)

; #######################################################
; # setup language-strings
; #######################################################
; # english
; #######################################################

(procedure p_english
    (set #true  (cat "Yes"))
    (set #false (cat "No"))
    (set #work1 (cat "Update"))
    (set #work2 (cat "New installation"))

    (set #falsekick
    (cat "\nDataM II requires OS3.0 or higher."
    ))

    (set #falseinstaller
    (cat "\nThis installer-script requires an installer of "
         "version V43.2 or higher. Version 43.2 of "
         "the installer can be found on Aminet-CD 16 !"
    ))

    (set #info1
    (cat "\nThis script installs DataM II and all "
         "required data on your harddisk or "
         "updates an existing DataM II installation."
         "But at first, let's have a look  at the changes "
         "and news of \"DataM II\"."
    ))

    (set #info2
    (cat "\nIf you decide for a new installation a directory "
         "called \"DataM_II\" will be created in which all important"
         "pats of the program will be copied. If there exists "
         "a DataM II installationin this path already, "
         "the old directorywill be renamed to \"DataM_II_old\", "
         "so that no old data are lost."
         "\n\nIf you decide for an update, only the new "
         "pats of the program, documentations and "
         "catalogfiles will be installed. Your old data and "
         "prefs remain unchanged "
    ))

    (set #choice1
    (cat "\nDo you want to update an existing "
         "DataM II installation or do you want "
         "a new installation ? "
    ))

    (set #updateinfo
    (cat "\nPlease select the path or directory "
         "in which the DataM II directory is located.\n"
    ))

    (set #installinfo
    (cat "\nPlease select the directory for the "
         "new installation. A directory \"DataM_II\" "
         "will be created.\n"
    ))

    (set #oldmv
    (cat "\nAn old DataM II directory has been "
         "found. This will be renamed to \"DataM_II_old\"."
    ))

    (set #createdirs
    (cat "\nCreating required directories... "
    ))

    (set #copymain      "\nCopying DataM II")
    (set #copylocal     "\nCopying locale files")
    (set #copyinfos     "\nCopying info files")
    (set #copyarexx     "\nCopying ARexx scripts")
    (set #copydata      "\nCopying example data files")
    (set #copyprefs     "\nCopying preferences")

    (set #askforlanguages
    (cat "\nYou now have the possibility to "
         "install more languages for \"DataM II\"."
    ))

    (set #askforolddata
    (cat "\nDo you want to keep the data of your"
         "old DataM II installation ?"
         "This concernes your keyfile, the"
         "data and the prefs."
    ))

    (set #error1
    (cat "\nAn old directory called \"DataM_II\" could "
         "not be found in this path. Please keep in mind "
         "not to select the directory of DataM II but "
         "the parent directory."
    ))

    (set verinfo1 "\n\nInstalled Version %ld.%ld\n")
    (set verinfo2 "Version to be installed%ld.%ld")
    (set verinfo3 "\n\nNot installed.\n")

    (set #destination-help
    (cat "\nPlease select the directory where DataM II will "
         "be installed. During a new installation a directory "
         "called \"DataM_II\" will be created. If a directory with"
         "this name exists in this path, it will be renamed in "
         "\"DataM_II_old\". If you are updating an existing "
         "installation, please keep in mind not to select the "
         "directory of DataM II but the parent directory. "
    ))

    (set #newname-help
    (cat "\nAn older backup directory named \"DataM_II_old\" "
         "allready exists. A prior installation has generated"
         "it. You have to rename or delete this old backup"
         "before the installer is able to generate a new backup."
    ))

    (set #deloldbackup-help
    (cat "\nIf you choose to delete the old backup all files"
         "inside this directory will be deletet. If You are"
         "not sure, if there are important files left, choose"
         "\"Skip this part\". You can rename the directory then."
    ))

    (set #versions-help
    (cat "\nBei jedem Update von \"DataM II\" werden grundsätzlich "
         "die Versionen der einzelnen Programmteile mit denen der "
         "bereits installierten verglichen. Sie können so leichter "
         "entscheiden, ob Sie ein Programmteil installieren möchten "
         "oder nicht. Bitte beachten Sie aber, dass es auch möglich "
         "ist, neuere Programmteile durch ältere zu ersetzen. "
         "Schauen Sie sich die ausgegebenen Versionsnummern also "
         "genau an, bevor Sie einen Kopiervorgang bestätigen."
    ))

    (set #endmessage
    (cat "\nWe wish a lot of fun and pleasure with DataM II. "
         "If you use this program without registering, please "
         "read the documentation how to become a registered "
         "user. Please support shareware ! "
    ))
)

; #######################################################
; # getversions-procedure ( forget the bloody (copylib) )
; #######################################################

; arg1 = means the name of actual file
; arg2 = means the name of older file

(procedure p_getversions arg1 arg2
    (set aktversion (getversion arg1))
    (set aktver (/ aktversion 65536))
    (set aktrev (- aktversion (* aktver 65536)))
    (set oldversion (getversion (tackon mvdest arg2)))
    (set oldver (/ oldversion 65536))
    (set oldrev (- oldversion (* oldver 65536)))
)

; #######################################################
; # deloldbackup-procedure
; #######################################################

; arg1 = path to workon

(procedure p_deloldbackup arg1
    (set vote
        (askbool
            (prompt #oldmvexists)
            (choices #work3 #work4)
            (help @askbool-help)
        )
    )
    (if (= 1 vote)
        (
            (set nname
                (askstring
                    (prompt #askfornewname)
                    (default "DataM_II_old1")
                    (help #newname-help)
                )
            )
            (rename arg1 (tackon mvpath nname)
                (prompt #askforrename)
                (help #newname-help)
            )
        )
        (
            (delete arg1
                (prompt #askfordel1 arg1 #askfordel2)
                (all)
                (infos)
                (confirm "average")
                (optional "askuser")
                (help #deloldbackup-help)
            )
        )
    )
)


; #######################################################
; # check language
; #######################################################

(If (= @language "deutsch")
    (
        (p_deutsch)
    )
    (
        (p_english)
    )
)

; #######################################################
; # test kick- & installer-version
; #######################################################

(if (< (/ (getversion) 65536) 39)
    (abort #falsekick)
)

(If (= 0 @installer-version)
    (abort #falseinstaller)
)

; #######################################################
; # view infos
; #######################################################

(message #info1)
; (run "run >nil: SYS:Utilities/MultiView" #infotxt (prompt #readme))
(message #info2)

; #######################################################
; # choose work
; #######################################################

(set work
    (askbool
        (prompt #choice1)
        (choices #work1 #work2)
        (help #info2)
    )
)

; #######################################################
; # choose destination
; #######################################################

(If (= 1 work)
    (
        (set mvpath
            (askdir
                (prompt #updateinfo)
                (help #destination-help)
                (default "work:")
            )
        )
    )
    (
        (set mvpath
            (askdir
                (prompt #installinfo)
                (help #destination-help)
                (default "work:")
            )
        )
    )
)

(set mvdest (tackon mvpath "DataM_II"))
(set @default-dest mvdest)

; #######################################################
; # update procedure
; #######################################################

(if (= 1 work)
    ( ; update start

        ; #######################################################
        ; # update: DataM II main, modules & catalogs
        ; #######################################################
        ; # DataM II
        ; #######################################################

        (if (exists mvdest)
            (
                (p_getversions "/DataM_ II" (tackon mvdest "DataM_II"))
                (if (= 1 (askbool (prompt (#updatemuimain) (if (= 0 oldversion) ((verinfo3)) ((verinfo1 oldver oldrev))) (verinfo2 aktver aktrev)) (help #versions-help)))
                    (
                        (copyfiles
                            (prompt #copymain)
                            (source "/DataM_II")
                            (dest mvdest)
                            (if (<> (exists (tackon mvdest "DataM_II.info")) (infos)))
                            (help @copyfiles-help)
                        )
                        (if (= @language "english")
                            (
                                (copyfiles
                                    (prompt "Update DataM II Catalogs")
                                    (source "/catalogs/english")
                                    (dest (tackon mvdest "catalogs/english"))
                                    (pattern "(#?.catalogs)")
                                    (help @copyfiles-help)
                                )
                            )
                            (
                                (copyfiles
                                    (prompt "Update der DataM II Katalog-Files")
                                    (source "/catalogs")
                                    (dest (tackon mvdest "catalogs"))
                                    (pattern "(#?.cd)")
                                    (confirm "expert")
                                    (help @copyfiles-help)
                                )
                            )
                        )
                    )
                )

                ; #######################################################
                ; # update documentations: german part
                ; #######################################################

                (if (= @language "deutsch")
                    (
                        (copyfiles
                            (prompt #copyinfos)
                            (source "/Docs/deutsch")
                            (dest (tackon mvdest "Docs/deutsch"))
                            (pattern "#?")
                            (nogauge)
                            (infos)
                            (help @copyfiles-help)
                        )
                    )

                    ; #######################################################
                    ; # update documentations: english part
                    ; #######################################################

                    (
                        (copyfiles
                            (prompt #copyinfos)
                            (source "/Docs/english")
                            (dest (tackon mvdest "Docs/english"))
                            (pattern "#")
                            (nogauge)
                            (infos)
                            (help @copyfiles-help)
                        )
                    )
                )
            )
            (
                (message #error1)
                (exit)
            )
        )
    ) ; update end

    ; #######################################################
    ; # new installation procedure
    ; #######################################################

    (
        (while (exists (tackon mvpath "DataM_II_old"))
            (p_deloldbackup (tackon mvpath "DataM_II_old"))
        )
        (if (exists mvdest)
            (
                (message #oldmv)
                (set oldmv (cat mvdest "_old"))
                (rename mvdest oldmv)
                (rename (cat mvdest ".info") (cat oldmv ".info"))
            )
        )
        (if (= @user-level 2)
            (message #createdirs)
        )
        ; (makedir mvdest (infos) (prompt #createdir))
        (makedir (tackon mvdest "ARexx"))
        (makedir (tackon mvdest "Schalter"))
        (makedir (tackon mvdest "Tabellen"))
        (makedir (tackon mvdest "Catalogs"))
        (makedir (tackon mvdest "Docs"))
        (if (= @language "deutsch")
            (
                 (copyfiles
                     (prompt #copylocal)
                     (source "/Catalogs")
                     (dest (tackon mvdest "catalogs"))
                     (pattern "(DataM_II.cd)")
                     (help @copyfiles-help)
                 )
                (copyfiles
                    (prompt #copyinfos)
                    (source "/Docs/deutsch")
                    (dest (tackon mvdest "Docs/deutsch"))
                    (pattern "#?")
                    (nogauge)
                    (infos)
                    (help @copyfiles-help)
                )
                (copyfiles
                    (prompt #copyinfos)
                    (source "/Docs/deutsch.info")
                    (dest (tackon mvdest "Docs"))
                    (nogauge)
                    (help @copyfiles-help)
                )
            )
            (
                (makedir (tackon mvdest "catalogs/englisch"))
                (copyfiles
                    (prompt #copylocal)
                    (source "/Catalogs/english")
                    (dest (tackon mvdest "catalogs/english"))
                    (pattern "(DataM_II#?.catalog)")
                    (help @copyfiles-help)
                )
                (copyfiles
                    (prompt #copyinfos)
                    (source "/Docs/english")
                    (dest (tackon mvdest "Docs/english"))
                    (pattern "#?")
                    (help @copyfiles-help)
                )
                (copyfiles
                    (prompt #copyinfos)
                    (source "/Docs/english.info")
                    (dest (tackon mvdest "Docs"))
                    (nogauge)
                    (help @copyfiles-help)
                )
            )
        )
        (if (= @user-level 2)
            (
                (copyfiles
                    (prompt #askforlanguages)
                    (source "/catalogs")
                    (dest (tackon mvdest "catalogs"))
                    (pattern "~(#?.cd)")
                    (confirm)
                    (help copyfiles-help)
                )
            )
        )
        (copyfiles
            (prompt #copyinfos)
            (source "/")
            (dest (tackon mvdest "/"))
            (pattern "#?.info")
            (nogauge)
            (infos)
            (help @copyfiles-help)
        )
        (copyfiles
            (prompt #copyarexx)
            (source "/ARexx")
            (dest (tackon mvdest "ARexx"))
            (all)
            (infos)
            (confirm "expert")
            (help @copyfiles-help)
        )
        (copyfiles
            (prompt #copybuttons)
            (source "/Schalter")
            (dest (tackon mvdest "Schalter"))
            (all)
            (confirm "expert")
            (help @copyfiles-help)
        )
        (copyfiles
            (prompt #copymain)
            (source "/DataM_II")
            (dest mvdest)
            (infos)
            (help @copyfiles-help)
        )
        (copyfiles
            (prompt #copydata)
            (source "/Tabellen")
            (dest (tackon mvdest "Tabellen"))
            (all)
            (confirm "2")
            (help @copyfiles-help)
        )
        (copyfiles
            (prompt #copyprefs)
            (source "/")
            (dest mvdest)
            (pattern "#?.dmp")
            (confirm "3")
            (help @copyfiles-help)
        )

        ; #######################################################
        ; # save old data and maybe users nerves
        ; #######################################################

        (if (exists (cat mvpath "DataM_II_old"))
            (
                (set vote
                    (askbool
                        (prompt #askforolddata)
                        (choices #true #false)
                        (help @guidehelp)
                    )
                )
                (if (= 1 vote)
                    (
                        (copyfiles
                            (prompt #copyoldmainrexx)
                            (source (tackon oldmv "ARexx"))
                            (dest (tackon mvdest "ARexx"))
                            (all)
                            (confirm "expert")
                            (help @copyfiles-help)
                        )
                        (copyfiles
                            (prompt #copyoldmaindata)
                            (source (tackon oldmv "Tabellen"))
                            (dest (tackon mvdest "Tabellen"))
                            (all)
                            (confirm "expert")
                            (help @copyfiles-help)
                        )
                        (if (exists (tackon oldmv "DataM_II.key"))
                            (
                                (copyfiles
                                    (prompt #copykeyfile)
                                    (source (tackon oldmv "DataM_II.key"))
                                    (dest mvdest)
                                    (confirm "expert")
                                    (help @copyfiles-help)
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

(message #endmessage) ; and now quit the lisp-like-shit
(exit)
