;
; Install Fiasco 2.02 Patch
; Patches Fiasco Release Version 2.01 to Release Version 2.02
; Copyright © 1997 Nils Bandener
; $VER: PatchFiasco 5.11 (8.5.97)
;

(procedure applypatch
    ;
    ; Expected parameters:
    ;
    ; apfile = Name of file to patch
    ; appch  = Name of patch file
    ;

    (working (#patching-s apfile))

    (if (=
           (run ("\"%s\" \"-p%s\" -ot:Fiasco_New \"%s\"" spatch appch apfile))

         0)
    (
        (delete apfile)
        (copyfiles (source "T:Fiasco_New")
                   (dest (pathonly apfile)))

        (rename (tackon (pathonly apfile) "Fiasco_New") apfile)
        (delete "T:Fiasco_New")
    )
    (
        (abort (#patch-could-not-be-applied apfile))
    ))
)

(procedure applyldocpatch

    (set apfile (tackon ldocdir "Fiasco.guide"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (set appch (tackon srcdir ("Doc_guide_%s.pch" ldoclang)))

            (applypatch)
        ))
    ))

    (set apfile (tackon ldocdir "Fiasco.dvi"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (set appch (tackon srcdir ("Doc_dvi_%s.pch" ldoclang)))

            (applypatch)
        ))
    ))
)

(if (= @language "deutsch")
(
    (set #yes "Ja")

    (set #no "Nein")

    (set #patching-s "Patche \"%s\"...")

    (set #patch-could-not-be-applied "Patch konnte nicht auf \"%s\" angewendet werden.")

    (set #want-to-patch "Wollen Sie \"%s\" patchen?")

    (set #patch-doc-help "Diese Prozedur aktualisiert das Dokument der Fiasco 2.01-Distribution auf die 2.02-Version. Dieses Script sichert ab, daß der richtige Patch angewendet wird.")

    (set #select-fiasco-dir "Bitte wählen Sie das Verzeichnis aus, in dem sich Fiasco 2.01 befindet.")

    (set #select-fiasco-dir-help "Benutzen Sie diesen Requester, um das Verzeichnis anzugeben, in dem Fiasco 2.01 abgelegt ist.")

    (set #fiasco-dir-does-not-exist "Das ausgewählte Verzeichnis existiert nicht!")

    (set #fiasco-dir-not-ok "Das ausgewählte Verzeichnis enthält nicht die Fiasco-Haupt-Datei!")

    (set #version-not-ok "Sie haben nicht Fiasco Version 2.01 installiert!\nDie installierte Fiasco-Haupt-Datei sollte Version 5.459 haben, Sie haben Version %ld.%ld.\nIm Aminet ist ein Patch enthalten, der Fiasco 2.0 auf Fiasco 2.01 patcht.")

    (set #patch-fiasco-main "Wollen Sie die Fiasco-Haupt-Datei patchen?")

    (set #patch-fiasco-main-help "Diese Prozedur aktualisiert die ausführbare Datei von Fiasco Relase Version 2.01 auf die Version 2.02.")

    (set #unknown-file "Kann Patch nicht anwenden:\nDie Datei %s ist dem Installer-Script unbekannt.")

    (set #install-impcol "Wollen Sie das neue ARexx-Script importcolumn.rexx installieren?")

    (set #install-impcol-help "Installiert ein neues ARexx-Script für Fiasco, das ASCII-Dateien, in denen die Daten spaltenweise abgelegt sind, in Fiasco importieren kann.")

    (set #install-danish-catalog "Wollen Sie den dänischen Catalog für Fiasco installieren?")

    (set #install-danish-catalog-help "Installiert den neuen dänischen Catalog für Fiasco. Damit können Sie Fiasco in Dänisch betreiben.")

    (set #examining-s "Untersuche \"%s\" ...")
)
(
    (set #yes "Yes")

    (set #no "No")

    (set #patching-s "Patching \"%s\"...")

    (set #patch-could-not-be-applied "Patch could not be applied to \"%s\".")

    (set #want-to-patch "Do you want to patch \"%s\"?")

    (set #patch-doc-help "This procedure updates the document from the Fiasco 2.01 distribution to the 2.02 version. This script makes sure, that the correct patch will be applied")

    (set #select-fiasco-dir "Please select the directory where you have installed Fiasco 2.01")

    (set #select-fiasco-dir-help "Use this requester to select the directory Fiasco release version 2.01 is located.")

    (set #fiasco-dir-does-not-exist "The selected directory does not exist!")

    (set #fiasco-dir-not-ok "The selected directory does not contain the Fiasco main executable!")

    (set #version-not-ok "You do not have Fiasco 2.01 installed!\nThe installed Fiasco main executable should have version 5.459, you have version %ld.%ld.")

    (set #patch-fiasco-main "Do you want to patch the main Fiasco executable?")

    (set #patch-fiasco-main-help "This procedure will change the Fiasco release version 2.01 main file to the 2.02 version.")

    (set #unknown-file "Unable to apply patch:\nThe file %s is unkown to this installer script.")

    (set #install-impcol "Do you want to install the new ARexx script importcolumn.rexx?")

    (set #install-impcol-help "Installs a new ARexx support script for Fiasco, that is able to import an ASCII file, in which the data are structured by columns, into Fiasco.")

    (set #install-danish-catalog "Do you want to install the Danish catalog for Fiasco?")

    (set #install-danish-catalog-help "Installs the new Danish catalog for Fiasco. If you have installed it, you may use Fiasco in Danish language.")

    (set #examining-s "Examining \"%s\"...")
))

(set srcdir (tackon (pathonly @icon) "data"))

(set spatch (tackon (pathonly @icon) "spatch"))

(set destok 0)

(while (not destok)
(
    (set @default-dest
        (askdir (prompt #select-fiasco-dir)
                (default "Work:")
                (help #select-fiasco-dir-help)))

    (if (exists @default-dest)
    (
        (if (= (exists (tackon @default-dest "Fiasco")) 1)
        (
            (set destok 1)
        )
        (
            (message #fiasco-dir-not-ok)
        ))
    )
    (
        (message #fiasco-dir-does-not-exist)
    ))
))

(complete 5)

(set exver (getversion (tackon @default-dest "Fiasco")))

(if (<> exver (+ (* 5 65536) 459))
(
    (set ver (/ exver 65536))
    (set rev (- exver (* ver 65536)))

    (abort (#version-not-ok ver rev))
))

(if (askbool (prompt #patch-fiasco-main)
             (choices #yes #no)
             (help #patch-fiasco-main-help)
             (default 1))
(
    (set appch (tackon srcdir "Fiasco.pch"))
    (set apfile (tackon @default-dest "Fiasco"))

    (applypatch)
))

(complete 15)

(set docdir (tackon @default-dest "Documentation"))

(if (exists docdir)
(
    (set apfile (tackon docdir "Fiasco.dvi"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (working (#examining-s apfile))

            (set sum (getsum apfile))

            (complete 30)

            (if (= sum -89170205)
            (
                (set lang "English")
                (set appch (tackon srcdir "Doc_dvi_eng.pch"))
            )
            (
                (if (= sum 34182494)
                (
                    (set lang "Deutsch")
                    (set appch (tackon srcdir "Doc_dvi_deu.pch"))
                )
                (
                    (message (#unknown-file apfile))
                    (set appch "")
                ))
            ))

            (if (<> appch "")
            (
                (applypatch)
            ))

            (complete 40)
        ))
    ))

    (set apfile (tackon docdir "Fiasco.guide"))

    (if (exists apfile)
    (
        (if (askbool (prompt (#want-to-patch apfile))
                     (choices #yes #no)
                     (help #patch-doc-help)
                     (default 1))
        (
            (working (#examining-s apfile))

            (set sum (getsum apfile))

            (complete 55)

            (if (= sum 280577263)
            (
                (set lang "English")
                (set appch (tackon srcdir "Doc_guide_eng.pch"))
            )
            (
                (if (= sum -822521324)
                (
                    (set lang "Deutsch")
                    (set appch (tackon srcdir "Doc_guide_deu.pch"))
                )
                (
                    (message (#unknown-file apfile))
                    (set appch "")
                ))
            ))

            (if (<> appch "")
            (
                (applypatch)
            ))

            (complete 65)
        ))
    ))

    (set ldocdir (tackon docdir "English"))
    (set ldoclang "eng")

    (applyldocpatch)

    (complete 75)

    (set ldocdir (tackon docdir "Deutsch"))
    (set ldoclang "deu")

    (applyldocpatch)

    (complete 85)
))

(complete 90)

(set rexxdir (tackon @default-dest "ARexx"))

(if (exists rexxdir)
(
    (if (askbool (prompt #install-impcol)
                 (choices #yes #no)
                 (help #install-impcol-help)
                 (default 1))
    (
        (copyfiles (source (tackon srcdir "importcolumn.rexx"))
                   (dest rexxdir)
                   (infos))
    ))
))

(complete 95)

(set catalogdir (tackon @default-dest "catalogs"))

(if (not (exists catalogdir))
(
    (set catalogdir "sys:locale/catalogs")
))

(if (exists catalogdir)
(
    (if (askbool (prompt #install-danish-catalog)
                 (choices #yes #no)
                 (help #install-danish-catalog-help)
                 (default 0))
    (
        (copyfiles (source (tackon srcdir "Fiasco_dan.catalog"))
                   (dest (tackon catalogdir "Dansk")))

        (rename (tackon catalogdir "Dansk/Fiasco_dan.catalog")
                (tackon catalogdir "Dansk/Fiasco.catalog"))
    ))
))

(complete 99)

(if (not (exists (tackon @default-dest "Fiasco.key")))
(
    (copyfiles (source (tackon (pathonly @icon) "RegForm.txt"))
               (dest @default-dest)
               (infos))
))

(complete 100)
