;
; Install Fiasco 2.21 Patch
; Patches Fiasco Release Version 2.2 to Release Version 2.21
; Copyright © 1997-1998 Nils Bandener
; $VER: PatchFiasco 8.1 (5.11.98)
;

(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.2-Distribution auf die 2.21-Version. Dieses Skript sichert ab, daß der richtige Patch angewendet wird.")

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

    (set #select-fiasco-dir-help "Benutzen Sie diesen Requester, um das Verzeichnis anzugeben, in dem Fiasco 2.2 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.2 installiert!\nDie installierte Fiasco-Haupt-Datei sollte Version 8.67 haben, Sie haben Version %ld.%ld.\nFiasco 2.2 ist im Aminet verfügbar.")

    (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 Release Version 2.2 auf die Version 2.21.")

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

    (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.2 distribution to the 2.21 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.2")

    (set #select-fiasco-dir-help "Use this requester to select the directory Fiasco release version 2.2 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.2 installed!\nThe installed Fiasco main executable should have version 8.67, 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.2 main file to the 2.21 version.")

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

    (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 (+ (* 8 65536) 67))
(
    (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 -2103969894)
            (
                (set lang "English")
                (set appch (tackon srcdir "Doc_dvi_eng.pch"))
            )
            (
                (if (= sum 569878482)
                (
                    (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 501297872)
            (
                (set lang "English")
                (set appch (tackon srcdir "Doc_guide_eng.pch"))
            )
            (
                (if (= sum -851714824)
                (
                    (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 95)
))

(complete 99)

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

(complete 100)
